nextclaw 0.18.8 → 0.18.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/app/index.js +5 -3
- package/package.json +12 -12
- package/resources/USAGE.md +6 -0
- package/ui-dist/assets/{api-BIg--UMJ.js → api-BurjmW4A.js} +1 -1
- package/ui-dist/assets/{app-manager-provider-BfKiVYea.js → app-manager-provider-DhxUmyTv.js} +1 -1
- package/ui-dist/assets/{app-navigation.config-xIjCAn-R.js → app-navigation.config-Bpd16Pem.js} +1 -1
- package/ui-dist/assets/{book-open-CUd69I2f.js → book-open-CVEuA0y5.js} +1 -1
- package/ui-dist/assets/{channels-list-page-5wQy-UW7.js → channels-list-page-BqhqaBf1.js} +1 -1
- package/ui-dist/assets/{chat-C7Ywus_K.js → chat-D4KecKjB.js} +7 -7
- package/ui-dist/assets/chat-page-Cc7n80lW.js +1 -0
- package/ui-dist/assets/{chunk-JZWAC4HX-THqEFwu9.js → chunk-JZWAC4HX-24FLdHl7.js} +1 -1
- package/ui-dist/assets/{config-split-page-UJSTBsEU.js → config-split-page-BGjVACdO.js} +1 -1
- package/ui-dist/assets/{createLucideIcon-DVAlgDOi.js → createLucideIcon-PPrXCGK8.js} +1 -1
- package/ui-dist/assets/{desktop-update-config-8wQZEsBU.js → desktop-update-config-fMLlSStv.js} +1 -1
- package/ui-dist/assets/{dialog-t7OAmObC.js → dialog-CTCX7oLf.js} +1 -1
- package/ui-dist/assets/{dist-DWPNydLC.js → dist-FL5e8mMi.js} +1 -1
- package/ui-dist/assets/{doc-browser-DznuT-CU.js → doc-browser-C02neCIE.js} +1 -1
- package/ui-dist/assets/doc-browser-COj7x090.js +1 -0
- package/ui-dist/assets/{doc-browser-context-zXaTjrpA.js → doc-browser-context-C-WPOji4.js} +1 -1
- package/ui-dist/assets/{doc-browser-t96ibd-b.js → doc-browser-fyn7eDTp.js} +1 -1
- package/ui-dist/assets/{es2015-BRVsmfFO.js → es2015-BNy4R8AC.js} +1 -1
- package/ui-dist/assets/{external-link-D1Xqff6i.js → external-link-BNtqJE01.js} +1 -1
- package/ui-dist/assets/{folder-B_fuaX3x.js → folder-QyJHVUNz.js} +1 -1
- package/ui-dist/assets/{hash-BRvv_UUq.js → hash-BGYUE-zr.js} +1 -1
- package/ui-dist/assets/{i18n-CF_jgT_-.js → i18n-CM4y8Mw9.js} +1 -1
- package/ui-dist/assets/index-CtVSzMPM.js +2 -0
- package/ui-dist/assets/index-N3hjuljD.css +1 -0
- package/ui-dist/assets/{key-round-DFVNXZcD.js → key-round-DenCfA2w.js} +1 -1
- package/ui-dist/assets/loader-circle-R23uEPkM.js +1 -0
- package/ui-dist/assets/{logo-badge-CRVKkIl9.js → logo-badge-CKAxvQFc.js} +1 -1
- package/ui-dist/assets/{logos-BVCi_7_I.js → logos-CqXnaJIm.js} +1 -1
- package/ui-dist/assets/{marketplace-page-apq5LpYx.js → marketplace-page-XnDa2ulT.js} +1 -1
- package/ui-dist/assets/marketplace-page-mF-M5mku.js +1 -0
- package/ui-dist/assets/{mcp-marketplace-page-DiqTAdRJ.js → mcp-marketplace-page-BArKWcRZ.js} +1 -1
- package/ui-dist/assets/mcp-marketplace-page-DBUcIIHJ.js +1 -0
- package/ui-dist/assets/message-square-Dm34zD6k.js +1 -0
- package/ui-dist/assets/{model-config-cth12uRn.js → model-config-ByeL6Toe.js} +1 -1
- package/ui-dist/assets/{notice-card-CXY09tsa.js → notice-card-D00-02yg.js} +1 -1
- package/ui-dist/assets/play-ul4L6MWm.js +1 -0
- package/ui-dist/assets/plus-D14303DH.js +1 -0
- package/ui-dist/assets/{popover-CbQxrchk.js → popover-AmJkxio3.js} +1 -1
- package/ui-dist/assets/{provider-scoped-model-input-CZEB2m98.js → provider-scoped-model-input-CfFJsJp-.js} +1 -1
- package/ui-dist/assets/{providers-list-Dsj2BYPm.js → providers-list-HMQzW2WV.js} +1 -1
- package/ui-dist/assets/{refresh-ccw-C-ytTHiq.js → refresh-ccw-B-dhb3yS.js} +1 -1
- package/ui-dist/assets/remote-B4ELSd3u.js +1 -0
- package/ui-dist/assets/{rotate-cw-ClSrRUa0.js → rotate-cw-BWqAG3Fv.js} +1 -1
- package/ui-dist/assets/{runtime-config-page-CDniEeHX.js → runtime-config-page-N4FP6H0M.js} +1 -1
- package/ui-dist/assets/{save-KxhpE3Zr.js → save-DpdkGieJ.js} +1 -1
- package/ui-dist/assets/{search-Bz3Q64sr.js → search-CQUdr7j_.js} +1 -1
- package/ui-dist/assets/{search-config-C_xRBv_i.js → search-config-B62TY-z2.js} +1 -1
- package/ui-dist/assets/{secrets-config-BOL024Fj.js → secrets-config-YCsGd1am.js} +1 -1
- package/ui-dist/assets/{select-tRTLG4FK.js → select-DVUtSFHZ.js} +1 -1
- package/ui-dist/assets/{sessions-config-page-Ck6nbIFq.js → sessions-config-page-BKN-XdKr.js} +1 -1
- package/ui-dist/assets/{setting-row-DMDgBCC7.js → setting-row-Cb5-lFs-.js} +1 -1
- package/ui-dist/assets/{settings-Cto6z-Ij.js → settings-DgtZZlnF.js} +1 -1
- package/ui-dist/assets/skeleton-BCPi52jT.js +1 -0
- package/ui-dist/assets/{sparkles-xZ74eW0P.js → sparkles-DNSCyDhL.js} +1 -1
- package/ui-dist/assets/{status-dot-Bobpfutv.js → status-dot-X_j51OfA.js} +1 -1
- package/ui-dist/assets/{tabs-custom-C3Mf-NLb.js → tabs-custom-CcWmekaF.js} +1 -1
- package/ui-dist/assets/{tag-chip-BZ14i5b1.js → tag-chip-fdbK2wE6.js} +1 -1
- package/ui-dist/assets/{theme-provider-D6Cgm6i-.js → theme-provider-WTWq_jYq.js} +1 -1
- package/ui-dist/assets/{tooltip-7lsLGcL9.js → tooltip-BkZCQcKw.js} +1 -1
- package/ui-dist/assets/{trash-2-WFSNa5oj.js → trash-2-CqciSCsg.js} +1 -1
- package/ui-dist/assets/{use-config-CXu7dFzw.js → use-config-CyvhbRhf.js} +1 -1
- package/ui-dist/assets/{use-confirm-dialog-Df1SozKw.js → use-confirm-dialog-DSrb9205.js} +1 -1
- package/ui-dist/assets/{use-infinite-scroll-loader-BogRuzgz.js → use-infinite-scroll-loader-DmowtyTI.js} +1 -1
- package/ui-dist/assets/{use-viewport-layout-CWlW5b-T.js → use-viewport-layout-CaALCA51.js} +1 -1
- package/ui-dist/assets/x-tYcSDsrY.js +1 -0
- package/ui-dist/index.html +39 -39
- package/ui-dist/assets/chat-page-DfVjokks.js +0 -1
- package/ui-dist/assets/doc-browser-BIggpN8Z.js +0 -1
- package/ui-dist/assets/index-D4Rrurox.css +0 -1
- package/ui-dist/assets/index-DlDSGTF8.js +0 -2
- package/ui-dist/assets/loader-circle-DEz3bHGb.js +0 -1
- package/ui-dist/assets/marketplace-page-DVmk8dZk.js +0 -1
- package/ui-dist/assets/mcp-marketplace-page-CskrJuKU.js +0 -1
- package/ui-dist/assets/message-square-CLhDWybk.js +0 -1
- package/ui-dist/assets/play-CnnPm8ca.js +0 -1
- package/ui-dist/assets/plus-CdYMdiws.js +0 -1
- package/ui-dist/assets/remote-DMMC2PSo.js +0 -1
- package/ui-dist/assets/skeleton-BwfJfVK3.js +0 -1
- package/ui-dist/assets/x-BvS2y4e_.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{_ as e,a as t,d as n,f as r,g as i,h as a,i as o,m as s,n as c,p as l,t as u,u as d}from"./i18n-CF_jgT_-.js";import{At as f,Ft as p,Gt as m,H as h,It as g,Mt as _,Ot as v,Pt as y,_t as b,at as x,b as S,bt as C,g as w,h as T,it as E,jt as D,kt as O,m as ee,mt as k,n as te,ot as A,p as ne,r as j,rt as re,st as ie,y as ae,yt as oe,zt as se}from"./api-BIg--UMJ.js";import{a as ce,i as le,n as ue,o as de,r as fe,t as pe}from"./dialog-t7OAmObC.js";import{t as M}from"./createLucideIcon-DVAlgDOi.js";import{b as me,c as he,d as ge,f as _e,g as ve,h as ye,l as be,m as xe,n as Se,s as Ce,u as we,v as Te,y as Ee}from"./theme-provider-D6Cgm6i-.js";import{n as De,t as Oe}from"./search-Bz3Q64sr.js";import{t as ke}from"./book-open-CUd69I2f.js";import{D as Ae,O as je,_ as Me,b as Ne,c as Pe,d as Fe,f as Ie,g as Le,h as Re,i as ze,k as Be,l as Ve,m as He,n as Ue,o as We,p as Ge,r as Ke,s as qe,t as Je,u as Ye,v as Xe,y as Ze}from"./select-tRTLG4FK.js";import{t as Qe}from"./external-link-D1Xqff6i.js";import{t as $e}from"./folder-B_fuaX3x.js";import{n as et,t as tt}from"./logos-BVCi_7_I.js";import{t as nt}from"./loader-circle-DEz3bHGb.js";import{t as rt}from"./plus-CdYMdiws.js";import{t as it}from"./refresh-ccw-C-ytTHiq.js";import{t as at}from"./settings-Cto6z-Ij.js";import{t as ot}from"./sparkles-xZ74eW0P.js";import{t as st}from"./trash-2-WFSNa5oj.js";import{t as ct}from"./x-BvS2y4e_.js";import{i as lt}from"./doc-browser-context-zXaTjrpA.js";import{n as ut}from"./doc-browser-DznuT-CU.js";import{n as dt,t as ft}from"./use-viewport-layout-CWlW5b-T.js";import{m as pt}from"./use-config-CXu7dFzw.js";import{a as mt,c as ht,i as gt,n as _t,o as vt,r as yt,s as bt,t as xt}from"./popover-CbQxrchk.js";import{t as St}from"./logo-badge-CRVKkIl9.js";import{a as Ct,c as wt,i as Tt,l as Et,n as Dt,o as Ot,r as kt,s as At,t as jt}from"./tooltip-7lsLGcL9.js";import{t as Mt}from"./skeleton-BwfJfVK3.js";var Nt=M(`ArrowUpRight`,[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]),Pt=M(`ArrowUp`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),Ft=M(`Brain`,[[`path`,{d:`M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z`,key:`l5xja`}],[`path`,{d:`M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z`,key:`ep3f8r`}],[`path`,{d:`M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4`,key:`1p4c4q`}],[`path`,{d:`M17.599 6.5a3 3 0 0 0 .399-1.375`,key:`tmeiqw`}],[`path`,{d:`M6.003 5.125A3 3 0 0 0 6.401 6.5`,key:`105sqy`}],[`path`,{d:`M3.477 10.896a4 4 0 0 1 .585-.396`,key:`ql3yin`}],[`path`,{d:`M19.938 10.5a4 4 0 0 1 .585.396`,key:`1qfode`}],[`path`,{d:`M6 18a4 4 0 0 1-1.967-.516`,key:`2e4loj`}],[`path`,{d:`M19.967 17.484A4 4 0 0 1 18 18`,key:`159ez6`}]]),It=M(`ChevronRight`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),Lt=M(`CodeXml`,[[`path`,{d:`m18 16 4-4-4-4`,key:`1inbqp`}],[`path`,{d:`m6 8-4 4 4 4`,key:`15zrgr`}],[`path`,{d:`m14.5 4-5 16`,key:`e7oirm`}]]),Rt=M(`Copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),zt=M(`Ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),Bt=M(`FileArchive`,[[`path`,{d:`M10 12v-1`,key:`v7bkov`}],[`path`,{d:`M10 18v-2`,key:`1cjy8d`}],[`path`,{d:`M10 7V6`,key:`dljcrl`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M15.5 22H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v16a2 2 0 0 0 .274 1.01`,key:`gkbcor`}],[`circle`,{cx:`10`,cy:`20`,r:`2`,key:`1xzdoj`}]]),Vt=M(`FileAudio2`,[[`path`,{d:`M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v2`,key:`17k7jt`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`circle`,{cx:`3`,cy:`17`,r:`1`,key:`vo6nti`}],[`path`,{d:`M2 17v-3a4 4 0 0 1 8 0v3`,key:`1ggdre`}],[`circle`,{cx:`9`,cy:`17`,r:`1`,key:`bc1fq4`}]]),Ht=M(`FileCode2`,[[`path`,{d:`M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4`,key:`1pf5j1`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`m5 12-3 3 3 3`,key:`oke12k`}],[`path`,{d:`m9 18 3-3-3-3`,key:`112psh`}]]),Ut=M(`FileImage`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`circle`,{cx:`10`,cy:`12`,r:`2`,key:`737tya`}],[`path`,{d:`m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22`,key:`wt3hpn`}]]),Wt=M(`FileJson2`,[[`path`,{d:`M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4`,key:`1pf5j1`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M4 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1`,key:`fq0c9t`}],[`path`,{d:`M8 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1`,key:`4gibmv`}]]),Gt=M(`FileSpreadsheet`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M8 13h2`,key:`yr2amv`}],[`path`,{d:`M14 13h2`,key:`un5t4a`}],[`path`,{d:`M8 17h2`,key:`2yhykz`}],[`path`,{d:`M14 17h2`,key:`10kma7`}]]),Kt=M(`FileText`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),qt=M(`FileVideo2`,[[`path`,{d:`M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4`,key:`1pf5j1`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`rect`,{width:`8`,height:`6`,x:`2`,y:`12`,rx:`1`,key:`1a6c1e`}],[`path`,{d:`m10 15.5 4 2.5v-6l-4 2.5`,key:`t7cp39`}]]),Jt=M(`File`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}]]),Yt=M(`FolderGit2`,[[`path`,{d:`M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v5`,key:`1w6njk`}],[`circle`,{cx:`13`,cy:`12`,r:`2`,key:`1j92g6`}],[`path`,{d:`M18 19c-2.8 0-5-2.2-5-5v8`,key:`pkpw2h`}],[`circle`,{cx:`20`,cy:`19`,r:`2`,key:`1obnsp`}]]),Xt=M(`FolderOpen`,[[`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2`,key:`usdka0`}]]),Zt=M(`FolderTree`,[[`path`,{d:`M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`hod4my`}],[`path`,{d:`M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`w4yl2u`}],[`path`,{d:`M3 5a2 2 0 0 0 2 2h3`,key:`f2jnh7`}],[`path`,{d:`M3 3v13a2 2 0 0 0 2 2h3`,key:`k8epm1`}]]),Qt=M(`FolderUp`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}],[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`m9 13 3-3 3 3`,key:`1pxg3c`}]]),$t=M(`FolderX`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}],[`path`,{d:`m9.5 10.5 5 5`,key:`ra9qjz`}],[`path`,{d:`m14.5 10.5-5 5`,key:`l2rkpq`}]]),en=M(`GitBranch`,[[`line`,{x1:`6`,x2:`6`,y1:`3`,y2:`15`,key:`17qcm7`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M18 9a9 9 0 0 1-9 9`,key:`n2h4wq`}]]),tn=M(`HeartPulse`,[[`path`,{d:`M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z`,key:`c3ymky`}],[`path`,{d:`M3.22 12H9.5l.5-1 2 4.5 2-7 1.5 3.5h5.27`,key:`1uw2ng`}]]),nn=M(`House`,[[`path`,{d:`M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8`,key:`5wwlr5`}],[`path`,{d:`M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`1d0kgt`}]]),rn=M(`MessageSquareText`,[[`path`,{d:`M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z`,key:`1lielz`}],[`path`,{d:`M13 8H7`,key:`14i4kc`}],[`path`,{d:`M17 12H7`,key:`16if0g`}]]),an=M(`Minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),on=M(`Paperclip`,[[`path`,{d:`m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48`,key:`1u3ebp`}]]),sn=M(`Pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),cn=M(`Puzzle`,[[`path`,{d:`M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z`,key:`w46dr5`}]]),ln=M(`Terminal`,[[`polyline`,{points:`4 17 10 11 4 5`,key:`akl6gq`}],[`line`,{x1:`12`,x2:`20`,y1:`19`,y2:`19`,key:`q2wloq`}]]),un=M(`TriangleAlert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),dn=M(`User`,[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]),N=l();function fn({isProjectFirstView:e,onSelectMode:t}){return(0,N.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,children:[(0,N.jsx)(`button`,{type:`button`,"aria-pressed":!e,onClick:()=>t(`time-first`),className:d(`transition-colors`,e?`text-gray-400 hover:text-gray-600`:`font-medium text-gray-600`),children:o(`chatSidebarViewTime`)}),(0,N.jsx)(`span`,{className:`text-gray-300`,children:`/`}),(0,N.jsx)(`button`,{type:`button`,"aria-pressed":e,onClick:()=>t(`project-first`),className:d(`transition-colors`,e?`font-medium text-gray-600`:`text-gray-400 hover:text-gray-600`),children:o(`chatSidebarViewProject`)})]})}var pn={wx:`weixin`,lark:`feishu`},mn={heartbeat:{icon:`heartbeat`},cron:{icon:`cron`}},hn={codex:`chatSessionTypeCodex`,claude:`chatSessionTypeClaude`};function gn(e){return e?.trim().toLowerCase()??``}function _n(e){return e.split(/[-_]+/g).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function vn(e,t){let n=gn(e);if(!n||n===`native`)return null;let r=t.find(e=>gn(e.value)===n);return r?.label.trim()?r.label.trim():_n(n)}function yn(e,t){let n=gn(e);return!n||n===`native`?null:t.find(e=>gn(e.value)===n)??null}function bn(e){let t=gn(e);if(!t)return null;let n=pn[t]??t;return tt(n)?n:null}function xn(e,t){let n=bn(e.channel??``);if(n)return{icon:{kind:`channel-logo`,channel:n},label:null};let r=mn[gn(e.type)];if(r)return{icon:{kind:`symbol`,icon:r.icon},label:null};let i=gn(e.sessionType),a=yn(i,t);if(a?.icon?.src?.trim())return{icon:{kind:`runtime-image`,src:a.icon.src,alt:a.icon.alt??null,name:a.label},label:null};let s=hn[i];return s?{icon:null,label:o(s)}:{icon:null,label:a?.label?.trim()||vn(e.sessionType,t)}}var Sn=`app://`;function Cn(e){let t=e.trim().replace(/^\/+/,``);if(!t)return null;let n=t.split(`/`);return n.some(e=>e.trim().length===0||e===`.`||e===`..`)?null:n.join(`/`)}function wn(e){let t=e.trim();if(!t)return null;if(!t.startsWith(Sn))return t;let n=Cn(t.slice(6));return n?`/${n}`:null}function Tn({icon:e,className:t}){if(e.kind===`channel-logo`)return(0,N.jsx)(En,{channel:e.channel,className:t});if(e.kind===`runtime-image`){let n=wn(e.src);return(0,N.jsx)(St,{name:e.name?.trim()||e.alt?.trim()||`runtime`,src:n??void 0,className:d(`h-[1.125rem] w-[1.125rem]`,t),imgClassName:`h-full w-full object-contain`,fallback:(0,N.jsx)(Ee,{className:d(`h-3 w-3 text-gray-500`,t)})})}return e.icon===`heartbeat`?(0,N.jsx)(tn,{className:d(`h-3.5 w-3.5`,t)}):(0,N.jsx)(me,{className:d(`h-3.5 w-3.5`,t)})}function En({channel:e,className:t}){return(0,N.jsx)(St,{name:e,src:tt(e),className:d(`h-[1.125rem] w-[1.125rem]`,t),imgClassName:`h-full w-full object-contain`,fallback:(0,N.jsx)(Ee,{className:`h-3 w-3 text-gray-500`})})}function Dn(e){let{option:t,onSelect:n}=e,r=t.ready===!1?t.reasonMessage?.trim()||o(`statusSetup`):null;return(0,N.jsx)(`button`,{type:`button`,onClick:n,className:`w-full rounded-2xl px-3 py-2.5 text-left transition-colors hover:bg-gray-50`,children:(0,N.jsx)(`div`,{className:`flex items-start gap-3`,children:(0,N.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-2.5`,children:[t.icon?.src?(0,N.jsx)(`span`,{className:`inline-flex h-5 w-5 shrink-0 items-center justify-center pt-0.5`,children:(0,N.jsx)(Tn,{icon:{kind:`runtime-image`,src:t.icon.src,alt:t.icon.alt??null,name:t.label}})}):(0,N.jsx)(`span`,{className:`inline-flex h-5 w-5 shrink-0 items-center justify-center pt-0.5 text-gray-400`,children:(0,N.jsx)(Ee,{className:`h-4 w-4`})}),(0,N.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,N.jsx)(`div`,{className:`truncate text-[13px] font-semibold text-gray-900`,children:t.label}),(0,N.jsxs)(`span`,{className:d(`inline-flex shrink-0 items-center gap-1.5 text-[11px] font-medium`,t.ready===!1?`text-amber-700`:`text-emerald-600`),children:[(0,N.jsx)(`span`,{className:d(`h-1.5 w-1.5 rounded-full`,t.ready===!1?`bg-amber-500`:`bg-emerald-500`)}),t.ready===!1?o(`statusSetup`):o(`statusReady`)]})]}),r?(0,N.jsx)(`div`,{className:`mt-1 pr-4 text-[11px] leading-4 text-gray-500`,children:r}):null]})]})})})}var P=e(s(),1);function On(e,t){return t.some(t=>t.value===e)?e:t[0]?.value??e}function kn(e){let{groups:t,defaultSessionType:n,sessionTypeOptions:r,renderSessionItem:i,onCreateSession:a}=e,[s,c]=(0,P.useState)(null),l=(0,P.useMemo)(()=>On(n,r),[n,r]),u=r.length>1;return(0,N.jsx)(`div`,{className:`space-y-3`,children:t.map(e=>{let t=`${o(`chatSidebarNewTask`)} · ${e.projectName}`;return(0,N.jsxs)(`div`,{children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-2 py-0.5`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,N.jsx)(`div`,{className:`truncate text-[11px] font-medium uppercase tracking-wider text-gray-500`,title:e.projectRoot,children:e.projectName}),(0,N.jsx)(`span`,{className:`shrink-0 text-[10px] text-gray-400`,children:e.items.length})]}),u?(0,N.jsxs)(xt,{open:s===e.projectRoot,onOpenChange:t=>{c(t?e.projectRoot:null)},children:[(0,N.jsx)(yt,{asChild:!0,children:(0,N.jsx)(f,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0 rounded-lg text-gray-400 hover:bg-white hover:text-gray-900`,"aria-label":t,title:t,children:(0,N.jsx)(rt,{className:`h-3.5 w-3.5`})})}),(0,N.jsxs)(_t,{align:`end`,className:`w-56 rounded-2xl border border-gray-200/80 bg-white p-1.5 shadow-[0_24px_60px_-28px_rgba(15,23,42,0.38)]`,children:[(0,N.jsx)(`div`,{className:`px-3 pb-1 pt-2 text-[10px] font-semibold uppercase tracking-[0.18em] text-gray-400`,children:o(`chatSessionTypeLabel`)}),(0,N.jsx)(`div`,{className:`space-y-1`,children:r.map(t=>(0,N.jsx)(Dn,{option:t,onSelect:()=>{a(t.value,e.projectRoot),c(null)}},`${e.projectRoot}:${t.value}`))})]})]}):(0,N.jsx)(f,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0 rounded-lg text-gray-400 hover:bg-white hover:text-gray-900`,onClick:()=>a(l,e.projectRoot),"aria-label":t,title:t,children:(0,N.jsx)(rt,{className:`h-3.5 w-3.5`})})]}),(0,N.jsx)(`div`,{className:`space-y-0.5 pl-2`,children:e.items.map(i)})]},e.projectRoot)})})}var An=[[`bg-amber-100`,`text-amber-700`],[`bg-emerald-100`,`text-emerald-700`],[`bg-blue-100`,`text-blue-700`],[`bg-rose-100`,`text-rose-700`],[`bg-cyan-100`,`text-cyan-700`],[`bg-violet-100`,`text-violet-700`]];function jn(e){let t=0;for(let n=0;n<e.length;n+=1)t=(t<<5)-t+e.charCodeAt(n),t|=0;return Math.abs(t)}function Mn({agentId:e,displayName:t,avatarUrl:n,className:r}){let i=t?.trim()||e,[a,o]=An[jn(e)%An.length]??An[0];return n?.trim()?(0,N.jsx)(`img`,{src:n,alt:t?.trim()||e,className:d(`rounded-full object-cover`,r)}):(0,N.jsx)(`div`,{className:d(`rounded-full flex items-center justify-center font-semibold`,a,o,r),"aria-label":t?.trim()||e,children:e.trim().toLowerCase()===`main`?(0,N.jsx)(Ee,{className:`h-[55%] w-[55%]`,strokeWidth:2.4}):(i.trim()||`A`).slice(0,1).toUpperCase()})}function Nn({status:e,className:t}){let n=o(e===`running`?`sessionsRunStatusRunning`:`sessionsRunStatusQueued`);return(0,N.jsxs)(`span`,{className:d(`inline-flex h-3.5 w-3.5 items-center justify-center text-gray-400`,t),title:n,"aria-label":n,children:[(0,N.jsx)(nt,{className:`h-3 w-3 animate-spin`}),(0,N.jsx)(`span`,{className:`sr-only`,children:n})]})}function Pn({session:e,draftLabel:t,isSaving:n,onDraftLabelChange:r,onSave:i,onCancel:a}){return(0,N.jsxs)(`div`,{className:`space-y-2`,children:[(0,N.jsx)(O,{value:t,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),i()):e.key===`Escape`&&(e.preventDefault(),a())},placeholder:o(`sessionsLabelPlaceholder`),className:`h-8 rounded-lg border-gray-300 bg-white text-xs`,autoFocus:!0,disabled:n}),(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,N.jsx)(`div`,{className:`min-w-0 text-[11px] text-gray-400 truncate`,children:e.key}),(0,N.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,N.jsx)(f,{type:`button`,size:`icon`,variant:`ghost`,className:`h-7 w-7 rounded-lg text-gray-500 hover:bg-white hover:text-gray-900`,onClick:()=>void i(),disabled:n,"aria-label":o(`save`),children:(0,N.jsx)(Be,{className:`h-3.5 w-3.5`})}),(0,N.jsx)(f,{type:`button`,size:`icon`,variant:`ghost`,className:`h-7 w-7 rounded-lg text-gray-500 hover:bg-white hover:text-gray-900`,onClick:a,disabled:n,"aria-label":o(`cancel`),children:(0,N.jsx)(ct,{className:`h-3.5 w-3.5`})})]})]})]})}function Fn({session:e,active:t,showUnreadDot:n,runStatus:r,context:i,title:a,agentId:s,agentLabel:c,agentAvatarUrl:l,childSessionCount:f=0,onSelect:p,onOpenChildSessions:m,onStartEditing:h}){return(0,N.jsxs)(`div`,{className:`group/session relative`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:p,className:`w-full text-left`,children:[(0,N.jsxs)(`div`,{className:d(`grid grid-cols-[minmax(0,1fr)_auto] items-start gap-2`,f>0&&m?`pr-14`:`pr-6`),children:[(0,N.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[s?.trim()&&s.trim().toLowerCase()!==`main`?(0,N.jsx)(Mn,{agentId:s,displayName:c,avatarUrl:l,className:`h-5 w-5 shrink-0`}):null,(0,N.jsx)(`span`,{className:`truncate font-medium`,children:a}),i.label?(0,N.jsx)(`span`,{className:d(`shrink-0 rounded-full border px-1.5 py-0.5 text-[10px] font-semibold leading-none`,t?`border-gray-300 bg-white/80 text-gray-700`:`border-gray-200 bg-gray-100 text-gray-500`),children:i.label}):null,i.icon?(0,N.jsx)(`span`,{className:`inline-flex h-[1.125rem] w-[1.125rem] shrink-0 items-center justify-center`,children:(0,N.jsx)(Tn,{icon:i.icon,className:t?`text-gray-700`:`text-gray-500`})}):null]}),r?(0,N.jsx)(`span`,{className:`inline-flex shrink-0 items-center justify-end gap-1.5 pt-0.5`,children:(0,N.jsx)(Nn,{status:r})}):null]}),(0,N.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-[11px] text-gray-400`,children:[(0,N.jsxs)(`span`,{className:`min-w-0 truncate`,children:[c?.trim()?`${c} · `:``,e.messageCount]}),n?(0,N.jsx)(`span`,{"aria-label":o(`chatSessionUnread`),className:`ml-auto h-2 w-2 shrink-0 rounded-full bg-primary`}):(0,N.jsx)(`span`,{className:`ml-auto shrink-0`,children:u(e.updatedAt)})]})]}),f>0&&m?(0,N.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),m()},className:d(`absolute right-6 top-0 inline-flex h-5 items-center gap-1 rounded-md px-1.5 text-[10px] font-medium text-gray-400 transition-all hover:bg-white hover:text-gray-900`,t?`opacity-100`:`opacity-0 group-hover/session:opacity-100 group-focus-within/session:opacity-100`),"aria-label":o(`chatSessionOpenChildSessions`),title:o(`chatSessionOpenChildSessions`),children:[(0,N.jsx)(en,{className:`h-3.5 w-3.5`}),(0,N.jsx)(`span`,{children:f})]}):null,(0,N.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),h()},className:d(`absolute right-0 top-0 inline-flex h-5 w-5 items-center justify-center rounded-md text-gray-400 transition-all hover:bg-white hover:text-gray-900`,t?`opacity-100`:`opacity-0 group-hover/session:opacity-100 group-focus-within/session:opacity-100`),"aria-label":o(`edit`),children:(0,N.jsx)(sn,{className:`h-3 w-3`})})]})}function In({session:e,active:t,showUnreadDot:n,runStatus:r,context:i,title:a,agentId:o,agentLabel:s,agentAvatarUrl:c,childSessionCount:l,isEditing:u,draftLabel:f,isSaving:p,onSelect:m,onOpenChildSessions:h,onStartEditing:g,onDraftLabelChange:_,onSave:v,onCancel:y}){return(0,N.jsx)(`div`,{className:d(`w-full rounded-xl px-3 py-2.5 text-left transition-all text-[13px]`,t?`bg-gray-200 text-gray-900 font-semibold shadow-sm`:`text-gray-700 hover:bg-gray-200/60 hover:text-gray-900`),children:u?(0,N.jsx)(Pn,{session:e,draftLabel:f,isSaving:p,onDraftLabelChange:_,onSave:v,onCancel:y}):(0,N.jsx)(Fn,{session:e,active:t,showUnreadDot:n,runStatus:r,context:i,title:a,agentId:o,agentLabel:s,agentAvatarUrl:c,onSelect:m,childSessionCount:l,onOpenChildSessions:h,onStartEditing:g})})}var Ln=[{icon:ye,titleKey:`chatWelcomeCapability1Title`,descKey:`chatWelcomeCapability1Desc`},{icon:Te,titleKey:`chatWelcomeCapability2Title`,descKey:`chatWelcomeCapability2Desc`},{icon:me,titleKey:`chatWelcomeCapability3Title`,descKey:`chatWelcomeCapability3Desc`}];function Rn({onCreateSession:e,agents:t,selectedAgentId:n,onSelectAgent:r}){let i=t.find(e=>e.id===n)??null;return(0,N.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,N.jsxs)(`div`,{className:`max-w-lg w-full text-center`,children:[(0,N.jsx)(`div`,{className:`mx-auto mb-6 h-16 w-16 rounded-2xl bg-primary/10 flex items-center justify-center`,children:(0,N.jsx)(Ee,{className:`h-8 w-8 text-primary`})}),(0,N.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 mb-2`,children:o(`chatWelcomeTitle`)}),(0,N.jsx)(`p`,{className:`text-sm text-gray-500 mb-8`,children:o(`chatWelcomeSubtitle`)}),(0,N.jsxs)(`div`,{className:`mb-6 flex items-center justify-center gap-2.5`,children:[(0,N.jsx)(`span`,{className:`text-[13px] font-medium text-gray-500`,children:o(`chatDraftAgentTitle`)}),(0,N.jsxs)(Je,{value:n,onValueChange:r,children:[(0,N.jsxs)(ze,{"aria-label":o(`chatDraftAgentTitle`),className:`h-auto w-auto gap-1 rounded-full border-0 bg-transparent px-1.5 py-1 text-gray-500 shadow-none hover:bg-white/70 hover:text-gray-800 focus:ring-0`,children:[(0,N.jsx)(`span`,{className:`sr-only`,children:o(`chatDraftAgentTitle`)}),(0,N.jsx)(`div`,{className:`flex items-center gap-1.5`,children:i?(0,N.jsx)(Mn,{agentId:i.id,displayName:i.displayName,avatarUrl:i.avatarUrl,className:`h-7 w-7 shrink-0`}):null})]}),(0,N.jsx)(Ue,{className:`rounded-xl border-gray-200/80 shadow-lg`,children:t.map(e=>(0,N.jsx)(Ke,{value:e.id,className:`rounded-lg pr-10`,children:(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,N.jsx)(Mn,{agentId:e.id,displayName:e.displayName,avatarUrl:e.avatarUrl,className:`h-5 w-5 shrink-0`}),(0,N.jsx)(`span`,{className:`truncate text-sm font-medium text-gray-700`,children:e.displayName?.trim()||e.id})]})},e.id))})]})]}),(0,N.jsx)(`div`,{className:`grid grid-cols-3 gap-3`,children:Ln.map(t=>{let n=t.icon;return(0,N.jsxs)(`button`,{onClick:e,className:`rounded-2xl border border-gray-200 bg-white p-4 text-left shadow-card hover:shadow-card-hover transition-shadow cursor-pointer`,children:[(0,N.jsx)(`div`,{className:`h-9 w-9 rounded-xl bg-primary/8 flex items-center justify-center mb-3`,children:(0,N.jsx)(n,{className:`h-4.5 w-4.5 text-primary`})}),(0,N.jsx)(`div`,{className:`text-sm font-semibold text-gray-900 mb-1`,children:o(t.titleKey)}),(0,N.jsx)(`div`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:o(t.descKey)})]},t.titleKey)})})]})})}var zn=e=>`[data-item-index="${e}"]`;function Bn(e){let{activeIndex:t,containerRef:n,getItemSelector:r,isEnabled:i,itemCount:a}=e,o=r??zn;(0,P.useEffect)(()=>{if(!i||a===0)return;let e=n.current;if(!e)return;let r=e.querySelector(o(t));typeof r?.scrollIntoView==`function`&&r.scrollIntoView({block:`nearest`,inline:`nearest`})},[t,n,o,i,a])}function Vn(){let e=(0,P.useRef)(null),[t,n]=(0,P.useState)(null);return(0,P.useEffect)(()=>{let t=e.current;if(!t||typeof ResizeObserver>`u`)return;let r=()=>{n(t.getBoundingClientRect().width)};r();let i=new ResizeObserver(()=>r());return i.observe(t),()=>i.disconnect()},[]),{elementRef:e,width:t}}function F(...e){return n(r(e))}var Hn=P.forwardRef(({className:e,type:t,...n},r)=>(0,N.jsx)(`input`,{type:t,className:F(`flex h-9 w-full rounded-xl border border-gray-200/80 bg-white px-3.5 py-2 text-sm text-gray-900 file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-gray-300 placeholder:font-normal focus:outline-none focus:ring-1 focus:ring-primary/40 focus:border-primary/40 transition-colors disabled:cursor-not-allowed disabled:opacity-50`,e),ref:r,...n}));Hn.displayName=`ChatInput`;var Un=bt,Wn=ht,Gn=gt,Kn=P.forwardRef(({className:e,sideOffset:t=8,align:n=`start`,...r},i)=>(0,N.jsx)(vt,{children:(0,N.jsx)(mt,{ref:i,sideOffset:t,align:n,className:F(`z-[var(--z-popover,50)] w-72 overflow-hidden rounded-2xl border border-gray-200/50 bg-white p-4 shadow-lg animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...r})}));Kn.displayName=mt.displayName;var qn=He,Jn=qe,Yn=Ze,Xn=P.forwardRef(({className:e,children:t,...n},r)=>(0,N.jsxs)(Xe,{ref:r,className:F(`flex h-9 w-full items-center justify-between whitespace-nowrap rounded-xl border border-gray-200/80 bg-white px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/40 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1`,e),...n,children:[t,(0,N.jsx)(Pe,{asChild:!0,children:(0,N.jsx)(je,{className:`h-4 w-4 opacity-50`})})]}));Xn.displayName=Xe.displayName;var Zn=P.forwardRef(({className:e,...t},n)=>(0,N.jsx)(Le,{ref:n,className:F(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,N.jsx)(Ae,{className:`h-4 w-4`})}));Zn.displayName=Le.displayName;var Qn=P.forwardRef(({className:e,...t},n)=>(0,N.jsx)(Re,{ref:n,className:F(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,N.jsx)(je,{className:`h-4 w-4`})}));Qn.displayName=Re.displayName;var $n=P.forwardRef(({className:e,children:t,position:n=`popper`,...r},i)=>(0,N.jsx)(Ge,{children:(0,N.jsxs)(We,{ref:i,className:F(`relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md bg-white text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,...r,children:[(0,N.jsx)(Zn,{}),(0,N.jsx)(Ne,{className:F(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]`),children:t}),(0,N.jsx)(Qn,{})]})}));$n.displayName=We.displayName;var er=P.forwardRef(({className:e,...t},n)=>(0,N.jsx)(Ie,{ref:n,className:F(`px-2 py-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500`,e),...t}));er.displayName=Ie.displayName;var tr=P.forwardRef(({className:e,children:t,...n},r)=>(0,N.jsxs)(Ve,{ref:r,className:F(`relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-gray-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 hover:bg-gray-100`,e),...n,children:[(0,N.jsx)(`span`,{className:`absolute right-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,N.jsx)(Ye,{children:(0,N.jsx)(Be,{className:`h-4 w-4`})})}),(0,N.jsx)(Fe,{children:t})]}));tr.displayName=Ve.displayName;var nr=P.forwardRef(({className:e,...t},n)=>(0,N.jsx)(Me,{ref:n,className:F(`-mx-1 my-1 h-px bg-gray-100`,e),...t}));nr.displayName=Me.displayName;var rr=At,ir=wt,ar=Et,or=P.forwardRef(({className:e,sideOffset:t=4,...n},r)=>(0,N.jsx)(Ot,{children:(0,N.jsx)(Ct,{ref:r,sideOffset:t,className:F(`z-[var(--z-tooltip)] overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...n})}));or.displayName=Ct.displayName;var sr={Popover:Un,PopoverAnchor:Gn,PopoverContent:Kn,PopoverTrigger:Wn,Input:Hn,Select:qn,SelectContent:$n,SelectGroup:Jn,SelectItem:tr,SelectLabel:er,SelectSeparator:nr,SelectTrigger:Xn,SelectValue:Yn,Tooltip:ir,TooltipContent:or,TooltipProvider:rr,TooltipTrigger:ar},cr=680,lr=.82,ur=560;function dr(e){let{Popover:t,PopoverAnchor:n,PopoverContent:r}=sr,{elementRef:i,width:a}=Vn(),o=(0,P.useRef)(null),{isOpen:s,isLoading:c,items:l,activeIndex:u,activeItem:d,texts:f,onSelectItem:p,onOpenChange:m,onSetActiveIndex:h}=e,g=(0,P.useMemo)(()=>{if(a)return Math.min(a>ur?a*lr:a,cr)},[a]);return Bn({containerRef:o,activeIndex:u,itemCount:l.length,isEnabled:s&&!c,getItemSelector:e=>`[data-slash-index="${e}"]`}),(0,N.jsxs)(t,{open:s,onOpenChange:m,children:[(0,N.jsx)(n,{asChild:!0,children:(0,N.jsx)(`div`,{ref:i,className:`pointer-events-none absolute bottom-full left-3 right-3 h-0`})}),(0,N.jsx)(r,{side:`top`,align:`start`,sideOffset:10,className:`z-[70] max-w-[calc(100vw-1.5rem)] overflow-hidden rounded-2xl border border-gray-200 bg-white/95 p-0 shadow-2xl backdrop-blur-md`,onOpenAutoFocus:e=>e.preventDefault(),style:g?{width:`${g}px`}:void 0,children:(0,N.jsxs)(`div`,{className:`grid min-h-[240px] grid-cols-[minmax(220px,300px)_minmax(0,1fr)]`,children:[(0,N.jsx)(`div`,{ref:o,role:`listbox`,"aria-label":f.slashSectionLabel,className:`custom-scrollbar max-h-[320px] overflow-y-auto border-r border-gray-200 p-2.5`,children:c?(0,N.jsx)(`div`,{className:`p-2 text-xs text-gray-500`,children:f.slashLoadingLabel}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`div`,{className:`mb-2 px-2 text-[11px] font-semibold uppercase tracking-wide text-gray-500`,children:f.slashSectionLabel}),l.length===0?(0,N.jsx)(`div`,{className:`px-2 text-xs text-gray-400`,children:f.slashEmptyLabel}):(0,N.jsx)(`div`,{className:`space-y-1`,children:l.map((e,t)=>{let n=t===u;return(0,N.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":n,"data-slash-index":t,onMouseEnter:()=>h(t),onClick:()=>p(e),className:`flex w-full items-start gap-2 rounded-lg px-2 py-1.5 text-left transition ${n?`bg-gray-100 text-gray-900`:`text-gray-700 hover:bg-gray-50`}`,children:[(0,N.jsx)(`span`,{className:`truncate text-xs font-semibold`,children:e.title}),(0,N.jsx)(`span`,{className:`truncate text-xs text-gray-500`,children:e.subtitle})]},e.key)})})]})}),(0,N.jsx)(`div`,{className:`min-w-0 p-2.5`,children:d?(0,N.jsxs)(`div`,{className:`space-y-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`span`,{className:`inline-flex rounded-full bg-primary/10 px-2 py-0.5 text-[11px] font-semibold text-primary`,children:d.subtitle}),(0,N.jsx)(`span`,{className:`text-sm font-semibold text-gray-900`,children:d.title})]}),(0,N.jsx)(`p`,{className:`text-xs leading-5 text-gray-600`,children:d.description}),(0,N.jsx)(`div`,{className:`space-y-1`,children:d.detailLines.map(e=>(0,N.jsx)(`div`,{className:`min-w-0 break-all rounded-md bg-gray-50 px-2 py-1 text-[11px] leading-5 text-gray-600`,children:e},e))}),(0,N.jsx)(`div`,{className:`pt-1 text-[11px] text-gray-500`,children:f.slashSkillHintLabel})]}):(0,N.jsx)(`div`,{className:`text-xs text-gray-500`,children:f.slashHintLabel})})]})})]})}var fr=D(`inline-flex items-center justify-center whitespace-nowrap rounded-full text-sm font-medium ring-offset-background transition-all duration-fast focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary-600 active:bg-primary-700 shadow-sm`,destructive:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,outline:`border border-gray-200 bg-white hover:bg-gray-50 hover:text-gray-800 text-gray-600`,secondary:`bg-gray-100 text-gray-700 hover:bg-gray-200/80`,ghost:`hover:bg-gray-100/80 hover:text-gray-800`,link:`text-primary underline-offset-4 hover:underline`,primary:`bg-primary text-primary-foreground hover:bg-primary-600 active:bg-primary-700 shadow-sm`,subtle:`bg-gray-100 text-gray-600 hover:bg-gray-200/80`,"primary-outline":`border border-primary/30 text-primary hover:bg-primary hover:text-primary-foreground`},size:{default:`h-9 px-4 py-2`,sm:`h-8 px-3 text-xs`,lg:`h-11 px-5 text-[14px]`,xl:`h-12 px-6 text-[15px]`,icon:`h-9 w-9`}},defaultVariants:{variant:`default`,size:`default`}}),pr=P.forwardRef(({className:e,variant:t,size:n,...r},i)=>(0,N.jsx)(`button`,{className:F(fr({variant:t,size:n,className:e})),ref:i,...r}));pr.displayName=`ChatButton`;var mr=120;function hr(e){let t=e.replace(/\s+/g,` `).trim();return t.length<=mr?t:`${t.slice(0,mr-1)}…`}function gr(){return(0,N.jsx)(`span`,{"aria-hidden":`true`,"data-testid":`chat-stop-icon`,className:`block h-3 w-3 rounded-[2px] bg-gray-700 shadow-[inset_0_0_0_1px_rgba(17,24,39,0.06)]`})}function _r({sendError:e,sendErrorDetailsLabel:t,isSending:n,canStopGeneration:r,sendDisabled:i,stopDisabled:a,stopHint:o,sendButtonLabel:s,stopButtonLabel:c,onSend:l,onStop:u}){let{Popover:d,PopoverContent:f,PopoverTrigger:p,Tooltip:m,TooltipContent:h,TooltipProvider:g,TooltipTrigger:_}=sr,v=e?.trim()??``,y=v?hr(v):``,b=t?.trim()||`Details`;return(0,N.jsxs)(`div`,{className:`flex shrink-0 flex-col items-end gap-1`,children:[v?(0,N.jsxs)(`div`,{className:`flex max-w-[420px] items-start justify-end gap-2 text-right`,children:[(0,N.jsx)(`div`,{className:`min-w-0 flex-1 text-[11px] text-red-600`,children:(0,N.jsx)(`span`,{className:`block truncate`,title:v,children:y})}),(0,N.jsxs)(d,{children:[(0,N.jsx)(p,{asChild:!0,children:(0,N.jsx)(`button`,{type:`button`,className:`shrink-0 rounded-full border border-red-200/80 bg-red-50 px-2 py-0.5 text-[10px] font-semibold text-red-700 transition-colors hover:bg-red-100`,children:b})}),(0,N.jsxs)(f,{align:`end`,className:`w-[min(32rem,calc(100vw-1.5rem))] border-red-100/80 p-0`,children:[(0,N.jsx)(`div`,{className:`border-b border-red-100 bg-red-50/80 px-4 py-2 text-xs font-semibold text-red-700`,children:b}),(0,N.jsx)(`pre`,{className:`max-h-80 overflow-auto whitespace-pre-wrap break-words px-4 py-3 text-xs leading-relaxed text-red-700`,children:v})]})]})]}):null,(0,N.jsx)(`div`,{className:`flex items-center gap-2`,children:n?r?(0,N.jsx)(pr,{size:`icon`,variant:`outline`,className:`h-8 w-8 rounded-full`,"aria-label":c,onClick:()=>void u(),disabled:a,children:(0,N.jsx)(gr,{})}):(0,N.jsx)(g,{children:(0,N.jsxs)(m,{children:[(0,N.jsx)(_,{asChild:!0,children:(0,N.jsx)(`span`,{children:(0,N.jsx)(pr,{size:`icon`,variant:`outline`,className:`h-8 w-8 rounded-full`,"aria-label":c,disabled:!0,children:(0,N.jsx)(gr,{})})})}),(0,N.jsx)(h,{side:`top`,children:(0,N.jsx)(`p`,{className:`text-xs`,children:o})})]})}):(0,N.jsx)(pr,{size:`icon`,className:`h-8 w-8 rounded-full`,"aria-label":s,onClick:()=>void l(),disabled:i,children:(0,N.jsx)(Pt,{className:`h-5 w-5`})})})]})}function vr(e,t){let n=t.trim().toLowerCase();return n?e.filter(e=>[e.label,e.key,e.description].filter(e=>typeof e==`string`&&e.trim().length>0).join(` `).toLowerCase().includes(n)):e}function yr(e){let{Input:t,Popover:n,PopoverContent:r,PopoverTrigger:i}=sr,{picker:a}=e,o=(0,P.useRef)(null),s=(0,P.useId)(),[c,l]=(0,P.useState)(``),[u,d]=(0,P.useState)(0),f=(0,P.useMemo)(()=>new Set(a.selectedKeys),[a.selectedKeys]),p=a.selectedKeys.length,m=c.trim().length>0,h=(0,P.useMemo)(()=>{if(m)return null;let e=a.groups?.filter(e=>e.options.length>0)??[];return e.length>0?e:null},[m,a.groups]),g=(0,P.useMemo)(()=>h?h.flatMap(e=>e.options):vr(a.options,c),[h,a.options,c]);(0,P.useEffect)(()=>{d(0)},[c]),(0,P.useEffect)(()=>{d(e=>g.length===0?0:Math.min(e,g.length-1))},[g.length]),Bn({containerRef:o,activeIndex:u,itemCount:g.length,isEnabled:g.length>0,getItemSelector:e=>`[data-skill-index="${e}"]`});let _=e=>{if(f.has(e)){a.onSelectedKeysChange(a.selectedKeys.filter(t=>t!==e));return}a.onSelectedKeysChange([...a.selectedKeys,e])},v=e=>{if(g.length!==0){if(e.key===`ArrowDown`){e.preventDefault(),d(e=>Math.min(e+1,g.length-1));return}if(e.key===`ArrowUp`){e.preventDefault(),d(e=>Math.max(e-1,0));return}if(e.key===`Enter`){e.preventDefault();let t=g[u];t&&_(t.key)}}};return(0,N.jsxs)(n,{children:[(0,N.jsx)(i,{asChild:!0,children:(0,N.jsxs)(`button`,{type:`button`,"aria-haspopup":`listbox`,"aria-label":a.title,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg px-0 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-100 hover:text-gray-900 sm:w-auto sm:gap-1.5 sm:px-3`,children:[(0,N.jsx)(Te,{className:`h-4 w-4`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:a.title}),p>0?(0,N.jsx)(`span`,{className:`absolute -right-1 -top-1 flex h-[18px] min-w-[18px] items-center justify-center rounded-full bg-primary px-1 text-[10px] font-semibold leading-none text-white shadow-sm sm:static sm:ml-0.5 sm:bg-primary/10 sm:text-primary sm:shadow-none`,children:p}):null]})}),(0,N.jsxs)(r,{side:`top`,align:`start`,className:`w-[360px] p-0`,children:[(0,N.jsxs)(`div`,{className:`space-y-2 border-b border-gray-100 px-4 py-3`,children:[(0,N.jsx)(`div`,{className:`text-sm font-semibold text-gray-900`,children:a.title}),(0,N.jsxs)(`div`,{className:`relative`,children:[(0,N.jsx)(Oe,{className:`pointer-events-none absolute left-3 top-2.5 h-3.5 w-3.5 text-gray-400`}),(0,N.jsx)(t,{value:c,onChange:e=>l(e.target.value),onKeyDown:v,placeholder:a.searchPlaceholder,role:`combobox`,"aria-controls":s,"aria-expanded":`true`,"aria-autocomplete":`list`,"aria-activedescendant":g[u]?`${s}-option-${u}`:void 0,className:`h-8 rounded-lg pl-8 text-xs`})]})]}),(0,N.jsx)(`div`,{ref:o,id:s,role:`listbox`,"aria-multiselectable":`true`,className:`custom-scrollbar max-h-[320px] overflow-y-auto`,children:a.isLoading?(0,N.jsx)(`div`,{className:`p-4 text-xs text-gray-500`,children:a.loadingLabel}):g.length===0?(0,N.jsx)(`div`,{className:`p-4 text-center text-xs text-gray-500`,children:a.emptyLabel}):(0,N.jsx)(`div`,{className:`py-1`,children:(()=>{let e=h??[{key:`all-skills`,options:g}],t=0;return e.map(e=>(0,N.jsxs)(`div`,{children:[e.label?(0,N.jsx)(`div`,{className:`px-4 pb-1 pt-2 text-[11px] font-semibold uppercase tracking-wide text-gray-500`,children:e.label}):null,e.options.map(e=>{let n=t;t+=1;let r=f.has(e.key),i=n===u;return(0,N.jsxs)(`button`,{type:`button`,id:`${s}-option-${n}`,role:`option`,"aria-selected":r,"data-skill-index":n,onClick:()=>_(e.key),onMouseEnter:()=>d(n),className:`flex w-full items-center gap-3 px-4 py-2.5 text-left transition-colors ${i?`bg-gray-50`:`hover:bg-gray-50`}`,children:[(0,N.jsx)(`div`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-gray-100 text-gray-500`,children:(0,N.jsx)(cn,{className:`h-4 w-4`})}),(0,N.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,N.jsx)(`span`,{className:`truncate text-sm text-gray-900`,children:e.label}),e.badgeLabel?(0,N.jsx)(`span`,{className:`shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:e.badgeLabel}):null]}),(0,N.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-gray-500`,children:e.description||e.key})]}),(0,N.jsx)(`div`,{className:`ml-3 shrink-0`,children:(0,N.jsx)(`span`,{className:r?`inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-white`:`inline-flex h-5 w-5 items-center justify-center rounded-full border border-gray-300 bg-white`,children:r?(0,N.jsx)(Be,{className:`h-3 w-3`}):null})})]},e.key)})]},e.key))})()})}),a.manageHref&&a.manageLabel?(0,N.jsx)(`div`,{className:`border-t border-gray-100 px-4 py-2.5`,children:(0,N.jsxs)(`a`,{href:a.manageHref,className:`inline-flex items-center gap-1.5 text-xs font-medium text-primary transition-colors hover:text-primary/80`,children:[a.manageLabel,(0,N.jsx)(Qe,{className:`h-3 w-3`})]})}):null]})]})}function br({icon:e}){return e===`sparkles`?(0,N.jsx)(ot,{className:`h-3.5 w-3.5 shrink-0 text-primary`}):e===`brain`?(0,N.jsx)(Ft,{className:`h-3.5 w-3.5 shrink-0 text-gray-500`}):null}function xr({icon:e}){return e===`paperclip`?(0,N.jsx)(on,{className:`h-4 w-4`}):(0,N.jsx)(br,{icon:e})}var Sr={model:`min-w-0 flex-1 sm:min-w-[220px] sm:flex-none`,"session-type":`shrink-0`,thinking:`shrink-0`},Cr={model:`w-[min(18rem,calc(100vw-1rem))] sm:w-[320px]`,"session-type":`w-[220px]`,thinking:`w-[180px]`};function wr(e){return e.key===`model`&&e.selectedLabel&&e.selectedLabel.split(`/`).slice(1).join(`/`).trim()||e.selectedLabel}function Tr({item:e}){let{Select:t,SelectContent:n,SelectGroup:r,SelectItem:i,SelectLabel:a,SelectSeparator:o,SelectTrigger:s,SelectValue:c}=sr,l=e.groups?.filter(e=>e.options.length>0)??(e.options.length>0?[{key:`${e.key}-default`,options:e.options}]:[]),u=l.some(e=>e.options.length>0),d=wr(e);return(0,N.jsxs)(t,{value:e.value,onValueChange:e.onValueChange,disabled:e.disabled,children:[(0,N.jsx)(s,{className:`h-8 w-auto rounded-lg border-0 bg-transparent px-2 text-xs font-medium text-gray-600 shadow-none hover:bg-gray-100 focus:ring-0 sm:px-3 ${Sr[e.key]??``}`,children:e.selectedLabel?(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-left`,children:[(0,N.jsx)(br,{icon:e.icon}),(0,N.jsx)(`span`,{className:`truncate text-xs font-semibold text-gray-700 sm:hidden`,children:d}),(0,N.jsx)(`span`,{className:`hidden truncate text-xs font-semibold text-gray-700 sm:inline`,children:e.selectedLabel})]}):e.loading?(0,N.jsx)(`div`,{className:`h-3 w-24 animate-pulse rounded bg-gray-200`}):(0,N.jsx)(c,{placeholder:e.placeholder})}),(0,N.jsxs)(n,{className:Cr[e.key]??``,children:[u?null:e.loading?(0,N.jsxs)(`div`,{className:`space-y-2 px-3 py-2`,children:[(0,N.jsx)(`div`,{className:`h-3 w-36 animate-pulse rounded bg-gray-200`}),(0,N.jsx)(`div`,{className:`h-3 w-28 animate-pulse rounded bg-gray-200`}),(0,N.jsx)(`div`,{className:`h-3 w-32 animate-pulse rounded bg-gray-200`})]}):e.emptyLabel?(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-gray-500`,children:e.emptyLabel}):null,l.map((e,t)=>(0,N.jsxs)(`div`,{children:[t>0?(0,N.jsx)(o,{}):null,(0,N.jsxs)(r,{children:[e.label?(0,N.jsx)(a,{children:e.label}):null,e.options.map(e=>(0,N.jsx)(i,{value:e.value,className:`py-2`,children:e.description?(0,N.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,N.jsx)(`span`,{className:`truncate text-xs font-semibold text-gray-800`,children:e.label}),(0,N.jsx)(`span`,{className:`truncate text-[11px] text-gray-500`,children:e.description})]}):(0,N.jsx)(`span`,{className:`truncate text-xs font-semibold text-gray-800`,children:e.label})},e.value))]})]},e.key))]})]})}function Er({actions:e,accessories:t,selects:n,skillPicker:r}){let{Tooltip:i,TooltipContent:a,TooltipProvider:o,TooltipTrigger:s}=sr;return(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 pb-3`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 overflow-hidden`,children:[r?(0,N.jsx)(yr,{picker:r}):null,n.map(e=>(0,N.jsx)(Tr,{item:e},e.key)),t?.map(e=>{let t=(0,N.jsxs)(`button`,{type:`button`,className:`inline-flex items-center rounded-lg py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-100 hover:text-gray-900 disabled:cursor-not-allowed disabled:text-gray-400 ${e.iconOnly?`h-8 w-8 justify-center px-0`:`gap-1.5 px-3`}`,onClick:e.onClick,disabled:e.disabled,"aria-label":e.label,children:[(0,N.jsx)(xr,{icon:e.icon}),e.iconOnly?null:(0,N.jsx)(`span`,{children:e.label})]});return e.tooltip?(0,N.jsx)(o,{children:(0,N.jsxs)(i,{children:[(0,N.jsx)(s,{asChild:!0,children:e.disabled?(0,N.jsx)(`span`,{className:`inline-flex`,children:t}):t}),(0,N.jsx)(a,{side:`top`,children:(0,N.jsx)(`p`,{className:`text-xs`,children:e.tooltip})})]})},e.key):(0,N.jsx)(`div`,{children:t},e.key)})]}),(0,N.jsx)(_r,{...e})]})}var Dr=(0,P.createContext)(null);function Or(e,t){let n=null;return e!=null&&(n=e[1]),{getTheme:function(){return t??(n==null?null:n.getTheme())}}}function kr(){let e=(0,P.useContext)(Dr);return e??function(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(8),e}function I(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function Ar(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);n.search=r.toString(),console.warn(`Minified Lexical warning #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}var jr=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0,Mr=jr&&`documentMode`in document?document.documentMode:null,Nr=jr&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),Pr=jr&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),Fr=!(!jr||!(`InputEvent`in window)||Mr)&&`getTargetRanges`in new window.InputEvent(`input`),Ir=jr&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,Lr=jr&&/Android/.test(navigator.userAgent),Rr=jr&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!Lr,zr=jr&&/^(?=.*Chrome).*/i.test(navigator.userAgent),Br=jr&&Lr&&zr,Vr=jr&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&Nr&&!zr,Hr=0,Ur=1,Wr=2,Gr=1,Kr=2,qr=3,Jr=4,Yr=5,Xr=6,Zr=Rr||Ir||Vr?`\xA0`:``,Qr=`
|
|
1
|
+
import{_ as e,a as t,d as n,f as r,g as i,h as a,i as o,m as s,n as c,p as l,t as u,u as d}from"./i18n-CM4y8Mw9.js";import{At as f,Ft as p,Gt as m,H as h,It as g,Mt as _,Ot as v,Pt as y,_t as b,at as x,b as S,bt as C,g as w,h as T,it as E,jt as D,kt as O,m as ee,mt as k,n as te,ot as A,p as ne,r as j,rt as re,st as ie,y as ae,yt as oe,zt as se}from"./api-BurjmW4A.js";import{a as ce,i as le,n as ue,o as de,r as fe,t as pe}from"./dialog-CTCX7oLf.js";import{t as M}from"./createLucideIcon-PPrXCGK8.js";import{b as me,c as he,d as ge,f as _e,g as ve,h as ye,l as be,m as xe,n as Se,s as Ce,u as we,v as Te,y as Ee}from"./theme-provider-WTWq_jYq.js";import{n as De,t as Oe}from"./search-CQUdr7j_.js";import{t as ke}from"./book-open-CVEuA0y5.js";import{D as Ae,O as je,_ as Me,b as Ne,c as Pe,d as Fe,f as Ie,g as Le,h as Re,i as ze,k as Be,l as Ve,m as He,n as Ue,o as We,p as Ge,r as Ke,s as qe,t as Je,u as Ye,v as Xe,y as Ze}from"./select-DVUtSFHZ.js";import{t as Qe}from"./external-link-BNtqJE01.js";import{t as $e}from"./folder-QyJHVUNz.js";import{n as et,t as tt}from"./logos-CqXnaJIm.js";import{t as nt}from"./loader-circle-R23uEPkM.js";import{t as rt}from"./plus-D14303DH.js";import{t as it}from"./refresh-ccw-B-dhb3yS.js";import{t as at}from"./settings-DgtZZlnF.js";import{t as ot}from"./sparkles-DNSCyDhL.js";import{t as st}from"./trash-2-CqciSCsg.js";import{t as ct}from"./x-tYcSDsrY.js";import{i as lt}from"./doc-browser-context-C-WPOji4.js";import{n as ut}from"./doc-browser-C02neCIE.js";import{n as dt,t as ft}from"./use-viewport-layout-CaALCA51.js";import{m as pt}from"./use-config-CyvhbRhf.js";import{a as mt,c as ht,i as gt,n as _t,o as vt,r as yt,s as bt,t as xt}from"./popover-AmJkxio3.js";import{t as St}from"./logo-badge-CKAxvQFc.js";import{a as Ct,c as wt,i as Tt,l as Et,n as Dt,o as Ot,r as kt,s as At,t as jt}from"./tooltip-BkZCQcKw.js";import{t as Mt}from"./skeleton-BCPi52jT.js";var Nt=M(`ArrowUpRight`,[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]),Pt=M(`ArrowUp`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),Ft=M(`Brain`,[[`path`,{d:`M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z`,key:`l5xja`}],[`path`,{d:`M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z`,key:`ep3f8r`}],[`path`,{d:`M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4`,key:`1p4c4q`}],[`path`,{d:`M17.599 6.5a3 3 0 0 0 .399-1.375`,key:`tmeiqw`}],[`path`,{d:`M6.003 5.125A3 3 0 0 0 6.401 6.5`,key:`105sqy`}],[`path`,{d:`M3.477 10.896a4 4 0 0 1 .585-.396`,key:`ql3yin`}],[`path`,{d:`M19.938 10.5a4 4 0 0 1 .585.396`,key:`1qfode`}],[`path`,{d:`M6 18a4 4 0 0 1-1.967-.516`,key:`2e4loj`}],[`path`,{d:`M19.967 17.484A4 4 0 0 1 18 18`,key:`159ez6`}]]),It=M(`ChevronRight`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),Lt=M(`CodeXml`,[[`path`,{d:`m18 16 4-4-4-4`,key:`1inbqp`}],[`path`,{d:`m6 8-4 4 4 4`,key:`15zrgr`}],[`path`,{d:`m14.5 4-5 16`,key:`e7oirm`}]]),Rt=M(`Copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),zt=M(`Ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),Bt=M(`FileArchive`,[[`path`,{d:`M10 12v-1`,key:`v7bkov`}],[`path`,{d:`M10 18v-2`,key:`1cjy8d`}],[`path`,{d:`M10 7V6`,key:`dljcrl`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M15.5 22H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v16a2 2 0 0 0 .274 1.01`,key:`gkbcor`}],[`circle`,{cx:`10`,cy:`20`,r:`2`,key:`1xzdoj`}]]),Vt=M(`FileAudio2`,[[`path`,{d:`M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v2`,key:`17k7jt`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`circle`,{cx:`3`,cy:`17`,r:`1`,key:`vo6nti`}],[`path`,{d:`M2 17v-3a4 4 0 0 1 8 0v3`,key:`1ggdre`}],[`circle`,{cx:`9`,cy:`17`,r:`1`,key:`bc1fq4`}]]),Ht=M(`FileCode2`,[[`path`,{d:`M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4`,key:`1pf5j1`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`m5 12-3 3 3 3`,key:`oke12k`}],[`path`,{d:`m9 18 3-3-3-3`,key:`112psh`}]]),Ut=M(`FileImage`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`circle`,{cx:`10`,cy:`12`,r:`2`,key:`737tya`}],[`path`,{d:`m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22`,key:`wt3hpn`}]]),Wt=M(`FileJson2`,[[`path`,{d:`M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4`,key:`1pf5j1`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M4 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1`,key:`fq0c9t`}],[`path`,{d:`M8 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1`,key:`4gibmv`}]]),Gt=M(`FileSpreadsheet`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M8 13h2`,key:`yr2amv`}],[`path`,{d:`M14 13h2`,key:`un5t4a`}],[`path`,{d:`M8 17h2`,key:`2yhykz`}],[`path`,{d:`M14 17h2`,key:`10kma7`}]]),Kt=M(`FileText`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),qt=M(`FileVideo2`,[[`path`,{d:`M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4`,key:`1pf5j1`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`rect`,{width:`8`,height:`6`,x:`2`,y:`12`,rx:`1`,key:`1a6c1e`}],[`path`,{d:`m10 15.5 4 2.5v-6l-4 2.5`,key:`t7cp39`}]]),Jt=M(`File`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}]]),Yt=M(`FolderGit2`,[[`path`,{d:`M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v5`,key:`1w6njk`}],[`circle`,{cx:`13`,cy:`12`,r:`2`,key:`1j92g6`}],[`path`,{d:`M18 19c-2.8 0-5-2.2-5-5v8`,key:`pkpw2h`}],[`circle`,{cx:`20`,cy:`19`,r:`2`,key:`1obnsp`}]]),Xt=M(`FolderOpen`,[[`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2`,key:`usdka0`}]]),Zt=M(`FolderTree`,[[`path`,{d:`M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`hod4my`}],[`path`,{d:`M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`w4yl2u`}],[`path`,{d:`M3 5a2 2 0 0 0 2 2h3`,key:`f2jnh7`}],[`path`,{d:`M3 3v13a2 2 0 0 0 2 2h3`,key:`k8epm1`}]]),Qt=M(`FolderUp`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}],[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`m9 13 3-3 3 3`,key:`1pxg3c`}]]),$t=M(`FolderX`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}],[`path`,{d:`m9.5 10.5 5 5`,key:`ra9qjz`}],[`path`,{d:`m14.5 10.5-5 5`,key:`l2rkpq`}]]),en=M(`GitBranch`,[[`line`,{x1:`6`,x2:`6`,y1:`3`,y2:`15`,key:`17qcm7`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M18 9a9 9 0 0 1-9 9`,key:`n2h4wq`}]]),tn=M(`HeartPulse`,[[`path`,{d:`M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z`,key:`c3ymky`}],[`path`,{d:`M3.22 12H9.5l.5-1 2 4.5 2-7 1.5 3.5h5.27`,key:`1uw2ng`}]]),nn=M(`House`,[[`path`,{d:`M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8`,key:`5wwlr5`}],[`path`,{d:`M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`1d0kgt`}]]),rn=M(`MessageSquareText`,[[`path`,{d:`M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z`,key:`1lielz`}],[`path`,{d:`M13 8H7`,key:`14i4kc`}],[`path`,{d:`M17 12H7`,key:`16if0g`}]]),an=M(`Minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),on=M(`Paperclip`,[[`path`,{d:`m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48`,key:`1u3ebp`}]]),sn=M(`Pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),cn=M(`Puzzle`,[[`path`,{d:`M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z`,key:`w46dr5`}]]),ln=M(`Terminal`,[[`polyline`,{points:`4 17 10 11 4 5`,key:`akl6gq`}],[`line`,{x1:`12`,x2:`20`,y1:`19`,y2:`19`,key:`q2wloq`}]]),un=M(`TriangleAlert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),dn=M(`User`,[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]),N=l();function fn({isProjectFirstView:e,onSelectMode:t}){return(0,N.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,children:[(0,N.jsx)(`button`,{type:`button`,"aria-pressed":!e,onClick:()=>t(`time-first`),className:d(`transition-colors`,e?`text-gray-400 hover:text-gray-600`:`font-medium text-gray-600`),children:o(`chatSidebarViewTime`)}),(0,N.jsx)(`span`,{className:`text-gray-300`,children:`/`}),(0,N.jsx)(`button`,{type:`button`,"aria-pressed":e,onClick:()=>t(`project-first`),className:d(`transition-colors`,e?`font-medium text-gray-600`:`text-gray-400 hover:text-gray-600`),children:o(`chatSidebarViewProject`)})]})}var pn={wx:`weixin`,lark:`feishu`},mn={heartbeat:{icon:`heartbeat`},cron:{icon:`cron`}},hn={codex:`chatSessionTypeCodex`,claude:`chatSessionTypeClaude`};function gn(e){return e?.trim().toLowerCase()??``}function _n(e){return e.split(/[-_]+/g).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function vn(e,t){let n=gn(e);if(!n||n===`native`)return null;let r=t.find(e=>gn(e.value)===n);return r?.label.trim()?r.label.trim():_n(n)}function yn(e,t){let n=gn(e);return!n||n===`native`?null:t.find(e=>gn(e.value)===n)??null}function bn(e){let t=gn(e);if(!t)return null;let n=pn[t]??t;return tt(n)?n:null}function xn(e,t){let n=bn(e.channel??``);if(n)return{icon:{kind:`channel-logo`,channel:n},label:null};let r=mn[gn(e.type)];if(r)return{icon:{kind:`symbol`,icon:r.icon},label:null};let i=gn(e.sessionType),a=yn(i,t);if(a?.icon?.src?.trim())return{icon:{kind:`runtime-image`,src:a.icon.src,alt:a.icon.alt??null,name:a.label},label:null};let s=hn[i];return s?{icon:null,label:o(s)}:{icon:null,label:a?.label?.trim()||vn(e.sessionType,t)}}var Sn=`app://`;function Cn(e){let t=e.trim().replace(/^\/+/,``);if(!t)return null;let n=t.split(`/`);return n.some(e=>e.trim().length===0||e===`.`||e===`..`)?null:n.join(`/`)}function wn(e){let t=e.trim();if(!t)return null;if(!t.startsWith(Sn))return t;let n=Cn(t.slice(6));return n?`/${n}`:null}function Tn({icon:e,className:t}){if(e.kind===`channel-logo`)return(0,N.jsx)(En,{channel:e.channel,className:t});if(e.kind===`runtime-image`){let n=wn(e.src);return(0,N.jsx)(St,{name:e.name?.trim()||e.alt?.trim()||`runtime`,src:n??void 0,className:d(`h-[1.125rem] w-[1.125rem]`,t),imgClassName:`h-full w-full object-contain`,fallback:(0,N.jsx)(Ee,{className:d(`h-3 w-3 text-gray-500`,t)})})}return e.icon===`heartbeat`?(0,N.jsx)(tn,{className:d(`h-3.5 w-3.5`,t)}):(0,N.jsx)(me,{className:d(`h-3.5 w-3.5`,t)})}function En({channel:e,className:t}){return(0,N.jsx)(St,{name:e,src:tt(e),className:d(`h-[1.125rem] w-[1.125rem]`,t),imgClassName:`h-full w-full object-contain`,fallback:(0,N.jsx)(Ee,{className:`h-3 w-3 text-gray-500`})})}function Dn(e){let{option:t,onSelect:n}=e,r=t.ready===!1?t.reasonMessage?.trim()||o(`statusSetup`):null;return(0,N.jsx)(`button`,{type:`button`,onClick:n,className:`w-full rounded-2xl px-3 py-2.5 text-left transition-colors hover:bg-gray-50`,children:(0,N.jsx)(`div`,{className:`flex items-start gap-3`,children:(0,N.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-2.5`,children:[t.icon?.src?(0,N.jsx)(`span`,{className:`inline-flex h-5 w-5 shrink-0 items-center justify-center pt-0.5`,children:(0,N.jsx)(Tn,{icon:{kind:`runtime-image`,src:t.icon.src,alt:t.icon.alt??null,name:t.label}})}):(0,N.jsx)(`span`,{className:`inline-flex h-5 w-5 shrink-0 items-center justify-center pt-0.5 text-gray-400`,children:(0,N.jsx)(Ee,{className:`h-4 w-4`})}),(0,N.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,N.jsx)(`div`,{className:`truncate text-[13px] font-semibold text-gray-900`,children:t.label}),(0,N.jsxs)(`span`,{className:d(`inline-flex shrink-0 items-center gap-1.5 text-[11px] font-medium`,t.ready===!1?`text-amber-700`:`text-emerald-600`),children:[(0,N.jsx)(`span`,{className:d(`h-1.5 w-1.5 rounded-full`,t.ready===!1?`bg-amber-500`:`bg-emerald-500`)}),t.ready===!1?o(`statusSetup`):o(`statusReady`)]})]}),r?(0,N.jsx)(`div`,{className:`mt-1 pr-4 text-[11px] leading-4 text-gray-500`,children:r}):null]})]})})})}var P=e(s(),1);function On(e,t){return t.some(t=>t.value===e)?e:t[0]?.value??e}function kn(e){let{groups:t,defaultSessionType:n,sessionTypeOptions:r,renderSessionItem:i,onCreateSession:a}=e,[s,c]=(0,P.useState)(null),l=(0,P.useMemo)(()=>On(n,r),[n,r]),u=r.length>1;return(0,N.jsx)(`div`,{className:`space-y-3`,children:t.map(e=>{let t=`${o(`chatSidebarNewTask`)} · ${e.projectName}`;return(0,N.jsxs)(`div`,{children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-2 py-0.5`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,N.jsx)(`div`,{className:`truncate text-[11px] font-medium uppercase tracking-wider text-gray-500`,title:e.projectRoot,children:e.projectName}),(0,N.jsx)(`span`,{className:`shrink-0 text-[10px] text-gray-400`,children:e.items.length})]}),u?(0,N.jsxs)(xt,{open:s===e.projectRoot,onOpenChange:t=>{c(t?e.projectRoot:null)},children:[(0,N.jsx)(yt,{asChild:!0,children:(0,N.jsx)(f,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0 rounded-lg text-gray-400 hover:bg-white hover:text-gray-900`,"aria-label":t,title:t,children:(0,N.jsx)(rt,{className:`h-3.5 w-3.5`})})}),(0,N.jsxs)(_t,{align:`end`,className:`w-56 rounded-2xl border border-gray-200/80 bg-white p-1.5 shadow-[0_24px_60px_-28px_rgba(15,23,42,0.38)]`,children:[(0,N.jsx)(`div`,{className:`px-3 pb-1 pt-2 text-[10px] font-semibold uppercase tracking-[0.18em] text-gray-400`,children:o(`chatSessionTypeLabel`)}),(0,N.jsx)(`div`,{className:`space-y-1`,children:r.map(t=>(0,N.jsx)(Dn,{option:t,onSelect:()=>{a(t.value,e.projectRoot),c(null)}},`${e.projectRoot}:${t.value}`))})]})]}):(0,N.jsx)(f,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0 rounded-lg text-gray-400 hover:bg-white hover:text-gray-900`,onClick:()=>a(l,e.projectRoot),"aria-label":t,title:t,children:(0,N.jsx)(rt,{className:`h-3.5 w-3.5`})})]}),(0,N.jsx)(`div`,{className:`space-y-0.5 pl-2`,children:e.items.map(i)})]},e.projectRoot)})})}var An=[[`bg-amber-100`,`text-amber-700`],[`bg-emerald-100`,`text-emerald-700`],[`bg-blue-100`,`text-blue-700`],[`bg-rose-100`,`text-rose-700`],[`bg-cyan-100`,`text-cyan-700`],[`bg-violet-100`,`text-violet-700`]];function jn(e){let t=0;for(let n=0;n<e.length;n+=1)t=(t<<5)-t+e.charCodeAt(n),t|=0;return Math.abs(t)}function Mn({agentId:e,displayName:t,avatarUrl:n,className:r}){let i=t?.trim()||e,[a,o]=An[jn(e)%An.length]??An[0];return n?.trim()?(0,N.jsx)(`img`,{src:n,alt:t?.trim()||e,className:d(`rounded-full object-cover`,r)}):(0,N.jsx)(`div`,{className:d(`rounded-full flex items-center justify-center font-semibold`,a,o,r),"aria-label":t?.trim()||e,children:e.trim().toLowerCase()===`main`?(0,N.jsx)(Ee,{className:`h-[55%] w-[55%]`,strokeWidth:2.4}):(i.trim()||`A`).slice(0,1).toUpperCase()})}function Nn({status:e,className:t}){let n=o(e===`running`?`sessionsRunStatusRunning`:`sessionsRunStatusQueued`);return(0,N.jsxs)(`span`,{className:d(`inline-flex h-3.5 w-3.5 items-center justify-center text-gray-400`,t),title:n,"aria-label":n,children:[(0,N.jsx)(nt,{className:`h-3 w-3 animate-spin`}),(0,N.jsx)(`span`,{className:`sr-only`,children:n})]})}function Pn({session:e,draftLabel:t,isSaving:n,onDraftLabelChange:r,onSave:i,onCancel:a}){return(0,N.jsxs)(`div`,{className:`space-y-2`,children:[(0,N.jsx)(O,{value:t,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),i()):e.key===`Escape`&&(e.preventDefault(),a())},placeholder:o(`sessionsLabelPlaceholder`),className:`h-8 rounded-lg border-gray-300 bg-white text-xs`,autoFocus:!0,disabled:n}),(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,N.jsx)(`div`,{className:`min-w-0 text-[11px] text-gray-400 truncate`,children:e.key}),(0,N.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,N.jsx)(f,{type:`button`,size:`icon`,variant:`ghost`,className:`h-7 w-7 rounded-lg text-gray-500 hover:bg-white hover:text-gray-900`,onClick:()=>void i(),disabled:n,"aria-label":o(`save`),children:(0,N.jsx)(Be,{className:`h-3.5 w-3.5`})}),(0,N.jsx)(f,{type:`button`,size:`icon`,variant:`ghost`,className:`h-7 w-7 rounded-lg text-gray-500 hover:bg-white hover:text-gray-900`,onClick:a,disabled:n,"aria-label":o(`cancel`),children:(0,N.jsx)(ct,{className:`h-3.5 w-3.5`})})]})]})]})}function Fn({session:e,active:t,showUnreadDot:n,runStatus:r,context:i,title:a,agentId:s,agentLabel:c,agentAvatarUrl:l,childSessionCount:f=0,onSelect:p,onOpenChildSessions:m,onStartEditing:h}){return(0,N.jsxs)(`div`,{className:`group/session relative`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:p,className:`w-full text-left`,children:[(0,N.jsxs)(`div`,{className:d(`grid grid-cols-[minmax(0,1fr)_auto] items-start gap-2`,f>0&&m?`pr-14`:`pr-6`),children:[(0,N.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[s?.trim()&&s.trim().toLowerCase()!==`main`?(0,N.jsx)(Mn,{agentId:s,displayName:c,avatarUrl:l,className:`h-5 w-5 shrink-0`}):null,(0,N.jsx)(`span`,{className:`truncate font-medium`,children:a}),i.label?(0,N.jsx)(`span`,{className:d(`shrink-0 rounded-full border px-1.5 py-0.5 text-[10px] font-semibold leading-none`,t?`border-gray-300 bg-white/80 text-gray-700`:`border-gray-200 bg-gray-100 text-gray-500`),children:i.label}):null,i.icon?(0,N.jsx)(`span`,{className:`inline-flex h-[1.125rem] w-[1.125rem] shrink-0 items-center justify-center`,children:(0,N.jsx)(Tn,{icon:i.icon,className:t?`text-gray-700`:`text-gray-500`})}):null]}),r?(0,N.jsx)(`span`,{className:`inline-flex shrink-0 items-center justify-end gap-1.5 pt-0.5`,children:(0,N.jsx)(Nn,{status:r})}):null]}),(0,N.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-[11px] text-gray-400`,children:[(0,N.jsxs)(`span`,{className:`min-w-0 truncate`,children:[c?.trim()?`${c} · `:``,e.messageCount]}),n?(0,N.jsx)(`span`,{"aria-label":o(`chatSessionUnread`),className:`ml-auto h-2 w-2 shrink-0 rounded-full bg-primary`}):(0,N.jsx)(`span`,{className:`ml-auto shrink-0`,children:u(e.updatedAt)})]})]}),f>0&&m?(0,N.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),m()},className:d(`absolute right-6 top-0 inline-flex h-5 items-center gap-1 rounded-md px-1.5 text-[10px] font-medium text-gray-400 transition-all hover:bg-white hover:text-gray-900`,t?`opacity-100`:`opacity-0 group-hover/session:opacity-100 group-focus-within/session:opacity-100`),"aria-label":o(`chatSessionOpenChildSessions`),title:o(`chatSessionOpenChildSessions`),children:[(0,N.jsx)(en,{className:`h-3.5 w-3.5`}),(0,N.jsx)(`span`,{children:f})]}):null,(0,N.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),h()},className:d(`absolute right-0 top-0 inline-flex h-5 w-5 items-center justify-center rounded-md text-gray-400 transition-all hover:bg-white hover:text-gray-900`,t?`opacity-100`:`opacity-0 group-hover/session:opacity-100 group-focus-within/session:opacity-100`),"aria-label":o(`edit`),children:(0,N.jsx)(sn,{className:`h-3 w-3`})})]})}function In({session:e,active:t,showUnreadDot:n,runStatus:r,context:i,title:a,agentId:o,agentLabel:s,agentAvatarUrl:c,childSessionCount:l,isEditing:u,draftLabel:f,isSaving:p,onSelect:m,onOpenChildSessions:h,onStartEditing:g,onDraftLabelChange:_,onSave:v,onCancel:y}){return(0,N.jsx)(`div`,{className:d(`w-full rounded-xl px-3 py-2.5 text-left transition-all text-[13px]`,t?`bg-gray-200 text-gray-900 font-semibold shadow-sm`:`text-gray-700 hover:bg-gray-200/60 hover:text-gray-900`),children:u?(0,N.jsx)(Pn,{session:e,draftLabel:f,isSaving:p,onDraftLabelChange:_,onSave:v,onCancel:y}):(0,N.jsx)(Fn,{session:e,active:t,showUnreadDot:n,runStatus:r,context:i,title:a,agentId:o,agentLabel:s,agentAvatarUrl:c,onSelect:m,childSessionCount:l,onOpenChildSessions:h,onStartEditing:g})})}var Ln=[{icon:ye,titleKey:`chatWelcomeCapability1Title`,descKey:`chatWelcomeCapability1Desc`},{icon:Te,titleKey:`chatWelcomeCapability2Title`,descKey:`chatWelcomeCapability2Desc`},{icon:me,titleKey:`chatWelcomeCapability3Title`,descKey:`chatWelcomeCapability3Desc`}];function Rn({onCreateSession:e,agents:t,selectedAgentId:n,onSelectAgent:r}){let i=t.find(e=>e.id===n)??null;return(0,N.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,N.jsxs)(`div`,{className:`max-w-lg w-full text-center`,children:[(0,N.jsx)(`div`,{className:`mx-auto mb-6 h-16 w-16 rounded-2xl bg-primary/10 flex items-center justify-center`,children:(0,N.jsx)(Ee,{className:`h-8 w-8 text-primary`})}),(0,N.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 mb-2`,children:o(`chatWelcomeTitle`)}),(0,N.jsx)(`p`,{className:`text-sm text-gray-500 mb-8`,children:o(`chatWelcomeSubtitle`)}),(0,N.jsxs)(`div`,{className:`mb-6 flex items-center justify-center gap-2.5`,children:[(0,N.jsx)(`span`,{className:`text-[13px] font-medium text-gray-500`,children:o(`chatDraftAgentTitle`)}),(0,N.jsxs)(Je,{value:n,onValueChange:r,children:[(0,N.jsxs)(ze,{"aria-label":o(`chatDraftAgentTitle`),className:`h-auto w-auto gap-1 rounded-full border-0 bg-transparent px-1.5 py-1 text-gray-500 shadow-none hover:bg-white/70 hover:text-gray-800 focus:ring-0`,children:[(0,N.jsx)(`span`,{className:`sr-only`,children:o(`chatDraftAgentTitle`)}),(0,N.jsx)(`div`,{className:`flex items-center gap-1.5`,children:i?(0,N.jsx)(Mn,{agentId:i.id,displayName:i.displayName,avatarUrl:i.avatarUrl,className:`h-7 w-7 shrink-0`}):null})]}),(0,N.jsx)(Ue,{className:`rounded-xl border-gray-200/80 shadow-lg`,children:t.map(e=>(0,N.jsx)(Ke,{value:e.id,className:`rounded-lg pr-10`,children:(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,N.jsx)(Mn,{agentId:e.id,displayName:e.displayName,avatarUrl:e.avatarUrl,className:`h-5 w-5 shrink-0`}),(0,N.jsx)(`span`,{className:`truncate text-sm font-medium text-gray-700`,children:e.displayName?.trim()||e.id})]})},e.id))})]})]}),(0,N.jsx)(`div`,{className:`grid grid-cols-3 gap-3`,children:Ln.map(t=>{let n=t.icon;return(0,N.jsxs)(`button`,{onClick:e,className:`rounded-2xl border border-gray-200 bg-white p-4 text-left shadow-card hover:shadow-card-hover transition-shadow cursor-pointer`,children:[(0,N.jsx)(`div`,{className:`h-9 w-9 rounded-xl bg-primary/8 flex items-center justify-center mb-3`,children:(0,N.jsx)(n,{className:`h-4.5 w-4.5 text-primary`})}),(0,N.jsx)(`div`,{className:`text-sm font-semibold text-gray-900 mb-1`,children:o(t.titleKey)}),(0,N.jsx)(`div`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:o(t.descKey)})]},t.titleKey)})})]})})}var zn=e=>`[data-item-index="${e}"]`;function Bn(e){let{activeIndex:t,containerRef:n,getItemSelector:r,isEnabled:i,itemCount:a}=e,o=r??zn;(0,P.useEffect)(()=>{if(!i||a===0)return;let e=n.current;if(!e)return;let r=e.querySelector(o(t));typeof r?.scrollIntoView==`function`&&r.scrollIntoView({block:`nearest`,inline:`nearest`})},[t,n,o,i,a])}function Vn(){let e=(0,P.useRef)(null),[t,n]=(0,P.useState)(null);return(0,P.useEffect)(()=>{let t=e.current;if(!t||typeof ResizeObserver>`u`)return;let r=()=>{n(t.getBoundingClientRect().width)};r();let i=new ResizeObserver(()=>r());return i.observe(t),()=>i.disconnect()},[]),{elementRef:e,width:t}}function F(...e){return n(r(e))}var Hn=P.forwardRef(({className:e,type:t,...n},r)=>(0,N.jsx)(`input`,{type:t,className:F(`flex h-9 w-full rounded-xl border border-gray-200/80 bg-white px-3.5 py-2 text-sm text-gray-900 file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-gray-300 placeholder:font-normal focus:outline-none focus:ring-1 focus:ring-primary/40 focus:border-primary/40 transition-colors disabled:cursor-not-allowed disabled:opacity-50`,e),ref:r,...n}));Hn.displayName=`ChatInput`;var Un=bt,Wn=ht,Gn=gt,Kn=P.forwardRef(({className:e,sideOffset:t=8,align:n=`start`,...r},i)=>(0,N.jsx)(vt,{children:(0,N.jsx)(mt,{ref:i,sideOffset:t,align:n,className:F(`z-[var(--z-popover,50)] w-72 overflow-hidden rounded-2xl border border-gray-200/50 bg-white p-4 shadow-lg animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...r})}));Kn.displayName=mt.displayName;var qn=He,Jn=qe,Yn=Ze,Xn=P.forwardRef(({className:e,children:t,...n},r)=>(0,N.jsxs)(Xe,{ref:r,className:F(`flex h-9 w-full items-center justify-between whitespace-nowrap rounded-xl border border-gray-200/80 bg-white px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/40 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1`,e),...n,children:[t,(0,N.jsx)(Pe,{asChild:!0,children:(0,N.jsx)(je,{className:`h-4 w-4 opacity-50`})})]}));Xn.displayName=Xe.displayName;var Zn=P.forwardRef(({className:e,...t},n)=>(0,N.jsx)(Le,{ref:n,className:F(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,N.jsx)(Ae,{className:`h-4 w-4`})}));Zn.displayName=Le.displayName;var Qn=P.forwardRef(({className:e,...t},n)=>(0,N.jsx)(Re,{ref:n,className:F(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,N.jsx)(je,{className:`h-4 w-4`})}));Qn.displayName=Re.displayName;var $n=P.forwardRef(({className:e,children:t,position:n=`popper`,...r},i)=>(0,N.jsx)(Ge,{children:(0,N.jsxs)(We,{ref:i,className:F(`relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md bg-white text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,...r,children:[(0,N.jsx)(Zn,{}),(0,N.jsx)(Ne,{className:F(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]`),children:t}),(0,N.jsx)(Qn,{})]})}));$n.displayName=We.displayName;var er=P.forwardRef(({className:e,...t},n)=>(0,N.jsx)(Ie,{ref:n,className:F(`px-2 py-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500`,e),...t}));er.displayName=Ie.displayName;var tr=P.forwardRef(({className:e,children:t,...n},r)=>(0,N.jsxs)(Ve,{ref:r,className:F(`relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-gray-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 hover:bg-gray-100`,e),...n,children:[(0,N.jsx)(`span`,{className:`absolute right-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,N.jsx)(Ye,{children:(0,N.jsx)(Be,{className:`h-4 w-4`})})}),(0,N.jsx)(Fe,{children:t})]}));tr.displayName=Ve.displayName;var nr=P.forwardRef(({className:e,...t},n)=>(0,N.jsx)(Me,{ref:n,className:F(`-mx-1 my-1 h-px bg-gray-100`,e),...t}));nr.displayName=Me.displayName;var rr=At,ir=wt,ar=Et,or=P.forwardRef(({className:e,sideOffset:t=4,...n},r)=>(0,N.jsx)(Ot,{children:(0,N.jsx)(Ct,{ref:r,sideOffset:t,className:F(`z-[var(--z-tooltip)] overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...n})}));or.displayName=Ct.displayName;var sr={Popover:Un,PopoverAnchor:Gn,PopoverContent:Kn,PopoverTrigger:Wn,Input:Hn,Select:qn,SelectContent:$n,SelectGroup:Jn,SelectItem:tr,SelectLabel:er,SelectSeparator:nr,SelectTrigger:Xn,SelectValue:Yn,Tooltip:ir,TooltipContent:or,TooltipProvider:rr,TooltipTrigger:ar},cr=680,lr=.82,ur=560;function dr(e){let{Popover:t,PopoverAnchor:n,PopoverContent:r}=sr,{elementRef:i,width:a}=Vn(),o=(0,P.useRef)(null),{isOpen:s,isLoading:c,items:l,activeIndex:u,activeItem:d,texts:f,onSelectItem:p,onOpenChange:m,onSetActiveIndex:h}=e,g=(0,P.useMemo)(()=>{if(a)return Math.min(a>ur?a*lr:a,cr)},[a]);return Bn({containerRef:o,activeIndex:u,itemCount:l.length,isEnabled:s&&!c,getItemSelector:e=>`[data-slash-index="${e}"]`}),(0,N.jsxs)(t,{open:s,onOpenChange:m,children:[(0,N.jsx)(n,{asChild:!0,children:(0,N.jsx)(`div`,{ref:i,className:`pointer-events-none absolute bottom-full left-3 right-3 h-0`})}),(0,N.jsx)(r,{side:`top`,align:`start`,sideOffset:10,className:`z-[70] max-w-[calc(100vw-1.5rem)] overflow-hidden rounded-2xl border border-gray-200 bg-white/95 p-0 shadow-2xl backdrop-blur-md`,onOpenAutoFocus:e=>e.preventDefault(),style:g?{width:`${g}px`}:void 0,children:(0,N.jsxs)(`div`,{className:`grid min-h-[240px] grid-cols-[minmax(220px,300px)_minmax(0,1fr)]`,children:[(0,N.jsx)(`div`,{ref:o,role:`listbox`,"aria-label":f.slashSectionLabel,className:`custom-scrollbar max-h-[320px] overflow-y-auto border-r border-gray-200 p-2.5`,children:c?(0,N.jsx)(`div`,{className:`p-2 text-xs text-gray-500`,children:f.slashLoadingLabel}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`div`,{className:`mb-2 px-2 text-[11px] font-semibold uppercase tracking-wide text-gray-500`,children:f.slashSectionLabel}),l.length===0?(0,N.jsx)(`div`,{className:`px-2 text-xs text-gray-400`,children:f.slashEmptyLabel}):(0,N.jsx)(`div`,{className:`space-y-1`,children:l.map((e,t)=>{let n=t===u;return(0,N.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":n,"data-slash-index":t,onMouseEnter:()=>h(t),onClick:()=>p(e),className:`flex w-full items-start gap-2 rounded-lg px-2 py-1.5 text-left transition ${n?`bg-gray-100 text-gray-900`:`text-gray-700 hover:bg-gray-50`}`,children:[(0,N.jsx)(`span`,{className:`truncate text-xs font-semibold`,children:e.title}),(0,N.jsx)(`span`,{className:`truncate text-xs text-gray-500`,children:e.subtitle})]},e.key)})})]})}),(0,N.jsx)(`div`,{className:`min-w-0 p-2.5`,children:d?(0,N.jsxs)(`div`,{className:`space-y-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`span`,{className:`inline-flex rounded-full bg-primary/10 px-2 py-0.5 text-[11px] font-semibold text-primary`,children:d.subtitle}),(0,N.jsx)(`span`,{className:`text-sm font-semibold text-gray-900`,children:d.title})]}),(0,N.jsx)(`p`,{className:`text-xs leading-5 text-gray-600`,children:d.description}),(0,N.jsx)(`div`,{className:`space-y-1`,children:d.detailLines.map(e=>(0,N.jsx)(`div`,{className:`min-w-0 break-all rounded-md bg-gray-50 px-2 py-1 text-[11px] leading-5 text-gray-600`,children:e},e))}),(0,N.jsx)(`div`,{className:`pt-1 text-[11px] text-gray-500`,children:f.slashSkillHintLabel})]}):(0,N.jsx)(`div`,{className:`text-xs text-gray-500`,children:f.slashHintLabel})})]})})]})}var fr=D(`inline-flex items-center justify-center whitespace-nowrap rounded-full text-sm font-medium ring-offset-background transition-all duration-fast focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary-600 active:bg-primary-700 shadow-sm`,destructive:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,outline:`border border-gray-200 bg-white hover:bg-gray-50 hover:text-gray-800 text-gray-600`,secondary:`bg-gray-100 text-gray-700 hover:bg-gray-200/80`,ghost:`hover:bg-gray-100/80 hover:text-gray-800`,link:`text-primary underline-offset-4 hover:underline`,primary:`bg-primary text-primary-foreground hover:bg-primary-600 active:bg-primary-700 shadow-sm`,subtle:`bg-gray-100 text-gray-600 hover:bg-gray-200/80`,"primary-outline":`border border-primary/30 text-primary hover:bg-primary hover:text-primary-foreground`},size:{default:`h-9 px-4 py-2`,sm:`h-8 px-3 text-xs`,lg:`h-11 px-5 text-[14px]`,xl:`h-12 px-6 text-[15px]`,icon:`h-9 w-9`}},defaultVariants:{variant:`default`,size:`default`}}),pr=P.forwardRef(({className:e,variant:t,size:n,...r},i)=>(0,N.jsx)(`button`,{className:F(fr({variant:t,size:n,className:e})),ref:i,...r}));pr.displayName=`ChatButton`;var mr=120;function hr(e){let t=e.replace(/\s+/g,` `).trim();return t.length<=mr?t:`${t.slice(0,mr-1)}…`}function gr(){return(0,N.jsx)(`span`,{"aria-hidden":`true`,"data-testid":`chat-stop-icon`,className:`block h-3 w-3 rounded-[2px] bg-gray-700 shadow-[inset_0_0_0_1px_rgba(17,24,39,0.06)]`})}function _r({sendError:e,sendErrorDetailsLabel:t,isSending:n,canStopGeneration:r,sendDisabled:i,stopDisabled:a,stopHint:o,sendButtonLabel:s,stopButtonLabel:c,onSend:l,onStop:u}){let{Popover:d,PopoverContent:f,PopoverTrigger:p,Tooltip:m,TooltipContent:h,TooltipProvider:g,TooltipTrigger:_}=sr,v=e?.trim()??``,y=v?hr(v):``,b=t?.trim()||`Details`;return(0,N.jsxs)(`div`,{className:`flex shrink-0 flex-col items-end gap-1`,children:[v?(0,N.jsxs)(`div`,{className:`flex max-w-[420px] items-start justify-end gap-2 text-right`,children:[(0,N.jsx)(`div`,{className:`min-w-0 flex-1 text-[11px] text-red-600`,children:(0,N.jsx)(`span`,{className:`block truncate`,title:v,children:y})}),(0,N.jsxs)(d,{children:[(0,N.jsx)(p,{asChild:!0,children:(0,N.jsx)(`button`,{type:`button`,className:`shrink-0 rounded-full border border-red-200/80 bg-red-50 px-2 py-0.5 text-[10px] font-semibold text-red-700 transition-colors hover:bg-red-100`,children:b})}),(0,N.jsxs)(f,{align:`end`,className:`w-[min(32rem,calc(100vw-1.5rem))] border-red-100/80 p-0`,children:[(0,N.jsx)(`div`,{className:`border-b border-red-100 bg-red-50/80 px-4 py-2 text-xs font-semibold text-red-700`,children:b}),(0,N.jsx)(`pre`,{className:`max-h-80 overflow-auto whitespace-pre-wrap break-words px-4 py-3 text-xs leading-relaxed text-red-700`,children:v})]})]})]}):null,(0,N.jsx)(`div`,{className:`flex items-center gap-2`,children:n?r?(0,N.jsx)(pr,{size:`icon`,variant:`outline`,className:`h-8 w-8 rounded-full`,"aria-label":c,onClick:()=>void u(),disabled:a,children:(0,N.jsx)(gr,{})}):(0,N.jsx)(g,{children:(0,N.jsxs)(m,{children:[(0,N.jsx)(_,{asChild:!0,children:(0,N.jsx)(`span`,{children:(0,N.jsx)(pr,{size:`icon`,variant:`outline`,className:`h-8 w-8 rounded-full`,"aria-label":c,disabled:!0,children:(0,N.jsx)(gr,{})})})}),(0,N.jsx)(h,{side:`top`,children:(0,N.jsx)(`p`,{className:`text-xs`,children:o})})]})}):(0,N.jsx)(pr,{size:`icon`,className:`h-8 w-8 rounded-full`,"aria-label":s,onClick:()=>void l(),disabled:i,children:(0,N.jsx)(Pt,{className:`h-5 w-5`})})})]})}function vr(e,t){let n=t.trim().toLowerCase();return n?e.filter(e=>[e.label,e.key,e.description].filter(e=>typeof e==`string`&&e.trim().length>0).join(` `).toLowerCase().includes(n)):e}function yr(e){let{Input:t,Popover:n,PopoverContent:r,PopoverTrigger:i}=sr,{picker:a}=e,o=(0,P.useRef)(null),s=(0,P.useId)(),[c,l]=(0,P.useState)(``),[u,d]=(0,P.useState)(0),f=(0,P.useMemo)(()=>new Set(a.selectedKeys),[a.selectedKeys]),p=a.selectedKeys.length,m=c.trim().length>0,h=(0,P.useMemo)(()=>{if(m)return null;let e=a.groups?.filter(e=>e.options.length>0)??[];return e.length>0?e:null},[m,a.groups]),g=(0,P.useMemo)(()=>h?h.flatMap(e=>e.options):vr(a.options,c),[h,a.options,c]);(0,P.useEffect)(()=>{d(0)},[c]),(0,P.useEffect)(()=>{d(e=>g.length===0?0:Math.min(e,g.length-1))},[g.length]),Bn({containerRef:o,activeIndex:u,itemCount:g.length,isEnabled:g.length>0,getItemSelector:e=>`[data-skill-index="${e}"]`});let _=e=>{if(f.has(e)){a.onSelectedKeysChange(a.selectedKeys.filter(t=>t!==e));return}a.onSelectedKeysChange([...a.selectedKeys,e])},v=e=>{if(g.length!==0){if(e.key===`ArrowDown`){e.preventDefault(),d(e=>Math.min(e+1,g.length-1));return}if(e.key===`ArrowUp`){e.preventDefault(),d(e=>Math.max(e-1,0));return}if(e.key===`Enter`){e.preventDefault();let t=g[u];t&&_(t.key)}}};return(0,N.jsxs)(n,{children:[(0,N.jsx)(i,{asChild:!0,children:(0,N.jsxs)(`button`,{type:`button`,"aria-haspopup":`listbox`,"aria-label":a.title,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg px-0 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-100 hover:text-gray-900 sm:w-auto sm:gap-1.5 sm:px-3`,children:[(0,N.jsx)(Te,{className:`h-4 w-4`}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:a.title}),p>0?(0,N.jsx)(`span`,{className:`absolute -right-1 -top-1 flex h-[18px] min-w-[18px] items-center justify-center rounded-full bg-primary px-1 text-[10px] font-semibold leading-none text-white shadow-sm sm:static sm:ml-0.5 sm:bg-primary/10 sm:text-primary sm:shadow-none`,children:p}):null]})}),(0,N.jsxs)(r,{side:`top`,align:`start`,className:`w-[360px] p-0`,children:[(0,N.jsxs)(`div`,{className:`space-y-2 border-b border-gray-100 px-4 py-3`,children:[(0,N.jsx)(`div`,{className:`text-sm font-semibold text-gray-900`,children:a.title}),(0,N.jsxs)(`div`,{className:`relative`,children:[(0,N.jsx)(Oe,{className:`pointer-events-none absolute left-3 top-2.5 h-3.5 w-3.5 text-gray-400`}),(0,N.jsx)(t,{value:c,onChange:e=>l(e.target.value),onKeyDown:v,placeholder:a.searchPlaceholder,role:`combobox`,"aria-controls":s,"aria-expanded":`true`,"aria-autocomplete":`list`,"aria-activedescendant":g[u]?`${s}-option-${u}`:void 0,className:`h-8 rounded-lg pl-8 text-xs`})]})]}),(0,N.jsx)(`div`,{ref:o,id:s,role:`listbox`,"aria-multiselectable":`true`,className:`custom-scrollbar max-h-[320px] overflow-y-auto`,children:a.isLoading?(0,N.jsx)(`div`,{className:`p-4 text-xs text-gray-500`,children:a.loadingLabel}):g.length===0?(0,N.jsx)(`div`,{className:`p-4 text-center text-xs text-gray-500`,children:a.emptyLabel}):(0,N.jsx)(`div`,{className:`py-1`,children:(()=>{let e=h??[{key:`all-skills`,options:g}],t=0;return e.map(e=>(0,N.jsxs)(`div`,{children:[e.label?(0,N.jsx)(`div`,{className:`px-4 pb-1 pt-2 text-[11px] font-semibold uppercase tracking-wide text-gray-500`,children:e.label}):null,e.options.map(e=>{let n=t;t+=1;let r=f.has(e.key),i=n===u;return(0,N.jsxs)(`button`,{type:`button`,id:`${s}-option-${n}`,role:`option`,"aria-selected":r,"data-skill-index":n,onClick:()=>_(e.key),onMouseEnter:()=>d(n),className:`flex w-full items-center gap-3 px-4 py-2.5 text-left transition-colors ${i?`bg-gray-50`:`hover:bg-gray-50`}`,children:[(0,N.jsx)(`div`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-gray-100 text-gray-500`,children:(0,N.jsx)(cn,{className:`h-4 w-4`})}),(0,N.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,N.jsx)(`span`,{className:`truncate text-sm text-gray-900`,children:e.label}),e.badgeLabel?(0,N.jsx)(`span`,{className:`shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:e.badgeLabel}):null]}),(0,N.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-gray-500`,children:e.description||e.key})]}),(0,N.jsx)(`div`,{className:`ml-3 shrink-0`,children:(0,N.jsx)(`span`,{className:r?`inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-white`:`inline-flex h-5 w-5 items-center justify-center rounded-full border border-gray-300 bg-white`,children:r?(0,N.jsx)(Be,{className:`h-3 w-3`}):null})})]},e.key)})]},e.key))})()})}),a.manageHref&&a.manageLabel?(0,N.jsx)(`div`,{className:`border-t border-gray-100 px-4 py-2.5`,children:(0,N.jsxs)(`a`,{href:a.manageHref,className:`inline-flex items-center gap-1.5 text-xs font-medium text-primary transition-colors hover:text-primary/80`,children:[a.manageLabel,(0,N.jsx)(Qe,{className:`h-3 w-3`})]})}):null]})]})}function br({icon:e}){return e===`sparkles`?(0,N.jsx)(ot,{className:`h-3.5 w-3.5 shrink-0 text-primary`}):e===`brain`?(0,N.jsx)(Ft,{className:`h-3.5 w-3.5 shrink-0 text-gray-500`}):null}function xr({icon:e}){return e===`paperclip`?(0,N.jsx)(on,{className:`h-4 w-4`}):(0,N.jsx)(br,{icon:e})}var Sr={model:`min-w-0 flex-1 sm:min-w-[220px] sm:flex-none`,"session-type":`shrink-0`,thinking:`shrink-0`},Cr={model:`w-[min(18rem,calc(100vw-1rem))] sm:w-[320px]`,"session-type":`w-[220px]`,thinking:`w-[180px]`};function wr(e){return e.key===`model`&&e.selectedLabel&&e.selectedLabel.split(`/`).slice(1).join(`/`).trim()||e.selectedLabel}function Tr({item:e}){let{Select:t,SelectContent:n,SelectGroup:r,SelectItem:i,SelectLabel:a,SelectSeparator:o,SelectTrigger:s,SelectValue:c}=sr,l=e.groups?.filter(e=>e.options.length>0)??(e.options.length>0?[{key:`${e.key}-default`,options:e.options}]:[]),u=l.some(e=>e.options.length>0),d=wr(e);return(0,N.jsxs)(t,{value:e.value,onValueChange:e.onValueChange,disabled:e.disabled,children:[(0,N.jsx)(s,{className:`h-8 w-auto rounded-lg border-0 bg-transparent px-2 text-xs font-medium text-gray-600 shadow-none hover:bg-gray-100 focus:ring-0 sm:px-3 ${Sr[e.key]??``}`,children:e.selectedLabel?(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-left`,children:[(0,N.jsx)(br,{icon:e.icon}),(0,N.jsx)(`span`,{className:`truncate text-xs font-semibold text-gray-700 sm:hidden`,children:d}),(0,N.jsx)(`span`,{className:`hidden truncate text-xs font-semibold text-gray-700 sm:inline`,children:e.selectedLabel})]}):e.loading?(0,N.jsx)(`div`,{className:`h-3 w-24 animate-pulse rounded bg-gray-200`}):(0,N.jsx)(c,{placeholder:e.placeholder})}),(0,N.jsxs)(n,{className:Cr[e.key]??``,children:[u?null:e.loading?(0,N.jsxs)(`div`,{className:`space-y-2 px-3 py-2`,children:[(0,N.jsx)(`div`,{className:`h-3 w-36 animate-pulse rounded bg-gray-200`}),(0,N.jsx)(`div`,{className:`h-3 w-28 animate-pulse rounded bg-gray-200`}),(0,N.jsx)(`div`,{className:`h-3 w-32 animate-pulse rounded bg-gray-200`})]}):e.emptyLabel?(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-gray-500`,children:e.emptyLabel}):null,l.map((e,t)=>(0,N.jsxs)(`div`,{children:[t>0?(0,N.jsx)(o,{}):null,(0,N.jsxs)(r,{children:[e.label?(0,N.jsx)(a,{children:e.label}):null,e.options.map(e=>(0,N.jsx)(i,{value:e.value,className:`py-2`,children:e.description?(0,N.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,N.jsx)(`span`,{className:`truncate text-xs font-semibold text-gray-800`,children:e.label}),(0,N.jsx)(`span`,{className:`truncate text-[11px] text-gray-500`,children:e.description})]}):(0,N.jsx)(`span`,{className:`truncate text-xs font-semibold text-gray-800`,children:e.label})},e.value))]})]},e.key))]})]})}function Er({actions:e,accessories:t,selects:n,skillPicker:r}){let{Tooltip:i,TooltipContent:a,TooltipProvider:o,TooltipTrigger:s}=sr;return(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 pb-3`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 overflow-hidden`,children:[r?(0,N.jsx)(yr,{picker:r}):null,n.map(e=>(0,N.jsx)(Tr,{item:e},e.key)),t?.map(e=>{let t=(0,N.jsxs)(`button`,{type:`button`,className:`inline-flex items-center rounded-lg py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-100 hover:text-gray-900 disabled:cursor-not-allowed disabled:text-gray-400 ${e.iconOnly?`h-8 w-8 justify-center px-0`:`gap-1.5 px-3`}`,onClick:e.onClick,disabled:e.disabled,"aria-label":e.label,children:[(0,N.jsx)(xr,{icon:e.icon}),e.iconOnly?null:(0,N.jsx)(`span`,{children:e.label})]});return e.tooltip?(0,N.jsx)(o,{children:(0,N.jsxs)(i,{children:[(0,N.jsx)(s,{asChild:!0,children:e.disabled?(0,N.jsx)(`span`,{className:`inline-flex`,children:t}):t}),(0,N.jsx)(a,{side:`top`,children:(0,N.jsx)(`p`,{className:`text-xs`,children:e.tooltip})})]})},e.key):(0,N.jsx)(`div`,{children:t},e.key)})]}),(0,N.jsx)(_r,{...e})]})}var Dr=(0,P.createContext)(null);function Or(e,t){let n=null;return e!=null&&(n=e[1]),{getTheme:function(){return t??(n==null?null:n.getTheme())}}}function kr(){let e=(0,P.useContext)(Dr);return e??function(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(8),e}function I(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function Ar(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);n.search=r.toString(),console.warn(`Minified Lexical warning #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}var jr=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0,Mr=jr&&`documentMode`in document?document.documentMode:null,Nr=jr&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),Pr=jr&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),Fr=!(!jr||!(`InputEvent`in window)||Mr)&&`getTargetRanges`in new window.InputEvent(`input`),Ir=jr&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,Lr=jr&&/Android/.test(navigator.userAgent),Rr=jr&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!Lr,zr=jr&&/^(?=.*Chrome).*/i.test(navigator.userAgent),Br=jr&&Lr&&zr,Vr=jr&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&Nr&&!zr,Hr=0,Ur=1,Wr=2,Gr=1,Kr=2,qr=3,Jr=4,Yr=5,Xr=6,Zr=Rr||Ir||Vr?`\xA0`:``,Qr=`
|
|
2
2
|
|
|
3
3
|
`,$r=Pr?`\xA0`:Zr,ei={bold:1,capitalize:1024,code:16,highlight:128,italic:2,lowercase:256,strikethrough:4,subscript:32,superscript:64,underline:8,uppercase:512},ti={directionless:1,unmergeable:2},ni={center:2,end:6,justify:4,left:1,right:3,start:5},ri={[Kr]:`center`,[Xr]:`end`,[Jr]:`justify`,[Gr]:`left`,[qr]:`right`,[Yr]:`start`},ii={normal:0,segmented:2,token:1},ai={[Hr]:`normal`,[Wr]:`segmented`,[Ur]:`token`},oi=`$config`;function si(e,t,n,r,i,a){let o=e.getFirstChild();for(;o!==null;){let e=o.__key;o.__parent===t&&(V(o)&&si(o,e,n,r,i,a),n.has(e)||a.delete(e),i.push(e)),o=o.getNextSibling()}}var ci=!1,li=0;function ui(e){li=e.timeStamp}function di(e,t,n){let r=e.nodeName===`BR`,i=t.__lexicalLineBreak;return i&&(e===i||r&&e.previousSibling===i)||r&&ll(e,n)!==void 0}function fi(e,t,n){let r=Zl(Ul(n)),i=null,a=null;r!==null&&r.anchorNode===e&&(i=r.anchorOffset,a=r.focusOffset);let o=e.nodeValue;o!==null&&Sl(t,o,i,a,!1)}function pi(e,t,n){if(z(e)){let t=e.anchor.getNode();if(t.is(n)&&e.format!==t.getFormat())return!1}return Qc(t)&&n.isAttached()}function mi(e,t,n,r){for(let i=e;i&&!fu(i);i=Ll(i)){let e=ll(i,t);if(e!==void 0){let t=sl(e,n);if(t)return yc(t)||!$l(i)?void 0:[i,t]}else if(i===r)return[r,ml(n)]}}function hi(e,t,n){ci=!0;let r=performance.now()-li>100;try{pc(e,()=>{let i=B()||function(e){return e.getEditorState().read(()=>{let e=B();return e===null?null:e.clone()})}(e),a=new Map,o=e.getRootElement(),s=e._editorState,c=e._blockCursorElement,l=!1,u=``;for(let n=0;n<t.length;n++){let d=t[n],f=d.type,p=d.target,m=mi(p,e,s,o);if(!m)continue;let[h,g]=m;if(f===`characterData`)r&&R(g)&&Qc(p)&&pi(i,p,g)&&fi(p,g,e);else if(f===`childList`){l=!0;let t=d.addedNodes;for(let n=0;n<t.length;n++){let r=t[n],i=cl(r),a=r.parentNode;if(a!=null&&r!==c&&i===null&&!di(r,a,e)){if(Pr){let e=($l(r)?r.innerText:null)||r.nodeValue;e&&(u+=e)}a.removeChild(r)}}let n=d.removedNodes,r=n.length;if(r>0){let t=0;for(let i=0;i<r;i++){let r=n[i];(di(r,p,e)||c===r)&&(p.appendChild(r),t++)}r!==t&&a.set(h,g)}}}if(a.size>0)for(let[t,n]of a)n.reconcileObservedMutation(t,e);let d=n.takeRecords();if(d.length>0){for(let t=0;t<d.length;t++){let n=d[t],r=n.addedNodes,i=n.target;for(let t=0;t<r.length;t++){let n=r[t],a=n.parentNode;a==null||n.nodeName!==`BR`||di(n,i,e)||a.removeChild(n)}}n.takeRecords()}i!==null&&(l&&hl(i),Pr&&Fl(e)&&i.insertRawText(u))})}finally{ci=!1}}function gi(e){let t=e._observer;t!==null&&hi(e,t.takeRecords(),t)}function _i(e){(function(e){li===0&&Ul(e).addEventListener(`textInput`,ui,!0)})(e),e._observer=new MutationObserver((t,n)=>{hi(e,t,n)})}var vi=class{key;parse;unparse;isEqual;defaultValue;resetOnCopyNode;constructor(e,t){this.key=e,this.parse=t.parse.bind(t),this.unparse=(t.unparse||Ti).bind(t),this.isEqual=(t.isEqual||Object.is).bind(t),this.defaultValue=this.parse(void 0),this.resetOnCopyNode=t.resetOnCopyNode||!1}};function yi(e,t){return new vi(e,t)}function bi(e){let t=new Map,n=new Set;for(let r=typeof e==`function`?e:e.replace;r.prototype&&r.prototype.getType!==void 0;r=Object.getPrototypeOf(r)){let{ownNodeConfig:e}=mu(r);if(e&&e.stateConfigs)for(let r of e.stateConfigs){let e;`stateConfig`in r?(e=r.stateConfig,r.flat&&n.add(e.key)):e=r,t.set(e.key,e)}}return{flatKeys:n,sharedConfigMap:t}}var xi=class e{node;knownState;unknownState;sharedNodeState;size;constructor(e,t,n=void 0,r=new Map,i=void 0){this.node=e,this.sharedNodeState=t,this.unknownState=n,this.knownState=r;let{sharedConfigMap:a}=this.sharedNodeState;this.size=i===void 0?function(e,t,n){let r=n.size;if(t)for(let i in t){let t=e.get(i);t&&n.has(t)||r++}return r}(a,n,r):i}getValue(e){let t=this.knownState.get(e);if(t!==void 0)return t;this.sharedNodeState.sharedConfigMap.set(e.key,e);let n=e.defaultValue;if(this.unknownState&&e.key in this.unknownState){let t=this.unknownState[e.key];t!==void 0&&(n=e.parse(t)),this.updateFromKnown(e,n)}return n}getInternalState(){return[this.unknownState,this.knownState]}toJSON(){let e={...this.unknownState},t={};for(let[t,n]of this.knownState)t.isEqual(n,t.defaultValue)?delete e[t.key]:e[t.key]=t.unparse(n);for(let n of this.sharedNodeState.flatKeys)n in e&&(t[n]=e[n],delete e[n]);return wi(e)&&(t.$=e),t}getWritable(t){if(this.node===t)return this;let{sharedNodeState:n,unknownState:r}=this,i=new Map(this.knownState);return new e(t,n,function(e,t,n){let r;if(n)for(let[i,a]of Object.entries(n)){let n=e.get(i);n?t.has(n)||t.set(n,n.parse(a)):(r||={},r[i]=a)}return r}(n.sharedConfigMap,i,r),i,this.size)}resetOnCopyNode(){for(let e of this.knownState.keys())e.resetOnCopyNode&&this.knownState.set(e,e.defaultValue);return this}updateFromKnown(e,t){let n=e.key;this.sharedNodeState.sharedConfigMap.set(n,e);let{knownState:r,unknownState:i}=this;r.has(e)||i&&n in i||(i&&(delete i[n],this.unknownState=wi(i)),this.size++),r.set(e,t)}updateFromUnknown(e,t){let n=this.sharedNodeState.sharedConfigMap.get(e);n?this.updateFromKnown(n,n.parse(t)):(this.unknownState=this.unknownState||{},e in this.unknownState||this.size++,this.unknownState[e]=t)}updateFromJSON(e){let{knownState:t}=this;for(let e of t.keys())t.set(e,e.defaultValue);if(this.size=t.size,this.unknownState=void 0,e)for(let[t,n]of Object.entries(e))this.updateFromUnknown(t,n)}};function Si(e){let t=e.getWritable(),n=t.__state?t.__state.getWritable(t):new xi(t,Ci(t));return t.__state=n,n}function Ci(e){return e.__state?e.__state.sharedNodeState:Vc(au(),e.getType()).sharedNodeState}function wi(e){if(e)for(let t in e)return e}function Ti(e){return e}function Ei(e,t,n){for(let[r,i]of t.knownState){if(e.has(r.key))continue;e.add(r.key);let t=n?n.getValue(r):r.defaultValue;if(t!==i&&!r.isEqual(t,i))return!0}return!1}function Di(e,t,n){let{unknownState:r}=t,i=n?n.unknownState:void 0;if(r){for(let[t,n]of Object.entries(r))if(!e.has(t)&&(e.add(t),n!==(i?i[t]:void 0)))return!0}return!1}function Oi(e,t){let n=e.__state;return n&&n.node===e?n.getWritable(t):n}function ki(e,t){let n=e.__mode,r=e.__format,i=e.__style,a=t.__mode,o=t.__format,s=t.__style,c=e.__state,l=t.__state;return(n===null||n===a)&&(r===null||r===o)&&(i===null||i===s)&&(e.__state===null||c===l||function(e,t){if(e===t)return!0;let n=new Set;return!(e&&Ei(n,e,t)||t&&Ei(n,t,e)||e&&Di(n,e,t)||t&&Di(n,t,e))}(c,l))}function Ai(e,t){let n=e.mergeWithSibling(t),r=ec()._normalizedNodes;return r.add(e.__key),r.add(t.__key),n}function ji(e){let t,n,r=e;if(r.__text!==``||!r.isSimpleText()||r.isUnmergeable()){for(;(t=r.getPreviousSibling())!==null&&R(t)&&t.isSimpleText()&&!t.isUnmergeable();){if(t.__text!==``){if(ki(t,r)){r=Ai(t,r);break}break}t.remove()}for(;(n=r.getNextSibling())!==null&&R(n)&&n.isSimpleText()&&!n.isUnmergeable();){if(n.__text!==``){if(ki(r,n)){r=Ai(r,n);break}break}n.remove()}}else r.remove()}function Mi(e){return Ni(e.anchor),Ni(e.focus),e}function Ni(e){for(;e.type===`element`;){let t=e.getNode(),n=e.offset,r,i;if(n===t.getChildrenSize()?(r=t.getChildAtIndex(n-1),i=!0):(r=t.getChildAtIndex(n),i=!1),R(r)){e.set(r.__key,i?r.getTextContentSize():0,`text`,!0);break}if(!V(r))break;e.set(r.__key,i?r.getChildrenSize():0,`element`,!0)}}var Pi,Fi,Ii,Li,Ri,zi,Bi,Vi,Hi,Ui,Wi=``,Gi=null,Ki=null,qi=!1,Ji=!1;function Yi(e,t){let n=Bi.get(e);if(t!==null){let n=pa(e);n.parentNode===t&&t.removeChild(n)}if(Vi.has(e)||Fi._keyToDOMMap.delete(e),V(n)){let e=sa(n,Bi);Xi(e,0,e.length-1,null)}n!==void 0&&Ml(Ui,Ii,Li,n,`destroyed`)}function Xi(e,t,n,r){for(let i=t;i<=n;++i){let t=e[i];t!==void 0&&Yi(t,r)}}function Zi(e,t){e.setProperty(`text-align`,t)}var Qi=`40px`;function $i(e,t){let n=Pi.theme.indent;if(typeof n==`string`){let r=e.classList.contains(n);t>0&&!r?e.classList.add(n):t<1&&r&&e.classList.remove(n)}if(t===0)return void e.style.setProperty(`padding-inline-start`,``);let r=getComputedStyle(Fi._rootElement||e).getPropertyValue(`--lexical-indent-base-value`)||Qi;e.style.setProperty(`padding-inline-start`,`calc(${t} * ${r})`)}function ea(e,t){let n=e.style;t===0?Zi(n,``):t===1?Zi(n,`left`):t===2?Zi(n,`center`):t===3?Zi(n,`right`):t===4?Zi(n,`justify`):t===5?Zi(n,`start`):t===6&&Zi(n,`end`)}function ta(e,t){let n=function(e){let t=e.__dir;if(t!==null)return t;if(xc(e))return null;let n=e.getParentOrThrow();return xc(n)&&n.__dir===null?`auto`:null}(t);n===null?e.removeAttribute(`dir`):e.dir=n}function na(e,t){let n=Vi.get(e);n===void 0&&I(60);let r=n.createDOM(Pi,Fi);if(function(e,t,n){let r=n._keyToDOMMap;(function(e,t,n){let r=`__lexicalKey_${t._key}`;e[r]=n})(t,n,e),r.set(e,t)}(e,r,Fi),R(n)?r.setAttribute(`data-lexical-text`,`true`):yc(n)&&r.setAttribute(`data-lexical-decorator`,`true`),V(n)){let e=n.__indent,t=n.__size;if(ta(r,n),e!==0&&$i(r,e),t!==0){let e=t-1;ra(sa(n,Vi),n,0,e,n.getDOMSlot(r))}let i=n.__format;i!==0&&ea(r,i),n.isInline()||aa(null,n,r)}else{let t=n.getTextContent();if(yc(n)){let t=n.decorate(Fi,Pi);t!==null&&la(e,t),r.contentEditable=`false`}Wi+=t}return t!==null&&t.insertChild(r),Ml(Ui,Ii,Li,n,`created`),r}function ra(e,t,n,r,i){let a=Wi;Wi=``;let o=n;for(;o<=r;++o){na(e[o],i);let t=Vi.get(e[o]);t!==null&&R(t)?Gi===null&&(Gi=t.getFormat(),Ki=t.getStyle()):V(t)&&o<r&&!t.isInline()&&(Wi+=Qr)}i.element.__lexicalTextContent=Wi,Wi=a+Wi}function ia(e,t){if(e){let n=e.__last;if(n){let e=t.get(n);if(e)return Go(e)?`line-break`:yc(e)&&e.isInline()?`decorator`:null}return`empty`}return null}function aa(e,t,n){let r=ia(e,Bi),i=ia(t,Vi);r!==i&&t.getDOMSlot(n).setManagedLineBreak(i)}function oa(e,t,n){var r;Gi=null,Ki=null,function(e,t,n){let r=Wi,i=e.__size,a=t.__size;Wi=``;let o=n.element;if(i===1&&a===1){let n=e.__first,r=t.__first;if(n===r)ca(n,o);else{let e=pa(n),t=na(r,null);try{o.replaceChild(t,e)}catch(i){if(typeof i==`object`&&i){let a=`${i.toString()} Parent: ${o.tagName}, new child: {tag: ${t.tagName} key: ${r}}, old child: {tag: ${e.tagName}, key: ${n}}.`;throw Error(a)}throw i}Yi(n,null)}let i=Vi.get(r);R(i)&&Gi===null&&(Gi=i.getFormat(),Ki=i.getStyle())}else{let r=sa(e,Bi),s=sa(t,Vi);if(r.length!==i&&I(227),s.length!==a&&I(228),i===0)a!==0&&ra(s,0,0,a-1,n);else if(a===0){if(i!==0){let e=n.after==null&&n.before==null&&n.element.__lexicalLineBreak==null;Xi(r,0,i-1,e?null:o),e&&(o.textContent=``)}}else (function(e,t,n,r,i,a){let o=r-1,s=i-1,c,l,u=a.getFirstChild(),d=0,f=0;for(;d<=o&&f<=s;){let e=t[d],r=n[f];if(e===r)u=ua(ca(r,a.element)),d++,f++;else{if(l===void 0&&(l=da(n,f)),c===void 0)c=da(t,d);else if(!c.has(e)){d++;continue}if(!l.has(e)){u=ua(pa(e)),Yi(e,a.element),d++,c.delete(e);continue}if(c.has(r)){let e=Il(Fi,r);e!==u&&a.withBefore(u).insertChild(e),u=ua(ca(r,a.element)),d++,f++}else na(r,a.withBefore(u)),f++}let i=Vi.get(r);i!==null&&R(i)?Gi===null&&(Gi=i.getFormat(),Ki=i.getStyle()):V(i)&&f<=s&&!i.isInline()&&(Wi+=Qr)}let p=d>o,m=f>s;if(p&&!m){let e=n[s+1],t=e===void 0?null:Fi.getElementByKey(e);ra(n,0,f,s,a.withBefore(t))}else m&&!p&&Xi(t,d,o,a.element)})(0,r,s,i,a,n)}o.__lexicalTextContent=Wi,Wi=r+Wi}(e,t,t.getDOMSlot(n)),r=t,Gi==null||Gi===r.__textFormat||Ji||r.setTextFormat(Gi),function(e){Ki==null||Ki===e.__textStyle||Ji||e.setTextStyle(Ki)}(t)}function sa(e,t){let n=[],r=e.__first;for(;r!==null;){let e=t.get(r);e===void 0&&I(101),n.push(r),r=e.__next}return n}function ca(e,t){let n=Bi.get(e),r=Vi.get(e);n!==void 0&&r!==void 0||I(61);let i=qi||zi.has(e)||Ri.has(e),a=Il(Fi,e);if(n===r&&!i){let e;if(V(n)){let t=a.__lexicalTextContent;typeof t==`string`?e=t:(e=n.getTextContent(),a.__lexicalTextContent=e)}else e=n.getTextContent();return Wi+=e,a}if(n!==r&&i&&Ml(Ui,Ii,Li,r,`updated`),r.updateDOM(n,a,Pi)){let n=na(e,null);return t===null&&I(62),t.replaceChild(n,a),Yi(e,null),n}if(V(n)){V(r)||I(334,e);let t=r.__indent;(qi||t!==n.__indent)&&$i(a,t);let o=r.__format;if((qi||o!==n.__format)&&ea(a,o),i)oa(n,r,a),xc(r)||r.isInline()||aa(n,r,a);else{let e=a.__lexicalTextContent,t;typeof e==`string`?t=e:(t=n.getTextContent(),a.__lexicalTextContent=t),Wi+=t}if((qi||r.__dir!==n.__dir)&&(ta(a,r),xc(r)&&!qi))for(let e of r.getChildren())V(e)&&ta(Il(Fi,e.getKey()),e)}else{let t=r.getTextContent();if(yc(r)){let t=r.decorate(Fi,Pi);t!==null&&la(e,t)}Wi+=t}if(!Ji&&xc(r)&&r.__cachedText!==Wi){let e=r.getWritable();e.__cachedText=Wi,r=e}return a}function la(e,t){let n=Fi._pendingDecorators,r=Fi._decorators;if(n===null){if(r[e]===t)return;n=dl(Fi)}n[e]=t}function ua(e){let t=e.nextSibling;return t!==null&&t===Fi._blockCursorElement&&(t=t.nextSibling),t}function da(e,t){let n=new Set;for(let r=t;r<e.length;r++)n.add(e[r]);return n}function fa(e,t,n,r,i,a){Wi=``,qi=r===2,Fi=n,Pi=n._config,Ii=n._nodes,Li=Fi._listeners.mutation,Ri=i,zi=a,Bi=e._nodeMap,Vi=t._nodeMap,Ji=t._readOnly,Hi=new Map(n._keyToDOMMap);let o=new Map;return Ui=o,ca(`root`,null),Fi=void 0,Ii=void 0,Ri=void 0,zi=void 0,Bi=void 0,Vi=void 0,Pi=void 0,Hi=void 0,Ui=void 0,o}function pa(e){let t=Hi.get(e);return t===void 0&&I(75,e),t}function L(e){return{type:e}}var ma=L(`SELECTION_CHANGE_COMMAND`),ha=L(`CLICK_COMMAND`),ga=L(`BEFORE_INPUT_COMMAND`),_a=L(`INPUT_COMMAND`),va=L(`COMPOSITION_START_COMMAND`),ya=L(`COMPOSITION_END_COMMAND`),ba=L(`DELETE_CHARACTER_COMMAND`),xa=L(`INSERT_LINE_BREAK_COMMAND`),Sa=L(`INSERT_PARAGRAPH_COMMAND`),Ca=L(`CONTROLLED_TEXT_INSERTION_COMMAND`),wa=L(`PASTE_COMMAND`),Ta=L(`REMOVE_TEXT_COMMAND`),Ea=L(`DELETE_WORD_COMMAND`),Da=L(`DELETE_LINE_COMMAND`),Oa=L(`FORMAT_TEXT_COMMAND`),ka=L(`UNDO_COMMAND`),Aa=L(`REDO_COMMAND`),ja=L(`KEYDOWN_COMMAND`),Ma=L(`KEY_ARROW_RIGHT_COMMAND`),Na=L(`MOVE_TO_END`),Pa=L(`KEY_ARROW_LEFT_COMMAND`),Fa=L(`MOVE_TO_START`),Ia=L(`KEY_ARROW_UP_COMMAND`),La=L(`KEY_ARROW_DOWN_COMMAND`),Ra=L(`KEY_ENTER_COMMAND`),za=L(`KEY_SPACE_COMMAND`),Ba=L(`KEY_BACKSPACE_COMMAND`),Va=L(`KEY_ESCAPE_COMMAND`),Ha=L(`KEY_DELETE_COMMAND`),Ua=L(`KEY_TAB_COMMAND`),Wa=L(`DROP_COMMAND`),Ga=L(`DRAGSTART_COMMAND`),Ka=L(`DRAGOVER_COMMAND`),qa=L(`DRAGEND_COMMAND`),Ja=L(`COPY_COMMAND`),Ya=L(`CUT_COMMAND`),Xa=L(`SELECT_ALL_COMMAND`),Za=L(`FOCUS_COMMAND`),Qa=L(`BLUR_COMMAND`),$a=L(`KEY_MODIFIER_COMMAND`),eo=Object.freeze({}),to=[[`keydown`,function(e,t){no=e.timeStamp,ro=e.key,!t.isComposing()&&U(t,ja,e)}],[`pointerdown`,function(e,t){let n=e.target,r=e.pointerType;eu(n)&&r!==`touch`&&r!==`pen`&&e.button===0&&pc(t,()=>{Wc(n)||(lo=!0)})}],[`compositionstart`,function(e,t){U(t,va,e)}],[`compositionend`,function(e,t){Pr?fo=!0:Ir||!Rr&&!Vr?U(t,ya,e):(po=!0,mo=e.data)}],[`input`,function(e,t){e.stopPropagation(),pc(t,()=>{t.dispatchCommand(_a,e)},{event:e}),ao=null}],[`click`,function(e,t){pc(t,()=>{let n=B(),r=Zl(Ul(t)),i=Ns();if(r){if(z(n)){let t=n.anchor,a=t.getNode();if(t.type===`element`&&t.offset===0&&n.isCollapsed()&&!xc(a)&&pl().getChildrenSize()===1&&a.getTopLevelElementOrThrow().isEmpty()&&i!==null&&n.is(i))r.removeAllRanges(),n.dirty=!0;else if(e.detail===3&&!n.isCollapsed()&&a!==n.focus.getNode()){let e=gu(a,e=>V(e)&&!e.isInline());V(e)&&e.select(0)}}else if(e.pointerType===`touch`||e.pointerType===`pen`){let n=r.anchorNode;($l(n)||Qc(n))&&hl(Ms(i,r,t,e))}}U(t,ha,e)})}],[`cut`,eo],[`copy`,eo],[`dragstart`,eo],[`dragover`,eo],[`dragend`,eo],[`paste`,eo],[`focus`,eo],[`blur`,eo],[`drop`,eo]];Fr&&to.push([`beforeinput`,(e,t)=>function(e,t){let n=e.inputType;n===`deleteCompositionText`||Pr&&Fl(t)||n!==`insertCompositionText`&&U(t,ga,e)}(e,t)]);var no=0,ro=null,io=0,ao=null,oo=new WeakMap,so=new WeakMap,co=!1,lo=!1,uo=!1,fo=!1,po=!1,mo=``,ho=null,go=[0,``,0,`root`,0];function _o(e,t,n,r,i){let a=e.anchor,o=e.focus,s=a.getNode(),c=ec(),l=Zl(Ul(c)),u=l===null?null:l.anchorNode,d=a.key,f=c.getElementByKey(d),p=n.length;return d!==o.key||!R(s)||(!i&&(!Fr||io<r+50)||s.isDirty()&&p<2||_l(n))&&a.offset!==o.offset&&!s.isComposing()||Zc(s)||s.isDirty()&&p>1||(i||!Fr)&&f!==null&&!s.isComposing()&&u!==el(f)||l!==null&&t!==null&&(!t.collapsed||t.startContainer!==l.anchorNode||t.startOffset!==l.anchorOffset)||!s.isComposing()&&(s.getFormat()!==e.format||s.getStyle()!==e.style)||function(e,t){if(t.isSegmented())return!0;if(!e.isCollapsed())return!1;let n=e.anchor.offset,r=t.getParentOrThrow(),i=Xc(t);return n===0?!t.canInsertTextBefore()||!r.canInsertTextBefore()&&!t.isComposing()||i||function(e){let t=e.getPreviousSibling();return(R(t)||V(t)&&t.isInline())&&!t.canInsertTextAfter()}(t):n===t.getTextContentSize()&&(!t.canInsertTextAfter()||!r.canInsertTextAfter()&&!t.isComposing()||i)}(e,s)}function vo(e,t){return Qc(e)&&e.nodeValue!==null&&t!==0&&t!==e.nodeValue.length}function yo(e,t,n){let{anchorNode:r,anchorOffset:i,focusNode:a,focusOffset:o}=e;co&&(co=!1,vo(r,i)&&vo(a,o)&&!ho)||pc(t,()=>{if(!n)return void hl(null);if(!Kc(t,r,a))return;let s=B();if(ho&&z(s)&&s.isCollapsed()){let e=s.anchor,t=ho.anchor;(e.key===t.key&&e.offset===t.offset+1||e.offset===1&&t.getNode().is(e.getNode().getPreviousSibling()))&&(s=ho.clone(),hl(s))}if(ho=null,z(s)){let n=s.anchor,r=n.getNode();if(s.isCollapsed()){e.type===`Range`&&e.anchorNode===e.focusNode&&(s.dirty=!0);let i=Ul(t).event,a=i?i.timeStamp:performance.now(),[o,c,l,u,d]=go,f=pl(),p=!1===t.isComposing()&&f.getTextContent()===``;if(a<d+200&&n.offset===l&&n.key===u)bo(s,o,c);else if(n.type===`text`)R(r)||I(141),xo(s,r);else if(n.type===`element`&&!p){V(r)||I(259);let e=n.getNode();e.isEmpty()?function(e,t){bo(e,t.getTextFormat(),t.getTextStyle())}(s,e):bo(s,s.format,``)}}else{let e=n.key,t=s.focus.key,r=s.getNodes(),a=r.length,c=s.isBackward(),l=c?o:i,u=c?i:o,d=c?t:e,f=c?e:t,p=2047,m=!1;for(let e=0;e<a;e++){let t=r[e],n=t.getTextContentSize();if(R(t)&&n!==0&&!(e===0&&t.__key===d&&l===n||e===a-1&&t.__key===f&&u===0)&&(m=!0,p&=t.getFormat(),p===0))break}s.format=m?p:0}}U(t,ma,void 0)})}function bo(e,t,n){e.format===t&&e.style===n||(e.format=t,e.style=n,e.dirty=!0)}function xo(e,t){bo(e,t.getFormat(),t.getStyle())}function So(e){if(!e.getTargetRanges)return null;let t=e.getTargetRanges();return t.length===0?null:t[0]}function Co(e){let t=e.inputType,n=So(e),r=ec(),i=B();if(t===`deleteContentBackward`){if(i===null){let e=Ns();if(!z(e))return!0;hl(e.clone())}if(z(i)){let t=i.anchor.key===i.focus.key;if(a=e.timeStamp,ro===`MediaLast`&&a<no+30&&r.isComposing()&&t){if(al(null),no=0,setTimeout(()=>{pc(r,()=>{al(null)})},30),z(i)){let e=i.anchor.getNode();e.markDirty(),R(e)||I(142),xo(i,e)}}else{al(null),e.preventDefault();let n=i.anchor.getNode(),a=n.getTextContent(),o=n.canInsertTextAfter(),s=i.anchor.offset===0&&i.focus.offset===a.length,c=Br&&t&&!s&&o;if(c&&i.isCollapsed()&&(c=!yc(Pl(i.anchor,!0))),!c){U(r,ba,!0);let e=B();Br&&z(e)&&e.isCollapsed()&&(ho=e,setTimeout(()=>ho=null))}}return!0}}var a;if(!z(i))return!0;let o=e.data;ao!==null&&xl(!1,r,ao),i.dirty&&ao===null||!i.isCollapsed()||xc(i.anchor.getNode())||n===null||i.applyDOMRange(n),ao=null;let s=i.anchor,c=i.focus,l=s.getNode(),u=c.getNode();if(t===`insertText`||t===`insertTranspose`){if(o===`
|
|
4
4
|
`)e.preventDefault(),U(r,xa,!1);else if(o===Qr)e.preventDefault(),U(r,Sa,void 0);else if(o==null&&e.dataTransfer){let t=e.dataTransfer.getData(`text/plain`);e.preventDefault(),i.insertRawText(t)}else o!=null&&_o(i,n,o,e.timeStamp,!0)?(e.preventDefault(),U(r,Ca,o)):ao=o;return io=e.timeStamp,!0}switch(e.preventDefault(),t){case`insertFromYank`:case`insertFromDrop`:case`insertReplacementText`:U(r,Ca,e);break;case`insertFromComposition`:al(null),U(r,Ca,e);break;case`insertLineBreak`:al(null),U(r,xa,!1);break;case`insertParagraph`:al(null),uo&&!Ir?(uo=!1,U(r,xa,!1)):U(r,Sa,void 0);break;case`insertFromPaste`:case`insertFromPasteAsQuotation`:U(r,wa,e);break;case`deleteByComposition`:(function(e,t){return e!==t||V(e)||V(t)||!Xc(e)||!Xc(t)})(l,u)&&U(r,Ta,e);break;case`deleteByDrag`:case`deleteByCut`:U(r,Ta,e);break;case`deleteContent`:U(r,ba,!1);break;case`deleteWordBackward`:U(r,Ea,!0);break;case`deleteWordForward`:U(r,Ea,!1);break;case`deleteHardLineBackward`:case`deleteSoftLineBackward`:U(r,Da,!0);break;case`deleteContentForward`:case`deleteHardLineForward`:case`deleteSoftLineForward`:U(r,Da,!1);break;case`formatStrikeThrough`:U(r,Oa,`strikethrough`);break;case`formatBold`:U(r,Oa,`bold`);break;case`formatItalic`:U(r,Oa,`italic`);break;case`formatUnderline`:U(r,Oa,`underline`);break;case`historyUndo`:U(r,ka,void 0);break;case`historyRedo`:U(r,Aa,void 0)}return!0}function wo(e){if($l(e.target)&&Wc(e.target))return!0;let t=ec(),n=B(),r=e.data,i=So(e);if(r!=null&&z(n)&&_o(n,i,r,e.timeStamp,!1)){fo&&=(Do(t,r),!1);let i=n.anchor.getNode(),a=Zl(Ul(t));if(a===null)return!0;let o=n.isBackward(),s=o?n.anchor.offset:n.focus.offset,c=o?n.focus.offset:n.anchor.offset;Fr&&!n.isCollapsed()&&R(i)&&a.anchorNode!==null&&i.getTextContent().slice(0,s)+r+i.getTextContent().slice(s+c)===bl(a.anchorNode)||U(t,Ca,r);let l=r.length;Pr&&l>1&&e.inputType===`insertCompositionText`&&!t.isComposing()&&(n.anchor.offset-=l),Br&&t.isComposing()&&(no=0,al(null))}else xl(!1,t,r===null?void 0:r),fo&&=(Do(t,r||void 0),!1);return function(){Zs(),gi(ec())}(),!0}function To(e){let t=ec(),n=B();if(z(n)&&!t.isComposing()){let r=n.anchor,i=n.anchor.getNode();al(r.key),zl(Bo),(e.timeStamp<no+30||r.type===`element`||!n.isCollapsed()||i.getFormat()!==n.format||R(i)&&i.getStyle()!==n.style)&&U(t,Ca,$r)}return!0}function Eo(e){return Do(ec(),e.data),zl(Vo),!0}function Do(e,t){let n=e._compositionKey;if(al(null),n!==null&&t!=null){if(t===``){let t=sl(n),r=el(e.getElementByKey(n));if(r!==null&&r.nodeValue!==null&&R(t)){let n=Zl(Ul(e)),i=null,a=null;n!==null&&n.anchorNode===r&&(i=n.anchorOffset,a=n.focusOffset),Sl(t,r.nodeValue,i,a,!0)}return}if(t[t.length-1]===`
|
|
@@ -48,13 +48,13 @@ https://github.com/highlightjs/highlight.js/issues/2277`),i=e,r=t),n===void 0&&(
|
|
|
48
48
|
`)}function yE(e){return/^\+\d+$/.test(e)?`text-emerald-700`:/^-\d+$/.test(e)?`text-rose-700`:`text-stone-500`}function bE(e){let t=e.split(`·`).map(e=>e.trim()).filter(e=>/^\+\d+$/.test(e)||/^-\d+$/.test(e));return t.length===0?null:(0,N.jsx)(`div`,{className:`flex shrink-0 items-center gap-x-1 whitespace-nowrap text-[10px] font-medium uppercase tracking-[0.08em]`,children:t.map((e,t)=>(0,N.jsxs)(P.Fragment,{children:[t>0?(0,N.jsx)(`span`,{className:`text-stone-300`,children:`·`}):null,(0,N.jsx)(`span`,{className:F(yE(e)),children:e})]},`${e}-${t}`))})}function xE(e){return{path:e.path,label:e.path.split(`/`).filter(Boolean).pop()??e.path,viewMode:e.display===`diff`?`diff`:`preview`,...e.rawText?{rawText:e.rawText}:{},...e.beforeText?{beforeText:e.beforeText}:{},...e.afterText?{afterText:e.afterText}:{},...e.patchText?{patchText:e.patchText}:{},...typeof e.oldStartLine==`number`?{oldStartLine:e.oldStartLine}:{},...typeof e.newStartLine==`number`?{newStartLine:e.newStartLine}:{},fullLines:e.fullLines??e.lines}}function SE({children:e,contentVersion:t,resetKey:n,className:r,scrollKind:i}){let a=(0,P.useRef)(null),{onScroll:o}=WT({scrollRef:a,resetKey:n,isLoading:!1,hasContent:!0,contentVersion:t,stickyThresholdPx:20});return(0,N.jsx)(`div`,{ref:a,onScroll:o,"data-file-scroll-kind":i,className:F(`overflow-y-auto bg-white custom-scrollbar-amber`,r),children:e})}function CE({block:e,showPathRow:t,isFirst:n,onFileOpen:r}){let{Tooltip:i,TooltipContent:a,TooltipProvider:o,TooltipTrigger:s}=sr,c=_E(e),l=t||!!e.caption;return(0,N.jsxs)(`section`,{className:F(`overflow-hidden bg-white`,!n&&`border-t border-stone-200/80`),children:[l?(0,N.jsxs)(`div`,{className:F(`flex items-center justify-between gap-4 border-b border-stone-200/80 px-4 text-stone-700`,t?`py-2`:`py-1.5`),children:[(0,N.jsx)(`div`,{className:`min-w-0 flex-1`,children:t?(0,N.jsx)(o,{delayDuration:250,children:(0,N.jsxs)(i,{children:[(0,N.jsx)(s,{asChild:!0,children:(0,N.jsx)(`button`,{type:`button`,onClick:()=>{r&&r(xE(e))},className:F(`w-full truncate whitespace-nowrap text-left font-mono text-[12px] font-medium text-stone-700`,r&&`transition-colors hover:text-amber-900 hover:underline`),title:e.path,children:e.path})}),(0,N.jsx)(a,{side:`top`,className:`max-w-[420px] text-xs font-mono break-all`,children:e.path})]})}):null}),e.caption?bE(e.caption):null]}):null,e.lines.length>0?(0,N.jsx)(SE,{resetKey:`block:${e.key}`,contentVersion:vE(e),className:`max-h-72`,scrollKind:`block`,children:(0,N.jsx)(gE,{block:e})}):e.rawText?(0,N.jsx)(SE,{resetKey:`raw:${e.key}`,contentVersion:e.rawText,className:`max-h-72`,scrollKind:`raw`,children:(0,N.jsx)(`div`,{className:`overflow-x-auto custom-scrollbar-amber`,children:(0,N.jsx)(`pre`,{className:`min-w-max whitespace-pre bg-white px-4 py-2 font-mono text-[11px] leading-5 text-amber-950/80`,children:e.rawText})})}):null,e.truncated&&!c?(0,N.jsx)(`div`,{className:`border-t border-stone-200/85 bg-stone-50 px-4 py-2 text-[10px] text-stone-500`,children:`Showing a shortened diff preview.`}):null]})}function wE({card:e,className:t,onFileOpen:n}){let r=e.fileOperation?.blocks??[],i=e.output?.trim()??``;return r.length===0&&!i?null:(0,N.jsxs)(`div`,{className:F(`overflow-hidden bg-white`,t),children:[r.map((e,t)=>(0,N.jsx)(CE,{block:e,showPathRow:!0,isFirst:t===0,onFileOpen:n},e.key)),i?(0,N.jsx)(SE,{resetKey:`output:${e.toolName}:${e.summary??`none`}`,contentVersion:i,className:F(`max-h-56`,r.length>0&&`border-t border-stone-200/80`),scrollKind:`output`,children:(0,N.jsx)(`div`,{className:`overflow-x-auto custom-scrollbar-amber`,children:(0,N.jsx)(`pre`,{className:`min-w-max whitespace-pre bg-white px-4 py-2 font-mono text-[11px] leading-5 text-amber-950/80`,children:i})})}):null]})}var TE=200,EE=RegExp(`\x1B\\[[0-?]*[ -/]*[@-~]`,`g`);function DE(e){return typeof e==`string`&&e.length>0?e:null}function OE(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function kE(e){return e.replace(EE,``)}function AE(e){return`command`in e||`workingDir`in e||`exitCode`in e||`durationMs`in e||`stdout`in e||`stderr`in e||`aggregated_output`in e||`combinedOutput`in e}function jE(e){let t=DE(e.aggregated_output)??DE(e.combinedOutput)??DE(e.output);if(t)return t;let n=DE(e.stdout),r=DE(e.stderr);return!n&&!r?null:[n,r].filter(e=>!!e).join(`
|
|
49
49
|
`)}function ME(e,t){if(OE(t)){let e=jE(t);if(e)return kE(e);if(AE(t))return``}if(!e)return``;let n=e.trim();if(!n.startsWith(`{`))return kE(e);try{let t=JSON.parse(n);if(!OE(t))return kE(e);let r=jE(t);return r?kE(r):AE(t)?``:kE(e)}catch{return kE(e)}}function NE(e){return e===`write_file`||e===`edit_file`}function PE({canExpand:e,isRunning:t,autoExpandWhileRunning:n=!0,expandOnError:r=!1,statusTone:i}){let[a,o]=(0,P.useState)(!1),[s,c]=(0,P.useState)(!1),l=(0,P.useRef)(null),u=(0,P.useRef)(t),d=(0,P.useRef)(!0);return(0,P.useEffect)(()=>()=>{l.current!==null&&window.clearTimeout(l.current)},[]),(0,P.useEffect)(()=>{if(r&&i===`error`&&e&&!s){l.current!==null&&(window.clearTimeout(l.current),l.current=null),o(!0),u.current=t,d.current=!1;return}n&&t&&e&&!s&&!a&&(d.current||!u.current)&&(l.current=window.setTimeout(()=>{o(!0),l.current=null},TE)),t||(l.current!==null&&(window.clearTimeout(l.current),l.current=null),u.current&&!s&&o(!1)),u.current=t,d.current=!1},[n,e,r,a,s,t,i]),{expanded:a,onToggle:()=>{e&&(l.current!==null&&(window.clearTimeout(l.current),l.current=null),o(e=>!e),c(!0))}}}function FE({label:e,tone:t,children:n}){let r={input:{shell:`border-stone-200/80 bg-stone-50/90`,header:`border-stone-200/80 bg-stone-100/85 text-stone-500`,dot:`bg-stone-400/80`,body:`text-stone-700`},output:{shell:`border-amber-200/70 bg-white/90`,header:`border-amber-200/70 bg-amber-50/90 text-amber-700`,dot:`bg-amber-500/80`,body:`text-amber-950/80`},error:{shell:`border-rose-200/80 bg-rose-50/85`,header:`border-rose-200/80 bg-rose-100/80 text-rose-700`,dot:`bg-rose-500/80`,body:`text-rose-950/85`}}[t];return(0,N.jsxs)(`section`,{className:F(`overflow-hidden rounded-md border shadow-[inset_0_1px_0_rgba(255,255,255,0.45)]`,r.shell),children:[(0,N.jsxs)(`div`,{className:F(`flex items-center gap-2 border-b px-3 py-2 text-[10px] font-semibold uppercase tracking-[0.16em]`,r.header),children:[(0,N.jsx)(`span`,{className:F(`h-1.5 w-1.5 rounded-full`,r.dot)}),(0,N.jsx)(`span`,{children:e})]}),(0,N.jsx)(`div`,{className:`w-full overflow-hidden`,children:(0,N.jsx)(`pre`,{className:F(`w-full max-w-full min-w-0 max-h-64 overflow-x-auto overflow-y-auto px-3 py-2.5 font-mono text-[12px] leading-relaxed whitespace-pre custom-scrollbar-amber`,r.body),children:n})})]})}function IE({card:e}){let t=ME(e.output,e.outputData),n=e.statusTone===`running`,r=!!(e.summary?.trim()||t.trim().length>0),{expanded:i,onToggle:a}=PE({canExpand:t.trim().length>0||n,isRunning:n,autoExpandWhileRunning:!1,expandOnError:r,statusTone:e.statusTone}),o=e.summary?.replace(/^(command|path|args|query|input):\s*/i,``);return(0,N.jsxs)(qT,{children:[(0,N.jsx)(QT,{card:e,icon:ln,expanded:i,canExpand:t.trim().length>0||n,onToggle:a}),i&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`div`,{className:`px-3 pb-2 font-mono w-full max-h-48 overflow-y-auto custom-scrollbar-amber min-h-0 text-[12px]`,children:(0,N.jsxs)(`div`,{className:`flex items-start gap-2 leading-relaxed`,children:[(0,N.jsx)(`span`,{className:`text-amber-500/50 font-medium shrink-0 select-none mt-[1px]`,children:`$`}),(0,N.jsx)(`div`,{className:`flex-1 min-w-0`,children:o?(0,N.jsxs)(`div`,{className:`text-amber-950/80 break-words whitespace-pre-wrap tracking-tight font-medium inline-block`,children:[o,n&&!t&&(0,N.jsx)(`span`,{className:`inline-block w-1.5 h-3 ml-1 bg-amber-500/60 animate-pulse align-middle`})]}):(0,N.jsx)(`div`,{className:`h-3 w-32 bg-amber-200/30 rounded animate-pulse mt-2`})})]})}),t&&(0,N.jsx)(JT,{children:(0,N.jsxs)(`pre`,{className:`font-mono text-[12px] text-amber-950/70 whitespace-pre-wrap break-all w-full max-w-full max-h-64 overflow-y-auto overflow-x-hidden min-w-0 custom-scrollbar-amber leading-relaxed px-0`,children:[t,n&&(0,N.jsx)(`span`,{className:`inline-block w-1.5 h-3 ml-1 bg-amber-500/60 animate-pulse align-middle`})]})})]})]})}function LE({card:e,onFileOpen:t}){let n=e.output?.trim()??``,r=e.statusTone===`running`,i=!!e.fileOperation?.blocks.length,a=i||!!n,o=e.fileOperation?.blocks??[],s=o.reduce((e,t)=>e+t.lines.length,0),c=o.reduce((e,t)=>t.rawText?e+t.rawText.length:e+t.lines.reduce((e,t)=>e+t.text.length+1,0),0),l=NE(e.toolName)&&!(r&&e.toolName===`write_file`&&(s>24||c>1200)),{expanded:u,onToggle:d}=PE({canExpand:a||r,isRunning:r,autoExpandWhileRunning:l,expandOnError:a,statusTone:e.statusTone});return(0,N.jsxs)(qT,{children:[(0,N.jsx)(QT,{card:e,icon:e.toolName===`edit_file`||e.toolName===`write_file`||e.toolName===`apply_patch`||e.toolName===`file_change`?Lt:Kt,expanded:u,canExpand:a||r,hideSummary:u&&i,onToggle:d}),u&&a&&(0,N.jsx)(JT,{className:`border-t border-amber-200/20 bg-transparent px-0 pt-0 pb-0`,children:(0,N.jsx)(wE,{card:e,onFileOpen:t})})]})}function RE({card:e}){let t=e.statusTone===`running`,n=e.output?.trim()??``,{expanded:r,onToggle:i}=PE({canExpand:!!n||t,isRunning:t,autoExpandWhileRunning:!1,statusTone:e.statusTone});return(0,N.jsxs)(qT,{children:[(0,N.jsx)(QT,{card:e,icon:Oe,expanded:r,canExpand:!!n||t,onToggle:i}),r&&n&&(0,N.jsx)(JT,{children:(0,N.jsx)(`pre`,{className:`font-mono text-[12px] text-amber-950/70 whitespace-pre-wrap break-all w-full max-w-full max-h-64 overflow-y-auto overflow-x-hidden min-w-0 custom-scrollbar-amber leading-relaxed`,children:n})})]})}function zE({card:e,onToolAction:t,renderToolAgent:n}){let r=e.input?.trim()??``,i=e.output?.trim()??``,a=e.statusTone===`running`,o=r.length>0,s=i.length>0,c=o||s,l=e.inputLabel?.trim()||`Input`,u=e.outputLabel?.trim()||`Output`,{expanded:d,onToggle:f}=PE({canExpand:c||a,isRunning:a,autoExpandWhileRunning:!1,statusTone:e.statusTone});return(0,N.jsxs)(qT,{children:[(0,N.jsx)(QT,{card:e,icon:et,expanded:d,canExpand:c||a,actionSlot:e.agentId||e.action&&t?(0,N.jsxs)(N.Fragment,{children:[e.agentId&&n?n(e.agentId):null,e.action&&t?(0,N.jsx)($T,{action:e.action,onAction:t}):null]}):void 0,onToggle:f}),d&&c&&(0,N.jsxs)(JT,{className:`bg-transparent px-2.5 py-2.5`,children:[o&&(0,N.jsx)(FE,{label:l,tone:`input`,children:r}),o&&s&&(0,N.jsx)(`div`,{className:`h-2`}),s&&(0,N.jsx)(FE,{label:u,tone:e.statusTone===`error`?`error`:`output`,children:i})]})]})}function BE(e){let t=e.toLowerCase();return t===`exec`||t===`exec_command`||t===`execute_command`||t===`command_execution`||t===`bash`||t===`shell`||t.includes(`run_`)}function VE(e){let t=e.toLowerCase();return t===`read_file`||t===`write_file`||t===`edit_file`||t===`apply_patch`||t===`file_change`}function HE(e){let t=e.toLowerCase();return t===`grep_search`||t===`find_files`||t.includes(`search`)}function UE({card:e,onToolAction:t,onFileOpen:n,renderToolAgent:r}){return BE(e.toolName)?(0,N.jsx)(IE,{card:e}):VE(e.toolName)?(0,N.jsx)(LE,{card:e,onFileOpen:n}):HE(e.toolName)?(0,N.jsx)(RE,{card:e}):(0,N.jsx)(zE,{card:e,onToolAction:t,renderToolAgent:r})}function WE(e){return(0,N.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-gray-50 px-2.5 py-2 text-xs text-gray-600`,children:[(0,N.jsxs)(`div`,{className:`font-semibold text-gray-700`,children:[e.label,`: `,e.rawType]}),e.text?(0,N.jsx)(`pre`,{className:`mt-1 whitespace-pre-wrap break-words text-[11px] text-gray-500`,children:e.text}):null]})}var GE=(0,P.memo)(function(e){let{message:t,texts:n,onToolAction:r,onFileOpen:i,renderToolAgent:a}=e,{role:o}=t,s=o===`user`,c=t.status===`pending`||t.status===`streaming`;return(0,N.jsx)(`div`,{className:F(`inline-block w-fit max-w-full rounded-2xl border px-4 shadow-sm`,s?`border-primary bg-primary py-3 text-white`:o===`assistant`?`border-gray-200 bg-white pb-3 pt-4 text-gray-900`:`border-orange-200/80 bg-orange-50/70 py-3 text-gray-900`),children:(0,N.jsx)(`div`,{className:`space-y-2`,children:t.parts.map((e,l)=>{let{type:u}=e;return u===`markdown`?(0,N.jsx)(aT,{text:e.text,role:o,texts:n,onFileOpen:i},`markdown-${l}`):u===`inline-content`?(0,N.jsx)(lT,{segments:e.segments,role:o,texts:n,onFileOpen:i},`inline-content-${l}`):u===`reasoning`?(0,N.jsx)(KT,{label:e.label,text:e.text,isUser:s,isInProgress:c&&l===t.parts.length-1},`reasoning-${l}`):u===`tool-card`?(0,N.jsx)(`div`,{className:`mt-0.5`,children:(0,N.jsx)(UE,{card:e.card,onToolAction:r,onFileOpen:i,renderToolAgent:a})},`tool-${l}`):u===`file`?(0,N.jsx)(zT,{file:e.file,isUser:s,texts:n},`file-${l}`):u===`unknown`?(0,N.jsx)(WE,{label:e.label,rawType:e.rawType,text:e.text},`unknown-${l}`):null})})})});function KE(e){return(0,N.jsxs)(`div`,{className:F(`px-1 text-[11px] leading-4 text-gray-400`,e.isUser?`text-right`:`text-left`),children:[e.roleLabel,` · `,e.timestampLabel]})}function qE({message:e,texts:t}){let n=(0,P.useMemo)(()=>e.parts.map(e=>e.type===`markdown`||e.type===`unknown`?e.text:``).filter(e=>!!e&&e.trim().length>0).join(`
|
|
50
50
|
|
|
51
|
-
`),[e.parts]),{copied:r,copy:i}=tw({text:n});return n?(0,N.jsx)(`button`,{type:`button`,onClick:()=>void i(),className:`text-gray-400 hover:text-gray-600 transition-colors p-1 rounded-md hover:bg-gray-100 flex items-center justify-center`,"aria-label":r?t.copiedMessageLabel:t.copyMessageLabel,title:r?t.copiedMessageLabel:t.copyMessageLabel,children:r?(0,N.jsx)(Be,{className:`h-3.5 w-3.5`}):(0,N.jsx)(Rt,{className:`h-3.5 w-3.5`})}):null}var JE=/\u200B|\u200C|\u200D|\u2060|\uFEFF/g;function YE(e){let t=e.trim();return t?t.replace(JE,``).trim().length>0:!1}function XE(e){return e.parts.some(e=>e.type===`markdown`||e.type===`reasoning`?YE(e.text):!0)}function ZE(){return(0,N.jsx)(`div`,{className:`flex items-center gap-2 px-1 py-0.5 text-[11px] text-gray-400`,children:(0,N.jsxs)(`div`,{className:`flex space-x-1 items-center h-full`,children:[(0,N.jsx)(`div`,{className:`h-1.5 w-1.5 rounded-full bg-gray-400 animate-pulse`}),(0,N.jsx)(`div`,{className:`h-1.5 w-1.5 rounded-full bg-gray-400 animate-pulse [animation-delay:200ms]`}),(0,N.jsx)(`div`,{className:`h-1.5 w-1.5 rounded-full bg-gray-400 animate-pulse [animation-delay:400ms]`})]})})}function QE(e){let t=e.messages.filter(XE),n=t.some(e=>e.role===`assistant`&&(e.status===`streaming`||e.status===`pending`));return(0,N.jsxs)(`div`,{className:F(`space-y-5`,e.className),children:[t.map(t=>{let n=t.role===`user`,r=!n&&(t.status===`streaming`||t.status===`pending`);return(0,N.jsxs)(`div`,{className:F(`flex gap-3`,n?`justify-end`:`justify-start`),children:[n?null:(0,N.jsx)(mm,{role:t.role}),(0,N.jsxs)(`div`,{className:F(`w-fit max-w-[92%] space-y-2`,n&&`flex flex-col items-end`),children:[(0,N.jsx)(GE,{message:t,texts:e.texts,onToolAction:e.onToolAction,onFileOpen:e.onFileOpen,renderToolAgent:e.renderToolAgent}),(0,N.jsx)(`div`,{className:F(`flex items-center gap-2`,n&&`justify-end`),children:r?(0,N.jsx)(ZE,{}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(KE,{roleLabel:t.roleLabel,timestampLabel:t.timestampLabel,isUser:n}),n?null:(0,N.jsx)(qE,{message:t,texts:e.texts})]})})]}),n?(0,N.jsx)(mm,{role:t.role}):null]},t.id)}),e.isSending&&!n?(0,N.jsxs)(`div`,{className:`flex justify-start gap-3`,children:[(0,N.jsx)(mm,{role:`assistant`}),(0,N.jsx)(`div`,{className:`rounded-2xl border border-gray-200 bg-white px-4 py-3 text-sm text-gray-500 shadow-sm`,children:e.texts.typingLabel})]}):null]})}var $E=function(e){return e.EndpointReady=`endpoint.ready`,e.EndpointError=`endpoint.error`,e.MessageRequest=`message.request`,e.MessageStreamRequest=`message.stream-request`,e.MessageSent=`message.sent`,e.MessageAccepted=`message.accepted`,e.MessageIncoming=`message.incoming`,e.MessageCompleted=`message.completed`,e.MessageFailed=`message.failed`,e.MessageAbort=`message.abort`,e.MessageTextStart=`message.text-start`,e.MessageTextDelta=`message.text-delta`,e.MessageTextEnd=`message.text-end`,e.MessageReasoningStart=`message.reasoning-start`,e.MessageReasoningDelta=`message.reasoning-delta`,e.MessageReasoningEnd=`message.reasoning-end`,e.MessageToolCallStart=`message.tool-call-start`,e.MessageToolCallArgs=`message.tool-call-args`,e.MessageToolCallArgsDelta=`message.tool-call-args-delta`,e.MessageToolCallEnd=`message.tool-call-end`,e.MessageToolCallResult=`message.tool-call-result`,e.MessageRead=`message.read`,e.MessageDelivered=`message.delivered`,e.MessageRecalled=`message.recalled`,e.MessageReaction=`message.reaction`,e.RunStarted=`run.started`,e.RunFinished=`run.finished`,e.RunError=`run.error`,e.RunMetadata=`run.metadata`,e.TypingStart=`typing.start`,e.TypingEnd=`typing.end`,e.PresenceUpdated=`presence.updated`,e}({}),eD=/\[\[\s*reply_to_current\s*\]\]/gi,tD=/\[\[\s*reply_to\s*:\s*([^\]]+?)\s*\]\]/i;function nD(e){if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0}function rD(e,t){let n=e,r;eD.test(n)&&(r=nD(t),n=n.replace(eD,``).trim());let i=n.match(tD)?.[1];return i&&(r=nD(i),n=n.replace(tD,``).trim()),r?{content:n,replyTo:r}:{content:n}}function iD(e,t=e.id){if(e.role!==`assistant`)return{...e,parts:[...e.parts],metadata:e.metadata?{...e.metadata}:void 0};let n=e.parts.findIndex(e=>e.type===`text`),r=e.metadata?{...e.metadata}:void 0,i=nD(r?.reply_to);if(n<0)return{...e,parts:[...e.parts],metadata:r};let a=e.parts[n];if(!a||a.type!==`text`)return{...e,parts:[...e.parts],metadata:r};let{content:o,replyTo:s}=rD(a.text,t),c=s??i,l=e.parts.flatMap((e,t)=>t!==n||e.type!==`text`?[e]:o.length===0?[]:[{...e,text:o}]);return c?{...e,parts:l,metadata:{...r,reply_to:c}}:{...e,parts:l,metadata:r}}function aD(e){return{...e,parts:[...e.parts],metadata:e.metadata?{...e.metadata}:void 0}}function oD(e){return aD(iD(e))}function sD(e){let t=e.error?.trim();return{code:`runtime-error`,message:t&&t.length>0?t:`Agent run failed.`,details:{sessionId:e.sessionId,messageId:e.messageId,threadId:e.threadId,runId:e.runId}}}function cD(e,t){return t.trim()?e.id.startsWith(`tool-`)?!0:e.parts.some(e=>e.type===`tool-invocation`):!1}function lD(e,t,n){for(let[r,i]of e)i===t&&e.set(r,n)}function uD(e,t,n){for(let[r,i]of e)i===n&&(e.delete(r),t.delete(r))}function dD(e,t){for(let n=e.length-1;n>=0;--n){let r=e[n];if(r.type===`tool-invocation`&&r.toolCallId===t)return r}return null}function fD(e,t){return dD(e,t)?.toolName??null}function pD(e,t){let n=[...e];for(let e=n.length-1;e>=0;--e){let r=n[e];if(r.type===`tool-invocation`&&r.toolCallId===t.toolCallId)return n[e]={...r,...t},n}return n.push(t),n}var mD=`assistant`,hD=class{messages=[];streamingMessage=null;error=null;activeRun=null;listeners=new Set;toolCallMessageIdByCallId=new Map;toolCallArgsRawByCallId=new Map;lastSettledRunId=null;snapshotCache=null;snapshotVersion=-1;stateVersion=0;getSnapshot=()=>{if(this.snapshotCache&&this.snapshotVersion===this.stateVersion)return this.snapshotCache;let e={messages:this.messages,streamingMessage:this.streamingMessage,error:this.error?{...this.error,details:this.error.details?{...this.error.details}:void 0}:null,activeRun:this.activeRun?{...this.activeRun}:null};return this.snapshotCache=e,this.snapshotVersion=this.stateVersion,e};subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e));reset=()=>{this.messages.length===0&&!this.streamingMessage&&!this.error&&!this.activeRun&&this.toolCallMessageIdByCallId.size===0&&this.toolCallArgsRawByCallId.size===0||(this.messages=[],this.streamingMessage=null,this.error=null,this.activeRun=null,this.toolCallMessageIdByCallId.clear(),this.toolCallArgsRawByCallId.clear(),this.lastSettledRunId=null,this.stateVersion+=1,this.notifyListeners())};hydrate=e=>{this.messages=e.messages.map(e=>oD(e)),this.streamingMessage=null,this.error=null,this.activeRun=e.activeRun?{...e.activeRun,sessionId:e.activeRun.sessionId??e.sessionId,abortDisabledReason:e.activeRun.abortDisabledReason??null}:null,this.toolCallMessageIdByCallId.clear(),this.toolCallArgsRawByCallId.clear(),this.lastSettledRunId=null,this.stateVersion+=1,this.notifyListeners()};dispatch=e=>this.dispatchBatch([e]);dispatchBatch=async e=>{if(!e.length)return;let t=this.stateVersion;e.forEach(this.applyEvent),this.stateVersion!==t&&this.notifyListeners()};applyEvent=e=>{switch(e.type){case $E.MessageSent:this.handleMessageSent(e.payload);break;case $E.MessageAbort:this.handleMessageAbort(e.payload);break;case $E.MessageTextStart:this.handleMessageTextStart(e.payload);break;case $E.MessageTextDelta:this.handleMessageTextDelta(e.payload);break;case $E.MessageTextEnd:this.handleMessageTextEnd(e.payload);break;case $E.MessageReasoningStart:this.handleMessageReasoningStart(e.payload);break;case $E.MessageReasoningDelta:this.handleMessageReasoningDelta(e.payload);break;case $E.MessageReasoningEnd:this.handleMessageReasoningEnd(e.payload);break;case $E.MessageToolCallStart:this.handleMessageToolCallStart(e.payload);break;case $E.MessageToolCallArgs:this.handleMessageToolCallArgs(e.payload);break;case $E.MessageToolCallArgsDelta:this.handleMessageToolCallArgsDelta(e.payload);break;case $E.MessageToolCallEnd:this.handleMessageToolCallEnd(e.payload);break;case $E.MessageToolCallResult:this.handleMessageToolCallResult(e.payload);break;case $E.RunStarted:this.handleRunStarted(e.payload);break;case $E.RunFinished:this.handleRunFinished(e.payload);break;case $E.RunError:this.handleRunError(e.payload);break;case $E.RunMetadata:this.handleRunMetadata(e.payload);break;case $E.EndpointError:this.handleEndpointError(e.payload);break;default:break}};handleMessageSent=e=>{this.upsertMessage(e.message),this.setError(null)};handleMessageAbort=e=>{let t=e.messageId?.trim();if(this.clearActiveRun(),this.setError(null),this.streamingMessage&&(!t||this.streamingMessage.id===t)){let e=this.streamingMessage.id;this.upsertMessage({...this.streamingMessage,status:`final`}),this.replaceStreamingMessage(null),t?uD(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,t):uD(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,e)}};handleMessageTextStart=e=>{this.ensureStreamingMessage(e.sessionId,e.messageId,`streaming`),this.setError(null)};handleMessageTextDelta=e=>{if(!e.delta)return;let t=this.ensureStreamingMessage(e.sessionId,e.messageId,`streaming`),n=[...t.parts],r=n[n.length-1];r?.type===`text`?n[n.length-1]={type:`text`,text:`${r.text}${e.delta}`}:n.push({type:`text`,text:e.delta}),this.replaceStreamingMessage({...t,parts:n,status:`streaming`})};handleMessageTextEnd=e=>{this.streamingMessage?.id===e.messageId&&this.streamingMessage.status===`streaming`&&this.replaceStreamingMessage({...this.streamingMessage,status:`pending`})};handleMessageReasoningStart=e=>{this.ensureStreamingMessage(e.sessionId,e.messageId,`streaming`)};handleMessageReasoningDelta=e=>{if(!e.delta)return;let t=this.ensureStreamingMessage(e.sessionId,e.messageId,`streaming`),n=[...t.parts],r=n[n.length-1];r?.type===`reasoning`?n[n.length-1]={type:`reasoning`,text:`${r.text}${e.delta}`}:n.push({type:`reasoning`,text:e.delta}),this.replaceStreamingMessage({...t,parts:n,status:`streaming`})};handleMessageReasoningEnd=e=>{this.streamingMessage?.id,e.messageId};handleMessageToolCallStart=e=>{let t=this.resolveToolCallTargetMessage(e.sessionId,e.toolCallId,e.messageId);this.toolCallArgsRawByCallId.set(e.toolCallId,``);let n=pD(t.parts,{type:`tool-invocation`,toolCallId:e.toolCallId,toolName:e.toolName,state:`partial-call`,args:``});this.replaceStreamingMessage({...t,parts:n,status:`streaming`}),this.setError(null)};handleMessageToolCallArgs=e=>{this.toolCallArgsRawByCallId.set(e.toolCallId,e.args),this.applyToolCallArgs(e.sessionId,e.toolCallId,e.args)};handleMessageToolCallArgsDelta=e=>{let t=`${this.toolCallArgsRawByCallId.get(e.toolCallId)??``}${e.delta}`;this.toolCallArgsRawByCallId.set(e.toolCallId,t),this.applyToolCallArgs(e.sessionId,e.toolCallId,t,e.messageId)};handleMessageToolCallEnd=e=>{let t=this.resolveToolCallTargetMessage(e.sessionId,e.toolCallId),n=this.toolCallArgsRawByCallId.get(e.toolCallId)??``,r=pD(t.parts,{type:`tool-invocation`,toolCallId:e.toolCallId,toolName:fD(t.parts,e.toolCallId)??`unknown`,state:`call`,args:n});this.replaceStreamingMessage({...t,parts:r,status:`streaming`})};handleMessageToolCallResult=e=>{if(!this.updateMessageContainingToolCall(e.toolCallId,(t,n)=>{let r={type:`tool-invocation`,toolCallId:e.toolCallId,toolName:n.toolName,state:`result`,args:n.args,result:e.content};return pD(t.parts,r)})){let t=this.resolveToolCallTargetMessage(e.sessionId,e.toolCallId),n=pD(t.parts,{type:`tool-invocation`,toolCallId:e.toolCallId,toolName:`unknown`,state:`result`,result:e.content});this.replaceStreamingMessage({...t,parts:n,status:`streaming`})}};handleRunStarted=e=>{this.isSettledRunId(e.runId)||(this.setError(null),this.activeRun={runId:e.runId??null,sessionId:e.sessionId},this.stateVersion+=1)};handleRunFinished=e=>{this.markRunAsSettled(e.runId??this.activeRun?.runId??null),this.settleStreamingMessage(`final`),this.setError(null),this.clearActiveRun()};handleRunError=e=>{this.markRunAsSettled(e.runId??this.activeRun?.runId??null),this.settleStreamingMessage(`error`),this.setError(sD(e)),this.clearActiveRun()};handleRunMetadata=e=>{let t=e.metadata;if(t?.kind===`ready`){let e=t;if(this.isSettledRunId(e.runId))return;this.activeRun={runId:e.runId??this.activeRun?.runId??null,sessionId:e.sessionId??this.activeRun?.sessionId,abortDisabledReason:e.supportsAbort===!1?e.abortDisabledReason??`Unsupported`:null},this.stateVersion+=1}else t?.kind===`final`&&(this.markRunAsSettled(e.runId??this.activeRun?.runId??null),this.clearActiveRun())};handleEndpointError=e=>{if(e.code===`abort-error`){this.handleMessageAbort({sessionId:this.activeRun?.sessionId??this.streamingMessage?.sessionId??``,...this.streamingMessage?.id?{messageId:this.streamingMessage.id}:{}});return}this.settleStreamingMessage(`error`),this.clearActiveRun(),this.setError(e)};applyToolCallArgs=(e,t,n,r)=>{let i=this.resolveToolCallTargetMessage(e,t,r),a=fD(i.parts,t)??`unknown`,o=pD(i.parts,{type:`tool-invocation`,toolCallId:t,toolName:a,state:`partial-call`,args:n});this.replaceStreamingMessage({...i,parts:o,status:`streaming`})};ensureStreamingMessage=(e,t,n)=>{if(this.streamingMessage?.id===t){if(this.streamingMessage.status===n)return this.streamingMessage;let e={...this.streamingMessage,status:n};return this.replaceStreamingMessage(e),e}let r=this.messages.findIndex(e=>e.id===t);if(r>=0){let t=aD(this.messages[r]),i=[...this.messages];i.splice(r,1),this.messages=i,this.stateVersion+=1;let a={...t,sessionId:e,status:n};return this.replaceStreamingMessage(a),a}let i=this.streamingMessage;if(i&&i.id!==t&&i.sessionId===e&&cD(i,t)){let r={...i,id:t,sessionId:e,status:n};return lD(this.toolCallMessageIdByCallId,i.id,t),this.replaceStreamingMessage(r),r}let a={id:t,sessionId:e,role:mD,status:n,parts:[],timestamp:new Date().toISOString()};return this.replaceStreamingMessage(a),a};resolveToolCallTargetMessage=(e,t,n)=>{let r=n?.trim()||this.toolCallMessageIdByCallId.get(t)||this.streamingMessage?.id||`tool-${t}`;return this.toolCallMessageIdByCallId.set(t,r),this.ensureStreamingMessage(e,r,`streaming`)};updateMessageContainingToolCall=(e,t)=>{if(this.streamingMessage){let n=dD(this.streamingMessage.parts,e);if(n){let e=t(this.streamingMessage,n);return this.replaceStreamingMessage({...this.streamingMessage,parts:e}),!0}}for(let n=this.messages.length-1;n>=0;--n){let r=this.messages[n],i=dD(r.parts,e);if(!i)continue;let a=[...this.messages];return a[n]={...r,parts:t(r,i)},this.messages=a,this.stateVersion+=1,!0}return!1};upsertMessage=e=>{let t=oD(e),n=this.messages.findIndex(e=>e.id===t.id);if(n<0){this.messages=[...this.messages,t],this.stateVersion+=1;return}let r=[...this.messages];r[n]=t,this.messages=r,this.stateVersion+=1};replaceStreamingMessage=e=>{!e&&!this.streamingMessage||(this.streamingMessage=e?oD(e):null,this.stateVersion+=1)};setError=e=>{this.error?.code===e?.code&&this.error?.message===e?.message&&this.error?.details===e?.details&&this.error?.cause===e?.cause||(this.error=e?{...e,details:e.details?{...e.details}:void 0}:null,this.stateVersion+=1)};clearActiveRun=()=>{this.activeRun&&(this.activeRun=null,this.stateVersion+=1)};isSettledRunId=e=>!!e?.trim()&&e===this.lastSettledRunId;markRunAsSettled=e=>{this.lastSettledRunId=e?.trim()||null};settleStreamingMessage=e=>{if(!this.streamingMessage)return;let t={...this.streamingMessage,status:e};this.upsertMessage(t),this.replaceStreamingMessage(null),uD(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,t.id)};notifyListeners=()=>{let e=this.getSnapshot();for(let t of this.listeners)t(e)}},gD=16,_D=class{constructor(e){this.dispatchBatch=e,this.queue=[],this.flushTimerId=null,this.isFlushing=!1,this.isDisposed=!1,this.enqueue=e=>{this.isDisposed||(this.queue.push(e),this.scheduleFlush())},this.dispose=()=>{this.isDisposed=!0,this.flushTimerId!==null&&(window.clearTimeout(this.flushTimerId),this.flushTimerId=null),this.queue.length=0},this.scheduleFlush=()=>{this.flushTimerId!==null||this.isFlushing||this.queue.length===0||(this.flushTimerId=window.setTimeout(()=>{this.flushTimerId=null,this.flush()},gD))},this.flush=async()=>{if(!(this.isDisposed||this.isFlushing||this.queue.length===0)){this.isFlushing=!0;try{for(;this.queue.length>0;){let e=this.queue.splice(0);await this.dispatchBatch(e)}}finally{this.isFlushing=!1,this.scheduleFlush()}}}}};function vD(e,t){let n=e.dispatchBatch;return typeof n==`function`?n.call(e,t):t.reduce((t,n)=>t.then(()=>e.dispatch(n)),Promise.resolve())}function yD(e,t){let n=`payload`in e?e.payload:null;return!n||typeof n!=`object`||!(`sessionId`in n)||typeof n.sessionId!=`string`?!0:n.sessionId===t}function bD(e){return e.parts.some(e=>e.type===`text`||e.type===`rich-text`||e.type===`reasoning`?e.text.trim().length>0:!0)}function xD(e,t){if(typeof e==`string`){let n=e.trim();return n?{sessionId:t,message:{id:`user-${Date.now().toString(36)}`,sessionId:t,role:`user`,status:`final`,parts:[{type:`text`,text:n}],timestamp:new Date().toISOString()}}:null}return bD(e.message)?{...e,sessionId:e.sessionId,message:{...e.message,sessionId:e.message.sessionId||e.sessionId}}:null}function SD(e){let t=(0,P.useRef)();return(!t.current||t.current.sessionId!==e)&&(t.current={sessionId:e,manager:new hD}),t.current.manager}function CD({sessionId:e,client:t,manager:n}){let r=(0,P.useSyncExternalStore)(e=>n.subscribe(()=>e()),()=>n.getSnapshot(),()=>n.getSnapshot()),[i,a]=(0,P.useState)(!1);(0,P.useEffect)(()=>{a(!1)},[e]),(0,P.useEffect)(()=>{let r=new _D(e=>vD(n,e)),i=t.subscribe(t=>{yD(t,e)&&r.enqueue(t)});return()=>{i(),r.dispose(),t.stop()}},[t,n,e]);let o=r.streamingMessage?[...r.messages,r.streamingMessage]:r.messages,s=r.activeRun?.runId??null,c=!!r.activeRun;return{snapshot:r,visibleMessages:o,activeRunId:s,isRunning:c,isSending:i,send:async r=>{if(i||c)return;let o=xD(r,e);if(o){a(!0),await n.dispatch({type:$E.MessageSent,payload:{sessionId:e,message:o.message,metadata:o.metadata}});try{await t.send(o)}finally{a(!1)}}},abort:async()=>{r.activeRun&&await t.abort({sessionId:e})},streamRun:async()=>{await t.stop(),await t.stream({sessionId:e})}}}function wD(e){return e instanceof Error?e:Error(String(e))}function TD(e){return e.isHydrating||e.hydratedSessionId!==e.sessionId}function ED({sessionId:e,client:t,loadSeed:n}){let r=SD(e),i=CD({sessionId:e,client:t,manager:r}),[a,o]=(0,P.useState)(!0),[s,c]=(0,P.useState)(null),[l,u]=(0,P.useState)(null),d=(0,P.useRef)({requestId:0,controller:null}),f=(0,P.useCallback)(async()=>{d.current.controller?.abort();let i=new AbortController,a=d.current.requestId+1;d.current={requestId:a,controller:i},await t.stop(),r.reset(),c(null),o(!0);try{let s=await n(e,i.signal);if(i.signal.aborted||d.current.requestId!==a)return;r.hydrate({sessionId:e,messages:s.messages,activeRun:s.status===`running`?{runId:null,sessionId:e,abortDisabledReason:null}:null}),c(null),u(e),o(!1),t.stream({sessionId:e}).catch(e=>{d.current.requestId===a&&c(wD(e))})}catch(t){if(i.signal.aborted||d.current.requestId!==a)return;c(wD(t)),u(e),o(!1)}finally{d.current.controller===i&&(d.current.controller=null)}},[t,n,r,e]);return(0,P.useEffect)(()=>(f(),()=>{d.current.controller?.abort(),d.current.controller=null}),[f]),{...i,isHydrating:TD({sessionId:e,hydratedSessionId:l,isHydrating:a}),hydrateError:s}}var DD=200*1024*1024,OD=`application/octet-stream`;function kD(e){let t=e.type.trim().toLowerCase();return t.length>0?t:OD}function AD(e,t){let n=t.acceptedMimeTypes&&t.acceptedMimeTypes.length>0?new Set(t.acceptedMimeTypes.map(e=>e.trim().toLowerCase())):null,r=t.maxBytes??209715200,i=kD(e);return n&&!n.has(i)?{ok:!1,rejected:{fileName:e.name,mimeType:i,sizeBytes:e.size,reason:`unsupported-type`}}:e.size>r?{ok:!1,rejected:{fileName:e.name,mimeType:i,sizeBytes:e.size,reason:`too-large`}}:{ok:!0,mimeType:i}}function jD(e){let t=e.parts&&e.parts.length>0?e.parts.map(e=>structuredClone(e)):[...e.text?.trim()??``?[{type:`text`,text:e.text.trim()}]:[],...(e.attachments??[]).map(e=>({type:`file`,name:e.name,mimeType:e.mimeType,...e.assetUri?.trim()?{assetUri:e.assetUri.trim()}:{},...e.url?.trim()?{url:e.url.trim()}:{},...e.contentBase64?.trim()?{contentBase64:e.contentBase64.trim()}:{},sizeBytes:e.sizeBytes}))];if(t.length===0)return null;let n=e.timestamp??new Date().toISOString(),r=e.messageId??`user-${Date.now().toString(36)}`;return{sessionId:e.sessionId,message:{id:r,sessionId:e.sessionId,role:`user`,status:`final`,parts:t,timestamp:n,...e.metadata?{metadata:e.metadata}:{}},...e.metadata?{metadata:e.metadata}:{}}}async function MD(e,t){let n=[],r=[];for(let i of e){let e=AD(i,t);if(!e.ok){r.push(e.rejected);continue}n.push(i)}if(n.length===0)return{attachments:[],rejected:r};try{return{attachments:await t.uploadBatch(n),rejected:r}}catch{return r.push(...n.map(e=>({fileName:e.name,mimeType:kD(e),sizeBytes:e.size,reason:`read-failed`}))),{attachments:[],rejected:r}}}function ND(e){let t=e.modelLabel.trim(),n=e.providerLabel.trim();return n?`${n}/${t}`:t}function PD(e){let t=[];for(let n of[`off`,...e])t.includes(n)||t.push(n);return t}function FD(e){return!e.isModelOptionsLoading&&!e.isModelOptionsEmpty?null:e.isModelOptionsLoading?{tone:`neutral`,loading:!0}:{tone:`warning`,text:e.texts.noModelOptionsLabel,actionLabel:e.texts.configureProviderLabel,onAction:e.onGoToProviders}}function ID({modelOptions:e,recentModelValues:t,selectedModel:n,isModelOptionsLoading:r,hasModelOptions:i,onValueChange:a,texts:o}){let s=e.find(e=>e.value===n)??e[0],c=i?s?.value:void 0,l=new Set(t??[]),u=new Map(e.map(e=>[e.value,e])),d=(t??[]).map(e=>u.get(e)).filter(e=>!!e),f=e.filter(e=>!l.has(e.value)),p=d.length>0?[{key:`recent-models`,label:o.recentModelsLabel,options:d.map(e=>({value:e.value,label:ND(e)}))},{key:`all-models`,label:o.allModelsLabel,options:f.map(e=>({value:e.value,label:ND(e)}))}].filter(e=>e.options.length>0):void 0;return{key:`model`,value:c,placeholder:o.modelSelectPlaceholder,selectedLabel:s?ND(s):void 0,icon:`sparkles`,options:e.map(e=>({value:e.value,label:ND(e)})),groups:p,disabled:!i,loading:r,emptyLabel:o.modelNoOptionsLabel,onValueChange:a}}function LD(e){if(e.supportedLevels.length===0)return null;let t=PD(e.supportedLevels),n=t.includes(`off`)?`off`:t[0],r=e.selectedThinkingLevel&&t.includes(e.selectedThinkingLevel)&&e.selectedThinkingLevel||e.defaultThinkingLevel&&t.includes(e.defaultThinkingLevel)&&e.defaultThinkingLevel||n;return{key:`thinking`,value:r,placeholder:e.texts.thinkingLabels[r],selectedLabel:e.texts.thinkingLabels[r],icon:`brain`,options:t.map(t=>({value:t,label:e.texts.thinkingLabels[t]})),onValueChange:t=>e.onValueChange(t)}}var RD={exactSpec:1200,exactLabel:1150,prefixSpec:1e3,prefixLabel:950,prefixToken:900,containsSpec:800,containsLabel:760,containsDescription:500,subsequence:300,fallback:1};function zD(e){return(e??``).trim().toLowerCase()}function BD(e,t){if(!e||!t)return!1;let n=0;for(let r of t)if(r===e[n]&&(n+=1,n>=e.length))return!0;return!1}function VD(e,t){let n=zD(t);if(!n)return RD.fallback;let r=zD(e.key),i=zD(e.label||e.key),a=zD(`${e.descriptionZh??``} ${e.description??``}`),o=i.split(/[\s/_-]+/).filter(Boolean);return r===n?RD.exactSpec:i===n?RD.exactLabel:r.startsWith(n)?RD.prefixSpec:i.startsWith(n)?RD.prefixLabel:o.some(e=>e.startsWith(n))?RD.prefixToken:r.includes(n)?RD.containsSpec:i.includes(n)?RD.containsLabel:a.includes(n)?RD.containsDescription:BD(n,i)||BD(n,r)?RD.subsequence:0}function HD(e){return e>=RD.exactLabel?4:e>=RD.prefixToken?3:e>=RD.containsLabel?2:e>0?1:0}function UD(e){return new Map(e.map((e,t)=>[e,t]))}function WD(e,t){let n=UD(t),r=[],i=[];for(let t of e){if(n.has(t.key)){r.push(t);continue}i.push(t)}return r.sort((e,t)=>(n.get(e.key)??1/0)-(n.get(t.key)??1/0)),[...r,...i]}function GD(e,t,n,r=[]){let i=new Intl.Collator(void 0,{sensitivity:`base`,numeric:!0}),a=UD(r);return e.map((e,n)=>({record:e,order:n,score:VD(e,t)})).filter(e=>e.score>0).sort((e,t)=>{let n=HD(e.score),r=HD(t.score);if(r!==n)return r-n;let o=a.get(e.record.key)??1/0,s=a.get(t.record.key)??1/0;if(o!==s)return o-s;if(t.score!==e.score)return t.score-e.score;let c=(e.record.label||e.record.key).trim(),l=(t.record.label||t.record.key).trim(),u=i.compare(c,l);return u===0?e.order-t.order:u}).map(({record:e})=>({key:`skill:${e.key}`,title:e.label||e.key,subtitle:n.slashSkillSubtitle,description:(e.descriptionZh??e.description??``).trim()||n.noSkillDescription,detailLines:[`${n.slashSkillSpecLabel}: ${e.key}`,...e.scopeLabel?[`${n.slashSkillScopeLabel}: ${e.scopeLabel}`]:[]],value:e.key}))}function KD(e){return e.map(e=>({key:e.key,label:e.label,description:e.descriptionZh||e.description||``,badgeLabel:e.badgeLabel}))}function qD(e){let t=WD(e.skillRecords,e.recentSkillValues??[]),n=new Set(e.groupedRecentSkillValues??[]),r=KD(t.filter(e=>n.has(e.key))),i=KD(t.filter(e=>!n.has(e.key)));return{title:e.texts.title,searchPlaceholder:e.texts.searchPlaceholder,emptyLabel:e.texts.emptyLabel,loadingLabel:e.texts.loadingLabel,isLoading:e.isLoading,manageLabel:e.texts.manageLabel,manageHref:`/marketplace/skills`,options:KD(t),groups:r.length>0?[{key:`recent-skills`,label:e.texts.recentSkillsLabel,options:r},{key:`all-skills`,label:e.texts.allSkillsLabel,options:i}].filter(e=>e.options.length>0):void 0,selectedKeys:e.selectedSkills,onSelectedKeysChange:e.onSelectedKeysChange}}var JD=(0,P.createContext)(null);function YD({presenter:e,children:t}){return(0,N.jsx)(JD.Provider,{value:e,children:t})}function XD(){let e=(0,P.useContext)(JD);if(!e)throw Error(`usePresenter must be used inside ChatPresenterProvider`);return e}var ZD=`$`;function QD(e,t){if(t.length===0)return e;let n=e[e.length-1];return n?.type===`text`?[...e.slice(0,-1),{...n,text:n.text+t}]:[...e,{type:`text`,text:t}]}function $D(){return xp()}function eO(e){return Sp(e)}function tO(e){return Tp(e)}function nO(e){return Ep(e,`skill`)}function rO(e){return Ep(e,`file`)}function iO(e,t,n){let r=new Set(t),i=Np(e,e=>e.tokenKind===`skill`&&!r.has(e.tokenKey)),a=Ep(i,`skill`),o=new Map(n.map(e=>[e.ref,e])),s=t.filter(e=>!a.includes(e)).map(e=>yp({tokenKind:`skill`,tokenKey:e,label:o.get(e)?.name||e}));return s.length===0?i:Cp([...i,...s])}function aO(e,t){let n=new Set(t.map(e=>e.id));return Np(e,e=>e.tokenKind===`file`&&!n.has(e.tokenKey))}function oO(e,t){let n=new Set(rO(e));return t.filter(e=>n.has(e.id))}function sO(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[];for(let t of e){if(t.type===`text`){r=QD(r,t.text);continue}if(t.tokenKind===`skill`){r=QD(r,`${ZD}${t.tokenKey}`);continue}if(t.tokenKind!==`file`)continue;let e=n.get(t.tokenKey);e&&r.push({type:`file`,name:e.name,mimeType:e.mimeType,...e.assetUri?{assetUri:e.assetUri}:{},...e.url?{url:e.url}:{},...e.contentBase64?{contentBase64:e.contentBase64}:{},sizeBytes:e.sizeBytes})}return r}var cO={isProviderStateResolved:!1,composerNodes:$D(),attachments:[],draft:``,pendingSessionType:`native`,pendingProjectRoot:null,pendingProjectRootSessionKey:null,defaultSessionType:`native`,canStopGeneration:!1,stopDisabledReason:null,sendError:null,isSending:!1,modelOptions:[],selectedModel:``,selectedThinkingLevel:null,sessionTypeOptions:[],selectedSessionType:void 0,stopSupported:!1,stopReason:void 0,canEditSessionType:!1,sessionTypeUnavailable:!1,skillRecords:[],isSkillsLoading:!1,selectedSkills:[]},Q=C(e=>({snapshot:cO,setSnapshot:t=>e(e=>({snapshot:{...e.snapshot,...t}}))})),lO=class{constructor(e){this.options=e,this.read=()=>{let e=this.getStorage();if(!e)return[];try{return this.normalizeList(JSON.parse(e.getItem(this.options.storageKey)??`[]`))}catch{return[]}},this.remember=e=>{let t=this.normalizeValue(e);if(!t)return this.read();let n=[t,...this.read().filter(e=>e!==t)].slice(0,this.options.limit);return this.write(n),n},this.resolveVisible=e=>{let t=this.normalizeList(e.availableValues,1/0);if(t.length<=e.minAvailableCount)return[];let n=new Set(t),r=[],i=Math.max(1,e.limit??this.options.limit);for(let e of this.read())if(!(!n.has(e)||r.includes(e))&&(r.push(e),r.length>=i))break;return r},this.write=e=>{let t=this.getStorage();if(t)try{t.setItem(this.options.storageKey,JSON.stringify(this.normalizeList(e)))}catch{}},this.getStorage=()=>Object.prototype.hasOwnProperty.call(this.options,`storage`)?this.options.storage??null:typeof window>`u`?null:window.localStorage,this.normalizeList=(e,t=this.options.limit)=>{if(!Array.isArray(e))return[];let n=[];for(let r of e){let e=this.normalizeValue(r);if(!(!e||n.includes(e))&&(n.push(e),n.length>=t))break}return n},this.normalizeValue=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}}},uO=new lO({storageKey:`nextclaw.chat.recent-models`,limit:3}),dO=new lO({storageKey:`nextclaw.chat.recent-skills`,limit:5});function fO(e){return e.modelOptions.length>0}function pO(e){return!e.isProviderStateResolved&&!fO(e)}function mO(e){return e.isProviderStateResolved&&!fO(e)}function hO(e){return!1}function gO(e){let{hasSendableDraft:t,isRuntimeBlocked:n}=e;return n||!t}function _O(){return{off:o(`chatThinkingLevelOff`),minimal:o(`chatThinkingLevelMinimal`),low:o(`chatThinkingLevelLow`),medium:o(`chatThinkingLevelMedium`),high:o(`chatThinkingLevelHigh`),adaptive:o(`chatThinkingLevelAdaptive`),xhigh:o(`chatThinkingLevelXhigh`)}}function vO(e,t){return e.map(e=>({key:e.ref,label:e.name,scopeLabel:t[e.scope],description:e.description,descriptionZh:e.descriptionZh,badgeLabel:t[e.scope]}))}function yO(e){return e.map(e=>({value:e.value,modelLabel:e.modelLabel,providerLabel:e.providerLabel,thinkingCapability:e.thinkingCapability?{supported:e.thinkingCapability.supported,default:e.thinkingCapability.default??null}:null}))}function bO(e){return{skillScopeLabels:(0,P.useMemo)(()=>({builtin:o(`chatSkillScopeBuiltin`),project:o(`chatSkillScopeProject`),workspace:o(`chatSkillScopeWorkspace`)}),[e]),slashTexts:(0,P.useMemo)(()=>({slashSkillSubtitle:o(`chatSlashTypeSkill`),slashSkillSpecLabel:o(`chatSlashSkillSpec`),slashSkillScopeLabel:o(`chatSlashSkillScope`),noSkillDescription:o(`chatSkillsPickerNoDescription`)}),[e]),recentModelsLabel:o(`chatPickerRecentModels`),allModelsLabel:o(`chatPickerAllModels`),recentSkillsLabel:o(`chatPickerRecent`),allSkillsLabel:o(`chatPickerAllSkills`)}}function xO(e,t){let n=(0,P.useMemo)(()=>vO(e.skillRecords,t),[e.skillRecords,t]),r=(0,P.useMemo)(()=>yO(e.modelOptions),[e.modelOptions]);return{skillRecords:n,modelRecords:r,recentModelValues:uO.resolveVisible({availableValues:r.map(e=>e.value),minAvailableCount:5}),recentSkillValues:dO.resolveVisible({availableValues:n.map(e=>e.key),minAvailableCount:0}),recentSkillGroupValues:dO.resolveVisible({availableValues:n.map(e=>e.key),minAvailableCount:4})}}function SO(e){let{attachmentSupported:t,inputBarRef:n,presenter:r}=e,i=(0,P.useCallback)(e=>{if(e===`unsupported-type`){y.error(o(`chatInputAttachmentUnsupported`));return}if(e===`too-large`){y.error(o(`chatInputAttachmentTooLarge`).replace(`{maxMb}`,String(DD/(1024*1024))));return}y.error(o(`chatInputAttachmentReadFailed`))},[]),a=(0,P.useCallback)(async e=>{if(!t||e.length===0)return;let a=await MD(e,{uploadBatch:S});if(a.attachments.length>0){let e=r.chatInputManager.addAttachments?.(a.attachments)??[];e.length>0&&n.current?.insertFileTokens(e.map(e=>({tokenKey:e.id,label:e.name})))}a.rejected.length>0&&i(a.rejected[0].reason)},[t,n,r.chatInputManager,i]);return{handleFilesAdd:a,handleFileInputChange:(0,P.useCallback)(async e=>{let t=Array.from(e.target.files??[]);e.currentTarget.value=``,await a(t)},[a])}}function CO(e){let{allModelsLabel:t,hasModelOptions:n,isModelOptionsLoading:r,modelRecords:i,presenter:a,recentModelValues:s,recentModelsLabel:c,selectedModel:l,selectedThinkingLevel:u,thinkingSupportedLevels:d,thinkingDefaultLevel:f}=e;return[ID({modelOptions:i,recentModelValues:s,selectedModel:l,isModelOptionsLoading:r,hasModelOptions:n,onValueChange:a.chatInputManager.selectModel,texts:{modelSelectPlaceholder:o(`chatSelectModel`),modelNoOptionsLabel:o(`chatModelNoOptions`),recentModelsLabel:c,allModelsLabel:t}}),LD({supportedLevels:d,selectedThinkingLevel:u,defaultThinkingLevel:f,onValueChange:e=>a.chatInputManager.selectThinkingLevel(e),texts:{thinkingLabels:_O()}})].filter(e=>e!==null)}function wO(e){let{allSkillsLabel:t,presenter:n,recentSkillGroupValues:r,recentSkillValues:i,recentSkillsLabel:a,skillRecords:s,snapshot:c}=e;return qD({skillRecords:s,recentSkillValues:i,groupedRecentSkillValues:r,selectedSkills:c.selectedSkills,isLoading:c.isSkillsLoading,onSelectedKeysChange:n.chatInputManager.selectSkills,texts:{title:o(`chatSkillsPickerTitle`),searchPlaceholder:o(`chatSkillsPickerSearchPlaceholder`),emptyLabel:o(`chatSkillsPickerEmpty`),loadingLabel:o(`sessionsLoading`),manageLabel:o(`chatSkillsPickerManage`),recentSkillsLabel:a,allSkillsLabel:t}})}function TO(){let e=XD(),{language:t}=ut(),{isMobile:n}=ft(),r=Q(e=>e.snapshot),i=k(),[a,s]=(0,P.useState)(null),c=(0,P.useRef)(null),l=(0,P.useRef)(null),u=bO(t),{skillRecords:d,modelRecords:f,recentModelValues:p,recentSkillValues:m,recentSkillGroupValues:h}=xO(r,u.skillScopeLabels),g=fO(r),_=pO(r),v=mO(r),y=hO(r),b=typeof e.chatInputManager.addAttachments==`function`,x=o(v?`chatModelNoOptions`:n?`chatInputPlaceholderCompact`:`chatInputPlaceholder`),S=(0,P.useMemo)(()=>GD(d,a??``,u.slashTexts,m),[u.slashTexts,m,d,a]),C=f.find(e=>e.value===r.selectedModel),w=C?.thinkingCapability?.supported??[],T=r.stopDisabledReason===`__preparing__`?o(`chatStopPreparing`):r.stopDisabledReason?.trim()||o(`chatStopUnavailable`),{handleFilesAdd:E,handleFileInputChange:D}=SO({attachmentSupported:b,inputBarRef:c,presenter:e}),O=CO({allModelsLabel:u.allModelsLabel,hasModelOptions:g,isModelOptionsLoading:_,modelRecords:f,presenter:e,recentModelValues:p,recentModelsLabel:u.recentModelsLabel,selectedModel:r.selectedModel,selectedThinkingLevel:r.selectedThinkingLevel,thinkingSupportedLevels:w,thinkingDefaultLevel:C?.thinkingCapability?.default??null}),ee=wO({allSkillsLabel:u.allSkillsLabel,presenter:e,recentSkillGroupValues:h,recentSkillValues:m,recentSkillsLabel:u.recentSkillsLabel,skillRecords:d,snapshot:r}),te=r.draft.trim().length>0||r.attachments.length>0||nO(r.composerNodes).length>0;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(pm,{ref:c,composer:{nodes:r.composerNodes,placeholder:x,disabled:y,onNodesChange:e.chatInputManager.setComposerNodes,...b?{onFilesAdd:E}:{},onSlashQueryChange:s},slashMenu:{isLoading:r.isSkillsLoading,items:S,onSelectItem:t=>{t.value&&e.chatInputManager.rememberSkillSelection(t.value)},texts:{slashLoadingLabel:o(`chatSlashLoading`),slashSectionLabel:o(`chatSlashSectionSkills`),slashEmptyLabel:o(`chatSlashNoResult`),slashHintLabel:o(`chatSlashHint`),slashSkillHintLabel:o(`chatSlashSkillHint`)}},hint:FD({isModelOptionsLoading:_,isModelOptionsEmpty:v,onGoToProviders:e.chatInputManager.goToProviders,texts:{noModelOptionsLabel:o(`chatModelNoOptions`),configureProviderLabel:o(`chatGoConfigureProvider`)}}),toolbar:{selects:O,accessories:[{key:`attach`,label:o(`chatInputAttach`),icon:`paperclip`,iconOnly:!0,disabled:!b||y||r.isSending,...b?{onClick:()=>l.current?.click()}:{tooltip:o(`chatInputAttachComingSoon`)}}],skillPicker:ee,actions:{sendError:i.isBlocked?null:r.sendError,isSending:r.isSending,canStopGeneration:r.canStopGeneration,sendDisabled:gO({snapshot:r,hasSendableDraft:te,isRuntimeBlocked:i.isBlocked}),stopDisabled:!r.canStopGeneration,stopHint:T,sendButtonLabel:o(`chatSend`),stopButtonLabel:o(`chatStop`),onSend:e.chatInputManager.send,onStop:e.chatInputManager.stop}}}),b?(0,N.jsx)(`input`,{ref:l,type:`file`,multiple:!0,className:`hidden`,onChange:D}):null]})}var EO=[`cmd`,`command`,`query`,`q`,`path`,`url`,`to`,`channel`,`agentId`,`sessionKey`];function DO(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function OO(e,t=2400){return e.length<=t?e:`${e.slice(0,t)}\n…`}function kO(e,t=120){let n=e.replace(/\s+/g,` `).trim();return n.length<=t?n:t<=1?`…`:`${n.slice(0,t-1)}…`}function AO(e){if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);if(e==null)return``;try{return OO(JSON.stringify(e,null,2))}catch{return String(e)}}function jO(e){if(DO(e))return e;if(typeof e!=`string`)return null;let t=e.trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`))return null;try{let e=JSON.parse(t);return DO(e)?e:null}catch{return null}}function MO(e){let t=jO(e);if(!t){let t=AO(e).trim();return t?kO(t,120):void 0}let n=[];for(let e of EO){let r=t[e];if(typeof r==`string`&&r.trim()?n.push(`${e}: ${r.trim()}`):(typeof r==`number`||typeof r==`boolean`)&&n.push(`${e}: ${String(r)}`),n.length>=2)break}return n.length>0?kO(n.join(` · `),120):kO(AO(t),140)}var NO=`ui_inline_tokens`,PO=`$`;function FO(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function IO(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function LO(e){let t=new Set,n=[];for(let r of e){let e=`${r.kind}:${r.key}:${r.rawText}`;t.has(e)||(t.add(e),n.push(r))}return n}function RO(e){let t=[];for(let n of e)n.type!==`token`||n.tokenKind!==`skill`||t.push({kind:`skill`,key:n.tokenKey,label:n.label,rawText:`${PO}${n.tokenKey}`});return LO(t)}function zO(e){let t=e?.[NO];if(!Array.isArray(t))return[];let n=[];for(let e of t){if(!FO(e))continue;let t=IO(e.kind),r=IO(e.key),i=IO(e.rawText);!t||!r||!i||n.push({kind:t,key:r,rawText:i,label:IO(e.label)??r})}return LO(n)}function BO(e,t){if(e.length===0||t.length===0)return e.length===0?[]:[{type:`text`,text:e}];let n=[...t].sort((e,t)=>t.rawText.length-e.rawText.length),r=[],i=0;for(;i<e.length;){let t=null;for(let r of n)if(e.startsWith(r.rawText,i)){t=r;break}if(!t){let t=i+1;for(;t<e.length&&!n.some(n=>e.startsWith(n.rawText,t));)t+=1;r.push({type:`text`,text:e.slice(i,t)}),i=t;continue}r.push({type:`token`,token:t}),i+=t.rawText.length}return r}var VO=/\u200B|\u200C|\u200D|\u2060|\uFEFF/g;function HO(e){let t=e.trim();return t&&t.replace(VO,``).trim()?t:null}function UO(e){return e.replace(VO,``).trim().length>0}function WO(e,t){let n=BO(e,t);if(n.length===0)return null;let r=[],i=!1;for(let e of n){if(e.type===`token`){i=!0,r.push({type:`token`,token:{kind:e.token.kind,key:e.token.key,label:e.token.label,rawText:e.token.rawText}});continue}e.text.length!==0&&(UO(e.text)&&(i=!0),r.push({type:`markdown`,text:e.text}))}return i?r:null}function GO(e,t){let n=WO(e.text,t);if(n&&n.some(e=>e.type===`token`))return{type:`inline-content`,segments:n};let r=HO(e.text);return r?{type:`markdown`,text:r}:null}function KO(e){return HO(e)}function qO(e){return typeof e==`object`&&!!e}function JO(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function YO(e){if(typeof e==`number`&&Number.isFinite(e)&&e>=0)return e;if(typeof e!=`string`)return null;let t=e.trim();if(!t)return null;let n=Number(t);return Number.isFinite(n)&&n>=0?n:null}function XO(e){return qO(e)?`command`in e||`workingDir`in e||`exitCode`in e||`stdout`in e||`stderr`in e||`aggregated_output`in e||`combinedOutput`in e:!1}function ZO(e,t){if(!qO(e))return null;let n=qO(e.asset)?e.asset:Array.isArray(e.assets)&&e.assets.length>0&&qO(e.assets[0])?e.assets[0]:null;if(!n)return null;let r=JO(n.url),i=JO(n.mimeType)??`application/octet-stream`,a=YO(n.sizeBytes);return r?{type:`file`,file:{label:JO(n.name)??(i.startsWith(`image/`)?t.imageAttachmentLabel:t.fileAttachmentLabel),mimeType:i,dataUrl:r,...a==null?{}:{sizeBytes:a},isImage:i.startsWith(`image/`)}}:null}function QO(e,t){return{kind:e.kind,toolName:e.name,...`agentId`in e&&e.agentId?{agentId:e.agentId}:{},summary:e.detail,inputLabel:t.toolInputLabel,input:`input`in e&&typeof e.input==`string`?e.input:void 0,output:e.text,outputData:e.outputData,hasResult:!!e.hasResult,statusTone:e.statusTone,statusLabel:e.statusLabel,titleLabel:e.kind===`call`?t.toolCallLabel:t.toolResultLabel,outputLabel:t.toolOutputLabel,emptyLabel:t.toolNoOutputLabel,...`action`in e&&e.action?{action:e.action}:{},...`fileOperation`in e&&e.fileOperation?{fileOperation:e.fileOperation}:{}}}function $O(e){let t=typeof e.status==`string`?e.status.trim().toLowerCase():``,n=typeof e.error==`string`&&e.error.trim().length>0;return e.cancelled===!0||t===`cancelled`?{kind:`result`,hasResult:!0,statusTone:`cancelled`,statusLabel:e.texts.toolStatusCancelledLabel}:n||t===`error`?{kind:`result`,hasResult:!0,statusTone:`error`,statusLabel:e.texts.toolStatusFailedLabel}:t===`result`||e.result!=null?{kind:`result`,hasResult:!0,statusTone:`success`,statusLabel:e.texts.toolStatusCompletedLabel}:{kind:`call`,hasResult:!1,statusTone:`running`,statusLabel:e.texts.toolStatusRunningLabel}}function ek(e){if(typeof e!=`string`)return e;let t=e.trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`))return e;try{return JSON.parse(t)}catch{return e}}function tk(e,t){return AO(t??ek(e)).trim()||void 0}function nk(e){return typeof e==`object`&&!!e}function rk(e){if(typeof e!=`string`)return e;let t=e.trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`))return e;try{return JSON.parse(t)}catch{return e}}function ik(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function ak(e){let t=rk(e);return nk(t)?ik(t.agentId):null}function ok(e){return ak(e.parsedArgs)??ak(e.args)??ak(e.result)}var sk=12e3,ck=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/;function lk(e){let t=e.replace(/\r\n/g,`
|
|
51
|
+
`),[e.parts]),{copied:r,copy:i}=tw({text:n});return n?(0,N.jsx)(`button`,{type:`button`,onClick:()=>void i(),className:`text-gray-400 hover:text-gray-600 transition-colors p-1 rounded-md hover:bg-gray-100 flex items-center justify-center`,"aria-label":r?t.copiedMessageLabel:t.copyMessageLabel,title:r?t.copiedMessageLabel:t.copyMessageLabel,children:r?(0,N.jsx)(Be,{className:`h-3.5 w-3.5`}):(0,N.jsx)(Rt,{className:`h-3.5 w-3.5`})}):null}var JE=/\u200B|\u200C|\u200D|\u2060|\uFEFF/g;function YE(e){let t=e.trim();return t?t.replace(JE,``).trim().length>0:!1}function XE(e){return e.parts.some(e=>e.type===`markdown`||e.type===`reasoning`?YE(e.text):!0)}function ZE(){return(0,N.jsx)(`div`,{className:`flex items-center gap-2 px-1 py-0.5 text-[11px] text-gray-400`,children:(0,N.jsxs)(`div`,{className:`flex space-x-1 items-center h-full`,children:[(0,N.jsx)(`div`,{className:`h-1.5 w-1.5 rounded-full bg-gray-400 animate-pulse`}),(0,N.jsx)(`div`,{className:`h-1.5 w-1.5 rounded-full bg-gray-400 animate-pulse [animation-delay:200ms]`}),(0,N.jsx)(`div`,{className:`h-1.5 w-1.5 rounded-full bg-gray-400 animate-pulse [animation-delay:400ms]`})]})})}function QE(e){let t=e.messages.filter(XE),n=t.some(e=>e.role===`assistant`&&(e.status===`streaming`||e.status===`pending`));return(0,N.jsxs)(`div`,{className:F(`space-y-5`,e.className),children:[t.map(t=>{let n=t.role===`user`,r=!n&&(t.status===`streaming`||t.status===`pending`);return(0,N.jsxs)(`div`,{className:F(`flex gap-3`,n?`justify-end`:`justify-start`),children:[n?null:(0,N.jsx)(mm,{role:t.role}),(0,N.jsxs)(`div`,{className:F(`w-fit max-w-[92%] space-y-2`,n&&`flex flex-col items-end`),children:[(0,N.jsx)(GE,{message:t,texts:e.texts,onToolAction:e.onToolAction,onFileOpen:e.onFileOpen,renderToolAgent:e.renderToolAgent}),(0,N.jsx)(`div`,{className:F(`flex items-center gap-2`,n&&`justify-end`),children:r?(0,N.jsx)(ZE,{}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(KE,{roleLabel:t.roleLabel,timestampLabel:t.timestampLabel,isUser:n}),n?null:(0,N.jsx)(qE,{message:t,texts:e.texts})]})})]}),n?(0,N.jsx)(mm,{role:t.role}):null]},t.id)}),e.isSending&&!n?(0,N.jsxs)(`div`,{className:`flex justify-start gap-3`,children:[(0,N.jsx)(mm,{role:`assistant`}),(0,N.jsx)(`div`,{className:`rounded-2xl border border-gray-200 bg-white px-4 py-3 text-sm text-gray-500 shadow-sm`,children:e.texts.typingLabel})]}):null]})}var $E=function(e){return e.EndpointReady=`endpoint.ready`,e.EndpointError=`endpoint.error`,e.MessageRequest=`message.request`,e.MessageStreamRequest=`message.stream-request`,e.MessageSent=`message.sent`,e.MessageAccepted=`message.accepted`,e.MessageIncoming=`message.incoming`,e.MessageCompleted=`message.completed`,e.MessageFailed=`message.failed`,e.MessageAbort=`message.abort`,e.MessageTextStart=`message.text-start`,e.MessageTextDelta=`message.text-delta`,e.MessageTextEnd=`message.text-end`,e.MessageReasoningStart=`message.reasoning-start`,e.MessageReasoningDelta=`message.reasoning-delta`,e.MessageReasoningEnd=`message.reasoning-end`,e.MessageToolCallStart=`message.tool-call-start`,e.MessageToolCallArgs=`message.tool-call-args`,e.MessageToolCallArgsDelta=`message.tool-call-args-delta`,e.MessageToolCallEnd=`message.tool-call-end`,e.MessageToolCallResult=`message.tool-call-result`,e.MessageRead=`message.read`,e.MessageDelivered=`message.delivered`,e.MessageRecalled=`message.recalled`,e.MessageReaction=`message.reaction`,e.RunStarted=`run.started`,e.RunFinished=`run.finished`,e.RunError=`run.error`,e.RunMetadata=`run.metadata`,e.TypingStart=`typing.start`,e.TypingEnd=`typing.end`,e.PresenceUpdated=`presence.updated`,e}({}),eD=/\[\[\s*reply_to_current\s*\]\]/gi,tD=/\[\[\s*reply_to\s*:\s*([^\]]+?)\s*\]\]/i;function nD(e){if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0}function rD(e,t){let n=e,r;eD.test(n)&&(r=nD(t),n=n.replace(eD,``).trim());let i=n.match(tD)?.[1];return i&&(r=nD(i),n=n.replace(tD,``).trim()),r?{content:n,replyTo:r}:{content:n}}function iD(e,t=e.id){if(e.role!==`assistant`)return{...e,parts:[...e.parts],metadata:e.metadata?{...e.metadata}:void 0};let n=e.parts.findIndex(e=>e.type===`text`),r=e.metadata?{...e.metadata}:void 0,i=nD(r?.reply_to);if(n<0)return{...e,parts:[...e.parts],metadata:r};let a=e.parts[n];if(!a||a.type!==`text`)return{...e,parts:[...e.parts],metadata:r};let{content:o,replyTo:s}=rD(a.text,t),c=s??i,l=e.parts.flatMap((e,t)=>t!==n||e.type!==`text`?[e]:o.length===0?[]:[{...e,text:o}]);return c?{...e,parts:l,metadata:{...r,reply_to:c}}:{...e,parts:l,metadata:r}}function aD(e){return{...e,parts:[...e.parts],metadata:e.metadata?{...e.metadata}:void 0}}function oD(e){return aD(iD(e))}var sD=`__nextclaw_aborted_tool_call__`;function cD(e){let t=e.error?.trim();return{code:`runtime-error`,message:t&&t.length>0?t:`Agent run failed.`,details:{sessionId:e.sessionId,messageId:e.messageId,threadId:e.threadId,runId:e.runId}}}function lD(e,t){return t.trim()?e.id.startsWith(`tool-`)?!0:e.parts.some(e=>e.type===`tool-invocation`):!1}function uD(e,t,n){for(let[r,i]of e)i===t&&e.set(r,n)}function dD(e,t,n){for(let[r,i]of e)i===n&&(e.delete(r),t.delete(r))}function fD(e,t){for(let n=e.length-1;n>=0;--n){let r=e[n];if(r.type===`tool-invocation`&&r.toolCallId===t)return r}return null}function pD(e,t){return fD(e,t)?.toolName??null}function mD(e,t){let n=[...e];for(let e=n.length-1;e>=0;--e){let r=n[e];if(r.type===`tool-invocation`&&r.toolCallId===t.toolCallId)return n[e]={...r,...t},n}return n.push(t),n}function hD(e){let t=[];return{parts:e.map(e=>e.type!==`tool-invocation`||!e.toolCallId||e.state===`result`||e.state===`cancelled`?e:(t.push(e.toolCallId),{...e,state:`cancelled`})),toolCallIds:t}}var gD=`assistant`,_D=class{messages=[];streamingMessage=null;error=null;activeRun=null;listeners=new Set;toolCallMessageIdByCallId=new Map;toolCallArgsRawByCallId=new Map;lastSettledRunId=null;snapshotCache=null;snapshotVersion=-1;stateVersion=0;getSnapshot=()=>{if(this.snapshotCache&&this.snapshotVersion===this.stateVersion)return this.snapshotCache;let e={messages:this.messages,streamingMessage:this.streamingMessage,error:this.error?{...this.error,details:this.error.details?{...this.error.details}:void 0}:null,activeRun:this.activeRun?{...this.activeRun}:null};return this.snapshotCache=e,this.snapshotVersion=this.stateVersion,e};subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e));reset=()=>{this.messages.length===0&&!this.streamingMessage&&!this.error&&!this.activeRun&&this.toolCallMessageIdByCallId.size===0&&this.toolCallArgsRawByCallId.size===0||(this.messages=[],this.streamingMessage=null,this.error=null,this.activeRun=null,this.toolCallMessageIdByCallId.clear(),this.toolCallArgsRawByCallId.clear(),this.lastSettledRunId=null,this.stateVersion+=1,this.notifyListeners())};hydrate=e=>{this.messages=e.messages.map(e=>oD(e)),this.streamingMessage=null,this.error=null,this.activeRun=e.activeRun?{...e.activeRun,sessionId:e.activeRun.sessionId??e.sessionId,abortDisabledReason:e.activeRun.abortDisabledReason??null}:null,this.toolCallMessageIdByCallId.clear(),this.toolCallArgsRawByCallId.clear(),this.lastSettledRunId=null,this.stateVersion+=1,this.notifyListeners()};dispatch=e=>this.dispatchBatch([e]);dispatchBatch=async e=>{if(!e.length)return;let t=this.stateVersion;e.forEach(this.applyEvent),this.stateVersion!==t&&this.notifyListeners()};applyEvent=e=>{switch(e.type){case $E.MessageSent:this.handleMessageSent(e.payload);break;case $E.MessageAbort:this.handleMessageAbort(e.payload);break;case $E.MessageTextStart:this.handleMessageTextStart(e.payload);break;case $E.MessageTextDelta:this.handleMessageTextDelta(e.payload);break;case $E.MessageTextEnd:this.handleMessageTextEnd(e.payload);break;case $E.MessageReasoningStart:this.handleMessageReasoningStart(e.payload);break;case $E.MessageReasoningDelta:this.handleMessageReasoningDelta(e.payload);break;case $E.MessageReasoningEnd:this.handleMessageReasoningEnd(e.payload);break;case $E.MessageToolCallStart:this.handleMessageToolCallStart(e.payload);break;case $E.MessageToolCallArgs:this.handleMessageToolCallArgs(e.payload);break;case $E.MessageToolCallArgsDelta:this.handleMessageToolCallArgsDelta(e.payload);break;case $E.MessageToolCallEnd:this.handleMessageToolCallEnd(e.payload);break;case $E.MessageToolCallResult:this.handleMessageToolCallResult(e.payload);break;case $E.RunStarted:this.handleRunStarted(e.payload);break;case $E.RunFinished:this.handleRunFinished(e.payload);break;case $E.RunError:this.handleRunError(e.payload);break;case $E.RunMetadata:this.handleRunMetadata(e.payload);break;case $E.EndpointError:this.handleEndpointError(e.payload);break;default:break}};handleMessageSent=e=>{this.upsertMessage(e.message),this.setError(null)};handleMessageAbort=e=>{let t=e.messageId?.trim();if(this.clearActiveRun(),this.setError(null),this.streamingMessage&&(!t||this.streamingMessage.id===t)){let e=this.streamingMessage.id,{parts:n,toolCallIds:r}=hD(this.streamingMessage.parts);this.upsertMessage({...this.streamingMessage,status:`final`,parts:n}),this.replaceStreamingMessage(null),t?dD(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,t):dD(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,e),r.forEach(e=>this.toolCallArgsRawByCallId.set(e,sD))}};handleMessageTextStart=e=>{this.ensureStreamingMessage(e.sessionId,e.messageId,`streaming`),this.setError(null)};handleMessageTextDelta=e=>{if(!e.delta)return;let t=this.ensureStreamingMessage(e.sessionId,e.messageId,`streaming`),n=[...t.parts],r=n[n.length-1];r?.type===`text`?n[n.length-1]={type:`text`,text:`${r.text}${e.delta}`}:n.push({type:`text`,text:e.delta}),this.replaceStreamingMessage({...t,parts:n,status:`streaming`})};handleMessageTextEnd=e=>{this.streamingMessage?.id===e.messageId&&this.streamingMessage.status===`streaming`&&this.replaceStreamingMessage({...this.streamingMessage,status:`pending`})};handleMessageReasoningStart=e=>{this.ensureStreamingMessage(e.sessionId,e.messageId,`streaming`)};handleMessageReasoningDelta=e=>{if(!e.delta)return;let t=this.ensureStreamingMessage(e.sessionId,e.messageId,`streaming`),n=[...t.parts],r=n[n.length-1];r?.type===`reasoning`?n[n.length-1]={type:`reasoning`,text:`${r.text}${e.delta}`}:n.push({type:`reasoning`,text:e.delta}),this.replaceStreamingMessage({...t,parts:n,status:`streaming`})};handleMessageReasoningEnd=e=>{this.streamingMessage?.id,e.messageId};handleMessageToolCallStart=e=>{if(this.toolCallArgsRawByCallId.get(e.toolCallId)===`__nextclaw_aborted_tool_call__`)return;let t=this.resolveToolCallTargetMessage(e.sessionId,e.toolCallId,e.messageId);this.toolCallArgsRawByCallId.set(e.toolCallId,``);let n=mD(t.parts,{type:`tool-invocation`,toolCallId:e.toolCallId,toolName:e.toolName,state:`partial-call`,args:``});this.replaceStreamingMessage({...t,parts:n,status:`streaming`}),this.setError(null)};handleMessageToolCallArgs=e=>{this.toolCallArgsRawByCallId.get(e.toolCallId)!==`__nextclaw_aborted_tool_call__`&&(this.toolCallArgsRawByCallId.set(e.toolCallId,e.args),this.applyToolCallArgs(e.sessionId,e.toolCallId,e.args))};handleMessageToolCallArgsDelta=e=>{if(this.toolCallArgsRawByCallId.get(e.toolCallId)===`__nextclaw_aborted_tool_call__`)return;let t=`${this.toolCallArgsRawByCallId.get(e.toolCallId)??``}${e.delta}`;this.toolCallArgsRawByCallId.set(e.toolCallId,t),this.applyToolCallArgs(e.sessionId,e.toolCallId,t,e.messageId)};handleMessageToolCallEnd=e=>{if(this.toolCallArgsRawByCallId.get(e.toolCallId)===`__nextclaw_aborted_tool_call__`)return;let t=this.resolveToolCallTargetMessage(e.sessionId,e.toolCallId),n=this.toolCallArgsRawByCallId.get(e.toolCallId)??``,r=mD(t.parts,{type:`tool-invocation`,toolCallId:e.toolCallId,toolName:pD(t.parts,e.toolCallId)??`unknown`,state:`call`,args:n});this.replaceStreamingMessage({...t,parts:r,status:`streaming`})};handleMessageToolCallResult=e=>{if(this.toolCallArgsRawByCallId.get(e.toolCallId)!==`__nextclaw_aborted_tool_call__`&&!this.updateMessageContainingToolCall(e.toolCallId,(t,n)=>{let r={type:`tool-invocation`,toolCallId:e.toolCallId,toolName:n.toolName,state:`result`,args:n.args,result:e.content,resultContentItems:e.contentItems};return mD(t.parts,r)})){let t=this.resolveToolCallTargetMessage(e.sessionId,e.toolCallId),n=mD(t.parts,{type:`tool-invocation`,toolCallId:e.toolCallId,toolName:`unknown`,state:`result`,result:e.content,resultContentItems:e.contentItems});this.replaceStreamingMessage({...t,parts:n,status:`streaming`})}};handleRunStarted=e=>{this.isSettledRunId(e.runId)||(this.setError(null),this.activeRun={runId:e.runId??null,sessionId:e.sessionId},this.stateVersion+=1)};handleRunFinished=e=>{this.markRunAsSettled(e.runId??this.activeRun?.runId??null),this.settleStreamingMessage(`final`),this.setError(null),this.clearActiveRun()};handleRunError=e=>{this.markRunAsSettled(e.runId??this.activeRun?.runId??null),this.settleStreamingMessage(`error`),this.setError(cD(e)),this.clearActiveRun()};handleRunMetadata=e=>{let t=e.metadata;if(t?.kind===`ready`){let e=t;if(this.isSettledRunId(e.runId))return;this.activeRun={runId:e.runId??this.activeRun?.runId??null,sessionId:e.sessionId??this.activeRun?.sessionId,abortDisabledReason:e.supportsAbort===!1?e.abortDisabledReason??`Unsupported`:null},this.stateVersion+=1}else t?.kind===`final`&&(this.markRunAsSettled(e.runId??this.activeRun?.runId??null),this.clearActiveRun())};handleEndpointError=e=>{if(e.code===`abort-error`){this.handleMessageAbort({sessionId:this.activeRun?.sessionId??this.streamingMessage?.sessionId??``,...this.streamingMessage?.id?{messageId:this.streamingMessage.id}:{}});return}this.settleStreamingMessage(`error`),this.clearActiveRun(),this.setError(e)};applyToolCallArgs=(e,t,n,r)=>{let i=this.resolveToolCallTargetMessage(e,t,r),a=pD(i.parts,t)??`unknown`,o=mD(i.parts,{type:`tool-invocation`,toolCallId:t,toolName:a,state:`partial-call`,args:n});this.replaceStreamingMessage({...i,parts:o,status:`streaming`})};ensureStreamingMessage=(e,t,n)=>{if(this.streamingMessage?.id===t){if(this.streamingMessage.status===n)return this.streamingMessage;let e={...this.streamingMessage,status:n};return this.replaceStreamingMessage(e),e}let r=this.messages.findIndex(e=>e.id===t);if(r>=0){let t=aD(this.messages[r]),i=[...this.messages];i.splice(r,1),this.messages=i,this.stateVersion+=1;let a={...t,sessionId:e,status:n};return this.replaceStreamingMessage(a),a}let i=this.streamingMessage;if(i&&i.id!==t&&i.sessionId===e&&lD(i,t)){let r={...i,id:t,sessionId:e,status:n};return uD(this.toolCallMessageIdByCallId,i.id,t),this.replaceStreamingMessage(r),r}let a={id:t,sessionId:e,role:gD,status:n,parts:[],timestamp:new Date().toISOString()};return this.replaceStreamingMessage(a),a};resolveToolCallTargetMessage=(e,t,n)=>{let r=n?.trim()||this.toolCallMessageIdByCallId.get(t)||this.streamingMessage?.id||`tool-${t}`;return this.toolCallMessageIdByCallId.set(t,r),this.ensureStreamingMessage(e,r,`streaming`)};updateMessageContainingToolCall=(e,t)=>{if(this.streamingMessage){let n=fD(this.streamingMessage.parts,e);if(n){let e=t(this.streamingMessage,n);return this.replaceStreamingMessage({...this.streamingMessage,parts:e}),!0}}for(let n=this.messages.length-1;n>=0;--n){let r=this.messages[n],i=fD(r.parts,e);if(!i)continue;let a=[...this.messages];return a[n]={...r,parts:t(r,i)},this.messages=a,this.stateVersion+=1,!0}return!1};upsertMessage=e=>{let t=oD(e),n=this.messages.findIndex(e=>e.id===t.id);if(n<0){this.messages=[...this.messages,t],this.stateVersion+=1;return}let r=[...this.messages];r[n]=t,this.messages=r,this.stateVersion+=1};replaceStreamingMessage=e=>{!e&&!this.streamingMessage||(this.streamingMessage=e?oD(e):null,this.stateVersion+=1)};setError=e=>{this.error?.code===e?.code&&this.error?.message===e?.message&&this.error?.details===e?.details&&this.error?.cause===e?.cause||(this.error=e?{...e,details:e.details?{...e.details}:void 0}:null,this.stateVersion+=1)};clearActiveRun=()=>{this.activeRun&&(this.activeRun=null,this.stateVersion+=1)};isSettledRunId=e=>!!e?.trim()&&e===this.lastSettledRunId;markRunAsSettled=e=>{this.lastSettledRunId=e?.trim()||null};settleStreamingMessage=e=>{if(!this.streamingMessage)return;let t={...this.streamingMessage,status:e};this.upsertMessage(t),this.replaceStreamingMessage(null),dD(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,t.id)};notifyListeners=()=>{let e=this.getSnapshot();for(let t of this.listeners)t(e)}},vD=16,yD=class{constructor(e){this.dispatchBatch=e,this.queue=[],this.flushTimerId=null,this.isFlushing=!1,this.isDisposed=!1,this.enqueue=e=>{this.isDisposed||(this.queue.push(e),this.scheduleFlush())},this.dispose=()=>{this.isDisposed=!0,this.flushTimerId!==null&&(window.clearTimeout(this.flushTimerId),this.flushTimerId=null),this.queue.length=0},this.scheduleFlush=()=>{this.flushTimerId!==null||this.isFlushing||this.queue.length===0||(this.flushTimerId=window.setTimeout(()=>{this.flushTimerId=null,this.flush()},vD))},this.flush=async()=>{if(!(this.isDisposed||this.isFlushing||this.queue.length===0)){this.isFlushing=!0;try{for(;this.queue.length>0;){let e=this.queue.splice(0);await this.dispatchBatch(e)}}finally{this.isFlushing=!1,this.scheduleFlush()}}}}};function bD(e,t){let n=e.dispatchBatch;return typeof n==`function`?n.call(e,t):t.reduce((t,n)=>t.then(()=>e.dispatch(n)),Promise.resolve())}function xD(e,t){let n=`payload`in e?e.payload:null;return!n||typeof n!=`object`||!(`sessionId`in n)||typeof n.sessionId!=`string`?!0:n.sessionId===t}function SD(e){return e.parts.some(e=>e.type===`text`||e.type===`rich-text`||e.type===`reasoning`?e.text.trim().length>0:!0)}function CD(e,t){if(typeof e==`string`){let n=e.trim();return n?{sessionId:t,message:{id:`user-${Date.now().toString(36)}`,sessionId:t,role:`user`,status:`final`,parts:[{type:`text`,text:n}],timestamp:new Date().toISOString()}}:null}return SD(e.message)?{...e,sessionId:e.sessionId,message:{...e.message,sessionId:e.message.sessionId||e.sessionId}}:null}function wD(e){let t=(0,P.useRef)();return(!t.current||t.current.sessionId!==e)&&(t.current={sessionId:e,manager:new _D}),t.current.manager}function TD({sessionId:e,client:t,manager:n}){let r=(0,P.useSyncExternalStore)(e=>n.subscribe(()=>e()),()=>n.getSnapshot(),()=>n.getSnapshot()),[i,a]=(0,P.useState)(!1);(0,P.useEffect)(()=>{a(!1)},[e]),(0,P.useEffect)(()=>{let r=new yD(e=>bD(n,e)),i=t.subscribe(t=>{xD(t,e)&&r.enqueue(t)});return()=>{i(),r.dispose(),t.stop()}},[t,n,e]);let o=r.streamingMessage?[...r.messages,r.streamingMessage]:r.messages,s=r.activeRun?.runId??null,c=!!r.activeRun;return{snapshot:r,visibleMessages:o,activeRunId:s,isRunning:c,isSending:i,send:async r=>{if(i||c)return;let o=CD(r,e);if(o){a(!0),await n.dispatch({type:$E.MessageSent,payload:{sessionId:e,message:o.message,metadata:o.metadata}});try{await t.send(o)}finally{a(!1)}}},abort:async()=>{r.activeRun&&await t.abort({sessionId:e})},streamRun:async()=>{await t.stop(),await t.stream({sessionId:e})}}}function ED(e){return e instanceof Error?e:Error(String(e))}function DD(e){return e.isHydrating||e.hydratedSessionId!==e.sessionId}function OD({sessionId:e,client:t,loadSeed:n}){let r=wD(e),i=TD({sessionId:e,client:t,manager:r}),[a,o]=(0,P.useState)(!0),[s,c]=(0,P.useState)(null),[l,u]=(0,P.useState)(null),d=(0,P.useRef)({requestId:0,controller:null}),f=(0,P.useCallback)(async()=>{d.current.controller?.abort();let i=new AbortController,a=d.current.requestId+1;d.current={requestId:a,controller:i},await t.stop(),r.reset(),c(null),o(!0);try{let s=await n(e,i.signal);if(i.signal.aborted||d.current.requestId!==a)return;r.hydrate({sessionId:e,messages:s.messages,activeRun:s.status===`running`?{runId:null,sessionId:e,abortDisabledReason:null}:null}),c(null),u(e),o(!1),t.stream({sessionId:e}).catch(e=>{d.current.requestId===a&&c(ED(e))})}catch(t){if(i.signal.aborted||d.current.requestId!==a)return;c(ED(t)),u(e),o(!1)}finally{d.current.controller===i&&(d.current.controller=null)}},[t,n,r,e]);return(0,P.useEffect)(()=>(f(),()=>{d.current.controller?.abort(),d.current.controller=null}),[f]),{...i,isHydrating:DD({sessionId:e,hydratedSessionId:l,isHydrating:a}),hydrateError:s}}var kD=200*1024*1024,AD=`application/octet-stream`;function jD(e){let t=e.type.trim().toLowerCase();return t.length>0?t:AD}function MD(e,t){let n=t.acceptedMimeTypes&&t.acceptedMimeTypes.length>0?new Set(t.acceptedMimeTypes.map(e=>e.trim().toLowerCase())):null,r=t.maxBytes??209715200,i=jD(e);return n&&!n.has(i)?{ok:!1,rejected:{fileName:e.name,mimeType:i,sizeBytes:e.size,reason:`unsupported-type`}}:e.size>r?{ok:!1,rejected:{fileName:e.name,mimeType:i,sizeBytes:e.size,reason:`too-large`}}:{ok:!0,mimeType:i}}function ND(e){let t=e.parts&&e.parts.length>0?e.parts.map(e=>structuredClone(e)):[...e.text?.trim()??``?[{type:`text`,text:e.text.trim()}]:[],...(e.attachments??[]).map(e=>({type:`file`,name:e.name,mimeType:e.mimeType,...e.assetUri?.trim()?{assetUri:e.assetUri.trim()}:{},...e.url?.trim()?{url:e.url.trim()}:{},...e.contentBase64?.trim()?{contentBase64:e.contentBase64.trim()}:{},sizeBytes:e.sizeBytes}))];if(t.length===0)return null;let n=e.timestamp??new Date().toISOString(),r=e.messageId??`user-${Date.now().toString(36)}`;return{sessionId:e.sessionId,message:{id:r,sessionId:e.sessionId,role:`user`,status:`final`,parts:t,timestamp:n,...e.metadata?{metadata:e.metadata}:{}},...e.metadata?{metadata:e.metadata}:{}}}async function PD(e,t){let n=[],r=[];for(let i of e){let e=MD(i,t);if(!e.ok){r.push(e.rejected);continue}n.push(i)}if(n.length===0)return{attachments:[],rejected:r};try{return{attachments:await t.uploadBatch(n),rejected:r}}catch{return r.push(...n.map(e=>({fileName:e.name,mimeType:jD(e),sizeBytes:e.size,reason:`read-failed`}))),{attachments:[],rejected:r}}}function FD(e){let t=e.modelLabel.trim(),n=e.providerLabel.trim();return n?`${n}/${t}`:t}function ID(e){let t=[];for(let n of[`off`,...e])t.includes(n)||t.push(n);return t}function LD(e){return!e.isModelOptionsLoading&&!e.isModelOptionsEmpty?null:e.isModelOptionsLoading?{tone:`neutral`,loading:!0}:{tone:`warning`,text:e.texts.noModelOptionsLabel,actionLabel:e.texts.configureProviderLabel,onAction:e.onGoToProviders}}function RD({modelOptions:e,recentModelValues:t,selectedModel:n,isModelOptionsLoading:r,hasModelOptions:i,onValueChange:a,texts:o}){let s=e.find(e=>e.value===n)??e[0],c=i?s?.value:void 0,l=new Set(t??[]),u=new Map(e.map(e=>[e.value,e])),d=(t??[]).map(e=>u.get(e)).filter(e=>!!e),f=e.filter(e=>!l.has(e.value)),p=d.length>0?[{key:`recent-models`,label:o.recentModelsLabel,options:d.map(e=>({value:e.value,label:FD(e)}))},{key:`all-models`,label:o.allModelsLabel,options:f.map(e=>({value:e.value,label:FD(e)}))}].filter(e=>e.options.length>0):void 0;return{key:`model`,value:c,placeholder:o.modelSelectPlaceholder,selectedLabel:s?FD(s):void 0,icon:`sparkles`,options:e.map(e=>({value:e.value,label:FD(e)})),groups:p,disabled:!i,loading:r,emptyLabel:o.modelNoOptionsLabel,onValueChange:a}}function zD(e){if(e.supportedLevels.length===0)return null;let t=ID(e.supportedLevels),n=t.includes(`off`)?`off`:t[0],r=e.selectedThinkingLevel&&t.includes(e.selectedThinkingLevel)&&e.selectedThinkingLevel||e.defaultThinkingLevel&&t.includes(e.defaultThinkingLevel)&&e.defaultThinkingLevel||n;return{key:`thinking`,value:r,placeholder:e.texts.thinkingLabels[r],selectedLabel:e.texts.thinkingLabels[r],icon:`brain`,options:t.map(t=>({value:t,label:e.texts.thinkingLabels[t]})),onValueChange:t=>e.onValueChange(t)}}var BD={exactSpec:1200,exactLabel:1150,prefixSpec:1e3,prefixLabel:950,prefixToken:900,containsSpec:800,containsLabel:760,containsDescription:500,subsequence:300,fallback:1};function VD(e){return(e??``).trim().toLowerCase()}function HD(e,t){if(!e||!t)return!1;let n=0;for(let r of t)if(r===e[n]&&(n+=1,n>=e.length))return!0;return!1}function UD(e,t){let n=VD(t);if(!n)return BD.fallback;let r=VD(e.key),i=VD(e.label||e.key),a=VD(`${e.descriptionZh??``} ${e.description??``}`),o=i.split(/[\s/_-]+/).filter(Boolean);return r===n?BD.exactSpec:i===n?BD.exactLabel:r.startsWith(n)?BD.prefixSpec:i.startsWith(n)?BD.prefixLabel:o.some(e=>e.startsWith(n))?BD.prefixToken:r.includes(n)?BD.containsSpec:i.includes(n)?BD.containsLabel:a.includes(n)?BD.containsDescription:HD(n,i)||HD(n,r)?BD.subsequence:0}function WD(e){return e>=BD.exactLabel?4:e>=BD.prefixToken?3:e>=BD.containsLabel?2:e>0?1:0}function GD(e){return new Map(e.map((e,t)=>[e,t]))}function KD(e,t){let n=GD(t),r=[],i=[];for(let t of e){if(n.has(t.key)){r.push(t);continue}i.push(t)}return r.sort((e,t)=>(n.get(e.key)??1/0)-(n.get(t.key)??1/0)),[...r,...i]}function qD(e,t,n,r=[]){let i=new Intl.Collator(void 0,{sensitivity:`base`,numeric:!0}),a=GD(r);return e.map((e,n)=>({record:e,order:n,score:UD(e,t)})).filter(e=>e.score>0).sort((e,t)=>{let n=WD(e.score),r=WD(t.score);if(r!==n)return r-n;let o=a.get(e.record.key)??1/0,s=a.get(t.record.key)??1/0;if(o!==s)return o-s;if(t.score!==e.score)return t.score-e.score;let c=(e.record.label||e.record.key).trim(),l=(t.record.label||t.record.key).trim(),u=i.compare(c,l);return u===0?e.order-t.order:u}).map(({record:e})=>({key:`skill:${e.key}`,title:e.label||e.key,subtitle:n.slashSkillSubtitle,description:(e.descriptionZh??e.description??``).trim()||n.noSkillDescription,detailLines:[`${n.slashSkillSpecLabel}: ${e.key}`,...e.scopeLabel?[`${n.slashSkillScopeLabel}: ${e.scopeLabel}`]:[]],value:e.key}))}function JD(e){return e.map(e=>({key:e.key,label:e.label,description:e.descriptionZh||e.description||``,badgeLabel:e.badgeLabel}))}function YD(e){let t=KD(e.skillRecords,e.recentSkillValues??[]),n=new Set(e.groupedRecentSkillValues??[]),r=JD(t.filter(e=>n.has(e.key))),i=JD(t.filter(e=>!n.has(e.key)));return{title:e.texts.title,searchPlaceholder:e.texts.searchPlaceholder,emptyLabel:e.texts.emptyLabel,loadingLabel:e.texts.loadingLabel,isLoading:e.isLoading,manageLabel:e.texts.manageLabel,manageHref:`/marketplace/skills`,options:JD(t),groups:r.length>0?[{key:`recent-skills`,label:e.texts.recentSkillsLabel,options:r},{key:`all-skills`,label:e.texts.allSkillsLabel,options:i}].filter(e=>e.options.length>0):void 0,selectedKeys:e.selectedSkills,onSelectedKeysChange:e.onSelectedKeysChange}}var XD=(0,P.createContext)(null);function ZD({presenter:e,children:t}){return(0,N.jsx)(XD.Provider,{value:e,children:t})}function QD(){let e=(0,P.useContext)(XD);if(!e)throw Error(`usePresenter must be used inside ChatPresenterProvider`);return e}var $D=`$`;function eO(e,t){if(t.length===0)return e;let n=e[e.length-1];return n?.type===`text`?[...e.slice(0,-1),{...n,text:n.text+t}]:[...e,{type:`text`,text:t}]}function tO(){return xp()}function nO(e){return Sp(e)}function rO(e){return Tp(e)}function iO(e){return Ep(e,`skill`)}function aO(e){return Ep(e,`file`)}function oO(e,t,n){let r=new Set(t),i=Np(e,e=>e.tokenKind===`skill`&&!r.has(e.tokenKey)),a=Ep(i,`skill`),o=new Map(n.map(e=>[e.ref,e])),s=t.filter(e=>!a.includes(e)).map(e=>yp({tokenKind:`skill`,tokenKey:e,label:o.get(e)?.name||e}));return s.length===0?i:Cp([...i,...s])}function sO(e,t){let n=new Set(t.map(e=>e.id));return Np(e,e=>e.tokenKind===`file`&&!n.has(e.tokenKey))}function cO(e,t){let n=new Set(aO(e));return t.filter(e=>n.has(e.id))}function lO(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[];for(let t of e){if(t.type===`text`){r=eO(r,t.text);continue}if(t.tokenKind===`skill`){r=eO(r,`${$D}${t.tokenKey}`);continue}if(t.tokenKind!==`file`)continue;let e=n.get(t.tokenKey);e&&r.push({type:`file`,name:e.name,mimeType:e.mimeType,...e.assetUri?{assetUri:e.assetUri}:{},...e.url?{url:e.url}:{},...e.contentBase64?{contentBase64:e.contentBase64}:{},sizeBytes:e.sizeBytes})}return r}var uO={isProviderStateResolved:!1,composerNodes:tO(),attachments:[],draft:``,pendingSessionType:`native`,pendingProjectRoot:null,pendingProjectRootSessionKey:null,defaultSessionType:`native`,canStopGeneration:!1,stopDisabledReason:null,sendError:null,isSending:!1,modelOptions:[],selectedModel:``,selectedThinkingLevel:null,sessionTypeOptions:[],selectedSessionType:void 0,stopSupported:!1,stopReason:void 0,canEditSessionType:!1,sessionTypeUnavailable:!1,skillRecords:[],isSkillsLoading:!1,selectedSkills:[]},Q=C(e=>({snapshot:uO,setSnapshot:t=>e(e=>({snapshot:{...e.snapshot,...t}}))})),dO=class{constructor(e){this.options=e,this.read=()=>{let e=this.getStorage();if(!e)return[];try{return this.normalizeList(JSON.parse(e.getItem(this.options.storageKey)??`[]`))}catch{return[]}},this.remember=e=>{let t=this.normalizeValue(e);if(!t)return this.read();let n=[t,...this.read().filter(e=>e!==t)].slice(0,this.options.limit);return this.write(n),n},this.resolveVisible=e=>{let t=this.normalizeList(e.availableValues,1/0);if(t.length<=e.minAvailableCount)return[];let n=new Set(t),r=[],i=Math.max(1,e.limit??this.options.limit);for(let e of this.read())if(!(!n.has(e)||r.includes(e))&&(r.push(e),r.length>=i))break;return r},this.write=e=>{let t=this.getStorage();if(t)try{t.setItem(this.options.storageKey,JSON.stringify(this.normalizeList(e)))}catch{}},this.getStorage=()=>Object.prototype.hasOwnProperty.call(this.options,`storage`)?this.options.storage??null:typeof window>`u`?null:window.localStorage,this.normalizeList=(e,t=this.options.limit)=>{if(!Array.isArray(e))return[];let n=[];for(let r of e){let e=this.normalizeValue(r);if(!(!e||n.includes(e))&&(n.push(e),n.length>=t))break}return n},this.normalizeValue=e=>{if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}}},fO=new dO({storageKey:`nextclaw.chat.recent-models`,limit:3}),pO=new dO({storageKey:`nextclaw.chat.recent-skills`,limit:5});function mO(e){return e.modelOptions.length>0}function hO(e){return!e.isProviderStateResolved&&!mO(e)}function gO(e){return e.isProviderStateResolved&&!mO(e)}function _O(e){return!1}function vO(e){let{hasSendableDraft:t,isRuntimeBlocked:n}=e;return n||!t}function yO(){return{off:o(`chatThinkingLevelOff`),minimal:o(`chatThinkingLevelMinimal`),low:o(`chatThinkingLevelLow`),medium:o(`chatThinkingLevelMedium`),high:o(`chatThinkingLevelHigh`),adaptive:o(`chatThinkingLevelAdaptive`),xhigh:o(`chatThinkingLevelXhigh`)}}function bO(e,t){return e.map(e=>({key:e.ref,label:e.name,scopeLabel:t[e.scope],description:e.description,descriptionZh:e.descriptionZh,badgeLabel:t[e.scope]}))}function xO(e){return e.map(e=>({value:e.value,modelLabel:e.modelLabel,providerLabel:e.providerLabel,thinkingCapability:e.thinkingCapability?{supported:e.thinkingCapability.supported,default:e.thinkingCapability.default??null}:null}))}function SO(e){return{skillScopeLabels:(0,P.useMemo)(()=>({builtin:o(`chatSkillScopeBuiltin`),project:o(`chatSkillScopeProject`),workspace:o(`chatSkillScopeWorkspace`)}),[e]),slashTexts:(0,P.useMemo)(()=>({slashSkillSubtitle:o(`chatSlashTypeSkill`),slashSkillSpecLabel:o(`chatSlashSkillSpec`),slashSkillScopeLabel:o(`chatSlashSkillScope`),noSkillDescription:o(`chatSkillsPickerNoDescription`)}),[e]),recentModelsLabel:o(`chatPickerRecentModels`),allModelsLabel:o(`chatPickerAllModels`),recentSkillsLabel:o(`chatPickerRecent`),allSkillsLabel:o(`chatPickerAllSkills`)}}function CO(e,t){let n=(0,P.useMemo)(()=>bO(e.skillRecords,t),[e.skillRecords,t]),r=(0,P.useMemo)(()=>xO(e.modelOptions),[e.modelOptions]);return{skillRecords:n,modelRecords:r,recentModelValues:fO.resolveVisible({availableValues:r.map(e=>e.value),minAvailableCount:5}),recentSkillValues:pO.resolveVisible({availableValues:n.map(e=>e.key),minAvailableCount:0}),recentSkillGroupValues:pO.resolveVisible({availableValues:n.map(e=>e.key),minAvailableCount:4})}}function wO(e){let{attachmentSupported:t,inputBarRef:n,presenter:r}=e,i=(0,P.useCallback)(e=>{if(e===`unsupported-type`){y.error(o(`chatInputAttachmentUnsupported`));return}if(e===`too-large`){y.error(o(`chatInputAttachmentTooLarge`).replace(`{maxMb}`,String(kD/(1024*1024))));return}y.error(o(`chatInputAttachmentReadFailed`))},[]),a=(0,P.useCallback)(async e=>{if(!t||e.length===0)return;let a=await PD(e,{uploadBatch:S});if(a.attachments.length>0){let e=r.chatInputManager.addAttachments?.(a.attachments)??[];e.length>0&&n.current?.insertFileTokens(e.map(e=>({tokenKey:e.id,label:e.name})))}a.rejected.length>0&&i(a.rejected[0].reason)},[t,n,r.chatInputManager,i]);return{handleFilesAdd:a,handleFileInputChange:(0,P.useCallback)(async e=>{let t=Array.from(e.target.files??[]);e.currentTarget.value=``,await a(t)},[a])}}function TO(e){let{allModelsLabel:t,hasModelOptions:n,isModelOptionsLoading:r,modelRecords:i,presenter:a,recentModelValues:s,recentModelsLabel:c,selectedModel:l,selectedThinkingLevel:u,thinkingSupportedLevels:d,thinkingDefaultLevel:f}=e;return[RD({modelOptions:i,recentModelValues:s,selectedModel:l,isModelOptionsLoading:r,hasModelOptions:n,onValueChange:a.chatInputManager.selectModel,texts:{modelSelectPlaceholder:o(`chatSelectModel`),modelNoOptionsLabel:o(`chatModelNoOptions`),recentModelsLabel:c,allModelsLabel:t}}),zD({supportedLevels:d,selectedThinkingLevel:u,defaultThinkingLevel:f,onValueChange:e=>a.chatInputManager.selectThinkingLevel(e),texts:{thinkingLabels:yO()}})].filter(e=>e!==null)}function EO(e){let{allSkillsLabel:t,presenter:n,recentSkillGroupValues:r,recentSkillValues:i,recentSkillsLabel:a,skillRecords:s,snapshot:c}=e;return YD({skillRecords:s,recentSkillValues:i,groupedRecentSkillValues:r,selectedSkills:c.selectedSkills,isLoading:c.isSkillsLoading,onSelectedKeysChange:n.chatInputManager.selectSkills,texts:{title:o(`chatSkillsPickerTitle`),searchPlaceholder:o(`chatSkillsPickerSearchPlaceholder`),emptyLabel:o(`chatSkillsPickerEmpty`),loadingLabel:o(`sessionsLoading`),manageLabel:o(`chatSkillsPickerManage`),recentSkillsLabel:a,allSkillsLabel:t}})}function DO(){let e=QD(),{language:t}=ut(),{isMobile:n}=ft(),r=Q(e=>e.snapshot),i=k(),[a,s]=(0,P.useState)(null),c=(0,P.useRef)(null),l=(0,P.useRef)(null),u=SO(t),{skillRecords:d,modelRecords:f,recentModelValues:p,recentSkillValues:m,recentSkillGroupValues:h}=CO(r,u.skillScopeLabels),g=mO(r),_=hO(r),v=gO(r),y=_O(r),b=typeof e.chatInputManager.addAttachments==`function`,x=o(v?`chatModelNoOptions`:n?`chatInputPlaceholderCompact`:`chatInputPlaceholder`),S=(0,P.useMemo)(()=>qD(d,a??``,u.slashTexts,m),[u.slashTexts,m,d,a]),C=f.find(e=>e.value===r.selectedModel),w=C?.thinkingCapability?.supported??[],T=r.stopDisabledReason===`__preparing__`?o(`chatStopPreparing`):r.stopDisabledReason?.trim()||o(`chatStopUnavailable`),{handleFilesAdd:E,handleFileInputChange:D}=wO({attachmentSupported:b,inputBarRef:c,presenter:e}),O=TO({allModelsLabel:u.allModelsLabel,hasModelOptions:g,isModelOptionsLoading:_,modelRecords:f,presenter:e,recentModelValues:p,recentModelsLabel:u.recentModelsLabel,selectedModel:r.selectedModel,selectedThinkingLevel:r.selectedThinkingLevel,thinkingSupportedLevels:w,thinkingDefaultLevel:C?.thinkingCapability?.default??null}),ee=EO({allSkillsLabel:u.allSkillsLabel,presenter:e,recentSkillGroupValues:h,recentSkillValues:m,recentSkillsLabel:u.recentSkillsLabel,skillRecords:d,snapshot:r}),te=r.draft.trim().length>0||r.attachments.length>0||iO(r.composerNodes).length>0;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(pm,{ref:c,composer:{nodes:r.composerNodes,placeholder:x,disabled:y,onNodesChange:e.chatInputManager.setComposerNodes,...b?{onFilesAdd:E}:{},onSlashQueryChange:s},slashMenu:{isLoading:r.isSkillsLoading,items:S,onSelectItem:t=>{t.value&&e.chatInputManager.rememberSkillSelection(t.value)},texts:{slashLoadingLabel:o(`chatSlashLoading`),slashSectionLabel:o(`chatSlashSectionSkills`),slashEmptyLabel:o(`chatSlashNoResult`),slashHintLabel:o(`chatSlashHint`),slashSkillHintLabel:o(`chatSlashSkillHint`)}},hint:LD({isModelOptionsLoading:_,isModelOptionsEmpty:v,onGoToProviders:e.chatInputManager.goToProviders,texts:{noModelOptionsLabel:o(`chatModelNoOptions`),configureProviderLabel:o(`chatGoConfigureProvider`)}}),toolbar:{selects:O,accessories:[{key:`attach`,label:o(`chatInputAttach`),icon:`paperclip`,iconOnly:!0,disabled:!b||y||r.isSending,...b?{onClick:()=>l.current?.click()}:{tooltip:o(`chatInputAttachComingSoon`)}}],skillPicker:ee,actions:{sendError:i.isBlocked?null:r.sendError,isSending:r.isSending,canStopGeneration:r.canStopGeneration,sendDisabled:vO({snapshot:r,hasSendableDraft:te,isRuntimeBlocked:i.isBlocked}),stopDisabled:!r.canStopGeneration,stopHint:T,sendButtonLabel:o(`chatSend`),stopButtonLabel:o(`chatStop`),onSend:e.chatInputManager.send,onStop:e.chatInputManager.stop}}}),b?(0,N.jsx)(`input`,{ref:l,type:`file`,multiple:!0,className:`hidden`,onChange:D}):null]})}var OO=[`cmd`,`command`,`query`,`q`,`path`,`url`,`to`,`channel`,`agentId`,`sessionKey`];function kO(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function AO(e,t=2400){return e.length<=t?e:`${e.slice(0,t)}\n…`}function jO(e,t=120){let n=e.replace(/\s+/g,` `).trim();return n.length<=t?n:t<=1?`…`:`${n.slice(0,t-1)}…`}function MO(e){if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);if(e==null)return``;try{return AO(JSON.stringify(e,null,2))}catch{return String(e)}}function NO(e){if(kO(e))return e;if(typeof e!=`string`)return null;let t=e.trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`))return null;try{let e=JSON.parse(t);return kO(e)?e:null}catch{return null}}function PO(e){let t=NO(e);if(!t){let t=MO(e).trim();return t?jO(t,120):void 0}let n=[];for(let e of OO){let r=t[e];if(typeof r==`string`&&r.trim()?n.push(`${e}: ${r.trim()}`):(typeof r==`number`||typeof r==`boolean`)&&n.push(`${e}: ${String(r)}`),n.length>=2)break}return n.length>0?jO(n.join(` · `),120):jO(MO(t),140)}var FO=`ui_inline_tokens`,IO=`$`;function LO(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function RO(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function zO(e){let t=new Set,n=[];for(let r of e){let e=`${r.kind}:${r.key}:${r.rawText}`;t.has(e)||(t.add(e),n.push(r))}return n}function BO(e){let t=[];for(let n of e)n.type!==`token`||n.tokenKind!==`skill`||t.push({kind:`skill`,key:n.tokenKey,label:n.label,rawText:`${IO}${n.tokenKey}`});return zO(t)}function VO(e){let t=e?.[FO];if(!Array.isArray(t))return[];let n=[];for(let e of t){if(!LO(e))continue;let t=RO(e.kind),r=RO(e.key),i=RO(e.rawText);!t||!r||!i||n.push({kind:t,key:r,rawText:i,label:RO(e.label)??r})}return zO(n)}function HO(e,t){if(e.length===0||t.length===0)return e.length===0?[]:[{type:`text`,text:e}];let n=[...t].sort((e,t)=>t.rawText.length-e.rawText.length),r=[],i=0;for(;i<e.length;){let t=null;for(let r of n)if(e.startsWith(r.rawText,i)){t=r;break}if(!t){let t=i+1;for(;t<e.length&&!n.some(n=>e.startsWith(n.rawText,t));)t+=1;r.push({type:`text`,text:e.slice(i,t)}),i=t;continue}r.push({type:`token`,token:t}),i+=t.rawText.length}return r}var UO=/\u200B|\u200C|\u200D|\u2060|\uFEFF/g;function WO(e){let t=e.trim();return t&&t.replace(UO,``).trim()?t:null}function GO(e){return e.replace(UO,``).trim().length>0}function KO(e,t){let n=HO(e,t);if(n.length===0)return null;let r=[],i=!1;for(let e of n){if(e.type===`token`){i=!0,r.push({type:`token`,token:{kind:e.token.kind,key:e.token.key,label:e.token.label,rawText:e.token.rawText}});continue}e.text.length!==0&&(GO(e.text)&&(i=!0),r.push({type:`markdown`,text:e.text}))}return i?r:null}function qO(e,t){let n=KO(e.text,t);if(n&&n.some(e=>e.type===`token`))return{type:`inline-content`,segments:n};let r=WO(e.text);return r?{type:`markdown`,text:r}:null}function JO(e){return WO(e)}function YO(e){return typeof e==`object`&&!!e}function XO(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function ZO(e){if(typeof e==`number`&&Number.isFinite(e)&&e>=0)return e;if(typeof e!=`string`)return null;let t=e.trim();if(!t)return null;let n=Number(t);return Number.isFinite(n)&&n>=0?n:null}function QO(e){return YO(e)?`command`in e||`workingDir`in e||`exitCode`in e||`stdout`in e||`stderr`in e||`aggregated_output`in e||`combinedOutput`in e:!1}function $O(e,t){if(!YO(e))return null;let n=YO(e.asset)?e.asset:Array.isArray(e.assets)&&e.assets.length>0&&YO(e.assets[0])?e.assets[0]:null;if(!n)return null;let r=XO(n.url),i=XO(n.mimeType)??`application/octet-stream`,a=ZO(n.sizeBytes);return r?{type:`file`,file:{label:XO(n.name)??(i.startsWith(`image/`)?t.imageAttachmentLabel:t.fileAttachmentLabel),mimeType:i,dataUrl:r,...a==null?{}:{sizeBytes:a},isImage:i.startsWith(`image/`)}}:null}function ek(e,t){return{kind:e.kind,toolName:e.name,...`agentId`in e&&e.agentId?{agentId:e.agentId}:{},summary:e.detail,inputLabel:t.toolInputLabel,input:`input`in e&&typeof e.input==`string`?e.input:void 0,output:e.text,outputData:e.outputData,hasResult:!!e.hasResult,statusTone:e.statusTone,statusLabel:e.statusLabel,titleLabel:e.kind===`call`?t.toolCallLabel:t.toolResultLabel,outputLabel:t.toolOutputLabel,emptyLabel:t.toolNoOutputLabel,...`action`in e&&e.action?{action:e.action}:{},...`fileOperation`in e&&e.fileOperation?{fileOperation:e.fileOperation}:{}}}function tk(e){let t=typeof e.status==`string`?e.status.trim().toLowerCase():``,n=typeof e.error==`string`&&e.error.trim().length>0;return e.cancelled===!0||t===`cancelled`?{kind:`result`,hasResult:!0,statusTone:`cancelled`,statusLabel:e.texts.toolStatusCancelledLabel}:n||t===`error`?{kind:`result`,hasResult:!0,statusTone:`error`,statusLabel:e.texts.toolStatusFailedLabel}:t===`result`||e.result!=null?{kind:`result`,hasResult:!0,statusTone:`success`,statusLabel:e.texts.toolStatusCompletedLabel}:{kind:`call`,hasResult:!1,statusTone:`running`,statusLabel:e.texts.toolStatusRunningLabel}}function nk(e){if(typeof e!=`string`)return e;let t=e.trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`))return e;try{return JSON.parse(t)}catch{return e}}function rk(e,t){return MO(t??nk(e)).trim()||void 0}function ik(e){return typeof e==`object`&&!!e}function ak(e){if(typeof e!=`string`)return e;let t=e.trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`))return e;try{return JSON.parse(t)}catch{return e}}function ok(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function sk(e){let t=ak(e);return ik(t)?ok(t.agentId):null}function ck(e){return sk(e.parsedArgs)??sk(e.args)??sk(e.result)}var lk=12e3,uk=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/;function dk(e){let t=e.replace(/\r\n/g,`
|
|
52
52
|
`).replace(/\r/g,`
|
|
53
53
|
`);return t===``?[]:t.split(`
|
|
54
|
-
`)}function
|
|
55
|
-
`;case`r`:return`\r`;case`t`:return` `;default:return e}}function
|
|
54
|
+
`)}function fk(e){return typeof e==`number`?e+1:void 0}function pk(e){return{kind:e.kind,text:e.text,...typeof e.oldLineNumber==`number`?{oldLineNumber:e.oldLineNumber}:{},...typeof e.newLineNumber==`number`?{newLineNumber:e.newLineNumber}:{}}}function mk(e){let t=uk.exec(e);return t?{oldLineNumber:Number(t[1]),newLineNumber:Number(t[2])}:null}function hk(e){return dk(e.text).map((t,n)=>e.kind===`add`?pk({kind:`add`,text:t,newLineNumber:e.newStartLine+n}):pk({kind:`context`,text:t,oldLineNumber:e.oldStartLine+n,newLineNumber:e.newStartLine+n}))}function gk(e){let t=e.oldStartLine,n=e.newStartLine;return[...e.beforeLines.map(e=>{let n=pk({kind:`remove`,text:e,oldLineNumber:t});return t=fk(t),n}),...e.afterLines.map(e=>{let t=pk({kind:`add`,text:e,newLineNumber:n});return n=fk(n),t})]}function _k(e){let t=Array.from({length:e.beforeLines.length+1},()=>Array.from({length:e.afterLines.length+1},()=>0));for(let n=e.beforeLines.length-1;n>=0;--n)for(let r=e.afterLines.length-1;r>=0;--r)t[n][r]=e.beforeLines[n]===e.afterLines[r]?(t[n+1][r+1]??0)+1:Math.max(t[n+1][r]??0,t[n][r+1]??0);return t}function vk(e){for(let t=e.beforeIndex;t<e.beforeLines.length;t+=1)e.lines.push(pk({kind:`remove`,text:e.beforeLines[t]??``,oldLineNumber:e.oldLineNumber})),e.oldLineNumber=fk(e.oldLineNumber);for(let t=e.afterIndex;t<e.afterLines.length;t+=1)e.lines.push(pk({kind:`add`,text:e.afterLines[t]??``,newLineNumber:e.newLineNumber})),e.newLineNumber=fk(e.newLineNumber)}function yk(e){let t=dk(e.beforeText),n=dk(e.afterText);if(t.length*n.length>lk)return gk({beforeLines:t,afterLines:n,oldStartLine:e.oldStartLine,newStartLine:e.newStartLine});let r=_k({beforeLines:t,afterLines:n}),i=[],a=0,o=0,s=e.oldStartLine,c=e.newStartLine;for(;a<t.length&&o<n.length;){if(t[a]===n[o]){i.push(pk({kind:`context`,text:t[a]??``,oldLineNumber:s,newLineNumber:c})),a+=1,o+=1,s=fk(s),c=fk(c);continue}if((r[a+1][o]??0)>=(r[a][o+1]??0)){i.push(pk({kind:`remove`,text:t[a]??``,oldLineNumber:s})),a+=1,s=fk(s);continue}i.push(pk({kind:`add`,text:n[o]??``,newLineNumber:c})),o+=1,c=fk(c)}return vk({lines:i,beforeLines:t,afterLines:n,beforeIndex:a,afterIndex:o,oldLineNumber:s,newLineNumber:c}),i}var bk=120;function xk(e){let t=e.lines.filter(e=>e.kind===`add`).length,n=e.lines.filter(e=>e.kind===`remove`).length,r=[],i=e.operation?.trim().toLowerCase()??``;return i&&i!==`update`&&r.push(i),t>0&&r.push(`+${t}`),n>0&&r.push(`-${n}`),r.length>0?r.join(` · `):void 0}function Sk(e){let t=e.operation?.trim().toLowerCase()??``;return{oldStartLine:typeof e.oldStartLine==`number`?e.oldStartLine:(t===`delete`||t===`remove`)&&e.beforeText!=null?1:void 0,newStartLine:typeof e.newStartLine==`number`?e.newStartLine:(t===`write`||t===`add`)&&e.afterText!=null?1:void 0}}function Ck(e){return e.length<=bk?{lines:e,truncated:!1}:{lines:e.slice(0,bk),truncated:!0}}function wk(e){let t=Ck(e.lines);return{path:e.path,display:`diff`,caption:xk({operation:e.operation,lines:e.lines}),lines:t.lines,...t.truncated?{fullLines:e.lines}:{},truncated:t.truncated}}function Tk(e){let t=e.text.trim();if(!t)return null;let n=e.operation?.trim().toLowerCase()===`write`?`add`:`context`,r=typeof e.oldStartLine==`number`?e.oldStartLine:1,i=typeof e.newStartLine==`number`?e.newStartLine:1,a=hk({text:t,kind:n,oldStartLine:r,newStartLine:i});return{path:e.path,display:`preview`,caption:xk({operation:e.operation,lines:a}),lines:a,rawText:t,oldStartLine:r,newStartLine:i}}function Ek(e){let{oldStartLine:t,newStartLine:n}=Sk(e),r=yk({beforeText:e.beforeText??``,afterText:e.afterText??``,oldStartLine:t,newStartLine:n}),i=Ck(r);return i.lines.length===0?null:{path:e.path,display:`diff`,caption:xk({operation:e.operation,lines:r}),lines:i.lines,...i.truncated?{fullLines:r}:{},...e.beforeText==null?{}:{beforeText:e.beforeText},...e.afterText==null?{}:{afterText:e.afterText},...typeof t==`number`?{oldStartLine:t}:{},...typeof n==`number`?{newStartLine:n}:{},truncated:i.truncated}}function Dk(e){return e.line.startsWith(`*** Update File: `)?(e.flushCurrent(),e.setCurrent(e.line.slice(17).trim(),`update`),!0):e.line.startsWith(`*** Add File: `)?(e.flushCurrent(),e.setCurrent(e.line.slice(14).trim(),`add`),!0):e.line.startsWith(`*** Delete File: `)?(e.flushCurrent(),e.setCurrent(e.line.slice(17).trim(),`delete`),!0):!1}function Ok(e){let{currentLines:t,line:n}=e;return n.startsWith(`+`)?(t.push(pk({kind:`add`,text:n.slice(1),newLineNumber:e.newLineNumber})),{oldLineNumber:e.oldLineNumber,newLineNumber:fk(e.newLineNumber)}):n.startsWith(`-`)?(t.push(pk({kind:`remove`,text:n.slice(1),oldLineNumber:e.oldLineNumber})),{oldLineNumber:fk(e.oldLineNumber),newLineNumber:e.newLineNumber}):n.startsWith(` `)?(t.push(pk({kind:`context`,text:n.slice(1),oldLineNumber:e.oldLineNumber,newLineNumber:e.newLineNumber})),{oldLineNumber:fk(e.oldLineNumber),newLineNumber:fk(e.newLineNumber)}):{oldLineNumber:e.oldLineNumber,newLineNumber:e.newLineNumber}}function kk(e){let t=[],n=null,r=null,i=[],a,o,s=()=>{if(!n){i=[],r=null,a=void 0,o=void 0;return}t.push(wk({path:n,operation:r,lines:i})),n=null,r=null,i=[],a=void 0,o=void 0};for(let t of dk(e)){if(Dk({line:t,flushCurrent:s,setCurrent:(e,t)=>{n=e,r=t}})||t.startsWith(`*** Move to: `)||t.startsWith(`*** Begin Patch`)||t.startsWith(`*** End Patch`))continue;if(t.startsWith(`@@`)){let e=mk(t);a=e?.oldLineNumber,o=e?.newLineNumber;continue}if(!n)continue;let e=Ok({currentLines:i,line:t,oldLineNumber:a,newLineNumber:o});a=e.oldLineNumber,o=e.newLineNumber}return s(),t}function Ak(e){let t=[],n=null,r=[],i,a,o=()=>{if(!n){r=[],i=void 0,a=void 0;return}t.push(wk({path:n,operation:`update`,lines:r})),n=null,r=[],i=void 0,a=void 0};for(let t of dk(e)){if(t.startsWith(`+++ `)){o(),n=t.slice(4).trim().replace(/^b\//,``).replace(/^a\//,``);continue}if(t.startsWith(`--- `))continue;if(t.startsWith(`@@`)){let e=mk(t);i=e?.oldLineNumber,a=e?.newLineNumber;continue}if(!n)continue;let e=Ok({currentLines:r,line:t,oldLineNumber:i,newLineNumber:a});i=e.oldLineNumber,a=e.newLineNumber}return o(),t}function jk(e){return e.includes(`*** Begin Patch`)?kk(e):e.includes(`--- `)&&e.includes(`+++ `)?Ak(e):[]}function Mk(e){switch(e){case`"`:case`\\`:case`/`:return e;case`b`:return`\b`;case`f`:return`\f`;case`n`:return`
|
|
55
|
+
`;case`r`:return`\r`;case`t`:return` `;default:return e}}function Nk(e,t){let n=`"${t}"`,r=e.indexOf(n);if(r<0)return null;let i=e.indexOf(`:`,r+n.length);if(i<0)return null;let a=i+1;for(;a<e.length&&/\s/.test(e[a]??``);)a+=1;return e[a]===`"`?a+1:null}function Pk(e,t,n=1/0){let r=``,i=!1;for(let a=t;a<e.length;a+=1){let t=e[a];if(t==null)break;if(i){r+=Mk(t),i=!1;continue}if(t===`\\`){i=!0;continue}if(t===`"`)return{value:r,truncated:!1};if(r+=t,r.length>=n)return{value:r,truncated:!0}}return r.length>0?{value:r,truncated:!1}:null}function Fk(e,t,n=1/0){for(let r of t){let t=Nk(e,r);if(t!=null)return Pk(e,t,n)}return null}function Ik(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function Lk(e){return typeof e==`string`&&e.trim()?e.trim():null}function Rk(e){return typeof e==`number`&&Number.isInteger(e)&&e>0?e:typeof e==`string`&&/^\d+$/.test(e.trim())?Number(e.trim()):null}function zk(e){if(Ik(e))return e;if(typeof e!=`string`)return null;let t=e.trim();if(!t.startsWith(`{`))return null;try{let e=JSON.parse(t);return Ik(e)?e:null}catch{return null}}function Bk(e){if(Ik(e))return e;if(typeof e!=`string`)return null;let t=e.trim();if(!t.startsWith(`{`))return null;let n=Fk(t,[`path`,`filePath`,`file_path`,`targetPath`,`target_path`,`filename`,`name`])?.value??null,r=Fk(t,[`content`,`text`,`afterText`,`after_text`])?.value??null,i=Fk(t,[`oldText`,`beforeText`,`before_text`])?.value??null,a=Fk(t,[`newText`,`afterText`,`after_text`])?.value??null,o=Fk(t,[`patch`,`diff`,`unifiedDiff`,`unified_diff`])?.value??null,s={};return n&&(s.path=n),r&&(s.content=r),i&&(s.oldText=i),a&&(s.newText=a),o&&(s.patch=o),Object.keys(s).length>0?s:null}function Vk(e){return Lk(e.path)??Lk(e.filePath)??Lk(e.file_path)??Lk(e.targetPath)??Lk(e.target_path)??Lk(e.filename)??Lk(e.name)}function Hk(e){return $(e.operation)??$(e.op)??$(e.action)??$(e.kind)??$(e.type)??$(e.status)}function Uk(e,t){for(let n of t){let t=Rk(e[n]);if(t!==null)return t}return null}function Wk(e){return Uk(e,[`oldStartLine`,`old_start_line`,`startOldLine`,`start_old_line`,`oldLineStart`,`old_line_start`,`oldLineNumber`,`old_line_number`,`lineStart`,`line_start`,`startLine`,`start_line`,`lineNumber`,`line_number`])}function Gk(e){return Uk(e,[`newStartLine`,`new_start_line`,`startNewLine`,`start_new_line`,`newLineStart`,`new_line_start`,`newLineNumber`,`new_line_number`,`lineStart`,`line_start`,`startLine`,`start_line`,`lineNumber`,`line_number`])}function Kk(e){return $(e.patch)??$(e.diff)??$(e.unifiedDiff)??$(e.unified_diff)}function qk(e){return $(e.beforeText)??$(e.before_text)??$(e.oldText)??$(e.old_text)??$(e.oldContent)??$(e.old_content)??$(e.before)??$(e.previous)}function Jk(e){return $(e.afterText)??$(e.after_text)??$(e.newText)??$(e.new_text)??$(e.newContent)??$(e.new_content)??$(e.content)??$(e.text)??$(e.after)??$(e.updated)}var Yk=new Set([`file_change`,`read_file`,`write_file`,`edit_file`,`apply_patch`]);function Xk(e){let t=e.map((e,t)=>({key:`${e.path}-${t+1}`,path:e.path,display:e.display,...e.caption?{caption:e.caption}:{},lines:e.lines,...e.fullLines?{fullLines:e.fullLines}:{},...e.rawText?{rawText:e.rawText}:{},...e.beforeText?{beforeText:e.beforeText}:{},...e.afterText?{afterText:e.afterText}:{},...typeof e.oldStartLine==`number`?{oldStartLine:e.oldStartLine}:{},...typeof e.newStartLine==`number`?{newStartLine:e.newStartLine}:{},...e.truncated?{truncated:!0}:{}})).filter(e=>e.lines.length>0||!!e.rawText);if(t.length===0)return null;let n=t.map(e=>e.path);return{summary:n.length===1?n[0]:`${n.length} files · ${n.slice(0,2).join(` · `)}${n.length>2?` …`:``}`,fileOperation:{blocks:t}}}function Zk(e,t){let n=Vk(e)??t,r=Hk(e),i=Wk(e),a=Gk(e),o=Kk(e);if(o){let e=jk(o);if(e.length>0)return e[0]??null}let s=qk(e),c=Jk(e);if(s!=null||c!=null)return Ek({path:n,beforeText:s,afterText:c,operation:r,oldStartLine:i,newStartLine:a});let l=$(e.preview);return l?Tk({path:n,text:l,operation:r,oldStartLine:i,newStartLine:a}):null}function Qk(e){if(!Array.isArray(e))return[];let t=[];return e.forEach((e,n)=>{if(typeof e==`string`){let n=jk(e);n.length>0&&t.push(...n);return}if(!Ik(e))return;let r=Zk(e,Vk(e)??`file-${n+1}`);if(r){t.push(r);return}let i=Array.isArray(e.changes)?Qk(e.changes):[];i.length>0&&t.push(...i)}),t}function $k(e){let t=zk(e.result)??zk(e.parsedArgs)??zk(e.args);return t?Xk(Qk(t.changes)):null}function eA(e){let t=zk(e.parsedArgs)??zk(e.args)??Bk(e.args),n=t&&Vk(t),r=$(e.result);return!n||!r?null:Xk([Tk({path:n,text:r,operation:`read`})].filter(e=>!!e))}function tA(e){if(e.status===`partial-call`&&typeof e.args==`string`){let t=Fk(e.args,[`path`,`filePath`,`file_path`,`targetPath`,`target_path`,`filename`,`name`]),n=Fk(e.args,[`content`,`text`,`afterText`,`after_text`]);if(t?.value&&n?.value){let e=Tk({path:t.value,text:n.value,operation:`write`});if(e)return Xk([e])}}let t=zk(e.parsedArgs)??zk(e.args)??Bk(e.args);if(!t)return null;let n=Vk(t),r=$(t.content);return!n||!r?null:Xk([Tk({path:n,text:r,operation:`write`})].filter(e=>!!e))}function nA(e){let t=zk(e.result),n=zk(e.parsedArgs)??zk(e.args)??Bk(e.args);if(!t&&!n)return null;let r=(t?Vk(t):null)??(n?Vk(n):null),i=(t?qk(t):null)??(n?qk(n):null),a=(t?Jk(t):null)??(n?Jk(n):null),o=(t?Wk(t):null)??(n?Wk(n):null),s=(t?Gk(t):null)??(n?Gk(n):null);return!r||i==null&&a==null?null:Xk([Ek({path:r,beforeText:i,afterText:a,operation:`edit`,oldStartLine:o,newStartLine:s})].filter(e=>!!e))}function rA(e){let t=zk(e.parsedArgs),n=zk(e.args)??Bk(e.args),r=$(e.args)??(t?$(t.patch):null)??(n?$(n.patch):null);return r?Xk(jk(r)):null}function iA(e){return Yk.has(e.toolName)?e.toolName===`file_change`?$k(e):e.toolName===`read_file`?eA(e):e.toolName===`write_file`?tA(e):e.toolName===`edit_file`?nA(e):e.toolName===`apply_patch`?rA(e):null:null}function aA(e){return typeof e==`object`&&!!e}function oA(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function sA(e){return!aA(e)||e.kind!==`nextclaw.session_request`?null:e}function cA(e){return!aA(e)||e.kind!==`nextclaw.session`?null:e}function lA(e){if(typeof e!=`string`)return e;let t=e.trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`))return e;try{return JSON.parse(t)}catch{return e}}function uA(e){return MO(lA(e)).trim()||void 0}function dA(e,t){return[oA(e.title)?`title: ${e.title?.trim()}`:null,oA(e.sessionId)?`session: ${e.sessionId?.trim()}`:null,oA(e.task)?`task: ${e.task?.trim()}`:null].filter(e=>!!e).join(` · `)||PO(t)}function fA(e,t){return[oA(e.title)?`title: ${e.title?.trim()}`:null,oA(e.sessionId)?`session: ${e.sessionId?.trim()}`:null].filter(e=>!!e).join(` · `)||PO(t)}function pA(e){let t=oA(e.requestId),n=oA(e.sessionId),r=oA(e.title),i=oA(e.task),a=oA(e.status),o=oA(e.notify),s=oA(e.lifecycle),c=oA(e.parentSessionId),l=oA(e.spawnedByRequestId),u=e.message===void 0?``:MO(e.message).trim(),d=e.finalResponseText===void 0?``:MO(e.finalResponseText).trim(),f=e.error===void 0?``:MO(e.error).trim(),p=[t?`Request ID: ${t}`:null,n?`Session ID: ${n}`:null,typeof e.isChildSession==`boolean`?`Target: ${e.isChildSession?`child`:`session`}`:null,a?`Status: ${a}`:null,o?`Notify: ${o}`:null,s?`Lifecycle: ${s}`:null,c?`Parent Session ID: ${c}`:null,l?`Spawned By Request ID: ${l}`:null,r?`Title: ${r}`:null,i?`Task:\n${i}`:null,d?`Final Response:\n${d}`:f?`Error:\n${f}`:u?`Status:\n${u}`:null].filter(e=>!!e);return p.length>0?p.join(`
|
|
56
56
|
|
|
57
|
-
`):void 0}function
|
|
57
|
+
`):void 0}function mA(e){let t=oA(e.sessionId),n=oA(e.title),r=oA(e.sessionType),i=oA(e.lifecycle),a=oA(e.parentSessionId),o=oA(e.createdAt),s=[t?`Session ID: ${t}`:null,typeof e.isChildSession==`boolean`?`Target: ${e.isChildSession?`child`:`session`}`:null,n?`Title: ${n}`:null,r?`Session Type: ${r}`:null,i?`Lifecycle: ${i}`:null,a?`Parent Session ID: ${a}`:null,o?`Created At: ${o}`:null].filter(e=>!!e);return s.length>0?s.join(`
|
|
58
58
|
|
|
59
|
-
`):void 0}function pA(e){let{invocation:t,texts:n}=e,{toolName:r,toolCallId:i,args:a,result:o}=t;if(r!==`spawn`&&r!==`sessions_request`&&r!==`sessions_spawn`)return null;let s=aA(o);if(s){let e=iA(s.status)?.toLowerCase(),t=lA(s,a),o=dA(s),c=iA(s.sessionId),l=ok({args:a,result:s}),u=c?{kind:`open-session`,sessionId:c,sessionKind:s.isChildSession===!0?`child`:`session`,...l?{agentId:l}:{},...iA(s.title)?{label:s.title.trim()}:{},...iA(s.parentSessionId)?{parentSessionId:s.parentSessionId.trim()}:{}}:void 0;return e===`failed`?{kind:`result`,name:r,detail:t,input:cA(a),text:o,callId:i||void 0,hasResult:!!o,statusTone:`error`,statusLabel:n.toolStatusFailedLabel,...l?{agentId:l}:{},...u?{action:u}:{}}:e===`completed`?{kind:`result`,name:r,detail:t,input:cA(a),text:o,callId:i||void 0,hasResult:!!o,statusTone:`success`,statusLabel:n.toolStatusCompletedLabel,...l?{agentId:l}:{},...u?{action:u}:{}}:{kind:`result`,name:r,detail:t,input:cA(a),text:o,callId:i||void 0,hasResult:!!o,statusTone:`running`,statusLabel:n.toolStatusRunningLabel,...l?{agentId:l}:{},...u?{action:u}:{}}}let c=oA(o);if(!c)return null;let l=uA(c,a),u=fA(c),d=iA(c.sessionId),f=ok({args:a,result:c}),p=d?{kind:`open-session`,sessionId:d,sessionKind:c.isChildSession===!0?`child`:`session`,...f?{agentId:f}:{},...iA(c.title)?{label:c.title.trim()}:{},...iA(c.parentSessionId)?{parentSessionId:c.parentSessionId.trim()}:{}}:void 0;return{kind:`result`,name:r,detail:l,input:cA(a),text:u,callId:i||void 0,hasResult:!!u,statusTone:`success`,statusLabel:n.toolStatusCompletedLabel,...f?{agentId:f}:{},...p?{action:p}:{}}}function mA(e,t){let n=KO(e.reasoning);return n?{type:`reasoning`,text:n,label:t.reasoningLabel}:null}function hA(e,t){let n=e.mimeType.startsWith(`image/`),r=YO(e.sizeBytes);return{type:`file`,file:{label:typeof e.name==`string`&&e.name.trim()?e.name.trim():n?t.imageAttachmentLabel:t.fileAttachmentLabel,mimeType:e.mimeType,dataUrl:typeof e.url==`string`&&e.url.trim().length>0?e.url.trim():`data:${e.mimeType};base64,${e.data}`,...r==null?{}:{sizeBytes:r},isImage:n}}}function gA(e,t){let n=e.toolInvocation,r=ZO(n.result,t);if(r)return r;let i=pA({invocation:n,texts:{toolStatusRunningLabel:t.toolStatusRunningLabel,toolStatusCompletedLabel:t.toolStatusCompletedLabel,toolStatusFailedLabel:t.toolStatusFailedLabel}});if(i)return{type:`tool-card`,card:QO(i,t)};let a=$O({status:n.status,error:n.error,cancelled:n.cancelled,result:n.result,texts:t}),o=nA({toolName:n.toolName,status:n.status,toolCallId:n.toolCallId,args:n.args,parsedArgs:n.parsedArgs,result:n.result}),s=o?.summary??MO(n.parsedArgs??n.args),c=o?void 0:tk(n.args,n.parsedArgs),l=typeof n.error==`string`&&n.error.trim()?n.error.trim():n.result==null?``:AO(n.result).trim(),u=!n.error&&XO(n.result),d=(!o?.fileOperation||!!n.error)&&!u,f=ok(n);return{type:`tool-card`,card:QO({kind:a.kind,name:n.toolName,...f?{agentId:f}:{},detail:s,...c?{input:c}:{},text:d&&l?l:void 0,outputData:n.result,callId:n.toolCallId||void 0,hasResult:a.hasResult,statusTone:a.statusTone,statusLabel:a.statusLabel,...o?.fileOperation?{fileOperation:o.fileOperation}:{}},t)}}function _A(e,t){return{type:`unknown`,label:t.unknownPartLabel,rawType:typeof e.type==`string`?e.type:`unknown`,text:AO(e)}}function vA(e){return e.type===`text`&&typeof e.text==`string`}function yA(e){return e.type===`reasoning`&&typeof e.reasoning==`string`}function bA(e){return e.type===`file`&&typeof e.mimeType==`string`&&typeof e.data==`string`}function xA(e){return e.type!==`tool-invocation`||typeof e.toolInvocation!=`object`||e.toolInvocation===null||Array.isArray(e.toolInvocation)?!1:`toolName`in e.toolInvocation&&typeof e.toolInvocation.toolName==`string`}function SA(e){return vA(e.part)?GO(e.part,e.inlineTokens):yA(e.part)?mA(e.part,e.texts):bA(e.part)?hA(e.part,e.texts):xA(e.part)?gA(e.part,e.texts):_A(e.part,e.texts)}function CA(e){let t=e.meta?.timestamp;return t&&Number.isFinite(Date.parse(t))?t:new Date().toISOString()}function wA(e,t){return e===`user`?t.user:e===`assistant`?t.assistant:e===`tool`?t.tool:e===`system`?t.system:t.fallback}function TA(e){return e===`user`||e===`assistant`||e===`tool`||e===`system`?e:`message`}function EA(e,t){return{id:e.id,role:TA(e.role),roleLabel:wA(e.role,t.texts.roleLabels),timestampLabel:t.formatTimestamp(CA(e)),status:e.meta?.status,parts:e.parts.map(n=>SA({part:n,inlineTokens:e.meta?.inlineTokens??[],texts:t.texts})).filter(e=>e!==null)}}var DA=function(e){return e.CALL=`call`,e.RESULT=`result`,e.PARTIAL_CALL=`partial-call`,e.ERROR=`error`,e.CANCELLED=`cancelled`,e}({});function OA(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function kA(e){return OA(e)}function AA(e){let t=OA(e);if(!t)return null;let n=t.replace(/[\\/]+$/,``);if(!n)return t;let r=n.split(/[\\/]/).filter(Boolean);return r[r.length-1]??n}function jA(e){return/^[A-Za-z]:[\\/]?$/.test(e)||e===`/`?e:e.replace(/[\\/]+$/,``)}function MA(e){let t=jA(e.trim().replace(/\\/g,`/`));return/^[A-Za-z]:/.test(t)?`${t.slice(0,1).toLowerCase()}${t.slice(1)}`:t}function NA(e){let t=e.trim().replace(/\\/g,`/`);return t?/^[A-Za-z]:\//.test(t)?{prefix:t.slice(0,2),segments:t.slice(3).split(`/`).filter(Boolean)}:t.startsWith(`/`)?{prefix:`/`,segments:t.slice(1).split(`/`).filter(Boolean)}:{prefix:null,segments:t.split(`/`).filter(Boolean)}:{prefix:null,segments:[]}}function PA(e){let t=MA(e.path),n=MA(e.sessionProjectRoot);if(!t||!n)return null;if(!t.startsWith(`/`)&&!/^[A-Za-z]:\//.test(t))return t.split(`/`).filter(Boolean);if(t===n)return[];let r=n.endsWith(`/`)?n:`${n}/`;return t.startsWith(r)?t.slice(r.length).split(`/`).filter(Boolean):null}function FA(e){let{labels:t,leading:n=null}=e,r=t.map((e,n)=>({key:`${n}:${e}`,label:e,kind:n===t.length-1?`file`:`directory`,isCurrent:n===t.length-1}));return n?[n,...r]:r}function IA(e){let{column:t,line:n}=e;return typeof n==`number`?`L${n}${typeof t==`number`?`:${t}`:``}`:null}function LA(e){let{column:t,line:n,path:r,sessionProjectRoot:i,truncated:a}=e,o=r.trim(),s=i?.trim()&&o?PA({path:o,sessionProjectRoot:i}):null,c;if(i?.trim()&&s){let e=AA(i)??i.trim();c=FA({labels:s,leading:{key:`workspace:${e}`,label:e,kind:`workspace`,isCurrent:s.length===0}})}else{let{prefix:e,segments:t}=NA(o);c=FA({labels:t,leading:e?{key:`root:${e}`,label:e,kind:`root`,isCurrent:t.length===0}:null})}return c.length===0&&(c=[{key:`file:unknown`,label:o||`file`,kind:`file`,isCurrent:!0}]),{fullPath:o,locationLabel:IA({line:n,column:t}),truncated:a,segments:c}}var RA=new Set([`off`,`minimal`,`low`,`medium`,`high`,`adaptive`,`xhigh`]);function zA(e){if(typeof e==`string`)return e;try{return JSON.stringify(e??{})}catch{return String(e??``)}}function BA(e){return`${re}/api/ncp/assets/content?${new URLSearchParams({uri:e}).toString()}`}function VA(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function HA(e){let{metadata:t}=e;return!t||typeof t!=`object`||Array.isArray(t)?null:t}function UA(e){let t=HA(e);return t?VA(t.preferred_model)??VA(t.preferredModel)??VA(t.model):null}function WA(e){let t=HA(e);if(!t)return null;let n=VA(t.preferred_thinking)??VA(t.thinking)??VA(t.thinking_level)??VA(t.thinkingLevel);if(!n)return null;let r=n.toLowerCase();return RA.has(r)?r:null}function GA(e){let t=HA(e);return t?VA(t.label):null}function KA(e){let t=HA(e);return t?kA(t.project_root??t.projectRoot):null}function qA(e){let t=HA(e);return t?VA(t.ui_last_read_at):null}function JA(e){let t=HA(e);return t?VA(t.runtime)??VA(t.session_type)??VA(t.sessionType)??`native`:`native`}function YA(e){let t=HA(e);return t?VA(t.parent_session_id)??VA(t.parentSessionId):null}function XA(e){let t=HA(e);return t?VA(t.spawned_by_request_id)??VA(t.spawnedByRequestId):null}function ZA(e){let t=HA(e);return t?t.child_session_promoted===!0:!1}function QA(e){if(e===`heartbeat`)return{type:`heartbeat`};if(e.startsWith(`cron:`))return{type:`cron`};if(e.startsWith(`agent:`)){let t=e.split(`:`);if(t.length>=3){let e=t[2];if(e&&e!==`main`&&e!==`direct`)return{channel:e}}}return{}}function $A(e){return e.state===`cancelled`?DA.CANCELLED:e.state===`result`?DA.RESULT:e.state===`partial-call`?DA.PARTIAL_CALL:DA.CALL}function ej(e){let t=[];for(let n of e){if(n.type===`text`){t.push({type:`text`,text:n.text});continue}if(n.type===`rich-text`){t.push({type:`text`,text:n.text});continue}if(n.type===`reasoning`){t.push({type:`reasoning`,reasoning:n.text,details:[]});continue}if(n.type===`source`){t.push({type:`source`,source:{sourceType:`url`,id:n.url??n.title??Math.random().toString(36).slice(2,8),url:n.url??``,...n.title?{title:n.title}:{}}});continue}if(n.type===`file`&&n.contentBase64){t.push({type:`file`,...n.name?{name:n.name}:{},mimeType:n.mimeType??`application/octet-stream`,data:n.contentBase64,...n.url?{url:n.url}:{},...typeof n.sizeBytes==`number`?{sizeBytes:n.sizeBytes}:{}});continue}if(n.type===`file`&&n.url){t.push({type:`file`,...n.name?{name:n.name}:{},mimeType:n.mimeType??`application/octet-stream`,data:``,url:n.url,...typeof n.sizeBytes==`number`?{sizeBytes:n.sizeBytes}:{}});continue}if(n.type===`file`&&n.assetUri){t.push({type:`file`,...n.name?{name:n.name}:{},mimeType:n.mimeType??`application/octet-stream`,data:``,url:BA(n.assetUri),...typeof n.sizeBytes==`number`?{sizeBytes:n.sizeBytes}:{}});continue}if(n.type===`step-start`){t.push({type:`step-start`});continue}n.type===`tool-invocation`&&t.push({type:`tool-invocation`,toolInvocation:{status:$A(n),toolCallId:n.toolCallId??`${n.toolName}-${Math.random().toString(36).slice(2,8)}`,toolName:n.toolName,args:zA(n.args),result:n.result}})}return t}function tj(e){return e===`service`?`system`:e===`tool`?`assistant`:e}function nj(e){return{id:e.id,role:tj(e.role),parts:ej(e.parts),meta:{source:`stream`,status:e.status,sessionKey:e.sessionId,timestamp:e.timestamp}}}function rj(e){let t=GA(e),n=UA(e),r=WA(e),i=KA(e),a=qA(e),o=VA(e.lastMessageAt),s=AA(i),c=QA(e.sessionId),l=YA(e),u=XA(e),d=ZA(e);return{key:e.sessionId,createdAt:e.updatedAt,updatedAt:e.updatedAt,...o?{lastMessageAt:o}:{},...a?{readAt:a}:{},...typeof e.agentId==`string`&&e.agentId.trim().length>0?{agentId:e.agentId.trim()}:{},...t?{label:t}:{},...c,...n?{preferredModel:n}:{},...r?{preferredThinking:r}:{},...i?{projectRoot:i}:{},...s?{projectName:s}:{},sessionType:JA(e),sessionTypeMutable:!1,isChildSession:!!l,...d?{isPromotedChildSession:d}:{},...l?{parentSessionId:l}:{},...u?{spawnedByRequestId:u}:{},messageCount:e.messageCount}}function ij(e){return e.map(rj)}function aj(){return`ncp-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function oj(){return g({queryKey:[`agents`],queryFn:A,staleTime:3e4})}function sj(){let e=se();return p({mutationFn:({data:e})=>E(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`agents`]}),e.invalidateQueries({queryKey:[`config`]}),y.success(o(`configSavedApplied`))},onError:e=>{y.error(o(`configSaveFailed`)+`: `+e.message)}})}function cj(){let e=se();return p({mutationFn:({agentId:e,data:t})=>ie(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`agents`]}),e.invalidateQueries({queryKey:[`config`]}),y.success(o(`configSavedApplied`))},onError:e=>{y.error(o(`configSaveFailed`)+`: `+e.message)}})}function lj(){let e=se();return p({mutationFn:({agentId:e})=>x(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`agents`]}),e.invalidateQueries({queryKey:[`config`]}),y.success(o(`configSavedApplied`))},onError:e=>{y.error(o(`configSaveFailed`)+`: `+e.message)}})}function uj(e,t){return new Map([...t,...e].filter(e=>typeof e.id==`string`&&e.id.trim().length>0).map(e=>[e.id,e]))}function dj(e){let t=e?.trim()??``,n=Fj(e=>e.snapshot.availableAgents??[]),r=oj(),i=(0,P.useMemo)(()=>uj(n,r.data?.agents??[]),[r.data?.agents,n]);return(0,P.useMemo)(()=>{if(!t)return null;let e=i.get(t)??null;return{agentId:t,profile:e,displayName:e?.displayName?.trim()||t,avatarUrl:e?.avatarUrl?.trim()||null}},[i,t])}function fj({agentId:e,className:t}){let n=dj(e);return n?(0,N.jsx)(Mn,{agentId:n.agentId,displayName:n.displayName,avatarUrl:n.avatarUrl,className:t}):null}var pj=new WeakMap;function mj(e){return{roleLabels:{user:o(`chatRoleUser`),assistant:o(`chatRoleAssistant`),tool:o(`chatRoleTool`),system:o(`chatRoleSystem`),fallback:o(`chatRoleMessage`)},reasoningLabel:o(`chatReasoning`),toolCallLabel:o(`chatToolCall`),toolResultLabel:o(`chatToolResult`),toolInputLabel:o(`chatToolInput`),toolNoOutputLabel:o(`chatToolNoOutput`),toolOutputLabel:o(`chatToolOutput`),toolStatusPreparingLabel:o(`chatToolStatusPreparing`),toolStatusRunningLabel:o(`chatToolStatusRunning`),toolStatusCompletedLabel:o(`chatToolStatusCompleted`),toolStatusFailedLabel:o(`chatToolStatusFailed`),toolStatusCancelledLabel:o(`chatToolStatusCancelled`),imageAttachmentLabel:o(`chatImageAttachment`),fileAttachmentLabel:o(`chatFileAttachment`),unknownPartLabel:o(`chatUnknownPart`)}}function hj(e){return{copyCodeLabel:o(`chatCodeCopy`),copiedCodeLabel:o(`chatCodeCopied`),copyMessageLabel:o(`chatMessageCopy`),copiedMessageLabel:o(`chatMessageCopied`),typingLabel:o(`chatTyping`),attachmentOpenLabel:o(`chatAttachmentOpen`),attachmentAttachedLabel:o(`chatAttachmentAttached`),attachmentCategoryLabels:{archive:o(`chatAttachmentCategoryArchive`),audio:o(`chatAttachmentCategoryAudio`),code:o(`chatAttachmentCategoryCode`),data:o(`chatAttachmentCategoryData`),document:o(`chatAttachmentCategoryDocument`),generic:o(`chatAttachmentCategoryGeneric`),image:o(`chatAttachmentCategoryImage`),pdf:o(`chatAttachmentCategoryPdf`),sheet:o(`chatAttachmentCategorySheet`),video:o(`chatAttachmentCategoryVideo`)}}}function gj({messages:e,isSending:t,className:n,onToolAction:r,onFileOpen:i}){let{language:a}=ut(),o=(0,P.useMemo)(()=>mj(a),[a]),s=(0,P.useMemo)(()=>e.map(e=>{let t=pj.get(e);if(t&&t.language===a)return t.viewModel;let n=nj(e),r=EA({id:n.id,role:n.role,meta:{timestamp:n.meta?.timestamp,status:n.meta?.status,inlineTokens:zO(e.metadata)},parts:n.parts},{formatTimestamp:e=>c(e,a),texts:o});return pj.set(e,{language:a,viewModel:r}),r}),[a,e,o]);return(0,N.jsx)(QE,{messages:s,isSending:t,hasAssistantDraft:(0,P.useMemo)(()=>s.some(e=>e.role===`assistant`&&(e.status===`streaming`||e.status===`pending`)),[s]),className:n,texts:(0,P.useMemo)(()=>hj(a),[a]),onToolAction:r,onFileOpen:i,renderToolAgent:e=>(0,N.jsx)(fj,{agentId:e,className:`h-4 w-4 shrink-0`})})}function _j(){let e=se();return async t=>{let{sessionKey:n,patch:r,successMessage:i}=t;try{ee(e,await ae(n,r)),await e.invalidateQueries({queryKey:[`ncp-session-skills`,n]}),y.success(i??o(`configSavedApplied`))}catch(e){throw y.error(o(`configSaveFailed`)+`: `+(e instanceof Error?e.message:String(e))),e}}}function vj(){let e=_j();return async t=>{let{persistToServer:n,projectRoot:r,sessionKey:i}=t,a=o(r?`chatSessionProjectUpdated`:`chatSessionProjectCleared`);if(!n){Q.getState().setSnapshot({pendingProjectRoot:r,pendingProjectRootSessionKey:i}),y.success(a);return}await e({sessionKey:i,patch:{projectRoot:r},successMessage:a})}}function yj({icon:e,label:t,onClick:n,disabled:r=!1,destructive:i=!1}){return(0,N.jsxs)(`button`,{type:`button`,className:d(`flex w-full items-center gap-2 rounded-xl px-3 py-2 text-left text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-50`,i?`text-destructive hover:bg-destructive/10`:`text-gray-700 hover:bg-gray-100`),onClick:n,disabled:r,children:[(0,N.jsx)(e,{className:`h-4 w-4 shrink-0`}),(0,N.jsx)(`span`,{children:t})]})}function bj(e){return g({queryKey:[`server-path-browse`,e.path??null,e.includeFiles??!1],queryFn:()=>te({path:e.path,includeFiles:e.includeFiles}),enabled:e.enabled??!0,staleTime:0})}var xj=P.forwardRef(({className:e,children:t,...n},r)=>(0,N.jsx)(`div`,{ref:r,className:d(`overflow-auto`,e),...n,children:t}));xj.displayName=`ScrollArea`;function Sj({open:e,currentPath:t,isSaving:n,onOpenChange:r,onConfirm:i,title:a,description:s,pathLabel:c,pathPlaceholder:l,confirmLabel:u,hint:d}){let[p,m]=(0,P.useState)(``),[h,g]=(0,P.useState)(null),[_,y]=(0,P.useState)(``);(0,P.useEffect)(()=>{if(!e)return;let n=t?.trim()||null;m(n??``),g(n),y(``)},[t,e]);let b=bj({path:h,enabled:e});(0,P.useEffect)(()=>{!e||!b.data||p.trim().length===0&&m(b.data.currentPath)},[b.data,p,e]);let x=p.trim(),S=x.length===0||n,C=(0,P.useMemo)(()=>b.error?b.error instanceof Error?b.error.message:String(b.error):null,[b.error]),w=_.trim().toLowerCase(),T=(0,P.useMemo)(()=>{let e=b.data?.entries??[];return w.length===0?e:e.filter(e=>{let t=e.name.toLowerCase(),n=e.path.toLowerCase();return t.includes(w)||n.includes(w)})},[b.data?.entries,w]),E=e=>{g(e),y(``),e&&m(e)};return(0,N.jsx)(pe,{open:e,onOpenChange:e=>{n||r(e)},children:(0,N.jsxs)(ue,{className:`max-h-[85vh] overflow-hidden sm:h-[42rem] sm:max-w-2xl sm:grid-rows-[auto_minmax(0,1fr)]`,children:[(0,N.jsxs)(ce,{children:[(0,N.jsx)(de,{children:a}),s?(0,N.jsx)(fe,{children:s}):null]}),(0,N.jsxs)(`form`,{className:`flex min-h-0 flex-col gap-4`,onSubmit:e=>{e.preventDefault(),!S&&i(x)},children:[(0,N.jsxs)(`div`,{className:`space-y-2`,children:[(0,N.jsx)(v,{htmlFor:`server-path-picker-input`,children:c}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(O,{id:`server-path-picker-input`,value:p,onChange:e=>m(e.target.value),placeholder:l,autoFocus:!0,disabled:n}),(0,N.jsx)(f,{type:`button`,variant:`outline`,onClick:()=>E(x||null),disabled:n,children:o(`openPath`)})]})]}),(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-2xl border border-gray-200 bg-gray-50/70`,children:[(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-gray-200 px-3 py-2`,children:[(0,N.jsxs)(f,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>E(b.data?.homePath??null),disabled:n||b.isLoading,children:[(0,N.jsx)(nn,{className:`mr-1 h-4 w-4`}),o(`homeDirectory`)]}),(0,N.jsxs)(f,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>E(b.data?.parentPath??null),disabled:!b.data?.parentPath||n||b.isLoading,children:[(0,N.jsx)(Qt,{className:`mr-1 h-4 w-4`}),o(`parentDirectory`)]}),(0,N.jsxs)(f,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{b.refetch()},disabled:n||b.isLoading,children:[(0,N.jsx)(it,{className:`mr-1 h-4 w-4`}),o(`chatRefresh`)]})]}),(0,N.jsxs)(`div`,{className:`border-b border-gray-200 px-3 py-2`,children:[(0,N.jsx)(`div`,{className:`mb-2 text-xs font-medium text-gray-500`,children:o(`currentDirectory`)}),(0,N.jsx)(`div`,{className:`flex flex-wrap items-center gap-1 text-xs text-gray-600`,children:b.data?.breadcrumbs.map((e,t)=>(0,N.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,N.jsx)(`button`,{type:`button`,className:`rounded px-1.5 py-0.5 hover:bg-gray-200`,onClick:()=>E(e.path),disabled:n,children:e.label}),t<b.data.breadcrumbs.length-1?(0,N.jsx)(It,{className:`h-3 w-3 text-gray-400`}):null]},e.path))})]}),(0,N.jsx)(`div`,{className:`border-b border-gray-200 px-3 py-2`,children:(0,N.jsxs)(`div`,{className:`relative`,children:[(0,N.jsx)(Oe,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,N.jsx)(O,{value:_,onChange:e=>y(e.target.value),placeholder:o(`pathPickerSearchPlaceholder`),disabled:n||b.isLoading,className:`pl-9`})]})}),(0,N.jsx)(xj,{className:`min-h-0 flex-1 px-2 py-2`,children:b.isLoading?(0,N.jsx)(`div`,{className:`px-2 py-6 text-sm text-gray-500`,children:o(`loading`)}):C?(0,N.jsxs)(`div`,{className:`px-2 py-4 text-sm text-destructive`,children:[o(`pathBrowseFailed`),`: `,C]}):b.data&&T.length>0?(0,N.jsx)(`div`,{className:`space-y-1`,children:T.map(e=>(0,N.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-xl px-3 py-2 text-left text-sm text-gray-700 transition-colors hover:bg-white`,onClick:()=>E(e.path),disabled:n,children:[(0,N.jsx)($e,{className:`h-4 w-4 shrink-0 text-emerald-600`}),(0,N.jsx)(`span`,{className:`truncate`,children:e.name})]},e.path))}):b.data&&b.data.entries.length>0?(0,N.jsx)(`div`,{className:`px-2 py-6 text-sm text-gray-500`,children:o(`pathPickerSearchEmpty`)}):(0,N.jsx)(`div`,{className:`px-2 py-6 text-sm text-gray-500`,children:o(`emptyDirectory`)})})]}),d?(0,N.jsx)(`p`,{className:`text-xs leading-relaxed text-gray-500`,children:d}):null,(0,N.jsxs)(le,{children:[(0,N.jsx)(f,{type:`button`,variant:`outline`,onClick:()=>r(!1),disabled:n,children:o(`cancel`)}),(0,N.jsx)(f,{type:`submit`,disabled:S,children:n?o(`saving`):u})]})]})]})})}function Cj({open:e,currentProjectRoot:t,isSaving:n,onOpenChange:r,onSave:i}){return(0,N.jsx)(Sj,{open:e,currentPath:t,isSaving:n,onOpenChange:r,onConfirm:i,title:o(`chatSessionProjectDialogTitle`),description:o(`chatSessionProjectDialogDescription`),pathLabel:o(`chatSessionProjectPathLabel`),pathPlaceholder:o(`chatSessionProjectPathPlaceholder`),confirmLabel:o(`chatSessionSetProject`),hint:o(`chatSessionProjectUpdateHint`)})}function wj({sessionKey:e,canDeleteSession:t,isDeletePending:n,projectRoot:r,childSessionCount:i=0,onOpenChildSessions:a,onDeleteSession:s}){let c=vj(),[l,u]=(0,P.useState)(!1),[d,p]=(0,P.useState)(!1),[m,h]=(0,P.useState)(!1),g=n||m,_=async n=>{let r=t;h(!0);try{await c({sessionKey:e,projectRoot:n,persistToServer:r}),p(!1),u(!1)}finally{h(!1)}};return(0,N.jsxs)(N.Fragment,{children:[i>0&&a?(0,N.jsx)(f,{type:`button`,variant:`ghost`,size:`icon`,className:`rounded-lg shrink-0 text-gray-400 hover:text-gray-700`,"aria-label":o(`chatSessionOpenChildSessions`),title:o(`chatSessionOpenChildSessions`),onClick:a,disabled:g,children:(0,N.jsx)(en,{className:`h-4 w-4`})}):null,(0,N.jsxs)(xt,{open:l,onOpenChange:u,children:[(0,N.jsx)(yt,{asChild:!0,children:(0,N.jsx)(f,{variant:`ghost`,size:`icon`,className:`rounded-lg shrink-0 text-gray-400 hover:text-gray-700`,"aria-label":o(`chatSessionMoreActions`),disabled:g,children:(0,N.jsx)(zt,{className:`h-4 w-4`})})}),(0,N.jsx)(_t,{align:`end`,className:`w-56 p-2`,children:(0,N.jsxs)(`div`,{className:`space-y-1`,children:[(0,N.jsx)(yj,{icon:Xt,label:o(`chatSessionSetProject`),onClick:()=>{u(!1),p(!0)},disabled:g}),(0,N.jsx)(yj,{icon:st,label:o(`chatDeleteSession`),onClick:()=>{u(!1),s()},disabled:!t||g,destructive:!0})]})})]}),(0,N.jsx)(Cj,{open:d,currentProjectRoot:r,isSaving:m,onOpenChange:p,onSave:_})]})}function Tj({sessionKey:e,projectName:t,projectRoot:n,persistToServer:r}){let i=vj(),[a,s]=(0,P.useState)(!1),[c,l]=(0,P.useState)(!1),[u,d]=(0,P.useState)(!1),f=async t=>{d(!0);try{await i({sessionKey:e,projectRoot:t,persistToServer:r}),l(!1),s(!1)}finally{d(!1)}};return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(xt,{open:a,onOpenChange:s,children:[(0,N.jsx)(yt,{asChild:!0,children:(0,N.jsx)(`button`,{type:`button`,title:n??void 0,className:`min-w-0 max-w-[320px] shrink rounded-full border border-gray-200 bg-gray-100/90 px-2 py-0.5 text-[11px] font-medium text-gray-600 transition-colors hover:border-gray-300 hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-60`,"aria-label":o(`chatSessionSetProject`),disabled:u,children:(0,N.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,N.jsx)(Xt,{className:`h-3.5 w-3.5 shrink-0`}),(0,N.jsx)(`span`,{className:`truncate`,children:t}),(0,N.jsx)(je,{className:`h-3 w-3 shrink-0 opacity-70`})]})})}),(0,N.jsxs)(_t,{align:`start`,className:`w-72 p-2`,children:[(0,N.jsxs)(`div`,{className:`px-3 pb-2 pt-1`,children:[(0,N.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-gray-500`,children:t}),n?(0,N.jsx)(`div`,{className:`mt-1 break-all text-xs text-gray-500`,children:n}):null]}),(0,N.jsxs)(`div`,{className:`space-y-1`,children:[(0,N.jsx)(yj,{icon:sn,label:o(`chatSessionSetProject`),onClick:()=>{s(!1),l(!0)},disabled:u}),(0,N.jsx)(yj,{icon:$t,label:o(`chatSessionClearProject`),onClick:()=>{f(null)},disabled:u})]})]})]}),(0,N.jsx)(Cj,{open:c,currentProjectRoot:n,isSaving:u,onOpenChange:l,onSave:f})]})}function Ej({parentSessionLabel:e,onGoToParentSession:t}){if(!e)return null;let n=e.trim();return(0,N.jsx)(`div`,{className:`border-b border-gray-200/60 bg-white/75 px-4 py-2 backdrop-blur-sm sm:px-5`,children:(0,N.jsxs)(`button`,{type:`button`,onClick:t,className:`inline-flex items-center gap-2 text-xs font-medium text-gray-600 transition-colors hover:text-gray-900`,children:[(0,N.jsx)(De,{className:`h-3.5 w-3.5`}),(0,N.jsxs)(`span`,{children:[o(`chatBackToParent`),n?` · ${n}`:``]})]})})}function Dj({snapshot:e,childSessionCount:t,layoutMode:n,normalizedAgentId:r,sessionHeaderTitle:i,shouldShowHeaderAgentAvatar:a,shouldShowSessionHeader:s,onBackToList:c,onOpenChildSessions:l,onDeleteSession:u}){let f=n===`mobile`;return(0,N.jsxs)(`div`,{className:d(`border-b border-gray-200/60 bg-white/80 backdrop-blur-sm flex items-center justify-between shrink-0 overflow-hidden transition-all duration-200`,f?`px-3 sm:px-3`:`px-4 sm:px-5`,s?`opacity-100`:`h-0 py-0 opacity-0 border-b-0`,s&&(f?`pb-2 pt-2`:`py-3`)),style:f&&s?{paddingTop:`calc(env(safe-area-inset-top, 0px) + 0.5rem)`}:void 0,children:[(0,N.jsxs)(`div`,{className:`min-w-0 flex-1 flex items-center gap-2`,children:[f&&c?(0,N.jsx)(`button`,{type:`button`,onClick:c,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full text-gray-600 transition-colors hover:bg-gray-100 hover:text-gray-900`,"aria-label":o(`chat`),children:(0,N.jsx)(De,{className:`h-4 w-4`})}):null,a?(0,N.jsx)(`div`,{className:`inline-flex shrink-0 items-center`,children:(0,N.jsx)(Mn,{agentId:r,displayName:e.agentDisplayName,avatarUrl:e.agentAvatarUrl,className:`h-5 w-5`})}):null,(0,N.jsx)(`span`,{className:`text-sm font-medium text-gray-700 truncate`,children:i}),e.sessionTypeLabel?(0,N.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1.5 rounded-full border border-gray-200 bg-gray-100 px-2 py-0.5 text-[11px] font-medium text-gray-600`,children:[e.sessionTypeIcon?.src?(0,N.jsx)(`span`,{className:`inline-flex h-[1.125rem] w-[1.125rem] items-center justify-center`,children:(0,N.jsx)(Tn,{icon:{kind:`runtime-image`,src:e.sessionTypeIcon.src,alt:e.sessionTypeIcon.alt??null,name:e.sessionTypeLabel}})}):null,e.sessionTypeLabel]}):null,e.sessionProjectName?(0,N.jsx)(Tj,{sessionKey:e.sessionKey??`draft`,projectName:e.sessionProjectName,projectRoot:e.sessionProjectRoot,persistToServer:e.canDeleteSession}):null]}),e.sessionKey?(0,N.jsx)(wj,{sessionKey:e.sessionKey,canDeleteSession:e.canDeleteSession,isDeletePending:e.isDeletePending,projectRoot:e.sessionProjectRoot,childSessionCount:t,onOpenChildSessions:l,onDeleteSession:u}):null]})}var Oj=`native`;function kj(e){return typeof e==`string`?e.trim().toLowerCase()||`native`:Oj}function Aj(e,t=Oj){return kj(e?.runtime?.trim()||e?.engine?.trim()||t)}function jj(e,t){return e===`native`?o(`chatSessionTypeNative`):t?.trim()||e.trim().split(/[-_]+/g).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)||e}function Mj(e){let t=new Map;for(let n of e){let e=kj(n.value);t.set(e,{value:e,label:n.label?.trim()||jj(e),icon:n.icon??null,ready:n.ready??!0,reason:n.reason??null,reasonMessage:n.reasonMessage??null,supportedModels:n.supportedModels,recommendedModel:n.recommendedModel??null,cta:n.cta??null})}return t.has(`native`)||t.set(Oj,{value:Oj,label:jj(Oj),icon:null,ready:!0,reason:null,reasonMessage:null,supportedModels:void 0,recommendedModel:null,cta:null}),Array.from(t.values()).sort((e,t)=>e.value===`native`?-1:t.value===`native`?1:e.value.localeCompare(t.value))}function Nj(e){let{selectedSession:t,pendingSessionType:n,setPendingSessionType:r,sessionTypesData:i}=e,a=(0,P.useMemo)(()=>Mj(i?.options??[]),[i?.options]),s=(0,P.useMemo)(()=>{let e=[...a],n=kj(t?.sessionType);return e.some(e=>e.value===n)||e.push({value:n,label:jj(n),icon:null,ready:!0,reason:null,reasonMessage:null,supportedModels:void 0,recommendedModel:null,cta:null}),e.sort((e,t)=>e.value===`native`?-1:t.value===`native`?1:e.value.localeCompare(t.value))},[a,t?.sessionType]),c=(0,P.useMemo)(()=>kj(i?.defaultType??`native`),[i?.defaultType]),l=(0,P.useRef)(null),u=(0,P.useMemo)(()=>kj(t?.sessionType??n??c),[c,n,t?.sessionType]),d=(0,P.useMemo)(()=>s.find(e=>e.value===u)??null,[u,s]);(0,P.useEffect)(()=>{if(t)return;let e=typeof n==`string`?n.trim():``,i=kj(n);(e.length===0||l.current===i||l.current===null&&i===`native`)&&(l.current=c,i!==c&&r(c))},[c,n,t,r]);let f=!t||!!t.sessionTypeMutable,p=(0,P.useMemo)(()=>new Set(a.map(e=>e.value)),[a]);return{sessionTypeOptions:s,selectedSessionTypeOption:d,defaultSessionType:c,selectedSessionType:u,canEditSessionType:f,sessionTypeUnavailable:(0,P.useMemo)(()=>t&&!p.has(kj(t.sessionType))?!0:d?.ready===!1,[p,t,d?.ready]),sessionTypeUnavailableMessage:(0,P.useMemo)(()=>t&&!p.has(kj(t.sessionType))?`${jj(u)} ${o(`chatSessionTypeUnavailableSuffix`)}`:d?.ready===!1?d.reasonMessage?.trim()||`${d.label} setup required`:null,[p,t,u,d])}}var Pj={isProviderStateResolved:!1,modelOptions:[],sessionTypeUnavailable:!1,sessionTypeUnavailableMessage:null,sessionTypeLabel:null,sessionTypeIcon:null,sessionKey:null,agentId:null,agentDisplayName:null,agentAvatarUrl:null,availableAgents:[],sessionDisplayName:void 0,sessionProjectRoot:null,sessionProjectName:null,canDeleteSession:!1,isDeletePending:!1,threadRef:null,isHistoryLoading:!1,messages:[],isSending:!1,isAwaitingAssistantOutput:!1,parentSessionKey:null,parentSessionLabel:null,workspacePanelParentKey:null,childSessionTabs:[],activeChildSessionKey:null,workspaceFileTabs:[],activeWorkspaceFileKey:null},Fj=C(e=>({snapshot:Pj,setSnapshot:t=>e(e=>({snapshot:{...e.snapshot,...t}}))})),Ij=[{key:`hero`,alignmentClassName:`justify-start`,bubbleClassName:`max-w-[78%] h-32 rounded-[30px]`},{key:`follow-up`,alignmentClassName:`justify-start`,bubbleClassName:`max-w-[62%] h-24 rounded-[28px]`},{key:`reply`,alignmentClassName:`justify-end`,bubbleClassName:`max-w-[70%] h-24 rounded-[28px]`},{key:`detail`,alignmentClassName:`justify-start`,bubbleClassName:`max-w-[88%] h-36 rounded-[30px]`}];function Lj(){return(0,N.jsxs)(`section`,{"data-testid":`chat-conversation-skeleton`,className:`flex-1 min-h-0 flex flex-col overflow-hidden bg-gradient-to-b from-gray-50/60 to-white`,children:[(0,N.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar`,children:(0,N.jsx)(`div`,{className:`mx-auto flex min-h-full w-full max-w-[min(1120px,100%)] flex-col px-6 py-5`,children:(0,N.jsxs)(`div`,{className:`flex flex-1 flex-col gap-8`,children:[(0,N.jsxs)(`div`,{className:`space-y-6`,children:[(0,N.jsx)(Mt,{className:`h-6 w-52 rounded-lg bg-gray-200/90`}),(0,N.jsx)(`div`,{className:`space-y-5`,children:Ij.map(e=>(0,N.jsx)(`div`,{className:d(`flex w-full`,e.alignmentClassName),children:(0,N.jsx)(Mt,{"data-testid":`chat-conversation-skeleton-bubble`,className:d(`w-full bg-gray-200/80`,e.bubbleClassName)})},e.key))})]}),(0,N.jsxs)(`div`,{className:`mt-auto grid gap-4 pb-2 sm:grid-cols-[minmax(0,1fr)_minmax(180px,240px)] sm:items-end`,children:[(0,N.jsxs)(`div`,{className:`space-y-3`,children:[(0,N.jsx)(Mt,{className:`h-4 w-40 rounded-full bg-gray-200/70`}),(0,N.jsx)(Mt,{className:`h-[112px] w-full rounded-[30px] bg-gray-200/70`})]}),(0,N.jsx)(`div`,{className:`hidden justify-end sm:flex`,children:(0,N.jsx)(Mt,{className:`h-10 w-36 rounded-full bg-gray-200/75`})})]})]})})}),(0,N.jsx)(`div`,{className:`border-t border-gray-200/80 bg-white p-4`,children:(0,N.jsx)(`div`,{className:`mx-auto w-full max-w-[min(1120px,100%)]`,children:(0,N.jsxs)(`div`,{className:`overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-card`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5`,children:(0,N.jsx)(Mt,{className:`h-[84px] w-full rounded-[28px] bg-gray-200/80`})}),(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 pb-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(Mt,{className:`h-8 w-20 rounded-full bg-gray-200/75`}),(0,N.jsx)(Mt,{className:`h-8 w-28 rounded-full bg-gray-200/75`}),(0,N.jsx)(Mt,{className:`hidden h-8 w-24 rounded-full bg-gray-200/70 sm:block`})]}),(0,N.jsx)(Mt,{className:`h-8 w-8 rounded-full bg-gray-200/85`})]})]})})})]})}function Rj({shouldShowProviderHint:e,sessionTypeUnavailable:t,sessionTypeUnavailableMessage:n,onGoToProviders:r}){return(0,N.jsxs)(N.Fragment,{children:[e?(0,N.jsxs)(`div`,{className:`px-4 py-2.5 border-b border-amber-200/70 bg-amber-50/70 flex items-center justify-between gap-3 shrink-0 sm:px-5`,children:[(0,N.jsx)(`span`,{className:`text-xs text-amber-800`,children:o(`chatModelNoOptions`)}),(0,N.jsx)(`button`,{type:`button`,onClick:r,className:`text-xs font-semibold text-amber-900 underline-offset-2 hover:underline`,children:o(`chatGoConfigureProvider`)})]}):null,t&&n?.trim()?(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-amber-200/70 bg-amber-50/70 shrink-0 sm:px-5`,children:(0,N.jsx)(`span`,{className:`text-xs text-amber-800`,children:n})}):null]})}function zj({snapshot:e,availableAgents:t,hideEmptyHint:n,showWelcome:r,threadRef:i,onScroll:a,onCreateSession:s,onSelectAgent:c,onToolAction:l,onFileOpen:u}){return(0,N.jsx)(`div`,{ref:i,onScroll:a,className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar`,children:r?(0,N.jsx)(Rn,{onCreateSession:s,agents:t,selectedAgentId:e.agentId??`main`,onSelectAgent:c}):n?null:e.messages.length===0?(0,N.jsx)(`div`,{className:`px-4 py-4 text-sm text-gray-500 sm:px-5 sm:py-5`,children:o(`chatNoMessages`)}):(0,N.jsx)(`div`,{className:`mx-auto w-full max-w-[min(1120px,100%)] px-4 py-4 sm:px-6 sm:py-5`,children:(0,N.jsx)(gj,{messages:e.messages,isSending:e.isSending&&e.isAwaitingAssistantOutput,onToolAction:l,onFileOpen:u},e.sessionKey??`draft`)})})}function Bj(e,t,n){return e.workspacePanelParentKey===e.sessionKey?t.length>0||n.length>0:!1}function Vj({layoutMode:e=`desktop`,onBackToList:t}){let n=XD(),r=Q(e=>e.snapshot.defaultSessionType),i=Fj(e=>e.snapshot),a=(0,P.useRef)(null),s=i.threadRef??a,c=i.childSessionTabs.filter(e=>e.parentSessionKey===i.sessionKey),l=i.workspaceFileTabs.filter(e=>e.parentSessionKey===i.sessionKey),u=Bj(i,c,l),d=!!(i.sessionKey||i.sessionTypeLabel),f=i.sessionDisplayName||(i.canDeleteSession&&i.sessionKey?i.sessionKey:null)||o(`chatSidebarNewTask`),p=i.agentId?.trim()??``,m=p.length>0&&p.toLowerCase()!==`main`,h=!i.canDeleteSession&&i.messages.length===0&&!i.isSending,g=i.modelOptions.length>0,_=i.isProviderStateResolved&&!g,v=i.isHistoryLoading&&i.messages.length===0&&!i.isSending&&!i.isAwaitingAssistantOutput,y=i.availableAgents??[],b=e=>y.find(t=>t.id===e)??null,x=()=>{let t=Aj(b(i.agentId??`main`),r),a=n.chatSessionListManager.createSession(t);e===`mobile`&&n.chatUiManager.goToSession(a)},S=e=>{n.chatSessionListManager.setSelectedAgentId(e),n.chatInputManager.setPendingSessionType(Aj(b(e),r))},C=e=>{n.chatThreadManager.openFilePreview(e)},w=()=>{i.sessionKey&&n.chatThreadManager.openChildSessionPanel({parentSessionKey:i.sessionKey,activeChildSessionKey:c[0]?.sessionKey??null})},{onScroll:T}=WT({scrollRef:s,resetKey:i.sessionKey,isLoading:i.isHistoryLoading,hasContent:i.messages.length>0,contentVersion:i.messages[i.messages.length-1]??null});return i.isProviderStateResolved?(0,N.jsxs)(`section`,{className:`flex-1 min-h-0 flex overflow-hidden bg-gradient-to-b from-gray-50/60 to-white`,children:[(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[(0,N.jsx)(Ej,{parentSessionLabel:i.parentSessionKey?i.parentSessionLabel??null:null,onGoToParentSession:n.chatThreadManager.goToParentSession}),(0,N.jsx)(Dj,{snapshot:i,childSessionCount:c.length,layoutMode:e,normalizedAgentId:p,sessionHeaderTitle:f,shouldShowHeaderAgentAvatar:m,shouldShowSessionHeader:d,onBackToList:t,onOpenChildSessions:w,onDeleteSession:n.chatThreadManager.deleteSession}),(0,N.jsx)(Rj,{shouldShowProviderHint:_,sessionTypeUnavailable:i.sessionTypeUnavailable,sessionTypeUnavailableMessage:i.sessionTypeUnavailableMessage??null,onGoToProviders:n.chatThreadManager.goToProviders}),(0,N.jsx)(zj,{snapshot:i,availableAgents:y,hideEmptyHint:v,showWelcome:h,threadRef:s,onScroll:T,onCreateSession:x,onSelectAgent:S,onToolAction:n.chatThreadManager.openSessionFromToolAction,onFileOpen:C}),(0,N.jsx)(TO,{})]}),u?(0,N.jsx)(vN,{childSessionTabs:c,activeChildSessionKey:i.activeChildSessionKey??null,workspaceFileTabs:l,activeWorkspaceFileKey:i.activeWorkspaceFileKey??null,sessionProjectRoot:i.sessionProjectRoot??null,displayMode:e===`mobile`?`overlay`:`docked`,onSelectSession:n.chatThreadManager.selectChildSessionDetail,onSelectFile:n.chatThreadManager.selectWorkspaceFile,onCloseFile:n.chatThreadManager.closeWorkspaceFile,onClose:n.chatThreadManager.closeWorkspacePanel,onBackToParent:n.chatThreadManager.goToParentSession,onToolAction:n.chatThreadManager.openSessionFromToolAction,onFileOpen:C}):null]}):(0,N.jsx)(Lj,{})}var Hj={connected:{dotClass:`bg-emerald-500`},disconnected:{dotClass:`h-2.5 w-2.5 rounded-full border border-gray-400 bg-transparent`},connecting:{dotClass:`text-amber-600`}};function Uj({status:e,className:t}){let n=Hj[e],r=o(e===`connected`?`connected`:e===`disconnected`?`disconnected`:`connecting`);return(0,N.jsx)(kt,{delayDuration:250,children:(0,N.jsxs)(jt,{children:[(0,N.jsx)(Tt,{asChild:!0,children:(0,N.jsx)(`span`,{role:`status`,"aria-label":r,className:d(`inline-flex h-5 w-5 items-center justify-center`,t),children:e===`connecting`?(0,N.jsx)(nt,{className:d(`h-3 w-3 animate-spin`,n.dotClass)}):(0,N.jsx)(`span`,{className:d(e===`connected`?`h-2 w-2 rounded-full`:``,n.dotClass)})})}),(0,N.jsx)(Dt,{side:`bottom`,className:`text-xs`,children:r})]})})}function Wj(){let e=_j();return async t=>{await e({sessionKey:t.sessionKey,patch:{label:t.label},successMessage:o(`configSavedApplied`)})}}function Gj(){let e=Wj(),[t,n]=(0,P.useState)(null),[r,i]=(0,P.useState)(``),[a,o]=(0,P.useState)(null),s=e=>{n(e.key),i(e.label?.trim()??``)},c=()=>{n(null),i(``),o(null)};return{editingSessionKey:t,draftLabel:r,savingSessionKey:a,setDraftLabel:i,startEditingSessionLabel:s,cancelEditingSessionLabel:c,saveSessionLabel:async t=>{let n=r.trim();if(n===(t.label?.trim()??``)){c();return}o(t.key);try{await e({sessionKey:t.key,label:n||null}),c()}catch{o(null)}}}}function Kj(e){let t=e.label?.trim();if(t)return t;let n=e.key.split(`:`);return n[n.length-1]||e.key}function qj(e){return e.trim().toLowerCase()}function Jj(e,t){let n=qj(t);return n?[e.key,Kj(e),e.projectRoot??``,e.projectName??``].map(qj).some(e=>e.includes(n)):!0}function Yj(e,t){let n=e?.trim();if(!n)return!1;let r=t?.trim();return r?n.localeCompare(r)>0:!1}function Xj(e){let{active:t,readAt:n,runStatus:r,lastMessageAt:i}=e;return t||r===`running`?!1:Yj(i,n)}var Zj={selectedSessionKey:null,draftSessionKey:aj(),selectedAgentId:`main`,query:``,listMode:`time-first`};function Qj(e){return t=>e(e=>({snapshot:{...e.snapshot,...t}}))}function $j(e){return(t,n)=>e(e=>{let r=t.trim(),i=n?.trim();if(!r||!i)return e;let a=e.optimisticReadAtBySessionKey[r];return a&&a.localeCompare(i)>=0?e:{...e,optimisticReadAtBySessionKey:{...e.optimisticReadAtBySessionKey,[r]:i}}})}var eM=C(e=>({snapshot:Zj,optimisticReadAtBySessionKey:{},setSnapshot:Qj(e),markSessionRead:$j(e)}));function tM(e,t){return e.filter(e=>Jj(e,t))}function nM(e){return e.isChildSession?e.isPromotedChildSession===!0:!0}function rM(e={}){let t=eM(e=>e.snapshot.query),n=pt({limit:e.limit??200}),r=(0,P.useMemo)(()=>{let e=n.data?.sessions??[],r=tM(ij(e).filter(nM),t),i=new Map(e.map(e=>[e.sessionId,e]));return r.map(e=>({session:e,runStatus:i.get(e.key)?.status===`running`?`running`:void 0}))},[t,n.data?.sessions]);return{isLoading:n.isLoading,items:r}}function iM(e){let{item:t,selectedSessionKey:n,optimisticReadAtBySessionKey:r,agentsById:i,childSessionsByParentKey:a,editingSessionKey:o,draftLabel:s,savingSessionKey:c,sessionTitle:l,onSelectSession:u,onOpenChildSessions:d,onStartEditingSessionLabel:f,onDraftLabelChange:p,onSaveSessionLabel:m,onCancelEditingSessionLabel:h}=e,{session:g,runStatus:_}=t,v=Q(e=>e.snapshot),y=n===g.key,b=r[g.key],x=b&&g.readAt?b.localeCompare(g.readAt)>0?b:g.readAt:b??g.readAt,S=a.get(g.key)??[];return(0,N.jsx)(In,{session:g,active:y,showUnreadDot:Xj({active:y,lastMessageAt:g.lastMessageAt,readAt:x,runStatus:_}),runStatus:_,context:xn(g,v.sessionTypeOptions),title:l(g),agentId:g.agentId??null,agentLabel:g.agentId?i.get(g.agentId)?.displayName??g.agentId:null,agentAvatarUrl:g.agentId?i.get(g.agentId)?.avatarUrl??null:null,childSessionCount:S.length,isEditing:o===g.key,draftLabel:s,isSaving:c===g.key,onSelect:()=>u(g.key),onOpenChildSessions:()=>d(g.key,S[0]?.session.key??null),onStartEditing:()=>f(g),onDraftLabelChange:p,onSave:()=>m(g),onCancel:h})}function aM(e){let t=e.sessionTypeOptions.find(t=>t.value===e.defaultSessionType);return[...t?[t]:[],...e.nonDefaultSessionTypeOptions]}function oM(e){let{query:t,defaultSessionType:n,nonDefaultSessionTypeOptions:r,isCreateMenuOpen:i,onCreateMenuOpenChange:a,onCreateSession:s,onQueryChange:c}=e;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`div`,{className:`px-4 pb-3`,children:(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsxs)(f,{variant:`primary`,className:d(`min-w-0 rounded-xl`,r.length>0?`flex-1 rounded-r-md`:`w-full`),onClick:()=>{a(!1),s(n)},children:[(0,N.jsx)(rt,{className:`mr-2 h-4 w-4`}),o(`chatSidebarNewTask`)]}),r.length>0?(0,N.jsxs)(xt,{open:i,onOpenChange:a,children:[(0,N.jsx)(yt,{asChild:!0,children:(0,N.jsx)(f,{variant:`primary`,size:`icon`,className:`h-9 w-10 shrink-0 rounded-xl rounded-l-md`,"aria-label":o(`chatSessionTypeLabel`),children:(0,N.jsx)(je,{className:`h-4 w-4`})})}),(0,N.jsxs)(_t,{align:`end`,className:`w-56 rounded-2xl border border-gray-200/80 bg-white p-1.5 shadow-[0_24px_60px_-28px_rgba(15,23,42,0.38)]`,children:[(0,N.jsx)(`div`,{className:`px-3 pb-1 pt-2 text-[10px] font-semibold uppercase tracking-[0.18em] text-gray-400`,children:o(`chatSessionTypeLabel`)}),(0,N.jsx)(`div`,{className:`space-y-1`,children:r.map(e=>(0,N.jsx)(Dn,{option:e,onSelect:()=>{s(e.value),a(!1)}},e.value))})]})]}):null]})}),(0,N.jsx)(`div`,{className:`px-4 pb-3`,children:(0,N.jsxs)(`div`,{className:`relative`,children:[(0,N.jsx)(Oe,{className:`absolute left-3 top-2.5 h-3.5 w-3.5 text-gray-400`}),(0,N.jsx)(O,{value:t,onChange:e=>c(e.target.value),placeholder:o(`chatSidebarSearchPlaceholder`),className:`h-9 rounded-lg pl-8 text-xs`})]})})]})}function sM(e){let{query:t,defaultSessionType:n,sessionTypeOptions:r,nonDefaultSessionTypeOptions:i,isCreateMenuOpen:a,onCreateMenuOpenChange:s,onCreateSession:c,onQueryChange:l}=e,u=aM({defaultSessionType:n,sessionTypeOptions:r,nonDefaultSessionTypeOptions:i}),d=u.length>1;return(0,N.jsx)(`div`,{className:`px-4 pb-2 pt-1`,children:(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,N.jsx)(Oe,{className:`absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,N.jsx)(O,{value:t,onChange:e=>l(e.target.value),placeholder:o(`chatSidebarSearchPlaceholder`),className:`h-9 rounded-full border-transparent bg-gray-100/80 pl-9 pr-3 text-[13px] shadow-none focus:border-gray-200/80 focus:bg-white`})]}),d?(0,N.jsxs)(xt,{open:a,onOpenChange:s,children:[(0,N.jsx)(yt,{asChild:!0,children:(0,N.jsx)(f,{variant:`ghost`,size:`icon`,className:`h-9 w-9 shrink-0 rounded-full bg-gray-100/80 text-gray-700 shadow-none hover:bg-gray-200/80 hover:text-gray-900`,"aria-label":o(`chatSidebarNewTask`),children:(0,N.jsx)(rt,{className:`h-4 w-4`})})}),(0,N.jsxs)(_t,{align:`end`,className:`w-60 rounded-3xl border border-gray-200/80 bg-white p-2 shadow-[0_24px_70px_-30px_rgba(15,23,42,0.45)]`,children:[(0,N.jsx)(`div`,{className:`px-3 pb-1.5 pt-2 text-[11px] font-medium text-gray-400`,children:o(`chatSidebarNewTask`)}),(0,N.jsx)(`div`,{className:`space-y-1`,children:u.map(e=>(0,N.jsx)(Dn,{option:e,onSelect:()=>{c(e.value),s(!1)}},e.value))})]})]}):(0,N.jsx)(f,{variant:`ghost`,size:`icon`,className:`h-9 w-9 shrink-0 rounded-full bg-gray-100/80 text-gray-700 shadow-none hover:bg-gray-200/80 hover:text-gray-900`,"aria-label":o(`chatSidebarNewTask`),onClick:()=>c(n),children:(0,N.jsx)(rt,{className:`h-4 w-4`})})]})})}function cM(e){return new Date(e.session.updatedAt).getTime()}function lM(e){return[...e].sort((e,t)=>cM(t)-cM(e))}function uM(e){let t=new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),r=n-864e5,i=n-7*864e5,a=[],s=[],c=[],l=[];for(let t of e){let{session:e}=t,o=new Date(e.updatedAt).getTime();o>=n?a.push(t):o>=r?s.push(t):o>=i?c.push(t):l.push(t)}let u=[];return a.length>0&&u.push({label:o(`chatSidebarToday`),items:a}),s.length>0&&u.push({label:o(`chatSidebarYesterday`),items:s}),c.length>0&&u.push({label:o(`chatSidebarPrevious7Days`),items:c}),l.length>0&&u.push({label:o(`chatSidebarOlder`),items:l}),u}function dM(e){let t=new Map;for(let n of e){let e=n.session.projectRoot?.trim();if(!e)continue;let r=t.get(e),i=cM(n);if(r){r.items.push(n),r.latestUpdatedAt=Math.max(r.latestUpdatedAt,i);continue}t.set(e,{projectRoot:e,projectName:n.session.projectName?.trim()||AA(e)||e,items:[n],latestUpdatedAt:i})}return[...t.values()].map(e=>({...e,items:lM(e.items)})).sort((e,t)=>t.latestUpdatedAt-e.latestUpdatedAt)}function fM(e){if(e.label&&e.label.trim())return e.label.trim();let t=e.key.split(`:`);return t[t.length-1]||e.key}var pM=[{target:`/cron`,label:()=>o(`chatSidebarScheduledTasks`),icon:me},{target:`/skills`,label:()=>o(`chatSidebarSkills`),icon:Te},{target:`/agents`,label:()=>o(`agentsPageTitle`),icon:Ee}];function mM(e,t,n){let r=eM(e=>e.optimisticReadAtBySessionKey);return(0,P.useEffect)(()=>{(()=>{if(!t)return;let r=e.find(({session:e})=>e.key===t);if(!r)return;let{session:i}=r;n(i.key,i.lastMessageAt,i.readAt)})()},[e,n,t]),r}function hM({variant:e=`desktop`}){let n=e===`mobile`,r=XD(),i=lt(),[a,s]=(0,P.useState)(!1),c=Q(e=>e.snapshot),l=eM(e=>e.snapshot),u=b(),f=oj(),{isLoading:p,items:m}=rM(),{language:h,setLanguage:g}=ut(),{theme:_,setTheme:v}=Se(),y=o(ge.find(e=>e.value===_)?.labelKey??`themeWarm`),x=t.find(e=>e.value===h)?.label??h,S=(0,P.useMemo)(()=>new Map((f.data?.agents??[]).map(e=>[e.id,e])),[f.data?.agents]),C=(0,P.useMemo)(()=>lM(m),[m]),w=(0,P.useMemo)(()=>{let e=new Map;for(let t of m){let n=t.session.parentSessionId?.trim();if(!n)continue;let r=e.get(n)??[];r.push(t),e.set(n,r)}for(let t of e.values())t.sort((e,t)=>cM(t)-cM(e));return e},[m]),T=(0,P.useMemo)(()=>uM(C),[C]),E=(0,P.useMemo)(()=>dM(C),[C]),D=c.defaultSessionType||`native`,O=(0,P.useMemo)(()=>c.sessionTypeOptions.filter(e=>e.value!==D),[D,c.sessionTypeOptions]),ee=l.listMode===`project-first`,k=mM(m,l.selectedSessionKey,r.chatSessionListManager.markSessionRead),{editingSessionKey:te,draftLabel:A,savingSessionKey:ne,setDraftLabel:j,startEditingSessionLabel:re,cancelEditingSessionLabel:ie,saveSessionLabel:ae}=Gj(),oe=e=>{h!==e&&(g(e),window.location.reload())},se=e=>(0,N.jsx)(iM,{item:e,selectedSessionKey:l.selectedSessionKey,optimisticReadAtBySessionKey:k,agentsById:S,childSessionsByParentKey:w,editingSessionKey:te,draftLabel:A,savingSessionKey:ne,sessionTitle:fM,onSelectSession:r.chatSessionListManager.selectSession,onOpenChildSessions:(e,t)=>r.chatThreadManager.openChildSessionPanel({parentSessionKey:e,activeChildSessionKey:t}),onStartEditingSessionLabel:re,onDraftLabelChange:j,onSaveSessionLabel:ae,onCancelEditingSessionLabel:ie},e.session.key),ce=(e,t)=>{let i=typeof t==`string`?r.chatSessionListManager.createSession(e,t):r.chatSessionListManager.createSession(e);n&&r.chatUiManager.goToSession(i)};return(0,N.jsxs)(`aside`,{className:d(`flex h-full min-h-0 flex-col bg-secondary`,n?`flex-1 overflow-hidden`:`w-[280px] shrink-0 border-r border-gray-200/60`),children:[n?null:(0,N.jsx)(`div`,{className:`px-5 pt-5 pb-3`,children:(0,N.jsx)(we,{className:`flex items-center gap-2.5 min-w-0`,suffix:(0,N.jsx)(Uj,{status:u.connectionStatus})})}),n?(0,N.jsx)(sM,{query:l.query,defaultSessionType:D,sessionTypeOptions:c.sessionTypeOptions,nonDefaultSessionTypeOptions:O,isCreateMenuOpen:a,onCreateMenuOpenChange:s,onCreateSession:ce,onQueryChange:r.chatSessionListManager.setQuery}):(0,N.jsx)(oM,{query:l.query,defaultSessionType:D,sessionTypeOptions:c.sessionTypeOptions,nonDefaultSessionTypeOptions:O,isCreateMenuOpen:a,onCreateMenuOpenChange:s,onCreateSession:ce,onQueryChange:r.chatSessionListManager.setQuery}),n?null:(0,N.jsx)(`div`,{className:`px-3 pb-2`,children:(0,N.jsx)(`ul`,{className:`space-y-0.5`,children:pM.map(e=>(0,N.jsx)(`li`,{children:(0,N.jsx)(he,{to:e.target,label:e.label(),icon:e.icon,density:`compact`})},e.target))})}),n?null:(0,N.jsx)(`div`,{className:`mx-4 border-t border-gray-200/60`}),(0,N.jsxs)(`div`,{className:`flex items-center justify-between px-5 pb-2 pt-3`,children:[(0,N.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-gray-400`,children:o(`chatSidebarTaskRecords`)}),(0,N.jsx)(fn,{isProjectFirstView:ee,onSelectMode:r.chatSessionListManager.setListMode})]}),(0,N.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar px-3 py-2`,children:p?(0,N.jsx)(`div`,{className:`text-xs text-gray-500 p-3`,children:o(`sessionsLoading`)}):ee?E.length===0?(0,N.jsxs)(`div`,{className:`p-4 text-center`,children:[(0,N.jsx)(rn,{className:`h-6 w-6 mx-auto mb-2 text-gray-300`}),(0,N.jsx)(`div`,{className:`text-xs text-gray-500`,children:o(`chatSidebarProjectViewEmpty`)})]}):(0,N.jsx)(kn,{groups:E,defaultSessionType:D,sessionTypeOptions:c.sessionTypeOptions,renderSessionItem:se,onCreateSession:ce}):T.length===0?(0,N.jsxs)(`div`,{className:`p-4 text-center`,children:[(0,N.jsx)(rn,{className:`h-6 w-6 mx-auto mb-2 text-gray-300`}),(0,N.jsx)(`div`,{className:`text-xs text-gray-500`,children:o(`sessionsEmpty`)})]}):(0,N.jsx)(`div`,{className:`space-y-3`,children:T.map(e=>(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`px-2 py-1 text-[11px] font-medium text-gray-400 uppercase tracking-wider`,children:e.label}),(0,N.jsx)(`div`,{className:`space-y-0.5`,children:e.items.map(se)})]},e.label))})}),n?null:(0,N.jsxs)(`div`,{className:`px-3 py-3 border-t border-gray-200/60 space-y-0.5`,children:[(0,N.jsx)(he,{to:`/settings`,label:o(`settings`),icon:at,density:`compact`}),(0,N.jsx)(Ce,{onClick:()=>i.open(void 0,{kind:`docs`,newTab:!0,title:`Docs`}),icon:ke,label:o(`docBrowserHelp`),density:`compact`}),(0,N.jsx)(be,{value:_,onValueChange:e=>v(e),icon:xe,label:o(`theme`),valueLabel:y,density:`compact`,children:ge.map(e=>(0,N.jsx)(Ke,{value:e.value,className:`text-xs`,children:o(e.labelKey)},e.value))}),(0,N.jsx)(be,{value:h,onValueChange:e=>oe(e),icon:ve,label:o(`language`),valueLabel:x,density:`compact`,children:t.map(e=>(0,N.jsx)(Ke,{value:e.value,className:`text-xs`,children:e.label},e.value))})]})]})}function gM({tone:e=`neutral`,value:t}){return(0,N.jsx)(`span`,{className:d(`inline-flex h-5 items-center rounded-sm border px-1.5 text-[10px] font-medium leading-none`,e===`warning`?`border-amber-200 bg-amber-50 text-amber-700`:`border-gray-200 bg-gray-50 text-gray-500`),children:t})}function _M({breadcrumb:e}){return(0,N.jsx)(`div`,{"data-testid":`workspace-file-breadcrumbs`,title:e.fullPath,className:`workspace-horizontal-scrollbar overflow-x-auto overflow-y-hidden border-b border-gray-200/80 bg-gray-50/55`,children:(0,N.jsxs)(`div`,{"data-testid":`workspace-file-breadcrumb-scroll`,className:`flex min-w-max items-center gap-2.5 px-3 py-1.5`,children:[(0,N.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 pr-1`,children:e.segments.map((t,n)=>(0,N.jsxs)(P.Fragment,{children:[(0,N.jsxs)(`span`,{className:d(`inline-flex h-5 items-center gap-1 rounded-sm px-1 text-[11px] leading-none`,t.kind===`workspace`?`bg-primary/8 text-primary`:t.isCurrent?`bg-gray-200/70 text-gray-900`:`text-gray-500`),children:[t.kind===`workspace`?(0,N.jsx)(Zt,{className:`h-3 w-3 shrink-0`}):t.isCurrent?(0,N.jsx)(Ht,{className:`h-3 w-3 shrink-0`}):null,(0,N.jsx)(`span`,{children:t.label})]}),n<e.segments.length-1?(0,N.jsx)(It,{className:`h-3 w-3 shrink-0 text-gray-300`}):null]},t.key))}),e.locationLabel||e.truncated?(0,N.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-1`,children:[e.locationLabel?(0,N.jsx)(gM,{value:e.locationLabel}):null,e.truncated?(0,N.jsx)(gM,{tone:`warning`,value:o(`chatWorkspacePreviewTruncated`)}):null]}):null]})})}function vM(e){let t=e.path?.trim()??``;return g({queryKey:[`server-path-read`,t,e.basePath??null],queryFn:()=>j({path:t,basePath:e.basePath}),enabled:(e.enabled??!0)&&t.length>0,staleTime:0})}function yM(e){return e.serverKind?e.serverKind:/\.mdx?$/i.test(e.path)?`markdown`:`text`}function bM(e){let{line:t,path:n,text:r}=e,i=t??1;return{key:`preview:${n}`,path:n,display:`preview`,lines:pk({text:r,kind:`context`,oldStartLine:i,newStartLine:i}),rawText:r,oldStartLine:i,newStartLine:i}}function xM(e){if(Array.isArray(e.fullLines)&&e.fullLines.length>0)return{key:`diff:${e.key}`,path:e.path,display:`diff`,lines:e.fullLines,fullLines:e.fullLines,...e.beforeText?{beforeText:e.beforeText}:{},...e.afterText?{afterText:e.afterText}:{},...e.patchText?{patchText:e.patchText}:{},...typeof e.oldStartLine==`number`?{oldStartLine:e.oldStartLine}:{},...typeof e.newStartLine==`number`?{newStartLine:e.newStartLine}:{}};if(e.beforeText==null&&e.afterText==null)return null;let t=_k({beforeText:e.beforeText??``,afterText:e.afterText??``,oldStartLine:e.oldStartLine??void 0,newStartLine:e.newStartLine??void 0});return{key:`diff:${e.key}`,path:e.path,display:`diff`,lines:t,fullLines:t,...e.beforeText?{beforeText:e.beforeText}:{},...e.afterText?{afterText:e.afterText}:{},...typeof e.oldStartLine==`number`?{oldStartLine:e.oldStartLine}:{},...typeof e.newStartLine==`number`?{newStartLine:e.newStartLine}:{}}}function SM({text:e,tone:t=`muted`}){return(0,N.jsx)(`div`,{className:d(`flex h-full items-center justify-center px-6 text-center text-sm`,t===`error`?`text-rose-600`:`text-gray-500`),children:e})}function CM({diffBlock:e}){return e?(0,N.jsx)(wM,{block:e}):(0,N.jsx)(SM,{text:o(`chatWorkspaceDiffEmpty`)})}function wM({block:e}){return(0,N.jsx)(`div`,{className:`h-full overflow-auto custom-scrollbar bg-white`,children:(0,N.jsx)(hE,{block:e,layout:`workspace`})})}function TM({onFileOpen:e,previewBlock:t,previewKind:n,previewQuery:r,previewText:i}){return r.isLoading&&!t?(0,N.jsx)(SM,{text:o(`chatWorkspaceLoadingFile`)}):r.data?.kind===`binary`?(0,N.jsx)(SM,{text:o(`chatWorkspacePreviewUnsupported`)}):r.error&&!t?(0,N.jsx)(SM,{tone:`error`,text:r.error instanceof Error?r.error.message:String(r.error)}):n===`markdown`&&i?(0,N.jsx)(`div`,{className:`h-full overflow-auto custom-scrollbar px-5 py-4`,children:(0,N.jsx)(aT,{text:i,role:`assistant`,texts:{copyCodeLabel:o(`chatCodeCopy`),copiedCodeLabel:o(`chatCodeCopied`)},onFileOpen:e})}):t?(0,N.jsx)(wM,{block:t}):(0,N.jsx)(SM,{text:o(`chatWorkspacePreviewEmpty`)})}function EM({file:e,sessionProjectRoot:t,onFileOpen:n}){let r=e.viewMode===`preview`,i=vM({path:e.path,basePath:t,enabled:r}),a=(0,P.useMemo)(()=>e.viewMode===`diff`?xM(e):null,[e]),o=r?i.data?.text??e.rawText??null:null,s=yM({path:i.data?.resolvedPath??e.path,serverKind:i.data?.kind}),c=(0,P.useMemo)(()=>!r||!o?null:bM({path:i.data?.resolvedPath??e.path,text:o,line:e.line}),[e.line,e.path,r,i.data?.resolvedPath,o]),l=i.data?.resolvedPath??e.path,u=!!i.data?.truncated;return(0,N.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-white`,children:[(0,N.jsx)(_M,{breadcrumb:(0,P.useMemo)(()=>LA({path:l,sessionProjectRoot:t,line:e.line,column:e.column,truncated:u}),[e.column,e.line,u,l,t])}),(0,N.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:e.viewMode===`diff`?(0,N.jsx)(CM,{diffBlock:a}):(0,N.jsx)(TM,{onFileOpen:n,previewBlock:c,previewKind:s,previewQuery:i,previewText:o})})]})}function DM(e,t){return e.label?.trim()?e.label.trim():t?Kj(t):e.sessionKey}function OM(e){let t=pt({limit:200}),n=(0,P.useMemo)(()=>t.data?.sessions??[],[t.data?.sessions]),r=(0,P.useMemo)(()=>{let e=ij(n);return new Map(e.map(e=>[e.key,e]))},[n]),i=(0,P.useMemo)(()=>new Map(n.map(e=>[e.sessionId,e])),[n]);return(0,P.useMemo)(()=>e.map(e=>{let t=r.get(e.sessionKey)??null,n=i.get(e.sessionKey)??null,a=e.agentId?.trim()||t?.agentId||null;return{sessionKey:e.sessionKey,parentSessionKey:e.parentSessionKey,title:DM(e,t),agentId:a,updatedAt:t?.updatedAt??null,lastMessageAt:t?.lastMessageAt??null,readAt:t?.readAt??null,runStatus:n?.status===`running`?`running`:void 0,sessionTypeLabel:t?.sessionType?jj(t.sessionType):null,preferredModel:t?.preferredModel?.trim()||null,projectName:t?.projectName?.trim()||null,projectRoot:t?.projectRoot?.trim()||null}}),[r,i,e])}function kM(e){let t=e.split(/\r?\n/),n=`message`,r=[];for(let e of t){let t=e.trimEnd();if(!(!t||t.startsWith(`:`))){if(t.startsWith(`event:`)){n=t.slice(6).trim()||`message`;continue}t.startsWith(`data:`)&&r.push(t.slice(5).trimStart())}}return r.length===0?null:{event:n,data:r.join(`
|
|
60
|
-
`)}}async function*AM(e){let t=e.getReader(),n=new TextDecoder,r=``;try{for(;;){let{value:e,done:i}=await t.read();if(i)break;r+=n.decode(e,{stream:!0});let{frames:a,rest:o}=jM(r);r=o;for(let e of a)yield e}r+=n.decode();let{frames:e}=jM(r,!0);for(let t of e)yield t}finally{t.releaseLock()}}function jM(e,t=!1){let n=e.split(/\r?\n\r?\n/),r=n.pop()??``,i=[];for(let e of n){let t=kM(e);t&&i.push(t)}if(t&&r.trim()){let e=kM(r);return e&&i.push(e),{frames:i,rest:``}}return{frames:i,rest:r}}var MM=`/ncp/agent`,NM=class extends Error{ncpError;alreadyPublished;constructor(e,t=!1){super(e.message),this.name=`NcpHttpAgentClientError(${e.code})`,this.ncpError=e,this.alreadyPublished=t}};function PM(e){let t=e.trim();if(!t)throw Error(`NcpHttpAgentClient requires a non-empty baseUrl.`);return new URL(t)}function FM(e){if(e)return e;if(typeof globalThis.fetch==`function`)return globalThis.fetch.bind(globalThis);throw Error(`No fetch implementation found. Pass options.fetchImpl explicitly.`)}function IM(e){let t=(e??`/ncp/agent`).trim();if(!t)return MM;let n=t.startsWith(`/`)?t:`/${t}`;return n.endsWith(`/`)?n.slice(0,-1):n}async function LM(e){try{return(await e.text()).trim()}catch{return``}}function RM(e){if(HM(e))return e.ncpError;if(BM(e))return e;let t=e instanceof Error?e.message:String(e??`Unknown error`);return{code:WM(void 0),message:t,...e instanceof Error&&e.stack?{details:{stack:e.stack}}:{}}}function zM(e,t={}){return new NM(e,t.alreadyPublished??!1)}function BM(e){return VM(e)&&typeof e.code==`string`&&typeof e.message==`string`}function VM(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function HM(e){return e instanceof NM}var UM={"config-error":`config-error`,"auth-error":`auth-error`,"runtime-error":`runtime-error`,"timeout-error":`timeout-error`,"abort-error":`abort-error`};function WM(e){if(!e)return`runtime-error`;let t=UM[e];if(t)return t;let n=e.toLowerCase();return n.includes(`timeout`)?`timeout-error`:n.includes(`abort`)||n.includes(`cancel`)?`abort-error`:n.includes(`auth`)?`auth-error`:n.includes(`config`)?`config-error`:`runtime-error`}function GM(e){let t=qM(e);return!t||typeof t.type!=`string`||!t.type.trim()?null:t}function KM(e){let t=qM(e);if(!t)return{code:`runtime-error`,message:e||`Unknown stream error.`};let n=typeof t.code==`string`?t.code:void 0,r=WM(n),i=VM(t.details)?t.details:{};return n&&n!==r&&(i.originalCode=n),{code:r,message:typeof t.message==`string`&&t.message?t.message:`Unknown stream error.`,...Object.keys(i).length>0?{details:i}:{}}}function qM(e){try{let t=JSON.parse(e);return VM(t)?t:null}catch{return null}}var JM=[`text`,`file`,`source`,`step-start`,`reasoning`,`tool-invocation`,`card`,`rich-text`,`action`,`extension`],YM=class{manifest;baseUrl;basePath;fetchImpl;defaultHeaders;subscribers=new Set;activeControllers=new Set;started=!1;constructor(e){this.baseUrl=PM(e.baseUrl),this.basePath=IM(e.basePath),this.fetchImpl=FM(e.fetchImpl),this.defaultHeaders=e.headers??{},this.manifest={endpointKind:`custom`,endpointId:e.endpointId?.trim()||`ncp-http-agent-client`,version:`0.1.0`,supportsStreaming:!0,supportsAbort:!0,supportsProactiveMessages:!1,supportsLiveSessionStream:!0,supportedPartTypes:JM,expectedLatency:`seconds`,metadata:{transport:`http+sse`,scope:`agent`}}}async start(){this.started||(this.started=!0,this.publish({type:$E.EndpointReady}))}async stop(){if(this.started){this.started=!1;for(let e of this.activeControllers)e.abort();this.activeControllers.clear()}}async emit(e){switch(e.type){case`message.request`:await this.send(e.payload);return;case`message.stream-request`:await this.stream(e.payload);return;case`message.abort`:await this.abort(e.payload);return;default:this.publish(e);return}}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}async send(e){await this.ensureStarted(),await this.jsonRequest({path:`/send`,method:`POST`,body:e})}async stream(e){await this.ensureStarted();let t=new URLSearchParams({sessionId:e.sessionId});await this.streamRequest({path:`/stream?${t.toString()}`,method:`GET`})}async abort(e){await this.ensureStarted();let t=new AbortController;this.activeControllers.add(t);try{let n=await this.fetchImpl(this.resolveUrl(`/abort`),{method:`POST`,headers:{...this.defaultHeaders,"content-type":`application/json`,accept:`application/json`},body:JSON.stringify(e),signal:t.signal});if(!n.ok)throw Error(`Abort request failed with HTTP ${n.status}: ${await LM(n)}`)}catch(e){if(t.signal.aborted)return;let n=RM(e);throw this.publish({type:$E.EndpointError,payload:n}),zM(n)}finally{this.activeControllers.delete(t)}}async ensureStarted(){this.started||await this.start()}publish(e){for(let t of this.subscribers)t(e)}resolveUrl(e){return new URL(`${this.basePath}${e}`,this.baseUrl)}async jsonRequest(e){let t=new AbortController;this.activeControllers.add(t);try{let n=await this.fetchImpl(this.resolveUrl(e.path),{method:e.method,headers:{...this.defaultHeaders,"content-type":`application/json`,accept:`application/json`},body:e.body===void 0?void 0:JSON.stringify(e.body),signal:t.signal});if(!n.ok)throw Error(`NCP request failed with HTTP ${n.status}: ${await LM(n)}`)}catch(e){if(t.signal.aborted)return;if(HM(e))throw e;let n=RM(e);throw this.publish({type:$E.EndpointError,payload:n}),zM(n)}finally{this.activeControllers.delete(t)}}async streamRequest(e){let t=new AbortController;this.activeControllers.add(t);try{let n=await this.fetchImpl(this.resolveUrl(e.path),{method:e.method,headers:{...this.defaultHeaders,accept:`text/event-stream`,...e.body===void 0?{}:{"content-type":`application/json`}},body:e.body===void 0?void 0:JSON.stringify(e.body),signal:t.signal});if(!n.ok)throw Error(`NCP stream request failed with HTTP ${n.status}: ${await LM(n)}`);if(!n.body)throw Error(`NCP stream response has no body.`);for await(let e of AM(n.body)){if(t.signal.aborted)return;this.handleSseFrame(e)}}catch(e){if(t.signal.aborted)return;if(HM(e))throw e;let n=RM(e);throw this.publish({type:$E.EndpointError,payload:n}),zM(n)}finally{this.activeControllers.delete(t)}}handleSseFrame(e){if(e.event===`ncp-event`){let t=GM(e.data);if(!t){this.publish({type:$E.EndpointError,payload:{code:`runtime-error`,message:`Received malformed ncp-event frame.`}});return}this.publish(t);return}if(e.event===`error`){let t=KM(e.data);throw this.publish({type:$E.EndpointError,payload:t}),zM(t,{alreadyPublished:!0})}}};function XM(e){return typeof e==`string`?e:e instanceof URL?e.toString():e.url}function ZM(e){if(e instanceof Error){let t=e.name?.trim(),n=e.message?.trim();return t&&n?`${t}: ${n}`:n||t||`Unknown Error`}return String(e??`Unknown error`)}function QM(e,t){let n=Error(e);return t!==void 0&&(n.cause=t),n}function $M(){return async(e,t)=>{try{return await fetch(e,{credentials:`include`,...t})}catch(n){throw oe.reportTransportFailure(ZM(n)),QM(`NCP fetch failed for ${(t?.method||`GET`).toUpperCase()} ${XM(e)}: ${ZM(n)}`,n)}}}var eN=300,tN=`ncp agent unavailable during startup`;function nN(e){return e instanceof Error?e.message.includes(`ncp session not found:`):!1}function rN(e){return e?.trim().toLowerCase().includes(tN)??!1}function iN(){return new YM({baseUrl:re,basePath:`/api/ncp/agent`,fetchImpl:$M()})}async function aN(e,t,n=eN){t.throwIfAborted();try{let r=await w(e,n);return t.throwIfAborted(),{messages:r.messages,status:r.status??`idle`}}catch(e){if(t.throwIfAborted(),!nN(e))throw e;return{messages:[],status:`idle`}}}function oN(e,t){let n=(0,P.useRef)(null),r=(0,P.useCallback)(e=>{if(!e){n.current=null;return}n.current!==e&&(n.current=e,t())},[t]);(0,P.useEffect)(()=>{r(e)},[e,r])}function sN(e,t={}){let[n]=(0,P.useState)(()=>iN()),r=k(),[i,a]=(0,P.useState)(0),o=t.messageLimit??eN,s=ED({sessionId:e,client:n,loadSeed:(0,P.useCallback)((e,t)=>aN(e,t,o),[i,o])}),c=s.hydrateError?.message??s.snapshot.error?.message??null;return oN(r.phase===`ready`&&rN(c)?`${e}:${r.lastReadyAt??0}`:null,()=>{a(e=>e+1)}),s}function cN(e){return e.label?.trim()||e.path.split(`/`).filter(Boolean).pop()||e.path}function lN(e){let{activeChildSessionKey:t,activeWorkspaceFileKey:n,childSessionTabs:r,workspaceFileTabs:i}=e;if(n){let e=i.find(e=>e.key===n);if(e)return{kind:`file`,file:e}}if(t){let e=r.find(e=>e.sessionKey===t);if(e)return{kind:`child-session`,tab:e}}return r[0]?{kind:`child-session`,tab:r[0]}:i[0]?{kind:`file`,file:i[0]}:null}function uN({agentId:e,kind:t}){return t===`file`?(0,N.jsx)(Ht,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):e?(0,N.jsx)(fj,{agentId:e,className:`h-3.5 w-3.5 shrink-0`}):(0,N.jsx)(rn,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`})}function dN({tab:e}){return(0,N.jsx)(kt,{delayDuration:250,children:(0,N.jsxs)(jt,{children:[(0,N.jsx)(Tt,{asChild:!0,children:(0,N.jsxs)(`div`,{className:d(`group flex max-w-[180px] min-w-0 items-center gap-1.5 border-r border-gray-200/70 border-b-2 px-2.5 py-2 transition-colors`,e.active?`border-b-primary bg-white text-gray-900`:`border-b-transparent bg-gray-50/85 text-gray-500 hover:bg-gray-100`),children:[(0,N.jsxs)(`button`,{type:`button`,onClick:e.onSelect,className:`flex min-w-0 flex-1 items-center gap-1.5 text-left`,children:[(0,N.jsx)(uN,{kind:e.kind,agentId:e.agentId}),(0,N.jsx)(`span`,{className:`min-w-0 truncate text-[12px] font-medium`,children:e.title}),e.kind===`file`&&e.viewMode===`diff`?(0,N.jsx)(`span`,{className:`shrink-0 rounded border border-amber-200 bg-amber-50 px-1 py-0 text-[9px] font-medium uppercase tracking-[0.08em] text-amber-700`,children:o(`chatWorkspaceDiff`)}):null,e.showUnreadDot?(0,N.jsx)(`span`,{"aria-label":o(`chatSessionUnread`),className:`h-2 w-2 shrink-0 rounded-full bg-primary`}):null]}),e.onClose?(0,N.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),e.onClose?.()},className:d(`rounded p-0.5 text-gray-400 transition-colors hover:bg-gray-200 hover:text-gray-700`,e.active?`opacity-100`:`opacity-0 group-hover:opacity-100`),"aria-label":o(`chatWorkspaceCloseFile`),children:(0,N.jsx)(ct,{className:`h-3 w-3`})}):null]})}),(0,N.jsx)(Dt,{side:`bottom`,className:`max-w-[320px] text-xs`,children:e.tooltip})]})})}function fN({tabs:e}){return(0,N.jsx)(`div`,{"data-testid":`workspace-tabs-bar`,className:`workspace-horizontal-scrollbar overflow-x-auto overflow-y-hidden border-b border-gray-200/70 bg-gray-50/85`,children:(0,N.jsx)(`div`,{"data-testid":`workspace-tabs-scroll`,className:`flex min-w-max items-stretch`,children:e.map(e=>(0,N.jsx)(dN,{tab:e},e.key))})})}function pN({sessionKey:e,onToolAction:t,onFileOpen:n}){let r=sN(e),i=r.visibleMessages,a=(0,P.useRef)(null),{onScroll:s}=WT({scrollRef:a,resetKey:e,isLoading:r.isHydrating,hasContent:i.length>0,contentVersion:i[i.length-1]??null,stickyThresholdPx:20});return(0,N.jsx)(`div`,{ref:a,onScroll:s,className:`h-full overflow-y-auto custom-scrollbar`,children:r.isHydrating?(0,N.jsxs)(`div`,{className:`flex h-full items-center justify-center text-sm text-gray-500`,children:[(0,N.jsx)(nt,{className:`mr-2 h-4 w-4 animate-spin`}),o(`chatChildSessionLoading`)]}):r.hydrateError?(0,N.jsx)(`div`,{className:`px-4 py-5 text-sm text-rose-600`,children:r.hydrateError.message}):i.length===0&&!r.isRunning?(0,N.jsx)(`div`,{className:`px-4 py-5 text-sm text-gray-500`,children:o(`chatChildSessionEmpty`)}):(0,N.jsx)(`div`,{className:`px-4 py-5`,children:(0,N.jsx)(gj,{messages:i,isSending:r.isRunning,onToolAction:t,onFileOpen:n})})})}function mN({value:e}){return(0,N.jsx)(`span`,{className:`inline-flex max-w-full items-center rounded border border-gray-200 bg-gray-50 px-2 py-0.5 text-[10px] font-medium text-gray-600`,children:(0,N.jsx)(`span`,{className:`truncate`,children:e})})}function hN({tab:e}){let t=[e.sessionTypeLabel,e.preferredModel,e.projectName].filter(e=>!!e?.trim());return t.length===0&&!e.projectRoot?null:(0,N.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[t.length>0?(0,N.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(e=>(0,N.jsx)(mN,{value:e},e))}):null,e.projectRoot?(0,N.jsx)(`div`,{title:e.projectRoot,className:`truncate rounded border border-gray-200 bg-gray-50 px-2 py-1.5 font-mono text-[11px] text-gray-500`,children:e.projectRoot}):null]})}function gN({tab:e}){return(0,N.jsxs)(`div`,{className:`border-b border-gray-200/70 px-4 py-3`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-sm font-semibold text-gray-900`,children:[e.agentId?(0,N.jsx)(fj,{agentId:e.agentId,className:`h-4 w-4 shrink-0`}):(0,N.jsx)(Yt,{className:`h-4 w-4 shrink-0 text-gray-400`}),(0,N.jsx)(`span`,{className:`truncate`,children:e.title})]}),(0,N.jsx)(hN,{tab:e})]})}function _N(e){let{resolvedChildTabs:t,workspaceFileTabs:n,activeSelection:r,optimisticReadAtBySessionKey:i,onSelectSession:a,onSelectFile:o,onCloseFile:s}=e,c=t.map(e=>{let t=i[e.sessionKey],n=t&&e.readAt?t.localeCompare(e.readAt)>0?t:e.readAt:t??e.readAt;return{key:`child:${e.sessionKey}`,kind:`child-session`,title:e.title,tooltip:e.title,agentId:e.agentId,active:r?.kind===`child-session`&&r.tab.sessionKey===e.sessionKey,showUnreadDot:Xj({active:r?.kind===`child-session`&&r.tab.sessionKey===e.sessionKey,lastMessageAt:e.lastMessageAt,readAt:n,runStatus:e.runStatus}),onSelect:()=>a(e.sessionKey)}}),l=n.map(e=>({key:`file:${e.key}`,kind:`file`,title:cN(e),tooltip:e.path,viewMode:e.viewMode,active:r?.kind===`file`&&r.file.key===e.key,onSelect:()=>o(e.key),onClose:()=>s(e.key)}));return[...c,...l]}function vN({childSessionTabs:e,activeChildSessionKey:t,workspaceFileTabs:n,activeWorkspaceFileKey:r,sessionProjectRoot:i,displayMode:a=`docked`,onSelectSession:s,onSelectFile:c,onCloseFile:l,onClose:u,onBackToParent:f,onToolAction:p,onFileOpen:m}){let h=XD(),g=OM(e),_=eM(e=>e.optimisticReadAtBySessionKey),v=lN({activeChildSessionKey:t,activeWorkspaceFileKey:r,childSessionTabs:g,workspaceFileTabs:n}),y=g.some(e=>!!e.parentSessionKey);(0,P.useEffect)(()=>{if(v?.kind!==`child-session`)return;let e=v.tab.lastMessageAt?.trim()??null;e&&h.chatSessionListManager.markSessionRead(v.tab.sessionKey,e,v.tab.readAt??null)},[v,h]);let b=(0,P.useMemo)(()=>_N({resolvedChildTabs:g,workspaceFileTabs:n,activeSelection:v,optimisticReadAtBySessionKey:_,onSelectSession:s,onSelectFile:c,onCloseFile:l}),[v,l,c,s,_,g,n]);return v?(0,N.jsx)(`aside`,{className:d(a===`overlay`?`fixed inset-0 z-40 flex bg-white`:`hidden shrink-0 border-l border-gray-200/70 bg-white/95 backdrop-blur-sm md:flex md:w-[26rem] lg:w-[30rem] xl:w-[34rem]`),children:(0,N.jsxs)(`div`,{className:`flex h-full min-h-0 w-full flex-col`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-gray-200/70 px-4 py-2.5`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:f,className:d(`inline-flex items-center gap-1 text-xs font-medium text-gray-600 transition-colors hover:text-gray-900`,!y&&`pointer-events-none opacity-0`),children:[(0,N.jsx)(De,{className:`h-3.5 w-3.5`}),(0,N.jsx)(`span`,{children:o(`chatBackToParent`)})]}),(0,N.jsx)(`button`,{type:`button`,onClick:u,className:`rounded-full border border-gray-200/80 p-1.5 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900`,"aria-label":o(`chatWorkspaceClosePanel`),children:(0,N.jsx)(ct,{className:`h-4 w-4`})})]}),(0,N.jsx)(fN,{tabs:b}),(0,N.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col bg-white`,children:v.kind===`child-session`?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(gN,{tab:v.tab}),(0,N.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,N.jsx)(pN,{sessionKey:v.tab.sessionKey,onToolAction:p,onFileOpen:m})})]}):(0,N.jsx)(EM,{file:v.file,sessionProjectRoot:i,onFileOpen:m})})]})}):null}function yN(){return g({queryKey:[`ncp-session-types`],queryFn:h,staleTime:1e4,retry:!1})}function bN(e){let t=e.trim();return t.length>0?t:null}function xN(e){return e??null}var SN=class{constructor(e){this.updateSession=e,this.inFlight=null,this.queued=null,this.syncSelectedSessionPreferences=()=>{let e=Q.getState().snapshot,t=eM.getState().snapshot,n=Fj.getState().snapshot,r=t.selectedSessionKey;!r||!n.canDeleteSession||this.enqueue({sessionKey:r,patch:{preferredModel:bN(e.selectedModel),preferredThinking:xN(e.selectedThinkingLevel)}})},this.enqueue=e=>{this.queued=e,!this.inFlight&&this.startFlush()},this.startFlush=()=>{this.inFlight=this.flush().catch(e=>{console.error(`Failed to sync chat session preferences: ${String(e)}`)}).finally(()=>{this.inFlight=null,this.queued&&this.startFlush()})},this.flush=async()=>{for(;this.queued;){let e=this.queued;this.queued=null,await this.updateSession(e.sessionKey,e.patch)}}}},CN=class{constructor(e,t,n){this.uiManager=e,this.streamActionsManager=t,this.sessionListManager=n,this.sessionPreferenceSync=new SN(ae),this.buildAttachmentSignature=e=>[e.assetUri??``,e.url??``,e.name,e.mimeType,String(e.sizeBytes),e.contentBase64??``].join(`:`),this.hasSnapshotChanges=e=>{let t=Q.getState().snapshot;for(let[n,r]of Object.entries(e))if(!Object.is(t[n],r))return!0;return!1},this.resolveUpdateValue=(e,t)=>typeof t==`function`?t(e):t,this.isSameStringArray=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),this.syncComposerSnapshot=e=>{let t=Q.getState().snapshot.attachments,n=oO(e,t);Q.getState().setSnapshot({composerNodes:e,attachments:n,draft:tO(e),selectedSkills:nO(e)})},this.syncComposerSnapshotWithAttachments=(e,t)=>{Q.getState().setSnapshot({composerNodes:e,attachments:t,draft:tO(e),selectedSkills:nO(e)})},this.dedupeAttachments=e=>{let t=new Set,n=[];for(let r of e){let e=this.buildAttachmentSignature(r);t.has(e)||(t.add(e),n.push(r))}return n},this.syncSnapshot=e=>{if(this.hasSnapshotChanges(e)&&(Q.getState().setSnapshot(e),Object.prototype.hasOwnProperty.call(e,`modelOptions`)||Object.prototype.hasOwnProperty.call(e,`selectedModel`)||Object.prototype.hasOwnProperty.call(e,`selectedThinkingLevel`))){let{selectedModel:e}=Q.getState().snapshot;this.reconcileThinkingForModel(e)}},this.setDraft=e=>{let t=Q.getState().snapshot.draft,n=this.resolveUpdateValue(t,e);n!==t&&this.syncComposerSnapshot(eO(n))},this.setComposerNodes=e=>{let t=Q.getState().snapshot.composerNodes,n=this.resolveUpdateValue(t,e);Object.is(n,t)||this.syncComposerSnapshot(n)},this.addAttachments=e=>{if(e.length===0)return[];let{snapshot:t}=Q.getState(),n=new Set(t.attachments.map(this.buildAttachmentSignature)),r=this.dedupeAttachments([...t.attachments,...e]),i=r.filter(e=>!n.has(this.buildAttachmentSignature(e)));if(i.length===0)return[];let a=aO(t.composerNodes,r);return this.syncComposerSnapshotWithAttachments(a,r),i},this.restoreComposerState=(e,t)=>{let n=this.dedupeAttachments(t),r=aO(e,n);this.syncComposerSnapshotWithAttachments(r,n)},this.setPendingSessionType=e=>{let t=Q.getState().snapshot.pendingSessionType,n=this.resolveUpdateValue(t,e);n!==t&&Q.getState().setSnapshot({pendingSessionType:n})},this.send=async()=>{let e=Q.getState().snapshot,t=eM.getState().snapshot,n=Fj.getState().snapshot,r=e.draft.trim(),{attachments:i}=e,a=sO(e.composerNodes,i);if(gO({snapshot:e,hasSendableDraft:a.some(e=>e.type!==`text`||e.text.trim().length>0),isRuntimeBlocked:oe.isChatInteractionBlocked()}))return;let{selectedSkills:o,composerNodes:s}=e,c=n.sessionKey??t.selectedSessionKey??this.sessionListManager.ensureDraftSession(e.selectedSessionType);this.setComposerNodes($D()),await this.streamActionsManager.sendMessage({message:r,sessionKey:c,agentId:t.selectedAgentId,sessionType:e.selectedSessionType,model:e.selectedModel||void 0,thinkingLevel:e.selectedThinkingLevel??void 0,stopSupported:!0,requestedSkills:o,attachments:i,parts:a,restoreDraftOnError:!0,composerNodes:s}),this.sessionListManager.promoteRootDraftSessionRoute(c)},this.stop=async()=>{await this.streamActionsManager.stopCurrentRun()},this.goToProviders=()=>{this.uiManager.goToProviders()},this.setSelectedModel=e=>{let t=Q.getState().snapshot.selectedModel,n=this.resolveUpdateValue(t,e);n!==t&&(Q.getState().setSnapshot({selectedModel:n}),this.reconcileThinkingForModel(n))},this.setSelectedThinkingLevel=e=>{let t=Q.getState().snapshot.selectedThinkingLevel,n=this.resolveUpdateValue(t,e);n!==t&&Q.getState().setSnapshot({selectedThinkingLevel:n})},this.selectSessionType=e=>{let t=kj(e);Q.getState().setSnapshot({selectedSessionType:t,pendingSessionType:t})},this.setSelectedSkills=e=>{let{snapshot:t}=Q.getState(),{selectedSkills:n}=t,r=this.resolveUpdateValue(n,e);this.isSameStringArray(r,n)||this.syncComposerSnapshot(iO(t.composerNodes,r,t.skillRecords))},this.selectModel=e=>{this.setSelectedModel(e),uO.remember(e),this.sessionPreferenceSync.syncSelectedSessionPreferences()},this.selectThinkingLevel=e=>{this.setSelectedThinkingLevel(e),this.sessionPreferenceSync.syncSelectedSessionPreferences()},this.rememberSkillSelection=e=>{dO.remember(e)},this.selectSkills=e=>{let t=Q.getState().snapshot.selectedSkills;for(let n of e)t.includes(n)||this.rememberSkillSelection(n);this.setSelectedSkills(e)},this.resolveThinkingForModel=(e,t)=>{let n=e?.thinkingCapability;return!n||n.supported.length===0?null:t===`off`?`off`:t&&n.supported.includes(t)?t:n.default&&n.supported.includes(n.default)?n.default:`off`},this.reconcileThinkingForModel=e=>{let{snapshot:t}=Q.getState(),n=t.modelOptions.find(t=>t.value===e),{selectedThinkingLevel:r}=t,i=this.resolveThinkingForModel(n,r);i!==r&&Q.getState().setSnapshot({selectedThinkingLevel:i})}}},wN=class{constructor(e,t){this.uiManager=e,this.streamActionsManager=t,this.syncDraftThreadState=e=>{Fj.getState().setSnapshot({sessionKey:e,sessionDisplayName:void 0,canDeleteSession:!1,isHistoryLoading:!1,messages:[],isSending:!1,isAwaitingAssistantOutput:!1,parentSessionKey:null,parentSessionLabel:null,workspacePanelParentKey:null,childSessionTabs:[],activeChildSessionKey:null,activeWorkspaceFileKey:null})},this.resolveUpdateValue=(e,t)=>typeof t==`function`?t(e):t,this.shouldPersistReadAt=(e,t,n)=>{let r=eM.getState().optimisticReadAtBySessionKey[e],i=r&&n?r.localeCompare(n)>0?r:n:r??n??void 0;return i?t.localeCompare(i)>0:!0},this.setSelectedAgentId=e=>{let t=eM.getState().snapshot.selectedAgentId,n=this.resolveUpdateValue(t,e);n!==t&&eM.getState().setSnapshot({selectedAgentId:n})},this.setSelectedSessionKey=e=>{let t=eM.getState().snapshot.selectedSessionKey,n=this.resolveUpdateValue(t,e);n!==t&&eM.getState().setSnapshot({selectedSessionKey:n})},this.setListMode=e=>{let t=eM.getState().snapshot.listMode,n=this.resolveUpdateValue(t,e);n!==t&&eM.getState().setSnapshot({listMode:n})},this.markSessionRead=(e,t,n)=>{let r=e?.trim(),i=t?.trim();!r||!i||this.shouldPersistReadAt(r,i,n)&&(eM.getState().markSessionRead(r,i),ae(r,{uiReadAt:i}).catch(()=>void 0))},this.createSession=(e,t)=>{let{snapshot:n}=Q.getState(),{defaultSessionType:r}=n,i=r||`native`,a=typeof e==`string`&&e.trim().length>0?e.trim():i,o=kA(t),s=aj();return this.streamActionsManager.resetStreamState(),eM.getState().setSnapshot({selectedSessionKey:null,draftSessionKey:s}),this.syncDraftThreadState(s),Q.getState().setSnapshot({pendingSessionType:a,pendingProjectRoot:o,pendingProjectRootSessionKey:o?s:null}),this.uiManager.goToChatRoot(),s},this.ensureDraftSession=e=>{let{snapshot:t}=eM.getState();if(t.selectedSessionKey)return t.selectedSessionKey;let n=typeof e==`string`&&e.trim().length>0?e.trim():null;return this.syncDraftThreadState(t.draftSessionKey),n&&Q.getState().setSnapshot({pendingSessionType:n}),t.draftSessionKey},this.promoteRootDraftSessionRoute=e=>{let t=e.trim();if(!t)return;let{snapshot:n}=eM.getState(),{sessionKey:r}=Fj.getState().snapshot;n.selectedSessionKey!==null||n.draftSessionKey!==t||r!==t||!this.uiManager.isAtChatRoot()||this.uiManager.goToSession(t,{replace:!0})},this.selectSession=e=>{Fj.getState().setSnapshot({workspacePanelParentKey:null,activeChildSessionKey:null,activeWorkspaceFileKey:null}),this.uiManager.goToSession(e)},this.setQuery=e=>{let t=eM.getState().snapshot.query,n=this.resolveUpdateValue(t,e);n!==t&&eM.getState().setSnapshot({query:n})}}},TN=async()=>{},EN=()=>{},DN=class{constructor(){this.actions={sendMessage:TN,stopCurrentRun:TN,resumeRun:TN,resetStreamState:EN,applyHistoryMessages:EN},this.bind=e=>{this.actions={...this.actions,...e}},this.sendMessage=e=>this.actions.sendMessage(e),this.stopCurrentRun=()=>this.actions.stopCurrentRun(),this.resumeRun=e=>this.actions.resumeRun(e),this.resetStreamState=()=>this.actions.resetStreamState(),this.applyHistoryMessages=(e,t)=>this.actions.applyHistoryMessages(e,t)}},ON=`sid_`;function kN(e){let t=new TextEncoder().encode(e),n=``;for(let e of t)n+=String.fromCharCode(e);return`${ON}${btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/g,``)}`}function AN(e){if(!e.startsWith(ON))return null;let t=e.slice(4).replace(/-/g,`+`).replace(/_/g,`/`),n=`=`.repeat((4-t.length%4)%4);try{let e=atob(t+n),r=Uint8Array.from(e,e=>e.charCodeAt(0));return new TextDecoder().decode(r)}catch{return null}}function jN(e){if(!e)return null;let t=AN(e);if(t)return t;try{return decodeURIComponent(e)}catch{return e}}function MN(e){return`/chat/${kN(e)}`}var NN=async e=>!1,PN=class{constructor(){this.state={pathname:``},this.actions={navigate:null,confirm:NN},this.syncState=e=>{this.state={...this.state,...e}},this.bindActions=e=>{this.actions={...this.actions,...e}},this.confirm=async e=>this.actions.confirm(e),this.navigateTo=(e,t)=>{this.actions.navigate&&(this.state.pathname===e&&!t?.replace||(this.actions.navigate(e,t),this.state.pathname=e))},this.goToProviders=()=>{this.navigateTo(`/providers`)},this.goToChatRoot=e=>{this.navigateTo(`/chat`,e)},this.isAtChatRoot=()=>this.state.pathname===`/chat`,this.goToSession=(e,t)=>{this.navigateTo(MN(e),t)}}},FN=class{constructor(e,t,n){this.uiManager=e,this.sessionListManager=t,this.streamActionsManager=n,this.hasSnapshotChanges=e=>{let t=Fj.getState().snapshot;for(let[n,r]of Object.entries(e))if(!Object.is(t[n],r))return!0;return!1},this.syncSnapshot=e=>{this.hasSnapshotChanges(e)&&Fj.getState().setSnapshot(e)},this.clearDeletedSessionState=e=>{eM.getState().snapshot.selectedSessionKey===e&&this.sessionListManager.setSelectedSessionKey(null),Fj.getState().setSnapshot({sessionKey:null,sessionTypeLabel:null,agentId:null,agentDisplayName:null,agentAvatarUrl:null,sessionDisplayName:void 0,sessionProjectRoot:null,sessionProjectName:null,canDeleteSession:!1,isHistoryLoading:!1,messages:[],isSending:!1,isAwaitingAssistantOutput:!1,parentSessionKey:null,parentSessionLabel:null,workspacePanelParentKey:null,childSessionTabs:[],activeChildSessionKey:null,workspaceFileTabs:[],activeWorkspaceFileKey:null})},this.resolveWorkspaceParentSessionKey=()=>Fj.getState().snapshot.sessionKey?.trim()||(eM.getState().snapshot.selectedSessionKey??null),this.buildWorkspaceFileTab=(e,t)=>{let n=e.path.trim();if(!n)return null;let r=t?.trim()||null;return{key:`${r??`draft`}::${e.viewMode}::${n}`,parentSessionKey:r,path:n,label:e.label?.trim()||null,viewMode:e.viewMode,line:e.line??null,column:e.column??null,rawText:e.rawText??null,beforeText:e.beforeText??null,afterText:e.afterText??null,patchText:e.patchText??null,oldStartLine:e.oldStartLine??null,newStartLine:e.newStartLine??null,fullLines:e.fullLines}},this.upsertWorkspaceFileTab=e=>{let{workspaceFileTabs:t}=Fj.getState().snapshot,n=t.findIndex(t=>t.key===e.key);if(n===-1)return[e,...t];let r=[...t];return r.splice(n,1),r.unshift({...t[n],...e}),r},this.ensureWorkspaceParentRoute=e=>{if(!e)return;let{snapshot:{selectedSessionKey:t}}=eM.getState();t!==e&&this.uiManager.goToSession(e)},this.deleteSession=()=>{this.deleteCurrentSession()},this.createSession=()=>{this.sessionListManager.createSession()},this.goToProviders=()=>{this.uiManager.goToProviders()},this.openChildSessionPanel=e=>{let t=e.parentSessionKey.trim();if(!t)return;let n=e.activeChildSessionKey?.trim()||null;Fj.getState().setSnapshot({workspacePanelParentKey:t,activeChildSessionKey:n,activeWorkspaceFileKey:null}),this.ensureWorkspaceParentRoute(t)},this.openFilePreview=e=>{let t=this.resolveWorkspaceParentSessionKey(),n=this.buildWorkspaceFileTab(e,t);n&&(Fj.getState().setSnapshot({workspacePanelParentKey:t,workspaceFileTabs:this.upsertWorkspaceFileTab(n),activeWorkspaceFileKey:n.key,activeChildSessionKey:null}),this.ensureWorkspaceParentRoute(t))},this.openSessionFromToolAction=e=>{if(e.kind===`open-session`){if(e.sessionKind===`child`&&!this.isCompactViewport()){let t=e.parentSessionId?.trim()||eM.getState().snapshot.selectedSessionKey||null;if(t){this.openChildSessionPanel({parentSessionKey:t,activeChildSessionKey:e.sessionId});return}}Fj.getState().setSnapshot({workspacePanelParentKey:null,activeChildSessionKey:null,activeWorkspaceFileKey:null}),this.uiManager.goToSession(e.sessionId)}},this.selectChildSessionDetail=e=>{let t=e.trim();if(!t)return;let{childSessionTabs:n}=Fj.getState().snapshot;n.some(e=>e.sessionKey===t)&&Fj.getState().setSnapshot({activeChildSessionKey:t,activeWorkspaceFileKey:null})},this.selectWorkspaceFile=e=>{let t=e.trim();if(!t)return;let{workspaceFileTabs:n}=Fj.getState().snapshot;n.some(e=>e.key===t)&&Fj.getState().setSnapshot({activeWorkspaceFileKey:t,activeChildSessionKey:null})},this.closeWorkspaceFile=e=>{let t=e.trim();if(!t)return;let{snapshot:n}=Fj.getState(),{activeWorkspaceFileKey:r,workspaceFileTabs:i}=n,a={workspaceFileTabs:i.filter(e=>e.key!==t)};r===t&&(a.activeWorkspaceFileKey=null),Fj.getState().setSnapshot(a)},this.closeWorkspacePanel=()=>{Fj.getState().setSnapshot({workspacePanelParentKey:null,activeChildSessionKey:null,activeWorkspaceFileKey:null})},this.closeChildSessionDetail=()=>{this.closeWorkspacePanel()},this.goToParentSession=()=>{let{parentSessionKey:e,childSessionTabs:t,activeChildSessionKey:n}=Fj.getState().snapshot,r=t.find(e=>e.sessionKey===n)?.parentSessionKey??null,i=e??r;i&&(this.closeWorkspacePanel(),this.uiManager.goToSession(i))},this.isCompactViewport=()=>dt.getSnapshot().mode===`mobile`,this.deleteCurrentSession=async()=>{let{snapshot:{selectedSessionKey:e}}=eM.getState();if(e&&await this.uiManager.confirm({title:o(`chatDeleteSessionConfirm`),variant:`destructive`,confirmLabel:o(`delete`)})){Fj.getState().setSnapshot({isDeletePending:!0});try{await T(e),ne(_,e),_.removeQueries({queryKey:[`ncp-session-messages`,e]}),this.streamActionsManager.resetStreamState(),this.clearDeletedSessionState(e),this.uiManager.goToChatRoot({replace:!0})}finally{Fj.getState().setSnapshot({isDeletePending:!1})}}}}},IN=class{constructor(){this.chatUiManager=new PN,this.chatStreamActionsManager=new DN,this.chatSessionListManager=new wN(this.chatUiManager,this.chatStreamActionsManager),this.chatInputManager=new CN(this.chatUiManager,this.chatStreamActionsManager,this.chatSessionListManager),this.chatThreadManager=new FN(this.chatUiManager,this.chatSessionListManager,this.chatStreamActionsManager)}};function LN(e){return e?.trim().toLowerCase()||`native`}function RN(e,t){if(typeof t!=`string`)return!1;let n=t.trim();return n?e.some(e=>e.value===n):!1}function zN(e,t){return typeof t==`string`&&e.includes(t)}function BN(e){return e.length===0?null:e.includes(`off`)?`off`:e[0]??null}function VN(e){let{currentValue:t,selectedSessionPreferredValue:n,fallbackPreferredValue:r,defaultValue:i,isValueSupported:a,firstAvailableValue:o,preferSessionPreferredValue:s=!1,preserveCurrentValueOnSessionChange:c=!1}=e;return a(t)&&(!s||c)?t:a(n)?n:a(r)?r:a(i)?i:o}function HN(e){let{modelOptions:t,currentSelectedModel:n,selectedSessionPreferredModel:r,fallbackPreferredModel:i,defaultModel:a,preferSessionPreferredModel:o,preserveCurrentSelectedModelOnSessionChange:s}=e;return t.length===0?``:VN({currentValue:n,selectedSessionPreferredValue:r,fallbackPreferredValue:i,defaultValue:a,isValueSupported:e=>RN(t,e),firstAvailableValue:t[0]?.value??``,preferSessionPreferredValue:o,preserveCurrentValueOnSessionChange:s})}function UN(e){let{supportedThinkingLevels:t,currentSelectedThinkingLevel:n,selectedSessionPreferredThinking:r,fallbackPreferredThinking:i,defaultThinkingLevel:a,preferSessionPreferredThinking:o,preserveCurrentSelectedThinkingOnSessionChange:s}=e;return t.length===0?null:VN({currentValue:n,selectedSessionPreferredValue:r,fallbackPreferredValue:i,defaultValue:a,isValueSupported:e=>zN(t,e),firstAvailableValue:BN(t)??`off`,preferSessionPreferredValue:o,preserveCurrentValueOnSessionChange:s})}function WN(e){let{sessions:t,selectedSessionKey:n,sessionType:r,readPreference:i}=e,a=LN(r),o,s=-1/0;for(let e of t){if(e.key===n||LN(e.sessionType)!==a)continue;let t=i(e);if(t==null)continue;let r=Date.parse(e.updatedAt),c=Number.isFinite(r)?r:-1/0;(o===void 0||c>s)&&(o=t,s=c)}return o}function GN(e){let{sessions:t,selectedSessionKey:n,sessionType:r}=e;return WN({sessions:t,selectedSessionKey:n,sessionType:r,readPreference:e=>e.preferredModel?.trim()||void 0})}function KN(e){let{sessions:t,selectedSessionKey:n,sessionType:r}=e;return WN({sessions:t,selectedSessionKey:n,sessionType:r,readPreference:e=>e.preferredThinking??void 0})}function qN(e){let{isPreferenceAvailable:t,emptyValue:n,selectedSessionKey:r,selectedSessionExists:i=!1,setValue:a,resolveValue:o}=e,s=(0,P.useRef)(void 0),c=(0,P.useRef)(o);(0,P.useEffect)(()=>{c.current=o},[o]),(0,P.useEffect)(()=>{let e=s.current!==r;if(!t){a(n),s.current=r;return}a(t=>c.current({currentValue:t,sessionChanged:e,preserveCurrentValueOnSessionChange:e&&!!r&&!i})),s.current=r},[n,t,i,r,a])}function JN(e){let{modelOptions:t,selectedSessionKey:n,selectedSessionExists:r=!1,selectedSessionPreferredModel:i,fallbackPreferredModel:a,defaultModel:o,setSelectedModel:s}=e;qN({isPreferenceAvailable:t.length>0,emptyValue:``,selectedSessionKey:n,selectedSessionExists:r,setValue:s,resolveValue:({currentValue:e,sessionChanged:n,preserveCurrentValueOnSessionChange:r})=>HN({currentSelectedModel:e,modelOptions:t,selectedSessionPreferredModel:i,fallbackPreferredModel:a,defaultModel:o,preferSessionPreferredModel:n,preserveCurrentSelectedModelOnSessionChange:r})})}function YN(e){let{supportedThinkingLevels:t,selectedSessionKey:n,selectedSessionExists:r=!1,selectedSessionPreferredThinking:i,fallbackPreferredThinking:a,defaultThinkingLevel:o,setSelectedThinkingLevel:s}=e;qN({isPreferenceAvailable:t.length>0,emptyValue:null,selectedSessionKey:n,selectedSessionExists:r,setValue:s,resolveValue:({currentValue:e,sessionChanged:n,preserveCurrentValueOnSessionChange:r})=>UN({currentSelectedThinkingLevel:e,supportedThinkingLevels:t,selectedSessionPreferredThinking:i,fallbackPreferredThinking:a,defaultThinkingLevel:o,preferSessionPreferredThinking:n,preserveCurrentSelectedThinkingOnSessionChange:r})})}export{Q as A,cj as C,kA as D,AA as E,dn as F,sn as I,nn as L,jD as M,Nn as N,NO as O,Mn as P,lj as S,rj as T,Aj as _,IN as a,oj as b,rN as c,eM as d,Kj as f,kj as g,Mj as h,YN as i,YD as j,RO as k,sN as l,Vj as m,KN as n,jN as o,Jj as p,JN as r,yN as s,GN as t,hM as u,jj as v,ij as w,sj as x,Nj as y};
|
|
59
|
+
`):void 0}function hA(e){let{invocation:t,texts:n}=e,{toolName:r,toolCallId:i,args:a,result:o}=t;if(r!==`spawn`&&r!==`sessions_request`&&r!==`sessions_spawn`)return null;let s=sA(o);if(s){let e=oA(s.status)?.toLowerCase(),t=dA(s,a),o=pA(s),c=oA(s.sessionId),l=ck({args:a,result:s}),u=c?{kind:`open-session`,sessionId:c,sessionKind:s.isChildSession===!0?`child`:`session`,...l?{agentId:l}:{},...oA(s.title)?{label:s.title.trim()}:{},...oA(s.parentSessionId)?{parentSessionId:s.parentSessionId.trim()}:{}}:void 0;return e===`failed`?{kind:`result`,name:r,detail:t,input:uA(a),text:o,callId:i||void 0,hasResult:!!o,statusTone:`error`,statusLabel:n.toolStatusFailedLabel,...l?{agentId:l}:{},...u?{action:u}:{}}:e===`completed`?{kind:`result`,name:r,detail:t,input:uA(a),text:o,callId:i||void 0,hasResult:!!o,statusTone:`success`,statusLabel:n.toolStatusCompletedLabel,...l?{agentId:l}:{},...u?{action:u}:{}}:{kind:`result`,name:r,detail:t,input:uA(a),text:o,callId:i||void 0,hasResult:!!o,statusTone:`running`,statusLabel:n.toolStatusRunningLabel,...l?{agentId:l}:{},...u?{action:u}:{}}}let c=cA(o);if(!c)return null;let l=fA(c,a),u=mA(c),d=oA(c.sessionId),f=ck({args:a,result:c}),p=d?{kind:`open-session`,sessionId:d,sessionKind:c.isChildSession===!0?`child`:`session`,...f?{agentId:f}:{},...oA(c.title)?{label:c.title.trim()}:{},...oA(c.parentSessionId)?{parentSessionId:c.parentSessionId.trim()}:{}}:void 0;return{kind:`result`,name:r,detail:l,input:uA(a),text:u,callId:i||void 0,hasResult:!!u,statusTone:`success`,statusLabel:n.toolStatusCompletedLabel,...f?{agentId:f}:{},...p?{action:p}:{}}}function gA(e,t){let n=JO(e.reasoning);return n?{type:`reasoning`,text:n,label:t.reasoningLabel}:null}function _A(e,t){let n=e.mimeType.startsWith(`image/`),r=ZO(e.sizeBytes);return{type:`file`,file:{label:typeof e.name==`string`&&e.name.trim()?e.name.trim():n?t.imageAttachmentLabel:t.fileAttachmentLabel,mimeType:e.mimeType,dataUrl:typeof e.url==`string`&&e.url.trim().length>0?e.url.trim():`data:${e.mimeType};base64,${e.data}`,...r==null?{}:{sizeBytes:r},isImage:n}}}function vA(e,t){let n=e.toolInvocation,r=$O(n.result,t);if(r)return r;let i=hA({invocation:n,texts:{toolStatusRunningLabel:t.toolStatusRunningLabel,toolStatusCompletedLabel:t.toolStatusCompletedLabel,toolStatusFailedLabel:t.toolStatusFailedLabel}});if(i)return{type:`tool-card`,card:ek(i,t)};let a=tk({status:n.status,error:n.error,cancelled:n.cancelled,result:n.result,texts:t}),o=iA({toolName:n.toolName,status:n.status,toolCallId:n.toolCallId,args:n.args,parsedArgs:n.parsedArgs,result:n.result}),s=o?.summary??PO(n.parsedArgs??n.args),c=o?void 0:rk(n.args,n.parsedArgs),l=typeof n.error==`string`&&n.error.trim()?n.error.trim():n.result==null?``:MO(n.result).trim(),u=!n.error&&QO(n.result),d=(!o?.fileOperation||!!n.error)&&!u,f=ck(n);return{type:`tool-card`,card:ek({kind:a.kind,name:n.toolName,...f?{agentId:f}:{},detail:s,...c?{input:c}:{},text:d&&l?l:void 0,outputData:n.result,callId:n.toolCallId||void 0,hasResult:a.hasResult,statusTone:a.statusTone,statusLabel:a.statusLabel,...o?.fileOperation?{fileOperation:o.fileOperation}:{}},t)}}function yA(e,t){return{type:`unknown`,label:t.unknownPartLabel,rawType:typeof e.type==`string`?e.type:`unknown`,text:MO(e)}}function bA(e){return e.type===`text`&&typeof e.text==`string`}function xA(e){return e.type===`reasoning`&&typeof e.reasoning==`string`}function SA(e){return e.type===`file`&&typeof e.mimeType==`string`&&typeof e.data==`string`}function CA(e){return e.type!==`tool-invocation`||typeof e.toolInvocation!=`object`||e.toolInvocation===null||Array.isArray(e.toolInvocation)?!1:`toolName`in e.toolInvocation&&typeof e.toolInvocation.toolName==`string`}function wA(e){return bA(e.part)?qO(e.part,e.inlineTokens):xA(e.part)?gA(e.part,e.texts):SA(e.part)?_A(e.part,e.texts):CA(e.part)?vA(e.part,e.texts):yA(e.part,e.texts)}function TA(e){let t=e.meta?.timestamp;return t&&Number.isFinite(Date.parse(t))?t:new Date().toISOString()}function EA(e,t){return e===`user`?t.user:e===`assistant`?t.assistant:e===`tool`?t.tool:e===`system`?t.system:t.fallback}function DA(e){return e===`user`||e===`assistant`||e===`tool`||e===`system`?e:`message`}function OA(e,t){return{id:e.id,role:DA(e.role),roleLabel:EA(e.role,t.texts.roleLabels),timestampLabel:t.formatTimestamp(TA(e)),status:e.meta?.status,parts:e.parts.map(n=>wA({part:n,inlineTokens:e.meta?.inlineTokens??[],texts:t.texts})).filter(e=>e!==null)}}var kA=function(e){return e.CALL=`call`,e.RESULT=`result`,e.PARTIAL_CALL=`partial-call`,e.ERROR=`error`,e.CANCELLED=`cancelled`,e}({});function AA(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function jA(e){return AA(e)}function MA(e){let t=AA(e);if(!t)return null;let n=t.replace(/[\\/]+$/,``);if(!n)return t;let r=n.split(/[\\/]/).filter(Boolean);return r[r.length-1]??n}function NA(e){return/^[A-Za-z]:[\\/]?$/.test(e)||e===`/`?e:e.replace(/[\\/]+$/,``)}function PA(e){let t=NA(e.trim().replace(/\\/g,`/`));return/^[A-Za-z]:/.test(t)?`${t.slice(0,1).toLowerCase()}${t.slice(1)}`:t}function FA(e){let t=e.trim().replace(/\\/g,`/`);return t?/^[A-Za-z]:\//.test(t)?{prefix:t.slice(0,2),segments:t.slice(3).split(`/`).filter(Boolean)}:t.startsWith(`/`)?{prefix:`/`,segments:t.slice(1).split(`/`).filter(Boolean)}:{prefix:null,segments:t.split(`/`).filter(Boolean)}:{prefix:null,segments:[]}}function IA(e){let t=PA(e.path),n=PA(e.sessionProjectRoot);if(!t||!n)return null;if(!t.startsWith(`/`)&&!/^[A-Za-z]:\//.test(t))return t.split(`/`).filter(Boolean);if(t===n)return[];let r=n.endsWith(`/`)?n:`${n}/`;return t.startsWith(r)?t.slice(r.length).split(`/`).filter(Boolean):null}function LA(e){let{labels:t,leading:n=null}=e,r=t.map((e,n)=>({key:`${n}:${e}`,label:e,kind:n===t.length-1?`file`:`directory`,isCurrent:n===t.length-1}));return n?[n,...r]:r}function RA(e){let{column:t,line:n}=e;return typeof n==`number`?`L${n}${typeof t==`number`?`:${t}`:``}`:null}function zA(e){let{column:t,line:n,path:r,sessionProjectRoot:i,truncated:a}=e,o=r.trim(),s=i?.trim()&&o?IA({path:o,sessionProjectRoot:i}):null,c;if(i?.trim()&&s){let e=MA(i)??i.trim();c=LA({labels:s,leading:{key:`workspace:${e}`,label:e,kind:`workspace`,isCurrent:s.length===0}})}else{let{prefix:e,segments:t}=FA(o);c=LA({labels:t,leading:e?{key:`root:${e}`,label:e,kind:`root`,isCurrent:t.length===0}:null})}return c.length===0&&(c=[{key:`file:unknown`,label:o||`file`,kind:`file`,isCurrent:!0}]),{fullPath:o,locationLabel:RA({line:n,column:t}),truncated:a,segments:c}}var BA=new Set([`off`,`minimal`,`low`,`medium`,`high`,`adaptive`,`xhigh`]);function VA(e){if(typeof e==`string`)return e;try{return JSON.stringify(e??{})}catch{return String(e??``)}}function HA(e){return`${re}/api/ncp/assets/content?${new URLSearchParams({uri:e}).toString()}`}function UA(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function WA(e){let{metadata:t}=e;return!t||typeof t!=`object`||Array.isArray(t)?null:t}function GA(e){let t=WA(e);return t?UA(t.preferred_model)??UA(t.preferredModel)??UA(t.model):null}function KA(e){let t=WA(e);if(!t)return null;let n=UA(t.preferred_thinking)??UA(t.thinking)??UA(t.thinking_level)??UA(t.thinkingLevel);if(!n)return null;let r=n.toLowerCase();return BA.has(r)?r:null}function qA(e){let t=WA(e);return t?UA(t.label):null}function JA(e){let t=WA(e);return t?jA(t.project_root??t.projectRoot):null}function YA(e){let t=WA(e);return t?UA(t.ui_last_read_at):null}function XA(e){let t=WA(e);return t?UA(t.runtime)??UA(t.session_type)??UA(t.sessionType)??`native`:`native`}function ZA(e){let t=WA(e);return t?UA(t.parent_session_id)??UA(t.parentSessionId):null}function QA(e){let t=WA(e);return t?UA(t.spawned_by_request_id)??UA(t.spawnedByRequestId):null}function $A(e){let t=WA(e);return t?t.child_session_promoted===!0:!1}function ej(e){if(e===`heartbeat`)return{type:`heartbeat`};if(e.startsWith(`cron:`))return{type:`cron`};if(e.startsWith(`agent:`)){let t=e.split(`:`);if(t.length>=3){let e=t[2];if(e&&e!==`main`&&e!==`direct`)return{channel:e}}}return{}}function tj(e){return e.state===`cancelled`?kA.CANCELLED:e.state===`result`?kA.RESULT:e.state===`partial-call`?kA.PARTIAL_CALL:kA.CALL}function nj(e){let t=[];for(let n of e){if(n.type===`text`){t.push({type:`text`,text:n.text});continue}if(n.type===`rich-text`){t.push({type:`text`,text:n.text});continue}if(n.type===`reasoning`){t.push({type:`reasoning`,reasoning:n.text,details:[]});continue}if(n.type===`source`){t.push({type:`source`,source:{sourceType:`url`,id:n.url??n.title??Math.random().toString(36).slice(2,8),url:n.url??``,...n.title?{title:n.title}:{}}});continue}if(n.type===`file`&&n.contentBase64){t.push({type:`file`,...n.name?{name:n.name}:{},mimeType:n.mimeType??`application/octet-stream`,data:n.contentBase64,...n.url?{url:n.url}:{},...typeof n.sizeBytes==`number`?{sizeBytes:n.sizeBytes}:{}});continue}if(n.type===`file`&&n.url){t.push({type:`file`,...n.name?{name:n.name}:{},mimeType:n.mimeType??`application/octet-stream`,data:``,url:n.url,...typeof n.sizeBytes==`number`?{sizeBytes:n.sizeBytes}:{}});continue}if(n.type===`file`&&n.assetUri){t.push({type:`file`,...n.name?{name:n.name}:{},mimeType:n.mimeType??`application/octet-stream`,data:``,url:HA(n.assetUri),...typeof n.sizeBytes==`number`?{sizeBytes:n.sizeBytes}:{}});continue}if(n.type===`step-start`){t.push({type:`step-start`});continue}n.type===`tool-invocation`&&t.push({type:`tool-invocation`,toolInvocation:{status:tj(n),toolCallId:n.toolCallId??`${n.toolName}-${Math.random().toString(36).slice(2,8)}`,toolName:n.toolName,args:VA(n.args),result:n.result}})}return t}function rj(e){return e===`service`?`system`:e===`tool`?`assistant`:e}function ij(e){return{id:e.id,role:rj(e.role),parts:nj(e.parts),meta:{source:`stream`,status:e.status,sessionKey:e.sessionId,timestamp:e.timestamp}}}function aj(e){let t=qA(e),n=GA(e),r=KA(e),i=JA(e),a=YA(e),o=UA(e.lastMessageAt),s=MA(i),c=ej(e.sessionId),l=ZA(e),u=QA(e),d=$A(e);return{key:e.sessionId,createdAt:e.updatedAt,updatedAt:e.updatedAt,...o?{lastMessageAt:o}:{},...a?{readAt:a}:{},...typeof e.agentId==`string`&&e.agentId.trim().length>0?{agentId:e.agentId.trim()}:{},...t?{label:t}:{},...c,...n?{preferredModel:n}:{},...r?{preferredThinking:r}:{},...i?{projectRoot:i}:{},...s?{projectName:s}:{},sessionType:XA(e),sessionTypeMutable:!1,isChildSession:!!l,...d?{isPromotedChildSession:d}:{},...l?{parentSessionId:l}:{},...u?{spawnedByRequestId:u}:{},messageCount:e.messageCount}}function oj(e){return e.map(aj)}function sj(){return`ncp-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function cj(){return g({queryKey:[`agents`],queryFn:A,staleTime:3e4})}function lj(){let e=se();return p({mutationFn:({data:e})=>E(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`agents`]}),e.invalidateQueries({queryKey:[`config`]}),y.success(o(`configSavedApplied`))},onError:e=>{y.error(o(`configSaveFailed`)+`: `+e.message)}})}function uj(){let e=se();return p({mutationFn:({agentId:e,data:t})=>ie(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`agents`]}),e.invalidateQueries({queryKey:[`config`]}),y.success(o(`configSavedApplied`))},onError:e=>{y.error(o(`configSaveFailed`)+`: `+e.message)}})}function dj(){let e=se();return p({mutationFn:({agentId:e})=>x(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`agents`]}),e.invalidateQueries({queryKey:[`config`]}),y.success(o(`configSavedApplied`))},onError:e=>{y.error(o(`configSaveFailed`)+`: `+e.message)}})}function fj(e,t){return new Map([...t,...e].filter(e=>typeof e.id==`string`&&e.id.trim().length>0).map(e=>[e.id,e]))}function pj(e){let t=e?.trim()??``,n=Lj(e=>e.snapshot.availableAgents??[]),r=cj(),i=(0,P.useMemo)(()=>fj(n,r.data?.agents??[]),[r.data?.agents,n]);return(0,P.useMemo)(()=>{if(!t)return null;let e=i.get(t)??null;return{agentId:t,profile:e,displayName:e?.displayName?.trim()||t,avatarUrl:e?.avatarUrl?.trim()||null}},[i,t])}function mj({agentId:e,className:t}){let n=pj(e);return n?(0,N.jsx)(Mn,{agentId:n.agentId,displayName:n.displayName,avatarUrl:n.avatarUrl,className:t}):null}var hj=new WeakMap;function gj(e){return{roleLabels:{user:o(`chatRoleUser`),assistant:o(`chatRoleAssistant`),tool:o(`chatRoleTool`),system:o(`chatRoleSystem`),fallback:o(`chatRoleMessage`)},reasoningLabel:o(`chatReasoning`),toolCallLabel:o(`chatToolCall`),toolResultLabel:o(`chatToolResult`),toolInputLabel:o(`chatToolInput`),toolNoOutputLabel:o(`chatToolNoOutput`),toolOutputLabel:o(`chatToolOutput`),toolStatusPreparingLabel:o(`chatToolStatusPreparing`),toolStatusRunningLabel:o(`chatToolStatusRunning`),toolStatusCompletedLabel:o(`chatToolStatusCompleted`),toolStatusFailedLabel:o(`chatToolStatusFailed`),toolStatusCancelledLabel:o(`chatToolStatusCancelled`),imageAttachmentLabel:o(`chatImageAttachment`),fileAttachmentLabel:o(`chatFileAttachment`),unknownPartLabel:o(`chatUnknownPart`)}}function _j(e){return{copyCodeLabel:o(`chatCodeCopy`),copiedCodeLabel:o(`chatCodeCopied`),copyMessageLabel:o(`chatMessageCopy`),copiedMessageLabel:o(`chatMessageCopied`),typingLabel:o(`chatTyping`),attachmentOpenLabel:o(`chatAttachmentOpen`),attachmentAttachedLabel:o(`chatAttachmentAttached`),attachmentCategoryLabels:{archive:o(`chatAttachmentCategoryArchive`),audio:o(`chatAttachmentCategoryAudio`),code:o(`chatAttachmentCategoryCode`),data:o(`chatAttachmentCategoryData`),document:o(`chatAttachmentCategoryDocument`),generic:o(`chatAttachmentCategoryGeneric`),image:o(`chatAttachmentCategoryImage`),pdf:o(`chatAttachmentCategoryPdf`),sheet:o(`chatAttachmentCategorySheet`),video:o(`chatAttachmentCategoryVideo`)}}}function vj({messages:e,isSending:t,className:n,onToolAction:r,onFileOpen:i}){let{language:a}=ut(),o=(0,P.useMemo)(()=>gj(a),[a]),s=(0,P.useMemo)(()=>e.map(e=>{let t=hj.get(e);if(t&&t.language===a)return t.viewModel;let n=ij(e),r=OA({id:n.id,role:n.role,meta:{timestamp:n.meta?.timestamp,status:n.meta?.status,inlineTokens:VO(e.metadata)},parts:n.parts},{formatTimestamp:e=>c(e,a),texts:o});return hj.set(e,{language:a,viewModel:r}),r}),[a,e,o]);return(0,N.jsx)(QE,{messages:s,isSending:t,hasAssistantDraft:(0,P.useMemo)(()=>s.some(e=>e.role===`assistant`&&(e.status===`streaming`||e.status===`pending`)),[s]),className:n,texts:(0,P.useMemo)(()=>_j(a),[a]),onToolAction:r,onFileOpen:i,renderToolAgent:e=>(0,N.jsx)(mj,{agentId:e,className:`h-4 w-4 shrink-0`})})}function yj(){let e=se();return async t=>{let{sessionKey:n,patch:r,successMessage:i}=t;try{ee(e,await ae(n,r)),await e.invalidateQueries({queryKey:[`ncp-session-skills`,n]}),y.success(i??o(`configSavedApplied`))}catch(e){throw y.error(o(`configSaveFailed`)+`: `+(e instanceof Error?e.message:String(e))),e}}}function bj(){let e=yj();return async t=>{let{persistToServer:n,projectRoot:r,sessionKey:i}=t,a=o(r?`chatSessionProjectUpdated`:`chatSessionProjectCleared`);if(!n){Q.getState().setSnapshot({pendingProjectRoot:r,pendingProjectRootSessionKey:i}),y.success(a);return}await e({sessionKey:i,patch:{projectRoot:r},successMessage:a})}}function xj({icon:e,label:t,onClick:n,disabled:r=!1,destructive:i=!1}){return(0,N.jsxs)(`button`,{type:`button`,className:d(`flex w-full items-center gap-2 rounded-xl px-3 py-2 text-left text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-50`,i?`text-destructive hover:bg-destructive/10`:`text-gray-700 hover:bg-gray-100`),onClick:n,disabled:r,children:[(0,N.jsx)(e,{className:`h-4 w-4 shrink-0`}),(0,N.jsx)(`span`,{children:t})]})}function Sj(e){return g({queryKey:[`server-path-browse`,e.path??null,e.includeFiles??!1],queryFn:()=>te({path:e.path,includeFiles:e.includeFiles}),enabled:e.enabled??!0,staleTime:0})}var Cj=P.forwardRef(({className:e,children:t,...n},r)=>(0,N.jsx)(`div`,{ref:r,className:d(`overflow-auto`,e),...n,children:t}));Cj.displayName=`ScrollArea`;function wj({open:e,currentPath:t,isSaving:n,onOpenChange:r,onConfirm:i,title:a,description:s,pathLabel:c,pathPlaceholder:l,confirmLabel:u,hint:d}){let[p,m]=(0,P.useState)(``),[h,g]=(0,P.useState)(null),[_,y]=(0,P.useState)(``);(0,P.useEffect)(()=>{if(!e)return;let n=t?.trim()||null;m(n??``),g(n),y(``)},[t,e]);let b=Sj({path:h,enabled:e});(0,P.useEffect)(()=>{!e||!b.data||p.trim().length===0&&m(b.data.currentPath)},[b.data,p,e]);let x=p.trim(),S=x.length===0||n,C=(0,P.useMemo)(()=>b.error?b.error instanceof Error?b.error.message:String(b.error):null,[b.error]),w=_.trim().toLowerCase(),T=(0,P.useMemo)(()=>{let e=b.data?.entries??[];return w.length===0?e:e.filter(e=>{let t=e.name.toLowerCase(),n=e.path.toLowerCase();return t.includes(w)||n.includes(w)})},[b.data?.entries,w]),E=e=>{g(e),y(``),e&&m(e)};return(0,N.jsx)(pe,{open:e,onOpenChange:e=>{n||r(e)},children:(0,N.jsxs)(ue,{className:`max-h-[85vh] overflow-hidden sm:h-[42rem] sm:max-w-2xl sm:grid-rows-[auto_minmax(0,1fr)]`,children:[(0,N.jsxs)(ce,{children:[(0,N.jsx)(de,{children:a}),s?(0,N.jsx)(fe,{children:s}):null]}),(0,N.jsxs)(`form`,{className:`flex min-h-0 flex-col gap-4`,onSubmit:e=>{e.preventDefault(),!S&&i(x)},children:[(0,N.jsxs)(`div`,{className:`space-y-2`,children:[(0,N.jsx)(v,{htmlFor:`server-path-picker-input`,children:c}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(O,{id:`server-path-picker-input`,value:p,onChange:e=>m(e.target.value),placeholder:l,autoFocus:!0,disabled:n}),(0,N.jsx)(f,{type:`button`,variant:`outline`,onClick:()=>E(x||null),disabled:n,children:o(`openPath`)})]})]}),(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden rounded-2xl border border-gray-200 bg-gray-50/70`,children:[(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-gray-200 px-3 py-2`,children:[(0,N.jsxs)(f,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>E(b.data?.homePath??null),disabled:n||b.isLoading,children:[(0,N.jsx)(nn,{className:`mr-1 h-4 w-4`}),o(`homeDirectory`)]}),(0,N.jsxs)(f,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>E(b.data?.parentPath??null),disabled:!b.data?.parentPath||n||b.isLoading,children:[(0,N.jsx)(Qt,{className:`mr-1 h-4 w-4`}),o(`parentDirectory`)]}),(0,N.jsxs)(f,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{b.refetch()},disabled:n||b.isLoading,children:[(0,N.jsx)(it,{className:`mr-1 h-4 w-4`}),o(`chatRefresh`)]})]}),(0,N.jsxs)(`div`,{className:`border-b border-gray-200 px-3 py-2`,children:[(0,N.jsx)(`div`,{className:`mb-2 text-xs font-medium text-gray-500`,children:o(`currentDirectory`)}),(0,N.jsx)(`div`,{className:`flex flex-wrap items-center gap-1 text-xs text-gray-600`,children:b.data?.breadcrumbs.map((e,t)=>(0,N.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,N.jsx)(`button`,{type:`button`,className:`rounded px-1.5 py-0.5 hover:bg-gray-200`,onClick:()=>E(e.path),disabled:n,children:e.label}),t<b.data.breadcrumbs.length-1?(0,N.jsx)(It,{className:`h-3 w-3 text-gray-400`}):null]},e.path))})]}),(0,N.jsx)(`div`,{className:`border-b border-gray-200 px-3 py-2`,children:(0,N.jsxs)(`div`,{className:`relative`,children:[(0,N.jsx)(Oe,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,N.jsx)(O,{value:_,onChange:e=>y(e.target.value),placeholder:o(`pathPickerSearchPlaceholder`),disabled:n||b.isLoading,className:`pl-9`})]})}),(0,N.jsx)(Cj,{className:`min-h-0 flex-1 px-2 py-2`,children:b.isLoading?(0,N.jsx)(`div`,{className:`px-2 py-6 text-sm text-gray-500`,children:o(`loading`)}):C?(0,N.jsxs)(`div`,{className:`px-2 py-4 text-sm text-destructive`,children:[o(`pathBrowseFailed`),`: `,C]}):b.data&&T.length>0?(0,N.jsx)(`div`,{className:`space-y-1`,children:T.map(e=>(0,N.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-xl px-3 py-2 text-left text-sm text-gray-700 transition-colors hover:bg-white`,onClick:()=>E(e.path),disabled:n,children:[(0,N.jsx)($e,{className:`h-4 w-4 shrink-0 text-emerald-600`}),(0,N.jsx)(`span`,{className:`truncate`,children:e.name})]},e.path))}):b.data&&b.data.entries.length>0?(0,N.jsx)(`div`,{className:`px-2 py-6 text-sm text-gray-500`,children:o(`pathPickerSearchEmpty`)}):(0,N.jsx)(`div`,{className:`px-2 py-6 text-sm text-gray-500`,children:o(`emptyDirectory`)})})]}),d?(0,N.jsx)(`p`,{className:`text-xs leading-relaxed text-gray-500`,children:d}):null,(0,N.jsxs)(le,{children:[(0,N.jsx)(f,{type:`button`,variant:`outline`,onClick:()=>r(!1),disabled:n,children:o(`cancel`)}),(0,N.jsx)(f,{type:`submit`,disabled:S,children:n?o(`saving`):u})]})]})]})})}function Tj({open:e,currentProjectRoot:t,isSaving:n,onOpenChange:r,onSave:i}){return(0,N.jsx)(wj,{open:e,currentPath:t,isSaving:n,onOpenChange:r,onConfirm:i,title:o(`chatSessionProjectDialogTitle`),description:o(`chatSessionProjectDialogDescription`),pathLabel:o(`chatSessionProjectPathLabel`),pathPlaceholder:o(`chatSessionProjectPathPlaceholder`),confirmLabel:o(`chatSessionSetProject`),hint:o(`chatSessionProjectUpdateHint`)})}function Ej({sessionKey:e,canDeleteSession:t,isDeletePending:n,projectRoot:r,childSessionCount:i=0,onOpenChildSessions:a,onDeleteSession:s}){let c=bj(),[l,u]=(0,P.useState)(!1),[d,p]=(0,P.useState)(!1),[m,h]=(0,P.useState)(!1),g=n||m,_=async n=>{let r=t;h(!0);try{await c({sessionKey:e,projectRoot:n,persistToServer:r}),p(!1),u(!1)}finally{h(!1)}};return(0,N.jsxs)(N.Fragment,{children:[i>0&&a?(0,N.jsx)(f,{type:`button`,variant:`ghost`,size:`icon`,className:`rounded-lg shrink-0 text-gray-400 hover:text-gray-700`,"aria-label":o(`chatSessionOpenChildSessions`),title:o(`chatSessionOpenChildSessions`),onClick:a,disabled:g,children:(0,N.jsx)(en,{className:`h-4 w-4`})}):null,(0,N.jsxs)(xt,{open:l,onOpenChange:u,children:[(0,N.jsx)(yt,{asChild:!0,children:(0,N.jsx)(f,{variant:`ghost`,size:`icon`,className:`rounded-lg shrink-0 text-gray-400 hover:text-gray-700`,"aria-label":o(`chatSessionMoreActions`),disabled:g,children:(0,N.jsx)(zt,{className:`h-4 w-4`})})}),(0,N.jsx)(_t,{align:`end`,className:`w-56 p-2`,children:(0,N.jsxs)(`div`,{className:`space-y-1`,children:[(0,N.jsx)(xj,{icon:Xt,label:o(`chatSessionSetProject`),onClick:()=>{u(!1),p(!0)},disabled:g}),(0,N.jsx)(xj,{icon:st,label:o(`chatDeleteSession`),onClick:()=>{u(!1),s()},disabled:!t||g,destructive:!0})]})})]}),(0,N.jsx)(Tj,{open:d,currentProjectRoot:r,isSaving:m,onOpenChange:p,onSave:_})]})}function Dj({sessionKey:e,projectName:t,projectRoot:n,persistToServer:r}){let i=bj(),[a,s]=(0,P.useState)(!1),[c,l]=(0,P.useState)(!1),[u,d]=(0,P.useState)(!1),f=async t=>{d(!0);try{await i({sessionKey:e,projectRoot:t,persistToServer:r}),l(!1),s(!1)}finally{d(!1)}};return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(xt,{open:a,onOpenChange:s,children:[(0,N.jsx)(yt,{asChild:!0,children:(0,N.jsx)(`button`,{type:`button`,title:n??void 0,className:`min-w-0 max-w-[320px] shrink rounded-full border border-gray-200 bg-gray-100/90 px-2 py-0.5 text-[11px] font-medium text-gray-600 transition-colors hover:border-gray-300 hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-60`,"aria-label":o(`chatSessionSetProject`),disabled:u,children:(0,N.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,N.jsx)(Xt,{className:`h-3.5 w-3.5 shrink-0`}),(0,N.jsx)(`span`,{className:`truncate`,children:t}),(0,N.jsx)(je,{className:`h-3 w-3 shrink-0 opacity-70`})]})})}),(0,N.jsxs)(_t,{align:`start`,className:`w-72 p-2`,children:[(0,N.jsxs)(`div`,{className:`px-3 pb-2 pt-1`,children:[(0,N.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-gray-500`,children:t}),n?(0,N.jsx)(`div`,{className:`mt-1 break-all text-xs text-gray-500`,children:n}):null]}),(0,N.jsxs)(`div`,{className:`space-y-1`,children:[(0,N.jsx)(xj,{icon:sn,label:o(`chatSessionSetProject`),onClick:()=>{s(!1),l(!0)},disabled:u}),(0,N.jsx)(xj,{icon:$t,label:o(`chatSessionClearProject`),onClick:()=>{f(null)},disabled:u})]})]})]}),(0,N.jsx)(Tj,{open:c,currentProjectRoot:n,isSaving:u,onOpenChange:l,onSave:f})]})}function Oj({parentSessionLabel:e,onGoToParentSession:t}){if(!e)return null;let n=e.trim();return(0,N.jsx)(`div`,{className:`border-b border-gray-200/60 bg-white/75 px-4 py-2 backdrop-blur-sm sm:px-5`,children:(0,N.jsxs)(`button`,{type:`button`,onClick:t,className:`inline-flex items-center gap-2 text-xs font-medium text-gray-600 transition-colors hover:text-gray-900`,children:[(0,N.jsx)(De,{className:`h-3.5 w-3.5`}),(0,N.jsxs)(`span`,{children:[o(`chatBackToParent`),n?` · ${n}`:``]})]})})}function kj({snapshot:e,childSessionCount:t,layoutMode:n,normalizedAgentId:r,sessionHeaderTitle:i,shouldShowHeaderAgentAvatar:a,shouldShowSessionHeader:s,onBackToList:c,onOpenChildSessions:l,onDeleteSession:u}){let f=n===`mobile`;return(0,N.jsxs)(`div`,{className:d(`border-b border-gray-200/60 bg-white/80 backdrop-blur-sm flex items-center justify-between shrink-0 overflow-hidden transition-all duration-200`,f?`px-3 sm:px-3`:`px-4 sm:px-5`,s?`opacity-100`:`h-0 py-0 opacity-0 border-b-0`,s&&(f?`pb-2 pt-2`:`py-3`)),style:f&&s?{paddingTop:`calc(env(safe-area-inset-top, 0px) + 0.5rem)`}:void 0,children:[(0,N.jsxs)(`div`,{className:`min-w-0 flex-1 flex items-center gap-2`,children:[f&&c?(0,N.jsx)(`button`,{type:`button`,onClick:c,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full text-gray-600 transition-colors hover:bg-gray-100 hover:text-gray-900`,"aria-label":o(`chat`),children:(0,N.jsx)(De,{className:`h-4 w-4`})}):null,a?(0,N.jsx)(`div`,{className:`inline-flex shrink-0 items-center`,children:(0,N.jsx)(Mn,{agentId:r,displayName:e.agentDisplayName,avatarUrl:e.agentAvatarUrl,className:`h-5 w-5`})}):null,(0,N.jsx)(`span`,{className:`text-sm font-medium text-gray-700 truncate`,children:i}),e.sessionTypeLabel?(0,N.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1.5 rounded-full border border-gray-200 bg-gray-100 px-2 py-0.5 text-[11px] font-medium text-gray-600`,children:[e.sessionTypeIcon?.src?(0,N.jsx)(`span`,{className:`inline-flex h-[1.125rem] w-[1.125rem] items-center justify-center`,children:(0,N.jsx)(Tn,{icon:{kind:`runtime-image`,src:e.sessionTypeIcon.src,alt:e.sessionTypeIcon.alt??null,name:e.sessionTypeLabel}})}):null,e.sessionTypeLabel]}):null,e.sessionProjectName?(0,N.jsx)(Dj,{sessionKey:e.sessionKey??`draft`,projectName:e.sessionProjectName,projectRoot:e.sessionProjectRoot,persistToServer:e.canDeleteSession}):null]}),e.sessionKey?(0,N.jsx)(Ej,{sessionKey:e.sessionKey,canDeleteSession:e.canDeleteSession,isDeletePending:e.isDeletePending,projectRoot:e.sessionProjectRoot,childSessionCount:t,onOpenChildSessions:l,onDeleteSession:u}):null]})}var Aj=`native`;function jj(e){return typeof e==`string`?e.trim().toLowerCase()||`native`:Aj}function Mj(e,t=Aj){return jj(e?.runtime?.trim()||e?.engine?.trim()||t)}function Nj(e,t){return e===`native`?o(`chatSessionTypeNative`):t?.trim()||e.trim().split(/[-_]+/g).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)||e}function Pj(e){let t=new Map;for(let n of e){let e=jj(n.value);t.set(e,{value:e,label:n.label?.trim()||Nj(e),icon:n.icon??null,ready:n.ready??!0,reason:n.reason??null,reasonMessage:n.reasonMessage??null,supportedModels:n.supportedModels,recommendedModel:n.recommendedModel??null,cta:n.cta??null})}return t.has(`native`)||t.set(Aj,{value:Aj,label:Nj(Aj),icon:null,ready:!0,reason:null,reasonMessage:null,supportedModels:void 0,recommendedModel:null,cta:null}),Array.from(t.values()).sort((e,t)=>e.value===`native`?-1:t.value===`native`?1:e.value.localeCompare(t.value))}function Fj(e){let{selectedSession:t,pendingSessionType:n,setPendingSessionType:r,sessionTypesData:i}=e,a=(0,P.useMemo)(()=>Pj(i?.options??[]),[i?.options]),s=(0,P.useMemo)(()=>{let e=[...a],n=jj(t?.sessionType);return e.some(e=>e.value===n)||e.push({value:n,label:Nj(n),icon:null,ready:!0,reason:null,reasonMessage:null,supportedModels:void 0,recommendedModel:null,cta:null}),e.sort((e,t)=>e.value===`native`?-1:t.value===`native`?1:e.value.localeCompare(t.value))},[a,t?.sessionType]),c=(0,P.useMemo)(()=>jj(i?.defaultType??`native`),[i?.defaultType]),l=(0,P.useRef)(null),u=(0,P.useMemo)(()=>jj(t?.sessionType??n??c),[c,n,t?.sessionType]),d=(0,P.useMemo)(()=>s.find(e=>e.value===u)??null,[u,s]);(0,P.useEffect)(()=>{if(t)return;let e=typeof n==`string`?n.trim():``,i=jj(n);(e.length===0||l.current===i||l.current===null&&i===`native`)&&(l.current=c,i!==c&&r(c))},[c,n,t,r]);let f=!t||!!t.sessionTypeMutable,p=(0,P.useMemo)(()=>new Set(a.map(e=>e.value)),[a]);return{sessionTypeOptions:s,selectedSessionTypeOption:d,defaultSessionType:c,selectedSessionType:u,canEditSessionType:f,sessionTypeUnavailable:(0,P.useMemo)(()=>t&&!p.has(jj(t.sessionType))?!0:d?.ready===!1,[p,t,d?.ready]),sessionTypeUnavailableMessage:(0,P.useMemo)(()=>t&&!p.has(jj(t.sessionType))?`${Nj(u)} ${o(`chatSessionTypeUnavailableSuffix`)}`:d?.ready===!1?d.reasonMessage?.trim()||`${d.label} setup required`:null,[p,t,u,d])}}var Ij={isProviderStateResolved:!1,modelOptions:[],sessionTypeUnavailable:!1,sessionTypeUnavailableMessage:null,sessionTypeLabel:null,sessionTypeIcon:null,sessionKey:null,agentId:null,agentDisplayName:null,agentAvatarUrl:null,availableAgents:[],sessionDisplayName:void 0,sessionProjectRoot:null,sessionProjectName:null,canDeleteSession:!1,isDeletePending:!1,threadRef:null,isHistoryLoading:!1,messages:[],isSending:!1,isAwaitingAssistantOutput:!1,parentSessionKey:null,parentSessionLabel:null,workspacePanelParentKey:null,childSessionTabs:[],activeChildSessionKey:null,workspaceFileTabs:[],activeWorkspaceFileKey:null},Lj=C(e=>({snapshot:Ij,setSnapshot:t=>e(e=>({snapshot:{...e.snapshot,...t}}))})),Rj=[{key:`hero`,alignmentClassName:`justify-start`,bubbleClassName:`max-w-[78%] h-32 rounded-[30px]`},{key:`follow-up`,alignmentClassName:`justify-start`,bubbleClassName:`max-w-[62%] h-24 rounded-[28px]`},{key:`reply`,alignmentClassName:`justify-end`,bubbleClassName:`max-w-[70%] h-24 rounded-[28px]`},{key:`detail`,alignmentClassName:`justify-start`,bubbleClassName:`max-w-[88%] h-36 rounded-[30px]`}];function zj(){return(0,N.jsxs)(`section`,{"data-testid":`chat-conversation-skeleton`,className:`flex-1 min-h-0 flex flex-col overflow-hidden bg-gradient-to-b from-gray-50/60 to-white`,children:[(0,N.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar`,children:(0,N.jsx)(`div`,{className:`mx-auto flex min-h-full w-full max-w-[min(1120px,100%)] flex-col px-6 py-5`,children:(0,N.jsxs)(`div`,{className:`flex flex-1 flex-col gap-8`,children:[(0,N.jsxs)(`div`,{className:`space-y-6`,children:[(0,N.jsx)(Mt,{className:`h-6 w-52 rounded-lg bg-gray-200/90`}),(0,N.jsx)(`div`,{className:`space-y-5`,children:Rj.map(e=>(0,N.jsx)(`div`,{className:d(`flex w-full`,e.alignmentClassName),children:(0,N.jsx)(Mt,{"data-testid":`chat-conversation-skeleton-bubble`,className:d(`w-full bg-gray-200/80`,e.bubbleClassName)})},e.key))})]}),(0,N.jsxs)(`div`,{className:`mt-auto grid gap-4 pb-2 sm:grid-cols-[minmax(0,1fr)_minmax(180px,240px)] sm:items-end`,children:[(0,N.jsxs)(`div`,{className:`space-y-3`,children:[(0,N.jsx)(Mt,{className:`h-4 w-40 rounded-full bg-gray-200/70`}),(0,N.jsx)(Mt,{className:`h-[112px] w-full rounded-[30px] bg-gray-200/70`})]}),(0,N.jsx)(`div`,{className:`hidden justify-end sm:flex`,children:(0,N.jsx)(Mt,{className:`h-10 w-36 rounded-full bg-gray-200/75`})})]})]})})}),(0,N.jsx)(`div`,{className:`border-t border-gray-200/80 bg-white p-4`,children:(0,N.jsx)(`div`,{className:`mx-auto w-full max-w-[min(1120px,100%)]`,children:(0,N.jsxs)(`div`,{className:`overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-card`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5`,children:(0,N.jsx)(Mt,{className:`h-[84px] w-full rounded-[28px] bg-gray-200/80`})}),(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 pb-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(Mt,{className:`h-8 w-20 rounded-full bg-gray-200/75`}),(0,N.jsx)(Mt,{className:`h-8 w-28 rounded-full bg-gray-200/75`}),(0,N.jsx)(Mt,{className:`hidden h-8 w-24 rounded-full bg-gray-200/70 sm:block`})]}),(0,N.jsx)(Mt,{className:`h-8 w-8 rounded-full bg-gray-200/85`})]})]})})})]})}function Bj({shouldShowProviderHint:e,sessionTypeUnavailable:t,sessionTypeUnavailableMessage:n,onGoToProviders:r}){return(0,N.jsxs)(N.Fragment,{children:[e?(0,N.jsxs)(`div`,{className:`px-4 py-2.5 border-b border-amber-200/70 bg-amber-50/70 flex items-center justify-between gap-3 shrink-0 sm:px-5`,children:[(0,N.jsx)(`span`,{className:`text-xs text-amber-800`,children:o(`chatModelNoOptions`)}),(0,N.jsx)(`button`,{type:`button`,onClick:r,className:`text-xs font-semibold text-amber-900 underline-offset-2 hover:underline`,children:o(`chatGoConfigureProvider`)})]}):null,t&&n?.trim()?(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-amber-200/70 bg-amber-50/70 shrink-0 sm:px-5`,children:(0,N.jsx)(`span`,{className:`text-xs text-amber-800`,children:n})}):null]})}function Vj({snapshot:e,availableAgents:t,hideEmptyHint:n,showWelcome:r,threadRef:i,onScroll:a,onCreateSession:s,onSelectAgent:c,onToolAction:l,onFileOpen:u}){return(0,N.jsx)(`div`,{ref:i,onScroll:a,className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar`,children:r?(0,N.jsx)(Rn,{onCreateSession:s,agents:t,selectedAgentId:e.agentId??`main`,onSelectAgent:c}):n?null:e.messages.length===0?(0,N.jsx)(`div`,{className:`px-4 py-4 text-sm text-gray-500 sm:px-5 sm:py-5`,children:o(`chatNoMessages`)}):(0,N.jsx)(`div`,{className:`mx-auto w-full max-w-[min(1120px,100%)] px-4 py-4 sm:px-6 sm:py-5`,children:(0,N.jsx)(vj,{messages:e.messages,isSending:e.isSending&&e.isAwaitingAssistantOutput,onToolAction:l,onFileOpen:u},e.sessionKey??`draft`)})})}function Hj(e,t,n){return e.workspacePanelParentKey===e.sessionKey?t.length>0||n.length>0:!1}function Uj({layoutMode:e=`desktop`,onBackToList:t}){let n=QD(),r=Q(e=>e.snapshot.defaultSessionType),i=Lj(e=>e.snapshot),a=(0,P.useRef)(null),s=i.threadRef??a,c=i.childSessionTabs.filter(e=>e.parentSessionKey===i.sessionKey),l=i.workspaceFileTabs.filter(e=>e.parentSessionKey===i.sessionKey),u=Hj(i,c,l),d=!!(i.sessionKey||i.sessionTypeLabel),f=i.sessionDisplayName||(i.canDeleteSession&&i.sessionKey?i.sessionKey:null)||o(`chatSidebarNewTask`),p=i.agentId?.trim()??``,m=p.length>0&&p.toLowerCase()!==`main`,h=!i.canDeleteSession&&i.messages.length===0&&!i.isSending,g=i.modelOptions.length>0,_=i.isProviderStateResolved&&!g,v=i.isHistoryLoading&&i.messages.length===0&&!i.isSending&&!i.isAwaitingAssistantOutput,y=i.availableAgents??[],b=e=>y.find(t=>t.id===e)??null,x=()=>{let t=Mj(b(i.agentId??`main`),r),a=n.chatSessionListManager.createSession(t);e===`mobile`&&n.chatUiManager.goToSession(a)},S=e=>{n.chatSessionListManager.setSelectedAgentId(e),n.chatInputManager.setPendingSessionType(Mj(b(e),r))},C=e=>{n.chatThreadManager.openFilePreview(e)},w=()=>{i.sessionKey&&n.chatThreadManager.openChildSessionPanel({parentSessionKey:i.sessionKey,activeChildSessionKey:c[0]?.sessionKey??null})},{onScroll:T}=WT({scrollRef:s,resetKey:i.sessionKey,isLoading:i.isHistoryLoading,hasContent:i.messages.length>0,contentVersion:i.messages[i.messages.length-1]??null});return i.isProviderStateResolved?(0,N.jsxs)(`section`,{className:`flex-1 min-h-0 flex overflow-hidden bg-gradient-to-b from-gray-50/60 to-white`,children:[(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[(0,N.jsx)(Oj,{parentSessionLabel:i.parentSessionKey?i.parentSessionLabel??null:null,onGoToParentSession:n.chatThreadManager.goToParentSession}),(0,N.jsx)(kj,{snapshot:i,childSessionCount:c.length,layoutMode:e,normalizedAgentId:p,sessionHeaderTitle:f,shouldShowHeaderAgentAvatar:m,shouldShowSessionHeader:d,onBackToList:t,onOpenChildSessions:w,onDeleteSession:n.chatThreadManager.deleteSession}),(0,N.jsx)(Bj,{shouldShowProviderHint:_,sessionTypeUnavailable:i.sessionTypeUnavailable,sessionTypeUnavailableMessage:i.sessionTypeUnavailableMessage??null,onGoToProviders:n.chatThreadManager.goToProviders}),(0,N.jsx)(Vj,{snapshot:i,availableAgents:y,hideEmptyHint:v,showWelcome:h,threadRef:s,onScroll:T,onCreateSession:x,onSelectAgent:S,onToolAction:n.chatThreadManager.openSessionFromToolAction,onFileOpen:C}),(0,N.jsx)(DO,{})]}),u?(0,N.jsx)(bN,{childSessionTabs:c,activeChildSessionKey:i.activeChildSessionKey??null,workspaceFileTabs:l,activeWorkspaceFileKey:i.activeWorkspaceFileKey??null,sessionProjectRoot:i.sessionProjectRoot??null,displayMode:e===`mobile`?`overlay`:`docked`,onSelectSession:n.chatThreadManager.selectChildSessionDetail,onSelectFile:n.chatThreadManager.selectWorkspaceFile,onCloseFile:n.chatThreadManager.closeWorkspaceFile,onClose:n.chatThreadManager.closeWorkspacePanel,onBackToParent:n.chatThreadManager.goToParentSession,onToolAction:n.chatThreadManager.openSessionFromToolAction,onFileOpen:C}):null]}):(0,N.jsx)(zj,{})}var Wj={connected:{dotClass:`bg-emerald-500`},disconnected:{dotClass:`h-2.5 w-2.5 rounded-full border border-gray-400 bg-transparent`},connecting:{dotClass:`text-amber-600`}};function Gj({status:e,className:t}){let n=Wj[e],r=o(e===`connected`?`connected`:e===`disconnected`?`disconnected`:`connecting`);return(0,N.jsx)(kt,{delayDuration:250,children:(0,N.jsxs)(jt,{children:[(0,N.jsx)(Tt,{asChild:!0,children:(0,N.jsx)(`span`,{role:`status`,"aria-label":r,className:d(`inline-flex h-5 w-5 items-center justify-center`,t),children:e===`connecting`?(0,N.jsx)(nt,{className:d(`h-3 w-3 animate-spin`,n.dotClass)}):(0,N.jsx)(`span`,{className:d(e===`connected`?`h-2 w-2 rounded-full`:``,n.dotClass)})})}),(0,N.jsx)(Dt,{side:`bottom`,className:`text-xs`,children:r})]})})}function Kj(){let e=yj();return async t=>{await e({sessionKey:t.sessionKey,patch:{label:t.label},successMessage:o(`configSavedApplied`)})}}function qj(){let e=Kj(),[t,n]=(0,P.useState)(null),[r,i]=(0,P.useState)(``),[a,o]=(0,P.useState)(null),s=e=>{n(e.key),i(e.label?.trim()??``)},c=()=>{n(null),i(``),o(null)};return{editingSessionKey:t,draftLabel:r,savingSessionKey:a,setDraftLabel:i,startEditingSessionLabel:s,cancelEditingSessionLabel:c,saveSessionLabel:async t=>{let n=r.trim();if(n===(t.label?.trim()??``)){c();return}o(t.key);try{await e({sessionKey:t.key,label:n||null}),c()}catch{o(null)}}}}function Jj(e){let t=e.label?.trim();if(t)return t;let n=e.key.split(`:`);return n[n.length-1]||e.key}function Yj(e){return e.trim().toLowerCase()}function Xj(e,t){let n=Yj(t);return n?[e.key,Jj(e),e.projectRoot??``,e.projectName??``].map(Yj).some(e=>e.includes(n)):!0}function Zj(e,t){let n=e?.trim();if(!n)return!1;let r=t?.trim();return r?n.localeCompare(r)>0:!1}function Qj(e){let{active:t,readAt:n,runStatus:r,lastMessageAt:i}=e;return t||r===`running`?!1:Zj(i,n)}var $j={selectedSessionKey:null,draftSessionKey:sj(),selectedAgentId:`main`,query:``,listMode:`time-first`};function eM(e){return t=>e(e=>({snapshot:{...e.snapshot,...t}}))}function tM(e){return(t,n)=>e(e=>{let r=t.trim(),i=n?.trim();if(!r||!i)return e;let a=e.optimisticReadAtBySessionKey[r];return a&&a.localeCompare(i)>=0?e:{...e,optimisticReadAtBySessionKey:{...e.optimisticReadAtBySessionKey,[r]:i}}})}var nM=C(e=>({snapshot:$j,optimisticReadAtBySessionKey:{},setSnapshot:eM(e),markSessionRead:tM(e)}));function rM(e,t){return e.filter(e=>Xj(e,t))}function iM(e){return e.isChildSession?e.isPromotedChildSession===!0:!0}function aM(e={}){let t=nM(e=>e.snapshot.query),n=pt({limit:e.limit??200}),r=(0,P.useMemo)(()=>{let e=n.data?.sessions??[],r=rM(oj(e).filter(iM),t),i=new Map(e.map(e=>[e.sessionId,e]));return r.map(e=>({session:e,runStatus:i.get(e.key)?.status===`running`?`running`:void 0}))},[t,n.data?.sessions]);return{isLoading:n.isLoading,items:r}}function oM(e){let{item:t,selectedSessionKey:n,optimisticReadAtBySessionKey:r,agentsById:i,childSessionsByParentKey:a,editingSessionKey:o,draftLabel:s,savingSessionKey:c,sessionTitle:l,onSelectSession:u,onOpenChildSessions:d,onStartEditingSessionLabel:f,onDraftLabelChange:p,onSaveSessionLabel:m,onCancelEditingSessionLabel:h}=e,{session:g,runStatus:_}=t,v=Q(e=>e.snapshot),y=n===g.key,b=r[g.key],x=b&&g.readAt?b.localeCompare(g.readAt)>0?b:g.readAt:b??g.readAt,S=a.get(g.key)??[];return(0,N.jsx)(In,{session:g,active:y,showUnreadDot:Qj({active:y,lastMessageAt:g.lastMessageAt,readAt:x,runStatus:_}),runStatus:_,context:xn(g,v.sessionTypeOptions),title:l(g),agentId:g.agentId??null,agentLabel:g.agentId?i.get(g.agentId)?.displayName??g.agentId:null,agentAvatarUrl:g.agentId?i.get(g.agentId)?.avatarUrl??null:null,childSessionCount:S.length,isEditing:o===g.key,draftLabel:s,isSaving:c===g.key,onSelect:()=>u(g.key),onOpenChildSessions:()=>d(g.key,S[0]?.session.key??null),onStartEditing:()=>f(g),onDraftLabelChange:p,onSave:()=>m(g),onCancel:h})}function sM(e){let t=e.sessionTypeOptions.find(t=>t.value===e.defaultSessionType);return[...t?[t]:[],...e.nonDefaultSessionTypeOptions]}function cM(e){let{query:t,defaultSessionType:n,nonDefaultSessionTypeOptions:r,isCreateMenuOpen:i,onCreateMenuOpenChange:a,onCreateSession:s,onQueryChange:c}=e;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`div`,{className:`px-4 pb-3`,children:(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsxs)(f,{variant:`primary`,className:d(`min-w-0 rounded-xl`,r.length>0?`flex-1 rounded-r-md`:`w-full`),onClick:()=>{a(!1),s(n)},children:[(0,N.jsx)(rt,{className:`mr-2 h-4 w-4`}),o(`chatSidebarNewTask`)]}),r.length>0?(0,N.jsxs)(xt,{open:i,onOpenChange:a,children:[(0,N.jsx)(yt,{asChild:!0,children:(0,N.jsx)(f,{variant:`primary`,size:`icon`,className:`h-9 w-10 shrink-0 rounded-xl rounded-l-md`,"aria-label":o(`chatSessionTypeLabel`),children:(0,N.jsx)(je,{className:`h-4 w-4`})})}),(0,N.jsxs)(_t,{align:`end`,className:`w-56 rounded-2xl border border-gray-200/80 bg-white p-1.5 shadow-[0_24px_60px_-28px_rgba(15,23,42,0.38)]`,children:[(0,N.jsx)(`div`,{className:`px-3 pb-1 pt-2 text-[10px] font-semibold uppercase tracking-[0.18em] text-gray-400`,children:o(`chatSessionTypeLabel`)}),(0,N.jsx)(`div`,{className:`space-y-1`,children:r.map(e=>(0,N.jsx)(Dn,{option:e,onSelect:()=>{s(e.value),a(!1)}},e.value))})]})]}):null]})}),(0,N.jsx)(`div`,{className:`px-4 pb-3`,children:(0,N.jsxs)(`div`,{className:`relative`,children:[(0,N.jsx)(Oe,{className:`absolute left-3 top-2.5 h-3.5 w-3.5 text-gray-400`}),(0,N.jsx)(O,{value:t,onChange:e=>c(e.target.value),placeholder:o(`chatSidebarSearchPlaceholder`),className:`h-9 rounded-lg pl-8 text-xs`})]})})]})}function lM(e){let{query:t,defaultSessionType:n,sessionTypeOptions:r,nonDefaultSessionTypeOptions:i,isCreateMenuOpen:a,onCreateMenuOpenChange:s,onCreateSession:c,onQueryChange:l}=e,u=sM({defaultSessionType:n,sessionTypeOptions:r,nonDefaultSessionTypeOptions:i}),d=u.length>1;return(0,N.jsx)(`div`,{className:`px-4 pb-2 pt-1`,children:(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,N.jsx)(Oe,{className:`absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,N.jsx)(O,{value:t,onChange:e=>l(e.target.value),placeholder:o(`chatSidebarSearchPlaceholder`),className:`h-9 rounded-full border-transparent bg-gray-100/80 pl-9 pr-3 text-[13px] shadow-none focus:border-gray-200/80 focus:bg-white`})]}),d?(0,N.jsxs)(xt,{open:a,onOpenChange:s,children:[(0,N.jsx)(yt,{asChild:!0,children:(0,N.jsx)(f,{variant:`ghost`,size:`icon`,className:`h-9 w-9 shrink-0 rounded-full bg-gray-100/80 text-gray-700 shadow-none hover:bg-gray-200/80 hover:text-gray-900`,"aria-label":o(`chatSidebarNewTask`),children:(0,N.jsx)(rt,{className:`h-4 w-4`})})}),(0,N.jsxs)(_t,{align:`end`,className:`w-60 rounded-3xl border border-gray-200/80 bg-white p-2 shadow-[0_24px_70px_-30px_rgba(15,23,42,0.45)]`,children:[(0,N.jsx)(`div`,{className:`px-3 pb-1.5 pt-2 text-[11px] font-medium text-gray-400`,children:o(`chatSidebarNewTask`)}),(0,N.jsx)(`div`,{className:`space-y-1`,children:u.map(e=>(0,N.jsx)(Dn,{option:e,onSelect:()=>{c(e.value),s(!1)}},e.value))})]})]}):(0,N.jsx)(f,{variant:`ghost`,size:`icon`,className:`h-9 w-9 shrink-0 rounded-full bg-gray-100/80 text-gray-700 shadow-none hover:bg-gray-200/80 hover:text-gray-900`,"aria-label":o(`chatSidebarNewTask`),onClick:()=>c(n),children:(0,N.jsx)(rt,{className:`h-4 w-4`})})]})})}function uM(e){return new Date(e.session.updatedAt).getTime()}function dM(e){return[...e].sort((e,t)=>uM(t)-uM(e))}function fM(e){let t=new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),r=n-864e5,i=n-7*864e5,a=[],s=[],c=[],l=[];for(let t of e){let{session:e}=t,o=new Date(e.updatedAt).getTime();o>=n?a.push(t):o>=r?s.push(t):o>=i?c.push(t):l.push(t)}let u=[];return a.length>0&&u.push({label:o(`chatSidebarToday`),items:a}),s.length>0&&u.push({label:o(`chatSidebarYesterday`),items:s}),c.length>0&&u.push({label:o(`chatSidebarPrevious7Days`),items:c}),l.length>0&&u.push({label:o(`chatSidebarOlder`),items:l}),u}function pM(e){let t=new Map;for(let n of e){let e=n.session.projectRoot?.trim();if(!e)continue;let r=t.get(e),i=uM(n);if(r){r.items.push(n),r.latestUpdatedAt=Math.max(r.latestUpdatedAt,i);continue}t.set(e,{projectRoot:e,projectName:n.session.projectName?.trim()||MA(e)||e,items:[n],latestUpdatedAt:i})}return[...t.values()].map(e=>({...e,items:dM(e.items)})).sort((e,t)=>t.latestUpdatedAt-e.latestUpdatedAt)}function mM(e){if(e.label&&e.label.trim())return e.label.trim();let t=e.key.split(`:`);return t[t.length-1]||e.key}var hM=[{target:`/cron`,label:()=>o(`chatSidebarScheduledTasks`),icon:me},{target:`/skills`,label:()=>o(`chatSidebarSkills`),icon:Te},{target:`/agents`,label:()=>o(`agentsPageTitle`),icon:Ee}];function gM(e,t,n){let r=nM(e=>e.optimisticReadAtBySessionKey);return(0,P.useEffect)(()=>{(()=>{if(!t)return;let r=e.find(({session:e})=>e.key===t);if(!r)return;let{session:i}=r;n(i.key,i.lastMessageAt,i.readAt)})()},[e,n,t]),r}function _M({variant:e=`desktop`}){let n=e===`mobile`,r=QD(),i=lt(),[a,s]=(0,P.useState)(!1),c=Q(e=>e.snapshot),l=nM(e=>e.snapshot),u=b(),f=cj(),{isLoading:p,items:m}=aM(),{language:h,setLanguage:g}=ut(),{theme:_,setTheme:v}=Se(),y=o(ge.find(e=>e.value===_)?.labelKey??`themeWarm`),x=t.find(e=>e.value===h)?.label??h,S=(0,P.useMemo)(()=>new Map((f.data?.agents??[]).map(e=>[e.id,e])),[f.data?.agents]),C=(0,P.useMemo)(()=>dM(m),[m]),w=(0,P.useMemo)(()=>{let e=new Map;for(let t of m){let n=t.session.parentSessionId?.trim();if(!n)continue;let r=e.get(n)??[];r.push(t),e.set(n,r)}for(let t of e.values())t.sort((e,t)=>uM(t)-uM(e));return e},[m]),T=(0,P.useMemo)(()=>fM(C),[C]),E=(0,P.useMemo)(()=>pM(C),[C]),D=c.defaultSessionType||`native`,O=(0,P.useMemo)(()=>c.sessionTypeOptions.filter(e=>e.value!==D),[D,c.sessionTypeOptions]),ee=l.listMode===`project-first`,k=gM(m,l.selectedSessionKey,r.chatSessionListManager.markSessionRead),{editingSessionKey:te,draftLabel:A,savingSessionKey:ne,setDraftLabel:j,startEditingSessionLabel:re,cancelEditingSessionLabel:ie,saveSessionLabel:ae}=qj(),oe=e=>{h!==e&&(g(e),window.location.reload())},se=e=>(0,N.jsx)(oM,{item:e,selectedSessionKey:l.selectedSessionKey,optimisticReadAtBySessionKey:k,agentsById:S,childSessionsByParentKey:w,editingSessionKey:te,draftLabel:A,savingSessionKey:ne,sessionTitle:mM,onSelectSession:r.chatSessionListManager.selectSession,onOpenChildSessions:(e,t)=>r.chatThreadManager.openChildSessionPanel({parentSessionKey:e,activeChildSessionKey:t}),onStartEditingSessionLabel:re,onDraftLabelChange:j,onSaveSessionLabel:ae,onCancelEditingSessionLabel:ie},e.session.key),ce=(e,t)=>{let i=typeof t==`string`?r.chatSessionListManager.createSession(e,t):r.chatSessionListManager.createSession(e);n&&r.chatUiManager.goToSession(i)};return(0,N.jsxs)(`aside`,{className:d(`flex h-full min-h-0 flex-col bg-secondary`,n?`flex-1 overflow-hidden`:`w-[280px] shrink-0 border-r border-gray-200/60`),children:[n?null:(0,N.jsx)(`div`,{className:`px-5 pt-5 pb-3`,children:(0,N.jsx)(we,{className:`flex items-center gap-2.5 min-w-0`,suffix:(0,N.jsx)(Gj,{status:u.connectionStatus})})}),n?(0,N.jsx)(lM,{query:l.query,defaultSessionType:D,sessionTypeOptions:c.sessionTypeOptions,nonDefaultSessionTypeOptions:O,isCreateMenuOpen:a,onCreateMenuOpenChange:s,onCreateSession:ce,onQueryChange:r.chatSessionListManager.setQuery}):(0,N.jsx)(cM,{query:l.query,defaultSessionType:D,sessionTypeOptions:c.sessionTypeOptions,nonDefaultSessionTypeOptions:O,isCreateMenuOpen:a,onCreateMenuOpenChange:s,onCreateSession:ce,onQueryChange:r.chatSessionListManager.setQuery}),n?null:(0,N.jsx)(`div`,{className:`px-3 pb-2`,children:(0,N.jsx)(`ul`,{className:`space-y-0.5`,children:hM.map(e=>(0,N.jsx)(`li`,{children:(0,N.jsx)(he,{to:e.target,label:e.label(),icon:e.icon,density:`compact`})},e.target))})}),n?null:(0,N.jsx)(`div`,{className:`mx-4 border-t border-gray-200/60`}),(0,N.jsxs)(`div`,{className:`flex items-center justify-between px-5 pb-2 pt-3`,children:[(0,N.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-gray-400`,children:o(`chatSidebarTaskRecords`)}),(0,N.jsx)(fn,{isProjectFirstView:ee,onSelectMode:r.chatSessionListManager.setListMode})]}),(0,N.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar px-3 py-2`,children:p?(0,N.jsx)(`div`,{className:`text-xs text-gray-500 p-3`,children:o(`sessionsLoading`)}):ee?E.length===0?(0,N.jsxs)(`div`,{className:`p-4 text-center`,children:[(0,N.jsx)(rn,{className:`h-6 w-6 mx-auto mb-2 text-gray-300`}),(0,N.jsx)(`div`,{className:`text-xs text-gray-500`,children:o(`chatSidebarProjectViewEmpty`)})]}):(0,N.jsx)(kn,{groups:E,defaultSessionType:D,sessionTypeOptions:c.sessionTypeOptions,renderSessionItem:se,onCreateSession:ce}):T.length===0?(0,N.jsxs)(`div`,{className:`p-4 text-center`,children:[(0,N.jsx)(rn,{className:`h-6 w-6 mx-auto mb-2 text-gray-300`}),(0,N.jsx)(`div`,{className:`text-xs text-gray-500`,children:o(`sessionsEmpty`)})]}):(0,N.jsx)(`div`,{className:`space-y-3`,children:T.map(e=>(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`px-2 py-1 text-[11px] font-medium text-gray-400 uppercase tracking-wider`,children:e.label}),(0,N.jsx)(`div`,{className:`space-y-0.5`,children:e.items.map(se)})]},e.label))})}),n?null:(0,N.jsxs)(`div`,{className:`px-3 py-3 border-t border-gray-200/60 space-y-0.5`,children:[(0,N.jsx)(he,{to:`/settings`,label:o(`settings`),icon:at,density:`compact`}),(0,N.jsx)(Ce,{onClick:()=>i.open(void 0,{kind:`docs`,newTab:!0,title:`Docs`}),icon:ke,label:o(`docBrowserHelp`),density:`compact`}),(0,N.jsx)(be,{value:_,onValueChange:e=>v(e),icon:xe,label:o(`theme`),valueLabel:y,density:`compact`,children:ge.map(e=>(0,N.jsx)(Ke,{value:e.value,className:`text-xs`,children:o(e.labelKey)},e.value))}),(0,N.jsx)(be,{value:h,onValueChange:e=>oe(e),icon:ve,label:o(`language`),valueLabel:x,density:`compact`,children:t.map(e=>(0,N.jsx)(Ke,{value:e.value,className:`text-xs`,children:e.label},e.value))})]})]})}function vM({tone:e=`neutral`,value:t}){return(0,N.jsx)(`span`,{className:d(`inline-flex h-5 items-center rounded-sm border px-1.5 text-[10px] font-medium leading-none`,e===`warning`?`border-amber-200 bg-amber-50 text-amber-700`:`border-gray-200 bg-gray-50 text-gray-500`),children:t})}function yM({breadcrumb:e}){return(0,N.jsx)(`div`,{"data-testid":`workspace-file-breadcrumbs`,title:e.fullPath,className:`workspace-horizontal-scrollbar overflow-x-auto overflow-y-hidden border-b border-gray-200/80 bg-gray-50/55`,children:(0,N.jsxs)(`div`,{"data-testid":`workspace-file-breadcrumb-scroll`,className:`flex min-w-max items-center gap-2.5 px-3 py-1.5`,children:[(0,N.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 pr-1`,children:e.segments.map((t,n)=>(0,N.jsxs)(P.Fragment,{children:[(0,N.jsxs)(`span`,{className:d(`inline-flex h-5 items-center gap-1 rounded-sm px-1 text-[11px] leading-none`,t.kind===`workspace`?`bg-primary/8 text-primary`:t.isCurrent?`bg-gray-200/70 text-gray-900`:`text-gray-500`),children:[t.kind===`workspace`?(0,N.jsx)(Zt,{className:`h-3 w-3 shrink-0`}):t.isCurrent?(0,N.jsx)(Ht,{className:`h-3 w-3 shrink-0`}):null,(0,N.jsx)(`span`,{children:t.label})]}),n<e.segments.length-1?(0,N.jsx)(It,{className:`h-3 w-3 shrink-0 text-gray-300`}):null]},t.key))}),e.locationLabel||e.truncated?(0,N.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-1`,children:[e.locationLabel?(0,N.jsx)(vM,{value:e.locationLabel}):null,e.truncated?(0,N.jsx)(vM,{tone:`warning`,value:o(`chatWorkspacePreviewTruncated`)}):null]}):null]})})}function bM(e){let t=e.path?.trim()??``;return g({queryKey:[`server-path-read`,t,e.basePath??null],queryFn:()=>j({path:t,basePath:e.basePath}),enabled:(e.enabled??!0)&&t.length>0,staleTime:0})}function xM(e){return e.serverKind?e.serverKind:/\.mdx?$/i.test(e.path)?`markdown`:`text`}function SM(e){let{line:t,path:n,text:r}=e,i=t??1;return{key:`preview:${n}`,path:n,display:`preview`,lines:hk({text:r,kind:`context`,oldStartLine:i,newStartLine:i}),rawText:r,oldStartLine:i,newStartLine:i}}function CM(e){if(Array.isArray(e.fullLines)&&e.fullLines.length>0)return{key:`diff:${e.key}`,path:e.path,display:`diff`,lines:e.fullLines,fullLines:e.fullLines,...e.beforeText?{beforeText:e.beforeText}:{},...e.afterText?{afterText:e.afterText}:{},...e.patchText?{patchText:e.patchText}:{},...typeof e.oldStartLine==`number`?{oldStartLine:e.oldStartLine}:{},...typeof e.newStartLine==`number`?{newStartLine:e.newStartLine}:{}};if(e.beforeText==null&&e.afterText==null)return null;let t=yk({beforeText:e.beforeText??``,afterText:e.afterText??``,oldStartLine:e.oldStartLine??void 0,newStartLine:e.newStartLine??void 0});return{key:`diff:${e.key}`,path:e.path,display:`diff`,lines:t,fullLines:t,...e.beforeText?{beforeText:e.beforeText}:{},...e.afterText?{afterText:e.afterText}:{},...typeof e.oldStartLine==`number`?{oldStartLine:e.oldStartLine}:{},...typeof e.newStartLine==`number`?{newStartLine:e.newStartLine}:{}}}function wM({text:e,tone:t=`muted`}){return(0,N.jsx)(`div`,{className:d(`flex h-full items-center justify-center px-6 text-center text-sm`,t===`error`?`text-rose-600`:`text-gray-500`),children:e})}function TM({diffBlock:e}){return e?(0,N.jsx)(EM,{block:e}):(0,N.jsx)(wM,{text:o(`chatWorkspaceDiffEmpty`)})}function EM({block:e}){return(0,N.jsx)(`div`,{className:`h-full overflow-auto custom-scrollbar bg-white`,children:(0,N.jsx)(hE,{block:e,layout:`workspace`})})}function DM({onFileOpen:e,previewBlock:t,previewKind:n,previewQuery:r,previewText:i}){return r.isLoading&&!t?(0,N.jsx)(wM,{text:o(`chatWorkspaceLoadingFile`)}):r.data?.kind===`binary`?(0,N.jsx)(wM,{text:o(`chatWorkspacePreviewUnsupported`)}):r.error&&!t?(0,N.jsx)(wM,{tone:`error`,text:r.error instanceof Error?r.error.message:String(r.error)}):n===`markdown`&&i?(0,N.jsx)(`div`,{className:`h-full overflow-auto custom-scrollbar px-5 py-4`,children:(0,N.jsx)(aT,{text:i,role:`assistant`,texts:{copyCodeLabel:o(`chatCodeCopy`),copiedCodeLabel:o(`chatCodeCopied`)},onFileOpen:e})}):t?(0,N.jsx)(EM,{block:t}):(0,N.jsx)(wM,{text:o(`chatWorkspacePreviewEmpty`)})}function OM({file:e,sessionProjectRoot:t,onFileOpen:n}){let r=e.viewMode===`preview`,i=bM({path:e.path,basePath:t,enabled:r}),a=(0,P.useMemo)(()=>e.viewMode===`diff`?CM(e):null,[e]),o=r?i.data?.text??e.rawText??null:null,s=xM({path:i.data?.resolvedPath??e.path,serverKind:i.data?.kind}),c=(0,P.useMemo)(()=>!r||!o?null:SM({path:i.data?.resolvedPath??e.path,text:o,line:e.line}),[e.line,e.path,r,i.data?.resolvedPath,o]),l=i.data?.resolvedPath??e.path,u=!!i.data?.truncated;return(0,N.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-white`,children:[(0,N.jsx)(yM,{breadcrumb:(0,P.useMemo)(()=>zA({path:l,sessionProjectRoot:t,line:e.line,column:e.column,truncated:u}),[e.column,e.line,u,l,t])}),(0,N.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:e.viewMode===`diff`?(0,N.jsx)(TM,{diffBlock:a}):(0,N.jsx)(DM,{onFileOpen:n,previewBlock:c,previewKind:s,previewQuery:i,previewText:o})})]})}function kM(e,t){return e.label?.trim()?e.label.trim():t?Jj(t):e.sessionKey}function AM(e){let t=pt({limit:200}),n=(0,P.useMemo)(()=>t.data?.sessions??[],[t.data?.sessions]),r=(0,P.useMemo)(()=>{let e=oj(n);return new Map(e.map(e=>[e.key,e]))},[n]),i=(0,P.useMemo)(()=>new Map(n.map(e=>[e.sessionId,e])),[n]);return(0,P.useMemo)(()=>e.map(e=>{let t=r.get(e.sessionKey)??null,n=i.get(e.sessionKey)??null,a=e.agentId?.trim()||t?.agentId||null;return{sessionKey:e.sessionKey,parentSessionKey:e.parentSessionKey,title:kM(e,t),agentId:a,updatedAt:t?.updatedAt??null,lastMessageAt:t?.lastMessageAt??null,readAt:t?.readAt??null,runStatus:n?.status===`running`?`running`:void 0,sessionTypeLabel:t?.sessionType?Nj(t.sessionType):null,preferredModel:t?.preferredModel?.trim()||null,projectName:t?.projectName?.trim()||null,projectRoot:t?.projectRoot?.trim()||null}}),[r,i,e])}function jM(e){let t=e.split(/\r?\n/),n=`message`,r=[];for(let e of t){let t=e.trimEnd();if(!(!t||t.startsWith(`:`))){if(t.startsWith(`event:`)){n=t.slice(6).trim()||`message`;continue}t.startsWith(`data:`)&&r.push(t.slice(5).trimStart())}}return r.length===0?null:{event:n,data:r.join(`
|
|
60
|
+
`)}}async function*MM(e){let t=e.getReader(),n=new TextDecoder,r=``;try{for(;;){let{value:e,done:i}=await t.read();if(i)break;r+=n.decode(e,{stream:!0});let{frames:a,rest:o}=NM(r);r=o;for(let e of a)yield e}r+=n.decode();let{frames:e}=NM(r,!0);for(let t of e)yield t}finally{t.releaseLock()}}function NM(e,t=!1){let n=e.split(/\r?\n\r?\n/),r=n.pop()??``,i=[];for(let e of n){let t=jM(e);t&&i.push(t)}if(t&&r.trim()){let e=jM(r);return e&&i.push(e),{frames:i,rest:``}}return{frames:i,rest:r}}var PM=`/ncp/agent`,FM=class extends Error{ncpError;alreadyPublished;constructor(e,t=!1){super(e.message),this.name=`NcpHttpAgentClientError(${e.code})`,this.ncpError=e,this.alreadyPublished=t}};function IM(e){let t=e.trim();if(!t)throw Error(`NcpHttpAgentClient requires a non-empty baseUrl.`);return new URL(t)}function LM(e){if(e)return e;if(typeof globalThis.fetch==`function`)return globalThis.fetch.bind(globalThis);throw Error(`No fetch implementation found. Pass options.fetchImpl explicitly.`)}function RM(e){let t=(e??`/ncp/agent`).trim();if(!t)return PM;let n=t.startsWith(`/`)?t:`/${t}`;return n.endsWith(`/`)?n.slice(0,-1):n}async function zM(e){try{return(await e.text()).trim()}catch{return``}}function BM(e){if(WM(e))return e.ncpError;if(HM(e))return e;let t=e instanceof Error?e.message:String(e??`Unknown error`);return{code:KM(void 0),message:t,...e instanceof Error&&e.stack?{details:{stack:e.stack}}:{}}}function VM(e,t={}){return new FM(e,t.alreadyPublished??!1)}function HM(e){return UM(e)&&typeof e.code==`string`&&typeof e.message==`string`}function UM(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function WM(e){return e instanceof FM}var GM={"config-error":`config-error`,"auth-error":`auth-error`,"runtime-error":`runtime-error`,"timeout-error":`timeout-error`,"abort-error":`abort-error`};function KM(e){if(!e)return`runtime-error`;let t=GM[e];if(t)return t;let n=e.toLowerCase();return n.includes(`timeout`)?`timeout-error`:n.includes(`abort`)||n.includes(`cancel`)?`abort-error`:n.includes(`auth`)?`auth-error`:n.includes(`config`)?`config-error`:`runtime-error`}function qM(e){let t=YM(e);return!t||typeof t.type!=`string`||!t.type.trim()?null:t}function JM(e){let t=YM(e);if(!t)return{code:`runtime-error`,message:e||`Unknown stream error.`};let n=typeof t.code==`string`?t.code:void 0,r=KM(n),i=UM(t.details)?t.details:{};return n&&n!==r&&(i.originalCode=n),{code:r,message:typeof t.message==`string`&&t.message?t.message:`Unknown stream error.`,...Object.keys(i).length>0?{details:i}:{}}}function YM(e){try{let t=JSON.parse(e);return UM(t)?t:null}catch{return null}}var XM=[`text`,`file`,`source`,`step-start`,`reasoning`,`tool-invocation`,`card`,`rich-text`,`action`,`extension`],ZM=class{manifest;baseUrl;basePath;fetchImpl;defaultHeaders;subscribers=new Set;activeControllers=new Set;started=!1;constructor(e){this.baseUrl=IM(e.baseUrl),this.basePath=RM(e.basePath),this.fetchImpl=LM(e.fetchImpl),this.defaultHeaders=e.headers??{},this.manifest={endpointKind:`custom`,endpointId:e.endpointId?.trim()||`ncp-http-agent-client`,version:`0.1.0`,supportsStreaming:!0,supportsAbort:!0,supportsProactiveMessages:!1,supportsLiveSessionStream:!0,supportedPartTypes:XM,expectedLatency:`seconds`,metadata:{transport:`http+sse`,scope:`agent`}}}async start(){this.started||(this.started=!0,this.publish({type:$E.EndpointReady}))}async stop(){if(this.started){this.started=!1;for(let e of this.activeControllers)e.abort();this.activeControllers.clear()}}async emit(e){switch(e.type){case`message.request`:await this.send(e.payload);return;case`message.stream-request`:await this.stream(e.payload);return;case`message.abort`:await this.abort(e.payload);return;default:this.publish(e);return}}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}async send(e){await this.ensureStarted(),await this.jsonRequest({path:`/send`,method:`POST`,body:e})}async stream(e){await this.ensureStarted();let t=new URLSearchParams({sessionId:e.sessionId});await this.streamRequest({path:`/stream?${t.toString()}`,method:`GET`})}async abort(e){await this.ensureStarted();let t=new AbortController;this.activeControllers.add(t);try{let n=await this.fetchImpl(this.resolveUrl(`/abort`),{method:`POST`,headers:{...this.defaultHeaders,"content-type":`application/json`,accept:`application/json`},body:JSON.stringify(e),signal:t.signal});if(!n.ok)throw Error(`Abort request failed with HTTP ${n.status}: ${await zM(n)}`)}catch(e){if(t.signal.aborted)return;let n=BM(e);throw this.publish({type:$E.EndpointError,payload:n}),VM(n)}finally{this.activeControllers.delete(t)}}async ensureStarted(){this.started||await this.start()}publish(e){for(let t of this.subscribers)t(e)}resolveUrl(e){return new URL(`${this.basePath}${e}`,this.baseUrl)}async jsonRequest(e){let t=new AbortController;this.activeControllers.add(t);try{let n=await this.fetchImpl(this.resolveUrl(e.path),{method:e.method,headers:{...this.defaultHeaders,"content-type":`application/json`,accept:`application/json`},body:e.body===void 0?void 0:JSON.stringify(e.body),signal:t.signal});if(!n.ok)throw Error(`NCP request failed with HTTP ${n.status}: ${await zM(n)}`)}catch(e){if(t.signal.aborted)return;if(WM(e))throw e;let n=BM(e);throw this.publish({type:$E.EndpointError,payload:n}),VM(n)}finally{this.activeControllers.delete(t)}}async streamRequest(e){let t=new AbortController;this.activeControllers.add(t);try{let n=await this.fetchImpl(this.resolveUrl(e.path),{method:e.method,headers:{...this.defaultHeaders,accept:`text/event-stream`,...e.body===void 0?{}:{"content-type":`application/json`}},body:e.body===void 0?void 0:JSON.stringify(e.body),signal:t.signal});if(!n.ok)throw Error(`NCP stream request failed with HTTP ${n.status}: ${await zM(n)}`);if(!n.body)throw Error(`NCP stream response has no body.`);for await(let e of MM(n.body)){if(t.signal.aborted)return;this.handleSseFrame(e)}}catch(e){if(t.signal.aborted)return;if(WM(e))throw e;let n=BM(e);throw this.publish({type:$E.EndpointError,payload:n}),VM(n)}finally{this.activeControllers.delete(t)}}handleSseFrame(e){if(e.event===`ncp-event`){let t=qM(e.data);if(!t){this.publish({type:$E.EndpointError,payload:{code:`runtime-error`,message:`Received malformed ncp-event frame.`}});return}this.publish(t);return}if(e.event===`error`){let t=JM(e.data);throw this.publish({type:$E.EndpointError,payload:t}),VM(t,{alreadyPublished:!0})}}};function QM(e){return typeof e==`string`?e:e instanceof URL?e.toString():e.url}function $M(e){if(e instanceof Error){let t=e.name?.trim(),n=e.message?.trim();return t&&n?`${t}: ${n}`:n||t||`Unknown Error`}return String(e??`Unknown error`)}function eN(e,t){let n=Error(e);return t!==void 0&&(n.cause=t),n}function tN(){return async(e,t)=>{try{return await fetch(e,{credentials:`include`,...t})}catch(n){throw oe.reportTransportFailure($M(n)),eN(`NCP fetch failed for ${(t?.method||`GET`).toUpperCase()} ${QM(e)}: ${$M(n)}`,n)}}}var nN=300,rN=`ncp agent unavailable during startup`;function iN(e){return e instanceof Error?e.message.includes(`ncp session not found:`):!1}function aN(e){return e?.trim().toLowerCase().includes(rN)??!1}function oN(){return new ZM({baseUrl:re,basePath:`/api/ncp/agent`,fetchImpl:tN()})}async function sN(e,t,n=nN){t.throwIfAborted();try{let r=await w(e,n);return t.throwIfAborted(),{messages:r.messages,status:r.status??`idle`}}catch(e){if(t.throwIfAborted(),!iN(e))throw e;return{messages:[],status:`idle`}}}function cN(e,t){let n=(0,P.useRef)(null),r=(0,P.useCallback)(e=>{if(!e){n.current=null;return}n.current!==e&&(n.current=e,t())},[t]);(0,P.useEffect)(()=>{r(e)},[e,r])}function lN(e,t={}){let[n]=(0,P.useState)(()=>oN()),r=k(),[i,a]=(0,P.useState)(0),o=t.messageLimit??nN,s=OD({sessionId:e,client:n,loadSeed:(0,P.useCallback)((e,t)=>sN(e,t,o),[i,o])}),c=s.hydrateError?.message??s.snapshot.error?.message??null;return cN(r.phase===`ready`&&aN(c)?`${e}:${r.lastReadyAt??0}`:null,()=>{a(e=>e+1)}),s}function uN(e){return e.label?.trim()||e.path.split(`/`).filter(Boolean).pop()||e.path}function dN(e){let{activeChildSessionKey:t,activeWorkspaceFileKey:n,childSessionTabs:r,workspaceFileTabs:i}=e;if(n){let e=i.find(e=>e.key===n);if(e)return{kind:`file`,file:e}}if(t){let e=r.find(e=>e.sessionKey===t);if(e)return{kind:`child-session`,tab:e}}return r[0]?{kind:`child-session`,tab:r[0]}:i[0]?{kind:`file`,file:i[0]}:null}function fN({agentId:e,kind:t}){return t===`file`?(0,N.jsx)(Ht,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):e?(0,N.jsx)(mj,{agentId:e,className:`h-3.5 w-3.5 shrink-0`}):(0,N.jsx)(rn,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`})}function pN({tab:e}){return(0,N.jsx)(kt,{delayDuration:250,children:(0,N.jsxs)(jt,{children:[(0,N.jsx)(Tt,{asChild:!0,children:(0,N.jsxs)(`div`,{className:d(`group flex max-w-[180px] min-w-0 items-center gap-1.5 border-r border-gray-200/70 border-b-2 px-2.5 py-2 transition-colors`,e.active?`border-b-primary bg-white text-gray-900`:`border-b-transparent bg-gray-50/85 text-gray-500 hover:bg-gray-100`),children:[(0,N.jsxs)(`button`,{type:`button`,onClick:e.onSelect,className:`flex min-w-0 flex-1 items-center gap-1.5 text-left`,children:[(0,N.jsx)(fN,{kind:e.kind,agentId:e.agentId}),(0,N.jsx)(`span`,{className:`min-w-0 truncate text-[12px] font-medium`,children:e.title}),e.kind===`file`&&e.viewMode===`diff`?(0,N.jsx)(`span`,{className:`shrink-0 rounded border border-amber-200 bg-amber-50 px-1 py-0 text-[9px] font-medium uppercase tracking-[0.08em] text-amber-700`,children:o(`chatWorkspaceDiff`)}):null,e.showUnreadDot?(0,N.jsx)(`span`,{"aria-label":o(`chatSessionUnread`),className:`h-2 w-2 shrink-0 rounded-full bg-primary`}):null]}),e.onClose?(0,N.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),e.onClose?.()},className:d(`rounded p-0.5 text-gray-400 transition-colors hover:bg-gray-200 hover:text-gray-700`,e.active?`opacity-100`:`opacity-0 group-hover:opacity-100`),"aria-label":o(`chatWorkspaceCloseFile`),children:(0,N.jsx)(ct,{className:`h-3 w-3`})}):null]})}),(0,N.jsx)(Dt,{side:`bottom`,className:`max-w-[320px] text-xs`,children:e.tooltip})]})})}function mN({tabs:e}){return(0,N.jsx)(`div`,{"data-testid":`workspace-tabs-bar`,className:`workspace-horizontal-scrollbar overflow-x-auto overflow-y-hidden border-b border-gray-200/70 bg-gray-50/85`,children:(0,N.jsx)(`div`,{"data-testid":`workspace-tabs-scroll`,className:`flex min-w-max items-stretch`,children:e.map(e=>(0,N.jsx)(pN,{tab:e},e.key))})})}function hN({sessionKey:e,onToolAction:t,onFileOpen:n}){let r=lN(e),i=r.visibleMessages,a=(0,P.useRef)(null),{onScroll:s}=WT({scrollRef:a,resetKey:e,isLoading:r.isHydrating,hasContent:i.length>0,contentVersion:i[i.length-1]??null,stickyThresholdPx:20});return(0,N.jsx)(`div`,{ref:a,onScroll:s,className:`h-full overflow-y-auto custom-scrollbar`,children:r.isHydrating?(0,N.jsxs)(`div`,{className:`flex h-full items-center justify-center text-sm text-gray-500`,children:[(0,N.jsx)(nt,{className:`mr-2 h-4 w-4 animate-spin`}),o(`chatChildSessionLoading`)]}):r.hydrateError?(0,N.jsx)(`div`,{className:`px-4 py-5 text-sm text-rose-600`,children:r.hydrateError.message}):i.length===0&&!r.isRunning?(0,N.jsx)(`div`,{className:`px-4 py-5 text-sm text-gray-500`,children:o(`chatChildSessionEmpty`)}):(0,N.jsx)(`div`,{className:`px-4 py-5`,children:(0,N.jsx)(vj,{messages:i,isSending:r.isRunning,onToolAction:t,onFileOpen:n})})})}function gN({value:e}){return(0,N.jsx)(`span`,{className:`inline-flex max-w-full items-center rounded border border-gray-200 bg-gray-50 px-2 py-0.5 text-[10px] font-medium text-gray-600`,children:(0,N.jsx)(`span`,{className:`truncate`,children:e})})}function _N({tab:e}){let t=[e.sessionTypeLabel,e.preferredModel,e.projectName].filter(e=>!!e?.trim());return t.length===0&&!e.projectRoot?null:(0,N.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[t.length>0?(0,N.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(e=>(0,N.jsx)(gN,{value:e},e))}):null,e.projectRoot?(0,N.jsx)(`div`,{title:e.projectRoot,className:`truncate rounded border border-gray-200 bg-gray-50 px-2 py-1.5 font-mono text-[11px] text-gray-500`,children:e.projectRoot}):null]})}function vN({tab:e}){return(0,N.jsxs)(`div`,{className:`border-b border-gray-200/70 px-4 py-3`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-sm font-semibold text-gray-900`,children:[e.agentId?(0,N.jsx)(mj,{agentId:e.agentId,className:`h-4 w-4 shrink-0`}):(0,N.jsx)(Yt,{className:`h-4 w-4 shrink-0 text-gray-400`}),(0,N.jsx)(`span`,{className:`truncate`,children:e.title})]}),(0,N.jsx)(_N,{tab:e})]})}function yN(e){let{resolvedChildTabs:t,workspaceFileTabs:n,activeSelection:r,optimisticReadAtBySessionKey:i,onSelectSession:a,onSelectFile:o,onCloseFile:s}=e,c=t.map(e=>{let t=i[e.sessionKey],n=t&&e.readAt?t.localeCompare(e.readAt)>0?t:e.readAt:t??e.readAt;return{key:`child:${e.sessionKey}`,kind:`child-session`,title:e.title,tooltip:e.title,agentId:e.agentId,active:r?.kind===`child-session`&&r.tab.sessionKey===e.sessionKey,showUnreadDot:Qj({active:r?.kind===`child-session`&&r.tab.sessionKey===e.sessionKey,lastMessageAt:e.lastMessageAt,readAt:n,runStatus:e.runStatus}),onSelect:()=>a(e.sessionKey)}}),l=n.map(e=>({key:`file:${e.key}`,kind:`file`,title:uN(e),tooltip:e.path,viewMode:e.viewMode,active:r?.kind===`file`&&r.file.key===e.key,onSelect:()=>o(e.key),onClose:()=>s(e.key)}));return[...c,...l]}function bN({childSessionTabs:e,activeChildSessionKey:t,workspaceFileTabs:n,activeWorkspaceFileKey:r,sessionProjectRoot:i,displayMode:a=`docked`,onSelectSession:s,onSelectFile:c,onCloseFile:l,onClose:u,onBackToParent:f,onToolAction:p,onFileOpen:m}){let h=QD(),g=AM(e),_=nM(e=>e.optimisticReadAtBySessionKey),v=dN({activeChildSessionKey:t,activeWorkspaceFileKey:r,childSessionTabs:g,workspaceFileTabs:n}),y=g.some(e=>!!e.parentSessionKey);(0,P.useEffect)(()=>{if(v?.kind!==`child-session`)return;let e=v.tab.lastMessageAt?.trim()??null;e&&h.chatSessionListManager.markSessionRead(v.tab.sessionKey,e,v.tab.readAt??null)},[v,h]);let b=(0,P.useMemo)(()=>yN({resolvedChildTabs:g,workspaceFileTabs:n,activeSelection:v,optimisticReadAtBySessionKey:_,onSelectSession:s,onSelectFile:c,onCloseFile:l}),[v,l,c,s,_,g,n]);return v?(0,N.jsx)(`aside`,{className:d(a===`overlay`?`fixed inset-0 z-40 flex bg-white`:`hidden shrink-0 border-l border-gray-200/70 bg-white/95 backdrop-blur-sm md:flex md:w-[26rem] lg:w-[30rem] xl:w-[34rem]`),children:(0,N.jsxs)(`div`,{className:`flex h-full min-h-0 w-full flex-col`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-gray-200/70 px-4 py-2.5`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:f,className:d(`inline-flex items-center gap-1 text-xs font-medium text-gray-600 transition-colors hover:text-gray-900`,!y&&`pointer-events-none opacity-0`),children:[(0,N.jsx)(De,{className:`h-3.5 w-3.5`}),(0,N.jsx)(`span`,{children:o(`chatBackToParent`)})]}),(0,N.jsx)(`button`,{type:`button`,onClick:u,className:`rounded-full border border-gray-200/80 p-1.5 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900`,"aria-label":o(`chatWorkspaceClosePanel`),children:(0,N.jsx)(ct,{className:`h-4 w-4`})})]}),(0,N.jsx)(mN,{tabs:b}),(0,N.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col bg-white`,children:v.kind===`child-session`?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(vN,{tab:v.tab}),(0,N.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,N.jsx)(hN,{sessionKey:v.tab.sessionKey,onToolAction:p,onFileOpen:m})})]}):(0,N.jsx)(OM,{file:v.file,sessionProjectRoot:i,onFileOpen:m})})]})}):null}function xN(){return g({queryKey:[`ncp-session-types`],queryFn:h,staleTime:1e4,retry:!1})}function SN(e){let t=e.trim();return t.length>0?t:null}function CN(e){return e??null}var wN=class{constructor(e){this.updateSession=e,this.inFlight=null,this.queued=null,this.syncSelectedSessionPreferences=()=>{let e=Q.getState().snapshot,t=nM.getState().snapshot,n=Lj.getState().snapshot,r=t.selectedSessionKey;!r||!n.canDeleteSession||this.enqueue({sessionKey:r,patch:{preferredModel:SN(e.selectedModel),preferredThinking:CN(e.selectedThinkingLevel)}})},this.enqueue=e=>{this.queued=e,!this.inFlight&&this.startFlush()},this.startFlush=()=>{this.inFlight=this.flush().catch(e=>{console.error(`Failed to sync chat session preferences: ${String(e)}`)}).finally(()=>{this.inFlight=null,this.queued&&this.startFlush()})},this.flush=async()=>{for(;this.queued;){let e=this.queued;this.queued=null,await this.updateSession(e.sessionKey,e.patch)}}}},TN=class{constructor(e,t,n){this.uiManager=e,this.streamActionsManager=t,this.sessionListManager=n,this.sessionPreferenceSync=new wN(ae),this.buildAttachmentSignature=e=>[e.assetUri??``,e.url??``,e.name,e.mimeType,String(e.sizeBytes),e.contentBase64??``].join(`:`),this.hasSnapshotChanges=e=>{let t=Q.getState().snapshot;for(let[n,r]of Object.entries(e))if(!Object.is(t[n],r))return!0;return!1},this.resolveUpdateValue=(e,t)=>typeof t==`function`?t(e):t,this.isSameStringArray=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),this.syncComposerSnapshot=e=>{let t=Q.getState().snapshot.attachments,n=cO(e,t);Q.getState().setSnapshot({composerNodes:e,attachments:n,draft:rO(e),selectedSkills:iO(e)})},this.syncComposerSnapshotWithAttachments=(e,t)=>{Q.getState().setSnapshot({composerNodes:e,attachments:t,draft:rO(e),selectedSkills:iO(e)})},this.dedupeAttachments=e=>{let t=new Set,n=[];for(let r of e){let e=this.buildAttachmentSignature(r);t.has(e)||(t.add(e),n.push(r))}return n},this.syncSnapshot=e=>{if(this.hasSnapshotChanges(e)&&(Q.getState().setSnapshot(e),Object.prototype.hasOwnProperty.call(e,`modelOptions`)||Object.prototype.hasOwnProperty.call(e,`selectedModel`)||Object.prototype.hasOwnProperty.call(e,`selectedThinkingLevel`))){let{selectedModel:e}=Q.getState().snapshot;this.reconcileThinkingForModel(e)}},this.setDraft=e=>{let t=Q.getState().snapshot.draft,n=this.resolveUpdateValue(t,e);n!==t&&this.syncComposerSnapshot(nO(n))},this.setComposerNodes=e=>{let t=Q.getState().snapshot.composerNodes,n=this.resolveUpdateValue(t,e);Object.is(n,t)||this.syncComposerSnapshot(n)},this.addAttachments=e=>{if(e.length===0)return[];let{snapshot:t}=Q.getState(),n=new Set(t.attachments.map(this.buildAttachmentSignature)),r=this.dedupeAttachments([...t.attachments,...e]),i=r.filter(e=>!n.has(this.buildAttachmentSignature(e)));if(i.length===0)return[];let a=sO(t.composerNodes,r);return this.syncComposerSnapshotWithAttachments(a,r),i},this.restoreComposerState=(e,t)=>{let n=this.dedupeAttachments(t),r=sO(e,n);this.syncComposerSnapshotWithAttachments(r,n)},this.setPendingSessionType=e=>{let t=Q.getState().snapshot.pendingSessionType,n=this.resolveUpdateValue(t,e);n!==t&&Q.getState().setSnapshot({pendingSessionType:n})},this.send=async()=>{let e=Q.getState().snapshot,t=nM.getState().snapshot,n=Lj.getState().snapshot,r=e.draft.trim(),{attachments:i}=e,a=lO(e.composerNodes,i);if(vO({snapshot:e,hasSendableDraft:a.some(e=>e.type!==`text`||e.text.trim().length>0),isRuntimeBlocked:oe.isChatInteractionBlocked()}))return;let{selectedSkills:o,composerNodes:s}=e,c=n.sessionKey??t.selectedSessionKey??this.sessionListManager.ensureDraftSession(e.selectedSessionType);this.setComposerNodes(tO()),await this.streamActionsManager.sendMessage({message:r,sessionKey:c,agentId:t.selectedAgentId,sessionType:e.selectedSessionType,model:e.selectedModel||void 0,thinkingLevel:e.selectedThinkingLevel??void 0,stopSupported:!0,requestedSkills:o,attachments:i,parts:a,restoreDraftOnError:!0,composerNodes:s}),this.sessionListManager.promoteRootDraftSessionRoute(c)},this.stop=async()=>{await this.streamActionsManager.stopCurrentRun()},this.goToProviders=()=>{this.uiManager.goToProviders()},this.setSelectedModel=e=>{let t=Q.getState().snapshot.selectedModel,n=this.resolveUpdateValue(t,e);n!==t&&(Q.getState().setSnapshot({selectedModel:n}),this.reconcileThinkingForModel(n))},this.setSelectedThinkingLevel=e=>{let t=Q.getState().snapshot.selectedThinkingLevel,n=this.resolveUpdateValue(t,e);n!==t&&Q.getState().setSnapshot({selectedThinkingLevel:n})},this.selectSessionType=e=>{let t=jj(e);Q.getState().setSnapshot({selectedSessionType:t,pendingSessionType:t})},this.setSelectedSkills=e=>{let{snapshot:t}=Q.getState(),{selectedSkills:n}=t,r=this.resolveUpdateValue(n,e);this.isSameStringArray(r,n)||this.syncComposerSnapshot(oO(t.composerNodes,r,t.skillRecords))},this.selectModel=e=>{this.setSelectedModel(e),fO.remember(e),this.sessionPreferenceSync.syncSelectedSessionPreferences()},this.selectThinkingLevel=e=>{this.setSelectedThinkingLevel(e),this.sessionPreferenceSync.syncSelectedSessionPreferences()},this.rememberSkillSelection=e=>{pO.remember(e)},this.selectSkills=e=>{let t=Q.getState().snapshot.selectedSkills;for(let n of e)t.includes(n)||this.rememberSkillSelection(n);this.setSelectedSkills(e)},this.resolveThinkingForModel=(e,t)=>{let n=e?.thinkingCapability;return!n||n.supported.length===0?null:t===`off`?`off`:t&&n.supported.includes(t)?t:n.default&&n.supported.includes(n.default)?n.default:`off`},this.reconcileThinkingForModel=e=>{let{snapshot:t}=Q.getState(),n=t.modelOptions.find(t=>t.value===e),{selectedThinkingLevel:r}=t,i=this.resolveThinkingForModel(n,r);i!==r&&Q.getState().setSnapshot({selectedThinkingLevel:i})}}},EN=class{constructor(e,t){this.uiManager=e,this.streamActionsManager=t,this.syncDraftThreadState=e=>{Lj.getState().setSnapshot({sessionKey:e,sessionDisplayName:void 0,canDeleteSession:!1,isHistoryLoading:!1,messages:[],isSending:!1,isAwaitingAssistantOutput:!1,parentSessionKey:null,parentSessionLabel:null,workspacePanelParentKey:null,childSessionTabs:[],activeChildSessionKey:null,activeWorkspaceFileKey:null})},this.resolveUpdateValue=(e,t)=>typeof t==`function`?t(e):t,this.shouldPersistReadAt=(e,t,n)=>{let r=nM.getState().optimisticReadAtBySessionKey[e],i=r&&n?r.localeCompare(n)>0?r:n:r??n??void 0;return i?t.localeCompare(i)>0:!0},this.setSelectedAgentId=e=>{let t=nM.getState().snapshot.selectedAgentId,n=this.resolveUpdateValue(t,e);n!==t&&nM.getState().setSnapshot({selectedAgentId:n})},this.setSelectedSessionKey=e=>{let t=nM.getState().snapshot.selectedSessionKey,n=this.resolveUpdateValue(t,e);n!==t&&nM.getState().setSnapshot({selectedSessionKey:n})},this.setListMode=e=>{let t=nM.getState().snapshot.listMode,n=this.resolveUpdateValue(t,e);n!==t&&nM.getState().setSnapshot({listMode:n})},this.markSessionRead=(e,t,n)=>{let r=e?.trim(),i=t?.trim();!r||!i||this.shouldPersistReadAt(r,i,n)&&(nM.getState().markSessionRead(r,i),ae(r,{uiReadAt:i}).catch(()=>void 0))},this.createSession=(e,t)=>{let{snapshot:n}=Q.getState(),{defaultSessionType:r}=n,i=r||`native`,a=typeof e==`string`&&e.trim().length>0?e.trim():i,o=jA(t),s=sj();return this.streamActionsManager.resetStreamState(),nM.getState().setSnapshot({selectedSessionKey:null,draftSessionKey:s}),this.syncDraftThreadState(s),Q.getState().setSnapshot({pendingSessionType:a,pendingProjectRoot:o,pendingProjectRootSessionKey:o?s:null}),this.uiManager.goToChatRoot(),s},this.ensureDraftSession=e=>{let{snapshot:t}=nM.getState();if(t.selectedSessionKey)return t.selectedSessionKey;let n=typeof e==`string`&&e.trim().length>0?e.trim():null;return this.syncDraftThreadState(t.draftSessionKey),n&&Q.getState().setSnapshot({pendingSessionType:n}),t.draftSessionKey},this.promoteRootDraftSessionRoute=e=>{let t=e.trim();if(!t)return;let{snapshot:n}=nM.getState(),{sessionKey:r}=Lj.getState().snapshot;n.selectedSessionKey!==null||n.draftSessionKey!==t||r!==t||!this.uiManager.isAtChatRoot()||this.uiManager.goToSession(t,{replace:!0})},this.selectSession=e=>{Lj.getState().setSnapshot({workspacePanelParentKey:null,activeChildSessionKey:null,activeWorkspaceFileKey:null}),this.uiManager.goToSession(e)},this.setQuery=e=>{let t=nM.getState().snapshot.query,n=this.resolveUpdateValue(t,e);n!==t&&nM.getState().setSnapshot({query:n})}}},DN=async()=>{},ON=()=>{},kN=class{constructor(){this.actions={sendMessage:DN,stopCurrentRun:DN,resumeRun:DN,resetStreamState:ON,applyHistoryMessages:ON},this.bind=e=>{this.actions={...this.actions,...e}},this.sendMessage=e=>this.actions.sendMessage(e),this.stopCurrentRun=()=>this.actions.stopCurrentRun(),this.resumeRun=e=>this.actions.resumeRun(e),this.resetStreamState=()=>this.actions.resetStreamState(),this.applyHistoryMessages=(e,t)=>this.actions.applyHistoryMessages(e,t)}},AN=`sid_`;function jN(e){let t=new TextEncoder().encode(e),n=``;for(let e of t)n+=String.fromCharCode(e);return`${AN}${btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/g,``)}`}function MN(e){if(!e.startsWith(AN))return null;let t=e.slice(4).replace(/-/g,`+`).replace(/_/g,`/`),n=`=`.repeat((4-t.length%4)%4);try{let e=atob(t+n),r=Uint8Array.from(e,e=>e.charCodeAt(0));return new TextDecoder().decode(r)}catch{return null}}function NN(e){if(!e)return null;let t=MN(e);if(t)return t;try{return decodeURIComponent(e)}catch{return e}}function PN(e){return`/chat/${jN(e)}`}var FN=async e=>!1,IN=class{constructor(){this.state={pathname:``},this.actions={navigate:null,confirm:FN},this.syncState=e=>{this.state={...this.state,...e}},this.bindActions=e=>{this.actions={...this.actions,...e}},this.confirm=async e=>this.actions.confirm(e),this.navigateTo=(e,t)=>{this.actions.navigate&&(this.state.pathname===e&&!t?.replace||(this.actions.navigate(e,t),this.state.pathname=e))},this.goToProviders=()=>{this.navigateTo(`/providers`)},this.goToChatRoot=e=>{this.navigateTo(`/chat`,e)},this.isAtChatRoot=()=>this.state.pathname===`/chat`,this.goToSession=(e,t)=>{this.navigateTo(PN(e),t)}}},LN=class{constructor(e,t,n){this.uiManager=e,this.sessionListManager=t,this.streamActionsManager=n,this.hasSnapshotChanges=e=>{let t=Lj.getState().snapshot;for(let[n,r]of Object.entries(e))if(!Object.is(t[n],r))return!0;return!1},this.syncSnapshot=e=>{this.hasSnapshotChanges(e)&&Lj.getState().setSnapshot(e)},this.clearDeletedSessionState=e=>{nM.getState().snapshot.selectedSessionKey===e&&this.sessionListManager.setSelectedSessionKey(null),Lj.getState().setSnapshot({sessionKey:null,sessionTypeLabel:null,agentId:null,agentDisplayName:null,agentAvatarUrl:null,sessionDisplayName:void 0,sessionProjectRoot:null,sessionProjectName:null,canDeleteSession:!1,isHistoryLoading:!1,messages:[],isSending:!1,isAwaitingAssistantOutput:!1,parentSessionKey:null,parentSessionLabel:null,workspacePanelParentKey:null,childSessionTabs:[],activeChildSessionKey:null,workspaceFileTabs:[],activeWorkspaceFileKey:null})},this.resolveWorkspaceParentSessionKey=()=>Lj.getState().snapshot.sessionKey?.trim()||(nM.getState().snapshot.selectedSessionKey??null),this.buildWorkspaceFileTab=(e,t)=>{let n=e.path.trim();if(!n)return null;let r=t?.trim()||null;return{key:`${r??`draft`}::${e.viewMode}::${n}`,parentSessionKey:r,path:n,label:e.label?.trim()||null,viewMode:e.viewMode,line:e.line??null,column:e.column??null,rawText:e.rawText??null,beforeText:e.beforeText??null,afterText:e.afterText??null,patchText:e.patchText??null,oldStartLine:e.oldStartLine??null,newStartLine:e.newStartLine??null,fullLines:e.fullLines}},this.upsertWorkspaceFileTab=e=>{let{workspaceFileTabs:t}=Lj.getState().snapshot,n=t.findIndex(t=>t.key===e.key);if(n===-1)return[e,...t];let r=[...t];return r.splice(n,1),r.unshift({...t[n],...e}),r},this.ensureWorkspaceParentRoute=e=>{if(!e)return;let{snapshot:{selectedSessionKey:t}}=nM.getState();t!==e&&this.uiManager.goToSession(e)},this.deleteSession=()=>{this.deleteCurrentSession()},this.createSession=()=>{this.sessionListManager.createSession()},this.goToProviders=()=>{this.uiManager.goToProviders()},this.openChildSessionPanel=e=>{let t=e.parentSessionKey.trim();if(!t)return;let n=e.activeChildSessionKey?.trim()||null;Lj.getState().setSnapshot({workspacePanelParentKey:t,activeChildSessionKey:n,activeWorkspaceFileKey:null}),this.ensureWorkspaceParentRoute(t)},this.openFilePreview=e=>{let t=this.resolveWorkspaceParentSessionKey(),n=this.buildWorkspaceFileTab(e,t);n&&(Lj.getState().setSnapshot({workspacePanelParentKey:t,workspaceFileTabs:this.upsertWorkspaceFileTab(n),activeWorkspaceFileKey:n.key,activeChildSessionKey:null}),this.ensureWorkspaceParentRoute(t))},this.openSessionFromToolAction=e=>{if(e.kind===`open-session`){if(e.sessionKind===`child`&&!this.isCompactViewport()){let t=e.parentSessionId?.trim()||nM.getState().snapshot.selectedSessionKey||null;if(t){this.openChildSessionPanel({parentSessionKey:t,activeChildSessionKey:e.sessionId});return}}Lj.getState().setSnapshot({workspacePanelParentKey:null,activeChildSessionKey:null,activeWorkspaceFileKey:null}),this.uiManager.goToSession(e.sessionId)}},this.selectChildSessionDetail=e=>{let t=e.trim();if(!t)return;let{childSessionTabs:n}=Lj.getState().snapshot;n.some(e=>e.sessionKey===t)&&Lj.getState().setSnapshot({activeChildSessionKey:t,activeWorkspaceFileKey:null})},this.selectWorkspaceFile=e=>{let t=e.trim();if(!t)return;let{workspaceFileTabs:n}=Lj.getState().snapshot;n.some(e=>e.key===t)&&Lj.getState().setSnapshot({activeWorkspaceFileKey:t,activeChildSessionKey:null})},this.closeWorkspaceFile=e=>{let t=e.trim();if(!t)return;let{snapshot:n}=Lj.getState(),{activeWorkspaceFileKey:r,workspaceFileTabs:i}=n,a={workspaceFileTabs:i.filter(e=>e.key!==t)};r===t&&(a.activeWorkspaceFileKey=null),Lj.getState().setSnapshot(a)},this.closeWorkspacePanel=()=>{Lj.getState().setSnapshot({workspacePanelParentKey:null,activeChildSessionKey:null,activeWorkspaceFileKey:null})},this.closeChildSessionDetail=()=>{this.closeWorkspacePanel()},this.goToParentSession=()=>{let{parentSessionKey:e,childSessionTabs:t,activeChildSessionKey:n}=Lj.getState().snapshot,r=t.find(e=>e.sessionKey===n)?.parentSessionKey??null,i=e??r;i&&(this.closeWorkspacePanel(),this.uiManager.goToSession(i))},this.isCompactViewport=()=>dt.getSnapshot().mode===`mobile`,this.deleteCurrentSession=async()=>{let{snapshot:{selectedSessionKey:e}}=nM.getState();if(e&&await this.uiManager.confirm({title:o(`chatDeleteSessionConfirm`),variant:`destructive`,confirmLabel:o(`delete`)})){Lj.getState().setSnapshot({isDeletePending:!0});try{await T(e),ne(_,e),_.removeQueries({queryKey:[`ncp-session-messages`,e]}),this.streamActionsManager.resetStreamState(),this.clearDeletedSessionState(e),this.uiManager.goToChatRoot({replace:!0})}finally{Lj.getState().setSnapshot({isDeletePending:!1})}}}}},RN=class{constructor(){this.chatUiManager=new IN,this.chatStreamActionsManager=new kN,this.chatSessionListManager=new EN(this.chatUiManager,this.chatStreamActionsManager),this.chatInputManager=new TN(this.chatUiManager,this.chatStreamActionsManager,this.chatSessionListManager),this.chatThreadManager=new LN(this.chatUiManager,this.chatSessionListManager,this.chatStreamActionsManager)}};function zN(e){return e?.trim().toLowerCase()||`native`}function BN(e,t){if(typeof t!=`string`)return!1;let n=t.trim();return n?e.some(e=>e.value===n):!1}function VN(e,t){return typeof t==`string`&&e.includes(t)}function HN(e){return e.length===0?null:e.includes(`off`)?`off`:e[0]??null}function UN(e){let{currentValue:t,selectedSessionPreferredValue:n,fallbackPreferredValue:r,defaultValue:i,isValueSupported:a,firstAvailableValue:o,preferSessionPreferredValue:s=!1,preserveCurrentValueOnSessionChange:c=!1}=e;return a(t)&&(!s||c)?t:a(n)?n:a(r)?r:a(i)?i:o}function WN(e){let{modelOptions:t,currentSelectedModel:n,selectedSessionPreferredModel:r,fallbackPreferredModel:i,defaultModel:a,preferSessionPreferredModel:o,preserveCurrentSelectedModelOnSessionChange:s}=e;return t.length===0?``:UN({currentValue:n,selectedSessionPreferredValue:r,fallbackPreferredValue:i,defaultValue:a,isValueSupported:e=>BN(t,e),firstAvailableValue:t[0]?.value??``,preferSessionPreferredValue:o,preserveCurrentValueOnSessionChange:s})}function GN(e){let{supportedThinkingLevels:t,currentSelectedThinkingLevel:n,selectedSessionPreferredThinking:r,fallbackPreferredThinking:i,defaultThinkingLevel:a,preferSessionPreferredThinking:o,preserveCurrentSelectedThinkingOnSessionChange:s}=e;return t.length===0?null:UN({currentValue:n,selectedSessionPreferredValue:r,fallbackPreferredValue:i,defaultValue:a,isValueSupported:e=>VN(t,e),firstAvailableValue:HN(t)??`off`,preferSessionPreferredValue:o,preserveCurrentValueOnSessionChange:s})}function KN(e){let{sessions:t,selectedSessionKey:n,sessionType:r,readPreference:i}=e,a=zN(r),o,s=-1/0;for(let e of t){if(e.key===n||zN(e.sessionType)!==a)continue;let t=i(e);if(t==null)continue;let r=Date.parse(e.updatedAt),c=Number.isFinite(r)?r:-1/0;(o===void 0||c>s)&&(o=t,s=c)}return o}function qN(e){let{sessions:t,selectedSessionKey:n,sessionType:r}=e;return KN({sessions:t,selectedSessionKey:n,sessionType:r,readPreference:e=>e.preferredModel?.trim()||void 0})}function JN(e){let{sessions:t,selectedSessionKey:n,sessionType:r}=e;return KN({sessions:t,selectedSessionKey:n,sessionType:r,readPreference:e=>e.preferredThinking??void 0})}function YN(e){let{isPreferenceAvailable:t,emptyValue:n,selectedSessionKey:r,selectedSessionExists:i=!1,setValue:a,resolveValue:o}=e,s=(0,P.useRef)(void 0),c=(0,P.useRef)(o);(0,P.useEffect)(()=>{c.current=o},[o]),(0,P.useEffect)(()=>{let e=s.current!==r;if(!t){a(n),s.current=r;return}a(t=>c.current({currentValue:t,sessionChanged:e,preserveCurrentValueOnSessionChange:e&&!!r&&!i})),s.current=r},[n,t,i,r,a])}function XN(e){let{modelOptions:t,selectedSessionKey:n,selectedSessionExists:r=!1,selectedSessionPreferredModel:i,fallbackPreferredModel:a,defaultModel:o,setSelectedModel:s}=e;YN({isPreferenceAvailable:t.length>0,emptyValue:``,selectedSessionKey:n,selectedSessionExists:r,setValue:s,resolveValue:({currentValue:e,sessionChanged:n,preserveCurrentValueOnSessionChange:r})=>WN({currentSelectedModel:e,modelOptions:t,selectedSessionPreferredModel:i,fallbackPreferredModel:a,defaultModel:o,preferSessionPreferredModel:n,preserveCurrentSelectedModelOnSessionChange:r})})}function ZN(e){let{supportedThinkingLevels:t,selectedSessionKey:n,selectedSessionExists:r=!1,selectedSessionPreferredThinking:i,fallbackPreferredThinking:a,defaultThinkingLevel:o,setSelectedThinkingLevel:s}=e;YN({isPreferenceAvailable:t.length>0,emptyValue:null,selectedSessionKey:n,selectedSessionExists:r,setValue:s,resolveValue:({currentValue:e,sessionChanged:n,preserveCurrentValueOnSessionChange:r})=>GN({currentSelectedThinkingLevel:e,supportedThinkingLevels:t,selectedSessionPreferredThinking:i,fallbackPreferredThinking:a,defaultThinkingLevel:o,preferSessionPreferredThinking:n,preserveCurrentSelectedThinkingOnSessionChange:r})})}export{Q as A,uj as C,jA as D,MA as E,dn as F,sn as I,nn as L,ND as M,Nn as N,FO as O,Mn as P,dj as S,aj as T,Mj as _,RN as a,cj as b,aN as c,nM as d,Jj as f,jj as g,Pj as h,ZN as i,ZD as j,BO as k,lN as l,Uj as m,JN as n,NN as o,Xj as p,XN as r,xN as s,qN as t,_M as u,Nj as v,oj as w,lj as x,Fj as y};
|