@openchambery/web 1.18.2-beta.43 → 1.18.2-beta.45
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-B8_EPDAq.js → AssistantView-D5dwzTW-.js} +1 -1
- package/dist/assets/{ChatContainer-DESDROKK.js → ChatContainer-C0aSmaP7.js} +9 -9
- package/dist/assets/{DiagramView-CBj5OlBj.js → DiagramView-B9MkYVdB.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-CRWrh3xn.js → MarkdownRendererImpl-DV9BO3YP.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-DLgSO5Kg.js → MobileDetailNavigation-BlMONzIF.js} +1 -1
- package/dist/assets/{MobileShareBridge-Bd8nzfsv.js → MobileShareBridge-CmjbxTz5.js} +1 -1
- package/dist/assets/{MobileSurface-Bc3797j0.js → MobileSurface-DC5TfVFJ.js} +1 -1
- package/dist/assets/{MultiRunWindow-CyWOW69k.js → MultiRunWindow-Bd2WXyNm.js} +1 -1
- package/dist/assets/{SettingsView-DWVO6ORR.js → SettingsView-FWM7IoJh.js} +1 -1
- package/dist/assets/{SettingsWindow-DcgiqXuj.js → SettingsWindow-CUj1RbMY.js} +1 -1
- package/dist/assets/{TerminalView-Bhd-iolh.js → TerminalView-Bf0YAeDi.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BST1ibJ-.js → ToolOutputDialog-B-3Wg0na.js} +1 -1
- package/dist/assets/{appThemeRegistry-1dvFBOjv.js → appThemeRegistry-MdrVqcRf.js} +2 -2
- package/dist/assets/{context-menu-DdpyAEq9.js → context-menu-aYTZ8IdV.js} +1 -1
- package/dist/assets/{gitApi-CHWQ9HHr.js → gitApi-CWWLhr6A.js} +1 -1
- package/dist/assets/{insertionBoundaries-tLVWM0T0.js → insertionBoundaries-Gxlz7c_q.js} +1 -1
- package/dist/assets/{main-BuReDA8k.js → main-7bHGLmPb.js} +4 -4
- package/dist/assets/{main-RxFu8BCg.js → main-cVQmYrnI.js} +2 -2
- package/dist/assets/{miniChat-CMIqUHeK.js → miniChat-CH1bTME8.js} +2 -2
- package/dist/assets/{mobile-DWXp3zNj.js → mobile-DTOe9M-_.js} +2 -2
- package/dist/assets/{multirun-DNgYzfJG.js → multirun-CiSKWYKN.js} +1 -1
- package/dist/assets/{projectMeta-Blj79fFK.js → projectMeta-DLXb99IT.js} +1 -1
- package/dist/assets/{radio-DwrbCe5s.js → radio-SaNMUOXT.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-vZlkQAOk.js → renderElectronMiniChatApp-Cp7o7A_b.js} +2 -2
- package/dist/assets/{renderMobileApp-Cdrt2ZEN.js → renderMobileApp-DfRyj-dR.js} +5 -5
- package/dist/assets/{runtimeConfig-B_3FljnM.js → runtimeConfig-CsBnmDwC.js} +1 -1
- package/dist/assets/{runtimeEndpointReset-Bhthnk06.js → runtimeEndpointReset-DYq0N9UQ.js} +1 -1
- package/dist/assets/{src-g24RTPja.css → src-CmuRWlC-.css} +1 -1
- package/dist/assets/{useAppFontEffects-y9IgBoeF.js → useAppFontEffects--aew6FZ5.js} +2 -2
- package/dist/assets/{useDesktopWindowControlsLayout-oaFybFc3.js → useDesktopWindowControlsLayout-CyuSgLBM.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-DLRToAto.js → useEffectiveDirectory-CzRV5a49.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-D9hGzn72.js → useMobileNavigationStore-C6clfdA_.js} +1 -1
- package/dist/assets/{useSessionAutoCleanup-CFCT9dyA.js → useSessionAutoCleanup-DzED64Bx.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-D18SEyBe.js → useWorkerHighlightedLines-abN0NaM0.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
|
@@ -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{D as t,E as n,F as r,T as i,W as a,g as o,j as s,t as c,y as l}from"./useUIStore-CJsC3a8g.js";import{$ as u,$t as d,B as f,C as p,Ct as m,Dt as h,G as g,I as _,J as v,K as y,M as b,N as x,Q as S,R as C,S as w,T,U as E,V as D,W as O,Wt as k,Y as A,Z as j,_ as M,at as N,b as P,ct as F,d as I,et as L,ft as R,it as z,j as B,kn as V,lt as H,mt as U,nt as W,ot as ee,pt as G,q as K,r as te,st as ne,u as re,ut as ie,v as ae,wt as oe,x as se,y as ce,yt as le,z as ue}from"./persistence-DPmGG6sf.js";import{a as de,i as fe,r as pe,t as me}from"./vendor-zustand-B4dlGEM2.js";import{c as he,d as ge,f as _e,l as ve,nt as ye,rt as be,tt as xe,u as Se}from"./vendor-base-ui-CnHfUmDN.js";import{At as Ce,Bt as we,Ct as Te,Gt as Ee,Ht as De,Jt as Oe,Nt as ke,Pt as Ae,Rt as je,St as Me,Ut as Ne,Wt as Pe,jt as Fe,kt as Ie,n as Le,qt as Re,t as ze,zt as Be}from"./platform-CbV34Pzu.js";import{a as Ve,n as He,o as Ue}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as We}from"./vendor-react-DLPElpoQ.js";import{i as Ge,n as Ke,s as qe,t as Je}from"./vendor-tanstack-react-query-D7pys_c9.js";import{B as Ye,R as Xe,V as Ze,c as Qe}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{a as $e,d as et,i as tt,l as nt,n as q,o as rt,r as it,u as at}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ot,r as st,t as ct}from"./clipboard-Bu8y4WEC.js";import{i as lt,t as ut}from"./store-BLmIK6EO.js";import{$ as dt,$r as ft,$t as pt,A as mt,Aa as ht,Ai as gt,An as _t,Ao as vt,Ar as yt,B as bt,Ba as xt,Bi as St,Br as Ct,Bt as wt,Ca as Tt,Ci as Et,Cn as Dt,Cr as Ot,Ct as kt,D as At,Di as jt,Dt as Mt,E as Nt,Ei as Pt,Er as Ft,Et as It,F as Lt,Fi as Rt,Fn as zt,Fr as Bt,G as Vt,Ga as Ht,Gr as Ut,Gt as Wt,Ha as Gt,Hi as Kt,Hn as qt,Hr as Jt,Ht as Yt,I as Xt,Ia as Zt,Ii as Qt,In as $t,J as en,Ja as tn,Jr as nn,Jt as rn,K as an,Ka as on,Kr as sn,Kt as cn,L as ln,Li as un,Ln as dn,Lr as fn,M as pn,Ma as mn,Mi as hn,Mr as gn,Mt as _n,N as vn,Ni as yn,No as bn,Nr as xn,Nt as Sn,O as Cn,Oa as wn,Oi as Tn,Ot as En,P as Dn,Pi as On,Pn as kn,Q as An,Qi as jn,Qt as Mn,Ri as Nn,Rt as Pn,S as Fn,Si as In,Sn as Ln,T as Rn,Ta as zn,Ti as Bn,Tr as Vn,Tt as Hn,U as Un,Ua as Wn,Ui as Gn,Un as Kn,Ur as qn,Va as Jn,Vi as Yn,Vr as Xn,Vt as Zn,Wa as Qn,X as $n,Xt as er,Y as tr,Ya as nr,Z as rr,Zi as ir,Zt as ar,_a as or,_i as sr,_n as cr,a as lr,aa as ur,an as dr,at as fr,ba as pr,bi as mr,bn as hr,bo as gr,cn as _r,ct as vr,da as yr,di as br,dn as xr,dt as Sr,ea as Cr,ei as wr,en as Tr,eo as Er,er as Dr,et as Or,f as kr,fa as Ar,fi as jr,fn as Mr,ft as Nr,g as Pr,ga as Fr,gi as Ir,ha as Lr,hi as Rr,hr as zr,ht as Br,i as Vr,ii as Hr,in as Ur,io as Wr,it as Gr,j as Kr,ji as qr,jr as Jr,jt as Yr,k as Xr,ka as Zr,ki as Qr,kr as $r,l as J,la as ei,li as ti,ln as ni,lt as ri,m as ii,ma as ai,mi as oi,n as si,na as ci,ni as li,nn as ui,nr as di,nt as fi,oi as pi,on as mi,pa as hi,pt as gi,q as _i,qa as vi,qi as yi,qt as bi,ri as xi,rn as Si,rr as Ci,rt as wi,sn as Ti,ta as Ei,ti as Di,to as Oi,tr as ki,tt as Ai,ui as ji,un as Mi,ut as Ni,vi as Pi,vn as Fi,vr as Ii,vt as Li,w as Ri,wi as zi,wn as Bi,wr as Vi,wt as Hi,x as Ui,xa as Wi,xi as Gi,xn as Ki,xo as qi,ya as Ji,yt as Yi,z as Xi,za as Zi,zi as Qi,zr as $i,zt as ea}from"./useMobileNavigationStore-D9hGzn72.js";import{n as ta,t as na}from"./AgentAvatar-y3ycseGU.js";import{n as ra,t as Y}from"./utils-DpGCrB3y.js";import{n as X}from"./Icon-CstxOD6I.js";import{a as ia,i as aa,n as oa,o as sa,r as ca,s as la,t as ua}from"./dialog-CsFlH6Lj.js";import{t as da}from"./button-CQ8B8MBG.js";import{E as fa,n as pa}from"./gitApi-CHWQ9HHr.js";import{A as ma,C as ha,M as ga,N as _a,O as va,S as ya,T as ba,a as xa,b as Sa,d as Ca,g as wa,h as Ta,i as Ea,j as Da,k as Oa,n as ka,o as Aa,p as ja,s as Ma,u as Na,v as Pa,w as Fa,x as Ia}from"./projectMeta-Blj79fFK.js";import{t as La}from"./input-DVGFeMHA.js";import{i as Ra,n as za,t as Ba}from"./tooltip-BkJSe4NL.js";import{n as Va,t as Ha}from"./useThemeSystem-DMzWVJaW.js";import{D as Ua,E as Wa,M as Ga,N as Ka,O as qa,Q as Ja,S as Ya,U as Xa,V as Za,X as Qa,Y as $a,_ as eo,a as to,f as no,g as ro,h as io,i as ao,m as oo,o as so,p as co,r as lo,t as uo,x as fo,z as po}from"./radio-DwrbCe5s.js";import{i as mo,t as ho}from"./OverlayScrollbar-CW5VL9Qc.js";import{_ as go,a as _o,d as vo,f as yo,g as bo,h as xo,i as So,l as Co,m as wo,n as To,u as Eo,v as Do,x as Oo}from"./markdownTheme-X0oilYoj.js";import{n as ko,r as Ao,t as jo}from"./useRuntimeAPIs-DSLXJybW.js";import{a as Mo,c as No,i as Po,r as Fo,t as Io,u as Lo}from"./appThemeRegistry-1dvFBOjv.js";import{_ as Ro,a as zo,c as Bo,g as Vo,l as Ho,o as Uo,t as Wo,v as Go,y as Ko}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{i as qo,n as Jo,o as Yo,s as Xo,t as Zo}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as Qo,n as $o,t as es}from"./url-DNq-9alX.js";import{_ as ts,l as ns,m as rs,p as is,s as as}from"./markdown-worker-BJk0TBYO.js";import{n as os}from"./useEffectiveDirectory-DLRToAto.js";import{a as ss,c as cs,d as ls,f as us,i as ds,l as fs,n as ps,r as ms,s as hs,t as gs}from"./FadeInOnReveal-CPfDtuId.js";import{A as _s,C as vs,D as ys,E as bs,M as xs,O as Ss,S as Cs,T as ws,a as Ts,b as Es,c as Ds,f as Os,i as ks,j as As,k as js,l as Ms,m as Ns,n as Ps,o as Fs,p as Is,r as Ls,s as Rs,t as zs,u as Bs,w as Vs,x as Hs}from"./insertionBoundaries-tLVWM0T0.js";import{A as Us,C as Ws,D as Gs,E as Ks,M as qs,O as Js,S as Ys,T as Xs,a as Zs,b as Qs,c as $s,g as ec,h as tc,i as nc,j as rc,k as ic,o as ac,p as oc,r as sc,s as cc,t as lc,v as uc,w as dc,x as fc,y as pc}from"./useWorkerHighlightedLines-D18SEyBe.js";import{t as mc}from"./vendor-cmdk-CeAGfrLo.js";import{t as hc}from"./sortable-tabs-strip-DuAPHzVT.js";import{n as gc,t as _c}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{i as vc,u as yc}from"./vendor-pierre-diffs-BenIz2TM.js";import{i as bc,t as xc}from"./vendor-framer-motion-DFy_BSVd.js";var Z=e(be(),1),Q=We(),$=ye(),Sc=e(xe(),1),Cc=`openchamber:close-embedded-session-chat`,wc=`openchamber:embedded-visibility`,Tc=`openchamber:embedded-visibility-request`,Ec=e=>new URLSearchParams(e).get(`ocPanel`)===`session-chat`,Dc=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),Oc=(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()},kc=(e,t,n,r,i,a)=>{let o=Dc(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=Oc(n,r,i,a);return e.set(t,{signature:o,src:c}),c},Ac=null,jc=()=>{if(Ac!==null)return Ac;if(typeof window>`u`)return Ac=!1,!1;try{return Ac=new URLSearchParams(window.location.search).get(`ocPanel`)===`session-chat`,Ac}catch{return Ac=!1,!1}},Mc=()=>{if(!jc())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},Nc=Ve(`OpenChamberMedia`);function Pc(){return Le()&&He.getPlatform()===`android`&&He.isPluginAvailable(`OpenChamberMedia`)}async function Fc(e){if(!Pc())return null;let t=await Nc.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 Ic=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},Lc=1e4,Rc=15e3,zc=3e4,Bc=3e4,Vc=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`))}},Lc);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`))},Rc);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`))},Bc),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=Ic(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)}}},zc))}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`,()=>{Vc.cancelAllForRuntimeSwitch()});var Hc=128,Uc=`audio/pcm;rate=16000;bits=16`,Wc=()=>new Promise(e=>setTimeout(e,0)),Gc=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},Kc=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??Uc,this.getStartOptions=e.getStartOptions,this.createDictationId=e.createDictationId??Gc}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<Hc;){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 Wc()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},qc=16e3,Jc=qc,Yc=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},Xc=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},Zc=(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]=Xc(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]=Xc(e[i]*(1-s)+e[o]*s)}return a},Qc=(e,t)=>{if(e.length===0)return t;if(t.length===0)return e;let n=new Int16Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n},$c=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)},el=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),tl=e=>{if(e)try{e.disconnect()}catch{}},nl=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Yc()!==null;function rl(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=el(),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=Yc();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(ol);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=Zc(a,n.sampleRate,qc);for(t.pending=Qc(t.pending,c);t.pending.length>=Jc;){let e=t.pending.slice(0,Jc);t.pending=t.pending.slice(Jc),i.current($c(e))}},e.connect(a),a.connect(o),o.connect(n.destination)}catch(e){let r=e;t.getTracks().forEach(al);try{await n.close()}catch{}throw l.current=el(),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{}tl(e.processor),tl(e.source),tl(e.gain),e.stream&&e.stream.getTracks().forEach(il);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current($c(t)),e.context)try{await e.context.close()}catch{}l.current===e&&(l.current=el())},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 il(e){try{e.stop()}catch{}}function al(e){try{e.stop()}catch{}}function ol(){}var sl=1e3,cl=e=>e instanceof Error?e:Error(String(e)),ll=()=>{let e=Ei.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 ul(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 Kc({client:Vc,getStartOptions:ll});let x=(0,Z.useCallback)(()=>{g.current&&=(clearInterval(g.current),null)},[]),S=(0,Z.useCallback)(()=>{g.current||=setInterval(()=>{l(e=>e+1)},sl)},[]),C=(0,Z.useCallback)(e=>{let t=cl(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)(()=>Vc.onPartial((e,t)=>{let n=b.current?.getDictationId();!n||e!==n||(h.current=t,s(t))}),[]),(0,Z.useEffect)(()=>Vc.subscribeConnectionStatus(e=>{e&&m.current===`recording`&&b.current?.restartStream().catch(e=>{C(e)})}),[C]);let E=rl({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 dl=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},fl=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=Va(),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},pl=e=>{let t=Ei(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},ml=e=>{let t=(0,Q.c)(86),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:s,disabled:l,onInsert:u,onInsertAndSend:d,onActiveChange:f,onContentHeightChange:p,renderTrigger:m,topAccessory:h}=e,g=m===void 0||m,{t:_}=ot(),{currentTheme:v}=Va(),y=Ei(hl),b=c(gl),x;t[0]===b?x=t[1]:(x=Za(Xa(`toggle_dictation`,b)),t[0]=b,t[1]=x);let S=x,[C]=Z.useState(_l),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}=ul(k),H=A===`recording`&&F===`model_download_in_progress`,U=pl(H),W=Z.useRef(A),ee,G;t[7]===A?(ee=t[8],G=t[9]):(ee=()=>{W.current=A},G=[A],t[7]=A,t[8]=ee,t[9]=G),Z.useEffect(ee,G);let K,te;t[10]!==f||t[11]!==A?(K=()=>{f?.(A!==`idle`)},te=[A,f],t[10]=f,t[11]=A,t[12]=K,t[13]=te):(K=t[12],te=t[13]),Z.useLayoutEffect(K,te);let ne,re;t[14]!==L||t[15]!==I?(ne=()=>{let e=()=>{W.current===`idle`?I():W.current===`recording`&&(w.current=`insert`,L())};return window.addEventListener(`openchamber:dictation-toggle`,e),()=>window.removeEventListener(`openchamber:dictation-toggle`,e)},re=[I,L],t[14]=L,t[15]=I,t[16]=ne,t[17]=re):(ne=t[16],re=t[17]),Z.useEffect(ne,re);let ie,ae;t[18]!==R||t[19]!==L||t[20]!==A?(ie=()=>{if(A!==`recording`)return;let e=e=>{if(!e.isComposing){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault(),e.stopPropagation(),w.current=`insert`,L();return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),R())}};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},ae=[A,L,R],t[18]=R,t[19]=L,t[20]=A,t[21]=ie,t[22]=ae):(ie=t[21],ae=t[22]),Z.useEffect(ie,ae);let oe=Z.useRef(null),se=Z.useRef(null),ce=Z.useRef(null),[le,ue]=Z.useState(null),de=A!==`idle`,fe=Z.useRef(p),pe,me;t[23]===p?(pe=t[24],me=t[25]):(pe=()=>{fe.current=p},me=[p],t[23]=p,t[24]=pe,t[25]=me),Z.useEffect(pe,me);let he=Z.useRef(!1),ge;t[26]===de?ge=t[27]:(ge=()=>{if(!de){he.current&&(he.current=!1,fe.current?.(null));return}let e=se.current,t=ce.current;if(!e||!t)return;let n=window.getComputedStyle(e),r=(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0);he.current=!0,fe.current?.(t.offsetHeight+r),e.scrollTop=e.scrollHeight},t[26]=de,t[27]=ge);let _e;t[28]!==P||t[29]!==de||t[30]!==j||t[31]!==A?(_e=[de,j,A,P],t[28]=P,t[29]=de,t[30]=j,t[31]=A,t[32]=_e):_e=t[32],Z.useLayoutEffect(ge,_e);let ve,ye;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(ve=()=>()=>{he.current&&(he.current=!1,fe.current?.(null))},ye=[],t[33]=ve,t[34]=ye):(ve=t[33],ye=t[34]),Z.useEffect(ve,ye);let be,xe;if(t[35]===de?(be=t[36],xe=t[37]):(be=()=>{if(!de)return;let e=oe.current?.closest(`[data-chat-input-footer="true"]`);e&&e.offsetHeight>0&&ue(e.offsetHeight)},xe=[de],t[35]=de,t[36]=be,t[37]=xe),Z.useLayoutEffect(be,xe),!C||!y)return null;let Se=A!==`idle`,Ce;t[38]===L?Ce=t[39]:(Ce=e=>{w.current=e,L()},t[38]=L,t[39]=Ce);let we=Ce,Te;t[40]===z?Te=t[41]:(Te=()=>{w.current=`insert`,z()},t[40]=z,t[41]=Te);let Ee=Te,De;bb0:{if(A===`failed`){De=``;break bb0}if(A===`uploading`){let e;t[42]===_?e=t[43]:(e=_(`chat.dictation.processing`),t[42]=_,t[43]=e),De=e;break bb0}if(H){let e;t[44]!==U||t[45]!==_?(e=U===null?_(`chat.dictation.downloadingModel`):_(`chat.dictation.downloadingModelProgress`,{percent:String(U)}),t[44]=U,t[45]=_,t[46]=e):e=t[46],De=e;break bb0}let e;t[47]===_?e=t[48]:(e=_(`chat.dictation.listening`),t[47]=_,t[48]=e),De=e}let Oe=De,ke;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(ke={onMouseDown:vl,onPointerDownCapture:yl},t[49]=ke):ke=t[49];let Ae=ke,je;t[50]!==S||t[51]!==l||t[52]!==i||t[53]!==o||t[54]!==Se||t[55]!==g||t[56]!==I||t[57]!==_?(je=g?(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:()=>{I()},disabled:l||Se,title:S?`${_(`chat.dictation.start`)} (${S})`:_(`chat.dictation.start`),"aria-label":_(`chat.dictation.start`),children:(0,$.jsx)(X,{name:`mic`,className:Y(o,`text-current`)})}):null,t[50]=S,t[51]=l,t[52]=i,t[53]=o,t[54]=Se,t[55]=g,t[56]=I,t[57]=_,t[58]=je):je=t[58];let Me;t[59]!==B||t[60]!==R||t[61]!==we||t[62]!==v||t[63]!==V||t[64]!==N||t[65]!==P||t[66]!==le||t[67]!==i||t[68]!==a||t[69]!==o||t[70]!==Se||t[71]!==r||t[72]!==H||t[73]!==j||t[74]!==Oe||t[75]!==n||t[76]!==Ee||t[77]!==s||t[78]!==A||t[79]!==_||t[80]!==h||t[81]!==M?(Me=Se?(0,$.jsxs)(`div`,{ref:oe,className:Y(`absolute inset-0 z-50 flex flex-col overflow-x-hidden overflow-y-hidden`,r&&`oc-composer-morph-content-fade`),style:{borderRadius:n,backgroundColor:v.colors.surface.subtle},role:`dialog`,"aria-label":_(`chat.dictation.overlayAria`),children:[h,(0,$.jsx)(`div`,{ref:se,className:Y(`scrollbar-none flex-1 min-h-0 overflow-y-auto px-3`,r?`pt-3.5 pb-2.5`:`pt-5 pb-2`),children:(0,$.jsxs)(`div`,{ref:ce,className:Y(!j&&`translate-y-1.5`),children:[j?(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label whitespace-pre-wrap`,style:{color:v.colors.surface.foreground},children:j}):A===`recording`?(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,style:{color:v.colors.surface.mutedForeground},children:[(0,$.jsx)(fl,{volume:M}),(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,children:Oe})]}):(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,style:{color:v.colors.surface.mutedForeground},children:Oe}),A===`failed`?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.error},children:P||_(`chat.dictation.failed`)}):null,A===`recording`&&P&&!H?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.warning},children:P}):null]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center gap-x-3`,a),style:le?{height:le}:void 0,children:[A===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`relative ml-1 flex h-2 w-2 flex-shrink-0`,"aria-hidden":`true`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full opacity-60`,style:{backgroundColor:v.colors.status.error}}),(0,$.jsx)(`span`,{className:`relative inline-flex h-2 w-2 rounded-full`,style:{backgroundColor:v.colors.status.error}})]}),(0,$.jsx)(fl,{volume:M}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:v.colors.surface.mutedForeground},children:dl(N)})]}):A===`uploading`?(0,$.jsx)(X,{name:`loader-4`,className:`ml-1 h-4 w-4 animate-spin`,style:{color:v.colors.surface.mutedForeground}}):null,(0,$.jsx)(`div`,{className:Y(`ml-auto flex items-center`,r?`gap-x-1`:`gap-x-1.5 md:gap-x-3`),children:A===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...Ae,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:()=>we(`insert`),title:_(`chat.dictation.insert`),"aria-label":_(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...Ae,className:Y(i,`text-primary hover:text-primary`),onClick:()=>we(`send`),title:_(`chat.dictation.insertAndSend`),"aria-label":_(`chat.dictation.insertAndSend`),children:(0,$.jsx)(X,{name:`send-plane-2`,className:s})})]}):A===`uploading`?(0,$.jsx)(`button`,{type:`button`,...Ae,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...Ae,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:V,title:_(`chat.dictation.discard`),"aria-label":_(`chat.dictation.discard`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:Ee,title:_(`chat.dictation.retry`),"aria-label":_(`chat.dictation.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:o})}),j.trim()?(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:()=>{w.current=`insert`,B()},title:_(`chat.dictation.insert`),"aria-label":_(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}):null]})})]})]}):null,t[59]=B,t[60]=R,t[61]=we,t[62]=v,t[63]=V,t[64]=N,t[65]=P,t[66]=le,t[67]=i,t[68]=a,t[69]=o,t[70]=Se,t[71]=r,t[72]=H,t[73]=j,t[74]=Oe,t[75]=n,t[76]=Ee,t[77]=s,t[78]=A,t[79]=_,t[80]=h,t[81]=M,t[82]=Me):Me=t[82];let Ne;return t[83]!==je||t[84]!==Me?(Ne=(0,$.jsxs)($.Fragment,{children:[je,Me]}),t[83]=je,t[84]=Me,t[85]=Ne):Ne=t[85],Ne};function hl(e){return e.dictationEnabled}function gl(e){return e.shortcutOverrides}function _l(){return!d()&&nl()}function vl(e){return e.preventDefault()}function yl(e){e.pointerType===`touch`&&e.preventDefault()}var bl=2e3,xl=de((e,t)=>({pending:!1,expiresAt:null,arm:(t=bl)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),Sl=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}},Cl=15e3,wl=100,Tl=new Map,El=new Map,Dl=e=>`${e.runtimeKey}\n${e.directory}\n${e.sessionID}`,Ol=e=>{let t=Dl(e),n=e.now??Date.now(),r=El.get(t);if(r&&n-r.loadedAt<Cl)return Promise.resolve(r.sessions);let i=Tl.get(t);if(i)return i;let a=e.request().then(e=>{for(El.delete(t);El.size>=wl;){let e=El.keys().next().value;if(typeof e!=`string`)break;El.delete(e)}return El.set(t,{loadedAt:Date.now(),sessions:e}),e});return Tl.set(t,a),a.then(()=>{Tl.get(t)===a&&Tl.delete(t)},()=>{Tl.get(t)===a&&Tl.delete(t)}),a},kl=(e,t)=>e.id<t.id?-1:+(e.id>t.id),Al=(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(kl)},jl=30;function Ml(e){return e===`busy`||e===`retry`}var Nl=new Map;function Pl(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function Fl(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 Il(e,t){if(!e.error)return;let n=e.response?.status;throw Error(`${t} failed${n?` (${n})`:``}: ${Fl(e.error)}`)}function Ll(e,t){let n=or();if(!n)return!1;let r=n.getTranscript(zn(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>yn()}function Rl(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function zl(e,t,n){let r=[...e.getState().session],i=ht.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function Bl(){let e=xr(),t=wt(),r=Pn(),i=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),a=(0,Z.useCallback)((t,n=e)=>{let r=or();if(!r||!t)return Pl({kind:`unknown`,loadedTurns:0},!1);let i=zn(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return Pl(a.boundary,o?.status===`loading`)},[e]),o=(0,Z.useCallback)((e,t)=>{if(t.length===0)return;let n=r.getChild(e);if(!n)return;let i=n.getState(),a={session_status:{...i.session_status},session_status_observed_at:{...i.session_status_observed_at},session_diff:{...i.session_diff},todo:{...i.todo},permission:{...i.permission},question:{...i.question}};Ln(a,t),Yr(n,t),n.setState(a);for(let n of t)pr(e,n)},[r]),s=(0,Z.useCallback)((t=e)=>{let n=Nl.get(t);if(n)return Nl.delete(t),Nl.set(t,n),n;let r=new Set;for(Nl.set(t,r);Nl.size>jl;){let e=Nl.keys().next().value;if(!e)break;let t=[...Nl.get(e)??[]];Nl.delete(e),o(e,t)}return r},[e,o]),c=(0,Z.useCallback)((n,i=e)=>{let a=i===e?t:r.ensureChild(i,{bootstrap:!1}),c=s(i),l=Dt(a.getState()),u=qr(),d=Bi({seen:c,keep:n,limit:u,preserve:l});if(o(i,d),hn()){let e=new Set([n,...c,...l]),t=(or()?.getCacheBudget?.().listCanonical({directory:i})??[]).map(e=>e.scope.sessionID),r=(t.length>0?t:Array.from(c)).filter(t=>t===n||e.has(t)?!1:Ll(i,t));if(r.length>0){for(let e of r)c.delete(e);o(i,r)}}},[r,e,s,o,t]),l=(0,Z.useCallback)(async(n,i)=>{let a=i?.directory??e;if(!n||!a||a===`global`)return;let o=a===e?t:r.ensureChild(a,{bootstrap:!1}),s=o.getState(),c=s.session_status?.[n],l=s.session_status_observed_at?.[n];try{i?.purpose===`prepend`||i?.before?await Lr(a,n):await ai(a,n)}catch{return}if(i?.isStale?.())return;let u=or()?.getTranscript(zn(a,n));Di({directory:a,sessionID:n,store:o,transcript:u,isStale:i?.isStale}),await xi({directory:a,sessionID:n,store:o,statusBeforePull:c,statusObservedAtBeforePull:l,hasMessages:(u?.messageOrder.length??0)>0,isTailPage:!i?.before,isStale:i?.isStale})},[r,t,e]),u=(0,Z.useCallback)(async(t,n)=>{await bn();let a=typeof n==`boolean`?n:n?.force,o=typeof n==`object`?n.directory??e:e,s=r.ensureChild(o,{bootstrap:!1}),u=ke.getScopedSdkClient(o);c(t,o);let d=i(t,o);return Sl.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=or(),i=zn(o,t),c=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=ht.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&c&&d.kind!==`unknown`&&p?.status!==`error`&&f&&Rt(o,t)){Di({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!c||f),h=Rl({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await jn(async()=>{let e=await u.session.get({sessionID:t,directory:o});return Il(e,`session.get`),e});if(n.data&&!e()){let r=ir(n.data);e()||zl(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?l(t,{isStale:e,directory:o}):Promise.resolve()])}})},[r,i,c,l,e]),d=(0,Z.useCallback)(async(t,i)=>{let a=i||e;if(!t||!a)return;let o=r.ensureChild(a,{bootstrap:!1}),s=ke.getScopedSdkClient(a),c=await Ol({runtimeKey:n(),directory:a,sessionID:t,request:async()=>{let e=await s.session.children({sessionID:t,directory:a});return Il(e,`session.children`),e.data??[]}});o.setState(e=>{let n=Al(e.session,c,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})},[r,e]),f=(0,Z.useCallback)((t,n)=>{let r=a(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,a]),p=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).loading,[e,a]),m=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).complete,[e,a]),h=(0,Z.useCallback)(t=>{let n=t.directory||e;hi(zn(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;hi(zn(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;hi(zn(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(async(t,n)=>{if(!t)return;await bn();let i=n?.directory??e;if(!i||i===`global`)return;let a=r.ensureChild(i,{bootstrap:!1}),o=a.getState().session_status?.[t]?.type;if(Ml(o))throw Error(`refresh transcript busy`);try{await Wi(i,t),Di({directory:i,sessionID:t,store:a})}catch(e){throw e instanceof Error&&e.message===`refresh transcript busy`?e:Error(`refresh transcript failed`)}},[r,e]);return(0,Z.useMemo)(()=>({ensureSessionRenderable:u,syncSession:u,loadChildren:d,hasMore:f,isLoading:p,isComplete:m,refreshSessionTranscript:v,optimistic:{add:h,remove:g,confirm:_}}),[u,d,f,p,m,v,h,g,_])}var Vl=e=>e===`diff`||e===`plan`||e===`file`||e===`preview-console`||e===`preview-annotation`,Hl=e=>e===`original`||e===`modified`,Ul=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},Wl=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!Vl(t.source))return null;let n=Ul(t.startLine),r=Ul(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:Hl(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()}},Gl=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(Wl).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},Kl=de()(pe(fe((e,t)=>({drafts:{},addDraft:t=>{let n=`icd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,r={...t,id:n,createdAt:Date.now()};return e(e=>{let n=e.drafts[t.sessionKey]??[];return{drafts:{...e.drafts,[t.sessionKey]:[...n,r]}}}),n},updateDraft:(t,n,r)=>{e(e=>{let i=(e.drafts[t]??[]).map(e=>e.id===n?{...e,...r}:e);return{drafts:{...e.drafts,[t]:i}}})},removeDraft:(t,n)=>{e(e=>{let r=(e.drafts[t]??[]).filter(e=>e.id!==n);if(r.length===0){let{[t]:n,...r}=e.drafts;return{drafts:r}}return{drafts:{...e.drafts,[t]:r}}})},clearDrafts:t=>{e(e=>{let{[t]:n,...r}=e.drafts;return{drafts:r}})},getDrafts:e=>t().drafts[e]??[],consumeDrafts:n=>{let r=t().drafts[n]??[];if(r.length===0)return[];let i=[...r].sort((e,t)=>e.createdAt-t.createdAt);return e(e=>{let{[n]:t,...r}=e.drafts;return{drafts:r}}),i},getDraftCount:e=>(t().drafts[e]??[]).length,hasDrafts:e=>(t().drafts[e]??[]).length>0}),{name:`openchamber-inline-comment-drafts`,storage:l(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:Gl(e.drafts)}}),{name:`inline-comment-draft-store`}));function ql(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 Jl(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(ql).join(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-B-3Wg0na.js","assets/rolldown-runtime-C0FnF6B9.js","assets/useUIStore-CJsC3a8g.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-base-ui-CnHfUmDN.js","assets/persistence-DPmGG6sf.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-Bu8y4WEC.js","assets/store-BLmIK6EO.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/utils-DpGCrB3y.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-CstxOD6I.js","assets/dialog-CsFlH6Lj.js","assets/button-CQ8B8MBG.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-X0oilYoj.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-MdrVqcRf.js","assets/platform-CbV34Pzu.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/markdown-worker-BJk0TBYO.js","assets/useEffectiveDirectory-CzRV5a49.js","assets/useMobileNavigationStore-C6clfdA_.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-gi2s2F--.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/useWorkerHighlightedLines-abN0NaM0.js","assets/tooltip-BkJSe4NL.js","assets/vendor-tanstack-react-virtual-tlDgH6PG.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{D as t,E as n,F as r,T as i,W as a,g as o,j as s,t as c,y as l}from"./useUIStore-CJsC3a8g.js";import{$ as u,$t as d,B as f,C as p,Ct as m,Dt as h,G as g,I as _,J as v,K as y,M as b,N as x,Q as S,R as C,S as w,T,U as E,V as D,W as O,Wt as k,Y as A,Z as j,_ as M,at as N,b as P,ct as F,d as I,et as L,ft as R,it as z,j as B,kn as V,lt as H,mt as U,nt as W,ot as ee,pt as G,q as K,r as te,st as ne,u as re,ut as ie,v as ae,wt as oe,x as se,y as ce,yt as le,z as ue}from"./persistence-DPmGG6sf.js";import{a as de,i as fe,r as pe,t as me}from"./vendor-zustand-B4dlGEM2.js";import{c as he,d as ge,f as _e,l as ve,nt as ye,rt as be,tt as xe,u as Se}from"./vendor-base-ui-CnHfUmDN.js";import{At as Ce,Bt as we,Ct as Te,Gt as Ee,Ht as De,Jt as Oe,Nt as ke,Pt as Ae,Rt as je,St as Me,Ut as Ne,Wt as Pe,jt as Fe,kt as Ie,n as Le,qt as Re,t as ze,zt as Be}from"./platform-CbV34Pzu.js";import{a as Ve,n as He,o as Ue}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as We}from"./vendor-react-DLPElpoQ.js";import{i as Ge,n as Ke,s as qe,t as Je}from"./vendor-tanstack-react-query-D7pys_c9.js";import{B as Ye,R as Xe,V as Ze,c as Qe}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{a as $e,d as et,i as tt,l as nt,n as q,o as rt,r as it,u as at}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ot,r as st,t as ct}from"./clipboard-Bu8y4WEC.js";import{i as lt,t as ut}from"./store-BLmIK6EO.js";import{$ as dt,$r as ft,$t as pt,A as mt,Aa as ht,Ai as gt,An as _t,Ao as vt,Ar as yt,B as bt,Ba as xt,Bi as St,Br as Ct,Bt as wt,Ca as Tt,Ci as Et,Cn as Dt,Cr as Ot,Ct as kt,D as At,Di as jt,Dt as Mt,E as Nt,Ei as Pt,Er as Ft,Et as It,F as Lt,Fi as Rt,Fn as zt,Fr as Bt,G as Vt,Ga as Ht,Gr as Ut,Gt as Wt,Ha as Gt,Hi as Kt,Hn as qt,Hr as Jt,Ht as Yt,I as Xt,Ia as Zt,Ii as Qt,In as $t,J as en,Ja as tn,Jr as nn,Jt as rn,K as an,Ka as on,Kr as sn,Kt as cn,L as ln,Li as un,Ln as dn,Lr as fn,M as pn,Ma as mn,Mi as hn,Mr as gn,Mt as _n,N as vn,Ni as yn,No as bn,Nr as xn,Nt as Sn,O as Cn,Oa as wn,Oi as Tn,Ot as En,P as Dn,Pi as On,Pn as kn,Q as An,Qi as jn,Qt as Mn,Ri as Nn,Rt as Pn,S as Fn,Si as In,Sn as Ln,T as Rn,Ta as zn,Ti as Bn,Tr as Vn,Tt as Hn,U as Un,Ua as Wn,Ui as Gn,Un as Kn,Ur as qn,Va as Jn,Vi as Yn,Vr as Xn,Vt as Zn,Wa as Qn,X as $n,Xt as er,Y as tr,Ya as nr,Z as rr,Zi as ir,Zt as ar,_a as or,_i as sr,_n as cr,a as lr,aa as ur,an as dr,at as fr,ba as pr,bi as mr,bn as hr,bo as gr,cn as _r,ct as vr,da as yr,di as br,dn as xr,dt as Sr,ea as Cr,ei as wr,en as Tr,eo as Er,er as Dr,et as Or,f as kr,fa as Ar,fi as jr,fn as Mr,ft as Nr,g as Pr,ga as Fr,gi as Ir,ha as Lr,hi as Rr,hr as zr,ht as Br,i as Vr,ii as Hr,in as Ur,io as Wr,it as Gr,j as Kr,ji as qr,jr as Jr,jt as Yr,k as Xr,ka as Zr,ki as Qr,kr as $r,l as J,la as ei,li as ti,ln as ni,lt as ri,m as ii,ma as ai,mi as oi,n as si,na as ci,ni as li,nn as ui,nr as di,nt as fi,oi as pi,on as mi,pa as hi,pt as gi,q as _i,qa as vi,qi as yi,qt as bi,ri as xi,rn as Si,rr as Ci,rt as wi,sn as Ti,ta as Ei,ti as Di,to as Oi,tr as ki,tt as Ai,ui as ji,un as Mi,ut as Ni,vi as Pi,vn as Fi,vr as Ii,vt as Li,w as Ri,wi as zi,wn as Bi,wr as Vi,wt as Hi,x as Ui,xa as Wi,xi as Gi,xn as Ki,xo as qi,ya as Ji,yt as Yi,z as Xi,za as Zi,zi as Qi,zr as $i,zt as ea}from"./useMobileNavigationStore-C6clfdA_.js";import{n as ta,t as na}from"./AgentAvatar-y3ycseGU.js";import{n as ra,t as Y}from"./utils-DpGCrB3y.js";import{n as X}from"./Icon-CstxOD6I.js";import{a as ia,i as aa,n as oa,o as sa,r as ca,s as la,t as ua}from"./dialog-CsFlH6Lj.js";import{t as da}from"./button-CQ8B8MBG.js";import{E as fa,n as pa}from"./gitApi-CWWLhr6A.js";import{A as ma,C as ha,M as ga,N as _a,O as va,S as ya,T as ba,a as xa,b as Sa,d as Ca,g as wa,h as Ta,i as Ea,j as Da,k as Oa,n as ka,o as Aa,p as ja,s as Ma,u as Na,v as Pa,w as Fa,x as Ia}from"./projectMeta-DLXb99IT.js";import{t as La}from"./input-DVGFeMHA.js";import{i as Ra,n as za,t as Ba}from"./tooltip-BkJSe4NL.js";import{n as Va,t as Ha}from"./useThemeSystem-DMzWVJaW.js";import{D as Ua,E as Wa,M as Ga,N as Ka,O as qa,Q as Ja,S as Ya,U as Xa,V as Za,X as Qa,Y as $a,_ as eo,a as to,f as no,g as ro,h as io,i as ao,m as oo,o as so,p as co,r as lo,t as uo,x as fo,z as po}from"./radio-SaNMUOXT.js";import{i as mo,t as ho}from"./OverlayScrollbar-CW5VL9Qc.js";import{_ as go,a as _o,d as vo,f as yo,g as bo,h as xo,i as So,l as Co,m as wo,n as To,u as Eo,v as Do,x as Oo}from"./markdownTheme-X0oilYoj.js";import{n as ko,r as Ao,t as jo}from"./useRuntimeAPIs-DSLXJybW.js";import{a as Mo,c as No,i as Po,r as Fo,t as Io,u as Lo}from"./appThemeRegistry-MdrVqcRf.js";import{_ as Ro,a as zo,c as Bo,g as Vo,l as Ho,o as Uo,t as Wo,v as Go,y as Ko}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{i as qo,n as Jo,o as Yo,s as Xo,t as Zo}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as Qo,n as $o,t as es}from"./url-DNq-9alX.js";import{_ as ts,l as ns,m as rs,p as is,s as as}from"./markdown-worker-BJk0TBYO.js";import{n as os}from"./useEffectiveDirectory-CzRV5a49.js";import{a as ss,c as cs,d as ls,f as us,i as ds,l as fs,n as ps,r as ms,s as hs,t as gs}from"./FadeInOnReveal-CPfDtuId.js";import{A as _s,C as vs,D as ys,E as bs,M as xs,O as Ss,S as Cs,T as ws,a as Ts,b as Es,c as Ds,f as Os,i as ks,j as As,k as js,l as Ms,m as Ns,n as Ps,o as Fs,p as Is,r as Ls,s as Rs,t as zs,u as Bs,w as Vs,x as Hs}from"./insertionBoundaries-Gxlz7c_q.js";import{A as Us,C as Ws,D as Gs,E as Ks,M as qs,O as Js,S as Ys,T as Xs,a as Zs,b as Qs,c as $s,g as ec,h as tc,i as nc,j as rc,k as ic,o as ac,p as oc,r as sc,s as cc,t as lc,v as uc,w as dc,x as fc,y as pc}from"./useWorkerHighlightedLines-abN0NaM0.js";import{t as mc}from"./vendor-cmdk-CeAGfrLo.js";import{t as hc}from"./sortable-tabs-strip-DuAPHzVT.js";import{n as gc,t as _c}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{i as vc,u as yc}from"./vendor-pierre-diffs-BenIz2TM.js";import{i as bc,t as xc}from"./vendor-framer-motion-DFy_BSVd.js";var Z=e(be(),1),Q=We(),$=ye(),Sc=e(xe(),1),Cc=`openchamber:close-embedded-session-chat`,wc=`openchamber:embedded-visibility`,Tc=`openchamber:embedded-visibility-request`,Ec=e=>new URLSearchParams(e).get(`ocPanel`)===`session-chat`,Dc=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),Oc=(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()},kc=(e,t,n,r,i,a)=>{let o=Dc(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=Oc(n,r,i,a);return e.set(t,{signature:o,src:c}),c},Ac=null,jc=()=>{if(Ac!==null)return Ac;if(typeof window>`u`)return Ac=!1,!1;try{return Ac=new URLSearchParams(window.location.search).get(`ocPanel`)===`session-chat`,Ac}catch{return Ac=!1,!1}},Mc=()=>{if(!jc())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},Nc=Ve(`OpenChamberMedia`);function Pc(){return Le()&&He.getPlatform()===`android`&&He.isPluginAvailable(`OpenChamberMedia`)}async function Fc(e){if(!Pc())return null;let t=await Nc.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 Ic=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},Lc=1e4,Rc=15e3,zc=3e4,Bc=3e4,Vc=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`))}},Lc);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`))},Rc);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`))},Bc),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=Ic(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)}}},zc))}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`,()=>{Vc.cancelAllForRuntimeSwitch()});var Hc=128,Uc=`audio/pcm;rate=16000;bits=16`,Wc=()=>new Promise(e=>setTimeout(e,0)),Gc=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},Kc=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??Uc,this.getStartOptions=e.getStartOptions,this.createDictationId=e.createDictationId??Gc}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<Hc;){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 Wc()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},qc=16e3,Jc=qc,Yc=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},Xc=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},Zc=(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]=Xc(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]=Xc(e[i]*(1-s)+e[o]*s)}return a},Qc=(e,t)=>{if(e.length===0)return t;if(t.length===0)return e;let n=new Int16Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n},$c=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)},el=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),tl=e=>{if(e)try{e.disconnect()}catch{}},nl=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Yc()!==null;function rl(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=el(),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=Yc();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(ol);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=Zc(a,n.sampleRate,qc);for(t.pending=Qc(t.pending,c);t.pending.length>=Jc;){let e=t.pending.slice(0,Jc);t.pending=t.pending.slice(Jc),i.current($c(e))}},e.connect(a),a.connect(o),o.connect(n.destination)}catch(e){let r=e;t.getTracks().forEach(al);try{await n.close()}catch{}throw l.current=el(),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{}tl(e.processor),tl(e.source),tl(e.gain),e.stream&&e.stream.getTracks().forEach(il);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current($c(t)),e.context)try{await e.context.close()}catch{}l.current===e&&(l.current=el())},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 il(e){try{e.stop()}catch{}}function al(e){try{e.stop()}catch{}}function ol(){}var sl=1e3,cl=e=>e instanceof Error?e:Error(String(e)),ll=()=>{let e=Ei.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 ul(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 Kc({client:Vc,getStartOptions:ll});let x=(0,Z.useCallback)(()=>{g.current&&=(clearInterval(g.current),null)},[]),S=(0,Z.useCallback)(()=>{g.current||=setInterval(()=>{l(e=>e+1)},sl)},[]),C=(0,Z.useCallback)(e=>{let t=cl(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)(()=>Vc.onPartial((e,t)=>{let n=b.current?.getDictationId();!n||e!==n||(h.current=t,s(t))}),[]),(0,Z.useEffect)(()=>Vc.subscribeConnectionStatus(e=>{e&&m.current===`recording`&&b.current?.restartStream().catch(e=>{C(e)})}),[C]);let E=rl({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 dl=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},fl=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=Va(),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},pl=e=>{let t=Ei(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},ml=e=>{let t=(0,Q.c)(86),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:s,disabled:l,onInsert:u,onInsertAndSend:d,onActiveChange:f,onContentHeightChange:p,renderTrigger:m,topAccessory:h}=e,g=m===void 0||m,{t:_}=ot(),{currentTheme:v}=Va(),y=Ei(hl),b=c(gl),x;t[0]===b?x=t[1]:(x=Za(Xa(`toggle_dictation`,b)),t[0]=b,t[1]=x);let S=x,[C]=Z.useState(_l),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}=ul(k),H=A===`recording`&&F===`model_download_in_progress`,U=pl(H),W=Z.useRef(A),ee,G;t[7]===A?(ee=t[8],G=t[9]):(ee=()=>{W.current=A},G=[A],t[7]=A,t[8]=ee,t[9]=G),Z.useEffect(ee,G);let K,te;t[10]!==f||t[11]!==A?(K=()=>{f?.(A!==`idle`)},te=[A,f],t[10]=f,t[11]=A,t[12]=K,t[13]=te):(K=t[12],te=t[13]),Z.useLayoutEffect(K,te);let ne,re;t[14]!==L||t[15]!==I?(ne=()=>{let e=()=>{W.current===`idle`?I():W.current===`recording`&&(w.current=`insert`,L())};return window.addEventListener(`openchamber:dictation-toggle`,e),()=>window.removeEventListener(`openchamber:dictation-toggle`,e)},re=[I,L],t[14]=L,t[15]=I,t[16]=ne,t[17]=re):(ne=t[16],re=t[17]),Z.useEffect(ne,re);let ie,ae;t[18]!==R||t[19]!==L||t[20]!==A?(ie=()=>{if(A!==`recording`)return;let e=e=>{if(!e.isComposing){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault(),e.stopPropagation(),w.current=`insert`,L();return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),R())}};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},ae=[A,L,R],t[18]=R,t[19]=L,t[20]=A,t[21]=ie,t[22]=ae):(ie=t[21],ae=t[22]),Z.useEffect(ie,ae);let oe=Z.useRef(null),se=Z.useRef(null),ce=Z.useRef(null),[le,ue]=Z.useState(null),de=A!==`idle`,fe=Z.useRef(p),pe,me;t[23]===p?(pe=t[24],me=t[25]):(pe=()=>{fe.current=p},me=[p],t[23]=p,t[24]=pe,t[25]=me),Z.useEffect(pe,me);let he=Z.useRef(!1),ge;t[26]===de?ge=t[27]:(ge=()=>{if(!de){he.current&&(he.current=!1,fe.current?.(null));return}let e=se.current,t=ce.current;if(!e||!t)return;let n=window.getComputedStyle(e),r=(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0);he.current=!0,fe.current?.(t.offsetHeight+r),e.scrollTop=e.scrollHeight},t[26]=de,t[27]=ge);let _e;t[28]!==P||t[29]!==de||t[30]!==j||t[31]!==A?(_e=[de,j,A,P],t[28]=P,t[29]=de,t[30]=j,t[31]=A,t[32]=_e):_e=t[32],Z.useLayoutEffect(ge,_e);let ve,ye;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(ve=()=>()=>{he.current&&(he.current=!1,fe.current?.(null))},ye=[],t[33]=ve,t[34]=ye):(ve=t[33],ye=t[34]),Z.useEffect(ve,ye);let be,xe;if(t[35]===de?(be=t[36],xe=t[37]):(be=()=>{if(!de)return;let e=oe.current?.closest(`[data-chat-input-footer="true"]`);e&&e.offsetHeight>0&&ue(e.offsetHeight)},xe=[de],t[35]=de,t[36]=be,t[37]=xe),Z.useLayoutEffect(be,xe),!C||!y)return null;let Se=A!==`idle`,Ce;t[38]===L?Ce=t[39]:(Ce=e=>{w.current=e,L()},t[38]=L,t[39]=Ce);let we=Ce,Te;t[40]===z?Te=t[41]:(Te=()=>{w.current=`insert`,z()},t[40]=z,t[41]=Te);let Ee=Te,De;bb0:{if(A===`failed`){De=``;break bb0}if(A===`uploading`){let e;t[42]===_?e=t[43]:(e=_(`chat.dictation.processing`),t[42]=_,t[43]=e),De=e;break bb0}if(H){let e;t[44]!==U||t[45]!==_?(e=U===null?_(`chat.dictation.downloadingModel`):_(`chat.dictation.downloadingModelProgress`,{percent:String(U)}),t[44]=U,t[45]=_,t[46]=e):e=t[46],De=e;break bb0}let e;t[47]===_?e=t[48]:(e=_(`chat.dictation.listening`),t[47]=_,t[48]=e),De=e}let Oe=De,ke;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(ke={onMouseDown:vl,onPointerDownCapture:yl},t[49]=ke):ke=t[49];let Ae=ke,je;t[50]!==S||t[51]!==l||t[52]!==i||t[53]!==o||t[54]!==Se||t[55]!==g||t[56]!==I||t[57]!==_?(je=g?(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:()=>{I()},disabled:l||Se,title:S?`${_(`chat.dictation.start`)} (${S})`:_(`chat.dictation.start`),"aria-label":_(`chat.dictation.start`),children:(0,$.jsx)(X,{name:`mic`,className:Y(o,`text-current`)})}):null,t[50]=S,t[51]=l,t[52]=i,t[53]=o,t[54]=Se,t[55]=g,t[56]=I,t[57]=_,t[58]=je):je=t[58];let Me;t[59]!==B||t[60]!==R||t[61]!==we||t[62]!==v||t[63]!==V||t[64]!==N||t[65]!==P||t[66]!==le||t[67]!==i||t[68]!==a||t[69]!==o||t[70]!==Se||t[71]!==r||t[72]!==H||t[73]!==j||t[74]!==Oe||t[75]!==n||t[76]!==Ee||t[77]!==s||t[78]!==A||t[79]!==_||t[80]!==h||t[81]!==M?(Me=Se?(0,$.jsxs)(`div`,{ref:oe,className:Y(`absolute inset-0 z-50 flex flex-col overflow-x-hidden overflow-y-hidden`,r&&`oc-composer-morph-content-fade`),style:{borderRadius:n,backgroundColor:v.colors.surface.subtle},role:`dialog`,"aria-label":_(`chat.dictation.overlayAria`),children:[h,(0,$.jsx)(`div`,{ref:se,className:Y(`scrollbar-none flex-1 min-h-0 overflow-y-auto px-3`,r?`pt-3.5 pb-2.5`:`pt-5 pb-2`),children:(0,$.jsxs)(`div`,{ref:ce,className:Y(!j&&`translate-y-1.5`),children:[j?(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label whitespace-pre-wrap`,style:{color:v.colors.surface.foreground},children:j}):A===`recording`?(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,style:{color:v.colors.surface.mutedForeground},children:[(0,$.jsx)(fl,{volume:M}),(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,children:Oe})]}):(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,style:{color:v.colors.surface.mutedForeground},children:Oe}),A===`failed`?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.error},children:P||_(`chat.dictation.failed`)}):null,A===`recording`&&P&&!H?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.warning},children:P}):null]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center gap-x-3`,a),style:le?{height:le}:void 0,children:[A===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`relative ml-1 flex h-2 w-2 flex-shrink-0`,"aria-hidden":`true`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full opacity-60`,style:{backgroundColor:v.colors.status.error}}),(0,$.jsx)(`span`,{className:`relative inline-flex h-2 w-2 rounded-full`,style:{backgroundColor:v.colors.status.error}})]}),(0,$.jsx)(fl,{volume:M}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:v.colors.surface.mutedForeground},children:dl(N)})]}):A===`uploading`?(0,$.jsx)(X,{name:`loader-4`,className:`ml-1 h-4 w-4 animate-spin`,style:{color:v.colors.surface.mutedForeground}}):null,(0,$.jsx)(`div`,{className:Y(`ml-auto flex items-center`,r?`gap-x-1`:`gap-x-1.5 md:gap-x-3`),children:A===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...Ae,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:()=>we(`insert`),title:_(`chat.dictation.insert`),"aria-label":_(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...Ae,className:Y(i,`text-primary hover:text-primary`),onClick:()=>we(`send`),title:_(`chat.dictation.insertAndSend`),"aria-label":_(`chat.dictation.insertAndSend`),children:(0,$.jsx)(X,{name:`send-plane-2`,className:s})})]}):A===`uploading`?(0,$.jsx)(`button`,{type:`button`,...Ae,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...Ae,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:V,title:_(`chat.dictation.discard`),"aria-label":_(`chat.dictation.discard`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:Ee,title:_(`chat.dictation.retry`),"aria-label":_(`chat.dictation.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:o})}),j.trim()?(0,$.jsx)(`button`,{type:`button`,...Ae,className:i,onClick:()=>{w.current=`insert`,B()},title:_(`chat.dictation.insert`),"aria-label":_(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}):null]})})]})]}):null,t[59]=B,t[60]=R,t[61]=we,t[62]=v,t[63]=V,t[64]=N,t[65]=P,t[66]=le,t[67]=i,t[68]=a,t[69]=o,t[70]=Se,t[71]=r,t[72]=H,t[73]=j,t[74]=Oe,t[75]=n,t[76]=Ee,t[77]=s,t[78]=A,t[79]=_,t[80]=h,t[81]=M,t[82]=Me):Me=t[82];let Ne;return t[83]!==je||t[84]!==Me?(Ne=(0,$.jsxs)($.Fragment,{children:[je,Me]}),t[83]=je,t[84]=Me,t[85]=Ne):Ne=t[85],Ne};function hl(e){return e.dictationEnabled}function gl(e){return e.shortcutOverrides}function _l(){return!d()&&nl()}function vl(e){return e.preventDefault()}function yl(e){e.pointerType===`touch`&&e.preventDefault()}var bl=2e3,xl=de((e,t)=>({pending:!1,expiresAt:null,arm:(t=bl)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),Sl=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}},Cl=15e3,wl=100,Tl=new Map,El=new Map,Dl=e=>`${e.runtimeKey}\n${e.directory}\n${e.sessionID}`,Ol=e=>{let t=Dl(e),n=e.now??Date.now(),r=El.get(t);if(r&&n-r.loadedAt<Cl)return Promise.resolve(r.sessions);let i=Tl.get(t);if(i)return i;let a=e.request().then(e=>{for(El.delete(t);El.size>=wl;){let e=El.keys().next().value;if(typeof e!=`string`)break;El.delete(e)}return El.set(t,{loadedAt:Date.now(),sessions:e}),e});return Tl.set(t,a),a.then(()=>{Tl.get(t)===a&&Tl.delete(t)},()=>{Tl.get(t)===a&&Tl.delete(t)}),a},kl=(e,t)=>e.id<t.id?-1:+(e.id>t.id),Al=(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(kl)},jl=30;function Ml(e){return e===`busy`||e===`retry`}var Nl=new Map;function Pl(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function Fl(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 Il(e,t){if(!e.error)return;let n=e.response?.status;throw Error(`${t} failed${n?` (${n})`:``}: ${Fl(e.error)}`)}function Ll(e,t){let n=or();if(!n)return!1;let r=n.getTranscript(zn(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>yn()}function Rl(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function zl(e,t,n){let r=[...e.getState().session],i=ht.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function Bl(){let e=xr(),t=wt(),r=Pn(),i=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),a=(0,Z.useCallback)((t,n=e)=>{let r=or();if(!r||!t)return Pl({kind:`unknown`,loadedTurns:0},!1);let i=zn(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return Pl(a.boundary,o?.status===`loading`)},[e]),o=(0,Z.useCallback)((e,t)=>{if(t.length===0)return;let n=r.getChild(e);if(!n)return;let i=n.getState(),a={session_status:{...i.session_status},session_status_observed_at:{...i.session_status_observed_at},session_diff:{...i.session_diff},todo:{...i.todo},permission:{...i.permission},question:{...i.question}};Ln(a,t),Yr(n,t),n.setState(a);for(let n of t)pr(e,n)},[r]),s=(0,Z.useCallback)((t=e)=>{let n=Nl.get(t);if(n)return Nl.delete(t),Nl.set(t,n),n;let r=new Set;for(Nl.set(t,r);Nl.size>jl;){let e=Nl.keys().next().value;if(!e)break;let t=[...Nl.get(e)??[]];Nl.delete(e),o(e,t)}return r},[e,o]),c=(0,Z.useCallback)((n,i=e)=>{let a=i===e?t:r.ensureChild(i,{bootstrap:!1}),c=s(i),l=Dt(a.getState()),u=qr(),d=Bi({seen:c,keep:n,limit:u,preserve:l});if(o(i,d),hn()){let e=new Set([n,...c,...l]),t=(or()?.getCacheBudget?.().listCanonical({directory:i})??[]).map(e=>e.scope.sessionID),r=(t.length>0?t:Array.from(c)).filter(t=>t===n||e.has(t)?!1:Ll(i,t));if(r.length>0){for(let e of r)c.delete(e);o(i,r)}}},[r,e,s,o,t]),l=(0,Z.useCallback)(async(n,i)=>{let a=i?.directory??e;if(!n||!a||a===`global`)return;let o=a===e?t:r.ensureChild(a,{bootstrap:!1}),s=o.getState(),c=s.session_status?.[n],l=s.session_status_observed_at?.[n];try{i?.purpose===`prepend`||i?.before?await Lr(a,n):await ai(a,n)}catch{return}if(i?.isStale?.())return;let u=or()?.getTranscript(zn(a,n));Di({directory:a,sessionID:n,store:o,transcript:u,isStale:i?.isStale}),await xi({directory:a,sessionID:n,store:o,statusBeforePull:c,statusObservedAtBeforePull:l,hasMessages:(u?.messageOrder.length??0)>0,isTailPage:!i?.before,isStale:i?.isStale})},[r,t,e]),u=(0,Z.useCallback)(async(t,n)=>{await bn();let a=typeof n==`boolean`?n:n?.force,o=typeof n==`object`?n.directory??e:e,s=r.ensureChild(o,{bootstrap:!1}),u=ke.getScopedSdkClient(o);c(t,o);let d=i(t,o);return Sl.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=or(),i=zn(o,t),c=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=ht.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&c&&d.kind!==`unknown`&&p?.status!==`error`&&f&&Rt(o,t)){Di({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!c||f),h=Rl({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await jn(async()=>{let e=await u.session.get({sessionID:t,directory:o});return Il(e,`session.get`),e});if(n.data&&!e()){let r=ir(n.data);e()||zl(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?l(t,{isStale:e,directory:o}):Promise.resolve()])}})},[r,i,c,l,e]),d=(0,Z.useCallback)(async(t,i)=>{let a=i||e;if(!t||!a)return;let o=r.ensureChild(a,{bootstrap:!1}),s=ke.getScopedSdkClient(a),c=await Ol({runtimeKey:n(),directory:a,sessionID:t,request:async()=>{let e=await s.session.children({sessionID:t,directory:a});return Il(e,`session.children`),e.data??[]}});o.setState(e=>{let n=Al(e.session,c,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})},[r,e]),f=(0,Z.useCallback)((t,n)=>{let r=a(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,a]),p=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).loading,[e,a]),m=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).complete,[e,a]),h=(0,Z.useCallback)(t=>{let n=t.directory||e;hi(zn(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;hi(zn(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;hi(zn(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(async(t,n)=>{if(!t)return;await bn();let i=n?.directory??e;if(!i||i===`global`)return;let a=r.ensureChild(i,{bootstrap:!1}),o=a.getState().session_status?.[t]?.type;if(Ml(o))throw Error(`refresh transcript busy`);try{await Wi(i,t),Di({directory:i,sessionID:t,store:a})}catch(e){throw e instanceof Error&&e.message===`refresh transcript busy`?e:Error(`refresh transcript failed`)}},[r,e]);return(0,Z.useMemo)(()=>({ensureSessionRenderable:u,syncSession:u,loadChildren:d,hasMore:f,isLoading:p,isComplete:m,refreshSessionTranscript:v,optimistic:{add:h,remove:g,confirm:_}}),[u,d,f,p,m,v,h,g,_])}var Vl=e=>e===`diff`||e===`plan`||e===`file`||e===`preview-console`||e===`preview-annotation`,Hl=e=>e===`original`||e===`modified`,Ul=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},Wl=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!Vl(t.source))return null;let n=Ul(t.startLine),r=Ul(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:Hl(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()}},Gl=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(Wl).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},Kl=de()(pe(fe((e,t)=>({drafts:{},addDraft:t=>{let n=`icd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,r={...t,id:n,createdAt:Date.now()};return e(e=>{let n=e.drafts[t.sessionKey]??[];return{drafts:{...e.drafts,[t.sessionKey]:[...n,r]}}}),n},updateDraft:(t,n,r)=>{e(e=>{let i=(e.drafts[t]??[]).map(e=>e.id===n?{...e,...r}:e);return{drafts:{...e.drafts,[t]:i}}})},removeDraft:(t,n)=>{e(e=>{let r=(e.drafts[t]??[]).filter(e=>e.id!==n);if(r.length===0){let{[t]:n,...r}=e.drafts;return{drafts:r}}return{drafts:{...e.drafts,[t]:r}}})},clearDrafts:t=>{e(e=>{let{[t]:n,...r}=e.drafts;return{drafts:r}})},getDrafts:e=>t().drafts[e]??[],consumeDrafts:n=>{let r=t().drafts[n]??[];if(r.length===0)return[];let i=[...r].sort((e,t)=>e.createdAt-t.createdAt);return e(e=>{let{[n]:t,...r}=e.drafts;return{drafts:r}}),i},getDraftCount:e=>(t().drafts[e]??[]).length,hasDrafts:e=>(t().drafts[e]??[]).length>0}),{name:`openchamber-inline-comment-drafts`,storage:l(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:Gl(e.drafts)}}),{name:`inline-comment-draft-store`}));function ql(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 Jl(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(ql).join(`
|
|
3
3
|
|
|
4
4
|
---
|
|
5
5
|
|
|
@@ -6521,7 +6521,7 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{D as t,E as n,F as r,T
|
|
|
6521
6521
|
`))r.startsWith(`+`)&&!r.startsWith(`+++`)&&t++,r.startsWith(`-`)&&!r.startsWith(`---`)&&n++;return{added:t,removed:n}},Sh=e=>{let t=[],n=new Set;for(let r of e){if(r.type!==`tool`||!vh.has(r.tool))continue;let e=r.state;if(e.status&&e.status!==`completed`)continue;let i=t.length,a=e.metadata,o=Array.isArray(a?.files)?a.files:[];for(let e of o){if(!e||typeof e!=`object`)continue;let i=e,a=i.relativePath||i.filePath||``;!a||n.has(a)||(n.add(a),t.push({path:a,tool:r.tool,partId:r.id,messageID:r.messageID,additions:bh(i.additions)??void 0,deletions:bh(i.deletions)??void 0,patch:typeof i.patch==`string`?i.patch:void 0}))}if(o.length===0&&a?.filediff&&typeof a.filediff==`object`){let e=a.filediff,i=typeof e.file==`string`?e.file:``;i&&!n.has(i)&&(n.add(i),t.push({path:i,tool:r.tool,partId:r.id,messageID:r.messageID,additions:bh(e.additions)??void 0,deletions:bh(e.deletions)??void 0,patch:typeof e.patch==`string`?e.patch:void 0}))}if(o.length===0&&Array.isArray(a?.results))for(let e of a.results){if(!e||typeof e!=`object`)continue;let i=e.filediff;if(!i||typeof i!=`object`)continue;let a=typeof i.file==`string`?i.file:``;!a||n.has(a)||(n.add(a),t.push({path:a,tool:r.tool,partId:r.id,messageID:r.messageID,additions:bh(i.additions)??void 0,deletions:bh(i.deletions)??void 0,patch:typeof i.patch==`string`?i.patch:void 0}))}if(t.length===i){let i=e.input,a=typeof i?.filePath==`string`?i.filePath:typeof i?.file_path==`string`?i.file_path:typeof i?.path==`string`?i.path:void 0;a&&!n.has(a)&&(n.add(a),t.push({path:a,tool:r.tool,partId:r.id,messageID:r.messageID}))}if(t.length===i){let e=typeof a?.patch==`string`?a.patch.trim():typeof a?.diff==`string`?a.diff.trim():``;if(e&&!n.has(`Diff`)){n.add(`Diff`);let i=xh(e);t.push({path:`Diff`,tool:r.tool,partId:r.id,messageID:r.messageID,additions:i.added,deletions:i.removed})}}}return t},Ch=(e,t,n)=>{let r=[];for(let i of e){let e=i.index?.trim()??``,a=i.working_dir?.trim()??``,o=!!(e&&e!==`?`),s=!!(a||e===`?`),c=a||e;if(!c||c===`!`)continue;let l=t?.[i.path];r.push({path:bo(n,i.path),relativePath:i.path,insertions:l?.insertions??0,deletions:l?.deletions??0,status:c,hasStagedChanges:o,hasWorkingChanges:s})}return r},wh=e=>{for(let t of e){let e=t.index?.trim()??``,n=(t.working_dir?.trim()??``)||e;if(!(!n||n===`!`))return!0}return!1},Th=(e,t)=>yo(e,t),Eh=(e,t)=>{let n=yh(e)&&e.relativePath?e.relativePath:Th(e.path,t);return{fileName:n.split(`/`).pop()??n,dirPart:n.includes(`/`)?n.slice(0,n.lastIndexOf(`/`)):``}},Dh=e=>yh(e)?{additions:e.insertions,deletions:e.deletions}:{additions:e.additions??0,deletions:e.deletions??0},Oh=e=>{let t=(0,Q.c)(23),{files:n,currentDirectory:r,onOpenFile:i}=e,{t:a}=ot(),o;t[0]===a?o=t[1]:(o=a(`chat.changedFiles.title`),t[0]=a,t[1]=o);let s;t[2]===o?s=t[3]:(s=(0,$.jsx)(`span`,{className:Ws,children:o}),t[2]=o,t[3]=s);let c;t[4]===n.length?c=t[5]:(c=(0,$.jsx)(`span`,{className:Ys,children:n.length}),t[4]=n.length,t[5]=c);let l;t[6]!==s||t[7]!==c?(l=(0,$.jsxs)(`div`,{className:fc,children:[s,c]}),t[6]=s,t[7]=c,t[8]=l):l=t[8];let u;if(t[9]!==r||t[10]!==n||t[11]!==i||t[12]!==a){let e;t[14]!==r||t[15]!==i||t[16]!==a?(e=(e,t)=>{let{fileName:n,dirPart:o}=Eh(e,r),s=Dh(e);return(0,$.jsxs)(`button`,{type:`button`,className:Y(`relative flex w-full cursor-pointer items-center gap-2.5 outline-hidden select-none text-left hover:bg-interactive-hover`,Xs),title:a(`chat.changedFiles.actions.openFileTitle`,{path:e.path}),onClick:()=>i(e),children:[(0,$.jsx)(Au,{filePath:e.path,className:`h-3 w-3 shrink-0 md:h-3.5 md:w-3.5`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 flex items-baseline overflow-hidden`,title:e.path,children:o?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,style:{direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:o}),(0,$.jsxs)(`span`,{className:`flex-shrink-0`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`/`}),(0,$.jsx)(`span`,{className:`text-foreground`,children:n})]})]}):(0,$.jsx)(`span`,{className:`truncate text-foreground`,children:n})}),s.additions>0||s.deletions>0?(0,$.jsxs)(`span`,{className:`flex-shrink-0 inline-flex items-baseline gap-1 text-xs tabular-nums leading-4 md:text-[0.8125rem] md:leading-5`,children:[s.additions>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,s.additions]}):null,s.deletions>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,s.deletions]}):null]}):null]},`${e.path}:${t}`)},t[14]=r,t[15]=i,t[16]=a,t[17]=e):e=t[17],u=n.map(e),t[9]=r,t[10]=n,t[11]=i,t[12]=a,t[13]=u}else u=t[13];let d;t[18]===u?d=t[19]:(d=(0,$.jsx)(`div`,{className:dc,children:u}),t[18]=u,t[19]=d);let f;return t[20]!==l||t[21]!==d?(f=(0,$.jsxs)($.Fragment,{children:[l,d]}),t[20]=l,t[21]=d,t[22]=f):f=t[22],f},kh=`${Qs} origin-[var(--transform-origin)]`,Ah=Ks,jh=Z.memo(()=>{let e=(0,Q.c)(60),{t}=ot(),[n,r]=Z.useState(!1),i=Z.useRef(null),a=os()??null,o=Z.useContext(Ao),s=Hs(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=Es(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||s!==!0||!u||u.isClean){let t;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[5]=t):t=e[5],m=t;break bb0}let t;e[6]!==a||e[7]!==u.diffStats||e[8]!==u.files?(t=Ch(u.files,u.diffStats,a),e[6]=a,e[7]=u.diffStats,e[8]=u.files,e[9]=t):t=e[9],m=t}let h=m,g=0,_=0;if(e[10]!==g||e[11]!==h||e[12]!==_){for(let e of h)g+=e.insertions,_+=e.deletions;e[10]=g,e[11]=h,e[12]=_,e[13]=g,e[14]=_}else g=e[13],_=e[14];let v;e[15]!==g||e[16]!==_?(v={totalAdded:g,totalRemoved:_},e[15]=g,e[16]=_,e[17]=v):v=e[17];let{totalAdded:y,totalRemoved:b}=v;if(!a||s!==!0||h.length===0)return null;let x;e[18]!==a||e[19]!==d||e[20]!==o?.editor?(x=e=>{if(!a||!yh(e))return;r(!1);let t=e.path;if(d){d.openChanges({diffPath:e.relativePath,staged:e.hasStagedChanges&&!e.hasWorkingChanges});return}let n=o?.editor;if(n){n.openFile(t);return}let i=c.getState(),s=e.hasStagedChanges&&!e.hasWorkingChanges;if(!i.isMobile){i.openContextDiff(a,e.relativePath,s);return}i.navigateToDiff(e.relativePath,s),i.setRightSidebarOpen(!1)},e[18]=a,e[19]=d,e[20]=o?.editor,e[21]=x):x=e[21];let S=x,C=h.length,w;e[22]!==C||e[23]!==t?(w=t(C===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:C}),e[22]=C,e[23]=t,e[24]=w):w=e[24];let T=w,E,D;e[25]===Symbol.for(`react.memo_cache_sentinel`)?(E=Y(Gs,`max-w-full text-left`),D=()=>r(Mh),e[25]=E,e[26]=D):(E=e[25],D=e[26]);let O,k;e[27]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(X,{name:`file-edit`,className:Js}),O=Y(ic,`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`,ic),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(Us,`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:Js}):(0,$.jsx)(X,{name:`arrow-down-s`,className:Js}),e[44]=n,e[45]=R);let z;e[46]!==n||e[47]!==A||e[48]!==N||e[49]!==L||e[50]!==R?(z=(0,$.jsxs)(`button`,{type:`button`,className:E,onClick:D,"aria-expanded":n,children:[k,A,N,L,R]}),e[46]=n,e[47]=A,e[48]=N,e[49]=L,e[50]=R,e[51]=z):z=e[51];let B;e[52]!==a||e[53]!==h||e[54]!==S||e[55]!==n?(B=n&&(0,$.jsx)(`div`,{style:Ah,className:Y(kh,`absolute left-0 bottom-full mb-1 z-50`,`animate-in fade-in-0 zoom-in-95 slide-in-from-bottom-2`,`duration-150`),children:(0,$.jsx)(Oh,{files:h,currentDirectory:a,onOpenFile:S})}),e[52]=a,e[53]=h,e[54]=S,e[55]=n,e[56]=B):B=e[56];let V;return e[57]!==z||e[58]!==B?(V=(0,$.jsxs)(`div`,{className:`relative`,ref:i,children:[z,B]}),e[57]=z,e[58]=B,e[59]=V):V=e[59],V});jh.displayName=`PendingChangesBar`;function Mh(e){return!e}var Nh=Z.createContext(`default`),Ph=()=>Z.useContext(Nh),Fh=500,Ih=e=>{let t=(0,Q.c)(30),{onCycleAgent:n,onOpenAgentPanel:r,className:i,agentName:a,agents:o,disabled:s}=e,c;t[0]===o?c=t[1]:(c=o===void 0?[]:o,t[0]=o,t[1]=c);let l=c,u=s!==void 0&&s,d=a??void 0,f;t[2]!==l||t[3]!==d?(f=Gt(l,d),t[2]=l,t[3]=d,t[4]=f):f=t[4];let p=f,m=Dp(d),h;t[5]===d?h=t[6]:(h=ta(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()},Fh))},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`,Np,i),t[16]=i,t[17]=D);let O;t[18]!==g.var||t[19]!==p||t[20]!==d||t[21]!==m?(O=(0,$.jsx)(Ep,{name:d,label:p,revealed:m,avatarSize:16,slotClassName:`h-6 w-6`,colorVar:g.var}),t[18]=g.var,t[19]=p,t[20]=d,t[21]=m,t[22]=O):O=t[22];let k;return t[23]!==p||t[24]!==u||t[25]!==b||t[26]!==S||t[27]!==D||t[28]!==O?(k=(0,$.jsx)(`button`,{type:`button`,disabled:u,onPointerDown:b,onPointerUp:S,onPointerLeave:w,onContextMenu:Lh,onMouseDown:Rh,className:D,title:p,"aria-label":p,children:O}),t[23]=p,t[24]=u,t[25]=b,t[26]=S,t[27]=D,t[28]=O,t[29]=k):k=t[29],k};function Lh(e){return e.preventDefault()}function Rh(e){return e.preventDefault()}var zh=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=Qn(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()?Jn(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)(Oa,{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:Bh,onPointerDownCapture:Vh,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 Bh(e){return e.preventDefault()}function Vh(e){e.preventDefault()}var Hh={phase:`idle`,isWorking:!1,isBusy:!1,isCooldown:!1};function Uh(e,t){let n=(0,Q.c)(3),r=dr(e??``,t),i=mi(e??``,t),a=Tr(e??``,t),o=Si(e??``,t),s=Ur(e??``,t),c=Ti(t),l;bb0:{if(!e){l=Hh;break bb0}if(o.length>0||s.length>0){l=Hh;break bb0}let t=r?.type??`idle`,u=a[a.length-1],d=!!(u&&u.role===`assistant`&&typeof u.time?.completed!=`number`),f=u?.time?.created,p=!!(d&&typeof c==`number`&&typeof f==`number`&&f<=c),m=r!==void 0,h=m&&t!==`idle`,g=h||d&&!p;if(m&&!h&&(!d||m&&!h&&typeof i==`number`&&typeof f==`number`&&f<=i)){l=Hh;break bb0}if(!g){l=Hh;break bb0}let _=h?t:`busy`,v=t===`busy`||!h&&d,y;n[0]!==_||n[1]!==v?(y={phase:_,isWorking:!0,isBusy:v,isCooldown:!1},n[0]=_,n[1]=v,n[2]=y):y=n[2],l=y}return l}var Wh=e=>e.nativeEvent.isComposing||e.nativeEvent.keyCode===229;function Gh(e){let t=(0,Q.c)(4),n,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`path`,{d:`M208,56V200a8,8,0,0,1-8,8H56a8,8,0,0,1-8-8V56a8,8,0,0,1,8-8H200A8,8,0,0,1,208,56Z`,opacity:`0.2`}),r=(0,$.jsx)(`path`,{d:`M200,40H56A16,16,0,0,0,40,56V200a16,16,0,0,0,16,16H200a16,16,0,0,0,16-16V56A16,16,0,0,0,200,40Zm0,160H56V56H200V200Z`}),t[0]=n,t[1]=r):(n=t[0],r=t[1]);let i;return t[2]===e?i=t[3]:(i=(0,$.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,fill:`currentColor`,viewBox:`0 0 256 256`,...e,children:[n,r]}),t[2]=e,t[3]=i),i}var Kh=e=>!(!e.sessionId||e.composerSurfaceKind===`secondary`||e.hasSessionEntity||e.hasRenderableSessionSnapshot),qh=e=>{let t=e.isSubagentSession&&!e.allowPromptingSubagentSessions;return{showReadOnlyBanner:e.isSubagentSession&&(e.readOnly||t),blockSubmission:e.sessionIdentityPending}},Jh=(e,t)=>({agentName:t.agentName??e?.agentName,providerId:t.providerId??e?.providerId,modelId:t.modelId??e?.modelId}),Yh=(e,t)=>e.id===t.id&&e.directory===t.directory,Xh=(e,t)=>e.agentName===t.agentName&&e.providerId===t.providerId&&e.modelId===t.modelId,Zh=(e,t,n,r)=>{if(!t)return null;let i=n??(e?.viewKey===t?e.parentTarget:null);if(!i)return null;let a=Jh(e?.viewKey===t?e.execution:void 0,r);return e&&e.viewKey===t&&Yh(e.parentTarget,i)&&Xh(e.execution,a)?e:{viewKey:t,parentTarget:i,execution:a}},Qh=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`}},$h=`data-mobile-overlay-active`,eg=e=>Array.from(e).some(e=>e.getAttribute($h)!==`false`),tg=`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(`.`),ng=`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 rg(){return`${tg[Math.floor(Math.random()*tg.length)]}-${ng[Math.floor(Math.random()*ng.length)]}`}function ig(e){let t=rg();return e&&e.trim()?`${e.trim().replace(/\/+$/,``)}/${t}`:t}var ag=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||e,og=e=>({agentName:e.currentAgentName,providerId:e.currentProviderId,modelId:e.currentModelId,variant:e.currentVariant}),sg=(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))},cg=async(e,t)=>{await dn(e)&&await Dr(t)},lg=e=>{let t=ag(e),n=qi.getState().projects;if(n.length===0)return null;let r=qi.getState().getActiveProject();if(r?.path){let e=ag(r.path);if(t===e||t.startsWith(`${e}/`))return{id:r.id,path:r.path}}let i=n.filter(e=>{let n=ag(e.path);return t===n||t.startsWith(`${n}/`)}).sort((e,t)=>ag(t.path).length-ag(e.path).length)[0];return i?{id:i.id,path:i.path}:null},ug=!1,dg=async(e,t)=>{try{let n=qi.getState().projects.find(e=>e.id===t.id)??qi.getState().projects.find(e=>ag(e.path)===ag(t.path)),r=Cr(t.path);await Ei.getState().activateDirectory(t.path,{source:`worktreeSessionCreator`});let i=Ei.getState();if(i.activeDirectoryKey!==r||i.providers.length===0||i.agents.length===0)return;i.applyDefaultModelAgentSelection({projectDefaultModel:n?.defaultModel??void 0}),sg(e,og(Ei.getState()),xt.getState())}catch{}},fg=async(e,t,n)=>{let r=J.getState(),i=Ei.getState();r.initializeNewOpenChamberSession(e,i.agents),r.setSessionDirectory(e,t.path),r.setWorktreeMetadata(e,t),await dg(e,n),Te.getState().setDirectory(t.path,{showOverlay:!1})},pg=e=>e.trim().replace(/^remotes\//,``).replace(/[^A-Za-z0-9._/-]+/g,`-`).replace(/\/+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`worktree`,mg=async e=>{if(ug)return null;let t=qi.getState().getActiveProject(),n=e?.projectDirectory?.trim()||t?.path;if(!n)return Ii.error(`No active project`,{description:`Please select a project first.`}),null;let r=lg(n)??(t?.path?{id:t.id,path:t.path}:null);if(!r)return Ii.error(`No active project`,{description:`Please select a project first.`}),null;let i=!1;try{i=await pa(r.path)}catch{}if(!i)return Ii.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;ug=!0;try{let t=ki(),n=e?.existingBranch?.trim().replace(/^remotes\//,``)||``,i=n?pg(n):ig(),a=n?`existing`:`new`,o=J.getState();o.newSessionDraft?.open?o.overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:o.newSessionDraft.directoryOverride??r.path,pendingWorktreeRequestId:t,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}):o.openNewSessionDraft({selectedProjectId:r.id,directoryOverride:r.path,pendingWorktreeRequestId:t,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt});let s=await fa(r.path,{mode:a,...a===`new`?{branchName:i,worktreeName:i}:{existingBranch:n,worktreeName:i}}).catch(()=>null);s?.path&&(J.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:s.path,pendingWorktreeRequestId:t,bootstrapPendingDirectory:s.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),Te.getState().setDirectory(s.path,{showOverlay:!1}));let c=await $t(r),l=await Ds(r,{preferredName:i,mode:a,worktreeName:i,setupCommands:c,returnAfterDirectoryCreated:!0,...a===`new`?{branchName:i}:{existingBranch:n}});return Ci(t,l.path),J.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:l.path,pendingWorktreeRequestId:null,bootstrapPendingDirectory:l.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),Te.getState().setDirectory(l.path,{showOverlay:!1}),l.path}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree`,n=J.getState().newSessionDraft.pendingWorktreeRequestId;return n&&(di(n,e instanceof Error?e:Error(t)),J.getState().resolvePendingDraftWorktreeTarget(n,null)),J.getState().setDraftBootstrapPendingDirectory(null),Ii.error(`Failed to create worktree`,{description:t}),null}finally{ug=!1}};async function hg(){return mg()}async function gg(e){let t=e.branch?.trim();return t?mg({existingBranch:t,projectDirectory:e.projectDirectory,initialPrompt:e.initialPrompt,title:e.title}):null}async function _g(e,t,n,r){if(ug)return null;ug=!0;try{let i=n?.trim()||`HEAD`,a=t?.trim();if(!a)throw Error(`Branch name is required`);let o=r?.kind??`standard`,s=lg(e);if(!s)throw Error(`Project is not registered in OpenChamber`);let c=!1;try{c=await pa(s.path)}catch{}if(!c)return Ii.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;let l=await $t(s),u=await ja(s.path);try{let e=await Ds(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 cg(s,e.path);let n=await J.getState().createSession(void 0,e.path);if(!n)throw await Na(s,e,{deleteLocalBranch:!0}).catch(()=>void 0),Error(`Could not create a session for the worktree.`);return await fg(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 Ii.error(`Failed to create worktree`,{description:t}),null}}finally{ug=!1}}var vg=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},yg=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 bg({open:e,onOpenChange:t,mode:n=`createSession`,onSelect:r}){let{t:i}=ot(),{github:a}=ko(),o=no(),s=o.data??null,l=o.isFetched,u=c(e=>e.setSettingsDialogOpen),d=c(e=>e.setSettingsPage),f=c(e=>e.isMobile),{isTablet:p}=mo(),m=f||p,h=qi(e=>e.getActiveProject()),g=Te(e=>e.currentDirectory),_=Z.useMemo(()=>h?.path?.trim()||g?.trim()||null,[h?.path,g]),[v,y]=Z.useState(``),[b,x]=Z.useState(!1),[S,C]=Z.useState(null),w=Z.useRef(0),T=Z.useMemo(()=>vg(v),[v]),E=xs(v,350),D=T?``:E.trim(),O=!!T||v===E,k=e&&O&&!!_&&!!a?.issuesList&&!(l&&s?.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);Ii.error(i(`session.githubIssuePicker.toast.loadMoreFailed`),{description:t})}},[A,i]);Z.useEffect(()=>{e||(++w.current,y(``),x(!1),C(null))},[e]),Z.useEffect(()=>{++w.current},[e,_]);let B=!l||s?.connected!==!1&&j?.connected!==!1,V=j?.repo?.url??null,H=Z.useCallback(()=>{d(`github`),u(!0)},[u,d]),U=Z.useCallback(()=>{let e=Ei.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=Ei.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=Zt(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=Ei.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(!_){Ii.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){Ii.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){Ii.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){Ii.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let s=n.issue;if(!s){Ii.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let l=await a.issueComments(_,e,{sourceRepo:o});if(!c())return;if(l.connected===!1){Ii.error(i(`session.githubIssuePicker.error.notConnected`));return}let u=l.comments??[],d=yg({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);Ii.error(i(`session.githubIssuePicker.toast.loadIssueDetailsFailed`),{description:t})}finally{c()&&C(null)}return}if(!_){Ii.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){Ii.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){Ii.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){Ii.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let r=n.issue;if(!r){Ii.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let s=await a.issueComments(_,e,{sourceRepo:o});if(!c())return;if(s.connected===!1){Ii.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}-${rg()}`,t=await _g(_,e,void 0,{returnAfterDirectoryCreated:!0});if(!t?.id)throw Error(`Failed to create worktree session`);return{sessionId:t.id,sessionDirectory:t.path}}let e=await Ct(u,_,null);if(!e?.id)throw Error(`Failed to create session`);return{sessionId:e.id,sessionDirectory:e.directory??_}})();if(!c())return;ft(d,u).catch(()=>void 0);try{J.getState().initializeNewOpenChamberSession(d,Ei.getState().agents)}catch{}t(!1);let f=Ei.getState(),p=xt.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){Ii.error(i(`session.githubIssuePicker.error.noModelSelected`));return}let y=ee(h,g),x=await yi(`github.issue.review.visible`,{issue_number:String(r.number)});if(!c())return;let S=await yi(`github.issue.review.instructions`);if(!c())return;let C=yg({repo:n.repo,issue:r,comments:l});J.getState().sendMessage(x,h,g,v,void 0,void 0,[{text:S,synthetic:!0},{text:C,synthetic:!0}],y,void 0,{sessionId:d}).catch(e=>{let t=e instanceof Error?e.message:String(e);Ii.error(i(`session.githubIssuePicker.toast.sendContextFailed`),{description:t})}),Ii.success(i(`session.githubIssuePicker.toast.sessionCreated`))}catch(e){if(!c())return;let t=e instanceof Error?e.message:String(e);Ii.error(i(`session.githubIssuePicker.toast.startSessionFailed`),{description:t})}finally{c()&&C(null)}}},[b,a,n,t,r,_,U,W,ee,S,i]),K=i(n===`select`?`session.githubIssuePicker.title.select`:`session.githubIssuePicker.title.createSession`),te=i(n===`select`?`session.githubIssuePicker.description.select`:`session.githubIssuePicker.description.createSession`),ne=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(La,{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)(da,{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)(da,{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)(da,{variant:`outline`,size:`sm`,onClick:R,disabled:P||!!S,children:i(`session.githubIssuePicker.actions.refresh`)})]})]})]})]});return f?(0,$.jsx)(Cp,{open:e,title:K,onClose:()=>t(!1),renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:K}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:te})]}),children:ne}):(0,$.jsx)(ua,{open:e,onOpenChange:t,children:(0,$.jsxs)(oa,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(ia,{className:`flex-shrink-0`,children:[(0,$.jsxs)(sa,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),K]}),(0,$.jsx)(ca,{children:te})]}),ne]})})}var xg=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},Sg=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function Cg({open:e,onOpenChange:t,onSelect:n}){let{t:r}=ot(),{github:i}=ko(),a=no(),o=a.data??null,s=a.isFetched,l=c(e=>e.setSettingsDialogOpen),u=c(e=>e.setSettingsPage),d=c(e=>e.isMobile),{isTablet:f}=mo(),p=d||f,m=qi(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(()=>xg(h),[h]),C=xs(h,350),w=S?``:C.trim(),T=!!S||h===C,E=e&&T&&!!m&&!!i?.prsList&&!(s&&o?.connected===!1),D=Je({queryKey:I.scoped(`github-prs`,m,w),enabled:E,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>i.prsList(m,{page:e,...w?{query:w}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),O=T?D.data?.pages.at(-1)??null:null,k=T?D.data?.pages.flatMap(e=>e.prs??[])??[]:[],A=T&&D.hasNextPage,j=!S&&!T||D.isLoading,M=T&&D.isFetchingNextPage,N=T&&D.error?D.error instanceof Error?D.error.message:String(D.error):null,P=q(async()=>{try{await D.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);Ii.error(r(`session.githubPrPicker.toast.loadMoreFailed`),{description:t})}});Z.useEffect(()=>{e||(++x.current,g(``),v(!1),b(null))},[e]),Z.useEffect(()=>{++x.current},[e,m]);let F=!s||o?.connected!==!1&&O?.connected!==!1,L=q(()=>{u(`github`),l(!0)}),R=q(async(e,a)=>{if(!m){Ii.error(r(`session.githubPrPicker.error.noActiveProject`));return}if(!i?.prContext){Ii.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){Ii.error(r(`session.githubPrPicker.error.notConnected`));return}if(!o.pr){Ii.error(r(`session.githubPrPicker.error.prNotFound`));return}if(!o.repo){Ii.error(r(`session.githubPrPicker.error.repoNotResolvable`),{description:r(`session.githubPrPicker.error.repoMustBeGithub`)});return}if(n){let e=await yi(`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:Sg(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);Ii.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)(La,{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)(_a,{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)(da,{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)(Cp,{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)(ua,{open:e,onOpenChange:t,children:(0,$.jsxs)(oa,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(ia,{className:`flex-shrink-0`,children:[(0,$.jsxs)(sa,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),z]}),(0,$.jsx)(ca,{children:B})]}),V]})})}function wg(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)(mc,{"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 Tg=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)(mc.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});Tg.displayName=`CommandInput`;function Eg(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)(ma,{as:mc.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 Dg(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)(mc.Empty,{"data-slot":`command-empty`,className:`py-6 text-center typography-ui-label`,...n}),t[2]=n,t[3]=r),r}function Og(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)(mc.Group,{"data-slot":`command-group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function kg(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)(mc.Separator,{"data-slot":`command-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Ag(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Y(`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)(mc.Item,{"data-slot":`command-item`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var jg=(e,t)=>`${e}:${T(t)}`,Mg=e=>e.type===`skill`||!se(e.name);function Ng(e){let{t}=ot(),n=Z.useMemo(()=>d(),[]),r=c(e=>e.globalDraftStarters),i=qi(e=>e.activeProjectId),a=qi(e=>e.projects),o=Z.useMemo(()=>{if(!i)return null;let e=a.find(e=>e.id===i);return e?.path?{id:e.id,path:e.path}:null},[i,a]),[s,l]=Z.useState([]),u=Z.useMemo(()=>r??ce,[r]),f=u.some(Mg)||s.some(Mg),m=gr({directory:e,enabled:f}),h=Z.useMemo(()=>m.data??[],[m.data]),{refetch:g}=m,_=Wr({directory:e,enabled:f}),v=Z.useMemo(()=>_.data??[],[_.data]),{refetch:y}=_;Z.useEffect(()=>{let e=!1;if(!o){l([]);return}return kn(o).then(t=>{e||l(t)}).catch(()=>{e||l([])}),()=>{e=!0}},[o?.id]);let b=Z.useCallback(()=>{g(),y()},[g,y]),x=Z.useMemo(()=>new Set(h.map(e=>e.name)),[h]),S=Z.useMemo(()=>new Set(v.map(e=>e.name)),[v]),C=Z.useCallback((e,r)=>{if(n&&e.type===`command`&&e.name===`craft-goal`)return null;if(e.type===`command`){let n=se(e.name);return n?{id:jg(r,e),ref:e,group:r,label:t(n.labelKey),icon:n.icon,submitText:n.command}:x.has(e.name)?{id:jg(r,e),ref:e,group:r,label:w(e.name),icon:ae,submitText:`/${e.name}`}:null}return S.has(e.name)?{id:jg(r,e),ref:e,group:r,label:w(e.name),icon:P,submitText:`/${e.name}`}:null},[t,x,S,n]),E=Z.useMemo(()=>u.map(e=>C(e,`global`)).filter(e=>e!==null),[u,C]),D=Z.useMemo(()=>s.map(e=>C(e,`project`)).filter(e=>e!==null),[s,C]),O=Z.useMemo(()=>{let e=new Set;for(let t of u)e.add(T(t));for(let t of s)e.add(T(t));return e},[u,s]),k=Z.useMemo(()=>{let e=[];for(let r of M)n&&r.name===`craft-goal`||e.push({type:`command`,name:r.name,label:t(r.labelKey),icon:r.icon,section:`built-in`,scope:`user`});for(let t of h)t.isBuiltIn||t.source===`skill`||se(t.name)||e.push({type:`command`,name:t.name,label:w(t.name),icon:ae,section:`command`,scope:t.scope===`project`?`project`:`user`});for(let t of v)e.push({type:`skill`,name:t.name,label:w(t.name),icon:P,section:`skill`,scope:t.scope===`project`?`project`:`user`});return e.filter(e=>!O.has(`${e.type}:${e.name}`))},[t,h,v,O,n]),A=Z.useCallback(e=>{c.getState().setGlobalDraftStarters(e),te({draftStarters:e})},[]),j=Z.useCallback(e=>{l(e),o&&qt(o,e)},[o]),N=Z.useCallback(e=>{let t={type:e.type,name:e.name};if(e.scope===`project`){if(!o||s.some(e=>p(e,t)))return;j([...s,t])}else{let e=r??ce;if(e.some(e=>p(e,t)))return;A([...e,t])}},[o,s,r,j,A]),F=Z.useCallback((e,t)=>{e===`project`?j(s.filter(e=>!p(e,t))):A((r??ce).filter(e=>!p(e,t)))},[s,r,j,A]),I=Z.useCallback((e,t,n)=>{let i=e===`project`?s:r??ce,a=i.findIndex(n=>jg(e,n)===t),o=i.findIndex(t=>jg(e,t)===n);if(a<0||o<0||a===o)return;let c=Jo([...i],a,o);e===`project`?j(c):A(c)},[s,r,j,A]);return{global:E,project:D,pinnable:k,hasProject:!!o,ensureLoaded:b,addStarter:N,removeStarter:F,reorder:I}}var Pg=`__draft-starter-trash__`,Fg=`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`,Ig=`max-h-7`,Lg=[{key:`built-in`,headingKey:`chat.draftStarters.sectionBuiltIn`},{key:`command`,headingKey:`chat.draftStarters.sectionCommands`},{key:`skill`,headingKey:`chat.draftStarters.sectionSkills`}],Rg=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}=Yo(s),m;t[2]===d?m=t[3]:(m=Ko.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},zg=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(Wg),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)(Rg,{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)(Zo,{items:o,strategy:qo,children:s}),t[11]=o,t[12]=s,t[13]=c):c=t[13],c},Bg=()=>{let e=(0,Q.c)(13),{t}=ot(),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={id:Pg},e[0]=n):n=e[0];let{setNodeRef:r,isOver:i}=Vo(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(Fg,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},Vg=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)(Tg,{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)(Dg,{children:l}),t[8]=l,t[9]=u);let d;t[10]!==r||t[11]!==n||t[12]!==a?(d=Lg.map(e=>{let t=n.filter(t=>t.section===e.key);return t.length===0?null:(0,$.jsx)(Og,{heading:a(e.headingKey),children:t.map(e=>(0,$.jsx)(Ag,{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)(Eg,{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)(wg,{className:o,children:[c,f]}),t[17]=o,t[18]=c,t[19]=f,t[20]=p):p=t[20],p},Hg=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)(la,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:u,className:Fg,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)(ia,{className:`px-4 pb-2 pt-4 text-left`,children:(0,$.jsx)(sa,{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)(Vg,{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)(oa,{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)(ua,{open:o,onOpenChange:c,children:[f,_]}),t[22]=o,t[23]=c,t[24]=_,t[25]=f,t[26]=v):v=t[26],v},Ug=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}=Ng(os()),{isMobile:f}=mo(),[p,m]=Z.useState(!1),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),y=Z.useRef(null),b;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(b={activationConstraint:{distance:8}},t[0]=b):b=t[0];let x;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(x={activationConstraint:{delay:200,tolerance:6}},t[1]=x):x=t[1];let S=Go(Ro(Uo,b),Ro(Bo,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)===Pg){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:zo.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&&Ig,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)(zg,{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)(zg,{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(Gg),"aria-expanded":h,"aria-label":i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),title:i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),className:Fg,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)(Bg,{}):(0,$.jsx)(Hg,{pinnable:s,onOpen:c,onAdd:l}),t[46]=l,t[47]=c,t[48]=p,t[49]=f,t[50]=s,t[51]=G):G=t[51];let K;t[52]!==ee||t[53]!==G?(K=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 self-start`,children:[ee,G]}),t[52]=ee,t[53]=G,t[54]=K):K=t[54];let te;t[55]!==R||t[56]!==W||t[57]!==K?(te=(0,$.jsxs)(`div`,{className:R,children:[W,K]}),t[55]=R,t[56]=W,t[57]=K,t[58]=te):te=t[58];let ne;return t[59]!==F||t[60]!==S||t[61]!==te?(ne=(0,$.jsx)(Wo,{sensors:S,collisionDetection:Ho,measuring:L,onDragStart:j,onDragCancel:N,onDragEnd:F,children:te}),t[59]=F,t[60]=S,t[61]=te,t[62]=ne):ne=t[62],ne};function Wg(e){return e.id}function Gg(e){return!e}var Kg=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});Kg.displayName=`ChatComposerSurface`;var qg=Z.forwardRef((e,t)=>{let n=(0,Q.c)(3),r;return n[0]!==e||n[1]!==t?(r=(0,$.jsx)(Aa,{ref:t,...e}),n[0]=e,n[1]=t,n[2]=r):r=n[2],r});qg.displayName=`ChatPromptTextarea`;var Jg=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},Yg=(e,t)=>{typeof e==`function`?e(t):e&&(e.current=t)},Xg=e=>{let t=(0,Q.c)(139),n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M,N,P,F,I,L,R,z,B;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5],s=t[6],c=t[7],l=t[8],u=t[9],d=t[10],f=t[11],p=t[12],m=t[13],h=t[14],g=t[15],_=t[16],v=t[17],y=t[18],b=t[19],x=t[20],S=t[21],C=t[22],w=t[23],T=t[24],E=t[25],D=t[26],O=t[27],k=t[28],A=t[29],j=t[30],M=t[31],N=t[32],P=t[33],F=t[34],I=t[35],L=t[36],R=t[37],z=t[38],B=t[39]):({value:B,attachments:j,disabled:M,pending:N,placeholder:T,isMobile:P,onChange:x,onSubmit:w,onStop:C,onAddFiles:b,onRemoveAttachment:S,addFilesLabel:n,removeAttachmentLabel:E,sendLabel:O,stopLabel:k,hint:f,leftControls:y,rightControls:D,footerContent:c,inputHeader:m,attachmentContent:r,highlightedContent:d,highlightRef:u,inputRef:g,textareaProps:z,textLayoutClassName:R,inputClassName:p,inputOuterClassName:h,inputStyle:v,footerClassName:s,footerStyle:l,contentClassName:o,inputSectionClassName:_,autoResize:F,disableInputWhilePending:I,children:i,className:a,expanded:L,...A}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o,t[6]=s,t[7]=c,t[8]=l,t[9]=u,t[10]=d,t[11]=f,t[12]=p,t[13]=m,t[14]=h,t[15]=g,t[16]=_,t[17]=v,t[18]=y,t[19]=b,t[20]=x,t[21]=S,t[22]=C,t[23]=w,t[24]=T,t[25]=E,t[26]=D,t[27]=O,t[28]=k,t[29]=A,t[30]=j,t[31]=M,t[32]=N,t[33]=P,t[34]=F,t[35]=I,t[36]=L,t[37]=R,t[38]=z,t[39]=B);let V=j===void 0?[]:j,H=M!==void 0&&M,U=N!==void 0&&N,W=P!==void 0&&P,ee=F===void 0||F,G=I===void 0||I,K=L!==void 0&&L,te=Z.useRef(null),ne=Z.useRef(null),re;t[40]!==ee||t[41]!==K||t[42]!==z?.fillContainer?(re=()=>{if(!ee||K||z?.fillContainer)return;let e=te.current;if(!e)return;e.style.height=`auto`;let t=Number.parseFloat(window.getComputedStyle(e).maxHeight),n=Number.isFinite(t)?Math.min(e.scrollHeight,t):e.scrollHeight;e.style.height=`${n}px`,e.style.overflowY=Number.isFinite(t)&&e.scrollHeight>t?`auto`:`hidden`},t[40]=ee,t[41]=K,t[42]=z?.fillContainer,t[43]=re):re=t[43];let ie=z?.fillContainer,ae;t[44]!==ee||t[45]!==K||t[46]!==ie||t[47]!==B?(ae=[ee,K,ie,B],t[44]=ee,t[45]=K,t[46]=ie,t[47]=B,t[48]=ae):ae=t[48],Z.useLayoutEffect(re,ae);let oe;t[49]!==G||t[50]!==H||t[51]!==w||t[52]!==U||t[53]!==z?(oe=e=>{z?.onKeyDown?.(e),!(e.defaultPrevented||Wh(e))&&e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),!H&&(!U||!G)&&w())},t[49]=G,t[50]=H,t[51]=w,t[52]=U,t[53]=z,t[54]=oe):oe=t[54];let se=oe,ce;t[55]===b?ce=t[56]:(ce=e=>{b?.(e.target.files),e.target.value=``},t[55]=b,t[56]=ce);let le=ce,ue=B.trim().length>0||V.length>0,de=V.filter(Zg),fe;t[57]!==n||t[58]!==H||t[59]!==le||t[60]!==b||t[61]!==U?(fe=b?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{ref:ne,type:`file`,accept:`image/*`,multiple:!0,className:`hidden`,onChange:le}),(0,$.jsx)(`button`,{type:`button`,className:`flex size-8 shrink-0 items-center justify-center rounded-md text-foreground outline-none hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-40`,onClick:()=>ne.current?.click(),disabled:H||U,"aria-label":n,children:(0,$.jsx)(X,{name:`attachment-2`,className:`size-[18px]`})})]}):null,t[57]=n,t[58]=H,t[59]=le,t[60]=b,t[61]=U,t[62]=fe):fe=t[62];let pe=fe,me;t[63]!==H||t[64]!==ue||t[65]!==C||t[66]!==U||t[67]!==O||t[68]!==k?(me=U&&C?(0,$.jsx)(`button`,{type:`button`,className:`flex size-8 shrink-0 items-center justify-center rounded-md text-[var(--status-error)] outline-none hover:bg-[var(--interactive-hover)]`,onClick:C,"aria-label":k,children:(0,$.jsx)(Gh,{className:`size-5`})}):(0,$.jsx)(`button`,{type:`submit`,className:`flex size-8 shrink-0 items-center justify-center rounded-md text-primary outline-none hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-30`,disabled:H||U||!ue,"aria-label":O,children:(0,$.jsx)(X,{name:U?`loader-4`:`send-plane-2`,className:Y(`size-4`,U&&`animate-spin`)})}),t[63]=H,t[64]=ue,t[65]=C,t[66]=U,t[67]=O,t[68]=k,t[69]=me):me=t[69];let he=me,ge=Kg,_e=K&&`flex-1`,ve;t[70]!==o||t[71]!==_e?(ve=Y(`relative flex min-h-0 flex-col`,_e,o),t[70]=o,t[71]=_e,t[72]=ve):ve=t[72];let ye=K&&`flex min-h-0 flex-1 flex-col`,be;t[73]!==_||t[74]!==ye?(be=Y(`overflow-hidden`,ye,_),t[73]=_,t[74]=ye,t[75]=be):be=t[75];let xe=de.length>0?(0,$.jsx)(`div`,{className:`flex gap-2 overflow-x-auto px-3 pt-3`,"data-chat-prompt-attachments":`true`,children:de.map(e=>(0,$.jsxs)(`div`,{className:`group relative shrink-0`,children:[(0,$.jsx)(`img`,{src:e.url,alt:e.name,className:`size-16 rounded-lg border border-border object-cover`}),S?(0,$.jsx)(`button`,{type:`button`,className:`absolute -right-1 -top-1 flex size-6 items-center justify-center rounded-full border border-border bg-[var(--surface-elevated)] shadow-sm hover:bg-[var(--interactive-hover)]`,onClick:()=>S(e.id),"aria-label":E,children:(0,$.jsx)(X,{name:`close`,className:`size-3`})}):null]},e.id))}):null,Se=K&&`flex min-h-0 flex-1 flex-col`,Ce;t[76]===Se?Ce=t[77]:(Ce=Y(`relative overflow-hidden`,Se),t[76]=Se,t[77]=Ce);let we;t[78]!==u||t[79]!==d||t[80]!==p||t[81]!==R?(we=d?(0,$.jsx)(`div`,{ref:u,"aria-hidden":!0,"data-composer-highlight":`true`,className:Y(`pointer-events-none absolute inset-0 z-0 rounded-b-none`,R,p),children:d}):null,t[78]=u,t[79]=d,t[80]=p,t[81]=R,t[82]=we):we=t[82];let Te;t[83]===g?Te=t[84]:(Te=e=>{te.current=e,Yg(g,e)},t[83]=g,t[84]=Te);let Ee;t[85]===x?Ee=t[86]:(Ee=e=>x(e.target.value,e),t[85]=x,t[86]=Ee);let De=H||U&&G,Oe=W?`send`:z?.enterKeyHint,ke=K&&`min-h-0 flex-1`,Ae;t[87]!==h||t[88]!==ke?(Ae=Y(`ring-0 bg-transparent shadow-none hover:bg-transparent focus-within:ring-0`,ke,h),t[87]=h,t[88]=ke,t[89]=Ae):Ae=t[89];let je=d&&`text-transparent caret-[var(--surface-foreground)]`,Me;t[90]!==p||t[91]!==je||t[92]!==R?(Me=Y(`relative z-10 min-h-[52px] max-h-40 resize-none overflow-y-hidden appearance-none rounded-b-none border-0 bg-transparent px-3 pb-2 pt-4 typography-markdown hover:border-transparent md:typography-ui-label`,R,p,je),t[90]=p,t[91]=je,t[92]=R,t[93]=Me):Me=t[93];let Ne=z?.rows??1,Pe;t[94]!==se||t[95]!==v||t[96]!==T||t[97]!==Te||t[98]!==Ee||t[99]!==De||t[100]!==Oe||t[101]!==Ae||t[102]!==Me||t[103]!==Ne||t[104]!==z||t[105]!==B?(Pe=(0,$.jsx)(qg,{...z,simple:!0,ref:Te,"data-chat-input":`true`,value:B,onChange:Ee,onKeyDown:se,disabled:De,placeholder:T,enterKeyHint:Oe,outerClassName:Ae,className:Me,style:v,rows:Ne}),t[94]=se,t[95]=v,t[96]=T,t[97]=Te,t[98]=Ee,t[99]=De,t[100]=Oe,t[101]=Ae,t[102]=Me,t[103]=Ne,t[104]=z,t[105]=B,t[106]=Pe):Pe=t[106];let Fe;t[107]!==Ce||t[108]!==we||t[109]!==Pe?(Fe=(0,$.jsxs)(`div`,{className:Ce,"data-composer-input-shell":`true`,children:[we,Pe]}),t[107]=Ce,t[108]=we,t[109]=Pe,t[110]=Fe):Fe=t[110];let Ie;t[111]!==r||t[112]!==m||t[113]!==be||t[114]!==xe||t[115]!==Fe?(Ie=(0,$.jsxs)(`div`,{className:be,children:[m,r,xe,Fe]}),t[111]=r,t[112]=m,t[113]=be,t[114]=xe,t[115]=Fe,t[116]=Ie):Ie=t[116];let Le;t[117]!==pe||t[118]!==he||t[119]!==c||t[120]!==f||t[121]!==y||t[122]!==D?(Le=c??(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:y??pe}),f?(0,$.jsx)(`div`,{className:`min-w-0 flex-1 truncate typography-micro text-muted-foreground`,children:f}):(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:D??he})]}),t[117]=pe,t[118]=he,t[119]=c,t[120]=f,t[121]=y,t[122]=D,t[123]=Le):Le=t[123];let Re;t[124]!==s||t[125]!==l||t[126]!==Le?(Re=(0,$.jsx)(Jg,{className:s,style:l,children:Le}),t[124]=s,t[125]=l,t[126]=Le,t[127]=Re):Re=t[127];let ze;t[128]!==ve||t[129]!==Ie||t[130]!==Re?(ze=(0,$.jsxs)(`div`,{"data-composer-content":`true`,className:ve,children:[Ie,Re]}),t[128]=ve,t[129]=Ie,t[130]=Re,t[131]=ze):ze=t[131];let Be;return t[132]!==ge||t[133]!==i||t[134]!==a||t[135]!==K||t[136]!==A||t[137]!==ze?(Be=(0,$.jsxs)(ge,{className:a,expanded:K,...A,children:[i,ze]}),t[132]=ge,t[133]=i,t[134]=a,t[135]=K,t[136]=A,t[137]=ze,t[138]=Be):Be=t[138],Be};function Zg(e){return e.mime.startsWith(`image/`)}var Qg=e=>e.trim().replace(/\s+/g,`-`).replace(/[^A-Za-z0-9._/-]/g,`-`).replace(/-+/g,`-`).replace(/\/{2,}/g,`/`).replace(/\/-+/g,`/`).replace(/-+\//g,`/`).replace(/^[-/]+/,``).replace(/[-/]+$/,``),$g=({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(()=>Qg(N),[N]),ee=Z.useMemo(()=>{let e=D.trim();return e?vr(t,e,e=>e).map(e=>e.item):t},[D,t]),G=Z.useMemo(()=>{let e=D.trim();return e?vr(n,e,e=>e).map(e=>e.item):n},[D,n]),K=Z.useMemo(()=>{let e=D.trim();return e?vr(m,e,e=>e.label).map(e=>e.item):m},[D,m]),te=Z.useMemo(()=>{if(!p)return!1;let e=D.trim();return!e||vr([p],e,e=>[e.label,b??``]).length>0},[b,p,D]),ne=t=>{if(t===e){B(!1);return}i(t),B(!1),O(``)},re=e=>{g?.(e),B(!1),O(``)},ie=()=>{A(!0),setTimeout(()=>L.current?.focus(),50)},ae=async()=>{if(!(!W||F)){if(H){M(!0);return}I(!0);try{await a(W,o[0]),P(``),A(!1),B(!1)}finally{I(!1)}}},oe=async e=>{if(!(!W||F)){I(!0);try{await a(W,e),P(``),A(!1),M(!1),B(!1)}finally{I(!1)}}},se=()=>{M(!1)},ce=()=>{P(``),A(!1),M(!1)};Z.useEffect(()=>{z||(O(``),A(!1),M(!1),P(``))},[z]);let le=u||e||w(`gitView.branch.detachedHead`),ue=d??(c?`end`:`start`),de=v??w(`chat.chatInput.worktrees`),fe=y??w(`chat.chatInput.worktreeNew`),pe=b??w(`chat.chatInput.projectRoot`),me=c?(0,$.jsx)(`button`,{type:`button`,className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50`,disabled:s,"aria-label":le,children:(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5`})}):(0,$.jsxs)(da,{variant:`ghost`,size:`xs`,className:`h-6 min-w-0 max-w-full justify-start gap-1 px-0 hover:bg-transparent`,disabled:s,"aria-label":le,children:[(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5 text-primary`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate typography-ui-label font-semibold text-left text-foreground`,children:le}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`size-3 shrink-0 text-muted-foreground`})]}),he=(0,$.jsx)(Ka,{asChild:!0,disabled:s,children:l??me}),ge=(0,$.jsxs)(wg,{className:`h-full min-h-0`,children:[(0,$.jsx)(`div`,{"data-mobile-sheet-no-dismiss":C===`mobile-sheet`?``:void 0,children:(0,$.jsx)(Tg,{placeholder:w(`gitView.branch.searchPlaceholder`),value:D,onValueChange:O,onKeyDown:V})}),(0,$.jsxs)(Eg,{scrollbarClassName:`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,disableHorizontal:!0,children:[(0,$.jsx)(Dg,{children:w(`gitView.branch.empty`)}),(0,$.jsx)(Og,{children:j?(0,$.jsxs)(`div`,{className:`px-2 py-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:se,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,$.jsx)(X,{name:`arrow-left`,className:`size-4`})}),(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground`,children:[w(`gitView.branch.pushToPrefix`),` `,(0,$.jsx)(`span`,{className:`text-foreground font-medium`,children:W}),` `,w(`gitView.branch.pushToSuffix`)]})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:o.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>oe(e),disabled:F,className:`flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label text-foreground`,children:[F?(0,$.jsx)(X,{name:`loader-4`,className:`inline size-3 mr-1.5 animate-spin`}):null,e.name]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground truncate max-w-full`,children:e.pushUrl})]},e.name))})]}):k?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-lg`,children:[(0,$.jsx)(`input`,{ref:L,placeholder:w(`gitView.branch.newBranchPlaceholder`),value:N,onChange:e=>P(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{V(e),e.key===`Enter`?(e.preventDefault(),ae()):e.key===`Escape`&&(e.preventDefault(),ce())},className:`flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground`}),(0,$.jsx)(`button`,{type:`button`,onClick:ae,disabled:!W||F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:F?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`add`,className:`size-4`})}),(0,$.jsx)(`button`,{type:`button`,onClick:ce,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,$.jsx)(X,{name:`close`,className:`size-4`})})]}):(0,$.jsxs)(Ag,{onSelect:ie,children:[(0,$.jsx)(X,{name:`add`,className:`size-4`}),(0,$.jsx)(`span`,{children:w(`gitView.branch.create`)})]})}),(0,$.jsx)(kg,{}),(0,$.jsxs)(Og,{heading:w(`gitView.branch.localBranches`),children:[ee.map(t=>(0,$.jsxs)(Ag,{onSelect:()=>ne(t),children:[(0,$.jsxs)(`span`,{className:`flex flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:t}),(r?.[t]?.ahead||r?.[t]?.behind)&&(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[r[t].ahead||0,` ahead ·`,` `,r[t].behind||0,` behind`]})]}),e===t&&(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)})]},`local-${t}`)),ee.length===0&&(0,$.jsx)(Ag,{disabled:!0,className:`justify-center`,children:(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:w(`gitView.branch.noLocalBranches`)})})]}),(0,$.jsx)(kg,{}),(0,$.jsxs)(Og,{heading:w(`gitView.branch.remoteBranches`),children:[G.map(e=>(0,$.jsx)(Ag,{onSelect:()=>ne(e),children:(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e})},`remote-${e}`)),G.length===0&&(0,$.jsx)(Ag,{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)(kg,{}),(0,$.jsxs)(Og,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground typography-meta`,children:de}),_?(0,$.jsx)(`button`,{type:`button`,className:`cursor-pointer text-muted-foreground typography-meta hover:text-foreground`,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.preventDefault(),e.stopPropagation(),B(!1),_()},children:fe}):null]}),p&&te?(0,$.jsxs)(Ag,{onSelect:()=>re(p.value),children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:pe}),(0,$.jsx)(`span`,{className:`truncate typography-ui-label text-foreground`,children:p.label})]}),h===p.value?(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)}):null]}):null,K.map(e=>(0,$.jsxs)(Ag,{onSelect:()=>re(e.value),children:[(0,$.jsxs)(`span`,{className:`truncate typography-ui-label text-foreground`,children:[e.pending?`⏳ `:``,e.label]}),h===e.value?(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)}):null]},`worktree-${e.value}`))]})]}):null]})]});if(C===`mobile-sheet`){let e=Z.cloneElement(l??me,{onClick:()=>B(!0),"data-popup-open":z?``:void 0});return(0,$.jsxs)($.Fragment,{children:[e,(0,$.jsx)(eo,{id:`mobile-draft-branch-picker-sheet-${R}`,open:z,onOpenChange:B,ariaLabel:w(`gitView.branch.selectBranch`),closeAriaLabel:w(`mobile.surface.closeAria`),resizeAriaLabel:w(`mobile.sessions.sheet.resizeAria`),children:ge})]})}return(0,$.jsxs)(Wa,{open:z,onOpenChange:B,children:[f||l?he:(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:he}),(0,$.jsx)(za,{sideOffset:8,children:c?le:w(`gitView.branch.currentBranchTooltip`)})]}),(0,$.jsx)(Ua,{align:ue,className:`w-72 p-0 max-h-[60vh] flex flex-col`,children:ge})]})};function e_(e){let{localBranches:t,remoteBranches:n,query:r}=e,i=r.trim();if(!i)return{matching:[],otherLocal:t,otherRemote:n};let a=vr(t,i,e=>e),o=vr(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 t_(e,t){return`${e}\0${t}`}function n_({open:e,onOpenChange:t,onSelect:n}){let{t:r}=ot(),i=c(e=>e.isMobile),{github:a}=ko(),o=no(),s=o.data??null,l=o.isFetched,u=c(e=>e.setSettingsDialogOpen),d=c(e=>e.setSettingsPage),f=qi(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=xs(v,350),W=q(async e=>{if(!(!m||!a)&&!(l&&s?.connected===!1)){T(!0),k(null),z(1),V(!1);try{if(g===`issues`&&a.issuesList){let t=await a.issuesList(m,{page:1,query:e});t.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),x([])):(x(t.issues??[]),z(t.page??1),V(!!t.hasMore))}else if(g===`prs`&&a.prsList){let t=await a.prsList(m,{page:1,query:e});t.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),C([])):(C(t.prs??[]),z(t.page??1),V(!!t.hasMore))}}catch(e){k(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}finally{T(!1)}}});Z.useEffect(()=>{if(!e||!m||l&&s?.connected===!1||!a)return;if(!U.trim()){W();return}let t=new AbortController;T(!0),k(null),z(1),V(!1);let n=g===`issues`&&a.issuesList?a.issuesList(m,{page:1,query:U.trim()}):g===`prs`&&a.prsList?a.prsList(m,{page:1,query:U.trim()}):null;if(!n){T(!1);return}return n.then(e=>{t.signal.aborted||(`issues`in e?e.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),x([])):(x(e.issues??[]),z(e.page??1),V(!!e.hasMore)):`prs`in e&&(e.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),C([])):(C(e.prs??[]),z(e.page??1),V(!!e.hasMore))))}).catch(e=>{t.signal.aborted||k(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}).finally(()=>{t.signal.aborted||T(!1)}),()=>t.abort()},[e,m,a,l,s,g,U,W,r]);let ee=q(async()=>{if(!(!m||!a)&&!(w||E)&&B){D(!0);try{let e=R+1;if(g===`issues`&&a.issuesList){let t=U.trim()?await a.issuesList(m,{page:e,query:U.trim()}):await a.issuesList(m,{page:e});t.connected!==!1&&(x(e=>[...e,...t.issues??[]]),z(t.page??e),V(!!t.hasMore))}else if(g===`prs`&&a.prsList){let t=U.trim()?await a.prsList(m,{page:e,query:U.trim()}):await a.prsList(m,{page:e});t.connected!==!1&&(C(e=>[...e,...t.prs??[]]),z(t.page??e),V(!!t.hasMore))}}catch{}finally{D(!1)}}});Z.useEffect(()=>{if(!e){_(`issues`),y(``),x([]),C([]),j(null),N(null),F(!1),k(null),L(new Map),z(1),V(!1);return}W()},[e,W]),Z.useEffect(()=>{H.current+=1,L(new Map)},[m,h]);let G=q(async e=>{if(!h||!e)return;let t=t_(h.path,e);if(I.has(t))return;let n=H.current;try{let i=await Ca(h,{mode:`new`,branchName:e,worktreeName:e});if(n!==H.current)return;let a=i.errors.find(e=>e.code===`branch_in_use`);L(e=>new Map(e).set(t,{isValid:!a,error:a?r(a.code===`branch_exists`?`session.githubIntegration.validation.branchAlreadyExists`:`session.githubIntegration.validation.branchAlreadyCheckedOut`):null}))}catch{if(n!==H.current)return;L(e=>new Map(e).set(t,{isValid:!1,error:r(`session.githubIntegration.validation.failed`)}))}});Z.useEffect(()=>{!e||g!==`prs`||S.forEach(e=>{e.head&&G(e.head)})},[e,g,S,m,h,G]);let K=l&&s?.connected===!0,te=()=>{d(`github`),u(!0)},ne=e=>{j(e),N(null)},re=e=>{N(e),j(null)},ie=()=>{A?n({type:`issue`,item:A}):M&&n({type:`pr`,item:M,includeDiff:P}),t(!1)},ae=()=>{j(null),N(null),F(!1)},oe=A||(M?.head&&m?I.get(t_(m,M.head))?.isValid!==!1:!1),se=e=>!e.head||(m?I.get(t_(m,e.head)):void 0)?.isValid===!1,ce=(0,$.jsx)($.Fragment,{children:K?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(La,{value:v,onChange:e=>y(e.target.value),placeholder:r(g===`issues`?`session.githubIntegration.search.issuesPlaceholder`:`session.githubIntegration.search.prsPlaceholder`),className:`h-8 pl-9`})]}),(0,$.jsx)(`div`,{className:`mt-2 h-[300px] overflow-hidden`,children:(0,$.jsxs)(`div`,{className:`h-full overflow-y-auto`,children:[w&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-5 w-5 animate-spin text-muted-foreground`})}),O&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive`,children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-small`,children:O})]})}),!w&&!O&&g===`issues`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[b.length>0?b.map(e=>(0,$.jsx)(`button`,{onClick:()=>ne(e),className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,A?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-2`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noIssuesFound`)}),B&&!E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(da,{variant:`ghost`,size:`sm`,onClick:()=>void ee(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),E&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]}),!w&&!O&&g===`prs`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[S.length>0?S.map(e=>{let t=se(e),n=e.head&&m?I.get(t_(m,e.head)):void 0;return(0,$.jsx)(`button`,{onClick:()=>!t&&re(e),disabled:t,className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,M?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:t?`opacity-50 cursor-not-allowed`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-1`,children:e.title}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[e.head,` → `,e.base]}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,t&&n?.error&&(0,$.jsx)(`span`,{className:`typography-micro text-destructive`,children:n.error})]})]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)}):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noPullRequestsFound`)}),B&&!E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(da,{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)(da,{onClick:te,size:`sm`,children:r(`session.githubIntegration.connect.action`)})]})}),le=(0,$.jsxs)(`div`,{className:Y(`w-full`,i?`flex flex-col gap-2`:`flex flex-row items-center`),children:[(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-4`,i?`w-full justify-center order-1`:`flex-1`),children:[!i&&(A||M)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate max-w-[150px]`,children:A?r(`session.githubIntegration.selected.issueNumber`,{number:A.number}):r(`session.githubIntegration.selected.prNumber`,{number:M?.number??``})}),(0,$.jsx)(`button`,{onClick:ae,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),g===`prs`&&M&&(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer h-8`,children:[(0,$.jsx)(_a,{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)(da,{variant:`outline`,size:`sm`,onClick:()=>t(!1),className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.cancel`)}),(0,$.jsx)(da,{size:`sm`,onClick:ie,disabled:!oe,className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.select`)})]})]});return(0,$.jsx)($.Fragment,{children:i?(0,$.jsx)(Cp,{open:e,title:r(`session.githubIntegration.title`),onClose:()=>t(!1),footer:K?le:void 0,renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:r(`session.githubIntegration.title`)}),e]}),(0,$.jsx)(`div`,{className:`w-full`,children:(0,$.jsx)(hc,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:g,onSelect:e=>{_(e),y(``)},variant:`active-pill`,layoutMode:`fit`})}),(A||M)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate flex-1`,children:A?r(`session.githubIntegration.selected.issueNumber`,{number:A.number}):r(`session.githubIntegration.selected.prNumber`,{number:M?.number??``})}),(0,$.jsx)(`button`,{onClick:ae,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]})]}),children:ce}):(0,$.jsx)(ua,{open:e,onOpenChange:t,children:(0,$.jsxs)(oa,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsx)(ia,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(sa,{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)(hc,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:g,onSelect:e=>{_(e),y(``)},variant:`active-pill`,layoutMode:`fit`})})]})}),ce,(0,$.jsx)(aa,{className:`mt-1`,children:le})]})})})}var r_=(e,t,n)=>{let r=n??t;return r?e.find(e=>e.id===r)??null:null},i_=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``),a_=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),o_=e=>String(e||``).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`pr-head`,s_=(e,t,n)=>{let r=i_(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-${o_(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}`}},c_=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`},l_=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function u_({open:e,onOpenChange:t,onWorktreeCreated:n,projectId:r}){let{t:i}=ot(),{github:a,git:o}=ko(),s=c(e=>e.isMobile),l=Z.useId(),u=no(),d=u.data??null,f=u.isFetched,p=qi(e=>r_(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=Is(m),C=Ns(m),w=Es(e=>e.fetchBranches),T=Z.useMemo(()=>S?.all?S.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[S]),E=Z.useMemo(()=>S?.all?S.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[S]),D=J(e=>e.availableWorktreesByProject),O=Z.useMemo(()=>{if(!m)return new Set;let e=D.get(m)??[];return new Set(e.map(e=>e.name))},[D,m]),k=Z.useCallback((e=10)=>{for(let t=0;t<e;t++){let e=rg();if(!O.has(e))return e}return`${rg()}-${Date.now().toString(36).slice(-4)}`},[O]),[A,j]=Z.useState(!1),[M,N]=Z.useState(!1),[P,F]=Z.useState(!1),[I,L]=Z.useState(!1),[R,z]=Z.useState(!1),[B,V]=Z.useState(``),[H,U]=Z.useState(``),W=Z.useRef(null),ee=Z.useRef(null),G=Z.useRef(null),K=Z.useRef(null),te=Z.useCallback(e=>{e.stopPropagation()},[]),ne=Z.useCallback(e=>{let t=e;for(;t&&t!==document.body;){let{overflowY:e}=window.getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t;t=t.parentElement}return null},[]),re=Z.useCallback(e=>{e&&(e.scrollTop=0)},[]),ie=Z.useCallback(e=>{let t=e.current?.querySelector(`[data-slot="command-list"]`)??null;re(t)},[re]),ae=Z.useCallback(e=>{let t=ne(e.current);re(t)},[ne,re]),oe=Z.useMemo(()=>e_({localBranches:T,remoteBranches:E,query:B}),[T,E,B]),se=Z.useMemo(()=>e_({localBranches:T,remoteBranches:E,query:H}),[T,E,H]),ce=B.trim().length>0,le=H.trim().length>0,ue=oe.matching.length>0,de=se.matching.length>0,fe=!!(m&&o),pe=Z.useCallback(()=>{!m||!o||w(m,o)},[m,o,w]);Z.useEffect(()=>{!e||!m||!o||S?.all||w(m,o)},[e,m,o,S?.all,w]),Z.useEffect(()=>{!M&&!I&&V(``)},[M,I]),Z.useEffect(()=>{!P&&!R&&U(``)},[P,R]),Z.useEffect(()=>{M&&ie(W),I&&ae(G)},[M,I,B,ie,ae]),Z.useEffect(()=>{P&&ie(ee),R&&ae(K)},[P,R,H,ie,ae]);let[me,he]=Z.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[ge,_e]=Z.useState(!1),[ve,ye]=Z.useState(null),be=Z.useCallback(()=>{let e=Ei.getState(),t=e.getVisibleAgents();if(e.settingsDefaultAgent){let n=t.find(t=>t.name===e.settingsDefaultAgent);if(n)return n.name}return t.find(e=>e.name===`build`)?.name||t[0]?.name},[]),xe=Z.useCallback(()=>{let e=Ei.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=Zt(t);if(!n)return null;let{providerId:r,modelId:i}=n;return e.getModelMetadata(r,i)?{providerID:r,modelID:i}:null},[]),Se=Z.useCallback((e,t)=>{let n=Ei.getState(),r=n.settingsDefaultVariant,i=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0,a=n.providers.find(t=>t.id===e)?.models.find(e=>e.id===t)?.variants;if(!a)return r||i||void 0;if(r&&Object.prototype.hasOwnProperty.call(a,r))return r;if(i&&Object.prototype.hasOwnProperty.call(a,i))return i},[]),Ce=Z.useCallback(async e=>{if(!m||!a)return;let t=Ei.getState(),n=xt.getState().lastUsedProvider,r=xe(),o=r?.providerID||t.currentProviderId||n?.providerID,s=r?.modelID||t.currentModelId||n?.modelID,c=be()||t.currentAgentName||void 0;if(!o||!s){Ii.error(i(`session.newWorktree.error.noModelSelected`));return}let l=Se(o,s);if(e.issue){if(!a.issueGet||!a.issueComments)return;let t=await a.issueGet(m,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(t.connected===!1||!t.repo||!t.issue)throw Error(`Failed to load issue context`);let n=await a.issueComments(m,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(n.connected===!1)throw Error(`Failed to load issue comments`);let r=await yi(`github.issue.review.visible`,{issue_number:String(e.issue.number)}),u=await yi(`github.issue.review.instructions`),d=c_({repo:t.repo,issue:t.issue,comments:n.comments??[]});await J.getState().sendMessage(r,o,s,c,void 0,void 0,[{text:u,synthetic:!0},{text:d,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),Ii.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 yi(`github.pr.review.visible`,{pr_number:String(e.pr.number)}),r=await yi(`github.pr.review.instructions`),u=l_(t);await J.getState().sendMessage(n,o,s,c,void 0,void 0,[{text:r,synthetic:!0},{text:u,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),Ii.success(i(`session.newWorktree.toast.sessionFromPr`))}},[a,m,be,xe,Se,i]),we=g===`new-branch`?v:b;Z.useEffect(()=>{if(!e||!S?.all||!m||v.sourceBranch)return;let t=v.sourceBranch,n=!1;return(async()=>{try{let e=await ja(m).catch(()=>null);if(n)return;let r=localStorage.getItem(Ts),{sourceBranch:i,shouldClearSavedSourceBranch:a}=Fs({branches:S.all,savedSourceBranch:r,rootBranch:e});if(a&&localStorage.removeItem(Ts),n||t)return;i&&y(e=>({...e,sourceBranch:i}))}catch{}})(),()=>{n=!0}},[e,S?.all,m,v.sourceBranch]),Z.useLayoutEffect(()=>{if(!e)return;_(`new-branch`),x({selectedBranch:``,worktreeName:``}),N(!1),F(!1),L(!1),z(!1),V(``),U(``),he({isValidating:!1,branchError:null,worktreeError:null,touched:!1});let t=k();y({branchName:t,worktreeName:t,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1})},[e,k]),Z.useEffect(()=>{if(g!==`new-branch`||!v.isSyncingWorktreeName)return;let e=a_(i_(v.branchName));y(t=>({...t,worktreeName:e}))},[g,v.branchName,v.isSyncingWorktreeName]);let Te=Z.useCallback(async()=>{if(!h||!me.touched||ge)return;ve&&ve.abort();let e=new AbortController;ye(e),he(e=>({...e,isValidating:!0}));try{let t=g===`new-branch`?v.branchName:b.selectedBranch,n=we.worktreeName,r=i_(t),a=a_(n),o=null,s=null;if(r||(o=i(`session.newWorktree.error.branchNameRequired`)),a||(s=i(`session.newWorktree.error.worktreeDirectoryRequired`)),r&&a){let t=g===`new-branch`?v.linkedPr:null,n=t?s_(t,T,E):null,i=await Ca(h,{mode:g===`existing-branch`||n?`existing`:`new`,branchName:r,worktreeName:a,existingBranch:n?.existingBranch??(g===`existing-branch`?r:void 0),...n?.ensureRemoteName?{ensureRemoteName:n.ensureRemoteName}:{},...n?.ensureRemoteUrl?{ensureRemoteUrl:n.ensureRemoteUrl}:{}});if(e.signal.aborted)return;i.ok||i.errors.forEach(e=>{if(e.code===`worktree_exists`){s??=e.message;return}e.code.startsWith(`branch_`)&&(o??=e.message)})}e.signal.aborted||he(e=>({...e,isValidating:!1,branchError:o,worktreeError:s}))}catch{e.signal.aborted||he(e=>({...e,isValidating:!1}))}},[h,g,v.branchName,v.linkedPr,b.selectedBranch,we.worktreeName,T,E,me.touched,ve,ge,i]),Ee=g===`new-branch`?v.branchName:b.selectedBranch;Z.useEffect(()=>{if(!e||!h||!me.touched||ge)return;let t=setTimeout(()=>{Te()},300);return()=>clearTimeout(t)},[we.worktreeName,Ee,e,h,Te,me.touched,ge]);let De=async()=>{if(!h||!m){Ii.error(i(`session.newWorktree.error.noActiveProject`));return}he(e=>({...e,touched:!0}));let e=g===`new-branch`?v.branchName:b.selectedBranch,r=we.worktreeName,a=i_(e),o=a_(r);if(!a){Ii.error(i(`session.newWorktree.error.branchNameRequired`));return}if(!o){Ii.error(i(`session.newWorktree.error.worktreeDirectoryRequired`));return}ve&&(ve.abort(),ye(null)),he(e=>({...e,isValidating:!1,branchError:null,worktreeError:null})),_e(!0);try{let e=g===`new-branch`?v.linkedPr:null,r=g===`new-branch`?v.linkedIssue:null,s=g===`new-branch`?v.linkedPr:null,c=g===`new-branch`&&v.includePrDiff,l=!!(r||s),[u,d]=await Promise.all([$t(h),Ms(m)]),f=v.sourceBranch,p=``,_=(()=>{if(e){let t=s_(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 Bs(m,_,{resolvedRootTrackingRemote:d}),x=await Ma(h,y),S=null;if(l){await dn(h)&&await Dr(x.path);let e=r?`#${r.number} ${r.title}`.trim():s?`#${s.number} ${s.title}`.trim():i(`session.newWorktree.newSessionTitle`),a=await Ct(e,x.path,null);if(!a?.id)throw Error(`Failed to create session`);S=a.id,n?.(x.path,{sessionId:S}),t(!1),_e(!1),ft(a.id,e).catch(()=>void 0);try{J.getState().initializeNewOpenChamberSession(a.id,Ei.getState().agents)}catch{}}else t(!1),_e(!1);let C=Rs({mode:g,sourceBranch:v.sourceBranch,linkedPr:!!v.linkedPr,selectedBranch:b.selectedBranch});C&&localStorage.setItem(Ts,C),Ii.success(i(`session.newWorktree.toast.worktreeCreated`),{description:i(`session.newWorktree.toast.worktreeCreatedDescription`,{target:`${x.branch||x.name}${p?` ${i(`session.newWorktree.fromSource`,{source:p})}`:``}`})}),S?Ce({sessionId:S,directory:x.path,issue:r,pr:s,includeDiff:c}).catch(e=>{let t=e instanceof Error?e.message:i(`session.newWorktree.error.sendGitHubContextFailed`);Ii.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`);Ii.error(i(`session.newWorktree.error.createWorktreeFailed`),{description:t})}finally{_e(!1)}},Oe=e=>{_(e),he(e=>({...e,touched:!1,branchError:null,worktreeError:null}))},ke=e=>{if(!e){y(e=>({...e,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:``}));return}if(e.type===`issue`){let t=e.item,n=`issue-${t.number}-${rg()}`;y(e=>({...e,linkedIssue:t,linkedPr:null,includePrDiff:!1,branchName:n,worktreeName:a_(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:a_(t.head),isSyncingWorktreeName:!0}))}},Ae=f&&d?.connected===!0,je=(g===`existing-branch`?!!b.selectedBranch&&!!b.worktreeName&&!me.branchError&&!me.worktreeError:!!i_(v.branchName)&&!!v.worktreeName&&!me.branchError&&!me.worktreeError)&&!ge,Me=()=>{y(e=>({...e,linkedIssue:null,linkedPr:null,branchName:``,includePrDiff:!1,isSyncingWorktreeName:!0}))},Ne=(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,s?`flex-col w-full`:`flex-row items-center`),children:[(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1.5 text-destructive`,s?`w-full justify-center order-first`:`mr-auto`),children:me.touched&&(me.branchError||me.worktreeError)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:me.branchError||me.worktreeError})]})}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,s&&`w-full`),children:[(0,$.jsx)(da,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:ge,className:Y(s&&`flex-1`),children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(da,{size:`sm`,onClick:De,disabled:!je||ge,className:Y(`gap-1.5`,s&&`flex-1`),children:[ge&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(ge?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]});return(0,$.jsxs)($.Fragment,{children:[s?(0,$.jsx)(eo,{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)(ma,{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)(hc,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:g,onSelect:e=>Oe(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})}),(0,$.jsxs)(`div`,{className:`space-y-6`,children:[g===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(da,{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)(da,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:pe,disabled:!fe||C,title:i(`session.newWorktree.fetchBranches`),children:C?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]}),(0,$.jsx)(Cp,{open:I,title:i(`session.newWorktree.selectBranch`),onClose:()=>L(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:G,children:[(0,$.jsx)(La,{value:B,onChange:e=>V(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),C?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[ce&&ue&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(`session.newWorktree.matchingBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:oe.matching.map(e=>(0,$.jsx)(`button`,{onClick:()=>{x(t=>({...t,selectedBranch:e.value,worktreeName:a_(e.label)})),he(e=>({...e,touched:!0})),L(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,b.selectedBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),ce&&!ue&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),oe.otherLocal.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(ce?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:oe.otherLocal.map(e=>(0,$.jsx)(`button`,{onClick:()=>{x(t=>({...t,selectedBranch:e,worktreeName:a_(e)})),he(e=>({...e,touched:!0})),L(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,b.selectedBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),oe.otherRemote.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(ce?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:oe.otherRemote.map(e=>(0,$.jsx)(`button`,{onClick:()=>{x(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:a_(e)})),he(e=>({...e,touched:!0})),L(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,b.selectedBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),g===`new-branch`&&Ae&&(0,$.jsxs)(da,{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)(La,{value:v.branchName,onChange:e=>{y(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>he(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!v.linkedPr,className:Y(`h-8`,me.touched&&me.branchError&&`border-destructive`,v.linkedPr&&`bg-muted text-muted-foreground`)}),v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:v.linkedPr.head})})]}),v.linkedIssue&&!v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:v.linkedIssue.number,title:v.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),g!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=a_(g===`new-branch`?v.branchName:``);y(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!v.branchName||v.worktreeName===a_(v.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,v.worktreeName===a_(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)(La,{value:we.worktreeName,onChange:e=>{g===`new-branch`?y(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):x(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>he(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,me.touched&&me.worktreeError&&`border-destructive`)})]}),g===`new-branch`&&!v.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)(da,{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)(Cp,{open:R,title:i(`session.newWorktree.selectSourceBranch`),onClose:()=>z(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:K,children:[(0,$.jsx)(La,{value:H,onChange:e=>U(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),C?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[le&&de&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(`session.newWorktree.matchingBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:se.matching.map(e=>(0,$.jsx)(`button`,{onClick:()=>{y(t=>({...t,sourceBranch:e.value})),z(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,v.sourceBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),le&&!de&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),se.otherLocal.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(le?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:se.otherLocal.map(e=>(0,$.jsx)(`button`,{onClick:()=>{y(t=>({...t,sourceBranch:e})),z(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,v.sourceBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),se.otherRemote.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(le?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:se.otherRemote.map(e=>(0,$.jsx)(`button`,{onClick:()=>{y(t=>({...t,sourceBranch:`remotes/${e}`})),z(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,v.sourceBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}),(v.linkedIssue||v.linkedPr)&&g===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),v.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:v.linkedIssue.number})}),v.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:v.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:v.linkedIssue?.title||v.linkedPr?.title}),(0,$.jsx)(`a`,{href:v.linkedIssue?.url||v.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick:Me,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[v.linkedPr.head,` → `,v.linkedPr.base]}),v.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]})]}),(0,$.jsx)(`div`,{className:`shrink-0 border-t border-border/50 px-4 pb-3 pt-2`,children:Ne})]})}):(0,$.jsx)(ua,{open:e,onOpenChange:t,children:(0,$.jsxs)(oa,{className:`max-w-lg max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(ia,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(sa,{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)(hc,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:g,onSelect:e=>Oe(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})})]})}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto mt-2 space-y-6`,children:[g===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(Wa,{open:M,onOpenChange:N,children:[(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsxs)(da,{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)(Ua,{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)(wg,{shouldFilter:!1,children:[(0,$.jsx)(Tg,{placeholder:i(`session.newWorktree.searchBranches`),value:B,onValueChange:V,onKeyDown:te}),(0,$.jsx)(Eg,{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)(Dg,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[ce&&ue&&(0,$.jsx)(Og,{heading:i(`session.newWorktree.matchingBranches`),children:oe.matching.map(e=>(0,$.jsx)(Ag,{value:e.value,onSelect:()=>{x(t=>({...t,selectedBranch:e.value,worktreeName:a_(e.label)})),he(e=>({...e,touched:!0})),N(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),ce&&!ue&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),oe.otherLocal.length>0&&(0,$.jsxs)($.Fragment,{children:[ce&&(0,$.jsx)(kg,{}),(0,$.jsx)(Og,{heading:i(ce?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:oe.otherLocal.map(e=>(0,$.jsx)(Ag,{value:e,onSelect:()=>{x(t=>({...t,selectedBranch:e,worktreeName:a_(e)})),he(e=>({...e,touched:!0})),N(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),oe.otherRemote.length>0&&(0,$.jsxs)($.Fragment,{children:[(oe.otherLocal.length>0||ce)&&(0,$.jsx)(kg,{}),(0,$.jsx)(Og,{heading:i(ce?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:oe.otherRemote.map(e=>(0,$.jsx)(Ag,{value:`remotes/${e}`,onSelect:()=>{x(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:a_(e)})),he(e=>({...e,touched:!0})),N(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),(0,$.jsx)(da,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:pe,disabled:!fe||C,title:i(`session.newWorktree.fetchBranches`),children:C?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),g===`new-branch`&&Ae&&(0,$.jsxs)(da,{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)(La,{value:v.branchName,onChange:e=>{y(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>he(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!v.linkedPr,className:Y(`h-8`,me.touched&&me.branchError&&`border-destructive`,v.linkedPr&&`bg-muted text-muted-foreground`)}),v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:v.linkedPr.head})})]}),v.linkedIssue&&!v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:v.linkedIssue.number,title:v.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),g!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=a_(g===`new-branch`?v.branchName:``);y(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!v.branchName||v.worktreeName===a_(v.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,v.worktreeName===a_(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)(La,{value:we.worktreeName,onChange:e=>{g===`new-branch`?y(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):x(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>he(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,me.touched&&me.worktreeError&&`border-destructive`)})]}),g===`new-branch`&&!v.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)(Wa,{open:P,onOpenChange:F,children:[(0,$.jsx)(Ka,{asChild:!0,children:(0,$.jsxs)(da,{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)(Ua,{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)(wg,{shouldFilter:!1,children:[(0,$.jsx)(Tg,{placeholder:i(`session.newWorktree.searchBranches`),value:H,onValueChange:U,onKeyDown:te}),(0,$.jsx)(Eg,{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)(Dg,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[le&&de&&(0,$.jsx)(Og,{heading:i(`session.newWorktree.matchingBranches`),children:se.matching.map(e=>(0,$.jsx)(Ag,{value:e.value,onSelect:()=>{y(t=>({...t,sourceBranch:e.value})),F(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),le&&!de&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),se.otherLocal.length>0&&(0,$.jsxs)($.Fragment,{children:[le&&(0,$.jsx)(kg,{}),(0,$.jsx)(Og,{heading:i(le?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:se.otherLocal.map(e=>(0,$.jsx)(Ag,{value:e,onSelect:()=>{y(t=>({...t,sourceBranch:e})),F(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),se.otherRemote.length>0&&(0,$.jsxs)($.Fragment,{children:[(se.otherLocal.length>0||le)&&(0,$.jsx)(kg,{}),(0,$.jsx)(Og,{heading:i(le?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:se.otherRemote.map(e=>(0,$.jsx)(Ag,{value:`remotes/${e}`,onSelect:()=>{y(t=>({...t,sourceBranch:`remotes/${e}`})),F(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),v.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:v.sourceBranch})})]}),(v.linkedIssue||v.linkedPr)&&g===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),v.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:v.linkedIssue.number})}),v.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:v.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:v.linkedIssue?.title||v.linkedPr?.title}),(0,$.jsx)(`a`,{href:v.linkedIssue?.url||v.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick:Me,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[v.linkedPr.head,` → `,v.linkedPr.base]}),v.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]}),(0,$.jsxs)(aa,{className:`mt-1 flex items-center justify-between`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 text-destructive`,children:me.touched&&(me.branchError||me.worktreeError)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:me.branchError||me.worktreeError})]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(da,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:ge,children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(da,{size:`sm`,onClick:De,disabled:!je||ge,className:`gap-1.5`,children:[ge&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(ge?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]})]})}),(0,$.jsx)(n_,{open:A,onOpenChange:j,onSelect:ke})]})}function d_(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 f_(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 p_=(e,t)=>e??t??null,m_=(e,t)=>!!e&&t!==!1,h_=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:[]},g_=e=>e.replace(/^remotes\//,``).trim(),__=e=>{let t=g_(e),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},v_=({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}=ko(),f=p_(t,e),p=e,m=Hs(f),h=Hs(p),g=m_(f,m),_=p!==f&&m_(p,h),v=vs(f,d,g),y=vs(p,d,_),b=v.data,x=p===f?b:y.data,S=Es(e=>e.fetchStatus),C=Es(e=>p&&e.directories.get(p)?.status?.current?.trim()||null),[w,T]=Z.useState(!1),E=Vs(f,d,g&&w).data??[],[D,O]=Z.useState(null),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),N=qi(e=>e.projects),P=qi(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(()=>h_(b?.all),[b]),R=x?.current?.trim()||C||null,z=!f_(n,e)&&n||R||n||l(`chat.chatInput.branch`),B=q(async()=>{if(!d)return;let e=new Set;f&&e.add(f),p&&e.add(p),await Promise.all([...e].map(async e=>{await Cs(e,d),await S(e,d,{silent:!0})}))}),V=q(e=>{let t=g_(e),n=__(t);return i.find(e=>{let r=e.label.trim();return r===t||r===n})??null}),H=q(async e=>{if(!p||!d)return;let t=g_(e);if(R!==t&&R!==__(t))try{await d.checkoutBranch(p,t),Ii.success(l(`gitView.toast.checkedOut`,{name:t})),await B()}catch(e){let n=e instanceof Error?e.message:l(`gitView.toast.checkoutFailed`,{name:t});Ii.error(n)}}),U=q(e=>{let t=g_(e);if(!t||R===t||R===__(t))return;let n=V(t);if(n){a(n.value);return}O(t)}),W=q(async()=>{if(!(!D||k)){A(!0);try{await H(D),O(null)}finally{A(!1)}}}),ee=q(async()=>{if(!(!D||k)){A(!0);try{await gg({branch:D,projectDirectory:t??void 0})&&O(null)}finally{A(!1)}}}),G=q(async(e,t)=>{if(!p||!d)return;let n=t?.name??`origin`;try{await d.createBranch(p,e,R??`HEAD`),Ii.success(l(`gitView.toast.createdBranch`,{name:e})),O(e),d.gitPush(p,{remote:n,branch:e,options:[`--set-upstream`]}).then(async()=>{await B(),Ii.success(l(`gitView.toast.upstreamSet`,{branch:e,remote:n}))}).catch(async e=>{let t=e instanceof Error?e.message:l(`gitView.toast.branchCreatedLocally`);Ii.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 Ii.error(t),e}}),K=q(()=>{let e=qi.getState(),n=u(t),r=n?e.projects.find(e=>u(e.path)===n)??null:null;r&&e.activeProjectId!==r.id&&e.setActiveProjectIdOnly(r.id),M(!0)}),te=q((e,n)=>{if(M(!1),n?.sessionId){J.getState().setCurrentSession(n.sessionId,e);return}let r=qi.getState(),i=u(t),a=(i?r.projects.find(e=>u(e.path)===i)??null:null)?.id??r.activeProjectId??null,o=J.getState();if(o.newSessionDraft?.open){o.overrideNewSessionDraftTarget({...a?{selectedProjectId:a}:{},directoryOverride:e,bootstrapPendingDirectory:e,preserveDirectoryOverride:!0}),Te.getState().setDirectory(e,{showOverlay:!1});return}o.openNewSessionDraft({...a?{selectedProjectId:a}:{},directoryOverride:e,preserveDirectoryOverride:!0})}),ne=(0,$.jsxs)(`button`,{type:`button`,className:Y(`group relative inline-flex min-w-0 w-fit items-center gap-1.5 rounded-lg !border-0 px-1.5 font-medium text-foreground/80`,c===`mobile-sheet`?`h-[26px] text-[11px] leading-none`:`h-6 py-1 pr-1.5 typography-micro transition-[padding] hover:pr-5 focus-visible:pr-5 data-[popup-open]:pr-5`,s,jp,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)($g,{currentBranch:R,localBranches:I,remoteBranches:L,branchInfo:b?.branches,onCheckout:U,onCreate:G,remotes:E,trigger:ne,triggerLabel:z,hideTooltip:!0,projectRootOption:r,worktreeOptions:i,selectedDirectory:e,onSelectDirectory:a,onCreateWorktree:K,open:w,presentation:c,onOpenChange:T}),j?(0,$.jsx)(u_,{open:!0,projectId:F,onOpenChange:M,onWorktreeCreated:te}):null,(0,$.jsx)(ua,{open:!!D,onOpenChange:e=>{!e&&!k&&O(null)},children:(0,$.jsxs)(oa,{showCloseButton:!1,className:`max-w-sm gap-4`,children:[(0,$.jsxs)(ia,{children:[(0,$.jsx)(sa,{children:l(`chat.chatInput.branchSwitch.title`,{branch:D??``})}),(0,$.jsx)(ca,{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)(aa,{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`)})})]})})]})},y_=[],b_=[],x_={revertMessageID:void 0,records:b_},S_=e=>e.role===`user`,C_=(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},w_=(e,t,n=x_)=>{if(!t)return x_;let r=(`session`in e?e.session:[]).find(e=>e.id===t)?.revert?.messageID;if(!r)return x_;let i=`messages`in e?e.messages:e.message[t]??[],a=`partsByMessageID`in e?e.partsByMessageID:e.part,o=[];for(let e of i)!S_(e)||!Zr(i,e.id,r)||o.push({message:e,parts:a[e.id]??y_});let s=o.length===0?b_:o;return n.revertMessageID===r&&C_(n.records,s)?n:{revertMessageID:r,records:s}},T_={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},E_={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`},D_=`text-foreground`;function O_(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 k_=/^(\s*)(`{3,}|~{3,})\s*(\S*)/;function A_(e){let t=k_.exec(e);return t?{marker:t[2],lang:t[3]||``}:null}function j_(e,t){return RegExp(`^\\s*\\${t[0]}{${t.length},}\\s*$`).test(e)}function M_(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`}),j_(o,i)&&(r=!1);continue}let l=A_(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`}),O_(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`}),O_(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;O_(o.slice(r-s),r,t);continue}O_(o,s,t)}return t}function N_(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??T_[e.style];(n>u||n===u&&t<d)&&(u=n,d=t,l=e)}let f=l?l.className??E_[l.style]:D_,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 P_(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 F_(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 I_(e,t,n){let r=P_(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 L_(e){return e.map(e=>({start:e.start,end:e.end,style:e.kind===`file`?`mentionFile`:e.kind===`session`?`mentionSession`:`mentionAgent`,visual:e.kind===`session`&&e.label?ie({trigger:`@`,icon:`chat-thread`,label:e.label},H({trigger:`@`,icon:`chat-thread`,label:e.label})):void 0}))}function R_(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 z_=`bg-[var(--surface-subtle)]`,B_=91,V_=94,H_={keyword:8,function:7,type:6,string:5,number:5,variable:4,operator:3,comment:2},U_={keyword:`${z_} text-[var(--syntax-keyword)]`,string:`${z_} text-[var(--syntax-string)]`,number:`${z_} text-[var(--syntax-number)]`,comment:`${z_} text-[var(--syntax-comment)]`,function:`${z_} text-[var(--syntax-function)]`,type:`${z_} text-[var(--syntax-type)]`,variable:`${z_} text-[var(--syntax-variable)]`,operator:`${z_} text-[var(--syntax-operator)]`},W_=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`}]),G_=e=>{let t=null;for(let n of e.split(` `)){let e=n;H_[e]!==void 0&&(t===null||H_[e]>H_[t])&&(t=e)}return t?U_[t]:null},K_=2e4,q_=e=>{if(!e)return null;try{let t=so(e);return t instanceof Qe?t:null}catch{return null}};function J_(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=A_(i);if(!a)continue;let o=q_(a.lang),s=r,c=[],l=e+1,u=r;for(;l<n.length;l+=1){let e=n[l];if(j_(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:`${z_} text-[var(--syntax-foreground)]`,priority:B_}),!(d.length>K_)))try{let e=o.parser.parse(d);Xe(e,W_,(e,n,r)=>{let i=G_(r);i&&t.push({start:s+e,end:s+n,style:`codeFence`,className:i,priority:V_})})}catch{}}return t}var Y_=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],X_=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),Z_=e=>{if(!X_(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(`/`)},Q_=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?Z_(n):X_(n))?n:null},$_=(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)$_(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))$_(r,t,n+1)}},ev=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=Q_(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=Q_(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;$_(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},tv=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of Y_){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 ev(r,i))t.add(e)}return Array.from(t)},nv=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}}},rv=e=>X_(e);function iv(e,t){let n=(0,Q.c)(5),r=rn(e,t),i=c(av),a;n[0]===r?a=n[1]:(a=pn(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 av(e){return e.sessionGoalEnabled}function ov(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 Nt(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 sv={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},cv={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`},lv=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=ot(),i=c(e=>e.isMobile),{goal:a,enabled:o}=iv(e??``,t),s=ov(e??``,a),l=dr(e??``,t),u=bi(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,At(e,t))},[e,t,a,u]);let g=q(async n=>{if(!(!e||f)){p(!0);try{await Cn(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),Ii.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?`${Kr(a.tokensUsed)}/${Kr(a.tokenBudget)}`:a.tokensUsed>0?Kr(a.tokensUsed):null,b=a.status===`active`?{icon:`pause`,labelKey:`chat.goal.action.pause`,next:`paused`}:a.status===`paused`||a.status===`blocked`||a.status===`budgetLimited`?{icon:`play`,labelKey:`chat.goal.action.resume`,next:`active`}:null,x=i?`text-[11px] leading-none text-muted-foreground`:`typography-meta text-muted-foreground`,S=i?`text-xs leading-5 text-foreground`:`typography-ui-label leading-5 text-foreground`,C=i?`size-3`:`size-3.5`;return(0,$.jsxs)(`div`,{className:Y(`flex w-full min-w-0 items-center`,i?`gap-1 py-0.5`:`gap-1.5 py-0.5 md:gap-2`,n),"aria-label":r(`chat.goal.row.aria`),title:s??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(C,`flex-shrink-0`),style:{color:sv[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,S),children:a.note||s||``}),a.status===`active`&&(!l||l.type===`idle`)?(0,$.jsxs)(`span`,{className:Y(`flex flex-shrink-0 items-center gap-1`,x),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(C,`animate-spin`),"aria-hidden":`true`}),r(`chat.goal.status.evaluating`)]}):(0,$.jsx)(`span`,{className:Y(`flex-shrink-0`,x),children:r(cv[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]})});lv.displayName=`SessionGoalRow`;var uv=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=ot(),{goal:i,enabled:a}=iv(e??``,t),o=kt(e=>e.armed),s=kt(e=>e.setArmed),[c,l]=Z.useState(!1);if(d()||!a||!e&&!n||!o&&!i)return null;let u=i?.status===`complete`?`text-[var(--status-success)]`:i?.status===`blocked`||i?.status===`budgetLimited`?`text-[var(--status-error)]`:o||i?.status===`active`||i?.status===`paused`?`text-[var(--status-info)]`:``,f=async()=>{if(o){s(!1);return}if(!(!e||c)){l(!0);try{await Rn(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),Ii.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`})})]})});uv.displayName=`SessionGoalButton`;var dv=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=ot();if(!kt(fv)||n===0)return null;let i=n>5e3?`text-[var(--status-error)]`:`text-muted-foreground/70`,a;t[0]===i?a=t[1]:(a=Y(`flex-shrink-0 self-center typography-micro tabular-nums`,i),t[0]=i,t[1]=a);let o;t[2]===r?o=t[3]:(o=r(`chat.goal.counter.aria`),t[2]=r,t[3]=o);let s;t[4]===r?s=t[5]:(s=r(`chat.goal.counter.aria`),t[4]=r,t[5]=s);let c;return t[6]!==n||t[7]!==a||t[8]!==o||t[9]!==s?(c=(0,$.jsxs)(`span`,{className:a,"aria-label":o,title:s,children:[n,`/`,Xr]}),t[6]=n,t[7]=a,t[8]=o,t[9]=s,t[10]=c):c=t[10],c});dv.displayName=`SessionGoalObjectiveCounter`;function fv(e){return e.armed}var pv=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`plan-feature`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`]),mv=new Set([`compact`,`fork`,`undo`,`redo`]),hv=/^\/\u2003?([^\s]+)/i,gv=/^\/\u2003?goal\b/i,_v=(e,t)=>{if(t!==`normal`)return null;let n=e.trimStart().match(hv)?.[1]?.toLowerCase();return n&&pv.has(n)?n:null},vv=(e,t)=>_v(e,t)===`goal`?e.trimStart().replace(gv,``).trim():null,yv=(e,t)=>_v(e,t)!==null,bv=(e,t)=>{let n=_v(e,t);return n!==null&&mv.has(n)},xv=(e,t)=>{if(!e.includes(`/`)||t.size===0)return[];let n=RegExp(`(^|\\s)/(${ee})?([A-Za-z0-9][A-Za-z0-9_-]*)(?=$|\\s)`,`g`),r=[],i;for(;(i=n.exec(e))!==null;){let e=i[3]??``;if(!t.has(e.toLowerCase()))continue;let n=i[2]??``,a=i.index+(i[1]?.length??0);r.push({start:a,end:a+1+n.length+e.length,name:e,hasSlot:n.length>0})}return r},Sv=(e,t,n=e.length)=>{let r=xv(e,t).filter(e=>!e.hasSlot);if(r.length===0)return null;let i=e,a=n;for(let e=r.length-1;e>=0;--e){let t=r[e].start+1;i=`${i.slice(0,t)}${ee}${i.slice(t)}`,a>t&&(a+=ee.length)}return i===e?null:{text:i,caret:a}},Cv=e=>e.startsWith(ee)?e.slice(ee.length):e,wv=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},Tv=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()}},Ev=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,Dv=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,Ov=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},kv=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),Av=(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},jv=async e=>{let t=En.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=kv(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}Av(n,a)?r+=1:i+=1}catch{try{Av(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},Mv=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),Nv=e=>e===`allow`||e===`ask`||e===`deny`,Pv=e=>{if(Nv(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`&&Nv(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(Nv(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))Nv(i)&&t.push({permission:n,pattern:e,action:i})}return t},Fv=e=>{let t=Pv(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},Iv=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>Fv(e.permission));let r=e.find(e=>e?.name===n);return!r||Fv(r.permission)},Lv=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)},Rv=null,zv=new Set,Bv=()=>{for(let e of zv)e()},Vv=e=>e===`chat`||e===`assistant`,Hv=()=>Rv,Uv=e=>{Rv!==e&&(Rv=e,Bv())},Wv=e=>{Rv&&(e&&Rv.surfaceID!==e||(Rv=null,Bv()))},Gv=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},Kv=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}},qv=(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}),Jv=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=qv(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=qv(e,`send`,i),o=cm(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=qv(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=qv(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=qv(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:cm(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>tm(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=qv(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=qv(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},Yv=(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)))},Xv=(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},Zv=(e,t)=>e.agents.some(e=>e.name===t),Qv=(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},$v=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return Qv(t,n,r,i)?i:void 0;if(a&&Qv(t,n,r,a))return a},ey=e=>{let{sessionId:t,latestUserChoice:n,catalog:r,memory:i,fallbackAgentName:a}=e;if(n?.providerID&&n.modelID&&Xv(r,n.providerID,n.modelID)){let e=n.agent&&Zv(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&Zv(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):a&&Zv(r,a)?a:void 0,o=e?i?.getAgentModelVariantForSession?.(t,e,n.providerID,n.modelID):void 0,s=$v({catalog:r,providerID:n.providerID,modelID:n.modelID,historyVariant:n.variant,memoryVariant:o});return{agent:e,providerID:n.providerID,modelID:n.modelID,variant:s,source:`history`,messageId:n.id}}if(!i)return null;let o=i.getSessionAgentSelection?.(t)??null,s=o&&Zv(r,o)?o:a&&Zv(r,a)?a:void 0;if(s){let e=i.getAgentModelForSession?.(t,s);if(e&&Xv(r,e.providerId,e.modelId)){let n=i.getAgentModelVariantForSession?.(t,s,e.providerId,e.modelId),a=n&&Qv(r,e.providerId,e.modelId,n)?n:void 0;return{agent:s,providerID:e.providerId,modelID:e.modelId,variant:a,source:`session-memory`}}}let c=i.getSessionModelSelection?.(t);if(c&&Xv(r,c.providerId,c.modelId)){let e=s?i.getAgentModelVariantForSession?.(t,s,c.providerId,c.modelId):void 0,n=e&&Qv(r,c.providerId,c.modelId,e)?e:void 0;return{agent:s,providerID:c.providerId,modelID:c.modelId,variant:n,source:`session-memory`}}return null},ty=(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))},ny=(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}},ry=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}:{}}},iy=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},ay=500,oy=e=>Array.from(e).length,sy=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},cy=e=>oy(e)>=ay,ly=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},uy=(e,t)=>{let n=t??e;return typeof n!=`string`||!cy(n)?!1:ue(typeof e==`string`?{text:``,references:[]}:e,n)},dy=(e,t,n,r,i=1)=>{let a=oy(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}-${sy(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},fy=e=>({text:e.text,references:e.references.map(e=>({...e}))}),py=e=>e.map(e=>({...e,range:{...e.range}})),my=(e,t)=>e.text===t.text&&JSON.stringify(e.references)===JSON.stringify(t.references),hy=(e,t,n)=>({document:fy(e),mentions:py(t),selection:{...n}}),gy=()=>({undo:[],redo:[]}),_y=(e,t)=>({undo:[...e.undo,t].slice(-100),redo:[]}),vy=(e,t)=>{let n=e.undo.at(-1);return!n||!my(n.after.document,t)?null:{history:{undo:e.undo.slice(0,-1),redo:[...e.redo,n]},snapshot:hy(n.before.document,n.before.mentions,n.before.selection)}},yy=(e,t)=>{let n=e.redo.at(-1);return!n||!my(n.before.document,t)?null:{history:{undo:[...e.undo,n],redo:e.redo.slice(0,-1)},snapshot:hy(n.after.document,n.after.mentions,n.after.selection)}},by=e=>({text:e?.text??``,references:e?.composerReferences??[]}),xy=e=>({text:e.text,references:e.references.map(e=>({...e}))}),Sy=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),Cy=e=>JSON.stringify([e.text,e.references]),wy=(e,t)=>e!==null&&t!==null&&le(e)===t,Ty=(e,t,n)=>{let r=e?Sy(e):null,i=r?n(r):void 0;return{document:D(by(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?le(r):null}},Ey=(e,t,n,r)=>{if(!t||le(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=Cy(by(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===Cy(e)?`same-document-metadata`:`external-document`},Dy=(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}]:[]})},Oy=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),ky=(e,t,n,r,i=r)=>{let a=g(e,n,r,i);return{document:a.document,mentions:Dy(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},Ay=(e,t,n)=>({preview:{real:xy(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),jy=e=>({document:e.real,mentions:e.realMentions}),My=(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)})},Ny=(e,t)=>{let n=by(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:My(e.mentions,t?.mentions??[],r,i)}},Py=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=vt})=>{let a=e?le(e):null,o=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().drafts[a]:void 0,()=>void 0),s=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftHydration[a]??`idle`:`idle`,()=>`idle`),c=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftPersistence[a]:void 0,()=>void 0),[l,u]=(0,Z.useState)(()=>Ty(e,t,i.getState().getDraft).document),[d,p]=(0,Z.useState)(()=>Ty(e,t,i.getState().getDraft).mentions),[m,h]=(0,Z.useState)(`compose`),_=(0,Z.useRef)(l),b=(0,Z.useRef)(d),x=(0,Z.useRef)(t),S=(0,Z.useRef)(r),C=(0,Z.useRef)(e),w=(0,Z.useRef)(e?Sy(e):null),T=(0,Z.useRef)(a),E=(0,Z.useRef)(a),k=(0,Z.useRef)(0),A=(0,Z.useRef)(o?.revision??0),M=(0,Z.useRef)(void 0),N=(0,Z.useRef)(void 0),P=(0,Z.useRef)(gy());_.current=l,b.current=d,x.current=t,S.current=r,C.current=e,T.current=a;let F=(0,Z.useCallback)((e,t)=>{_.current=e,b.current=t,u(e),p(t)},[]),I=(0,Z.useCallback)((e,t)=>{let n=j(e,t);S.current?.(n)},[]);(0,Z.useEffect)(()=>{i.getState().setDraftPersistenceEnabled(n)},[n,i]),(0,Z.useLayoutEffect)(()=>{k.current+=1;let e=k.current;E.current=a;let t=Ty(C.current,x.current,i.getState().getDraft),n=t.key;if(w.current=t.key,M.current=void 0,N.current=void 0,P.current=gy(),h(`compose`),A.current=t.revision,F(t.document,t.mentions),n?.owner.kind===`draft`){let r=t.revision;i.getState().claimLegacyNewDraft(n).then(t=>{let o=i.getState().getDraft(n);!t||!wy(w.current,a)||E.current!==a||T.current!==a||k.current!==e||A.current!==r||o?.revision!==t.revision||(A.current=t.revision,F(D(by(t),x.current),t.mentions))})}},[a,F,i]),(0,Z.useEffect)(()=>{if(!a||E.current!==a||N.current)return;let e=Ey(_.current,o,M.current,{keyID:a,epoch:k.current,appliedRevision:A.current});if(e!==`ignore`){if(o&&(A.current=o.revision),e===`local-echo`||e===`same-document-metadata`){o&&p(o.mentions);return}e===`external-document`&&o&&(M.current=void 0,F(D(by(o),x.current),o.mentions),h(`compose`))}},[a,F,o]);let L=(0,Z.useCallback)((e,t)=>{let n=w.current;if(!wy(n,T.current)||N.current)return;let r=_.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:Oy(t)});if(!a)return;let o=by(a);return M.current={keyID:le(n),revision:a.revision,fingerprint:Cy(o)},A.current=a.revision,F(o,a.mentions),I(r,o),a},[i,F,I]),R=(0,Z.useCallback)((e,t,n,r,i,a)=>{P.current=_y(P.current,{before:hy(e,t,n),after:hy(r,i,a)})},[]),z=(0,Z.useCallback)(()=>N.current?(N.current=void 0,h(`compose`),!0):!1,[]),B=(0,Z.useCallback)(e=>(z(),L({text:e,references:[]},[])),[L,z]),V=(0,Z.useCallback)((e,t=[])=>{z();let n=oe(e.text,e.references);return n?L(D(n,x.current),t):void 0},[L,z]),H=(0,Z.useCallback)((e,t,n=t)=>{let r=z(),i=xy(_.current),a=r?[]:b.current,o=ky(i,a,e,t,n);return L(o.document,o.mentions),o.removedReferences.length>0&&R(i,a,{start:o.selectionStart,end:o.selectionEnd},o.document,o.mentions,{start:o.selectionStart,end:o.selectionEnd}),{start:o.selectionStart,end:o.selectionEnd,requiresTextCorrection:o.requiresTextCorrection}},[L,z,R]),U=(0,Z.useCallback)((e,t)=>{let n=_.current,r=Math.max(0,Math.min(e.start,n.text.length)),i=Math.max(r,Math.min(e.end,n.text.length)),a=z(),o=g(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=Dy(a?[]:b.current,o.document,o.edit);return L(o.document,t?t(s,o.document):s),{start:o.selectionStart,end:o.selectionEnd}},[L,z]),W=(0,Z.useCallback)((e,t)=>{let n=_.current;return U({start:0,end:n.text.length,text:e},t)},[U]),ee=(0,Z.useCallback)((e,t,n,r)=>{let i=z(),a=f(_.current,e,t,n,r);return L(a.document,Dy(i?[]:b.current,a.document,a.edit)),{start:a.caret,end:a.caret,caret:a.caret,document:a.document}},[L,z]),G=(0,Z.useCallback)(e=>{let t=xy(_.current),n=y(t,e);if(!n)return null;let r=z()?[]:b.current,i=Dy(r,n.document,n.edit),a=O(n.document.text,n.caret),o=g(n.document,a.text,a.caret),s=Dy(i,o.document,o.edit);return L(o.document,s),R(t,r,{start:e.selectionStart,end:e.selectionEnd},o.document,s,{start:o.selectionStart,end:o.selectionEnd}),{start:o.selectionStart,end:o.selectionEnd}},[L,z,R]),K=(0,Z.useCallback)(e=>{if(N.current)return null;let t=e===`undo`?vy(P.current,_.current):yy(P.current,_.current);return!t||!L(t.snapshot.document,t.snapshot.mentions)?null:(P.current=t.history,t.snapshot.selection)},[L]),te=(0,Z.useCallback)(e=>L(_.current,e),[L]),ne=(0,Z.useCallback)(e=>{let t=N.current?{document:{text:e.text,references:[]},mentions:[]}:Ay(_.current,b.current,e);`preview`in t&&(N.current=t.preview),h(`history-preview`),F(t.document,t.mentions)},[F]),re=(0,Z.useCallback)(()=>{let e=N.current;if(!e)return;N.current=void 0,h(`compose`);let t=jy(e);F(t.document,t.mentions)},[F]),ie=(0,Z.useCallback)(()=>{let e=w.current;if(!wy(e,T.current))return null;let t=i.getState().getDraft(e);return{key:Sy(e),keyID:le(e),revision:t?.revision??0,document:xy(_.current),mentions:b.current.map(e=>({...e,range:{...e.range}})),epoch:k.current,runtime:i.getState().captureDraftRuntime()}},[i]),ae=(0,Z.useCallback)(e=>{let t=Ny(e,i.getState().getDraft(e.key)),n=by(i.getState().getDraft(e.key)),r=v(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:Oy(t.mentions)});if(a){let e=by(a);I(r,e)}return a},[I,i]),se=(0,Z.useCallback)(()=>_.current,[]);return(0,Z.useMemo)(()=>({document:l,mentions:d,confirmedFileMentions:d.filter(e=>e.kind===`file`||e.kind===`directory`),inputMode:m,hydration:s,persistence:c,getDocument:se,replacePlainDocument:B,replaceMaterializedDocument:V,applyBrowserEdit:H,applyProgrammaticEdit:U,replaceProgrammaticText:W,insertReference:ee,deleteReference:G,restoreReferenceHistory:K,commitMentions:te,enterHistoryPreview:ne,exitHistoryPreview:re,captureSubmission:ie,recoverSubmission:ae}),[H,U,ie,te,G,l,ne,re,se,s,m,ee,d,c,ae,V,B,W,K])};function Fy(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 Iy=`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`,Ly=Lo(()=>Ue(()=>import(`./ToolOutputDialog-BST1ibJ-.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]))),Ry=[],zy=[],By=[],Vy=[],Hy=/^@[^\s]+$/,Uy=({inputMode:e,message:t,showCommandAutocomplete:n,showSkillAutocomplete:r})=>e!==`shell`&&(n||r||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),Wy=/^(https?:\/\/|mailto:)\S+$/i,Gy=560,Ky=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),qy=(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)},Jy=e=>e.includes(`@`)?`paste`:`manual`,Yy=(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}},Xy=(e,t)=>ur(e,t).some(e=>e.role===`user`),Zy=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!Yn(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
|
|
6524
|
+
`);if(d.trim()&&(t.push({start:s,end:s+d.length,style:`codeFence`,className:`${z_} text-[var(--syntax-foreground)]`,priority:B_}),!(d.length>K_)))try{let e=o.parser.parse(d);Xe(e,W_,(e,n,r)=>{let i=G_(r);i&&t.push({start:s+e,end:s+n,style:`codeFence`,className:i,priority:V_})})}catch{}}return t}var Y_=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],X_=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),Z_=e=>{if(!X_(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(`/`)},Q_=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?Z_(n):X_(n))?n:null},$_=(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)$_(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))$_(r,t,n+1)}},ev=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=Q_(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=Q_(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;$_(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},tv=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of Y_){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 ev(r,i))t.add(e)}return Array.from(t)},nv=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}}},rv=e=>X_(e);function iv(e,t){let n=(0,Q.c)(5),r=rn(e,t),i=c(av),a;n[0]===r?a=n[1]:(a=pn(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 av(e){return e.sessionGoalEnabled}function ov(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 Nt(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 sv={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},cv={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`},lv=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=ot(),i=c(e=>e.isMobile),{goal:a,enabled:o}=iv(e??``,t),s=ov(e??``,a),l=dr(e??``,t),u=bi(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,At(e,t))},[e,t,a,u]);let g=q(async n=>{if(!(!e||f)){p(!0);try{await Cn(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),Ii.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?`${Kr(a.tokensUsed)}/${Kr(a.tokenBudget)}`:a.tokensUsed>0?Kr(a.tokensUsed):null,b=a.status===`active`?{icon:`pause`,labelKey:`chat.goal.action.pause`,next:`paused`}:a.status===`paused`||a.status===`blocked`||a.status===`budgetLimited`?{icon:`play`,labelKey:`chat.goal.action.resume`,next:`active`}:null,x=i?`text-[11px] leading-none text-muted-foreground`:`typography-meta text-muted-foreground`,S=i?`text-xs leading-5 text-foreground`:`typography-ui-label leading-5 text-foreground`,C=i?`size-3`:`size-3.5`;return(0,$.jsxs)(`div`,{className:Y(`flex w-full min-w-0 items-center`,i?`gap-1 py-0.5`:`gap-1.5 py-0.5 md:gap-2`,n),"aria-label":r(`chat.goal.row.aria`),title:s??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(C,`flex-shrink-0`),style:{color:sv[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,S),children:a.note||s||``}),a.status===`active`&&(!l||l.type===`idle`)?(0,$.jsxs)(`span`,{className:Y(`flex flex-shrink-0 items-center gap-1`,x),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(C,`animate-spin`),"aria-hidden":`true`}),r(`chat.goal.status.evaluating`)]}):(0,$.jsx)(`span`,{className:Y(`flex-shrink-0`,x),children:r(cv[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]})});lv.displayName=`SessionGoalRow`;var uv=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=ot(),{goal:i,enabled:a}=iv(e??``,t),o=kt(e=>e.armed),s=kt(e=>e.setArmed),[c,l]=Z.useState(!1);if(d()||!a||!e&&!n||!o&&!i)return null;let u=i?.status===`complete`?`text-[var(--status-success)]`:i?.status===`blocked`||i?.status===`budgetLimited`?`text-[var(--status-error)]`:o||i?.status===`active`||i?.status===`paused`?`text-[var(--status-info)]`:``,f=async()=>{if(o){s(!1);return}if(!(!e||c)){l(!0);try{await Rn(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),Ii.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`})})]})});uv.displayName=`SessionGoalButton`;var dv=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=ot();if(!kt(fv)||n===0)return null;let i=n>5e3?`text-[var(--status-error)]`:`text-muted-foreground/70`,a;t[0]===i?a=t[1]:(a=Y(`flex-shrink-0 self-center typography-micro tabular-nums`,i),t[0]=i,t[1]=a);let o;t[2]===r?o=t[3]:(o=r(`chat.goal.counter.aria`),t[2]=r,t[3]=o);let s;t[4]===r?s=t[5]:(s=r(`chat.goal.counter.aria`),t[4]=r,t[5]=s);let c;return t[6]!==n||t[7]!==a||t[8]!==o||t[9]!==s?(c=(0,$.jsxs)(`span`,{className:a,"aria-label":o,title:s,children:[n,`/`,Xr]}),t[6]=n,t[7]=a,t[8]=o,t[9]=s,t[10]=c):c=t[10],c});dv.displayName=`SessionGoalObjectiveCounter`;function fv(e){return e.armed}var pv=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`plan-feature`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`]),mv=new Set([`compact`,`fork`,`undo`,`redo`]),hv=/^\/\u2003?([^\s]+)/i,gv=/^\/\u2003?goal\b/i,_v=(e,t)=>{if(t!==`normal`)return null;let n=e.trimStart().match(hv)?.[1]?.toLowerCase();return n&&pv.has(n)?n:null},vv=(e,t)=>_v(e,t)===`goal`?e.trimStart().replace(gv,``).trim():null,yv=(e,t)=>_v(e,t)!==null,bv=(e,t)=>{let n=_v(e,t);return n!==null&&mv.has(n)},xv=(e,t)=>{if(!e.includes(`/`)||t.size===0)return[];let n=RegExp(`(^|\\s)/(${ee})?([A-Za-z0-9][A-Za-z0-9_-]*)(?=$|\\s)`,`g`),r=[],i;for(;(i=n.exec(e))!==null;){let e=i[3]??``;if(!t.has(e.toLowerCase()))continue;let n=i[2]??``,a=i.index+(i[1]?.length??0);r.push({start:a,end:a+1+n.length+e.length,name:e,hasSlot:n.length>0})}return r},Sv=(e,t,n=e.length)=>{let r=xv(e,t).filter(e=>!e.hasSlot);if(r.length===0)return null;let i=e,a=n;for(let e=r.length-1;e>=0;--e){let t=r[e].start+1;i=`${i.slice(0,t)}${ee}${i.slice(t)}`,a>t&&(a+=ee.length)}return i===e?null:{text:i,caret:a}},Cv=e=>e.startsWith(ee)?e.slice(ee.length):e,wv=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},Tv=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()}},Ev=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,Dv=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,Ov=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},kv=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),Av=(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},jv=async e=>{let t=En.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=kv(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}Av(n,a)?r+=1:i+=1}catch{try{Av(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},Mv=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),Nv=e=>e===`allow`||e===`ask`||e===`deny`,Pv=e=>{if(Nv(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`&&Nv(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(Nv(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))Nv(i)&&t.push({permission:n,pattern:e,action:i})}return t},Fv=e=>{let t=Pv(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},Iv=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>Fv(e.permission));let r=e.find(e=>e?.name===n);return!r||Fv(r.permission)},Lv=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)},Rv=null,zv=new Set,Bv=()=>{for(let e of zv)e()},Vv=e=>e===`chat`||e===`assistant`,Hv=()=>Rv,Uv=e=>{Rv!==e&&(Rv=e,Bv())},Wv=e=>{Rv&&(e&&Rv.surfaceID!==e||(Rv=null,Bv()))},Gv=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},Kv=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}},qv=(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}),Jv=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=qv(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=qv(e,`send`,i),o=cm(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=qv(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=qv(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=qv(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:cm(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>tm(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=qv(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=qv(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},Yv=(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)))},Xv=(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},Zv=(e,t)=>e.agents.some(e=>e.name===t),Qv=(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},$v=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return Qv(t,n,r,i)?i:void 0;if(a&&Qv(t,n,r,a))return a},ey=e=>{let{sessionId:t,latestUserChoice:n,catalog:r,memory:i,fallbackAgentName:a}=e;if(n?.providerID&&n.modelID&&Xv(r,n.providerID,n.modelID)){let e=n.agent&&Zv(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&Zv(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):a&&Zv(r,a)?a:void 0,o=e?i?.getAgentModelVariantForSession?.(t,e,n.providerID,n.modelID):void 0,s=$v({catalog:r,providerID:n.providerID,modelID:n.modelID,historyVariant:n.variant,memoryVariant:o});return{agent:e,providerID:n.providerID,modelID:n.modelID,variant:s,source:`history`,messageId:n.id}}if(!i)return null;let o=i.getSessionAgentSelection?.(t)??null,s=o&&Zv(r,o)?o:a&&Zv(r,a)?a:void 0;if(s){let e=i.getAgentModelForSession?.(t,s);if(e&&Xv(r,e.providerId,e.modelId)){let n=i.getAgentModelVariantForSession?.(t,s,e.providerId,e.modelId),a=n&&Qv(r,e.providerId,e.modelId,n)?n:void 0;return{agent:s,providerID:e.providerId,modelID:e.modelId,variant:a,source:`session-memory`}}}let c=i.getSessionModelSelection?.(t);if(c&&Xv(r,c.providerId,c.modelId)){let e=s?i.getAgentModelVariantForSession?.(t,s,c.providerId,c.modelId):void 0,n=e&&Qv(r,c.providerId,c.modelId,e)?e:void 0;return{agent:s,providerID:c.providerId,modelID:c.modelId,variant:n,source:`session-memory`}}return null},ty=(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))},ny=(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}},ry=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}:{}}},iy=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},ay=500,oy=e=>Array.from(e).length,sy=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},cy=e=>oy(e)>=ay,ly=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},uy=(e,t)=>{let n=t??e;return typeof n!=`string`||!cy(n)?!1:ue(typeof e==`string`?{text:``,references:[]}:e,n)},dy=(e,t,n,r,i=1)=>{let a=oy(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}-${sy(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},fy=e=>({text:e.text,references:e.references.map(e=>({...e}))}),py=e=>e.map(e=>({...e,range:{...e.range}})),my=(e,t)=>e.text===t.text&&JSON.stringify(e.references)===JSON.stringify(t.references),hy=(e,t,n)=>({document:fy(e),mentions:py(t),selection:{...n}}),gy=()=>({undo:[],redo:[]}),_y=(e,t)=>({undo:[...e.undo,t].slice(-100),redo:[]}),vy=(e,t)=>{let n=e.undo.at(-1);return!n||!my(n.after.document,t)?null:{history:{undo:e.undo.slice(0,-1),redo:[...e.redo,n]},snapshot:hy(n.before.document,n.before.mentions,n.before.selection)}},yy=(e,t)=>{let n=e.redo.at(-1);return!n||!my(n.before.document,t)?null:{history:{undo:[...e.undo,n],redo:e.redo.slice(0,-1)},snapshot:hy(n.after.document,n.after.mentions,n.after.selection)}},by=e=>({text:e?.text??``,references:e?.composerReferences??[]}),xy=e=>({text:e.text,references:e.references.map(e=>({...e}))}),Sy=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),Cy=e=>JSON.stringify([e.text,e.references]),wy=(e,t)=>e!==null&&t!==null&&le(e)===t,Ty=(e,t,n)=>{let r=e?Sy(e):null,i=r?n(r):void 0;return{document:D(by(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?le(r):null}},Ey=(e,t,n,r)=>{if(!t||le(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=Cy(by(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===Cy(e)?`same-document-metadata`:`external-document`},Dy=(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}]:[]})},Oy=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),ky=(e,t,n,r,i=r)=>{let a=g(e,n,r,i);return{document:a.document,mentions:Dy(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},Ay=(e,t,n)=>({preview:{real:xy(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),jy=e=>({document:e.real,mentions:e.realMentions}),My=(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)})},Ny=(e,t)=>{let n=by(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:My(e.mentions,t?.mentions??[],r,i)}},Py=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=vt})=>{let a=e?le(e):null,o=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().drafts[a]:void 0,()=>void 0),s=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftHydration[a]??`idle`:`idle`,()=>`idle`),c=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftPersistence[a]:void 0,()=>void 0),[l,u]=(0,Z.useState)(()=>Ty(e,t,i.getState().getDraft).document),[d,p]=(0,Z.useState)(()=>Ty(e,t,i.getState().getDraft).mentions),[m,h]=(0,Z.useState)(`compose`),_=(0,Z.useRef)(l),b=(0,Z.useRef)(d),x=(0,Z.useRef)(t),S=(0,Z.useRef)(r),C=(0,Z.useRef)(e),w=(0,Z.useRef)(e?Sy(e):null),T=(0,Z.useRef)(a),E=(0,Z.useRef)(a),k=(0,Z.useRef)(0),A=(0,Z.useRef)(o?.revision??0),M=(0,Z.useRef)(void 0),N=(0,Z.useRef)(void 0),P=(0,Z.useRef)(gy());_.current=l,b.current=d,x.current=t,S.current=r,C.current=e,T.current=a;let F=(0,Z.useCallback)((e,t)=>{_.current=e,b.current=t,u(e),p(t)},[]),I=(0,Z.useCallback)((e,t)=>{let n=j(e,t);S.current?.(n)},[]);(0,Z.useEffect)(()=>{i.getState().setDraftPersistenceEnabled(n)},[n,i]),(0,Z.useLayoutEffect)(()=>{k.current+=1;let e=k.current;E.current=a;let t=Ty(C.current,x.current,i.getState().getDraft),n=t.key;if(w.current=t.key,M.current=void 0,N.current=void 0,P.current=gy(),h(`compose`),A.current=t.revision,F(t.document,t.mentions),n?.owner.kind===`draft`){let r=t.revision;i.getState().claimLegacyNewDraft(n).then(t=>{let o=i.getState().getDraft(n);!t||!wy(w.current,a)||E.current!==a||T.current!==a||k.current!==e||A.current!==r||o?.revision!==t.revision||(A.current=t.revision,F(D(by(t),x.current),t.mentions))})}},[a,F,i]),(0,Z.useEffect)(()=>{if(!a||E.current!==a||N.current)return;let e=Ey(_.current,o,M.current,{keyID:a,epoch:k.current,appliedRevision:A.current});if(e!==`ignore`){if(o&&(A.current=o.revision),e===`local-echo`||e===`same-document-metadata`){o&&p(o.mentions);return}e===`external-document`&&o&&(M.current=void 0,F(D(by(o),x.current),o.mentions),h(`compose`))}},[a,F,o]);let L=(0,Z.useCallback)((e,t)=>{let n=w.current;if(!wy(n,T.current)||N.current)return;let r=_.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:Oy(t)});if(!a)return;let o=by(a);return M.current={keyID:le(n),revision:a.revision,fingerprint:Cy(o)},A.current=a.revision,F(o,a.mentions),I(r,o),a},[i,F,I]),R=(0,Z.useCallback)((e,t,n,r,i,a)=>{P.current=_y(P.current,{before:hy(e,t,n),after:hy(r,i,a)})},[]),z=(0,Z.useCallback)(()=>N.current?(N.current=void 0,h(`compose`),!0):!1,[]),B=(0,Z.useCallback)(e=>(z(),L({text:e,references:[]},[])),[L,z]),V=(0,Z.useCallback)((e,t=[])=>{z();let n=oe(e.text,e.references);return n?L(D(n,x.current),t):void 0},[L,z]),H=(0,Z.useCallback)((e,t,n=t)=>{let r=z(),i=xy(_.current),a=r?[]:b.current,o=ky(i,a,e,t,n);return L(o.document,o.mentions),o.removedReferences.length>0&&R(i,a,{start:o.selectionStart,end:o.selectionEnd},o.document,o.mentions,{start:o.selectionStart,end:o.selectionEnd}),{start:o.selectionStart,end:o.selectionEnd,requiresTextCorrection:o.requiresTextCorrection}},[L,z,R]),U=(0,Z.useCallback)((e,t)=>{let n=_.current,r=Math.max(0,Math.min(e.start,n.text.length)),i=Math.max(r,Math.min(e.end,n.text.length)),a=z(),o=g(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=Dy(a?[]:b.current,o.document,o.edit);return L(o.document,t?t(s,o.document):s),{start:o.selectionStart,end:o.selectionEnd}},[L,z]),W=(0,Z.useCallback)((e,t)=>{let n=_.current;return U({start:0,end:n.text.length,text:e},t)},[U]),ee=(0,Z.useCallback)((e,t,n,r)=>{let i=z(),a=f(_.current,e,t,n,r);return L(a.document,Dy(i?[]:b.current,a.document,a.edit)),{start:a.caret,end:a.caret,caret:a.caret,document:a.document}},[L,z]),G=(0,Z.useCallback)(e=>{let t=xy(_.current),n=y(t,e);if(!n)return null;let r=z()?[]:b.current,i=Dy(r,n.document,n.edit),a=O(n.document.text,n.caret),o=g(n.document,a.text,a.caret),s=Dy(i,o.document,o.edit);return L(o.document,s),R(t,r,{start:e.selectionStart,end:e.selectionEnd},o.document,s,{start:o.selectionStart,end:o.selectionEnd}),{start:o.selectionStart,end:o.selectionEnd}},[L,z,R]),K=(0,Z.useCallback)(e=>{if(N.current)return null;let t=e===`undo`?vy(P.current,_.current):yy(P.current,_.current);return!t||!L(t.snapshot.document,t.snapshot.mentions)?null:(P.current=t.history,t.snapshot.selection)},[L]),te=(0,Z.useCallback)(e=>L(_.current,e),[L]),ne=(0,Z.useCallback)(e=>{let t=N.current?{document:{text:e.text,references:[]},mentions:[]}:Ay(_.current,b.current,e);`preview`in t&&(N.current=t.preview),h(`history-preview`),F(t.document,t.mentions)},[F]),re=(0,Z.useCallback)(()=>{let e=N.current;if(!e)return;N.current=void 0,h(`compose`);let t=jy(e);F(t.document,t.mentions)},[F]),ie=(0,Z.useCallback)(()=>{let e=w.current;if(!wy(e,T.current))return null;let t=i.getState().getDraft(e);return{key:Sy(e),keyID:le(e),revision:t?.revision??0,document:xy(_.current),mentions:b.current.map(e=>({...e,range:{...e.range}})),epoch:k.current,runtime:i.getState().captureDraftRuntime()}},[i]),ae=(0,Z.useCallback)(e=>{let t=Ny(e,i.getState().getDraft(e.key)),n=by(i.getState().getDraft(e.key)),r=v(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:Oy(t.mentions)});if(a){let e=by(a);I(r,e)}return a},[I,i]),se=(0,Z.useCallback)(()=>_.current,[]);return(0,Z.useMemo)(()=>({document:l,mentions:d,confirmedFileMentions:d.filter(e=>e.kind===`file`||e.kind===`directory`),inputMode:m,hydration:s,persistence:c,getDocument:se,replacePlainDocument:B,replaceMaterializedDocument:V,applyBrowserEdit:H,applyProgrammaticEdit:U,replaceProgrammaticText:W,insertReference:ee,deleteReference:G,restoreReferenceHistory:K,commitMentions:te,enterHistoryPreview:ne,exitHistoryPreview:re,captureSubmission:ie,recoverSubmission:ae}),[H,U,ie,te,G,l,ne,re,se,s,m,ee,d,c,ae,V,B,W,K])};function Fy(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 Iy=`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`,Ly=Lo(()=>Ue(()=>import(`./ToolOutputDialog-B-3Wg0na.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]))),Ry=[],zy=[],By=[],Vy=[],Hy=/^@[^\s]+$/,Uy=({inputMode:e,message:t,showCommandAutocomplete:n,showSkillAutocomplete:r})=>e!==`shell`&&(n||r||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),Wy=/^(https?:\/\/|mailto:)\S+$/i,Gy=560,Ky=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),qy=(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)},Jy=e=>e.includes(`@`)?`paste`:`manual`,Yy=(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}},Xy=(e,t)=>ur(e,t).some(e=>e.role===`user`),Zy=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!Yn(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
|
|
6525
6525
|
`).replace(/\s+/g,` `).trim();if(n)return n;let r=e.find(e=>e.type===`file`);return r?.filename?`[${r.filename}]`:t},Qy=`file://`,$y=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(`/`)},eb=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(Qy)?t:`file://${$y(t)}`},tb=e=>{if(!e)return[];let t=[...tv(e).map(nv),...Array.from(e.files||[]).map(e=>k(e)).filter(e=>!!e)];return Array.from(new Set(t.filter(rv)))},nb=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},rb=e=>ra(e.path),ib=(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)]})},ab=Z.memo(Om),ob=Z.memo(ml),sb=Z.memo(Ih),cb=Z.memo(zh),lb=Z.memo(rh),ub=Z.memo(({sessionId:e,directory:t})=>{let{t:n}=ot(),r=c(e=>e.isMobile),i=J(e=>e.revertToMessage),a=J(e=>e.forkFromMessage),o=J(e=>e.handleSlashRedo),[s,l]=Z.useState(null),[u,d]=Z.useState(null),[f,p]=Z.useState(!0),m=Z.useRef(x_),h=xr(),g=t||h,_=wt(g),v=yr(e??``,g,_),y=Zn(e=>e.session,g),b=Z.useMemo(()=>{let t=v.messageOrder.map(e=>v.messagesByID[e]).filter(e=>!!e),n=w_({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:Zy(e.parts,C)})):[],[C,x,b]),T=w[0]?.id;Z.useEffect(()=>{p(!0)},[x,T]);let E=Z.useCallback(async t=>{if(!(!e||s)){l(t);try{let n=S.find(e=>e.id>t);n?await i(e,n.id,{skipRedoPush:!0}):await o(e,{fullUnrevert:!0})}finally{l(null)}}},[o,i,s,e,S]),D=Z.useCallback(async t=>{if(!(!e||u)){d(t);try{await a(e,t)}finally{d(null)}}},[a,u,e]);return!e||w.length===0?null:(0,$.jsx)(`div`,{className:Y(`w-full px-1`,r?`pb-1 text-xs`:`pb-2`),children:(0,$.jsxs)(`div`,{className:Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,r?`rounded-lg`:`rounded-xl`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex w-full items-center text-left hover:bg-[var(--interactive-hover)] transition-colors`,r?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`),onClick:()=>p(e=>!e),"aria-expanded":!f,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground flex-shrink-0`,children:[n(`chat.revertPopover.title`),` messages `,w.length]}),(0,$.jsx)(X,{name:`arrow-down-s`,className:Y(`ml-auto text-muted-foreground transition-transform`,r?`size-3.5`:`size-4`,!f&&`rotate-180`),"aria-hidden":`true`})]}),!f&&(0,$.jsx)(`div`,{className:Y(`flex flex-col overflow-y-auto`,r?`max-h-[8rem] gap-1 px-2 pb-1.5`:`max-h-[10.5rem] gap-1.5 px-3 pb-3`),children:w.map(e=>(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 items-center`,r?`gap-1.5`:`gap-2 py-1`),children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-ui-label text-foreground`,children:e.text}),(0,$.jsxs)(da,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||u),onClick:()=>{D(e.id)},children:[u===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`git-branch`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.fork`)]}),(0,$.jsxs)(da,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||u),onClick:()=>{E(e.id)},children:[s===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`arrow-go-forward`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.restore`)]})]},e.id))})]})})});ub.displayName=`RevertedMessageDock`;var db=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?xb:void 0,v=f?Sb: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)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:S}),(0,$.jsx)(za,{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),fb=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=()=>Lv({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)(Ra,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:o,"aria-pressed":s,"aria-label":a,className:c,onClick:l,onMouseDown:Cb,onPointerDownCapture:wb,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)(za,{side:`top`,sideOffset:8,children:a}),t[24]=a,t[25]=m);let h;return t[26]!==m||t[27]!==p?(h=(0,$.jsxs)(Ba,{children:[p,m]}),t[26]=m,t[27]=p,t[28]=h):h=t[28],h}),pb=Z.memo(function(e){let t=(0,Q.c)(59),{isMobile:n,footerIconButtonClass:r,sendIconSizeClass:i,stopIconSizeClass:a,canSend:o,canAbort:s,hasContent:c,currentSessionId:l,newSessionDraftOpen:u,draftSubmitting:d,submissionBlocked:f,sendPhase:p,queueFrozen:m,queueFallbackAvailable:h,onPrimaryAction:g,onAbort:_}=e,{t:v}=ot(),y,b,x;if(t[0]!==s||t[1]!==o||t[2]!==l||t[3]!==d||t[4]!==r||t[5]!==c||t[6]!==n||t[7]!==u||t[8]!==g||t[9]!==h||t[10]!==m||t[11]!==i||t[12]!==p||t[13]!==f||t[14]!==v){x=Symbol.for(`react.early_return_sentinel`);bb0:{let e=Qh({canSend:o,hasSessionTarget:!!(l||u),draftSubmitting:!!d,submissionBlocked:f,sendPhase:p,queueFrozen:m,queueFallbackAvailable:h}),a;t[18]===n?a=t[19]:(a=n?{onMouseDown:Tb,onPointerDownCapture:Eb}:{},t[18]=n,t[19]=a);let _=a,S=p.inFlight,C=S&&p.flightKind===`queue`,w=S&&p.flightKind!==`queue`,T;t[20]!==s||t[21]!==h||t[22]!==m||t[23]!==C||t[24]!==w||t[25]!==v?(T=v(C?`chat.chatInput.actions.queuingMessageAria`:w?`chat.chatInput.actions.sendingMessageAria`:m&&h&&s?`chat.chatInput.actions.sendMessageAria`:s?`chat.chatInput.actions.queueMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[20]=s,t[21]=h,t[22]=m,t[23]=C,t[24]=w,t[25]=v,t[26]=T):T=t[26];let E=T,D=S?`loader-4`:`send-plane-2`,O=e.sendDisabled,k;t[27]!==n||t[28]!==g?(k=e=>{n&&(e.preventDefault(),g())},t[27]=n,t[28]=g,t[29]=k):k=t[29];let A=Y(r,e.sendDisabled?e.disabledClass:`text-primary hover:text-primary`),j;t[30]!==s||t[31]!==S||t[32]!==C||t[33]!==w||t[34]!==v?(j=v(w||!s&&S?C?`chat.chatInput.actions.queuingMessageAria`:`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[30]=s,t[31]=S,t[32]=C,t[33]=w,t[34]=v,t[35]=j):j=t[35];let M=S?`loader-4`:`send-plane-2`,N=S&&`animate-spin`,P;t[36]!==i||t[37]!==N?(P=Y(i,N),t[36]=i,t[37]=N,t[38]=P):P=t[38];let F;t[39]!==P||t[40]!==M?(F=(0,$.jsx)(X,{name:M,className:P}),t[39]=P,t[40]=M,t[41]=F):F=t[41];let I=(0,$.jsx)(`button`,{type:n?`button`:`submit`,disabled:O,"aria-busy":S||void 0,..._,onClick:k,className:A,"aria-label":j,children:F});if(!s){x=I;break bb0}y=`relative z-30 overflow-visible`,b=c||C?(0,$.jsx)(`button`,{type:`button`,disabled:e.sendDisabled||C,"aria-busy":C||void 0,..._,onClick:e=>{e.preventDefault(),!C&&g()},className:Y(r,`absolute z-30 bottom-full left-1/2 -translate-x-1/2 mb-1`,!e.sendDisabled&&!C?`text-primary hover:text-primary`:e.disabledClass),"aria-label":E,children:(0,$.jsx)(X,{name:D,className:Y(i,C?`animate-spin`:`-rotate-90`)})}):null}t[0]=s,t[1]=o,t[2]=l,t[3]=d,t[4]=r,t[5]=c,t[6]=n,t[7]=u,t[8]=g,t[9]=h,t[10]=m,t[11]=i,t[12]=p,t[13]=f,t[14]=v,t[15]=y,t[16]=b,t[17]=x}else y=t[15],b=t[16],x=t[17];if(x!==Symbol.for(`react.early_return_sentinel`))return x;let S;t[42]===r?S=t[43]:(S=Y(r,`relative z-30 text-[var(--status-error)] hover:text-[var(--status-error)]`),t[42]=r,t[43]=S);let C;t[44]===v?C=t[45]:(C=v(`chat.chatInput.actions.stopGeneratingAria`),t[44]=v,t[45]=C);let w;t[46]===a?w=t[47]:(w=Y(a),t[46]=a,t[47]=w);let T;t[48]===w?T=t[49]:(T=(0,$.jsx)(Gh,{className:w}),t[48]=w,t[49]=T);let E;t[50]!==_||t[51]!==S||t[52]!==C||t[53]!==T?(E=(0,$.jsx)(`button`,{type:`button`,onClick:_,className:S,"aria-label":C,children:T}),t[50]=_,t[51]=S,t[52]=C,t[53]=T,t[54]=E):E=t[54];let D;return t[55]!==y||t[56]!==b||t[57]!==E?(D=(0,$.jsxs)(`div`,{className:y,children:[b,E]}),t[55]=y,t[56]=b,t[57]=E,t[58]=D):D=t[58],D},(e,t)=>e.isMobile===t.isMobile&&e.footerIconButtonClass===t.footerIconButtonClass&&e.sendIconSizeClass===t.sendIconSizeClass&&e.stopIconSizeClass===t.stopIconSizeClass&&e.canSend===t.canSend&&e.canAbort===t.canAbort&&e.hasContent===t.hasContent&&e.currentSessionId===t.currentSessionId&&e.newSessionDraftOpen===t.newSessionDraftOpen&&e.draftSubmitting===t.draftSubmitting&&e.submissionBlocked===t.submissionBlocked&&e.sendPhase===t.sendPhase&&e.queueFrozen===t.queueFrozen&&e.queueFallbackAvailable===t.queueFallbackAvailable&&e.onPrimaryAction===t.onPrimaryAction&&e.onAbort===t.onAbort),mb=(e,t)=>`${e}${e?e.endsWith(`
|
|
6526
6526
|
|
|
6527
6527
|
`)?``:e.endsWith(`
|
|
@@ -6531,11 +6531,11 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{D as t,E as n,F as r,T
|
|
|
6531
6531
|
`:``}${t.endsWith(`
|
|
6532
6532
|
|
|
6533
6533
|
`)?t:t.endsWith(`
|
|
6534
|
-
`)?`${t}\n`:`${t}\n\n`}`,hb=(e,t)=>{let n=t.trim();return n?e?`${e}${/[\s\n]$/.test(e)?``:` `}${n} `:`${n} `:e},gb=(e,t,n,r)=>t?h({transportIdentity:e},t):n?m({transportIdentity:e},n):r,_b=[],vb=({onOpenSettings:e,scrollToBottom:r,submissionBlocked:a=!1,surface:o})=>{let{t:l}=ot(),[u,f]=Z.useState({open:!1,title:``,content:``}),[p,m]=Z.useState(`normal`),[h,g]=Z.useState(!1),[y,w]=Z.useState(!1),[T,E]=Z.useState(!1),[D,O]=Z.useState(``),[k,j]=Z.useState(!1),[M,N]=Z.useState(``),[P,I]=Z.useState(!1),[R,z]=Z.useState(``),[V,H]=Z.useState(!1),[te,ne]=Z.useState(``),[ae,oe]=Z.useState(null),[se,ce]=Z.useState(null),[ue,de]=Z.useState(!1),[fe,pe]=Z.useState(`idle`),[me,he]=Z.useState(112),ge=Z.useRef(null),[_e,ve]=Z.useState(!1),ye=Z.useRef(null),[be,xe]=Z.useState(`collapsed`),Se=q(()=>ve(!0)),[Ce,De]=Z.useState(!1),Ae=Z.useRef(null);Z.useEffect(()=>()=>{Ae.current!==null&&window.clearTimeout(Ae.current)},[]);let[Me,Ne]=Z.useState(!1),[Pe,Fe]=Z.useState(!1),[Ie,ze]=Z.useState(!1),[Ve,He]=Z.useState(null),Ue=Z.useId(),[We,Ge]=Z.useState(``),[Ke,qe]=Z.useState(``),[Je,Ye]=Z.useState(!1),[Xe,Ze]=Z.useState(!1),Qe=Z.useRef(null),$e=Z.useRef(0),et=Z.useCallback(()=>{$e.current=Date.now()+500,Qe.current=null},[]),tt=Z.useRef(0),nt=Z.useRef(!1),[rt,it]=Z.useState(-1),at=Z.useRef(()=>{}),st=Z.useRef((...e)=>Promise.resolve().then(()=>J.getState().sendMessage(...e))).current,ct=J(e=>e.currentSessionId),lt=Ei(e=>e.currentProviderId),ut=Ei(e=>e.currentModelId),ft=Ei(e=>e.currentAgentName),pt=Ei(e=>e.currentVariant),mt=Ei(e=>e.providers),ht=Ei(e=>e.agents),gt=Ei(e=>e.getVisibleAgents),_t=Z.useMemo(()=>Gp(gt()),[gt,ht]),yt=Ei(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),St=Ei(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),Ct=Z.useMemo(()=>{let e=mt.find(e=>e.id===lt)?.models?.find(e=>e.id===ut);return Qp(e)},[ut,lt,mt]),wt=Te(e=>e.currentDirectory),Tt=os()??wt,{ensureSessionRenderable:Et}=Bl(),Dt=J(Z.useCallback(e=>ct?e.getDirectoryForSession(ct):null,[ct])),Ot=Tr(ct??``,Dt??void 0),At=Z.useMemo(()=>iy(Ot),[Ot]),jt=Ei(e=>e.activeDirectoryKey),Nt=Z.useRef(0),Pt=Z.useRef(null),Ft=J(e=>e.newSessionDraft),Lt=!!Ft?.open,Rt=J(e=>e.newSessionDraft.draftSubmitting??!1),zt=J(e=>e.newSessionDraft.draftEstablishing??!1),Ht=Rt||zt,Ut=J(e=>e.openNewSessionDraft),Wt=J(e=>e.setDraftPermissionAutoAcceptEnabled),Gt=cr(e=>e.autoAccept),qt=cr(e=>e.saving),Jt=cr(e=>e.setSessionAutoAccept),Yt=J(e=>e.setNewSessionDraftTarget),Zt=J(e=>e.availableWorktreesByProject),$t=J(e=>e.abortPromptSessionId),tn=J(e=>e.clearAbortPrompt),rn=vt(e=>e.consumePendingInputText),sn=vt(e=>e.pendingPresetSubmit),cn=vt(e=>e.pendingInputText),ln=vt(e=>e.pendingInputMode),dn=vt(e=>e.consumePendingSyntheticParts),pn=vt(e=>e.activeAttachmentDraft),hn=Kl(Z.useCallback(e=>{let t=ct??(Lt?`draft`:``);return t?e.drafts[t]??zy:zy},[Lt,ct])),gn=Mr(ct??``),_n=Z.useSyncExternalStore(s,t,t),vn=pn?.transportIdentity??null,yn=pn?.owner.kind??null,bn=pn?.owner.ownerID??null,xn=Z.useMemo(()=>gb(_n,ct,Ft.draftID,vn&&yn&&bn?{transportIdentity:vn,owner:{kind:yn,ownerID:bn}}:null),[bn,yn,vn,_n,ct,Ft.draftID]),Sn=xn?le(xn):null,Cn=vt(Z.useCallback(e=>Sn?e.draftAttachmentViews[Sn]:void 0,[Sn])),wn=vt(Z.useCallback(e=>Sn?e.drafts[Sn]:void 0,[Sn])),Tn=Z.useMemo(()=>{if(!wn||!Cn)return _b;let e=wn.attachments.flatMap(e=>{let t=Cn[e.attachmentRefID];return t?[t]:[]});return e.length===0?_b:e},[Cn,wn]);Z.useEffect(()=>{xn&&vt.getState().hydrateDraftAttachments(xn)},[xn]);let Dn=rm(),On=c(e=>e.activeMainTab===`chat`),kn=dr(ct??``,Tt??void 0),jn=im({kind:`primary`,surfaceID:`primary`,active:On,sessionID:ct,directory:Tt??null,activity:{phase:kn?.type===`busy`?`busy`:kn?.type===`retry`?`retry`:`idle`,canAbort:kn?.type===`busy`||kn?.type===`retry`},draftKey:xn,transportIdentity:_n,runtimeGeneration:i(),selection:{value:{providerID:lt,modelID:ut,agent:ft,variant:pt},catalog:{providers:mt,agents:_t,variants:Ct,variantsReady:!yt,ready:!yt&&!St,loading:yt||St},flush:async()=>{let e=J.getState().currentSessionId;if(!e)return;let n=i(),r=t(),a=Nt.current,o=e,s=J.getState().getDirectoryForSession(o)??null,c=Cr(s);if(Ei.getState().activeDirectoryKey!==c&&await Ei.getState().activateDirectory(s),i()!==n||t()!==r||J.getState().currentSessionId!==o||Ei.getState().activeDirectoryKey!==c||Nt.current!==a)return;await Et(o,{directory:s??void 0});let l=J.getState().getDirectoryForSession(o)??null,u=Cr(l);if(i()!==n||t()!==r||J.getState().currentSessionId!==o||l!==s||u!==c||Ei.getState().activeDirectoryKey!==c||Nt.current!==a)return;let d=Ei.getState(),f={providers:d.providers,agents:d.getVisibleAgents()};if(f.providers.length===0||f.agents.length===0)return;let p=iy(ur(o,l??void 0)),m=xt.getState(),h=ey({sessionId:o,latestUserChoice:p,catalog:f,memory:m,fallbackAgentName:d.currentAgentName});if(!h)return;let g=[o,h.source,h.messageId??``,h.agent??``,h.providerID,h.modelID,h.variant??``,c].join(`|`);Pt.current!==g&&(ty(h,{currentAgentName:d.currentAgentName,setAgent:d.setAgent,setProvider:d.setProvider,setModel:d.setModel,setCurrentVariant:d.setCurrentVariant},{sessionId:o,memory:m}),Pt.current=g)},change:async e=>{Nt.current+=1;let t=Ei.getState();Yv(e,{currentAgentName:t.currentAgentName,setAgent:t.setAgent,setProvider:t.setProvider,setModel:t.setModel,setCurrentVariant:t.setCurrentVariant,saveAgentModelSelection:t.saveAgentModelSelection},{sessionId:J.getState().currentSessionId,memory:xt.getState()});let n=J.getState().currentSessionId;if(n){let r=J.getState().getDirectoryForSession(n)??void 0,i=iy(ur(n,r)),a=xt.getState(),o=ey({sessionId:n,latestUserChoice:i,catalog:{providers:t.providers,agents:t.getVisibleAgents()},memory:a,fallbackAgentName:e.agent??t.currentAgentName});o&&(Pt.current=[n,o.source,o.messageId??``,o.agent??``,o.providerID,o.modelID,o.variant??``,Ei.getState().activeDirectoryKey].join(`|`))}}},resources:{attachments:Tn,addAttachment:async e=>{xn&&await Qt(xn,()=>vt.getState()).addLocal(e)},removeAttachment:async e=>xn?Qt(xn,()=>vt.getState()).removeByAttachmentID(e):!1,clearAttachments:async()=>xn?Qt(xn,()=>vt.getState()).clearRootAttachments():!1,restoreAttachments:async e=>xn?Qt(xn,()=>vt.getState()).restoreRootAttachments(e):!1,pendingInput:cn===null?null:{text:cn,mode:ln},consumePendingInput:rn,pendingPreset:sn,consumePendingPreset:()=>vt.getState().consumePendingPresetSubmit(),consumeSyntheticParts:dn,restoreSyntheticParts:e=>vt.setState(t=>({pendingSyntheticParts:[...e,...t.pendingSyntheticParts??[]]})),inlineDrafts:hn,removeInlineDraft:e=>{let t=ct??(Lt?`draft`:``);t&&Kl.getState().removeDraft(t,e)},restoreInlineDrafts:e=>{let t=ct??(Lt?`draft`:``);!t||e.length===0||Kl.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:gn,captureRuntime:()=>vt.getState().captureDraftRuntime(),getDraft:e=>vt.getState().getDraft(e),abortPrompt:{sessionID:$t,clear:tn}},backend:{send:e=>{Gv(e,{transportIdentity:t(),runtimeGeneration:i()});let n=Kv(e);return st(e.text??``,e.providerID,e.modelID,e.agent,e.attachments??[],e.agentMention,e.parts,e.variant,e.inputMode,n)},sendQueued:e=>bt(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()=>Ut(),compact:async e=>ke.summarizeSession(e.sessionID??``,e.providerID??``,e.modelID??``,e.directory),abort:e=>(e.sessionID&&Xt(e.sessionID),Bt(e.sessionID??``))},shortcuts:{cycle:e=>at.current(e),new:()=>Ut(),abort:()=>(ct&&Xt(ct),Bt(ct??``)),submit:()=>{}},deliveryTarget:{kind:`primary`}}),Mn=am(jn,o??Dn);om(Mn),Z.useLayoutEffect(()=>{if(!Mn.active){Wv(Mn.surfaceID);return}return Uv(Mn),()=>Wv(Mn.surfaceID)},[Mn]);let Pn=Jv(Mn),Fn=Mn.resources??(Mn.kind===`primary`?jn.resources:void 0);if(!Fn)throw Error(`chat-input-surface-resources-incomplete`);let In=[...Fn.attachments],Ln=Mn.sessionID,Rn=sm(Mn,Ht),zn=Mn.kind===`secondary`?Mn.commands.hasNewDraft:Lt,Bn=zn,Vn=Mn.directory??Tt,Un=Mn.draftKey??xn,Gn=Z.useMemo(()=>{if(Mn.kind===`secondary`)return lm(Mn,!1,!1);let e=Ln?Xy(Ln,Dt??void 0):!1;return lm(Mn,e,zn)},[Mn,Ln,Dt,zn]),Kn=(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]),Jn=qi(e=>e.projects),Yn=qi(e=>e.activeProjectId),Zn=qi(e=>e.setActiveProjectIdOnly),[Qn,er]=Z.useState(!1),[nr,rr]=Z.useState(!1),ir=Z.useMemo(()=>Ln?Fi({autoAccept:Gt,sessions:[],sessionById:ci(),sessionID:Ln}):Ft.permissionAutoAcceptEnabled===!0,[Ln,Ft.permissionAutoAcceptEnabled,Gt]),ar=Ei(e=>e.agents),or=Mn.kind===`secondary`?Mn.selection.value.agent:ft,sr=Mn.kind===`secondary`?Gp(Mn.selection.catalog?.agents):ar,pr=d()||Iv(sr,or),mr=Z.useCallback(()=>{Ii.error(l(`chat.chatInput.toast.togglePermissionAutoAcceptFailed`))},[l]),hr=Mn.selection.value,_r=Mn.selection.change,vr=Mn.selection.catalog,yr=Z.useMemo(()=>({selection:{providerID:hr.providerID??``,modelID:hr.modelID??``,agent:hr.agent??null,variant:hr.variant},onChange:async e=>{if(!_r)throw Error(`chat-input-surface-selection-readonly`);await _r({...e,agent:e.agent??void 0,variant:e.variant})},disabled:!Mn.active,catalog:vr}),[vr,_r,hr.agent,hr.modelID,hr.providerID,hr.variant,Mn.active]);Z.useEffect(()=>{if(Mn.kind!==`primary`||!ct){ct||(Pt.current=null);return}if(yt||St||mt.length===0||_t.length===0)return;let e=Cr(Dt);if(jt!==e)return;let t=xt.getState(),n=ey({sessionId:ct,latestUserChoice:At,catalog:{providers:mt,agents:_t},memory:t,fallbackAgentName:ft});if(!n)return;let r=[ct,n.source,n.messageId??``,n.agent??``,n.providerID,n.modelID,n.variant??``,jt].join(`|`);if(Pt.current===r)return;if((n.agent===void 0||n.agent===ft)&&n.providerID===lt&&n.modelID===ut&&n.variant===pt){Pt.current=r;return}if(Ei.getState().activeDirectoryKey!==e)return;let i=Ei.getState();ty(n,{currentAgentName:i.currentAgentName,setAgent:i.setAgent,setProvider:i.setProvider,setModel:i.setModel,setCurrentVariant:i.setCurrentVariant},{sessionId:ct,memory:t}),Pt.current=r},[Mn.kind,ct,At,mt,_t,yt,St,jt,Dt,ft,lt,ut,pt]);let br=Ei(e=>e.getVisibleAgents),xr=Mn.kind===`primary`?br():By,Er=Ei(e=>Mn.kind===`primary`?e.providers:Vy),Dr=Mn.kind===`secondary`?Gp(Mn.selection.catalog?.agents):xr,kr=Mn.kind===`secondary`?Mn.selection.catalog?.providers??Vy:Er,Ar=Mn.kind===`secondary`&&(!Mn.selection.catalog?.ready||!!Mn.selection.catalog.error),jr=!Mn.active||!Mn.selection.change||Ar,Nr=c(e=>e.isMobile),Fr=c(e=>e.setImagePreviewOpen),Ir=Z.useCallback(e=>{e.image&&(f(e),Fr(!0))},[Fr]),Lr=Z.useCallback(e=>{f(t=>({...t,open:e})),Fr(e)},[Fr]),Rr=xl(e=>e.pending),zr=c(e=>e.inputBarOffset),Br=c(e=>e.persistChatDraft),Ur=c(e=>e.inputSpellcheckEnabled),Kr=c(e=>e.isExpandedInput),qr=c(e=>e.setExpandedInput),Yr=c(e=>e.setTimelineDialogOpen),Xr=Py({draftKey:Un,sessionTitles:new Map(Array.from(ci(),([e,t])=>[e,t.title||e])),persistenceEnabled:Br}),Zr=Xr.document,Qr=Zr.text,{replacePlainDocument:$r,replaceProgrammaticText:ti,applyBrowserEdit:ni,insertReference:ii,deleteReference:ai,enterHistoryPreview:oi,exitHistoryPreview:si,captureSubmission:li,recoverSubmission:ui,confirmedFileMentions:di,mentions:pi}=Xr,mi=Z.useCallback((e,t)=>ti(e,t),[ti]),hi=Z.useCallback(e=>!e.startsWith(`session:`)&&(e.includes(`/`)||e.includes(`\\`)||e.includes(`.`)||di.some(t=>t.value===e)),[di]),gi=Z.useRef(null),vi=Z.useRef(!1),bi=Z.useRef(0),xi=Z.useRef(Qr.length),Si=Z.useRef(null),Ci=Z.useRef(0),Ti=Z.useRef(!1),Di=Z.useRef(null),ki=Z.useRef(!1),ji=Z.useRef(null),Mi=Z.useRef([]),Pi=Z.useRef(!1),Li=Z.useRef(null),zi=Z.useRef(!1),Bi=Z.useRef(null),Vi=Z.useRef(null),Ui=Z.useRef(null),Wi=Z.useRef(Qr),Gi=Z.useRef(new Set),Ki=Xr.getDocument,Ji=Z.useCallback((e,t,n=[])=>mi(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}`))]}),[mi]),Yi=$m(Qm()),{git:Xi,vscode:Zi}=ko(),Qi=c(e=>e.shortcutOverrides.cycle_agent),ea=c(e=>e.shortcutOverrides),ta=Z.useMemo(()=>Xa(`cycle_agent`,Qi?{cycle_agent:Qi}:void 0),[Qi]),na=Z.useMemo(()=>Xa(`clear_all_messages`,ea),[ea]),{currentTheme:ia}=Va(),aa=As(),oa=Hs(Vn),sa=Es(e=>Vn?e.directories.get(Vn)?.status??null:null),ca=Es(e=>e.ensureStatus),la=Es(e=>e.fetchStatus),[ua,da]=Z.useState(!1),fa=Z.useRef(null),[pa,ha]=Z.useState(!1),_a=c(e=>e.isAgentSelectorOpen),va=c(e=>e.isModelSelectorOpen),[ba,Ca]=Z.useState(!1);Z.useEffect(()=>{!Vn||!Xi||ca(Vn,Xi)},[Vn,Xi,ca]),Z.useEffect(()=>{if(!(!Vn||!Xi))return Hr.onGitRefreshHint(e=>{nb(e.directory)===nb(Vn)&&la(Vn,Xi)})},[Vn,Xi,la]);let Da=Z.useCallback(async e=>{if(!Ln)return;let t=J.getState().getDirectoryForSession(Ln)||Vn||``;if(!t){Ii.error(l(`diffView.reviewDialog.toast.noSessionDirectory`));return}rr(!0);try{await Jr({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}),er(!1)}catch(e){console.error(`[review-flow] failed to start review flow`,e),Ii.error(e instanceof Error?e.message:l(`diffView.reviewDialog.toast.startFailed`))}finally{rr(!1)}},[Ln,Vn,l]),Oa=Kr&&!Nr,Aa=Kr&&Nr,ja=Oa||Aa,Ma=`1.5rem`,Na=Nr||ba;Z.useEffect(()=>{let e=Si.current;if(!e)return;let t=e=>{let t=e>0&&e<Gy;Ca(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 Ra=In,za=Z.useMemo(()=>new Set(Dr.map(e=>e.name.toLowerCase())),[Dr]),Ba=Z.useRef(za);Ba.current=za;let Ha=Uy({inputMode:p,message:Qr,showCommandAutocomplete:k,showSkillAutocomplete:P}),Ua=gr({directory:Vn,enabled:Ha}),Wa=Z.useMemo(()=>Ua.data??[],[Ua.data]),Ga=Wr({directory:Vn,enabled:Ha}),Ka=Z.useMemo(()=>Ga.data??[],[Ga.data]),qa=Z.useMemo(()=>new Map(Ka.map(e=>[e.name.toLowerCase(),e.name])),[Ka]),Ja=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`]);!Nr&&!d()&&e.add(`handoff-review`);for(let t of Wa)e.add(t.name.toLowerCase());for(let t of Ka)e.add(t.name.toLowerCase());return e},[Wa,Ka,Nr]),Ya=Z.useMemo(()=>{if(!Qr||!Qr.includes(`/`)||p===`shell`||Ja.size===0)return[];let e=[],t=RegExp(`(^|\\s)/(${ee})?([A-Za-z0-9][A-Za-z0-9_-]*)`,`g`),n;for(;(n=t.exec(Qr))!==null;){let t=n[2]??``,r=n[3];if(!Ja.has(r.toLowerCase()))continue;let i=n.index+n[1].length,a=1+t.length+r.length,o=qa.get(r.toLowerCase());e.push(o?{start:i,end:i+a,style:`mentionCommand`,priority:102,skillName:o,visual:ie({trigger:`/`,icon:`book-open`,label:o},Qr.slice(i,i+a))}:{start:i,end:i+a,style:`mentionCommand`,visual:ie({trigger:`/`,icon:`command`,label:r},Qr.slice(i,i+a))})}return e},[qa,p,Ja,Qr]),Za=ga(e=>e.snippets),to=Z.useMemo(()=>{let e=new Set;for(let t of Za){e.add(t.name.toLowerCase());for(let n of t.aliases??[])e.add(n.toLowerCase())}return e},[Za]),no=Z.useMemo(()=>{if(!Qr||!Qr.includes(`#`)||p===`shell`||to.size===0)return[];let e=[],t=/(^|\s)#([A-Za-z0-9][A-Za-z0-9_-]*)/g,n;for(;(n=t.exec(Qr))!==null;){let t=n[2];if(!to.has(t.toLowerCase()))continue;let r=n.index+n[1].length;e.push({start:r,end:r+1+t.length,style:`mentionSnippet`})}return e},[p,to,Qr]),ro=Z.useMemo(()=>{if(!Qr||!Qr.includes(`@`)||p===`shell`)return[];let e=[],t=/@([^\s]+)/g,n;for(;(n=t.exec(Qr))!==null;){let t=n[0],r=String(n[1]||``).trim().replace(/[),.;:!?`"'>]+$/g,``),i=n.index,a=i+t.length,o=i>0?Qr[i-1]:null;!(!o||/(\s|\(|\)|\[|\]|\{|\}|"|'|`|,|\.|;|:)/.test(o))||r.length===0||r.startsWith(`session:`)||(za.has(r.toLowerCase())?e.push({start:i,end:a,kind:`agent`}):hi(r)&&e.push({start:i,end:a,kind:`file`}))}return e},[p,Qr,za]),io=Z.useMemo(()=>{if(!Qr||!Qr.includes(`[`)||p===`shell`||Ra.length===0)return[];let e=Ra.filter(Oe),t=new Map(e.map(e=>[e.filename.trim().toLowerCase(),e.mimeType.startsWith(`image/`)?`image`:`attachment`]));return Re(Qr,e.map(e=>e.filename)).flatMap(e=>{let n=G(Qr.slice(e.start+1,e.end-1)).trim(),r=t.get(n.toLowerCase());return[{...e,style:`mentionFile`,priority:101,visual:ie({trigger:`[`,icon:r===`image`?`file-image`:`attachment-2`,label:n,suffix:`]`},Qr.slice(e.start,e.end))}]})},[p,Qr,Ra]),ao=Z.useMemo(()=>{if(!Qr||p===`shell`)return null;let e=[...M_(Qr),...J_(Qr),...L_(ro),...Ya,...no,...io,...Zr.references.map(e=>({start:e.start,end:e.end,priority:103,...A(e)}))];return N_(Qr,e)},[io,Ya,no,ro,Zr.references,p,Qr]),oo=Z.useCallback(e=>(e??[]).map(e=>({...e,dataUrl:e.source===`server`&&e.serverPath?eb(e.serverPath):e.dataUrl})),[]),[so,co]=Z.useState(null),lo=Z.useRef(null),[uo,fo]=Z.useState(!1),[mo,ho]=Z.useState(!1),[go,_o]=Z.useState(null),[vo,yo]=Z.useState(null),bo=C(e=>e.followUpBehavior),xo=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]),So=au({transportIdentity:xo?.transportIdentity??``,directory:xo?.directory??``,sessionID:xo?.sessionID??``}),Co=Z.useMemo(()=>Ln?x(Ln):null,[Ln]),wo=C(Z.useCallback(e=>xo?b(e,xo):Ry,[xo])),To=C(Z.useCallback(e=>Co?b(e,Co):Ry,[Co])),Eo=Z.useMemo(()=>To.length===0?wo:wo.length===0?To:[...To,...wo],[wo,To]),Do=So.mode===`server`?Ry:Eo,Oo=C(Z.useCallback(e=>xo?B(e,xo):Ry,[xo])),Ao=C(e=>e.clearQueue),jo=C(e=>e.removeFromQueue),Mo=Fn.inlineDrafts,No=Mo.length>0,[Po,Fo,Io]=Z.useMemo(()=>{let e=0,t=0,n=0;for(let r of Mo)r.source===`preview-console`?e+=1:r.source===`preview-annotation`?t+=1:n+=1;return[e,t,n]},[Mo]),Lo=Z.useCallback(e=>{for(let t of Fn.inlineDrafts)t.source===e&&Fn.removeInlineDraft(t.id)},[Fn]),Ro=Z.useCallback(()=>{for(let e of Fn.inlineDrafts)e.source!==`preview-console`&&e.source!==`preview-annotation`&&Fn.removeInlineDraft(e.id)},[Fn]),zo=Fn.history;Z.useEffect(()=>{Wi.current=Qr},[Qr]),Z.useLayoutEffect(()=>{m(`normal`),it(-1)},[Un?.transportIdentity,Un?.owner.kind,Un?.owner.ownerID]),Z.useLayoutEffect(()=>{if(!zn||Nr)return;let e=()=>{let e=gi.current;!e||e.disabled||e.focus({preventScroll:!0})};e();let t=window.requestAnimationFrame(e);return()=>window.cancelAnimationFrame(t)},[zn,Nr]);let Bo=Uh(Mn.kind===`primary`?Ln:null,Mn.kind===`primary`?Vn??void 0:void 0),Vo=Mn.activity?.phase??Bo.phase,Ho=Kt(Z.useCallback(e=>{if(!Ln)return!1;let t=e.runsByOriginalSessionID[Ln];return t?.status===`running`&&t.runtimeKey===n()},[Ln])),Uo=q(e=>{Nr&&(et(),ce(e),gi.current?.blur(),Ei.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobilePanel`}))}),Wo=Fn.pendingInput,Go=Fn.consumePendingInput;Z.useEffect(()=>{if(Wo===null)return;let e=Go();if(e){if(e.mode===`append`){if(!e.text.trim())return;let t=mb(Wi.current,e.text);Wi.current=t,mi(t)}else if(e.mode===`append-inline`){let t=hb(Wi.current,e.text);Wi.current=t,mi(t)}else $r(e.text);setTimeout(()=>{gi.current?.focus()},0)}},[Wo,Go,$r,mi]);let Ko=Qr.trim().length>0||Ra.length>0||No,qo=So.mode===`server`?So.items.length>0:Do.length>0||Oo.length>0,Jo=!$d(So.mode),Yo=Ko||qo,Xo=J(e=>e.stagedMessageEdit?.sessionId===Ln?e.stagedMessageEdit.messageId:null),Zo=Vo===`busy`||Vo===`retry`,Qo=Mn.activity?.canAbort??Zo,$o=Z.useCallback(()=>{let e=gi.current,t=e?.value??Ki().text;t!==Ki().text&&ni(t,e?.selectionStart??t.length,e?.selectionEnd??e?.selectionStart??t.length);let n=Ki();return{message:n.text,document:n,hasContent:n.text.trim().length>0||Ra.length>0||No}},[ni,Ki,No,Ra.length]),es=Z.useRef(async()=>{}),ts=Mn.surfaceID,ns=Ft?.draftID??null,rs=En(Z.useMemo(()=>Hn(ts),[ts])),is=En(Z.useMemo(()=>Mt(ns),[ns])),as=Z.useMemo(()=>Hi(rs,is),[rs,is]),ss=(e=`send`)=>En.getState().beginFlight(ts,e),cs=()=>{En.getState().endFlight(ts)},ls=()=>En.getState().isInFlight(ts),us=Z.useRef(null);Z.useEffect(()=>{if(Mn.kind!==`primary`||!Xo){us.current=null;return}us.current!==Xo&&(us.current=Xo,Xp(gi)||requestAnimationFrame(()=>Xp(gi)))},[Xo,Mn.kind]);let ds=En(Z.useMemo(()=>It(ns),[ns])),fs=q(async()=>{let e=J.getState().newSessionDraft.draftID;if(!e||!En.getState().isEstablishing(e))return!1;let t=$o();if(!t.hasContent)return!1;let n=K(t.document,`queue-canonical`);if(!n.ok)return Ii.error(l(`chat.chatInput.toast.messageSendFailed`)),!1;if(await Mn.selection.flush(),!En.getState().isEstablishing(e))return!1;let r=ny(Ei.getState());if(!r?.providerID||!r?.modelID)return Ii.error(l(`chat.chatInput.toast.messageSendFailed`)),!1;let i=oo(Ra);return En.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})?($r(``),it(-1),qr(!1),i.length>0&&Fn.clearAttachments(),!0):!1}),ps=()=>{if(Ln)return!1;let e=J.getState().newSessionDraft.draftID;return En.getState().isEstablishing(e)?(fs(),!0):!1},ms=q(async()=>{if(!Mn.active||ls())return;if(Ln){let e=J.getState().stagedMessageEdit;if(e&&e.sessionId===Ln){J.getState().beginMessageEditCommit(e.sessionId,e.messageId);try{await $i(e.sessionId,e.messageId)}catch(e){console.warn(`[chat-input] staged-edit delete failed before queue admission`,e);return}finally{J.getState().endMessageEditCommit(e.sessionId,e.messageId)}J.getState().stagedMessageEdit===e&&J.getState().clearStagedMessageEdit(e.sessionId)}}let e=$o(),n=K(e.document);if(!n.ok){Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}let r={chunks:n.chunks??[],semantics:n.semantics??[]},o=n.text,s=o.trimStart(),c=r.chunks.every(e=>e.provenance===`authored`)&&p===`normal`&&s.startsWith(`/`)?Cv(s.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(c&&!Ss(c,e=>tm(Mn,{name:e.name,source:`openchamber`}))||a||!e.hasContent||!Ln)return;if(Jo||!an(Mn.deliveryTarget?.kind,So.mode)){es.current(Zo?{delivery:`steer`}:void 0);return}if(r.chunks.every(e=>e.provenance===`authored`)&&yv(o,p)){es.current();return}if(!ss(`queue`))return;let u=Mn.transportIdentity,d=Mn.runtimeGeneration,f=Fn.captureRuntime(),m=xo,h=Mn.kind===`primary`?xo?.sessionID??Ln:null,g=[...Fn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt),_=g.length>0?v(Yl(e.document.text,g),e.document.references).document:e.document,y=K(_,`queue-canonical`);if(!y.ok){cs(),Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}let b=oo(Ra),w=li(),T=b,E=$n(),D=!1,O=null,k=()=>{D&&m&&(So.actions.unstageAdmission({requestID:E.requestID,scope:{directory:m.directory,sessionID:m.sessionID}}),D=!1),O&&m&&(C.getState().unstageAdmission(m,O),O=null)},A=async e=>{k(),w&&ui(w),T.length>0&&await Fn.restoreAttachments(T),e&&Fn.restoreSyntheticParts(e),g.length>0&&Fn.restoreInlineDrafts(g)};try{if(!m){Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}if(So.mode===`server`){if(!Un){Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}en({stage:()=>{So.actions.stageAdmission({requestID:E.requestID,scope:{directory:m.directory,sessionID:m.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:pi}}),D=!0},clearComposer:()=>{$r(``),it(-1),qr(!1)}})}else en({stage:()=>{C.getState().bindLegacyQueue(x(m.sessionID),m),C.getState().stageAdmission(m,{requestID:E.requestID,queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:pi}),O=E.requestID},clearComposer:()=>{$r(``),it(-1),qr(!1)}});if(await Mn.selection.flush(),!dt({transportIdentity:u,generation:d},{transportIdentity:t(),generation:i()})){await A();return}if(!dt(f,Fn.captureRuntime())){await A();return}if(h&&J.getState().currentSessionId!==h){await A();return}if(m.transportIdentity!==t()||m.runtimeGeneration!==i()||m.sessionID!==(h??m.sessionID)||h&&S(J.getState().getDirectoryForSession(h))!==S(m.directory)){await A();return}let n=m,r=Mn.kind===`primary`?(()=>{let e=Ei.getState(),t=h?J.getState().getDirectoryForSession(h)??null:null;return ny(e,{expectedConfigKey:Cr(t),activeDirectoryKey:e.activeDirectoryKey})})():Mn.selection.value.providerID&&Mn.selection.value.modelID?{...Mn.selection.value,providerID:Mn.selection.value.providerID,modelID:Mn.selection.value.modelID}:void 0;if(!An(r)){await A();return}if(So.mode===`server`){if(!Un){await A(),Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}let t=tr({draftKey:Un,runtime:f,document:e.document,attachments:Ra,inlineDrafts:g}),i=n.deliveryTarget.kind===`assistant`?Fn.consumeSyntheticParts()?.map(e=>({...e,partID:e.partID??L()}))??null:null,a,o=[],s=n.deliveryTarget.kind===`assistant`?(()=>{let e=wi({plan:{chunks:y.chunks??[],semantics:y.semantics??[]},agents:Dr,installedSkillNames:new Set(Oi(re,Vn).map(e=>e.name)),directory:Vn,root:aa||Vn,confirmedFilePaths:di.map(e=>e.path),confirmedDirectoryPaths:di.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Ra});return o=e.attachments,Or({text:g.length>0?Yl(e.text,g):e.text,attachments:[...b,...e.attachments],semanticParts:ri(e.semantics,n.directory),syntheticParts:i})})():void 0;try{let e=[..._i(b),..._i(o),...(i??[]).flatMap(e=>_i(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),Ii.error(l(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`));return}let c=s&&i?Ai(s,i.map(e=>({...e,partID:e.partID}))):void 0;try{let e=!1,o=await Vt({capture:t,admit:async()=>{let t=await So.actions.admit({requestID:E.requestID,scope:{directory:n.directory,sessionID:n.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,composerDocument:_,composerMentions:pi,sendConfig:r,deliveryTarget:n.deliveryTarget,...s?{deliveryParts:s}:{},...c?{syntheticParts:c}:{},attachmentIssues:[],createdAt:E.createdAt},attachments:a});return t.status===`committed`&&(e=!0,D=!1),t},captureRuntime:Fn.captureRuntime,getCurrentDraftKey:()=>Un,getDocument:Ki,consumeBody:()=>$r(``),getAttachments:()=>Fn.attachments,removeAttachment:Fn.removeAttachment,getInlineDrafts:()=>Fn.inlineDrafts,removeInlineDraft:Fn.removeInlineDraft});if(!e){await A(i),o.status===`stale`&&Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}if(o.status===`partial`){Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}o.status===`committed`&&!Nr&&gi.current?.focus()}catch(e){await A(i),Ii.error(l(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}return}if(!C.getState().confirmAdmission(n,{requestID:E.requestID,sendConfig:r,attachments:b.length>0?b:void 0}).ok){await A(),Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}O=null;for(let e of g)Fn.removeInlineDraft(e.id);b.length>0&&Fn.clearAttachments(),Nr||gi.current?.focus()}catch(e){await A(),Ii.error(l(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}finally{cs()}}),hs=q(()=>{Mv(()=>ms(),()=>{Ii.error(l(`chat.chatInput.toast.messageSendFailed`))})}),gs=q(async(e,t,n,r)=>{if(Jo||!Mn.draftKey)return!1;try{let i=await Nn({content:e,composerDocument:n,composerMentions:r,attachments:t}),a=vt.getState(),o=a.getDraft(Mn.draftKey);return tf(await un({key:Mn.draftKey,expectedRevision:o?.revision??`absent`,payload:i,runtime:a.captureDraftRuntime()}))?!0:(Ii.error(l(`chat.chatInput.toast.messageSendFailed`)),!1)}catch{return Ii.error(l(`chat.chatInput.toast.messageSendFailed`)),!1}}),_s=q(e=>{if(!(a||Jo)){if(Pn){Pn.sendQueued(e,{options:{delivery:`steer`},manual:!0});return}Ii.error(l(`chat.chatInput.toast.messageSendFailed`))}}),vs=q(()=>{et(),ce(`agent`),gi.current?.blur(),Ei.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobileAgentPanel`})}),xs=Z.useCallback(()=>{fo(!0)},[]),Cs=Z.useCallback(()=>{ho(!0)},[]),Ts=async e=>{if(!Mn.active||a||ps()||ls())return;let n=e?.queuedOnly??!1,o=e?.queuedMessageId,s=e?.delivery===`steer`&&Zo?`steer`:void 0,u=e?.presetText==null?$o():{message:e.presetText,document:{text:e.presetText,references:[]},hasContent:e.presetText.trim().length>0||Ra.length>0||No},f=e?.presetText==null?li():null,m=In,h=K(u.document,`direct-send-display`);if(!h.ok){Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}let g=h.text,v={chunks:h.chunks??[],semantics:h.semantics??[]},y=v.chunks.every(e=>e.provenance===`authored`),x=g.trimStart(),S=y?_v(x,p):null,w=y&&yv(g,p),T=y&&p===`normal`&&/^\/model(?:\s|$)/i.test(x),E=y&&p===`normal`&&x.startsWith(`/`)?Cv(x.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(E&&!Ss(E,e=>tm(Mn,{name:e.name,source:`openchamber`}))||n&&Jo)return;if(!n&&T){j(!1),N(``),Nr?Uo(`model`):(c.getState().setModelSelectorOpen(!0),Ei.getState().refreshCatalogsOnPickerOpen({source:`chatInput:modelCommand`}));return}if(!(!n&&S&&S!==`model`)){if(!n&&Ln&&qo&&Jo)return;if(!n&&Ln&&qo&&So.mode===`server`){u.hasContent&&hs();return}if(!n&&Ln&&qo){u.hasContent&&hs();let e=Do[0];e&&Pn&&await Pn.sendQueued(e.queueItemID,{options:Zo?{delivery:`steer`}:void 0});return}}let D=w?[]:o?Do.filter(e=>e.id===o):Do;if(n&&Ho)return;if(n){if(D.length===0||!Ln)return}else if(!u.hasContent&&!qo||!Ln&&!zn)return;if(!Ln&&Rn||!ss())return;let O=!Ln&&zn&&!n&&!w?J.getState().newSessionDraft.draftID??null:null,k=O?W(`msg`):void 0;if(O&&k&&!En.getState().beginEstablishing({draftID:O,primaryMessageID:k})){cs();return}let A=()=>{lr(),O&&En.getState().clearEstablishing(O)},M=e=>{let n=J.getState().currentSessionId,r=(n?J.getState().getDirectoryForSession(n):null)??Vn??``;if(!n||!r){En.getState().clearEstablishing(e);return}jv({draftID:e,sessionID:n,directory:r,transportIdentity:t(),runtimeGeneration:i(),admitServer:So.mode===`server`?async e=>So.actions.admit({requestID:e.requestID,scope:{directory:r,sessionID:n},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?_i(e.attachments):void 0}):void 0})};if(Ln&&!n&&!w&&Ho){cs(),hs();return}let P=!n&&!w;P&&($r(``),it(-1),qr(!1));let F=!1,I,L,R=!1;try{if(Dv({surfaceKind:Mn.kind,currentSessionId:Ln,queuedOnly:n,resourcePolicy:w,inputMode:p,localCommand:S})&&Ln){let e=J.getState().getDirectoryForSession(Ln)??Vn??null,t=J.getState().stagedMessageEdit;t&&t.sessionId===Ln&&(L={sessionId:t.sessionId,messageId:t.messageId},J.getState().beginMessageEditCommit(t.sessionId,t.messageId));let n=Ei.getState(),r=ny(n,{expectedConfigKey:Cr(e),activeDirectoryKey:n.activeDirectoryKey});if(r?.providerID&&r?.modelID){let t=oo(Ra);I=fn({sessionId:Ln,directory:e,content:u.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=Mn.kind===`primary`?(()=>{if(n){let e=D[0]?.owner;if(e?.state===`bound`||e?.state===`unbound-legacy`)return e.sessionID;if(xo?.sessionID)return xo.sessionID}return Ln})():null,t=n?D[0]?.sendConfig:void 0;if(n&&t||await Mn.selection.flush(),e!==null&&J.getState().currentSessionId!==e)return;let i=async()=>{let n=t?{...t}:Mn.kind===`primary`?(()=>{let t=Ei.getState();if(!e)return ry({captured:ny(t),surfaceSelection:Mn.selection.value});let n=J.getState().getDirectoryForSession(e)??Vn??null;return ry({captured:ny(t,{expectedConfigKey:Cr(n),activeDirectoryKey:t.activeDirectoryKey}),surfaceSelection:Mn.selection.value})})():Mn.selection.value.providerID&&Mn.selection.value.modelID?{...Mn.selection.value,providerID:Mn.selection.value.providerID,modelID:Mn.selection.value.modelID}:void 0;if(Mn.kind===`primary`&&e&&(!n?.providerID||!n?.modelID)){let t=J.getState().getDirectoryForSession(e)??Vn??null,r=Cr(t);if(Ei.getState().activeDirectoryKey!==r&&await Ei.getState().activateDirectory(t),J.getState().currentSessionId===e){let e=Ei.getState();n=ry({captured:ny(e,{expectedConfigKey:Cr(t),activeDirectoryKey:e.activeDirectoryKey}),surfaceSelection:Mn.selection.value})}}return n},a=await i(),c=!1,h=a?.providerID,g=a?.modelID,y=a?.agent,x=a?.variant;if(!h||!g){if(!c){c=!0;try{await Ei.getState().loadProviders({forceRefresh:!0,source:`chat-input-send-recovery`}),a=await i(),h=a?.providerID,g=a?.modelID,y=a?.agent,x=a?.variant}catch{}}if(!h||!g){console.warn(`Cannot send message: provider or model not selected`),Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}}Ln&&!n&&!w&&await Xn(Ln)&&await Bt(Ln);let T={...s?{delivery:s}:{},commitStagedMessageEdit:!n,...I?{messageID:I.messageID,ticket:I}:k?{messageID:k}:{},...e?{sessionId:e,directoryHint:J.getState().getDirectoryForSession(e)??Vn??null}:Mn.kind===`primary`&&Ln?{sessionId:Ln,directoryHint:J.getState().getDirectoryForSession(Ln)??Vn??null}:{}},E=``,j=[],N,P=[],z=new Set(Oi(re,Vn).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:Vn,a=new Set(Oi(re,i).map(e=>e.name)),o=wi({plan:r??Gr(t.content),agents:Dr,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,j=Ni([...oo(t.attachments),...o.attachments]);else{let e=oo(t.attachments);P.push({text:o.text,attachments:Ni([...e,...o.attachments])})}}if(!n&&u.hasContent){let e=oo(Ra),t=wi({plan:v,agents:Dr,installedSkillNames:z,directory:Vn,root:aa||Vn,confirmedFilePaths:di.map(e=>e.path),confirmedDirectoryPaths:di.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Ra});B.push(...t.semantics),!N&&t.agent&&(N=t.agent),D.length===0?(E=t.text,j=Ni([...e,...t.attachments])):P.push({text:t.text,attachments:Ni([...e,...t.attachments])})}let H=Ln??(zn?`draft`:null),U=[];if(!n&&H&&!w&&(U=[...Fn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt)),U.length>0)if(D.length===0)E=Yl(E,U);else if(P.length>0){let e=P[P.length-1];e.text=Yl(e.text,U)}else E=Yl(E,U);if(V&&V.length>0&&P.push(...fi(V)),go&&P.push({text:go.contextText,synthetic:!0}),vo&&(P.push({text:vo.instructionsText,synthetic:!0}),P.push({text:vo.contextText,synthetic:!0})),P.push(...ri(B,Ln&&J.getState().getDirectoryForSession(Ln)||Vn)),!E&&j.length===0&&P.length===0)return;if(O&&k){if(!await Vr({messageID:k,providerID:h,modelID:g,agent:y,text:E,attachments:j,additionalParts:P,agentMentionName:N}))return;if(!En.getState().isEstablishing(O)){A();return}}let W=async()=>{if(A(),xo&&D.length>0&&C.setState(e=>{let t=_(xo),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))]}}}),n)return V&&Fn.restoreSyntheticParts(V),!0;Fn.pendingInput?.text===u.message&&Fn.consumePendingInput(),f&&ui(f);let e=!0;return m.length>0&&(e=await Fn.restoreAttachments(m)),V&&Fn.restoreSyntheticParts(V),U.length>0&&Fn.restoreInlineDrafts(U),e};if(!w&&Ln&&o){let e=xo?b(C.getState(),xo).find(e=>e.id===o||e.queueItemID===o):void 0;xo&&e?.queueItemID&&e.operationID&&jo(xo,e.queueItemID,e.operationID)}else!w&&Ln&&qo&&xo&&Ao(xo);!n&&!w&&($r(``),it(-1),qr(!1),Ev({queuedOnly:n,resourcePolicy:w,rootAttachmentCount:m.length})&&Fn.clearAttachments());let ee=()=>wv({currentSessionId:Ln,messageRef:Wi,replacePlainDocument:$r}),G=E.trimStart();if(p===`normal`&&G.startsWith(`/`)){let e=Cv(G.slice(1).trim()).split(/\s+/)[0]?.toLowerCase();if(!Ss(e,e=>tm(Mn,{name:e.name,source:`openchamber`})))return;if(Ln&&(e===`undo`||e===`redo`)&&bv(G,p)&&ee(),e===`undo`&&Ln){try{await J.getState().handleSlashUndo(Ln),r?.()}catch(e){Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`new`){await Pn?.shortcut(`new`);return}if(e===`redo`&&Ln){try{await J.getState().handleSlashRedo(Ln),r?.()}catch(e){Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`fork`&&Ln){await Tv({command:`fork`,consumeCommandText:ee,forkSession:()=>J.getState().forkCurrentSession(Ln),waitForConnection:wr,getDirectoryForSession:()=>J.getState().getDirectoryForSession(Ln),summarizeSession:async()=>void 0,onCompactError:()=>void 0,onForkError:e=>{Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.messageSendFailed`))}});return}if(e===`timeline`&&Ln&&Yi.timeline){Yr(!0);return}if(e===`compact`&&Ln){Tv({command:`compact`,consumeCommandText:ee,forkSession:async()=>void 0,waitForConnection:wr,getDirectoryForSession:()=>Mn.directory??``,summarizeSession:e=>Un?Mn.backend.compact({operation:`compact`,surfaceID:Mn.surfaceID,transportIdentity:Mn.transportIdentity,runtimeGeneration:Mn.runtimeGeneration,sessionID:Ln,directory:e,draftKey:Un,deliveryTarget:Mn.deliveryTarget,providerID:h,modelID:g,agent:y,variant:x}):Promise.reject(Error(`chat-input-surface-incomplete`)),onCompactError:()=>{Ii.error(l(`chat.chatInput.toast.compactFailed`))},onForkError:()=>void 0});return}if(e===`summary`&&Ln){try{await wr();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 yi(`session.summary.visible`,{topic_line:t}),a=await yi(`session.summary.instructions`,{topic_block:n});await Kn(i,h,g,y,[],N,[{text:a,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.summaryFailed`))}return}if(e===`workspace-review`&&(Ln||zn)){try{await wr();let e=await yi(`session.review.visible`),t=await yi(`session.review.instructions`);await Kn(e,h,g,y,[],N,[{text:t,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.reviewFailed`))}return}if(e===`handoff-review`&&Ln&&!Nr&&!d()){er(!0);return}if(e===`plan-feature`&&(Ln||zn)){try{await wr();let e=await yi(`session.plan.visible`),t=await yi(`session.plan.instructions`);await Kn(e,h,g,y,[],N,[{text:t,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.planFeatureFailed`))}return}if(e===`goal`&&(Ln||zn)){A(),kt.getState().setArmed(!0);let e=vv(G,p)??``;$r(e),Wi.current=e,it(-1),e||qr(!1);return}if(e===`craft-goal`&&(Ln||zn)){try{await wr();let e=G.replace(/^\/\u2003?craft-goal\b/i,``).trim(),t=await yi(`session.craftGoal.visible`,{idea_block:e?`\n\nHere is my initial idea:\n${e}`:``}),n=await yi(`session.craftGoal.instructions`);await Kn(t,h,g,y,[],N,[{text:n,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.craftGoalFailed`))}return}if(e===`catch-up`&&(Ln||zn)){try{await wr();let e=await yi(`session.catchup.visible`),t=await yi(`session.catchup.instructions`);await Kn(e,h,g,y,[],N,[{text:t,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.catchUpFailed`))}return}if(e===`debug`&&(Ln||zn)){try{await wr();let e=await yi(`session.debug.visible`),t=await yi(`session.debug.instructions`);await Kn(e,h,g,y,[],N,[{text:t,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.debugFailed`))}return}if(e===`weigh`&&(Ln||zn)){try{await wr();let e=await yi(`session.weigh.visible`),t=await yi(`session.weigh.instructions`);await Kn(e,h,g,y,[],N,[{text:t,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.weighFailed`))}return}if(e===`explore`&&(Ln||zn)){try{await wr();let e=await yi(`session.explore.visible`),t=await yi(`session.explore.instructions`);await Kn(e,h,g,y,[],N,[{text:t,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.exploreFailed`))}return}}let te=Ln&&J.getState().getDirectoryForSession(Ln)||Vn;if(Bn||Ln&&!Xy(Ln,te)){let e=await mn().catch(()=>null);e&&P.push({text:Ri(e),synthetic:!0})}try{let e=ga.getState().expandText;E=await e(E);for(let t of P)t.synthetic||(t.text=await e(t.text))}catch(e){console.warn(`[ChatInput] Failed to expand snippets, sending original text:`,e)}R=!0;let ne=Kn(E,h,g,y,j,N,P.length>0?P:void 0,x,p,T);F=!0,ne.finally(()=>{cs(),L&&J.getState().endMessageEditCommit(L.sessionId,L.messageId)}),O&&ne.then(()=>{M(O)}).catch(()=>{En.getState().clearEstablishing(O)}),typeof window>`u`?r?.():window.requestAnimationFrame(()=>{r?.()}),ne.then(()=>{go&&_o(null),vo&&yo(null)}).catch(e=>{I&&nn(I),W().then(e=>{e||Ii.error(l(`chat.chatInput.toast.messageSendFailed`))});let t=e instanceof Error?e.message:typeof e==`string`?e:String(e??``),n=t.toLowerCase();console.error(`Message send failed:`,t||e);let r=n.includes(`timeout`)||n.includes(`timed out`)||n.includes(`may still be processing`)||n.includes(`being processed`)||n.includes(`failed to fetch`)||n.includes(`networkerror`)||n.includes(`network error`)||n.includes(`gateway timeout`)||n===`failed to send message`;if(n.includes(`payload too large`)||n.includes(`413`)||n.includes(`entity too large`)){Ii.error(l(`chat.chatInput.toast.attachmentsTooLarge`));return}if(r){m.length>0&&Ii.error(l(`chat.chatInput.toast.sendAttachmentsFailed`));return}Ii.error(t||l(`chat.chatInput.toast.messageSendFailed`))}),Nr||gi.current?.focus()}finally{R||(I&&nn(I),L&&J.getState().endMessageEditCommit(L.sessionId,L.messageId)),F||(P&&f&&ui(f),cs(),O&&M(O))}};es.current=Ts;let Ds=Z.useCallback(()=>{if(ps()||ls())return;let e=$o(),t=p===`normal`&&e.hasContent&&Ln&&(Zo||Ho),n=t&&$d(So.mode)&&an(Mn.deliveryTarget?.kind,So.mode);bo===`queue`&&n?hs():bo===`steer`&&t||bo===`queue`&&t&&!n?es.current(t?{delivery:`steer`}:void 0):es.current()},[p,$o,Ln,Zo,Ho,bo,hs,So.mode,Mn.deliveryTarget?.kind,fs]),Ms=Z.useCallback(e=>{if(ls())return;let t=(gi.current?.value??Wi.current).trim(),n=t?`${e}\n${t}`:e;es.current({presetText:n})},[]),Ns=Z.useCallback(e=>{let t=hb(Ki().text,e);mi(t),gi.current&&(gi.current.value=t),setTimeout(()=>{gi.current?.focus()},0)},[mi]),Fs=Z.useCallback(e=>{if(ls())return;let t=hb(gi.current?.value??Wi.current,e);es.current({presetText:t})},[]),Rs=Fn.pendingPreset,Bs=Fn.consumePendingPreset;Z.useEffect(()=>{if(Rs==null)return;let e=Bs();e&&Ms(e)},[Rs,Bs,Ms]);let Vs=Z.useCallback(()=>{$r(``),it(-1),In.length>0&&Fn.clearAttachments(),xo&&Ao(xo),j(!1),I(!1),H(!1),E(!1),p===`shell`&&m(`normal`)},[In.length,Fn,Ao,xo,$r,p]),Us=e=>{if(!Mn.active||Wh(e))return;if(na&&po(e,na)&&!Rr){let t=gi.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),Vs();return}}if(p===`shell`&&e.key===`Escape`){e.preventDefault(),m(`normal`);return}if(p===`shell`&&e.key===`Backspace`&&Qr.length===0){e.preventDefault(),m(`normal`);return}if((e.key===`Backspace`||e.key===`Delete`)&&!e.metaKey&&!e.ctrlKey){let t=gi.current,n=t?.selectionStart??Qr.length,r=t?.selectionEnd??Qr.length,i=ai({key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(i){let t=Yy(Xr.getDocument().text,i.start);e.preventDefault(),mi(t.text),requestAnimationFrame(()=>{gi.current?.setSelectionRange(t.caret,t.caret),$s()}),ec(t.text,t.caret);return}let a=Ee(Qr,In.filter(Oe).map(e=>e.filename),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(a){let t=new Set(a.removedFilenames.map(e=>e.toLowerCase())),n=Yy(a.text,a.caret);e.preventDefault(),mi(n.text);for(let e of In)t.has(e.filename.toLowerCase())&&Fn.removeAttachment(e.id);requestAnimationFrame(()=>{gi.current&&(gi.current.selectionStart=n.caret,gi.current.selectionEnd=n.caret),$s()}),ec(n.text,n.caret);return}let o=I_(Qr,qa.keys(),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(o){let t=Yy(o.text,o.caret);e.preventDefault(),mi(t.text),requestAnimationFrame(()=>{gi.current&&(gi.current.selectionStart=t.caret,gi.current.selectionEnd=t.caret),$s()}),ec(t.text,t.caret);return}if(n===r&&!e.altKey){let t=e.key===`Backspace`?n-1:n;if(t>=0&&t<Qr.length){let n=Re(Qr,In.map(e=>e.filename)).find(e=>t>=e.start&&t<e.end);if(n){let t=G(Qr.slice(n.start+1,n.end-1)).trim(),r=In.find(e=>e.filename.toLowerCase()===t.toLowerCase()),i=Qr[n.end]===` `?n.end+1:n.end,a=`${Qr.slice(0,n.start)}${Qr.slice(i)}`;e.preventDefault(),mi(a),r&&Fn.removeAttachment(r.id),requestAnimationFrame(()=>{gi.current&&(gi.current.selectionStart=n.start,gi.current.selectionEnd=n.start),$s()}),ec(a,n.start);return}let r=t;for(;r>0&&!/\s/.test(Qr[r-1]);)--r;let i=t+1;for(;i<Qr.length&&!/\s/.test(Qr[i]);)i+=1;let a=Qr.slice(r,i),o=a.slice(1);if(Hy.test(a)&&!Ba.current.has(o.toLowerCase())&&hi(o)){let t=Qr[i]===` `?i+1:i,n=`${Qr.slice(0,r)}${Qr.slice(t)}`;e.preventDefault(),mi(n),requestAnimationFrame(()=>{gi.current&&(gi.current.selectionStart=r,gi.current.selectionEnd=r),$s()}),ec(n,r);return}}}}let t=(e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.metaKey&&!e.ctrlKey;if(k&&Bi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Bi.current.handleKeyDown(e.key);return}if(P&&Vi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Vi.current.handleKeyDown(e.key);return}if(V&&Ui.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Ui.current.handleKeyDown(e.key);return}if(T&&Li.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Li.current.handleKeyDown(e.key);return}if(Oa&&e.key===`Escape`){e.preventDefault(),qr(!1);return}let n=ta&&!ta.includes(`shift`)?$a(`shift+${ta}`):``,r=n&&po(e,n)?-1:+!!po(e,ta);if(r!==0&&!k&&!P&&!V&&!T){e.preventDefault(),e.stopPropagation(),Pn?.shortcut(`cycle`,r),requestAnimationFrame(()=>{gi.current?.focus({preventScroll:!0})});return}let i=k||P||V||T,a=gi.current?.selectionStart===0&&gi.current?.selectionEnd===0,o=gi.current?.selectionStart===Qr.length&&gi.current?.selectionEnd===Qr.length,s=!i&&(Qr.length===0||a),c=!i&&(Qr.length===0||o);if(p===`normal`&&!i&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=gi.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&n>=0){let t=(t,n,r)=>{e.preventDefault(),mi(t),requestAnimationFrame(()=>{let e=gi.current;e&&(e.selectionStart=n,e.selectionEnd=r),$s()}),ec(t,r)},i={"`":["`","`"],"*":[`*`,`*`],_:[`_`,`_`],"~":[`~`,`~`],"(":[`(`,`)`],"[":[`[`,`]`],"{":[`{`,`}`],'"':[`"`,`"`],"'":[`'`,`'`]};if(r>n&&i[e.key]){let[a,o]=i[e.key],s=Qr.slice(n,r);t(`${Qr.slice(0,n)}${a}${s}${o}${Qr.slice(r)}`,n+a.length,r+a.length);return}if(e.key==="`"&&n===r){let e=Qr.slice(0,n);if(/(^|\n)``$/.test(e)){let n=`${e}\`\n\n\`\`\`${Qr.slice(r)}`,i=e.length+2;t(n,i,i);return}}}}if(e.key===`ArrowUp`&&!e.metaKey&&!e.ctrlKey&&s&&zo.length>0){if(e.preventDefault(),rt===-1)it(0),oi({text:zo[0],references:[]});else if(rt<zo.length-1){let e=rt+1;it(e),oi({text:zo[e],references:[]})}requestAnimationFrame(()=>{gi.current?.setSelectionRange(0,0)});return}if(e.key===`ArrowDown`&&!e.metaKey&&!e.ctrlKey&&c&&rt>=0){if(e.preventDefault(),rt===0)it(-1),si();else{let e=rt-1;it(e),oi({text:zo[e],references:[]})}return}if(e.key===`Enter`&&!e.shiftKey){if(e.preventDefault(),ps()||ls())return;let t=e.ctrlKey||e.metaKey,n=p===`normal`&&Ko&&Ln&&(Zo||Ho),r=n&&$d(So.mode)&&an(Mn.deliveryTarget?.kind,So.mode);bo===`queue`?t||!n?Ts():r?hs():Ts({delivery:`steer`}):t||!n?Ts():Ts({delivery:`steer`})}},Ws=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}},[]),Gs=Z.useCallback(()=>{if(!Oa){co(null);return}if(!k&&!P&&!V&&!T){co(null);return}let e=gi.current,t=Si.current;if(!e||!t)return;let n=e.selectionStart??Qr.length,r=Ws(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=T?520:k||V?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));co({top:u===`below`?o+22:o-6,left:f,place:u,maxHeight:p})},[Oa,Ws,Qr.length,k,T,V,P]);Z.useLayoutEffect(()=>{Gs()},[Gs,Qr,k,P,V,T,Oa]),Z.useEffect(()=>{if(!Oa)return;let e=()=>Gs();return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[Oa,Gs]);let Ks=Z.useCallback(()=>{lo.current&&=(clearTimeout(lo.current),null),da(!0),lo.current=setTimeout(()=>{da(!1),lo.current=null},1800)},[]),qs=Z.useCallback(()=>{if(Fn.abortPrompt.clear(),Ks(),Mn.kind===`secondary`){Pn?.shortcut(`abort`);return}qn()},[qn,Pn,Ks,Mn.kind,Fn]),Js=Z.useCallback((e=1)=>{if(Ar)return;let t=Wn(Dr,Mn.selection.value.agent??or,e);if(!t||!Mn.selection.change)return;let n=on({providerID:Mn.selection.value.providerID??``,modelID:Mn.selection.value.modelID??``,agent:Mn.selection.value.agent??null},t,Dr,kr);Mn.selection.change({...Mn.selection.value,...n,agent:n.agent??void 0}),Mn.kind===`primary`&&(c.getState().addRecentAgent(t),Mn.sessionID&&xt.getState().saveSessionAgentSelection(Mn.sessionID,t))},[Dr,or,kr,Ar,Mn.kind,Mn.selection,Mn.sessionID]);at.current=Js;let Ys=Z.useRef(null),[Xs,Zs]=Z.useState(null),Qs=Z.useCallback(e=>{Zs(t=>t===e?t:e)},[]),$s=Z.useCallback(e=>{let t=gi.current;if(!t)return;let n=t.scrollTop;if(ja){t.style.height=`100%`,t.style.maxHeight=`none`,t.style.overflowY=`auto`,oe(null),t.scrollTop!==n&&(t.scrollTop=n);return}if(Nr&&!ue){let e=t.ownerDocument?.defaultView,n=e?e.getComputedStyle(t):null,r=n?parseFloat(n.lineHeight):NaN,i=Number.isNaN(r)?20:r;t.style.height=`${i}px`,t.style.maxHeight=`${i}px`,t.style.overflow=`hidden`,t.style.overflowX=`hidden`,t.style.overflowY=`hidden`,t.scrollTop!==0&&(t.scrollTop=0),t.scrollLeft!==0&&(t.scrollLeft=0),oe(e=>e&&e.height===i&&e.maxHeight===i?e:{height:i,maxHeight:i});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=Fy({scrollHeight:t.scrollHeight||t.offsetHeight,dictationHeight:Ys.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),oe(e=>e&&e.height===u.height&&e.maxHeight===u.maxHeight?e:{height:u.height,maxHeight:u.maxHeight})},[ja,Nr,ue]);Z.useLayoutEffect(()=>{let e=Qr.length<xi.current;xi.current=Qr.length,$s({allowShrink:e})},[$s,Qr,Nr,ue]),Z.useLayoutEffect(()=>{Ys.current=Xs,$s({allowShrink:Xs===null})},[$s,Xs]);let ec=Z.useCallback((e,t,n=`manual`,r)=>{if(p===`shell`){j(!1),E(!1),I(!1),H(!1);return}if(e.startsWith(`/`)){let n=e.indexOf(` `),r=e.indexOf(`
|
|
6534
|
+
`)?`${t}\n`:`${t}\n\n`}`,hb=(e,t)=>{let n=t.trim();return n?e?`${e}${/[\s\n]$/.test(e)?``:` `}${n} `:`${n} `:e},gb=(e,t,n,r)=>t?h({transportIdentity:e},t):n?m({transportIdentity:e},n):r,_b=[],vb=({onOpenSettings:e,scrollToBottom:r,submissionBlocked:a=!1,surface:o})=>{let{t:l}=ot(),[u,f]=Z.useState({open:!1,title:``,content:``}),[p,m]=Z.useState(`normal`),[h,g]=Z.useState(!1),[y,w]=Z.useState(!1),[T,E]=Z.useState(!1),[D,O]=Z.useState(``),[k,j]=Z.useState(!1),[M,N]=Z.useState(``),[P,I]=Z.useState(!1),[R,z]=Z.useState(``),[V,H]=Z.useState(!1),[te,ne]=Z.useState(``),[ae,oe]=Z.useState(null),[se,ce]=Z.useState(null),[ue,de]=Z.useState(!1),[fe,pe]=Z.useState(`idle`),[me,he]=Z.useState(112),ge=Z.useRef(null),[_e,ve]=Z.useState(!1),ye=Z.useRef(null),be=Z.useRef(null),xe=Z.useRef(null),Se=Z.useRef(null),[Ce,De]=Z.useState(`collapsed`),Ae=q(()=>ve(!0)),[Me,Ne]=Z.useState(!1),Pe=Z.useRef(null);Z.useEffect(()=>()=>{Pe.current!==null&&window.clearTimeout(Pe.current),be.current!==null&&window.clearTimeout(be.current),xe.current!==null&&window.clearTimeout(xe.current),Se.current!==null&&window.clearTimeout(Se.current)},[]);let[Fe,Ie]=Z.useState(!1),[ze,Ve]=Z.useState(!1),[He,Ue]=Z.useState(!1),[We,Ge]=Z.useState(null),Ke=Z.useId(),[qe,Je]=Z.useState(``),[Ye,Xe]=Z.useState(``),[Ze,Qe]=Z.useState(!1),[$e,et]=Z.useState(!1),tt=Z.useRef(null),nt=Z.useRef(0),rt=Z.useCallback(()=>{nt.current=Date.now()+500,tt.current=null},[]),it=Z.useRef(0),at=Z.useRef(!1),[st,ct]=Z.useState(-1),lt=Z.useRef(()=>{}),ut=Z.useRef((...e)=>Promise.resolve().then(()=>J.getState().sendMessage(...e))).current,ft=J(e=>e.currentSessionId),pt=Ei(e=>e.currentProviderId),mt=Ei(e=>e.currentModelId),ht=Ei(e=>e.currentAgentName),gt=Ei(e=>e.currentVariant),_t=Ei(e=>e.providers),yt=Ei(e=>e.agents),St=Ei(e=>e.getVisibleAgents),Ct=Z.useMemo(()=>Gp(St()),[St,yt]),wt=Ei(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),Tt=Ei(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),Et=Z.useMemo(()=>{let e=_t.find(e=>e.id===pt)?.models?.find(e=>e.id===mt);return Qp(e)},[mt,pt,_t]),Dt=Te(e=>e.currentDirectory),Ot=os()??Dt,{ensureSessionRenderable:At}=Bl(),jt=J(Z.useCallback(e=>ft?e.getDirectoryForSession(ft):null,[ft])),Nt=Tr(ft??``,jt??void 0),Pt=Z.useMemo(()=>iy(Nt),[Nt]),Ft=Ei(e=>e.activeDirectoryKey),Lt=Z.useRef(0),Rt=Z.useRef(null),zt=J(e=>e.newSessionDraft),Ht=!!zt?.open,Ut=J(e=>e.newSessionDraft.draftSubmitting??!1),Wt=J(e=>e.newSessionDraft.draftEstablishing??!1),Gt=Ut||Wt,qt=J(e=>e.openNewSessionDraft),Jt=J(e=>e.setDraftPermissionAutoAcceptEnabled),Yt=cr(e=>e.autoAccept),Zt=cr(e=>e.saving),$t=cr(e=>e.setSessionAutoAccept),tn=J(e=>e.setNewSessionDraftTarget),rn=J(e=>e.availableWorktreesByProject),sn=J(e=>e.abortPromptSessionId),cn=J(e=>e.clearAbortPrompt),ln=vt(e=>e.consumePendingInputText),dn=vt(e=>e.pendingPresetSubmit),pn=vt(e=>e.pendingInputText),hn=vt(e=>e.pendingInputMode),gn=vt(e=>e.consumePendingSyntheticParts),_n=vt(e=>e.activeAttachmentDraft),vn=Kl(Z.useCallback(e=>{let t=ft??(Ht?`draft`:``);return t?e.drafts[t]??zy:zy},[Ht,ft])),yn=Mr(ft??``),bn=Z.useSyncExternalStore(s,t,t),xn=_n?.transportIdentity??null,Sn=_n?.owner.kind??null,Cn=_n?.owner.ownerID??null,wn=Z.useMemo(()=>gb(bn,ft,zt.draftID,xn&&Sn&&Cn?{transportIdentity:xn,owner:{kind:Sn,ownerID:Cn}}:null),[Cn,Sn,xn,bn,ft,zt.draftID]),Tn=wn?le(wn):null,Dn=vt(Z.useCallback(e=>Tn?e.draftAttachmentViews[Tn]:void 0,[Tn])),On=vt(Z.useCallback(e=>Tn?e.drafts[Tn]:void 0,[Tn])),kn=Z.useMemo(()=>{if(!On||!Dn)return _b;let e=On.attachments.flatMap(e=>{let t=Dn[e.attachmentRefID];return t?[t]:[]});return e.length===0?_b:e},[Dn,On]);Z.useEffect(()=>{wn&&vt.getState().hydrateDraftAttachments(wn)},[wn]);let jn=rm(),Mn=c(e=>e.activeMainTab===`chat`),Pn=dr(ft??``,Ot??void 0),Fn=im({kind:`primary`,surfaceID:`primary`,active:Mn,sessionID:ft,directory:Ot??null,activity:{phase:Pn?.type===`busy`?`busy`:Pn?.type===`retry`?`retry`:`idle`,canAbort:Pn?.type===`busy`||Pn?.type===`retry`},draftKey:wn,transportIdentity:bn,runtimeGeneration:i(),selection:{value:{providerID:pt,modelID:mt,agent:ht,variant:gt},catalog:{providers:_t,agents:Ct,variants:Et,variantsReady:!wt,ready:!wt&&!Tt,loading:wt||Tt},flush:async()=>{let e=J.getState().currentSessionId;if(!e)return;let n=i(),r=t(),a=Lt.current,o=e,s=J.getState().getDirectoryForSession(o)??null,c=Cr(s);if(Ei.getState().activeDirectoryKey!==c&&await Ei.getState().activateDirectory(s),i()!==n||t()!==r||J.getState().currentSessionId!==o||Ei.getState().activeDirectoryKey!==c||Lt.current!==a)return;await At(o,{directory:s??void 0});let l=J.getState().getDirectoryForSession(o)??null,u=Cr(l);if(i()!==n||t()!==r||J.getState().currentSessionId!==o||l!==s||u!==c||Ei.getState().activeDirectoryKey!==c||Lt.current!==a)return;let d=Ei.getState(),f={providers:d.providers,agents:d.getVisibleAgents()};if(f.providers.length===0||f.agents.length===0)return;let p=iy(ur(o,l??void 0)),m=xt.getState(),h=ey({sessionId:o,latestUserChoice:p,catalog:f,memory:m,fallbackAgentName:d.currentAgentName});if(!h)return;let g=[o,h.source,h.messageId??``,h.agent??``,h.providerID,h.modelID,h.variant??``,c].join(`|`);Rt.current!==g&&(ty(h,{currentAgentName:d.currentAgentName,setAgent:d.setAgent,setProvider:d.setProvider,setModel:d.setModel,setCurrentVariant:d.setCurrentVariant},{sessionId:o,memory:m}),Rt.current=g)},change:async e=>{Lt.current+=1;let t=Ei.getState();Yv(e,{currentAgentName:t.currentAgentName,setAgent:t.setAgent,setProvider:t.setProvider,setModel:t.setModel,setCurrentVariant:t.setCurrentVariant,saveAgentModelSelection:t.saveAgentModelSelection},{sessionId:J.getState().currentSessionId,memory:xt.getState()});let n=J.getState().currentSessionId;if(n){let r=J.getState().getDirectoryForSession(n)??void 0,i=iy(ur(n,r)),a=xt.getState(),o=ey({sessionId:n,latestUserChoice:i,catalog:{providers:t.providers,agents:t.getVisibleAgents()},memory:a,fallbackAgentName:e.agent??t.currentAgentName});o&&(Rt.current=[n,o.source,o.messageId??``,o.agent??``,o.providerID,o.modelID,o.variant??``,Ei.getState().activeDirectoryKey].join(`|`))}}},resources:{attachments:kn,addAttachment:async e=>{wn&&await Qt(wn,()=>vt.getState()).addLocal(e)},removeAttachment:async e=>wn?Qt(wn,()=>vt.getState()).removeByAttachmentID(e):!1,clearAttachments:async()=>wn?Qt(wn,()=>vt.getState()).clearRootAttachments():!1,restoreAttachments:async e=>wn?Qt(wn,()=>vt.getState()).restoreRootAttachments(e):!1,pendingInput:pn===null?null:{text:pn,mode:hn},consumePendingInput:ln,pendingPreset:dn,consumePendingPreset:()=>vt.getState().consumePendingPresetSubmit(),consumeSyntheticParts:gn,restoreSyntheticParts:e=>vt.setState(t=>({pendingSyntheticParts:[...e,...t.pendingSyntheticParts??[]]})),inlineDrafts:vn,removeInlineDraft:e=>{let t=ft??(Ht?`draft`:``);t&&Kl.getState().removeDraft(t,e)},restoreInlineDrafts:e=>{let t=ft??(Ht?`draft`:``);!t||e.length===0||Kl.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:yn,captureRuntime:()=>vt.getState().captureDraftRuntime(),getDraft:e=>vt.getState().getDraft(e),abortPrompt:{sessionID:sn,clear:cn}},backend:{send:e=>{Gv(e,{transportIdentity:t(),runtimeGeneration:i()});let n=Kv(e);return ut(e.text??``,e.providerID,e.modelID,e.agent,e.attachments??[],e.agentMention,e.parts,e.variant,e.inputMode,n)},sendQueued:e=>bt(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()=>qt(),compact:async e=>ke.summarizeSession(e.sessionID??``,e.providerID??``,e.modelID??``,e.directory),abort:e=>(e.sessionID&&Xt(e.sessionID),Bt(e.sessionID??``))},shortcuts:{cycle:e=>lt.current(e),new:()=>qt(),abort:()=>(ft&&Xt(ft),Bt(ft??``)),submit:()=>{}},deliveryTarget:{kind:`primary`}}),In=am(Fn,o??jn);om(In),Z.useLayoutEffect(()=>{if(!In.active){Wv(In.surfaceID);return}return Uv(In),()=>Wv(In.surfaceID)},[In]);let Ln=Jv(In),Rn=In.resources??(In.kind===`primary`?Fn.resources:void 0);if(!Rn)throw Error(`chat-input-surface-resources-incomplete`);let zn=[...Rn.attachments],Bn=In.sessionID,Vn=sm(In,Gt),Un=In.kind===`secondary`?In.commands.hasNewDraft:Ht,Gn=Un,Kn=In.directory??Ot,qn=In.draftKey??wn,Jn=Z.useMemo(()=>{if(In.kind===`secondary`)return lm(In,!1,!1);let e=Bn?Xy(Bn,jt??void 0):!1;return lm(In,e,Un)},[In,Bn,jt,Un]),Yn=(e,t,n,r,i,a,o,s,c,l)=>Ln?Ln.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`)),Zn=Z.useCallback(()=>Ln?Ln.abort():Promise.reject(Error(`chat-input-surface-incomplete`)),[Ln]),Qn=qi(e=>e.projects),er=qi(e=>e.activeProjectId),nr=qi(e=>e.setActiveProjectIdOnly),[rr,ir]=Z.useState(!1),[ar,or]=Z.useState(!1),sr=Z.useMemo(()=>Bn?Fi({autoAccept:Yt,sessions:[],sessionById:ci(),sessionID:Bn}):zt.permissionAutoAcceptEnabled===!0,[Bn,zt.permissionAutoAcceptEnabled,Yt]),pr=Ei(e=>e.agents),mr=In.kind===`secondary`?In.selection.value.agent:ht,hr=In.kind===`secondary`?Gp(In.selection.catalog?.agents):pr,_r=d()||Iv(hr,mr),vr=Z.useCallback(()=>{Ii.error(l(`chat.chatInput.toast.togglePermissionAutoAcceptFailed`))},[l]),yr=In.selection.value,br=In.selection.change,xr=In.selection.catalog,Er=Z.useMemo(()=>({selection:{providerID:yr.providerID??``,modelID:yr.modelID??``,agent:yr.agent??null,variant:yr.variant},onChange:async e=>{if(!br)throw Error(`chat-input-surface-selection-readonly`);await br({...e,agent:e.agent??void 0,variant:e.variant})},disabled:!In.active,catalog:xr}),[xr,br,yr.agent,yr.modelID,yr.providerID,yr.variant,In.active]);Z.useEffect(()=>{if(In.kind!==`primary`||!ft){ft||(Rt.current=null);return}if(wt||Tt||_t.length===0||Ct.length===0)return;let e=Cr(jt);if(Ft!==e)return;let t=xt.getState(),n=ey({sessionId:ft,latestUserChoice:Pt,catalog:{providers:_t,agents:Ct},memory:t,fallbackAgentName:ht});if(!n)return;let r=[ft,n.source,n.messageId??``,n.agent??``,n.providerID,n.modelID,n.variant??``,Ft].join(`|`);if(Rt.current===r)return;if((n.agent===void 0||n.agent===ht)&&n.providerID===pt&&n.modelID===mt&&n.variant===gt){Rt.current=r;return}if(Ei.getState().activeDirectoryKey!==e)return;let i=Ei.getState();ty(n,{currentAgentName:i.currentAgentName,setAgent:i.setAgent,setProvider:i.setProvider,setModel:i.setModel,setCurrentVariant:i.setCurrentVariant},{sessionId:ft,memory:t}),Rt.current=r},[In.kind,ft,Pt,_t,Ct,wt,Tt,Ft,jt,ht,pt,mt,gt]);let Dr=Ei(e=>e.getVisibleAgents),kr=In.kind===`primary`?Dr():By,Ar=Ei(e=>In.kind===`primary`?e.providers:Vy),jr=In.kind===`secondary`?Gp(In.selection.catalog?.agents):kr,Nr=In.kind===`secondary`?In.selection.catalog?.providers??Vy:Ar,Fr=In.kind===`secondary`&&(!In.selection.catalog?.ready||!!In.selection.catalog.error),Ir=!In.active||!In.selection.change||Fr,Lr=c(e=>e.isMobile),Rr=c(e=>e.setImagePreviewOpen),zr=Z.useCallback(e=>{e.image&&(f(e),Rr(!0))},[Rr]),Br=Z.useCallback(e=>{f(t=>({...t,open:e})),Rr(e)},[Rr]),Ur=xl(e=>e.pending),Kr=c(e=>e.inputBarOffset),qr=c(e=>e.persistChatDraft),Yr=c(e=>e.inputSpellcheckEnabled),Xr=c(e=>e.isExpandedInput),Zr=c(e=>e.setExpandedInput),Qr=c(e=>e.setTimelineDialogOpen),$r=Py({draftKey:qn,sessionTitles:new Map(Array.from(ci(),([e,t])=>[e,t.title||e])),persistenceEnabled:qr}),ti=$r.document,ni=ti.text,{replacePlainDocument:ii,replaceProgrammaticText:ai,applyBrowserEdit:oi,insertReference:si,deleteReference:li,enterHistoryPreview:ui,exitHistoryPreview:di,captureSubmission:pi,recoverSubmission:mi,confirmedFileMentions:hi,mentions:gi}=$r,vi=Z.useCallback((e,t)=>ai(e,t),[ai]),bi=Z.useCallback(e=>!e.startsWith(`session:`)&&(e.includes(`/`)||e.includes(`\\`)||e.includes(`.`)||hi.some(t=>t.value===e)),[hi]),xi=Z.useRef(null),Si=Z.useRef(!1),Ci=Z.useRef(0),Ti=Z.useRef(ni.length),Di=Z.useRef(null),ki=Z.useRef(0),ji=Z.useRef(!1),Mi=Z.useRef(null),Pi=Z.useRef(!1),Li=Z.useRef(null),zi=Z.useRef([]),Bi=Z.useRef(!1),Vi=Z.useRef(null),Ui=Z.useRef(!1),Wi=Z.useRef(null),Gi=Z.useRef(null),Ki=Z.useRef(null),Ji=Z.useRef(ni),Yi=Z.useRef(new Set),Xi=$r.getDocument,Zi=Z.useCallback((e,t,n=[])=>vi(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}`))]}),[vi]),Qi=$m(Qm()),{git:ea,vscode:ta}=ko(),na=c(e=>e.shortcutOverrides.cycle_agent),ia=c(e=>e.shortcutOverrides),aa=Z.useMemo(()=>Xa(`cycle_agent`,na?{cycle_agent:na}:void 0),[na]),oa=Z.useMemo(()=>Xa(`clear_all_messages`,ia),[ia]),{currentTheme:sa}=Va(),ca=As(),la=Hs(Kn),ua=Es(e=>Kn?e.directories.get(Kn)?.status??null:null),da=Es(e=>e.ensureStatus),fa=Es(e=>e.fetchStatus),[pa,ha]=Z.useState(!1),_a=Z.useRef(null),[va,ba]=Z.useState(!1),Ca=c(e=>e.isAgentSelectorOpen),Da=c(e=>e.isModelSelectorOpen),[Oa,Aa]=Z.useState(!1);Z.useEffect(()=>{!Kn||!ea||da(Kn,ea)},[Kn,ea,da]),Z.useEffect(()=>{if(!(!Kn||!ea))return Hr.onGitRefreshHint(e=>{nb(e.directory)===nb(Kn)&&fa(Kn,ea)})},[Kn,ea,fa]);let ja=Z.useCallback(async e=>{if(!Bn)return;let t=J.getState().getDirectoryForSession(Bn)||Kn||``;if(!t){Ii.error(l(`diffView.reviewDialog.toast.noSessionDirectory`));return}or(!0);try{await Jr({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}),ir(!1)}catch(e){console.error(`[review-flow] failed to start review flow`,e),Ii.error(e instanceof Error?e.message:l(`diffView.reviewDialog.toast.startFailed`))}finally{or(!1)}},[Bn,Kn,l]),Ma=Xr&&!Lr,Na=Xr&&Lr,Ra=Ma||Na,za=`1.5rem`,Ba=Lr||Oa;Z.useEffect(()=>{let e=Di.current;if(!e)return;let t=e=>{let t=e>0&&e<Gy;Aa(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 Ha=zn,Ua=Z.useMemo(()=>new Set(jr.map(e=>e.name.toLowerCase())),[jr]),Wa=Z.useRef(Ua);Wa.current=Ua;let Ga=Uy({inputMode:p,message:ni,showCommandAutocomplete:k,showSkillAutocomplete:P}),Ka=gr({directory:Kn,enabled:Ga}),qa=Z.useMemo(()=>Ka.data??[],[Ka.data]),Ja=Wr({directory:Kn,enabled:Ga}),Ya=Z.useMemo(()=>Ja.data??[],[Ja.data]),Za=Z.useMemo(()=>new Map(Ya.map(e=>[e.name.toLowerCase(),e.name])),[Ya]),to=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`]);!Lr&&!d()&&e.add(`handoff-review`);for(let t of qa)e.add(t.name.toLowerCase());for(let t of Ya)e.add(t.name.toLowerCase());return e},[qa,Ya,Lr]),no=Z.useMemo(()=>{if(!ni||!ni.includes(`/`)||p===`shell`||to.size===0)return[];let e=[],t=RegExp(`(^|\\s)/(${ee})?([A-Za-z0-9][A-Za-z0-9_-]*)`,`g`),n;for(;(n=t.exec(ni))!==null;){let t=n[2]??``,r=n[3];if(!to.has(r.toLowerCase()))continue;let i=n.index+n[1].length,a=1+t.length+r.length,o=Za.get(r.toLowerCase());e.push(o?{start:i,end:i+a,style:`mentionCommand`,priority:102,skillName:o,visual:ie({trigger:`/`,icon:`book-open`,label:o},ni.slice(i,i+a))}:{start:i,end:i+a,style:`mentionCommand`,visual:ie({trigger:`/`,icon:`command`,label:r},ni.slice(i,i+a))})}return e},[Za,p,to,ni]),ro=ga(e=>e.snippets),io=Z.useMemo(()=>{let e=new Set;for(let t of ro){e.add(t.name.toLowerCase());for(let n of t.aliases??[])e.add(n.toLowerCase())}return e},[ro]),ao=Z.useMemo(()=>{if(!ni||!ni.includes(`#`)||p===`shell`||io.size===0)return[];let e=[],t=/(^|\s)#([A-Za-z0-9][A-Za-z0-9_-]*)/g,n;for(;(n=t.exec(ni))!==null;){let t=n[2];if(!io.has(t.toLowerCase()))continue;let r=n.index+n[1].length;e.push({start:r,end:r+1+t.length,style:`mentionSnippet`})}return e},[p,io,ni]),oo=Z.useMemo(()=>{if(!ni||!ni.includes(`@`)||p===`shell`)return[];let e=[],t=/@([^\s]+)/g,n;for(;(n=t.exec(ni))!==null;){let t=n[0],r=String(n[1]||``).trim().replace(/[),.;:!?`"'>]+$/g,``),i=n.index,a=i+t.length,o=i>0?ni[i-1]:null;!(!o||/(\s|\(|\)|\[|\]|\{|\}|"|'|`|,|\.|;|:)/.test(o))||r.length===0||r.startsWith(`session:`)||(Ua.has(r.toLowerCase())?e.push({start:i,end:a,kind:`agent`}):bi(r)&&e.push({start:i,end:a,kind:`file`}))}return e},[p,ni,Ua]),so=Z.useMemo(()=>{if(!ni||!ni.includes(`[`)||p===`shell`||Ha.length===0)return[];let e=Ha.filter(Oe),t=new Map(e.map(e=>[e.filename.trim().toLowerCase(),e.mimeType.startsWith(`image/`)?`image`:`attachment`]));return Re(ni,e.map(e=>e.filename)).flatMap(e=>{let n=G(ni.slice(e.start+1,e.end-1)).trim(),r=t.get(n.toLowerCase());return[{...e,style:`mentionFile`,priority:101,visual:ie({trigger:`[`,icon:r===`image`?`file-image`:`attachment-2`,label:n,suffix:`]`},ni.slice(e.start,e.end))}]})},[p,ni,Ha]),co=Z.useMemo(()=>{if(!ni||p===`shell`)return null;let e=[...M_(ni),...J_(ni),...L_(oo),...no,...ao,...so,...ti.references.map(e=>({start:e.start,end:e.end,priority:103,...A(e)}))];return N_(ni,e)},[so,no,ao,oo,ti.references,p,ni]),lo=Z.useCallback(e=>(e??[]).map(e=>({...e,dataUrl:e.source===`server`&&e.serverPath?eb(e.serverPath):e.dataUrl})),[]),[uo,fo]=Z.useState(null),mo=Z.useRef(null),[ho,go]=Z.useState(!1),[_o,vo]=Z.useState(!1),[yo,bo]=Z.useState(null),[xo,So]=Z.useState(null),Co=C(e=>e.followUpBehavior),wo=Z.useMemo(()=>{let e=Ln?.queueScope;return e?{state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:e.deliveryTarget,runtimeGeneration:e.runtimeGeneration}:null},[Ln]),To=au({transportIdentity:wo?.transportIdentity??``,directory:wo?.directory??``,sessionID:wo?.sessionID??``}),Eo=Z.useMemo(()=>Bn?x(Bn):null,[Bn]),Do=C(Z.useCallback(e=>wo?b(e,wo):Ry,[wo])),Oo=C(Z.useCallback(e=>Eo?b(e,Eo):Ry,[Eo])),Ao=Z.useMemo(()=>Oo.length===0?Do:Do.length===0?Oo:[...Oo,...Do],[Do,Oo]),jo=To.mode===`server`?Ry:Ao,Mo=C(Z.useCallback(e=>wo?B(e,wo):Ry,[wo])),No=C(e=>e.clearQueue),Po=C(e=>e.removeFromQueue),Fo=Rn.inlineDrafts,Io=Fo.length>0,[Lo,Ro,zo]=Z.useMemo(()=>{let e=0,t=0,n=0;for(let r of Fo)r.source===`preview-console`?e+=1:r.source===`preview-annotation`?t+=1:n+=1;return[e,t,n]},[Fo]),Bo=Z.useCallback(e=>{for(let t of Rn.inlineDrafts)t.source===e&&Rn.removeInlineDraft(t.id)},[Rn]),Vo=Z.useCallback(()=>{for(let e of Rn.inlineDrafts)e.source!==`preview-console`&&e.source!==`preview-annotation`&&Rn.removeInlineDraft(e.id)},[Rn]),Ho=Rn.history;Z.useEffect(()=>{Ji.current=ni},[ni]),Z.useLayoutEffect(()=>{m(`normal`),ct(-1)},[qn?.transportIdentity,qn?.owner.kind,qn?.owner.ownerID]),Z.useLayoutEffect(()=>{if(!Un||Lr)return;let e=()=>{let e=xi.current;!e||e.disabled||e.focus({preventScroll:!0})};e();let t=window.requestAnimationFrame(e);return()=>window.cancelAnimationFrame(t)},[Un,Lr]);let Uo=Uh(In.kind===`primary`?Bn:null,In.kind===`primary`?Kn??void 0:void 0),Wo=In.activity?.phase??Uo.phase,Go=Kt(Z.useCallback(e=>{if(!Bn)return!1;let t=e.runsByOriginalSessionID[Bn];return t?.status===`running`&&t.runtimeKey===n()},[Bn])),Ko=q(e=>{Lr&&(rt(),ce(e),xi.current?.blur(),Ei.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobilePanel`}))}),qo=Rn.pendingInput,Jo=Rn.consumePendingInput;Z.useEffect(()=>{if(qo===null)return;let e=Jo();if(e){if(e.mode===`append`){if(!e.text.trim())return;let t=mb(Ji.current,e.text);Ji.current=t,vi(t)}else if(e.mode===`append-inline`){let t=hb(Ji.current,e.text);Ji.current=t,vi(t)}else ii(e.text);setTimeout(()=>{xi.current?.focus()},0)}},[qo,Jo,ii,vi]);let Yo=ni.trim().length>0||Ha.length>0||Io,Xo=To.mode===`server`?To.items.length>0:jo.length>0||Mo.length>0,Zo=!$d(To.mode),Qo=Yo||Xo,$o=J(e=>e.stagedMessageEdit?.sessionId===Bn?e.stagedMessageEdit.messageId:null),es=Wo===`busy`||Wo===`retry`,ts=In.activity?.canAbort??es,ns=Z.useCallback(()=>{let e=xi.current,t=e?.value??Xi().text;t!==Xi().text&&oi(t,e?.selectionStart??t.length,e?.selectionEnd??e?.selectionStart??t.length);let n=Xi();return{message:n.text,document:n,hasContent:n.text.trim().length>0||Ha.length>0||Io}},[oi,Xi,Io,Ha.length]),rs=Z.useRef(async()=>{}),is=In.surfaceID,as=zt?.draftID??null,ss=En(Z.useMemo(()=>Hn(is),[is])),cs=En(Z.useMemo(()=>Mt(as),[as])),ls=Z.useMemo(()=>Hi(ss,cs),[ss,cs]),us=(e=`send`)=>En.getState().beginFlight(is,e),ds=()=>{En.getState().endFlight(is)},fs=()=>En.getState().isInFlight(is),ps=Z.useRef(null);Z.useEffect(()=>{if(In.kind!==`primary`||!$o){ps.current=null;return}ps.current!==$o&&(ps.current=$o,Xp(xi)||requestAnimationFrame(()=>Xp(xi)))},[$o,In.kind]);let ms=En(Z.useMemo(()=>It(as),[as])),hs=q(async()=>{let e=J.getState().newSessionDraft.draftID;if(!e||!En.getState().isEstablishing(e))return!1;let t=ns();if(!t.hasContent)return!1;let n=K(t.document,`queue-canonical`);if(!n.ok)return Ii.error(l(`chat.chatInput.toast.messageSendFailed`)),!1;if(await In.selection.flush(),!En.getState().isEstablishing(e))return!1;let r=ny(Ei.getState());if(!r?.providerID||!r?.modelID)return Ii.error(l(`chat.chatInput.toast.messageSendFailed`)),!1;let i=lo(Ha);return En.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})?(ii(``),ct(-1),Zr(!1),i.length>0&&Rn.clearAttachments(),!0):!1}),gs=()=>{if(Bn)return!1;let e=J.getState().newSessionDraft.draftID;return En.getState().isEstablishing(e)?(hs(),!0):!1},_s=q(async()=>{if(!In.active||fs())return;if(Bn){let e=J.getState().stagedMessageEdit;if(e&&e.sessionId===Bn){J.getState().beginMessageEditCommit(e.sessionId,e.messageId);try{await $i(e.sessionId,e.messageId)}catch(e){console.warn(`[chat-input] staged-edit delete failed before queue admission`,e);return}finally{J.getState().endMessageEditCommit(e.sessionId,e.messageId)}J.getState().stagedMessageEdit===e&&J.getState().clearStagedMessageEdit(e.sessionId)}}let e=ns(),n=K(e.document);if(!n.ok){Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}let r={chunks:n.chunks??[],semantics:n.semantics??[]},o=n.text,s=o.trimStart(),c=r.chunks.every(e=>e.provenance===`authored`)&&p===`normal`&&s.startsWith(`/`)?Cv(s.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(c&&!Ss(c,e=>tm(In,{name:e.name,source:`openchamber`}))||a||!e.hasContent||!Bn)return;if(Zo||!an(In.deliveryTarget?.kind,To.mode)){rs.current(es?{delivery:`steer`}:void 0);return}if(r.chunks.every(e=>e.provenance===`authored`)&&yv(o,p)){rs.current();return}if(!us(`queue`))return;let u=In.transportIdentity,d=In.runtimeGeneration,f=Rn.captureRuntime(),m=wo,h=In.kind===`primary`?wo?.sessionID??Bn:null,g=[...Rn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt),_=g.length>0?v(Yl(e.document.text,g),e.document.references).document:e.document,y=K(_,`queue-canonical`);if(!y.ok){ds(),Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}let b=lo(Ha),w=pi(),T=b,E=$n(),D=!1,O=null,k=()=>{D&&m&&(To.actions.unstageAdmission({requestID:E.requestID,scope:{directory:m.directory,sessionID:m.sessionID}}),D=!1),O&&m&&(C.getState().unstageAdmission(m,O),O=null)},A=async e=>{k(),w&&mi(w),T.length>0&&await Rn.restoreAttachments(T),e&&Rn.restoreSyntheticParts(e),g.length>0&&Rn.restoreInlineDrafts(g)};try{if(!m){Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}if(To.mode===`server`){if(!qn){Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}en({stage:()=>{To.actions.stageAdmission({requestID:E.requestID,scope:{directory:m.directory,sessionID:m.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:gi}}),D=!0},clearComposer:()=>{ii(``),ct(-1),Zr(!1)}})}else en({stage:()=>{C.getState().bindLegacyQueue(x(m.sessionID),m),C.getState().stageAdmission(m,{requestID:E.requestID,queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:gi}),O=E.requestID},clearComposer:()=>{ii(``),ct(-1),Zr(!1)}});if(await In.selection.flush(),!dt({transportIdentity:u,generation:d},{transportIdentity:t(),generation:i()})){await A();return}if(!dt(f,Rn.captureRuntime())){await A();return}if(h&&J.getState().currentSessionId!==h){await A();return}if(m.transportIdentity!==t()||m.runtimeGeneration!==i()||m.sessionID!==(h??m.sessionID)||h&&S(J.getState().getDirectoryForSession(h))!==S(m.directory)){await A();return}let n=m,r=In.kind===`primary`?(()=>{let e=Ei.getState(),t=h?J.getState().getDirectoryForSession(h)??null:null;return ny(e,{expectedConfigKey:Cr(t),activeDirectoryKey:e.activeDirectoryKey})})():In.selection.value.providerID&&In.selection.value.modelID?{...In.selection.value,providerID:In.selection.value.providerID,modelID:In.selection.value.modelID}:void 0;if(!An(r)){await A();return}if(To.mode===`server`){if(!qn){await A(),Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}let t=tr({draftKey:qn,runtime:f,document:e.document,attachments:Ha,inlineDrafts:g}),i=n.deliveryTarget.kind===`assistant`?Rn.consumeSyntheticParts()?.map(e=>({...e,partID:e.partID??L()}))??null:null,a,o=[],s=n.deliveryTarget.kind===`assistant`?(()=>{let e=wi({plan:{chunks:y.chunks??[],semantics:y.semantics??[]},agents:jr,installedSkillNames:new Set(Oi(re,Kn).map(e=>e.name)),directory:Kn,root:ca||Kn,confirmedFilePaths:hi.map(e=>e.path),confirmedDirectoryPaths:hi.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Ha});return o=e.attachments,Or({text:g.length>0?Yl(e.text,g):e.text,attachments:[...b,...e.attachments],semanticParts:ri(e.semantics,n.directory),syntheticParts:i})})():void 0;try{let e=[..._i(b),..._i(o),...(i??[]).flatMap(e=>_i(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),Ii.error(l(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`));return}let c=s&&i?Ai(s,i.map(e=>({...e,partID:e.partID}))):void 0;try{let e=!1,o=await Vt({capture:t,admit:async()=>{let t=await To.actions.admit({requestID:E.requestID,scope:{directory:n.directory,sessionID:n.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,composerDocument:_,composerMentions:gi,sendConfig:r,deliveryTarget:n.deliveryTarget,...s?{deliveryParts:s}:{},...c?{syntheticParts:c}:{},attachmentIssues:[],createdAt:E.createdAt},attachments:a});return t.status===`committed`&&(e=!0,D=!1),t},captureRuntime:Rn.captureRuntime,getCurrentDraftKey:()=>qn,getDocument:Xi,consumeBody:()=>ii(``),getAttachments:()=>Rn.attachments,removeAttachment:Rn.removeAttachment,getInlineDrafts:()=>Rn.inlineDrafts,removeInlineDraft:Rn.removeInlineDraft});if(!e){await A(i),o.status===`stale`&&Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}if(o.status===`partial`){Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}o.status===`committed`&&!Lr&&xi.current?.focus()}catch(e){await A(i),Ii.error(l(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}return}if(!C.getState().confirmAdmission(n,{requestID:E.requestID,sendConfig:r,attachments:b.length>0?b:void 0}).ok){await A(),Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}O=null;for(let e of g)Rn.removeInlineDraft(e.id);b.length>0&&Rn.clearAttachments(),Lr||xi.current?.focus()}catch(e){await A(),Ii.error(l(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}finally{ds()}}),vs=q(()=>{Mv(()=>_s(),()=>{Ii.error(l(`chat.chatInput.toast.messageSendFailed`))})}),xs=q(async(e,t,n,r)=>{if(Zo||!In.draftKey)return!1;try{let i=await Nn({content:e,composerDocument:n,composerMentions:r,attachments:t}),a=vt.getState(),o=a.getDraft(In.draftKey);return tf(await un({key:In.draftKey,expectedRevision:o?.revision??`absent`,payload:i,runtime:a.captureDraftRuntime()}))?!0:(Ii.error(l(`chat.chatInput.toast.messageSendFailed`)),!1)}catch{return Ii.error(l(`chat.chatInput.toast.messageSendFailed`)),!1}}),Cs=q(e=>{if(!(a||Zo)){if(Ln){Ln.sendQueued(e,{options:{delivery:`steer`},manual:!0});return}Ii.error(l(`chat.chatInput.toast.messageSendFailed`))}}),Ts=q(()=>{rt(),ce(`agent`),xi.current?.blur(),Ei.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobileAgentPanel`})}),Ds=Z.useCallback(()=>{go(!0)},[]),Ms=Z.useCallback(()=>{vo(!0)},[]),Ns=async e=>{if(!In.active||a||gs()||fs())return;let n=e?.queuedOnly??!1,o=e?.queuedMessageId,s=e?.delivery===`steer`&&es?`steer`:void 0,u=e?.presetText==null?ns():{message:e.presetText,document:{text:e.presetText,references:[]},hasContent:e.presetText.trim().length>0||Ha.length>0||Io},f=e?.presetText==null?pi():null,m=zn,h=K(u.document,`direct-send-display`);if(!h.ok){Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}let g=h.text,v={chunks:h.chunks??[],semantics:h.semantics??[]},y=v.chunks.every(e=>e.provenance===`authored`),x=g.trimStart(),S=y?_v(x,p):null,w=y&&yv(g,p),T=y&&p===`normal`&&/^\/model(?:\s|$)/i.test(x),E=y&&p===`normal`&&x.startsWith(`/`)?Cv(x.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(E&&!Ss(E,e=>tm(In,{name:e.name,source:`openchamber`}))||n&&Zo)return;if(!n&&T){j(!1),N(``),Lr?Ko(`model`):(c.getState().setModelSelectorOpen(!0),Ei.getState().refreshCatalogsOnPickerOpen({source:`chatInput:modelCommand`}));return}if(!(!n&&S&&S!==`model`)){if(!n&&Bn&&Xo&&Zo)return;if(!n&&Bn&&Xo&&To.mode===`server`){u.hasContent&&vs();return}if(!n&&Bn&&Xo){u.hasContent&&vs();let e=jo[0];e&&Ln&&await Ln.sendQueued(e.queueItemID,{options:es?{delivery:`steer`}:void 0});return}}let D=w?[]:o?jo.filter(e=>e.id===o):jo;if(n&&Go)return;if(n){if(D.length===0||!Bn)return}else if(!u.hasContent&&!Xo||!Bn&&!Un)return;if(!Bn&&Vn||!us())return;let O=!Bn&&Un&&!n&&!w?J.getState().newSessionDraft.draftID??null:null,k=O?W(`msg`):void 0;if(O&&k&&!En.getState().beginEstablishing({draftID:O,primaryMessageID:k})){ds();return}let A=()=>{lr(),O&&En.getState().clearEstablishing(O)},M=e=>{let n=J.getState().currentSessionId,r=(n?J.getState().getDirectoryForSession(n):null)??Kn??``;if(!n||!r){En.getState().clearEstablishing(e);return}jv({draftID:e,sessionID:n,directory:r,transportIdentity:t(),runtimeGeneration:i(),admitServer:To.mode===`server`?async e=>To.actions.admit({requestID:e.requestID,scope:{directory:r,sessionID:n},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?_i(e.attachments):void 0}):void 0})};if(Bn&&!n&&!w&&Go){ds(),vs();return}let P=!n&&!w;P&&(ii(``),ct(-1),Zr(!1));let F=!1,I,L,R=!1;try{if(Dv({surfaceKind:In.kind,currentSessionId:Bn,queuedOnly:n,resourcePolicy:w,inputMode:p,localCommand:S})&&Bn){let e=J.getState().getDirectoryForSession(Bn)??Kn??null,t=J.getState().stagedMessageEdit;t&&t.sessionId===Bn&&(L={sessionId:t.sessionId,messageId:t.messageId},J.getState().beginMessageEditCommit(t.sessionId,t.messageId));let n=Ei.getState(),r=ny(n,{expectedConfigKey:Cr(e),activeDirectoryKey:n.activeDirectoryKey});if(r?.providerID&&r?.modelID){let t=lo(Ha);I=fn({sessionId:Bn,directory:e,content:u.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=In.kind===`primary`?(()=>{if(n){let e=D[0]?.owner;if(e?.state===`bound`||e?.state===`unbound-legacy`)return e.sessionID;if(wo?.sessionID)return wo.sessionID}return Bn})():null,t=n?D[0]?.sendConfig:void 0;if(n&&t||await In.selection.flush(),e!==null&&J.getState().currentSessionId!==e)return;let i=async()=>{let n=t?{...t}:In.kind===`primary`?(()=>{let t=Ei.getState();if(!e)return ry({captured:ny(t),surfaceSelection:In.selection.value});let n=J.getState().getDirectoryForSession(e)??Kn??null;return ry({captured:ny(t,{expectedConfigKey:Cr(n),activeDirectoryKey:t.activeDirectoryKey}),surfaceSelection:In.selection.value})})():In.selection.value.providerID&&In.selection.value.modelID?{...In.selection.value,providerID:In.selection.value.providerID,modelID:In.selection.value.modelID}:void 0;if(In.kind===`primary`&&e&&(!n?.providerID||!n?.modelID)){let t=J.getState().getDirectoryForSession(e)??Kn??null,r=Cr(t);if(Ei.getState().activeDirectoryKey!==r&&await Ei.getState().activateDirectory(t),J.getState().currentSessionId===e){let e=Ei.getState();n=ry({captured:ny(e,{expectedConfigKey:Cr(t),activeDirectoryKey:e.activeDirectoryKey}),surfaceSelection:In.selection.value})}}return n},a=await i(),c=!1,h=a?.providerID,g=a?.modelID,y=a?.agent,x=a?.variant;if(!h||!g){if(!c){c=!0;try{await Ei.getState().loadProviders({forceRefresh:!0,source:`chat-input-send-recovery`}),a=await i(),h=a?.providerID,g=a?.modelID,y=a?.agent,x=a?.variant}catch{}}if(!h||!g){console.warn(`Cannot send message: provider or model not selected`),Ii.error(l(`chat.chatInput.toast.messageSendFailed`));return}}Bn&&!n&&!w&&await Xn(Bn)&&await Bt(Bn);let T={...s?{delivery:s}:{},commitStagedMessageEdit:!n,...I?{messageID:I.messageID,ticket:I}:k?{messageID:k}:{},...e?{sessionId:e,directoryHint:J.getState().getDirectoryForSession(e)??Kn??null}:In.kind===`primary`&&Bn?{sessionId:Bn,directoryHint:J.getState().getDirectoryForSession(Bn)??Kn??null}:{}},E=``,j=[],N,P=[],z=new Set(Oi(re,Kn).map(e=>e.name)),B=[],V=w?void 0:Rn.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(Oi(re,i).map(e=>e.name)),o=wi({plan:r??Gr(t.content),agents:jr,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,j=Ni([...lo(t.attachments),...o.attachments]);else{let e=lo(t.attachments);P.push({text:o.text,attachments:Ni([...e,...o.attachments])})}}if(!n&&u.hasContent){let e=lo(Ha),t=wi({plan:v,agents:jr,installedSkillNames:z,directory:Kn,root:ca||Kn,confirmedFilePaths:hi.map(e=>e.path),confirmedDirectoryPaths:hi.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:Ha});B.push(...t.semantics),!N&&t.agent&&(N=t.agent),D.length===0?(E=t.text,j=Ni([...e,...t.attachments])):P.push({text:t.text,attachments:Ni([...e,...t.attachments])})}let H=Bn??(Un?`draft`:null),U=[];if(!n&&H&&!w&&(U=[...Rn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt)),U.length>0)if(D.length===0)E=Yl(E,U);else if(P.length>0){let e=P[P.length-1];e.text=Yl(e.text,U)}else E=Yl(E,U);if(V&&V.length>0&&P.push(...fi(V)),yo&&P.push({text:yo.contextText,synthetic:!0}),xo&&(P.push({text:xo.instructionsText,synthetic:!0}),P.push({text:xo.contextText,synthetic:!0})),P.push(...ri(B,Bn&&J.getState().getDirectoryForSession(Bn)||Kn)),!E&&j.length===0&&P.length===0)return;if(O&&k){if(!await Vr({messageID:k,providerID:h,modelID:g,agent:y,text:E,attachments:j,additionalParts:P,agentMentionName:N}))return;if(!En.getState().isEstablishing(O)){A();return}}let W=async()=>{if(A(),wo&&D.length>0&&C.setState(e=>{let t=_(wo),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))]}}}),n)return V&&Rn.restoreSyntheticParts(V),!0;Rn.pendingInput?.text===u.message&&Rn.consumePendingInput(),f&&mi(f);let e=!0;return m.length>0&&(e=await Rn.restoreAttachments(m)),V&&Rn.restoreSyntheticParts(V),U.length>0&&Rn.restoreInlineDrafts(U),e};if(!w&&Bn&&o){let e=wo?b(C.getState(),wo).find(e=>e.id===o||e.queueItemID===o):void 0;wo&&e?.queueItemID&&e.operationID&&Po(wo,e.queueItemID,e.operationID)}else!w&&Bn&&Xo&&wo&&No(wo);!n&&!w&&(ii(``),ct(-1),Zr(!1),Ev({queuedOnly:n,resourcePolicy:w,rootAttachmentCount:m.length})&&Rn.clearAttachments());let ee=()=>wv({currentSessionId:Bn,messageRef:Ji,replacePlainDocument:ii}),G=E.trimStart();if(p===`normal`&&G.startsWith(`/`)){let e=Cv(G.slice(1).trim()).split(/\s+/)[0]?.toLowerCase();if(!Ss(e,e=>tm(In,{name:e.name,source:`openchamber`})))return;if(Bn&&(e===`undo`||e===`redo`)&&bv(G,p)&&ee(),e===`undo`&&Bn){try{await J.getState().handleSlashUndo(Bn),r?.()}catch(e){Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`new`){await Ln?.shortcut(`new`);return}if(e===`redo`&&Bn){try{await J.getState().handleSlashRedo(Bn),r?.()}catch(e){Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`fork`&&Bn){await Tv({command:`fork`,consumeCommandText:ee,forkSession:()=>J.getState().forkCurrentSession(Bn),waitForConnection:wr,getDirectoryForSession:()=>J.getState().getDirectoryForSession(Bn),summarizeSession:async()=>void 0,onCompactError:()=>void 0,onForkError:e=>{Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.messageSendFailed`))}});return}if(e===`timeline`&&Bn&&Qi.timeline){Qr(!0);return}if(e===`compact`&&Bn){Tv({command:`compact`,consumeCommandText:ee,forkSession:async()=>void 0,waitForConnection:wr,getDirectoryForSession:()=>In.directory??``,summarizeSession:e=>qn?In.backend.compact({operation:`compact`,surfaceID:In.surfaceID,transportIdentity:In.transportIdentity,runtimeGeneration:In.runtimeGeneration,sessionID:Bn,directory:e,draftKey:qn,deliveryTarget:In.deliveryTarget,providerID:h,modelID:g,agent:y,variant:x}):Promise.reject(Error(`chat-input-surface-incomplete`)),onCompactError:()=>{Ii.error(l(`chat.chatInput.toast.compactFailed`))},onForkError:()=>void 0});return}if(e===`summary`&&Bn){try{await wr();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 yi(`session.summary.visible`,{topic_line:t}),a=await yi(`session.summary.instructions`,{topic_block:n});await Yn(i,h,g,y,[],N,[{text:a,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.summaryFailed`))}return}if(e===`workspace-review`&&(Bn||Un)){try{await wr();let e=await yi(`session.review.visible`),t=await yi(`session.review.instructions`);await Yn(e,h,g,y,[],N,[{text:t,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.reviewFailed`))}return}if(e===`handoff-review`&&Bn&&!Lr&&!d()){ir(!0);return}if(e===`plan-feature`&&(Bn||Un)){try{await wr();let e=await yi(`session.plan.visible`),t=await yi(`session.plan.instructions`);await Yn(e,h,g,y,[],N,[{text:t,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.planFeatureFailed`))}return}if(e===`goal`&&(Bn||Un)){A(),kt.getState().setArmed(!0);let e=vv(G,p)??``;ii(e),Ji.current=e,ct(-1),e||Zr(!1);return}if(e===`craft-goal`&&(Bn||Un)){try{await wr();let e=G.replace(/^\/\u2003?craft-goal\b/i,``).trim(),t=await yi(`session.craftGoal.visible`,{idea_block:e?`\n\nHere is my initial idea:\n${e}`:``}),n=await yi(`session.craftGoal.instructions`);await Yn(t,h,g,y,[],N,[{text:n,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.craftGoalFailed`))}return}if(e===`catch-up`&&(Bn||Un)){try{await wr();let e=await yi(`session.catchup.visible`),t=await yi(`session.catchup.instructions`);await Yn(e,h,g,y,[],N,[{text:t,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.catchUpFailed`))}return}if(e===`debug`&&(Bn||Un)){try{await wr();let e=await yi(`session.debug.visible`),t=await yi(`session.debug.instructions`);await Yn(e,h,g,y,[],N,[{text:t,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.debugFailed`))}return}if(e===`weigh`&&(Bn||Un)){try{await wr();let e=await yi(`session.weigh.visible`),t=await yi(`session.weigh.instructions`);await Yn(e,h,g,y,[],N,[{text:t,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.weighFailed`))}return}if(e===`explore`&&(Bn||Un)){try{await wr();let e=await yi(`session.explore.visible`),t=await yi(`session.explore.instructions`);await Yn(e,h,g,y,[],N,[{text:t,synthetic:!0}],x,p,T),r?.()}catch(e){await W(),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.exploreFailed`))}return}}let te=Bn&&J.getState().getDirectoryForSession(Bn)||Kn;if(Gn||Bn&&!Xy(Bn,te)){let e=await mn().catch(()=>null);e&&P.push({text:Ri(e),synthetic:!0})}try{let e=ga.getState().expandText;E=await e(E);for(let t of P)t.synthetic||(t.text=await e(t.text))}catch(e){console.warn(`[ChatInput] Failed to expand snippets, sending original text:`,e)}R=!0;let ne=Yn(E,h,g,y,j,N,P.length>0?P:void 0,x,p,T);F=!0,ne.finally(()=>{ds(),L&&J.getState().endMessageEditCommit(L.sessionId,L.messageId)}),O&&ne.then(()=>{M(O)}).catch(()=>{En.getState().clearEstablishing(O)}),typeof window>`u`?r?.():window.requestAnimationFrame(()=>{r?.()}),ne.then(()=>{yo&&bo(null),xo&&So(null)}).catch(e=>{I&&nn(I),W().then(e=>{e||Ii.error(l(`chat.chatInput.toast.messageSendFailed`))});let t=e instanceof Error?e.message:typeof e==`string`?e:String(e??``),n=t.toLowerCase();console.error(`Message send failed:`,t||e);let r=n.includes(`timeout`)||n.includes(`timed out`)||n.includes(`may still be processing`)||n.includes(`being processed`)||n.includes(`failed to fetch`)||n.includes(`networkerror`)||n.includes(`network error`)||n.includes(`gateway timeout`)||n===`failed to send message`;if(n.includes(`payload too large`)||n.includes(`413`)||n.includes(`entity too large`)){Ii.error(l(`chat.chatInput.toast.attachmentsTooLarge`));return}if(r){m.length>0&&Ii.error(l(`chat.chatInput.toast.sendAttachmentsFailed`));return}Ii.error(t||l(`chat.chatInput.toast.messageSendFailed`))}),Lr||xi.current?.focus()}finally{R||(I&&nn(I),L&&J.getState().endMessageEditCommit(L.sessionId,L.messageId)),F||(P&&f&&mi(f),ds(),O&&M(O))}};rs.current=Ns;let Fs=Z.useCallback(()=>{if(gs()||fs())return;let e=ns(),t=p===`normal`&&e.hasContent&&Bn&&(es||Go),n=t&&$d(To.mode)&&an(In.deliveryTarget?.kind,To.mode);Co===`queue`&&n?vs():Co===`steer`&&t||Co===`queue`&&t&&!n?rs.current(t?{delivery:`steer`}:void 0):rs.current()},[p,ns,Bn,es,Go,Co,vs,To.mode,In.deliveryTarget?.kind,hs]),Rs=Z.useCallback(e=>{if(fs())return;let t=(xi.current?.value??Ji.current).trim(),n=t?`${e}\n${t}`:e;rs.current({presetText:n})},[]),Bs=Z.useCallback(e=>{let t=hb(Xi().text,e);vi(t),xi.current&&(xi.current.value=t),setTimeout(()=>{xi.current?.focus()},0)},[vi]),Vs=Z.useCallback(e=>{if(fs())return;let t=hb(xi.current?.value??Ji.current,e);rs.current({presetText:t})},[]),Us=Rn.pendingPreset,Ws=Rn.consumePendingPreset;Z.useEffect(()=>{if(Us==null)return;let e=Ws();e&&Rs(e)},[Us,Ws,Rs]);let Gs=Z.useCallback(()=>{ii(``),ct(-1),zn.length>0&&Rn.clearAttachments(),wo&&No(wo),j(!1),I(!1),H(!1),E(!1),p===`shell`&&m(`normal`)},[zn.length,Rn,No,wo,ii,p]),Ks=e=>{if(!In.active||Wh(e))return;if(oa&&po(e,oa)&&!Ur){let t=xi.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),Gs();return}}if(p===`shell`&&e.key===`Escape`){e.preventDefault(),m(`normal`);return}if(p===`shell`&&e.key===`Backspace`&&ni.length===0){e.preventDefault(),m(`normal`);return}if((e.key===`Backspace`||e.key===`Delete`)&&!e.metaKey&&!e.ctrlKey){let t=xi.current,n=t?.selectionStart??ni.length,r=t?.selectionEnd??ni.length,i=li({key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(i){let t=Yy($r.getDocument().text,i.start);e.preventDefault(),vi(t.text),requestAnimationFrame(()=>{xi.current?.setSelectionRange(t.caret,t.caret),nc()}),rc(t.text,t.caret);return}let a=Ee(ni,zn.filter(Oe).map(e=>e.filename),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(a){let t=new Set(a.removedFilenames.map(e=>e.toLowerCase())),n=Yy(a.text,a.caret);e.preventDefault(),vi(n.text);for(let e of zn)t.has(e.filename.toLowerCase())&&Rn.removeAttachment(e.id);requestAnimationFrame(()=>{xi.current&&(xi.current.selectionStart=n.caret,xi.current.selectionEnd=n.caret),nc()}),rc(n.text,n.caret);return}let o=I_(ni,Za.keys(),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(o){let t=Yy(o.text,o.caret);e.preventDefault(),vi(t.text),requestAnimationFrame(()=>{xi.current&&(xi.current.selectionStart=t.caret,xi.current.selectionEnd=t.caret),nc()}),rc(t.text,t.caret);return}if(n===r&&!e.altKey){let t=e.key===`Backspace`?n-1:n;if(t>=0&&t<ni.length){let n=Re(ni,zn.map(e=>e.filename)).find(e=>t>=e.start&&t<e.end);if(n){let t=G(ni.slice(n.start+1,n.end-1)).trim(),r=zn.find(e=>e.filename.toLowerCase()===t.toLowerCase()),i=ni[n.end]===` `?n.end+1:n.end,a=`${ni.slice(0,n.start)}${ni.slice(i)}`;e.preventDefault(),vi(a),r&&Rn.removeAttachment(r.id),requestAnimationFrame(()=>{xi.current&&(xi.current.selectionStart=n.start,xi.current.selectionEnd=n.start),nc()}),rc(a,n.start);return}let r=t;for(;r>0&&!/\s/.test(ni[r-1]);)--r;let i=t+1;for(;i<ni.length&&!/\s/.test(ni[i]);)i+=1;let a=ni.slice(r,i),o=a.slice(1);if(Hy.test(a)&&!Wa.current.has(o.toLowerCase())&&bi(o)){let t=ni[i]===` `?i+1:i,n=`${ni.slice(0,r)}${ni.slice(t)}`;e.preventDefault(),vi(n),requestAnimationFrame(()=>{xi.current&&(xi.current.selectionStart=r,xi.current.selectionEnd=r),nc()}),rc(n,r);return}}}}let t=(e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.metaKey&&!e.ctrlKey;if(k&&Wi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Wi.current.handleKeyDown(e.key);return}if(P&&Gi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Gi.current.handleKeyDown(e.key);return}if(V&&Ki.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Ki.current.handleKeyDown(e.key);return}if(T&&Vi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Vi.current.handleKeyDown(e.key);return}if(Ma&&e.key===`Escape`){e.preventDefault(),Zr(!1);return}let n=aa&&!aa.includes(`shift`)?$a(`shift+${aa}`):``,r=n&&po(e,n)?-1:+!!po(e,aa);if(r!==0&&!k&&!P&&!V&&!T){e.preventDefault(),e.stopPropagation(),Ln?.shortcut(`cycle`,r),requestAnimationFrame(()=>{xi.current?.focus({preventScroll:!0})});return}let i=k||P||V||T,a=xi.current?.selectionStart===0&&xi.current?.selectionEnd===0,o=xi.current?.selectionStart===ni.length&&xi.current?.selectionEnd===ni.length,s=!i&&(ni.length===0||a),c=!i&&(ni.length===0||o);if(p===`normal`&&!i&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=xi.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&n>=0){let t=(t,n,r)=>{e.preventDefault(),vi(t),requestAnimationFrame(()=>{let e=xi.current;e&&(e.selectionStart=n,e.selectionEnd=r),nc()}),rc(t,r)},i={"`":["`","`"],"*":[`*`,`*`],_:[`_`,`_`],"~":[`~`,`~`],"(":[`(`,`)`],"[":[`[`,`]`],"{":[`{`,`}`],'"':[`"`,`"`],"'":[`'`,`'`]};if(r>n&&i[e.key]){let[a,o]=i[e.key],s=ni.slice(n,r);t(`${ni.slice(0,n)}${a}${s}${o}${ni.slice(r)}`,n+a.length,r+a.length);return}if(e.key==="`"&&n===r){let e=ni.slice(0,n);if(/(^|\n)``$/.test(e)){let n=`${e}\`\n\n\`\`\`${ni.slice(r)}`,i=e.length+2;t(n,i,i);return}}}}if(e.key===`ArrowUp`&&!e.metaKey&&!e.ctrlKey&&s&&Ho.length>0){if(e.preventDefault(),st===-1)ct(0),ui({text:Ho[0],references:[]});else if(st<Ho.length-1){let e=st+1;ct(e),ui({text:Ho[e],references:[]})}requestAnimationFrame(()=>{xi.current?.setSelectionRange(0,0)});return}if(e.key===`ArrowDown`&&!e.metaKey&&!e.ctrlKey&&c&&st>=0){if(e.preventDefault(),st===0)ct(-1),di();else{let e=st-1;ct(e),ui({text:Ho[e],references:[]})}return}if(e.key===`Enter`&&!e.shiftKey){if(e.preventDefault(),gs()||fs())return;let t=e.ctrlKey||e.metaKey,n=p===`normal`&&Yo&&Bn&&(es||Go),r=n&&$d(To.mode)&&an(In.deliveryTarget?.kind,To.mode);Co===`queue`?t||!n?Ns():r?vs():Ns({delivery:`steer`}):t||!n?Ns():Ns({delivery:`steer`})}},qs=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}},[]),Js=Z.useCallback(()=>{if(!Ma){fo(null);return}if(!k&&!P&&!V&&!T){fo(null);return}let e=xi.current,t=Di.current;if(!e||!t)return;let n=e.selectionStart??ni.length,r=qs(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=T?520:k||V?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));fo({top:u===`below`?o+22:o-6,left:f,place:u,maxHeight:p})},[Ma,qs,ni.length,k,T,V,P]);Z.useLayoutEffect(()=>{Js()},[Js,ni,k,P,V,T,Ma]),Z.useEffect(()=>{if(!Ma)return;let e=()=>Js();return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[Ma,Js]);let Ys=Z.useCallback(()=>{mo.current&&=(clearTimeout(mo.current),null),ha(!0),mo.current=setTimeout(()=>{ha(!1),mo.current=null},1800)},[]),Xs=Z.useCallback(()=>{if(Rn.abortPrompt.clear(),Ys(),In.kind===`secondary`){Ln?.shortcut(`abort`);return}Zn()},[Zn,Ln,Ys,In.kind,Rn]),Zs=Z.useCallback((e=1)=>{if(Fr)return;let t=Wn(jr,In.selection.value.agent??mr,e);if(!t||!In.selection.change)return;let n=on({providerID:In.selection.value.providerID??``,modelID:In.selection.value.modelID??``,agent:In.selection.value.agent??null},t,jr,Nr);In.selection.change({...In.selection.value,...n,agent:n.agent??void 0}),In.kind===`primary`&&(c.getState().addRecentAgent(t),In.sessionID&&xt.getState().saveSessionAgentSelection(In.sessionID,t))},[jr,mr,Nr,Fr,In.kind,In.selection,In.sessionID]);lt.current=Zs;let Qs=Z.useRef(null),[$s,ec]=Z.useState(null),tc=Z.useCallback(e=>{ec(t=>t===e?t:e)},[]),nc=Z.useCallback(e=>{let t=xi.current;if(!t)return;let n=t.scrollTop;if(Ra){t.style.height=`100%`,t.style.maxHeight=`none`,t.style.overflowY=`auto`,oe(null),t.scrollTop!==n&&(t.scrollTop=n);return}if(Lr&&!ue){let e=t.ownerDocument?.defaultView,n=e?e.getComputedStyle(t):null,r=n?parseFloat(n.lineHeight):NaN,i=Number.isNaN(r)?20:r;t.style.height=`${i}px`,t.style.maxHeight=`${i}px`,t.style.overflow=`hidden`,t.style.overflowX=`hidden`,t.style.overflowY=`hidden`,t.scrollTop!==0&&(t.scrollTop=0),t.scrollLeft!==0&&(t.scrollLeft=0),oe(e=>e&&e.height===i&&e.maxHeight===i?e:{height:i,maxHeight:i});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=Fy({scrollHeight:t.scrollHeight||t.offsetHeight,dictationHeight:Qs.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),oe(e=>e&&e.height===u.height&&e.maxHeight===u.maxHeight?e:{height:u.height,maxHeight:u.maxHeight})},[Ra,Lr,ue]);Z.useLayoutEffect(()=>{let e=ni.length<Ti.current;Ti.current=ni.length,nc({allowShrink:e})},[nc,ni,Lr,ue]),Z.useLayoutEffect(()=>{Qs.current=$s,nc({allowShrink:$s===null})},[nc,$s]);let rc=Z.useCallback((e,t,n=`manual`,r)=>{if(p===`shell`){j(!1),E(!1),I(!1),H(!1);return}if(e.startsWith(`/`)){let n=e.indexOf(` `),r=e.indexOf(`
|
|
6535
6535
|
`),i=Math.min(n===-1?e.length:n,r===-1?e.length:r);if(t<=i&&n===-1){let t=Cv(e.substring(1,i));N(t),j(!0),E(!1),I(!1),H(!1);return}}j(!1);let i=e.substring(0,t),a=i.lastIndexOf(`/`);if(a!==-1){let e=a>0?i[a-1]:null,t=Cv(i.substring(a+1)),n=t.includes(` `)||t.includes(`
|
|
6536
6536
|
`);if((!e||/\s/.test(e))&&!n){z(t),I(!0),E(!1);return}}I(!1),z(``);let o=i.lastIndexOf(`#`);if(o!==-1){let e=o>0?i[o-1]:null,t=i.substring(o+1);if((!e||/\s/.test(e))&&!t.includes(` `)&&!t.includes(`
|
|
6537
|
-
`)){ne(t),H(!0),E(!1);return}}H(!1);let s=fr({value:e,cursorPosition:t,inputSource:n,insertedText:r});s===null?E(!1):(O(s),E(!0))},[p,N,O,j,E,I,H,z,ne]),tc=Z.useCallback((e,t,n,r=`manual`,i)=>{let a=e,o=t,s=n;if(p===`normal`&&!vi.current&&Ja.size>0&&e.includes(`/`)){let r=Sv(e,Ja,n);r&&(a=r.text,o=t+(r.caret-n),s=r.caret)}let c=ni(a,o,s),l=Ki(),u=c.requiresTextCorrection||o!==c.start||s!==c.end||a!==e;return requestAnimationFrame(()=>{let e=gi.current;e&&Zp(u,vi.current)&&(e.value=l.text,e.setSelectionRange(c.start,c.end)),$s()}),ec(l.text,c.end,r,i),{document:l,selection:c}},[$s,ni,Ki,p,Ja,ec]),nc=Z.useCallback((e,t=`manual`)=>{if(!e)return;let n=gi.current;if(!n){let n=Qr+e;tc(n,n.length,n.length,t,e);return}let r=n.selectionStart??Qr.length,i=n.selectionEnd??Qr.length,a=`${Qr.substring(0,r)}${e}${Qr.substring(i)}`,o=r+e.length;tc(a,o,o,t,e)},[tc,Qr]),rc=q((e,t)=>{let n=new Set(we(In.map(e=>e.filename),e,t));if(n.size!==0)for(let e of In)n.has(e.filename)&&Fn.removeAttachment(e.id)}),ic=Z.useCallback(e=>{Fn.removeAttachment(e.id)},[Fn]),ac=Z.useCallback(()=>{Ti.current=!1,Mi.current=[],Di.current&&=(clearTimeout(Di.current),null)},[]),oc=Z.useCallback(()=>{Di.current&&clearTimeout(Di.current),Di.current=setTimeout(()=>{ac()},700)},[ac]),sc=Z.useCallback(()=>{ki.current=!1,ji.current&&=(clearTimeout(ji.current),null)},[]),cc=Z.useCallback(()=>{ki.current=!0,ji.current&&clearTimeout(ji.current),ji.current=setTimeout(()=>{ki.current=!1,ji.current=null},700)},[]),lc=Z.useCallback(e=>{!d()||!Ti.current||e.nativeEvent?.inputType===`insertFromDrop`&&(e.preventDefault(),ac())},[ac]),uc=e=>{if(Rr)return;let t=e.nativeEvent;if(d()&&Ti.current){let n=Mi.current;if(t?.inputType===`insertFromDrop`||n.some(t=>t.length>0&&e.target.value.includes(t))){ac();return}}let n=e.target.value;rc(Wi.current,n);let r=e.target.selectionStart??n.length,i=t?.inputType?.startsWith(`insertFromPaste`)?qy(Wi.current,n):``,a=i.includes(`@`)||ki.current;ki.current&&sc();let o=a?`paste`:`manual`;if(p===`normal`&&n.startsWith(`!`)){let e=n.slice(1),t=Math.max(0,r-1);m(`shell`),$r(e),$s(),j(!1),I(!1),E(!1),requestAnimationFrame(()=>{gi.current&&(gi.current.selectionStart=t,gi.current.selectionEnd=t)});return}tc(n,r,e.target.selectionEnd??r,o,i)};Z.useEffect(()=>()=>{ac(),sc()},[ac,sc]);let dc=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=gi.current,i=r?.selectionStart??Qr.length,a=r?.selectionEnd??Qr.length,o=ks(n,Qr.slice(0,i),Qr.slice(a)),s=`${Qr.slice(0,i)}${o}${Qr.slice(a)}`;rc(Qr,s),Ji(s,t)},[Qr,Ji,rc]),fc=Z.useCallback(async e=>{let t=tb(e.clipboardData);if(t.length>0&&(Ln||zn)){e.preventDefault(),dc(t);return}if(p===`normal`&&(Ln||zn)){let t=gi.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&r>n){let t=e.clipboardData.getData(`text`).trim(),i=Qr.slice(n,r);if(Wy.test(t)&&!/\s/.test(t)&&i.trim().length>0&&!i.includes(`](`)){e.preventDefault();let a=`${Qr.slice(0,n)}[${i}](${t})${Qr.slice(r)}`,o=n+1+i.length+2+t.length+1;mi(a),requestAnimationFrame(()=>{let e=gi.current;e&&(e.selectionStart=o,e.selectionEnd=o),$s()}),ec(a,o,Jy(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(p===`normal`&&uy(Ki(),a)){e.preventDefault();let t=Ki().text,n=gi.current,r=n?.selectionStart??Qr.length,i=n?.selectionEnd??Qr.length,o=dy(a,Qr,Ki().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>l(`chat.chatInput.pastedTextReference`,{index:e,count:t}),ly(Ki())),s=ii(r,i,{id:o.id,kind:`paste`,text:o.text,characterCount:o.characterCount,index:o.index,display:o.token},{inlineBoundaries:!0,padDocumentEdges:!0}),c=zs(s.document.text,s.caret);gi.current&&(gi.current.value=s.document.text),requestAnimationFrame(()=>{gi.current?.setSelectionRange(c,c),$s()}),ec(s.document.text,c),rc(t,s.document.text);return}a.includes(`@`)&&cc();return}if(!Ln&&!zn){a.includes(`@`)&&cc();return}e.preventDefault();let o=je(i,[...In.map(e=>e.filename),...Gi.current]),s=Be(o),c=Ki().text,u=gi.current,d=u?.selectionStart??Qr.length,f=u?.selectionEnd??Qr.length,m=p===`normal`&&uy(Ki(),a)?dy(a,Qr,Ki().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>l(`chat.chatInput.pastedTextReference`,{index:e,count:t}),ly(Ki())):null,h=a?`${a}${/\s$/.test(a)?``:` `}${s}`:s,g=ks(h,Qr.slice(0,d),Qr.slice(f));if(m){let e=ii(d,f,{id:m.id,kind:`paste`,text:m.text,characterCount:m.characterCount,index:m.index,display:m.token},{inlineBoundaries:!0,padDocumentEdges:!0}),t=zs(e.document.text,e.caret),n=`${e.document.text.slice(0,t)}${s}${e.document.text.slice(t)}`;tc(n,t+s.length,t+s.length,Jy(n),s),rc(c,n)}else nc(g,Jy(g)),rc(c,`${Qr.slice(0,d)}${g}${Qr.slice(f)}`);for(let e=0;e<i.length;e+=1){let t=o[e],n=Ky(i[e],t);Gi.current.add(t);try{await Fn.addAttachment(n)}catch(e){console.error(`Clipboard image attach failed`,e),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.clipboardAttachFailed`))}finally{Gi.current.delete(t)}}},[Fn,dc,In,$s,Ln,Ki,p,ii,cc,Qr,zn,nc,l,ec,tc,mi,rc]),pc=Z.useCallback((e,t)=>{let n=e.currentTarget,r=n.selectionStart??0,i=n.selectionEnd??r;if(i<=r)return;let a=F_(r,i,[...Re(Qr,In.filter(Oe).map(e=>e.filename)),...P_(Qr,qa.keys()),...Ki().references]),o=a?.start??r,s=a?.end??i,c=Qr.slice(o,s),l=U(c);if(!(l===c&&!a))if(e.preventDefault(),e.clipboardData.setData(`text/plain`,l),t===`cut`){let e=`${Qr.slice(0,o)}${Qr.slice(s)}`;tc(e,o,o),requestAnimationFrame(()=>{gi.current?.setSelectionRange(o,o),$s()})}else a&&(a.start!==r||a.end!==i)&&requestAnimationFrame(()=>{gi.current?.setSelectionRange(o,s)})},[$s,In,qa,tc,Ki,Qr]),mc=Z.useCallback(e=>{pc(e,`copy`)},[pc]),hc=Z.useCallback(e=>{pc(e,`cut`)},[pc]),gc=e=>{let t=gi.current,n=Math.min(t&&document.activeElement===t?t.selectionStart??bi.current:bi.current,Qr.length),r=Qr.substring(0,n).lastIndexOf(`@`),i=e.relativePath&&e.relativePath.trim().length>0?e.relativePath.trim():Dc(e.path)||e.name,a=e.isDirectory?[i]:[],o=Ls(Qr,r===-1?n:r,n,`@${i}`);Ji(o.text,[i],a),requestAnimationFrame(()=>{gi.current&&(gi.current.selectionStart=o.caret,gi.current.selectionEnd=o.caret),$s(),ec(o.text,o.caret)}),E(!1),O(``),gi.current?.focus()},_c=e=>{let t=gi.current,n=Math.min(t&&document.activeElement===t?t.selectionStart??bi.current:bi.current,Qr.length),r=Qr.substring(0,n).lastIndexOf(`@`),i=Ls(Qr,r===-1?n:r,n,`@${e}`);mi(i.text,t=>Ps(t,{kind:`agent`,value:e,path:e,label:e,range:{start:i.start,end:i.end}})),requestAnimationFrame(()=>{gi.current&&(gi.current.selectionStart=i.caret,gi.current.selectionEnd=i.caret),$s(),ec(i.text,i.caret)}),E(!1),O(``),gi.current?.focus()},vc=q(e=>{zi.current||(zi.current=!0,(async()=>{try{let t=J.getState().getAuthoritativeDirectoryForSession(e.id);if(!t){Ii.error(l(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}if(await Et(e.id,{directory:t}),!ei(e.id,t)){Ii.error(l(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}Sr([{type:`session`,sessionId:e.id}],t).catch(()=>void 0);let n=Ki(),r=gi.current?.selectionStart??n.text.length,i=n.text.substring(0,r).lastIndexOf(`@`),a=ci().get(e.id)?.title||e.title||e.id,o=i===-1?r:i,s={id:`session:${e.id}:${L()}`,kind:`session`,sessionId:e.id,display:F({trigger:`@`,icon:`chat-thread`,label:a})},c=ii(o,r,s,{inlineBoundaries:!0,padDocumentEdges:!0}),u=zs(c.document.text,c.caret);requestAnimationFrame(()=>{gi.current&&(gi.current.selectionStart=u,gi.current.selectionEnd=u),$s(),ec(c.document.text,u)}),E(!1),O(``),gi.current?.focus()}catch{Ii.error(l(`chat.chatInput.toast.sessionReferenceLoadFailed`))}finally{zi.current=!1}})())}),yc=q(e=>{let t=Ki(),n=gi.current?.selectionStart??t.text.length,r=ys(t.text,n);if(!r)return!1;let i=ii(r.start,r.end,e,{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=i.document.references.some(t=>t.id===e.id),o=zs(i.document.text,i.caret);return requestAnimationFrame(()=>{gi.current&&(gi.current.selectionStart=o,gi.current.selectionEnd=o),$s(),ec(i.document.text,o),a&&(j(!1),I(!1))}),gi.current?.focus(),a}),bc=e=>{yc({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&z(``)},xc=(e,t)=>{let n=gi.current?.selectionStart??Qr.length,r=Qr.substring(0,n).lastIndexOf(`#`),i=r===-1?n:r,a=`${Qr.substring(0,i)}#${t} ${Qr.substring(n)}`;mi(a);let o=i+t.length+2;requestAnimationFrame(()=>{gi.current&&(gi.current.selectionStart=o,gi.current.selectionEnd=o),$s(),ec(a,o)}),H(!1),ne(``),gi.current?.focus()},Q=(e,t=!1)=>{if(!tm(Mn,e))return;let n=`/${e.name}`;if(!t&&e.isSkill){yc({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&N(``);return}if(!t&&e.source===`opencode`&&!e.isSkill&&e.isBuiltIn!==!0&&yc({id:`command:${e.name}:${L()}`,kind:`command`,commandName:e.name,reference:e.reference??e.name,display:F({trigger:`/`,icon:`command`,label:e.name})})){N(``);return}let r=e.isSkill?` ${n} `:`${n} `,i=Sv(r,new Set([...Ja,e.name.toLowerCase()]),r.length);$r(i?.text??r);let a=gi.current;if(a&&(a._commandMetadata=e),j(!1),N(``),t){Ts({presetText:n});return}let o=()=>{if(gi.current){try{gi.current.focus({preventScroll:!0})}catch{gi.current.focus()}gi.current.setSelectionRange(gi.current.value.length,gi.current.value.length)}};requestAnimationFrame(()=>{o(),requestAnimationFrame(o)}),setTimeout(o,60)};Z.useEffect(()=>{Ln&&gi.current&&!Nr&&gi.current.focus()},[Ln,Nr]),Z.useEffect(()=>{Nr||ce(null)},[Nr]);let Cc=Fn.abortPrompt.sessionID,wc=Fn.abortPrompt.clear;Z.useEffect(()=>{Cc&&Cc!==Ln&&wc()},[Ln,Cc,wc]),Z.useEffect(()=>{Pi.current=!!(Ln||zn)},[Ln,zn]);let Tc=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 tv(e).length>0},[]),Ec=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)},[]),Dc=Z.useCallback(e=>{let t=e.replace(/\\/g,`/`).trim(),n=(aa||``).replace(/\\/g,`/`).replace(/\/+$/,``);if(!n||t===n)return t;let r=`${n}/`;return t.startsWith(r)?t.slice(r.length):t},[aa]),Oc=e=>{if(!Tc(e.dataTransfer))return;e.preventDefault(),e.stopPropagation(),Ci.current++;let t=e.dataTransfer.types?.includes(`application/x-openchamber-file-path`)??!1;t!==y&&w(t),(Ln||zn)&&!h&&g(!0)},kc=e=>{Tc(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,(Ln||zn)&&!h&&g(!0))},Ac=e=>{e.preventDefault(),e.stopPropagation(),Ci.current--,Ci.current<=0&&(Ci.current=0,g(!1),w(!1),ac())},jc=()=>{Ci.current=0,g(!1),w(!1),ac()},Mc=async e=>{if(Ci.current=0,!Tc(e.dataTransfer)){ac();return}if(e.preventDefault(),e.stopPropagation(),g(!1),!Ln&&!zn)return;let t=e.dataTransfer.getData(`application/x-openchamber-file-path`);if(t&&t!==`.`){let e=`@${t}`,n=gi.current,r=Wi.current;if(n){let t=n.selectionStart??bi.current,i=n.selectionEnd??t,a=Ls(r,t,i,e);mi(a.text),requestAnimationFrame(()=>{n.selectionStart=a.caret,n.selectionEnd=a.caret,bi.current=a.caret,n.focus()})}else{let t=Ls(r,r.length,r.length,e);mi(t.text)}ac();return}let n=tb(e.dataTransfer);if(n.length>0){d()&&(Mi.current=n),dc(n),d()||ac();return}let r=Ec(e.dataTransfer);if(r.length>0){let e=Be(r.map(e=>e.name)),t=ks(e,Wi.current.slice(0,gi.current?.selectionStart??Wi.current.length),Wi.current.slice(gi.current?.selectionEnd??Wi.current.length));nc(t);for(let e of r)try{await Fn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.attachFileFailed`))}}ac()},Nc=e=>{Tc(e.dataTransfer)&&(e.preventDefault(),d()&&(Ti.current=!0,oc()))},Ic=Z.useRef(null),Lc=Z.useRef(null),Rc=q((e=!0)=>{$e.current=0;let t=()=>{let t=Yp(gi);if(!t||(Xp(gi),!e))return;let n=t.value.length;try{t.setSelectionRange(n,n)}catch{}};t(),window.requestAnimationFrame(t)}),zc=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=ks(e,Wi.current.slice(0,gi.current?.selectionStart??Wi.current.length),Wi.current.slice(gi.current?.selectionEnd??Wi.current.length));nc(n)}for(let e of t)try{await Fn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.attachFileFailed`))}},[Fn,nc,l]),Bc=Z.useCallback(async()=>{try{let e=await Zi?.pickFiles?.(),t=Array.isArray(e?.files)?e.files:[],n=Array.isArray(e?.skipped)?e.skipped:[];if(n.length>0){let e=n.map(e=>`${e?.name||`file`}: ${e?.reason||`skipped`}`).join(`
|
|
6538
|
-
`);Ii.error(l(`chat.chatInput.toast.someFilesSkipped`,{summary:e}))}let r=t.map(e=>{if(!e?.dataUrl)return null;try{let[t,n]=e.dataUrl.split(`,`),r=e.mimeType||t?.match(/data:(.*);base64/)?.[1]||`application/octet-stream`;if(!n)return null;let i=atob(n),a=new Uint8Array(i.length);for(let e=0;e<i.length;e++)a[e]=i.charCodeAt(e);let o=new Blob([a],{type:r});return new File([o],e.name||`file`,{type:r})}catch(e){return console.error(`Failed to decode VS Code picked file`,e),null}}).filter(Boolean);r.length>0&&(Rc(!1),await zc(r),Rc())}catch(e){console.error(`VS Code file pick failed`,e),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.vscodePickFailed`))}},[zc,Rc,l,Zi]),Vc=Z.useCallback(()=>{if(d()){Bc();return}Ic.current?.click()},[Bc]),Hc=Z.useCallback(()=>{if(d()){Bc();return}Lc.current?.click()},[Bc]),Uc=Z.useCallback(async()=>{if(!Pc()){Hc();return}try{let e=await Fc(20);if(e===null){Hc();return}e.length>0&&(Rc(!1),await zc(e),Rc())}catch(e){console.error(`Native photo pick failed`,e),Ii.error(l(`chat.chatInput.toast.attachFileFailed`))}},[zc,Rc,Hc,l]),Wc=Z.useCallback(async e=>{let t=e.target.files;!t||t.length===0||(Rc(!1),await zc(t),e.target.value=``,Rc())},[zc,Rc]),Gc=`gap-x-1.5 gap-y-0`,Kc=d(),qc=Mn.kind===`primary`&&Bn&&!Kc,Jc=Z.useMemo(()=>(Ft?.selectedProjectId?Jn.find(e=>e.id===Ft.selectedProjectId)??null:null)||(Yn?Jn.find(e=>e.id===Yn)??null:null)||(Jn[0]??null),[Yn,Ft?.selectedProjectId,Jn]),Yc=Z.useMemo(()=>nb(Jc?.path??null),[Jc?.path]),Xc=Jc?rb(Jc):null,Zc=Is(Yc),Qc=Es(e=>Yc?e.directories.get(Yc)?.lastBranchesFetch??0:0),$c=Hs(Yc),el=!!Zc?.all,tl=Es(e=>e.fetchBranches),[nl,rl]=Z.useState(!1);Z.useEffect(()=>{!qc||!Yc||!Xi||$c!==null||la(Yc,Xi,{silent:!0})},[la,Xi,$c,Yc,qc]),Z.useEffect(()=>{if(!qc||!Yc||!Jc||!Xi||$c!==!0){rl(!1);return}let e=!Qc||Date.now()-Qc>3e4;if(el&&!e){rl(!1);return}let t=!1;return rl(!el),tl(Yc,Xi).finally(()=>{t||rl(!1)}),()=>{t=!0}},[tl,Xi,Jc,Qc,el,$c,Yc,qc]);let il=Os(Yc),al=Zc?.current?.trim()||il?.trim()||``,ol=Z.useMemo(()=>{if(!Jc)return null;let e=nb(Jc.path);return!e||!al?null:{value:e,label:al}},[Jc,al]),sl=Z.useMemo(()=>{if(!Jc)return[];let e=Yc?Zt.get(Yc)??Zt.get(Jc.path)??[]:[];return Pr({projectRoot:nb(Jc.path)??``,rootBranch:al,worktrees:e,pendingBootstrapDirectory:Ft?.bootstrapPendingDirectory??null}).filter(e=>e.kind===`worktree`)},[Zt,Ft?.bootstrapPendingDirectory,Jc,al,Yc]),cl=Z.useMemo(()=>nb(Ft?.bootstrapPendingDirectory??null)??nb(Ft?.directoryOverride??null)??Yc,[Ft?.bootstrapPendingDirectory,Ft?.directoryOverride,Yc]),ll=Z.useMemo(()=>{let e=nb(Ft?.bootstrapPendingDirectory??null);return!!(Ft?.preserveDirectoryOverride||Ft?.pendingWorktreeRequestId||e&&e===cl)},[Ft?.bootstrapPendingDirectory,Ft?.pendingWorktreeRequestId,Ft?.preserveDirectoryOverride,cl]),ul=Z.useMemo(()=>{let e=[];return ol&&e.push(ol),e.push(...sl),!cl||e.some(e=>e.value===cl)||!ll?e:[...e,{value:cl,label:ra(cl)}]},[ol,cl,ll,sl]),dl=Z.useMemo(()=>d_({selectedDirectory:cl,projectRootOption:ol,worktreeOptions:sl}),[ol,cl,sl]),fl=Ph()===`mini-chat`,pl=Z.useMemo(()=>fl||oa!==!0||!sa||sa.isClean?!1:wh(sa.files),[sa,oa,fl]),ml=Z.useMemo(()=>!cl||ol?.value===cl||sl.some(e=>e.value===cl),[ol?.value,cl,sl]);Z.useEffect(()=>{Ft?.open&&(!Ft.preserveDirectoryOverride&&!Ft.bootstrapPendingDirectory||!cl||!ml||(Ft.preserveDirectoryOverride&&J.getState().setDraftPreserveDirectoryOverride(!1),Ft.bootstrapPendingDirectory&&J.getState().setDraftBootstrapPendingDirectory(null)))},[Ft?.bootstrapPendingDirectory,Ft?.open,Ft?.preserveDirectoryOverride,ml,cl]);let hl=Z.useMemo(()=>$c!==!0||nl?!1:ol?!0:sl.length>0,[nl,ol,$c,sl.length]),gl=Z.useCallback(e=>{if(J.getState().newSessionDraft?.pendingWorktreeRequestId)return;let t=Jn.find(t=>t.id===e);t&&(Yn!==e&&Zn(e),Yt({projectId:e,directoryOverride:t.path},{force:!0}))},[Yn,Jn,Zn,Yt]),_l=Z.useCallback(e=>{J.getState().newSessionDraft?.pendingWorktreeRequestId||Jc&&Yt({projectId:Jc.id,directoryOverride:e},{force:!0})},[Jc,Yt]),vl=Z.useCallback(e=>{let t=e.icon?Ea[e.icon]:null,n=e.color?ka[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)(xa,{project:e,className:`size-full object-contain`,fallback:r}):r}),(0,$.jsx)(`span`,{className:`truncate`,children:rb(e)})]})},[]);Z.useEffect(()=>{!qc||!Jc||!cl||Ft?.pendingWorktreeRequestId||Ft?.bootstrapPendingDirectory||Ft?.preserveDirectoryOverride||ul.some(e=>e.value===cl)||Yt({projectId:Jc.id,directoryOverride:Jc.path})},[ul,Ft?.bootstrapPendingDirectory,Ft?.pendingWorktreeRequestId,Ft?.preserveDirectoryOverride,cl,Jc,Yt,qc]);let yl=Z.useRef(ue);Z.useEffect(()=>{fe===`idle`&&(yl.current=ue)},[ue,fe]);let bl=q(()=>{ye.current!==null&&(window.clearTimeout(ye.current),ye.current=null)}),Sl=q(()=>{bl(),fe===`collapsing`&&(de(!1),xe(`collapsed`),qr(!1)),pe(`idle`)}),Cl=q(()=>{bl(),ye.current=window.setTimeout(Sl,240)}),wl=q(()=>{if(yl.current){if(yl.current=!1,Qe.current=null,xe(`none`),window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches){de(!1),xe(`collapsed`),qr(!1),pe(`idle`);return}pe(`collapsing`),Cl()}});Z.useEffect(()=>()=>bl(),[bl]);let Tl=q(e=>{if(!(Date.now()<$e.current)){if(Se(),Qe.current=e,Le()&&typeof window<`u`&&window.dispatchEvent(new CustomEvent(`oc:keyboard-intent`,{detail:{open:!0}})),!yl.current){bl(),yl.current=!0;let e=typeof window<`u`?window.Capacitor?.getPlatform?.():void 0,t=window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches??!1;if(Le()&&(e===`ios`||e===`android`)){if((0,Sc.flushSync)(()=>{de(!0),xe(`full`),pe(t?`idle`:`expanding`)}),!(Zo&&ge.current===Rl)){let e=Si.current;if(e){let t=Math.max(44,Math.ceil(e.offsetHeight));ge.current=Rl,he(e=>Math.abs(e-t)<=2?e:t)}}t||Cl()}else Z.startTransition(()=>{de(!0),xe(`full`),pe(t?`idle`:`expanding`)}),t||Cl()}gi.current?.focus({preventScroll:Le()})}}),El=Z.useCallback(()=>{et(),Fe(!0),gi.current?.blur()},[et]),Dl=Z.useCallback(()=>{et(),ze(!0),gi.current?.blur()},[et]),Ol=Z.useCallback(e=>{if(Ne(e),e){Qe.current=null,yl.current||(yl.current=!0,Se(),de(!0),xe(`full`));return}window.setTimeout(()=>{yl.current&&document.activeElement!==gi.current&&wl()},30)},[wl]);Z.useEffect(()=>{if(!Nr||typeof document>`u`)return;let e=document.getElementById(`mobile-overlay-root`);e||(e=document.createElement(`div`),e.id=`mobile-overlay-root`,document.body.appendChild(e));let t=e,n=()=>Ze(eg(t.children));n();let r=new MutationObserver(n);return r.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[$h]}),()=>r.disconnect()},[Nr]);let kl=Xe||!!se||Pe||Ie||uo||mo,Al=Z.useRef(!1);Al.current=uo||mo;let jl=Z.useRef(!1),Ml=Z.useRef(0),Nl=Z.useRef(0),Pl=q(()=>{let e=J.getState().stagedMessageEdit;!e||e.sessionId!==Ln||window.setTimeout(()=>{let t=J.getState().stagedMessageEdit,n=document.activeElement,r=Ov({surfaceKind:Mn.kind,stagedSessionId:t?.sessionId??null,stagedMessageId:t?.messageId??null,blurredMessageId:e.messageId,submitInFlight:ls(),focusHeld:Date.now()<Nl.current,overlayOpen:Ml.current>0||Al.current,focusInsideComposer:n instanceof Element&&!!(n.closest(`[data-composer-content="true"]`)||n.closest(`[data-slot="dropdown-menu-content"]`))||Date.now()<$e.current});r.action===`disarm`&&J.getState().clearStagedMessageEdit(r.sessionId)},0)});Z.useEffect(()=>{if(!Nr||Le()||typeof window>`u`||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=()=>{Ml.current+=1},t=()=>{if(Ml.current=Math.max(0,Ml.current-1),jl.current){jl.current=!1;return}if(!nt.current||Al.current||Ml.current>0)return;if(Qa()){nt.current=!1;return}nt.current=!1,Nl.current=Date.now()+600,gi.current?.focus(),document.activeElement===gi.current&&De(!0);let e=()=>{let e=gi.current;!e||document.activeElement!==e||(Vl.current??e).scrollIntoView({block:`end`})};window.setTimeout(e,300),window.setTimeout(e,650)};return window.addEventListener(`oc:mobile-overlay-opened`,e),window.addEventListener(`oc:mobile-overlay-closed`,t),()=>{window.removeEventListener(`oc:mobile-overlay-opened`,e),window.removeEventListener(`oc:mobile-overlay-closed`,t)}},[Nr]),Z.useEffect(()=>{if(!Nr)return;if(kl){(Ce||Date.now()-tt.current<800)&&(nt.current=!0);return}if(!nt.current)return;let e=window.setTimeout(()=>{if(nt.current=!1,Qa())return;let e=gi.current;e&&document.activeElement!==e&&e.focus({preventScroll:Le()})},180);return()=>window.clearTimeout(e)},[Nr,kl,Ce]);let Fl=Ce||Xe||Me||!!se||Pe||Ie||Ve!==null||uo||mo||h,Il=Xe||Me||!!se||Pe||Ie||Ve!==null||uo||mo||h;Z.useEffect(()=>{if(!Nr||!ue||Fl)return;let e=window.setTimeout(()=>{document.activeElement!==gi.current&&wl()},250);return()=>window.clearTimeout(e)},[Nr,ue,Fl,wl]);let Ll=Z.useRef(!1);Ll.current=Il,Z.useEffect(()=>{if(!Nr||Le()||typeof document>`u`)return;let e=document.documentElement;return Ce?e.classList.add(`oc-browser-keyboard-open`):(e.classList.remove(`oc-browser-keyboard-open`),window.matchMedia?.(`(display-mode: standalone)`)?.matches&&window.setTimeout(()=>{e.classList.contains(`oc-browser-keyboard-open`)||(window.scrollTo(0,0),document.body.scrollTop=0,e.scrollTop=0)},350)),()=>e.classList.remove(`oc-browser-keyboard-open`)},[Nr,Ce]),Z.useEffect(()=>{if(!Nr||typeof window>`u`)return;let e=e=>{let t=e.detail;!t||t.open!==!1||yl.current&&(Ll.current||(0,Sc.flushSync)(()=>{wl()}))};return window.addEventListener(`oc:keyboard-intent`,e),()=>window.removeEventListener(`oc:keyboard-intent`,e)},[Nr,wl]);let Rl=Un?le(Un):Mn.surfaceID;Z.useLayoutEffect(()=>{if(!Nr||!ue||fe!==`idle`||Zo&&ge.current===Rl)return;let e=Si.current;if(!e)return;let t=()=>{let t=Math.max(44,Math.ceil(e.offsetHeight));ge.current=Rl,he(e=>e===t?e:t)};t();let n=typeof ResizeObserver==`function`?new ResizeObserver(t):null;return n?.observe(e),()=>n?.disconnect()},[Nr,ue,fe,Rl,Zo,ae]);let zl=q(e=>{e.currentTarget===e.target&&e.animationName.startsWith(`oc-mobile-composer-motion-`)&&Sl()});Z.useEffect(()=>{Ge(``)},[Ve]);let Vl=Z.useRef(null);Z.useLayoutEffect(()=>{if(!Nr||!Aa||Le())return;let e=window.visualViewport,t=Vl.current,n=gi.current;if(!e||!t)return;document.documentElement.classList.add(`oc-browser-kb-fullscreen`);let r=()=>{let n=Math.max(0,Math.floor(e.offsetTop)),r=document.documentElement.clientHeight;t.style.position=`fixed`,t.style.left=`0`,t.style.right=`0`,t.style.top=`${n}px`,t.style.height=`${Math.floor(Math.min(e.height,r-n))}px`,t.style.zIndex=`40`,t.style.background=`var(--background)`};return r(),e.addEventListener(`resize`,r),e.addEventListener(`scroll`,r),window.addEventListener(`resize`,r),window.addEventListener(`scroll`,r,!0),()=>{e.removeEventListener(`resize`,r),e.removeEventListener(`scroll`,r),window.removeEventListener(`resize`,r),window.removeEventListener(`scroll`,r,!0),document.documentElement.classList.remove(`oc-browser-kb-fullscreen`),t.style.position=``,t.style.left=``,t.style.right=``,t.style.top=``,t.style.height=``,t.style.zIndex=``,t.style.background=``,requestAnimationFrame(()=>{n&&document.activeElement===n&&n.scrollIntoView({block:`nearest`})})}},[Nr,Aa]),Z.useLayoutEffect(()=>{if(!Nr||Le()||!zn||Aa||!Ce)return;let e=window.visualViewport,t=Vl.current;if(!e||!t)return;let n=t.getBoundingClientRect();t.style.position=`fixed`,t.style.left=`${Math.floor(n.left)}px`,t.style.width=`${Math.floor(n.width)}px`,t.style.zIndex=`40`,t.style.background=`var(--background)`;let r=NaN,i=0,a=()=>{let n=document.documentElement.clientHeight,o=e.offsetTop+e.height,s=Math.max(0,Math.floor(Math.min(o,n)-t.offsetHeight));s!==r&&(r=s,t.style.top=`${s}px`),i=requestAnimationFrame(a)};return a(),()=>{cancelAnimationFrame(i),t.style.position=``,t.style.left=``,t.style.width=``,t.style.top=``,t.style.zIndex=``,t.style.background=``}},[Nr,Aa,zn,Ce]);let Hl=Nr?`px-1.5 py-1.5`:Kc?`px-1.5 py-1`:`px-2.5 py-1.5`,Ul=Nr?`h-8 w-8`:Kc?`h-5 w-5`:`h-6 w-6`,Wl=Nr?`h-4 w-4`:Kc?`h-3.5 w-3.5`:`h-4 w-4`,Gl=Nr?`h-6 w-6`:Kc?`h-4 w-4`:`h-5 w-5`,ql=Nr?`h-[18px] w-[18px]`:Kc?`h-4 w-4`:`h-[18px] w-[18px]`,Jl=Y(`flex cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed`,Np),Xl=Y(Jl,Ul),Zl=(Nr?Ce||_a||va||se:pa||_a||va)?`opacity-100`:`opacity-45 hover:opacity-100 focus-within:opacity-100`;Z.useEffect(()=>()=>{lo.current&&=(clearTimeout(lo.current),null)},[]);let Ql=Nr?(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)(sb,{onOpenAgentPanel:vs,onCycleAgent:()=>{et(),Js()},agentName:Mn.selection.value.agent,agents:Dr,disabled:jr}),(0,$.jsx)(cb,{onOpenModel:()=>Uo(`model`),providerID:Mn.selection.value.providerID,modelID:Mn.selection.value.modelID,provider:kr.find(e=>e.id===Mn.selection.value.providerID),variant:Mn.selection.value.variant})]}):null,$l=(0,$.jsxs)(`div`,{className:`relative z-10 flex flex-wrap items-center gap-1 px-3 pt-1`,children:[(0,$.jsx)(Fu,{attachments:In,onShowPopup:Ir,onRemoveAttachedFile:ic}),Mn.kind===`primary`?(0,$.jsx)(zu,{attachedFiles:In,onAddVSCodeFile:(e,t,n)=>{Un&&Qt(Un,()=>vt.getState()).addVSCodeFile(e,t,n)},onAddVSCodeSelection:(e,t)=>{if(Un)return Qt(Un,()=>vt.getState()).addVSCodeSelection(e,t)}}):null]}),eu=ao?.map((e,t)=>(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(R_,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)),tu=Nr?(0,$.jsxs)($.Fragment,{children:[be===`collapsed`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{"data-mobile-composer-collapsed-slot":`attach`,"data-composer-action":`true`,className:`composer-mobile-actions flex shrink-0 items-center`,children:(0,$.jsx)(db,{isVSCode:Kc,footerIconButtonClass:Xl,iconSizeClass:ql,handlePickLocalFiles:Vc,handlePickLocalImages:Hc,openIssuePicker:xs,openPrPicker:Cs,onOpenMobileSheet:El,onOpenAndroidPickSheet:Pc()?Dl:void 0})}),Qo?(0,$.jsx)(`div`,{"data-mobile-composer-collapsed-slot":`action`,"data-composer-action":`true`,className:`flex shrink-0 items-center justify-end`,children:(0,$.jsx)(pb,{isMobile:!0,footerIconButtonClass:Xl,sendIconSizeClass:Wl,stopIconSizeClass:Gl,canSend:Yo,canAbort:!0,hasContent:!1,currentSessionId:Ln,newSessionDraftOpen:zn,draftSubmitting:Rn,submissionBlocked:a,sendPhase:as,queueFrozen:Jo,queueFallbackAvailable:Qo||Zo,onPrimaryAction:Ds,onAbort:qs})}):null]}):null,_e?(0,$.jsxs)(`div`,{className:Y(`w-full min-w-0 items-center gap-x-1.5`,be===`full`?`flex`:`hidden`),"data-composer-action":`true`,"aria-hidden":be!==`full`||void 0,inert:be!==`full`||void 0,children:[(0,$.jsxs)(`div`,{className:`composer-mobile-actions flex shrink-0 items-center gap-x-2 pl-1`,children:[(0,$.jsx)(db,{isVSCode:Kc,footerIconButtonClass:Xl,iconSizeClass:ql,handlePickLocalFiles:Vc,handlePickLocalImages:Hc,openIssuePicker:xs,openPrPicker:Cs,onOpenSettings:e,onOpenMobileSheet:El,onOpenAndroidPickSheet:Pc()?Dl:void 0}),pr?(0,$.jsx)(fb,{sessionId:Ln,draftOpen:zn,draftEnabled:Ft.permissionAutoAcceptEnabled===!0,enabled:ir,saving:Ln?qt:!1,footerIconButtonClass:Xl,iconSizeClass:ql,onSetDraftEnabled:Wt,onSetSessionEnabled:Jt,onOpenSessionFirst:Ut,onToggleFailed:mr}):null,(0,$.jsx)(uv,{sessionId:Ln,directory:Dt??Vn,draftOpen:zn}),(0,$.jsx)(dv,{length:Qr.length})]}),Ql,(0,$.jsx)(`div`,{className:`relative z-30 flex shrink-0 items-center justify-end gap-x-1.5`,children:(0,$.jsx)(pb,{isMobile:Nr,footerIconButtonClass:Xl,sendIconSizeClass:Wl,stopIconSizeClass:Gl,canSend:Yo,canAbort:Qo,hasContent:!!Ko,currentSessionId:Ln,newSessionDraftOpen:zn,draftSubmitting:Rn,submissionBlocked:a,sendPhase:as,queueFrozen:Jo,queueFallbackAvailable:Qo||Zo,onPrimaryAction:Ds,onAbort:qs})})]}):null]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center`,Gc),children:[(0,$.jsx)(db,{isVSCode:Kc,footerIconButtonClass:Xl,iconSizeClass:ql,handlePickLocalFiles:Vc,handlePickLocalImages:Hc,openIssuePicker:xs,openPrPicker:Cs,onOpenSettings:e,withTooltip:!0}),pr?(0,$.jsx)(fb,{sessionId:Ln,draftOpen:zn,draftEnabled:Ft.permissionAutoAcceptEnabled===!0,enabled:ir,saving:Ln?qt:!1,footerIconButtonClass:Xl,iconSizeClass:ql,onSetDraftEnabled:Wt,onSetSessionEnabled:Jt,onOpenSessionFirst:Ut,onToggleFailed:mr}):null,(0,$.jsx)(uv,{sessionId:Ln,directory:Dt??Vn,draftOpen:zn}),(0,$.jsx)(dv,{length:Qr.length})]}),(0,$.jsxs)(`div`,{className:Y(`relative z-30 flex flex-1 items-center justify-end md:gap-x-1.5`,Gc),children:[(0,$.jsx)(ab,{className:`min-w-0 flex-1 justify-end`,composerTextareaRef:gi,selectionAdapter:yr}),(0,$.jsx)(ob,{radius:Ma,isMobile:Nr,footerIconButtonClass:Xl,footerPaddingClass:Hl,iconSizeClass:ql,sendIconSizeClass:Wl,onInsert:Ns,onInsertAndSend:Fs,onContentHeightChange:Qs,renderTrigger:!1}),(0,$.jsx)(pb,{isMobile:Nr,footerIconButtonClass:Xl,sendIconSizeClass:Wl,stopIconSizeClass:Gl,canSend:Yo,canAbort:Qo,hasContent:!!Ko,currentSessionId:Ln,newSessionDraftOpen:zn,draftSubmitting:Rn,submissionBlocked:a,sendPhase:as,queueFrozen:Jo,queueFallbackAvailable:Qo||Zo,onPrimaryAction:Ds,onAbort:qs})]})]}),nu=q(()=>{if(Nr){Nl.current=Date.now()+600,Tl(`focus`);let e=()=>{gi.current?.focus({preventScroll:Le()}),document.activeElement===gi.current&&De(!0)};e(),window.requestAnimationFrame(e);return}let e=()=>{if(!Xp(gi))return;let e=Yp(gi);if(!e)return;let t=e.value.length;try{e.setSelectionRange(t,t)}catch{}};e(),window.requestAnimationFrame(()=>{e(),window.setTimeout(e,0)})}),ru=Dt??Vn,{goal:iu,enabled:ou}=iv(Ln??``,ru),su=(0,$.jsx)(Lf,{onEditMessage:gs,onSendMessage:_s,onEditCommitted:nu,draftKey:Un,scope:xo,draftTarget:Un?{key:Un,expectedRevision:()=>Fn.getDraft(Un)?.revision??`absent`}:null,clientPendingItems:ds,onRemoveClientPending:e=>{let t=En.getState().removeEstablishingFollowUp(e);t&&(t.content&&$r(t.content),t.attachments.length>0&&Fn.restoreAttachments(t.attachments))},trailing:Ln&&ou&&iu?(0,$.jsx)(lv,{sessionId:Ln,directory:ru}):null});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`form`,{ref:Vl,onSubmit:e=>{e.preventDefault(),Ds()},onPointerDownCapture:e=>{if(!Nr)return;let t=e.target;t instanceof Element&&(!yl.current&&t.closest(`[data-mobile-composer-surface="true"]`)&&Se(),!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"]`)&&(et(),e.preventDefault())))},className:Y(`relative w-full pt-0 pb-4`,Oa&&`flex h-full min-h-0 flex-col pt-4`,Aa&&`flex h-full min-h-0 flex-col pt-1`,Nr&&`bottom-safe-area oc-mobile-composer`),style:Nr&&zr>0?{marginBottom:`${zr}px`}:void 0,children:[Bn&&!Oa&&!Nr&&!Kc&&!fl?(0,$.jsx)(`div`,{className:`chat-input-column mb-7 text-center`,children:(0,$.jsx)(`h1`,{className:`text-balance text-2xl font-normal tracking-tight text-foreground md:text-3xl`,children:ib(Xc?l(`chat.emptyState.draftTitleWithProject`,{project:Xc}):l(`chat.emptyState.draftTitle`),Xc)})}):null,(0,$.jsxs)(`div`,{className:Y(`chat-input-column relative overflow-visible`,ja&&`flex flex-1 min-h-0 flex-col`),children:[(0,$.jsx)(Iu,{attachments:In,onShowPopup:Ir,onRemoveAttachedFile:ic}),(0,$.jsx)(tp,{}),No&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pb-2`,children:[Io>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ia?.colors?.surface?.elevated,borderColor:ia?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:l(`chat.chatInput.reviewComments`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ia?.colors?.status?.info},children:Io}),(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:Ro,"aria-label":l(`chat.chatInput.reviewCommentsRemove`),title:l(`chat.chatInput.reviewCommentsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,Po>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ia?.colors?.surface?.elevated,borderColor:ia?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:l(`chat.chatInput.devServerLogs`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ia?.colors?.status?.info},children:Po}),(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:()=>Lo(`preview-console`),"aria-label":l(`chat.chatInput.devServerLogsRemove`),title:l(`chat.chatInput.devServerLogsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,Fo>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ia?.colors?.surface?.elevated,borderColor:ia?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:l(`chat.chatInput.previewAnnotations`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ia?.colors?.status?.info},children:Fo}),(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:()=>Lo(`preview-annotation`),"aria-label":l(`chat.chatInput.previewContextRemove`),title:l(`chat.chatInput.previewContextRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null]}),go&&!Kc&&(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:()=>fo(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[go.author?.avatarUrl&&(0,$.jsx)(`img`,{src:go.author.avatarUrl,alt:go.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`#`,go.number,go.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:l(`chat.chatInput.linked.byAuthor`,{author:go.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:go.title})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:go.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":l(`chat.chatInput.linked.issue.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{_o(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":l(`chat.chatInput.linked.issue.removeAria`),title:l(`chat.chatInput.linked.issue.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),vo&&!Kc&&(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:()=>ho(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[vo.author?.avatarUrl&&(0,$.jsx)(`img`,{src:vo.author.avatarUrl,alt:vo.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[l(`chat.chatInput.linked.pr.number`,{number:vo.number}),vo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:l(`chat.chatInput.linked.byAuthor`,{author:vo.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:vo.title}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0 typography-meta`,children:[vo.head,` → `,vo.base]})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:vo.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":l(`chat.chatInput.linked.pr.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{yo(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":l(`chat.chatInput.linked.pr.removeAria`),title:l(`chat.chatInput.linked.pr.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),(0,$.jsx)(ub,{sessionId:Ln,directory:Dt??Vn}),(0,$.jsx)(lb,{showAbortStatus:ua,showAssistantStatus:!1,showTodos:!0,leftAccessory:zn||!pl?null:(0,$.jsx)(jh,{})}),!Nr&&qc?(0,$.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[Jc?(0,$.jsxs)(Ta,{value:Jc.id,open:Je,onValueChange:gl,onOpenChange:e=>{Ye(e),e||qe(``)},children:[(0,$.jsx)(Ia,{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]`,jp),children:[(0,$.jsx)(ya,{children:vl(Jc)}),(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)(wa,{fitContent:!0,children:[(0,$.jsx)(La,{autoFocus:!0,value:Ke,onChange:e=>qe(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:l(`chat.chatInput.draftPicker.searchProjects`),className:`mb-1 h-8 min-w-56`}),Jn.filter(e=>Fa(rb(e),Ke)||Fa(e.path,Ke)).map(e=>(0,$.jsx)(Pa,{value:e.id,className:`max-w-[24rem] truncate`,children:vl(e)},e.id)),(0,$.jsx)(Sa,{}),(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(),Ye(!1),requestAnimationFrame(()=>Hr.requestDirectoryDialog())},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`chat.chatInput.draftPicker.newProject`)})]})]})]}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-auto min-h-6 cursor-pointer items-center gap-1.5 rounded-lg px-2.5 py-1 typography-micro font-medium text-foreground/80`,jp),onClick:()=>Hr.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`chat.chatInput.draftPicker.newProject`)})]}),Jc&&hl?(0,$.jsx)(v_,{directory:cl,projectDirectory:Yc,label:dl,projectRootOption:ol,worktreeOptions:sl,onSelectDirectory:_l}):null]}):null,Nr&&qc?(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:[Jc?(0,$.jsx)(`button`,{type:`button`,className:Y(`inline-flex h-[26px] 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`,jp),onClick:()=>He(`project`),children:vl(Jc)}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-[26px] 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`,jp),onClick:()=>Hr.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`chat.chatInput.draftPicker.newProject`)})]}),Jc&&hl?(0,$.jsx)(v_,{directory:cl,projectDirectory:Yc,label:dl,projectRootOption:ol,worktreeOptions:sl,onSelectDirectory:_l,maxWidthClassName:`max-w-[50%]`,presentation:`mobile-sheet`}):null]}):null,(0,$.jsxs)(`div`,{className:Y(!Nr&&`contents`,Nr&&`relative`,Aa&&`flex min-h-0 flex-1 flex-col`),children:[su,(0,$.jsxs)(`div`,{className:Y(Nr?`oc-mobile-composer-motion-viewport`:`contents`,Nr&&fe!==`idle`&&`oc-mobile-composer-motion-active`,Nr&&!ue&&fe===`idle`&&`oc-mobile-composer-motion-collapsed`),style:Nr?{"--oc-mobile-composer-stage-height":`${me}px`}:void 0,children:[(0,$.jsxs)(Xg,{value:Qr,attachments:[],disabled:!Ln&&!zn||Rn&&!as.establishing,pending:Qo||as.inFlight&&!as.establishing,isMobile:Nr,onSubmit:Ds,"data-mobile-composer-surface":Nr?`true`:void 0,"data-mobile-composer-collapsed":Nr&&!ue?`true`:void 0,"data-session-swipe-surface":Nr?`true`:void 0,expanded:ja,focusedTone:p===`shell`?`info`:`primary`,className:Y(`relative z-10`,h&&`ring-2 ring-primary ring-offset-2`,Rr&&`ring-1 ring-[var(--interactive-selection)] border-[var(--interactive-selection)]`,Nr&&!ue&&`oc-mobile-composer-collapsed`,Nr&&`oc-mobile-composer-surface`,Nr&&fe===`expanding`&&`oc-mobile-composer-motion-expanding`,Nr&&fe===`collapsing`&&`oc-mobile-composer-motion-collapsing`,Nr&&fe!==`idle`&&`oc-mobile-composer-effects-reduced`),style:{borderRadius:Ma,backgroundColor:ia?.colors?.surface?.subtle},ref:Si,onDropCapture:Nc,onDragEnter:Oc,onDragOver:kc,onDragLeave:Ac,onDrop:Mc,onDragEnd:jc,onAnimationEnd:zl,autoResize:!1,disableInputWhilePending:!1,contentClassName:Y(`transition-opacity duration-200`,Zl,ja&&`flex-1 min-h-0`,Nr&&!ue&&`oc-mobile-composer-collapsed-content`),inputHeader:void 0,attachmentContent:Nr&&be!==`full`?void 0:$l,highlightedContent:eu,highlightRef:fa,inputRef:gi,textLayoutClassName:Y(Iy,ja?Y(`h-full min-h-0`,Nr?`py-2.5`:`py-4`):Nr?ue?`py-2.5`:`py-0`:`pt-4 pb-2`,p===`shell`?`font-mono`:`typography-markdown md:typography-ui-label`,Nr&&!ue&&`oc-mobile-composer-collapsed-text`),inputOuterClassName:Y(ja&&`flex-1 min-h-0`,Nr&&!ue&&`min-h-0 flex-1`),inputStyle:{flex:ja||Nr&&!ue?`1 1 auto`:`none`,height:Nr&&!ue?`100%`:!ja&&ae?`${ae.height}px`:void 0,maxHeight:Nr&&!ue?`100%`:!ja&&ae?`${ae.maxHeight}px`:void 0,borderTopLeftRadius:Ma,borderTopRightRadius:Ma},footerClassName:Y(`relative z-30 bg-transparent flex-shrink-0`,Nr&&!ue?`oc-mobile-composer-collapsed-footer px-0 py-0`:Hl,Nr?`flex items-center gap-x-1.5`:Y(`flex items-center justify-between`,Gc)),footerStyle:{borderBottomLeftRadius:Ma,borderBottomRightRadius:Ma},footerContent:tu,placeholder:l(Ln||zn?p===`shell`?`chat.chatInput.placeholder.shell`:Na?`chat.chatInput.placeholder.chatCompact`:`chat.chatInput.placeholder.chat`:`chat.chatInput.placeholder.selectSession`),onChange:(e,t)=>uc(t),textareaProps:{readOnly:Rr,onCompositionStart:()=>{vi.current=!0},onCompositionEnd:e=>{vi.current=!1;let t=e.currentTarget;tc(t.value,t.selectionStart??t.value.length,t.selectionEnd??t.selectionStart??t.value.length)},onBeforeInput:lc,onKeyDown:Us,onCopy:mc,onCut:hc,onPaste:fc,onDragEnter:Oc,onDragOver:kc,onDropCapture:Nc,onDrop:Mc,onDragEnd:jc,onKeyUp:Gs,onClick:()=>{Nr&&!yl.current&&Date.now()>=$e.current&&Tl(`focus`),Gs()},onScroll:e=>{if(Nr&&!yl.current){let t=e.currentTarget;t.scrollTop!==0&&(t.scrollTop=0),t.scrollLeft!==0&&(t.scrollLeft=0),fa.current&&(fa.current.style.transform=``);return}Gs();let t=e.currentTarget.scrollTop;fa.current&&(fa.current.style.transform=`translateY(-${t}px)`)},onSelect:e=>{let t=e.currentTarget,n=t.selectionStart??0,r=t.selectionEnd??n;if(vi.current){bi.current=r;return}let i=F_(n,r,[...Re(Qr,In.filter(Oe).map(e=>e.filename)),...P_(Qr,qa.keys()),...Zr.references]);i&&(i.start!==n||i.end!==r)?(t.setSelectionRange(i.start,i.end),bi.current=i.end):bi.current=n,Gs()},onFocus:()=>{if(!Nr){ha(!0);return}if(Date.now()<$e.current){let e=gi.current;e&&e.blur();return}Ae.current!==null&&(window.clearTimeout(Ae.current),Ae.current=null),yl.current?(Qe.current=null,Le()&&typeof window<`u`&&window.dispatchEvent(new CustomEvent(`oc:keyboard-intent`,{detail:{open:!0}}))):Tl(`focus`),De(!0)},onBlur:e=>{if(vi.current=!1,bi.current=e.currentTarget.selectionStart??bi.current,Pl(),!Nr){window.setTimeout(()=>{let e=document.activeElement;if(!(e instanceof Element)){ha(!1);return}e.closest(`[data-composer-content="true"]`)||e.closest(`[data-slot="dropdown-menu-content"]`)||ha(!1)},0);return}if(Date.now()<Nl.current){let e=gi.current;if(e){e.focus(),window.setTimeout(()=>{Date.now()<Nl.current&&document.activeElement!==e&&e.focus()},50);return}}if(tt.current=Date.now(),Le()){De(!1);return}Ae.current!==null&&window.clearTimeout(Ae.current),Ae.current=window.setTimeout(()=>{Ae.current=null,De(!1)},120)},autoCorrect:Nr?`on`:`off`,autoCapitalize:Nr?`sentences`:`off`,spellCheck:Nr||Ur,fillContainer:ja||Nr&&!ue,rows:1},children:[(0,$.jsx)(Am,{}),h&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/90`,style:{borderRadius:Ma},children:(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`inline-flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,className:Jl,onClick:()=>Vc(),title:l(`chat.chatInput.actions.attachFiles`),"aria-label":l(`chat.chatInput.actions.attachFiles`),children:(0,$.jsx)(X,{name:`attachment-2`,className:Y(ql,`text-current`)})})}),(0,$.jsx)(`p`,{className:`mt-2 typography-ui-label text-muted-foreground`,children:l(y?`chat.chatInput.drop.insertMention`:`chat.chatInput.drop.attachFiles`)})]})}),k&&(0,$.jsx)(bs,{ref:Bi,searchQuery:M,directory:Vn,onCommandSelect:Q,onClose:()=>j(!1),commandPolicy:e=>tm(Mn,e),commandContext:Gn,style:Oa&&so?{left:`${so.left}px`,top:`${so.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${so.left+8}px))`,maxHeight:`${so.maxHeight}px`,transform:so.place===`above`?`translateY(-100%)`:void 0}:void 0}),P&&(0,$.jsx)(op,{ref:Vi,searchQuery:R,directory:Vn,onSkillSelect:bc,onClose:()=>I(!1),style:Oa&&so?{left:`${so.left}px`,top:`${so.top}px`,bottom:`auto`,width:`min(360px, calc(100% - ${so.left+8}px))`,maxHeight:`${so.maxHeight}px`,transform:so.place===`above`?`translateY(-100%)`:void 0}:void 0}),V&&(0,$.jsx)(ws,{ref:Ui,searchQuery:te,onSnippetSelect:xc,onClose:()=>H(!1),style:Oa&&so?{left:`${so.left}px`,top:`${so.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${so.left+8}px))`,maxHeight:`${so.maxHeight}px`,transform:so.place===`above`?`translateY(-100%)`:void 0}:void 0}),T&&(0,$.jsx)(js,{ref:Li,searchQuery:D,onFileSelect:gc,onAgentSelect:_c,onSessionSelect:vc,onClose:()=>E(!1),style:Oa&&so?{left:`${so.left}px`,top:`${so.top}px`,bottom:`auto`,width:`min(520px, calc(100% - ${so.left+8}px))`,maxHeight:`${so.maxHeight}px`,transform:so.place===`above`?`translateY(-100%)`:void 0}:void 0})]}),Nr?(0,$.jsx)(ob,{radius:Ma,isMobile:Nr,footerIconButtonClass:Xl,footerPaddingClass:Hl,iconSizeClass:ql,sendIconSizeClass:Wl,onInsert:Ns,onInsertAndSend:Fs,onActiveChange:Ol,onContentHeightChange:Qs,renderTrigger:!1}):null]})]}),Nr?(0,$.jsx)(ab,{className:`hidden`,composerTextareaRef:gi,selectionAdapter:yr,mobilePanel:se,onMobilePanelChange:ce}):null]}),zn&&!Oa&&!Nr&&!Kc&&!fl?(0,$.jsx)(Ug,{onSubmit:Ms,className:`chat-input-column mt-4`}):null]}),u.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(Ly,{popup:u,onOpenChange:Lr,isMobile:Nr})}):null,(0,$.jsx)(bg,{open:uo,onOpenChange:fo,mode:`select`,onSelect:e=>{_o(e),yo(null)}}),(0,$.jsx)(Cg,{open:mo,onOpenChange:ho,onSelect:e=>{yo(e),_o(null)}}),(0,$.jsx)(cu,{open:Qn,onOpenChange:er,projectDirectory:Dt??Vn??null,submitting:nr,onConfirm:Da}),(0,$.jsx)(`input`,{ref:Ic,type:`file`,multiple:!0,className:`hidden`,onChange:Wc,accept:`*/*`}),(0,$.jsx)(`input`,{ref:Lc,type:`file`,multiple:!0,className:`hidden`,onChange:Wc,accept:`image/*`}),null,Nr&&Ie?(0,$.jsx)(Cp,{open:!0,onClose:()=>ze(!1),title:l(`chat.chatInput.actions.addAttachment`),children:(0,$.jsxs)(`div`,{className:`flex flex-col px-3 pb-4 pt-1`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2.5 rounded-lg px-2 py-3 text-left typography-ui-label hover:bg-[var(--interactive-hover)]`,onClick:()=>{nt.current=!1,ze(!1),requestAnimationFrame(Uc)},children:[(0,$.jsx)(X,{name:`file-image`,className:`h-[18px] w-[18px] flex-shrink-0 text-muted-foreground`}),l(`chat.chatInput.actions.attachPhotos`)]}),(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2.5 rounded-lg px-2 py-3 text-left typography-ui-label hover:bg-[var(--interactive-hover)]`,onClick:()=>{nt.current=!1,ze(!1),requestAnimationFrame(Vc)},children:[(0,$.jsx)(X,{name:`attachment-2`,className:`h-[18px] w-[18px] flex-shrink-0 text-muted-foreground`}),l(`chat.chatInput.actions.attachFiles`)]})]})}):null,Nr&&qc&&Jc?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(eo,{id:`mobile-draft-project-picker-sheet-${Ue}`,open:Ve===`project`,onOpenChange:e=>{e||He(null)},ariaLabel:l(`chat.chatInput.draftPicker.projectTitle`),closeAriaLabel:l(`mobile.surface.closeAria`),resizeAriaLabel:l(`mobile.sessions.sheet.resizeAria`),children:[(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-2 pt-1`,"data-mobile-sheet-no-dismiss":``,children:(0,$.jsx)(La,{value:We,onChange:e=>Ge(e.target.value),placeholder:l(`chat.chatInput.draftPicker.searchProjects`),className:`h-9`})}),(0,$.jsx)(ma,{outerClassName:`min-h-0 flex-1`,disableHorizontal:!0,children:(0,$.jsx)(`div`,{className:`flex flex-col px-3 pb-2`,children:Jn.filter(e=>Fa(rb(e),We)||Fa(e.path,We)).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:()=>{gl(e.id),He(null)},children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:vl(e)}),e.id===Jc.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:()=>{He(null),Hr.requestDirectoryDialog()},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`chat.chatInput.draftPicker.newProject`)})]})})]})}):null]})},yb=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)(vb,{...e,surface:i}),t[0]=e,t[1]=i,t[2]=a):a=t[2],a};yb.displayName=`ChatInput`;var bb=Z.memo(yb);function xb(e){return e.preventDefault()}function Sb(e){e.preventDefault()}function Cb(e){return e.preventDefault()}function wb(e){e.pointerType===`touch`&&e.preventDefault()}function Tb(e){e.preventDefault()}function Eb(e){e.pointerType===`touch`&&e.preventDefault()}function Db(){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=()=>go(e=>{r(e),a(!1)}),l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),Z.useEffect(c,l);let u;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=e=>{e||(r(null),a(!1))},e[2]=u):u=e[2];let d=q(u),f;e[3]===d?f=e[4]:(f=()=>(d(!1),!0),e[3]=d,e[4]=f);let p;e[5]!==s||e[6]!==f?(p={id:`image-save-actions`,active:s,layer:`overlay`,onBack:f,surfaceRef:o},e[5]=s,e[6]=f,e[7]=p):p=e[7],No(p);let m;e[8]!==i||e[9]!==t||e[10]!==n?(m=async()=>{if(!(!n||i)){a(!0);try{await uc(n),Ii.success(t(`chat.image.actions.saveSuccess`)),r(null)}catch(e){let n=e;if(n instanceof DOMException&&n.name===`AbortError`){a(!1);return}Ii.error(t(`chat.image.actions.saveFailed`)),a(!1);return}a(!1)}},e[8]=i,e[9]=t,e[10]=n,e[11]=m):m=e[11];let h=q(m);if(!n)return null;let g;e[12]!==t||e[13]!==n.filename?(g=n.filename?.trim()||t(`chat.image.actions.sheetTitle`),e[12]=t,e[13]=n.filename,e[14]=g):g=e[14];let _=g,v;e[15]===t?v=e[16]:(v=Le()?t(`chat.image.actions.saveToPhotos`):t(`chat.image.actions.saveImage`),e[15]=t,e[16]=v);let y=v,b;e[17]===_?b=e[18]:(b=(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:_}),e[17]=_,e[18]=b);let x;e[19]===t?x=e[20]:(x=t(`mobile.surface.closeAria`),e[19]=t,e[20]=x);let S;e[21]===t?S=e[22]:(S=t(`mobile.sessions.sheet.resizeAria`),e[21]=t,e[22]=S);let C;e[23]===h?C=e[24]:(C=()=>{h()},e[23]=h,e[24]=C);let w=i?`loader-4`:`download`,T=i?`size-5 animate-spin`:`size-5`,E;e[25]!==w||e[26]!==T?(E=(0,$.jsx)(X,{name:w,className:T}),e[25]=w,e[26]=T,e[27]=E):E=e[27];let D;e[28]!==y||e[29]!==i||e[30]!==t?(D=i?t(`chat.image.actions.saving`):y,e[28]=y,e[29]=i,e[30]=t,e[31]=D):D=e[31];let O;e[32]===D?O=e[33]:(O=(0,$.jsx)(`span`,{className:`truncate`,children:D}),e[32]=D,e[33]=O);let k;e[34]!==i||e[35]!==C||e[36]!==E||e[37]!==O?(k=(0,$.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto overscroll-contain px-2 pb-2`,children:(0,$.jsxs)(da,{type:`button`,variant:`ghost`,size:`lg`,className:`min-h-12 w-full justify-start gap-3 rounded-lg px-4`,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)(eo,{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 Ob=(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(Et(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]},kb=(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},Ab=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}},jb=e=>e.syncLoading||e.assistantLoading,Mb=e=>e.isMobile&&(e.canLoadEarlier||e.isLoadingOlder),Nb=e=>e.isLoadingOlder,Pb=e=>!e.isMobile&&e.isLoadingOlder,Fb=e=>e.transcriptMessageCount>0||e.pendingUserCount>0||e.historyPrefixCount>0,Ib=e=>e.p0Satisfied||e.hasBusyShell||e.hasImmediateShell||e.hasPaintedTranscript?`pass`:e.prefetchStatus===`loading`||e.syncLoading||e.userRetrying?`hydrating`:e.prefetchStatus===`error`?`load-error`:e.hasRenderableSessionSnapshot?`pass`:`hydrating`,Lb=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}},Rb=e=>({newSessionDraft:e?.features?.newSessionDraft??!e,promptNavigator:e?.features?.promptNavigator??!e,returnToParent:e?.features?.returnToParent??!e}),zb=`text-[13px] leading-4 sm:text-[length:var(--text-micro)] sm:leading-5`,Bb=`relative bottom-safe-area oc-mobile-readonly-prompt-foot`,Vb=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)(Oa,{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},Hb=e=>{let t=(0,Q.c)(42),{t:n}=ot(),r=c(Ub),i=`agentName`in e||`providerId`in e||`modelId`in e||`modelName`in e;if(!i){let e=r&&Bb,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 ${zb}`,children:a}),t[4]=a,t[5]=o);let s;return t[6]!==i||t[7]!==o?(s=(0,$.jsx)(`div`,{className:i,children:o}),t[6]=i,t[7]=o,t[8]=s):s=t[8],s}let a;t[9]===n?a=t[10]:(a=n(`common.unavailable`),t[9]=n,t[10]=a);let o=a,s;t[11]!==e.agentName||t[12]!==o?(s=e.agentName?e.agentName.charAt(0).toUpperCase()+e.agentName.slice(1):o,t[11]=e.agentName,t[12]=o,t[13]=s):s=t[13];let l=s,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&&Bb,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 ${zb}`,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 ${zb}`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 overflow-hidden`,children:[(0,$.jsx)(na,{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)(Vb,{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 Ub(e){return e.isMobile}var Wb=Z.memo(()=>{let e=(0,Q.c)(5),{t}=ot(),{currentTheme:n}=Va(),r=Ki(Gb),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:`text-body-md font-medium text-destructive`,children:t(`chat.emptyState.opencodeUnreachable`)}),(0,$.jsx)(`span`,{className:`text-body-sm`,style:{color:i},children:r.message})]}):(0,$.jsx)(`span`,{className:`text-body-md`,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 Gb(e){return e.error}var Kb=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)}}},qb=de(e=>({planModeEnabled:!1,setPlanModeEnabled:t=>e({planModeEnabled:t})})),Jb=e=>{if(!e?.trim())return null;let t=e.trim();return t.toLowerCase()==="default"?null:Jn(t)},Yb=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?Jb(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)(Oa,{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(${ta(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-none`,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-none 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-none`,r?`px-1 py-px text-[10px]`:`px-1.5 py-0.5 typography-micro`,ta(o).class),children:[(0,$.jsx)(na,{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}),Xb=/(^|\s)\/([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)/g,Zb=/(```[\s\S]*?```|~~~[\s\S]*?~~~)/g,Qb=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),$b=(e,t)=>e.split(Zb).map((e,n)=>n%2==1?e:t(e)).join(``),ex=e=>$b(e,e=>e.replace(/ *\n/g,`
|
|
6537
|
+
`)){ne(t),H(!0),E(!1);return}}H(!1);let s=fr({value:e,cursorPosition:t,inputSource:n,insertedText:r});s===null?E(!1):(O(s),E(!0))},[p,N,O,j,E,I,H,z,ne]),ic=Z.useCallback((e,t,n,r=`manual`,i)=>{let a=e,o=t,s=n;if(p===`normal`&&!Si.current&&to.size>0&&e.includes(`/`)){let r=Sv(e,to,n);r&&(a=r.text,o=t+(r.caret-n),s=r.caret)}let c=oi(a,o,s),l=Xi(),u=c.requiresTextCorrection||o!==c.start||s!==c.end||a!==e;return requestAnimationFrame(()=>{let e=xi.current;e&&Zp(u,Si.current)&&(e.value=l.text,e.setSelectionRange(c.start,c.end)),nc()}),rc(l.text,c.end,r,i),{document:l,selection:c}},[nc,oi,Xi,p,to,rc]),ac=Z.useCallback((e,t=`manual`)=>{if(!e)return;let n=xi.current;if(!n){let n=ni+e;ic(n,n.length,n.length,t,e);return}let r=n.selectionStart??ni.length,i=n.selectionEnd??ni.length,a=`${ni.substring(0,r)}${e}${ni.substring(i)}`,o=r+e.length;ic(a,o,o,t,e)},[ic,ni]),oc=q((e,t)=>{let n=new Set(we(zn.map(e=>e.filename),e,t));if(n.size!==0)for(let e of zn)n.has(e.filename)&&Rn.removeAttachment(e.id)}),sc=Z.useCallback(e=>{Rn.removeAttachment(e.id)},[Rn]),cc=Z.useCallback(()=>{ji.current=!1,zi.current=[],Mi.current&&=(clearTimeout(Mi.current),null)},[]),lc=Z.useCallback(()=>{Mi.current&&clearTimeout(Mi.current),Mi.current=setTimeout(()=>{cc()},700)},[cc]),uc=Z.useCallback(()=>{Pi.current=!1,Li.current&&=(clearTimeout(Li.current),null)},[]),dc=Z.useCallback(()=>{Pi.current=!0,Li.current&&clearTimeout(Li.current),Li.current=setTimeout(()=>{Pi.current=!1,Li.current=null},700)},[]),fc=Z.useCallback(e=>{!d()||!ji.current||e.nativeEvent?.inputType===`insertFromDrop`&&(e.preventDefault(),cc())},[cc]),pc=e=>{if(Ur)return;let t=e.nativeEvent;if(d()&&ji.current){let n=zi.current;if(t?.inputType===`insertFromDrop`||n.some(t=>t.length>0&&e.target.value.includes(t))){cc();return}}let n=e.target.value;oc(Ji.current,n);let r=e.target.selectionStart??n.length,i=t?.inputType?.startsWith(`insertFromPaste`)?qy(Ji.current,n):``,a=i.includes(`@`)||Pi.current;Pi.current&&uc();let o=a?`paste`:`manual`;if(p===`normal`&&n.startsWith(`!`)){let e=n.slice(1),t=Math.max(0,r-1);m(`shell`),ii(e),nc(),j(!1),I(!1),E(!1),requestAnimationFrame(()=>{xi.current&&(xi.current.selectionStart=t,xi.current.selectionEnd=t)});return}ic(n,r,e.target.selectionEnd??r,o,i)};Z.useEffect(()=>()=>{cc(),uc()},[cc,uc]);let mc=Z.useCallback(e=>{let t=Array.from(new Set(e.map(e=>e.trim()).filter(Boolean)));if(t.length===0)return;let n=t.map(e=>`@${e}`).join(` `),r=xi.current,i=r?.selectionStart??ni.length,a=r?.selectionEnd??ni.length,o=ks(n,ni.slice(0,i),ni.slice(a)),s=`${ni.slice(0,i)}${o}${ni.slice(a)}`;oc(ni,s),Zi(s,t)},[ni,Zi,oc]),hc=Z.useCallback(async e=>{let t=tb(e.clipboardData);if(t.length>0&&(Bn||Un)){e.preventDefault(),mc(t);return}if(p===`normal`&&(Bn||Un)){let t=xi.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&r>n){let t=e.clipboardData.getData(`text`).trim(),i=ni.slice(n,r);if(Wy.test(t)&&!/\s/.test(t)&&i.trim().length>0&&!i.includes(`](`)){e.preventDefault();let a=`${ni.slice(0,n)}[${i}](${t})${ni.slice(r)}`,o=n+1+i.length+2+t.length+1;vi(a),requestAnimationFrame(()=>{let e=xi.current;e&&(e.selectionStart=o,e.selectionEnd=o),nc()}),rc(a,o,Jy(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(p===`normal`&&uy(Xi(),a)){e.preventDefault();let t=Xi().text,n=xi.current,r=n?.selectionStart??ni.length,i=n?.selectionEnd??ni.length,o=dy(a,ni,Xi().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>l(`chat.chatInput.pastedTextReference`,{index:e,count:t}),ly(Xi())),s=si(r,i,{id:o.id,kind:`paste`,text:o.text,characterCount:o.characterCount,index:o.index,display:o.token},{inlineBoundaries:!0,padDocumentEdges:!0}),c=zs(s.document.text,s.caret);xi.current&&(xi.current.value=s.document.text),requestAnimationFrame(()=>{xi.current?.setSelectionRange(c,c),nc()}),rc(s.document.text,c),oc(t,s.document.text);return}a.includes(`@`)&&dc();return}if(!Bn&&!Un){a.includes(`@`)&&dc();return}e.preventDefault();let o=je(i,[...zn.map(e=>e.filename),...Yi.current]),s=Be(o),c=Xi().text,u=xi.current,d=u?.selectionStart??ni.length,f=u?.selectionEnd??ni.length,m=p===`normal`&&uy(Xi(),a)?dy(a,ni,Xi().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>l(`chat.chatInput.pastedTextReference`,{index:e,count:t}),ly(Xi())):null,h=a?`${a}${/\s$/.test(a)?``:` `}${s}`:s,g=ks(h,ni.slice(0,d),ni.slice(f));if(m){let e=si(d,f,{id:m.id,kind:`paste`,text:m.text,characterCount:m.characterCount,index:m.index,display:m.token},{inlineBoundaries:!0,padDocumentEdges:!0}),t=zs(e.document.text,e.caret),n=`${e.document.text.slice(0,t)}${s}${e.document.text.slice(t)}`;ic(n,t+s.length,t+s.length,Jy(n),s),oc(c,n)}else ac(g,Jy(g)),oc(c,`${ni.slice(0,d)}${g}${ni.slice(f)}`);for(let e=0;e<i.length;e+=1){let t=o[e],n=Ky(i[e],t);Yi.current.add(t);try{await Rn.addAttachment(n)}catch(e){console.error(`Clipboard image attach failed`,e),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.clipboardAttachFailed`))}finally{Yi.current.delete(t)}}},[Rn,mc,zn,nc,Bn,Xi,p,si,dc,ni,Un,ac,l,rc,ic,vi,oc]),gc=Z.useCallback((e,t)=>{let n=e.currentTarget,r=n.selectionStart??0,i=n.selectionEnd??r;if(i<=r)return;let a=F_(r,i,[...Re(ni,zn.filter(Oe).map(e=>e.filename)),...P_(ni,Za.keys()),...Xi().references]),o=a?.start??r,s=a?.end??i,c=ni.slice(o,s),l=U(c);if(!(l===c&&!a))if(e.preventDefault(),e.clipboardData.setData(`text/plain`,l),t===`cut`){let e=`${ni.slice(0,o)}${ni.slice(s)}`;ic(e,o,o),requestAnimationFrame(()=>{xi.current?.setSelectionRange(o,o),nc()})}else a&&(a.start!==r||a.end!==i)&&requestAnimationFrame(()=>{xi.current?.setSelectionRange(o,s)})},[nc,zn,Za,ic,Xi,ni]),_c=Z.useCallback(e=>{gc(e,`copy`)},[gc]),vc=Z.useCallback(e=>{gc(e,`cut`)},[gc]),yc=e=>{let t=xi.current,n=Math.min(t&&document.activeElement===t?t.selectionStart??Ci.current:Ci.current,ni.length),r=ni.substring(0,n).lastIndexOf(`@`),i=e.relativePath&&e.relativePath.trim().length>0?e.relativePath.trim():Ac(e.path)||e.name,a=e.isDirectory?[i]:[],o=Ls(ni,r===-1?n:r,n,`@${i}`);Zi(o.text,[i],a),requestAnimationFrame(()=>{xi.current&&(xi.current.selectionStart=o.caret,xi.current.selectionEnd=o.caret),nc(),rc(o.text,o.caret)}),E(!1),O(``),xi.current?.focus()},bc=e=>{let t=xi.current,n=Math.min(t&&document.activeElement===t?t.selectionStart??Ci.current:Ci.current,ni.length),r=ni.substring(0,n).lastIndexOf(`@`),i=Ls(ni,r===-1?n:r,n,`@${e}`);vi(i.text,t=>Ps(t,{kind:`agent`,value:e,path:e,label:e,range:{start:i.start,end:i.end}})),requestAnimationFrame(()=>{xi.current&&(xi.current.selectionStart=i.caret,xi.current.selectionEnd=i.caret),nc(),rc(i.text,i.caret)}),E(!1),O(``),xi.current?.focus()},xc=q(e=>{Ui.current||(Ui.current=!0,(async()=>{try{let t=J.getState().getAuthoritativeDirectoryForSession(e.id);if(!t){Ii.error(l(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}if(await At(e.id,{directory:t}),!ei(e.id,t)){Ii.error(l(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}Sr([{type:`session`,sessionId:e.id}],t).catch(()=>void 0);let n=Xi(),r=xi.current?.selectionStart??n.text.length,i=n.text.substring(0,r).lastIndexOf(`@`),a=ci().get(e.id)?.title||e.title||e.id,o=i===-1?r:i,s={id:`session:${e.id}:${L()}`,kind:`session`,sessionId:e.id,display:F({trigger:`@`,icon:`chat-thread`,label:a})},c=si(o,r,s,{inlineBoundaries:!0,padDocumentEdges:!0}),u=zs(c.document.text,c.caret);requestAnimationFrame(()=>{xi.current&&(xi.current.selectionStart=u,xi.current.selectionEnd=u),nc(),rc(c.document.text,u)}),E(!1),O(``),xi.current?.focus()}catch{Ii.error(l(`chat.chatInput.toast.sessionReferenceLoadFailed`))}finally{Ui.current=!1}})())}),Q=q(e=>{let t=Xi(),n=xi.current?.selectionStart??t.text.length,r=ys(t.text,n);if(!r)return!1;let i=si(r.start,r.end,e,{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=i.document.references.some(t=>t.id===e.id),o=zs(i.document.text,i.caret);return requestAnimationFrame(()=>{xi.current&&(xi.current.selectionStart=o,xi.current.selectionEnd=o),nc(),rc(i.document.text,o),a&&(j(!1),I(!1))}),xi.current?.focus(),a}),Cc=e=>{Q({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&z(``)},wc=(e,t)=>{let n=xi.current?.selectionStart??ni.length,r=ni.substring(0,n).lastIndexOf(`#`),i=r===-1?n:r,a=`${ni.substring(0,i)}#${t} ${ni.substring(n)}`;vi(a);let o=i+t.length+2;requestAnimationFrame(()=>{xi.current&&(xi.current.selectionStart=o,xi.current.selectionEnd=o),nc(),rc(a,o)}),H(!1),ne(``),xi.current?.focus()},Tc=(e,t=!1)=>{if(!tm(In,e))return;let n=`/${e.name}`;if(!t&&e.isSkill){Q({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&N(``);return}if(!t&&e.source===`opencode`&&!e.isSkill&&e.isBuiltIn!==!0&&Q({id:`command:${e.name}:${L()}`,kind:`command`,commandName:e.name,reference:e.reference??e.name,display:F({trigger:`/`,icon:`command`,label:e.name})})){N(``);return}let r=e.isSkill?` ${n} `:`${n} `,i=Sv(r,new Set([...to,e.name.toLowerCase()]),r.length);ii(i?.text??r);let a=xi.current;if(a&&(a._commandMetadata=e),j(!1),N(``),t){Ns({presetText:n});return}let o=()=>{if(xi.current){try{xi.current.focus({preventScroll:!0})}catch{xi.current.focus()}xi.current.setSelectionRange(xi.current.value.length,xi.current.value.length)}};requestAnimationFrame(()=>{o(),requestAnimationFrame(o)}),setTimeout(o,60)};Z.useEffect(()=>{Bn&&xi.current&&!Lr&&xi.current.focus()},[Bn,Lr]),Z.useEffect(()=>{Lr||ce(null)},[Lr]);let Ec=Rn.abortPrompt.sessionID,Dc=Rn.abortPrompt.clear;Z.useEffect(()=>{Ec&&Ec!==Bn&&Dc()},[Bn,Ec,Dc]),Z.useEffect(()=>{Bi.current=!!(Bn||Un)},[Bn,Un]);let Oc=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 tv(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)},[]),Ac=Z.useCallback(e=>{let t=e.replace(/\\/g,`/`).trim(),n=(ca||``).replace(/\\/g,`/`).replace(/\/+$/,``);if(!n||t===n)return t;let r=`${n}/`;return t.startsWith(r)?t.slice(r.length):t},[ca]),jc=e=>{if(!Oc(e.dataTransfer))return;e.preventDefault(),e.stopPropagation(),ki.current++;let t=e.dataTransfer.types?.includes(`application/x-openchamber-file-path`)??!1;t!==y&&w(t),(Bn||Un)&&!h&&g(!0)},Mc=e=>{Oc(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,(Bn||Un)&&!h&&g(!0))},Nc=e=>{e.preventDefault(),e.stopPropagation(),ki.current--,ki.current<=0&&(ki.current=0,g(!1),w(!1),cc())},Ic=()=>{ki.current=0,g(!1),w(!1),cc()},Lc=async e=>{if(ki.current=0,!Oc(e.dataTransfer)){cc();return}if(e.preventDefault(),e.stopPropagation(),g(!1),!Bn&&!Un)return;let t=e.dataTransfer.getData(`application/x-openchamber-file-path`);if(t&&t!==`.`){let e=`@${t}`,n=xi.current,r=Ji.current;if(n){let t=n.selectionStart??Ci.current,i=n.selectionEnd??t,a=Ls(r,t,i,e);vi(a.text),requestAnimationFrame(()=>{n.selectionStart=a.caret,n.selectionEnd=a.caret,Ci.current=a.caret,n.focus()})}else{let t=Ls(r,r.length,r.length,e);vi(t.text)}cc();return}let n=tb(e.dataTransfer);if(n.length>0){d()&&(zi.current=n),mc(n),d()||cc();return}let r=kc(e.dataTransfer);if(r.length>0){let e=Be(r.map(e=>e.name)),t=ks(e,Ji.current.slice(0,xi.current?.selectionStart??Ji.current.length),Ji.current.slice(xi.current?.selectionEnd??Ji.current.length));ac(t);for(let e of r)try{await Rn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.attachFileFailed`))}}cc()},Rc=e=>{Oc(e.dataTransfer)&&(e.preventDefault(),d()&&(ji.current=!0,lc()))},zc=Z.useRef(null),Bc=Z.useRef(null),Vc=q((e=!0)=>{nt.current=0;let t=()=>{let t=Yp(xi);if(!t||(Xp(xi),!e))return;let n=t.value.length;try{t.setSelectionRange(n,n)}catch{}};t(),window.requestAnimationFrame(t)}),Hc=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=ks(e,Ji.current.slice(0,xi.current?.selectionStart??Ji.current.length),Ji.current.slice(xi.current?.selectionEnd??Ji.current.length));ac(n)}for(let e of t)try{await Rn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.attachFileFailed`))}},[Rn,ac,l]),Uc=Z.useCallback(async()=>{try{let e=await ta?.pickFiles?.(),t=Array.isArray(e?.files)?e.files:[],n=Array.isArray(e?.skipped)?e.skipped:[];if(n.length>0){let e=n.map(e=>`${e?.name||`file`}: ${e?.reason||`skipped`}`).join(`
|
|
6538
|
+
`);Ii.error(l(`chat.chatInput.toast.someFilesSkipped`,{summary:e}))}let r=t.map(e=>{if(!e?.dataUrl)return null;try{let[t,n]=e.dataUrl.split(`,`),r=e.mimeType||t?.match(/data:(.*);base64/)?.[1]||`application/octet-stream`;if(!n)return null;let i=atob(n),a=new Uint8Array(i.length);for(let e=0;e<i.length;e++)a[e]=i.charCodeAt(e);let o=new Blob([a],{type:r});return new File([o],e.name||`file`,{type:r})}catch(e){return console.error(`Failed to decode VS Code picked file`,e),null}}).filter(Boolean);r.length>0&&(Vc(!1),await Hc(r),Vc())}catch(e){console.error(`VS Code file pick failed`,e),Ii.error(e instanceof Error?e.message:l(`chat.chatInput.toast.vscodePickFailed`))}},[Hc,Vc,l,ta]),Wc=Z.useCallback(()=>{if(d()){Uc();return}zc.current?.click()},[Uc]),Gc=Z.useCallback(()=>{if(d()){Uc();return}Bc.current?.click()},[Uc]),Kc=Z.useCallback(async()=>{if(!Pc()){Gc();return}try{let e=await Fc(20);if(e===null){Gc();return}e.length>0&&(Vc(!1),await Hc(e),Vc())}catch(e){console.error(`Native photo pick failed`,e),Ii.error(l(`chat.chatInput.toast.attachFileFailed`))}},[Hc,Vc,Gc,l]),qc=Z.useCallback(async e=>{let t=e.target.files;!t||t.length===0||(Vc(!1),await Hc(t),e.target.value=``,Vc())},[Hc,Vc]),Jc=`gap-x-1.5 gap-y-0`,Yc=d(),Xc=In.kind===`primary`&&Gn&&!Yc,Zc=Z.useMemo(()=>(zt?.selectedProjectId?Qn.find(e=>e.id===zt.selectedProjectId)??null:null)||(er?Qn.find(e=>e.id===er)??null:null)||(Qn[0]??null),[er,zt?.selectedProjectId,Qn]),Qc=Z.useMemo(()=>nb(Zc?.path??null),[Zc?.path]),$c=Zc?rb(Zc):null,el=Is(Qc),tl=Es(e=>Qc?e.directories.get(Qc)?.lastBranchesFetch??0:0),nl=Hs(Qc),rl=!!el?.all,il=Es(e=>e.fetchBranches),[al,ol]=Z.useState(!1);Z.useEffect(()=>{!Xc||!Qc||!ea||nl!==null||fa(Qc,ea,{silent:!0})},[fa,ea,nl,Qc,Xc]),Z.useEffect(()=>{if(!Xc||!Qc||!Zc||!ea||nl!==!0){ol(!1);return}let e=!tl||Date.now()-tl>3e4;if(rl&&!e){ol(!1);return}let t=!1;return ol(!rl),il(Qc,ea).finally(()=>{t||ol(!1)}),()=>{t=!0}},[il,ea,Zc,tl,rl,nl,Qc,Xc]);let sl=Os(Qc),cl=el?.current?.trim()||sl?.trim()||``,ll=Z.useMemo(()=>{if(!Zc)return null;let e=nb(Zc.path);return!e||!cl?null:{value:e,label:cl}},[Zc,cl]),ul=Z.useMemo(()=>{if(!Zc)return[];let e=Qc?rn.get(Qc)??rn.get(Zc.path)??[]:[];return Pr({projectRoot:nb(Zc.path)??``,rootBranch:cl,worktrees:e,pendingBootstrapDirectory:zt?.bootstrapPendingDirectory??null}).filter(e=>e.kind===`worktree`)},[rn,zt?.bootstrapPendingDirectory,Zc,cl,Qc]),dl=Z.useMemo(()=>nb(zt?.bootstrapPendingDirectory??null)??nb(zt?.directoryOverride??null)??Qc,[zt?.bootstrapPendingDirectory,zt?.directoryOverride,Qc]),fl=Z.useMemo(()=>{let e=nb(zt?.bootstrapPendingDirectory??null);return!!(zt?.preserveDirectoryOverride||zt?.pendingWorktreeRequestId||e&&e===dl)},[zt?.bootstrapPendingDirectory,zt?.pendingWorktreeRequestId,zt?.preserveDirectoryOverride,dl]),pl=Z.useMemo(()=>{let e=[];return ll&&e.push(ll),e.push(...ul),!dl||e.some(e=>e.value===dl)||!fl?e:[...e,{value:dl,label:ra(dl)}]},[ll,dl,fl,ul]),ml=Z.useMemo(()=>d_({selectedDirectory:dl,projectRootOption:ll,worktreeOptions:ul}),[ll,dl,ul]),hl=Ph()===`mini-chat`,gl=Z.useMemo(()=>hl||la!==!0||!ua||ua.isClean?!1:wh(ua.files),[ua,la,hl]),_l=Z.useMemo(()=>!dl||ll?.value===dl||ul.some(e=>e.value===dl),[ll?.value,dl,ul]);Z.useEffect(()=>{zt?.open&&(!zt.preserveDirectoryOverride&&!zt.bootstrapPendingDirectory||!dl||!_l||(zt.preserveDirectoryOverride&&J.getState().setDraftPreserveDirectoryOverride(!1),zt.bootstrapPendingDirectory&&J.getState().setDraftBootstrapPendingDirectory(null)))},[zt?.bootstrapPendingDirectory,zt?.open,zt?.preserveDirectoryOverride,_l,dl]);let vl=Z.useMemo(()=>nl!==!0||al?!1:ll?!0:ul.length>0,[al,ll,nl,ul.length]),yl=Z.useCallback(e=>{if(J.getState().newSessionDraft?.pendingWorktreeRequestId)return;let t=Qn.find(t=>t.id===e);t&&(er!==e&&nr(e),tn({projectId:e,directoryOverride:t.path},{force:!0}))},[er,Qn,nr,tn]),bl=Z.useCallback(e=>{J.getState().newSessionDraft?.pendingWorktreeRequestId||Zc&&tn({projectId:Zc.id,directoryOverride:e},{force:!0})},[Zc,tn]),Sl=Z.useCallback(e=>{let t=e.icon?Ea[e.icon]:null,n=e.color?ka[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)(xa,{project:e,className:`size-full object-contain`,fallback:r}):r}),(0,$.jsx)(`span`,{className:`truncate`,children:rb(e)})]})},[]);Z.useEffect(()=>{!Xc||!Zc||!dl||zt?.pendingWorktreeRequestId||zt?.bootstrapPendingDirectory||zt?.preserveDirectoryOverride||pl.some(e=>e.value===dl)||tn({projectId:Zc.id,directoryOverride:Zc.path})},[pl,zt?.bootstrapPendingDirectory,zt?.pendingWorktreeRequestId,zt?.preserveDirectoryOverride,dl,Zc,tn,Xc]);let Cl=Z.useRef(ue);Z.useEffect(()=>{fe===`idle`&&(Cl.current=ue)},[ue,fe]);let wl=q(()=>{ye.current!==null&&(window.clearTimeout(ye.current),ye.current=null)}),Tl=q(()=>{wl(),fe===`collapsing`&&(de(!1),De(`collapsed`),Zr(!1)),pe(`idle`)}),El=q(()=>{wl(),ye.current=window.setTimeout(Tl,240)}),Dl=q(()=>{if(Cl.current){if(Cl.current=!1,tt.current=null,De(`none`),window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches){de(!1),De(`collapsed`),Zr(!1),pe(`idle`);return}pe(`collapsing`),El()}});Z.useEffect(()=>()=>wl(),[wl]);let Ol=q(e=>{if(!(Date.now()<nt.current)){if(Ae(),tt.current=e,Le()&&typeof window<`u`&&window.dispatchEvent(new CustomEvent(`oc:keyboard-intent`,{detail:{open:!0}})),!Cl.current){wl(),Cl.current=!0;let e=typeof window<`u`?window.Capacitor?.getPlatform?.():void 0,t=window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches??!1;if(Le()&&(e===`ios`||e===`android`)){if((0,Sc.flushSync)(()=>{de(!0),De(`full`),pe(t?`idle`:`expanding`)}),!(es&&ge.current===Hl)){let e=Di.current;if(e){let t=Math.max(44,Math.ceil(e.offsetHeight));ge.current=Hl,he(e=>Math.abs(e-t)<=2?e:t)}}t||El()}else Z.startTransition(()=>{de(!0),De(`full`),pe(t?`idle`:`expanding`)}),t||El()}xi.current?.focus({preventScroll:Le()})}}),kl=Z.useCallback(()=>{rt(),Ve(!0),xi.current?.blur()},[rt]),Al=Z.useCallback(()=>{rt(),Ue(!0),xi.current?.blur()},[rt]),jl=Z.useCallback(e=>{if(Ie(e),be.current!==null&&(window.clearTimeout(be.current),be.current=null),e){tt.current=null,Cl.current||(Cl.current=!0,Ae(),de(!0),De(`full`));return}be.current=window.setTimeout(()=>{be.current=null,Cl.current&&document.activeElement!==xi.current&&Dl()},30)},[Dl]);Z.useEffect(()=>{if(!Lr||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=()=>et(eg(t.children));n();let r=new MutationObserver(n);return r.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[$h]}),()=>r.disconnect()},[Lr]);let Ml=$e||!!se||ze||He||ho||_o,Nl=Z.useRef(!1);Nl.current=ho||_o;let Pl=Z.useRef(!1),Fl=Z.useRef(0),Il=Z.useRef(0),Ll=q(()=>{let e=J.getState().stagedMessageEdit;!e||e.sessionId!==Bn||window.setTimeout(()=>{let t=J.getState().stagedMessageEdit,n=document.activeElement,r=Ov({surfaceKind:In.kind,stagedSessionId:t?.sessionId??null,stagedMessageId:t?.messageId??null,blurredMessageId:e.messageId,submitInFlight:fs(),focusHeld:Date.now()<Il.current,overlayOpen:Fl.current>0||Nl.current,focusInsideComposer:n instanceof Element&&!!(n.closest(`[data-composer-content="true"]`)||n.closest(`[data-slot="dropdown-menu-content"]`))||Date.now()<nt.current});r.action===`disarm`&&J.getState().clearStagedMessageEdit(r.sessionId)},0)});Z.useEffect(()=>{if(!Lr||Le()||typeof window>`u`||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=()=>{Fl.current+=1},t=()=>{if(Fl.current=Math.max(0,Fl.current-1),Pl.current){Pl.current=!1;return}if(!at.current||Nl.current||Fl.current>0)return;if(Qa()){at.current=!1;return}at.current=!1,Il.current=Date.now()+600,xi.current?.focus(),document.activeElement===xi.current&&Ne(!0);let e=()=>{let e=xi.current;!e||document.activeElement!==e||(Wl.current??e).scrollIntoView({block:`end`})};xe.current!==null&&(window.clearTimeout(xe.current),xe.current=null),Se.current!==null&&(window.clearTimeout(Se.current),Se.current=null),xe.current=window.setTimeout(()=>{xe.current=null,e()},300),Se.current=window.setTimeout(()=>{Se.current=null,e()},650)};return window.addEventListener(`oc:mobile-overlay-opened`,e),window.addEventListener(`oc:mobile-overlay-closed`,t),()=>{xe.current!==null&&(window.clearTimeout(xe.current),xe.current=null),Se.current!==null&&(window.clearTimeout(Se.current),Se.current=null),window.removeEventListener(`oc:mobile-overlay-opened`,e),window.removeEventListener(`oc:mobile-overlay-closed`,t)}},[Lr]),Z.useEffect(()=>{if(!Lr)return;if(Ml){(Me||Date.now()-it.current<800)&&(at.current=!0);return}if(!at.current)return;let e=window.setTimeout(()=>{if(at.current=!1,Qa())return;let e=xi.current;e&&document.activeElement!==e&&e.focus({preventScroll:Le()})},180);return()=>window.clearTimeout(e)},[Lr,Ml,Me]);let Rl=Me||$e||Fe||!!se||ze||He||We!==null||ho||_o||h,zl=$e||Fe||!!se||ze||He||We!==null||ho||_o||h;Z.useEffect(()=>{if(!Lr||!ue||Rl)return;let e=window.setTimeout(()=>{document.activeElement!==xi.current&&Dl()},250);return()=>window.clearTimeout(e)},[Lr,ue,Rl,Dl]);let Vl=Z.useRef(!1);Vl.current=zl,Z.useEffect(()=>{if(!Lr||Le()||typeof document>`u`)return;let e=document.documentElement;return Me?e.classList.add(`oc-browser-keyboard-open`):(e.classList.remove(`oc-browser-keyboard-open`),window.matchMedia?.(`(display-mode: standalone)`)?.matches&&window.setTimeout(()=>{e.classList.contains(`oc-browser-keyboard-open`)||(window.scrollTo(0,0),document.body.scrollTop=0,e.scrollTop=0)},350)),()=>e.classList.remove(`oc-browser-keyboard-open`)},[Lr,Me]),Z.useEffect(()=>{if(!Lr||typeof window>`u`)return;let e=e=>{let t=e.detail;!t||t.open!==!1||Cl.current&&(Vl.current||(0,Sc.flushSync)(()=>{Dl()}))};return window.addEventListener(`oc:keyboard-intent`,e),()=>window.removeEventListener(`oc:keyboard-intent`,e)},[Lr,Dl]);let Hl=qn?le(qn):In.surfaceID;Z.useLayoutEffect(()=>{if(!Lr||!ue||fe!==`idle`||es&&ge.current===Hl)return;let e=Di.current;if(!e)return;let t=()=>{let t=Math.max(44,Math.ceil(e.offsetHeight));ge.current=Hl,he(e=>e===t?e:t)};t();let n=typeof ResizeObserver==`function`?new ResizeObserver(t):null;return n?.observe(e),()=>n?.disconnect()},[Lr,ue,fe,Hl,es,ae]);let Ul=q(e=>{e.currentTarget===e.target&&e.animationName.startsWith(`oc-mobile-composer-motion-`)&&Tl()});Z.useEffect(()=>{Je(``)},[We]);let Wl=Z.useRef(null);Z.useLayoutEffect(()=>{if(!Lr||!Na||Le())return;let e=window.visualViewport,t=Wl.current,n=xi.current;if(!e||!t)return;document.documentElement.classList.add(`oc-browser-kb-fullscreen`);let r=()=>{let n=Math.max(0,Math.floor(e.offsetTop)),r=document.documentElement.clientHeight;t.style.position=`fixed`,t.style.left=`0`,t.style.right=`0`,t.style.top=`${n}px`,t.style.height=`${Math.floor(Math.min(e.height,r-n))}px`,t.style.zIndex=`40`,t.style.background=`var(--background)`};return r(),e.addEventListener(`resize`,r),e.addEventListener(`scroll`,r),window.addEventListener(`resize`,r),window.addEventListener(`scroll`,r,!0),()=>{e.removeEventListener(`resize`,r),e.removeEventListener(`scroll`,r),window.removeEventListener(`resize`,r),window.removeEventListener(`scroll`,r,!0),document.documentElement.classList.remove(`oc-browser-kb-fullscreen`),t.style.position=``,t.style.left=``,t.style.right=``,t.style.top=``,t.style.height=``,t.style.zIndex=``,t.style.background=``,requestAnimationFrame(()=>{n&&document.activeElement===n&&n.scrollIntoView({block:`nearest`})})}},[Lr,Na]),Z.useLayoutEffect(()=>{if(!Lr||Le()||!Un||Na||!Me)return;let e=window.visualViewport,t=Wl.current;if(!e||!t)return;let n=t.getBoundingClientRect();t.style.position=`fixed`,t.style.left=`${Math.floor(n.left)}px`,t.style.width=`${Math.floor(n.width)}px`,t.style.zIndex=`40`,t.style.background=`var(--background)`;let r=NaN,i=0,a=()=>{let n=document.documentElement.clientHeight,o=e.offsetTop+e.height,s=Math.max(0,Math.floor(Math.min(o,n)-t.offsetHeight));s!==r&&(r=s,t.style.top=`${s}px`),i=requestAnimationFrame(a)};return a(),()=>{cancelAnimationFrame(i),t.style.position=``,t.style.left=``,t.style.width=``,t.style.top=``,t.style.zIndex=``,t.style.background=``}},[Lr,Na,Un,Me]);let Gl=Lr?`px-1.5 py-1.5`:Yc?`px-1.5 py-1`:`px-2.5 py-1.5`,ql=Lr?`h-8 w-8`:Yc?`h-5 w-5`:`h-6 w-6`,Jl=Lr?`h-4 w-4`:Yc?`h-3.5 w-3.5`:`h-4 w-4`,Xl=Lr?`h-6 w-6`:Yc?`h-4 w-4`:`h-5 w-5`,Zl=Lr?`h-[18px] w-[18px]`:Yc?`h-4 w-4`:`h-[18px] w-[18px]`,Ql=Y(`flex cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed`,Np),$l=Y(Ql,ql),eu=(Lr?Me||Ca||Da||se:va||Ca||Da)?`opacity-100`:`opacity-45 hover:opacity-100 focus-within:opacity-100`;Z.useEffect(()=>()=>{mo.current&&=(clearTimeout(mo.current),null)},[]);let tu=Lr?(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)(sb,{onOpenAgentPanel:Ts,onCycleAgent:()=>{rt(),Zs()},agentName:In.selection.value.agent,agents:jr,disabled:Ir}),(0,$.jsx)(cb,{onOpenModel:()=>Ko(`model`),providerID:In.selection.value.providerID,modelID:In.selection.value.modelID,provider:Nr.find(e=>e.id===In.selection.value.providerID),variant:In.selection.value.variant})]}):null,nu=(0,$.jsxs)(`div`,{className:`relative z-10 flex flex-wrap items-center gap-1 px-3 pt-1`,children:[(0,$.jsx)(Fu,{attachments:zn,onShowPopup:zr,onRemoveAttachedFile:sc}),In.kind===`primary`?(0,$.jsx)(zu,{attachedFiles:zn,onAddVSCodeFile:(e,t,n)=>{qn&&Qt(qn,()=>vt.getState()).addVSCodeFile(e,t,n)},onAddVSCodeSelection:(e,t)=>{if(qn)return Qt(qn,()=>vt.getState()).addVSCodeSelection(e,t)}}):null]}),ru=co?.map((e,t)=>(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(R_,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)),iu=Lr?(0,$.jsxs)($.Fragment,{children:[Ce===`collapsed`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{"data-mobile-composer-collapsed-slot":`attach`,"data-composer-action":`true`,className:`composer-mobile-actions flex shrink-0 items-center`,children:(0,$.jsx)(db,{isVSCode:Yc,footerIconButtonClass:$l,iconSizeClass:Zl,handlePickLocalFiles:Wc,handlePickLocalImages:Gc,openIssuePicker:Ds,openPrPicker:Ms,onOpenMobileSheet:kl,onOpenAndroidPickSheet:Pc()?Al:void 0})}),ts?(0,$.jsx)(`div`,{"data-mobile-composer-collapsed-slot":`action`,"data-composer-action":`true`,className:`flex shrink-0 items-center justify-end`,children:(0,$.jsx)(pb,{isMobile:!0,footerIconButtonClass:$l,sendIconSizeClass:Jl,stopIconSizeClass:Xl,canSend:Qo,canAbort:!0,hasContent:!1,currentSessionId:Bn,newSessionDraftOpen:Un,draftSubmitting:Vn,submissionBlocked:a,sendPhase:ls,queueFrozen:Zo,queueFallbackAvailable:ts||es,onPrimaryAction:Fs,onAbort:Xs})}):null]}):null,_e?(0,$.jsxs)(`div`,{className:Y(`w-full min-w-0 items-center gap-x-1.5`,Ce===`full`?`flex`:`hidden`),"data-composer-action":`true`,"aria-hidden":Ce!==`full`||void 0,inert:Ce!==`full`||void 0,children:[(0,$.jsxs)(`div`,{className:`composer-mobile-actions flex shrink-0 items-center gap-x-2 pl-1`,children:[(0,$.jsx)(db,{isVSCode:Yc,footerIconButtonClass:$l,iconSizeClass:Zl,handlePickLocalFiles:Wc,handlePickLocalImages:Gc,openIssuePicker:Ds,openPrPicker:Ms,onOpenSettings:e,onOpenMobileSheet:kl,onOpenAndroidPickSheet:Pc()?Al:void 0}),_r?(0,$.jsx)(fb,{sessionId:Bn,draftOpen:Un,draftEnabled:zt.permissionAutoAcceptEnabled===!0,enabled:sr,saving:Bn?Zt:!1,footerIconButtonClass:$l,iconSizeClass:Zl,onSetDraftEnabled:Jt,onSetSessionEnabled:$t,onOpenSessionFirst:qt,onToggleFailed:vr}):null,(0,$.jsx)(uv,{sessionId:Bn,directory:jt??Kn,draftOpen:Un}),(0,$.jsx)(dv,{length:ni.length})]}),tu,(0,$.jsx)(`div`,{className:`relative z-30 flex shrink-0 items-center justify-end gap-x-1.5`,children:(0,$.jsx)(pb,{isMobile:Lr,footerIconButtonClass:$l,sendIconSizeClass:Jl,stopIconSizeClass:Xl,canSend:Qo,canAbort:ts,hasContent:!!Yo,currentSessionId:Bn,newSessionDraftOpen:Un,draftSubmitting:Vn,submissionBlocked:a,sendPhase:ls,queueFrozen:Zo,queueFallbackAvailable:ts||es,onPrimaryAction:Fs,onAbort:Xs})})]}):null]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center`,Jc),children:[(0,$.jsx)(db,{isVSCode:Yc,footerIconButtonClass:$l,iconSizeClass:Zl,handlePickLocalFiles:Wc,handlePickLocalImages:Gc,openIssuePicker:Ds,openPrPicker:Ms,onOpenSettings:e,withTooltip:!0}),_r?(0,$.jsx)(fb,{sessionId:Bn,draftOpen:Un,draftEnabled:zt.permissionAutoAcceptEnabled===!0,enabled:sr,saving:Bn?Zt:!1,footerIconButtonClass:$l,iconSizeClass:Zl,onSetDraftEnabled:Jt,onSetSessionEnabled:$t,onOpenSessionFirst:qt,onToggleFailed:vr}):null,(0,$.jsx)(uv,{sessionId:Bn,directory:jt??Kn,draftOpen:Un}),(0,$.jsx)(dv,{length:ni.length})]}),(0,$.jsxs)(`div`,{className:Y(`relative z-30 flex flex-1 items-center justify-end md:gap-x-1.5`,Jc),children:[(0,$.jsx)(ab,{className:`min-w-0 flex-1 justify-end`,composerTextareaRef:xi,selectionAdapter:Er}),(0,$.jsx)(ob,{radius:za,isMobile:Lr,footerIconButtonClass:$l,footerPaddingClass:Gl,iconSizeClass:Zl,sendIconSizeClass:Jl,onInsert:Bs,onInsertAndSend:Vs,onContentHeightChange:tc,renderTrigger:!1}),(0,$.jsx)(pb,{isMobile:Lr,footerIconButtonClass:$l,sendIconSizeClass:Jl,stopIconSizeClass:Xl,canSend:Qo,canAbort:ts,hasContent:!!Yo,currentSessionId:Bn,newSessionDraftOpen:Un,draftSubmitting:Vn,submissionBlocked:a,sendPhase:ls,queueFrozen:Zo,queueFallbackAvailable:ts||es,onPrimaryAction:Fs,onAbort:Xs})]})]}),ou=q(()=>{if(Lr){Il.current=Date.now()+600,Ol(`focus`);let e=()=>{xi.current?.focus({preventScroll:Le()}),document.activeElement===xi.current&&Ne(!0)};e(),window.requestAnimationFrame(e);return}let e=()=>{if(!Xp(xi))return;let e=Yp(xi);if(!e)return;let t=e.value.length;try{e.setSelectionRange(t,t)}catch{}};e(),window.requestAnimationFrame(()=>{e(),window.setTimeout(e,0)})}),su=jt??Kn,{goal:lu,enabled:uu}=iv(Bn??``,su),du=(0,$.jsx)(Lf,{onEditMessage:xs,onSendMessage:Cs,onEditCommitted:ou,draftKey:qn,scope:wo,draftTarget:qn?{key:qn,expectedRevision:()=>Rn.getDraft(qn)?.revision??`absent`}:null,clientPendingItems:ms,onRemoveClientPending:e=>{let t=En.getState().removeEstablishingFollowUp(e);t&&(t.content&&ii(t.content),t.attachments.length>0&&Rn.restoreAttachments(t.attachments))},trailing:Bn&&uu&&lu?(0,$.jsx)(lv,{sessionId:Bn,directory:su}):null});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`form`,{ref:Wl,onSubmit:e=>{e.preventDefault(),Fs()},onPointerDownCapture:e=>{if(!Lr)return;let t=e.target;t instanceof Element&&(!Cl.current&&t.closest(`[data-mobile-composer-surface="true"]`)&&Ae(),!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"]`)&&(rt(),e.preventDefault())))},className:Y(`relative w-full pt-0 pb-4`,Ma&&`flex h-full min-h-0 flex-col pt-4`,Na&&`flex h-full min-h-0 flex-col pt-1`,Lr&&`bottom-safe-area oc-mobile-composer`),style:Lr&&Kr>0?{marginBottom:`${Kr}px`}:void 0,children:[Gn&&!Ma&&!Lr&&!Yc&&!hl?(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:ib($c?l(`chat.emptyState.draftTitleWithProject`,{project:$c}):l(`chat.emptyState.draftTitle`),$c)})}):null,(0,$.jsxs)(`div`,{className:Y(`chat-input-column relative overflow-visible`,Ra&&`flex flex-1 min-h-0 flex-col`),children:[(0,$.jsx)(Iu,{attachments:zn,onShowPopup:zr,onRemoveAttachedFile:sc}),(0,$.jsx)(tp,{}),Io&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pb-2`,children:[zo>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:sa?.colors?.surface?.elevated,borderColor:sa?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:l(`chat.chatInput.reviewComments`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:sa?.colors?.status?.info},children:zo}),(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:Vo,"aria-label":l(`chat.chatInput.reviewCommentsRemove`),title:l(`chat.chatInput.reviewCommentsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,Lo>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:sa?.colors?.surface?.elevated,borderColor:sa?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:l(`chat.chatInput.devServerLogs`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:sa?.colors?.status?.info},children:Lo}),(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:()=>Bo(`preview-console`),"aria-label":l(`chat.chatInput.devServerLogsRemove`),title:l(`chat.chatInput.devServerLogsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,Ro>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:sa?.colors?.surface?.elevated,borderColor:sa?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:l(`chat.chatInput.previewAnnotations`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:sa?.colors?.status?.info},children:Ro}),(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:()=>Bo(`preview-annotation`),"aria-label":l(`chat.chatInput.previewContextRemove`),title:l(`chat.chatInput.previewContextRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null]}),yo&&!Yc&&(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:()=>go(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[yo.author?.avatarUrl&&(0,$.jsx)(`img`,{src:yo.author.avatarUrl,alt:yo.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`#`,yo.number,yo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:l(`chat.chatInput.linked.byAuthor`,{author:yo.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:yo.title})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:yo.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":l(`chat.chatInput.linked.issue.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{bo(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":l(`chat.chatInput.linked.issue.removeAria`),title:l(`chat.chatInput.linked.issue.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),xo&&!Yc&&(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:()=>vo(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[xo.author?.avatarUrl&&(0,$.jsx)(`img`,{src:xo.author.avatarUrl,alt:xo.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[l(`chat.chatInput.linked.pr.number`,{number:xo.number}),xo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:l(`chat.chatInput.linked.byAuthor`,{author:xo.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:xo.title}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0 typography-meta`,children:[xo.head,` → `,xo.base]})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:xo.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":l(`chat.chatInput.linked.pr.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{So(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":l(`chat.chatInput.linked.pr.removeAria`),title:l(`chat.chatInput.linked.pr.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),(0,$.jsx)(ub,{sessionId:Bn,directory:jt??Kn}),(0,$.jsx)(lb,{showAbortStatus:pa,showAssistantStatus:!1,showTodos:!0,leftAccessory:Un||!gl?null:(0,$.jsx)(jh,{})}),!Lr&&Xc?(0,$.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[Zc?(0,$.jsxs)(Ta,{value:Zc.id,open:Ze,onValueChange:yl,onOpenChange:e=>{Qe(e),e||Xe(``)},children:[(0,$.jsx)(Ia,{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]`,jp),children:[(0,$.jsx)(ya,{children:Sl(Zc)}),(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)(wa,{fitContent:!0,children:[(0,$.jsx)(La,{autoFocus:!0,value:Ye,onChange:e=>Xe(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:l(`chat.chatInput.draftPicker.searchProjects`),className:`mb-1 h-8 min-w-56`}),Qn.filter(e=>Fa(rb(e),Ye)||Fa(e.path,Ye)).map(e=>(0,$.jsx)(Pa,{value:e.id,className:`max-w-[24rem] truncate`,children:Sl(e)},e.id)),(0,$.jsx)(Sa,{}),(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(),Qe(!1),requestAnimationFrame(()=>Hr.requestDirectoryDialog())},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`chat.chatInput.draftPicker.newProject`)})]})]})]}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-auto min-h-6 cursor-pointer items-center gap-1.5 rounded-lg px-2.5 py-1 typography-micro font-medium text-foreground/80`,jp),onClick:()=>Hr.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`chat.chatInput.draftPicker.newProject`)})]}),Zc&&vl?(0,$.jsx)(v_,{directory:dl,projectDirectory:Qc,label:ml,projectRootOption:ll,worktreeOptions:ul,onSelectDirectory:bl}):null]}):null,Lr&&Xc?(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:[Zc?(0,$.jsx)(`button`,{type:`button`,className:Y(`inline-flex h-[26px] 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`,jp),onClick:()=>Ge(`project`),children:Sl(Zc)}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-[26px] 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`,jp),onClick:()=>Hr.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`chat.chatInput.draftPicker.newProject`)})]}),Zc&&vl?(0,$.jsx)(v_,{directory:dl,projectDirectory:Qc,label:ml,projectRootOption:ll,worktreeOptions:ul,onSelectDirectory:bl,maxWidthClassName:`max-w-[50%]`,presentation:`mobile-sheet`}):null]}):null,(0,$.jsxs)(`div`,{className:Y(!Lr&&`contents`,Lr&&`relative`,Na&&`flex min-h-0 flex-1 flex-col`),children:[du,(0,$.jsxs)(`div`,{className:Y(Lr?`oc-mobile-composer-motion-viewport`:`contents`,Lr&&fe!==`idle`&&`oc-mobile-composer-motion-active`,Lr&&!ue&&fe===`idle`&&`oc-mobile-composer-motion-collapsed`),style:Lr?{"--oc-mobile-composer-stage-height":`${me}px`}:void 0,children:[(0,$.jsxs)(Xg,{value:ni,attachments:[],disabled:!Bn&&!Un||Vn&&!ls.establishing,pending:ts||ls.inFlight&&!ls.establishing,isMobile:Lr,onSubmit:Fs,"data-mobile-composer-surface":Lr?`true`:void 0,"data-mobile-composer-collapsed":Lr&&!ue?`true`:void 0,"data-session-swipe-surface":Lr?`true`:void 0,expanded:Ra,focusedTone:p===`shell`?`info`:`primary`,className:Y(`relative z-10`,h&&`ring-2 ring-primary ring-offset-2`,Ur&&`ring-1 ring-[var(--interactive-selection)] border-[var(--interactive-selection)]`,Lr&&!ue&&`oc-mobile-composer-collapsed`,Lr&&`oc-mobile-composer-surface`,Lr&&fe===`expanding`&&`oc-mobile-composer-motion-expanding`,Lr&&fe===`collapsing`&&`oc-mobile-composer-motion-collapsing`,Lr&&fe!==`idle`&&`oc-mobile-composer-effects-reduced`),style:{borderRadius:za,backgroundColor:sa?.colors?.surface?.subtle},ref:Di,onDropCapture:Rc,onDragEnter:jc,onDragOver:Mc,onDragLeave:Nc,onDrop:Lc,onDragEnd:Ic,onAnimationEnd:Ul,autoResize:!1,disableInputWhilePending:!1,contentClassName:Y(`transition-opacity duration-200`,eu,Ra&&`flex-1 min-h-0`,Lr&&!ue&&`oc-mobile-composer-collapsed-content`),inputHeader:void 0,attachmentContent:Lr&&Ce!==`full`?void 0:nu,highlightedContent:ru,highlightRef:_a,inputRef:xi,textLayoutClassName:Y(Iy,Ra?Y(`h-full min-h-0`,Lr?`py-2.5`:`py-4`):Lr?ue?`py-2.5`:`py-0`:`pt-4 pb-2`,p===`shell`?`font-mono`:`typography-markdown md:typography-ui-label`,Lr&&!ue&&`oc-mobile-composer-collapsed-text`),inputOuterClassName:Y(Ra&&`flex-1 min-h-0`,Lr&&!ue&&`min-h-0 flex-1`),inputStyle:{flex:Ra||Lr&&!ue?`1 1 auto`:`none`,height:Lr&&!ue?`100%`:!Ra&&ae?`${ae.height}px`:void 0,maxHeight:Lr&&!ue?`100%`:!Ra&&ae?`${ae.maxHeight}px`:void 0,borderTopLeftRadius:za,borderTopRightRadius:za},footerClassName:Y(`relative z-30 bg-transparent flex-shrink-0`,Lr&&!ue?`oc-mobile-composer-collapsed-footer px-0 py-0`:Gl,Lr?`flex items-center gap-x-1.5`:Y(`flex items-center justify-between`,Jc)),footerStyle:{borderBottomLeftRadius:za,borderBottomRightRadius:za},footerContent:iu,placeholder:l(Bn||Un?p===`shell`?`chat.chatInput.placeholder.shell`:Ba?`chat.chatInput.placeholder.chatCompact`:`chat.chatInput.placeholder.chat`:`chat.chatInput.placeholder.selectSession`),onChange:(e,t)=>pc(t),textareaProps:{readOnly:Ur,onCompositionStart:()=>{Si.current=!0},onCompositionEnd:e=>{Si.current=!1;let t=e.currentTarget;ic(t.value,t.selectionStart??t.value.length,t.selectionEnd??t.selectionStart??t.value.length)},onBeforeInput:fc,onKeyDown:Ks,onCopy:_c,onCut:vc,onPaste:hc,onDragEnter:jc,onDragOver:Mc,onDropCapture:Rc,onDrop:Lc,onDragEnd:Ic,onKeyUp:Js,onClick:()=>{Lr&&!Cl.current&&Date.now()>=nt.current&&Ol(`focus`),Js()},onScroll:e=>{if(Lr&&!Cl.current){let t=e.currentTarget;t.scrollTop!==0&&(t.scrollTop=0),t.scrollLeft!==0&&(t.scrollLeft=0),_a.current&&(_a.current.style.transform=``);return}Js();let t=e.currentTarget.scrollTop;_a.current&&(_a.current.style.transform=`translateY(-${t}px)`)},onSelect:e=>{let t=e.currentTarget,n=t.selectionStart??0,r=t.selectionEnd??n;if(Si.current){Ci.current=r;return}let i=F_(n,r,[...Re(ni,zn.filter(Oe).map(e=>e.filename)),...P_(ni,Za.keys()),...ti.references]);i&&(i.start!==n||i.end!==r)?(t.setSelectionRange(i.start,i.end),Ci.current=i.end):Ci.current=n,Js()},onFocus:()=>{if(!Lr){ba(!0);return}if(Date.now()<nt.current){let e=xi.current;e&&e.blur();return}Pe.current!==null&&(window.clearTimeout(Pe.current),Pe.current=null),Cl.current?(tt.current=null,Le()&&typeof window<`u`&&window.dispatchEvent(new CustomEvent(`oc:keyboard-intent`,{detail:{open:!0}}))):Ol(`focus`),Ne(!0)},onBlur:e=>{if(Si.current=!1,Ci.current=e.currentTarget.selectionStart??Ci.current,Ll(),!Lr){window.setTimeout(()=>{let e=document.activeElement;if(!(e instanceof Element)){ba(!1);return}e.closest(`[data-composer-content="true"]`)||e.closest(`[data-slot="dropdown-menu-content"]`)||ba(!1)},0);return}if(Date.now()<Il.current){let e=xi.current;if(e){e.focus(),window.setTimeout(()=>{Date.now()<Il.current&&document.activeElement!==e&&e.focus()},50);return}}if(it.current=Date.now(),Le()){Ne(!1);return}Pe.current!==null&&window.clearTimeout(Pe.current),Pe.current=window.setTimeout(()=>{Pe.current=null,Ne(!1)},120)},autoCorrect:Lr?`on`:`off`,autoCapitalize:Lr?`sentences`:`off`,spellCheck:Lr||Yr,fillContainer:Ra||Lr&&!ue,rows:1},children:[(0,$.jsx)(Am,{}),h&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/90`,style:{borderRadius:za},children:(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`inline-flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,className:Ql,onClick:()=>Wc(),title:l(`chat.chatInput.actions.attachFiles`),"aria-label":l(`chat.chatInput.actions.attachFiles`),children:(0,$.jsx)(X,{name:`attachment-2`,className:Y(Zl,`text-current`)})})}),(0,$.jsx)(`p`,{className:`mt-2 typography-ui-label text-muted-foreground`,children:l(y?`chat.chatInput.drop.insertMention`:`chat.chatInput.drop.attachFiles`)})]})}),k&&(0,$.jsx)(bs,{ref:Wi,searchQuery:M,directory:Kn,onCommandSelect:Tc,onClose:()=>j(!1),commandPolicy:e=>tm(In,e),commandContext:Jn,style:Ma&&uo?{left:`${uo.left}px`,top:`${uo.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${uo.left+8}px))`,maxHeight:`${uo.maxHeight}px`,transform:uo.place===`above`?`translateY(-100%)`:void 0}:void 0}),P&&(0,$.jsx)(op,{ref:Gi,searchQuery:R,directory:Kn,onSkillSelect:Cc,onClose:()=>I(!1),style:Ma&&uo?{left:`${uo.left}px`,top:`${uo.top}px`,bottom:`auto`,width:`min(360px, calc(100% - ${uo.left+8}px))`,maxHeight:`${uo.maxHeight}px`,transform:uo.place===`above`?`translateY(-100%)`:void 0}:void 0}),V&&(0,$.jsx)(ws,{ref:Ki,searchQuery:te,onSnippetSelect:wc,onClose:()=>H(!1),style:Ma&&uo?{left:`${uo.left}px`,top:`${uo.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${uo.left+8}px))`,maxHeight:`${uo.maxHeight}px`,transform:uo.place===`above`?`translateY(-100%)`:void 0}:void 0}),T&&(0,$.jsx)(js,{ref:Vi,searchQuery:D,onFileSelect:yc,onAgentSelect:bc,onSessionSelect:xc,onClose:()=>E(!1),style:Ma&&uo?{left:`${uo.left}px`,top:`${uo.top}px`,bottom:`auto`,width:`min(520px, calc(100% - ${uo.left+8}px))`,maxHeight:`${uo.maxHeight}px`,transform:uo.place===`above`?`translateY(-100%)`:void 0}:void 0})]}),Lr?(0,$.jsx)(ob,{radius:za,isMobile:Lr,footerIconButtonClass:$l,footerPaddingClass:Gl,iconSizeClass:Zl,sendIconSizeClass:Jl,onInsert:Bs,onInsertAndSend:Vs,onActiveChange:jl,onContentHeightChange:tc,renderTrigger:!1}):null]})]}),Lr?(0,$.jsx)(ab,{className:`hidden`,composerTextareaRef:xi,selectionAdapter:Er,mobilePanel:se,onMobilePanelChange:ce}):null]}),Un&&!Ma&&!Lr&&!Yc&&!hl?(0,$.jsx)(Ug,{onSubmit:Rs,className:`chat-input-column mt-4`}):null]}),u.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(Ly,{popup:u,onOpenChange:Br,isMobile:Lr})}):null,(0,$.jsx)(bg,{open:ho,onOpenChange:go,mode:`select`,onSelect:e=>{bo(e),So(null)}}),(0,$.jsx)(Cg,{open:_o,onOpenChange:vo,onSelect:e=>{So(e),bo(null)}}),(0,$.jsx)(cu,{open:rr,onOpenChange:ir,projectDirectory:jt??Kn??null,submitting:ar,onConfirm:ja}),(0,$.jsx)(`input`,{ref:zc,type:`file`,multiple:!0,className:`hidden`,onChange:qc,accept:`*/*`}),(0,$.jsx)(`input`,{ref:Bc,type:`file`,multiple:!0,className:`hidden`,onChange:qc,accept:`image/*`}),null,Lr&&He?(0,$.jsx)(Cp,{open:!0,onClose:()=>Ue(!1),title:l(`chat.chatInput.actions.addAttachment`),children:(0,$.jsxs)(`div`,{className:`flex flex-col px-3 pb-4 pt-1`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2.5 rounded-lg px-2 py-3 text-left typography-ui-label hover:bg-[var(--interactive-hover)]`,onClick:()=>{at.current=!1,Ue(!1),requestAnimationFrame(Kc)},children:[(0,$.jsx)(X,{name:`file-image`,className:`h-[18px] w-[18px] flex-shrink-0 text-muted-foreground`}),l(`chat.chatInput.actions.attachPhotos`)]}),(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2.5 rounded-lg px-2 py-3 text-left typography-ui-label hover:bg-[var(--interactive-hover)]`,onClick:()=>{at.current=!1,Ue(!1),requestAnimationFrame(Wc)},children:[(0,$.jsx)(X,{name:`attachment-2`,className:`h-[18px] w-[18px] flex-shrink-0 text-muted-foreground`}),l(`chat.chatInput.actions.attachFiles`)]})]})}):null,Lr&&Xc&&Zc?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(eo,{id:`mobile-draft-project-picker-sheet-${Ke}`,open:We===`project`,onOpenChange:e=>{e||Ge(null)},ariaLabel:l(`chat.chatInput.draftPicker.projectTitle`),closeAriaLabel:l(`mobile.surface.closeAria`),resizeAriaLabel:l(`mobile.sessions.sheet.resizeAria`),children:[(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-2 pt-1`,"data-mobile-sheet-no-dismiss":``,children:(0,$.jsx)(La,{value:qe,onChange:e=>Je(e.target.value),placeholder:l(`chat.chatInput.draftPicker.searchProjects`),className:`h-9`})}),(0,$.jsx)(ma,{outerClassName:`min-h-0 flex-1`,disableHorizontal:!0,children:(0,$.jsx)(`div`,{className:`flex flex-col px-3 pb-2`,children:Qn.filter(e=>Fa(rb(e),qe)||Fa(e.path,qe)).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:()=>{yl(e.id),Ge(null)},children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:Sl(e)}),e.id===Zc.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:()=>{Ge(null),Hr.requestDirectoryDialog()},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:l(`chat.chatInput.draftPicker.newProject`)})]})})]})}):null]})},yb=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)(vb,{...e,surface:i}),t[0]=e,t[1]=i,t[2]=a):a=t[2],a};yb.displayName=`ChatInput`;var bb=Z.memo(yb);function xb(e){return e.preventDefault()}function Sb(e){e.preventDefault()}function Cb(e){return e.preventDefault()}function wb(e){e.pointerType===`touch`&&e.preventDefault()}function Tb(e){e.preventDefault()}function Eb(e){e.pointerType===`touch`&&e.preventDefault()}function Db(){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=()=>go(e=>{r(e),a(!1)}),l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),Z.useEffect(c,l);let u;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=e=>{e||(r(null),a(!1))},e[2]=u):u=e[2];let d=q(u),f;e[3]===d?f=e[4]:(f=()=>(d(!1),!0),e[3]=d,e[4]=f);let p;e[5]!==s||e[6]!==f?(p={id:`image-save-actions`,active:s,layer:`overlay`,onBack:f,surfaceRef:o},e[5]=s,e[6]=f,e[7]=p):p=e[7],No(p);let m;e[8]!==i||e[9]!==t||e[10]!==n?(m=async()=>{if(!(!n||i)){a(!0);try{await uc(n),Ii.success(t(`chat.image.actions.saveSuccess`)),r(null)}catch(e){let n=e;if(n instanceof DOMException&&n.name===`AbortError`){a(!1);return}Ii.error(t(`chat.image.actions.saveFailed`)),a(!1);return}a(!1)}},e[8]=i,e[9]=t,e[10]=n,e[11]=m):m=e[11];let h=q(m);if(!n)return null;let g;e[12]!==t||e[13]!==n.filename?(g=n.filename?.trim()||t(`chat.image.actions.sheetTitle`),e[12]=t,e[13]=n.filename,e[14]=g):g=e[14];let _=g,v;e[15]===t?v=e[16]:(v=Le()?t(`chat.image.actions.saveToPhotos`):t(`chat.image.actions.saveImage`),e[15]=t,e[16]=v);let y=v,b;e[17]===_?b=e[18]:(b=(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:_}),e[17]=_,e[18]=b);let x;e[19]===t?x=e[20]:(x=t(`mobile.surface.closeAria`),e[19]=t,e[20]=x);let S;e[21]===t?S=e[22]:(S=t(`mobile.sessions.sheet.resizeAria`),e[21]=t,e[22]=S);let C;e[23]===h?C=e[24]:(C=()=>{h()},e[23]=h,e[24]=C);let w=i?`loader-4`:`download`,T=i?`size-5 animate-spin`:`size-5`,E;e[25]!==w||e[26]!==T?(E=(0,$.jsx)(X,{name:w,className:T}),e[25]=w,e[26]=T,e[27]=E):E=e[27];let D;e[28]!==y||e[29]!==i||e[30]!==t?(D=i?t(`chat.image.actions.saving`):y,e[28]=y,e[29]=i,e[30]=t,e[31]=D):D=e[31];let O;e[32]===D?O=e[33]:(O=(0,$.jsx)(`span`,{className:`truncate`,children:D}),e[32]=D,e[33]=O);let k;e[34]!==i||e[35]!==C||e[36]!==E||e[37]!==O?(k=(0,$.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto overscroll-contain px-2 pb-2`,children:(0,$.jsxs)(da,{type:`button`,variant:`ghost`,size:`lg`,className:`min-h-12 w-full justify-start gap-3 rounded-lg px-4`,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)(eo,{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 Ob=(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(Et(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]},kb=(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},Ab=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}},jb=e=>e.syncLoading||e.assistantLoading,Mb=e=>e.isMobile&&(e.canLoadEarlier||e.isLoadingOlder),Nb=e=>e.isLoadingOlder,Pb=e=>!e.isMobile&&e.isLoadingOlder,Fb=e=>e.transcriptMessageCount>0||e.pendingUserCount>0||e.historyPrefixCount>0,Ib=e=>e.p0Satisfied||e.hasBusyShell||e.hasImmediateShell||e.hasPaintedTranscript?`pass`:e.prefetchStatus===`loading`||e.syncLoading||e.userRetrying?`hydrating`:e.prefetchStatus===`error`?`load-error`:e.hasRenderableSessionSnapshot?`pass`:`hydrating`,Lb=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}},Rb=e=>({newSessionDraft:e?.features?.newSessionDraft??!e,promptNavigator:e?.features?.promptNavigator??!e,returnToParent:e?.features?.returnToParent??!e}),zb=`text-[13px] leading-4 sm:text-[length:var(--text-micro)] sm:leading-5`,Bb=`relative bottom-safe-area oc-mobile-readonly-prompt-foot`,Vb=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)(Oa,{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},Hb=e=>{let t=(0,Q.c)(42),{t:n}=ot(),r=c(Ub),i=`agentName`in e||`providerId`in e||`modelId`in e||`modelName`in e;if(!i){let e=r&&Bb,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 ${zb}`,children:a}),t[4]=a,t[5]=o);let s;return t[6]!==i||t[7]!==o?(s=(0,$.jsx)(`div`,{className:i,children:o}),t[6]=i,t[7]=o,t[8]=s):s=t[8],s}let a;t[9]===n?a=t[10]:(a=n(`common.unavailable`),t[9]=n,t[10]=a);let o=a,s;t[11]!==e.agentName||t[12]!==o?(s=e.agentName?e.agentName.charAt(0).toUpperCase()+e.agentName.slice(1):o,t[11]=e.agentName,t[12]=o,t[13]=s):s=t[13];let l=s,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&&Bb,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 ${zb}`,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 ${zb}`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 overflow-hidden`,children:[(0,$.jsx)(na,{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)(Vb,{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 Ub(e){return e.isMobile}var Wb=Z.memo(()=>{let e=(0,Q.c)(5),{t}=ot(),{currentTheme:n}=Va(),r=Ki(Gb),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:`text-body-md font-medium text-destructive`,children:t(`chat.emptyState.opencodeUnreachable`)}),(0,$.jsx)(`span`,{className:`text-body-sm`,style:{color:i},children:r.message})]}):(0,$.jsx)(`span`,{className:`text-body-md`,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 Gb(e){return e.error}var Kb=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)}}},qb=de(e=>({planModeEnabled:!1,setPlanModeEnabled:t=>e({planModeEnabled:t})})),Jb=e=>{if(!e?.trim())return null;let t=e.trim();return t.toLowerCase()==="default"?null:Jn(t)},Yb=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?Jb(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)(Oa,{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(${ta(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-none`,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-none 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-none`,r?`px-1 py-px text-[10px]`:`px-1.5 py-0.5 typography-micro`,ta(o).class),children:[(0,$.jsx)(na,{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}),Xb=/(^|\s)\/([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)/g,Zb=/(```[\s\S]*?```|~~~[\s\S]*?~~~)/g,Qb=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),$b=(e,t)=>e.split(Zb).map((e,n)=>n%2==1?e:t(e)).join(``),ex=e=>$b(e,e=>e.replace(/ *\n/g,`
|
|
6539
6539
|
`)),tx=({textContent:e,agentMention:t,skillNames:n,decorateInlineReferences:r=!0})=>{let i=$b(e,Qb);if(r){if(t?.token&&i.includes(t.token)){let e=`[${t.token}](${hs(t.name)})`;i=i.replace(t.token,e)}i=i.replace(Xb,(e,t,r)=>n.has(r)?`${t}[/${r}](${fs(r)})`:e)}return ex(i)},nx=e=>(Xb.lastIndex=0,Xb.test(e)||e.includes(`[skill:`)),rx=e=>e===`markdown`?`markdown`:`plain`,ix=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)},ax=Z.memo(({part:e,messageId:t,agentMention:n,messageParts:r})=>{let i=e,a=i.text,o=typeof a==`string`?a:i.content||i.value||``,[s,l]=Z.useState(!1),[u,d]=Z.useState(!1),f=c(e=>e.userMessageRenderingMode),p=c(e=>e.collapsibleUserMessages),m=os(),h=Wr({directory:m,enabled:nx(o)}),g=Z.useMemo(()=>h.data??[],[h.data]),_=c(e=>e.openContextFile),{t:v}=ot(),y=rx(f),b=p&&!s,x=Z.useRef(null),S=Z.useMemo(()=>new Map(g.map(e=>[e.name,e])),[g]),C=Z.useMemo(()=>Yd(r,o),[r,o]),w=Z.useMemo(()=>{let e=new Map;for(let t of r??[]){if(t.type!==`text`||!Yn(t))continue;let n=t.text;if(typeof n==`string`)for(let t of Nr(n))e.set(t.id,{sessionId:t.id,sessionLabel:t.title||t.id})}if(o.includes(`@`))for(let[t,n]of ci()){let r=typeof n.title==`string`?n.title.trim():``;!r||e.has(t)||(o.includes(`@${r}`)||o.includes(`@${ee}${r}`))&&e.set(t,{sessionId:t,sessionLabel:r})}return Array.from(e.values())},[r,o]),T=q(e=>{let t=S.get(e),n=typeof t?.path==`string`?t.path:``,r=xo(n);if(!r||r===`<built-in>`)return;let i=r.toLowerCase().endsWith(`/skill.md`)?r:`${r}/SKILL.md`,a=m||vo(``,i)||`/`,o=()=>{_(a,i)};if(m&&!wo(i,m)){ss(i,m).then(o);return}o()});Z.useEffect(()=>{let e=x.current;if(!e)return;let t=()=>{p&&!s&&d(e.scrollHeight>e.clientHeight)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[p,o,s]),Z.useEffect(()=>{p||(l(!1),d(!1))},[p]);let E=q(e=>{let t=e.target,n=(t?.closest(`[data-skill-name]`))?.dataset.skillName??ls(t?.closest(`a[href]`)?.getAttribute(`href`));if(n){e.preventDefault(),e.stopPropagation(),T(n);return}let r=x.current;r&&(ix(r)||p&&!s&&u&&l(!0))}),D=q(e=>{e.stopPropagation(),l(!1)}),O=Z.useMemo(()=>Ud(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(()=>tx({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=tx({textContent:e,skillNames:new Set,decorateInlineReferences:!1});return(0,$.jsx)(Po,{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)(Zd,{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(Xb.lastIndex=0;(i=Xb.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:cs(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&&s&&(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`,s&&`pb-3`,y===`plain`&&`whitespace-pre-wrap`,b&&`line-clamp-10`,p&&u&&!s&&`cursor-pointer`),ref:x,onClick:E,children:y===`markdown`?O?j(O):(0,$.jsx)(Po,{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`)}),ox=[{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)(bc.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)(bc.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)(bc.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)(bc.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 sx(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=ox.find(e=>e.variant===a)?.component,t[4]=a,t[5]=o);let s=o||ox[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 cx=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})},lx=new Map,ux=e=>{let t=lx.get(e);if(t)return t;let n={subscribers:new Set,timerId:null};return lx.set(e,n),n},dx=(e,t)=>{let n=ux(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=lx.get(e);n&&(n.subscribers.delete(t),!(n.subscribers.size>0)&&(n.timerId!==null&&typeof window<`u`&&window.clearInterval(n.timerId),lx.delete(e)))}},fx=(e,t)=>{let n=(0,Q.c)(4),r=t===void 0?250:t,[i,a]=Z.useState(px),o,s;return n[0]!==e||n[1]!==r?(o=()=>{if(e)return dx(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 px(){return Date.now()}var mx=e=>e.match(/<task\s+id="([^"]+)"(?:\s+[^>]*)?>/i)?.[1],hx=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},gx=e=>{if(!e||typeof e!=`object`)return;let t=e;return hx(t.sessionId)??hx(t.sessionID)},_x=(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},vx=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},yx=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:hx(e.sessionId)??hx(e.sessionID),status:hx(e.status),summaryEntries:vx(e.summary??e.entries??e.tools??e.calls)}}catch{return{summaryEntries:[]}}},bx=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=yx(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 hx((n?.[1]??r?.[1])||mx(e))},xx=e=>{if(!(!e||typeof e!=`object`))return hx(e.status)},Sx=/"status"\s*:\s*"running"/i,Cx=/\bstatus\s*[:=]\s*["'`]?running\b/i,wx=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]&&Sx.test(t[1])?!0:Cx.test(e)},Tx=/<subagent\s+([^>]*?)>([\s\S]*?)<\/subagent>/i,Ex=(e,t)=>hx(e.match(RegExp(`${t}\\s*=\\s*"([^"]*)"`,`i`))?.[1]),Dx=e=>{if(e===`completed`||e===`error`||e===`cancelled`)return e},Ox=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=e.trim().match(Tx);if(!t)return;let n=Ex(t[1],`sessionID`)??Ex(t[1],`sessionId`),r=Dx(Ex(t[1],`state`));if(!(!n||!r))return{sessionID:n,state:r,description:Ex(t[1],`description`),body:t[2].trim()}},kx=new WeakMap,Ax=e=>{let t=kx.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 kx.set(e,n),n},jx=e=>{let t=[];for(let n of e)t.push(...Ax(n));return t},Mx=e=>e.replace(/\n*<task_metadata>[\s\S]*?<\/task_metadata>\s*$/i,``).trimEnd(),Nx=[`summary`,`changes`,`verification`],Px={summary:`Summary`,changes:`Changes`,verification:`Verification`},Fx=/<(summary|changes|verification)(?:\s[^>]*)?>/i,Ix=()=>RegExp(`<(${Nx.join(`|`)})(?:\\s[^>]*)?>\\s*([\\s\\S]*?)\\s*<\\/\\1>`,`gi`),Lx=e=>typeof e!=`string`||e.length===0?!1:Fx.test(e),Rx=e=>typeof e!=`string`||e.length===0||!e.includes(`<`)||!Lx(e)?e:e.replace(Ix(),(e,t,n)=>{let r=Px[t.toLowerCase()]??t,i=n.trim();return i.length>0?`## ${r}\n\n${i}`:`## ${r}`}).trimEnd(),zx=e=>Rx(Mx(e)),Bx=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 Vx(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 Hx=(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},Ux=e=>{if(!e)return null;let t=e.id;return typeof t==`string`&&t.length>0?t:null},Wx=e=>{let t=e?.state?.status;return typeof t==`string`?t:null},Gx=e=>e?.state,Kx=e=>e?.metadata,qx=e=>{let t=e?.time;return{start:typeof t?.start==`number`?t.start:null,end:typeof t?.end==`number`?t.end:null}},Jx=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,``):``},Yx=(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||Ux(r)!==Ux(i))return!1;if(r.type===`tool`){if(Gx(r)!==Gx(i)||Kx(r)!==Kx(i)||Wx(r)!==Wx(i))return!1;let e=qx(r),t=qx(i);if(e.start!==t.start||e.end!==t.end||r.tool!==i.tool||r.output!==i.output)return!1;continue}let a=qx(r),o=qx(i);if(a.start!==o.start||a.end!==o.end)return!1;if(r.type===`text`||r.type===`reasoning`){if(Jx(r)!==Jx(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},Xx=(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)&&Hx(e.tokens,t.tokens),Zx=(e,t)=>Xx(e.info,t.info)&&Yx(e.parts,t.parts),Qx=(e,t)=>!e||!t?e===t:Zx(e,t),$x=(e,t)=>!e||!t?e===t:e.additions===t.additions&&e.deletions===t.deletions&&e.files===t.files&&e.hasDiffs===t.hasDiffs,eS=(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},tS=(e,t)=>e.id===t.id&&e.messageId===t.messageId&&e.kind===t.kind&&e.partIndex===t.partIndex&&e.endedAt===t.endedAt&&Yx([e.part],[t.part]),nS=(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(!tS(a,o))return!1;r+=1,i+=1}},rS=(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(!tS(e.parts[n],t.parts[n]))return!1;return!0},iS=(e,t)=>!!e?.some(e=>e.anchorMessageId===t),aS=(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(!rS(a,o))return!1;r+=1,i+=1}},oS=(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||!nS(e.activityParts,t.activityParts,n)||!aS(e.activityGroupSegments,t.activityGroupSegments,n))return!1;let a=iS(e.activityGroupSegments,n)||iS(t.activityGroupSegments,n);return!((i||a)&&e.toggleGroup!==t.toggleGroup||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!$x(e.diffStats,t.diffStats)||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!eS(e.changedFiles,t.changedFiles))},sS=/^\*\*\*\s+(?:Begin Patch|End Patch|Add File:|Update File:|Delete File:|Move to:)/m,cS=/^@@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+@@/m,lS=/(?=^diff --git\s+)/gm,uS=/^diff --git\s+/m,dS=/(?=^---\s+\S)/gm,fS=/^---\s+\S/m,pS=e=>typeof e==`object`&&!!e,mS=e=>e.replace(/\r\n/g,`
|
|
6540
6540
|
`).replace(/\r/g,`
|
|
6541
6541
|
`).trim(),hS=e=>{let t=!1;return e.split(`
|
|
@@ -6563,7 +6563,7 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{D as t,E as n,F as r,T
|
|
|
6563
6563
|
|
|
6564
6564
|
`)}let u=l,d;t[8]!==u||t[9]!==n.raw?(d=async()=>{(await ct(u||n.raw)).ok&&(o.current!==null&&window.clearTimeout(o.current),a(!0),o.current=window.setTimeout(()=>{o.current=null,a(!1)},2e3))},t[8]=u,t[9]=n.raw,t[10]=d):d=t[10];let f=q(d),p;t[11]!==n.kind||t[12]!==r?(p=n.kind===`commit`?r(`chat.generatedResult.commit.title`):r(`chat.generatedResult.pullRequest.title`),t[11]=n.kind,t[12]=r,t[13]=p):p=t[13];let m;t[14]===p?m=t[15]:(m=(0,$.jsx)(`span`,{className:`font-mono text-[13px] text-muted-foreground`,children:p}),t[14]=p,t[15]=m);let h;t[16]===f?h=t[17]:(h=()=>{f()},t[16]=f,t[17]=h);let g;t[18]!==i||t[19]!==r?(g=r(i?`chat.generatedResult.actions.copied`:`chat.generatedResult.actions.copy`),t[18]=i,t[19]=r,t[20]=g):g=t[20];let _;t[21]!==i||t[22]!==r?(_=r(i?`chat.generatedResult.actions.copied`:`chat.generatedResult.actions.copy`),t[21]=i,t[22]=r,t[23]=_):_=t[23];let v;t[24]===i?v=t[25]:(v=i?(0,$.jsx)(X,{name:`check`,className:`size-3.5`}):(0,$.jsx)(X,{name:`file-copy`,className:`size-3.5`}),t[24]=i,t[25]=v);let y;t[26]!==v||t[27]!==h||t[28]!==g||t[29]!==_?(y=(0,$.jsx)(da,{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(Nw)}):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 Mw(e){return`- ${e}`}function Nw(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 Pw=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},Fw=e=>{for(let t of Pw(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},Iw=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(Lw,``),h=(u===`live`||d)&&(a===`streaming`||a===`cooldown`);Ie(`ui.assistant_text_part.render`),h&&Ie(`ui.assistant_text_part.render.streaming`);let g=kw({textContent:m,throttledTextContent:Ow({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(!Vn())return;let e=n.type===`text`||n.type===`reasoning`,t=Vi(v.current,{identity:_,content:g,isActive:f&&e,mode:n.type===`reasoning`?`appearance`:`changes`});v.current=t.nextState,!(!t.shouldEmit||!r)&&Ot({sessionID:r,messageID:i,partID:n.id,kind:n.type===`reasoning`?`thinking`:`text`})},b=[g,_,f,i,n.id,n.type,r],t[0]=g,t[1]=_,t[2]=f,t[3]=i,t[4]=n.id,t[5]=n.type,t[6]=r,t[7]=y,t[8]=b):(y=t[7],b=t[8]),Z.useEffect(y,b),Fe(`ui.assistant_text_part.display_len`,g.length);let x=p.time,S=!!(x&&x.end!==void 0);if(n.type!==`text`&&n.type!==`reasoning`||!Aw({displayTextContent:g,isFinalized:S}))return null;let C;t[9]!==g||t[10]!==S||t[11]!==h?(C=!h&&S?Fw(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)(jw,{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)(Fo,{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 Lw(e,t){return t.length>e.length?t:e}var Rw=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,zw=Y(`typography-meta font-medium`,Rw),Bw=Y(`typography-meta`,Rw),Vw=e=>typeof e!=`string`||e.trim().length===0?``:e.split(`
|
|
6565
6565
|
`).map(e=>e.replace(/^>\s?/,``).trimEnd()).filter(e=>e.trim().length>0).join(`
|
|
6566
|
-
`).trim(),Hw=80,Uw=200,Ww={duration:.2,ease:`easeOut`},Gw=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(),Kw=e=>{if(!e)return``;let t=Gw(e).replace(/\s+/g,` `).trim();if(t.length<=Hw)return t;let n=t.lastIndexOf(` `,Hw),r=n>0?n:Hw;return`${t.substring(0,r).trimEnd()}…`},qw=({text:e,variant:t,onContentChange:n,blockId:r,time:i,isStreaming:a=!1,actions:o,defaultExpanded:s})=>{let{t:l}=ot(),u=c(e=>e.isMobile),d=typeof i?.end==`number`,f=a&&!d,[p,m]=Z.useState(()=>s===!0?{expanded:!0,source:`user`}:{expanded:f,source:`auto`}),h=p.source===`auto`?f&&p.expanded:p.expanded,[g,_]=Z.useState(s===!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(()=>Kw(e),[e]),w=l(h?`chat.reasoningTrace.collapseAria`:`chat.reasoningTrace.expandAria`),T=q(()=>{_(!0),m({expanded:!h,source:`user`}),n?.(`structural`)}),E=q(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),T())});if(Z.useLayoutEffect(()=>{m(e=>e.source===`user`||e.expanded===f?e:{expanded:f,source:`auto`})},[f]),Z.useEffect(()=>{e.trim().length!==0&&n?.(`structural`)},[n,e]),Z.useEffect(()=>{if(h||a){_(!0);return}if(!g)return;if(typeof window>`u`){_(!1);return}let e=window.setTimeout(()=>{_(!1)},Uw);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=xc(e,{height:`auto`},Ww);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=xc(e,{height:h?`auto`:`0px`},Ww);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)(Fo,{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`,Ap),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`,zw),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)(US,{isMobile:u,className:`block text-[var(--tools-icon)]`})]}):h?(0,$.jsx)(`span`,{className:zw,style:{color:`var(--tools-title)`},children:l(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}):(0,$.jsx)(`span`,{className:zw,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`,Bw),style:{color:`var(--tools-description)`},children:!a&&!h&&C?(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,Bw),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)(ma,{as:`div`,outerClassName:`max-h-80`,className:`p-0`,useScrollShadow:!0,scrollShadowSize:36,userIntentOnly:!0,children:D})]})}):null]})},Jw=Z.memo(e=>{let t=(0,Q.c)(20),{part:n,onContentChange:r,messageId:i,streamPhase:a}=e,o=c(Yw),s=n,l=s.text||s.content||``,u;t[0]===l?u=t[1]:(u=Vw(l),t[0]=l,t[1]=u);let d=u,f=s.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 _=Ow(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(!Vn())return;let e=Vi(y.current,{identity:v,content:_,isActive:x,mode:`appearance`});y.current=e.nextState,!(!e.shouldEmit||!b)&&Ot({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)(qw,{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 Yw(e){return e.chatRenderMode}var Xw=(e,t)=>{let n=bo(e,t)||xo(t);return n?wo(n,e)?{kind:`diff`,path:yo(n,e)||t}:{kind:`file`,path:n,notice:`turn-diff-outside-workspace`}:{kind:`diff`,path:t}},Zw=e=>{let t=c.getState(),n=Xw(e.directory,e.filePath);if(n.kind===`file`){ss(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)},Qw=Z.memo(e=>{let t=(0,Q.c)(35),{activityParts:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(null),s=Z.useRef(null),l=Qm(),u=Te($w),d=l.directory||u,f=Hs(d),p;if(t[0]!==n||t[1]!==f){bb0:{if(f!==!1){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[3]=e):e=t[3],p=e;break bb0}if(!n||n.length===0){let e;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[4]=e):e=t[4],p=e;break bb0}let e=[];for(let t of n){let n=t.part;n.type===`tool`&&vh.has(n.tool)&&e.push(n)}if(e.length===0){let e;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[5]=e):e=t[5],p=e;break bb0}p=Sh(e)}t[0]=n,t[1]=f,t[2]=p}else p=t[2];let m=p;if(m.length===0)return null;let h;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{let e=s.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=c.getState();Zw({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)(Ra,{asChild:!0,children:(0,$.jsx)(ge,{render:(0,$.jsxs)(`button`,{ref:s,type:`button`,className:`flex items-center gap-1 text-sm text-muted-foreground/60 hover:text-muted-foreground tabular-nums`,"aria-label":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)(za,{children:[b,` changed in this turn`]}),t[19]=b,t[20]=E);let D;t[21]!==T||t[22]!==E?(D=(0,$.jsxs)(Ba,{children:[T,E]}),t[21]=T,t[22]=E,t[23]=D):D=t[23];let O=a||void 0,k;t[24]!==m||t[25]!==d||t[26]!==v?(k=(0,$.jsx)(ve,{side:`top`,align:`start`,sideOffset:4,collisionPadding:8,children:(0,$.jsx)(he,{style:Ah,className:`${kh} transition-all duration-150 ease-out data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95`,children:(0,$.jsx)(Oh,{files:m,currentDirectory:d,onOpenFile:v})})}),t[24]=m,t[25]=d,t[26]=v,t[27]=k):k=t[27];let A;t[28]!==O||t[29]!==k?(A=(0,$.jsx)(Se,{container:O,children:k}),t[28]=O,t[29]=k,t[30]=A):A=t[30];let j;return t[31]!==r||t[32]!==D||t[33]!==A?(j=(0,$.jsxs)(_e,{open:r,onOpenChange:i,children:[D,A]}),t[31]=r,t[32]=D,t[33]=A,t[34]=j):j=t[34],j});Qw.displayName=`TurnChangedFilesDropdown`;function $w(e){return e.currentDirectory}var eT=e=>e.type===`tool`&&e.metadata?.providerExecuted===!0,tT=e=>{if(e.type!==`tool`)return!1;let t=e.state;return t?.status===`error`&&t.metadata?.interrupted===!0},nT=e=>e.type!==`tool`||eT(e)?!1:!tT(e),rT=e=>{let t=0;for(let n of e)nT(n)&&(t+=1);return t},iT=(e,t)=>e===`stop`&&rT(t)===0,aT=e=>{if(e.type!==`text`||e.synthetic===!0)return!1;let t=e.text;return typeof t==`string`&&t.trim().length>0},oT=(e,t,n)=>{if(n||!iT(e,t))return!1;for(let e of t)if(aT(e))return!0;return!1},sT=e=>e===`streaming`||e===`cooldown`,cT=e=>e.finish===`stop`||e.isMessageCompleted?`completed`:e.activeStreamingPhase??`streaming`,lT=e=>e.error||e.isLastAssistantInTurn===!1?!1:iT(e.finish,e.parts)?!0:sT(e.streamPhase)?typeof e.finish!=`string`||e.finish===`stop`:!1,uT=e=>sT(e.streamPhase)?lT(e):!1,dT=3e4,fT=new Map,pT=new Map;async function mT(e){let t=Date.now(),n=fT.get(e);if(n&&t-n.checkedAt<dT)return n.available;let r=pT.get(e);if(r)return r;let i=(async()=>{try{let t=await V(`/api/tts/status`);if(!t.ok)return fT.set(e,{available:!1,checkedAt:Date.now()}),!1;let n=!!(await t.json()).available;return fT.set(e,{available:n,checkedAt:Date.now()}),n}catch{return fT.set(e,{available:!1,checkedAt:Date.now()}),!1}finally{pT.delete(e)}})();return pT.set(e,i),i}var hT=null;function gT(){return hT||=new(window.AudioContext||window.webkitAudioContext),hT}function _T(e={}){let n=e.enabled??!0,r=e.availabilityMode??`auto`,[i,a]=(0,Z.useState)(!1),[o,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=Ei(e=>e.currentProviderId),h=Ei(e=>e.currentModelId),g=Ei(e=>e.openaiApiKey),_=Ei(e=>e.openaiCompatibleUrl),v=Ei(e=>e.openaiCompatibleApiKey),y=(0,Z.useCallback)(async()=>{let e=++p.current,i=t(),a=n=>(e===p.current&&t()===i&&c(n),n);if(!n)return a(!1);let o=!!(g&&g.trim().length>0),s=!!(_&&_.trim().length>0);if(r===`openai-compatible`)return a(s);if(o||r===`auto`&&s)return a(!0);try{return a(await mT(i))}catch{return a(!1)}},[r,n,g,_]);(0,Z.useEffect)(()=>{y()},[y]),(0,Z.useEffect)(()=>s(()=>{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}a(!1)},[]),x=(0,Z.useCallback)(async()=>{try{let e=gT();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=gT();r.state===`suspended`&&await r.resume();let i=r.createBuffer(1,1,22050),o=r.createBufferSource();o.buffer=i,o.connect(r.destination),o.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&&(a(!1),d.current=null,f.current=null,t?.onEnd?.())},a(!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),a(!1),d.current&&=(d.current.onended=null,null),f.current=null}},[b,m,h,g,v]);return(0,Z.useEffect)(()=>()=>{b()},[b]),{isPlaying:i,isAvailable:o,error:l,speak:S,stop:b,checkAvailability:y,unlockAudio:x}}var vT=3e4,yT=null,bT=null;async function xT(){return yT&&Date.now()-yT.checkedAt<vT?yT:bT||(bT=(async()=>{try{let e=await V(`/api/tts/say/status`);if(!e.ok){let e={available:!1,voices:[],checkedAt:Date.now()};return yT=e,e}let t=await e.json(),n={available:!!t.available,voices:Array.isArray(t.voices)?t.voices:[],checkedAt:Date.now()};return yT=n,n}catch{let e={available:!1,voices:[],checkedAt:Date.now()};return yT=e,e}finally{bT=null}})(),bT)}var ST=null;function CT(){return ST||=new(window.AudioContext||window.webkitAudioContext),ST}function wT(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=CT();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 xT();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=CT();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 TT(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 ET=600,DT=`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 OT(e,t){try{let n=await V(`/api/small-model/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prompt:e,system:DT,...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 kT(){let[e,t]=(0,Z.useState)(!1),n=Ei(e=>e.voiceProvider),r=Ei(e=>e.speechRate),i=Ei(e=>e.speechPitch),a=Ei(e=>e.speechVolume),o=Ei(e=>e.sayVoice),s=Ei(e=>e.localTtsVoiceId),c=Ei(e=>e.browserVoice),l=Ei(e=>e.openaiVoice),u=Ei(e=>e.openaiCompatibleVoice),d=Ei(e=>e.openaiCompatibleUrl),f=Ei(e=>e.openaiCompatibleTtsModel),p=Ei(e=>e.showMessageTTSButtons),m=Ei(e=>e.ttsInputMode),h=n===`openai`||n===`openai-compatible`,g=p&&h,_=p&&n===`say`,{speak:v,stop:y,isAvailable:b}=_T({enabled:g,availabilityMode:n===`openai-compatible`?`openai-compatible`:`openai`}),{speak:x,stop:S,isAvailable:C}=wT({enabled:_}),{speak:w,stop:T}=to(),E=(0,Z.useCallback)(()=>{t(!1),y(),S(),T(),ao.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>=ET){let{currentProviderId:t,currentModelId:n}=Ei.getState(),r=await OT(e,{providerID:t||void 0,modelID:n||void 0});r&&(p=r)}let g=m===`raw`&&h,_=TT(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 ao.waitForVoices(),await ao.resumeAudioContext(),await ao.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 AT=(e,t)=>{let n=t.trim().replace(/^[-*+]\s+/,``).slice(0,_t);if(!n)return e;let r=e.trimEnd();return r?`${r}\n${n}`:n},jT=8,MT=280,NT=null;kr(()=>{typeof window<`u`&&window.getSelection()?.removeAllRanges(),NT&&(0,Sc.flushSync)(NT)});var PT=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(`.`)),FT=e=>e.replace(/\r\n?/g,`
|
|
6566
|
+
`).trim(),Hw=80,Uw=200,Ww={duration:.2,ease:`easeOut`},Gw=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(),Kw=e=>{if(!e)return``;let t=Gw(e).replace(/\s+/g,` `).trim();if(t.length<=Hw)return t;let n=t.lastIndexOf(` `,Hw),r=n>0?n:Hw;return`${t.substring(0,r).trimEnd()}…`},qw=({text:e,variant:t,onContentChange:n,blockId:r,time:i,isStreaming:a=!1,actions:o,defaultExpanded:s})=>{let{t:l}=ot(),u=c(e=>e.isMobile),d=typeof i?.end==`number`,f=a&&!d,[p,m]=Z.useState(()=>s===!0?{expanded:!0,source:`user`}:{expanded:f,source:`auto`}),h=p.source===`auto`?f&&p.expanded:p.expanded,[g,_]=Z.useState(s===!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(()=>Kw(e),[e]),w=l(h?`chat.reasoningTrace.collapseAria`:`chat.reasoningTrace.expandAria`),T=q(()=>{_(!0),m({expanded:!h,source:`user`}),n?.(`structural`)}),E=q(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),T())});if(Z.useLayoutEffect(()=>{m(e=>e.source===`user`||e.expanded===f?e:{expanded:f,source:`auto`})},[f]),Z.useEffect(()=>{e.trim().length!==0&&n?.(`structural`)},[n,e]),Z.useEffect(()=>{if(h||a){_(!0);return}if(!g)return;if(typeof window>`u`){_(!1);return}let e=window.setTimeout(()=>{_(!1)},Uw);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=xc(e,{height:`auto`},Ww);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=xc(e,{height:h?`auto`:`0px`},Ww);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)(Fo,{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`,Ap),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`,zw),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)(US,{isMobile:u,className:`block text-[var(--tools-icon)]`})]}):h?(0,$.jsx)(`span`,{className:zw,style:{color:`var(--tools-title)`},children:l(t===`justification`?`chat.reasoningTrace.justification`:`chat.reasoningTrace.thinking`)}):(0,$.jsx)(`span`,{className:zw,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`,Bw),style:{color:`var(--tools-description)`},children:!a&&!h&&C?(0,$.jsx)(`span`,{className:Y(`min-w-0 truncate`,Bw),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)(ma,{as:`div`,outerClassName:`max-h-80`,className:`p-0`,useScrollShadow:!0,scrollShadowSize:36,userIntentOnly:!0,children:D})]})}):null]})},Jw=Z.memo(e=>{let t=(0,Q.c)(20),{part:n,onContentChange:r,messageId:i,streamPhase:a}=e,o=c(Yw),s=n,l=s.text||s.content||``,u;t[0]===l?u=t[1]:(u=Vw(l),t[0]=l,t[1]=u);let d=u,f=s.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 _=Ow(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(!Vn())return;let e=Vi(y.current,{identity:v,content:_,isActive:x,mode:`appearance`});y.current=e.nextState,!(!e.shouldEmit||!b)&&Ot({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)(qw,{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 Yw(e){return e.chatRenderMode}var Xw=(e,t)=>{let n=bo(e,t)||xo(t);return n?wo(n,e)?{kind:`diff`,path:yo(n,e)||t}:{kind:`file`,path:n,notice:`turn-diff-outside-workspace`}:{kind:`diff`,path:t}},Zw=e=>{let t=c.getState(),n=Xw(e.directory,e.filePath);if(n.kind===`file`){ss(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)},Qw=Z.memo(e=>{let t=(0,Q.c)(35),{activityParts:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(null),s=Z.useRef(null),l=Qm(),u=Te($w),d=l.directory||u,f=Hs(d),p;if(t[0]!==n||t[1]!==f){bb0:{if(f!==!1){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[3]=e):e=t[3],p=e;break bb0}if(!n||n.length===0){let e;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[4]=e):e=t[4],p=e;break bb0}let e=[];for(let t of n){let n=t.part;n.type===`tool`&&vh.has(n.tool)&&e.push(n)}if(e.length===0){let e;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[5]=e):e=t[5],p=e;break bb0}p=Sh(e)}t[0]=n,t[1]=f,t[2]=p}else p=t[2];let m=p;if(m.length===0)return null;let h;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>{let e=s.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=c.getState();Zw({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)(Ra,{asChild:!0,children:(0,$.jsx)(ge,{render:(0,$.jsxs)(`button`,{ref:s,type:`button`,className:`flex items-center gap-1 text-sm text-muted-foreground/60 hover:text-muted-foreground tabular-nums`,"aria-label":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)(za,{children:[b,` changed in this turn`]}),t[19]=b,t[20]=E);let D;t[21]!==T||t[22]!==E?(D=(0,$.jsxs)(Ba,{children:[T,E]}),t[21]=T,t[22]=E,t[23]=D):D=t[23];let O=a||void 0,k;t[24]!==m||t[25]!==d||t[26]!==v?(k=(0,$.jsx)(ve,{side:`top`,align:`start`,sideOffset:4,collisionPadding:8,children:(0,$.jsx)(he,{style:Ah,className:`${kh} transition-all duration-150 ease-out data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95`,children:(0,$.jsx)(Oh,{files:m,currentDirectory:d,onOpenFile:v})})}),t[24]=m,t[25]=d,t[26]=v,t[27]=k):k=t[27];let A;t[28]!==O||t[29]!==k?(A=(0,$.jsx)(Se,{container:O,children:k}),t[28]=O,t[29]=k,t[30]=A):A=t[30];let j;return t[31]!==r||t[32]!==D||t[33]!==A?(j=(0,$.jsxs)(_e,{open:r,onOpenChange:i,children:[D,A]}),t[31]=r,t[32]=D,t[33]=A,t[34]=j):j=t[34],j});Qw.displayName=`TurnChangedFilesDropdown`;function $w(e){return e.currentDirectory}var eT=e=>e.type===`tool`&&e.metadata?.providerExecuted===!0,tT=e=>{if(e.type!==`tool`)return!1;let t=e.state;return t?.status===`error`&&t.metadata?.interrupted===!0},nT=e=>e.type!==`tool`||eT(e)?!1:!tT(e),rT=e=>{let t=0;for(let n of e)nT(n)&&(t+=1);return t},iT=(e,t)=>e===`stop`&&rT(t)===0,aT=e=>{if(e.type!==`text`||e.synthetic===!0)return!1;let t=e.text;return typeof t==`string`&&t.trim().length>0},oT=(e,t,n)=>{if(n||!iT(e,t))return!1;for(let e of t)if(aT(e))return!0;return!1},sT=e=>e===`streaming`||e===`cooldown`,cT=e=>e.finish===`stop`||e.isMessageCompleted?`completed`:e.activeStreamingPhase??`streaming`,lT=e=>e.error||e.isLastAssistantInTurn===!1?!1:iT(e.finish,e.parts)?!0:!sT(e.streamPhase)||typeof e.finish==`string`&&e.finish!==`stop`?!1:rT(e.parts)===0,uT=e=>sT(e.streamPhase)?lT(e):!1,dT=3e4,fT=new Map,pT=new Map;async function mT(e){let t=Date.now(),n=fT.get(e);if(n&&t-n.checkedAt<dT)return n.available;let r=pT.get(e);if(r)return r;let i=(async()=>{try{let t=await V(`/api/tts/status`);if(!t.ok)return fT.set(e,{available:!1,checkedAt:Date.now()}),!1;let n=!!(await t.json()).available;return fT.set(e,{available:n,checkedAt:Date.now()}),n}catch{return fT.set(e,{available:!1,checkedAt:Date.now()}),!1}finally{pT.delete(e)}})();return pT.set(e,i),i}var hT=null;function gT(){return hT||=new(window.AudioContext||window.webkitAudioContext),hT}function _T(e={}){let n=e.enabled??!0,r=e.availabilityMode??`auto`,[i,a]=(0,Z.useState)(!1),[o,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=Ei(e=>e.currentProviderId),h=Ei(e=>e.currentModelId),g=Ei(e=>e.openaiApiKey),_=Ei(e=>e.openaiCompatibleUrl),v=Ei(e=>e.openaiCompatibleApiKey),y=(0,Z.useCallback)(async()=>{let e=++p.current,i=t(),a=n=>(e===p.current&&t()===i&&c(n),n);if(!n)return a(!1);let o=!!(g&&g.trim().length>0),s=!!(_&&_.trim().length>0);if(r===`openai-compatible`)return a(s);if(o||r===`auto`&&s)return a(!0);try{return a(await mT(i))}catch{return a(!1)}},[r,n,g,_]);(0,Z.useEffect)(()=>{y()},[y]),(0,Z.useEffect)(()=>s(()=>{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}a(!1)},[]),x=(0,Z.useCallback)(async()=>{try{let e=gT();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=gT();r.state===`suspended`&&await r.resume();let i=r.createBuffer(1,1,22050),o=r.createBufferSource();o.buffer=i,o.connect(r.destination),o.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&&(a(!1),d.current=null,f.current=null,t?.onEnd?.())},a(!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),a(!1),d.current&&=(d.current.onended=null,null),f.current=null}},[b,m,h,g,v]);return(0,Z.useEffect)(()=>()=>{b()},[b]),{isPlaying:i,isAvailable:o,error:l,speak:S,stop:b,checkAvailability:y,unlockAudio:x}}var vT=3e4,yT=null,bT=null;async function xT(){return yT&&Date.now()-yT.checkedAt<vT?yT:bT||(bT=(async()=>{try{let e=await V(`/api/tts/say/status`);if(!e.ok){let e={available:!1,voices:[],checkedAt:Date.now()};return yT=e,e}let t=await e.json(),n={available:!!t.available,voices:Array.isArray(t.voices)?t.voices:[],checkedAt:Date.now()};return yT=n,n}catch{let e={available:!1,voices:[],checkedAt:Date.now()};return yT=e,e}finally{bT=null}})(),bT)}var ST=null;function CT(){return ST||=new(window.AudioContext||window.webkitAudioContext),ST}function wT(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=CT();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 xT();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=CT();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 TT(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 ET=600,DT=`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 OT(e,t){try{let n=await V(`/api/small-model/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prompt:e,system:DT,...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 kT(){let[e,t]=(0,Z.useState)(!1),n=Ei(e=>e.voiceProvider),r=Ei(e=>e.speechRate),i=Ei(e=>e.speechPitch),a=Ei(e=>e.speechVolume),o=Ei(e=>e.sayVoice),s=Ei(e=>e.localTtsVoiceId),c=Ei(e=>e.browserVoice),l=Ei(e=>e.openaiVoice),u=Ei(e=>e.openaiCompatibleVoice),d=Ei(e=>e.openaiCompatibleUrl),f=Ei(e=>e.openaiCompatibleTtsModel),p=Ei(e=>e.showMessageTTSButtons),m=Ei(e=>e.ttsInputMode),h=n===`openai`||n===`openai-compatible`,g=p&&h,_=p&&n===`say`,{speak:v,stop:y,isAvailable:b}=_T({enabled:g,availabilityMode:n===`openai-compatible`?`openai-compatible`:`openai`}),{speak:x,stop:S,isAvailable:C}=wT({enabled:_}),{speak:w,stop:T}=to(),E=(0,Z.useCallback)(()=>{t(!1),y(),S(),T(),ao.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>=ET){let{currentProviderId:t,currentModelId:n}=Ei.getState(),r=await OT(e,{providerID:t||void 0,modelID:n||void 0});r&&(p=r)}let g=m===`raw`&&h,_=TT(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 ao.waitForVoices(),await ao.resumeAudioContext(),await ao.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 AT=(e,t)=>{let n=t.trim().replace(/^[-*+]\s+/,``).slice(0,_t);if(!n)return e;let r=e.trimEnd();return r?`${r}\n${n}`:n},jT=8,MT=280,NT=null;kr(()=>{typeof window<`u`&&window.getSelection()?.removeAllRanges(),NT&&(0,Sc.flushSync)(NT)});var PT=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(`.`)),FT=e=>e.replace(/\r\n?/g,`
|
|
6567
6567
|
`),IT=e=>FT(e).trim(),LT=(e,t)=>{if(e.contains(t))return!0;let n=t instanceof ShadowRoot?t:t.getRootNode();return n instanceof ShadowRoot&&e.contains(n.host)},RT=e=>{let t=[],n=e=>{for(let r of e.querySelectorAll(`*`))r.shadowRoot&&(t.push(r.shadowRoot),n(r.shadowRoot))};return n(e),t},zT=(e,t)=>{let n=RT(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),LT(t,e.commonAncestorContainer))return e}if(e.rangeCount===0)return null;let i=e.getRangeAt(0);return LT(t,i.commonAncestorContainer)?i:null},BT=e=>e.replace(/\s+/g,` `).trim(),VT=e=>{if(e.nodeType===Node.TEXT_NODE)return BT(e.textContent||``);if(e.nodeType!==Node.ELEMENT_NODE)return``;let t=e,n=t.tagName.toLowerCase(),r=Array.from(t.childNodes).map(e=>VT(e)).join(``).replace(/\s+/g,` `).trim();if(!r&&n!==`br`)return``;if(n===`br`)return`
|
|
6568
6568
|
`;if(n===`strong`||n===`b`)return`**${r}**`;if(n===`em`||n===`i`)return`*${r}*`;if(n===`code`)return`\`${r.replace(/`/g,"\\`")}\``;if(n===`a`){let e=t.getAttribute(`href`);return e?`[${r}](${e})`:r}return r},HT=(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=>VT(e)).join(``).replace(/\s+/g,` `).trim();return i?`${r}${i}`:``}).filter(Boolean).join(`
|
|
6569
6569
|
`),UT=e=>{if(e.nodeType===Node.TEXT_NODE)return IT(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${FT(e?.textContent||t.textContent||``).replace(/\n$/,``)}\n\`\`\``}if(n===`code`){let e=FT(t.textContent||``).trim();return e?`\`${e.replace(/`/g,"\\`")}\``:``}if(n===`ul`)return HT(t,!1);if(n===`ol`)return HT(t,!0);if(n===`blockquote`)return IT(Array.from(t.childNodes).map(e=>UT(e)).join(`
|
|
@@ -6573,12 +6573,12 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{D as t,E as n,F as r,T
|
|
|
6573
6573
|
|
|
6574
6574
|
`):IT(Array.from(t.childNodes).map(e=>VT(e)).join(``))},WT=e=>Array.from(e.childNodes).every(e=>{if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return!0;let t=e;return!PT.has(t.tagName.toLowerCase())}),GT=(e,t)=>{let n=e.cloneContents();if(WT(n)){let e=IT(Array.from(n.childNodes).map(e=>VT(e)).join(``));if(e)return e}return Array.from(n.childNodes).map(e=>UT(e)).filter(e=>e.length>0).join(`
|
|
6575
6575
|
|
|
6576
|
-
`).trim()||IT(t)},KT=({containerRef:e})=>{let{t}=ot(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),[o,s]=Z.useState(``),l=Z.useRef(!1),[u,f]=Z.useState(!1),[p,m]=Z.useState(!1),h=Z.useRef(null),g=Z.useRef(MT),_=Z.useRef(null),v=Z.useRef(null),y=Z.useRef(null),b=Z.useRef(!1),x=J(e=>e.createSession),S=J(e=>e.currentSessionId),C=vt(e=>e.setPendingInputText),w=c(e=>e.isMobile),T=qi(e=>e.projects),E=J(e=>e.availableWorktreesByProject),D=os(),O=Mi(),k=$m(Qm()).textSelectionMutation;Z.useEffect(()=>{b.current=n.show},[n.show]),Z.useEffect(()=>()=>{v.current!==null&&(window.cancelAnimationFrame(v.current),v.current=null),y.current!==null&&(window.clearTimeout(y.current),y.current=null)},[]);let A=Z.useCallback(()=>{_.current=null,NT===A&&(NT=null),b.current&&=(v.current!==null&&(window.cancelAnimationFrame(v.current),v.current=null),f(!1),r(e=>({...e,show:!1})),a(``),s(``),!1)},[]);Z.useEffect(()=>()=>{NT===A&&(NT=null)},[A]);let j=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=g.current/2,r=jT+n,i=t-jT-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),M=Z.useCallback(()=>{if(!_.current)return;NT!==A&&(NT?.(),NT=A);let{plainText:e,markdownText:t,rect:i}=_.current,o=!n.show,c=w?i.left+i.width/2:j(i.left+i.width/2),l=i.top-10;a(e),s(t),r({x:c,y:l,show:!0}),b.current=!0,o&&(f(!0),v.current!==null&&window.cancelAnimationFrame(v.current),v.current=window.requestAnimationFrame(()=>{f(!1),v.current=null}))},[j,A,w,n.show]);Z.useLayoutEffect(()=>{if(!n.show||w||!h.current)return;let e=h.current.offsetWidth;!Number.isFinite(e)||e<=0||e===g.current||(g.current=e,r(e=>({...e,x:j(e.x)})))},[j,w,n.show]),Z.useEffect(()=>{if(!n.show||w)return;let e=()=>{r(e=>({...e,x:j(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[j,w,n.show]);let N=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){l.current||A();return}let r=IT(t.toString());if(!r){l.current||A();return}let i=zT(t,n);if(!i){l.current||A();return}let a=i.getBoundingClientRect();_.current={plainText:r,markdownText:GT(i,r),rect:a},l.current||M()},[e,A,M]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{l.current=!0,A()},r=()=>{l.current=!1,y.current!==null&&window.clearTimeout(y.current),y.current=window.setTimeout(()=>{y.current=null,N()},10)},i=new Set,a=()=>{for(let e of RT(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,N))};a();let o=new MutationObserver(a);o.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,N),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let s=e=>{h.current&&!h.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&A()};return document.addEventListener(`mousedown`,s),()=>{y.current!==null&&(window.clearTimeout(y.current),y.current=null),o.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,N);document.removeEventListener(`selectionchange`,N),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,s)}},[e,N,A,M]);let P=Z.useCallback(e=>{if(!e)return;let t=`\`\`\`md\n${e}\n\`\`\``;C(t,`append`),A(),window.getSelection()?.removeAllRanges()},[C,A]),F=Z.useCallback(()=>{P(o)},[P,o]);Z.useEffect(()=>{let t=t=>{if(!k||!t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||t.key.toLowerCase()!==`i`)return;let n=window.getSelection(),r=e.current;if(!n||!r||!n.toString().trim())return;let i=zT(n,r);i&&(t.preventDefault(),P(GT(i,n.toString())))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[P,k,e]);let I=Z.useCallback(async()=>{i&&(await x(void 0,null,null)&&C(i,`replace`),A(),window.getSelection()?.removeAllRanges())},[i,x,C,A]),L=Z.useCallback(async()=>{if(!i)return;let e=await ct(i);e.ok||console.error(`Failed to copy:`,e.error),A(),window.getSelection()?.removeAllRanges()},[i,A]),R=Z.useMemo(()=>S?O.find(e=>e.id===S)??null:null,[S,O]),z=Z.useMemo(()=>{let e=D??(typeof R?.directory==`string`?R.directory:``),t=Zi(T,E,e);return t?{id:t.id,path:t.path}:null},[E,R?.directory,D,T]),B=Z.useCallback(async()=>{if(!i||!z){z||Ii.error(t(`chat.textSelection.toast.noProject`));return}try{m(!0);let e=await vn(o||i,S),n=await zt(z),r=AT(n.notes,e);if(!await Kn(z,{notes:r,todos:n.todos})){Ii.error(t(`chat.textSelection.toast.addToNotesFailed`));return}window.dispatchEvent(new CustomEvent(`openchamber:project-notes-updated`,{detail:{projectId:z.id}})),Ii.success(t(`chat.textSelection.toast.addToNotesSuccess`)),A(),window.getSelection()?.removeAllRanges()}catch(e){let n=e instanceof Error?e.message:void 0;Ii.error(t(`chat.textSelection.toast.addToNotesFailed`),n?{description:n}:void 0)}finally{m(!1)}},[z,S,A,i,o,t]);return n.show?w?(0,Sc.createPortal)((0,$.jsx)(`div`,{ref:h,className:Y(`fixed left-3 right-3 bottom-0 z-50 mx-auto max-w-[420px]`,`rounded-2xl border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] p-2 shadow-lg`,`safe-area-bottom`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),style:{bottom:`calc(0.5rem + env(safe-area-inset-bottom, 0px))`},children:(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[k?(0,$.jsxs)(`button`,{onClick:F,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--primary-base)] text-[var(--primary-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.addToChat`)})]}):null,k?(0,$.jsxs)(`button`,{onClick:I,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.newSession`)})]}):null,(0,$.jsxs)(`button`,{onClick:L,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.copy`)})]}),k&&!d()?(0,$.jsxs)(`button`,{onClick:B,disabled:p,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80 disabled:opacity-60 disabled:cursor-not-allowed`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.saveInsightToNotes`),type:`button`,children:[p?(0,$.jsx)(X,{name:`loader-4`,className:`h-5 w-5 flex-shrink-0 animate-spin`}):(0,$.jsx)(X,{name:`booklet`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.addToNotes`)})]}):null]})}),document.body):(0,Sc.createPortal)((0,$.jsx)(`div`,{ref:h,className:`fixed z-50`,style:{left:n.x,top:n.y,transform:`translate(-50%, -100%)`},children:(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1 whitespace-nowrap`,`rounded-lg border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] shadow-none`,`px-1.5 py-1`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),children:[k?(0,$.jsxs)(`button`,{onClick:F,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.addToChat`)}),(0,$.jsx)(pp,{shortcut:`⌘+I`})]}):null,k?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,k?(0,$.jsxs)(`button`,{onClick:I,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.newSession`)})]}):null,k?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{onClick:L,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.copy`)})]}),k&&!d()?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}),(0,$.jsxs)(`button`,{onClick:B,disabled:p,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)] disabled:opacity-60 disabled:cursor-not-allowed`,`transition-colors duration-150`),title:t(`chat.textSelection.title.saveInsightToNotes`),type:`button`,children:[p?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`booklet`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.addToNotes`)})]})]}):null]})}),document.body):null},qT=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),JT=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),qT(e,n)},YT=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),XT=(e,t)=>{if(!YT(e))return``;let n=new Date(e),r=new Date,i=lo(n,t),a=st(),o=lt.getState().dictionary;if(qT(n,r))return i;if(JT(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}`},ZT=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,QT=e=>e,$T=e=>{if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let n of e){let e=QT(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},eE=(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-$T(n);return!Number.isFinite(a)||a<=0?null:a},tE=e=>{let t=eE(e.createdAt,e.completedAt,e.parts,e.fallbackDurationMs);if(t===null)return null;let n=ZT(e.outputTokens)+ZT(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},nE=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`},rE=e=>{let t=(0,Q.c)(20),{text:n,active:r,className:i}=e,a=Z.useRef(n),[o,s]=Z.useState(n),[c,l]=Z.useState(null),u,d;t[0]!==r||t[1]!==n?(u=()=>{if(n===a.current)return;let e=a.current;if(a.current=n,!r||e.length===0){l(null),s(n);return}l(e),s(n)},d=[r,n],t[0]=r,t[1]=n,t[2]=u,t[3]=d):(u=t[2],d=t[3]),Z.useEffect(u,d);let f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>{l(null)},t[4]=f):f=t[4];let p=q(f),m;t[5]===i?m=t[6]:(m=Y(`oc-summary-flip-viewport relative block h-5 min-h-0 w-full min-w-0 max-w-full overflow-clip sm:h-6`,i),t[5]=i,t[6]=m);let h=c&&`invisible`,g;t[7]===h?g=t[8]:(g=Y(`block h-full min-w-0 truncate leading-5 sm:leading-6`,h),t[7]=h,t[8]=g);let _;t[9]!==o||t[10]!==g?(_=(0,$.jsx)(`span`,{className:g,children:o}),t[9]=o,t[10]=g,t[11]=_):_=t[11];let v;t[12]!==o||t[13]!==p||t[14]!==c?(v=c?(0,$.jsxs)(`span`,{className:`oc-summary-flip-stage absolute inset-0 block overflow-clip`,children:[(0,$.jsx)(`span`,{className:`oc-summary-flip-out absolute inset-x-0 top-0 block h-full truncate`,"aria-hidden":`true`,children:c}),(0,$.jsx)(`span`,{className:`oc-summary-flip-in absolute inset-x-0 top-0 block h-full truncate`,onAnimationEnd:p,children:o})]}):null,t[12]=o,t[13]=p,t[14]=c,t[15]=v):v=t[15];let y;return t[16]!==m||t[17]!==_||t[18]!==v?(y=(0,$.jsxs)(`span`,{className:m,children:[_,v]}),t[16]=m,t[17]=_,t[18]=v,t[19]=y):y=t[19],y},iE=[`search`,`read`,`list`];function aE(e){let t=aC(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function oE(e){let t={read:0,search:0,list:0};for(let n of e){let e=aE(n);e&&(t[e]+=1)}return t}function sE(e){return iC(e)}function cE(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!tC(e.toolName):e.kind!=null||e.type!=null}function lE(e,t,n){for(let r=t;r<e.length;r+=1)if(cE(n(e[r])))return!0;return!1}function uE(e){return`parts`in e?e.parts.some(e=>sE(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>sE(e))}function dE(e,t,n){let r=[],i=t;for(;i<e.length&&tC(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var fE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,pE=({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??uE({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=oE(u.map(e=>e.tool)),p=iE.filter(e=>f[e]>0).map(e=>{let t=f[e];return o(e===`search`?t===1?`chat.contextGroup.searchSingle`:`chat.contextGroup.searchPlural`:e===`read`?t===1?`chat.contextGroup.readSingle`:`chat.contextGroup.readPlural`:t===1?`chat.contextGroup.listSingle`:`chat.contextGroup.listPlural`,{count:t})}).join(`, `),m=q(()=>{c(e=>!e)}),h=q(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),m())}),g=o(s?`chat.contextGroup.collapseAria`:`chat.contextGroup.expandAria`),_=o(d?`chat.contextGroup.exploring`:`chat.contextGroup.explored`),v=t?`h-5`:`h-6`;return(0,$.jsxs)(`div`,{"data-component":`context-tool-group`,className:kp(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":s,"aria-controls":l,"aria-label":g,"data-mobile-press-feedback":`soft`,className:Y(`flex w-full min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,Ap),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)(US,{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,fE,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,fE),style:{color:`var(--tools-description)`},children:(0,$.jsx)(rE,{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 mE(e,t,n){let r=[],i=t;for(;i<e.length&&nC(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var hE=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function gE(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=hE(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=hE(e.name);if(t)return t;let r=hE(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=hE(n.output.name);if(e)return e}return null}function _E(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 vE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,yE=({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=>iC(e)),{joinedVisible:l,hiddenCount:u}=_E(s.map(gE)),d=u>0?r(`chat.skillGroup.summaryOverflow`,{names:l,count:u}):l,f=q(()=>{a(e=>!e)}),p=q(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),f())}),m=r(i?`chat.skillGroup.collapseAria`:`chat.skillGroup.expandAria`),h=r(`chat.tools.display.skill`);return(0,$.jsxs)(`div`,{"data-component":`skill-tool-group`,className:kp(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":i,"aria-controls":o,"aria-label":m,"data-mobile-press-feedback":`soft`,className:Y(`flex w-full min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,Ap),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)(US,{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`,vE,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`,vE),style:{color:`var(--tools-description)`},children:(0,$.jsx)(rE,{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]})},bE=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:s}=e,l=c(xE),u=n,d=typeof u.text==`string`?u.text:``,f=typeof u.content==`string`?u.content:``,p=f.length>d.length?f:d,m=u.time,h=n.sessionID,g=o===void 0||o!==`completed`,_,v;if(t[0]!==i||t[1]!==p?(_=()=>{p.trim().length!==0&&i?.(`structural`)},v=[i,p],t[0]=i,t[1]=p,t[2]=_,t[3]=v):(_=t[2],v=t[3]),Z.useEffect(_,v),!p||p.trim().length===0)return null;let y=o??`streaming`,b=g&&typeof m?.end!=`number`,x;t[4]!==l||t[5]!==r||t[6]!==i||t[7]!==s||t[8]!==n||t[9]!==h||t[10]!==y||t[11]!==b?(x=(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(Iw,{part:n,sessionId:h,messageId:r,streamPhase:y,chatRenderMode:l,hasStreamingHapticLifecycle:b,onContentChange:i,onShowPopup:s})}),t[4]=l,t[5]=r,t[6]=i,t[7]=s,t[8]=n,t[9]=h,t[10]=y,t[11]=b,t[12]=x):x=t[12];let S;t[13]===a?S=t[14]:(S=a?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:a})}):null,t[13]=a,t[14]=S);let C;return t[15]!==x||t[16]!==S?(C=(0,$.jsxs)(`div`,{"data-message-text-export-root":`true`,children:[x,S]}),t[15]=x,t[16]=S,t[17]=C):C=t[17],C});function xE(e){return e.chatRenderMode}var SE=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},CE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,wE=Y(`typography-meta font-medium`,CE),TE=Y(`typography-meta`,CE),EE=[],DE=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},OE=e=>{let t=new Set;for(let n of e)DE(n)&&n.messageId&&t.add(n.messageId);return[...t]},kE=(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}),AE=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=$o(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},jE=e=>e,ME=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},NE=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},PE=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},FE=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},IE=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=FE(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`}`},LE=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=IE(n.todos);if(e)return e}if(Array.isArray(r)){let e=IE(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=IE(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=IE(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=IE(e.todos);if(t)return t}}catch{}return null},RE=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)},zE=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(sx,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,TE),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`,TE),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)(sx,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},BE=e=>{let t=xo(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},VE=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 gE(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`?LE(e):ME(e)},HE=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}},UE=Z.memo(e=>{let t=(0,Q.c)(16),{activity:n,isExpanded:r,isMobile:i,onToggleTool:a,onShowPopup:o,onContentChange:s}=e,c;t[0]!==n.id||t[1]!==a?(c=()=>{a(n.id)},t[0]=n.id,t[1]=a,t[2]=c):c=t[2];let l=q(c),u;t[3]===i?u=t[4]:(u=kp(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)(gw,{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&&Yx([e.activity.part],[t.activity.part])),WE=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=kp(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(qE,{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&&KE(e.activities,t.activities)),GE=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!Pt(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(tC(i)){let r=dE(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:lE(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(nC(i)){let r=mE(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($S(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(QS(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(eC(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},KE=(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||!Yx([r.part],[i.part]))return!1}return!0},qE=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=ot(),s=c(ZE),l=ts(n,o),u;t[0]===n?u=t[1]:(u=cx(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(Ao),h=_h(),g=Te(QE),_=Qm(),v=_.kind===`embedded`?_.directory:g,y;t[4]===n?y=t[5]:(y=n.toLowerCase(),t[4]=n,t[5]=y);let b=y===`skill`,x;t[6]===b?x=t[7]:(x={enabled:b},t[6]=b,t[7]=x);let S=Wr(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($E)),t[10]=w,t[11]=T);let E=T,D=r[0]??null,O=!D||iC(D.part),k;t[12]===D?k=t[13]:(k=D?VE(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||PE(D);if(!e||e===`<built-in>`){j=null;break bb0}let r=BE(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=NE(D);if(!e){N=null;break bb1}let n=yo(e,v);if(!n){N=null;break bb1}let r;t[26]===D?r=t[27]:(r=RE(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=bo(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(!wo(n,v)){ss(n,v).then(()=>{let e=c.getState(),r=v||vo(v,n);if(t&&Number.isFinite(t)){e.openContextFileAtLine(r,n,Math.max(1,Math.trunc(t)),1);return}e.openContextFile(r,n)});return}let r=c.getState(),i=vo(v,n);if(t&&Number.isFinite(t)){r.openContextFileAtLine(i,n,Math.max(1,Math.trunc(t)),1);return}r.openContextFile(i,n)},t[32]=v,t[33]=h,t[34]=m,t[35]=F):F=t[35];let I=q(F),L;t[36]!==v||t[37]!==h?(L=e=>{let t=xo(e);if(!t)return;let n=()=>{if(h){h.openFile({path:t});return}let e=c.getState(),n=v||vo(``,t);e.openContextFile(n,t)};if(v&&!wo(t,v)){ss(t,v).then(n);return}n()},t[36]=v,t[37]=h,t[38]=L):L=t[38];let R=q(L),z;t[39]===n?z=t[40]:(z=n.toLowerCase(),t[39]=n,t[40]=z);let B=z,V=B===`grep`||B===`search`||B===`find`||B===`ripgrep`||B===`glob`,H=B===`webfetch`||B===`fetch`||B===`curl`||B===`wget`,U=B===`skill`,W=!!(P||M),ee=!!(P&&v||M),G;t[41]!==ee||t[42]!==I||t[43]!==R||t[44]!==W||t[45]!==P||t[46]!==M?(G=()=>{if(!(!W||!ee)){if(P){I(P.path,P.offset);return}M&&R(M.path)}},t[41]=ee,t[42]=I,t[43]=R,t[44]=W,t[45]=P,t[46]=M,t[47]=G):G=t[47];let K=q(G),te;t[48]===K?te=t[49]:(te=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),K())},t[48]=K,t[49]=te);let ne=q(te),re=W&&ee&&`cursor-pointer`,ie=W&&!ee&&`cursor-default opacity-70`,ae;t[50]!==re||t[51]!==ie?(ae=Y(`flex w-full items-center gap-x-1.5 min-w-0`,Ap,re,ie),t[50]=re,t[51]=ie,t[52]=ae):ae=t[52];let oe=W?`soft`:void 0,se=W?K:void 0,ce=W?ne:void 0,le=W?`button`:void 0,ue=W&&ee?0:void 0,de=W&&!ee?!0:void 0,fe=i?`size-4`:`size-3.5`,pe;t[53]===fe?pe=t[54]:(pe=Y(`inline-flex items-center justify-center flex-shrink-0`,fe),t[53]=fe,t[54]=pe);let me;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(me={color:`var(--tools-icon)`},t[55]=me):me=t[55];let he=O?(0,$.jsx)(US,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:l})}):d,ge;t[56]!==pe||t[57]!==me||t[58]!==he?(ge=(0,$.jsx)(`div`,{className:pe,style:me,children:he}),t[56]=pe,t[57]=me,t[58]=he,t[59]=ge):ge=t[59];let _e,ve;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(_e=Y(wE,`inline-flex items-center flex-shrink-0 opacity-85`),ve={color:`var(--tools-title)`},t[60]=_e,t[61]=ve):(_e=t[60],ve=t[61]);let ye;t[62]===l?ye=t[63]:(ye=(0,$.jsx)(`span`,{className:_e,style:ve,title:l,children:l}),t[62]=l,t[63]=ye);let be;t[64]!==a||t[65]!==p||t[66]!==P||t[67]!==s?(be=p&&P?(0,$.jsxs)(`span`,{className:Y(`inline-flex !min-h-0 items-center justify-start gap-1 min-w-0 flex-1 text-left`,TE),style:{color:`var(--tools-description)`},title:P.offset?`${P.displayPath}:${P.offset}`:P.displayPath,children:[s?(0,$.jsx)(Au,{filePath:P.path,className:`h-3.5 w-3.5`}):null,zE(P.displayPath,a)]}):null,t[64]=a,t[65]=p,t[66]=P,t[67]=s,t[68]=be):be=t[68];let xe;t[69]!==a||t[70]!==A||t[71]!==V?(xe=V&&A?(0,$.jsx)(`span`,{className:`inline-flex min-w-0 flex-1`,children:(0,$.jsxs)(sx,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,TE),style:{color:`var(--tools-description)`},title:A,children:[`"`,A,`"`]})}):null,t[69]=a,t[70]=A,t[71]=V,t[72]=xe):xe=t[72];let Se;t[73]!==A||t[74]!==H?(Se=H&&A?(0,$.jsxs)(`a`,{href:A,target:`_blank`,rel:`noopener noreferrer`,onClick:eD,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`,TE),style:{color:`var(--status-info)`},title:A,children:[(0,$.jsx)(AE,{href:A}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:A})]}):null,t[73]=A,t[74]=H,t[75]=Se):Se=t[75];let Ce;t[76]!==U||t[77]!==M?(Ce=U&&M?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,TE),style:{color:`var(--tools-description)`},title:M.path,children:M.name}):null,t[76]=U,t[77]=M,t[78]=Ce):Ce=t[78];let we;t[79]!==A||t[80]!==U||t[81]!==M?(we=U&&!M&&A?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,TE),style:{color:`var(--tools-description)`},title:A,children:A}):null,t[79]=A,t[80]=U,t[81]=M,t[82]=we):we=t[82];let Ee;t[83]!==a||t[84]!==A||t[85]!==H||t[86]!==p||t[87]!==V||t[88]!==U?(Ee=!p&&!V&&!H&&!U&&A?(0,$.jsx)(sx,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,TE),style:{color:`var(--tools-description)`},children:A}):null,t[83]=a,t[84]=A,t[85]=H,t[86]=p,t[87]=V,t[88]=U,t[89]=Ee):Ee=t[89];let De;return t[90]!==ae||t[91]!==oe||t[92]!==se||t[93]!==ce||t[94]!==le||t[95]!==ue||t[96]!==de||t[97]!==ge||t[98]!==ye||t[99]!==be||t[100]!==xe||t[101]!==Se||t[102]!==Ce||t[103]!==we||t[104]!==Ee?(De=(0,$.jsxs)(`div`,{className:ae,"data-mobile-press-feedback":oe,onClick:se,onKeyDown:ce,role:le,tabIndex:ue,"aria-disabled":de,children:[ge,ye,be,xe,Se,Ce,we,Ee]}),t[90]=ae,t[91]=oe,t[92]=se,t[93]=ce,t[94]=le,t[95]=ue,t[96]=de,t[97]=ge,t[98]=ye,t[99]=be,t[100]=xe,t[101]=Se,t[102]=Ce,t[103]=we,t[104]=Ee,t[105]=De):De=t[105],De},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&KE(e.activities,t.activities)),JE=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)(Jw,{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}),YE=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)(bE,{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}),XE=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(),_=os()??``,v=Z.useMemo(()=>OE(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?SE(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(()=>HE(e),[e]),M=T?j.active:j.all,N=M.slice(0,c?2:3),P=q((e=!1,n=!1)=>{if(!(!_||!v.length)){for(let r of v){let i=t.find(e=>e.messageId===r)?.part.sessionID;if(!i)continue;let a=Fr(_,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=Ji(_,i,r,{priority:n?`background`:`user`}).catch(()=>{x.current.add(r)}).finally(()=>{b.current.delete(r),S(e=>e+1)});b.current.set(r,o)}S(e=>e+1)}}),F=q(e=>{e.stopPropagation(),P(!0)}),I=q(()=>{let e=C.current;w.current=e?{top:e.getBoundingClientRect().top,scrollContainer:e.closest(`[data-scrollbar="chat"]`)}:null,n||P(),s()});Z.useEffect(()=>{T||!n||P(!1,!0)},[T,n]),Z.useLayoutEffect(()=>{let e=w.current,t=C.current;if(!e||!t)return;let n=()=>{if(!t.isConnected)return;let n=t.getBoundingClientRect().top-e.top;if(!(Math.abs(n)<.5)){if(e.scrollContainer?.isConnected){e.scrollContainer.scrollTop+=n;return}window.scrollBy(0,n)}};if(n(),typeof window>`u`||typeof window.requestAnimationFrame!=`function`){w.current=null;return}let r=window.requestAnimationFrame(()=>{n(),w.current=null});return()=>window.cancelAnimationFrame(r)},[n]);let L=m&&!n?Math.max(0,Math.floor(r)):0,R=!m||n||L>0,z=y.current,B=[...z].map(e=>{if(b.current.has(e))return`loading`;if(x.current.has(e))return`error`;let n=t.find(t=>t.messageId===e)?.part.sessionID??``;return Fr(_,n,e).status}),V=B.includes(`loading`),H=B.includes(`error`),U=B.length>0&&B.every(e=>e===`ready`),W=t.some(e=>z.has(e.messageId)&&DE(e)),ee=U&&!W&&!kE(t,z),G=Z.useMemo(()=>R?jE(e):EE,[e,R]),K=Z.useMemo(()=>R?GE(G):[],[R,G]),te=Z.useMemo(()=>n||L===0?0:Math.max(0,K.length-L),[n,L,K.length]),ne=Z.useMemo(()=>n||L===0?K:K.slice(-L),[n,L,K]);if(!m&&K.length===0)return null;let re=(e,t)=>{let n=(0,$.jsx)(`div`,{className:kp(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},ie=R?ne.map((e,t)=>{switch(e.type){case`reasoning`:return re(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(JE,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return re(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(YE,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(UE,{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)(WE,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(pE,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(qE,{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)(yE,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(qE,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(UE,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,ae=ne.length>0;return m?(0,$.jsxs)(`div`,{className:kp(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`,Ap,c&&`pr-0`),"data-mobile-press-feedback":`soft`,onClick:I,"aria-expanded":n,"aria-label":g(n?`chat.activity.collapseAria`:`chat.activity.expandAria`),children:[(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 flex-1 items-center overflow-clip`,c?`gap-x-1`:`gap-x-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,c?`h-5 w-4`:`h-6 w-3.5`),style:{color:`var(--tools-icon)`},children:T&&!O?(0,$.jsx)(US,{isMobile:c,label:A,className:`block`}):(0,$.jsx)(X,{name:k,className:`h-[14px] w-[14px]`})}),(0,$.jsx)(`span`,{className:Y(`inline-flex flex-shrink-0 items-center`,c?`typography-meta h-5`:`typography-ui-label h-5 font-semibold`,T?`animate-text-shimmer text-[var(--status-info)] [--oc-text-shimmer-base:var(--status-info)]`:`text-foreground/85`),children:A}),E?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 tabular-nums text-muted-foreground`,children:E}):null]}),(0,$.jsxs)(`span`,{className:Y(`ml-auto inline-flex max-w-[min(14rem,55%)] shrink-0 items-center justify-end`,c?`gap-0.5`:`gap-1`),children:[M.length>0?(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center text-muted-foreground`,c?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5`,"aria-hidden":`true`,children:N.map((e,t)=>(0,$.jsx)(na,{name:e,size:c?12:14,className:Y(`flex-none`,c?`size-3 min-h-3 min-w-3 max-h-3 max-w-3`:`size-3.5 min-h-3.5 min-w-3.5 max-h-3.5 max-w-3.5`)},`${e}-${t}`))}),(0,$.jsx)(`span`,{className:`typography-meta min-w-0 truncate`,children:g(T?`chat.activity.agentsWorking`:`chat.activity.agentsInvolved`,{count:M.length})})]}):null,(0,$.jsx)(X,{name:n?`arrow-down-s`:`arrow-right-s`,className:Y(`flex-shrink-0 text-muted-foreground opacity-70`,c&&`-mr-0.5`,c?`size-3`:`size-3.5`)})]})]}),ae?(0,$.jsxs)(`div`,{className:`relative ml-2 pl-3`,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-px bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),te>0?(0,$.jsxs)(`button`,{type:`button`,onClick:I,className:`typography-meta leading-4 px-2 py-1 text-muted-foreground/45 hover:text-muted-foreground/65 text-left`,children:[`+`,te,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:ie})]}):null,n&&(V||H||ee)?(0,$.jsx)(`div`,{className:Y(`typography-meta ml-5 flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,H&&`text-[var(--status-error)]`),role:H?`alert`:`status`,children:V?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{children:g(`chat.activity.outputLoading`)})]}):H?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:g(`chat.activity.outputLoadFailed`)}),(0,$.jsx)(da,{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:kp(c),children:ie})});function ZE(e){return e.showToolFileIcons}function QE(e){return e.currentDirectory}function $E(e){return[e.name,e]}function eD(e){e.stopPropagation()}var tD=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(XE,{...e}),t[0]=e,t[1]=n),n}),nD={contain:`layout`},rD={containerType:`inline-size`,containerName:`message-footer`},iD=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,aD=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,oD=`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`,sD=`size-3.5!`,cD=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,lD=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,uD=`flex items-center gap-2`,dD=`flex items-center gap-2 text-muted-foreground`,fD=`inline-flex h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,pD=`size-3.5!`,mD=`medium`,hD=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,gD=`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)]`,_D=`h-7 gap-1.5`,vD=`h-6 gap-1`,yD=`text-[11px] leading-none`,bD=`size-3.5`,xD=`size-3`,SD=5,CD=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)(Au,{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=hD(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}),wD=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=ot(),s;t[0]!==n.file||t[1]!==a?(s=()=>{a(n.file)},t[0]=n.file,t[1]=a,t[2]=s):s=t[2];let c=q(s),l=!r,u=i?vD:_D,d;t[3]===u?d=t[4]:(d=Y(gD,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)(CD,{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)(da,{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}),TD=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:s}=ot(),l=os(),u=Qm(),d=u.directory||l,f=u.sessionId,p=_h(),m=c(zD),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,SD),t[2]=g,t[3]=_);let v=_,y=Math.max(0,g.length-v.length),b=g.length>0?g.length:n,x=!!(p||!o&&d||o&&a),S;t[4]!==b||t[5]!==s?(S=s(b===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:b}),t[4]=b,t[5]=s,t[6]=S):S=t[6];let C=S,w;t[7]!==y||t[8]!==s?(w=s(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[7]=y,t[8]=s,t[9]=w):w=t[9];let T=w,E=Y(gD,o?vD:_D),D=o?xD:bD,O;t[10]===o?O=t[11]:(O=o?Y(yD,`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(yD,`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(yD,`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){Zw({directory:d,filePath:e,turnMessageId:i,sessionId:f});return}o&&a&&d&&Zw({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[16]=d,t[17]=f,t[18]=a,t[19]=o,t[20]=p,t[21]=i,t[22]=P):P=t[22];let F=q(P),I;t[23]!==d||t[24]!==f||t[25]!==a||t[26]!==o||t[27]!==p||t[28]!==m||t[29]!==i||t[30]!==v[0]?.file?(I=()=>{if(p){p.openTurnDiff(i,f);return}if(!o&&d){m(d,{mode:`diff`,dedupeKey:`turn-diff:${f||`session`}:${i}`,targetPath:null,diffScope:`turn`,diffTurnMessageId:i,diffSessionId:f});return}let e=v[0]?.file;e&&o&&a&&d&&Zw({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[23]=d,t[24]=f,t[25]=a,t[26]=o,t[27]=p,t[28]=m,t[29]=i,t[30]=v[0]?.file,t[31]=I):I=t[31];let L=q(I),R=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,z;t[32]===R?z=t[33]:(z=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,R),t[32]=R,t[33]=z);let B=Y(E,`max-w-full text-muted-foreground hover:text-foreground`),V;t[34]===s?V=t[35]:(V=s(`diffView.actions.reviewAria`),t[34]=s,t[35]=V);let H;t[36]===s?H=t[37]:(H=s(`diffView.actions.reviewAria`),t[36]=s,t[37]=H);let U;t[38]===D?U=t[39]:(U=(0,$.jsx)(X,{name:`file-edit`,className:D}),t[38]=D,t[39]=U);let W=`turn-changes-${i}`,ee;t[40]===s?ee=t[41]:(ee=s(`chat.changedFiles.title`),t[40]=s,t[41]=ee);let G;t[42]!==W||t[43]!==ee||t[44]!==k?(G=(0,$.jsx)(`span`,{id:W,className:k,children:ee}),t[42]=W,t[43]=ee,t[44]=k,t[45]=G):G=t[45];let K;t[46]!==C||t[47]!==j?(K=(0,$.jsx)(`span`,{className:j,children:C}),t[46]=C,t[47]=j,t[48]=K):K=t[48];let te;t[49]===D?te=t[50]:(te=Y(D,`opacity-60`),t[49]=D,t[50]=te);let ne;return t[51]===te?ne=t[52]:(ne=(0,$.jsx)(X,{name:`arrow-right-s`,className:te}),t[51]=te,t[52]=ne),(0,$.jsxs)(`section`,{className:z,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(da,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,onClick:L,className:B,"aria-label":V,title:H,children:[U,G,K,ne]}),v.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[v.map(e=>(0,$.jsx)(wD,{file:e,canOpen:x,isMobile:o,onOpen:F},e.file)),y>0?(0,$.jsxs)(da,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,className:Y(E,`text-muted-foreground hover:text-foreground`),onClick:L,"aria-label":s(`diffView.actions.reviewAria`),title:s(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(D,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:N,children:[`+`,T]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:D})]}):null]}):null]})}),ED=e=>e.type===`subtask`,DD=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},OD=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}`},kD=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=os(),{isMobile:o}=mo(),s=J(BD),l=c(VD),u=Qm(),{t:f}=ot(),p;t[0]===n.description?p=t[1]:(p=typeof n.description==`string`?n.description.trim():``,t[0]=n.description,t[1]=p);let m=p,h;t[2]===n.command?h=t[3]:(h=typeof n.command==`string`?n.command.trim():``,t[2]=n.command,t[3]=h);let g=h,_;t[4]===n.agent?_=t[5]:(_=typeof n.agent==`string`?n.agent.trim():``,t[4]=n.agent,t[5]=_);let v=_,y;t[6]===n.prompt?y=t[7]:(y=typeof n.prompt==`string`?n.prompt.trim():``,t[6]=n.prompt,t[7]=y);let b=y,x;t[8]===n.taskSessionID?x=t[9]:(x=typeof n.taskSessionID==`string`?n.taskSessionID.trim():``,t[8]=n.taskSessionID,t[9]=x);let S=x,C;t[10]===n.model?C=t[11]:(C=OD(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(HD),children:f(r?`chat.messageBody.subtask.hidePrompt`:`chat.messageBody.subtask.showPrompt`)}),r?(0,$.jsx)(`pre`,{className:`typography-meta mt-1.5 overflow-x-auto whitespace-pre-wrap break-words text-foreground/85`,children:b}):null]}):null,t[29]=r,t[30]=b,t[31]=T,t[32]=f,t[33]=N):N=t[33];let P;t[34]!==v||t[35]!==m||t[36]!==a||t[37]!==o||t[38]!==l||t[39]!==u||t[40]!==s||t[41]!==f||t[42]!==S?(P=S&&u.capabilities.navigateNestedSession?(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>{a&&eh(u,S,a,()=>{if(!si({sessionId:S,directory:a})){if(jc()||o||d()){s(S,a);return}l(a,{mode:`chat`,dedupeKey:`session:${S}`,label:m||v||f(`contextPanel.mode.chat`),readOnly:!0})}})},children:f(`chat.messageBody.subtask.openSession`)})}):null,t[34]=v,t[35]=m,t[36]=a,t[37]=o,t[38]=l,t[39]=u,t[40]=s,t[41]=f,t[42]=S,t[43]=P):P=t[43];let F;return t[44]!==j||t[45]!==M||t[46]!==N||t[47]!==P?(F=(0,$.jsxs)(`div`,{className:`mt-2`,children:[j,M,N,P]}),t[44]=j,t[45]=M,t[46]=N,t[47]=P,t[48]=F):F=t[48],F},AD=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=os(),i=c(UD),{isMobile:a}=mo(),{t:o}=ot(),s;t[0]!==r||t[1]!==a?(s=r&&!a&&!d(),t[0]=r,t[1]=a,t[2]=s):s=t[2];let l=!!s,u;t[3]!==n.state||t[4]!==o?(u=n.state===`completed`?o(`chat.messageBody.subagent.completed`):n.state===`error`?o(`chat.messageBody.subagent.error`):o(`chat.messageBody.subagent.cancelled`),t[3]=n.state,t[4]=o,t[5]=u):u=t[5];let f=u,p=n.state===`completed`?o(`chat.messageBody.subagent.completedDescription`):n.state===`error`?o(`chat.messageBody.subagent.errorDescription`):o(`chat.messageBody.subagent.cancelledDescription`),m=n.description||p,h=q(()=>{!l||!r||i(r,{mode:`chat`,dedupeKey:`session:${n.sessionID}`,label:m,readOnly:!0})}),g;t[6]===h?g=t[7]:(g=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())},t[6]=h,t[7]=g);let _=q(g),v=l&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,y;t[8]===v?y=t[9]:(y=Y(`mt-2 flex min-w-0 gap-2.5 rounded-[var(--radius-lg)] border border-border/60 bg-muted/20 px-3 py-2.5`,v),t[8]=v,t[9]=y);let b=l?`button`:void 0,x=l?0:void 0,S=l?o(`chat.messageBody.subagent.openSession`,{label:m}):void 0,C=l?h:void 0,w=l?_:void 0,T;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(`span`,{className:`mt-0.5 flex size-6 flex-shrink-0 items-center justify-center rounded-md bg-foreground/5 text-muted-foreground`,children:(0,$.jsx)(X,{name:`robot-2`,className:`size-3.5`})}),t[10]=T):T=t[10];let E;t[11]===m?E=t[12]:(E=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:m}),t[11]=m,t[12]=E);let D=n.state===`completed`?`bg-[var(--status-success-background)] text-[var(--status-success)]`:n.state===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`,O;t[13]===D?O=t[14]:(O=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,D),t[13]=D,t[14]=O);let k;t[15]!==f||t[16]!==O?(k=(0,$.jsx)(`span`,{className:O,children:f}),t[15]=f,t[16]=O,t[17]=k):k=t[17];let A;t[18]!==E||t[19]!==k?(A=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[E,k]}),t[18]=E,t[19]=k,t[20]=A):A=t[20];let j;t[21]===n.body?j=t[22]:(j=n.body?(0,$.jsx)(`div`,{className:`typography-meta mt-1 max-h-16 overflow-hidden text-muted-foreground [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,children:(0,$.jsx)(Po,{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},jD={background:`transparent`,backgroundColor:`transparent`},MD=e=>{let t=(0,Q.c)(36),{part:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=Z.useRef(null),{t:c}=ot(),l;t[0]===n.shellAction?l=t[1]:(l=typeof n.shellAction?.command==`string`?n.shellAction.command.trim():``,t[0]=n.shellAction,t[1]=l);let u=l,d=typeof n.shellAction?.output==`string`?n.shellAction.output:``,f;t[2]===n.shellAction?f=t[3]:(f=typeof n.shellAction?.status==`string`?n.shellAction.status.trim().toLowerCase():``,t[2]=n.shellAction,t[3]=f);let p=f,m;t[4]===d?m=t[5]:(m=d.trim(),t[4]=d,t[5]=m);let h=m.length>0,g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{s.current!==null&&typeof window<`u`&&(window.clearTimeout(s.current),s.current=null)},t[6]=g):g=t[6];let _=q(g),v,y;t[7]===_?(v=t[8],y=t[9]):(v=()=>()=>{_()},y=[_],t[7]=_,t[8]=v,t[9]=y),Z.useEffect(v,y);let b;t[10]!==_||t[11]!==h||t[12]!==d?(b=async()=>{h&&(await ct(d)).ok&&(_(),o(!0),typeof window<`u`&&(s.current=window.setTimeout(()=>{o(!1),s.current=null},2e3)))},t[10]=_,t[11]=h,t[12]=d,t[13]=b):b=t[13];let x=q(b),S;t[14]===c?S=t[15]:(S=c(`chat.messageBody.shellCommand.title`),t[14]=c,t[15]=S);let C;t[16]===S?C=t[17]:(C=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:S}),t[16]=S,t[17]=C);let w;t[18]===p?w=t[19]:(w=p?(0,$.jsx)(`span`,{className:Y(`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none`,p===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`),children:p}):null,t[18]=p,t[19]=w);let T;t[20]!==w||t[21]!==C?(T=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[C,w]}),t[20]=w,t[21]=C,t[22]=T):T=t[22];let E;t[23]===u?E=t[24]:(E=u?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 overflow-x-auto font-mono`,children:(0,$.jsx)(ec,{language:`bash`,code:u,codeStyle:jD,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(WD),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)(ec,{language:`bash`,code:d,codeStyle:jD,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},ND=e=>{let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},PD=(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}},FD=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:s,hasTextContent:l,onCopyMessage:u,copiedMessage:d,onShowPopup:f,agentMention:p,onEdit:m,onRevert:h,onFork:g,pendingMessageAction:_,editing:v,editStaged:y,onCancelEdit:b,userActionsMode:x=`inline`,stickyUserHeaderEnabled:S=!0})=>{let{locale:C,t:w}=ot(),T=Ph(),E=$m(Qm()),D=c(e=>e.timeFormatPreference),[O,k]=Z.useState(!1),A=Z.useRef(null),j=Z.useMemo(()=>n.filter(e=>e.type===`text`?!Tn(e):!!(ED(e)||DD(e))),[n]),M=Z.useMemo(()=>j.map(e=>Yn(e)?Ox(Pt(e)):void 0),[j]),N=p?.token,P=!1,F=!!u,I=!!d,L=!!(s??a),R=!!l,z=x!==`external-actions`,B=x!==`external-content`,V=S&&x===`inline`,H=q(()=>{A.current!==null&&typeof window<`u`&&(window.clearTimeout(A.current),A.current=null)}),U=q(()=>{!L||!F||!R||typeof window>`u`||(H(),k(!0),A.current=window.setTimeout(()=>{k(!1),A.current=null},1800))});Z.useEffect(()=>{R||(k(!1),H())},[H,R]);let W=q(e=>{!u||!R||(e.stopPropagation(),e.preventDefault(),u(),L&&U())}),ee=T===`mini-chat`||!E.fork?void 0:g,G=Z.useMemo(()=>{if(typeof i!=`number`||i<=0)return null;let e=XT(i,D);return e.length>0?e:null},[C,i,D]),K=Y(`group/user-actions`,a?x===`inline`?`flex items-center justify-end pt-2 pb-3`:S?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:x===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),te=!v&&y&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsxs)(`div`,{className:Y(uD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(fD,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:mD,name:`edit`,className:pD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:w(`chat.messageBody.actions.editStaged`)})]}),b?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,className:oD,"aria-label":w(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),b()},children:(0,$.jsx)(X,{weight:mD,name:`close`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:w(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,ne=(v&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsx)(`div`,{className:Y(uD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(fD,`animate-text-shimmer`),"aria-live":`polite`,children:w(`chat.messageBody.actions.editing`)})})}):null)??te??((F&&R||m||h||ee)&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsxs)(`div`,{className:Y(uD,`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)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(fD,`mr-1`),"aria-label":`Message time: ${G}`,children:[(0,$.jsx)(X,{weight:mD,name:`time`,className:pD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:G})]})}),(0,$.jsx)(za,{children:G})]}):null,h&&(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,className:oD,"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:mD,name:_===`revert`?`loader-4`:`arrow-go-back`,className:Y(sD,_===`revert`&&`animate-spin`)})})}),(0,$.jsx)(za,{sideOffset:6,children:w(`chat.messageBody.actions.revert`)})]}),m&&(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,className:oD,"aria-label":w(`chat.messageBody.actions.editAria`),disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:mD,name:`edit`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:w(`chat.messageBody.actions.edit`)})]}),ee&&(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,className:oD,"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:mD,name:_===`fork`?`loader-4`:`git-branch`,className:Y(sD,_===`fork`&&`animate-spin`)})})}),(0,$.jsx)(za,{sideOffset:6,children:w(`chat.messageBody.actions.fork`)})]}),F&&R&&(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":O||I?`true`:void 0,className:oD,"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:mD,name:`check`,className:Y(sD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:mD,name:`file-copy`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:w(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return z?(0,$.jsxs)(`div`,{className:`relative w-full group/message`,style:nD,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(ED(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(kD,{part:e})},e.id??`user-subtask-${i}`);if(DD(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(MD,{part:e})},e.id??`user-shell-${i}`);let o=M[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(AD,{notification:o})},e.id??`subagent-notification-${i}`);let s;return p&&N&&!P&&Pt(e).includes(N)&&(s=p,P=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(ax,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(nd,{files:n,messageID:t,sessionID:e,onShowPopup:f,compact:!0}),ne]}):(0,$.jsx)($.Fragment,{children:ne})}),ID=Z.memo(({hasCopyableText:e,isTouchContext:t,onCopyMessage:n,reviewTransferAction:r,ttsText:i,sessionId:a})=>{let{t:o}=ot(),s=Ph(),c=Qm(),l=$m(c),{isPlaying:u,play:d,stop:f}=kT(),p=Ei(e=>e.showMessageTTSButtons),m=Ei(e=>e.voiceProvider),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),[y,b]=Z.useState(!1),x=Z.useRef(null),S=Z.useRef(null),C=!!n,w=!!((c.sessionId||a)&&c.directory&&l.openSourceSession&&s!==`mini-chat`),T=q(()=>{x.current!==null&&typeof window<`u`&&(window.clearTimeout(x.current),x.current=null)}),E=q(()=>{S.current!==null&&typeof window<`u`&&(window.clearTimeout(S.current),S.current=null)});Z.useEffect(()=>()=>{T(),E()},[E,T]),Z.useEffect(()=>{(!e||!C)&&(g(!1),v(!1),T(),E())},[C,E,T,e]);let D=q(()=>{!t||!C||!e||typeof window>`u`||(T(),g(!0),x.current=window.setTimeout(()=>{g(!1),x.current=null},1800))}),O=q(async r=>{!n||!e||(r.stopPropagation(),r.preventDefault(),await n()!==!1&&(E(),v(!0),typeof window<`u`&&(S.current=window.setTimeout(()=>{v(!1),S.current=null},2e3)),t&&D()))}),k=q(async t=>{if(t.stopPropagation(),t.preventDefault(),!(!r||y||!e)){b(!0);try{await r.onClick()}finally{b(!1)}}}),A=q(e=>{e.stopPropagation(),e.preventDefault();let t=c.sessionId||a;!t||!c.directory||!c.openSourceSession||c.openSourceSession(t,c.directory)}),j=Z.useMemo(()=>u?o(`chat.messageBody.tts.stopSpeaking`):o(`chat.messageBody.tts.readAloudWithProvider`,{provider:m===`browser`?`Browser`:m===`openai`?`OpenAI`:m===`openai-compatible`?`Custom`:`Say`}),[u,o,m]),M=q(e=>{if(e.stopPropagation(),e.preventDefault(),u){f();return}i.trim()&&d(i)});return(0,$.jsxs)($.Fragment,{children:[n&&(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":h||_?`true`:void 0,className:Y(oD,!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:mD,name:`check`,className:Y(sD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:mD,name:`file-copy`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:o(`chat.messageBody.actions.copyAnswer`)})]}),w?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,className:oD,"aria-label":o(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:A,children:(0,$.jsx)(X,{weight:mD,name:`target`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:o(`chat.messageBody.actions.openSourceSession`)})]}):null,r&&s!==`mini-chat`&&l.reviewTransfer?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,size:`icon`,variant:`ghost`,disabled:y||!e,className:Y(oD,(!e||y)&&`opacity-50`),"aria-label":r.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{k(e)},children:y?(0,$.jsx)(X,{weight:mD,name:`loader-4`,className:Y(sD,`animate-spin`)}):(0,$.jsx)(X,{weight:mD,name:`arrow-left-right`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:r.tooltip})]}):null,s!==`mini-chat`&&p&&e&&(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,className:Y(oD,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:mD,name:`stop`,className:sD}):(0,$.jsx)(X,{weight:mD,name:`volume-up`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:j})]})]})}),LD=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:s,messageTokens:l,isMobile:u,alwaysShowActions:f,hasTouchInput:p,expandedTools:m,onToggleTool:h,onShowPopup:g,streamPhase:_,allowAnimation:v,onContentChange:y,hasTextContent:b=!1,onCopyMessage:x,onAuxiliaryContentComplete:S,showReasoningTraces:C=!1,turnGroupingContext:w,errorMessage:T,errorVariant:E=`error`,reviewTransferDirection:D=null})=>{let{t:O,locale:k}=ot(),A=Ph(),j=$m(Qm()),M=_,N=Z.useRef(null),P=Z.useRef(null),F=_===`streaming`||_===`cooldown`,I=Z.useRef({messageId:t,experiencedStreamingOrCooldown:F});I.current.messageId===t?F&&(I.current.experiencedStreamingOrCooldown=!0):I.current={messageId:t,experiencedStreamingOrCooldown:F};let L=!!(p??u),R=!!(f??u),z=u?lD:cD,B=!i,V=Z.useMemo(()=>n.filter(e=>!Tn(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(()=>Gn(U),[U]),ee=c(e=>e.openContextPreview),G=d(),K=A===`mini-chat`,te=Z.useMemo(()=>{if(G||u||K)return null;for(let e of U){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=es(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=es(n.replace(/\x1b\[[0-9;]*m/g,``))[0];if(r)return r.includes(`0.0.0.0`)?r.replace(`0.0.0.0`,`127.0.0.1`):r}return null},[U,u,K,G,H]),ne=J(e=>e.forkFromMessage),re=J(e=>e.forkTransition),ie=J(e=>e.currentSessionId),ae=J(e=>e.getDirectoryForSession),oe=os(),se=D===`review-to-original`,ce=!u&&!G?D:null,le=Z.useMemo(()=>{let t=W.trim();if(!(!e||!oe||!t||!ce))return ce===`review-to-original`?{ariaLabel:O(`chat.messageBody.actions.sendReviewFeedback`),tooltip:O(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await yt(e,oe,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:O(`chat.messageBody.actions.sendImplementationResponse`),tooltip:O(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await $r(e,oe,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[W,oe,ce,e,O]),[ue,de]=Z.useState(!1),fe=c(e=>e.chatRenderMode),pe=c(e=>e.collapsibleThinkingBlocks),me=c(e=>e.showSplitAssistantMessageActions),he=c(e=>e.showAssistantTps),ge=c(e=>e.timeFormatPreference),_e=fe===`sorted`,ve=w?.isLastAssistantInTurn??!1,ye=a===`stop`,be=(ye||i||!!T)&&(w?.isTurnSettled??!0),xe=ye?`completed`:M,Se=H.length>0,Ce=Z.useMemo(()=>H.some(e=>iC(e)),[H]),we=iC,Te=rC,Ee=I.current.experiencedStreamingOrCooldown,De=Z.useRef({messageId:t,initialized:!1,observedPartIds:new Set});Z.useEffect(()=>{if(De.current.messageId!==t&&(De.current={messageId:t,initialized:!1,observedPartIds:new Set}),!Ee||!Vn())return;let n=De.current,r=!n.initialized;n.initialized=!0;for(let i of H){if(n.observedPartIds.has(i.id))continue;if(!Ft(r,we(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Ot({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[Ee,we,t,e,H]);let Oe=Z.useMemo(()=>H.length===0||!Ce&&H.every(e=>Te(e)),[H,Ce,Te]),ke=Z.useMemo(()=>V.filter(e=>e.type===`reasoning`),[V]),Ae=Z.useMemo(()=>ke.length===0||ke.every(e=>typeof e.time?.end==`number`),[ke]),je=typeof a!=`string`,Me=ke.length>0&&Se&&(Ce||je||!Oe),Ne=B||Se&&(Ce||je||!Oe),Pe=B||Me,Fe=Se||ke.length>0,Ie=U.length===0,Le=Fe&&Ie&&!Ne&&!Pe&&Oe&&Ae,Re=Z.useRef(!1),ze=Z.useRef(!1);Z.useEffect(()=>{ze.current=!1},[t]),Z.useEffect(()=>{if(!Le){Re.current=!1;return}Re.current||(Re.current=!0,S?.())},[Le,S]),Z.useEffect(()=>{if(B){ze.current=!1;return}if(Se){ze.current=!1;return}ke.length!==0&&(Pe||!Ae||ze.current||(ze.current=!0,y?.(`structural`)))},[B,Se,y,Ae,ke.length,Pe]);let Be=!!b&&!B,Ve=q(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||ue||re)){de(!0);try{await ne(e,t)}finally{de(!1)}}}),He=Z.useMemo(()=>{let e=w?.activityParts;return!_e||!e?[]:e},[_e,w?.activityParts]),Ue=Z.useMemo(()=>{let e=w?.activityGroupSegments;return!_e||!e?[]:e.filter(e=>e.anchorMessageId===t)},[_e,t,w?.activityGroupSegments]),We=Ue.length>0,Ge=Z.useMemo(()=>{let e=new Map,t=new Map;return He.forEach(n=>{e.set(n.part,n);let r=n.part.id;typeof r==`string`&&r.length>0&&t.set(r,n)}),{get:n=>{let r=e.get(n);if(r)return r;let i=n.id;if(typeof i==`string`&&i.length>0)return t.get(i)}}},[He]),Ke=w?.toggleGroup,qe=w?.activityPresentationKind===`compaction`,Je=w?.isGroupExpanded===!0,Ye=_e&&qe&&!Je,Xe=_e?w?.activityOwnerMessageId===t||We:!w?.activityOwnerMessageId||w.activityOwnerMessageId===t||We,Ze=_e&&Xe&&(We||qe)&&!!Ke,Qe=iT(a,V),$e={finish:a,parts:V,streamPhase:xe,error:T,isLastAssistantInTurn:ve},et=lT($e),tt=_e&&uT($e),nt=_e&&!et&&!(qe&&Je),rt=!!T,it=E===`info`?`information`:`error-warning`,at=Be,st=ve&&be&&!Ye&&(b||!!T||i),lt=w?.diffStats?.hasDiffs===!0,ut=!K&&ve&&Qe&&be&&!Ye&&w?.diffStats?.hasDiffs===!0,dt=me&&at&&!st&&!_e,ft=Z.useMemo(()=>(0,$.jsx)(ID,{hasCopyableText:Be,isTouchContext:L,onCopyMessage:x,ttsText:W,reviewTransferAction:le,sessionId:e}),[W,Be,L,x,le,e]),pt=Z.useMemo(()=>e=>{if(!me||!_e)return null;let t=Pt(e.part).trim();return t?(0,$.jsx)(ID,{hasCopyableText:!0,isTouchContext:L,onCopyMessage:async()=>(await ct(t)).ok,ttsText:t}):null},[_e,L,me]),mt=Z.useMemo(()=>{if(!dt)return-1;let e=-1;for(let t=0;t<V.length;t+=1){let n=V[t];!n||n.type!==`text`||nt||Ge.get(n)?.kind!==`justification`&&(e=t)}return e},[Ge,nt,dt,V]),ht=dt&&mt<0,gt=Z.useMemo(()=>{let n=[];if(Ze&&Ke&&w){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(tD,{parts:t,materializationParts:r,isExpanded:w.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:w.completionDisposition,activityPresentationKind:w.activityPresentationKind,durationMs:w.durationMs,startedAt:w.userMessageCreatedAt,onToggle:Ke,isMobile:u,expandedTools:m,onToggleTool:h,onShowPopup:g,onContentChange:y,streamPhase:xe,showHeader:!0,diffStats:w.diffStats,renderJustificationActions:pt})},`progressive-group-${e}`))};Ue.length>0?Ue.forEach(t=>{let n=C?t.parts:t.parts.filter(e=>e.kind!==`reasoning`);e(t.id,n,t.parts)}):qe&&e(`${t}:compaction-status`,[])}let r=0;for(;r<V.length;){let i=V[r];if(i.type===`text`){let a=Ge.get(i);if(nt){r+=1;continue}if(Ye){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:P,"data-message-text-export-source":`true`,children:(0,$.jsx)(Iw,{part:i,sessionId:e,messageId:t,streamPhase:xe,chatRenderMode:fe,allowSortedFinalStreaming:tt,hasStreamingHapticLifecycle:Ee,onContentChange:y,onShowPopup:g})},`assistant-text-${t}-${i.id??r}`)),dt&&r===mt&&n.push((0,$.jsx)(`div`,{className:u?aD:iD,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:uD,"data-message-action-group":`true`,children:ft})},`message-actions-${t}`)),r++;continue}if(i.type===`reasoning`){if(Ge.get(i)?.kind===`reasoning`){r+=1;continue}if(!Pt(i).trim()){r+=1;continue}C&&(pe?n.push((0,$.jsx)(`div`,{className:kp(u),children:(0,$.jsx)(Jw,{part:i,messageId:t,streamPhase:xe,onContentChange:y})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(Iw,{part:i,sessionId:e,messageId:t,streamPhase:xe,chatRenderMode:fe,hasStreamingHapticLifecycle:Ee,onContentChange:y,onShowPopup:g},`reasoning-${t}-${i.id??r}`))),r++;continue}if(i.type===`tool`){let e=i,a=e.tool?.toLowerCase()??``;if(_e&&!Xe){r+=1;continue}if(Ge.get(i)?.kind===`tool`){r+=1;continue}if(tC(a)){let e=[],i=r;for(;i<V.length;){let n=V[i];if(n.type!==`tool`)break;let r=n;if(!tC(r.tool?.toLowerCase()??``)||Ge.get(n)?.kind===`tool`)break;e.push({id:r.id,turnId:``,messageId:t,partIndex:i,part:r,kind:`tool`}),i+=1}if(e.length>0){n.push((0,$.jsx)(pE,{activities:e,isMobile:u,isTurnLive:xe!==`completed`,hasFollowingOtherType:lE(V,i,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:e.map(e=>(0,$.jsx)(qE,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`context-tools-${e[0].id}`)),r=i;continue}}if(nC(a)){let e=mE(V,r,e=>e.type!==`tool`||Ge.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(yE,{activities:i,isMobile:u,children:i.map(e=>(0,$.jsx)(qE,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(QS(a)){n.push((0,$.jsx)(`div`,{className:kp(u),children:(0,$.jsx)(gw,{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:kp(u),children:(0,$.jsx)(qE,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:u,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}return n},[Ge,Ue,R,fe,pe,0,m,Ye,qe,u,Xe,_e,mt,t,ft,pt,e,y,g,h,Ze,dt,xe,Ee,C,nt,tt,Ke,w,V]),_t=Z.useMemo(()=>{if(!ve||!be)return;let e=w?.durationMs;if(!(typeof e!=`number`||e<=0))return ND(e)},[ve,be,w?.durationMs]),vt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof s==`number`&&s>0?s:null;if(e===null)return null;let t=XT(e,ge);return t.length>0?t:null},[o,s,ge,k]),bt=Z.useMemo(()=>{if(!he||!ve||!be)return null;let e=r??n,t=PD(e,l),i=tE({createdAt:s,completedAt:o,fallbackDurationMs:w?.durationMs,outputTokens:t.output,reasoningTokens:t.reasoning,parts:e});if(i===null)return null;let a=nE(i);return a.length>0?a:null},[he,ve,be,n,r,l,s,o,w?.durationMs]),xt=(0,$.jsxs)($.Fragment,{children:[!K&&!u&&!G&&te?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,className:oD,"aria-label":O(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=oe??(ie?ae(ie):null);e&&ee(e,te)},children:(0,$.jsx)(X,{weight:mD,name:`global`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:O(`chat.messageBody.actions.openPreview`)})]}):null,!K&&!se&&j.fork?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,size:`icon`,variant:`ghost`,className:oD,"aria-label":O(`chat.messageBody.actions.forkAria`),"aria-busy":ue,disabled:ue||!!re,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Ve(e)},children:(0,$.jsx)(X,{weight:mD,name:ue?`loader-4`:`git-branch`,className:Y(sD,ue&&`animate-spin`)})})}),(0,$.jsx)(za,{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:nD,children:[(0,$.jsx)(KT,{containerRef:N}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`message-content-text leading-relaxed text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0`,children:[gt,rt&&(0,$.jsx)(ps,{children:(0,$.jsxs)(`div`,{className:Y(`group/assistant-text relative flow-root my-1.5 break-words max-w-full`,E===`info`?Y(`inline-flex w-fit max-w-full border border-[var(--status-info-border)]/45 bg-[var(--status-info-background)]/40`,u?`items-start gap-1.5 rounded-lg px-2.5 py-1.5`:Y(`items-center gap-1.5`,`rounded-lg px-2 py-0.5`)):`mt-3 flex items-center gap-2 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3`),children:[E===`info`&&u?(0,$.jsx)(`span`,{className:`inline-flex h-5 w-3.5 shrink-0 items-center justify-center translate-y-[2px]`,"aria-hidden":`true`,children:(0,$.jsx)(X,{name:it,weight:mD,className:Y(sD,`text-[var(--status-info)]/80`)})}):(0,$.jsx)(X,{name:it,weight:E===`info`?mD:void 0,className:Y(`shrink-0`,E===`info`?Y(sD,`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)(Po,{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)(TD,{fileCount:w.diffStats.files,changedFiles:w.changedFiles,turnId:w.turnId,isLatestTurn:w.isLatestTurn,isMobile:u}):null,(0,$.jsx)(nd,{files:n,messageID:t,sessionID:e,onShowPopup:g}),ht&&(0,$.jsx)(`div`,{className:Y(u?aD:iD),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:uD,"data-message-action-group":`true`,children:ft})}),st&&(0,$.jsxs)(`div`,{className:z,"data-message-footer":`true`,style:rD,children:[(0,$.jsxs)(`div`,{className:uD,"data-message-action-group":`true`,children:[ft,xt]}),bt||_t||vt?(0,$.jsxs)(`div`,{className:dD,children:[bt?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsxs)(`span`,{className:fD,"aria-label":O(`chat.messageBody.meta.tpsAria`,{rate:bt}),children:[(0,$.jsx)(X,{weight:mD,name:`pulse`,className:pD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:bt})]})}),(0,$.jsx)(za,{children:O(`chat.messageBody.meta.tpsTooltip`)})]}):null,_t?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsxs)(`span`,{className:fD,children:[(0,$.jsx)(X,{weight:mD,name:`hourglass`,className:pD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:_t})]})}),(0,$.jsx)(za,{children:_t})]}):null,vt?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsxs)(`span`,{className:fD,"aria-label":`Message time: ${vt}`,children:[(0,$.jsx)(X,{weight:mD,name:`time`,className:pD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:vt})]})}),(0,$.jsx)(za,{children:vt})]}):null]}):null,!K&&ve&&ye&&!lt?(0,$.jsx)(Qw,{activityParts:w?.activityParts}):null]})]})]})}),RD=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)(FD,{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)(LD,{...r}),t[26]=r,t[27]=i),i});function zD(e){return e.openContextPanelTab}function BD(e){return e.setCurrentSession}function VD(e){return e.openContextPanelTab}function HD(e){return!e}function UD(e){return e.openContextPanelTab}function WD(e){return!e}var GD=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}},KD=`Authentication failed for this provider. Please re-authenticate and retry.`,qD=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},JD=Lo(()=>Ue(()=>import(`./ToolOutputDialog-BST1ibJ-.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]))),YD=4e3,XD=new Map,ZD=new Map,QD=new Set([`bash`,`shell`,`cmd`,`terminal`]),$D=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},eO=e=>{let t=XD.get(e);return t?new Set(t):new Set},tO=(e,t)=>{if(XD.size>=YD&&!XD.has(e)){let e=XD.keys().next().value;typeof e==`string`&&XD.delete(e)}XD.set(e,new Set(t))},nO=e=>{let t=ZD.get(e);return t?new Set(t):new Set},rO=(e,t)=>{if(ZD.size>=YD&&!ZD.has(e)){let e=ZD.keys().next().value;typeof e==`string`&&ZD.delete(e)}ZD.set(e,new Set(t))},iO=200,aO=new Map,oO=e=>aO.get(e),sO=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=aO.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(aO.size>=iO&&!aO.has(e)){let e=aO.keys().next().value;typeof e==`string`&&aO.delete(e)}aO.set(e,t)}};function cO(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 lO=(e,t)=>{if(typeof e==`object`&&e)return e[t]},uO=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s=!1,activeStreamingPhase:l=null,animateUserOnMount:u=!1,onUserAnimationConsumed:d,reviewTransferDirection:f=null})=>{let{isMobile:p,isTablet:m,hasTouchInput:h}=mo(),g=Qm(),_=$m(g),v=p||m,y=Z.useRef(null),b=J(e=>e.currentSessionId),x=xt(e=>e.getAgentModelForSession),S=xt(e=>e.getSessionModelSelection),C=J(e=>e.revertToMessage),w=J(e=>e.editMessagePreservingChanges),T=J(e=>e.forkFromMessage),E=J(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),D=J(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),O=J(e=>e.clearStagedMessageEdit);Ie(`ui.chat_message.render`),s&&Ie(`ui.chat_message.render.streaming`);let k=Ei(e=>e.providers),{showReasoningTraces:A,stickyUserHeader:j,chatRenderMode:M,showExpandedBashTools:N}=c(me(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{b&&Kb.getInstance().recordSessionStart(b)},[b]);let[P,F]=Z.useState(null),[I,L]=Z.useState(!1),[R,z]=Z.useState(null),B=Z.useRef(null),[V,H]=Z.useState(()=>eO(e.info.id)),[U,W]=Z.useState(()=>nO(e.info.id)),[ee,G]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{H(eO(e.info.id)),W(nO(e.info.id))},[e.info.id]);let K=Z.useMemo(()=>GD(e.info),[e.info]).isUser,te=K&&(p||!j),ne=K&&!p&&j&&!te,re=e.info.sessionID,ie=qb(e=>e.planModeEnabled),{currentContextAgent:ae,savedSessionAgentSelection:oe}=Wp(me(e=>({currentContextAgent:s&&re?e.currentAgentContext.get(re):void 0,savedSessionAgentSelection:s&&re?e.sessionAgentSelections.get(re):void 0}))),se=Z.useMemo(()=>Qr(e.sourceParts??e.parts),[e.parts,e.sourceParts]),ce=Z.useMemo(()=>K?Bn(se,{planModeEnabled:ie}):Qr(e.parts),[K,e.parts,ie,se]),le=Z.useMemo(()=>{if(K||!t)return null;let e=lO(t.info,`clientRole`),n=lO(t.info,`role`);if((typeof e==`string`?e:typeof n==`string`?n:void 0)!==`user`)return null;let r=lO(t.info,`mode`),i=lO(t.info,`agent`),a=lO(t.info,`providerID`),o=lO(t.info,`modelID`),s=lO(t.info,`variant`),c=typeof r==`string`&&r.trim().length>0?r:typeof i==`string`&&i.trim().length>0?i:void 0,l=typeof a==`string`&&a.trim().length>0?a:void 0,u=typeof o==`string`&&o.trim().length>0?o:void 0,d=typeof s==`string`&&s.trim().length>0?s:void 0;return!c&&!l&&!u&&!d?null:{agentName:c,providerId:l,modelId:u,variant:d}},[K,t]),ue=Z.useMemo(()=>{if(!ie||K||!t)return!1;let e=Array.isArray(t.parts)?t.parts:[];for(let t=0;t<e.length;t++){let n=e[t];if(n?.type!==`text`||n?.synthetic!==!0)continue;let r=typeof n.text==`string`?n.text.trim():``;if(r.startsWith(`User has requested to enter plan mode`)||r.startsWith(`The plan at `))return!0}return!1},[K,ie,t]),de=Z.useMemo(()=>{if(K)return;let t=e.info.time;if(!(typeof t?.completed==`number`&&t.completed>0)&&ue&&le?.agentName)return le.agentName;let n=lO(e.info,`mode`);if(typeof n==`string`&&n.trim().length>0)return n;let r=lO(e.info,`agent`);if(typeof r==`string`&&r.trim().length>0)return r;if(le?.agentName)return le.agentName;if(re)return ae||(oe??void 0)},[K,e.info,ue,le,re,ae,oe]),fe=K?null:lO(e.info,`providerID`),pe=K?null:lO(e.info,`modelID`),he=Z.useMemo(()=>{if(K||!re)return null;if(le?.providerId&&le?.modelId)return{providerId:le.providerId,modelId:le.modelId};if(de){let e=x(re,de);if(e?.providerId&&e?.modelId)return e}let e=S(re);return e?.providerId&&e?.modelId?e:null},[K,re,de,le,x,S]),ge=Z.useMemo(()=>K?null:typeof fe==`string`&&fe.trim().length>0?fe:he?.providerId??null,[K,fe,he]),_e=Z.useMemo(()=>K?null:typeof pe==`string`&&pe.trim().length>0?pe:he?.modelId??null,[K,pe,he]),ve=e.info.id?oO(e.info.id):void 0;K||sO(e.info.id,{agent:de,provider:ge??void 0,model:_e??void 0});let ye=de??ve?.agent,be=ge??ve?.provider??null,xe=_e??ve?.model??null,Se=Z.useMemo(()=>{if(K)return;let e=be&&k.length>0?k.find(e=>e.id===be):void 0;return tn(e,xe)||void 0},[K,be,xe,k]),Ce=Z.useMemo(()=>{if(K||!ge||!_e)return!1;let e=k.find(e=>e.id===ge);if(!e?.models||!Array.isArray(e.models))return!1;let t=e.models.find(e=>e.id===_e)?.variants;return!!(t&&Object.keys(t).length>0)},[K,_e,ge,k]),we=cO(ye),Te=cO(be??void 0),Ee=cO(xe??void 0),De=cO(Se),Oe=we??void 0,ke=Te??null,Ae=Ee??null,je=De??void 0,Me=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),Ne=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Pe=Z.useMemo(()=>K?!0:!!(Me&&Me>0),[K,Me]),Fe=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),Le=Z.useMemo(()=>{if(K)return null;let t=e.info.tokens;return!t||typeof t!=`object`?null:{output:typeof t.output==`number`?t.output:void 0,reasoning:typeof t.reasoning==`number`?t.reasoning:void 0}},[K,e.info]),Re=Z.useMemo(()=>jt(ce,{includeReasoning:A}),[ce,A]),ze=Z.useMemo(()=>K?Re:!Pe&&M===`sorted`?[]:Re,[M,Pe,K,Re]),Be=Z.useMemo(()=>K?[]:Re.filter(e=>e.type===`text`),[K,Re]),Ve=Z.useMemo(()=>K?[]:Re.filter(e=>e.type===`tool`),[K,Re]),He=Z.useMemo(()=>{if(!N)return new Set;let e=new Set;for(let t of Ve){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=$D(t.tool);!r||!QD.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=$D(t.part.tool);!n||!QD.has(n)||e.add(t.id)}return e},[N,Ve,a?.activityParts]),Ue=Z.useMemo(()=>{if(He.size===0&&U.size===0)return V;let e=new Set(V);return He.forEach(t=>{U.has(t)||e.add(t)}),U.forEach(t=>{e.delete(t)}),e},[U,He,V]),We=Z.useMemo(()=>{if(!K)return;let e=ce.find(e=>e.type===`agent`);if(!e)return;let t=e,n=typeof t.name==`string`?t.name:void 0;if(n)return{name:n,token:t.source&&typeof t.source.value==`string`&&t.source.value.trim().length>0?t.source.value:`@${n}`}},[K,ce]),Ge=K&&!zi(ze),Ke=typeof Fe!=`string`,qe=Z.useMemo(()=>K?!1:Be.length===0||Ve.length===0?Ke:!0,[Be.length,Ve.length,Ke,K]),Je=Z.useMemo(()=>!K&&Kb.getInstance().shouldAnimateMessage(e.info,b||e.info.sessionID),[e.info,b,K]),[Ye,Xe]=Z.useState(!1),Ze=Z.useMemo(()=>n?GD(n.info):null,[n]),Qe=!!a,$e=a?.isLastAssistantInTurn??!1,et=a?.isWorking===!0||s,tt=Z.useMemo(()=>K?!1:Qe?!$e:Ze?!Ze.isUser&&Ze.role===`assistant`:!1,[Qe,$e,K,Ze]),nt=Z.useMemo(()=>Pe?`completed`:s?l??`streaming`:`completed`,[l,s,Pe]);Z.useEffect(()=>{!K||!u||d?.(e.info.id)},[u,K,e.info.id,d]),Z.useEffect(()=>{Xe(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;K||!t||t!==e.info.id||(nt===`streaming`||nt===`cooldown`)&&Xe(!0)},[o,K,e.info.id,nt,a?.headerMessageId]);let rt=Z.useMemo(()=>{if(K)return!0;let t=o??a?.headerMessageId;return t?e.info.id===t?nt===`completed`||Ye||nt===`streaming`||nt===`cooldown`:!1:!0},[o,Ye,K,a,nt,e.info.id]),it=Z.useCallback(e=>{ct(e).then(t=>{t.ok&&(F(e),setTimeout(()=>F(null),2e3))})},[]),at=K?void 0:a?.userMessageVariant??le?.variant,ot=!K&&Ce&&typeof at==`string`&&at.trim().length>0?at:void 0,st=Z.useMemo(()=>{if(K)return;let t=e.info?.error;if(!t)return;let n=typeof t.data?.message==`string`?t.data.message:void 0,r=typeof t.message==`string`?t.message:void 0,i=typeof t.name==`string`?t.name:void 0,a=n||r||i;if(a)return i===`SessionRetry`?{text:`Opencode failed to send a message. Retry attempt info: \n\`${a}\``,variant:`info`}:qD(a)?{text:KD,variant:`error`}:a.trim().toLowerCase()===`aborted`?{text:`The running turn was stopped before OpenCode could send the next message.`,variant:`info`}:{text:`Opencode failed to send message with error:\n\`${a}\``,variant:`error`}},[K,e.info]),lt=st?.text,ut=st?.variant,dt=Z.useMemo(()=>{if(K){let e=ze.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.output;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);if(e.length>0)return e.join(`
|
|
6576
|
+
`).trim()||IT(t)},KT=({containerRef:e})=>{let{t}=ot(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),[o,s]=Z.useState(``),l=Z.useRef(!1),[u,f]=Z.useState(!1),[p,m]=Z.useState(!1),h=Z.useRef(null),g=Z.useRef(MT),_=Z.useRef(null),v=Z.useRef(null),y=Z.useRef(null),b=Z.useRef(!1),x=J(e=>e.createSession),S=J(e=>e.currentSessionId),C=vt(e=>e.setPendingInputText),w=c(e=>e.isMobile),T=qi(e=>e.projects),E=J(e=>e.availableWorktreesByProject),D=os(),O=Mi(),k=$m(Qm()).textSelectionMutation;Z.useEffect(()=>{b.current=n.show},[n.show]),Z.useEffect(()=>()=>{v.current!==null&&(window.cancelAnimationFrame(v.current),v.current=null),y.current!==null&&(window.clearTimeout(y.current),y.current=null)},[]);let A=Z.useCallback(()=>{_.current=null,NT===A&&(NT=null),b.current&&=(v.current!==null&&(window.cancelAnimationFrame(v.current),v.current=null),f(!1),r(e=>({...e,show:!1})),a(``),s(``),!1)},[]);Z.useEffect(()=>()=>{NT===A&&(NT=null)},[A]);let j=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=g.current/2,r=jT+n,i=t-jT-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),M=Z.useCallback(()=>{if(!_.current)return;NT!==A&&(NT?.(),NT=A);let{plainText:e,markdownText:t,rect:i}=_.current,o=!n.show,c=w?i.left+i.width/2:j(i.left+i.width/2),l=i.top-10;a(e),s(t),r({x:c,y:l,show:!0}),b.current=!0,o&&(f(!0),v.current!==null&&window.cancelAnimationFrame(v.current),v.current=window.requestAnimationFrame(()=>{f(!1),v.current=null}))},[j,A,w,n.show]);Z.useLayoutEffect(()=>{if(!n.show||w||!h.current)return;let e=h.current.offsetWidth;!Number.isFinite(e)||e<=0||e===g.current||(g.current=e,r(e=>({...e,x:j(e.x)})))},[j,w,n.show]),Z.useEffect(()=>{if(!n.show||w)return;let e=()=>{r(e=>({...e,x:j(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[j,w,n.show]);let N=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){l.current||A();return}let r=IT(t.toString());if(!r){l.current||A();return}let i=zT(t,n);if(!i){l.current||A();return}let a=i.getBoundingClientRect();_.current={plainText:r,markdownText:GT(i,r),rect:a},l.current||M()},[e,A,M]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{l.current=!0,A()},r=()=>{l.current=!1,y.current!==null&&window.clearTimeout(y.current),y.current=window.setTimeout(()=>{y.current=null,N()},10)},i=new Set,a=()=>{for(let e of RT(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,N))};a();let o=new MutationObserver(a);o.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,N),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let s=e=>{h.current&&!h.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&A()};return document.addEventListener(`mousedown`,s),()=>{y.current!==null&&(window.clearTimeout(y.current),y.current=null),o.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,N);document.removeEventListener(`selectionchange`,N),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,s)}},[e,N,A,M]);let P=Z.useCallback(e=>{if(!e)return;let t=`\`\`\`md\n${e}\n\`\`\``;C(t,`append`),A(),window.getSelection()?.removeAllRanges()},[C,A]),F=Z.useCallback(()=>{P(o)},[P,o]);Z.useEffect(()=>{let t=t=>{if(!k||!t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||t.key.toLowerCase()!==`i`)return;let n=window.getSelection(),r=e.current;if(!n||!r||!n.toString().trim())return;let i=zT(n,r);i&&(t.preventDefault(),P(GT(i,n.toString())))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[P,k,e]);let I=Z.useCallback(async()=>{i&&(await x(void 0,null,null)&&C(i,`replace`),A(),window.getSelection()?.removeAllRanges())},[i,x,C,A]),L=Z.useCallback(async()=>{if(!i)return;let e=await ct(i);e.ok||console.error(`Failed to copy:`,e.error),A(),window.getSelection()?.removeAllRanges()},[i,A]),R=Z.useMemo(()=>S?O.find(e=>e.id===S)??null:null,[S,O]),z=Z.useMemo(()=>{let e=D??(typeof R?.directory==`string`?R.directory:``),t=Zi(T,E,e);return t?{id:t.id,path:t.path}:null},[E,R?.directory,D,T]),B=Z.useCallback(async()=>{if(!i||!z){z||Ii.error(t(`chat.textSelection.toast.noProject`));return}try{m(!0);let e=await vn(o||i,S),n=await zt(z),r=AT(n.notes,e);if(!await Kn(z,{notes:r,todos:n.todos})){Ii.error(t(`chat.textSelection.toast.addToNotesFailed`));return}window.dispatchEvent(new CustomEvent(`openchamber:project-notes-updated`,{detail:{projectId:z.id}})),Ii.success(t(`chat.textSelection.toast.addToNotesSuccess`)),A(),window.getSelection()?.removeAllRanges()}catch(e){let n=e instanceof Error?e.message:void 0;Ii.error(t(`chat.textSelection.toast.addToNotesFailed`),n?{description:n}:void 0)}finally{m(!1)}},[z,S,A,i,o,t]);return n.show?w?(0,Sc.createPortal)((0,$.jsx)(`div`,{ref:h,className:Y(`fixed left-3 right-3 bottom-0 z-50 mx-auto max-w-[420px]`,`rounded-2xl border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] p-2 shadow-lg`,`safe-area-bottom`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),style:{bottom:`calc(0.5rem + env(safe-area-inset-bottom, 0px))`},children:(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[k?(0,$.jsxs)(`button`,{onClick:F,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--primary-base)] text-[var(--primary-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.addToChat`)})]}):null,k?(0,$.jsxs)(`button`,{onClick:I,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.newSession`)})]}):null,(0,$.jsxs)(`button`,{onClick:L,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.copy`)})]}),k&&!d()?(0,$.jsxs)(`button`,{onClick:B,disabled:p,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80 disabled:opacity-60 disabled:cursor-not-allowed`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.saveInsightToNotes`),type:`button`,children:[p?(0,$.jsx)(X,{name:`loader-4`,className:`h-5 w-5 flex-shrink-0 animate-spin`}):(0,$.jsx)(X,{name:`booklet`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.addToNotes`)})]}):null]})}),document.body):(0,Sc.createPortal)((0,$.jsx)(`div`,{ref:h,className:`fixed z-50`,style:{left:n.x,top:n.y,transform:`translate(-50%, -100%)`},children:(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1 whitespace-nowrap`,`rounded-lg border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] shadow-none`,`px-1.5 py-1`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),children:[k?(0,$.jsxs)(`button`,{onClick:F,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.addToChat`)}),(0,$.jsx)(pp,{shortcut:`⌘+I`})]}):null,k?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,k?(0,$.jsxs)(`button`,{onClick:I,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.newSession`)})]}):null,k?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{onClick:L,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.copy`)})]}),k&&!d()?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}),(0,$.jsxs)(`button`,{onClick:B,disabled:p,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)] disabled:opacity-60 disabled:cursor-not-allowed`,`transition-colors duration-150`),title:t(`chat.textSelection.title.saveInsightToNotes`),type:`button`,children:[p?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}):(0,$.jsx)(X,{name:`booklet`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.addToNotes`)})]})]}):null]})}),document.body):null},qT=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),JT=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),qT(e,n)},YT=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),XT=(e,t)=>{if(!YT(e))return``;let n=new Date(e),r=new Date,i=lo(n,t),a=st(),o=lt.getState().dictionary;if(qT(n,r))return i;if(JT(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}`},ZT=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,QT=e=>e,$T=e=>{if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let n of e){let e=QT(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},eE=(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-$T(n);return!Number.isFinite(a)||a<=0?null:a},tE=e=>{let t=eE(e.createdAt,e.completedAt,e.parts,e.fallbackDurationMs);if(t===null)return null;let n=ZT(e.outputTokens)+ZT(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},nE=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`},rE=e=>{let t=(0,Q.c)(20),{text:n,active:r,className:i}=e,a=Z.useRef(n),[o,s]=Z.useState(n),[c,l]=Z.useState(null),u,d;t[0]!==r||t[1]!==n?(u=()=>{if(n===a.current)return;let e=a.current;if(a.current=n,!r||e.length===0){l(null),s(n);return}l(e),s(n)},d=[r,n],t[0]=r,t[1]=n,t[2]=u,t[3]=d):(u=t[2],d=t[3]),Z.useEffect(u,d);let f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>{l(null)},t[4]=f):f=t[4];let p=q(f),m;t[5]===i?m=t[6]:(m=Y(`oc-summary-flip-viewport relative block h-5 min-h-0 w-full min-w-0 max-w-full overflow-clip sm:h-6`,i),t[5]=i,t[6]=m);let h=c&&`invisible`,g;t[7]===h?g=t[8]:(g=Y(`block h-full min-w-0 truncate leading-5 sm:leading-6`,h),t[7]=h,t[8]=g);let _;t[9]!==o||t[10]!==g?(_=(0,$.jsx)(`span`,{className:g,children:o}),t[9]=o,t[10]=g,t[11]=_):_=t[11];let v;t[12]!==o||t[13]!==p||t[14]!==c?(v=c?(0,$.jsxs)(`span`,{className:`oc-summary-flip-stage absolute inset-0 block overflow-clip`,children:[(0,$.jsx)(`span`,{className:`oc-summary-flip-out absolute inset-x-0 top-0 block h-full truncate`,"aria-hidden":`true`,children:c}),(0,$.jsx)(`span`,{className:`oc-summary-flip-in absolute inset-x-0 top-0 block h-full truncate`,onAnimationEnd:p,children:o})]}):null,t[12]=o,t[13]=p,t[14]=c,t[15]=v):v=t[15];let y;return t[16]!==m||t[17]!==_||t[18]!==v?(y=(0,$.jsxs)(`span`,{className:m,children:[_,v]}),t[16]=m,t[17]=_,t[18]=v,t[19]=y):y=t[19],y},iE=[`search`,`read`,`list`];function aE(e){let t=aC(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function oE(e){let t={read:0,search:0,list:0};for(let n of e){let e=aE(n);e&&(t[e]+=1)}return t}function sE(e){return iC(e)}function cE(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!tC(e.toolName):e.kind!=null||e.type!=null}function lE(e,t,n){for(let r=t;r<e.length;r+=1)if(cE(n(e[r])))return!0;return!1}function uE(e){return`parts`in e?e.parts.some(e=>sE(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>sE(e))}function dE(e,t,n){let r=[],i=t;for(;i<e.length&&tC(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var fE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,pE=({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??uE({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=oE(u.map(e=>e.tool)),p=iE.filter(e=>f[e]>0).map(e=>{let t=f[e];return o(e===`search`?t===1?`chat.contextGroup.searchSingle`:`chat.contextGroup.searchPlural`:e===`read`?t===1?`chat.contextGroup.readSingle`:`chat.contextGroup.readPlural`:t===1?`chat.contextGroup.listSingle`:`chat.contextGroup.listPlural`,{count:t})}).join(`, `),m=q(()=>{c(e=>!e)}),h=q(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),m())}),g=o(s?`chat.contextGroup.collapseAria`:`chat.contextGroup.expandAria`),_=o(d?`chat.contextGroup.exploring`:`chat.contextGroup.explored`),v=t?`h-5`:`h-6`;return(0,$.jsxs)(`div`,{"data-component":`context-tool-group`,className:kp(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":s,"aria-controls":l,"aria-label":g,"data-mobile-press-feedback":`soft`,className:Y(`flex w-full min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,Ap),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)(US,{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,fE,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,fE),style:{color:`var(--tools-description)`},children:(0,$.jsx)(rE,{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 mE(e,t,n){let r=[],i=t;for(;i<e.length&&nC(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var hE=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function gE(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=hE(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=hE(e.name);if(t)return t;let r=hE(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=hE(n.output.name);if(e)return e}return null}function _E(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 vE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,yE=({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=>iC(e)),{joinedVisible:l,hiddenCount:u}=_E(s.map(gE)),d=u>0?r(`chat.skillGroup.summaryOverflow`,{names:l,count:u}):l,f=q(()=>{a(e=>!e)}),p=q(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),f())}),m=r(i?`chat.skillGroup.collapseAria`:`chat.skillGroup.expandAria`),h=r(`chat.tools.display.skill`);return(0,$.jsxs)(`div`,{"data-component":`skill-tool-group`,className:kp(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":i,"aria-controls":o,"aria-label":m,"data-mobile-press-feedback":`soft`,className:Y(`flex w-full min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,Ap),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)(US,{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`,vE,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`,vE),style:{color:`var(--tools-description)`},children:(0,$.jsx)(rE,{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]})},bE=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:s}=e,l=c(xE),u=n,d=typeof u.text==`string`?u.text:``,f=typeof u.content==`string`?u.content:``,p=f.length>d.length?f:d,m=u.time,h=n.sessionID,g=o===void 0||o!==`completed`,_,v;if(t[0]!==i||t[1]!==p?(_=()=>{p.trim().length!==0&&i?.(`structural`)},v=[i,p],t[0]=i,t[1]=p,t[2]=_,t[3]=v):(_=t[2],v=t[3]),Z.useEffect(_,v),!p||p.trim().length===0)return null;let y=o??`streaming`,b=g&&typeof m?.end!=`number`,x;t[4]!==l||t[5]!==r||t[6]!==i||t[7]!==s||t[8]!==n||t[9]!==h||t[10]!==y||t[11]!==b?(x=(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(Iw,{part:n,sessionId:h,messageId:r,streamPhase:y,chatRenderMode:l,hasStreamingHapticLifecycle:b,onContentChange:i,onShowPopup:s})}),t[4]=l,t[5]=r,t[6]=i,t[7]=s,t[8]=n,t[9]=h,t[10]=y,t[11]=b,t[12]=x):x=t[12];let S;t[13]===a?S=t[14]:(S=a?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:a})}):null,t[13]=a,t[14]=S);let C;return t[15]!==x||t[16]!==S?(C=(0,$.jsxs)(`div`,{"data-message-text-export-root":`true`,children:[x,S]}),t[15]=x,t[16]=S,t[17]=C):C=t[17],C});function xE(e){return e.chatRenderMode}var SE=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},CE=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,wE=Y(`typography-meta font-medium`,CE),TE=Y(`typography-meta`,CE),EE=[],DE=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},OE=e=>{let t=new Set;for(let n of e)DE(n)&&n.messageId&&t.add(n.messageId);return[...t]},kE=(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}),AE=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=$o(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},jE=e=>e,ME=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},NE=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},PE=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},FE=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},IE=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=FE(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`}`},LE=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=IE(n.todos);if(e)return e}if(Array.isArray(r)){let e=IE(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=IE(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=IE(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=IE(e.todos);if(t)return t}}catch{}return null},RE=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)},zE=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(sx,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,TE),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`,TE),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)(sx,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},BE=e=>{let t=xo(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},VE=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 gE(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`?LE(e):ME(e)},HE=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}},UE=Z.memo(e=>{let t=(0,Q.c)(16),{activity:n,isExpanded:r,isMobile:i,onToggleTool:a,onShowPopup:o,onContentChange:s}=e,c;t[0]!==n.id||t[1]!==a?(c=()=>{a(n.id)},t[0]=n.id,t[1]=a,t[2]=c):c=t[2];let l=q(c),u;t[3]===i?u=t[4]:(u=kp(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)(gw,{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&&Yx([e.activity.part],[t.activity.part])),WE=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=kp(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(qE,{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&&KE(e.activities,t.activities)),GE=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!Pt(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(tC(i)){let r=dE(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:lE(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(nC(i)){let r=mE(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($S(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(QS(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(eC(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},KE=(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||!Yx([r.part],[i.part]))return!1}return!0},qE=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=ot(),s=c(ZE),l=ts(n,o),u;t[0]===n?u=t[1]:(u=cx(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(Ao),h=_h(),g=Te(QE),_=Qm(),v=_.kind===`embedded`?_.directory:g,y;t[4]===n?y=t[5]:(y=n.toLowerCase(),t[4]=n,t[5]=y);let b=y===`skill`,x;t[6]===b?x=t[7]:(x={enabled:b},t[6]=b,t[7]=x);let S=Wr(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($E)),t[10]=w,t[11]=T);let E=T,D=r[0]??null,O=!D||iC(D.part),k;t[12]===D?k=t[13]:(k=D?VE(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||PE(D);if(!e||e===`<built-in>`){j=null;break bb0}let r=BE(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=NE(D);if(!e){N=null;break bb1}let n=yo(e,v);if(!n){N=null;break bb1}let r;t[26]===D?r=t[27]:(r=RE(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=bo(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(!wo(n,v)){ss(n,v).then(()=>{let e=c.getState(),r=v||vo(v,n);if(t&&Number.isFinite(t)){e.openContextFileAtLine(r,n,Math.max(1,Math.trunc(t)),1);return}e.openContextFile(r,n)});return}let r=c.getState(),i=vo(v,n);if(t&&Number.isFinite(t)){r.openContextFileAtLine(i,n,Math.max(1,Math.trunc(t)),1);return}r.openContextFile(i,n)},t[32]=v,t[33]=h,t[34]=m,t[35]=F):F=t[35];let I=q(F),L;t[36]!==v||t[37]!==h?(L=e=>{let t=xo(e);if(!t)return;let n=()=>{if(h){h.openFile({path:t});return}let e=c.getState(),n=v||vo(``,t);e.openContextFile(n,t)};if(v&&!wo(t,v)){ss(t,v).then(n);return}n()},t[36]=v,t[37]=h,t[38]=L):L=t[38];let R=q(L),z;t[39]===n?z=t[40]:(z=n.toLowerCase(),t[39]=n,t[40]=z);let B=z,V=B===`grep`||B===`search`||B===`find`||B===`ripgrep`||B===`glob`,H=B===`webfetch`||B===`fetch`||B===`curl`||B===`wget`,U=B===`skill`,W=!!(P||M),ee=!!(P&&v||M),G;t[41]!==ee||t[42]!==I||t[43]!==R||t[44]!==W||t[45]!==P||t[46]!==M?(G=()=>{if(!(!W||!ee)){if(P){I(P.path,P.offset);return}M&&R(M.path)}},t[41]=ee,t[42]=I,t[43]=R,t[44]=W,t[45]=P,t[46]=M,t[47]=G):G=t[47];let K=q(G),te;t[48]===K?te=t[49]:(te=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),K())},t[48]=K,t[49]=te);let ne=q(te),re=W&&ee&&`cursor-pointer`,ie=W&&!ee&&`cursor-default opacity-70`,ae;t[50]!==re||t[51]!==ie?(ae=Y(`flex w-full items-center gap-x-1.5 min-w-0`,Ap,re,ie),t[50]=re,t[51]=ie,t[52]=ae):ae=t[52];let oe=W?`soft`:void 0,se=W?K:void 0,ce=W?ne:void 0,le=W?`button`:void 0,ue=W&&ee?0:void 0,de=W&&!ee?!0:void 0,fe=i?`size-4`:`size-3.5`,pe;t[53]===fe?pe=t[54]:(pe=Y(`inline-flex items-center justify-center flex-shrink-0`,fe),t[53]=fe,t[54]=pe);let me;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(me={color:`var(--tools-icon)`},t[55]=me):me=t[55];let he=O?(0,$.jsx)(US,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:l})}):d,ge;t[56]!==pe||t[57]!==me||t[58]!==he?(ge=(0,$.jsx)(`div`,{className:pe,style:me,children:he}),t[56]=pe,t[57]=me,t[58]=he,t[59]=ge):ge=t[59];let _e,ve;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(_e=Y(wE,`inline-flex items-center flex-shrink-0 opacity-85`),ve={color:`var(--tools-title)`},t[60]=_e,t[61]=ve):(_e=t[60],ve=t[61]);let ye;t[62]===l?ye=t[63]:(ye=(0,$.jsx)(`span`,{className:_e,style:ve,title:l,children:l}),t[62]=l,t[63]=ye);let be;t[64]!==a||t[65]!==p||t[66]!==P||t[67]!==s?(be=p&&P?(0,$.jsxs)(`span`,{className:Y(`inline-flex !min-h-0 items-center justify-start gap-1 min-w-0 flex-1 text-left`,TE),style:{color:`var(--tools-description)`},title:P.offset?`${P.displayPath}:${P.offset}`:P.displayPath,children:[s?(0,$.jsx)(Au,{filePath:P.path,className:`h-3.5 w-3.5`}):null,zE(P.displayPath,a)]}):null,t[64]=a,t[65]=p,t[66]=P,t[67]=s,t[68]=be):be=t[68];let xe;t[69]!==a||t[70]!==A||t[71]!==V?(xe=V&&A?(0,$.jsx)(`span`,{className:`inline-flex min-w-0 flex-1`,children:(0,$.jsxs)(sx,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,TE),style:{color:`var(--tools-description)`},title:A,children:[`"`,A,`"`]})}):null,t[69]=a,t[70]=A,t[71]=V,t[72]=xe):xe=t[72];let Se;t[73]!==A||t[74]!==H?(Se=H&&A?(0,$.jsxs)(`a`,{href:A,target:`_blank`,rel:`noopener noreferrer`,onClick:eD,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`,TE),style:{color:`var(--status-info)`},title:A,children:[(0,$.jsx)(AE,{href:A}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:A})]}):null,t[73]=A,t[74]=H,t[75]=Se):Se=t[75];let Ce;t[76]!==U||t[77]!==M?(Ce=U&&M?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,TE),style:{color:`var(--tools-description)`},title:M.path,children:M.name}):null,t[76]=U,t[77]=M,t[78]=Ce):Ce=t[78];let we;t[79]!==A||t[80]!==U||t[81]!==M?(we=U&&!M&&A?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,TE),style:{color:`var(--tools-description)`},title:A,children:A}):null,t[79]=A,t[80]=U,t[81]=M,t[82]=we):we=t[82];let Ee;t[83]!==a||t[84]!==A||t[85]!==H||t[86]!==p||t[87]!==V||t[88]!==U?(Ee=!p&&!V&&!H&&!U&&A?(0,$.jsx)(sx,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,TE),style:{color:`var(--tools-description)`},children:A}):null,t[83]=a,t[84]=A,t[85]=H,t[86]=p,t[87]=V,t[88]=U,t[89]=Ee):Ee=t[89];let De;return t[90]!==ae||t[91]!==oe||t[92]!==se||t[93]!==ce||t[94]!==le||t[95]!==ue||t[96]!==de||t[97]!==ge||t[98]!==ye||t[99]!==be||t[100]!==xe||t[101]!==Se||t[102]!==Ce||t[103]!==we||t[104]!==Ee?(De=(0,$.jsxs)(`div`,{className:ae,"data-mobile-press-feedback":oe,onClick:se,onKeyDown:ce,role:le,tabIndex:ue,"aria-disabled":de,children:[ge,ye,be,xe,Se,Ce,we,Ee]}),t[90]=ae,t[91]=oe,t[92]=se,t[93]=ce,t[94]=le,t[95]=ue,t[96]=de,t[97]=ge,t[98]=ye,t[99]=be,t[100]=xe,t[101]=Se,t[102]=Ce,t[103]=we,t[104]=Ee,t[105]=De):De=t[105],De},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&KE(e.activities,t.activities)),JE=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)(Jw,{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}),YE=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)(bE,{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}),XE=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(),_=os()??``,v=Z.useMemo(()=>OE(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?SE(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(()=>HE(e),[e]),M=T?j.active:j.all,N=M.slice(0,c?2:3),P=q((e=!1,n=!1)=>{if(!(!_||!v.length)){for(let r of v){let i=t.find(e=>e.messageId===r)?.part.sessionID;if(!i)continue;let a=Fr(_,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=Ji(_,i,r,{priority:n?`background`:`user`}).catch(()=>{x.current.add(r)}).finally(()=>{b.current.delete(r),S(e=>e+1)});b.current.set(r,o)}S(e=>e+1)}}),F=q(e=>{e.stopPropagation(),P(!0)}),I=q(()=>{let e=C.current;w.current=e?{top:e.getBoundingClientRect().top,scrollContainer:e.closest(`[data-scrollbar="chat"]`)}:null,n||P(),s()});Z.useEffect(()=>{T||!n||P(!1,!0)},[T,n]),Z.useLayoutEffect(()=>{let e=w.current,t=C.current;if(!e||!t)return;let n=()=>{if(!t.isConnected)return;let n=t.getBoundingClientRect().top-e.top;if(!(Math.abs(n)<.5)){if(e.scrollContainer?.isConnected){e.scrollContainer.scrollTop+=n;return}window.scrollBy(0,n)}};if(n(),typeof window>`u`||typeof window.requestAnimationFrame!=`function`){w.current=null;return}let r=window.requestAnimationFrame(()=>{n(),w.current=null});return()=>window.cancelAnimationFrame(r)},[n]);let L=m&&!n?Math.max(0,Math.floor(r)):0,R=!m||n||L>0,z=y.current,B=[...z].map(e=>{if(b.current.has(e))return`loading`;if(x.current.has(e))return`error`;let n=t.find(t=>t.messageId===e)?.part.sessionID??``;return Fr(_,n,e).status}),V=B.includes(`loading`),H=B.includes(`error`),U=B.length>0&&B.every(e=>e===`ready`),W=t.some(e=>z.has(e.messageId)&&DE(e)),ee=U&&!W&&!kE(t,z),G=Z.useMemo(()=>R?jE(e):EE,[e,R]),K=Z.useMemo(()=>R?GE(G):[],[R,G]),te=Z.useMemo(()=>n||L===0?0:Math.max(0,K.length-L),[n,L,K.length]),ne=Z.useMemo(()=>n||L===0?K:K.slice(-L),[n,L,K]);if(!m&&K.length===0)return null;let re=(e,t)=>{let n=(0,$.jsx)(`div`,{className:kp(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},ie=R?ne.map((e,t)=>{switch(e.type){case`reasoning`:return re(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(JE,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return re(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(YE,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(UE,{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)(WE,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(pE,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(qE,{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)(yE,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(qE,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(UE,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,ae=ne.length>0;return m?(0,$.jsxs)(`div`,{className:kp(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`,Ap,c&&`pr-0`),"data-mobile-press-feedback":`soft`,onClick:I,"aria-expanded":n,"aria-label":g(n?`chat.activity.collapseAria`:`chat.activity.expandAria`),children:[(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 flex-1 items-center overflow-clip`,c?`gap-x-1`:`gap-x-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,c?`h-5 w-4`:`h-6 w-3.5`),style:{color:`var(--tools-icon)`},children:T&&!O?(0,$.jsx)(US,{isMobile:c,label:A,className:`block`}):(0,$.jsx)(X,{name:k,className:`h-[14px] w-[14px]`})}),(0,$.jsx)(`span`,{className:Y(`inline-flex flex-shrink-0 items-center`,c?`typography-meta h-5`:`typography-ui-label h-5 font-semibold`,T?`animate-text-shimmer text-[var(--status-info)] [--oc-text-shimmer-base:var(--status-info)]`:`text-foreground/85`),children:A}),E?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 tabular-nums text-muted-foreground`,children:E}):null]}),(0,$.jsxs)(`span`,{className:Y(`ml-auto inline-flex max-w-[min(14rem,55%)] shrink-0 items-center justify-end`,c?`gap-0.5`:`gap-1`),children:[M.length>0?(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center text-muted-foreground`,c?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5`,"aria-hidden":`true`,children:N.map((e,t)=>(0,$.jsx)(na,{name:e,size:c?12:14,className:Y(`flex-none`,c?`size-3 min-h-3 min-w-3 max-h-3 max-w-3`:`size-3.5 min-h-3.5 min-w-3.5 max-h-3.5 max-w-3.5`)},`${e}-${t}`))}),(0,$.jsx)(`span`,{className:`typography-meta min-w-0 truncate`,children:g(T?`chat.activity.agentsWorking`:`chat.activity.agentsInvolved`,{count:M.length})})]}):null,(0,$.jsx)(X,{name:n?`arrow-down-s`:`arrow-right-s`,className:Y(`flex-shrink-0 text-muted-foreground opacity-70`,c&&`-mr-0.5`,c?`size-3`:`size-3.5`)})]})]}),ae?(0,$.jsxs)(`div`,{className:`relative ml-2 pl-3`,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-px bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),te>0?(0,$.jsxs)(`button`,{type:`button`,onClick:I,className:`typography-meta leading-4 px-2 py-1 text-muted-foreground/45 hover:text-muted-foreground/65 text-left`,children:[`+`,te,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:ie})]}):null,n&&(V||H||ee)?(0,$.jsx)(`div`,{className:Y(`typography-meta ml-5 flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,H&&`text-[var(--status-error)]`),role:H?`alert`:`status`,children:V?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{children:g(`chat.activity.outputLoading`)})]}):H?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:g(`chat.activity.outputLoadFailed`)}),(0,$.jsx)(da,{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:kp(c),children:ie})});function ZE(e){return e.showToolFileIcons}function QE(e){return e.currentDirectory}function $E(e){return[e.name,e]}function eD(e){e.stopPropagation()}var tD=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(XE,{...e}),t[0]=e,t[1]=n),n}),nD={contain:`layout`},rD={containerType:`inline-size`,containerName:`message-footer`},iD=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,aD=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,oD=`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`,sD=`size-3.5!`,cD=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,lD=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,uD=`flex items-center gap-2`,dD=`flex items-center gap-2 text-muted-foreground`,fD=`inline-flex h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,pD=`size-3.5!`,mD=`medium`,hD=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,gD=`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)]`,_D=`h-7 gap-1.5`,vD=`h-6 gap-1`,yD=`text-[11px] leading-none`,bD=`size-3.5`,xD=`size-3`,SD=5,CD=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)(Au,{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=hD(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}),wD=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=ot(),s;t[0]!==n.file||t[1]!==a?(s=()=>{a(n.file)},t[0]=n.file,t[1]=a,t[2]=s):s=t[2];let c=q(s),l=!r,u=i?vD:_D,d;t[3]===u?d=t[4]:(d=Y(gD,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)(CD,{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)(da,{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}),TD=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:s}=ot(),l=os(),u=Qm(),d=u.directory||l,f=u.sessionId,p=_h(),m=c(zD),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,SD),t[2]=g,t[3]=_);let v=_,y=Math.max(0,g.length-v.length),b=g.length>0?g.length:n,x=!!(p||!o&&d||o&&a),S;t[4]!==b||t[5]!==s?(S=s(b===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:b}),t[4]=b,t[5]=s,t[6]=S):S=t[6];let C=S,w;t[7]!==y||t[8]!==s?(w=s(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[7]=y,t[8]=s,t[9]=w):w=t[9];let T=w,E=Y(gD,o?vD:_D),D=o?xD:bD,O;t[10]===o?O=t[11]:(O=o?Y(yD,`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(yD,`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(yD,`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){Zw({directory:d,filePath:e,turnMessageId:i,sessionId:f});return}o&&a&&d&&Zw({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[16]=d,t[17]=f,t[18]=a,t[19]=o,t[20]=p,t[21]=i,t[22]=P):P=t[22];let F=q(P),I;t[23]!==d||t[24]!==f||t[25]!==a||t[26]!==o||t[27]!==p||t[28]!==m||t[29]!==i||t[30]!==v[0]?.file?(I=()=>{if(p){p.openTurnDiff(i,f);return}if(!o&&d){m(d,{mode:`diff`,dedupeKey:`turn-diff:${f||`session`}:${i}`,targetPath:null,diffScope:`turn`,diffTurnMessageId:i,diffSessionId:f});return}let e=v[0]?.file;e&&o&&a&&d&&Zw({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[23]=d,t[24]=f,t[25]=a,t[26]=o,t[27]=p,t[28]=m,t[29]=i,t[30]=v[0]?.file,t[31]=I):I=t[31];let L=q(I),R=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,z;t[32]===R?z=t[33]:(z=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,R),t[32]=R,t[33]=z);let B=Y(E,`max-w-full text-muted-foreground hover:text-foreground`),V;t[34]===s?V=t[35]:(V=s(`diffView.actions.reviewAria`),t[34]=s,t[35]=V);let H;t[36]===s?H=t[37]:(H=s(`diffView.actions.reviewAria`),t[36]=s,t[37]=H);let U;t[38]===D?U=t[39]:(U=(0,$.jsx)(X,{name:`file-edit`,className:D}),t[38]=D,t[39]=U);let W=`turn-changes-${i}`,ee;t[40]===s?ee=t[41]:(ee=s(`chat.changedFiles.title`),t[40]=s,t[41]=ee);let G;t[42]!==W||t[43]!==ee||t[44]!==k?(G=(0,$.jsx)(`span`,{id:W,className:k,children:ee}),t[42]=W,t[43]=ee,t[44]=k,t[45]=G):G=t[45];let K;t[46]!==C||t[47]!==j?(K=(0,$.jsx)(`span`,{className:j,children:C}),t[46]=C,t[47]=j,t[48]=K):K=t[48];let te;t[49]===D?te=t[50]:(te=Y(D,`opacity-60`),t[49]=D,t[50]=te);let ne;return t[51]===te?ne=t[52]:(ne=(0,$.jsx)(X,{name:`arrow-right-s`,className:te}),t[51]=te,t[52]=ne),(0,$.jsxs)(`section`,{className:z,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(da,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,onClick:L,className:B,"aria-label":V,title:H,children:[U,G,K,ne]}),v.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[v.map(e=>(0,$.jsx)(wD,{file:e,canOpen:x,isMobile:o,onOpen:F},e.file)),y>0?(0,$.jsxs)(da,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,className:Y(E,`text-muted-foreground hover:text-foreground`),onClick:L,"aria-label":s(`diffView.actions.reviewAria`),title:s(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(D,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:N,children:[`+`,T]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:D})]}):null]}):null]})}),ED=e=>e.type===`subtask`,DD=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},OD=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}`},kD=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=os(),{isMobile:o}=mo(),s=J(BD),l=c(VD),u=Qm(),{t:f}=ot(),p;t[0]===n.description?p=t[1]:(p=typeof n.description==`string`?n.description.trim():``,t[0]=n.description,t[1]=p);let m=p,h;t[2]===n.command?h=t[3]:(h=typeof n.command==`string`?n.command.trim():``,t[2]=n.command,t[3]=h);let g=h,_;t[4]===n.agent?_=t[5]:(_=typeof n.agent==`string`?n.agent.trim():``,t[4]=n.agent,t[5]=_);let v=_,y;t[6]===n.prompt?y=t[7]:(y=typeof n.prompt==`string`?n.prompt.trim():``,t[6]=n.prompt,t[7]=y);let b=y,x;t[8]===n.taskSessionID?x=t[9]:(x=typeof n.taskSessionID==`string`?n.taskSessionID.trim():``,t[8]=n.taskSessionID,t[9]=x);let S=x,C;t[10]===n.model?C=t[11]:(C=OD(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(HD),children:f(r?`chat.messageBody.subtask.hidePrompt`:`chat.messageBody.subtask.showPrompt`)}),r?(0,$.jsx)(`pre`,{className:`typography-meta mt-1.5 overflow-x-auto whitespace-pre-wrap break-words text-foreground/85`,children:b}):null]}):null,t[29]=r,t[30]=b,t[31]=T,t[32]=f,t[33]=N):N=t[33];let P;t[34]!==v||t[35]!==m||t[36]!==a||t[37]!==o||t[38]!==l||t[39]!==u||t[40]!==s||t[41]!==f||t[42]!==S?(P=S&&u.capabilities.navigateNestedSession?(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>{a&&eh(u,S,a,()=>{if(!si({sessionId:S,directory:a})){if(jc()||o||d()){s(S,a);return}l(a,{mode:`chat`,dedupeKey:`session:${S}`,label:m||v||f(`contextPanel.mode.chat`),readOnly:!0})}})},children:f(`chat.messageBody.subtask.openSession`)})}):null,t[34]=v,t[35]=m,t[36]=a,t[37]=o,t[38]=l,t[39]=u,t[40]=s,t[41]=f,t[42]=S,t[43]=P):P=t[43];let F;return t[44]!==j||t[45]!==M||t[46]!==N||t[47]!==P?(F=(0,$.jsxs)(`div`,{className:`mt-2`,children:[j,M,N,P]}),t[44]=j,t[45]=M,t[46]=N,t[47]=P,t[48]=F):F=t[48],F},AD=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=os(),i=c(UD),{isMobile:a}=mo(),{t:o}=ot(),s;t[0]!==r||t[1]!==a?(s=r&&!a&&!d(),t[0]=r,t[1]=a,t[2]=s):s=t[2];let l=!!s,u;t[3]!==n.state||t[4]!==o?(u=n.state===`completed`?o(`chat.messageBody.subagent.completed`):n.state===`error`?o(`chat.messageBody.subagent.error`):o(`chat.messageBody.subagent.cancelled`),t[3]=n.state,t[4]=o,t[5]=u):u=t[5];let f=u,p=n.state===`completed`?o(`chat.messageBody.subagent.completedDescription`):n.state===`error`?o(`chat.messageBody.subagent.errorDescription`):o(`chat.messageBody.subagent.cancelledDescription`),m=n.description||p,h=q(()=>{!l||!r||i(r,{mode:`chat`,dedupeKey:`session:${n.sessionID}`,label:m,readOnly:!0})}),g;t[6]===h?g=t[7]:(g=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())},t[6]=h,t[7]=g);let _=q(g),v=l&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,y;t[8]===v?y=t[9]:(y=Y(`mt-2 flex min-w-0 gap-2.5 rounded-[var(--radius-lg)] border border-border/60 bg-muted/20 px-3 py-2.5`,v),t[8]=v,t[9]=y);let b=l?`button`:void 0,x=l?0:void 0,S=l?o(`chat.messageBody.subagent.openSession`,{label:m}):void 0,C=l?h:void 0,w=l?_:void 0,T;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(`span`,{className:`mt-0.5 flex size-6 flex-shrink-0 items-center justify-center rounded-md bg-foreground/5 text-muted-foreground`,children:(0,$.jsx)(X,{name:`robot-2`,className:`size-3.5`})}),t[10]=T):T=t[10];let E;t[11]===m?E=t[12]:(E=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:m}),t[11]=m,t[12]=E);let D=n.state===`completed`?`bg-[var(--status-success-background)] text-[var(--status-success)]`:n.state===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`,O;t[13]===D?O=t[14]:(O=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,D),t[13]=D,t[14]=O);let k;t[15]!==f||t[16]!==O?(k=(0,$.jsx)(`span`,{className:O,children:f}),t[15]=f,t[16]=O,t[17]=k):k=t[17];let A;t[18]!==E||t[19]!==k?(A=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[E,k]}),t[18]=E,t[19]=k,t[20]=A):A=t[20];let j;t[21]===n.body?j=t[22]:(j=n.body?(0,$.jsx)(`div`,{className:`typography-meta mt-1 max-h-16 overflow-hidden text-muted-foreground [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,children:(0,$.jsx)(Po,{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},jD={background:`transparent`,backgroundColor:`transparent`},MD=e=>{let t=(0,Q.c)(36),{part:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=Z.useRef(null),{t:c}=ot(),l;t[0]===n.shellAction?l=t[1]:(l=typeof n.shellAction?.command==`string`?n.shellAction.command.trim():``,t[0]=n.shellAction,t[1]=l);let u=l,d=typeof n.shellAction?.output==`string`?n.shellAction.output:``,f;t[2]===n.shellAction?f=t[3]:(f=typeof n.shellAction?.status==`string`?n.shellAction.status.trim().toLowerCase():``,t[2]=n.shellAction,t[3]=f);let p=f,m;t[4]===d?m=t[5]:(m=d.trim(),t[4]=d,t[5]=m);let h=m.length>0,g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{s.current!==null&&typeof window<`u`&&(window.clearTimeout(s.current),s.current=null)},t[6]=g):g=t[6];let _=q(g),v,y;t[7]===_?(v=t[8],y=t[9]):(v=()=>()=>{_()},y=[_],t[7]=_,t[8]=v,t[9]=y),Z.useEffect(v,y);let b;t[10]!==_||t[11]!==h||t[12]!==d?(b=async()=>{h&&(await ct(d)).ok&&(_(),o(!0),typeof window<`u`&&(s.current=window.setTimeout(()=>{o(!1),s.current=null},2e3)))},t[10]=_,t[11]=h,t[12]=d,t[13]=b):b=t[13];let x=q(b),S;t[14]===c?S=t[15]:(S=c(`chat.messageBody.shellCommand.title`),t[14]=c,t[15]=S);let C;t[16]===S?C=t[17]:(C=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:S}),t[16]=S,t[17]=C);let w;t[18]===p?w=t[19]:(w=p?(0,$.jsx)(`span`,{className:Y(`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none`,p===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`),children:p}):null,t[18]=p,t[19]=w);let T;t[20]!==w||t[21]!==C?(T=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[C,w]}),t[20]=w,t[21]=C,t[22]=T):T=t[22];let E;t[23]===u?E=t[24]:(E=u?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 overflow-x-auto font-mono`,children:(0,$.jsx)(ec,{language:`bash`,code:u,codeStyle:jD,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(WD),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)(ec,{language:`bash`,code:d,codeStyle:jD,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},ND=e=>{let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},PD=(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}},FD=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:s,hasTextContent:l,onCopyMessage:u,copiedMessage:d,onShowPopup:f,agentMention:p,onEdit:m,onRevert:h,onFork:g,pendingMessageAction:_,editing:v,editStaged:y,onCancelEdit:b,userActionsMode:x=`inline`,stickyUserHeaderEnabled:S=!0})=>{let{locale:C,t:w}=ot(),T=Ph(),E=$m(Qm()),D=c(e=>e.timeFormatPreference),[O,k]=Z.useState(!1),A=Z.useRef(null),j=Z.useMemo(()=>n.filter(e=>e.type===`text`?!Tn(e):!!(ED(e)||DD(e))),[n]),M=Z.useMemo(()=>j.map(e=>Yn(e)?Ox(Pt(e)):void 0),[j]),N=p?.token,P=!1,F=!!u,I=!!d,L=!!(s??a),R=!!l,z=x!==`external-actions`,B=x!==`external-content`,V=S&&x===`inline`,H=q(()=>{A.current!==null&&typeof window<`u`&&(window.clearTimeout(A.current),A.current=null)}),U=q(()=>{!L||!F||!R||typeof window>`u`||(H(),k(!0),A.current=window.setTimeout(()=>{k(!1),A.current=null},1800))});Z.useEffect(()=>{R||(k(!1),H())},[H,R]);let W=q(e=>{!u||!R||(e.stopPropagation(),e.preventDefault(),u(),L&&U())}),ee=T===`mini-chat`||!E.fork?void 0:g,G=Z.useMemo(()=>{if(typeof i!=`number`||i<=0)return null;let e=XT(i,D);return e.length>0?e:null},[C,i,D]),K=Y(`group/user-actions`,a?x===`inline`?`flex items-center justify-end pt-2 pb-3`:S?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:x===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),te=!v&&y&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsxs)(`div`,{className:Y(uD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(fD,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:mD,name:`edit`,className:pD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:w(`chat.messageBody.actions.editStaged`)})]}),b?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,className:oD,"aria-label":w(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),b()},children:(0,$.jsx)(X,{weight:mD,name:`close`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:w(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,ne=(v&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsx)(`div`,{className:Y(uD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(fD,`animate-text-shimmer`),"aria-live":`polite`,children:w(`chat.messageBody.actions.editing`)})})}):null)??te??((F&&R||m||h||ee)&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsxs)(`div`,{className:Y(uD,`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)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(fD,`mr-1`),"aria-label":`Message time: ${G}`,children:[(0,$.jsx)(X,{weight:mD,name:`time`,className:pD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:G})]})}),(0,$.jsx)(za,{children:G})]}):null,h&&(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,className:oD,"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:mD,name:_===`revert`?`loader-4`:`arrow-go-back`,className:Y(sD,_===`revert`&&`animate-spin`)})})}),(0,$.jsx)(za,{sideOffset:6,children:w(`chat.messageBody.actions.revert`)})]}),m&&(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,className:oD,"aria-label":w(`chat.messageBody.actions.editAria`),disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:mD,name:`edit`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:w(`chat.messageBody.actions.edit`)})]}),ee&&(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,className:oD,"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:mD,name:_===`fork`?`loader-4`:`git-branch`,className:Y(sD,_===`fork`&&`animate-spin`)})})}),(0,$.jsx)(za,{sideOffset:6,children:w(`chat.messageBody.actions.fork`)})]}),F&&R&&(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":O||I?`true`:void 0,className:oD,"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:mD,name:`check`,className:Y(sD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:mD,name:`file-copy`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:w(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return z?(0,$.jsxs)(`div`,{className:`relative w-full group/message`,style:nD,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(ED(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(kD,{part:e})},e.id??`user-subtask-${i}`);if(DD(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(MD,{part:e})},e.id??`user-shell-${i}`);let o=M[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(AD,{notification:o})},e.id??`subagent-notification-${i}`);let s;return p&&N&&!P&&Pt(e).includes(N)&&(s=p,P=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(ax,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(nd,{files:n,messageID:t,sessionID:e,onShowPopup:f,compact:!0}),ne]}):(0,$.jsx)($.Fragment,{children:ne})}),ID=Z.memo(({hasCopyableText:e,isTouchContext:t,onCopyMessage:n,reviewTransferAction:r,ttsText:i,sessionId:a})=>{let{t:o}=ot(),s=Ph(),c=Qm(),l=$m(c),{isPlaying:u,play:d,stop:f}=kT(),p=Ei(e=>e.showMessageTTSButtons),m=Ei(e=>e.voiceProvider),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),[y,b]=Z.useState(!1),x=Z.useRef(null),S=Z.useRef(null),C=!!n,w=!!((c.sessionId||a)&&c.directory&&l.openSourceSession&&s!==`mini-chat`),T=q(()=>{x.current!==null&&typeof window<`u`&&(window.clearTimeout(x.current),x.current=null)}),E=q(()=>{S.current!==null&&typeof window<`u`&&(window.clearTimeout(S.current),S.current=null)});Z.useEffect(()=>()=>{T(),E()},[E,T]),Z.useEffect(()=>{(!e||!C)&&(g(!1),v(!1),T(),E())},[C,E,T,e]);let D=q(()=>{!t||!C||!e||typeof window>`u`||(T(),g(!0),x.current=window.setTimeout(()=>{g(!1),x.current=null},1800))}),O=q(async r=>{!n||!e||(r.stopPropagation(),r.preventDefault(),await n()!==!1&&(E(),v(!0),typeof window<`u`&&(S.current=window.setTimeout(()=>{v(!1),S.current=null},2e3)),t&&D()))}),k=q(async t=>{if(t.stopPropagation(),t.preventDefault(),!(!r||y||!e)){b(!0);try{await r.onClick()}finally{b(!1)}}}),A=q(e=>{e.stopPropagation(),e.preventDefault();let t=c.sessionId||a;!t||!c.directory||!c.openSourceSession||c.openSourceSession(t,c.directory)}),j=Z.useMemo(()=>u?o(`chat.messageBody.tts.stopSpeaking`):o(`chat.messageBody.tts.readAloudWithProvider`,{provider:m===`browser`?`Browser`:m===`openai`?`OpenAI`:m===`openai-compatible`?`Custom`:`Say`}),[u,o,m]),M=q(e=>{if(e.stopPropagation(),e.preventDefault(),u){f();return}i.trim()&&d(i)});return(0,$.jsxs)($.Fragment,{children:[n&&(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":h||_?`true`:void 0,className:Y(oD,!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:mD,name:`check`,className:Y(sD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:mD,name:`file-copy`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:o(`chat.messageBody.actions.copyAnswer`)})]}),w?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,className:oD,"aria-label":o(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:A,children:(0,$.jsx)(X,{weight:mD,name:`target`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:o(`chat.messageBody.actions.openSourceSession`)})]}):null,r&&s!==`mini-chat`&&l.reviewTransfer?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,size:`icon`,variant:`ghost`,disabled:y||!e,className:Y(oD,(!e||y)&&`opacity-50`),"aria-label":r.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{k(e)},children:y?(0,$.jsx)(X,{weight:mD,name:`loader-4`,className:Y(sD,`animate-spin`)}):(0,$.jsx)(X,{weight:mD,name:`arrow-left-right`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:r.tooltip})]}):null,s!==`mini-chat`&&p&&e&&(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,className:Y(oD,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:mD,name:`stop`,className:sD}):(0,$.jsx)(X,{weight:mD,name:`volume-up`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:j})]})]})}),LD=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:s,messageTokens:l,isMobile:u,alwaysShowActions:f,hasTouchInput:p,expandedTools:m,onToggleTool:h,onShowPopup:g,streamPhase:_,allowAnimation:v,onContentChange:y,hasTextContent:b=!1,onCopyMessage:x,onAuxiliaryContentComplete:S,showReasoningTraces:C=!1,turnGroupingContext:w,errorMessage:T,errorVariant:E=`error`,reviewTransferDirection:D=null})=>{let{t:O,locale:k}=ot(),A=Ph(),j=$m(Qm()),M=_,N=Z.useRef(null),P=Z.useRef(null),F=_===`streaming`||_===`cooldown`,I=Z.useRef({messageId:t,experiencedStreamingOrCooldown:F});I.current.messageId===t?F&&(I.current.experiencedStreamingOrCooldown=!0):I.current={messageId:t,experiencedStreamingOrCooldown:F};let L=!!(p??u),R=!!(f??u),z=u?lD:cD,B=!i,V=Z.useMemo(()=>n.filter(e=>!Tn(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(()=>Gn(U),[U]),ee=c(e=>e.openContextPreview),G=d(),K=A===`mini-chat`,te=Z.useMemo(()=>{if(G||u||K)return null;for(let e of U){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=es(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=es(n.replace(/\x1b\[[0-9;]*m/g,``))[0];if(r)return r.includes(`0.0.0.0`)?r.replace(`0.0.0.0`,`127.0.0.1`):r}return null},[U,u,K,G,H]),ne=J(e=>e.forkFromMessage),re=J(e=>e.forkTransition),ie=J(e=>e.currentSessionId),ae=J(e=>e.getDirectoryForSession),oe=os(),se=D===`review-to-original`,ce=!u&&!G?D:null,le=Z.useMemo(()=>{let t=W.trim();if(!(!e||!oe||!t||!ce))return ce===`review-to-original`?{ariaLabel:O(`chat.messageBody.actions.sendReviewFeedback`),tooltip:O(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await yt(e,oe,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:O(`chat.messageBody.actions.sendImplementationResponse`),tooltip:O(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await $r(e,oe,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[W,oe,ce,e,O]),[ue,de]=Z.useState(!1),fe=c(e=>e.chatRenderMode),pe=c(e=>e.collapsibleThinkingBlocks),me=c(e=>e.showSplitAssistantMessageActions),he=c(e=>e.showAssistantTps),ge=c(e=>e.timeFormatPreference),_e=fe===`sorted`,ve=w?.isLastAssistantInTurn??!1,ye=a===`stop`,be=(ye||i||!!T)&&(w?.isTurnSettled??!0),xe=ye?`completed`:M,Se=H.length>0,Ce=Z.useMemo(()=>H.some(e=>iC(e)),[H]),we=iC,Te=rC,Ee=I.current.experiencedStreamingOrCooldown,De=Z.useRef({messageId:t,initialized:!1,observedPartIds:new Set});Z.useEffect(()=>{if(De.current.messageId!==t&&(De.current={messageId:t,initialized:!1,observedPartIds:new Set}),!Ee||!Vn())return;let n=De.current,r=!n.initialized;n.initialized=!0;for(let i of H){if(n.observedPartIds.has(i.id))continue;if(!Ft(r,we(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Ot({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[Ee,we,t,e,H]);let Oe=Z.useMemo(()=>H.length===0||!Ce&&H.every(e=>Te(e)),[H,Ce,Te]),ke=Z.useMemo(()=>V.filter(e=>e.type===`reasoning`),[V]),Ae=Z.useMemo(()=>ke.length===0||ke.every(e=>typeof e.time?.end==`number`),[ke]),je=typeof a!=`string`,Me=ke.length>0&&Se&&(Ce||je||!Oe),Ne=B||Se&&(Ce||je||!Oe),Pe=B||Me,Fe=Se||ke.length>0,Ie=U.length===0,Le=Fe&&Ie&&!Ne&&!Pe&&Oe&&Ae,Re=Z.useRef(!1),ze=Z.useRef(!1);Z.useEffect(()=>{ze.current=!1},[t]),Z.useEffect(()=>{if(!Le){Re.current=!1;return}Re.current||(Re.current=!0,S?.())},[Le,S]),Z.useEffect(()=>{if(B){ze.current=!1;return}if(Se){ze.current=!1;return}ke.length!==0&&(Pe||!Ae||ze.current||(ze.current=!0,y?.(`structural`)))},[B,Se,y,Ae,ke.length,Pe]);let Be=!!b&&!B,Ve=q(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||ue||re)){de(!0);try{await ne(e,t)}finally{de(!1)}}}),He=Z.useMemo(()=>{let e=w?.activityParts;return!_e||!e?[]:e},[_e,w?.activityParts]),Ue=Z.useMemo(()=>{let e=w?.activityGroupSegments;return!_e||!e?[]:e.filter(e=>e.anchorMessageId===t)},[_e,t,w?.activityGroupSegments]),We=Ue.length>0,Ge=Z.useMemo(()=>{let e=new Map,t=new Map;return He.forEach(n=>{e.set(n.part,n);let r=n.part.id;typeof r==`string`&&r.length>0&&t.set(r,n)}),{get:n=>{let r=e.get(n);if(r)return r;let i=n.id;if(typeof i==`string`&&i.length>0)return t.get(i)}}},[He]),Ke=w?.toggleGroup,qe=w?.activityPresentationKind===`compaction`,Je=w?.isGroupExpanded===!0,Ye=_e&&qe&&!Je,Xe=_e?w?.activityOwnerMessageId===t||We:!w?.activityOwnerMessageId||w.activityOwnerMessageId===t||We,Ze=_e&&Xe&&(We||qe)&&!!Ke,Qe=iT(a,V),$e={finish:a,parts:V,streamPhase:xe,error:T,isLastAssistantInTurn:ve},et=lT($e),tt=_e&&uT($e),nt=_e&&!et&&!(qe&&Je),rt=!!T,it=E===`info`?`information`:`error-warning`,at=Be,st=ve&&be&&!Ye&&(b||!!T||i),lt=w?.diffStats?.hasDiffs===!0,ut=!K&&ve&&Qe&&be&&!Ye&&w?.diffStats?.hasDiffs===!0,dt=me&&at&&!st&&!_e,ft=Z.useMemo(()=>(0,$.jsx)(ID,{hasCopyableText:Be,isTouchContext:L,onCopyMessage:x,ttsText:W,reviewTransferAction:le,sessionId:e}),[W,Be,L,x,le,e]),pt=Z.useMemo(()=>e=>{if(!me||!_e)return null;let t=Pt(e.part).trim();return t?(0,$.jsx)(ID,{hasCopyableText:!0,isTouchContext:L,onCopyMessage:async()=>(await ct(t)).ok,ttsText:t}):null},[_e,L,me]),mt=Z.useMemo(()=>{if(!dt)return-1;let e=-1;for(let t=0;t<V.length;t+=1){let n=V[t];!n||n.type!==`text`||nt||Ge.get(n)?.kind!==`justification`&&(e=t)}return e},[Ge,nt,dt,V]),ht=dt&&mt<0,gt=Z.useMemo(()=>{let n=[];if(Ze&&Ke&&w){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(tD,{parts:t,materializationParts:r,isExpanded:w.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:w.completionDisposition,activityPresentationKind:w.activityPresentationKind,durationMs:w.durationMs,startedAt:w.userMessageCreatedAt,onToggle:Ke,isMobile:u,expandedTools:m,onToggleTool:h,onShowPopup:g,onContentChange:y,streamPhase:xe,showHeader:!0,diffStats:w.diffStats,renderJustificationActions:pt})},`progressive-group-${e}`))};Ue.length>0?Ue.forEach(t=>{let n=C?t.parts:t.parts.filter(e=>e.kind!==`reasoning`);e(t.id,n,t.parts)}):qe&&e(`${t}:compaction-status`,[])}let r=0;for(;r<V.length;){let i=V[r];if(i.type===`text`){let a=Ge.get(i);if(nt){r+=1;continue}if(Ye){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:P,"data-message-text-export-source":`true`,children:(0,$.jsx)(Iw,{part:i,sessionId:e,messageId:t,streamPhase:xe,chatRenderMode:fe,allowSortedFinalStreaming:tt,hasStreamingHapticLifecycle:Ee,onContentChange:y,onShowPopup:g})},`assistant-text-${t}-${i.id??r}`)),dt&&r===mt&&n.push((0,$.jsx)(`div`,{className:u?aD:iD,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:uD,"data-message-action-group":`true`,children:ft})},`message-actions-${t}`)),r++;continue}if(i.type===`reasoning`){if(Ge.get(i)?.kind===`reasoning`){r+=1;continue}if(!Pt(i).trim()){r+=1;continue}C&&(pe?n.push((0,$.jsx)(`div`,{className:kp(u),children:(0,$.jsx)(Jw,{part:i,messageId:t,streamPhase:xe,onContentChange:y})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(Iw,{part:i,sessionId:e,messageId:t,streamPhase:xe,chatRenderMode:fe,hasStreamingHapticLifecycle:Ee,onContentChange:y,onShowPopup:g},`reasoning-${t}-${i.id??r}`))),r++;continue}if(i.type===`tool`){let e=i,a=e.tool?.toLowerCase()??``;if(_e&&!Xe){r+=1;continue}if(Ge.get(i)?.kind===`tool`){r+=1;continue}if(tC(a)){let e=[],i=r;for(;i<V.length;){let n=V[i];if(n.type!==`tool`)break;let r=n;if(!tC(r.tool?.toLowerCase()??``)||Ge.get(n)?.kind===`tool`)break;e.push({id:r.id,turnId:``,messageId:t,partIndex:i,part:r,kind:`tool`}),i+=1}if(e.length>0){n.push((0,$.jsx)(pE,{activities:e,isMobile:u,isTurnLive:xe!==`completed`,hasFollowingOtherType:lE(V,i,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:e.map(e=>(0,$.jsx)(qE,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`context-tools-${e[0].id}`)),r=i;continue}}if(nC(a)){let e=mE(V,r,e=>e.type!==`tool`||Ge.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(yE,{activities:i,isMobile:u,children:i.map(e=>(0,$.jsx)(qE,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(QS(a)){n.push((0,$.jsx)(`div`,{className:kp(u),children:(0,$.jsx)(gw,{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:kp(u),children:(0,$.jsx)(qE,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:u,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}return n},[Ge,Ue,R,fe,pe,0,m,Ye,qe,u,Xe,_e,mt,t,ft,pt,e,y,g,h,Ze,dt,xe,Ee,C,nt,tt,Ke,w,V]),_t=Z.useMemo(()=>{if(!ve||!be)return;let e=w?.durationMs;if(!(typeof e!=`number`||e<=0))return ND(e)},[ve,be,w?.durationMs]),vt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof s==`number`&&s>0?s:null;if(e===null)return null;let t=XT(e,ge);return t.length>0?t:null},[o,s,ge,k]),bt=Z.useMemo(()=>{if(!he||!ve||!be)return null;let e=r??n,t=PD(e,l),i=tE({createdAt:s,completedAt:o,fallbackDurationMs:w?.durationMs,outputTokens:t.output,reasoningTokens:t.reasoning,parts:e});if(i===null)return null;let a=nE(i);return a.length>0?a:null},[he,ve,be,n,r,l,s,o,w?.durationMs]),xt=(0,$.jsxs)($.Fragment,{children:[!K&&!u&&!G&&te?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,variant:`ghost`,size:`icon`,className:oD,"aria-label":O(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=oe??(ie?ae(ie):null);e&&ee(e,te)},children:(0,$.jsx)(X,{weight:mD,name:`global`,className:sD})})}),(0,$.jsx)(za,{sideOffset:6,children:O(`chat.messageBody.actions.openPreview`)})]}):null,!K&&!se&&j.fork?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsx)(da,{type:`button`,size:`icon`,variant:`ghost`,className:oD,"aria-label":O(`chat.messageBody.actions.forkAria`),"aria-busy":ue,disabled:ue||!!re,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Ve(e)},children:(0,$.jsx)(X,{weight:mD,name:ue?`loader-4`:`git-branch`,className:Y(sD,ue&&`animate-spin`)})})}),(0,$.jsx)(za,{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:nD,children:[(0,$.jsx)(KT,{containerRef:N}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`message-content-text leading-relaxed text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0`,children:[gt,rt&&(0,$.jsx)(ps,{children:(0,$.jsxs)(`div`,{className:Y(`group/assistant-text relative flow-root my-1.5 break-words max-w-full`,E===`info`?Y(`inline-flex w-fit max-w-full border border-[var(--status-info-border)]/45 bg-[var(--status-info-background)]/40`,u?`items-start gap-1.5 rounded-lg px-2.5 py-1.5`:Y(`items-center gap-1.5`,`rounded-lg px-2 py-0.5`)):`mt-3 flex items-center gap-2 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3`),children:[E===`info`&&u?(0,$.jsx)(`span`,{className:`inline-flex h-5 w-3.5 shrink-0 items-center justify-center translate-y-[2px]`,"aria-hidden":`true`,children:(0,$.jsx)(X,{name:it,weight:mD,className:Y(sD,`text-[var(--status-info)]/80`)})}):(0,$.jsx)(X,{name:it,weight:E===`info`?mD:void 0,className:Y(`shrink-0`,E===`info`?Y(sD,`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)(Po,{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)(TD,{fileCount:w.diffStats.files,changedFiles:w.changedFiles,turnId:w.turnId,isLatestTurn:w.isLatestTurn,isMobile:u}):null,(0,$.jsx)(nd,{files:n,messageID:t,sessionID:e,onShowPopup:g}),ht&&(0,$.jsx)(`div`,{className:Y(u?aD:iD),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:uD,"data-message-action-group":`true`,children:ft})}),st&&(0,$.jsxs)(`div`,{className:z,"data-message-footer":`true`,style:rD,children:[(0,$.jsxs)(`div`,{className:uD,"data-message-action-group":`true`,children:[ft,xt]}),bt||_t||vt?(0,$.jsxs)(`div`,{className:dD,children:[bt?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsxs)(`span`,{className:fD,"aria-label":O(`chat.messageBody.meta.tpsAria`,{rate:bt}),children:[(0,$.jsx)(X,{weight:mD,name:`pulse`,className:pD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:bt})]})}),(0,$.jsx)(za,{children:O(`chat.messageBody.meta.tpsTooltip`)})]}):null,_t?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsxs)(`span`,{className:fD,children:[(0,$.jsx)(X,{weight:mD,name:`hourglass`,className:pD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:_t})]})}),(0,$.jsx)(za,{children:_t})]}):null,vt?(0,$.jsxs)(Ba,{children:[(0,$.jsx)(Ra,{asChild:!0,children:(0,$.jsxs)(`span`,{className:fD,"aria-label":`Message time: ${vt}`,children:[(0,$.jsx)(X,{weight:mD,name:`time`,className:pD}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:vt})]})}),(0,$.jsx)(za,{children:vt})]}):null]}):null,!K&&ve&&ye&&!lt?(0,$.jsx)(Qw,{activityParts:w?.activityParts}):null]})]})]})}),RD=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)(FD,{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)(LD,{...r}),t[26]=r,t[27]=i),i});function zD(e){return e.openContextPanelTab}function BD(e){return e.setCurrentSession}function VD(e){return e.openContextPanelTab}function HD(e){return!e}function UD(e){return e.openContextPanelTab}function WD(e){return!e}var GD=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}},KD=`Authentication failed for this provider. Please re-authenticate and retry.`,qD=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},JD=Lo(()=>Ue(()=>import(`./ToolOutputDialog-B-3Wg0na.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]))),YD=4e3,XD=new Map,ZD=new Map,QD=new Set([`bash`,`shell`,`cmd`,`terminal`]),$D=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},eO=e=>{let t=XD.get(e);return t?new Set(t):new Set},tO=(e,t)=>{if(XD.size>=YD&&!XD.has(e)){let e=XD.keys().next().value;typeof e==`string`&&XD.delete(e)}XD.set(e,new Set(t))},nO=e=>{let t=ZD.get(e);return t?new Set(t):new Set},rO=(e,t)=>{if(ZD.size>=YD&&!ZD.has(e)){let e=ZD.keys().next().value;typeof e==`string`&&ZD.delete(e)}ZD.set(e,new Set(t))},iO=200,aO=new Map,oO=e=>aO.get(e),sO=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=aO.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(aO.size>=iO&&!aO.has(e)){let e=aO.keys().next().value;typeof e==`string`&&aO.delete(e)}aO.set(e,t)}};function cO(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 lO=(e,t)=>{if(typeof e==`object`&&e)return e[t]},uO=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s=!1,activeStreamingPhase:l=null,animateUserOnMount:u=!1,onUserAnimationConsumed:d,reviewTransferDirection:f=null})=>{let{isMobile:p,isTablet:m,hasTouchInput:h}=mo(),g=Qm(),_=$m(g),v=p||m,y=Z.useRef(null),b=J(e=>e.currentSessionId),x=xt(e=>e.getAgentModelForSession),S=xt(e=>e.getSessionModelSelection),C=J(e=>e.revertToMessage),w=J(e=>e.editMessagePreservingChanges),T=J(e=>e.forkFromMessage),E=J(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),D=J(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),O=J(e=>e.clearStagedMessageEdit);Ie(`ui.chat_message.render`),s&&Ie(`ui.chat_message.render.streaming`);let k=Ei(e=>e.providers),{showReasoningTraces:A,stickyUserHeader:j,chatRenderMode:M,showExpandedBashTools:N}=c(me(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{b&&Kb.getInstance().recordSessionStart(b)},[b]);let[P,F]=Z.useState(null),[I,L]=Z.useState(!1),[R,z]=Z.useState(null),B=Z.useRef(null),[V,H]=Z.useState(()=>eO(e.info.id)),[U,W]=Z.useState(()=>nO(e.info.id)),[ee,G]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{H(eO(e.info.id)),W(nO(e.info.id))},[e.info.id]);let K=Z.useMemo(()=>GD(e.info),[e.info]).isUser,te=K&&(p||!j),ne=K&&!p&&j&&!te,re=e.info.sessionID,ie=qb(e=>e.planModeEnabled),{currentContextAgent:ae,savedSessionAgentSelection:oe}=Wp(me(e=>({currentContextAgent:s&&re?e.currentAgentContext.get(re):void 0,savedSessionAgentSelection:s&&re?e.sessionAgentSelections.get(re):void 0}))),se=Z.useMemo(()=>Qr(e.sourceParts??e.parts),[e.parts,e.sourceParts]),ce=Z.useMemo(()=>K?Bn(se,{planModeEnabled:ie}):Qr(e.parts),[K,e.parts,ie,se]),le=Z.useMemo(()=>{if(K||!t)return null;let e=lO(t.info,`clientRole`),n=lO(t.info,`role`);if((typeof e==`string`?e:typeof n==`string`?n:void 0)!==`user`)return null;let r=lO(t.info,`mode`),i=lO(t.info,`agent`),a=lO(t.info,`providerID`),o=lO(t.info,`modelID`),s=lO(t.info,`variant`),c=typeof r==`string`&&r.trim().length>0?r:typeof i==`string`&&i.trim().length>0?i:void 0,l=typeof a==`string`&&a.trim().length>0?a:void 0,u=typeof o==`string`&&o.trim().length>0?o:void 0,d=typeof s==`string`&&s.trim().length>0?s:void 0;return!c&&!l&&!u&&!d?null:{agentName:c,providerId:l,modelId:u,variant:d}},[K,t]),ue=Z.useMemo(()=>{if(!ie||K||!t)return!1;let e=Array.isArray(t.parts)?t.parts:[];for(let t=0;t<e.length;t++){let n=e[t];if(n?.type!==`text`||n?.synthetic!==!0)continue;let r=typeof n.text==`string`?n.text.trim():``;if(r.startsWith(`User has requested to enter plan mode`)||r.startsWith(`The plan at `))return!0}return!1},[K,ie,t]),de=Z.useMemo(()=>{if(K)return;let t=e.info.time;if(!(typeof t?.completed==`number`&&t.completed>0)&&ue&&le?.agentName)return le.agentName;let n=lO(e.info,`mode`);if(typeof n==`string`&&n.trim().length>0)return n;let r=lO(e.info,`agent`);if(typeof r==`string`&&r.trim().length>0)return r;if(le?.agentName)return le.agentName;if(re)return ae||(oe??void 0)},[K,e.info,ue,le,re,ae,oe]),fe=K?null:lO(e.info,`providerID`),pe=K?null:lO(e.info,`modelID`),he=Z.useMemo(()=>{if(K||!re)return null;if(le?.providerId&&le?.modelId)return{providerId:le.providerId,modelId:le.modelId};if(de){let e=x(re,de);if(e?.providerId&&e?.modelId)return e}let e=S(re);return e?.providerId&&e?.modelId?e:null},[K,re,de,le,x,S]),ge=Z.useMemo(()=>K?null:typeof fe==`string`&&fe.trim().length>0?fe:he?.providerId??null,[K,fe,he]),_e=Z.useMemo(()=>K?null:typeof pe==`string`&&pe.trim().length>0?pe:he?.modelId??null,[K,pe,he]),ve=e.info.id?oO(e.info.id):void 0;K||sO(e.info.id,{agent:de,provider:ge??void 0,model:_e??void 0});let ye=de??ve?.agent,be=ge??ve?.provider??null,xe=_e??ve?.model??null,Se=Z.useMemo(()=>{if(K)return;let e=be&&k.length>0?k.find(e=>e.id===be):void 0;return tn(e,xe)||void 0},[K,be,xe,k]),Ce=Z.useMemo(()=>{if(K||!ge||!_e)return!1;let e=k.find(e=>e.id===ge);if(!e?.models||!Array.isArray(e.models))return!1;let t=e.models.find(e=>e.id===_e)?.variants;return!!(t&&Object.keys(t).length>0)},[K,_e,ge,k]),we=cO(ye),Te=cO(be??void 0),Ee=cO(xe??void 0),De=cO(Se),Oe=we??void 0,ke=Te??null,Ae=Ee??null,je=De??void 0,Me=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),Ne=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Pe=Z.useMemo(()=>K?!0:!!(Me&&Me>0),[K,Me]),Fe=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),Le=Z.useMemo(()=>{if(K)return null;let t=e.info.tokens;return!t||typeof t!=`object`?null:{output:typeof t.output==`number`?t.output:void 0,reasoning:typeof t.reasoning==`number`?t.reasoning:void 0}},[K,e.info]),Re=Z.useMemo(()=>jt(ce,{includeReasoning:A}),[ce,A]),ze=Z.useMemo(()=>K?Re:!Pe&&M===`sorted`?[]:Re,[M,Pe,K,Re]),Be=Z.useMemo(()=>K?[]:Re.filter(e=>e.type===`text`),[K,Re]),Ve=Z.useMemo(()=>K?[]:Re.filter(e=>e.type===`tool`),[K,Re]),He=Z.useMemo(()=>{if(!N)return new Set;let e=new Set;for(let t of Ve){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=$D(t.tool);!r||!QD.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=$D(t.part.tool);!n||!QD.has(n)||e.add(t.id)}return e},[N,Ve,a?.activityParts]),Ue=Z.useMemo(()=>{if(He.size===0&&U.size===0)return V;let e=new Set(V);return He.forEach(t=>{U.has(t)||e.add(t)}),U.forEach(t=>{e.delete(t)}),e},[U,He,V]),We=Z.useMemo(()=>{if(!K)return;let e=ce.find(e=>e.type===`agent`);if(!e)return;let t=e,n=typeof t.name==`string`?t.name:void 0;if(n)return{name:n,token:t.source&&typeof t.source.value==`string`&&t.source.value.trim().length>0?t.source.value:`@${n}`}},[K,ce]),Ge=K&&!zi(ze),Ke=typeof Fe!=`string`,qe=Z.useMemo(()=>K?!1:Be.length===0||Ve.length===0?Ke:!0,[Be.length,Ve.length,Ke,K]),Je=Z.useMemo(()=>!K&&Kb.getInstance().shouldAnimateMessage(e.info,b||e.info.sessionID),[e.info,b,K]),[Ye,Xe]=Z.useState(!1),Ze=Z.useMemo(()=>n?GD(n.info):null,[n]),Qe=!!a,$e=a?.isLastAssistantInTurn??!1,et=a?.isWorking===!0||s,tt=Z.useMemo(()=>K?!1:Qe?!$e:Ze?!Ze.isUser&&Ze.role===`assistant`:!1,[Qe,$e,K,Ze]),nt=Z.useMemo(()=>Pe?`completed`:s?l??`streaming`:`completed`,[l,s,Pe]);Z.useEffect(()=>{!K||!u||d?.(e.info.id)},[u,K,e.info.id,d]),Z.useEffect(()=>{Xe(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;K||!t||t!==e.info.id||(nt===`streaming`||nt===`cooldown`)&&Xe(!0)},[o,K,e.info.id,nt,a?.headerMessageId]);let rt=Z.useMemo(()=>{if(K)return!0;let t=o??a?.headerMessageId;return t?e.info.id===t?nt===`completed`||Ye||nt===`streaming`||nt===`cooldown`:!1:!0},[o,Ye,K,a,nt,e.info.id]),it=Z.useCallback(e=>{ct(e).then(t=>{t.ok&&(F(e),setTimeout(()=>F(null),2e3))})},[]),at=K?void 0:a?.userMessageVariant??le?.variant,ot=!K&&Ce&&typeof at==`string`&&at.trim().length>0?at:void 0,st=Z.useMemo(()=>{if(K)return;let t=e.info?.error;if(!t)return;let n=typeof t.data?.message==`string`?t.data.message:void 0,r=typeof t.message==`string`?t.message:void 0,i=typeof t.name==`string`?t.name:void 0,a=n||r||i;if(a)return i===`SessionRetry`?{text:`Opencode failed to send a message. Retry attempt info: \n\`${a}\``,variant:`info`}:qD(a)?{text:KD,variant:`error`}:a.trim().toLowerCase()===`aborted`?{text:`The running turn was stopped before OpenCode could send the next message.`,variant:`info`}:{text:`Opencode failed to send message with error:\n\`${a}\``,variant:`error`}},[K,e.info]),lt=st?.text,ut=st?.variant,dt=Z.useMemo(()=>{if(K){let e=ze.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.output;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);if(e.length>0)return e.join(`
|
|
6577
6577
|
|
|
6578
6578
|
`);let t=ze.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.command;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);return t.length>0?t.join(`
|
|
6579
6579
|
`):ze.filter(e=>e.type===`text`).map(e=>(e.text||e.content||``).trim()).filter(e=>e.length>0).join(`
|
|
6580
6580
|
`).replace(/\n\s*\n+/g,`
|
|
6581
|
-
`)}return lt&<.trim().length>0?lt:Gn(ze)},[lt,ze,K]),ft=dt.length>0,pt=Z.useCallback(async()=>(await ct(dt)).ok?(K&&(L(!0),setTimeout(()=>L(!1),2e3)),!0):!1,[K,dt]),mt=Z.useCallback(async()=>{if(!(!re||!e.info.id||B.current)){B.current=`revert`,z(`revert`);try{g.onRevertMessage?await g.onRevertMessage(e.info.id):await C(re,e.info.id,{directory:g.directory??void 0})}finally{B.current=null,z(null)}}},[re,e.info.id,C,g]),ht=q(()=>{if(!re||!e.info.id||B.current)return;let t={info:e.info,parts:e.parts};if(g.onEditMessage){g.onEditMessage(e.info.id,t).catch(()=>{});return}w(re,e.info.id,t).catch(()=>{})}),gt=q(()=>{re&&O(re)}),_t=Z.useCallback(async()=>{if(e.info.id,!re||!e.info.id){console.warn(`[session-fork] message action is missing identifiers`,{hasSessionId:!!re,hasMessageId:!!e.info.id});return}if(!B.current){B.current=`fork`,z(`fork`);try{await T(re,e.info.id)}finally{B.current=null,z(null)}}},[re,e.info.id,T]),vt=q(t=>{let n=He.has(t),r=Ue.has(t);if(n){W(n=>{let i=new Set(n);return r?i.add(t):i.delete(t),rO(e.info.id,i),i}),r||H(n=>{let r=new Set(n);return r.delete(t),tO(e.info.id,r),r});return}H(n=>{let r=new Set(n);return r.has(t)?r.delete(t):r.add(t),tO(e.info.id,r),r}),W(n=>{if(!n.has(t))return n;let r=new Set(n);return r.delete(t),rO(e.info.id,r),r})}),yt=i??null,bt=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,bt.current=!1,Et.current=!1},[e.info.id]);let Dt=Z.useCallback(()=>{K||bt.current||(bt.current=!0,r?.(`structural`))},[K,r]),Ot=c(e=>e.setImagePreviewOpen),kt=Z.useCallback(e=>{(e.image||e.mermaid)&&(G(e),Ot(!0))},[Ot]),At=Z.useCallback(e=>{G(t=>({...t,open:e})),Ot(e)},[Ot]),Mt=!!lO(e.info,`animationSettled`),Nt=nt===`streaming`||nt===`cooldown`;Nt&&(Et.current=!0);let Pt=Z.useMemo(()=>!K&&Re.some(e=>e.type===`reasoning`),[K,Re]),Ft=Je&&!Mt&&!Nt&&!Et.current,It=!K&&Je&&Be.length>0&&!qe;return Z.useEffect(()=>{if(yt?.onStreamingCandidate){if(!It){Ct.current&&=(Pt&&yt?.onReasoningBlock?yt.onReasoningBlock():yt?.onReservationCancelled&&yt.onReservationCancelled(),!1);return}Tt.current||(Tt.current=!0,yt.onStreamingCandidate(),Ct.current=!0)}},[yt,It,Pt]),Z.useEffect(()=>{yt?.onAnimationStart&&Ft&&(wt.current||=(yt.onAnimationStart(),!0))},[yt,Ft]),Z.useEffect(()=>{if(K)return;let e=yt?.onAnimatedHeightChange;if(!e||!(Ft||It))return;let t=y.current;if(!t)return;if(typeof window>`u`||typeof ResizeObserver>`u`){e(t.getBoundingClientRect().height);return}let n=null,r=t=>{if(typeof window>`u`){e(t);return}n!==null&&window.cancelAnimationFrame(n),n=window.requestAnimationFrame(()=>{e(t)})},i=new ResizeObserver(e=>{let t=e[0];t&&r(t.contentRect.height)});return i.observe(t),r(t.getBoundingClientRect().height),()=>{n!==null&&(window.cancelAnimationFrame(n),n=null),i.disconnect()}},[Ft,K,yt,It]),Ge?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Y(`group w-full`,K?p?`pt-2`:`pt-6`:!K&&rt?p?j?`pt-4`:`pt-0`:`pt-6`:`pt-0`,K||tt?`pb-0`:et?`pb-1`:`pb-8`),id:`message-${e.info.id}`,"data-message-id":e.info.id,ref:y,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:K?zi(ze)?(0,$.jsx)(ps,{forceAnimation:!0,skipAnimation:!u,ignoreContextDisabled:!0,respectReducedMotion:!0,children:(0,$.jsx)(`div`,{className:Y(`relative flex justify-end`,p?void 0:`group/user-shell`),children:(0,$.jsxs)(`div`,{className:Y(`max-w-[85%]`,ne?`pb-5`:void 0),children:[(0,$.jsx)(`div`,{style:{backgroundColor:`var(--chat-user-message-bg)`,borderRadius:`var(--radius-xl)`,borderBottomRightRadius:`var(--radius-sm)`},className:`px-3 py-1.5 shadow-none border border-primary/5`,children:(0,$.jsx)(RD,{messageId:e.info.id,parts:ze,sourceParts:se,isUser:K,isMessageCompleted:Pe,messageFinish:Fe,messageCreatedAt:Ne??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:it,expandedTools:V,onToggleTool:vt,onShowPopup:kt,streamPhase:nt,allowAnimation:Ft,onContentChange:r,shouldShowHeader:!1,hasTextContent:ft,onCopyMessage:pt,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:Dt,agentMention:We,onEdit:!E&&_.edit?ht:void 0,onRevert:!E&&_.revert?mt:void 0,onFork:!E&&K&&_.fork?_t:void 0,editing:E,editStaged:D,onCancelEdit:D?gt:void 0,pendingMessageAction:R,errorMessage:lt,errorVariant:ut,userActionsMode:te?`external-content`:`inline`,stickyUserHeaderEnabled:j})}),te?(0,$.jsx)(RD,{messageId:e.info.id,parts:ze,sourceParts:se,isUser:K,isMessageCompleted:Pe,messageFinish:Fe,messageCreatedAt:Ne??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:it,expandedTools:V,onToggleTool:vt,onShowPopup:kt,streamPhase:nt,allowAnimation:Ft,onContentChange:r,shouldShowHeader:!1,hasTextContent:ft,onCopyMessage:pt,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:Dt,agentMention:We,onEdit:!E&&_.edit?ht:void 0,onRevert:!E&&_.revert?mt:void 0,onFork:!E&&K&&_.fork?_t:void 0,editing:E,editStaged:D,onCancelEdit:D?gt:void 0,pendingMessageAction:R,errorMessage:lt,errorVariant:ut,userActionsMode:`external-actions`,stickyUserHeaderEnabled:j}):null]})})}):null:(0,$.jsxs)(`div`,{className:`relative`,children:[rt&&(0,$.jsx)(Yb,{isUser:K,isMobile:p,providerID:ke,modelID:Ae,agentName:Oe,modelName:je,variant:ot}),(0,$.jsx)(RD,{sessionId:e.info.sessionID,messageId:e.info.id,parts:Re,sourceParts:ce,isUser:K,isMessageCompleted:Pe,messageFinish:Fe,messageCompletedAt:Me??void 0,messageCreatedAt:Ne??void 0,messageTokens:Le,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:it,expandedTools:Ue,onToggleTool:vt,onShowPopup:kt,streamPhase:nt,allowAnimation:Ft,onContentChange:r,shouldShowHeader:rt,hasTextContent:ft,onCopyMessage:pt,copiedMessage:I,onAuxiliaryContentComplete:Dt,showReasoningTraces:A,agentMention:We,turnGroupingContext:a,errorMessage:lt,errorVariant:ut,reviewTransferDirection:f})]})})}),ee.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(JD,{popup:ee,onOpenChange:At,isMobile:p})}):null]})},(e,t)=>Zx({info:e.message.info,parts:e.message.parts},{info:t.message.info,parts:t.message.parts})&&e.message.sourceParts===t.message.sourceParts&&Qx(e.previousMessage?{info:e.previousMessage.info,parts:e.previousMessage.parts}:void 0,t.previousMessage?{info:t.previousMessage.info,parts:t.previousMessage.parts}:void 0)&&Qx(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&&oS(e.turnGroupingContext,t.turnGroupingContext,e.message.info.id,GD(e.message.info).isUser)),dO=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}),fO=new Set,pO=()=>{},mO=()=>{},hO=Z.memo(e=>{let t=(0,Q.c)(26),{turn:n,activityExpanded:r,showCompactionStatus:i,onToggleActivity:a,stickyUserHeader:o,renderMessage:s}=e,l=o===void 0||o,u=c(gO),d=n.userMessage.info.time?.created,f=n.activityPresentationKind===`compaction`,p=`turn-${n.turnId}`,m;t[0]!==r||t[1]!==f||t[2]!==s||t[3]!==l||t[4]!==n.userMessage?(m=f?null:l?(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:s(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`})]}):s(n.userMessage,r),t[0]=r,t[1]=f,t[2]=s,t[3]=l,t[4]=n.userMessage,t[5]=m):m=t[5];let h;t[6]!==r||t[7]!==u||t[8]!==a||t[9]!==i||t[10]!==n.assistantMessages||t[11]!==n.completionDisposition||t[12]!==n.durationMs||t[13]!==d?(h=i?(0,$.jsx)(`div`,{className:`group w-full ${u?`pt-4`:`pt-6`} ${n.assistantMessages.length===0?`pb-8`:`pb-0`}`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(tD,{parts:[],isExpanded:r,completionDisposition:n.completionDisposition,activityPresentationKind:`compaction`,durationMs:n.durationMs,startedAt:typeof d==`number`?d:void 0,onToggle:a,isMobile:u,expandedTools:fO,onToggleTool:pO,onShowPopup:mO,streamPhase:n.completionDisposition===`active`?`streaming`:`completed`,showHeader:!0})})}):null,t[6]=r,t[7]=u,t[8]=a,t[9]=i,t[10]=n.assistantMessages,t[11]=n.completionDisposition,t[12]=n.durationMs,t[13]=d,t[14]=h):h=t[14];let g;t[15]!==r||t[16]!==s||t[17]!==n.assistantMessages?(g=(0,$.jsx)(dO,{assistantMessages:n.assistantMessages,activityExpanded:r,renderMessage:s}),t[15]=r,t[16]=s,t[17]=n.assistantMessages,t[18]=g):g=t[18];let _;return t[19]!==r||t[20]!==p||t[21]!==m||t[22]!==h||t[23]!==g||t[24]!==n.turnId?(_=(0,$.jsxs)(`section`,{className:`relative w-full`,id:p,"data-turn-id":n.turnId,"data-turn-activity-expanded":r,"data-scroll-spy-id":n.turnId,children:[m,h,g]}),t[19]=r,t[20]=p,t[21]=m,t[22]=h,t[23]=g,t[24]=n.turnId,t[25]=_):_=t[25],_});function gO(e){return e.isMobile}var _O=e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``},vO=e=>{let t=e?.type;return t===`compaction`||t===`text`&&_O(e).trim()===`/compact`},yO=e=>e?e.some(e=>vO(e)):!1,bO=e=>yO(e.parts),xO=e=>e?yO(e.sourceParts)||yO(e.parts):!1,SO=e=>{if(!bO(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}},CO=e=>{let t=Qr(e.parts);return t.length===e.parts.length?e:{...e,parts:t}},wO=new WeakMap,TO=e=>{let t=wO.get(e);if(t)return t;let n=SO(CO(e)),r=n.parts,i=Qi(r),a=i===r?n:{...n,parts:i,sourceParts:r};return wO.set(e,a),a},EO=(e,t,n)=>t.id??`${e}-part-${n}-${t.type}`,DO=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},OO=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},kO=e=>{let t=e.info.finish;return typeof t==`string`?t:void 0},AO=(e,t,n,r)=>({id:EO(t,n,r),turnId:e,messageId:t,part:n,partIndex:r,endedAt:DO(n)}),jO=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`&&OO(e)&&(r=!0)})});let i=!!e.summarySourceMessageId&&!!e.summarySourcePartId&&e.assistantMessages.some(t=>t.info.id===e.summarySourceMessageId&&iT(kO(t),t.parts));e.assistantMessages.forEach(n=>{let r=kO(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`?OO(o):void 0,u=EO(n.info.id,o,s),d=o.type===`text`&&typeof l==`string`&&iT(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({...AO(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}},MO=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}},NO=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},PO=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(!n)continue;let r=n.info.finish;if(iT(r,n.parts))for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||!aT(t))continue;let r=NO(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:EO(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=NO(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:EO(n.info.id,t,e)}}}return{}},FO=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}},IO=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},LO=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},RO=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},zO=e=>{let t=e.info.time?.created;return typeof t==`number`?t:void 0},BO=e=>{let t=e.info.time?.completed;return typeof t==`number`?t:void 0},VO=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},HO=e=>{let t=e.info?.summary?.body;if(typeof t==`string`)return t.trim().length>0?t:void 0},UO=(e,t)=>{let n=LO(e);return{messageId:e.info.id,role:n,parentMessageId:RO(e),message:e,order:t}},WO=(e,t)=>{let n=zO(e),r,i,a=!1;t.forEach(e=>{let t=BO(e);typeof t==`number`?r=Math.max(r??0,t):a=!0,e.parts.forEach(e=>{let t=VO(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}},GO=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`||rT(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 BO(t)!=`number`)return`active`;return`active`},KO=e=>{let t=e[e.length-1];if(!t)return!1;let n=t.info;return oT(n.finish,t.parts,n.error)},qO=e=>xO(e)?`compaction`:`default`,JO={previousProjection:null,showTextJustificationActivity:!1,showTurnChangedFiles:!1},YO=(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},XO=(e,t)=>e.userMessage===t.userMessage&&e.headerMessageId===t.headerMessageId&&YO(e.assistantMessages,t.assistantMessages),ZO=(e,t)=>{e.summary=PO(e.assistantMessages),e.summaryText=e.summary.text??HO(e.userMessage),e.diffStats=FO(e.userMessage),e.changedFiles=t.showTurnChangedFiles?IO(e.userMessage):void 0,e.completionDisposition=GO(e.assistantMessages),e.hasConfirmedFinalBody=KO(e.assistantMessages),e.activityPresentationKind=qO(e.userMessage);let n=jO({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=WO(e.userMessage,e.assistantMessages),e.startedAt=e.stream.startedAt,e.completedAt=e.stream.completedAt,e.durationMs=e.stream.durationMs,e},QO=(e,t)=>{let n=t.previousProjection;if(!n||n.turns.length===0||e.length===0)return e.map(e=>ZO(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&&XO(o,e)?(i=!0,n.turns[a]!==o&&(r=!1),o):(r=!1,ZO(e,t))});return r&&i?n.turns:a},$O=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},ek=(e,t)=>{let n={...JO,...t},r=[],i=new Map,a=new Set;e.forEach((e,t)=>{if(LO(e)!==`user`)return;let n={turnId:e.info.id,userMessageId:e.info.id,userMessage:e,headerMessageId:void 0,messages:[UO(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(LO(e)!==`assistant`)return;let n=RO(e),r=n?i.get(n):void 0;r&&(r.assistantMessages.push(e),r.assistantMessageIds.push(e.info.id),r.messages.push(UO(e,t)),r.headerMessageId||=e.info.id,a.add(e.info.id))});let o=MO($O(QO(r,n))),s=new Set;return e.forEach(e=>{LO(e)!==`assistant`&&(a.has(e.info.id)||s.add(e.info.id))}),{...o,ungroupedMessageIds:s}},tk=30,nk=4,rk=4,ik=33554432,ak=8388608,ok=new Map,sk=new Map,ck=0,lk=new WeakMap,uk=1,dk=()=>d()?nk:On()?rk:tk,fk=()=>d()||On()?ak:ik,pk=(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},mk=e=>{ok.delete(e);let t=sk.get(e)??0;sk.delete(e),ck=Math.max(0,ck-t)},hk=e=>{let t=lk.get(e);if(t!==void 0)return t;let n=uk;return uk+=1,lk.set(e,n),n},gk=e=>e.map(e=>`${hk(e.info)}:${hk(e.parts)}:${e.parts.map(e=>hk(e)).join(`,`)}`).join(`;`),_k=(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,gk(t),n?`1`:`0`,r?`1`:`0`].join(`|`)},vk=e=>{let t=ok.get(e);return t&&(ok.delete(e),ok.set(e,t)),t},yk=(e,t)=>{mk(e);let n=dk(),r=fk(),i=pk(e,t);if(!(i>r)){for(;ok.size>=n||ck+i>r;){let e=ok.keys().next().value;if(typeof e!=`string`)break;mk(e)}ok.set(e,t),sk.set(e,i),ck+=i}},bk=[],xk=(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},Sk=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},Ck=(e,t)=>t===null?{staticTurns:e,streamingTurns:bk}:{staticTurns:t===0?bk:e.slice(0,t),streamingTurns:e.slice(t)},wk=(e,t)=>{let n=Z.useRef(null),r=Z.useRef([]),i=Z.useRef(bk),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=bk,a.current=null);let l=Z.useMemo(()=>{let r=_k(t.sessionKey??``,e,t.showTextJustificationActivity,t.showTurnChangedFiles),i=vk(r);return i?(n.current=i,i):Ce(`ui.turns.projection_ms`,()=>{let i=ek(e,{previousProjection:n.current,showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles});return n.current=i,yk(r,i),i})},[e,t.showTextJustificationActivity,t.showTurnChangedFiles,t.sessionKey]),u=Sk({turnCount:l.turns.length,hasLiveTail:t.hasLiveTail,liveTailActive:t.liveTailActive,previousStart:a.current});return a.current=u,{projection:l,staticTurns:Z.useMemo(()=>{let e=Ck(l.turns,u).staticTurns;return xk(r.current,e)?r.current:r.current=e},[u,l.turns]),streamingTurns:Z.useMemo(()=>{let e=Ck(l.turns,u).streamingTurns;return xk(i.current,e)?i.current:i.current=e},[u,l.turns])}},Tk=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},Ek=(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(Tk(e[t])===`user`){r=t;break}if(r<0)return e;let i=-1;for(let t=e.length-1;t>r;--t)if(Tk(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},Dk=(e,t,n)=>{if(e.info.id!==t||e.parts===n)return e;let r=wn(e.parts,n,e.info);return r.length===e.parts.length&&r.every((t,n)=>t===e.parts[n])?e:TO({...e,parts:r})},Ok=(e,t)=>{let n=t.activeStreamingMessageId;if(!n)return e;if(e.kind===`ungrouped`){let r=Dk(e.message,n,t.liveParts);return r===e.message?e:{...e,message:r}}let r=!1,i=e.turn.assistantMessages.map(e=>{let i=Dk(e,n,t.liveParts);return i!==e&&(r=!0),i});if(!r)return e;let a=ek([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}},kk=e=>{let t=Z.useRef(e);return t.current=e,Z.useMemo(()=>(...e)=>t.current(...e),[])},Ak=2,jk=2,Mk=e=>Math.min(Math.max(0,e),Ak),Nk=(e,t)=>Math.min(Math.max(0,t),Math.max(0,e)+jk),Pk=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(jS.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Fk=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Mo.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Ik=12,Lk=16,Rk=new Map,zk=e=>{let t=Rk.get(e);if(t)return Rk.delete(e),Rk.set(e,t),t},Bk=(e,t)=>{if(t.size!==0)for(Rk.delete(e),Rk.set(e,t);Rk.size>Lk;){let e=Rk.keys().next().value;if(typeof e!=`string`)break;Rk.delete(e)}},Vk=(e,t)=>{let n=Math.max(1,Math.floor(t?.seedCount??Ik)),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},Hk=(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},Uk=({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}},Wk=e=>{let{visible:t,preload:n}=Uk(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},Gk=(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},Kk=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},qk=e=>{let t=e.info;return typeof t.parentID==`string`&&t.parentID.length>0?t.parentID:null},Jk=e=>!e||Kk(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`)}),Yk=(e,t)=>{if(Kk(e)!==`assistant`||t&&qk(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}}},Xk=(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(Kk(t)===`user`)break;let{hide:i,details:a}=Yk(t,r);if(i){let e=typeof a?.command==`string`?a.command.trim():``;return e.length>0?e:null}}return null},Zk=e=>{let t=e.info,n=t.time?.completed,r=t.status;return typeof n!=`number`||n<=0?!1:typeof r!=`string`||r===`completed`},Qk=(e,t)=>{if(e.length===0)return[];if(e.filter(Zk).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},$k=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=cT({finish:r.finish,isMessageCompleted:Zk(n),activeStreamingPhase:e.activeStreamingPhase});return lT({finish:r.finish,parts:n.parts,streamPhase:i,error:r.error,isLastAssistantInTurn:!0})?t:null},eA=(e,t)=>{if(!t)return e;let n=e.filter(e=>e.kind!==`justification`||e.messageId!==t);return n.length===e.length?e:n},tA=(e,t)=>{if(!t)return e;let n=!1,r=e.map(e=>{let r=eA(e.parts,t);return r===e.parts?e:(n=!0,{...e,parts:r})});return n?r:e},nA=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,rA=e=>!e,iA=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},aA=e=>e.completionDisposition!==`active`&&!(e.isLastTurn&&e.sessionIsWorking),oA=e=>e.isLastTurn&&e.turnCompletionDisposition===`active`?`active`:e.headerPresentationDisposition,sA=e=>e.isActivelyProcessing||e.expansionDisposition===`active`?!0:nA(e.expansionDisposition,e.activityRenderMode,{isLastTurn:e.isLastTurn,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),cA=5,lA=[],uA=new Set,dA=[],fA=16,pA=(e,t)=>e===t?!0:!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n]),mA=320,hA=168,gA=8,_A=16,vA=6,yA=12,bA=4,xA=1,SA=2,CA=6,wA=4,TA=()=>On()?_A:gA,EA=30,DA=180,OA=5,kA=2,AA=120,jA=1200,MA=80,NA=160,PA=1500,FA=1.5,IA=90,LA=(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},RA=(e=>{let t=new Map;return{read:(e,n)=>{let r=t.get(e);if(r){if(pA(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)}}}})(fA),zA=(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})},BA=(e,t)=>({sessionKey:e,virtualizerKey:t??e}),VA=e=>e===`collapsed`?hA:mA,HA=(e,t)=>`${e}::activity:${t}`,UA=(e,t=0)=>Math.max(e===`collapsed`?yA:vA,Math.max(0,Math.floor(t))),WA=e=>e===`collapsed`?SA:xA,GA=e=>e===`collapsed`?wA:CA,KA=e=>e===`collapsed`?kA:OA,qA=(e,t)=>{e.current=t},JA=(e,t)=>RA.read(e,t),YA=(e,t,n)=>{!n||t.length===0||RA.write(e,t,n.takeSnapshot())},XA=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},ZA=(e,t)=>{if(XA(e)!==`system`)return e;let n=ej(e);return!n||!t.has(n)||e.info.clientRole===`assistant`?e:{...e,info:{...e.info,clientRole:`assistant`}}},QA=e=>!e||XA(e)!==`user`?!1:e.parts.some(e=>e?.type===`subtask`),$A=e=>{if(!e)return null;let t=e.info.id;return typeof t==`string`&&t.trim().length>0?t:null},ej=e=>{let t=e.info.parentID;return typeof t==`string`&&t.trim().length>0?t:null},tj=(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},nj=(e,t)=>Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.dataset.messageId===t)??null,rj=(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&&!tj(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}},ij=(e,t)=>{let n=rj(t,e);if(!n)return null;let r=nj(e,n.messageId)?.closest(`[data-turn-entry]`)?.dataset.turnEntry;return r?{...n,entryKey:r,attempts:0}:null},aj=e=>{let t=e,n=t.state?.metadata,r=gx(n)??null;if(r)return r;let i=t.state?.output;return typeof i==`string`?bx(i)??null:null},oj=e=>{if(XA(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:aj(e.parts[0])}},sj=(e,t)=>{if(!t)return e;let n=_x(e.parts,t);return n===e.parts?e:{...e,parts:n}},cj=(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}},lj=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,uj=Z.memo(e=>{let t=(0,Q.c)(22),{message:n,previousMessage:r,nextMessage:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s,activeStreamingPhase:c,animateUserOnMount:l,onUserAnimationConsumed:u,onContentChange:d,animationHandlers:f,scrollToBottom:p,reviewTransferDirection:m}=e,h=Qm(),g;t[0]!==n.sourceDirectory||t[1]!==n.sourceSessionID||t[2]!==h?(g=n.sourceSessionID?{...h,sessionId:n.sourceSessionID,directory:n.sourceDirectory??null,onRevertMessage:void 0,onEditMessage:void 0,capabilities:{...h.capabilities,compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,forkSession:!1,navigateNestedSession:!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)(uO,{message:n,previousMessage:r,nextMessage:i,animateUserOnMount:l,onUserAnimationConsumed:u,onContentChange:d,animationHandlers:f,scrollToBottom:p,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s,activeStreamingPhase:c,reviewTransferDirection:m}),t[4]=c,t[5]=l,t[6]=f,t[7]=o,t[8]=s,t[9]=n,t[10]=i,t[11]=d,t[12]=u,t[13]=r,t[14]=m,t[15]=p,t[16]=a,t[17]=v):v=t[17];let y=v,b;return t[18]!==y||t[19]!==_||t[20]!==h?(b=_===h?y:(0,$.jsx)(Zm.Provider,{value:_,children:y}),t[18]=y,t[19]=_,t[20]=h,t[21]=b):b=t[21],b},(e,t)=>{let n=e.turnGroupingContext,r=t.turnGroupingContext;return Zx(e.message,t.message)&&e.message.sourceSessionID===t.message.sourceSessionID&&e.message.sourceDirectory===t.message.sourceDirectory&&Qx(e.previousMessage,t.previousMessage)&&Qx(e.nextMessage,t.nextMessage)&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&e.onContentChange===t.onContentChange&&e.scrollToBottom===t.scrollToBottom&&oS(n,r,e.message.info.id,XA(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});uj.displayName=`MessageRow`;var dj=Z.memo(e=>{let t=(0,Q.c)(104),{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.completionDisposition||t[7]!==n.durationMs||t[8]!==n.hasConfirmedFinalBody){let e=iA({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,durationMs:n.durationMs});x=sA({expansionDisposition:oA({isLastTurn:r,turnCompletionDisposition:n.completionDisposition,headerPresentationDisposition:e.completionDisposition}),activityRenderMode:a,isLastTurn:r,isActivelyProcessing:r&&i,hasConfirmedFinalBody:n.hasConfirmedFinalBody}),t[3]=a,t[4]=r,t[5]=i,t[6]=n.completionDisposition,t[7]=n.durationMs,t[8]=n.hasConfirmedFinalBody,t[9]=x}else x=t[9];let S=x,C=b?b.isExpanded:S,w;t[10]!==S||t[11]!==s||t[12]!==n.turnId?(w=()=>{s(n.turnId,S)},t[10]=S,t[11]=s,t[12]=n.turnId,t[13]=w):w=t[13];let T=q(w),E;if(t[14]!==n.assistantMessages||t[15]!==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[14]=n.assistantMessages,t[15]=n.userMessage,t[16]=E}else E=t[16];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(!Zk(t)){O=t.info.id;break bb0}}O=null}let k=O,A;t[17]!==g||t[18]!==c||t[19]!==k||t[20]!==n.assistantMessages?(A=$k({chatRenderMode:c,assistants:n.assistantMessages,streamingAssistantMessageId:k,activeStreamingPhase:g}),t[17]=g,t[18]=c,t[19]=k,t[20]=n.assistantMessages,t[21]=A):A=t[21];let j=A,M;bb1:{if(c===`live`){M=n.assistantMessages;break bb1}let e;t[22]!==k||t[23]!==n.assistantMessages?(e=Qk(n.assistantMessages,k),t[22]=k,t[23]=n.assistantMessages,t[24]=e):e=t[24],M=e}let N=M,P;t[25]===N?P=t[26]:(P=new Map,N.forEach((e,t)=>{P.set(e.info.id,t)}),t[25]=N,t[26]=P);let F=P,I;t[27]===N?I=t[28]:(I=new Set(N.map(yj)),t[27]=N,t[28]=I);let L=I,R=N[0]?.info.id,z;bb2:{if(c!==`sorted`){z=n.activityParts;break bb2}let e;t[29]!==n.activityParts||t[30]!==n.assistantMessages.length||t[31]!==L?(e=L.size===n.assistantMessages.length?n.activityParts:n.activityParts.filter(e=>L.has(e.messageId)),t[29]=n.activityParts,t[30]=n.assistantMessages.length,t[31]=L,t[32]=e):e=t[32];let r=e,i;t[33]!==j||t[34]!==r?(i=eA(r,j),t[33]=j,t[34]=r,t[35]=i):i=t[35],z=i}let B=z,V;bb3:{if(c!==`sorted`){V=n.activitySegments;break bb3}if(j){let e;t[36]!==j||t[37]!==n.activitySegments?(e=tA(n.activitySegments,j),t[36]=j,t[37]=n.activitySegments,t[38]=e):e=t[38],V=e;break bb3}if(L.size===n.assistantMessages.length){V=n.activitySegments;break bb3}let e;if(t[39]!==n.activitySegments||t[40]!==L){let r;t[42]===L?r=t[43]:(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[42]=L,t[43]=r),e=n.activitySegments.map(r).filter(bj),t[39]=n.activitySegments,t[40]=L,t[41]=e}else e=t[41];V=e}let H=V,U=n.userMessage.info.time?.created,W=n.userMessage.info,ee=W?.model?.variant??W?.variant,G=typeof ee==`string`&&ee.trim().length>0?ee:void 0,K=typeof U==`number`?U:void 0,te;t[44]!==K||t[45]!==n.activityPresentationKind||t[46]!==n.changedFiles||t[47]!==n.diffStats||t[48]!==n.hasReasoning||t[49]!==n.hasTools||t[50]!==n.headerMessageId||t[51]!==n.summaryText||t[52]!==n.turnId||t[53]!==G||t[54]!==B||t[55]!==H?(te={turnId:n.turnId,summaryBody:n.summaryText,activityParts:B,activityGroupSegments:H,headerMessageId:n.headerMessageId,hasTools:n.hasTools,hasReasoning:n.hasReasoning,activityPresentationKind:n.activityPresentationKind,diffStats:n.diffStats,changedFiles:n.changedFiles,userMessageCreatedAt:K,userMessageVariant:G},t[44]=K,t[45]=n.activityPresentationKind,t[46]=n.changedFiles,t[47]=n.diffStats,t[48]=n.hasReasoning,t[49]=n.hasTools,t[50]=n.headerMessageId,t[51]=n.summaryText,t[52]=n.turnId,t[53]=G,t[54]=B,t[55]=H,t[56]=te):te=t[56];let ne=te,re;t[57]!==g||t[58]!==R||t[59]!==c||t[60]!==u||t[61]!==T||t[62]!==r||t[63]!==D.lookup||t[64]!==D.ordered||t[65]!==l||t[66]!==m||t[67]!==_||t[68]!==d||t[69]!==i||t[70]!==p||t[71]!==k||t[72]!==n.activityPresentationKind||t[73]!==n.completionDisposition||t[74]!==n.durationMs||t[75]!==n.hasReasoning||t[76]!==n.hasTools||t[77]!==n.headerMessageId||t[78]!==n.turnId||t[79]!==n.userMessage||t[80]!==ne||t[81]!==H||t[82]!==F||t[83]!==N[0]?.info.id||t[84]!==N.length?(re=(e,t)=>{let a=XA(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=iA({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&&i&&(c===`sorted`?b:e.info.id===k),isTurnSettled:aA({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i}),hasTools:n.hasTools,hasReasoning:n.hasReasoning,completionDisposition:w.completionDisposition,activityPresentationKind:n.activityPresentationKind,durationMs:w.durationMs,...x?{summaryBody:ne.summaryBody,activityParts:ne.activityParts,activityGroupSegments:ne.activityGroupSegments,headerMessageId:ne.headerMessageId,diffStats:ne.diffStats,changedFiles:ne.changedFiles,userMessageCreatedAt:ne.userMessageCreatedAt,userMessageVariant:ne.userMessageVariant,isGroupExpanded:t,toggleGroup:T}:{}}:void 0;return(0,$.jsx)(uj,{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[57]=g,t[58]=R,t[59]=c,t[60]=u,t[61]=T,t[62]=r,t[63]=D.lookup,t[64]=D.ordered,t[65]=l,t[66]=m,t[67]=_,t[68]=d,t[69]=i,t[70]=p,t[71]=k,t[72]=n.activityPresentationKind,t[73]=n.completionDisposition,t[74]=n.durationMs,t[75]=n.hasReasoning,t[76]=n.hasTools,t[77]=n.headerMessageId,t[78]=n.turnId,t[79]=n.userMessage,t[80]=ne,t[81]=H,t[82]=F,t[83]=N[0]?.info.id,t[84]=N.length,t[85]=re):re=t[85];let ie=kk(re),ae;bb4:{if(N===n.assistantMessages){ae=n;break bb4}let e;t[86]!==n||t[87]!==N?(e={...n,assistantMessages:N},t[86]=n,t[87]=N,t[88]=e):e=t[88],ae=e}let oe=ae,se=H.length>0,ce=n.assistantMessages.length>0,le;t[89]!==c||t[90]!==r||t[91]!==i||t[92]!==se||t[93]!==ce||t[94]!==n.activityPresentationKind||t[95]!==n.completionDisposition?(le=lj({chatRenderMode:c,activityPresentationKind:n.activityPresentationKind,hasVisibleActivitySegments:se,hasAssistantMessages:ce,completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i}),t[89]=c,t[90]=r,t[91]=i,t[92]=se,t[93]=ce,t[94]=n.activityPresentationKind,t[95]=n.completionDisposition,t[96]=le):le=t[96];let ue;return t[97]!==T||t[98]!==C||t[99]!==ie||t[100]!==oe||t[101]!==v||t[102]!==le?(ue=(0,$.jsx)(hO,{turn:oe,activityExpanded:C,onToggleActivity:T,showCompactionStatus:le,stickyUserHeader:v,renderMessage:ie}),t[97]=T,t[98]=C,t[99]=ie,t[100]=oe,t[101]=v,t[102]=le,t[103]=ue):ue=t[103],ue});dj.displayName=`TurnBlock`;var fj=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(mr(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)(uj,{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});fj.displayName=`UngroupedMessageRow`;var pj=Z.memo(e=>{let t=(0,Q.c)(29),{entry:n,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,stickyUserHeader:o,sessionIsWorking:s,activityRenderMode:c,turnUiStates:l,onToggleTurnGroup:u,chatRenderMode:d,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g}=e;if(n.kind===`ungrouped`){let e;return t[0]!==m||t[1]!==h||t[2]!==n.message||t[3]!==n.nextMessage||t[4]!==n.previousMessage||t[5]!==i||t[6]!==r||t[7]!==p||t[8]!==g||t[9]!==a||t[10]!==f?(e=(0,$.jsx)(fj,{message:n.message,previousMessage:n.previousMessage,nextMessage:n.nextMessage,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g}),t[0]=m,t[1]=h,t[2]=n.message,t[3]=n.nextMessage,t[4]=n.previousMessage,t[5]=i,t[6]=r,t[7]=p,t[8]=g,t[9]=a,t[10]=f,t[11]=e):e=t[11],e}let _;return t[12]!==m||t[13]!==h||t[14]!==c||t[15]!==d||t[16]!==n.isLastTurn||t[17]!==n.turn||t[18]!==i||t[19]!==r||t[20]!==u||t[21]!==p||t[22]!==g||t[23]!==a||t[24]!==s||t[25]!==f||t[26]!==o||t[27]!==l?(_=(0,$.jsx)(dj,{turn:n.turn,isLastTurn:n.isLastTurn,sessionIsWorking:s,activityRenderMode:c,turnUiStates:l,onToggleTurnGroup:u,chatRenderMode:d,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,stickyUserHeader:o}),t[12]=m,t[13]=h,t[14]=c,t[15]=d,t[16]=n.isLastTurn,t[17]=n.turn,t[18]=i,t[19]=r,t[20]=u,t[21]=p,t[22]=g,t[23]=a,t[24]=s,t[25]=f,t[26]=o,t[27]=l,t[28]=_):_=t[28],_});pj.displayName=`MessageListEntry`;var mj=Z.memo(({entries:e,engine:t,contentRef:n,scrollRef:r,registerTanstackVirtualizer:i,virtualizerKey:a,onMessageContentChange:o,getAnimationHandlers:s,scrollToBottom:c,stickyUserHeader:l,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,shouldAnimateUserMessage:m,onUserAnimationConsumed:h,reviewTransferDirection:g})=>{let _=t===`tanstack`,v=Z.useRef(t),y=Z.useRef(null),[b,x]=Z.useReducer(e=>e+1,0);if(t===`none`)y.current=null;else if(v.current===`none`&&_&&y.current===null){let e=n.current,t=r?.current;e&&t&&(y.current=ij(e,t))}let S=Z.useRef(!1),C=Z.useRef(0),w=Z.useRef(null),T=_&&On();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<NA,D=()=>{let e=r?.current;return!e||e.scrollTop<e.clientHeight*FA},[O,k]=Z.useState(e),A=O;e===O?w.current!==null&&(w.current=null):T&&LA(O,e)&&E()&&!D()&&(w.current===null||performance.now()-w.current<PA)?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>=PA;(!E()||D()||e)&&j()},T?IA:null);let M=Z.useRef(A);M.current=A;let N=Z.useMemo(()=>A.map(e=>e.key),[A]),P=TA(),[F,I]=Z.useState(()=>Mk(P));Z.useEffect(()=>{if(!(!_||F>=P))return ds(()=>{Z.startTransition(()=>{I(e=>Nk(e,P))})})},[F,_,P]);let L=HA(a,u),[R]=Z.useState(()=>_?JA(L,e.map(e=>e.key)):void 0),z=Z.useRef(null),B=VA(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??zA(N,W.current,V.current));let G=_c({count:A.length,enabled:_,getScrollElement:()=>r?.current??null,estimateSize:()=>V.current,overscan:F,scrollToFn:(e,t,n)=>{let r=z.current;r&&(r.style.height=`${n.getTotalSize()}px`),gc(e,t,n)},getItemKey:e=>M.current[e]?.key??`index:${e}`,anchorTo:`end`,followOnAppend:!0,scrollEndThreshold:MA,initialOffset:()=>U.current?2**53-1:r?.current?.scrollTop??0,initialMeasurementsCache:ee.current});rt(()=>{if(v.current=t,!_){y.current=null;return}let e=y.current,n=r?.current;if(!e||!n)return;let i=nj(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 K=G.getVirtualItems(),te=K.map(e=>e.index),[ne,re]=Z.useState(()=>Vk(N,{seedCount:UA(u),restore:zk(L)})),ie=Hk(ne,N);ie!==ne&&re(ie);let ae=Z.useRef(ie);ae.current=ie;let oe=Z.useRef(null);G.scrollDirection&&(oe.current=G.scrollDirection);let se=G.range?.startIndex??K[0]?.index??Math.max(0,A.length-1),ce=G.range?.endIndex??K[K.length-1]?.index??Math.max(0,A.length-1),le=G.isScrolling,ue=Math.max(0,ce-se+1),de=Wk({entryKeys:N,mountedIndexes:te,visibleStartIndex:se,visibleEndIndex:ce,scrollDirection:oe.current,preloadEntries:UA(u,ue),hydratedKeys:ie,allowVisibleRelease:!le,preloadReleaseLimit:le?WA(u):bA,visibleReleaseLimit:le?0:GA(u)}),fe=de.join(`\0`),pe=Z.useRef(de);pe.current=de,Z.useEffect(()=>{if(!(!_||!fe))return ds(()=>{Z.startTransition(()=>{re(e=>{let t=null;for(let n of pe.current)e.has(n)||(t??=new Set(e),t.add(n));return t??e})})})},[_,fe]),Z.useEffect(()=>{re(e=>Gk(e,N))},[N]),Z.useEffect(()=>{if(!_)return;let e=G.itemSizeCache,t=KA(u);if(e.size>=t){let t=0;for(let n of e.values())t+=n;V.current=Math.min(jA,Math.max(AA,Math.round(t/e.size)))}}),Z.useEffect(()=>{if(_)return i?.(G),()=>{YA(L,M.current.map(e=>e.key),G),Bk(L,ae.current),i?.(null)}},[_,G,L]);let me=kk((e,t=!0)=>(0,$.jsx)(Fk,{enabled:t,children:(0,$.jsx)(pj,{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:me(e)},e.key))});if(t===`tanstack`){let e=K[0]?.start??0;return(0,$.jsx)(`div`,{ref:z,className:`relative w-full`,style:{height:G.getTotalSize()},children:(0,$.jsx)(`div`,{style:{paddingTop:`${e}px`},children:K.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:me(t,ie.has(t.key))},t.key):null})})})}return null});mj.displayName=`StaticHistoryList`;var hj=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)(pj,{...e})}),t[0]=e,t[1]=n),n});hj.displayName=`TailEntry`;var gj=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=ui(_??``,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=Ok(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)(hj,{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};gj.displayName=`StreamingTailContent`;var _j=Z.forwardRef(({sessionKey:e,virtualizerKey:t,messages:n,sessionIsWorking:r=!1,activeStreamingMessageId:i=null,activeStreamingPhase:a=null,retryOverlay:o=null,onMessageContentChange:s,getAnimationHandlers:l,scrollToBottom:u,scrollRef:d,directory:f},p)=>{Ie(`ui.message_list.render`);let{sessionKey:m,virtualizerKey:h}=BA(e,t),g=c(e=>e.stickyUserHeader),_=c(e=>e.chatRenderMode),v=c(e=>e.activityRenderMode),y=c(e=>e.showTurnChangedFiles),b=zr(e=>e.reviewTransferBySessionId.get(m)??null),[x,S]=Z.useState(()=>new Map),C=Z.useRef({sessionKey:void 0,previousOrder:[],animatedIds:new Set}),w=q(l),T=q(()=>{u?.()}),E=q((e,t)=>{S(n=>{let r=new Map(n),i=n.get(e)?.isExpanded??t;return r.set(e,{isExpanded:rA(i)}),r})}),D=Z.useMemo(()=>Ce(`ui.message_list.base_display_ms`,()=>{let e=new Set,t=new Map,r=[];for(let e of n){let n=e.info?.id;typeof n==`string`&&t.set(n,e)}for(let i=0;i<n.length;i+=1){let a=n[i],o=a.info?.id;if(typeof o==`string`){if(e.has(o))continue;e.add(o)}r.push(TO(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=ZA(t,a);xO(t)&&a.add(t.info.id);let o=i.length>0?i[i.length-1]:void 0;if(QA(o)){let e=oj(n);if(e.hide){i[i.length-1]=sj(o,e.taskSessionId);continue}}if(Jk(o)){let e=Yk(n,$A(o));if(e.hide){i[i.length-1]=cj(o,e.details);continue}}i.push(n)}return i}),[n]),O=Z.useRef(null),k=Z.useRef(null),A=Z.useCallback(()=>{let e=k.current;e&&(k.current=null,e.cancel())},[]);Z.useEffect(()=>()=>{A()},[A]);let j=q(()=>d?.current?d.current:typeof document>`u`?null:document.querySelector(`[data-scrollbar="chat"]`)),M=Z.useMemo(()=>Ce(`ui.message_list.retry_overlay_ms`,()=>Ek(D,{sessionId:o?.sessionId??null,message:o?.message??`Quota limit reached. Retrying automatically.`,confirmedAt:o?.confirmedAt,fallbackTimestamp:o?.fallbackTimestamp??0})),[D,o]),N=r||!!i,P=Z.useRef(N),F=Z.useRef(m);F.current!==m&&(F.current=m,P.current=!1),N&&(P.current=!0);let{projection:I,staticTurns:L,streamingTurns:R}=wk(M,{sessionKey:m,showTextJustificationActivity:_===`sorted`,showTurnChangedFiles:y,hasLiveTail:N||P.current,liveTailActive:N}),z=I.ungroupedMessageIds.size>0,B=z?M:lA,V=z?I.ungroupedMessageIds:uA,H=Z.useMemo(()=>Ce(`ui.message_list.render_entries_ms`,()=>{let e=L.map(e=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===I.lastTurnId}));if(V.size===0)return e;let t=new Map;e.forEach(e=>{t.set(e.turn.userMessage.info.id,e)});let n=[];return B.forEach((e,r)=>{let i=t.get(e.info.id);if(i){n.push(i);return}V.has(e.info.id)&&n.push({kind:`ungrouped`,key:`msg:${e.info.id}`,message:e,previousMessage:r>0?B[r-1]:void 0,nextMessage:r<B.length-1?B[r+1]:void 0})}),n}),[I.lastTurnId,B,V,L]),U=Z.useMemo(()=>{if(R.length>0)return R.map(e=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===I.lastTurnId}));if(I.ungroupedMessageIds.size===0)return dA;let e=M[M.length-1];return!e||!I.ungroupedMessageIds.has(e.info.id)?dA:[{kind:`ungrouped`,key:`msg:${e.info.id}`,message:e,previousMessage:M.length>1?M[M.length-2]:void 0,nextMessage:void 0}]},[M,I.lastTurnId,I.ungroupedMessageIds,R]),W=U.length>0;W&&N&&Ie(`ui.message_list.render.streaming`);let ee=H,G=ee.length>=cA,K=Z.useRef(G);qA(K,G);let te=G?`tanstack`:`none`,ne=Z.useRef(null),re=q(e=>{ne.current=e}),ie=Z.useMemo(()=>U.length>0?[...ee,...U]:ee,[ee,U]),ae=q(e=>{s(e)}),oe=q(e=>{s(e)}),se=Z.useMemo(()=>n.filter(e=>XA(e)===`user`).map(e=>e.info.id),[n]);{let t=C.current;t.sessionKey!==e&&(t.sessionKey=e,t.previousOrder=se,t.animatedIds=new Set);let n=t.previousOrder;if(se.length>n.length&&n.every((e,t)=>se[t]===e)&&xn(e))for(let r=n.length;r<se.length;r+=1){let n=se[r];if(n&&!t.animatedIds.has(n)){if(!gn(e))break;t.animatedIds.add(n)}}t.previousOrder=se}let ce=q(e=>XA(e)===`user`&&C.current.animatedIds.has(e.info.id)),le=q(e=>{C.current.animatedIds.delete(e)}),ue=Z.useMemo(()=>{let e=new Map;return ie.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},[ie]),de=Z.useMemo(()=>{let e=new Map;return ie.forEach((t,n)=>{t.kind===`turn`&&e.set(t.turn.turnId,n)}),e},[ie]),fe=q(e=>{let t=j();return t?t.querySelector(`[data-message-id="${e}"]`):null}),pe=q((e,t=`auto`)=>{if(e<0||e>=ee.length||!G)return!1;let n=ne.current;return n?(n.scrollToIndex(e,{align:`start`,behavior:t===`smooth`?`smooth`:`auto`}),!0):!1}),me=q((e,t=`auto`)=>{let n=j();if(!n)return!1;let r=fe(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(!p)return;let e={scrollToTurnId:(e,t)=>{let n=t?.behavior??`auto`,r=de.get(e);if(r===void 0)return!1;let i=j();if(!i)return!1;let a=i.querySelector(`[data-turn-id="${e}"]`);return a?(a.scrollIntoView({behavior:n,block:`start`}),!0):W&&r>=ee.length?!1:pe(r,n)},scrollToMessageId:(e,t)=>{let n=t?.behavior??`auto`,r=ue.get(e);return r===void 0?!1:me(e,n)||(W&&r>=ee.length?!1:pe(r,n))},holdViewportAnchor:e=>{let t=j();if(!t||typeof window>`u`)return;A();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(),k.current?.cancel===s&&(k.current=null))},c=()=>{s()};k.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=fe(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>=EA||n>=DA){s();return}a=window.requestAnimationFrame(l)};a=window.requestAnimationFrame(l)},cancelViewportAnchorHold:A,isHistoryVirtualized:()=>K.current,captureViewportAnchor:()=>{let e=j();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`||!tj(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=j();if(!t||!ue.has(e.messageId))return!1;let n=()=>{let n=fe(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=ue.get(e.messageId);if(typeof t==`number`&&t<ee.length)return pe(t,`auto`)}return n()},scrollToBottom:()=>{if(G&&ee.length>0&&ne.current){ne.current.scrollToEnd();return}let e=j();e&&(e.scrollTop=e.scrollHeight)}};if(typeof p==`function`)return p(e),()=>{p(null)};let t=p;return t.current=e,()=>{t.current=null}},[A,ee.length,ue,G,W,de,p]),(0,$.jsx)(`div`,{children:(0,$.jsx)(gs,{disabled:!1,children:(0,$.jsxs)(`div`,{className:`relative w-full`,children:[(0,$.jsx)(gs,{disabled:G,children:(0,$.jsx)(Pk,{enabled:!0,children:(0,$.jsx)(mj,{entries:ee,engine:te,contentRef:O,scrollRef:d,registerTanstackVirtualizer:re,virtualizerKey:h,onMessageContentChange:ae,getAnimationHandlers:w,scrollToBottom:T,stickyUserHeader:g,activityRenderMode:v,turnUiStates:x,onToggleTurnGroup:E,chatRenderMode:_,shouldAnimateUserMessage:ce,onUserAnimationConsumed:le,reviewTransferDirection:b},h)})}),(0,$.jsx)(gj,{entries:U,directory:f,sessionId:m,onMessageContentChange:oe,getAnimationHandlers:w,scrollToBottom:T,stickyUserHeader:g,sessionIsWorking:r,activityRenderMode:v,turnUiStates:x,onToggleTurnGroup:E,chatRenderMode:_,showTurnChangedFiles:y,shouldAnimateUserMessage:ce,onUserAnimationConsumed:le,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:b})]})})})});_j.displayName=`MessageList`;var vj=Z.memo(_j);function yj(e){return e.info.id}function bj(e){return e!==null}var xj=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},Sj=({diff:e,filePath:t})=>{let{currentTheme:n}=Va(),r=Z.useMemo(()=>To(n),[n]),i=Z.useMemo(()=>$s(e),[e]),a=is(t||i[0]?.file)||`text`,o=Z.useMemo(()=>i.flatMap(e=>e.lines.map(e=>e.content)).join(`
|
|
6581
|
+
`)}return lt&<.trim().length>0?lt:Gn(ze)},[lt,ze,K]),ft=dt.length>0,pt=Z.useCallback(async()=>(await ct(dt)).ok?(K&&(L(!0),setTimeout(()=>L(!1),2e3)),!0):!1,[K,dt]),mt=Z.useCallback(async()=>{if(!(!re||!e.info.id||B.current)){B.current=`revert`,z(`revert`);try{g.onRevertMessage?await g.onRevertMessage(e.info.id):await C(re,e.info.id,{directory:g.directory??void 0})}finally{B.current=null,z(null)}}},[re,e.info.id,C,g]),ht=q(()=>{if(!re||!e.info.id||B.current)return;let t={info:e.info,parts:e.parts};if(g.onEditMessage){g.onEditMessage(e.info.id,t).catch(()=>{});return}w(re,e.info.id,t).catch(()=>{})}),gt=q(()=>{re&&O(re)}),_t=Z.useCallback(async()=>{if(e.info.id,!re||!e.info.id){console.warn(`[session-fork] message action is missing identifiers`,{hasSessionId:!!re,hasMessageId:!!e.info.id});return}if(!B.current){B.current=`fork`,z(`fork`);try{await T(re,e.info.id)}finally{B.current=null,z(null)}}},[re,e.info.id,T]),vt=q(t=>{let n=He.has(t),r=Ue.has(t);if(n){W(n=>{let i=new Set(n);return r?i.add(t):i.delete(t),rO(e.info.id,i),i}),r||H(n=>{let r=new Set(n);return r.delete(t),tO(e.info.id,r),r});return}H(n=>{let r=new Set(n);return r.has(t)?r.delete(t):r.add(t),tO(e.info.id,r),r}),W(n=>{if(!n.has(t))return n;let r=new Set(n);return r.delete(t),rO(e.info.id,r),r})}),yt=i??null,bt=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,bt.current=!1,Et.current=!1},[e.info.id]);let Dt=Z.useCallback(()=>{K||bt.current||(bt.current=!0,r?.(`structural`))},[K,r]),Ot=c(e=>e.setImagePreviewOpen),kt=Z.useCallback(e=>{(e.image||e.mermaid)&&(G(e),Ot(!0))},[Ot]),At=Z.useCallback(e=>{G(t=>({...t,open:e})),Ot(e)},[Ot]),Mt=!!lO(e.info,`animationSettled`),Nt=nt===`streaming`||nt===`cooldown`;Nt&&(Et.current=!0);let Pt=Z.useMemo(()=>!K&&Re.some(e=>e.type===`reasoning`),[K,Re]),Ft=Je&&!Mt&&!Nt&&!Et.current,It=!K&&Je&&Be.length>0&&!qe;return Z.useEffect(()=>{if(yt?.onStreamingCandidate){if(!It){Ct.current&&=(Pt&&yt?.onReasoningBlock?yt.onReasoningBlock():yt?.onReservationCancelled&&yt.onReservationCancelled(),!1);return}Tt.current||(Tt.current=!0,yt.onStreamingCandidate(),Ct.current=!0)}},[yt,It,Pt]),Z.useEffect(()=>{yt?.onAnimationStart&&Ft&&(wt.current||=(yt.onAnimationStart(),!0))},[yt,Ft]),Z.useEffect(()=>{if(K)return;let e=yt?.onAnimatedHeightChange;if(!e||!(Ft||It))return;let t=y.current;if(!t)return;if(typeof window>`u`||typeof ResizeObserver>`u`){e(t.getBoundingClientRect().height);return}let n=null,r=t=>{if(typeof window>`u`){e(t);return}n!==null&&window.cancelAnimationFrame(n),n=window.requestAnimationFrame(()=>{e(t)})},i=new ResizeObserver(e=>{let t=e[0];t&&r(t.contentRect.height)});return i.observe(t),r(t.getBoundingClientRect().height),()=>{n!==null&&(window.cancelAnimationFrame(n),n=null),i.disconnect()}},[Ft,K,yt,It]),Ge?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:Y(`group w-full`,K?p?`pt-2`:`pt-6`:!K&&rt?p?j?`pt-4`:`pt-0`:`pt-6`:`pt-0`,K||tt?`pb-0`:et?`pb-1`:`pb-8`),id:`message-${e.info.id}`,"data-message-id":e.info.id,ref:y,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:K?zi(ze)?(0,$.jsx)(ps,{forceAnimation:!0,skipAnimation:!u,ignoreContextDisabled:!0,respectReducedMotion:!0,children:(0,$.jsx)(`div`,{className:Y(`relative flex justify-end`,p?void 0:`group/user-shell`),children:(0,$.jsxs)(`div`,{className:Y(`max-w-[85%]`,ne?`pb-5`:void 0),children:[(0,$.jsx)(`div`,{style:{backgroundColor:`var(--chat-user-message-bg)`,borderRadius:`var(--radius-xl)`,borderBottomRightRadius:`var(--radius-sm)`},className:`px-3 py-1.5 shadow-none border border-primary/5`,children:(0,$.jsx)(RD,{messageId:e.info.id,parts:ze,sourceParts:se,isUser:K,isMessageCompleted:Pe,messageFinish:Fe,messageCreatedAt:Ne??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:it,expandedTools:V,onToggleTool:vt,onShowPopup:kt,streamPhase:nt,allowAnimation:Ft,onContentChange:r,shouldShowHeader:!1,hasTextContent:ft,onCopyMessage:pt,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:Dt,agentMention:We,onEdit:!E&&_.edit?ht:void 0,onRevert:!E&&_.revert?mt:void 0,onFork:!E&&K&&_.fork?_t:void 0,editing:E,editStaged:D,onCancelEdit:D?gt:void 0,pendingMessageAction:R,errorMessage:lt,errorVariant:ut,userActionsMode:te?`external-content`:`inline`,stickyUserHeaderEnabled:j})}),te?(0,$.jsx)(RD,{messageId:e.info.id,parts:ze,sourceParts:se,isUser:K,isMessageCompleted:Pe,messageFinish:Fe,messageCreatedAt:Ne??void 0,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:it,expandedTools:V,onToggleTool:vt,onShowPopup:kt,streamPhase:nt,allowAnimation:Ft,onContentChange:r,shouldShowHeader:!1,hasTextContent:ft,onCopyMessage:pt,copiedMessage:I,showReasoningTraces:A,onAuxiliaryContentComplete:Dt,agentMention:We,onEdit:!E&&_.edit?ht:void 0,onRevert:!E&&_.revert?mt:void 0,onFork:!E&&K&&_.fork?_t:void 0,editing:E,editStaged:D,onCancelEdit:D?gt:void 0,pendingMessageAction:R,errorMessage:lt,errorVariant:ut,userActionsMode:`external-actions`,stickyUserHeaderEnabled:j}):null]})})}):null:(0,$.jsxs)(`div`,{className:`relative`,children:[rt&&(0,$.jsx)(Yb,{isUser:K,isMobile:p,providerID:ke,modelID:Ae,agentName:Oe,modelName:je,variant:ot}),(0,$.jsx)(RD,{sessionId:e.info.sessionID,messageId:e.info.id,parts:Re,sourceParts:ce,isUser:K,isMessageCompleted:Pe,messageFinish:Fe,messageCompletedAt:Me??void 0,messageCreatedAt:Ne??void 0,messageTokens:Le,isMobile:p,alwaysShowActions:v,hasTouchInput:h,copiedCode:P,onCopyCode:it,expandedTools:Ue,onToggleTool:vt,onShowPopup:kt,streamPhase:nt,allowAnimation:Ft,onContentChange:r,shouldShowHeader:rt,hasTextContent:ft,onCopyMessage:pt,copiedMessage:I,onAuxiliaryContentComplete:Dt,showReasoningTraces:A,agentMention:We,turnGroupingContext:a,errorMessage:lt,errorVariant:ut,reviewTransferDirection:f})]})})}),ee.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(JD,{popup:ee,onOpenChange:At,isMobile:p})}):null]})},(e,t)=>Zx({info:e.message.info,parts:e.message.parts},{info:t.message.info,parts:t.message.parts})&&e.message.sourceParts===t.message.sourceParts&&Qx(e.previousMessage?{info:e.previousMessage.info,parts:e.previousMessage.parts}:void 0,t.previousMessage?{info:t.previousMessage.info,parts:t.previousMessage.parts}:void 0)&&Qx(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&&oS(e.turnGroupingContext,t.turnGroupingContext,e.message.info.id,GD(e.message.info).isUser)),dO=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}),fO=new Set,pO=()=>{},mO=()=>{},hO=Z.memo(e=>{let t=(0,Q.c)(26),{turn:n,activityExpanded:r,showCompactionStatus:i,onToggleActivity:a,stickyUserHeader:o,renderMessage:s}=e,l=o===void 0||o,u=c(gO),d=n.userMessage.info.time?.created,f=n.activityPresentationKind===`compaction`,p=`turn-${n.turnId}`,m;t[0]!==r||t[1]!==f||t[2]!==s||t[3]!==l||t[4]!==n.userMessage?(m=f?null:l?(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:s(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`})]}):s(n.userMessage,r),t[0]=r,t[1]=f,t[2]=s,t[3]=l,t[4]=n.userMessage,t[5]=m):m=t[5];let h;t[6]!==r||t[7]!==u||t[8]!==a||t[9]!==i||t[10]!==n.assistantMessages||t[11]!==n.completionDisposition||t[12]!==n.durationMs||t[13]!==d?(h=i?(0,$.jsx)(`div`,{className:`group w-full ${u?`pt-4`:`pt-6`} ${n.assistantMessages.length===0?`pb-8`:`pb-0`}`,children:(0,$.jsx)(`div`,{className:`chat-message-column relative`,children:(0,$.jsx)(tD,{parts:[],isExpanded:r,completionDisposition:n.completionDisposition,activityPresentationKind:`compaction`,durationMs:n.durationMs,startedAt:typeof d==`number`?d:void 0,onToggle:a,isMobile:u,expandedTools:fO,onToggleTool:pO,onShowPopup:mO,streamPhase:n.completionDisposition===`active`?`streaming`:`completed`,showHeader:!0})})}):null,t[6]=r,t[7]=u,t[8]=a,t[9]=i,t[10]=n.assistantMessages,t[11]=n.completionDisposition,t[12]=n.durationMs,t[13]=d,t[14]=h):h=t[14];let g;t[15]!==r||t[16]!==s||t[17]!==n.assistantMessages?(g=(0,$.jsx)(dO,{assistantMessages:n.assistantMessages,activityExpanded:r,renderMessage:s}),t[15]=r,t[16]=s,t[17]=n.assistantMessages,t[18]=g):g=t[18];let _;return t[19]!==r||t[20]!==p||t[21]!==m||t[22]!==h||t[23]!==g||t[24]!==n.turnId?(_=(0,$.jsxs)(`section`,{className:`relative w-full`,id:p,"data-turn-id":n.turnId,"data-turn-activity-expanded":r,"data-scroll-spy-id":n.turnId,children:[m,h,g]}),t[19]=r,t[20]=p,t[21]=m,t[22]=h,t[23]=g,t[24]=n.turnId,t[25]=_):_=t[25],_});function gO(e){return e.isMobile}var _O=e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``},vO=e=>{let t=e?.type;return t===`compaction`||t===`text`&&_O(e).trim()===`/compact`},yO=e=>e?e.some(e=>vO(e)):!1,bO=e=>yO(e.parts),xO=e=>e?yO(e.sourceParts)||yO(e.parts):!1,SO=e=>{if(!bO(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}},CO=e=>{let t=Qr(e.parts);return t.length===e.parts.length?e:{...e,parts:t}},wO=new WeakMap,TO=e=>{let t=wO.get(e);if(t)return t;let n=SO(CO(e)),r=n.parts,i=Qi(r),a=i===r?n:{...n,parts:i,sourceParts:r};return wO.set(e,a),a},EO=(e,t,n)=>t.id??`${e}-part-${n}-${t.type}`,DO=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},OO=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},kO=e=>{let t=e.info.finish;return typeof t==`string`?t:void 0},AO=(e,t,n,r)=>({id:EO(t,n,r),turnId:e,messageId:t,part:n,partIndex:r,endedAt:DO(n)}),jO=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`&&OO(e)&&(r=!0)})});let i=!!e.summarySourceMessageId&&!!e.summarySourcePartId&&e.assistantMessages.some(t=>t.info.id===e.summarySourceMessageId&&iT(kO(t),t.parts));e.assistantMessages.forEach(n=>{let r=kO(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`?OO(o):void 0,u=EO(n.info.id,o,s),d=o.type===`text`&&typeof l==`string`&&iT(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({...AO(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}},MO=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}},NO=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},PO=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(!n)continue;let r=n.info.finish;if(iT(r,n.parts))for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(!t||!aT(t))continue;let r=NO(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:EO(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=NO(t);if(r)return{text:r,sourceMessageId:n.info.id,sourcePartId:EO(n.info.id,t,e)}}}return{}},FO=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}},IO=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},LO=e=>{let t=e.info.clientRole??e.info.role;return typeof t==`string`?t:``},RO=e=>{let t=e.info.parentID;if(typeof t==`string`&&t.trim().length!==0)return t},zO=e=>{let t=e.info.time?.created;return typeof t==`number`?t:void 0},BO=e=>{let t=e.info.time?.completed;return typeof t==`number`?t:void 0},VO=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},HO=e=>{let t=e.info?.summary?.body;if(typeof t==`string`)return t.trim().length>0?t:void 0},UO=(e,t)=>{let n=LO(e);return{messageId:e.info.id,role:n,parentMessageId:RO(e),message:e,order:t}},WO=(e,t)=>{let n=zO(e),r,i,a=!1;t.forEach(e=>{let t=BO(e);typeof t==`number`?r=Math.max(r??0,t):a=!0,e.parts.forEach(e=>{let t=VO(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}},GO=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`||rT(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 BO(t)!=`number`)return`active`;return`active`},KO=e=>{let t=e[e.length-1];if(!t)return!1;let n=t.info;return oT(n.finish,t.parts,n.error)},qO=e=>xO(e)?`compaction`:`default`,JO={previousProjection:null,showTextJustificationActivity:!1,showTurnChangedFiles:!1},YO=(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},XO=(e,t)=>e.userMessage===t.userMessage&&e.headerMessageId===t.headerMessageId&&YO(e.assistantMessages,t.assistantMessages),ZO=(e,t)=>{e.summary=PO(e.assistantMessages),e.summaryText=e.summary.text??HO(e.userMessage),e.diffStats=FO(e.userMessage),e.changedFiles=t.showTurnChangedFiles?IO(e.userMessage):void 0,e.completionDisposition=GO(e.assistantMessages),e.hasConfirmedFinalBody=KO(e.assistantMessages),e.activityPresentationKind=qO(e.userMessage);let n=jO({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=WO(e.userMessage,e.assistantMessages),e.startedAt=e.stream.startedAt,e.completedAt=e.stream.completedAt,e.durationMs=e.stream.durationMs,e},QO=(e,t)=>{let n=t.previousProjection;if(!n||n.turns.length===0||e.length===0)return e.map(e=>ZO(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&&XO(o,e)?(i=!0,n.turns[a]!==o&&(r=!1),o):(r=!1,ZO(e,t))});return r&&i?n.turns:a},$O=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},ek=(e,t)=>{let n={...JO,...t},r=[],i=new Map,a=new Set;e.forEach((e,t)=>{if(LO(e)!==`user`)return;let n={turnId:e.info.id,userMessageId:e.info.id,userMessage:e,headerMessageId:void 0,messages:[UO(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(LO(e)!==`assistant`)return;let n=RO(e),r=n?i.get(n):void 0;r&&(r.assistantMessages.push(e),r.assistantMessageIds.push(e.info.id),r.messages.push(UO(e,t)),r.headerMessageId||=e.info.id,a.add(e.info.id))});let o=MO($O(QO(r,n))),s=new Set;return e.forEach(e=>{LO(e)!==`assistant`&&(a.has(e.info.id)||s.add(e.info.id))}),{...o,ungroupedMessageIds:s}},tk=30,nk=4,rk=4,ik=33554432,ak=8388608,ok=new Map,sk=new Map,ck=0,lk=new WeakMap,uk=1,dk=()=>d()?nk:On()?rk:tk,fk=()=>d()||On()?ak:ik,pk=(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},mk=e=>{ok.delete(e);let t=sk.get(e)??0;sk.delete(e),ck=Math.max(0,ck-t)},hk=e=>{let t=lk.get(e);if(t!==void 0)return t;let n=uk;return uk+=1,lk.set(e,n),n},gk=e=>e.map(e=>`${hk(e.info)}:${hk(e.parts)}:${e.parts.map(e=>hk(e)).join(`,`)}`).join(`;`),_k=(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,gk(t),n?`1`:`0`,r?`1`:`0`].join(`|`)},vk=e=>{let t=ok.get(e);return t&&(ok.delete(e),ok.set(e,t)),t},yk=(e,t)=>{mk(e);let n=dk(),r=fk(),i=pk(e,t);if(!(i>r)){for(;ok.size>=n||ck+i>r;){let e=ok.keys().next().value;if(typeof e!=`string`)break;mk(e)}ok.set(e,t),sk.set(e,i),ck+=i}},bk=[],xk=(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},Sk=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},Ck=(e,t)=>t===null?{staticTurns:e,streamingTurns:bk}:{staticTurns:t===0?bk:e.slice(0,t),streamingTurns:e.slice(t)},wk=(e,t)=>{let n=Z.useRef(null),r=Z.useRef([]),i=Z.useRef(bk),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=bk,a.current=null);let l=Z.useMemo(()=>{let r=_k(t.sessionKey??``,e,t.showTextJustificationActivity,t.showTurnChangedFiles),i=vk(r);return i?(n.current=i,i):Ce(`ui.turns.projection_ms`,()=>{let i=ek(e,{previousProjection:n.current,showTextJustificationActivity:t.showTextJustificationActivity,showTurnChangedFiles:t.showTurnChangedFiles});return n.current=i,yk(r,i),i})},[e,t.showTextJustificationActivity,t.showTurnChangedFiles,t.sessionKey]),u=Sk({turnCount:l.turns.length,hasLiveTail:t.hasLiveTail,liveTailActive:t.liveTailActive,previousStart:a.current});return a.current=u,{projection:l,staticTurns:Z.useMemo(()=>{let e=Ck(l.turns,u).staticTurns;return xk(r.current,e)?r.current:r.current=e},[u,l.turns]),streamingTurns:Z.useMemo(()=>{let e=Ck(l.turns,u).streamingTurns;return xk(i.current,e)?i.current:i.current=e},[u,l.turns])}},Tk=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},Ek=(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(Tk(e[t])===`user`){r=t;break}if(r<0)return e;let i=-1;for(let t=e.length-1;t>r;--t)if(Tk(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},Dk=(e,t,n)=>{if(e.info.id!==t||e.parts===n)return e;let r=wn(e.parts,n,e.info);return r.length===e.parts.length&&r.every((t,n)=>t===e.parts[n])?e:TO({...e,parts:r})},Ok=(e,t)=>{let n=t.activeStreamingMessageId;if(!n)return e;if(e.kind===`ungrouped`){let r=Dk(e.message,n,t.liveParts);return r===e.message?e:{...e,message:r}}let r=!1,i=e.turn.assistantMessages.map(e=>{let i=Dk(e,n,t.liveParts);return i!==e&&(r=!0),i});if(!r)return e;let a=ek([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}},kk=e=>{let t=Z.useRef(e);return t.current=e,Z.useMemo(()=>(...e)=>t.current(...e),[])},Ak=2,jk=2,Mk=e=>Math.min(Math.max(0,e),Ak),Nk=(e,t)=>Math.min(Math.max(0,t),Math.max(0,e)+jk),Pk=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(jS.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Fk=e=>{let t=(0,Q.c)(3),{children:n,enabled:r}=e,i;return t[0]!==n||t[1]!==r?(i=(0,$.jsx)(Mo.Provider,{value:r,children:n}),t[0]=n,t[1]=r,t[2]=i):i=t[2],i},Ik=12,Lk=16,Rk=new Map,zk=e=>{let t=Rk.get(e);if(t)return Rk.delete(e),Rk.set(e,t),t},Bk=(e,t)=>{if(t.size!==0)for(Rk.delete(e),Rk.set(e,t);Rk.size>Lk;){let e=Rk.keys().next().value;if(typeof e!=`string`)break;Rk.delete(e)}},Vk=(e,t)=>{let n=Math.max(1,Math.floor(t?.seedCount??Ik)),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},Hk=(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},Uk=({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}},Wk=e=>{let{visible:t,preload:n}=Uk(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},Gk=(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},Kk=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},qk=e=>{let t=e.info;return typeof t.parentID==`string`&&t.parentID.length>0?t.parentID:null},Jk=e=>!e||Kk(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`)}),Yk=(e,t)=>{if(Kk(e)!==`assistant`||t&&qk(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}}},Xk=(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(Kk(t)===`user`)break;let{hide:i,details:a}=Yk(t,r);if(i){let e=typeof a?.command==`string`?a.command.trim():``;return e.length>0?e:null}}return null},Zk=e=>{let t=e.info,n=t.time?.completed,r=t.status;return typeof n!=`number`||n<=0?!1:typeof r!=`string`||r===`completed`},Qk=(e,t)=>{if(e.length===0)return[];if(e.filter(Zk).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},$k=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=cT({finish:r.finish,isMessageCompleted:Zk(n),activeStreamingPhase:e.activeStreamingPhase});return lT({finish:r.finish,parts:n.parts,streamPhase:i,error:r.error,isLastAssistantInTurn:!0})?t:null},eA=(e,t)=>{if(!t)return e;let n=e.filter(e=>e.kind!==`justification`||e.messageId!==t);return n.length===e.length?e:n},tA=(e,t)=>{if(!t)return e;let n=!1,r=e.map(e=>{let r=eA(e.parts,t);return r===e.parts?e:(n=!0,{...e,parts:r})});return n?r:e},nA=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,rA=e=>!e,iA=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},aA=e=>e.completionDisposition!==`active`&&!(e.isLastTurn&&e.sessionIsWorking),oA=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,sA=e=>e.isActivelyProcessing||e.expansionDisposition===`active`?!0:nA(e.expansionDisposition,e.activityRenderMode,{isLastTurn:e.isLastTurn,hasConfirmedFinalBody:e.hasConfirmedFinalBody}),cA=5,lA=[],uA=new Set,dA=[],fA=16,pA=(e,t)=>e===t?!0:!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n]),mA=320,hA=168,gA=8,_A=16,vA=6,yA=12,bA=4,xA=1,SA=2,CA=6,wA=4,TA=()=>On()?_A:gA,EA=30,DA=180,OA=5,kA=2,AA=120,jA=1200,MA=80,NA=160,PA=1500,FA=1.5,IA=90,LA=(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},RA=(e=>{let t=new Map;return{read:(e,n)=>{let r=t.get(e);if(r){if(pA(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)}}}})(fA),zA=(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})},BA=(e,t)=>({sessionKey:e,virtualizerKey:t??e}),VA=e=>e===`collapsed`?hA:mA,HA=(e,t)=>`${e}::activity:${t}`,UA=(e,t=0)=>Math.max(e===`collapsed`?yA:vA,Math.max(0,Math.floor(t))),WA=e=>e===`collapsed`?SA:xA,GA=e=>e===`collapsed`?wA:CA,KA=e=>e===`collapsed`?kA:OA,qA=(e,t)=>{e.current=t},JA=(e,t)=>RA.read(e,t),YA=(e,t,n)=>{!n||t.length===0||RA.write(e,t,n.takeSnapshot())},XA=e=>{let t=e.info;return(typeof t.clientRole==`string`?t.clientRole:null)??(typeof t.role==`string`?t.role:null)??null},ZA=(e,t)=>{if(XA(e)!==`system`)return e;let n=ej(e);return!n||!t.has(n)||e.info.clientRole===`assistant`?e:{...e,info:{...e.info,clientRole:`assistant`}}},QA=e=>!e||XA(e)!==`user`?!1:e.parts.some(e=>e?.type===`subtask`),$A=e=>{if(!e)return null;let t=e.info.id;return typeof t==`string`&&t.trim().length>0?t:null},ej=e=>{let t=e.info.parentID;return typeof t==`string`&&t.trim().length>0?t:null},tj=(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},nj=(e,t)=>Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.dataset.messageId===t)??null,rj=(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&&!tj(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}},ij=(e,t)=>{let n=rj(t,e);if(!n)return null;let r=nj(e,n.messageId)?.closest(`[data-turn-entry]`)?.dataset.turnEntry;return r?{...n,entryKey:r,attempts:0}:null},aj=e=>{let t=e,n=t.state?.metadata,r=gx(n)??null;if(r)return r;let i=t.state?.output;return typeof i==`string`?bx(i)??null:null},oj=e=>{if(XA(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:aj(e.parts[0])}},sj=(e,t)=>{if(!t)return e;let n=_x(e.parts,t);return n===e.parts?e:{...e,parts:n}},cj=(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}},lj=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,uj=Z.memo(e=>{let t=(0,Q.c)(22),{message:n,previousMessage:r,nextMessage:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s,activeStreamingPhase:c,animateUserOnMount:l,onUserAnimationConsumed:u,onContentChange:d,animationHandlers:f,scrollToBottom:p,reviewTransferDirection:m}=e,h=Qm(),g;t[0]!==n.sourceDirectory||t[1]!==n.sourceSessionID||t[2]!==h?(g=n.sourceSessionID?{...h,sessionId:n.sourceSessionID,directory:n.sourceDirectory??null,onRevertMessage:void 0,onEditMessage:void 0,capabilities:{...h.capabilities,compose:!1,mutateSession:!1,answerRequests:!1,openTimeline:!1,forkSession:!1,navigateNestedSession:!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)(uO,{message:n,previousMessage:r,nextMessage:i,animateUserOnMount:l,onUserAnimationConsumed:u,onContentChange:d,animationHandlers:f,scrollToBottom:p,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s,activeStreamingPhase:c,reviewTransferDirection:m}),t[4]=c,t[5]=l,t[6]=f,t[7]=o,t[8]=s,t[9]=n,t[10]=i,t[11]=d,t[12]=u,t[13]=r,t[14]=m,t[15]=p,t[16]=a,t[17]=v):v=t[17];let y=v,b;return t[18]!==y||t[19]!==_||t[20]!==h?(b=_===h?y:(0,$.jsx)(Zm.Provider,{value:_,children:y}),t[18]=y,t[19]=_,t[20]=h,t[21]=b):b=t[21],b},(e,t)=>{let n=e.turnGroupingContext,r=t.turnGroupingContext;return Zx(e.message,t.message)&&e.message.sourceSessionID===t.message.sourceSessionID&&e.message.sourceDirectory===t.message.sourceDirectory&&Qx(e.previousMessage,t.previousMessage)&&Qx(e.nextMessage,t.nextMessage)&&e.animateUserOnMount===t.animateUserOnMount&&e.onUserAnimationConsumed===t.onUserAnimationConsumed&&e.onContentChange===t.onContentChange&&e.scrollToBottom===t.scrollToBottom&&oS(n,r,e.message.info.id,XA(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});uj.displayName=`MessageRow`;var dj=Z.memo(e=>{let t=(0,Q.c)(105),{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=iA({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i,durationMs:n.durationMs});x=sA({expansionDisposition:oA({isLastTurn:r,turnCompletionDisposition:n.completionDisposition,headerPresentationDisposition:e.completionDisposition,hasAssistantMessages:n.assistantMessages.length>0}),activityRenderMode:a,isLastTurn:r,isActivelyProcessing:r&&i,hasConfirmedFinalBody:n.hasConfirmedFinalBody}),t[3]=a,t[4]=r,t[5]=i,t[6]=n.assistantMessages.length,t[7]=n.completionDisposition,t[8]=n.durationMs,t[9]=n.hasConfirmedFinalBody,t[10]=x}else x=t[10];let S=x,C=b?b.isExpanded:S,w;t[11]!==S||t[12]!==s||t[13]!==n.turnId?(w=()=>{s(n.turnId,S)},t[11]=S,t[12]=s,t[13]=n.turnId,t[14]=w):w=t[14];let T=q(w),E;if(t[15]!==n.assistantMessages||t[16]!==n.userMessage){let e=[n.userMessage,...n.assistantMessages],r=new Map;e.forEach((e,t)=>{r.set(e.info.id,t)}),E={ordered:e,lookup:r},t[15]=n.assistantMessages,t[16]=n.userMessage,t[17]=E}else E=t[17];let D=E,O;bb0:{if(h&&n.assistantMessages.some(e=>e.info.id===h)){O=h;break bb0}for(let e=n.assistantMessages.length-1;e>=0;--e){let t=n.assistantMessages[e];if(!Zk(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=$k({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=Qk(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(yj)),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=eA(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=tA(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(bj),t[40]=n.activitySegments,t[41]=L,t[42]=e}else e=t[42];V=e}let H=V,U=n.userMessage.info.time?.created,W=n.userMessage.info,ee=W?.model?.variant??W?.variant,G=typeof ee==`string`&&ee.trim().length>0?ee:void 0,K=typeof U==`number`?U:void 0,te;t[45]!==K||t[46]!==n.activityPresentationKind||t[47]!==n.changedFiles||t[48]!==n.diffStats||t[49]!==n.hasReasoning||t[50]!==n.hasTools||t[51]!==n.headerMessageId||t[52]!==n.summaryText||t[53]!==n.turnId||t[54]!==G||t[55]!==B||t[56]!==H?(te={turnId:n.turnId,summaryBody:n.summaryText,activityParts:B,activityGroupSegments:H,headerMessageId:n.headerMessageId,hasTools:n.hasTools,hasReasoning:n.hasReasoning,activityPresentationKind:n.activityPresentationKind,diffStats:n.diffStats,changedFiles:n.changedFiles,userMessageCreatedAt:K,userMessageVariant:G},t[45]=K,t[46]=n.activityPresentationKind,t[47]=n.changedFiles,t[48]=n.diffStats,t[49]=n.hasReasoning,t[50]=n.hasTools,t[51]=n.headerMessageId,t[52]=n.summaryText,t[53]=n.turnId,t[54]=G,t[55]=B,t[56]=H,t[57]=te):te=t[57];let ne=te,re;t[58]!==g||t[59]!==R||t[60]!==c||t[61]!==u||t[62]!==T||t[63]!==r||t[64]!==D.lookup||t[65]!==D.ordered||t[66]!==l||t[67]!==m||t[68]!==_||t[69]!==d||t[70]!==i||t[71]!==p||t[72]!==k||t[73]!==n.activityPresentationKind||t[74]!==n.completionDisposition||t[75]!==n.durationMs||t[76]!==n.hasReasoning||t[77]!==n.hasTools||t[78]!==n.headerMessageId||t[79]!==n.turnId||t[80]!==n.userMessage||t[81]!==ne||t[82]!==H||t[83]!==F||t[84]!==N[0]?.info.id||t[85]!==N.length?(re=(e,t)=>{let a=XA(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=iA({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:aA({completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i}),hasTools:n.hasTools,hasReasoning:n.hasReasoning,completionDisposition:w.completionDisposition,activityPresentationKind:n.activityPresentationKind,durationMs:w.durationMs,...x?{summaryBody:ne.summaryBody,activityParts:ne.activityParts,activityGroupSegments:ne.activityGroupSegments,headerMessageId:ne.headerMessageId,diffStats:ne.diffStats,changedFiles:ne.changedFiles,userMessageCreatedAt:ne.userMessageCreatedAt,userMessageVariant:ne.userMessageVariant,isGroupExpanded:t,toggleGroup:T}:{}}:void 0;return(0,$.jsx)(uj,{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.hasReasoning,t[77]=n.hasTools,t[78]=n.headerMessageId,t[79]=n.turnId,t[80]=n.userMessage,t[81]=ne,t[82]=H,t[83]=F,t[84]=N[0]?.info.id,t[85]=N.length,t[86]=re):re=t[86];let ie=kk(re),ae;bb4:{if(N===n.assistantMessages){ae=n;break bb4}let e;t[87]!==n||t[88]!==N?(e={...n,assistantMessages:N},t[87]=n,t[88]=N,t[89]=e):e=t[89],ae=e}let oe=ae,se=H.length>0,ce=n.assistantMessages.length>0,le;t[90]!==c||t[91]!==r||t[92]!==i||t[93]!==se||t[94]!==ce||t[95]!==n.activityPresentationKind||t[96]!==n.completionDisposition?(le=lj({chatRenderMode:c,activityPresentationKind:n.activityPresentationKind,hasVisibleActivitySegments:se,hasAssistantMessages:ce,completionDisposition:n.completionDisposition,isLastTurn:r,sessionIsWorking:i}),t[90]=c,t[91]=r,t[92]=i,t[93]=se,t[94]=ce,t[95]=n.activityPresentationKind,t[96]=n.completionDisposition,t[97]=le):le=t[97];let ue;return t[98]!==T||t[99]!==C||t[100]!==ie||t[101]!==oe||t[102]!==v||t[103]!==le?(ue=(0,$.jsx)(hO,{turn:oe,activityExpanded:C,onToggleActivity:T,showCompactionStatus:le,stickyUserHeader:v,renderMessage:ie}),t[98]=T,t[99]=C,t[100]=ie,t[101]=oe,t[102]=v,t[103]=le,t[104]=ue):ue=t[104],ue});dj.displayName=`TurnBlock`;var fj=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(mr(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)(uj,{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});fj.displayName=`UngroupedMessageRow`;var pj=Z.memo(e=>{let t=(0,Q.c)(29),{entry:n,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,stickyUserHeader:o,sessionIsWorking:s,activityRenderMode:c,turnUiStates:l,onToggleTurnGroup:u,chatRenderMode:d,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g}=e;if(n.kind===`ungrouped`){let e;return t[0]!==m||t[1]!==h||t[2]!==n.message||t[3]!==n.nextMessage||t[4]!==n.previousMessage||t[5]!==i||t[6]!==r||t[7]!==p||t[8]!==g||t[9]!==a||t[10]!==f?(e=(0,$.jsx)(fj,{message:n.message,previousMessage:n.previousMessage,nextMessage:n.nextMessage,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g}),t[0]=m,t[1]=h,t[2]=n.message,t[3]=n.nextMessage,t[4]=n.previousMessage,t[5]=i,t[6]=r,t[7]=p,t[8]=g,t[9]=a,t[10]=f,t[11]=e):e=t[11],e}let _;return t[12]!==m||t[13]!==h||t[14]!==c||t[15]!==d||t[16]!==n.isLastTurn||t[17]!==n.turn||t[18]!==i||t[19]!==r||t[20]!==u||t[21]!==p||t[22]!==g||t[23]!==a||t[24]!==s||t[25]!==f||t[26]!==o||t[27]!==l?(_=(0,$.jsx)(dj,{turn:n.turn,isLastTurn:n.isLastTurn,sessionIsWorking:s,activityRenderMode:c,turnUiStates:l,onToggleTurnGroup:u,chatRenderMode:d,shouldAnimateUserMessage:f,onUserAnimationConsumed:p,activeStreamingMessageId:m,activeStreamingPhase:h,reviewTransferDirection:g,onMessageContentChange:r,getAnimationHandlers:i,scrollToBottom:a,stickyUserHeader:o}),t[12]=m,t[13]=h,t[14]=c,t[15]=d,t[16]=n.isLastTurn,t[17]=n.turn,t[18]=i,t[19]=r,t[20]=u,t[21]=p,t[22]=g,t[23]=a,t[24]=s,t[25]=f,t[26]=o,t[27]=l,t[28]=_):_=t[28],_});pj.displayName=`MessageListEntry`;var mj=Z.memo(({entries:e,engine:t,contentRef:n,scrollRef:r,registerTanstackVirtualizer:i,virtualizerKey:a,onMessageContentChange:o,getAnimationHandlers:s,scrollToBottom:c,stickyUserHeader:l,activityRenderMode:u,turnUiStates:d,onToggleTurnGroup:f,chatRenderMode:p,shouldAnimateUserMessage:m,onUserAnimationConsumed:h,reviewTransferDirection:g})=>{let _=t===`tanstack`,v=Z.useRef(t),y=Z.useRef(null),[b,x]=Z.useReducer(e=>e+1,0);if(t===`none`)y.current=null;else if(v.current===`none`&&_&&y.current===null){let e=n.current,t=r?.current;e&&t&&(y.current=ij(e,t))}let S=Z.useRef(!1),C=Z.useRef(0),w=Z.useRef(null),T=_&&On();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<NA,D=()=>{let e=r?.current;return!e||e.scrollTop<e.clientHeight*FA},[O,k]=Z.useState(e),A=O;e===O?w.current!==null&&(w.current=null):T&&LA(O,e)&&E()&&!D()&&(w.current===null||performance.now()-w.current<PA)?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>=PA;(!E()||D()||e)&&j()},T?IA:null);let M=Z.useRef(A);M.current=A;let N=Z.useMemo(()=>A.map(e=>e.key),[A]),P=TA(),[F,I]=Z.useState(()=>Mk(P));Z.useEffect(()=>{if(!(!_||F>=P))return ds(()=>{Z.startTransition(()=>{I(e=>Nk(e,P))})})},[F,_,P]);let L=HA(a,u),[R]=Z.useState(()=>_?JA(L,e.map(e=>e.key)):void 0),z=Z.useRef(null),B=VA(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??zA(N,W.current,V.current));let G=_c({count:A.length,enabled:_,getScrollElement:()=>r?.current??null,estimateSize:()=>V.current,overscan:F,scrollToFn:(e,t,n)=>{let r=z.current;r&&(r.style.height=`${n.getTotalSize()}px`),gc(e,t,n)},getItemKey:e=>M.current[e]?.key??`index:${e}`,anchorTo:`end`,followOnAppend:!0,scrollEndThreshold:MA,initialOffset:()=>U.current?2**53-1:r?.current?.scrollTop??0,initialMeasurementsCache:ee.current});rt(()=>{if(v.current=t,!_){y.current=null;return}let e=y.current,n=r?.current;if(!e||!n)return;let i=nj(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 K=G.getVirtualItems(),te=K.map(e=>e.index),[ne,re]=Z.useState(()=>Vk(N,{seedCount:UA(u),restore:zk(L)})),ie=Hk(ne,N);ie!==ne&&re(ie);let ae=Z.useRef(ie);ae.current=ie;let oe=Z.useRef(null);G.scrollDirection&&(oe.current=G.scrollDirection);let se=G.range?.startIndex??K[0]?.index??Math.max(0,A.length-1),ce=G.range?.endIndex??K[K.length-1]?.index??Math.max(0,A.length-1),le=G.isScrolling,ue=Math.max(0,ce-se+1),de=Wk({entryKeys:N,mountedIndexes:te,visibleStartIndex:se,visibleEndIndex:ce,scrollDirection:oe.current,preloadEntries:UA(u,ue),hydratedKeys:ie,allowVisibleRelease:!le,preloadReleaseLimit:le?WA(u):bA,visibleReleaseLimit:le?0:GA(u)}),fe=de.join(`\0`),pe=Z.useRef(de);pe.current=de,Z.useEffect(()=>{if(!(!_||!fe))return ds(()=>{Z.startTransition(()=>{re(e=>{let t=null;for(let n of pe.current)e.has(n)||(t??=new Set(e),t.add(n));return t??e})})})},[_,fe]),Z.useEffect(()=>{re(e=>Gk(e,N))},[N]),Z.useEffect(()=>{if(!_)return;let e=G.itemSizeCache,t=KA(u);if(e.size>=t){let t=0;for(let n of e.values())t+=n;V.current=Math.min(jA,Math.max(AA,Math.round(t/e.size)))}}),Z.useEffect(()=>{if(_)return i?.(G),()=>{YA(L,M.current.map(e=>e.key),G),Bk(L,ae.current),i?.(null)}},[_,G,L]);let me=kk((e,t=!0)=>(0,$.jsx)(Fk,{enabled:t,children:(0,$.jsx)(pj,{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:me(e)},e.key))});if(t===`tanstack`){let e=K[0]?.start??0;return(0,$.jsx)(`div`,{ref:z,className:`relative w-full`,style:{height:G.getTotalSize()},children:(0,$.jsx)(`div`,{style:{paddingTop:`${e}px`},children:K.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:me(t,ie.has(t.key))},t.key):null})})})}return null});mj.displayName=`StaticHistoryList`;var hj=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)(pj,{...e})}),t[0]=e,t[1]=n),n});hj.displayName=`TailEntry`;var gj=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=ui(_??``,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=Ok(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)(hj,{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};gj.displayName=`StreamingTailContent`;var _j=Z.forwardRef(({sessionKey:e,virtualizerKey:t,messages:n,sessionIsWorking:r=!1,activeStreamingMessageId:i=null,activeStreamingPhase:a=null,retryOverlay:o=null,onMessageContentChange:s,getAnimationHandlers:l,scrollToBottom:u,scrollRef:d,directory:f},p)=>{Ie(`ui.message_list.render`);let{sessionKey:m,virtualizerKey:h}=BA(e,t),g=c(e=>e.stickyUserHeader),_=c(e=>e.chatRenderMode),v=c(e=>e.activityRenderMode),y=c(e=>e.showTurnChangedFiles),b=zr(e=>e.reviewTransferBySessionId.get(m)??null),[x,S]=Z.useState(()=>new Map),C=Z.useRef({sessionKey:void 0,previousOrder:[],animatedIds:new Set}),w=q(l),T=q(()=>{u?.()}),E=q((e,t)=>{S(n=>{let r=new Map(n),i=n.get(e)?.isExpanded??t;return r.set(e,{isExpanded:rA(i)}),r})}),D=Z.useMemo(()=>Ce(`ui.message_list.base_display_ms`,()=>{let e=new Set,t=new Map,r=[];for(let e of n){let n=e.info?.id;typeof n==`string`&&t.set(n,e)}for(let i=0;i<n.length;i+=1){let a=n[i],o=a.info?.id;if(typeof o==`string`){if(e.has(o))continue;e.add(o)}r.push(TO(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=ZA(t,a);xO(t)&&a.add(t.info.id);let o=i.length>0?i[i.length-1]:void 0;if(QA(o)){let e=oj(n);if(e.hide){i[i.length-1]=sj(o,e.taskSessionId);continue}}if(Jk(o)){let e=Yk(n,$A(o));if(e.hide){i[i.length-1]=cj(o,e.details);continue}}i.push(n)}return i}),[n]),O=Z.useRef(null),k=Z.useRef(null),A=Z.useCallback(()=>{let e=k.current;e&&(k.current=null,e.cancel())},[]);Z.useEffect(()=>()=>{A()},[A]);let j=q(()=>d?.current?d.current:typeof document>`u`?null:document.querySelector(`[data-scrollbar="chat"]`)),M=Z.useMemo(()=>Ce(`ui.message_list.retry_overlay_ms`,()=>Ek(D,{sessionId:o?.sessionId??null,message:o?.message??`Quota limit reached. Retrying automatically.`,confirmedAt:o?.confirmedAt,fallbackTimestamp:o?.fallbackTimestamp??0})),[D,o]),N=r||!!i,P=Z.useRef(N),F=Z.useRef(m);F.current!==m&&(F.current=m,P.current=!1),N&&(P.current=!0);let{projection:I,staticTurns:L,streamingTurns:R}=wk(M,{sessionKey:m,showTextJustificationActivity:_===`sorted`,showTurnChangedFiles:y,hasLiveTail:N||P.current,liveTailActive:N}),z=I.ungroupedMessageIds.size>0,B=z?M:lA,V=z?I.ungroupedMessageIds:uA,H=Z.useMemo(()=>Ce(`ui.message_list.render_entries_ms`,()=>{let e=L.map(e=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===I.lastTurnId}));if(V.size===0)return e;let t=new Map;e.forEach(e=>{t.set(e.turn.userMessage.info.id,e)});let n=[];return B.forEach((e,r)=>{let i=t.get(e.info.id);if(i){n.push(i);return}V.has(e.info.id)&&n.push({kind:`ungrouped`,key:`msg:${e.info.id}`,message:e,previousMessage:r>0?B[r-1]:void 0,nextMessage:r<B.length-1?B[r+1]:void 0})}),n}),[I.lastTurnId,B,V,L]),U=Z.useMemo(()=>{if(R.length>0)return R.map(e=>({kind:`turn`,key:`turn:${e.turnId}`,turn:e,isLastTurn:e.turnId===I.lastTurnId}));if(I.ungroupedMessageIds.size===0)return dA;let e=M[M.length-1];return!e||!I.ungroupedMessageIds.has(e.info.id)?dA:[{kind:`ungrouped`,key:`msg:${e.info.id}`,message:e,previousMessage:M.length>1?M[M.length-2]:void 0,nextMessage:void 0}]},[M,I.lastTurnId,I.ungroupedMessageIds,R]),W=U.length>0;W&&N&&Ie(`ui.message_list.render.streaming`);let ee=H,G=ee.length>=cA,K=Z.useRef(G);qA(K,G);let te=G?`tanstack`:`none`,ne=Z.useRef(null),re=q(e=>{ne.current=e}),ie=Z.useMemo(()=>U.length>0?[...ee,...U]:ee,[ee,U]),ae=q(e=>{s(e)}),oe=q(e=>{s(e)}),se=Z.useMemo(()=>n.filter(e=>XA(e)===`user`).map(e=>e.info.id),[n]);{let t=C.current;t.sessionKey!==e&&(t.sessionKey=e,t.previousOrder=se,t.animatedIds=new Set);let n=t.previousOrder;if(se.length>n.length&&n.every((e,t)=>se[t]===e)&&xn(e))for(let r=n.length;r<se.length;r+=1){let n=se[r];if(n&&!t.animatedIds.has(n)){if(!gn(e))break;t.animatedIds.add(n)}}t.previousOrder=se}let ce=q(e=>XA(e)===`user`&&C.current.animatedIds.has(e.info.id)),le=q(e=>{C.current.animatedIds.delete(e)}),ue=Z.useMemo(()=>{let e=new Map;return ie.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},[ie]),de=Z.useMemo(()=>{let e=new Map;return ie.forEach((t,n)=>{t.kind===`turn`&&e.set(t.turn.turnId,n)}),e},[ie]),fe=q(e=>{let t=j();return t?t.querySelector(`[data-message-id="${e}"]`):null}),pe=q((e,t=`auto`)=>{if(e<0||e>=ee.length||!G)return!1;let n=ne.current;return n?(n.scrollToIndex(e,{align:`start`,behavior:t===`smooth`?`smooth`:`auto`}),!0):!1}),me=q((e,t=`auto`)=>{let n=j();if(!n)return!1;let r=fe(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(!p)return;let e={scrollToTurnId:(e,t)=>{let n=t?.behavior??`auto`,r=de.get(e);if(r===void 0)return!1;let i=j();if(!i)return!1;let a=i.querySelector(`[data-turn-id="${e}"]`);return a?(a.scrollIntoView({behavior:n,block:`start`}),!0):W&&r>=ee.length?!1:pe(r,n)},scrollToMessageId:(e,t)=>{let n=t?.behavior??`auto`,r=ue.get(e);return r===void 0?!1:me(e,n)||(W&&r>=ee.length?!1:pe(r,n))},holdViewportAnchor:e=>{let t=j();if(!t||typeof window>`u`)return;A();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(),k.current?.cancel===s&&(k.current=null))},c=()=>{s()};k.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=fe(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>=EA||n>=DA){s();return}a=window.requestAnimationFrame(l)};a=window.requestAnimationFrame(l)},cancelViewportAnchorHold:A,isHistoryVirtualized:()=>K.current,captureViewportAnchor:()=>{let e=j();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`||!tj(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=j();if(!t||!ue.has(e.messageId))return!1;let n=()=>{let n=fe(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=ue.get(e.messageId);if(typeof t==`number`&&t<ee.length)return pe(t,`auto`)}return n()},scrollToBottom:()=>{if(G&&ee.length>0&&ne.current){ne.current.scrollToEnd();return}let e=j();e&&(e.scrollTop=e.scrollHeight)}};if(typeof p==`function`)return p(e),()=>{p(null)};let t=p;return t.current=e,()=>{t.current=null}},[A,ee.length,ue,G,W,de,p]),(0,$.jsx)(`div`,{children:(0,$.jsx)(gs,{disabled:!1,children:(0,$.jsxs)(`div`,{className:`relative w-full`,children:[(0,$.jsx)(gs,{disabled:G,children:(0,$.jsx)(Pk,{enabled:!0,children:(0,$.jsx)(mj,{entries:ee,engine:te,contentRef:O,scrollRef:d,registerTanstackVirtualizer:re,virtualizerKey:h,onMessageContentChange:ae,getAnimationHandlers:w,scrollToBottom:T,stickyUserHeader:g,activityRenderMode:v,turnUiStates:x,onToggleTurnGroup:E,chatRenderMode:_,shouldAnimateUserMessage:ce,onUserAnimationConsumed:le,reviewTransferDirection:b},h)})}),(0,$.jsx)(gj,{entries:U,directory:f,sessionId:m,onMessageContentChange:oe,getAnimationHandlers:w,scrollToBottom:T,stickyUserHeader:g,sessionIsWorking:r,activityRenderMode:v,turnUiStates:x,onToggleTurnGroup:E,chatRenderMode:_,showTurnChangedFiles:y,shouldAnimateUserMessage:ce,onUserAnimationConsumed:le,activeStreamingMessageId:i,activeStreamingPhase:a,reviewTransferDirection:b})]})})})});_j.displayName=`MessageList`;var vj=Z.memo(_j);function yj(e){return e.info.id}function bj(e){return e!==null}var xj=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},Sj=({diff:e,filePath:t})=>{let{currentTheme:n}=Va(),r=Z.useMemo(()=>To(n),[n]),i=Z.useMemo(()=>$s(e),[e]),a=is(t||i[0]?.file)||`text`,o=Z.useMemo(()=>i.flatMap(e=>e.lines.map(e=>e.content)).join(`
|
|
6582
6582
|
`),[i]),s=lc(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)(xj,{content:e.content,html:n})})]},t)})})]},n))})},Cj=e=>{let t=(0,Q.c)(21),{content:n,filePath:r}=e,{currentTheme:i}=Va(),a;t[0]===i?a=t[1]:(a=To(i),t[0]=i,t[1]=a);let o=a,s;t[2]===n?s=t[3]:(s=n.split(`
|
|
6583
6583
|
`),t[2]=n,t[3]=s);let c=s,l;t[4]===r?l=t[5]:(l=is(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=lc(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)(xj,{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},wj=new Set([`id`,`identifier`,`title`,`name`]),Tj=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Ej=e=>e.replace(/([A-Z])/g,` $1`).replace(/[_-]/g,` `).replace(/^./,e=>e.toUpperCase()),Dj=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},Oj=e=>{try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}},kj=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?`${Ej(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)(kj,{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(Tj(n)){let e;t[18]===n?e=t[19]:(e=Dj(n),t[18]=n,t[19]=e);let a=e,o;t[20]===n?o=t[21]:(o=Object.entries(n).filter(jj),t[20]=n,t[21]=o);let s=o,c;t[22]!==a||t[23]!==r?(c=r?`${Ej(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)(kj,{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?Ej(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`&&Oj(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:Ej(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});kj.displayName=`JsonSummaryValue`;var Aj=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)(kj,{value:n,depth:0})}),t[0]=n,t[1]=r),r});Aj.displayName=`JsonSummaryView`;function jj(e){let[t]=e;return!wj.has(t)}var Mj={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`},Nj={style:{whiteSpace:`pre-wrap`,wordBreak:`break-word`,overflowWrap:`break-word`}},Pj=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})},Fj=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},Ij=e=>e===`filepath`||e===`file_path`?`filePath`:e===`parentDir`||e===`parent_dir`?`parentDirectory`:e,Lj=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)(Aj,{data:n})}),t[0]=n,t[1]=r),r},Rj=({permission:e,onResponse:t})=>{let{t:n}=ot(),[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=Ut,c=Mi(),l=J(e=>e.currentSessionId),u=Z.useMemo(()=>{if(!l||e.sessionID===l)return!1;let t=c.find(t=>t.id===e.sessionID);return!!(t?.parentID&&t.parentID===l)},[e.sessionID,l,c]),d=async n=>{i(!0);try{await s(e.sessionID,e.id,n),o(!0),t?.(n)}catch(e){console.error(`[PermissionCard] Failed to respond to permission:`,e)}finally{i(!1)}};if(a)return null;let f=e.permission||`unknown`,p=f.toLowerCase(),m=(t,n=``)=>{let r=e.metadata[t];return typeof r==`string`?r:typeof r==`number`?String(r):n},h=t=>{let n=e.metadata[t];return typeof n==`number`?n:void 0},g=t=>!!e.metadata[t],_=Fj(f),v=Object.fromEntries(Object.entries(e.metadata).filter(([e])=>e!==`always`).map(([e,t])=>[Ij(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:[Pj(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)(ec,{language:`bash`,code:e,style:Mj,codeStyle:Nj.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)(ma,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(Sj,{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)(ma,{outerClassName:`max-h-[60vh]`,className:`tool-output-surface p-1 rounded-xl border border-border/20 bg-transparent`,children:(0,$.jsx)(Cj,{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)(ma,{outerClassName:`max-h-32`,className:`p-0`,children:(0,$.jsx)(Lj,{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)(ma,{outerClassName:`max-h-32`,className:`p-0`,children:typeof a==`object`&&a?(0,$.jsx)(Lj,{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)(ma,{outerClassName:`max-h-48`,className:`p-0`,children:(0,$.jsx)(Lj,{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)(da,{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)(da,{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)(da,{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 zj(e){let t=[];return(e.questions??[]).forEach((e,n)=>{let r=e.header?.trim(),i=r&&r.length>0?r:`Question ${n+1}`;t.push(`## ${i}`),t.push(``),t.push(e.question),t.push(``),e.multiple&&(t.push(`_Select all that apply._`),t.push(``)),e.options.forEach(e=>{let n=e.label,r=e.description?.trim();t.push(r?`- **${n}** — ${r}`:`- **${n}**`)}),t.push(``)}),t.join(`
|
|
6584
6584
|
`).trimEnd()}function Bj(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 Vj({scrollHeight:e,currentHeight:t}){let n=Math.min(Math.max(e,40),200);return t===n?null:n}var Hj=`summary`,Uj=Z.memo(function(e){let t=(0,Q.c)(31),{value:n,placeholder:r,disabled:i,onValueChange:a,onKeyDown:o}=e,s=Z.useRef(null),[c,l]=Z.useState(n),[u,d]=Z.useState(40),[f,p]=Z.useState(!1),m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{let e=s.current;if(!e||document.activeElement!==e)return;let t=e.closest(`.chat-scroll`);if(!t){e.scrollIntoView({block:`nearest`});return}let n=window.visualViewport,r=t.getBoundingClientRect(),i=n?.offsetTop??0,a=n?n.offsetTop+n.height:document.documentElement.clientHeight,o=Number.parseFloat(getComputedStyle(document.documentElement).getPropertyValue(`--oc-kb-scroll-inset`))||0,c=Math.max(r.top,i),l=Math.min(r.bottom,a-o),u=Math.max(0,l-c),d=e.closest(`[data-question-card]`),f=d?.getBoundingClientRect(),p=(d&&f&&f.height<=u?d:e).getBoundingClientRect();p.bottom>l-12?t.scrollTop+=p.bottom-l+12:p.top<c+12&&(t.scrollTop+=p.top-c-12)},t[0]=m):m=t[0];let h=q(m),g;t[1]===h?g=t[2]:(g=()=>{requestAnimationFrame(h)},t[1]=h,t[2]=g);let _=q(g),v;t[3]===h?v=t[4]:(v=()=>{let e=()=>requestAnimationFrame(h);return e(),window.addEventListener(`oc:keyboard-settled`,e),window.addEventListener(`resize`,e),window.visualViewport?.addEventListener(`resize`,e),window.visualViewport?.addEventListener(`scroll`,e),()=>{window.removeEventListener(`oc:keyboard-settled`,e),window.removeEventListener(`resize`,e),window.visualViewport?.removeEventListener(`resize`,e),window.visualViewport?.removeEventListener(`scroll`,e)}},t[3]=h,t[4]=v);let y;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(y=[],t[5]=y):y=t[5],Z.useEffect(v,y);let b,x;t[6]===n?(b=t[7],x=t[8]):(b=()=>{l(n)},x=[n],t[6]=n,t[7]=b,t[8]=x),Z.useEffect(b,x);let S;t[9]!==u||t[10]!==f?(S=()=>{let e=s.current;if(!e)return;let t=Vj({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}),Wj=({question:e})=>{let{t}=ot(),n=sn,r=qn,i=c(e=>e.isMobile),a=Mi(),o=J(e=>e.currentSessionId),s=Z.useMemo(()=>{if(!o||e.sessionID===o)return!1;let t=a.find(t=>t.id===e.sessionID);return!!(t?.parentID&&t.parentID===o)},[e.sessionID,o,a]),[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===Hj,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:Hj,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){Jt(e)?(Ii.info(t(`chat.questionCard.noLongerPending`)),m(!0)):Ii.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=>{Wh(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){Jt(e)?(Ii.info(t(`chat.questionCard.noLongerPending`)),m(!0)):Ii.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=zj(e);if((await ct(n)).ok){Ii.success(t(`chat.questionCard.copiedMarkdown`));return}Ii.error(t(`chat.questionCard.copyFailed`))},[e,t]),U=Z.useCallback(async()=>{let n=Bj(e);if((await ct(n)).ok){Ii.success(t(`chat.questionCard.copiedJson`));return}Ii.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`)}),s?(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground px-1.5 py-0.5 rounded bg-foreground/5`,children:t(`chat.questionCard.fromSubagent`)}):null,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===Hj,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)(_a,{checked:r,onChange:()=>I(e.label),disabled:d}):(0,$.jsx)(uo,{checked:r,onChange:()=>I(e.label),disabled:d})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:Y(`typography-meta break-all`,r?`text-foreground font-medium`:`text-foreground/80`),children:e.label}),i?(0,$.jsx)(`span`,{className:`typography-micro text-primary/80`,children:t(`chat.questionCard.recommended`)}):null]}),e.description?(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground break-words`,children:e.description}):null]})]})},`${n}:${e.label}`)}),(0,$.jsx)(`button`,{type:`button`,onClick:L,disabled:d,className:Y(`w-full px-1.5 py-1 text-left rounded transition-colors`,`hover:bg-interactive-hover/30`,j?`bg-interactive-selection/20`:null,d?`opacity-60 cursor-not-allowed`:null),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`edit`,className:Y(`h-3.5 w-3.5`,j?`text-primary`:`text-muted-foreground/50`)}),(0,$.jsx)(`span`,{className:Y(`typography-meta`,j?`text-foreground font-medium`:`text-muted-foreground`),children:t(`chat.questionCard.other`)})]})}),j?(0,$.jsx)(`div`,{className:`pl-6 pr-1 pt-0.5`,children:(0,$.jsx)(Uj,{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]})]})})})},Gj={activity:`idle`,hasWorkingContext:!1,hasActiveTools:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,lifecyclePhase:null,statusText:null,isGenericStatus:!0,isWaitingForPermission:!1,canAbort:!1,compactionDeadline:null,activePartType:void 0,activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,retryInfo:null,turnStartedAt:void 0},Kj=[],qj=`\0`,Jj=new Set([`edit`,`write`,`multiedit`,`apply_patch`]),Yj={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`},Xj=[`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`],Zj=(e,t)=>{let n=Yj[e];return n?t(n):t(`chat.assistantStatus.usingTool`,{tool:e})},Qj=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)},$j=(e,t)=>t(Xj[Qj(e)%Xj.length]??`chat.assistantStatus.working`),eM=(e,t,n)=>{let r,i;if(!St(e))for(let t=e.length-1;t>=0;--t){let n=e[t];if(n)switch(n.type){case`reasoning`:{let e=n.time??oM(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=sM(n);Jj.has(e)?(r=`editing`,i=e):(r=`tool`,i=e)}break}case`text`:{let e=aM(n)??``;if(typeof e==`string`&&e.trim().length>0){let e=oM(n);(!e||e.end===void 0)&&!r&&(r=`text`)}break}}}let a=r===void 0,o=r===`editing`?i===`multiedit`?Zj(i,n):n(`chat.assistantStatus.editingFile`):r===`tool`&&i?Zj(i,n):r===`reasoning`?n(`chat.assistantStatus.thinking`):r===`text`?n(`chat.assistantStatus.composing`):$j(t,n);return{activePartType:r,activeToolName:i,statusText:o,isGenericStatus:a}},tM=e=>[e.activePartType??``,e.activeToolName??``,e.statusText,e.isGenericStatus?`1`:`0`].join(qj),nM=e=>{let[t,n,r=`working`,i]=e.split(qj);return{activePartType:t===`text`||t===`tool`||t===`reasoning`||t===`editing`?t:void 0,activeToolName:n||void 0,statusText:r,isGenericStatus:i===`1`}},rM=e=>e.type===`reasoning`,iM=e=>e.type===`text`,aM=e=>{if(iM(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},oM=e=>(iM(e)||rM(e),e.time),sM=e=>{if(e.tool)return e.tool;let t=e;return typeof t.name==`string`?t.name:`tool`};function cM(e,t){let{t:n}=ot(),r=J(e=>e.currentSessionId),i=J(e=>e.currentSessionDirectory),a=e??r,o=t??i,s=Z.useMemo(()=>e=>a?e.pendingSendMessageIDs.get(a)??null:null,[a]),c=J(s),l=Tr(a??``,o??void 0),u=Z.useMemo(()=>{for(let e=l.length-1;e>=0;e--)if(l[e].role===`assistant`)return l[e].id;return null},[l]),d=Z.useMemo(()=>{for(let e=l.length-1;e>=0;e--){let t=l[e];if(t.role===`user`)return{id:t.id,turnStartedAt:Number.isFinite(t.time.created)?t.time.created:void 0}}return{id:null,turnStartedAt:void 0}},[l]),f=d.id,p=ui(u??``,o??void 0,a??void 0),m=ui(f??``,o??void 0,a??void 0),h=!!f&&yO(m),g=Z.useMemo(()=>{let e=`${a??``}:${u??``}`;return tM(eM(u?p:Kj,e,n))},[a,u,p,n]),_=Si(a??``,o??void 0),v=Ur(a??``,o??void 0),y=Z.useMemo(()=>e=>a?e.sessionAbortFlags?.get(a)??null:null,[a]),b=J(y),{phase:x,isWorking:S}=Uh(a,o??void 0),C=dr(a??``,o??void 0),w=C?.type===`retry`?C.attempt:void 0,T=C?.type===`retry`?C.next:void 0,E=Z.useMemo(()=>nM(g),[g]),D=Z.useMemo(()=>{let e=!!(b&&!b.acknowledged);return{wasAborted:e,abortActive:e}},[b]),O=Z.useMemo(()=>{if(D.wasAborted)return{...Gj,wasAborted:!0,abortActive:D.abortActive,activity:`idle`,hasWorkingContext:!1,isWorking:!1,isStreaming:!1,isCooldown:!1,statusText:null,canAbort:!1,retryInfo:null};let e=S,t=x===`busy`,r=x===`retry`,i=e&&h,a=`idle`;e&&(a=!i&&(E.activePartType===`tool`||E.activePartType===`editing`)?`tooling`:`streaming`);let o=r?{attempt:w,next:T}:null;return{activity:a,hasWorkingContext:e,hasActiveTools:!i&&(E.activePartType===`tool`||E.activePartType===`editing`),isWorking:e,isStreaming:t,isCooldown:!1,lifecyclePhase:t?`streaming`:null,statusText:e?i?n(`chat.assistantStatus.compacting`):E.statusText:null,isGenericStatus:!e||!i&&E.isGenericStatus,isWaitingForPermission:!1,canAbort:e,compactionDeadline:null,activePartType:e&&!i?E.activePartType:void 0,activeToolName:e&&!i?E.activeToolName:void 0,wasAborted:!1,abortActive:!1,lastCompletionId:null,isComplete:!1,retryInfo:o,turnStartedAt:d.turnStartedAt}},[x,S,h,d.turnStartedAt,E,D,w,T,n]);return{forming:Z.useMemo(()=>({isActive:S&&E.activePartType===`text`,characterCount:0}),[S,E.activePartType]),working:Z.useMemo(()=>{if(O.wasAborted||O.abortActive)return O;if(c)return{...O,activity:`streaming`,hasWorkingContext:!0,isWorking:!0,isStreaming:!0,isCooldown:!1,lifecyclePhase:`streaming`,statusText:n(`chat.assistantStatus.sendingMessage`),isGenericStatus:!1,isWaitingForPermission:!1,canAbort:!1,activePartType:void 0,activeToolName:void 0,retryInfo:null};let e=_.length>0,t=v.length>0;return!e&&!t?O:t?{...O,statusText:null,isWorking:!1,hasWorkingContext:!1,hasActiveTools:!1,canAbort:!1,activePartType:void 0,activeToolName:void 0,retryInfo:null}:{...O,statusText:n(`chat.assistantStatus.waitingForPermission`),isWaitingForPermission:!0,canAbort:!1,retryInfo:null}},[O,c,_,v,n])}}var lM=Z.memo(()=>{let e=(0,Q.c)(13),t=Qm(),n=J(uM),r=J(dM),i=t.sessionId??n,a=t.directory??r??void 0,o;e[0]===i?o=e[1]:(o=e=>i?e.sessionAbortFlags?.get(i)??null:null,e[0]=i,e[1]=o);let s=J(o),c=J(fM),l=J(pM),{working:u}=cM(i,a),d=Ei(mM),f=!!(s&&!s.acknowledged),p=!!(i&&c===i&&typeof l==`number`&&l>Date.now()),m=f||u.wasAborted,h=f||u.abortActive,g;return e[2]!==d||e[3]!==p||e[4]!==m||e[5]!==h||e[6]!==u.isGenericStatus||e[7]!==u.isWaitingForPermission||e[8]!==u.isWorking||e[9]!==u.retryInfo||e[10]!==u.statusText||e[11]!==u.turnStartedAt?(g=(0,$.jsx)(rh,{isWorking:u.isWorking,statusText:u.statusText,isGenericStatus:u.isGenericStatus,isWaitingForPermission:u.isWaitingForPermission,wasAborted:m,abortActive:h,retryInfo:u.retryInfo,turnStartedAt:u.turnStartedAt,showAbortPrompt:p,showAssistantStatus:!0,showTodos:!1,agentName:d}),e[2]=d,e[3]=p,e[4]=m,e[5]=h,e[6]=u.isGenericStatus,e[7]=u.isWaitingForPermission,e[8]=u.isWorking,e[9]=u.retryInfo,e[10]=u.statusText,e[11]=u.turnStartedAt,e[12]=g):g=e[12],g});lM.displayName=`StatusRowContainer`;function uM(e){return e.currentSessionId}function dM(e){return e.currentSessionDirectory}function fM(e){return e.abortPromptSessionId}function pM(e){return e.abortPromptExpiresAt}function mM(e){return e.currentAgentName}var hM=e=>!!e&&typeof e==`object`&&!Array.isArray(e);function gM(e){let t=e?.metadata;if(!hM(t))return null;let n=t.openchamber;if(!hM(n))return null;let r=n.assist;if(!hM(r))return null;let i=typeof r.recap==`string`?r.recap.trim():``,a=typeof r.forMessageID==`string`?r.forMessageID:``;return!a||!i?null:{recap:i,forMessageID:a,generatedAt:typeof r.generatedAt==`number`?r.generatedAt:0}}var _M=6e4;function vM(e,t){let n=xr(),r=t||n,i=wt(r);return Ar(e,r,i)}function yM(e,t){let n=(0,Q.c)(14),r=rn(e,t),i=dr(e,t),a=vM(e,t),o=c(xM),s=!i||i.type===`idle`,l;n[0]===r?l=n[1]:(l=gM(r),n[0]=r,n[1]=l);let u=l,d=u&&a&&a.role===`assistant`&&a.id===u.forMessageID&&s?u:null,f=a?.timestamp??0,[,p]=Z.useReducer(bM,0),m=d?Date.now()-f>=_M:!1,h;n[2]!==d||n[3]!==p||n[4]!==f||n[5]!==m?(h=()=>{if(!d||m||!f)return;let e=_M-(Date.now()-f);if(e<=0)return;let t=setTimeout(p,e+250);return()=>clearTimeout(t)},n[2]=d,n[3]=p,n[4]=f,n[5]=m,n[6]=h):h=n[6];let g;n[7]!==d||n[8]!==f||n[9]!==m?(g=[d,m,f],n[7]=d,n[8]=f,n[9]=m,n[10]=g):g=n[10],Z.useEffect(h,g);let _=o&&d&&d.recap&&m?d.recap:null,v;return n[11]!==d||n[12]!==_?(v={assist:d,visibleRecap:_},n[11]=d,n[12]=_,n[13]=v):v=n[13],v}function bM(e){return e+1}function xM(e){return e.sessionRecapEnabled}var SM=Z.memo(e=>{let t=(0,Q.c)(13),{sessionId:n,directory:r,isMobile:i}=e,{visibleRecap:a}=yM(n,r),{t:o}=ot();if(!a)return null;let s;t[0]===o?s=t[1]:(s=o(`chat.recap.aria`),t[0]=o,t[1]=s);let c=`typography-markdown-body text-muted-foreground/70 ${i?`line-clamp-4`:`line-clamp-2`}`,l;t[2]===o?l=t[3]:(l=o(`chat.recap.label`),t[2]=o,t[3]=l);let u;t[4]===l?u=t[5]:(u=(0,$.jsxs)(`span`,{className:`italic text-muted-foreground/50`,children:[l,` `]}),t[4]=l,t[5]=u);let d;t[6]!==c||t[7]!==u||t[8]!==a?(d=(0,$.jsxs)(`span`,{className:c,children:[u,a]}),t[6]=c,t[7]=u,t[8]=a,t[9]=d):d=t[9];let f;return t[10]!==s||t[11]!==d?(f=(0,$.jsx)(`div`,{className:`chat-message-column`,children:(0,$.jsx)(`div`,{className:`-mt-6`,"aria-label":s,children:d})}),t[10]=s,t[11]=d,t[12]=f):f=t[12],f});SM.displayName=`SessionRecapNote`;var CM=Z.memo(e=>{let t=(0,Q.c)(11),{visible:n,onClick:r}=e,{t:i}=ot(),a=n?`opacity-100 translate-y-0 scale-100 pointer-events-auto`:`opacity-0 translate-y-2 scale-95 pointer-events-none`,o;t[0]===a?o=t[1]:(o=Y(`absolute bottom-full left-1/2 -translate-x-1/2 mb-2 transition-all duration-150`,a),t[0]=a,t[1]=o);let s;t[2]===i?s=t[3]:(s=i(`chat.scrollToBottom.aria`),t[2]=i,t[3]=s);let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(X,{name:`arrow-down`,className:`h-4 w-4`}),t[4]=c):c=t[4];let l;t[5]!==r||t[6]!==s?(l=(0,$.jsx)(da,{variant:`outline`,size:`sm`,onClick:r,className:`size-8 rounded-full [corner-shape:round] p-0 shadow-none bg-background/95 hover:bg-interactive-hover`,"aria-label":s,children:c}),t[5]=r,t[6]=s,t[7]=l):l=t[7];let u;return t[8]!==o||t[9]!==l?(u=(0,$.jsx)(`div`,{className:o,children:l}),t[8]=o,t[9]=l,t[10]=u):u=t[10],u});function wM(e){return e.filter(e=>e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(`
|