@openchambery/web 1.19.7-beta.7 → 1.19.7-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/assets/{AssistantView-AWe-3bXR.js → AssistantView-DYdXsGDh.js} +1 -1
  2. package/dist/assets/{ChatContainer-XHQSSICA.js → ChatContainer-D3onaUkL.js} +4 -4
  3. package/dist/assets/{ContextPanel-BT6bgBJ_.js → ContextPanel-Cj6RVUAe.js} +3 -3
  4. package/dist/assets/{DiagramView-DNLNZOT6.js → DiagramView-BoRTG67Z.js} +1 -1
  5. package/dist/assets/{MarkdownRendererImpl-C6E0KL8H.js → MarkdownRendererImpl-DwUKY9k4.js} +1 -1
  6. package/dist/assets/MarkstreamRendererImpl-BRvprELo.js +1 -0
  7. package/dist/assets/{MarkstreamRendererImpl-CxeWpDCK.css → MarkstreamRendererImpl-Ca7RATbs.css} +1 -1
  8. package/dist/assets/{MobileDetailNavigation-Sg0VMlOz.js → MobileDetailNavigation-C0Z8beRL.js} +1 -1
  9. package/dist/assets/{MobileShareBridge-QTUpK3s7.js → MobileShareBridge-DTvmm9vz.js} +1 -1
  10. package/dist/assets/{MobileSurface-BasV1X13.js → MobileSurface-CfrI-5uf.js} +1 -1
  11. package/dist/assets/{MultiRunWindow-BxyF4Xy4.js → MultiRunWindow-D_jo8cqz.js} +1 -1
  12. package/dist/assets/{SettingsView-BywiwJ_a.js → SettingsView-BOT158gD.js} +1 -1
  13. package/dist/assets/{SettingsWindow-zQ1dc-wl.js → SettingsWindow-CzMoz2fi.js} +1 -1
  14. package/dist/assets/{TerminalView-BMXYfo8d.js → TerminalView-sf_LfP6Z.js} +1 -1
  15. package/dist/assets/{ToolOutputDialog-CFFkJzQ4.js → ToolOutputDialog-BI5vwuaT.js} +1 -1
  16. package/dist/assets/{appThemeRegistry-4oEk9SR8.js → appThemeRegistry-G_zwgqAH.js} +2 -2
  17. package/dist/assets/{gitApi-Dqg8EDsg.js → gitApi-BE0vA4zm.js} +1 -1
  18. package/dist/assets/{insertionBoundaries-BtiZxiKR.js → insertionBoundaries-CJksyugt.js} +1 -1
  19. package/dist/assets/{main-D4qq97ip.js → main-BTeHOAU_.js} +3 -3
  20. package/dist/assets/{main-Blsi9j8P.js → main-BUBx-y1E.js} +2 -2
  21. package/dist/assets/{miniChat-QgI11lL4.js → miniChat-Btnf42TH.js} +2 -2
  22. package/dist/assets/{mobile-BjMMtvjD.js → mobile-CAjwV6ly.js} +2 -2
  23. package/dist/assets/{multirun-C9CKfXyS.js → multirun-Rpz1_-fz.js} +1 -1
  24. package/dist/assets/{projectMeta-DzGPV_uF.js → projectMeta-CvUuy-j5.js} +1 -1
  25. package/dist/assets/{radio-TX0aocEX.js → radio-D_a28OlM.js} +1 -1
  26. package/dist/assets/{renderElectronMiniChatApp-DZOBP2No.js → renderElectronMiniChatApp-DCzBQk2w.js} +2 -2
  27. package/dist/assets/{renderMobileApp-DP1_xIqJ.js → renderMobileApp-U5sclQRp.js} +4 -4
  28. package/dist/assets/{runtimeConfig-ClsErHd9.js → runtimeConfig-6inIl99b.js} +1 -1
  29. package/dist/assets/{runtimeEndpointReset-DoLMDfAs.js → runtimeEndpointReset-B_rUFDT5.js} +1 -1
  30. package/dist/assets/{shikiHighlight-B25fE64n.js → shikiHighlight-CMpSAuTl.js} +1 -1
  31. package/dist/assets/{useAppFontEffects-D1u63a6o.js → useAppFontEffects-3xHRVJcf.js} +2 -2
  32. package/dist/assets/{useDesktopWindowControlsLayout-DW_ouBDs.js → useDesktopWindowControlsLayout-QJlddPRn.js} +1 -1
  33. package/dist/assets/{useEffectiveDirectory-D976zCCc.js → useEffectiveDirectory-Bcj1wP95.js} +1 -1
  34. package/dist/assets/{useMobileNavigationStore-lcj5GHR3.js → useMobileNavigationStore-CD0GRjaV.js} +1 -1
  35. package/dist/assets/{useSessionAutoCleanup-DMNa_krc.js → useSessionAutoCleanup-CN_6ABvx.js} +1 -1
  36. package/dist/assets/{useWorkerHighlightedLines-BQNOf2U4.js → useWorkerHighlightedLines-DX9znDoW.js} +1 -1
  37. package/dist/index.html +2 -2
  38. package/dist/mini-chat.html +2 -2
  39. package/dist/mobile.html +2 -2
  40. package/package.json +1 -1
  41. package/dist/assets/MarkstreamRendererImpl-BKsc-avF.js +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-CFFkJzQ4.js","assets/rolldown-runtime-C0FnF6B9.js","assets/persistence-w-AiX2i4.js","assets/runtime-switch-BkpTTbEi.js","assets/desktop-CfLlmafK.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-base-ui-CnHfUmDN.js","assets/useUIStore-CNLmCoPU.js","assets/vendor-pathe-vBmvQE8f.js","assets/vendor-react-DLPElpoQ.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/vendor-pierre-diffs-DX7XTPG3.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/vendor-hast-util-to-html-B0p1k5Xa.js","assets/vendor-character-entities-legacy-Wut6vMuj.js","assets/vendor-character-entities-html4-DlN_yAFd.js","assets/vendor-ccount-CyGsA0u7.js","assets/vendor-comma-separated-tokens-B9ouxNNS.js","assets/vendor-oniguruma-to-es-CrHzjjSU.js","assets/vendor-oniguruma-parser-D2DIvhSP.js","assets/vendor-diff-Dq7CZNim.js","assets/vendor-lru_map-DpDied8H.js","assets/vendor-reactuses-core-DDoDDyM9.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/clipboard-D35XSwID.js","assets/store-CL3WP48T.js","assets/dialog-x2hirWBd.js","assets/utils-CTL16t2f.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-CLpn1mIz.js","assets/button-z0GOBtWi.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-SPe4jOwX.js","assets/appThemeRegistry-4oEk9SR8.js","assets/platform-4eCmsdol.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/useMobileNavigationStore-lcj5GHR3.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-I0VWrB5V.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/markdown-worker-y3ewaqAK.js","assets/markdownHeightCache-CvUyZT4q.js","assets/useEffectiveDirectory-D976zCCc.js","assets/useWorkerHighlightedLines-BQNOf2U4.js","assets/tooltip-CtH61mQh.js","assets/vendor-tanstack-react-virtual-tlDgH6PG.js"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{c as t,f as n,i as r,n as i,r as a,x as o}from"./runtime-switch-BkpTTbEi.js";import{$ as s,B as c,C as l,Ct as u,Dt as d,G as f,I as p,It as m,J as h,K as g,M as _,N as v,Q as y,R as b,S as x,T as S,U as C,V as w,W as T,Y as E,Z as D,_ as O,at as k,b as A,ct as j,d as M,et as N,ft as P,it as F,j as I,lt as L,mt as R,nt as z,ot as B,pt as V,q as H,r as U,st as W,u as ee,ut as G,v as K,wt as te,x as ne,y as re,yt as ie,z as ae}from"./persistence-w-AiX2i4.js";import{u as oe,y as se}from"./desktop-CfLlmafK.js";import{a as ce,i as le,r as ue,t as de}from"./vendor-zustand-B4dlGEM2.js";import{c as fe,d as pe,f as me,l as he,nt as ge,rt as _e,tt as ve,u as ye}from"./vendor-base-ui-CnHfUmDN.js";import{At as be,Bt as xe,Ct as Se,Gt as Ce,Ht as we,Jt as Te,Kt as Ee,Nt as De,Pt as Oe,Rt as ke,St as Ae,Ut as je,Wt as Me,Yt as Ne,jt as Pe,kt as Fe,n as Ie,t as Le,zt as Re}from"./platform-4eCmsdol.js";import{g as ze,t as q,y as Be}from"./useUIStore-CNLmCoPU.js";import{a as Ve,n as He,o as Ue}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as We}from"./vendor-react-DLPElpoQ.js";import{i as Ge,n as Ke,s as qe,t as Je}from"./vendor-tanstack-react-query-D7pys_c9.js";import{B as Ye,R as Xe,V as Ze,c as Qe}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{i as $e,u as et}from"./vendor-pierre-diffs-DX7XTPG3.js";import{a as tt,d as nt,i as rt,l as it,n as J,o as at,r as ot,u as st}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ct,r as lt,t as ut}from"./clipboard-D35XSwID.js";import{i as dt,t as ft}from"./store-CL3WP48T.js";import{$ as pt,$a as mt,$n as ht,$r as gt,$t as _t,A as vt,Ai as yt,At as bt,Ba as xt,Bi as St,Bn as Ct,Ci as wt,Cn as Tt,Cr as Et,Ct as Dt,D as Ot,Da as kt,Dn as At,Dr as jt,E as Mt,Ei as Nt,En as Pt,F as Ft,Fa as It,Fi as Lt,Fr as Rt,G as zt,Ga as Bt,Gt as Vt,H as Ht,Ha as Ut,Hi as Wt,Hr as Gt,I as Kt,Ii as qt,In as Jt,Ir as Yt,It as Xt,J as Zt,Ja as Qt,K as $t,Ka as en,Kt as tn,Li as nn,Ln as rn,Lr as an,Lt as on,M as sn,Mi as cn,Mo as ln,Mt as un,N as dn,Ni as fn,Nr as pn,Nt as mn,O as hn,Oa as gn,On as _n,Or as vn,Ot as yn,P as bn,Pi as xn,Q as Sn,Qi as Cn,Qn as wn,Qr as Tn,Qt as En,R as Dn,Ri as On,Rn as kn,Rr as An,Rt as jn,S as Mn,Sa as Nn,Si as Pn,Sn as Fn,Sr as In,T as Ln,Ti as Rn,Tn as zn,Ua as Bn,Ui as Vn,Ut as Hn,Va as Un,Vi as Wn,Vr as Gn,W as Kn,Wa as qn,Wr as Jn,Wt as Yn,X as Xn,Xr as Zn,Xt as Qn,Y as $n,Yr as er,Z as tr,Zi as nr,Zn as rr,Zr as ir,Zt as ar,_i as or,_n as sr,_t as cr,a as lr,aa as ur,ai as dr,an as fr,at as pr,ba as mr,bi as hr,bo as gr,bt as _r,ci as vr,cn as yr,da as br,di as xr,dn as Sr,dt as Cr,ea as wr,eo as Tr,er as Er,et as Dr,f as Or,fa as kr,fi as Ar,fn as jr,fr as Mr,g as Nr,ga as Pr,gi as Fr,gn as Ir,gt as Lr,ha as Rr,hn as zr,hr as Br,ht as Vr,i as Hr,in as Ur,it as Wr,j as Gr,ja as Kr,ji as qr,jr as Jr,jt as Yr,k as Xr,ka as Zr,ki as Qr,kn as $r,ko as ei,kr as ti,kt as ni,l as ri,la as ii,ln as ai,m as oi,ma as si,mi as ci,mn as li,mt as ui,n as di,na as fi,ni as pi,nn as mi,nt as hi,oi as gi,pa as _i,pi as vi,pn as yi,pt as bi,q as xi,qa as Si,qi as Ci,qt as wi,rn as Ti,ro as Ei,rt as Di,si as Oi,sn as ki,ta as Ai,ti as ji,tn as Mi,tt as Ni,ui as Pi,un as Fi,va as Ii,vi as Li,vt as Ri,w as zi,wa as Bi,wi as Vi,wr as Hi,wt as Ui,x as Wi,xi as Gi,xr as Ki,ya as qi,yi as Ji,yo as Yi,z as Xi,za as Zi,zi as Qi,zr as $i}from"./useMobileNavigationStore-lcj5GHR3.js";import{a as ea,i as ta,l as na,n as ra,o as ia,r as aa,s as oa,t as sa}from"./dialog-x2hirWBd.js";import{n as ca,t as Y}from"./utils-CTL16t2f.js";import{t as la}from"./AgentAvatar-Di8F4QJh.js";import{n as X}from"./Icon-CLpn1mIz.js";import{t as ua}from"./button-z0GOBtWi.js";import{E as da,n as fa}from"./gitApi-Dqg8EDsg.js";import{A as pa,C as ma,G as ha,K as ga,M as _a,O as va,Q as ya,S as ba,T as xa,X as Sa,Z as Ca,a as wa,b as Ta,d as Ea,et as Da,g as Oa,h as ka,i as Aa,j as ja,k as Ma,n as Na,o as Pa,p as Fa,s as Ia,u as La,v as Ra,w as za,x as Ba}from"./projectMeta-DzGPV_uF.js";import{t as Va}from"./input-BG3VWTIF.js";import{i as Ha,n as Ua,t as Wa}from"./tooltip-CtH61mQh.js";import{n as Ga,t as Ka}from"./useThemeSystem-DMzWVJaW.js";import{A as qa,B as Ja,C as Ya,K as Xa,M as Za,P as Qa,_ as $a,a as eo,f as to,g as no,h as ro,i as io,m as ao,o as oo,p as so,r as co,t as lo,v as uo,w as fo,y as po}from"./radio-TX0aocEX.js";import{i as mo,t as ho}from"./OverlayScrollbar-DlNZho3q.js";import{_ as go,a as _o,d as vo,f as yo,g as bo,h as xo,i as So,l as Co,m as wo,n as To,u as Eo,v as Do,x as Oo}from"./markdownTheme-SPe4jOwX.js";import{n as ko,r as Ao,t as jo}from"./useRuntimeAPIs-DSLXJybW.js";import{A as Mo,B as No,C as Po,D as Fo,E as Io,F as Lo,H as Ro,I as zo,L as Bo,M as Vo,N as Ho,O as Uo,R as Wo,S as Go,T as Ko,U as qo,V as Jo,a as Yo,b as Xo,c as Zo,f as Qo,i as $o,j as es,k as ts,l as ns,m as rs,n as is,o as as,p as os,r as ss,s as cs,t as ls,u as us,w as ds,x as fs,z as ps}from"./insertionBoundaries-BtiZxiKR.js";import{A as ms,C as hs,D as gs,E as _s,F as vs,M as ys,N as bs,O as xs,P as Ss,R as Cs,S as ws,T as Ts,_ as Es,a as Ds,b as Os,d as ks,f as As,g as js,h as Ms,i as Ns,j as Ps,k as Fs,l as Is,m as Ls,p as Rs,r as zs,s as Bs,t as Vs,v as Hs,w as Us,x as Ws,y as Gs}from"./appThemeRegistry-4oEk9SR8.js";import{_ as Ks,a as qs,c as Js,g as Ys,l as Xs,o as Zs,t as Qs,v as $s,y as ec}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{i as tc,n as nc,o as rc,s as ic,t as ac}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as oc,n as sc,t as cc}from"./url-KeihbE0d.js";import{d as lc,h as uc,o as dc,u as fc}from"./markdown-worker-y3ewaqAK.js";import{n as pc}from"./useEffectiveDirectory-D976zCCc.js";import{a as mc,c as hc,d as gc,f as _c,i as vc,l as yc,n as bc,r as xc,s as Sc,t as Cc}from"./FadeInOnReveal-CV2s6YN8.js";import{A as wc,C as Tc,D as Ec,E as Dc,M as Oc,O as kc,S as Ac,T as jc,a as Mc,b as Nc,c as Pc,g as Fc,h as Ic,i as Lc,j as Rc,k as zc,o as Bc,p as Vc,r as Hc,s as Uc,t as Wc,v as Gc,w as Kc,x as qc,y as Jc}from"./useWorkerHighlightedLines-BQNOf2U4.js";import{t as Yc}from"./vendor-cmdk-CeAGfrLo.js";import{t as Xc}from"./sortable-tabs-strip-CNDgyX0B.js";import{n as Zc,t as Qc}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{i as $c}from"./markdownHeightCache-CvUyZT4q.js";import{i as el,t as tl}from"./vendor-framer-motion-DFy_BSVd.js";import{t as nl}from"./vendor-legendapp-list-WE32lwNk.js";var Z=e(_e(),1),Q=We(),$=ge(),rl=e(ve(),1),il=`openchamber:close-embedded-session-chat`,al=`openchamber:embedded-visibility`,ol=`openchamber:embedded-visibility-request`,sl=e=>new URLSearchParams(e).get(`ocPanel`)===`session-chat`,cl=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),ll=(e,t,n,r)=>{if(typeof window>`u`)return``;let i=new URL(window.location.pathname,window.location.origin);return i.searchParams.set(`ocPanel`,`session-chat`),i.searchParams.set(`surface`,`desktop`),i.searchParams.set(`sessionId`,e),n?i.searchParams.set(`readOnly`,`1`):i.searchParams.delete(`readOnly`),t&&t.trim().length>0?i.searchParams.set(`directory`,t):i.searchParams.delete(`directory`),i.searchParams.set(`themeMode`,r.mode),i.searchParams.set(`lightThemeId`,r.lightThemeId),i.searchParams.set(`darkThemeId`,r.darkThemeId),i.searchParams.set(`themeVariant`,r.currentTheme.metadata.variant===`dark`?`dark`:`light`),i.searchParams.set(`currentTheme`,JSON.stringify(r.currentTheme)),i.hash=``,i.toString()},ul=(e,t,n,r,i,a)=>{let o=cl(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=ll(n,r,i,a);return e.set(t,{signature:o,src:c}),c},dl=null,fl=()=>{if(dl!==null)return dl;if(typeof window>`u`)return dl=!1,!1;try{return dl=new URLSearchParams(window.location.search).get(`ocPanel`)===`session-chat`,dl}catch{return dl=!1,!1}},pl=()=>{if(!fl())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},ml=Ve(`OpenChamberMedia`);function hl(){return Ie()&&He.getPlatform()===`android`&&He.isPluginAvailable(`OpenChamberMedia`)}async function gl(e){if(!hl())return null;let t=await ml.pickMedia({limit:e});if(t.cancelled)return[];let n=[];for(let e of t.files){let t=await fetch(He.convertFileSrc(e.path));if(!t.ok)throw Error(`Native media fetch failed (${t.status})`);let r=await t.blob();n.push(new File([r],e.name,{type:e.mimeType}))}return n}var _l=(e,t)=>{let n=t.trim();if(!n.length)return[...e].sort((e,t)=>e.scope===`project`&&t.scope!==`project`?-1:e.scope!==`project`&&t.scope===`project`?1:e.name.localeCompare(t.name));let r=bi([...e],n,e=>[e.name,e.description??``]);return r.sort((e,t)=>e.score===t.score?e.item.scope===`project`&&t.item.scope!==`project`?-1:e.item.scope!==`project`&&t.item.scope===`project`?1:e.item.name.localeCompare(t.item.name):e.score-t.score),r.map(e=>e.item)},vl=new Map,yl=(e,t,n)=>`${+!!t}:${n}:${e.map(e=>`${e.id}\0${e.title}\0${e.subtitle??``}\0${e.badge??``}\0${e.iconName}`).join(`|`)}`,bl=async e=>{let t=ys(`--surface-foreground`);return Promise.all(e.slice(0,40).map(async e=>{let n=`${e.iconName}:${t}`,r=vl.get(n);return r===void 0&&(r=await qo(e.iconName,t)??``,vl.set(n,r)),{id:e.id,title:e.title,subtitle:e.subtitle??``,badge:e.badge??``,iconBase64:r}}))},xl=[],Sl=e=>void 0,Cl=()=>void 0;function wl(e){let t=Cs()&&e.enabled&&Gs(e.isMobile),n=(0,Z.useRef)(null),r=(0,Z.useRef)(e.text),i=(0,Z.useRef)(!1),a=(0,Z.useRef)(-1),o=(0,Z.useRef)(null),s=(0,Z.useRef)(``),c=(0,Z.useRef)([]),l=(0,Z.useRef)(Os()),u=J(e.onText),d=J(e.onSend),f=J(e.onAbort),p=J(e.onAttach),m=J(e.onFiles),h=J(e.onRemoveAttachment),g=J(e.onOpenModel),_=J(e.onCycleAgent),v=J(e.onOpenAgent),y=J(e.onScrollToBottom),b=J(e.onAutocompleteAccept??Sl),x=J(e.onAutocompleteDismiss??Cl),S=J(e=>{typeof document>`u`||Ms(document.documentElement,e)});Rs.bind({onText:(e,t,n)=>{vs({incoming:e,replacedText:o.current})||(o.current=null,r.current=e,i.current=!0,u(e,t,n))},onSend:e=>{r.current=e,d(e)},onAbort:f,onAttach:p,onFiles:m,onRemoveAttachment:h,onOpenModel:g,onCycleAgent:_,onOpenAgent:v,onHeight:S,onScrollToBottom:y,onAutocompleteAccept:e=>{i.current=!1,b(e)},onAutocompleteDismiss:x});let C=()=>({text:e.text,placeholder:e.placeholder,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel,modelIcon:s.current,canSend:e.canSend,canAbort:e.canAbort,attachmentCount:e.attachmentCount,attachmentPreviews:c.current,citationRanges:Te(e.text,e.attachments.map(e=>e.filename)),chipRanges:Es(Us(e.text,e.chipHighlights),ys(`--primary`)),appearance:typeof document>`u`?`dark`:gs(document.documentElement),attachAria:e.attachAria,attachTitle:e.attachTitle,attachPhotosLabel:e.attachPhotosLabel,attachFilesLabel:e.attachFilesLabel,attachCancelLabel:e.attachCancelLabel,sendAria:e.sendAria,queueAria:e.queueAria,stopAria:e.stopAria,modelAria:e.modelAria,agentAria:e.agentAria,agentLabel:e.agentLabel,agentColor:_s(e.agentName||void 0),agentIdenticon:xs(e.agentName||void 0),suppressed:e.suppressed,showScrollToBottom:e.showScrollToBottom,scrollAria:e.scrollAria,autocomplete:l.current});(0,Z.useLayoutEffect)(()=>{if(!t||typeof document>`u`)return;let e=document.documentElement;return Ss(e,!0),()=>{Ss(e,!1)}},[t]),(0,Z.useEffect)(()=>{if(!t||typeof document>`u`)return;let e=document.documentElement,i=C();n.current=i,r.current=i.text,Rs.rememberText(i.text),Rs.retain(e,i);let a=As();return()=>{n.current=null,a(),Rs.release(e)}},[t]),(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=Ca(e.modelId,e.providerId),a={modelIcon:``,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};if(s.current=``,n.current&&={...n.current,...a},Ws().update(a),i)return ms(i).then(t=>{if(r)return;let i=t??``;s.current=i;let a={modelIcon:i,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};n.current&&={...n.current,...a},Ws().update(a)}),()=>{r=!0}},[t,e.modelId,e.providerId,e.modelLabel,e.modelVariantLabel]);let w=js(e.attachments);(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=e.attachments;if(i.length===0){c.current=[],n.current&&(n.current={...n.current,attachmentPreviews:[]},Rs.rememberState(n.current)),Ws().update({attachmentPreviews:[]});return}return Promise.all(i.map(async t=>{let n=t.mimeType.startsWith(`image/`)&&t.dataUrl?await Fs(t.dataUrl):``;return{id:t.id,filename:t.filename,mime:t.mimeType,thumbnailBase64:n??``,removeAria:e.removeAttachmentNamedAria(t.filename)}})).then(e=>{r||(c.current=e,n.current&&(n.current={...n.current,attachmentPreviews:e},Rs.rememberState(n.current)),Ws().update({attachmentPreviews:e}))}),()=>{r=!0}},[t,w]);let T=e.autocompleteRows??xl,E=e.autocompleteOpen===!0,D=e.autocompleteHighlightedIndex??0,O=yl(T,E,D);(0,Z.useEffect)(()=>{if(!t)return;let e=!1;if(!(E&&T.length>0)){let e=Os();hs(l.current,e)||(l.current=e,n.current&&(n.current={...n.current,autocomplete:e},Rs.rememberState(n.current)),Ws().update({autocomplete:e}));return}return bl(T).then(t=>{if(e)return;let r={open:t.length>0,highlightedIndex:Math.max(0,Math.min(D,Math.max(t.length-1,0))),rows:t};hs(l.current,r)||(l.current=r,n.current&&(n.current={...n.current,autocomplete:r},Rs.rememberState(n.current)),Ws().update({autocomplete:r}))}),()=>{e=!0}},[t,O]);let k=t?Us(e.text,e.chipHighlights).map(e=>`${e.start}:${e.end}:${e.triggerLength}`).join(`|`):``;return(0,Z.useEffect)(()=>{if(!t)return;let s=C(),c=n.current;if(c&&Ts(c,s)){i.current=!1,a.current=e.textPresetEpoch;return}n.current=s,Rs.rememberState(s);let l=e.textPresetEpoch!==a.current;a.current=e.textPresetEpoch;let u=bs({nextText:s.text,nativeOwnedText:r.current,echoingNative:i.current,preset:l});i.current=!1,!u.omitText&&u.forceText&&(o.current=r.current),u.omitText||(r.current=s.text);let d=Hs(c,s,u,{caret:e.caret});d&&Ws().update(d)},[t,e.text,e.textPresetEpoch,e.placeholder,e.modelLabel,e.modelVariantLabel,e.modelId,e.providerId,e.canSend,e.canAbort,e.attachmentCount,w,e.suppressed,e.attachAria,e.attachTitle,e.attachPhotosLabel,e.attachFilesLabel,e.attachCancelLabel,e.sendAria,e.queueAria,e.stopAria,e.modelAria,e.agentName,e.agentLabel,e.agentAria,e.showScrollToBottom,e.scrollAria,k]),t}var Tl=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},El=1e4,Dl=15e3,Ol=3e4,kl=3e4,Al=new class{socket=null;connectPromise=null;idleCloseTimer=null;pendingStarts=new Map;pendingFinishes=new Map;connectionListeners=new Set;partialListeners=new Set;activeDictations=0;get isConnected(){return this.socket?.readyState===WebSocket.OPEN}subscribeConnectionStatus(e){return this.connectionListeners.add(e),()=>{this.connectionListeners.delete(e)}}onPartial(e){return this.partialListeners.add(e),()=>{this.partialListeners.delete(e)}}async ensureConnected(){if(!this.isConnected){if(this.connectPromise){await this.connectPromise;return}try{await o()}catch{}this.connectPromise=new Promise((e,t)=>{let r=!1,i;try{let e=n().websocket(`/api/dictation/ws`);i=Ae(e)}catch(e){this.connectPromise=null,t(e instanceof Error?e:Error(String(e)));return}let a=setTimeout(()=>{if(!r){r=!0,this.connectPromise=null;try{i.close()}catch{}t(Error(`Dictation connection timed out`))}},El);i.onopen=()=>{},i.onmessage=t=>{let n;try{n=JSON.parse(String(t.data))}catch{return}if(!r&&n.type===`ready`){r=!0,clearTimeout(a),this.socket=i,this.connectPromise=null,this.notifyConnection(!0),e();return}this.handleMessage(n)},i.onerror=()=>{window.setTimeout(()=>{r||(r=!0,clearTimeout(a),this.connectPromise=null,t(Error(`Dictation connection failed`)))},250)},i.onclose=e=>{if(!r){r=!0,clearTimeout(a),this.connectPromise=null;let n=e?.reason?`: ${e.reason}`:``;t(Error(`Dictation connection failed${n}`));return}this.socket===i&&(this.socket=null,this.rejectAllPending(Error(`Dictation connection lost`)),this.notifyConnection(!1))}}),await this.connectPromise}}async startDictationStream(e,t,n){return await this.ensureConnected(),this.activeDictations+=1,this.clearIdleCloseTimer(),new Promise((r,i)=>{let a=setTimeout(()=>{this.pendingStarts.delete(e),this.releaseDictation(),i(Error(`Dictation start timed out`))},Dl);this.pendingStarts.set(e,{resolve:()=>{clearTimeout(a),r()},reject:e=>{clearTimeout(a),this.releaseDictation(),i(e)},timeout:a}),this.send({type:`start`,dictationId:e,format:t,options:n})||(clearTimeout(a),this.pendingStarts.delete(e),this.releaseDictation(),i(Error(`Dictation connection lost`)))})}sendDictationStreamChunk(e,t,n){return this.send({type:`chunk`,dictationId:e,seq:t,audio:n})}finishDictationStream(e,t){return new Promise((n,r)=>{let i={resolve:e=>{i.timeout&&clearTimeout(i.timeout),this.releaseDictation(),n(e)},reject:e=>{i.timeout&&clearTimeout(i.timeout),this.releaseDictation(),r(e)},timeout:null};i.timeout=setTimeout(()=>{this.pendingFinishes.delete(e),this.releaseDictation(),r(Error(`Timed out waiting for transcription`))},kl),this.pendingFinishes.set(e,i),this.send({type:`finish`,dictationId:e,finalSeq:t})||(this.pendingFinishes.delete(e),i.reject(Error(`Dictation connection lost`)))})}cancelDictationStream(e){this.send({type:`cancel`,dictationId:e});let t=this.pendingStarts.get(e);t&&(this.pendingStarts.delete(e),t.reject(Error(`Dictation cancelled`)));let n=this.pendingFinishes.get(e);n&&(this.pendingFinishes.delete(e),n.reject(Error(`Dictation cancelled`))),this.releaseDictation(),this.scheduleIdleCloseIfReady()}handleMessage(e){let t=e.dictationId;if(t)switch(e.type){case`ack`:{let e=this.pendingStarts.get(t);e&&(this.pendingStarts.delete(t),e.resolve());return}case`partial`:for(let n of this.partialListeners)n(t,e.text??``);return;case`finish_accepted`:{let n=this.pendingFinishes.get(t);n&&typeof e.timeoutMs==`number`&&(n.timeout&&clearTimeout(n.timeout),n.timeout=setTimeout(()=>{this.pendingFinishes.delete(t),n.reject(Error(`Timed out waiting for transcription`))},e.timeoutMs+5e3));return}case`final`:{let n=this.pendingFinishes.get(t);n&&(this.pendingFinishes.delete(t),n.resolve({text:e.text??``})),this.scheduleIdleCloseIfReady();return}case`error`:{let n=Tl(e.error||`Dictation failed`,e.retryable!==!1,e.reasonCode),r=this.pendingStarts.get(t);r&&(this.pendingStarts.delete(t),r.reject(n));let i=this.pendingFinishes.get(t);i&&(this.pendingFinishes.delete(t),i.reject(n)),this.scheduleIdleCloseIfReady();return}}}send(e){if(!this.isConnected||!this.socket)return!1;try{return this.socket.send(JSON.stringify(e)),!0}catch{return!1}}notifyConnection(e){for(let t of this.connectionListeners)t(e)}rejectAllPending(e){for(let[t,n]of this.pendingStarts)this.pendingStarts.delete(t),n.reject(e);for(let[t,n]of this.pendingFinishes)this.pendingFinishes.delete(t),n.reject(e);this.activeDictations=0}releaseDictation(){this.activeDictations=Math.max(0,this.activeDictations-1),this.scheduleIdleCloseIfReady()}scheduleIdleCloseIfReady(){this.activeDictations>0||this.pendingFinishes.size>0||this.pendingStarts.size>0||(this.clearIdleCloseTimer(),this.idleCloseTimer=setTimeout(()=>{if(this.activeDictations===0&&this.pendingFinishes.size===0&&this.pendingStarts.size===0){let e=this.socket;if(this.socket=null,e){try{e.close(1e3,`idle`)}catch{}this.notifyConnection(!1)}}},Ol))}cancelAllForRuntimeSwitch(){this.clearIdleCloseTimer();let e=this.socket;if(this.socket=null,this.connectPromise=null,this.rejectAllPending(Error(`Runtime changed`)),e){try{e.close(1e3,`runtime switch`)}catch{}this.notifyConnection(!1)}}clearIdleCloseTimer(){this.idleCloseTimer&&=(clearTimeout(this.idleCloseTimer),null)}};typeof window<`u`&&window.addEventListener(`openchamber:runtime-endpoint-changed`,()=>{Al.cancelAllForRuntimeSwitch()});var jl=128,Ml=`audio/pcm;rate=16000;bits=16`,Nl=()=>new Promise(e=>setTimeout(e,0)),Pl=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},Fl=class{client;format;createDictationId;getStartOptions;dictationId=null;sendSeq=0;segments=[];streamReady=!1;flushTimer=null;drainWaiters=[];startGeneration=0;startPromise=null;constructor(e){this.client=e.client,this.format=e.format??Ml,this.getStartOptions=e.getStartOptions,this.createDictationId=e.createDictationId??Pl}getDictationId(){return this.dictationId}getFinalSeq(){return this.segments.length-1}hasSegments(){return this.segments.length>0}clearAll(){this.clearScheduledFlush(),this.dictationId=null,this.sendSeq=0,this.segments=[],this.streamReady=!1,this.startPromise=null,this.startGeneration+=1}resetStreamForReplay(){this.clearScheduledFlush(),this.dictationId=null,this.sendSeq=0,this.streamReady=!1,this.startPromise=null,this.startGeneration+=1}enqueueSegment(e){if(this.segments.push(e),this.client.isConnected){if(!this.dictationId){this.startPromise||this.restartStream().catch(()=>{});return}this.flush()}}flush(){let e=this.dictationId;if(!this.client.isConnected||!e||!this.streamReady)return 0;let t=0;for(;this.sendSeq<this.segments.length&&t<jl;){let n=this.sendSeq,r=this.segments[n];if(!this.client.sendDictationStreamChunk(e,n,r))break;this.sendSeq=n+1,t+=1}return this.hasPendingSegments()?this.scheduleFlush():this.resolveDrainWaiters(),t}async restartStream(){this.startGeneration+=1;let e=this.startGeneration,t=this.createDictationId();this.dictationId=t,this.sendSeq=0,this.streamReady=!1;let n=(async()=>{await this.client.startDictationStream(t,this.format,this.getStartOptions()),this.startGeneration===e&&this.dictationId===t&&(this.streamReady=!0,this.flush())})().catch(n=>{throw this.startGeneration===e&&this.dictationId===t&&(this.dictationId=null,this.streamReady=!1),n}).finally(()=>{this.startPromise===n&&(this.startPromise=null)});this.startPromise=n,await n}async finish(e){this.dictationId||await this.restartStream(),this.startPromise&&await this.startPromise;let t=this.dictationId;if(!t||!this.streamReady)throw Error(`Failed to start dictation stream`);return this.flush(),await this.waitForFlushDrain(),{dictationId:t,text:(await this.client.finishDictationStream(t,e)).text}}cancel(){let e=this.dictationId;this.client.isConnected&&e&&this.client.cancelDictationStream(e),this.resetStreamForReplay()}hasPendingSegments(){return this.sendSeq<this.segments.length}scheduleFlush(){this.flushTimer||=setTimeout(()=>{this.flushTimer=null,this.flush()},0)}clearScheduledFlush(){this.flushTimer&&=(clearTimeout(this.flushTimer),null)}async waitForFlushDrain(){for(;this.hasPendingSegments();){if(!this.client.isConnected||!this.dictationId||!this.streamReady)throw Error(`Failed to flush dictation stream`);await new Promise(e=>{this.drainWaiters.push(e)}),await Nl()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},Il=16e3,Ll=Il,Rl=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},zl=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},Bl=(e,t,n)=>{if(e.length===0)return new Int16Array;if(t===n){let t=new Int16Array(e.length);for(let n=0;n<e.length;n++)t[n]=zl(e[n]);return t}let r=t/n,i=Math.max(1,Math.round(e.length/r)),a=new Int16Array(i);for(let t=0;t<i;t++){let n=t*r,i=Math.floor(n),o=Math.min(e.length-1,i+1),s=n-i;a[t]=zl(e[i]*(1-s)+e[o]*s)}return a},Vl=(e,t)=>{if(e.length===0)return t;if(t.length===0)return e;let n=new Int16Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n},Hl=e=>{let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=``;for(let e=0;e<t.length;e++)n+=String.fromCharCode(t[e]);return btoa(n)},Ul=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),Wl=e=>{if(e)try{e.disconnect()}catch{}},Gl=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Rl()!==null;function Kl(e){let t=(0,Q.c)(12),[n,r]=(0,Z.useState)(0),i=(0,Z.useRef)(e.onPcmSegment),a=(0,Z.useRef)(e.onError),o,s;t[0]!==e.onError||t[1]!==e.onPcmSegment?(o=()=>{i.current=e.onPcmSegment,a.current=e.onError},s=[e.onPcmSegment,e.onError],t[0]=e.onError,t[1]=e.onPcmSegment,t[2]=o,t[3]=s):(o=t[2],s=t[3]),(0,Z.useEffect)(o,s);let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=Ul(),t[4]=c):c=t[4];let l=(0,Z.useRef)(c),u;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=async()=>{if(l.current.started)return;if(typeof navigator>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`)throw Error(`Microphone capture is not supported in this environment`);let e=Rl();if(!e)throw Error(`AudioContext unavailable`);let t=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,noiseSuppression:!0,echoCancellation:!0,autoGainControl:!0}}),n=new e;try{n.state===`suspended`&&await n.resume().catch(Yl);let e=n.createMediaStreamSource(t),a=n.createScriptProcessor(4096,1,1),o=n.createGain();o.gain.value=0,l.current={stream:t,context:n,source:e,processor:a,gain:o,pending:new Int16Array,started:!0},a.onaudioprocess=e=>{let t=l.current;if(!t.started)return;let a=e.inputBuffer.getChannelData(0),o=0;for(let e=0;e<a.length;e++)o+=a[e]*a[e];let s=Math.sqrt(o/Math.max(1,a.length));r(Math.min(1,Math.max(0,s*2)));let c=Bl(a,n.sampleRate,Il);for(t.pending=Vl(t.pending,c);t.pending.length>=Ll;){let e=t.pending.slice(0,Ll);t.pending=t.pending.slice(Ll),i.current(Hl(e))}},e.connect(a),a.connect(o),o.connect(n.destination)}catch(e){let r=e;t.getTracks().forEach(Jl);try{await n.close()}catch{}throw l.current=Ul(),r instanceof Error?r:Error(String(r))}},t[5]=u):u=t[5];let d=u,f;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(f=async()=>{let e=l.current;if(e.started=!1,r(0),e.processor)try{e.processor.onaudioprocess=null}catch{}Wl(e.processor),Wl(e.source),Wl(e.gain),e.stream&&e.stream.getTracks().forEach(ql);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current(Hl(t)),e.context)try{await e.context.close()}catch{}l.current===e&&(l.current=Ul())},t[6]=f):f=t[6];let p=f,m,h;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>()=>{p().catch(e=>{a.current?.(e instanceof Error?e:Error(String(e)))})},h=[p],t[7]=m,t[8]=h):(m=t[7],h=t[8]),(0,Z.useEffect)(m,h);let g;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(g=async()=>{try{await d()}catch(e){let t=e,n=t instanceof Error?t:Error(String(t));throw a.current?.(n),n}},t[9]=g):g=t[9];let _;return t[10]===n?_=t[11]:(_={start:g,stop:p,volume:n},t[10]=n,t[11]=_),_}function ql(e){try{e.stop()}catch{}}function Jl(e){try{e.stop()}catch{}}function Yl(){}var Xl=1e3,Zl=e=>e instanceof Error?e:Error(String(e)),Ql=()=>{let e=Ai.getState(),t=e.sttLanguage?.trim();return e.sttProvider===`openai-compatible`?{provider:`openai-compatible`,...t?{language:t}:{},openaiCompatible:{baseUrl:e.sttServerUrl,model:e.sttModel,...e.sttApiKey?{apiKey:e.sttApiKey}:{}}}:{provider:`local`,...t?{language:t}:{},localModel:e.sttLocalModel}};function $l(e={}){let{onTranscript:t,onError:n,canStart:r}=e,[i,a]=(0,Z.useState)(`idle`),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(0),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),m=(0,Z.useRef)(i);(0,Z.useEffect)(()=>{m.current=i},[i]);let h=(0,Z.useRef)(``),g=(0,Z.useRef)(null),_=(0,Z.useRef)({starting:!1,confirming:!1,cancelling:!1}),v=(0,Z.useRef)(t),y=(0,Z.useRef)(n);(0,Z.useEffect)(()=>{v.current=t,y.current=n},[t,n]);let b=(0,Z.useRef)(null);b.current||=new Fl({client:Al,getStartOptions:Ql});let x=(0,Z.useCallback)(()=>{g.current&&=(clearInterval(g.current),null)},[]),S=(0,Z.useCallback)(()=>{g.current||=setInterval(()=>{l(e=>e+1)},Xl)},[]),C=(0,Z.useCallback)(e=>{let t=Zl(e);d(t.message);let n=t.reasonCode;p(typeof n==`string`?n:null),y.current?.(t)},[]),w=(0,Z.useCallback)(()=>{d(null),p(null)},[]),T=(0,Z.useCallback)(()=>{b.current?.clearAll(),h.current=``,s(``)},[]);(0,Z.useEffect)(()=>Al.onPartial((e,t)=>{let n=b.current?.getDictationId();!n||e!==n||(h.current=t,s(t))}),[]),(0,Z.useEffect)(()=>Al.subscribeConnectionStatus(e=>{e&&m.current===`recording`&&b.current?.restartStream().catch(e=>{C(e)})}),[C]);let E=Kl({onPcmSegment:e=>{b.current?.enqueueSegment(e)},onError:e=>{y.current?.(e)}}),D=(0,Z.useRef)(E.stop);(0,Z.useEffect)(()=>{D.current=E.stop},[E.stop]);let O=(0,Z.useCallback)(e=>{l(0),a(`idle`);let t=e.trim().length>0?e.trim():h.current.trim();return T(),t?(v.current?.(t),t):null},[T]),k=(0,Z.useCallback)(e=>{b.current?.hasSegments()?a(`failed`):a(`idle`),C(e)},[C]),A=(0,Z.useCallback)(async()=>{let e=_.current;if(!(e.starting||e.confirming||e.cancelling)&&m.current===`idle`&&!(r&&!r())){e.starting=!0,w(),s(``),l(0),a(`recording`),m.current=`recording`,T();try{await E.start(),S(),await b.current?.restartStream().catch(e=>{C(e)})}catch(e){await E.stop().catch(()=>void 0),x(),a(`idle`),m.current=`idle`,C(e)}finally{e.starting=!1}}},[E,r,w,T,C,S,x]),j=(0,Z.useCallback)(async()=>{let e=_.current;if(!e.cancelling&&(m.current===`recording`||m.current===`uploading`)){e.cancelling=!0,x(),l(0),w(),a(`idle`),m.current=`idle`;try{b.current?.cancel()}catch{}T();try{await E.stop()}catch{}finally{e.cancelling=!1}}},[E,w,T,x]),M=(0,Z.useCallback)(async()=>{let e=_.current;if(e.confirming||m.current!==`recording`)return null;e.confirming=!0,w(),x();try{await E.stop(),a(`uploading`),m.current=`uploading`;let e=b.current?.getFinalSeq()??-1;if(e<0)return O(``);let t=await b.current.finish(e);return O(t.text)}catch(e){return k(e),null}finally{e.confirming=!1}},[E,w,k,O,x]),N=(0,Z.useCallback)(async()=>{if(m.current!==`failed`||!b.current?.hasSegments())return null;w(),a(`uploading`),m.current=`uploading`;try{b.current.resetStreamForReplay();let e=b.current.getFinalSeq(),t=await b.current.finish(e);return O(t.text)}catch(e){return k(e),null}},[w,k,O]),P=(0,Z.useCallback)(()=>{if(m.current!==`failed`)return null;let e=h.current.trim();l(0),a(`idle`),m.current=`idle`,w();try{b.current?.cancel()}catch{}return T(),e?(v.current?.(e),e):null},[w,T]),F=(0,Z.useCallback)(()=>{l(0),a(`idle`),m.current=`idle`,w(),T()},[w,T]);return(0,Z.useEffect)(()=>{if(i!==`recording`||f!==`model_download_in_progress`)return;let e=setInterval(()=>{m.current!==`recording`||b.current?.getDictationId()||b.current?.restartStream().then(()=>{w()}).catch(e=>{C(e)})},3e3);return()=>clearInterval(e)},[i,f,w,C]),(0,Z.useEffect)(()=>()=>{x(),D.current().catch(()=>void 0),b.current?.cancel()},[x]),{status:i,isRecording:i===`recording`,isProcessing:i===`uploading`,partialTranscript:o,volume:E.volume,duration:c,error:u,errorReason:f,startDictation:A,confirmDictation:M,cancelDictation:j,retryFailedDictation:N,acceptPartialTranscript:P,discardFailedDictation:F}}var eu=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},tu=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=Ga(),i=Math.min(1,Math.max(0,n)),a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=[.45,.7,1,.7,.45],t[0]=a):a=t[0];let o=a,s;return t[1]!==r||t[2]!==i?(s=(0,$.jsx)(`div`,{className:`flex h-6 w-10 flex-shrink-0 items-center justify-center gap-1`,"aria-hidden":`true`,children:o.map((e,t)=>(0,$.jsx)(`span`,{className:`h-full w-1 rounded-full transition-transform duration-75 ease-out motion-reduce:transition-none`,style:{backgroundColor:r.colors.primary.base,transform:`scaleY(${.25+i*e*.75})`}},t))}),t[1]=r,t[2]=i,t[3]=s):s=t[3],s},nu=e=>{let t=Ai(e=>e.sttLocalModel),[n,r]=Z.useState(null);return Z.useEffect(()=>{if(!e){r(null);return}let n=!1,i=async()=>{try{let e=await m(`/api/dictation/status`,{query:{provider:`local`,localModel:t}});if(!e.ok||n)return;let i=await e.json(),a=Array.isArray(i?.models)?i.models.find(e=>e.id===t):null;n||r(typeof a?.downloadProgress==`number`?a.downloadProgress:null)}catch{}};i();let a=setInterval(()=>{i()},2e3);return()=>{n=!0,clearInterval(a)}},[e,t]),e?n:null},ru=e=>{let t=(0,Q.c)(86),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:s,disabled:c,onInsert:l,onInsertAndSend:u,onActiveChange:d,onContentHeightChange:f,renderTrigger:p,topAccessory:m}=e,h=p===void 0||p,{t:g}=ct(),{currentTheme:_}=Ga(),v=Ai(iu),y=q(au),b;t[0]===y?b=t[1]:(b=Za(Qa(`toggle_dictation`,y)),t[0]=y,t[1]=b);let x=b,[S]=Z.useState(ou),C=Z.useRef(null),w=Z.useRef(l),T=Z.useRef(u),E,D;t[2]!==l||t[3]!==u?(E=()=>{w.current=l,T.current=u},D=[l,u],t[2]=l,t[3]=u,t[4]=E,t[5]=D):(E=t[4],D=t[5]),Z.useEffect(E,D);let O;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(O={onTranscript:e=>{let t=C.current;C.current=null,t===`send`?T.current(e):w.current(e)}},t[6]=O):O=t[6];let{status:k,partialTranscript:A,volume:j,duration:M,error:N,errorReason:P,startDictation:F,confirmDictation:I,cancelDictation:L,retryFailedDictation:R,acceptPartialTranscript:z,discardFailedDictation:B}=$l(O),V=k===`recording`&&P===`model_download_in_progress`,H=nu(V),U=Z.useRef(k),W,ee;t[7]===k?(W=t[8],ee=t[9]):(W=()=>{U.current=k},ee=[k],t[7]=k,t[8]=W,t[9]=ee),Z.useEffect(W,ee);let G,K;t[10]!==d||t[11]!==k?(G=()=>{d?.(k!==`idle`)},K=[k,d],t[10]=d,t[11]=k,t[12]=G,t[13]=K):(G=t[12],K=t[13]),Z.useLayoutEffect(G,K);let te,ne;t[14]!==I||t[15]!==F?(te=()=>{let e=()=>{U.current===`idle`?F():U.current===`recording`&&(C.current=`insert`,I())};return window.addEventListener(`openchamber:dictation-toggle`,e),()=>window.removeEventListener(`openchamber:dictation-toggle`,e)},ne=[F,I],t[14]=I,t[15]=F,t[16]=te,t[17]=ne):(te=t[16],ne=t[17]),Z.useEffect(te,ne);let re,ie;t[18]!==L||t[19]!==I||t[20]!==k?(re=()=>{if(k!==`recording`)return;let e=e=>{if(!e.isComposing){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault(),e.stopPropagation(),C.current=`insert`,I();return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),L())}};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},ie=[k,I,L],t[18]=L,t[19]=I,t[20]=k,t[21]=re,t[22]=ie):(re=t[21],ie=t[22]),Z.useEffect(re,ie);let ae=Z.useRef(null),oe=Z.useRef(null),se=Z.useRef(null),[ce,le]=Z.useState(null),ue=k!==`idle`,de=Z.useRef(f),fe,pe;t[23]===f?(fe=t[24],pe=t[25]):(fe=()=>{de.current=f},pe=[f],t[23]=f,t[24]=fe,t[25]=pe),Z.useEffect(fe,pe);let me=Z.useRef(!1),he;t[26]===ue?he=t[27]:(he=()=>{if(!ue){me.current&&(me.current=!1,de.current?.(null));return}let e=oe.current,t=se.current;if(!e||!t)return;let n=window.getComputedStyle(e),r=(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0);me.current=!0,de.current?.(t.offsetHeight+r),e.scrollTop=e.scrollHeight},t[26]=ue,t[27]=he);let ge;t[28]!==N||t[29]!==ue||t[30]!==A||t[31]!==k?(ge=[ue,A,k,N],t[28]=N,t[29]=ue,t[30]=A,t[31]=k,t[32]=ge):ge=t[32],Z.useLayoutEffect(he,ge);let _e,ve;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(_e=()=>()=>{me.current&&(me.current=!1,de.current?.(null))},ve=[],t[33]=_e,t[34]=ve):(_e=t[33],ve=t[34]),Z.useEffect(_e,ve);let ye,be;if(t[35]===ue?(ye=t[36],be=t[37]):(ye=()=>{if(!ue)return;let e=ae.current?.closest(`[data-chat-input-footer="true"]`);e&&e.offsetHeight>0&&le(e.offsetHeight)},be=[ue],t[35]=ue,t[36]=ye,t[37]=be),Z.useLayoutEffect(ye,be),!S||!v)return null;let xe=k!==`idle`,Se;t[38]===I?Se=t[39]:(Se=e=>{C.current=e,I()},t[38]=I,t[39]=Se);let Ce=Se,we;t[40]===R?we=t[41]:(we=()=>{C.current=`insert`,R()},t[40]=R,t[41]=we);let Te=we,Ee;bb0:{if(k===`failed`){Ee=``;break bb0}if(k===`uploading`){let e;t[42]===g?e=t[43]:(e=g(`chat.dictation.processing`),t[42]=g,t[43]=e),Ee=e;break bb0}if(V){let e;t[44]!==H||t[45]!==g?(e=H===null?g(`chat.dictation.downloadingModel`):g(`chat.dictation.downloadingModelProgress`,{percent:String(H)}),t[44]=H,t[45]=g,t[46]=e):e=t[46],Ee=e;break bb0}let e;t[47]===g?e=t[48]:(e=g(`chat.dictation.listening`),t[47]=g,t[48]=e),Ee=e}let De=Ee,Oe;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(Oe={onMouseDown:su,onPointerDownCapture:cu},t[49]=Oe):Oe=t[49];let ke=Oe,Ae;t[50]!==x||t[51]!==c||t[52]!==i||t[53]!==o||t[54]!==xe||t[55]!==h||t[56]!==F||t[57]!==g?(Ae=h?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{F()},disabled:c||xe,title:x?`${g(`chat.dictation.start`)} (${x})`:g(`chat.dictation.start`),"aria-label":g(`chat.dictation.start`),children:(0,$.jsx)(X,{name:`mic`,className:Y(o,`text-current`)})}):null,t[50]=x,t[51]=c,t[52]=i,t[53]=o,t[54]=xe,t[55]=h,t[56]=F,t[57]=g,t[58]=Ae):Ae=t[58];let je;t[59]!==z||t[60]!==L||t[61]!==Ce||t[62]!==_||t[63]!==B||t[64]!==M||t[65]!==N||t[66]!==ce||t[67]!==i||t[68]!==a||t[69]!==o||t[70]!==xe||t[71]!==r||t[72]!==V||t[73]!==A||t[74]!==De||t[75]!==n||t[76]!==Te||t[77]!==s||t[78]!==k||t[79]!==g||t[80]!==m||t[81]!==j?(je=xe?(0,$.jsxs)(`div`,{ref:ae,className:Y(`absolute inset-0 z-50 flex flex-col overflow-x-hidden overflow-y-hidden`,r&&`oc-composer-morph-content-fade`),style:{borderRadius:n,backgroundColor:_.colors.surface.subtle},role:`dialog`,"aria-label":g(`chat.dictation.overlayAria`),children:[m,(0,$.jsx)(`div`,{ref:oe,className:Y(`scrollbar-none flex-1 min-h-0 overflow-y-auto px-3`,r?`pt-3.5 pb-2.5`:`pt-5 pb-2`),children:(0,$.jsxs)(`div`,{ref:se,className:Y(!A&&`translate-y-1.5`),children:[A?(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label whitespace-pre-wrap`,style:{color:_.colors.surface.foreground},children:A}):k===`recording`?(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,style:{color:_.colors.surface.mutedForeground},children:[(0,$.jsx)(tu,{volume:j}),(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,children:De})]}):(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,style:{color:_.colors.surface.mutedForeground},children:De}),k===`failed`?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:_.colors.status.error},children:N||g(`chat.dictation.failed`)}):null,k===`recording`&&N&&!V?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:_.colors.status.warning},children:N}):null]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center gap-x-3`,a),style:ce?{height:ce}:void 0,children:[k===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`relative ml-1 flex h-2 w-2 flex-shrink-0`,"aria-hidden":`true`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full opacity-60`,style:{backgroundColor:_.colors.status.error}}),(0,$.jsx)(`span`,{className:`relative inline-flex h-2 w-2 rounded-full`,style:{backgroundColor:_.colors.status.error}})]}),(0,$.jsx)(tu,{volume:j}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:_.colors.surface.mutedForeground},children:eu(M)})]}):k===`uploading`?(0,$.jsx)(X,{name:`loader-4`,className:`ml-1 h-4 w-4 animate-spin`,style:{color:_.colors.surface.mutedForeground}}):null,(0,$.jsx)(`div`,{className:Y(`ml-auto flex items-center`,r?`gap-x-1`:`gap-x-1.5 md:gap-x-3`),children:k===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{L()},title:g(`chat.dictation.cancel`),"aria-label":g(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>Ce(`insert`),title:g(`chat.dictation.insert`),"aria-label":g(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-primary hover:text-primary`),onClick:()=>Ce(`send`),title:g(`chat.dictation.insertAndSend`),"aria-label":g(`chat.dictation.insertAndSend`),children:(0,$.jsx)(X,{name:`send-plane-2`,className:s})})]}):k===`uploading`?(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{L()},title:g(`chat.dictation.cancel`),"aria-label":g(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:B,title:g(`chat.dictation.discard`),"aria-label":g(`chat.dictation.discard`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:Te,title:g(`chat.dictation.retry`),"aria-label":g(`chat.dictation.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:o})}),A.trim()?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{C.current=`insert`,z()},title:g(`chat.dictation.insert`),"aria-label":g(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}):null]})})]})]}):null,t[59]=z,t[60]=L,t[61]=Ce,t[62]=_,t[63]=B,t[64]=M,t[65]=N,t[66]=ce,t[67]=i,t[68]=a,t[69]=o,t[70]=xe,t[71]=r,t[72]=V,t[73]=A,t[74]=De,t[75]=n,t[76]=Te,t[77]=s,t[78]=k,t[79]=g,t[80]=m,t[81]=j,t[82]=je):je=t[82];let Me;return t[83]!==Ae||t[84]!==je?(Me=(0,$.jsxs)($.Fragment,{children:[Ae,je]}),t[83]=Ae,t[84]=je,t[85]=Me):Me=t[85],Me};function iu(e){return e.dictationEnabled}function au(e){return e.shortcutOverrides}function ou(){return!se()&&Gl()}function su(e){return e.preventDefault()}function cu(e){e.pointerType===`touch`&&e.preventDefault()}var lu=2e3,uu=ce((e,t)=>({pending:!1,expiresAt:null,arm:(t=lu)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),du=new class{inFlightByScope=new WeakMap;generationByScope=new WeakMap;run(e){let t=this.inFlightByScope.get(e.scope);t||(t=new Map,this.inFlightByScope.set(e.scope,t));let n=t.get(e.key);if(n)return n;let r=this.generationByScope.get(e.scope);r||(r=new Map,this.generationByScope.set(e.scope,r));let i=(r.get(e.key)??0)+1;r.set(e.key,i);let a=e.request(()=>r?.get(e.key)!==i);return t.set(e.key,a),a.finally(()=>{t?.get(e.key)===a&&t.delete(e.key)}).catch(()=>{}),a}},fu=15e3,pu=100,mu=new Map,hu=new Map,gu=e=>`${e.runtimeKey}\n${e.directory}\n${e.sessionID}`,_u=e=>{let t=gu(e),n=e.now??Date.now(),r=hu.get(t);if(r&&n-r.loadedAt<fu)return Promise.resolve(r.sessions);let i=mu.get(t);if(i)return i;let a=e.request().then(e=>{for(hu.delete(t);hu.size>=pu;){let e=hu.keys().next().value;if(typeof e!=`string`)break;hu.delete(e)}return hu.set(t,{loadedAt:Date.now(),sessions:e}),e});return mu.set(t,a),a.then(()=>{mu.get(t)===a&&mu.delete(t)},()=>{mu.get(t)===a&&mu.delete(t)}),a},vu=(e,t)=>e.id<t.id?-1:+(e.id>t.id),yu=(e,t,n)=>{let r=new Set(e.map(e=>e.id)),i=t.filter(e=>!!e?.id&&!r.has(e.id)&&e.parentID===n);return i.length===0?e:[...e,...i].sort(vu)},bu=30;function xu(e){return e===`busy`||e===`retry`}var Su=new Map;function Cu(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function wu(e){if(e instanceof Error)return e.message;if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.message;if(typeof t==`string`&&t.length>0)return t}try{return JSON.stringify(e)}catch{return String(e)}}function Tu(e,t){if(!e.error)return;let n=e.response?.status;throw Error(`${t} failed${n?` (${n})`:``}: ${wu(e.error)}`)}function Eu(e,t){let n=Pr();if(!n)return!1;let r=n.getTranscript(Bi(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>qr()}function Du(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function Ou(e,t,n){let r=[...e.getState().session],i=Zr.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function ku(){let e=Ir(),t=Vt(),n=Hn(),r=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),i=(0,Z.useCallback)((t,n=e)=>{let r=Pr();if(!r||!t)return Cu({kind:`unknown`,loadedTurns:0},!1);let i=Bi(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return Cu(a.boundary,o?.status===`loading`)},[e]),o=(0,Z.useCallback)((e,t)=>{if(t.length===0)return;let r=n.getChild(e);if(!r)return;let i=r.getState(),a={session_status:{...i.session_status},session_status_observed_at:{...i.session_status_observed_at},session_error_at:{...i.session_error_at},session_diff:{...i.session_diff},todo:{...i.todo},permission:{...i.permission},question:{...i.question}};At(a,t),Xt(r,t),r.setState(a);for(let n of t)qi(e,n)},[n]),s=(0,Z.useCallback)((t=e)=>{let n=Su.get(t);if(n)return Su.delete(t),Su.set(t,n),n;let r=new Set;for(Su.set(t,r);Su.size>bu;){let e=Su.keys().next().value;if(!e)break;let t=[...Su.get(e)??[]];Su.delete(e),o(e,t)}return r},[e,o]),c=(0,Z.useCallback)((r,i=e)=>{let a=i===e?t:n.ensureChild(i,{bootstrap:!1}),c=s(i),l=_n(a.getState()),u=Qr(),d=$r({seen:c,keep:r,limit:u,preserve:l});if(o(i,d),yt()){let e=new Set([r,...c,...l]),t=(Pr()?.getCacheBudget?.().listCanonical({directory:i})??[]).map(e=>e.scope.sessionID),n=(t.length>0?t:Array.from(c)).filter(t=>t===r||e.has(t)?!1:Eu(i,t));if(n.length>0){for(let e of n)c.delete(e);o(i,n)}}},[n,e,s,o,t]),l=(0,Z.useCallback)(async(r,i)=>{let a=i?.directory??e;if(!r||!a||a===`global`)return;let o=a===e?t:n.ensureChild(a,{bootstrap:!1}),s=o.getState(),c=s.session_status?.[r],l=s.session_status_observed_at?.[r];try{i?.purpose===`prepend`||i?.before?await si(a,r):await _i(a,r)}catch{return}if(i?.isStale?.())return;let u=Pr()?.getTranscript(Bi(a,r));ir({directory:a,sessionID:r,store:o,transcript:u,isStale:i?.isStale}),await pi({directory:a,sessionID:r,store:o,statusBeforePull:c,statusObservedAtBeforePull:l,hasMessages:(u?.messageOrder.length??0)>0,isTailPage:!i?.before,isStale:i?.isStale})},[n,t,e]),u=(0,Z.useCallback)(async(t,i)=>{await ln();let a=typeof i==`boolean`?i:i?.force,o=typeof i==`object`?i.directory??e:e,s=n.ensureChild(o,{bootstrap:!1}),u=De.getScopedSdkClient(o);c(t,o);let d=r(t,o);return du.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=Pr(),i=Bi(o,t),c=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=Zr.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&c&&d.kind!==`unknown`&&p?.status!==`error`&&f&&fn(o,t)){ir({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!c||f),h=Du({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await Cn(async()=>{let e=await u.session.get({sessionID:t,directory:o});return Tu(e,`session.get`),e});if(n.data&&!e()){let r=nr(n.data);e()||Ou(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?l(t,{isStale:e,directory:o}):Promise.resolve()])}})},[n,r,c,l,e]),d=(0,Z.useCallback)(async(t,r)=>{let i=r||e;if(!t||!i)return;let o=n.ensureChild(i,{bootstrap:!1}),s=De.getScopedSdkClient(i),c=await _u({runtimeKey:a(),directory:i,sessionID:t,request:async()=>{let e=await s.session.children({sessionID:t,directory:i});return Tu(e,`session.children`),e.data??[]}});o.setState(e=>{let n=yu(e.session,c,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})},[n,e]),f=(0,Z.useCallback)((t,n)=>{let r=i(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,i]),p=(0,Z.useCallback)((t,n)=>i(t,n?.directory??e).loading,[e,i]),m=(0,Z.useCallback)((t,n)=>i(t,n?.directory??e).complete,[e,i]),h=(0,Z.useCallback)(t=>{let n=t.directory||e;kr(Bi(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;kr(Bi(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;kr(Bi(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(async(t,r)=>{if(!t)return;await ln();let i=r?.directory??e;if(!i||i===`global`)return;let a=n.ensureChild(i,{bootstrap:!1}),o=a.getState().session_status?.[t]?.type;if(xu(o))throw Error(`refresh transcript busy`);try{await mr(i,t),ir({directory:i,sessionID:t,store:a})}catch(e){throw e instanceof Error&&e.message===`refresh transcript busy`?e:Error(`refresh transcript failed`)}},[n,e]);return(0,Z.useMemo)(()=>({ensureSessionRenderable:u,syncSession:u,loadChildren:d,hasMore:f,isLoading:p,isComplete:m,refreshSessionTranscript:v,optimistic:{add:h,remove:g,confirm:_}}),[u,d,f,p,m,v,h,g,_])}var Au=e=>e===`diff`||e===`file`||e===`preview-console`||e===`preview-annotation`,ju=e=>e===`original`||e===`modified`,Mu=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},Nu=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!Au(t.source))return null;let n=Mu(t.startLine),r=Mu(t.endLine);return!n||!r?null:{id:typeof t.id==`string`&&t.id.trim().length>0?t.id:`icd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,sessionKey:t.sessionKey,source:t.source,fileLabel:typeof t.fileLabel==`string`?t.fileLabel:`unknown`,startLine:n,endLine:r,side:ju(t.side)?t.side:void 0,code:typeof t.code==`string`?t.code:``,language:typeof t.language==`string`?t.language:`text`,text:typeof t.text==`string`?t.text:``,createdAt:Number.isFinite(t.createdAt)?Number(t.createdAt):Date.now()}},Pu=e=>{if(!e||typeof e!=`object`)return{};let t=Object.entries(e),n={};for(let[e,r]of t){if(!Array.isArray(r))continue;let t=r.map(Nu).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},Fu=ce()(ue(le((e,t)=>({drafts:{},addDraft:t=>{let n=`icd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,r={...t,id:n,createdAt:Date.now()};return e(e=>{let n=e.drafts[t.sessionKey]??[];return{drafts:{...e.drafts,[t.sessionKey]:[...n,r]}}}),n},updateDraft:(t,n,r)=>{e(e=>{let i=(e.drafts[t]??[]).map(e=>e.id===n?{...e,...r}:e);return{drafts:{...e.drafts,[t]:i}}})},removeDraft:(t,n)=>{e(e=>{let r=(e.drafts[t]??[]).filter(e=>e.id!==n);if(r.length===0){let{[t]:n,...r}=e.drafts;return{drafts:r}}return{drafts:{...e.drafts,[t]:r}}})},clearDrafts:t=>{e(e=>{let{[t]:n,...r}=e.drafts;return{drafts:r}})},getDrafts:e=>t().drafts[e]??[],consumeDrafts:n=>{let r=t().drafts[n]??[];if(r.length===0)return[];let i=[...r].sort((e,t)=>e.createdAt-t.createdAt);return e(e=>{let{[n]:t,...r}=e.drafts;return{drafts:r}}),i},getDraftCount:e=>(t().drafts[e]??[]).length,hasDrafts:e=>(t().drafts[e]??[]).length>0}),{name:`openchamber-inline-comment-drafts`,storage:Be(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:Pu(e.drafts)}}),{name:`inline-comment-draft-store`}));function Iu(e){let{fileLabel:t,startLine:n,endLine:r,side:i,language:a,code:o,text:s}=e;return e.source===`diff`&&i?`Comment on \`${t}\` lines ${n}-${r} (${i}):\n\`\`\`${a}\n${o}\n\`\`\`\n\n${s}`:e.source===`preview-console`?`Attached preview context from \`${t}\`:\n\`\`\`${a}\n${o}\n\`\`\`\n\n${s}`:e.source===`preview-annotation`?s?`${o}\n\n${s}`:o:`Comment on \`${t}\` lines ${n}-${r}:\n\`\`\`${a}\n${o}\n\`\`\`\n\n${s}`}function Lu(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(Iu).join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-BI5vwuaT.js","assets/rolldown-runtime-C0FnF6B9.js","assets/persistence-w-AiX2i4.js","assets/runtime-switch-BkpTTbEi.js","assets/desktop-CfLlmafK.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-base-ui-CnHfUmDN.js","assets/useUIStore-CNLmCoPU.js","assets/vendor-pathe-vBmvQE8f.js","assets/vendor-react-DLPElpoQ.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/vendor-pierre-diffs-DX7XTPG3.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/vendor-hast-util-to-html-B0p1k5Xa.js","assets/vendor-character-entities-legacy-Wut6vMuj.js","assets/vendor-character-entities-html4-DlN_yAFd.js","assets/vendor-ccount-CyGsA0u7.js","assets/vendor-comma-separated-tokens-B9ouxNNS.js","assets/vendor-oniguruma-to-es-CrHzjjSU.js","assets/vendor-oniguruma-parser-D2DIvhSP.js","assets/vendor-diff-Dq7CZNim.js","assets/vendor-lru_map-DpDied8H.js","assets/vendor-reactuses-core-DDoDDyM9.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/clipboard-D35XSwID.js","assets/store-CL3WP48T.js","assets/dialog-x2hirWBd.js","assets/utils-CTL16t2f.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-CLpn1mIz.js","assets/button-z0GOBtWi.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-SPe4jOwX.js","assets/appThemeRegistry-G_zwgqAH.js","assets/platform-4eCmsdol.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/useMobileNavigationStore-CD0GRjaV.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-I0VWrB5V.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/markdown-worker-y3ewaqAK.js","assets/markdownHeightCache-CvUyZT4q.js","assets/useEffectiveDirectory-Bcj1wP95.js","assets/useWorkerHighlightedLines-DX9znDoW.js","assets/tooltip-CtH61mQh.js","assets/vendor-tanstack-react-virtual-tlDgH6PG.js"])))=>i.map(i=>d[i]);
2
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{c as t,f as n,i as r,n as i,r as a,x as o}from"./runtime-switch-BkpTTbEi.js";import{$ as s,B as c,C as l,Ct as u,Dt as d,G as f,I as p,It as m,J as h,K as g,M as _,N as v,Q as y,R as b,S as x,T as S,U as C,V as w,W as T,Y as E,Z as D,_ as O,at as k,b as A,ct as j,d as M,et as N,ft as P,it as F,j as I,lt as L,mt as R,nt as z,ot as B,pt as V,q as H,r as U,st as W,u as ee,ut as G,v as K,wt as te,x as ne,y as re,yt as ie,z as ae}from"./persistence-w-AiX2i4.js";import{u as oe,y as se}from"./desktop-CfLlmafK.js";import{a as ce,i as le,r as ue,t as de}from"./vendor-zustand-B4dlGEM2.js";import{c as fe,d as pe,f as me,l as he,nt as ge,rt as _e,tt as ve,u as ye}from"./vendor-base-ui-CnHfUmDN.js";import{At as be,Bt as xe,Ct as Se,Gt as Ce,Ht as we,Jt as Te,Kt as Ee,Nt as De,Pt as Oe,Rt as ke,St as Ae,Ut as je,Wt as Me,Yt as Ne,jt as Pe,kt as Fe,n as Ie,t as Le,zt as Re}from"./platform-4eCmsdol.js";import{g as ze,t as q,y as Be}from"./useUIStore-CNLmCoPU.js";import{a as Ve,n as He,o as Ue}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as We}from"./vendor-react-DLPElpoQ.js";import{i as Ge,n as Ke,s as qe,t as Je}from"./vendor-tanstack-react-query-D7pys_c9.js";import{B as Ye,R as Xe,V as Ze,c as Qe}from"./vendor-codemirror-autocomplete-DHomsvW7.js";import{i as $e,u as et}from"./vendor-pierre-diffs-DX7XTPG3.js";import{a as tt,d as nt,i as rt,l as it,n as J,o as at,r as ot,u as st}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ct,r as lt,t as ut}from"./clipboard-D35XSwID.js";import{i as dt,t as ft}from"./store-CL3WP48T.js";import{$ as pt,$a as mt,$n as ht,$r as gt,$t as _t,A as vt,Ai as yt,At as bt,Ba as xt,Bi as St,Bn as Ct,Ci as wt,Cn as Tt,Cr as Et,Ct as Dt,D as Ot,Da as kt,Dn as At,Dr as jt,E as Mt,Ei as Nt,En as Pt,F as Ft,Fa as It,Fi as Lt,Fr as Rt,G as zt,Ga as Bt,Gt as Vt,H as Ht,Ha as Ut,Hi as Wt,Hr as Gt,I as Kt,Ii as qt,In as Jt,Ir as Yt,It as Xt,J as Zt,Ja as Qt,K as $t,Ka as en,Kt as tn,Li as nn,Ln as rn,Lr as an,Lt as on,M as sn,Mi as cn,Mo as ln,Mt as un,N as dn,Ni as fn,Nr as pn,Nt as mn,O as hn,Oa as gn,On as _n,Or as vn,Ot as yn,P as bn,Pi as xn,Q as Sn,Qi as Cn,Qn as wn,Qr as Tn,Qt as En,R as Dn,Ri as On,Rn as kn,Rr as An,Rt as jn,S as Mn,Sa as Nn,Si as Pn,Sn as Fn,Sr as In,T as Ln,Ti as Rn,Tn as zn,Ua as Bn,Ui as Vn,Ut as Hn,Va as Un,Vi as Wn,Vr as Gn,W as Kn,Wa as qn,Wr as Jn,Wt as Yn,X as Xn,Xr as Zn,Xt as Qn,Y as $n,Yr as er,Z as tr,Zi as nr,Zn as rr,Zr as ir,Zt as ar,_i as or,_n as sr,_t as cr,a as lr,aa as ur,ai as dr,an as fr,at as pr,ba as mr,bi as hr,bo as gr,bt as _r,ci as vr,cn as yr,da as br,di as xr,dn as Sr,dt as Cr,ea as wr,eo as Tr,er as Er,et as Dr,f as Or,fa as kr,fi as Ar,fn as jr,fr as Mr,g as Nr,ga as Pr,gi as Fr,gn as Ir,gt as Lr,ha as Rr,hn as zr,hr as Br,ht as Vr,i as Hr,in as Ur,it as Wr,j as Gr,ja as Kr,ji as qr,jr as Jr,jt as Yr,k as Xr,ka as Zr,ki as Qr,kn as $r,ko as ei,kr as ti,kt as ni,l as ri,la as ii,ln as ai,m as oi,ma as si,mi as ci,mn as li,mt as ui,n as di,na as fi,ni as pi,nn as mi,nt as hi,oi as gi,pa as _i,pi as vi,pn as yi,pt as bi,q as xi,qa as Si,qi as Ci,qt as wi,rn as Ti,ro as Ei,rt as Di,si as Oi,sn as ki,ta as Ai,ti as ji,tn as Mi,tt as Ni,ui as Pi,un as Fi,va as Ii,vi as Li,vt as Ri,w as zi,wa as Bi,wi as Vi,wr as Hi,wt as Ui,x as Wi,xi as Gi,xr as Ki,ya as qi,yi as Ji,yo as Yi,z as Xi,za as Zi,zi as Qi,zr as $i}from"./useMobileNavigationStore-CD0GRjaV.js";import{a as ea,i as ta,l as na,n as ra,o as ia,r as aa,s as oa,t as sa}from"./dialog-x2hirWBd.js";import{n as ca,t as Y}from"./utils-CTL16t2f.js";import{t as la}from"./AgentAvatar-Di8F4QJh.js";import{n as X}from"./Icon-CLpn1mIz.js";import{t as ua}from"./button-z0GOBtWi.js";import{E as da,n as fa}from"./gitApi-BE0vA4zm.js";import{A as pa,C as ma,G as ha,K as ga,M as _a,O as va,Q as ya,S as ba,T as xa,X as Sa,Z as Ca,a as wa,b as Ta,d as Ea,et as Da,g as Oa,h as ka,i as Aa,j as ja,k as Ma,n as Na,o as Pa,p as Fa,s as Ia,u as La,v as Ra,w as za,x as Ba}from"./projectMeta-CvUuy-j5.js";import{t as Va}from"./input-BG3VWTIF.js";import{i as Ha,n as Ua,t as Wa}from"./tooltip-CtH61mQh.js";import{n as Ga,t as Ka}from"./useThemeSystem-DMzWVJaW.js";import{A as qa,B as Ja,C as Ya,K as Xa,M as Za,P as Qa,_ as $a,a as eo,f as to,g as no,h as ro,i as io,m as ao,o as oo,p as so,r as co,t as lo,v as uo,w as fo,y as po}from"./radio-D_a28OlM.js";import{i as mo,t as ho}from"./OverlayScrollbar-DlNZho3q.js";import{_ as go,a as _o,d as vo,f as yo,g as bo,h as xo,i as So,l as Co,m as wo,n as To,u as Eo,v as Do,x as Oo}from"./markdownTheme-SPe4jOwX.js";import{n as ko,r as Ao,t as jo}from"./useRuntimeAPIs-DSLXJybW.js";import{A as Mo,B as No,C as Po,D as Fo,E as Io,F as Lo,H as Ro,I as zo,L as Bo,M as Vo,N as Ho,O as Uo,R as Wo,S as Go,T as Ko,U as qo,V as Jo,a as Yo,b as Xo,c as Zo,f as Qo,i as $o,j as es,k as ts,l as ns,m as rs,n as is,o as as,p as os,r as ss,s as cs,t as ls,u as us,w as ds,x as fs,z as ps}from"./insertionBoundaries-CJksyugt.js";import{A as ms,C as hs,D as gs,E as _s,F as vs,M as ys,N as bs,O as xs,P as Ss,R as Cs,S as ws,T as Ts,_ as Es,a as Ds,b as Os,d as ks,f as As,g as js,h as Ms,i as Ns,j as Ps,k as Fs,l as Is,m as Ls,p as Rs,r as zs,s as Bs,t as Vs,v as Hs,w as Us,x as Ws,y as Gs}from"./appThemeRegistry-G_zwgqAH.js";import{_ as Ks,a as qs,c as Js,g as Ys,l as Xs,o as Zs,t as Qs,v as $s,y as ec}from"./vendor-dnd-kit-core-CvWxUPdb.js";import{i as tc,n as nc,o as rc,s as ic,t as ac}from"./vendor-dnd-kit-sortable-hHdP9lLb.js";import{a as oc,n as sc,t as cc}from"./url-KeihbE0d.js";import{d as lc,h as uc,o as dc,u as fc}from"./markdown-worker-y3ewaqAK.js";import{n as pc}from"./useEffectiveDirectory-Bcj1wP95.js";import{a as mc,c as hc,d as gc,f as _c,i as vc,l as yc,n as bc,r as xc,s as Sc,t as Cc}from"./FadeInOnReveal-CV2s6YN8.js";import{A as wc,C as Tc,D as Ec,E as Dc,M as Oc,O as kc,S as Ac,T as jc,a as Mc,b as Nc,c as Pc,g as Fc,h as Ic,i as Lc,j as Rc,k as zc,o as Bc,p as Vc,r as Hc,s as Uc,t as Wc,v as Gc,w as Kc,x as qc,y as Jc}from"./useWorkerHighlightedLines-DX9znDoW.js";import{t as Yc}from"./vendor-cmdk-CeAGfrLo.js";import{t as Xc}from"./sortable-tabs-strip-CNDgyX0B.js";import{n as Zc,t as Qc}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";import{i as $c}from"./markdownHeightCache-CvUyZT4q.js";import{i as el,t as tl}from"./vendor-framer-motion-DFy_BSVd.js";import{t as nl}from"./vendor-legendapp-list-WE32lwNk.js";var Z=e(_e(),1),Q=We(),$=ge(),rl=e(ve(),1),il=`openchamber:close-embedded-session-chat`,al=`openchamber:embedded-visibility`,ol=`openchamber:embedded-visibility-request`,sl=e=>new URLSearchParams(e).get(`ocPanel`)===`session-chat`,cl=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),ll=(e,t,n,r)=>{if(typeof window>`u`)return``;let i=new URL(window.location.pathname,window.location.origin);return i.searchParams.set(`ocPanel`,`session-chat`),i.searchParams.set(`surface`,`desktop`),i.searchParams.set(`sessionId`,e),n?i.searchParams.set(`readOnly`,`1`):i.searchParams.delete(`readOnly`),t&&t.trim().length>0?i.searchParams.set(`directory`,t):i.searchParams.delete(`directory`),i.searchParams.set(`themeMode`,r.mode),i.searchParams.set(`lightThemeId`,r.lightThemeId),i.searchParams.set(`darkThemeId`,r.darkThemeId),i.searchParams.set(`themeVariant`,r.currentTheme.metadata.variant===`dark`?`dark`:`light`),i.searchParams.set(`currentTheme`,JSON.stringify(r.currentTheme)),i.hash=``,i.toString()},ul=(e,t,n,r,i,a)=>{let o=cl(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=ll(n,r,i,a);return e.set(t,{signature:o,src:c}),c},dl=null,fl=()=>{if(dl!==null)return dl;if(typeof window>`u`)return dl=!1,!1;try{return dl=new URLSearchParams(window.location.search).get(`ocPanel`)===`session-chat`,dl}catch{return dl=!1,!1}},pl=()=>{if(!fl())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},ml=Ve(`OpenChamberMedia`);function hl(){return Ie()&&He.getPlatform()===`android`&&He.isPluginAvailable(`OpenChamberMedia`)}async function gl(e){if(!hl())return null;let t=await ml.pickMedia({limit:e});if(t.cancelled)return[];let n=[];for(let e of t.files){let t=await fetch(He.convertFileSrc(e.path));if(!t.ok)throw Error(`Native media fetch failed (${t.status})`);let r=await t.blob();n.push(new File([r],e.name,{type:e.mimeType}))}return n}var _l=(e,t)=>{let n=t.trim();if(!n.length)return[...e].sort((e,t)=>e.scope===`project`&&t.scope!==`project`?-1:e.scope!==`project`&&t.scope===`project`?1:e.name.localeCompare(t.name));let r=bi([...e],n,e=>[e.name,e.description??``]);return r.sort((e,t)=>e.score===t.score?e.item.scope===`project`&&t.item.scope!==`project`?-1:e.item.scope!==`project`&&t.item.scope===`project`?1:e.item.name.localeCompare(t.item.name):e.score-t.score),r.map(e=>e.item)},vl=new Map,yl=(e,t,n)=>`${+!!t}:${n}:${e.map(e=>`${e.id}\0${e.title}\0${e.subtitle??``}\0${e.badge??``}\0${e.iconName}`).join(`|`)}`,bl=async e=>{let t=ys(`--surface-foreground`);return Promise.all(e.slice(0,40).map(async e=>{let n=`${e.iconName}:${t}`,r=vl.get(n);return r===void 0&&(r=await qo(e.iconName,t)??``,vl.set(n,r)),{id:e.id,title:e.title,subtitle:e.subtitle??``,badge:e.badge??``,iconBase64:r}}))},xl=[],Sl=e=>void 0,Cl=()=>void 0;function wl(e){let t=Cs()&&e.enabled&&Gs(e.isMobile),n=(0,Z.useRef)(null),r=(0,Z.useRef)(e.text),i=(0,Z.useRef)(!1),a=(0,Z.useRef)(-1),o=(0,Z.useRef)(null),s=(0,Z.useRef)(``),c=(0,Z.useRef)([]),l=(0,Z.useRef)(Os()),u=J(e.onText),d=J(e.onSend),f=J(e.onAbort),p=J(e.onAttach),m=J(e.onFiles),h=J(e.onRemoveAttachment),g=J(e.onOpenModel),_=J(e.onCycleAgent),v=J(e.onOpenAgent),y=J(e.onScrollToBottom),b=J(e.onAutocompleteAccept??Sl),x=J(e.onAutocompleteDismiss??Cl),S=J(e=>{typeof document>`u`||Ms(document.documentElement,e)});Rs.bind({onText:(e,t,n)=>{vs({incoming:e,replacedText:o.current})||(o.current=null,r.current=e,i.current=!0,u(e,t,n))},onSend:e=>{r.current=e,d(e)},onAbort:f,onAttach:p,onFiles:m,onRemoveAttachment:h,onOpenModel:g,onCycleAgent:_,onOpenAgent:v,onHeight:S,onScrollToBottom:y,onAutocompleteAccept:e=>{i.current=!1,b(e)},onAutocompleteDismiss:x});let C=()=>({text:e.text,placeholder:e.placeholder,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel,modelIcon:s.current,canSend:e.canSend,canAbort:e.canAbort,attachmentCount:e.attachmentCount,attachmentPreviews:c.current,citationRanges:Te(e.text,e.attachments.map(e=>e.filename)),chipRanges:Es(Us(e.text,e.chipHighlights),ys(`--primary`)),appearance:typeof document>`u`?`dark`:gs(document.documentElement),attachAria:e.attachAria,attachTitle:e.attachTitle,attachPhotosLabel:e.attachPhotosLabel,attachFilesLabel:e.attachFilesLabel,attachCancelLabel:e.attachCancelLabel,sendAria:e.sendAria,queueAria:e.queueAria,stopAria:e.stopAria,modelAria:e.modelAria,agentAria:e.agentAria,agentLabel:e.agentLabel,agentColor:_s(e.agentName||void 0),agentIdenticon:xs(e.agentName||void 0),suppressed:e.suppressed,showScrollToBottom:e.showScrollToBottom,scrollAria:e.scrollAria,autocomplete:l.current});(0,Z.useLayoutEffect)(()=>{if(!t||typeof document>`u`)return;let e=document.documentElement;return Ss(e,!0),()=>{Ss(e,!1)}},[t]),(0,Z.useEffect)(()=>{if(!t||typeof document>`u`)return;let e=document.documentElement,i=C();n.current=i,r.current=i.text,Rs.rememberText(i.text),Rs.retain(e,i);let a=As();return()=>{n.current=null,a(),Rs.release(e)}},[t]),(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=Ca(e.modelId,e.providerId),a={modelIcon:``,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};if(s.current=``,n.current&&={...n.current,...a},Ws().update(a),i)return ms(i).then(t=>{if(r)return;let i=t??``;s.current=i;let a={modelIcon:i,modelLabel:e.modelLabel,modelVariantLabel:e.modelVariantLabel};n.current&&={...n.current,...a},Ws().update(a)}),()=>{r=!0}},[t,e.modelId,e.providerId,e.modelLabel,e.modelVariantLabel]);let w=js(e.attachments);(0,Z.useEffect)(()=>{if(!t)return;let r=!1,i=e.attachments;if(i.length===0){c.current=[],n.current&&(n.current={...n.current,attachmentPreviews:[]},Rs.rememberState(n.current)),Ws().update({attachmentPreviews:[]});return}return Promise.all(i.map(async t=>{let n=t.mimeType.startsWith(`image/`)&&t.dataUrl?await Fs(t.dataUrl):``;return{id:t.id,filename:t.filename,mime:t.mimeType,thumbnailBase64:n??``,removeAria:e.removeAttachmentNamedAria(t.filename)}})).then(e=>{r||(c.current=e,n.current&&(n.current={...n.current,attachmentPreviews:e},Rs.rememberState(n.current)),Ws().update({attachmentPreviews:e}))}),()=>{r=!0}},[t,w]);let T=e.autocompleteRows??xl,E=e.autocompleteOpen===!0,D=e.autocompleteHighlightedIndex??0,O=yl(T,E,D);(0,Z.useEffect)(()=>{if(!t)return;let e=!1;if(!(E&&T.length>0)){let e=Os();hs(l.current,e)||(l.current=e,n.current&&(n.current={...n.current,autocomplete:e},Rs.rememberState(n.current)),Ws().update({autocomplete:e}));return}return bl(T).then(t=>{if(e)return;let r={open:t.length>0,highlightedIndex:Math.max(0,Math.min(D,Math.max(t.length-1,0))),rows:t};hs(l.current,r)||(l.current=r,n.current&&(n.current={...n.current,autocomplete:r},Rs.rememberState(n.current)),Ws().update({autocomplete:r}))}),()=>{e=!0}},[t,O]);let k=t?Us(e.text,e.chipHighlights).map(e=>`${e.start}:${e.end}:${e.triggerLength}`).join(`|`):``;return(0,Z.useEffect)(()=>{if(!t)return;let s=C(),c=n.current;if(c&&Ts(c,s)){i.current=!1,a.current=e.textPresetEpoch;return}n.current=s,Rs.rememberState(s);let l=e.textPresetEpoch!==a.current;a.current=e.textPresetEpoch;let u=bs({nextText:s.text,nativeOwnedText:r.current,echoingNative:i.current,preset:l});i.current=!1,!u.omitText&&u.forceText&&(o.current=r.current),u.omitText||(r.current=s.text);let d=Hs(c,s,u,{caret:e.caret});d&&Ws().update(d)},[t,e.text,e.textPresetEpoch,e.placeholder,e.modelLabel,e.modelVariantLabel,e.modelId,e.providerId,e.canSend,e.canAbort,e.attachmentCount,w,e.suppressed,e.attachAria,e.attachTitle,e.attachPhotosLabel,e.attachFilesLabel,e.attachCancelLabel,e.sendAria,e.queueAria,e.stopAria,e.modelAria,e.agentName,e.agentLabel,e.agentAria,e.showScrollToBottom,e.scrollAria,k]),t}var Tl=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},El=1e4,Dl=15e3,Ol=3e4,kl=3e4,Al=new class{socket=null;connectPromise=null;idleCloseTimer=null;pendingStarts=new Map;pendingFinishes=new Map;connectionListeners=new Set;partialListeners=new Set;activeDictations=0;get isConnected(){return this.socket?.readyState===WebSocket.OPEN}subscribeConnectionStatus(e){return this.connectionListeners.add(e),()=>{this.connectionListeners.delete(e)}}onPartial(e){return this.partialListeners.add(e),()=>{this.partialListeners.delete(e)}}async ensureConnected(){if(!this.isConnected){if(this.connectPromise){await this.connectPromise;return}try{await o()}catch{}this.connectPromise=new Promise((e,t)=>{let r=!1,i;try{let e=n().websocket(`/api/dictation/ws`);i=Ae(e)}catch(e){this.connectPromise=null,t(e instanceof Error?e:Error(String(e)));return}let a=setTimeout(()=>{if(!r){r=!0,this.connectPromise=null;try{i.close()}catch{}t(Error(`Dictation connection timed out`))}},El);i.onopen=()=>{},i.onmessage=t=>{let n;try{n=JSON.parse(String(t.data))}catch{return}if(!r&&n.type===`ready`){r=!0,clearTimeout(a),this.socket=i,this.connectPromise=null,this.notifyConnection(!0),e();return}this.handleMessage(n)},i.onerror=()=>{window.setTimeout(()=>{r||(r=!0,clearTimeout(a),this.connectPromise=null,t(Error(`Dictation connection failed`)))},250)},i.onclose=e=>{if(!r){r=!0,clearTimeout(a),this.connectPromise=null;let n=e?.reason?`: ${e.reason}`:``;t(Error(`Dictation connection failed${n}`));return}this.socket===i&&(this.socket=null,this.rejectAllPending(Error(`Dictation connection lost`)),this.notifyConnection(!1))}}),await this.connectPromise}}async startDictationStream(e,t,n){return await this.ensureConnected(),this.activeDictations+=1,this.clearIdleCloseTimer(),new Promise((r,i)=>{let a=setTimeout(()=>{this.pendingStarts.delete(e),this.releaseDictation(),i(Error(`Dictation start timed out`))},Dl);this.pendingStarts.set(e,{resolve:()=>{clearTimeout(a),r()},reject:e=>{clearTimeout(a),this.releaseDictation(),i(e)},timeout:a}),this.send({type:`start`,dictationId:e,format:t,options:n})||(clearTimeout(a),this.pendingStarts.delete(e),this.releaseDictation(),i(Error(`Dictation connection lost`)))})}sendDictationStreamChunk(e,t,n){return this.send({type:`chunk`,dictationId:e,seq:t,audio:n})}finishDictationStream(e,t){return new Promise((n,r)=>{let i={resolve:e=>{i.timeout&&clearTimeout(i.timeout),this.releaseDictation(),n(e)},reject:e=>{i.timeout&&clearTimeout(i.timeout),this.releaseDictation(),r(e)},timeout:null};i.timeout=setTimeout(()=>{this.pendingFinishes.delete(e),this.releaseDictation(),r(Error(`Timed out waiting for transcription`))},kl),this.pendingFinishes.set(e,i),this.send({type:`finish`,dictationId:e,finalSeq:t})||(this.pendingFinishes.delete(e),i.reject(Error(`Dictation connection lost`)))})}cancelDictationStream(e){this.send({type:`cancel`,dictationId:e});let t=this.pendingStarts.get(e);t&&(this.pendingStarts.delete(e),t.reject(Error(`Dictation cancelled`)));let n=this.pendingFinishes.get(e);n&&(this.pendingFinishes.delete(e),n.reject(Error(`Dictation cancelled`))),this.releaseDictation(),this.scheduleIdleCloseIfReady()}handleMessage(e){let t=e.dictationId;if(t)switch(e.type){case`ack`:{let e=this.pendingStarts.get(t);e&&(this.pendingStarts.delete(t),e.resolve());return}case`partial`:for(let n of this.partialListeners)n(t,e.text??``);return;case`finish_accepted`:{let n=this.pendingFinishes.get(t);n&&typeof e.timeoutMs==`number`&&(n.timeout&&clearTimeout(n.timeout),n.timeout=setTimeout(()=>{this.pendingFinishes.delete(t),n.reject(Error(`Timed out waiting for transcription`))},e.timeoutMs+5e3));return}case`final`:{let n=this.pendingFinishes.get(t);n&&(this.pendingFinishes.delete(t),n.resolve({text:e.text??``})),this.scheduleIdleCloseIfReady();return}case`error`:{let n=Tl(e.error||`Dictation failed`,e.retryable!==!1,e.reasonCode),r=this.pendingStarts.get(t);r&&(this.pendingStarts.delete(t),r.reject(n));let i=this.pendingFinishes.get(t);i&&(this.pendingFinishes.delete(t),i.reject(n)),this.scheduleIdleCloseIfReady();return}}}send(e){if(!this.isConnected||!this.socket)return!1;try{return this.socket.send(JSON.stringify(e)),!0}catch{return!1}}notifyConnection(e){for(let t of this.connectionListeners)t(e)}rejectAllPending(e){for(let[t,n]of this.pendingStarts)this.pendingStarts.delete(t),n.reject(e);for(let[t,n]of this.pendingFinishes)this.pendingFinishes.delete(t),n.reject(e);this.activeDictations=0}releaseDictation(){this.activeDictations=Math.max(0,this.activeDictations-1),this.scheduleIdleCloseIfReady()}scheduleIdleCloseIfReady(){this.activeDictations>0||this.pendingFinishes.size>0||this.pendingStarts.size>0||(this.clearIdleCloseTimer(),this.idleCloseTimer=setTimeout(()=>{if(this.activeDictations===0&&this.pendingFinishes.size===0&&this.pendingStarts.size===0){let e=this.socket;if(this.socket=null,e){try{e.close(1e3,`idle`)}catch{}this.notifyConnection(!1)}}},Ol))}cancelAllForRuntimeSwitch(){this.clearIdleCloseTimer();let e=this.socket;if(this.socket=null,this.connectPromise=null,this.rejectAllPending(Error(`Runtime changed`)),e){try{e.close(1e3,`runtime switch`)}catch{}this.notifyConnection(!1)}}clearIdleCloseTimer(){this.idleCloseTimer&&=(clearTimeout(this.idleCloseTimer),null)}};typeof window<`u`&&window.addEventListener(`openchamber:runtime-endpoint-changed`,()=>{Al.cancelAllForRuntimeSwitch()});var jl=128,Ml=`audio/pcm;rate=16000;bits=16`,Nl=()=>new Promise(e=>setTimeout(e,0)),Pl=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},Fl=class{client;format;createDictationId;getStartOptions;dictationId=null;sendSeq=0;segments=[];streamReady=!1;flushTimer=null;drainWaiters=[];startGeneration=0;startPromise=null;constructor(e){this.client=e.client,this.format=e.format??Ml,this.getStartOptions=e.getStartOptions,this.createDictationId=e.createDictationId??Pl}getDictationId(){return this.dictationId}getFinalSeq(){return this.segments.length-1}hasSegments(){return this.segments.length>0}clearAll(){this.clearScheduledFlush(),this.dictationId=null,this.sendSeq=0,this.segments=[],this.streamReady=!1,this.startPromise=null,this.startGeneration+=1}resetStreamForReplay(){this.clearScheduledFlush(),this.dictationId=null,this.sendSeq=0,this.streamReady=!1,this.startPromise=null,this.startGeneration+=1}enqueueSegment(e){if(this.segments.push(e),this.client.isConnected){if(!this.dictationId){this.startPromise||this.restartStream().catch(()=>{});return}this.flush()}}flush(){let e=this.dictationId;if(!this.client.isConnected||!e||!this.streamReady)return 0;let t=0;for(;this.sendSeq<this.segments.length&&t<jl;){let n=this.sendSeq,r=this.segments[n];if(!this.client.sendDictationStreamChunk(e,n,r))break;this.sendSeq=n+1,t+=1}return this.hasPendingSegments()?this.scheduleFlush():this.resolveDrainWaiters(),t}async restartStream(){this.startGeneration+=1;let e=this.startGeneration,t=this.createDictationId();this.dictationId=t,this.sendSeq=0,this.streamReady=!1;let n=(async()=>{await this.client.startDictationStream(t,this.format,this.getStartOptions()),this.startGeneration===e&&this.dictationId===t&&(this.streamReady=!0,this.flush())})().catch(n=>{throw this.startGeneration===e&&this.dictationId===t&&(this.dictationId=null,this.streamReady=!1),n}).finally(()=>{this.startPromise===n&&(this.startPromise=null)});this.startPromise=n,await n}async finish(e){this.dictationId||await this.restartStream(),this.startPromise&&await this.startPromise;let t=this.dictationId;if(!t||!this.streamReady)throw Error(`Failed to start dictation stream`);return this.flush(),await this.waitForFlushDrain(),{dictationId:t,text:(await this.client.finishDictationStream(t,e)).text}}cancel(){let e=this.dictationId;this.client.isConnected&&e&&this.client.cancelDictationStream(e),this.resetStreamForReplay()}hasPendingSegments(){return this.sendSeq<this.segments.length}scheduleFlush(){this.flushTimer||=setTimeout(()=>{this.flushTimer=null,this.flush()},0)}clearScheduledFlush(){this.flushTimer&&=(clearTimeout(this.flushTimer),null)}async waitForFlushDrain(){for(;this.hasPendingSegments();){if(!this.client.isConnected||!this.dictationId||!this.streamReady)throw Error(`Failed to flush dictation stream`);await new Promise(e=>{this.drainWaiters.push(e)}),await Nl()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},Il=16e3,Ll=Il,Rl=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},zl=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},Bl=(e,t,n)=>{if(e.length===0)return new Int16Array;if(t===n){let t=new Int16Array(e.length);for(let n=0;n<e.length;n++)t[n]=zl(e[n]);return t}let r=t/n,i=Math.max(1,Math.round(e.length/r)),a=new Int16Array(i);for(let t=0;t<i;t++){let n=t*r,i=Math.floor(n),o=Math.min(e.length-1,i+1),s=n-i;a[t]=zl(e[i]*(1-s)+e[o]*s)}return a},Vl=(e,t)=>{if(e.length===0)return t;if(t.length===0)return e;let n=new Int16Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n},Hl=e=>{let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=``;for(let e=0;e<t.length;e++)n+=String.fromCharCode(t[e]);return btoa(n)},Ul=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),Wl=e=>{if(e)try{e.disconnect()}catch{}},Gl=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Rl()!==null;function Kl(e){let t=(0,Q.c)(12),[n,r]=(0,Z.useState)(0),i=(0,Z.useRef)(e.onPcmSegment),a=(0,Z.useRef)(e.onError),o,s;t[0]!==e.onError||t[1]!==e.onPcmSegment?(o=()=>{i.current=e.onPcmSegment,a.current=e.onError},s=[e.onPcmSegment,e.onError],t[0]=e.onError,t[1]=e.onPcmSegment,t[2]=o,t[3]=s):(o=t[2],s=t[3]),(0,Z.useEffect)(o,s);let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=Ul(),t[4]=c):c=t[4];let l=(0,Z.useRef)(c),u;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=async()=>{if(l.current.started)return;if(typeof navigator>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`)throw Error(`Microphone capture is not supported in this environment`);let e=Rl();if(!e)throw Error(`AudioContext unavailable`);let t=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,noiseSuppression:!0,echoCancellation:!0,autoGainControl:!0}}),n=new e;try{n.state===`suspended`&&await n.resume().catch(Yl);let e=n.createMediaStreamSource(t),a=n.createScriptProcessor(4096,1,1),o=n.createGain();o.gain.value=0,l.current={stream:t,context:n,source:e,processor:a,gain:o,pending:new Int16Array,started:!0},a.onaudioprocess=e=>{let t=l.current;if(!t.started)return;let a=e.inputBuffer.getChannelData(0),o=0;for(let e=0;e<a.length;e++)o+=a[e]*a[e];let s=Math.sqrt(o/Math.max(1,a.length));r(Math.min(1,Math.max(0,s*2)));let c=Bl(a,n.sampleRate,Il);for(t.pending=Vl(t.pending,c);t.pending.length>=Ll;){let e=t.pending.slice(0,Ll);t.pending=t.pending.slice(Ll),i.current(Hl(e))}},e.connect(a),a.connect(o),o.connect(n.destination)}catch(e){let r=e;t.getTracks().forEach(Jl);try{await n.close()}catch{}throw l.current=Ul(),r instanceof Error?r:Error(String(r))}},t[5]=u):u=t[5];let d=u,f;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(f=async()=>{let e=l.current;if(e.started=!1,r(0),e.processor)try{e.processor.onaudioprocess=null}catch{}Wl(e.processor),Wl(e.source),Wl(e.gain),e.stream&&e.stream.getTracks().forEach(ql);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current(Hl(t)),e.context)try{await e.context.close()}catch{}l.current===e&&(l.current=Ul())},t[6]=f):f=t[6];let p=f,m,h;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>()=>{p().catch(e=>{a.current?.(e instanceof Error?e:Error(String(e)))})},h=[p],t[7]=m,t[8]=h):(m=t[7],h=t[8]),(0,Z.useEffect)(m,h);let g;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(g=async()=>{try{await d()}catch(e){let t=e,n=t instanceof Error?t:Error(String(t));throw a.current?.(n),n}},t[9]=g):g=t[9];let _;return t[10]===n?_=t[11]:(_={start:g,stop:p,volume:n},t[10]=n,t[11]=_),_}function ql(e){try{e.stop()}catch{}}function Jl(e){try{e.stop()}catch{}}function Yl(){}var Xl=1e3,Zl=e=>e instanceof Error?e:Error(String(e)),Ql=()=>{let e=Ai.getState(),t=e.sttLanguage?.trim();return e.sttProvider===`openai-compatible`?{provider:`openai-compatible`,...t?{language:t}:{},openaiCompatible:{baseUrl:e.sttServerUrl,model:e.sttModel,...e.sttApiKey?{apiKey:e.sttApiKey}:{}}}:{provider:`local`,...t?{language:t}:{},localModel:e.sttLocalModel}};function $l(e={}){let{onTranscript:t,onError:n,canStart:r}=e,[i,a]=(0,Z.useState)(`idle`),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(0),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),m=(0,Z.useRef)(i);(0,Z.useEffect)(()=>{m.current=i},[i]);let h=(0,Z.useRef)(``),g=(0,Z.useRef)(null),_=(0,Z.useRef)({starting:!1,confirming:!1,cancelling:!1}),v=(0,Z.useRef)(t),y=(0,Z.useRef)(n);(0,Z.useEffect)(()=>{v.current=t,y.current=n},[t,n]);let b=(0,Z.useRef)(null);b.current||=new Fl({client:Al,getStartOptions:Ql});let x=(0,Z.useCallback)(()=>{g.current&&=(clearInterval(g.current),null)},[]),S=(0,Z.useCallback)(()=>{g.current||=setInterval(()=>{l(e=>e+1)},Xl)},[]),C=(0,Z.useCallback)(e=>{let t=Zl(e);d(t.message);let n=t.reasonCode;p(typeof n==`string`?n:null),y.current?.(t)},[]),w=(0,Z.useCallback)(()=>{d(null),p(null)},[]),T=(0,Z.useCallback)(()=>{b.current?.clearAll(),h.current=``,s(``)},[]);(0,Z.useEffect)(()=>Al.onPartial((e,t)=>{let n=b.current?.getDictationId();!n||e!==n||(h.current=t,s(t))}),[]),(0,Z.useEffect)(()=>Al.subscribeConnectionStatus(e=>{e&&m.current===`recording`&&b.current?.restartStream().catch(e=>{C(e)})}),[C]);let E=Kl({onPcmSegment:e=>{b.current?.enqueueSegment(e)},onError:e=>{y.current?.(e)}}),D=(0,Z.useRef)(E.stop);(0,Z.useEffect)(()=>{D.current=E.stop},[E.stop]);let O=(0,Z.useCallback)(e=>{l(0),a(`idle`);let t=e.trim().length>0?e.trim():h.current.trim();return T(),t?(v.current?.(t),t):null},[T]),k=(0,Z.useCallback)(e=>{b.current?.hasSegments()?a(`failed`):a(`idle`),C(e)},[C]),A=(0,Z.useCallback)(async()=>{let e=_.current;if(!(e.starting||e.confirming||e.cancelling)&&m.current===`idle`&&!(r&&!r())){e.starting=!0,w(),s(``),l(0),a(`recording`),m.current=`recording`,T();try{await E.start(),S(),await b.current?.restartStream().catch(e=>{C(e)})}catch(e){await E.stop().catch(()=>void 0),x(),a(`idle`),m.current=`idle`,C(e)}finally{e.starting=!1}}},[E,r,w,T,C,S,x]),j=(0,Z.useCallback)(async()=>{let e=_.current;if(!e.cancelling&&(m.current===`recording`||m.current===`uploading`)){e.cancelling=!0,x(),l(0),w(),a(`idle`),m.current=`idle`;try{b.current?.cancel()}catch{}T();try{await E.stop()}catch{}finally{e.cancelling=!1}}},[E,w,T,x]),M=(0,Z.useCallback)(async()=>{let e=_.current;if(e.confirming||m.current!==`recording`)return null;e.confirming=!0,w(),x();try{await E.stop(),a(`uploading`),m.current=`uploading`;let e=b.current?.getFinalSeq()??-1;if(e<0)return O(``);let t=await b.current.finish(e);return O(t.text)}catch(e){return k(e),null}finally{e.confirming=!1}},[E,w,k,O,x]),N=(0,Z.useCallback)(async()=>{if(m.current!==`failed`||!b.current?.hasSegments())return null;w(),a(`uploading`),m.current=`uploading`;try{b.current.resetStreamForReplay();let e=b.current.getFinalSeq(),t=await b.current.finish(e);return O(t.text)}catch(e){return k(e),null}},[w,k,O]),P=(0,Z.useCallback)(()=>{if(m.current!==`failed`)return null;let e=h.current.trim();l(0),a(`idle`),m.current=`idle`,w();try{b.current?.cancel()}catch{}return T(),e?(v.current?.(e),e):null},[w,T]),F=(0,Z.useCallback)(()=>{l(0),a(`idle`),m.current=`idle`,w(),T()},[w,T]);return(0,Z.useEffect)(()=>{if(i!==`recording`||f!==`model_download_in_progress`)return;let e=setInterval(()=>{m.current!==`recording`||b.current?.getDictationId()||b.current?.restartStream().then(()=>{w()}).catch(e=>{C(e)})},3e3);return()=>clearInterval(e)},[i,f,w,C]),(0,Z.useEffect)(()=>()=>{x(),D.current().catch(()=>void 0),b.current?.cancel()},[x]),{status:i,isRecording:i===`recording`,isProcessing:i===`uploading`,partialTranscript:o,volume:E.volume,duration:c,error:u,errorReason:f,startDictation:A,confirmDictation:M,cancelDictation:j,retryFailedDictation:N,acceptPartialTranscript:P,discardFailedDictation:F}}var eu=e=>{let t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,`0`)}`},tu=e=>{let t=(0,Q.c)(4),{volume:n}=e,{currentTheme:r}=Ga(),i=Math.min(1,Math.max(0,n)),a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=[.45,.7,1,.7,.45],t[0]=a):a=t[0];let o=a,s;return t[1]!==r||t[2]!==i?(s=(0,$.jsx)(`div`,{className:`flex h-6 w-10 flex-shrink-0 items-center justify-center gap-1`,"aria-hidden":`true`,children:o.map((e,t)=>(0,$.jsx)(`span`,{className:`h-full w-1 rounded-full transition-transform duration-75 ease-out motion-reduce:transition-none`,style:{backgroundColor:r.colors.primary.base,transform:`scaleY(${.25+i*e*.75})`}},t))}),t[1]=r,t[2]=i,t[3]=s):s=t[3],s},nu=e=>{let t=Ai(e=>e.sttLocalModel),[n,r]=Z.useState(null);return Z.useEffect(()=>{if(!e){r(null);return}let n=!1,i=async()=>{try{let e=await m(`/api/dictation/status`,{query:{provider:`local`,localModel:t}});if(!e.ok||n)return;let i=await e.json(),a=Array.isArray(i?.models)?i.models.find(e=>e.id===t):null;n||r(typeof a?.downloadProgress==`number`?a.downloadProgress:null)}catch{}};i();let a=setInterval(()=>{i()},2e3);return()=>{n=!0,clearInterval(a)}},[e,t]),e?n:null},ru=e=>{let t=(0,Q.c)(86),{radius:n,isMobile:r,footerIconButtonClass:i,footerPaddingClass:a,iconSizeClass:o,sendIconSizeClass:s,disabled:c,onInsert:l,onInsertAndSend:u,onActiveChange:d,onContentHeightChange:f,renderTrigger:p,topAccessory:m}=e,h=p===void 0||p,{t:g}=ct(),{currentTheme:_}=Ga(),v=Ai(iu),y=q(au),b;t[0]===y?b=t[1]:(b=Za(Qa(`toggle_dictation`,y)),t[0]=y,t[1]=b);let x=b,[S]=Z.useState(ou),C=Z.useRef(null),w=Z.useRef(l),T=Z.useRef(u),E,D;t[2]!==l||t[3]!==u?(E=()=>{w.current=l,T.current=u},D=[l,u],t[2]=l,t[3]=u,t[4]=E,t[5]=D):(E=t[4],D=t[5]),Z.useEffect(E,D);let O;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(O={onTranscript:e=>{let t=C.current;C.current=null,t===`send`?T.current(e):w.current(e)}},t[6]=O):O=t[6];let{status:k,partialTranscript:A,volume:j,duration:M,error:N,errorReason:P,startDictation:F,confirmDictation:I,cancelDictation:L,retryFailedDictation:R,acceptPartialTranscript:z,discardFailedDictation:B}=$l(O),V=k===`recording`&&P===`model_download_in_progress`,H=nu(V),U=Z.useRef(k),W,ee;t[7]===k?(W=t[8],ee=t[9]):(W=()=>{U.current=k},ee=[k],t[7]=k,t[8]=W,t[9]=ee),Z.useEffect(W,ee);let G,K;t[10]!==d||t[11]!==k?(G=()=>{d?.(k!==`idle`)},K=[k,d],t[10]=d,t[11]=k,t[12]=G,t[13]=K):(G=t[12],K=t[13]),Z.useLayoutEffect(G,K);let te,ne;t[14]!==I||t[15]!==F?(te=()=>{let e=()=>{U.current===`idle`?F():U.current===`recording`&&(C.current=`insert`,I())};return window.addEventListener(`openchamber:dictation-toggle`,e),()=>window.removeEventListener(`openchamber:dictation-toggle`,e)},ne=[F,I],t[14]=I,t[15]=F,t[16]=te,t[17]=ne):(te=t[16],ne=t[17]),Z.useEffect(te,ne);let re,ie;t[18]!==L||t[19]!==I||t[20]!==k?(re=()=>{if(k!==`recording`)return;let e=e=>{if(!e.isComposing){if(e.key===`Enter`&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey){e.preventDefault(),e.stopPropagation(),C.current=`insert`,I();return}e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),L())}};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},ie=[k,I,L],t[18]=L,t[19]=I,t[20]=k,t[21]=re,t[22]=ie):(re=t[21],ie=t[22]),Z.useEffect(re,ie);let ae=Z.useRef(null),oe=Z.useRef(null),se=Z.useRef(null),[ce,le]=Z.useState(null),ue=k!==`idle`,de=Z.useRef(f),fe,pe;t[23]===f?(fe=t[24],pe=t[25]):(fe=()=>{de.current=f},pe=[f],t[23]=f,t[24]=fe,t[25]=pe),Z.useEffect(fe,pe);let me=Z.useRef(!1),he;t[26]===ue?he=t[27]:(he=()=>{if(!ue){me.current&&(me.current=!1,de.current?.(null));return}let e=oe.current,t=se.current;if(!e||!t)return;let n=window.getComputedStyle(e),r=(parseFloat(n.paddingTop)||0)+(parseFloat(n.paddingBottom)||0);me.current=!0,de.current?.(t.offsetHeight+r),e.scrollTop=e.scrollHeight},t[26]=ue,t[27]=he);let ge;t[28]!==N||t[29]!==ue||t[30]!==A||t[31]!==k?(ge=[ue,A,k,N],t[28]=N,t[29]=ue,t[30]=A,t[31]=k,t[32]=ge):ge=t[32],Z.useLayoutEffect(he,ge);let _e,ve;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(_e=()=>()=>{me.current&&(me.current=!1,de.current?.(null))},ve=[],t[33]=_e,t[34]=ve):(_e=t[33],ve=t[34]),Z.useEffect(_e,ve);let ye,be;if(t[35]===ue?(ye=t[36],be=t[37]):(ye=()=>{if(!ue)return;let e=ae.current?.closest(`[data-chat-input-footer="true"]`);e&&e.offsetHeight>0&&le(e.offsetHeight)},be=[ue],t[35]=ue,t[36]=ye,t[37]=be),Z.useLayoutEffect(ye,be),!S||!v)return null;let xe=k!==`idle`,Se;t[38]===I?Se=t[39]:(Se=e=>{C.current=e,I()},t[38]=I,t[39]=Se);let Ce=Se,we;t[40]===R?we=t[41]:(we=()=>{C.current=`insert`,R()},t[40]=R,t[41]=we);let Te=we,Ee;bb0:{if(k===`failed`){Ee=``;break bb0}if(k===`uploading`){let e;t[42]===g?e=t[43]:(e=g(`chat.dictation.processing`),t[42]=g,t[43]=e),Ee=e;break bb0}if(V){let e;t[44]!==H||t[45]!==g?(e=H===null?g(`chat.dictation.downloadingModel`):g(`chat.dictation.downloadingModelProgress`,{percent:String(H)}),t[44]=H,t[45]=g,t[46]=e):e=t[46],Ee=e;break bb0}let e;t[47]===g?e=t[48]:(e=g(`chat.dictation.listening`),t[47]=g,t[48]=e),Ee=e}let De=Ee,Oe;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(Oe={onMouseDown:su,onPointerDownCapture:cu},t[49]=Oe):Oe=t[49];let ke=Oe,Ae;t[50]!==x||t[51]!==c||t[52]!==i||t[53]!==o||t[54]!==xe||t[55]!==h||t[56]!==F||t[57]!==g?(Ae=h?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{F()},disabled:c||xe,title:x?`${g(`chat.dictation.start`)} (${x})`:g(`chat.dictation.start`),"aria-label":g(`chat.dictation.start`),children:(0,$.jsx)(X,{name:`mic`,className:Y(o,`text-current`)})}):null,t[50]=x,t[51]=c,t[52]=i,t[53]=o,t[54]=xe,t[55]=h,t[56]=F,t[57]=g,t[58]=Ae):Ae=t[58];let je;t[59]!==z||t[60]!==L||t[61]!==Ce||t[62]!==_||t[63]!==B||t[64]!==M||t[65]!==N||t[66]!==ce||t[67]!==i||t[68]!==a||t[69]!==o||t[70]!==xe||t[71]!==r||t[72]!==V||t[73]!==A||t[74]!==De||t[75]!==n||t[76]!==Te||t[77]!==s||t[78]!==k||t[79]!==g||t[80]!==m||t[81]!==j?(je=xe?(0,$.jsxs)(`div`,{ref:ae,className:Y(`absolute inset-0 z-50 flex flex-col overflow-x-hidden overflow-y-hidden`,r&&`oc-composer-morph-content-fade`),style:{borderRadius:n,backgroundColor:_.colors.surface.subtle},role:`dialog`,"aria-label":g(`chat.dictation.overlayAria`),children:[m,(0,$.jsx)(`div`,{ref:oe,className:Y(`scrollbar-none flex-1 min-h-0 overflow-y-auto px-3`,r?`pt-3.5 pb-2.5`:`pt-5 pb-2`),children:(0,$.jsxs)(`div`,{ref:se,className:Y(!A&&`translate-y-1.5`),children:[A?(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label whitespace-pre-wrap`,style:{color:_.colors.surface.foreground},children:A}):k===`recording`?(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,style:{color:_.colors.surface.mutedForeground},children:[(0,$.jsx)(tu,{volume:j}),(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,children:De})]}):(0,$.jsx)(`p`,{className:`typography-markdown md:typography-ui-label`,style:{color:_.colors.surface.mutedForeground},children:De}),k===`failed`?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:_.colors.status.error},children:N||g(`chat.dictation.failed`)}):null,k===`recording`&&N&&!V?(0,$.jsx)(`p`,{className:`typography-meta mt-1`,style:{color:_.colors.status.warning},children:N}):null]})}),(0,$.jsxs)(`div`,{className:Y(`flex flex-shrink-0 items-center gap-x-3`,a),style:ce?{height:ce}:void 0,children:[k===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`relative ml-1 flex h-2 w-2 flex-shrink-0`,"aria-hidden":`true`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full opacity-60`,style:{backgroundColor:_.colors.status.error}}),(0,$.jsx)(`span`,{className:`relative inline-flex h-2 w-2 rounded-full`,style:{backgroundColor:_.colors.status.error}})]}),(0,$.jsx)(tu,{volume:j}),(0,$.jsx)(`span`,{className:`typography-meta tabular-nums`,style:{color:_.colors.surface.mutedForeground},children:eu(M)})]}):k===`uploading`?(0,$.jsx)(X,{name:`loader-4`,className:`ml-1 h-4 w-4 animate-spin`,style:{color:_.colors.surface.mutedForeground}}):null,(0,$.jsx)(`div`,{className:Y(`ml-auto flex items-center`,r?`gap-x-1`:`gap-x-1.5 md:gap-x-3`),children:k===`recording`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{L()},title:g(`chat.dictation.cancel`),"aria-label":g(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>Ce(`insert`),title:g(`chat.dictation.insert`),"aria-label":g(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-primary hover:text-primary`),onClick:()=>Ce(`send`),title:g(`chat.dictation.insertAndSend`),"aria-label":g(`chat.dictation.insertAndSend`),children:(0,$.jsx)(X,{name:`send-plane-2`,className:s})})]}):k===`uploading`?(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:()=>{L()},title:g(`chat.dictation.cancel`),"aria-label":g(`chat.dictation.cancel`),children:(0,$.jsx)(X,{name:`close`,className:o})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,...ke,className:Y(i,`text-muted-foreground hover:text-foreground`),onClick:B,title:g(`chat.dictation.discard`),"aria-label":g(`chat.dictation.discard`),children:(0,$.jsx)(X,{name:`close`,className:o})}),(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:Te,title:g(`chat.dictation.retry`),"aria-label":g(`chat.dictation.retry`),children:(0,$.jsx)(X,{name:`refresh`,className:o})}),A.trim()?(0,$.jsx)(`button`,{type:`button`,...ke,className:i,onClick:()=>{C.current=`insert`,z()},title:g(`chat.dictation.insert`),"aria-label":g(`chat.dictation.insert`),children:(0,$.jsx)(X,{name:`check`,className:o})}):null]})})]})]}):null,t[59]=z,t[60]=L,t[61]=Ce,t[62]=_,t[63]=B,t[64]=M,t[65]=N,t[66]=ce,t[67]=i,t[68]=a,t[69]=o,t[70]=xe,t[71]=r,t[72]=V,t[73]=A,t[74]=De,t[75]=n,t[76]=Te,t[77]=s,t[78]=k,t[79]=g,t[80]=m,t[81]=j,t[82]=je):je=t[82];let Me;return t[83]!==Ae||t[84]!==je?(Me=(0,$.jsxs)($.Fragment,{children:[Ae,je]}),t[83]=Ae,t[84]=je,t[85]=Me):Me=t[85],Me};function iu(e){return e.dictationEnabled}function au(e){return e.shortcutOverrides}function ou(){return!se()&&Gl()}function su(e){return e.preventDefault()}function cu(e){e.pointerType===`touch`&&e.preventDefault()}var lu=2e3,uu=ce((e,t)=>({pending:!1,expiresAt:null,arm:(t=lu)=>{let n=Date.now()+t;return e({pending:!0,expiresAt:n}),n},clear:()=>{!t().pending&&t().expiresAt===null||e({pending:!1,expiresAt:null})}})),du=new class{inFlightByScope=new WeakMap;generationByScope=new WeakMap;run(e){let t=this.inFlightByScope.get(e.scope);t||(t=new Map,this.inFlightByScope.set(e.scope,t));let n=t.get(e.key);if(n)return n;let r=this.generationByScope.get(e.scope);r||(r=new Map,this.generationByScope.set(e.scope,r));let i=(r.get(e.key)??0)+1;r.set(e.key,i);let a=e.request(()=>r?.get(e.key)!==i);return t.set(e.key,a),a.finally(()=>{t?.get(e.key)===a&&t.delete(e.key)}).catch(()=>{}),a}},fu=15e3,pu=100,mu=new Map,hu=new Map,gu=e=>`${e.runtimeKey}\n${e.directory}\n${e.sessionID}`,_u=e=>{let t=gu(e),n=e.now??Date.now(),r=hu.get(t);if(r&&n-r.loadedAt<fu)return Promise.resolve(r.sessions);let i=mu.get(t);if(i)return i;let a=e.request().then(e=>{for(hu.delete(t);hu.size>=pu;){let e=hu.keys().next().value;if(typeof e!=`string`)break;hu.delete(e)}return hu.set(t,{loadedAt:Date.now(),sessions:e}),e});return mu.set(t,a),a.then(()=>{mu.get(t)===a&&mu.delete(t)},()=>{mu.get(t)===a&&mu.delete(t)}),a},vu=(e,t)=>e.id<t.id?-1:+(e.id>t.id),yu=(e,t,n)=>{let r=new Set(e.map(e=>e.id)),i=t.filter(e=>!!e?.id&&!r.has(e.id)&&e.parentID===n);return i.length===0?e:[...e,...i].sort(vu)},bu=30;function xu(e){return e===`busy`||e===`retry`}var Su=new Map;function Cu(e,t=!1){return{limit:e.loadedTurns,cursor:e.kind===`has-more`?e.cursor:void 0,complete:e.kind===`exhausted`,loading:t}}function wu(e){if(e instanceof Error)return e.message;if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.message;if(typeof t==`string`&&t.length>0)return t}try{return JSON.stringify(e)}catch{return String(e)}}function Tu(e,t){if(!e.error)return;let n=e.response?.status;throw Error(`${t} failed${n?` (${n})`:``}: ${wu(e.error)}`)}function Eu(e,t){let n=Pr();if(!n)return!1;let r=n.getTranscript(Bi(e,t));return r.messageOrder.length!==0&&r.messageOrder.length>qr()}function Du(e){return!!e.force||!e.hasSession||e.shouldLoadMessages}function Ou(e,t,n){let r=[...e.getState().session],i=Zr.search(r,t,e=>e.id);i.found?r[i.index]=n:r.splice(i.index,0,n),e.setState({session:r})}function ku(){let e=Ir(),t=Vt(),n=Hn(),r=(0,Z.useCallback)((t,n=e)=>`${n}\n${t}`,[e]),i=(0,Z.useCallback)((t,n=e)=>{let r=Pr();if(!r||!t)return Cu({kind:`unknown`,loadedTurns:0},!1);let i=Bi(n,t),a=r.getPagination(i),o=r.getRequestState?.(i);return Cu(a.boundary,o?.status===`loading`)},[e]),o=(0,Z.useCallback)((e,t)=>{if(t.length===0)return;let r=n.getChild(e);if(!r)return;let i=r.getState(),a={session_status:{...i.session_status},session_status_observed_at:{...i.session_status_observed_at},session_error_at:{...i.session_error_at},session_diff:{...i.session_diff},todo:{...i.todo},permission:{...i.permission},question:{...i.question}};At(a,t),Xt(r,t),r.setState(a);for(let n of t)qi(e,n)},[n]),s=(0,Z.useCallback)((t=e)=>{let n=Su.get(t);if(n)return Su.delete(t),Su.set(t,n),n;let r=new Set;for(Su.set(t,r);Su.size>bu;){let e=Su.keys().next().value;if(!e)break;let t=[...Su.get(e)??[]];Su.delete(e),o(e,t)}return r},[e,o]),c=(0,Z.useCallback)((r,i=e)=>{let a=i===e?t:n.ensureChild(i,{bootstrap:!1}),c=s(i),l=_n(a.getState()),u=Qr(),d=$r({seen:c,keep:r,limit:u,preserve:l});if(o(i,d),yt()){let e=new Set([r,...c,...l]),t=(Pr()?.getCacheBudget?.().listCanonical({directory:i})??[]).map(e=>e.scope.sessionID),n=(t.length>0?t:Array.from(c)).filter(t=>t===r||e.has(t)?!1:Eu(i,t));if(n.length>0){for(let e of n)c.delete(e);o(i,n)}}},[n,e,s,o,t]),l=(0,Z.useCallback)(async(r,i)=>{let a=i?.directory??e;if(!r||!a||a===`global`)return;let o=a===e?t:n.ensureChild(a,{bootstrap:!1}),s=o.getState(),c=s.session_status?.[r],l=s.session_status_observed_at?.[r];try{i?.purpose===`prepend`||i?.before?await si(a,r):await _i(a,r)}catch{return}if(i?.isStale?.())return;let u=Pr()?.getTranscript(Bi(a,r));ir({directory:a,sessionID:r,store:o,transcript:u,isStale:i?.isStale}),await pi({directory:a,sessionID:r,store:o,statusBeforePull:c,statusObservedAtBeforePull:l,hasMessages:(u?.messageOrder.length??0)>0,isTailPage:!i?.before,isStale:i?.isStale})},[n,t,e]),u=(0,Z.useCallback)(async(t,i)=>{await ln();let a=typeof i==`boolean`?i:i?.force,o=typeof i==`object`?i.directory??e:e,s=n.ensureChild(o,{bootstrap:!1}),u=De.getScopedSdkClient(o);c(t,o);let d=r(t,o);return du.run({scope:s,key:d,request:async e=>{let n=s.getState(),r=Pr(),i=Bi(o,t),c=r?.hasSession?.(i)??(r?.getTranscript(i).messageOrder.length??0)>0,d=r?.getPagination(i)?.boundary??{kind:`unknown`,loadedTurns:0},f=Zr.search(n.session,t,e=>e.id).found,p=r?.getRequestState?.(i);if(!a&&c&&d.kind!==`unknown`&&p?.status!==`error`&&f&&fn(o,t)){ir({directory:o,sessionID:t,store:s,isStale:e});return}let m=!!(a||!c||f),h=Du({hasSession:f,shouldLoadMessages:m,force:!!a});await Promise.all([h?(async()=>{try{let n=await Cn(async()=>{let e=await u.session.get({sessionID:t,directory:o});return Tu(e,`session.get`),e});if(n.data&&!e()){let r=nr(n.data);e()||Ou(s,t,r)}}catch(e){console.error(`[sync] failed to fetch session`,t,e)}})():Promise.resolve(),m?l(t,{isStale:e,directory:o}):Promise.resolve()])}})},[n,r,c,l,e]),d=(0,Z.useCallback)(async(t,r)=>{let i=r||e;if(!t||!i)return;let o=n.ensureChild(i,{bootstrap:!1}),s=De.getScopedSdkClient(i),c=await _u({runtimeKey:a(),directory:i,sessionID:t,request:async()=>{let e=await s.session.children({sessionID:t,directory:i});return Tu(e,`session.children`),e.data??[]}});o.setState(e=>{let n=yu(e.session,c,t);return n===e.session?e:{session:n,limit:Math.max(e.limit,n.length)}})},[n,e]),f=(0,Z.useCallback)((t,n)=>{let r=i(t,n?.directory??e);return!r.complete&&!!r.cursor},[e,i]),p=(0,Z.useCallback)((t,n)=>i(t,n?.directory??e).loading,[e,i]),m=(0,Z.useCallback)((t,n)=>i(t,n?.directory??e).complete,[e,i]),h=(0,Z.useCallback)(t=>{let n=t.directory||e;kr(Bi(n,t.sessionID),{type:`optimistic-add`,message:t.message,parts:t.parts})},[e]),g=(0,Z.useCallback)(t=>{let n=t.directory||e;kr(Bi(n,t.sessionID),{type:`optimistic-remove`,messageID:t.messageID})},[e]),_=(0,Z.useCallback)(t=>{let n=t.directory||e;kr(Bi(n,t.sessionID),{type:`optimistic-confirm`,messageID:t.messageID})},[e]),v=(0,Z.useCallback)(async(t,r)=>{if(!t)return;await ln();let i=r?.directory??e;if(!i||i===`global`)return;let a=n.ensureChild(i,{bootstrap:!1}),o=a.getState().session_status?.[t]?.type;if(xu(o))throw Error(`refresh transcript busy`);try{await mr(i,t),ir({directory:i,sessionID:t,store:a})}catch(e){throw e instanceof Error&&e.message===`refresh transcript busy`?e:Error(`refresh transcript failed`)}},[n,e]);return(0,Z.useMemo)(()=>({ensureSessionRenderable:u,syncSession:u,loadChildren:d,hasMore:f,isLoading:p,isComplete:m,refreshSessionTranscript:v,optimistic:{add:h,remove:g,confirm:_}}),[u,d,f,p,m,v,h,g,_])}var Au=e=>e===`diff`||e===`file`||e===`preview-console`||e===`preview-annotation`,ju=e=>e===`original`||e===`modified`,Mu=e=>{let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(1,Math.floor(t)):null},Nu=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.sessionKey!=`string`||t.sessionKey.trim().length===0||!Au(t.source))return null;let n=Mu(t.startLine),r=Mu(t.endLine);return!n||!r?null:{id:typeof t.id==`string`&&t.id.trim().length>0?t.id:`icd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,sessionKey:t.sessionKey,source:t.source,fileLabel:typeof t.fileLabel==`string`?t.fileLabel:`unknown`,startLine:n,endLine:r,side:ju(t.side)?t.side:void 0,code:typeof t.code==`string`?t.code:``,language:typeof t.language==`string`?t.language:`text`,text:typeof t.text==`string`?t.text:``,createdAt:Number.isFinite(t.createdAt)?Number(t.createdAt):Date.now()}},Pu=e=>{if(!e||typeof e!=`object`)return{};let t=Object.entries(e),n={};for(let[e,r]of t){if(!Array.isArray(r))continue;let t=r.map(Nu).filter(e=>!!e).filter(t=>t.sessionKey===e);t.length>0&&(n[e]=t)}return n},Fu=ce()(ue(le((e,t)=>({drafts:{},addDraft:t=>{let n=`icd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,r={...t,id:n,createdAt:Date.now()};return e(e=>{let n=e.drafts[t.sessionKey]??[];return{drafts:{...e.drafts,[t.sessionKey]:[...n,r]}}}),n},updateDraft:(t,n,r)=>{e(e=>{let i=(e.drafts[t]??[]).map(e=>e.id===n?{...e,...r}:e);return{drafts:{...e.drafts,[t]:i}}})},removeDraft:(t,n)=>{e(e=>{let r=(e.drafts[t]??[]).filter(e=>e.id!==n);if(r.length===0){let{[t]:n,...r}=e.drafts;return{drafts:r}}return{drafts:{...e.drafts,[t]:r}}})},clearDrafts:t=>{e(e=>{let{[t]:n,...r}=e.drafts;return{drafts:r}})},getDrafts:e=>t().drafts[e]??[],consumeDrafts:n=>{let r=t().drafts[n]??[];if(r.length===0)return[];let i=[...r].sort((e,t)=>e.createdAt-t.createdAt);return e(e=>{let{[n]:t,...r}=e.drafts;return{drafts:r}}),i},getDraftCount:e=>(t().drafts[e]??[]).length,hasDrafts:e=>(t().drafts[e]??[]).length>0}),{name:`openchamber-inline-comment-drafts`,storage:Be(),version:1,migrate:e=>!e||typeof e!=`object`?{drafts:{}}:{drafts:Pu(e.drafts)}}),{name:`inline-comment-draft-store`}));function Iu(e){let{fileLabel:t,startLine:n,endLine:r,side:i,language:a,code:o,text:s}=e;return e.source===`diff`&&i?`Comment on \`${t}\` lines ${n}-${r} (${i}):\n\`\`\`${a}\n${o}\n\`\`\`\n\n${s}`:e.source===`preview-console`?`Attached preview context from \`${t}\`:\n\`\`\`${a}\n${o}\n\`\`\`\n\n${s}`:e.source===`preview-annotation`?s?`${o}\n\n${s}`:o:`Comment on \`${t}\` lines ${n}-${r}:\n\`\`\`${a}\n${o}\n\`\`\`\n\n${s}`}function Lu(e){return e.length===0?``:e.every(e=>e.source===`preview-annotation`)?e.map(Iu).join(`
3
3
 
4
4
  ---
5
5
 
@@ -6521,7 +6521,7 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{c as t,f as n,i as r,n
6521
6521
  `))r.startsWith(`+`)&&!r.startsWith(`+++`)&&t++,r.startsWith(`-`)&&!r.startsWith(`---`)&&n++;return{added:t,removed:n}},cg=e=>{let t=[],n=new Set;for(let r of e){if(r.type!==`tool`||!ig.has(r.tool))continue;let e=r.state;if(e.status&&e.status!==`completed`)continue;let i=t.length,a=e.metadata,o=Array.isArray(a?.files)?a.files:[];for(let e of o){if(!e||typeof e!=`object`)continue;let i=e,a=i.relativePath||i.filePath||``;!a||n.has(a)||(n.add(a),t.push({path:a,tool:r.tool,partId:r.id,messageID:r.messageID,additions:og(i.additions)??void 0,deletions:og(i.deletions)??void 0,patch:typeof i.patch==`string`?i.patch:void 0}))}if(o.length===0&&a?.filediff&&typeof a.filediff==`object`){let e=a.filediff,i=typeof e.file==`string`?e.file:``;i&&!n.has(i)&&(n.add(i),t.push({path:i,tool:r.tool,partId:r.id,messageID:r.messageID,additions:og(e.additions)??void 0,deletions:og(e.deletions)??void 0,patch:typeof e.patch==`string`?e.patch:void 0}))}if(o.length===0&&Array.isArray(a?.results))for(let e of a.results){if(!e||typeof e!=`object`)continue;let i=e.filediff;if(!i||typeof i!=`object`)continue;let a=typeof i.file==`string`?i.file:``;!a||n.has(a)||(n.add(a),t.push({path:a,tool:r.tool,partId:r.id,messageID:r.messageID,additions:og(i.additions)??void 0,deletions:og(i.deletions)??void 0,patch:typeof i.patch==`string`?i.patch:void 0}))}if(t.length===i){let i=e.input,a=typeof i?.filePath==`string`?i.filePath:typeof i?.file_path==`string`?i.file_path:typeof i?.path==`string`?i.path:void 0;a&&!n.has(a)&&(n.add(a),t.push({path:a,tool:r.tool,partId:r.id,messageID:r.messageID}))}if(t.length===i){let e=typeof a?.patch==`string`?a.patch.trim():typeof a?.diff==`string`?a.diff.trim():``;if(e&&!n.has(`Diff`)){n.add(`Diff`);let i=sg(e);t.push({path:`Diff`,tool:r.tool,partId:r.id,messageID:r.messageID,additions:i.added,deletions:i.removed})}}}return t},lg=(e,t,n)=>{let r=[];for(let i of e){let e=i.index?.trim()??``,a=i.working_dir?.trim()??``,o=!!(e&&e!==`?`),s=!!(a||e===`?`),c=a||e;if(!c||c===`!`)continue;let l=t?.[i.path];r.push({path:bo(n,i.path),relativePath:i.path,insertions:l?.insertions??0,deletions:l?.deletions??0,status:c,hasStagedChanges:o,hasWorkingChanges:s})}return r},ug=e=>{for(let t of e){let e=t.index?.trim()??``,n=(t.working_dir?.trim()??``)||e;if(!(!n||n===`!`))return!0}return!1},dg=(e,t)=>yo(e,t),fg=(e,t)=>{let n=ag(e)&&e.relativePath?e.relativePath:dg(e.path,t);return{fileName:n.split(`/`).pop()??n,dirPart:n.includes(`/`)?n.slice(0,n.lastIndexOf(`/`)):``}},pg=e=>ag(e)?{additions:e.insertions,deletions:e.deletions}:{additions:e.additions??0,deletions:e.deletions??0},mg=2;function hg(e){let t=e.lastIndexOf(`.`);return t<=0||t===e.length-1?{stem:e,ext:``}:{stem:e.slice(0,t),ext:e.slice(t)}}function gg(e,t=mg){let n=e??``,r=n.startsWith(`/`),i=n.split(`/`).filter(Boolean);if(i.length===0)return{prefix:``,parent:``,stem:``,ext:``,name:``,leadingSlash:r};let a=i[i.length-1]??``,{stem:o,ext:s}=hg(a),c=Math.max(1,Math.floor(t)),l=Math.min(i.length-1,c-1),u=i.length-1-l,d=l>0?i.slice(u,-1).join(`/`):``,f=i.slice(0,u).join(`/`),p=f?r?`/${f}`:f:``;return{prefix:p,parent:d,stem:o,ext:s,name:a,leadingSlash:r&&!p}}function _g(e){let t=(0,Q.c)(36),{path:n,className:r,title:i,dirClassName:a,nameClassName:o}=e,s=a===void 0?`text-muted-foreground`:a,c=o===void 0?`text-foreground`:o,l;t[0]===n?l=t[1]:(l=gg(n),t[0]=n,t[1]=l);let{prefix:u,parent:d,stem:f,ext:p,leadingSlash:m}=l,h=!!(u||d),g;t[2]===r?g=t[3]:(g=Y(`flex min-w-0 items-baseline overflow-hidden`,r),t[2]=r,t[3]=g);let _=i??n,v;t[4]!==s||t[5]!==m?(v=m?(0,$.jsx)(`span`,{className:Y(`shrink-0`,s),children:`/`}):null,t[4]=s,t[5]=m,t[6]=v):v=t[6];let y;t[7]!==s||t[8]!==u?(y=u?(0,$.jsx)(`span`,{className:Y(`min-w-0 shrink-[9999] truncate`,s),children:u}):null,t[7]=s,t[8]=u,t[9]=y):y=t[9];let b;t[10]!==s||t[11]!==d||t[12]!==u?(b=d?(0,$.jsxs)(`span`,{className:Y(`shrink-0`,s),children:[u?`/`:``,d]}):null,t[10]=s,t[11]=d,t[12]=u,t[13]=b):b=t[13];let x;t[14]!==s||t[15]!==h?(x=h?(0,$.jsx)(`span`,{className:s,children:`/`}):null,t[14]=s,t[15]=h,t[16]=x):x=t[16];let S;t[17]===c?S=t[18]:(S=Y(`min-w-0 truncate`,c),t[17]=c,t[18]=S);let C;t[19]!==f||t[20]!==S?(C=(0,$.jsx)(`span`,{className:S,children:f}),t[19]=f,t[20]=S,t[21]=C):C=t[21];let w;t[22]!==p||t[23]!==c?(w=p?(0,$.jsx)(`span`,{className:Y(`shrink-0`,c),children:p}):null,t[22]=p,t[23]=c,t[24]=w):w=t[24];let T;t[25]!==C||t[26]!==w||t[27]!==x?(T=(0,$.jsxs)(`span`,{className:`flex min-w-0 shrink items-baseline`,children:[x,C,w]}),t[25]=C,t[26]=w,t[27]=x,t[28]=T):T=t[28];let E;return t[29]!==T||t[30]!==g||t[31]!==_||t[32]!==v||t[33]!==y||t[34]!==b?(E=(0,$.jsxs)(`span`,{className:g,title:_,children:[v,y,b,T]}),t[29]=T,t[30]=g,t[31]=_,t[32]=v,t[33]=y,t[34]=b,t[35]=E):E=t[35],E}var vg=e=>{let t=(0,Q.c)(23),{files:n,currentDirectory:r,onOpenFile:i}=e,{t:a}=ct(),o;t[0]===a?o=t[1]:(o=a(`chat.changedFiles.title`),t[0]=a,t[1]=o);let s;t[2]===o?s=t[3]:(s=(0,$.jsx)(`span`,{className:Tc,children:o}),t[2]=o,t[3]=s);let c;t[4]===n.length?c=t[5]:(c=(0,$.jsx)(`span`,{className:Ac,children:n.length}),t[4]=n.length,t[5]=c);let l;t[6]!==s||t[7]!==c?(l=(0,$.jsxs)(`div`,{className:qc,children:[s,c]}),t[6]=s,t[7]=c,t[8]=l):l=t[8];let u;if(t[9]!==r||t[10]!==n||t[11]!==i||t[12]!==a){let e;t[14]!==r||t[15]!==i||t[16]!==a?(e=(e,t)=>{let{fileName:n,dirPart:o}=fg(e,r),s=pg(e);return(0,$.jsxs)(`button`,{type:`button`,className:Y(`relative flex w-full cursor-pointer items-center gap-2.5 outline-hidden select-none text-left hover:bg-interactive-hover`,jc),title:a(`chat.changedFiles.actions.openFileTitle`,{path:e.path}),onClick:()=>i(e),children:[(0,$.jsx)(yd,{filePath:e.path,className:`h-3 w-3 shrink-0 md:h-3.5 md:w-3.5`}),(0,$.jsx)(_g,{path:o?`${o}/${n}`:n,title:e.path,className:`min-w-0 flex-1`}),s.additions>0||s.deletions>0?(0,$.jsxs)(`span`,{className:`flex-shrink-0 inline-flex items-baseline gap-1 text-xs tabular-nums leading-4 md:text-[0.8125rem] md:leading-5`,children:[s.additions>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,s.additions]}):null,s.deletions>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,s.deletions]}):null]}):null]},`${e.path}:${t}`)},t[14]=r,t[15]=i,t[16]=a,t[17]=e):e=t[17],u=n.map(e),t[9]=r,t[10]=n,t[11]=i,t[12]=a,t[13]=u}else u=t[13];let d;t[18]===u?d=t[19]:(d=(0,$.jsx)(`div`,{className:Kc,children:u}),t[18]=u,t[19]=d);let f;return t[20]!==l||t[21]!==d?(f=(0,$.jsxs)($.Fragment,{children:[l,d]}),t[20]=l,t[21]=d,t[22]=f):f=t[22],f},yg=`${Nc} origin-[var(--transform-origin)]`,bg=Dc,xg=Z.memo(()=>{let e=(0,Q.c)(60),{t}=ct(),[n,r]=Z.useState(!1),i=Z.useRef(null),a=pc()??null,o=Z.useContext(Ao),s=fs(a),c;e[0]===a?c=e[1]:(c=e=>a?e.directories.get(a)?.status??null:null,e[0]=a,e[1]=c);let l=Xo(c),u=rg(),d,f;e[2]===n?(d=e[3],f=e[4]):(d=()=>{if(!n)return;let e=e=>{i.current&&!i.current.contains(e.target)&&r(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},f=[n],e[2]=n,e[3]=d,e[4]=f),Z.useEffect(d,f);let p;bb0:{if(!a||s!==!0||!l||l.isClean){let t;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[5]=t):t=e[5],p=t;break bb0}let t;e[6]!==a||e[7]!==l.diffStats||e[8]!==l.files?(t=lg(l.files,l.diffStats,a),e[6]=a,e[7]=l.diffStats,e[8]=l.files,e[9]=t):t=e[9],p=t}let m=p,h=0,g=0;if(e[10]!==h||e[11]!==m||e[12]!==g){for(let e of m)h+=e.insertions,g+=e.deletions;e[10]=h,e[11]=m,e[12]=g,e[13]=h,e[14]=g}else h=e[13],g=e[14];let _;e[15]!==h||e[16]!==g?(_={totalAdded:h,totalRemoved:g},e[15]=h,e[16]=g,e[17]=_):_=e[17];let{totalAdded:v,totalRemoved:y}=_;if(!a||s!==!0||m.length===0)return null;let b;e[18]!==a||e[19]!==u||e[20]!==o?.editor?(b=e=>{if(!a||!ag(e))return;r(!1);let t=e.path;if(u){u.openChanges({diffPath:e.relativePath,staged:e.hasStagedChanges&&!e.hasWorkingChanges});return}let n=o?.editor;if(n){n.openFile(t);return}let i=q.getState(),s=e.hasStagedChanges&&!e.hasWorkingChanges;if(!i.isMobile){i.openContextDiff(a,e.relativePath,s);return}i.navigateToDiff(e.relativePath,s),i.setRightSidebarOpen(!1)},e[18]=a,e[19]=u,e[20]=o?.editor,e[21]=b):b=e[21];let x=b,S=m.length,C;e[22]!==S||e[23]!==t?(C=t(S===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:S}),e[22]=S,e[23]=t,e[24]=C):C=e[24];let w=C,T,E;e[25]===Symbol.for(`react.memo_cache_sentinel`)?(T=Y(Ec,`max-w-full text-left`),E=()=>r(Sg),e[25]=T,e[26]=E):(T=e[25],E=e[26]);let D,O;e[27]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(X,{name:`file-edit`,className:kc}),D=Y(zc,`shrink-0`),e[27]=D,e[28]=O):(D=e[27],O=e[28]);let k;e[29]===w?k=e[30]:(k=(0,$.jsx)(`span`,{className:D,children:w}),e[29]=w,e[30]=k);let A;e[31]===Symbol.for(`react.memo_cache_sentinel`)?(A=Y(`status-row__changed-label`,zc),e[31]=A):A=e[31];let j;e[32]===t?j=e[33]:(j=t(`chat.pendingChanges.changedInWorkspace`),e[32]=t,e[33]=j);let M;e[34]===j?M=e[35]:(M=(0,$.jsx)(`span`,{className:A,children:j}),e[34]=j,e[35]=M);let N;e[36]===Symbol.for(`react.memo_cache_sentinel`)?(N=Y(wc,`items-baseline gap-0.5`),e[36]=N):N=e[36];let P;e[37]===v?P=e[38]:(P=v>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,v]}):null,e[37]=v,e[38]=P);let F;e[39]===y?F=e[40]:(F=y>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,y]}):null,e[39]=y,e[40]=F);let I;e[41]!==P||e[42]!==F?(I=(0,$.jsxs)(`span`,{className:N,children:[P,F]}),e[41]=P,e[42]=F,e[43]=I):I=e[43];let L;e[44]===n?L=e[45]:(L=n?(0,$.jsx)(X,{name:`arrow-up-s`,className:kc}):(0,$.jsx)(X,{name:`arrow-down-s`,className:kc}),e[44]=n,e[45]=L);let R;e[46]!==n||e[47]!==k||e[48]!==M||e[49]!==I||e[50]!==L?(R=(0,$.jsxs)(`button`,{type:`button`,className:T,onClick:E,"aria-expanded":n,children:[O,k,M,I,L]}),e[46]=n,e[47]=k,e[48]=M,e[49]=I,e[50]=L,e[51]=R):R=e[51];let z;e[52]!==a||e[53]!==m||e[54]!==x||e[55]!==n?(z=n&&(0,$.jsx)(`div`,{style:bg,className:Y(yg,`absolute left-0 bottom-full mb-1 z-50`,`animate-in fade-in-0 zoom-in-95 slide-in-from-bottom-2`,`duration-150`),children:(0,$.jsx)(vg,{files:m,currentDirectory:a,onOpenFile:x})}),e[52]=a,e[53]=m,e[54]=x,e[55]=n,e[56]=z):z=e[56];let B;return e[57]!==R||e[58]!==z?(B=(0,$.jsxs)(`div`,{className:`relative`,ref:i,children:[R,z]}),e[57]=R,e[58]=z,e[59]=B):B=e[59],B});xg.displayName=`PendingChangesBar`;function Sg(e){return!e}var Cg=Z.memo(e=>{let t=(0,Q.c)(22),{visible:n,onClick:r,placement:i}=e,a=i===void 0?`default`:i,{t:o}=ct(),s=a===`compact`;if(s&&!n)return null;let c=a==="default"&&`absolute left-1/2 bottom-full mb-2 -translate-x-1/2`,l=a===`expanded`&&`absolute left-1/2 -translate-x-1/2 oc-scroll-to-bottom--expanded mb-2`,u=a===`compact`&&`oc-scroll-to-bottom--compact relative shrink-0`,d;t[0]!==a||t[1]!==c||t[2]!==l||t[3]!==u||t[4]!==n?(d=Y(c,l,u,n?Y(`pointer-events-auto`,a==="default"&&`opacity-100`):Y(`opacity-0 pointer-events-none`,a===`expanded`&&`oc-scroll-to-bottom--hidden`)),t[0]=a,t[1]=c,t[2]=l,t[3]=u,t[4]=n,t[5]=d):d=t[5];let f=s?`ghost`:`outline`,p=s?`composer-mobile-actions h-8 w-8 rounded-none bg-transparent hover:bg-transparent text-foreground`:`size-8 rounded-full [corner-shape:round] bg-background/95 hover:bg-interactive-hover`,m;t[6]===p?m=t[7]:(m=Y(`p-0 shadow-none`,p),t[6]=p,t[7]=m);let h;t[8]===o?h=t[9]:(h=o(`chat.scrollToBottom.aria`),t[8]=o,t[9]=h);let g=s?`size-5`:`size-4`,_=s?`medium`:`regular`,v;t[10]!==g||t[11]!==_?(v=(0,$.jsx)(X,{name:`arrow-down`,className:g,weight:_}),t[10]=g,t[11]=_,t[12]=v):v=t[12];let y;t[13]!==r||t[14]!==v||t[15]!==f||t[16]!==m||t[17]!==h?(y=(0,$.jsx)(ua,{variant:f,size:`sm`,onClick:r,className:m,"aria-label":h,children:v}),t[13]=r,t[14]=v,t[15]=f,t[16]=m,t[17]=h,t[18]=y):y=t[18];let b;return t[19]!==y||t[20]!==d?(b=(0,$.jsx)(`div`,{className:d,children:y}),t[19]=y,t[20]=d,t[21]=b):b=t[21],b}),wg=Z.createContext(`default`),Tg=()=>Z.useContext(wg),Eg=500,Dg=e=>{let t=(0,Q.c)(31),{onCycleAgent:n,onOpenAgentPanel:r,className:i,agentName:a,agents:o,disabled:s}=e,c;t[0]===o?c=t[1]:(c=o===void 0?[]:o,t[0]=o,t[1]=c);let l=c,u=s!==void 0&&s,d=a??void 0,f;t[2]!==l||t[3]!==d?(f=Un(l,d),t[2]=l,t[3]=d,t[4]=f):f=t[4];let p=f,m=dm(d),h;t[5]===d?h=t[6]:(h=na(d),t[5]=d,t[6]=h);let g=h,_=Z.useRef(null),v=Z.useRef(!1),y;t[7]!==u||t[8]!==r?(y=e=>{e.preventDefault(),!u&&(v.current=!1,_.current=setTimeout(()=>{v.current=!0,r()},Eg))},t[7]=u,t[8]=r,t[9]=y):y=t[9];let b=y,x;t[10]!==u||t[11]!==n?(x=()=>{_.current&&=(clearTimeout(_.current),null),!u&&!v.current&&n()},t[10]=u,t[11]=n,t[12]=x):x=t[12];let S=x,C;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(C=()=>{_.current&&=(clearTimeout(_.current),null)},t[13]=C):C=t[13];let w=C,T,E;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(E=()=>()=>{_.current&&clearTimeout(_.current)},T=[],t[14]=T,t[15]=E):(T=t[14],E=t[15]),Z.useEffect(E,T);let D;t[16]===i?D=t[17]:(D=Y(`inline-flex flex-shrink-0 items-center select-none focus:outline-none touch-none disabled:cursor-not-allowed disabled:opacity-40`,vm,i),t[16]=i,t[17]=D);let O;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(O={height:`26px`,maxHeight:`26px`,minHeight:`26px`},t[18]=O):O=t[18];let k;t[19]!==g.var||t[20]!==p||t[21]!==d||t[22]!==m?(k=(0,$.jsx)(um,{name:d,label:p,revealed:m,avatarSize:16,slotClassName:`h-[26px] w-6`,colorVar:g.var}),t[19]=g.var,t[20]=p,t[21]=d,t[22]=m,t[23]=k):k=t[23];let A;return t[24]!==p||t[25]!==u||t[26]!==b||t[27]!==S||t[28]!==D||t[29]!==k?(A=(0,$.jsx)(`button`,{type:`button`,disabled:u,onPointerDown:b,onPointerUp:S,onPointerLeave:w,onContextMenu:Og,onMouseDown:kg,className:D,style:O,title:p,"aria-label":p,children:k}),t[24]=p,t[25]=u,t[26]=b,t[27]=S,t[28]=D,t[29]=k,t[30]=A):A=t[30],A};function Og(e){return e.preventDefault()}function kg(e){return e.preventDefault()}var Ag=e=>{let t=(0,Q.c)(28),{onOpenModel:n,className:r,providerID:i,modelID:a,provider:o,variant:s,disabled:c}=e,l=c!==void 0&&c,{t:u}=ct(),d;t[0]!==a||t[1]!==o||t[2]!==u?(d=Bn(o,a,u(`chat.modelControls.selectModel`)),t[0]=a,t[1]=o,t[2]=u,t[3]=d):d=t[3];let f=d,p;t[4]===s?p=t[5]:(p=s?.trim()?xt(s):null,t[4]=s,t[5]=p);let m=p,h=m?`${f} ${m}`:f,g;t[6]===r?g=t[7]:(g=Y(`inline-flex min-w-0 max-w-36 items-stretch`,`rounded-lg`,`focus:outline-none hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-40`,r),t[6]=r,t[7]=g);let _;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(_={height:`26px`,maxHeight:`26px`,minHeight:`26px`},t[8]=_):_=t[8];let v;t[9]!==a||t[10]!==i?(v=a||i?(0,$.jsx)(Ma,{modelId:a,providerId:i,className:`size-4 flex-shrink-0`}):null,t[9]=a,t[10]=i,t[11]=v):v=t[11];let y;t[12]===f?y=t[13]:(y=(0,$.jsx)(`span`,{className:`truncate text-[11px] leading-none font-medium text-foreground/80`,children:f}),t[12]=f,t[13]=y);let b;t[14]===m?b=t[15]:(b=m?(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] leading-none font-normal text-muted-foreground`,children:m}):null,t[14]=m,t[15]=b);let x;t[16]!==y||t[17]!==b?(x=(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1`,children:[y,b]}),t[16]=y,t[17]=b,t[18]=x):x=t[18];let S;t[19]!==v||t[20]!==x?(S=(0,$.jsxs)(`span`,{className:`flex h-full w-full min-w-0 items-center gap-1`,children:[v,x]}),t[19]=v,t[20]=x,t[21]=S):S=t[21];let C;return t[22]!==h||t[23]!==l||t[24]!==n||t[25]!==S||t[26]!==g?(C=(0,$.jsx)(`button`,{type:`button`,disabled:l,onClick:n,onMouseDown:jg,onPointerDownCapture:Mg,className:g,style:_,title:h,"aria-label":h,children:S}),t[22]=h,t[23]=l,t[24]=n,t[25]=S,t[26]=g,t[27]=C):C=t[27],C};function jg(e){return e.preventDefault()}function Mg(e){e.preventDefault()}var Ng={phase:`idle`,isWorking:!1,isBusy:!1,isCooldown:!1},Pg=e=>e.hasPendingAssistant?e.messages.some(e=>e.role===`assistant`&&typeof e.time?.completed==`number`):!1;function Fg(e,t){let n=(0,Q.c)(6),r=Fi(e??``,t),i=Sr(e??``,t),a=fr(e??``,t),o=yr(e??``,t),s=ai(e??``,t),c=jr(t),l;bb0:{if(!e){l=Ng;break bb0}if(o.length>0||s.length>0){l=Ng;break bb0}let t=r?.type??`idle`,u=a[a.length-1],d=!!(u&&u.role===`assistant`&&typeof u.time?.completed!=`number`),f=a,p;n[0]!==d||n[1]!==f?(p=Pg({messages:f,hasPendingAssistant:d}),n[0]=d,n[1]=f,n[2]=p):p=n[2];let m=p,h=u?.time?.created,g=!!(m&&typeof c==`number`&&typeof h==`number`&&h<=c),_=r!==void 0,v=_&&t!==`idle`,y=v||m&&!g;if(_&&!v&&(!m||_&&!v&&typeof i==`number`&&typeof h==`number`&&h<=i)){l=Ng;break bb0}if(!y){l=Ng;break bb0}let b=v?t:`busy`,x=t===`busy`||!v&&m,S;n[3]!==b||n[4]!==x?(S={phase:b,isWorking:!0,isBusy:x,isCooldown:!1},n[3]=b,n[4]=x,n[5]=S):S=n[5],l=S}return l}var Ig=e=>e.nativeEvent.isComposing||e.nativeEvent.keyCode===229;function Lg(e){let t=(0,Q.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:r,children:n,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===r?a=t[5]:(a=Y(`inline-flex shrink-0 items-center justify-center rounded-full bg-foreground text-background`,r),t[4]=r,t[5]=a);let o;return t[6]!==n||t[7]!==i||t[8]!==a?(o=(0,$.jsx)(`span`,{className:a,...i,"aria-hidden":!0,children:n}),t[6]=n,t[7]=i,t[8]=a,t[9]=o):o=t[9],o}function Rg(e){let t=(0,Q.c)(7),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(`span`,{"data-stop-glyph":`true`,className:`block size-[38%] rounded-[20%] bg-current`}),t[3]=i):i=t[3];let a;return t[4]!==n||t[5]!==r?(a=(0,$.jsx)(Lg,{className:n,...r,children:i}),t[4]=n,t[5]=r,t[6]=a):a=t[6],a}function zg(e){let t=(0,Q.c)(13),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,spinning:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i!==void 0&&i,o=a?`loader-4`:`arrow-up`,s=a?`size-[50%] animate-spin`:`size-[56%]`,c;t[4]===s?c=t[5]:(c=Y(s),t[4]=s,t[5]=c);let l;t[6]!==o||t[7]!==c?(l=(0,$.jsx)(X,{name:o,weight:`medium`,className:c}),t[6]=o,t[7]=c,t[8]=l):l=t[8];let u;return t[9]!==n||t[10]!==r||t[11]!==l?(u=(0,$.jsx)(Lg,{className:n,...r,children:l}),t[9]=n,t[10]=r,t[11]=l,t[12]=u):u=t[12],u}var Bg=e=>!(!e.sessionId||e.composerSurfaceKind===`secondary`||e.hasSessionEntity||e.hasRenderableSessionSnapshot),Vg=e=>{let t=e.isSubagentSession&&!e.allowPromptingSubagentSessions;return{showReadOnlyBanner:e.isSubagentSession&&(e.readOnly||t),blockSubmission:e.sessionIdentityPending}},Hg=(e,t)=>({agentName:t.agentName??e?.agentName,providerId:t.providerId??e?.providerId,modelId:t.modelId??e?.modelId}),Ug=(e,t)=>e.id===t.id&&e.directory===t.directory,Wg=(e,t)=>e.agentName===t.agentName&&e.providerId===t.providerId&&e.modelId===t.modelId,Gg=(e,t,n,r)=>{if(!t)return null;let i=n??(e?.viewKey===t?e.parentTarget:null);if(!i)return null;let a=Hg(e?.viewKey===t?e.execution:void 0,r);return e&&e.viewKey===t&&Ug(e.parentTarget,i)&&Wg(e.execution,a)?e:{viewKey:t,parentTarget:i,execution:a}},Kg=e=>{let{inFlight:t,establishing:n}=e.sendPhase,r=!n&&(e.draftSubmitting||t);return{sendDisabled:!e.canSend||!e.hasSessionTarget||e.submissionBlocked||r,queueDisabled:!e.hasSessionTarget||e.submissionBlocked||!n&&t||e.queueFrozen&&!e.queueFallbackAvailable,disabledClass:`opacity-30 pointer-events-none`}},qg=`data-mobile-overlay-active`,Jg=e=>Array.from(e).some(e=>e.getAttribute(qg)!==`false`),Yg=`artful.bionic.cosmic.disco.focal.groovy.jammy.kinetic.lunar.noble.bold.brave.calm.eager.gentle.happy.keen.lively.merry.swift.warm.wise.bright.clever.daring.agile.crisp.fresh.lucid.quick.sharp.vivid.zealous`.split(`.`),Xg=`aardvark.beaver.chipmunk.dolphin.falcon.gopher.hedgehog.jackal.koala.lemur.mongoose.narwhal.otter.pangolin.quokka.raccoon.salamander.toucan.walrus.yak.zebra.badger.condor.dingo.egret.ferret.gecko.heron.iguana`.split(`.`);function Zg(){return`${Yg[Math.floor(Math.random()*Yg.length)]}-${Xg[Math.floor(Math.random()*Xg.length)]}`}function Qg(e){let t=Zg();return e&&e.trim()?`${e.trim().replace(/\/+$/,``)}/${t}`:t}var $g=e=>e.replace(/\\/g,`/`).replace(/\/+$/,``)||e,e_=e=>({agentName:e.currentAgentName,providerId:e.currentProviderId,modelId:e.currentModelId,variant:e.currentVariant}),t_=(e,t,n)=>{let r=t.agentName?.trim()||void 0,i=t.providerId?.trim()||void 0,a=t.modelId?.trim()||void 0;!r||!i||!a||(n.saveSessionAgentSelection(e,r),n.saveSessionModelSelection(e,i,a),n.saveAgentModelForSession(e,r,i,a),n.saveAgentModelVariantForSession(e,r,i,a,t.variant))},n_=async(e,t)=>{await kn(e)&&await rr(t)},r_=e=>{let t=$g(e),n=gr.getState().projects;if(n.length===0)return null;let r=gr.getState().getActiveProject();if(r?.path){let e=$g(r.path);if(t===e||t.startsWith(`${e}/`))return{id:r.id,path:r.path}}let i=n.filter(e=>{let n=$g(e.path);return t===n||t.startsWith(`${n}/`)}).sort((e,t)=>$g(t.path).length-$g(e.path).length)[0];return i?{id:i.id,path:i.path}:null},i_=!1,a_=async(e,t)=>{try{let n=gr.getState().projects.find(e=>e.id===t.id)??gr.getState().projects.find(e=>$g(e.path)===$g(t.path)),r=wr(t.path);await Ai.getState().activateDirectory(t.path,{source:`worktreeSessionCreator`});let i=Ai.getState();if(i.activeDirectoryKey!==r||i.providers.length===0||i.agents.length===0)return;i.applyDefaultModelAgentSelection({projectDefaultModel:n?.defaultModel??void 0}),t_(e,e_(Ai.getState()),Zi.getState())}catch{}},o_=async(e,t,n)=>{let r=ri.getState(),i=Ai.getState();r.initializeNewOpenChamberSession(e,i.agents),r.setSessionDirectory(e,t.path),r.setWorktreeMetadata(e,t),await a_(e,n),Se.getState().setDirectory(t.path,{showOverlay:!1})},s_=e=>e.trim().replace(/^remotes\//,``).replace(/[^A-Za-z0-9._/-]+/g,`-`).replace(/\/+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`worktree`,c_=async e=>{if(i_)return null;let t=gr.getState().getActiveProject(),n=e?.projectDirectory?.trim()||t?.path;if(!n)return Br.error(`No active project`,{description:`Please select a project first.`}),null;let r=r_(n)??(t?.path?{id:t.id,path:t.path}:null);if(!r)return Br.error(`No active project`,{description:`Please select a project first.`}),null;let i=!1;try{i=await fa(r.path)}catch{}if(!i)return Br.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;i_=!0;try{let t=wn(),n=e?.existingBranch?.trim().replace(/^remotes\//,``)||``,i=n?s_(n):Qg(),a=n?`existing`:`new`,o=ri.getState();o.newSessionDraft?.open?o.overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:o.newSessionDraft.directoryOverride??r.path,pendingWorktreeRequestId:t,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}):o.openNewSessionDraft({selectedProjectId:r.id,directoryOverride:r.path,pendingWorktreeRequestId:t,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt});let s=await da(r.path,{mode:a,...a===`new`?{branchName:i,worktreeName:i}:{existingBranch:n,worktreeName:i}}).catch(()=>null);s?.path&&(ri.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:s.path,pendingWorktreeRequestId:t,bootstrapPendingDirectory:s.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),Se.getState().setDirectory(s.path,{showOverlay:!1}));let c=await rn(r),l=await Zo(r,{preferredName:i,mode:a,worktreeName:i,setupCommands:c,returnAfterDirectoryCreated:!0,...a===`new`?{branchName:i}:{existingBranch:n}});return Er(t,l.path),ri.getState().overrideNewSessionDraftTarget({projectId:r.id,directoryOverride:l.path,pendingWorktreeRequestId:null,bootstrapPendingDirectory:l.path,preserveDirectoryOverride:!0,title:e?.title,initialPrompt:e?.initialPrompt}),Se.getState().setDirectory(l.path,{showOverlay:!1}),l.path}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree`,n=ri.getState().newSessionDraft.pendingWorktreeRequestId;return n&&(ht(n,e instanceof Error?e:Error(t)),ri.getState().resolvePendingDraftWorktreeTarget(n,null)),ri.getState().setDraftBootstrapPendingDirectory(null),Br.error(`Failed to create worktree`,{description:t}),null}finally{i_=!1}};async function l_(){return c_()}async function u_(e){let t=e.branch?.trim();return t?c_({existingBranch:t,projectDirectory:e.projectDirectory,initialPrompt:e.initialPrompt,title:e.title}):null}async function d_(e,t,n,r){if(i_)return null;i_=!0;try{let i=n?.trim()||`HEAD`,a=t?.trim();if(!a)throw Error(`Branch name is required`);let o=r?.kind??`standard`,s=r_(e);if(!s)throw Error(`Project is not registered in OpenChamber`);let c=!1;try{c=await fa(s.path)}catch{}if(!c)return Br.error(`Not a Git repository`,{description:`Worktrees can only be created in Git repositories.`}),null;let l=await rn(s),u=await Fa(s.path);try{let e=await Zo(s,{preferredName:a,mode:`new`,branchName:a,worktreeName:r?.worktreeName||a,startRef:i,setUpstream:r?.setUpstream,upstreamRemote:r?.upstreamRemote,upstreamBranch:r?.upstreamBranch,ensureRemoteName:r?.ensureRemoteName,ensureRemoteUrl:r?.ensureRemoteUrl,setupCommands:l,returnAfterDirectoryCreated:r?.returnAfterDirectoryCreated}),t={...e,createdFromBranch:r?.createdFromBranch||u||i,kind:o};await n_(s,e.path);let n=await ri.getState().createSession(void 0,e.path);if(!n)throw await La(s,e,{deleteLocalBranch:!0}).catch(()=>void 0),Error(`Could not create a session for the worktree.`);return await o_(n.id,t,s),{id:n.id,branch:e.branch||a,path:e.path}}catch(e){let t=e instanceof Error?e.message:`Failed to create worktree session`;return Br.error(`Failed to create worktree`,{description:t}),null}}finally{i_=!1}}var f_=e=>{let t=e.trim();if(!t)return null;let n=t.match(/\/issues\/(\d+)(?:\b|\/|$)/i);if(n){let e=Number(n[1]);return Number.isFinite(e)&&e>0?e:null}let r=t.match(/^#?(\d+)$/);if(r){let e=Number(r[1]);return Number.isFinite(e)&&e>0?e:null}return null},p_=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`};function m_({open:e,onOpenChange:t,mode:n=`createSession`,onSelect:r}){let{t:i}=ct(),{github:a}=ko(),o=to(),s=o.data??null,c=o.isFetched,l=q(e=>e.setSettingsDialogOpen),u=q(e=>e.setSettingsPage),d=q(e=>e.isMobile),{isTablet:f}=mo(),p=d||f,m=gr(e=>e.getActiveProject()),h=Se(e=>e.currentDirectory),g=Z.useMemo(()=>m?.path?.trim()||h?.trim()||null,[m?.path,h]),[_,v]=Z.useState(``),[y,b]=Z.useState(!1),[x,S]=Z.useState(null),C=Z.useRef(0),w=Z.useMemo(()=>f_(_),[_]),T=Ho(_,350),E=w?``:T.trim(),D=!!w||_===T,O=e&&D&&!!g&&!!a?.issuesList&&!(c&&s?.connected===!1),k=Je({queryKey:M.scoped(`github-issues`,g,E),enabled:O,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>a.issuesList(g,{page:e,...E?{query:E}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),A=D?k.data?.pages.at(-1)??null:null,j=D?k.data?.pages.flatMap(e=>e.issues??[])??[]:[],N=D&&k.hasNextPage,P=!w&&!D||k.isLoading,F=D&&k.isFetchingNextPage,I=D&&k.error?k.error instanceof Error?k.error.message:String(k.error):null,L=Z.useCallback(()=>k.refetch(),[k]),R=Z.useCallback(async()=>{try{await k.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);Br.error(i(`session.githubIssuePicker.toast.loadMoreFailed`),{description:t})}},[k,i]);Z.useEffect(()=>{e||(++C.current,v(``),b(!1),S(null))},[e]),Z.useEffect(()=>{++C.current},[e,g]);let z=!c||s?.connected!==!1&&A?.connected!==!1,B=A?.repo?.url??null,V=Z.useCallback(()=>{u(`github`),l(!0)},[l,u]),H=Z.useCallback(()=>{let e=Ai.getState(),t=e.getVisibleAgents();if(e.settingsDefaultAgent){let n=t.find(t=>t.name===e.settingsDefaultAgent);if(n)return n.name}return t.find(e=>e.name===`build`)?.name||t[0]?.name},[]),U=Z.useCallback(()=>{let e=Ai.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=It(t);if(!n)return null;let{providerId:r,modelId:i}=n;return e.getModelMetadata(r,i)?{providerID:r,modelID:i}:null},[]),W=Z.useCallback((e,t)=>{let n=Ai.getState(),r=n.settingsDefaultVariant,i=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0,a=n.providers.find(t=>t.id===e)?.models.find(e=>e.id===t)?.variants;if(!a)return r||i||void 0;if(r&&Object.prototype.hasOwnProperty.call(a,r))return r;if(i&&Object.prototype.hasOwnProperty.call(a,i))return i},[]),ee=Z.useCallback(async(e,o)=>{let s=++C.current,c=()=>C.current===s;if(n===`select`){if(!g){Br.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){Br.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(x)return;S(e);try{let n=await a.issueGet(g,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){Br.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){Br.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let s=n.issue;if(!s){Br.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let l=await a.issueComments(g,e,{sourceRepo:o});if(!c())return;if(l.connected===!1){Br.error(i(`session.githubIssuePicker.error.notConnected`));return}let u=l.comments??[],d=p_({repo:n.repo,issue:s,comments:u});r&&r({number:s.number,title:s.title,url:s.url,contextText:d,author:s.author?{login:s.author.login,avatarUrl:s.author.avatarUrl}:void 0}),t(!1)}catch(e){if(!c())return;let t=e instanceof Error?e.message:String(e);Br.error(i(`session.githubIssuePicker.toast.loadIssueDetailsFailed`),{description:t})}finally{c()&&S(null)}return}if(!g){Br.error(i(`session.githubIssuePicker.error.noActiveProject`));return}if(!a?.issueGet||!a?.issueComments){Br.error(i(`session.githubIssuePicker.error.runtimeUnavailable`));return}if(!x){S(e);try{let n=await a.issueGet(g,e,{sourceRepo:o});if(!c())return;if(n.connected===!1){Br.error(i(`session.githubIssuePicker.error.notConnected`));return}if(!n.repo){Br.error(i(`session.githubIssuePicker.error.repoNotResolvable`),{description:i(`session.githubIssuePicker.error.repoMustBeGithub`)});return}let r=n.issue;if(!r){Br.error(i(`session.githubIssuePicker.error.issueNotFound`));return}let s=await a.issueComments(g,e,{sourceRepo:o});if(!c())return;if(s.connected===!1){Br.error(i(`session.githubIssuePicker.error.notConnected`));return}let l=s.comments??[],u=`#${r.number} ${r.title}`.trim(),{sessionId:d}=await(async()=>{if(y){let e=`issue-${r.number}-${Zg()}`,t=await d_(g,e,void 0,{returnAfterDirectoryCreated:!0});if(!t?.id)throw Error(`Failed to create worktree session`);return{sessionId:t.id,sessionDirectory:t.path}}let e=await Yt(u,g,null);if(!e?.id)throw Error(`Failed to create session`);return{sessionId:e.id,sessionDirectory:e.directory??g}})();if(!c())return;er(d,u).catch(()=>void 0);try{ri.getState().initializeNewOpenChamberSession(d,Ai.getState().agents)}catch{}t(!1);let f=Ai.getState(),p=Zi.getState().lastUsedProvider,m=U(),h=m?.providerID||f.currentProviderId||p?.providerID,_=m?.modelID||f.currentModelId||p?.modelID,v=H()||f.currentAgentName||void 0;if(!h||!_){Br.error(i(`session.githubIssuePicker.error.noModelSelected`));return}let b=W(h,_),x=await Ci(`github.issue.review.visible`,{issue_number:String(r.number)});if(!c())return;let S=await Ci(`github.issue.review.instructions`);if(!c())return;let C=p_({repo:n.repo,issue:r,comments:l});ri.getState().sendMessage(x,h,_,v,void 0,void 0,[{text:S,synthetic:!0},{text:C,synthetic:!0}],b,void 0,{sessionId:d}).catch(e=>{let t=e instanceof Error?e.message:String(e);Br.error(i(`session.githubIssuePicker.toast.sendContextFailed`),{description:t})}),Br.success(i(`session.githubIssuePicker.toast.sessionCreated`))}catch(e){if(!c())return;let t=e instanceof Error?e.message:String(e);Br.error(i(`session.githubIssuePicker.toast.startSessionFailed`),{description:t})}finally{c()&&S(null)}}},[y,a,n,t,r,g,H,U,W,x,i]),G=i(n===`select`?`session.githubIssuePicker.title.select`:`session.githubIssuePicker.title.createSession`),K=i(n===`select`?`session.githubIssuePicker.description.select`:`session.githubIssuePicker.description.createSession`),te=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Va,{placeholder:i(`session.githubIssuePicker.searchPlaceholder`),value:_,onChange:e=>{v(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`div`,{className:Y(d?`min-h-0 mt-2`:`flex-1 overflow-y-auto mt-2`),children:[g?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:i(`session.githubIssuePicker.empty.noActiveProject`)}),a?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:i(`session.githubIssuePicker.empty.runtimeUnavailable`)}),P?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 flex items-center justify-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),i(`session.githubIssuePicker.loading.issues`)]}):null,z===!1?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 space-y-3`,children:[(0,$.jsx)(`div`,{children:i(`session.githubIssuePicker.empty.notConnected`)}),(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsx)(ua,{variant:`outline`,size:`sm`,onClick:V,children:i(`session.githubIssuePicker.actions.openSettings`)})})]}):null,I?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:I}):null,w&&g&&a&&z?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,x===w&&`bg-interactive-selection/30`),onClick:()=>void ee(w),children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground w-5 text-right flex-shrink-0`,children:`#`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 typography-small text-foreground truncate ml-0.5`,children:i(`session.githubIssuePicker.actions.useIssue`,{number:w})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:x===w?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,j.length===0&&!P&&!I&&z&&a&&g?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:T.trim()?i(`session.githubIssuePicker.empty.noIssuesFound`):i(`session.githubIssuePicker.empty.noOpenIssuesFound`)}):null,j.map(e=>(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,x===e.number&&`bg-interactive-selection/30`),onClick:()=>void ee(e.number,e.sourceRepo),children:[(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground w-12 text-right flex-shrink-0`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 ml-0.5`,children:[(0,$.jsx)(`p`,{className:`typography-small text-foreground truncate`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:x===e.number?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:Y(`h-5 w-5 items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,p?`flex`:`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),"aria-label":i(`session.githubIssuePicker.actions.openInGitHubAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4`})})})]},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)),N&&z&&g&&a?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void R(),disabled:F||!!x,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(F||!!x)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:F?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),i(`session.githubIssuePicker.loading.more`)]}):i(`session.githubIssuePicker.actions.loadMore`)})}):null]}),n!==`select`&&(0,$.jsxs)(`div`,{className:`mt-4 p-3 bg-muted/30 rounded-lg`,children:[(0,$.jsx)(`p`,{className:`typography-meta text-muted-foreground font-medium mb-2`,children:i(`session.githubIssuePicker.actions.sectionTitle`)}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 cursor-pointer`,role:`button`,tabIndex:0,"aria-pressed":y,onClick:()=>b(e=>!e),onKeyDown:e=>{(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),b(e=>!e))},children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),b(e=>!e)},"aria-label":i(`session.githubIssuePicker.actions.toggleWorktreeAria`),className:`flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,children:y?(0,$.jsx)(X,{name:`checkbox`,className:`h-4 w-4 text-primary`}):(0,$.jsx)(X,{name:`checkbox-blank`,className:`h-4 w-4`})}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:i(`session.githubIssuePicker.actions.createInWorktree`)}),(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground/70 hidden sm:inline`,children:`(issue-<number>-<slug>)`})]}),(0,$.jsx)(`div`,{className:`hidden sm:block sm:flex-1`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[B?(0,$.jsx)(ua,{variant:`outline`,size:`sm`,asChild:!0,children:(0,$.jsxs)(`a`,{href:B,target:`_blank`,rel:`noopener noreferrer`,children:[(0,$.jsx)(X,{name:`external-link`,className:`size-4`}),i(`session.githubIssuePicker.actions.openRepo`)]})}):null,(0,$.jsx)(ua,{variant:`outline`,size:`sm`,onClick:L,disabled:P||!!x,children:i(`session.githubIssuePicker.actions.refresh`)})]})]})]})]});return d?(0,$.jsx)(sm,{open:e,title:G,onClose:()=>t(!1),renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:G}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:K})]}),children:te}):(0,$.jsx)(sa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ra,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(ea,{className:`flex-shrink-0`,children:[(0,$.jsxs)(ia,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),G]}),(0,$.jsx)(aa,{children:K})]}),te]})})}var h_=e=>{let t=e.trim();if(!t)return null;let n=t.match(/\/pull\/(\d+)(?:\b|\/|$)/i);if(n){let e=Number(n[1]);return Number.isFinite(e)&&e>0?e:null}let r=t.match(/^#?(\d+)$/);if(r){let e=Number(r[1]);return Number.isFinite(e)&&e>0?e:null}return null},g_=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function __({open:e,onOpenChange:t,onSelect:n}){let{t:r}=ct(),{github:i}=ko(),a=to(),o=a.data??null,s=a.isFetched,c=q(e=>e.setSettingsDialogOpen),l=q(e=>e.setSettingsPage),u=q(e=>e.isMobile),{isTablet:d}=mo(),f=u||d,p=gr(e=>e.getActiveProject())?.path??null,[m,h]=Z.useState(``),[g,_]=Z.useState(!1),[v,y]=Z.useState(null),b=Z.useRef(0),x=Z.useMemo(()=>h_(m),[m]),S=Ho(m,350),C=x?``:S.trim(),w=!!x||m===S,T=e&&w&&!!p&&!!i?.prsList&&!(s&&o?.connected===!1),E=Je({queryKey:M.scoped(`github-prs`,p,C),enabled:T,initialPageParam:1,refetchOnMount:`always`,queryFn:({pageParam:e})=>i.prsList(p,{page:e,...C?{query:C}:{}}),getNextPageParam:e=>e.hasMore?(e.page??1)+1:void 0}),D=w?E.data?.pages.at(-1)??null:null,O=w?E.data?.pages.flatMap(e=>e.prs??[])??[]:[],k=w&&E.hasNextPage,A=!x&&!w||E.isLoading,j=w&&E.isFetchingNextPage,N=w&&E.error?E.error instanceof Error?E.error.message:String(E.error):null,P=J(async()=>{try{await E.fetchNextPage()}catch(e){let t=e instanceof Error?e.message:String(e);Br.error(r(`session.githubPrPicker.toast.loadMoreFailed`),{description:t})}});Z.useEffect(()=>{e||(++b.current,h(``),_(!1),y(null))},[e]),Z.useEffect(()=>{++b.current},[e,p]);let F=!s||o?.connected!==!1&&D?.connected!==!1,I=J(()=>{l(`github`),c(!0)}),L=J(async(e,a)=>{if(!p){Br.error(r(`session.githubPrPicker.error.noActiveProject`));return}if(!i?.prContext){Br.error(r(`session.githubPrPicker.error.runtimeUnavailable`));return}if(v)return;let o=++b.current,s=()=>b.current===o;y(e);try{let o=await i.prContext(p,e,{includeDiff:g,includeCheckDetails:!1,sourceRepo:a});if(!s())return;if(o.connected===!1){Br.error(r(`session.githubPrPicker.error.notConnected`));return}if(!o.pr){Br.error(r(`session.githubPrPicker.error.prNotFound`));return}if(!o.repo){Br.error(r(`session.githubPrPicker.error.repoNotResolvable`),{description:r(`session.githubPrPicker.error.repoMustBeGithub`)});return}if(n){let e=await Ci(`github.pr.review.instructions`);if(!s())return;n({number:o.pr.number,title:o.pr.title,url:o.pr.url,head:o.pr.head,base:o.pr.base,includeDiff:g,instructionsText:e,contextText:g_(o),author:o.pr.author?{login:o.pr.author.login,avatarUrl:o.pr.author.avatarUrl}:void 0})}t(!1)}catch(e){if(!s())return;let t=e instanceof Error?e.message:String(e);Br.error(r(`session.githubPrPicker.toast.loadDetailsFailed`),{description:t})}finally{s()&&y(null)}}),R=r(`session.githubPrPicker.title`),z=r(`session.githubPrPicker.description`),B=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1 min-w-0`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Va,{placeholder:r(`session.githubPrPicker.searchPlaceholder`),value:m,onChange:e=>{h(e.target.value)},className:`pl-9 w-full`})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`h-9 shrink-0 flex items-center gap-2 text-left`,"aria-pressed":g,"aria-label":r(`session.githubPrPicker.includeDiffAria`),children:[(0,$.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,$.jsx)(Da,{checked:g,onChange:e=>_(e),ariaLabel:r(`session.githubPrPicker.includeDiffAria`)})}),(0,$.jsx)(`span`,{className:`typography-small text-muted-foreground whitespace-nowrap`,children:r(`session.githubPrPicker.includeDiff`)})]})]}),(0,$.jsxs)(`div`,{className:Y(u?`min-h-0`:`flex-1 overflow-y-auto`),children:[p?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:r(`session.githubPrPicker.empty.noActiveProject`)}),i?null:(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:r(`session.githubPrPicker.empty.runtimeUnavailable`)}),A?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 flex items-center justify-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),r(`session.githubPrPicker.loading.pullRequests`)]}):null,F===!1?(0,$.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 space-y-3`,children:[(0,$.jsx)(`div`,{children:r(`session.githubPrPicker.empty.notConnected`)}),(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsx)(ua,{variant:`outline`,size:`sm`,onClick:I,children:r(`session.githubPrPicker.actions.openSettings`)})})]}):null,N?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8 break-words`,children:N}):null,x&&p&&i&&F?(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,v===x&&`bg-interactive-selection/30`),onClick:()=>void L(x),children:[(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground w-5 text-right flex-shrink-0`,children:`#`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 typography-small text-foreground truncate ml-0.5`,children:r(`session.githubPrPicker.actions.usePullRequest`,{number:x})}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:v===x?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):null})]}):null,O.length===0&&!A&&!N&&F&&i&&p?(0,$.jsx)(`div`,{className:`text-center text-muted-foreground py-8`,children:S.trim()?r(`session.githubPrPicker.empty.noPullRequestsFound`):r(`session.githubPrPicker.empty.noOpenPullRequestsFound`)}):null,O.map(e=>(0,$.jsxs)(`div`,{className:Y(`group flex items-center gap-2 py-1.5 hover:bg-interactive-hover/30 rounded transition-colors cursor-pointer`,v===e.number&&`bg-interactive-selection/30`),onClick:()=>void L(e.number,e.sourceRepo),children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 ml-0.5`,children:[(0,$.jsxs)(`p`,{className:`typography-small text-foreground truncate`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground mr-1`,children:[`#`,e.number]}),e.title]}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,(0,$.jsxs)(`p`,{className:`typography-meta text-muted-foreground truncate`,children:[e.head,` → `,e.base]})]}),(0,$.jsx)(`div`,{className:`flex-shrink-0 h-5 flex items-center mr-2`,children:v===e.number?(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`}):(0,$.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:Y(`h-5 w-5 items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,f?`flex`:`hidden group-hover:flex`),onClick:e=>e.stopPropagation(),"aria-label":r(`session.githubPrPicker.actions.openInGitHubAria`),children:(0,$.jsx)(X,{name:`external-link`,className:`h-4 w-4`})})})]},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)),k&&F&&p&&i?(0,$.jsx)(`div`,{className:`py-2 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>void P(),disabled:j||!!v,className:Y(`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-4`,(j||!!v)&&`opacity-50 cursor-not-allowed hover:text-muted-foreground`),children:j?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin`}),r(`session.githubPrPicker.loading.more`)]}):r(`session.githubPrPicker.actions.loadMore`)})}):null]})]});return u?(0,$.jsx)(sm,{open:e,title:R,onClose:()=>t(!1),renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:R}),e]}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground`,children:z})]}),children:B}):(0,$.jsx)(sa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ra,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsxs)(ea,{className:`flex-shrink-0`,children:[(0,$.jsxs)(ia,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),R]}),(0,$.jsx)(aa,{children:z})]}),B]})})}function v_(e){let t=(0,Q.c)(12),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,style:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===i?a=t[5]:(a={color:`var(--surface-elevated-foreground)`,...i},t[4]=i,t[5]=a);let o;t[6]===n?o=t[7]:(o=Y(`flex h-full w-full flex-col overflow-hidden rounded-xl`,n),t[6]=n,t[7]=o);let s;return t[8]!==r||t[9]!==a||t[10]!==o?(s=(0,$.jsx)(Yc,{"data-slot":`command`,style:a,className:o,...r}),t[8]=r,t[9]=a,t[10]=o,t[11]=s):s=t[11],s}var y_=Z.forwardRef((e,t)=>{let n=(0,Q.c)(11),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a,o;n[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=Y(`flex h-8 items-center gap-2 rounded-lg px-3`,`bg-[var(--surface-elevated)] ring-1 ring-inset ring-border/60 transition duration-200 ease-out`,`hover:[&:not(:focus-within)]:bg-[var(--surface-subtle)] hover:[&:not(:focus-within)]:ring-transparent`,`focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]`),o=(0,$.jsx)(X,{name:`search`,className:`size-4 shrink-0 opacity-50`}),n[3]=a,n[4]=o):(a=n[3],o=n[4]);let s;n[5]===r?s=n[6]:(s=Y(`placeholder:text-muted-foreground flex h-8 w-full bg-transparent typography-meta outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50`,r),n[5]=r,n[6]=s);let c;return n[7]!==i||n[8]!==t||n[9]!==s?(c=(0,$.jsx)(`div`,{"data-slot":`command-input-wrapper`,className:`p-1.5 pb-1`,children:(0,$.jsxs)(`div`,{"data-slot":`command-input-field`,className:a,children:[o,(0,$.jsx)(Yc.Input,{ref:t,"data-slot":`command-input`,className:s,...i})]})}),n[7]=i,n[8]=t,n[9]=s,n[10]=c):c=n[10],c});y_.displayName=`CommandInput`;function b_(e){let t=(0,Q.c)(14),n,r,i,a,o;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5]):({className:r,children:n,scrollbarClassName:o,disableHorizontal:i,...a}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o);let s;t[6]===r?s=t[7]:(s=Y(`scroll-py-1 overflow-x-hidden h-full min-h-0`,r),t[6]=r,t[7]=s);let c=o??`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,l=i??!0,u;return t[8]!==n||t[9]!==a||t[10]!==s||t[11]!==c||t[12]!==l?(u=(0,$.jsx)(pa,{as:Yc.List,"data-slot":`command-list`,outerClassName:`max-h-[min(600px,calc(100vh-10rem))] overflow-x-hidden p-0 w-full h-full min-h-0`,className:s,scrollbarClassName:c,disableHorizontal:l,...a,children:n}),t[8]=n,t[9]=a,t[10]=s,t[11]=c,t[12]=l,t[13]=u):u=t[13],u}function x_(e){let t=(0,Q.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,$.jsx)(Yc.Empty,{"data-slot":`command-empty`,className:`py-6 text-center typography-ui-label`,...n}),t[2]=n,t[3]=r),r}function S_(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Y(`text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:typography-meta [&_[cmdk-group-heading]]:font-medium`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(Yc.Group,{"data-slot":`command-group`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function C_(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Y(`bg-border -mx-1 h-px`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(Yc.Separator,{"data-slot":`command-separator`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function w_(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=Y(`data-[selected=true]:bg-interactive-selection data-[selected=true]:text-interactive-selection-foreground data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 typography-meta outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(Yc.Item,{"data-slot":`command-item`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var T_=(e,t)=>`${e}:${S(t)}`,E_=e=>e.type===`skill`||!ne(e.name);function D_(e){let{t}=ct(),n=Z.useMemo(()=>se(),[]),r=q(e=>e.globalDraftStarters),i=gr(e=>e.activeProjectId),a=gr(e=>e.projects),o=Z.useMemo(()=>{if(!i)return null;let e=a.find(e=>e.id===i);return e?.path?{id:e.id,path:e.path}:null},[i,a]),[s,c]=Z.useState([]),u=Z.useMemo(()=>r??re,[r]),d=u.some(E_)||s.some(E_),f=Yi({directory:e,enabled:d}),p=Z.useMemo(()=>f.data??[],[f.data]),{refetch:m}=f,h=Ei({directory:e,enabled:d}),g=Z.useMemo(()=>h.data??[],[h.data]),{refetch:_}=h;Z.useEffect(()=>{let e=!1;if(!o){c([]);return}return Jt(o).then(t=>{e||c(t)}).catch(()=>{e||c([])}),()=>{e=!0}},[o?.id]);let v=Z.useCallback(()=>{m(),_()},[m,_]),y=Z.useMemo(()=>new Set(p.map(e=>e.name)),[p]),b=Z.useMemo(()=>new Set(g.map(e=>e.name)),[g]),C=Z.useCallback((e,r)=>{if(n&&e.type===`command`&&e.name===`craft-goal`)return null;if(e.type===`command`){let n=ne(e.name);return n?{id:T_(r,e),ref:e,group:r,label:t(n.labelKey),icon:n.icon,submitText:n.command}:y.has(e.name)?{id:T_(r,e),ref:e,group:r,label:x(e.name),icon:K,submitText:`/${e.name}`}:null}return b.has(e.name)?{id:T_(r,e),ref:e,group:r,label:x(e.name),icon:A,submitText:`/${e.name}`}:null},[t,y,b,n]),w=Z.useMemo(()=>u.map(e=>C(e,`global`)).filter(e=>e!==null),[u,C]),T=Z.useMemo(()=>s.map(e=>C(e,`project`)).filter(e=>e!==null),[s,C]),E=Z.useMemo(()=>{let e=new Set;for(let t of u)e.add(S(t));for(let t of s)e.add(S(t));return e},[u,s]),D=Z.useMemo(()=>{let e=[];for(let r of O)n&&r.name===`craft-goal`||e.push({type:`command`,name:r.name,label:t(r.labelKey),icon:r.icon,section:`built-in`,scope:`user`});for(let t of p)t.isBuiltIn||t.source===`skill`||ne(t.name)||e.push({type:`command`,name:t.name,label:x(t.name),icon:K,section:`command`,scope:t.scope===`project`?`project`:`user`});for(let t of g)e.push({type:`skill`,name:t.name,label:x(t.name),icon:A,section:`skill`,scope:t.scope===`project`?`project`:`user`});return e.filter(e=>!E.has(`${e.type}:${e.name}`))},[t,p,g,E,n]),k=Z.useCallback(e=>{q.getState().setGlobalDraftStarters(e),U({draftStarters:e})},[]),j=Z.useCallback(e=>{c(e),o&&Ct(o,e)},[o]),M=Z.useCallback(e=>{let t={type:e.type,name:e.name};if(e.scope===`project`){if(!o||s.some(e=>l(e,t)))return;j([...s,t])}else{let e=r??re;if(e.some(e=>l(e,t)))return;k([...e,t])}},[o,s,r,j,k]),N=Z.useCallback((e,t)=>{e===`project`?j(s.filter(e=>!l(e,t))):k((r??re).filter(e=>!l(e,t)))},[s,r,j,k]),P=Z.useCallback((e,t,n)=>{let i=e===`project`?s:r??re,a=i.findIndex(n=>T_(e,n)===t),o=i.findIndex(t=>T_(e,t)===n);if(a<0||o<0||a===o)return;let c=nc([...i],a,o);e===`project`?j(c):k(c)},[s,r,j,k]);return{global:w,project:T,pinnable:D,hasProject:!!o,ensureLoaded:v,addStarter:M,removeStarter:N,reorder:P}}var O_=`__draft-starter-trash__`,k_=`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-[var(--interactive-hover)] hover:text-foreground`,A_=`max-h-7`,j_=[{key:`built-in`,headingKey:`chat.draftStarters.sectionBuiltIn`},{key:`command`,headingKey:`chat.draftStarters.sectionCommands`},{key:`skill`,headingKey:`chat.draftStarters.sectionSkills`}],M_=e=>{let t=(0,Q.c)(35),{item:n,onSubmit:r,onRemove:i,hideRemove:a}=e,{t:o}=ct(),s;t[0]===n.id?s=t[1]:(s={id:n.id},t[0]=n.id,t[1]=s);let{attributes:c,listeners:l,setNodeRef:u,transform:d,transition:f,isDragging:p}=rc(s),m;t[2]===d?m=t[3]:(m=ec.Translate.toString(d),t[2]=d,t[3]=m);let h;t[4]!==m||t[5]!==f?(h={transform:m,transition:f},t[4]=m,t[5]=f,t[6]=h):h=t[6];let g=p&&`z-10 opacity-60`,_;t[7]===g?_=t[8]:(_=Y(`group/chip relative`,g),t[7]=g,t[8]=_);let v;t[9]!==n.submitText||t[10]!==r?(v=()=>r(n.submitText),t[9]=n.submitText,t[10]=r,t[11]=v):v=t[11];let y=!a&&`pr-5`,b;t[12]===y?b=t[13]:(b=Y(`group inline-flex touch-none select-none items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground transition-colors`,`hover:bg-[var(--interactive-hover)] hover:text-foreground`,y),t[12]=y,t[13]=b);let x;t[14]===n.icon?x=t[15]:(x=(0,$.jsx)(X,{name:n.icon,className:`h-3 w-3 shrink-0 opacity-60 transition-opacity group-hover:opacity-100`}),t[14]=n.icon,t[15]=x);let S;t[16]===n.label?S=t[17]:(S=(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:n.label}),t[16]=n.label,t[17]=S);let C;t[18]!==c||t[19]!==l||t[20]!==S||t[21]!==v||t[22]!==b||t[23]!==x?(C=(0,$.jsxs)(`button`,{type:`button`,...c,...l,onClick:v,className:b,children:[x,S]}),t[18]=c,t[19]=l,t[20]=S,t[21]=v,t[22]=b,t[23]=x,t[24]=C):C=t[24];let w;t[25]!==a||t[26]!==i||t[27]!==o?(w=a?null:(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},"aria-label":o(`chat.draftStarters.remove`),title:o(`chat.draftStarters.remove`),className:`absolute right-0.5 top-1/2 hidden h-4 w-4 -translate-y-1/2 items-center justify-center rounded text-muted-foreground hover:text-foreground group-hover/chip:flex`,children:(0,$.jsx)(X,{name:`close`,className:`h-2.5 w-2.5`})}),t[25]=a,t[26]=i,t[27]=o,t[28]=w):w=t[28];let T;return t[29]!==u||t[30]!==C||t[31]!==w||t[32]!==h||t[33]!==_?(T=(0,$.jsxs)(`div`,{ref:u,style:h,className:_,children:[C,w]}),t[29]=u,t[30]=C,t[31]=w,t[32]=h,t[33]=_,t[34]=T):T=t[34],T},N_=e=>{let t=(0,Q.c)(14),{items:n,onSubmit:r,onRemove:i,hideRemove:a}=e,o;t[0]===n?o=t[1]:(o=n.map(R_),t[0]=n,t[1]=o);let s;if(t[2]!==a||t[3]!==n||t[4]!==i||t[5]!==r){let e;t[7]!==a||t[8]!==i||t[9]!==r?(e=e=>(0,$.jsx)(M_,{item:e,onSubmit:r,onRemove:()=>i(e),hideRemove:a},e.id),t[7]=a,t[8]=i,t[9]=r,t[10]=e):e=t[10],s=n.map(e),t[2]=a,t[3]=n,t[4]=i,t[5]=r,t[6]=s}else s=t[6];let c;return t[11]!==o||t[12]!==s?(c=(0,$.jsx)(ac,{items:o,strategy:tc,children:s}),t[11]=o,t[12]=s,t[13]=c):c=t[13],c},P_=()=>{let e=(0,Q.c)(13),{t}=ct(),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={id:O_},e[0]=n):n=e[0];let{setNodeRef:r,isOver:i}=Ys(n),a;e[1]===t?a=e[2]:(a=t(`chat.draftStarters.remove`),e[1]=t,e[2]=a);let o;e[3]===t?o=e[4]:(o=t(`chat.draftStarters.remove`),e[3]=t,e[4]=o);let s=i&&`text-destructive hover:text-destructive`,c;e[5]===s?c=e[6]:(c=Y(k_,s),e[5]=s,e[6]=c);let l;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(X,{name:`delete-bin`,className:`h-3.5 w-3.5`}),e[7]=l):l=e[7];let u;return e[8]!==r||e[9]!==a||e[10]!==o||e[11]!==c?(u=(0,$.jsx)(`button`,{type:`button`,ref:r,"aria-label":a,title:o,className:c,children:l}),e[8]=r,e[9]=a,e[10]=o,e[11]=c,e[12]=u):u=e[12],u},F_=e=>{let t=(0,Q.c)(21),{pinnable:n,onPick:r,className:i}=e,{t:a}=ct(),o;t[0]===i?o=t[1]:(o=Y(`min-h-0`,i),t[0]=i,t[1]=o);let s;t[2]===a?s=t[3]:(s=a(`chat.draftStarters.searchPlaceholder`),t[2]=a,t[3]=s);let c;t[4]===s?c=t[5]:(c=(0,$.jsx)(y_,{placeholder:s}),t[4]=s,t[5]=c);let l;t[6]===a?l=t[7]:(l=a(`chat.draftStarters.empty`),t[6]=a,t[7]=l);let u;t[8]===l?u=t[9]:(u=(0,$.jsx)(x_,{children:l}),t[8]=l,t[9]=u);let d;t[10]!==r||t[11]!==n||t[12]!==a?(d=j_.map(e=>{let t=n.filter(t=>t.section===e.key);return t.length===0?null:(0,$.jsx)(S_,{heading:a(e.headingKey),children:t.map(e=>(0,$.jsx)(w_,{value:`${e.section} ${e.label} ${e.name}`,onSelect:()=>r(e),children:(0,$.jsx)(`span`,{className:`truncate`,children:e.label})},`${e.type}:${e.name}`))},e.key)}),t[10]=r,t[11]=n,t[12]=a,t[13]=d):d=t[13];let f;t[14]!==u||t[15]!==d?(f=(0,$.jsxs)(b_,{children:[u,d]}),t[14]=u,t[15]=d,t[16]=f):f=t[16];let p;return t[17]!==o||t[18]!==c||t[19]!==f?(p=(0,$.jsxs)(v_,{className:o,children:[c,f]}),t[17]=o,t[18]=c,t[19]=f,t[20]=p):p=t[20],p},I_=e=>{let t=(0,Q.c)(27),{pinnable:n,onOpen:r,onAdd:i}=e,{t:a}=ct(),[o,s]=Z.useState(!1),c;t[0]===r?c=t[1]:(c=e=>{s(e),e&&r()},t[0]=r,t[1]=c);let l;t[2]===a?l=t[3]:(l=a(`chat.draftStarters.add`),t[2]=a,t[3]=l);let u;t[4]===a?u=t[5]:(u=a(`chat.draftStarters.add`),t[4]=a,t[5]=u);let d;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(X,{name:`add`,className:`h-3.5 w-3.5`}),t[6]=d):d=t[6];let f;t[7]!==l||t[8]!==u?(f=(0,$.jsx)(oa,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":l,title:u,className:k_,children:d})}),t[7]=l,t[8]=u,t[9]=f):f=t[9];let p;t[10]===a?p=t[11]:(p=a(`chat.draftStarters.add`),t[10]=a,t[11]=p);let m;t[12]===p?m=t[13]:(m=(0,$.jsx)(ea,{className:`px-4 pb-2 pt-4 text-left`,children:(0,$.jsx)(ia,{children:p})}),t[12]=p,t[13]=m);let h;t[14]===i?h=t[15]:(h=e=>{i(e),s(!1)},t[14]=i,t[15]=h);let g;t[16]!==n||t[17]!==h?(g=(0,$.jsx)(F_,{pinnable:n,onPick:h,className:`flex max-h-[60vh] flex-col`}),t[16]=n,t[17]=h,t[18]=g):g=t[18];let _;t[19]!==m||t[20]!==g?(_=(0,$.jsxs)(ra,{className:`gap-0 overflow-hidden p-0 sm:max-w-sm`,children:[m,g]}),t[19]=m,t[20]=g,t[21]=_):_=t[21];let v;return t[22]!==o||t[23]!==c||t[24]!==_||t[25]!==f?(v=(0,$.jsxs)(sa,{open:o,onOpenChange:c,children:[f,_]}),t[22]=o,t[23]=c,t[24]=_,t[25]=f,t[26]=v):v=t[26],v},L_=e=>{let t=(0,Q.c)(63),{onSubmit:n,className:r}=e,{t:i}=ct(),{global:a,project:o,pinnable:s,ensureLoaded:c,addStarter:l,removeStarter:u,reorder:d}=D_(pc()),{isMobile:f}=mo(),[p,m]=Z.useState(!1),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),y=Z.useRef(null),b;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(b={activationConstraint:{distance:8}},t[0]=b):b=t[0];let x;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(x={activationConstraint:{delay:200,tolerance:6}},t[1]=x):x=t[1];let S=$s(Ks(Zs,b),Ks(Js,x)),C;t[2]!==a||t[3]!==o?(C=e=>a.find(t=>t.id===e)??o.find(t=>t.id===e),t[2]=a,t[3]=o,t[4]=C):C=t[4];let w=C,T=a.length+o.length,E;t[5]===T?E=t[6]:(E=()=>{let e=y.current;if(!e||T===0){v(!1);return}let t=()=>{let t=e.firstElementChild?.offsetHeight??28;v(e.scrollHeight>t+4)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},t[5]=T,t[6]=E);let D;t[7]!==h||t[8]!==a||t[9]!==o||t[10]!==T?(D=[T,h,a,o],t[7]=h,t[8]=a,t[9]=o,t[10]=T,t[11]=D):D=t[11],Z.useLayoutEffect(E,D);let O,k;t[12]!==_||t[13]!==h?(O=()=>{!_&&h&&g(!1)},k=[_,h],t[12]=_,t[13]=h,t[14]=O,t[15]=k):(O=t[14],k=t[15]),Z.useEffect(O,k);let A;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(A=()=>m(!0),t[16]=A):A=t[16];let j=A,M;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(M=()=>m(!1),t[17]=M):M=t[17];let N=M,P;t[18]!==w||t[19]!==u||t[20]!==d?(P=e=>{m(!1);let{active:t,over:n}=e;if(!n)return;let r=String(t.id),i=w(r);if(!i)return;if(String(n.id)===O_){u(i.group,i.ref);return}let a=String(n.id);if(r===a)return;let o=w(a);o&&o.group===i.group&&d(i.group,r,a)},t[18]=w,t[19]=u,t[20]=d,t[21]=P):P=t[21];let F=P,I=_||h,L;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(L={droppable:{strategy:qs.Always}},t[22]=L):L=t[22];let R;t[23]===r?R=t[24]:(R=Y(`flex min-w-0 max-w-full items-start justify-center gap-0.5`,r),t[23]=r,t[24]=R);let z=!h&&A_,B=!h&&`overflow-clip`,V;t[25]!==z||t[26]!==B?(V=Y(`flex min-w-0 flex-1 flex-wrap items-center justify-center gap-x-0.5 gap-y-0.5`,z,B),t[25]=z,t[26]=B,t[27]=V):V=t[27];let H;t[28]!==a||t[29]!==f||t[30]!==n||t[31]!==u?(H=a.length>0?(0,$.jsx)(N_,{items:a,onSubmit:n,onRemove:e=>u(`global`,e.ref),hideRemove:f}):null,t[28]=a,t[29]=f,t[30]=n,t[31]=u,t[32]=H):H=t[32];let U;t[33]!==f||t[34]!==n||t[35]!==o||t[36]!==u?(U=o.length>0?(0,$.jsx)(N_,{items:o,onSubmit:n,onRemove:e=>u(`project`,e.ref),hideRemove:f}):null,t[33]=f,t[34]=n,t[35]=o,t[36]=u,t[37]=U):U=t[37];let W;t[38]!==V||t[39]!==H||t[40]!==U?(W=(0,$.jsxs)(`div`,{ref:y,className:V,children:[H,U]}),t[38]=V,t[39]=H,t[40]=U,t[41]=W):W=t[41];let ee;t[42]!==h||t[43]!==I||t[44]!==i?(ee=I?(0,$.jsx)(`button`,{type:`button`,onClick:()=>g(z_),"aria-expanded":h,"aria-label":i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),title:i(h?`chat.draftStarters.collapse`:`chat.draftStarters.expand`),className:k_,children:(0,$.jsx)(X,{name:h?`arrow-up-s`:`arrow-down-s`,className:`h-3.5 w-3.5`})}):null,t[42]=h,t[43]=I,t[44]=i,t[45]=ee):ee=t[45];let G;t[46]!==l||t[47]!==c||t[48]!==p||t[49]!==f||t[50]!==s?(G=f&&p?(0,$.jsx)(P_,{}):(0,$.jsx)(I_,{pinnable:s,onOpen:c,onAdd:l}),t[46]=l,t[47]=c,t[48]=p,t[49]=f,t[50]=s,t[51]=G):G=t[51];let K;t[52]!==ee||t[53]!==G?(K=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 self-start`,children:[ee,G]}),t[52]=ee,t[53]=G,t[54]=K):K=t[54];let te;t[55]!==R||t[56]!==W||t[57]!==K?(te=(0,$.jsxs)(`div`,{className:R,children:[W,K]}),t[55]=R,t[56]=W,t[57]=K,t[58]=te):te=t[58];let ne;return t[59]!==F||t[60]!==S||t[61]!==te?(ne=(0,$.jsx)(Qs,{sensors:S,collisionDetection:Xs,measuring:L,onDragStart:j,onDragCancel:N,onDragEnd:F,children:te}),t[59]=F,t[60]=S,t[61]=te,t[62]=ne):ne=t[62],ne};function R_(e){return e.id}function z_(e){return!e}var B_=Z.forwardRef((e,t)=>{let n=(0,Q.c)(19),r,i,a,o,s,c;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4],s=n[5],c=n[6]):({children:r,className:i,expanded:s,focusedTone:c,style:o,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o,n[5]=s,n[6]=c);let l=s!==void 0&&s,u=c===void 0?`primary`:c,d=l&&`min-h-0 flex-1`,f=u===`info`?`focus-within:ring-[var(--status-info)]`:`focus-within:ring-primary/50`,p;n[7]!==i||n[8]!==d||n[9]!==f?(p=Y(`relative flex flex-col overflow-visible border border-border/80 focus-within:ring-1`,d,f,i),n[7]=i,n[8]=d,n[9]=f,n[10]=p):p=n[10];let m;n[11]===o?m=n[12]:(m={borderRadius:`var(--radius-xl)`,backgroundColor:`var(--surface-subtle)`,...o},n[11]=o,n[12]=m);let h;return n[13]!==r||n[14]!==a||n[15]!==t||n[16]!==p||n[17]!==m?(h=(0,$.jsx)(`div`,{ref:t,className:p,style:m,...a,children:r}),n[13]=r,n[14]=a,n[15]=t,n[16]=p,n[17]=m,n[18]=h):h=n[18],h});B_.displayName=`ChatComposerSurface`;var V_=Z.forwardRef((e,t)=>{let n=(0,Q.c)(3),r;return n[0]!==e||n[1]!==t?(r=(0,$.jsx)(Pa,{ref:t,...e}),n[0]=e,n[1]=t,n[2]=r):r=n[2],r});V_.displayName=`ChatPromptTextarea`;var H_=e=>{let t=(0,Q.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:r,children:n,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===r?a=t[5]:(a=Y(`flex shrink-0 items-center gap-2 bg-transparent px-2.5 py-1.5`,r),t[4]=r,t[5]=a);let o;return t[6]!==n||t[7]!==i||t[8]!==a?(o=(0,$.jsx)(`div`,{className:a,"data-chat-input-footer":`true`,...i,children:n}),t[6]=n,t[7]=i,t[8]=a,t[9]=o):o=t[9],o},U_=(e,t)=>{typeof e==`function`?e(t):e&&(e.current=t)},W_=e=>{let t=(0,Q.c)(141),n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M,N,P,F,I,L,R,z,B;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5],s=t[6],c=t[7],l=t[8],u=t[9],d=t[10],f=t[11],p=t[12],m=t[13],h=t[14],g=t[15],_=t[16],v=t[17],y=t[18],b=t[19],x=t[20],S=t[21],C=t[22],w=t[23],T=t[24],E=t[25],D=t[26],O=t[27],k=t[28],A=t[29],j=t[30],M=t[31],N=t[32],P=t[33],F=t[34],I=t[35],L=t[36],R=t[37],z=t[38],B=t[39]):({value:B,attachments:j,disabled:M,pending:N,placeholder:T,isMobile:P,onChange:x,onSubmit:w,onStop:C,onAddFiles:b,onRemoveAttachment:S,addFilesLabel:n,removeAttachmentLabel:E,sendLabel:O,stopLabel:k,hint:f,leftControls:y,rightControls:D,footerContent:c,inputHeader:m,attachmentContent:r,highlightedContent:d,highlightRef:u,inputRef:g,textareaProps:z,textLayoutClassName:R,inputClassName:p,inputOuterClassName:h,inputStyle:v,footerClassName:s,footerStyle:l,contentClassName:o,inputSectionClassName:_,autoResize:F,disableInputWhilePending:I,children:i,className:a,expanded:L,...A}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o,t[6]=s,t[7]=c,t[8]=l,t[9]=u,t[10]=d,t[11]=f,t[12]=p,t[13]=m,t[14]=h,t[15]=g,t[16]=_,t[17]=v,t[18]=y,t[19]=b,t[20]=x,t[21]=S,t[22]=C,t[23]=w,t[24]=T,t[25]=E,t[26]=D,t[27]=O,t[28]=k,t[29]=A,t[30]=j,t[31]=M,t[32]=N,t[33]=P,t[34]=F,t[35]=I,t[36]=L,t[37]=R,t[38]=z,t[39]=B);let V=j===void 0?[]:j,H=M!==void 0&&M,U=N!==void 0&&N,W=P!==void 0&&P,ee=F===void 0||F,G=I===void 0||I,K=L!==void 0&&L,te=Z.useRef(null),ne=Z.useRef(null),re;t[40]!==ee||t[41]!==K||t[42]!==z?.fillContainer?(re=()=>{if(!ee||K||z?.fillContainer)return;let e=te.current;if(!e)return;e.style.height=`auto`;let t=Number.parseFloat(window.getComputedStyle(e).maxHeight),n=Number.isFinite(t)?Math.min(e.scrollHeight,t):e.scrollHeight;e.style.height=`${n}px`,e.style.overflowY=Number.isFinite(t)&&e.scrollHeight>t?`auto`:`hidden`},t[40]=ee,t[41]=K,t[42]=z?.fillContainer,t[43]=re):re=t[43];let ie=z?.fillContainer,ae;t[44]!==ee||t[45]!==K||t[46]!==ie||t[47]!==B?(ae=[ee,K,ie,B],t[44]=ee,t[45]=K,t[46]=ie,t[47]=B,t[48]=ae):ae=t[48],Z.useLayoutEffect(re,ae);let oe;t[49]!==G||t[50]!==H||t[51]!==w||t[52]!==U||t[53]!==z?(oe=e=>{z?.onKeyDown?.(e),!(e.defaultPrevented||Ig(e))&&e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),!H&&(!U||!G)&&w())},t[49]=G,t[50]=H,t[51]=w,t[52]=U,t[53]=z,t[54]=oe):oe=t[54];let se=oe,ce;t[55]===b?ce=t[56]:(ce=e=>{b?.(e.target.files),e.target.value=``},t[55]=b,t[56]=ce);let le=ce,ue=B.trim().length>0||V.length>0,de=V.filter(G_),fe;t[57]!==n||t[58]!==H||t[59]!==le||t[60]!==b||t[61]!==U?(fe=b?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{ref:ne,type:`file`,accept:`image/*`,multiple:!0,className:`hidden`,onChange:le}),(0,$.jsx)(`button`,{type:`button`,className:`flex size-8 shrink-0 items-center justify-center rounded-md text-foreground outline-none hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-40`,onClick:()=>ne.current?.click(),disabled:H||U,"aria-label":n,children:(0,$.jsx)(X,{name:`attachment-2`,className:`size-[18px]`})})]}):null,t[57]=n,t[58]=H,t[59]=le,t[60]=b,t[61]=U,t[62]=fe):fe=t[62];let pe=fe,me=!H&&!U&&ue,he;t[63]!==H||t[64]!==ue||t[65]!==W||t[66]!==C||t[67]!==U||t[68]!==O||t[69]!==me||t[70]!==k?(he=U&&C?(0,$.jsx)(`button`,{type:`button`,"data-composer-stop":`true`,className:`flex size-8 shrink-0 items-center justify-center rounded-full outline-none hover:opacity-80`,onClick:C,"aria-label":k,children:(0,$.jsx)(Rg,{className:W?`size-6`:`size-full`})}):(0,$.jsx)(`button`,{type:`submit`,"data-composer-send":`true`,"data-composer-circle":me?`true`:void 0,className:Y(`flex size-8 shrink-0 items-center justify-center outline-none`,me?`rounded-full hover:opacity-80`:`rounded-md text-primary hover:bg-[var(--interactive-hover)] disabled:cursor-not-allowed disabled:opacity-30`),disabled:H||U||!ue,"aria-label":O,children:me?(0,$.jsx)(zg,{className:W?`size-6`:`size-full`}):(0,$.jsx)(X,{name:U?`loader-4`:`send-plane-2`,className:Y(`size-4`,U&&`animate-spin`)})}),t[63]=H,t[64]=ue,t[65]=W,t[66]=C,t[67]=U,t[68]=O,t[69]=me,t[70]=k,t[71]=he):he=t[71];let ge=he,_e=B_,ve=K&&`flex-1`,ye;t[72]!==o||t[73]!==ve?(ye=Y(`relative flex min-h-0 flex-col`,ve,o),t[72]=o,t[73]=ve,t[74]=ye):ye=t[74];let be=K&&`flex min-h-0 flex-1 flex-col`,xe;t[75]!==_||t[76]!==be?(xe=Y(`overflow-hidden`,be,_),t[75]=_,t[76]=be,t[77]=xe):xe=t[77];let Se=de.length>0?(0,$.jsx)(`div`,{className:`flex gap-2 overflow-x-auto px-3 pt-3`,"data-chat-prompt-attachments":`true`,children:de.map(e=>(0,$.jsxs)(`div`,{className:`group relative shrink-0`,children:[(0,$.jsx)(`img`,{src:e.url,alt:e.name,className:`size-16 rounded-lg border border-border object-cover`}),S?(0,$.jsx)(`button`,{type:`button`,className:`absolute -right-1 -top-1 flex size-6 items-center justify-center rounded-full border border-border bg-[var(--surface-elevated)] shadow-sm hover:bg-[var(--interactive-hover)]`,onClick:()=>S(e.id),"aria-label":E,children:(0,$.jsx)(X,{name:`close`,className:`size-3`})}):null]},e.id))}):null,Ce=K&&`flex min-h-0 flex-1 flex-col`,we;t[78]===Ce?we=t[79]:(we=Y(`relative overflow-hidden`,Ce),t[78]=Ce,t[79]=we);let Te;t[80]!==u||t[81]!==d||t[82]!==p||t[83]!==R?(Te=d?(0,$.jsx)(`div`,{ref:u,"aria-hidden":!0,"data-composer-highlight":`true`,className:Y(`pointer-events-none absolute inset-0 z-0 rounded-b-none`,R,p),children:d}):null,t[80]=u,t[81]=d,t[82]=p,t[83]=R,t[84]=Te):Te=t[84];let Ee;t[85]===g?Ee=t[86]:(Ee=e=>{te.current=e,U_(g,e)},t[85]=g,t[86]=Ee);let De;t[87]===x?De=t[88]:(De=e=>x(e.target.value,e),t[87]=x,t[88]=De);let Oe=H||U&&G,ke=W?`send`:z?.enterKeyHint,Ae=K&&`min-h-0 flex-1`,je;t[89]!==h||t[90]!==Ae?(je=Y(`ring-0 bg-transparent shadow-none hover:bg-transparent focus-within:ring-0`,Ae,h),t[89]=h,t[90]=Ae,t[91]=je):je=t[91];let Me=d&&`text-transparent caret-[var(--surface-foreground)]`,Ne;t[92]!==p||t[93]!==Me||t[94]!==R?(Ne=Y(`relative z-10 min-h-[52px] max-h-40 resize-none overflow-y-hidden appearance-none rounded-b-none border-0 bg-transparent px-3 pb-2 pt-4 typography-markdown hover:border-transparent md:typography-ui-label`,R,p,Me),t[92]=p,t[93]=Me,t[94]=R,t[95]=Ne):Ne=t[95];let Pe=z?.rows??1,Fe;t[96]!==se||t[97]!==v||t[98]!==T||t[99]!==Ee||t[100]!==De||t[101]!==Oe||t[102]!==ke||t[103]!==je||t[104]!==Ne||t[105]!==Pe||t[106]!==z||t[107]!==B?(Fe=(0,$.jsx)(V_,{...z,simple:!0,ref:Ee,"data-chat-input":`true`,value:B,onChange:De,onKeyDown:se,disabled:Oe,placeholder:T,enterKeyHint:ke,outerClassName:je,className:Ne,style:v,rows:Pe}),t[96]=se,t[97]=v,t[98]=T,t[99]=Ee,t[100]=De,t[101]=Oe,t[102]=ke,t[103]=je,t[104]=Ne,t[105]=Pe,t[106]=z,t[107]=B,t[108]=Fe):Fe=t[108];let Ie;t[109]!==we||t[110]!==Te||t[111]!==Fe?(Ie=(0,$.jsxs)(`div`,{className:we,"data-composer-input-shell":`true`,children:[Te,Fe]}),t[109]=we,t[110]=Te,t[111]=Fe,t[112]=Ie):Ie=t[112];let Le;t[113]!==r||t[114]!==m||t[115]!==xe||t[116]!==Se||t[117]!==Ie?(Le=(0,$.jsxs)(`div`,{className:xe,children:[m,r,Se,Ie]}),t[113]=r,t[114]=m,t[115]=xe,t[116]=Se,t[117]=Ie,t[118]=Le):Le=t[118];let Re;t[119]!==pe||t[120]!==ge||t[121]!==c||t[122]!==f||t[123]!==y||t[124]!==D?(Re=c??(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:y??pe}),f?(0,$.jsx)(`div`,{className:`min-w-0 flex-1 truncate typography-micro text-muted-foreground`,children:f}):(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,children:D??ge})]}),t[119]=pe,t[120]=ge,t[121]=c,t[122]=f,t[123]=y,t[124]=D,t[125]=Re):Re=t[125];let ze;t[126]!==s||t[127]!==l||t[128]!==Re?(ze=(0,$.jsx)(H_,{className:s,style:l,children:Re}),t[126]=s,t[127]=l,t[128]=Re,t[129]=ze):ze=t[129];let q;t[130]!==ye||t[131]!==Le||t[132]!==ze?(q=(0,$.jsxs)(`div`,{"data-composer-content":`true`,className:ye,children:[Le,ze]}),t[130]=ye,t[131]=Le,t[132]=ze,t[133]=q):q=t[133];let Be;return t[134]!==_e||t[135]!==i||t[136]!==a||t[137]!==K||t[138]!==A||t[139]!==q?(Be=(0,$.jsxs)(_e,{className:a,expanded:K,...A,children:[i,q]}),t[134]=_e,t[135]=i,t[136]=a,t[137]=K,t[138]=A,t[139]=q,t[140]=Be):Be=t[140],Be};function G_(e){return e.mime.startsWith(`image/`)}var K_=e=>e.trim().replace(/\s+/g,`-`).replace(/[^A-Za-z0-9._/-]/g,`-`).replace(/-+/g,`-`).replace(/\/{2,}/g,`/`).replace(/\/-+/g,`/`).replace(/-+\//g,`/`).replace(/^[-/]+/,``).replace(/[-/]+$/,``),q_=({currentBranch:e,localBranches:t,remoteBranches:n,branchInfo:r,onCheckout:i,onCreate:a,remotes:o=[],disabled:s=!1,iconOnly:c=!1,trigger:l,triggerLabel:u,contentAlign:d,hideTooltip:f=!1,projectRootOption:p=null,worktreeOptions:m=[],selectedDirectory:h=null,onSelectDirectory:g,onCreateWorktree:_,worktreesLabel:v,worktreeNewLabel:y,projectRootLabel:b,onOpenChange:x,open:S,presentation:C=`dropdown`})=>{let{t:w}=ct(),[T,E]=Z.useState(!1),[D,O]=Z.useState(``),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),[N,P]=Z.useState(``),[F,I]=Z.useState(!1),L=Z.useRef(null),R=Z.useId(),z=S??T,B=e=>{S===void 0&&E(e),x?.(e)},V=Z.useCallback(e=>{e.stopPropagation()},[]),H=o.length>1,U=!!(g||_),W=Z.useMemo(()=>K_(N),[N]),ee=Z.useMemo(()=>{let e=D.trim();return e?bi(t,e,e=>e).map(e=>e.item):t},[D,t]),G=Z.useMemo(()=>{let e=D.trim();return e?bi(n,e,e=>e).map(e=>e.item):n},[D,n]),K=Z.useMemo(()=>{let e=D.trim();return e?bi(m,e,e=>e.label).map(e=>e.item):m},[D,m]),te=Z.useMemo(()=>{if(!p)return!1;let e=D.trim();return!e||bi([p],e,e=>[e.label,b??``]).length>0},[b,p,D]),ne=t=>{if(t===e){B(!1);return}i(t),B(!1),O(``)},re=e=>{g?.(e),B(!1),O(``)},ie=()=>{A(!0),setTimeout(()=>L.current?.focus(),50)},ae=async()=>{if(!(!W||F)){if(H){M(!0);return}I(!0);try{await a(W,o[0]),P(``),A(!1),B(!1)}finally{I(!1)}}},oe=async e=>{if(!(!W||F)){I(!0);try{await a(W,e),P(``),A(!1),M(!1),B(!1)}finally{I(!1)}}},se=()=>{M(!1)},ce=()=>{P(``),A(!1),M(!1)};Z.useEffect(()=>{z||(O(``),A(!1),M(!1),P(``))},[z]);let le=u||e||w(`gitView.branch.detachedHead`),ue=d??(c?`end`:`start`),de=v??w(`chat.chatInput.worktrees`),fe=y??w(`chat.chatInput.worktreeNew`),pe=b??w(`chat.chatInput.projectRoot`),me=c?(0,$.jsx)(`button`,{type:`button`,className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50`,disabled:s,"aria-label":le,children:(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5`})}):(0,$.jsxs)(ua,{variant:`ghost`,size:`xs`,className:`h-6 min-w-0 max-w-full justify-start gap-1 px-0 hover:bg-transparent`,disabled:s,"aria-label":le,children:[(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5 text-primary`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate typography-ui-label font-semibold text-left text-foreground`,children:le}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`size-3 shrink-0 text-muted-foreground`})]}),he=(0,$.jsx)(fo,{asChild:!0,disabled:s,children:l??me}),ge=(0,$.jsxs)(v_,{className:`h-full min-h-0`,children:[(0,$.jsx)(`div`,{"data-mobile-sheet-no-dismiss":C===`mobile-sheet`?``:void 0,children:(0,$.jsx)(y_,{placeholder:w(`gitView.branch.searchPlaceholder`),value:D,onValueChange:O,onKeyDown:V})}),(0,$.jsxs)(b_,{scrollbarClassName:`overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero`,disableHorizontal:!0,children:[(0,$.jsx)(x_,{children:w(`gitView.branch.empty`)}),(0,$.jsx)(S_,{children:j?(0,$.jsxs)(`div`,{className:`px-2 py-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:se,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,$.jsx)(X,{name:`arrow-left`,className:`size-4`})}),(0,$.jsxs)(`span`,{className:`typography-meta text-muted-foreground`,children:[w(`gitView.branch.pushToPrefix`),` `,(0,$.jsx)(`span`,{className:`text-foreground font-medium`,children:W}),` `,w(`gitView.branch.pushToSuffix`)]})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-1`,children:o.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>oe(e),disabled:F,className:`flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label text-foreground`,children:[F?(0,$.jsx)(X,{name:`loader-4`,className:`inline size-3 mr-1.5 animate-spin`}):null,e.name]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground truncate max-w-full`,children:e.pushUrl})]},e.name))})]}):k?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-lg`,children:[(0,$.jsx)(`input`,{ref:L,placeholder:w(`gitView.branch.newBranchPlaceholder`),value:N,onChange:e=>P(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{V(e),e.key===`Enter`?(e.preventDefault(),ae()):e.key===`Escape`&&(e.preventDefault(),ce())},className:`flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground`}),(0,$.jsx)(`button`,{type:`button`,onClick:ae,disabled:!W||F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:F?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`add`,className:`size-4`})}),(0,$.jsx)(`button`,{type:`button`,onClick:ce,disabled:F,className:`shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50`,children:(0,$.jsx)(X,{name:`close`,className:`size-4`})})]}):(0,$.jsxs)(w_,{onSelect:ie,children:[(0,$.jsx)(X,{name:`add`,className:`size-4`}),(0,$.jsx)(`span`,{children:w(`gitView.branch.create`)})]})}),(0,$.jsx)(C_,{}),(0,$.jsxs)(S_,{heading:w(`gitView.branch.localBranches`),children:[ee.map(t=>(0,$.jsxs)(w_,{onSelect:()=>ne(t),children:[(0,$.jsxs)(`span`,{className:`flex flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:t}),(r?.[t]?.ahead||r?.[t]?.behind)&&(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[r[t].ahead||0,` ahead ·`,` `,r[t].behind||0,` behind`]})]}),e===t&&(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)})]},`local-${t}`)),ee.length===0&&(0,$.jsx)(w_,{disabled:!0,className:`justify-center`,children:(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:w(`gitView.branch.noLocalBranches`)})})]}),(0,$.jsx)(C_,{}),(0,$.jsxs)(S_,{heading:w(`gitView.branch.remoteBranches`),children:[G.map(e=>(0,$.jsx)(w_,{onSelect:()=>ne(e),children:(0,$.jsx)(`span`,{className:`typography-ui-label text-foreground`,children:e})},`remote-${e}`)),G.length===0&&(0,$.jsx)(w_,{disabled:!0,className:`justify-center`,children:(0,$.jsx)(`span`,{className:`typography-meta text-muted-foreground`,children:w(`gitView.branch.noRemoteBranches`)})})]}),U?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(C_,{}),(0,$.jsxs)(S_,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground typography-meta`,children:de}),_?(0,$.jsx)(`button`,{type:`button`,className:`cursor-pointer text-muted-foreground typography-meta hover:text-foreground`,onPointerDown:e=>{e.stopPropagation()},onClick:e=>{e.preventDefault(),e.stopPropagation(),B(!1),_()},children:fe}):null]}),p&&te?(0,$.jsxs)(w_,{onSelect:()=>re(p.value),children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:pe}),(0,$.jsx)(`span`,{className:`truncate typography-ui-label text-foreground`,children:p.label})]}),h===p.value?(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)}):null]}):null,K.map(e=>(0,$.jsxs)(w_,{onSelect:()=>re(e.value),children:[(0,$.jsxs)(`span`,{className:`truncate typography-ui-label text-foreground`,children:[e.pending?`⏳ `:``,e.label]}),h===e.value?(0,$.jsx)(`span`,{className:`typography-micro text-primary`,children:w(`gitView.branch.currentBadge`)}):null]},`worktree-${e.value}`))]})]}):null]})]});if(C===`mobile-sheet`){let e=Z.cloneElement(l??me,{onClick:()=>B(!0),"data-popup-open":z?``:void 0});return(0,$.jsxs)($.Fragment,{children:[e,(0,$.jsx)(_a,{id:`mobile-draft-branch-picker-sheet-${R}`,open:z,onOpenChange:B,ariaLabel:w(`gitView.branch.selectBranch`),closeAriaLabel:w(`mobile.surface.closeAria`),resizeAriaLabel:w(`mobile.sessions.sheet.resizeAria`),children:ge})]})}return(0,$.jsxs)($a,{open:z,onOpenChange:B,children:[f||l?he:(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:he}),(0,$.jsx)(Ua,{sideOffset:8,children:c?le:w(`gitView.branch.currentBranchTooltip`)})]}),(0,$.jsx)(uo,{align:ue,className:`w-72 p-0 max-h-[60vh] flex flex-col`,children:ge})]})};function J_(e){let{localBranches:t,remoteBranches:n,query:r}=e,i=r.trim();if(!i)return{matching:[],otherLocal:t,otherRemote:n};let a=bi(t,i,e=>e),o=bi(n,i,e=>e),s=new Set(a.map(e=>e.item)),c=new Set(o.map(e=>e.item));return{matching:[...a.map(e=>({label:e.item,value:e.item,source:`local`,score:e.score})),...o.map(e=>({label:e.item,value:`remotes/${e.item}`,source:`remote`,score:e.score}))].sort((e,t)=>e.score===t.score?e.source===t.source?e.label.length===t.label.length?e.label.localeCompare(t.label,void 0,{sensitivity:`accent`}):e.label.length-t.label.length:e.source===`local`?-1:1:e.score-t.score).map(({label:e,value:t,source:n})=>({label:e,value:t,source:n})),otherLocal:t.filter(e=>!s.has(e)),otherRemote:n.filter(e=>!c.has(e))}}function Y_(e,t){return`${e}\0${t}`}function X_({open:e,onOpenChange:t,onSelect:n}){let{t:r}=ct(),i=q(e=>e.isMobile),{github:a}=ko(),o=to(),s=o.data??null,c=o.isFetched,l=q(e=>e.setSettingsDialogOpen),u=q(e=>e.setSettingsPage),d=gr(e=>e.getActiveProject()),f=d?.id??null,p=d?.path??null,m=Z.useMemo(()=>p&&f?{id:f,path:p}:null,[f,p]),[h,g]=Z.useState(`issues`),[_,v]=Z.useState(``),[y,b]=Z.useState([]),[x,S]=Z.useState([]),[C,w]=Z.useState(!1),[T,E]=Z.useState(!1),[D,O]=Z.useState(null),[k,A]=Z.useState(null),[j,M]=Z.useState(null),[N,P]=Z.useState(!1),[F,I]=Z.useState(new Map),[L,R]=Z.useState(1),[z,B]=Z.useState(!1),V=Z.useRef(0),H=Ho(_,350),U=J(async e=>{if(!(!p||!a)&&!(c&&s?.connected===!1)){w(!0),O(null),R(1),B(!1);try{if(h===`issues`&&a.issuesList){let t=await a.issuesList(p,{page:1,query:e});t.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),b([])):(b(t.issues??[]),R(t.page??1),B(!!t.hasMore))}else if(h===`prs`&&a.prsList){let t=await a.prsList(p,{page:1,query:e});t.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),S([])):(S(t.prs??[]),R(t.page??1),B(!!t.hasMore))}}catch(e){O(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}finally{w(!1)}}});Z.useEffect(()=>{if(!e||!p||c&&s?.connected===!1||!a)return;if(!H.trim()){U();return}let t=new AbortController;w(!0),O(null),R(1),B(!1);let n=h===`issues`&&a.issuesList?a.issuesList(p,{page:1,query:H.trim()}):h===`prs`&&a.prsList?a.prsList(p,{page:1,query:H.trim()}):null;if(!n){w(!1);return}return n.then(e=>{t.signal.aborted||(`issues`in e?e.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),b([])):(b(e.issues??[]),R(e.page??1),B(!!e.hasMore)):`prs`in e&&(e.connected===!1?(O(r(`session.githubIntegration.error.notConnected`)),S([])):(S(e.prs??[]),R(e.page??1),B(!!e.hasMore))))}).catch(e=>{t.signal.aborted||O(e instanceof Error?e.message:r(`session.githubIntegration.error.loadDataFailed`))}).finally(()=>{t.signal.aborted||w(!1)}),()=>t.abort()},[e,p,a,c,s,h,H,U,r]);let W=J(async()=>{if(!(!p||!a)&&!(C||T)&&z){E(!0);try{let e=L+1;if(h===`issues`&&a.issuesList){let t=H.trim()?await a.issuesList(p,{page:e,query:H.trim()}):await a.issuesList(p,{page:e});t.connected!==!1&&(b(e=>[...e,...t.issues??[]]),R(t.page??e),B(!!t.hasMore))}else if(h===`prs`&&a.prsList){let t=H.trim()?await a.prsList(p,{page:e,query:H.trim()}):await a.prsList(p,{page:e});t.connected!==!1&&(S(e=>[...e,...t.prs??[]]),R(t.page??e),B(!!t.hasMore))}}catch{}finally{E(!1)}}});Z.useEffect(()=>{if(!e){g(`issues`),v(``),b([]),S([]),A(null),M(null),P(!1),O(null),I(new Map),R(1),B(!1);return}U()},[e,U]),Z.useEffect(()=>{V.current+=1,I(new Map)},[p,m]);let ee=J(async e=>{if(!m||!e)return;let t=Y_(m.path,e);if(F.has(t))return;let n=V.current;try{let i=await Ea(m,{mode:`new`,branchName:e,worktreeName:e});if(n!==V.current)return;let a=i.errors.find(e=>e.code===`branch_in_use`);I(e=>new Map(e).set(t,{isValid:!a,error:a?r(a.code===`branch_exists`?`session.githubIntegration.validation.branchAlreadyExists`:`session.githubIntegration.validation.branchAlreadyCheckedOut`):null}))}catch{if(n!==V.current)return;I(e=>new Map(e).set(t,{isValid:!1,error:r(`session.githubIntegration.validation.failed`)}))}});Z.useEffect(()=>{!e||h!==`prs`||x.forEach(e=>{e.head&&ee(e.head)})},[e,h,x,p,m,ee]);let G=c&&s?.connected===!0,K=()=>{u(`github`),l(!0)},te=e=>{A(e),M(null)},ne=e=>{M(e),A(null)},re=()=>{k?n({type:`issue`,item:k}):j&&n({type:`pr`,item:j,includeDiff:N}),t(!1)},ie=()=>{A(null),M(null),P(!1)},ae=k||(j?.head&&p?F.get(Y_(p,j.head))?.isValid!==!1:!1),oe=e=>!e.head||(p?F.get(Y_(p,e.head)):void 0)?.isValid===!1,se=(0,$.jsx)($.Fragment,{children:G?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative mt-2`,children:[(0,$.jsx)(X,{name:`search`,className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(Va,{value:_,onChange:e=>v(e.target.value),placeholder:r(h===`issues`?`session.githubIntegration.search.issuesPlaceholder`:`session.githubIntegration.search.prsPlaceholder`),className:`h-8 pl-9`})]}),(0,$.jsx)(`div`,{className:`mt-2 h-[300px] overflow-hidden`,children:(0,$.jsxs)(`div`,{className:`h-full overflow-y-auto`,children:[C&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-5 w-5 animate-spin text-muted-foreground`})}),D&&(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive`,children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`typography-small`,children:D})]})}),!C&&!D&&h===`issues`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[y.length>0?y.map(e=>(0,$.jsx)(`button`,{onClick:()=>te(e),className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,k?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-2`,children:e.title}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info mt-0.5 inline-block`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noIssuesFound`)}),z&&!T&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(ua,{variant:`ghost`,size:`sm`,onClick:()=>void W(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),T&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]}),!C&&!D&&h===`prs`&&(0,$.jsxs)(`div`,{className:`space-y-0.5 min-h-full`,children:[x.length>0?x.map(e=>{let t=oe(e),n=e.head&&p?F.get(Y_(p,e.head)):void 0;return(0,$.jsx)(`button`,{onClick:()=>!t&&ne(e),disabled:t,className:Y(`w-full text-left px-2 py-1.5 rounded transition-colors`,j?.number===e.number?`bg-interactive-selection text-interactive-selection-foreground`:t?`opacity-50 cursor-not-allowed`:`hover:bg-interactive-hover`),children:(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-muted-foreground shrink-0 typography-micro`,children:[`#`,e.number]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`typography-small line-clamp-1`,children:e.title}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[e.head,` → `,e.base]}),e.sourceRepo?.source===`upstream`?(0,$.jsxs)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info`,children:[e.sourceRepo.owner,`/`,e.sourceRepo.repo]}):null,t&&n?.error&&(0,$.jsx)(`span`,{className:`typography-micro text-destructive`,children:n.error})]})]})]})},`${e.sourceRepo?.owner??``}-${e.sourceRepo?.repo??``}-${e.number}`)}):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground`,children:r(`session.githubIntegration.empty.noPullRequestsFound`)}),z&&!T&&(0,$.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,$.jsx)(ua,{variant:`ghost`,size:`sm`,onClick:()=>void W(),className:`h-7 text-xs`,children:r(`session.githubIntegration.actions.loadMore`)})}),T&&(0,$.jsx)(`div`,{className:`flex items-center justify-center py-2`,children:(0,$.jsx)(X,{name:`loader-4`,className:`h-4 w-4 animate-spin text-muted-foreground`})})]})]})})]}):(0,$.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center p-8 gap-4`,children:[(0,$.jsx)(X,{name:`github`,className:`h-12 w-12 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`p`,{className:`typography-ui-label text-foreground`,children:r(`session.githubIntegration.connect.title`)}),(0,$.jsx)(`p`,{className:`typography-small text-muted-foreground mt-1`,children:r(`session.githubIntegration.connect.description`)})]}),(0,$.jsx)(ua,{onClick:K,size:`sm`,children:r(`session.githubIntegration.connect.action`)})]})}),ce=(0,$.jsxs)(`div`,{className:Y(`w-full`,i?`flex flex-col gap-2`:`flex flex-row items-center`),children:[(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-4`,i?`w-full justify-center order-1`:`flex-1`),children:[!i&&(k||j)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate max-w-[150px]`,children:k?r(`session.githubIntegration.selected.issueNumber`,{number:k.number}):r(`session.githubIntegration.selected.prNumber`,{number:j?.number??``})}),(0,$.jsx)(`button`,{onClick:ie,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),h===`prs`&&j&&(0,$.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer h-8`,children:[(0,$.jsx)(Da,{checked:N,onChange:e=>P(e),ariaLabel:r(`session.githubIntegration.includeDiffAria`)}),(0,$.jsx)(`span`,{className:`typography-small text-foreground`,children:r(`session.githubIntegration.includeDiff`)})]})]}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,i?`w-full order-2`:`justify-end`),children:[(0,$.jsx)(ua,{variant:`outline`,size:`sm`,onClick:()=>t(!1),className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.cancel`)}),(0,$.jsx)(ua,{size:`sm`,onClick:re,disabled:!ae,className:Y(i&&`flex-1`),children:r(`session.githubIntegration.actions.select`)})]})]});return(0,$.jsx)($.Fragment,{children:i?(0,$.jsx)(sm,{open:e,title:r(`session.githubIntegration.title`),onClose:()=>t(!1),footer:G?ce:void 0,renderHeader:e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 px-3 py-2 border-b border-border/40`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h2`,{className:`typography-ui-label font-semibold text-foreground`,children:r(`session.githubIntegration.title`)}),e]}),(0,$.jsx)(`div`,{className:`w-full`,children:(0,$.jsx)(Xc,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>{g(e),v(``)},variant:`active-pill`,layoutMode:`fit`})}),(k||j)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),(0,$.jsx)(`span`,{className:`typography-small truncate flex-1`,children:k?r(`session.githubIntegration.selected.issueNumber`,{number:k.number}):r(`session.githubIntegration.selected.prNumber`,{number:j?.number??``})}),(0,$.jsx)(`button`,{onClick:ie,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]})]}),children:se}):(0,$.jsx)(sa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ra,{className:`max-w-2xl max-h-[70vh] flex flex-col`,children:[(0,$.jsx)(ea,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(ia,{className:`flex items-center gap-2 shrink-0`,children:[(0,$.jsx)(X,{name:`github`,className:`h-5 w-5`}),r(`session.githubIntegration.title`)]}),(0,$.jsx)(`div`,{className:`w-[220px]`,children:(0,$.jsx)(Xc,{items:[{id:`issues`,label:r(`session.githubIntegration.tabs.issues`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`prs`,label:r(`session.githubIntegration.tabs.pullRequests`),icon:(0,$.jsx)(X,{name:`git-pull-request`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>{g(e),v(``)},variant:`active-pill`,layoutMode:`fit`})})]})}),se,(0,$.jsx)(ta,{className:`mt-1`,children:ce})]})})})}var Z_=(e,t,n)=>{let r=n??t;return r?e.find(e=>e.id===r)??null:null},Q_=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``),$_=e=>e.trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/\s+/g,`-`).replace(/^\/+|\/+$/g,``).split(`/`).join(`-`).replace(/[^A-Za-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``).slice(0,80),ev=e=>String(e||``).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``)||`pr-head`,tv=(e,t,n)=>{let r=Q_(e.head||``);if(!r)throw Error(`PR head branch is missing`);if(t.includes(r))return{existingBranch:r,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:r};let i=n.find(e=>{let t=e.indexOf(`/`);return t<=0||t>=e.length-1?!1:e.slice(t+1)===r});if(i){let e=i.indexOf(`/`),t=i.slice(0,e);return{existingBranch:`remotes/${i}`,setUpstream:!0,upstreamRemote:t,upstreamBranch:r,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${t}/${r}`}}let a=String(e.headLabel||``).split(`:`)[0]?.trim(),o=`pr-${ev(e.headRepo?.owner||a||`pr-head`)}`,s=e.headRepo?.sshUrl||e.headRepo?.cloneUrl||``;if(!s)throw Error(`PR head repository URL is unavailable`);return{existingBranch:`remotes/${o}/${r}`,setUpstream:!0,upstreamRemote:o,upstreamBranch:r,ensureRemoteName:o,ensureRemoteUrl:s,sourceLabel:`${o}/${r}`}},nv=e=>{let t={repo:e.repo??null,issue:e.issue,comments:e.comments};return`GitHub issue context (JSON)\n${JSON.stringify(t,null,2)}`},rv=e=>`GitHub pull request context (JSON)\n${JSON.stringify(e,null,2)}`;function iv({open:e,onOpenChange:t,onWorktreeCreated:n,projectId:r}){let{t:i}=ct(),{github:a,git:o}=ko(),s=q(e=>e.isMobile),c=Z.useId(),l=to(),u=l.data??null,d=l.isFetched,f=gr(e=>Z_(e.projects,e.activeProjectId,r)),p=f?.path??null,m=Z.useMemo(()=>p&&f?{id:f.id,path:p}:null,[f,p]),[h,g]=Z.useState(`new-branch`),[_,v]=Z.useState({branchName:``,worktreeName:``,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1}),[y,b]=Z.useState({selectedBranch:``,worktreeName:``}),x=os(p),S=rs(p),C=Xo(e=>e.fetchBranches),w=Z.useMemo(()=>x?.all?x.all.filter(e=>!e.startsWith(`remotes/`)).sort():[],[x]),T=Z.useMemo(()=>x?.all?x.all.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort():[],[x]),E=ri(e=>e.availableWorktreesByProject),D=Z.useMemo(()=>{if(!p)return new Set;let e=E.get(p)??[];return new Set(e.map(e=>e.name))},[E,p]),O=Z.useCallback((e=10)=>{for(let t=0;t<e;t++){let e=Zg();if(!D.has(e))return e}return`${Zg()}-${Date.now().toString(36).slice(-4)}`},[D]),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),[N,P]=Z.useState(!1),[F,I]=Z.useState(!1),[L,R]=Z.useState(!1),[z,B]=Z.useState(``),[V,H]=Z.useState(``),U=Z.useRef(null),W=Z.useRef(null),ee=Z.useRef(null),G=Z.useRef(null),K=Z.useCallback(e=>{e.stopPropagation()},[]),te=Z.useCallback(e=>{let t=e;for(;t&&t!==document.body;){let{overflowY:e}=window.getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t;t=t.parentElement}return null},[]),ne=Z.useCallback(e=>{e&&(e.scrollTop=0)},[]),re=Z.useCallback(e=>{let t=e.current?.querySelector(`[data-slot="command-list"]`)??null;ne(t)},[ne]),ie=Z.useCallback(e=>{let t=te(e.current);ne(t)},[te,ne]),ae=Z.useMemo(()=>J_({localBranches:w,remoteBranches:T,query:z}),[w,T,z]),oe=Z.useMemo(()=>J_({localBranches:w,remoteBranches:T,query:V}),[w,T,V]),se=z.trim().length>0,ce=V.trim().length>0,le=ae.matching.length>0,ue=oe.matching.length>0,de=!!(p&&o),fe=Z.useCallback(()=>{!p||!o||C(p,o)},[p,o,C]);Z.useEffect(()=>{!e||!p||!o||x?.all||C(p,o)},[e,p,o,x?.all,C]),Z.useEffect(()=>{!j&&!F&&B(``)},[j,F]),Z.useEffect(()=>{!N&&!L&&H(``)},[N,L]),Z.useEffect(()=>{j&&re(U),F&&ie(ee)},[j,F,z,re,ie]),Z.useEffect(()=>{N&&re(W),L&&ie(G)},[N,L,V,re,ie]);let[pe,me]=Z.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[he,ge]=Z.useState(!1),[_e,ve]=Z.useState(null),ye=Z.useCallback(()=>{let e=Ai.getState(),t=e.getVisibleAgents();if(e.settingsDefaultAgent){let n=t.find(t=>t.name===e.settingsDefaultAgent);if(n)return n.name}return t.find(e=>e.name===`build`)?.name||t[0]?.name},[]),be=Z.useCallback(()=>{let e=Ai.getState(),t=e.settingsDefaultModel;if(!t)return null;let n=It(t);if(!n)return null;let{providerId:r,modelId:i}=n;return e.getModelMetadata(r,i)?{providerID:r,modelID:i}:null},[]),xe=Z.useCallback((e,t)=>{let n=Ai.getState(),r=n.settingsDefaultVariant,i=n.currentProviderId===e&&n.currentModelId===t?n.currentVariant:void 0,a=n.providers.find(t=>t.id===e)?.models.find(e=>e.id===t)?.variants;if(!a)return r||i||void 0;if(r&&Object.prototype.hasOwnProperty.call(a,r))return r;if(i&&Object.prototype.hasOwnProperty.call(a,i))return i},[]),Se=Z.useCallback(async e=>{if(!p||!a)return;let t=Ai.getState(),n=Zi.getState().lastUsedProvider,r=be(),o=r?.providerID||t.currentProviderId||n?.providerID,s=r?.modelID||t.currentModelId||n?.modelID,c=ye()||t.currentAgentName||void 0;if(!o||!s){Br.error(i(`session.newWorktree.error.noModelSelected`));return}let l=xe(o,s);if(e.issue){if(!a.issueGet||!a.issueComments)return;let t=await a.issueGet(p,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(t.connected===!1||!t.repo||!t.issue)throw Error(`Failed to load issue context`);let n=await a.issueComments(p,e.issue.number,{sourceRepo:e.issue.sourceRepo??null});if(n.connected===!1)throw Error(`Failed to load issue comments`);let r=await Ci(`github.issue.review.visible`,{issue_number:String(e.issue.number)}),u=await Ci(`github.issue.review.instructions`),d=nv({repo:t.repo,issue:t.issue,comments:n.comments??[]});await ri.getState().sendMessage(r,o,s,c,void 0,void 0,[{text:u,synthetic:!0},{text:d,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),Br.success(i(`session.newWorktree.toast.sessionFromIssue`));return}if(e.pr){if(!a.prContext)return;let t=await a.prContext(p,e.pr.number,{sourceRepo:e.pr.sourceRepo??null,includeDiff:e.includeDiff,includeCheckDetails:!1});if(t.connected===!1||!t.repo||!t.pr)throw Error(`Failed to load PR context`);let n=await Ci(`github.pr.review.visible`,{pr_number:String(e.pr.number)}),r=await Ci(`github.pr.review.instructions`),u=rv(t);await ri.getState().sendMessage(n,o,s,c,void 0,void 0,[{text:r,synthetic:!0},{text:u,synthetic:!0}],l,void 0,{sessionId:e.sessionId}),Br.success(i(`session.newWorktree.toast.sessionFromPr`))}},[a,p,ye,be,xe,i]),Ce=h===`new-branch`?_:y;Z.useEffect(()=>{if(!e||!x?.all||!p||_.sourceBranch)return;let t=_.sourceBranch,n=!1;return(async()=>{try{let e=await Fa(p).catch(()=>null);if(n)return;let r=localStorage.getItem(Yo),{sourceBranch:i,shouldClearSavedSourceBranch:a}=as({branches:x.all,savedSourceBranch:r,rootBranch:e});if(a&&localStorage.removeItem(Yo),n||t)return;i&&v(e=>({...e,sourceBranch:i}))}catch{}})(),()=>{n=!0}},[e,x?.all,p,_.sourceBranch]),Z.useLayoutEffect(()=>{if(!e)return;g(`new-branch`),b({selectedBranch:``,worktreeName:``}),M(!1),P(!1),I(!1),R(!1),B(``),H(``),me({isValidating:!1,branchError:null,worktreeError:null,touched:!1});let t=O();v({branchName:t,worktreeName:t,isSyncingWorktreeName:!0,sourceBranch:``,linkedIssue:null,linkedPr:null,includePrDiff:!1})},[e,O]),Z.useEffect(()=>{if(h!==`new-branch`||!_.isSyncingWorktreeName)return;let e=$_(Q_(_.branchName));v(t=>({...t,worktreeName:e}))},[h,_.branchName,_.isSyncingWorktreeName]);let we=Z.useCallback(async()=>{if(!m||!pe.touched||he)return;_e&&_e.abort();let e=new AbortController;ve(e),me(e=>({...e,isValidating:!0}));try{let t=h===`new-branch`?_.branchName:y.selectedBranch,n=Ce.worktreeName,r=Q_(t),a=$_(n),o=null,s=null;if(r||(o=i(`session.newWorktree.error.branchNameRequired`)),a||(s=i(`session.newWorktree.error.worktreeDirectoryRequired`)),r&&a){let t=h===`new-branch`?_.linkedPr:null,n=t?tv(t,w,T):null,i=await Ea(m,{mode:h===`existing-branch`||n?`existing`:`new`,branchName:r,worktreeName:a,existingBranch:n?.existingBranch??(h===`existing-branch`?r:void 0),...n?.ensureRemoteName?{ensureRemoteName:n.ensureRemoteName}:{},...n?.ensureRemoteUrl?{ensureRemoteUrl:n.ensureRemoteUrl}:{}});if(e.signal.aborted)return;i.ok||i.errors.forEach(e=>{if(e.code===`worktree_exists`){s??=e.message;return}e.code.startsWith(`branch_`)&&(o??=e.message)})}e.signal.aborted||me(e=>({...e,isValidating:!1,branchError:o,worktreeError:s}))}catch{e.signal.aborted||me(e=>({...e,isValidating:!1}))}},[m,h,_.branchName,_.linkedPr,y.selectedBranch,Ce.worktreeName,w,T,pe.touched,_e,he,i]),Te=h===`new-branch`?_.branchName:y.selectedBranch;Z.useEffect(()=>{if(!e||!m||!pe.touched||he)return;let t=setTimeout(()=>{we()},300);return()=>clearTimeout(t)},[Ce.worktreeName,Te,e,m,we,pe.touched,he]);let Ee=async()=>{if(!m||!p){Br.error(i(`session.newWorktree.error.noActiveProject`));return}me(e=>({...e,touched:!0}));let e=h===`new-branch`?_.branchName:y.selectedBranch,r=Ce.worktreeName,a=Q_(e),o=$_(r);if(!a){Br.error(i(`session.newWorktree.error.branchNameRequired`));return}if(!o){Br.error(i(`session.newWorktree.error.worktreeDirectoryRequired`));return}_e&&(_e.abort(),ve(null)),me(e=>({...e,isValidating:!1,branchError:null,worktreeError:null})),ge(!0);try{let e=h===`new-branch`?_.linkedPr:null,r=h===`new-branch`?_.linkedIssue:null,s=h===`new-branch`?_.linkedPr:null,c=h===`new-branch`&&_.includePrDiff,l=!!(r||s),[u,d]=await Promise.all([rn(m),ns(p)]),f=_.sourceBranch,g=``,v=(()=>{if(e){let t=tv(e,w,T);return g=t.sourceLabel,{preferredName:a||o,mode:`existing`,branchName:a,worktreeName:o,existingBranch:t.existingBranch,setupCommands:u,setUpstream:t.setUpstream,upstreamRemote:t.upstreamRemote,upstreamBranch:t.upstreamBranch,returnAfterDirectoryCreated:!0,...t.ensureRemoteName?{ensureRemoteName:t.ensureRemoteName}:{},...t.ensureRemoteUrl?{ensureRemoteUrl:t.ensureRemoteUrl}:{}}}return g=h===`new-branch`?f:``,{preferredName:a||o,mode:h===`existing-branch`?`existing`:`new`,branchName:h===`existing-branch`?void 0:a,worktreeName:o,existingBranch:h===`existing-branch`?a:void 0,setupCommands:u,returnAfterDirectoryCreated:!0,...f&&h===`new-branch`?{startRef:f}:{}}})(),b=await us(p,v,{resolvedRootTrackingRemote:d}),x=await Ia(m,b),S=null;if(l){await kn(m)&&await rr(x.path);let e=r?`#${r.number} ${r.title}`.trim():s?`#${s.number} ${s.title}`.trim():i(`session.newWorktree.newSessionTitle`),a=await Yt(e,x.path,null);if(!a?.id)throw Error(`Failed to create session`);S=a.id,n?.(x.path,{sessionId:S}),t(!1),ge(!1),er(a.id,e).catch(()=>void 0);try{ri.getState().initializeNewOpenChamberSession(a.id,Ai.getState().agents)}catch{}}else t(!1),ge(!1);let C=cs({mode:h,sourceBranch:_.sourceBranch,linkedPr:!!_.linkedPr,selectedBranch:y.selectedBranch});C&&localStorage.setItem(Yo,C),Br.success(i(`session.newWorktree.toast.worktreeCreated`),{description:i(`session.newWorktree.toast.worktreeCreatedDescription`,{target:`${x.branch||x.name}${g?` ${i(`session.newWorktree.fromSource`,{source:g})}`:``}`})}),S?Se({sessionId:S,directory:x.path,issue:r,pr:s,includeDiff:c}).catch(e=>{let t=e instanceof Error?e.message:i(`session.newWorktree.error.sendGitHubContextFailed`);Br.error(i(`session.newWorktree.error.sendGitHubContextFailed`),{description:t})}):n?.(x.path)}catch(e){let t=e instanceof Error?e.message:i(`session.newWorktree.error.createWorktreeFailed`);Br.error(i(`session.newWorktree.error.createWorktreeFailed`),{description:t})}finally{ge(!1)}},De=e=>{g(e),me(e=>({...e,touched:!1,branchError:null,worktreeError:null}))},Oe=e=>{if(!e){v(e=>({...e,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:``}));return}if(e.type===`issue`){let t=e.item,n=`issue-${t.number}-${Zg()}`;v(e=>({...e,linkedIssue:t,linkedPr:null,includePrDiff:!1,branchName:n,worktreeName:$_(n),isSyncingWorktreeName:!0}))}else if(e.type===`pr`){let t=e.item;v(n=>({...n,linkedPr:t,linkedIssue:null,includePrDiff:e.includeDiff??!1,branchName:t.head,worktreeName:$_(t.head),isSyncingWorktreeName:!0}))}},ke=d&&u?.connected===!0,Ae=(h===`existing-branch`?!!y.selectedBranch&&!!y.worktreeName&&!pe.branchError&&!pe.worktreeError:!!Q_(_.branchName)&&!!_.worktreeName&&!pe.branchError&&!pe.worktreeError)&&!he,je=()=>{v(e=>({...e,linkedIssue:null,linkedPr:null,branchName:``,includePrDiff:!1,isSyncingWorktreeName:!0}))},Me=(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,s?`flex-col w-full`:`flex-row items-center`),children:[(0,$.jsx)(`div`,{className:Y(`flex items-center gap-1.5 text-destructive`,s?`w-full justify-center order-first`:`mr-auto`),children:pe.touched&&(pe.branchError||pe.worktreeError)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:pe.branchError||pe.worktreeError})]})}),(0,$.jsxs)(`div`,{className:Y(`flex gap-2`,s&&`w-full`),children:[(0,$.jsx)(ua,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:he,className:Y(s&&`flex-1`),children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(ua,{size:`sm`,onClick:Ee,disabled:!Ae||he,className:Y(`gap-1.5`,s&&`flex-1`),children:[he&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(he?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]});return(0,$.jsxs)($.Fragment,{children:[s?(0,$.jsx)(_a,{id:`new-worktree-sheet-${c}`,open:e,onOpenChange:t,title:(0,$.jsx)(`h2`,{className:`truncate typography-ui-label font-semibold text-foreground`,children:i(`session.newWorktree.title`)}),ariaLabel:i(`session.newWorktree.title`),closeAriaLabel:i(`mobile.surface.closeAria`),resizeAriaLabel:i(`mobile.sessions.sheet.resizeAria`),children:(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,$.jsxs)(pa,{useScrollShadow:!0,disableHorizontal:!0,preventOverscroll:!0,outerClassName:`min-h-0 flex-1`,className:`overscroll-contain px-4 pb-4 pt-2`,children:[(0,$.jsx)(`div`,{className:`w-full mb-4`,children:(0,$.jsx)(Xc,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>De(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})}),(0,$.jsxs)(`div`,{className:`space-y-6`,children:[h===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,onClick:()=>I(!0),className:`flex-1 justify-between h-9`,children:[(0,$.jsx)(`span`,{className:y.selectedBranch?`text-foreground`:`text-muted-foreground`,children:y.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),(0,$.jsx)(ua,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:fe,disabled:!de||S,title:i(`session.newWorktree.fetchBranches`),children:S?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]}),(0,$.jsx)(sm,{open:F,title:i(`session.newWorktree.selectBranch`),onClose:()=>I(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:ee,children:[(0,$.jsx)(Va,{value:z,onChange:e=>B(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),S?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[se&&le&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(`session.newWorktree.matchingBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:ae.matching.map(e=>(0,$.jsx)(`button`,{onClick:()=>{b(t=>({...t,selectedBranch:e.value,worktreeName:$_(e.label)})),me(e=>({...e,touched:!0})),I(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.selectedBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),se&&!le&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),ae.otherLocal.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(se?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:ae.otherLocal.map(e=>(0,$.jsx)(`button`,{onClick:()=>{b(t=>({...t,selectedBranch:e,worktreeName:$_(e)})),me(e=>({...e,touched:!0})),I(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.selectedBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),ae.otherRemote.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(se?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:ae.otherRemote.map(e=>(0,$.jsx)(`button`,{onClick:()=>{b(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:$_(e)})),me(e=>({...e,touched:!0})),I(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,y.selectedBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),h===`new-branch`&&ke&&(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,onClick:()=>A(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),_.linkedIssue||_.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Va,{value:_.branchName,onChange:e=>{v(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!_.linkedPr,className:Y(`h-8`,pe.touched&&pe.branchError&&`border-destructive`,_.linkedPr&&`bg-muted text-muted-foreground`)}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:_.linkedPr.head})})]}),_.linkedIssue&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:_.linkedIssue.number,title:_.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),h!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=$_(h===`new-branch`?_.branchName:``);v(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!_.branchName||_.worktreeName===$_(_.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,_.worktreeName===$_(_.branchName)||!_.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,$.jsx)(Va,{value:Ce.worktreeName,onChange:e=>{h===`new-branch`?v(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):b(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,pe.touched&&pe.worktreeError&&`border-destructive`)})]}),h===`new-branch`&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,onClick:()=>R(!0),className:`w-full justify-between h-9`,children:[(0,$.jsx)(`span`,{className:_.sourceBranch?`text-foreground`:`text-muted-foreground`,children:_.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`git-branch`,className:`h-4 w-4 text-muted-foreground`})]}),_.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:_.sourceBranch})}),(0,$.jsx)(sm,{open:L,title:i(`session.newWorktree.selectSourceBranch`),onClose:()=>R(!1),children:(0,$.jsxs)(`div`,{className:`space-y-4`,ref:G,children:[(0,$.jsx)(Va,{value:V,onChange:e=>H(e.target.value),placeholder:i(`session.newWorktree.searchBranches`),className:`h-8`}),S?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(`div`,{className:`px-2 py-8 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[ce&&ue&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(`session.newWorktree.matchingBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:oe.matching.map(e=>(0,$.jsx)(`button`,{onClick:()=>{v(t=>({...t,sourceBranch:e.value})),R(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,_.sourceBranch===e.value?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))})]}),ce&&!ue&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),oe.otherLocal.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(ce?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:oe.otherLocal.map(e=>(0,$.jsx)(`button`,{onClick:()=>{v(t=>({...t,sourceBranch:e})),R(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,_.sourceBranch===e?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},e))})]}),oe.otherRemote.length>0&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`typography-small font-semibold text-foreground px-2`,children:i(ce?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`)}),(0,$.jsx)(`div`,{className:`space-y-1`,children:oe.otherRemote.map(e=>(0,$.jsx)(`button`,{onClick:()=>{v(t=>({...t,sourceBranch:`remotes/${e}`})),R(!1)},className:Y(`w-full text-left px-3 py-2.5 rounded-md transition-colors`,_.sourceBranch===`remotes/${e}`?`bg-interactive-selection text-interactive-selection-foreground`:`hover:bg-interactive-hover`),children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remotes/${e}`))})]})]})]})})]}),(_.linkedIssue||_.linkedPr)&&h===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),_.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:_.linkedIssue.number})}),_.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:_.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:_.linkedIssue?.title||_.linkedPr?.title}),(0,$.jsx)(`a`,{href:_.linkedIssue?.url||_.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick:je,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[_.linkedPr.head,` → `,_.linkedPr.base]}),_.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]})]}),(0,$.jsx)(`div`,{className:`shrink-0 border-t border-border/50 px-4 pb-3 pt-2`,children:Me})]})}):(0,$.jsx)(sa,{open:e,onOpenChange:t,children:(0,$.jsxs)(ra,{className:`max-w-lg max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(ea,{className:`flex flex-row items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(ia,{className:`flex items-center gap-2 shrink-0`,children:[(0,$.jsx)(X,{name:`git-branch`,className:`h-5 w-5`}),i(`session.newWorktree.title`)]}),(0,$.jsx)(`div`,{className:`w-[280px] shrink-0`,children:(0,$.jsx)(Xc,{items:[{id:`new-branch`,label:i(`session.newWorktree.mode.newBranch`),icon:(0,$.jsx)(X,{name:`git-branch`,className:`h-3.5 w-3.5`})},{id:`existing-branch`,label:i(`session.newWorktree.mode.existingBranch`),icon:(0,$.jsx)(X,{name:`git-repository`,className:`h-3.5 w-3.5`})}],activeId:h,onSelect:e=>De(e),variant:`active-pill`,layoutMode:`fit`,className:`w-full`})})]})}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto mt-2 space-y-6`,children:[h===`existing-branch`?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.selectBranch`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)($a,{open:j,onOpenChange:M,children:[(0,$.jsx)(fo,{asChild:!0,children:(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,y.selectedBranch?`text-foreground`:`text-muted-foreground`),children:y.selectedBranch||i(`session.newWorktree.chooseBranch`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(uo,{align:`start`,sideOffset:6,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:U,children:(0,$.jsxs)(v_,{shouldFilter:!1,children:[(0,$.jsx)(y_,{placeholder:i(`session.newWorktree.searchBranches`),value:z,onValueChange:B,onKeyDown:K}),(0,$.jsx)(b_,{disableHorizontal:!0,children:S?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(x_,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[se&&le&&(0,$.jsx)(S_,{heading:i(`session.newWorktree.matchingBranches`),children:ae.matching.map(e=>(0,$.jsx)(w_,{value:e.value,onSelect:()=>{b(t=>({...t,selectedBranch:e.value,worktreeName:$_(e.label)})),me(e=>({...e,touched:!0})),M(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),se&&!le&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),ae.otherLocal.length>0&&(0,$.jsxs)($.Fragment,{children:[se&&(0,$.jsx)(C_,{}),(0,$.jsx)(S_,{heading:i(se?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:ae.otherLocal.map(e=>(0,$.jsx)(w_,{value:e,onSelect:()=>{b(t=>({...t,selectedBranch:e,worktreeName:$_(e)})),me(e=>({...e,touched:!0})),M(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),ae.otherRemote.length>0&&(0,$.jsxs)($.Fragment,{children:[(ae.otherLocal.length>0||se)&&(0,$.jsx)(C_,{}),(0,$.jsx)(S_,{heading:i(se?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:ae.otherRemote.map(e=>(0,$.jsx)(w_,{value:`remotes/${e}`,onSelect:()=>{b(t=>({...t,selectedBranch:`remotes/${e}`,worktreeName:$_(e)})),me(e=>({...e,touched:!0})),M(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),(0,$.jsx)(ua,{variant:`ghost`,size:`sm`,className:`h-8 w-8 px-0 shrink-0`,onClick:fe,disabled:!de||S,title:i(`session.newWorktree.fetchBranches`),children:S?(0,$.jsx)(X,{name:`loader-4`,className:`size-4 animate-spin`}):(0,$.jsx)(X,{name:`refresh`,className:`size-4`})})]})]}):(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.branchName`)}),h===`new-branch`&&ke&&(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,onClick:()=>A(!0),className:`gap-1.5 h-7`,children:[(0,$.jsx)(X,{name:`github`,className:`size-4 text-status-success`}),_.linkedIssue||_.linkedPr?i(`session.newWorktree.actions.change`):i(`session.newWorktree.actions.startFromGitHubIssuePr`)]})]}),(0,$.jsx)(Va,{value:_.branchName,onChange:e=>{v(t=>({...t,branchName:e.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.branchNamePlaceholder`),disabled:!!_.linkedPr,className:Y(`h-8`,pe.touched&&pe.branchError&&`border-destructive`,_.linkedPr&&`bg-muted text-muted-foreground`)}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.usingPrBranch`,{branch:_.linkedPr.head})})]}),_.linkedIssue&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5 text-status-success`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:i(`session.newWorktree.fromIssue`,{number:_.linkedIssue.number,title:_.linkedIssue.title})})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground font-semibold`,children:i(`session.newWorktree.worktreeDirectory`)}),h!==`existing-branch`&&(0,$.jsxs)(`button`,{onClick:()=>{let e=$_(h===`new-branch`?_.branchName:``);v(t=>({...t,worktreeName:e,isSyncingWorktreeName:!0}))},disabled:!_.branchName||_.worktreeName===$_(_.branchName),className:Y(`flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded`,_.worktreeName===$_(_.branchName)||!_.branchName?`text-muted-foreground/40 cursor-not-allowed`:`text-muted-foreground hover:text-foreground hover:bg-muted`),title:i(`session.newWorktree.resetToMatchBranchName`),children:[(0,$.jsx)(X,{name:`refresh`,className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:i(`session.newWorktree.actions.reset`)})]})]}),(0,$.jsx)(Va,{value:Ce.worktreeName,onChange:e=>{h===`new-branch`?v(t=>({...t,worktreeName:e.target.value,isSyncingWorktreeName:!1})):b(t=>({...t,worktreeName:e.target.value}))},onBlur:()=>me(e=>({...e,touched:!0})),placeholder:i(`session.newWorktree.worktreeDirectoryPlaceholder`),className:Y(`h-8`,pe.touched&&pe.worktreeError&&`border-destructive`)})]}),h===`new-branch`&&!_.linkedPr&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`typography-ui-label text-foreground block font-semibold`,children:i(`session.newWorktree.sourceBranch`)}),(0,$.jsxs)($a,{open:N,onOpenChange:P,children:[(0,$.jsx)(fo,{asChild:!0,children:(0,$.jsxs)(ua,{variant:`outline`,size:`sm`,className:`h-9 min-w-[220px] max-w-full justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:Y(`truncate`,_.sourceBranch?`text-foreground`:`text-muted-foreground`),children:_.sourceBranch||i(`session.newWorktree.selectSourceBranchPlaceholder`)}),(0,$.jsx)(X,{name:`arrow-down-s`,className:`h-4 w-4 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(uo,{align:`start`,portalToBody:!0,className:`w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden`,ref:W,children:(0,$.jsxs)(v_,{shouldFilter:!1,children:[(0,$.jsx)(y_,{placeholder:i(`session.newWorktree.searchBranches`),value:V,onValueChange:H,onKeyDown:K}),(0,$.jsx)(b_,{disableHorizontal:!0,children:S?(0,$.jsx)(`div`,{className:`px-2 py-4 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.loadingBranches`)}):w.length===0&&T.length===0?(0,$.jsx)(x_,{children:i(`session.newWorktree.noBranchesFound`)}):(0,$.jsxs)($.Fragment,{children:[ce&&ue&&(0,$.jsx)(S_,{heading:i(`session.newWorktree.matchingBranches`),children:oe.matching.map(e=>(0,$.jsx)(w_,{value:e.value,onSelect:()=>{v(t=>({...t,sourceBranch:e.value})),P(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e.label})},`${e.source}-${e.value}`))}),ce&&!ue&&(0,$.jsx)(`div`,{className:`px-2 py-1 text-center typography-small text-muted-foreground`,children:i(`session.newWorktree.noMatchingBranches`)}),oe.otherLocal.length>0&&(0,$.jsxs)($.Fragment,{children:[ce&&(0,$.jsx)(C_,{}),(0,$.jsx)(S_,{heading:i(ce?`session.newWorktree.otherLocalBranches`:`session.newWorktree.localBranches`),children:oe.otherLocal.map(e=>(0,$.jsx)(w_,{value:e,onSelect:()=>{v(t=>({...t,sourceBranch:e})),P(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`local-${e}`))})]}),oe.otherRemote.length>0&&(0,$.jsxs)($.Fragment,{children:[(oe.otherLocal.length>0||ce)&&(0,$.jsx)(C_,{}),(0,$.jsx)(S_,{heading:i(ce?`session.newWorktree.otherRemoteBranches`:`session.newWorktree.remoteBranches`),children:oe.otherRemote.map(e=>(0,$.jsx)(w_,{value:`remotes/${e}`,onSelect:()=>{v(t=>({...t,sourceBranch:`remotes/${e}`})),P(!1)},children:(0,$.jsx)(`span`,{className:`typography-small break-all`,children:e})},`remote-${e}`))})]})]})})]})})]}),_.sourceBranch&&(0,$.jsx)(`div`,{className:`typography-micro text-muted-foreground`,children:i(`session.newWorktree.newBranchFromSource`,{source:_.sourceBranch})})]}),(_.linkedIssue||_.linkedPr)&&h===`new-branch`&&(0,$.jsxs)(`div`,{className:`mt-2 px-2 py-1.5 rounded bg-muted/30`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{name:`github`,className:`h-3.5 w-3.5 text-status-success shrink-0`}),_.linkedIssue&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.issueNumber`,{number:_.linkedIssue.number})}),_.linkedPr&&(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground shrink-0`,children:i(`session.newWorktree.prNumber`,{number:_.linkedPr.number})}),(0,$.jsx)(`span`,{className:`typography-micro text-foreground truncate flex-1`,children:_.linkedIssue?.title||_.linkedPr?.title}),(0,$.jsx)(`a`,{href:_.linkedIssue?.url||_.linkedPr?.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-muted-foreground hover:text-foreground shrink-0`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(X,{name:`external-link`,className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick:je,className:`text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors`,children:(0,$.jsx)(X,{name:`close`,className:`h-3.5 w-3.5`})})]}),_.linkedPr&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 pl-5`,children:[(0,$.jsxs)(`span`,{className:`typography-micro text-muted-foreground`,children:[_.linkedPr.head,` → `,_.linkedPr.base]}),_.includePrDiff&&(0,$.jsx)(`span`,{className:`typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success`,children:i(`session.newWorktree.includeDiffBadge`)})]})]})]}),(0,$.jsxs)(ta,{className:`mt-1 flex items-center justify-between`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 text-destructive`,children:pe.touched&&(pe.branchError||pe.worktreeError)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`typography-micro`,children:pe.branchError||pe.worktreeError})]})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ua,{variant:`outline`,size:`sm`,onClick:()=>t(!1),disabled:he,children:i(`session.newWorktree.actions.cancel`)}),(0,$.jsxs)(ua,{size:`sm`,onClick:Ee,disabled:!Ae||he,className:`gap-1.5`,children:[he&&(0,$.jsx)(X,{name:`loader-4`,className:`h-3.5 w-3.5 animate-spin`}),i(he?`session.newWorktree.actions.creating`:`session.newWorktree.actions.createWorktree`)]})]})]})]})}),(0,$.jsx)(X_,{open:k,onOpenChange:A,onSelect:Oe})]})}function av(e){let t=e.selectedDirectory??e.projectRootOption?.value??e.worktreeOptions[0]?.value??null;return t?e.projectRootOption?.value===t?e.projectRootOption.label?.trim()||null:e.worktreeOptions.find(e=>e.value===t)?.label?.trim()||null:null}function ov(e,t){if(!e||!t)return!1;let n=t.replace(/\\/g,`/`).replace(/\/+$/,``);if(!n)return!1;let r=n===`/`?`/`:n.split(`/`).pop()||``;return!!r&&e===r}var sv=(e,t)=>e??t??null,cv=(e,t)=>!!e&&t!==!1,lv=e=>e?.length?{localBranches:e.filter(e=>!e.startsWith(`remotes/`)).sort(),remoteBranches:e.filter(e=>e.startsWith(`remotes/`)).map(e=>e.replace(/^remotes\//,``)).sort()}:{localBranches:[],remoteBranches:[]},uv=e=>e.replace(/^remotes\//,``).trim(),dv=e=>{let t=uv(e),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t},fv=({directory:e,projectDirectory:t,label:n,projectRootOption:r,worktreeOptions:i,onSelectDirectory:a,className:o,maxWidthClassName:c=`max-w-[48vw] sm:max-w-[20rem]`,presentation:l=`dropdown`})=>{let{t:u}=ct(),{git:d}=ko(),f=sv(t,e),p=e,m=fs(f),h=fs(p),g=cv(f,m),_=p!==f&&cv(p,h),v=Po(f,d,g),y=Po(p,d,_),b=v.data,x=p===f?b:y.data,S=Xo(e=>e.fetchStatus),C=Xo(e=>p&&e.directories.get(p)?.status?.current?.trim()||null),[w,T]=Z.useState(!1),E=ds(f,d,g&&w).data??[],[D,O]=Z.useState(null),[k,A]=Z.useState(!1),[j,M]=Z.useState(!1),N=gr(e=>e.projects),P=gr(e=>e.activeProjectId);Z.useEffect(()=>{d&&(f&&m===null&&S(f,d,{silent:!0}),p&&p!==f&&h===null&&S(p,d,{silent:!0}))},[S,d,m,h,f,p]);let F=Z.useMemo(()=>{let e=s(t);if(e){let t=N.find(t=>s(t.path)===e);if(t)return t.id}return P},[P,t,N]),{localBranches:I,remoteBranches:L}=Z.useMemo(()=>lv(b?.all),[b]),R=x?.current?.trim()||C||null,z=!ov(n,e)&&n||R||n||u(`chat.chatInput.branch`),B=J(async()=>{if(!d)return;let e=new Set;f&&e.add(f),p&&e.add(p),await Promise.all([...e].map(async e=>{await Go(e,d),await S(e,d,{silent:!0})}))}),V=J(e=>{let t=uv(e),n=dv(t);return i.find(e=>{let r=e.label.trim();return r===t||r===n})??null}),H=J(async e=>{if(!p||!d)return;let t=uv(e);if(R!==t&&R!==dv(t))try{await d.checkoutBranch(p,t),Br.success(u(`gitView.toast.checkedOut`,{name:t})),await B()}catch(e){let n=e instanceof Error?e.message:u(`gitView.toast.checkoutFailed`,{name:t});Br.error(n)}}),U=J(e=>{let t=uv(e);if(!t||R===t||R===dv(t))return;let n=V(t);if(n){a(n.value);return}O(t)}),W=J(async()=>{if(!(!D||k)){A(!0);try{await H(D),O(null)}finally{A(!1)}}}),ee=J(async()=>{if(!(!D||k)){A(!0);try{await u_({branch:D,projectDirectory:t??void 0})&&O(null)}finally{A(!1)}}}),G=J(async(e,t)=>{if(!p||!d)return;let n=t?.name??`origin`;try{await d.createBranch(p,e,R??`HEAD`),Br.success(u(`gitView.toast.createdBranch`,{name:e})),O(e),d.gitPush(p,{remote:n,branch:e,options:[`--set-upstream`]}).then(async()=>{await B(),Br.success(u(`gitView.toast.upstreamSet`,{branch:e,remote:n}))}).catch(async e=>{let t=e instanceof Error?e.message:u(`gitView.toast.branchCreatedLocally`);Br.warning(u(`gitView.toast.branchCreatedLocally`),{description:(0,$.jsx)(`span`,{className:`text-foreground/80 dark:text-foreground/70`,children:t})}),await B()})}catch(e){let t=e instanceof Error?e.message:u(`gitView.toast.createBranchFailed`);throw Br.error(t),e}}),K=J(()=>{let e=gr.getState(),n=s(t),r=n?e.projects.find(e=>s(e.path)===n)??null:null;r&&e.activeProjectId!==r.id&&e.setActiveProjectIdOnly(r.id),M(!0)}),te=J((e,n)=>{if(M(!1),n?.sessionId){ri.getState().setCurrentSession(n.sessionId,e);return}let r=gr.getState(),i=s(t),a=(i?r.projects.find(e=>s(e.path)===i)??null:null)?.id??r.activeProjectId??null,o=ri.getState();if(o.newSessionDraft?.open){o.overrideNewSessionDraftTarget({...a?{selectedProjectId:a}:{},directoryOverride:e,bootstrapPendingDirectory:e,preserveDirectoryOverride:!0}),Se.getState().setDirectory(e,{showOverlay:!1});return}o.openNewSessionDraft({...a?{selectedProjectId:a}:{},directoryOverride:e,preserveDirectoryOverride:!0})}),ne=(0,$.jsxs)(`button`,{type:`button`,className:Y(`group relative inline-flex min-w-0 w-fit items-center gap-1.5 rounded-lg !border-0 px-1.5 font-medium text-foreground/80`,l===`mobile-sheet`?`h-[26px] text-[11px] leading-none`:`h-6 py-1 pr-1.5 typography-micro transition-[padding] hover:pr-5 focus-visible:pr-5 data-[popup-open]:pr-5`,c,gm,o),"aria-label":z,children:[(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:z}),l===`dropdown`?(0,$.jsx)(X,{name:`arrow-down-s`,className:`pointer-events-none absolute right-1 size-3.5 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100 group-data-[popup-open]:opacity-100`,"aria-hidden":`true`}):null]});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(q_,{currentBranch:R,localBranches:I,remoteBranches:L,branchInfo:b?.branches,onCheckout:U,onCreate:G,remotes:E,trigger:ne,triggerLabel:z,hideTooltip:!0,projectRootOption:r,worktreeOptions:i,selectedDirectory:e,onSelectDirectory:a,onCreateWorktree:K,open:w,presentation:l,onOpenChange:T}),j?(0,$.jsx)(iv,{open:!0,projectId:F,onOpenChange:M,onWorktreeCreated:te}):null,(0,$.jsx)(sa,{open:!!D,onOpenChange:e=>{!e&&!k&&O(null)},children:(0,$.jsxs)(ra,{showCloseButton:!1,className:`max-w-sm gap-4`,children:[(0,$.jsxs)(ea,{children:[(0,$.jsx)(ia,{children:u(`chat.chatInput.branchSwitch.title`,{branch:D??``})}),(0,$.jsx)(aa,{children:u(`chat.chatInput.branchSwitch.description`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`button`,{type:`button`,disabled:k,onClick:()=>{W()},className:`flex w-full flex-col items-start gap-0.5 rounded-lg border border-border px-3 py-2.5 text-left hover:bg-interactive-hover disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 typography-ui-label font-medium text-foreground`,children:[k?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`arrow-left-right`,className:`size-3.5 text-muted-foreground`}),u(`chat.chatInput.branchSwitch.checkoutHere`)]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:u(`chat.chatInput.branchSwitch.checkoutHereDescription`)})]}),(0,$.jsxs)(`button`,{type:`button`,disabled:k,onClick:()=>{ee()},className:`flex w-full flex-col items-start gap-0.5 rounded-lg border border-border px-3 py-2.5 text-left hover:bg-interactive-hover disabled:opacity-50`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 typography-ui-label font-medium text-foreground`,children:[k?(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 animate-spin`}):(0,$.jsx)(X,{name:`git-branch`,className:`size-3.5 text-muted-foreground`}),u(`chat.chatInput.branchSwitch.createWorktree`)]}),(0,$.jsx)(`span`,{className:`typography-micro text-muted-foreground`,children:u(`chat.chatInput.branchSwitch.createWorktreeDescription`)})]})]}),(0,$.jsx)(ta,{children:(0,$.jsx)(`button`,{type:`button`,disabled:k,onClick:()=>O(null),className:`inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 disabled:opacity-50`,children:u(`chat.chatInput.branchSwitch.cancel`)})})]})})]})},pv=[],mv=[],hv={revertMessageID:void 0,records:mv},gv=e=>e.role===`user`,_v=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]?.message!==t[n]?.message||e[n]?.parts!==t[n]?.parts)return!1;return!0},vv=(e,t,n=hv)=>{if(!t)return hv;let r=(`session`in e?e.session:[]).find(e=>e.id===t)?.revert?.messageID;if(!r)return hv;let i=`messages`in e?e.messages:e.message[t]??[],a=`partsByMessageID`in e?e.partsByMessageID:e.part,o=[];for(let e of i)!gv(e)||!gn(i,e.id,r)||o.push({message:e,parts:a[e.id]??pv});let s=o.length===0?mv:o;return n.revertMessageID===r&&_v(n.records,s)?n:{revertMessageID:r,records:s}},yv={mentionFile:100,mentionAgent:100,mentionSession:100,mentionCommand:100,mentionSnippet:100,mentionPaste:100,code:90,codeFence:90,link:80,linkUrl:78,heading:70,blockquote:40,listMarker:35,marker:10},bv={mentionFile:`text-[var(--primary)]`,mentionAgent:`text-[var(--primary)]`,mentionSession:`text-[var(--primary)]`,mentionCommand:`text-[var(--primary)]`,mentionSnippet:`text-[var(--primary)]`,mentionPaste:`text-[var(--primary)]`,code:`rounded-[3px] bg-[var(--surface-subtle)] text-[var(--markdown-inline-code)]`,codeFence:`bg-[var(--surface-subtle)] text-[var(--markdown-inline-code)]`,link:`text-[var(--status-info)] underline`,linkUrl:`text-muted-foreground`,heading:`text-[var(--syntax-keyword)]`,blockquote:`text-muted-foreground`,listMarker:`text-[var(--syntax-keyword)]`,marker:`text-muted-foreground`},xv=`text-foreground`;function Sv(e,t,n){let r=0,i=e.length;for(;r<i;){let i=e[r];if(i==="`"){let i=/^`+/.exec(e.slice(r))?.[0]??``,a=e.indexOf(i,r+i.length);if(a!==-1){let e=a+i.length;n.push({start:t+r,end:t+e,style:`code`}),r=e;continue}}if(i===`[`){let i=/^\[([^\]\n]*)\]\(([^)\n]*)\)/.exec(e.slice(r));if(i){let e=t+r,a=i[1].length,o=i[2].length,s=e+1,c=s+a,l=c+2,u=l+o,d=u+1;n.push({start:e,end:s,style:`marker`}),a>0&&n.push({start:s,end:c,style:`link`}),n.push({start:c,end:l,style:`marker`}),o>0&&n.push({start:l,end:u,style:`linkUrl`}),n.push({start:u,end:d,style:`marker`}),r+=i[0].length;continue}}r+=1}}var Cv=/^(\s*)(`{3,}|~{3,})\s*(\S*)/;function wv(e){let t=Cv.exec(e);return t?{marker:t[2],lang:t[3]||``}:null}function Tv(e,t){return RegExp(`^\\s*\\${t[0]}{${t.length},}\\s*$`).test(e)}function Ev(e){let t=[];if(!e)return t;let n=0,r=!1,i=``,a=e.split(`
6522
6522
  `);for(let e=0;e<a.length;e+=1){let o=a[e],s=n,c=s+o.length;if(n=c+1,r){t.push({start:s,end:c,style:`codeFence`}),Tv(o,i)&&(r=!1);continue}let l=wv(o);if(l){r=!0,i=l.marker,t.push({start:s,end:c,style:`codeFence`});continue}let u=/^(\s*)(#{1,6})(\s+)/.exec(o);if(u){let e=s+u[1].length,n=e+u[2].length;t.push({start:e,end:n,style:`marker`});let r=n+u[3].length;c>r&&(t.push({start:r,end:c,style:`heading`}),Sv(o.slice(r-s),r,t));continue}let d=/^(\s*)(>+)(\s?)/.exec(o);if(d){let e=s+d[1].length,n=e+d[2].length;t.push({start:e,end:n,style:`marker`});let r=n+d[3].length;c>r&&(t.push({start:r,end:c,style:`blockquote`}),Sv(o.slice(r-s),r,t));continue}let f=/^(\s*)([-*+]|\d{1,9}[.)])(\s+)/.exec(o);if(f){let e=s+f[1].length,n=e+f[2].length;t.push({start:e,end:n,style:`listMarker`});let r=n+f[3].length;Sv(o.slice(r-s),r,t);continue}Sv(o,s,t)}return t}function Dv(e,t){if(!e||t.length===0)return null;let n=e.length,r=new Set([0,n]);for(let e of t)e.start>0&&e.start<n&&r.add(e.start),e.end>0&&e.end<n&&r.add(e.end);let i=[...r].sort((e,t)=>e-t),a=t.map((e,t)=>({range:e,index:t})).filter(e=>e.range.end>e.range.start).sort((e,t)=>e.range.start-t.range.start),o=[],s=[],c=0;for(let t=0;t<i.length-1;t+=1){let n=i[t],r=i[t+1];if(r<=n)continue;for(;c<a.length&&a[c].range.start<=n;)s.push(a[c]),c+=1;for(let e=s.length-1;e>=0;--e)s[e].range.end<=n&&s.splice(e,1);let l=null,u=-1,d=1/0;for(let{range:e,index:t}of s){let n=e.priority??yv[e.style];(n>u||n===u&&t<d)&&(u=n,d=t,l=e)}let f=l?l.className??bv[l.style]:xv,p=e.slice(n,r),m=l?.visual,h=l?.skillName,g=o[o.length-1];g&&g.className===f&&P(g.visual,m)&&g.skillName===h?g.text+=p:o.push({text:p,className:f,visual:m,skillName:h})}return o.length>0?o:null}function Ov(e,t){let n=new Set(Array.from(t,e=>e.toLowerCase())),r=[],i=/(^|\s)\/(\u2003)?([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)/gi,a;for(;(a=i.exec(e))!==null;){let e=a[2]??``,t=a[3]||``;if(!n.has(t.toLowerCase()))continue;let i=a.index+(a[1]?.length??0);r.push({start:i,end:i+1+e.length+t.length,name:t})}return r}function kv(e,t,n){if(e===t){let t=n.find(t=>e>t.start&&e<t.end);return t?{start:t.start,end:t.end}:null}let r=n.filter(n=>n.start<t&&n.end>e);return r.length===0?null:{start:Math.min(e,...r.map(e=>e.start)),end:Math.max(t,...r.map(e=>e.end))}}function Av(e,t,n){let r=Ov(e,t),i=Math.max(0,Math.min(n.selectionStart,e.length)),a=Math.max(i,Math.min(n.selectionEnd,e.length)),o=i,s=a;if(i===a)if(n.altKey)if(n.key===`Backspace`){for(;o>0&&/\s/.test(e[o-1]);)--o;for(;o>0&&!/\s/.test(e[o-1]);)--o}else{for(;s<e.length&&/\s/.test(e[s]);)s+=1;for(;s<e.length&&!/\s/.test(e[s]);)s+=1}else n.key===`Backspace`?o=Math.max(0,i-1):s=Math.min(e.length,i+1);if(o===s)return null;let c=r.filter(e=>e.start<s&&e.end>o);if(c.length===0)return null;let l=Math.min(o,...c.map(e=>e.start)),u=Math.max(s,...c.map(e=>e.end));return u<e.length&&/\s/.test(e[u])&&(l===0||/\s/.test(e[l-1]))?u+=1:u===e.length&&l>0&&/\s/.test(e[l-1])&&--l,{text:`${e.slice(0,l)}${e.slice(u)}`,caret:l,removedSkillNames:c.map(e=>e.name)}}function jv(e){return e.map(e=>({start:e.start,end:e.end,style:e.kind===`file`?`mentionFile`:e.kind===`session`?`mentionSession`:`mentionAgent`,visual:e.kind===`session`&&e.label?G({trigger:`@`,icon:`chat-thread`,label:e.label},L({trigger:`@`,icon:`chat-thread`,label:e.label})):void 0}))}function Mv(e){let t=(0,Q.c)(28),{visual:n,text:r}=e,i=n.trigger.length,a=i+n.label.length,o=a+(n.suffix?.length??0),s;t[0]!==a||t[1]!==i||t[2]!==r?(s=r.slice(i,Math.min(a,r.length)),t[0]=a,t[1]=i,t[2]=r,t[3]=s):s=t[3];let c=s,l;t[4]!==a||t[5]!==o||t[6]!==r?(l=r.slice(a,Math.min(o,r.length)),t[4]=a,t[5]=o,t[6]=r,t[7]=l):l=t[7];let u=l,d;t[8]!==o||t[9]!==r?(d=r.slice(Math.min(o,r.length)),t[8]=o,t[9]=r,t[10]=d):d=t[10];let f=d,p;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(p={left:F,right:F},t[11]=p):p=t[11];let m=n.icon,h;t[12]===m?h=t[13]:(h=(0,$.jsx)(`span`,{className:`pointer-events-none absolute inset-y-0 inline-flex items-center justify-center`,style:p,children:(0,$.jsx)(X,{name:m,className:`${k} shrink-0 text-[var(--primary)]`,"aria-hidden":`true`})}),t[12]=m,t[13]=h);let g;t[14]!==h||t[15]!==n.trigger?(g=(0,$.jsxs)(`span`,{className:`relative inline-block align-baseline text-transparent leading-none`,children:[n.trigger,h]}),t[14]=h,t[15]=n.trigger,t[16]=g):g=t[16];let _;t[17]===c?_=t[18]:(_=(0,$.jsx)(`span`,{children:c}),t[17]=c,t[18]=_);let v;t[19]===u?v=t[20]:(v=u?(0,$.jsx)(`span`,{className:`text-transparent`,children:u}):null,t[19]=u,t[20]=v);let y;t[21]===f?y=t[22]:(y=f?(0,$.jsx)(`span`,{className:`text-transparent`,children:f}):null,t[21]=f,t[22]=y);let b;return t[23]!==y||t[24]!==g||t[25]!==_||t[26]!==v?(b=(0,$.jsxs)($.Fragment,{children:[g,_,v,y]}),t[23]=y,t[24]=g,t[25]=_,t[26]=v,t[27]=b):b=t[27],b}var Nv=`bg-[var(--surface-subtle)]`,Pv=91,Fv=94,Iv={keyword:8,function:7,type:6,string:5,number:5,variable:4,operator:3,comment:2},Lv={keyword:`${Nv} text-[var(--syntax-keyword)]`,string:`${Nv} text-[var(--syntax-string)]`,number:`${Nv} text-[var(--syntax-number)]`,comment:`${Nv} text-[var(--syntax-comment)]`,function:`${Nv} text-[var(--syntax-function)]`,type:`${Nv} text-[var(--syntax-type)]`,variable:`${Nv} text-[var(--syntax-variable)]`,operator:`${Nv} text-[var(--syntax-operator)]`},Rv=Ye([{tag:[Ze.comment,Ze.lineComment,Ze.blockComment,Ze.docComment,Ze.meta],class:`comment`},{tag:[Ze.keyword,Ze.modifier,Ze.controlKeyword,Ze.operatorKeyword,Ze.definitionKeyword,Ze.moduleKeyword,Ze.self,Ze.null],class:`keyword`},{tag:[Ze.string,Ze.special(Ze.string),Ze.docString,Ze.character,Ze.regexp],class:`string`},{tag:[Ze.number,Ze.integer,Ze.float,Ze.bool,Ze.atom],class:`number`},{tag:[Ze.function(Ze.variableName),Ze.function(Ze.propertyName),Ze.macroName,Ze.standard(Ze.variableName)],class:`function`},{tag:[Ze.typeName,Ze.className,Ze.namespace,Ze.tagName],class:`type`},{tag:[Ze.variableName,Ze.propertyName,Ze.attributeName,Ze.labelName,Ze.definition(Ze.variableName)],class:`variable`},{tag:[Ze.operator,Ze.punctuation,Ze.bracket,Ze.derefOperator,Ze.separator],class:`operator`},{tag:[Ze.heading,Ze.heading1,Ze.heading2,Ze.heading3,Ze.heading4,Ze.heading5,Ze.heading6,Ze.strong],class:`keyword`},{tag:[Ze.emphasis,Ze.quote],class:`type`},{tag:[Ze.link,Ze.url],class:`function`},{tag:[Ze.monospace],class:`string`},{tag:[Ze.strikethrough],class:`comment`}]),zv=e=>{let t=null;for(let n of e.split(` `)){let e=n;Iv[e]!==void 0&&(t===null||Iv[e]>Iv[t])&&(t=e)}return t?Lv[t]:null},Bv=2e4,Vv=e=>{if(!e)return null;try{let t=oo(e);return t instanceof Qe?t:null}catch{return null}};function Hv(e){if(!e||!e.includes("```")&&!e.includes(`~~~`))return[];let t=[],n=e.split(`
6523
6523
  `),r=0;for(let e=0;e<n.length;e+=1){let i=n[e];r+=i.length+1;let a=wv(i);if(!a)continue;let o=Vv(a.lang),s=r,c=[],l=e+1,u=r;for(;l<n.length;l+=1){let e=n[l];if(Tv(e,a.marker)){u+=e.length+1;break}c.push(e),u+=e.length+1}if(e=l,r=u,!o||c.length===0)continue;let d=c.join(`
6524
- `);if(d.trim()&&(t.push({start:s,end:s+d.length,style:`codeFence`,className:`${Nv} text-[var(--syntax-foreground)]`,priority:Pv}),!(d.length>Bv)))try{let e=o.parser.parse(d);Xe(e,Rv,(e,n,r)=>{let i=zv(r);i&&t.push({start:s+e,end:s+n,style:`codeFence`,className:i,priority:Fv})})}catch{}}return t}var Uv=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],Wv=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),Gv=e=>{if(!Wv(e)||/\s/.test(e))return!1;if(e.startsWith(`//`)||e.startsWith(`\\\\`)){let t=e.replace(/^[\\/]+/,``);return/[\\/]/.test(t)}if(/^[A-Za-z]:[\\/]/.test(e)){let t=e.slice(3);return t.includes(`\\`)||t.includes(`/`)||t.includes(`.`)}return e.replace(/^\/+/,``).includes(`/`)},Kv=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?Gv(n):Wv(n))?n:null},qv=(e,t,n=0)=>{if(!(n>6||e==null)){if(typeof e==`string`){t.add(e);return}if(Array.isArray(e)){for(let r of e)qv(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))qv(r,t,n+1)}},Jv=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=Kv(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=Kv(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;qv(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},Yv=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of Uv){let r=``;try{r=e.getData(n)}catch{continue}let i=n===`text/plain`?{allowMultipleLines:!1,allowStructuredPayload:!1,fromPlainText:!0}:n===`text/uri-list`?{allowStructuredPayload:!1}:void 0;for(let e of Jv(r,i))t.add(e)}return Array.from(t)},Xv=e=>{let t=e.trim();if(!t.toLowerCase().startsWith(`file://`))return t;try{let e=new URL(t),n=decodeURIComponent(e.pathname||``);return e.hostname&&e.hostname!==`localhost`&&(n=`//${e.hostname}${n}`),/^\/[A-Za-z]:\//.test(n)&&(n=n.slice(1)),n||t}catch{let e=t.replace(/^file:\/\//i,``);try{return decodeURIComponent(e)}catch{return e}}},Zv=e=>Wv(e);function Qv(e,t){let n=(0,Q.c)(5),r=_t(e,t),i=q($v),a;n[0]===r?a=n[1]:(a=sn(r),n[0]=r,n[1]=a);let o;return n[2]!==i||n[3]!==a?(o={goal:a,enabled:i},n[2]=i,n[3]=a,n[4]=o):o=n[4],o}function $v(e){return e.sessionGoalEnabled}function ey(e,t){let n=(0,Q.c)(4),[r,i]=Z.useState(null),a=t?.objectiveFile?`${e}:${t.id}:${t.updatedAt}`:``,o,s;return n[0]!==a||n[1]!==e?(o=()=>{if(!a){i(null);return}let t=!0;return Mt(e).then(e=>{t&&i(e)}),()=>{t=!1}},s=[a,e],n[0]=a,n[1]=e,n[2]=o,n[3]=s):(o=n[2],s=n[3]),Z.useEffect(o,s),t?t.objectiveFile?r:t.objective:null}var ty={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},ny={active:`chat.goal.status.active`,paused:`chat.goal.status.paused`,blocked:`chat.goal.status.blocked`,budgetLimited:`chat.goal.status.budgetLimited`,complete:`chat.goal.status.complete`},ry=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=ct(),i=q(e=>e.isMobile),{goal:a,enabled:o}=Qv(e??``,t),s=ey(e??``,a),c=Fi(e??``,t),l=En(e,t),u=Z.useRef(null),[d,f]=Z.useState(!1),[p,m]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!a||a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`)return;let e=window.setInterval(()=>m(Date.now()),1e3);return()=>window.clearInterval(e)},[a?.id,a?.status]),Z.useEffect(()=>{if(!e||!a||a.status!==`active`)return;let n=l[0]?.id;if(!n)return;let r=`${e}:${a.id}:${n}`;u.current!==r&&(u.current=r,Ot(e,t))},[e,t,a,l]);let h=J(async n=>{if(!(!e||d)){f(!0);try{await hn(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),Br.error(r(`chat.goal.toast.actionFailed`))}finally{f(!1)}}});if(!e||!o||!a)return null;let g=Math.max(0,(a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`?a.updatedAt:p)-(a.createdAt||p)),_=vt(g),v=a.tokenBudget?`${Gr(a.tokensUsed)}/${Gr(a.tokenBudget)}`:a.tokensUsed>0?Gr(a.tokensUsed):null,y=a.status===`active`?{icon:`pause`,labelKey:`chat.goal.action.pause`,next:`paused`}:a.status===`paused`||a.status===`blocked`||a.status===`budgetLimited`?{icon:`play`,labelKey:`chat.goal.action.resume`,next:`active`}:null,b=i?`text-[11px] leading-none text-muted-foreground`:`typography-meta text-muted-foreground`,x=i?`text-xs leading-5 text-foreground`:`typography-ui-label leading-5 text-foreground`,S=i?`size-3`:`size-3.5`;return(0,$.jsxs)(`div`,{className:Y(`flex w-full min-w-0 items-center`,i?`gap-1 py-0.5`:`gap-1.5 py-0.5 md:gap-2`,n),"aria-label":r(`chat.goal.row.aria`),title:s??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(S,`flex-shrink-0`),style:{color:ty[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,x),children:a.note||s||``}),a.status===`active`&&(!c||c.type===`idle`)?(0,$.jsxs)(`span`,{className:Y(`flex flex-shrink-0 items-center gap-1`,b),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(S,`animate-spin`),"aria-hidden":`true`}),r(`chat.goal.status.evaluating`)]}):(0,$.jsx)(`span`,{className:Y(`flex-shrink-0`,b),children:r(ny[a.status])}),(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,b,`text-muted-foreground/70`),children:_}),v?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,b,`text-muted-foreground/70`),children:v}):null,y?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void h(y.next),disabled:d,className:Y(`inline-flex flex-shrink-0 cursor-pointer items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,i?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),"aria-label":r(y.labelKey),children:[(0,$.jsx)(X,{name:y.icon,className:S,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,i?`leading-none`:`typography-ui-label`),children:r(y.labelKey)})]}):null]})});ry.displayName=`SessionGoalRow`;var iy=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=ct(),{goal:i,enabled:a}=Qv(e??``,t),o=yn(e=>e.armed),s=yn(e=>e.setArmed),[c,l]=Z.useState(!1);if(se()||!a||!e&&!n||!o&&!i)return null;let u=i?.status===`complete`?`text-[var(--status-success)]`:i?.status===`blocked`||i?.status===`budgetLimited`?`text-[var(--status-error)]`:o||i?.status===`active`||i?.status===`paused`?`text-[var(--status-info)]`:``,d=async()=>{if(o){s(!1);return}if(!(!e||c)){l(!0);try{await Ln(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),Br.error(r(`chat.goal.toast.actionFailed`))}finally{l(!1)}}};return(0,$.jsxs)(`span`,{className:Y(`inline-flex h-7 items-center gap-1 rounded-full bg-[var(--surface-muted)] py-1 pl-2 pr-1 typography-ui-label`,u),children:[(0,$.jsx)(X,{name:`target`,className:`h-4 w-4`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:r(`chat.goal.chip.label`)}),(0,$.jsx)(`button`,{type:`button`,className:`flex h-5 w-5 items-center justify-center rounded-full text-current hover:bg-[var(--interactive-hover)] disabled:opacity-50`,onClick:()=>void d(),disabled:c,"aria-label":r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),title:r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`,"aria-hidden":`true`})})]})});iy.displayName=`SessionGoalButton`;var ay=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=ct();if(!yn(oy)||n===0)return null;let i=n>5e3?`text-[var(--status-error)]`:`text-muted-foreground/70`,a;t[0]===i?a=t[1]:(a=Y(`flex-shrink-0 self-center typography-micro tabular-nums`,i),t[0]=i,t[1]=a);let o;t[2]===r?o=t[3]:(o=r(`chat.goal.counter.aria`),t[2]=r,t[3]=o);let s;t[4]===r?s=t[5]:(s=r(`chat.goal.counter.aria`),t[4]=r,t[5]=s);let c;return t[6]!==n||t[7]!==a||t[8]!==o||t[9]!==s?(c=(0,$.jsxs)(`span`,{className:a,"aria-label":o,title:s,children:[n,`/`,Xr]}),t[6]=n,t[7]=a,t[8]=o,t[9]=s,t[10]=c):c=t[10],c});ay.displayName=`SessionGoalObjectiveCounter`;function oy(e){return e.armed}var sy=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`]),cy=new Set([`new`,`compact`,`fork`,`undo`,`redo`]),ly=/^\/\u2003?([^\s]+)/i,uy=/^\/\u2003?goal\b/i,dy=(e,t)=>{if(t!==`normal`)return null;let n=e.trimStart().match(ly)?.[1]?.toLowerCase();return n&&sy.has(n)?n:null},fy=(e,t)=>dy(e,t)===`goal`?e.trimStart().replace(uy,``).trim():null,py=(e,t)=>dy(e,t)!==null,my=(e,t)=>{let n=dy(e,t);return n!==null&&cy.has(n)},hy=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},gy=async({command:e,consumeCommandText:t,forkSession:n,waitForConnection:r,getDirectoryForSession:i,summarizeSession:a,onCompactError:o,onForkError:s})=>{if(t(),e===`fork`){try{await n()}catch(e){s(e)}return}try{await r();let e=i();if(!e){o();return}await a(e)}catch{o()}},_y=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,vy=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,yy=e=>e.surfaceKind!==`primary`||!e.stagedSessionId||!e.stagedMessageId||e.stagedMessageId!==e.blurredMessageId||e.submitInFlight||e.focusHeld||e.overlayOpen||e.focusInsideComposer?{action:`keep`}:{action:`disarm`,sessionId:e.stagedSessionId},by=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),xy=(e,t)=>{let n=b.getState();return n.bindLegacyQueue(v(e.sessionID),e),n.stageAdmission(e,{requestID:t.requestID,queueItemID:t.queueItemID,operationID:t.operationID,messageID:t.messageID,content:t.content,createdAt:t.createdAt,attachmentCount:t.attachments.length,...t.composerDocument?{composerDocument:t.composerDocument}:{},...t.composerMentions?{composerMentions:t.composerMentions}:{}}),n.confirmAdmission(e,{requestID:t.requestID,sendConfig:t.sendConfig,attachments:t.attachments}).ok},Sy=async e=>{let t=mn.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=by(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}xy(n,a)?r+=1:i+=1}catch{try{xy(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},Cy=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),wy=e=>e===`allow`||e===`ask`||e===`deny`,Ty=e=>{if(wy(e))return[{permission:`*`,pattern:`*`,action:e}];if(Array.isArray(e))return e.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e;return typeof t.permission==`string`&&typeof t.pattern==`string`&&wy(t.action)?[{permission:t.permission,pattern:t.pattern,action:t.action}]:[]});if(!e||typeof e!=`object`)return[];let t=[];for(let[n,r]of Object.entries(e))if(n!==`__originalKeys`){if(wy(r)){t.push({permission:n,pattern:`*`,action:r});continue}if(!(!r||typeof r!=`object`||Array.isArray(r)))for(let[e,i]of Object.entries(r))wy(i)&&t.push({permission:n,pattern:e,action:i})}return t},Ey=e=>{let t=Ty(e);for(let e=t.length-1;e>=0;--e){let n=t[e];if(n.permission===`*`&&n.pattern===`*`)return n.action===`ask`;if(n.action===`ask`)return!0}return!0},Dy=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>Ey(e.permission));let r=e.find(e=>e?.name===n);return!r||Ey(r.permission)},Oy=e=>{let{permissionScopeSessionId:t,newSessionDraftOpen:n,draftPermissionAutoAcceptEnabled:r,permissionAutoAcceptEnabled:i,setDraftPermissionAutoAcceptEnabled:a,setSessionAutoAccept:o,onOpenSessionFirst:s,onToggleFailed:c}=e;if(!t){if(!n){s();return}a(!r);return}o(t,!i).catch(c)},ky=null,Ay=new Set,jy=()=>{for(let e of Ay)e()},My=e=>e===`chat`||e===`assistant`,Ny=()=>ky,Py=e=>{ky!==e&&(ky=e,jy())},Fy=e=>{ky&&(e&&ky.surfaceID!==e||(ky=null,jy()))},Iy=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},Ly=e=>{let t={...e.options?.delivery===`steer`?{delivery:`steer`}:{},...e.options?.commitStagedMessageEdit===void 0?{}:{commitStagedMessageEdit:e.options.commitStagedMessageEdit},...e.options?.messageID?{messageID:e.options.messageID}:{},...e.options?.ticket?{ticket:e.options.ticket}:{}},n=e.options?.sessionId??e.sessionID??void 0;if(!n)return t;let r=e.options?.directoryHint===void 0?e.directory||null:e.options.directoryHint;return{...t,sessionId:n,directoryHint:r}},Ry=(e,t,n={})=>({operation:t,surfaceID:e.surfaceID,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration,sessionID:e.sessionID,directory:e.directory??``,draftKey:e.draftKey,deliveryTarget:e.deliveryTarget,...n}),zy=e=>{if(!e.active||!e.draftKey||!e.directory)return null;let t=e.activity?.phase??`idle`,n=e.activity?.canAbort??(t===`busy`||t===`retry`);return{send:async t=>{let n=Ry(e,`send`,t);return await e.selection.flush(),e.kind===`secondary`&&await e.shortcuts.submit(),e.backend.send(n)},sendQueued:async(t,n={})=>{let{manual:r,...i}=n,a=Ry(e,`send`,i),o=qm(e);if(await e.selection.flush(),!o)throw Error(`chat-input-queue-scope-incomplete`);return e.backend.sendQueued({...a,queueItemID:t,manual:r,queueScope:o})},create:async()=>{let t=Ry(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=Ry(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=Ry(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:qm(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>Bm(e,{name:t,source:`openchamber`}),shortcut:async(t,n=1)=>{if(e.kind===`secondary`){t===`cycle`?await e.shortcuts.cycle(n):t===`new`?await e.shortcuts.new():t===`abort`?await e.shortcuts.abort():await e.shortcuts.submit();return}if(t===`abort`){let t=Ry(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=Ry(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},By=(e,t,n)=>{let r=e.agent;r&&r!==t.currentAgentName&&t.setAgent(r),e.providerID&&t.setProvider(e.providerID),e.modelID&&t.setModel(e.modelID),t.setCurrentVariant(e.variant);let i=r??t.currentAgentName;i&&e.providerID&&e.modelID&&t.saveAgentModelSelection(i,e.providerID,e.modelID,e.variant);let a=n?.sessionId,o=n?.memory;!a||!o||!e.providerID||!e.modelID||(o.saveSessionModelSelection(a,e.providerID,e.modelID),i&&o.saveSessionAgentSelection&&o.saveSessionAgentSelection(a,i),i&&(o.saveAgentModelForSession(a,i,e.providerID,e.modelID),o.saveAgentModelVariantForSession(a,i,e.providerID,e.modelID,e.variant)))},Vy=(e,t,n)=>{let r=e.providers.find(e=>e.id===t);return r?(Array.isArray(r.models)?r.models:[]).some(e=>e.id===n):!1},Hy=(e,t)=>e.agents.some(e=>e.name===t),Uy=(e,t,n,r)=>{if(!r)return!0;let i=e.providers.find(e=>e.id===t)?.models?.find(e=>e.id===n)?.variants;return i?Array.isArray(i)?i.includes(r):typeof i==`object`&&Object.prototype.hasOwnProperty.call(i,r):!1},Wy=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return Uy(t,n,r,i)?i:void 0;if(a&&Uy(t,n,r,a))return a},Gy=e=>{let{sessionId:t,choice:n,catalog:r,memory:i,fallbackAgentName:a,source:o}=e;if(!n.providerID||!n.modelID||!Vy(r,n.providerID,n.modelID))return null;let s=n.agent&&Hy(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&Hy(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):a&&Hy(r,a)?a:void 0,c=s?i?.getAgentModelVariantForSession?.(t,s,n.providerID,n.modelID):void 0,l=Wy({catalog:r,providerID:n.providerID,modelID:n.modelID,historyVariant:n.variant,memoryVariant:c});return{agent:s,providerID:n.providerID,modelID:n.modelID,variant:l,source:o,messageId:n.id}},Ky=e=>{let{sessionId:t,latestUserChoice:n,latestExecution:r,catalog:i,memory:a,sessionEntity:o,fallbackAgentName:s,transcriptReady:c=!0}=e;if(c&&r){let e=Gy({sessionId:t,choice:r,catalog:i,memory:a,fallbackAgentName:s,source:`execution`});if(e)return e}if(c&&n){let e=Gy({sessionId:t,choice:n,catalog:i,memory:a,fallbackAgentName:s,source:`history`});if(e)return e}if(c&&a){let e=a.getSessionAgentSelection?.(t)??null,n=e&&Hy(i,e)?e:s&&Hy(i,s)?s:void 0;if(n){let e=a.getAgentModelForSession?.(t,n);if(e&&Vy(i,e.providerId,e.modelId)){let r=a.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=r&&Uy(i,e.providerId,e.modelId,r)?r:void 0;return{agent:n,providerID:e.providerId,modelID:e.modelId,variant:o,source:`session-memory`}}}let r=a.getSessionModelSelection?.(t);if(r&&Vy(i,r.providerId,r.modelId)){let e=n?a.getAgentModelVariantForSession?.(t,n,r.providerId,r.modelId):void 0,o=e&&Uy(i,r.providerId,r.modelId,e)?e:void 0;return{agent:n,providerID:r.providerId,modelID:r.modelId,variant:o,source:`session-memory`}}}let l=o?.model;if(l&&Vy(i,l.providerID,l.id)){let e=a?.getSessionAgentSelection?.(t)??null,n=(o?.agent&&Hy(i,o.agent)?o.agent:void 0)??(e&&Hy(i,e)?e:s&&Hy(i,s)?s:void 0),r=l.variant,c=r&&Uy(i,l.providerID,l.id,r)?r:void 0;return{agent:n,providerID:l.providerID,modelID:l.id,variant:c,source:`session-entity`}}return null},qy=(e,t,n)=>{let r=e.agent;r&&r!==t.currentAgentName&&t.setAgent(r),e.providerID&&t.setProvider(e.providerID),e.modelID&&t.setModel(e.modelID),t.setCurrentVariant(e.variant);let{sessionId:i,memory:a}=n;a.saveSessionModelSelection(i,e.providerID,e.modelID);let o=r??t.currentAgentName;o&&a.saveSessionAgentSelection&&a.saveSessionAgentSelection(i,o),o&&(a.saveAgentModelForSession(i,o,e.providerID,e.modelID),a.saveAgentModelVariantForSession(i,o,e.providerID,e.modelID,e.variant))},Jy=(e,t)=>{if((t?.expectedConfigKey===void 0||t.activeDirectoryKey===t.expectedConfigKey)&&!(!e.currentProviderId||!e.currentModelId))return{providerID:e.currentProviderId,modelID:e.currentModelId,agent:e.currentAgentName,variant:e.currentVariant}},Yy=e=>e.editRevision<=0?!1:e.pinnedHistoryMessageId==null||e.latestHistoryMessageId==null||e.latestHistoryMessageId===e.pinnedHistoryMessageId,Xy=e=>{if(e.captured?.providerID&&e.captured?.modelID)return e.captured;let t=e.surfaceSelection;if(!(!t?.providerID||!t?.modelID))return{providerID:t.providerID,modelID:t.modelID,...t.agent?{agent:t.agent}:{},...t.variant?{variant:t.variant}:{}}},Zy=e=>typeof e==`string`&&e.trim().length>0?e:void 0,Qy=e=>Zy(e.agent)??Zy(e.mode),$y=e=>Zy(e.model?.variant)??Zy(e.variant),eb=e=>{let t=Zy(e.model?.providerID),n=Zy(e.model?.modelID);return!t||!n?null:{providerID:t,modelID:n}},tb=e=>{let t=Zy(e.providerID)??Zy(e.model?.providerID),n=Zy(e.modelID)??Zy(e.model?.modelID);return!t||!n?null:{providerID:t,modelID:n}},nb=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role!==`user`)continue;let r=eb(n);return{id:typeof n.id==`string`?n.id:void 0,agent:Qy(n),providerID:r?.providerID,modelID:r?.modelID,variant:$y(n)}}return null},rb=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role===`user`){if(eb(n))return null;continue}if(n.role!==`assistant`)continue;let r=tb(n);if(r)return{id:typeof n.id==`string`?n.id:void 0,agent:Qy(n),providerID:r.providerID,modelID:r.modelID,variant:$y(n)}}return null},ib=500,ab=e=>Array.from(e).length,ob=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},sb=e=>ab(e)>=ib,cb=e=>{let t=h(e.text,e.references).document.references,n=t.reduce((e,t)=>{let n=t.kind===`paste`?t.index:0;return typeof n==`number`&&Number.isSafeInteger(n)&&n>=1?Math.max(e,n):e},0);if(n<2**53-1)return n+1;let r=new Set(t.flatMap(e=>e.kind===`paste`&&typeof e.index==`number`&&Number.isSafeInteger(e.index)&&e.index>=1?[e.index]:[]));for(let e=1;e<=t.length+1;e+=1)if(!r.has(e))return e;return 1},lb=(e,t)=>{let n=t??e;return typeof n!=`string`||!sb(n)?!1:ae(typeof e==`string`?{text:``,references:[]}:e,n)},ub=(e,t,n,r,i=1)=>{let a=ab(e),o=new Set(n.map(e=>e.token));for(let n=i;n<2**53-1;n+=1){let i=`[${r({index:n,count:a})}]`;if(!(t.includes(i)||o.has(i)))return{id:`pasted-text-${n}-${ob(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},db=e=>({text:e.text,references:e.references.map(e=>({...e}))}),fb=e=>e.map(e=>({...e,range:{...e.range}})),pb=(e,t)=>e.text===t.text&&JSON.stringify(e.references)===JSON.stringify(t.references),mb=(e,t,n)=>({document:db(e),mentions:fb(t),selection:{...n}}),hb=()=>({undo:[],redo:[]}),gb=(e,t)=>({undo:[...e.undo,t].slice(-100),redo:[]}),_b=(e,t)=>{let n=e.undo.at(-1);return!n||!pb(n.after.document,t)?null:{history:{undo:e.undo.slice(0,-1),redo:[...e.redo,n]},snapshot:mb(n.before.document,n.before.mentions,n.before.selection)}},vb=(e,t)=>{let n=e.redo.at(-1);return!n||!pb(n.before.document,t)?null:{history:{undo:[...e.undo,n],redo:e.redo.slice(0,-1)},snapshot:mb(n.after.document,n.after.mentions,n.after.selection)}},yb=e=>({text:e?.text??``,references:e?.composerReferences??[]}),bb=e=>({text:e.text,references:e.references.map(e=>({...e}))}),xb=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),Sb=e=>JSON.stringify([e.text,e.references]),Cb=(e,t)=>e!==null&&t!==null&&ie(e)===t,wb=(e,t,n)=>{let r=e?xb(e):null,i=r?n(r):void 0;return{document:w(yb(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?ie(r):null}},Tb=(e,t,n,r)=>{if(!t||ie(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=Sb(yb(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===Sb(e)?`same-document-metadata`:`external-document`},Eb=(e,t,n)=>{let r=n.newEnd-n.oldEnd;return e.flatMap(e=>{if(e.range.start<n.oldEnd&&e.range.end>n.oldStart)return[];let i=e.range.start>=n.oldEnd?{start:e.range.start+r,end:e.range.end+r}:e.range;return t.text.slice(i.start,i.end)===`@${e.value}`?[{...e,range:i}]:[]})},Db=e=>e.map((e,t)=>({mention:e,index:t})).sort((e,t)=>e.mention.range.start-t.mention.range.start||e.mention.range.end-t.mention.range.end||e.index-t.index).map(({mention:e})=>e),Ob=(e,t,n,r,i=r)=>{let a=f(e,n,r,i);return{document:a.document,mentions:Eb(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},kb=(e,t,n)=>({preview:{real:bb(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),Ab=e=>({document:e.real,mentions:e.realMentions}),jb=(e,t,n,r)=>{let i=[...e,...t.map(e=>({...e,range:{start:e.range.start+r,end:e.range.end+r}}))],a=new Set;return i.filter(e=>{let t=`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`;return a.has(t)||n.text.slice(e.range.start,e.range.end)!==`@${e.value}`?!1:(a.add(t),!0)})},Mb=(e,t)=>{let n=yb(t),r=C(e.document,n),i=e.document.text===n.text&&JSON.stringify(e.document.references)===JSON.stringify(n.references)?0:e.document.text.length+2;return{document:r,mentions:jb(e.mentions,t?.mentions??[],r,i)}},Nb=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=ei})=>{let a=e?ie(e):null,o=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().drafts[a]:void 0,()=>void 0),s=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftHydration[a]??`idle`:`idle`,()=>`idle`),l=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftPersistence[a]:void 0,()=>void 0),[u,d]=(0,Z.useState)(()=>wb(e,t,i.getState().getDraft).document),[p,m]=(0,Z.useState)(()=>wb(e,t,i.getState().getDraft).mentions),[_,v]=(0,Z.useState)(`compose`),[y,b]=(0,Z.useState)(0),x=(0,Z.useRef)(u),S=(0,Z.useRef)(p),C=(0,Z.useRef)(t),E=(0,Z.useRef)(r),O=(0,Z.useRef)(e),k=(0,Z.useRef)(e?xb(e):null),A=(0,Z.useRef)(a),j=(0,Z.useRef)(a),M=(0,Z.useRef)(0),N=(0,Z.useRef)(o?.revision??0),P=(0,Z.useRef)(void 0),F=(0,Z.useRef)(void 0),I=(0,Z.useRef)(hb());x.current=u,S.current=p,C.current=t,E.current=r,O.current=e,A.current=a;let L=(0,Z.useCallback)((e,t)=>{x.current=e,S.current=t,d(e),m(t)},[]),R=(0,Z.useCallback)((e,t)=>{let n=D(e,t);E.current?.(n)},[]);(0,Z.useEffect)(()=>{i.getState().setDraftPersistenceEnabled(n)},[n,i]),(0,Z.useLayoutEffect)(()=>{M.current+=1;let e=M.current;j.current=a;let t=wb(O.current,C.current,i.getState().getDraft),n=t.key;if(k.current=t.key,P.current=void 0,F.current=void 0,I.current=hb(),v(`compose`),N.current=t.revision,L(t.document,t.mentions),b(e=>e+1),n?.owner.kind===`draft`){let r=t.revision;i.getState().claimLegacyNewDraft(n).then(t=>{let o=i.getState().getDraft(n);!t||!Cb(k.current,a)||j.current!==a||A.current!==a||M.current!==e||N.current!==r||o?.revision!==t.revision||(N.current=t.revision,L(w(yb(t),C.current),t.mentions))})}},[a,L,i]),(0,Z.useEffect)(()=>{if(!a||j.current!==a||F.current)return;let e=Tb(x.current,o,P.current,{keyID:a,epoch:M.current,appliedRevision:N.current});if(e!==`ignore`){if(o&&(N.current=o.revision),e===`local-echo`||e===`same-document-metadata`){o&&m(o.mentions);return}e===`external-document`&&o&&(P.current=void 0,L(w(yb(o),C.current),o.mentions),v(`compose`),b(e=>e+1))}},[a,L,o]);let z=(0,Z.useCallback)((e,t)=>{let n=k.current;if(!Cb(n,A.current)||F.current)return;let r=x.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:Db(t)});if(!a)return;let o=yb(a);return P.current={keyID:ie(n),revision:a.revision,fingerprint:Sb(o)},N.current=a.revision,L(o,a.mentions),R(r,o),a},[i,L,R]),B=(0,Z.useCallback)((e,t,n,r,i,a)=>{I.current=gb(I.current,{before:mb(e,t,n),after:mb(r,i,a)})},[]),V=(0,Z.useCallback)(()=>F.current?(F.current=void 0,v(`compose`),!0):!1,[]),H=(0,Z.useCallback)(e=>(V(),z({text:e,references:[]},[])),[z,V]),U=(0,Z.useCallback)((e,t=[])=>{V();let n=te(e.text,e.references);return n?z(w(n,C.current),t):void 0},[z,V]),W=(0,Z.useCallback)((e,t,n=t,r)=>{let i=V(),a=bb(x.current),o=i?[]:S.current,s=Ob(a,o,e,t,n),c=r?r(s.mentions,s.document):s.mentions;return z(s.document,c),s.removedReferences.length>0&&B(a,o,{start:s.selectionStart,end:s.selectionEnd},s.document,c,{start:s.selectionStart,end:s.selectionEnd}),{start:s.selectionStart,end:s.selectionEnd,requiresTextCorrection:s.requiresTextCorrection}},[z,V,B]),ee=(0,Z.useCallback)((e,t)=>{let n=x.current,r=Math.max(0,Math.min(e.start,n.text.length)),i=Math.max(r,Math.min(e.end,n.text.length)),a=V(),o=f(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=Eb(a?[]:S.current,o.document,o.edit);return z(o.document,t?t(s,o.document):s),{start:o.selectionStart,end:o.selectionEnd}},[z,V]),G=(0,Z.useCallback)((e,t)=>{let n=x.current;return ee({start:0,end:n.text.length,text:e},t)},[ee]),K=(0,Z.useCallback)((e,t,n,r)=>{let i=V(),a=c(x.current,e,t,n,r);return z(a.document,Eb(i?[]:S.current,a.document,a.edit)),{start:a.caret,end:a.caret,caret:a.caret,document:a.document}},[z,V]),ne=(0,Z.useCallback)(e=>{let t=bb(x.current),n=g(t,e);if(!n)return null;let r=V()?[]:S.current,i=Eb(r,n.document,n.edit),a=T(n.document.text,n.caret),o=f(n.document,a.text,a.caret),s=Eb(i,o.document,o.edit);return z(o.document,s),B(t,r,{start:e.selectionStart,end:e.selectionEnd},o.document,s,{start:o.selectionStart,end:o.selectionEnd}),{start:o.selectionStart,end:o.selectionEnd}},[z,V,B]),re=(0,Z.useCallback)(e=>{if(F.current)return null;let t=e===`undo`?_b(I.current,x.current):vb(I.current,x.current);return!t||!z(t.snapshot.document,t.snapshot.mentions)?null:(I.current=t.history,t.snapshot.selection)},[z]),ae=(0,Z.useCallback)(e=>z(x.current,e),[z]),oe=(0,Z.useCallback)(e=>{let t=F.current?{document:{text:e.text,references:[]},mentions:[]}:kb(x.current,S.current,e);`preview`in t&&(F.current=t.preview),v(`history-preview`),L(t.document,t.mentions),b(e=>e+1)},[L]),se=(0,Z.useCallback)(()=>{let e=F.current;if(!e)return;F.current=void 0,v(`compose`);let t=Ab(e);L(t.document,t.mentions),b(e=>e+1)},[L]),ce=(0,Z.useCallback)(()=>{let e=k.current;if(!Cb(e,A.current))return null;let t=i.getState().getDraft(e);return{key:xb(e),keyID:ie(e),revision:t?.revision??0,document:bb(x.current),mentions:S.current.map(e=>({...e,range:{...e.range}})),epoch:M.current,runtime:i.getState().captureDraftRuntime()}},[i]),le=(0,Z.useCallback)(e=>{let t=Mb(e,i.getState().getDraft(e.key)),n=yb(i.getState().getDraft(e.key)),r=h(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:Db(t.mentions)});if(a){let e=yb(a);R(r,e)}return a},[R,i]),ue=(0,Z.useCallback)(()=>x.current,[]);return(0,Z.useMemo)(()=>({document:u,mentions:p,confirmedFileMentions:p.filter(e=>e.kind===`file`||e.kind===`directory`),inputMode:_,hydration:s,persistence:l,textPresetEpoch:y,getDocument:ue,replacePlainDocument:H,replaceMaterializedDocument:U,applyBrowserEdit:W,applyProgrammaticEdit:ee,replaceProgrammaticText:G,insertReference:K,deleteReference:ne,restoreReferenceHistory:re,commitMentions:ae,enterHistoryPreview:oe,exitHistoryPreview:se,captureSubmission:ce,recoverSubmission:le}),[W,ee,ce,ae,ne,u,oe,se,ue,s,_,K,p,l,le,U,H,G,re,y])};function Pb(e){let t=e.maxLines??8,n=e.lineHeight*t+e.paddingTotal,r=Math.max(e.scrollHeight,e.dictationHeight);return{height:Math.min(r,n),maxHeight:n,overflowY:r>n?`auto`:`hidden`}}var Fb=`box-border w-full whitespace-pre-wrap break-words px-3 typography-markdown [font-family:inherit] [font-style:inherit] [font-weight:inherit] leading-[inherit] tracking-[inherit] md:typography-ui-label`,Ib=ks(()=>Ue(()=>import(`./ToolOutputDialog-CFFkJzQ4.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48]))),Lb=[],Rb=[],zb=[],Bb=[],Vb=/^@[^\s]+$/,Hb=({inputMode:e,message:t,showCommandAutocomplete:n,showSkillAutocomplete:r})=>e!==`shell`&&(n||r||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),Ub=/^(https?:\/\/|mailto:)\S+$/i,Wb=560,Gb=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),Kb=(e,t)=>{if(e===t)return``;let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n+=1;let r=e.length,i=t.length;for(;r>n&&i>n&&e[r-1]===t[i-1];)--r,--i;return t.slice(n,i)},qb=e=>e.includes(`@`)?`paste`:`manual`,Jb=(e,t)=>{let n=t,r=t;for(;n>0&&/\s/.test(e[n-1]);)--n;for(;r<e.length&&/\s/.test(e[r]);)r+=1;let i=n>0&&r<e.length?` `:``;return{text:`${e.slice(0,n)}${i}${e.slice(r)}`,caret:n+i.length}},Yb=(e,t)=>ur(e,t).some(e=>e.role===`user`),Xb=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!Wn(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
6524
+ `);if(d.trim()&&(t.push({start:s,end:s+d.length,style:`codeFence`,className:`${Nv} text-[var(--syntax-foreground)]`,priority:Pv}),!(d.length>Bv)))try{let e=o.parser.parse(d);Xe(e,Rv,(e,n,r)=>{let i=zv(r);i&&t.push({start:s+e,end:s+n,style:`codeFence`,className:i,priority:Fv})})}catch{}}return t}var Uv=[`CodeFiles`,`codefiles`,`application/vnd.code.tree`,`application/vnd.code.tree.explorer`,`text/uri-list`,`text/plain`],Wv=e=>e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`\\\\`)||/^[A-Za-z]:[\\/]/.test(e),Gv=e=>{if(!Wv(e)||/\s/.test(e))return!1;if(e.startsWith(`//`)||e.startsWith(`\\\\`)){let t=e.replace(/^[\\/]+/,``);return/[\\/]/.test(t)}if(/^[A-Za-z]:[\\/]/.test(e)){let t=e.slice(3);return t.includes(`\\`)||t.includes(`/`)||t.includes(`.`)}return e.replace(/^\/+/,``).includes(`/`)},Kv=(e,{fromPlainText:t=!1}={})=>{let n=e.trim().replace(/^['"]+|['"]+$/g,``);return!n||n===`/>`||/[\r\n]/.test(n)?null:n.toLowerCase().startsWith(`file://`)||(t?Gv(n):Wv(n))?n:null},qv=(e,t,n=0)=>{if(!(n>6||e==null)){if(typeof e==`string`){t.add(e);return}if(Array.isArray(e)){for(let r of e)qv(r,t,n+1);return}if(typeof e==`object`)for(let r of Object.values(e))qv(r,t,n+1)}},Jv=(e,{allowMultipleLines:t=!0,allowStructuredPayload:n=!0,fromPlainText:r=!1}={})=>{let i=new Set,a=e=>{let n=Kv(e,{fromPlainText:r});if(n){i.add(n);return}if(t)for(let t of e.split(/\r?\n/)){let e=Kv(t,{fromPlainText:r});e&&i.add(e)}};if(a(e),n)try{let t=JSON.parse(e),n=new Set;qv(t,n);for(let e of n)a(e)}catch{}return Array.from(i)},Yv=e=>{if(!e||typeof e.getData!=`function`)return[];let t=new Set;for(let n of Uv){let r=``;try{r=e.getData(n)}catch{continue}let i=n===`text/plain`?{allowMultipleLines:!1,allowStructuredPayload:!1,fromPlainText:!0}:n===`text/uri-list`?{allowStructuredPayload:!1}:void 0;for(let e of Jv(r,i))t.add(e)}return Array.from(t)},Xv=e=>{let t=e.trim();if(!t.toLowerCase().startsWith(`file://`))return t;try{let e=new URL(t),n=decodeURIComponent(e.pathname||``);return e.hostname&&e.hostname!==`localhost`&&(n=`//${e.hostname}${n}`),/^\/[A-Za-z]:\//.test(n)&&(n=n.slice(1)),n||t}catch{let e=t.replace(/^file:\/\//i,``);try{return decodeURIComponent(e)}catch{return e}}},Zv=e=>Wv(e);function Qv(e,t){let n=(0,Q.c)(5),r=_t(e,t),i=q($v),a;n[0]===r?a=n[1]:(a=sn(r),n[0]=r,n[1]=a);let o;return n[2]!==i||n[3]!==a?(o={goal:a,enabled:i},n[2]=i,n[3]=a,n[4]=o):o=n[4],o}function $v(e){return e.sessionGoalEnabled}function ey(e,t){let n=(0,Q.c)(4),[r,i]=Z.useState(null),a=t?.objectiveFile?`${e}:${t.id}:${t.updatedAt}`:``,o,s;return n[0]!==a||n[1]!==e?(o=()=>{if(!a){i(null);return}let t=!0;return Mt(e).then(e=>{t&&i(e)}),()=>{t=!1}},s=[a,e],n[0]=a,n[1]=e,n[2]=o,n[3]=s):(o=n[2],s=n[3]),Z.useEffect(o,s),t?t.objectiveFile?r:t.objective:null}var ty={active:`var(--status-info)`,paused:`var(--surface-muted-foreground)`,blocked:`var(--status-warning)`,budgetLimited:`var(--status-warning)`,complete:`var(--status-success)`},ny={active:`chat.goal.status.active`,paused:`chat.goal.status.paused`,blocked:`chat.goal.status.blocked`,budgetLimited:`chat.goal.status.budgetLimited`,complete:`chat.goal.status.complete`},ry=Z.memo(({sessionId:e,directory:t,className:n})=>{let{t:r}=ct(),i=q(e=>e.isMobile),{goal:a,enabled:o}=Qv(e??``,t),s=ey(e??``,a),c=Fi(e??``,t),l=En(e,t),u=Z.useRef(null),[d,f]=Z.useState(!1),[p,m]=Z.useState(()=>Date.now());Z.useEffect(()=>{if(!a||a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`)return;let e=window.setInterval(()=>m(Date.now()),1e3);return()=>window.clearInterval(e)},[a?.id,a?.status]),Z.useEffect(()=>{if(!e||!a||a.status!==`active`)return;let n=l[0]?.id;if(!n)return;let r=`${e}:${a.id}:${n}`;u.current!==r&&(u.current=r,Ot(e,t))},[e,t,a,l]);let h=J(async n=>{if(!(!e||d)){f(!0);try{await hn(e,t,n)}catch(e){console.warn(`[session-goal] status change failed:`,e),Br.error(r(`chat.goal.toast.actionFailed`))}finally{f(!1)}}});if(!e||!o||!a)return null;let g=Math.max(0,(a.status===`complete`||a.status===`blocked`||a.status===`budgetLimited`?a.updatedAt:p)-(a.createdAt||p)),_=vt(g),v=a.tokenBudget?`${Gr(a.tokensUsed)}/${Gr(a.tokenBudget)}`:a.tokensUsed>0?Gr(a.tokensUsed):null,y=a.status===`active`?{icon:`pause`,labelKey:`chat.goal.action.pause`,next:`paused`}:a.status===`paused`||a.status===`blocked`||a.status===`budgetLimited`?{icon:`play`,labelKey:`chat.goal.action.resume`,next:`active`}:null,b=i?`text-[11px] leading-none text-muted-foreground`:`typography-meta text-muted-foreground`,x=i?`text-xs leading-5 text-foreground`:`typography-ui-label leading-5 text-foreground`,S=i?`size-3`:`size-3.5`;return(0,$.jsxs)(`div`,{className:Y(`flex w-full min-w-0 items-center`,i?`gap-1 py-0.5`:`gap-1.5 py-0.5 md:gap-2`,n),"aria-label":r(`chat.goal.row.aria`),title:s??void 0,children:[(0,$.jsx)(X,{name:`target`,className:Y(S,`flex-shrink-0`),style:{color:ty[a.status]},"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`min-w-0 flex-1 truncate`,x),children:a.note||s||``}),a.status===`active`&&(!c||c.type===`idle`)?(0,$.jsxs)(`span`,{className:Y(`flex flex-shrink-0 items-center gap-1`,b),children:[(0,$.jsx)(X,{name:`loader-4`,className:Y(S,`animate-spin`),"aria-hidden":`true`}),r(`chat.goal.status.evaluating`)]}):(0,$.jsx)(`span`,{className:Y(`flex-shrink-0`,b),children:r(ny[a.status])}),(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,b,`text-muted-foreground/70`),children:_}),v?(0,$.jsx)(`span`,{className:Y(`flex-shrink-0 tabular-nums`,b,`text-muted-foreground/70`),children:v}):null,y?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void h(y.next),disabled:d,className:Y(`inline-flex flex-shrink-0 cursor-pointer items-center bg-transparent text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,i?`h-7 gap-1.5 px-0 text-[11px]`:`h-7 gap-1 px-0.5`),"aria-label":r(y.labelKey),children:[(0,$.jsx)(X,{name:y.icon,className:S,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:Y(`font-medium`,i?`leading-none`:`typography-ui-label`),children:r(y.labelKey)})]}):null]})});ry.displayName=`SessionGoalRow`;var iy=Z.memo(({sessionId:e,directory:t,draftOpen:n=!1})=>{let{t:r}=ct(),{goal:i,enabled:a}=Qv(e??``,t),o=yn(e=>e.armed),s=yn(e=>e.setArmed),[c,l]=Z.useState(!1);if(se()||!a||!e&&!n||!o&&!i)return null;let u=i?.status===`complete`?`text-[var(--status-success)]`:i?.status===`blocked`||i?.status===`budgetLimited`?`text-[var(--status-error)]`:o||i?.status===`active`||i?.status===`paused`?`text-[var(--status-info)]`:``,d=async()=>{if(o){s(!1);return}if(!(!e||c)){l(!0);try{await Ln(e,t)}catch(e){console.warn(`[session-goal] clear failed:`,e),Br.error(r(`chat.goal.toast.actionFailed`))}finally{l(!1)}}};return(0,$.jsxs)(`span`,{className:Y(`inline-flex h-7 items-center gap-1 rounded-full bg-[var(--surface-muted)] py-1 pl-2 pr-1 typography-ui-label`,u),children:[(0,$.jsx)(X,{name:`target`,className:`h-4 w-4`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:r(`chat.goal.chip.label`)}),(0,$.jsx)(`button`,{type:`button`,className:`flex h-5 w-5 items-center justify-center rounded-full text-current hover:bg-[var(--interactive-hover)] disabled:opacity-50`,onClick:()=>void d(),disabled:c,"aria-label":r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),title:r(o?`chat.goal.button.disarmAria`:`chat.goal.action.clear`),children:(0,$.jsx)(X,{name:`close`,className:`h-3 w-3`,"aria-hidden":`true`})})]})});iy.displayName=`SessionGoalButton`;var ay=Z.memo(e=>{let t=(0,Q.c)(11),{length:n}=e,{t:r}=ct();if(!yn(oy)||n===0)return null;let i=n>5e3?`text-[var(--status-error)]`:`text-muted-foreground/70`,a;t[0]===i?a=t[1]:(a=Y(`flex-shrink-0 self-center typography-micro tabular-nums`,i),t[0]=i,t[1]=a);let o;t[2]===r?o=t[3]:(o=r(`chat.goal.counter.aria`),t[2]=r,t[3]=o);let s;t[4]===r?s=t[5]:(s=r(`chat.goal.counter.aria`),t[4]=r,t[5]=s);let c;return t[6]!==n||t[7]!==a||t[8]!==o||t[9]!==s?(c=(0,$.jsxs)(`span`,{className:a,"aria-label":o,title:s,children:[n,`/`,Xr]}),t[6]=n,t[7]=a,t[8]=o,t[9]=s,t[10]=c):c=t[10],c});ay.displayName=`SessionGoalObjectiveCounter`;function oy(e){return e.armed}var sy=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`timeline`,`model`,`summary`,`workspace-review`,`handoff-review`,`goal`,`craft-goal`,`catch-up`,`debug`,`weigh`,`explore`]),cy=new Set([`new`,`compact`,`fork`,`undo`,`redo`]),ly=/^\/\u2003?([^\s]+)/i,uy=/^\/\u2003?goal\b/i,dy=(e,t)=>{if(t!==`normal`)return null;let n=e.trimStart().match(ly)?.[1]?.toLowerCase();return n&&sy.has(n)?n:null},fy=(e,t)=>dy(e,t)===`goal`?e.trimStart().replace(uy,``).trim():null,py=(e,t)=>dy(e,t)!==null,my=(e,t)=>{let n=dy(e,t);return n!==null&&cy.has(n)},hy=({currentSessionId:e,messageRef:t,replacePlainDocument:n})=>{let r=e;return t.current=``,n(``),r},gy=async({command:e,consumeCommandText:t,forkSession:n,waitForConnection:r,getDirectoryForSession:i,summarizeSession:a,onCompactError:o,onForkError:s})=>{if(t(),e===`fork`){try{await n()}catch(e){s(e)}return}try{await r();let e=i();if(!e){o();return}await a(e)}catch{o()}},_y=e=>!e.queuedOnly&&!e.resourcePolicy&&e.rootAttachmentCount>0,vy=e=>e.surfaceKind===`primary`&&!!e.currentSessionId&&!e.queuedOnly&&!e.resourcePolicy&&e.inputMode!==`shell`&&!e.localCommand,yy=e=>e.surfaceKind!==`primary`||!e.stagedSessionId||!e.stagedMessageId||e.stagedMessageId!==e.blurredMessageId||e.submitInFlight||e.focusHeld||e.overlayOpen||e.focusInsideComposer?{action:`keep`}:{action:`disarm`,sessionId:e.stagedSessionId},by=e=>({state:`bound`,transportIdentity:e.transportIdentity,directory:e.directory,sessionID:e.sessionID,deliveryTarget:{kind:`primary`},runtimeGeneration:e.runtimeGeneration}),xy=(e,t)=>{let n=b.getState();return n.bindLegacyQueue(v(e.sessionID),e),n.stageAdmission(e,{requestID:t.requestID,queueItemID:t.queueItemID,operationID:t.operationID,messageID:t.messageID,content:t.content,createdAt:t.createdAt,attachmentCount:t.attachments.length,...t.composerDocument?{composerDocument:t.composerDocument}:{},...t.composerMentions?{composerMentions:t.composerMentions}:{}}),n.confirmAdmission(e,{requestID:t.requestID,sendConfig:t.sendConfig,attachments:t.attachments}).ok},Sy=async e=>{let t=mn.getState().takeEstablishingPending(e.draftID);if(t.length===0)return{drained:0,failed:0};let n=by(e),r=0,i=0;for(let a of t)try{if(e.admitServer&&(await e.admitServer(a)).status===`committed`){r+=1;continue}xy(n,a)?r+=1:i+=1}catch{try{xy(n,a)?r+=1:i+=1}catch{i+=1}}return{drained:r,failed:i}},Cy=(e,t)=>Promise.resolve().then(()=>e()).catch(()=>{t()}),wy=e=>e===`allow`||e===`ask`||e===`deny`,Ty=e=>{if(wy(e))return[{permission:`*`,pattern:`*`,action:e}];if(Array.isArray(e))return e.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e;return typeof t.permission==`string`&&typeof t.pattern==`string`&&wy(t.action)?[{permission:t.permission,pattern:t.pattern,action:t.action}]:[]});if(!e||typeof e!=`object`)return[];let t=[];for(let[n,r]of Object.entries(e))if(n!==`__originalKeys`){if(wy(r)){t.push({permission:n,pattern:`*`,action:r});continue}if(!(!r||typeof r!=`object`||Array.isArray(r)))for(let[e,i]of Object.entries(r))wy(i)&&t.push({permission:n,pattern:e,action:i})}return t},Ey=e=>{let t=Ty(e);for(let e=t.length-1;e>=0;--e){let n=t[e];if(n.permission===`*`&&n.pattern===`*`)return n.action===`ask`;if(n.action===`ask`)return!0}return!0},Dy=(e,t)=>{let n=t?.trim();if(!n)return e.length===0||e.some(e=>Ey(e.permission));let r=e.find(e=>e?.name===n);return!r||Ey(r.permission)},Oy=e=>{let{permissionScopeSessionId:t,newSessionDraftOpen:n,draftPermissionAutoAcceptEnabled:r,permissionAutoAcceptEnabled:i,setDraftPermissionAutoAcceptEnabled:a,setSessionAutoAccept:o,onOpenSessionFirst:s,onToggleFailed:c}=e;if(!t){if(!n){s();return}a(!r);return}o(t,!i).catch(c)},ky=null,Ay=new Set,jy=()=>{for(let e of Ay)e()},My=e=>e===`chat`||e===`assistant`,Ny=()=>ky,Py=e=>{ky!==e&&(ky=e,jy())},Fy=e=>{ky&&(e&&ky.surfaceID!==e||(ky=null,jy()))},Iy=(e,t)=>{if(e.transportIdentity!==t.transportIdentity||e.runtimeGeneration!==t.runtimeGeneration)throw Error(`chat-input-delivery-runtime-stale`)},Ly=e=>{let t={...e.options?.delivery===`steer`?{delivery:`steer`}:{},...e.options?.commitStagedMessageEdit===void 0?{}:{commitStagedMessageEdit:e.options.commitStagedMessageEdit},...e.options?.messageID?{messageID:e.options.messageID}:{},...e.options?.ticket?{ticket:e.options.ticket}:{}},n=e.options?.sessionId??e.sessionID??void 0;if(!n)return t;let r=e.options?.directoryHint===void 0?e.directory||null:e.options.directoryHint;return{...t,sessionId:n,directoryHint:r}},Ry=(e,t,n={})=>({operation:t,surfaceID:e.surfaceID,transportIdentity:e.transportIdentity,runtimeGeneration:e.runtimeGeneration,sessionID:e.sessionID,directory:e.directory??``,draftKey:e.draftKey,deliveryTarget:e.deliveryTarget,...n}),zy=e=>{if(!e.active||!e.draftKey||!e.directory)return null;let t=e.activity?.phase??`idle`,n=e.activity?.canAbort??(t===`busy`||t===`retry`);return{send:async t=>{let n=Ry(e,`send`,t);return await e.selection.flush(),e.kind===`secondary`&&await e.shortcuts.submit(),e.backend.send(n)},sendQueued:async(t,n={})=>{let{manual:r,...i}=n,a=Ry(e,`send`,i),o=qm(e);if(await e.selection.flush(),!o)throw Error(`chat-input-queue-scope-incomplete`);return e.backend.sendQueued({...a,queueItemID:t,manual:r,queueScope:o})},create:async()=>{let t=Ry(e,`create`);return await e.selection.flush(),e.backend.create(t)},compact:async t=>{let n=Ry(e,`compact`,t);return await e.selection.flush(),e.backend.compact(n)},abort:async()=>{let t=Ry(e,`abort`);return await e.selection.flush(),e.backend.abort(t)},queueScope:qm(e),canAbort:n,canQueue:t===`busy`||t===`retry`,allowsCommand:t=>Bm(e,{name:t,source:`openchamber`}),shortcut:async(t,n=1)=>{if(e.kind===`secondary`){t===`cycle`?await e.shortcuts.cycle(n):t===`new`?await e.shortcuts.new():t===`abort`?await e.shortcuts.abort():await e.shortcuts.submit();return}if(t===`abort`){let t=Ry(e,`abort`);await e.selection.flush(),await e.backend.abort(t);return}if(t===`new`){let t=Ry(e,`create`);await e.selection.flush(),await e.backend.create(t);return}t!==`submit`&&await e.shortcuts?.cycle(n)},resources:e.resources??null}},By=(e,t,n)=>{let r=e.agent;r&&r!==t.currentAgentName&&t.setAgent(r),e.providerID&&t.setProvider(e.providerID),e.modelID&&t.setModel(e.modelID),t.setCurrentVariant(e.variant);let i=r??t.currentAgentName;i&&e.providerID&&e.modelID&&t.saveAgentModelSelection(i,e.providerID,e.modelID,e.variant);let a=n?.sessionId,o=n?.memory;!a||!o||!e.providerID||!e.modelID||(o.saveSessionModelSelection(a,e.providerID,e.modelID),i&&o.saveSessionAgentSelection&&o.saveSessionAgentSelection(a,i),i&&(o.saveAgentModelForSession(a,i,e.providerID,e.modelID),o.saveAgentModelVariantForSession(a,i,e.providerID,e.modelID,e.variant)))},Vy=(e,t,n)=>{let r=e.providers.find(e=>e.id===t);return r?(Array.isArray(r.models)?r.models:[]).some(e=>e.id===n):!1},Hy=(e,t)=>e.agents.some(e=>e.name===t),Uy=(e,t,n,r)=>{if(!r)return!0;let i=e.providers.find(e=>e.id===t)?.models?.find(e=>e.id===n)?.variants;return i?Array.isArray(i)?i.includes(r):typeof i==`object`&&Object.prototype.hasOwnProperty.call(i,r):!1},Wy=e=>{let{catalog:t,providerID:n,modelID:r,historyVariant:i,memoryVariant:a}=e;if(i)return Uy(t,n,r,i)?i:void 0;if(a&&Uy(t,n,r,a))return a},Gy=e=>{let{sessionId:t,choice:n,catalog:r,memory:i,fallbackAgentName:a,source:o}=e;if(!n.providerID||!n.modelID||!Vy(r,n.providerID,n.modelID))return null;let s=n.agent&&Hy(r,n.agent)?n.agent:i?.getSessionAgentSelection?.(t)&&Hy(r,i.getSessionAgentSelection(t))?i.getSessionAgentSelection(t):a&&Hy(r,a)?a:void 0,c=s?i?.getAgentModelVariantForSession?.(t,s,n.providerID,n.modelID):void 0,l=Wy({catalog:r,providerID:n.providerID,modelID:n.modelID,historyVariant:n.variant,memoryVariant:c});return{agent:s,providerID:n.providerID,modelID:n.modelID,variant:l,source:o,messageId:n.id}},Ky=e=>{let{sessionId:t,latestUserChoice:n,latestExecution:r,catalog:i,memory:a,sessionEntity:o,fallbackAgentName:s,transcriptReady:c=!0}=e;if(c&&r){let e=Gy({sessionId:t,choice:r,catalog:i,memory:a,fallbackAgentName:s,source:`execution`});if(e)return e}if(c&&n){let e=Gy({sessionId:t,choice:n,catalog:i,memory:a,fallbackAgentName:s,source:`history`});if(e)return e}if(c&&a){let e=a.getSessionAgentSelection?.(t)??null,n=e&&Hy(i,e)?e:s&&Hy(i,s)?s:void 0;if(n){let e=a.getAgentModelForSession?.(t,n);if(e&&Vy(i,e.providerId,e.modelId)){let r=a.getAgentModelVariantForSession?.(t,n,e.providerId,e.modelId),o=r&&Uy(i,e.providerId,e.modelId,r)?r:void 0;return{agent:n,providerID:e.providerId,modelID:e.modelId,variant:o,source:`session-memory`}}}let r=a.getSessionModelSelection?.(t);if(r&&Vy(i,r.providerId,r.modelId)){let e=n?a.getAgentModelVariantForSession?.(t,n,r.providerId,r.modelId):void 0,o=e&&Uy(i,r.providerId,r.modelId,e)?e:void 0;return{agent:n,providerID:r.providerId,modelID:r.modelId,variant:o,source:`session-memory`}}}let l=o?.model;if(l&&Vy(i,l.providerID,l.id)){let e=a?.getSessionAgentSelection?.(t)??null,n=(o?.agent&&Hy(i,o.agent)?o.agent:void 0)??(e&&Hy(i,e)?e:s&&Hy(i,s)?s:void 0),r=l.variant,c=r&&Uy(i,l.providerID,l.id,r)?r:void 0;return{agent:n,providerID:l.providerID,modelID:l.id,variant:c,source:`session-entity`}}return null},qy=(e,t,n)=>{let r=e.agent;r&&r!==t.currentAgentName&&t.setAgent(r),e.providerID&&t.setProvider(e.providerID),e.modelID&&t.setModel(e.modelID),t.setCurrentVariant(e.variant);let{sessionId:i,memory:a}=n;a.saveSessionModelSelection(i,e.providerID,e.modelID);let o=r??t.currentAgentName;o&&a.saveSessionAgentSelection&&a.saveSessionAgentSelection(i,o),o&&(a.saveAgentModelForSession(i,o,e.providerID,e.modelID),a.saveAgentModelVariantForSession(i,o,e.providerID,e.modelID,e.variant))},Jy=(e,t)=>{if((t?.expectedConfigKey===void 0||t.activeDirectoryKey===t.expectedConfigKey)&&!(!e.currentProviderId||!e.currentModelId))return{providerID:e.currentProviderId,modelID:e.currentModelId,agent:e.currentAgentName,variant:e.currentVariant}},Yy=e=>e.editRevision<=0?!1:e.pinnedHistoryMessageId==null||e.latestHistoryMessageId==null||e.latestHistoryMessageId===e.pinnedHistoryMessageId,Xy=e=>{if(e.captured?.providerID&&e.captured?.modelID)return e.captured;let t=e.surfaceSelection;if(!(!t?.providerID||!t?.modelID))return{providerID:t.providerID,modelID:t.modelID,...t.agent?{agent:t.agent}:{},...t.variant?{variant:t.variant}:{}}},Zy=e=>typeof e==`string`&&e.trim().length>0?e:void 0,Qy=e=>Zy(e.agent)??Zy(e.mode),$y=e=>Zy(e.model?.variant)??Zy(e.variant),eb=e=>{let t=Zy(e.model?.providerID),n=Zy(e.model?.modelID);return!t||!n?null:{providerID:t,modelID:n}},tb=e=>{let t=Zy(e.providerID)??Zy(e.model?.providerID),n=Zy(e.modelID)??Zy(e.model?.modelID);return!t||!n?null:{providerID:t,modelID:n}},nb=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role!==`user`)continue;let r=eb(n);return{id:typeof n.id==`string`?n.id:void 0,agent:Qy(n),providerID:r?.providerID,modelID:r?.modelID,variant:$y(n)}}return null},rb=e=>{for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role===`user`){if(eb(n))return null;continue}if(n.role!==`assistant`)continue;let r=tb(n);if(r)return{id:typeof n.id==`string`?n.id:void 0,agent:Qy(n),providerID:r.providerID,modelID:r.modelID,variant:$y(n)}}return null},ib=500,ab=e=>Array.from(e).length,ob=e=>{let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return(t>>>0).toString(36)},sb=e=>ab(e)>=ib,cb=e=>{let t=h(e.text,e.references).document.references,n=t.reduce((e,t)=>{let n=t.kind===`paste`?t.index:0;return typeof n==`number`&&Number.isSafeInteger(n)&&n>=1?Math.max(e,n):e},0);if(n<2**53-1)return n+1;let r=new Set(t.flatMap(e=>e.kind===`paste`&&typeof e.index==`number`&&Number.isSafeInteger(e.index)&&e.index>=1?[e.index]:[]));for(let e=1;e<=t.length+1;e+=1)if(!r.has(e))return e;return 1},lb=(e,t)=>{let n=t??e;return typeof n!=`string`||!sb(n)?!1:ae(typeof e==`string`?{text:``,references:[]}:e,n)},ub=(e,t,n,r,i=1)=>{let a=ab(e),o=new Set(n.map(e=>e.token));for(let n=i;n<2**53-1;n+=1){let i=`[${r({index:n,count:a})}]`;if(!(t.includes(i)||o.has(i)))return{id:`pasted-text-${n}-${ob(e)}`,token:i,text:e,characterCount:a,index:n}}throw Error(`Unable to create a unique pasted text reference`)},db=e=>({text:e.text,references:e.references.map(e=>({...e}))}),fb=e=>e.map(e=>({...e,range:{...e.range}})),pb=(e,t)=>e.text===t.text&&JSON.stringify(e.references)===JSON.stringify(t.references),mb=(e,t,n)=>({document:db(e),mentions:fb(t),selection:{...n}}),hb=()=>({undo:[],redo:[]}),gb=(e,t)=>({undo:[...e.undo,t].slice(-100),redo:[]}),_b=(e,t)=>{let n=e.undo.at(-1);return!n||!pb(n.after.document,t)?null:{history:{undo:e.undo.slice(0,-1),redo:[...e.redo,n]},snapshot:mb(n.before.document,n.before.mentions,n.before.selection)}},vb=(e,t)=>{let n=e.redo.at(-1);return!n||!pb(n.before.document,t)?null:{history:{undo:[...e.undo,n],redo:e.redo.slice(0,-1)},snapshot:mb(n.after.document,n.after.mentions,n.after.selection)}},yb=e=>({text:e?.text??``,references:e?.composerReferences??[]}),bb=e=>({text:e.text,references:e.references.map(e=>({...e}))}),xb=e=>({transportIdentity:e.transportIdentity,owner:{...e.owner}}),Sb=e=>JSON.stringify([e.text,e.references]),Cb=(e,t)=>e!==null&&t!==null&&ie(e)===t,wb=(e,t,n)=>{let r=e?xb(e):null,i=r?n(r):void 0;return{document:w(yb(i),t),mentions:i?.mentions??[],revision:i?.revision??0,key:r,keyID:r?ie(r):null}},Tb=(e,t,n,r)=>{if(!t||ie(t.key)!==r.keyID||t.revision<r.appliedRevision)return`ignore`;let i=Sb(yb(t));return n?.keyID===r.keyID&&n.revision===t.revision&&n.fingerprint===i?`local-echo`:t.revision===r.appliedRevision?`ignore`:i===Sb(e)?`same-document-metadata`:`external-document`},Eb=(e,t,n)=>{let r=n.newEnd-n.oldEnd;return e.flatMap(e=>{if(e.range.start<n.oldEnd&&e.range.end>n.oldStart)return[];let i=e.range.start>=n.oldEnd?{start:e.range.start+r,end:e.range.end+r}:e.range;return t.text.slice(i.start,i.end)===`@${e.value}`?[{...e,range:i}]:[]})},Db=e=>e.map((e,t)=>({mention:e,index:t})).sort((e,t)=>e.mention.range.start-t.mention.range.start||e.mention.range.end-t.mention.range.end||e.index-t.index).map(({mention:e})=>e),Ob=(e,t,n,r,i=r)=>{let a=f(e,n,r,i);return{document:a.document,mentions:Eb(t,a.document,a.edit),requiresTextCorrection:a.requiresTextCorrection,selectionStart:a.selectionStart,selectionEnd:a.selectionEnd,removedReferences:a.removedReferences}},kb=(e,t,n)=>({preview:{real:bb(e),realMentions:[...t]},document:{text:n.text,references:[]},mentions:[]}),Ab=e=>({document:e.real,mentions:e.realMentions}),jb=(e,t,n,r)=>{let i=[...e,...t.map(e=>({...e,range:{start:e.range.start+r,end:e.range.end+r}}))],a=new Set;return i.filter(e=>{let t=`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`;return a.has(t)||n.text.slice(e.range.start,e.range.end)!==`@${e.value}`?!1:(a.add(t),!0)})},Mb=(e,t)=>{let n=yb(t),r=C(e.document,n),i=e.document.text===n.text&&JSON.stringify(e.document.references)===JSON.stringify(n.references)?0:e.document.text.length+2;return{document:r,mentions:jb(e.mentions,t?.mentions??[],r,i)}},Nb=({draftKey:e,sessionTitles:t,persistenceEnabled:n,onResourcesChanged:r,store:i=ei})=>{let a=e?ie(e):null,o=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().drafts[a]:void 0,()=>void 0),s=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftHydration[a]??`idle`:`idle`,()=>`idle`),l=(0,Z.useSyncExternalStore)(i.subscribe,()=>a?i.getState().draftPersistence[a]:void 0,()=>void 0),[u,d]=(0,Z.useState)(()=>wb(e,t,i.getState().getDraft).document),[p,m]=(0,Z.useState)(()=>wb(e,t,i.getState().getDraft).mentions),[_,v]=(0,Z.useState)(`compose`),[y,b]=(0,Z.useState)(0),x=(0,Z.useRef)(u),S=(0,Z.useRef)(p),C=(0,Z.useRef)(t),E=(0,Z.useRef)(r),O=(0,Z.useRef)(e),k=(0,Z.useRef)(e?xb(e):null),A=(0,Z.useRef)(a),j=(0,Z.useRef)(a),M=(0,Z.useRef)(0),N=(0,Z.useRef)(o?.revision??0),P=(0,Z.useRef)(void 0),F=(0,Z.useRef)(void 0),I=(0,Z.useRef)(hb());x.current=u,S.current=p,C.current=t,E.current=r,O.current=e,A.current=a;let L=(0,Z.useCallback)((e,t)=>{x.current=e,S.current=t,d(e),m(t)},[]),R=(0,Z.useCallback)((e,t)=>{let n=D(e,t);E.current?.(n)},[]);(0,Z.useEffect)(()=>{i.getState().setDraftPersistenceEnabled(n)},[n,i]),(0,Z.useLayoutEffect)(()=>{M.current+=1;let e=M.current;j.current=a;let t=wb(O.current,C.current,i.getState().getDraft),n=t.key;if(k.current=t.key,P.current=void 0,F.current=void 0,I.current=hb(),v(`compose`),N.current=t.revision,L(t.document,t.mentions),b(e=>e+1),n?.owner.kind===`draft`){let r=t.revision;i.getState().claimLegacyNewDraft(n).then(t=>{let o=i.getState().getDraft(n);!t||!Cb(k.current,a)||j.current!==a||A.current!==a||M.current!==e||N.current!==r||o?.revision!==t.revision||(N.current=t.revision,L(w(yb(t),C.current),t.mentions))})}},[a,L,i]),(0,Z.useEffect)(()=>{if(!a||j.current!==a||F.current)return;let e=Tb(x.current,o,P.current,{keyID:a,epoch:M.current,appliedRevision:N.current});if(e!==`ignore`){if(o&&(N.current=o.revision),e===`local-echo`||e===`same-document-metadata`){o&&m(o.mentions);return}e===`external-document`&&o&&(P.current=void 0,L(w(yb(o),C.current),o.mentions),v(`compose`),b(e=>e+1))}},[a,L,o]);let z=(0,Z.useCallback)((e,t)=>{let n=k.current;if(!Cb(n,A.current)||F.current)return;let r=x.current,a=i.getState().setDraftComposerState(n,{document:e,mentions:Db(t)});if(!a)return;let o=yb(a);return P.current={keyID:ie(n),revision:a.revision,fingerprint:Sb(o)},N.current=a.revision,L(o,a.mentions),R(r,o),a},[i,L,R]),B=(0,Z.useCallback)((e,t,n,r,i,a)=>{I.current=gb(I.current,{before:mb(e,t,n),after:mb(r,i,a)})},[]),V=(0,Z.useCallback)(()=>F.current?(F.current=void 0,v(`compose`),!0):!1,[]),H=(0,Z.useCallback)(e=>(V(),z({text:e,references:[]},[])),[z,V]),U=(0,Z.useCallback)((e,t=[])=>{V();let n=te(e.text,e.references);return n?z(w(n,C.current),t):void 0},[z,V]),W=(0,Z.useCallback)((e,t,n=t,r)=>{let i=V(),a=bb(x.current),o=i?[]:S.current,s=Ob(a,o,e,t,n),c=r?r(s.mentions,s.document):s.mentions;return z(s.document,c),s.removedReferences.length>0&&B(a,o,{start:s.selectionStart,end:s.selectionEnd},s.document,c,{start:s.selectionStart,end:s.selectionEnd}),{start:s.selectionStart,end:s.selectionEnd,requiresTextCorrection:s.requiresTextCorrection}},[z,V,B]),ee=(0,Z.useCallback)((e,t)=>{let n=x.current,r=Math.max(0,Math.min(e.start,n.text.length)),i=Math.max(r,Math.min(e.end,n.text.length)),a=V(),o=f(n,`${n.text.slice(0,r)}${e.text}${n.text.slice(i)}`,r+e.text.length),s=Eb(a?[]:S.current,o.document,o.edit);return z(o.document,t?t(s,o.document):s),{start:o.selectionStart,end:o.selectionEnd}},[z,V]),G=(0,Z.useCallback)((e,t)=>{let n=x.current;return ee({start:0,end:n.text.length,text:e},t)},[ee]),K=(0,Z.useCallback)((e,t,n,r)=>{let i=V(),a=c(x.current,e,t,n,r);return z(a.document,Eb(i?[]:S.current,a.document,a.edit)),{start:a.caret,end:a.caret,caret:a.caret,document:a.document}},[z,V]),ne=(0,Z.useCallback)(e=>{let t=bb(x.current),n=g(t,e);if(!n)return null;let r=V()?[]:S.current,i=Eb(r,n.document,n.edit),a=T(n.document.text,n.caret),o=f(n.document,a.text,a.caret),s=Eb(i,o.document,o.edit);return z(o.document,s),B(t,r,{start:e.selectionStart,end:e.selectionEnd},o.document,s,{start:o.selectionStart,end:o.selectionEnd}),{start:o.selectionStart,end:o.selectionEnd}},[z,V,B]),re=(0,Z.useCallback)(e=>{if(F.current)return null;let t=e===`undo`?_b(I.current,x.current):vb(I.current,x.current);return!t||!z(t.snapshot.document,t.snapshot.mentions)?null:(I.current=t.history,t.snapshot.selection)},[z]),ae=(0,Z.useCallback)(e=>z(x.current,e),[z]),oe=(0,Z.useCallback)(e=>{let t=F.current?{document:{text:e.text,references:[]},mentions:[]}:kb(x.current,S.current,e);`preview`in t&&(F.current=t.preview),v(`history-preview`),L(t.document,t.mentions),b(e=>e+1)},[L]),se=(0,Z.useCallback)(()=>{let e=F.current;if(!e)return;F.current=void 0,v(`compose`);let t=Ab(e);L(t.document,t.mentions),b(e=>e+1)},[L]),ce=(0,Z.useCallback)(()=>{let e=k.current;if(!Cb(e,A.current))return null;let t=i.getState().getDraft(e);return{key:xb(e),keyID:ie(e),revision:t?.revision??0,document:bb(x.current),mentions:S.current.map(e=>({...e,range:{...e.range}})),epoch:M.current,runtime:i.getState().captureDraftRuntime()}},[i]),le=(0,Z.useCallback)(e=>{let t=Mb(e,i.getState().getDraft(e.key)),n=yb(i.getState().getDraft(e.key)),r=h(n.text,n.references).document,a=i.getState().setDraftComposerState(e.key,{...t,mentions:Db(t.mentions)});if(a){let e=yb(a);R(r,e)}return a},[R,i]),ue=(0,Z.useCallback)(()=>x.current,[]);return(0,Z.useMemo)(()=>({document:u,mentions:p,confirmedFileMentions:p.filter(e=>e.kind===`file`||e.kind===`directory`),inputMode:_,hydration:s,persistence:l,textPresetEpoch:y,getDocument:ue,replacePlainDocument:H,replaceMaterializedDocument:U,applyBrowserEdit:W,applyProgrammaticEdit:ee,replaceProgrammaticText:G,insertReference:K,deleteReference:ne,restoreReferenceHistory:re,commitMentions:ae,enterHistoryPreview:oe,exitHistoryPreview:se,captureSubmission:ce,recoverSubmission:le}),[W,ee,ce,ae,ne,u,oe,se,ue,s,_,K,p,l,le,U,H,G,re,y])};function Pb(e){let t=e.maxLines??8,n=e.lineHeight*t+e.paddingTotal,r=Math.max(e.scrollHeight,e.dictationHeight);return{height:Math.min(r,n),maxHeight:n,overflowY:r>n?`auto`:`hidden`}}var Fb=`box-border w-full whitespace-pre-wrap break-words px-3 typography-markdown [font-family:inherit] [font-style:inherit] [font-weight:inherit] leading-[inherit] tracking-[inherit] md:typography-ui-label`,Ib=ks(()=>Ue(()=>import(`./ToolOutputDialog-BI5vwuaT.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48]))),Lb=[],Rb=[],zb=[],Bb=[],Vb=/^@[^\s]+$/,Hb=({inputMode:e,message:t,showCommandAutocomplete:n,showSkillAutocomplete:r})=>e!==`shell`&&(n||r||/(^|\s)\/[A-Za-z0-9_-]*/.test(t)),Ub=/^(https?:\/\/|mailto:)\S+$/i,Wb=560,Gb=(e,t)=>e.name===t?e:new File([e],t,{type:e.type,lastModified:e.lastModified}),Kb=(e,t)=>{if(e===t)return``;let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n+=1;let r=e.length,i=t.length;for(;r>n&&i>n&&e[r-1]===t[i-1];)--r,--i;return t.slice(n,i)},qb=e=>e.includes(`@`)?`paste`:`manual`,Jb=(e,t)=>{let n=t,r=t;for(;n>0&&/\s/.test(e[n-1]);)--n;for(;r<e.length&&/\s/.test(e[r]);)r+=1;let i=n>0&&r<e.length?` `:``;return{text:`${e.slice(0,n)}${i}${e.slice(r)}`,caret:n+i.length}},Yb=(e,t)=>ur(e,t).some(e=>e.role===`user`),Xb=(e,t)=>{let n=e.filter(e=>e.type===`text`&&!Wn(e)).map(e=>{let t=e;return typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:``}).join(`
6525
6525
  `).replace(/\s+/g,` `).trim();if(n)return n;let r=e.find(e=>e.type===`file`);return r?.filename?`[${r.filename}]`:t},Zb=`file://`,Qb=e=>{let t=e.replace(/\\/g,`/`);return/^[A-Za-z]:/.test(t)&&(t=`/${t}`),t.split(`/`).map((e,t)=>t===1&&/^[A-Za-z]:$/.test(e)?e:encodeURIComponent(e)).join(`/`)},$b=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(Zb)?t:`file://${Qb(t)}`},ex=e=>{if(!e)return[];let t=[...Yv(e).map(Xv),...Array.from(e.files||[]).map(e=>oe(e)).filter(e=>!!e)];return Array.from(new Set(t.filter(Zv)))},tx=e=>{if(typeof e!=`string`)return null;let t=e.trim();if(!t)return null;let n=t.replace(/\\/g,`/`);return n===`/`?`/`:n.length>1?n.replace(/\/+$/,``):n},nx=e=>ca(e.path),rx=(e,t)=>{if(!t)return e;let n=e.indexOf(t);return n===-1?e:(0,$.jsxs)($.Fragment,{children:[e.slice(0,n),(0,$.jsx)(`span`,{className:`font-medium`,children:t}),e.slice(n+t.length)]})},ix=Z.memo(ph),ax=Z.memo(ru),ox=Z.memo(Dg),sx=Z.memo(Ag),cx=Z.memo(Uh),lx=Z.memo(({sessionId:e,directory:t})=>{let{t:n}=ct(),r=q(e=>e.isMobile),i=ri(e=>e.revertToMessage),a=ri(e=>e.forkFromMessage),o=ri(e=>e.handleSlashRedo),[s,c]=Z.useState(null),[l,u]=Z.useState(null),[d,f]=Z.useState(!0),p=Z.useRef(hv),m=Ir(),h=t||m,g=Vt(h),_=br(e??``,h,g),v=tn(e=>e.session,h),y=Z.useMemo(()=>{let t=_.messageOrder.map(e=>_.messagesByID[e]).filter(e=>!!e),n=vv({session:v,messages:t,partsByMessageID:_.partsByMessageID},e,p.current);return p.current=n,n},[e,v,_]),b=y.revertMessageID,x=Z.useMemo(()=>y.records.map(e=>e.message),[y]),S=n(`chat.revertPopover.noTextContent`),C=Z.useMemo(()=>b?y.records.map(e=>({id:e.message.id,text:Xb(e.parts,S)})):[],[S,b,y]),w=C[0]?.id;Z.useEffect(()=>{f(!0)},[b,w]);let T=Z.useCallback(async t=>{if(!(!e||s)){c(t);try{let n=x.find(e=>e.id>t);n?await i(e,n.id,{skipRedoPush:!0}):await o(e,{fullUnrevert:!0})}finally{c(null)}}},[o,i,s,e,x]),E=Z.useCallback(async t=>{if(!(!e||l)){u(t);try{await a(e,t)}finally{u(null)}}},[a,l,e]);return!e||C.length===0?null:(0,$.jsx)(`div`,{className:Y(`w-full px-1`,r?`pb-1 text-xs`:`pb-2`),children:(0,$.jsxs)(`div`,{className:Y(`border border-border/60 bg-[var(--surface-elevated)] text-[var(--surface-elevated-foreground)] shadow-sm dark:shadow-none overflow-hidden`,r?`rounded-lg`:`rounded-xl`),children:[(0,$.jsxs)(`button`,{type:`button`,className:Y(`flex w-full items-center text-left hover:bg-[var(--interactive-hover)] transition-colors`,r?`gap-1.5 px-2 py-1`:`gap-2 px-3 py-2`),onClick:()=>f(e=>!e),"aria-expanded":!d,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium text-foreground flex-shrink-0`,children:[n(`chat.revertPopover.title`),` messages `,C.length]}),(0,$.jsx)(X,{name:`arrow-down-s`,className:Y(`ml-auto text-muted-foreground transition-transform`,r?`size-3.5`:`size-4`,!d&&`rotate-180`),"aria-hidden":`true`})]}),!d&&(0,$.jsx)(`div`,{className:Y(`flex flex-col overflow-y-auto`,r?`max-h-[8rem] gap-1 px-2 pb-1.5`:`max-h-[10.5rem] gap-1.5 px-3 pb-3`),children:C.map(e=>(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 items-center`,r?`gap-1.5`:`gap-2 py-1`),children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate typography-ui-label text-foreground`,children:e.text}),(0,$.jsxs)(ua,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||l),onClick:()=>{E(e.id)},children:[l===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`git-branch`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.fork`)]}),(0,$.jsxs)(ua,{type:`button`,variant:`secondary`,size:`xs`,disabled:!!(s||l),onClick:()=>{T(e.id)},children:[s===e.id?(0,$.jsx)(X,{name:`loader-4`,className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):(0,$.jsx)(X,{name:`arrow-go-forward`,className:`h-3 w-3`,"aria-hidden":`true`}),n(`chat.revertPopover.restore`)]})]},e.id))})]})})});lx.displayName=`RevertedMessageDock`;var ux=Z.memo(function(e){let t=(0,Q.c)(41),{t:n}=ct(),{isVSCode:r,footerIconButtonClass:i,iconSizeClass:a,handlePickLocalFiles:o,openIssuePicker:s,openPrPicker:c,onOpenSettings:l,withTooltip:u}=e,d=u!==void 0&&u,f=!!e.onOpenMobileSheet,p;t[0]===n?p=t[1]:(p=n(`chat.chatInput.actions.attachFiles`),t[0]=n,t[1]=p);let m=p,h=o,g;t[2]!==h||t[3]!==e?(g=()=>e.onOpenAndroidPickSheet?e.onOpenAndroidPickSheet():h(),t[2]=h,t[3]=e,t[4]=g):g=t[4];let _=f?bx:void 0,v=f?xx:void 0,y;t[5]===a?y=t[6]:(y=Y(a,`text-current`),t[5]=a,t[6]=y);let b;t[7]===y?b=t[8]:(b=(0,$.jsx)(X,{name:`attachment-2`,className:y}),t[7]=y,t[8]=b);let x;t[9]!==m||t[10]!==i||t[11]!==g||t[12]!==_||t[13]!==v||t[14]!==b?(x=(0,$.jsx)(`button`,{type:`button`,className:i,onClick:g,onMouseDown:_,onPointerDownCapture:v,title:m,"aria-label":m,children:b}),t[9]=m,t[10]=i,t[11]=g,t[12]=_,t[13]=v,t[14]=b,t[15]=x):x=t[15];let S=x,C;t[16]!==S||t[17]!==m||t[18]!==d?(C=d?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:S}),(0,$.jsx)(Ua,{side:`top`,sideOffset:8,children:m})]}):S,t[16]=S,t[17]=m,t[18]=d,t[19]=C):C=t[19];let w;t[20]!==i||t[21]!==o||t[22]!==a||t[23]!==r||t[24]!==s||t[25]!==c||t[26]!==e.onMenuOpenChange||t[27]!==e.onOpenMobileSheet||t[28]!==n?(w=null,t[20]=i,t[21]=o,t[22]=a,t[23]=r,t[24]=s,t[25]=c,t[26]=e.onMenuOpenChange,t[27]=e.onOpenMobileSheet,t[28]=n,t[29]=w):w=t[29];let T;t[30]!==C||t[31]!==w?(T=(0,$.jsxs)(`div`,{className:`relative inline-flex`,children:[C,w]}),t[30]=C,t[31]=w,t[32]=T):T=t[32];let E;t[33]!==i||t[34]!==a||t[35]!==l||t[36]!==n?(E=l?(0,$.jsx)(`button`,{type:`button`,onClick:l,className:i,title:n(`chat.chatInput.actions.modelAgentSettings`),"aria-label":n(`chat.chatInput.actions.modelAgentSettings`),children:(0,$.jsx)(X,{name:`ai-agent`,className:Y(a,`text-current`)})}):null,t[33]=i,t[34]=a,t[35]=l,t[36]=n,t[37]=E):E=t[37];let D;return t[38]!==T||t[39]!==E?(D=(0,$.jsxs)(`div`,{className:`flex items-center gap-x-1.5`,children:[T,E]}),t[38]=T,t[39]=E,t[40]=D):D=t[40],D},(e,t)=>e.isVSCode===t.isVSCode&&e.footerIconButtonClass===t.footerIconButtonClass&&e.iconSizeClass===t.iconSizeClass&&e.onOpenSettings===t.onOpenSettings&&e.onMenuOpenChange===t.onMenuOpenChange&&e.onOpenMobileSheet===t.onOpenMobileSheet&&e.onOpenAndroidPickSheet===t.onOpenAndroidPickSheet&&e.withTooltip===t.withTooltip),dx=Z.memo(function(e){let t=(0,Q.c)(29),{t:n}=ct(),r=e.enabled?`chat.chatInput.permissionAutoAccept.disable`:`chat.chatInput.permissionAutoAccept.enable`,i;t[0]!==n||t[1]!==r?(i=n(r),t[0]=n,t[1]=r,t[2]=i):i=t[2];let a=i,o=e.saving,s=e.enabled,c=e.footerIconButtonClass,l;t[3]!==e.draftEnabled||t[4]!==e.draftOpen||t[5]!==e.enabled||t[6]!==e.onOpenSessionFirst||t[7]!==e.onSetDraftEnabled||t[8]!==e.onSetSessionEnabled||t[9]!==e.onToggleFailed||t[10]!==e.sessionId?(l=()=>Oy({permissionScopeSessionId:e.sessionId,newSessionDraftOpen:e.draftOpen,draftPermissionAutoAcceptEnabled:e.draftEnabled,permissionAutoAcceptEnabled:e.enabled,setDraftPermissionAutoAcceptEnabled:e.onSetDraftEnabled,setSessionAutoAccept:e.onSetSessionEnabled,onOpenSessionFirst:e.onOpenSessionFirst,onToggleFailed:e.onToggleFailed}),t[3]=e.draftEnabled,t[4]=e.draftOpen,t[5]=e.enabled,t[6]=e.onOpenSessionFirst,t[7]=e.onSetDraftEnabled,t[8]=e.onSetSessionEnabled,t[9]=e.onToggleFailed,t[10]=e.sessionId,t[11]=l):l=t[11];let u=e.enabled?`shield-check`:`shield`,d;t[12]===e.iconSizeClass?d=t[13]:(d=Y(e.iconSizeClass,`text-current`),t[12]=e.iconSizeClass,t[13]=d);let f;t[14]!==u||t[15]!==d?(f=(0,$.jsx)(X,{name:u,className:d}),t[14]=u,t[15]=d,t[16]=f):f=t[16];let p;t[17]!==a||t[18]!==e.enabled||t[19]!==e.footerIconButtonClass||t[20]!==e.saving||t[21]!==l||t[22]!==f?(p=(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,disabled:o,"aria-pressed":s,"aria-label":a,className:c,onClick:l,onMouseDown:Sx,onPointerDownCapture:Cx,children:f})}),t[17]=a,t[18]=e.enabled,t[19]=e.footerIconButtonClass,t[20]=e.saving,t[21]=l,t[22]=f,t[23]=p):p=t[23];let m;t[24]===a?m=t[25]:(m=(0,$.jsx)(Ua,{side:`top`,sideOffset:8,children:a}),t[24]=a,t[25]=m);let h;return t[26]!==m||t[27]!==p?(h=(0,$.jsxs)(Wa,{children:[p,m]}),t[26]=m,t[27]=p,t[28]=h):h=t[28],h}),fx=Z.memo(function(e){let t=(0,Q.c)(67),{isMobile:n,compact:r,footerIconButtonClass:i,stopFooterIconButtonClass:a,compactCircleButtonClass:o,sendIconSizeClass:s,stopIconSizeClass:c,canSend:l,canAbort:u,hasContent:d,currentSessionId:f,newSessionDraftOpen:p,draftSubmitting:m,submissionBlocked:h,sendPhase:g,queueFrozen:_,queueFallbackAvailable:v,onPrimaryAction:y,onAbort:b}=e,x=r!==void 0&&r,{t:S}=ct(),C,w,T,E,D;if(t[0]!==u||t[1]!==l||t[2]!==x||t[3]!==o||t[4]!==f||t[5]!==m||t[6]!==i||t[7]!==d||t[8]!==n||t[9]!==p||t[10]!==y||t[11]!==v||t[12]!==_||t[13]!==s||t[14]!==g||t[15]!==a||t[16]!==c||t[17]!==h||t[18]!==S){D=Symbol.for(`react.early_return_sentinel`);bb0:{let e=Kg({canSend:l,hasSessionTarget:!!(f||p),draftSubmitting:!!m,submissionBlocked:h,sendPhase:g,queueFrozen:_,queueFallbackAvailable:v}),r;t[24]===n?r=t[25]:(r=n?{onMouseDown:wx,onPointerDownCapture:Tx}:{},t[24]=n,t[25]=r);let b=r,O=g.inFlight,k=O&&g.flightKind===`queue`,A=O&&g.flightKind!==`queue`,j;t[26]!==u||t[27]!==v||t[28]!==_||t[29]!==k||t[30]!==A||t[31]!==S?(j=S(k?`chat.chatInput.actions.queuingMessageAria`:A?`chat.chatInput.actions.sendingMessageAria`:_&&v&&u?`chat.chatInput.actions.sendMessageAria`:u?`chat.chatInput.actions.queueMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[26]=u,t[27]=v,t[28]=_,t[29]=k,t[30]=A,t[31]=S,t[32]=j):j=t[32];let M=j;C=x?o??a??i:a??i,w=c;let N=!u&&(!e.sendDisabled||O),P;t[33]!==n||t[34]!==y?(P=e=>{n&&(e.preventDefault(),y())},t[33]=n,t[34]=y,t[35]=P):P=t[35];let F;t[36]!==u||t[37]!==O||t[38]!==k||t[39]!==A||t[40]!==S?(F=S(A||!u&&O?k?`chat.chatInput.actions.queuingMessageAria`:`chat.chatInput.actions.sendingMessageAria`:`chat.chatInput.actions.sendMessageAria`),t[36]=u,t[37]=O,t[38]=k,t[39]=A,t[40]=S,t[41]=F):F=t[41];let I;t[42]!==u||t[43]!==w||t[44]!==O||t[45]!==s||t[46]!==N?(I=N?(0,$.jsx)(zg,{className:w,spinning:!!(O&&!u)}):(0,$.jsx)(X,{name:`send-plane-2`,className:s}),t[42]=u,t[43]=w,t[44]=O,t[45]=s,t[46]=N,t[47]=I):I=t[47];let L=(0,$.jsx)(`button`,{type:n?`button`:`submit`,"data-composer-send":`true`,"data-composer-circle":N?`true`:void 0,disabled:e.sendDisabled,"aria-busy":O||void 0,...b,onClick:P,className:Y(N?C:i,N?void 0:e.sendDisabled?e.disabledClass:`text-primary hover:text-primary`),"aria-label":F,children:I});if(!u){D=L;break bb0}let R=!x&&(d||k),z=!e.sendDisabled&&!k,B=x&&`h-full`;t[48]===B?T=t[49]:(T=Y(`relative z-30 overflow-visible`,B),t[48]=B,t[49]=T),E=R?(0,$.jsx)(`button`,{type:`button`,"data-composer-send":`true`,"data-composer-circle":z||k?`true`:void 0,disabled:e.sendDisabled||k,"aria-busy":k||void 0,...b,onClick:e=>{e.preventDefault(),!k&&y()},className:Y(z||k?C:i,`absolute z-30 bottom-full left-1/2 -translate-x-1/2 mb-1`,z||k?void 0:e.disabledClass),"aria-label":M,children:z||k?(0,$.jsx)(zg,{className:w,spinning:k}):(0,$.jsx)(X,{name:`send-plane-2`,className:s})}):null}t[0]=u,t[1]=l,t[2]=x,t[3]=o,t[4]=f,t[5]=m,t[6]=i,t[7]=d,t[8]=n,t[9]=p,t[10]=y,t[11]=v,t[12]=_,t[13]=s,t[14]=g,t[15]=a,t[16]=c,t[17]=h,t[18]=S,t[19]=C,t[20]=w,t[21]=T,t[22]=E,t[23]=D}else C=t[19],w=t[20],T=t[21],E=t[22],D=t[23];if(D!==Symbol.for(`react.early_return_sentinel`))return D;let O;t[50]===C?O=t[51]:(O=Y(C,`relative z-30`),t[50]=C,t[51]=O);let k;t[52]===S?k=t[53]:(k=S(`chat.chatInput.actions.stopGeneratingAria`),t[52]=S,t[53]=k);let A;t[54]===w?A=t[55]:(A=Y(w),t[54]=w,t[55]=A);let j;t[56]===A?j=t[57]:(j=(0,$.jsx)(Rg,{className:A}),t[56]=A,t[57]=j);let M;t[58]!==b||t[59]!==O||t[60]!==k||t[61]!==j?(M=(0,$.jsx)(`button`,{type:`button`,"data-composer-stop":`true`,onClick:b,className:O,"aria-label":k,children:j}),t[58]=b,t[59]=O,t[60]=k,t[61]=j,t[62]=M):M=t[62];let N;return t[63]!==T||t[64]!==E||t[65]!==M?(N=(0,$.jsxs)(`div`,{className:T,children:[E,M]}),t[63]=T,t[64]=E,t[65]=M,t[66]=N):N=t[66],N},(e,t)=>e.isMobile===t.isMobile&&e.compact===t.compact&&e.footerIconButtonClass===t.footerIconButtonClass&&e.stopFooterIconButtonClass===t.stopFooterIconButtonClass&&e.compactCircleButtonClass===t.compactCircleButtonClass&&e.sendIconSizeClass===t.sendIconSizeClass&&e.stopIconSizeClass===t.stopIconSizeClass&&e.canSend===t.canSend&&e.canAbort===t.canAbort&&e.hasContent===t.hasContent&&e.currentSessionId===t.currentSessionId&&e.newSessionDraftOpen===t.newSessionDraftOpen&&e.draftSubmitting===t.draftSubmitting&&e.submissionBlocked===t.submissionBlocked&&e.sendPhase===t.sendPhase&&e.queueFrozen===t.queueFrozen&&e.queueFallbackAvailable===t.queueFallbackAvailable&&e.onPrimaryAction===t.onPrimaryAction&&e.onAbort===t.onAbort),px=(e,t)=>`${e}${e?e.endsWith(`
6526
6526
 
6527
6527
  `)?``:e.endsWith(`
@@ -6571,7 +6571,7 @@ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{c as t,f as n,i as r,n
6571
6571
 
6572
6572
  `):HE(Array.from(t.childNodes).map(e=>qE(e)).join(``))},XE=e=>Array.from(e.childNodes).every(e=>{if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return!0;let t=e;return!BE.has(t.tagName.toLowerCase())}),ZE=(e,t)=>{let n=e.cloneContents();if(XE(n)){let e=HE(Array.from(n.childNodes).map(e=>qE(e)).join(``));if(e)return e}return Array.from(n.childNodes).map(e=>YE(e)).filter(e=>e.length>0).join(`
6573
6573
 
6574
- `).trim()||HE(t)},QE=({containerRef:e})=>{let{t}=ct(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),[o,s]=Z.useState(``),c=Z.useRef(!1),[l,u]=Z.useState(!1),d=Z.useRef(null),f=Z.useRef(RE),p=Z.useRef(null),m=Z.useRef(null),h=Z.useRef(null),g=Z.useRef(!1),_=ri(e=>e.createSession),v=ei(e=>e.setPendingInputText),y=q(e=>e.isMobile),b=zh(Rh()).textSelectionMutation;Z.useEffect(()=>{g.current=n.show},[n.show]),Z.useEffect(()=>()=>{m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null),h.current!==null&&(window.clearTimeout(h.current),h.current=null)},[]);let x=Z.useCallback(()=>{p.current=null,zE===x&&(zE=null),g.current&&=(m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null),u(!1),r(e=>({...e,show:!1})),a(``),s(``),!1)},[]);Z.useEffect(()=>()=>{zE===x&&(zE=null)},[x]);let S=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=f.current/2,r=LE+n,i=t-LE-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),C=Z.useCallback(()=>{if(!p.current)return;zE!==x&&(zE?.(),zE=x);let{plainText:e,markdownText:t,rect:i}=p.current,o=!n.show,c=y?i.left+i.width/2:S(i.left+i.width/2),l=i.top-10;a(e),s(t),r({x:c,y:l,show:!0}),g.current=!0,o&&(u(!0),m.current!==null&&window.cancelAnimationFrame(m.current),m.current=window.requestAnimationFrame(()=>{u(!1),m.current=null}))},[S,x,y,n.show]);Z.useLayoutEffect(()=>{if(!n.show||y||!d.current)return;let e=d.current.offsetWidth;!Number.isFinite(e)||e<=0||e===f.current||(f.current=e,r(e=>({...e,x:S(e.x)})))},[S,y,n.show]),Z.useEffect(()=>{if(!n.show||y)return;let e=()=>{r(e=>({...e,x:S(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[S,y,n.show]);let w=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){c.current||x();return}let r=HE(t.toString());if(!r){c.current||x();return}let i=GE(t,n);if(!i){c.current||x();return}let a=i.getBoundingClientRect();p.current={plainText:r,markdownText:ZE(i,r),rect:a},c.current||C()},[e,x,C]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{c.current=!0,x()},r=()=>{c.current=!1,h.current!==null&&window.clearTimeout(h.current),h.current=window.setTimeout(()=>{h.current=null,w()},10)},i=new Set,a=()=>{for(let e of WE(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,w))};a();let o=new MutationObserver(a);o.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,w),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let s=e=>{d.current&&!d.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&x()};return document.addEventListener(`mousedown`,s),()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null),o.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,w);document.removeEventListener(`selectionchange`,w),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,s)}},[e,w,x,C]),Z.useEffect(()=>{if(!n.show)return;let e=e=>{d.current&&e.target instanceof Node&&d.current.contains(e.target)||x()};return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),()=>{window.removeEventListener(`scroll`,e,!0)}},[n.show,x]);let T=Z.useCallback(e=>{if(!e)return;let t=`\`\`\`md\n${e}\n\`\`\``;v(t,`append`),x(),window.getSelection()?.removeAllRanges()},[v,x]),E=Z.useCallback(()=>{T(o)},[T,o]);Z.useEffect(()=>{let t=t=>{if(!b||!t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||t.key.toLowerCase()!==`i`)return;let n=window.getSelection(),r=e.current;if(!n||!r||!n.toString().trim())return;let i=GE(n,r);i&&(t.preventDefault(),T(ZE(i,n.toString())))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[T,b,e]);let D=Z.useCallback(async()=>{i&&(await _(void 0,null,null)&&v(i,`replace`),x(),window.getSelection()?.removeAllRanges())},[i,_,v,x]),O=Z.useCallback(async()=>{if(!i)return;let e=await ut(i);e.ok||console.error(`Failed to copy:`,e.error),x(),window.getSelection()?.removeAllRanges()},[i,x]);return n.show?y?(0,rl.createPortal)((0,$.jsx)(`div`,{ref:d,className:Y(`fixed left-3 right-3 bottom-0 z-50 mx-auto max-w-[420px]`,`rounded-2xl border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] p-2 shadow-lg`,`safe-area-bottom`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,l?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),style:{bottom:`calc(0.5rem + env(safe-area-inset-bottom, 0px))`},children:(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[b?(0,$.jsxs)(`button`,{onClick:E,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--primary-base)] text-[var(--primary-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.addToChat`)})]}):null,b?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.newSession`)})]}):null,(0,$.jsxs)(`button`,{onClick:O,className:Y(`col-span-2 flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):(0,rl.createPortal)((0,$.jsx)(`div`,{ref:d,className:`fixed z-50`,style:{left:n.x,top:n.y,transform:`translate(-50%, -100%)`},children:(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1 whitespace-nowrap`,`rounded-lg border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] shadow-none`,`px-1.5 py-1`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,l?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),children:[b?(0,$.jsxs)(`button`,{onClick:E,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.addToChat`)}),(0,$.jsx)(Zp,{shortcut:`⌘+I`})]}):null,b?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,b?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.newSession`)})]}):null,b?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):null},$E=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),eD=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),$E(e,n)},tD=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),nD=(e,t)=>{if(!tD(e))return``;let n=new Date(e),r=new Date,i=co(n,t),a=lt(),o=dt.getState().dictionary;if($E(n,r))return i;if(eD(n,r))return ft(o,`common.date.yesterdayWithTime`,{time:i});let s=`${n.toLocaleString(a,{month:`short`})} ${n.getDate()}`;return n.getFullYear()===r.getFullYear()?`${s}, ${i}`:`${s}, ${n.getFullYear()}, ${i}`},rD=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,iD=e=>e,aD=e=>{if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let n of e){let e=iD(n);if(e.type!==`tool`)continue;let r=e.state,i=r?.time?.start,a=r?.time?.end;typeof i!=`number`||!Number.isFinite(i)||typeof a!=`number`||!Number.isFinite(a)||a<i||(t+=a-i)}return t},oD=(e,t,n,r)=>{let i=(typeof e==`number`&&Number.isFinite(e)&&e>0&&typeof t==`number`&&Number.isFinite(t)&&t>e?t-e:null)??(typeof r==`number`&&Number.isFinite(r)&&r>0?r:null);if(i===null)return null;let a=i-aD(n);return!Number.isFinite(a)||a<=0?null:a},sD=e=>{let t=oD(e.createdAt,e.completedAt,e.parts,e.fallbackDurationMs);if(t===null)return null;let n=rD(e.outputTokens)+rD(e.reasoningTokens);if(n<=0)return null;let r=t/1e3;if(r<=0)return null;let i=n/r;return!Number.isFinite(i)||i<=0?null:i},cD=e=>{if(!Number.isFinite(e)||e<=0)return``;if(e>=1e3){let t=e/1e3;return`${t>=10?t.toFixed(0):t.toFixed(1)}k tok/s`}return e>=100?`${Math.round(e)} tok/s`:e>=10?`${e.toFixed(1)} tok/s`:`${e.toFixed(2)} tok/s`},lD=e=>{let t=(0,Q.c)(20),{text:n,active:r,className:i}=e,a=Z.useRef(n),[o,s]=Z.useState(n),[c,l]=Z.useState(null),u,d;t[0]!==r||t[1]!==n?(u=()=>{if(n===a.current)return;let e=a.current;if(a.current=n,!r||e.length===0){l(null),s(n);return}l(e),s(n)},d=[r,n],t[0]=r,t[1]=n,t[2]=u,t[3]=d):(u=t[2],d=t[3]),Z.useEffect(u,d);let f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>{l(null)},t[4]=f):f=t[4];let p=J(f),m;t[5]===i?m=t[6]:(m=Y(`oc-summary-flip-viewport relative block h-5 min-h-0 w-full min-w-0 max-w-full overflow-clip sm:h-6`,i),t[5]=i,t[6]=m);let h=c&&`invisible`,g;t[7]===h?g=t[8]:(g=Y(`block h-full min-w-0 truncate leading-5 sm:leading-6`,h),t[7]=h,t[8]=g);let _;t[9]!==o||t[10]!==g?(_=(0,$.jsx)(`span`,{className:g,children:o}),t[9]=o,t[10]=g,t[11]=_):_=t[11];let v;t[12]!==o||t[13]!==p||t[14]!==c?(v=c?(0,$.jsxs)(`span`,{className:`oc-summary-flip-stage absolute inset-0 block overflow-clip`,children:[(0,$.jsx)(`span`,{className:`oc-summary-flip-out absolute inset-x-0 top-0 block h-full truncate`,"aria-hidden":`true`,children:c}),(0,$.jsx)(`span`,{className:`oc-summary-flip-in absolute inset-x-0 top-0 block h-full truncate`,onAnimationEnd:p,children:o})]}):null,t[12]=o,t[13]=p,t[14]=c,t[15]=v):v=t[15];let y;return t[16]!==m||t[17]!==_||t[18]!==v?(y=(0,$.jsxs)(`span`,{className:m,children:[_,v]}),t[16]=m,t[17]=_,t[18]=v,t[19]=y):y=t[19],y},uD=[`search`,`read`,`list`];function dD(e){let t=dw(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function fD(e){let t={read:0,search:0,list:0};for(let n of e){let e=dD(n);e&&(t[e]+=1)}return t}var pD=[`edit`,`command`,`other`],mD=new Set([`edit`,`multiedit`,`write`,`create`,`file_write`,`apply_patch`,`patch`]),hD=new Set([`bash`,`shell`,`cmd`,`command`,`exec`,`terminal`]);function gD(e){if(!sw(e))return null;let t=dw(e);return mD.has(t)?`edit`:hD.has(t)?`command`:`other`}function _D(e){let t={edit:0,command:0,other:0};for(let n of e){let e=gD(n);e&&(t[e]+=1)}return t}function vD(e){return PC(e)}var yD=[...uD,...pD];function bD(e){return{...fD(e),..._D(e)}}function xD(e){return uw(e)}function SD(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!cw(e.toolName):e.kind!=null||e.type!=null}function CD(e,t,n){for(let r=t;r<e.length;r+=1)if(SD(n(e[r])))return!0;return!1}function wD(e){return`parts`in e?e.parts.some(e=>xD(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>xD(e))}function TD(e,t,n){let r=[],i=t;for(;i<e.length&&cw(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var ED=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,DD=e=>{let t=(0,Q.c)(12),{added:n,removed:r}=e;if(n<=0&&r<=0)return null;let i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=Y(`inline-flex flex-none items-center gap-0.5 tabular-nums`,ED),t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=n>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,n]}):null,t[1]=n,t[2]=a);let o;t[3]!==n||t[4]!==r?(o=n>0&&r>0?(0,$.jsx)(`span`,{style:{color:`var(--tools-description)`},children:`/`}):null,t[3]=n,t[4]=r,t[5]=o):o=t[5];let s;t[6]===r?s=t[7]:(s=r>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,r]}):null,t[6]=r,t[7]=s);let c;return t[8]!==a||t[9]!==o||t[10]!==s?(c=(0,$.jsxs)(`span`,{className:i,children:[a,o,s]}),t[8]=a,t[9]=o,t[10]=s,t[11]=c):c=t[11],c},OD=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=ct(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??wD({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=bD(u.map(e=>e.tool)),p=vD(u),m=yD.filter(e=>f[e]>0).map(e=>{let t=f[e];return o(e===`search`?t===1?`chat.contextGroup.searchSingle`:`chat.contextGroup.searchPlural`:e===`read`?t===1?`chat.contextGroup.readSingle`:`chat.contextGroup.readPlural`:e===`list`?t===1?`chat.contextGroup.listSingle`:`chat.contextGroup.listPlural`:e===`edit`?t===1?`chat.usedGroup.editSingle`:`chat.usedGroup.editPlural`:e===`command`?t===1?`chat.usedGroup.commandSingle`:`chat.usedGroup.commandPlural`:t===1?`chat.usedGroup.otherSingle`:`chat.usedGroup.otherPlural`,{count:t})}).join(`, `),h=J(()=>{c(e=>!e)}),g=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())}),_=o(s?`chat.usedGroup.collapseAria`:`chat.usedGroup.expandAria`),v=o(d?`chat.usedGroup.running`:`chat.usedGroup.used`),y=t?`h-5`:`h-6`;return(0,$.jsxs)(`div`,{"data-component":`context-tool-group`,className:pm(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":s,"aria-controls":l,"aria-label":_,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,hm),onClick:h,onKeyDown:g,children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center self-center`,y,t?`w-4`:`w-3.5`),style:{color:`var(--tools-icon)`},children:d?(0,$.jsx)(qC,{isMobile:t,label:o(`chat.usedGroup.running`),className:`block`}):(0,$.jsx)(X,{name:`search`,className:`block h-[13px] w-[13px]`})}),(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex flex-none items-center self-center font-medium`,y,ED,d&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...d?{"--oc-text-shimmer-base":`var(--tools-title)`}:{}},children:v}),m?(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex min-h-0 w-0 min-w-0 max-w-full flex-1 items-center self-center overflow-clip`,y,ED),style:{color:`var(--tools-description)`},children:(0,$.jsx)(lD,{text:m,active:d,className:t?`!h-5 sm:!h-5`:`!h-6 sm:!h-6`})}):null,(0,$.jsx)(DD,{added:p.added,removed:p.removed}),(0,$.jsx)(X,{name:s?`arrow-down-s`:`arrow-right-s`,className:`ml-auto size-3.5 flex-none self-center text-muted-foreground opacity-70`})]}),s&&a?(0,$.jsxs)(`div`,{id:l,className:mm(t),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-0 left-0 top-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),a]}):null]})};function kD(e,t,n){let r=[],i=t;for(;i<e.length&&ow(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var AD=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function jD(e){if(!e||typeof e!=`object`)return null;let t=e.state;if(!t||typeof t!=`object`)return null;let n=t;if(n.metadata&&typeof n.metadata==`object`){let e=AD(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=AD(e.name);if(t)return t;let r=AD(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=AD(n.output.name);if(e)return e}return null}function MD(e){let t=[];for(let n of e){if(typeof n!=`string`)continue;let e=n.trim();e&&t.push(e)}let n=t.slice(0,3);return{visibleNames:n,hiddenCount:Math.max(0,t.length-n.length),joinedVisible:n.join(`, `)}}var ND=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,PD=({activities:e,isMobile:t,children:n})=>{let{t:r}=ct(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>uw(e)),{joinedVisible:l,hiddenCount:u}=MD(s.map(jD)),d=u>0?r(`chat.skillGroup.summaryOverflow`,{names:l,count:u}):l,f=J(()=>{a(e=>!e)}),p=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),f())}),m=r(i?`chat.skillGroup.collapseAria`:`chat.skillGroup.expandAria`),h=r(`chat.tools.display.skill`);return(0,$.jsxs)(`div`,{"data-component":`skill-tool-group`,className:pm(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":i,"aria-controls":o,"aria-label":m,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,hm),onClick:f,onKeyDown:p,children:[(0,$.jsx)(`span`,{className:Y(`flex flex-none items-center justify-center`,t?`size-4`:`size-3.5`),style:{color:`var(--tools-icon)`},children:c?(0,$.jsx)(qC,{isMobile:t,label:h,className:`block`}):(0,$.jsx)(X,{name:`book`,className:`h-[13px] w-[13px]`})}),(0,$.jsx)(`span`,{className:Y(`typography-meta flex-none font-medium`,ND,c&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...c?{"--oc-text-shimmer-base":`var(--tools-title)`}:{}},children:h}),d?(0,$.jsx)(`span`,{className:Y(`typography-meta h-5 min-h-0 w-0 min-w-0 max-w-full flex-1 overflow-clip sm:h-6`,ND),style:{color:`var(--tools-description)`},children:(0,$.jsx)(lD,{text:d,active:c})}):null,(0,$.jsx)(X,{name:i?`arrow-down-s`:`arrow-right-s`,className:`ml-auto size-3.5 flex-none text-muted-foreground opacity-70`})]}),i&&n?(0,$.jsxs)(`div`,{id:o,className:mm(t),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-0 left-0 top-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),n]}):null]})},FD=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:s}=e,c=q(ID),l=n,u=typeof l.text==`string`?l.text:``,d=typeof l.content==`string`?l.content:``,f=d.length>u.length?d:u,p=l.time,m=n.sessionID,h=o===void 0||o!==`completed`,g,_;if(t[0]!==i||t[1]!==f?(g=()=>{f.trim().length!==0&&i?.(`structural`)},_=[i,f],t[0]=i,t[1]=f,t[2]=g,t[3]=_):(g=t[2],_=t[3]),Z.useEffect(g,_),!f||f.trim().length===0)return null;let v=o??`streaming`,y=h&&typeof p?.end!=`number`,b;t[4]!==c||t[5]!==r||t[6]!==i||t[7]!==s||t[8]!==n||t[9]!==m||t[10]!==v||t[11]!==y?(b=(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(UT,{part:n,sessionId:m,messageId:r,streamPhase:v,chatRenderMode:c,hasStreamingHapticLifecycle:y,onContentChange:i,onShowPopup:s})}),t[4]=c,t[5]=r,t[6]=i,t[7]=s,t[8]=n,t[9]=m,t[10]=v,t[11]=y,t[12]=b):b=t[12];let x;t[13]===a?x=t[14]:(x=a?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:a})}):null,t[13]=a,t[14]=x);let S;return t[15]!==b||t[16]!==x?(S=(0,$.jsxs)(`div`,{"data-message-text-export-root":`true`,children:[b,x]}),t[15]=b,t[16]=x,t[17]=S):S=t[17],S});function ID(e){return e.chatRenderMode}var LD=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},RD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,zD=Y(`typography-meta font-medium`,RD),BD=Y(`typography-meta`,RD),VD=[],HD=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},UD=e=>{let t=new Set;for(let n of e)HD(n)&&n.messageId&&t.add(n.messageId);return[...t]},WD=(e,t)=>e.some(e=>{if(!t.has(e.messageId))return!1;let n=e.part;if(n.slim===!0)return!1;if(n.type===`reasoning`)return typeof n.text==`string`&&n.text.trim().length>0;if(n.type===`file`)return typeof n.url==`string`&&n.url.trim().length>0;if(n.type===`tool`){let e=n.state?.output,t=n.state?.error;return(typeof e==`string`?e.trim().length>0:e!=null)||(typeof t==`string`?t.trim().length>0:t!=null)}return!1}),GD=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=sc(n),t[0]=n,t[1]=a);let o=a;if(!o||r)return null;let s;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>i(!0),t[2]=s):s=t[2];let c;return t[3]===o?c=t[4]:(c=(0,$.jsx)(`span`,{className:`inline-flex size-[18px] flex-shrink-0 items-center justify-center rounded border border-[var(--border)] bg-[var(--interactive-hover)]`,children:(0,$.jsx)(`img`,{src:o,alt:``,"aria-hidden":`true`,loading:`lazy`,decoding:`async`,className:`size-3.5 rounded-sm`,onError:s})}),t[3]=o,t[4]=c),c},KD=e=>e,qD=e=>{let t=e.part.state,n=t?.input,r=t?.metadata,i=n?.filePath||n?.file_path||n?.path||r?.filePath||r?.file_path||r?.path;if(typeof i==`string`&&i.trim().length>0){let e=i.lastIndexOf(`/`);return e>=0?i.slice(e+1):i}return null},JD=e=>{let t=e.part.state,n=t?.input,r=t?.metadata,i=n?.filePath||n?.file_path||n?.path||r?.filePath||r?.file_path||r?.path;return typeof i==`string`&&i.trim().length>0?i:null},YD=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},XD=e=>{if(typeof e!=`string`)return null;let t=e.trim().toLowerCase();return t===`pending`?`pending`:t===`in_progress`||t===`in progress`||t===`inprogress`?`in_progress`:t===`completed`||t===`done`?`completed`:t===`cancelled`||t===`canceled`?`cancelled`:null},ZD=e=>{if(e.length===0)return`0 tasks`;let t=0,n=0;for(let r of e){if(!r||typeof r!=`object`)continue;let e=XD(r.status);e&&(e===`pending`&&(t+=1),e===`in_progress`&&(n+=1))}let r=t+n;return r===0?`0 tasks`:`${r} ${r===1?`task`:`tasks`}`},QD=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=ZD(n.todos);if(e)return e}if(Array.isArray(r)){let e=ZD(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=ZD(r.todos);if(e)return e}if(typeof r==`string`&&r.trim().length>0)try{let e=JSON.parse(r);if(Array.isArray(e)){let t=ZD(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=ZD(e.todos);if(t)return t}}catch{}return null},$D=e=>{let t=e.part.state,n=t?.input,r=t?.metadata,i=(typeof n?.offset==`number`&&Number.isFinite(n.offset)?n.offset:void 0)??(typeof n?.line==`number`&&Number.isFinite(n.line)?n.line:void 0)??(typeof r?.offset==`number`&&Number.isFinite(r.offset)?r.offset:void 0)??(typeof r?.line==`number`&&Number.isFinite(r.line)?r.line:void 0);if(!(typeof i!=`number`||i<=0))return Math.floor(i)},eO=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(aS,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,BD),style:{color:`var(--tools-description)`},title:e,children:e});let r=e.slice(0,n),i=e.slice(n+1),a=r.startsWith(`/`),o=a?r.slice(1):r;return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex max-w-full flex-1 items-baseline overflow-hidden`,BD),title:e,children:[a?(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}):null,(0,$.jsx)(`span`,{className:`min-w-0 shrink truncate whitespace-nowrap`,style:{color:`var(--tools-description)`,direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:o}),(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsx)(aS,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},tO=e=>{let t=xo(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},nO=e=>{let t=e.part,n=t.tool?.toLowerCase()??``,r=t.state,i=r?.input,a=r?.metadata;if(n===`grep`||n===`search`||n===`find`||n===`ripgrep`){let e=i?.pattern;if(typeof e==`string`&&e.trim().length>0)return e.length>40?e.slice(0,40)+`...`:e}if(n===`glob`){let e=i?.pattern;if(typeof e==`string`&&e.trim().length>0)return e.length>40?e.slice(0,40)+`...`:e}if(n===`websearch`||n===`web-search`||n===`search_web`||n===`codesearch`||n===`perplexity`){let e=i?.query;if(typeof e==`string`&&e.trim().length>0)return e.length>50?e.slice(0,50)+`...`:e}if(n===`skill`)return jD(t);if(n===`webfetch`||n===`fetch`||n===`curl`||n===`wget`){let e=typeof i?.url==`string`&&i.url||typeof i?.URL==`string`&&i.URL||typeof a?.url==`string`&&a.url||typeof a?.URL==`string`&&a.URL||``;if(typeof e==`string`&&e.trim().length>0)return e.trim()}return n===`todowrite`||n===`todoread`?QD(e):qD(e)},rO=e=>{let t=[],n=[];for(let r of e){if(r.kind!==`tool`)continue;let e=r.part;if(e.tool?.trim().toLowerCase()!==`task`)continue;let i=typeof e.id==`string`?e.id.trim():``;if(!i)continue;let a=e.state;if(!a||typeof a!=`object`)continue;let o=a;n.push(i),(o.status===`pending`||o.status===`running`)&&t.push(i)}return{active:t,all:n}},iO=Z.memo(e=>{let t=(0,Q.c)(16),{activity:n,isExpanded:r,isMobile:i,onToggleTool:a,onShowPopup:o,onContentChange:s}=e,c;t[0]!==n.id||t[1]!==a?(c=()=>{a(n.id)},t[0]=n.id,t[1]=a,t[2]=c):c=t[2];let l=J(c),u;t[3]===i?u=t[4]:(u=pm(i),t[3]=i,t[4]=u);let d=n.part,f;t[5]!==n.messageId||t[6]!==l||t[7]!==r||t[8]!==i||t[9]!==s||t[10]!==o||t[11]!==d?(f=(0,$.jsx)(CT,{part:d,messageId:n.messageId,isExpanded:r,onToggle:l,isMobile:i,onContentChange:s,onShowPopup:o,animateTailText:!1}),t[5]=n.messageId,t[6]=l,t[7]=r,t[8]=i,t[9]=s,t[10]=o,t[11]=d,t[12]=f):f=t[12];let p;return t[13]!==u||t[14]!==f?(p=(0,$.jsx)(`div`,{className:u,children:f}),t[13]=u,t[14]=f,t[15]=p):p=t[15],p},(e,t)=>e.isExpanded===t.isExpanded&&e.isMobile===t.isMobile&&e.onToggleTool===t.onToggleTool&&e.onShowPopup===t.onShowPopup&&e.onContentChange===t.onContentChange&&e.activity.id===t.activity.id&&e.activity.messageId===t.activity.messageId&&e.activity.kind===t.activity.kind&&e.activity.endedAt===t.activity.endedAt&&qS([e.activity.part],[t.activity.part])),aO=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=pm(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(cO,{toolName:n,activities:r,isMobile:i,animateTailText:!1}),t[2]=r,t[3]=i,t[4]=n,t[5]=o):o=t[5];let s;return t[6]!==a||t[7]!==o?(s=(0,$.jsx)(`div`,{className:a,children:o}),t[6]=a,t[7]=o,t[8]=s):s=t[8],s},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&sO(e.activities,t.activities)),oO=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!Pn(r.part).trim()){n++;continue}t.push({type:`reasoning`,activity:r}),n++;continue}if(r.kind===`justification`){t.push({type:`justification`,activity:r}),n++;continue}let i=r.part.tool?.toLowerCase()??``;if(cw(i)){let r=TD(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:CD(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(ow(i)){let r=kD(e,n,e=>e.part.tool);if(r.items.length>0){t.push({type:`tool-skill-group`,activities:r.items}),n=r.end;continue}}if(rw(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(nw(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(iw(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},sO=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(r.id!==i.id||r.kind!==i.kind||r.endedAt!==i.endedAt||!qS([r.part],[i.part]))return!1}return!0},cO=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=ct(),s=q(fO),c=uc(n,o),l;t[0]===n?l=t[1]:(l=oS(n),t[0]=n,t[1]=l);let u=l,d;t[2]===n?d=t[3]:(d=n.toLowerCase(),t[2]=n,t[3]=d);let f=d===`read`,p=Z.useContext(Ao),m=rg(),h=Se(pO),g=Rh(),_=g.kind===`embedded`?g.directory:h,v;t[4]===n?v=t[5]:(v=n.toLowerCase(),t[4]=n,t[5]=v);let y=v===`skill`,b;t[6]===y?b=t[7]:(b={enabled:y},t[6]=y,t[7]=b);let x=Ei(b),S;t[8]===x.data?S=t[9]:(S=x.data??[],t[8]=x.data,t[9]=S);let C=S,w;t[10]===C?w=t[11]:(w=new Map(C.map(mO)),t[10]=C,t[11]=w);let T=w,E=r[0]??null,D=!E||uw(E.part),O;t[12]===E?O=t[13]:(O=E?nO(E):null,t[12]=E,t[13]=O);let k=O,A;if(t[14]!==k||t[15]!==E||t[16]!==T||t[17]!==n){bb0:{if(n.toLowerCase()!==`skill`||!E||!k){A=null;break bb0}let e=T.get(k)?.path||YD(E);if(!e||e===`<built-in>`){A=null;break bb0}let r=tO(e);if(!r){A=null;break bb0}let i;t[19]!==k||t[20]!==r?(i={name:k,path:r},t[19]=k,t[20]=r,t[21]=i):i=t[21],A=i}t[14]=k,t[15]=E,t[16]=T,t[17]=n,t[18]=A}else A=t[18];let j=A,M;if(t[22]!==_||t[23]!==f||t[24]!==E){bb1:{if(!f||!E){M=null;break bb1}let e=JD(E);if(!e){M=null;break bb1}let n=yo(e,_);if(!n){M=null;break bb1}let r;t[26]===E?r=t[27]:(r=$D(E),t[26]=E,t[27]=r);let i;t[28]!==n||t[29]!==e||t[30]!==r?(i={path:e,displayPath:n,offset:r},t[28]=n,t[29]=e,t[30]=r,t[31]=i):i=t[31],M=i}t[22]=_,t[23]=f,t[24]=E,t[25]=M}else M=t[25];let N=M,P;t[32]!==_||t[33]!==m||t[34]!==p?(P=(e,t)=>{if(!_)return;let n=bo(_,e);if(!n)return;if(m){m.openFile({path:n,targetLine:t&&Number.isFinite(t)?Math.max(1,Math.trunc(t)):void 0});return}if(p?.editor){p.editor.openFile(n,t);return}if(!wo(n,_)){mc(n,_).then(()=>{let e=q.getState(),r=_||vo(_,n);if(t&&Number.isFinite(t)){e.openContextFileAtLine(r,n,Math.max(1,Math.trunc(t)),1);return}e.openContextFile(r,n)});return}let r=q.getState(),i=vo(_,n);if(t&&Number.isFinite(t)){r.openContextFileAtLine(i,n,Math.max(1,Math.trunc(t)),1);return}r.openContextFile(i,n)},t[32]=_,t[33]=m,t[34]=p,t[35]=P):P=t[35];let F=J(P),I;t[36]!==_||t[37]!==m?(I=e=>{let t=xo(e);if(!t)return;let n=()=>{if(m){m.openFile({path:t});return}let e=q.getState(),n=_||vo(``,t);e.openContextFile(n,t)};if(_&&!wo(t,_)){mc(t,_).then(n);return}n()},t[36]=_,t[37]=m,t[38]=I):I=t[38];let L=J(I),R;t[39]===n?R=t[40]:(R=n.toLowerCase(),t[39]=n,t[40]=R);let z=R,B=z===`grep`||z===`search`||z===`find`||z===`ripgrep`||z===`glob`,V=z===`webfetch`||z===`fetch`||z===`curl`||z===`wget`,H=z===`skill`,U=!!(N||j),W=!!(N&&_||j),ee;t[41]!==W||t[42]!==F||t[43]!==L||t[44]!==U||t[45]!==N||t[46]!==j?(ee=()=>{if(!(!U||!W)){if(N){F(N.path,N.offset);return}j&&L(j.path)}},t[41]=W,t[42]=F,t[43]=L,t[44]=U,t[45]=N,t[46]=j,t[47]=ee):ee=t[47];let G=J(ee),K;t[48]===G?K=t[49]:(K=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),G())},t[48]=G,t[49]=K);let te=J(K),ne=U&&W&&`cursor-pointer`,re=U&&!W&&`cursor-default opacity-70`,ie;t[50]!==ne||t[51]!==re?(ie=Y(`flex w-full items-center gap-x-1.5 min-w-0`,hm,ne,re),t[50]=ne,t[51]=re,t[52]=ie):ie=t[52];let ae=U?`soft`:void 0,oe=U?G:void 0,se=U?te:void 0,ce=U?`button`:void 0,le=U&&W?0:void 0,ue=U&&!W?!0:void 0,de=i?`size-4`:`size-3.5`,fe;t[53]===de?fe=t[54]:(fe=Y(`inline-flex items-center justify-center flex-shrink-0`,de),t[53]=de,t[54]=fe);let pe;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(pe={color:`var(--tools-icon)`},t[55]=pe):pe=t[55];let me=D?(0,$.jsx)(qC,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:c})}):u,he;t[56]!==fe||t[57]!==pe||t[58]!==me?(he=(0,$.jsx)(`div`,{className:fe,style:pe,children:me}),t[56]=fe,t[57]=pe,t[58]=me,t[59]=he):he=t[59];let ge,_e;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(ge=Y(zD,`inline-flex items-center flex-shrink-0 opacity-85`),_e={color:`var(--tools-title)`},t[60]=ge,t[61]=_e):(ge=t[60],_e=t[61]);let ve;t[62]===c?ve=t[63]:(ve=(0,$.jsx)(`span`,{className:ge,style:_e,title:c,children:c}),t[62]=c,t[63]=ve);let ye;t[64]!==a||t[65]!==f||t[66]!==N||t[67]!==s?(ye=f&&N?(0,$.jsxs)(`span`,{className:Y(`inline-flex !min-h-0 items-center justify-start gap-1 min-w-0 flex-1 text-left`,BD),style:{color:`var(--tools-description)`},title:N.offset?`${N.displayPath}:${N.offset}`:N.displayPath,children:[s?(0,$.jsx)(yd,{filePath:N.path,className:`h-3.5 w-3.5`}):null,eO(N.displayPath,a)]}):null,t[64]=a,t[65]=f,t[66]=N,t[67]=s,t[68]=ye):ye=t[68];let be;t[69]!==a||t[70]!==k||t[71]!==B?(be=B&&k?(0,$.jsx)(`span`,{className:`inline-flex min-w-0 flex-1`,children:(0,$.jsxs)(aS,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,BD),style:{color:`var(--tools-description)`},title:k,children:[`"`,k,`"`]})}):null,t[69]=a,t[70]=k,t[71]=B,t[72]=be):be=t[72];let xe;t[73]!==k||t[74]!==V?(xe=V&&k?(0,$.jsxs)(`a`,{href:k,target:`_blank`,rel:`noopener noreferrer`,onClick:hO,className:Y(`min-w-0 flex-1 inline-flex items-center gap-1.5 underline decoration-[color:var(--status-info)] underline-offset-2 hover:opacity-90`,`truncate whitespace-nowrap`,BD),style:{color:`var(--status-info)`},title:k,children:[(0,$.jsx)(GD,{href:k}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:k})]}):null,t[73]=k,t[74]=V,t[75]=xe):xe=t[75];let Ce;t[76]!==H||t[77]!==j?(Ce=H&&j?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,BD),style:{color:`var(--tools-description)`},title:j.path,children:j.name}):null,t[76]=H,t[77]=j,t[78]=Ce):Ce=t[78];let we;t[79]!==k||t[80]!==H||t[81]!==j?(we=H&&!j&&k?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,BD),style:{color:`var(--tools-description)`},title:k,children:k}):null,t[79]=k,t[80]=H,t[81]=j,t[82]=we):we=t[82];let Te;t[83]!==a||t[84]!==k||t[85]!==V||t[86]!==f||t[87]!==B||t[88]!==H?(Te=!f&&!B&&!V&&!H&&k?(0,$.jsx)(aS,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,BD),style:{color:`var(--tools-description)`},children:k}):null,t[83]=a,t[84]=k,t[85]=V,t[86]=f,t[87]=B,t[88]=H,t[89]=Te):Te=t[89];let Ee;return t[90]!==ie||t[91]!==ae||t[92]!==oe||t[93]!==se||t[94]!==ce||t[95]!==le||t[96]!==ue||t[97]!==he||t[98]!==ve||t[99]!==ye||t[100]!==be||t[101]!==xe||t[102]!==Ce||t[103]!==we||t[104]!==Te?(Ee=(0,$.jsxs)(`div`,{className:ie,"data-mobile-press-feedback":ae,onClick:oe,onKeyDown:se,role:ce,tabIndex:le,"aria-disabled":ue,children:[he,ve,ye,be,xe,Ce,we,Te]}),t[90]=ie,t[91]=ae,t[92]=oe,t[93]=se,t[94]=ce,t[95]=le,t[96]=ue,t[97]=he,t[98]=ve,t[99]=ye,t[100]=be,t[101]=xe,t[102]=Ce,t[103]=we,t[104]=Te,t[105]=Ee):Ee=t[105],Ee},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&sO(e.activities,t.activities)),lO=Z.memo(e=>{let t=(0,Q.c)(5),{activity:n,onContentChange:r,streamPhase:i}=e,a;return t[0]!==n.messageId||t[1]!==n.part||t[2]!==r||t[3]!==i?(a=(0,$.jsx)(tE,{part:n.part,messageId:n.messageId,streamPhase:i,onContentChange:r}),t[0]=n.messageId,t[1]=n.part,t[2]=r,t[3]=i,t[4]=a):a=t[4],a}),uO=Z.memo(e=>{let t=(0,Q.c)(7),{activity:n,onContentChange:r,onShowPopup:i,actions:a,streamPhase:o}=e,s;return t[0]!==a||t[1]!==n.messageId||t[2]!==n.part||t[3]!==r||t[4]!==i||t[5]!==o?(s=(0,$.jsx)(FD,{part:n.part,messageId:n.messageId,onContentChange:r,onShowPopup:i,actions:a,streamPhase:o}),t[0]=a,t[1]=n.messageId,t[2]=n.part,t[3]=r,t[4]=i,t[5]=o,t[6]=s):s=t[6],s}),dO=Z.memo(({parts:e,materializationParts:t=e,isExpanded:n,collapsedPreviewCount:r=0,completionDisposition:i,activityPresentationKind:a=`default`,durationMs:o,onToggle:s,isMobile:c,expandedTools:l,onToggleTool:u,onShowPopup:d,onContentChange:f,streamPhase:p,showHeader:m,renderJustificationActions:h})=>{let{t:g}=ct(),_=pc()??``,v=Z.useMemo(()=>UD(t),[t]),y=Z.useRef(new Set),b=Z.useRef(new Map),x=Z.useRef(new Set),[,S]=Z.useState(0),C=Z.useRef(null),w=Z.useRef(null),T=i===`active`,E=!T&&(i===`normal`||i===`abnormal`)&&typeof o==`number`&&Number.isFinite(o)&&o>=0?LD(o):null,D=i===`normal`||i===`abnormal`,O=a===`compaction`,k=O?`fold-vertical`:`stack`,A=g(i===void 0?`chat.activity.title`:T?O?`chat.activity.compacting`:`chat.activity.active`:D?O?`chat.activity.compactionCompleted`:`chat.activity.completedStatus`:`chat.activity.title`),j=Z.useMemo(()=>rO(e),[e]),M=T?j.active:j.all,N=M.slice(0,c?2:3),P=J((e=!1,n=!1)=>{if(!(!_||!v.length)){for(let r of v){let i=t.find(e=>e.messageId===r)?.part.sessionID;if(!i)continue;let a=Rr(_,i,r);if(a.status===`ready`||n&&a.status===`error`||e&&a.status!==`error`&&!x.current.has(r)||(y.current.add(r),x.current.delete(r),b.current.has(r)))continue;let o=Ii(_,i,r,{priority:n?`background`:`user`}).catch(()=>{x.current.add(r)}).finally(()=>{b.current.delete(r),S(e=>e+1)});b.current.set(r,o)}S(e=>e+1)}}),F=J(e=>{e.stopPropagation(),P(!0)}),I=T,L=I||n,R=J(()=>{if(I)return;let e=C.current;w.current=e?{top:e.getBoundingClientRect().top,scrollContainer:e.closest(`[data-scrollbar="chat"]`)}:null,L||P(),s()});Z.useEffect(()=>{T||!L||P(!1,!0)},[T,L]),Z.useLayoutEffect(()=>{let e=w.current,t=C.current;if(!e||!t)return;let n=()=>{if(!t.isConnected)return;let n=t.getBoundingClientRect().top-e.top;if(!(Math.abs(n)<.5)){if(e.scrollContainer?.isConnected){e.scrollContainer.scrollTop+=n;return}window.scrollBy(0,n)}};if(n(),typeof window>`u`||typeof window.requestAnimationFrame!=`function`){w.current=null;return}let r=window.requestAnimationFrame(()=>{n(),w.current=null});return()=>window.cancelAnimationFrame(r)},[L]);let z=m&&!L?Math.max(0,Math.floor(r)):0,B=!m||L||z>0,V=y.current,H=[...V].map(e=>{if(b.current.has(e))return`loading`;if(x.current.has(e))return`error`;let n=t.find(t=>t.messageId===e)?.part.sessionID??``;return Rr(_,n,e).status}),U=H.includes(`loading`),W=H.includes(`error`),ee=H.length>0&&H.every(e=>e===`ready`),G=t.some(e=>V.has(e.messageId)&&HD(e)),K=ee&&!G&&!WD(t,V),te=Z.useMemo(()=>B?KD(e):VD,[e,B]),ne=Z.useMemo(()=>B?oO(te):[],[B,te]),re=Z.useMemo(()=>L||z===0?0:Math.max(0,ne.length-z),[L,z,ne.length]),ie=Z.useMemo(()=>L||z===0?ne:ne.slice(-z),[L,z,ne]);if((!m||I&&!O)&&ne.length===0)return null;let ae=(e,t)=>{let n=(0,$.jsx)(`div`,{className:pm(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},oe=B?ie.map((e,t)=>{switch(e.type){case`reasoning`:return ae(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(lO,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return ae(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(uO,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(iO,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);case`tool-static-group`:return(0,$.jsx)(aO,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(OD,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part,n=t.tool?.toLowerCase()??``;return aw(n)?(0,$.jsx)(cO,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(CT,{part:t,messageId:e.messageId,isExpanded:l.has(e.id),onToggle:u,isMobile:c,onContentChange:f,onShowPopup:d,animateTailText:!1},e.id)})},e.activities[0]?.id??`context-${t}`);case`tool-skill-group`:return(0,$.jsx)(PD,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(cO,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(iO,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,se=ie.length>0;return m?(0,$.jsxs)(`div`,{className:pm(c),children:[(0,$.jsxs)(`button`,{ref:C,type:`button`,className:Y(`group/tool flex w-full min-w-0 flex-nowrap items-center text-left`,c?`gap-x-1`:`gap-x-2`,!I&&hm,I&&`oc-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-default`,c&&`pr-0`),"data-mobile-press-feedback":I?void 0:`soft`,onClick:I?void 0:R,"aria-expanded":L,"aria-disabled":I||void 0,"aria-label":I?A:g(L?`chat.activity.collapseAria`:`chat.activity.expandAria`),children:[(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 flex-1 items-center overflow-clip`,c?`gap-x-1`:`gap-x-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,c?`h-5 w-4`:`h-6 w-3.5`),style:{color:`var(--tools-icon)`},children:T&&!O?(0,$.jsx)(qC,{isMobile:c,label:A,className:`block`}):(0,$.jsx)(X,{name:k,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:Y(`inline-flex flex-shrink-0 items-center`,c?`typography-meta h-5`:`typography-ui-label h-5 font-semibold`,T?`animate-text-shimmer text-[var(--status-info)] [--oc-text-shimmer-base:var(--status-info)]`:`text-foreground/85`),children:A}),E?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 tabular-nums text-muted-foreground`,children:E}):null]}),(0,$.jsxs)(`span`,{className:Y(`ml-auto inline-flex max-w-[min(14rem,55%)] shrink-0 items-center justify-end`,c?`gap-0.5`:`gap-1`),children:[M.length>0?(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center text-muted-foreground`,c?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5`,"aria-hidden":`true`,children:N.map((e,t)=>(0,$.jsx)(la,{name:e,size:c?12:14,className:Y(`flex-none`,c?`size-3 min-h-3 min-w-3 max-h-3 max-w-3`:`size-3.5 min-h-3.5 min-w-3.5 max-h-3.5 max-w-3.5`)},`${e}-${t}`))}),(0,$.jsx)(`span`,{className:`typography-meta min-w-0 truncate`,children:g(T?`chat.activity.agentsWorking`:`chat.activity.agentsInvolved`,{count:M.length})})]}):null,I?null:(0,$.jsx)(X,{name:L?`arrow-down-s`:`arrow-right-s`,className:Y(`flex-shrink-0 text-muted-foreground opacity-70`,c&&`-mr-0.5`,c?`size-3`:`size-3.5`)})]})]}),se?(0,$.jsxs)(`div`,{className:I?void 0:`relative ml-2 pl-3`,children:[I?null:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-px bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),re>0?(0,$.jsxs)(`button`,{type:`button`,onClick:R,className:`typography-meta leading-4 px-2 py-1 text-muted-foreground/45 hover:text-muted-foreground/65 text-left`,children:[`+`,re,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:oe})]}):null,L&&(U||W||K)?(0,$.jsx)(`div`,{className:Y(`typography-meta flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,I?void 0:`ml-5`,W&&`text-[var(--status-error)]`),role:W?`alert`:`status`,children:U?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{children:g(`chat.activity.outputLoading`)})]}):W?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:g(`chat.activity.outputLoadFailed`)}),(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`xs`,onClick:F,children:g(`chat.activity.outputRetry`)})]}):(0,$.jsx)(`span`,{children:g(`chat.toolOutputDialog.noOutputProduced`)})}):null]}):(0,$.jsx)(`div`,{className:pm(c),children:oe})});function fO(e){return e.showToolFileIcons}function pO(e){return e.currentDirectory}function mO(e){return[e.name,e]}function hO(e){e.stopPropagation()}var gO=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(dO,{...e}),t[0]=e,t[1]=n),n}),_O={contain:`layout`},vO={containerType:`inline-size`,containerName:`message-footer`},yO=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,bO=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,xO=`size-6! p-0 text-muted-foreground bg-transparent hover:text-foreground hover:!bg-transparent active:!bg-transparent focus-visible:!bg-transparent focus-visible:ring-2 focus-visible:ring-primary/50`,SO=`size-3.5!`,CO=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,wO=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,TO=`flex items-center gap-2`,EO=`flex items-center gap-2 text-muted-foreground`,DO=`inline-flex h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,OO=`size-3.5!`,kO=`medium`,AO=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,jO=`w-full min-w-0 justify-start rounded-[var(--radius-md)] bg-transparent px-1 hover:!bg-interactive-hover focus-visible:!bg-interactive-hover active:!bg-interactive-active supports-[corner-shape:squircle]:rounded-[var(--radius-md)]`,MO=`h-7 gap-1.5`,NO=`h-6 gap-1`,PO=`text-[11px] leading-none`,FO=`size-3.5`,IO=`size-3`,LO=5,RO=Z.memo(e=>{let t=(0,Q.c)(30),{file:n,isMobile:r}=e,i=r?`gap-1 text-[11px]`:`gap-1.5 text-xs`,a;t[0]===i?a=t[1]:(a=Y(`flex min-w-0 flex-1 items-center leading-none text-muted-foreground`,i),t[0]=i,t[1]=a);let o=n.file,s=r?`h-3 w-3`:`h-3.5 w-3.5`,c;t[2]===s?c=t[3]:(c=Y(`flex-shrink-0`,s),t[2]=s,t[3]=c);let l;t[4]!==n.file||t[5]!==c?(l=(0,$.jsx)(yd,{filePath:o,className:c}),t[4]=n.file,t[5]=c,t[6]=l):l=t[6];let u=n.file,d;t[7]===n.file?d=t[8]:(d=AO(n.file),t[7]=n.file,t[8]=d);let f;t[9]!==n.file||t[10]!==d?(f=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left text-foreground/80`,title:u,children:d}),t[9]=n.file,t[10]=d,t[11]=f):f=t[11];let p=r?`text-[11px]`:`typography-meta`,m;t[12]===p?m=t[13]:(m=Y(`inline-flex flex-shrink-0 items-center gap-0 leading-none tabular-nums`,p),t[12]=p,t[13]=m);let h;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(h={color:`var(--status-success)`},t[14]=h):h=t[14];let g;t[15]===n.additions?g=t[16]:(g=(0,$.jsxs)(`span`,{style:h,children:[`+`,n.additions]}),t[15]=n.additions,t[16]=g);let _,v;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(`span`,{className:`text-muted-foreground/70`,children:`/`}),v={color:`var(--status-error)`},t[17]=_,t[18]=v):(_=t[17],v=t[18]);let y;t[19]===n.deletions?y=t[20]:(y=(0,$.jsxs)(`span`,{style:v,children:[`-`,n.deletions]}),t[19]=n.deletions,t[20]=y);let b;t[21]!==m||t[22]!==g||t[23]!==y?(b=(0,$.jsxs)(`span`,{className:m,children:[g,_,y]}),t[21]=m,t[22]=g,t[23]=y,t[24]=b):b=t[24];let x;return t[25]!==b||t[26]!==a||t[27]!==l||t[28]!==f?(x=(0,$.jsxs)(`span`,{className:a,children:[l,f,b]}),t[25]=b,t[26]=a,t[27]=l,t[28]=f,t[29]=x):x=t[29],x}),zO=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=ct(),s;t[0]!==n.file||t[1]!==a?(s=()=>{a(n.file)},t[0]=n.file,t[1]=a,t[2]=s):s=t[2];let c=J(s),l=!r,u=i?NO:MO,d;t[3]===u?d=t[4]:(d=Y(jO,u),t[3]=u,t[4]=d);let f;t[5]!==n.file||t[6]!==o?(f=o(`chat.changedFiles.actions.openFileTitle`,{path:n.file}),t[5]=n.file,t[6]=o,t[7]=f):f=t[7];let p;t[8]!==n||t[9]!==i?(p=(0,$.jsx)(RO,{file:n,isMobile:i}),t[8]=n,t[9]=i,t[10]=p):p=t[10];let m;return t[11]!==n.file||t[12]!==c||t[13]!==l||t[14]!==d||t[15]!==f||t[16]!==p?(m=(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`xs`,disabled:l,"data-turn-change-file":`true`,className:d,"aria-label":f,title:n.file,onClick:c,children:p}),t[11]=n.file,t[12]=c,t[13]=l,t[14]=d,t[15]=f,t[16]=p,t[17]=m):m=t[17],m}),BO=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:s}=ct(),c=pc(),l=Rh(),u=l.directory||c,d=l.sessionId,f=rg(),p=q(ek),m;t[0]===r?m=t[1]:(m=r??[],t[0]=r,t[1]=m);let h=m,g;t[2]===h?g=t[3]:(g=h.slice(0,LO),t[2]=h,t[3]=g);let _=g,v=Math.max(0,h.length-_.length),y=h.length>0?h.length:n,b=!!(f||!o&&u||o&&a),x;t[4]!==y||t[5]!==s?(x=s(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[4]=y,t[5]=s,t[6]=x):x=t[6];let S=x,C;t[7]!==v||t[8]!==s?(C=s(v===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:v}),t[7]=v,t[8]=s,t[9]=C):C=t[9];let w=C,T=Y(jO,o?NO:MO),E=o?IO:FO,D;t[10]===o?D=t[11]:(D=o?Y(PO,`font-semibold text-foreground/85`):`typography-meta font-semibold text-foreground/85`,t[10]=o,t[11]=D);let O=D,k;t[12]===o?k=t[13]:(k=o?Y(PO,`text-muted-foreground`):`typography-meta text-muted-foreground`,t[12]=o,t[13]=k);let A=k,j;t[14]===o?j=t[15]:(j=o?Y(PO,`font-medium`):`typography-meta font-medium`,t[14]=o,t[15]=j);let M=j,N;t[16]!==u||t[17]!==d||t[18]!==a||t[19]!==o||t[20]!==f||t[21]!==i?(N=e=>{if(f){f.openTurnDiff(i,d,e);return}if(!o&&u){iE({directory:u,filePath:e,turnMessageId:i,sessionId:d});return}o&&a&&u&&iE({directory:u,filePath:e,turnMessageId:i,sessionId:d,mobile:!0})},t[16]=u,t[17]=d,t[18]=a,t[19]=o,t[20]=f,t[21]=i,t[22]=N):N=t[22];let P=J(N),F;t[23]!==u||t[24]!==d||t[25]!==a||t[26]!==o||t[27]!==f||t[28]!==p||t[29]!==i||t[30]!==_[0]?.file?(F=()=>{if(f){f.openTurnDiff(i,d);return}if(!o&&u){p(u,{mode:`diff`,dedupeKey:`turn-diff:${d||`session`}:${i}`,targetPath:null,diffScope:`turn`,diffTurnMessageId:i,diffSessionId:d});return}let e=_[0]?.file;e&&o&&a&&u&&iE({directory:u,filePath:e,turnMessageId:i,sessionId:d,mobile:!0})},t[23]=u,t[24]=d,t[25]=a,t[26]=o,t[27]=f,t[28]=p,t[29]=i,t[30]=_[0]?.file,t[31]=F):F=t[31];let I=J(F),L=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,R;t[32]===L?R=t[33]:(R=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,L),t[32]=L,t[33]=R);let z=Y(T,`max-w-full text-muted-foreground hover:text-foreground`),B;t[34]===s?B=t[35]:(B=s(`diffView.actions.reviewAria`),t[34]=s,t[35]=B);let V;t[36]===s?V=t[37]:(V=s(`diffView.actions.reviewAria`),t[36]=s,t[37]=V);let H;t[38]===E?H=t[39]:(H=(0,$.jsx)(X,{name:`file-edit`,className:E}),t[38]=E,t[39]=H);let U=`turn-changes-${i}`,W;t[40]===s?W=t[41]:(W=s(`chat.changedFiles.title`),t[40]=s,t[41]=W);let ee;t[42]!==U||t[43]!==W||t[44]!==O?(ee=(0,$.jsx)(`span`,{id:U,className:O,children:W}),t[42]=U,t[43]=W,t[44]=O,t[45]=ee):ee=t[45];let G;t[46]!==S||t[47]!==A?(G=(0,$.jsx)(`span`,{className:A,children:S}),t[46]=S,t[47]=A,t[48]=G):G=t[48];let K;t[49]===E?K=t[50]:(K=Y(E,`opacity-60`),t[49]=E,t[50]=K);let te;return t[51]===K?te=t[52]:(te=(0,$.jsx)(X,{name:`arrow-right-s`,className:K}),t[51]=K,t[52]=te),(0,$.jsxs)(`section`,{className:R,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,onClick:I,className:z,"aria-label":B,title:V,children:[H,ee,G,te]}),_.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[_.map(e=>(0,$.jsx)(zO,{file:e,canOpen:b,isMobile:o,onOpen:P},e.file)),v>0?(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,className:Y(T,`text-muted-foreground hover:text-foreground`),onClick:I,"aria-label":s(`diffView.actions.reviewAria`),title:s(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(E,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:M,children:[`+`,w]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:E})]}):null]}):null]})}),VO=e=>e.type===`subtask`,HO=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},UO=e=>{if(!e||typeof e!=`object`)return null;let t=typeof e.providerID==`string`?e.providerID.trim():``,n=typeof e.modelID==`string`?e.modelID.trim():``;return!t||!n?null:`${t}/${n}`},WO=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=pc(),{isMobile:o}=mo(),s=ri(tk),c=q(nk),l=Rh(),{t:u}=ct(),d;t[0]===n.description?d=t[1]:(d=typeof n.description==`string`?n.description.trim():``,t[0]=n.description,t[1]=d);let f=d,p;t[2]===n.command?p=t[3]:(p=typeof n.command==`string`?n.command.trim():``,t[2]=n.command,t[3]=p);let m=p,h;t[4]===n.agent?h=t[5]:(h=typeof n.agent==`string`?n.agent.trim():``,t[4]=n.agent,t[5]=h);let g=h,_;t[6]===n.prompt?_=t[7]:(_=typeof n.prompt==`string`?n.prompt.trim():``,t[6]=n.prompt,t[7]=_);let v=_,y;t[8]===n.taskSessionID?y=t[9]:(y=typeof n.taskSessionID==`string`?n.taskSessionID.trim():``,t[8]=n.taskSessionID,t[9]=y);let b=y,x;t[10]===n.model?x=t[11]:(x=UO(n.model),t[10]=n.model,t[11]=x);let S=x,C=!!v&&!(o&&l.kind===`primary`),w;t[12]===u?w=t[13]:(w=u(`chat.messageBody.subtask.title`),t[12]=u,t[13]=w);let T;t[14]===w?T=t[15]:(T=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:w}),t[14]=w,t[15]=T);let E;t[16]===m?E=t[17]:(E=m?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`/`,m]}):null,t[16]=m,t[17]=E);let D;t[18]===g?D=t[19]:(D=g?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`@`,g]}):null,t[18]=g,t[19]=D);let O;t[20]===S?O=t[21]:(O=S?(0,$.jsx)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:S}):null,t[20]=S,t[21]=O);let k;t[22]!==D||t[23]!==O||t[24]!==T||t[25]!==E?(k=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[T,E,D,O]}),t[22]=D,t[23]=O,t[24]=T,t[25]=E,t[26]=k):k=t[26];let A;t[27]===f?A=t[28]:(A=f?(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground/90 mt-1.5`,children:f}):null,t[27]=f,t[28]=A);let j;t[29]!==r||t[30]!==v||t[31]!==C||t[32]!==u?(j=C?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>i(rk),children:u(r?`chat.messageBody.subtask.hidePrompt`:`chat.messageBody.subtask.showPrompt`)}),r?(0,$.jsx)(`pre`,{className:`typography-meta mt-1.5 overflow-x-auto whitespace-pre-wrap break-words text-foreground/85`,children:v}):null]}):null,t[29]=r,t[30]=v,t[31]=C,t[32]=u,t[33]=j):j=t[33];let M;t[34]!==g||t[35]!==f||t[36]!==a||t[37]!==o||t[38]!==c||t[39]!==l||t[40]!==s||t[41]!==u||t[42]!==b?(M=b&&l.capabilities.navigateNestedSession?(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>{let e=l.directory||a;e&&Bh(l,b,e,()=>{if(!di({sessionId:b,directory:e})){if(fl()||o||se()){s(b,e);return}c(e,{mode:`chat`,dedupeKey:`session:${b}`,label:f||g||u(`contextPanel.mode.chat`),readOnly:!0})}})},children:u(`chat.messageBody.subtask.openSession`)})}):null,t[34]=g,t[35]=f,t[36]=a,t[37]=o,t[38]=c,t[39]=l,t[40]=s,t[41]=u,t[42]=b,t[43]=M):M=t[43];let N;return t[44]!==k||t[45]!==A||t[46]!==j||t[47]!==M?(N=(0,$.jsxs)(`div`,{className:`mt-2`,children:[k,A,j,M]}),t[44]=k,t[45]=A,t[46]=j,t[47]=M,t[48]=N):N=t[48],N},GO=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=pc(),i=q(ik),{isMobile:a}=mo(),{t:o}=ct(),s;t[0]!==r||t[1]!==a?(s=r&&!a&&!se(),t[0]=r,t[1]=a,t[2]=s):s=t[2];let c=!!s,l;t[3]!==n.state||t[4]!==o?(l=n.state===`completed`?o(`chat.messageBody.subagent.completed`):n.state===`error`?o(`chat.messageBody.subagent.error`):o(`chat.messageBody.subagent.cancelled`),t[3]=n.state,t[4]=o,t[5]=l):l=t[5];let u=l,d=n.state===`completed`?o(`chat.messageBody.subagent.completedDescription`):n.state===`error`?o(`chat.messageBody.subagent.errorDescription`):o(`chat.messageBody.subagent.cancelledDescription`),f=n.description||d,p=J(()=>{!c||!r||i(r,{mode:`chat`,dedupeKey:`session:${n.sessionID}`,label:f,readOnly:!0})}),m;t[6]===p?m=t[7]:(m=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),p())},t[6]=p,t[7]=m);let h=J(m),g=c&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,_;t[8]===g?_=t[9]:(_=Y(`mt-2 flex min-w-0 gap-2.5 rounded-[var(--radius-lg)] border border-border/60 bg-muted/20 px-3 py-2.5`,g),t[8]=g,t[9]=_);let v=c?`button`:void 0,y=c?0:void 0,b=c?o(`chat.messageBody.subagent.openSession`,{label:f}):void 0,x=c?p:void 0,S=c?h:void 0,C;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(`span`,{className:`mt-0.5 flex size-6 flex-shrink-0 items-center justify-center rounded-md bg-foreground/5 text-muted-foreground`,children:(0,$.jsx)(X,{name:`robot-2`,className:`size-3.5`})}),t[10]=C):C=t[10];let w;t[11]===f?w=t[12]:(w=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:f}),t[11]=f,t[12]=w);let T=n.state===`completed`?`bg-[var(--status-success-background)] text-[var(--status-success)]`:n.state===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`,E;t[13]===T?E=t[14]:(E=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,T),t[13]=T,t[14]=E);let D;t[15]!==u||t[16]!==E?(D=(0,$.jsx)(`span`,{className:E,children:u}),t[15]=u,t[16]=E,t[17]=D):D=t[17];let O;t[18]!==w||t[19]!==D?(O=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[w,D]}),t[18]=w,t[19]=D,t[20]=O):O=t[20];let k;t[21]===n.body?k=t[22]:(k=n.body?(0,$.jsx)(`div`,{className:`typography-meta mt-1 max-h-16 overflow-hidden text-muted-foreground [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,children:(0,$.jsx)(Ns,{content:n.body,variant:`tool`,enableFileReferences:!1})}):null,t[21]=n.body,t[22]=k);let A;t[23]!==O||t[24]!==k?(A=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[O,k]}),t[23]=O,t[24]=k,t[25]=A):A=t[25];let j;return t[26]!==S||t[27]!==A||t[28]!==_||t[29]!==v||t[30]!==y||t[31]!==b||t[32]!==x?(j=(0,$.jsxs)(`div`,{className:_,role:v,tabIndex:y,"aria-label":b,onClick:x,onKeyDown:S,children:[C,A]}),t[26]=S,t[27]=A,t[28]=_,t[29]=v,t[30]=y,t[31]=b,t[32]=x,t[33]=j):j=t[33],j},KO={background:`transparent`,backgroundColor:`transparent`},qO=e=>{let t=(0,Q.c)(36),{part:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=Z.useRef(null),{t:c}=ct(),l;t[0]===n.shellAction?l=t[1]:(l=typeof n.shellAction?.command==`string`?n.shellAction.command.trim():``,t[0]=n.shellAction,t[1]=l);let u=l,d=typeof n.shellAction?.output==`string`?n.shellAction.output:``,f;t[2]===n.shellAction?f=t[3]:(f=typeof n.shellAction?.status==`string`?n.shellAction.status.trim().toLowerCase():``,t[2]=n.shellAction,t[3]=f);let p=f,m;t[4]===d?m=t[5]:(m=d.trim(),t[4]=d,t[5]=m);let h=m.length>0,g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{s.current!==null&&typeof window<`u`&&(window.clearTimeout(s.current),s.current=null)},t[6]=g):g=t[6];let _=J(g),v,y;t[7]===_?(v=t[8],y=t[9]):(v=()=>()=>{_()},y=[_],t[7]=_,t[8]=v,t[9]=y),Z.useEffect(v,y);let b;t[10]!==_||t[11]!==h||t[12]!==d?(b=async()=>{h&&(await ut(d)).ok&&(_(),o(!0),typeof window<`u`&&(s.current=window.setTimeout(()=>{o(!1),s.current=null},2e3)))},t[10]=_,t[11]=h,t[12]=d,t[13]=b):b=t[13];let x=J(b),S;t[14]===c?S=t[15]:(S=c(`chat.messageBody.shellCommand.title`),t[14]=c,t[15]=S);let C;t[16]===S?C=t[17]:(C=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:S}),t[16]=S,t[17]=C);let w;t[18]===p?w=t[19]:(w=p?(0,$.jsx)(`span`,{className:Y(`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none`,p===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`),children:p}):null,t[18]=p,t[19]=w);let T;t[20]!==w||t[21]!==C?(T=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[C,w]}),t[20]=w,t[21]=C,t[22]=T):T=t[22];let E;t[23]===u?E=t[24]:(E=u?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 overflow-x-auto font-mono`,children:(0,$.jsx)(Fc,{language:`bash`,code:u,codeStyle:KO,wrap:!0})}):null,t[23]=u,t[24]=E);let D;t[25]!==a||t[26]!==x||t[27]!==r||t[28]!==h||t[29]!==d||t[30]!==c?(D=h?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>i(ak),children:c(r?`chat.messageBody.shellCommand.hideOutput`:`chat.messageBody.shellCommand.showOutput`)}),(0,$.jsx)(`button`,{type:`button`,className:`inline-flex items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,onClick:()=>{x()},"aria-label":c(a?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),title:c(a?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),children:a?(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`file-copy`,className:`h-3.5 w-3.5`})})]}),r?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 max-h-56 overflow-auto font-mono text-foreground/85`,children:(0,$.jsx)(Fc,{language:`bash`,code:d,codeStyle:KO,wrap:!0})}):null]}):null,t[25]=a,t[26]=x,t[27]=r,t[28]=h,t[29]=d,t[30]=c,t[31]=D):D=t[31];let O;return t[32]!==T||t[33]!==E||t[34]!==D?(O=(0,$.jsxs)(`div`,{className:`mt-2`,children:[T,E,D]}),t[32]=T,t[33]=E,t[34]=D,t[35]=O):O=t[35],O},JO=e=>{let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},YO=(e,t)=>{if(t&&typeof t==`object`)return{output:typeof t.output==`number`&&Number.isFinite(t.output)?Math.max(0,t.output):0,reasoning:typeof t.reasoning==`number`&&Number.isFinite(t.reasoning)?Math.max(0,t.reasoning):0};for(let t of e){let e=t.tokens;if(!(!e||typeof e!=`object`))return{output:typeof e.output==`number`&&Number.isFinite(e.output)?Math.max(0,e.output):0,reasoning:typeof e.reasoning==`number`&&Number.isFinite(e.reasoning)?Math.max(0,e.reasoning):0}}return{output:0,reasoning:0}},XO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:s,hasTextContent:c,onCopyMessage:l,copiedMessage:u,onShowPopup:d,agentMention:f,onEdit:p,onRevert:m,onFork:h,pendingMessageAction:g,editing:_,editStaged:v,onCancelEdit:y,userActionsMode:b=`inline`,stickyUserHeaderEnabled:x=!0})=>{let{locale:S,t:C}=ct(),w=Tg(),T=zh(Rh()),E=q(e=>e.timeFormatPreference),[D,O]=Z.useState(!1),k=Z.useRef(null),A=Z.useMemo(()=>n.filter(e=>e.type===`text`?!Vi(e):!!(VO(e)||HO(e))),[n]),j=Z.useMemo(()=>A.map(e=>Wn(e)?ES(Pn(e)):void 0),[A]),M=f?.token,N=!1,P=!!l,F=!!u,I=!!(s??a),L=!!c,R=b!==`external-actions`,z=b!==`external-content`,B=x&&b===`inline`,V=J(()=>{k.current!==null&&typeof window<`u`&&(window.clearTimeout(k.current),k.current=null)}),H=J(()=>{!I||!P||!L||typeof window>`u`||(V(),O(!0),k.current=window.setTimeout(()=>{O(!1),k.current=null},1800))});Z.useEffect(()=>{L||(O(!1),V())},[V,L]);let U=J(e=>{!l||!L||(e.stopPropagation(),e.preventDefault(),l(),I&&H())}),W=w===`mini-chat`||!T.fork?void 0:h,ee=Z.useMemo(()=>{if(typeof i!=`number`||i<=0)return null;let e=nD(i,E);return e.length>0?e:null},[S,i,E]),G=Y(`group/user-actions`,a?b===`inline`?`flex items-center justify-end pt-2 pb-3`:x?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:b===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),K=!_&&v&&z?(0,$.jsx)(`div`,{className:G,children:(0,$.jsxs)(`div`,{className:Y(TO,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(DO,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:kO,name:`edit`,className:OO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:C(`chat.messageBody.actions.editStaged`)})]}),y?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":C(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),y()},children:(0,$.jsx)(X,{weight:kO,name:`close`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,te=(_&&z?(0,$.jsx)(`div`,{className:G,children:(0,$.jsx)(`div`,{className:Y(TO,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(DO,`animate-text-shimmer`),"aria-live":`polite`,children:C(`chat.messageBody.actions.editing`)})})}):null)??K??((P&&L||p||m||W)&&z?(0,$.jsx)(`div`,{className:G,children:(0,$.jsxs)(`div`,{className:Y(TO,`justify-end`,!a&&b===`inline`&&`translate-x-5`,o?`pointer-events-auto opacity-100`:`pointer-events-none opacity-0 transition-opacity duration-150 group-hover/message:pointer-events-auto group-hover/message:opacity-100 group-hover/user-actions:pointer-events-auto group-hover/user-actions:opacity-100 group-hover/user-shell:pointer-events-auto group-hover/user-shell:opacity-100`),"data-message-action-group":`true`,children:[ee?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(DO,`mr-1`),"aria-label":`Message time: ${ee}`,children:[(0,$.jsx)(X,{weight:kO,name:`time`,className:OO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:ee})]})}),(0,$.jsx)(Ua,{children:ee})]}):null,m&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":C(`chat.messageBody.actions.revertAria`),"aria-busy":g===`revert`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:kO,name:g===`revert`?`loader-4`:`arrow-go-back`,className:Y(SO,g===`revert`&&`animate-spin`)})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.revert`)})]}),p&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":C(`chat.messageBody.actions.editAria`),disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),p()},children:(0,$.jsx)(X,{weight:kO,name:`edit`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.edit`)})]}),W&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":C(`chat.messageBody.actions.forkAria`),"aria-busy":g===`fork`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),W()},children:(0,$.jsx)(X,{weight:kO,name:g===`fork`?`loader-4`:`git-branch`,className:Y(SO,g===`fork`&&`animate-spin`)})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.fork`)})]}),P&&L&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":D||F?`true`:void 0,className:xO,"aria-label":C(`chat.messageBody.actions.copyMessageAria`),onPointerDown:e=>e.stopPropagation(),onClick:U,onFocus:()=>O(!0),onBlur:()=>{F||O(!1)},children:F?(0,$.jsx)(X,{weight:kO,name:`check`,className:Y(SO,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:kO,name:`file-copy`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return R?(0,$.jsxs)(`div`,{className:`relative w-full group/message`,style:_O,onTouchStart:I&&P&&L?H:void 0,children:[(0,$.jsx)(`div`,{className:Y(`leading-relaxed text-foreground/90 text-base overflow-x-hidden`,B?`overflow-y-auto overscroll-contain scrollbar-none`:`overflow-y-hidden`),style:B?{maxHeight:`calc(var(--chat-scroll-height, 100dvh) * 0.4)`}:void 0,children:A.map((e,i)=>{if(VO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(WO,{part:e})},e.id??`user-subtask-${i}`);if(HO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(qO,{part:e})},e.id??`user-shell-${i}`);let o=j[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(GO,{notification:o})},e.id??`subagent-notification-${i}`);let s;return f&&M&&!N&&Pn(e).includes(M)&&(s=f,N=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(rS,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(Gd,{files:n,messageID:t,sessionID:e,onShowPopup:d,compact:!0}),te]}):(0,$.jsx)($.Fragment,{children:te})}),ZO=Z.memo(({hasCopyableText:e,isTouchContext:t,onCopyMessage:n,reviewTransferAction:r,ttsText:i,sessionId:a})=>{let{t:o}=ct(),s=Tg(),c=Rh(),l=zh(c),{isPlaying:u,play:d,stop:f}=IE(),p=Ai(e=>e.showMessageTTSButtons),m=Ai(e=>e.voiceProvider),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),[y,b]=Z.useState(!1),x=Z.useRef(null),S=Z.useRef(null),C=!!n,w=!!((c.sessionId||a)&&c.directory&&l.openSourceSession&&s!==`mini-chat`),T=J(()=>{x.current!==null&&typeof window<`u`&&(window.clearTimeout(x.current),x.current=null)}),E=J(()=>{S.current!==null&&typeof window<`u`&&(window.clearTimeout(S.current),S.current=null)});Z.useEffect(()=>()=>{T(),E()},[E,T]),Z.useEffect(()=>{(!e||!C)&&(g(!1),v(!1),T(),E())},[C,E,T,e]);let D=J(()=>{!t||!C||!e||typeof window>`u`||(T(),g(!0),x.current=window.setTimeout(()=>{g(!1),x.current=null},1800))}),O=J(async r=>{!n||!e||(r.stopPropagation(),r.preventDefault(),await n()!==!1&&(E(),v(!0),typeof window<`u`&&(S.current=window.setTimeout(()=>{v(!1),S.current=null},2e3)),t&&D()))}),k=J(async t=>{if(t.stopPropagation(),t.preventDefault(),!(!r||y||!e)){b(!0);try{await r.onClick()}finally{b(!1)}}}),A=J(e=>{e.stopPropagation(),e.preventDefault();let t=c.sessionId||a;!t||!c.directory||!c.openSourceSession||c.openSourceSession(t,c.directory)}),j=Z.useMemo(()=>u?o(`chat.messageBody.tts.stopSpeaking`):o(`chat.messageBody.tts.readAloudWithProvider`,{provider:m===`browser`?`Browser`:m===`openai`?`OpenAI`:m===`openai-compatible`?`Custom`:`Say`}),[u,o,m]),M=J(e=>{if(e.stopPropagation(),e.preventDefault(),u){f();return}i.trim()&&d(i)});return(0,$.jsxs)($.Fragment,{children:[n&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":h||_?`true`:void 0,className:Y(xO,!e&&`opacity-50`),disabled:!e,"aria-label":o(`chat.messageBody.actions.copyMessageAria`),"aria-hidden":!e,onPointerDown:e=>e.stopPropagation(),onClick:e=>{O(e)},onFocus:()=>{e&&g(!0)},onBlur:()=>{_||g(!1)},children:_?(0,$.jsx)(X,{weight:kO,name:`check`,className:Y(SO,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:kO,name:`file-copy`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:o(`chat.messageBody.actions.copyAnswer`)})]}),w?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":o(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:A,children:(0,$.jsx)(X,{weight:kO,name:`target`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:o(`chat.messageBody.actions.openSourceSession`)})]}):null,r&&s!==`mini-chat`&&l.reviewTransfer?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,size:`icon`,variant:`ghost`,disabled:y||!e,className:Y(xO,(!e||y)&&`opacity-50`),"aria-label":r.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{k(e)},children:y?(0,$.jsx)(X,{weight:kO,name:`loader-4`,className:Y(SO,`animate-spin`)}):(0,$.jsx)(X,{weight:kO,name:`arrow-left-right`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:r.tooltip})]}):null,s!==`mini-chat`&&p&&e&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:Y(xO,u?`text-green-500`:`hover:text-foreground/80`),"aria-label":o(u?`chat.messageBody.tts.stopSpeaking`:`chat.messageBody.tts.readAloud`),onPointerDown:e=>e.stopPropagation(),onClick:M,children:u?(0,$.jsx)(X,{weight:kO,name:`stop`,className:SO}):(0,$.jsx)(X,{weight:kO,name:`volume-up`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:j})]})]})}),QO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:s,messageTokens:c,isMobile:l,alwaysShowActions:u,hasTouchInput:d,expandedTools:f,onToggleTool:p,onShowPopup:m,streamPhase:h,allowAnimation:g,onContentChange:_,hasTextContent:v=!1,onCopyMessage:y,onAuxiliaryContentComplete:b,showReasoningTraces:x=!1,turnGroupingContext:S,errorMessage:C,errorVariant:w=`error`,reviewTransferDirection:T=null})=>{let{t:E,locale:D}=ct(),O=Tg(),k=zh(Rh()),A=h,j=Z.useRef(null),M=Z.useRef(null),N=h===`streaming`||h===`cooldown`,P=Z.useRef({messageId:t,experiencedStreamingOrCooldown:N});P.current.messageId===t?N&&(P.current.experiencedStreamingOrCooldown=!0):P.current={messageId:t,experiencedStreamingOrCooldown:N};let F=!!(d??l),I=!!(u??l),L=l?wO:CO,R=!i,z=Z.useMemo(()=>n.filter(e=>!Vi(e)).filter(e=>e.type!==`compaction`),[n]),B=Z.useMemo(()=>z.filter(e=>e.type===`tool`),[z]),V=Z.useMemo(()=>z.filter(e=>e.type===`text`),[z]),H=Z.useMemo(()=>Vn(V),[V]),U=q(e=>e.openContextPreview),W=se(),ee=O===`mini-chat`,G=Z.useMemo(()=>{if(W||l||ee)return null;for(let e of V){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=cc(t)[0];if(n)return n.includes(`0.0.0.0`)?n.replace(`0.0.0.0`,`127.0.0.1`):n}for(let e of B){let t=e.state,n=t&&typeof t.output==`string`?t.output:null;if(!n)continue;let r=cc(n.replace(/\x1b\[[0-9;]*m/g,``))[0];if(r)return r.includes(`0.0.0.0`)?r.replace(`0.0.0.0`,`127.0.0.1`):r}return null},[V,l,ee,W,B]),K=ri(e=>e.forkFromMessage),te=ri(e=>e.forkTransition),ne=ri(e=>e.currentSessionId),re=ri(e=>e.getDirectoryForSession),ie=pc(),ae=T===`review-to-original`,oe=!l&&!W?T:null,ce=Z.useMemo(()=>{let t=H.trim();if(!(!e||!ie||!t||!oe))return oe===`review-to-original`?{ariaLabel:E(`chat.messageBody.actions.sendReviewFeedback`),tooltip:E(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await vn(e,ie,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:E(`chat.messageBody.actions.sendImplementationResponse`),tooltip:E(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await jt(e,ie,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[H,ie,oe,e,E]),[le,ue]=Z.useState(!1),de=q(e=>e.chatRenderMode),fe=q(e=>e.collapsibleThinkingBlocks),pe=q(e=>e.showSplitAssistantMessageActions),me=q(e=>e.showAssistantTps),he=q(e=>e.timeFormatPreference),ge=de===`sorted`,_e=S?.isLastAssistantInTurn??!1,ve=a===`stop`,ye=(ve||i||!!C)&&(S?.isTurnSettled??!0),be=ve?`completed`:A,xe=B.length>0,Se=Z.useMemo(()=>B.some(e=>uw(e)),[B]),Ce=uw,we=lw,Te=P.current.experiencedStreamingOrCooldown,Ee=Z.useRef({messageId:t,initialized:!1,observedPartIds:new Set});Z.useEffect(()=>{if(Ee.current.messageId!==t&&(Ee.current={messageId:t,initialized:!1,observedPartIds:new Set}),!Te||!Et())return;let n=Ee.current,r=!n.initialized;n.initialized=!0;for(let i of B){if(n.observedPartIds.has(i.id))continue;if(!Hi(r,Ce(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Ki({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[Te,Ce,t,e,B]);let De=Z.useMemo(()=>B.length===0||!Se&&B.every(e=>we(e)),[B,Se,we]),Oe=Z.useMemo(()=>z.filter(e=>e.type===`reasoning`),[z]),ke=Z.useMemo(()=>Oe.length===0||Oe.every(e=>typeof e.time?.end==`number`),[Oe]),Ae=typeof a!=`string`,je=Oe.length>0&&xe&&(Se||Ae||!De),Me=R||xe&&(Se||Ae||!De),Ne=R||je,Pe=xe||Oe.length>0,Fe=V.length===0,Ie=Pe&&Fe&&!Me&&!Ne&&De&&ke,Le=Z.useRef(!1),Re=Z.useRef(!1);Z.useEffect(()=>{Re.current=!1},[t]),Z.useEffect(()=>{if(!Ie){Le.current=!1;return}Le.current||(Le.current=!0,b?.())},[Ie,b]),Z.useEffect(()=>{if(R){Re.current=!1;return}if(xe){Re.current=!1;return}Oe.length!==0&&(Ne||!ke||Re.current||(Re.current=!0,_?.(`structural`)))},[R,xe,_,ke,Oe.length,Ne]);let ze=!!v&&!R,Be=J(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||le||te)){ue(!0);try{await K(e,t)}finally{ue(!1)}}}),Ve=Z.useMemo(()=>{let e=S?.activityParts;return!ge||!e?[]:e},[ge,S?.activityParts]),He=Z.useMemo(()=>{let e=S?.activityGroupSegments;return!ge||!e?[]:e.filter(e=>e.anchorMessageId===t)},[ge,t,S?.activityGroupSegments]),Ue=He.length>0,We=Z.useMemo(()=>{let e=new Map,t=new Map;return Ve.forEach(n=>{e.set(n.part,n);let r=n.part.id;typeof r==`string`&&r.length>0&&t.set(r,n)}),{get:n=>{let r=e.get(n);if(r)return r;let i=n.id;if(typeof i==`string`&&i.length>0)return t.get(i)}}},[Ve]),Ge=S?.toggleGroup,Ke=S?.activityPresentationKind===`compaction`,qe=S?.isGroupExpanded===!0,Je=ge&&Ke&&!qe,Ye=ge?S?.activityOwnerMessageId===t||Ue:!S?.activityOwnerMessageId||S.activityOwnerMessageId===t||Ue,Xe=ge&&Ye&&(Ue||Ke)&&!!Ge,Ze=dE(a,z),Qe={finish:a,parts:z,streamPhase:be,error:C,isLastAssistantInTurn:_e},$e=gE(Qe),et=ge&&_E(Qe),tt=ge&&!$e&&!(Ke&&qe),nt=!!C,rt=w===`info`?`information`:`error-warning`,it=w===`muted`,at=ze,ot=_e&&ye&&!Je&&(v||!!C||i),st=S?.diffStats?.hasDiffs===!0,lt=!ee&&_e&&Ze&&ye&&!Je&&S?.diffStats?.hasDiffs===!0,dt=pe&&at&&!ot&&!ge,ft=Z.useMemo(()=>(0,$.jsx)(ZO,{hasCopyableText:ze,isTouchContext:F,onCopyMessage:y,ttsText:H,reviewTransferAction:ce,sessionId:e}),[H,ze,F,y,ce,e]),pt=Z.useMemo(()=>e=>{if(!pe||!ge)return null;let t=Pn(e.part).trim();return t?(0,$.jsx)(ZO,{hasCopyableText:!0,isTouchContext:F,onCopyMessage:async()=>(await ut(t)).ok,ttsText:t}):null},[ge,F,pe]),mt=Z.useMemo(()=>{if(!dt)return-1;let e=-1;for(let t=0;t<z.length;t+=1){let n=z[t];!n||n.type!==`text`||tt||We.get(n)?.kind!==`justification`&&(e=t)}return e},[We,tt,dt,z]),ht=dt&&mt<0,gt=Z.useMemo(()=>{let n=[];if(Xe&&Ge&&S){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(gO,{parts:t,materializationParts:r,isExpanded:S.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:S.completionDisposition,activityPresentationKind:S.activityPresentationKind,durationMs:S.durationMs,startedAt:S.userMessageCreatedAt,onToggle:Ge,isMobile:l,expandedTools:f,onToggleTool:p,onShowPopup:m,onContentChange:_,streamPhase:be,showHeader:!0,diffStats:S.diffStats,renderJustificationActions:pt})},`progressive-group-${e}`))};He.length>0?He.forEach(t=>{let n=x?t.parts:t.parts.filter(e=>e.kind!==`reasoning`);e(t.id,n,t.parts)}):Ke&&e(`${t}:compaction-status`,[])}let r=0;for(;r<z.length;){let i=z[r];if(i.type===`text`){let a=We.get(i);if(tt){r+=1;continue}if(Je){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:M,"data-message-text-export-source":`true`,children:(0,$.jsx)(UT,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,allowSortedFinalStreaming:et,hasStreamingHapticLifecycle:Te,onContentChange:_,onShowPopup:m})},`assistant-text-${t}-${i.id??r}`)),dt&&r===mt&&n.push((0,$.jsx)(`div`,{className:l?bO:yO,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:TO,"data-message-action-group":`true`,children:ft})},`message-actions-${t}`)),r++;continue}if(i.type===`reasoning`){if(We.get(i)?.kind===`reasoning`){r+=1;continue}if(!Pn(i).trim()){r+=1;continue}x&&(fe?n.push((0,$.jsx)(`div`,{className:pm(l),children:(0,$.jsx)(tE,{part:i,messageId:t,streamPhase:be,onContentChange:_})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(UT,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,hasStreamingHapticLifecycle:Te,onContentChange:_,onShowPopup:m},`reasoning-${t}-${i.id??r}`))),r++;continue}if(i.type===`tool`){let e=i,a=e.tool?.toLowerCase()??``;if(ge&&!Ye){r+=1;continue}if(We.get(i)?.kind===`tool`){r+=1;continue}if(cw(a)){let e=TD(z,r,e=>e.type!==`tool`||We.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(OD,{activities:i,isMobile:l,isTurnLive:be!==`completed`,hasFollowingOtherType:CD(z,e.end,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:i.map(e=>{let n=e.part.tool?.toLowerCase()??``;return aw(n)?(0,$.jsx)(cO,{toolName:n,activities:[e],isMobile:l,animateTailText:!1},e.id):(0,$.jsx)(CT,{part:e.part,messageId:t,isExpanded:f.has(e.part.id),onToggle:p,isMobile:l,alwaysShowActions:I,onContentChange:_,onShowPopup:m,animateTailText:!1},e.id)})},`context-tools-${i[0].id}`)),r=e.end;continue}}if(ow(a)){let e=kD(z,r,e=>e.type!==`tool`||We.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(PD,{activities:i,isMobile:l,children:i.map(e=>(0,$.jsx)(cO,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:l,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(nw(a)){n.push((0,$.jsx)(`div`,{className:pm(l),children:(0,$.jsx)(CT,{part:e,messageId:t,isExpanded:f.has(e.id),onToggle:p,isMobile:l,alwaysShowActions:I,onContentChange:_,onShowPopup:m,animateTailText:!1})},`tool-${e.id}`)),r++;continue}n.push((0,$.jsx)(`div`,{className:pm(l),children:(0,$.jsx)(cO,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:l,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}return n},[We,He,I,de,fe,0,f,Je,Ke,l,Ye,ge,mt,t,ft,pt,e,_,m,p,Xe,dt,be,Te,x,tt,et,Ge,S,z]),_t=Z.useMemo(()=>{if(!_e||!ye)return;let e=S?.durationMs;if(!(typeof e!=`number`||e<=0))return JO(e)},[_e,ye,S?.durationMs]),vt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof s==`number`&&s>0?s:null;if(e===null)return null;let t=nD(e,he);return t.length>0?t:null},[o,s,he,D]),yt=Z.useMemo(()=>{if(!me||!_e||!ye)return null;let e=r??n,t=YO(e,c),i=sD({createdAt:s,completedAt:o,fallbackDurationMs:S?.durationMs,outputTokens:t.output,reasoningTokens:t.reasoning,parts:e});if(i===null)return null;let a=cD(i);return a.length>0?a:null},[me,_e,ye,n,r,c,s,o,S?.durationMs]),bt=(0,$.jsxs)($.Fragment,{children:[!ee&&!l&&!W&&G?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":E(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=ie??(ne?re(ne):null);e&&U(e,G)},children:(0,$.jsx)(X,{weight:kO,name:`global`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:E(`chat.messageBody.actions.openPreview`)})]}):null,!ee&&!ae&&k.fork?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,size:`icon`,variant:`ghost`,className:xO,"aria-label":E(`chat.messageBody.actions.forkAria`),"aria-busy":le,disabled:le||!!te,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Be(e)},children:(0,$.jsx)(X,{weight:kO,name:le?`loader-4`:`git-branch`,className:Y(SO,le&&`animate-spin`)})})}),(0,$.jsx)(Ua,{sideOffset:6,children:E(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:j,"data-message-text-export-root":`true`,className:Y(`relative w-full group/message`),style:_O,children:[(0,$.jsx)(QE,{containerRef:j}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`message-content-text leading-relaxed text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0`,children:[gt,nt&&(0,$.jsx)(bc,{children:it?(0,$.jsxs)(`div`,{role:`status`,className:`my-1.5 flex max-w-full items-center gap-1.5 break-words typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`stop-circle`,className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0`,children:C})]}):(0,$.jsxs)(`div`,{className:Y(`group/assistant-text relative flow-root my-1.5 break-words max-w-full`,w===`info`?Y(`inline-flex w-fit max-w-full border border-[var(--status-info-border)]/45 bg-[var(--status-info-background)]/40`,l?`items-start gap-1.5 rounded-lg px-2.5 py-1.5`:Y(`items-center gap-1.5`,`rounded-lg px-2 py-0.5`)):`mt-3 flex items-center gap-2 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3`),children:[w===`info`&&l?(0,$.jsx)(`span`,{className:`inline-flex h-5 w-3.5 shrink-0 items-center justify-center translate-y-[2px]`,"aria-hidden":`true`,children:(0,$.jsx)(X,{name:rt,weight:kO,className:Y(SO,`text-[var(--status-info)]/80`)})}):(0,$.jsx)(X,{name:rt,weight:w===`info`?kO:void 0,className:Y(`shrink-0`,w===`info`?Y(SO,`text-[var(--status-info)]/80`):`h-4 w-4 text-[var(--status-error)]`)}),(0,$.jsx)(`div`,{className:Y(`min-w-0 break-words`,w===`info`?Y(`text-muted-foreground [&_.markdown-content]:text-muted-foreground [&_p]:m-0`,`[&_.markdown-content]:!leading-5`,l?`[&_.markdown-content]:!text-[length:var(--text-meta)]`:`[&_.markdown-content]:!text-[13px]`):`flex-1`),children:(0,$.jsx)(Ns,{content:C??``,onShowPopup:m,className:`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,enableFileReferences:!1})})]})},`assistant-error`)]}),lt&&S?.diffStats?(0,$.jsx)(BO,{fileCount:S.diffStats.files,changedFiles:S.changedFiles,turnId:S.turnId,isLatestTurn:S.isLatestTurn,isMobile:l}):null,(0,$.jsx)(Gd,{files:n,messageID:t,sessionID:e,onShowPopup:m}),ht&&(0,$.jsx)(`div`,{className:Y(l?bO:yO),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:TO,"data-message-action-group":`true`,children:ft})}),ot&&(0,$.jsxs)(`div`,{className:L,"data-message-footer":`true`,style:vO,children:[(0,$.jsxs)(`div`,{className:TO,"data-message-action-group":`true`,children:[ft,bt]}),yt||_t||vt?(0,$.jsxs)(`div`,{className:EO,children:[yt?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:DO,"aria-label":E(`chat.messageBody.meta.tpsAria`,{rate:yt}),children:[(0,$.jsx)(X,{weight:kO,name:`pulse`,className:OO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:yt})]})}),(0,$.jsx)(Ua,{children:E(`chat.messageBody.meta.tpsTooltip`)})]}):null,_t?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:DO,children:[(0,$.jsx)(X,{weight:kO,name:`hourglass`,className:OO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:_t})]})}),(0,$.jsx)(Ua,{children:_t})]}):null,vt?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:DO,"aria-label":`Message time: ${vt}`,children:[(0,$.jsx)(X,{weight:kO,name:`time`,className:OO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:vt})]})}),(0,$.jsx)(Ua,{children:vt})]}):null]}):null,!ee&&_e&&ve&&!st?(0,$.jsx)(aE,{activityParts:S?.activityParts}):null]})]})]})}),$O=Z.memo(e=>{let t=(0,Q.c)(28),n,r;if(t[0]===e?(n=t[1],r=t[2]):({isUser:n,...r}=e,t[0]=e,t[1]=n,t[2]=r),n){let e;return t[3]!==r.agentMention||t[4]!==r.alwaysShowActions||t[5]!==r.copiedMessage||t[6]!==r.editStaged||t[7]!==r.editing||t[8]!==r.hasTextContent||t[9]!==r.hasTouchInput||t[10]!==r.isMobile||t[11]!==r.messageCreatedAt||t[12]!==r.messageId||t[13]!==r.onCancelEdit||t[14]!==r.onCopyMessage||t[15]!==r.onEdit||t[16]!==r.onFork||t[17]!==r.onRevert||t[18]!==r.onShowPopup||t[19]!==r.parts||t[20]!==r.pendingMessageAction||t[21]!==r.sessionId||t[22]!==r.sourceParts||t[23]!==r.stickyUserHeaderEnabled||t[24]!==r.userActionsMode?(e=(0,$.jsx)(XO,{sessionId:r.sessionId,messageId:r.messageId,parts:r.parts,sourceParts:r.sourceParts,messageCreatedAt:r.messageCreatedAt,isMobile:r.isMobile,alwaysShowActions:r.alwaysShowActions,hasTouchInput:r.hasTouchInput,hasTextContent:r.hasTextContent,onCopyMessage:r.onCopyMessage,copiedMessage:r.copiedMessage,onShowPopup:r.onShowPopup,agentMention:r.agentMention,onEdit:r.onEdit,onRevert:r.onRevert,onFork:r.onFork,pendingMessageAction:r.pendingMessageAction,editing:r.editing,editStaged:r.editStaged,onCancelEdit:r.onCancelEdit,userActionsMode:r.userActionsMode,stickyUserHeaderEnabled:r.stickyUserHeaderEnabled}),t[3]=r.agentMention,t[4]=r.alwaysShowActions,t[5]=r.copiedMessage,t[6]=r.editStaged,t[7]=r.editing,t[8]=r.hasTextContent,t[9]=r.hasTouchInput,t[10]=r.isMobile,t[11]=r.messageCreatedAt,t[12]=r.messageId,t[13]=r.onCancelEdit,t[14]=r.onCopyMessage,t[15]=r.onEdit,t[16]=r.onFork,t[17]=r.onRevert,t[18]=r.onShowPopup,t[19]=r.parts,t[20]=r.pendingMessageAction,t[21]=r.sessionId,t[22]=r.sourceParts,t[23]=r.stickyUserHeaderEnabled,t[24]=r.userActionsMode,t[25]=e):e=t[25],e}let i;return t[26]===r?i=t[27]:(i=(0,$.jsx)(QO,{...r}),t[26]=r,t[27]=i),i});function ek(e){return e.openContextPanelTab}function tk(e){return e.setCurrentSession}function nk(e){return e.openContextPanelTab}function rk(e){return!e}function ik(e){return e.openContextPanelTab}function ak(e){return!e}var ok=e=>{let t=e,n=t?.clientRole,r=t?.role;return t?.userMessageMarker===!0||n===`user`||r===`user`||t?.origin===`user`||t?.source===`user`?{role:`user`,isUser:!0}:{role:n||r||`assistant`,isUser:!1}},sk=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,ck=e=>!e,lk=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},uk=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),dk=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,fk=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,pk=`Authentication failed for this provider. Please re-authenticate and retry.`,mk=e=>{if(typeof e!=`string`)return!1;let t=e.toLowerCase().trim();if(!t)return!1;if(t.includes(`token refresh failed`)||t.includes(`unauthorized`)||t.includes(`invalid token`)||t.includes(`expired token`))return!0;let n=t.includes(`oauth`),r=t.includes(`failed`)||t.includes(`invalid`)||t.includes(`expired`);if(n&&r)return!0;let i=/\b401\b/.test(t),a=t.includes(`auth`)||t.includes(`token`)||t.includes(`unauthorized`);return i&&a};function hk(e,t){if(!e||typeof e!=`object`)return;let n=e,r=typeof n.data?.message==`string`?n.data.message:void 0,i=typeof n.message==`string`?n.message:void 0,a=typeof n.name==`string`?n.name:void 0,o=r||i||a;if(o)return a===`SessionRetry`?{text:`Opencode failed to send a message. Retry attempt info: \n\`${o}\``,variant:`info`}:mk(o)?{text:pk,variant:`error`}:a===`MessageAbortedError`||o.trim().toLowerCase()===`aborted`?{text:t,variant:`muted`}:{text:`Opencode failed to send message with error:\n\`${o}\``,variant:`error`}}var gk=ks(()=>Ue(()=>import(`./ToolOutputDialog-CFFkJzQ4.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48]))),_k=4e3,vk=new Map,yk=new Map,bk=new Set([`bash`,`shell`,`cmd`,`terminal`]),xk=e=>{if(typeof e!=`string`)return``;let t=e.trim().toLowerCase();if(!t)return``;let n=t.replace(/:\d+$/,``);if(!n.includes(`.`))return n;let r=n.split(`.`).filter(Boolean);return r[r.length-1]??n},Sk=e=>{let t=vk.get(e);return t?new Set(t):new Set},Ck=(e,t)=>{if(vk.size>=_k&&!vk.has(e)){let e=vk.keys().next().value;typeof e==`string`&&vk.delete(e)}vk.set(e,new Set(t))},wk=e=>{let t=yk.get(e);return t?new Set(t):new Set},Tk=(e,t)=>{if(yk.size>=_k&&!yk.has(e)){let e=yk.keys().next().value;typeof e==`string`&&yk.delete(e)}yk.set(e,new Set(t))},Ek=200,Dk=new Map,Ok=e=>Dk.get(e),kk=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=Dk.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(Dk.size>=Ek&&!Dk.has(e)){let e=Dk.keys().next().value;typeof e==`string`&&Dk.delete(e)}Dk.set(e,t)}};function Ak(e){let t=(0,Q.c)(3),[n,r]=Z.useState(e),i,a;return t[0]===e?(i=t[1],a=t[2]):(i=()=>{e!=null&&r(e)},a=[e],t[0]=e,t[1]=i,t[2]=a),Z.useEffect(i,a),e??n}var jk=(e,t)=>{if(typeof e==`object`&&e)return e[t]},Mk=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s=!1,activeStreamingPhase:c=null,animateUserOnMount:l=!1,onUserAnimationConsumed:u,reviewTransferDirection:d=null})=>{let{t:f}=ct(),{isMobile:p,isTablet:m,hasTouchInput:h}=mo(),g=Rh(),_=zh(g),v=p||m,y=Z.useRef(null),b=ri(e=>e.currentSessionId),x=Zi(e=>e.getAgentModelForSession),S=Zi(e=>e.getSessionModelSelection),C=ri(e=>e.revertToMessage),w=ri(e=>e.editMessagePreservingChanges),T=ri(e=>e.forkFromMessage),E=ri(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),D=ri(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),O=ri(e=>e.clearStagedMessageEdit);Fe(`ui.chat_message.render`),s&&Fe(`ui.chat_message.render.streaming`);let k=Ai(e=>e.providers),{showReasoningTraces:A,stickyUserHeader:j,chatRenderMode:M,showExpandedBashTools:N}=q(de(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{b&&Gx.getInstance().recordSessionStart(b)},[b]);let[P,F]=Z.useState(null),[I,L]=Z.useState(!1),[R,z]=Z.useState(null),B=Z.useRef(null),[V,H]=Z.useState(()=>Sk(e.info.id)),[U,W]=Z.useState(()=>wk(e.info.id)),[ee,G]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{H(Sk(e.info.id)),W(wk(e.info.id))},[e.info.id]);let K=Z.useMemo(()=>ok(e.info),[e.info]).isUser,te=K&&(p||!j),ne=K&&!p&&j&&!te,re=e.info.sessionID,{currentContextAgent:ie,savedSessionAgentSelection:ae}=km(de(e=>({currentContextAgent:s&&re?e.currentAgentContext.get(re):void 0,savedSessionAgentSelection:s&&re?e.sessionAgentSelections.get(re):void 0}))),oe=Z.useMemo(()=>Rn(e.sourceParts??e.parts),[e.parts,e.sourceParts]),se=Z.useMemo(()=>K?Gi(oe):Rn(e.parts),[K,e.parts,oe]),ce=Z.useMemo(()=>{if(K||!t)return null;let e=jk(t.info,`clientRole`),n=jk(t.info,`role`);if((typeof e==`string`?e:typeof n==`string`?n:void 0)!==`user`)return null;let r=jk(t.info,`mode`),i=jk(t.info,`agent`),a=jk(t.info,`providerID`),o=jk(t.info,`modelID`),s=jk(t.info,`model`),c=typeof s==`object`&&s?s.variant:void 0,l=jk(t.info,`variant`),u=c??l,d=typeof s==`object`&&s?s.providerID:void 0,f=typeof s==`object`&&s?s.modelID:void 0,p=typeof r==`string`&&r.trim().length>0?r:typeof i==`string`&&i.trim().length>0?i:void 0,m=typeof a==`string`&&a.trim().length>0?a:typeof d==`string`&&d.trim().length>0?d:void 0,h=typeof o==`string`&&o.trim().length>0?o:typeof f==`string`&&f.trim().length>0?f:void 0,g=typeof u==`string`&&u.trim().length>0?u:void 0;return!p&&!m&&!h&&!g?null:{agentName:p,providerId:m,modelId:h,variant:g}},[K,t]),le=Z.useMemo(()=>{if(K)return;let t=jk(e.info,`mode`);if(typeof t==`string`&&t.trim().length>0)return t;let n=jk(e.info,`agent`);if(typeof n==`string`&&n.trim().length>0)return n;if(ce?.agentName)return ce.agentName;if(re)return ie||(ae??void 0)},[K,e.info,ce,re,ie,ae]),ue=K?null:jk(e.info,`providerID`),fe=K?null:jk(e.info,`modelID`),pe=Z.useMemo(()=>{if(K||!re)return null;if(ce?.providerId&&ce?.modelId)return{providerId:ce.providerId,modelId:ce.modelId};if(le){let e=x(re,le);if(e?.providerId&&e?.modelId)return e}let e=S(re);return e?.providerId&&e?.modelId?e:null},[K,re,le,ce,x,S]),me=Z.useMemo(()=>K?null:typeof ue==`string`&&ue.trim().length>0?ue:pe?.providerId??null,[K,ue,pe]),he=Z.useMemo(()=>K?null:typeof fe==`string`&&fe.trim().length>0?fe:pe?.modelId??null,[K,fe,pe]),ge=e.info.id?Ok(e.info.id):void 0;K||kk(e.info.id,{agent:le,provider:me??void 0,model:he??void 0});let _e=le??ge?.agent,ve=me??ge?.provider??null,ye=he??ge?.model??null,be=Z.useMemo(()=>{if(K)return;let e=ve&&k.length>0?k.find(e=>e.id===ve):void 0;return Si(e,ye)||void 0},[K,ve,ye,k]),xe=Z.useMemo(()=>{if(K||!me||!he)return!1;let e=k.find(e=>e.id===me);if(!e?.models||!Array.isArray(e.models))return!1;let t=e.models.find(e=>e.id===he)?.variants;return!!(t&&Object.keys(t).length>0)},[K,he,me,k]),Se=Ak(_e),Ce=Ak(ve??void 0),we=Ak(ye??void 0),Te=Ak(be),Ee=Se??void 0,De=Ce??null,Oe=we??null,ke=Te??void 0,Ae=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),je=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Me=Z.useMemo(()=>K?!0:!!(Ae&&Ae>0),[K,Ae]),Ne=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),Pe=Z.useMemo(()=>{if(K)return null;let t=e.info.tokens;return!t||typeof t!=`object`?null:{output:typeof t.output==`number`?t.output:void 0,reasoning:typeof t.reasoning==`number`?t.reasoning:void 0}},[K,e.info]),Ie=Z.useMemo(()=>wt(se,{includeReasoning:A}),[se,A]),Le=Z.useMemo(()=>K?Ie:!Me&&M===`sorted`?[]:Ie,[M,Me,K,Ie]),Re=Z.useMemo(()=>K?[]:Ie.filter(e=>e.type===`text`),[K,Ie]),ze=Z.useMemo(()=>K?[]:Ie.filter(e=>e.type===`tool`),[K,Ie]),Be=Z.useMemo(()=>{if(!N)return new Set;let e=new Set;for(let t of ze){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=xk(t.tool);!r||!bk.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=xk(t.part.tool);!n||!bk.has(n)||e.add(t.id)}return e},[N,ze,a?.activityParts]),Ve=Z.useMemo(()=>{if(Be.size===0&&U.size===0)return V;let e=new Set(V);return Be.forEach(t=>{U.has(t)||e.add(t)}),U.forEach(t=>{e.delete(t)}),e},[U,Be,V]),He=Z.useMemo(()=>{if(!K)return;let e=se.find(e=>e.type===`agent`);if(!e)return;let t=e,n=typeof t.name==`string`?t.name:void 0;if(n)return{name:n,token:t.source&&typeof t.source.value==`string`&&t.source.value.trim().length>0?t.source.value:`@${n}`}},[K,se]),Ue=K&&!hr(Le),We=typeof Ne!=`string`,Ge=Z.useMemo(()=>K?!1:Re.length===0||ze.length===0?We:!0,[Re.length,ze.length,We,K]),Ke=Z.useMemo(()=>!K&&Gx.getInstance().shouldAnimateMessage(e.info,b||e.info.sessionID),[e.info,b,K]),[qe,Je]=Z.useState(!1),Ye=Z.useMemo(()=>n?ok(n.info):null,[n]),Xe=!!a,Ze=a?.isLastAssistantInTurn??!1,Qe=dk({isWorking:a?.isWorking===!0,isInActiveTurn:s,headerCompletionDisposition:a?.completionDisposition}),$e=Z.useMemo(()=>K?!1:Xe?!Ze:Ye?!Ye.isUser&&Ye.role===`assistant`:!1,[Xe,Ze,K,Ye]),et=Z.useMemo(()=>Me?`completed`:s?c??`streaming`:`completed`,[c,s,Me]);Z.useEffect(()=>{!K||!l||u?.(e.info.id)},[l,K,e.info.id,u]),Z.useEffect(()=>{Je(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;K||!t||t!==e.info.id||(et===`streaming`||et===`cooldown`)&&Je(!0)},[o,K,e.info.id,et,a?.headerMessageId]);let tt=Z.useMemo(()=>{if(K)return!0;let t=o??a?.headerMessageId;return t?e.info.id===t?et===`completed`||qe||et===`streaming`||et===`cooldown`:!1:!0},[o,qe,K,a,et,e.info.id]),nt=Z.useCallback(e=>{ut(e).then(t=>{t.ok&&(F(e),setTimeout(()=>F(null),2e3))})},[]),rt=K?void 0:a?.userMessageVariant??ce?.variant,it=!K&&xe&&typeof rt==`string`&&rt.trim().length>0?rt:void 0,at=Z.useMemo(()=>{if(!K)return hk(e.info?.error,f(`chat.messageBody.aborted`))},[K,e.info,f]),ot=at?.text,st=at?.variant,lt=Z.useMemo(()=>{if(K){let e=Le.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.output;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);if(e.length>0)return e.join(`
6574
+ `).trim()||HE(t)},QE=({containerRef:e})=>{let{t}=ct(),[n,r]=Z.useState({x:0,y:0,show:!1}),[i,a]=Z.useState(``),[o,s]=Z.useState(``),c=Z.useRef(!1),[l,u]=Z.useState(!1),d=Z.useRef(null),f=Z.useRef(RE),p=Z.useRef(null),m=Z.useRef(null),h=Z.useRef(null),g=Z.useRef(!1),_=ri(e=>e.createSession),v=ei(e=>e.setPendingInputText),y=q(e=>e.isMobile),b=zh(Rh()).textSelectionMutation;Z.useEffect(()=>{g.current=n.show},[n.show]),Z.useEffect(()=>()=>{m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null),h.current!==null&&(window.clearTimeout(h.current),h.current=null)},[]);let x=Z.useCallback(()=>{p.current=null,zE===x&&(zE=null),g.current&&=(m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null),u(!1),r(e=>({...e,show:!1})),a(``),s(``),!1)},[]);Z.useEffect(()=>()=>{zE===x&&(zE=null)},[x]);let S=Z.useCallback(e=>{if(typeof window>`u`)return e;let t=window.innerWidth,n=f.current/2,r=LE+n,i=t-LE-n;return r>i?t/2:Math.min(Math.max(e,r),i)},[]),C=Z.useCallback(()=>{if(!p.current)return;zE!==x&&(zE?.(),zE=x);let{plainText:e,markdownText:t,rect:i}=p.current,o=!n.show,c=y?i.left+i.width/2:S(i.left+i.width/2),l=i.top-10;a(e),s(t),r({x:c,y:l,show:!0}),g.current=!0,o&&(u(!0),m.current!==null&&window.cancelAnimationFrame(m.current),m.current=window.requestAnimationFrame(()=>{u(!1),m.current=null}))},[S,x,y,n.show]);Z.useLayoutEffect(()=>{if(!n.show||y||!d.current)return;let e=d.current.offsetWidth;!Number.isFinite(e)||e<=0||e===f.current||(f.current=e,r(e=>({...e,x:S(e.x)})))},[S,y,n.show]),Z.useEffect(()=>{if(!n.show||y)return;let e=()=>{r(e=>({...e,x:S(e.x)}))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[S,y,n.show]);let w=Z.useCallback(()=>{let t=window.getSelection(),n=e.current;if(!t||!n){c.current||x();return}let r=HE(t.toString());if(!r){c.current||x();return}let i=GE(t,n);if(!i){c.current||x();return}let a=i.getBoundingClientRect();p.current={plainText:r,markdownText:ZE(i,r),rect:a},c.current||C()},[e,x,C]);Z.useEffect(()=>{let t=e.current;if(!t)return;let n=()=>{c.current=!0,x()},r=()=>{c.current=!1,h.current!==null&&window.clearTimeout(h.current),h.current=window.setTimeout(()=>{h.current=null,w()},10)},i=new Set,a=()=>{for(let e of WE(t))i.has(e)||(i.add(e),e.addEventListener(`selectionchange`,w))};a();let o=new MutationObserver(a);o.observe(t,{childList:!0,subtree:!0}),document.addEventListener(`selectionchange`,w),t.addEventListener(`mousedown`,n),document.addEventListener(`mouseup`,r);let s=e=>{d.current&&!d.current.contains(e.target)&&!window.getSelection()?.toString().trim()&&x()};return document.addEventListener(`mousedown`,s),()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null),o.disconnect();for(let e of i)e.removeEventListener(`selectionchange`,w);document.removeEventListener(`selectionchange`,w),t.removeEventListener(`mousedown`,n),document.removeEventListener(`mouseup`,r),document.removeEventListener(`mousedown`,s)}},[e,w,x,C]),Z.useEffect(()=>{if(!n.show)return;let e=e=>{d.current&&e.target instanceof Node&&d.current.contains(e.target)||x()};return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),()=>{window.removeEventListener(`scroll`,e,!0)}},[n.show,x]);let T=Z.useCallback(e=>{if(!e)return;let t=`\`\`\`md\n${e}\n\`\`\``;v(t,`append`),x(),window.getSelection()?.removeAllRanges()},[v,x]),E=Z.useCallback(()=>{T(o)},[T,o]);Z.useEffect(()=>{let t=t=>{if(!b||!t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||t.key.toLowerCase()!==`i`)return;let n=window.getSelection(),r=e.current;if(!n||!r||!n.toString().trim())return;let i=GE(n,r);i&&(t.preventDefault(),T(ZE(i,n.toString())))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[T,b,e]);let D=Z.useCallback(async()=>{i&&(await _(void 0,null,null)&&v(i,`replace`),x(),window.getSelection()?.removeAllRanges())},[i,_,v,x]),O=Z.useCallback(async()=>{if(!i)return;let e=await ut(i);e.ok||console.error(`Failed to copy:`,e.error),x(),window.getSelection()?.removeAllRanges()},[i,x]);return n.show?y?(0,rl.createPortal)((0,$.jsx)(`div`,{ref:d,className:Y(`fixed left-3 right-3 bottom-0 z-50 mx-auto max-w-[420px]`,`rounded-2xl border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] p-2 shadow-lg`,`safe-area-bottom`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,l?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),style:{bottom:`calc(0.5rem + env(safe-area-inset-bottom, 0px))`},children:(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[b?(0,$.jsxs)(`button`,{onClick:E,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--primary-base)] text-[var(--primary-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.addToChat`)})]}):null,b?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.newSession`)})]}):null,(0,$.jsxs)(`button`,{onClick:O,className:Y(`col-span-2 flex min-w-0 items-center gap-2 rounded-xl px-3 py-2.5 text-left`,`text-sm font-medium leading-tight`,`bg-[var(--surface-muted)] text-[var(--surface-foreground)]`,`active:opacity-80`,`transition-opacity duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-5 w-5 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 whitespace-normal`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):(0,rl.createPortal)((0,$.jsx)(`div`,{ref:d,className:`fixed z-50`,style:{left:n.x,top:n.y,transform:`translate(-50%, -100%)`},children:(0,$.jsxs)(`div`,{className:Y(`flex items-center gap-1 whitespace-nowrap`,`rounded-lg border border-[var(--interactive-border)]`,`bg-[var(--surface-elevated)] shadow-none`,`px-1.5 py-1`,`transition-[opacity,transform] duration-200 ease-out will-change-[opacity,transform]`,l?`opacity-0 translate-y-[4px]`:`opacity-100 translate-y-0`),children:[b?(0,$.jsxs)(`button`,{onClick:E,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.addToCurrentChat`),type:`button`,children:[(0,$.jsx)(X,{name:`add`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.addToChat`)}),(0,$.jsx)(Zp,{shortcut:`⌘+I`})]}):null,b?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,b?(0,$.jsxs)(`button`,{onClick:D,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.title.newSessionWithSelection`),type:`button`,children:[(0,$.jsx)(X,{name:`chat-new`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.newSession`)})]}):null,b?(0,$.jsx)(`div`,{className:`w-px h-4 bg-[var(--interactive-border)]`}):null,(0,$.jsxs)(`button`,{onClick:O,className:Y(`flex items-center gap-1.5 px-2 py-1 rounded-md`,`text-sm font-medium`,`text-[var(--surface-foreground)]`,`hover:bg-[var(--interactive-hover)]`,`transition-colors duration-150`),title:t(`chat.textSelection.actions.copy`),type:`button`,children:[(0,$.jsx)(X,{name:`file-copy`,className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`whitespace-nowrap`,children:t(`chat.textSelection.actions.copy`)})]})]})}),document.body):null},$E=(e,t)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate(),eD=(e,t)=>{let n=new Date(t);return n.setDate(t.getDate()-1),$E(e,n)},tD=e=>Number.isFinite(e)&&!Number.isNaN(new Date(e).getTime()),nD=(e,t)=>{if(!tD(e))return``;let n=new Date(e),r=new Date,i=co(n,t),a=lt(),o=dt.getState().dictionary;if($E(n,r))return i;if(eD(n,r))return ft(o,`common.date.yesterdayWithTime`,{time:i});let s=`${n.toLocaleString(a,{month:`short`})} ${n.getDate()}`;return n.getFullYear()===r.getFullYear()?`${s}, ${i}`:`${s}, ${n.getFullYear()}, ${i}`},rD=e=>typeof e!=`number`||!Number.isFinite(e)||e<0?0:e,iD=e=>e,aD=e=>{if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let n of e){let e=iD(n);if(e.type!==`tool`)continue;let r=e.state,i=r?.time?.start,a=r?.time?.end;typeof i!=`number`||!Number.isFinite(i)||typeof a!=`number`||!Number.isFinite(a)||a<i||(t+=a-i)}return t},oD=(e,t,n,r)=>{let i=(typeof e==`number`&&Number.isFinite(e)&&e>0&&typeof t==`number`&&Number.isFinite(t)&&t>e?t-e:null)??(typeof r==`number`&&Number.isFinite(r)&&r>0?r:null);if(i===null)return null;let a=i-aD(n);return!Number.isFinite(a)||a<=0?null:a},sD=e=>{let t=oD(e.createdAt,e.completedAt,e.parts,e.fallbackDurationMs);if(t===null)return null;let n=rD(e.outputTokens)+rD(e.reasoningTokens);if(n<=0)return null;let r=t/1e3;if(r<=0)return null;let i=n/r;return!Number.isFinite(i)||i<=0?null:i},cD=e=>{if(!Number.isFinite(e)||e<=0)return``;if(e>=1e3){let t=e/1e3;return`${t>=10?t.toFixed(0):t.toFixed(1)}k tok/s`}return e>=100?`${Math.round(e)} tok/s`:e>=10?`${e.toFixed(1)} tok/s`:`${e.toFixed(2)} tok/s`},lD=e=>{let t=(0,Q.c)(20),{text:n,active:r,className:i}=e,a=Z.useRef(n),[o,s]=Z.useState(n),[c,l]=Z.useState(null),u,d;t[0]!==r||t[1]!==n?(u=()=>{if(n===a.current)return;let e=a.current;if(a.current=n,!r||e.length===0){l(null),s(n);return}l(e),s(n)},d=[r,n],t[0]=r,t[1]=n,t[2]=u,t[3]=d):(u=t[2],d=t[3]),Z.useEffect(u,d);let f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>{l(null)},t[4]=f):f=t[4];let p=J(f),m;t[5]===i?m=t[6]:(m=Y(`oc-summary-flip-viewport relative block h-5 min-h-0 w-full min-w-0 max-w-full overflow-clip sm:h-6`,i),t[5]=i,t[6]=m);let h=c&&`invisible`,g;t[7]===h?g=t[8]:(g=Y(`block h-full min-w-0 truncate leading-5 sm:leading-6`,h),t[7]=h,t[8]=g);let _;t[9]!==o||t[10]!==g?(_=(0,$.jsx)(`span`,{className:g,children:o}),t[9]=o,t[10]=g,t[11]=_):_=t[11];let v;t[12]!==o||t[13]!==p||t[14]!==c?(v=c?(0,$.jsxs)(`span`,{className:`oc-summary-flip-stage absolute inset-0 block overflow-clip`,children:[(0,$.jsx)(`span`,{className:`oc-summary-flip-out absolute inset-x-0 top-0 block h-full truncate`,"aria-hidden":`true`,children:c}),(0,$.jsx)(`span`,{className:`oc-summary-flip-in absolute inset-x-0 top-0 block h-full truncate`,onAnimationEnd:p,children:o})]}):null,t[12]=o,t[13]=p,t[14]=c,t[15]=v):v=t[15];let y;return t[16]!==m||t[17]!==_||t[18]!==v?(y=(0,$.jsxs)(`span`,{className:m,children:[_,v]}),t[16]=m,t[17]=_,t[18]=v,t[19]=y):y=t[19],y},uD=[`search`,`read`,`list`];function dD(e){let t=dw(e);return t===`read`?`read`:t===`glob`||t===`grep`?`search`:t===`list`?`list`:null}function fD(e){let t={read:0,search:0,list:0};for(let n of e){let e=dD(n);e&&(t[e]+=1)}return t}var pD=[`edit`,`command`,`other`],mD=new Set([`edit`,`multiedit`,`write`,`create`,`file_write`,`apply_patch`,`patch`]),hD=new Set([`bash`,`shell`,`cmd`,`command`,`exec`,`terminal`]);function gD(e){if(!sw(e))return null;let t=dw(e);return mD.has(t)?`edit`:hD.has(t)?`command`:`other`}function _D(e){let t={edit:0,command:0,other:0};for(let n of e){let e=gD(n);e&&(t[e]+=1)}return t}function vD(e){return PC(e)}var yD=[...uD,...pD];function bD(e){return{...fD(e),..._D(e)}}function xD(e){return uw(e)}function SD(e){return e.kind===`reasoning`||e.type===`reasoning`?!1:e.kind===`justification`||e.type===`text`?!0:e.kind===`tool`||e.type===`tool`?!cw(e.toolName):e.kind!=null||e.type!=null}function CD(e,t,n){for(let r=t;r<e.length;r+=1)if(SD(n(e[r])))return!0;return!1}function wD(e){return`parts`in e?e.parts.some(e=>xD(e))?!0:!e.hasFollowingOtherType&&e.isTurnLive:e.some(e=>xD(e))}function TD(e,t,n){let r=[],i=t;for(;i<e.length&&cw(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var ED=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,DD=e=>{let t=(0,Q.c)(12),{added:n,removed:r}=e;if(n<=0&&r<=0)return null;let i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=Y(`inline-flex flex-none items-center gap-0.5 tabular-nums`,ED),t[0]=i):i=t[0];let a;t[1]===n?a=t[2]:(a=n>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-success)`},children:[`+`,n]}):null,t[1]=n,t[2]=a);let o;t[3]!==n||t[4]!==r?(o=n>0&&r>0?(0,$.jsx)(`span`,{style:{color:`var(--tools-description)`},children:`/`}):null,t[3]=n,t[4]=r,t[5]=o):o=t[5];let s;t[6]===r?s=t[7]:(s=r>0?(0,$.jsxs)(`span`,{style:{color:`var(--status-error)`},children:[`-`,r]}):null,t[6]=r,t[7]=s);let c;return t[8]!==a||t[9]!==o||t[10]!==s?(c=(0,$.jsxs)(`span`,{className:i,children:[a,o,s]}),t[8]=a,t[9]=o,t[10]=s,t[11]=c):c=t[11],c},OD=({activities:e,isMobile:t,isTurnLive:n=!1,hasFollowingOtherType:r=!1,exploring:i,children:a})=>{let{t:o}=ct(),[s,c]=Z.useState(!1),l=Z.useId(),u=e.map(e=>e.part),d=i??wD({parts:u,hasFollowingOtherType:r,isTurnLive:n}),f=bD(u.map(e=>e.tool)),p=vD(u),m=yD.filter(e=>f[e]>0).map(e=>{let t=f[e];return o(e===`search`?t===1?`chat.contextGroup.searchSingle`:`chat.contextGroup.searchPlural`:e===`read`?t===1?`chat.contextGroup.readSingle`:`chat.contextGroup.readPlural`:e===`list`?t===1?`chat.contextGroup.listSingle`:`chat.contextGroup.listPlural`:e===`edit`?t===1?`chat.usedGroup.editSingle`:`chat.usedGroup.editPlural`:e===`command`?t===1?`chat.usedGroup.commandSingle`:`chat.usedGroup.commandPlural`:t===1?`chat.usedGroup.otherSingle`:`chat.usedGroup.otherPlural`,{count:t})}).join(`, `),h=J(()=>{c(e=>!e)}),g=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())}),_=o(s?`chat.usedGroup.collapseAria`:`chat.usedGroup.expandAria`),v=o(d?`chat.usedGroup.running`:`chat.usedGroup.used`),y=t?`h-5`:`h-6`;return(0,$.jsxs)(`div`,{"data-component":`context-tool-group`,className:pm(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":s,"aria-controls":l,"aria-label":_,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,hm),onClick:h,onKeyDown:g,children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center self-center`,y,t?`w-4`:`w-3.5`),style:{color:`var(--tools-icon)`},children:d?(0,$.jsx)(qC,{isMobile:t,label:o(`chat.usedGroup.running`),className:`block`}):(0,$.jsx)(X,{name:`search`,className:`block h-[13px] w-[13px]`})}),(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex flex-none items-center self-center font-medium`,y,ED,d&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...d?{"--oc-text-shimmer-base":`var(--tools-title)`}:{}},children:v}),m?(0,$.jsx)(`span`,{className:Y(`typography-meta inline-flex min-h-0 w-0 min-w-0 max-w-full flex-1 items-center self-center overflow-clip`,y,ED),style:{color:`var(--tools-description)`},children:(0,$.jsx)(lD,{text:m,active:d,className:t?`!h-5 sm:!h-5`:`!h-6 sm:!h-6`})}):null,(0,$.jsx)(DD,{added:p.added,removed:p.removed}),(0,$.jsx)(X,{name:s?`arrow-down-s`:`arrow-right-s`,className:`ml-auto size-3.5 flex-none self-center text-muted-foreground opacity-70`})]}),s&&a?(0,$.jsxs)(`div`,{id:l,className:mm(t),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-0 left-0 top-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),a]}):null]})};function kD(e,t,n){let r=[],i=t;for(;i<e.length&&ow(n(e[i]));)r.push(e[i]),i+=1;return{items:r,end:i}}var AD=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null};function jD(e){if(!e||typeof e!=`object`)return null;let t=e.state;if(!t||typeof t!=`object`)return null;let n=t;if(n.metadata&&typeof n.metadata==`object`){let e=AD(n.metadata.name);if(e)return e}if(n.input&&typeof n.input==`object`){let e=n.input,t=AD(e.name);if(t)return t;let r=AD(e.id);if(r)return r}if(n.output&&typeof n.output==`object`){let e=AD(n.output.name);if(e)return e}return null}function MD(e){let t=[];for(let n of e){if(typeof n!=`string`)continue;let e=n.trim();e&&t.push(e)}let n=t.slice(0,3);return{visibleNames:n,hiddenCount:Math.max(0,t.length-n.length),joinedVisible:n.join(`, `)}}var ND=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,PD=({activities:e,isMobile:t,children:n})=>{let{t:r}=ct(),[i,a]=Z.useState(!1),o=Z.useId(),s=e.map(e=>e.part),c=s.some(e=>uw(e)),{joinedVisible:l,hiddenCount:u}=MD(s.map(jD)),d=u>0?r(`chat.skillGroup.summaryOverflow`,{names:l,count:u}):l,f=J(()=>{a(e=>!e)}),p=J(e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),f())}),m=r(i?`chat.skillGroup.collapseAria`:`chat.skillGroup.expandAria`),h=r(`chat.tools.display.skill`);return(0,$.jsxs)(`div`,{"data-component":`skill-tool-group`,className:pm(t),children:[(0,$.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-expanded":i,"aria-controls":o,"aria-label":m,"data-mobile-press-feedback":`soft`,className:Y(`flex min-h-0 min-w-0 items-center gap-1.5 overflow-clip`,hm),onClick:f,onKeyDown:p,children:[(0,$.jsx)(`span`,{className:Y(`flex flex-none items-center justify-center`,t?`size-4`:`size-3.5`),style:{color:`var(--tools-icon)`},children:c?(0,$.jsx)(qC,{isMobile:t,label:h,className:`block`}):(0,$.jsx)(X,{name:`book`,className:`h-[13px] w-[13px]`})}),(0,$.jsx)(`span`,{className:Y(`typography-meta flex-none font-medium`,ND,c&&`animate-text-shimmer`),style:{color:`var(--tools-title)`,...c?{"--oc-text-shimmer-base":`var(--tools-title)`}:{}},children:h}),d?(0,$.jsx)(`span`,{className:Y(`typography-meta h-5 min-h-0 w-0 min-w-0 max-w-full flex-1 overflow-clip sm:h-6`,ND),style:{color:`var(--tools-description)`},children:(0,$.jsx)(lD,{text:d,active:c})}):null,(0,$.jsx)(X,{name:i?`arrow-down-s`:`arrow-right-s`,className:`ml-auto size-3.5 flex-none text-muted-foreground opacity-70`})]}),i&&n?(0,$.jsxs)(`div`,{id:o,className:mm(t),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-0 left-0 top-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),n]}):null]})},FD=Z.memo(e=>{let t=(0,Q.c)(18),{part:n,messageId:r,onContentChange:i,actions:a,streamPhase:o,onShowPopup:s}=e,c=q(ID),l=n,u=typeof l.text==`string`?l.text:``,d=typeof l.content==`string`?l.content:``,f=d.length>u.length?d:u,p=l.time,m=n.sessionID,h=o===void 0||o!==`completed`,g,_;if(t[0]!==i||t[1]!==f?(g=()=>{f.trim().length!==0&&i?.(`structural`)},_=[i,f],t[0]=i,t[1]=f,t[2]=g,t[3]=_):(g=t[2],_=t[3]),Z.useEffect(g,_),!f||f.trim().length===0)return null;let v=o??`streaming`,y=h&&typeof p?.end!=`number`,b;t[4]!==c||t[5]!==r||t[6]!==i||t[7]!==s||t[8]!==n||t[9]!==m||t[10]!==v||t[11]!==y?(b=(0,$.jsx)(`div`,{"data-message-text-export-source":`true`,children:(0,$.jsx)(UT,{part:n,sessionId:m,messageId:r,streamPhase:v,chatRenderMode:c,hasStreamingHapticLifecycle:y,onContentChange:i,onShowPopup:s})}),t[4]=c,t[5]=r,t[6]=i,t[7]=s,t[8]=n,t[9]=m,t[10]=v,t[11]=y,t[12]=b):b=t[12];let x;t[13]===a?x=t[14]:(x=a?(0,$.jsx)(`div`,{className:`mt-2 mb-1 flex items-center justify-start gap-1.5`,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-1.5`,"data-message-action-group":`true`,children:a})}):null,t[13]=a,t[14]=x);let S;return t[15]!==b||t[16]!==x?(S=(0,$.jsxs)(`div`,{"data-message-text-export-root":`true`,children:[b,x]}),t[15]=b,t[16]=x,t[17]=S):S=t[17],S});function ID(e){return e.chatRenderMode}var LD=e=>{let t=Math.max(0,Math.round(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},RD=`!text-[length:var(--text-meta)] !leading-5 sm:!leading-6 tracking-normal`,zD=Y(`typography-meta font-medium`,RD),BD=Y(`typography-meta`,RD),VD=[],HD=e=>{let t=e.part;return t.slim===!0&&(t.type===`tool`||t.type===`reasoning`||t.type===`file`)},UD=e=>{let t=new Set;for(let n of e)HD(n)&&n.messageId&&t.add(n.messageId);return[...t]},WD=(e,t)=>e.some(e=>{if(!t.has(e.messageId))return!1;let n=e.part;if(n.slim===!0)return!1;if(n.type===`reasoning`)return typeof n.text==`string`&&n.text.trim().length>0;if(n.type===`file`)return typeof n.url==`string`&&n.url.trim().length>0;if(n.type===`tool`){let e=n.state?.output,t=n.state?.error;return(typeof e==`string`?e.trim().length>0:e!=null)||(typeof t==`string`?t.trim().length>0:t!=null)}return!1}),GD=e=>{let t=(0,Q.c)(5),{href:n}=e,[r,i]=Z.useState(!1),a;t[0]===n?a=t[1]:(a=sc(n),t[0]=n,t[1]=a);let o=a;if(!o||r)return null;let s;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(s=()=>i(!0),t[2]=s):s=t[2];let c;return t[3]===o?c=t[4]:(c=(0,$.jsx)(`span`,{className:`inline-flex size-[18px] flex-shrink-0 items-center justify-center rounded border border-[var(--border)] bg-[var(--interactive-hover)]`,children:(0,$.jsx)(`img`,{src:o,alt:``,"aria-hidden":`true`,loading:`lazy`,decoding:`async`,className:`size-3.5 rounded-sm`,onError:s})}),t[3]=o,t[4]=c),c},KD=e=>e,qD=e=>{let t=e.part.state,n=t?.input,r=t?.metadata,i=n?.filePath||n?.file_path||n?.path||r?.filePath||r?.file_path||r?.path;if(typeof i==`string`&&i.trim().length>0){let e=i.lastIndexOf(`/`);return e>=0?i.slice(e+1):i}return null},JD=e=>{let t=e.part.state,n=t?.input,r=t?.metadata,i=n?.filePath||n?.file_path||n?.path||r?.filePath||r?.file_path||r?.path;return typeof i==`string`&&i.trim().length>0?i:null},YD=e=>{let t=e.part.state?.metadata?.dir;return typeof t==`string`&&t.trim().length>0?t:null},XD=e=>{if(typeof e!=`string`)return null;let t=e.trim().toLowerCase();return t===`pending`?`pending`:t===`in_progress`||t===`in progress`||t===`inprogress`?`in_progress`:t===`completed`||t===`done`?`completed`:t===`cancelled`||t===`canceled`?`cancelled`:null},ZD=e=>{if(e.length===0)return`0 tasks`;let t=0,n=0;for(let r of e){if(!r||typeof r!=`object`)continue;let e=XD(r.status);e&&(e===`pending`&&(t+=1),e===`in_progress`&&(n+=1))}let r=t+n;return r===0?`0 tasks`:`${r} ${r===1?`task`:`tasks`}`},QD=e=>{let t=e.part.state,n=t?.input,r=t?.output;if(Array.isArray(n?.todos)){let e=ZD(n.todos);if(e)return e}if(Array.isArray(r)){let e=ZD(r);if(e)return e}if(r&&typeof r==`object`&&Array.isArray(r.todos)){let e=ZD(r.todos);if(e)return e}if(typeof r==`string`&&r.trim().length>0)try{let e=JSON.parse(r);if(Array.isArray(e)){let t=ZD(e);if(t)return t}if(e&&typeof e==`object`&&Array.isArray(e.todos)){let t=ZD(e.todos);if(t)return t}}catch{}return null},$D=e=>{let t=e.part.state,n=t?.input,r=t?.metadata,i=(typeof n?.offset==`number`&&Number.isFinite(n.offset)?n.offset:void 0)??(typeof n?.line==`number`&&Number.isFinite(n.line)?n.line:void 0)??(typeof r?.offset==`number`&&Number.isFinite(r.offset)?r.offset:void 0)??(typeof r?.line==`number`&&Number.isFinite(r.line)?r.line:void 0);if(!(typeof i!=`number`||i<=0))return Math.floor(i)},eO=(e,t=!0)=>{let n=e.lastIndexOf(`/`);if(n===-1)return(0,$.jsx)(aS,{variant:t?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,BD),style:{color:`var(--tools-description)`},title:e,children:e});let r=e.slice(0,n),i=e.slice(n+1),a=r.startsWith(`/`),o=a?r.slice(1):r;return(0,$.jsxs)(`span`,{className:Y(`min-w-0 inline-flex max-w-full flex-1 items-baseline overflow-hidden`,BD),title:e,children:[a?(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}):null,(0,$.jsx)(`span`,{className:`min-w-0 shrink truncate whitespace-nowrap`,style:{color:`var(--tools-description)`,direction:`rtl`,textAlign:`left`,unicodeBidi:`plaintext`},children:o}),(0,$.jsx)(`span`,{className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:`/`}),(0,$.jsx)(aS,{variant:t?`generate-effect`:`static`,className:`flex-shrink-0`,style:{color:`var(--tools-description)`},children:i})]})},tO=e=>{let t=xo(e);return t?t.toLowerCase().endsWith(`/skill.md`)?t:`${t}/SKILL.md`:``},nO=e=>{let t=e.part,n=t.tool?.toLowerCase()??``,r=t.state,i=r?.input,a=r?.metadata;if(n===`grep`||n===`search`||n===`find`||n===`ripgrep`){let e=i?.pattern;if(typeof e==`string`&&e.trim().length>0)return e.length>40?e.slice(0,40)+`...`:e}if(n===`glob`){let e=i?.pattern;if(typeof e==`string`&&e.trim().length>0)return e.length>40?e.slice(0,40)+`...`:e}if(n===`websearch`||n===`web-search`||n===`search_web`||n===`codesearch`||n===`perplexity`){let e=i?.query;if(typeof e==`string`&&e.trim().length>0)return e.length>50?e.slice(0,50)+`...`:e}if(n===`skill`)return jD(t);if(n===`webfetch`||n===`fetch`||n===`curl`||n===`wget`){let e=typeof i?.url==`string`&&i.url||typeof i?.URL==`string`&&i.URL||typeof a?.url==`string`&&a.url||typeof a?.URL==`string`&&a.URL||``;if(typeof e==`string`&&e.trim().length>0)return e.trim()}return n===`todowrite`||n===`todoread`?QD(e):qD(e)},rO=e=>{let t=[],n=[];for(let r of e){if(r.kind!==`tool`)continue;let e=r.part;if(e.tool?.trim().toLowerCase()!==`task`)continue;let i=typeof e.id==`string`?e.id.trim():``;if(!i)continue;let a=e.state;if(!a||typeof a!=`object`)continue;let o=a;n.push(i),(o.status===`pending`||o.status===`running`)&&t.push(i)}return{active:t,all:n}},iO=Z.memo(e=>{let t=(0,Q.c)(16),{activity:n,isExpanded:r,isMobile:i,onToggleTool:a,onShowPopup:o,onContentChange:s}=e,c;t[0]!==n.id||t[1]!==a?(c=()=>{a(n.id)},t[0]=n.id,t[1]=a,t[2]=c):c=t[2];let l=J(c),u;t[3]===i?u=t[4]:(u=pm(i),t[3]=i,t[4]=u);let d=n.part,f;t[5]!==n.messageId||t[6]!==l||t[7]!==r||t[8]!==i||t[9]!==s||t[10]!==o||t[11]!==d?(f=(0,$.jsx)(CT,{part:d,messageId:n.messageId,isExpanded:r,onToggle:l,isMobile:i,onContentChange:s,onShowPopup:o,animateTailText:!1}),t[5]=n.messageId,t[6]=l,t[7]=r,t[8]=i,t[9]=s,t[10]=o,t[11]=d,t[12]=f):f=t[12];let p;return t[13]!==u||t[14]!==f?(p=(0,$.jsx)(`div`,{className:u,children:f}),t[13]=u,t[14]=f,t[15]=p):p=t[15],p},(e,t)=>e.isExpanded===t.isExpanded&&e.isMobile===t.isMobile&&e.onToggleTool===t.onToggleTool&&e.onShowPopup===t.onShowPopup&&e.onContentChange===t.onContentChange&&e.activity.id===t.activity.id&&e.activity.messageId===t.activity.messageId&&e.activity.kind===t.activity.kind&&e.activity.endedAt===t.activity.endedAt&&qS([e.activity.part],[t.activity.part])),aO=Z.memo(e=>{let t=(0,Q.c)(9),{toolName:n,activities:r,isMobile:i}=e,a;t[0]===i?a=t[1]:(a=pm(i),t[0]=i,t[1]=a);let o;t[2]!==r||t[3]!==i||t[4]!==n?(o=(0,$.jsx)(cO,{toolName:n,activities:r,isMobile:i,animateTailText:!1}),t[2]=r,t[3]=i,t[4]=n,t[5]=o):o=t[5];let s;return t[6]!==a||t[7]!==o?(s=(0,$.jsx)(`div`,{className:a,children:o}),t[6]=a,t[7]=o,t[8]=s):s=t[8],s},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&sO(e.activities,t.activities)),oO=e=>{let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.kind===`reasoning`){if(!Pn(r.part).trim()){n++;continue}t.push({type:`reasoning`,activity:r}),n++;continue}if(r.kind===`justification`){t.push({type:`justification`,activity:r}),n++;continue}let i=r.part.tool?.toLowerCase()??``;if(cw(i)){let r=TD(e,n,e=>e.part.tool);t.push({type:`tool-context-group`,activities:r.items,hasFollowingOtherType:CD(e,r.end,e=>({kind:e.kind,toolName:e.part.tool}))}),n=r.end;continue}if(ow(i)){let r=kD(e,n,e=>e.part.tool);if(r.items.length>0){t.push({type:`tool-skill-group`,activities:r.items}),n=r.end;continue}}if(rw(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(nw(i)){t.push({type:`tool-expandable`,activity:r}),n++;continue}if(iw(i)){t.push({type:`tool-static-group`,toolName:i,activities:[r]}),n++;continue}t.push({type:`tool-fallback`,activity:r}),n++}return t},sO=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(r.id!==i.id||r.kind!==i.kind||r.endedAt!==i.endedAt||!qS([r.part],[i.part]))return!1}return!0},cO=Z.memo(e=>{let t=(0,Q.c)(106),{toolName:n,activities:r,isMobile:i,animateTailText:a}=e,{t:o}=ct(),s=q(fO),c=uc(n,o),l;t[0]===n?l=t[1]:(l=oS(n),t[0]=n,t[1]=l);let u=l,d;t[2]===n?d=t[3]:(d=n.toLowerCase(),t[2]=n,t[3]=d);let f=d===`read`,p=Z.useContext(Ao),m=rg(),h=Se(pO),g=Rh(),_=g.kind===`embedded`?g.directory:h,v;t[4]===n?v=t[5]:(v=n.toLowerCase(),t[4]=n,t[5]=v);let y=v===`skill`,b;t[6]===y?b=t[7]:(b={enabled:y},t[6]=y,t[7]=b);let x=Ei(b),S;t[8]===x.data?S=t[9]:(S=x.data??[],t[8]=x.data,t[9]=S);let C=S,w;t[10]===C?w=t[11]:(w=new Map(C.map(mO)),t[10]=C,t[11]=w);let T=w,E=r[0]??null,D=!E||uw(E.part),O;t[12]===E?O=t[13]:(O=E?nO(E):null,t[12]=E,t[13]=O);let k=O,A;if(t[14]!==k||t[15]!==E||t[16]!==T||t[17]!==n){bb0:{if(n.toLowerCase()!==`skill`||!E||!k){A=null;break bb0}let e=T.get(k)?.path||YD(E);if(!e||e===`<built-in>`){A=null;break bb0}let r=tO(e);if(!r){A=null;break bb0}let i;t[19]!==k||t[20]!==r?(i={name:k,path:r},t[19]=k,t[20]=r,t[21]=i):i=t[21],A=i}t[14]=k,t[15]=E,t[16]=T,t[17]=n,t[18]=A}else A=t[18];let j=A,M;if(t[22]!==_||t[23]!==f||t[24]!==E){bb1:{if(!f||!E){M=null;break bb1}let e=JD(E);if(!e){M=null;break bb1}let n=yo(e,_);if(!n){M=null;break bb1}let r;t[26]===E?r=t[27]:(r=$D(E),t[26]=E,t[27]=r);let i;t[28]!==n||t[29]!==e||t[30]!==r?(i={path:e,displayPath:n,offset:r},t[28]=n,t[29]=e,t[30]=r,t[31]=i):i=t[31],M=i}t[22]=_,t[23]=f,t[24]=E,t[25]=M}else M=t[25];let N=M,P;t[32]!==_||t[33]!==m||t[34]!==p?(P=(e,t)=>{if(!_)return;let n=bo(_,e);if(!n)return;if(m){m.openFile({path:n,targetLine:t&&Number.isFinite(t)?Math.max(1,Math.trunc(t)):void 0});return}if(p?.editor){p.editor.openFile(n,t);return}if(!wo(n,_)){mc(n,_).then(()=>{let e=q.getState(),r=_||vo(_,n);if(t&&Number.isFinite(t)){e.openContextFileAtLine(r,n,Math.max(1,Math.trunc(t)),1);return}e.openContextFile(r,n)});return}let r=q.getState(),i=vo(_,n);if(t&&Number.isFinite(t)){r.openContextFileAtLine(i,n,Math.max(1,Math.trunc(t)),1);return}r.openContextFile(i,n)},t[32]=_,t[33]=m,t[34]=p,t[35]=P):P=t[35];let F=J(P),I;t[36]!==_||t[37]!==m?(I=e=>{let t=xo(e);if(!t)return;let n=()=>{if(m){m.openFile({path:t});return}let e=q.getState(),n=_||vo(``,t);e.openContextFile(n,t)};if(_&&!wo(t,_)){mc(t,_).then(n);return}n()},t[36]=_,t[37]=m,t[38]=I):I=t[38];let L=J(I),R;t[39]===n?R=t[40]:(R=n.toLowerCase(),t[39]=n,t[40]=R);let z=R,B=z===`grep`||z===`search`||z===`find`||z===`ripgrep`||z===`glob`,V=z===`webfetch`||z===`fetch`||z===`curl`||z===`wget`,H=z===`skill`,U=!!(N||j),W=!!(N&&_||j),ee;t[41]!==W||t[42]!==F||t[43]!==L||t[44]!==U||t[45]!==N||t[46]!==j?(ee=()=>{if(!(!U||!W)){if(N){F(N.path,N.offset);return}j&&L(j.path)}},t[41]=W,t[42]=F,t[43]=L,t[44]=U,t[45]=N,t[46]=j,t[47]=ee):ee=t[47];let G=J(ee),K;t[48]===G?K=t[49]:(K=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),G())},t[48]=G,t[49]=K);let te=J(K),ne=U&&W&&`cursor-pointer`,re=U&&!W&&`cursor-default opacity-70`,ie;t[50]!==ne||t[51]!==re?(ie=Y(`flex w-full items-center gap-x-1.5 min-w-0`,hm,ne,re),t[50]=ne,t[51]=re,t[52]=ie):ie=t[52];let ae=U?`soft`:void 0,oe=U?G:void 0,se=U?te:void 0,ce=U?`button`:void 0,le=U&&W?0:void 0,ue=U&&!W?!0:void 0,de=i?`size-4`:`size-3.5`,fe;t[53]===de?fe=t[54]:(fe=Y(`inline-flex items-center justify-center flex-shrink-0`,de),t[53]=de,t[54]=fe);let pe;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(pe={color:`var(--tools-icon)`},t[55]=pe):pe=t[55];let me=D?(0,$.jsx)(qC,{isMobile:i,label:o(`chat.assistantStatus.usingTool`,{tool:c})}):u,he;t[56]!==fe||t[57]!==pe||t[58]!==me?(he=(0,$.jsx)(`div`,{className:fe,style:pe,children:me}),t[56]=fe,t[57]=pe,t[58]=me,t[59]=he):he=t[59];let ge,_e;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(ge=Y(zD,`inline-flex items-center flex-shrink-0 opacity-85`),_e={color:`var(--tools-title)`},t[60]=ge,t[61]=_e):(ge=t[60],_e=t[61]);let ve;t[62]===c?ve=t[63]:(ve=(0,$.jsx)(`span`,{className:ge,style:_e,title:c,children:c}),t[62]=c,t[63]=ve);let ye;t[64]!==a||t[65]!==f||t[66]!==N||t[67]!==s?(ye=f&&N?(0,$.jsxs)(`span`,{className:Y(`inline-flex !min-h-0 items-center justify-start gap-1 min-w-0 flex-1 text-left`,BD),style:{color:`var(--tools-description)`},title:N.offset?`${N.displayPath}:${N.offset}`:N.displayPath,children:[s?(0,$.jsx)(yd,{filePath:N.path,className:`h-3.5 w-3.5`}):null,eO(N.displayPath,a)]}):null,t[64]=a,t[65]=f,t[66]=N,t[67]=s,t[68]=ye):ye=t[68];let be;t[69]!==a||t[70]!==k||t[71]!==B?(be=B&&k?(0,$.jsx)(`span`,{className:`inline-flex min-w-0 flex-1`,children:(0,$.jsxs)(aS,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,BD),style:{color:`var(--tools-description)`},title:k,children:[`"`,k,`"`]})}):null,t[69]=a,t[70]=k,t[71]=B,t[72]=be):be=t[72];let xe;t[73]!==k||t[74]!==V?(xe=V&&k?(0,$.jsxs)(`a`,{href:k,target:`_blank`,rel:`noopener noreferrer`,onClick:hO,className:Y(`min-w-0 flex-1 inline-flex items-center gap-1.5 underline decoration-[color:var(--status-info)] underline-offset-2 hover:opacity-90`,`truncate whitespace-nowrap`,BD),style:{color:`var(--status-info)`},title:k,children:[(0,$.jsx)(GD,{href:k}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:k})]}):null,t[73]=k,t[74]=V,t[75]=xe):xe=t[75];let Ce;t[76]!==H||t[77]!==j?(Ce=H&&j?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,BD),style:{color:`var(--tools-description)`},title:j.path,children:j.name}):null,t[76]=H,t[77]=j,t[78]=Ce):Ce=t[78];let we;t[79]!==k||t[80]!==H||t[81]!==j?(we=H&&!j&&k?(0,$.jsx)(`span`,{className:Y(`!min-h-0 min-w-0 flex-1 truncate whitespace-nowrap text-left`,BD),style:{color:`var(--tools-description)`},title:k,children:k}):null,t[79]=k,t[80]=H,t[81]=j,t[82]=we):we=t[82];let Te;t[83]!==a||t[84]!==k||t[85]!==V||t[86]!==f||t[87]!==B||t[88]!==H?(Te=!f&&!B&&!V&&!H&&k?(0,$.jsx)(aS,{variant:a?`generate-effect`:`static`,className:Y(`min-w-0 flex-1 truncate whitespace-nowrap`,BD),style:{color:`var(--tools-description)`},children:k}):null,t[83]=a,t[84]=k,t[85]=V,t[86]=f,t[87]=B,t[88]=H,t[89]=Te):Te=t[89];let Ee;return t[90]!==ie||t[91]!==ae||t[92]!==oe||t[93]!==se||t[94]!==ce||t[95]!==le||t[96]!==ue||t[97]!==he||t[98]!==ve||t[99]!==ye||t[100]!==be||t[101]!==xe||t[102]!==Ce||t[103]!==we||t[104]!==Te?(Ee=(0,$.jsxs)(`div`,{className:ie,"data-mobile-press-feedback":ae,onClick:oe,onKeyDown:se,role:ce,tabIndex:le,"aria-disabled":ue,children:[he,ve,ye,be,xe,Ce,we,Te]}),t[90]=ie,t[91]=ae,t[92]=oe,t[93]=se,t[94]=ce,t[95]=le,t[96]=ue,t[97]=he,t[98]=ve,t[99]=ye,t[100]=be,t[101]=xe,t[102]=Ce,t[103]=we,t[104]=Te,t[105]=Ee):Ee=t[105],Ee},(e,t)=>e.toolName===t.toolName&&e.isMobile===t.isMobile&&e.animateTailText===t.animateTailText&&sO(e.activities,t.activities)),lO=Z.memo(e=>{let t=(0,Q.c)(5),{activity:n,onContentChange:r,streamPhase:i}=e,a;return t[0]!==n.messageId||t[1]!==n.part||t[2]!==r||t[3]!==i?(a=(0,$.jsx)(tE,{part:n.part,messageId:n.messageId,streamPhase:i,onContentChange:r}),t[0]=n.messageId,t[1]=n.part,t[2]=r,t[3]=i,t[4]=a):a=t[4],a}),uO=Z.memo(e=>{let t=(0,Q.c)(7),{activity:n,onContentChange:r,onShowPopup:i,actions:a,streamPhase:o}=e,s;return t[0]!==a||t[1]!==n.messageId||t[2]!==n.part||t[3]!==r||t[4]!==i||t[5]!==o?(s=(0,$.jsx)(FD,{part:n.part,messageId:n.messageId,onContentChange:r,onShowPopup:i,actions:a,streamPhase:o}),t[0]=a,t[1]=n.messageId,t[2]=n.part,t[3]=r,t[4]=i,t[5]=o,t[6]=s):s=t[6],s}),dO=Z.memo(({parts:e,materializationParts:t=e,isExpanded:n,collapsedPreviewCount:r=0,completionDisposition:i,activityPresentationKind:a=`default`,durationMs:o,onToggle:s,isMobile:c,expandedTools:l,onToggleTool:u,onShowPopup:d,onContentChange:f,streamPhase:p,showHeader:m,renderJustificationActions:h})=>{let{t:g}=ct(),_=pc()??``,v=Z.useMemo(()=>UD(t),[t]),y=Z.useRef(new Set),b=Z.useRef(new Map),x=Z.useRef(new Set),[,S]=Z.useState(0),C=Z.useRef(null),w=Z.useRef(null),T=i===`active`,E=!T&&(i===`normal`||i===`abnormal`)&&typeof o==`number`&&Number.isFinite(o)&&o>=0?LD(o):null,D=i===`normal`||i===`abnormal`,O=a===`compaction`,k=O?`fold-vertical`:`stack`,A=g(i===void 0?`chat.activity.title`:T?O?`chat.activity.compacting`:`chat.activity.active`:D?O?`chat.activity.compactionCompleted`:`chat.activity.completedStatus`:`chat.activity.title`),j=Z.useMemo(()=>rO(e),[e]),M=T?j.active:j.all,N=M.slice(0,c?2:3),P=J((e=!1,n=!1)=>{if(!(!_||!v.length)){for(let r of v){let i=t.find(e=>e.messageId===r)?.part.sessionID;if(!i)continue;let a=Rr(_,i,r);if(a.status===`ready`||n&&a.status===`error`||e&&a.status!==`error`&&!x.current.has(r)||(y.current.add(r),x.current.delete(r),b.current.has(r)))continue;let o=Ii(_,i,r,{priority:n?`background`:`user`}).catch(()=>{x.current.add(r)}).finally(()=>{b.current.delete(r),S(e=>e+1)});b.current.set(r,o)}S(e=>e+1)}}),F=J(e=>{e.stopPropagation(),P(!0)}),I=T,L=I||n,R=J(()=>{if(I)return;let e=C.current;w.current=e?{top:e.getBoundingClientRect().top,scrollContainer:e.closest(`[data-scrollbar="chat"]`)}:null,L||P(),s()});Z.useEffect(()=>{T||!L||P(!1,!0)},[T,L]),Z.useLayoutEffect(()=>{let e=w.current,t=C.current;if(!e||!t)return;let n=()=>{if(!t.isConnected)return;let n=t.getBoundingClientRect().top-e.top;if(!(Math.abs(n)<.5)){if(e.scrollContainer?.isConnected){e.scrollContainer.scrollTop+=n;return}window.scrollBy(0,n)}};if(n(),typeof window>`u`||typeof window.requestAnimationFrame!=`function`){w.current=null;return}let r=window.requestAnimationFrame(()=>{n(),w.current=null});return()=>window.cancelAnimationFrame(r)},[L]);let z=m&&!L?Math.max(0,Math.floor(r)):0,B=!m||L||z>0,V=y.current,H=[...V].map(e=>{if(b.current.has(e))return`loading`;if(x.current.has(e))return`error`;let n=t.find(t=>t.messageId===e)?.part.sessionID??``;return Rr(_,n,e).status}),U=H.includes(`loading`),W=H.includes(`error`),ee=H.length>0&&H.every(e=>e===`ready`),G=t.some(e=>V.has(e.messageId)&&HD(e)),K=ee&&!G&&!WD(t,V),te=Z.useMemo(()=>B?KD(e):VD,[e,B]),ne=Z.useMemo(()=>B?oO(te):[],[B,te]),re=Z.useMemo(()=>L||z===0?0:Math.max(0,ne.length-z),[L,z,ne.length]),ie=Z.useMemo(()=>L||z===0?ne:ne.slice(-z),[L,z,ne]);if((!m||I&&!O)&&ne.length===0)return null;let ae=(e,t)=>{let n=(0,$.jsx)(`div`,{className:pm(c),children:t});return(0,$.jsx)(Z.Fragment,{children:n},e)},oe=B?ie.map((e,t)=>{switch(e.type){case`reasoning`:return ae(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(lO,{activity:e.activity,streamPhase:p,onContentChange:f})}));case`justification`:return ae(e.activity.id,(0,$.jsx)($.Fragment,{children:(0,$.jsx)(uO,{activity:e.activity,onContentChange:f,onShowPopup:d,actions:h?.(e.activity),streamPhase:p})}));case`tool-expandable`:return(0,$.jsx)(iO,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);case`tool-static-group`:return(0,$.jsx)(aO,{toolName:e.toolName,activities:e.activities,isMobile:c},e.activities[0]?.id??`static-${e.toolName}-${t}`);case`tool-context-group`:return(0,$.jsx)(OD,{activities:e.activities,isMobile:c,isTurnLive:T,hasFollowingOtherType:e.hasFollowingOtherType,children:e.activities.map(e=>{let t=e.part,n=t.tool?.toLowerCase()??``;return aw(n)?(0,$.jsx)(cO,{toolName:n,activities:[e],isMobile:c,animateTailText:!1},e.id):(0,$.jsx)(CT,{part:t,messageId:e.messageId,isExpanded:l.has(e.id),onToggle:u,isMobile:c,onContentChange:f,onShowPopup:d,animateTailText:!1},e.id)})},e.activities[0]?.id??`context-${t}`);case`tool-skill-group`:return(0,$.jsx)(PD,{activities:e.activities,isMobile:c,children:e.activities.map(e=>{let t=e.part;return(0,$.jsx)(cO,{toolName:t.tool?.toLowerCase()??``,activities:[e],isMobile:c,animateTailText:!1},e.id)})},e.activities[0]?.id??`skill-${t}`);case`tool-fallback`:return(0,$.jsx)(iO,{activity:e.activity,isExpanded:l.has(e.activity.id),isMobile:c,onToggleTool:u,onShowPopup:d,onContentChange:f},e.activity.id);default:return null}}):null,se=ie.length>0;return m?(0,$.jsxs)(`div`,{className:pm(c),children:[(0,$.jsxs)(`button`,{ref:C,type:`button`,className:Y(`group/tool flex w-full min-w-0 flex-nowrap items-center text-left`,c?`gap-x-1`:`gap-x-2`,!I&&hm,I&&`oc-tool-row -mx-2 rounded-lg px-2 py-0.5 cursor-default`,c&&`pr-0`),"data-mobile-press-feedback":I?void 0:`soft`,onClick:I?void 0:R,"aria-expanded":L,"aria-disabled":I||void 0,"aria-label":I?A:g(L?`chat.activity.collapseAria`:`chat.activity.expandAria`),children:[(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 flex-1 items-center overflow-clip`,c?`gap-x-1`:`gap-x-1.5`),children:[(0,$.jsx)(`span`,{className:Y(`inline-flex flex-none items-center justify-center`,c?`h-5 w-4`:`h-6 w-3.5`),style:{color:`var(--tools-icon)`},children:T&&!O?(0,$.jsx)(qC,{isMobile:c,label:A,className:`block`}):(0,$.jsx)(X,{name:k,className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:Y(`inline-flex flex-shrink-0 items-center`,c?`typography-meta h-5`:`typography-ui-label h-5 font-semibold`,T?`animate-text-shimmer text-[var(--status-info)] [--oc-text-shimmer-base:var(--status-info)]`:`text-foreground/85`),children:A}),E?(0,$.jsx)(`span`,{className:`typography-meta shrink-0 tabular-nums text-muted-foreground`,children:E}):null]}),(0,$.jsxs)(`span`,{className:Y(`ml-auto inline-flex max-w-[min(14rem,55%)] shrink-0 items-center justify-end`,c?`gap-0.5`:`gap-1`),children:[M.length>0?(0,$.jsxs)(`span`,{className:Y(`inline-flex min-w-0 items-center text-muted-foreground`,c?`gap-1`:`gap-1.5`),children:[(0,$.jsx)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5`,"aria-hidden":`true`,children:N.map((e,t)=>(0,$.jsx)(la,{name:e,size:c?12:14,className:Y(`flex-none`,c?`size-3 min-h-3 min-w-3 max-h-3 max-w-3`:`size-3.5 min-h-3.5 min-w-3.5 max-h-3.5 max-w-3.5`)},`${e}-${t}`))}),(0,$.jsx)(`span`,{className:`typography-meta min-w-0 truncate`,children:g(T?`chat.activity.agentsWorking`:`chat.activity.agentsInvolved`,{count:M.length})})]}):null,I?null:(0,$.jsx)(X,{name:L?`arrow-down-s`:`arrow-right-s`,className:Y(`flex-shrink-0 text-muted-foreground opacity-70`,c&&`-mr-0.5`,c?`size-3`:`size-3.5`)})]})]}),se?(0,$.jsxs)(`div`,{className:I?void 0:`relative ml-2 pl-3`,children:[I?null:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-px bottom-0 w-px opacity-40`,style:{backgroundColor:`var(--tools-border)`}}),re>0?(0,$.jsxs)(`button`,{type:`button`,onClick:R,className:`typography-meta leading-4 px-2 py-1 text-muted-foreground/45 hover:text-muted-foreground/65 text-left`,children:[`+`,re,` more...`]}):null,(0,$.jsx)(`div`,{className:`flow-root`,children:oe})]}):null,L&&(U||W||K)?(0,$.jsx)(`div`,{className:Y(`typography-meta flex min-h-9 items-center gap-2 px-2 text-muted-foreground`,I?void 0:`ml-5`,W&&`text-[var(--status-error)]`),role:W?`alert`:`status`,children:U?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`loader-4`,className:`size-3.5 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{children:g(`chat.activity.outputLoading`)})]}):W?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{name:`error-warning`,className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1`,children:g(`chat.activity.outputLoadFailed`)}),(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`xs`,onClick:F,children:g(`chat.activity.outputRetry`)})]}):(0,$.jsx)(`span`,{children:g(`chat.toolOutputDialog.noOutputProduced`)})}):null]}):(0,$.jsx)(`div`,{className:pm(c),children:oe})});function fO(e){return e.showToolFileIcons}function pO(e){return e.currentDirectory}function mO(e){return[e.name,e]}function hO(e){e.stopPropagation()}var gO=Z.memo(e=>{let t=(0,Q.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(dO,{...e}),t[0]=e,t[1]=n),n}),_O={contain:`layout`},vO={containerType:`inline-size`,containerName:`message-footer`},yO=`mt-1.5 mb-0.5 flex items-center justify-start gap-1.5`,bO=`mt-3 mb-0.5 flex items-center justify-start gap-1.5`,xO=`size-6! p-0 text-muted-foreground bg-transparent hover:text-foreground hover:!bg-transparent active:!bg-transparent focus-visible:!bg-transparent focus-visible:ring-2 focus-visible:ring-primary/50`,SO=`size-3.5!`,CO=`mt-1.5 mb-0.5 flex flex-wrap items-center gap-3`,wO=`mt-3 mb-0.5 flex flex-wrap items-center gap-3 -ml-[5px]`,TO=`flex items-center gap-2`,EO=`flex items-center gap-2 text-muted-foreground`,DO=`inline-flex h-3.5 items-center gap-1 text-[11px] leading-none tabular-nums text-muted-foreground`,OO=`size-3.5!`,kO=`medium`,AO=e=>e.replace(/\\/g,`/`).split(`/`).filter(Boolean).at(-1)??e,jO=`w-full min-w-0 justify-start rounded-[var(--radius-md)] bg-transparent px-1 hover:!bg-interactive-hover focus-visible:!bg-interactive-hover active:!bg-interactive-active supports-[corner-shape:squircle]:rounded-[var(--radius-md)]`,MO=`h-7 gap-1.5`,NO=`h-6 gap-1`,PO=`text-[11px] leading-none`,FO=`size-3.5`,IO=`size-3`,LO=5,RO=Z.memo(e=>{let t=(0,Q.c)(30),{file:n,isMobile:r}=e,i=r?`gap-1 text-[11px]`:`gap-1.5 text-xs`,a;t[0]===i?a=t[1]:(a=Y(`flex min-w-0 flex-1 items-center leading-none text-muted-foreground`,i),t[0]=i,t[1]=a);let o=n.file,s=r?`h-3 w-3`:`h-3.5 w-3.5`,c;t[2]===s?c=t[3]:(c=Y(`flex-shrink-0`,s),t[2]=s,t[3]=c);let l;t[4]!==n.file||t[5]!==c?(l=(0,$.jsx)(yd,{filePath:o,className:c}),t[4]=n.file,t[5]=c,t[6]=l):l=t[6];let u=n.file,d;t[7]===n.file?d=t[8]:(d=AO(n.file),t[7]=n.file,t[8]=d);let f;t[9]!==n.file||t[10]!==d?(f=(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left text-foreground/80`,title:u,children:d}),t[9]=n.file,t[10]=d,t[11]=f):f=t[11];let p=r?`text-[11px]`:`typography-meta`,m;t[12]===p?m=t[13]:(m=Y(`inline-flex flex-shrink-0 items-center gap-0 leading-none tabular-nums`,p),t[12]=p,t[13]=m);let h;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(h={color:`var(--status-success)`},t[14]=h):h=t[14];let g;t[15]===n.additions?g=t[16]:(g=(0,$.jsxs)(`span`,{style:h,children:[`+`,n.additions]}),t[15]=n.additions,t[16]=g);let _,v;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(`span`,{className:`text-muted-foreground/70`,children:`/`}),v={color:`var(--status-error)`},t[17]=_,t[18]=v):(_=t[17],v=t[18]);let y;t[19]===n.deletions?y=t[20]:(y=(0,$.jsxs)(`span`,{style:v,children:[`-`,n.deletions]}),t[19]=n.deletions,t[20]=y);let b;t[21]!==m||t[22]!==g||t[23]!==y?(b=(0,$.jsxs)(`span`,{className:m,children:[g,_,y]}),t[21]=m,t[22]=g,t[23]=y,t[24]=b):b=t[24];let x;return t[25]!==b||t[26]!==a||t[27]!==l||t[28]!==f?(x=(0,$.jsxs)(`span`,{className:a,children:[l,f,b]}),t[25]=b,t[26]=a,t[27]=l,t[28]=f,t[29]=x):x=t[29],x}),zO=Z.memo(e=>{let t=(0,Q.c)(18),{file:n,canOpen:r,isMobile:i,onOpen:a}=e,{t:o}=ct(),s;t[0]!==n.file||t[1]!==a?(s=()=>{a(n.file)},t[0]=n.file,t[1]=a,t[2]=s):s=t[2];let c=J(s),l=!r,u=i?NO:MO,d;t[3]===u?d=t[4]:(d=Y(jO,u),t[3]=u,t[4]=d);let f;t[5]!==n.file||t[6]!==o?(f=o(`chat.changedFiles.actions.openFileTitle`,{path:n.file}),t[5]=n.file,t[6]=o,t[7]=f):f=t[7];let p;t[8]!==n||t[9]!==i?(p=(0,$.jsx)(RO,{file:n,isMobile:i}),t[8]=n,t[9]=i,t[10]=p):p=t[10];let m;return t[11]!==n.file||t[12]!==c||t[13]!==l||t[14]!==d||t[15]!==f||t[16]!==p?(m=(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`xs`,disabled:l,"data-turn-change-file":`true`,className:d,"aria-label":f,title:n.file,onClick:c,children:p}),t[11]=n.file,t[12]=c,t[13]=l,t[14]=d,t[15]=f,t[16]=p,t[17]=m):m=t[17],m}),BO=Z.memo(e=>{let t=(0,Q.c)(53),{fileCount:n,changedFiles:r,turnId:i,isLatestTurn:a,isMobile:o}=e,{t:s}=ct(),c=pc(),l=Rh(),u=l.directory||c,d=l.sessionId,f=rg(),p=q(ek),m;t[0]===r?m=t[1]:(m=r??[],t[0]=r,t[1]=m);let h=m,g;t[2]===h?g=t[3]:(g=h.slice(0,LO),t[2]=h,t[3]=g);let _=g,v=Math.max(0,h.length-_.length),y=h.length>0?h.length:n,b=!!(f||!o&&u||o&&a),x;t[4]!==y||t[5]!==s?(x=s(y===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:y}),t[4]=y,t[5]=s,t[6]=x):x=t[6];let S=x,C;t[7]!==v||t[8]!==s?(C=s(v===1?`chat.pendingChanges.fileCountSingle`:`chat.pendingChanges.fileCountPlural`,{count:v}),t[7]=v,t[8]=s,t[9]=C):C=t[9];let w=C,T=Y(jO,o?NO:MO),E=o?IO:FO,D;t[10]===o?D=t[11]:(D=o?Y(PO,`font-semibold text-foreground/85`):`typography-meta font-semibold text-foreground/85`,t[10]=o,t[11]=D);let O=D,k;t[12]===o?k=t[13]:(k=o?Y(PO,`text-muted-foreground`):`typography-meta text-muted-foreground`,t[12]=o,t[13]=k);let A=k,j;t[14]===o?j=t[15]:(j=o?Y(PO,`font-medium`):`typography-meta font-medium`,t[14]=o,t[15]=j);let M=j,N;t[16]!==u||t[17]!==d||t[18]!==a||t[19]!==o||t[20]!==f||t[21]!==i?(N=e=>{if(f){f.openTurnDiff(i,d,e);return}if(!o&&u){iE({directory:u,filePath:e,turnMessageId:i,sessionId:d});return}o&&a&&u&&iE({directory:u,filePath:e,turnMessageId:i,sessionId:d,mobile:!0})},t[16]=u,t[17]=d,t[18]=a,t[19]=o,t[20]=f,t[21]=i,t[22]=N):N=t[22];let P=J(N),F;t[23]!==u||t[24]!==d||t[25]!==a||t[26]!==o||t[27]!==f||t[28]!==p||t[29]!==i||t[30]!==_[0]?.file?(F=()=>{if(f){f.openTurnDiff(i,d);return}if(!o&&u){p(u,{mode:`diff`,dedupeKey:`turn-diff:${d||`session`}:${i}`,targetPath:null,diffScope:`turn`,diffTurnMessageId:i,diffSessionId:d});return}let e=_[0]?.file;e&&o&&a&&u&&iE({directory:u,filePath:e,turnMessageId:i,sessionId:d,mobile:!0})},t[23]=u,t[24]=d,t[25]=a,t[26]=o,t[27]=f,t[28]=p,t[29]=i,t[30]=_[0]?.file,t[31]=F):F=t[31];let I=J(F),L=o?`gap-0 border-foreground/15 p-1`:`gap-0.5 border-border/50 p-1.5`,R;t[32]===L?R=t[33]:(R=Y(`mt-4 flex min-w-0 flex-col rounded-[var(--radius-lg)] border bg-muted/20`,L),t[32]=L,t[33]=R);let z=Y(T,`max-w-full text-muted-foreground hover:text-foreground`),B;t[34]===s?B=t[35]:(B=s(`diffView.actions.reviewAria`),t[34]=s,t[35]=B);let V;t[36]===s?V=t[37]:(V=s(`diffView.actions.reviewAria`),t[36]=s,t[37]=V);let H;t[38]===E?H=t[39]:(H=(0,$.jsx)(X,{name:`file-edit`,className:E}),t[38]=E,t[39]=H);let U=`turn-changes-${i}`,W;t[40]===s?W=t[41]:(W=s(`chat.changedFiles.title`),t[40]=s,t[41]=W);let ee;t[42]!==U||t[43]!==W||t[44]!==O?(ee=(0,$.jsx)(`span`,{id:U,className:O,children:W}),t[42]=U,t[43]=W,t[44]=O,t[45]=ee):ee=t[45];let G;t[46]!==S||t[47]!==A?(G=(0,$.jsx)(`span`,{className:A,children:S}),t[46]=S,t[47]=A,t[48]=G):G=t[48];let K;t[49]===E?K=t[50]:(K=Y(E,`opacity-60`),t[49]=E,t[50]=K);let te;return t[51]===K?te=t[52]:(te=(0,$.jsx)(X,{name:`arrow-right-s`,className:K}),t[51]=K,t[52]=te),(0,$.jsxs)(`section`,{className:R,"data-turn-changes-preview":`true`,"data-message-action-group":`true`,"aria-labelledby":`turn-changes-${i}`,children:[(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,onClick:I,className:z,"aria-label":B,title:V,children:[H,ee,G,te]}),_.length>0?(0,$.jsxs)(`div`,{className:Y(`flex min-w-0 flex-col`,o?`gap-0`:`gap-0.5`),children:[_.map(e=>(0,$.jsx)(zO,{file:e,canOpen:b,isMobile:o,onOpen:P},e.file)),v>0?(0,$.jsxs)(ua,{type:`button`,variant:`ghost`,size:`xs`,disabled:!b,className:Y(T,`text-muted-foreground hover:text-foreground`),onClick:I,"aria-label":s(`diffView.actions.reviewAria`),title:s(`diffView.actions.reviewAria`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:Y(E,`flex-shrink-0`)}),(0,$.jsxs)(`span`,{className:M,children:[`+`,w]}),(0,$.jsx)(X,{name:`arrow-right-s`,className:E})]}):null]}):null]})}),VO=e=>e.type===`subtask`,HO=e=>{let t=e;return t.type===`text`&&typeof t.shellAction==`object`&&t.shellAction!==null},UO=e=>{if(!e||typeof e!=`object`)return null;let t=typeof e.providerID==`string`?e.providerID.trim():``,n=typeof e.modelID==`string`?e.modelID.trim():``;return!t||!n?null:`${t}/${n}`},WO=e=>{let t=(0,Q.c)(49),{part:n}=e,[r,i]=Z.useState(!1),a=pc(),{isMobile:o}=mo(),s=ri(tk),c=q(nk),l=Rh(),{t:u}=ct(),d;t[0]===n.description?d=t[1]:(d=typeof n.description==`string`?n.description.trim():``,t[0]=n.description,t[1]=d);let f=d,p;t[2]===n.command?p=t[3]:(p=typeof n.command==`string`?n.command.trim():``,t[2]=n.command,t[3]=p);let m=p,h;t[4]===n.agent?h=t[5]:(h=typeof n.agent==`string`?n.agent.trim():``,t[4]=n.agent,t[5]=h);let g=h,_;t[6]===n.prompt?_=t[7]:(_=typeof n.prompt==`string`?n.prompt.trim():``,t[6]=n.prompt,t[7]=_);let v=_,y;t[8]===n.taskSessionID?y=t[9]:(y=typeof n.taskSessionID==`string`?n.taskSessionID.trim():``,t[8]=n.taskSessionID,t[9]=y);let b=y,x;t[10]===n.model?x=t[11]:(x=UO(n.model),t[10]=n.model,t[11]=x);let S=x,C=!!v&&!(o&&l.kind===`primary`),w;t[12]===u?w=t[13]:(w=u(`chat.messageBody.subtask.title`),t[12]=u,t[13]=w);let T;t[14]===w?T=t[15]:(T=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:w}),t[14]=w,t[15]=T);let E;t[16]===m?E=t[17]:(E=m?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`/`,m]}):null,t[16]=m,t[17]=E);let D;t[18]===g?D=t[19]:(D=g?(0,$.jsxs)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:[`@`,g]}):null,t[18]=g,t[19]=D);let O;t[20]===S?O=t[21]:(O=S?(0,$.jsx)(`span`,{className:`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none bg-foreground/5 text-muted-foreground`,children:S}):null,t[20]=S,t[21]=O);let k;t[22]!==D||t[23]!==O||t[24]!==T||t[25]!==E?(k=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[T,E,D,O]}),t[22]=D,t[23]=O,t[24]=T,t[25]=E,t[26]=k):k=t[26];let A;t[27]===f?A=t[28]:(A=f?(0,$.jsx)(`div`,{className:`typography-ui-label text-foreground/90 mt-1.5`,children:f}):null,t[27]=f,t[28]=A);let j;t[29]!==r||t[30]!==v||t[31]!==C||t[32]!==u?(j=C?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>i(rk),children:u(r?`chat.messageBody.subtask.hidePrompt`:`chat.messageBody.subtask.showPrompt`)}),r?(0,$.jsx)(`pre`,{className:`typography-meta mt-1.5 overflow-x-auto whitespace-pre-wrap break-words text-foreground/85`,children:v}):null]}):null,t[29]=r,t[30]=v,t[31]=C,t[32]=u,t[33]=j):j=t[33];let M;t[34]!==g||t[35]!==f||t[36]!==a||t[37]!==o||t[38]!==c||t[39]!==l||t[40]!==s||t[41]!==u||t[42]!==b?(M=b&&l.capabilities.navigateNestedSession?(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>{let e=l.directory||a;e&&Bh(l,b,e,()=>{if(!di({sessionId:b,directory:e})){if(fl()||o||se()){s(b,e);return}c(e,{mode:`chat`,dedupeKey:`session:${b}`,label:f||g||u(`contextPanel.mode.chat`),readOnly:!0})}})},children:u(`chat.messageBody.subtask.openSession`)})}):null,t[34]=g,t[35]=f,t[36]=a,t[37]=o,t[38]=c,t[39]=l,t[40]=s,t[41]=u,t[42]=b,t[43]=M):M=t[43];let N;return t[44]!==k||t[45]!==A||t[46]!==j||t[47]!==M?(N=(0,$.jsxs)(`div`,{className:`mt-2`,children:[k,A,j,M]}),t[44]=k,t[45]=A,t[46]=j,t[47]=M,t[48]=N):N=t[48],N},GO=e=>{let t=(0,Q.c)(34),{notification:n}=e,r=pc(),i=q(ik),{isMobile:a}=mo(),{t:o}=ct(),s;t[0]!==r||t[1]!==a?(s=r&&!a&&!se(),t[0]=r,t[1]=a,t[2]=s):s=t[2];let c=!!s,l;t[3]!==n.state||t[4]!==o?(l=n.state===`completed`?o(`chat.messageBody.subagent.completed`):n.state===`error`?o(`chat.messageBody.subagent.error`):o(`chat.messageBody.subagent.cancelled`),t[3]=n.state,t[4]=o,t[5]=l):l=t[5];let u=l,d=n.state===`completed`?o(`chat.messageBody.subagent.completedDescription`):n.state===`error`?o(`chat.messageBody.subagent.errorDescription`):o(`chat.messageBody.subagent.cancelledDescription`),f=n.description||d,p=J(()=>{!c||!r||i(r,{mode:`chat`,dedupeKey:`session:${n.sessionID}`,label:f,readOnly:!0})}),m;t[6]===p?m=t[7]:(m=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),p())},t[6]=p,t[7]=m);let h=J(m),g=c&&`cursor-pointer hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`,_;t[8]===g?_=t[9]:(_=Y(`mt-2 flex min-w-0 gap-2.5 rounded-[var(--radius-lg)] border border-border/60 bg-muted/20 px-3 py-2.5`,g),t[8]=g,t[9]=_);let v=c?`button`:void 0,y=c?0:void 0,b=c?o(`chat.messageBody.subagent.openSession`,{label:f}):void 0,x=c?p:void 0,S=c?h:void 0,C;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(`span`,{className:`mt-0.5 flex size-6 flex-shrink-0 items-center justify-center rounded-md bg-foreground/5 text-muted-foreground`,children:(0,$.jsx)(X,{name:`robot-2`,className:`size-3.5`})}),t[10]=C):C=t[10];let w;t[11]===f?w=t[12]:(w=(0,$.jsx)(`span`,{className:`typography-meta min-w-0 flex-1 truncate font-semibold text-foreground/90`,children:f}),t[11]=f,t[12]=w);let T=n.state===`completed`?`bg-[var(--status-success-background)] text-[var(--status-success)]`:n.state===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`,E;t[13]===T?E=t[14]:(E=Y(`inline-flex h-5 flex-shrink-0 items-center rounded px-1.5 text-[11px] leading-none`,T),t[13]=T,t[14]=E);let D;t[15]!==u||t[16]!==E?(D=(0,$.jsx)(`span`,{className:E,children:u}),t[15]=u,t[16]=E,t[17]=D):D=t[17];let O;t[18]!==w||t[19]!==D?(O=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[w,D]}),t[18]=w,t[19]=D,t[20]=O):O=t[20];let k;t[21]===n.body?k=t[22]:(k=n.body?(0,$.jsx)(`div`,{className:`typography-meta mt-1 max-h-16 overflow-hidden text-muted-foreground [&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,children:(0,$.jsx)(Ns,{content:n.body,variant:`tool`,enableFileReferences:!1})}):null,t[21]=n.body,t[22]=k);let A;t[23]!==O||t[24]!==k?(A=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[O,k]}),t[23]=O,t[24]=k,t[25]=A):A=t[25];let j;return t[26]!==S||t[27]!==A||t[28]!==_||t[29]!==v||t[30]!==y||t[31]!==b||t[32]!==x?(j=(0,$.jsxs)(`div`,{className:_,role:v,tabIndex:y,"aria-label":b,onClick:x,onKeyDown:S,children:[C,A]}),t[26]=S,t[27]=A,t[28]=_,t[29]=v,t[30]=y,t[31]=b,t[32]=x,t[33]=j):j=t[33],j},KO={background:`transparent`,backgroundColor:`transparent`},qO=e=>{let t=(0,Q.c)(36),{part:n}=e,[r,i]=Z.useState(!1),[a,o]=Z.useState(!1),s=Z.useRef(null),{t:c}=ct(),l;t[0]===n.shellAction?l=t[1]:(l=typeof n.shellAction?.command==`string`?n.shellAction.command.trim():``,t[0]=n.shellAction,t[1]=l);let u=l,d=typeof n.shellAction?.output==`string`?n.shellAction.output:``,f;t[2]===n.shellAction?f=t[3]:(f=typeof n.shellAction?.status==`string`?n.shellAction.status.trim().toLowerCase():``,t[2]=n.shellAction,t[3]=f);let p=f,m;t[4]===d?m=t[5]:(m=d.trim(),t[4]=d,t[5]=m);let h=m.length>0,g;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{s.current!==null&&typeof window<`u`&&(window.clearTimeout(s.current),s.current=null)},t[6]=g):g=t[6];let _=J(g),v,y;t[7]===_?(v=t[8],y=t[9]):(v=()=>()=>{_()},y=[_],t[7]=_,t[8]=v,t[9]=y),Z.useEffect(v,y);let b;t[10]!==_||t[11]!==h||t[12]!==d?(b=async()=>{h&&(await ut(d)).ok&&(_(),o(!0),typeof window<`u`&&(s.current=window.setTimeout(()=>{o(!1),s.current=null},2e3)))},t[10]=_,t[11]=h,t[12]=d,t[13]=b):b=t[13];let x=J(b),S;t[14]===c?S=t[15]:(S=c(`chat.messageBody.shellCommand.title`),t[14]=c,t[15]=S);let C;t[16]===S?C=t[17]:(C=(0,$.jsx)(`span`,{className:`typography-meta font-semibold text-foreground`,children:S}),t[16]=S,t[17]=C);let w;t[18]===p?w=t[19]:(w=p?(0,$.jsx)(`span`,{className:Y(`inline-flex h-5 items-center rounded px-1.5 text-[11px] leading-none`,p===`error`?`bg-[var(--status-error-background)] text-[var(--status-error)]`:`bg-foreground/5 text-muted-foreground`),children:p}):null,t[18]=p,t[19]=w);let T;t[20]!==w||t[21]!==C?(T=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[C,w]}),t[20]=w,t[21]=C,t[22]=T):T=t[22];let E;t[23]===u?E=t[24]:(E=u?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 overflow-x-auto font-mono`,children:(0,$.jsx)(Fc,{language:`bash`,code:u,codeStyle:KO,wrap:!0})}):null,t[23]=u,t[24]=E);let D;t[25]!==a||t[26]!==x||t[27]!==r||t[28]!==h||t[29]!==d||t[30]!==c?(D=h?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-border/60 pt-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,$.jsx)(`button`,{type:`button`,className:`typography-meta text-muted-foreground hover:text-foreground transition-colors underline underline-offset-2`,onClick:()=>i(ak),children:c(r?`chat.messageBody.shellCommand.hideOutput`:`chat.messageBody.shellCommand.showOutput`)}),(0,$.jsx)(`button`,{type:`button`,className:`inline-flex items-center justify-center text-muted-foreground hover:text-foreground transition-colors`,onClick:()=>{x()},"aria-label":c(a?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),title:c(a?`chat.messageBody.shellCommand.copied`:`chat.messageBody.shellCommand.copyOutput`),children:a?(0,$.jsx)(X,{name:`check`,className:`h-3.5 w-3.5`}):(0,$.jsx)(X,{name:`file-copy`,className:`h-3.5 w-3.5`})})]}),r?(0,$.jsx)(`div`,{className:`typography-meta mt-1.5 max-h-56 overflow-auto font-mono text-foreground/85`,children:(0,$.jsx)(Fc,{language:`bash`,code:d,codeStyle:KO,wrap:!0})}):null]}):null,t[25]=a,t[26]=x,t[27]=r,t[28]=h,t[29]=d,t[30]=c,t[31]=D):D=t[31];let O;return t[32]!==T||t[33]!==E||t[34]!==D?(O=(0,$.jsxs)(`div`,{className:`mt-2`,children:[T,E,D]}),t[32]=T,t[33]=E,t[34]=D,t[35]=O):O=t[35],O},JO=e=>{let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`},YO=(e,t)=>{if(t&&typeof t==`object`)return{output:typeof t.output==`number`&&Number.isFinite(t.output)?Math.max(0,t.output):0,reasoning:typeof t.reasoning==`number`&&Number.isFinite(t.reasoning)?Math.max(0,t.reasoning):0};for(let t of e){let e=t.tokens;if(!(!e||typeof e!=`object`))return{output:typeof e.output==`number`&&Number.isFinite(e.output)?Math.max(0,e.output):0,reasoning:typeof e.reasoning==`number`&&Number.isFinite(e.reasoning)?Math.max(0,e.reasoning):0}}return{output:0,reasoning:0}},XO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,messageCreatedAt:i,isMobile:a,alwaysShowActions:o=a,hasTouchInput:s,hasTextContent:c,onCopyMessage:l,copiedMessage:u,onShowPopup:d,agentMention:f,onEdit:p,onRevert:m,onFork:h,pendingMessageAction:g,editing:_,editStaged:v,onCancelEdit:y,userActionsMode:b=`inline`,stickyUserHeaderEnabled:x=!0})=>{let{locale:S,t:C}=ct(),w=Tg(),T=zh(Rh()),E=q(e=>e.timeFormatPreference),[D,O]=Z.useState(!1),k=Z.useRef(null),A=Z.useMemo(()=>n.filter(e=>e.type===`text`?!Vi(e):!!(VO(e)||HO(e))),[n]),j=Z.useMemo(()=>A.map(e=>Wn(e)?ES(Pn(e)):void 0),[A]),M=f?.token,N=!1,P=!!l,F=!!u,I=!!(s??a),L=!!c,R=b!==`external-actions`,z=b!==`external-content`,B=x&&b===`inline`,V=J(()=>{k.current!==null&&typeof window<`u`&&(window.clearTimeout(k.current),k.current=null)}),H=J(()=>{!I||!P||!L||typeof window>`u`||(V(),O(!0),k.current=window.setTimeout(()=>{O(!1),k.current=null},1800))});Z.useEffect(()=>{L||(O(!1),V())},[V,L]);let U=J(e=>{!l||!L||(e.stopPropagation(),e.preventDefault(),l(),I&&H())}),W=w===`mini-chat`||!T.fork?void 0:h,ee=Z.useMemo(()=>{if(typeof i!=`number`||i<=0)return null;let e=nD(i,E);return e.length>0?e:null},[S,i,E]),G=Y(`group/user-actions`,a?b===`inline`?`flex items-center justify-end pt-2 pb-3`:x?`flex h-9 items-start justify-end pt-0`:`flex h-11 items-start justify-end pt-0`:b===`inline`?`absolute top-full left-0 right-0 z-10 pt-5`:`flex h-8 items-start justify-end pt-2`),K=!_&&v&&z?(0,$.jsx)(`div`,{className:G,children:(0,$.jsxs)(`div`,{className:Y(TO,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-auto opacity-100`),"data-message-action-group":`true`,children:[(0,$.jsxs)(`span`,{className:Y(DO,`text-primary`),"aria-live":`polite`,children:[(0,$.jsx)(X,{weight:kO,name:`edit`,className:OO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:C(`chat.messageBody.actions.editStaged`)})]}),y?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":C(`chat.messageBody.actions.cancelEdit`),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),y()},children:(0,$.jsx)(X,{weight:kO,name:`close`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.cancelEdit`)})]}):null]})}):null,te=(_&&z?(0,$.jsx)(`div`,{className:G,children:(0,$.jsx)(`div`,{className:Y(TO,`justify-end`,!a&&b===`inline`&&`translate-x-5`,`pointer-events-none opacity-100`),children:(0,$.jsx)(`span`,{className:Y(DO,`animate-text-shimmer`),"aria-live":`polite`,children:C(`chat.messageBody.actions.editing`)})})}):null)??K??((P&&L||p||m||W)&&z?(0,$.jsx)(`div`,{className:G,children:(0,$.jsxs)(`div`,{className:Y(TO,`justify-end`,!a&&b===`inline`&&`translate-x-5`,o?`pointer-events-auto opacity-100`:`pointer-events-none opacity-0 transition-opacity duration-150 group-hover/message:pointer-events-auto group-hover/message:opacity-100 group-hover/user-actions:pointer-events-auto group-hover/user-actions:opacity-100 group-hover/user-shell:pointer-events-auto group-hover/user-shell:opacity-100`),"data-message-action-group":`true`,children:[ee?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:Y(DO,`mr-1`),"aria-label":`Message time: ${ee}`,children:[(0,$.jsx)(X,{weight:kO,name:`time`,className:OO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:ee})]})}),(0,$.jsx)(Ua,{children:ee})]}):null,m&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":C(`chat.messageBody.actions.revertAria`),"aria-busy":g===`revert`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m()},children:(0,$.jsx)(X,{weight:kO,name:g===`revert`?`loader-4`:`arrow-go-back`,className:Y(SO,g===`revert`&&`animate-spin`)})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.revert`)})]}),p&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":C(`chat.messageBody.actions.editAria`),disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),p()},children:(0,$.jsx)(X,{weight:kO,name:`edit`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.edit`)})]}),W&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":C(`chat.messageBody.actions.forkAria`),"aria-busy":g===`fork`,disabled:!!g,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),W()},children:(0,$.jsx)(X,{weight:kO,name:g===`fork`?`loader-4`:`git-branch`,className:Y(SO,g===`fork`&&`animate-spin`)})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.fork`)})]}),P&&L&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":D||F?`true`:void 0,className:xO,"aria-label":C(`chat.messageBody.actions.copyMessageAria`),onPointerDown:e=>e.stopPropagation(),onClick:U,onFocus:()=>O(!0),onBlur:()=>{F||O(!1)},children:F?(0,$.jsx)(X,{weight:kO,name:`check`,className:Y(SO,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:kO,name:`file-copy`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:C(`chat.messageBody.actions.copyMessage`)})]})]})}):null);return R?(0,$.jsxs)(`div`,{className:`relative w-full group/message`,style:_O,onTouchStart:I&&P&&L?H:void 0,children:[(0,$.jsx)(`div`,{className:Y(`leading-relaxed text-foreground/90 text-base overflow-x-hidden`,B?`overflow-y-auto overscroll-contain scrollbar-none`:`overflow-y-hidden`),style:B?{maxHeight:`calc(var(--chat-scroll-height, 100dvh) * 0.4)`}:void 0,children:A.map((e,i)=>{if(VO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(WO,{part:e})},e.id??`user-subtask-${i}`);if(HO(e))return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(qO,{part:e})},e.id??`user-shell-${i}`);let o=j[i];if(o)return(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(GO,{notification:o})},e.id??`subagent-notification-${i}`);let s;return f&&M&&!N&&Pn(e).includes(M)&&(s=f,N=!0),(0,$.jsx)(Z.Fragment,{children:(0,$.jsx)(rS,{part:e,messageId:t,isMobile:a,agentMention:s,messageParts:r??n})},e.id??`user-text-${i}`)})}),(0,$.jsx)(Gd,{files:n,messageID:t,sessionID:e,onShowPopup:d,compact:!0}),te]}):(0,$.jsx)($.Fragment,{children:te})}),ZO=Z.memo(({hasCopyableText:e,isTouchContext:t,onCopyMessage:n,reviewTransferAction:r,ttsText:i,sessionId:a})=>{let{t:o}=ct(),s=Tg(),c=Rh(),l=zh(c),{isPlaying:u,play:d,stop:f}=IE(),p=Ai(e=>e.showMessageTTSButtons),m=Ai(e=>e.voiceProvider),[h,g]=Z.useState(!1),[_,v]=Z.useState(!1),[y,b]=Z.useState(!1),x=Z.useRef(null),S=Z.useRef(null),C=!!n,w=!!((c.sessionId||a)&&c.directory&&l.openSourceSession&&s!==`mini-chat`),T=J(()=>{x.current!==null&&typeof window<`u`&&(window.clearTimeout(x.current),x.current=null)}),E=J(()=>{S.current!==null&&typeof window<`u`&&(window.clearTimeout(S.current),S.current=null)});Z.useEffect(()=>()=>{T(),E()},[E,T]),Z.useEffect(()=>{(!e||!C)&&(g(!1),v(!1),T(),E())},[C,E,T,e]);let D=J(()=>{!t||!C||!e||typeof window>`u`||(T(),g(!0),x.current=window.setTimeout(()=>{g(!1),x.current=null},1800))}),O=J(async r=>{!n||!e||(r.stopPropagation(),r.preventDefault(),await n()!==!1&&(E(),v(!0),typeof window<`u`&&(S.current=window.setTimeout(()=>{v(!1),S.current=null},2e3)),t&&D()))}),k=J(async t=>{if(t.stopPropagation(),t.preventDefault(),!(!r||y||!e)){b(!0);try{await r.onClick()}finally{b(!1)}}}),A=J(e=>{e.stopPropagation(),e.preventDefault();let t=c.sessionId||a;!t||!c.directory||!c.openSourceSession||c.openSourceSession(t,c.directory)}),j=Z.useMemo(()=>u?o(`chat.messageBody.tts.stopSpeaking`):o(`chat.messageBody.tts.readAloudWithProvider`,{provider:m===`browser`?`Browser`:m===`openai`?`OpenAI`:m===`openai-compatible`?`Custom`:`Say`}),[u,o,m]),M=J(e=>{if(e.stopPropagation(),e.preventDefault(),u){f();return}i.trim()&&d(i)});return(0,$.jsxs)($.Fragment,{children:[n&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,"data-visible":h||_?`true`:void 0,className:Y(xO,!e&&`opacity-50`),disabled:!e,"aria-label":o(`chat.messageBody.actions.copyMessageAria`),"aria-hidden":!e,onPointerDown:e=>e.stopPropagation(),onClick:e=>{O(e)},onFocus:()=>{e&&g(!0)},onBlur:()=>{_||g(!1)},children:_?(0,$.jsx)(X,{weight:kO,name:`check`,className:Y(SO,`text-[color:var(--status-success)]`)}):(0,$.jsx)(X,{weight:kO,name:`file-copy`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:o(`chat.messageBody.actions.copyAnswer`)})]}),w?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":o(`chat.messageBody.actions.openSourceSessionAria`),onPointerDown:e=>e.stopPropagation(),onClick:A,children:(0,$.jsx)(X,{weight:kO,name:`target`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:o(`chat.messageBody.actions.openSourceSession`)})]}):null,r&&s!==`mini-chat`&&l.reviewTransfer?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,size:`icon`,variant:`ghost`,disabled:y||!e,className:Y(xO,(!e||y)&&`opacity-50`),"aria-label":r.ariaLabel,onPointerDown:e=>e.stopPropagation(),onClick:e=>{k(e)},children:y?(0,$.jsx)(X,{weight:kO,name:`loader-4`,className:Y(SO,`animate-spin`)}):(0,$.jsx)(X,{weight:kO,name:`arrow-left-right`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:r.tooltip})]}):null,s!==`mini-chat`&&p&&e&&(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:Y(xO,u?`text-green-500`:`hover:text-foreground/80`),"aria-label":o(u?`chat.messageBody.tts.stopSpeaking`:`chat.messageBody.tts.readAloud`),onPointerDown:e=>e.stopPropagation(),onClick:M,children:u?(0,$.jsx)(X,{weight:kO,name:`stop`,className:SO}):(0,$.jsx)(X,{weight:kO,name:`volume-up`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:j})]})]})}),QO=Z.memo(({sessionId:e,messageId:t,parts:n,sourceParts:r,isMessageCompleted:i,messageFinish:a,messageCompletedAt:o,messageCreatedAt:s,messageTokens:c,isMobile:l,alwaysShowActions:u,hasTouchInput:d,expandedTools:f,onToggleTool:p,onShowPopup:m,streamPhase:h,allowAnimation:g,onContentChange:_,hasTextContent:v=!1,onCopyMessage:y,onAuxiliaryContentComplete:b,showReasoningTraces:x=!1,turnGroupingContext:S,errorMessage:C,errorVariant:w=`error`,reviewTransferDirection:T=null})=>{let{t:E,locale:D}=ct(),O=Tg(),k=zh(Rh()),A=h,j=Z.useRef(null),M=Z.useRef(null),N=h===`streaming`||h===`cooldown`,P=Z.useRef({messageId:t,experiencedStreamingOrCooldown:N});P.current.messageId===t?N&&(P.current.experiencedStreamingOrCooldown=!0):P.current={messageId:t,experiencedStreamingOrCooldown:N};let F=!!(d??l),I=!!(u??l),L=l?wO:CO,R=!i,z=Z.useMemo(()=>n.filter(e=>!Vi(e)).filter(e=>e.type!==`compaction`),[n]),B=Z.useMemo(()=>z.filter(e=>e.type===`tool`),[z]),V=Z.useMemo(()=>z.filter(e=>e.type===`text`),[z]),H=Z.useMemo(()=>Vn(V),[V]),U=q(e=>e.openContextPreview),W=se(),ee=O===`mini-chat`,G=Z.useMemo(()=>{if(W||l||ee)return null;for(let e of V){let t=e.text;if(typeof t!=`string`||t.length===0)continue;let n=cc(t)[0];if(n)return n.includes(`0.0.0.0`)?n.replace(`0.0.0.0`,`127.0.0.1`):n}for(let e of B){let t=e.state,n=t&&typeof t.output==`string`?t.output:null;if(!n)continue;let r=cc(n.replace(/\x1b\[[0-9;]*m/g,``))[0];if(r)return r.includes(`0.0.0.0`)?r.replace(`0.0.0.0`,`127.0.0.1`):r}return null},[V,l,ee,W,B]),K=ri(e=>e.forkFromMessage),te=ri(e=>e.forkTransition),ne=ri(e=>e.currentSessionId),re=ri(e=>e.getDirectoryForSession),ie=pc(),ae=T===`review-to-original`,oe=!l&&!W?T:null,ce=Z.useMemo(()=>{let t=H.trim();if(!(!e||!ie||!t||!oe))return oe===`review-to-original`?{ariaLabel:E(`chat.messageBody.actions.sendReviewFeedback`),tooltip:E(`chat.messageBody.actions.sendReviewFeedback`),onClick:async()=>{try{await vn(e,ie,t)}catch(e){console.error(`[review-flow] failed to send review feedback`,e)}}}:{ariaLabel:E(`chat.messageBody.actions.sendImplementationResponse`),tooltip:E(`chat.messageBody.actions.sendImplementationResponse`),onClick:async()=>{try{await jt(e,ie,t)}catch(e){console.error(`[review-flow] failed to send implementation response`,e)}}}},[H,ie,oe,e,E]),[le,ue]=Z.useState(!1),de=q(e=>e.chatRenderMode),fe=q(e=>e.collapsibleThinkingBlocks),pe=q(e=>e.showSplitAssistantMessageActions),me=q(e=>e.showAssistantTps),he=q(e=>e.timeFormatPreference),ge=de===`sorted`,_e=S?.isLastAssistantInTurn??!1,ve=a===`stop`,ye=(ve||i||!!C)&&(S?.isTurnSettled??!0),be=ve?`completed`:A,xe=B.length>0,Se=Z.useMemo(()=>B.some(e=>uw(e)),[B]),Ce=uw,we=lw,Te=P.current.experiencedStreamingOrCooldown,Ee=Z.useRef({messageId:t,initialized:!1,observedPartIds:new Set});Z.useEffect(()=>{if(Ee.current.messageId!==t&&(Ee.current={messageId:t,initialized:!1,observedPartIds:new Set}),!Te||!Et())return;let n=Ee.current,r=!n.initialized;n.initialized=!0;for(let i of B){if(n.observedPartIds.has(i.id))continue;if(!Hi(r,Ce(i))){n.observedPartIds.add(i.id);continue}let a=e??i.sessionID;a&&(n.observedPartIds.add(i.id),Ki({sessionID:a,messageID:t,partID:i.id,kind:`tool`}))}},[Te,Ce,t,e,B]);let De=Z.useMemo(()=>B.length===0||!Se&&B.every(e=>we(e)),[B,Se,we]),Oe=Z.useMemo(()=>z.filter(e=>e.type===`reasoning`),[z]),ke=Z.useMemo(()=>Oe.length===0||Oe.every(e=>typeof e.time?.end==`number`),[Oe]),Ae=typeof a!=`string`,je=Oe.length>0&&xe&&(Se||Ae||!De),Me=R||xe&&(Se||Ae||!De),Ne=R||je,Pe=xe||Oe.length>0,Fe=V.length===0,Ie=Pe&&Fe&&!Me&&!Ne&&De&&ke,Le=Z.useRef(!1),Re=Z.useRef(!1);Z.useEffect(()=>{Re.current=!1},[t]),Z.useEffect(()=>{if(!Ie){Le.current=!1;return}Le.current||(Le.current=!0,b?.())},[Ie,b]),Z.useEffect(()=>{if(R){Re.current=!1;return}if(xe){Re.current=!1;return}Oe.length!==0&&(Ne||!ke||Re.current||(Re.current=!0,_?.(`structural`)))},[R,xe,_,ke,Oe.length,Ne]);let ze=!!v&&!R,Be=J(async n=>{if(n.stopPropagation(),n.preventDefault(),!(!e||!t||le||te)){ue(!0);try{await K(e,t)}finally{ue(!1)}}}),Ve=Z.useMemo(()=>{let e=S?.activityParts;return!ge||!e?[]:e},[ge,S?.activityParts]),He=Z.useMemo(()=>{let e=S?.activityGroupSegments;return!ge||!e?[]:e.filter(e=>e.anchorMessageId===t)},[ge,t,S?.activityGroupSegments]),Ue=He.length>0,We=Z.useMemo(()=>{let e=new Map,t=new Map;return Ve.forEach(n=>{e.set(n.part,n);let r=n.part.id;typeof r==`string`&&r.length>0&&t.set(r,n)}),{get:n=>{let r=e.get(n);if(r)return r;let i=n.id;if(typeof i==`string`&&i.length>0)return t.get(i)}}},[Ve]),Ge=S?.toggleGroup,Ke=S?.activityPresentationKind===`compaction`,qe=S?.isGroupExpanded===!0,Je=ge&&Ke&&!qe,Ye=ge?S?.activityOwnerMessageId===t||Ue:!S?.activityOwnerMessageId||S.activityOwnerMessageId===t||Ue,Xe=ge&&Ye&&(Ue||Ke)&&!!Ge,Ze=dE(a,z),Qe={finish:a,parts:z,streamPhase:be,error:C,isLastAssistantInTurn:_e},$e=gE(Qe),et=ge&&_E(Qe),tt=ge&&!$e&&!(Ke&&qe),nt=!!C,rt=w===`info`?`information`:`error-warning`,it=w===`muted`,at=ze,ot=_e&&ye&&!Je&&(v||!!C||i),st=S?.diffStats?.hasDiffs===!0,lt=!ee&&_e&&Ze&&ye&&!Je&&S?.diffStats?.hasDiffs===!0,dt=pe&&at&&!ot&&!ge,ft=Z.useMemo(()=>(0,$.jsx)(ZO,{hasCopyableText:ze,isTouchContext:F,onCopyMessage:y,ttsText:H,reviewTransferAction:ce,sessionId:e}),[H,ze,F,y,ce,e]),pt=Z.useMemo(()=>e=>{if(!pe||!ge)return null;let t=Pn(e.part).trim();return t?(0,$.jsx)(ZO,{hasCopyableText:!0,isTouchContext:F,onCopyMessage:async()=>(await ut(t)).ok,ttsText:t}):null},[ge,F,pe]),mt=Z.useMemo(()=>{if(!dt)return-1;let e=-1;for(let t=0;t<z.length;t+=1){let n=z[t];!n||n.type!==`text`||tt||We.get(n)?.kind!==`justification`&&(e=t)}return e},[We,tt,dt,z]),ht=dt&&mt<0,gt=Z.useMemo(()=>{let n=[];if(Xe&&Ge&&S){let e=(e,t,r=t)=>{n.push((0,$.jsx)(`div`,{children:(0,$.jsx)(gO,{parts:t,materializationParts:r,isExpanded:S.isGroupExpanded===!0,collapsedPreviewCount:0,completionDisposition:S.completionDisposition,activityPresentationKind:S.activityPresentationKind,durationMs:S.durationMs,startedAt:S.userMessageCreatedAt,onToggle:Ge,isMobile:l,expandedTools:f,onToggleTool:p,onShowPopup:m,onContentChange:_,streamPhase:be,showHeader:!0,diffStats:S.diffStats,renderJustificationActions:pt})},`progressive-group-${e}`))};He.length>0?He.forEach(t=>{let n=x?t.parts:t.parts.filter(e=>e.kind!==`reasoning`);e(t.id,n,t.parts)}):Ke&&e(`${t}:compaction-status`,[])}let r=0;for(;r<z.length;){let i=z[r];if(i.type===`text`){let a=We.get(i);if(tt){r+=1;continue}if(Je){r+=1;continue}if(a?.kind===`justification`){r+=1;continue}n.push((0,$.jsx)(`div`,{ref:M,"data-message-text-export-source":`true`,children:(0,$.jsx)(UT,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,allowSortedFinalStreaming:et,hasStreamingHapticLifecycle:Te,onContentChange:_,onShowPopup:m})},`assistant-text-${t}-${i.id??r}`)),dt&&r===mt&&n.push((0,$.jsx)(`div`,{className:l?bO:yO,"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:TO,"data-message-action-group":`true`,children:ft})},`message-actions-${t}`)),r++;continue}if(i.type===`reasoning`){if(We.get(i)?.kind===`reasoning`){r+=1;continue}if(!Pn(i).trim()){r+=1;continue}x&&(fe?n.push((0,$.jsx)(`div`,{className:pm(l),children:(0,$.jsx)(tE,{part:i,messageId:t,streamPhase:be,onContentChange:_})},`reasoning-${t}-${i.id??r}`)):n.push((0,$.jsx)(UT,{part:i,sessionId:e,messageId:t,streamPhase:be,chatRenderMode:de,hasStreamingHapticLifecycle:Te,onContentChange:_,onShowPopup:m},`reasoning-${t}-${i.id??r}`))),r++;continue}if(i.type===`tool`){let e=i,a=e.tool?.toLowerCase()??``;if(ge&&!Ye){r+=1;continue}if(We.get(i)?.kind===`tool`){r+=1;continue}if(cw(a)){let e=TD(z,r,e=>e.type!==`tool`||We.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(OD,{activities:i,isMobile:l,isTurnLive:be!==`completed`,hasFollowingOtherType:CD(z,e.end,e=>({type:e.type,toolName:e.type===`tool`?e.tool:void 0})),children:i.map(e=>{let n=e.part.tool?.toLowerCase()??``;return aw(n)?(0,$.jsx)(cO,{toolName:n,activities:[e],isMobile:l,animateTailText:!1},e.id):(0,$.jsx)(CT,{part:e.part,messageId:t,isExpanded:f.has(e.part.id),onToggle:p,isMobile:l,alwaysShowActions:I,onContentChange:_,onShowPopup:m,animateTailText:!1},e.id)})},`context-tools-${i[0].id}`)),r=e.end;continue}}if(ow(a)){let e=kD(z,r,e=>e.type!==`tool`||We.get(e)?.kind===`tool`?``:e.tool);if(e.items.length>0){let i=e.items.map((e,n)=>{let i=e;return{id:i.id,turnId:``,messageId:t,partIndex:r+n,part:i,kind:`tool`}});n.push((0,$.jsx)(PD,{activities:i,isMobile:l,children:i.map(e=>(0,$.jsx)(cO,{toolName:e.part.tool?.toLowerCase()??``,activities:[e],isMobile:l,animateTailText:!1},e.id))},`skill-tools-${i[0].id}`)),r=e.end;continue}}if(nw(a)){n.push((0,$.jsx)(`div`,{className:pm(l),children:(0,$.jsx)(CT,{part:e,messageId:t,isExpanded:f.has(e.id),onToggle:p,isMobile:l,alwaysShowActions:I,onContentChange:_,onShowPopup:m,animateTailText:!1})},`tool-${e.id}`)),r++;continue}n.push((0,$.jsx)(`div`,{className:pm(l),children:(0,$.jsx)(cO,{toolName:a,activities:[{id:e.id,turnId:``,messageId:t,partIndex:r,part:e,kind:`tool`}],isMobile:l,animateTailText:!1})},`static-tools-${e.id}`)),r++;continue}r++}return n},[We,He,I,de,fe,0,f,Je,Ke,l,Ye,ge,mt,t,ft,pt,e,_,m,p,Xe,dt,be,Te,x,tt,et,Ge,S,z]),_t=Z.useMemo(()=>{if(!_e||!ye)return;let e=S?.durationMs;if(!(typeof e!=`number`||e<=0))return JO(e)},[_e,ye,S?.durationMs]),vt=Z.useMemo(()=>{let e=typeof o==`number`&&o>0?o:typeof s==`number`&&s>0?s:null;if(e===null)return null;let t=nD(e,he);return t.length>0?t:null},[o,s,he,D]),yt=Z.useMemo(()=>{if(!me||!_e||!ye)return null;let e=r??n,t=YO(e,c),i=sD({createdAt:s,completedAt:o,fallbackDurationMs:S?.durationMs,outputTokens:t.output,reasoningTokens:t.reasoning,parts:e});if(i===null)return null;let a=cD(i);return a.length>0?a:null},[me,_e,ye,n,r,c,s,o,S?.durationMs]),bt=(0,$.jsxs)($.Fragment,{children:[!ee&&!l&&!W&&G?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,variant:`ghost`,size:`icon`,className:xO,"aria-label":E(`chat.messageBody.actions.openPreviewAria`),onPointerDown:e=>e.stopPropagation(),onClick:()=>{let e=ie??(ne?re(ne):null);e&&U(e,G)},children:(0,$.jsx)(X,{weight:kO,name:`global`,className:SO})})}),(0,$.jsx)(Ua,{sideOffset:6,children:E(`chat.messageBody.actions.openPreview`)})]}):null,!ee&&!ae&&k.fork?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsx)(ua,{type:`button`,size:`icon`,variant:`ghost`,className:xO,"aria-label":E(`chat.messageBody.actions.forkAria`),"aria-busy":le,disabled:le||!!te,onPointerDown:e=>e.stopPropagation(),onClick:e=>{Be(e)},children:(0,$.jsx)(X,{weight:kO,name:le?`loader-4`:`git-branch`,className:Y(SO,le&&`animate-spin`)})})}),(0,$.jsx)(Ua,{sideOffset:6,children:E(`chat.messageBody.actions.fork`)})]}):null]});return(0,$.jsxs)(`div`,{ref:j,"data-message-text-export-root":`true`,className:Y(`relative w-full group/message`),style:_O,children:[(0,$.jsx)(QE,{containerRef:j}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`message-content-text leading-relaxed text-foreground/90 [&_p:last-child]:mb-0 [&_ul:last-child]:mb-0 [&_ol:last-child]:mb-0`,children:[gt,nt&&(0,$.jsx)(bc,{children:it?(0,$.jsxs)(`div`,{role:`status`,className:`my-1.5 flex max-w-full items-center gap-1.5 break-words typography-meta text-muted-foreground`,children:[(0,$.jsx)(X,{name:`stop-circle`,className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0`,children:C})]}):(0,$.jsxs)(`div`,{className:Y(`group/assistant-text relative flow-root my-1.5 break-words max-w-full`,w===`info`?Y(`inline-flex w-fit max-w-full border border-[var(--status-info-border)]/45 bg-[var(--status-info-background)]/40`,l?`items-start gap-1.5 rounded-lg px-2.5 py-1.5`:Y(`items-center gap-1.5`,`rounded-lg px-2 py-0.5`)):`mt-3 flex items-center gap-2 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3`),children:[w===`info`&&l?(0,$.jsx)(`span`,{className:`inline-flex h-5 w-3.5 shrink-0 items-center justify-center translate-y-[2px]`,"aria-hidden":`true`,children:(0,$.jsx)(X,{name:rt,weight:kO,className:Y(SO,`text-[var(--status-info)]/80`)})}):(0,$.jsx)(X,{name:rt,weight:w===`info`?kO:void 0,className:Y(`shrink-0`,w===`info`?Y(SO,`text-[var(--status-info)]/80`):`h-4 w-4 text-[var(--status-error)]`)}),(0,$.jsx)(`div`,{className:Y(`min-w-0 break-words`,w===`info`?Y(`text-muted-foreground [&_.markdown-content]:text-muted-foreground [&_p]:m-0`,`[&_.markdown-content]:!leading-5`,l?`[&_.markdown-content]:!text-[length:var(--text-meta)]`:`[&_.markdown-content]:!text-[13px]`):`flex-1`),children:(0,$.jsx)(Ns,{content:C??``,onShowPopup:m,className:`[&_.markdown-content>*:first-child]:mt-0 [&_.markdown-content>*:last-child]:mb-0`,enableFileReferences:!1})})]})},`assistant-error`)]}),lt&&S?.diffStats?(0,$.jsx)(BO,{fileCount:S.diffStats.files,changedFiles:S.changedFiles,turnId:S.turnId,isLatestTurn:S.isLatestTurn,isMobile:l}):null,(0,$.jsx)(Gd,{files:n,messageID:t,sessionID:e,onShowPopup:m}),ht&&(0,$.jsx)(`div`,{className:Y(l?bO:yO),"data-message-actions":`true`,children:(0,$.jsx)(`div`,{className:TO,"data-message-action-group":`true`,children:ft})}),ot&&(0,$.jsxs)(`div`,{className:L,"data-message-footer":`true`,style:vO,children:[(0,$.jsxs)(`div`,{className:TO,"data-message-action-group":`true`,children:[ft,bt]}),yt||_t||vt?(0,$.jsxs)(`div`,{className:EO,children:[yt?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:DO,"aria-label":E(`chat.messageBody.meta.tpsAria`,{rate:yt}),children:[(0,$.jsx)(X,{weight:kO,name:`pulse`,className:OO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:yt})]})}),(0,$.jsx)(Ua,{children:E(`chat.messageBody.meta.tpsTooltip`)})]}):null,_t?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:DO,children:[(0,$.jsx)(X,{weight:kO,name:`hourglass`,className:OO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:_t})]})}),(0,$.jsx)(Ua,{children:_t})]}):null,vt?(0,$.jsxs)(Wa,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`span`,{className:DO,"aria-label":`Message time: ${vt}`,children:[(0,$.jsx)(X,{weight:kO,name:`time`,className:OO}),(0,$.jsx)(`span`,{className:`message-footer__label`,children:vt})]})}),(0,$.jsx)(Ua,{children:vt})]}):null]}):null,!ee&&_e&&ve&&!st?(0,$.jsx)(aE,{activityParts:S?.activityParts}):null]})]})]})}),$O=Z.memo(e=>{let t=(0,Q.c)(28),n,r;if(t[0]===e?(n=t[1],r=t[2]):({isUser:n,...r}=e,t[0]=e,t[1]=n,t[2]=r),n){let e;return t[3]!==r.agentMention||t[4]!==r.alwaysShowActions||t[5]!==r.copiedMessage||t[6]!==r.editStaged||t[7]!==r.editing||t[8]!==r.hasTextContent||t[9]!==r.hasTouchInput||t[10]!==r.isMobile||t[11]!==r.messageCreatedAt||t[12]!==r.messageId||t[13]!==r.onCancelEdit||t[14]!==r.onCopyMessage||t[15]!==r.onEdit||t[16]!==r.onFork||t[17]!==r.onRevert||t[18]!==r.onShowPopup||t[19]!==r.parts||t[20]!==r.pendingMessageAction||t[21]!==r.sessionId||t[22]!==r.sourceParts||t[23]!==r.stickyUserHeaderEnabled||t[24]!==r.userActionsMode?(e=(0,$.jsx)(XO,{sessionId:r.sessionId,messageId:r.messageId,parts:r.parts,sourceParts:r.sourceParts,messageCreatedAt:r.messageCreatedAt,isMobile:r.isMobile,alwaysShowActions:r.alwaysShowActions,hasTouchInput:r.hasTouchInput,hasTextContent:r.hasTextContent,onCopyMessage:r.onCopyMessage,copiedMessage:r.copiedMessage,onShowPopup:r.onShowPopup,agentMention:r.agentMention,onEdit:r.onEdit,onRevert:r.onRevert,onFork:r.onFork,pendingMessageAction:r.pendingMessageAction,editing:r.editing,editStaged:r.editStaged,onCancelEdit:r.onCancelEdit,userActionsMode:r.userActionsMode,stickyUserHeaderEnabled:r.stickyUserHeaderEnabled}),t[3]=r.agentMention,t[4]=r.alwaysShowActions,t[5]=r.copiedMessage,t[6]=r.editStaged,t[7]=r.editing,t[8]=r.hasTextContent,t[9]=r.hasTouchInput,t[10]=r.isMobile,t[11]=r.messageCreatedAt,t[12]=r.messageId,t[13]=r.onCancelEdit,t[14]=r.onCopyMessage,t[15]=r.onEdit,t[16]=r.onFork,t[17]=r.onRevert,t[18]=r.onShowPopup,t[19]=r.parts,t[20]=r.pendingMessageAction,t[21]=r.sessionId,t[22]=r.sourceParts,t[23]=r.stickyUserHeaderEnabled,t[24]=r.userActionsMode,t[25]=e):e=t[25],e}let i;return t[26]===r?i=t[27]:(i=(0,$.jsx)(QO,{...r}),t[26]=r,t[27]=i),i});function ek(e){return e.openContextPanelTab}function tk(e){return e.setCurrentSession}function nk(e){return e.openContextPanelTab}function rk(e){return!e}function ik(e){return e.openContextPanelTab}function ak(e){return!e}var ok=e=>{let t=e,n=t?.clientRole,r=t?.role;return t?.userMessageMarker===!0||n===`user`||r===`user`||t?.origin===`user`||t?.source===`user`?{role:`user`,isUser:!0}:{role:n||r||`assistant`,isUser:!1}},sk=(e,t,n)=>e===`active`||n?.isLastTurn&&n.hasConfirmedFinalBody!==!0?!0:t===`summary`,ck=e=>!e,lk=e=>e.completionDisposition===`active`?e.isLastTurn&&e.sessionIsWorking?{completionDisposition:`active`,durationMs:e.durationMs}:{completionDisposition:`abnormal`,durationMs:e.durationMs}:{completionDisposition:e.completionDisposition,durationMs:e.durationMs},uk=e=>!(e.completionDisposition===`active`||e.isLastTurn&&e.sessionIsWorking&&!e.hasConfirmedSettledAssistant),dk=e=>e.isWorking?!0:e.isInActiveTurn?e.headerCompletionDisposition!==`normal`&&e.headerCompletionDisposition!==`abnormal`:!1,fk=e=>e.turnCompletionDisposition===`active`&&(e.isLastTurn||e.hasAssistantMessages)?`active`:e.headerPresentationDisposition,pk=`Authentication failed for this provider. Please re-authenticate and retry.`,mk=e=>{if(typeof e!=`string`)return!1;let t=e.toLowerCase().trim();if(!t)return!1;if(t.includes(`token refresh failed`)||t.includes(`unauthorized`)||t.includes(`invalid token`)||t.includes(`expired token`))return!0;let n=t.includes(`oauth`),r=t.includes(`failed`)||t.includes(`invalid`)||t.includes(`expired`);if(n&&r)return!0;let i=/\b401\b/.test(t),a=t.includes(`auth`)||t.includes(`token`)||t.includes(`unauthorized`);return i&&a};function hk(e,t){if(!e||typeof e!=`object`)return;let n=e,r=typeof n.data?.message==`string`?n.data.message:void 0,i=typeof n.message==`string`?n.message:void 0,a=typeof n.name==`string`?n.name:void 0,o=r||i||a;if(o)return a===`SessionRetry`?{text:`Opencode failed to send a message. Retry attempt info: \n\`${o}\``,variant:`info`}:mk(o)?{text:pk,variant:`error`}:a===`MessageAbortedError`||o.trim().toLowerCase()===`aborted`?{text:t,variant:`muted`}:{text:`Opencode failed to send message with error:\n\`${o}\``,variant:`error`}}var gk=ks(()=>Ue(()=>import(`./ToolOutputDialog-BI5vwuaT.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48]))),_k=4e3,vk=new Map,yk=new Map,bk=new Set([`bash`,`shell`,`cmd`,`terminal`]),xk=e=>{if(typeof e!=`string`)return``;let t=e.trim().toLowerCase();if(!t)return``;let n=t.replace(/:\d+$/,``);if(!n.includes(`.`))return n;let r=n.split(`.`).filter(Boolean);return r[r.length-1]??n},Sk=e=>{let t=vk.get(e);return t?new Set(t):new Set},Ck=(e,t)=>{if(vk.size>=_k&&!vk.has(e)){let e=vk.keys().next().value;typeof e==`string`&&vk.delete(e)}vk.set(e,new Set(t))},wk=e=>{let t=yk.get(e);return t?new Set(t):new Set},Tk=(e,t)=>{if(yk.size>=_k&&!yk.has(e)){let e=yk.keys().next().value;typeof e==`string`&&yk.delete(e)}yk.set(e,new Set(t))},Ek=200,Dk=new Map,Ok=e=>Dk.get(e),kk=(e,t)=>{if(!t.agent&&!t.provider&&!t.model)return;let n=Dk.get(e);if(!(n&&n.agent===t.agent&&n.provider===t.provider&&n.model===t.model)){if(Dk.size>=Ek&&!Dk.has(e)){let e=Dk.keys().next().value;typeof e==`string`&&Dk.delete(e)}Dk.set(e,t)}};function Ak(e){let t=(0,Q.c)(3),[n,r]=Z.useState(e),i,a;return t[0]===e?(i=t[1],a=t[2]):(i=()=>{e!=null&&r(e)},a=[e],t[0]=e,t[1]=i,t[2]=a),Z.useEffect(i,a),e??n}var jk=(e,t)=>{if(typeof e==`object`&&e)return e[t]},Mk=Z.memo(({message:e,previousMessage:t,nextMessage:n,onContentChange:r,animationHandlers:i,turnGroupingContext:a,assistantHeaderMessageId:o,isInActiveTurn:s=!1,activeStreamingPhase:c=null,animateUserOnMount:l=!1,onUserAnimationConsumed:u,reviewTransferDirection:d=null})=>{let{t:f}=ct(),{isMobile:p,isTablet:m,hasTouchInput:h}=mo(),g=Rh(),_=zh(g),v=p||m,y=Z.useRef(null),b=ri(e=>e.currentSessionId),x=Zi(e=>e.getAgentModelForSession),S=Zi(e=>e.getSessionModelSelection),C=ri(e=>e.revertToMessage),w=ri(e=>e.editMessagePreservingChanges),T=ri(e=>e.forkFromMessage),E=ri(t=>t.messageEditCommitting?.messageId===e.info.id&&t.messageEditCommitting?.sessionId===e.info.sessionID),D=ri(t=>t.stagedMessageEdit?.messageId===e.info.id&&t.stagedMessageEdit?.sessionId===e.info.sessionID),O=ri(e=>e.clearStagedMessageEdit);Fe(`ui.chat_message.render`),s&&Fe(`ui.chat_message.render.streaming`);let k=Ai(e=>e.providers),{showReasoningTraces:A,stickyUserHeader:j,chatRenderMode:M,showExpandedBashTools:N}=q(de(e=>({showReasoningTraces:e.showReasoningTraces,stickyUserHeader:e.stickyUserHeader,chatRenderMode:e.chatRenderMode,showExpandedBashTools:e.showExpandedBashTools})));Z.useEffect(()=>{b&&Gx.getInstance().recordSessionStart(b)},[b]);let[P,F]=Z.useState(null),[I,L]=Z.useState(!1),[R,z]=Z.useState(null),B=Z.useRef(null),[V,H]=Z.useState(()=>Sk(e.info.id)),[U,W]=Z.useState(()=>wk(e.info.id)),[ee,G]=Z.useState({open:!1,title:``,content:``});Z.useEffect(()=>{H(Sk(e.info.id)),W(wk(e.info.id))},[e.info.id]);let K=Z.useMemo(()=>ok(e.info),[e.info]).isUser,te=K&&(p||!j),ne=K&&!p&&j&&!te,re=e.info.sessionID,{currentContextAgent:ie,savedSessionAgentSelection:ae}=km(de(e=>({currentContextAgent:s&&re?e.currentAgentContext.get(re):void 0,savedSessionAgentSelection:s&&re?e.sessionAgentSelections.get(re):void 0}))),oe=Z.useMemo(()=>Rn(e.sourceParts??e.parts),[e.parts,e.sourceParts]),se=Z.useMemo(()=>K?Gi(oe):Rn(e.parts),[K,e.parts,oe]),ce=Z.useMemo(()=>{if(K||!t)return null;let e=jk(t.info,`clientRole`),n=jk(t.info,`role`);if((typeof e==`string`?e:typeof n==`string`?n:void 0)!==`user`)return null;let r=jk(t.info,`mode`),i=jk(t.info,`agent`),a=jk(t.info,`providerID`),o=jk(t.info,`modelID`),s=jk(t.info,`model`),c=typeof s==`object`&&s?s.variant:void 0,l=jk(t.info,`variant`),u=c??l,d=typeof s==`object`&&s?s.providerID:void 0,f=typeof s==`object`&&s?s.modelID:void 0,p=typeof r==`string`&&r.trim().length>0?r:typeof i==`string`&&i.trim().length>0?i:void 0,m=typeof a==`string`&&a.trim().length>0?a:typeof d==`string`&&d.trim().length>0?d:void 0,h=typeof o==`string`&&o.trim().length>0?o:typeof f==`string`&&f.trim().length>0?f:void 0,g=typeof u==`string`&&u.trim().length>0?u:void 0;return!p&&!m&&!h&&!g?null:{agentName:p,providerId:m,modelId:h,variant:g}},[K,t]),le=Z.useMemo(()=>{if(K)return;let t=jk(e.info,`mode`);if(typeof t==`string`&&t.trim().length>0)return t;let n=jk(e.info,`agent`);if(typeof n==`string`&&n.trim().length>0)return n;if(ce?.agentName)return ce.agentName;if(re)return ie||(ae??void 0)},[K,e.info,ce,re,ie,ae]),ue=K?null:jk(e.info,`providerID`),fe=K?null:jk(e.info,`modelID`),pe=Z.useMemo(()=>{if(K||!re)return null;if(ce?.providerId&&ce?.modelId)return{providerId:ce.providerId,modelId:ce.modelId};if(le){let e=x(re,le);if(e?.providerId&&e?.modelId)return e}let e=S(re);return e?.providerId&&e?.modelId?e:null},[K,re,le,ce,x,S]),me=Z.useMemo(()=>K?null:typeof ue==`string`&&ue.trim().length>0?ue:pe?.providerId??null,[K,ue,pe]),he=Z.useMemo(()=>K?null:typeof fe==`string`&&fe.trim().length>0?fe:pe?.modelId??null,[K,fe,pe]),ge=e.info.id?Ok(e.info.id):void 0;K||kk(e.info.id,{agent:le,provider:me??void 0,model:he??void 0});let _e=le??ge?.agent,ve=me??ge?.provider??null,ye=he??ge?.model??null,be=Z.useMemo(()=>{if(K)return;let e=ve&&k.length>0?k.find(e=>e.id===ve):void 0;return Si(e,ye)||void 0},[K,ve,ye,k]),xe=Z.useMemo(()=>{if(K||!me||!he)return!1;let e=k.find(e=>e.id===me);if(!e?.models||!Array.isArray(e.models))return!1;let t=e.models.find(e=>e.id===he)?.variants;return!!(t&&Object.keys(t).length>0)},[K,he,me,k]),Se=Ak(_e),Ce=Ak(ve??void 0),we=Ak(ye??void 0),Te=Ak(be),Ee=Se??void 0,De=Ce??null,Oe=we??null,ke=Te??void 0,Ae=Z.useMemo(()=>{let t=e.info.time;return typeof t?.completed==`number`?t.completed:null},[e.info.time]),je=Z.useMemo(()=>{let t=e.info.time;return typeof t?.created==`number`?t.created:null},[e.info.time]),Me=Z.useMemo(()=>K?!0:!!(Ae&&Ae>0),[K,Ae]),Ne=Z.useMemo(()=>{let t=e.info.finish;return typeof t==`string`?t:void 0},[e.info]),Pe=Z.useMemo(()=>{if(K)return null;let t=e.info.tokens;return!t||typeof t!=`object`?null:{output:typeof t.output==`number`?t.output:void 0,reasoning:typeof t.reasoning==`number`?t.reasoning:void 0}},[K,e.info]),Ie=Z.useMemo(()=>wt(se,{includeReasoning:A}),[se,A]),Le=Z.useMemo(()=>K?Ie:!Me&&M===`sorted`?[]:Ie,[M,Me,K,Ie]),Re=Z.useMemo(()=>K?[]:Ie.filter(e=>e.type===`text`),[K,Ie]),ze=Z.useMemo(()=>K?[]:Ie.filter(e=>e.type===`tool`),[K,Ie]),Be=Z.useMemo(()=>{if(!N)return new Set;let e=new Set;for(let t of ze){let n=typeof t?.id==`string`?t.id:``;if(!n)continue;let r=xk(t.tool);!r||!bk.has(r)||e.add(n)}for(let t of a?.activityParts??[]){if(t.kind!==`tool`)continue;let n=xk(t.part.tool);!n||!bk.has(n)||e.add(t.id)}return e},[N,ze,a?.activityParts]),Ve=Z.useMemo(()=>{if(Be.size===0&&U.size===0)return V;let e=new Set(V);return Be.forEach(t=>{U.has(t)||e.add(t)}),U.forEach(t=>{e.delete(t)}),e},[U,Be,V]),He=Z.useMemo(()=>{if(!K)return;let e=se.find(e=>e.type===`agent`);if(!e)return;let t=e,n=typeof t.name==`string`?t.name:void 0;if(n)return{name:n,token:t.source&&typeof t.source.value==`string`&&t.source.value.trim().length>0?t.source.value:`@${n}`}},[K,se]),Ue=K&&!hr(Le),We=typeof Ne!=`string`,Ge=Z.useMemo(()=>K?!1:Re.length===0||ze.length===0?We:!0,[Re.length,ze.length,We,K]),Ke=Z.useMemo(()=>!K&&Gx.getInstance().shouldAnimateMessage(e.info,b||e.info.sessionID),[e.info,b,K]),[qe,Je]=Z.useState(!1),Ye=Z.useMemo(()=>n?ok(n.info):null,[n]),Xe=!!a,Ze=a?.isLastAssistantInTurn??!1,Qe=dk({isWorking:a?.isWorking===!0,isInActiveTurn:s,headerCompletionDisposition:a?.completionDisposition}),$e=Z.useMemo(()=>K?!1:Xe?!Ze:Ye?!Ye.isUser&&Ye.role===`assistant`:!1,[Xe,Ze,K,Ye]),et=Z.useMemo(()=>Me?`completed`:s?c??`streaming`:`completed`,[c,s,Me]);Z.useEffect(()=>{!K||!l||u?.(e.info.id)},[l,K,e.info.id,u]),Z.useEffect(()=>{Je(!1)},[e.info.id]),Z.useEffect(()=>{let t=o??a?.headerMessageId;K||!t||t!==e.info.id||(et===`streaming`||et===`cooldown`)&&Je(!0)},[o,K,e.info.id,et,a?.headerMessageId]);let tt=Z.useMemo(()=>{if(K)return!0;let t=o??a?.headerMessageId;return t?e.info.id===t?et===`completed`||qe||et===`streaming`||et===`cooldown`:!1:!0},[o,qe,K,a,et,e.info.id]),nt=Z.useCallback(e=>{ut(e).then(t=>{t.ok&&(F(e),setTimeout(()=>F(null),2e3))})},[]),rt=K?void 0:a?.userMessageVariant??ce?.variant,it=!K&&xe&&typeof rt==`string`&&rt.trim().length>0?rt:void 0,at=Z.useMemo(()=>{if(!K)return hk(e.info?.error,f(`chat.messageBody.aborted`))},[K,e.info,f]),ot=at?.text,st=at?.variant,lt=Z.useMemo(()=>{if(K){let e=Le.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.output;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);if(e.length>0)return e.join(`
6575
6575
 
6576
6576
  `);let t=Le.filter(e=>e.type===`text`).map(e=>{let t=e.shellAction?.command;return typeof t==`string`?t.trim():``}).filter(e=>e.length>0);return t.length>0?t.join(`
6577
6577
  `):Le.filter(e=>e.type===`text`).map(e=>(e.text||e.content||``).trim()).filter(e=>e.length>0).join(`