@openchambery/web 1.19.0-beta.30 → 1.19.0-beta.32
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-C6j1IdWs.js → AssistantView-DT9jviTH.js} +1 -1
- package/dist/assets/{ChatContainer-DMlBQLDP.js → ChatContainer-zQQKWQT_.js} +7 -7
- package/dist/assets/{ContextPanel-BRPUhK2H.js → ContextPanel-DQdZTb-V.js} +3 -3
- package/dist/assets/{DiagramView-CNivb4tq.js → DiagramView-et44X8Ex.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-DqAZhxRt.js → MarkdownRendererImpl-BKyOH-vB.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-DGzHNs84.js → MobileDetailNavigation-BMLT6Hs1.js} +1 -1
- package/dist/assets/{MobileShareBridge-CR2-gGoH.js → MobileShareBridge-VbKAaDJd.js} +1 -1
- package/dist/assets/{MobileSurface-DLNG62sp.js → MobileSurface-xspYQedr.js} +1 -1
- package/dist/assets/{MultiRunWindow-BSUo9V1B.js → MultiRunWindow-MRcAnDuR.js} +1 -1
- package/dist/assets/{SettingsView-DoZCcLtJ.js → SettingsView-DamINmSZ.js} +1 -1
- package/dist/assets/{SettingsWindow-Bveq9CYy.js → SettingsWindow-D2wTtIvr.js} +1 -1
- package/dist/assets/{TerminalView-C3U70VqY.js → TerminalView-BWNuTeSo.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BvkZesJU.js → ToolOutputDialog-4-hGl1I6.js} +1 -1
- package/dist/assets/appThemeRegistry-BxZGWyHG.js +2 -0
- package/dist/assets/{gitApi-DIkcL_Nf.js → gitApi-B81GgsWU.js} +1 -1
- package/dist/assets/{insertionBoundaries-DovsbXNF.js → insertionBoundaries-BQhLuPL0.js} +1 -1
- package/dist/assets/{main-DIK46kWN.js → main-CyReKMti.js} +2 -2
- package/dist/assets/{main-Dn0ZO3xc.js → main-innJABZ9.js} +3 -3
- package/dist/assets/{miniChat-BkSUOP7y.js → miniChat-uiJrHz_r.js} +2 -2
- package/dist/assets/{mobile-BzYQUgMF.js → mobile-Bc5Jf4qk.js} +2 -2
- package/dist/assets/{multirun-D829SjIb.js → multirun-0FoW4ydx.js} +1 -1
- package/dist/assets/{projectMeta-DUekBttY.js → projectMeta-C6CXnKkb.js} +1 -1
- package/dist/assets/{radio-DCljqJHm.js → radio-BkN54ReP.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-BU47xLBi.js → renderElectronMiniChatApp-D57uwlb7.js} +2 -2
- package/dist/assets/{renderMobileApp-CWDz7K3b.js → renderMobileApp-CKEgVJ13.js} +4 -4
- package/dist/assets/{runtimeConfig-7mBQeCB4.js → runtimeConfig-BBAcFSOK.js} +1 -1
- package/dist/assets/{runtimeEndpointReset-BK973evb.js → runtimeEndpointReset-zS8LcztG.js} +1 -1
- package/dist/assets/{shikiHighlight-BQL1ix3m.js → shikiHighlight-BtmT0Q4w.js} +1 -1
- package/dist/assets/{useAppFontEffects-CzWKDHkL.js → useAppFontEffects-Dm6AyC8i.js} +2 -2
- package/dist/assets/{useDesktopWindowControlsLayout-C89-MzoQ.js → useDesktopWindowControlsLayout-YqZuXFJ6.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-BFfcqq6b.js → useEffectiveDirectory-n3phoQvw.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-BnaXhlF_.js → useMobileNavigationStore-BhzZPyek.js} +1 -1
- package/dist/assets/{useSessionAutoCleanup-1xqh7PsY.js → useSessionAutoCleanup-D3VApHzF.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-DoRVHCsK.js → useWorkerHighlightedLines-TzNgQMkz.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/mini-chat.html +2 -2
- package/dist/mobile.html +2 -2
- package/package.json +1 -1
- package/dist/assets/appThemeRegistry-DChXj7w9.js +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-
|
|
2
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,E as n,P as r,T as i,U as a,g as o,t as s,w as c,y as l}from"./useUIStore-Wyu09VUF.js";import{$ as u,$t as d,B as f,C as p,Ct as m,Dt as h,G as g,I as _,J as v,K as y,M as b,N as x,Q as S,R as C,S as w,T,U as E,V as D,W as O,Wt as k,Y as A,Z as j,_ as M,at as N,b as P,ct as F,d as I,et as L,ft as R,it as z,j as B,kn as V,lt as H,mt as U,nt as W,ot as ee,pt as G,q as K,r as q,st as te,u as ne,ut as re,v as ie,wt as ae,x as oe,y as se,yt as ce,z as le}from"./persistence-aCOlo6ew.js";import{a as ue,i as de,r as fe,t as pe}from"./vendor-zustand-B4dlGEM2.js";import{c as me,d as he,f as ge,l as _e,nt as ve,rt as ye,tt as be,u as xe}from"./vendor-base-ui-CnHfUmDN.js";import{At as Se,Bt as Ce,Ct as we,Gt as Te,Ht as Ee,Jt as De,Kt as Oe,Nt as ke,Pt as Ae,Rt as je,St as Me,Ut as Ne,Wt as Pe,Yt as Fe,jt as Ie,kt as Le,n as Re,t as ze,zt as Be}from"./platform-ulFAVx1H.js";import{a as Ve,n as He,o as Ue}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as We}from"./vendor-react-DLPElpoQ.js";import{i as Ge,n as Ke,s as qe,t as Je}from"./vendor-tanstack-react-query-D7pys_c9.js";import{B as Ye,R as Xe,V as Ze,c as Qe}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{a as $e,d as et,i as tt,l as nt,n as J,o as rt,r as it,u as at}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ot,r as st,t as ct}from"./clipboard-C7zcAKyC.js";import{i as lt,t as ut}from"./store-upwbPNfx.js";import{$ as dt,$a as ft,$t as pt,A as mt,Ai as ht,Ar as gt,At as _t,Bi as vt,Bn as yt,Br as bt,Ca as xt,Ci as St,Cn as Ct,Ct as wt,D as Tt,Da as Et,Di as Dt,Dn as Ot,Do as kt,E as At,Ea as jt,Ei as Mt,En as Nt,Eo as Pt,F as Ft,Fa as It,Fr as Lt,G as Rt,Gi as zt,Gr as Bt,Gt as Vt,H as Ht,Ha as Ut,Hi as Wt,Hr as Gt,I as Kt,Ia as qt,Ii as Jt,Io as Yt,Ir as Xt,It as Zt,J as Qt,Ja as $t,Ji as en,Jr as tn,K as nn,Ka as rn,Ki as an,Kn as on,Kr as sn,Kt as cn,Li as ln,Lt as un,M as dn,Mi as fn,Mt as pn,N as mn,Ni as hn,Nt as gn,O as _n,Oi as vn,On as yn,Or as bn,Ot as xn,P as Sn,Pa as Cn,Pr as wn,Q as Tn,Qa as En,Qt as Dn,R as On,Ra as kn,Ri as An,Rr as jn,Rt as Mn,S as Nn,Sa as Pn,Sn as Fn,Sr as In,T as Ln,Ta as Rn,Ti as zn,Tn as Bn,Ui as Vn,Ur as Hn,Ut as Un,Vi as Wn,Vn as Gn,W as Kn,Wi as qn,Wr as Jn,Wt as Yn,X as Xn,Xa as Zn,Xi as Qn,Xt as $n,Y as er,Ya as tr,Yi as nr,Yr as rr,Z as ir,Za as ar,Zr as or,Zt as sr,_i as cr,_n as lr,_t as ur,a as dr,aa as fr,ai as pr,an as mr,ar as hr,at as gr,ba as _r,bi as vr,bt as yr,ca as br,ci as xr,cn as Sr,dn as Cr,dt as wr,ea as Tr,eo as Er,et as Dr,f as Or,fa as kr,fi as Ar,fn as jr,g as Mr,ga as Nr,gn as Pr,gt as Fr,hi as Ir,hn as Lr,ht as Rr,i as zr,ia as Br,ii as Vr,in as Hr,ir as Ur,it as Wr,j as Gr,ja as Kr,ji as qr,jr as Jr,jt as Yr,k as Xr,ka as Zr,ki as Qr,kn as $r,kr as ei,kt as ti,l as ni,la as ri,li as ii,ln as ai,m as oi,mi as si,mn as ci,mt as li,n as ui,ni as di,nn as fi,nt as pi,oi as mi,oo as hi,or as gi,pi as _i,pn as vi,pt as yi,q as bi,qa as xi,qi as Si,qt as Ci,ri as wi,rn as Ti,rt as Ei,sa as Di,sn as Oi,so as ki,sr as Ai,tn as ji,to as Mi,tt as Ni,un as Pi,uo as Fi,va as Ii,vi as Li,vt as Ri,w as zi,wi as Bi,wt as Vi,x as Hi,xa as Ui,xi as Wi,ya as Gi,yi as Ki,yr as qi,z as Ji,zi as Yi,zn as Xi,zo as Zi}from"./useMobileNavigationStore-BnaXhlF_.js";import{a as Qi,i as $i,l as ea,n as ta,o as na,r as ra,s as ia,t as aa}from"./dialog-BUQDNX62.js";import{n as oa,t as Y}from"./utils-CJdWZupK.js";import{t as sa}from"./AgentAvatar-Dn37YqCC.js";import{n as X}from"./Icon-Bs6GJIoO.js";import{t as ca}from"./button-DfF088a8.js";import{E as la,n as ua}from"./gitApi-DIkcL_Nf.js";import{A as da,C as fa,M as pa,N as ma,O as ha,P as ga,S as _a,T as va,a as ya,b as ba,d as xa,g as Sa,h as Ca,i as wa,j as Ta,k as Ea,n as Da,o as Oa,p as ka,s as Aa,u as ja,v as Ma,w as Na,x as Pa}from"./projectMeta-DUekBttY.js";import{t as Fa}from"./input-Ca2tUhgN.js";import{i as Ia,n as La,t as Ra}from"./tooltip-GC3dg3gO.js";import{n as za,t as Ba}from"./useThemeSystem-DMzWVJaW.js";import{B as Va,C as Ha,D as Ua,H as Wa,N as Ga,O as Ka,P as qa,S as Ja,W as Ya,X as Xa,Z as Za,_ as Qa,a as $a,f as eo,g as to,h as no,i as ro,it as io,k as ao,m as oo,o as so,p as co,r as lo,t as uo}from"./radio-DCljqJHm.js";import{i as fo,t as po}from"./OverlayScrollbar-VZKKu-cu.js";import{_ as mo,a as ho,d as go,f as _o,g as vo,h as yo,i as bo,l as xo,m as So,n as Co,u as wo,v as To,x as Eo}from"./markdownTheme-DidS-jC5.js";import{n as Do,r as Oo,t as ko}from"./useRuntimeAPIs-DSLXJybW.js";import{A as Ao,B as jo,C as Mo,D as No,E as Po,F as Fo,H as Io,I as Lo,L as Ro,M as zo,O as Bo,P as Vo,R as Ho,S as Uo,T as Wo,V as Go,a as Ko,b as qo,c as Jo,f as Yo,i as Xo,j as Zo,k as Qo,l as $o,m as es,n as ts,o as ns,p as rs,r as is,s as as,t as os,u as ss,w as cs,x as ls,z as us}from"./insertionBoundaries-DovsbXNF.js";import{A as ds,C as fs,D as ps,E as ms,M as hs,N as gs,O as _s,S as vs,T as ys,_ as bs,a as xs,b as Ss,c as Cs,d as ws,f as Ts,g as Es,h as Ds,i as Os,j as ks,k as As,m as js,p as Ms,r as Ns,t as Ps,u as Fs,v as Is,w as Ls,x as Rs,y as zs}from"./appThemeRegistry-DChXj7w9.js";import{_ as Bs,a as Vs,c as Hs,g as Us,l as Ws,o as Gs,t as Ks,v as qs,y as Js}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{i as Ys,n as Xs,o as Zs,s as Qs,t as $s}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as ec,n as tc,t as nc}from"./url-BQHM4bC4.js";import{_ as rc,l as ic,m as ac,p as oc,s as sc}from"./markdown-worker-9Sn2jsDp.js";import{n as cc}from"./useEffectiveDirectory-BFfcqq6b.js";import{a as lc,c as uc,d as dc,f as fc,i as pc,l as mc,n as hc,r as gc,s as _c,t as vc}from"./FadeInOnReveal-BpIMrqet.js";import{A as yc,C as bc,D as xc,E as Sc,M as Cc,O as wc,S as Tc,T as Ec,a as Dc,b as Oc,c as kc,g as Ac,h as jc,i as Mc,j as Nc,k as Pc,o as Fc,p as Ic,r as Lc,s as Rc,t as zc,v as Bc,w as Vc,x as Hc,y as Uc}from"./useWorkerHighlightedLines-DoRVHCsK.js";import{t as Wc}from"./vendor-cmdk-CeAGfrLo.js";import{t as Gc}from"./sortable-tabs-strip-COl2MAH7.js";import{n as Kc,t as qc}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{i as Jc,u as Yc}from"./vendor-pierre-diffs-BenIz2TM.js";import{i as Xc,t as Zc}from"./vendor-framer-motion-DFy_BSVd.js";import{t as Qc}from"./vendor-legendapp-list-WE32lwNk.js";var Z=e(ye(),1),Q=We(),$=ve(),$c=e(be(),1),el=`openchamber:close-embedded-session-chat`,tl=`openchamber:embedded-visibility`,nl=`openchamber:embedded-visibility-request`,rl=e=>new URLSearchParams(e).get(`ocPanel`)===`session-chat`,il=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),al=(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()},ol=(e,t,n,r,i,a)=>{let o=il(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=al(n,r,i,a);return e.set(t,{signature:o,src:c}),c},sl=null,cl=()=>{if(sl!==null)return sl;if(typeof window>`u`)return sl=!1,!1;try{return sl=new URLSearchParams(window.location.search).get(`ocPanel`)===`session-chat`,sl}catch{return sl=!1,!1}},ll=()=>{if(!cl())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},ul=Ve(`OpenChamberMedia`);function dl(){return Re()&&He.getPlatform()===`android`&&He.isPluginAvailable(`OpenChamberMedia`)}async function fl(e){if(!dl())return null;let t=await ul.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 pl=(e,t)=>{let n=t.trim();if(!n.length)return[...e].sort((e,t)=>e.scope===`project`&&t.scope!==`project`?-1:e.scope!==`project`&&t.scope===`project`?1:e.name.localeCompare(t.name));let r=yi([...e],n,e=>[e.name,e.description??``]);return r.sort((e,t)=>e.score===t.score?e.item.scope===`project`&&t.item.scope!==`project`?-1:e.item.scope!==`project`&&t.item.scope===`project`?1:e.item.name.localeCompare(t.item.name):e.score-t.score),r.map(e=>e.item)},ml=new Map,hl=(e,t,n)=>`${+!!t}:${n}:${e.map(e=>`${e.id}\0${e.title}\0${e.subtitle??``}\0${e.badge??``}\0${e.iconName}`).join(`|`)}`,gl=async e=>{let t=ks(`--surface-foreground`);return Promise.all(e.slice(0,40).map(async e=>{let n=`${e.iconName}:${t}`,r=ml.get(n);return r===void 0&&(r=await Io(e.iconName,t)??``,ml.set(n,r)),{id:e.id,title:e.title,subtitle:e.subtitle??``,badge:e.badge??``,iconBase64:r}}))},_l=[],vl=e=>void 0,yl=()=>void 0;function bl(e){let t=e.enabled&&Is(e.isMobile),n=(0,Z.useRef)(null),r=(0,Z.useRef)(e.text),i=(0,Z.useRef)(!1),a=(0,Z.useRef)(``),o=(0,Z.useRef)([]),s=(0,Z.useRef)(zs()),c=J(e.onText),l=J(e.onSend),u=J(e.onAbort),d=J(e.onAttach),f=J(e.onFiles),p=J(e.onRemoveAttachment),m=J(e.onOpenModel),h=J(e.onCycleAgent),g=J(e.onOpenAgent),_=J(e.onScrollToBottom),v=J(e.onAutocompleteAccept??vl),y=J(e.onAutocompleteDismiss??yl),b=J(e=>{typeof document>`u`||js(document.documentElement,e)});Ts.bind({onText:(e,t,n)=>{r.current=e,i.current=!0,c(e,t,n)},onSend:e=>{r.current=e,l(e)},onAbort:u,onAttach:d,onFiles:f,onRemoveAttachment:p,onOpenModel:m,onCycleAgent:h,onOpenAgent:g,onHeight:b,onScrollToBottom:_,onAutocompleteAccept:e=>{i.current=!1,v(e)},onAutocompleteDismiss:y});let x=()=>({text:e.text,placeholder:e.placeholder,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel,modelIcon:a.current,canSend:e.canSend,canAbort:e.canAbort,attachmentCount:e.attachmentCount,attachmentPreviews:o.current,citationRanges:De(e.text,e.attachments.map(e=>e.filename)),chipRanges:Es(fs(e.text,e.chipHighlights),ks(`--primary`)),appearance:typeof document>`u`?`dark`:ms(document.documentElement),attachAria:e.attachAria,attachTitle:e.attachTitle,attachPhotosLabel:e.attachPhotosLabel,attachFilesLabel:e.attachFilesLabel,attachCancelLabel:e.attachCancelLabel,sendAria:e.sendAria,queueAria:e.queueAria,stopAria:e.stopAria,modelAria:e.modelAria,agentAria:e.agentAria,agentLabel:e.agentLabel,agentColor:ys(e.agentName||void 0),agentIdenticon:ps(e.agentName||void 0),suppressed:e.suppressed,showScrollToBottom:e.showScrollToBottom,scrollAria:e.scrollAria,autocomplete:s.current});(0,Z.useLayoutEffect)(()=>{if(!t||typeof document>`u`)return;let e=document.documentElement;return gs(e,!0),()=>{gs(e,!1)}},[t]),(0,Z.useEffect)(()=>{if(!t||typeof document>`u`)return;let e=document.documentElement,i=x();n.current=i,r.current=i.text,Ts.rememberText(i.text),Ts.retain(e,i);let a=ws();return()=>{n.current=null,a(),Ts.release(e)}},[t]),(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=ma(e.modelId,e.providerId),o={modelIcon:``,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};if(a.current=``,n.current&&={...n.current,...o},Ss().update(o),i)return As(i).then(t=>{if(r)return;let i=t??``;a.current=i;let o={modelIcon:i,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};n.current&&={...n.current,...o},Ss().update(o)}),()=>{r=!0}},[t,e.modelId,e.providerId,e.modelLabel,e.modelVariantLabel]);let S=Ds(e.attachments);(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=e.attachments;if(i.length===0){o.current=[],n.current&&(n.current={...n.current,attachmentPreviews:[]},Ts.rememberState(n.current)),Ss().update({attachmentPreviews:[]});return}return Promise.all(i.map(async t=>{let n=t.mimeType.startsWith(`image/`)&&t.dataUrl?await _s(t.dataUrl):``;return{id:t.id,filename:t.filename,mime:t.mimeType,thumbnailBase64:n??``,removeAria:e.removeAttachmentNamedAria(t.filename)}})).then(e=>{r||(o.current=e,n.current&&(n.current={...n.current,attachmentPreviews:e},Ts.rememberState(n.current)),Ss().update({attachmentPreviews:e}))}),()=>{r=!0}},[t,S]);let C=e.autocompleteRows??_l,w=e.autocompleteOpen===!0,T=e.autocompleteHighlightedIndex??0,E=hl(C,w,T);(0,Z.useEffect)(()=>{if(!t)return;let e=!1;if(!(w&&C.length>0)){let e=zs();vs(s.current,e)||(s.current=e,n.current&&(n.current={...n.current,autocomplete:e},Ts.rememberState(n.current)),Ss().update({autocomplete:e}));return}return gl(C).then(t=>{if(e)return;let r={open:t.length>0,highlightedIndex:Math.max(0,Math.min(T,Math.max(t.length-1,0))),rows:t};vs(s.current,r)||(s.current=r,n.current&&(n.current={...n.current,autocomplete:r},Ts.rememberState(n.current)),Ss().update({autocomplete:r}))}),()=>{e=!0}},[t,E]);let D=t?fs(e.text,e.chipHighlights).map(e=>`${e.start}:${e.end}:${e.triggerLength}`).join(`|`):``;return(0,Z.useEffect)(()=>{if(!t)return;let a=x(),o=n.current;if(o&&Ls(o,a)){i.current=!1;return}n.current=a,Ts.rememberState(a);let s=hs({nextText:a.text,nativeOwnedText:r.current,echoingNative:i.current});i.current=!1,r.current=a.text;let c=bs(o,a,s,{caret:e.caret});c&&Ss().update(c)},[t,e.text,e.placeholder,e.modelLabel,e.modelVariantLabel,e.modelId,e.providerId,e.canSend,e.canAbort,e.attachmentCount,S,e.suppressed,e.attachAria,e.attachTitle,e.attachPhotosLabel,e.attachFilesLabel,e.attachCancelLabel,e.sendAria,e.queueAria,e.stopAria,e.modelAria,e.agentName,e.agentLabel,e.agentAria,e.showScrollToBottom,e.scrollAria,D]),t}var xl=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},Sl=1e4,Cl=15e3,wl=3e4,Tl=3e4,El=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`))}},Sl);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`))},Cl);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`))},Tl),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=xl(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)}}},wl))}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`,()=>{El.cancelAllForRuntimeSwitch()});var Dl=128,Ol=`audio/pcm;rate=16000;bits=16`,kl=()=>new Promise(e=>setTimeout(e,0)),Al=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},jl=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??Ol,this.getStartOptions=e.getStartOptions,this.createDictationId=e.createDictationId??Al}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<Dl;){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 kl()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},Ml=16e3,Nl=Ml,Pl=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},Fl=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},Il=(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]=Fl(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]=Fl(e[i]*(1-s)+e[o]*s)}return a},Ll=(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},Rl=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)},zl=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),Bl=e=>{if(e)try{e.disconnect()}catch{}},Vl=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Pl()!==null;function Hl(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=zl(),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=Pl();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(Gl);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=Il(a,n.sampleRate,Ml);for(t.pending=Ll(t.pending,c);t.pending.length>=Nl;){let e=t.pending.slice(0,Nl);t.pending=t.pending.slice(Nl),i.current(Rl(e))}},e.connect(a),a.connect(o),o.connect(n.destination)}catch(e){let r=e;t.getTracks().forEach(Wl);try{await n.close()}catch{}throw l.current=zl(),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{}Bl(e.processor),Bl(e.source),Bl(e.gain),e.stream&&e.stream.getTracks().forEach(Ul);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current(Rl(t)),e.context)try{await e.context.close()}catch{}l.current===e&&(l.current=zl())},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 Ul(e){try{e.stop()}catch{}}function Wl(e){try{e.stop()}catch{}}function Gl(){}var Kl=1e3,ql=e=>e instanceof Error?e:Error(String(e)),Jl=()=>{let e=br.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 Yl(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 jl({client:El,getStartOptions:Jl});let x=(0,Z.useCallback)(()=>{g.current&&=(clearInterval(g.current),null)},[]),S=(0,Z.useCallback)(()=>{g.current||=setInterval(()=>{l(e=>e+1)},Kl)},[]),C=(0,Z.useCallback)(e=>{let t=ql(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)(()=>El.onPartial((e,t)=>{let n=b.current?.getDictationId();!n||e!==n||(h.current=t,s(t))}),[]),(0,Z.useEffect)(()=>El.subscribeConnectionStatus(e=>{e&&m.current===`recording`&&b.current?.restartStream().catch(e=>{C(e)})}),[C]);let E=Hl({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 Xl=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},Zl=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=za(),i=Math.min(1,Math.max(0,n)),a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=[.45,.7,1,.7,.45],t[0]=a):a=t[0];let o=a,s;return t[1]!==r||t[2]!==i?(s=(0,$.jsx)(`div`,{className:`flex h-6 w-10 flex-shrink-0 items-center justify-center gap-1`,"aria-hidden":`true`,children:o.map((e,t)=>(0,$.jsx)(`span`,{className:`h-full w-1 rounded-full transition-transform duration-75 ease-out motion-reduce:transition-none`,style:{backgroundColor:r.colors.primary.base,transform:`scaleY(${.25+i*e*.75})`}},t))}),t[1]=r,t[2]=i,t[3]=s):s=t[3],s},Ql=e=>{let t=br(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},$l=e=>{let t=(0,Q.c)(86),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:c,disabled:l,onInsert:u,onInsertAndSend:d,onActiveChange:f,onContentHeightChange:p,renderTrigger:m,topAccessory:h}=e,g=m===void 0||m,{t:_}=ot(),{currentTheme:v}=za(),y=br(eu),b=s(tu),x;t[0]===b?x=t[1]:(x=Wa(Ya(`toggle_dictation`,b)),t[0]=b,t[1]=x);let S=x,[C]=Z.useState(nu),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}=Yl(k),H=A===`recording`&&F===`model_download_in_progress`,U=Ql(H),W=Z.useRef(A),ee,G;t[7]===A?(ee=t[8],G=t[9]):(ee=()=>{W.current=A},G=[A],t[7]=A,t[8]=ee,t[9]=G),Z.useEffect(ee,G);let K,q;t[10]!==f||t[11]!==A?(K=()=>{f?.(A!==`idle`)},q=[A,f],t[10]=f,t[11]=A,t[12]=K,t[13]=q):(K=t[12],q=t[13]),Z.useLayoutEffect(K,q);let te,ne;t[14]!==L||t[15]!==I?(te=()=>{let e=()=>{W.current===`idle`?I():W.current===`recording`&&(w.current=`insert`,L())};return window.addEventListener(`openchamber:dictation-toggle`,e),()=>window.removeEventListener(`openchamber:dictation-toggle`,e)},ne=[I,L],t[14]=L,t[15]=I,t[16]=te,t[17]=ne):(te=t[16],ne=t[17]),Z.useEffect(te,ne);let re,ie;t[18]!==R||t[19]!==L||t[20]!==A?(re=()=>{if(A!==`recording`)return;let e=e=>{if(!e.isComposing){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault(),e.stopPropagation(),w.current=`insert`,L();return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),R())}};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},ie=[A,L,R],t[18]=R,t[19]=L,t[20]=A,t[21]=re,t[22]=ie):(re=t[21],ie=t[22]),Z.useEffect(re,ie);let ae=Z.useRef(null),oe=Z.useRef(null),se=Z.useRef(null),[ce,le]=Z.useState(null),ue=A!==`idle`,de=Z.useRef(p),fe,pe;t[23]===p?(fe=t[24],pe=t[25]):(fe=()=>{de.current=p},pe=[p],t[23]=p,t[24]=fe,t[25]=pe),Z.useEffect(fe,pe);let me=Z.useRef(!1),he;t[26]===ue?he=t[27]:(he=()=>{if(!ue){me.current&&(me.current=!1,de.current?.(null));return}let e=oe.current,t=se.current;if(!e||!t)return;let n=window.getComputedStyle(e),r=(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0);me.current=!0,de.current?.(t.offsetHeight+r),e.scrollTop=e.scrollHeight},t[26]=ue,t[27]=he);let ge;t[28]!==P||t[29]!==ue||t[30]!==j||t[31]!==A?(ge=[ue,j,A,P],t[28]=P,t[29]=ue,t[30]=j,t[31]=A,t[32]=ge):ge=t[32],Z.useLayoutEffect(he,ge);let _e,ve;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(_e=()=>()=>{me.current&&(me.current=!1,de.current?.(null))},ve=[],t[33]=_e,t[34]=ve):(_e=t[33],ve=t[34]),Z.useEffect(_e,ve);let ye,be;if(t[35]===ue?(ye=t[36],be=t[37]):(ye=()=>{if(!ue)return;let e=ae.current?.closest(`[data-chat-input-footer="true"]`);e&&e.offsetHeight>0&&le(e.offsetHeight)},be=[ue],t[35]=ue,t[36]=ye,t[37]=be),Z.useLayoutEffect(ye,be),!C||!y)return null;let xe=A!==`idle`,Se;t[38]===L?Se=t[39]:(Se=e=>{w.current=e,L()},t[38]=L,t[39]=Se);let Ce=Se,we;t[40]===z?we=t[41]:(we=()=>{w.current=`insert`,z()},t[40]=z,t[41]=we);let Te=we,Ee;bb0:{if(A===`failed`){Ee=``;break bb0}if(A===`uploading`){let e;t[42]===_?e=t[43]:(e=_(`chat.dictation.processing`),t[42]=_,t[43]=e),Ee=e;break bb0}if(H){let e;t[44]!==U||t[45]!==_?(e=U===null?_(`chat.dictation.downloadingModel`):_(`chat.dictation.downloadingModelProgress`,{percent:String(U)}),t[44]=U,t[45]=_,t[46]=e):e=t[46],Ee=e;break bb0}let e;t[47]===_?e=t[48]:(e=_(`chat.dictation.listening`),t[47]=_,t[48]=e),Ee=e}let De=Ee,Oe;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(Oe={onMouseDown:ru,onPointerDownCapture:iu},t[49]=Oe):Oe=t[49];let ke=Oe,Ae;t[50]!==S||t[51]!==l||t[52]!==i||t[53]!==o||t[54]!==xe||t[55]!==g||t[56]!==I||t[57]!==_?(Ae=g?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{I()},disabled:l||xe,title:S?`${_(`chat.dictation.start`)} (${S})`:_(`chat.dictation.start`),"aria-label":_(`chat.dictation.start`),children:(0,$.jsx)(X,{name:`mic`,className:Y(o,`text-current`)})}):null,t[50]=S,t[51]=l,t[52]=i,t[53]=o,t[54]=xe,t[55]=g,t[56]=I,t[57]=_,t[58]=Ae):Ae=t[58];let je;t[59]!==B||t[60]!==R||t[61]!==Ce||t[62]!==v||t[63]!==V||t[64]!==N||t[65]!==P||t[66]!==ce||t[67]!==i||t[68]!==a||t[69]!==o||t[70]!==xe||t[71]!==r||t[72]!==H||t[73]!==j||t[74]!==De||t[75]!==n||t[76]!==Te||t[77]!==c||t[78]!==A||t[79]!==_||t[80]!==h||t[81]!==M?(je=xe?(0,$.jsxs)(`div`,{ref:ae,className:Y(`absolute inset-0 z-50 flex flex-col overflow-x-hidden overflow-y-hidden`,r&&`oc-composer-morph-content-fade`),style:{borderRadius:n,backgroundColor:v.colors.surface.subtle},role:`dialog`,"aria-label":_(`chat.dictation.overlayAria`),children:[h,(0,$.jsx)(`div`,{ref:oe,className:Y(`scrollbar-none flex-1 min-h-0 overflow-y-auto px-3`,r?`pt-3.5 pb-2.5`:`pt-5 pb-2`),children:(0,$.jsxs)(`div`,{ref:se,className:Y(!j&&`translate-y-1.5`),children:[j?(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label whitespace-pre-wrap`,style:{color:v.colors.surface.foreground},children:j}):A===`recording`?(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,style:{color:v.colors.surface.mutedForeground},children:[(0,$.jsx)(Zl,{volume:M}),(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,children:De})]}):(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,style:{color:v.colors.surface.mutedForeground},children:De}),A===`failed`?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.error},children:P||_(`chat.dictation.failed`)}):null,A===`recording`&&P&&!H?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.warning},children:P}):null]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center gap-x-3`,a),style:ce?{height:ce}:void 0,children:[A===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`relative ml-1 flex h-2 w-2 flex-shrink-0`,"aria-hidden":`true`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full opacity-60`,style:{backgroundColor:v.colors.status.error}}),(0,$.jsx)(`span`,{className:`relative inline-flex h-2 w-2 rounded-full`,style:{backgroundColor:v.colors.status.error}})]}),(0,$.jsx)(Zl,{volume:M}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:v.colors.surface.mutedForeground},children:Xl(N)})]}):A===`uploading`?(0,$.jsx)(X,{name:`loader-4`,className:`ml-1 h-4 w-4 animate-spin`,style:{color:v.colors.surface.mutedForeground}}):null,(0,$.jsx)(`div`,{className:Y(`ml-auto flex items-center`,r?`gap-x-1`:`gap-x-1.5 md:gap-x-3`),children:A===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>Ce(`insert`),title:_(`chat.dictation.insert`),"aria-label":_(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-primary hover:text-primary`),onClick:()=>Ce(`send`),title:_(`chat.dictation.insertAndSend`),"aria-label":_(`chat.dictation.insertAndSend`),children:(0,$.jsx)(X,{name:`send-plane-2`,className:c})})]}):A===`uploading`?(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:V,title:_(`chat.dictation.discard`),"aria-label":_(`chat.dictation.discard`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:Te,title:_(`chat.dictation.retry`),"aria-label":_(`chat.dictation.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:o})}),j.trim()?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{w.current=`insert`,B()},title:_(`chat.dictation.insert`),"aria-label":_(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}):null]})})]})]}):null,t[59]=B,t[60]=R,t[61]=Ce,t[62]=v,t[63]=V,t[64]=N,t[65]=P,t[66]=ce,t[67]=i,t[68]=a,t[69]=o,t[70]=xe,t[71]=r,t[72]=H,t[73]=j,t[74]=De,t[75]=n,t[76]=Te,t[77]=c,t[78]=A,t[79]=_,t[80]=h,t[81]=M,t[82]=je):je=t[82];let Me;return t[83]!==Ae||t[84]!==je?(Me=(0,$.jsxs)($.Fragment,{children:[Ae,je]}),t[83]=Ae,t[84]=je,t[85]=Me):Me=t[85],Me};function eu(e){return e.dictationEnabled}function tu(e){return e.shortcutOverrides}function nu(){return!d()&&Vl()}function ru(e){return e.preventDefault()}function iu(e){e.pointerType===`touch`&&e.preventDefault()}var au=2e3,ou=ue((e,t)=>({pending:!1,expiresAt:null,arm:(t=au)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),su=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}},cu=15e3,lu=100,uu=new Map,du=new Map,fu=e=>`${e.runtimeKey}\n${e.directory}\n${e.sessionID}`,pu=e=>{let t=fu(e),n=e.now??Date.now(),r=du.get(t);if(r&&n-r.loadedAt<cu)return Promise.resolve(r.sessions);let i=uu.get(t);if(i)return i;let a=e.request().then(e=>{for(du.delete(t);du.size>=lu;){let e=du.keys().next().value;if(typeof e!=`string`)break;du.delete(e)}return du.set(t,{loadedAt:Date.now(),sessions:e}),e});return uu.set(t,a),a.then(()=>{uu.get(t)===a&&uu.delete(t)},()=>{uu.get(t)===a&&uu.delete(t)}),a},mu=(e,t)=>e.id<t.id?-1:+(e.id>t.id),hu=(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(mu)},gu=30;function _u(e){return e===`busy`||e===`retry`}var vu=new Map;function yu(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function bu(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 xu(e,t){if(!e.error)return;let n=e.response?.status;throw Error(`${t} failed${n?` (${n})`:``}: ${bu(e.error)}`)}function Su(e,t){let n=xt();if(!n)return!1;let r=n.getTranscript(Kr(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>An()}function Cu(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function wu(e,t,n){let r=[...e.getState().session],i=qt.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function Tu(){let e=Pr(),t=Vt(),n=Un(),r=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),a=(0,Z.useCallback)((t,n=e)=>{let r=xt();if(!r||!t)return yu({kind:`unknown`,loadedTurns:0},!1);let i=Kr(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return yu(a.boundary,o?.status===`loading`)},[e]),o=(0,Z.useCallback)((e,t)=>{if(t.length===0)return;let r=n.getChild(e);if(!r)return;let i=r.getState(),a={session_status:{...i.session_status},session_status_observed_at:{...i.session_status_observed_at},session_diff:{...i.session_diff},todo:{...i.todo},permission:{...i.permission},question:{...i.question}};Ot(a,t),Zt(r,t),r.setState(a);for(let n of t)jt(e,n)},[n]),s=(0,Z.useCallback)((t=e)=>{let n=vu.get(t);if(n)return vu.delete(t),vu.set(t,n),n;let r=new Set;for(vu.set(t,r);vu.size>gu;){let e=vu.keys().next().value;if(!e)break;let t=[...vu.get(e)??[]];vu.delete(e),o(e,t)}return r},[e,o]),c=(0,Z.useCallback)((r,i=e)=>{let a=i===e?t:n.ensureChild(i,{bootstrap:!1}),c=s(i),l=yn(a.getState()),u=Jt(),d=$r({seen:c,keep:r,limit:u,preserve:l});if(o(i,d),ln()){let e=new Set([r,...c,...l]),t=(xt()?.getCacheBudget?.().listCanonical({directory:i})??[]).map(e=>e.scope.sessionID),n=(t.length>0?t:Array.from(c)).filter(t=>t===r||e.has(t)?!1:Su(i,t));if(n.length>0){for(let e of n)c.delete(e);o(i,n)}}},[n,e,s,o,t]),l=(0,Z.useCallback)(async(r,i)=>{let a=i?.directory??e;if(!r||!a||a===`global`)return;let o=a===e?t:n.ensureChild(a,{bootstrap:!1}),s=o.getState(),c=s.session_status?.[r],l=s.session_status_observed_at?.[r];try{i?.purpose===`prepend`||i?.before?await Ui(a,r):await _r(a,r)}catch{return}if(i?.isStale?.())return;let u=xt()?.getTranscript(Kr(a,r));Vr({directory:a,sessionID:r,store:o,transcript:u,isStale:i?.isStale}),await ii({directory:a,sessionID:r,store:o,statusBeforePull:c,statusObservedAtBeforePull:l,hasMessages:(u?.messageOrder.length??0)>0,isTailPage:!i?.before,isStale:i?.isStale})},[n,t,e]),u=(0,Z.useCallback)(async(t,i)=>{await Zi();let a=typeof i==`boolean`?i:i?.force,o=typeof i==`object`?i.directory??e:e,s=n.ensureChild(o,{bootstrap:!1}),u=ke.getScopedSdkClient(o);c(t,o);let d=r(t,o);return su.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=xt(),i=Kr(o,t),c=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=qt.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&c&&d.kind!==`unknown`&&p?.status!==`error`&&f&&vt(o,t)){Vr({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!c||f),h=Cu({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await fr(async()=>{let e=await u.session.get({sessionID:t,directory:o});return xu(e,`session.get`),e});if(n.data&&!e()){let r=Br(n.data);e()||wu(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?l(t,{isStale:e,directory:o}):Promise.resolve()])}})},[n,r,c,l,e]),d=(0,Z.useCallback)(async(t,r)=>{let a=r||e;if(!t||!a)return;let o=n.ensureChild(a,{bootstrap:!1}),s=ke.getScopedSdkClient(a),c=await pu({runtimeKey:i(),directory:a,sessionID:t,request:async()=>{let e=await s.session.children({sessionID:t,directory:a});return xu(e,`session.children`),e.data??[]}});o.setState(e=>{let n=hu(e.session,c,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})},[n,e]),f=(0,Z.useCallback)((t,n)=>{let r=a(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,a]),p=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).loading,[e,a]),m=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).complete,[e,a]),h=(0,Z.useCallback)(t=>{let n=t.directory||e;Gi(Kr(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;Gi(Kr(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;Gi(Kr(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(async(t,r)=>{if(!t)return;await Zi();let i=r?.directory??e;if(!i||i===`global`)return;let a=n.ensureChild(i,{bootstrap:!1}),o=a.getState().session_status?.[t]?.type;if(_u(o))throw Error(`refresh transcript busy`);try{await Et(i,t),Vr({directory:i,sessionID:t,store:a})}catch(e){throw e instanceof Error&&e.message===`refresh transcript busy`?e:Error(`refresh transcript failed`)}},[n,e]);return(0,Z.useMemo)(()=>({ensureSessionRenderable:u,syncSession:u,loadChildren:d,hasMore:f,isLoading:p,isComplete:m,refreshSessionTranscript:v,optimistic:{add:h,remove:g,confirm:_}}),[u,d,f,p,m,v,h,g,_])}var Eu=e=>e===`diff`||e===`plan`||e===`file`||e===`preview-console`||e===`preview-annotation`,Du=e=>e===`original`||e===`modified`,Ou=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},ku=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!Eu(t.source))return null;let n=Ou(t.startLine),r=Ou(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:Du(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()}},Au=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(ku).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},ju=ue()(fe(de((e,t)=>({drafts:{},addDraft:t=>{let n=`icd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,r={...t,id:n,createdAt:Date.now()};return e(e=>{let n=e.drafts[t.sessionKey]??[];return{drafts:{...e.drafts,[t.sessionKey]:[...n,r]}}}),n},updateDraft:(t,n,r)=>{e(e=>{let i=(e.drafts[t]??[]).map(e=>e.id===n?{...e,...r}:e);return{drafts:{...e.drafts,[t]:i}}})},removeDraft:(t,n)=>{e(e=>{let r=(e.drafts[t]??[]).filter(e=>e.id!==n);if(r.length===0){let{[t]:n,...r}=e.drafts;return{drafts:r}}return{drafts:{...e.drafts,[t]:r}}})},clearDrafts:t=>{e(e=>{let{[t]:n,...r}=e.drafts;return{drafts:r}})},getDrafts:e=>t().drafts[e]??[],consumeDrafts:n=>{let r=t().drafts[n]??[];if(r.length===0)return[];let i=[...r].sort((e,t)=>e.createdAt-t.createdAt);return e(e=>{let{[n]:t,...r}=e.drafts;return{drafts:r}}),i},getDraftCount:e=>(t().drafts[e]??[]).length,hasDrafts:e=>(t().drafts[e]??[]).length>0}),{name:`openchamber-inline-comment-drafts`,storage:l(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:Au(e.drafts)}}),{name:`inline-comment-draft-store`}));function Mu(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 Nu(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(Mu).join(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-4-hGl1I6.js","assets/rolldown-runtime-C0FnF6B9.js","assets/useUIStore-Wyu09VUF.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-base-ui-CnHfUmDN.js","assets/persistence-aCOlo6ew.js","assets/vendor-pathe-vBmvQE8f.js","assets/vendor-react-DLPElpoQ.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/vendor-reactuses-core-DDoDDyM9.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/clipboard-C7zcAKyC.js","assets/store-upwbPNfx.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/dialog-BUQDNX62.js","assets/utils-CJdWZupK.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-Bs6GJIoO.js","assets/button-DfF088a8.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-DidS-jC5.js","assets/vendor-pierre-diffs-BenIz2TM.js","assets/vendor-hast-util-to-html-B0p1k5Xa.js","assets/vendor-character-entities-legacy-Wut6vMuj.js","assets/vendor-character-entities-html4-DlN_yAFd.js","assets/vendor-ccount-CyGsA0u7.js","assets/vendor-comma-separated-tokens-B9ouxNNS.js","assets/vendor-oniguruma-to-es-CrHzjjSU.js","assets/vendor-oniguruma-parser-D2DIvhSP.js","assets/vendor-diff-Dq7CZNim.js","assets/vendor-lru_map-DpDied8H.js","assets/appThemeRegistry-BxZGWyHG.js","assets/platform-ulFAVx1H.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/useMobileNavigationStore-BhzZPyek.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-DxZsjSPQ.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/markdown-worker-9Sn2jsDp.js","assets/useEffectiveDirectory-n3phoQvw.js","assets/useWorkerHighlightedLines-TzNgQMkz.js","assets/tooltip-GC3dg3gO.js","assets/vendor-tanstack-react-virtual-tlDgH6PG.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,E as n,P as r,T as i,U as a,g as o,t as s,w as c,y as l}from"./useUIStore-Wyu09VUF.js";import{$ as u,$t as d,B as f,C as p,Ct as m,Dt as h,G as g,I as _,J as v,K as y,M as b,N as x,Q as S,R as C,S as w,T,U as E,V as D,W as O,Wt as k,Y as A,Z as j,_ as M,at as N,b as P,ct as F,d as I,et as L,ft as R,it as z,j as B,kn as V,lt as H,mt as U,nt as W,ot as ee,pt as G,q as K,r as q,st as te,u as ne,ut as re,v as ie,wt as ae,x as oe,y as se,yt as ce,z as le}from"./persistence-aCOlo6ew.js";import{a as ue,i as de,r as fe,t as pe}from"./vendor-zustand-B4dlGEM2.js";import{c as me,d as he,f as ge,l as _e,nt as ve,rt as ye,tt as be,u as xe}from"./vendor-base-ui-CnHfUmDN.js";import{At as Se,Bt as Ce,Ct as we,Gt as Te,Ht as Ee,Jt as De,Kt as Oe,Nt as ke,Pt as Ae,Rt as je,St as Me,Ut as Ne,Wt as Pe,Yt as Fe,jt as Ie,kt as Le,n as Re,t as ze,zt as Be}from"./platform-ulFAVx1H.js";import{a as Ve,n as He,o as Ue}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as We}from"./vendor-react-DLPElpoQ.js";import{i as Ge,n as Ke,s as qe,t as Je}from"./vendor-tanstack-react-query-D7pys_c9.js";import{B as Ye,R as Xe,V as Ze,c as Qe}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{a as $e,d as et,i as tt,l as nt,n as J,o as rt,r as it,u as at}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ot,r as st,t as ct}from"./clipboard-C7zcAKyC.js";import{i as lt,t as ut}from"./store-upwbPNfx.js";import{$ as dt,$a as ft,$t as pt,A as mt,Ai as ht,Ar as gt,At as _t,Bi as vt,Bn as yt,Br as bt,Ca as xt,Ci as St,Cn as Ct,Ct as wt,D as Tt,Da as Et,Di as Dt,Dn as Ot,Do as kt,E as At,Ea as jt,Ei as Mt,En as Nt,Eo as Pt,F as Ft,Fa as It,Fr as Lt,G as Rt,Gi as zt,Gr as Bt,Gt as Vt,H as Ht,Ha as Ut,Hi as Wt,Hr as Gt,I as Kt,Ia as qt,Ii as Jt,Io as Yt,Ir as Xt,It as Zt,J as Qt,Ja as $t,Ji as en,Jr as tn,K as nn,Ka as rn,Ki as an,Kn as on,Kr as sn,Kt as cn,Li as ln,Lt as un,M as dn,Mi as fn,Mt as pn,N as mn,Ni as hn,Nt as gn,O as _n,Oi as vn,On as yn,Or as bn,Ot as xn,P as Sn,Pa as Cn,Pr as wn,Q as Tn,Qa as En,Qt as Dn,R as On,Ra as kn,Ri as An,Rr as jn,Rt as Mn,S as Nn,Sa as Pn,Sn as Fn,Sr as In,T as Ln,Ta as Rn,Ti as zn,Tn as Bn,Ui as Vn,Ur as Hn,Ut as Un,Vi as Wn,Vn as Gn,W as Kn,Wi as qn,Wr as Jn,Wt as Yn,X as Xn,Xa as Zn,Xi as Qn,Xt as $n,Y as er,Ya as tr,Yi as nr,Yr as rr,Z as ir,Za as ar,Zr as or,Zt as sr,_i as cr,_n as lr,_t as ur,a as dr,aa as fr,ai as pr,an as mr,ar as hr,at as gr,ba as _r,bi as vr,bt as yr,ca as br,ci as xr,cn as Sr,dn as Cr,dt as wr,ea as Tr,eo as Er,et as Dr,f as Or,fa as kr,fi as Ar,fn as jr,g as Mr,ga as Nr,gn as Pr,gt as Fr,hi as Ir,hn as Lr,ht as Rr,i as zr,ia as Br,ii as Vr,in as Hr,ir as Ur,it as Wr,j as Gr,ja as Kr,ji as qr,jr as Jr,jt as Yr,k as Xr,ka as Zr,ki as Qr,kn as $r,kr as ei,kt as ti,l as ni,la as ri,li as ii,ln as ai,m as oi,mi as si,mn as ci,mt as li,n as ui,ni as di,nn as fi,nt as pi,oi as mi,oo as hi,or as gi,pi as _i,pn as vi,pt as yi,q as bi,qa as xi,qi as Si,qt as Ci,ri as wi,rn as Ti,rt as Ei,sa as Di,sn as Oi,so as ki,sr as Ai,tn as ji,to as Mi,tt as Ni,un as Pi,uo as Fi,va as Ii,vi as Li,vt as Ri,w as zi,wi as Bi,wt as Vi,x as Hi,xa as Ui,xi as Wi,ya as Gi,yi as Ki,yr as qi,z as Ji,zi as Yi,zn as Xi,zo as Zi}from"./useMobileNavigationStore-BhzZPyek.js";import{a as Qi,i as $i,l as ea,n as ta,o as na,r as ra,s as ia,t as aa}from"./dialog-BUQDNX62.js";import{n as oa,t as Y}from"./utils-CJdWZupK.js";import{t as sa}from"./AgentAvatar-Dn37YqCC.js";import{n as X}from"./Icon-Bs6GJIoO.js";import{t as ca}from"./button-DfF088a8.js";import{E as la,n as ua}from"./gitApi-B81GgsWU.js";import{A as da,C as fa,M as pa,N as ma,O as ha,P as ga,S as _a,T as va,a as ya,b as ba,d as xa,g as Sa,h as Ca,i as wa,j as Ta,k as Ea,n as Da,o as Oa,p as ka,s as Aa,u as ja,v as Ma,w as Na,x as Pa}from"./projectMeta-C6CXnKkb.js";import{t as Fa}from"./input-Ca2tUhgN.js";import{i as Ia,n as La,t as Ra}from"./tooltip-GC3dg3gO.js";import{n as za,t as Ba}from"./useThemeSystem-DMzWVJaW.js";import{B as Va,C as Ha,D as Ua,H as Wa,N as Ga,O as Ka,P as qa,S as Ja,W as Ya,X as Xa,Z as Za,_ as Qa,a as $a,f as eo,g as to,h as no,i as ro,it as io,k as ao,m as oo,o as so,p as co,r as lo,t as uo}from"./radio-BkN54ReP.js";import{i as fo,t as po}from"./OverlayScrollbar-VZKKu-cu.js";import{_ as mo,a as ho,d as go,f as _o,g as vo,h as yo,i as bo,l as xo,m as So,n as Co,u as wo,v as To,x as Eo}from"./markdownTheme-DidS-jC5.js";import{n as Do,r as Oo,t as ko}from"./useRuntimeAPIs-DSLXJybW.js";import{A as Ao,B as jo,C as Mo,D as No,E as Po,F as Fo,H as Io,I as Lo,L as Ro,M as zo,O as Bo,P as Vo,R as Ho,S as Uo,T as Wo,V as Go,a as Ko,b as qo,c as Jo,f as Yo,i as Xo,j as Zo,k as Qo,l as $o,m as es,n as ts,o as ns,p as rs,r as is,s as as,t as os,u as ss,w as cs,x as ls,z as us}from"./insertionBoundaries-BQhLuPL0.js";import{A as ds,C as fs,D as ps,E as ms,M as hs,N as gs,O as _s,S as vs,T as ys,_ as bs,a as xs,b as Ss,c as Cs,d as ws,f as Ts,g as Es,h as Ds,i as Os,j as ks,k as As,m as js,p as Ms,r as Ns,t as Ps,u as Fs,v as Is,w as Ls,x as Rs,y as zs}from"./appThemeRegistry-BxZGWyHG.js";import{_ as Bs,a as Vs,c as Hs,g as Us,l as Ws,o as Gs,t as Ks,v as qs,y as Js}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{i as Ys,n as Xs,o as Zs,s as Qs,t as $s}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as ec,n as tc,t as nc}from"./url-BQHM4bC4.js";import{_ as rc,l as ic,m as ac,p as oc,s as sc}from"./markdown-worker-9Sn2jsDp.js";import{n as cc}from"./useEffectiveDirectory-n3phoQvw.js";import{a as lc,c as uc,d as dc,f as fc,i as pc,l as mc,n as hc,r as gc,s as _c,t as vc}from"./FadeInOnReveal-BpIMrqet.js";import{A as yc,C as bc,D as xc,E as Sc,M as Cc,O as wc,S as Tc,T as Ec,a as Dc,b as Oc,c as kc,g as Ac,h as jc,i as Mc,j as Nc,k as Pc,o as Fc,p as Ic,r as Lc,s as Rc,t as zc,v as Bc,w as Vc,x as Hc,y as Uc}from"./useWorkerHighlightedLines-TzNgQMkz.js";import{t as Wc}from"./vendor-cmdk-CeAGfrLo.js";import{t as Gc}from"./sortable-tabs-strip-COl2MAH7.js";import{n as Kc,t as qc}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{i as Jc,u as Yc}from"./vendor-pierre-diffs-BenIz2TM.js";import{i as Xc,t as Zc}from"./vendor-framer-motion-DFy_BSVd.js";import{t as Qc}from"./vendor-legendapp-list-WE32lwNk.js";var Z=e(ye(),1),Q=We(),$=ve(),$c=e(be(),1),el=`openchamber:close-embedded-session-chat`,tl=`openchamber:embedded-visibility`,nl=`openchamber:embedded-visibility-request`,rl=e=>new URLSearchParams(e).get(`ocPanel`)===`session-chat`,il=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),al=(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()},ol=(e,t,n,r,i,a)=>{let o=il(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=al(n,r,i,a);return e.set(t,{signature:o,src:c}),c},sl=null,cl=()=>{if(sl!==null)return sl;if(typeof window>`u`)return sl=!1,!1;try{return sl=new URLSearchParams(window.location.search).get(`ocPanel`)===`session-chat`,sl}catch{return sl=!1,!1}},ll=()=>{if(!cl())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},ul=Ve(`OpenChamberMedia`);function dl(){return Re()&&He.getPlatform()===`android`&&He.isPluginAvailable(`OpenChamberMedia`)}async function fl(e){if(!dl())return null;let t=await ul.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 pl=(e,t)=>{let n=t.trim();if(!n.length)return[...e].sort((e,t)=>e.scope===`project`&&t.scope!==`project`?-1:e.scope!==`project`&&t.scope===`project`?1:e.name.localeCompare(t.name));let r=yi([...e],n,e=>[e.name,e.description??``]);return r.sort((e,t)=>e.score===t.score?e.item.scope===`project`&&t.item.scope!==`project`?-1:e.item.scope!==`project`&&t.item.scope===`project`?1:e.item.name.localeCompare(t.item.name):e.score-t.score),r.map(e=>e.item)},ml=new Map,hl=(e,t,n)=>`${+!!t}:${n}:${e.map(e=>`${e.id}\0${e.title}\0${e.subtitle??``}\0${e.badge??``}\0${e.iconName}`).join(`|`)}`,gl=async e=>{let t=ks(`--surface-foreground`);return Promise.all(e.slice(0,40).map(async e=>{let n=`${e.iconName}:${t}`,r=ml.get(n);return r===void 0&&(r=await Io(e.iconName,t)??``,ml.set(n,r)),{id:e.id,title:e.title,subtitle:e.subtitle??``,badge:e.badge??``,iconBase64:r}}))},_l=[],vl=e=>void 0,yl=()=>void 0;function bl(e){let t=e.enabled&&Is(e.isMobile),n=(0,Z.useRef)(null),r=(0,Z.useRef)(e.text),i=(0,Z.useRef)(!1),a=(0,Z.useRef)(``),o=(0,Z.useRef)([]),s=(0,Z.useRef)(zs()),c=J(e.onText),l=J(e.onSend),u=J(e.onAbort),d=J(e.onAttach),f=J(e.onFiles),p=J(e.onRemoveAttachment),m=J(e.onOpenModel),h=J(e.onCycleAgent),g=J(e.onOpenAgent),_=J(e.onScrollToBottom),v=J(e.onAutocompleteAccept??vl),y=J(e.onAutocompleteDismiss??yl),b=J(e=>{typeof document>`u`||js(document.documentElement,e)});Ts.bind({onText:(e,t,n)=>{r.current=e,i.current=!0,c(e,t,n)},onSend:e=>{r.current=e,l(e)},onAbort:u,onAttach:d,onFiles:f,onRemoveAttachment:p,onOpenModel:m,onCycleAgent:h,onOpenAgent:g,onHeight:b,onScrollToBottom:_,onAutocompleteAccept:e=>{i.current=!1,v(e)},onAutocompleteDismiss:y});let x=()=>({text:e.text,placeholder:e.placeholder,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel,modelIcon:a.current,canSend:e.canSend,canAbort:e.canAbort,attachmentCount:e.attachmentCount,attachmentPreviews:o.current,citationRanges:De(e.text,e.attachments.map(e=>e.filename)),chipRanges:Es(fs(e.text,e.chipHighlights),ks(`--primary`)),appearance:typeof document>`u`?`dark`:ms(document.documentElement),attachAria:e.attachAria,attachTitle:e.attachTitle,attachPhotosLabel:e.attachPhotosLabel,attachFilesLabel:e.attachFilesLabel,attachCancelLabel:e.attachCancelLabel,sendAria:e.sendAria,queueAria:e.queueAria,stopAria:e.stopAria,modelAria:e.modelAria,agentAria:e.agentAria,agentLabel:e.agentLabel,agentColor:ys(e.agentName||void 0),agentIdenticon:ps(e.agentName||void 0),suppressed:e.suppressed,showScrollToBottom:e.showScrollToBottom,scrollAria:e.scrollAria,autocomplete:s.current});(0,Z.useLayoutEffect)(()=>{if(!t||typeof document>`u`)return;let e=document.documentElement;return gs(e,!0),()=>{gs(e,!1)}},[t]),(0,Z.useEffect)(()=>{if(!t||typeof document>`u`)return;let e=document.documentElement,i=x();n.current=i,r.current=i.text,Ts.rememberText(i.text),Ts.retain(e,i);let a=ws();return()=>{n.current=null,a(),Ts.release(e)}},[t]),(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=ma(e.modelId,e.providerId),o={modelIcon:``,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};if(a.current=``,n.current&&={...n.current,...o},Ss().update(o),i)return As(i).then(t=>{if(r)return;let i=t??``;a.current=i;let o={modelIcon:i,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};n.current&&={...n.current,...o},Ss().update(o)}),()=>{r=!0}},[t,e.modelId,e.providerId,e.modelLabel,e.modelVariantLabel]);let S=Ds(e.attachments);(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=e.attachments;if(i.length===0){o.current=[],n.current&&(n.current={...n.current,attachmentPreviews:[]},Ts.rememberState(n.current)),Ss().update({attachmentPreviews:[]});return}return Promise.all(i.map(async t=>{let n=t.mimeType.startsWith(`image/`)&&t.dataUrl?await _s(t.dataUrl):``;return{id:t.id,filename:t.filename,mime:t.mimeType,thumbnailBase64:n??``,removeAria:e.removeAttachmentNamedAria(t.filename)}})).then(e=>{r||(o.current=e,n.current&&(n.current={...n.current,attachmentPreviews:e},Ts.rememberState(n.current)),Ss().update({attachmentPreviews:e}))}),()=>{r=!0}},[t,S]);let C=e.autocompleteRows??_l,w=e.autocompleteOpen===!0,T=e.autocompleteHighlightedIndex??0,E=hl(C,w,T);(0,Z.useEffect)(()=>{if(!t)return;let e=!1;if(!(w&&C.length>0)){let e=zs();vs(s.current,e)||(s.current=e,n.current&&(n.current={...n.current,autocomplete:e},Ts.rememberState(n.current)),Ss().update({autocomplete:e}));return}return gl(C).then(t=>{if(e)return;let r={open:t.length>0,highlightedIndex:Math.max(0,Math.min(T,Math.max(t.length-1,0))),rows:t};vs(s.current,r)||(s.current=r,n.current&&(n.current={...n.current,autocomplete:r},Ts.rememberState(n.current)),Ss().update({autocomplete:r}))}),()=>{e=!0}},[t,E]);let D=t?fs(e.text,e.chipHighlights).map(e=>`${e.start}:${e.end}:${e.triggerLength}`).join(`|`):``;return(0,Z.useEffect)(()=>{if(!t)return;let a=x(),o=n.current;if(o&&Ls(o,a)){i.current=!1;return}n.current=a,Ts.rememberState(a);let s=hs({nextText:a.text,nativeOwnedText:r.current,echoingNative:i.current});i.current=!1,r.current=a.text;let c=bs(o,a,s,{caret:e.caret});c&&Ss().update(c)},[t,e.text,e.placeholder,e.modelLabel,e.modelVariantLabel,e.modelId,e.providerId,e.canSend,e.canAbort,e.attachmentCount,S,e.suppressed,e.attachAria,e.attachTitle,e.attachPhotosLabel,e.attachFilesLabel,e.attachCancelLabel,e.sendAria,e.queueAria,e.stopAria,e.modelAria,e.agentName,e.agentLabel,e.agentAria,e.showScrollToBottom,e.scrollAria,D]),t}var xl=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},Sl=1e4,Cl=15e3,wl=3e4,Tl=3e4,El=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`))}},Sl);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`))},Cl);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`))},Tl),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=xl(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)}}},wl))}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`,()=>{El.cancelAllForRuntimeSwitch()});var Dl=128,Ol=`audio/pcm;rate=16000;bits=16`,kl=()=>new Promise(e=>setTimeout(e,0)),Al=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},jl=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??Ol,this.getStartOptions=e.getStartOptions,this.createDictationId=e.createDictationId??Al}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<Dl;){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 kl()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},Ml=16e3,Nl=Ml,Pl=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},Fl=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},Il=(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]=Fl(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]=Fl(e[i]*(1-s)+e[o]*s)}return a},Ll=(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},Rl=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)},zl=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),Bl=e=>{if(e)try{e.disconnect()}catch{}},Vl=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Pl()!==null;function Hl(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=zl(),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=Pl();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(Gl);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=Il(a,n.sampleRate,Ml);for(t.pending=Ll(t.pending,c);t.pending.length>=Nl;){let e=t.pending.slice(0,Nl);t.pending=t.pending.slice(Nl),i.current(Rl(e))}},e.connect(a),a.connect(o),o.connect(n.destination)}catch(e){let r=e;t.getTracks().forEach(Wl);try{await n.close()}catch{}throw l.current=zl(),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{}Bl(e.processor),Bl(e.source),Bl(e.gain),e.stream&&e.stream.getTracks().forEach(Ul);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current(Rl(t)),e.context)try{await e.context.close()}catch{}l.current===e&&(l.current=zl())},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 Ul(e){try{e.stop()}catch{}}function Wl(e){try{e.stop()}catch{}}function Gl(){}var Kl=1e3,ql=e=>e instanceof Error?e:Error(String(e)),Jl=()=>{let e=br.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 Yl(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 jl({client:El,getStartOptions:Jl});let x=(0,Z.useCallback)(()=>{g.current&&=(clearInterval(g.current),null)},[]),S=(0,Z.useCallback)(()=>{g.current||=setInterval(()=>{l(e=>e+1)},Kl)},[]),C=(0,Z.useCallback)(e=>{let t=ql(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)(()=>El.onPartial((e,t)=>{let n=b.current?.getDictationId();!n||e!==n||(h.current=t,s(t))}),[]),(0,Z.useEffect)(()=>El.subscribeConnectionStatus(e=>{e&&m.current===`recording`&&b.current?.restartStream().catch(e=>{C(e)})}),[C]);let E=Hl({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 Xl=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},Zl=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=za(),i=Math.min(1,Math.max(0,n)),a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=[.45,.7,1,.7,.45],t[0]=a):a=t[0];let o=a,s;return t[1]!==r||t[2]!==i?(s=(0,$.jsx)(`div`,{className:`flex h-6 w-10 flex-shrink-0 items-center justify-center gap-1`,"aria-hidden":`true`,children:o.map((e,t)=>(0,$.jsx)(`span`,{className:`h-full w-1 rounded-full transition-transform duration-75 ease-out motion-reduce:transition-none`,style:{backgroundColor:r.colors.primary.base,transform:`scaleY(${.25+i*e*.75})`}},t))}),t[1]=r,t[2]=i,t[3]=s):s=t[3],s},Ql=e=>{let t=br(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},$l=e=>{let t=(0,Q.c)(86),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:c,disabled:l,onInsert:u,onInsertAndSend:d,onActiveChange:f,onContentHeightChange:p,renderTrigger:m,topAccessory:h}=e,g=m===void 0||m,{t:_}=ot(),{currentTheme:v}=za(),y=br(eu),b=s(tu),x;t[0]===b?x=t[1]:(x=Wa(Ya(`toggle_dictation`,b)),t[0]=b,t[1]=x);let S=x,[C]=Z.useState(nu),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}=Yl(k),H=A===`recording`&&F===`model_download_in_progress`,U=Ql(H),W=Z.useRef(A),ee,G;t[7]===A?(ee=t[8],G=t[9]):(ee=()=>{W.current=A},G=[A],t[7]=A,t[8]=ee,t[9]=G),Z.useEffect(ee,G);let K,q;t[10]!==f||t[11]!==A?(K=()=>{f?.(A!==`idle`)},q=[A,f],t[10]=f,t[11]=A,t[12]=K,t[13]=q):(K=t[12],q=t[13]),Z.useLayoutEffect(K,q);let te,ne;t[14]!==L||t[15]!==I?(te=()=>{let e=()=>{W.current===`idle`?I():W.current===`recording`&&(w.current=`insert`,L())};return window.addEventListener(`openchamber:dictation-toggle`,e),()=>window.removeEventListener(`openchamber:dictation-toggle`,e)},ne=[I,L],t[14]=L,t[15]=I,t[16]=te,t[17]=ne):(te=t[16],ne=t[17]),Z.useEffect(te,ne);let re,ie;t[18]!==R||t[19]!==L||t[20]!==A?(re=()=>{if(A!==`recording`)return;let e=e=>{if(!e.isComposing){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault(),e.stopPropagation(),w.current=`insert`,L();return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),R())}};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},ie=[A,L,R],t[18]=R,t[19]=L,t[20]=A,t[21]=re,t[22]=ie):(re=t[21],ie=t[22]),Z.useEffect(re,ie);let ae=Z.useRef(null),oe=Z.useRef(null),se=Z.useRef(null),[ce,le]=Z.useState(null),ue=A!==`idle`,de=Z.useRef(p),fe,pe;t[23]===p?(fe=t[24],pe=t[25]):(fe=()=>{de.current=p},pe=[p],t[23]=p,t[24]=fe,t[25]=pe),Z.useEffect(fe,pe);let me=Z.useRef(!1),he;t[26]===ue?he=t[27]:(he=()=>{if(!ue){me.current&&(me.current=!1,de.current?.(null));return}let e=oe.current,t=se.current;if(!e||!t)return;let n=window.getComputedStyle(e),r=(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0);me.current=!0,de.current?.(t.offsetHeight+r),e.scrollTop=e.scrollHeight},t[26]=ue,t[27]=he);let ge;t[28]!==P||t[29]!==ue||t[30]!==j||t[31]!==A?(ge=[ue,j,A,P],t[28]=P,t[29]=ue,t[30]=j,t[31]=A,t[32]=ge):ge=t[32],Z.useLayoutEffect(he,ge);let _e,ve;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(_e=()=>()=>{me.current&&(me.current=!1,de.current?.(null))},ve=[],t[33]=_e,t[34]=ve):(_e=t[33],ve=t[34]),Z.useEffect(_e,ve);let ye,be;if(t[35]===ue?(ye=t[36],be=t[37]):(ye=()=>{if(!ue)return;let e=ae.current?.closest(`[data-chat-input-footer="true"]`);e&&e.offsetHeight>0&&le(e.offsetHeight)},be=[ue],t[35]=ue,t[36]=ye,t[37]=be),Z.useLayoutEffect(ye,be),!C||!y)return null;let xe=A!==`idle`,Se;t[38]===L?Se=t[39]:(Se=e=>{w.current=e,L()},t[38]=L,t[39]=Se);let Ce=Se,we;t[40]===z?we=t[41]:(we=()=>{w.current=`insert`,z()},t[40]=z,t[41]=we);let Te=we,Ee;bb0:{if(A===`failed`){Ee=``;break bb0}if(A===`uploading`){let e;t[42]===_?e=t[43]:(e=_(`chat.dictation.processing`),t[42]=_,t[43]=e),Ee=e;break bb0}if(H){let e;t[44]!==U||t[45]!==_?(e=U===null?_(`chat.dictation.downloadingModel`):_(`chat.dictation.downloadingModelProgress`,{percent:String(U)}),t[44]=U,t[45]=_,t[46]=e):e=t[46],Ee=e;break bb0}let e;t[47]===_?e=t[48]:(e=_(`chat.dictation.listening`),t[47]=_,t[48]=e),Ee=e}let De=Ee,Oe;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(Oe={onMouseDown:ru,onPointerDownCapture:iu},t[49]=Oe):Oe=t[49];let ke=Oe,Ae;t[50]!==S||t[51]!==l||t[52]!==i||t[53]!==o||t[54]!==xe||t[55]!==g||t[56]!==I||t[57]!==_?(Ae=g?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{I()},disabled:l||xe,title:S?`${_(`chat.dictation.start`)} (${S})`:_(`chat.dictation.start`),"aria-label":_(`chat.dictation.start`),children:(0,$.jsx)(X,{name:`mic`,className:Y(o,`text-current`)})}):null,t[50]=S,t[51]=l,t[52]=i,t[53]=o,t[54]=xe,t[55]=g,t[56]=I,t[57]=_,t[58]=Ae):Ae=t[58];let je;t[59]!==B||t[60]!==R||t[61]!==Ce||t[62]!==v||t[63]!==V||t[64]!==N||t[65]!==P||t[66]!==ce||t[67]!==i||t[68]!==a||t[69]!==o||t[70]!==xe||t[71]!==r||t[72]!==H||t[73]!==j||t[74]!==De||t[75]!==n||t[76]!==Te||t[77]!==c||t[78]!==A||t[79]!==_||t[80]!==h||t[81]!==M?(je=xe?(0,$.jsxs)(`div`,{ref:ae,className:Y(`absolute inset-0 z-50 flex flex-col overflow-x-hidden overflow-y-hidden`,r&&`oc-composer-morph-content-fade`),style:{borderRadius:n,backgroundColor:v.colors.surface.subtle},role:`dialog`,"aria-label":_(`chat.dictation.overlayAria`),children:[h,(0,$.jsx)(`div`,{ref:oe,className:Y(`scrollbar-none flex-1 min-h-0 overflow-y-auto px-3`,r?`pt-3.5 pb-2.5`:`pt-5 pb-2`),children:(0,$.jsxs)(`div`,{ref:se,className:Y(!j&&`translate-y-1.5`),children:[j?(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label whitespace-pre-wrap`,style:{color:v.colors.surface.foreground},children:j}):A===`recording`?(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,style:{color:v.colors.surface.mutedForeground},children:[(0,$.jsx)(Zl,{volume:M}),(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,children:De})]}):(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,style:{color:v.colors.surface.mutedForeground},children:De}),A===`failed`?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.error},children:P||_(`chat.dictation.failed`)}):null,A===`recording`&&P&&!H?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:v.colors.status.warning},children:P}):null]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center gap-x-3`,a),style:ce?{height:ce}:void 0,children:[A===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`relative ml-1 flex h-2 w-2 flex-shrink-0`,"aria-hidden":`true`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full opacity-60`,style:{backgroundColor:v.colors.status.error}}),(0,$.jsx)(`span`,{className:`relative inline-flex h-2 w-2 rounded-full`,style:{backgroundColor:v.colors.status.error}})]}),(0,$.jsx)(Zl,{volume:M}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:v.colors.surface.mutedForeground},children:Xl(N)})]}):A===`uploading`?(0,$.jsx)(X,{name:`loader-4`,className:`ml-1 h-4 w-4 animate-spin`,style:{color:v.colors.surface.mutedForeground}}):null,(0,$.jsx)(`div`,{className:Y(`ml-auto flex items-center`,r?`gap-x-1`:`gap-x-1.5 md:gap-x-3`),children:A===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>Ce(`insert`),title:_(`chat.dictation.insert`),"aria-label":_(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-primary hover:text-primary`),onClick:()=>Ce(`send`),title:_(`chat.dictation.insertAndSend`),"aria-label":_(`chat.dictation.insertAndSend`),children:(0,$.jsx)(X,{name:`send-plane-2`,className:c})})]}):A===`uploading`?(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{R()},title:_(`chat.dictation.cancel`),"aria-label":_(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:V,title:_(`chat.dictation.discard`),"aria-label":_(`chat.dictation.discard`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:Te,title:_(`chat.dictation.retry`),"aria-label":_(`chat.dictation.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:o})}),j.trim()?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{w.current=`insert`,B()},title:_(`chat.dictation.insert`),"aria-label":_(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}):null]})})]})]}):null,t[59]=B,t[60]=R,t[61]=Ce,t[62]=v,t[63]=V,t[64]=N,t[65]=P,t[66]=ce,t[67]=i,t[68]=a,t[69]=o,t[70]=xe,t[71]=r,t[72]=H,t[73]=j,t[74]=De,t[75]=n,t[76]=Te,t[77]=c,t[78]=A,t[79]=_,t[80]=h,t[81]=M,t[82]=je):je=t[82];let Me;return t[83]!==Ae||t[84]!==je?(Me=(0,$.jsxs)($.Fragment,{children:[Ae,je]}),t[83]=Ae,t[84]=je,t[85]=Me):Me=t[85],Me};function eu(e){return e.dictationEnabled}function tu(e){return e.shortcutOverrides}function nu(){return!d()&&Vl()}function ru(e){return e.preventDefault()}function iu(e){e.pointerType===`touch`&&e.preventDefault()}var au=2e3,ou=ue((e,t)=>({pending:!1,expiresAt:null,arm:(t=au)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),su=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}},cu=15e3,lu=100,uu=new Map,du=new Map,fu=e=>`${e.runtimeKey}\n${e.directory}\n${e.sessionID}`,pu=e=>{let t=fu(e),n=e.now??Date.now(),r=du.get(t);if(r&&n-r.loadedAt<cu)return Promise.resolve(r.sessions);let i=uu.get(t);if(i)return i;let a=e.request().then(e=>{for(du.delete(t);du.size>=lu;){let e=du.keys().next().value;if(typeof e!=`string`)break;du.delete(e)}return du.set(t,{loadedAt:Date.now(),sessions:e}),e});return uu.set(t,a),a.then(()=>{uu.get(t)===a&&uu.delete(t)},()=>{uu.get(t)===a&&uu.delete(t)}),a},mu=(e,t)=>e.id<t.id?-1:+(e.id>t.id),hu=(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(mu)},gu=30;function _u(e){return e===`busy`||e===`retry`}var vu=new Map;function yu(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function bu(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 xu(e,t){if(!e.error)return;let n=e.response?.status;throw Error(`${t} failed${n?` (${n})`:``}: ${bu(e.error)}`)}function Su(e,t){let n=xt();if(!n)return!1;let r=n.getTranscript(Kr(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>An()}function Cu(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function wu(e,t,n){let r=[...e.getState().session],i=qt.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function Tu(){let e=Pr(),t=Vt(),n=Un(),r=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),a=(0,Z.useCallback)((t,n=e)=>{let r=xt();if(!r||!t)return yu({kind:`unknown`,loadedTurns:0},!1);let i=Kr(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return yu(a.boundary,o?.status===`loading`)},[e]),o=(0,Z.useCallback)((e,t)=>{if(t.length===0)return;let r=n.getChild(e);if(!r)return;let i=r.getState(),a={session_status:{...i.session_status},session_status_observed_at:{...i.session_status_observed_at},session_diff:{...i.session_diff},todo:{...i.todo},permission:{...i.permission},question:{...i.question}};Ot(a,t),Zt(r,t),r.setState(a);for(let n of t)jt(e,n)},[n]),s=(0,Z.useCallback)((t=e)=>{let n=vu.get(t);if(n)return vu.delete(t),vu.set(t,n),n;let r=new Set;for(vu.set(t,r);vu.size>gu;){let e=vu.keys().next().value;if(!e)break;let t=[...vu.get(e)??[]];vu.delete(e),o(e,t)}return r},[e,o]),c=(0,Z.useCallback)((r,i=e)=>{let a=i===e?t:n.ensureChild(i,{bootstrap:!1}),c=s(i),l=yn(a.getState()),u=Jt(),d=$r({seen:c,keep:r,limit:u,preserve:l});if(o(i,d),ln()){let e=new Set([r,...c,...l]),t=(xt()?.getCacheBudget?.().listCanonical({directory:i})??[]).map(e=>e.scope.sessionID),n=(t.length>0?t:Array.from(c)).filter(t=>t===r||e.has(t)?!1:Su(i,t));if(n.length>0){for(let e of n)c.delete(e);o(i,n)}}},[n,e,s,o,t]),l=(0,Z.useCallback)(async(r,i)=>{let a=i?.directory??e;if(!r||!a||a===`global`)return;let o=a===e?t:n.ensureChild(a,{bootstrap:!1}),s=o.getState(),c=s.session_status?.[r],l=s.session_status_observed_at?.[r];try{i?.purpose===`prepend`||i?.before?await Ui(a,r):await _r(a,r)}catch{return}if(i?.isStale?.())return;let u=xt()?.getTranscript(Kr(a,r));Vr({directory:a,sessionID:r,store:o,transcript:u,isStale:i?.isStale}),await ii({directory:a,sessionID:r,store:o,statusBeforePull:c,statusObservedAtBeforePull:l,hasMessages:(u?.messageOrder.length??0)>0,isTailPage:!i?.before,isStale:i?.isStale})},[n,t,e]),u=(0,Z.useCallback)(async(t,i)=>{await Zi();let a=typeof i==`boolean`?i:i?.force,o=typeof i==`object`?i.directory??e:e,s=n.ensureChild(o,{bootstrap:!1}),u=ke.getScopedSdkClient(o);c(t,o);let d=r(t,o);return su.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=xt(),i=Kr(o,t),c=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=qt.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&c&&d.kind!==`unknown`&&p?.status!==`error`&&f&&vt(o,t)){Vr({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!c||f),h=Cu({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await fr(async()=>{let e=await u.session.get({sessionID:t,directory:o});return xu(e,`session.get`),e});if(n.data&&!e()){let r=Br(n.data);e()||wu(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?l(t,{isStale:e,directory:o}):Promise.resolve()])}})},[n,r,c,l,e]),d=(0,Z.useCallback)(async(t,r)=>{let a=r||e;if(!t||!a)return;let o=n.ensureChild(a,{bootstrap:!1}),s=ke.getScopedSdkClient(a),c=await pu({runtimeKey:i(),directory:a,sessionID:t,request:async()=>{let e=await s.session.children({sessionID:t,directory:a});return xu(e,`session.children`),e.data??[]}});o.setState(e=>{let n=hu(e.session,c,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})},[n,e]),f=(0,Z.useCallback)((t,n)=>{let r=a(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,a]),p=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).loading,[e,a]),m=(0,Z.useCallback)((t,n)=>a(t,n?.directory??e).complete,[e,a]),h=(0,Z.useCallback)(t=>{let n=t.directory||e;Gi(Kr(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;Gi(Kr(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;Gi(Kr(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(async(t,r)=>{if(!t)return;await Zi();let i=r?.directory??e;if(!i||i===`global`)return;let a=n.ensureChild(i,{bootstrap:!1}),o=a.getState().session_status?.[t]?.type;if(_u(o))throw Error(`refresh transcript busy`);try{await Et(i,t),Vr({directory:i,sessionID:t,store:a})}catch(e){throw e instanceof Error&&e.message===`refresh transcript busy`?e:Error(`refresh transcript failed`)}},[n,e]);return(0,Z.useMemo)(()=>({ensureSessionRenderable:u,syncSession:u,loadChildren:d,hasMore:f,isLoading:p,isComplete:m,refreshSessionTranscript:v,optimistic:{add:h,remove:g,confirm:_}}),[u,d,f,p,m,v,h,g,_])}var Eu=e=>e===`diff`||e===`plan`||e===`file`||e===`preview-console`||e===`preview-annotation`,Du=e=>e===`original`||e===`modified`,Ou=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},ku=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!Eu(t.source))return null;let n=Ou(t.startLine),r=Ou(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:Du(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()}},Au=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(ku).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},ju=ue()(fe(de((e,t)=>({drafts:{},addDraft:t=>{let n=`icd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,r={...t,id:n,createdAt:Date.now()};return e(e=>{let n=e.drafts[t.sessionKey]??[];return{drafts:{...e.drafts,[t.sessionKey]:[...n,r]}}}),n},updateDraft:(t,n,r)=>{e(e=>{let i=(e.drafts[t]??[]).map(e=>e.id===n?{...e,...r}:e);return{drafts:{...e.drafts,[t]:i}}})},removeDraft:(t,n)=>{e(e=>{let r=(e.drafts[t]??[]).filter(e=>e.id!==n);if(r.length===0){let{[t]:n,...r}=e.drafts;return{drafts:r}}return{drafts:{...e.drafts,[t]:r}}})},clearDrafts:t=>{e(e=>{let{[t]:n,...r}=e.drafts;return{drafts:r}})},getDrafts:e=>t().drafts[e]??[],consumeDrafts:n=>{let r=t().drafts[n]??[];if(r.length===0)return[];let i=[...r].sort((e,t)=>e.createdAt-t.createdAt);return e(e=>{let{[n]:t,...r}=e.drafts;return{drafts:r}}),i},getDraftCount:e=>(t().drafts[e]??[]).length,hasDrafts:e=>(t().drafts[e]??[]).length>0}),{name:`openchamber-inline-comment-drafts`,storage:l(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:Au(e.drafts)}}),{name:`inline-comment-draft-store`}));function Mu(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 Nu(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(Mu).join(`
|
|
3
3
|
|
|
4
4
|
---
|
|
5
5
|
|
|
@@ -6521,7 +6521,7 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,E as n,P as r,T
|
|
|
6521
6521
|
`))r.startsWith(`+`)&&!r.startsWith(`+++`)&&t++,r.startsWith(`-`)&&!r.startsWith(`---`)&&n++;return{added:t,removed:n}},rg=e=>{let t=[],n=new Set;for(let r of e){if(r.type!==`tool`||!$h.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:tg(i.additions)??void 0,deletions:tg(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:tg(e.additions)??void 0,deletions:tg(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:tg(i.additions)??void 0,deletions:tg(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=ng(e);t.push({path:`Diff`,tool:r.tool,partId:r.id,messageID:r.messageID,additions:i.added,deletions:i.removed})}}}return t},ig=(e,t,n)=>{let r=[];for(let i of e){let e=i.index?.trim()??``,a=i.working_dir?.trim()??``,o=!!(e&&e!==`?`),s=!!(a||e===`?`),c=a||e;if(!c||c===`!`)continue;let l=t?.[i.path];r.push({path:vo(n,i.path),relativePath:i.path,insertions:l?.insertions??0,deletions:l?.deletions??0,status:c,hasStagedChanges:o,hasWorkingChanges:s})}return r},ag=e=>{for(let t of e){let e=t.index?.trim()??``,n=(t.working_dir?.trim()??``)||e;if(!(!n||n===`!`))return!0}return!1},og=(e,t)=>_o(e,t),sg=(e,t)=>{let n=eg(e)&&e.relativePath?e.relativePath:og(e.path,t);return{fileName:n.split(`/`).pop()??n,dirPart:n.includes(`/`)?n.slice(0,n.lastIndexOf(`/`)):``}},cg=e=>eg(e)?{additions:e.insertions,deletions:e.deletions}:{additions:e.additions??0,deletions:e.deletions??0},lg=2;function ug(e){let t=e.lastIndexOf(`.`);return t<=0||t===e.length-1?{stem:e,ext:``}:{stem:e.slice(0,t),ext:e.slice(t)}}function dg(e,t=lg){let n=e??``,r=n.startsWith(`/`),i=n.split(`/`).filter(Boolean);if(i.length===0)return{prefix:``,parent:``,stem:``,ext:``,name:``,leadingSlash:r};let a=i[i.length-1]??``,{stem:o,ext:s}=ug(a),c=Math.max(1,Math.floor(t)),l=Math.min(i.length-1,c-1),u=i.length-1-l,d=l>0?i.slice(u,-1).join(`/`):``,f=i.slice(0,u).join(`/`),p=f?r?`/${f}`:f:``;return{prefix:p,parent:d,stem:o,ext:s,name:a,leadingSlash:r&&!p}}function fg(e){let t=(0,Q.c)(36),{path:n,className:r,title:i,dirClassName:a,nameClassName:o}=e,s=a===void 0?`text-muted-foreground`:a,c=o===void 0?`text-foreground`:o,l;t[0]===n?l=t[1]:(l=dg(n),t[0]=n,t[1]=l);let{prefix:u,parent:d,stem:f,ext:p,leadingSlash:m}=l,h=!!(u||d),g;t[2]===r?g=t[3]:(g=Y(`flex min-w-0 items-baseline overflow-hidden`,r),t[2]=r,t[3]=g);let _=i??n,v;t[4]!==s||t[5]!==m?(v=m?(0,$.jsx)(`span`,{className:Y(`shrink-0`,s),children:`/`}):null,t[4]=s,t[5]=m,t[6]=v):v=t[6];let y;t[7]!==s||t[8]!==u?(y=u?(0,$.jsx)(`span`,{className:Y(`min-w-0 shrink-[9999] truncate`,s),children:u}):null,t[7]=s,t[8]=u,t[9]=y):y=t[9];let b;t[10]!==s||t[11]!==d||t[12]!==u?(b=d?(0,$.jsxs)(`span`,{className:Y(`shrink-0`,s),children:[u?`/`:``,d]}):null,t[10]=s,t[11]=d,t[12]=u,t[13]=b):b=t[13];let x;t[14]!==s||t[15]!==h?(x=h?(0,$.jsx)(`span`,{className:s,children:`/`}):null,t[14]=s,t[15]=h,t[16]=x):x=t[16];let S;t[17]===c?S=t[18]:(S=Y(`min-w-0 truncate`,c),t[17]=c,t[18]=S);let C;t[19]!==f||t[20]!==S?(C=(0,$.jsx)(`span`,{className:S,children:f}),t[19]=f,t[20]=S,t[21]=C):C=t[21];let w;t[22]!==p||t[23]!==c?(w=p?(0,$.jsx)(`span`,{className:Y(`shrink-0`,c),children:p}):null,t[22]=p,t[23]=c,t[24]=w):w=t[24];let T;t[25]!==C||t[26]!==w||t[27]!==x?(T=(0,$.jsxs)(`span`,{className:`flex min-w-0 shrink items-baseline`,children:[x,C,w]}),t[25]=C,t[26]=w,t[27]=x,t[28]=T):T=t[28];let E;return t[29]!==T||t[30]!==g||t[31]!==_||t[32]!==v||t[33]!==y||t[34]!==b?(E=(0,$.jsxs)(`span`,{className:g,title:_,children:[v,y,b,T]}),t[29]=T,t[30]=g,t[31]=_,t[32]=v,t[33]=y,t[34]=b,t[35]=E):E=t[35],E}var pg=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:bc,children:o}),t[2]=o,t[3]=s);let c;t[4]===n.length?c=t[5]:(c=(0,$.jsx)(`span`,{className:Tc,children:n.length}),t[4]=n.length,t[5]=c);let l;t[6]!==s||t[7]!==c?(l=(0,$.jsxs)(`div`,{className:Hc,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}=sg(e,r),s=cg(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`,Ec),title:a(`chat.changedFiles.actions.openFileTitle`,{path:e.path}),onClick:()=>i(e),children:[(0,$.jsx)(hd,{filePath:e.path,className:`h-3 w-3 shrink-0 md:h-3.5 md:w-3.5`}),(0,$.jsx)(fg,{path:o?`${o}/${n}`:n,title:e.path,className:`min-w-0 flex-1`}),s.additions>0||s.deletions>0?(0,$.jsxs)(`span`,{className:`flex-shrink-0 inline-flex items-baseline gap-1 text-xs tabular-nums leading-4 md:text-[0.8125rem] md:leading-5`,children:[s.additions>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,s.additions]}):null,s.deletions>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,s.deletions]}):null]}):null]},`${e.path}:${t}`)},t[14]=r,t[15]=i,t[16]=a,t[17]=e):e=t[17],u=n.map(e),t[9]=r,t[10]=n,t[11]=i,t[12]=a,t[13]=u}else u=t[13];let d;t[18]===u?d=t[19]:(d=(0,$.jsx)(`div`,{className:Vc,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},mg=`${Oc} origin-[var(--transform-origin)]`,hg=Sc,gg=Z.memo(()=>{let e=(0,Q.c)(60),{t}=ot(),[n,r]=Z.useState(!1),i=Z.useRef(null),a=cc()??null,o=Z.useContext(Oo),c=ls(a),l;e[0]===a?l=e[1]:(l=e=>a?e.directories.get(a)?.status??null:null,e[0]=a,e[1]=l);let u=qo(l),d=Qh(),f,p;e[2]===n?(f=e[3],p=e[4]):(f=()=>{if(!n)return;let e=e=>{i.current&&!i.current.contains(e.target)&&r(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},p=[n],e[2]=n,e[3]=f,e[4]=p),Z.useEffect(f,p);let m;bb0:{if(!a||c!==!0||!u||u.isClean){let t;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[5]=t):t=e[5],m=t;break bb0}let t;e[6]!==a||e[7]!==u.diffStats||e[8]!==u.files?(t=ig(u.files,u.diffStats,a),e[6]=a,e[7]=u.diffStats,e[8]=u.files,e[9]=t):t=e[9],m=t}let h=m,g=0,_=0;if(e[10]!==g||e[11]!==h||e[12]!==_){for(let e of h)g+=e.insertions,_+=e.deletions;e[10]=g,e[11]=h,e[12]=_,e[13]=g,e[14]=_}else g=e[13],_=e[14];let v;e[15]!==g||e[16]!==_?(v={totalAdded:g,totalRemoved:_},e[15]=g,e[16]=_,e[17]=v):v=e[17];let{totalAdded:y,totalRemoved:b}=v;if(!a||c!==!0||h.length===0)return null;let x;e[18]!==a||e[19]!==d||e[20]!==o?.editor?(x=e=>{if(!a||!eg(e))return;r(!1);let t=e.path;if(d){d.openChanges({diffPath:e.relativePath,staged:e.hasStagedChanges&&!e.hasWorkingChanges});return}let n=o?.editor;if(n){n.openFile(t);return}let i=s.getState(),c=e.hasStagedChanges&&!e.hasWorkingChanges;if(!i.isMobile){i.openContextDiff(a,e.relativePath,c);return}i.navigateToDiff(e.relativePath,c),i.setRightSidebarOpen(!1)},e[18]=a,e[19]=d,e[20]=o?.editor,e[21]=x):x=e[21];let S=x,C=h.length,w;e[22]!==C||e[23]!==t?(w=t(C===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:C}),e[22]=C,e[23]=t,e[24]=w):w=e[24];let T=w,E,D;e[25]===Symbol.for(`react.memo_cache_sentinel`)?(E=Y(xc,`max-w-full text-left`),D=()=>r(_g),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:wc}),O=Y(Pc,`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`,Pc),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(yc,`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:wc}):(0,$.jsx)(X,{name:`arrow-down-s`,className:wc}),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:hg,className:Y(mg,`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)(pg,{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});gg.displayName=`PendingChangesBar`;function _g(e){return!e}var vg=Z.memo(e=>{let t=(0,Q.c)(22),{visible:n,onClick:r,placement:i}=e,a=i===void 0?`default`:i,{t:o}=ot(),s=a===`compact`;if(s&&!n)return null;let c=a==="default"&&`absolute left-1/2 bottom-full mb-2 -translate-x-1/2`,l=a===`expanded`&&`absolute left-1/2 -translate-x-1/2 oc-scroll-to-bottom--expanded mb-2`,u=a===`compact`&&`oc-scroll-to-bottom--compact relative shrink-0`,d;t[0]!==a||t[1]!==c||t[2]!==l||t[3]!==u||t[4]!==n?(d=Y(c,l,u,n?Y(`pointer-events-auto`,a==="default"&&`opacity-100`):Y(`opacity-0 pointer-events-none`,a===`expanded`&&`oc-scroll-to-bottom--hidden`)),t[0]=a,t[1]=c,t[2]=l,t[3]=u,t[4]=n,t[5]=d):d=t[5];let f=s?`ghost`:`outline`,p=s?`composer-mobile-actions h-8 w-8 rounded-none bg-transparent hover:bg-transparent text-foreground`:`size-8 rounded-full [corner-shape:round] bg-background/95 hover:bg-interactive-hover`,m;t[6]===p?m=t[7]:(m=Y(`p-0 shadow-none`,p),t[6]=p,t[7]=m);let h;t[8]===o?h=t[9]:(h=o(`chat.scrollToBottom.aria`),t[8]=o,t[9]=h);let g=s?`size-5`:`size-4`,_=s?`medium`:`regular`,v;t[10]!==g||t[11]!==_?(v=(0,$.jsx)(X,{name:`arrow-down`,className:g,weight:_}),t[10]=g,t[11]=_,t[12]=v):v=t[12];let y;t[13]!==r||t[14]!==v||t[15]!==f||t[16]!==m||t[17]!==h?(y=(0,$.jsx)(ca,{variant:f,size:`sm`,onClick:r,className:m,"aria-label":h,children:v}),t[13]=r,t[14]=v,t[15]=f,t[16]=m,t[17]=h,t[18]=y):y=t[18];let b;return t[19]!==y||t[20]!==d?(b=(0,$.jsx)(`div`,{className:d,children:y}),t[19]=y,t[20]=d,t[21]=b):b=t[21],b}),yg=Z.createContext(`default`),bg=()=>Z.useContext(yg),xg=500,Sg=e=>{let t=(0,Q.c)(31),{onCycleAgent:n,onOpenAgentPanel:r,className:i,agentName:a,agents:o,disabled:s}=e,c;t[0]===o?c=t[1]:(c=o===void 0?[]:o,t[0]=o,t[1]=c);let l=c,u=s!==void 0&&s,d=a??void 0,f;t[2]!==l||t[3]!==d?(f=$t(l,d),t[2]=l,t[3]=d,t[4]=f):f=t[4];let p=f,m=sm(d),h;t[5]===d?h=t[6]:(h=ea(d),t[5]=d,t[6]=h);let g=h,_=Z.useRef(null),v=Z.useRef(!1),y;t[7]!==u||t[8]!==r?(y=e=>{e.preventDefault(),!u&&(v.current=!1,_.current=setTimeout(()=>{v.current=!0,r()},xg))},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`,pm,i),t[16]=i,t[17]=D);let O;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(O={height:`26px`,maxHeight:`26px`,minHeight:`26px`},t[18]=O):O=t[18];let k;t[19]!==g.var||t[20]!==p||t[21]!==d||t[22]!==m?(k=(0,$.jsx)(om,{name:d,label:p,revealed:m,avatarSize:16,slotClassName:`h-[26px] w-6`,colorVar:g.var}),t[19]=g.var,t[20]=p,t[21]=d,t[22]=m,t[23]=k):k=t[23];let A;return t[24]!==p||t[25]!==u||t[26]!==b||t[27]!==S||t[28]!==D||t[29]!==k?(A=(0,$.jsx)(`button`,{type:`button`,disabled:u,onPointerDown:b,onPointerUp:S,onPointerLeave:w,onContextMenu:Cg,onMouseDown:wg,className:D,style:O,title:p,"aria-label":p,children:k}),t[24]=p,t[25]=u,t[26]=b,t[27]=S,t[28]=D,t[29]=k,t[30]=A):A=t[30],A};function Cg(e){return e.preventDefault()}function wg(e){return e.preventDefault()}var Tg=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=Zn(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()?xi(s):null,t[4]=s,t[5]=p);let m=p,h=m?`${f} ${m}`:f,g;t[6]===r?g=t[7]:(g=Y(`inline-flex min-w-0 max-w-36 items-stretch`,`rounded-lg`,`focus:outline-none hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-40`,r),t[6]=r,t[7]=g);let _;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(_={height:`26px`,maxHeight:`26px`,minHeight:`26px`},t[8]=_):_=t[8];let v;t[9]!==a||t[10]!==i?(v=a||i?(0,$.jsx)(Ea,{modelId:a,providerId:i,className:`size-4 flex-shrink-0`}):null,t[9]=a,t[10]=i,t[11]=v):v=t[11];let y;t[12]===f?y=t[13]:(y=(0,$.jsx)(`span`,{className:`truncate text-[11px] leading-none font-medium text-foreground/80`,children:f}),t[12]=f,t[13]=y);let b;t[14]===m?b=t[15]:(b=m?(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] leading-none font-normal text-muted-foreground`,children:m}):null,t[14]=m,t[15]=b);let x;t[16]!==y||t[17]!==b?(x=(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1`,children:[y,b]}),t[16]=y,t[17]=b,t[18]=x):x=t[18];let S;t[19]!==v||t[20]!==x?(S=(0,$.jsxs)(`span`,{className:`flex h-full w-full min-w-0 items-center gap-1`,children:[v,x]}),t[19]=v,t[20]=x,t[21]=S):S=t[21];let C;return t[22]!==h||t[23]!==l||t[24]!==n||t[25]!==S||t[26]!==g?(C=(0,$.jsx)(`button`,{type:`button`,disabled:l,onClick:n,onMouseDown:Eg,onPointerDownCapture:Dg,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 Eg(e){return e.preventDefault()}function Dg(e){e.preventDefault()}var Og={phase:`idle`,isWorking:!1,isBusy:!1,isCooldown:!1},kg=e=>e.hasPendingAssistant?e.messages.some(e=>e.role===`assistant`&&typeof e.time?.completed==`number`):!1;function Ag(e,t){let n=(0,Q.c)(6),r=Pi(e??``,t),i=Cr(e??``,t),a=mr(e??``,t),o=Sr(e??``,t),s=ai(e??``,t),c=jr(t),l;bb0:{if(!e){l=Og;break bb0}if(o.length>0||s.length>0){l=Og;break bb0}let t=r?.type??`idle`,u=a[a.length-1],d=!!(u&&u.role===`assistant`&&typeof u.time?.completed!=`number`),f=a,p;n[0]!==d||n[1]!==f?(p=kg({messages:f,hasPendingAssistant:d}),n[0]=d,n[1]=f,n[2]=p):p=n[2];let m=p,h=u?.time?.created,g=!!(m&&typeof c==`number`&&typeof h==`number`&&h<=c),_=r!==void 0,v=_&&t!==`idle`,y=v||m&&!g;if(_&&!v&&(!m||_&&!v&&typeof i==`number`&&typeof h==`number`&&h<=i)){l=Og;break bb0}if(!y){l=Og;break bb0}let b=v?t:`busy`,x=t===`busy`||!v&&m,S;n[3]!==b||n[4]!==x?(S={phase:b,isWorking:!0,isBusy:x,isCooldown:!1},n[3]=b,n[4]=x,n[5]=S):S=n[5],l=S}return l}var jg=e=>e.nativeEvent.isComposing||e.nativeEvent.keyCode===229;function Mg(e){let t=(0,Q.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:r,children:n,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===r?a=t[5]:(a=Y(`inline-flex shrink-0 items-center justify-center rounded-full bg-foreground text-background`,r),t[4]=r,t[5]=a);let o;return t[6]!==n||t[7]!==i||t[8]!==a?(o=(0,$.jsx)(`span`,{className:a,...i,"aria-hidden":!0,children:n}),t[6]=n,t[7]=i,t[8]=a,t[9]=o):o=t[9],o}function Ng(e){let t=(0,Q.c)(7),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(`span`,{"data-stop-glyph":`true`,className:`block size-[38%] rounded-[20%] bg-current`}),t[3]=i):i=t[3];let a;return t[4]!==n||t[5]!==r?(a=(0,$.jsx)(Mg,{className:n,...r,children:i}),t[4]=n,t[5]=r,t[6]=a):a=t[6],a}function Pg(e){let t=(0,Q.c)(13),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,spinning:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i!==void 0&&i,o=a?`loader-4`:`arrow-up`,s=a?`size-[50%] animate-spin`:`size-[56%]`,c;t[4]===s?c=t[5]:(c=Y(s),t[4]=s,t[5]=c);let l;t[6]!==o||t[7]!==c?(l=(0,$.jsx)(X,{name:o,weight:`medium`,className:c}),t[6]=o,t[7]=c,t[8]=l):l=t[8];let u;return t[9]!==n||t[10]!==r||t[11]!==l?(u=(0,$.jsx)(Mg,{className:n,...r,children:l}),t[9]=n,t[10]=r,t[11]=l,t[12]=u):u=t[12],u}var Fg=e=>!(!e.sessionId||e.composerSurfaceKind===`secondary`||e.hasSessionEntity||e.hasRenderableSessionSnapshot),Ig=e=>{let t=e.isSubagentSession&&!e.allowPromptingSubagentSessions;return{showReadOnlyBanner:e.isSubagentSession&&(e.readOnly||t),blockSubmission:e.sessionIdentityPending}},Lg=(e,t)=>({agentName:t.agentName??e?.agentName,providerId:t.providerId??e?.providerId,modelId:t.modelId??e?.modelId}),Rg=(e,t)=>e.id===t.id&&e.directory===t.directory,zg=(e,t)=>e.agentName===t.agentName&&e.providerId===t.providerId&&e.modelId===t.modelId,Bg=(e,t,n,r)=>{if(!t)return null;let i=n??(e?.viewKey===t?e.parentTarget:null);if(!i)return null;let a=Lg(e?.viewKey===t?e.execution:void 0,r);return e&&e.viewKey===t&&Rg(e.parentTarget,i)&&zg(e.execution,a)?e:{viewKey:t,parentTarget:i,execution:a}},Vg=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`}},Hg=`data-mobile-overlay-active`,Ug=e=>Array.from(e).some(e=>e.getAttribute(Hg)!==`false`),Wg=`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(`.`),Gg=`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 Kg(){return`${Wg[Math.floor(Math.random()*Wg.length)]}-${Gg[Math.floor(Math.random()*Gg.length)]}`}function qg(e){let t=Kg();return e&&e.trim()?`${e.trim().replace(/\/+$/,``)}/${t}`:t}var Jg=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||e,Yg=e=>({agentName:e.currentAgentName,providerId:e.currentProviderId,modelId:e.currentModelId,variant:e.currentVariant}),Xg=(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))},Zg=async(e,t)=>{await Gn(e)&&await Ur(t)},Qg=e=>{let t=Jg(e),n=kt.getState().projects;if(n.length===0)return null;let r=kt.getState().getActiveProject();if(r?.path){let e=Jg(r.path);if(t===e||t.startsWith(`${e}/`))return{id:r.id,path:r.path}}let i=n.filter(e=>{let n=Jg(e.path);return t===n||t.startsWith(`${n}/`)}).sort((e,t)=>Jg(t.path).length-Jg(e.path).length)[0];return i?{id:i.id,path:i.path}:null},$g=!1,e_=async(e,t)=>{try{let n=kt.getState().projects.find(e=>e.id===t.id)??kt.getState().projects.find(e=>Jg(e.path)===Jg(t.path)),r=Di(t.path);await br.getState().activateDirectory(t.path,{source:`worktreeSessionCreator`});let i=br.getState();if(i.activeDirectoryKey!==r||i.providers.length===0||i.agents.length===0)return;i.applyDefaultModelAgentSelection({projectDefaultModel:n?.defaultModel??void 0}),Xg(e,Yg(br.getState()),rn.getState())}catch{}},t_=async(e,t,n)=>{let r=ni.getState(),i=br.getState();r.initializeNewOpenChamberSession(e,i.agents),r.setSessionDirectory(e,t.path),r.setWorktreeMetadata(e,t),await e_(e,n),we.getState().setDirectory(t.path,{showOverlay:!1})},n_=e=>e.trim().replace(/^remotes\//,``).replace(/[^A-Za-z0-9._/-]+/g,`-`).replace(/\/+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`worktree`,r_=async e=>{if($g)return null;let t=kt.getState().getActiveProject(),n=e?.projectDirectory?.trim()||t?.path;if(!n)return In.error(`No active project`,{description:`Please select a project first.`}),null;let r=Qg(n)??(t?.path?{id:t.id,path:t.path}:null);if(!r)return In.error(`No active project`,{description:`Please select a project first.`}),null;let i=!1;try{i=await ua(r.path)}catch{}if(!i)return In.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;$g=!0;try{let t=hr(),n=e?.existingBranch?.trim().replace(/^remotes\//,``)||``,i=n?n_(n):qg(),a=n?`existing`:`new`,o=ni.getState();o.newSessionDraft?.open?o.overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:o.newSessionDraft.directoryOverride??r.path,pendingWorktreeRequestId:t,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}):o.openNewSessionDraft({selectedProjectId:r.id,directoryOverride:r.path,pendingWorktreeRequestId:t,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt});let s=await la(r.path,{mode:a,...a===`new`?{branchName:i,worktreeName:i}:{existingBranch:n,worktreeName:i}}).catch(()=>null);s?.path&&(ni.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:s.path,pendingWorktreeRequestId:t,bootstrapPendingDirectory:s.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),we.getState().setDirectory(s.path,{showOverlay:!1}));let c=await yt(r),l=await Jo(r,{preferredName:i,mode:a,worktreeName:i,setupCommands:c,returnAfterDirectoryCreated:!0,...a===`new`?{branchName:i}:{existingBranch:n}});return Ai(t,l.path),ni.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:l.path,pendingWorktreeRequestId:null,bootstrapPendingDirectory:l.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),we.getState().setDirectory(l.path,{showOverlay:!1}),l.path}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree`,n=ni.getState().newSessionDraft.pendingWorktreeRequestId;return n&&(gi(n,e instanceof Error?e:Error(t)),ni.getState().resolvePendingDraftWorktreeTarget(n,null)),ni.getState().setDraftBootstrapPendingDirectory(null),In.error(`Failed to create worktree`,{description:t}),null}finally{$g=!1}};async function i_(){return r_()}async function a_(e){let t=e.branch?.trim();return t?r_({existingBranch:t,projectDirectory:e.projectDirectory,initialPrompt:e.initialPrompt,title:e.title}):null}async function o_(e,t,n,r){if($g)return null;$g=!0;try{let i=n?.trim()||`HEAD`,a=t?.trim();if(!a)throw Error(`Branch name is required`);let o=r?.kind??`standard`,s=Qg(e);if(!s)throw Error(`Project is not registered in OpenChamber`);let c=!1;try{c=await ua(s.path)}catch{}if(!c)return In.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;let l=await yt(s),u=await ka(s.path);try{let e=await Jo(s,{preferredName:a,mode:`new`,branchName:a,worktreeName:r?.worktreeName||a,startRef:i,setUpstream:r?.setUpstream,upstreamRemote:r?.upstreamRemote,upstreamBranch:r?.upstreamBranch,ensureRemoteName:r?.ensureRemoteName,ensureRemoteUrl:r?.ensureRemoteUrl,setupCommands:l,returnAfterDirectoryCreated:r?.returnAfterDirectoryCreated}),t={...e,createdFromBranch:r?.createdFromBranch||u||i,kind:o};await Zg(s,e.path);let n=await ni.getState().createSession(void 0,e.path);if(!n)throw await ja(s,e,{deleteLocalBranch:!0}).catch(()=>void 0),Error(`Could not create a session for the worktree.`);return await t_(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 In.error(`Failed to create worktree`,{description:t}),null}}finally{$g=!1}}var s_=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},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)}`};function l_({open:e,onOpenChange:t,mode:n=`createSession`,onSelect:r}){let{t:i}=ot(),{github:a}=Do(),o=eo(),c=o.data??null,l=o.isFetched,u=s(e=>e.setSettingsDialogOpen),d=s(e=>e.setSettingsPage),f=s(e=>e.isMobile),{isTablet:p}=fo(),m=f||p,h=kt(e=>e.getActiveProject()),g=we(e=>e.currentDirectory),_=Z.useMemo(()=>h?.path?.trim()||g?.trim()||null,[h?.path,g]),[v,y]=Z.useState(``),[b,x]=Z.useState(!1),[S,C]=Z.useState(null),w=Z.useRef(0),T=Z.useMemo(()=>s_(v),[v]),E=zo(v,350),D=T?``:E.trim(),O=!!T||v===E,k=e&&O&&!!_&&!!a?.issuesList&&!(l&&c?.connected===!1),A=Je({queryKey:I.scoped(`github-issues`,_,D),enabled:k,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>a.issuesList(_,{page:e,...D?{query:D}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),j=O?A.data?.pages.at(-1)??null:null,M=O?A.data?.pages.flatMap(e=>e.issues??[])??[]:[],N=O&&A.hasNextPage,P=!T&&!O||A.isLoading,F=O&&A.isFetchingNextPage,L=O&&A.error?A.error instanceof Error?A.error.message:String(A.error):null,R=Z.useCallback(()=>A.refetch(),[A]),z=Z.useCallback(async()=>{try{await A.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);In.error(i(`session.githubIssuePicker.toast.loadMoreFailed`),{description:t})}},[A,i]);Z.useEffect(()=>{e||(++w.current,y(``),x(!1),C(null))},[e]),Z.useEffect(()=>{++w.current},[e,_]);let B=!l||c?.connected!==!1&&j?.connected!==!1,V=j?.repo?.url??null,H=Z.useCallback(()=>{d(`github`),u(!0)},[u,d]),U=Z.useCallback(()=>{let e=br.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=br.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=Ut(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=br.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(!_){In.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){In.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){In.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){In.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let s=n.issue;if(!s){In.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let l=await a.issueComments(_,e,{sourceRepo:o});if(!c())return;if(l.connected===!1){In.error(i(`session.githubIssuePicker.error.notConnected`));return}let u=l.comments??[],d=c_({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);In.error(i(`session.githubIssuePicker.toast.loadIssueDetailsFailed`),{description:t})}finally{c()&&C(null)}return}if(!_){In.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){In.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){In.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){In.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let r=n.issue;if(!r){In.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let s=await a.issueComments(_,e,{sourceRepo:o});if(!c())return;if(s.connected===!1){In.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}-${Kg()}`,t=await o_(_,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 Hn(u,_,null);if(!e?.id)throw Error(`Failed to create session`);return{sessionId:e.id,sessionDirectory:e.directory??_}})();if(!c())return;di(d,u).catch(()=>void 0);try{ni.getState().initializeNewOpenChamberSession(d,br.getState().agents)}catch{}t(!1);let f=br.getState(),p=rn.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){In.error(i(`session.githubIssuePicker.error.noModelSelected`));return}let y=ee(h,g),x=await Tr(`github.issue.review.visible`,{issue_number:String(r.number)});if(!c())return;let S=await Tr(`github.issue.review.instructions`);if(!c())return;let C=c_({repo:n.repo,issue:r,comments:l});ni.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);In.error(i(`session.githubIssuePicker.toast.sendContextFailed`),{description:t})}),In.success(i(`session.githubIssuePicker.toast.sessionCreated`))}catch(e){if(!c())return;let t=e instanceof Error?e.message:String(e);In.error(i(`session.githubIssuePicker.toast.startSessionFailed`),{description:t})}finally{c()&&C(null)}}},[b,a,n,t,r,_,U,W,ee,S,i]),K=i(n===`select`?`session.githubIssuePicker.title.select`:`session.githubIssuePicker.title.createSession`),q=i(n===`select`?`session.githubIssuePicker.description.select`:`session.githubIssuePicker.description.createSession`),te=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Fa,{placeholder:i(`session.githubIssuePicker.searchPlaceholder`),value:v,onChange:e=>{y(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`div`,{className:Y(f?`min-h-0 mt-2`:`flex-1 overflow-y-auto mt-2`),children:[_?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:i(`session.githubIssuePicker.empty.noActiveProject`)}),a?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:i(`session.githubIssuePicker.empty.runtimeUnavailable`)}),P?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 flex items-center justify-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),i(`session.githubIssuePicker.loading.issues`)]}):null,B===!1?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 space-y-3`,children:[(0,$.jsx)(`div`,{children:i(`session.githubIssuePicker.empty.notConnected`)}),(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsx)(ca,{variant:`outline`,size:`sm`,onClick:H,children:i(`session.githubIssuePicker.actions.openSettings`)})})]}):null,L?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:L}):null,T&&_&&a&&B?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,S===T&&`bg-interactive-selection/30`),onClick:()=>void G(T),children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground w-5 text-right flex-shrink-0`,children:`#`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 typography-small text-foreground truncate ml-0.5`,children:i(`session.githubIssuePicker.actions.useIssue`,{number:T})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:S===T?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,M.length===0&&!P&&!L&&B&&a&&_?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:E.trim()?i(`session.githubIssuePicker.empty.noIssuesFound`):i(`session.githubIssuePicker.empty.noOpenIssuesFound`)}):null,M.map(e=>(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,S===e.number&&`bg-interactive-selection/30`),onClick:()=>void G(e.number,e.sourceRepo),children:[(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground w-12 text-right flex-shrink-0`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 ml-0.5`,children:[(0,$.jsx)(`p`,{className:`typography-small text-foreground truncate`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:S===e.number?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:Y(`h-5 w-5 items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,m?`flex`:`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),"aria-label":i(`session.githubIssuePicker.actions.openInGitHubAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4`})})})]},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)),N&&B&&_&&a?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void z(),disabled:F||!!S,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(F||!!S)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:F?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),i(`session.githubIssuePicker.loading.more`)]}):i(`session.githubIssuePicker.actions.loadMore`)})}):null]}),n!==`select`&&(0,$.jsxs)(`div`,{className:`mt-4 p-3 bg-muted/30 rounded-lg`,children:[(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground font-medium mb-2`,children:i(`session.githubIssuePicker.actions.sectionTitle`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 cursor-pointer`,role:`button`,tabIndex:0,"aria-pressed":b,onClick:()=>x(e=>!e),onKeyDown:e=>{(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),x(e=>!e))},children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),x(e=>!e)},"aria-label":i(`session.githubIssuePicker.actions.toggleWorktreeAria`),className:`flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,children:b?(0,$.jsx)(X,{name:`checkbox`,className:`h-4 w-4 text-primary`}):(0,$.jsx)(X,{name:`checkbox-blank`,className:`h-4 w-4`})}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:i(`session.githubIssuePicker.actions.createInWorktree`)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/70 hidden sm:inline`,children:`(issue-<number>-<slug>)`})]}),(0,$.jsx)(`div`,{className:`hidden sm:block sm:flex-1`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[V?(0,$.jsx)(ca,{variant:`outline`,size:`sm`,asChild:!0,children:(0,$.jsxs)(`a`,{href:V,target:`_blank`,rel:`noopener noreferrer`,children:[(0,$.jsx)(X,{name:`external-link`,className:`size-4`}),i(`session.githubIssuePicker.actions.openRepo`)]})}):null,(0,$.jsx)(ca,{variant:`outline`,size:`sm`,onClick:R,disabled:P||!!S,children:i(`session.githubIssuePicker.actions.refresh`)})]})]})]})]});return f?(0,$.jsx)(rm,{open:e,title:K,onClose:()=>t(!1),renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:K}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:q})]}),children:te}):(0,$.jsx)(aa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ta,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(Qi,{className:`flex-shrink-0`,children:[(0,$.jsxs)(na,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),K]}),(0,$.jsx)(ra,{children:q})]}),te]})})}var u_=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},d_=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function f_({open:e,onOpenChange:t,onSelect:n}){let{t:r}=ot(),{github:i}=Do(),a=eo(),o=a.data??null,c=a.isFetched,l=s(e=>e.setSettingsDialogOpen),u=s(e=>e.setSettingsPage),d=s(e=>e.isMobile),{isTablet:f}=fo(),p=d||f,m=kt(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(()=>u_(h),[h]),C=zo(h,350),w=S?``:C.trim(),T=!!S||h===C,E=e&&T&&!!m&&!!i?.prsList&&!(c&&o?.connected===!1),D=Je({queryKey:I.scoped(`github-prs`,m,w),enabled:E,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>i.prsList(m,{page:e,...w?{query:w}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),O=T?D.data?.pages.at(-1)??null:null,k=T?D.data?.pages.flatMap(e=>e.prs??[])??[]:[],A=T&&D.hasNextPage,j=!S&&!T||D.isLoading,M=T&&D.isFetchingNextPage,N=T&&D.error?D.error instanceof Error?D.error.message:String(D.error):null,P=J(async()=>{try{await D.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);In.error(r(`session.githubPrPicker.toast.loadMoreFailed`),{description:t})}});Z.useEffect(()=>{e||(++x.current,g(``),v(!1),b(null))},[e]),Z.useEffect(()=>{++x.current},[e,m]);let F=!c||o?.connected!==!1&&O?.connected!==!1,L=J(()=>{u(`github`),l(!0)}),R=J(async(e,a)=>{if(!m){In.error(r(`session.githubPrPicker.error.noActiveProject`));return}if(!i?.prContext){In.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){In.error(r(`session.githubPrPicker.error.notConnected`));return}if(!o.pr){In.error(r(`session.githubPrPicker.error.prNotFound`));return}if(!o.repo){In.error(r(`session.githubPrPicker.error.repoNotResolvable`),{description:r(`session.githubPrPicker.error.repoMustBeGithub`)});return}if(n){let e=await Tr(`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:d_(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);In.error(r(`session.githubPrPicker.toast.loadDetailsFailed`),{description:t})}finally{s()&&b(null)}}),z=r(`session.githubPrPicker.title`),B=r(`session.githubPrPicker.description`),V=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1 min-w-0`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Fa,{placeholder:r(`session.githubPrPicker.searchPlaceholder`),value:h,onChange:e=>{g(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>v(e=>!e),className:`h-9 shrink-0 flex items-center gap-2 text-left`,"aria-pressed":_,"aria-label":r(`session.githubPrPicker.includeDiffAria`),children:[(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(ga,{checked:_,onChange:e=>v(e),ariaLabel:r(`session.githubPrPicker.includeDiffAria`)})}),(0,$.jsx)(`span`,{className:`typography-small text-muted-foreground whitespace-nowrap`,children:r(`session.githubPrPicker.includeDiff`)})]})]}),(0,$.jsxs)(`div`,{className:Y(d?`min-h-0`:`flex-1 overflow-y-auto`),children:[m?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:r(`session.githubPrPicker.empty.noActiveProject`)}),i?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:r(`session.githubPrPicker.empty.runtimeUnavailable`)}),j?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 flex items-center justify-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),r(`session.githubPrPicker.loading.pullRequests`)]}):null,F===!1?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 space-y-3`,children:[(0,$.jsx)(`div`,{children:r(`session.githubPrPicker.empty.notConnected`)}),(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsx)(ca,{variant:`outline`,size:`sm`,onClick:L,children:r(`session.githubPrPicker.actions.openSettings`)})})]}):null,N?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:N}):null,S&&m&&i&&F?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,y===S&&`bg-interactive-selection/30`),onClick:()=>void R(S),children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground w-5 text-right flex-shrink-0`,children:`#`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 typography-small text-foreground truncate ml-0.5`,children:r(`session.githubPrPicker.actions.usePullRequest`,{number:S})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:y===S?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,k.length===0&&!j&&!N&&F&&i&&m?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:C.trim()?r(`session.githubPrPicker.empty.noPullRequestsFound`):r(`session.githubPrPicker.empty.noOpenPullRequestsFound`)}):null,k.map(e=>(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,y===e.number&&`bg-interactive-selection/30`),onClick:()=>void R(e.number,e.sourceRepo),children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 ml-0.5`,children:[(0,$.jsxs)(`p`,{className:`typography-small text-foreground truncate`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground mr-1`,children:[`#`,e.number]}),e.title]}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,(0,$.jsxs)(`p`,{className:`typography-meta text-muted-foreground truncate`,children:[e.head,` → `,e.base]})]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:y===e.number?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:Y(`h-5 w-5 items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,p?`flex`:`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),"aria-label":r(`session.githubPrPicker.actions.openInGitHubAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4`})})})]},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)),A&&F&&m&&i?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void P(),disabled:M||!!y,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(M||!!y)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:M?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),r(`session.githubPrPicker.loading.more`)]}):r(`session.githubPrPicker.actions.loadMore`)})}):null]})]});return d?(0,$.jsx)(rm,{open:e,title:z,onClose:()=>t(!1),renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:z}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:B})]}),children:V}):(0,$.jsx)(aa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ta,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(Qi,{className:`flex-shrink-0`,children:[(0,$.jsxs)(na,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),z]}),(0,$.jsx)(ra,{children:B})]}),V]})})}function p_(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)(Wc,{"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 m_=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)(Wc.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});m_.displayName=`CommandInput`;function h_(e){let t=(0,Q.c)(14),n,r,i,a,o;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5]):({className:r,children:n,scrollbarClassName:o,disableHorizontal:i,...a}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o);let s;t[6]===r?s=t[7]:(s=Y(`scroll-py-1 overflow-x-hidden h-full min-h-0`,r),t[6]=r,t[7]=s);let c=o??`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,l=i??!0,u;return t[8]!==n||t[9]!==a||t[10]!==s||t[11]!==c||t[12]!==l?(u=(0,$.jsx)(da,{as:Wc.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 g_(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)(Wc.Empty,{"data-slot":`command-empty`,className:`py-6 text-center typography-ui-label`,...n}),t[2]=n,t[3]=r),r}function __(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)(Wc.Group,{"data-slot":`command-group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function v_(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Y(`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)(Wc.Separator,{"data-slot":`command-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function y_(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Y(`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)(Wc.Item,{"data-slot":`command-item`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var b_=(e,t)=>`${e}:${T(t)}`,x_=e=>e.type===`skill`||!oe(e.name);function S_(e){let{t}=ot(),n=Z.useMemo(()=>d(),[]),r=s(e=>e.globalDraftStarters),i=kt(e=>e.activeProjectId),a=kt(e=>e.projects),o=Z.useMemo(()=>{if(!i)return null;let e=a.find(e=>e.id===i);return e?.path?{id:e.id,path:e.path}:null},[i,a]),[c,l]=Z.useState([]),u=Z.useMemo(()=>r??se,[r]),f=u.some(x_)||c.some(x_),m=Pt({directory:e,enabled:f}),h=Z.useMemo(()=>m.data??[],[m.data]),{refetch:g}=m,_=Fi({directory:e,enabled:f}),v=Z.useMemo(()=>_.data??[],[_.data]),{refetch:y}=_;Z.useEffect(()=>{let e=!1;if(!o){l([]);return}return Xi(o).then(t=>{e||l(t)}).catch(()=>{e||l([])}),()=>{e=!0}},[o?.id]);let b=Z.useCallback(()=>{g(),y()},[g,y]),x=Z.useMemo(()=>new Set(h.map(e=>e.name)),[h]),S=Z.useMemo(()=>new Set(v.map(e=>e.name)),[v]),C=Z.useCallback((e,r)=>{if(n&&e.type===`command`&&e.name===`craft-goal`)return null;if(e.type===`command`){let n=oe(e.name);return n?{id:b_(r,e),ref:e,group:r,label:t(n.labelKey),icon:n.icon,submitText:n.command}:x.has(e.name)?{id:b_(r,e),ref:e,group:r,label:w(e.name),icon:ie,submitText:`/${e.name}`}:null}return S.has(e.name)?{id:b_(r,e),ref:e,group:r,label:w(e.name),icon:P,submitText:`/${e.name}`}:null},[t,x,S,n]),E=Z.useMemo(()=>u.map(e=>C(e,`global`)).filter(e=>e!==null),[u,C]),D=Z.useMemo(()=>c.map(e=>C(e,`project`)).filter(e=>e!==null),[c,C]),O=Z.useMemo(()=>{let e=new Set;for(let t of u)e.add(T(t));for(let t of c)e.add(T(t));return e},[u,c]),k=Z.useMemo(()=>{let e=[];for(let r of M)n&&r.name===`craft-goal`||e.push({type:`command`,name:r.name,label:t(r.labelKey),icon:r.icon,section:`built-in`,scope:`user`});for(let t of h)t.isBuiltIn||t.source===`skill`||oe(t.name)||e.push({type:`command`,name:t.name,label:w(t.name),icon:ie,section:`command`,scope:t.scope===`project`?`project`:`user`});for(let t of v)e.push({type:`skill`,name:t.name,label:w(t.name),icon:P,section:`skill`,scope:t.scope===`project`?`project`:`user`});return e.filter(e=>!O.has(`${e.type}:${e.name}`))},[t,h,v,O,n]),A=Z.useCallback(e=>{s.getState().setGlobalDraftStarters(e),q({draftStarters:e})},[]),j=Z.useCallback(e=>{l(e),o&&on(o,e)},[o]),N=Z.useCallback(e=>{let t={type:e.type,name:e.name};if(e.scope===`project`){if(!o||c.some(e=>p(e,t)))return;j([...c,t])}else{let e=r??se;if(e.some(e=>p(e,t)))return;A([...e,t])}},[o,c,r,j,A]),F=Z.useCallback((e,t)=>{e===`project`?j(c.filter(e=>!p(e,t))):A((r??se).filter(e=>!p(e,t)))},[c,r,j,A]),I=Z.useCallback((e,t,n)=>{let i=e===`project`?c:r??se,a=i.findIndex(n=>b_(e,n)===t),o=i.findIndex(t=>b_(e,t)===n);if(a<0||o<0||a===o)return;let s=Xs([...i],a,o);e===`project`?j(s):A(s)},[c,r,j,A]);return{global:E,project:D,pinnable:k,hasProject:!!o,ensureLoaded:b,addStarter:N,removeStarter:F,reorder:I}}var C_=`__draft-starter-trash__`,w_=`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`,T_=`max-h-7`,E_=[{key:`built-in`,headingKey:`chat.draftStarters.sectionBuiltIn`},{key:`command`,headingKey:`chat.draftStarters.sectionCommands`},{key:`skill`,headingKey:`chat.draftStarters.sectionSkills`}],D_=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}=Zs(s),m;t[2]===d?m=t[3]:(m=Js.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},O_=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(N_),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)(D_,{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)($s,{items:o,strategy:Ys,children:s}),t[11]=o,t[12]=s,t[13]=c):c=t[13],c},k_=()=>{let e=(0,Q.c)(13),{t}=ot(),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={id:C_},e[0]=n):n=e[0];let{setNodeRef:r,isOver:i}=Us(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(w_,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},A_=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)(m_,{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)(g_,{children:l}),t[8]=l,t[9]=u);let d;t[10]!==r||t[11]!==n||t[12]!==a?(d=E_.map(e=>{let t=n.filter(t=>t.section===e.key);return t.length===0?null:(0,$.jsx)(__,{heading:a(e.headingKey),children:t.map(e=>(0,$.jsx)(y_,{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)(h_,{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)(p_,{className:o,children:[c,f]}),t[17]=o,t[18]=c,t[19]=f,t[20]=p):p=t[20],p},j_=e=>{let t=(0,Q.c)(27),{pinnable:n,onOpen:r,onAdd:i}=e,{t:a}=ot(),[o,s]=Z.useState(!1),c;t[0]===r?c=t[1]:(c=e=>{s(e),e&&r()},t[0]=r,t[1]=c);let l;t[2]===a?l=t[3]:(l=a(`chat.draftStarters.add`),t[2]=a,t[3]=l);let u;t[4]===a?u=t[5]:(u=a(`chat.draftStarters.add`),t[4]=a,t[5]=u);let d;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(X,{name:`add`,className:`h-3.5 w-3.5`}),t[6]=d):d=t[6];let f;t[7]!==l||t[8]!==u?(f=(0,$.jsx)(ia,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:u,className:w_,children:d})}),t[7]=l,t[8]=u,t[9]=f):f=t[9];let p;t[10]===a?p=t[11]:(p=a(`chat.draftStarters.add`),t[10]=a,t[11]=p);let m;t[12]===p?m=t[13]:(m=(0,$.jsx)(Qi,{className:`px-4 pb-2 pt-4 text-left`,children:(0,$.jsx)(na,{children:p})}),t[12]=p,t[13]=m);let h;t[14]===i?h=t[15]:(h=e=>{i(e),s(!1)},t[14]=i,t[15]=h);let g;t[16]!==n||t[17]!==h?(g=(0,$.jsx)(A_,{pinnable:n,onPick:h,className:`flex max-h-[60vh] flex-col`}),t[16]=n,t[17]=h,t[18]=g):g=t[18];let _;t[19]!==m||t[20]!==g?(_=(0,$.jsxs)(ta,{className:`gap-0 overflow-hidden p-0 sm:max-w-sm`,children:[m,g]}),t[19]=m,t[20]=g,t[21]=_):_=t[21];let v;return t[22]!==o||t[23]!==c||t[24]!==_||t[25]!==f?(v=(0,$.jsxs)(aa,{open:o,onOpenChange:c,children:[f,_]}),t[22]=o,t[23]=c,t[24]=_,t[25]=f,t[26]=v):v=t[26],v},M_=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}=S_(cc()),{isMobile:f}=fo(),[p,m]=Z.useState(!1),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),y=Z.useRef(null),b;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(b={activationConstraint:{distance:8}},t[0]=b):b=t[0];let x;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(x={activationConstraint:{delay:200,tolerance:6}},t[1]=x):x=t[1];let S=qs(Bs(Gs,b),Bs(Hs,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)===C_){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:Vs.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&&T_,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)(O_,{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)(O_,{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(P_),"aria-expanded":h,"aria-label":i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),title:i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),className:w_,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)(k_,{}):(0,$.jsx)(j_,{pinnable:s,onOpen:c,onAdd:l}),t[46]=l,t[47]=c,t[48]=p,t[49]=f,t[50]=s,t[51]=G):G=t[51];let K;t[52]!==ee||t[53]!==G?(K=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 self-start`,children:[ee,G]}),t[52]=ee,t[53]=G,t[54]=K):K=t[54];let q;t[55]!==R||t[56]!==W||t[57]!==K?(q=(0,$.jsxs)(`div`,{className:R,children:[W,K]}),t[55]=R,t[56]=W,t[57]=K,t[58]=q):q=t[58];let te;return t[59]!==F||t[60]!==S||t[61]!==q?(te=(0,$.jsx)(Ks,{sensors:S,collisionDetection:Ws,measuring:L,onDragStart:j,onDragCancel:N,onDragEnd:F,children:q}),t[59]=F,t[60]=S,t[61]=q,t[62]=te):te=t[62],te};function N_(e){return e.id}function P_(e){return!e}var F_=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});F_.displayName=`ChatComposerSurface`;var I_=Z.forwardRef((e,t)=>{let n=(0,Q.c)(3),r;return n[0]!==e||n[1]!==t?(r=(0,$.jsx)(Oa,{ref:t,...e}),n[0]=e,n[1]=t,n[2]=r):r=n[2],r});I_.displayName=`ChatPromptTextarea`;var L_=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},R_=(e,t)=>{typeof e==`function`?e(t):e&&(e.current=t)},z_=e=>{let t=(0,Q.c)(141),n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M,N,P,F,I,L,R,z,B;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5],s=t[6],c=t[7],l=t[8],u=t[9],d=t[10],f=t[11],p=t[12],m=t[13],h=t[14],g=t[15],_=t[16],v=t[17],y=t[18],b=t[19],x=t[20],S=t[21],C=t[22],w=t[23],T=t[24],E=t[25],D=t[26],O=t[27],k=t[28],A=t[29],j=t[30],M=t[31],N=t[32],P=t[33],F=t[34],I=t[35],L=t[36],R=t[37],z=t[38],B=t[39]):({value:B,attachments:j,disabled:M,pending:N,placeholder:T,isMobile:P,onChange:x,onSubmit:w,onStop:C,onAddFiles:b,onRemoveAttachment:S,addFilesLabel:n,removeAttachmentLabel:E,sendLabel:O,stopLabel:k,hint:f,leftControls:y,rightControls:D,footerContent:c,inputHeader:m,attachmentContent:r,highlightedContent:d,highlightRef:u,inputRef:g,textareaProps:z,textLayoutClassName:R,inputClassName:p,inputOuterClassName:h,inputStyle:v,footerClassName:s,footerStyle:l,contentClassName:o,inputSectionClassName:_,autoResize:F,disableInputWhilePending:I,children:i,className:a,expanded:L,...A}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o,t[6]=s,t[7]=c,t[8]=l,t[9]=u,t[10]=d,t[11]=f,t[12]=p,t[13]=m,t[14]=h,t[15]=g,t[16]=_,t[17]=v,t[18]=y,t[19]=b,t[20]=x,t[21]=S,t[22]=C,t[23]=w,t[24]=T,t[25]=E,t[26]=D,t[27]=O,t[28]=k,t[29]=A,t[30]=j,t[31]=M,t[32]=N,t[33]=P,t[34]=F,t[35]=I,t[36]=L,t[37]=R,t[38]=z,t[39]=B);let V=j===void 0?[]:j,H=M!==void 0&&M,U=N!==void 0&&N,W=P!==void 0&&P,ee=F===void 0||F,G=I===void 0||I,K=L!==void 0&&L,q=Z.useRef(null),te=Z.useRef(null),ne;t[40]!==ee||t[41]!==K||t[42]!==z?.fillContainer?(ne=()=>{if(!ee||K||z?.fillContainer)return;let e=q.current;if(!e)return;e.style.height=`auto`;let t=Number.parseFloat(window.getComputedStyle(e).maxHeight),n=Number.isFinite(t)?Math.min(e.scrollHeight,t):e.scrollHeight;e.style.height=`${n}px`,e.style.overflowY=Number.isFinite(t)&&e.scrollHeight>t?`auto`:`hidden`},t[40]=ee,t[41]=K,t[42]=z?.fillContainer,t[43]=ne):ne=t[43];let re=z?.fillContainer,ie;t[44]!==ee||t[45]!==K||t[46]!==re||t[47]!==B?(ie=[ee,K,re,B],t[44]=ee,t[45]=K,t[46]=re,t[47]=B,t[48]=ie):ie=t[48],Z.useLayoutEffect(ne,ie);let ae;t[49]!==G||t[50]!==H||t[51]!==w||t[52]!==U||t[53]!==z?(ae=e=>{z?.onKeyDown?.(e),!(e.defaultPrevented||jg(e))&&e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),!H&&(!U||!G)&&w())},t[49]=G,t[50]=H,t[51]=w,t[52]=U,t[53]=z,t[54]=ae):ae=t[54];let oe=ae,se;t[55]===b?se=t[56]:(se=e=>{b?.(e.target.files),e.target.value=``},t[55]=b,t[56]=se);let ce=se,le=B.trim().length>0||V.length>0,ue=V.filter(B_),de;t[57]!==n||t[58]!==H||t[59]!==ce||t[60]!==b||t[61]!==U?(de=b?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{ref:te,type:`file`,accept:`image/*`,multiple:!0,className:`hidden`,onChange:ce}),(0,$.jsx)(`button`,{type:`button`,className:`flex size-8 shrink-0 items-center justify-center rounded-md text-foreground outline-none hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-40`,onClick:()=>te.current?.click(),disabled:H||U,"aria-label":n,children:(0,$.jsx)(X,{name:`attachment-2`,className:`size-[18px]`})})]}):null,t[57]=n,t[58]=H,t[59]=ce,t[60]=b,t[61]=U,t[62]=de):de=t[62];let fe=de,pe=!H&&!U&&le,me;t[63]!==H||t[64]!==le||t[65]!==W||t[66]!==C||t[67]!==U||t[68]!==O||t[69]!==pe||t[70]!==k?(me=U&&C?(0,$.jsx)(`button`,{type:`button`,"data-composer-stop":`true`,className:`flex size-8 shrink-0 items-center justify-center rounded-full outline-none hover:opacity-80`,onClick:C,"aria-label":k,children:(0,$.jsx)(Ng,{className:W?`size-6`:`size-full`})}):(0,$.jsx)(`button`,{type:`submit`,"data-composer-send":`true`,"data-composer-circle":pe?`true`:void 0,className:Y(`flex size-8 shrink-0 items-center justify-center outline-none`,pe?`rounded-full hover:opacity-80`:`rounded-md text-primary hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-30`),disabled:H||U||!le,"aria-label":O,children:pe?(0,$.jsx)(Pg,{className:W?`size-6`:`size-full`}):(0,$.jsx)(X,{name:U?`loader-4`:`send-plane-2`,className:Y(`size-4`,U&&`animate-spin`)})}),t[63]=H,t[64]=le,t[65]=W,t[66]=C,t[67]=U,t[68]=O,t[69]=pe,t[70]=k,t[71]=me):me=t[71];let he=me,ge=F_,_e=K&&`flex-1`,ve;t[72]!==o||t[73]!==_e?(ve=Y(`relative flex min-h-0 flex-col`,_e,o),t[72]=o,t[73]=_e,t[74]=ve):ve=t[74];let ye=K&&`flex min-h-0 flex-1 flex-col`,be;t[75]!==_||t[76]!==ye?(be=Y(`overflow-hidden`,ye,_),t[75]=_,t[76]=ye,t[77]=be):be=t[77];let xe=ue.length>0?(0,$.jsx)(`div`,{className:`flex gap-2 overflow-x-auto px-3 pt-3`,"data-chat-prompt-attachments":`true`,children:ue.map(e=>(0,$.jsxs)(`div`,{className:`group relative shrink-0`,children:[(0,$.jsx)(`img`,{src:e.url,alt:e.name,className:`size-16 rounded-lg border border-border object-cover`}),S?(0,$.jsx)(`button`,{type:`button`,className:`absolute -right-1 -top-1 flex size-6 items-center justify-center rounded-full border border-border bg-[var(--surface-elevated)] shadow-sm hover:bg-[var(--interactive-hover)]`,onClick:()=>S(e.id),"aria-label":E,children:(0,$.jsx)(X,{name:`close`,className:`size-3`})}):null]},e.id))}):null,Se=K&&`flex min-h-0 flex-1 flex-col`,Ce;t[78]===Se?Ce=t[79]:(Ce=Y(`relative overflow-hidden`,Se),t[78]=Se,t[79]=Ce);let we;t[80]!==u||t[81]!==d||t[82]!==p||t[83]!==R?(we=d?(0,$.jsx)(`div`,{ref:u,"aria-hidden":!0,"data-composer-highlight":`true`,className:Y(`pointer-events-none absolute inset-0 z-0 rounded-b-none`,R,p),children:d}):null,t[80]=u,t[81]=d,t[82]=p,t[83]=R,t[84]=we):we=t[84];let Te;t[85]===g?Te=t[86]:(Te=e=>{q.current=e,R_(g,e)},t[85]=g,t[86]=Te);let Ee;t[87]===x?Ee=t[88]:(Ee=e=>x(e.target.value,e),t[87]=x,t[88]=Ee);let De=H||U&&G,Oe=W?`send`:z?.enterKeyHint,ke=K&&`min-h-0 flex-1`,Ae;t[89]!==h||t[90]!==ke?(Ae=Y(`ring-0 bg-transparent shadow-none hover:bg-transparent focus-within:ring-0`,ke,h),t[89]=h,t[90]=ke,t[91]=Ae):Ae=t[91];let je=d&&`text-transparent caret-[var(--surface-foreground)]`,Me;t[92]!==p||t[93]!==je||t[94]!==R?(Me=Y(`relative z-10 min-h-[52px] max-h-40 resize-none overflow-y-hidden appearance-none rounded-b-none border-0 bg-transparent px-3 pb-2 pt-4 typography-markdown hover:border-transparent md:typography-ui-label`,R,p,je),t[92]=p,t[93]=je,t[94]=R,t[95]=Me):Me=t[95];let Ne=z?.rows??1,Pe;t[96]!==oe||t[97]!==v||t[98]!==T||t[99]!==Te||t[100]!==Ee||t[101]!==De||t[102]!==Oe||t[103]!==Ae||t[104]!==Me||t[105]!==Ne||t[106]!==z||t[107]!==B?(Pe=(0,$.jsx)(I_,{...z,simple:!0,ref:Te,"data-chat-input":`true`,value:B,onChange:Ee,onKeyDown:oe,disabled:De,placeholder:T,enterKeyHint:Oe,outerClassName:Ae,className:Me,style:v,rows:Ne}),t[96]=oe,t[97]=v,t[98]=T,t[99]=Te,t[100]=Ee,t[101]=De,t[102]=Oe,t[103]=Ae,t[104]=Me,t[105]=Ne,t[106]=z,t[107]=B,t[108]=Pe):Pe=t[108];let Fe;t[109]!==Ce||t[110]!==we||t[111]!==Pe?(Fe=(0,$.jsxs)(`div`,{className:Ce,"data-composer-input-shell":`true`,children:[we,Pe]}),t[109]=Ce,t[110]=we,t[111]=Pe,t[112]=Fe):Fe=t[112];let Ie;t[113]!==r||t[114]!==m||t[115]!==be||t[116]!==xe||t[117]!==Fe?(Ie=(0,$.jsxs)(`div`,{className:be,children:[m,r,xe,Fe]}),t[113]=r,t[114]=m,t[115]=be,t[116]=xe,t[117]=Fe,t[118]=Ie):Ie=t[118];let Le;t[119]!==fe||t[120]!==he||t[121]!==c||t[122]!==f||t[123]!==y||t[124]!==D?(Le=c??(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:y??fe}),f?(0,$.jsx)(`div`,{className:`min-w-0 flex-1 truncate typography-micro text-muted-foreground`,children:f}):(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:D??he})]}),t[119]=fe,t[120]=he,t[121]=c,t[122]=f,t[123]=y,t[124]=D,t[125]=Le):Le=t[125];let Re;t[126]!==s||t[127]!==l||t[128]!==Le?(Re=(0,$.jsx)(L_,{className:s,style:l,children:Le}),t[126]=s,t[127]=l,t[128]=Le,t[129]=Re):Re=t[129];let ze;t[130]!==ve||t[131]!==Ie||t[132]!==Re?(ze=(0,$.jsxs)(`div`,{"data-composer-content":`true`,className:ve,children:[Ie,Re]}),t[130]=ve,t[131]=Ie,t[132]=Re,t[133]=ze):ze=t[133];let Be;return t[134]!==ge||t[135]!==i||t[136]!==a||t[137]!==K||t[138]!==A||t[139]!==ze?(Be=(0,$.jsxs)(ge,{className:a,expanded:K,...A,children:[i,ze]}),t[134]=ge,t[135]=i,t[136]=a,t[137]=K,t[138]=A,t[139]=ze,t[140]=Be):Be=t[140],Be};function B_(e){return e.mime.startsWith(`image/`)}var V_=e=>e.trim().replace(/\s+/g,`-`).replace(/[^A-Za-z0-9._/-]/g,`-`).replace(/-+/g,`-`).replace(/\/{2,}/g,`/`).replace(/\/-+/g,`/`).replace(/-+\//g,`/`).replace(/^[-/]+/,``).replace(/[-/]+$/,``),H_=({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(()=>V_(N),[N]),ee=Z.useMemo(()=>{let e=D.trim();return e?yi(t,e,e=>e).map(e=>e.item):t},[D,t]),G=Z.useMemo(()=>{let e=D.trim();return e?yi(n,e,e=>e).map(e=>e.item):n},[D,n]),K=Z.useMemo(()=>{let e=D.trim();return e?yi(m,e,e=>e.label).map(e=>e.item):m},[D,m]),q=Z.useMemo(()=>{if(!p)return!1;let e=D.trim();return!e||yi([p],e,e=>[e.label,b??``]).length>0},[b,p,D]),te=t=>{if(t===e){B(!1);return}i(t),B(!1),O(``)},ne=e=>{g?.(e),B(!1),O(``)},re=()=>{A(!0),setTimeout(()=>L.current?.focus(),50)},ie=async()=>{if(!(!W||F)){if(H){M(!0);return}I(!0);try{await a(W,o[0]),P(``),A(!1),B(!1)}finally{I(!1)}}},ae=async e=>{if(!(!W||F)){I(!0);try{await a(W,e),P(``),A(!1),M(!1),B(!1)}finally{I(!1)}}},oe=()=>{M(!1)},se=()=>{P(``),A(!1),M(!1)};Z.useEffect(()=>{z||(O(``),A(!1),M(!1),P(``))},[z]);let ce=u||e||w(`gitView.branch.detachedHead`),le=d??(c?`end`:`start`),ue=v??w(`chat.chatInput.worktrees`),de=y??w(`chat.chatInput.worktreeNew`),fe=b??w(`chat.chatInput.projectRoot`),pe=c?(0,$.jsx)(`button`,{type:`button`,className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50`,disabled:s,"aria-label":ce,children:(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5`})}):(0,$.jsxs)(ca,{variant:`ghost`,size:`xs`,className:`h-6 min-w-0 max-w-full justify-start gap-1 px-0 hover:bg-transparent`,disabled:s,"aria-label":ce,children:[(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5 text-primary`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate typography-ui-label font-semibold text-left text-foreground`,children:ce}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`size-3 shrink-0 text-muted-foreground`})]}),me=(0,$.jsx)(qa,{asChild:!0,disabled:s,children:l??pe}),he=(0,$.jsxs)(p_,{className:`h-full min-h-0`,children:[(0,$.jsx)(`div`,{"data-mobile-sheet-no-dismiss":C===`mobile-sheet`?``:void 0,children:(0,$.jsx)(m_,{placeholder:w(`gitView.branch.searchPlaceholder`),value:D,onValueChange:O,onKeyDown:V})}),(0,$.jsxs)(h_,{scrollbarClassName:`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,disableHorizontal:!0,children:[(0,$.jsx)(g_,{children:w(`gitView.branch.empty`)}),(0,$.jsx)(__,{children:j?(0,$.jsxs)(`div`,{className:`px-2 py-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:oe,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,$.jsx)(X,{name:`arrow-left`,className:`size-4`})}),(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground`,children:[w(`gitView.branch.pushToPrefix`),` `,(0,$.jsx)(`span`,{className:`text-foreground font-medium`,children:W}),` `,w(`gitView.branch.pushToSuffix`)]})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:o.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>ae(e),disabled:F,className:`flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label text-foreground`,children:[F?(0,$.jsx)(X,{name:`loader-4`,className:`inline size-3 mr-1.5 animate-spin`}):null,e.name]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground truncate max-w-full`,children:e.pushUrl})]},e.name))})]}):k?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-lg`,children:[(0,$.jsx)(`input`,{ref:L,placeholder:w(`gitView.branch.newBranchPlaceholder`),value:N,onChange:e=>P(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{V(e),e.key===`Enter`?(e.preventDefault(),ie()):e.key===`Escape`&&(e.preventDefault(),se())},className:`flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground`}),(0,$.jsx)(`button`,{type:`button`,onClick:ie,disabled:!W||F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:F?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`add`,className:`size-4`})}),(0,$.jsx)(`button`,{type:`button`,onClick:se,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,$.jsx)(X,{name:`close`,className:`size-4`})})]}):(0,$.jsxs)(y_,{onSelect:re,children:[(0,$.jsx)(X,{name:`add`,className:`size-4`}),(0,$.jsx)(`span`,{children:w(`gitView.branch.create`)})]})}),(0,$.jsx)(v_,{}),(0,$.jsxs)(__,{heading:w(`gitView.branch.localBranches`),children:[ee.map(t=>(0,$.jsxs)(y_,{onSelect:()=>te(t),children:[(0,$.jsxs)(`span`,{className:`flex flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:t}),(r?.[t]?.ahead||r?.[t]?.behind)&&(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[r[t].ahead||0,` ahead ·`,` `,r[t].behind||0,` behind`]})]}),e===t&&(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)})]},`local-${t}`)),ee.length===0&&(0,$.jsx)(y_,{disabled:!0,className:`justify-center`,children:(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:w(`gitView.branch.noLocalBranches`)})})]}),(0,$.jsx)(v_,{}),(0,$.jsxs)(__,{heading:w(`gitView.branch.remoteBranches`),children:[G.map(e=>(0,$.jsx)(y_,{onSelect:()=>te(e),children:(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e})},`remote-${e}`)),G.length===0&&(0,$.jsx)(y_,{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)(v_,{}),(0,$.jsxs)(__,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground typography-meta`,children:ue}),_?(0,$.jsx)(`button`,{type:`button`,className:`cursor-pointer text-muted-foreground typography-meta hover:text-foreground`,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.preventDefault(),e.stopPropagation(),B(!1),_()},children:de}):null]}),p&&q?(0,$.jsxs)(y_,{onSelect:()=>ne(p.value),children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:fe}),(0,$.jsx)(`span`,{className:`truncate typography-ui-label text-foreground`,children:p.label})]}),h===p.value?(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)}):null]}):null,K.map(e=>(0,$.jsxs)(y_,{onSelect:()=>ne(e.value),children:[(0,$.jsxs)(`span`,{className:`truncate typography-ui-label text-foreground`,children:[e.pending?`⏳ `:``,e.label]}),h===e.value?(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)}):null]},`worktree-${e.value}`))]})]}):null]})]});if(C===`mobile-sheet`){let e=Z.cloneElement(l??pe,{onClick:()=>B(!0),"data-popup-open":z?``:void 0});return(0,$.jsxs)($.Fragment,{children:[e,(0,$.jsx)(Qa,{id:`mobile-draft-branch-picker-sheet-${R}`,open:z,onOpenChange:B,ariaLabel:w(`gitView.branch.selectBranch`),closeAriaLabel:w(`mobile.surface.closeAria`),resizeAriaLabel:w(`mobile.sessions.sheet.resizeAria`),children:he})]})}return(0,$.jsxs)(Ua,{open:z,onOpenChange:B,children:[f||l?me:(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:me}),(0,$.jsx)(La,{sideOffset:8,children:c?ce:w(`gitView.branch.currentBranchTooltip`)})]}),(0,$.jsx)(Ka,{align:le,className:`w-72 p-0 max-h-[60vh] flex flex-col`,children:he})]})};function U_(e){let{localBranches:t,remoteBranches:n,query:r}=e,i=r.trim();if(!i)return{matching:[],otherLocal:t,otherRemote:n};let a=yi(t,i,e=>e),o=yi(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 W_(e,t){return`${e}\0${t}`}function G_({open:e,onOpenChange:t,onSelect:n}){let{t:r}=ot(),i=s(e=>e.isMobile),{github:a}=Do(),o=eo(),c=o.data??null,l=o.isFetched,u=s(e=>e.setSettingsDialogOpen),d=s(e=>e.setSettingsPage),f=kt(e=>e.getActiveProject()),p=f?.id??null,m=f?.path??null,h=Z.useMemo(()=>m&&p?{id:p,path:m}:null,[p,m]),[g,_]=Z.useState(`issues`),[v,y]=Z.useState(``),[b,x]=Z.useState([]),[S,C]=Z.useState([]),[w,T]=Z.useState(!1),[E,D]=Z.useState(!1),[O,k]=Z.useState(null),[A,j]=Z.useState(null),[M,N]=Z.useState(null),[P,F]=Z.useState(!1),[I,L]=Z.useState(new Map),[R,z]=Z.useState(1),[B,V]=Z.useState(!1),H=Z.useRef(0),U=zo(v,350),W=J(async e=>{if(!(!m||!a)&&!(l&&c?.connected===!1)){T(!0),k(null),z(1),V(!1);try{if(g===`issues`&&a.issuesList){let t=await a.issuesList(m,{page:1,query:e});t.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),x([])):(x(t.issues??[]),z(t.page??1),V(!!t.hasMore))}else if(g===`prs`&&a.prsList){let t=await a.prsList(m,{page:1,query:e});t.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),C([])):(C(t.prs??[]),z(t.page??1),V(!!t.hasMore))}}catch(e){k(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}finally{T(!1)}}});Z.useEffect(()=>{if(!e||!m||l&&c?.connected===!1||!a)return;if(!U.trim()){W();return}let t=new AbortController;T(!0),k(null),z(1),V(!1);let n=g===`issues`&&a.issuesList?a.issuesList(m,{page:1,query:U.trim()}):g===`prs`&&a.prsList?a.prsList(m,{page:1,query:U.trim()}):null;if(!n){T(!1);return}return n.then(e=>{t.signal.aborted||(`issues`in e?e.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),x([])):(x(e.issues??[]),z(e.page??1),V(!!e.hasMore)):`prs`in e&&(e.connected===!1?(k(r(`session.githubIntegration.error.notConnected`)),C([])):(C(e.prs??[]),z(e.page??1),V(!!e.hasMore))))}).catch(e=>{t.signal.aborted||k(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}).finally(()=>{t.signal.aborted||T(!1)}),()=>t.abort()},[e,m,a,l,c,g,U,W,r]);let ee=J(async()=>{if(!(!m||!a)&&!(w||E)&&B){D(!0);try{let e=R+1;if(g===`issues`&&a.issuesList){let t=U.trim()?await a.issuesList(m,{page:e,query:U.trim()}):await a.issuesList(m,{page:e});t.connected!==!1&&(x(e=>[...e,...t.issues??[]]),z(t.page??e),V(!!t.hasMore))}else if(g===`prs`&&a.prsList){let t=U.trim()?await a.prsList(m,{page:e,query:U.trim()}):await a.prsList(m,{page:e});t.connected!==!1&&(C(e=>[...e,...t.prs??[]]),z(t.page??e),V(!!t.hasMore))}}catch{}finally{D(!1)}}});Z.useEffect(()=>{if(!e){_(`issues`),y(``),x([]),C([]),j(null),N(null),F(!1),k(null),L(new Map),z(1),V(!1);return}W()},[e,W]),Z.useEffect(()=>{H.current+=1,L(new Map)},[m,h]);let G=J(async e=>{if(!h||!e)return;let t=W_(h.path,e);if(I.has(t))return;let n=H.current;try{let i=await xa(h,{mode:`new`,branchName:e,worktreeName:e});if(n!==H.current)return;let a=i.errors.find(e=>e.code===`branch_in_use`);L(e=>new Map(e).set(t,{isValid:!a,error:a?r(a.code===`branch_exists`?`session.githubIntegration.validation.branchAlreadyExists`:`session.githubIntegration.validation.branchAlreadyCheckedOut`):null}))}catch{if(n!==H.current)return;L(e=>new Map(e).set(t,{isValid:!1,error:r(`session.githubIntegration.validation.failed`)}))}});Z.useEffect(()=>{!e||g!==`prs`||S.forEach(e=>{e.head&&G(e.head)})},[e,g,S,m,h,G]);let K=l&&c?.connected===!0,q=()=>{d(`github`),u(!0)},te=e=>{j(e),N(null)},ne=e=>{N(e),j(null)},re=()=>{A?n({type:`issue`,item:A}):M&&n({type:`pr`,item:M,includeDiff:P}),t(!1)},ie=()=>{j(null),N(null),F(!1)},ae=A||(M?.head&&m?I.get(W_(m,M.head))?.isValid!==!1:!1),oe=e=>!e.head||(m?I.get(W_(m,e.head)):void 0)?.isValid===!1,se=(0,$.jsx)($.Fragment,{children:K?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Fa,{value:v,onChange:e=>y(e.target.value),placeholder:r(g===`issues`?`session.githubIntegration.search.issuesPlaceholder`:`session.githubIntegration.search.prsPlaceholder`),className:`h-8 pl-9`})]}),(0,$.jsx)(`div`,{className:`mt-2 h-[300px] overflow-hidden`,children:(0,$.jsxs)(`div`,{className:`h-full overflow-y-auto`,children:[w&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-5 w-5 animate-spin text-muted-foreground`})}),O&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive`,children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-small`,children:O})]})}),!w&&!O&&g===`issues`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[b.length>0?b.map(e=>(0,$.jsx)(`button`,{onClick:()=>te(e),className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,A?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-2`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noIssuesFound`)}),B&&!E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(ca,{variant:`ghost`,size:`sm`,onClick:()=>void ee(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),E&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]}),!w&&!O&&g===`prs`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[S.length>0?S.map(e=>{let t=oe(e),n=e.head&&m?I.get(W_(m,e.head)):void 0;return(0,$.jsx)(`button`,{onClick:()=>!t&&ne(e),disabled:t,className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,M?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:t?`opacity-50 cursor-not-allowed`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-1`,children:e.title}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[e.head,` → `,e.base]}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,t&&n?.error&&(0,$.jsx)(`span`,{className:`typography-micro text-destructive`,children:n.error})]})]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)}):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noPullRequestsFound`)}),B&&!E&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(ca,{variant:`ghost`,size:`sm`,onClick:()=>void ee(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),E&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]})]})})]}):(0,$.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center p-8 gap-4`,children:[(0,$.jsx)(X,{name:`github`,className:`h-12 w-12 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`p`,{className:`typography-ui-label text-foreground`,children:r(`session.githubIntegration.connect.title`)}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground mt-1`,children:r(`session.githubIntegration.connect.description`)})]}),(0,$.jsx)(ca,{onClick:q,size:`sm`,children:r(`session.githubIntegration.connect.action`)})]})}),ce=(0,$.jsxs)(`div`,{className:Y(`w-full`,i?`flex flex-col gap-2`:`flex flex-row items-center`),children:[(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-4`,i?`w-full justify-center order-1`:`flex-1`),children:[!i&&(A||M)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate max-w-[150px]`,children:A?r(`session.githubIntegration.selected.issueNumber`,{number:A.number}):r(`session.githubIntegration.selected.prNumber`,{number:M?.number??``})}),(0,$.jsx)(`button`,{onClick:ie,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),g===`prs`&&M&&(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer h-8`,children:[(0,$.jsx)(ga,{checked:P,onChange:e=>F(e),ariaLabel:r(`session.githubIntegration.includeDiffAria`)}),(0,$.jsx)(`span`,{className:`typography-small text-foreground`,children:r(`session.githubIntegration.includeDiff`)})]})]}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,i?`w-full order-2`:`justify-end`),children:[(0,$.jsx)(ca,{variant:`outline`,size:`sm`,onClick:()=>t(!1),className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.cancel`)}),(0,$.jsx)(ca,{size:`sm`,onClick:re,disabled:!ae,className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.select`)})]})]});return(0,$.jsx)($.Fragment,{children:i?(0,$.jsx)(rm,{open:e,title:r(`session.githubIntegration.title`),onClose:()=>t(!1),footer:K?ce:void 0,renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:r(`session.githubIntegration.title`)}),e]}),(0,$.jsx)(`div`,{className:`w-full`,children:(0,$.jsx)(Gc,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:g,onSelect:e=>{_(e),y(``)},variant:`active-pill`,layoutMode:`fit`})}),(A||M)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate flex-1`,children:A?r(`session.githubIntegration.selected.issueNumber`,{number:A.number}):r(`session.githubIntegration.selected.prNumber`,{number:M?.number??``})}),(0,$.jsx)(`button`,{onClick:ie,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]})]}),children:se}):(0,$.jsx)(aa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ta,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsx)(Qi,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(na,{className:`flex items-center gap-2 shrink-0`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),r(`session.githubIntegration.title`)]}),(0,$.jsx)(`div`,{className:`w-[220px]`,children:(0,$.jsx)(Gc,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:g,onSelect:e=>{_(e),y(``)},variant:`active-pill`,layoutMode:`fit`})})]})}),se,(0,$.jsx)($i,{className:`mt-1`,children:ce})]})})})}var K_=(e,t,n)=>{let r=n??t;return r?e.find(e=>e.id===r)??null:null},q_=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``),J_=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),Y_=e=>String(e||``).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`pr-head`,X_=(e,t,n)=>{let r=q_(e.head||``);if(!r)throw Error(`PR head branch is missing`);if(t.includes(r))return{existingBranch:r,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:r};let i=n.find(e=>{let t=e.indexOf(`/`);return t<=0||t>=e.length-1?!1:e.slice(t+1)===r});if(i){let e=i.indexOf(`/`),t=i.slice(0,e);return{existingBranch:`remotes/${i}`,setUpstream:!0,upstreamRemote:t,upstreamBranch:r,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${t}/${r}`}}let a=String(e.headLabel||``).split(`:`)[0]?.trim(),o=`pr-${Y_(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}`}},Z_=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`},Q_=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function $_({open:e,onOpenChange:t,onWorktreeCreated:n,projectId:r}){let{t:i}=ot(),{github:a,git:o}=Do(),c=s(e=>e.isMobile),l=Z.useId(),u=eo(),d=u.data??null,f=u.isFetched,p=kt(e=>K_(e.projects,e.activeProjectId,r)),m=p?.path??null,h=Z.useMemo(()=>m&&p?{id:p.id,path:m}:null,[p,m]),[g,_]=Z.useState(`new-branch`),[v,y]=Z.useState({branchName:``,worktreeName:``,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1}),[b,x]=Z.useState({selectedBranch:``,worktreeName:``}),S=rs(m),C=es(m),w=qo(e=>e.fetchBranches),T=Z.useMemo(()=>S?.all?S.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[S]),E=Z.useMemo(()=>S?.all?S.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[S]),D=ni(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=Kg();if(!O.has(e))return e}return`${Kg()}-${Date.now().toString(36).slice(-4)}`},[O]),[A,j]=Z.useState(!1),[M,N]=Z.useState(!1),[P,F]=Z.useState(!1),[I,L]=Z.useState(!1),[R,z]=Z.useState(!1),[B,V]=Z.useState(``),[H,U]=Z.useState(``),W=Z.useRef(null),ee=Z.useRef(null),G=Z.useRef(null),K=Z.useRef(null),q=Z.useCallback(e=>{e.stopPropagation()},[]),te=Z.useCallback(e=>{let t=e;for(;t&&t!==document.body;){let{overflowY:e}=window.getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t;t=t.parentElement}return null},[]),ne=Z.useCallback(e=>{e&&(e.scrollTop=0)},[]),re=Z.useCallback(e=>{let t=e.current?.querySelector(`[data-slot="command-list"]`)??null;ne(t)},[ne]),ie=Z.useCallback(e=>{let t=te(e.current);ne(t)},[te,ne]),ae=Z.useMemo(()=>U_({localBranches:T,remoteBranches:E,query:B}),[T,E,B]),oe=Z.useMemo(()=>U_({localBranches:T,remoteBranches:E,query:H}),[T,E,H]),se=B.trim().length>0,ce=H.trim().length>0,le=ae.matching.length>0,ue=oe.matching.length>0,de=!!(m&&o),fe=Z.useCallback(()=>{!m||!o||w(m,o)},[m,o,w]);Z.useEffect(()=>{!e||!m||!o||S?.all||w(m,o)},[e,m,o,S?.all,w]),Z.useEffect(()=>{!M&&!I&&V(``)},[M,I]),Z.useEffect(()=>{!P&&!R&&U(``)},[P,R]),Z.useEffect(()=>{M&&re(W),I&&ie(G)},[M,I,B,re,ie]),Z.useEffect(()=>{P&&re(ee),R&&ie(K)},[P,R,H,re,ie]);let[pe,me]=Z.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[he,ge]=Z.useState(!1),[_e,ve]=Z.useState(null),ye=Z.useCallback(()=>{let e=br.getState(),t=e.getVisibleAgents();if(e.settingsDefaultAgent){let n=t.find(t=>t.name===e.settingsDefaultAgent);if(n)return n.name}return t.find(e=>e.name===`build`)?.name||t[0]?.name},[]),be=Z.useCallback(()=>{let e=br.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=Ut(t);if(!n)return null;let{providerId:r,modelId:i}=n;return e.getModelMetadata(r,i)?{providerID:r,modelID:i}:null},[]),xe=Z.useCallback((e,t)=>{let n=br.getState(),r=n.settingsDefaultVariant,i=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0,a=n.providers.find(t=>t.id===e)?.models.find(e=>e.id===t)?.variants;if(!a)return r||i||void 0;if(r&&Object.prototype.hasOwnProperty.call(a,r))return r;if(i&&Object.prototype.hasOwnProperty.call(a,i))return i},[]),Se=Z.useCallback(async e=>{if(!m||!a)return;let t=br.getState(),n=rn.getState().lastUsedProvider,r=be(),o=r?.providerID||t.currentProviderId||n?.providerID,s=r?.modelID||t.currentModelId||n?.modelID,c=ye()||t.currentAgentName||void 0;if(!o||!s){In.error(i(`session.newWorktree.error.noModelSelected`));return}let l=xe(o,s);if(e.issue){if(!a.issueGet||!a.issueComments)return;let t=await a.issueGet(m,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(t.connected===!1||!t.repo||!t.issue)throw Error(`Failed to load issue context`);let n=await a.issueComments(m,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(n.connected===!1)throw Error(`Failed to load issue comments`);let r=await Tr(`github.issue.review.visible`,{issue_number:String(e.issue.number)}),u=await Tr(`github.issue.review.instructions`),d=Z_({repo:t.repo,issue:t.issue,comments:n.comments??[]});await ni.getState().sendMessage(r,o,s,c,void 0,void 0,[{text:u,synthetic:!0},{text:d,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),In.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 Tr(`github.pr.review.visible`,{pr_number:String(e.pr.number)}),r=await Tr(`github.pr.review.instructions`),u=Q_(t);await ni.getState().sendMessage(n,o,s,c,void 0,void 0,[{text:r,synthetic:!0},{text:u,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),In.success(i(`session.newWorktree.toast.sessionFromPr`))}},[a,m,ye,be,xe,i]),Ce=g===`new-branch`?v:b;Z.useEffect(()=>{if(!e||!S?.all||!m||v.sourceBranch)return;let t=v.sourceBranch,n=!1;return(async()=>{try{let e=await ka(m).catch(()=>null);if(n)return;let r=localStorage.getItem(Ko),{sourceBranch:i,shouldClearSavedSourceBranch:a}=ns({branches:S.all,savedSourceBranch:r,rootBranch:e});if(a&&localStorage.removeItem(Ko),n||t)return;i&&y(e=>({...e,sourceBranch:i}))}catch{}})(),()=>{n=!0}},[e,S?.all,m,v.sourceBranch]),Z.useLayoutEffect(()=>{if(!e)return;_(`new-branch`),x({selectedBranch:``,worktreeName:``}),N(!1),F(!1),L(!1),z(!1),V(``),U(``),me({isValidating:!1,branchError:null,worktreeError:null,touched:!1});let t=k();y({branchName:t,worktreeName:t,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1})},[e,k]),Z.useEffect(()=>{if(g!==`new-branch`||!v.isSyncingWorktreeName)return;let e=J_(q_(v.branchName));y(t=>({...t,worktreeName:e}))},[g,v.branchName,v.isSyncingWorktreeName]);let we=Z.useCallback(async()=>{if(!h||!pe.touched||he)return;_e&&_e.abort();let e=new AbortController;ve(e),me(e=>({...e,isValidating:!0}));try{let t=g===`new-branch`?v.branchName:b.selectedBranch,n=Ce.worktreeName,r=q_(t),a=J_(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?X_(t,T,E):null,i=await xa(h,{mode:g===`existing-branch`||n?`existing`:`new`,branchName:r,worktreeName:a,existingBranch:n?.existingBranch??(g===`existing-branch`?r:void 0),...n?.ensureRemoteName?{ensureRemoteName:n.ensureRemoteName}:{},...n?.ensureRemoteUrl?{ensureRemoteUrl:n.ensureRemoteUrl}:{}});if(e.signal.aborted)return;i.ok||i.errors.forEach(e=>{if(e.code===`worktree_exists`){s??=e.message;return}e.code.startsWith(`branch_`)&&(o??=e.message)})}e.signal.aborted||me(e=>({...e,isValidating:!1,branchError:o,worktreeError:s}))}catch{e.signal.aborted||me(e=>({...e,isValidating:!1}))}},[h,g,v.branchName,v.linkedPr,b.selectedBranch,Ce.worktreeName,T,E,pe.touched,_e,he,i]),Te=g===`new-branch`?v.branchName:b.selectedBranch;Z.useEffect(()=>{if(!e||!h||!pe.touched||he)return;let t=setTimeout(()=>{we()},300);return()=>clearTimeout(t)},[Ce.worktreeName,Te,e,h,we,pe.touched,he]);let Ee=async()=>{if(!h||!m){In.error(i(`session.newWorktree.error.noActiveProject`));return}me(e=>({...e,touched:!0}));let e=g===`new-branch`?v.branchName:b.selectedBranch,r=Ce.worktreeName,a=q_(e),o=J_(r);if(!a){In.error(i(`session.newWorktree.error.branchNameRequired`));return}if(!o){In.error(i(`session.newWorktree.error.worktreeDirectoryRequired`));return}_e&&(_e.abort(),ve(null)),me(e=>({...e,isValidating:!1,branchError:null,worktreeError:null})),ge(!0);try{let e=g===`new-branch`?v.linkedPr:null,r=g===`new-branch`?v.linkedIssue:null,s=g===`new-branch`?v.linkedPr:null,c=g===`new-branch`&&v.includePrDiff,l=!!(r||s),[u,d]=await Promise.all([yt(h),$o(m)]),f=v.sourceBranch,p=``,_=(()=>{if(e){let t=X_(e,T,E);return p=t.sourceLabel,{preferredName:a||o,mode:`existing`,branchName:a,worktreeName:o,existingBranch:t.existingBranch,setupCommands:u,setUpstream:t.setUpstream,upstreamRemote:t.upstreamRemote,upstreamBranch:t.upstreamBranch,returnAfterDirectoryCreated:!0,...t.ensureRemoteName?{ensureRemoteName:t.ensureRemoteName}:{},...t.ensureRemoteUrl?{ensureRemoteUrl:t.ensureRemoteUrl}:{}}}return p=g===`new-branch`?f:``,{preferredName:a||o,mode:g===`existing-branch`?`existing`:`new`,branchName:g===`existing-branch`?void 0:a,worktreeName:o,existingBranch:g===`existing-branch`?a:void 0,setupCommands:u,returnAfterDirectoryCreated:!0,...f&&g===`new-branch`?{startRef:f}:{}}})(),y=await ss(m,_,{resolvedRootTrackingRemote:d}),x=await Aa(h,y),S=null;if(l){await Gn(h)&&await Ur(x.path);let e=r?`#${r.number} ${r.title}`.trim():s?`#${s.number} ${s.title}`.trim():i(`session.newWorktree.newSessionTitle`),a=await Hn(e,x.path,null);if(!a?.id)throw Error(`Failed to create session`);S=a.id,n?.(x.path,{sessionId:S}),t(!1),ge(!1),di(a.id,e).catch(()=>void 0);try{ni.getState().initializeNewOpenChamberSession(a.id,br.getState().agents)}catch{}}else t(!1),ge(!1);let C=as({mode:g,sourceBranch:v.sourceBranch,linkedPr:!!v.linkedPr,selectedBranch:b.selectedBranch});C&&localStorage.setItem(Ko,C),In.success(i(`session.newWorktree.toast.worktreeCreated`),{description:i(`session.newWorktree.toast.worktreeCreatedDescription`,{target:`${x.branch||x.name}${p?` ${i(`session.newWorktree.fromSource`,{source:p})}`:``}`})}),S?Se({sessionId:S,directory:x.path,issue:r,pr:s,includeDiff:c}).catch(e=>{let t=e instanceof Error?e.message:i(`session.newWorktree.error.sendGitHubContextFailed`);In.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`);In.error(i(`session.newWorktree.error.createWorktreeFailed`),{description:t})}finally{ge(!1)}},De=e=>{_(e),me(e=>({...e,touched:!1,branchError:null,worktreeError:null}))},Oe=e=>{if(!e){y(e=>({...e,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:``}));return}if(e.type===`issue`){let t=e.item,n=`issue-${t.number}-${Kg()}`;y(e=>({...e,linkedIssue:t,linkedPr:null,includePrDiff:!1,branchName:n,worktreeName:J_(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:J_(t.head),isSyncingWorktreeName:!0}))}},ke=f&&d?.connected===!0,Ae=(g===`existing-branch`?!!b.selectedBranch&&!!b.worktreeName&&!pe.branchError&&!pe.worktreeError:!!q_(v.branchName)&&!!v.worktreeName&&!pe.branchError&&!pe.worktreeError)&&!he,je=()=>{y(e=>({...e,linkedIssue:null,linkedPr:null,branchName:``,includePrDiff:!1,isSyncingWorktreeName:!0}))},Me=(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,c?`flex-col w-full`:`flex-row items-center`),children:[(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1.5 text-destructive`,c?`w-full justify-center order-first`:`mr-auto`),children:pe.touched&&(pe.branchError||pe.worktreeError)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:pe.branchError||pe.worktreeError})]})}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,c&&`w-full`),children:[(0,$.jsx)(ca,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:he,className:Y(c&&`flex-1`),children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(ca,{size:`sm`,onClick:Ee,disabled:!Ae||he,className:Y(`gap-1.5`,c&&`flex-1`),children:[he&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(he?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]});return(0,$.jsxs)($.Fragment,{children:[c?(0,$.jsx)(Qa,{id:`new-worktree-sheet-${l}`,open:e,onOpenChange:t,title:(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold text-foreground`,children:i(`session.newWorktree.title`)}),ariaLabel:i(`session.newWorktree.title`),closeAriaLabel:i(`mobile.surface.closeAria`),resizeAriaLabel:i(`mobile.sessions.sheet.resizeAria`),children:(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,$.jsxs)(da,{useScrollShadow:!0,disableHorizontal:!0,preventOverscroll:!0,outerClassName:`min-h-0 flex-1`,className:`overscroll-contain px-4 pb-4 pt-2`,children:[(0,$.jsx)(`div`,{className:`w-full mb-4`,children:(0,$.jsx)(Gc,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:g,onSelect:e=>De(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})}),(0,$.jsxs)(`div`,{className:`space-y-6`,children:[g===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(ca,{variant:`outline`,size:`sm`,onClick:()=>L(!0),className:`flex-1 justify-between h-9`,children:[(0,$.jsx)(`span`,{className:b.selectedBranch?`text-foreground`:`text-muted-foreground`,children:b.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),(0,$.jsx)(ca,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:fe,disabled:!de||C,title:i(`session.newWorktree.fetchBranches`),children:C?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]}),(0,$.jsx)(rm,{open:I,title:i(`session.newWorktree.selectBranch`),onClose:()=>L(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:G,children:[(0,$.jsx)(Fa,{value:B,onChange:e=>V(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),C?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[se&&le&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(`session.newWorktree.matchingBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:ae.matching.map(e=>(0,$.jsx)(`button`,{onClick:()=>{x(t=>({...t,selectedBranch:e.value,worktreeName:J_(e.label)})),me(e=>({...e,touched:!0})),L(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,b.selectedBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),se&&!le&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),ae.otherLocal.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(se?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:ae.otherLocal.map(e=>(0,$.jsx)(`button`,{onClick:()=>{x(t=>({...t,selectedBranch:e,worktreeName:J_(e)})),me(e=>({...e,touched:!0})),L(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,b.selectedBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),ae.otherRemote.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(se?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:ae.otherRemote.map(e=>(0,$.jsx)(`button`,{onClick:()=>{x(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:J_(e)})),me(e=>({...e,touched:!0})),L(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,b.selectedBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),g===`new-branch`&&ke&&(0,$.jsxs)(ca,{variant:`outline`,size:`sm`,onClick:()=>j(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),v.linkedIssue||v.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Fa,{value:v.branchName,onChange:e=>{y(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!v.linkedPr,className:Y(`h-8`,pe.touched&&pe.branchError&&`border-destructive`,v.linkedPr&&`bg-muted text-muted-foreground`)}),v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:v.linkedPr.head})})]}),v.linkedIssue&&!v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:v.linkedIssue.number,title:v.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),g!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=J_(g===`new-branch`?v.branchName:``);y(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!v.branchName||v.worktreeName===J_(v.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,v.worktreeName===J_(v.branchName)||!v.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,$.jsx)(Fa,{value:Ce.worktreeName,onChange:e=>{g===`new-branch`?y(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):x(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,pe.touched&&pe.worktreeError&&`border-destructive`)})]}),g===`new-branch`&&!v.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)(ca,{variant:`outline`,size:`sm`,onClick:()=>z(!0),className:`w-full justify-between h-9`,children:[(0,$.jsx)(`span`,{className:v.sourceBranch?`text-foreground`:`text-muted-foreground`,children:v.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),v.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:v.sourceBranch})}),(0,$.jsx)(rm,{open:R,title:i(`session.newWorktree.selectSourceBranch`),onClose:()=>z(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:K,children:[(0,$.jsx)(Fa,{value:H,onChange:e=>U(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),C?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):T.length===0&&E.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[ce&&ue&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(`session.newWorktree.matchingBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:oe.matching.map(e=>(0,$.jsx)(`button`,{onClick:()=>{y(t=>({...t,sourceBranch:e.value})),z(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,v.sourceBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),ce&&!ue&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),oe.otherLocal.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(ce?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:oe.otherLocal.map(e=>(0,$.jsx)(`button`,{onClick:()=>{y(t=>({...t,sourceBranch:e})),z(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,v.sourceBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),oe.otherRemote.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(ce?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:oe.otherRemote.map(e=>(0,$.jsx)(`button`,{onClick:()=>{y(t=>({...t,sourceBranch:`remotes/${e}`})),z(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,v.sourceBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}),(v.linkedIssue||v.linkedPr)&&g===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),v.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:v.linkedIssue.number})}),v.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:v.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:v.linkedIssue?.title||v.linkedPr?.title}),(0,$.jsx)(`a`,{href:v.linkedIssue?.url||v.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick:je,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[v.linkedPr.head,` → `,v.linkedPr.base]}),v.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]})]}),(0,$.jsx)(`div`,{className:`shrink-0 border-t border-border/50 px-4 pb-3 pt-2`,children:Me})]})}):(0,$.jsx)(aa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ta,{className:`max-w-lg max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(Qi,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(na,{className:`flex items-center gap-2 shrink-0`,children:[(0,$.jsx)(X,{name:`git-branch`,className:`h-5 w-5`}),i(`session.newWorktree.title`)]}),(0,$.jsx)(`div`,{className:`w-[280px] shrink-0`,children:(0,$.jsx)(Gc,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:g,onSelect:e=>De(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})})]})}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto mt-2 space-y-6`,children:[g===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(Ua,{open:M,onOpenChange:N,children:[(0,$.jsx)(qa,{asChild:!0,children:(0,$.jsxs)(ca,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,b.selectedBranch?`text-foreground`:`text-muted-foreground`),children:b.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(Ka,{align:`start`,sideOffset:6,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:W,children:(0,$.jsxs)(p_,{shouldFilter:!1,children:[(0,$.jsx)(m_,{placeholder:i(`session.newWorktree.searchBranches`),value:B,onValueChange:V,onKeyDown:q}),(0,$.jsx)(h_,{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)(g_,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[se&&le&&(0,$.jsx)(__,{heading:i(`session.newWorktree.matchingBranches`),children:ae.matching.map(e=>(0,$.jsx)(y_,{value:e.value,onSelect:()=>{x(t=>({...t,selectedBranch:e.value,worktreeName:J_(e.label)})),me(e=>({...e,touched:!0})),N(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),se&&!le&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),ae.otherLocal.length>0&&(0,$.jsxs)($.Fragment,{children:[se&&(0,$.jsx)(v_,{}),(0,$.jsx)(__,{heading:i(se?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:ae.otherLocal.map(e=>(0,$.jsx)(y_,{value:e,onSelect:()=>{x(t=>({...t,selectedBranch:e,worktreeName:J_(e)})),me(e=>({...e,touched:!0})),N(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),ae.otherRemote.length>0&&(0,$.jsxs)($.Fragment,{children:[(ae.otherLocal.length>0||se)&&(0,$.jsx)(v_,{}),(0,$.jsx)(__,{heading:i(se?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:ae.otherRemote.map(e=>(0,$.jsx)(y_,{value:`remotes/${e}`,onSelect:()=>{x(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:J_(e)})),me(e=>({...e,touched:!0})),N(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),(0,$.jsx)(ca,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:fe,disabled:!de||C,title:i(`session.newWorktree.fetchBranches`),children:C?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),g===`new-branch`&&ke&&(0,$.jsxs)(ca,{variant:`outline`,size:`sm`,onClick:()=>j(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),v.linkedIssue||v.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Fa,{value:v.branchName,onChange:e=>{y(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!v.linkedPr,className:Y(`h-8`,pe.touched&&pe.branchError&&`border-destructive`,v.linkedPr&&`bg-muted text-muted-foreground`)}),v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:v.linkedPr.head})})]}),v.linkedIssue&&!v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:v.linkedIssue.number,title:v.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),g!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=J_(g===`new-branch`?v.branchName:``);y(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!v.branchName||v.worktreeName===J_(v.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,v.worktreeName===J_(v.branchName)||!v.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,$.jsx)(Fa,{value:Ce.worktreeName,onChange:e=>{g===`new-branch`?y(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):x(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,pe.touched&&pe.worktreeError&&`border-destructive`)})]}),g===`new-branch`&&!v.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)(Ua,{open:P,onOpenChange:F,children:[(0,$.jsx)(qa,{asChild:!0,children:(0,$.jsxs)(ca,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,v.sourceBranch?`text-foreground`:`text-muted-foreground`),children:v.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(Ka,{align:`start`,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:ee,children:(0,$.jsxs)(p_,{shouldFilter:!1,children:[(0,$.jsx)(m_,{placeholder:i(`session.newWorktree.searchBranches`),value:H,onValueChange:U,onKeyDown:q}),(0,$.jsx)(h_,{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)(g_,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[ce&&ue&&(0,$.jsx)(__,{heading:i(`session.newWorktree.matchingBranches`),children:oe.matching.map(e=>(0,$.jsx)(y_,{value:e.value,onSelect:()=>{y(t=>({...t,sourceBranch:e.value})),F(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),ce&&!ue&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),oe.otherLocal.length>0&&(0,$.jsxs)($.Fragment,{children:[ce&&(0,$.jsx)(v_,{}),(0,$.jsx)(__,{heading:i(ce?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:oe.otherLocal.map(e=>(0,$.jsx)(y_,{value:e,onSelect:()=>{y(t=>({...t,sourceBranch:e})),F(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),oe.otherRemote.length>0&&(0,$.jsxs)($.Fragment,{children:[(oe.otherLocal.length>0||ce)&&(0,$.jsx)(v_,{}),(0,$.jsx)(__,{heading:i(ce?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:oe.otherRemote.map(e=>(0,$.jsx)(y_,{value:`remotes/${e}`,onSelect:()=>{y(t=>({...t,sourceBranch:`remotes/${e}`})),F(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),v.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:v.sourceBranch})})]}),(v.linkedIssue||v.linkedPr)&&g===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),v.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:v.linkedIssue.number})}),v.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:v.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:v.linkedIssue?.title||v.linkedPr?.title}),(0,$.jsx)(`a`,{href:v.linkedIssue?.url||v.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick:je,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),v.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[v.linkedPr.head,` → `,v.linkedPr.base]}),v.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]}),(0,$.jsxs)($i,{className:`mt-1 flex items-center justify-between`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 text-destructive`,children:pe.touched&&(pe.branchError||pe.worktreeError)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:pe.branchError||pe.worktreeError})]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ca,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:he,children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(ca,{size:`sm`,onClick:Ee,disabled:!Ae||he,className:`gap-1.5`,children:[he&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(he?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]})]})}),(0,$.jsx)(G_,{open:A,onOpenChange:j,onSelect:Oe})]})}function ev(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 tv(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 nv=(e,t)=>e??t??null,rv=(e,t)=>!!e&&t!==!1,iv=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:[]},av=e=>e.replace(/^remotes\//,``).trim(),ov=e=>{let t=av(e),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},sv=({directory:e,projectDirectory:t,label:n,projectRootOption:r,worktreeOptions:i,onSelectDirectory:a,className:o,maxWidthClassName:s=`max-w-[48vw] sm:max-w-[20rem]`,presentation:c=`dropdown`})=>{let{t:l}=ot(),{git:d}=Do(),f=nv(t,e),p=e,m=ls(f),h=ls(p),g=rv(f,m),_=p!==f&&rv(p,h),v=Mo(f,d,g),y=Mo(p,d,_),b=v.data,x=p===f?b:y.data,S=qo(e=>e.fetchStatus),C=qo(e=>p&&e.directories.get(p)?.status?.current?.trim()||null),[w,T]=Z.useState(!1),E=cs(f,d,g&&w).data??[],[D,O]=Z.useState(null),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),N=kt(e=>e.projects),P=kt(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(()=>iv(b?.all),[b]),R=x?.current?.trim()||C||null,z=!tv(n,e)&&n||R||n||l(`chat.chatInput.branch`),B=J(async()=>{if(!d)return;let e=new Set;f&&e.add(f),p&&e.add(p),await Promise.all([...e].map(async e=>{await Uo(e,d),await S(e,d,{silent:!0})}))}),V=J(e=>{let t=av(e),n=ov(t);return i.find(e=>{let r=e.label.trim();return r===t||r===n})??null}),H=J(async e=>{if(!p||!d)return;let t=av(e);if(R!==t&&R!==ov(t))try{await d.checkoutBranch(p,t),In.success(l(`gitView.toast.checkedOut`,{name:t})),await B()}catch(e){let n=e instanceof Error?e.message:l(`gitView.toast.checkoutFailed`,{name:t});In.error(n)}}),U=J(e=>{let t=av(e);if(!t||R===t||R===ov(t))return;let n=V(t);if(n){a(n.value);return}O(t)}),W=J(async()=>{if(!(!D||k)){A(!0);try{await H(D),O(null)}finally{A(!1)}}}),ee=J(async()=>{if(!(!D||k)){A(!0);try{await a_({branch:D,projectDirectory:t??void 0})&&O(null)}finally{A(!1)}}}),G=J(async(e,t)=>{if(!p||!d)return;let n=t?.name??`origin`;try{await d.createBranch(p,e,R??`HEAD`),In.success(l(`gitView.toast.createdBranch`,{name:e})),O(e),d.gitPush(p,{remote:n,branch:e,options:[`--set-upstream`]}).then(async()=>{await B(),In.success(l(`gitView.toast.upstreamSet`,{branch:e,remote:n}))}).catch(async e=>{let t=e instanceof Error?e.message:l(`gitView.toast.branchCreatedLocally`);In.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 In.error(t),e}}),K=J(()=>{let e=kt.getState(),n=u(t),r=n?e.projects.find(e=>u(e.path)===n)??null:null;r&&e.activeProjectId!==r.id&&e.setActiveProjectIdOnly(r.id),M(!0)}),q=J((e,n)=>{if(M(!1),n?.sessionId){ni.getState().setCurrentSession(n.sessionId,e);return}let r=kt.getState(),i=u(t),a=(i?r.projects.find(e=>u(e.path)===i)??null:null)?.id??r.activeProjectId??null,o=ni.getState();if(o.newSessionDraft?.open){o.overrideNewSessionDraftTarget({...a?{selectedProjectId:a}:{},directoryOverride:e,bootstrapPendingDirectory:e,preserveDirectoryOverride:!0}),we.getState().setDirectory(e,{showOverlay:!1});return}o.openNewSessionDraft({...a?{selectedProjectId:a}:{},directoryOverride:e,preserveDirectoryOverride:!0})}),te=(0,$.jsxs)(`button`,{type:`button`,className:Y(`group relative inline-flex min-w-0 w-fit items-center gap-1.5 rounded-lg !border-0 px-1.5 font-medium text-foreground/80`,c===`mobile-sheet`?`h-[26px] text-[11px] leading-none`:`h-6 py-1 pr-1.5 typography-micro transition-[padding] hover:pr-5 focus-visible:pr-5 data-[popup-open]:pr-5`,s,dm,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)(H_,{currentBranch:R,localBranches:I,remoteBranches:L,branchInfo:b?.branches,onCheckout:U,onCreate:G,remotes:E,trigger:te,triggerLabel:z,hideTooltip:!0,projectRootOption:r,worktreeOptions:i,selectedDirectory:e,onSelectDirectory:a,onCreateWorktree:K,open:w,presentation:c,onOpenChange:T}),j?(0,$.jsx)($_,{open:!0,projectId:F,onOpenChange:M,onWorktreeCreated:q}):null,(0,$.jsx)(aa,{open:!!D,onOpenChange:e=>{!e&&!k&&O(null)},children:(0,$.jsxs)(ta,{showCloseButton:!1,className:`max-w-sm gap-4`,children:[(0,$.jsxs)(Qi,{children:[(0,$.jsx)(na,{children:l(`chat.chatInput.branchSwitch.title`,{branch:D??``})}),(0,$.jsx)(ra,{children:l(`chat.chatInput.branchSwitch.description`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`button`,{type:`button`,disabled:k,onClick:()=>{W()},className:`flex w-full flex-col items-start gap-0.5 rounded-lg border border-border px-3 py-2.5 text-left hover:bg-interactive-hover disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 typography-ui-label font-medium text-foreground`,children:[k?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`arrow-left-right`,className:`size-3.5 text-muted-foreground`}),l(`chat.chatInput.branchSwitch.checkoutHere`)]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:l(`chat.chatInput.branchSwitch.checkoutHereDescription`)})]}),(0,$.jsxs)(`button`,{type:`button`,disabled:k,onClick:()=>{ee()},className:`flex w-full flex-col items-start gap-0.5 rounded-lg border border-border px-3 py-2.5 text-left hover:bg-interactive-hover disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 typography-ui-label font-medium text-foreground`,children:[k?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5 text-muted-foreground`}),l(`chat.chatInput.branchSwitch.createWorktree`)]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:l(`chat.chatInput.branchSwitch.createWorktreeDescription`)})]})]}),(0,$.jsx)($i,{children:(0,$.jsx)(`button`,{type:`button`,disabled:k,onClick:()=>O(null),className:`inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 disabled:opacity-50`,children:l(`chat.chatInput.branchSwitch.cancel`)})})]})})]})},cv=[],lv=[],uv={revertMessageID:void 0,records:lv},dv=e=>e.role===`user`,fv=(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},pv=(e,t,n=uv)=>{if(!t)return uv;let r=(`session`in e?e.session:[]).find(e=>e.id===t)?.revert?.messageID;if(!r)return uv;let i=`messages`in e?e.messages:e.message[t]??[],a=`partsByMessageID`in e?e.partsByMessageID:e.part,o=[];for(let e of i)!dv(e)||!It(i,e.id,r)||o.push({message:e,parts:a[e.id]??cv});let s=o.length===0?lv:o;return n.revertMessageID===r&&fv(n.records,s)?n:{revertMessageID:r,records:s}},mv={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},hv={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`},gv=`text-foreground`;function _v(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 vv=/^(\s*)(`{3,}|~{3,})\s*(\S*)/;function yv(e){let t=vv.exec(e);return t?{marker:t[2],lang:t[3]||``}:null}function bv(e,t){return RegExp(`^\\s*\\${t[0]}{${t.length},}\\s*$`).test(e)}function xv(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`}),bv(o,i)&&(r=!1);continue}let l=yv(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`}),_v(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`}),_v(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;_v(o.slice(r-s),r,t);continue}_v(o,s,t)}return t}function Sv(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??mv[e.style];(n>u||n===u&&t<d)&&(u=n,d=t,l=e)}let f=l?l.className??hv[l.style]:gv,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 Cv(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 wv(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 Tv(e,t,n){let r=Cv(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 Ev(e){return e.map(e=>({start:e.start,end:e.end,style:e.kind===`file`?`mentionFile`:e.kind===`session`?`mentionSession`:`mentionAgent`,visual:e.kind===`session`&&e.label?re({trigger:`@`,icon:`chat-thread`,label:e.label},H({trigger:`@`,icon:`chat-thread`,label:e.label})):void 0}))}function Dv(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 Ov=`bg-[var(--surface-subtle)]`,kv=91,Av=94,jv={keyword:8,function:7,type:6,string:5,number:5,variable:4,operator:3,comment:2},Mv={keyword:`${Ov} text-[var(--syntax-keyword)]`,string:`${Ov} text-[var(--syntax-string)]`,number:`${Ov} text-[var(--syntax-number)]`,comment:`${Ov} text-[var(--syntax-comment)]`,function:`${Ov} text-[var(--syntax-function)]`,type:`${Ov} text-[var(--syntax-type)]`,variable:`${Ov} text-[var(--syntax-variable)]`,operator:`${Ov} text-[var(--syntax-operator)]`},Nv=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`}]),Pv=e=>{let t=null;for(let n of e.split(` `)){let e=n;jv[e]!==void 0&&(t===null||jv[e]>jv[t])&&(t=e)}return t?Mv[t]:null},Fv=2e4,Iv=e=>{if(!e)return null;try{let t=so(e);return t instanceof Qe?t:null}catch{return null}};function Lv(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=yv(i);if(!a)continue;let o=Iv(a.lang),s=r,c=[],l=e+1,u=r;for(;l<n.length;l+=1){let e=n[l];if(bv(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:`${Ov} text-[var(--syntax-foreground)]`,priority:kv}),!(d.length>Fv)))try{let e=o.parser.parse(d);Xe(e,Nv,(e,n,r)=>{let i=Pv(r);i&&t.push({start:s+e,end:s+n,style:`codeFence`,className:i,priority:Av})})}catch{}}return t}var Rv=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],zv=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),Bv=e=>{if(!zv(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(`/`)},Vv=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?Bv(n):zv(n))?n:null},Hv=(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)Hv(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))Hv(r,t,n+1)}},Uv=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=Vv(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=Vv(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;Hv(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},Wv=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of Rv){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 Uv(r,i))t.add(e)}return Array.from(t)},Gv=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}}},Kv=e=>zv(e);function qv(e,t){let n=(0,Q.c)(5),r=pt(e,t),i=s(Jv),a;n[0]===r?a=n[1]:(a=dn(r),n[0]=r,n[1]=a);let o;return n[2]!==i||n[3]!==a?(o={goal:a,enabled:i},n[2]=i,n[3]=a,n[4]=o):o=n[4],o}function Jv(e){return e.sessionGoalEnabled}function Yv(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 At(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 Xv={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},Zv={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`},Qv=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=ot(),i=s(e=>e.isMobile),{goal:a,enabled:o}=qv(e??``,t),c=Yv(e??``,a),l=Pi(e??``,t),u=Dn(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,Tt(e,t))},[e,t,a,u]);let g=J(async n=>{if(!(!e||f)){p(!0);try{await _n(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),In.error(r(`chat.goal.toast.actionFailed`))}finally{p(!1)}}});if(!e||!o||!a)return null;let _=Math.max(0,(a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`?a.updatedAt:m)-(a.createdAt||m)),v=mt(_),y=a.tokenBudget?`${Gr(a.tokensUsed)}/${Gr(a.tokenBudget)}`:a.tokensUsed>0?Gr(a.tokensUsed):null,b=a.status===`active`?{icon:`pause`,labelKey:`chat.goal.action.pause`,next:`paused`}:a.status===`paused`||a.status===`blocked`||a.status===`budgetLimited`?{icon:`play`,labelKey:`chat.goal.action.resume`,next:`active`}:null,x=i?`text-[11px] leading-none text-muted-foreground`:`typography-meta text-muted-foreground`,S=i?`text-xs leading-5 text-foreground`:`typography-ui-label leading-5 text-foreground`,C=i?`size-3`:`size-3.5`;return(0,$.jsxs)(`div`,{className:Y(`flex w-full min-w-0 items-center`,i?`gap-1 py-0.5`:`gap-1.5 py-0.5 md:gap-2`,n),"aria-label":r(`chat.goal.row.aria`),title:c??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(C,`flex-shrink-0`),style:{color:Xv[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,S),children:a.note||c||``}),a.status===`active`&&(!l||l.type===`idle`)?(0,$.jsxs)(`span`,{className:Y(`flex flex-shrink-0 items-center gap-1`,x),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(C,`animate-spin`),"aria-hidden":`true`}),r(`chat.goal.status.evaluating`)]}):(0,$.jsx)(`span`,{className:Y(`flex-shrink-0`,x),children:r(Zv[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]})});Qv.displayName=`SessionGoalRow`;var $v=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=ot(),{goal:i,enabled:a}=qv(e??``,t),o=xn(e=>e.armed),s=xn(e=>e.setArmed),[c,l]=Z.useState(!1);if(d()||!a||!e&&!n||!o&&!i)return null;let u=i?.status===`complete`?`text-[var(--status-success)]`:i?.status===`blocked`||i?.status===`budgetLimited`?`text-[var(--status-error)]`:o||i?.status===`active`||i?.status===`paused`?`text-[var(--status-info)]`:``,f=async()=>{if(o){s(!1);return}if(!(!e||c)){l(!0);try{await Ln(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),In.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`})})]})});$v.displayName=`SessionGoalButton`;var ey=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=ot();if(!xn(ty)||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});ey.displayName=`SessionGoalObjectiveCounter`;function ty(e){return e.armed}var ny=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`plan-feature`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`]),ry=new Set([`new`,`compact`,`fork`,`undo`,`redo`]),iy=/^\/\u2003?([^\s]+)/i,ay=/^\/\u2003?goal\b/i,oy=(e,t)=>{if(t!==`normal`)return null;let n=e.trimStart().match(iy)?.[1]?.toLowerCase();return n&&ny.has(n)?n:null},sy=(e,t)=>oy(e,t)===`goal`?e.trimStart().replace(ay,``).trim():null,cy=(e,t)=>oy(e,t)!==null,ly=(e,t)=>{let n=oy(e,t);return n!==null&&ry.has(n)},uy=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},dy=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()}},fy=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,py=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,my=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},hy=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),gy=(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},_y=async e=>{let t=gn.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=hy(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}gy(n,a)?r+=1:i+=1}catch{try{gy(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},vy=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),yy=e=>e===`allow`||e===`ask`||e===`deny`,by=e=>{if(yy(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`&&yy(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(yy(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))yy(i)&&t.push({permission:n,pattern:e,action:i})}return t},xy=e=>{let t=by(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},Sy=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>xy(e.permission));let r=e.find(e=>e?.name===n);return!r||xy(r.permission)},Cy=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)},wy=null,Ty=new Set,Ey=()=>{for(let e of Ty)e()},Dy=e=>e===`chat`||e===`assistant`,Oy=()=>wy,ky=e=>{wy!==e&&(wy=e,Ey())},Ay=e=>{wy&&(e&&wy.surfaceID!==e||(wy=null,Ey()))},jy=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},My=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}},Ny=(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}),Py=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=Ny(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=Ny(e,`send`,i),o=Hm(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=Ny(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=Ny(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=Ny(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:Hm(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>Fm(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=Ny(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=Ny(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},Fy=(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)))},Iy=(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},Ly=(e,t)=>e.agents.some(e=>e.name===t),Ry=(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},zy=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return Ry(t,n,r,i)?i:void 0;if(a&&Ry(t,n,r,a))return a},By=e=>{let{sessionId:t,latestUserChoice:n,catalog:r,memory:i,sessionEntity:a,fallbackAgentName:o,transcriptReady:s=!0}=e;if(s&&n?.providerID&&n.modelID&&Iy(r,n.providerID,n.modelID)){let e=n.agent&&Ly(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&Ly(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):o&&Ly(r,o)?o:void 0,a=e?i?.getAgentModelVariantForSession?.(t,e,n.providerID,n.modelID):void 0,s=zy({catalog:r,providerID:n.providerID,modelID:n.modelID,historyVariant:n.variant,memoryVariant:a});return{agent:e,providerID:n.providerID,modelID:n.modelID,variant:s,source:`history`,messageId:n.id}}if(s&&i){let e=i.getSessionAgentSelection?.(t)??null,n=e&&Ly(r,e)?e:o&&Ly(r,o)?o:void 0;if(n){let e=i.getAgentModelForSession?.(t,n);if(e&&Iy(r,e.providerId,e.modelId)){let a=i.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=a&&Ry(r,e.providerId,e.modelId,a)?a:void 0;return{agent:n,providerID:e.providerId,modelID:e.modelId,variant:o,source:`session-memory`}}}let a=i.getSessionModelSelection?.(t);if(a&&Iy(r,a.providerId,a.modelId)){let e=n?i.getAgentModelVariantForSession?.(t,n,a.providerId,a.modelId):void 0,o=e&&Ry(r,a.providerId,a.modelId,e)?e:void 0;return{agent:n,providerID:a.providerId,modelID:a.modelId,variant:o,source:`session-memory`}}}let c=a?.model;if(c&&Iy(r,c.providerID,c.id)){let e=i?.getSessionAgentSelection?.(t)??null,n=(a?.agent&&Ly(r,a.agent)?a.agent:void 0)??(e&&Ly(r,e)?e:o&&Ly(r,o)?o:void 0),s=c.variant,l=s&&Ry(r,c.providerID,c.id,s)?s:void 0;return{agent:n,providerID:c.providerID,modelID:c.id,variant:l,source:`session-entity`}}return null},Vy=(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))},Hy=(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}},Uy=e=>e.editRevision<=0?!1:e.pinnedHistoryMessageId==null||e.latestHistoryMessageId==null||e.latestHistoryMessageId===e.pinnedHistoryMessageId,Wy=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}:{}}},Gy=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},Ky=500,qy=e=>Array.from(e).length,Jy=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},Yy=e=>qy(e)>=Ky,Xy=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},Zy=(e,t)=>{let n=t??e;return typeof n!=`string`||!Yy(n)?!1:le(typeof e==`string`?{text:``,references:[]}:e,n)},Qy=(e,t,n,r,i=1)=>{let a=qy(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}-${Jy(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},$y=e=>({text:e.text,references:e.references.map(e=>({...e}))}),eb=e=>e.map(e=>({...e,range:{...e.range}})),tb=(e,t)=>e.text===t.text&&JSON.stringify(e.references)===JSON.stringify(t.references),nb=(e,t,n)=>({document:$y(e),mentions:eb(t),selection:{...n}}),rb=()=>({undo:[],redo:[]}),ib=(e,t)=>({undo:[...e.undo,t].slice(-100),redo:[]}),ab=(e,t)=>{let n=e.undo.at(-1);return!n||!tb(n.after.document,t)?null:{history:{undo:e.undo.slice(0,-1),redo:[...e.redo,n]},snapshot:nb(n.before.document,n.before.mentions,n.before.selection)}},ob=(e,t)=>{let n=e.redo.at(-1);return!n||!tb(n.before.document,t)?null:{history:{undo:[...e.undo,n],redo:e.redo.slice(0,-1)},snapshot:nb(n.after.document,n.after.mentions,n.after.selection)}},sb=e=>({text:e?.text??``,references:e?.composerReferences??[]}),cb=e=>({text:e.text,references:e.references.map(e=>({...e}))}),lb=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),ub=e=>JSON.stringify([e.text,e.references]),db=(e,t)=>e!==null&&t!==null&&ce(e)===t,fb=(e,t,n)=>{let r=e?lb(e):null,i=r?n(r):void 0;return{document:D(sb(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?ce(r):null}},pb=(e,t,n,r)=>{if(!t||ce(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=ub(sb(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===ub(e)?`same-document-metadata`:`external-document`},mb=(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}]:[]})},hb=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),gb=(e,t,n,r,i=r)=>{let a=g(e,n,r,i);return{document:a.document,mentions:mb(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},_b=(e,t,n)=>({preview:{real:cb(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),vb=e=>({document:e.real,mentions:e.realMentions}),yb=(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)})},bb=(e,t)=>{let n=sb(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:yb(e.mentions,t?.mentions??[],r,i)}},xb=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=Yt})=>{let a=e?ce(e):null,o=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().drafts[a]:void 0,()=>void 0),s=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftHydration[a]??`idle`:`idle`,()=>`idle`),c=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftPersistence[a]:void 0,()=>void 0),[l,u]=(0,Z.useState)(()=>fb(e,t,i.getState().getDraft).document),[d,p]=(0,Z.useState)(()=>fb(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?lb(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)(rb());_.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=fb(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=rb(),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||!db(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(sb(t),x.current),t.mentions))})}},[a,F,i]),(0,Z.useEffect)(()=>{if(!a||E.current!==a||N.current)return;let e=pb(_.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(sb(o),x.current),o.mentions),h(`compose`))}},[a,F,o]);let L=(0,Z.useCallback)((e,t)=>{let n=w.current;if(!db(n,T.current)||N.current)return;let r=_.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:hb(t)});if(!a)return;let o=sb(a);return M.current={keyID:ce(n),revision:a.revision,fingerprint:ub(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=ib(P.current,{before:nb(e,t,n),after:nb(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=ae(e.text,e.references);return n?L(D(n,x.current),t):void 0},[L,z]),H=(0,Z.useCallback)((e,t,n=t,r)=>{let i=z(),a=cb(_.current),o=i?[]:b.current,s=gb(a,o,e,t,n),c=r?r(s.mentions,s.document):s.mentions;return L(s.document,c),s.removedReferences.length>0&&R(a,o,{start:s.selectionStart,end:s.selectionEnd},s.document,c,{start:s.selectionStart,end:s.selectionEnd}),{start:s.selectionStart,end:s.selectionEnd,requiresTextCorrection:s.requiresTextCorrection}},[L,z,R]),U=(0,Z.useCallback)((e,t)=>{let n=_.current,r=Math.max(0,Math.min(e.start,n.text.length)),i=Math.max(r,Math.min(e.end,n.text.length)),a=z(),o=g(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=mb(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,mb(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=cb(_.current),n=y(t,e);if(!n)return null;let r=z()?[]:b.current,i=mb(r,n.document,n.edit),a=O(n.document.text,n.caret),o=g(n.document,a.text,a.caret),s=mb(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`?ab(P.current,_.current):ob(P.current,_.current);return!t||!L(t.snapshot.document,t.snapshot.mentions)?null:(P.current=t.history,t.snapshot.selection)},[L]),q=(0,Z.useCallback)(e=>L(_.current,e),[L]),te=(0,Z.useCallback)(e=>{let t=N.current?{document:{text:e.text,references:[]},mentions:[]}:_b(_.current,b.current,e);`preview`in t&&(N.current=t.preview),h(`history-preview`),F(t.document,t.mentions)},[F]),ne=(0,Z.useCallback)(()=>{let e=N.current;if(!e)return;N.current=void 0,h(`compose`);let t=vb(e);F(t.document,t.mentions)},[F]),re=(0,Z.useCallback)(()=>{let e=w.current;if(!db(e,T.current))return null;let t=i.getState().getDraft(e);return{key:lb(e),keyID:ce(e),revision:t?.revision??0,document:cb(_.current),mentions:b.current.map(e=>({...e,range:{...e.range}})),epoch:k.current,runtime:i.getState().captureDraftRuntime()}},[i]),ie=(0,Z.useCallback)(e=>{let t=bb(e,i.getState().getDraft(e.key)),n=sb(i.getState().getDraft(e.key)),r=v(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:hb(t.mentions)});if(a){let e=sb(a);I(r,e)}return a},[I,i]),oe=(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:oe,replacePlainDocument:B,replaceMaterializedDocument:V,applyBrowserEdit:H,applyProgrammaticEdit:U,replaceProgrammaticText:W,insertReference:ee,deleteReference:G,restoreReferenceHistory:K,commitMentions:q,enterHistoryPreview:te,exitHistoryPreview:ne,captureSubmission:re,recoverSubmission:ie}),[H,U,re,q,G,l,te,ne,oe,s,m,ee,d,c,ie,V,B,W,K])};function Sb(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 Cb=`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`,wb=Fs(()=>Ue(()=>import(`./ToolOutputDialog-BvkZesJU.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]))),Tb=[],Eb=[],Db=[],Ob=[],kb=/^@[^\s]+$/,Ab=({inputMode:e,message:t,showCommandAutocomplete:n,showSkillAutocomplete:r})=>e!==`shell`&&(n||r||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),jb=/^(https?:\/\/|mailto:)\S+$/i,Mb=560,Nb=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),Pb=(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)},Fb=e=>e.includes(`@`)?`paste`:`manual`,Ib=(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}},Lb=(e,t)=>kr(e,t).some(e=>e.role===`user`),Rb=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!en(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:`${Ov} text-[var(--syntax-foreground)]`,priority:kv}),!(d.length>Fv)))try{let e=o.parser.parse(d);Xe(e,Nv,(e,n,r)=>{let i=Pv(r);i&&t.push({start:s+e,end:s+n,style:`codeFence`,className:i,priority:Av})})}catch{}}return t}var Rv=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],zv=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),Bv=e=>{if(!zv(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(`/`)},Vv=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?Bv(n):zv(n))?n:null},Hv=(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)Hv(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))Hv(r,t,n+1)}},Uv=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=Vv(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=Vv(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;Hv(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},Wv=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of Rv){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 Uv(r,i))t.add(e)}return Array.from(t)},Gv=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}}},Kv=e=>zv(e);function qv(e,t){let n=(0,Q.c)(5),r=pt(e,t),i=s(Jv),a;n[0]===r?a=n[1]:(a=dn(r),n[0]=r,n[1]=a);let o;return n[2]!==i||n[3]!==a?(o={goal:a,enabled:i},n[2]=i,n[3]=a,n[4]=o):o=n[4],o}function Jv(e){return e.sessionGoalEnabled}function Yv(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 At(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 Xv={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},Zv={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`},Qv=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=ot(),i=s(e=>e.isMobile),{goal:a,enabled:o}=qv(e??``,t),c=Yv(e??``,a),l=Pi(e??``,t),u=Dn(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,Tt(e,t))},[e,t,a,u]);let g=J(async n=>{if(!(!e||f)){p(!0);try{await _n(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),In.error(r(`chat.goal.toast.actionFailed`))}finally{p(!1)}}});if(!e||!o||!a)return null;let _=Math.max(0,(a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`?a.updatedAt:m)-(a.createdAt||m)),v=mt(_),y=a.tokenBudget?`${Gr(a.tokensUsed)}/${Gr(a.tokenBudget)}`:a.tokensUsed>0?Gr(a.tokensUsed):null,b=a.status===`active`?{icon:`pause`,labelKey:`chat.goal.action.pause`,next:`paused`}:a.status===`paused`||a.status===`blocked`||a.status===`budgetLimited`?{icon:`play`,labelKey:`chat.goal.action.resume`,next:`active`}:null,x=i?`text-[11px] leading-none text-muted-foreground`:`typography-meta text-muted-foreground`,S=i?`text-xs leading-5 text-foreground`:`typography-ui-label leading-5 text-foreground`,C=i?`size-3`:`size-3.5`;return(0,$.jsxs)(`div`,{className:Y(`flex w-full min-w-0 items-center`,i?`gap-1 py-0.5`:`gap-1.5 py-0.5 md:gap-2`,n),"aria-label":r(`chat.goal.row.aria`),title:c??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(C,`flex-shrink-0`),style:{color:Xv[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,S),children:a.note||c||``}),a.status===`active`&&(!l||l.type===`idle`)?(0,$.jsxs)(`span`,{className:Y(`flex flex-shrink-0 items-center gap-1`,x),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(C,`animate-spin`),"aria-hidden":`true`}),r(`chat.goal.status.evaluating`)]}):(0,$.jsx)(`span`,{className:Y(`flex-shrink-0`,x),children:r(Zv[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]})});Qv.displayName=`SessionGoalRow`;var $v=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=ot(),{goal:i,enabled:a}=qv(e??``,t),o=xn(e=>e.armed),s=xn(e=>e.setArmed),[c,l]=Z.useState(!1);if(d()||!a||!e&&!n||!o&&!i)return null;let u=i?.status===`complete`?`text-[var(--status-success)]`:i?.status===`blocked`||i?.status===`budgetLimited`?`text-[var(--status-error)]`:o||i?.status===`active`||i?.status===`paused`?`text-[var(--status-info)]`:``,f=async()=>{if(o){s(!1);return}if(!(!e||c)){l(!0);try{await Ln(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),In.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`})})]})});$v.displayName=`SessionGoalButton`;var ey=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=ot();if(!xn(ty)||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});ey.displayName=`SessionGoalObjectiveCounter`;function ty(e){return e.armed}var ny=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`plan-feature`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`]),ry=new Set([`new`,`compact`,`fork`,`undo`,`redo`]),iy=/^\/\u2003?([^\s]+)/i,ay=/^\/\u2003?goal\b/i,oy=(e,t)=>{if(t!==`normal`)return null;let n=e.trimStart().match(iy)?.[1]?.toLowerCase();return n&&ny.has(n)?n:null},sy=(e,t)=>oy(e,t)===`goal`?e.trimStart().replace(ay,``).trim():null,cy=(e,t)=>oy(e,t)!==null,ly=(e,t)=>{let n=oy(e,t);return n!==null&&ry.has(n)},uy=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},dy=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()}},fy=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,py=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,my=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},hy=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),gy=(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},_y=async e=>{let t=gn.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=hy(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}gy(n,a)?r+=1:i+=1}catch{try{gy(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},vy=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),yy=e=>e===`allow`||e===`ask`||e===`deny`,by=e=>{if(yy(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`&&yy(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(yy(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))yy(i)&&t.push({permission:n,pattern:e,action:i})}return t},xy=e=>{let t=by(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},Sy=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>xy(e.permission));let r=e.find(e=>e?.name===n);return!r||xy(r.permission)},Cy=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)},wy=null,Ty=new Set,Ey=()=>{for(let e of Ty)e()},Dy=e=>e===`chat`||e===`assistant`,Oy=()=>wy,ky=e=>{wy!==e&&(wy=e,Ey())},Ay=e=>{wy&&(e&&wy.surfaceID!==e||(wy=null,Ey()))},jy=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},My=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}},Ny=(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}),Py=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=Ny(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=Ny(e,`send`,i),o=Hm(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=Ny(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=Ny(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=Ny(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:Hm(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>Fm(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=Ny(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=Ny(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},Fy=(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)))},Iy=(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},Ly=(e,t)=>e.agents.some(e=>e.name===t),Ry=(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},zy=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return Ry(t,n,r,i)?i:void 0;if(a&&Ry(t,n,r,a))return a},By=e=>{let{sessionId:t,latestUserChoice:n,catalog:r,memory:i,sessionEntity:a,fallbackAgentName:o,transcriptReady:s=!0}=e;if(s&&n?.providerID&&n.modelID&&Iy(r,n.providerID,n.modelID)){let e=n.agent&&Ly(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&Ly(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):o&&Ly(r,o)?o:void 0,a=e?i?.getAgentModelVariantForSession?.(t,e,n.providerID,n.modelID):void 0,s=zy({catalog:r,providerID:n.providerID,modelID:n.modelID,historyVariant:n.variant,memoryVariant:a});return{agent:e,providerID:n.providerID,modelID:n.modelID,variant:s,source:`history`,messageId:n.id}}if(s&&i){let e=i.getSessionAgentSelection?.(t)??null,n=e&&Ly(r,e)?e:o&&Ly(r,o)?o:void 0;if(n){let e=i.getAgentModelForSession?.(t,n);if(e&&Iy(r,e.providerId,e.modelId)){let a=i.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=a&&Ry(r,e.providerId,e.modelId,a)?a:void 0;return{agent:n,providerID:e.providerId,modelID:e.modelId,variant:o,source:`session-memory`}}}let a=i.getSessionModelSelection?.(t);if(a&&Iy(r,a.providerId,a.modelId)){let e=n?i.getAgentModelVariantForSession?.(t,n,a.providerId,a.modelId):void 0,o=e&&Ry(r,a.providerId,a.modelId,e)?e:void 0;return{agent:n,providerID:a.providerId,modelID:a.modelId,variant:o,source:`session-memory`}}}let c=a?.model;if(c&&Iy(r,c.providerID,c.id)){let e=i?.getSessionAgentSelection?.(t)??null,n=(a?.agent&&Ly(r,a.agent)?a.agent:void 0)??(e&&Ly(r,e)?e:o&&Ly(r,o)?o:void 0),s=c.variant,l=s&&Ry(r,c.providerID,c.id,s)?s:void 0;return{agent:n,providerID:c.providerID,modelID:c.id,variant:l,source:`session-entity`}}return null},Vy=(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))},Hy=(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}},Uy=e=>e.editRevision<=0?!1:e.pinnedHistoryMessageId==null||e.latestHistoryMessageId==null||e.latestHistoryMessageId===e.pinnedHistoryMessageId,Wy=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}:{}}},Gy=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},Ky=500,qy=e=>Array.from(e).length,Jy=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},Yy=e=>qy(e)>=Ky,Xy=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},Zy=(e,t)=>{let n=t??e;return typeof n!=`string`||!Yy(n)?!1:le(typeof e==`string`?{text:``,references:[]}:e,n)},Qy=(e,t,n,r,i=1)=>{let a=qy(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}-${Jy(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},$y=e=>({text:e.text,references:e.references.map(e=>({...e}))}),eb=e=>e.map(e=>({...e,range:{...e.range}})),tb=(e,t)=>e.text===t.text&&JSON.stringify(e.references)===JSON.stringify(t.references),nb=(e,t,n)=>({document:$y(e),mentions:eb(t),selection:{...n}}),rb=()=>({undo:[],redo:[]}),ib=(e,t)=>({undo:[...e.undo,t].slice(-100),redo:[]}),ab=(e,t)=>{let n=e.undo.at(-1);return!n||!tb(n.after.document,t)?null:{history:{undo:e.undo.slice(0,-1),redo:[...e.redo,n]},snapshot:nb(n.before.document,n.before.mentions,n.before.selection)}},ob=(e,t)=>{let n=e.redo.at(-1);return!n||!tb(n.before.document,t)?null:{history:{undo:[...e.undo,n],redo:e.redo.slice(0,-1)},snapshot:nb(n.after.document,n.after.mentions,n.after.selection)}},sb=e=>({text:e?.text??``,references:e?.composerReferences??[]}),cb=e=>({text:e.text,references:e.references.map(e=>({...e}))}),lb=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),ub=e=>JSON.stringify([e.text,e.references]),db=(e,t)=>e!==null&&t!==null&&ce(e)===t,fb=(e,t,n)=>{let r=e?lb(e):null,i=r?n(r):void 0;return{document:D(sb(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?ce(r):null}},pb=(e,t,n,r)=>{if(!t||ce(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=ub(sb(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===ub(e)?`same-document-metadata`:`external-document`},mb=(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}]:[]})},hb=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),gb=(e,t,n,r,i=r)=>{let a=g(e,n,r,i);return{document:a.document,mentions:mb(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},_b=(e,t,n)=>({preview:{real:cb(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),vb=e=>({document:e.real,mentions:e.realMentions}),yb=(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)})},bb=(e,t)=>{let n=sb(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:yb(e.mentions,t?.mentions??[],r,i)}},xb=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=Yt})=>{let a=e?ce(e):null,o=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().drafts[a]:void 0,()=>void 0),s=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftHydration[a]??`idle`:`idle`,()=>`idle`),c=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftPersistence[a]:void 0,()=>void 0),[l,u]=(0,Z.useState)(()=>fb(e,t,i.getState().getDraft).document),[d,p]=(0,Z.useState)(()=>fb(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?lb(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)(rb());_.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=fb(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=rb(),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||!db(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(sb(t),x.current),t.mentions))})}},[a,F,i]),(0,Z.useEffect)(()=>{if(!a||E.current!==a||N.current)return;let e=pb(_.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(sb(o),x.current),o.mentions),h(`compose`))}},[a,F,o]);let L=(0,Z.useCallback)((e,t)=>{let n=w.current;if(!db(n,T.current)||N.current)return;let r=_.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:hb(t)});if(!a)return;let o=sb(a);return M.current={keyID:ce(n),revision:a.revision,fingerprint:ub(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=ib(P.current,{before:nb(e,t,n),after:nb(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=ae(e.text,e.references);return n?L(D(n,x.current),t):void 0},[L,z]),H=(0,Z.useCallback)((e,t,n=t,r)=>{let i=z(),a=cb(_.current),o=i?[]:b.current,s=gb(a,o,e,t,n),c=r?r(s.mentions,s.document):s.mentions;return L(s.document,c),s.removedReferences.length>0&&R(a,o,{start:s.selectionStart,end:s.selectionEnd},s.document,c,{start:s.selectionStart,end:s.selectionEnd}),{start:s.selectionStart,end:s.selectionEnd,requiresTextCorrection:s.requiresTextCorrection}},[L,z,R]),U=(0,Z.useCallback)((e,t)=>{let n=_.current,r=Math.max(0,Math.min(e.start,n.text.length)),i=Math.max(r,Math.min(e.end,n.text.length)),a=z(),o=g(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=mb(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,mb(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=cb(_.current),n=y(t,e);if(!n)return null;let r=z()?[]:b.current,i=mb(r,n.document,n.edit),a=O(n.document.text,n.caret),o=g(n.document,a.text,a.caret),s=mb(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`?ab(P.current,_.current):ob(P.current,_.current);return!t||!L(t.snapshot.document,t.snapshot.mentions)?null:(P.current=t.history,t.snapshot.selection)},[L]),q=(0,Z.useCallback)(e=>L(_.current,e),[L]),te=(0,Z.useCallback)(e=>{let t=N.current?{document:{text:e.text,references:[]},mentions:[]}:_b(_.current,b.current,e);`preview`in t&&(N.current=t.preview),h(`history-preview`),F(t.document,t.mentions)},[F]),ne=(0,Z.useCallback)(()=>{let e=N.current;if(!e)return;N.current=void 0,h(`compose`);let t=vb(e);F(t.document,t.mentions)},[F]),re=(0,Z.useCallback)(()=>{let e=w.current;if(!db(e,T.current))return null;let t=i.getState().getDraft(e);return{key:lb(e),keyID:ce(e),revision:t?.revision??0,document:cb(_.current),mentions:b.current.map(e=>({...e,range:{...e.range}})),epoch:k.current,runtime:i.getState().captureDraftRuntime()}},[i]),ie=(0,Z.useCallback)(e=>{let t=bb(e,i.getState().getDraft(e.key)),n=sb(i.getState().getDraft(e.key)),r=v(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:hb(t.mentions)});if(a){let e=sb(a);I(r,e)}return a},[I,i]),oe=(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:oe,replacePlainDocument:B,replaceMaterializedDocument:V,applyBrowserEdit:H,applyProgrammaticEdit:U,replaceProgrammaticText:W,insertReference:ee,deleteReference:G,restoreReferenceHistory:K,commitMentions:q,enterHistoryPreview:te,exitHistoryPreview:ne,captureSubmission:re,recoverSubmission:ie}),[H,U,re,q,G,l,te,ne,oe,s,m,ee,d,c,ie,V,B,W,K])};function Sb(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 Cb=`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`,wb=Fs(()=>Ue(()=>import(`./ToolOutputDialog-4-hGl1I6.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]))),Tb=[],Eb=[],Db=[],Ob=[],kb=/^@[^\s]+$/,Ab=({inputMode:e,message:t,showCommandAutocomplete:n,showSkillAutocomplete:r})=>e!==`shell`&&(n||r||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),jb=/^(https?:\/\/|mailto:)\S+$/i,Mb=560,Nb=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),Pb=(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)},Fb=e=>e.includes(`@`)?`paste`:`manual`,Ib=(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}},Lb=(e,t)=>kr(e,t).some(e=>e.role===`user`),Rb=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!en(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},zb=`file://`,Bb=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(`/`)},Vb=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(zb)?t:`file://${Bb(t)}`},Hb=e=>{if(!e)return[];let t=[...Wv(e).map(Gv),...Array.from(e.files||[]).map(e=>k(e)).filter(e=>!!e)];return Array.from(new Set(t.filter(Kv)))},Ub=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},Wb=e=>oa(e.path),Gb=(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)]})},Kb=Z.memo(ch),qb=Z.memo($l),Jb=Z.memo(Sg),Yb=Z.memo(Tg),Xb=Z.memo(Rh),Zb=Z.memo(({sessionId:e,directory:t})=>{let{t:n}=ot(),r=s(e=>e.isMobile),i=ni(e=>e.revertToMessage),a=ni(e=>e.forkFromMessage),o=ni(e=>e.handleSlashRedo),[c,l]=Z.useState(null),[u,d]=Z.useState(null),[f,p]=Z.useState(!0),m=Z.useRef(uv),h=Pr(),g=t||h,_=Vt(g),v=Ii(e??``,g,_),y=cn(e=>e.session,g),b=Z.useMemo(()=>{let t=v.messageOrder.map(e=>v.messagesByID[e]).filter(e=>!!e),n=pv({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:Rb(e.parts,C)})):[],[C,x,b]),T=w[0]?.id;Z.useEffect(()=>{p(!0)},[x,T]);let E=Z.useCallback(async t=>{if(!(!e||c)){l(t);try{let n=S.find(e=>e.id>t);n?await i(e,n.id,{skipRedoPush:!0}):await o(e,{fullUnrevert:!0})}finally{l(null)}}},[o,i,c,e,S]),D=Z.useCallback(async t=>{if(!(!e||u)){d(t);try{await a(e,t)}finally{d(null)}}},[a,u,e]);return!e||w.length===0?null:(0,$.jsx)(`div`,{className:Y(`w-full px-1`,r?`pb-1 text-xs`:`pb-2`),children:(0,$.jsxs)(`div`,{className:Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,r?`rounded-lg`:`rounded-xl`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex w-full items-center text-left hover:bg-[var(--interactive-hover)] transition-colors`,r?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`),onClick:()=>p(e=>!e),"aria-expanded":!f,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground flex-shrink-0`,children:[n(`chat.revertPopover.title`),` messages `,w.length]}),(0,$.jsx)(X,{name:`arrow-down-s`,className:Y(`ml-auto text-muted-foreground transition-transform`,r?`size-3.5`:`size-4`,!f&&`rotate-180`),"aria-hidden":`true`})]}),!f&&(0,$.jsx)(`div`,{className:Y(`flex flex-col overflow-y-auto`,r?`max-h-[8rem] gap-1 px-2 pb-1.5`:`max-h-[10.5rem] gap-1.5 px-3 pb-3`),children:w.map(e=>(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 items-center`,r?`gap-1.5`:`gap-2 py-1`),children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-ui-label text-foreground`,children:e.text}),(0,$.jsxs)(ca,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(c||u),onClick:()=>{D(e.id)},children:[u===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`git-branch`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.fork`)]}),(0,$.jsxs)(ca,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(c||u),onClick:()=>{E(e.id)},children:[c===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`arrow-go-forward`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.restore`)]})]},e.id))})]})})});Zb.displayName=`RevertedMessageDock`;var Qb=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?cx:void 0,v=f?lx:void 0,y;t[5]===a?y=t[6]:(y=Y(a,`text-current`),t[5]=a,t[6]=y);let b;t[7]===y?b=t[8]:(b=(0,$.jsx)(X,{name:`attachment-2`,className:y}),t[7]=y,t[8]=b);let x;t[9]!==m||t[10]!==i||t[11]!==g||t[12]!==_||t[13]!==v||t[14]!==b?(x=(0,$.jsx)(`button`,{type:`button`,className:i,onClick:g,onMouseDown:_,onPointerDownCapture:v,title:m,"aria-label":m,children:b}),t[9]=m,t[10]=i,t[11]=g,t[12]=_,t[13]=v,t[14]=b,t[15]=x):x=t[15];let S=x,C;t[16]!==S||t[17]!==m||t[18]!==d?(C=d?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:S}),(0,$.jsx)(La,{side:`top`,sideOffset:8,children:m})]}):S,t[16]=S,t[17]=m,t[18]=d,t[19]=C):C=t[19];let w;t[20]!==i||t[21]!==o||t[22]!==a||t[23]!==r||t[24]!==s||t[25]!==c||t[26]!==e.onMenuOpenChange||t[27]!==e.onOpenMobileSheet||t[28]!==n?(w=null,t[20]=i,t[21]=o,t[22]=a,t[23]=r,t[24]=s,t[25]=c,t[26]=e.onMenuOpenChange,t[27]=e.onOpenMobileSheet,t[28]=n,t[29]=w):w=t[29];let T;t[30]!==C||t[31]!==w?(T=(0,$.jsxs)(`div`,{className:`relative inline-flex`,children:[C,w]}),t[30]=C,t[31]=w,t[32]=T):T=t[32];let E;t[33]!==i||t[34]!==a||t[35]!==l||t[36]!==n?(E=l?(0,$.jsx)(`button`,{type:`button`,onClick:l,className:i,title:n(`chat.chatInput.actions.modelAgentSettings`),"aria-label":n(`chat.chatInput.actions.modelAgentSettings`),children:(0,$.jsx)(X,{name:`ai-agent`,className:Y(a,`text-current`)})}):null,t[33]=i,t[34]=a,t[35]=l,t[36]=n,t[37]=E):E=t[37];let D;return t[38]!==T||t[39]!==E?(D=(0,$.jsxs)(`div`,{className:`flex items-center gap-x-1.5`,children:[T,E]}),t[38]=T,t[39]=E,t[40]=D):D=t[40],D},(e,t)=>e.isVSCode===t.isVSCode&&e.footerIconButtonClass===t.footerIconButtonClass&&e.iconSizeClass===t.iconSizeClass&&e.onOpenSettings===t.onOpenSettings&&e.onMenuOpenChange===t.onMenuOpenChange&&e.onOpenMobileSheet===t.onOpenMobileSheet&&e.onOpenAndroidPickSheet===t.onOpenAndroidPickSheet&&e.withTooltip===t.withTooltip),$b=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=()=>Cy({permissionScopeSessionId:e.sessionId,newSessionDraftOpen:e.draftOpen,draftPermissionAutoAcceptEnabled:e.draftEnabled,permissionAutoAcceptEnabled:e.enabled,setDraftPermissionAutoAcceptEnabled:e.onSetDraftEnabled,setSessionAutoAccept:e.onSetSessionEnabled,onOpenSessionFirst:e.onOpenSessionFirst,onToggleFailed:e.onToggleFailed}),t[3]=e.draftEnabled,t[4]=e.draftOpen,t[5]=e.enabled,t[6]=e.onOpenSessionFirst,t[7]=e.onSetDraftEnabled,t[8]=e.onSetSessionEnabled,t[9]=e.onToggleFailed,t[10]=e.sessionId,t[11]=l):l=t[11];let u=e.enabled?`shield-check`:`shield`,d;t[12]===e.iconSizeClass?d=t[13]:(d=Y(e.iconSizeClass,`text-current`),t[12]=e.iconSizeClass,t[13]=d);let f;t[14]!==u||t[15]!==d?(f=(0,$.jsx)(X,{name:u,className:d}),t[14]=u,t[15]=d,t[16]=f):f=t[16];let p;t[17]!==a||t[18]!==e.enabled||t[19]!==e.footerIconButtonClass||t[20]!==e.saving||t[21]!==l||t[22]!==f?(p=(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:o,"aria-pressed":s,"aria-label":a,className:c,onClick:l,onMouseDown:ux,onPointerDownCapture:dx,children:f})}),t[17]=a,t[18]=e.enabled,t[19]=e.footerIconButtonClass,t[20]=e.saving,t[21]=l,t[22]=f,t[23]=p):p=t[23];let m;t[24]===a?m=t[25]:(m=(0,$.jsx)(La,{side:`top`,sideOffset:8,children:a}),t[24]=a,t[25]=m);let h;return t[26]!==m||t[27]!==p?(h=(0,$.jsxs)(Ra,{children:[p,m]}),t[26]=m,t[27]=p,t[28]=h):h=t[28],h}),ex=Z.memo(function(e){let t=(0,Q.c)(67),{isMobile:n,compact:r,footerIconButtonClass:i,stopFooterIconButtonClass:a,compactCircleButtonClass:o,sendIconSizeClass:s,stopIconSizeClass:c,canSend:l,canAbort:u,hasContent:d,currentSessionId:f,newSessionDraftOpen:p,draftSubmitting:m,submissionBlocked:h,sendPhase:g,queueFrozen:_,queueFallbackAvailable:v,onPrimaryAction:y,onAbort:b}=e,x=r!==void 0&&r,{t:S}=ot(),C,w,T,E,D;if(t[0]!==u||t[1]!==l||t[2]!==x||t[3]!==o||t[4]!==f||t[5]!==m||t[6]!==i||t[7]!==d||t[8]!==n||t[9]!==p||t[10]!==y||t[11]!==v||t[12]!==_||t[13]!==s||t[14]!==g||t[15]!==a||t[16]!==c||t[17]!==h||t[18]!==S){D=Symbol.for(`react.early_return_sentinel`);bb0:{let e=Vg({canSend:l,hasSessionTarget:!!(f||p),draftSubmitting:!!m,submissionBlocked:h,sendPhase:g,queueFrozen:_,queueFallbackAvailable:v}),r;t[24]===n?r=t[25]:(r=n?{onMouseDown:fx,onPointerDownCapture:px}:{},t[24]=n,t[25]=r);let b=r,O=g.inFlight,k=O&&g.flightKind===`queue`,A=O&&g.flightKind!==`queue`,j;t[26]!==u||t[27]!==v||t[28]!==_||t[29]!==k||t[30]!==A||t[31]!==S?(j=S(k?`chat.chatInput.actions.queuingMessageAria`:A?`chat.chatInput.actions.sendingMessageAria`:_&&v&&u?`chat.chatInput.actions.sendMessageAria`:u?`chat.chatInput.actions.queueMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[26]=u,t[27]=v,t[28]=_,t[29]=k,t[30]=A,t[31]=S,t[32]=j):j=t[32];let M=j;C=x?o??a??i:a??i,w=c;let N=!u&&(!e.sendDisabled||O),P;t[33]!==n||t[34]!==y?(P=e=>{n&&(e.preventDefault(),y())},t[33]=n,t[34]=y,t[35]=P):P=t[35];let F;t[36]!==u||t[37]!==O||t[38]!==k||t[39]!==A||t[40]!==S?(F=S(A||!u&&O?k?`chat.chatInput.actions.queuingMessageAria`:`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[36]=u,t[37]=O,t[38]=k,t[39]=A,t[40]=S,t[41]=F):F=t[41];let I;t[42]!==u||t[43]!==w||t[44]!==O||t[45]!==s||t[46]!==N?(I=N?(0,$.jsx)(Pg,{className:w,spinning:!!(O&&!u)}):(0,$.jsx)(X,{name:`send-plane-2`,className:s}),t[42]=u,t[43]=w,t[44]=O,t[45]=s,t[46]=N,t[47]=I):I=t[47];let L=(0,$.jsx)(`button`,{type:n?`button`:`submit`,"data-composer-send":`true`,"data-composer-circle":N?`true`:void 0,disabled:e.sendDisabled,"aria-busy":O||void 0,...b,onClick:P,className:Y(N?C:i,N?void 0:e.sendDisabled?e.disabledClass:`text-primary hover:text-primary`),"aria-label":F,children:I});if(!u){D=L;break bb0}let R=!x&&(d||k),z=!e.sendDisabled&&!k,B=x&&`h-full`;t[48]===B?T=t[49]:(T=Y(`relative z-30 overflow-visible`,B),t[48]=B,t[49]=T),E=R?(0,$.jsx)(`button`,{type:`button`,"data-composer-send":`true`,"data-composer-circle":z||k?`true`:void 0,disabled:e.sendDisabled||k,"aria-busy":k||void 0,...b,onClick:e=>{e.preventDefault(),!k&&y()},className:Y(z||k?C:i,`absolute z-30 bottom-full left-1/2 -translate-x-1/2 mb-1`,z||k?void 0:e.disabledClass),"aria-label":M,children:z||k?(0,$.jsx)(Pg,{className:w,spinning:k}):(0,$.jsx)(X,{name:`send-plane-2`,className:s})}):null}t[0]=u,t[1]=l,t[2]=x,t[3]=o,t[4]=f,t[5]=m,t[6]=i,t[7]=d,t[8]=n,t[9]=p,t[10]=y,t[11]=v,t[12]=_,t[13]=s,t[14]=g,t[15]=a,t[16]=c,t[17]=h,t[18]=S,t[19]=C,t[20]=w,t[21]=T,t[22]=E,t[23]=D}else C=t[19],w=t[20],T=t[21],E=t[22],D=t[23];if(D!==Symbol.for(`react.early_return_sentinel`))return D;let O;t[50]===C?O=t[51]:(O=Y(C,`relative z-30`),t[50]=C,t[51]=O);let k;t[52]===S?k=t[53]:(k=S(`chat.chatInput.actions.stopGeneratingAria`),t[52]=S,t[53]=k);let A;t[54]===w?A=t[55]:(A=Y(w),t[54]=w,t[55]=A);let j;t[56]===A?j=t[57]:(j=(0,$.jsx)(Ng,{className:A}),t[56]=A,t[57]=j);let M;t[58]!==b||t[59]!==O||t[60]!==k||t[61]!==j?(M=(0,$.jsx)(`button`,{type:`button`,"data-composer-stop":`true`,onClick:b,className:O,"aria-label":k,children:j}),t[58]=b,t[59]=O,t[60]=k,t[61]=j,t[62]=M):M=t[62];let N;return t[63]!==T||t[64]!==E||t[65]!==M?(N=(0,$.jsxs)(`div`,{className:T,children:[E,M]}),t[63]=T,t[64]=E,t[65]=M,t[66]=N):N=t[66],N},(e,t)=>e.isMobile===t.isMobile&&e.compact===t.compact&&e.footerIconButtonClass===t.footerIconButtonClass&&e.stopFooterIconButtonClass===t.stopFooterIconButtonClass&&e.compactCircleButtonClass===t.compactCircleButtonClass&&e.sendIconSizeClass===t.sendIconSizeClass&&e.stopIconSizeClass===t.stopIconSizeClass&&e.canSend===t.canSend&&e.canAbort===t.canAbort&&e.hasContent===t.hasContent&&e.currentSessionId===t.currentSessionId&&e.newSessionDraftOpen===t.newSessionDraftOpen&&e.draftSubmitting===t.draftSubmitting&&e.submissionBlocked===t.submissionBlocked&&e.sendPhase===t.sendPhase&&e.queueFrozen===t.queueFrozen&&e.queueFallbackAvailable===t.queueFallbackAvailable&&e.onPrimaryAction===t.onPrimaryAction&&e.onAbort===t.onAbort),tx=(e,t)=>`${e}${e?e.endsWith(`
|
|
6526
6526
|
|
|
6527
6527
|
`)?``:e.endsWith(`
|
|
@@ -6531,9 +6531,9 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,E as n,P as r,T
|
|
|
6531
6531
|
`:``}${t.endsWith(`
|
|
6532
6532
|
|
|
6533
6533
|
`)?t:t.endsWith(`
|
|
6534
|
-
`)?`${t}\n`:`${t}\n\n`}`,nx=(e,t)=>{let n=t.trim();return n?e?`${e}${/[\s\n]$/.test(e)?``:` `}${n} `:`${n} `:e},rx=(e,t,n,r)=>t?h({transportIdentity:e},t):n?m({transportIdentity:e},n):r,ix=[],ax=({onOpenSettings:e,scrollToBottom:r,showScrollToBottom:a=!1,onScrollToBottom:o,submissionBlocked:l=!1,surface:u})=>{let{t:f}=ot(),[p,m]=Z.useState({open:!1,title:``,content:``}),[h,g]=Z.useState(`normal`),[y,w]=Z.useState(!1),[T,E]=Z.useState(!1),[D,O]=Z.useState(!1),[k,j]=Z.useState(``),[M,N]=Z.useState(!1),[P,I]=Z.useState(``),[R,z]=Z.useState(!1),[V,H]=Z.useState(``),[q,te]=Z.useState(!1),[ie,ae]=Z.useState(``),[oe,se]=Z.useState([]),[le,ue]=Z.useState(0),[de,fe]=Z.useState(null),[pe,me]=Z.useState(null),he=Z.useRef(null),ge=Z.useRef(null),[_e,ve]=Z.useState(!1),ye=Z.useRef(null);Z.useEffect(()=>()=>{ye.current!==null&&window.clearTimeout(ye.current),he.current!==null&&window.clearTimeout(he.current),ge.current!==null&&window.clearTimeout(ge.current)},[]);let[be,xe]=Z.useState(!1),[Se,Ee]=Z.useState(!1),[Ae,Me]=Z.useState(null),Ne=Z.useId(),[Pe,Ie]=Z.useState(``),[Le,ze]=Z.useState(``),[Ve,He]=Z.useState(!1),[Ue,We]=Z.useState(!1),Ge=Z.useRef(0),Ke=Z.useCallback(()=>{Ge.current=Date.now()+500},[]),qe=Z.useRef(0),Je=Z.useRef(!1),[Ye,Xe]=Z.useState(-1),Ze=Z.useRef(()=>{}),Qe=Z.useRef((...e)=>Promise.resolve().then(()=>ni.getState().sendMessage(...e))).current,$e=ni(e=>e.currentSessionId),et=br(e=>e.currentProviderId),tt=br(e=>e.currentModelId),nt=br(e=>e.currentAgentName),rt=br(e=>e.currentVariant),it=br(e=>e.providers),st=br(e=>e.agents),ct=br(e=>e.getVisibleAgents),lt=Z.useMemo(()=>Tm(ct()),[ct,st]),ut=br(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),ft=br(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),mt=Z.useMemo(()=>{let e=it.find(e=>e.id===et)?.models?.find(e=>e.id===tt);return Mm(e)},[tt,et,it]),ht=we(e=>e.currentDirectory),gt=cc()??ht,{ensureSessionRenderable:vt}=Tu(),yt=ni(Z.useCallback(e=>$e?e.getDirectoryForSession($e):null,[$e])),xt=mr($e??``,yt??void 0),St=Z.useMemo(()=>Gy(xt),[xt]),wt=ji($e??``,yt??void 0).renderable,Tt=pt($e,yt??void 0),Et=Tt?.agent,Dt=Tt?.model?.id,Ot=Tt?.model?.providerID,At=Tt?.model?.variant,jt=br(e=>e.activeDirectoryKey),Mt=Z.useRef(0),Nt=Z.useRef(null),It=Z.useRef(null),Lt=ni(e=>e.newSessionDraft),zt=!!Lt?.open,Bt=ni(e=>e.newSessionDraft.draftSubmitting??!1),Vt=ni(e=>e.newSessionDraft.draftEstablishing??!1),Ht=Bt||Vt,Ut=ni(e=>e.openNewSessionDraft),Kt=ni(e=>e.setDraftPermissionAutoAcceptEnabled),qt=Fn(e=>e.autoAccept),Jt=Fn(e=>e.saving),Zt=Fn(e=>e.setSessionAutoAccept),en=ni(e=>e.setNewSessionDraftTarget),tn=ni(e=>e.availableWorktreesByProject),an=ni(e=>e.abortPromptSessionId),on=ni(e=>e.clearAbortPrompt),sn=Yt(e=>e.consumePendingInputText),cn=Yt(e=>e.pendingPresetSubmit),ln=Yt(e=>e.pendingInputText),un=Yt(e=>e.pendingInputMode),dn=Yt(e=>e.consumePendingSyntheticParts),fn=Yt(e=>e.activeAttachmentDraft),mn=ju(Z.useCallback(e=>{let t=$e??(zt?`draft`:``);return t?e.drafts[t]??Eb:Eb},[zt,$e])),hn=lr($e??``),_n=Z.useSyncExternalStore(t,n,n),vn=fn?.transportIdentity??null,yn=fn?.owner.kind??null,bn=fn?.owner.ownerID??null,Sn=Z.useMemo(()=>rx(_n,$e,Lt.draftID,vn&&yn&&bn?{transportIdentity:vn,owner:{kind:yn,ownerID:bn}}:null),[bn,yn,vn,_n,$e,Lt.draftID]),Cn=Sn?ce(Sn):null,wn=Yt(Z.useCallback(e=>Cn?e.draftAttachmentViews[Cn]:void 0,[Cn])),Dn=Yt(Z.useCallback(e=>Cn?e.drafts[Cn]:void 0,[Cn])),On=Z.useMemo(()=>{if(!Dn||!wn)return ix;let e=Dn.attachments.flatMap(e=>{let t=wn[e.attachmentRefID];return t?[t]:[]});return e.length===0?ix:e},[wn,Dn]);Z.useEffect(()=>{Sn&&Yt.getState().hydrateDraftAttachments(Sn)},[Sn]);let An=Lm(),Mn=s(e=>e.activeMainTab===`chat`),Nn=Pi($e??``,gt??void 0),Pn=Rm({kind:`primary`,surfaceID:`primary`,active:Mn,sessionID:$e,directory:gt??null,activity:{phase:Nn?.type===`busy`?`busy`:Nn?.type===`retry`?`retry`:`idle`,canAbort:Nn?.type===`busy`||Nn?.type===`retry`},draftKey:Sn,transportIdentity:_n,runtimeGeneration:c(),selection:{value:{providerID:et,modelID:tt,agent:nt,variant:rt},catalog:{providers:it,agents:lt,variants:mt,variantsReady:!ut,ready:!ut&&!ft,loading:ut||ft},flush:async()=>{let e=ni.getState().currentSessionId;if(!e)return;let t=c(),r=n(),i=Mt.current,a=e,o=ni.getState().getDirectoryForSession(a)??null,s=Di(o);if(br.getState().activeDirectoryKey!==s&&await br.getState().activateDirectory(o),c()!==t||n()!==r||ni.getState().currentSessionId!==a||br.getState().activeDirectoryKey!==s||Mt.current!==i)return;await vt(a,{directory:o??void 0});let l=ni.getState().getDirectoryForSession(a)??null,u=Di(l);if(c()!==t||n()!==r||ni.getState().currentSessionId!==a||l!==o||u!==s||br.getState().activeDirectoryKey!==s||Mt.current!==i)return;let d=br.getState(),f={providers:d.providers,agents:d.getVisibleAgents()};if(f.providers.length===0||f.agents.length===0)return;let p=Gy(kr(a,l??void 0));if(Uy({editRevision:i,pinnedHistoryMessageId:Nt.current,latestHistoryMessageId:p?.id??null}))return;let m=rn.getState(),h=ri().get(a),g=By({sessionId:a,latestUserChoice:p,catalog:f,memory:m,sessionEntity:h?.model?{agent:h.agent,model:{id:h.model.id,providerID:h.model.providerID,variant:h.model.variant}}:h?.agent?{agent:h.agent}:null,fallbackAgentName:d.currentAgentName});if(!g)return;let _=[a,g.source,g.messageId??``,g.agent??``,g.providerID,g.modelID,g.variant??``,s].join(`|`);It.current!==_&&(Vy(g,{currentAgentName:d.currentAgentName,setAgent:d.setAgent,setProvider:d.setProvider,setModel:d.setModel,setCurrentVariant:d.setCurrentVariant},{sessionId:a,memory:m}),It.current=_)},change:async e=>{Mt.current+=1;let t=ni.getState().currentSessionId;if(t){let e=ni.getState().getDirectoryForSession(t)??void 0,n=Gy(kr(t,e));Nt.current=n?.id??null}else Nt.current=null;let n=br.getState();Fy(e,{currentAgentName:n.currentAgentName,setAgent:n.setAgent,setProvider:n.setProvider,setModel:n.setModel,setCurrentVariant:n.setCurrentVariant,saveAgentModelSelection:n.saveAgentModelSelection},{sessionId:t,memory:rn.getState()})}},resources:{attachments:On,addAttachment:async e=>{Sn&&await Wn(Sn,()=>Yt.getState()).addLocal(e)},removeAttachment:async e=>Sn?Wn(Sn,()=>Yt.getState()).removeByAttachmentID(e):!1,clearAttachments:async()=>Sn?Wn(Sn,()=>Yt.getState()).clearRootAttachments():!1,restoreAttachments:async e=>Sn?Wn(Sn,()=>Yt.getState()).restoreRootAttachments(e):!1,pendingInput:ln===null?null:{text:ln,mode:un},consumePendingInput:sn,pendingPreset:cn,consumePendingPreset:()=>Yt.getState().consumePendingPresetSubmit(),consumeSyntheticParts:dn,restoreSyntheticParts:e=>Yt.setState(t=>({pendingSyntheticParts:[...e,...t.pendingSyntheticParts??[]]})),inlineDrafts:mn,removeInlineDraft:e=>{let t=$e??(zt?`draft`:``);t&&ju.getState().removeDraft(t,e)},restoreInlineDrafts:e=>{let t=$e??(zt?`draft`:``);!t||e.length===0||ju.setState(n=>{let r=n.drafts[t]??[],i=new Set(e.map(e=>e.id));return{drafts:{...n.drafts,[t]:[...e,...r.filter(e=>!i.has(e.id))]}}})},history:hn,captureRuntime:()=>Yt.getState().captureDraftRuntime(),getDraft:e=>Yt.getState().getDraft(e),abortPrompt:{sessionID:an,clear:on}},backend:{send:e=>{jy(e,{transportIdentity:n(),runtimeGeneration:c()});let t=My(e);return Qe(e.text??``,e.providerID,e.modelID,e.agent,e.attachments??[],e.agentMention,e.parts,e.variant,e.inputMode,t)},sendQueued:e=>Ji(e.sessionID??``,{delivery:e.options?.delivery===`steer`?`steer`:void 0,queueItemID:e.queueItemID,manual:e.manual,scope:e.queueScope?{state:`bound`,...e.queueScope}:void 0}),create:async()=>Ut(),compact:async e=>ke.summarizeSession(e.sessionID??``,e.providerID??``,e.modelID??``,e.directory),abort:e=>(e.sessionID&&Ft(e.sessionID),jn(e.sessionID??``))},shortcuts:{cycle:e=>Ze.current(e),new:()=>Ut(),abort:()=>($e&&Ft($e),jn($e??``)),submit:()=>{}},deliveryTarget:{kind:`primary`}}),Ln=zm(Pn,u??An);Bm(Ln),Z.useLayoutEffect(()=>{if(!Ln.active){Ay(Ln.surfaceID);return}return ky(Ln),()=>Ay(Ln.surfaceID)},[Ln]);let Rn=Py(Ln),zn=Ln.resources??(Ln.kind===`primary`?Pn.resources:void 0);if(!zn)throw Error(`chat-input-surface-resources-incomplete`);let Bn=[...zn.attachments],Hn=Ln.sessionID,Un=Vm(Ln,Ht),Gn=Ln.kind===`secondary`?Ln.commands.hasNewDraft:zt,qn=Gn,Yn=Ln.directory??gt,Xn=Ln.draftKey??Sn,Qn=Z.useMemo(()=>{if(Ln.kind===`secondary`)return Um(Ln,!1,!1);let e=Hn?Lb(Hn,yt??void 0):!1;return Um(Ln,e,Gn)},[Ln,Hn,yt,Gn]),$n=(e,t,n,r,i,a,o,s,c,l)=>Rn?Rn.send({providerID:t,modelID:n,agent:r,variant:s,text:e,attachments:i,agentMention:a,parts:o,systemContext:o?.filter(e=>e.synthetic).map(e=>({text:e.text,synthetic:!0})),inputMode:c,options:l}):Promise.reject(Error(`chat-input-surface-incomplete`)),rr=Z.useCallback(()=>Rn?Rn.abort():Promise.reject(Error(`chat-input-surface-incomplete`)),[Rn]),ar=kt(e=>e.projects),sr=kt(e=>e.activeProjectId),cr=kt(e=>e.setActiveProjectIdOnly),[ur,fr]=Z.useState(!1),[pr,hr]=Z.useState(!1),_r=Z.useMemo(()=>Hn?Ct({autoAccept:qt,sessions:[],sessionById:ri(),sessionID:Hn}):Lt.permissionAutoAcceptEnabled===!0,[Hn,Lt.permissionAutoAcceptEnabled,qt]),vr=br(e=>e.agents),yr=Ln.kind===`secondary`?Ln.selection.value.agent:nt,xr=Ln.kind===`secondary`?Tm(Ln.selection.catalog?.agents):vr,Sr=d()||Sy(xr,yr),Cr=Z.useCallback(()=>{In.error(f(`chat.chatInput.toast.togglePermissionAutoAcceptFailed`))},[f]),Er=Ln.selection.value,Or=Ln.selection.change,Ar=Ln.selection.catalog,jr=Z.useMemo(()=>({selection:{providerID:Er.providerID??``,modelID:Er.modelID??``,agent:Er.agent??null,variant:Er.variant},onChange:async e=>{if(!Or)throw Error(`chat-input-surface-selection-readonly`);await Or({...e,agent:e.agent??void 0,variant:e.variant})},disabled:!Ln.active,catalog:Ar}),[Ar,Or,Er.agent,Er.modelID,Er.providerID,Er.variant,Ln.active]);Z.useEffect(()=>{Mt.current=0,Nt.current=null,It.current=null},[$e]),Z.useEffect(()=>{if(Ln.kind!==`primary`||!$e||ut||ft||it.length===0||lt.length===0)return;let e=Di(yt);if(jt!==e)return;let t=rn.getState(),n={providers:it,agents:lt};if(Uy({editRevision:Mt.current,pinnedHistoryMessageId:Nt.current,latestHistoryMessageId:St?.id??null}))return;let r=By({sessionId:$e,latestUserChoice:St,catalog:n,memory:t,sessionEntity:Ot&&Dt?{agent:Et,model:{id:Dt,providerID:Ot,variant:At}}:Et?{agent:Et}:null,fallbackAgentName:nt,transcriptReady:wt});if(!r)return;let i=[$e,r.source,r.messageId??``,r.agent??``,r.providerID,r.modelID,r.variant??``,jt].join(`|`);if(It.current===i)return;if((r.agent===void 0||r.agent===nt)&&r.providerID===et&&r.modelID===tt&&r.variant===rt){It.current=i;return}if(br.getState().activeDirectoryKey!==e)return;let a=br.getState();Vy(r,{currentAgentName:a.currentAgentName,setAgent:a.setAgent,setProvider:a.setProvider,setModel:a.setModel,setCurrentVariant:a.setCurrentVariant},{sessionId:$e,memory:t}),It.current=i},[Ln.kind,$e,St,wt,it,lt,ut,ft,jt,yt,nt,et,tt,rt,Et,Dt,Ot,At]);let Pr=br(e=>e.getVisibleAgents),Ir=Ln.kind===`primary`?Pr():Db,Lr=br(e=>Ln.kind===`primary`?e.providers:Ob),Br=Ln.kind===`secondary`?Tm(Ln.selection.catalog?.agents):Ir,Vr=Ln.kind===`secondary`?Ln.selection.catalog?.providers??Ob:Lr,Hr=Ln.kind===`secondary`&&(!Ln.selection.catalog?.ready||!!Ln.selection.catalog.error),Ur=!Ln.active||!Ln.selection.change||Hr,Gr=s(e=>e.isMobile),Kr=s(e=>e.setImagePreviewOpen),qr=Z.useCallback(e=>{e.image&&(m(e),Kr(!0))},[Kr]),Jr=Z.useCallback(e=>{m(t=>({...t,open:e})),Kr(e)},[Kr]),Xr=ou(e=>e.pending),Zr=s(e=>e.inputBarOffset),Qr=s(e=>e.persistChatDraft),$r=s(e=>e.inputSpellcheckEnabled),ei=s(e=>e.isExpandedInput),ii=s(e=>e.setExpandedInput),ai=s(e=>e.setTimelineDialogOpen),oi=xb({draftKey:Xn,sessionTitles:new Map(Array.from(ri(),([e,t])=>[e,t.title||e])),persistenceEnabled:Qr}),si=oi.document,ci=si.text,{replacePlainDocument:ui,replaceProgrammaticText:di,applyBrowserEdit:fi,insertReference:hi,deleteReference:gi,enterHistoryPreview:_i,exitHistoryPreview:vi,captureSubmission:yi,recoverSubmission:Si,confirmedFileMentions:Ci,mentions:Ti}=oi,Oi=Z.useCallback((e,t)=>di(e,t),[di]),Ai=Z.useMemo(()=>new Set(Ci.map(e=>e.value)),[Ci]),Mi=Z.useRef(null),Ii=Z.useRef(!1),Li=Z.useRef(0),Ri=Z.useRef(null),Bi=Z.useRef(ci.length),Vi=Z.useRef(null),Hi=Z.useRef(0),Ui=Z.useRef(!1),Wi=Z.useRef(null),Gi=Z.useRef(!1),Ki=Z.useRef(null),qi=Z.useRef([]),Yi=Z.useRef(!1),Xi=Z.useRef(null),Zi=Z.useRef(!1),Qi=Z.useRef(null),$i=Z.useRef(null),ea=Z.useRef(null),ta=Z.useRef(ci),na=Z.useRef(new Set),ra=oi.getDocument,ia=Z.useCallback((e,t,n=[])=>Oi(e,(e,r)=>{let i=[],a=new Set(n);for(let e of t){let t=0,n=`@${e}`;for(;t<r.text.length;){let o=r.text.indexOf(n,t);if(o<0)break;i.push({kind:a.has(e)?`directory`:`file`,value:e,path:e,label:e,range:{start:o,end:o+n.length}}),t=o+n.length}}let o=new Set(e.map(e=>`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`));return[...e,...i.filter(e=>!o.has(`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`))]}),[Oi]),aa=Ph(Nh()),{git:sa,vscode:la}=Do(),ua=s(e=>e.shortcutOverrides.cycle_agent),fa=s(e=>e.shortcutOverrides),ma=Z.useMemo(()=>Ya(`cycle_agent`,ua?{cycle_agent:ua}:void 0),[ua]),ha=Z.useMemo(()=>Ya(`clear_all_messages`,fa),[fa]),{currentTheme:ga}=za(),va=Zo(),xa=ls(Yn),Ta=qo(e=>Yn?e.directories.get(Yn)?.status??null:null),Ea=qo(e=>e.ensureStatus),Oa=qo(e=>e.fetchStatus),[ka,Aa]=Z.useState(!1),ja=Z.useRef(null),[Ia,La]=Z.useState(!1);Z.useEffect(()=>{!Yn||!sa||Ea(Yn,sa)},[Yn,sa,Ea]),Z.useEffect(()=>{if(!(!Yn||!sa))return mi.onGitRefreshHint(e=>{Ub(e.directory)===Ub(Yn)&&Oa(Yn,sa)})},[Yn,sa,Oa]);let Ra=Z.useCallback(async e=>{if(!Hn)return;let t=ni.getState().getDirectoryForSession(Hn)||Yn||``;if(!t){In.error(f(`diffView.reviewDialog.toast.noSessionDirectory`));return}hr(!0);try{await Xt({originalSessionID:Hn,directory:t,providerID:e.providerID,modelID:e.modelID,agent:e.agent||void 0,variant:e.variant||void 0,generateHandoff:e.generateHandoff,returnAfterHandoffRequest:e.generateHandoff,autoReview:e.autoReview}),fr(!1)}catch(e){console.error(`[review-flow] failed to start review flow`,e),In.error(e instanceof Error?e.message:f(`diffView.reviewDialog.toast.startFailed`))}finally{hr(!1)}},[Hn,Yn,f]),Ba=ei&&!Gr,Ha=ei&&Gr,Ua=Ba||Ha,Wa=`1.5rem`,Ga=f(Hn||Gn?h===`shell`?`chat.chatInput.placeholder.shell`:Gr||Ia?`chat.chatInput.placeholder.chatCompact`:`chat.chatInput.placeholder.chat`:`chat.chatInput.placeholder.selectSession`),Ka=f(`chat.chatInput.placeholder.compactTap`);Z.useEffect(()=>{let e=Vi.current;if(!e)return;let t=e=>{let t=e>0&&e<Mb;La(e=>e===t?e:t)};if(t(e.clientWidth),typeof ResizeObserver>`u`){let n=()=>t(e.clientWidth);return window.addEventListener(`resize`,n),()=>window.removeEventListener(`resize`,n)}let n=new ResizeObserver(n=>{t(n[0]?.contentRect.width??e.clientWidth)});return n.observe(e),()=>n.disconnect()},[]);let qa=Bn,Ja=Z.useMemo(()=>new Set(Br.map(e=>e.name.toLowerCase())),[Br]),$a=Z.useRef(Ja);$a.current=Ja;let eo=Ab({inputMode:h,message:ci,showCommandAutocomplete:M,showSkillAutocomplete:R}),to=Pt({directory:Yn,enabled:eo}),no=Z.useMemo(()=>to.data??[],[to.data]),ro=Fi({directory:Yn,enabled:eo}),io=Z.useMemo(()=>ro.data??[],[ro.data]),ao=Z.useMemo(()=>new Map(io.map(e=>[e.name.toLowerCase(),e.name])),[io]),oo=Z.useMemo(()=>{let e=new Set([`init`,`review`,`undo`,`redo`,`fork`,`timeline`,`model`,`compact`,`summary`,`workspace-review`,`plan-feature`,`craft-goal`,`goal`,`catch-up`,`debug`,`weigh`,`explore`]);!Gr&&!d()&&e.add(`handoff-review`);for(let t of no)e.add(t.name.toLowerCase());for(let t of io)e.add(t.name.toLowerCase());return e},[no,io,Gr]),so=Z.useMemo(()=>{if(!ci||!ci.includes(`/`)||h===`shell`||oo.size===0)return[];let e=[],t=RegExp(`(^|\\s)/(${ee})?([A-Za-z0-9][A-Za-z0-9_-]*)`,`g`),n;for(;(n=t.exec(ci))!==null;){let t=n[2]??``,r=n[3];if(!oo.has(r.toLowerCase()))continue;let i=n.index+n[1].length,a=1+t.length+r.length,o=ao.get(r.toLowerCase());e.push(o?{start:i,end:i+a,style:`mentionCommand`,priority:102,skillName:o,visual:re({trigger:`/`,icon:`book-open`,label:o},ci.slice(i,i+a))}:{start:i,end:i+a,style:`mentionCommand`,visual:re({trigger:`/`,icon:`command`,label:r},ci.slice(i,i+a))})}return e},[ao,h,oo,ci]),co=pa(e=>e.snippets),lo=Z.useMemo(()=>{let e=new Set;for(let t of co){e.add(t.name.toLowerCase());for(let n of t.aliases??[])e.add(n.toLowerCase())}return e},[co]),uo=Z.useMemo(()=>{if(!ci||!ci.includes(`#`)||h===`shell`||lo.size===0)return[];let e=[],t=/(^|\s)#([A-Za-z0-9][A-Za-z0-9_-]*)/g,n;for(;(n=t.exec(ci))!==null;){let t=n[2];if(!lo.has(t.toLowerCase()))continue;let r=n.index+n[1].length;e.push({start:r,end:r+1+t.length,style:`mentionSnippet`})}return e},[h,lo,ci]),fo=Z.useMemo(()=>!ci||!ci.includes(`@`)||h===`shell`?[]:Wr(ci,{confirmedValues:Ai,agentNames:Ja}),[Ai,h,Ja,ci]),po=Z.useMemo(()=>{if(!ci||!ci.includes(`[`)||h===`shell`||qa.length===0)return[];let e=qa.filter(Fe),t=new Map(e.map(e=>[e.filename.trim().toLowerCase(),e.mimeType.startsWith(`image/`)?`image`:`attachment`]));return De(ci,e.map(e=>e.filename)).flatMap(e=>{let n=G(ci.slice(e.start+1,e.end-1)).trim(),r=t.get(n.toLowerCase());return[{...e,style:`mentionFile`,priority:101,visual:re({trigger:`[`,icon:r===`image`?`file-image`:`attachment-2`,label:n,suffix:`]`},ci.slice(e.start,e.end))}]})},[h,ci,qa]),mo=Z.useMemo(()=>{if(!ci||h===`shell`)return null;let e=[...xv(ci),...Lv(ci),...Ev(fo),...so,...uo,...po,...si.references.map(e=>({start:e.start,end:e.end,priority:103,...A(e)}))];return Sv(ci,e)},[po,so,uo,fo,si.references,h,ci]),ho=Z.useCallback(e=>(e??[]).map(e=>({...e,dataUrl:e.source===`server`&&e.serverPath?Vb(e.serverPath):e.dataUrl})),[]),[go,_o]=Z.useState(null),vo=Z.useRef(null),[yo,bo]=Z.useState(!1),[xo,So]=Z.useState(!1),[Co,wo]=Z.useState(null),[To,Eo]=Z.useState(null),Oo=C(e=>e.followUpBehavior),ko=Z.useMemo(()=>{let e=Rn?.queueScope;return e?{state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:e.deliveryTarget,runtimeGeneration:e.runtimeGeneration}:null},[Rn]),Ao=Wu({transportIdentity:ko?.transportIdentity??``,directory:ko?.directory??``,sessionID:ko?.sessionID??``}),Mo=Z.useMemo(()=>Hn?x(Hn):null,[Hn]),Fo=C(Z.useCallback(e=>ko?b(e,ko):Tb,[ko])),Io=C(Z.useCallback(e=>Mo?b(e,Mo):Tb,[Mo])),Lo=Z.useMemo(()=>Io.length===0?Fo:Fo.length===0?Io:[...Io,...Fo],[Fo,Io]),zo=Ao.mode===`server`?Tb:Lo,Uo=C(Z.useCallback(e=>ko?B(e,ko):Tb,[ko])),Go=C(e=>e.clearQueue),Ko=C(e=>e.removeFromQueue),Jo=zn.inlineDrafts,$o=Jo.length>0,[es,ns,as]=Z.useMemo(()=>{let e=0,t=0,n=0;for(let r of Jo)r.source===`preview-console`?e+=1:r.source===`preview-annotation`?t+=1:n+=1;return[e,t,n]},[Jo]),ss=Z.useCallback(e=>{for(let t of zn.inlineDrafts)t.source===e&&zn.removeInlineDraft(t.id)},[zn]),cs=Z.useCallback(()=>{for(let e of zn.inlineDrafts)e.source!==`preview-console`&&e.source!==`preview-annotation`&&zn.removeInlineDraft(e.id)},[zn]),fs=zn.history;Z.useEffect(()=>{ta.current=ci},[ci]),Z.useLayoutEffect(()=>{g(`normal`),Xe(-1)},[Xn?.transportIdentity,Xn?.owner.kind,Xn?.owner.ownerID]),Z.useLayoutEffect(()=>{if(!Gn||Gr)return;let e=()=>{let e=Mi.current;!e||e.disabled||e.focus({preventScroll:!0})};e();let t=window.requestAnimationFrame(e);return()=>window.cancelAnimationFrame(t)},[Gn,Gr]);let ps=Ag(Ln.kind===`primary`?Hn:null,Ln.kind===`primary`?Yn??void 0:void 0),ms=Ln.activity?.phase??ps.phase,hs=nr(Z.useCallback(e=>{if(!Hn)return!1;let t=e.runsByOriginalSessionID[Hn];return t?.status===`running`&&t.runtimeKey===i()},[Hn])),gs=J(e=>{Gr&&(Ke(),me(e),Mi.current?.blur(),br.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobilePanel`}))}),_s=zn.pendingInput,vs=zn.consumePendingInput;Z.useEffect(()=>{if(_s===null)return;let e=vs();if(e){if(e.mode===`append`){if(!e.text.trim())return;let t=tx(ta.current,e.text);ta.current=t,Oi(t)}else if(e.mode===`append-inline`){let t=nx(ta.current,e.text);ta.current=t,Oi(t)}else ui(e.text);setTimeout(()=>{Mi.current?.focus()},0)}},[_s,vs,ui,Oi]);let ys=ci.trim().length>0||qa.length>0||$o,bs=Ao.mode===`server`?Ao.items.length>0:zo.length>0||Uo.length>0,xs=!zf(Ao.mode),Ss=ys||bs,Cs=ni(e=>e.stagedMessageEdit?.sessionId===Hn?e.stagedMessageEdit.messageId:null),ws=ms===`busy`||ms===`retry`,Ts=Ln.activity?.canAbort??ws,Es=Z.useCallback(()=>{let e=Mi.current,t=e?.value??ra().text;t!==ra().text&&fi(t,e?.selectionStart??t.length,e?.selectionEnd??e?.selectionStart??t.length);let n=ra();return{message:n.text,document:n,hasContent:n.text.trim().length>0||qa.length>0||$o}},[fi,ra,$o,qa.length]),Ds=Z.useRef(async()=>{}),Os=Ln.surfaceID,ks=Lt?.draftID??null,As=gn(Z.useMemo(()=>_t(Os),[Os])),js=gn(Z.useMemo(()=>pn(ks),[ks])),Ns=Z.useMemo(()=>ti(As,js),[As,js]),Ps=(e=`send`)=>gn.getState().beginFlight(Os,e),Fs=()=>{gn.getState().endFlight(Os)},Ls=()=>gn.getState().isInFlight(Os),zs=Z.useRef(null);Z.useEffect(()=>{if(Ln.kind!==`primary`||!Cs){zs.current=null;return}zs.current!==Cs&&(zs.current=Cs,Am(Mi)||requestAnimationFrame(()=>Am(Mi)))},[Cs,Ln.kind]);let Bs=gn(Z.useMemo(()=>Yr(ks),[ks])),Vs=J(async()=>{let e=ni.getState().newSessionDraft.draftID;if(!e||!gn.getState().isEstablishing(e))return!1;let t=Es();if(!t.hasContent)return!1;let n=K(t.document,`queue-canonical`);if(!n.ok)return In.error(f(`chat.chatInput.toast.messageSendFailed`)),!1;if(await Ln.selection.flush(),!gn.getState().isEstablishing(e))return!1;let r=Hy(br.getState());if(!r?.providerID||!r?.modelID)return In.error(f(`chat.chatInput.toast.messageSendFailed`)),!1;let i=ho(qa);return gn.getState().enqueueEstablishingFollowUp({draftID:e,content:n.text,sendConfig:{providerID:r.providerID,modelID:r.modelID,...r.agent?{agent:r.agent}:{},...r.variant?{variant:r.variant}:{}},attachments:i,composerDocument:t.document})?(ui(``),Xe(-1),ii(!1),i.length>0&&zn.clearAttachments(),!0):!1}),Hs=()=>{if(Hn)return!1;let e=ni.getState().newSessionDraft.draftID;return gn.getState().isEstablishing(e)?(Vs(),!0):!1},Us=J(async()=>{if(!Ln.active||Ls())return;if(Hn){let e=ni.getState().stagedMessageEdit;if(e&&e.sessionId===Hn){ni.getState().beginMessageEditCommit(e.sessionId,e.messageId);try{await Gt(e.sessionId,e.messageId)}catch(e){console.warn(`[chat-input] staged-edit delete failed before queue admission`,e);return}finally{ni.getState().endMessageEditCommit(e.sessionId,e.messageId)}ni.getState().stagedMessageEdit===e&&ni.getState().clearStagedMessageEdit(e.sessionId)}}let e=Es(),t=K(e.document);if(!t.ok){In.error(f(`chat.chatInput.toast.messageSendFailed`));return}let r={chunks:t.chunks??[],semantics:t.semantics??[]},i=t.text,a=i.trimStart(),o=r.chunks.every(e=>e.provenance===`authored`)&&h===`normal`&&a.startsWith(`/`)?jo(a.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(o&&!Bo(o,e=>Fm(Ln,{name:e.name,source:`openchamber`}))||l||!e.hasContent||!Hn)return;if(xs||!Rt(Ln.deliveryTarget?.kind,Ao.mode)){Ds.current(ws?{delivery:`steer`}:void 0);return}if(r.chunks.every(e=>e.provenance===`authored`)&&cy(i,h)){Ds.current();return}if(!Ps(`queue`))return;let s=Ln.transportIdentity,u=Ln.runtimeGeneration,d=zn.captureRuntime(),p=ko,m=Ln.kind===`primary`?ko?.sessionID??Hn:null,g=[...zn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt),_=g.length>0?v(Pu(e.document.text,g),e.document.references).document:e.document,y=K(_,`queue-canonical`);if(!y.ok){Fs(),In.error(f(`chat.chatInput.toast.messageSendFailed`));return}let b=ho(qa),w=yi(),T=b,E=er(),D=!1,O=null,k=()=>{D&&p&&(Ao.actions.unstageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID}}),D=!1),O&&p&&(C.getState().unstageAdmission(p,O),O=null)},A=async e=>{k(),w&&Si(w),T.length>0&&await zn.restoreAttachments(T),e&&zn.restoreSyntheticParts(e),g.length>0&&zn.restoreInlineDrafts(g)};try{if(!p){In.error(f(`chat.chatInput.toast.messageSendFailed`));return}if(Ao.mode===`server`){if(!Xn){In.error(f(`chat.chatInput.toast.messageSendFailed`));return}bi({stage:()=>{Ao.actions.stageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:Ti}}),D=!0},clearComposer:()=>{ui(``),Xe(-1),ii(!1)}})}else bi({stage:()=>{C.getState().bindLegacyQueue(x(p.sessionID),p),C.getState().stageAdmission(p,{requestID:E.requestID,queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:Ti}),O=E.requestID},clearComposer:()=>{ui(``),Xe(-1),ii(!1)}});if(await Ln.selection.flush(),!Tn({transportIdentity:s,generation:u},{transportIdentity:n(),generation:c()})){await A();return}if(!Tn(d,zn.captureRuntime())){await A();return}if(m&&ni.getState().currentSessionId!==m){await A();return}if(p.transportIdentity!==n()||p.runtimeGeneration!==c()||p.sessionID!==(m??p.sessionID)||m&&S(ni.getState().getDirectoryForSession(m))!==S(p.directory)){await A();return}let t=p,r=Ln.kind===`primary`?(()=>{let e=br.getState(),t=m?ni.getState().getDirectoryForSession(m)??null:null;return Hy(e,{expectedConfigKey:Di(t),activeDirectoryKey:e.activeDirectoryKey})})():Ln.selection.value.providerID&&Ln.selection.value.modelID?{...Ln.selection.value,providerID:Ln.selection.value.providerID,modelID:Ln.selection.value.modelID}:void 0;if(!ir(r)){await A();return}if(Ao.mode===`server`){if(!Xn){await A(),In.error(f(`chat.chatInput.toast.messageSendFailed`));return}let n=Qt({draftKey:Xn,runtime:d,document:e.document,attachments:qa,inlineDrafts:g}),i=t.deliveryTarget.kind===`assistant`?zn.consumeSyntheticParts()?.map(e=>({...e,partID:e.partID??L()}))??null:null,a,o=[],s=t.deliveryTarget.kind===`assistant`?(()=>{let e=pi({plan:{chunks:y.chunks??[],semantics:y.semantics??[]},agents:Br,installedSkillNames:new Set(ki(ne,Yn).map(e=>e.name)),directory:Yn,root:va||Yn,confirmedFilePaths:Ci.map(e=>e.path),confirmedDirectoryPaths:Ci.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:qa});return o=e.attachments,dt({text:g.length>0?Pu(e.text,g):e.text,attachments:[...b,...e.attachments],semanticParts:li(e.semantics,t.directory),syntheticParts:i})})():void 0;try{let e=[...nn(b),...nn(o),...(i??[]).flatMap(e=>nn(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),In.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`));return}let c=s&&i?Dr(s,i.map(e=>({...e,partID:e.partID}))):void 0;try{let e=!1,o=await Kn({capture:n,admit:async()=>{let n=await Ao.actions.admit({requestID:E.requestID,scope:{directory:t.directory,sessionID:t.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,composerDocument:_,composerMentions:Ti,sendConfig:r,deliveryTarget:t.deliveryTarget,...s?{deliveryParts:s}:{},...c?{syntheticParts:c}:{},attachmentIssues:[],createdAt:E.createdAt},attachments:a});return n.status===`committed`&&(e=!0,D=!1),n},captureRuntime:zn.captureRuntime,getCurrentDraftKey:()=>Xn,getDocument:ra,consumeBody:()=>ui(``),getAttachments:()=>zn.attachments,removeAttachment:zn.removeAttachment,getInlineDrafts:()=>zn.inlineDrafts,removeInlineDraft:zn.removeInlineDraft});if(!e){await A(i),o.status===`stale`&&In.error(f(`chat.chatInput.toast.messageSendFailed`));return}if(o.status===`partial`){In.error(f(`chat.chatInput.toast.messageSendFailed`));return}o.status===`committed`&&!Gr&&Mi.current?.focus()}catch(e){await A(i),In.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}return}if(!C.getState().confirmAdmission(t,{requestID:E.requestID,sendConfig:r,attachments:b.length>0?b:void 0}).ok){await A(),In.error(f(`chat.chatInput.toast.messageSendFailed`));return}O=null;for(let e of g)zn.removeInlineDraft(e.id);b.length>0&&zn.clearAttachments(),Gr||Mi.current?.focus()}catch(e){await A(),In.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}finally{Fs()}}),Ws=J(()=>{vy(()=>Us(),()=>{In.error(f(`chat.chatInput.toast.messageSendFailed`))})}),Gs=J(async(e,t,n,r)=>{if(xs||!Ln.draftKey)return!1;try{let i=await Vn({content:e,composerDocument:n,composerMentions:r,attachments:t}),a=Yt.getState(),o=a.getDraft(Ln.draftKey);return Vf(await Wt({key:Ln.draftKey,expectedRevision:o?.revision??`absent`,payload:i,runtime:a.captureDraftRuntime()}))?!0:(In.error(f(`chat.chatInput.toast.messageSendFailed`)),!1)}catch{return In.error(f(`chat.chatInput.toast.messageSendFailed`)),!1}}),Ks=J(e=>{if(!(l||xs)){if(Rn){Rn.sendQueued(e,{options:{delivery:`steer`},manual:!0});return}In.error(f(`chat.chatInput.toast.messageSendFailed`))}}),qs=J(()=>{Ke(),me(`agent`),Mi.current?.blur(),br.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobileAgentPanel`})}),Js=Z.useCallback(()=>{bo(!0)},[]),Ys=Z.useCallback(()=>{So(!0)},[]),Xs=async e=>{if(!Ln.active||l||Hs()||Ls())return;let t=e?.queuedOnly??!1,i=e?.queuedMessageId,a=e?.delivery===`steer`&&ws?`steer`:void 0,o=e?.presetText==null?Es():{message:e.presetText,document:{text:e.presetText,references:[]},hasContent:e.presetText.trim().length>0||qa.length>0||$o},u=e?.presetText==null?yi():null,p=Bn,m=K(o.document,`direct-send-display`);if(!m.ok){In.error(f(`chat.chatInput.toast.messageSendFailed`));return}let g=m.text,v={chunks:m.chunks??[],semantics:m.semantics??[]},y=v.chunks.every(e=>e.provenance===`authored`),x=g.trimStart(),S=y?oy(x,h):null,w=y&&cy(g,h),T=y&&h===`normal`&&/^\/model(?:\s|$)/i.test(x),E=y&&h===`normal`&&x.startsWith(`/`)?jo(x.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(E&&!Bo(E,e=>Fm(Ln,{name:e.name,source:`openchamber`}))||t&&xs)return;if(!t&&T){N(!1),I(``),Gr?gs(`model`):(s.getState().setModelSelectorOpen(!0),br.getState().refreshCatalogsOnPickerOpen({source:`chatInput:modelCommand`}));return}if(!(!t&&S&&S!==`model`)){if(!t&&Hn&&bs&&xs)return;if(!t&&Hn&&bs&&Ao.mode===`server`){o.hasContent&&Ws();return}if(!t&&Hn&&bs){o.hasContent&&Ws();let e=zo[0];e&&Rn&&await Rn.sendQueued(e.queueItemID,{options:ws?{delivery:`steer`}:void 0});return}}let D=w?[]:i?zo.filter(e=>e.id===i):zo;if(t&&hs)return;if(t){if(D.length===0||!Hn)return}else if(!o.hasContent&&!bs||!Hn&&!Gn)return;if(!Hn&&Un||!Ps())return;let O=!Hn&&Gn&&!t&&!w?ni.getState().newSessionDraft.draftID??null:null,k=O?W(`msg`):void 0;if(O&&k&&!gn.getState().beginEstablishing({draftID:O,primaryMessageID:k})){Fs();return}let A=()=>{dr(),O&&gn.getState().clearEstablishing(O)},j=e=>{let t=ni.getState().currentSessionId,r=(t?ni.getState().getDirectoryForSession(t):null)??Yn??``;if(!t||!r){gn.getState().clearEstablishing(e);return}_y({draftID:e,sessionID:t,directory:r,transportIdentity:n(),runtimeGeneration:c(),admitServer:Ao.mode===`server`?async e=>Ao.actions.admit({requestID:e.requestID,scope:{directory:r,sessionID:t},item:{queueItemID:e.queueItemID,operationID:e.operationID,messageID:e.messageID,content:e.content,createdAt:e.createdAt,sendConfig:e.sendConfig,attachmentIssues:[],...e.composerDocument?{composerDocument:e.composerDocument}:{},...e.composerMentions?{composerMentions:e.composerMentions}:{}},attachments:e.attachments.length>0?nn(e.attachments):void 0}):void 0})};if(Hn&&!t&&!w&&hs){Fs(),Ws();return}let M=!t&&!w;M&&(ui(``),Xe(-1),ii(!1));let P=!1,F,L,R=!1;try{if(py({surfaceKind:Ln.kind,currentSessionId:Hn,queuedOnly:t,resourcePolicy:w,inputMode:h,localCommand:S})&&Hn){let e=ni.getState().getDirectoryForSession(Hn)??Yn??null,t=ni.getState().stagedMessageEdit;t&&t.sessionId===Hn&&(L={sessionId:t.sessionId,messageId:t.messageId},ni.getState().beginMessageEditCommit(t.sessionId,t.messageId));let n=br.getState(),r=Hy(n,{expectedConfigKey:Di(e),activeDirectoryKey:n.activeDirectoryKey});if(r?.providerID&&r?.modelID){let t=ho(qa);F=bt({sessionId:Hn,directory:e,content:o.message,providerID:r.providerID,modelID:r.modelID,agent:r.agent,files:t.map(e=>({type:`file`,mime:e.mimeType,url:e.dataUrl,filename:e.filename}))})}}let e=Ln.kind===`primary`?(()=>{if(t){let e=D[0]?.owner;if(e?.state===`bound`||e?.state===`unbound-legacy`)return e.sessionID;if(ko?.sessionID)return ko.sessionID}return Hn})():null,n=t?D[0]?.sendConfig:void 0;if(t&&n||await Ln.selection.flush(),e!==null&&ni.getState().currentSessionId!==e)return;let s=async()=>{let t=n?{...n}:Ln.kind===`primary`?(()=>{let t=br.getState();if(!e)return Wy({captured:Hy(t),surfaceSelection:Ln.selection.value});let n=ni.getState().getDirectoryForSession(e)??Yn??null;return Wy({captured:Hy(t,{expectedConfigKey:Di(n),activeDirectoryKey:t.activeDirectoryKey}),surfaceSelection:Ln.selection.value})})():Ln.selection.value.providerID&&Ln.selection.value.modelID?{...Ln.selection.value,providerID:Ln.selection.value.providerID,modelID:Ln.selection.value.modelID}:void 0;if(Ln.kind===`primary`&&e&&(!t?.providerID||!t?.modelID)){let n=ni.getState().getDirectoryForSession(e)??Yn??null,r=Di(n);if(br.getState().activeDirectoryKey!==r&&await br.getState().activateDirectory(n),ni.getState().currentSessionId===e){let e=br.getState();t=Wy({captured:Hy(e,{expectedConfigKey:Di(n),activeDirectoryKey:e.activeDirectoryKey}),surfaceSelection:Ln.selection.value})}}return t},c=await s(),l=!1,m=c?.providerID,g=c?.modelID,y=c?.agent,x=c?.variant;if(!m||!g){if(!l){l=!0;try{await br.getState().loadProviders({forceRefresh:!0,source:`chat-input-send-recovery`}),c=await s(),m=c?.providerID,g=c?.modelID,y=c?.agent,x=c?.variant}catch{}}if(!m||!g){console.warn(`Cannot send message: provider or model not selected`),In.error(f(`chat.chatInput.toast.messageSendFailed`));return}}Hn&&!t&&!w&&await Jn(Hn)&&await jn(Hn);let T={...a?{delivery:a}:{},commitStagedMessageEdit:!t,...F?{messageID:F.messageID,ticket:F}:k?{messageID:k}:{},...e?{sessionId:e,directoryHint:ni.getState().getDirectoryForSession(e)??Yn??null}:Ln.kind===`primary`&&Hn?{sessionId:Hn,directoryHint:ni.getState().getDirectoryForSession(Hn)??Yn??null}:{}},E=``,M=[],N,I=[],z=new Set(ki(ne,Yn).map(e=>e.name)),B=[],V=w?void 0:zn.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:Yn,a=new Set(ki(ne,i).map(e=>e.name)),o=pi({plan:r??Ei(t.content),agents:Br,installedSkillNames:a,directory:i,root:i,confirmedFilePaths:t.composerMentions?.filter(e=>e.kind===`file`||e.kind===`directory`).map(e=>e.path||e.value),confirmedDirectoryPaths:t.composerMentions?.filter(e=>e.kind===`directory`).map(e=>e.path||e.value),citationAttachments:t.attachments});if(B.push(...o.semantics),!N&&o.agent&&(N=o.agent),e===0)E=o.text,M=Rr([...ho(t.attachments),...o.attachments]);else{let e=ho(t.attachments);I.push({text:o.text,attachments:Rr([...e,...o.attachments])})}}if(!t&&o.hasContent){let e=ho(qa),t=pi({plan:v,agents:Br,installedSkillNames:z,directory:Yn,root:va||Yn,confirmedFilePaths:Ci.map(e=>e.path),confirmedDirectoryPaths:Ci.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:qa});B.push(...t.semantics),!N&&t.agent&&(N=t.agent),D.length===0?(E=t.text,M=Rr([...e,...t.attachments])):I.push({text:t.text,attachments:Rr([...e,...t.attachments])})}let H=Hn??(Gn?`draft`:null),U=[];if(!t&&H&&!w&&(U=[...zn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt)),U.length>0)if(D.length===0)E=Pu(E,U);else if(I.length>0){let e=I[I.length-1];e.text=Pu(e.text,U)}else E=Pu(E,U);if(V&&V.length>0&&I.push(...Ni(V)),Co&&I.push({text:Co.contextText,synthetic:!0}),To&&(I.push({text:To.instructionsText,synthetic:!0}),I.push({text:To.contextText,synthetic:!0})),I.push(...li(B,Hn&&ni.getState().getDirectoryForSession(Hn)||Yn)),!E&&M.length===0&&I.length===0)return;if(O&&k){if(!await zr({messageID:k,providerID:m,modelID:g,agent:y,text:E,attachments:M,additionalParts:I,agentMentionName:N}))return;if(!gn.getState().isEstablishing(O)){A();return}}let W=async()=>{if(A(),ko&&D.length>0&&C.setState(e=>{let t=_(ko),n=e.queuedMessages[t]??[],r=new Set(D.map(e=>e.id));return{queuedMessages:{...e.queuedMessages,[t]:[...D,...n.filter(e=>!r.has(e.id))]}}}),t)return V&&zn.restoreSyntheticParts(V),!0;zn.pendingInput?.text===o.message&&zn.consumePendingInput(),u&&Si(u);let e=!0;return p.length>0&&(e=await zn.restoreAttachments(p)),V&&zn.restoreSyntheticParts(V),U.length>0&&zn.restoreInlineDrafts(U),e};if(!w&&Hn&&i){let e=ko?b(C.getState(),ko).find(e=>e.id===i||e.queueItemID===i):void 0;ko&&e?.queueItemID&&e.operationID&&Ko(ko,e.queueItemID,e.operationID)}else!w&&Hn&&bs&&ko&&Go(ko);!t&&!w&&(ui(``),Xe(-1),ii(!1),fy({queuedOnly:t,resourcePolicy:w,rootAttachmentCount:p.length})&&zn.clearAttachments());let ee=()=>uy({currentSessionId:Hn,messageRef:ta,replacePlainDocument:ui}),G=E.trimStart();if(h===`normal`&&G.startsWith(`/`)){let e=jo(G.slice(1).trim()).split(/\s+/)[0]?.toLowerCase();if(!Bo(e,e=>Fm(Ln,{name:e.name,source:`openchamber`})))return;if(Hn&&(e===`undo`||e===`redo`)&&ly(G,h)&&ee(),e===`undo`&&Hn){try{await ni.getState().handleSlashUndo(Hn),r?.()}catch(e){In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`new`){ly(G,h)&&ee(),await Rn?.shortcut(`new`);return}if(e===`redo`&&Hn){try{await ni.getState().handleSlashRedo(Hn),r?.()}catch(e){In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`fork`&&Hn){await dy({command:`fork`,consumeCommandText:ee,forkSession:()=>ni.getState().forkCurrentSession(Hn),waitForConnection:wi,getDirectoryForSession:()=>ni.getState().getDirectoryForSession(Hn),summarizeSession:async()=>void 0,onCompactError:()=>void 0,onForkError:e=>{In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}});return}if(e===`timeline`&&Hn&&aa.timeline){ai(!0);return}if(e===`compact`&&Hn){dy({command:`compact`,consumeCommandText:ee,forkSession:async()=>void 0,waitForConnection:wi,getDirectoryForSession:()=>Ln.directory??``,summarizeSession:e=>Xn?Ln.backend.compact({operation:`compact`,surfaceID:Ln.surfaceID,transportIdentity:Ln.transportIdentity,runtimeGeneration:Ln.runtimeGeneration,sessionID:Hn,directory:e,draftKey:Xn,deliveryTarget:Ln.deliveryTarget,providerID:m,modelID:g,agent:y,variant:x}):Promise.reject(Error(`chat-input-surface-incomplete`)),onCompactError:()=>{In.error(f(`chat.chatInput.toast.compactFailed`))},onForkError:()=>void 0});return}if(e===`summary`&&Hn){try{await wi();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 Tr(`session.summary.visible`,{topic_line:t}),a=await Tr(`session.summary.instructions`,{topic_block:n});await $n(i,m,g,y,[],N,[{text:a,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.summaryFailed`))}return}if(e===`workspace-review`&&(Hn||Gn)){try{await wi();let e=await Tr(`session.review.visible`),t=await Tr(`session.review.instructions`);await $n(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.reviewFailed`))}return}if(e===`handoff-review`&&Hn&&!Gr&&!d()){fr(!0);return}if(e===`plan-feature`&&(Hn||Gn)){try{await wi();let e=await Tr(`session.plan.visible`),t=await Tr(`session.plan.instructions`);await $n(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.planFeatureFailed`))}return}if(e===`goal`&&(Hn||Gn)){A(),xn.getState().setArmed(!0);let e=sy(G,h)??``;ui(e),ta.current=e,Xe(-1),e||ii(!1);return}if(e===`craft-goal`&&(Hn||Gn)){try{await wi();let e=G.replace(/^\/\u2003?craft-goal\b/i,``).trim(),t=await Tr(`session.craftGoal.visible`,{idea_block:e?`\n\nHere is my initial idea:\n${e}`:``}),n=await Tr(`session.craftGoal.instructions`);await $n(t,m,g,y,[],N,[{text:n,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.craftGoalFailed`))}return}if(e===`catch-up`&&(Hn||Gn)){try{await wi();let e=await Tr(`session.catchup.visible`),t=await Tr(`session.catchup.instructions`);await $n(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.catchUpFailed`))}return}if(e===`debug`&&(Hn||Gn)){try{await wi();let e=await Tr(`session.debug.visible`),t=await Tr(`session.debug.instructions`);await $n(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.debugFailed`))}return}if(e===`weigh`&&(Hn||Gn)){try{await wi();let e=await Tr(`session.weigh.visible`),t=await Tr(`session.weigh.instructions`);await $n(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.weighFailed`))}return}if(e===`explore`&&(Hn||Gn)){try{await wi();let e=await Tr(`session.explore.visible`),t=await Tr(`session.explore.instructions`);await $n(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.exploreFailed`))}return}}let q=Hn&&ni.getState().getDirectoryForSession(Hn)||Yn;if(qn||Hn&&!Lb(Hn,q)){let e=await kn().catch(()=>null);e&&I.push({text:zi(e),synthetic:!0})}try{let e=pa.getState().expandText;E=await e(E);for(let t of I)t.synthetic||(t.text=await e(t.text))}catch(e){console.warn(`[ChatInput] Failed to expand snippets, sending original text:`,e)}R=!0;let te=$n(E,m,g,y,M,N,I.length>0?I:void 0,x,h,T);P=!0,te.finally(()=>{Fs(),L&&ni.getState().endMessageEditCommit(L.sessionId,L.messageId)}),O&&te.then(()=>{j(O)}).catch(()=>{gn.getState().clearEstablishing(O)}),typeof window>`u`?r?.():window.requestAnimationFrame(()=>{r?.()}),te.then(()=>{Co&&wo(null),To&&Eo(null)}).catch(e=>{F&&or(F),W().then(e=>{e||In.error(f(`chat.chatInput.toast.messageSendFailed`))});let t=e instanceof Error?e.message:typeof e==`string`?e:String(e??``),n=t.toLowerCase();console.error(`Message send failed:`,t||e);let r=n.includes(`timeout`)||n.includes(`timed out`)||n.includes(`may still be processing`)||n.includes(`being processed`)||n.includes(`failed to fetch`)||n.includes(`networkerror`)||n.includes(`network error`)||n.includes(`gateway timeout`)||n===`failed to send message`;if(n.includes(`payload too large`)||n.includes(`413`)||n.includes(`entity too large`)){In.error(f(`chat.chatInput.toast.attachmentsTooLarge`));return}if(r){p.length>0&&In.error(f(`chat.chatInput.toast.sendAttachmentsFailed`));return}In.error(t||f(`chat.chatInput.toast.messageSendFailed`))}),Gr||Mi.current?.focus()}finally{R||(F&&or(F),L&&ni.getState().endMessageEditCommit(L.sessionId,L.messageId)),P||(M&&u&&Si(u),Fs(),O&&j(O))}};Ds.current=Xs;let Zs=Z.useCallback(()=>{if(Hs()||Ls())return;let e=Es(),t=h===`normal`&&e.hasContent&&Hn&&(ws||hs),n=t&&zf(Ao.mode)&&Rt(Ln.deliveryTarget?.kind,Ao.mode);Oo===`queue`&&n?Ws():Oo===`steer`&&t||Oo===`queue`&&t&&!n?Ds.current(t?{delivery:`steer`}:void 0):Ds.current()},[h,Es,Hn,ws,hs,Oo,Ws,Ao.mode,Ln.deliveryTarget?.kind,Vs]),Qs=Z.useCallback(e=>{if(Ls())return;let t=(Mi.current?.value??ta.current).trim(),n=t?`${e}\n${t}`:e;Ds.current({presetText:n})},[]),$s=Z.useCallback(e=>{let t=nx(ra().text,e);Oi(t),Mi.current&&(Mi.current.value=t),setTimeout(()=>{Mi.current?.focus()},0)},[Oi]),ec=Z.useCallback(e=>{if(Ls())return;let t=nx(Mi.current?.value??ta.current,e);Ds.current({presetText:t})},[]),tc=zn.pendingPreset,nc=zn.consumePendingPreset;Z.useEffect(()=>{if(tc==null)return;let e=nc();e&&Qs(e)},[tc,nc,Qs]);let rc=Z.useCallback(()=>{ui(``),Xe(-1),Bn.length>0&&zn.clearAttachments(),ko&&Go(ko),N(!1),z(!1),te(!1),O(!1),h===`shell`&&g(`normal`)},[Bn.length,zn,Go,ko,ui,h]),ic=e=>{if(!Ln.active||jg(e))return;if(ha&&Va(e,ha)&&!Xr){let t=Mi.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),rc();return}}if(h===`shell`&&e.key===`Escape`){e.preventDefault(),g(`normal`);return}if(h===`shell`&&e.key===`Backspace`&&ci.length===0){e.preventDefault(),g(`normal`);return}if((e.key===`Backspace`||e.key===`Delete`)&&!e.metaKey&&!e.ctrlKey){let t=Mi.current,n=t?.selectionStart??ci.length,r=t?.selectionEnd??ci.length,i=gi({key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(i){let t=Ib(oi.getDocument().text,i.start);e.preventDefault(),Oi(t.text),requestAnimationFrame(()=>{Mi.current?.setSelectionRange(t.caret,t.caret),hc()}),gc(t.text,t.caret);return}let a=Oe(ci,Bn.filter(Fe).map(e=>e.filename),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(a){let t=new Set(a.removedFilenames.map(e=>e.toLowerCase())),n=Ib(a.text,a.caret);e.preventDefault(),Oi(n.text);for(let e of Bn)t.has(e.filename.toLowerCase())&&zn.removeAttachment(e.id);requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=n.caret,Mi.current.selectionEnd=n.caret),hc()}),gc(n.text,n.caret);return}let o=Tv(ci,ao.keys(),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(o){let t=Ib(o.text,o.caret);e.preventDefault(),Oi(t.text),requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=t.caret,Mi.current.selectionEnd=t.caret),hc()}),gc(t.text,t.caret);return}if(n===r&&!e.altKey){let t=e.key===`Backspace`?n-1:n;if(t>=0&&t<ci.length){let n=De(ci,Bn.map(e=>e.filename)).find(e=>t>=e.start&&t<e.end);if(n){let t=G(ci.slice(n.start+1,n.end-1)).trim(),r=Bn.find(e=>e.filename.toLowerCase()===t.toLowerCase()),i=ci[n.end]===` `?n.end+1:n.end,a=`${ci.slice(0,n.start)}${ci.slice(i)}`;e.preventDefault(),Oi(a),r&&zn.removeAttachment(r.id),requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=n.start,Mi.current.selectionEnd=n.start),hc()}),gc(a,n.start);return}let r=t;for(;r>0&&!/\s/.test(ci[r-1]);)--r;let i=t+1;for(;i<ci.length&&!/\s/.test(ci[i]);)i+=1;let a=ci.slice(r,i),o=a.slice(1);if(kb.test(a)&&!$a.current.has(o.toLowerCase())&&wr({mention:o,confirmed:Ai.has(o),terminated:i<ci.length&&/\s/.test(ci[i])})){let t=ci[i]===` `?i+1:i,n=`${ci.slice(0,r)}${ci.slice(t)}`;e.preventDefault(),Oi(n),requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=r,Mi.current.selectionEnd=r),hc()}),gc(n,r);return}}}}let t=(e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.metaKey&&!e.ctrlKey;if(M&&Qi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Qi.current.handleKeyDown(e.key);return}if(R&&$i.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),$i.current.handleKeyDown(e.key);return}if(q&&ea.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),ea.current.handleKeyDown(e.key);return}if(D&&Xi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Xi.current.handleKeyDown(e.key);return}if(Ba&&e.key===`Escape`){e.preventDefault(),ii(!1);return}let n=ma&&!ma.includes(`shift`)?Xa(`shift+${ma}`):``,r=n&&Va(e,n)?-1:+!!Va(e,ma);if(r!==0&&!M&&!R&&!q&&!D){e.preventDefault(),e.stopPropagation(),Rn?.shortcut(`cycle`,r),requestAnimationFrame(()=>{Mi.current?.focus({preventScroll:!0})});return}let i=M||R||q||D,a=Mi.current?.selectionStart===0&&Mi.current?.selectionEnd===0,o=Mi.current?.selectionStart===ci.length&&Mi.current?.selectionEnd===ci.length,s=!i&&(ci.length===0||a),c=!i&&(ci.length===0||o);if(h===`normal`&&!i&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=Mi.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&n>=0){let t=(t,n,r)=>{e.preventDefault(),Oi(t),requestAnimationFrame(()=>{let e=Mi.current;e&&(e.selectionStart=n,e.selectionEnd=r),hc()}),gc(t,r)},i={"`":["`","`"],"*":[`*`,`*`],_:[`_`,`_`],"~":[`~`,`~`],"(":[`(`,`)`],"[":[`[`,`]`],"{":[`{`,`}`],'"':[`"`,`"`],"'":[`'`,`'`]};if(r>n&&i[e.key]){let[a,o]=i[e.key],s=ci.slice(n,r);t(`${ci.slice(0,n)}${a}${s}${o}${ci.slice(r)}`,n+a.length,r+a.length);return}if(e.key==="`"&&n===r){let e=ci.slice(0,n);if(/(^|\n)``$/.test(e)){let n=`${e}\`\n\n\`\`\`${ci.slice(r)}`,i=e.length+2;t(n,i,i);return}}}}if(e.key===`ArrowUp`&&!e.metaKey&&!e.ctrlKey&&s&&fs.length>0){if(e.preventDefault(),Ye===-1)Xe(0),_i({text:fs[0],references:[]});else if(Ye<fs.length-1){let e=Ye+1;Xe(e),_i({text:fs[e],references:[]})}requestAnimationFrame(()=>{Mi.current?.setSelectionRange(0,0)});return}if(e.key===`ArrowDown`&&!e.metaKey&&!e.ctrlKey&&c&&Ye>=0){if(e.preventDefault(),Ye===0)Xe(-1),vi();else{let e=Ye-1;Xe(e),_i({text:fs[e],references:[]})}return}if(e.key===`Enter`&&!e.shiftKey){if(e.preventDefault(),Hs()||Ls())return;let t=e.ctrlKey||e.metaKey,n=h===`normal`&&ys&&Hn&&(ws||hs),r=n&&zf(Ao.mode)&&Rt(Ln.deliveryTarget?.kind,Ao.mode);Oo===`queue`?t||!n?Xs():r?Ws():Xs({delivery:`steer`}):t||!n?Xs():Xs({delivery:`steer`})}},ac=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}},[]),oc=Z.useCallback(()=>{if(!Ba){_o(null);return}if(!M&&!R&&!q&&!D){_o(null);return}let e=Mi.current,t=Vi.current;if(!e||!t)return;let n=e.selectionStart??ci.length,r=ac(e,n);if(!r)return;let i=e.getBoundingClientRect(),a=t.getBoundingClientRect(),o=i.top-a.top+(r.top-e.scrollTop),s=i.left-a.left+(r.left-e.scrollLeft),c=o-8,l=a.height-o-8,u=l>=260||l>=c?`below`:`above`,d=D?520:M||q?450:360,f=Math.max(8,Math.min(s-24,a.width-d-8)),p=Math.max(120,Math.min(260,u===`below`?l:c));_o({top:u===`below`?o+22:o-6,left:f,place:u,maxHeight:p})},[Ba,ac,ci.length,M,D,q,R]);Z.useLayoutEffect(()=>{oc()},[oc,ci,M,R,q,D,Ba]),Z.useEffect(()=>{if(!Ba)return;let e=()=>oc();return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[Ba,oc]);let sc=Z.useCallback(()=>{vo.current&&=(clearTimeout(vo.current),null),Aa(!0),vo.current=setTimeout(()=>{Aa(!1),vo.current=null},1800)},[]),lc=Z.useCallback(()=>{if(zn.abortPrompt.clear(),sc(),Ln.kind===`secondary`){Rn?.shortcut(`abort`);return}rr()},[rr,Rn,sc,Ln.kind,zn]),uc=Z.useCallback((e=1)=>{if(Hr)return;let t=tr(Br,Ln.selection.value.agent??yr,e);if(!t||!Ln.selection.change)return;let n=En({providerID:Ln.selection.value.providerID??``,modelID:Ln.selection.value.modelID??``,agent:Ln.selection.value.agent??null},t,Br,Vr);Ln.selection.change({...Ln.selection.value,...n,agent:n.agent??void 0}),Ln.kind===`primary`&&(s.getState().addRecentAgent(t),Ln.sessionID&&rn.getState().saveSessionAgentSelection(Ln.sessionID,t))},[Br,yr,Vr,Hr,Ln.kind,Ln.selection,Ln.sessionID]);Ze.current=uc;let dc=Z.useRef(null),[fc,pc]=Z.useState(null),mc=Z.useCallback(e=>{pc(t=>t===e?t:e)},[]),hc=Z.useCallback(e=>{let t=Mi.current;if(!t)return;let n=t.scrollTop;if(Ua){t.style.height=`100%`,t.style.maxHeight=`none`,t.style.overflowY=`auto`,fe(null),t.scrollTop!==n&&(t.scrollTop=n);return}t.style.overflow=`hidden`,t.style.overflowX=`hidden`,t.style.overflowY=`hidden`,(e?.allowShrink??!0)&&(t.style.height=`auto`);let r=t.ownerDocument?.defaultView,i=r?r.getComputedStyle(t):null,a=i?parseFloat(i.lineHeight):NaN,o=i?parseFloat(i.paddingTop):NaN,s=i?parseFloat(i.paddingBottom):NaN,c=Number.isNaN(o)||Number.isNaN(s)?16:o+s,l=Number.isNaN(a)?22:a,u=Sb({scrollHeight:t.scrollHeight||t.offsetHeight,dictationHeight:dc.current??0,lineHeight:l,paddingTotal:c});t.style.height=`${u.height}px`,t.style.maxHeight=`${u.maxHeight}px`,t.style.overflowY=u.overflowY,t.scrollTop!==n&&(t.scrollTop=n),fe(e=>e&&e.height===u.height&&e.maxHeight===u.maxHeight?e:{height:u.height,maxHeight:u.maxHeight})},[Ua]);Z.useLayoutEffect(()=>{let e=ci.length<Bi.current;Bi.current=ci.length,hc({allowShrink:e})},[hc,ci,Gr]),Z.useLayoutEffect(()=>{dc.current=fc,hc({allowShrink:fc===null})},[hc,fc]);let gc=Z.useCallback((e,t,n=`manual`,r)=>{let i=Ho({text:e,cursor:t,inputMode:h,mentionInputSource:n,insertedText:r});if(Ri.current=i,!i){N(!1),O(!1),z(!1),te(!1),H(``);return}if(i.kind===`slash-command`){I(i.query),N(!0),O(!1),z(!1),te(!1);return}if(N(!1),i.kind===`slash-skill`){H(i.query),z(!0),O(!1),te(!1);return}if(z(!1),H(``),i.kind===`snippet`){ae(i.query),te(!0),O(!1);return}te(!1),j(i.query),O(!0)},[h,I,j,N,O,z,te,H,ae]),_c=Z.useCallback((e,t,n,r=`manual`,i)=>{let a=e,o=t,s=n;if(h===`normal`&&!Ii.current&&oo.size>0&&e.includes(`/`)){let r=us(e,oo,n);r&&(a=r.text,o=t+(r.caret-n),s=r.caret)}let c=fi(a,o,s,(e,t)=>{let n=[...e];for(let e of gr(t.text,{agentNames:Ja,includeUnterminatedPastedReferences:r===`paste`}))n=ts(n,{kind:e.kind,value:e.value,path:e.value,label:e.value,range:{start:e.start,end:e.end}});return n}),l=ra(),u=c.requiresTextCorrection||o!==c.start||s!==c.end||a!==e;return requestAnimationFrame(()=>{let e=Mi.current;e&&jm(u,Ii.current)&&(e.value=l.text,e.setSelectionRange(c.start,c.end)),hc()}),gc(l.text,c.end,r,i),{document:l,selection:c}},[hc,fi,ra,h,Ja,oo,gc]),vc=Z.useCallback((e,t=`manual`)=>{if(!e)return;let n=Mi.current;if(!n){let n=ci+e;_c(n,n.length,n.length,t,e);return}let r=n.selectionStart??ci.length,i=n.selectionEnd??ci.length,a=`${ci.substring(0,r)}${e}${ci.substring(i)}`,o=r+e.length;_c(a,o,o,t,e)},[_c,ci]),yc=J((e,t)=>{let n=new Set(Ce(Bn.map(e=>e.filename),e,t));if(n.size!==0)for(let e of Bn)n.has(e.filename)&&zn.removeAttachment(e.id)}),bc=Z.useCallback(e=>{zn.removeAttachment(e.id)},[zn]),xc=Z.useCallback(()=>{Ui.current=!1,qi.current=[],Wi.current&&=(clearTimeout(Wi.current),null)},[]),Sc=Z.useCallback(()=>{Wi.current&&clearTimeout(Wi.current),Wi.current=setTimeout(()=>{xc()},700)},[xc]),Cc=Z.useCallback(()=>{Gi.current=!1,Ki.current&&=(clearTimeout(Ki.current),null)},[]),wc=Z.useCallback(()=>{Gi.current=!0,Ki.current&&clearTimeout(Ki.current),Ki.current=setTimeout(()=>{Gi.current=!1,Ki.current=null},700)},[]),Tc=Z.useCallback(e=>{!d()||!Ui.current||e.nativeEvent?.inputType===`insertFromDrop`&&(e.preventDefault(),xc())},[xc]),Ec=e=>{if(Xr)return;let t=e.nativeEvent;if(d()&&Ui.current){let n=qi.current;if(t?.inputType===`insertFromDrop`||n.some(t=>t.length>0&&e.target.value.includes(t))){xc();return}}let n=e.target.value;yc(ta.current,n);let r=e.target.selectionStart??n.length,i=t?.inputType?.startsWith(`insertFromPaste`)?Pb(ta.current,n):``,a=i.includes(`@`)||Gi.current;Gi.current&&Cc();let o=a?`paste`:`manual`;if(h===`normal`&&n.startsWith(`!`)){let e=n.slice(1),t=Math.max(0,r-1);g(`shell`),ui(e),hc(),N(!1),z(!1),O(!1),requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=t,Mi.current.selectionEnd=t)});return}_c(n,r,e.target.selectionEnd??r,o,i)};Z.useEffect(()=>()=>{xc(),Cc()},[xc,Cc]);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=Mi.current,i=r?.selectionStart??ci.length,a=r?.selectionEnd??ci.length,o=Xo(n,ci.slice(0,i),ci.slice(a)),s=`${ci.slice(0,i)}${o}${ci.slice(a)}`;yc(ci,s),ia(s,t)},[ci,ia,yc]),Oc=Z.useCallback(async e=>{let t=Hb(e.clipboardData);if(t.length>0&&(Hn||Gn)){e.preventDefault(),Dc(t);return}if(h===`normal`&&(Hn||Gn)){let t=Mi.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&r>n){let t=e.clipboardData.getData(`text`).trim(),i=ci.slice(n,r);if(jb.test(t)&&!/\s/.test(t)&&i.trim().length>0&&!i.includes(`](`)){e.preventDefault();let a=`${ci.slice(0,n)}[${i}](${t})${ci.slice(r)}`,o=n+1+i.length+2+t.length+1;Oi(a),requestAnimationFrame(()=>{let e=Mi.current;e&&(e.selectionStart=o,e.selectionEnd=o),hc()}),gc(a,o,Fb(t),t);return}}}let n=Array.from(e.clipboardData.files||[]).filter(e=>e.type.startsWith(`image/`)),r=Array.from(e.clipboardData.items||[]).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e),i=n.length>0?n:(()=>{if(r.length<=1)return r;let e=r.find(e=>/image\/(png|webp|jpe?g|gif)/i.test(e.type));return e?[e]:[r[0]]})(),a=e.clipboardData.getData(`text`);if(i.length===0){if(h===`normal`&&Zy(ra(),a)){e.preventDefault();let t=ra().text,n=Mi.current,r=n?.selectionStart??ci.length,i=n?.selectionEnd??ci.length,o=Qy(a,ci,ra().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>f(`chat.chatInput.pastedTextReference`,{index:e,count:t}),Xy(ra())),s=hi(r,i,{id:o.id,kind:`paste`,text:o.text,characterCount:o.characterCount,index:o.index,display:o.token},{inlineBoundaries:!0,padDocumentEdges:!0}),c=os(s.document.text,s.caret);Mi.current&&(Mi.current.value=s.document.text),requestAnimationFrame(()=>{Mi.current?.setSelectionRange(c,c),hc()}),gc(s.document.text,c),yc(t,s.document.text);return}a.includes(`@`)&&wc();return}if(!Hn&&!Gn){a.includes(`@`)&&wc();return}e.preventDefault();let o=je(i,[...Bn.map(e=>e.filename),...na.current]),s=Be(o),c=ra().text,l=Mi.current,u=l?.selectionStart??ci.length,d=l?.selectionEnd??ci.length,p=h===`normal`&&Zy(ra(),a)?Qy(a,ci,ra().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>f(`chat.chatInput.pastedTextReference`,{index:e,count:t}),Xy(ra())):null,m=a?`${a}${/\s$/.test(a)?``:` `}${s}`:s,g=Xo(m,ci.slice(0,u),ci.slice(d));if(p){let e=hi(u,d,{id:p.id,kind:`paste`,text:p.text,characterCount:p.characterCount,index:p.index,display:p.token},{inlineBoundaries:!0,padDocumentEdges:!0}),t=os(e.document.text,e.caret),n=`${e.document.text.slice(0,t)}${s}${e.document.text.slice(t)}`;_c(n,t+s.length,t+s.length,Fb(n),s),yc(c,n)}else vc(g,Fb(g)),yc(c,`${ci.slice(0,u)}${g}${ci.slice(d)}`);for(let e=0;e<i.length;e+=1){let t=o[e],n=Nb(i[e],t);na.current.add(t);try{await zn.addAttachment(n)}catch(e){console.error(`Clipboard image attach failed`,e),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.clipboardAttachFailed`))}finally{na.current.delete(t)}}},[zn,Dc,Bn,hc,Hn,ra,h,hi,wc,ci,Gn,vc,f,gc,_c,Oi,yc]),kc=Z.useCallback((e,t)=>{let n=e.currentTarget,r=n.selectionStart??0,i=n.selectionEnd??r;if(i<=r)return;let a=wv(r,i,[...De(ci,Bn.filter(Fe).map(e=>e.filename)),...Cv(ci,ao.keys()),...ra().references]),o=a?.start??r,s=a?.end??i,c=ci.slice(o,s),l=U(c);if(!(l===c&&!a))if(e.preventDefault(),e.clipboardData.setData(`text/plain`,l),t===`cut`){let e=`${ci.slice(0,o)}${ci.slice(s)}`;_c(e,o,o),requestAnimationFrame(()=>{Mi.current?.setSelectionRange(o,o),hc()})}else a&&(a.start!==r||a.end!==i)&&requestAnimationFrame(()=>{Mi.current?.setSelectionRange(o,s)})},[hc,Bn,ao,_c,ra,ci]),Ac=Z.useCallback(e=>{kc(e,`copy`)},[kc]),jc=Z.useCallback(e=>{kc(e,`cut`)},[kc]),Mc=e=>{let t=Mi.current,n=t&&document.activeElement===t?t.selectionStart??Li.current:Li.current;return ds(e,n)},Nc=()=>{Is(Gr)||Mi.current?.focus()},Pc=e=>{let t=Mc(ci.length),n=Ro(ci,t,Ri.current),r=ci.substring(0,t).lastIndexOf(`@`),i=e.relativePath&&e.relativePath.trim().length>0?e.relativePath.trim():Gc(e.path)||e.name,a=e.isDirectory?[i]:[],o=n?.start??(r===-1?t:r),s=n?.end??t,c=is(ci,o,s,`@${i}`);ia(c.text,[i],a),Li.current=c.caret,requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=c.caret,Mi.current.selectionEnd=c.caret),hc(),gc(c.text,c.caret)}),O(!1),j(``),Nc()},Fc=e=>{let t=Mc(ci.length),n=Ro(ci,t,Ri.current),r=ci.substring(0,t).lastIndexOf(`@`),i=n?.start??(r===-1?t:r),a=n?.end??t,o=is(ci,i,a,`@${e}`);Oi(o.text,t=>ts(t,{kind:`agent`,value:e,path:e,label:e,range:{start:o.start,end:o.end}})),Li.current=o.caret,requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=o.caret,Mi.current.selectionEnd=o.caret),hc(),gc(o.text,o.caret)}),O(!1),j(``),Nc()},Ic=J(e=>{Zi.current||(Zi.current=!0,(async()=>{try{let t=ni.getState().getAuthoritativeDirectoryForSession(e.id);if(!t){In.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}if(await vt(e.id,{directory:t}),!Nr(e.id,t)){In.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}Fr([{type:`session`,sessionId:e.id}],t).catch(()=>void 0);let n=ra(),r=Mc(n.text.length),i=Ro(n.text,r,Ri.current),a=n.text.substring(0,r).lastIndexOf(`@`),o=ri().get(e.id)?.title||e.title||e.id,s=i?.start??(a===-1?r:a),c=i?.end??r,l={id:`session:${e.id}:${L()}`,kind:`session`,sessionId:e.id,display:F({trigger:`@`,icon:`chat-thread`,label:o})},u=hi(s,c,l,{inlineBoundaries:!0,padDocumentEdges:!0}),d=os(u.document.text,u.caret);Li.current=d,requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=d,Mi.current.selectionEnd=d),hc(),gc(u.document.text,d)}),O(!1),j(``),Nc()}catch{In.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`))}finally{Zi.current=!1}})())}),Lc=J(e=>{let t=ra(),n=Mc(t.text.length),r=Ro(t.text,n,Ri.current)??No(t.text,n);if(!r)return!1;let i=hi(r.start,r.end,e,{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=i.document.references.some(t=>t.id===e.id),o=os(i.document.text,i.caret);return Li.current=o,requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=o,Mi.current.selectionEnd=o),hc(),gc(i.document.text,o),a&&(N(!1),z(!1))}),Nc(),a}),Rc=e=>{Lc({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&H(``)},zc=(e,t)=>{let n=Mc(ci.length),r=Ro(ci,n,Ri.current),i=ci.substring(0,n).lastIndexOf(`#`),a=r?.start??(i===-1?n:i),o=r?.end??n,s=`${ci.substring(0,a)}#${t} ${ci.substring(o)}`;Oi(s);let c=a+t.length+2;Li.current=c,requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=c,Mi.current.selectionEnd=c),hc(),gc(s,c)}),te(!1),ae(``),Nc()},Bc=(e,t=!1)=>{if(!Fm(Ln,e))return;let n=`/${e.name}`;if(!t&&e.isSkill){Lc({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&I(``);return}if(!t&&e.source===`opencode`&&!e.isSkill&&e.isBuiltIn!==!0&&Lc({id:`command:${e.name}:${L()}`,kind:`command`,commandName:e.name,reference:e.reference??e.name,display:F({trigger:`/`,icon:`command`,label:e.name})})){I(``);return}let r=e.isSkill?` ${n} `:`${n} `,i=us(r,new Set([...oo,e.name.toLowerCase()]),r.length);ui(i?.text??r);let a=Mi.current;if(a&&(a._commandMetadata=e),N(!1),I(``),t){Xs({presetText:n});return}let o=()=>{if(!Is(Gr)&&Mi.current){try{Mi.current.focus({preventScroll:!0})}catch{Mi.current.focus()}Mi.current.setSelectionRange(Mi.current.value.length,Mi.current.value.length)}};requestAnimationFrame(()=>{o(),requestAnimationFrame(o)}),setTimeout(o,60)};Z.useEffect(()=>{Hn&&Mi.current&&!Gr&&Mi.current.focus()},[Hn,Gr]),Z.useEffect(()=>{Gr||me(null)},[Gr]);let Vc=zn.abortPrompt.sessionID,Hc=zn.abortPrompt.clear;Z.useEffect(()=>{Vc&&Vc!==Hn&&Hc()},[Hn,Vc,Hc]),Z.useEffect(()=>{Yi.current=!!(Hn||Gn)},[Hn,Gn]);let Uc=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 Wv(e).length>0},[]),Wc=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)},[]),Gc=Z.useCallback(e=>{let t=e.replace(/\\/g,`/`).trim(),n=(va||``).replace(/\\/g,`/`).replace(/\/+$/,``);if(!n||t===n)return t;let r=`${n}/`;return t.startsWith(r)?t.slice(r.length):t},[va]),Kc=e=>{if(!Uc(e.dataTransfer))return;e.preventDefault(),e.stopPropagation(),Hi.current++;let t=e.dataTransfer.types?.includes(`application/x-openchamber-file-path`)??!1;t!==T&&E(t),(Hn||Gn)&&!y&&w(!0)},qc=e=>{Uc(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,(Hn||Gn)&&!y&&w(!0))},Jc=e=>{e.preventDefault(),e.stopPropagation(),Hi.current--,Hi.current<=0&&(Hi.current=0,w(!1),E(!1),xc())},Yc=()=>{Hi.current=0,w(!1),E(!1),xc()},Xc=async e=>{if(Hi.current=0,!Uc(e.dataTransfer)){xc();return}if(e.preventDefault(),e.stopPropagation(),w(!1),!Hn&&!Gn)return;let t=e.dataTransfer.getData(`application/x-openchamber-file-path`);if(t&&t!==`.`){let e=`@${t}`,n=Mi.current,r=ta.current;if(n){let t=n.selectionStart??Li.current,i=n.selectionEnd??t,a=is(r,t,i,e);Oi(a.text),requestAnimationFrame(()=>{n.selectionStart=a.caret,n.selectionEnd=a.caret,Li.current=a.caret,n.focus()})}else{let t=is(r,r.length,r.length,e);Oi(t.text)}xc();return}let n=Hb(e.dataTransfer);if(n.length>0){d()&&(qi.current=n),Dc(n),d()||xc();return}let r=Wc(e.dataTransfer);if(r.length>0){let e=Be(r.map(e=>e.name)),t=Xo(e,ta.current.slice(0,Mi.current?.selectionStart??ta.current.length),ta.current.slice(Mi.current?.selectionEnd??ta.current.length));vc(t);for(let e of r)try{await zn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.attachFileFailed`))}}xc()},Zc=e=>{Uc(e.dataTransfer)&&(e.preventDefault(),d()&&(Ui.current=!0,Sc()))},Qc=Z.useRef(null),Q=Z.useRef(null),$c=J((e=!0)=>{Ge.current=0;let t=()=>{let t=km(Mi);if(!t||(Am(Mi),!e))return;let n=t.value.length;try{t.setSelectionRange(n,n)}catch{}};t(),window.requestAnimationFrame(t)}),el=Z.useCallback(async e=>{let t=Array.isArray(e)?e:Array.from(e);if(t.length>0){let e=Be(t.map(e=>e.name)),n=Xo(e,ta.current.slice(0,Mi.current?.selectionStart??ta.current.length),ta.current.slice(Mi.current?.selectionEnd??ta.current.length));vc(n)}for(let e of t)try{await zn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.attachFileFailed`))}},[zn,vc,f]),tl=Z.useCallback(async()=>{try{let e=await la?.pickFiles?.(),t=Array.isArray(e?.files)?e.files:[],n=Array.isArray(e?.skipped)?e.skipped:[];if(n.length>0){let e=n.map(e=>`${e?.name||`file`}: ${e?.reason||`skipped`}`).join(`
|
|
6535
|
-
`);In.error(f(`chat.chatInput.toast.someFilesSkipped`,{summary:e}))}let r=t.map(e=>{if(!e?.dataUrl)return null;try{let[t,n]=e.dataUrl.split(`,`),r=e.mimeType||t?.match(/data:(.*);base64/)?.[1]||`application/octet-stream`;if(!n)return null;let i=atob(n),a=new Uint8Array(i.length);for(let e=0;e<i.length;e++)a[e]=i.charCodeAt(e);let o=new Blob([a],{type:r});return new File([o],e.name||`file`,{type:r})}catch(e){return console.error(`Failed to decode VS Code picked file`,e),null}}).filter(Boolean);r.length>0&&(
|
|
6536
|
-
`)})),e.length!==0&&el(e)},onRemoveAttachment:e=>{zn.removeAttachment(e)},onOpenModel:()=>gs(`model`),onCycleAgent:()=>uc(),onOpenAgent:qs,showScrollToBottom:!!(a&&o),scrollAria:f(`chat.scrollToBottom.aria`),onScrollToBottom:o??(()=>{}),autocompleteOpen:oe.length>0&&(M||R||D),autocompleteHighlightedIndex:le,autocompleteRows:oe,caret:Li.current,onAutocompleteAccept:Wl,onAutocompleteDismiss:Gl,chipHighlights:mo}),ql=Z.useRef(null);at(Kl?ql:null,()=>{let e=ql.current?.getBoundingClientRect().height??0;Ms(document.documentElement,e)});let Jl=Z.useRef(!1);Jl.current=yo||xo;let Yl=Z.useRef(!1),Xl=Z.useRef(0),Zl=Z.useRef(0),Ql=J(()=>{let e=ni.getState().stagedMessageEdit;!e||e.sessionId!==Hn||window.setTimeout(()=>{let t=ni.getState().stagedMessageEdit,n=document.activeElement,r=my({surfaceKind:Ln.kind,stagedSessionId:t?.sessionId??null,stagedMessageId:t?.messageId??null,blurredMessageId:e.messageId,submitInFlight:Ls(),focusHeld:Date.now()<Zl.current,overlayOpen:Xl.current>0||Jl.current,focusInsideComposer:n instanceof Element&&!!(n.closest(`[data-composer-content="true"]`)||n.closest(`[data-slot="dropdown-menu-content"]`))||Date.now()<Ge.current});r.action===`disarm`&&ni.getState().clearStagedMessageEdit(r.sessionId)},0)});Z.useEffect(()=>{if(!Gr||Re()||typeof window>`u`||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=()=>{Xl.current+=1},t=()=>{if(Xl.current=Math.max(0,Xl.current-1),Yl.current){Yl.current=!1;return}if(!Je.current||Jl.current||Xl.current>0)return;if(Za()){Je.current=!1;return}Je.current=!1,Zl.current=Date.now()+600,Mi.current?.focus(),document.activeElement===Mi.current&&ve(!0);let e=()=>{let e=Mi.current;!e||document.activeElement!==e||($l.current??e).scrollIntoView({block:`end`})};he.current!==null&&(window.clearTimeout(he.current),he.current=null),ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null),he.current=window.setTimeout(()=>{he.current=null,e()},300),ge.current=window.setTimeout(()=>{ge.current=null,e()},650)};return window.addEventListener(`oc:mobile-overlay-opened`,e),window.addEventListener(`oc:mobile-overlay-closed`,t),()=>{he.current!==null&&(window.clearTimeout(he.current),he.current=null),ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null),window.removeEventListener(`oc:mobile-overlay-opened`,e),window.removeEventListener(`oc:mobile-overlay-closed`,t)}},[Gr]),Z.useEffect(()=>{if(!Gr)return;if(zl){(_e||Date.now()-qe.current<800)&&(Je.current=!0);return}if(!Je.current)return;let e=window.setTimeout(()=>{if(Je.current=!1,Za())return;let e=Mi.current;e&&document.activeElement!==e&&e.focus({preventScroll:Re()})},180);return()=>window.clearTimeout(e)},[Gr,zl,_e]),Z.useEffect(()=>{if(!Gr||Re()||typeof document>`u`||_e||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=document.documentElement,t=window.setTimeout(()=>{document.activeElement!==Mi.current&&(window.scrollTo(0,0),document.body.scrollTop=0,e.scrollTop=0)},350);return()=>window.clearTimeout(t)},[Gr,_e]),Z.useEffect(()=>{Ie(``)},[Ae]);let $l=Z.useRef(null),eu=Gr?`px-1.5 py-1.5`:sl?`px-1.5 py-1`:`px-2.5 py-1.5`,tu=Gr?`h-8 w-8`:sl?`h-5 w-5`:`h-6 w-6`,nu=Gr?`h-4 w-4`:sl?`h-3.5 w-3.5`:`h-4 w-4`,ru=Gr?`h-6 w-6`:`size-full`,iu=Gr?`h-[1.125rem] w-[1.125rem]`:sl?`h-4 w-4`:`h-[1.125rem] w-[1.125rem]`,au=Y(`flex cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed`,pm),su=Y(au,tu),cu=Y(`flex cursor-pointer items-center justify-center transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed rounded-full hover:opacity-80`,tu),lu=Y(`flex cursor-pointer items-center justify-center transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed rounded-full hover:opacity-80`,`h-6 w-6`);Z.useEffect(()=>()=>{vo.current&&=(clearTimeout(vo.current),null)},[]);let uu=Gr?(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)(Jb,{onOpenAgentPanel:qs,onCycleAgent:()=>{Ke(),uc()},agentName:Ln.selection.value.agent,agents:Br,disabled:Ur}),(0,$.jsx)(Yb,{onOpenModel:()=>gs(`model`),providerID:Ln.selection.value.providerID,modelID:Ln.selection.value.modelID,provider:Vr.find(e=>e.id===Ln.selection.value.providerID),variant:Ln.selection.value.variant})]}):null,du=(0,$.jsxs)(`div`,{className:`oc-mobile-composer-attachment-content relative z-10 flex flex-wrap items-center gap-1 px-3 pt-1`,children:[(0,$.jsx)(bd,{attachments:Bn,onShowPopup:qr,onRemoveAttachedFile:bc}),Ln.kind===`primary`?(0,$.jsx)(wd,{attachedFiles:Bn,onAddVSCodeFile:(e,t,n)=>{Xn&&Wn(Xn,()=>Yt.getState()).addVSCodeFile(e,t,n)},onAddVSCodeSelection:(e,t)=>{if(Xn)return Wn(Xn,()=>Yt.getState()).addVSCodeSelection(e,t)}}):null]}),fu=mo?.map((e,t)=>(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(Dv,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)),pu=Gr?(0,$.jsxs)(`div`,{className:Y(`oc-mobile-composer-compact-chrome`,Ts&&`oc-mobile-composer-compact-chrome--aborting`,Ss&&!Ts&&`oc-mobile-composer-compact-chrome--sending`,a&&o&&`oc-mobile-composer-compact-chrome--with-scroll`),children:[(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`attach`,"data-composer-action":`true`,className:`composer-mobile-actions flex shrink-0 items-center`,children:(0,$.jsx)(Qb,{isVSCode:sl,footerIconButtonClass:su,iconSizeClass:iu,handlePickLocalFiles:nl,handlePickLocalImages:rl,openIssuePicker:Js,openPrPicker:Ys,onOpenMobileSheet:Ll,onOpenAndroidPickSheet:dl()?Rl:void 0})}),(0,$.jsxs)(`div`,{"data-mobile-composer-compact-slot":`trailing`,className:`ml-auto flex shrink-0 items-center justify-end gap-x-1`,children:[a&&o?(0,$.jsx)(`div`,{"data-composer-action":`true`,className:`flex shrink-0 items-center`,children:(0,$.jsx)(vg,{placement:`compact`,visible:a,onClick:o})}):null,Ts||Ss?(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`action`,"data-composer-action":`true`,className:`flex shrink-0 items-center justify-end`,children:(0,$.jsx)(ex,{isMobile:!0,compact:!0,footerIconButtonClass:su,stopFooterIconButtonClass:cu,compactCircleButtonClass:lu,sendIconSizeClass:nu,stopIconSizeClass:ru,canSend:Ss,canAbort:Ts,hasContent:!1,currentSessionId:Hn,newSessionDraftOpen:Gn,draftSubmitting:Un,submissionBlocked:l,sendPhase:Ns,queueFrozen:xs,queueFallbackAvailable:Ts||ws,onPrimaryAction:Zs,onAbort:lc})}):null]})]}):null,mu=Gr?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`div`,{className:`oc-mobile-composer-full-chrome flex w-full min-w-0 items-center gap-x-1.5`,"data-composer-action":`true`,children:[(0,$.jsxs)(`div`,{className:`composer-mobile-actions flex shrink-0 items-center gap-x-2 pl-1`,children:[(0,$.jsx)(Qb,{isVSCode:sl,footerIconButtonClass:su,iconSizeClass:iu,handlePickLocalFiles:nl,handlePickLocalImages:rl,openIssuePicker:Js,openPrPicker:Ys,onOpenSettings:e,onOpenMobileSheet:Ll,onOpenAndroidPickSheet:dl()?Rl:void 0}),Sr?(0,$.jsx)($b,{sessionId:Hn,draftOpen:Gn,draftEnabled:Lt.permissionAutoAcceptEnabled===!0,enabled:_r,saving:Hn?Jt:!1,footerIconButtonClass:su,iconSizeClass:iu,onSetDraftEnabled:Kt,onSetSessionEnabled:Zt,onOpenSessionFirst:Ut,onToggleFailed:Cr}):null,(0,$.jsx)($v,{sessionId:Hn,directory:yt??Yn,draftOpen:Gn}),(0,$.jsx)(ey,{length:ci.length})]}),uu,(0,$.jsx)(`div`,{className:`relative z-30 flex shrink-0 items-center justify-end gap-x-1.5`,children:(0,$.jsx)(ex,{isMobile:Gr,footerIconButtonClass:su,stopFooterIconButtonClass:cu,sendIconSizeClass:nu,stopIconSizeClass:ru,canSend:Ss,canAbort:Ts,hasContent:!!ys,currentSessionId:Hn,newSessionDraftOpen:Gn,draftSubmitting:Un,submissionBlocked:l,sendPhase:Ns,queueFrozen:xs,queueFallbackAvailable:Ts||ws,onPrimaryAction:Zs,onAbort:lc})})]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center`,ol),children:[(0,$.jsx)(Qb,{isVSCode:sl,footerIconButtonClass:su,iconSizeClass:iu,handlePickLocalFiles:nl,handlePickLocalImages:rl,openIssuePicker:Js,openPrPicker:Ys,onOpenSettings:e,withTooltip:!0}),Sr?(0,$.jsx)($b,{sessionId:Hn,draftOpen:Gn,draftEnabled:Lt.permissionAutoAcceptEnabled===!0,enabled:_r,saving:Hn?Jt:!1,footerIconButtonClass:su,iconSizeClass:iu,onSetDraftEnabled:Kt,onSetSessionEnabled:Zt,onOpenSessionFirst:Ut,onToggleFailed:Cr}):null,(0,$.jsx)($v,{sessionId:Hn,directory:yt??Yn,draftOpen:Gn}),(0,$.jsx)(ey,{length:ci.length})]}),(0,$.jsxs)(`div`,{className:Y(`relative z-30 flex flex-1 items-center justify-end md:gap-x-1.5`,ol),children:[(0,$.jsx)(Kb,{className:`min-w-0 flex-1 justify-end`,composerTextareaRef:Mi,selectionAdapter:jr}),(0,$.jsx)(qb,{radius:Wa,isMobile:Gr,footerIconButtonClass:su,footerPaddingClass:eu,iconSizeClass:iu,sendIconSizeClass:nu,onInsert:$s,onInsertAndSend:ec,onContentHeightChange:mc,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}),(0,$.jsx)(ex,{isMobile:Gr,footerIconButtonClass:su,stopFooterIconButtonClass:cu,sendIconSizeClass:nu,stopIconSizeClass:ru,canSend:Ss,canAbort:Ts,hasContent:!!ys,currentSessionId:Hn,newSessionDraftOpen:Gn,draftSubmitting:Un,submissionBlocked:l,sendPhase:Ns,queueFrozen:xs,queueFallbackAvailable:Ts||ws,onPrimaryAction:Zs,onAbort:lc})]})]}),hu=J(()=>{if(Gr){Zl.current=Date.now()+600;let e=()=>{Mi.current?.focus({preventScroll:Re()}),document.activeElement===Mi.current&&ve(!0)};e(),window.requestAnimationFrame(e);return}let e=()=>{if(!Am(Mi))return;let e=km(Mi);if(!e)return;let t=e.value.length;try{e.setSelectionRange(t,t)}catch{}};e(),window.requestAnimationFrame(()=>{e(),window.setTimeout(e,0)})}),gu=yt??Yn,{goal:_u,enabled:vu}=qv(Hn??``,gu),yu=(0,$.jsx)(Sp,{onEditMessage:Gs,onSendMessage:Ks,onEditCommitted:hu,draftKey:Xn,scope:ko,draftTarget:Xn?{key:Xn,expectedRevision:()=>zn.getDraft(Xn)?.revision??`absent`}:null,clientPendingItems:Bs,onRemoveClientPending:e=>{let t=gn.getState().removeEstablishingFollowUp(e);t&&(t.content&&ui(t.content),t.attachments.length>0&&zn.restoreAttachments(t.attachments))},trailing:Hn&&vu&&_u?(0,$.jsx)(Qv,{sessionId:Hn,directory:gu}):null});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`form`,{ref:$l,onSubmit:e=>{e.preventDefault(),Zs()},onPointerDownCapture:e=>{if(!Gr)return;let t=e.target;t instanceof Element&&(t.closest(`textarea[data-chat-input="true"]`)||t.closest(`[data-chat-prompt-attachments="true"]`)||t.closest(`button, [role="button"], a, label, input, select, [data-composer-action="true"], [data-chat-input-footer="true"]`)&&(Ke(),e.preventDefault()))},className:Y(`relative w-full pt-0 pb-4`,Ba&&`flex h-full min-h-0 flex-col pt-4`,Ha&&`flex h-full min-h-0 flex-col pt-1`,Gr&&`bottom-safe-area oc-mobile-composer`),"data-native-ios-composer":Kl?`true`:void 0,style:Gr&&Re()&&!Kl&&Zr>0&&!_e?{marginBottom:`${Zr}px`}:void 0,children:[qn&&!Ba&&!Gr&&!sl&&!Al?(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:Gb(pl?f(`chat.emptyState.draftTitleWithProject`,{project:pl}):f(`chat.emptyState.draftTitle`),pl)})}):null,(0,$.jsxs)(`div`,{className:Y(`chat-input-column relative overflow-visible`,Ua&&`flex flex-1 min-h-0 flex-col`),children:[Kl?null:(0,$.jsx)(xd,{attachments:Bn,onShowPopup:qr,onRemoveAttachedFile:bc}),(0,$.jsx)(Bp,{}),$o&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pb-2`,children:[as>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ga?.colors?.surface?.elevated,borderColor:ga?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`chat.chatInput.reviewComments`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ga?.colors?.status?.info},children:as}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:cs,"aria-label":f(`chat.chatInput.reviewCommentsRemove`),title:f(`chat.chatInput.reviewCommentsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,es>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ga?.colors?.surface?.elevated,borderColor:ga?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`chat.chatInput.devServerLogs`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ga?.colors?.status?.info},children:es}),(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:()=>ss(`preview-console`),"aria-label":f(`chat.chatInput.devServerLogsRemove`),title:f(`chat.chatInput.devServerLogsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,ns>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ga?.colors?.surface?.elevated,borderColor:ga?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`chat.chatInput.previewAnnotations`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ga?.colors?.status?.info},children:ns}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:()=>ss(`preview-annotation`),"aria-label":f(`chat.chatInput.previewContextRemove`),title:f(`chat.chatInput.previewContextRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null]}),Co&&!sl&&(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:()=>bo(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[Co.author?.avatarUrl&&(0,$.jsx)(`img`,{src:Co.author.avatarUrl,alt:Co.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`#`,Co.number,Co.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:f(`chat.chatInput.linked.byAuthor`,{author:Co.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:Co.title})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:Co.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.issue.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{wo(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.issue.removeAria`),title:f(`chat.chatInput.linked.issue.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),To&&!sl&&(0,$.jsx)(`div`,{className:`pb-2 w-full px-1`,children:(0,$.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 text-sm h-5 px-1`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>So(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[To.author?.avatarUrl&&(0,$.jsx)(`img`,{src:To.author.avatarUrl,alt:To.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[f(`chat.chatInput.linked.pr.number`,{number:To.number}),To.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:f(`chat.chatInput.linked.byAuthor`,{author:To.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:To.title}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0 typography-meta`,children:[To.head,` → `,To.base]})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:To.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.pr.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{Eo(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.pr.removeAria`),title:f(`chat.chatInput.linked.pr.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),(0,$.jsx)(Zb,{sessionId:Hn,directory:yt??Yn}),(0,$.jsxs)(`div`,{className:Gr?`relative oc-mobile-composer-stack`:`contents`,children:[(0,$.jsxs)(`div`,{className:Gr?`oc-mobile-composer-expanded-layer`:`contents`,children:[(0,$.jsx)(`div`,{className:Gr?`oc-mobile-composer-reveal`:`contents`,children:(0,$.jsxs)(`div`,{ref:ql,"data-native-composer-accessories":`true`,children:[(0,$.jsx)(Xb,{showAbortStatus:ka,showAssistantStatus:!1,showTodos:!0,leftAccessory:Gn||!jl?null:(0,$.jsx)(gg,{})}),!Gr&&cl?(0,$.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[ll?(0,$.jsxs)(Ca,{value:ll.id,open:Ve,onValueChange:Pl,onOpenChange:e=>{He(e),e||ze(``)},children:[(0,$.jsx)(Pa,{asChild:!0,size:`sm`,children:(0,$.jsxs)(`button`,{type:`button`,className:Y(`group relative inline-flex h-6 min-w-0 w-fit max-w-[42vw] items-center rounded-lg !border-0 px-1.5 py-1 pr-1.5 typography-micro font-medium text-foreground/80 transition-[padding] hover:pr-5 focus-visible:pr-5 data-[popup-open]:pr-5 sm:max-w-[18rem]`,dm),children:[(0,$.jsx)(_a,{children:Il(ll)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`pointer-events-none absolute right-1 size-3.5 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100 group-data-[popup-open]:opacity-100`,"aria-hidden":`true`})]})}),(0,$.jsxs)(Sa,{fitContent:!0,children:[(0,$.jsx)(Fa,{autoFocus:!0,value:Le,onChange:e=>ze(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:f(`chat.chatInput.draftPicker.searchProjects`),className:`mb-1 h-8 min-w-56`}),ar.filter(e=>Na(Wb(e),Le)||Na(e.path,Le)).map(e=>(0,$.jsx)(Ma,{value:e.id,className:`max-w-[24rem] truncate`,children:Il(e)},e.id)),(0,$.jsx)(ba,{}),(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left typography-ui-label text-foreground hover:bg-interactive-hover`,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.preventDefault(),e.stopPropagation(),He(!1),requestAnimationFrame(()=>mi.requestDirectoryDialog())},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]})]})]}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-auto min-h-6 cursor-pointer items-center gap-1.5 rounded-lg px-2.5 py-1 typography-micro font-medium text-foreground/80`,dm),onClick:()=>mi.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]}),ll&&Nl?(0,$.jsx)(sv,{directory:El,projectDirectory:ul,label:kl,projectRootOption:wl,worktreeOptions:Tl,onSelectDirectory:Fl}):null]}):null,Gr&&cl?(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:[ll?(0,$.jsx)(`button`,{type:`button`,className:Y(`inline-flex h-[1.625rem] min-w-0 max-w-[46%] shrink items-center gap-1.5 rounded-lg px-1.5 text-[11px] leading-none font-medium text-foreground/80`,dm),onClick:()=>Me(`project`),children:Il(ll)}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-[1.625rem] min-w-0 max-w-[46%] items-center gap-1.5 rounded-lg px-1.5 text-[11px] leading-none font-medium text-foreground/80`,dm),onClick:()=>mi.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]}),ll&&Nl?(0,$.jsx)(sv,{directory:El,projectDirectory:ul,label:kl,projectRootOption:wl,worktreeOptions:Tl,onSelectDirectory:Fl,maxWidthClassName:`max-w-[50%]`,presentation:`mobile-sheet`}):null]}):null,yu]})}),(0,$.jsx)(`div`,{className:Y(!Gr&&`contents`,Gr&&`contents`,Ha&&`flex min-h-0 flex-1 flex-col`),children:(0,$.jsxs)(`div`,{className:Gr?`oc-mobile-composer-motion-viewport`:`contents`,children:[(0,$.jsxs)(z_,{value:ci,attachments:[],disabled:!Hn&&!Gn||Un&&!Ns.establishing,pending:Ts||Ns.inFlight&&!Ns.establishing,isMobile:Gr,onSubmit:Zs,"data-mobile-composer-surface":Gr?`true`:void 0,"data-session-swipe-surface":Gr?`true`:void 0,expanded:Ua,focusedTone:h===`shell`?`info`:`primary`,className:Y(`relative z-10`,y&&`ring-2 ring-primary ring-offset-2`,Xr&&`ring-1 ring-[var(--interactive-selection)] border-[var(--interactive-selection)]`,Gr&&`oc-mobile-composer-surface`),style:{borderRadius:Wa},ref:Vi,onDropCapture:Zc,onDragEnter:Kc,onDragOver:qc,onDragLeave:Jc,onDrop:Xc,onDragEnd:Yc,autoResize:!1,disableInputWhilePending:!1,contentClassName:Ua?`flex-1 min-h-0`:void 0,inputHeader:void 0,attachmentContent:du,highlightedContent:fu,highlightRef:ja,inputRef:Mi,textLayoutClassName:Y(Cb,Ua?Y(`h-full min-h-0`,Gr?`py-2.5`:`py-4`):Gr?`py-2.5`:`pt-4 pb-2`,h===`shell`?`font-mono`:`typography-markdown md:typography-ui-label`),inputOuterClassName:Y(Ua&&`flex-1 min-h-0`),inputStyle:{flex:Ua?`1 1 auto`:`none`,height:!Ua&&de?`${de.height}px`:void 0,maxHeight:!Ua&&de?`${de.maxHeight}px`:void 0,"--oc-composer-textarea-resting-height":Ua?`100%`:de?`${de.height}px`:`auto`,"--oc-composer-textarea-resting-max-height":!Ua&&de?`${de.maxHeight}px`:`none`,borderTopLeftRadius:Wa,borderTopRightRadius:Wa},footerClassName:Y(`z-30 bg-transparent flex-shrink-0`,eu,Gr?`flex items-center gap-x-1.5`:Y(`flex items-center justify-between`,ol)),footerStyle:{borderBottomLeftRadius:Wa,borderBottomRightRadius:Wa},footerContent:mu,placeholder:Ga,onChange:(e,t)=>Ec(t),textareaProps:{readOnly:Xr,onCompositionStart:()=>{Ii.current=!0},onCompositionEnd:e=>{Ii.current=!1;let t=e.currentTarget;_c(t.value,t.selectionStart??t.value.length,t.selectionEnd??t.selectionStart??t.value.length)},onBeforeInput:Tc,onKeyDown:ic,onCopy:Ac,onCut:jc,onPaste:Oc,onDragEnter:Kc,onDragOver:qc,onDropCapture:Zc,onDrop:Xc,onDragEnd:Yc,onKeyUp:oc,onClick:()=>{oc()},onScroll:e=>{oc();let t=e.currentTarget.scrollTop;ja.current&&(ja.current.style.transform=`translateY(-${t}px)`)},onSelect:e=>{let t=e.currentTarget,n=t.selectionStart??0,r=t.selectionEnd??n;if(Ii.current){Li.current=r;return}let i=wv(n,r,[...De(ci,Bn.filter(Fe).map(e=>e.filename)),...Cv(ci,ao.keys()),...si.references]);i&&(i.start!==n||i.end!==r)?(t.setSelectionRange(i.start,i.end),Li.current=i.end):Li.current=n,oc()},onFocus:()=>{if(Gr){if(Date.now()<Ge.current){let e=Mi.current;e&&e.blur();return}ye.current!==null&&(window.clearTimeout(ye.current),ye.current=null),ve(!0)}},onBlur:e=>{if(Ii.current=!1,Li.current=e.currentTarget.selectionStart??Li.current,Ql(),Gr){if(Date.now()<Zl.current){let e=Mi.current;if(e){e.focus(),window.setTimeout(()=>{Date.now()<Zl.current&&document.activeElement!==e&&e.focus()},50);return}}if(qe.current=Date.now(),Re()){ve(!1);return}ye.current!==null&&window.clearTimeout(ye.current),ye.current=window.setTimeout(()=>{ye.current=null,ve(!1)},120)}},autoCorrect:Gr?`on`:`off`,autoCapitalize:Gr?`sentences`:`off`,spellCheck:Gr||$r,fillContainer:Ua,rows:1},children:[(0,$.jsx)(uh,{}),y&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/90`,style:{borderRadius:Wa},children:(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`inline-flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,className:au,onClick:()=>nl(),title:f(`chat.chatInput.actions.attachFiles`),"aria-label":f(`chat.chatInput.actions.attachFiles`),children:(0,$.jsx)(X,{name:`attachment-2`,className:Y(iu,`text-current`)})})}),(0,$.jsx)(`p`,{className:`mt-2 typography-ui-label text-muted-foreground`,children:f(T?`chat.chatInput.drop.insertMention`:`chat.chatInput.drop.attachFiles`)})]})}),M&&(0,$.jsx)(Po,{ref:Qi,searchQuery:P,directory:Yn,onCommandSelect:Bc,onClose:()=>N(!1),commandPolicy:Ul,commandContext:Qn,onRowsChange:Kl?Hl:void 0,style:Ba&&go?{left:`${go.left}px`,top:`${go.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${go.left+8}px))`,maxHeight:`${go.maxHeight}px`,transform:go.place===`above`?`translateY(-100%)`:void 0}:void 0}),R&&(0,$.jsx)(Gp,{ref:$i,searchQuery:V,directory:Yn,onSkillSelect:Rc,onClose:()=>z(!1),onRowsChange:Kl?Hl:void 0,style:Ba&&go?{left:`${go.left}px`,top:`${go.top}px`,bottom:`auto`,width:`min(360px, calc(100% - ${go.left+8}px))`,maxHeight:`${go.maxHeight}px`,transform:go.place===`above`?`translateY(-100%)`:void 0}:void 0}),q&&(0,$.jsx)(Wo,{ref:ea,searchQuery:ie,onSnippetSelect:zc,onClose:()=>te(!1),style:Ba&&go?{left:`${go.left}px`,top:`${go.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${go.left+8}px))`,maxHeight:`${go.maxHeight}px`,transform:go.place===`above`?`translateY(-100%)`:void 0}:void 0}),D&&(0,$.jsx)(Qo,{ref:Xi,searchQuery:k,onFileSelect:Pc,onAgentSelect:Fc,onSessionSelect:Ic,onClose:()=>O(!1),onRowsChange:Kl?Hl:void 0,style:Ba&&go?{left:`${go.left}px`,top:`${go.top}px`,bottom:`auto`,width:`min(520px, calc(100% - ${go.left+8}px))`,maxHeight:`${go.maxHeight}px`,transform:go.place===`above`?`translateY(-100%)`:void 0}:void 0})]}),Gr?(0,$.jsx)(qb,{radius:Wa,isMobile:Gr,footerIconButtonClass:su,footerPaddingClass:eu,iconSizeClass:iu,sendIconSizeClass:nu,onInsert:$s,onInsertAndSend:ec,onContentHeightChange:mc,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}):null]})})]}),Gr?(0,$.jsxs)(`div`,{className:`oc-mobile-composer-compact-layer`,"data-oc-composer-compact-surface":`true`,children:[pu,(0,$.jsx)(`div`,{className:Y(`oc-mobile-composer-compact-preview`,!ci.trim()&&`oc-mobile-composer-compact-preview--placeholder`),"aria-hidden":`true`,children:ci.trim()?ci:Ka})]}):null]}),Gr?(0,$.jsx)(Kb,{className:`hidden`,composerTextareaRef:Mi,selectionAdapter:jr,mobilePanel:pe,onMobilePanelChange:me}):null]}),Gn&&!Ba&&!Gr&&!sl&&!Al?(0,$.jsx)(M_,{onSubmit:Qs,className:`chat-input-column mt-4`}):null]}),p.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(wb,{popup:p,onOpenChange:Jr,isMobile:Gr})}):null,(0,$.jsx)(l_,{open:yo,onOpenChange:bo,mode:`select`,onSelect:e=>{wo(e),Eo(null)}}),(0,$.jsx)(f_,{open:xo,onOpenChange:So,onSelect:e=>{Eo(e),wo(null)}}),(0,$.jsx)(qu,{open:ur,onOpenChange:fr,projectDirectory:yt??Yn??null,submitting:pr,onConfirm:Ra}),(0,$.jsx)(`input`,{ref:Qc,type:`file`,multiple:!0,className:`hidden`,onChange:al,accept:`*/*`}),(0,$.jsx)(`input`,{ref:Q,type:`file`,multiple:!0,className:`hidden`,onChange:al,accept:`image/*`}),null,Gr?(0,$.jsx)(Qa,{id:`android-media-pick-sheet`,open:Se,onOpenChange:e=>{e||Ee(!1)},title:(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:f(`chat.chatInput.actions.addAttachment`)}),ariaLabel:f(`chat.chatInput.actions.addAttachment`),closeAriaLabel:f(`mobile.surface.closeAria`),resizeAriaLabel:f(`mobile.sessions.sheet.resizeAria`),fitContent:!0,children:(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsxs)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:[(0,$.jsxs)(ca,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,onClick:()=>{Je.current=!1,Ee(!1),requestAnimationFrame(il)},children:[(0,$.jsx)(X,{name:`file-image`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:f(`chat.chatInput.actions.attachPhotos`)})]}),(0,$.jsxs)(ca,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,onClick:()=>{Je.current=!1,Ee(!1),requestAnimationFrame(nl)},children:[(0,$.jsx)(X,{name:`attachment-2`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:f(`chat.chatInput.actions.attachFiles`)})]})]})})}):null,Gr&&cl&&ll?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(Qa,{id:`mobile-draft-project-picker-sheet-${Ne}`,open:Ae===`project`,onOpenChange:e=>{e||Me(null)},ariaLabel:f(`chat.chatInput.draftPicker.projectTitle`),closeAriaLabel:f(`mobile.surface.closeAria`),resizeAriaLabel:f(`mobile.sessions.sheet.resizeAria`),children:[(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-2 pt-1`,"data-mobile-sheet-no-dismiss":``,children:(0,$.jsx)(Fa,{value:Pe,onChange:e=>Ie(e.target.value),placeholder:f(`chat.chatInput.draftPicker.searchProjects`),className:`h-9`})}),(0,$.jsx)(da,{outerClassName:`min-h-0 flex-1`,disableHorizontal:!0,children:(0,$.jsx)(`div`,{className:`flex flex-col px-3 pb-2`,children:ar.filter(e=>Na(Wb(e),Pe)||Na(e.path,Pe)).map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-2.5 text-left typography-ui-label hover:bg-[var(--interactive-hover)]`,onClick:()=>{Pl(e.id),Me(null)},children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:Il(e)}),e.id===ll.id?(0,$.jsx)(X,{name:`check`,className:`h-4 w-4 flex-shrink-0 text-muted-foreground`}):null]},e.id))})}),(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-4 pt-1`,children:(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg border-t border-border/50 px-2 py-2.5 text-left typography-ui-label hover:bg-[var(--interactive-hover)]`,onClick:()=>{Me(null),mi.requestDirectoryDialog()},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]})})]})}):null]})},ox=e=>{let t=(0,Q.c)(3),n=Lm(),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)(ax,{...e,surface:i}),t[0]=e,t[1]=i,t[2]=a):a=t[2],a};ox.displayName=`ChatInput`;var sx=Z.memo(ox);function cx(e){return e.preventDefault()}function lx(e){e.preventDefault()}function ux(e){return e.preventDefault()}function dx(e){e.pointerType===`touch`&&e.preventDefault()}function fx(e){e.preventDefault()}function px(e){e.pointerType===`touch`&&e.preventDefault()}function mx(){let e=(0,Q.c)(47),{t}=ot(),[n,r]=Z.useState(null),[i,a]=Z.useState(!1),o=Z.useRef(null),s=!!n,c,l;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>mo(e=>{r(e),a(!1)}),l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),Z.useEffect(c,l);let u;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=e=>{e||(r(null),a(!1))},e[2]=u):u=e[2];let d=J(u),f;e[3]===d?f=e[4]:(f=()=>(d(!1),!0),e[3]=d,e[4]=f);let p;e[5]!==s||e[6]!==f?(p={id:`image-save-actions`,active:s,layer:`overlay`,onBack:f,surfaceRef:o},e[5]=s,e[6]=f,e[7]=p):p=e[7],Cs(p);let m;e[8]!==i||e[9]!==t||e[10]!==n?(m=async()=>{if(!(!n||i)){a(!0);try{await Bc(n),In.success(t(`chat.image.actions.saveSuccess`)),r(null)}catch(e){let n=e;if(n instanceof DOMException&&n.name===`AbortError`){a(!1);return}In.error(t(`chat.image.actions.saveFailed`)),a(!1);return}a(!1)}},e[8]=i,e[9]=t,e[10]=n,e[11]=m):m=e[11];let h=J(m);if(!n)return null;let g;e[12]!==t||e[13]!==n.filename?(g=n.filename?.trim()||t(`chat.image.actions.sheetTitle`),e[12]=t,e[13]=n.filename,e[14]=g):g=e[14];let _=g,v;e[15]===t?v=e[16]:(v=Re()?t(`chat.image.actions.saveToPhotos`):t(`chat.image.actions.saveImage`),e[15]=t,e[16]=v);let y=v,b;e[17]===_?b=e[18]:(b=(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:_}),e[17]=_,e[18]=b);let x;e[19]===t?x=e[20]:(x=t(`mobile.surface.closeAria`),e[19]=t,e[20]=x);let S;e[21]===t?S=e[22]:(S=t(`mobile.sessions.sheet.resizeAria`),e[21]=t,e[22]=S);let C;e[23]===h?C=e[24]:(C=()=>{h()},e[23]=h,e[24]=C);let w=i?`loader-4`:`download`,T=i?`size-5 animate-spin`:`size-5`,E;e[25]!==w||e[26]!==T?(E=(0,$.jsx)(X,{name:w,className:T}),e[25]=w,e[26]=T,e[27]=E):E=e[27];let D;e[28]!==y||e[29]!==i||e[30]!==t?(D=i?t(`chat.image.actions.saving`):y,e[28]=y,e[29]=i,e[30]=t,e[31]=D):D=e[31];let O;e[32]===D?O=e[33]:(O=(0,$.jsx)(`span`,{className:`truncate`,children:D}),e[32]=D,e[33]=O);let k;e[34]!==i||e[35]!==C||e[36]!==E||e[37]!==O?(k=(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsx)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:(0,$.jsxs)(ca,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,disabled:i,onClick:C,children:[E,O]})})}),e[34]=i,e[35]=C,e[36]=E,e[37]=O,e[38]=k):k=e[38];let A;return e[39]!==d||e[40]!==s||e[41]!==S||e[42]!==k||e[43]!==b||e[44]!==x||e[45]!==_?(A=(0,$.jsx)(`div`,{ref:o,children:(0,$.jsx)(Qa,{id:`image-save-actions-sheet`,open:s,onOpenChange:d,title:b,ariaLabel:_,closeAriaLabel:x,resizeAriaLabel:S,fitContent:!0,children:k})}),e[39]=d,e[40]=s,e[41]=S,e[42]=k,e[43]=b,e[44]=x,e[45]=_,e[46]=A):A=e[46],A}var hx=(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(Mt(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]},gx=(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},_x=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}},vx=e=>e.syncLoading||e.assistantLoading,yx=e=>e.isMobile&&(e.canLoadEarlier||e.isLoadingOlder),bx=e=>e.isLoadingOlder,xx=e=>!e.isMobile&&e.isLoadingOlder,Sx=e=>e.transcriptMessageCount>0||e.pendingUserCount>0||e.historyPrefixCount>0,Cx=e=>e.hasTranscriptShell||e.hasBusyShell||e.hasImmediateShell||e.hasPaintedTranscript?`pass`:e.prefetchStatus===`loading`||e.syncLoading||e.userRetrying?`hydrating`:e.prefetchStatus===`error`?`load-error`:e.hasRenderableSessionSnapshot?`pass`:`hydrating`,wx=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}},Tx=e=>({newSessionDraft:e?.features?.newSessionDraft??!e,promptNavigator:e?.features?.promptNavigator??!e,returnToParent:e?.features?.returnToParent??!e}),Ex=`text-[13px] leading-4 sm:text-[length:var(--text-micro)] sm:leading-5`,Dx=`relative bottom-safe-area oc-mobile-readonly-prompt-foot`,Ox=e=>{let t=(0,Q.c)(8),{providerId:n,modelId:r,label:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(X,{name:`brain-ai-3`,className:`size-3.5`}),t[0]=a):a=t[0];let o;t[1]===i?o=t[2]:(o=(0,$.jsx)(`span`,{role:`img`,"aria-label":i,className:`inline-flex size-3.5 shrink-0 items-center justify-center`,children:a}),t[1]=i,t[2]=o);let s;return t[3]!==i||t[4]!==r||t[5]!==n||t[6]!==o?(s=(0,$.jsx)(Ea,{modelId:r,providerId:n,alt:i,className:`size-3.5 shrink-0`,fallback:o}),t[3]=i,t[4]=r,t[5]=n,t[6]=o,t[7]=s):s=t[7],s},kx=e=>{let t=(0,Q.c)(42),{t:n}=ot(),r=s(Ax),i=`agentName`in e||`providerId`in e||`modelId`in e||`modelName`in e;if(!i){let e=r&&Dx,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 ${Ex}`,children:a}),t[4]=a,t[5]=o);let s;return t[6]!==i||t[7]!==o?(s=(0,$.jsx)(`div`,{className:i,children:o}),t[6]=i,t[7]=o,t[8]=s):s=t[8],s}let a;t[9]===n?a=t[10]:(a=n(`common.unavailable`),t[9]=n,t[10]=a);let o=a,c;t[11]!==e.agentName||t[12]!==o?(c=e.agentName?e.agentName.charAt(0).toUpperCase()+e.agentName.slice(1):o,t[11]=e.agentName,t[12]=o,t[13]=c):c=t[13];let l=c,u=e.modelName||o,d;t[14]===n?d=t[15]:(d=n(`chat.leaderKey.action.agent`),t[14]=n,t[15]=d);let f=`${d}: ${l}`,p;t[16]===n?p=t[17]:(p=n(`chat.leaderKey.action.model`),t[16]=n,t[17]=p);let m=`${p}: ${u}`,h=r&&Dx,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 ${Ex}`,children:y}),t[24]=y,t[25]=b);let x;t[26]!==f||t[27]!==l||t[28]!==m||t[29]!==u||t[30]!==e.agentName||t[31]!==e.modelId||t[32]!==e.providerId||t[33]!==i?(x=i?(0,$.jsxs)(`div`,{"data-testid":`read-only-prompt-banner-meta`,className:`mt-1.5 flex min-w-0 items-center justify-between gap-3 border-t border-border/70 pt-1.5 text-[13px] leading-none sm:text-[length:var(--text-micro)]`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 overflow-hidden`,children:[(0,$.jsx)(sa,{name:e.agentName,size:14,label:f}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,title:l,children:l})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-[55%] items-center justify-end gap-1.5 overflow-hidden`,children:[(0,$.jsx)(Ox,{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 Ax(e){return e.isMobile}var jx=Z.memo(()=>{let e=(0,Q.c)(5),{t}=ot(),{currentTheme:n}=za(),r=Nt(Mx),i=n?.colors?.surface?.mutedForeground||`var(--muted-foreground)`,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(io,{width:140,height:140,className:`opacity-20`}),e[0]=a):a=e[0];let o;return e[1]!==r||e[2]!==t||e[3]!==i?(o=(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-full w-full gap-6`,children:[a,r?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 max-w-md text-center px-4`,children:[(0,$.jsx)(`span`,{className:`typography-markdown font-medium text-destructive`,children:t(`chat.emptyState.opencodeUnreachable`)}),(0,$.jsx)(`span`,{className:`typography-meta`,style:{color:i},children:r.message})]}):(0,$.jsx)(`span`,{className:`typography-markdown`,style:{color:i},children:t(`chat.emptyState.startNewChat`)})]}),e[1]=r,e[2]=t,e[3]=i,e[4]=o):o=e[4],o});function Mx(e){return e.error}var Nx=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)}}},Px=`oc:legend-timeline`,Fx=()=>{try{return typeof localStorage>`u`||localStorage.getItem(Px)!==`0`}catch{return!0}},Ix=ue(e=>({planModeEnabled:!1,setPlanModeEnabled:t=>e({planModeEnabled:t}),legendTimelineEnabled:Fx(),setLegendTimelineEnabled:t=>{try{typeof localStorage<`u`&&localStorage.setItem(Px,t?`1`:`0`)}catch{}e({legendTimelineEnabled:t})}})),Lx=e=>{if(!e?.trim())return null;let t=e.trim();return t.toLowerCase()==="default"?null:xi(t)},Rx=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?Lx(c):null,t[0]=r,t[1]=n,t[2]=c,t[3]=l):l=t[3];let u=l,d=s||`Assistant`,f,p;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=Y(`mb-1.5`),p=Y(`flex items-center justify-between gap-2`),t[4]=f,t[5]=p):(f=t[4],p=t[5]);let m;t[6]!==o||t[7]!==n||t[8]!==a||t[9]!==i?(m=(0,$.jsx)(`div`,{className:`flex-shrink-0`,children:n?(0,$.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-primary/10 flex items-center justify-center`,children:(0,$.jsx)(X,{name:`user-3`,className:`h-4 w-4 text-primary`})}):(0,$.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,$.jsx)(Ea,{modelId:a,providerId:i,className:`h-4 w-4`,fallback:(0,$.jsx)(X,{name:`brain-ai-3`,className:`h-4 w-4`,style:{color:`var(${ea(o).var})`}})})})}),t[6]=o,t[7]=n,t[8]=a,t[9]=i,t[10]=m):m=t[10];let h=n?`text-primary`:`text-foreground`,g;t[11]===h?g=t[12]:(g=Y(`inline-flex min-w-0 items-center gap-1.5 font-semibold typography-ui-header tracking-tight leading-tight`,h),t[11]=h,t[12]=g);let _=n?`You`:d,v;t[13]===_?v=t[14]:(v=(0,$.jsx)(`span`,{className:`truncate`,children:_}),t[13]=_,t[14]=v);let y;t[15]===u?y=t[16]:(y=u?(0,$.jsx)(`span`,{className:`shrink-0 text-xs font-normal leading-tight text-muted-foreground`,children:u}):null,t[15]=u,t[16]=y);let b;t[17]!==g||t[18]!==v||t[19]!==y?(b=(0,$.jsxs)(`h3`,{className:g,children:[v,y]}),t[17]=g,t[18]=v,t[19]=y,t[20]=b):b=t[20];let x;t[21]!==o||t[22]!==r||t[23]!==n?(x=!n&&o&&(0,$.jsxs)(`div`,{className:Y(`agent-badge inline-flex items-center gap-1 cursor-default rounded font-normal leading-tight`,r?`px-1 py-px text-[10px]`:`px-1.5 py-0.5 typography-micro`,ea(o).class),children:[(0,$.jsx)(sa,{name:o,size:10}),(0,$.jsx)(`span`,{children:o.charAt(0).toUpperCase()+o.slice(1)})]}),t[21]=o,t[22]=r,t[23]=n,t[24]=x):x=t[24];let S;t[25]!==b||t[26]!==x?(S=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[b,x]}),t[25]=b,t[26]=x,t[27]=S):S=t[27];let C;return t[28]!==S||t[29]!==m?(C=(0,$.jsx)(`div`,{className:f,children:(0,$.jsx)(`div`,{className:p,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[m,S]})})}),t[28]=S,t[29]=m,t[30]=C):C=t[30],C}),zx=/(^|\s)\/([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)/g,Bx=/(```[\s\S]*?```|~~~[\s\S]*?~~~)/g,Vx=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),Hx=(e,t)=>e.split(Bx).map((e,n)=>n%2==1?e:t(e)).join(``),Ux=e=>Hx(e,e=>e.replace(/ *\n/g,`
|
|
6534
|
+
`)?`${t}\n`:`${t}\n\n`}`,nx=(e,t)=>{let n=t.trim();return n?e?`${e}${/[\s\n]$/.test(e)?``:` `}${n} `:`${n} `:e},rx=(e,t,n,r)=>t?h({transportIdentity:e},t):n?m({transportIdentity:e},n):r,ix=[],ax=({onOpenSettings:e,scrollToBottom:r,showScrollToBottom:a=!1,onScrollToBottom:o,submissionBlocked:l=!1,surface:u})=>{let{t:f}=ot(),[p,m]=Z.useState({open:!1,title:``,content:``}),[h,g]=Z.useState(`normal`),[y,w]=Z.useState(!1),[T,E]=Z.useState(!1),[D,O]=Z.useState(!1),[k,j]=Z.useState(``),[M,N]=Z.useState(!1),[P,I]=Z.useState(``),[R,z]=Z.useState(!1),[V,H]=Z.useState(``),[q,te]=Z.useState(!1),[ie,ae]=Z.useState(``),[oe,se]=Z.useState([]),[le,ue]=Z.useState(0),[de,fe]=Z.useState(null),[pe,me]=Z.useState(null),he=Z.useRef(null),ge=Z.useRef(null),[_e,ve]=Z.useState(!1),ye=Z.useRef(null);Z.useEffect(()=>()=>{ye.current!==null&&window.clearTimeout(ye.current),he.current!==null&&window.clearTimeout(he.current),ge.current!==null&&window.clearTimeout(ge.current)},[]);let[be,xe]=Z.useState(!1),[Se,Ee]=Z.useState(!1),[Ae,Me]=Z.useState(null),Ne=Z.useId(),[Pe,Ie]=Z.useState(``),[Le,ze]=Z.useState(``),[Ve,He]=Z.useState(!1),[Ue,We]=Z.useState(!1),Ge=Z.useRef(0),Ke=Z.useCallback(()=>{Ge.current=Date.now()+500},[]),qe=Z.useRef(0),Je=Z.useRef(!1),[Ye,Xe]=Z.useState(-1),Ze=Z.useRef(()=>{}),Qe=Z.useRef((...e)=>Promise.resolve().then(()=>ni.getState().sendMessage(...e))).current,$e=ni(e=>e.currentSessionId),et=br(e=>e.currentProviderId),tt=br(e=>e.currentModelId),nt=br(e=>e.currentAgentName),rt=br(e=>e.currentVariant),it=br(e=>e.providers),st=br(e=>e.agents),ct=br(e=>e.getVisibleAgents),lt=Z.useMemo(()=>Tm(ct()),[ct,st]),ut=br(e=>e.providerConfigLoadingByDirectory[e.activeDirectoryKey]===!0),ft=br(e=>e.agentConfigLoadingByDirectory[e.activeDirectoryKey]===!0),mt=Z.useMemo(()=>{let e=it.find(e=>e.id===et)?.models?.find(e=>e.id===tt);return Mm(e)},[tt,et,it]),ht=we(e=>e.currentDirectory),gt=cc()??ht,{ensureSessionRenderable:vt}=Tu(),yt=ni(Z.useCallback(e=>$e?e.getDirectoryForSession($e):null,[$e])),xt=mr($e??``,yt??void 0),St=Z.useMemo(()=>Gy(xt),[xt]),wt=ji($e??``,yt??void 0).renderable,Tt=pt($e,yt??void 0),Et=Tt?.agent,Dt=Tt?.model?.id,Ot=Tt?.model?.providerID,At=Tt?.model?.variant,jt=br(e=>e.activeDirectoryKey),Mt=Z.useRef(0),Nt=Z.useRef(null),It=Z.useRef(null),Lt=ni(e=>e.newSessionDraft),zt=!!Lt?.open,Bt=ni(e=>e.newSessionDraft.draftSubmitting??!1),Vt=ni(e=>e.newSessionDraft.draftEstablishing??!1),Ht=Bt||Vt,Ut=ni(e=>e.openNewSessionDraft),Kt=ni(e=>e.setDraftPermissionAutoAcceptEnabled),qt=Fn(e=>e.autoAccept),Jt=Fn(e=>e.saving),Zt=Fn(e=>e.setSessionAutoAccept),en=ni(e=>e.setNewSessionDraftTarget),tn=ni(e=>e.availableWorktreesByProject),an=ni(e=>e.abortPromptSessionId),on=ni(e=>e.clearAbortPrompt),sn=Yt(e=>e.consumePendingInputText),cn=Yt(e=>e.pendingPresetSubmit),ln=Yt(e=>e.pendingInputText),un=Yt(e=>e.pendingInputMode),dn=Yt(e=>e.consumePendingSyntheticParts),fn=Yt(e=>e.activeAttachmentDraft),mn=ju(Z.useCallback(e=>{let t=$e??(zt?`draft`:``);return t?e.drafts[t]??Eb:Eb},[zt,$e])),hn=lr($e??``),_n=Z.useSyncExternalStore(t,n,n),vn=fn?.transportIdentity??null,yn=fn?.owner.kind??null,bn=fn?.owner.ownerID??null,Sn=Z.useMemo(()=>rx(_n,$e,Lt.draftID,vn&&yn&&bn?{transportIdentity:vn,owner:{kind:yn,ownerID:bn}}:null),[bn,yn,vn,_n,$e,Lt.draftID]),Cn=Sn?ce(Sn):null,wn=Yt(Z.useCallback(e=>Cn?e.draftAttachmentViews[Cn]:void 0,[Cn])),Dn=Yt(Z.useCallback(e=>Cn?e.drafts[Cn]:void 0,[Cn])),On=Z.useMemo(()=>{if(!Dn||!wn)return ix;let e=Dn.attachments.flatMap(e=>{let t=wn[e.attachmentRefID];return t?[t]:[]});return e.length===0?ix:e},[wn,Dn]);Z.useEffect(()=>{Sn&&Yt.getState().hydrateDraftAttachments(Sn)},[Sn]);let An=Lm(),Mn=s(e=>e.activeMainTab===`chat`),Nn=Pi($e??``,gt??void 0),Pn=Rm({kind:`primary`,surfaceID:`primary`,active:Mn,sessionID:$e,directory:gt??null,activity:{phase:Nn?.type===`busy`?`busy`:Nn?.type===`retry`?`retry`:`idle`,canAbort:Nn?.type===`busy`||Nn?.type===`retry`},draftKey:Sn,transportIdentity:_n,runtimeGeneration:c(),selection:{value:{providerID:et,modelID:tt,agent:nt,variant:rt},catalog:{providers:it,agents:lt,variants:mt,variantsReady:!ut,ready:!ut&&!ft,loading:ut||ft},flush:async()=>{let e=ni.getState().currentSessionId;if(!e)return;let t=c(),r=n(),i=Mt.current,a=e,o=ni.getState().getDirectoryForSession(a)??null,s=Di(o);if(br.getState().activeDirectoryKey!==s&&await br.getState().activateDirectory(o),c()!==t||n()!==r||ni.getState().currentSessionId!==a||br.getState().activeDirectoryKey!==s||Mt.current!==i)return;await vt(a,{directory:o??void 0});let l=ni.getState().getDirectoryForSession(a)??null,u=Di(l);if(c()!==t||n()!==r||ni.getState().currentSessionId!==a||l!==o||u!==s||br.getState().activeDirectoryKey!==s||Mt.current!==i)return;let d=br.getState(),f={providers:d.providers,agents:d.getVisibleAgents()};if(f.providers.length===0||f.agents.length===0)return;let p=Gy(kr(a,l??void 0));if(Uy({editRevision:i,pinnedHistoryMessageId:Nt.current,latestHistoryMessageId:p?.id??null}))return;let m=rn.getState(),h=ri().get(a),g=By({sessionId:a,latestUserChoice:p,catalog:f,memory:m,sessionEntity:h?.model?{agent:h.agent,model:{id:h.model.id,providerID:h.model.providerID,variant:h.model.variant}}:h?.agent?{agent:h.agent}:null,fallbackAgentName:d.currentAgentName});if(!g)return;let _=[a,g.source,g.messageId??``,g.agent??``,g.providerID,g.modelID,g.variant??``,s].join(`|`);It.current!==_&&(Vy(g,{currentAgentName:d.currentAgentName,setAgent:d.setAgent,setProvider:d.setProvider,setModel:d.setModel,setCurrentVariant:d.setCurrentVariant},{sessionId:a,memory:m}),It.current=_)},change:async e=>{Mt.current+=1;let t=ni.getState().currentSessionId;if(t){let e=ni.getState().getDirectoryForSession(t)??void 0,n=Gy(kr(t,e));Nt.current=n?.id??null}else Nt.current=null;let n=br.getState();Fy(e,{currentAgentName:n.currentAgentName,setAgent:n.setAgent,setProvider:n.setProvider,setModel:n.setModel,setCurrentVariant:n.setCurrentVariant,saveAgentModelSelection:n.saveAgentModelSelection},{sessionId:t,memory:rn.getState()})}},resources:{attachments:On,addAttachment:async e=>{Sn&&await Wn(Sn,()=>Yt.getState()).addLocal(e)},removeAttachment:async e=>Sn?Wn(Sn,()=>Yt.getState()).removeByAttachmentID(e):!1,clearAttachments:async()=>Sn?Wn(Sn,()=>Yt.getState()).clearRootAttachments():!1,restoreAttachments:async e=>Sn?Wn(Sn,()=>Yt.getState()).restoreRootAttachments(e):!1,pendingInput:ln===null?null:{text:ln,mode:un},consumePendingInput:sn,pendingPreset:cn,consumePendingPreset:()=>Yt.getState().consumePendingPresetSubmit(),consumeSyntheticParts:dn,restoreSyntheticParts:e=>Yt.setState(t=>({pendingSyntheticParts:[...e,...t.pendingSyntheticParts??[]]})),inlineDrafts:mn,removeInlineDraft:e=>{let t=$e??(zt?`draft`:``);t&&ju.getState().removeDraft(t,e)},restoreInlineDrafts:e=>{let t=$e??(zt?`draft`:``);!t||e.length===0||ju.setState(n=>{let r=n.drafts[t]??[],i=new Set(e.map(e=>e.id));return{drafts:{...n.drafts,[t]:[...e,...r.filter(e=>!i.has(e.id))]}}})},history:hn,captureRuntime:()=>Yt.getState().captureDraftRuntime(),getDraft:e=>Yt.getState().getDraft(e),abortPrompt:{sessionID:an,clear:on}},backend:{send:e=>{jy(e,{transportIdentity:n(),runtimeGeneration:c()});let t=My(e);return Qe(e.text??``,e.providerID,e.modelID,e.agent,e.attachments??[],e.agentMention,e.parts,e.variant,e.inputMode,t)},sendQueued:e=>Ji(e.sessionID??``,{delivery:e.options?.delivery===`steer`?`steer`:void 0,queueItemID:e.queueItemID,manual:e.manual,scope:e.queueScope?{state:`bound`,...e.queueScope}:void 0}),create:async()=>Ut(),compact:async e=>ke.summarizeSession(e.sessionID??``,e.providerID??``,e.modelID??``,e.directory),abort:e=>(e.sessionID&&Ft(e.sessionID),jn(e.sessionID??``))},shortcuts:{cycle:e=>Ze.current(e),new:()=>Ut(),abort:()=>($e&&Ft($e),jn($e??``)),submit:()=>{}},deliveryTarget:{kind:`primary`}}),Ln=zm(Pn,u??An);Bm(Ln),Z.useLayoutEffect(()=>{if(!Ln.active){Ay(Ln.surfaceID);return}return ky(Ln),()=>Ay(Ln.surfaceID)},[Ln]);let Rn=Py(Ln),zn=Ln.resources??(Ln.kind===`primary`?Pn.resources:void 0);if(!zn)throw Error(`chat-input-surface-resources-incomplete`);let Bn=[...zn.attachments],Hn=Ln.sessionID,Un=Vm(Ln,Ht),Gn=Ln.kind===`secondary`?Ln.commands.hasNewDraft:zt,qn=Gn,Yn=Ln.directory??gt,Xn=Ln.draftKey??Sn,Qn=Z.useMemo(()=>{if(Ln.kind===`secondary`)return Um(Ln,!1,!1);let e=Hn?Lb(Hn,yt??void 0):!1;return Um(Ln,e,Gn)},[Ln,Hn,yt,Gn]),$n=(e,t,n,r,i,a,o,s,c,l)=>Rn?Rn.send({providerID:t,modelID:n,agent:r,variant:s,text:e,attachments:i,agentMention:a,parts:o,systemContext:o?.filter(e=>e.synthetic).map(e=>({text:e.text,synthetic:!0})),inputMode:c,options:l}):Promise.reject(Error(`chat-input-surface-incomplete`)),rr=Z.useCallback(()=>Rn?Rn.abort():Promise.reject(Error(`chat-input-surface-incomplete`)),[Rn]),ar=kt(e=>e.projects),sr=kt(e=>e.activeProjectId),cr=kt(e=>e.setActiveProjectIdOnly),[ur,fr]=Z.useState(!1),[pr,hr]=Z.useState(!1),_r=Z.useMemo(()=>Hn?Ct({autoAccept:qt,sessions:[],sessionById:ri(),sessionID:Hn}):Lt.permissionAutoAcceptEnabled===!0,[Hn,Lt.permissionAutoAcceptEnabled,qt]),vr=br(e=>e.agents),yr=Ln.kind===`secondary`?Ln.selection.value.agent:nt,xr=Ln.kind===`secondary`?Tm(Ln.selection.catalog?.agents):vr,Sr=d()||Sy(xr,yr),Cr=Z.useCallback(()=>{In.error(f(`chat.chatInput.toast.togglePermissionAutoAcceptFailed`))},[f]),Er=Ln.selection.value,Or=Ln.selection.change,Ar=Ln.selection.catalog,jr=Z.useMemo(()=>({selection:{providerID:Er.providerID??``,modelID:Er.modelID??``,agent:Er.agent??null,variant:Er.variant},onChange:async e=>{if(!Or)throw Error(`chat-input-surface-selection-readonly`);await Or({...e,agent:e.agent??void 0,variant:e.variant})},disabled:!Ln.active,catalog:Ar}),[Ar,Or,Er.agent,Er.modelID,Er.providerID,Er.variant,Ln.active]);Z.useEffect(()=>{Mt.current=0,Nt.current=null,It.current=null},[$e]),Z.useEffect(()=>{if(Ln.kind!==`primary`||!$e||ut||ft||it.length===0||lt.length===0)return;let e=Di(yt);if(jt!==e)return;let t=rn.getState(),n={providers:it,agents:lt};if(Uy({editRevision:Mt.current,pinnedHistoryMessageId:Nt.current,latestHistoryMessageId:St?.id??null}))return;let r=By({sessionId:$e,latestUserChoice:St,catalog:n,memory:t,sessionEntity:Ot&&Dt?{agent:Et,model:{id:Dt,providerID:Ot,variant:At}}:Et?{agent:Et}:null,fallbackAgentName:nt,transcriptReady:wt});if(!r)return;let i=[$e,r.source,r.messageId??``,r.agent??``,r.providerID,r.modelID,r.variant??``,jt].join(`|`);if(It.current===i)return;if((r.agent===void 0||r.agent===nt)&&r.providerID===et&&r.modelID===tt&&r.variant===rt){It.current=i;return}if(br.getState().activeDirectoryKey!==e)return;let a=br.getState();Vy(r,{currentAgentName:a.currentAgentName,setAgent:a.setAgent,setProvider:a.setProvider,setModel:a.setModel,setCurrentVariant:a.setCurrentVariant},{sessionId:$e,memory:t}),It.current=i},[Ln.kind,$e,St,wt,it,lt,ut,ft,jt,yt,nt,et,tt,rt,Et,Dt,Ot,At]);let Pr=br(e=>e.getVisibleAgents),Ir=Ln.kind===`primary`?Pr():Db,Lr=br(e=>Ln.kind===`primary`?e.providers:Ob),Br=Ln.kind===`secondary`?Tm(Ln.selection.catalog?.agents):Ir,Vr=Ln.kind===`secondary`?Ln.selection.catalog?.providers??Ob:Lr,Hr=Ln.kind===`secondary`&&(!Ln.selection.catalog?.ready||!!Ln.selection.catalog.error),Ur=!Ln.active||!Ln.selection.change||Hr,Gr=s(e=>e.isMobile),Kr=s(e=>e.setImagePreviewOpen),qr=Z.useCallback(e=>{e.image&&(m(e),Kr(!0))},[Kr]),Jr=Z.useCallback(e=>{m(t=>({...t,open:e})),Kr(e)},[Kr]),Xr=ou(e=>e.pending),Zr=s(e=>e.inputBarOffset),Qr=s(e=>e.persistChatDraft),$r=s(e=>e.inputSpellcheckEnabled),ei=s(e=>e.isExpandedInput),ii=s(e=>e.setExpandedInput),ai=s(e=>e.setTimelineDialogOpen),oi=xb({draftKey:Xn,sessionTitles:new Map(Array.from(ri(),([e,t])=>[e,t.title||e])),persistenceEnabled:Qr}),si=oi.document,ci=si.text,{replacePlainDocument:ui,replaceProgrammaticText:di,applyBrowserEdit:fi,insertReference:hi,deleteReference:gi,enterHistoryPreview:_i,exitHistoryPreview:vi,captureSubmission:yi,recoverSubmission:Si,confirmedFileMentions:Ci,mentions:Ti}=oi,Oi=Z.useCallback((e,t)=>di(e,t),[di]),Ai=Z.useMemo(()=>new Set(Ci.map(e=>e.value)),[Ci]),Mi=Z.useRef(null),Ii=Z.useRef(!1),Li=Z.useRef(0),Ri=Z.useRef(null),Bi=Z.useRef(ci.length),Vi=Z.useRef(null),Hi=Z.useRef(0),Ui=Z.useRef(!1),Wi=Z.useRef(null),Gi=Z.useRef(!1),Ki=Z.useRef(null),qi=Z.useRef([]),Yi=Z.useRef(!1),Xi=Z.useRef(null),Zi=Z.useRef(!1),Qi=Z.useRef(null),$i=Z.useRef(null),ea=Z.useRef(null),ta=Z.useRef(ci),na=Z.useRef(new Set),ra=oi.getDocument,ia=Z.useCallback((e,t,n=[])=>Oi(e,(e,r)=>{let i=[],a=new Set(n);for(let e of t){let t=0,n=`@${e}`;for(;t<r.text.length;){let o=r.text.indexOf(n,t);if(o<0)break;i.push({kind:a.has(e)?`directory`:`file`,value:e,path:e,label:e,range:{start:o,end:o+n.length}}),t=o+n.length}}let o=new Set(e.map(e=>`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`));return[...e,...i.filter(e=>!o.has(`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`))]}),[Oi]),aa=Ph(Nh()),{git:sa,vscode:la}=Do(),ua=s(e=>e.shortcutOverrides.cycle_agent),fa=s(e=>e.shortcutOverrides),ma=Z.useMemo(()=>Ya(`cycle_agent`,ua?{cycle_agent:ua}:void 0),[ua]),ha=Z.useMemo(()=>Ya(`clear_all_messages`,fa),[fa]),{currentTheme:ga}=za(),va=Zo(),xa=ls(Yn),Ta=qo(e=>Yn?e.directories.get(Yn)?.status??null:null),Ea=qo(e=>e.ensureStatus),Oa=qo(e=>e.fetchStatus),[ka,Aa]=Z.useState(!1),ja=Z.useRef(null),[Ia,La]=Z.useState(!1);Z.useEffect(()=>{!Yn||!sa||Ea(Yn,sa)},[Yn,sa,Ea]),Z.useEffect(()=>{if(!(!Yn||!sa))return mi.onGitRefreshHint(e=>{Ub(e.directory)===Ub(Yn)&&Oa(Yn,sa)})},[Yn,sa,Oa]);let Ra=Z.useCallback(async e=>{if(!Hn)return;let t=ni.getState().getDirectoryForSession(Hn)||Yn||``;if(!t){In.error(f(`diffView.reviewDialog.toast.noSessionDirectory`));return}hr(!0);try{await Xt({originalSessionID:Hn,directory:t,providerID:e.providerID,modelID:e.modelID,agent:e.agent||void 0,variant:e.variant||void 0,generateHandoff:e.generateHandoff,returnAfterHandoffRequest:e.generateHandoff,autoReview:e.autoReview}),fr(!1)}catch(e){console.error(`[review-flow] failed to start review flow`,e),In.error(e instanceof Error?e.message:f(`diffView.reviewDialog.toast.startFailed`))}finally{hr(!1)}},[Hn,Yn,f]),Ba=ei&&!Gr,Ha=ei&&Gr,Ua=Ba||Ha,Wa=`1.5rem`,Ga=f(Hn||Gn?h===`shell`?`chat.chatInput.placeholder.shell`:Gr||Ia?`chat.chatInput.placeholder.chatCompact`:`chat.chatInput.placeholder.chat`:`chat.chatInput.placeholder.selectSession`),Ka=f(`chat.chatInput.placeholder.compactTap`);Z.useEffect(()=>{let e=Vi.current;if(!e)return;let t=e=>{let t=e>0&&e<Mb;La(e=>e===t?e:t)};if(t(e.clientWidth),typeof ResizeObserver>`u`){let n=()=>t(e.clientWidth);return window.addEventListener(`resize`,n),()=>window.removeEventListener(`resize`,n)}let n=new ResizeObserver(n=>{t(n[0]?.contentRect.width??e.clientWidth)});return n.observe(e),()=>n.disconnect()},[]);let qa=Bn,Ja=Z.useMemo(()=>new Set(Br.map(e=>e.name.toLowerCase())),[Br]),$a=Z.useRef(Ja);$a.current=Ja;let eo=Ab({inputMode:h,message:ci,showCommandAutocomplete:M,showSkillAutocomplete:R}),to=Pt({directory:Yn,enabled:eo}),no=Z.useMemo(()=>to.data??[],[to.data]),ro=Fi({directory:Yn,enabled:eo}),io=Z.useMemo(()=>ro.data??[],[ro.data]),ao=Z.useMemo(()=>new Map(io.map(e=>[e.name.toLowerCase(),e.name])),[io]),oo=Z.useMemo(()=>{let e=new Set([`init`,`review`,`undo`,`redo`,`fork`,`timeline`,`model`,`compact`,`summary`,`workspace-review`,`plan-feature`,`craft-goal`,`goal`,`catch-up`,`debug`,`weigh`,`explore`]);!Gr&&!d()&&e.add(`handoff-review`);for(let t of no)e.add(t.name.toLowerCase());for(let t of io)e.add(t.name.toLowerCase());return e},[no,io,Gr]),so=Z.useMemo(()=>{if(!ci||!ci.includes(`/`)||h===`shell`||oo.size===0)return[];let e=[],t=RegExp(`(^|\\s)/(${ee})?([A-Za-z0-9][A-Za-z0-9_-]*)`,`g`),n;for(;(n=t.exec(ci))!==null;){let t=n[2]??``,r=n[3];if(!oo.has(r.toLowerCase()))continue;let i=n.index+n[1].length,a=1+t.length+r.length,o=ao.get(r.toLowerCase());e.push(o?{start:i,end:i+a,style:`mentionCommand`,priority:102,skillName:o,visual:re({trigger:`/`,icon:`book-open`,label:o},ci.slice(i,i+a))}:{start:i,end:i+a,style:`mentionCommand`,visual:re({trigger:`/`,icon:`command`,label:r},ci.slice(i,i+a))})}return e},[ao,h,oo,ci]),co=pa(e=>e.snippets),lo=Z.useMemo(()=>{let e=new Set;for(let t of co){e.add(t.name.toLowerCase());for(let n of t.aliases??[])e.add(n.toLowerCase())}return e},[co]),uo=Z.useMemo(()=>{if(!ci||!ci.includes(`#`)||h===`shell`||lo.size===0)return[];let e=[],t=/(^|\s)#([A-Za-z0-9][A-Za-z0-9_-]*)/g,n;for(;(n=t.exec(ci))!==null;){let t=n[2];if(!lo.has(t.toLowerCase()))continue;let r=n.index+n[1].length;e.push({start:r,end:r+1+t.length,style:`mentionSnippet`})}return e},[h,lo,ci]),fo=Z.useMemo(()=>!ci||!ci.includes(`@`)||h===`shell`?[]:Wr(ci,{confirmedValues:Ai,agentNames:Ja}),[Ai,h,Ja,ci]),po=Z.useMemo(()=>{if(!ci||!ci.includes(`[`)||h===`shell`||qa.length===0)return[];let e=qa.filter(Fe),t=new Map(e.map(e=>[e.filename.trim().toLowerCase(),e.mimeType.startsWith(`image/`)?`image`:`attachment`]));return De(ci,e.map(e=>e.filename)).flatMap(e=>{let n=G(ci.slice(e.start+1,e.end-1)).trim(),r=t.get(n.toLowerCase());return[{...e,style:`mentionFile`,priority:101,visual:re({trigger:`[`,icon:r===`image`?`file-image`:`attachment-2`,label:n,suffix:`]`},ci.slice(e.start,e.end))}]})},[h,ci,qa]),mo=Is(Gr)&&Ln.kind===`primary`,ho=Z.useMemo(()=>{if(!ci||h===`shell`)return null;let e=[...mo?[]:xv(ci),...mo?[]:Lv(ci),...Ev(fo),...so,...uo,...po,...si.references.map(e=>({start:e.start,end:e.end,priority:103,...A(e)}))];return Sv(ci,e)},[po,so,uo,fo,si.references,h,ci,mo]),go=Z.useCallback(e=>(e??[]).map(e=>({...e,dataUrl:e.source===`server`&&e.serverPath?Vb(e.serverPath):e.dataUrl})),[]),[_o,vo]=Z.useState(null),yo=Z.useRef(null),[bo,xo]=Z.useState(!1),[So,Co]=Z.useState(!1),[wo,To]=Z.useState(null),[Eo,Oo]=Z.useState(null),ko=C(e=>e.followUpBehavior),Ao=Z.useMemo(()=>{let e=Rn?.queueScope;return e?{state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:e.deliveryTarget,runtimeGeneration:e.runtimeGeneration}:null},[Rn]),Mo=Wu({transportIdentity:Ao?.transportIdentity??``,directory:Ao?.directory??``,sessionID:Ao?.sessionID??``}),Fo=Z.useMemo(()=>Hn?x(Hn):null,[Hn]),Io=C(Z.useCallback(e=>Ao?b(e,Ao):Tb,[Ao])),Lo=C(Z.useCallback(e=>Fo?b(e,Fo):Tb,[Fo])),zo=Z.useMemo(()=>Lo.length===0?Io:Io.length===0?Lo:[...Lo,...Io],[Io,Lo]),Uo=Mo.mode===`server`?Tb:zo,Go=C(Z.useCallback(e=>Ao?B(e,Ao):Tb,[Ao])),Ko=C(e=>e.clearQueue),Jo=C(e=>e.removeFromQueue),$o=zn.inlineDrafts,es=$o.length>0,[ns,as,ss]=Z.useMemo(()=>{let e=0,t=0,n=0;for(let r of $o)r.source===`preview-console`?e+=1:r.source===`preview-annotation`?t+=1:n+=1;return[e,t,n]},[$o]),cs=Z.useCallback(e=>{for(let t of zn.inlineDrafts)t.source===e&&zn.removeInlineDraft(t.id)},[zn]),fs=Z.useCallback(()=>{for(let e of zn.inlineDrafts)e.source!==`preview-console`&&e.source!==`preview-annotation`&&zn.removeInlineDraft(e.id)},[zn]),ps=zn.history;Z.useEffect(()=>{ta.current=ci},[ci]),Z.useLayoutEffect(()=>{g(`normal`),Xe(-1)},[Xn?.transportIdentity,Xn?.owner.kind,Xn?.owner.ownerID]),Z.useLayoutEffect(()=>{if(!Gn||Gr)return;let e=()=>{let e=Mi.current;!e||e.disabled||e.focus({preventScroll:!0})};e();let t=window.requestAnimationFrame(e);return()=>window.cancelAnimationFrame(t)},[Gn,Gr]);let ms=Ag(Ln.kind===`primary`?Hn:null,Ln.kind===`primary`?Yn??void 0:void 0),hs=Ln.activity?.phase??ms.phase,gs=nr(Z.useCallback(e=>{if(!Hn)return!1;let t=e.runsByOriginalSessionID[Hn];return t?.status===`running`&&t.runtimeKey===i()},[Hn])),_s=J(e=>{Gr&&(Ke(),me(e),Mi.current?.blur(),br.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobilePanel`}))}),vs=zn.pendingInput,ys=zn.consumePendingInput;Z.useEffect(()=>{if(vs===null)return;let e=ys();if(e){if(e.mode===`append`){if(!e.text.trim())return;let t=tx(ta.current,e.text);ta.current=t,Oi(t)}else if(e.mode===`append-inline`){let t=nx(ta.current,e.text);ta.current=t,Oi(t)}else ui(e.text);setTimeout(()=>{Mi.current?.focus()},0)}},[vs,ys,ui,Oi]);let bs=ci.trim().length>0||qa.length>0||es,xs=Mo.mode===`server`?Mo.items.length>0:Uo.length>0||Go.length>0,Ss=!zf(Mo.mode),Cs=bs||xs,ws=ni(e=>e.stagedMessageEdit?.sessionId===Hn?e.stagedMessageEdit.messageId:null),Ts=hs===`busy`||hs===`retry`,Es=Ln.activity?.canAbort??Ts,Ds=Z.useCallback(()=>{let e=Mi.current,t=e?.value??ra().text;t!==ra().text&&fi(t,e?.selectionStart??t.length,e?.selectionEnd??e?.selectionStart??t.length);let n=ra();return{message:n.text,document:n,hasContent:n.text.trim().length>0||qa.length>0||es}},[fi,ra,es,qa.length]),Os=Z.useRef(async()=>{}),ks=Ln.surfaceID,As=Lt?.draftID??null,js=gn(Z.useMemo(()=>_t(ks),[ks])),Ns=gn(Z.useMemo(()=>pn(As),[As])),Ps=Z.useMemo(()=>ti(js,Ns),[js,Ns]),Fs=(e=`send`)=>gn.getState().beginFlight(ks,e),Ls=()=>{gn.getState().endFlight(ks)},zs=()=>gn.getState().isInFlight(ks),Bs=Z.useRef(null);Z.useEffect(()=>{if(Ln.kind!==`primary`||!ws){Bs.current=null;return}Bs.current!==ws&&(Bs.current=ws,Am(Mi)||requestAnimationFrame(()=>Am(Mi)))},[ws,Ln.kind]);let Vs=gn(Z.useMemo(()=>Yr(As),[As])),Hs=J(async()=>{let e=ni.getState().newSessionDraft.draftID;if(!e||!gn.getState().isEstablishing(e))return!1;let t=Ds();if(!t.hasContent)return!1;let n=K(t.document,`queue-canonical`);if(!n.ok)return In.error(f(`chat.chatInput.toast.messageSendFailed`)),!1;if(await Ln.selection.flush(),!gn.getState().isEstablishing(e))return!1;let r=Hy(br.getState());if(!r?.providerID||!r?.modelID)return In.error(f(`chat.chatInput.toast.messageSendFailed`)),!1;let i=go(qa);return gn.getState().enqueueEstablishingFollowUp({draftID:e,content:n.text,sendConfig:{providerID:r.providerID,modelID:r.modelID,...r.agent?{agent:r.agent}:{},...r.variant?{variant:r.variant}:{}},attachments:i,composerDocument:t.document})?(ui(``),Xe(-1),ii(!1),i.length>0&&zn.clearAttachments(),!0):!1}),Us=()=>{if(Hn)return!1;let e=ni.getState().newSessionDraft.draftID;return gn.getState().isEstablishing(e)?(Hs(),!0):!1},Ws=J(async()=>{if(!Ln.active||zs())return;if(Hn){let e=ni.getState().stagedMessageEdit;if(e&&e.sessionId===Hn){ni.getState().beginMessageEditCommit(e.sessionId,e.messageId);try{await Gt(e.sessionId,e.messageId)}catch(e){console.warn(`[chat-input] staged-edit delete failed before queue admission`,e);return}finally{ni.getState().endMessageEditCommit(e.sessionId,e.messageId)}ni.getState().stagedMessageEdit===e&&ni.getState().clearStagedMessageEdit(e.sessionId)}}let e=Ds(),t=K(e.document);if(!t.ok){In.error(f(`chat.chatInput.toast.messageSendFailed`));return}let r={chunks:t.chunks??[],semantics:t.semantics??[]},i=t.text,a=i.trimStart(),o=r.chunks.every(e=>e.provenance===`authored`)&&h===`normal`&&a.startsWith(`/`)?jo(a.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(o&&!Bo(o,e=>Fm(Ln,{name:e.name,source:`openchamber`}))||l||!e.hasContent||!Hn)return;if(Ss||!Rt(Ln.deliveryTarget?.kind,Mo.mode)){Os.current(Ts?{delivery:`steer`}:void 0);return}if(r.chunks.every(e=>e.provenance===`authored`)&&cy(i,h)){Os.current();return}if(!Fs(`queue`))return;let s=Ln.transportIdentity,u=Ln.runtimeGeneration,d=zn.captureRuntime(),p=Ao,m=Ln.kind===`primary`?Ao?.sessionID??Hn:null,g=[...zn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt),_=g.length>0?v(Pu(e.document.text,g),e.document.references).document:e.document,y=K(_,`queue-canonical`);if(!y.ok){Ls(),In.error(f(`chat.chatInput.toast.messageSendFailed`));return}let b=go(qa),w=yi(),T=b,E=er(),D=!1,O=null,k=()=>{D&&p&&(Mo.actions.unstageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID}}),D=!1),O&&p&&(C.getState().unstageAdmission(p,O),O=null)},A=async e=>{k(),w&&Si(w),T.length>0&&await zn.restoreAttachments(T),e&&zn.restoreSyntheticParts(e),g.length>0&&zn.restoreInlineDrafts(g)};try{if(!p){In.error(f(`chat.chatInput.toast.messageSendFailed`));return}if(Mo.mode===`server`){if(!Xn){In.error(f(`chat.chatInput.toast.messageSendFailed`));return}bi({stage:()=>{Mo.actions.stageAdmission({requestID:E.requestID,scope:{directory:p.directory,sessionID:p.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:Ti}}),D=!0},clearComposer:()=>{ui(``),Xe(-1),ii(!1)}})}else bi({stage:()=>{C.getState().bindLegacyQueue(x(p.sessionID),p),C.getState().stageAdmission(p,{requestID:E.requestID,queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,createdAt:E.createdAt,attachmentCount:b.length,composerDocument:_,composerMentions:Ti}),O=E.requestID},clearComposer:()=>{ui(``),Xe(-1),ii(!1)}});if(await Ln.selection.flush(),!Tn({transportIdentity:s,generation:u},{transportIdentity:n(),generation:c()})){await A();return}if(!Tn(d,zn.captureRuntime())){await A();return}if(m&&ni.getState().currentSessionId!==m){await A();return}if(p.transportIdentity!==n()||p.runtimeGeneration!==c()||p.sessionID!==(m??p.sessionID)||m&&S(ni.getState().getDirectoryForSession(m))!==S(p.directory)){await A();return}let t=p,r=Ln.kind===`primary`?(()=>{let e=br.getState(),t=m?ni.getState().getDirectoryForSession(m)??null:null;return Hy(e,{expectedConfigKey:Di(t),activeDirectoryKey:e.activeDirectoryKey})})():Ln.selection.value.providerID&&Ln.selection.value.modelID?{...Ln.selection.value,providerID:Ln.selection.value.providerID,modelID:Ln.selection.value.modelID}:void 0;if(!ir(r)){await A();return}if(Mo.mode===`server`){if(!Xn){await A(),In.error(f(`chat.chatInput.toast.messageSendFailed`));return}let n=Qt({draftKey:Xn,runtime:d,document:e.document,attachments:qa,inlineDrafts:g}),i=t.deliveryTarget.kind===`assistant`?zn.consumeSyntheticParts()?.map(e=>({...e,partID:e.partID??L()}))??null:null,a,o=[],s=t.deliveryTarget.kind===`assistant`?(()=>{let e=pi({plan:{chunks:y.chunks??[],semantics:y.semantics??[]},agents:Br,installedSkillNames:new Set(ki(ne,Yn).map(e=>e.name)),directory:Yn,root:va||Yn,confirmedFilePaths:Ci.map(e=>e.path),confirmedDirectoryPaths:Ci.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:qa});return o=e.attachments,dt({text:g.length>0?Pu(e.text,g):e.text,attachments:[...b,...e.attachments],semanticParts:li(e.semantics,t.directory),syntheticParts:i})})():void 0;try{let e=[...nn(b),...nn(o),...(i??[]).flatMap(e=>nn(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),In.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`));return}let c=s&&i?Dr(s,i.map(e=>({...e,partID:e.partID}))):void 0;try{let e=!1,o=await Kn({capture:n,admit:async()=>{let n=await Mo.actions.admit({requestID:E.requestID,scope:{directory:t.directory,sessionID:t.sessionID},item:{queueItemID:E.queueItemID,operationID:E.operationID,messageID:E.messageID,content:y.text,composerDocument:_,composerMentions:Ti,sendConfig:r,deliveryTarget:t.deliveryTarget,...s?{deliveryParts:s}:{},...c?{syntheticParts:c}:{},attachmentIssues:[],createdAt:E.createdAt},attachments:a});return n.status===`committed`&&(e=!0,D=!1),n},captureRuntime:zn.captureRuntime,getCurrentDraftKey:()=>Xn,getDocument:ra,consumeBody:()=>ui(``),getAttachments:()=>zn.attachments,removeAttachment:zn.removeAttachment,getInlineDrafts:()=>zn.inlineDrafts,removeInlineDraft:zn.removeInlineDraft});if(!e){await A(i),o.status===`stale`&&In.error(f(`chat.chatInput.toast.messageSendFailed`));return}if(o.status===`partial`){In.error(f(`chat.chatInput.toast.messageSendFailed`));return}o.status===`committed`&&!Gr&&Mi.current?.focus()}catch(e){await A(i),In.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}return}if(!C.getState().confirmAdmission(t,{requestID:E.requestID,sendConfig:r,attachments:b.length>0?b:void 0}).ok){await A(),In.error(f(`chat.chatInput.toast.messageSendFailed`));return}O=null;for(let e of g)zn.removeInlineDraft(e.id);b.length>0&&zn.clearAttachments(),Gr||Mi.current?.focus()}catch(e){await A(),In.error(f(e instanceof RangeError?`chat.chatInput.toast.attachmentsTooLarge`:`chat.chatInput.toast.messageSendFailed`))}finally{Ls()}}),Gs=J(()=>{vy(()=>Ws(),()=>{In.error(f(`chat.chatInput.toast.messageSendFailed`))})}),Ks=J(async(e,t,n,r)=>{if(Ss||!Ln.draftKey)return!1;try{let i=await Vn({content:e,composerDocument:n,composerMentions:r,attachments:t}),a=Yt.getState(),o=a.getDraft(Ln.draftKey);return Vf(await Wt({key:Ln.draftKey,expectedRevision:o?.revision??`absent`,payload:i,runtime:a.captureDraftRuntime()}))?!0:(In.error(f(`chat.chatInput.toast.messageSendFailed`)),!1)}catch{return In.error(f(`chat.chatInput.toast.messageSendFailed`)),!1}}),qs=J(e=>{if(!(l||Ss)){if(Rn){Rn.sendQueued(e,{options:{delivery:`steer`},manual:!0});return}In.error(f(`chat.chatInput.toast.messageSendFailed`))}}),Js=J(()=>{Ke(),me(`agent`),Mi.current?.blur(),br.getState().refreshCatalogsOnPickerOpen({source:`chatInput:mobileAgentPanel`})}),Ys=Z.useCallback(()=>{xo(!0)},[]),Xs=Z.useCallback(()=>{Co(!0)},[]),Zs=async e=>{if(!Ln.active||l||Us()||zs())return;let t=e?.queuedOnly??!1,i=e?.queuedMessageId,a=e?.delivery===`steer`&&Ts?`steer`:void 0,o=e?.presetText==null?Ds():{message:e.presetText,document:{text:e.presetText,references:[]},hasContent:e.presetText.trim().length>0||qa.length>0||es},u=e?.presetText==null?yi():null,p=Bn,m=K(o.document,`direct-send-display`);if(!m.ok){In.error(f(`chat.chatInput.toast.messageSendFailed`));return}let g=m.text,v={chunks:m.chunks??[],semantics:m.semantics??[]},y=v.chunks.every(e=>e.provenance===`authored`),x=g.trimStart(),S=y?oy(x,h):null,w=y&&cy(g,h),T=y&&h===`normal`&&/^\/model(?:\s|$)/i.test(x),E=y&&h===`normal`&&x.startsWith(`/`)?jo(x.slice(1).trim()).split(/\s+/)[0]?.toLowerCase():void 0;if(E&&!Bo(E,e=>Fm(Ln,{name:e.name,source:`openchamber`}))||t&&Ss)return;if(!t&&T){N(!1),I(``),Gr?_s(`model`):(s.getState().setModelSelectorOpen(!0),br.getState().refreshCatalogsOnPickerOpen({source:`chatInput:modelCommand`}));return}if(!(!t&&S&&S!==`model`)){if(!t&&Hn&&xs&&Ss)return;if(!t&&Hn&&xs&&Mo.mode===`server`){o.hasContent&&Gs();return}if(!t&&Hn&&xs){o.hasContent&&Gs();let e=Uo[0];e&&Rn&&await Rn.sendQueued(e.queueItemID,{options:Ts?{delivery:`steer`}:void 0});return}}let D=w?[]:i?Uo.filter(e=>e.id===i):Uo;if(t&&gs)return;if(t){if(D.length===0||!Hn)return}else if(!o.hasContent&&!xs||!Hn&&!Gn)return;if(!Hn&&Un||!Fs())return;let O=!Hn&&Gn&&!t&&!w?ni.getState().newSessionDraft.draftID??null:null,k=O?W(`msg`):void 0;if(O&&k&&!gn.getState().beginEstablishing({draftID:O,primaryMessageID:k})){Ls();return}let A=()=>{dr(),O&&gn.getState().clearEstablishing(O)},j=e=>{let t=ni.getState().currentSessionId,r=(t?ni.getState().getDirectoryForSession(t):null)??Yn??``;if(!t||!r){gn.getState().clearEstablishing(e);return}_y({draftID:e,sessionID:t,directory:r,transportIdentity:n(),runtimeGeneration:c(),admitServer:Mo.mode===`server`?async e=>Mo.actions.admit({requestID:e.requestID,scope:{directory:r,sessionID:t},item:{queueItemID:e.queueItemID,operationID:e.operationID,messageID:e.messageID,content:e.content,createdAt:e.createdAt,sendConfig:e.sendConfig,attachmentIssues:[],...e.composerDocument?{composerDocument:e.composerDocument}:{},...e.composerMentions?{composerMentions:e.composerMentions}:{}},attachments:e.attachments.length>0?nn(e.attachments):void 0}):void 0})};if(Hn&&!t&&!w&&gs){Ls(),Gs();return}let M=!t&&!w;M&&(ui(``),Xe(-1),ii(!1));let P=!1,F,L,R=!1;try{if(py({surfaceKind:Ln.kind,currentSessionId:Hn,queuedOnly:t,resourcePolicy:w,inputMode:h,localCommand:S})&&Hn){let e=ni.getState().getDirectoryForSession(Hn)??Yn??null,t=ni.getState().stagedMessageEdit;t&&t.sessionId===Hn&&(L={sessionId:t.sessionId,messageId:t.messageId},ni.getState().beginMessageEditCommit(t.sessionId,t.messageId));let n=br.getState(),r=Hy(n,{expectedConfigKey:Di(e),activeDirectoryKey:n.activeDirectoryKey});if(r?.providerID&&r?.modelID){let t=go(qa);F=bt({sessionId:Hn,directory:e,content:o.message,providerID:r.providerID,modelID:r.modelID,agent:r.agent,files:t.map(e=>({type:`file`,mime:e.mimeType,url:e.dataUrl,filename:e.filename}))})}}let e=Ln.kind===`primary`?(()=>{if(t){let e=D[0]?.owner;if(e?.state===`bound`||e?.state===`unbound-legacy`)return e.sessionID;if(Ao?.sessionID)return Ao.sessionID}return Hn})():null,n=t?D[0]?.sendConfig:void 0;if(t&&n||await Ln.selection.flush(),e!==null&&ni.getState().currentSessionId!==e)return;let s=async()=>{let t=n?{...n}:Ln.kind===`primary`?(()=>{let t=br.getState();if(!e)return Wy({captured:Hy(t),surfaceSelection:Ln.selection.value});let n=ni.getState().getDirectoryForSession(e)??Yn??null;return Wy({captured:Hy(t,{expectedConfigKey:Di(n),activeDirectoryKey:t.activeDirectoryKey}),surfaceSelection:Ln.selection.value})})():Ln.selection.value.providerID&&Ln.selection.value.modelID?{...Ln.selection.value,providerID:Ln.selection.value.providerID,modelID:Ln.selection.value.modelID}:void 0;if(Ln.kind===`primary`&&e&&(!t?.providerID||!t?.modelID)){let n=ni.getState().getDirectoryForSession(e)??Yn??null,r=Di(n);if(br.getState().activeDirectoryKey!==r&&await br.getState().activateDirectory(n),ni.getState().currentSessionId===e){let e=br.getState();t=Wy({captured:Hy(e,{expectedConfigKey:Di(n),activeDirectoryKey:e.activeDirectoryKey}),surfaceSelection:Ln.selection.value})}}return t},c=await s(),l=!1,m=c?.providerID,g=c?.modelID,y=c?.agent,x=c?.variant;if(!m||!g){if(!l){l=!0;try{await br.getState().loadProviders({forceRefresh:!0,source:`chat-input-send-recovery`}),c=await s(),m=c?.providerID,g=c?.modelID,y=c?.agent,x=c?.variant}catch{}}if(!m||!g){console.warn(`Cannot send message: provider or model not selected`),In.error(f(`chat.chatInput.toast.messageSendFailed`));return}}Hn&&!t&&!w&&await Jn(Hn)&&await jn(Hn);let T={...a?{delivery:a}:{},commitStagedMessageEdit:!t,...F?{messageID:F.messageID,ticket:F}:k?{messageID:k}:{},...e?{sessionId:e,directoryHint:ni.getState().getDirectoryForSession(e)??Yn??null}:Ln.kind===`primary`&&Hn?{sessionId:Hn,directoryHint:ni.getState().getDirectoryForSession(Hn)??Yn??null}:{}},E=``,M=[],N,I=[],z=new Set(ki(ne,Yn).map(e=>e.name)),B=[],V=w?void 0:zn.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:Yn,a=new Set(ki(ne,i).map(e=>e.name)),o=pi({plan:r??Ei(t.content),agents:Br,installedSkillNames:a,directory:i,root:i,confirmedFilePaths:t.composerMentions?.filter(e=>e.kind===`file`||e.kind===`directory`).map(e=>e.path||e.value),confirmedDirectoryPaths:t.composerMentions?.filter(e=>e.kind===`directory`).map(e=>e.path||e.value),citationAttachments:t.attachments});if(B.push(...o.semantics),!N&&o.agent&&(N=o.agent),e===0)E=o.text,M=Rr([...go(t.attachments),...o.attachments]);else{let e=go(t.attachments);I.push({text:o.text,attachments:Rr([...e,...o.attachments])})}}if(!t&&o.hasContent){let e=go(qa),t=pi({plan:v,agents:Br,installedSkillNames:z,directory:Yn,root:va||Yn,confirmedFilePaths:Ci.map(e=>e.path),confirmedDirectoryPaths:Ci.filter(e=>e.kind===`directory`).map(e=>e.path),citationAttachments:qa});B.push(...t.semantics),!N&&t.agent&&(N=t.agent),D.length===0?(E=t.text,M=Rr([...e,...t.attachments])):I.push({text:t.text,attachments:Rr([...e,...t.attachments])})}let H=Hn??(Gn?`draft`:null),U=[];if(!t&&H&&!w&&(U=[...zn.inlineDrafts].sort((e,t)=>e.createdAt-t.createdAt)),U.length>0)if(D.length===0)E=Pu(E,U);else if(I.length>0){let e=I[I.length-1];e.text=Pu(e.text,U)}else E=Pu(E,U);if(V&&V.length>0&&I.push(...Ni(V)),wo&&I.push({text:wo.contextText,synthetic:!0}),Eo&&(I.push({text:Eo.instructionsText,synthetic:!0}),I.push({text:Eo.contextText,synthetic:!0})),I.push(...li(B,Hn&&ni.getState().getDirectoryForSession(Hn)||Yn)),!E&&M.length===0&&I.length===0)return;if(O&&k){if(!await zr({messageID:k,providerID:m,modelID:g,agent:y,text:E,attachments:M,additionalParts:I,agentMentionName:N}))return;if(!gn.getState().isEstablishing(O)){A();return}}let W=async()=>{if(A(),Ao&&D.length>0&&C.setState(e=>{let t=_(Ao),n=e.queuedMessages[t]??[],r=new Set(D.map(e=>e.id));return{queuedMessages:{...e.queuedMessages,[t]:[...D,...n.filter(e=>!r.has(e.id))]}}}),t)return V&&zn.restoreSyntheticParts(V),!0;zn.pendingInput?.text===o.message&&zn.consumePendingInput(),u&&Si(u);let e=!0;return p.length>0&&(e=await zn.restoreAttachments(p)),V&&zn.restoreSyntheticParts(V),U.length>0&&zn.restoreInlineDrafts(U),e};if(!w&&Hn&&i){let e=Ao?b(C.getState(),Ao).find(e=>e.id===i||e.queueItemID===i):void 0;Ao&&e?.queueItemID&&e.operationID&&Jo(Ao,e.queueItemID,e.operationID)}else!w&&Hn&&xs&&Ao&&Ko(Ao);!t&&!w&&(ui(``),Xe(-1),ii(!1),fy({queuedOnly:t,resourcePolicy:w,rootAttachmentCount:p.length})&&zn.clearAttachments());let ee=()=>uy({currentSessionId:Hn,messageRef:ta,replacePlainDocument:ui}),G=E.trimStart();if(h===`normal`&&G.startsWith(`/`)){let e=jo(G.slice(1).trim()).split(/\s+/)[0]?.toLowerCase();if(!Bo(e,e=>Fm(Ln,{name:e.name,source:`openchamber`})))return;if(Hn&&(e===`undo`||e===`redo`)&&ly(G,h)&&ee(),e===`undo`&&Hn){try{await ni.getState().handleSlashUndo(Hn),r?.()}catch(e){In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`new`){ly(G,h)&&ee(),await Rn?.shortcut(`new`);return}if(e===`redo`&&Hn){try{await ni.getState().handleSlashRedo(Hn),r?.()}catch(e){In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}return}if(e===`fork`&&Hn){await dy({command:`fork`,consumeCommandText:ee,forkSession:()=>ni.getState().forkCurrentSession(Hn),waitForConnection:wi,getDirectoryForSession:()=>ni.getState().getDirectoryForSession(Hn),summarizeSession:async()=>void 0,onCompactError:()=>void 0,onForkError:e=>{In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.messageSendFailed`))}});return}if(e===`timeline`&&Hn&&aa.timeline){ai(!0);return}if(e===`compact`&&Hn){dy({command:`compact`,consumeCommandText:ee,forkSession:async()=>void 0,waitForConnection:wi,getDirectoryForSession:()=>Ln.directory??``,summarizeSession:e=>Xn?Ln.backend.compact({operation:`compact`,surfaceID:Ln.surfaceID,transportIdentity:Ln.transportIdentity,runtimeGeneration:Ln.runtimeGeneration,sessionID:Hn,directory:e,draftKey:Xn,deliveryTarget:Ln.deliveryTarget,providerID:m,modelID:g,agent:y,variant:x}):Promise.reject(Error(`chat-input-surface-incomplete`)),onCompactError:()=>{In.error(f(`chat.chatInput.toast.compactFailed`))},onForkError:()=>void 0});return}if(e===`summary`&&Hn){try{await wi();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 Tr(`session.summary.visible`,{topic_line:t}),a=await Tr(`session.summary.instructions`,{topic_block:n});await $n(i,m,g,y,[],N,[{text:a,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.summaryFailed`))}return}if(e===`workspace-review`&&(Hn||Gn)){try{await wi();let e=await Tr(`session.review.visible`),t=await Tr(`session.review.instructions`);await $n(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.reviewFailed`))}return}if(e===`handoff-review`&&Hn&&!Gr&&!d()){fr(!0);return}if(e===`plan-feature`&&(Hn||Gn)){try{await wi();let e=await Tr(`session.plan.visible`),t=await Tr(`session.plan.instructions`);await $n(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.planFeatureFailed`))}return}if(e===`goal`&&(Hn||Gn)){A(),xn.getState().setArmed(!0);let e=sy(G,h)??``;ui(e),ta.current=e,Xe(-1),e||ii(!1);return}if(e===`craft-goal`&&(Hn||Gn)){try{await wi();let e=G.replace(/^\/\u2003?craft-goal\b/i,``).trim(),t=await Tr(`session.craftGoal.visible`,{idea_block:e?`\n\nHere is my initial idea:\n${e}`:``}),n=await Tr(`session.craftGoal.instructions`);await $n(t,m,g,y,[],N,[{text:n,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.craftGoalFailed`))}return}if(e===`catch-up`&&(Hn||Gn)){try{await wi();let e=await Tr(`session.catchup.visible`),t=await Tr(`session.catchup.instructions`);await $n(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.catchUpFailed`))}return}if(e===`debug`&&(Hn||Gn)){try{await wi();let e=await Tr(`session.debug.visible`),t=await Tr(`session.debug.instructions`);await $n(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.debugFailed`))}return}if(e===`weigh`&&(Hn||Gn)){try{await wi();let e=await Tr(`session.weigh.visible`),t=await Tr(`session.weigh.instructions`);await $n(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.weighFailed`))}return}if(e===`explore`&&(Hn||Gn)){try{await wi();let e=await Tr(`session.explore.visible`),t=await Tr(`session.explore.instructions`);await $n(e,m,g,y,[],N,[{text:t,synthetic:!0}],x,h,T),r?.()}catch(e){await W(),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.exploreFailed`))}return}}let q=Hn&&ni.getState().getDirectoryForSession(Hn)||Yn;if(qn||Hn&&!Lb(Hn,q)){let e=await kn().catch(()=>null);e&&I.push({text:zi(e),synthetic:!0})}try{let e=pa.getState().expandText;E=await e(E);for(let t of I)t.synthetic||(t.text=await e(t.text))}catch(e){console.warn(`[ChatInput] Failed to expand snippets, sending original text:`,e)}R=!0;let te=$n(E,m,g,y,M,N,I.length>0?I:void 0,x,h,T);P=!0,te.finally(()=>{Ls(),L&&ni.getState().endMessageEditCommit(L.sessionId,L.messageId)}),O&&te.then(()=>{j(O)}).catch(()=>{gn.getState().clearEstablishing(O)}),typeof window>`u`?r?.():window.requestAnimationFrame(()=>{r?.()}),te.then(()=>{wo&&To(null),Eo&&Oo(null)}).catch(e=>{F&&or(F),W().then(e=>{e||In.error(f(`chat.chatInput.toast.messageSendFailed`))});let t=e instanceof Error?e.message:typeof e==`string`?e:String(e??``),n=t.toLowerCase();console.error(`Message send failed:`,t||e);let r=n.includes(`timeout`)||n.includes(`timed out`)||n.includes(`may still be processing`)||n.includes(`being processed`)||n.includes(`failed to fetch`)||n.includes(`networkerror`)||n.includes(`network error`)||n.includes(`gateway timeout`)||n===`failed to send message`;if(n.includes(`payload too large`)||n.includes(`413`)||n.includes(`entity too large`)){In.error(f(`chat.chatInput.toast.attachmentsTooLarge`));return}if(r){p.length>0&&In.error(f(`chat.chatInput.toast.sendAttachmentsFailed`));return}In.error(t||f(`chat.chatInput.toast.messageSendFailed`))}),Gr||Mi.current?.focus()}finally{R||(F&&or(F),L&&ni.getState().endMessageEditCommit(L.sessionId,L.messageId)),P||(M&&u&&Si(u),Ls(),O&&j(O))}};Os.current=Zs;let Qs=Z.useCallback(()=>{if(Us()||zs())return;let e=Ds(),t=h===`normal`&&e.hasContent&&Hn&&(Ts||gs),n=t&&zf(Mo.mode)&&Rt(Ln.deliveryTarget?.kind,Mo.mode);ko===`queue`&&n?Gs():ko===`steer`&&t||ko===`queue`&&t&&!n?Os.current(t?{delivery:`steer`}:void 0):Os.current()},[h,Ds,Hn,Ts,gs,ko,Gs,Mo.mode,Ln.deliveryTarget?.kind,Hs]),$s=Z.useCallback(e=>{if(zs())return;let t=(Mi.current?.value??ta.current).trim(),n=t?`${e}\n${t}`:e;Os.current({presetText:n})},[]),ec=Z.useCallback(e=>{let t=nx(ra().text,e);Oi(t),Mi.current&&(Mi.current.value=t),setTimeout(()=>{Mi.current?.focus()},0)},[Oi]),tc=Z.useCallback(e=>{if(zs())return;let t=nx(Mi.current?.value??ta.current,e);Os.current({presetText:t})},[]),nc=zn.pendingPreset,rc=zn.consumePendingPreset;Z.useEffect(()=>{if(nc==null)return;let e=rc();e&&$s(e)},[nc,rc,$s]);let ic=Z.useCallback(()=>{ui(``),Xe(-1),Bn.length>0&&zn.clearAttachments(),Ao&&Ko(Ao),N(!1),z(!1),te(!1),O(!1),h===`shell`&&g(`normal`)},[Bn.length,zn,Ko,Ao,ui,h]),ac=e=>{if(!Ln.active||jg(e))return;if(ha&&Va(e,ha)&&!Xr){let t=Mi.current;if(!(t&&t.selectionStart!==t.selectionEnd)){e.preventDefault(),ic();return}}if(h===`shell`&&e.key===`Escape`){e.preventDefault(),g(`normal`);return}if(h===`shell`&&e.key===`Backspace`&&ci.length===0){e.preventDefault(),g(`normal`);return}if((e.key===`Backspace`||e.key===`Delete`)&&!e.metaKey&&!e.ctrlKey){let t=Mi.current,n=t?.selectionStart??ci.length,r=t?.selectionEnd??ci.length,i=gi({key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(i){let t=Ib(oi.getDocument().text,i.start);e.preventDefault(),Oi(t.text),requestAnimationFrame(()=>{Mi.current?.setSelectionRange(t.caret,t.caret),gc()}),_c(t.text,t.caret);return}let a=Oe(ci,Bn.filter(Fe).map(e=>e.filename),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(a){let t=new Set(a.removedFilenames.map(e=>e.toLowerCase())),n=Ib(a.text,a.caret);e.preventDefault(),Oi(n.text);for(let e of Bn)t.has(e.filename.toLowerCase())&&zn.removeAttachment(e.id);requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=n.caret,Mi.current.selectionEnd=n.caret),gc()}),_c(n.text,n.caret);return}let o=Tv(ci,ao.keys(),{key:e.key,selectionStart:n,selectionEnd:r,altKey:e.altKey});if(o){let t=Ib(o.text,o.caret);e.preventDefault(),Oi(t.text),requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=t.caret,Mi.current.selectionEnd=t.caret),gc()}),_c(t.text,t.caret);return}if(n===r&&!e.altKey){let t=e.key===`Backspace`?n-1:n;if(t>=0&&t<ci.length){let n=De(ci,Bn.map(e=>e.filename)).find(e=>t>=e.start&&t<e.end);if(n){let t=G(ci.slice(n.start+1,n.end-1)).trim(),r=Bn.find(e=>e.filename.toLowerCase()===t.toLowerCase()),i=ci[n.end]===` `?n.end+1:n.end,a=`${ci.slice(0,n.start)}${ci.slice(i)}`;e.preventDefault(),Oi(a),r&&zn.removeAttachment(r.id),requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=n.start,Mi.current.selectionEnd=n.start),gc()}),_c(a,n.start);return}let r=t;for(;r>0&&!/\s/.test(ci[r-1]);)--r;let i=t+1;for(;i<ci.length&&!/\s/.test(ci[i]);)i+=1;let a=ci.slice(r,i),o=a.slice(1);if(kb.test(a)&&!$a.current.has(o.toLowerCase())&&wr({mention:o,confirmed:Ai.has(o),terminated:i<ci.length&&/\s/.test(ci[i])})){let t=ci[i]===` `?i+1:i,n=`${ci.slice(0,r)}${ci.slice(t)}`;e.preventDefault(),Oi(n),requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=r,Mi.current.selectionEnd=r),gc()}),_c(n,r);return}}}}let t=(e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.metaKey&&!e.ctrlKey;if(M&&Qi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Qi.current.handleKeyDown(e.key);return}if(R&&$i.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),$i.current.handleKeyDown(e.key);return}if(q&&ea.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),ea.current.handleKeyDown(e.key);return}if(D&&Xi.current&&(e.key===`Enter`||e.key===`Escape`||e.key===`Tab`||t)){e.preventDefault(),e.stopPropagation(),Xi.current.handleKeyDown(e.key);return}if(Ba&&e.key===`Escape`){e.preventDefault(),ii(!1);return}let n=ma&&!ma.includes(`shift`)?Xa(`shift+${ma}`):``,r=n&&Va(e,n)?-1:+!!Va(e,ma);if(r!==0&&!M&&!R&&!q&&!D){e.preventDefault(),e.stopPropagation(),Rn?.shortcut(`cycle`,r),requestAnimationFrame(()=>{Mi.current?.focus({preventScroll:!0})});return}let i=M||R||q||D,a=Mi.current?.selectionStart===0&&Mi.current?.selectionEnd===0,o=Mi.current?.selectionStart===ci.length&&Mi.current?.selectionEnd===ci.length,s=!i&&(ci.length===0||a),c=!i&&(ci.length===0||o);if(h===`normal`&&!i&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=Mi.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&n>=0){let t=(t,n,r)=>{e.preventDefault(),Oi(t),requestAnimationFrame(()=>{let e=Mi.current;e&&(e.selectionStart=n,e.selectionEnd=r),gc()}),_c(t,r)},i={"`":["`","`"],"*":[`*`,`*`],_:[`_`,`_`],"~":[`~`,`~`],"(":[`(`,`)`],"[":[`[`,`]`],"{":[`{`,`}`],'"':[`"`,`"`],"'":[`'`,`'`]};if(r>n&&i[e.key]){let[a,o]=i[e.key],s=ci.slice(n,r);t(`${ci.slice(0,n)}${a}${s}${o}${ci.slice(r)}`,n+a.length,r+a.length);return}if(e.key==="`"&&n===r){let e=ci.slice(0,n);if(/(^|\n)``$/.test(e)){let n=`${e}\`\n\n\`\`\`${ci.slice(r)}`,i=e.length+2;t(n,i,i);return}}}}if(e.key===`ArrowUp`&&!e.metaKey&&!e.ctrlKey&&s&&ps.length>0){if(e.preventDefault(),Ye===-1)Xe(0),_i({text:ps[0],references:[]});else if(Ye<ps.length-1){let e=Ye+1;Xe(e),_i({text:ps[e],references:[]})}requestAnimationFrame(()=>{Mi.current?.setSelectionRange(0,0)});return}if(e.key===`ArrowDown`&&!e.metaKey&&!e.ctrlKey&&c&&Ye>=0){if(e.preventDefault(),Ye===0)Xe(-1),vi();else{let e=Ye-1;Xe(e),_i({text:ps[e],references:[]})}return}if(e.key===`Enter`&&!e.shiftKey){if(e.preventDefault(),Us()||zs())return;let t=e.ctrlKey||e.metaKey,n=h===`normal`&&bs&&Hn&&(Ts||gs),r=n&&zf(Mo.mode)&&Rt(Ln.deliveryTarget?.kind,Mo.mode);ko===`queue`?t||!n?Zs():r?Gs():Zs({delivery:`steer`}):t||!n?Zs():Zs({delivery:`steer`})}},oc=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}},[]),sc=Z.useCallback(()=>{if(!Ba){vo(null);return}if(!M&&!R&&!q&&!D){vo(null);return}let e=Mi.current,t=Vi.current;if(!e||!t)return;let n=e.selectionStart??ci.length,r=oc(e,n);if(!r)return;let i=e.getBoundingClientRect(),a=t.getBoundingClientRect(),o=i.top-a.top+(r.top-e.scrollTop),s=i.left-a.left+(r.left-e.scrollLeft),c=o-8,l=a.height-o-8,u=l>=260||l>=c?`below`:`above`,d=D?520:M||q?450:360,f=Math.max(8,Math.min(s-24,a.width-d-8)),p=Math.max(120,Math.min(260,u===`below`?l:c));vo({top:u===`below`?o+22:o-6,left:f,place:u,maxHeight:p})},[Ba,oc,ci.length,M,D,q,R]);Z.useLayoutEffect(()=>{sc()},[sc,ci,M,R,q,D,Ba]),Z.useEffect(()=>{if(!Ba)return;let e=()=>sc();return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[Ba,sc]);let lc=Z.useCallback(()=>{yo.current&&=(clearTimeout(yo.current),null),Aa(!0),yo.current=setTimeout(()=>{Aa(!1),yo.current=null},1800)},[]),uc=Z.useCallback(()=>{if(zn.abortPrompt.clear(),lc(),Ln.kind===`secondary`){Rn?.shortcut(`abort`);return}rr()},[rr,Rn,lc,Ln.kind,zn]),dc=Z.useCallback((e=1)=>{if(Hr)return;let t=tr(Br,Ln.selection.value.agent??yr,e);if(!t||!Ln.selection.change)return;let n=En({providerID:Ln.selection.value.providerID??``,modelID:Ln.selection.value.modelID??``,agent:Ln.selection.value.agent??null},t,Br,Vr);Ln.selection.change({...Ln.selection.value,...n,agent:n.agent??void 0}),Ln.kind===`primary`&&(s.getState().addRecentAgent(t),Ln.sessionID&&rn.getState().saveSessionAgentSelection(Ln.sessionID,t))},[Br,yr,Vr,Hr,Ln.kind,Ln.selection,Ln.sessionID]);Ze.current=dc;let fc=Z.useRef(null),[pc,mc]=Z.useState(null),hc=Z.useCallback(e=>{mc(t=>t===e?t:e)},[]),gc=Z.useCallback(e=>{let t=Mi.current;if(!t)return;let n=t.scrollTop;if(Ua){t.style.height=`100%`,t.style.maxHeight=`none`,t.style.overflowY=`auto`,fe(null),t.scrollTop!==n&&(t.scrollTop=n);return}t.style.overflow=`hidden`,t.style.overflowX=`hidden`,t.style.overflowY=`hidden`,(e?.allowShrink??!0)&&(t.style.height=`auto`);let r=t.ownerDocument?.defaultView,i=r?r.getComputedStyle(t):null,a=i?parseFloat(i.lineHeight):NaN,o=i?parseFloat(i.paddingTop):NaN,s=i?parseFloat(i.paddingBottom):NaN,c=Number.isNaN(o)||Number.isNaN(s)?16:o+s,l=Number.isNaN(a)?22:a,u=Sb({scrollHeight:t.scrollHeight||t.offsetHeight,dictationHeight:fc.current??0,lineHeight:l,paddingTotal:c});t.style.height=`${u.height}px`,t.style.maxHeight=`${u.maxHeight}px`,t.style.overflowY=u.overflowY,t.scrollTop!==n&&(t.scrollTop=n),fe(e=>e&&e.height===u.height&&e.maxHeight===u.maxHeight?e:{height:u.height,maxHeight:u.maxHeight})},[Ua]);Z.useLayoutEffect(()=>{let e=ci.length<Bi.current;Bi.current=ci.length,gc({allowShrink:e})},[gc,ci,Gr]),Z.useLayoutEffect(()=>{fc.current=pc,gc({allowShrink:pc===null})},[gc,pc]);let _c=Z.useCallback((e,t,n=`manual`,r)=>{let i=Ho({text:e,cursor:t,inputMode:h,mentionInputSource:n,insertedText:r});if(Ri.current=i,!i){N(!1),O(!1),z(!1),te(!1),H(``);return}if(i.kind===`slash-command`){I(i.query),N(!0),O(!1),z(!1),te(!1);return}if(N(!1),i.kind===`slash-skill`){H(i.query),z(!0),O(!1),te(!1);return}if(z(!1),H(``),i.kind===`snippet`){ae(i.query),te(!0),O(!1);return}te(!1),j(i.query),O(!0)},[h,I,j,N,O,z,te,H,ae]),vc=Z.useCallback((e,t,n,r=`manual`,i)=>{let a=e,o=t,s=n;if(h===`normal`&&!Ii.current&&oo.size>0&&e.includes(`/`)){let r=us(e,oo,n);r&&(a=r.text,o=t+(r.caret-n),s=r.caret)}let c=fi(a,o,s,(e,t)=>{let n=[...e];for(let e of gr(t.text,{agentNames:Ja,includeUnterminatedPastedReferences:r===`paste`}))n=ts(n,{kind:e.kind,value:e.value,path:e.value,label:e.value,range:{start:e.start,end:e.end}});return n}),l=ra(),u=c.requiresTextCorrection||o!==c.start||s!==c.end||a!==e;return requestAnimationFrame(()=>{let e=Mi.current;e&&jm(u,Ii.current)&&(e.value=l.text,e.setSelectionRange(c.start,c.end)),gc()}),_c(l.text,c.end,r,i),{document:l,selection:c}},[gc,fi,ra,h,Ja,oo,_c]),yc=Z.useCallback((e,t=`manual`)=>{if(!e)return;let n=Mi.current;if(!n){let n=ci+e;vc(n,n.length,n.length,t,e);return}let r=n.selectionStart??ci.length,i=n.selectionEnd??ci.length,a=`${ci.substring(0,r)}${e}${ci.substring(i)}`,o=r+e.length;vc(a,o,o,t,e)},[vc,ci]),bc=J((e,t)=>{let n=new Set(Ce(Bn.map(e=>e.filename),e,t));if(n.size!==0)for(let e of Bn)n.has(e.filename)&&zn.removeAttachment(e.id)}),xc=Z.useCallback(e=>{zn.removeAttachment(e.id)},[zn]),Sc=Z.useCallback(()=>{Ui.current=!1,qi.current=[],Wi.current&&=(clearTimeout(Wi.current),null)},[]),Cc=Z.useCallback(()=>{Wi.current&&clearTimeout(Wi.current),Wi.current=setTimeout(()=>{Sc()},700)},[Sc]),wc=Z.useCallback(()=>{Gi.current=!1,Ki.current&&=(clearTimeout(Ki.current),null)},[]),Tc=Z.useCallback(()=>{Gi.current=!0,Ki.current&&clearTimeout(Ki.current),Ki.current=setTimeout(()=>{Gi.current=!1,Ki.current=null},700)},[]),Ec=Z.useCallback(e=>{!d()||!Ui.current||e.nativeEvent?.inputType===`insertFromDrop`&&(e.preventDefault(),Sc())},[Sc]),Dc=e=>{if(Xr)return;let t=e.nativeEvent;if(d()&&Ui.current){let n=qi.current;if(t?.inputType===`insertFromDrop`||n.some(t=>t.length>0&&e.target.value.includes(t))){Sc();return}}let n=e.target.value;bc(ta.current,n);let r=e.target.selectionStart??n.length,i=t?.inputType?.startsWith(`insertFromPaste`)?Pb(ta.current,n):``,a=i.includes(`@`)||Gi.current;Gi.current&&wc();let o=a?`paste`:`manual`;if(h===`normal`&&n.startsWith(`!`)){let e=n.slice(1),t=Math.max(0,r-1);g(`shell`),ui(e),gc(),N(!1),z(!1),O(!1),requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=t,Mi.current.selectionEnd=t)});return}vc(n,r,e.target.selectionEnd??r,o,i)};Z.useEffect(()=>()=>{Sc(),wc()},[Sc,wc]);let Oc=Z.useCallback(e=>{let t=Array.from(new Set(e.map(e=>e.trim()).filter(Boolean)));if(t.length===0)return;let n=t.map(e=>`@${e}`).join(` `),r=Mi.current,i=r?.selectionStart??ci.length,a=r?.selectionEnd??ci.length,o=Xo(n,ci.slice(0,i),ci.slice(a)),s=`${ci.slice(0,i)}${o}${ci.slice(a)}`;bc(ci,s),ia(s,t)},[ci,ia,bc]),kc=Z.useCallback(async e=>{let t=Hb(e.clipboardData);if(t.length>0&&(Hn||Gn)){e.preventDefault(),Oc(t);return}if(h===`normal`&&(Hn||Gn)){let t=Mi.current,n=t?.selectionStart??-1,r=t?.selectionEnd??-1;if(t&&r>n){let t=e.clipboardData.getData(`text`).trim(),i=ci.slice(n,r);if(jb.test(t)&&!/\s/.test(t)&&i.trim().length>0&&!i.includes(`](`)){e.preventDefault();let a=`${ci.slice(0,n)}[${i}](${t})${ci.slice(r)}`,o=n+1+i.length+2+t.length+1;Oi(a),requestAnimationFrame(()=>{let e=Mi.current;e&&(e.selectionStart=o,e.selectionEnd=o),gc()}),_c(a,o,Fb(t),t);return}}}let n=Array.from(e.clipboardData.files||[]).filter(e=>e.type.startsWith(`image/`)),r=Array.from(e.clipboardData.items||[]).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e),i=n.length>0?n:(()=>{if(r.length<=1)return r;let e=r.find(e=>/image\/(png|webp|jpe?g|gif)/i.test(e.type));return e?[e]:[r[0]]})(),a=e.clipboardData.getData(`text`);if(i.length===0){if(h===`normal`&&Zy(ra(),a)){e.preventDefault();let t=ra().text,n=Mi.current,r=n?.selectionStart??ci.length,i=n?.selectionEnd??ci.length,o=Qy(a,ci,ra().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>f(`chat.chatInput.pastedTextReference`,{index:e,count:t}),Xy(ra())),s=hi(r,i,{id:o.id,kind:`paste`,text:o.text,characterCount:o.characterCount,index:o.index,display:o.token},{inlineBoundaries:!0,padDocumentEdges:!0}),c=os(s.document.text,s.caret);Mi.current&&(Mi.current.value=s.document.text),requestAnimationFrame(()=>{Mi.current?.setSelectionRange(c,c),gc()}),_c(s.document.text,c),bc(t,s.document.text);return}a.includes(`@`)&&Tc();return}if(!Hn&&!Gn){a.includes(`@`)&&Tc();return}e.preventDefault();let o=je(i,[...Bn.map(e=>e.filename),...na.current]),s=Be(o),c=ra().text,l=Mi.current,u=l?.selectionStart??ci.length,d=l?.selectionEnd??ci.length,p=h===`normal`&&Zy(ra(),a)?Qy(a,ci,ra().references.flatMap(e=>e.kind===`paste`?[{id:e.id,token:e.display,text:e.text,characterCount:e.characterCount,index:e.index}]:[]),({index:e,count:t})=>f(`chat.chatInput.pastedTextReference`,{index:e,count:t}),Xy(ra())):null,m=a?`${a}${/\s$/.test(a)?``:` `}${s}`:s,g=Xo(m,ci.slice(0,u),ci.slice(d));if(p){let e=hi(u,d,{id:p.id,kind:`paste`,text:p.text,characterCount:p.characterCount,index:p.index,display:p.token},{inlineBoundaries:!0,padDocumentEdges:!0}),t=os(e.document.text,e.caret),n=`${e.document.text.slice(0,t)}${s}${e.document.text.slice(t)}`;vc(n,t+s.length,t+s.length,Fb(n),s),bc(c,n)}else yc(g,Fb(g)),bc(c,`${ci.slice(0,u)}${g}${ci.slice(d)}`);for(let e=0;e<i.length;e+=1){let t=o[e],n=Nb(i[e],t);na.current.add(t);try{await zn.addAttachment(n)}catch(e){console.error(`Clipboard image attach failed`,e),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.clipboardAttachFailed`))}finally{na.current.delete(t)}}},[zn,Oc,Bn,gc,Hn,ra,h,hi,Tc,ci,Gn,yc,f,_c,vc,Oi,bc]),Ac=Z.useCallback((e,t)=>{let n=e.currentTarget,r=n.selectionStart??0,i=n.selectionEnd??r;if(i<=r)return;let a=wv(r,i,[...De(ci,Bn.filter(Fe).map(e=>e.filename)),...Cv(ci,ao.keys()),...ra().references]),o=a?.start??r,s=a?.end??i,c=ci.slice(o,s),l=U(c);if(!(l===c&&!a))if(e.preventDefault(),e.clipboardData.setData(`text/plain`,l),t===`cut`){let e=`${ci.slice(0,o)}${ci.slice(s)}`;vc(e,o,o),requestAnimationFrame(()=>{Mi.current?.setSelectionRange(o,o),gc()})}else a&&(a.start!==r||a.end!==i)&&requestAnimationFrame(()=>{Mi.current?.setSelectionRange(o,s)})},[gc,Bn,ao,vc,ra,ci]),jc=Z.useCallback(e=>{Ac(e,`copy`)},[Ac]),Mc=Z.useCallback(e=>{Ac(e,`cut`)},[Ac]),Nc=e=>{let t=Mi.current,n=t&&document.activeElement===t?t.selectionStart??Li.current:Li.current;return ds(e,n)},Pc=()=>{Is(Gr)||Mi.current?.focus()},Fc=e=>{let t=Nc(ci.length),n=Ro(ci,t,Ri.current),r=ci.substring(0,t).lastIndexOf(`@`),i=e.relativePath&&e.relativePath.trim().length>0?e.relativePath.trim():Kc(e.path)||e.name,a=e.isDirectory?[i]:[],o=n?.start??(r===-1?t:r),s=n?.end??t,c=is(ci,o,s,`@${i}`);ia(c.text,[i],a),Li.current=c.caret,requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=c.caret,Mi.current.selectionEnd=c.caret),gc(),_c(c.text,c.caret)}),O(!1),j(``),Pc()},Ic=e=>{let t=Nc(ci.length),n=Ro(ci,t,Ri.current),r=ci.substring(0,t).lastIndexOf(`@`),i=n?.start??(r===-1?t:r),a=n?.end??t,o=is(ci,i,a,`@${e}`);Oi(o.text,t=>ts(t,{kind:`agent`,value:e,path:e,label:e,range:{start:o.start,end:o.end}})),Li.current=o.caret,requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=o.caret,Mi.current.selectionEnd=o.caret),gc(),_c(o.text,o.caret)}),O(!1),j(``),Pc()},Lc=J(e=>{Zi.current||(Zi.current=!0,(async()=>{try{let t=ni.getState().getAuthoritativeDirectoryForSession(e.id);if(!t){In.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}if(await vt(e.id,{directory:t}),!Nr(e.id,t)){In.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`));return}Fr([{type:`session`,sessionId:e.id}],t).catch(()=>void 0);let n=ra(),r=Nc(n.text.length),i=Ro(n.text,r,Ri.current),a=n.text.substring(0,r).lastIndexOf(`@`),o=ri().get(e.id)?.title||e.title||e.id,s=i?.start??(a===-1?r:a),c=i?.end??r,l={id:`session:${e.id}:${L()}`,kind:`session`,sessionId:e.id,display:F({trigger:`@`,icon:`chat-thread`,label:o})},u=hi(s,c,l,{inlineBoundaries:!0,padDocumentEdges:!0}),d=os(u.document.text,u.caret);Li.current=d,requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=d,Mi.current.selectionEnd=d),gc(),_c(u.document.text,d)}),O(!1),j(``),Pc()}catch{In.error(f(`chat.chatInput.toast.sessionReferenceLoadFailed`))}finally{Zi.current=!1}})())}),Rc=J(e=>{let t=ra(),n=Nc(t.text.length),r=Ro(t.text,n,Ri.current)??No(t.text,n);if(!r)return!1;let i=hi(r.start,r.end,e,{inlineBoundaries:!0,padDocumentEdges:!0,padLeadingDocumentEdge:!1}),a=i.document.references.some(t=>t.id===e.id),o=os(i.document.text,i.caret);return Li.current=o,requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=o,Mi.current.selectionEnd=o),gc(),_c(i.document.text,o),a&&(N(!1),z(!1))}),Pc(),a}),zc=e=>{Rc({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&H(``)},Bc=(e,t)=>{let n=Nc(ci.length),r=Ro(ci,n,Ri.current),i=ci.substring(0,n).lastIndexOf(`#`),a=r?.start??(i===-1?n:i),o=r?.end??n,s=`${ci.substring(0,a)}#${t} ${ci.substring(o)}`;Oi(s);let c=a+t.length+2;Li.current=c,requestAnimationFrame(()=>{Mi.current&&(Mi.current.selectionStart=c,Mi.current.selectionEnd=c),gc(),_c(s,c)}),te(!1),ae(``),Pc()},Vc=(e,t=!1)=>{if(!Fm(Ln,e))return;let n=`/${e.name}`;if(!t&&e.isSkill){Rc({id:`skill:${e.name}:${L()}`,kind:`skill`,skillName:e.name,display:F({trigger:`/`,icon:`book-open`,label:e.name})})&&I(``);return}if(!t&&e.source===`opencode`&&!e.isSkill&&e.isBuiltIn!==!0&&Rc({id:`command:${e.name}:${L()}`,kind:`command`,commandName:e.name,reference:e.reference??e.name,display:F({trigger:`/`,icon:`command`,label:e.name})})){I(``);return}let r=e.isSkill?` ${n} `:`${n} `,i=us(r,new Set([...oo,e.name.toLowerCase()]),r.length);ui(i?.text??r);let a=Mi.current;if(a&&(a._commandMetadata=e),N(!1),I(``),t){Zs({presetText:n});return}let o=()=>{if(!Is(Gr)&&Mi.current){try{Mi.current.focus({preventScroll:!0})}catch{Mi.current.focus()}Mi.current.setSelectionRange(Mi.current.value.length,Mi.current.value.length)}};requestAnimationFrame(()=>{o(),requestAnimationFrame(o)}),setTimeout(o,60)};Z.useEffect(()=>{Hn&&Mi.current&&!Gr&&Mi.current.focus()},[Hn,Gr]),Z.useEffect(()=>{Gr||me(null)},[Gr]);let Hc=zn.abortPrompt.sessionID,Uc=zn.abortPrompt.clear;Z.useEffect(()=>{Hc&&Hc!==Hn&&Uc()},[Hn,Hc,Uc]),Z.useEffect(()=>{Yi.current=!!(Hn||Gn)},[Hn,Gn]);let Wc=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 Wv(e).length>0},[]),Gc=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)},[]),Kc=Z.useCallback(e=>{let t=e.replace(/\\/g,`/`).trim(),n=(va||``).replace(/\\/g,`/`).replace(/\/+$/,``);if(!n||t===n)return t;let r=`${n}/`;return t.startsWith(r)?t.slice(r.length):t},[va]),qc=e=>{if(!Wc(e.dataTransfer))return;e.preventDefault(),e.stopPropagation(),Hi.current++;let t=e.dataTransfer.types?.includes(`application/x-openchamber-file-path`)??!1;t!==T&&E(t),(Hn||Gn)&&!y&&w(!0)},Jc=e=>{Wc(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`copy`,(Hn||Gn)&&!y&&w(!0))},Yc=e=>{e.preventDefault(),e.stopPropagation(),Hi.current--,Hi.current<=0&&(Hi.current=0,w(!1),E(!1),Sc())},Xc=()=>{Hi.current=0,w(!1),E(!1),Sc()},Zc=async e=>{if(Hi.current=0,!Wc(e.dataTransfer)){Sc();return}if(e.preventDefault(),e.stopPropagation(),w(!1),!Hn&&!Gn)return;let t=e.dataTransfer.getData(`application/x-openchamber-file-path`);if(t&&t!==`.`){let e=`@${t}`,n=Mi.current,r=ta.current;if(n){let t=n.selectionStart??Li.current,i=n.selectionEnd??t,a=is(r,t,i,e);Oi(a.text),requestAnimationFrame(()=>{n.selectionStart=a.caret,n.selectionEnd=a.caret,Li.current=a.caret,n.focus()})}else{let t=is(r,r.length,r.length,e);Oi(t.text)}Sc();return}let n=Hb(e.dataTransfer);if(n.length>0){d()&&(qi.current=n),Oc(n),d()||Sc();return}let r=Gc(e.dataTransfer);if(r.length>0){let e=Be(r.map(e=>e.name)),t=Xo(e,ta.current.slice(0,Mi.current?.selectionStart??ta.current.length),ta.current.slice(Mi.current?.selectionEnd??ta.current.length));yc(t);for(let e of r)try{await zn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.attachFileFailed`))}}Sc()},Qc=e=>{Wc(e.dataTransfer)&&(e.preventDefault(),d()&&(Ui.current=!0,Cc()))},Q=Z.useRef(null),$c=Z.useRef(null),el=J((e=!0)=>{Ge.current=0;let t=()=>{let t=km(Mi);if(!t||(Am(Mi),!e))return;let n=t.value.length;try{t.setSelectionRange(n,n)}catch{}};t(),window.requestAnimationFrame(t)}),tl=Z.useCallback(async e=>{let t=Array.isArray(e)?e:Array.from(e);if(t.length>0){let e=Be(t.map(e=>e.name)),n=Xo(e,ta.current.slice(0,Mi.current?.selectionStart??ta.current.length),ta.current.slice(Mi.current?.selectionEnd??ta.current.length));yc(n)}for(let e of t)try{await zn.addAttachment(e)}catch(e){console.error(`File attach failed`,e),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.attachFileFailed`))}},[zn,yc,f]),nl=Z.useCallback(async()=>{try{let e=await la?.pickFiles?.(),t=Array.isArray(e?.files)?e.files:[],n=Array.isArray(e?.skipped)?e.skipped:[];if(n.length>0){let e=n.map(e=>`${e?.name||`file`}: ${e?.reason||`skipped`}`).join(`
|
|
6535
|
+
`);In.error(f(`chat.chatInput.toast.someFilesSkipped`,{summary:e}))}let r=t.map(e=>{if(!e?.dataUrl)return null;try{let[t,n]=e.dataUrl.split(`,`),r=e.mimeType||t?.match(/data:(.*);base64/)?.[1]||`application/octet-stream`;if(!n)return null;let i=atob(n),a=new Uint8Array(i.length);for(let e=0;e<i.length;e++)a[e]=i.charCodeAt(e);let o=new Blob([a],{type:r});return new File([o],e.name||`file`,{type:r})}catch(e){return console.error(`Failed to decode VS Code picked file`,e),null}}).filter(Boolean);r.length>0&&(el(!1),await tl(r),el())}catch(e){console.error(`VS Code file pick failed`,e),In.error(e instanceof Error?e.message:f(`chat.chatInput.toast.vscodePickFailed`))}},[tl,el,f,la]),rl=Z.useCallback(()=>{if(d()){nl();return}Q.current?.click()},[nl]),il=Z.useCallback(()=>{if(d()){nl();return}$c.current?.click()},[nl]),al=Z.useCallback(async()=>{if(!dl()){il();return}try{let e=await fl(20);if(e===null){il();return}e.length>0&&(el(!1),await tl(e),el())}catch(e){console.error(`Native photo pick failed`,e),In.error(f(`chat.chatInput.toast.attachFileFailed`))}},[tl,el,il,f]),ol=Z.useCallback(async e=>{let t=e.target.files;!t||t.length===0||(el(!1),await tl(t),e.target.value=``,el())},[tl,el]),sl=`gap-x-1.5 gap-y-0`,cl=d(),ll=Ln.kind===`primary`&&qn&&!cl,ul=Z.useMemo(()=>(Lt?.selectedProjectId?ar.find(e=>e.id===Lt.selectedProjectId)??null:null)||(sr?ar.find(e=>e.id===sr)??null:null)||(ar[0]??null),[sr,Lt?.selectedProjectId,ar]),pl=Z.useMemo(()=>Ub(ul?.path??null),[ul?.path]),ml=ul?Wb(ul):null,hl=rs(pl),gl=qo(e=>pl?e.directories.get(pl)?.lastBranchesFetch??0:0),_l=ls(pl),vl=!!hl?.all,yl=qo(e=>e.fetchBranches),[xl,Sl]=Z.useState(!1);Z.useEffect(()=>{!ll||!pl||!sa||_l!==null||Oa(pl,sa,{silent:!0})},[Oa,sa,_l,pl,ll]),Z.useEffect(()=>{if(!ll||!pl||!ul||!sa||_l!==!0){Sl(!1);return}let e=!gl||Date.now()-gl>3e4;if(vl&&!e){Sl(!1);return}let t=!1;return Sl(!vl),yl(pl,sa).finally(()=>{t||Sl(!1)}),()=>{t=!0}},[yl,sa,ul,gl,vl,_l,pl,ll]);let Cl=Yo(pl),wl=hl?.current?.trim()||Cl?.trim()||``,Tl=Z.useMemo(()=>{if(!ul)return null;let e=Ub(ul.path);return!e||!wl?null:{value:e,label:wl}},[ul,wl]),El=Z.useMemo(()=>{if(!ul)return[];let e=pl?tn.get(pl)??tn.get(ul.path)??[]:[];return Mr({projectRoot:Ub(ul.path)??``,rootBranch:wl,worktrees:e,pendingBootstrapDirectory:Lt?.bootstrapPendingDirectory??null}).filter(e=>e.kind===`worktree`)},[tn,Lt?.bootstrapPendingDirectory,ul,wl,pl]),Dl=Z.useMemo(()=>Ub(Lt?.bootstrapPendingDirectory??null)??Ub(Lt?.directoryOverride??null)??pl,[Lt?.bootstrapPendingDirectory,Lt?.directoryOverride,pl]),Ol=Z.useMemo(()=>{let e=Ub(Lt?.bootstrapPendingDirectory??null);return!!(Lt?.preserveDirectoryOverride||Lt?.pendingWorktreeRequestId||e&&e===Dl)},[Lt?.bootstrapPendingDirectory,Lt?.pendingWorktreeRequestId,Lt?.preserveDirectoryOverride,Dl]),kl=Z.useMemo(()=>{let e=[];return Tl&&e.push(Tl),e.push(...El),!Dl||e.some(e=>e.value===Dl)||!Ol?e:[...e,{value:Dl,label:oa(Dl)}]},[Tl,Dl,Ol,El]),Al=Z.useMemo(()=>ev({selectedDirectory:Dl,projectRootOption:Tl,worktreeOptions:El}),[Tl,Dl,El]),jl=bg()===`mini-chat`,Ml=Z.useMemo(()=>jl||xa!==!0||!Ta||Ta.isClean?!1:ag(Ta.files),[Ta,xa,jl]),Nl=Z.useMemo(()=>!Dl||Tl?.value===Dl||El.some(e=>e.value===Dl),[Tl?.value,Dl,El]);Z.useEffect(()=>{Lt?.open&&(!Lt.preserveDirectoryOverride&&!Lt.bootstrapPendingDirectory||!Dl||!Nl||(Lt.preserveDirectoryOverride&&ni.getState().setDraftPreserveDirectoryOverride(!1),Lt.bootstrapPendingDirectory&&ni.getState().setDraftBootstrapPendingDirectory(null)))},[Lt?.bootstrapPendingDirectory,Lt?.open,Lt?.preserveDirectoryOverride,Nl,Dl]);let Pl=Z.useMemo(()=>_l!==!0||xl?!1:Tl?!0:El.length>0,[xl,Tl,_l,El.length]),Fl=Z.useCallback(e=>{if(ni.getState().newSessionDraft?.pendingWorktreeRequestId)return;let t=ar.find(t=>t.id===e);t&&(sr!==e&&cr(e),en({projectId:e,directoryOverride:t.path},{force:!0}))},[sr,ar,cr,en]),Il=Z.useCallback(e=>{ni.getState().newSessionDraft?.pendingWorktreeRequestId||ul&&en({projectId:ul.id,directoryOverride:e},{force:!0})},[ul,en]),Ll=Z.useCallback(e=>{let t=e.icon?wa[e.icon]:null,n=e.color?Da[e.color]:void 0,r=(0,$.jsx)(X,{name:t??`folder`,className:`h-3.5 w-3.5`,style:n?{color:n}:void 0});return(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`flex h-4 w-4 shrink-0 items-center justify-center overflow-hidden text-muted-foreground`,children:e.iconImage?(0,$.jsx)(ya,{project:e,className:`size-full object-contain`,fallback:r}):r}),(0,$.jsx)(`span`,{className:`truncate`,children:Wb(e)})]})},[]);Z.useEffect(()=>{!ll||!ul||!Dl||Lt?.pendingWorktreeRequestId||Lt?.bootstrapPendingDirectory||Lt?.preserveDirectoryOverride||kl.some(e=>e.value===Dl)||en({projectId:ul.id,directoryOverride:ul.path})},[kl,Lt?.bootstrapPendingDirectory,Lt?.pendingWorktreeRequestId,Lt?.preserveDirectoryOverride,Dl,ul,en,ll]);let Rl=Z.useCallback(()=>{Ke(),xe(!0),Mi.current?.blur()},[Ke]),zl=Z.useCallback(()=>{Ke(),Ee(!0),Mi.current?.blur()},[Ke]);Z.useEffect(()=>{if(!Gr||typeof document>`u`)return;let e=document.getElementById(`mobile-overlay-root`);e||(e=document.createElement(`div`),e.id=`mobile-overlay-root`,document.body.appendChild(e));let t=e,n=()=>We(Ug(t.children));n();let r=new MutationObserver(n);return r.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[Hg]}),()=>r.disconnect()},[Gr]);let Bl=Ue||!!pe||be||Se||bo||So,Vl=Zn(Vr.find(e=>e.id===Ln.selection.value.providerID),Ln.selection.value.modelID,f(`chat.modelControls.selectModel`)),Hl=Ln.selection.value.variant?.trim(),Ul=J(e=>{se(t=>Vo(t,e.rows)),ue(t=>t===e.highlightedIndex?t:e.highlightedIndex)}),Wl=J(e=>Fm(Ln,e)),Gl=J(e=>{if(M){Qi.current?.acceptIndex(e,!0);return}if(R){$i.current?.acceptIndex(e);return}D&&Xi.current?.acceptIndex(e)}),Kl=J(()=>{Ri.current=null,N(!1),z(!1),te(!1),O(!1),se([]),ue(0)}),ql=bl({enabled:Gr&&Ln.kind===`primary`,isMobile:Gr,text:ci,placeholder:Ka,modelLabel:Vl,modelVariantLabel:Hl?xi(Hl):``,canSend:Cs,canAbort:Es,attachmentCount:Bn.length,suppressed:Bl,attachAria:f(`chat.chatInput.actions.addAttachment`),attachTitle:f(`chat.chatInput.actions.addAttachment`),attachPhotosLabel:f(`chat.chatInput.actions.attachPhotos`),attachFilesLabel:f(`chat.chatInput.actions.attachFiles`),attachCancelLabel:f(`chat.chatInput.actions.attachCancel`),sendAria:f(`chat.chatInput.actions.sendMessageAria`),queueAria:f(`chat.chatInput.actions.queueMessageAria`),stopAria:f(`chat.chatInput.actions.stopGeneratingAria`),modelAria:f(`chat.modelControls.selectModel`),modelId:Ln.selection.value.modelID,providerId:Ln.selection.value.providerID,agentName:Ln.selection.value.agent??``,agentLabel:$t(Br,Ln.selection.value.agent??void 0),agentAria:f(`chat.modelControls.selectAgent`),attachments:Bn,removeAttachmentNamedAria:e=>f(`chat.fileAttachment.actions.removeNamed`,{name:e}),onText:(e,t,n)=>{let r=ds(e.length,n?.end??n?.start??e.length);if(Li.current=r,t){Mi.current&&(Mi.current.value=e),Oi(e);return}let i=ta.current,a=Te(i,e,Bn.filter(Fe).map(e=>e.filename)),o=a?.text??e;Mi.current&&(Mi.current.value=o),Oi(o);let s=ds(o.length,n?.end??n?.start??o.length);if(Li.current=s,_c(o,s),!a)return;let c=new Set(a.removedFilenames.map(e=>e.toLowerCase()));for(let e of Bn)c.has(e.filename.toLowerCase())&&zn.removeAttachment(e.id)},onSend:e=>{Mi.current&&(Mi.current.value=e),Rs({text:e,applyDocument:Oi,submit:Qs})},onAbort:uc,onAttach:Ke,onFiles:(e,t)=>{t.length>0&&In.error(f(`chat.chatInput.toast.someFilesSkipped`,{summary:t.join(`
|
|
6536
|
+
`)})),e.length!==0&&tl(e)},onRemoveAttachment:e=>{zn.removeAttachment(e)},onOpenModel:()=>_s(`model`),onCycleAgent:()=>dc(),onOpenAgent:Js,showScrollToBottom:!!(a&&o),scrollAria:f(`chat.scrollToBottom.aria`),onScrollToBottom:o??(()=>{}),autocompleteOpen:oe.length>0&&(M||R||D),autocompleteHighlightedIndex:le,autocompleteRows:oe,caret:Li.current,onAutocompleteAccept:Gl,onAutocompleteDismiss:Kl,chipHighlights:ho}),Jl=Z.useRef(null);at(ql?Jl:null,()=>{let e=Jl.current?.getBoundingClientRect().height??0;Ms(document.documentElement,e)});let Yl=Z.useRef(!1);Yl.current=bo||So;let Xl=Z.useRef(!1),Zl=Z.useRef(0),Ql=Z.useRef(0),$l=J(()=>{let e=ni.getState().stagedMessageEdit;!e||e.sessionId!==Hn||window.setTimeout(()=>{let t=ni.getState().stagedMessageEdit,n=document.activeElement,r=my({surfaceKind:Ln.kind,stagedSessionId:t?.sessionId??null,stagedMessageId:t?.messageId??null,blurredMessageId:e.messageId,submitInFlight:zs(),focusHeld:Date.now()<Ql.current,overlayOpen:Zl.current>0||Yl.current,focusInsideComposer:n instanceof Element&&!!(n.closest(`[data-composer-content="true"]`)||n.closest(`[data-slot="dropdown-menu-content"]`))||Date.now()<Ge.current});r.action===`disarm`&&ni.getState().clearStagedMessageEdit(r.sessionId)},0)});Z.useEffect(()=>{if(!Gr||Re()||typeof window>`u`||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=()=>{Zl.current+=1},t=()=>{if(Zl.current=Math.max(0,Zl.current-1),Xl.current){Xl.current=!1;return}if(!Je.current||Yl.current||Zl.current>0)return;if(Za()){Je.current=!1;return}Je.current=!1,Ql.current=Date.now()+600,Mi.current?.focus(),document.activeElement===Mi.current&&ve(!0);let e=()=>{let e=Mi.current;!e||document.activeElement!==e||(eu.current??e).scrollIntoView({block:`end`})};he.current!==null&&(window.clearTimeout(he.current),he.current=null),ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null),he.current=window.setTimeout(()=>{he.current=null,e()},300),ge.current=window.setTimeout(()=>{ge.current=null,e()},650)};return window.addEventListener(`oc:mobile-overlay-opened`,e),window.addEventListener(`oc:mobile-overlay-closed`,t),()=>{he.current!==null&&(window.clearTimeout(he.current),he.current=null),ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null),window.removeEventListener(`oc:mobile-overlay-opened`,e),window.removeEventListener(`oc:mobile-overlay-closed`,t)}},[Gr]),Z.useEffect(()=>{if(!Gr)return;if(Bl){(_e||Date.now()-qe.current<800)&&(Je.current=!0);return}if(!Je.current)return;let e=window.setTimeout(()=>{if(Je.current=!1,Za())return;let e=Mi.current;e&&document.activeElement!==e&&e.focus({preventScroll:Re()})},180);return()=>window.clearTimeout(e)},[Gr,Bl,_e]),Z.useEffect(()=>{if(!Gr||Re()||typeof document>`u`||_e||!window.matchMedia?.(`(display-mode: standalone)`)?.matches)return;let e=document.documentElement,t=window.setTimeout(()=>{document.activeElement!==Mi.current&&(window.scrollTo(0,0),document.body.scrollTop=0,e.scrollTop=0)},350);return()=>window.clearTimeout(t)},[Gr,_e]),Z.useEffect(()=>{Ie(``)},[Ae]);let eu=Z.useRef(null),tu=Gr?`px-1.5 py-1.5`:cl?`px-1.5 py-1`:`px-2.5 py-1.5`,nu=Gr?`h-8 w-8`:cl?`h-5 w-5`:`h-6 w-6`,ru=Gr?`h-4 w-4`:cl?`h-3.5 w-3.5`:`h-4 w-4`,iu=Gr?`h-6 w-6`:`size-full`,au=Gr?`h-[1.125rem] w-[1.125rem]`:cl?`h-4 w-4`:`h-[1.125rem] w-[1.125rem]`,su=Y(`flex cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed`,pm),cu=Y(su,nu),lu=Y(`flex cursor-pointer items-center justify-center transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed rounded-full hover:opacity-80`,nu),uu=Y(`flex cursor-pointer items-center justify-center transition-none outline-none focus:outline-none flex-shrink-0 disabled:cursor-not-allowed rounded-full hover:opacity-80`,`h-6 w-6`);Z.useEffect(()=>()=>{yo.current&&=(clearTimeout(yo.current),null)},[]);let du=Gr?(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)(Jb,{onOpenAgentPanel:Js,onCycleAgent:()=>{Ke(),dc()},agentName:Ln.selection.value.agent,agents:Br,disabled:Ur}),(0,$.jsx)(Yb,{onOpenModel:()=>_s(`model`),providerID:Ln.selection.value.providerID,modelID:Ln.selection.value.modelID,provider:Vr.find(e=>e.id===Ln.selection.value.providerID),variant:Ln.selection.value.variant})]}):null,fu=(0,$.jsxs)(`div`,{className:`oc-mobile-composer-attachment-content relative z-10 flex flex-wrap items-center gap-1 px-3 pt-1`,children:[(0,$.jsx)(bd,{attachments:Bn,onShowPopup:qr,onRemoveAttachedFile:xc}),Ln.kind===`primary`?(0,$.jsx)(wd,{attachedFiles:Bn,onAddVSCodeFile:(e,t,n)=>{Xn&&Wn(Xn,()=>Yt.getState()).addVSCodeFile(e,t,n)},onAddVSCodeSelection:(e,t)=>{if(Xn)return Wn(Xn,()=>Yt.getState()).addVSCodeSelection(e,t)}}):null]}),pu=ho?.map((e,t)=>(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(Dv,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)),mu=Gr?(0,$.jsxs)(`div`,{className:Y(`oc-mobile-composer-compact-chrome`,Es&&`oc-mobile-composer-compact-chrome--aborting`,Cs&&!Es&&`oc-mobile-composer-compact-chrome--sending`,a&&o&&`oc-mobile-composer-compact-chrome--with-scroll`),children:[(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`attach`,"data-composer-action":`true`,className:`composer-mobile-actions flex shrink-0 items-center`,children:(0,$.jsx)(Qb,{isVSCode:cl,footerIconButtonClass:cu,iconSizeClass:au,handlePickLocalFiles:rl,handlePickLocalImages:il,openIssuePicker:Ys,openPrPicker:Xs,onOpenMobileSheet:Rl,onOpenAndroidPickSheet:dl()?zl:void 0})}),(0,$.jsxs)(`div`,{"data-mobile-composer-compact-slot":`trailing`,className:`ml-auto flex shrink-0 items-center justify-end gap-x-1`,children:[a&&o?(0,$.jsx)(`div`,{"data-composer-action":`true`,className:`flex shrink-0 items-center`,children:(0,$.jsx)(vg,{placement:`compact`,visible:a,onClick:o})}):null,Es||Cs?(0,$.jsx)(`div`,{"data-mobile-composer-compact-slot":`action`,"data-composer-action":`true`,className:`flex shrink-0 items-center justify-end`,children:(0,$.jsx)(ex,{isMobile:!0,compact:!0,footerIconButtonClass:cu,stopFooterIconButtonClass:lu,compactCircleButtonClass:uu,sendIconSizeClass:ru,stopIconSizeClass:iu,canSend:Cs,canAbort:Es,hasContent:!1,currentSessionId:Hn,newSessionDraftOpen:Gn,draftSubmitting:Un,submissionBlocked:l,sendPhase:Ps,queueFrozen:Ss,queueFallbackAvailable:Es||Ts,onPrimaryAction:Qs,onAbort:uc})}):null]})]}):null,hu=Gr?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`div`,{className:`oc-mobile-composer-full-chrome flex w-full min-w-0 items-center gap-x-1.5`,"data-composer-action":`true`,children:[(0,$.jsxs)(`div`,{className:`composer-mobile-actions flex shrink-0 items-center gap-x-2 pl-1`,children:[(0,$.jsx)(Qb,{isVSCode:cl,footerIconButtonClass:cu,iconSizeClass:au,handlePickLocalFiles:rl,handlePickLocalImages:il,openIssuePicker:Ys,openPrPicker:Xs,onOpenSettings:e,onOpenMobileSheet:Rl,onOpenAndroidPickSheet:dl()?zl:void 0}),Sr?(0,$.jsx)($b,{sessionId:Hn,draftOpen:Gn,draftEnabled:Lt.permissionAutoAcceptEnabled===!0,enabled:_r,saving:Hn?Jt:!1,footerIconButtonClass:cu,iconSizeClass:au,onSetDraftEnabled:Kt,onSetSessionEnabled:Zt,onOpenSessionFirst:Ut,onToggleFailed:Cr}):null,(0,$.jsx)($v,{sessionId:Hn,directory:yt??Yn,draftOpen:Gn}),(0,$.jsx)(ey,{length:ci.length})]}),du,(0,$.jsx)(`div`,{className:`relative z-30 flex shrink-0 items-center justify-end gap-x-1.5`,children:(0,$.jsx)(ex,{isMobile:Gr,footerIconButtonClass:cu,stopFooterIconButtonClass:lu,sendIconSizeClass:ru,stopIconSizeClass:iu,canSend:Cs,canAbort:Es,hasContent:!!bs,currentSessionId:Hn,newSessionDraftOpen:Gn,draftSubmitting:Un,submissionBlocked:l,sendPhase:Ps,queueFrozen:Ss,queueFallbackAvailable:Es||Ts,onPrimaryAction:Qs,onAbort:uc})})]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center`,sl),children:[(0,$.jsx)(Qb,{isVSCode:cl,footerIconButtonClass:cu,iconSizeClass:au,handlePickLocalFiles:rl,handlePickLocalImages:il,openIssuePicker:Ys,openPrPicker:Xs,onOpenSettings:e,withTooltip:!0}),Sr?(0,$.jsx)($b,{sessionId:Hn,draftOpen:Gn,draftEnabled:Lt.permissionAutoAcceptEnabled===!0,enabled:_r,saving:Hn?Jt:!1,footerIconButtonClass:cu,iconSizeClass:au,onSetDraftEnabled:Kt,onSetSessionEnabled:Zt,onOpenSessionFirst:Ut,onToggleFailed:Cr}):null,(0,$.jsx)($v,{sessionId:Hn,directory:yt??Yn,draftOpen:Gn}),(0,$.jsx)(ey,{length:ci.length})]}),(0,$.jsxs)(`div`,{className:Y(`relative z-30 flex flex-1 items-center justify-end md:gap-x-1.5`,sl),children:[(0,$.jsx)(Kb,{className:`min-w-0 flex-1 justify-end`,composerTextareaRef:Mi,selectionAdapter:jr}),(0,$.jsx)(qb,{radius:Wa,isMobile:Gr,footerIconButtonClass:cu,footerPaddingClass:tu,iconSizeClass:au,sendIconSizeClass:ru,onInsert:ec,onInsertAndSend:tc,onContentHeightChange:hc,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}),(0,$.jsx)(ex,{isMobile:Gr,footerIconButtonClass:cu,stopFooterIconButtonClass:lu,sendIconSizeClass:ru,stopIconSizeClass:iu,canSend:Cs,canAbort:Es,hasContent:!!bs,currentSessionId:Hn,newSessionDraftOpen:Gn,draftSubmitting:Un,submissionBlocked:l,sendPhase:Ps,queueFrozen:Ss,queueFallbackAvailable:Es||Ts,onPrimaryAction:Qs,onAbort:uc})]})]}),gu=J(()=>{if(Gr){Ql.current=Date.now()+600;let e=()=>{Mi.current?.focus({preventScroll:Re()}),document.activeElement===Mi.current&&ve(!0)};e(),window.requestAnimationFrame(e);return}let e=()=>{if(!Am(Mi))return;let e=km(Mi);if(!e)return;let t=e.value.length;try{e.setSelectionRange(t,t)}catch{}};e(),window.requestAnimationFrame(()=>{e(),window.setTimeout(e,0)})}),_u=yt??Yn,{goal:vu,enabled:yu}=qv(Hn??``,_u),bu=(0,$.jsx)(Sp,{onEditMessage:Ks,onSendMessage:qs,onEditCommitted:gu,draftKey:Xn,scope:Ao,draftTarget:Xn?{key:Xn,expectedRevision:()=>zn.getDraft(Xn)?.revision??`absent`}:null,clientPendingItems:Vs,onRemoveClientPending:e=>{let t=gn.getState().removeEstablishingFollowUp(e);t&&(t.content&&ui(t.content),t.attachments.length>0&&zn.restoreAttachments(t.attachments))},trailing:Hn&&yu&&vu?(0,$.jsx)(Qv,{sessionId:Hn,directory:_u}):null});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`form`,{ref:eu,onSubmit:e=>{e.preventDefault(),Qs()},onPointerDownCapture:e=>{if(!Gr)return;let t=e.target;t instanceof Element&&(t.closest(`textarea[data-chat-input="true"]`)||t.closest(`[data-chat-prompt-attachments="true"]`)||t.closest(`button, [role="button"], a, label, input, select, [data-composer-action="true"], [data-chat-input-footer="true"]`)&&(Ke(),e.preventDefault()))},className:Y(`relative w-full pt-0 pb-4`,Ba&&`flex h-full min-h-0 flex-col pt-4`,Ha&&`flex h-full min-h-0 flex-col pt-1`,Gr&&`bottom-safe-area oc-mobile-composer`),"data-native-ios-composer":ql?`true`:void 0,style:Gr&&Re()&&!ql&&Zr>0&&!_e?{marginBottom:`${Zr}px`}:void 0,children:[qn&&!Ba&&!Gr&&!cl&&!jl?(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:Gb(ml?f(`chat.emptyState.draftTitleWithProject`,{project:ml}):f(`chat.emptyState.draftTitle`),ml)})}):null,(0,$.jsxs)(`div`,{className:Y(`chat-input-column relative overflow-visible`,Ua&&`flex flex-1 min-h-0 flex-col`),children:[ql?null:(0,$.jsx)(xd,{attachments:Bn,onShowPopup:qr,onRemoveAttachedFile:xc}),(0,$.jsx)(Bp,{}),es&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pb-2`,children:[ss>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ga?.colors?.surface?.elevated,borderColor:ga?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`chat.chatInput.reviewComments`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ga?.colors?.status?.info},children:ss}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:fs,"aria-label":f(`chat.chatInput.reviewCommentsRemove`),title:f(`chat.chatInput.reviewCommentsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,ns>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ga?.colors?.surface?.elevated,borderColor:ga?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`chat.chatInput.devServerLogs`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ga?.colors?.status?.info},children:ns}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:()=>cs(`preview-console`),"aria-label":f(`chat.chatInput.devServerLogsRemove`),title:f(`chat.chatInput.devServerLogsRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null,as>0?(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 rounded-xl border px-2.5 py-1`,style:{backgroundColor:ga?.colors?.surface?.elevated,borderColor:ga?.colors?.interactive?.border},children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:f(`chat.chatInput.previewAnnotations`)}),(0,$.jsx)(`span`,{className:`text-xs font-semibold`,style:{color:ga?.colors?.status?.info},children:as}),(0,$.jsx)(`button`,{type:`button`,className:`ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-interactive-hover hover:text-foreground`,style:{minHeight:0,minWidth:0},onClick:()=>cs(`preview-annotation`),"aria-label":f(`chat.chatInput.previewContextRemove`),title:f(`chat.chatInput.previewContextRemove`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`})})]}):null]}),wo&&!cl&&(0,$.jsx)(`div`,{className:`pb-2 w-full px-1`,children:(0,$.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 text-sm h-5 px-1`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>xo(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[wo.author?.avatarUrl&&(0,$.jsx)(`img`,{src:wo.author.avatarUrl,alt:wo.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`#`,wo.number,wo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:f(`chat.chatInput.linked.byAuthor`,{author:wo.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:wo.title})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:wo.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.issue.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{To(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.issue.removeAria`),title:f(`chat.chatInput.linked.issue.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),Eo&&!cl&&(0,$.jsx)(`div`,{className:`pb-2 w-full px-1`,children:(0,$.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 text-sm h-5 px-1`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>Co(!0),className:`flex min-w-0 flex-1 items-center gap-1.5 text-left hover:opacity-80 transition-opacity`,children:[Eo.author?.avatarUrl&&(0,$.jsx)(`img`,{src:Eo.author.avatarUrl,alt:Eo.author.login,className:`h-5 w-5 rounded-full flex-shrink-0`}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[f(`chat.chatInput.linked.pr.number`,{number:Eo.number}),Eo.author&&(0,$.jsx)(`span`,{className:`ml-1`,children:f(`chat.chatInput.linked.byAuthor`,{author:Eo.author.login})})]}),(0,$.jsx)(`span`,{className:`text-foreground truncate`,children:Eo.title}),(0,$.jsxs)(`span`,{className:`text-muted-foreground flex-shrink-0 typography-meta`,children:[Eo.head,` → `,Eo.base]})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:Eo.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.pr.openInBrowserAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4 text-muted-foreground`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{Oo(null)},className:`flex items-center justify-center h-6 w-6 hover:bg-[var(--interactive-hover)] rounded-full transition-colors`,"aria-label":f(`chat.chatInput.linked.pr.removeAria`),title:f(`chat.chatInput.linked.pr.removeAria`),children:(0,$.jsx)(X,{name:`close`,className:`h-4 w-4 text-muted-foreground`})})]})]})}),(0,$.jsx)(Zb,{sessionId:Hn,directory:yt??Yn}),(0,$.jsxs)(`div`,{className:Gr?`relative oc-mobile-composer-stack`:`contents`,children:[(0,$.jsxs)(`div`,{className:Gr?`oc-mobile-composer-expanded-layer`:`contents`,children:[(0,$.jsx)(`div`,{className:Gr?`oc-mobile-composer-reveal`:`contents`,children:(0,$.jsxs)(`div`,{ref:Jl,"data-native-composer-accessories":`true`,children:[(0,$.jsx)(Xb,{showAbortStatus:ka,showAssistantStatus:!1,showTodos:!0,leftAccessory:Gn||!Ml?null:(0,$.jsx)(gg,{})}),!Gr&&ll?(0,$.jsxs)(`div`,{className:`mb-1.5 flex min-w-0 items-center gap-1.5 px-0.5`,children:[ul?(0,$.jsxs)(Ca,{value:ul.id,open:Ve,onValueChange:Fl,onOpenChange:e=>{He(e),e||ze(``)},children:[(0,$.jsx)(Pa,{asChild:!0,size:`sm`,children:(0,$.jsxs)(`button`,{type:`button`,className:Y(`group relative inline-flex h-6 min-w-0 w-fit max-w-[42vw] items-center rounded-lg !border-0 px-1.5 py-1 pr-1.5 typography-micro font-medium text-foreground/80 transition-[padding] hover:pr-5 focus-visible:pr-5 data-[popup-open]:pr-5 sm:max-w-[18rem]`,dm),children:[(0,$.jsx)(_a,{children:Ll(ul)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`pointer-events-none absolute right-1 size-3.5 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100 group-data-[popup-open]:opacity-100`,"aria-hidden":`true`})]})}),(0,$.jsxs)(Sa,{fitContent:!0,children:[(0,$.jsx)(Fa,{autoFocus:!0,value:Le,onChange:e=>ze(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:f(`chat.chatInput.draftPicker.searchProjects`),className:`mb-1 h-8 min-w-56`}),ar.filter(e=>Na(Wb(e),Le)||Na(e.path,Le)).map(e=>(0,$.jsx)(Ma,{value:e.id,className:`max-w-[24rem] truncate`,children:Ll(e)},e.id)),(0,$.jsx)(ba,{}),(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left typography-ui-label text-foreground hover:bg-interactive-hover`,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.preventDefault(),e.stopPropagation(),He(!1),requestAnimationFrame(()=>mi.requestDirectoryDialog())},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]})]})]}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-auto min-h-6 cursor-pointer items-center gap-1.5 rounded-lg px-2.5 py-1 typography-micro font-medium text-foreground/80`,dm),onClick:()=>mi.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]}),ul&&Pl?(0,$.jsx)(sv,{directory:Dl,projectDirectory:pl,label:Al,projectRootOption:Tl,worktreeOptions:El,onSelectDirectory:Il}):null]}):null,Gr&&ll?(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:[ul?(0,$.jsx)(`button`,{type:`button`,className:Y(`inline-flex h-[1.625rem] min-w-0 max-w-[46%] shrink items-center gap-1.5 rounded-lg px-1.5 text-[11px] leading-none font-medium text-foreground/80`,dm),onClick:()=>Me(`project`),children:Ll(ul)}):(0,$.jsxs)(`button`,{type:`button`,className:Y(`inline-flex h-[1.625rem] min-w-0 max-w-[46%] items-center gap-1.5 rounded-lg px-1.5 text-[11px] leading-none font-medium text-foreground/80`,dm),onClick:()=>mi.requestDirectoryDialog(),children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]}),ul&&Pl?(0,$.jsx)(sv,{directory:Dl,projectDirectory:pl,label:Al,projectRootOption:Tl,worktreeOptions:El,onSelectDirectory:Il,maxWidthClassName:`max-w-[50%]`,presentation:`mobile-sheet`}):null]}):null,bu]})}),(0,$.jsx)(`div`,{className:Y(!Gr&&`contents`,Gr&&`contents`,Ha&&`flex min-h-0 flex-1 flex-col`),children:(0,$.jsxs)(`div`,{className:Gr?`oc-mobile-composer-motion-viewport`:`contents`,children:[(0,$.jsxs)(z_,{value:ci,attachments:[],disabled:!Hn&&!Gn||Un&&!Ps.establishing,pending:Es||Ps.inFlight&&!Ps.establishing,isMobile:Gr,onSubmit:Qs,"data-mobile-composer-surface":Gr?`true`:void 0,"data-session-swipe-surface":Gr?`true`:void 0,expanded:Ua,focusedTone:h===`shell`?`info`:`primary`,className:Y(`relative z-10`,y&&`ring-2 ring-primary ring-offset-2`,Xr&&`ring-1 ring-[var(--interactive-selection)] border-[var(--interactive-selection)]`,Gr&&`oc-mobile-composer-surface`),style:{borderRadius:Wa},ref:Vi,onDropCapture:Qc,onDragEnter:qc,onDragOver:Jc,onDragLeave:Yc,onDrop:Zc,onDragEnd:Xc,autoResize:!1,disableInputWhilePending:!1,contentClassName:Ua?`flex-1 min-h-0`:void 0,inputHeader:void 0,attachmentContent:fu,highlightedContent:pu,highlightRef:ja,inputRef:Mi,textLayoutClassName:Y(Cb,Ua?Y(`h-full min-h-0`,Gr?`py-2.5`:`py-4`):Gr?`py-2.5`:`pt-4 pb-2`,h===`shell`?`font-mono`:`typography-markdown md:typography-ui-label`),inputOuterClassName:Y(Ua&&`flex-1 min-h-0`),inputStyle:{flex:Ua?`1 1 auto`:`none`,height:!Ua&&de?`${de.height}px`:void 0,maxHeight:!Ua&&de?`${de.maxHeight}px`:void 0,"--oc-composer-textarea-resting-height":Ua?`100%`:de?`${de.height}px`:`auto`,"--oc-composer-textarea-resting-max-height":!Ua&&de?`${de.maxHeight}px`:`none`,borderTopLeftRadius:Wa,borderTopRightRadius:Wa},footerClassName:Y(`z-30 bg-transparent flex-shrink-0`,tu,Gr?`flex items-center gap-x-1.5`:Y(`flex items-center justify-between`,sl)),footerStyle:{borderBottomLeftRadius:Wa,borderBottomRightRadius:Wa},footerContent:hu,placeholder:Ga,onChange:(e,t)=>Dc(t),textareaProps:{readOnly:Xr,onCompositionStart:()=>{Ii.current=!0},onCompositionEnd:e=>{Ii.current=!1;let t=e.currentTarget;vc(t.value,t.selectionStart??t.value.length,t.selectionEnd??t.selectionStart??t.value.length)},onBeforeInput:Ec,onKeyDown:ac,onCopy:jc,onCut:Mc,onPaste:kc,onDragEnter:qc,onDragOver:Jc,onDropCapture:Qc,onDrop:Zc,onDragEnd:Xc,onKeyUp:sc,onClick:()=>{sc()},onScroll:e=>{sc();let t=e.currentTarget.scrollTop;ja.current&&(ja.current.style.transform=`translateY(-${t}px)`)},onSelect:e=>{let t=e.currentTarget,n=t.selectionStart??0,r=t.selectionEnd??n;if(Ii.current){Li.current=r;return}let i=wv(n,r,[...De(ci,Bn.filter(Fe).map(e=>e.filename)),...Cv(ci,ao.keys()),...si.references]);i&&(i.start!==n||i.end!==r)?(t.setSelectionRange(i.start,i.end),Li.current=i.end):Li.current=n,sc()},onFocus:()=>{if(Gr){if(Date.now()<Ge.current){let e=Mi.current;e&&e.blur();return}ye.current!==null&&(window.clearTimeout(ye.current),ye.current=null),ve(!0)}},onBlur:e=>{if(Ii.current=!1,Li.current=e.currentTarget.selectionStart??Li.current,$l(),Gr){if(Date.now()<Ql.current){let e=Mi.current;if(e){e.focus(),window.setTimeout(()=>{Date.now()<Ql.current&&document.activeElement!==e&&e.focus()},50);return}}if(qe.current=Date.now(),Re()){ve(!1);return}ye.current!==null&&window.clearTimeout(ye.current),ye.current=window.setTimeout(()=>{ye.current=null,ve(!1)},120)}},autoCorrect:Gr?`on`:`off`,autoCapitalize:Gr?`sentences`:`off`,spellCheck:Gr||$r,fillContainer:Ua,rows:1},children:[(0,$.jsx)(uh,{}),y&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/90`,style:{borderRadius:Wa},children:(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`inline-flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,className:su,onClick:()=>rl(),title:f(`chat.chatInput.actions.attachFiles`),"aria-label":f(`chat.chatInput.actions.attachFiles`),children:(0,$.jsx)(X,{name:`attachment-2`,className:Y(au,`text-current`)})})}),(0,$.jsx)(`p`,{className:`mt-2 typography-ui-label text-muted-foreground`,children:f(T?`chat.chatInput.drop.insertMention`:`chat.chatInput.drop.attachFiles`)})]})}),M&&(0,$.jsx)(Po,{ref:Qi,searchQuery:P,directory:Yn,onCommandSelect:Vc,onClose:()=>N(!1),commandPolicy:Wl,commandContext:Qn,onRowsChange:ql?Ul:void 0,style:Ba&&_o?{left:`${_o.left}px`,top:`${_o.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${_o.left+8}px))`,maxHeight:`${_o.maxHeight}px`,transform:_o.place===`above`?`translateY(-100%)`:void 0}:void 0}),R&&(0,$.jsx)(Gp,{ref:$i,searchQuery:V,directory:Yn,onSkillSelect:zc,onClose:()=>z(!1),onRowsChange:ql?Ul:void 0,style:Ba&&_o?{left:`${_o.left}px`,top:`${_o.top}px`,bottom:`auto`,width:`min(360px, calc(100% - ${_o.left+8}px))`,maxHeight:`${_o.maxHeight}px`,transform:_o.place===`above`?`translateY(-100%)`:void 0}:void 0}),q&&(0,$.jsx)(Wo,{ref:ea,searchQuery:ie,onSnippetSelect:Bc,onClose:()=>te(!1),style:Ba&&_o?{left:`${_o.left}px`,top:`${_o.top}px`,bottom:`auto`,width:`min(450px, calc(100% - ${_o.left+8}px))`,maxHeight:`${_o.maxHeight}px`,transform:_o.place===`above`?`translateY(-100%)`:void 0}:void 0}),D&&(0,$.jsx)(Qo,{ref:Xi,searchQuery:k,onFileSelect:Fc,onAgentSelect:Ic,onSessionSelect:Lc,onClose:()=>O(!1),onRowsChange:ql?Ul:void 0,style:Ba&&_o?{left:`${_o.left}px`,top:`${_o.top}px`,bottom:`auto`,width:`min(520px, calc(100% - ${_o.left+8}px))`,maxHeight:`${_o.maxHeight}px`,transform:_o.place===`above`?`translateY(-100%)`:void 0}:void 0})]}),Gr?(0,$.jsx)(qb,{radius:Wa,isMobile:Gr,footerIconButtonClass:cu,footerPaddingClass:tu,iconSizeClass:au,sendIconSizeClass:ru,onInsert:ec,onInsertAndSend:tc,onContentHeightChange:hc,renderTrigger:!1,topAccessory:(0,$.jsx)(`span`,{"data-oc-composer-dictation-active":`true`,className:`hidden`,"aria-hidden":`true`})}):null]})})]}),Gr?(0,$.jsxs)(`div`,{className:`oc-mobile-composer-compact-layer`,"data-oc-composer-compact-surface":`true`,children:[mu,(0,$.jsx)(`div`,{className:Y(`oc-mobile-composer-compact-preview`,!ci.trim()&&`oc-mobile-composer-compact-preview--placeholder`),"aria-hidden":`true`,children:ci.trim()?ci:Ka})]}):null]}),Gr?(0,$.jsx)(Kb,{className:`hidden`,composerTextareaRef:Mi,selectionAdapter:jr,mobilePanel:pe,onMobilePanelChange:me}):null]}),Gn&&!Ba&&!Gr&&!cl&&!jl?(0,$.jsx)(M_,{onSubmit:$s,className:`chat-input-column mt-4`}):null]}),p.open?(0,$.jsx)(Z.Suspense,{fallback:null,children:(0,$.jsx)(wb,{popup:p,onOpenChange:Jr,isMobile:Gr})}):null,(0,$.jsx)(l_,{open:bo,onOpenChange:xo,mode:`select`,onSelect:e=>{To(e),Oo(null)}}),(0,$.jsx)(f_,{open:So,onOpenChange:Co,onSelect:e=>{Oo(e),To(null)}}),(0,$.jsx)(qu,{open:ur,onOpenChange:fr,projectDirectory:yt??Yn??null,submitting:pr,onConfirm:Ra}),(0,$.jsx)(`input`,{ref:Q,type:`file`,multiple:!0,className:`hidden`,onChange:ol,accept:`*/*`}),(0,$.jsx)(`input`,{ref:$c,type:`file`,multiple:!0,className:`hidden`,onChange:ol,accept:`image/*`}),null,Gr?(0,$.jsx)(Qa,{id:`android-media-pick-sheet`,open:Se,onOpenChange:e=>{e||Ee(!1)},title:(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:f(`chat.chatInput.actions.addAttachment`)}),ariaLabel:f(`chat.chatInput.actions.addAttachment`),closeAriaLabel:f(`mobile.surface.closeAria`),resizeAriaLabel:f(`mobile.sessions.sheet.resizeAria`),fitContent:!0,children:(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsxs)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:[(0,$.jsxs)(ca,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,onClick:()=>{Je.current=!1,Ee(!1),requestAnimationFrame(al)},children:[(0,$.jsx)(X,{name:`file-image`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:f(`chat.chatInput.actions.attachPhotos`)})]}),(0,$.jsxs)(ca,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,onClick:()=>{Je.current=!1,Ee(!1),requestAnimationFrame(rl)},children:[(0,$.jsx)(X,{name:`attachment-2`,className:`size-5 flex-shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:f(`chat.chatInput.actions.attachFiles`)})]})]})})}):null,Gr&&ll&&ul?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(Qa,{id:`mobile-draft-project-picker-sheet-${Ne}`,open:Ae===`project`,onOpenChange:e=>{e||Me(null)},ariaLabel:f(`chat.chatInput.draftPicker.projectTitle`),closeAriaLabel:f(`mobile.surface.closeAria`),resizeAriaLabel:f(`mobile.sessions.sheet.resizeAria`),children:[(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-2 pt-1`,"data-mobile-sheet-no-dismiss":``,children:(0,$.jsx)(Fa,{value:Pe,onChange:e=>Ie(e.target.value),placeholder:f(`chat.chatInput.draftPicker.searchProjects`),className:`h-9`})}),(0,$.jsx)(da,{outerClassName:`min-h-0 flex-1`,disableHorizontal:!0,children:(0,$.jsx)(`div`,{className:`flex flex-col px-3 pb-2`,children:ar.filter(e=>Na(Wb(e),Pe)||Na(e.path,Pe)).map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-2.5 text-left typography-ui-label hover:bg-[var(--interactive-hover)]`,onClick:()=>{Fl(e.id),Me(null)},children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:Ll(e)}),e.id===ul.id?(0,$.jsx)(X,{name:`check`,className:`h-4 w-4 flex-shrink-0 text-muted-foreground`}):null]},e.id))})}),(0,$.jsx)(`div`,{className:`shrink-0 px-3 pb-4 pt-1`,children:(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full cursor-pointer items-center gap-2 rounded-lg border-t border-border/50 px-2 py-2.5 text-left typography-ui-label hover:bg-[var(--interactive-hover)]`,onClick:()=>{Me(null),mi.requestDirectoryDialog()},children:[(0,$.jsx)(X,{name:`folder-add`,className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{children:f(`chat.chatInput.draftPicker.newProject`)})]})})]})}):null]})},ox=e=>{let t=(0,Q.c)(3),n=Lm(),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)(ax,{...e,surface:i}),t[0]=e,t[1]=i,t[2]=a):a=t[2],a};ox.displayName=`ChatInput`;var sx=Z.memo(ox);function cx(e){return e.preventDefault()}function lx(e){e.preventDefault()}function ux(e){return e.preventDefault()}function dx(e){e.pointerType===`touch`&&e.preventDefault()}function fx(e){e.preventDefault()}function px(e){e.pointerType===`touch`&&e.preventDefault()}function mx(){let e=(0,Q.c)(47),{t}=ot(),[n,r]=Z.useState(null),[i,a]=Z.useState(!1),o=Z.useRef(null),s=!!n,c,l;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>mo(e=>{r(e),a(!1)}),l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),Z.useEffect(c,l);let u;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=e=>{e||(r(null),a(!1))},e[2]=u):u=e[2];let d=J(u),f;e[3]===d?f=e[4]:(f=()=>(d(!1),!0),e[3]=d,e[4]=f);let p;e[5]!==s||e[6]!==f?(p={id:`image-save-actions`,active:s,layer:`overlay`,onBack:f,surfaceRef:o},e[5]=s,e[6]=f,e[7]=p):p=e[7],Cs(p);let m;e[8]!==i||e[9]!==t||e[10]!==n?(m=async()=>{if(!(!n||i)){a(!0);try{await Bc(n),In.success(t(`chat.image.actions.saveSuccess`)),r(null)}catch(e){let n=e;if(n instanceof DOMException&&n.name===`AbortError`){a(!1);return}In.error(t(`chat.image.actions.saveFailed`)),a(!1);return}a(!1)}},e[8]=i,e[9]=t,e[10]=n,e[11]=m):m=e[11];let h=J(m);if(!n)return null;let g;e[12]!==t||e[13]!==n.filename?(g=n.filename?.trim()||t(`chat.image.actions.sheetTitle`),e[12]=t,e[13]=n.filename,e[14]=g):g=e[14];let _=g,v;e[15]===t?v=e[16]:(v=Re()?t(`chat.image.actions.saveToPhotos`):t(`chat.image.actions.saveImage`),e[15]=t,e[16]=v);let y=v,b;e[17]===_?b=e[18]:(b=(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold`,children:_}),e[17]=_,e[18]=b);let x;e[19]===t?x=e[20]:(x=t(`mobile.surface.closeAria`),e[19]=t,e[20]=x);let S;e[21]===t?S=e[22]:(S=t(`mobile.sessions.sheet.resizeAria`),e[21]=t,e[22]=S);let C;e[23]===h?C=e[24]:(C=()=>{h()},e[23]=h,e[24]=C);let w=i?`loader-4`:`download`,T=i?`size-5 animate-spin`:`size-5`,E;e[25]!==w||e[26]!==T?(E=(0,$.jsx)(X,{name:w,className:T}),e[25]=w,e[26]=T,e[27]=E):E=e[27];let D;e[28]!==y||e[29]!==i||e[30]!==t?(D=i?t(`chat.image.actions.saving`):y,e[28]=y,e[29]=i,e[30]=t,e[31]=D):D=e[31];let O;e[32]===D?O=e[33]:(O=(0,$.jsx)(`span`,{className:`truncate`,children:D}),e[32]=D,e[33]=O);let k;e[34]!==i||e[35]!==C||e[36]!==E||e[37]!==O?(k=(0,$.jsx)(`div`,{className:`flex min-h-0 flex-col overflow-y-auto overscroll-contain px-3 pb-3`,children:(0,$.jsx)(`div`,{className:`overflow-hidden rounded-2xl bg-[var(--surface-muted)]`,"data-page-scroll-lock":`true`,children:(0,$.jsxs)(ca,{type:`button`,variant:`ghost`,size:`lg`,className:`h-auto min-h-12 w-full justify-start gap-3 rounded-none supports-[corner-shape:squircle]:rounded-none px-4 border-b border-[var(--surface-subtle)] last:border-b-0`,"data-mobile-press-feedback":`none`,disabled:i,onClick:C,children:[E,O]})})}),e[34]=i,e[35]=C,e[36]=E,e[37]=O,e[38]=k):k=e[38];let A;return e[39]!==d||e[40]!==s||e[41]!==S||e[42]!==k||e[43]!==b||e[44]!==x||e[45]!==_?(A=(0,$.jsx)(`div`,{ref:o,children:(0,$.jsx)(Qa,{id:`image-save-actions-sheet`,open:s,onOpenChange:d,title:b,ariaLabel:_,closeAriaLabel:x,resizeAriaLabel:S,fitContent:!0,children:k})}),e[39]=d,e[40]=s,e[41]=S,e[42]=k,e[43]=b,e[44]=x,e[45]=_,e[46]=A):A=e[46],A}var hx=(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(Mt(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]},gx=(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},_x=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}},vx=e=>e.syncLoading||e.assistantLoading,yx=e=>e.isMobile&&(e.canLoadEarlier||e.isLoadingOlder),bx=e=>e.isLoadingOlder,xx=e=>!e.isMobile&&e.isLoadingOlder,Sx=e=>e.transcriptMessageCount>0||e.pendingUserCount>0||e.historyPrefixCount>0,Cx=e=>e.hasTranscriptShell||e.hasBusyShell||e.hasImmediateShell||e.hasPaintedTranscript?`pass`:e.prefetchStatus===`loading`||e.syncLoading||e.userRetrying?`hydrating`:e.prefetchStatus===`error`?`load-error`:e.hasRenderableSessionSnapshot?`pass`:`hydrating`,wx=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}},Tx=e=>({newSessionDraft:e?.features?.newSessionDraft??!e,promptNavigator:e?.features?.promptNavigator??!e,returnToParent:e?.features?.returnToParent??!e}),Ex=`text-[13px] leading-4 sm:text-[length:var(--text-micro)] sm:leading-5`,Dx=`relative bottom-safe-area oc-mobile-readonly-prompt-foot`,Ox=e=>{let t=(0,Q.c)(8),{providerId:n,modelId:r,label:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(X,{name:`brain-ai-3`,className:`size-3.5`}),t[0]=a):a=t[0];let o;t[1]===i?o=t[2]:(o=(0,$.jsx)(`span`,{role:`img`,"aria-label":i,className:`inline-flex size-3.5 shrink-0 items-center justify-center`,children:a}),t[1]=i,t[2]=o);let s;return t[3]!==i||t[4]!==r||t[5]!==n||t[6]!==o?(s=(0,$.jsx)(Ea,{modelId:r,providerId:n,alt:i,className:`size-3.5 shrink-0`,fallback:o}),t[3]=i,t[4]=r,t[5]=n,t[6]=o,t[7]=s):s=t[7],s},kx=e=>{let t=(0,Q.c)(42),{t:n}=ot(),r=s(Ax),i=`agentName`in e||`providerId`in e||`modelId`in e||`modelName`in e;if(!i){let e=r&&Dx,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 ${Ex}`,children:a}),t[4]=a,t[5]=o);let s;return t[6]!==i||t[7]!==o?(s=(0,$.jsx)(`div`,{className:i,children:o}),t[6]=i,t[7]=o,t[8]=s):s=t[8],s}let a;t[9]===n?a=t[10]:(a=n(`common.unavailable`),t[9]=n,t[10]=a);let o=a,c;t[11]!==e.agentName||t[12]!==o?(c=e.agentName?e.agentName.charAt(0).toUpperCase()+e.agentName.slice(1):o,t[11]=e.agentName,t[12]=o,t[13]=c):c=t[13];let l=c,u=e.modelName||o,d;t[14]===n?d=t[15]:(d=n(`chat.leaderKey.action.agent`),t[14]=n,t[15]=d);let f=`${d}: ${l}`,p;t[16]===n?p=t[17]:(p=n(`chat.leaderKey.action.model`),t[16]=n,t[17]=p);let m=`${p}: ${u}`,h=r&&Dx,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 ${Ex}`,children:y}),t[24]=y,t[25]=b);let x;t[26]!==f||t[27]!==l||t[28]!==m||t[29]!==u||t[30]!==e.agentName||t[31]!==e.modelId||t[32]!==e.providerId||t[33]!==i?(x=i?(0,$.jsxs)(`div`,{"data-testid":`read-only-prompt-banner-meta`,className:`mt-1.5 flex min-w-0 items-center justify-between gap-3 border-t border-border/70 pt-1.5 text-[13px] leading-none sm:text-[length:var(--text-micro)]`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 overflow-hidden`,children:[(0,$.jsx)(sa,{name:e.agentName,size:14,label:f}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,title:l,children:l})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-[55%] items-center justify-end gap-1.5 overflow-hidden`,children:[(0,$.jsx)(Ox,{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 Ax(e){return e.isMobile}var jx=Z.memo(()=>{let e=(0,Q.c)(5),{t}=ot(),{currentTheme:n}=za(),r=Nt(Mx),i=n?.colors?.surface?.mutedForeground||`var(--muted-foreground)`,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(io,{width:140,height:140,className:`opacity-20`}),e[0]=a):a=e[0];let o;return e[1]!==r||e[2]!==t||e[3]!==i?(o=(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-full w-full gap-6`,children:[a,r?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 max-w-md text-center px-4`,children:[(0,$.jsx)(`span`,{className:`typography-markdown font-medium text-destructive`,children:t(`chat.emptyState.opencodeUnreachable`)}),(0,$.jsx)(`span`,{className:`typography-meta`,style:{color:i},children:r.message})]}):(0,$.jsx)(`span`,{className:`typography-markdown`,style:{color:i},children:t(`chat.emptyState.startNewChat`)})]}),e[1]=r,e[2]=t,e[3]=i,e[4]=o):o=e[4],o});function Mx(e){return e.error}var Nx=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)}}},Px=`oc:legend-timeline`,Fx=()=>{try{return typeof localStorage>`u`||localStorage.getItem(Px)!==`0`}catch{return!0}},Ix=ue(e=>({planModeEnabled:!1,setPlanModeEnabled:t=>e({planModeEnabled:t}),legendTimelineEnabled:Fx(),setLegendTimelineEnabled:t=>{try{typeof localStorage<`u`&&localStorage.setItem(Px,t?`1`:`0`)}catch{}e({legendTimelineEnabled:t})}})),Lx=e=>{if(!e?.trim())return null;let t=e.trim();return t.toLowerCase()==="default"?null:xi(t)},Rx=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?Lx(c):null,t[0]=r,t[1]=n,t[2]=c,t[3]=l):l=t[3];let u=l,d=s||`Assistant`,f,p;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=Y(`mb-1.5`),p=Y(`flex items-center justify-between gap-2`),t[4]=f,t[5]=p):(f=t[4],p=t[5]);let m;t[6]!==o||t[7]!==n||t[8]!==a||t[9]!==i?(m=(0,$.jsx)(`div`,{className:`flex-shrink-0`,children:n?(0,$.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-primary/10 flex items-center justify-center`,children:(0,$.jsx)(X,{name:`user-3`,className:`h-4 w-4 text-primary`})}):(0,$.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,$.jsx)(Ea,{modelId:a,providerId:i,className:`h-4 w-4`,fallback:(0,$.jsx)(X,{name:`brain-ai-3`,className:`h-4 w-4`,style:{color:`var(${ea(o).var})`}})})})}),t[6]=o,t[7]=n,t[8]=a,t[9]=i,t[10]=m):m=t[10];let h=n?`text-primary`:`text-foreground`,g;t[11]===h?g=t[12]:(g=Y(`inline-flex min-w-0 items-center gap-1.5 font-semibold typography-ui-header tracking-tight leading-tight`,h),t[11]=h,t[12]=g);let _=n?`You`:d,v;t[13]===_?v=t[14]:(v=(0,$.jsx)(`span`,{className:`truncate`,children:_}),t[13]=_,t[14]=v);let y;t[15]===u?y=t[16]:(y=u?(0,$.jsx)(`span`,{className:`shrink-0 text-xs font-normal leading-tight text-muted-foreground`,children:u}):null,t[15]=u,t[16]=y);let b;t[17]!==g||t[18]!==v||t[19]!==y?(b=(0,$.jsxs)(`h3`,{className:g,children:[v,y]}),t[17]=g,t[18]=v,t[19]=y,t[20]=b):b=t[20];let x;t[21]!==o||t[22]!==r||t[23]!==n?(x=!n&&o&&(0,$.jsxs)(`div`,{className:Y(`agent-badge inline-flex items-center gap-1 cursor-default rounded font-normal leading-tight`,r?`px-1 py-px text-[10px]`:`px-1.5 py-0.5 typography-micro`,ea(o).class),children:[(0,$.jsx)(sa,{name:o,size:10}),(0,$.jsx)(`span`,{children:o.charAt(0).toUpperCase()+o.slice(1)})]}),t[21]=o,t[22]=r,t[23]=n,t[24]=x):x=t[24];let S;t[25]!==b||t[26]!==x?(S=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[b,x]}),t[25]=b,t[26]=x,t[27]=S):S=t[27];let C;return t[28]!==S||t[29]!==m?(C=(0,$.jsx)(`div`,{className:f,children:(0,$.jsx)(`div`,{className:p,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[m,S]})})}),t[28]=S,t[29]=m,t[30]=C):C=t[30],C}),zx=/(^|\s)\/([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)/g,Bx=/(```[\s\S]*?```|~~~[\s\S]*?~~~)/g,Vx=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),Hx=(e,t)=>e.split(Bx).map((e,n)=>n%2==1?e:t(e)).join(``),Ux=e=>Hx(e,e=>e.replace(/ *\n/g,`
|
|
6537
6537
|
`)),Wx=({textContent:e,agentMention:t,skillNames:n,decorateInlineReferences:r=!0})=>{let i=Hx(e,Vx);if(r){if(t?.token&&i.includes(t.token)){let e=`[${t.token}](${_c(t.name)})`;i=i.replace(t.token,e)}i=i.replace(zx,(e,t,r)=>n.has(r)?`${t}[/${r}](${mc(r)})`:e)}return Ux(i)},Gx=e=>(zx.lastIndex=0,zx.test(e)||e.includes(`[skill:`)),Kx=e=>e===`markdown`?`markdown`:`plain`,qx=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)},Jx=Z.memo(({part:e,messageId:t,agentMention:n,messageParts:r})=>{let i=e,a=i.text,o=typeof a==`string`?a:i.content||i.value||``,[c,l]=Z.useState(!1),[u,d]=Z.useState(!1),f=s(e=>e.userMessageRenderingMode),p=s(e=>e.collapsibleUserMessages),m=cc(),h=Fi({directory:m,enabled:Gx(o)}),g=Z.useMemo(()=>h.data??[],[h.data]),_=s(e=>e.openContextFile),{t:v}=ot(),y=Kx(f),b=p&&!c,x=Z.useRef(null),S=Z.useMemo(()=>new Map(g.map(e=>[e.name,e])),[g]),C=Z.useMemo(()=>Ff(r,o),[r,o]),w=Z.useMemo(()=>{let e=new Map;for(let t of r??[]){if(t.type!==`text`||!en(t))continue;let n=t.text;if(typeof n==`string`)for(let t of ur(n))e.set(t.id,{sessionId:t.id,sessionLabel:t.title||t.id})}if(o.includes(`@`))for(let[t,n]of ri()){let r=typeof n.title==`string`?n.title.trim():``;!r||e.has(t)||(o.includes(`@${r}`)||o.includes(`@${ee}${r}`))&&e.set(t,{sessionId:t,sessionLabel:r})}return Array.from(e.values())},[r,o]),T=J(e=>{let t=S.get(e),n=typeof t?.path==`string`?t.path:``,r=yo(n);if(!r||r===`<built-in>`)return;let i=r.toLowerCase().endsWith(`/skill.md`)?r:`${r}/SKILL.md`,a=m||go(``,i)||`/`,o=()=>{_(a,i)};if(m&&!So(i,m)){lc(i,m).then(o);return}o()});Z.useEffect(()=>{let e=x.current;if(!e)return;let t=()=>{p&&!c&&d(e.scrollHeight>e.clientHeight)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[p,o,c]),Z.useEffect(()=>{p||(l(!1),d(!1))},[p]);let E=J(e=>{let t=e.target,n=(t?.closest(`[data-skill-name]`))?.dataset.skillName??dc(t?.closest(`a[href]`)?.getAttribute(`href`));if(n){e.preventDefault(),e.stopPropagation(),T(n);return}let r=x.current;r&&(qx(r)||p&&!c&&u&&l(!0))}),D=J(e=>{e.stopPropagation(),l(!1)}),O=Z.useMemo(()=>kf(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(()=>Wx({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=Wx({textContent:e,skillNames:new Set,decorateInlineReferences:!1});return(0,$.jsx)(Os,{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)(Lf,{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(zx.lastIndex=0;(i=zx.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:uc(n.name),className:`text-primary hover:underline`,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),children:n.token},`agent-${t}`),e.slice(i+n.token.length)])})},[n,T,O,j,S,o]);return!o||o.trim().length===0?null:(0,$.jsxs)(`div`,{className:`relative`,children:[p&&c&&(0,$.jsx)(`button`,{type:`button`,onClick:D,className:`absolute top-0 right-0 z-10 flex items-center justify-center rounded-sm bg-[var(--surface-elevated)] p-0.5 text-[var(--surface-mutedForeground)] hover:text-[var(--surface-foreground)] hover:bg-[var(--interactive-hover)] transition-colors`,"aria-label":v(`chat.message.userText.collapseAria`),children:(0,$.jsx)(X,{name:`arrow-up-s`,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`div`,{className:Y(`break-words font-sans typography-markdown-body`,c&&`pb-3`,y===`plain`&&`whitespace-pre-wrap`,b&&`line-clamp-10`,p&&u&&!c&&`cursor-pointer`),ref:x,onClick:E,children:y===`markdown`?O?j(O):(0,$.jsx)(Os,{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`)}),Yx=[{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)(Xc.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)(Xc.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)(Xc.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)(Xc.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 Xx(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=Yx.find(e=>e.variant===a)?.component,t[4]=a,t[5]=o);let s=o||Yx[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 Zx=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})},Qx=new Map,$x=e=>{let t=Qx.get(e);if(t)return t;let n={subscribers:new Set,timerId:null};return Qx.set(e,n),n},eS=(e,t)=>{let n=$x(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=Qx.get(e);n&&(n.subscribers.delete(t),!(n.subscribers.size>0)&&(n.timerId!==null&&typeof window<`u`&&window.clearInterval(n.timerId),Qx.delete(e)))}},tS=(e,t)=>{let n=(0,Q.c)(4),r=t===void 0?250:t,[i,a]=Z.useState(nS),o,s;return n[0]!==e||n[1]!==r?(o=()=>{if(e)return eS(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 nS(){return Date.now()}var rS=e=>e.match(/<task\s+id="([^"]+)"(?:\s+[^>]*)?>/i)?.[1],iS=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},aS=e=>{if(!e||typeof e!=`object`)return;let t=e;return iS(t.sessionId)??iS(t.sessionID)},oS=(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},sS=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},cS=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:iS(e.sessionId)??iS(e.sessionID),status:iS(e.status),summaryEntries:sS(e.summary??e.entries??e.tools??e.calls)}}catch{return{summaryEntries:[]}}},lS=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=cS(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 iS((n?.[1]??r?.[1])||rS(e))},uS=e=>{if(!(!e||typeof e!=`object`))return iS(e.status)},dS=/"status"\s*:\s*"running"/i,fS=/\bstatus\s*[:=]\s*["'`]?running\b/i,pS=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]&&dS.test(t[1])?!0:fS.test(e)},mS=/<subagent\s+([^>]*?)>([\s\S]*?)<\/subagent>/i,hS=(e,t)=>iS(e.match(RegExp(`${t}\\s*=\\s*"([^"]*)"`,`i`))?.[1]),gS=e=>{if(e===`completed`||e===`error`||e===`cancelled`)return e},_S=e=>{if(typeof e!=`string`||e.trim().length===0)return;let t=e.trim().match(mS);if(!t)return;let n=hS(t[1],`sessionID`)??hS(t[1],`sessionId`),r=gS(hS(t[1],`state`));if(!(!n||!r))return{sessionID:n,state:r,description:hS(t[1],`description`),body:t[2].trim()}},vS=new WeakMap,yS=e=>{let t=vS.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 vS.set(e,n),n},bS=e=>{let t=[];for(let n of e)t.push(...yS(n));return t},xS=e=>e.replace(/\n*<task_metadata>[\s\S]*?<\/task_metadata>\s*$/i,``).trimEnd(),SS=[`summary`,`changes`,`verification`],CS={summary:`Summary`,changes:`Changes`,verification:`Verification`},wS=/<(summary|changes|verification)(?:\s[^>]*)?>/i,TS=()=>RegExp(`<(${SS.join(`|`)})(?:\\s[^>]*)?>\\s*([\\s\\S]*?)\\s*<\\/\\1>`,`gi`),ES=e=>typeof e!=`string`||e.length===0?!1:wS.test(e),DS=e=>typeof e!=`string`||e.length===0||!e.includes(`<`)||!ES(e)?e:e.replace(TS(),(e,t,n)=>{let r=CS[t.toLowerCase()]??t,i=n.trim();return i.length>0?`## ${r}\n\n${i}`:`## ${r}`}).trimEnd(),OS=e=>DS(xS(e)),kS=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 AS(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 jS=(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},MS=e=>{if(!e)return null;let t=e.id;return typeof t==`string`&&t.length>0?t:null},NS=e=>{let t=e?.state?.status;return typeof t==`string`?t:null},PS=e=>e?.state,FS=e=>e?.metadata,IS=e=>{let t=e?.time;return{start:typeof t?.start==`number`?t.start:null,end:typeof t?.end==`number`?t.end:null}},LS=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,``):``},RS=(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||MS(r)!==MS(i))return!1;if(r.type===`tool`){if(PS(r)!==PS(i)||FS(r)!==FS(i)||NS(r)!==NS(i))return!1;let e=IS(r),t=IS(i);if(e.start!==t.start||e.end!==t.end||r.tool!==i.tool||r.output!==i.output)return!1;continue}let a=IS(r),o=IS(i);if(a.start!==o.start||a.end!==o.end)return!1;if(r.type===`text`||r.type===`reasoning`){if(LS(r)!==LS(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},zS=(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)&&jS(e.tokens,t.tokens),BS=(e,t)=>zS(e.info,t.info)&&RS(e.parts,t.parts),VS=(e,t)=>!e||!t?e===t:BS(e,t),HS=(e,t)=>!e||!t?e===t:e.additions===t.additions&&e.deletions===t.deletions&&e.files===t.files&&e.hasDiffs===t.hasDiffs,US=(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},WS=(e,t)=>e.id===t.id&&e.messageId===t.messageId&&e.kind===t.kind&&e.partIndex===t.partIndex&&e.endedAt===t.endedAt&&RS([e.part],[t.part]),GS=(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(!WS(a,o))return!1;r+=1,i+=1}},KS=(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(!WS(e.parts[n],t.parts[n]))return!1;return!0},qS=(e,t)=>!!e?.some(e=>e.anchorMessageId===t),JS=(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(!KS(a,o))return!1;r+=1,i+=1}},YS=(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||!GS(e.activityParts,t.activityParts,n)||!JS(e.activityGroupSegments,t.activityGroupSegments,n))return!1;let a=qS(e.activityGroupSegments,n)||qS(t.activityGroupSegments,n);return!((i||a)&&e.toggleGroup!==t.toggleGroup||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!HS(e.diffStats,t.diffStats)||(i||a||e.isLastAssistantInTurn||t.isLastAssistantInTurn)&&!US(e.changedFiles,t.changedFiles))},XS=/^\*\*\*\s+(?:Begin Patch|End Patch|Add File:|Update File:|Delete File:|Move to:)/m,ZS=/^@@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+@@/m,QS=/(?=^diff --git\s+)/gm,$S=/^diff --git\s+/m,eC=/(?=^---\s+\S)/gm,tC=/^---\s+\S/m,nC=e=>typeof e==`object`&&!!e,rC=e=>e.replace(/\r\n/g,`
|
|
6538
6538
|
`).replace(/\r/g,`
|
|
6539
6539
|
`).trim(),iC=e=>{let t=!1;return e.split(`
|
|
@@ -6571,7 +6571,7 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,E as n,P as r,T
|
|
|
6571
6571
|
|
|
6572
6572
|
`):wE(Array.from(t.childNodes).map(e=>kE(e)).join(``))},ME=e=>Array.from(e.childNodes).every(e=>{if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return!0;let t=e;return!SE.has(t.tagName.toLowerCase())}),NE=(e,t)=>{let n=e.cloneContents();if(ME(n)){let e=wE(Array.from(n.childNodes).map(e=>kE(e)).join(``));if(e)return e}return Array.from(n.childNodes).map(e=>jE(e)).filter(e=>e.length>0).join(`
|
|
6573
6573
|
|
|
6574
|
-
`).trim()||wE(t)},PE=({containerRef:e})=>{let{t}=ot(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),[o,c]=Z.useState(``),l=Z.useRef(!1),[u,d]=Z.useState(!1),f=Z.useRef(null),p=Z.useRef(bE),m=Z.useRef(null),h=Z.useRef(null),g=Z.useRef(null),_=Z.useRef(!1),v=ni(e=>e.createSession),y=Yt(e=>e.setPendingInputText),b=s(e=>e.isMobile),x=Ph(Nh()).textSelectionMutation;Z.useEffect(()=>{_.current=n.show},[n.show]),Z.useEffect(()=>()=>{h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null),g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]);let S=Z.useCallback(()=>{m.current=null,xE===S&&(xE=null),_.current&&=(h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null),d(!1),r(e=>({...e,show:!1})),a(``),c(``),!1)},[]);Z.useEffect(()=>()=>{xE===S&&(xE=null)},[S]);let C=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=p.current/2,r=yE+n,i=t-yE-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),w=Z.useCallback(()=>{if(!m.current)return;xE!==S&&(xE?.(),xE=S);let{plainText:e,markdownText:t,rect:i}=m.current,o=!n.show,s=b?i.left+i.width/2:C(i.left+i.width/2),l=i.top-10;a(e),c(t),r({x:s,y:l,show:!0}),_.current=!0,o&&(d(!0),h.current!==null&&window.cancelAnimationFrame(h.current),h.current=window.requestAnimationFrame(()=>{d(!1),h.current=null}))},[C,S,b,n.show]);Z.useLayoutEffect(()=>{if(!n.show||b||!f.current)return;let e=f.current.offsetWidth;!Number.isFinite(e)||e<=0||e===p.current||(p.current=e,r(e=>({...e,x:C(e.x)})))},[C,b,n.show]),Z.useEffect(()=>{if(!n.show||b)return;let e=()=>{r(e=>({...e,x:C(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[C,b,n.show]);let T=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){l.current||S();return}let r=wE(t.toString());if(!r){l.current||S();return}let i=DE(t,n);if(!i){l.current||S();return}let a=i.getBoundingClientRect();m.current={plainText:r,markdownText:NE(i,r),rect:a},l.current||w()},[e,S,w]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{l.current=!0,S()},r=()=>{l.current=!1,g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>{g.current=null,T()},10)},i=new Set,a=()=>{for(let e of EE(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,T))};a();let o=new MutationObserver(a);o.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,T),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let s=e=>{f.current&&!f.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&S()};return document.addEventListener(`mousedown`,s),()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null),o.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,T);document.removeEventListener(`selectionchange`,T),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,s)}},[e,T,S,w]),Z.useEffect(()=>{if(!n.show)return;let e=e=>{f.current&&e.target instanceof Node&&f.current.contains(e.target)||S()};return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),()=>{window.removeEventListener(`scroll`,e,!0)}},[n.show,S]);let E=Z.useCallback(e=>{if(!e)return;let t=`\`\`\`md\n${e}\n\`\`\``;y(t,`append`),S(),window.getSelection()?.removeAllRanges()},[y,S]),D=Z.useCallback(()=>{E(o)},[E,o]);Z.useEffect(()=>{let t=t=>{if(!x||!t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||t.key.toLowerCase()!==`i`)return;let n=window.getSelection(),r=e.current;if(!n||!r||!n.toString().trim())return;let i=DE(n,r);i&&(t.preventDefault(),E(NE(i,n.toString())))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[E,x,e]);let O=Z.useCallback(async()=>{i&&(await v(void 0,null,null)&&y(i,`replace`),S(),window.getSelection()?.removeAllRanges())},[i,v,y,S]),k=Z.useCallback(async()=>{if(!i)return;let e=await ct(i);e.ok||console.error(`Failed to copy:`,e.error),S(),window.getSelection()?.removeAllRanges()},[i,S]);return n.show?b?(0,$c.createPortal)((0,$.jsx)(`div`,{ref:f,className:Y(`fixed left-3 right-3 bottom-0 z-50 mx-auto max-w-[420px]`,`rounded-2xl border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] p-2 shadow-lg`,`safe-area-bottom`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),style:{bottom:`calc(0.5rem + env(safe-area-inset-bottom, 0px))`},children:(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[x?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--primary-base)] text-[var(--primary-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.addToChat`)})]}):null,x?(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.newSession`)})]}):null,(0,$.jsxs)(`button`,{onClick:k,className:Y(`col-span-2 flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):(0,$c.createPortal)((0,$.jsx)(`div`,{ref:f,className:`fixed z-50`,style:{left:n.x,top:n.y,transform:`translate(-50%, -100%)`},children:(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1 whitespace-nowrap`,`rounded-lg border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] shadow-none`,`px-1.5 py-1`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),children:[x?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.addToChat`)}),(0,$.jsx)(qp,{shortcut:`⌘+I`})]}):null,x?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,x?(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.newSession`)})]}):null,x?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{onClick:k,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):null},FE=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),IE=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),FE(e,n)},LE=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),RE=(e,t)=>{if(!LE(e))return``;let n=new Date(e),r=new Date,i=lo(n,t),a=st(),o=lt.getState().dictionary;if(FE(n,r))return i;if(IE(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}`},zE=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,BE=e=>e,VE=e=>{if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let n of e){let e=BE(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},HE=(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-VE(n);return!Number.isFinite(a)||a<=0?null:a},UE=e=>{let t=HE(e.createdAt,e.completedAt,e.parts,e.fallbackDurationMs);if(t===null)return null;let n=zE(e.outputTokens)+zE(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},WE=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`},GE=e=>{let t=(0,Q.c)(20),{text:n,active:r,className:i}=e,a=Z.useRef(n),[o,s]=Z.useState(n),[c,l]=Z.useState(null),u,d;t[0]!==r||t[1]!==n?(u=()=>{if(n===a.current)return;let e=a.current;if(a.current=n,!r||e.length===0){l(null),s(n);return}l(e),s(n)},d=[r,n],t[0]=r,t[1]=n,t[2]=u,t[3]=d):(u=t[2],d=t[3]),Z.useEffect(u,d);let f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>{l(null)},t[4]=f):f=t[4];let p=J(f),m;t[5]===i?m=t[6]:(m=Y(`oc-summary-flip-viewport relative block h-5 min-h-0 w-full min-w-0 max-w-full overflow-clip sm:h-6`,i),t[5]=i,t[6]=m);let h=c&&`invisible`,g;t[7]===h?g=t[8]:(g=Y(`block h-full min-w-0 truncate leading-5 sm:leading-6`,h),t[7]=h,t[8]=g);let _;t[9]!==o||t[10]!==g?(_=(0,$.jsx)(`span`,{className:g,children:o}),t[9]=o,t[10]=g,t[11]=_):_=t[11];let v;t[12]!==o||t[13]!==p||t[14]!==c?(v=c?(0,$.jsxs)(`span`,{className:`oc-summary-flip-stage absolute inset-0 block overflow-clip`,children:[(0,$.jsx)(`span`,{className:`oc-summary-flip-out absolute inset-x-0 top-0 block h-full truncate`,"aria-hidden":`true`,children:c}),(0,$.jsx)(`span`,{className:`oc-summary-flip-in absolute inset-x-0 top-0 block h-full truncate`,onAnimationEnd:p,children:o})]}):null,t[12]=o,t[13]=p,t[14]=c,t[15]=v):v=t[15];let y;return t[16]!==m||t[17]!==_||t[18]!==v?(y=(0,$.jsxs)(`span`,{className:m,children:[_,v]}),t[16]=m,t[17]=_,t[18]=v,t[19]=y):y=t[19],y},KE=[`search`,`read`,`list`];function qE(e){let t=JC(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function JE(e){let t={read:0,search:0,list:0};for(let n of e){let e=qE(n);e&&(t[e]+=1)}return t}function YE(e){return qC(e)}function XE(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!WC(e.toolName):e.kind!=null||e.type!=null}function ZE(e,t,n){for(let r=t;r<e.length;r+=1)if(XE(n(e[r])))return!0;return!1}function QE(e){return`parts`in e?e.parts.some(e=>YE(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>YE(e))}function $E(e,t,n){let r=[],i=t;for(;i<e.length&&WC(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var eD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,tD=({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??QE({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=JE(u.map(e=>e.tool)),p=KE.filter(e=>f[e]>0).map(e=>{let t=f[e];return o(e===`search`?t===1?`chat.contextGroup.searchSingle`:`chat.contextGroup.searchPlural`:e===`read`?t===1?`chat.contextGroup.readSingle`:`chat.contextGroup.readPlural`:t===1?`chat.contextGroup.listSingle`:`chat.contextGroup.listPlural`,{count:t})}).join(`, `),m=J(()=>{c(e=>!e)}),h=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),m())}),g=o(s?`chat.contextGroup.collapseAria`:`chat.contextGroup.expandAria`),_=o(d?`chat.contextGroup.exploring`:`chat.contextGroup.explored`),v=t?`h-5`:`h-6`;return(0,$.jsxs)(`div`,{"data-component":`context-tool-group`,className:lm(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":s,"aria-controls":l,"aria-label":g,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,um),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)(MC,{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,eD,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,eD),style:{color:`var(--tools-description)`},children:(0,$.jsx)(GE,{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 nD(e,t,n){let r=[],i=t;for(;i<e.length&&GC(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var rD=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function iD(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=rD(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=rD(e.name);if(t)return t;let r=rD(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=rD(n.output.name);if(e)return e}return null}function aD(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 oD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,sD=({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=>qC(e)),{joinedVisible:l,hiddenCount:u}=aD(s.map(iD)),d=u>0?r(`chat.skillGroup.summaryOverflow`,{names:l,count:u}):l,f=J(()=>{a(e=>!e)}),p=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),f())}),m=r(i?`chat.skillGroup.collapseAria`:`chat.skillGroup.expandAria`),h=r(`chat.tools.display.skill`);return(0,$.jsxs)(`div`,{"data-component":`skill-tool-group`,className:lm(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":i,"aria-controls":o,"aria-label":m,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,um),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)(MC,{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`,oD,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`,oD),style:{color:`var(--tools-description)`},children:(0,$.jsx)(GE,{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]})},cD=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:c}=e,l=s(lD),u=n,d=typeof u.text==`string`?u.text:``,f=typeof u.content==`string`?u.content:``,p=f.length>d.length?f:d,m=u.time,h=n.sessionID,g=o===void 0||o!==`completed`,_,v;if(t[0]!==i||t[1]!==p?(_=()=>{p.trim().length!==0&&i?.(`structural`)},v=[i,p],t[0]=i,t[1]=p,t[2]=_,t[3]=v):(_=t[2],v=t[3]),Z.useEffect(_,v),!p||p.trim().length===0)return null;let y=o??`streaming`,b=g&&typeof m?.end!=`number`,x;t[4]!==l||t[5]!==r||t[6]!==i||t[7]!==c||t[8]!==n||t[9]!==h||t[10]!==y||t[11]!==b?(x=(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(TT,{part:n,sessionId:h,messageId:r,streamPhase:y,chatRenderMode:l,hasStreamingHapticLifecycle:b,onContentChange:i,onShowPopup:c})}),t[4]=l,t[5]=r,t[6]=i,t[7]=c,t[8]=n,t[9]=h,t[10]=y,t[11]=b,t[12]=x):x=t[12];let S;t[13]===a?S=t[14]:(S=a?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:a})}):null,t[13]=a,t[14]=S);let C;return t[15]!==x||t[16]!==S?(C=(0,$.jsxs)(`div`,{"data-message-text-export-root":`true`,children:[x,S]}),t[15]=x,t[16]=S,t[17]=C):C=t[17],C});function lD(e){return e.chatRenderMode}var uD=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},dD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,fD=Y(`typography-meta font-medium`,dD),pD=Y(`typography-meta`,dD),mD=[],hD=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},gD=e=>{let t=new Set;for(let n of e)hD(n)&&n.messageId&&t.add(n.messageId);return[...t]},_D=(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}),vD=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=tc(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},yD=e=>e,bD=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},xD=e=>{let t=e.part.state,n=t?.input,r=t?.metadata,i=n?.filePath||n?.file_path||n?.path||r?.filePath||r?.file_path||r?.path;return typeof i==`string`&&i.trim().length>0?i:null},SD=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},CD=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},wD=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=CD(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`}`},TD=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=wD(n.todos);if(e)return e}if(Array.isArray(r)){let e=wD(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=wD(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=wD(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=wD(e.todos);if(t)return t}}catch{}return null},ED=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)},DD=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(Xx,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,pD),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`,pD),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)(Xx,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},OD=e=>{let t=yo(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},kD=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 iD(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`?TD(e):bD(e)},AD=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}},jD=Z.memo(e=>{let t=(0,Q.c)(16),{activity:n,isExpanded:r,isMobile:i,onToggleTool:a,onShowPopup:o,onContentChange:s}=e,c;t[0]!==n.id||t[1]!==a?(c=()=>{a(n.id)},t[0]=n.id,t[1]=a,t[2]=c):c=t[2];let l=J(c),u;t[3]===i?u=t[4]:(u=lm(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)(aT,{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&&RS([e.activity.part],[t.activity.part])),MD=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=lm(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(FD,{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&&PD(e.activities,t.activities)),ND=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!Qr(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(WC(i)){let r=$E(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:ZE(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(GC(i)){let r=nD(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(HC(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(VC(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(UC(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},PD=(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||!RS([r.part],[i.part]))return!1}return!0},FD=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=ot(),c=s(zD),l=rc(n,o),u;t[0]===n?u=t[1]:(u=Zx(n),t[0]=n,t[1]=u);let d=u,f;t[2]===n?f=t[3]:(f=n.toLowerCase(),t[2]=n,t[3]=f);let p=f===`read`,m=Z.useContext(Oo),h=Qh(),g=we(BD),_=Nh(),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=Fi(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(VD)),t[10]=w,t[11]=T);let E=T,D=r[0]??null,O=!D||qC(D.part),k;t[12]===D?k=t[13]:(k=D?kD(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||SD(D);if(!e||e===`<built-in>`){j=null;break bb0}let r=OD(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=xD(D);if(!e){N=null;break bb1}let n=_o(e,v);if(!n){N=null;break bb1}let r;t[26]===D?r=t[27]:(r=ED(D),t[26]=D,t[27]=r);let i;t[28]!==n||t[29]!==e||t[30]!==r?(i={path:e,displayPath:n,offset:r},t[28]=n,t[29]=e,t[30]=r,t[31]=i):i=t[31],N=i}t[22]=v,t[23]=p,t[24]=D,t[25]=N}else N=t[25];let P=N,F;t[32]!==v||t[33]!==h||t[34]!==m?(F=(e,t)=>{if(!v)return;let n=vo(v,e);if(!n)return;if(h){h.openFile({path:n,targetLine:t&&Number.isFinite(t)?Math.max(1,Math.trunc(t)):void 0});return}if(m?.editor){m.editor.openFile(n,t);return}if(!So(n,v)){lc(n,v).then(()=>{let e=s.getState(),r=v||go(v,n);if(t&&Number.isFinite(t)){e.openContextFileAtLine(r,n,Math.max(1,Math.trunc(t)),1);return}e.openContextFile(r,n)});return}let r=s.getState(),i=go(v,n);if(t&&Number.isFinite(t)){r.openContextFileAtLine(i,n,Math.max(1,Math.trunc(t)),1);return}r.openContextFile(i,n)},t[32]=v,t[33]=h,t[34]=m,t[35]=F):F=t[35];let I=J(F),L;t[36]!==v||t[37]!==h?(L=e=>{let t=yo(e);if(!t)return;let n=()=>{if(h){h.openFile({path:t});return}let e=s.getState(),n=v||go(``,t);e.openContextFile(n,t)};if(v&&!So(t,v)){lc(t,v).then(n);return}n()},t[36]=v,t[37]=h,t[38]=L):L=t[38];let R=J(L),z;t[39]===n?z=t[40]:(z=n.toLowerCase(),t[39]=n,t[40]=z);let B=z,V=B===`grep`||B===`search`||B===`find`||B===`ripgrep`||B===`glob`,H=B===`webfetch`||B===`fetch`||B===`curl`||B===`wget`,U=B===`skill`,W=!!(P||M),ee=!!(P&&v||M),G;t[41]!==ee||t[42]!==I||t[43]!==R||t[44]!==W||t[45]!==P||t[46]!==M?(G=()=>{if(!(!W||!ee)){if(P){I(P.path,P.offset);return}M&&R(M.path)}},t[41]=ee,t[42]=I,t[43]=R,t[44]=W,t[45]=P,t[46]=M,t[47]=G):G=t[47];let K=J(G),q;t[48]===K?q=t[49]:(q=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),K())},t[48]=K,t[49]=q);let te=J(q),ne=W&&ee&&`cursor-pointer`,re=W&&!ee&&`cursor-default opacity-70`,ie;t[50]!==ne||t[51]!==re?(ie=Y(`flex w-full items-center gap-x-1.5 min-w-0`,um,ne,re),t[50]=ne,t[51]=re,t[52]=ie):ie=t[52];let ae=W?`soft`:void 0,oe=W?K:void 0,se=W?te:void 0,ce=W?`button`:void 0,le=W&&ee?0:void 0,ue=W&&!ee?!0:void 0,de=i?`size-4`:`size-3.5`,fe;t[53]===de?fe=t[54]:(fe=Y(`inline-flex items-center justify-center flex-shrink-0`,de),t[53]=de,t[54]=fe);let pe;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(pe={color:`var(--tools-icon)`},t[55]=pe):pe=t[55];let me=O?(0,$.jsx)(MC,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:l})}):d,he;t[56]!==fe||t[57]!==pe||t[58]!==me?(he=(0,$.jsx)(`div`,{className:fe,style:pe,children:me}),t[56]=fe,t[57]=pe,t[58]=me,t[59]=he):he=t[59];let ge,_e;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(ge=Y(fD,`inline-flex items-center flex-shrink-0 opacity-85`),_e={color:`var(--tools-title)`},t[60]=ge,t[61]=_e):(ge=t[60],_e=t[61]);let ve;t[62]===l?ve=t[63]:(ve=(0,$.jsx)(`span`,{className:ge,style:_e,title:l,children:l}),t[62]=l,t[63]=ve);let ye;t[64]!==a||t[65]!==p||t[66]!==P||t[67]!==c?(ye=p&&P?(0,$.jsxs)(`span`,{className:Y(`inline-flex !min-h-0 items-center justify-start gap-1 min-w-0 flex-1 text-left`,pD),style:{color:`var(--tools-description)`},title:P.offset?`${P.displayPath}:${P.offset}`:P.displayPath,children:[c?(0,$.jsx)(hd,{filePath:P.path,className:`h-3.5 w-3.5`}):null,DD(P.displayPath,a)]}):null,t[64]=a,t[65]=p,t[66]=P,t[67]=c,t[68]=ye):ye=t[68];let be;t[69]!==a||t[70]!==A||t[71]!==V?(be=V&&A?(0,$.jsx)(`span`,{className:`inline-flex min-w-0 flex-1`,children:(0,$.jsxs)(Xx,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,pD),style:{color:`var(--tools-description)`},title:A,children:[`"`,A,`"`]})}):null,t[69]=a,t[70]=A,t[71]=V,t[72]=be):be=t[72];let xe;t[73]!==A||t[74]!==H?(xe=H&&A?(0,$.jsxs)(`a`,{href:A,target:`_blank`,rel:`noopener noreferrer`,onClick:HD,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`,pD),style:{color:`var(--status-info)`},title:A,children:[(0,$.jsx)(vD,{href:A}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:A})]}):null,t[73]=A,t[74]=H,t[75]=xe):xe=t[75];let Se;t[76]!==U||t[77]!==M?(Se=U&&M?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,pD),style:{color:`var(--tools-description)`},title:M.path,children:M.name}):null,t[76]=U,t[77]=M,t[78]=Se):Se=t[78];let Ce;t[79]!==A||t[80]!==U||t[81]!==M?(Ce=U&&!M&&A?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,pD),style:{color:`var(--tools-description)`},title:A,children:A}):null,t[79]=A,t[80]=U,t[81]=M,t[82]=Ce):Ce=t[82];let Te;t[83]!==a||t[84]!==A||t[85]!==H||t[86]!==p||t[87]!==V||t[88]!==U?(Te=!p&&!V&&!H&&!U&&A?(0,$.jsx)(Xx,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,pD),style:{color:`var(--tools-description)`},children:A}):null,t[83]=a,t[84]=A,t[85]=H,t[86]=p,t[87]=V,t[88]=U,t[89]=Te):Te=t[89];let Ee;return t[90]!==ie||t[91]!==ae||t[92]!==oe||t[93]!==se||t[94]!==ce||t[95]!==le||t[96]!==ue||t[97]!==he||t[98]!==ve||t[99]!==ye||t[100]!==be||t[101]!==xe||t[102]!==Se||t[103]!==Ce||t[104]!==Te?(Ee=(0,$.jsxs)(`div`,{className:ie,"data-mobile-press-feedback":ae,onClick:oe,onKeyDown:se,role:ce,tabIndex:le,"aria-disabled":ue,children:[he,ve,ye,be,xe,Se,Ce,Te]}),t[90]=ie,t[91]=ae,t[92]=oe,t[93]=se,t[94]=ce,t[95]=le,t[96]=ue,t[97]=he,t[98]=ve,t[99]=ye,t[100]=be,t[101]=xe,t[102]=Se,t[103]=Ce,t[104]=Te,t[105]=Ee):Ee=t[105],Ee},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&PD(e.activities,t.activities)),ID=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)(LT,{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}),LD=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)(cD,{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}),RD=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(),_=cc()??``,v=Z.useMemo(()=>gD(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?uD(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(()=>AD(e),[e]),M=T?j.active:j.all,N=M.slice(0,c?2:3),P=J((e=!1,n=!1)=>{if(!(!_||!v.length)){for(let r of v){let i=t.find(e=>e.messageId===r)?.part.sessionID;if(!i)continue;let a=Pn(_,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=Rn(_,i,r,{priority:n?`background`:`user`}).catch(()=>{x.current.add(r)}).finally(()=>{b.current.delete(r),S(e=>e+1)});b.current.set(r,o)}S(e=>e+1)}}),F=J(e=>{e.stopPropagation(),P(!0)}),I=T,L=I||n,R=J(()=>{if(I)return;let e=C.current;w.current=e?{top:e.getBoundingClientRect().top,scrollContainer:e.closest(`[data-scrollbar="chat"]`)}:null,L||P(),s()});Z.useEffect(()=>{T||!L||P(!1,!0)},[T,L]),Z.useLayoutEffect(()=>{let e=w.current,t=C.current;if(!e||!t)return;let n=()=>{if(!t.isConnected)return;let n=t.getBoundingClientRect().top-e.top;if(!(Math.abs(n)<.5)){if(e.scrollContainer?.isConnected){e.scrollContainer.scrollTop+=n;return}window.scrollBy(0,n)}};if(n(),typeof window>`u`||typeof window.requestAnimationFrame!=`function`){w.current=null;return}let r=window.requestAnimationFrame(()=>{n(),w.current=null});return()=>window.cancelAnimationFrame(r)},[L]);let z=m&&!L?Math.max(0,Math.floor(r)):0,B=!m||L||z>0,V=y.current,H=[...V].map(e=>{if(b.current.has(e))return`loading`;if(x.current.has(e))return`error`;let n=t.find(t=>t.messageId===e)?.part.sessionID??``;return Pn(_,n,e).status}),U=H.includes(`loading`),W=H.includes(`error`),ee=H.length>0&&H.every(e=>e===`ready`),G=t.some(e=>V.has(e.messageId)&&hD(e)),K=ee&&!G&&!_D(t,V),q=Z.useMemo(()=>B?yD(e):mD,[e,B]),te=Z.useMemo(()=>B?ND(q):[],[B,q]),ne=Z.useMemo(()=>L||z===0?0:Math.max(0,te.length-z),[L,z,te.length]),re=Z.useMemo(()=>L||z===0?te:te.slice(-z),[L,z,te]);if((!m||I&&!O)&&te.length===0)return null;let ie=(e,t)=>{let n=(0,$.jsx)(`div`,{className:lm(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},ae=B?re.map((e,t)=>{switch(e.type){case`reasoning`:return ie(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(ID,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return ie(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(LD,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(jD,{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)(MD,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(tD,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(FD,{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)(sD,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(FD,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(jD,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,oe=re.length>0;return m?(0,$.jsxs)(`div`,{className:lm(c),children:[(0,$.jsxs)(`button`,{ref:C,type:`button`,className:Y(`group/tool flex w-full min-w-0 flex-nowrap items-center text-left`,c?`gap-x-1`:`gap-x-2`,!I&&um,I&&`oc-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-default`,c&&`pr-0`),"data-mobile-press-feedback":I?void 0:`soft`,onClick:I?void 0:R,"aria-expanded":L,"aria-disabled":I||void 0,"aria-label":I?A:g(L?`chat.activity.collapseAria`:`chat.activity.expandAria`),children:[(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 flex-1 items-center overflow-clip`,c?`gap-x-1`:`gap-x-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,c?`h-5 w-4`:`h-6 w-3.5`),style:{color:`var(--tools-icon)`},children:T&&!O?(0,$.jsx)(MC,{isMobile:c,label:A,className:`block`}):(0,$.jsx)(X,{name:k,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:Y(`inline-flex flex-shrink-0 items-center`,c?`typography-meta h-5`:`typography-ui-label h-5 font-semibold`,T?`animate-text-shimmer text-[var(--status-info)] [--oc-text-shimmer-base:var(--status-info)]`:`text-foreground/85`),children:A}),E?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 tabular-nums text-muted-foreground`,children:E}):null]}),(0,$.jsxs)(`span`,{className:Y(`ml-auto inline-flex max-w-[min(14rem,55%)] shrink-0 items-center justify-end`,c?`gap-0.5`:`gap-1`),children:[M.length>0?(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center text-muted-foreground`,c?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5`,"aria-hidden":`true`,children:N.map((e,t)=>(0,$.jsx)(sa,{name:e,size:c?12:14,className:Y(`flex-none`,c?`size-3 min-h-3 min-w-3 max-h-3 max-w-3`:`size-3.5 min-h-3.5 min-w-3.5 max-h-3.5 max-w-3.5`)},`${e}-${t}`))}),(0,$.jsx)(`span`,{className:`typography-meta min-w-0 truncate`,children:g(T?`chat.activity.agentsWorking`:`chat.activity.agentsInvolved`,{count:M.length})})]}):null,I?null:(0,$.jsx)(X,{name:L?`arrow-down-s`:`arrow-right-s`,className:Y(`flex-shrink-0 text-muted-foreground opacity-70`,c&&`-mr-0.5`,c?`size-3`:`size-3.5`)})]})]}),oe?(0,$.jsxs)(`div`,{className:I?void 0:`relative ml-2 pl-3`,children:[I?null:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-px bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),ne>0?(0,$.jsxs)(`button`,{type:`button`,onClick:R,className:`typography-meta leading-4 px-2 py-1 text-muted-foreground/45 hover:text-muted-foreground/65 text-left`,children:[`+`,ne,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:ae})]}):null,L&&(U||W||K)?(0,$.jsx)(`div`,{className:Y(`typography-meta flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,I?void 0:`ml-5`,W&&`text-[var(--status-error)]`),role:W?`alert`:`status`,children:U?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{children:g(`chat.activity.outputLoading`)})]}):W?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:g(`chat.activity.outputLoadFailed`)}),(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`xs`,onClick:F,children:g(`chat.activity.outputRetry`)})]}):(0,$.jsx)(`span`,{children:g(`chat.toolOutputDialog.noOutputProduced`)})}):null]}):(0,$.jsx)(`div`,{className:lm(c),children:ae})});function zD(e){return e.showToolFileIcons}function BD(e){return e.currentDirectory}function VD(e){return[e.name,e]}function HD(e){e.stopPropagation()}var UD=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(RD,{...e}),t[0]=e,t[1]=n),n}),WD={contain:`layout`},GD={containerType:`inline-size`,containerName:`message-footer`},KD=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,qD=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,JD=`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`,YD=`size-3.5!`,XD=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,ZD=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,QD=`flex items-center gap-2`,$D=`flex items-center gap-2 text-muted-foreground`,eO=`inline-flex h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,tO=`size-3.5!`,nO=`medium`,rO=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,iO=`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)]`,aO=`h-7 gap-1.5`,oO=`h-6 gap-1`,sO=`text-[11px] leading-none`,cO=`size-3.5`,lO=`size-3`,uO=5,dO=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)(hd,{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=rO(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}),fO=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=ot(),s;t[0]!==n.file||t[1]!==a?(s=()=>{a(n.file)},t[0]=n.file,t[1]=a,t[2]=s):s=t[2];let c=J(s),l=!r,u=i?oO:aO,d;t[3]===u?d=t[4]:(d=Y(iO,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)(dO,{file:n,isMobile:i}),t[8]=n,t[9]=i,t[10]=p):p=t[10];let m;return t[11]!==n.file||t[12]!==c||t[13]!==l||t[14]!==d||t[15]!==f||t[16]!==p?(m=(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`xs`,disabled:l,"data-turn-change-file":`true`,className:d,"aria-label":f,title:n.file,onClick:c,children:p}),t[11]=n.file,t[12]=c,t[13]=l,t[14]=d,t[15]=f,t[16]=p,t[17]=m):m=t[17],m}),pO=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:c}=ot(),l=cc(),u=Nh(),d=u.directory||l,f=u.sessionId,p=Qh(),m=s(DO),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,uO),t[2]=g,t[3]=_);let v=_,y=Math.max(0,g.length-v.length),b=g.length>0?g.length:n,x=!!(p||!o&&d||o&&a),S;t[4]!==b||t[5]!==c?(S=c(b===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:b}),t[4]=b,t[5]=c,t[6]=S):S=t[6];let C=S,w;t[7]!==y||t[8]!==c?(w=c(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[7]=y,t[8]=c,t[9]=w):w=t[9];let T=w,E=Y(iO,o?oO:aO),D=o?lO:cO,O;t[10]===o?O=t[11]:(O=o?Y(sO,`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(sO,`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(sO,`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){BT({directory:d,filePath:e,turnMessageId:i,sessionId:f});return}o&&a&&d&&BT({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[16]=d,t[17]=f,t[18]=a,t[19]=o,t[20]=p,t[21]=i,t[22]=P):P=t[22];let F=J(P),I;t[23]!==d||t[24]!==f||t[25]!==a||t[26]!==o||t[27]!==p||t[28]!==m||t[29]!==i||t[30]!==v[0]?.file?(I=()=>{if(p){p.openTurnDiff(i,f);return}if(!o&&d){m(d,{mode:`diff`,dedupeKey:`turn-diff:${f||`session`}:${i}`,targetPath:null,diffScope:`turn`,diffTurnMessageId:i,diffSessionId:f});return}let e=v[0]?.file;e&&o&&a&&d&&BT({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[23]=d,t[24]=f,t[25]=a,t[26]=o,t[27]=p,t[28]=m,t[29]=i,t[30]=v[0]?.file,t[31]=I):I=t[31];let L=J(I),R=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,z;t[32]===R?z=t[33]:(z=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,R),t[32]=R,t[33]=z);let B=Y(E,`max-w-full text-muted-foreground hover:text-foreground`),V;t[34]===c?V=t[35]:(V=c(`diffView.actions.reviewAria`),t[34]=c,t[35]=V);let H;t[36]===c?H=t[37]:(H=c(`diffView.actions.reviewAria`),t[36]=c,t[37]=H);let U;t[38]===D?U=t[39]:(U=(0,$.jsx)(X,{name:`file-edit`,className:D}),t[38]=D,t[39]=U);let W=`turn-changes-${i}`,ee;t[40]===c?ee=t[41]:(ee=c(`chat.changedFiles.title`),t[40]=c,t[41]=ee);let G;t[42]!==W||t[43]!==ee||t[44]!==k?(G=(0,$.jsx)(`span`,{id:W,className:k,children:ee}),t[42]=W,t[43]=ee,t[44]=k,t[45]=G):G=t[45];let K;t[46]!==C||t[47]!==j?(K=(0,$.jsx)(`span`,{className:j,children:C}),t[46]=C,t[47]=j,t[48]=K):K=t[48];let q;t[49]===D?q=t[50]:(q=Y(D,`opacity-60`),t[49]=D,t[50]=q);let te;return t[51]===q?te=t[52]:(te=(0,$.jsx)(X,{name:`arrow-right-s`,className:q}),t[51]=q,t[52]=te),(0,$.jsxs)(`section`,{className:z,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(ca,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,onClick:L,className:B,"aria-label":V,title:H,children:[U,G,K,te]}),v.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[v.map(e=>(0,$.jsx)(fO,{file:e,canOpen:x,isMobile:o,onOpen:F},e.file)),y>0?(0,$.jsxs)(ca,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,className:Y(E,`text-muted-foreground hover:text-foreground`),onClick:L,"aria-label":c(`diffView.actions.reviewAria`),title:c(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(D,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:N,children:[`+`,T]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:D})]}):null]}):null]})}),mO=e=>e.type===`subtask`,hO=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},gO=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}`},_O=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=cc(),{isMobile:o}=fo(),c=ni(OO),l=s(kO),u=Nh(),{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=gO(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(AO),children:f(r?`chat.messageBody.subtask.hidePrompt`:`chat.messageBody.subtask.showPrompt`)}),r?(0,$.jsx)(`pre`,{className:`typography-meta mt-1.5 overflow-x-auto whitespace-pre-wrap break-words text-foreground/85`,children:b}):null]}):null,t[29]=r,t[30]=b,t[31]=T,t[32]=f,t[33]=N):N=t[33];let P;t[34]!==v||t[35]!==m||t[36]!==a||t[37]!==o||t[38]!==l||t[39]!==u||t[40]!==c||t[41]!==f||t[42]!==S?(P=S&&u.capabilities.navigateNestedSession?(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>{let e=u.directory||a;e&&Fh(u,S,e,()=>{if(!ui({sessionId:S,directory:e})){if(cl()||o||d()){c(S,e);return}l(e,{mode:`chat`,dedupeKey:`session:${S}`,label:m||v||f(`contextPanel.mode.chat`),readOnly:!0})}})},children:f(`chat.messageBody.subtask.openSession`)})}):null,t[34]=v,t[35]=m,t[36]=a,t[37]=o,t[38]=l,t[39]=u,t[40]=c,t[41]=f,t[42]=S,t[43]=P):P=t[43];let F;return t[44]!==j||t[45]!==M||t[46]!==N||t[47]!==P?(F=(0,$.jsxs)(`div`,{className:`mt-2`,children:[j,M,N,P]}),t[44]=j,t[45]=M,t[46]=N,t[47]=P,t[48]=F):F=t[48],F},vO=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=cc(),i=s(jO),{isMobile:a}=fo(),{t:o}=ot(),c;t[0]!==r||t[1]!==a?(c=r&&!a&&!d(),t[0]=r,t[1]=a,t[2]=c):c=t[2];let l=!!c,u;t[3]!==n.state||t[4]!==o?(u=n.state===`completed`?o(`chat.messageBody.subagent.completed`):n.state===`error`?o(`chat.messageBody.subagent.error`):o(`chat.messageBody.subagent.cancelled`),t[3]=n.state,t[4]=o,t[5]=u):u=t[5];let f=u,p=n.state===`completed`?o(`chat.messageBody.subagent.completedDescription`):n.state===`error`?o(`chat.messageBody.subagent.errorDescription`):o(`chat.messageBody.subagent.cancelledDescription`),m=n.description||p,h=J(()=>{!l||!r||i(r,{mode:`chat`,dedupeKey:`session:${n.sessionID}`,label:m,readOnly:!0})}),g;t[6]===h?g=t[7]:(g=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())},t[6]=h,t[7]=g);let _=J(g),v=l&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,y;t[8]===v?y=t[9]:(y=Y(`mt-2 flex min-w-0 gap-2.5 rounded-[var(--radius-lg)] border border-border/60 bg-muted/20 px-3 py-2.5`,v),t[8]=v,t[9]=y);let b=l?`button`:void 0,x=l?0:void 0,S=l?o(`chat.messageBody.subagent.openSession`,{label:m}):void 0,C=l?h:void 0,w=l?_:void 0,T;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(`span`,{className:`mt-0.5 flex size-6 flex-shrink-0 items-center justify-center rounded-md bg-foreground/5 text-muted-foreground`,children:(0,$.jsx)(X,{name:`robot-2`,className:`size-3.5`})}),t[10]=T):T=t[10];let E;t[11]===m?E=t[12]:(E=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:m}),t[11]=m,t[12]=E);let D=n.state===`completed`?`bg-[var(--status-success-background)] text-[var(--status-success)]`:n.state===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`,O;t[13]===D?O=t[14]:(O=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,D),t[13]=D,t[14]=O);let k;t[15]!==f||t[16]!==O?(k=(0,$.jsx)(`span`,{className:O,children:f}),t[15]=f,t[16]=O,t[17]=k):k=t[17];let A;t[18]!==E||t[19]!==k?(A=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[E,k]}),t[18]=E,t[19]=k,t[20]=A):A=t[20];let j;t[21]===n.body?j=t[22]:(j=n.body?(0,$.jsx)(`div`,{className:`typography-meta mt-1 max-h-16 overflow-hidden text-muted-foreground [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,children:(0,$.jsx)(Os,{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},yO={background:`transparent`,backgroundColor:`transparent`},bO=e=>{let t=(0,Q.c)(36),{part:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=Z.useRef(null),{t:c}=ot(),l;t[0]===n.shellAction?l=t[1]:(l=typeof n.shellAction?.command==`string`?n.shellAction.command.trim():``,t[0]=n.shellAction,t[1]=l);let u=l,d=typeof n.shellAction?.output==`string`?n.shellAction.output:``,f;t[2]===n.shellAction?f=t[3]:(f=typeof n.shellAction?.status==`string`?n.shellAction.status.trim().toLowerCase():``,t[2]=n.shellAction,t[3]=f);let p=f,m;t[4]===d?m=t[5]:(m=d.trim(),t[4]=d,t[5]=m);let h=m.length>0,g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{s.current!==null&&typeof window<`u`&&(window.clearTimeout(s.current),s.current=null)},t[6]=g):g=t[6];let _=J(g),v,y;t[7]===_?(v=t[8],y=t[9]):(v=()=>()=>{_()},y=[_],t[7]=_,t[8]=v,t[9]=y),Z.useEffect(v,y);let b;t[10]!==_||t[11]!==h||t[12]!==d?(b=async()=>{h&&(await ct(d)).ok&&(_(),o(!0),typeof window<`u`&&(s.current=window.setTimeout(()=>{o(!1),s.current=null},2e3)))},t[10]=_,t[11]=h,t[12]=d,t[13]=b):b=t[13];let x=J(b),S;t[14]===c?S=t[15]:(S=c(`chat.messageBody.shellCommand.title`),t[14]=c,t[15]=S);let C;t[16]===S?C=t[17]:(C=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:S}),t[16]=S,t[17]=C);let w;t[18]===p?w=t[19]:(w=p?(0,$.jsx)(`span`,{className:Y(`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none`,p===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`),children:p}):null,t[18]=p,t[19]=w);let T;t[20]!==w||t[21]!==C?(T=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[C,w]}),t[20]=w,t[21]=C,t[22]=T):T=t[22];let E;t[23]===u?E=t[24]:(E=u?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 overflow-x-auto font-mono`,children:(0,$.jsx)(Ac,{language:`bash`,code:u,codeStyle:yO,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(MO),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)(Ac,{language:`bash`,code:d,codeStyle:yO,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},xO=e=>{let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},SO=(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}},CO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:c,hasTextContent:l,onCopyMessage:u,copiedMessage:d,onShowPopup:f,agentMention:p,onEdit:m,onRevert:h,onFork:g,pendingMessageAction:_,editing:v,editStaged:y,onCancelEdit:b,userActionsMode:x=`inline`,stickyUserHeaderEnabled:S=!0})=>{let{locale:C,t:w}=ot(),T=bg(),E=Ph(Nh()),D=s(e=>e.timeFormatPreference),[O,k]=Z.useState(!1),A=Z.useRef(null),j=Z.useMemo(()=>n.filter(e=>e.type===`text`?!qr(e):!!(mO(e)||hO(e))),[n]),M=Z.useMemo(()=>j.map(e=>en(e)?_S(Qr(e)):void 0),[j]),N=p?.token,P=!1,F=!!u,I=!!d,L=!!(c??a),R=!!l,z=x!==`external-actions`,B=x!==`external-content`,V=S&&x===`inline`,H=J(()=>{A.current!==null&&typeof window<`u`&&(window.clearTimeout(A.current),A.current=null)}),U=J(()=>{!L||!F||!R||typeof window>`u`||(H(),k(!0),A.current=window.setTimeout(()=>{k(!1),A.current=null},1800))});Z.useEffect(()=>{R||(k(!1),H())},[H,R]);let W=J(e=>{!u||!R||(e.stopPropagation(),e.preventDefault(),u(),L&&U())}),ee=T===`mini-chat`||!E.fork?void 0:g,G=Z.useMemo(()=>{if(typeof i!=`number`||i<=0)return null;let e=RE(i,D);return e.length>0?e:null},[C,i,D]),K=Y(`group/user-actions`,a?x===`inline`?`flex items-center justify-end pt-2 pb-3`:S?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:x===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),q=!v&&y&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsxs)(`div`,{className:Y(QD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(eO,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:nO,name:`edit`,className:tO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:w(`chat.messageBody.actions.editStaged`)})]}),b?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:JD,"aria-label":w(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),b()},children:(0,$.jsx)(X,{weight:nO,name:`close`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,te=(v&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsx)(`div`,{className:Y(QD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(eO,`animate-text-shimmer`),"aria-live":`polite`,children:w(`chat.messageBody.actions.editing`)})})}):null)??q??((F&&R||m||h||ee)&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsxs)(`div`,{className:Y(QD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,o?`pointer-events-auto opacity-100`:`pointer-events-none opacity-0 transition-opacity duration-150 group-hover/message:pointer-events-auto group-hover/message:opacity-100 group-hover/user-actions:pointer-events-auto group-hover/user-actions:opacity-100 group-hover/user-shell:pointer-events-auto group-hover/user-shell:opacity-100`),"data-message-action-group":`true`,children:[G?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(eO,`mr-1`),"aria-label":`Message time: ${G}`,children:[(0,$.jsx)(X,{weight:nO,name:`time`,className:tO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:G})]})}),(0,$.jsx)(La,{children:G})]}):null,h&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:JD,"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:nO,name:_===`revert`?`loader-4`:`arrow-go-back`,className:Y(YD,_===`revert`&&`animate-spin`)})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.revert`)})]}),m&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:JD,"aria-label":w(`chat.messageBody.actions.editAria`),disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:nO,name:`edit`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.edit`)})]}),ee&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:JD,"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:nO,name:_===`fork`?`loader-4`:`git-branch`,className:Y(YD,_===`fork`&&`animate-spin`)})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.fork`)})]}),F&&R&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":O||I?`true`:void 0,className:JD,"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:nO,name:`check`,className:Y(YD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:nO,name:`file-copy`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return z?(0,$.jsxs)(`div`,{className:`relative w-full group/message`,style:WD,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(mO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(_O,{part:e})},e.id??`user-subtask-${i}`);if(hO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(bO,{part:e})},e.id??`user-shell-${i}`);let o=M[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(vO,{notification:o})},e.id??`subagent-notification-${i}`);let s;return p&&N&&!P&&Qr(e).includes(N)&&(s=p,P=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(Jx,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(Vd,{files:n,messageID:t,sessionID:e,onShowPopup:f,compact:!0}),te]}):(0,$.jsx)($.Fragment,{children:te})}),wO=Z.memo(({hasCopyableText:e,isTouchContext:t,onCopyMessage:n,reviewTransferAction:r,ttsText:i,sessionId:a})=>{let{t:o}=ot(),s=bg(),c=Nh(),l=Ph(c),{isPlaying:u,play:d,stop:f}=vE(),p=br(e=>e.showMessageTTSButtons),m=br(e=>e.voiceProvider),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),[y,b]=Z.useState(!1),x=Z.useRef(null),S=Z.useRef(null),C=!!n,w=!!((c.sessionId||a)&&c.directory&&l.openSourceSession&&s!==`mini-chat`),T=J(()=>{x.current!==null&&typeof window<`u`&&(window.clearTimeout(x.current),x.current=null)}),E=J(()=>{S.current!==null&&typeof window<`u`&&(window.clearTimeout(S.current),S.current=null)});Z.useEffect(()=>()=>{T(),E()},[E,T]),Z.useEffect(()=>{(!e||!C)&&(g(!1),v(!1),T(),E())},[C,E,T,e]);let D=J(()=>{!t||!C||!e||typeof window>`u`||(T(),g(!0),x.current=window.setTimeout(()=>{g(!1),x.current=null},1800))}),O=J(async r=>{!n||!e||(r.stopPropagation(),r.preventDefault(),await n()!==!1&&(E(),v(!0),typeof window<`u`&&(S.current=window.setTimeout(()=>{v(!1),S.current=null},2e3)),t&&D()))}),k=J(async t=>{if(t.stopPropagation(),t.preventDefault(),!(!r||y||!e)){b(!0);try{await r.onClick()}finally{b(!1)}}}),A=J(e=>{e.stopPropagation(),e.preventDefault();let t=c.sessionId||a;!t||!c.directory||!c.openSourceSession||c.openSourceSession(t,c.directory)}),j=Z.useMemo(()=>u?o(`chat.messageBody.tts.stopSpeaking`):o(`chat.messageBody.tts.readAloudWithProvider`,{provider:m===`browser`?`Browser`:m===`openai`?`OpenAI`:m===`openai-compatible`?`Custom`:`Say`}),[u,o,m]),M=J(e=>{if(e.stopPropagation(),e.preventDefault(),u){f();return}i.trim()&&d(i)});return(0,$.jsxs)($.Fragment,{children:[n&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":h||_?`true`:void 0,className:Y(JD,!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:nO,name:`check`,className:Y(YD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:nO,name:`file-copy`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:o(`chat.messageBody.actions.copyAnswer`)})]}),w?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:JD,"aria-label":o(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:A,children:(0,$.jsx)(X,{weight:nO,name:`target`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:o(`chat.messageBody.actions.openSourceSession`)})]}):null,r&&s!==`mini-chat`&&l.reviewTransfer?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,size:`icon`,variant:`ghost`,disabled:y||!e,className:Y(JD,(!e||y)&&`opacity-50`),"aria-label":r.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{k(e)},children:y?(0,$.jsx)(X,{weight:nO,name:`loader-4`,className:Y(YD,`animate-spin`)}):(0,$.jsx)(X,{weight:nO,name:`arrow-left-right`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:r.tooltip})]}):null,s!==`mini-chat`&&p&&e&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:Y(JD,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:nO,name:`stop`,className:YD}):(0,$.jsx)(X,{weight:nO,name:`volume-up`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:j})]})]})}),TO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:c,messageTokens:l,isMobile:u,alwaysShowActions:f,hasTouchInput:p,expandedTools:m,onToggleTool:h,onShowPopup:g,streamPhase:_,allowAnimation:v,onContentChange:y,hasTextContent:b=!1,onCopyMessage:x,onAuxiliaryContentComplete:S,showReasoningTraces:C=!1,turnGroupingContext:w,errorMessage:T,errorVariant:E=`error`,reviewTransferDirection:D=null})=>{let{t:O,locale:k}=ot(),A=bg(),j=Ph(Nh()),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?ZD:XD,B=!i,V=Z.useMemo(()=>n.filter(e=>!qr(e)).filter(e=>e.type!==`compaction`),[n]),H=Z.useMemo(()=>V.filter(e=>e.type===`tool`),[V]),U=Z.useMemo(()=>V.filter(e=>e.type===`text`),[V]),W=Z.useMemo(()=>Qn(U),[U]),ee=s(e=>e.openContextPreview),G=d(),K=A===`mini-chat`,q=Z.useMemo(()=>{if(G||u||K)return null;for(let e of U){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=nc(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=nc(n.replace(/\x1b\[[0-9;]*m/g,``))[0];if(r)return r.includes(`0.0.0.0`)?r.replace(`0.0.0.0`,`127.0.0.1`):r}return null},[U,u,K,G,H]),te=ni(e=>e.forkFromMessage),ne=ni(e=>e.forkTransition),re=ni(e=>e.currentSessionId),ie=ni(e=>e.getDirectoryForSession),ae=cc(),oe=D===`review-to-original`,se=!u&&!G?D:null,ce=Z.useMemo(()=>{let t=W.trim();if(!(!e||!ae||!t||!se))return se===`review-to-original`?{ariaLabel:O(`chat.messageBody.actions.sendReviewFeedback`),tooltip:O(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await Lt(e,ae,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:O(`chat.messageBody.actions.sendImplementationResponse`),tooltip:O(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await wn(e,ae,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[W,ae,se,e,O]),[le,ue]=Z.useState(!1),de=s(e=>e.chatRenderMode),fe=s(e=>e.collapsibleThinkingBlocks),pe=s(e=>e.showSplitAssistantMessageActions),me=s(e=>e.showAssistantTps),he=s(e=>e.timeFormatPreference),ge=de===`sorted`,_e=w?.isLastAssistantInTurn??!1,ve=a===`stop`,ye=(ve||i||!!T)&&(w?.isTurnSettled??!0),be=ve?`completed`:M,xe=H.length>0,Se=Z.useMemo(()=>H.some(e=>qC(e)),[H]),Ce=qC,we=KC,Te=I.current.experiencedStreamingOrCooldown,Ee=Z.useRef({messageId:t,initialized:!1,observedPartIds:new Set});Z.useEffect(()=>{if(Ee.current.messageId!==t&&(Ee.current={messageId:t,initialized:!1,observedPartIds:new Set}),!Te||!gt())return;let n=Ee.current,r=!n.initialized;n.initialized=!0;for(let i of H){if(n.observedPartIds.has(i.id))continue;if(!Jr(r,Ce(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),bn({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[Te,Ce,t,e,H]);let De=Z.useMemo(()=>H.length===0||!Se&&H.every(e=>we(e)),[H,Se,we]),Oe=Z.useMemo(()=>V.filter(e=>e.type===`reasoning`),[V]),ke=Z.useMemo(()=>Oe.length===0||Oe.every(e=>typeof e.time?.end==`number`),[Oe]),Ae=typeof a!=`string`,je=Oe.length>0&&xe&&(Se||Ae||!De),Me=B||xe&&(Se||Ae||!De),Ne=B||je,Pe=xe||Oe.length>0,Fe=U.length===0,Ie=Pe&&Fe&&!Me&&!Ne&&De&&ke,Le=Z.useRef(!1),Re=Z.useRef(!1);Z.useEffect(()=>{Re.current=!1},[t]),Z.useEffect(()=>{if(!Ie){Le.current=!1;return}Le.current||(Le.current=!0,S?.())},[Ie,S]),Z.useEffect(()=>{if(B){Re.current=!1;return}if(xe){Re.current=!1;return}Oe.length!==0&&(Ne||!ke||Re.current||(Re.current=!0,y?.(`structural`)))},[B,xe,y,ke,Oe.length,Ne]);let ze=!!b&&!B,Be=J(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||le||ne)){ue(!0);try{await te(e,t)}finally{ue(!1)}}}),Ve=Z.useMemo(()=>{let e=w?.activityParts;return!ge||!e?[]:e},[ge,w?.activityParts]),He=Z.useMemo(()=>{let e=w?.activityGroupSegments;return!ge||!e?[]:e.filter(e=>e.anchorMessageId===t)},[ge,t,w?.activityGroupSegments]),Ue=He.length>0,We=Z.useMemo(()=>{let e=new Map,t=new Map;return Ve.forEach(n=>{e.set(n.part,n);let r=n.part.id;typeof r==`string`&&r.length>0&&t.set(r,n)}),{get:n=>{let r=e.get(n);if(r)return r;let i=n.id;if(typeof i==`string`&&i.length>0)return t.get(i)}}},[Ve]),Ge=w?.toggleGroup,Ke=w?.activityPresentationKind===`compaction`,qe=w?.isGroupExpanded===!0,Je=ge&&Ke&&!qe,Ye=ge?w?.activityOwnerMessageId===t||Ue:!w?.activityOwnerMessageId||w.activityOwnerMessageId===t||Ue,Xe=ge&&Ye&&(Ue||Ke)&&!!Ge,Ze=qT(a,V),Qe={finish:a,parts:V,streamPhase:be,error:T,isLastAssistantInTurn:_e},$e=QT(Qe),et=ge&&$T(Qe),tt=ge&&!$e&&!(Ke&&qe),nt=!!T,rt=E===`info`?`information`:`error-warning`,it=E===`muted`,at=ze,st=_e&&ye&&!Je&&(b||!!T||i),lt=w?.diffStats?.hasDiffs===!0,ut=!K&&_e&&Ze&&ye&&!Je&&w?.diffStats?.hasDiffs===!0,dt=pe&&at&&!st&&!ge,ft=Z.useMemo(()=>(0,$.jsx)(wO,{hasCopyableText:ze,isTouchContext:L,onCopyMessage:x,ttsText:W,reviewTransferAction:ce,sessionId:e}),[W,ze,L,x,ce,e]),pt=Z.useMemo(()=>e=>{if(!pe||!ge)return null;let t=Qr(e.part).trim();return t?(0,$.jsx)(wO,{hasCopyableText:!0,isTouchContext:L,onCopyMessage:async()=>(await ct(t)).ok,ttsText:t}):null},[ge,L,pe]),mt=Z.useMemo(()=>{if(!dt)return-1;let e=-1;for(let t=0;t<V.length;t+=1){let n=V[t];!n||n.type!==`text`||tt||We.get(n)?.kind!==`justification`&&(e=t)}return e},[We,tt,dt,V]),ht=dt&&mt<0,_t=Z.useMemo(()=>{let n=[];if(Xe&&Ge&&w){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(UD,{parts:t,materializationParts:r,isExpanded:w.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:w.completionDisposition,activityPresentationKind:w.activityPresentationKind,durationMs:w.durationMs,startedAt:w.userMessageCreatedAt,onToggle:Ge,isMobile:u,expandedTools:m,onToggleTool:h,onShowPopup:g,onContentChange:y,streamPhase:be,showHeader:!0,diffStats:w.diffStats,renderJustificationActions:pt})},`progressive-group-${e}`))};He.length>0?He.forEach(t=>{let n=C?t.parts:t.parts.filter(e=>e.kind!==`reasoning`);e(t.id,n,t.parts)}):Ke&&e(`${t}:compaction-status`,[])}let r=0;for(;r<V.length;){let i=V[r];if(i.type===`text`){let a=We.get(i);if(tt){r+=1;continue}if(Je){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:P,"data-message-text-export-source":`true`,children:(0,$.jsx)(TT,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,allowSortedFinalStreaming:et,hasStreamingHapticLifecycle:Te,onContentChange:y,onShowPopup:g})},`assistant-text-${t}-${i.id??r}`)),dt&&r===mt&&n.push((0,$.jsx)(`div`,{className:u?qD:KD,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:QD,"data-message-action-group":`true`,children:ft})},`message-actions-${t}`)),r++;continue}if(i.type===`reasoning`){if(We.get(i)?.kind===`reasoning`){r+=1;continue}if(!Qr(i).trim()){r+=1;continue}C&&(fe?n.push((0,$.jsx)(`div`,{className:lm(u),children:(0,$.jsx)(LT,{part:i,messageId:t,streamPhase:be,onContentChange:y})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(TT,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,hasStreamingHapticLifecycle:Te,onContentChange:y,onShowPopup:g},`reasoning-${t}-${i.id??r}`))),r++;continue}if(i.type===`tool`){let e=i,a=e.tool?.toLowerCase()??``;if(ge&&!Ye){r+=1;continue}if(We.get(i)?.kind===`tool`){r+=1;continue}if(WC(a)){let e=[],i=r;for(;i<V.length;){let n=V[i];if(n.type!==`tool`)break;let r=n;if(!WC(r.tool?.toLowerCase()??``)||We.get(n)?.kind===`tool`)break;e.push({id:r.id,turnId:``,messageId:t,partIndex:i,part:r,kind:`tool`}),i+=1}if(e.length>0){n.push((0,$.jsx)(tD,{activities:e,isMobile:u,isTurnLive:be!==`completed`,hasFollowingOtherType:ZE(V,i,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:e.map(e=>(0,$.jsx)(FD,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`context-tools-${e[0].id}`)),r=i;continue}}if(GC(a)){let e=nD(V,r,e=>e.type!==`tool`||We.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(sD,{activities:i,isMobile:u,children:i.map(e=>(0,$.jsx)(FD,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(VC(a)){n.push((0,$.jsx)(`div`,{className:lm(u),children:(0,$.jsx)(aT,{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:lm(u),children:(0,$.jsx)(FD,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:u,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}return n},[We,He,R,de,fe,0,m,Je,Ke,u,Ye,ge,mt,t,ft,pt,e,y,g,h,Xe,dt,be,Te,C,tt,et,Ge,w,V]),vt=Z.useMemo(()=>{if(!_e||!ye)return;let e=w?.durationMs;if(!(typeof e!=`number`||e<=0))return xO(e)},[_e,ye,w?.durationMs]),yt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof c==`number`&&c>0?c:null;if(e===null)return null;let t=RE(e,he);return t.length>0?t:null},[o,c,he,k]),bt=Z.useMemo(()=>{if(!me||!_e||!ye)return null;let e=r??n,t=SO(e,l),i=UE({createdAt:c,completedAt:o,fallbackDurationMs:w?.durationMs,outputTokens:t.output,reasoningTokens:t.reasoning,parts:e});if(i===null)return null;let a=WE(i);return a.length>0?a:null},[me,_e,ye,n,r,l,c,o,w?.durationMs]),xt=(0,$.jsxs)($.Fragment,{children:[!K&&!u&&!G&&q?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:JD,"aria-label":O(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=ae??(re?ie(re):null);e&&ee(e,q)},children:(0,$.jsx)(X,{weight:nO,name:`global`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:O(`chat.messageBody.actions.openPreview`)})]}):null,!K&&!oe&&j.fork?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,size:`icon`,variant:`ghost`,className:JD,"aria-label":O(`chat.messageBody.actions.forkAria`),"aria-busy":le,disabled:le||!!ne,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Be(e)},children:(0,$.jsx)(X,{weight:nO,name:le?`loader-4`:`git-branch`,className:Y(YD,le&&`animate-spin`)})})}),(0,$.jsx)(La,{sideOffset:6,children:O(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:N,"data-message-text-export-root":`true`,className:Y(`relative w-full group/message`),style:WD,children:[(0,$.jsx)(PE,{containerRef:N}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`message-content-text leading-relaxed text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0`,children:[_t,nt&&(0,$.jsx)(hc,{children:it?(0,$.jsxs)(`div`,{role:`status`,className:`my-1.5 flex max-w-full items-center gap-1.5 break-words typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`stop-circle`,className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0`,children:T})]}):(0,$.jsxs)(`div`,{className:Y(`group/assistant-text relative flow-root my-1.5 break-words max-w-full`,E===`info`?Y(`inline-flex w-fit max-w-full border border-[var(--status-info-border)]/45 bg-[var(--status-info-background)]/40`,u?`items-start gap-1.5 rounded-lg px-2.5 py-1.5`:Y(`items-center gap-1.5`,`rounded-lg px-2 py-0.5`)):`mt-3 flex items-center gap-2 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3`),children:[E===`info`&&u?(0,$.jsx)(`span`,{className:`inline-flex h-5 w-3.5 shrink-0 items-center justify-center translate-y-[2px]`,"aria-hidden":`true`,children:(0,$.jsx)(X,{name:rt,weight:nO,className:Y(YD,`text-[var(--status-info)]/80`)})}):(0,$.jsx)(X,{name:rt,weight:E===`info`?nO:void 0,className:Y(`shrink-0`,E===`info`?Y(YD,`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)(Os,{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)(pO,{fileCount:w.diffStats.files,changedFiles:w.changedFiles,turnId:w.turnId,isLatestTurn:w.isLatestTurn,isMobile:u}):null,(0,$.jsx)(Vd,{files:n,messageID:t,sessionID:e,onShowPopup:g}),ht&&(0,$.jsx)(`div`,{className:Y(u?qD:KD),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:QD,"data-message-action-group":`true`,children:ft})}),st&&(0,$.jsxs)(`div`,{className:z,"data-message-footer":`true`,style:GD,children:[(0,$.jsxs)(`div`,{className:QD,"data-message-action-group":`true`,children:[ft,xt]}),bt||vt||yt?(0,$.jsxs)(`div`,{className:$D,children:[bt?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:eO,"aria-label":O(`chat.messageBody.meta.tpsAria`,{rate:bt}),children:[(0,$.jsx)(X,{weight:nO,name:`pulse`,className:tO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:bt})]})}),(0,$.jsx)(La,{children:O(`chat.messageBody.meta.tpsTooltip`)})]}):null,vt?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:eO,children:[(0,$.jsx)(X,{weight:nO,name:`hourglass`,className:tO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:vt})]})}),(0,$.jsx)(La,{children:vt})]}):null,yt?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:eO,"aria-label":`Message time: ${yt}`,children:[(0,$.jsx)(X,{weight:nO,name:`time`,className:tO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:yt})]})}),(0,$.jsx)(La,{children:yt})]}):null]}):null,!K&&_e&&ve&&!lt?(0,$.jsx)(VT,{activityParts:w?.activityParts}):null]})]})]})}),EO=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)(CO,{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)(TO,{...r}),t[26]=r,t[27]=i),i});function DO(e){return e.openContextPanelTab}function OO(e){return e.setCurrentSession}function kO(e){return e.openContextPanelTab}function AO(e){return!e}function jO(e){return e.openContextPanelTab}function MO(e){return!e}var NO=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}},PO=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,FO=e=>!e,IO=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},LO=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),RO=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,zO=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,BO=`Authentication failed for this provider. Please re-authenticate and retry.`,VO=e=>{if(typeof e!=`string`)return!1;let t=e.toLowerCase().trim();if(!t)return!1;if(t.includes(`token refresh failed`)||t.includes(`unauthorized`)||t.includes(`invalid token`)||t.includes(`expired token`))return!0;let n=t.includes(`oauth`),r=t.includes(`failed`)||t.includes(`invalid`)||t.includes(`expired`);if(n&&r)return!0;let i=/\b401\b/.test(t),a=t.includes(`auth`)||t.includes(`token`)||t.includes(`unauthorized`);return i&&a};function HO(e,t){if(!e||typeof e!=`object`)return;let n=e,r=typeof n.data?.message==`string`?n.data.message:void 0,i=typeof n.message==`string`?n.message:void 0,a=typeof n.name==`string`?n.name:void 0,o=r||i||a;if(o)return a===`SessionRetry`?{text:`Opencode failed to send a message. Retry attempt info: \n\`${o}\``,variant:`info`}:VO(o)?{text:BO,variant:`error`}:a===`MessageAbortedError`||o.trim().toLowerCase()===`aborted`?{text:t,variant:`muted`}:{text:`Opencode failed to send message with error:\n\`${o}\``,variant:`error`}}var UO=Fs(()=>Ue(()=>import(`./ToolOutputDialog-BvkZesJU.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]))),WO=4e3,GO=new Map,KO=new Map,qO=new Set([`bash`,`shell`,`cmd`,`terminal`]),JO=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},YO=e=>{let t=GO.get(e);return t?new Set(t):new Set},XO=(e,t)=>{if(GO.size>=WO&&!GO.has(e)){let e=GO.keys().next().value;typeof e==`string`&&GO.delete(e)}GO.set(e,new Set(t))},ZO=e=>{let t=KO.get(e);return t?new Set(t):new Set},QO=(e,t)=>{if(KO.size>=WO&&!KO.has(e)){let e=KO.keys().next().value;typeof e==`string`&&KO.delete(e)}KO.set(e,new Set(t))},$O=200,ek=new Map,tk=e=>ek.get(e),nk=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=ek.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(ek.size>=$O&&!ek.has(e)){let e=ek.keys().next().value;typeof e==`string`&&ek.delete(e)}ek.set(e,t)}};function rk(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 ik=(e,t)=>{if(typeof e==`object`&&e)return e[t]},ak=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:c=!1,activeStreamingPhase:l=null,animateUserOnMount:u=!1,onUserAnimationConsumed:d,reviewTransferDirection:f=null})=>{let{t:p}=ot(),{isMobile:m,isTablet:h,hasTouchInput:g}=fo(),_=Nh(),v=Ph(_),y=m||h,b=Z.useRef(null),x=ni(e=>e.currentSessionId),S=rn(e=>e.getAgentModelForSession),C=rn(e=>e.getSessionModelSelection),w=ni(e=>e.revertToMessage),T=ni(e=>e.editMessagePreservingChanges),E=ni(e=>e.forkFromMessage),D=ni(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),O=ni(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),k=ni(e=>e.clearStagedMessageEdit);Le(`ui.chat_message.render`),c&&Le(`ui.chat_message.render.streaming`);let A=br(e=>e.providers),{showReasoningTraces:j,stickyUserHeader:M,chatRenderMode:N,showExpandedBashTools:P}=s(pe(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{x&&Nx.getInstance().recordSessionStart(x)},[x]);let[F,I]=Z.useState(null),[L,R]=Z.useState(!1),[z,B]=Z.useState(null),V=Z.useRef(null),[H,U]=Z.useState(()=>YO(e.info.id)),[W,ee]=Z.useState(()=>ZO(e.info.id)),[G,K]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{U(YO(e.info.id)),ee(ZO(e.info.id))},[e.info.id]);let q=Z.useMemo(()=>NO(e.info),[e.info]).isUser,te=q&&(m||!M),ne=q&&!m&&M&&!te,re=e.info.sessionID,ie=Ix(e=>e.planModeEnabled),{currentContextAgent:ae,savedSessionAgentSelection:oe}=wm(pe(e=>({currentContextAgent:c&&re?e.currentAgentContext.get(re):void 0,savedSessionAgentSelection:c&&re?e.sessionAgentSelections.get(re):void 0}))),se=Z.useMemo(()=>fn(e.sourceParts??e.parts),[e.parts,e.sourceParts]),ce=Z.useMemo(()=>q?vn(se,{planModeEnabled:ie}):fn(e.parts),[q,e.parts,ie,se]),le=Z.useMemo(()=>{if(q||!t)return null;let e=ik(t.info,`clientRole`),n=ik(t.info,`role`);if((typeof e==`string`?e:typeof n==`string`?n:void 0)!==`user`)return null;let r=ik(t.info,`mode`),i=ik(t.info,`agent`),a=ik(t.info,`providerID`),o=ik(t.info,`modelID`),s=ik(t.info,`model`),c=typeof s==`object`&&s?s.variant:void 0,l=ik(t.info,`variant`),u=c??l,d=typeof s==`object`&&s?s.providerID:void 0,f=typeof s==`object`&&s?s.modelID:void 0,p=typeof r==`string`&&r.trim().length>0?r:typeof i==`string`&&i.trim().length>0?i:void 0,m=typeof a==`string`&&a.trim().length>0?a:typeof d==`string`&&d.trim().length>0?d:void 0,h=typeof o==`string`&&o.trim().length>0?o:typeof f==`string`&&f.trim().length>0?f:void 0,g=typeof u==`string`&&u.trim().length>0?u:void 0;return!p&&!m&&!h&&!g?null:{agentName:p,providerId:m,modelId:h,variant:g}},[q,t]),ue=Z.useMemo(()=>{if(!ie||q||!t)return!1;let e=Array.isArray(t.parts)?t.parts:[];for(let t=0;t<e.length;t++){let n=e[t];if(n?.type!==`text`||n?.synthetic!==!0)continue;let r=typeof n.text==`string`?n.text.trim():``;if(r.startsWith(`User has requested to enter plan mode`)||r.startsWith(`The plan at `))return!0}return!1},[q,ie,t]),de=Z.useMemo(()=>{if(q)return;let t=e.info.time;if(!(typeof t?.completed==`number`&&t.completed>0)&&ue&&le?.agentName)return le.agentName;let n=ik(e.info,`mode`);if(typeof n==`string`&&n.trim().length>0)return n;let r=ik(e.info,`agent`);if(typeof r==`string`&&r.trim().length>0)return r;if(le?.agentName)return le.agentName;if(re)return ae||(oe??void 0)},[q,e.info,ue,le,re,ae,oe]),fe=q?null:ik(e.info,`providerID`),me=q?null:ik(e.info,`modelID`),he=Z.useMemo(()=>{if(q||!re)return null;if(le?.providerId&&le?.modelId)return{providerId:le.providerId,modelId:le.modelId};if(de){let e=S(re,de);if(e?.providerId&&e?.modelId)return e}let e=C(re);return e?.providerId&&e?.modelId?e:null},[q,re,de,le,S,C]),ge=Z.useMemo(()=>q?null:typeof fe==`string`&&fe.trim().length>0?fe:he?.providerId??null,[q,fe,he]),_e=Z.useMemo(()=>q?null:typeof me==`string`&&me.trim().length>0?me:he?.modelId??null,[q,me,he]),ve=e.info.id?tk(e.info.id):void 0;q||nk(e.info.id,{agent:de,provider:ge??void 0,model:_e??void 0});let ye=de??ve?.agent,be=ge??ve?.provider??null,xe=_e??ve?.model??null,Se=Z.useMemo(()=>{if(q)return;let e=be&&A.length>0?A.find(e=>e.id===be):void 0;return Er(e,xe)||void 0},[q,be,xe,A]),Ce=Z.useMemo(()=>{if(q||!ge||!_e)return!1;let e=A.find(e=>e.id===ge);if(!e?.models||!Array.isArray(e.models))return!1;let t=e.models.find(e=>e.id===_e)?.variants;return!!(t&&Object.keys(t).length>0)},[q,_e,ge,A]),we=rk(ye),Te=rk(be??void 0),Ee=rk(xe??void 0),De=rk(Se),Oe=we??void 0,ke=Te??null,Ae=Ee??null,je=De??void 0,Me=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),Ne=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Pe=Z.useMemo(()=>q?!0:!!(Me&&Me>0),[q,Me]),Fe=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),Ie=Z.useMemo(()=>{if(q)return null;let t=e.info.tokens;return!t||typeof t!=`object`?null:{output:typeof t.output==`number`?t.output:void 0,reasoning:typeof t.reasoning==`number`?t.reasoning:void 0}},[q,e.info]),Re=Z.useMemo(()=>ht(ce,{includeReasoning:j}),[ce,j]),ze=Z.useMemo(()=>q?Re:!Pe&&N===`sorted`?[]:Re,[N,Pe,q,Re]),Be=Z.useMemo(()=>q?[]:Re.filter(e=>e.type===`text`),[q,Re]),Ve=Z.useMemo(()=>q?[]:Re.filter(e=>e.type===`tool`),[q,Re]),He=Z.useMemo(()=>{if(!P)return new Set;let e=new Set;for(let t of Ve){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=JO(t.tool);!r||!qO.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=JO(t.part.tool);!n||!qO.has(n)||e.add(t.id)}return e},[P,Ve,a?.activityParts]),Ue=Z.useMemo(()=>{if(He.size===0&&W.size===0)return H;let e=new Set(H);return He.forEach(t=>{W.has(t)||e.add(t)}),W.forEach(t=>{e.delete(t)}),e},[W,He,H]),We=Z.useMemo(()=>{if(!q)return;let e=ce.find(e=>e.type===`agent`);if(!e)return;let t=e,n=typeof t.name==`string`?t.name:void 0;if(n)return{name:n,token:t.source&&typeof t.source.value==`string`&&t.source.value.trim().length>0?t.source.value:`@${n}`}},[q,ce]),Ge=q&&!Dt(ze),Ke=typeof Fe!=`string`,qe=Z.useMemo(()=>q?!1:Be.length===0||Ve.length===0?Ke:!0,[Be.length,Ve.length,Ke,q]),Je=Z.useMemo(()=>!q&&Nx.getInstance().shouldAnimateMessage(e.info,x||e.info.sessionID),[e.info,x,q]),[Ye,Xe]=Z.useState(!1),Ze=Z.useMemo(()=>n?NO(n.info):null,[n]),Qe=!!a,$e=a?.isLastAssistantInTurn??!1,et=RO({isWorking:a?.isWorking===!0,isInActiveTurn:c,headerCompletionDisposition:a?.completionDisposition}),tt=Z.useMemo(()=>q?!1:Qe?!$e:Ze?!Ze.isUser&&Ze.role===`assistant`:!1,[Qe,$e,q,Ze]),nt=Z.useMemo(()=>Pe?`completed`:c?l??`streaming`:`completed`,[l,c,Pe]);Z.useEffect(()=>{!q||!u||d?.(e.info.id)},[u,q,e.info.id,d]),Z.useEffect(()=>{Xe(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;q||!t||t!==e.info.id||(nt===`streaming`||nt===`cooldown`)&&Xe(!0)},[o,q,e.info.id,nt,a?.headerMessageId]);let rt=Z.useMemo(()=>{if(q)return!0;let t=o??a?.headerMessageId;return t?e.info.id===t?nt===`completed`||Ye||nt===`streaming`||nt===`cooldown`:!1:!0},[o,Ye,q,a,nt,e.info.id]),it=Z.useCallback(e=>{ct(e).then(t=>{t.ok&&(I(e),setTimeout(()=>I(null),2e3))})},[]),at=q?void 0:a?.userMessageVariant??le?.variant,st=!q&&Ce&&typeof at==`string`&&at.trim().length>0?at:void 0,lt=Z.useMemo(()=>{if(!q)return HO(e.info?.error,p(`chat.messageBody.aborted`))},[q,e.info,p]),ut=lt?.text,dt=lt?.variant,ft=Z.useMemo(()=>{if(q){let e=ze.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.output;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);if(e.length>0)return e.join(`
|
|
6574
|
+
`).trim()||wE(t)},PE=({containerRef:e})=>{let{t}=ot(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),[o,c]=Z.useState(``),l=Z.useRef(!1),[u,d]=Z.useState(!1),f=Z.useRef(null),p=Z.useRef(bE),m=Z.useRef(null),h=Z.useRef(null),g=Z.useRef(null),_=Z.useRef(!1),v=ni(e=>e.createSession),y=Yt(e=>e.setPendingInputText),b=s(e=>e.isMobile),x=Ph(Nh()).textSelectionMutation;Z.useEffect(()=>{_.current=n.show},[n.show]),Z.useEffect(()=>()=>{h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null),g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]);let S=Z.useCallback(()=>{m.current=null,xE===S&&(xE=null),_.current&&=(h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null),d(!1),r(e=>({...e,show:!1})),a(``),c(``),!1)},[]);Z.useEffect(()=>()=>{xE===S&&(xE=null)},[S]);let C=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=p.current/2,r=yE+n,i=t-yE-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),w=Z.useCallback(()=>{if(!m.current)return;xE!==S&&(xE?.(),xE=S);let{plainText:e,markdownText:t,rect:i}=m.current,o=!n.show,s=b?i.left+i.width/2:C(i.left+i.width/2),l=i.top-10;a(e),c(t),r({x:s,y:l,show:!0}),_.current=!0,o&&(d(!0),h.current!==null&&window.cancelAnimationFrame(h.current),h.current=window.requestAnimationFrame(()=>{d(!1),h.current=null}))},[C,S,b,n.show]);Z.useLayoutEffect(()=>{if(!n.show||b||!f.current)return;let e=f.current.offsetWidth;!Number.isFinite(e)||e<=0||e===p.current||(p.current=e,r(e=>({...e,x:C(e.x)})))},[C,b,n.show]),Z.useEffect(()=>{if(!n.show||b)return;let e=()=>{r(e=>({...e,x:C(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[C,b,n.show]);let T=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){l.current||S();return}let r=wE(t.toString());if(!r){l.current||S();return}let i=DE(t,n);if(!i){l.current||S();return}let a=i.getBoundingClientRect();m.current={plainText:r,markdownText:NE(i,r),rect:a},l.current||w()},[e,S,w]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{l.current=!0,S()},r=()=>{l.current=!1,g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>{g.current=null,T()},10)},i=new Set,a=()=>{for(let e of EE(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,T))};a();let o=new MutationObserver(a);o.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,T),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let s=e=>{f.current&&!f.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&S()};return document.addEventListener(`mousedown`,s),()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null),o.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,T);document.removeEventListener(`selectionchange`,T),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,s)}},[e,T,S,w]),Z.useEffect(()=>{if(!n.show)return;let e=e=>{f.current&&e.target instanceof Node&&f.current.contains(e.target)||S()};return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),()=>{window.removeEventListener(`scroll`,e,!0)}},[n.show,S]);let E=Z.useCallback(e=>{if(!e)return;let t=`\`\`\`md\n${e}\n\`\`\``;y(t,`append`),S(),window.getSelection()?.removeAllRanges()},[y,S]),D=Z.useCallback(()=>{E(o)},[E,o]);Z.useEffect(()=>{let t=t=>{if(!x||!t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||t.key.toLowerCase()!==`i`)return;let n=window.getSelection(),r=e.current;if(!n||!r||!n.toString().trim())return;let i=DE(n,r);i&&(t.preventDefault(),E(NE(i,n.toString())))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[E,x,e]);let O=Z.useCallback(async()=>{i&&(await v(void 0,null,null)&&y(i,`replace`),S(),window.getSelection()?.removeAllRanges())},[i,v,y,S]),k=Z.useCallback(async()=>{if(!i)return;let e=await ct(i);e.ok||console.error(`Failed to copy:`,e.error),S(),window.getSelection()?.removeAllRanges()},[i,S]);return n.show?b?(0,$c.createPortal)((0,$.jsx)(`div`,{ref:f,className:Y(`fixed left-3 right-3 bottom-0 z-50 mx-auto max-w-[420px]`,`rounded-2xl border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] p-2 shadow-lg`,`safe-area-bottom`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),style:{bottom:`calc(0.5rem + env(safe-area-inset-bottom, 0px))`},children:(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[x?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--primary-base)] text-[var(--primary-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.addToChat`)})]}):null,x?(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.newSession`)})]}):null,(0,$.jsxs)(`button`,{onClick:k,className:Y(`col-span-2 flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):(0,$c.createPortal)((0,$.jsx)(`div`,{ref:f,className:`fixed z-50`,style:{left:n.x,top:n.y,transform:`translate(-50%, -100%)`},children:(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1 whitespace-nowrap`,`rounded-lg border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] shadow-none`,`px-1.5 py-1`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,u?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),children:[x?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.addToChat`)}),(0,$.jsx)(qp,{shortcut:`⌘+I`})]}):null,x?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,x?(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.newSession`)})]}):null,x?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{onClick:k,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):null},FE=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),IE=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),FE(e,n)},LE=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),RE=(e,t)=>{if(!LE(e))return``;let n=new Date(e),r=new Date,i=lo(n,t),a=st(),o=lt.getState().dictionary;if(FE(n,r))return i;if(IE(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}`},zE=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,BE=e=>e,VE=e=>{if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let n of e){let e=BE(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},HE=(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-VE(n);return!Number.isFinite(a)||a<=0?null:a},UE=e=>{let t=HE(e.createdAt,e.completedAt,e.parts,e.fallbackDurationMs);if(t===null)return null;let n=zE(e.outputTokens)+zE(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},WE=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`},GE=e=>{let t=(0,Q.c)(20),{text:n,active:r,className:i}=e,a=Z.useRef(n),[o,s]=Z.useState(n),[c,l]=Z.useState(null),u,d;t[0]!==r||t[1]!==n?(u=()=>{if(n===a.current)return;let e=a.current;if(a.current=n,!r||e.length===0){l(null),s(n);return}l(e),s(n)},d=[r,n],t[0]=r,t[1]=n,t[2]=u,t[3]=d):(u=t[2],d=t[3]),Z.useEffect(u,d);let f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>{l(null)},t[4]=f):f=t[4];let p=J(f),m;t[5]===i?m=t[6]:(m=Y(`oc-summary-flip-viewport relative block h-5 min-h-0 w-full min-w-0 max-w-full overflow-clip sm:h-6`,i),t[5]=i,t[6]=m);let h=c&&`invisible`,g;t[7]===h?g=t[8]:(g=Y(`block h-full min-w-0 truncate leading-5 sm:leading-6`,h),t[7]=h,t[8]=g);let _;t[9]!==o||t[10]!==g?(_=(0,$.jsx)(`span`,{className:g,children:o}),t[9]=o,t[10]=g,t[11]=_):_=t[11];let v;t[12]!==o||t[13]!==p||t[14]!==c?(v=c?(0,$.jsxs)(`span`,{className:`oc-summary-flip-stage absolute inset-0 block overflow-clip`,children:[(0,$.jsx)(`span`,{className:`oc-summary-flip-out absolute inset-x-0 top-0 block h-full truncate`,"aria-hidden":`true`,children:c}),(0,$.jsx)(`span`,{className:`oc-summary-flip-in absolute inset-x-0 top-0 block h-full truncate`,onAnimationEnd:p,children:o})]}):null,t[12]=o,t[13]=p,t[14]=c,t[15]=v):v=t[15];let y;return t[16]!==m||t[17]!==_||t[18]!==v?(y=(0,$.jsxs)(`span`,{className:m,children:[_,v]}),t[16]=m,t[17]=_,t[18]=v,t[19]=y):y=t[19],y},KE=[`search`,`read`,`list`];function qE(e){let t=JC(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function JE(e){let t={read:0,search:0,list:0};for(let n of e){let e=qE(n);e&&(t[e]+=1)}return t}function YE(e){return qC(e)}function XE(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!WC(e.toolName):e.kind!=null||e.type!=null}function ZE(e,t,n){for(let r=t;r<e.length;r+=1)if(XE(n(e[r])))return!0;return!1}function QE(e){return`parts`in e?e.parts.some(e=>YE(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>YE(e))}function $E(e,t,n){let r=[],i=t;for(;i<e.length&&WC(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var eD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,tD=({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??QE({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=JE(u.map(e=>e.tool)),p=KE.filter(e=>f[e]>0).map(e=>{let t=f[e];return o(e===`search`?t===1?`chat.contextGroup.searchSingle`:`chat.contextGroup.searchPlural`:e===`read`?t===1?`chat.contextGroup.readSingle`:`chat.contextGroup.readPlural`:t===1?`chat.contextGroup.listSingle`:`chat.contextGroup.listPlural`,{count:t})}).join(`, `),m=J(()=>{c(e=>!e)}),h=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),m())}),g=o(s?`chat.contextGroup.collapseAria`:`chat.contextGroup.expandAria`),_=o(d?`chat.contextGroup.exploring`:`chat.contextGroup.explored`),v=t?`h-5`:`h-6`;return(0,$.jsxs)(`div`,{"data-component":`context-tool-group`,className:lm(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":s,"aria-controls":l,"aria-label":g,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,um),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)(MC,{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,eD,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,eD),style:{color:`var(--tools-description)`},children:(0,$.jsx)(GE,{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 nD(e,t,n){let r=[],i=t;for(;i<e.length&&GC(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var rD=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function iD(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=rD(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=rD(e.name);if(t)return t;let r=rD(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=rD(n.output.name);if(e)return e}return null}function aD(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 oD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,sD=({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=>qC(e)),{joinedVisible:l,hiddenCount:u}=aD(s.map(iD)),d=u>0?r(`chat.skillGroup.summaryOverflow`,{names:l,count:u}):l,f=J(()=>{a(e=>!e)}),p=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),f())}),m=r(i?`chat.skillGroup.collapseAria`:`chat.skillGroup.expandAria`),h=r(`chat.tools.display.skill`);return(0,$.jsxs)(`div`,{"data-component":`skill-tool-group`,className:lm(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":i,"aria-controls":o,"aria-label":m,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,um),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)(MC,{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`,oD,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`,oD),style:{color:`var(--tools-description)`},children:(0,$.jsx)(GE,{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]})},cD=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:c}=e,l=s(lD),u=n,d=typeof u.text==`string`?u.text:``,f=typeof u.content==`string`?u.content:``,p=f.length>d.length?f:d,m=u.time,h=n.sessionID,g=o===void 0||o!==`completed`,_,v;if(t[0]!==i||t[1]!==p?(_=()=>{p.trim().length!==0&&i?.(`structural`)},v=[i,p],t[0]=i,t[1]=p,t[2]=_,t[3]=v):(_=t[2],v=t[3]),Z.useEffect(_,v),!p||p.trim().length===0)return null;let y=o??`streaming`,b=g&&typeof m?.end!=`number`,x;t[4]!==l||t[5]!==r||t[6]!==i||t[7]!==c||t[8]!==n||t[9]!==h||t[10]!==y||t[11]!==b?(x=(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(TT,{part:n,sessionId:h,messageId:r,streamPhase:y,chatRenderMode:l,hasStreamingHapticLifecycle:b,onContentChange:i,onShowPopup:c})}),t[4]=l,t[5]=r,t[6]=i,t[7]=c,t[8]=n,t[9]=h,t[10]=y,t[11]=b,t[12]=x):x=t[12];let S;t[13]===a?S=t[14]:(S=a?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:a})}):null,t[13]=a,t[14]=S);let C;return t[15]!==x||t[16]!==S?(C=(0,$.jsxs)(`div`,{"data-message-text-export-root":`true`,children:[x,S]}),t[15]=x,t[16]=S,t[17]=C):C=t[17],C});function lD(e){return e.chatRenderMode}var uD=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},dD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,fD=Y(`typography-meta font-medium`,dD),pD=Y(`typography-meta`,dD),mD=[],hD=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},gD=e=>{let t=new Set;for(let n of e)hD(n)&&n.messageId&&t.add(n.messageId);return[...t]},_D=(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}),vD=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=tc(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},yD=e=>e,bD=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},xD=e=>{let t=e.part.state,n=t?.input,r=t?.metadata,i=n?.filePath||n?.file_path||n?.path||r?.filePath||r?.file_path||r?.path;return typeof i==`string`&&i.trim().length>0?i:null},SD=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},CD=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},wD=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=CD(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`}`},TD=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=wD(n.todos);if(e)return e}if(Array.isArray(r)){let e=wD(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=wD(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=wD(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=wD(e.todos);if(t)return t}}catch{}return null},ED=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)},DD=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(Xx,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,pD),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`,pD),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)(Xx,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},OD=e=>{let t=yo(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},kD=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 iD(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`?TD(e):bD(e)},AD=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}},jD=Z.memo(e=>{let t=(0,Q.c)(16),{activity:n,isExpanded:r,isMobile:i,onToggleTool:a,onShowPopup:o,onContentChange:s}=e,c;t[0]!==n.id||t[1]!==a?(c=()=>{a(n.id)},t[0]=n.id,t[1]=a,t[2]=c):c=t[2];let l=J(c),u;t[3]===i?u=t[4]:(u=lm(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)(aT,{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&&RS([e.activity.part],[t.activity.part])),MD=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=lm(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(FD,{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&&PD(e.activities,t.activities)),ND=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!Qr(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(WC(i)){let r=$E(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:ZE(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(GC(i)){let r=nD(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(HC(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(VC(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(UC(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},PD=(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||!RS([r.part],[i.part]))return!1}return!0},FD=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=ot(),c=s(zD),l=rc(n,o),u;t[0]===n?u=t[1]:(u=Zx(n),t[0]=n,t[1]=u);let d=u,f;t[2]===n?f=t[3]:(f=n.toLowerCase(),t[2]=n,t[3]=f);let p=f===`read`,m=Z.useContext(Oo),h=Qh(),g=we(BD),_=Nh(),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=Fi(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(VD)),t[10]=w,t[11]=T);let E=T,D=r[0]??null,O=!D||qC(D.part),k;t[12]===D?k=t[13]:(k=D?kD(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||SD(D);if(!e||e===`<built-in>`){j=null;break bb0}let r=OD(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=xD(D);if(!e){N=null;break bb1}let n=_o(e,v);if(!n){N=null;break bb1}let r;t[26]===D?r=t[27]:(r=ED(D),t[26]=D,t[27]=r);let i;t[28]!==n||t[29]!==e||t[30]!==r?(i={path:e,displayPath:n,offset:r},t[28]=n,t[29]=e,t[30]=r,t[31]=i):i=t[31],N=i}t[22]=v,t[23]=p,t[24]=D,t[25]=N}else N=t[25];let P=N,F;t[32]!==v||t[33]!==h||t[34]!==m?(F=(e,t)=>{if(!v)return;let n=vo(v,e);if(!n)return;if(h){h.openFile({path:n,targetLine:t&&Number.isFinite(t)?Math.max(1,Math.trunc(t)):void 0});return}if(m?.editor){m.editor.openFile(n,t);return}if(!So(n,v)){lc(n,v).then(()=>{let e=s.getState(),r=v||go(v,n);if(t&&Number.isFinite(t)){e.openContextFileAtLine(r,n,Math.max(1,Math.trunc(t)),1);return}e.openContextFile(r,n)});return}let r=s.getState(),i=go(v,n);if(t&&Number.isFinite(t)){r.openContextFileAtLine(i,n,Math.max(1,Math.trunc(t)),1);return}r.openContextFile(i,n)},t[32]=v,t[33]=h,t[34]=m,t[35]=F):F=t[35];let I=J(F),L;t[36]!==v||t[37]!==h?(L=e=>{let t=yo(e);if(!t)return;let n=()=>{if(h){h.openFile({path:t});return}let e=s.getState(),n=v||go(``,t);e.openContextFile(n,t)};if(v&&!So(t,v)){lc(t,v).then(n);return}n()},t[36]=v,t[37]=h,t[38]=L):L=t[38];let R=J(L),z;t[39]===n?z=t[40]:(z=n.toLowerCase(),t[39]=n,t[40]=z);let B=z,V=B===`grep`||B===`search`||B===`find`||B===`ripgrep`||B===`glob`,H=B===`webfetch`||B===`fetch`||B===`curl`||B===`wget`,U=B===`skill`,W=!!(P||M),ee=!!(P&&v||M),G;t[41]!==ee||t[42]!==I||t[43]!==R||t[44]!==W||t[45]!==P||t[46]!==M?(G=()=>{if(!(!W||!ee)){if(P){I(P.path,P.offset);return}M&&R(M.path)}},t[41]=ee,t[42]=I,t[43]=R,t[44]=W,t[45]=P,t[46]=M,t[47]=G):G=t[47];let K=J(G),q;t[48]===K?q=t[49]:(q=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),K())},t[48]=K,t[49]=q);let te=J(q),ne=W&&ee&&`cursor-pointer`,re=W&&!ee&&`cursor-default opacity-70`,ie;t[50]!==ne||t[51]!==re?(ie=Y(`flex w-full items-center gap-x-1.5 min-w-0`,um,ne,re),t[50]=ne,t[51]=re,t[52]=ie):ie=t[52];let ae=W?`soft`:void 0,oe=W?K:void 0,se=W?te:void 0,ce=W?`button`:void 0,le=W&&ee?0:void 0,ue=W&&!ee?!0:void 0,de=i?`size-4`:`size-3.5`,fe;t[53]===de?fe=t[54]:(fe=Y(`inline-flex items-center justify-center flex-shrink-0`,de),t[53]=de,t[54]=fe);let pe;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(pe={color:`var(--tools-icon)`},t[55]=pe):pe=t[55];let me=O?(0,$.jsx)(MC,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:l})}):d,he;t[56]!==fe||t[57]!==pe||t[58]!==me?(he=(0,$.jsx)(`div`,{className:fe,style:pe,children:me}),t[56]=fe,t[57]=pe,t[58]=me,t[59]=he):he=t[59];let ge,_e;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(ge=Y(fD,`inline-flex items-center flex-shrink-0 opacity-85`),_e={color:`var(--tools-title)`},t[60]=ge,t[61]=_e):(ge=t[60],_e=t[61]);let ve;t[62]===l?ve=t[63]:(ve=(0,$.jsx)(`span`,{className:ge,style:_e,title:l,children:l}),t[62]=l,t[63]=ve);let ye;t[64]!==a||t[65]!==p||t[66]!==P||t[67]!==c?(ye=p&&P?(0,$.jsxs)(`span`,{className:Y(`inline-flex !min-h-0 items-center justify-start gap-1 min-w-0 flex-1 text-left`,pD),style:{color:`var(--tools-description)`},title:P.offset?`${P.displayPath}:${P.offset}`:P.displayPath,children:[c?(0,$.jsx)(hd,{filePath:P.path,className:`h-3.5 w-3.5`}):null,DD(P.displayPath,a)]}):null,t[64]=a,t[65]=p,t[66]=P,t[67]=c,t[68]=ye):ye=t[68];let be;t[69]!==a||t[70]!==A||t[71]!==V?(be=V&&A?(0,$.jsx)(`span`,{className:`inline-flex min-w-0 flex-1`,children:(0,$.jsxs)(Xx,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,pD),style:{color:`var(--tools-description)`},title:A,children:[`"`,A,`"`]})}):null,t[69]=a,t[70]=A,t[71]=V,t[72]=be):be=t[72];let xe;t[73]!==A||t[74]!==H?(xe=H&&A?(0,$.jsxs)(`a`,{href:A,target:`_blank`,rel:`noopener noreferrer`,onClick:HD,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`,pD),style:{color:`var(--status-info)`},title:A,children:[(0,$.jsx)(vD,{href:A}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:A})]}):null,t[73]=A,t[74]=H,t[75]=xe):xe=t[75];let Se;t[76]!==U||t[77]!==M?(Se=U&&M?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,pD),style:{color:`var(--tools-description)`},title:M.path,children:M.name}):null,t[76]=U,t[77]=M,t[78]=Se):Se=t[78];let Ce;t[79]!==A||t[80]!==U||t[81]!==M?(Ce=U&&!M&&A?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,pD),style:{color:`var(--tools-description)`},title:A,children:A}):null,t[79]=A,t[80]=U,t[81]=M,t[82]=Ce):Ce=t[82];let Te;t[83]!==a||t[84]!==A||t[85]!==H||t[86]!==p||t[87]!==V||t[88]!==U?(Te=!p&&!V&&!H&&!U&&A?(0,$.jsx)(Xx,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,pD),style:{color:`var(--tools-description)`},children:A}):null,t[83]=a,t[84]=A,t[85]=H,t[86]=p,t[87]=V,t[88]=U,t[89]=Te):Te=t[89];let Ee;return t[90]!==ie||t[91]!==ae||t[92]!==oe||t[93]!==se||t[94]!==ce||t[95]!==le||t[96]!==ue||t[97]!==he||t[98]!==ve||t[99]!==ye||t[100]!==be||t[101]!==xe||t[102]!==Se||t[103]!==Ce||t[104]!==Te?(Ee=(0,$.jsxs)(`div`,{className:ie,"data-mobile-press-feedback":ae,onClick:oe,onKeyDown:se,role:ce,tabIndex:le,"aria-disabled":ue,children:[he,ve,ye,be,xe,Se,Ce,Te]}),t[90]=ie,t[91]=ae,t[92]=oe,t[93]=se,t[94]=ce,t[95]=le,t[96]=ue,t[97]=he,t[98]=ve,t[99]=ye,t[100]=be,t[101]=xe,t[102]=Se,t[103]=Ce,t[104]=Te,t[105]=Ee):Ee=t[105],Ee},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&PD(e.activities,t.activities)),ID=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)(LT,{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}),LD=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)(cD,{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}),RD=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(),_=cc()??``,v=Z.useMemo(()=>gD(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?uD(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(()=>AD(e),[e]),M=T?j.active:j.all,N=M.slice(0,c?2:3),P=J((e=!1,n=!1)=>{if(!(!_||!v.length)){for(let r of v){let i=t.find(e=>e.messageId===r)?.part.sessionID;if(!i)continue;let a=Pn(_,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=Rn(_,i,r,{priority:n?`background`:`user`}).catch(()=>{x.current.add(r)}).finally(()=>{b.current.delete(r),S(e=>e+1)});b.current.set(r,o)}S(e=>e+1)}}),F=J(e=>{e.stopPropagation(),P(!0)}),I=T,L=I||n,R=J(()=>{if(I)return;let e=C.current;w.current=e?{top:e.getBoundingClientRect().top,scrollContainer:e.closest(`[data-scrollbar="chat"]`)}:null,L||P(),s()});Z.useEffect(()=>{T||!L||P(!1,!0)},[T,L]),Z.useLayoutEffect(()=>{let e=w.current,t=C.current;if(!e||!t)return;let n=()=>{if(!t.isConnected)return;let n=t.getBoundingClientRect().top-e.top;if(!(Math.abs(n)<.5)){if(e.scrollContainer?.isConnected){e.scrollContainer.scrollTop+=n;return}window.scrollBy(0,n)}};if(n(),typeof window>`u`||typeof window.requestAnimationFrame!=`function`){w.current=null;return}let r=window.requestAnimationFrame(()=>{n(),w.current=null});return()=>window.cancelAnimationFrame(r)},[L]);let z=m&&!L?Math.max(0,Math.floor(r)):0,B=!m||L||z>0,V=y.current,H=[...V].map(e=>{if(b.current.has(e))return`loading`;if(x.current.has(e))return`error`;let n=t.find(t=>t.messageId===e)?.part.sessionID??``;return Pn(_,n,e).status}),U=H.includes(`loading`),W=H.includes(`error`),ee=H.length>0&&H.every(e=>e===`ready`),G=t.some(e=>V.has(e.messageId)&&hD(e)),K=ee&&!G&&!_D(t,V),q=Z.useMemo(()=>B?yD(e):mD,[e,B]),te=Z.useMemo(()=>B?ND(q):[],[B,q]),ne=Z.useMemo(()=>L||z===0?0:Math.max(0,te.length-z),[L,z,te.length]),re=Z.useMemo(()=>L||z===0?te:te.slice(-z),[L,z,te]);if((!m||I&&!O)&&te.length===0)return null;let ie=(e,t)=>{let n=(0,$.jsx)(`div`,{className:lm(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},ae=B?re.map((e,t)=>{switch(e.type){case`reasoning`:return ie(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(ID,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return ie(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(LD,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(jD,{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)(MD,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(tD,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(FD,{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)(sD,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(FD,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(jD,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,oe=re.length>0;return m?(0,$.jsxs)(`div`,{className:lm(c),children:[(0,$.jsxs)(`button`,{ref:C,type:`button`,className:Y(`group/tool flex w-full min-w-0 flex-nowrap items-center text-left`,c?`gap-x-1`:`gap-x-2`,!I&&um,I&&`oc-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-default`,c&&`pr-0`),"data-mobile-press-feedback":I?void 0:`soft`,onClick:I?void 0:R,"aria-expanded":L,"aria-disabled":I||void 0,"aria-label":I?A:g(L?`chat.activity.collapseAria`:`chat.activity.expandAria`),children:[(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 flex-1 items-center overflow-clip`,c?`gap-x-1`:`gap-x-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,c?`h-5 w-4`:`h-6 w-3.5`),style:{color:`var(--tools-icon)`},children:T&&!O?(0,$.jsx)(MC,{isMobile:c,label:A,className:`block`}):(0,$.jsx)(X,{name:k,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:Y(`inline-flex flex-shrink-0 items-center`,c?`typography-meta h-5`:`typography-ui-label h-5 font-semibold`,T?`animate-text-shimmer text-[var(--status-info)] [--oc-text-shimmer-base:var(--status-info)]`:`text-foreground/85`),children:A}),E?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 tabular-nums text-muted-foreground`,children:E}):null]}),(0,$.jsxs)(`span`,{className:Y(`ml-auto inline-flex max-w-[min(14rem,55%)] shrink-0 items-center justify-end`,c?`gap-0.5`:`gap-1`),children:[M.length>0?(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center text-muted-foreground`,c?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5`,"aria-hidden":`true`,children:N.map((e,t)=>(0,$.jsx)(sa,{name:e,size:c?12:14,className:Y(`flex-none`,c?`size-3 min-h-3 min-w-3 max-h-3 max-w-3`:`size-3.5 min-h-3.5 min-w-3.5 max-h-3.5 max-w-3.5`)},`${e}-${t}`))}),(0,$.jsx)(`span`,{className:`typography-meta min-w-0 truncate`,children:g(T?`chat.activity.agentsWorking`:`chat.activity.agentsInvolved`,{count:M.length})})]}):null,I?null:(0,$.jsx)(X,{name:L?`arrow-down-s`:`arrow-right-s`,className:Y(`flex-shrink-0 text-muted-foreground opacity-70`,c&&`-mr-0.5`,c?`size-3`:`size-3.5`)})]})]}),oe?(0,$.jsxs)(`div`,{className:I?void 0:`relative ml-2 pl-3`,children:[I?null:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-px bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),ne>0?(0,$.jsxs)(`button`,{type:`button`,onClick:R,className:`typography-meta leading-4 px-2 py-1 text-muted-foreground/45 hover:text-muted-foreground/65 text-left`,children:[`+`,ne,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:ae})]}):null,L&&(U||W||K)?(0,$.jsx)(`div`,{className:Y(`typography-meta flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,I?void 0:`ml-5`,W&&`text-[var(--status-error)]`),role:W?`alert`:`status`,children:U?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{children:g(`chat.activity.outputLoading`)})]}):W?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:g(`chat.activity.outputLoadFailed`)}),(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`xs`,onClick:F,children:g(`chat.activity.outputRetry`)})]}):(0,$.jsx)(`span`,{children:g(`chat.toolOutputDialog.noOutputProduced`)})}):null]}):(0,$.jsx)(`div`,{className:lm(c),children:ae})});function zD(e){return e.showToolFileIcons}function BD(e){return e.currentDirectory}function VD(e){return[e.name,e]}function HD(e){e.stopPropagation()}var UD=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(RD,{...e}),t[0]=e,t[1]=n),n}),WD={contain:`layout`},GD={containerType:`inline-size`,containerName:`message-footer`},KD=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,qD=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,JD=`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`,YD=`size-3.5!`,XD=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,ZD=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,QD=`flex items-center gap-2`,$D=`flex items-center gap-2 text-muted-foreground`,eO=`inline-flex h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,tO=`size-3.5!`,nO=`medium`,rO=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,iO=`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)]`,aO=`h-7 gap-1.5`,oO=`h-6 gap-1`,sO=`text-[11px] leading-none`,cO=`size-3.5`,lO=`size-3`,uO=5,dO=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)(hd,{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=rO(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}),fO=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=ot(),s;t[0]!==n.file||t[1]!==a?(s=()=>{a(n.file)},t[0]=n.file,t[1]=a,t[2]=s):s=t[2];let c=J(s),l=!r,u=i?oO:aO,d;t[3]===u?d=t[4]:(d=Y(iO,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)(dO,{file:n,isMobile:i}),t[8]=n,t[9]=i,t[10]=p):p=t[10];let m;return t[11]!==n.file||t[12]!==c||t[13]!==l||t[14]!==d||t[15]!==f||t[16]!==p?(m=(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`xs`,disabled:l,"data-turn-change-file":`true`,className:d,"aria-label":f,title:n.file,onClick:c,children:p}),t[11]=n.file,t[12]=c,t[13]=l,t[14]=d,t[15]=f,t[16]=p,t[17]=m):m=t[17],m}),pO=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:c}=ot(),l=cc(),u=Nh(),d=u.directory||l,f=u.sessionId,p=Qh(),m=s(DO),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,uO),t[2]=g,t[3]=_);let v=_,y=Math.max(0,g.length-v.length),b=g.length>0?g.length:n,x=!!(p||!o&&d||o&&a),S;t[4]!==b||t[5]!==c?(S=c(b===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:b}),t[4]=b,t[5]=c,t[6]=S):S=t[6];let C=S,w;t[7]!==y||t[8]!==c?(w=c(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[7]=y,t[8]=c,t[9]=w):w=t[9];let T=w,E=Y(iO,o?oO:aO),D=o?lO:cO,O;t[10]===o?O=t[11]:(O=o?Y(sO,`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(sO,`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(sO,`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){BT({directory:d,filePath:e,turnMessageId:i,sessionId:f});return}o&&a&&d&&BT({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[16]=d,t[17]=f,t[18]=a,t[19]=o,t[20]=p,t[21]=i,t[22]=P):P=t[22];let F=J(P),I;t[23]!==d||t[24]!==f||t[25]!==a||t[26]!==o||t[27]!==p||t[28]!==m||t[29]!==i||t[30]!==v[0]?.file?(I=()=>{if(p){p.openTurnDiff(i,f);return}if(!o&&d){m(d,{mode:`diff`,dedupeKey:`turn-diff:${f||`session`}:${i}`,targetPath:null,diffScope:`turn`,diffTurnMessageId:i,diffSessionId:f});return}let e=v[0]?.file;e&&o&&a&&d&&BT({directory:d,filePath:e,turnMessageId:i,sessionId:f,mobile:!0})},t[23]=d,t[24]=f,t[25]=a,t[26]=o,t[27]=p,t[28]=m,t[29]=i,t[30]=v[0]?.file,t[31]=I):I=t[31];let L=J(I),R=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,z;t[32]===R?z=t[33]:(z=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,R),t[32]=R,t[33]=z);let B=Y(E,`max-w-full text-muted-foreground hover:text-foreground`),V;t[34]===c?V=t[35]:(V=c(`diffView.actions.reviewAria`),t[34]=c,t[35]=V);let H;t[36]===c?H=t[37]:(H=c(`diffView.actions.reviewAria`),t[36]=c,t[37]=H);let U;t[38]===D?U=t[39]:(U=(0,$.jsx)(X,{name:`file-edit`,className:D}),t[38]=D,t[39]=U);let W=`turn-changes-${i}`,ee;t[40]===c?ee=t[41]:(ee=c(`chat.changedFiles.title`),t[40]=c,t[41]=ee);let G;t[42]!==W||t[43]!==ee||t[44]!==k?(G=(0,$.jsx)(`span`,{id:W,className:k,children:ee}),t[42]=W,t[43]=ee,t[44]=k,t[45]=G):G=t[45];let K;t[46]!==C||t[47]!==j?(K=(0,$.jsx)(`span`,{className:j,children:C}),t[46]=C,t[47]=j,t[48]=K):K=t[48];let q;t[49]===D?q=t[50]:(q=Y(D,`opacity-60`),t[49]=D,t[50]=q);let te;return t[51]===q?te=t[52]:(te=(0,$.jsx)(X,{name:`arrow-right-s`,className:q}),t[51]=q,t[52]=te),(0,$.jsxs)(`section`,{className:z,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(ca,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,onClick:L,className:B,"aria-label":V,title:H,children:[U,G,K,te]}),v.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[v.map(e=>(0,$.jsx)(fO,{file:e,canOpen:x,isMobile:o,onOpen:F},e.file)),y>0?(0,$.jsxs)(ca,{type:`button`,variant:`ghost`,size:`xs`,disabled:!x,className:Y(E,`text-muted-foreground hover:text-foreground`),onClick:L,"aria-label":c(`diffView.actions.reviewAria`),title:c(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(D,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:N,children:[`+`,T]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:D})]}):null]}):null]})}),mO=e=>e.type===`subtask`,hO=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},gO=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}`},_O=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=cc(),{isMobile:o}=fo(),c=ni(OO),l=s(kO),u=Nh(),{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=gO(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(AO),children:f(r?`chat.messageBody.subtask.hidePrompt`:`chat.messageBody.subtask.showPrompt`)}),r?(0,$.jsx)(`pre`,{className:`typography-meta mt-1.5 overflow-x-auto whitespace-pre-wrap break-words text-foreground/85`,children:b}):null]}):null,t[29]=r,t[30]=b,t[31]=T,t[32]=f,t[33]=N):N=t[33];let P;t[34]!==v||t[35]!==m||t[36]!==a||t[37]!==o||t[38]!==l||t[39]!==u||t[40]!==c||t[41]!==f||t[42]!==S?(P=S&&u.capabilities.navigateNestedSession?(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>{let e=u.directory||a;e&&Fh(u,S,e,()=>{if(!ui({sessionId:S,directory:e})){if(cl()||o||d()){c(S,e);return}l(e,{mode:`chat`,dedupeKey:`session:${S}`,label:m||v||f(`contextPanel.mode.chat`),readOnly:!0})}})},children:f(`chat.messageBody.subtask.openSession`)})}):null,t[34]=v,t[35]=m,t[36]=a,t[37]=o,t[38]=l,t[39]=u,t[40]=c,t[41]=f,t[42]=S,t[43]=P):P=t[43];let F;return t[44]!==j||t[45]!==M||t[46]!==N||t[47]!==P?(F=(0,$.jsxs)(`div`,{className:`mt-2`,children:[j,M,N,P]}),t[44]=j,t[45]=M,t[46]=N,t[47]=P,t[48]=F):F=t[48],F},vO=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=cc(),i=s(jO),{isMobile:a}=fo(),{t:o}=ot(),c;t[0]!==r||t[1]!==a?(c=r&&!a&&!d(),t[0]=r,t[1]=a,t[2]=c):c=t[2];let l=!!c,u;t[3]!==n.state||t[4]!==o?(u=n.state===`completed`?o(`chat.messageBody.subagent.completed`):n.state===`error`?o(`chat.messageBody.subagent.error`):o(`chat.messageBody.subagent.cancelled`),t[3]=n.state,t[4]=o,t[5]=u):u=t[5];let f=u,p=n.state===`completed`?o(`chat.messageBody.subagent.completedDescription`):n.state===`error`?o(`chat.messageBody.subagent.errorDescription`):o(`chat.messageBody.subagent.cancelledDescription`),m=n.description||p,h=J(()=>{!l||!r||i(r,{mode:`chat`,dedupeKey:`session:${n.sessionID}`,label:m,readOnly:!0})}),g;t[6]===h?g=t[7]:(g=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())},t[6]=h,t[7]=g);let _=J(g),v=l&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,y;t[8]===v?y=t[9]:(y=Y(`mt-2 flex min-w-0 gap-2.5 rounded-[var(--radius-lg)] border border-border/60 bg-muted/20 px-3 py-2.5`,v),t[8]=v,t[9]=y);let b=l?`button`:void 0,x=l?0:void 0,S=l?o(`chat.messageBody.subagent.openSession`,{label:m}):void 0,C=l?h:void 0,w=l?_:void 0,T;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(`span`,{className:`mt-0.5 flex size-6 flex-shrink-0 items-center justify-center rounded-md bg-foreground/5 text-muted-foreground`,children:(0,$.jsx)(X,{name:`robot-2`,className:`size-3.5`})}),t[10]=T):T=t[10];let E;t[11]===m?E=t[12]:(E=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:m}),t[11]=m,t[12]=E);let D=n.state===`completed`?`bg-[var(--status-success-background)] text-[var(--status-success)]`:n.state===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`,O;t[13]===D?O=t[14]:(O=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,D),t[13]=D,t[14]=O);let k;t[15]!==f||t[16]!==O?(k=(0,$.jsx)(`span`,{className:O,children:f}),t[15]=f,t[16]=O,t[17]=k):k=t[17];let A;t[18]!==E||t[19]!==k?(A=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[E,k]}),t[18]=E,t[19]=k,t[20]=A):A=t[20];let j;t[21]===n.body?j=t[22]:(j=n.body?(0,$.jsx)(`div`,{className:`typography-meta mt-1 max-h-16 overflow-hidden text-muted-foreground [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,children:(0,$.jsx)(Os,{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},yO={background:`transparent`,backgroundColor:`transparent`},bO=e=>{let t=(0,Q.c)(36),{part:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=Z.useRef(null),{t:c}=ot(),l;t[0]===n.shellAction?l=t[1]:(l=typeof n.shellAction?.command==`string`?n.shellAction.command.trim():``,t[0]=n.shellAction,t[1]=l);let u=l,d=typeof n.shellAction?.output==`string`?n.shellAction.output:``,f;t[2]===n.shellAction?f=t[3]:(f=typeof n.shellAction?.status==`string`?n.shellAction.status.trim().toLowerCase():``,t[2]=n.shellAction,t[3]=f);let p=f,m;t[4]===d?m=t[5]:(m=d.trim(),t[4]=d,t[5]=m);let h=m.length>0,g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{s.current!==null&&typeof window<`u`&&(window.clearTimeout(s.current),s.current=null)},t[6]=g):g=t[6];let _=J(g),v,y;t[7]===_?(v=t[8],y=t[9]):(v=()=>()=>{_()},y=[_],t[7]=_,t[8]=v,t[9]=y),Z.useEffect(v,y);let b;t[10]!==_||t[11]!==h||t[12]!==d?(b=async()=>{h&&(await ct(d)).ok&&(_(),o(!0),typeof window<`u`&&(s.current=window.setTimeout(()=>{o(!1),s.current=null},2e3)))},t[10]=_,t[11]=h,t[12]=d,t[13]=b):b=t[13];let x=J(b),S;t[14]===c?S=t[15]:(S=c(`chat.messageBody.shellCommand.title`),t[14]=c,t[15]=S);let C;t[16]===S?C=t[17]:(C=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:S}),t[16]=S,t[17]=C);let w;t[18]===p?w=t[19]:(w=p?(0,$.jsx)(`span`,{className:Y(`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none`,p===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`),children:p}):null,t[18]=p,t[19]=w);let T;t[20]!==w||t[21]!==C?(T=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[C,w]}),t[20]=w,t[21]=C,t[22]=T):T=t[22];let E;t[23]===u?E=t[24]:(E=u?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 overflow-x-auto font-mono`,children:(0,$.jsx)(Ac,{language:`bash`,code:u,codeStyle:yO,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(MO),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)(Ac,{language:`bash`,code:d,codeStyle:yO,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},xO=e=>{let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},SO=(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}},CO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:c,hasTextContent:l,onCopyMessage:u,copiedMessage:d,onShowPopup:f,agentMention:p,onEdit:m,onRevert:h,onFork:g,pendingMessageAction:_,editing:v,editStaged:y,onCancelEdit:b,userActionsMode:x=`inline`,stickyUserHeaderEnabled:S=!0})=>{let{locale:C,t:w}=ot(),T=bg(),E=Ph(Nh()),D=s(e=>e.timeFormatPreference),[O,k]=Z.useState(!1),A=Z.useRef(null),j=Z.useMemo(()=>n.filter(e=>e.type===`text`?!qr(e):!!(mO(e)||hO(e))),[n]),M=Z.useMemo(()=>j.map(e=>en(e)?_S(Qr(e)):void 0),[j]),N=p?.token,P=!1,F=!!u,I=!!d,L=!!(c??a),R=!!l,z=x!==`external-actions`,B=x!==`external-content`,V=S&&x===`inline`,H=J(()=>{A.current!==null&&typeof window<`u`&&(window.clearTimeout(A.current),A.current=null)}),U=J(()=>{!L||!F||!R||typeof window>`u`||(H(),k(!0),A.current=window.setTimeout(()=>{k(!1),A.current=null},1800))});Z.useEffect(()=>{R||(k(!1),H())},[H,R]);let W=J(e=>{!u||!R||(e.stopPropagation(),e.preventDefault(),u(),L&&U())}),ee=T===`mini-chat`||!E.fork?void 0:g,G=Z.useMemo(()=>{if(typeof i!=`number`||i<=0)return null;let e=RE(i,D);return e.length>0?e:null},[C,i,D]),K=Y(`group/user-actions`,a?x===`inline`?`flex items-center justify-end pt-2 pb-3`:S?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:x===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),q=!v&&y&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsxs)(`div`,{className:Y(QD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(eO,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:nO,name:`edit`,className:tO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:w(`chat.messageBody.actions.editStaged`)})]}),b?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:JD,"aria-label":w(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),b()},children:(0,$.jsx)(X,{weight:nO,name:`close`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,te=(v&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsx)(`div`,{className:Y(QD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(eO,`animate-text-shimmer`),"aria-live":`polite`,children:w(`chat.messageBody.actions.editing`)})})}):null)??q??((F&&R||m||h||ee)&&B?(0,$.jsx)(`div`,{className:K,children:(0,$.jsxs)(`div`,{className:Y(QD,`justify-end`,!a&&x===`inline`&&`translate-x-5`,o?`pointer-events-auto opacity-100`:`pointer-events-none opacity-0 transition-opacity duration-150 group-hover/message:pointer-events-auto group-hover/message:opacity-100 group-hover/user-actions:pointer-events-auto group-hover/user-actions:opacity-100 group-hover/user-shell:pointer-events-auto group-hover/user-shell:opacity-100`),"data-message-action-group":`true`,children:[G?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(eO,`mr-1`),"aria-label":`Message time: ${G}`,children:[(0,$.jsx)(X,{weight:nO,name:`time`,className:tO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:G})]})}),(0,$.jsx)(La,{children:G})]}):null,h&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:JD,"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:nO,name:_===`revert`?`loader-4`:`arrow-go-back`,className:Y(YD,_===`revert`&&`animate-spin`)})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.revert`)})]}),m&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:JD,"aria-label":w(`chat.messageBody.actions.editAria`),disabled:!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:nO,name:`edit`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.edit`)})]}),ee&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:JD,"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:nO,name:_===`fork`?`loader-4`:`git-branch`,className:Y(YD,_===`fork`&&`animate-spin`)})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.fork`)})]}),F&&R&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":O||I?`true`:void 0,className:JD,"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:nO,name:`check`,className:Y(YD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:nO,name:`file-copy`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:w(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return z?(0,$.jsxs)(`div`,{className:`relative w-full group/message`,style:WD,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(mO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(_O,{part:e})},e.id??`user-subtask-${i}`);if(hO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(bO,{part:e})},e.id??`user-shell-${i}`);let o=M[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(vO,{notification:o})},e.id??`subagent-notification-${i}`);let s;return p&&N&&!P&&Qr(e).includes(N)&&(s=p,P=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(Jx,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(Vd,{files:n,messageID:t,sessionID:e,onShowPopup:f,compact:!0}),te]}):(0,$.jsx)($.Fragment,{children:te})}),wO=Z.memo(({hasCopyableText:e,isTouchContext:t,onCopyMessage:n,reviewTransferAction:r,ttsText:i,sessionId:a})=>{let{t:o}=ot(),s=bg(),c=Nh(),l=Ph(c),{isPlaying:u,play:d,stop:f}=vE(),p=br(e=>e.showMessageTTSButtons),m=br(e=>e.voiceProvider),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),[y,b]=Z.useState(!1),x=Z.useRef(null),S=Z.useRef(null),C=!!n,w=!!((c.sessionId||a)&&c.directory&&l.openSourceSession&&s!==`mini-chat`),T=J(()=>{x.current!==null&&typeof window<`u`&&(window.clearTimeout(x.current),x.current=null)}),E=J(()=>{S.current!==null&&typeof window<`u`&&(window.clearTimeout(S.current),S.current=null)});Z.useEffect(()=>()=>{T(),E()},[E,T]),Z.useEffect(()=>{(!e||!C)&&(g(!1),v(!1),T(),E())},[C,E,T,e]);let D=J(()=>{!t||!C||!e||typeof window>`u`||(T(),g(!0),x.current=window.setTimeout(()=>{g(!1),x.current=null},1800))}),O=J(async r=>{!n||!e||(r.stopPropagation(),r.preventDefault(),await n()!==!1&&(E(),v(!0),typeof window<`u`&&(S.current=window.setTimeout(()=>{v(!1),S.current=null},2e3)),t&&D()))}),k=J(async t=>{if(t.stopPropagation(),t.preventDefault(),!(!r||y||!e)){b(!0);try{await r.onClick()}finally{b(!1)}}}),A=J(e=>{e.stopPropagation(),e.preventDefault();let t=c.sessionId||a;!t||!c.directory||!c.openSourceSession||c.openSourceSession(t,c.directory)}),j=Z.useMemo(()=>u?o(`chat.messageBody.tts.stopSpeaking`):o(`chat.messageBody.tts.readAloudWithProvider`,{provider:m===`browser`?`Browser`:m===`openai`?`OpenAI`:m===`openai-compatible`?`Custom`:`Say`}),[u,o,m]),M=J(e=>{if(e.stopPropagation(),e.preventDefault(),u){f();return}i.trim()&&d(i)});return(0,$.jsxs)($.Fragment,{children:[n&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":h||_?`true`:void 0,className:Y(JD,!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:nO,name:`check`,className:Y(YD,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:nO,name:`file-copy`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:o(`chat.messageBody.actions.copyAnswer`)})]}),w?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:JD,"aria-label":o(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:A,children:(0,$.jsx)(X,{weight:nO,name:`target`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:o(`chat.messageBody.actions.openSourceSession`)})]}):null,r&&s!==`mini-chat`&&l.reviewTransfer?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,size:`icon`,variant:`ghost`,disabled:y||!e,className:Y(JD,(!e||y)&&`opacity-50`),"aria-label":r.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{k(e)},children:y?(0,$.jsx)(X,{weight:nO,name:`loader-4`,className:Y(YD,`animate-spin`)}):(0,$.jsx)(X,{weight:nO,name:`arrow-left-right`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:r.tooltip})]}):null,s!==`mini-chat`&&p&&e&&(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:Y(JD,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:nO,name:`stop`,className:YD}):(0,$.jsx)(X,{weight:nO,name:`volume-up`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:j})]})]})}),TO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:c,messageTokens:l,isMobile:u,alwaysShowActions:f,hasTouchInput:p,expandedTools:m,onToggleTool:h,onShowPopup:g,streamPhase:_,allowAnimation:v,onContentChange:y,hasTextContent:b=!1,onCopyMessage:x,onAuxiliaryContentComplete:S,showReasoningTraces:C=!1,turnGroupingContext:w,errorMessage:T,errorVariant:E=`error`,reviewTransferDirection:D=null})=>{let{t:O,locale:k}=ot(),A=bg(),j=Ph(Nh()),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?ZD:XD,B=!i,V=Z.useMemo(()=>n.filter(e=>!qr(e)).filter(e=>e.type!==`compaction`),[n]),H=Z.useMemo(()=>V.filter(e=>e.type===`tool`),[V]),U=Z.useMemo(()=>V.filter(e=>e.type===`text`),[V]),W=Z.useMemo(()=>Qn(U),[U]),ee=s(e=>e.openContextPreview),G=d(),K=A===`mini-chat`,q=Z.useMemo(()=>{if(G||u||K)return null;for(let e of U){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=nc(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=nc(n.replace(/\x1b\[[0-9;]*m/g,``))[0];if(r)return r.includes(`0.0.0.0`)?r.replace(`0.0.0.0`,`127.0.0.1`):r}return null},[U,u,K,G,H]),te=ni(e=>e.forkFromMessage),ne=ni(e=>e.forkTransition),re=ni(e=>e.currentSessionId),ie=ni(e=>e.getDirectoryForSession),ae=cc(),oe=D===`review-to-original`,se=!u&&!G?D:null,ce=Z.useMemo(()=>{let t=W.trim();if(!(!e||!ae||!t||!se))return se===`review-to-original`?{ariaLabel:O(`chat.messageBody.actions.sendReviewFeedback`),tooltip:O(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await Lt(e,ae,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:O(`chat.messageBody.actions.sendImplementationResponse`),tooltip:O(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await wn(e,ae,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[W,ae,se,e,O]),[le,ue]=Z.useState(!1),de=s(e=>e.chatRenderMode),fe=s(e=>e.collapsibleThinkingBlocks),pe=s(e=>e.showSplitAssistantMessageActions),me=s(e=>e.showAssistantTps),he=s(e=>e.timeFormatPreference),ge=de===`sorted`,_e=w?.isLastAssistantInTurn??!1,ve=a===`stop`,ye=(ve||i||!!T)&&(w?.isTurnSettled??!0),be=ve?`completed`:M,xe=H.length>0,Se=Z.useMemo(()=>H.some(e=>qC(e)),[H]),Ce=qC,we=KC,Te=I.current.experiencedStreamingOrCooldown,Ee=Z.useRef({messageId:t,initialized:!1,observedPartIds:new Set});Z.useEffect(()=>{if(Ee.current.messageId!==t&&(Ee.current={messageId:t,initialized:!1,observedPartIds:new Set}),!Te||!gt())return;let n=Ee.current,r=!n.initialized;n.initialized=!0;for(let i of H){if(n.observedPartIds.has(i.id))continue;if(!Jr(r,Ce(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),bn({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[Te,Ce,t,e,H]);let De=Z.useMemo(()=>H.length===0||!Se&&H.every(e=>we(e)),[H,Se,we]),Oe=Z.useMemo(()=>V.filter(e=>e.type===`reasoning`),[V]),ke=Z.useMemo(()=>Oe.length===0||Oe.every(e=>typeof e.time?.end==`number`),[Oe]),Ae=typeof a!=`string`,je=Oe.length>0&&xe&&(Se||Ae||!De),Me=B||xe&&(Se||Ae||!De),Ne=B||je,Pe=xe||Oe.length>0,Fe=U.length===0,Ie=Pe&&Fe&&!Me&&!Ne&&De&&ke,Le=Z.useRef(!1),Re=Z.useRef(!1);Z.useEffect(()=>{Re.current=!1},[t]),Z.useEffect(()=>{if(!Ie){Le.current=!1;return}Le.current||(Le.current=!0,S?.())},[Ie,S]),Z.useEffect(()=>{if(B){Re.current=!1;return}if(xe){Re.current=!1;return}Oe.length!==0&&(Ne||!ke||Re.current||(Re.current=!0,y?.(`structural`)))},[B,xe,y,ke,Oe.length,Ne]);let ze=!!b&&!B,Be=J(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||le||ne)){ue(!0);try{await te(e,t)}finally{ue(!1)}}}),Ve=Z.useMemo(()=>{let e=w?.activityParts;return!ge||!e?[]:e},[ge,w?.activityParts]),He=Z.useMemo(()=>{let e=w?.activityGroupSegments;return!ge||!e?[]:e.filter(e=>e.anchorMessageId===t)},[ge,t,w?.activityGroupSegments]),Ue=He.length>0,We=Z.useMemo(()=>{let e=new Map,t=new Map;return Ve.forEach(n=>{e.set(n.part,n);let r=n.part.id;typeof r==`string`&&r.length>0&&t.set(r,n)}),{get:n=>{let r=e.get(n);if(r)return r;let i=n.id;if(typeof i==`string`&&i.length>0)return t.get(i)}}},[Ve]),Ge=w?.toggleGroup,Ke=w?.activityPresentationKind===`compaction`,qe=w?.isGroupExpanded===!0,Je=ge&&Ke&&!qe,Ye=ge?w?.activityOwnerMessageId===t||Ue:!w?.activityOwnerMessageId||w.activityOwnerMessageId===t||Ue,Xe=ge&&Ye&&(Ue||Ke)&&!!Ge,Ze=qT(a,V),Qe={finish:a,parts:V,streamPhase:be,error:T,isLastAssistantInTurn:_e},$e=QT(Qe),et=ge&&$T(Qe),tt=ge&&!$e&&!(Ke&&qe),nt=!!T,rt=E===`info`?`information`:`error-warning`,it=E===`muted`,at=ze,st=_e&&ye&&!Je&&(b||!!T||i),lt=w?.diffStats?.hasDiffs===!0,ut=!K&&_e&&Ze&&ye&&!Je&&w?.diffStats?.hasDiffs===!0,dt=pe&&at&&!st&&!ge,ft=Z.useMemo(()=>(0,$.jsx)(wO,{hasCopyableText:ze,isTouchContext:L,onCopyMessage:x,ttsText:W,reviewTransferAction:ce,sessionId:e}),[W,ze,L,x,ce,e]),pt=Z.useMemo(()=>e=>{if(!pe||!ge)return null;let t=Qr(e.part).trim();return t?(0,$.jsx)(wO,{hasCopyableText:!0,isTouchContext:L,onCopyMessage:async()=>(await ct(t)).ok,ttsText:t}):null},[ge,L,pe]),mt=Z.useMemo(()=>{if(!dt)return-1;let e=-1;for(let t=0;t<V.length;t+=1){let n=V[t];!n||n.type!==`text`||tt||We.get(n)?.kind!==`justification`&&(e=t)}return e},[We,tt,dt,V]),ht=dt&&mt<0,_t=Z.useMemo(()=>{let n=[];if(Xe&&Ge&&w){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(UD,{parts:t,materializationParts:r,isExpanded:w.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:w.completionDisposition,activityPresentationKind:w.activityPresentationKind,durationMs:w.durationMs,startedAt:w.userMessageCreatedAt,onToggle:Ge,isMobile:u,expandedTools:m,onToggleTool:h,onShowPopup:g,onContentChange:y,streamPhase:be,showHeader:!0,diffStats:w.diffStats,renderJustificationActions:pt})},`progressive-group-${e}`))};He.length>0?He.forEach(t=>{let n=C?t.parts:t.parts.filter(e=>e.kind!==`reasoning`);e(t.id,n,t.parts)}):Ke&&e(`${t}:compaction-status`,[])}let r=0;for(;r<V.length;){let i=V[r];if(i.type===`text`){let a=We.get(i);if(tt){r+=1;continue}if(Je){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:P,"data-message-text-export-source":`true`,children:(0,$.jsx)(TT,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,allowSortedFinalStreaming:et,hasStreamingHapticLifecycle:Te,onContentChange:y,onShowPopup:g})},`assistant-text-${t}-${i.id??r}`)),dt&&r===mt&&n.push((0,$.jsx)(`div`,{className:u?qD:KD,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:QD,"data-message-action-group":`true`,children:ft})},`message-actions-${t}`)),r++;continue}if(i.type===`reasoning`){if(We.get(i)?.kind===`reasoning`){r+=1;continue}if(!Qr(i).trim()){r+=1;continue}C&&(fe?n.push((0,$.jsx)(`div`,{className:lm(u),children:(0,$.jsx)(LT,{part:i,messageId:t,streamPhase:be,onContentChange:y})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(TT,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,hasStreamingHapticLifecycle:Te,onContentChange:y,onShowPopup:g},`reasoning-${t}-${i.id??r}`))),r++;continue}if(i.type===`tool`){let e=i,a=e.tool?.toLowerCase()??``;if(ge&&!Ye){r+=1;continue}if(We.get(i)?.kind===`tool`){r+=1;continue}if(WC(a)){let e=[],i=r;for(;i<V.length;){let n=V[i];if(n.type!==`tool`)break;let r=n;if(!WC(r.tool?.toLowerCase()??``)||We.get(n)?.kind===`tool`)break;e.push({id:r.id,turnId:``,messageId:t,partIndex:i,part:r,kind:`tool`}),i+=1}if(e.length>0){n.push((0,$.jsx)(tD,{activities:e,isMobile:u,isTurnLive:be!==`completed`,hasFollowingOtherType:ZE(V,i,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:e.map(e=>(0,$.jsx)(FD,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`context-tools-${e[0].id}`)),r=i;continue}}if(GC(a)){let e=nD(V,r,e=>e.type!==`tool`||We.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(sD,{activities:i,isMobile:u,children:i.map(e=>(0,$.jsx)(FD,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:u,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(VC(a)){n.push((0,$.jsx)(`div`,{className:lm(u),children:(0,$.jsx)(aT,{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:lm(u),children:(0,$.jsx)(FD,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:u,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}return n},[We,He,R,de,fe,0,m,Je,Ke,u,Ye,ge,mt,t,ft,pt,e,y,g,h,Xe,dt,be,Te,C,tt,et,Ge,w,V]),vt=Z.useMemo(()=>{if(!_e||!ye)return;let e=w?.durationMs;if(!(typeof e!=`number`||e<=0))return xO(e)},[_e,ye,w?.durationMs]),yt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof c==`number`&&c>0?c:null;if(e===null)return null;let t=RE(e,he);return t.length>0?t:null},[o,c,he,k]),bt=Z.useMemo(()=>{if(!me||!_e||!ye)return null;let e=r??n,t=SO(e,l),i=UE({createdAt:c,completedAt:o,fallbackDurationMs:w?.durationMs,outputTokens:t.output,reasoningTokens:t.reasoning,parts:e});if(i===null)return null;let a=WE(i);return a.length>0?a:null},[me,_e,ye,n,r,l,c,o,w?.durationMs]),xt=(0,$.jsxs)($.Fragment,{children:[!K&&!u&&!G&&q?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,variant:`ghost`,size:`icon`,className:JD,"aria-label":O(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=ae??(re?ie(re):null);e&&ee(e,q)},children:(0,$.jsx)(X,{weight:nO,name:`global`,className:YD})})}),(0,$.jsx)(La,{sideOffset:6,children:O(`chat.messageBody.actions.openPreview`)})]}):null,!K&&!oe&&j.fork?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsx)(ca,{type:`button`,size:`icon`,variant:`ghost`,className:JD,"aria-label":O(`chat.messageBody.actions.forkAria`),"aria-busy":le,disabled:le||!!ne,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Be(e)},children:(0,$.jsx)(X,{weight:nO,name:le?`loader-4`:`git-branch`,className:Y(YD,le&&`animate-spin`)})})}),(0,$.jsx)(La,{sideOffset:6,children:O(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:N,"data-message-text-export-root":`true`,className:Y(`relative w-full group/message`),style:WD,children:[(0,$.jsx)(PE,{containerRef:N}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`message-content-text leading-relaxed text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0`,children:[_t,nt&&(0,$.jsx)(hc,{children:it?(0,$.jsxs)(`div`,{role:`status`,className:`my-1.5 flex max-w-full items-center gap-1.5 break-words typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`stop-circle`,className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0`,children:T})]}):(0,$.jsxs)(`div`,{className:Y(`group/assistant-text relative flow-root my-1.5 break-words max-w-full`,E===`info`?Y(`inline-flex w-fit max-w-full border border-[var(--status-info-border)]/45 bg-[var(--status-info-background)]/40`,u?`items-start gap-1.5 rounded-lg px-2.5 py-1.5`:Y(`items-center gap-1.5`,`rounded-lg px-2 py-0.5`)):`mt-3 flex items-center gap-2 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3`),children:[E===`info`&&u?(0,$.jsx)(`span`,{className:`inline-flex h-5 w-3.5 shrink-0 items-center justify-center translate-y-[2px]`,"aria-hidden":`true`,children:(0,$.jsx)(X,{name:rt,weight:nO,className:Y(YD,`text-[var(--status-info)]/80`)})}):(0,$.jsx)(X,{name:rt,weight:E===`info`?nO:void 0,className:Y(`shrink-0`,E===`info`?Y(YD,`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)(Os,{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)(pO,{fileCount:w.diffStats.files,changedFiles:w.changedFiles,turnId:w.turnId,isLatestTurn:w.isLatestTurn,isMobile:u}):null,(0,$.jsx)(Vd,{files:n,messageID:t,sessionID:e,onShowPopup:g}),ht&&(0,$.jsx)(`div`,{className:Y(u?qD:KD),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:QD,"data-message-action-group":`true`,children:ft})}),st&&(0,$.jsxs)(`div`,{className:z,"data-message-footer":`true`,style:GD,children:[(0,$.jsxs)(`div`,{className:QD,"data-message-action-group":`true`,children:[ft,xt]}),bt||vt||yt?(0,$.jsxs)(`div`,{className:$D,children:[bt?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:eO,"aria-label":O(`chat.messageBody.meta.tpsAria`,{rate:bt}),children:[(0,$.jsx)(X,{weight:nO,name:`pulse`,className:tO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:bt})]})}),(0,$.jsx)(La,{children:O(`chat.messageBody.meta.tpsTooltip`)})]}):null,vt?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:eO,children:[(0,$.jsx)(X,{weight:nO,name:`hourglass`,className:tO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:vt})]})}),(0,$.jsx)(La,{children:vt})]}):null,yt?(0,$.jsxs)(Ra,{children:[(0,$.jsx)(Ia,{asChild:!0,children:(0,$.jsxs)(`span`,{className:eO,"aria-label":`Message time: ${yt}`,children:[(0,$.jsx)(X,{weight:nO,name:`time`,className:tO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:yt})]})}),(0,$.jsx)(La,{children:yt})]}):null]}):null,!K&&_e&&ve&&!lt?(0,$.jsx)(VT,{activityParts:w?.activityParts}):null]})]})]})}),EO=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)(CO,{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)(TO,{...r}),t[26]=r,t[27]=i),i});function DO(e){return e.openContextPanelTab}function OO(e){return e.setCurrentSession}function kO(e){return e.openContextPanelTab}function AO(e){return!e}function jO(e){return e.openContextPanelTab}function MO(e){return!e}var NO=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}},PO=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,FO=e=>!e,IO=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},LO=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),RO=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,zO=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,BO=`Authentication failed for this provider. Please re-authenticate and retry.`,VO=e=>{if(typeof e!=`string`)return!1;let t=e.toLowerCase().trim();if(!t)return!1;if(t.includes(`token refresh failed`)||t.includes(`unauthorized`)||t.includes(`invalid token`)||t.includes(`expired token`))return!0;let n=t.includes(`oauth`),r=t.includes(`failed`)||t.includes(`invalid`)||t.includes(`expired`);if(n&&r)return!0;let i=/\b401\b/.test(t),a=t.includes(`auth`)||t.includes(`token`)||t.includes(`unauthorized`);return i&&a};function HO(e,t){if(!e||typeof e!=`object`)return;let n=e,r=typeof n.data?.message==`string`?n.data.message:void 0,i=typeof n.message==`string`?n.message:void 0,a=typeof n.name==`string`?n.name:void 0,o=r||i||a;if(o)return a===`SessionRetry`?{text:`Opencode failed to send a message. Retry attempt info: \n\`${o}\``,variant:`info`}:VO(o)?{text:BO,variant:`error`}:a===`MessageAbortedError`||o.trim().toLowerCase()===`aborted`?{text:t,variant:`muted`}:{text:`Opencode failed to send message with error:\n\`${o}\``,variant:`error`}}var UO=Fs(()=>Ue(()=>import(`./ToolOutputDialog-4-hGl1I6.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]))),WO=4e3,GO=new Map,KO=new Map,qO=new Set([`bash`,`shell`,`cmd`,`terminal`]),JO=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},YO=e=>{let t=GO.get(e);return t?new Set(t):new Set},XO=(e,t)=>{if(GO.size>=WO&&!GO.has(e)){let e=GO.keys().next().value;typeof e==`string`&&GO.delete(e)}GO.set(e,new Set(t))},ZO=e=>{let t=KO.get(e);return t?new Set(t):new Set},QO=(e,t)=>{if(KO.size>=WO&&!KO.has(e)){let e=KO.keys().next().value;typeof e==`string`&&KO.delete(e)}KO.set(e,new Set(t))},$O=200,ek=new Map,tk=e=>ek.get(e),nk=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=ek.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(ek.size>=$O&&!ek.has(e)){let e=ek.keys().next().value;typeof e==`string`&&ek.delete(e)}ek.set(e,t)}};function rk(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 ik=(e,t)=>{if(typeof e==`object`&&e)return e[t]},ak=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:c=!1,activeStreamingPhase:l=null,animateUserOnMount:u=!1,onUserAnimationConsumed:d,reviewTransferDirection:f=null})=>{let{t:p}=ot(),{isMobile:m,isTablet:h,hasTouchInput:g}=fo(),_=Nh(),v=Ph(_),y=m||h,b=Z.useRef(null),x=ni(e=>e.currentSessionId),S=rn(e=>e.getAgentModelForSession),C=rn(e=>e.getSessionModelSelection),w=ni(e=>e.revertToMessage),T=ni(e=>e.editMessagePreservingChanges),E=ni(e=>e.forkFromMessage),D=ni(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),O=ni(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),k=ni(e=>e.clearStagedMessageEdit);Le(`ui.chat_message.render`),c&&Le(`ui.chat_message.render.streaming`);let A=br(e=>e.providers),{showReasoningTraces:j,stickyUserHeader:M,chatRenderMode:N,showExpandedBashTools:P}=s(pe(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{x&&Nx.getInstance().recordSessionStart(x)},[x]);let[F,I]=Z.useState(null),[L,R]=Z.useState(!1),[z,B]=Z.useState(null),V=Z.useRef(null),[H,U]=Z.useState(()=>YO(e.info.id)),[W,ee]=Z.useState(()=>ZO(e.info.id)),[G,K]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{U(YO(e.info.id)),ee(ZO(e.info.id))},[e.info.id]);let q=Z.useMemo(()=>NO(e.info),[e.info]).isUser,te=q&&(m||!M),ne=q&&!m&&M&&!te,re=e.info.sessionID,ie=Ix(e=>e.planModeEnabled),{currentContextAgent:ae,savedSessionAgentSelection:oe}=wm(pe(e=>({currentContextAgent:c&&re?e.currentAgentContext.get(re):void 0,savedSessionAgentSelection:c&&re?e.sessionAgentSelections.get(re):void 0}))),se=Z.useMemo(()=>fn(e.sourceParts??e.parts),[e.parts,e.sourceParts]),ce=Z.useMemo(()=>q?vn(se,{planModeEnabled:ie}):fn(e.parts),[q,e.parts,ie,se]),le=Z.useMemo(()=>{if(q||!t)return null;let e=ik(t.info,`clientRole`),n=ik(t.info,`role`);if((typeof e==`string`?e:typeof n==`string`?n:void 0)!==`user`)return null;let r=ik(t.info,`mode`),i=ik(t.info,`agent`),a=ik(t.info,`providerID`),o=ik(t.info,`modelID`),s=ik(t.info,`model`),c=typeof s==`object`&&s?s.variant:void 0,l=ik(t.info,`variant`),u=c??l,d=typeof s==`object`&&s?s.providerID:void 0,f=typeof s==`object`&&s?s.modelID:void 0,p=typeof r==`string`&&r.trim().length>0?r:typeof i==`string`&&i.trim().length>0?i:void 0,m=typeof a==`string`&&a.trim().length>0?a:typeof d==`string`&&d.trim().length>0?d:void 0,h=typeof o==`string`&&o.trim().length>0?o:typeof f==`string`&&f.trim().length>0?f:void 0,g=typeof u==`string`&&u.trim().length>0?u:void 0;return!p&&!m&&!h&&!g?null:{agentName:p,providerId:m,modelId:h,variant:g}},[q,t]),ue=Z.useMemo(()=>{if(!ie||q||!t)return!1;let e=Array.isArray(t.parts)?t.parts:[];for(let t=0;t<e.length;t++){let n=e[t];if(n?.type!==`text`||n?.synthetic!==!0)continue;let r=typeof n.text==`string`?n.text.trim():``;if(r.startsWith(`User has requested to enter plan mode`)||r.startsWith(`The plan at `))return!0}return!1},[q,ie,t]),de=Z.useMemo(()=>{if(q)return;let t=e.info.time;if(!(typeof t?.completed==`number`&&t.completed>0)&&ue&&le?.agentName)return le.agentName;let n=ik(e.info,`mode`);if(typeof n==`string`&&n.trim().length>0)return n;let r=ik(e.info,`agent`);if(typeof r==`string`&&r.trim().length>0)return r;if(le?.agentName)return le.agentName;if(re)return ae||(oe??void 0)},[q,e.info,ue,le,re,ae,oe]),fe=q?null:ik(e.info,`providerID`),me=q?null:ik(e.info,`modelID`),he=Z.useMemo(()=>{if(q||!re)return null;if(le?.providerId&&le?.modelId)return{providerId:le.providerId,modelId:le.modelId};if(de){let e=S(re,de);if(e?.providerId&&e?.modelId)return e}let e=C(re);return e?.providerId&&e?.modelId?e:null},[q,re,de,le,S,C]),ge=Z.useMemo(()=>q?null:typeof fe==`string`&&fe.trim().length>0?fe:he?.providerId??null,[q,fe,he]),_e=Z.useMemo(()=>q?null:typeof me==`string`&&me.trim().length>0?me:he?.modelId??null,[q,me,he]),ve=e.info.id?tk(e.info.id):void 0;q||nk(e.info.id,{agent:de,provider:ge??void 0,model:_e??void 0});let ye=de??ve?.agent,be=ge??ve?.provider??null,xe=_e??ve?.model??null,Se=Z.useMemo(()=>{if(q)return;let e=be&&A.length>0?A.find(e=>e.id===be):void 0;return Er(e,xe)||void 0},[q,be,xe,A]),Ce=Z.useMemo(()=>{if(q||!ge||!_e)return!1;let e=A.find(e=>e.id===ge);if(!e?.models||!Array.isArray(e.models))return!1;let t=e.models.find(e=>e.id===_e)?.variants;return!!(t&&Object.keys(t).length>0)},[q,_e,ge,A]),we=rk(ye),Te=rk(be??void 0),Ee=rk(xe??void 0),De=rk(Se),Oe=we??void 0,ke=Te??null,Ae=Ee??null,je=De??void 0,Me=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),Ne=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Pe=Z.useMemo(()=>q?!0:!!(Me&&Me>0),[q,Me]),Fe=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),Ie=Z.useMemo(()=>{if(q)return null;let t=e.info.tokens;return!t||typeof t!=`object`?null:{output:typeof t.output==`number`?t.output:void 0,reasoning:typeof t.reasoning==`number`?t.reasoning:void 0}},[q,e.info]),Re=Z.useMemo(()=>ht(ce,{includeReasoning:j}),[ce,j]),ze=Z.useMemo(()=>q?Re:!Pe&&N===`sorted`?[]:Re,[N,Pe,q,Re]),Be=Z.useMemo(()=>q?[]:Re.filter(e=>e.type===`text`),[q,Re]),Ve=Z.useMemo(()=>q?[]:Re.filter(e=>e.type===`tool`),[q,Re]),He=Z.useMemo(()=>{if(!P)return new Set;let e=new Set;for(let t of Ve){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=JO(t.tool);!r||!qO.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=JO(t.part.tool);!n||!qO.has(n)||e.add(t.id)}return e},[P,Ve,a?.activityParts]),Ue=Z.useMemo(()=>{if(He.size===0&&W.size===0)return H;let e=new Set(H);return He.forEach(t=>{W.has(t)||e.add(t)}),W.forEach(t=>{e.delete(t)}),e},[W,He,H]),We=Z.useMemo(()=>{if(!q)return;let e=ce.find(e=>e.type===`agent`);if(!e)return;let t=e,n=typeof t.name==`string`?t.name:void 0;if(n)return{name:n,token:t.source&&typeof t.source.value==`string`&&t.source.value.trim().length>0?t.source.value:`@${n}`}},[q,ce]),Ge=q&&!Dt(ze),Ke=typeof Fe!=`string`,qe=Z.useMemo(()=>q?!1:Be.length===0||Ve.length===0?Ke:!0,[Be.length,Ve.length,Ke,q]),Je=Z.useMemo(()=>!q&&Nx.getInstance().shouldAnimateMessage(e.info,x||e.info.sessionID),[e.info,x,q]),[Ye,Xe]=Z.useState(!1),Ze=Z.useMemo(()=>n?NO(n.info):null,[n]),Qe=!!a,$e=a?.isLastAssistantInTurn??!1,et=RO({isWorking:a?.isWorking===!0,isInActiveTurn:c,headerCompletionDisposition:a?.completionDisposition}),tt=Z.useMemo(()=>q?!1:Qe?!$e:Ze?!Ze.isUser&&Ze.role===`assistant`:!1,[Qe,$e,q,Ze]),nt=Z.useMemo(()=>Pe?`completed`:c?l??`streaming`:`completed`,[l,c,Pe]);Z.useEffect(()=>{!q||!u||d?.(e.info.id)},[u,q,e.info.id,d]),Z.useEffect(()=>{Xe(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;q||!t||t!==e.info.id||(nt===`streaming`||nt===`cooldown`)&&Xe(!0)},[o,q,e.info.id,nt,a?.headerMessageId]);let rt=Z.useMemo(()=>{if(q)return!0;let t=o??a?.headerMessageId;return t?e.info.id===t?nt===`completed`||Ye||nt===`streaming`||nt===`cooldown`:!1:!0},[o,Ye,q,a,nt,e.info.id]),it=Z.useCallback(e=>{ct(e).then(t=>{t.ok&&(I(e),setTimeout(()=>I(null),2e3))})},[]),at=q?void 0:a?.userMessageVariant??le?.variant,st=!q&&Ce&&typeof at==`string`&&at.trim().length>0?at:void 0,lt=Z.useMemo(()=>{if(!q)return HO(e.info?.error,p(`chat.messageBody.aborted`))},[q,e.info,p]),ut=lt?.text,dt=lt?.variant,ft=Z.useMemo(()=>{if(q){let e=ze.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.output;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);if(e.length>0)return e.join(`
|
|
6575
6575
|
|
|
6576
6576
|
`);let t=ze.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.command;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);return t.length>0?t.join(`
|
|
6577
6577
|
`):ze.filter(e=>e.type===`text`).map(e=>(e.text||e.content||``).trim()).filter(e=>e.length>0).join(`
|