nextclaw 0.21.5 → 0.21.6
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/package.json +16 -16
- package/ui-dist/assets/{channels-list-page-bkKDqaO5.js → channels-list-page-D-WYFmcG.js} +1 -1
- package/ui-dist/assets/{chat-page-YKdeGoVx.js → chat-page-D1X8YNTC.js} +2 -2
- package/ui-dist/assets/{desktop-update-config-CLXdVz9r.js → desktop-update-config-DOi5R1fX.js} +1 -1
- package/ui-dist/assets/{index-DKflQCOL.js → index-ZDJP_uJc.js} +5 -5
- package/ui-dist/assets/mcp-marketplace-page-LmMhKH5a.js +1 -0
- package/ui-dist/assets/{mcp-marketplace-page-BaBuHB2L.js → mcp-marketplace-page-RqISBSqO.js} +1 -1
- package/ui-dist/assets/{model-config-B-qg70S4.js → model-config-JUsW1Khb.js} +1 -1
- package/ui-dist/assets/{provider-scoped-model-input-BgPTQa8H.js → provider-scoped-model-input-IMD4W0jD.js} +1 -1
- package/ui-dist/assets/{providers-list-cBeeslbc.js → providers-list-BsDpxNzy.js} +1 -1
- package/ui-dist/assets/{runtime-config-page-DYH2ejUI.js → runtime-config-page-DzbTVebD.js} +1 -1
- package/ui-dist/assets/{search-config-BRsrQ4zK.js → search-config-CJ6OPxAf.js} +1 -1
- package/ui-dist/assets/{secrets-config-eYdx5_AW.js → secrets-config-CYOHWL7P.js} +1 -1
- package/ui-dist/index.html +1 -1
- package/ui-dist/assets/mcp-marketplace-page-ooEvG_bB.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/doc-browser-D5FJcAyz.js","assets/doc-browser-DewXa6oX.js","assets/react-BVjl1ZaK.js","assets/dist-CyWdaJvr.js","assets/tooltip-CKGxLGnG.js","assets/dist-DzM2ZEVN.js","assets/arrow-left-Dd45Mvr1.js","assets/external-link-BLjo8z2a.js","assets/plus-DrpyArC8.js","assets/search-CjHGYvTI.js","assets/x-dpDISboO.js","assets/doc-browser-context-CpL2m4Sp.js","assets/model-config-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/doc-browser-D5FJcAyz.js","assets/doc-browser-DewXa6oX.js","assets/react-BVjl1ZaK.js","assets/dist-CyWdaJvr.js","assets/tooltip-CKGxLGnG.js","assets/dist-DzM2ZEVN.js","assets/arrow-left-Dd45Mvr1.js","assets/external-link-BLjo8z2a.js","assets/plus-DrpyArC8.js","assets/search-CjHGYvTI.js","assets/x-dpDISboO.js","assets/doc-browser-context-CpL2m4Sp.js","assets/model-config-JUsW1Khb.js","assets/api-DmxQnm30.js","assets/loader-circle-Dz4FssYC.js","assets/provider-scoped-model-input-IMD4W0jD.js","assets/provider-models-C_yOh6DE.js","assets/config-hints-Ceiol9x4.js","assets/chat-page-D1X8YNTC.js","assets/app-presenter-provider-CDSjiqfE.js","assets/confirm-dialog-BWRNsRgb.js","assets/es2015-WqekV0OK.js","assets/popover-BlJLguiZ.js","assets/key-round-Du8x3sWa.js","assets/refresh-cw-DFR87zei.js","assets/trash-2-yLA8BEcE.js","assets/notice-card-3a7FmAz-.js","assets/status-dot-SVPjIyG5.js","assets/tabs-Czd2mj6z.js","assets/mcp-marketplace-page-RqISBSqO.js","assets/tag-chip-Cdwb3JSH.js","assets/ellipsis-BDgTYNDX.js","assets/play-BziM-Y34.js","assets/tabs-custom-Ix4nkp2h.js","assets/search-config-CJ6OPxAf.js","assets/config-split-page-CdJEkWxv.js","assets/providers-list-BsDpxNzy.js","assets/channels-list-page-D-WYFmcG.js","assets/runtime-config-page-DzbTVebD.js","assets/rotate-cw-DMBnsYKm.js","assets/save-BDmIlHvN.js","assets/desktop-update-config-DOi5R1fX.js","assets/secrets-config-CYOHWL7P.js","assets/remote-DjhVMpVd.js","assets/mcp-marketplace-page-LmMhKH5a.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,s as p,t as m,u as h,v as g,y as _}from"./react-BVjl1ZaK.js";import{A as v,C as y,E as b,F as x,I as S,L as C,M as w,N as T,O as E,P as D,S as O,T as k,a as A,c as ee,i as j,j as te,k as M,l as ne,n as re,o as ie,r as ae,s as oe,t as se,u as ce,x as le,z as ue}from"./app-presenter-provider-CDSjiqfE.js";import{$ as de,At as fe,B as pe,Bt as me,Ct as he,Dt as ge,Et as _e,F as ve,Ft as ye,G as be,H as xe,I as Se,It as Ce,J as we,K as Te,L as Ee,Lt as De,M as Oe,N as ke,Nt as Ae,Ot as je,P as Me,Pt as Ne,Q as Pe,Qt as Fe,R as Ie,Rt as Le,Tt as Re,U as ze,V as Be,Vt as Ve,W as He,X as Ue,Y as We,Z as Ge,Zt as Ke,_ as qe,at as Je,bt as Ye,ct as Xe,d as Ze,dt as Qe,et as $e,f as et,ft as tt,g as nt,gt as rt,h as it,ht as at,kt as ot,lt as st,m as ct,n as lt,ot as ut,p as dt,q as ft,st as pt,t as mt,tt as ht,v as gt,vt as _t,xt as vt,y as yt,yt as bt,z as xt,zt as N}from"./api-DmxQnm30.js";import{_ as St,a as Ct,b as wt,c as P,d as Tt,f as Et,g as Dt,h as Ot,i as kt,l as At,n as jt,o as Mt,p as Nt,r as Pt,s as Ft,u as It,x as Lt,y as Rt}from"./dist-CyWdaJvr.js";import{i as zt,n as Bt,r as Vt,t as Ht}from"./es2015-WqekV0OK.js";import{a as Ut,i as Wt,n as Gt,o as Kt,r as qt,s as Jt,t as Yt}from"./confirm-dialog-BWRNsRgb.js";import{t as Xt}from"./arrow-left-Dd45Mvr1.js";import{n as Zt}from"./doc-browser-DewXa6oX.js";import{n as Qt,t as $t}from"./loader-circle-Dz4FssYC.js";import{a as en,c as tn,i as nn,l as rn,n as an,o as on,r as sn,s as cn,t as ln,u as un}from"./tooltip-CKGxLGnG.js";import{t as dn}from"./external-link-BLjo8z2a.js";import{t as fn}from"./key-round-Du8x3sWa.js";import{t as pn}from"./plus-DrpyArC8.js";import{t as mn}from"./search-CjHGYvTI.js";import{t as hn}from"./trash-2-yLA8BEcE.js";import{t as gn}from"./x-dpDISboO.js";import{a as _n,c as vn,i as yn,n as bn,o as xn,r as Sn,s as Cn,t as wn}from"./popover-BlJLguiZ.js";import{c as Tn,m as En,n as Dn,s as On,t as kn}from"./doc-browser-context-CpL2m4Sp.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var An=e((e=>{var t=o();e.createRoot=t.createRoot,e.hydrateRoot=t.hydrateRoot})),jn=P(`AlarmClock`,[[`circle`,{cx:`12`,cy:`13`,r:`8`,key:`3y4lt7`}],[`path`,{d:`M12 9v4l2 2`,key:`1c63tq`}],[`path`,{d:`M5 3 2 6`,key:`18tl5t`}],[`path`,{d:`m22 6-3-3`,key:`1opdir`}],[`path`,{d:`M6.38 18.7 4 21`,key:`17xu3x`}],[`path`,{d:`M17.64 18.67 20 21`,key:`kv2oe2`}]]),Mn=P(`ArrowUpRight`,[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]),Nn=P(`ArrowUp`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),Pn=P(`Bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),Fn=P(`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`}]]),In=P(`Check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),Ln=P(`ChevronDown`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),Rn=P(`ChevronRight`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),zn=P(`ChevronUp`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),Bn=P(`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`}]]),Vn=P(`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`}]]),Hn=P(`Cpu`,[[`rect`,{width:`16`,height:`16`,x:`4`,y:`4`,rx:`2`,key:`14l7u7`}],[`rect`,{width:`6`,height:`6`,x:`9`,y:`9`,rx:`1`,key:`5aljv4`}],[`path`,{d:`M15 2v2`,key:`13l42r`}],[`path`,{d:`M15 20v2`,key:`15mkzm`}],[`path`,{d:`M2 15h2`,key:`1gxd5l`}],[`path`,{d:`M2 9h2`,key:`1bbxkp`}],[`path`,{d:`M20 15h2`,key:`19e6y8`}],[`path`,{d:`M20 9h2`,key:`19tzq7`}],[`path`,{d:`M9 2v2`,key:`165o2o`}],[`path`,{d:`M9 20v2`,key:`i2bqo8`}]]),Un=P(`Download`,[[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`polyline`,{points:`7 10 12 15 17 10`,key:`2ggqvy`}],[`line`,{x1:`12`,x2:`12`,y1:`15`,y2:`3`,key:`1vk2je`}]]),Wn=P(`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`}]]),Gn=P(`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`}]]),Kn=P(`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`}]]),qn=P(`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`}]]),Jn=P(`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`}]]),Yn=P(`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`}]]),Xn=P(`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`}]]),Zn=P(`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`}]]),Qn=P(`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`}]]),$n=P(`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`}]]),er=P(`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`}]]),tr=P(`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`}]]),nr=P(`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`}]]),rr=P(`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`}]]),ir=P(`Folder`,[[`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`}]]),ar=P(`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`}]]),or=P(`Globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),sr=P(`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`}]]),cr=P(`Languages`,[[`path`,{d:`m5 8 6 6`,key:`1wu5hv`}],[`path`,{d:`m4 14 6-6 2-3`,key:`1k1g8d`}],[`path`,{d:`M2 5h12`,key:`or177f`}],[`path`,{d:`M7 2h1`,key:`1t2jsx`}],[`path`,{d:`m22 22-5-10-5 10`,key:`don7ne`}],[`path`,{d:`M14 18h6`,key:`1m8k6r`}]]),lr=P(`MessageCircle`,[[`path`,{d:`M7.9 20A9 9 0 1 0 4 16.1L2 22Z`,key:`vv11sd`}]]),ur=P(`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`}]]),dr=P(`MessageSquare`,[[`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`}]]),fr=P(`Minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),pr=P(`Palette`,[[`circle`,{cx:`13.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`1okk4w`}],[`circle`,{cx:`17.5`,cy:`10.5`,r:`.5`,fill:`currentColor`,key:`f64h9f`}],[`circle`,{cx:`8.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`fotxhn`}],[`circle`,{cx:`6.5`,cy:`12.5`,r:`.5`,fill:`currentColor`,key:`qy21gx`}],[`path`,{d:`M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z`,key:`12rzf8`}]]),mr=P(`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`}]]),hr=P(`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`}]]),gr=P(`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`}]]),_r=P(`Settings`,[[`path`,{d:`M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z`,key:`1qme2f`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),vr=P(`Shield`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}]]),yr=P(`Smartphone`,[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]),br=P(`Sparkles`,[[`path`,{d:`M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z`,key:`4pj2yx`}],[`path`,{d:`M20 3v4`,key:`1olli1`}],[`path`,{d:`M22 5h-4`,key:`1gvqau`}],[`path`,{d:`M4 17v2`,key:`vumght`}],[`path`,{d:`M5 18H3`,key:`zchphs`}]]),xr=P(`Square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),Sr=P(`Terminal`,[[`polyline`,{points:`4 17 10 11 4 5`,key:`akl6gq`}],[`line`,{x1:`12`,x2:`20`,y1:`19`,y2:`19`,key:`q2wloq`}]]),Cr=P(`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`}]]),wr=P(`Wifi`,[[`path`,{d:`M12 20h.01`,key:`zekei9`}],[`path`,{d:`M2 8.82a15 15 0 0 1 20 0`,key:`dnpr2z`}],[`path`,{d:`M5 12.859a10 10 0 0 1 14 0`,key:`1x1e6c`}],[`path`,{d:`M8.5 16.429a5 5 0 0 1 7 0`,key:`1bycff`}]]),Tr=An(),F=_(a(),1);function Er(){let e=Dn();(0,F.useEffect)(()=>{let t=t=>{let n=t.target.closest(`a[href]`);if(!n)return;let r=n.getAttribute(`href`)||``;En(r)&&(n.hasAttribute(`data-doc-external`)||t.ctrlKey||t.metaKey||t.shiftKey||(t.preventDefault(),t.stopPropagation(),e.open(r)))};return document.addEventListener(`click`,t,!0),()=>document.removeEventListener(`click`,t,!0)},[e])}var I=l(),Dr=(0,F.createContext)(null);function Or({children:e}){let[t,r]=(0,F.useState)(()=>n());(0,F.useEffect)(()=>h(e=>{r(e)}),[]);let i=(0,F.useCallback)(e=>{c(e),r(d())},[]),a=(0,F.useCallback)(()=>{i(t===`en`?`zh`:`en`)},[t,i]),o=(0,F.useMemo)(()=>({language:t,setLanguage:i,toggleLanguage:a}),[t,i,a]);return(0,I.jsx)(Dr.Provider,{value:o,children:e})}function kr(){let e=(0,F.useContext)(Dr);if(!e)throw Error(`useI18n must be used within I18nProvider`);return{...e,t:s}}function Ar(e){return typeof e!=`number`||!Number.isFinite(e)?`desktop`:e<=767?`mobile`:`desktop`}function jr(){let e=typeof window>`u`?null:window.innerWidth??null;return{mode:Ar(e),width:e}}var Mr=m(()=>jr()),Nr=new class{constructor(){this.consumerCount=0,this.started=!1,this.attach=()=>(this.consumerCount+=1,this.consumerCount===1&&this.start(),()=>{this.consumerCount=Math.max(0,this.consumerCount-1),this.consumerCount===0&&this.stop()}),this.start=()=>{this.started||typeof window>`u`||(this.started=!0,window.addEventListener(`resize`,this.handleViewportChange),window.addEventListener(`orientationchange`,this.handleViewportChange),this.syncFromWindow())},this.stop=()=>{!this.started||typeof window>`u`||(window.removeEventListener(`resize`,this.handleViewportChange),window.removeEventListener(`orientationchange`,this.handleViewportChange),this.started=!1)},this.getSnapshot=()=>Mr.getState(),this.resetForTests=()=>{this.consumerCount=0,this.stop(),Mr.setState(jr())},this.handleViewportChange=()=>{this.syncFromWindow()},this.syncFromWindow=()=>{if(typeof window>`u`)return;let e=window.innerWidth??null;Mr.setState({width:e,mode:Ar(e)})}}};function Pr(){return(0,F.useEffect)(()=>Nr.attach(),[]),{isMobile:Mr(e=>e.mode)===`mobile`}}var Fr=m(()=>({supported:!1,initialized:!1,busyAction:null,snapshot:null})),Ir=new class{constructor(){this.start=async()=>{let e=this.getDesktopApi();if(!e){this.markUnsupported();return}Fr.setState({supported:!0,initialized:!1,busyAction:`loading`});try{let t=await e.getPresenceState();Fr.setState({supported:!0,initialized:!0,busyAction:null,snapshot:t})}catch(e){Fr.setState({supported:!0,initialized:!0,busyAction:null}),N.error(`${s(`runtimePresenceLoadFailed`)}: ${this.getErrorMessage(e)}`)}},this.markUnsupported=()=>{Fr.setState({supported:!1,initialized:!0,busyAction:null,snapshot:null})},this.updatePreferences=async e=>{let t=this.getDesktopApi();if(!t)throw Error(s(`runtimePresenceLaunchAtLoginUnavailable`));Fr.setState({busyAction:`saving-preferences`});try{let n=await t.updatePresencePreferences(e);return Fr.setState({supported:!0,initialized:!0,snapshot:n}),N.success(s(`runtimePresenceSaved`)),n}catch(e){throw N.error(`${s(`runtimePresenceSaveFailed`)}: ${this.getErrorMessage(e)}`),e}finally{Fr.setState({busyAction:null})}},this.getDesktopApi=()=>typeof window>`u`?null:window.nextclawDesktop??null,this.getErrorMessage=e=>e instanceof Error?e.message:s(`error`)}},Lr=m(()=>({supported:!1,initialized:!1,busyAction:null,snapshot:null}));new class{constructor(){this.unsubscribe=null,this.subscriptionCount=0,this.start=async()=>{this.subscriptionCount+=1;let e=this.getDesktopApi();if(!e){Lr.setState({supported:!1,initialized:!0,snapshot:null});return}this.unsubscribe||=e.onUpdateStateChanged(e=>{Lr.setState({supported:!0,initialized:!0,snapshot:e})}),Lr.setState({supported:!0,initialized:!1});try{let t=await e.getUpdateState();Lr.setState({supported:!0,initialized:!0,snapshot:t})}catch(e){Lr.setState({supported:!0,initialized:!0}),N.error(`${s(`desktopUpdatesLoadFailed`)}: ${this.getErrorMessage(e)}`)}},this.stop=()=>{this.subscriptionCount=Math.max(0,this.subscriptionCount-1),!(this.subscriptionCount>0)&&(this.unsubscribe?.(),this.unsubscribe=null)},this.checkForUpdates=async()=>{let e;try{e=await this.runSnapshotCommand(`checking`,s(`desktopUpdatesCheckFailed`),async e=>await e.checkForUpdates())}catch{return}if(e.status===`up-to-date`){N.success(s(`desktopUpdatesAlreadyLatest`));return}if(e.status===`update-available`){N.success(s(`desktopUpdatesAvailable`).replace(`{version}`,e.availableVersion??s(`desktopUpdatesUnknownVersion`)));return}if(e.status===`downloaded`){N.success(s(`desktopUpdatesReadyToApply`));return}e.status===`failed`&&e.errorMessage&&N.error(e.errorMessage)},this.downloadUpdate=async()=>{let e;try{e=await this.runSnapshotCommand(`downloading`,s(`desktopUpdatesDownloadFailed`),async e=>await e.downloadUpdate())}catch{return}e.status===`downloaded`&&N.success(s(`desktopUpdatesReadyToApply`))},this.applyDownloadedUpdate=async()=>{try{await this.runSnapshotCommand(`applying`,s(`desktopUpdatesApplyFailed`),async e=>await e.applyDownloadedUpdate())}catch{return}},this.updatePreferences=async e=>{try{await this.runSnapshotCommand(`saving-preferences`,s(`desktopUpdatesPreferencesFailed`),async t=>await t.updatePreferences(e))}catch{return}},this.updateChannel=async e=>{if(Lr.getState().snapshot?.channel===e)return;let t;try{t=await this.runSnapshotCommand(`switching-channel`,s(`desktopUpdatesChannelChangeFailed`),async t=>await t.updateChannel(e))}catch{return}if(t.status===`update-available`&&t.availableVersion){N.success(s(`desktopUpdatesChannelChangedWithUpdate`).replace(`{channel}`,this.getChannelLabel(e)).replace(`{version}`,t.availableVersion));return}N.success(s(`desktopUpdatesChannelChanged`).replace(`{channel}`,this.getChannelLabel(e)))},this.runSnapshotCommand=async(e,t,n)=>{let r=this.getDesktopApi();if(!r)throw Error(s(`desktopUpdatesDesktopOnlyDescription`));Lr.setState({busyAction:e});try{let e=await n(r);return Lr.setState({snapshot:e}),e}catch(e){throw N.error(`${t}: ${this.getErrorMessage(e)}`),e}finally{Lr.setState({busyAction:null})}},this.getDesktopApi=()=>typeof window>`u`?null:window.nextclawDesktop??null,this.getErrorMessage=e=>e instanceof Error?e.message:s(`error`),this.getChannelLabel=e=>s(e===`beta`?`desktopUpdatesChannelBeta`:`desktopUpdatesChannelStable`)}};function Rr(e,t){let n=e.toLowerCase(),r=t.toLowerCase();return n===r||n.startsWith(`${r}/`)}function zr(e){let t=e.toLowerCase();return t===`/chat`||t.startsWith(`/chat/`)||t===`/skills`||t.startsWith(`/skills/`)||t===`/cron`||t.startsWith(`/cron/`)||t===`/agents`||t.startsWith(`/agents/`)}function Br(e){let t=e.toLowerCase();return t.startsWith(`/chat/`)&&t!==`/chat`}function Vr(e){return[{target:`/chat`,label:e(`chat`),icon:lr},{target:`/skills`,label:e(`marketplaceFilterSkills`),icon:E},{target:`/agents`,label:e(`agentsPageTitle`),icon:Pn},{target:`/settings`,label:e(`settings`),icon:_r}]}function Hr(e){return[{target:`/model`,label:e(`model`),icon:Hn},{target:`/providers`,label:e(`providers`),icon:br},{target:`/channels`,label:e(`channels`),icon:dr},{target:`/search`,label:e(`searchChannels`),icon:mn},{target:`/runtime`,label:e(`runtime`),icon:Hn},{target:`/updates`,label:e(`updates`),icon:Un},{target:`/remote`,label:e(`remote`),icon:wr},{target:`/security`,label:e(`security`),icon:vr},{target:`/secrets`,label:e(`secrets`),icon:fn},{target:`/marketplace/mcp`,label:e(`marketplaceFilterMcp`),icon:O}]}function Ur(e){return[{target:`/language`,label:e(`language`),icon:cr},...Hr(e)]}function Wr(e){let t=e.toLowerCase();return t===`/settings`?!0:Ur(e=>e).some(e=>Rr(t,e.target))}function Gr(e,t){let n=e.toLowerCase(),r=Ur(t);if(Br(n))return{title:t(`chat`),backTarget:`/chat`,backLabel:t(`chat`)};if(n===`/chat`)return{title:t(`chat`),backTarget:null,backLabel:null};if(n===`/skills`||n.startsWith(`/skills/`))return{title:t(`marketplaceFilterSkills`),backTarget:null,backLabel:null};if(n===`/agents`||n.startsWith(`/agents/`))return{title:t(`agentsPageTitle`),backTarget:null,backLabel:null};if(n===`/settings`)return{title:t(`settings`),backTarget:null,backLabel:null};for(let e of r)if(Rr(n,e.target))return{title:e.label,backTarget:`/settings`,backLabel:t(`settings`)};return{title:t(`settings`),backTarget:null,backLabel:null}}var Kr=`nextclaw.ui.theme`,qr=[{value:`warm`,labelKey:`themeWarm`},{value:`cool`,labelKey:`themeCool`}],Jr=`warm`,Yr=!1,Xr=new Set;function Zr(e){return e===`warm`||e===`cool`}function Qr(e){typeof document>`u`||document.documentElement.setAttribute(`data-theme`,e)}function $r(){if(typeof window>`u`)return`warm`;try{let e=window.localStorage.getItem(Kr);if(Zr(e))return e}catch{}return`warm`}function ei(){return Yr||=(Jr=$r(),Qr(Jr),!0),Jr}function ti(){return Yr?Jr:ei()}function ni(e){if(ei(),e!==Jr){if(Jr=e,Qr(Jr),typeof window<`u`)try{window.localStorage.setItem(Kr,Jr)}catch{}Xr.forEach(e=>e(Jr))}}function ri(e){return Xr.add(e),()=>{Xr.delete(e)}}function ii(){return Ve({queryKey:[`config`],queryFn:Ee,staleTime:3e4,refetchOnWindowFocus:!0})}function ai(){return Ve({queryKey:[`app-meta`],queryFn:Se,staleTime:1/0})}function oi(){return Ve({queryKey:[`config-meta`],queryFn:Ie,staleTime:1/0})}function si(){return Ve({queryKey:[`providers`],queryFn:ze,staleTime:3e4,refetchOnWindowFocus:!0})}function ci(){return Ve({queryKey:[`provider-templates`],queryFn:xe,staleTime:1/0})}function li(){return Ve({queryKey:[`config-schema`],queryFn:xt,staleTime:1/0})}function ui(){let e=Fe();return me({mutationFn:Ge,onSuccess:()=>{e.invalidateQueries({queryKey:[`config`]}),N.success(s(`configSaved`))},onError:e=>{N.error(s(`configSaveFailed`)+`: `+e.message)}})}function di(){let e=Fe();return me({mutationFn:({data:e})=>$e(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`config`]}),e.invalidateQueries({queryKey:[`config-meta`]}),N.success(s(`configSavedApplied`))},onError:e=>{N.error(s(`configSaveFailed`)+`: `+e.message)}})}function fi(){let e=Fe();return me({mutationFn:({provider:e,data:t})=>Pe(e,t),onSuccess:(t,n)=>{e.invalidateQueries({queryKey:[`providers`]}),e.invalidateQueries({queryKey:[`config`]}),n.silentSuccess||N.success(s(`configSaved`))},onError:e=>{N.error(s(`configSaveFailed`)+`: `+e.message)}})}function pi(){let e=Fe();return me({mutationFn:({data:e})=>Oe(e??{}),onSuccess:()=>{e.invalidateQueries({queryKey:[`providers`]}),e.invalidateQueries({queryKey:[`config`]}),N.success(s(`configSaved`))},onError:e=>{N.error(s(`configSaveFailed`)+`: `+e.message)}})}function mi(){let e=Fe();return me({mutationFn:({provider:e})=>Me(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`providers`]}),e.invalidateQueries({queryKey:[`config`]}),N.success(s(`configSaved`))},onError:e=>{N.error(s(`configSaveFailed`)+`: `+e.message)}})}function hi(){return me({mutationFn:({provider:e,data:t})=>We(e,t)})}function gi(){return me({mutationFn:({provider:e,data:t})=>we(e,t)})}function _i(){return me({mutationFn:({provider:e,data:t})=>be(e,t)})}function vi(){return me({mutationFn:({provider:e})=>He(e)})}function yi(){let e=Fe();return me({mutationFn:({channel:e,data:t})=>Ue(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`config`]}),e.invalidateQueries({queryKey:[`config-meta`]}),N.success(s(`configSavedApplying`))},onError:e=>{N.error(s(`configSaveFailed`)+`: `+e.message)}})}function bi(){let e=Fe();return me({mutationFn:({data:e})=>de(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`config`]}),N.success(s(`configSavedApplied`))},onError:e=>{N.error(s(`configSaveFailed`)+`: `+e.message)}})}function xi(){let e=Fe();return me({mutationFn:({data:e})=>ht(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`config`]}),N.success(s(`configSavedApplied`))},onError:e=>{N.error(s(`configSaveFailed`)+`: `+e.message)}})}function Si(){return me({mutationFn:({actionId:e,data:t})=>ve(e,t),onError:e=>{N.error(s(`error`)+`: `+e.message)}})}function Ci(e){return Ve({queryKey:[`ncp-sessions`,e?.limit??null,e?.peerId?.trim()||null],queryFn:()=>qe(e),staleTime:5e3,retry:!1})}function wi(e){return Ve({queryKey:[`ncp-session-skills`,e.sessionId,e.projectRoot??null],queryFn:()=>nt(e.sessionId,{...Object.prototype.hasOwnProperty.call(e,`projectRoot`)?{projectRoot:e.projectRoot??null}:{}}),enabled:!!e.sessionId,staleTime:5e3,retry:!1})}function Ti(e={all:!0}){return Ve({queryKey:[`cron`,e],queryFn:()=>pe(e),staleTime:1e4})}function Ei(){let e=Fe();return me({mutationFn:({id:e})=>ke(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`cron`]}),N.success(s(`configSavedApplied`))},onError:e=>{N.error(s(`configSaveFailed`)+`: `+e.message)}})}function Di(){let e=Fe();return me({mutationFn:({id:e,enabled:t})=>ft(e,{enabled:t}),onSuccess:()=>{e.invalidateQueries({queryKey:[`cron`]}),N.success(s(`configSavedApplied`))},onError:e=>{N.error(s(`configSaveFailed`)+`: `+e.message)}})}function Oi(){let e=Fe();return me({mutationFn:({id:e,force:t})=>Te(e,{force:t}),onSuccess:()=>{e.invalidateQueries({queryKey:[`cron`]}),N.success(s(`configSavedApplied`))},onError:e=>{N.error(s(`configSaveFailed`)+`: `+e.message)}})}var ki={healthy:`bg-emerald-500 shadow-[0_0_0_3px_rgba(16,185,129,0.14)]`,attention:`bg-amber-400 shadow-[0_0_0_3px_rgba(251,191,36,0.16)]`,inactive:`bg-gray-300 shadow-[0_0_0_3px_rgba(156,163,175,0.12)]`};function Ai(){let e=_t(),t=e.actionLabel===s(`runtimeStatusRestartAction`),n=()=>{e.tone!==`healthy`&&vt.requestRuntimeBootstrapProbeNow()},i=async()=>{if(t)try{let e=await vt.runRuntimeControlAction(`restart-service`);N.success(e.message)}catch(e){let t=e instanceof Error?e.message:s(`runtimeControlActionFailed`);N.error(`${s(`runtimeControlActionFailed`)}: ${t}`)}};return(0,I.jsxs)(wn,{children:[(0,I.jsx)(Sn,{asChild:!0,children:(0,I.jsx)(`button`,{type:`button`,className:`inline-flex items-center justify-center rounded-full p-0.5 transition-transform hover:scale-105`,"aria-label":e.title,title:e.title,"data-testid":`runtime-status-entry`,onClick:n,children:(0,I.jsx)(`span`,{className:r(`h-2.5 w-2.5 rounded-full`,ki[e.tone])})})}),(0,I.jsxs)(bn,{align:`start`,sideOffset:10,className:`w-[290px] space-y-3 rounded-2xl border border-gray-200 bg-white p-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(`div`,{className:`text-sm font-semibold text-gray-900`,children:e.title}),(0,I.jsx)(`p`,{className:`text-xs leading-5 text-gray-600`,children:e.description})]}),e.reasonLines.length>0?(0,I.jsx)(`div`,{className:`space-y-2`,children:e.reasonLines.map(e=>(0,I.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-xs leading-5 text-amber-900`,children:e},e))}):null,e.actionLabel?(0,I.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-100 pt-1`,children:[(0,I.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:s(`runtimeStatusActionHint`)}),(0,I.jsx)(`button`,{type:`button`,onClick:()=>void i(),disabled:e.isBusy,className:`text-sm font-semibold text-sky-600 transition-colors hover:text-sky-700 disabled:text-gray-400`,children:e.isBusy?s(`runtimeStatusRestartingAction`):e.actionLabel})]}):null]})]})}function ji({className:e,density:t=`sidebar`,suffix:n}){let{data:i}=ai(),a=i?.name??`NextClaw`,o=i?.productVersion?.trim(),s=o?`v${o}`:null,c=n??(0,I.jsx)(Ai,{}),l=typeof window<`u`&&window.nextclawDesktop?.platform===`darwin`,u=t===`chrome`;return(0,I.jsxs)(`div`,{className:r(e??`flex min-w-0 items-center gap-2`,l&&`pl-[58px]`),children:[(0,I.jsx)(`div`,{className:r(`flex shrink-0 items-center justify-center overflow-hidden`,`h-6 w-6 rounded-md`),children:(0,I.jsx)(`img`,{src:`/logo.svg`,alt:a,className:`h-full w-full object-contain`})}),(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-baseline gap-1.5`,children:[(0,I.jsx)(`span`,{className:r(`shrink-0 font-semibold text-gray-800`,u?`text-[15px]`:`text-[14px]`),children:a}),s?(0,I.jsx)(Mi,{versionLabel:s,density:t}):null]}),(0,I.jsx)(Ni,{}),c?(0,I.jsx)(`span`,{className:`inline-flex items-center shrink-0`,children:c}):null]})]})}function Mi({versionLabel:e,density:t}){let[n,i]=(0,F.useState)(!1);return(0,I.jsxs)(`span`,{className:`relative min-w-0 flex-1`,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),onFocus:()=>i(!0),onBlur:()=>i(!1),children:[(0,I.jsx)(`span`,{tabIndex:0,"aria-label":e,className:r(`block min-w-0 truncate font-medium text-gray-500 outline-none`,`text-[12px]`),children:e}),n?(0,I.jsx)(`span`,{className:`pointer-events-none absolute left-0 top-full z-[var(--z-tooltip)] mt-1 w-max max-w-none whitespace-nowrap rounded-md border bg-popover px-3 py-1.5 text-xs font-medium text-popover-foreground shadow-md`,children:e}):null]})}function Ni(){let{supported:e,busyAction:t,snapshot:n}=rt();return!e||!n?null:n.status===`downloading`||n.status===`blocked`||n.status===`failed`?(0,I.jsx)(Pi,{snapshot:n}):n.status===`downloaded`?(0,I.jsx)(`button`,{type:`button`,className:`inline-flex h-5 shrink-0 items-center rounded-full bg-emerald-50 px-2 text-[11px] font-semibold leading-none text-emerald-700 ring-1 ring-emerald-100 transition-colors hover:bg-emerald-100 disabled:opacity-70`,disabled:t===`applying`,onClick:()=>void at.applyDownloadedUpdate(),children:s(t===`applying`?`desktopUpdatesInlineApplying`:`desktopUpdatesInlineReady`)}):n.status===`update-available`?(0,I.jsx)(`button`,{type:`button`,className:`inline-flex h-5 shrink-0 items-center rounded-full bg-amber-50 px-2 text-[11px] font-semibold leading-none text-amber-700 ring-1 ring-amber-100 transition-colors hover:bg-amber-100 disabled:opacity-70`,disabled:t===`downloading`,onClick:()=>void at.downloadUpdate(),children:s(t===`downloading`?`desktopUpdatesInlineDownloading`:`desktopUpdatesInlineDownload`)}):null}function Pi({snapshot:e}){if(e.status===`blocked`||e.status===`failed`)return(0,I.jsx)(Fi,{snapshot:e});let t=e.status===`downloading`?Ii(e):null;return t?(0,I.jsx)(`span`,{className:`inline-flex h-5 shrink-0 items-center rounded-full bg-amber-50 px-2 text-[11px] font-semibold leading-none text-amber-700 ring-1 ring-amber-100 transition-colors hover:bg-amber-100 disabled:opacity-70`,title:s(`updates`),children:t}):null}function Fi({snapshot:e}){let t=e.status===`failed`?s(`desktopUpdatesStatusFailed`):s(`desktopUpdatesStatusBlocked`),n=e.recoveryCommand?.trim()||null,r=e.errorMessage?.trim()||e.blockReason?.trim()||null,i=[t,e.status===`blocked`&&e.blockReason?s(`desktopUpdatesBlockedRootCause.${e.blockReason}`):null,r,n].filter(Boolean).join(`
|
|
3
3
|
`);return(0,I.jsx)(`span`,{role:`img`,"aria-label":t,title:i,tabIndex:0,className:`inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-amber-50 text-[13px] font-bold leading-none text-amber-700 ring-1 ring-amber-100`,children:`!`})}function Ii(e){let t=e.progress?.percent;return t==null?s(`desktopUpdatesInlineDownloading`):s(`desktopUpdatesInlineDownloadingPercent`).replace(`{percent}`,String(t))}var Li=_(o(),1);function Ri(e,[t,n]){return Math.min(n,Math.max(t,e))}function zi(e){let t=e+`CollectionProvider`,[n,r]=Rt(t),[i,a]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=e=>{let{scope:t,children:n}=e,r=F.useRef(null),a=F.useRef(new Map).current;return(0,I.jsx)(i,{scope:t,itemMap:a,collectionRef:r,children:n})};o.displayName=t;let s=e+`CollectionSlot`,c=Nt(s),l=F.forwardRef((e,t)=>{let{scope:n,children:r}=e;return(0,I.jsx)(c,{ref:wt(t,a(s,n).collectionRef),children:r})});l.displayName=s;let u=e+`CollectionItemSlot`,d=`data-radix-collection-item`,f=Nt(u),p=F.forwardRef((e,t)=>{let{scope:n,children:r,...i}=e,o=F.useRef(null),s=wt(t,o),c=a(u,n);return F.useEffect(()=>(c.itemMap.set(o,{ref:o,...i}),()=>void c.itemMap.delete(o))),(0,I.jsx)(f,{[d]:``,ref:s,children:r})});p.displayName=u;function m(t){let n=a(e+`CollectionConsumer`,t);return F.useCallback(()=>{let e=n.collectionRef.current;if(!e)return[];let t=Array.from(e.querySelectorAll(`[${d}]`));return Array.from(n.itemMap.values()).sort((e,n)=>t.indexOf(e.ref.current)-t.indexOf(n.ref.current))},[n.collectionRef,n.itemMap])}return[{Provider:o,Slot:l,ItemSlot:p},m,r]}var Bi=F.createContext(void 0);function Vi(e){let t=F.useContext(Bi);return e||t||`ltr`}function Hi(e){let t=F.useRef({value:e,previous:e});return F.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Ui=[` `,`Enter`,`ArrowUp`,`ArrowDown`],Wi=[` `,`Enter`],Gi=`Select`,[Ki,qi,Ji]=zi(Gi),[Yi,Xi]=Rt(Gi,[Ji,Ft]),Zi=Ft(),[Qi,$i]=Yi(Gi),[ea,ta]=Yi(Gi),na=e=>{let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:a,value:o,defaultValue:s,onValueChange:c,dir:l,name:u,autoComplete:d,disabled:f,required:p,form:m}=e,h=Zi(t),[g,_]=F.useState(null),[v,y]=F.useState(null),[b,x]=F.useState(!1),S=Vi(l),[C,w]=Ot({prop:r,defaultProp:i??!1,onChange:a,caller:Gi}),[T,E]=Ot({prop:o,defaultProp:s,onChange:c,caller:Gi}),D=F.useRef(null),O=g?m||!!g.closest(`form`):!0,[k,A]=F.useState(new Set),ee=Array.from(k).map(e=>e.props.value).join(`;`);return(0,I.jsx)(Mt,{...h,children:(0,I.jsxs)(Qi,{required:p,scope:t,trigger:g,onTriggerChange:_,valueNode:v,onValueNodeChange:y,valueNodeHasChildren:b,onValueNodeHasChildrenChange:x,contentId:Dt(),value:T,onValueChange:E,open:C,onOpenChange:w,dir:S,triggerPointerDownPosRef:D,disabled:f,children:[(0,I.jsx)(Ki.Provider,{scope:t,children:(0,I.jsx)(ea,{scope:e.__scopeSelect,onNativeOptionAdd:F.useCallback(e=>{A(t=>new Set(t).add(e))},[]),onNativeOptionRemove:F.useCallback(e=>{A(t=>{let n=new Set(t);return n.delete(e),n})},[]),children:n})}),O?(0,I.jsxs)(Za,{"aria-hidden":!0,required:p,tabIndex:-1,name:u,autoComplete:d,value:T,onChange:e=>E(e.target.value),disabled:f,form:m,children:[T===void 0?(0,I.jsx)(`option`,{value:``}):null,Array.from(k)]},ee):null]})})};na.displayName=Gi;var ra=`SelectTrigger`,ia=F.forwardRef((e,t)=>{let{__scopeSelect:n,disabled:r=!1,...i}=e,a=Zi(n),o=$i(ra,n),s=o.disabled||r,c=wt(t,o.onTriggerChange),l=qi(n),u=F.useRef(`touch`),[d,f,p]=$a(e=>{let t=l().filter(e=>!e.disabled),n=eo(t,e,t.find(e=>e.value===o.value));n!==void 0&&o.onValueChange(n.value)}),m=e=>{s||(o.onOpenChange(!0),p()),e&&(o.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})};return(0,I.jsx)(Pt,{asChild:!0,...a,children:(0,I.jsx)(Et.button,{type:`button`,role:`combobox`,"aria-controls":o.contentId,"aria-expanded":o.open,"aria-required":o.required,"aria-autocomplete":`none`,dir:o.dir,"data-state":o.open?`open`:`closed`,disabled:s,"data-disabled":s?``:void 0,"data-placeholder":Qa(o.value)?``:void 0,...i,ref:c,onClick:Lt(i.onClick,e=>{e.currentTarget.focus(),u.current!==`mouse`&&m(e)}),onPointerDown:Lt(i.onPointerDown,e=>{u.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),e.button===0&&e.ctrlKey===!1&&e.pointerType===`mouse`&&(m(e),e.preventDefault())}),onKeyDown:Lt(i.onKeyDown,e=>{let t=d.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&f(e.key),!(t&&e.key===` `)&&Ui.includes(e.key)&&(m(),e.preventDefault())})})})});ia.displayName=ra;var aa=`SelectValue`,oa=F.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,children:a,placeholder:o=``,...s}=e,c=$i(aa,n),{onValueNodeHasChildrenChange:l}=c,u=a!==void 0,d=wt(t,c.onValueNodeChange);return St(()=>{l(u)},[l,u]),(0,I.jsx)(Et.span,{...s,ref:d,style:{pointerEvents:`none`},children:Qa(c.value)?(0,I.jsx)(I.Fragment,{children:o}):a})});oa.displayName=aa;var sa=`SelectIcon`,ca=F.forwardRef((e,t)=>{let{__scopeSelect:n,children:r,...i}=e;return(0,I.jsx)(Et.span,{"aria-hidden":!0,...i,ref:t,children:r||`▼`})});ca.displayName=sa;var la=`SelectPortal`,ua=e=>(0,I.jsx)(At,{asChild:!0,...e});ua.displayName=la;var da=`SelectContent`,fa=F.forwardRef((e,t)=>{let n=$i(da,e.__scopeSelect),[r,i]=F.useState();if(St(()=>{i(new DocumentFragment)},[]),!n.open){let t=r;return t?Li.createPortal((0,I.jsx)(ma,{scope:e.__scopeSelect,children:(0,I.jsx)(Ki.Slot,{scope:e.__scopeSelect,children:(0,I.jsx)(`div`,{children:e.children})})}),t):null}return(0,I.jsx)(va,{...e,ref:t})});fa.displayName=da;var pa=10,[ma,ha]=Yi(da),ga=`SelectContentImpl`,_a=Nt(`SelectContent.RemoveScroll`),va=F.forwardRef((e,t)=>{let{__scopeSelect:n,position:r=`item-aligned`,onCloseAutoFocus:i,onEscapeKeyDown:a,onPointerDownOutside:o,side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g,..._}=e,v=$i(da,n),[y,b]=F.useState(null),[x,S]=F.useState(null),C=wt(t,e=>b(e)),[w,T]=F.useState(null),[E,D]=F.useState(null),O=qi(n),[k,A]=F.useState(!1),ee=F.useRef(!1);F.useEffect(()=>{if(y)return Ht(y)},[y]),Vt();let j=F.useCallback(e=>{let[t,...n]=O().map(e=>e.ref.current),[r]=n.slice(-1),i=document.activeElement;for(let n of e)if(n===i||(n?.scrollIntoView({block:`nearest`}),n===t&&x&&(x.scrollTop=0),n===r&&x&&(x.scrollTop=x.scrollHeight),n?.focus(),document.activeElement!==i))return},[O,x]),te=F.useCallback(()=>j([w,y]),[j,w,y]);F.useEffect(()=>{k&&te()},[k,te]);let{onOpenChange:M,triggerPointerDownPosRef:ne}=v;F.useEffect(()=>{if(y){let e={x:0,y:0},t=t=>{e={x:Math.abs(Math.round(t.pageX)-(ne.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(ne.current?.y??0))}},n=n=>{e.x<=10&&e.y<=10?n.preventDefault():y.contains(n.target)||M(!1),document.removeEventListener(`pointermove`,t),ne.current=null};return ne.current!==null&&(document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,n,{capture:!0,once:!0})),()=>{document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,n,{capture:!0})}}},[y,M,ne]),F.useEffect(()=>{let e=()=>M(!1);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[M]);let[re,ie]=$a(e=>{let t=O().filter(e=>!e.disabled),n=eo(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current.focus())}),ae=F.useCallback((e,t,n)=>{let r=!ee.current&&!n;(v.value!==void 0&&v.value===t||r)&&(T(e),r&&(ee.current=!0))},[v.value]),oe=F.useCallback(()=>y?.focus(),[y]),se=F.useCallback((e,t,n)=>{let r=!ee.current&&!n;(v.value!==void 0&&v.value===t||r)&&D(e)},[v.value]),ce=r===`popper`?Sa:ba,le=ce===Sa?{side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g}:{};return(0,I.jsx)(ma,{scope:n,content:y,viewport:x,onViewportChange:S,itemRefCallback:ae,selectedItem:w,onItemLeave:oe,itemTextRefCallback:se,focusSelectedItem:te,selectedItemText:E,position:r,isPositioned:k,searchRef:re,children:(0,I.jsx)(Bt,{as:_a,allowPinchZoom:!0,children:(0,I.jsx)(zt,{asChild:!0,trapped:v.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:Lt(i,e=>{v.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,I.jsx)(It,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>v.onOpenChange(!1),children:(0,I.jsx)(ce,{role:`listbox`,id:v.contentId,"data-state":v.open?`open`:`closed`,dir:v.dir,onContextMenu:e=>e.preventDefault(),..._,...le,onPlaced:()=>A(!0),ref:C,style:{display:`flex`,flexDirection:`column`,outline:`none`,..._.style},onKeyDown:Lt(_.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&ie(e.key),[`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(e.key)){let t=O().filter(e=>!e.disabled).map(e=>e.ref.current);if([`ArrowUp`,`End`].includes(e.key)&&(t=t.slice().reverse()),[`ArrowUp`,`ArrowDown`].includes(e.key)){let n=e.target,r=t.indexOf(n);t=t.slice(r+1)}setTimeout(()=>j(t)),e.preventDefault()}})})})})})})});va.displayName=ga;var ya=`SelectItemAlignedPosition`,ba=F.forwardRef((e,t)=>{let{__scopeSelect:n,onPlaced:r,...i}=e,a=$i(da,n),o=ha(da,n),[s,c]=F.useState(null),[l,u]=F.useState(null),d=wt(t,e=>u(e)),f=qi(n),p=F.useRef(!1),m=F.useRef(!0),{viewport:h,selectedItem:g,selectedItemText:_,focusSelectedItem:v}=o,y=F.useCallback(()=>{if(a.trigger&&a.valueNode&&s&&l&&h&&g&&_){let e=a.trigger.getBoundingClientRect(),t=l.getBoundingClientRect(),n=a.valueNode.getBoundingClientRect(),i=_.getBoundingClientRect();if(a.dir!==`rtl`){let r=i.left-t.left,a=n.left-r,o=e.left-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-pa,d=Ri(a,[pa,Math.max(pa,u-l)]);s.style.minWidth=c+`px`,s.style.left=d+`px`}else{let r=t.right-i.right,a=window.innerWidth-n.right-r,o=window.innerWidth-e.right-a,c=e.width+o,l=Math.max(c,t.width),u=window.innerWidth-pa,d=Ri(a,[pa,Math.max(pa,u-l)]);s.style.minWidth=c+`px`,s.style.right=d+`px`}let o=f(),c=window.innerHeight-pa*2,u=h.scrollHeight,d=window.getComputedStyle(l),m=parseInt(d.borderTopWidth,10),v=parseInt(d.paddingTop,10),y=parseInt(d.borderBottomWidth,10),b=parseInt(d.paddingBottom,10),x=m+v+u+b+y,S=Math.min(g.offsetHeight*5,x),C=window.getComputedStyle(h),w=parseInt(C.paddingTop,10),T=parseInt(C.paddingBottom,10),E=e.top+e.height/2-pa,D=c-E,O=g.offsetHeight/2,k=g.offsetTop+O,A=m+v+k,ee=x-A;if(A<=E){let e=o.length>0&&g===o[o.length-1].ref.current;s.style.bottom=`0px`;let t=l.clientHeight-h.offsetTop-h.offsetHeight,n=A+Math.max(D,O+(e?T:0)+t+y);s.style.height=n+`px`}else{let e=o.length>0&&g===o[0].ref.current;s.style.top=`0px`;let t=Math.max(E,m+h.offsetTop+(e?w:0)+O)+ee;s.style.height=t+`px`,h.scrollTop=A-E+h.offsetTop}s.style.margin=`${pa}px 0`,s.style.minHeight=S+`px`,s.style.maxHeight=c+`px`,r?.(),requestAnimationFrame(()=>p.current=!0)}},[f,a.trigger,a.valueNode,s,l,h,g,_,a.dir,r]);St(()=>y(),[y]);let[b,x]=F.useState();return St(()=>{l&&x(window.getComputedStyle(l).zIndex)},[l]),(0,I.jsx)(Ca,{scope:n,contentWrapper:s,shouldExpandOnScrollRef:p,onScrollButtonChange:F.useCallback(e=>{e&&m.current===!0&&(y(),v?.(),m.current=!1)},[y,v]),children:(0,I.jsx)(`div`,{ref:c,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:b},children:(0,I.jsx)(Et.div,{...i,ref:d,style:{boxSizing:`border-box`,maxHeight:`100%`,...i.style}})})})});ba.displayName=ya;var xa=`SelectPopperPosition`,Sa=F.forwardRef((e,t)=>{let{__scopeSelect:n,align:r=`start`,collisionPadding:i=pa,...a}=e,o=Zi(n);return(0,I.jsx)(Ct,{...o,...a,ref:t,align:r,collisionPadding:i,style:{boxSizing:`border-box`,...a.style,"--radix-select-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-select-content-available-width":`var(--radix-popper-available-width)`,"--radix-select-content-available-height":`var(--radix-popper-available-height)`,"--radix-select-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-select-trigger-height":`var(--radix-popper-anchor-height)`}})});Sa.displayName=xa;var[Ca,wa]=Yi(da,{}),Ta=`SelectViewport`,Ea=F.forwardRef((e,t)=>{let{__scopeSelect:n,nonce:r,...i}=e,a=ha(Ta,n),o=wa(Ta,n),s=wt(t,a.onViewportChange),c=F.useRef(0);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`},nonce:r}),(0,I.jsx)(Ki.Slot,{scope:n,children:(0,I.jsx)(Et.div,{"data-radix-select-viewport":``,role:`presentation`,...i,ref:s,style:{position:`relative`,flex:1,overflow:`hidden auto`,...i.style},onScroll:Lt(i.onScroll,e=>{let t=e.currentTarget,{contentWrapper:n,shouldExpandOnScrollRef:r}=o;if(r?.current&&n){let e=Math.abs(c.current-t.scrollTop);if(e>0){let r=window.innerHeight-pa*2,i=parseFloat(n.style.minHeight),a=parseFloat(n.style.height),o=Math.max(i,a);if(o<r){let i=o+e,a=Math.min(r,i),s=i-a;n.style.height=a+`px`,n.style.bottom===`0px`&&(t.scrollTop=s>0?s:0,n.style.justifyContent=`flex-end`)}}}c.current=t.scrollTop})})})]})});Ea.displayName=Ta;var Da=`SelectGroup`,[Oa,ka]=Yi(Da),Aa=F.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=Dt();return(0,I.jsx)(Oa,{scope:n,id:i,children:(0,I.jsx)(Et.div,{role:`group`,"aria-labelledby":i,...r,ref:t})})});Aa.displayName=Da;var ja=`SelectLabel`,Ma=F.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=ka(ja,n);return(0,I.jsx)(Et.div,{id:i.id,...r,ref:t})});Ma.displayName=ja;var Na=`SelectItem`,[Pa,Fa]=Yi(Na),Ia=F.forwardRef((e,t)=>{let{__scopeSelect:n,value:r,disabled:i=!1,textValue:a,...o}=e,s=$i(Na,n),c=ha(Na,n),l=s.value===r,[u,d]=F.useState(a??``),[f,p]=F.useState(!1),m=wt(t,e=>c.itemRefCallback?.(e,r,i)),h=Dt(),g=F.useRef(`touch`),_=()=>{i||(s.onValueChange(r),s.onOpenChange(!1))};if(r===``)throw Error(`A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.`);return(0,I.jsx)(Pa,{scope:n,value:r,disabled:i,textId:h,isSelected:l,onItemTextChange:F.useCallback(e=>{d(t=>t||(e?.textContent??``).trim())},[]),children:(0,I.jsx)(Ki.ItemSlot,{scope:n,value:r,disabled:i,textValue:u,children:(0,I.jsx)(Et.div,{role:`option`,"aria-labelledby":h,"data-highlighted":f?``:void 0,"aria-selected":l&&f,"data-state":l?`checked`:`unchecked`,"aria-disabled":i||void 0,"data-disabled":i?``:void 0,tabIndex:i?void 0:-1,...o,ref:m,onFocus:Lt(o.onFocus,()=>p(!0)),onBlur:Lt(o.onBlur,()=>p(!1)),onClick:Lt(o.onClick,()=>{g.current!==`mouse`&&_()}),onPointerUp:Lt(o.onPointerUp,()=>{g.current===`mouse`&&_()}),onPointerDown:Lt(o.onPointerDown,e=>{g.current=e.pointerType}),onPointerMove:Lt(o.onPointerMove,e=>{g.current=e.pointerType,i?c.onItemLeave?.():g.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:Lt(o.onPointerLeave,e=>{e.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:Lt(o.onKeyDown,e=>{c.searchRef?.current!==``&&e.key===` `||(Wi.includes(e.key)&&_(),e.key===` `&&e.preventDefault())})})})})});Ia.displayName=Na;var La=`SelectItemText`,Ra=F.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,...a}=e,o=$i(La,n),s=ha(La,n),c=Fa(La,n),l=ta(La,n),[u,d]=F.useState(null),f=wt(t,e=>d(e),c.onItemTextChange,e=>s.itemTextRefCallback?.(e,c.value,c.disabled)),p=u?.textContent,m=F.useMemo(()=>(0,I.jsx)(`option`,{value:c.value,disabled:c.disabled,children:p},c.value),[c.disabled,c.value,p]),{onNativeOptionAdd:h,onNativeOptionRemove:g}=l;return St(()=>(h(m),()=>g(m)),[h,g,m]),(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Et.span,{id:c.textId,...a,ref:f}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren?Li.createPortal(a.children,o.valueNode):null]})});Ra.displayName=La;var za=`SelectItemIndicator`,Ba=F.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return Fa(za,n).isSelected?(0,I.jsx)(Et.span,{"aria-hidden":!0,...r,ref:t}):null});Ba.displayName=za;var Va=`SelectScrollUpButton`,Ha=F.forwardRef((e,t)=>{let n=ha(Va,e.__scopeSelect),r=wa(Va,e.__scopeSelect),[i,a]=F.useState(!1),o=wt(t,r.onScrollButtonChange);return St(()=>{if(n.viewport&&n.isPositioned){let e=function(){a(t.scrollTop>0)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,I.jsx)(Ga,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop-=t.offsetHeight)}}):null});Ha.displayName=Va;var Ua=`SelectScrollDownButton`,Wa=F.forwardRef((e,t)=>{let n=ha(Ua,e.__scopeSelect),r=wa(Ua,e.__scopeSelect),[i,a]=F.useState(!1),o=wt(t,r.onScrollButtonChange);return St(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollHeight-t.clientHeight;a(Math.ceil(t.scrollTop)<e)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,I.jsx)(Ga,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop+=t.offsetHeight)}}):null});Wa.displayName=Ua;var Ga=F.forwardRef((e,t)=>{let{__scopeSelect:n,onAutoScroll:r,...i}=e,a=ha(`SelectScrollButton`,n),o=F.useRef(null),s=qi(n),c=F.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return F.useEffect(()=>()=>c(),[c]),St(()=>{s().find(e=>e.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:`nearest`})},[s]),(0,I.jsx)(Et.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:Lt(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:Lt(i.onPointerMove,()=>{a.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:Lt(i.onPointerLeave,()=>{c()})})}),Ka=`SelectSeparator`,qa=F.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return(0,I.jsx)(Et.div,{"aria-hidden":!0,...r,ref:t})});qa.displayName=Ka;var Ja=`SelectArrow`,Ya=F.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=Zi(n),a=$i(Ja,n),o=ha(Ja,n);return a.open&&o.position===`popper`?(0,I.jsx)(kt,{...i,...r,ref:t}):null});Ya.displayName=Ja;var Xa=`SelectBubbleInput`,Za=F.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{let i=F.useRef(null),a=wt(r,i),o=Hi(t);return F.useEffect(()=>{let e=i.current;if(!e)return;let n=window.HTMLSelectElement.prototype,r=Object.getOwnPropertyDescriptor(n,`value`).set;if(o!==t&&r){let n=new Event(`change`,{bubbles:!0});r.call(e,t),e.dispatchEvent(n)}},[o,t]),(0,I.jsx)(Et.select,{...n,style:{...jt,...n.style},ref:a,defaultValue:t})});Za.displayName=Xa;function Qa(e){return e===``||e===void 0}function $a(e){let t=Tt(e),n=F.useRef(``),r=F.useRef(0),i=F.useCallback(e=>{let i=n.current+e;t(i),(function e(t){n.current=t,window.clearTimeout(r.current),t!==``&&(r.current=window.setTimeout(()=>e(``),1e3))})(i)},[t]),a=F.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return F.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}function eo(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=to(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}function to(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var no=na,ro=ia,io=oa,ao=ca,oo=ua,so=fa,co=Ea,lo=Aa,uo=Ma,fo=Ia,po=Ra,mo=Ba,ho=Ha,go=Wa,_o=qa,vo=no,yo=io,bo=F.forwardRef(({className:e,children:t,indicator:n,...i},a)=>(0,I.jsxs)(ro,{ref:a,className:r(`flex h-9 w-full items-center justify-between whitespace-nowrap rounded-xl border border-gray-200/80 bg-transparent 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 bg-white`,e),...i,children:[t,(0,I.jsx)(ao,{asChild:!0,children:n??(0,I.jsx)(Ln,{className:`h-4 w-4 opacity-50`})})]}));bo.displayName=ro.displayName;var xo=F.forwardRef(({className:e,...t},n)=>(0,I.jsx)(ho,{ref:n,className:r(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(zn,{className:`h-4 w-4`})}));xo.displayName=ho.displayName;var So=F.forwardRef(({className:e,...t},n)=>(0,I.jsx)(go,{ref:n,className:r(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(Ln,{className:`h-4 w-4`})}));So.displayName=go.displayName;var Co=F.forwardRef(({className:e,children:t,position:n=`popper`,viewportClassName:i,...a},o)=>(0,I.jsx)(oo,{children:(0,I.jsxs)(so,{ref:o,className:r(`relative z-[var(--z-popover,50)] max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover 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 bg-white`,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,...a,children:[(0,I.jsx)(xo,{}),(0,I.jsx)(co,{className:r(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]`,i),children:t}),(0,I.jsx)(So,{})]})}));Co.displayName=so.displayName;var wo=F.forwardRef(({className:e,...t},n)=>(0,I.jsx)(uo,{ref:n,className:r(`px-2 py-1.5 text-sm font-semibold`,e),...t}));wo.displayName=uo.displayName;var To=F.forwardRef(({className:e,children:t,...n},i)=>(0,I.jsxs)(fo,{ref:i,className:r(`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 focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 hover:bg-gray-100`,e),...n,children:[(0,I.jsx)(`span`,{className:`absolute right-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,I.jsx)(mo,{children:(0,I.jsx)(In,{className:`h-4 w-4`})})}),(0,I.jsx)(po,{children:t})]}));To.displayName=fo.displayName;var Eo=F.forwardRef(({className:e,...t},n)=>(0,I.jsx)(_o,{ref:n,className:r(`-mx-1 my-1 h-px bg-muted`,e),...t}));Eo.displayName=_o.displayName;var Do={default:{row:`gap-3 px-3 py-2.5 text-[14px]`,icon:`h-[17px] w-[17px]`,value:`text-xs`,gap:`gap-3`},compact:{row:`gap-2.5 px-3 py-2 text-[13px]`,icon:`h-4 w-4`,value:`text-[11px]`,gap:`gap-2.5`}};function Oo(e){return Do[e]}function ko({to:e,label:t,icon:n,density:i=`default`,className:a}){let o=Oo(i);return(0,I.jsx)(w,{to:e,className:({isActive:e})=>r(`group flex w-full items-center rounded-xl font-medium transition-colors duration-base`,o.row,e?`bg-gray-200 text-gray-900 shadow-sm`:`text-gray-600 hover:bg-gray-200/60 hover:text-gray-900`,a),children:({isActive:e})=>(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(n,{className:r(o.icon,`transition-colors`,e?`text-gray-900`:`text-gray-500 group-hover:text-gray-800`)}),(0,I.jsx)(`span`,{className:`min-w-0 flex-1 text-left`,children:t})]})})}function Ao({label:e,icon:t,onClick:n,density:i=`default`,className:a,labelClassName:o,trailing:s,trailingClassName:c,testId:l,trailingTestId:u}){let d=Oo(i);return(0,I.jsxs)(`button`,{type:`button`,onClick:n,className:r(`flex w-full items-center rounded-xl font-medium text-gray-600 transition-all duration-base hover:bg-gray-200/60 hover:text-gray-800`,d.row,a),"data-testid":l,children:[(0,I.jsx)(t,{className:r(d.icon,`shrink-0 text-gray-400`)}),(0,I.jsx)(`span`,{className:r(`min-w-0 flex-1 text-left`,o),children:e}),s?(0,I.jsx)(`span`,{className:r(`shrink-0 text-gray-500`,d.value,c),"data-testid":u,children:s}):null]})}function jo({label:e,icon:t,value:n,valueLabel:i,onValueChange:a,density:o=`default`,children:s}){let c=Oo(o);return(0,I.jsxs)(vo,{value:n,onValueChange:a,children:[(0,I.jsxs)(bo,{className:r(`h-auto w-full rounded-xl border-0 bg-transparent font-medium text-gray-600 shadow-none hover:bg-gray-200/60 focus:ring-0`,c.row),children:[(0,I.jsxs)(`div`,{className:r(`flex min-w-0 items-center`,c.gap),children:[(0,I.jsx)(t,{className:r(c.icon,`text-gray-400`)}),(0,I.jsx)(`span`,{className:`text-left`,children:e})]}),(0,I.jsx)(`span`,{className:r(`ml-auto text-gray-500`,c.value),children:i})]}),(0,I.jsx)(Co,{children:s})]})}var Mo=`nextclaw-pwa-install-banner-dismissed`,No=`nextclaw-pwa-install-banner-dismissed-until`;function Po(){let e=Lo();return e?e.getItem(`nextclaw-pwa-install-banner-dismissed`)===`1`?!0:Ro(e):!1}function Fo(){let e=Lo();e?.setItem(Mo,`1`),e?.removeItem(No)}function Io(){let e=Lo();e?.removeItem(Mo),e?.removeItem(No)}function Lo(){if(typeof window>`u`)return null;try{return window.localStorage}catch{return null}}function Ro(e){let t=e.getItem(No);if(!t)return!1;let n=Number.parseInt(t,10);return e.removeItem(No),!Number.isFinite(n)||n<=Date.now()?!1:(e.setItem(Mo,`1`),!0)}function zo(){return{initialized:!1,installability:`unsupported`,installMethod:`none`,blockedReason:`missing-browser-support`,dismissedInstallPrompt:Po()}}var Bo=m(()=>zo()),Vo=new class{constructor(){this.started=!1,this.deferredPrompt=null,this.displayModeMediaQuery=null,this.start=()=>{this.started||typeof window>`u`||(this.started=!0,window.addEventListener(`beforeinstallprompt`,this.handleBeforeInstallPrompt),window.addEventListener(`appinstalled`,this.handleAppInstalled),typeof window.matchMedia==`function`&&(this.displayModeMediaQuery=window.matchMedia(`(display-mode: standalone)`),this.bindDisplayModeListener(this.displayModeMediaQuery,this.handleDisplayModeChanged)),this.refreshState())},this.stop=()=>{!this.started||typeof window>`u`||(window.removeEventListener(`beforeinstallprompt`,this.handleBeforeInstallPrompt),window.removeEventListener(`appinstalled`,this.handleAppInstalled),this.displayModeMediaQuery&&=(this.unbindDisplayModeListener(this.displayModeMediaQuery,this.handleDisplayModeChanged),null),this.deferredPrompt=null,this.started=!1)},this.resetForTests=()=>{this.stop(),Bo.setState(zo())},this.refreshState=()=>{let e=this.resolveInstallability();Bo.setState(t=>({...t,initialized:!0,installability:e.installability,installMethod:e.installMethod,blockedReason:e.blockedReason,dismissedInstallPrompt:Po()}))},this.dismissInstallPrompt=()=>{Fo(),Bo.setState({dismissedInstallPrompt:!0})},this.promptInstall=async()=>{let e=this.resolveInstallability();if(e.installability!==`available`)return`unavailable`;if(e.installMethod===`manual`||!this.deferredPrompt)return`manual`;this.deferredPrompt.prompt();let t=await this.deferredPrompt.userChoice;return this.deferredPrompt=null,t.outcome===`accepted`?(Io(),this.refreshState(),N.success(s(`pwaInstallAccepted`)),`accepted`):(this.dismissInstallPrompt(),this.refreshState(),`dismissed`)},this.handleBeforeInstallPrompt=e=>{e.preventDefault(),this.deferredPrompt=e,this.refreshState()},this.handleAppInstalled=()=>{this.deferredPrompt=null,Io(),Bo.setState({dismissedInstallPrompt:!0}),N.success(s(`pwaInstalledToast`)),this.refreshState()},this.handleDisplayModeChanged=()=>{this.refreshState()},this.resolveInstallability=()=>this.isDevelopmentServer()?{installability:`unsupported`,installMethod:`none`,blockedReason:`dev-server`}:this.hasDesktopHost()?{installability:`suppressed`,installMethod:`none`,blockedReason:`desktop-host`}:this.isStandalone()?{installability:`installed`,installMethod:`none`,blockedReason:null}:this.hasInstallSurfaceSupport()?this.isEligibleInstallContext()?{installability:`available`,installMethod:this.deferredPrompt?`prompt`:`manual`,blockedReason:null}:{installability:`unsupported`,installMethod:`none`,blockedReason:`insecure-context`}:{installability:`unsupported`,installMethod:`none`,blockedReason:`missing-browser-support`},this.hasDesktopHost=()=>typeof window<`u`&&!!window.nextclawDesktop,this.hasInstallSurfaceSupport=()=>typeof window<`u`&&typeof window.matchMedia==`function`&&`serviceWorker`in navigator,this.isEligibleInstallContext=()=>typeof window>`u`?!1:window.isSecureContext||this.isTrustedLocalhost(window.location.hostname),this.isTrustedLocalhost=e=>e===`localhost`||e===`127.0.0.1`||e===`::1`||e===`[::1]`,this.isDevelopmentServer=()=>typeof window<`u`&&!1,this.isStandalone=()=>{if(typeof window>`u`)return!1;let e=window.navigator;return typeof window.matchMedia==`function`&&window.matchMedia(`(display-mode: standalone)`).matches||e.standalone===!0},this.bindDisplayModeListener=(e,t)=>{if(`addEventListener`in e){e.addEventListener(`change`,t);return}e.addListener?.(t)},this.unbindDisplayModeListener=(e,t)=>{if(`removeEventListener`in e){e.removeEventListener(`change`,t);return}e.removeListener?.(t)}}};function Ho(){let e=Bo(e=>e.installability);return(0,I.jsx)(`span`,{className:r(`inline-flex items-center rounded-full border px-3 py-1 text-xs font-medium`,e===`installed`?`bg-emerald-50 text-emerald-700 border-emerald-200`:e===`available`?`bg-amber-50 text-amber-700 border-amber-200`:`bg-gray-100 text-gray-600 border-gray-200`),children:Uo(e)})}function Uo(e){return s(e===`available`?`pwaInstallStatusAvailable`:e===`installed`?`pwaInstallStatusInstalled`:e===`suppressed`?`pwaInstallStatusDesktopHost`:`pwaInstallStatusUnavailable`)}function Wo(e,t,n){return s(e===`installed`?`pwaInstallCardInstalled`:e===`suppressed`?`pwaInstallCardSuppressed`:e===`available`&&t===`prompt`?`pwaInstallCardPrompt`:e===`available`?`pwaInstallCardManual`:n===`insecure-context`?`pwaInstallCardInsecureContext`:n===`dev-server`?`pwaInstallCardDevServer`:`pwaInstallCardUnsupported`)}function Go(){let e=Bo(e=>e.installability),t=Bo(e=>e.installMethod),n=Bo(e=>e.blockedReason);return(0,I.jsxs)(_e,{children:[(0,I.jsxs)(ot,{className:`flex flex-row items-start justify-between gap-4 space-y-0`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(fe,{children:s(`pwaInstallTitle`)}),(0,I.jsx)(je,{children:s(`pwaInstallDescription`)})]}),(0,I.jsx)(Ho,{})]}),(0,I.jsxs)(ge,{className:`space-y-4`,children:[(0,I.jsx)(`div`,{className:`rounded-2xl border border-gray-200 bg-gray-50/90 p-4`,children:(0,I.jsx)(`p`,{className:`text-sm leading-6 text-gray-700`,children:Wo(e,t,n)})}),e===`available`&&t===`prompt`?(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,I.jsxs)(ye,{type:`button`,className:`gap-2`,onClick:()=>{Vo.promptInstall()},children:[(0,I.jsx)(Un,{className:`h-4 w-4`}),s(`pwaInstallAction`)]}),(0,I.jsx)(`p`,{className:`text-sm text-gray-500`,children:s(`pwaInstallPromptHint`)})]}):null,e===`available`&&t===`manual`?(0,I.jsxs)(`div`,{className:`flex items-start gap-3 rounded-2xl border border-dashed border-gray-300 bg-white p-4`,children:[(0,I.jsx)(yr,{className:`mt-0.5 h-4 w-4 text-gray-500`}),(0,I.jsx)(`p`,{className:`text-sm leading-6 text-gray-600`,children:s(`pwaInstallManualHint`)})]}):null]})]})}function Ko(){let e=Bo(e=>e.installability),t=Bo(e=>e.installMethod),n=Bo(e=>e.dismissedInstallPrompt);return e!==`available`||t!==`prompt`||n?null:(0,I.jsxs)(`div`,{className:`fixed bottom-5 right-5 z-50 w-[min(420px,calc(100vw-2rem))] rounded-[26px] border border-gray-200 bg-white/95 p-5 shadow-2xl backdrop-blur-xl`,children:[(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(`p`,{className:`text-sm font-semibold text-gray-900`,children:s(`pwaInstallBannerTitle`)}),(0,I.jsx)(`p`,{className:`text-sm leading-6 text-gray-600`,children:s(`pwaInstallBannerDescription`)})]}),(0,I.jsx)(`button`,{type:`button`,"aria-label":s(`pwaInstallDismiss`),className:`rounded-full p-1 text-gray-400 transition hover:bg-gray-100 hover:text-gray-600`,onClick:()=>{Vo.dismissInstallPrompt()},children:(0,I.jsx)(gn,{className:`h-4 w-4`})})]}),(0,I.jsxs)(`div`,{className:`mt-4 flex items-center gap-3`,children:[(0,I.jsxs)(ye,{type:`button`,size:`sm`,className:`gap-2`,onClick:()=>{Vo.promptInstall()},children:[(0,I.jsx)(Un,{className:`h-4 w-4`}),s(`pwaInstallAction`)]}),(0,I.jsx)(ye,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>{Vo.dismissInstallPrompt()},children:s(`pwaInstallDismiss`)})]})]})}var qo=new class{constructor(){this.started=!1,this.registration=null,this.start=async()=>{if(!(this.started||typeof window>`u`)&&(this.started=!0,!(!(`serviceWorker`in navigator)||!this.isEligibleInstallContext()))){if(this.isDevelopmentServer()){await this.cleanupDevelopmentRegistrations();return}try{this.registration=await navigator.serviceWorker.register(`/sw.js`)}catch{return}}},this.stop=()=>{!this.started||typeof window>`u`||!(`serviceWorker`in navigator)||(this.started=!1,this.registration=null)},this.isEligibleInstallContext=()=>window.isSecureContext||this.isTrustedLocalhost(window.location.hostname),this.isTrustedLocalhost=e=>e===`localhost`||e===`127.0.0.1`||e===`::1`||e===`[::1]`,this.isDevelopmentServer=()=>!1,this.cleanupDevelopmentRegistrations=async()=>{if(typeof navigator.serviceWorker.getRegistrations!=`function`)return;let e=(await navigator.serviceWorker.getRegistrations()).filter(e=>[e.active?.scriptURL,e.installing?.scriptURL,e.waiting?.scriptURL].filter(e=>!!e).some(e=>e.endsWith(`/sw.js`)));await Promise.all(e.map(async e=>await e.unregister())),e.length>0&&await this.clearNextClawCaches()},this.clearNextClawCaches=async()=>{if(typeof window>`u`||!(`caches`in window)||typeof caches.keys!=`function`)return;let e=await caches.keys();await Promise.all(e.filter(e=>e.startsWith(`nextclaw-ui-`)).map(async e=>await caches.delete(e)))}}},Jo=!1;function Yo(){Jo||typeof window>`u`||(Jo=!0,Vo.start(),qo.start())}var Xo={warm:`#F9F8F5`,cool:`#F8FAFB`},Zo=new class{constructor(){this.syncTheme=e=>{if(typeof document>`u`)return;let t=Xo[e];this.updateThemeMeta(t),this.updateSurfaceBackgrounds(t),document.documentElement.style.colorScheme=`light`},this.syncCurrentTheme=()=>{if(typeof document>`u`)return;let e=document.documentElement.getAttribute(`data-theme`)===`cool`?`cool`:`warm`;this.syncTheme(e)},this.updateThemeMeta=e=>{let t=document.querySelector(`meta[name="theme-color"]`);t instanceof HTMLMetaElement&&(t.content=e)},this.updateSurfaceBackgrounds=e=>{document.documentElement.style.backgroundColor=e,document.body.style.backgroundColor=e;let t=document.getElementById(`root`);t&&(t.style.backgroundColor=e)}}},Qo=(0,F.createContext)(null);function $o({children:e}){let[t,n]=(0,F.useState)(()=>ei());(0,F.useEffect)(()=>{Zo.syncTheme(t)},[t]),(0,F.useEffect)(()=>ri(e=>{n(e)}),[]);let r=(0,F.useCallback)(e=>{ni(e),n(ti())},[]),i=(0,F.useMemo)(()=>({theme:t,setTheme:r}),[t,r]);return(0,I.jsx)(Qo.Provider,{value:i,children:e})}function es(){let e=(0,F.useContext)(Qo);if(!e)throw Error(`useTheme must be used within ThemeProvider`);return e}function ts(){let{language:e,setLanguage:n}=kr();return{currentLanguage:e,currentLanguageLabel:t.find(t=>t.value===e)?.label??e,languageOptions:t,selectLanguage:(0,F.useCallback)(t=>{e!==t&&(n(t),window.location.reload())},[e,n])}}function ns(){let{currentLanguage:e,currentLanguageLabel:t,languageOptions:n,selectLanguage:i}=ts();return(0,I.jsxs)(`section`,{className:`mx-auto w-full max-w-3xl space-y-4`,children:[(0,I.jsx)(`div`,{className:`rounded-3xl border border-gray-200/80 bg-white p-5 shadow-card`,children:(0,I.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,I.jsx)(`div`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-2xl bg-gray-100 text-gray-600`,children:(0,I.jsx)(cr,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`h2`,{className:`text-base font-semibold text-gray-900`,children:s(`language`)}),(0,I.jsx)(`p`,{className:`mt-1 text-sm text-gray-500`,children:t})]})]})}),(0,I.jsx)(`div`,{className:`overflow-hidden rounded-3xl border border-gray-200/80 bg-white shadow-card`,children:n.map(t=>{let n=t.value===e;return(0,I.jsxs)(`button`,{type:`button`,onClick:()=>i(t.value),className:r(`flex w-full items-center justify-between gap-3 border-b border-gray-100 px-5 py-4 text-left text-sm transition-colors last:border-b-0`,n?`bg-gray-50 text-gray-900`:`text-gray-700 hover:bg-gray-50/70`),"aria-current":n?`true`:void 0,children:[(0,I.jsx)(`span`,{className:`font-medium`,children:t.label}),n?(0,I.jsx)(In,{className:`h-4 w-4 text-gray-700`}):null]},t.value)})})]})}function rs({mode:e}){let t=re(),n=Dn(),i=le(),{currentLanguage:a,currentLanguageLabel:o,languageOptions:c,selectLanguage:l}=ts(),{theme:u,setTheme:d}=es(),f=e===`settings`,p=s(qr.find(e=>e.value===u)?.labelKey??`themeWarm`),m=i.data?.account.email?.trim(),h=!!i.data?.account.loggedIn,g=e=>{u!==e&&d(e)},_=[{target:`/chat`,label:s(`chat`),icon:lr},{target:`/chat/cron`,label:s(`cron`),icon:jn},{target:`/chat/skills`,label:s(`marketplaceFilterSkills`),icon:E},{target:`/agents`,label:s(`agentsPageTitle`),icon:Pn}],v=Hr(s),y=f?v:_,b=f?`compact`:`default`;return(0,I.jsxs)(`aside`,{className:`w-[240px] shrink-0 flex h-full min-h-0 flex-col overflow-hidden bg-secondary px-4 pb-6`,children:[f?(0,I.jsx)(`div`,{className:`shrink-0 px-2 py-2.5`,children:(0,I.jsxs)(`div`,{className:`flex items-center gap-2 px-1 py-1`,"data-testid":`settings-sidebar-header`,children:[(0,I.jsxs)(w,{to:`/chat`,className:`group inline-flex min-w-0 items-center gap-1.5 rounded-lg px-1 py-1 text-[12px] font-medium text-gray-500 transition-colors hover:bg-gray-200/60 hover:text-gray-900`,children:[(0,I.jsx)(Xt,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 group-hover:text-gray-700`}),(0,I.jsx)(`span`,{className:`truncate`,children:s(`backToMain`)})]}),(0,I.jsx)(`span`,{className:`h-4 w-px shrink-0 bg-[#dddfe6]`,"aria-hidden":`true`}),(0,I.jsx)(`h1`,{className:`truncate text-[15px] font-semibold tracking-[-0.01em] text-gray-800`,children:s(`settings`)})]})}):(0,I.jsx)(`div`,{className:`shrink-0 px-2 py-2.5`,children:(0,I.jsx)(ji,{className:`flex items-center gap-2.5 cursor-pointer`})}),(0,I.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,I.jsx)(`nav`,{className:`custom-scrollbar min-h-0 flex-1 overflow-y-auto pr-1`,children:(0,I.jsx)(`ul`,{className:r(f?`space-y-0.5 pb-3`:`space-y-1 pb-4`),children:y.map(e=>(0,I.jsx)(`li`,{children:(0,I.jsx)(ko,{to:e.target,label:e.label,icon:e.icon,density:b})},e.target))})}),(0,I.jsxs)(`div`,{className:r(`shrink-0 border-t border-[#dde0ea] bg-secondary`,f?`mt-2 pt-3`:`mt-3 pt-3`),children:[f?(0,I.jsx)(Ao,{onClick:()=>t.accountManager.openAccountPanel(),icon:fn,label:s(`remoteAccountEntryManage`),density:`compact`,className:`mb-1.5`,trailing:h?m||s(`remoteAccountEntryConnected`):s(`remoteAccountEntryDisconnected`),trailingClassName:`max-w-[92px] truncate text-right`,testId:`settings-sidebar-account-entry`,trailingTestId:`settings-sidebar-account-status`}):null,e===`main`&&(0,I.jsx)(`div`,{className:`mb-2`,children:(0,I.jsx)(ko,{to:`/settings`,label:s(`settings`),icon:_r})}),(0,I.jsx)(`div`,{className:`mb-2`,children:(0,I.jsx)(jo,{value:u,onValueChange:e=>g(e),icon:pr,label:s(`theme`),valueLabel:p,density:b,children:qr.map(e=>(0,I.jsx)(To,{value:e.value,className:`text-xs`,children:s(e.labelKey)},e.value))})}),(0,I.jsx)(`div`,{className:`mb-2`,children:(0,I.jsx)(jo,{value:a,onValueChange:e=>l(e),icon:cr,label:s(`language`),valueLabel:o,density:b,children:c.map(e=>(0,I.jsx)(To,{value:e.value,className:`text-xs`,children:e.label},e.value))})}),(0,I.jsx)(Ao,{onClick:()=>n.open(void 0,{kind:`docs`,title:s(`docBrowserHelp`)}),icon:Qt,label:s(`docBrowserHelp`),density:b})]})]})]})}var is=[{action:`minimize`,label:`Minimize`,icon:fr},{action:`close`,label:`Close`,icon:gn,variant:`danger`}];function as(){let e=ss()?{action:`toggle-maximize`,label:`Restore`,icon:Vn}:{action:`toggle-maximize`,label:`Maximize`,icon:xr};return(0,I.jsxs)(`header`,{className:`desktop-window-drag relative flex h-[var(--desktop-titlebar-height)] shrink-0 bg-secondary after:absolute after:bottom-0 after:left-[var(--desktop-sidebar-width)] after:right-0 after:border-b after:border-[#ebe7dc]/80`,"data-testid":`desktop-window-chrome`,children:[(0,I.jsx)(`div`,{className:`desktop-window-no-drag absolute left-0 right-0 top-0 h-1`,"data-testid":`desktop-window-chrome-resize-strip`}),(0,I.jsx)(`div`,{className:`desktop-window-drag relative z-10 flex h-full w-[var(--desktop-sidebar-width)] shrink-0 items-center bg-secondary pl-4 pr-3 text-secondary-foreground`,"data-testid":`desktop-window-chrome-sidebar`,children:(0,I.jsx)(ji,{className:`flex min-w-0 shrink-0 items-center gap-2.5`,density:`chrome`})}),(0,I.jsx)(`div`,{className:`desktop-window-no-drag absolute right-0 top-0 z-20 flex h-full w-[var(--desktop-caption-safe-right)] items-start justify-end`,"data-testid":`desktop-window-controls`,children:[is[0],e,is[1]].map(e=>(0,I.jsx)(os,{control:e},e.action))})]})}function os({control:e}){let t=e.icon;return(0,I.jsx)(`button`,{type:`button`,"aria-label":e.label,title:e.label,className:e.variant===`danger`?`desktop-window-no-drag flex h-10 w-[46px] items-center justify-center text-gray-700 transition-colors hover:bg-red-500 hover:text-white`:`desktop-window-no-drag flex h-10 w-[46px] items-center justify-center text-gray-700 transition-colors hover:bg-black/10`,onClick:()=>{window.nextclawDesktop?.controlWindow?.(e.action)},children:(0,I.jsx)(t,{className:`h-3.5 w-3.5`})})}function ss(){let[e,t]=(0,F.useState)(!1);return(0,F.useEffect)(()=>{let e=!0,n=window.nextclawDesktop;n?.getWindowState?.().then(n=>{e&&t(n.isMaximized)});let r=n?.onWindowStateChanged?.(e=>{t(e.isMaximized)});return()=>{e=!1,r?.()}},[]),e}function cs(){return typeof window>`u`?null:us()??window.nextclawDesktop?.platform??null}function ls(){return cs()===`win32`}function us(){return null}function ds(e,t){if(t===`/settings`)return Wr(e);let n=e.toLowerCase(),r=t.toLowerCase();return n===r||n.startsWith(`${r}/`)}function fs(){let{pathname:e}=S(),t=Vr(s);return(0,I.jsx)(`nav`,{"data-testid":`mobile-bottom-nav`,"aria-label":s(`settings`),className:`shrink-0 border-t border-gray-200/80 bg-white/95 backdrop-blur-sm`,style:{paddingBottom:`calc(env(safe-area-inset-bottom, 0px) + 0.25rem)`},children:(0,I.jsx)(`ul`,{className:`grid grid-cols-4 gap-1 px-2 pt-1`,children:t.map(t=>{let n=ds(e,t.target);return(0,I.jsx)(`li`,{children:(0,I.jsx)(v,{to:t.target,"aria-current":n?`page`:void 0,className:r(`group flex min-h-[2.875rem] items-center justify-center rounded-xl px-1 py-1 text-[10px] font-medium transition-colors`,n?`text-gray-900`:`text-gray-500 hover:text-gray-800`),children:(0,I.jsxs)(`span`,{"data-testid":n?`mobile-nav-active-indicator`:void 0,className:r(`inline-flex max-w-full min-w-14 flex-col items-center justify-center gap-0.5 rounded-xl px-2 py-1 transition-colors`,n?`bg-gray-100`:`bg-transparent group-hover:bg-gray-50`),children:[(0,I.jsx)(t.icon,{className:r(`h-3.5 w-3.5`,n?`text-gray-900`:`text-gray-400`)}),(0,I.jsx)(`span`,{className:`max-w-full truncate`,children:t.label})]})})},t.target)})})})}function ps({leadingInset:e}){let t=C(),{pathname:n}=S(),r=Gr(n,s);return(0,I.jsx)(`header`,{"data-testid":`mobile-topbar`,className:`shrink-0 border-b border-gray-200/80 bg-white/95 backdrop-blur-sm`,style:{paddingTop:`calc(env(safe-area-inset-top, 0px) + 0.25rem)`},children:(0,I.jsxs)(`div`,{className:`flex min-h-[2.75rem] items-center gap-2 py-1.5 pl-3 pr-3`,style:{paddingLeft:e?`calc(${e} + 0.75rem)`:void 0},children:[r.backTarget?(0,I.jsx)(`button`,{type:`button`,onClick:()=>t(r.backTarget),className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-gray-200 text-gray-600 transition-colors hover:bg-gray-50 hover:text-gray-900`,"aria-label":r.backLabel??s(`backToMain`),children:(0,I.jsx)(Xt,{className:`h-4 w-4`})}):null,(0,I.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,I.jsx)(`h1`,{className:`truncate text-center text-[15px] font-semibold text-gray-900`,children:r.title})}),r.backTarget?(0,I.jsx)(`div`,{className:`h-8 w-8 shrink-0`,"aria-hidden":`true`}):null]})})}var ms=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{DocBrowser:e}=await import(`./doc-browser-D5FJcAyz.js`);return{DocBrowser:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11]))).DocBrowser}));function hs({pathname:e,isDocBrowserOpen:t,docBrowserDockControls:n,docBrowserRenderers:r={},topbarLeadingInset:i,children:a}){let o=zr(e),s=!Br(e),c=!Br(e);return(0,I.jsxs)(`div`,{className:`flex h-[100svh] flex-col bg-background font-sans text-foreground supports-[height:100dvh]:h-[100dvh]`,children:[s?(0,I.jsx)(ps,{leadingInset:i}):null,(0,I.jsx)(`div`,{className:`relative flex-1 min-h-0 overflow-hidden`,children:o?(0,I.jsx)(`div`,{className:`h-full min-h-0 overflow-hidden`,children:a}):(0,I.jsx)(`main`,{className:`h-full overflow-auto px-4 py-4 custom-scrollbar`,children:(0,I.jsx)(`div`,{className:`mx-auto max-w-3xl animate-fade-in`,children:a})})}),c?(0,I.jsx)(fs,{}):null,t?(0,I.jsx)(F.Suspense,{fallback:null,children:(0,I.jsx)(ms,{customTabRenderers:r,displayMode:`fullscreen`,dockControls:n})}):null]})}function gs(){let e=Ur(s);return(0,I.jsx)(`div`,{"data-testid":`mobile-settings-shell`,className:`space-y-3 pb-4`,children:e.map(e=>(0,I.jsxs)(w,{to:e.target,className:({isActive:e})=>r(`flex items-center gap-3 rounded-2xl border border-gray-200/80 bg-white px-4 py-4 shadow-card transition-colors`,e?`border-gray-300 bg-gray-50`:`hover:border-gray-300 hover:bg-gray-50/70`),children:[(0,I.jsx)(`div`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-2xl bg-gray-100 text-gray-600`,children:(0,I.jsx)(e.icon,{className:`h-4 w-4`})}),(0,I.jsx)(`div`,{className:`min-w-0`,children:(0,I.jsx)(`p`,{className:`truncate text-sm font-semibold text-gray-900`,children:e.label})})]},e.target))})}function _s({isProjectFirstView:e,onSelectMode:t}){return(0,I.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,children:[(0,I.jsx)(`button`,{type:`button`,"aria-pressed":!e,onClick:()=>t(`time-first`),className:r(`transition-colors`,e?`text-gray-400 hover:text-gray-600`:`font-medium text-gray-600`),children:s(`chatSidebarViewTime`)}),(0,I.jsx)(`span`,{className:`text-gray-300`,children:`/`}),(0,I.jsx)(`button`,{type:`button`,"aria-pressed":e,onClick:()=>t(`project-first`),className:r(`transition-colors`,e?`font-medium text-gray-600`:`text-gray-400 hover:text-gray-600`),children:s(`chatSidebarViewProject`)})]})}var vs={telegram:`telegram.svg`,slack:`slack.svg`,discord:`discord.svg`,whatsapp:`whatsapp.svg`,qq:`qq.svg`,feishu:`feishu.svg`,dingtalk:`dingtalk.svg`,wecom:`wecom.svg`,weixin:`weixin.svg`,email:`email.svg`};function ys(e,t){let n=e[t.toLowerCase()];return n?`/logos/${n}`:null}function bs(e){return ys(vs,e)}var xs={wx:`weixin`,lark:`feishu`},Ss={cron:{icon:`cron`}},Cs={codex:`chatSessionTypeCodex`,claude:`chatSessionTypeClaude`};function ws(e){return e?.trim().toLowerCase()??``}function Ts(e){return e.split(/[-_]+/g).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Es(e,t){let n=ws(e);if(!n||n===`native`)return null;let r=t.find(e=>ws(e.value)===n);return r?.label.trim()?r.label.trim():Ts(n)}function Ds(e,t){let n=ws(e);return!n||n===`native`?null:t.find(e=>ws(e.value)===n)??null}function Os(e){let t=ws(e);if(!t)return null;let n=xs[t]??t;return bs(n)?n:null}function ks(e,t){let n=Os(e.channel??``);if(n)return{icon:{kind:`channel-logo`,channel:n},label:null};let r=Ss[ws(e.type)];if(r)return{icon:{kind:`symbol`,icon:r.icon},label:null};let i=ws(e.sessionType),a=Ds(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 o=Cs[i];return o?{icon:null,label:s(o)}:{icon:null,label:a?.label?.trim()||Es(e.sessionType,t)}}var As=`app://`;function js(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 Ms(e){let t=e.trim();if(!t)return null;if(!t.startsWith(As))return t;let n=js(t.slice(6));return n?`/${n}`:null}function Ns({name:e,src:t,className:n,imgClassName:i,fallback:a}){let[o,s]=(0,F.useState)(!1),c=!!t&&!o;return(0,I.jsx)(`div`,{className:r(`inline-flex shrink-0 items-center justify-center overflow-hidden`,n),children:c?(0,I.jsx)(`img`,{src:t,alt:`${e} logo`,className:r(`block h-6 w-6 object-contain`,i),onError:()=>s(!0),draggable:!1}):a??(0,I.jsx)(`span`,{className:`text-lg font-bold uppercase`,children:e.slice(0,1)})})}function Ps({icon:e,className:t}){if(e.kind===`channel-logo`)return(0,I.jsx)(Fs,{channel:e.channel,className:t});if(e.kind===`runtime-image`){let n=Ms(e.src);return(0,I.jsx)(Ns,{name:e.name?.trim()||e.alt?.trim()||`runtime`,src:n??void 0,className:r(`h-[1.125rem] w-[1.125rem]`,t),imgClassName:`h-full w-full object-contain`,fallback:(0,I.jsx)(Pn,{className:r(`h-3 w-3 text-gray-500`,t)})})}return(0,I.jsx)(jn,{className:r(`h-3.5 w-3.5`,t)})}function Fs({channel:e,className:t}){return(0,I.jsx)(Ns,{name:e,src:bs(e),className:r(`h-[1.125rem] w-[1.125rem]`,t),imgClassName:`h-full w-full object-contain`,fallback:(0,I.jsx)(Pn,{className:`h-3 w-3 text-gray-500`})})}function Is(e){let{option:t,onSelect:n}=e,i=t.ready===!1?t.reasonMessage?.trim()||s(`statusSetup`):null;return(0,I.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,I.jsx)(`div`,{className:`flex items-start gap-3`,children:(0,I.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-2.5`,children:[t.icon?.src?(0,I.jsx)(`span`,{className:`inline-flex h-5 w-5 shrink-0 items-center justify-center pt-0.5`,children:(0,I.jsx)(Ps,{icon:{kind:`runtime-image`,src:t.icon.src,alt:t.icon.alt??null,name:t.label}})}):(0,I.jsx)(`span`,{className:`inline-flex h-5 w-5 shrink-0 items-center justify-center pt-0.5 text-gray-400`,children:(0,I.jsx)(Pn,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,I.jsx)(`div`,{className:`truncate text-[13px] font-semibold text-gray-900`,children:t.label}),(0,I.jsxs)(`span`,{className:r(`inline-flex shrink-0 items-center gap-1.5 text-[11px] font-medium`,t.ready===!1?`text-amber-700`:`text-emerald-600`),children:[(0,I.jsx)(`span`,{className:r(`h-1.5 w-1.5 rounded-full`,t.ready===!1?`bg-amber-500`:`bg-emerald-500`)}),t.ready===!1?s(`statusSetup`):s(`statusReady`)]})]}),i?(0,I.jsx)(`div`,{className:`mt-1 pr-4 text-[11px] leading-4 text-gray-500`,children:i}):null]})]})})})}function Ls(e,t){return t.some(t=>t.value===e)?e:t[0]?.value??e}function Rs(e){let{groups:t,defaultSessionType:n,sessionTypeOptions:r,renderSessionItem:i,onCreateSession:a}=e,[o,c]=(0,F.useState)(null),l=(0,F.useMemo)(()=>Ls(n,r),[n,r]),u=r.length>1;return(0,I.jsx)(`div`,{className:`space-y-3`,children:t.map(e=>{let t=`${s(`chatSidebarNewTask`)} · ${e.projectName}`;return(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-2 py-0.5`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,I.jsx)(`div`,{className:`truncate text-[11px] font-medium uppercase tracking-wider text-gray-500`,title:e.projectRoot,children:e.projectName}),(0,I.jsx)(`span`,{className:`shrink-0 text-[10px] text-gray-400`,children:e.items.length})]}),u?(0,I.jsxs)(wn,{open:o===e.projectRoot,onOpenChange:t=>{c(t?e.projectRoot:null)},children:[(0,I.jsx)(Sn,{asChild:!0,children:(0,I.jsx)(ye,{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,I.jsx)(pn,{className:`h-3.5 w-3.5`})})}),(0,I.jsxs)(bn,{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,I.jsx)(`div`,{className:`px-3 pb-1 pt-2 text-[10px] font-semibold uppercase tracking-[0.18em] text-gray-400`,children:s(`chatSessionTypeLabel`)}),(0,I.jsx)(`div`,{className:`space-y-1`,children:r.map(t=>(0,I.jsx)(Is,{option:t,onSelect:()=>{a(t.value,e.projectRoot),c(null)}},`${e.projectRoot}:${t.value}`))})]})]}):(0,I.jsx)(ye,{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,I.jsx)(pn,{className:`h-3.5 w-3.5`})})]}),(0,I.jsx)(`div`,{className:`space-y-0.5 pl-2`,children:e.items.map(i)})]},e.projectRoot)})})}var zs=[[`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 Bs(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 Vs({agentId:e,displayName:t,avatarUrl:n,className:i}){let a=t?.trim()||e,[o,s]=zs[Bs(e)%zs.length]??zs[0];return n?.trim()?(0,I.jsx)(`img`,{src:n,alt:t?.trim()||e,className:r(`rounded-full object-cover`,i)}):(0,I.jsx)(`div`,{className:r(`rounded-full flex items-center justify-center font-semibold`,o,s,i),"aria-label":t?.trim()||e,children:e.trim().toLowerCase()===`main`?(0,I.jsx)(Pn,{className:`h-[55%] w-[55%]`,strokeWidth:2.4}):(a.trim()||`A`).slice(0,1).toUpperCase()})}function Hs({status:e,className:t}){let n=s(e===`running`?`sessionsRunStatusRunning`:`sessionsRunStatusQueued`);return(0,I.jsxs)(`span`,{className:r(`inline-flex h-3.5 w-3.5 items-center justify-center text-gray-400`,t),title:n,"aria-label":n,children:[(0,I.jsx)($t,{className:`h-3 w-3 animate-spin`}),(0,I.jsx)(`span`,{className:`sr-only`,children:n})]})}function Us(e){let t=e.label?.trim();if(t)return t;let n=e.key.split(`:`);return n[n.length-1]||e.key}function Ws(e){let t=e.activityPreview;return t?t.state===`failed`||t.state===`running`?t.statusText??t.replyText??null:t.state===`completed`?t.replyText??t.statusText??null:t.statusText??t.replyText??null:null}function Gs(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime()}function Ks(e,t){return e.getFullYear()===t.getFullYear()}function qs(e,t){let n=`${e.getMonth()+1}月${e.getDate()}日`;return Ks(e,t)?n:`${e.getFullYear()}年${n}`}function Js(e,t=d(),n=new Date){if(!e)return`-`;let r=e instanceof Date?e:new Date(e);if(Number.isNaN(r.getTime()))return typeof e==`string`?e:`-`;let i=p(t),a=Gs(r),o=Gs(n),c=Math.floor((o-a)/864e5);if(c===0)return new Intl.DateTimeFormat(i,{hour:`2-digit`,minute:`2-digit`,hour12:!1}).format(r);if(c===1)return s(`chatSidebarYesterday`,t);if(c>1&&c<7)return new Intl.DateTimeFormat(i,{weekday:`long`}).format(r);if(t===`zh`)return qs(r,n);let l=Ks(r,n)?{month:`numeric`,day:`numeric`}:{year:`numeric`,month:`numeric`,day:`numeric`};return new Intl.DateTimeFormat(i,l).format(r)}function Ys(e){return e.trim().toLowerCase()}function Xs(e,t){let n=Ys(t);return n?[e.key,Us(e),e.projectRoot??``,e.projectName??``].map(Ys).some(e=>e.includes(n)):!0}function Zs({session:e,draftLabel:t,isSaving:n,onDraftLabelChange:r,onSave:i,onCancel:a}){return(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(Ne,{value:t,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),i()):e.key===`Escape`&&(e.preventDefault(),a())},placeholder:s(`sessionsLabelPlaceholder`),className:`h-8 rounded-lg border-gray-300 bg-white text-xs`,autoFocus:!0,disabled:n}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,I.jsx)(`div`,{className:`min-w-0 text-[11px] text-gray-400 truncate`,children:e.key}),(0,I.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,I.jsx)(ye,{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":s(`save`),children:(0,I.jsx)(In,{className:`h-3.5 w-3.5`})}),(0,I.jsx)(ye,{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":s(`cancel`),children:(0,I.jsx)(gn,{className:`h-3.5 w-3.5`})})]})]})]})}function Qs({session:e,active:t,showUnreadDot:n,runStatus:i,context:a,title:o,agentId:c,agentLabel:l,agentAvatarUrl:u,childSessionCount:d=0,onSelect:f,onOpenChildSessions:p,onStartEditing:m}){let h=d>0&&p?`pr-14`:`pr-6`,g=Ws(e),_=`${l?.trim()?`${l} · `:``}${e.messageCount}`;return(0,I.jsxs)(`div`,{className:`group/session relative`,children:[(0,I.jsxs)(`button`,{type:`button`,onClick:f,className:`w-full text-left`,children:[(0,I.jsx)(`div`,{className:r(`flex min-w-0 items-start`,h),children:(0,I.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[c?.trim()&&c.trim().toLowerCase()!==`main`?(0,I.jsx)(Vs,{agentId:c,displayName:l,avatarUrl:u,className:`h-5 w-5 shrink-0`}):null,(0,I.jsx)(`span`,{className:`truncate font-medium`,children:o}),a.label?(0,I.jsx)(`span`,{className:r(`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:a.label}):null,a.icon?(0,I.jsx)(`span`,{className:`inline-flex h-[1.125rem] w-[1.125rem] shrink-0 items-center justify-center`,children:(0,I.jsx)(Ps,{icon:a.icon,className:t?`text-gray-700`:`text-gray-500`})}):null]})}),(0,I.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-[11px] text-gray-400`,children:[(0,I.jsx)(`span`,{className:`min-w-0 truncate`,children:g??_}),n?(0,I.jsx)(`span`,{"aria-label":s(`chatSessionUnread`),className:`ml-auto h-2 w-2 shrink-0 rounded-full bg-primary`}):(0,I.jsx)(`span`,{className:`ml-auto shrink-0`,children:Js(e.lastMessageAt??e.createdAt)})]})]}),d>0&&p?(0,I.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),p()},className:r(`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":s(`chatSessionOpenChildSessions`),title:s(`chatSessionOpenChildSessions`),children:[(0,I.jsx)(ar,{className:`h-3.5 w-3.5`}),(0,I.jsx)(`span`,{children:d})]}):null,i?(0,I.jsx)(`span`,{className:`absolute right-0 top-0 inline-flex h-5 w-5 items-center justify-center transition-opacity group-hover/session:opacity-0 group-focus-within/session:opacity-0`,children:(0,I.jsx)(Hs,{status:i})}):null,(0,I.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),m()},className:r(`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`,`opacity-0 group-hover/session:opacity-100 group-focus-within/session:opacity-100`),"aria-label":s(`edit`),children:(0,I.jsx)(hr,{className:`h-3 w-3`})})]})}function $s({session:e,active:t,showUnreadDot:n,runStatus:i,context:a,title:o,agentId:s,agentLabel:c,agentAvatarUrl:l,childSessionCount:u,isEditing:d,draftLabel:f,isSaving:p,onSelect:m,onOpenChildSessions:h,onStartEditing:g,onDraftLabelChange:_,onSave:v,onCancel:y}){return(0,I.jsx)(`div`,{className:r(`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:d?(0,I.jsx)(Zs,{session:e,draftLabel:f,isSaving:p,onDraftLabelChange:_,onSave:v,onCancel:y}):(0,I.jsx)(Qs,{session:e,active:t,showUnreadDot:n,runStatus:i,context:a,title:o,agentId:s,agentLabel:c,agentAvatarUrl:l,onSelect:m,childSessionCount:u,onOpenChildSessions:h,onStartEditing:g})})}var ec=[{icon:lr,titleKey:`chatWelcomeCapability1Title`,descKey:`chatWelcomeCapability1Desc`},{icon:E,titleKey:`chatWelcomeCapability2Title`,descKey:`chatWelcomeCapability2Desc`},{icon:jn,titleKey:`chatWelcomeCapability3Title`,descKey:`chatWelcomeCapability3Desc`}];function tc({onCreateSession:e,agents:t,selectedAgentId:n,onSelectAgent:r}){let i=t.find(e=>e.id===n)??null;return(0,I.jsx)(`div`,{className:`min-h-full flex items-center justify-center px-4 py-6 sm:p-8`,children:(0,I.jsxs)(`div`,{className:`max-w-lg w-full min-w-0 text-center`,children:[(0,I.jsx)(`div`,{className:`mx-auto mb-6 h-16 w-16 rounded-2xl bg-primary/10 flex items-center justify-center`,children:(0,I.jsx)(Pn,{className:`h-8 w-8 text-primary`})}),(0,I.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 mb-2`,children:s(`chatWelcomeTitle`)}),(0,I.jsx)(`p`,{className:`text-sm text-gray-500 mb-8`,children:s(`chatWelcomeSubtitle`)}),(0,I.jsxs)(`div`,{className:`mb-6 flex items-center justify-center gap-2.5`,children:[(0,I.jsx)(`span`,{className:`text-[13px] font-medium text-gray-500`,children:s(`chatDraftAgentTitle`)}),(0,I.jsxs)(vo,{value:n,onValueChange:r,children:[(0,I.jsxs)(bo,{"aria-label":s(`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,I.jsx)(`span`,{className:`sr-only`,children:s(`chatDraftAgentTitle`)}),(0,I.jsx)(`div`,{className:`flex items-center gap-1.5`,children:i?(0,I.jsx)(Vs,{agentId:i.id,displayName:i.displayName,avatarUrl:i.avatarUrl,className:`h-7 w-7 shrink-0`}):null})]}),(0,I.jsx)(Co,{className:`rounded-xl border-gray-200/80 shadow-lg`,children:t.map(e=>(0,I.jsx)(To,{value:e.id,className:`rounded-lg pr-10`,children:(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,I.jsx)(Vs,{agentId:e.id,displayName:e.displayName,avatarUrl:e.avatarUrl,className:`h-5 w-5 shrink-0`}),(0,I.jsx)(`span`,{className:`truncate text-sm font-medium text-gray-700`,children:e.displayName?.trim()||e.id})]})},e.id))})]})]}),(0,I.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(min(100%,9.5rem),1fr))] gap-3`,children:ec.map(t=>{let n=t.icon;return(0,I.jsxs)(`button`,{onClick:e,className:`min-w-0 rounded-2xl border border-gray-200 bg-white p-3 text-left shadow-card hover:shadow-card-hover transition-shadow cursor-pointer sm:p-4`,children:[(0,I.jsx)(`div`,{className:`h-9 w-9 rounded-xl bg-primary/8 flex items-center justify-center mb-3`,children:(0,I.jsx)(n,{className:`h-4.5 w-4.5 text-primary`})}),(0,I.jsx)(`div`,{className:`text-sm font-semibold text-gray-900 mb-1`,children:s(t.titleKey)}),(0,I.jsx)(`div`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:s(t.descKey)})]},t.titleKey)})})]})})}var nc=(0,F.createContext)(null);function rc({presenter:e,children:t}){return(0,I.jsx)(nc.Provider,{value:e,children:t})}function ic(){let e=(0,F.useContext)(nc);if(!e)throw Error(`usePresenter must be used inside ChatPresenterProvider`);return e}var ac=e=>`[data-item-index="${e}"]`;function oc(e){let{activeIndex:t,containerRef:n,getItemSelector:r,isEnabled:i,itemCount:a}=e,o=r??ac;(0,F.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 sc(){let e=(0,F.useRef)(null),[t,n]=(0,F.useState)(null);return(0,F.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 L(...e){return i(f(e))}var cc=F.forwardRef(({className:e,type:t,...n},r)=>(0,I.jsx)(`input`,{type:t,className:L(`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}));cc.displayName=`ChatInput`;var lc=Cn,uc=vn,dc=yn,fc=F.forwardRef(({className:e,sideOffset:t=8,align:n=`start`,...r},i)=>(0,I.jsx)(xn,{children:(0,I.jsx)(_n,{ref:i,sideOffset:t,align:n,className:L(`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})}));fc.displayName=_n.displayName;var pc=no,mc=lo,hc=io,gc=F.forwardRef(({className:e,children:t,...n},r)=>(0,I.jsxs)(ro,{ref:r,className:L(`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,I.jsx)(ao,{asChild:!0,children:(0,I.jsx)(Ln,{className:`h-4 w-4 opacity-50`})})]}));gc.displayName=ro.displayName;var _c=F.forwardRef(({className:e,...t},n)=>(0,I.jsx)(ho,{ref:n,className:L(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(zn,{className:`h-4 w-4`})}));_c.displayName=ho.displayName;var vc=F.forwardRef(({className:e,...t},n)=>(0,I.jsx)(go,{ref:n,className:L(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(Ln,{className:`h-4 w-4`})}));vc.displayName=go.displayName;var yc=F.forwardRef(({className:e,children:t,position:n=`popper`,...r},i)=>(0,I.jsx)(oo,{children:(0,I.jsxs)(so,{ref:i,className:L(`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,I.jsx)(_c,{}),(0,I.jsx)(co,{className:L(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]`),children:t}),(0,I.jsx)(vc,{})]})}));yc.displayName=so.displayName;var bc=F.forwardRef(({className:e,...t},n)=>(0,I.jsx)(uo,{ref:n,className:L(`px-2 py-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500`,e),...t}));bc.displayName=uo.displayName;var xc=F.forwardRef(({className:e,children:t,...n},r)=>(0,I.jsxs)(fo,{ref:r,className:L(`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,I.jsx)(`span`,{className:`absolute right-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,I.jsx)(mo,{children:(0,I.jsx)(In,{className:`h-4 w-4`})})}),(0,I.jsx)(po,{children:t})]}));xc.displayName=fo.displayName;var Sc=F.forwardRef(({className:e,...t},n)=>(0,I.jsx)(_o,{ref:n,className:L(`-mx-1 my-1 h-px bg-gray-100`,e),...t}));Sc.displayName=_o.displayName;var Cc=cn,wc=tn,Tc=rn,Ec=F.forwardRef(({className:e,sideOffset:t=4,...n},r)=>(0,I.jsx)(on,{children:(0,I.jsx)(en,{ref:r,sideOffset:t,className:L(`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})}));Ec.displayName=en.displayName;var Dc={Popover:lc,PopoverAnchor:dc,PopoverContent:fc,PopoverTrigger:uc,Input:cc,Select:pc,SelectContent:yc,SelectGroup:mc,SelectItem:xc,SelectLabel:bc,SelectSeparator:Sc,SelectTrigger:gc,SelectValue:hc,Tooltip:wc,TooltipContent:Ec,TooltipProvider:Cc,TooltipTrigger:Tc},Oc=680,kc=.82,Ac=560;function jc(e){let{Popover:t,PopoverAnchor:n,PopoverContent:r}=Dc,{elementRef:i,width:a}=sc(),o=(0,F.useRef)(null),{isOpen:s,isLoading:c,items:l,activeIndex:u,activeItem:d,texts:f,onSelectItem:p,onOpenChange:m,onDetailsPointerDown:h,onSetActiveIndex:g}=e,_=(0,F.useMemo)(()=>{if(a)return Math.min(a>Ac?a*kc:a,Oc)},[a]);return oc({containerRef:o,activeIndex:u,itemCount:l.length,isEnabled:s&&!c,getItemSelector:e=>`[data-slash-index="${e}"]`}),(0,I.jsxs)(t,{open:s,onOpenChange:m,children:[(0,I.jsx)(n,{asChild:!0,children:(0,I.jsx)(`div`,{ref:i,className:`pointer-events-none absolute bottom-full left-3 right-3 h-0`})}),(0,I.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:_?{width:`${_}px`}:void 0,children:(0,I.jsxs)(`div`,{className:`grid min-h-[240px] grid-cols-[minmax(220px,300px)_minmax(0,1fr)]`,children:[(0,I.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,I.jsx)(`div`,{className:`p-2 text-xs text-gray-500`,children:f.slashLoadingLabel}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`mb-2 px-2 text-[11px] font-semibold uppercase tracking-wide text-gray-500`,children:f.slashSectionLabel}),l.length===0?(0,I.jsx)(`div`,{className:`px-2 text-xs text-gray-400`,children:f.slashEmptyLabel}):(0,I.jsx)(`div`,{className:`space-y-1`,children:l.map((e,t)=>{let n=t===u;return(0,I.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":n,"data-slash-index":t,onMouseEnter:()=>g(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,I.jsx)(`span`,{className:`truncate text-xs font-semibold`,children:e.title}),(0,I.jsx)(`span`,{className:`truncate text-xs text-gray-500`,children:e.subtitle})]},e.key)})})]})}),(0,I.jsx)(`div`,{className:`min-w-0 p-2.5`,onPointerDown:h,children:d?(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.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,I.jsx)(`span`,{className:`text-sm font-semibold text-gray-900`,children:d.title})]}),(0,I.jsx)(`p`,{className:`text-xs leading-5 text-gray-600`,children:d.description}),(0,I.jsx)(`div`,{className:`space-y-1`,children:d.detailLines.map(e=>(0,I.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,I.jsx)(`div`,{className:`pt-1 text-[11px] text-gray-500`,children:f.slashSkillHintLabel})]}):(0,I.jsx)(`div`,{className:`text-xs text-gray-500`,children:f.slashHintLabel})})]})})]})}var Mc=Ce(`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`}}),Nc=F.forwardRef(({className:e,variant:t,size:n,...r},i)=>(0,I.jsx)(`button`,{className:L(Mc({variant:t,size:n,className:e})),ref:i,...r}));Nc.displayName=`ChatButton`;var Pc=120;function Fc(e){let t=e.replace(/\s+/g,` `).trim();return t.length<=Pc?t:`${t.slice(0,Pc-1)}…`}function Ic(){return(0,I.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 Lc({contextWindow:e}){let{Tooltip:t,TooltipContent:n,TooltipProvider:r,TooltipTrigger:i}=Dc,a=Math.max(0,Math.min(1,e.ratio)),o=Math.round(a*360);return(0,I.jsx)(r,{delayDuration:0,children:(0,I.jsxs)(t,{children:[(0,I.jsx)(i,{asChild:!0,children:(0,I.jsxs)(`button`,{type:`button`,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-700`,"aria-label":e.label,title:e.label,children:[(0,I.jsx)(`span`,{"aria-hidden":`true`,className:`absolute inset-[7px] rounded-full`,style:{background:`conic-gradient(#9ca3af ${o}deg, #e5e7eb 0deg)`}}),(0,I.jsx)(`span`,{"aria-hidden":`true`,className:`absolute inset-[10px] rounded-full bg-white`})]})}),(0,I.jsx)(n,{side:`top`,className:`max-w-[18rem]`,children:(0,I.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-5 font-semibold text-gray-800`,children:[(0,I.jsx)(`span`,{children:e.label}),(0,I.jsx)(`span`,{children:e.percentLabel})]}),e.details.map(e=>(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-5 text-gray-600`,children:[(0,I.jsx)(`span`,{children:e.label}),(0,I.jsx)(`span`,{className:`font-medium text-gray-800`,children:e.value})]},e.label))]})})]})})}function Rc({sendError:e,sendErrorDetailsLabel:t,isSending:n,canStopGeneration:r,sendDisabled:i,stopDisabled:a,stopHint:o,sendButtonLabel:s,stopButtonLabel:c,contextWindow:l,onSend:u,onStop:d}){let{Popover:f,PopoverContent:p,PopoverTrigger:m,Tooltip:h,TooltipContent:g,TooltipProvider:_,TooltipTrigger:v}=Dc,y=e?.trim()??``,b=y?Fc(y):``,x=t?.trim()||`Details`;return(0,I.jsxs)(`div`,{className:`flex shrink-0 flex-col items-end gap-1`,children:[y?(0,I.jsxs)(`div`,{className:`flex max-w-[420px] items-start justify-end gap-2 text-right`,children:[(0,I.jsx)(`div`,{className:`min-w-0 flex-1 text-[11px] text-red-600`,children:(0,I.jsx)(`span`,{className:`block truncate`,title:y,children:b})}),(0,I.jsxs)(f,{children:[(0,I.jsx)(m,{asChild:!0,children:(0,I.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:x})}),(0,I.jsxs)(p,{align:`end`,className:`w-[min(32rem,calc(100vw-1.5rem))] border-red-100/80 p-0`,children:[(0,I.jsx)(`div`,{className:`border-b border-red-100 bg-red-50/80 px-4 py-2 text-xs font-semibold text-red-700`,children:x}),(0,I.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:y})]})]})]}):null,(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[l?(0,I.jsx)(Lc,{contextWindow:l}):null,n?r?(0,I.jsx)(Nc,{size:`icon`,variant:`outline`,className:`h-8 w-8 rounded-full`,"aria-label":c,onClick:()=>void d(),disabled:a,children:(0,I.jsx)(Ic,{})}):(0,I.jsx)(_,{children:(0,I.jsxs)(h,{children:[(0,I.jsx)(v,{asChild:!0,children:(0,I.jsx)(`span`,{children:(0,I.jsx)(Nc,{size:`icon`,variant:`outline`,className:`h-8 w-8 rounded-full`,"aria-label":c,disabled:!0,children:(0,I.jsx)(Ic,{})})})}),(0,I.jsx)(g,{side:`top`,children:(0,I.jsx)(`p`,{className:`text-xs`,children:o})})]})}):(0,I.jsx)(Nc,{size:`icon`,className:`h-8 w-8 rounded-full`,"aria-label":s,onClick:()=>void u(),disabled:i,children:(0,I.jsx)(Nn,{className:`h-5 w-5`})})]})]})}function zc(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 Bc(e){let{Input:t,Popover:n,PopoverContent:r,PopoverTrigger:i}=Dc,{picker:a}=e,o=(0,F.useRef)(null),s=(0,F.useId)(),[c,l]=(0,F.useState)(``),[u,d]=(0,F.useState)(0),f=(0,F.useMemo)(()=>new Set(a.selectedKeys),[a.selectedKeys]),p=a.selectedKeys.length,m=c.trim().length>0,h=(0,F.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,F.useMemo)(()=>h?h.flatMap(e=>e.options):zc(a.options,c),[h,a.options,c]);(0,F.useEffect)(()=>{d(0)},[c]),(0,F.useEffect)(()=>{d(e=>g.length===0?0:Math.min(e,g.length-1))},[g.length]),oc({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,I.jsxs)(n,{children:[(0,I.jsx)(i,{asChild:!0,children:(0,I.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,I.jsx)(E,{className:`h-4 w-4`}),(0,I.jsx)(`span`,{className:`nextclaw-chat-skill-picker-label hidden sm:inline [@container_nextclaw-chat-input-bar_(max-width:440px)]:hidden`,children:a.title}),p>0?(0,I.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,I.jsxs)(r,{side:`top`,align:`start`,className:`w-[360px] p-0`,children:[(0,I.jsxs)(`div`,{className:`space-y-2 border-b border-gray-100 px-4 py-3`,children:[(0,I.jsx)(`div`,{className:`text-sm font-semibold text-gray-900`,children:a.title}),(0,I.jsxs)(`div`,{className:`relative`,children:[(0,I.jsx)(mn,{className:`pointer-events-none absolute left-3 top-2.5 h-3.5 w-3.5 text-gray-400`}),(0,I.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,I.jsx)(`div`,{ref:o,id:s,role:`listbox`,"aria-multiselectable":`true`,className:`custom-scrollbar max-h-[320px] overflow-y-auto`,children:a.isLoading?(0,I.jsx)(`div`,{className:`p-4 text-xs text-gray-500`,children:a.loadingLabel}):g.length===0?(0,I.jsx)(`div`,{className:`p-4 text-center text-xs text-gray-500`,children:a.emptyLabel}):(0,I.jsx)(`div`,{className:`py-1`,children:(()=>{let e=h??[{key:`all-skills`,options:g}],t=0;return e.map(e=>(0,I.jsxs)(`div`,{children:[e.label?(0,I.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,I.jsxs)(`div`,{id:`${s}-option-${n}`,role:`option`,"aria-selected":r,"data-skill-index":n,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,I.jsx)(`div`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-gray-100 text-gray-500`,children:(0,I.jsx)(gr,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1 select-text`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,I.jsx)(`span`,{className:`truncate text-sm text-gray-900`,children:e.label}),e.badgeLabel?(0,I.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,I.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-gray-500`,children:e.description||e.key})]}),(0,I.jsx)(`div`,{className:`ml-3 shrink-0`,children:(0,I.jsx)(`button`,{type:`button`,"aria-label":`${r?`Remove`:`Add`} ${e.label}`,onClick:()=>_(e.key),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,I.jsx)(In,{className:`h-3 w-3`}):null})})]},e.key)})]},e.key))})()})}),a.manageHref&&a.manageLabel?(0,I.jsx)(`div`,{className:`border-t border-gray-100 px-4 py-2.5`,children:(0,I.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,I.jsx)(dn,{className:`h-3 w-3`})]})}):null]})]})}function Vc({icon:e}){return e===`sparkles`?(0,I.jsx)(br,{className:`h-3.5 w-3.5 shrink-0 text-primary`}):e===`brain`?(0,I.jsx)(Fn,{className:`h-3.5 w-3.5 shrink-0 text-gray-500`}):null}function Hc({icon:e}){return e===`paperclip`?(0,I.jsx)(mr,{className:`h-4 w-4`}):(0,I.jsx)(Vc,{icon:e})}var Uc={model:`min-w-0 max-w-full flex-1 basis-[12rem] sm:max-w-[320px]`,"session-type":`shrink-0`,thinking:`shrink-0`},Wc={model:`w-[min(18rem,calc(100vw-1rem))] sm:w-[320px]`,"session-type":`w-[220px]`,thinking:`w-[180px]`};function Gc(e){return e.key===`model`&&e.selectedLabel&&e.selectedLabel.split(`/`).slice(1).join(`/`).trim()||e.selectedLabel}function Kc({item:e}){let{Select:t,SelectContent:n,SelectGroup:r,SelectItem:i,SelectLabel:a,SelectSeparator:o,SelectTrigger:s,SelectValue:c}=Dc,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=Gc(e);return(0,I.jsxs)(t,{value:e.value,onValueChange:e.onValueChange,disabled:e.disabled,children:[(0,I.jsx)(s,{"aria-label":e.selectedLabel?`${e.placeholder}: ${e.selectedLabel}`:e.placeholder,title:e.selectedLabel,className:`nextclaw-chat-toolbar-select-trigger 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 [@container_nextclaw-chat-input-bar_(max-width:440px)]:!basis-8 [@container_nextclaw-chat-input-bar_(max-width:440px)]:!justify-center [@container_nextclaw-chat-input-bar_(max-width:440px)]:!max-w-8 [@container_nextclaw-chat-input-bar_(max-width:440px)]:!min-w-8 [@container_nextclaw-chat-input-bar_(max-width:440px)]:!px-0 ${Uc[e.key]??``}`,children:e.selectedLabel?(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-left`,children:[(0,I.jsx)(Vc,{icon:e.icon}),(0,I.jsx)(`span`,{className:`nextclaw-chat-toolbar-mobile-label truncate text-xs font-semibold text-gray-700 sm:hidden [@container_nextclaw-chat-input-bar_(max-width:440px)]:hidden`,children:d}),(0,I.jsx)(`span`,{className:`nextclaw-chat-toolbar-label hidden truncate text-xs font-semibold text-gray-700 sm:inline [@container_nextclaw-chat-input-bar_(max-width:440px)]:hidden`,children:e.selectedLabel})]}):e.loading?(0,I.jsx)(`div`,{className:`h-3 w-24 animate-pulse rounded bg-gray-200`}):(0,I.jsx)(c,{placeholder:e.placeholder})}),(0,I.jsxs)(n,{className:Wc[e.key]??``,children:[u?null:e.loading?(0,I.jsxs)(`div`,{className:`space-y-2 px-3 py-2`,children:[(0,I.jsx)(`div`,{className:`h-3 w-36 animate-pulse rounded bg-gray-200`}),(0,I.jsx)(`div`,{className:`h-3 w-28 animate-pulse rounded bg-gray-200`}),(0,I.jsx)(`div`,{className:`h-3 w-32 animate-pulse rounded bg-gray-200`})]}):e.emptyLabel?(0,I.jsx)(`div`,{className:`px-3 py-2 text-xs text-gray-500`,children:e.emptyLabel}):null,l.map((e,t)=>(0,I.jsxs)(`div`,{children:[t>0?(0,I.jsx)(o,{}):null,(0,I.jsxs)(r,{children:[e.label?(0,I.jsx)(a,{children:e.label}):null,e.options.map(e=>(0,I.jsx)(i,{value:e.value,className:`py-2`,children:e.description?(0,I.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,I.jsx)(`span`,{className:`truncate text-xs font-semibold text-gray-800`,children:e.label}),(0,I.jsx)(`span`,{className:`truncate text-[11px] text-gray-500`,children:e.description})]}):(0,I.jsx)(`span`,{className:`truncate text-xs font-semibold text-gray-800`,children:e.label})},e.value))]})]},e.key))]})]})}function qc({actions:e,accessories:t,selects:n,skillPicker:r}){let{Tooltip:i,TooltipContent:a,TooltipProvider:o,TooltipTrigger:s}=Dc;return(0,I.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-2 px-3 pb-3`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-[12rem] flex-1 flex-wrap items-center gap-1 overflow-hidden`,children:[r?(0,I.jsx)(Bc,{picker:r}):null,n.map(e=>(0,I.jsx)(Kc,{item:e},e.key)),t?.map(e=>{let t=(0,I.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,I.jsx)(Hc,{icon:e.icon}),e.iconOnly?null:(0,I.jsx)(`span`,{children:e.label})]});return e.tooltip?(0,I.jsx)(o,{children:(0,I.jsxs)(i,{children:[(0,I.jsx)(s,{asChild:!0,children:e.disabled?(0,I.jsx)(`span`,{className:`inline-flex`,children:t}):t}),(0,I.jsx)(a,{side:`top`,children:(0,I.jsx)(`p`,{className:`text-xs`,children:e.tooltip})})]})},e.key):(0,I.jsx)(`div`,{children:t},e.key)})]}),(0,I.jsx)(Rc,{...e})]})}var Jc=(0,F.createContext)(null);function Yc(e,t){let n=null;return e!=null&&(n=e[1]),{getTheme:function(){return t??(n==null?null:n.getTheme())}}}function Xc(){let e=(0,F.useContext)(Jc);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 R(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 Zc(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 Qc=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0,$c=Qc&&`documentMode`in document?document.documentMode:null,el=Qc&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),tl=Qc&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),nl=!(!Qc||!(`InputEvent`in window)||$c)&&`getTargetRanges`in new window.InputEvent(`input`),rl=Qc&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,il=Qc&&/Android/.test(navigator.userAgent),al=Qc&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!il,ol=Qc&&/^(?=.*Chrome).*/i.test(navigator.userAgent),sl=Qc&&il&&ol,cl=Qc&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&el&&!ol,ll=0,ul=1,dl=2,fl=1,pl=2,ml=3,hl=4,gl=5,_l=6,vl=al||rl||cl?`\xA0`:``,yl=`
|
|
4
4
|
|
|
@@ -88,7 +88,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),i=e,r=t),n===void 0&&(
|
|
|
88
88
|
-webkit-text-fill-color: currentColor;
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
`;function bM(e){let t=e.trim();return t?t.replace(vM,``).trim().length>0:!1}function xM(e){return e.parts.some(e=>e.type===`markdown`||e.type===`reasoning`?bM(e.text):!0)}function SM(){return(0,I.jsx)(`div`,{className:`flex items-center gap-2 px-1 py-0.5 text-[11px] text-gray-400`,children:(0,I.jsxs)(`div`,{className:`flex space-x-1 items-center h-full`,children:[(0,I.jsx)(`div`,{className:`h-1.5 w-1.5 rounded-full bg-gray-400 animate-pulse`}),(0,I.jsx)(`div`,{className:`h-1.5 w-1.5 rounded-full bg-gray-400 animate-pulse [animation-delay:200ms]`}),(0,I.jsx)(`div`,{className:`h-1.5 w-1.5 rounded-full bg-gray-400 animate-pulse [animation-delay:400ms]`})]})})}function CM({label:e}){return(0,I.jsxs)(`div`,{className:`rounded-2xl border border-gray-200 bg-white px-4 py-3 text-sm text-gray-500 shadow-sm`,children:[(0,I.jsx)(`style`,{children:yM}),(0,I.jsx)(`span`,{className:`nextclaw-chat-typing-indicator__text`,children:e})]})}function wM(e){let t=e.messages.filter(xM),n=t.some(e=>e.role===`assistant`&&(e.status===`streaming`||e.status===`pending`));return(0,I.jsxs)(`div`,{className:L(`space-y-5`,e.className),children:[t.map(t=>{let n=t.role===`user`,r=!n&&(t.status===`streaming`||t.status===`pending`);return(0,I.jsxs)(`div`,{className:L(`flex gap-3`,n?`justify-end`:`justify-start`),children:[n?null:(0,I.jsx)(Fy,{role:t.role}),(0,I.jsxs)(`div`,{className:L(`w-fit max-w-[92%] space-y-2`,n&&`flex flex-col items-end`),children:[(0,I.jsx)(hM,{message:t,texts:e.texts,onToolAction:e.onToolAction,onFileOpen:e.onFileOpen,renderToolAgent:e.renderToolAgent}),(0,I.jsx)(`div`,{className:L(`flex items-center gap-2`,n&&`justify-end`),children:r?(0,I.jsx)(SM,{}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(gM,{roleLabel:t.roleLabel,timestampLabel:t.timestampLabel,isUser:n}),n?null:(0,I.jsx)(_M,{message:t,texts:e.texts})]})})]}),n?(0,I.jsx)(Fy,{role:t.role}):null]},t.id)}),e.isSending&&!n?(0,I.jsxs)(`div`,{className:`flex justify-start gap-3`,children:[(0,I.jsx)(Fy,{role:`assistant`}),(0,I.jsx)(CM,{label:e.texts.typingLabel})]}):null]})}var TM=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.ContextWindowUpdated=`context-window.updated`,e.TypingStart=`typing.start`,e.TypingEnd=`typing.end`,e.PresenceUpdated=`presence.updated`,e}({}),EM=/\[\[\s*reply_to_current\s*\]\]/gi,DM=/\[\[\s*reply_to\s*:\s*([^\]]+?)\s*\]\]/i;function OM(e){if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0}function kM(e,t){let n=e,r;EM.test(n)&&(r=OM(t),n=n.replace(EM,``).trim());let i=n.match(DM)?.[1];return i&&(r=OM(i),n=n.replace(DM,``).trim()),r?{content:n,replyTo:r}:{content:n}}function AM(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=OM(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}=kM(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 jM(e){return{...e,parts:[...e.parts],metadata:e.metadata?{...e.metadata}:void 0}}function MM(e){return jM(AM(e))}var NM=`__nextclaw_aborted_tool_call__`;function PM(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 FM(e,t){return t.trim()?e.id.startsWith(`tool-`)?!0:e.parts.some(e=>e.type===`tool-invocation`):!1}function IM(e,t,n){for(let[r,i]of e)i===t&&e.set(r,n)}function LM(e,t,n){for(let[r,i]of e)i===n&&(e.delete(r),t.delete(r))}function RM(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 zM(e,t){return RM(e,t)?.toolName??null}function BM(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 VM(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 HM=`assistant`,UM=class{messages=[];streamingMessage=null;error=null;activeRun=null;contextWindow=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,contextWindow:this.contextWindow?{...this.contextWindow}: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.contextWindow&&this.toolCallMessageIdByCallId.size===0&&this.toolCallArgsRawByCallId.size===0||(this.messages=[],this.streamingMessage=null,this.error=null,this.activeRun=null,this.contextWindow=null,this.toolCallMessageIdByCallId.clear(),this.toolCallArgsRawByCallId.clear(),this.lastSettledRunId=null,this.stateVersion+=1,this.notifyListeners())};hydrate=e=>{this.messages=e.messages.map(e=>MM(e)),this.streamingMessage=null,this.error=null,this.contextWindow=e.contextWindow?{...e.contextWindow}: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 TM.MessageSent:this.handleMessageSent(e.payload);break;case TM.MessageAbort:this.handleMessageAbort(e.payload);break;case TM.MessageTextStart:this.handleMessageTextStart(e.payload);break;case TM.MessageTextDelta:this.handleMessageTextDelta(e.payload);break;case TM.MessageTextEnd:this.handleMessageTextEnd(e.payload);break;case TM.MessageReasoningStart:this.handleMessageReasoningStart(e.payload);break;case TM.MessageReasoningDelta:this.handleMessageReasoningDelta(e.payload);break;case TM.MessageReasoningEnd:this.handleMessageReasoningEnd(e.payload);break;case TM.MessageToolCallStart:this.handleMessageToolCallStart(e.payload);break;case TM.MessageToolCallArgs:this.handleMessageToolCallArgs(e.payload);break;case TM.MessageToolCallArgsDelta:this.handleMessageToolCallArgsDelta(e.payload);break;case TM.MessageToolCallEnd:this.handleMessageToolCallEnd(e.payload);break;case TM.MessageToolCallResult:this.handleMessageToolCallResult(e.payload);break;case TM.RunStarted:this.handleRunStarted(e.payload);break;case TM.RunFinished:this.handleRunFinished(e.payload);break;case TM.RunError:this.handleRunError(e.payload);break;case TM.RunMetadata:this.handleRunMetadata(e.payload);break;case TM.ContextWindowUpdated:this.handleContextWindowUpdated(e.payload);break;case TM.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}=VM(this.streamingMessage.parts);this.upsertMessage({...this.streamingMessage,status:`final`,parts:n}),this.replaceStreamingMessage(null),t?LM(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,t):LM(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,e),r.forEach(e=>this.toolCallArgsRawByCallId.set(e,NM))}};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=BM(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=BM(t.parts,{type:`tool-invocation`,toolCallId:e.toolCallId,toolName:zM(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 BM(t.parts,r)})){let t=this.resolveToolCallTargetMessage(e.sessionId,e.toolCallId),n=BM(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(PM(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())};handleContextWindowUpdated=e=>{this.contextWindow={...e.contextWindow},this.stateVersion+=1};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=zM(i.parts,t)??`unknown`,o=BM(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=jM(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&&FM(i,t)){let r={...i,id:t,sessionId:e,status:n};return IM(this.toolCallMessageIdByCallId,i.id,t),this.replaceStreamingMessage(r),r}let a={id:t,sessionId:e,role:HM,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=RM(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=RM(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=MM(e);this.streamingMessage?.id===t.id&&(this.streamingMessage=null);let 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?MM(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),LM(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,t.id)};notifyListeners=()=>{let e=this.getSnapshot();for(let t of this.listeners)t(e)}},WM=16,GM=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()},WM))},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 KM(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 qM(e,t){if(!t)return!0;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 JM(e){return e.parts.some(e=>e.type===`text`||e.type===`rich-text`||e.type===`reasoning`?e.text.trim().length>0:!0)}function YM(e,t){if(typeof e==`string`){let n=e.trim();return n?{...t?{sessionId:t}:{},message:{id:`user-${Date.now().toString(36)}`,...t?{sessionId:t}:{},role:`user`,status:`final`,parts:[{type:`text`,text:n}],timestamp:new Date().toISOString()}}:null}if(!JM(e.message))return null;let n=e.sessionId||e.message.sessionId||t;return{...e,...n?{sessionId:n}:{},message:{...e.message,...n?{sessionId:n}:{}}}}function XM(e){let t=(0,F.useRef)();return t.current?e&&t.current.sessionId===null?t.current.sessionId=e:t.current.sessionId!==(e??null)&&(t.current={sessionId:e??null,manager:new UM}):t.current={sessionId:e??null,manager:new UM},t.current.manager}function ZM({sessionId:e,client:t,manager:n}){let r=(0,F.useRef)(e),i=(0,F.useSyncExternalStore)(e=>n.subscribe(()=>e()),()=>n.getSnapshot(),()=>n.getSnapshot()),[a,o]=(0,F.useState)(!1);(0,F.useEffect)(()=>{r.current=e},[e]),(0,F.useEffect)(()=>{o(!1)},[e]),(0,F.useEffect)(()=>{let e=new GM(e=>KM(n,e)),i=t.subscribe(t=>{qM(t,r.current)&&e.enqueue(t)});return()=>{i(),e.dispose(),t.stop()}},[t,n]);let s=i.streamingMessage?[...i.messages,i.streamingMessage]:i.messages,c=i.activeRun?.runId??null,l=!!i.activeRun;return{snapshot:i,visibleMessages:s,activeRunId:c,isRunning:l,isSending:a,send:async r=>{if(a||l)return null;let i=YM(r,e);if(!i)return null;o(!0),e&&await n.dispatch({type:TM.MessageSent,payload:{sessionId:e,message:{...i.message,sessionId:e},metadata:i.metadata}});try{return await t.send(i)}finally{o(!1)}},abort:async()=>{e&&await t.abort({sessionId:e})},streamRun:async()=>{e&&(await t.stop(),await t.stream({sessionId:e}))}}}function QM(e){return e instanceof Error?e:Error(String(e))}function $M(e){let{hydratedSessionId:t,isHydrating:n,sessionId:r}=e;return r?n||t!==r:!1}function eN(e,t){let n=e.getSnapshot();return n.activeRun?.sessionId===t||n.streamingMessage?.sessionId===t||n.messages.some(e=>e.sessionId===t)}function tN(e,t){return e.status===`running`?{runId:null,sessionId:t,abortDisabledReason:null}:null}function nN(e,t,n){return n.signal.aborted||e.requestId!==t}function rN({sessionId:e,client:t,loadSeed:n}){let r=XM(e),i=ZM({sessionId:e,client:t,manager:r}),[a,o]=(0,F.useState)(!0),[s,c]=(0,F.useState)(null),[l,u]=(0,F.useState)(null),d=(0,F.useRef)({requestId:0,controller:null}),f=(0,F.useCallback)(async()=>{await t.stop(),r.reset(),c(null),u(null),o(!1),d.current={requestId:d.current.requestId+1,controller:null}},[t,r]),p=(0,F.useCallback)(e=>{c(null),u(e),o(!1)},[]),m=(0,F.useCallback)(async()=>{if(d.current.controller?.abort(),!e){await f();return}let i=new AbortController,a=d.current.requestId+1;if(d.current={requestId:a,controller:i},eN(r,e)){p(e),d.current.controller===i&&(d.current.controller=null);return}await t.stop(),r.reset(),c(null),o(!0);try{let o=await n(e,i.signal);if(nN(d.current,a,i))return;r.hydrate({sessionId:e,messages:o.messages,activeRun:tN(o,e)}),p(e),t.stream({sessionId:e}).catch(e=>{d.current.requestId===a&&c(QM(e))})}catch(t){if(nN(d.current,a,i))return;c(QM(t)),u(e),o(!1)}finally{d.current.controller===i&&(d.current.controller=null)}},[t,n,r,p,f,e]);return(0,F.useEffect)(()=>(m(),()=>{d.current.controller?.abort(),d.current.controller=null}),[m]),{...i,isHydrating:$M({sessionId:e,hydratedSessionId:l,isHydrating:a}),hydrateError:s}}var iN=200*1024*1024,aN=`application/octet-stream`;function oN(e){let t=e.type.trim().toLowerCase();return t.length>0?t:aN}function sN(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=oN(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 cN(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{...e.sessionId?{sessionId:e.sessionId}:{},message:{id:r,...e.sessionId?{sessionId:e.sessionId}:{},role:`user`,status:`final`,parts:t,timestamp:n,...e.metadata?{metadata:e.metadata}:{}},...e.metadata?{metadata:e.metadata}:{}}}async function lN(e,t){let n=[],r=[];for(let i of e){let e=sN(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:oN(e),sizeBytes:e.size,reason:`read-failed`}))),{attachments:[],rejected:r}}}function uN(e){let t=e.modelLabel.trim(),n=e.providerLabel.trim();return n?`${n}/${t}`:t}function dN(e){let t=[];for(let n of[`off`,...e])t.includes(n)||t.push(n);return t}function fN(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 pN({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:uN(e)}))},{key:`all-models`,label:o.allModelsLabel,options:f.map(e=>({value:e.value,label:uN(e)}))}].filter(e=>e.options.length>0):void 0;return{key:`model`,value:c,placeholder:o.modelSelectPlaceholder,selectedLabel:s?uN(s):void 0,icon:`sparkles`,options:e.map(e=>({value:e.value,label:uN(e)})),groups:p,disabled:!i,loading:r,emptyLabel:o.modelNoOptionsLabel,onValueChange:a}}function mN(e){if(e.supportedLevels.length===0)return null;let t=dN(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 hN={exactSpec:1200,exactLabel:1150,prefixSpec:1e3,prefixLabel:950,prefixToken:900,containsSpec:800,containsLabel:760,containsDescription:500,subsequence:300,fallback:1};function gN(e){return(e??``).trim().toLowerCase()}function _N(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 vN(e,t){let n=gN(t);if(!n)return hN.fallback;let r=gN(e.key),i=gN(e.label||e.key),a=gN(`${e.descriptionZh??``} ${e.description??``}`),o=i.split(/[\s/_-]+/).filter(Boolean);return r===n?hN.exactSpec:i===n?hN.exactLabel:r.startsWith(n)?hN.prefixSpec:i.startsWith(n)?hN.prefixLabel:o.some(e=>e.startsWith(n))?hN.prefixToken:r.includes(n)?hN.containsSpec:i.includes(n)?hN.containsLabel:a.includes(n)?hN.containsDescription:_N(n,i)||_N(n,r)?hN.subsequence:0}function yN(e){return e>=hN.exactLabel?4:e>=hN.prefixToken?3:e>=hN.containsLabel?2:e>0?1:0}function bN(e){return new Map(e.map((e,t)=>[e,t]))}function xN(e,t){let n=bN(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 SN(e,t,n,r=[]){let i=new Intl.Collator(void 0,{sensitivity:`base`,numeric:!0}),a=bN(r);return e.map((e,n)=>({record:e,order:n,score:vN(e,t)})).filter(e=>e.score>0).sort((e,t)=>{let n=yN(e.score),r=yN(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 CN(e){return e.map(e=>({key:e.key,label:e.label,description:e.descriptionZh||e.description||``,badgeLabel:e.badgeLabel}))}function wN(e){let t=xN(e.skillRecords,e.recentSkillValues??[]),n=new Set(e.groupedRecentSkillValues??[]),r=CN(t.filter(e=>n.has(e.key))),i=CN(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:CN(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 TN=`$`;function EN(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 DN(){return Hv()}function ON(e){return Uv(e)}function kN(e){return Kv(e)}function AN(e){return qv(e,`skill`)}function jN(e){return qv(e,`file`)}function MN(e,t,n){let r=new Set(t),i=ey(e,e=>e.tokenKind===`skill`&&!r.has(e.tokenKey)),a=qv(i,`skill`),o=new Map(n.map(e=>[e.ref,e])),s=t.filter(e=>!a.includes(e)).map(e=>Bv({tokenKind:`skill`,tokenKey:e,label:o.get(e)?.name||e}));return s.length===0?i:Wv([...i,...s])}function NN(e,t){let n=new Set(t.map(e=>e.id));return ey(e,e=>e.tokenKind===`file`&&!n.has(e.tokenKey))}function PN(e,t){let n=new Set(jN(e));return t.filter(e=>n.has(e.id))}function FN(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[];for(let t of e){if(t.type===`text`){r=EN(r,t.text);continue}if(t.tokenKind===`skill`){r=EN(r,`${TN}${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 IN={isProviderStateResolved:!1,composerNodes:DN(),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:[],composerFocusRequest:null},Z=m(e=>({snapshot:IN,setSnapshot:t=>e(e=>({snapshot:{...e.snapshot,...t}}))})),LN=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}}},RN=new LN({storageKey:`nextclaw.chat.recent-models`,limit:3}),zN=new LN({storageKey:`nextclaw.chat.recent-skills`,limit:5});function BN(e){return e.modelOptions.length>0}function VN(e){return!e.isProviderStateResolved&&!BN(e)}function HN(e){return e.isProviderStateResolved&&!BN(e)}function UN(e){return!1}function WN(e){let{hasSendableDraft:t,isRuntimeBlocked:n}=e;return n||!t}var GN=`nextclaw.chat.session-list.mode`,KN=`time-first`;function qN(e){return e===`time-first`||e===`project-first`}function JN(e){if(!e||typeof e!=`object`)return null;let{snapshot:t}=e;return!t||typeof t!=`object`?null:qN(t.listMode)?t.listMode:null}function YN(e,t){let n=e?.trim();if(!n)return!1;let r=t?.trim();return r?n.localeCompare(r)>0:!1}function XN(e){let{active:t,readAt:n,runStatus:r,lastMessageAt:i}=e;return t||r===`running`?!1:YN(i,n)}var ZN={selectedSessionKey:null,selectedAgentId:`main`,query:``,listMode:KN};function QN(e){return t=>e(e=>({snapshot:{...e.snapshot,...t}}))}function $N(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 eP=m()(Tn(e=>({snapshot:ZN,optimisticReadAtBySessionKey:{},setSnapshot:QN(e),markSessionRead:$N(e)}),{name:GN,storage:On(()=>window.localStorage),partialize:e=>({snapshot:{listMode:e.snapshot.listMode}}),merge:(e,t)=>{let n=JN(e);return n?{...t,snapshot:{...t.snapshot,listMode:n}}:t}})),tP={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,hasSubmittedDraftMessage:!1,parentSessionKey:null,parentSessionLabel:null,workspacePanelParentKey:null,activeWorkspacePanelKind:null,childSessionTabs:[],activeChildSessionKey:null,workspaceFileTabs:[],activeWorkspaceFileKey:null,contextWindow:null},Q=m(e=>({snapshot:tP,setSnapshot:t=>e(e=>({snapshot:{...e.snapshot,...t}}))}));function nP(e){return e>=1e6?`${(e/1e6).toFixed(e>=1e7?0:1)}M`:e>=1e3?`${(e/1e3).toFixed(e>=1e4?0:1)}k`:String(e)}function rP(e){if(!e||e.totalContextTokens<=0)return null;let t=e.usedContextTokens/e.totalContextTokens,n=Math.max(0,Math.min(1,t)),r=`${Math.round(n*100)}%`,i=n>=.9?`danger`:n>=.75?`warning`:`neutral`,a=[{label:s(`chatContextWindowUsed`),value:nP(e.usedContextTokens)},{label:s(`chatContextWindowTotal`),value:nP(e.totalContextTokens)},{label:s(`chatContextWindowAvailable`),value:nP(e.availableContextTokens)}];return e.prunedUsedContextTokens!==e.usedContextTokens&&a.push({label:s(`chatContextWindowPruned`),value:nP(e.prunedUsedContextTokens)}),e.droppedHistoryCount>0&&a.push({label:s(`chatContextWindowDroppedHistory`),value:String(e.droppedHistoryCount)}),e.truncatedToolResultCount>0&&a.push({label:s(`chatContextWindowTruncatedTools`),value:String(e.truncatedToolResultCount)}),{label:s(`chatContextWindow`),percentLabel:r,ratio:n,tone:i,details:a}}function iP(){let e=eP(e=>e.snapshot.selectedSessionKey),t=Q(e=>e.snapshot.sessionKey),n=Q(e=>e.snapshot.contextWindow);return(0,F.useMemo)(()=>e&&t===e&&n?rP(n):null,[n,t,e])}function aP(e){return e.bootstrapStatus?.ncpAgent.state!==`ready`}function oP(e){return e.activeSystemAction?.message?.trim()||(e.lifecyclePhase===`cold-starting`?s(`chatRuntimeInitializing`):e.lifecyclePhase===`startup-failed`?e.bootstrapStatus?.ncpAgent.error?.trim()||e.bootstrapStatus?.lastError?.trim()||e.lastError?.trim()||s(`chatRuntimeInitializationFailed`):null)}function sP(e){let{message:t,status:n}=e,r=t?.trim();if(!r)return oP(n);let i=n.activeSystemAction?.message?.trim();if(n.phase===`service-transitioning`&&i)return i;let a=st(r);return n.phase===`recovering`&&a?s(`runtimeControlRecoveringHelp`):n.phase===`stalled`&&a?null:r}function cP(){return{off:s(`chatThinkingLevelOff`),minimal:s(`chatThinkingLevelMinimal`),low:s(`chatThinkingLevelLow`),medium:s(`chatThinkingLevelMedium`),high:s(`chatThinkingLevelHigh`),adaptive:s(`chatThinkingLevelAdaptive`),xhigh:s(`chatThinkingLevelXhigh`)}}function lP(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 uP(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 dP(e){return{skillScopeLabels:(0,F.useMemo)(()=>({builtin:s(`chatSkillScopeBuiltin`),project:s(`chatSkillScopeProject`),workspace:s(`chatSkillScopeWorkspace`)}),[e]),slashTexts:(0,F.useMemo)(()=>({slashSkillSubtitle:s(`chatSlashTypeSkill`),slashSkillSpecLabel:s(`chatSlashSkillSpec`),slashSkillScopeLabel:s(`chatSlashSkillScope`),noSkillDescription:s(`chatSkillsPickerNoDescription`)}),[e]),recentModelsLabel:s(`chatPickerRecentModels`),allModelsLabel:s(`chatPickerAllModels`),recentSkillsLabel:s(`chatPickerRecent`),allSkillsLabel:s(`chatPickerAllSkills`)}}function fP(e,t){let n=(0,F.useMemo)(()=>lP(e.skillRecords,t),[e.skillRecords,t]),r=(0,F.useMemo)(()=>uP(e.modelOptions),[e.modelOptions]);return{skillRecords:n,modelRecords:r,recentModelValues:RN.resolveVisible({availableValues:r.map(e=>e.value),minAvailableCount:5}),recentSkillValues:zN.resolveVisible({availableValues:n.map(e=>e.key),minAvailableCount:0}),recentSkillGroupValues:zN.resolveVisible({availableValues:n.map(e=>e.key),minAvailableCount:4})}}function pP(e){let{attachmentSupported:t,inputBarRef:n,presenter:r}=e,i=(0,F.useCallback)(e=>{if(e===`unsupported-type`){N.error(s(`chatInputAttachmentUnsupported`));return}if(e===`too-large`){N.error(s(`chatInputAttachmentTooLarge`).replace(`{maxMb}`,String(iN/(1024*1024))));return}N.error(s(`chatInputAttachmentReadFailed`))},[]),a=(0,F.useCallback)(async e=>{if(!t||e.length===0)return;let a=await lN(e,{uploadBatch:yt});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,F.useCallback)(async e=>{let t=Array.from(e.target.files??[]);e.currentTarget.value=``,await a(t)},[a])}}function mP(e){let{allModelsLabel:t,hasModelOptions:n,isModelOptionsLoading:r,modelRecords:i,presenter:a,recentModelValues:o,recentModelsLabel:c,selectedModel:l,selectedThinkingLevel:u,thinkingSupportedLevels:d,thinkingDefaultLevel:f}=e;return[pN({modelOptions:i,recentModelValues:o,selectedModel:l,isModelOptionsLoading:r,hasModelOptions:n,onValueChange:a.chatInputManager.selectModel,texts:{modelSelectPlaceholder:s(`chatSelectModel`),modelNoOptionsLabel:s(`chatModelNoOptions`),recentModelsLabel:c,allModelsLabel:t}}),mN({supportedLevels:d,selectedThinkingLevel:u,defaultThinkingLevel:f,onValueChange:e=>a.chatInputManager.selectThinkingLevel(e),texts:{thinkingLabels:cP()}})].filter(e=>e!==null)}function hP(e){let{allSkillsLabel:t,presenter:n,recentSkillGroupValues:r,recentSkillValues:i,recentSkillsLabel:a,skillRecords:o,snapshot:c}=e;return wN({skillRecords:o,recentSkillValues:i,groupedRecentSkillValues:r,selectedSkills:c.selectedSkills,isLoading:c.isSkillsLoading,onSelectedKeysChange:n.chatInputManager.selectSkills,texts:{title:s(`chatSkillsPickerTitle`),searchPlaceholder:s(`chatSkillsPickerSearchPlaceholder`),emptyLabel:s(`chatSkillsPickerEmpty`),loadingLabel:s(`sessionsLoading`),manageLabel:s(`chatSkillsPickerManage`),recentSkillsLabel:a,allSkillsLabel:t}})}function gP(){let e=ic(),{language:t}=kr(),{isMobile:n}=Pr(),r=Z(e=>e.snapshot),i=aP(bt()),[a,o]=(0,F.useState)(null),c=(0,F.useRef)(null),l=(0,F.useRef)(null),u=dP(t),{skillRecords:d,modelRecords:f,recentModelValues:p,recentSkillValues:m,recentSkillGroupValues:h}=fP(r,u.skillScopeLabels),g=BN(r),_=VN(r),v=HN(r),y=UN(r),b=typeof e.chatInputManager.addAttachments==`function`,x=s(v?`chatModelNoOptions`:n?`chatInputPlaceholderCompact`:`chatInputPlaceholder`),S=(0,F.useMemo)(()=>SN(d,a??``,u.slashTexts,m),[u.slashTexts,m,d,a]),C=iP(),w=f.find(e=>e.value===r.selectedModel),T=w?.thinkingCapability?.supported??[],E=r.stopDisabledReason===`__preparing__`?s(`chatStopPreparing`):r.stopDisabledReason?.trim()||s(`chatStopUnavailable`),{handleFilesAdd:D,handleFileInputChange:O}=pP({attachmentSupported:b,inputBarRef:c,presenter:e});(0,F.useEffect)(()=>{let t=r.composerFocusRequest;t&&(t.placement===`end`&&c.current?.focusComposerAtEnd(),e.chatInputManager.consumeComposerFocusRequest(t.id))},[e.chatInputManager,r.composerFocusRequest]);let k=mP({allModelsLabel:u.allModelsLabel,hasModelOptions:g,isModelOptionsLoading:_,modelRecords:f,presenter:e,recentModelValues:p,recentModelsLabel:u.recentModelsLabel,selectedModel:r.selectedModel,selectedThinkingLevel:r.selectedThinkingLevel,thinkingSupportedLevels:T,thinkingDefaultLevel:w?.thinkingCapability?.default??null}),A=hP({allSkillsLabel:u.allSkillsLabel,presenter:e,recentSkillGroupValues:h,recentSkillValues:m,recentSkillsLabel:u.recentSkillsLabel,skillRecords:d,snapshot:r}),ee=r.draft.trim().length>0||r.attachments.length>0||AN(r.composerNodes).length>0;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Py,{ref:c,composer:{nodes:r.composerNodes,placeholder:x,disabled:y,onNodesChange:e.chatInputManager.setComposerNodes,...b?{onFilesAdd:D}:{},onSlashQueryChange:o},slashMenu:{isLoading:r.isSkillsLoading,items:S,onSelectItem:t=>{t.value&&e.chatInputManager.rememberSkillSelection(t.value)},texts:{slashLoadingLabel:s(`chatSlashLoading`),slashSectionLabel:s(`chatSlashSectionSkills`),slashEmptyLabel:s(`chatSlashNoResult`),slashHintLabel:s(`chatSlashHint`),slashSkillHintLabel:s(`chatSlashSkillHint`)}},hint:fN({isModelOptionsLoading:_,isModelOptionsEmpty:v,onGoToProviders:e.chatInputManager.goToProviders,texts:{noModelOptionsLabel:s(`chatModelNoOptions`),configureProviderLabel:s(`chatGoConfigureProvider`)}}),toolbar:{selects:k,accessories:[{key:`attach`,label:s(`chatInputAttach`),icon:`paperclip`,iconOnly:!0,disabled:!b||y||r.isSending,...b?{onClick:()=>l.current?.click()}:{tooltip:s(`chatInputAttachComingSoon`)}}],skillPicker:A,actions:{sendError:i?null:r.sendError,isSending:r.isSending,canStopGeneration:r.canStopGeneration,sendDisabled:WN({snapshot:r,hasSendableDraft:ee,isRuntimeBlocked:i}),stopDisabled:!r.canStopGeneration,stopHint:E,sendButtonLabel:s(`chatSend`),stopButtonLabel:s(`chatStop`),contextWindow:C,onSend:e.chatInputManager.send,onStop:e.chatInputManager.stop}}}),b?(0,I.jsx)(`input`,{ref:l,type:`file`,multiple:!0,className:`hidden`,onChange:O}):null]})}var _P=[`cmd`,`command`,`query`,`q`,`path`,`url`,`to`,`channel`,`agentId`,`sessionKey`];function vP(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function yP(e,t=2400){return e.length<=t?e:`${e.slice(0,t)}\n…`}function bP(e,t=120){let n=e.replace(/\s+/g,` `).trim();return n.length<=t?n:t<=1?`…`:`${n.slice(0,t-1)}…`}function xP(e){if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);if(e==null)return``;try{return yP(JSON.stringify(e,null,2))}catch{return String(e)}}function SP(e){if(vP(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 vP(e)?e:null}catch{return null}}function CP(e){let t=SP(e);if(!t){let t=xP(e).trim();return t?bP(t,120):void 0}let n=[];for(let e of _P){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?bP(n.join(` · `),120):bP(xP(t),140)}var wP=`ui_inline_tokens`,TP=`$`;function EP(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function DP(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function OP(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 kP(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:`${TP}${n.tokenKey}`});return OP(t)}function AP(e){let t=e?.[wP];if(!Array.isArray(t))return[];let n=[];for(let e of t){if(!EP(e))continue;let t=DP(e.kind),r=DP(e.key),i=DP(e.rawText);!t||!r||!i||n.push({kind:t,key:r,rawText:i,label:DP(e.label)??r})}return OP(n)}function jP(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 MP=/\u200B|\u200C|\u200D|\u2060|\uFEFF/g;function NP(e){let t=e.trim();return t&&t.replace(MP,``).trim()?t:null}function PP(e){return e.replace(MP,``).trim().length>0}function FP(e,t){let n=jP(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&&(PP(e.text)&&(i=!0),r.push({type:`markdown`,text:e.text}))}return i?r:null}function IP(e,t){let n=FP(e.text,t);if(n&&n.some(e=>e.type===`token`))return{type:`inline-content`,segments:n};let r=NP(e.text);return r?{type:`markdown`,text:r}:null}function LP(e){return NP(e)}function RP(e){return typeof e==`object`&&!!e}function zP(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function BP(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 VP(e){return RP(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 HP(e,t){if(!RP(e))return null;let n=RP(e.asset)?e.asset:Array.isArray(e.assets)&&e.assets.length>0&&RP(e.assets[0])?e.assets[0]:null;if(!n)return null;let r=zP(n.url),i=zP(n.mimeType)??`application/octet-stream`,a=BP(n.sizeBytes);return r?{type:`file`,file:{label:zP(n.name)??(i.startsWith(`image/`)?t.imageAttachmentLabel:t.fileAttachmentLabel),mimeType:i,dataUrl:r,...a==null?{}:{sizeBytes:a},isImage:i.startsWith(`image/`)}}:null}function UP(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 WP(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 GP(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 KP(e,t){return xP(t??GP(e)).trim()||void 0}function qP(e){return typeof e==`object`&&!!e}function JP(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 YP(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function XP(e){let t=JP(e);return qP(t)?YP(t.agentId):null}function ZP(e){return XP(e.parsedArgs)??XP(e.args)??XP(e.result)}var QP=12e3,$P=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/;function eF(e){let t=e.replace(/\r\n/g,`
|
|
91
|
+
`;function bM(e){let t=e.trim();return t?t.replace(vM,``).trim().length>0:!1}function xM(e){return e.parts.some(e=>e.type===`markdown`||e.type===`reasoning`?bM(e.text):!0)}function SM(){return(0,I.jsx)(`div`,{className:`flex items-center gap-2 px-1 py-0.5 text-[11px] text-gray-400`,children:(0,I.jsxs)(`div`,{className:`flex space-x-1 items-center h-full`,children:[(0,I.jsx)(`div`,{className:`h-1.5 w-1.5 rounded-full bg-gray-400 animate-pulse`}),(0,I.jsx)(`div`,{className:`h-1.5 w-1.5 rounded-full bg-gray-400 animate-pulse [animation-delay:200ms]`}),(0,I.jsx)(`div`,{className:`h-1.5 w-1.5 rounded-full bg-gray-400 animate-pulse [animation-delay:400ms]`})]})})}function CM({label:e}){return(0,I.jsxs)(`div`,{className:`rounded-2xl border border-gray-200 bg-white px-4 py-3 text-sm text-gray-500 shadow-sm`,children:[(0,I.jsx)(`style`,{children:yM}),(0,I.jsx)(`span`,{className:`nextclaw-chat-typing-indicator__text`,children:e})]})}function wM(e){let t=e.messages.filter(xM),n=t.some(e=>e.role===`assistant`&&(e.status===`streaming`||e.status===`pending`));return(0,I.jsxs)(`div`,{className:L(`space-y-5`,e.className),children:[t.map(t=>{let n=t.role===`user`,r=!n&&(t.status===`streaming`||t.status===`pending`);return(0,I.jsxs)(`div`,{className:L(`flex gap-3`,n?`justify-end`:`justify-start`),children:[n?null:(0,I.jsx)(Fy,{role:t.role}),(0,I.jsxs)(`div`,{className:L(`w-fit max-w-[92%] space-y-2`,n&&`flex flex-col items-end`),children:[(0,I.jsx)(hM,{message:t,texts:e.texts,onToolAction:e.onToolAction,onFileOpen:e.onFileOpen,renderToolAgent:e.renderToolAgent}),(0,I.jsx)(`div`,{className:L(`flex items-center gap-2`,n&&`justify-end`),children:r?(0,I.jsx)(SM,{}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(gM,{roleLabel:t.roleLabel,timestampLabel:t.timestampLabel,isUser:n}),n?null:(0,I.jsx)(_M,{message:t,texts:e.texts})]})})]}),n?(0,I.jsx)(Fy,{role:t.role}):null]},t.id)}),e.isSending&&!n?(0,I.jsxs)(`div`,{className:`flex justify-start gap-3`,children:[(0,I.jsx)(Fy,{role:`assistant`}),(0,I.jsx)(CM,{label:e.texts.typingLabel})]}):null]})}var TM=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.ContextWindowUpdated=`context-window.updated`,e.TypingStart=`typing.start`,e.TypingEnd=`typing.end`,e.PresenceUpdated=`presence.updated`,e}({}),EM=/\[\[\s*reply_to_current\s*\]\]/gi,DM=/\[\[\s*reply_to\s*:\s*([^\]]+?)\s*\]\]/i;function OM(e){if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0}function kM(e,t){let n=e,r;EM.test(n)&&(r=OM(t),n=n.replace(EM,``).trim());let i=n.match(DM)?.[1];return i&&(r=OM(i),n=n.replace(DM,``).trim()),r?{content:n,replyTo:r}:{content:n}}function AM(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=OM(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}=kM(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 jM(e){return{...e,parts:[...e.parts],metadata:e.metadata?{...e.metadata}:void 0}}function MM(e){return jM(AM(e))}var NM=`__nextclaw_aborted_tool_call__`;function PM(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 FM(e,t){return t.trim()?e.id.startsWith(`tool-`)?!0:e.parts.some(e=>e.type===`tool-invocation`):!1}function IM(e,t,n){for(let[r,i]of e)i===t&&e.set(r,n)}function LM(e,t,n){for(let[r,i]of e)i===n&&(e.delete(r),t.delete(r))}function RM(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 zM(e,t){return RM(e,t)?.toolName??null}function BM(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 VM(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 HM=`assistant`,UM=class{messages=[];streamingMessage=null;error=null;activeRun=null;contextWindow=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,contextWindow:this.contextWindow?{...this.contextWindow}: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.contextWindow&&this.toolCallMessageIdByCallId.size===0&&this.toolCallArgsRawByCallId.size===0||(this.messages=[],this.streamingMessage=null,this.error=null,this.activeRun=null,this.contextWindow=null,this.toolCallMessageIdByCallId.clear(),this.toolCallArgsRawByCallId.clear(),this.lastSettledRunId=null,this.stateVersion+=1,this.notifyListeners())};hydrate=e=>{this.messages=e.messages.map(e=>MM(e)),this.streamingMessage=null,this.error=null,this.contextWindow=e.contextWindow?{...e.contextWindow}: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 TM.MessageSent:this.handleMessageSent(e.payload);break;case TM.MessageAbort:this.handleMessageAbort(e.payload);break;case TM.MessageTextStart:this.handleMessageTextStart(e.payload);break;case TM.MessageTextDelta:this.handleMessageTextDelta(e.payload);break;case TM.MessageTextEnd:this.handleMessageTextEnd(e.payload);break;case TM.MessageReasoningStart:this.handleMessageReasoningStart(e.payload);break;case TM.MessageReasoningDelta:this.handleMessageReasoningDelta(e.payload);break;case TM.MessageReasoningEnd:this.handleMessageReasoningEnd(e.payload);break;case TM.MessageToolCallStart:this.handleMessageToolCallStart(e.payload);break;case TM.MessageToolCallArgs:this.handleMessageToolCallArgs(e.payload);break;case TM.MessageToolCallArgsDelta:this.handleMessageToolCallArgsDelta(e.payload);break;case TM.MessageToolCallEnd:this.handleMessageToolCallEnd(e.payload);break;case TM.MessageToolCallResult:this.handleMessageToolCallResult(e.payload);break;case TM.RunStarted:this.handleRunStarted(e.payload);break;case TM.RunFinished:this.handleRunFinished(e.payload);break;case TM.RunError:this.handleRunError(e.payload);break;case TM.RunMetadata:this.handleRunMetadata(e.payload);break;case TM.ContextWindowUpdated:this.handleContextWindowUpdated(e.payload);break;case TM.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}=VM(this.streamingMessage.parts);this.upsertMessage({...this.streamingMessage,status:`final`,parts:n}),this.replaceStreamingMessage(null),t?LM(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,t):LM(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,e),r.forEach(e=>this.toolCallArgsRawByCallId.set(e,NM))}};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=BM(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=BM(t.parts,{type:`tool-invocation`,toolCallId:e.toolCallId,toolName:zM(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 BM(t.parts,r)})){let t=this.resolveToolCallTargetMessage(e.sessionId,e.toolCallId),n=BM(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(PM(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())};handleContextWindowUpdated=e=>{this.contextWindow={...e.contextWindow},this.stateVersion+=1};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=zM(i.parts,t)??`unknown`,o=BM(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=jM(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&&FM(i,t)){let r={...i,id:t,sessionId:e,status:n};return IM(this.toolCallMessageIdByCallId,i.id,t),this.replaceStreamingMessage(r),r}let a={id:t,sessionId:e,role:HM,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=RM(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=RM(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=MM(e);this.streamingMessage?.id===t.id&&(this.streamingMessage=null);let 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?MM(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),LM(this.toolCallMessageIdByCallId,this.toolCallArgsRawByCallId,t.id)};notifyListeners=()=>{let e=this.getSnapshot();for(let t of this.listeners)t(e)}},WM=16,GM=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()},WM))},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 KM(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 qM(e,t){if(!t)return!0;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 JM(e){return e.parts.some(e=>e.type===`text`||e.type===`rich-text`||e.type===`reasoning`?e.text.trim().length>0:!0)}function YM(e,t){if(typeof e==`string`){let n=e.trim();return n?{...t?{sessionId:t}:{},message:{id:`user-${Date.now().toString(36)}`,...t?{sessionId:t}:{},role:`user`,status:`final`,parts:[{type:`text`,text:n}],timestamp:new Date().toISOString()}}:null}if(!JM(e.message))return null;let n=e.sessionId||e.message.sessionId||t;return{...e,...n?{sessionId:n}:{},message:{...e.message,...n?{sessionId:n}:{}}}}function XM(e){let t=(0,F.useRef)();return t.current?e&&t.current.sessionId===null?t.current.sessionId=e:t.current.sessionId!==(e??null)&&(t.current={sessionId:e??null,manager:new UM}):t.current={sessionId:e??null,manager:new UM},t.current.manager}function ZM({sessionId:e,client:t,manager:n}){let r=(0,F.useRef)(e),i=(0,F.useSyncExternalStore)(e=>n.subscribe(()=>e()),()=>n.getSnapshot(),()=>n.getSnapshot()),[a,o]=(0,F.useState)(!1);(0,F.useEffect)(()=>{r.current=e},[e]),(0,F.useEffect)(()=>{o(!1)},[e]),(0,F.useEffect)(()=>{let e=new GM(e=>KM(n,e)),i=t.subscribe(t=>{qM(t,r.current)&&e.enqueue(t)});return()=>{i(),e.dispose(),t.stop()}},[t,n]);let s=i.streamingMessage?[...i.messages,i.streamingMessage]:i.messages,c=i.activeRun?.runId??null,l=!!i.activeRun;return{snapshot:i,visibleMessages:s,activeRunId:c,isRunning:l,isSending:a,send:async r=>{if(a||l)return null;let i=YM(r,e);if(!i)return null;o(!0),e&&await n.dispatch({type:TM.MessageSent,payload:{sessionId:e,message:{...i.message,sessionId:e},metadata:i.metadata}});try{return await t.send(i)}finally{o(!1)}},abort:async()=>{e&&await t.abort({sessionId:e})},streamRun:async()=>{e&&(await t.stop(),await t.stream({sessionId:e}))}}}function QM(e){return e instanceof Error?e:Error(String(e))}function $M(e){let{hydratedSessionId:t,isHydrating:n,sessionId:r}=e;return r?n||t!==r:!1}function eN(e,t){let n=e.getSnapshot();return n.activeRun?.sessionId===t||n.streamingMessage?.sessionId===t||n.messages.some(e=>e.sessionId===t)}function tN(e,t){return e.status===`running`?{runId:null,sessionId:t,abortDisabledReason:null}:null}function nN(e,t,n){return n.signal.aborted||e.requestId!==t}function rN({sessionId:e,client:t,loadSeed:n}){let r=XM(e),i=ZM({sessionId:e,client:t,manager:r}),[a,o]=(0,F.useState)(!0),[s,c]=(0,F.useState)(null),[l,u]=(0,F.useState)(null),d=(0,F.useRef)({requestId:0,controller:null}),f=(0,F.useCallback)(async()=>{await t.stop(),r.reset(),c(null),u(null),o(!1),d.current={requestId:d.current.requestId+1,controller:null}},[t,r]),p=(0,F.useCallback)(e=>{c(null),u(e),o(!1)},[]),m=(0,F.useCallback)(async()=>{if(d.current.controller?.abort(),!e){await f();return}let i=new AbortController,a=d.current.requestId+1;if(d.current={requestId:a,controller:i},eN(r,e)){p(e),d.current.controller===i&&(d.current.controller=null);return}await t.stop(),r.reset(),c(null),o(!0);try{let o=await n(e,i.signal);if(nN(d.current,a,i))return;r.hydrate({sessionId:e,messages:o.messages,activeRun:tN(o,e)}),p(e),t.stream({sessionId:e}).catch(e=>{d.current.requestId===a&&c(QM(e))})}catch(t){if(nN(d.current,a,i))return;c(QM(t)),u(e),o(!1)}finally{d.current.controller===i&&(d.current.controller=null)}},[t,n,r,p,f,e]);return(0,F.useEffect)(()=>(m(),()=>{d.current.controller?.abort(),d.current.controller=null}),[m]),{...i,isHydrating:$M({sessionId:e,hydratedSessionId:l,isHydrating:a}),hydrateError:s}}var iN=200*1024*1024,aN=`application/octet-stream`;function oN(e){let t=e.type.trim().toLowerCase();return t.length>0?t:aN}function sN(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=oN(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 cN(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{...e.sessionId?{sessionId:e.sessionId}:{},message:{id:r,...e.sessionId?{sessionId:e.sessionId}:{},role:`user`,status:`final`,parts:t,timestamp:n,...e.metadata?{metadata:e.metadata}:{}},...e.metadata?{metadata:e.metadata}:{}}}async function lN(e,t){let n=[],r=[];for(let i of e){let e=sN(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:oN(e),sizeBytes:e.size,reason:`read-failed`}))),{attachments:[],rejected:r}}}function uN(e){let t=e.modelLabel.trim(),n=e.providerLabel.trim();return n?`${n}/${t}`:t}function dN(e){let t=[];for(let n of[`off`,...e])t.includes(n)||t.push(n);return t}function fN(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 pN({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:uN(e)}))},{key:`all-models`,label:o.allModelsLabel,options:f.map(e=>({value:e.value,label:uN(e)}))}].filter(e=>e.options.length>0):void 0;return{key:`model`,value:c,placeholder:o.modelSelectPlaceholder,selectedLabel:s?uN(s):void 0,icon:`sparkles`,options:e.map(e=>({value:e.value,label:uN(e)})),groups:p,disabled:!i,loading:r,emptyLabel:o.modelNoOptionsLabel,onValueChange:a}}function mN(e){if(e.supportedLevels.length===0)return null;let t=dN(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 hN={exactSpec:1200,exactLabel:1150,prefixSpec:1e3,prefixLabel:950,prefixToken:900,containsSpec:800,containsLabel:760,containsDescription:500,subsequence:300,fallback:1};function gN(e){return(e??``).trim().toLowerCase()}function _N(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 vN(e,t){let n=gN(t);if(!n)return hN.fallback;let r=gN(e.key),i=gN(e.label||e.key),a=gN(`${e.descriptionZh??``} ${e.description??``}`),o=i.split(/[\s/_-]+/).filter(Boolean);return r===n?hN.exactSpec:i===n?hN.exactLabel:r.startsWith(n)?hN.prefixSpec:i.startsWith(n)?hN.prefixLabel:o.some(e=>e.startsWith(n))?hN.prefixToken:r.includes(n)?hN.containsSpec:i.includes(n)?hN.containsLabel:a.includes(n)?hN.containsDescription:_N(n,i)||_N(n,r)?hN.subsequence:0}function yN(e){return e>=hN.exactLabel?4:e>=hN.prefixToken?3:e>=hN.containsLabel?2:e>0?1:0}function bN(e){return new Map(e.map((e,t)=>[e,t]))}function xN(e,t){let n=bN(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 SN(e,t,n,r=[]){let i=new Intl.Collator(void 0,{sensitivity:`base`,numeric:!0}),a=bN(r);return e.map((e,n)=>({record:e,order:n,score:vN(e,t)})).filter(e=>e.score>0).sort((e,t)=>{let n=yN(e.score),r=yN(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 CN(e){return e.map(e=>({key:e.key,label:e.label,description:e.descriptionZh||e.description||``,badgeLabel:e.badgeLabel}))}function wN(e){let t=xN(e.skillRecords,e.recentSkillValues??[]),n=new Set(e.groupedRecentSkillValues??[]),r=CN(t.filter(e=>n.has(e.key))),i=CN(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:CN(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 TN=`$`;function EN(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 DN(){return Hv()}function ON(e){return Uv(e)}function kN(e){return Kv(e)}function AN(e){return qv(e,`skill`)}function jN(e){return qv(e,`file`)}function MN(e,t,n){let r=new Set(t),i=ey(e,e=>e.tokenKind===`skill`&&!r.has(e.tokenKey)),a=qv(i,`skill`),o=new Map(n.map(e=>[e.ref,e])),s=t.filter(e=>!a.includes(e)).map(e=>Bv({tokenKind:`skill`,tokenKey:e,label:o.get(e)?.name||e}));return s.length===0?i:Wv([...i,...s])}function NN(e,t){let n=new Set(t.map(e=>e.id));return ey(e,e=>e.tokenKind===`file`&&!n.has(e.tokenKey))}function PN(e,t){let n=new Set(jN(e));return t.filter(e=>n.has(e.id))}function FN(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[];for(let t of e){if(t.type===`text`){r=EN(r,t.text);continue}if(t.tokenKind===`skill`){r=EN(r,`${TN}${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 IN={isProviderStateResolved:!1,composerNodes:DN(),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:[],composerFocusRequest:null},Z=m(e=>({snapshot:IN,setSnapshot:t=>e(e=>({snapshot:{...e.snapshot,...t}}))})),LN=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}}},RN=new LN({storageKey:`nextclaw.chat.recent-models`,limit:3}),zN=new LN({storageKey:`nextclaw.chat.recent-skills`,limit:5});function BN(e){return e.modelOptions.length>0}function VN(e){return!e.isProviderStateResolved&&!BN(e)}function HN(e){return e.isProviderStateResolved&&!BN(e)}function UN(e){return!1}function WN(e){let{hasSendableDraft:t,isRuntimeBlocked:n}=e;return n||!t}var GN=`nextclaw.chat.session-list.mode`,KN=`time-first`;function qN(e){return e===`time-first`||e===`project-first`}function JN(e){if(!e||typeof e!=`object`)return null;let{snapshot:t}=e;return!t||typeof t!=`object`?null:qN(t.listMode)?t.listMode:null}function YN(e,t){let n=e?.trim();if(!n)return!1;let r=t?.trim();return r?n.localeCompare(r)>0:!1}function XN(e){let{active:t,readAt:n,runStatus:r,lastMessageAt:i}=e;return t||r===`running`?!1:YN(i,n)}var ZN={selectedSessionKey:null,selectedAgentId:`main`,query:``,listMode:KN};function QN(e){return t=>e(e=>({snapshot:{...e.snapshot,...t}}))}function $N(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 eP=m()(Tn(e=>({snapshot:ZN,optimisticReadAtBySessionKey:{},setSnapshot:QN(e),markSessionRead:$N(e)}),{name:GN,storage:On(()=>window.localStorage),partialize:e=>({snapshot:{listMode:e.snapshot.listMode}}),merge:(e,t)=>{let n=JN(e);return n?{...t,snapshot:{...t.snapshot,listMode:n}}:t}})),tP={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,sessionWorkingDir:null,sessionProjectName:null,canDeleteSession:!1,isDeletePending:!1,threadRef:null,isHistoryLoading:!1,messages:[],isSending:!1,isAwaitingAssistantOutput:!1,hasSubmittedDraftMessage:!1,parentSessionKey:null,parentSessionLabel:null,workspacePanelParentKey:null,activeWorkspacePanelKind:null,childSessionTabs:[],activeChildSessionKey:null,workspaceFileTabs:[],activeWorkspaceFileKey:null,contextWindow:null},Q=m(e=>({snapshot:tP,setSnapshot:t=>e(e=>({snapshot:{...e.snapshot,...t}}))}));function nP(e){return e>=1e6?`${(e/1e6).toFixed(e>=1e7?0:1)}M`:e>=1e3?`${(e/1e3).toFixed(e>=1e4?0:1)}k`:String(e)}function rP(e){if(!e||e.totalContextTokens<=0)return null;let t=e.usedContextTokens/e.totalContextTokens,n=Math.max(0,Math.min(1,t)),r=`${Math.round(n*100)}%`,i=n>=.9?`danger`:n>=.75?`warning`:`neutral`,a=[{label:s(`chatContextWindowUsed`),value:nP(e.usedContextTokens)},{label:s(`chatContextWindowTotal`),value:nP(e.totalContextTokens)},{label:s(`chatContextWindowAvailable`),value:nP(e.availableContextTokens)}];return e.prunedUsedContextTokens!==e.usedContextTokens&&a.push({label:s(`chatContextWindowPruned`),value:nP(e.prunedUsedContextTokens)}),e.droppedHistoryCount>0&&a.push({label:s(`chatContextWindowDroppedHistory`),value:String(e.droppedHistoryCount)}),e.truncatedToolResultCount>0&&a.push({label:s(`chatContextWindowTruncatedTools`),value:String(e.truncatedToolResultCount)}),{label:s(`chatContextWindow`),percentLabel:r,ratio:n,tone:i,details:a}}function iP(){let e=eP(e=>e.snapshot.selectedSessionKey),t=Q(e=>e.snapshot.sessionKey),n=Q(e=>e.snapshot.contextWindow);return(0,F.useMemo)(()=>e&&t===e&&n?rP(n):null,[n,t,e])}function aP(e){return e.bootstrapStatus?.ncpAgent.state!==`ready`}function oP(e){return e.activeSystemAction?.message?.trim()||(e.lifecyclePhase===`cold-starting`?s(`chatRuntimeInitializing`):e.lifecyclePhase===`startup-failed`?e.bootstrapStatus?.ncpAgent.error?.trim()||e.bootstrapStatus?.lastError?.trim()||e.lastError?.trim()||s(`chatRuntimeInitializationFailed`):null)}function sP(e){let{message:t,status:n}=e,r=t?.trim();if(!r)return oP(n);let i=n.activeSystemAction?.message?.trim();if(n.phase===`service-transitioning`&&i)return i;let a=st(r);return n.phase===`recovering`&&a?s(`runtimeControlRecoveringHelp`):n.phase===`stalled`&&a?null:r}function cP(){return{off:s(`chatThinkingLevelOff`),minimal:s(`chatThinkingLevelMinimal`),low:s(`chatThinkingLevelLow`),medium:s(`chatThinkingLevelMedium`),high:s(`chatThinkingLevelHigh`),adaptive:s(`chatThinkingLevelAdaptive`),xhigh:s(`chatThinkingLevelXhigh`)}}function lP(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 uP(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 dP(e){return{skillScopeLabels:(0,F.useMemo)(()=>({builtin:s(`chatSkillScopeBuiltin`),project:s(`chatSkillScopeProject`),workspace:s(`chatSkillScopeWorkspace`)}),[e]),slashTexts:(0,F.useMemo)(()=>({slashSkillSubtitle:s(`chatSlashTypeSkill`),slashSkillSpecLabel:s(`chatSlashSkillSpec`),slashSkillScopeLabel:s(`chatSlashSkillScope`),noSkillDescription:s(`chatSkillsPickerNoDescription`)}),[e]),recentModelsLabel:s(`chatPickerRecentModels`),allModelsLabel:s(`chatPickerAllModels`),recentSkillsLabel:s(`chatPickerRecent`),allSkillsLabel:s(`chatPickerAllSkills`)}}function fP(e,t){let n=(0,F.useMemo)(()=>lP(e.skillRecords,t),[e.skillRecords,t]),r=(0,F.useMemo)(()=>uP(e.modelOptions),[e.modelOptions]);return{skillRecords:n,modelRecords:r,recentModelValues:RN.resolveVisible({availableValues:r.map(e=>e.value),minAvailableCount:5}),recentSkillValues:zN.resolveVisible({availableValues:n.map(e=>e.key),minAvailableCount:0}),recentSkillGroupValues:zN.resolveVisible({availableValues:n.map(e=>e.key),minAvailableCount:4})}}function pP(e){let{attachmentSupported:t,inputBarRef:n,presenter:r}=e,i=(0,F.useCallback)(e=>{if(e===`unsupported-type`){N.error(s(`chatInputAttachmentUnsupported`));return}if(e===`too-large`){N.error(s(`chatInputAttachmentTooLarge`).replace(`{maxMb}`,String(iN/(1024*1024))));return}N.error(s(`chatInputAttachmentReadFailed`))},[]),a=(0,F.useCallback)(async e=>{if(!t||e.length===0)return;let a=await lN(e,{uploadBatch:yt});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,F.useCallback)(async e=>{let t=Array.from(e.target.files??[]);e.currentTarget.value=``,await a(t)},[a])}}function mP(e){let{allModelsLabel:t,hasModelOptions:n,isModelOptionsLoading:r,modelRecords:i,presenter:a,recentModelValues:o,recentModelsLabel:c,selectedModel:l,selectedThinkingLevel:u,thinkingSupportedLevels:d,thinkingDefaultLevel:f}=e;return[pN({modelOptions:i,recentModelValues:o,selectedModel:l,isModelOptionsLoading:r,hasModelOptions:n,onValueChange:a.chatInputManager.selectModel,texts:{modelSelectPlaceholder:s(`chatSelectModel`),modelNoOptionsLabel:s(`chatModelNoOptions`),recentModelsLabel:c,allModelsLabel:t}}),mN({supportedLevels:d,selectedThinkingLevel:u,defaultThinkingLevel:f,onValueChange:e=>a.chatInputManager.selectThinkingLevel(e),texts:{thinkingLabels:cP()}})].filter(e=>e!==null)}function hP(e){let{allSkillsLabel:t,presenter:n,recentSkillGroupValues:r,recentSkillValues:i,recentSkillsLabel:a,skillRecords:o,snapshot:c}=e;return wN({skillRecords:o,recentSkillValues:i,groupedRecentSkillValues:r,selectedSkills:c.selectedSkills,isLoading:c.isSkillsLoading,onSelectedKeysChange:n.chatInputManager.selectSkills,texts:{title:s(`chatSkillsPickerTitle`),searchPlaceholder:s(`chatSkillsPickerSearchPlaceholder`),emptyLabel:s(`chatSkillsPickerEmpty`),loadingLabel:s(`sessionsLoading`),manageLabel:s(`chatSkillsPickerManage`),recentSkillsLabel:a,allSkillsLabel:t}})}function gP(){let e=ic(),{language:t}=kr(),{isMobile:n}=Pr(),r=Z(e=>e.snapshot),i=aP(bt()),[a,o]=(0,F.useState)(null),c=(0,F.useRef)(null),l=(0,F.useRef)(null),u=dP(t),{skillRecords:d,modelRecords:f,recentModelValues:p,recentSkillValues:m,recentSkillGroupValues:h}=fP(r,u.skillScopeLabels),g=BN(r),_=VN(r),v=HN(r),y=UN(r),b=typeof e.chatInputManager.addAttachments==`function`,x=s(v?`chatModelNoOptions`:n?`chatInputPlaceholderCompact`:`chatInputPlaceholder`),S=(0,F.useMemo)(()=>SN(d,a??``,u.slashTexts,m),[u.slashTexts,m,d,a]),C=iP(),w=f.find(e=>e.value===r.selectedModel),T=w?.thinkingCapability?.supported??[],E=r.stopDisabledReason===`__preparing__`?s(`chatStopPreparing`):r.stopDisabledReason?.trim()||s(`chatStopUnavailable`),{handleFilesAdd:D,handleFileInputChange:O}=pP({attachmentSupported:b,inputBarRef:c,presenter:e});(0,F.useEffect)(()=>{let t=r.composerFocusRequest;t&&(t.placement===`end`&&c.current?.focusComposerAtEnd(),e.chatInputManager.consumeComposerFocusRequest(t.id))},[e.chatInputManager,r.composerFocusRequest]);let k=mP({allModelsLabel:u.allModelsLabel,hasModelOptions:g,isModelOptionsLoading:_,modelRecords:f,presenter:e,recentModelValues:p,recentModelsLabel:u.recentModelsLabel,selectedModel:r.selectedModel,selectedThinkingLevel:r.selectedThinkingLevel,thinkingSupportedLevels:T,thinkingDefaultLevel:w?.thinkingCapability?.default??null}),A=hP({allSkillsLabel:u.allSkillsLabel,presenter:e,recentSkillGroupValues:h,recentSkillValues:m,recentSkillsLabel:u.recentSkillsLabel,skillRecords:d,snapshot:r}),ee=r.draft.trim().length>0||r.attachments.length>0||AN(r.composerNodes).length>0;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(Py,{ref:c,composer:{nodes:r.composerNodes,placeholder:x,disabled:y,onNodesChange:e.chatInputManager.setComposerNodes,...b?{onFilesAdd:D}:{},onSlashQueryChange:o},slashMenu:{isLoading:r.isSkillsLoading,items:S,onSelectItem:t=>{t.value&&e.chatInputManager.rememberSkillSelection(t.value)},texts:{slashLoadingLabel:s(`chatSlashLoading`),slashSectionLabel:s(`chatSlashSectionSkills`),slashEmptyLabel:s(`chatSlashNoResult`),slashHintLabel:s(`chatSlashHint`),slashSkillHintLabel:s(`chatSlashSkillHint`)}},hint:fN({isModelOptionsLoading:_,isModelOptionsEmpty:v,onGoToProviders:e.chatInputManager.goToProviders,texts:{noModelOptionsLabel:s(`chatModelNoOptions`),configureProviderLabel:s(`chatGoConfigureProvider`)}}),toolbar:{selects:k,accessories:[{key:`attach`,label:s(`chatInputAttach`),icon:`paperclip`,iconOnly:!0,disabled:!b||y||r.isSending,...b?{onClick:()=>l.current?.click()}:{tooltip:s(`chatInputAttachComingSoon`)}}],skillPicker:A,actions:{sendError:i?null:r.sendError,isSending:r.isSending,canStopGeneration:r.canStopGeneration,sendDisabled:WN({snapshot:r,hasSendableDraft:ee,isRuntimeBlocked:i}),stopDisabled:!r.canStopGeneration,stopHint:E,sendButtonLabel:s(`chatSend`),stopButtonLabel:s(`chatStop`),contextWindow:C,onSend:e.chatInputManager.send,onStop:e.chatInputManager.stop}}}),b?(0,I.jsx)(`input`,{ref:l,type:`file`,multiple:!0,className:`hidden`,onChange:O}):null]})}var _P=[`cmd`,`command`,`query`,`q`,`path`,`url`,`to`,`channel`,`agentId`,`sessionKey`];function vP(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function yP(e,t=2400){return e.length<=t?e:`${e.slice(0,t)}\n…`}function bP(e,t=120){let n=e.replace(/\s+/g,` `).trim();return n.length<=t?n:t<=1?`…`:`${n.slice(0,t-1)}…`}function xP(e){if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);if(e==null)return``;try{return yP(JSON.stringify(e,null,2))}catch{return String(e)}}function SP(e){if(vP(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 vP(e)?e:null}catch{return null}}function CP(e){let t=SP(e);if(!t){let t=xP(e).trim();return t?bP(t,120):void 0}let n=[];for(let e of _P){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?bP(n.join(` · `),120):bP(xP(t),140)}var wP=`ui_inline_tokens`,TP=`$`;function EP(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function DP(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function OP(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 kP(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:`${TP}${n.tokenKey}`});return OP(t)}function AP(e){let t=e?.[wP];if(!Array.isArray(t))return[];let n=[];for(let e of t){if(!EP(e))continue;let t=DP(e.kind),r=DP(e.key),i=DP(e.rawText);!t||!r||!i||n.push({kind:t,key:r,rawText:i,label:DP(e.label)??r})}return OP(n)}function jP(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 MP=/\u200B|\u200C|\u200D|\u2060|\uFEFF/g;function NP(e){let t=e.trim();return t&&t.replace(MP,``).trim()?t:null}function PP(e){return e.replace(MP,``).trim().length>0}function FP(e,t){let n=jP(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&&(PP(e.text)&&(i=!0),r.push({type:`markdown`,text:e.text}))}return i?r:null}function IP(e,t){let n=FP(e.text,t);if(n&&n.some(e=>e.type===`token`))return{type:`inline-content`,segments:n};let r=NP(e.text);return r?{type:`markdown`,text:r}:null}function LP(e){return NP(e)}function RP(e){return typeof e==`object`&&!!e}function zP(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function BP(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 VP(e){return RP(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 HP(e,t){if(!RP(e))return null;let n=RP(e.asset)?e.asset:Array.isArray(e.assets)&&e.assets.length>0&&RP(e.assets[0])?e.assets[0]:null;if(!n)return null;let r=zP(n.url),i=zP(n.mimeType)??`application/octet-stream`,a=BP(n.sizeBytes);return r?{type:`file`,file:{label:zP(n.name)??(i.startsWith(`image/`)?t.imageAttachmentLabel:t.fileAttachmentLabel),mimeType:i,dataUrl:r,...a==null?{}:{sizeBytes:a},isImage:i.startsWith(`image/`)}}:null}function UP(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 WP(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 GP(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 KP(e,t){return xP(t??GP(e)).trim()||void 0}function qP(e){return typeof e==`object`&&!!e}function JP(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 YP(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function XP(e){let t=JP(e);return qP(t)?YP(t.agentId):null}function ZP(e){return XP(e.parsedArgs)??XP(e.args)??XP(e.result)}var QP=12e3,$P=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/;function eF(e){let t=e.replace(/\r\n/g,`
|
|
92
92
|
`).replace(/\r/g,`
|
|
93
93
|
`);return t===``?[]:t.split(`
|
|
94
94
|
`)}function tF(e){return typeof e==`number`?e+1:void 0}function nF(e){return{kind:e.kind,text:e.text,...typeof e.oldLineNumber==`number`?{oldLineNumber:e.oldLineNumber}:{},...typeof e.newLineNumber==`number`?{newLineNumber:e.newLineNumber}:{}}}function rF(e){let t=$P.exec(e);return t?{oldLineNumber:Number(t[1]),newLineNumber:Number(t[2])}:null}function iF(e){return eF(e.text).map((t,n)=>e.kind===`add`?nF({kind:`add`,text:t,newLineNumber:e.newStartLine+n}):nF({kind:`context`,text:t,oldLineNumber:e.oldStartLine+n,newLineNumber:e.newStartLine+n}))}function aF(e){let t=e.oldStartLine,n=e.newStartLine;return[...e.beforeLines.map(e=>{let n=nF({kind:`remove`,text:e,oldLineNumber:t});return t=tF(t),n}),...e.afterLines.map(e=>{let t=nF({kind:`add`,text:e,newLineNumber:n});return n=tF(n),t})]}function oF(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 sF(e){for(let t=e.beforeIndex;t<e.beforeLines.length;t+=1)e.lines.push(nF({kind:`remove`,text:e.beforeLines[t]??``,oldLineNumber:e.oldLineNumber})),e.oldLineNumber=tF(e.oldLineNumber);for(let t=e.afterIndex;t<e.afterLines.length;t+=1)e.lines.push(nF({kind:`add`,text:e.afterLines[t]??``,newLineNumber:e.newLineNumber})),e.newLineNumber=tF(e.newLineNumber)}function cF(e){let t=eF(e.beforeText),n=eF(e.afterText);if(t.length*n.length>QP)return aF({beforeLines:t,afterLines:n,oldStartLine:e.oldStartLine,newStartLine:e.newStartLine});let r=oF({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(nF({kind:`context`,text:t[a]??``,oldLineNumber:s,newLineNumber:c})),a+=1,o+=1,s=tF(s),c=tF(c);continue}if((r[a+1][o]??0)>=(r[a][o+1]??0)){i.push(nF({kind:`remove`,text:t[a]??``,oldLineNumber:s})),a+=1,s=tF(s);continue}i.push(nF({kind:`add`,text:n[o]??``,newLineNumber:c})),o+=1,c=tF(c)}return sF({lines:i,beforeLines:t,afterLines:n,beforeIndex:a,afterIndex:o,oldLineNumber:s,newLineNumber:c}),i}var lF=120;function uF(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 dF(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 fF(e){return e.length<=lF?{lines:e,truncated:!1}:{lines:e.slice(0,lF),truncated:!0}}function pF(e){let t=fF(e.lines);return{path:e.path,display:`diff`,caption:uF({operation:e.operation,lines:e.lines}),lines:t.lines,...t.truncated?{fullLines:e.lines}:{},truncated:t.truncated}}function mF(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=iF({text:t,kind:n,oldStartLine:r,newStartLine:i});return{path:e.path,display:`preview`,caption:uF({operation:e.operation,lines:a}),lines:a,rawText:t,oldStartLine:r,newStartLine:i}}function hF(e){let{oldStartLine:t,newStartLine:n}=dF(e),r=cF({beforeText:e.beforeText??``,afterText:e.afterText??``,oldStartLine:t,newStartLine:n}),i=fF(r);return i.lines.length===0?null:{path:e.path,display:`diff`,caption:uF({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 gF(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 _F(e){let{currentLines:t,line:n}=e;return n.startsWith(`+`)?(t.push(nF({kind:`add`,text:n.slice(1),newLineNumber:e.newLineNumber})),{oldLineNumber:e.oldLineNumber,newLineNumber:tF(e.newLineNumber)}):n.startsWith(`-`)?(t.push(nF({kind:`remove`,text:n.slice(1),oldLineNumber:e.oldLineNumber})),{oldLineNumber:tF(e.oldLineNumber),newLineNumber:e.newLineNumber}):n.startsWith(` `)?(t.push(nF({kind:`context`,text:n.slice(1),oldLineNumber:e.oldLineNumber,newLineNumber:e.newLineNumber})),{oldLineNumber:tF(e.oldLineNumber),newLineNumber:tF(e.newLineNumber)}):{oldLineNumber:e.oldLineNumber,newLineNumber:e.newLineNumber}}function vF(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(pF({path:n,operation:r,lines:i})),n=null,r=null,i=[],a=void 0,o=void 0};for(let t of eF(e)){if(gF({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=rF(t);a=e?.oldLineNumber,o=e?.newLineNumber;continue}if(!n)continue;let e=_F({currentLines:i,line:t,oldLineNumber:a,newLineNumber:o});a=e.oldLineNumber,o=e.newLineNumber}return s(),t}function yF(e){let t=[],n=null,r=[],i,a,o=()=>{if(!n){r=[],i=void 0,a=void 0;return}t.push(pF({path:n,operation:`update`,lines:r})),n=null,r=[],i=void 0,a=void 0};for(let t of eF(e)){if(t.startsWith(`+++ `)){o(),n=t.slice(4).trim().replace(/^b\//,``).replace(/^a\//,``);continue}if(t.startsWith(`--- `))continue;if(t.startsWith(`@@`)){let e=rF(t);i=e?.oldLineNumber,a=e?.newLineNumber;continue}if(!n)continue;let e=_F({currentLines:r,line:t,oldLineNumber:i,newLineNumber:a});i=e.oldLineNumber,a=e.newLineNumber}return o(),t}function bF(e){return e.includes(`*** Begin Patch`)?vF(e):e.includes(`--- `)&&e.includes(`+++ `)?yF(e):[]}function xF(e){switch(e){case`"`:case`\\`:case`/`:return e;case`b`:return`\b`;case`f`:return`\f`;case`n`:return`
|
|
@@ -96,6 +96,6 @@ https://github.com/highlightjs/highlight.js/issues/2277`),i=e,r=t),n===void 0&&(
|
|
|
96
96
|
|
|
97
97
|
`):void 0}function rI(e){let t=YF(e.sessionId),n=YF(e.title),r=YF(e.sessionType),i=YF(e.lifecycle),a=YF(e.parentSessionId),o=YF(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(`
|
|
98
98
|
|
|
99
|
-
`):void 0}function iI(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=XF(o);if(s){let e=YF(s.status)?.toLowerCase(),t=eI(s,a),o=nI(s),c=YF(s.sessionId),l=ZP({args:a,result:s}),u=c?{kind:`open-session`,sessionId:c,sessionKind:s.isChildSession===!0?`child`:`session`,...l?{agentId:l}:{},...YF(s.title)?{label:s.title.trim()}:{},...YF(s.parentSessionId)?{parentSessionId:s.parentSessionId.trim()}:{}}:void 0;return e===`failed`?{kind:`result`,name:r,detail:t,input:$F(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:$F(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:$F(a),text:o,callId:i||void 0,hasResult:!!o,statusTone:`running`,statusLabel:n.toolStatusRunningLabel,...l?{agentId:l}:{},...u?{action:u}:{}}}let c=ZF(o);if(!c)return null;let l=tI(c,a),u=rI(c),d=YF(c.sessionId),f=ZP({args:a,result:c}),p=d?{kind:`open-session`,sessionId:d,sessionKind:c.isChildSession===!0?`child`:`session`,...f?{agentId:f}:{},...YF(c.title)?{label:c.title.trim()}:{},...YF(c.parentSessionId)?{parentSessionId:c.parentSessionId.trim()}:{}}:void 0;return{kind:`result`,name:r,detail:l,input:$F(a),text:u,callId:i||void 0,hasResult:!!u,statusTone:`success`,statusLabel:n.toolStatusCompletedLabel,...f?{agentId:f}:{},...p?{action:p}:{}}}function aI(e){let t=typeof e==`object`&&e&&!Array.isArray(e)?e.error:null;return typeof t==`object`&&t&&!Array.isArray(t)&&t.code===`invalid_tool_arguments`?t:null}function oI(e,t){let n=LP(e.reasoning);return n?{type:`reasoning`,text:n,label:t.reasoningLabel}:null}function sI(e,t){let n=e.mimeType.startsWith(`image/`),r=BP(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 cI(e,t){let n=e.toolInvocation,r=HP(n.result,t);if(r)return r;let i=iI({invocation:n,texts:{toolStatusRunningLabel:t.toolStatusRunningLabel,toolStatusCompletedLabel:t.toolStatusCompletedLabel,toolStatusFailedLabel:t.toolStatusFailedLabel}});if(i)return{type:`tool-card`,card:UP(i,t)};let a=WP({status:n.status,error:n.error,cancelled:n.cancelled,result:n.result,texts:t}),o=aI(n.result),s=Array.isArray(o?.issues)?o.issues.find(e=>typeof e==`string`&&e.trim().length>0):void 0,c=qF({toolName:n.toolName,status:n.status,toolCallId:n.toolCallId,args:n.args,parsedArgs:n.parsedArgs,result:n.result}),l=s?`Invalid arguments: ${s}`:c?.summary??CP(n.parsedArgs??n.args),u=c?void 0:KP(n.args,n.parsedArgs),d=s||(typeof n.error==`string`&&n.error.trim()?n.error.trim():n.result==null?``:xP(n.result).trim()),f=!n.error&&VP(n.result),p=(!c?.fileOperation||!!n.error)&&!f,m=ZP(n);return{type:`tool-card`,card:UP({kind:a.kind,name:n.toolName,...m?{agentId:m}:{},detail:l,...u?{input:u}:{},text:p&&d?d:void 0,outputData:n.result,callId:n.toolCallId||void 0,hasResult:a.hasResult,statusTone:o?`error`:a.statusTone,statusLabel:o?t.toolStatusFailedLabel:a.statusLabel,...c?.fileOperation?{fileOperation:c.fileOperation}:{}},t)}}function lI(e,t){return{type:`unknown`,label:t.unknownPartLabel,rawType:typeof e.type==`string`?e.type:`unknown`,text:xP(e)}}function uI(e){return e.type===`text`&&typeof e.text==`string`}function dI(e){return e.type===`reasoning`&&typeof e.reasoning==`string`}function fI(e){return e.type===`file`&&typeof e.mimeType==`string`&&typeof e.data==`string`}function pI(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 mI(e){let{inlineTokens:t,part:n,texts:r}=e;return uI(n)?IP(n,t):dI(n)?oI(n,r):fI(n)?sI(n,r):pI(n)?cI(n,r):lI(n,r)}function hI(e){let t=e.meta?.timestamp;return t&&Number.isFinite(Date.parse(t))?t:new Date().toISOString()}function gI(e,t){return e===`user`?t.user:e===`assistant`?t.assistant:e===`tool`?t.tool:e===`system`?t.system:t.fallback}function _I(e){return e===`user`||e===`assistant`||e===`tool`||e===`system`?e:`message`}function vI(e,t){return{id:e.id,role:_I(e.role),roleLabel:gI(e.role,t.texts.roleLabels),timestampLabel:t.formatTimestamp(hI(e)),status:e.meta?.status,parts:e.parts.map(n=>mI({part:n,inlineTokens:e.meta?.inlineTokens??[],texts:t.texts})).filter(e=>e!==null)}}var yI=function(e){return e.CALL=`call`,e.RESULT=`result`,e.PARTIAL_CALL=`partial-call`,e.ERROR=`error`,e.CANCELLED=`cancelled`,e}({});function bI(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function xI(e){return bI(e)}function SI(e){let t=bI(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 CI(e){return/^[A-Za-z]:[\\/]?$/.test(e)||e===`/`?e:e.replace(/[\\/]+$/,``)}function wI(e){let t=CI(e.trim().replace(/\\/g,`/`));return/^[A-Za-z]:/.test(t)?`${t.slice(0,1).toLowerCase()}${t.slice(1)}`:t}function TI(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 EI(e){let t=wI(e.path),n=wI(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 DI(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 OI(e){let{column:t,line:n}=e;return typeof n==`number`?`L${n}${typeof t==`number`?`:${t}`:``}`:null}function kI(e){let{column:t,line:n,path:r,sessionProjectRoot:i,truncated:a}=e,o=r.trim(),s=i?.trim()&&o?EI({path:o,sessionProjectRoot:i}):null,c;if(i?.trim()&&s){let e=SI(i)??i.trim();c=DI({labels:s,leading:{key:`workspace:${e}`,label:e,kind:`workspace`,isCurrent:s.length===0}})}else{let{prefix:e,segments:t}=TI(o);c=DI({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:OI({line:n,column:t}),truncated:a,segments:c}}var AI=new Set([`off`,`minimal`,`low`,`medium`,`high`,`adaptive`,`xhigh`]),jI=new Set([`running`,`completed`,`failed`,`idle`]);function MI(e){if(typeof e==`string`)return e;try{return JSON.stringify(e??{})}catch{return String(e??``)}}function NI(e){return`${he}/api/ncp/assets/content?${new URLSearchParams({uri:e}).toString()}`}function PI(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function FI(e){let{metadata:t}=e;return!t||typeof t!=`object`||Array.isArray(t)?null:t}function II(e){let t=FI(e)?.last_activity_preview;if(!t||typeof t!=`object`||Array.isArray(t))return null;let n=t,{state:r}=n,i=PI(n.timestamp);if(!jI.has(r)||!i)return null;let a=PI(n.statusText),o=PI(n.replyText);return{state:r,timestamp:i,...a?{statusText:a}:{},...o?{replyText:o}:{}}}function LI(e){let t=FI(e);return t?PI(t.preferred_model)??PI(t.preferredModel)??PI(t.model):null}function RI(e){let t=FI(e);if(!t)return null;let n=PI(t.preferred_thinking)??PI(t.thinking)??PI(t.thinking_level)??PI(t.thinkingLevel);if(!n)return null;let r=n.toLowerCase();return AI.has(r)?r:null}function zI(e){let t=FI(e);return t?PI(t.label):null}function BI(e){let t=FI(e);return t?xI(t.project_root??t.projectRoot):null}function VI(e){let t=FI(e);return t?PI(t.ui_last_read_at):null}function HI(e){let t=FI(e);return t?PI(t.runtime)??PI(t.session_type)??PI(t.sessionType)??`native`:`native`}function UI(e){let t=FI(e);return t?PI(t.parent_session_id)??PI(t.parentSessionId):null}function WI(e){let t=FI(e);return t?PI(t.spawned_by_request_id)??PI(t.spawnedByRequestId):null}function GI(e){let t=FI(e);return t?t.child_session_promoted===!0:!1}function KI(e){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 qI(e){return e.state===`cancelled`?yI.CANCELLED:e.state===`result`?yI.RESULT:e.state===`partial-call`?yI.PARTIAL_CALL:yI.CALL}function JI(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:NI(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:qI(n),toolCallId:n.toolCallId??`${n.toolName}-${Math.random().toString(36).slice(2,8)}`,toolName:n.toolName,args:MI(n.args),result:n.result}})}return t}function YI(e){return e===`service`?`system`:e===`tool`?`assistant`:e}function XI(e){return{id:e.id,role:YI(e.role),parts:JI(e.parts),meta:{source:`stream`,status:e.status,sessionKey:e.sessionId,timestamp:e.timestamp}}}function ZI(e){let t=zI(e),n=LI(e),r=RI(e),i=BI(e),a=VI(e),o=PI(e.lastMessageAt),s=SI(i),c=KI(e.sessionId),l=UI(e),u=WI(e),d=GI(e),f=II(e);return{key:e.sessionId,createdAt:e.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:HI(e),sessionTypeMutable:!1,status:e.status??`idle`,isChildSession:!!l,...d?{isPromotedChildSession:d}:{},...l?{parentSessionId:l}:{},...u?{spawnedByRequestId:u}:{},...f?{activityPreview:f}:{},messageCount:e.messageCount}}function QI(e){return e.map(ZI)}function $I(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function eL(e){if(typeof e!=`number`||!Number.isFinite(e))return null;let t=Math.trunc(e);return t>=0?t:null}function tL(e){return e===!0}function nL(e){let t=e;if(!t||typeof t!=`object`||Array.isArray(t))return null;let n=t,r=eL(n.usedContextTokens),i=eL(n.totalContextTokens),a=eL(n.prunedUsedContextTokens),o=$I(n.updatedAt);if(r===null||i===null||a===null||!o)return null;let s=eL(n.compactedUsedContextTokens);return{usedContextTokens:r,totalContextTokens:i,prunedUsedContextTokens:a,availableContextTokens:eL(n.availableContextTokens)??Math.max(0,i-r),droppedHistoryCount:eL(n.droppedHistoryCount)??0,truncatedToolResultCount:eL(n.truncatedToolResultCount)??0,truncatedSystemPrompt:tL(n.truncatedSystemPrompt),truncatedUserMessage:tL(n.truncatedUserMessage),compacted:tL(n.compacted),...$I(n.checkpointId)?{checkpointId:$I(n.checkpointId)??void 0}:{},compactedMessageCount:eL(n.compactedMessageCount)??0,...s===null?{}:{compactedUsedContextTokens:s},updatedAt:o}}function rL(e){let{metadata:t}=e;if(!t||t.nextclaw_timeline_kind!==`context_compaction`)return null;let n=t.checkpoint&&typeof t.checkpoint==`object`&&!Array.isArray(t.checkpoint)?t.checkpoint:null;if(!n)return null;let r=$I(n.id),i=n.status===`compressing`?`compressing`:n.status===`compressed`?`compressed`:null,a=$I(n.summary),o=eL(n.coveredMessageCount),s=eL(n.coveredSessionMessageCount),c=eL(n.originalEstimatedTokens),l=eL(n.projectedEstimatedTokens),u=$I(n.createdAt),d=$I(n.updatedAt);return!r||!i||!a||o===null||s===null||c===null||l===null||!u||!d?null:{id:r,status:i,summary:a,coveredMessageCount:o,coveredSessionMessageCount:s,originalEstimatedTokens:c,projectedEstimatedTokens:l,createdAt:u,updatedAt:d}}function iL(){return Ve({queryKey:[`agents`],queryFn:ut,staleTime:3e4})}function aL(){let e=Fe();return me({mutationFn:({agentId:e,data:t})=>pt(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`agents`]}),e.invalidateQueries({queryKey:[`config`]}),N.success(s(`configSavedApplied`))},onError:e=>{N.error(s(`configSaveFailed`)+`: `+e.message)}})}function oL(){let e=Fe();return me({mutationFn:({agentId:e})=>Je(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`agents`]}),e.invalidateQueries({queryKey:[`config`]}),N.success(s(`configSavedApplied`))},onError:e=>{N.error(s(`configSaveFailed`)+`: `+e.message)}})}function sL(e,t){return new Map([...t,...e].filter(e=>typeof e.id==`string`&&e.id.trim().length>0).map(e=>[e.id,e]))}function cL(e){let t=e?.trim()??``,n=Q(e=>e.snapshot.availableAgents??[]),r=iL(),i=(0,F.useMemo)(()=>sL(n,r.data?.agents??[]),[r.data?.agents,n]);return(0,F.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 lL({agentId:e,className:t}){let n=cL(e);return n?(0,I.jsx)(Vs,{agentId:n.agentId,displayName:n.displayName,avatarUrl:n.avatarUrl,className:t}):null}var uL=new WeakMap;function dL(e){return{roleLabels:{user:s(`chatRoleUser`),assistant:s(`chatRoleAssistant`),tool:s(`chatRoleTool`),system:s(`chatRoleSystem`),fallback:s(`chatRoleMessage`)},reasoningLabel:s(`chatReasoning`),toolCallLabel:s(`chatToolCall`),toolResultLabel:s(`chatToolResult`),toolInputLabel:s(`chatToolInput`),toolNoOutputLabel:s(`chatToolNoOutput`),toolOutputLabel:s(`chatToolOutput`),toolStatusPreparingLabel:s(`chatToolStatusPreparing`),toolStatusRunningLabel:s(`chatToolStatusRunning`),toolStatusCompletedLabel:s(`chatToolStatusCompleted`),toolStatusFailedLabel:s(`chatToolStatusFailed`),toolStatusCancelledLabel:s(`chatToolStatusCancelled`),imageAttachmentLabel:s(`chatImageAttachment`),fileAttachmentLabel:s(`chatFileAttachment`),unknownPartLabel:s(`chatUnknownPart`)}}function fL(e){return{copyCodeLabel:s(`chatCodeCopy`),copiedCodeLabel:s(`chatCodeCopied`),copyMessageLabel:s(`chatMessageCopy`),copiedMessageLabel:s(`chatMessageCopied`),typingLabel:s(`chatTyping`),attachmentOpenLabel:s(`chatAttachmentOpen`),attachmentAttachedLabel:s(`chatAttachmentAttached`),attachmentCategoryLabels:{archive:s(`chatAttachmentCategoryArchive`),audio:s(`chatAttachmentCategoryAudio`),code:s(`chatAttachmentCategoryCode`),data:s(`chatAttachmentCategoryData`),document:s(`chatAttachmentCategoryDocument`),generic:s(`chatAttachmentCategoryGeneric`),image:s(`chatAttachmentCategoryImage`),pdf:s(`chatAttachmentCategoryPdf`),sheet:s(`chatAttachmentCategorySheet`),video:s(`chatAttachmentCategoryVideo`)}}}function pL({checkpoint:e}){return(0,I.jsxs)(`div`,{className:`my-4 flex items-center gap-3 text-[11px] text-gray-500`,title:[`${s(`chatContextCompactionCoveredMessages`)}: ${e.coveredSessionMessageCount}`,`${s(`chatContextCompactionOriginalTokens`)}: ${e.originalEstimatedTokens}`,`${s(`chatContextCompactionProjectedTokens`)}: ${e.projectedEstimatedTokens}`].join(`
|
|
100
|
-
`),children:[(0,I.jsx)(`div`,{className:`h-px flex-1 bg-gray-200`}),(0,I.jsxs)(`div`,{className:`inline-flex items-center gap-2 rounded-full border border-gray-200 bg-gray-50 px-3 py-1`,children:[e.status===`compressing`?(0,I.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-gray-400 animate-pulse`}):(0,I.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-gray-300`}),(0,I.jsx)(`span`,{children:e.status===`compressing`?s(`chatContextCompactionCompressing`):s(`chatContextCompactionCompressed`)})]}),(0,I.jsx)(`div`,{className:`h-px flex-1 bg-gray-200`})]})}function mL(e){let{normalRawMessages:t,rawMessageId:n,rawMessages:r}=e,i=r.findIndex(e=>e.id===n);return i<0?t.length-1:r.slice(0,i).filter(e=>!rL(e)).length-1}function hL(e){let t=e.rawMessages.filter(e=>!rL(e)),n=e.rawMessages.map(e=>({rawMessageId:e.id,checkpoint:rL(e)})).filter(e=>!!e.checkpoint).map(n=>({key:n.rawMessageId,checkpoint:n.checkpoint,boundaryIndex:mL({rawMessages:e.rawMessages,normalRawMessages:t,rawMessageId:n.rawMessageId})})).sort((e,t)=>e.boundaryIndex-t.boundaryIndex),r=[],i=[],a=0,o=e=>{i.length!==0&&(r.push({kind:`messages`,key:e,messages:i}),i=[])};for(t.forEach((t,s)=>{let c=e.messages[s];for(c&&i.push(c);a<n.length&&n[a]?.boundaryIndex<=s;){let e=n[a];o(`messages-before-${e.key}`),r.push({kind:`compaction`,key:e.key,checkpoint:e.checkpoint}),a+=1}});a<n.length;){let e=n[a];o(`messages-before-${e.key}`),r.push({kind:`compaction`,key:e.key,checkpoint:e.checkpoint}),a+=1}return o(`messages-final`),r.length===0&&r.push({kind:`messages`,key:`messages-empty`,messages:[]}),r}function gL({messages:e,isSending:t,className:n,onToolAction:r,onFileOpen:i}){let{language:a}=kr(),o=(0,F.useMemo)(()=>dL(a),[a]),s=(0,F.useMemo)(()=>e.flatMap(e=>{if(rL(e))return[];let t=uL.get(e);if(t&&t.language===a)return[t.viewModel];let n=XI(e),r=vI({id:n.id,role:n.role,meta:{timestamp:n.meta?.timestamp,status:n.meta?.status,inlineTokens:AP(e.metadata)},parts:n.parts},{formatTimestamp:e=>u(e,a),texts:o});return uL.set(e,{language:a,viewModel:r}),[r]}),[a,e,o]),c=(0,F.useMemo)(()=>s.some(e=>e.role===`assistant`&&(e.status===`streaming`||e.status===`pending`)),[s]),l=(0,F.useMemo)(()=>fL(a),[a]),d=(0,F.useMemo)(()=>hL({rawMessages:e,messages:s}),[s,e]);return(0,I.jsx)(`div`,{className:n,children:d.map((e,n)=>e.kind===`compaction`?(0,I.jsx)(pL,{checkpoint:e.checkpoint},e.key):(0,I.jsx)(wM,{messages:e.messages,isSending:n===d.length-1?t:!1,hasAssistantDraft:c,texts:l,onToolAction:r,onFileOpen:i,renderToolAgent:e=>(0,I.jsx)(lL,{agentId:e,className:`h-4 w-4 shrink-0`})},e.key))})}function _L(){let e=Fe();return async t=>{let{sessionKey:n,patch:r,successMessage:i}=t;try{dt(e,await gt(n,r)),await e.invalidateQueries({queryKey:[`ncp-session-skills`,n]}),N.success(i??s(`configSavedApplied`))}catch(e){throw N.error(s(`configSaveFailed`)+`: `+(e instanceof Error?e.message:String(e))),e}}}function vL(){let e=_L();return async t=>{let{persistToServer:n,projectRoot:r,sessionKey:i}=t,a=s(r?`chatSessionProjectUpdated`:`chatSessionProjectCleared`);if(!n){Z.getState().setSnapshot({pendingProjectRoot:r,pendingProjectRootSessionKey:i}),N.success(a);return}await e({sessionKey:i,patch:{projectRoot:r},successMessage:a})}}function yL({icon:e,label:t,onClick:n,disabled:i=!1,destructive:a=!1}){return(0,I.jsxs)(`button`,{type:`button`,className:r(`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`,a?`text-destructive hover:bg-destructive/10`:`text-gray-700 hover:bg-gray-100`),onClick:n,disabled:i,children:[(0,I.jsx)(e,{className:`h-4 w-4 shrink-0`}),(0,I.jsx)(`span`,{children:t})]})}function bL(e){return Ve({queryKey:[`server-path-browse`,e.path??null,e.includeFiles??!1],queryFn:()=>mt({path:e.path,includeFiles:e.includeFiles}),enabled:e.enabled??!0,staleTime:0})}var xL=F.forwardRef(({className:e,children:t,...n},i)=>(0,I.jsx)(`div`,{ref:i,className:r(`overflow-auto`,e),...n,children:t}));xL.displayName=`ScrollArea`;function SL({open:e,currentPath:t,isSaving:n,onOpenChange:r,onConfirm:i,title:a,description:o,pathLabel:c,pathPlaceholder:l,confirmLabel:u,hint:d}){let[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(null),[g,_]=(0,F.useState)(``);(0,F.useEffect)(()=>{if(!e)return;let n=t?.trim()||null;p(n??``),h(n),_(``)},[t,e]);let v=bL({path:m,enabled:e});(0,F.useEffect)(()=>{!e||!v.data||f.trim().length===0&&p(v.data.currentPath)},[v.data,f,e]);let y=f.trim(),b=y.length===0||n,x=(0,F.useMemo)(()=>v.error?v.error instanceof Error?v.error.message:String(v.error):null,[v.error]),S=g.trim().toLowerCase(),C=(0,F.useMemo)(()=>{let e=v.data?.entries??[];return S.length===0?e:e.filter(e=>{let t=e.name.toLowerCase(),n=e.path.toLowerCase();return t.includes(S)||n.includes(S)})},[v.data?.entries,S]),w=e=>{h(e),_(``),e&&p(e)};return(0,I.jsx)(Gt,{open:e,onOpenChange:e=>{n||r(e)},children:(0,I.jsxs)(qt,{className:`max-h-[85vh] overflow-hidden sm:h-[42rem] sm:max-w-2xl sm:grid-rows-[auto_minmax(0,1fr)]`,children:[(0,I.jsxs)(Kt,{children:[(0,I.jsx)(Jt,{children:a}),o?(0,I.jsx)(Wt,{children:o}):null]}),(0,I.jsxs)(`form`,{className:`flex min-h-0 flex-col gap-4`,onSubmit:e=>{e.preventDefault(),!b&&i(y)},children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(Ae,{htmlFor:`server-path-picker-input`,children:c}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(Ne,{id:`server-path-picker-input`,value:f,onChange:e=>p(e.target.value),placeholder:l,autoFocus:!0,disabled:n}),(0,I.jsx)(ye,{type:`button`,variant:`outline`,onClick:()=>w(y||null),disabled:n,children:s(`openPath`)})]})]}),(0,I.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,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-gray-200 px-3 py-2`,children:[(0,I.jsxs)(ye,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>w(v.data?.homePath??null),disabled:n||v.isLoading,children:[(0,I.jsx)(sr,{className:`mr-1 h-4 w-4`}),s(`homeDirectory`)]}),(0,I.jsxs)(ye,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>w(v.data?.parentPath??null),disabled:!v.data?.parentPath||n||v.isLoading,children:[(0,I.jsx)(nr,{className:`mr-1 h-4 w-4`}),s(`parentDirectory`)]}),(0,I.jsxs)(ye,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{v.refetch()},disabled:n||v.isLoading,children:[(0,I.jsx)(k,{className:`mr-1 h-4 w-4`}),s(`chatRefresh`)]})]}),(0,I.jsxs)(`div`,{className:`border-b border-gray-200 px-3 py-2`,children:[(0,I.jsx)(`div`,{className:`mb-2 text-xs font-medium text-gray-500`,children:s(`currentDirectory`)}),(0,I.jsx)(`div`,{className:`flex flex-wrap items-center gap-1 text-xs text-gray-600`,children:v.data?.breadcrumbs.map((e,t)=>(0,I.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,I.jsx)(`button`,{type:`button`,className:`rounded px-1.5 py-0.5 hover:bg-gray-200`,onClick:()=>w(e.path),disabled:n,children:e.label}),t<v.data.breadcrumbs.length-1?(0,I.jsx)(Rn,{className:`h-3 w-3 text-gray-400`}):null]},e.path))})]}),(0,I.jsx)(`div`,{className:`border-b border-gray-200 px-3 py-2`,children:(0,I.jsxs)(`div`,{className:`relative`,children:[(0,I.jsx)(mn,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,I.jsx)(Ne,{value:g,onChange:e=>_(e.target.value),placeholder:s(`pathPickerSearchPlaceholder`),disabled:n||v.isLoading,className:`pl-9`})]})}),(0,I.jsx)(xL,{className:`min-h-0 flex-1 px-2 py-2`,children:v.isLoading?(0,I.jsx)(`div`,{className:`px-2 py-6 text-sm text-gray-500`,children:s(`loading`)}):x?(0,I.jsxs)(`div`,{className:`px-2 py-4 text-sm text-destructive`,children:[s(`pathBrowseFailed`),`: `,x]}):v.data&&C.length>0?(0,I.jsx)(`div`,{className:`space-y-1`,children:C.map(e=>(0,I.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:()=>w(e.path),disabled:n,children:[(0,I.jsx)(ir,{className:`h-4 w-4 shrink-0 text-emerald-600`}),(0,I.jsx)(`span`,{className:`truncate`,children:e.name})]},e.path))}):v.data&&v.data.entries.length>0?(0,I.jsx)(`div`,{className:`px-2 py-6 text-sm text-gray-500`,children:s(`pathPickerSearchEmpty`)}):(0,I.jsx)(`div`,{className:`px-2 py-6 text-sm text-gray-500`,children:s(`emptyDirectory`)})})]}),d?(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-gray-500`,children:d}):null,(0,I.jsxs)(Ut,{children:[(0,I.jsx)(ye,{type:`button`,variant:`outline`,onClick:()=>r(!1),disabled:n,children:s(`cancel`)}),(0,I.jsx)(ye,{type:`submit`,disabled:b,children:n?s(`saving`):u})]})]})]})})}function CL({open:e,currentProjectRoot:t,isSaving:n,onOpenChange:r,onSave:i}){return(0,I.jsx)(SL,{open:e,currentPath:t,isSaving:n,onOpenChange:r,onConfirm:i,title:s(`chatSessionProjectDialogTitle`),description:s(`chatSessionProjectDialogDescription`),pathLabel:s(`chatSessionProjectPathLabel`),pathPlaceholder:s(`chatSessionProjectPathPlaceholder`),confirmLabel:s(`chatSessionSetProject`),hint:s(`chatSessionProjectUpdateHint`)})}var wL=`flex shrink-0 items-center gap-1.5`,TL=`h-7 w-7 rounded-lg shrink-0 text-gray-400 hover:text-gray-700`;function EL({sessionKey:e,canDeleteSession:t,isDeletePending:n,projectRoot:r,childSessionCount:i=0,sessionCronJobCount:a=0,onOpenChildSessions:o,onOpenSessionCronJobs:c,onDeleteSession:l}){let u=vL(),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)(!1),[h,g]=(0,F.useState)(!1),_=n||h,v=async n=>{let r=t;g(!0);try{await u({sessionKey:e,projectRoot:n,persistToServer:r}),m(!1),f(!1)}finally{g(!1)}};return(0,I.jsxs)(`div`,{className:wL,children:[i>0&&o?(0,I.jsx)(ye,{type:`button`,variant:`ghost`,size:`icon`,className:TL,"aria-label":s(`chatSessionOpenChildSessions`),title:s(`chatSessionOpenChildSessions`),onClick:o,disabled:_,children:(0,I.jsx)(ar,{className:`h-4 w-4`})}):null,a>0&&c?(0,I.jsx)(ye,{type:`button`,variant:`ghost`,size:`icon`,className:TL,"aria-label":s(`chatSessionOpenCronJobs`),title:s(`chatSessionOpenCronJobs`),onClick:c,disabled:_,children:(0,I.jsx)(jn,{className:`h-4 w-4`})}):null,(0,I.jsxs)(wn,{open:d,onOpenChange:f,children:[(0,I.jsx)(Sn,{asChild:!0,children:(0,I.jsx)(ye,{variant:`ghost`,size:`icon`,className:TL,"aria-label":s(`chatSessionMoreActions`),disabled:_,children:(0,I.jsx)(b,{className:`h-4 w-4`})})}),(0,I.jsx)(bn,{align:`end`,className:`w-56 p-2`,children:(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(yL,{icon:er,label:s(`chatSessionSetProject`),onClick:()=>{f(!1),m(!0)},disabled:_}),(0,I.jsx)(yL,{icon:hn,label:s(`chatDeleteSession`),onClick:()=>{f(!1),l()},disabled:!t||_,destructive:!0})]})})]}),(0,I.jsx)(CL,{open:p,currentProjectRoot:r,isSaving:h,onOpenChange:m,onSave:v})]})}function DL({sessionKey:e,projectName:t,projectRoot:n,persistToServer:r}){let i=vL(),[a,o]=(0,F.useState)(!1),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(!1),f=async t=>{d(!0);try{await i({sessionKey:e,projectRoot:t,persistToServer:r}),l(!1),o(!1)}finally{d(!1)}};return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(wn,{open:a,onOpenChange:o,children:[(0,I.jsx)(Sn,{asChild:!0,children:(0,I.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":s(`chatSessionSetProject`),disabled:u,children:(0,I.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,I.jsx)(er,{className:`h-3.5 w-3.5 shrink-0`}),(0,I.jsx)(`span`,{className:`truncate`,children:t}),(0,I.jsx)(Ln,{className:`h-3 w-3 shrink-0 opacity-70`})]})})}),(0,I.jsxs)(bn,{align:`start`,className:`w-72 p-2`,children:[(0,I.jsxs)(`div`,{className:`px-3 pb-2 pt-1`,children:[(0,I.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-gray-500`,children:t}),n?(0,I.jsx)(`div`,{className:`mt-1 break-all text-xs text-gray-500`,children:n}):null]}),(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(yL,{icon:hr,label:s(`chatSessionSetProject`),onClick:()=>{o(!1),l(!0)},disabled:u}),(0,I.jsx)(yL,{icon:rr,label:s(`chatSessionClearProject`),onClick:()=>{f(null)},disabled:u})]})]})]}),(0,I.jsx)(CL,{open:c,currentProjectRoot:n,isSaving:u,onOpenChange:l,onSave:f})]})}function OL({parentSessionLabel:e,onGoToParentSession:t}){if(!e)return null;let n=e.trim();return(0,I.jsx)(`div`,{className:`border-b border-gray-200/60 bg-white/75 px-4 py-2 backdrop-blur-sm sm:px-5`,children:(0,I.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,I.jsx)(Xt,{className:`h-3.5 w-3.5`}),(0,I.jsxs)(`span`,{children:[s(`chatBackToParent`),n?` · ${n}`:``]})]})})}function kL({snapshot:e,childSessionCount:t,sessionCronJobCount:n,layoutMode:i,normalizedAgentId:a,sessionHeaderTitle:o,shouldShowHeaderAgentAvatar:c,shouldShowSessionHeader:l,onBackToList:u,onOpenChildSessions:d,onOpenSessionCronJobs:f,onDeleteSession:p}){let m=i===`mobile`;return(0,I.jsxs)(`div`,{className:r(`border-b border-gray-200/60 bg-white/80 backdrop-blur-sm flex items-center justify-between shrink-0 overflow-hidden transition-colors duration-200`,m?`px-3 sm:px-3`:`px-4 sm:px-5`,l?`opacity-100`:`h-0 py-0 opacity-0 border-b-0`,l&&(m?`min-h-12 pb-2 pt-2`:`h-[52px]`)),style:m&&l?{paddingTop:`calc(env(safe-area-inset-top, 0px) + 0.5rem)`}:void 0,children:[(0,I.jsxs)(`div`,{className:`min-w-0 flex-1 flex items-center gap-2`,children:[m&&u?(0,I.jsx)(`button`,{type:`button`,onClick:u,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":s(`chat`),children:(0,I.jsx)(Xt,{className:`h-4 w-4`})}):null,c?(0,I.jsx)(`div`,{className:`inline-flex shrink-0 items-center`,children:(0,I.jsx)(Vs,{agentId:a,displayName:e.agentDisplayName,avatarUrl:e.agentAvatarUrl,className:`h-5 w-5`})}):null,(0,I.jsx)(`span`,{className:`text-sm font-medium text-gray-700 truncate`,children:o}),e.sessionTypeLabel?(0,I.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,I.jsx)(`span`,{className:`inline-flex h-[1.125rem] w-[1.125rem] items-center justify-center`,children:(0,I.jsx)(Ps,{icon:{kind:`runtime-image`,src:e.sessionTypeIcon.src,alt:e.sessionTypeIcon.alt??null,name:e.sessionTypeLabel}})}):null,e.sessionTypeLabel]}):null,e.sessionProjectName?(0,I.jsx)(DL,{sessionKey:e.sessionKey??`draft`,projectName:e.sessionProjectName,projectRoot:e.sessionProjectRoot,persistToServer:e.canDeleteSession}):null]}),e.sessionKey?(0,I.jsx)(EL,{sessionKey:e.sessionKey,canDeleteSession:e.canDeleteSession,isDeletePending:e.isDeletePending,projectRoot:e.sessionProjectRoot,childSessionCount:t,sessionCronJobCount:n,onOpenChildSessions:d,onOpenSessionCronJobs:f,onDeleteSession:p}):null]})}var AL=`native`;function jL(e){return typeof e==`string`?e.trim().toLowerCase()||`native`:AL}function ML(e,t=AL){return jL(e?.runtime?.trim()||e?.engine?.trim()||t)}function NL(e,t){return e===`native`?s(`chatSessionTypeNative`):t?.trim()||e.trim().split(/[-_]+/g).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)||e}function PL(e){let t=new Map;for(let n of e){let e=jL(n.value);t.set(e,{value:e,label:n.label?.trim()||NL(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(AL,{value:AL,label:NL(AL),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 FL(e){let{selectedSession:t,pendingSessionType:n,setPendingSessionType:r,sessionTypesData:i}=e,a=(0,F.useMemo)(()=>PL(i?.options??[]),[i?.options]),o=(0,F.useMemo)(()=>{let e=[...a],n=jL(t?.sessionType);return e.some(e=>e.value===n)||e.push({value:n,label:NL(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,F.useMemo)(()=>jL(i?.defaultType??`native`),[i?.defaultType]),l=(0,F.useRef)(null),u=(0,F.useMemo)(()=>jL(t?.sessionType??n??c),[c,n,t?.sessionType]),d=(0,F.useMemo)(()=>o.find(e=>e.value===u)??null,[u,o]);(0,F.useEffect)(()=>{if(t)return;let e=typeof n==`string`?n.trim():``,i=jL(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,F.useMemo)(()=>new Set(a.map(e=>e.value)),[a]);return{sessionTypeOptions:o,selectedSessionTypeOption:d,defaultSessionType:c,selectedSessionType:u,canEditSessionType:f,sessionTypeUnavailable:(0,F.useMemo)(()=>t&&!p.has(jL(t.sessionType))?!0:d?.ready===!1,[p,t,d?.ready]),sessionTypeUnavailableMessage:(0,F.useMemo)(()=>t&&!p.has(jL(t.sessionType))?`${NL(u)} ${s(`chatSessionTypeUnavailableSuffix`)}`:d?.ready===!1?d.reasonMessage?.trim()||`${d.label} setup required`:null,[p,t,u,d])}}function IL(e,t){return e.label?.trim()?e.label.trim():t?Us(t):e.sessionKey}function LL(e){let t=Ci({limit:200}),n=(0,F.useMemo)(()=>t.data?.sessions??[],[t.data?.sessions]),r=(0,F.useMemo)(()=>{let e=QI(n);return new Map(e.map(e=>[e.key,e]))},[n]);return(0,F.useMemo)(()=>e.map(e=>{let t=r.get(e.sessionKey)??null,n=e.agentId?.trim()||t?.agentId||null;return{sessionKey:e.sessionKey,parentSessionKey:e.parentSessionKey,title:IL(e,t),agentId:n,updatedAt:t?.updatedAt??null,lastMessageAt:t?.lastMessageAt??null,readAt:t?.readAt??null,runStatus:t?.status===`running`?`running`:void 0,sessionTypeLabel:t?.sessionType?NL(t.sessionType):null,preferredModel:t?.preferredModel?.trim()||null,projectName:t?.projectName?.trim()||null,projectRoot:t?.projectRoot?.trim()||null}}),[r,e])}function RL(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(`
|
|
101
|
-
`)}}async function*zL(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}=BL(r);r=o;for(let e of a)yield e}r+=n.decode();let{frames:e}=BL(r,!0);for(let t of e)yield t}finally{t.releaseLock()}}function BL(e,t=!1){let n=e.split(/\r?\n\r?\n/),r=n.pop()??``,i=[];for(let e of n){let t=RL(e);t&&i.push(t)}if(t&&r.trim()){let e=RL(r);return e&&i.push(e),{frames:i,rest:``}}return{frames:i,rest:r}}var VL=`/ncp/agent`,HL=class extends Error{ncpError;alreadyPublished;constructor(e,t=!1){super(e.message),this.name=`NcpHttpAgentClientError(${e.code})`,this.ncpError=e,this.alreadyPublished=t}};function UL(e){let t=e.trim();if(!t)throw Error(`NcpHttpAgentClient requires a non-empty baseUrl.`);return new URL(t)}function WL(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 GL(e){let t=(e??`/ncp/agent`).trim();if(!t)return VL;let n=t.startsWith(`/`)?t:`/${t}`;return n.endsWith(`/`)?n.slice(0,-1):n}async function KL(e){try{return(await e.text()).trim()}catch{return``}}function qL(e){if(ZL(e))return e.ncpError;if(YL(e))return e;let t=e instanceof Error?e.message:String(e??`Unknown error`);return{code:$L(void 0),message:t,...e instanceof Error&&e.stack?{details:{stack:e.stack}}:{}}}function JL(e,t={}){return new HL(e,t.alreadyPublished??!1)}function YL(e){return XL(e)&&typeof e.code==`string`&&typeof e.message==`string`}function XL(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function ZL(e){return e instanceof HL}var QL={"config-error":`config-error`,"auth-error":`auth-error`,"runtime-error":`runtime-error`,"timeout-error":`timeout-error`,"abort-error":`abort-error`};function $L(e){if(!e)return`runtime-error`;let t=QL[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 eR(e){let t=nR(e);return!t||typeof t.type!=`string`||!t.type.trim()?null:t}function tR(e){let t=nR(e);if(!t)return{code:`runtime-error`,message:e||`Unknown stream error.`};let n=typeof t.code==`string`?t.code:void 0,r=$L(n),i=XL(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 nR(e){try{let t=JSON.parse(e);return XL(t)?t:null}catch{return null}}var rR=[`text`,`file`,`source`,`step-start`,`reasoning`,`tool-invocation`,`card`,`rich-text`,`action`,`extension`],iR=class{manifest;baseUrl;basePath;fetchImpl;defaultHeaders;subscribers=new Set;activeControllers=new Set;started=!1;constructor(e){this.baseUrl=UL(e.baseUrl),this.basePath=GL(e.basePath),this.fetchImpl=WL(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:rR,expectedLatency:`seconds`,metadata:{transport:`http+sse`,scope:`agent`}}}async start(){this.started||(this.started=!0,this.publish({type:TM.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();let t=new AbortController;this.activeControllers.add(t);try{let n=await this.fetchImpl(this.resolveUrl(`/send`),{method:`POST`,headers:{...this.defaultHeaders,accept:`application/json`,"content-type":`application/json`},body:JSON.stringify(e),signal:t.signal});if(!n.ok)throw Error(`NCP send command failed with HTTP ${n.status}: ${await KL(n)}`);let r=await n.json();if(!r.ok||!r.data)throw Error(r.error?.message??`NCP send command returned an invalid handle.`);return r.data}catch(e){if(t.signal.aborted)throw Error(`NCP send command was cancelled.`);if(ZL(e))throw e;let n=qL(e);throw this.publish({type:TM.EndpointError,payload:n}),JL(n)}finally{this.activeControllers.delete(t)}}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 KL(n)}`)}catch(e){if(t.signal.aborted)return;let n=qL(e);throw this.publish({type:TM.EndpointError,payload:n}),JL(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 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 KL(n)}`);if(!n.body)throw Error(`NCP stream response has no body.`);for await(let e of zL(n.body)){if(t.signal.aborted)return;this.handleSseFrame(e)}}catch(e){if(t.signal.aborted)return;if(ZL(e))throw e;let n=qL(e);throw this.publish({type:TM.EndpointError,payload:n}),JL(n)}finally{this.activeControllers.delete(t)}}handleSseFrame(e){if(e.event===`ncp-event`){let t=eR(e.data);if(!t){this.publish({type:TM.EndpointError,payload:{code:`runtime-error`,message:`Received malformed ncp-event frame.`}});return}this.publish(t);return}if(e.event===`error`){let t=tR(e.data);throw this.publish({type:TM.EndpointError,payload:t}),JL(t,{alreadyPublished:!0})}}};function aR(e){return typeof e==`string`?e:e instanceof URL?e.toString():e.url}function oR(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 sR(e,t){let n=Error(e);return t!==void 0&&(n.cause=t),n}function cR(){return async(e,t)=>{try{return await fetch(e,{credentials:`include`,...t})}catch(n){throw vt.reportTransportFailure(oR(n)),sR(`NCP fetch failed for ${(t?.method||`GET`).toUpperCase()} ${aR(e)}: ${oR(n)}`,n)}}}var lR=300,uR=`ncp agent unavailable during startup`;function dR(e){return e instanceof Error?e.message.includes(`ncp session not found:`):!1}function fR(e){return e?.trim().toLowerCase().includes(uR)??!1}function pR(){return new iR({baseUrl:he,basePath:`/api/ncp/agent`,fetchImpl:cR()})}async function mR(e,t,n=lR){t.throwIfAborted();try{let r=await it(e,n);return t.throwIfAborted(),{messages:r.messages,status:r.status??`idle`,contextWindow:r.contextWindow??null}}catch(e){if(t.throwIfAborted(),!dR(e))throw e;return{messages:[],status:`idle`}}}function hR(e,t){let n=(0,F.useRef)(null),r=(0,F.useCallback)(e=>{if(!e){n.current=null;return}n.current!==e&&(n.current=e,t())},[t]);(0,F.useEffect)(()=>{r(e)},[e,r])}function gR(e,t={}){let[n]=(0,F.useState)(()=>pR()),r=bt(),[i,a]=(0,F.useState)(0),[o,s]=(0,F.useState)(null),c=t.messageLimit??lR;(0,F.useEffect)(()=>{s(null)},[e]);let l=rN({sessionId:e,client:n,loadSeed:(0,F.useCallback)(async(e,t)=>{let n=await mR(e,t,c);return t.aborted||s(n.contextWindow??null),{messages:n.messages,status:n.status}},[i,c])}),u=l.hydrateError?.message??l.snapshot.error?.message??null;return hR(e&&r.phase===`ready`&&fR(u)?`${e}:${r.lastReadyAt??0}`:null,()=>{a(e=>e+1)}),(0,F.useMemo)(()=>({...l,snapshot:{...l.snapshot,contextWindow:l.snapshot.contextWindow??o}}),[l,o])}function _R(e){return e.label?.trim()||e.path.split(`/`).filter(Boolean).pop()||e.path}function vR(e){let{activePanelKind:t,activeChildSessionKey:n,activeWorkspaceFileKey:r,childSessionTabs:i,workspaceFileTabs:a,sessionCronJobCount:o}=e;if(t===`cron`&&o>0)return{kind:`cron`};if(t!==`child-session`&&r){let e=a.find(e=>e.key===r);if(e)return{kind:`file`,file:e}}if(t!==`file`&&n){let e=i.find(e=>e.sessionKey===n);if(e)return{kind:`child-session`,tab:e}}return i[0]?{kind:`child-session`,tab:i[0]}:a[0]?{kind:`file`,file:a[0]}:o>0?{kind:`cron`}:null}function yR({agentId:e,kind:t}){return t===`cron`?(0,I.jsx)(jn,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):t===`file`?(0,I.jsx)(Kn,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):e?(0,I.jsx)(lL,{agentId:e,className:`h-3.5 w-3.5 shrink-0`}):(0,I.jsx)(ur,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`})}function bR({tab:e}){return(0,I.jsxs)(ln,{children:[(0,I.jsx)(nn,{asChild:!0,children:(0,I.jsxs)(`div`,{className:r(`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:[e.onClose?(0,I.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),e.onClose?.()},className:`relative inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-md text-gray-400 transition-colors hover:bg-gray-200 hover:text-gray-700`,"aria-label":s(`chatWorkspaceCloseFile`),children:[(0,I.jsx)(`span`,{className:`flex items-center justify-center group-hover:hidden`,children:(0,I.jsx)(yR,{kind:e.kind,agentId:e.agentId})}),(0,I.jsx)(gn,{className:`hidden h-3.5 w-3.5 group-hover:block`})]}):(0,I.jsx)(yR,{kind:e.kind,agentId:e.agentId}),(0,I.jsxs)(`button`,{type:`button`,onClick:e.onSelect,className:`flex min-w-0 flex-1 items-center gap-1.5 text-left`,children:[(0,I.jsx)(`span`,{className:`min-w-0 truncate text-[12px] font-medium`,children:e.title}),e.kind===`file`&&e.viewMode===`diff`?(0,I.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:s(`chatWorkspaceDiff`)}):null,e.showUnreadDot?(0,I.jsx)(`span`,{"aria-label":s(`chatSessionUnread`),className:`h-2 w-2 shrink-0 rounded-full bg-primary`}):null]})]})}),(0,I.jsx)(an,{side:`bottom`,className:`max-w-[320px] text-xs`,children:e.tooltip})]})}function xR({onBack:e,onClose:t,tabs:n}){return(0,I.jsx)(sn,{delayDuration:250,children:(0,I.jsxs)(`div`,{"data-testid":`workspace-tabs-bar`,className:`flex min-w-0 items-stretch border-b border-gray-200/70 bg-gray-50/85`,children:[(0,I.jsx)(`div`,{className:`workspace-horizontal-scrollbar min-w-0 flex-1 overflow-x-auto overflow-y-hidden`,children:(0,I.jsx)(`div`,{"data-testid":`workspace-tabs-scroll`,className:`flex min-w-max items-stretch`,children:n.map(e=>(0,I.jsx)(bR,{tab:e},e.key))})}),e?(0,I.jsx)(`button`,{type:`button`,onClick:e,className:`mx-1 flex h-7 w-7 shrink-0 self-center items-center justify-center rounded-md text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,"aria-label":s(`chatBackToParent`),children:(0,I.jsx)(Xt,{className:`h-4 w-4`})}):null,(0,I.jsx)(`button`,{type:`button`,onClick:t,className:`mx-1 flex h-7 w-7 shrink-0 self-center items-center justify-center rounded-md text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,"aria-label":s(`chatWorkspaceClosePanel`),children:(0,I.jsx)(gn,{className:`h-4 w-4`})})]})})}function SR({tone:e=`neutral`,value:t}){return(0,I.jsx)(`span`,{className:r(`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 CR({breadcrumb:e}){return(0,I.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,I.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,I.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 pr-1`,children:e.segments.map((t,n)=>(0,I.jsxs)(F.Fragment,{children:[(0,I.jsxs)(`span`,{className:r(`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,I.jsx)(tr,{className:`h-3 w-3 shrink-0`}):t.isCurrent?(0,I.jsx)(Kn,{className:`h-3 w-3 shrink-0`}):null,(0,I.jsx)(`span`,{children:t.label})]}),n<e.segments.length-1?(0,I.jsx)(Rn,{className:`h-3 w-3 shrink-0 text-gray-300`}):null]},t.key))}),e.locationLabel||e.truncated?(0,I.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-1`,children:[e.locationLabel?(0,I.jsx)(SR,{value:e.locationLabel}):null,e.truncated?(0,I.jsx)(SR,{tone:`warning`,value:s(`chatWorkspacePreviewTruncated`)}):null]}):null]})})}function wR(e){let t=e.path?.trim()??``;return Ve({queryKey:[`server-path-read`,t,e.basePath??null],queryFn:()=>lt({path:t,basePath:e.basePath}),enabled:(e.enabled??!0)&&t.length>0,staleTime:0})}function TR(e){return e.serverKind?e.serverKind:/\.mdx?$/i.test(e.path)?`markdown`:`text`}function ER(e){let{line:t,path:n,text:r}=e,i=t??1;return{key:`preview:${n}`,path:n,display:`preview`,lines:iF({text:r,kind:`context`,oldStartLine:i,newStartLine:i}),rawText:r,oldStartLine:i,newStartLine:i}}function DR(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=cF({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 OR({text:e,tone:t=`muted`}){return(0,I.jsx)(`div`,{className:r(`flex h-full items-center justify-center px-6 text-center text-sm`,t===`error`?`text-rose-600`:`text-gray-500`),children:e})}function kR({diffBlock:e}){return e?(0,I.jsx)(AR,{block:e}):(0,I.jsx)(OR,{text:s(`chatWorkspaceDiffEmpty`)})}function AR({block:e}){return(0,I.jsx)(`div`,{className:`h-full overflow-auto custom-scrollbar bg-white`,children:(0,I.jsx)(zj,{block:e,layout:`workspace`})})}function jR({onFileOpen:e,previewBlock:t,previewKind:n,previewQuery:r,previewText:i}){return r.isLoading&&!t?(0,I.jsx)(OR,{text:s(`chatWorkspaceLoadingFile`)}):r.data?.kind===`binary`?(0,I.jsx)(OR,{text:s(`chatWorkspacePreviewUnsupported`)}):r.error&&!t?(0,I.jsx)(OR,{tone:`error`,text:r.error instanceof Error?r.error.message:String(r.error)}):n===`markdown`&&i?(0,I.jsx)(`div`,{className:`h-full overflow-auto custom-scrollbar px-5 py-4`,children:(0,I.jsx)(kA,{text:i,role:`assistant`,texts:{copyCodeLabel:s(`chatCodeCopy`),copiedCodeLabel:s(`chatCodeCopied`)},onFileOpen:e})}):t?(0,I.jsx)(AR,{block:t}):(0,I.jsx)(OR,{text:s(`chatWorkspacePreviewEmpty`)})}function MR({file:e,sessionProjectRoot:t,onFileOpen:n}){let r=e.viewMode===`preview`,i=wR({path:e.path,basePath:t,enabled:r}),a=(0,F.useMemo)(()=>e.viewMode===`diff`?DR(e):null,[e]),o=r?i.data?.text??e.rawText??null:null,s=TR({path:i.data?.resolvedPath??e.path,serverKind:i.data?.kind}),c=(0,F.useMemo)(()=>!r||!o?null:ER({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,I.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-white`,children:[(0,I.jsx)(CR,{breadcrumb:(0,F.useMemo)(()=>kI({path:l,sessionProjectRoot:t,line:e.line,column:e.column,truncated:u}),[e.column,e.line,u,l,t])}),(0,I.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:e.viewMode===`diff`?(0,I.jsx)(kR,{diffBlock:a}):(0,I.jsx)(jR,{onFileOpen:n,previewBlock:c,previewKind:s,previewQuery:i,previewText:o})})]})}var NR={open:!1,title:``,description:``,confirmLabel:s(`confirm`),cancelLabel:s(`cancel`),variant:`default`,resolve:null};function PR(){let[e,t]=(0,F.useState)(NR),n=(0,F.useCallback)(e=>new Promise(n=>{t({open:!0,title:e.title,description:e.description??``,confirmLabel:e.confirmLabel??s(`confirm`),cancelLabel:e.cancelLabel??s(`cancel`),variant:e.variant??`default`,resolve:e=>{n(e),t(e=>({...e,open:!1,resolve:null}))}})}),[]),r=(0,F.useCallback)(e=>{t(t=>(!e&&t.resolve&&t.resolve(!1),{...t,open:e,resolve:e?t.resolve:null}))},[]);return{confirm:n,ConfirmDialog:(0,F.useCallback)(()=>(0,I.jsx)(Yt,{open:e.open,onOpenChange:r,title:e.title,description:e.description||void 0,confirmLabel:e.confirmLabel,cancelLabel:e.cancelLabel,variant:e.variant,onConfirm:()=>e.resolve?.(!0),onCancel:()=>e.resolve?.(!1)}),[e,r])}}function FR(e){return u(e??void 0)}function IR(e){if(!e)return`-`;let t=new Date(e);if(Number.isNaN(t.getTime()))return`-`;let n=Date.now(),r=t.getTime()-n,i=d(),a=Math.abs(r);if(a<6e4)return i===`zh`?`刚刚`:`just now`;if(a<36e5){let e=Math.round(a/6e4);return r>0?i===`zh`?`${e}分钟后`:`in ${e}m`:i===`zh`?`${e}分钟前`:`${e}m ago`}if(a<864e5){let e=Math.round(a/36e5);return r>0?i===`zh`?`${e}小时后`:`in ${e}h`:i===`zh`?`${e}小时前`:`${e}h ago`}let o=Math.round(a/864e5);return r>0?i===`zh`?`${o}天后`:`in ${o}d`:i===`zh`?`${o}天前`:`${o}d ago`}function LR(e){return typeof e!=`number`||!Number.isFinite(e)?`-`:u(new Date(e))}function RR(e){if(typeof e!=`number`||!Number.isFinite(e))return`-`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.round(t/60);if(n<60)return`${n}m`;let r=Math.round(n/60);return r<24?`${r}h`:`${Math.round(r/24)}d`}var zR=[`周日`,`周一`,`周二`,`周三`,`周四`,`周五`,`周六`],BR=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function VR(e){return e.padStart(2,`0`)}function HR(e,t){let n=e.trim().split(/\s+/);if(n.length!==5)return null;let[r,i,a,o,s]=n,c=t===`zh`;if(r===`*`&&i===`*`&&a===`*`&&o===`*`&&s===`*`)return c?`每分钟`:`every minute`;if(r.startsWith(`*/`)&&i===`*`&&a===`*`&&o===`*`&&s===`*`){let e=parseInt(r.slice(2),10);if(Number.isFinite(e)&&e>0)return c?`每 ${e} 分钟`:`every ${e}m`}if(r===`0`&&i===`*`&&a===`*`&&o===`*`&&s===`*`)return c?`每小时`:`every hour`;let l=`${VR(i)}:${VR(r)}`;if(r!==`*`&&i!==`*`&&a===`*`&&o===`*`&&s===`*`)return c?`每天 ${l}`:`daily ${l}`;if(r!==`*`&&i!==`*`&&a===`*`&&o===`*`&&s===`1-5`)return c?`工作日 ${l}`:`weekdays ${l}`;if(r!==`*`&&i!==`*`&&a===`*`&&o===`*`&&(s===`0,6`||s===`6,0`))return c?`周末 ${l}`:`weekends ${l}`;if(r!==`*`&&i!==`*`&&a===`*`&&o===`*`&&/^\d$/.test(s)){let e=parseInt(s,10),t=c?zR[e]:BR[e];return t?`${t} ${l}`:null}return r!==`*`&&i!==`*`&&a!==`*`&&o===`*`&&s===`*`?c?`每月 ${a} 日 ${l}`:`monthly ${a} ${l}`:null}function UR(e){let t=d(),n=t===`zh`,{schedule:r}=e;if(r.kind===`cron`)return r.expr?HR(r.expr,t)??`cron ${r.expr}`:`cron`;if(r.kind===`every`){let e=RR(r.everyMs);return n?`每 ${e}`:`every ${e}`}return r.kind===`at`?`${n?`定时`:`at`} ${LR(r.atMs)}`:`-`}function WR(e){return e.payload.sessionId?.trim()||`cron:${e.id}`}function GR(e,t){let n=t?.trim();return!!(n&&e.payload.sessionId?.trim()===n)}function KR({jobs:e}){let t=Ei(),{confirm:n,ConfirmDialog:r}=PR(),i=async e=>{await n({title:`${s(`cronDeleteConfirm`)}?`,description:e.name?`${e.name} (${e.id})`:e.id,confirmLabel:s(`delete`)})&&t.mutate({id:e.id})};return(0,I.jsxs)(`div`,{className:`h-full overflow-y-auto custom-scrollbar px-4 py-4`,children:[(0,I.jsxs)(`div`,{className:`mb-4`,children:[(0,I.jsx)(`div`,{className:`text-sm font-semibold text-gray-900`,children:s(`chatWorkspaceSessionCronJobs`)}),(0,I.jsxs)(`div`,{className:`mt-1 text-xs text-gray-500`,children:[s(`cronTotalLabel`),`: `,e.length]})]}),e.length===0?(0,I.jsx)(`div`,{className:`py-8 text-center text-sm text-gray-500`,children:s(`chatWorkspaceCronJobEmpty`)}):(0,I.jsx)(`div`,{className:`space-y-3`,children:e.map(e=>(0,I.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white px-3 py-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`div`,{className:`truncate text-sm font-semibold text-gray-900`,children:e.name||e.id}),(0,I.jsx)(`div`,{className:`mt-1 text-[11px] text-gray-400`,children:e.id})]}),(0,I.jsxs)(ye,{type:`button`,variant:`subtle`,size:`sm`,className:`h-7 gap-1 rounded-lg px-2`,onClick:()=>void i(e),disabled:t.isPending,children:[(0,I.jsx)(hn,{className:`h-3.5 w-3.5`}),s(`delete`)]})]}),(0,I.jsxs)(`div`,{className:`mt-3 space-y-1.5 text-xs text-gray-500`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`span`,{className:`font-medium text-gray-700`,children:[s(`cronScheduleLabel`),`:`]}),` `,UR(e)]}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`span`,{className:`font-medium text-gray-700`,children:[s(`cronNextRun`),`:`]}),` `,FR(e.state.nextRunAt)]}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`span`,{className:`font-medium text-gray-700`,children:[s(`cronLastRun`),`:`]}),` `,FR(e.state.lastRunAt)]}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`span`,{className:`font-medium text-gray-700`,children:[s(`cronLastStatus`),`:`]}),` `,e.state.lastStatus??`-`]}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`span`,{className:`font-medium text-gray-700`,children:[s(`cronSessionLabel`),`:`]}),` `,WR(e)]})]}),(0,I.jsx)(`div`,{className:`mt-3 whitespace-pre-wrap break-words text-sm text-gray-700`,children:e.payload.message})]},e.id))}),(0,I.jsx)(r,{})]})}function qR({sessionKey:e,onToolAction:t,onFileOpen:n}){let r=gR(e),i=r.visibleMessages,a=(0,F.useRef)(null),{onScroll:o}=mj({scrollRef:a,resetKey:e,isLoading:r.isHydrating,hasContent:i.length>0,contentVersion:i[i.length-1]??null,stickyThresholdPx:20});return(0,I.jsx)(`div`,{ref:a,onScroll:o,className:`h-full overflow-y-auto custom-scrollbar`,children:r.isHydrating?(0,I.jsxs)(`div`,{className:`flex h-full items-center justify-center text-sm text-gray-500`,children:[(0,I.jsx)($t,{className:`mr-2 h-4 w-4 animate-spin`}),s(`chatChildSessionLoading`)]}):r.hydrateError?(0,I.jsx)(`div`,{className:`px-4 py-5 text-sm text-rose-600`,children:r.hydrateError.message}):i.length===0&&!r.isRunning?(0,I.jsx)(`div`,{className:`px-4 py-5 text-sm text-gray-500`,children:s(`chatChildSessionEmpty`)}):(0,I.jsx)(`div`,{className:`px-4 py-5`,children:(0,I.jsx)(gL,{messages:i,isSending:r.isRunning,onToolAction:t,onFileOpen:n})})})}function JR({value:e}){return(0,I.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,I.jsx)(`span`,{className:`truncate`,children:e})})}function YR({tab:e}){let t=[e.sessionTypeLabel,e.preferredModel,e.projectName].filter(e=>!!e?.trim());return t.length===0&&!e.projectRoot?null:(0,I.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[t.length>0?(0,I.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(e=>(0,I.jsx)(JR,{value:e},e))}):null,e.projectRoot?(0,I.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 XR({tab:e}){return(0,I.jsxs)(`div`,{className:`border-b border-gray-200/70 px-4 py-3`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-sm font-semibold text-gray-900`,children:[e.agentId?(0,I.jsx)(lL,{agentId:e.agentId,className:`h-4 w-4 shrink-0`}):(0,I.jsx)($n,{className:`h-4 w-4 shrink-0 text-gray-400`}),(0,I.jsx)(`span`,{className:`truncate`,children:e.title})]}),(0,I.jsx)(YR,{tab:e})]})}function ZR(e){let{resolvedChildTabs:t,workspaceFileTabs:n,sessionCronJobCount:r,activeSelection:i,optimisticReadAtBySessionKey:a,onSelectSession:o,onSelectFile:c,onCloseFile:l,onSelectCronJobs:u}=e,d=t.map(e=>{let t=a[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:i?.kind===`child-session`&&i.tab.sessionKey===e.sessionKey,showUnreadDot:XN({active:i?.kind===`child-session`&&i.tab.sessionKey===e.sessionKey,lastMessageAt:e.lastMessageAt,readAt:n,runStatus:e.runStatus}),onSelect:()=>o(e.sessionKey)}}),f=n.map(e=>({key:`file:${e.key}`,kind:`file`,title:_R(e),tooltip:e.path,viewMode:e.viewMode,active:i?.kind===`file`&&i.file.key===e.key,onSelect:()=>c(e.key),onClose:()=>l(e.key)})),p=r>0?[{key:`cron:session`,kind:`cron`,title:s(`chatWorkspaceSessionCronJobs`),tooltip:s(`chatWorkspaceSessionCronJobs`),active:i?.kind===`cron`,onSelect:u}]:[];return[...d,...f,...p]}function QR({sessionKey:e,childSessionTabs:t,activeChildSessionKey:n,workspaceFileTabs:i,activeWorkspaceFileKey:a,activePanelKind:o,sessionCronJobs:s=[],sessionProjectRoot:c,displayMode:l=`docked`}){let u=ic(),d=LL(t),f=eP(e=>e.optimisticReadAtBySessionKey),p=vR({activeChildSessionKey:n,activeWorkspaceFileKey:a,activePanelKind:o,childSessionTabs:d,workspaceFileTabs:i,sessionCronJobCount:s.length}),m=d.some(e=>!!e.parentSessionKey);(0,F.useEffect)(()=>{if(p?.kind!==`child-session`||p.tab.runStatus===`running`)return;let e=p.tab.lastMessageAt?.trim()??null;e&&u.chatSessionListManager.markSessionRead(p.tab.sessionKey,e,p.tab.readAt??null)},[p,u]);let h=(0,F.useMemo)(()=>ZR({resolvedChildTabs:d,workspaceFileTabs:i,sessionCronJobCount:s.length,activeSelection:p,optimisticReadAtBySessionKey:f,onSelectSession:u.chatThreadManager.selectChildSessionDetail,onSelectFile:u.chatThreadManager.selectWorkspaceFile,onCloseFile:u.chatThreadManager.closeWorkspaceFile,onSelectCronJobs:()=>{e&&u.chatThreadManager.openSessionCronPanel(e)}}),[p,f,u.chatThreadManager,d,e,i,s.length]);return p?(0,I.jsxs)(Zt,{className:r(l===`overlay`?`bg-white`:`hidden border-gray-200/70 bg-white/95 backdrop-blur-sm md:flex`),defaultWidth:480,minWidth:360,maxWidth:860,overlay:l===`overlay`,children:[(0,I.jsx)(xR,{tabs:h,onBack:m?u.chatThreadManager.goToParentSession:void 0,onClose:u.chatThreadManager.closeWorkspacePanel}),(0,I.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col bg-white`,children:p.kind===`child-session`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(XR,{tab:p.tab}),(0,I.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,I.jsx)(qR,{sessionKey:p.tab.sessionKey,onToolAction:u.chatThreadManager.openSessionFromToolAction,onFileOpen:u.chatThreadManager.openFilePreview})})]}):p.kind===`file`?(0,I.jsx)(MR,{file:p.file,sessionProjectRoot:c,onFileOpen:u.chatThreadManager.openFilePreview}):(0,I.jsx)(KR,{jobs:s})})]}):null}function $R({className:e,...t}){return(0,I.jsx)(`div`,{className:r(`animate-pulse rounded-md bg-slate-200`,e),...t})}var ez=[{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 tz(){return(0,I.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,I.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar`,children:(0,I.jsx)(`div`,{className:`mx-auto flex min-h-full w-full max-w-[min(1120px,100%)] flex-col px-6 py-5`,children:(0,I.jsxs)(`div`,{className:`flex flex-1 flex-col gap-8`,children:[(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)($R,{className:`h-6 w-52 rounded-lg bg-gray-200/90`}),(0,I.jsx)(`div`,{className:`space-y-5`,children:ez.map(e=>(0,I.jsx)(`div`,{className:r(`flex w-full`,e.alignmentClassName),children:(0,I.jsx)($R,{"data-testid":`chat-conversation-skeleton-bubble`,className:r(`w-full bg-gray-200/80`,e.bubbleClassName)})},e.key))})]}),(0,I.jsxs)(`div`,{className:`mt-auto grid gap-4 pb-2 sm:grid-cols-[minmax(0,1fr)_minmax(180px,240px)] sm:items-end`,children:[(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)($R,{className:`h-4 w-40 rounded-full bg-gray-200/70`}),(0,I.jsx)($R,{className:`h-[112px] w-full rounded-[30px] bg-gray-200/70`})]}),(0,I.jsx)(`div`,{className:`hidden justify-end sm:flex`,children:(0,I.jsx)($R,{className:`h-10 w-36 rounded-full bg-gray-200/75`})})]})]})})}),(0,I.jsx)(`div`,{className:`border-t border-gray-200/80 bg-white p-4`,children:(0,I.jsx)(`div`,{className:`mx-auto w-full max-w-[min(1120px,100%)]`,children:(0,I.jsxs)(`div`,{className:`overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-card`,children:[(0,I.jsx)(`div`,{className:`px-4 py-2.5`,children:(0,I.jsx)($R,{className:`h-[84px] w-full rounded-[28px] bg-gray-200/80`})}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 pb-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)($R,{className:`h-8 w-20 rounded-full bg-gray-200/75`}),(0,I.jsx)($R,{className:`h-8 w-28 rounded-full bg-gray-200/75`}),(0,I.jsx)($R,{className:`hidden h-8 w-24 rounded-full bg-gray-200/70 sm:block`})]}),(0,I.jsx)($R,{className:`h-8 w-8 rounded-full bg-gray-200/85`})]})]})})})]})}function nz(){let e=ic(),t=Q(e=>e.snapshot);return(0,I.jsxs)(I.Fragment,{children:[t.isProviderStateResolved&&t.modelOptions.length===0?(0,I.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,I.jsx)(`span`,{className:`text-xs text-amber-800`,children:s(`chatModelNoOptions`)}),(0,I.jsx)(`button`,{type:`button`,onClick:e.chatThreadManager.goToProviders,className:`text-xs font-semibold text-amber-900 underline-offset-2 hover:underline`,children:s(`chatGoConfigureProvider`)})]}):null,t.sessionTypeUnavailable&&t.sessionTypeUnavailableMessage?.trim()?(0,I.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,I.jsx)(`span`,{className:`text-xs text-amber-800`,children:t.sessionTypeUnavailableMessage})}):null]})}function rz(){let e=ic(),t=Z(e=>e.snapshot.defaultSessionType),n=Q(e=>e.snapshot),r=(0,F.useRef)(null),i=n.threadRef??r,a=n.availableAgents??[],o=!n.canDeleteSession&&!n.hasSubmittedDraftMessage&&n.messages.length===0&&!n.isSending,s=n.isHistoryLoading&&n.messages.length===0&&!n.isSending&&!n.isAwaitingAssistantOutput,c=e=>a.find(t=>t.id===e)??null,l=()=>{let r=ML(c(n.agentId??`main`),t);e.chatSessionListManager.createSession(r)},u=n=>{e.chatSessionListManager.setSelectedAgentId(n),e.chatInputManager.setPendingSessionType(ML(c(n),t))},{onScroll:d}=mj({scrollRef:i,resetKey:n.sessionKey,isLoading:n.isHistoryLoading,hasContent:n.messages.length>0,contentVersion:n.messages[n.messages.length-1]??null}),f=n.messages.length>0,p=f&&n.isSending&&n.isAwaitingAssistantOutput;return(0,I.jsx)(`div`,{ref:i,onScroll:d,className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar`,children:o?(0,I.jsx)(tc,{onCreateSession:l,agents:a,selectedAgentId:n.agentId??`main`,onSelectAgent:u}):s||!f?null:(0,I.jsx)(`div`,{className:`mx-auto w-full max-w-[min(1120px,100%)] px-4 py-4 sm:px-6 sm:py-5`,children:(0,I.jsx)(gL,{messages:n.messages,isSending:p,onToolAction:e.chatThreadManager.openSessionFromToolAction,onFileOpen:e.chatThreadManager.openFilePreview})})})}function iz(e,t,n,r){return e.workspacePanelParentKey===e.sessionKey?t.length>0||n.length>0||r>0:!1}function az(e){let t=(0,F.useMemo)(()=>e.childSessionTabs.filter(t=>t.parentSessionKey===e.sessionKey),[e.childSessionTabs,e.sessionKey]),n=(0,F.useMemo)(()=>e.workspaceFileTabs.filter(t=>t.parentSessionKey===e.sessionKey),[e.sessionKey,e.workspaceFileTabs]),r=Ti({all:!0}),i=(0,F.useMemo)(()=>(r.data?.jobs??[]).filter(t=>GR(t,e.sessionKey)),[r.data?.jobs,e.sessionKey]);return{childSessionTabs:t,workspaceFileTabs:n,sessionCronJobs:i,showWorkspacePanel:iz(e,t,n,i.length)}}function oz(){let e=ic(),t=Q(e=>e.snapshot);return(0,I.jsx)(OL,{parentSessionLabel:t.parentSessionKey?t.parentSessionLabel??null:null,onGoToParentSession:e.chatThreadManager.goToParentSession})}function sz({layoutMode:e,onBackToList:t}){let n=ic(),r=Q(e=>e.snapshot),{childSessionTabs:i,sessionCronJobs:a}=az(r),o=!!(r.sessionKey||r.sessionTypeLabel),c=r.sessionDisplayName||(r.canDeleteSession&&r.sessionKey?r.sessionKey:null)||s(`chatSidebarNewTask`),l=r.agentId?.trim()??``,u=l.length>0&&l.toLowerCase()!==`main`;return(0,I.jsx)(kL,{snapshot:r,childSessionCount:i.length,sessionCronJobCount:a.length,layoutMode:e,normalizedAgentId:l,sessionHeaderTitle:c,shouldShowHeaderAgentAvatar:u,shouldShowSessionHeader:o,onBackToList:t,onOpenChildSessions:()=>{r.sessionKey&&n.chatThreadManager.openChildSessionPanel({parentSessionKey:r.sessionKey,activeChildSessionKey:i[0]?.sessionKey??null})},onOpenSessionCronJobs:()=>{!r.sessionKey||a.length===0||n.chatThreadManager.openSessionCronPanel(r.sessionKey)},onDeleteSession:n.chatThreadManager.deleteSession})}function cz({layoutMode:e}){let t=Q(e=>e.snapshot),{childSessionTabs:n,workspaceFileTabs:r,sessionCronJobs:i,showWorkspacePanel:a}=az(t);return a?(0,I.jsx)(QR,{sessionKey:t.sessionKey,childSessionTabs:n,activeChildSessionKey:t.activeChildSessionKey??null,workspaceFileTabs:r,activeWorkspaceFileKey:t.activeWorkspaceFileKey??null,activePanelKind:t.activeWorkspacePanelKind??null,sessionCronJobs:i,sessionProjectRoot:t.sessionProjectRoot??null,displayMode:e===`mobile`?`overlay`:`docked`}):null}function lz({layoutMode:e=`desktop`,onBackToList:t}){return Q(e=>e.snapshot).isProviderStateResolved?(0,I.jsxs)(`section`,{className:`flex-1 min-h-0 flex overflow-hidden bg-gradient-to-b from-gray-50/60 to-white`,children:[(0,I.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[(0,I.jsx)(oz,{}),(0,I.jsx)(sz,{layoutMode:e,onBackToList:t}),(0,I.jsx)(nz,{}),(0,I.jsx)(rz,{}),(0,I.jsx)(gP,{})]}),(0,I.jsx)(cz,{layoutMode:e})]}):(0,I.jsx)(tz,{})}var uz={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 dz({status:e,className:t}){let n=uz[e],i=s(e===`connected`?`connected`:e===`disconnected`?`disconnected`:`connecting`);return(0,I.jsx)(sn,{delayDuration:250,children:(0,I.jsxs)(ln,{children:[(0,I.jsx)(nn,{asChild:!0,children:(0,I.jsx)(`span`,{role:`status`,"aria-label":i,className:r(`inline-flex h-5 w-5 items-center justify-center`,t),children:e===`connecting`?(0,I.jsx)($t,{className:r(`h-3 w-3 animate-spin`,n.dotClass)}):(0,I.jsx)(`span`,{className:r(e===`connected`?`h-2 w-2 rounded-full`:``,n.dotClass)})})}),(0,I.jsx)(an,{side:`bottom`,className:`text-xs`,children:i})]})})}function fz(){let e=_L();return async t=>{await e({sessionKey:t.sessionKey,patch:{label:t.label},successMessage:s(`configSavedApplied`)})}}function pz(){let e=fz(),[t,n]=(0,F.useState)(null),[r,i]=(0,F.useState)(``),[a,o]=(0,F.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 mz(e,t){return e.filter(e=>Xs(e,t))}function hz(e){return e.isChildSession?e.isPromotedChildSession===!0:!0}function gz(e={}){let t=eP(e=>e.snapshot.query),n=Ci({limit:e.limit??200}),r=(0,F.useMemo)(()=>mz(QI(n.data?.sessions??[]).filter(hz),t).map(e=>({session:e,runStatus:e.status===`running`?`running`:void 0})),[t,n.data?.sessions]);return{isLoading:n.isLoading,items:r}}function _z(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=Z(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,I.jsx)($s,{session:g,active:y,showUnreadDot:XN({active:y,lastMessageAt:g.lastMessageAt,readAt:x,runStatus:_}),runStatus:_,context:ks(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 vz(e){let t=e.sessionTypeOptions.find(t=>t.value===e.defaultSessionType);return[...t?[t]:[],...e.nonDefaultSessionTypeOptions]}function yz(e){let{query:t,defaultSessionType:n,nonDefaultSessionTypeOptions:i,isCreateMenuOpen:a,onCreateMenuOpenChange:o,onCreateSession:c,onQueryChange:l}=e;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`px-4 pb-3`,children:(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsxs)(ye,{variant:`primary`,className:r(`min-w-0 rounded-xl`,i.length>0?`flex-1 rounded-r-md`:`w-full`),onClick:()=>{o(!1),c(n)},children:[(0,I.jsx)(pn,{className:`mr-2 h-4 w-4`}),s(`chatSidebarNewTask`)]}),i.length>0?(0,I.jsxs)(wn,{open:a,onOpenChange:o,children:[(0,I.jsx)(Sn,{asChild:!0,children:(0,I.jsx)(ye,{variant:`primary`,size:`icon`,className:`h-9 w-10 shrink-0 rounded-xl rounded-l-md`,"aria-label":s(`chatSessionTypeLabel`),children:(0,I.jsx)(Ln,{className:`h-4 w-4`})})}),(0,I.jsxs)(bn,{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,I.jsx)(`div`,{className:`px-3 pb-1 pt-2 text-[10px] font-semibold uppercase tracking-[0.18em] text-gray-400`,children:s(`chatSessionTypeLabel`)}),(0,I.jsx)(`div`,{className:`space-y-1`,children:i.map(e=>(0,I.jsx)(Is,{option:e,onSelect:()=>{c(e.value),o(!1)}},e.value))})]})]}):null]})}),(0,I.jsx)(`div`,{className:`px-4 pb-3`,children:(0,I.jsxs)(`div`,{className:`relative`,children:[(0,I.jsx)(mn,{className:`absolute left-3 top-2.5 h-3.5 w-3.5 text-gray-400`}),(0,I.jsx)(Ne,{value:t,onChange:e=>l(e.target.value),placeholder:s(`chatSidebarSearchPlaceholder`),className:`h-9 rounded-lg pl-8 text-xs`})]})})]})}function bz(e){let{query:t,defaultSessionType:n,sessionTypeOptions:r,nonDefaultSessionTypeOptions:i,isCreateMenuOpen:a,onCreateMenuOpenChange:o,onCreateSession:c,onQueryChange:l}=e,u=vz({defaultSessionType:n,sessionTypeOptions:r,nonDefaultSessionTypeOptions:i}),d=u.length>1;return(0,I.jsx)(`div`,{className:`px-4 pb-2 pt-1`,children:(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,I.jsx)(mn,{className:`absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,I.jsx)(Ne,{value:t,onChange:e=>l(e.target.value),placeholder:s(`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,I.jsxs)(wn,{open:a,onOpenChange:o,children:[(0,I.jsx)(Sn,{asChild:!0,children:(0,I.jsx)(ye,{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":s(`chatSidebarNewTask`),children:(0,I.jsx)(pn,{className:`h-4 w-4`})})}),(0,I.jsxs)(bn,{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,I.jsx)(`div`,{className:`px-3 pb-1.5 pt-2 text-[11px] font-medium text-gray-400`,children:s(`chatSidebarNewTask`)}),(0,I.jsx)(`div`,{className:`space-y-1`,children:u.map(e=>(0,I.jsx)(Is,{option:e,onSelect:()=>{c(e.value),o(!1)}},e.value))})]})]}):(0,I.jsx)(ye,{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":s(`chatSidebarNewTask`),onClick:()=>c(n),children:(0,I.jsx)(pn,{className:`h-4 w-4`})})]})})}function xz({isOpen:e,onOpenChange:t,currentTheme:n,currentThemeLabel:r,themeOptions:i,onSelectTheme:a,currentLanguage:o,currentLanguageLabel:c,languageOptions:l,onSelectLanguage:u,onOpenDocs:d,onOpenApps:f}){let p=()=>{d(),t(!1)},m=()=>{f(),t(!1)};return(0,I.jsxs)(wn,{open:e,onOpenChange:t,children:[(0,I.jsx)(Sn,{asChild:!0,children:(0,I.jsxs)(`button`,{type:`button`,"aria-label":o===`zh`?`设置菜单`:`Settings menu`,className:`flex w-full items-center gap-2.5 rounded-xl px-3 py-2 text-[13px] font-medium text-gray-600 transition-all duration-base hover:bg-gray-200/60 hover:text-gray-800`,children:[(0,I.jsx)(_r,{className:`h-4 w-4 shrink-0 text-gray-400`}),(0,I.jsx)(`span`,{className:`min-w-0 flex-1 text-left`,children:s(`settings`)}),(0,I.jsxs)(`span`,{className:`max-w-[112px] truncate text-[13px] text-gray-500`,children:[r,` / `,c]})]})}),(0,I.jsxs)(bn,{side:`top`,align:`start`,className:`w-64 p-2`,children:[(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsxs)(w,{to:`/settings`,onClick:()=>t(!1),className:`flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-[13px] font-medium text-gray-700 transition-colors hover:bg-gray-100`,children:[(0,I.jsx)(_r,{className:`h-4 w-4 text-gray-400`}),(0,I.jsx)(`span`,{className:`flex-1 text-left`,children:s(`settings`)})]}),(0,I.jsxs)(`button`,{type:`button`,onClick:p,className:`flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-[13px] font-medium text-gray-700 transition-colors hover:bg-gray-100`,children:[(0,I.jsx)(Qt,{className:`h-4 w-4 text-gray-400`}),(0,I.jsx)(`span`,{className:`flex-1 text-left`,children:s(`docBrowserHelp`)})]}),(0,I.jsxs)(`button`,{type:`button`,onClick:m,className:`flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-[13px] font-medium text-gray-700 transition-colors hover:bg-gray-100`,children:[(0,I.jsx)(un,{className:`h-4 w-4 text-gray-400`}),(0,I.jsx)(`span`,{className:`flex-1 text-left`,children:s(`appsTitle`)})]})]}),(0,I.jsx)(`div`,{className:`my-2 h-px bg-gray-200/70`}),(0,I.jsx)(Sz,{icon:pr,label:s(`theme`),options:i,value:n,valueLabel:r,onSelect:a,onCloseMenu:()=>t(!1)}),(0,I.jsx)(Sz,{icon:cr,label:s(`language`),options:l,value:o,valueLabel:c,onSelect:u,onCloseMenu:()=>t(!1)})]})]})}function Sz({icon:e,label:t,options:n,value:r,valueLabel:i,onSelect:a,onCloseMenu:o}){return(0,I.jsxs)(vo,{value:r,onOpenChange:e=>{e||o()},onValueChange:e=>a(e),children:[(0,I.jsxs)(bo,{"aria-label":t,className:`h-auto w-full rounded-lg border-0 bg-transparent px-3 py-2 text-[13px] font-medium text-gray-700 shadow-none hover:bg-gray-100 focus:ring-0`,indicator:(0,I.jsx)(Rn,{className:`h-4 w-4 text-gray-400`}),children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2.5`,children:[(0,I.jsx)(e,{className:`h-4 w-4 shrink-0 text-gray-400`}),(0,I.jsx)(`span`,{className:`text-left`,children:t})]}),(0,I.jsx)(`span`,{className:`ml-auto max-w-[96px] truncate text-[13px] text-gray-500`,children:i})]}),(0,I.jsx)(Co,{side:`right`,align:`center`,sideOffset:6,className:`z-[var(--z-tooltip)] min-w-[7rem] rounded-lg`,viewportClassName:`h-auto min-w-[7rem] w-auto`,children:n.map(e=>(0,I.jsx)(To,{value:e.value,className:`text-[13px]`,children:e.label},e.value))})]})}function Cz(e){return new Date(e.session.lastMessageAt??e.session.createdAt).getTime()}function wz(e){return[...e].sort((e,t)=>Cz(t)-Cz(e))}function Tz(e){let t=new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),r=n-864e5,i=n-7*864e5,a=[],o=[],c=[],l=[];for(let t of e){let e=Cz(t);e>=n?a.push(t):e>=r?o.push(t):e>=i?c.push(t):l.push(t)}let u=[];return a.length>0&&u.push({label:s(`chatSidebarToday`),items:a}),o.length>0&&u.push({label:s(`chatSidebarYesterday`),items:o}),c.length>0&&u.push({label:s(`chatSidebarPrevious7Days`),items:c}),l.length>0&&u.push({label:s(`chatSidebarOlder`),items:l}),u}function Ez(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=Cz(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()||SI(e)||e,items:[n],latestUpdatedAt:i})}return[...t.values()].map(e=>({...e,items:wz(e.items)})).sort((e,t)=>t.latestUpdatedAt-e.latestUpdatedAt)}function Dz(e){let t=new Map;for(let n of e){let e=n.session.parentSessionId?.trim();if(!e)continue;let r=t.get(e)??[];r.push(n),t.set(e,r)}for(let e of t.values())e.sort((e,t)=>Cz(t)-Cz(e));return t}function Oz(e){if(e.label&&e.label.trim())return e.label.trim();let t=e.key.split(`:`);return t[t.length-1]||e.key}var kz=[{target:`/cron`,label:()=>s(`chatSidebarScheduledTasks`),icon:jn},{target:`/skills`,label:()=>s(`chatSidebarSkills`),icon:E},{target:`/agents`,label:()=>s(`agentsPageTitle`),icon:Pn}];function Az(e,t,n){let r=eP(e=>e.optimisticReadAtBySessionKey);return(0,F.useEffect)(()=>{(()=>{if(!t)return;let r=e.find(({session:e})=>e.key===t);if(!r||r.runStatus===`running`)return;let{session:i}=r;n(i.key,i.lastMessageAt,i.readAt)})()},[e,n,t]),r}function jz({variant:e=`desktop`}){let n=e===`mobile`,i=ic(),a=Dn(),[o,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(!1),d=Z(e=>e.snapshot),f=eP(e=>e.snapshot),p=bt(),m=iL(),{isLoading:h,items:g}=gz(),{language:_,setLanguage:v}=kr(),{theme:y,setTheme:b}=es(),x=s(qr.find(e=>e.value===y)?.labelKey??`themeWarm`),S=t.find(e=>e.value===_)?.label??_,C=(0,F.useMemo)(()=>qr.map(e=>({value:e.value,label:s(e.labelKey)})),[]),w=(0,F.useMemo)(()=>t.map(e=>({value:e.value,label:e.label})),[]),T=(0,F.useMemo)(()=>new Map((m.data?.agents??[]).map(e=>[e.id,e])),[m.data?.agents]),E=(0,F.useMemo)(()=>wz(g),[g]),D=(0,F.useMemo)(()=>Dz(g),[g]),O=(0,F.useMemo)(()=>Tz(E),[E]),k=(0,F.useMemo)(()=>Ez(E),[E]),A=d.defaultSessionType||`native`,ee=(0,F.useMemo)(()=>d.sessionTypeOptions.filter(e=>e.value!==A),[A,d.sessionTypeOptions]),j=f.listMode===`project-first`,te=Az(g,f.selectedSessionKey,i.chatSessionListManager.markSessionRead),{editingSessionKey:M,draftLabel:ne,savingSessionKey:re,setDraftLabel:ie,startEditingSessionLabel:ae,cancelEditingSessionLabel:se,saveSessionLabel:ce}=pz(),le=e=>{_!==e&&(v(e),window.location.reload())},ue=e=>(0,I.jsx)(_z,{item:e,selectedSessionKey:f.selectedSessionKey,optimisticReadAtBySessionKey:te,agentsById:T,childSessionsByParentKey:D,editingSessionKey:M,draftLabel:ne,savingSessionKey:re,sessionTitle:Oz,onSelectSession:i.chatSessionListManager.selectSession,onOpenChildSessions:(e,t)=>i.chatThreadManager.openChildSessionPanel({parentSessionKey:e,activeChildSessionKey:t}),onStartEditingSessionLabel:ae,onDraftLabelChange:ie,onSaveSessionLabel:ce,onCancelEditingSessionLabel:se},e.session.key),de=(e,t)=>{i.chatSessionListManager.createSession(e,typeof t==`string`?t:void 0)};return(0,I.jsxs)(`aside`,{className:r(`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&&!ls()?(0,I.jsx)(`div`,{className:`px-5 py-2.5`,children:(0,I.jsx)(ji,{className:`flex min-w-0 items-center gap-2`,suffix:(0,I.jsx)(dz,{status:p.connectionStatus})})}):null,n?(0,I.jsx)(bz,{query:f.query,defaultSessionType:A,sessionTypeOptions:d.sessionTypeOptions,nonDefaultSessionTypeOptions:ee,isCreateMenuOpen:o,onCreateMenuOpenChange:c,onCreateSession:de,onQueryChange:i.chatSessionListManager.setQuery}):(0,I.jsx)(yz,{query:f.query,defaultSessionType:A,sessionTypeOptions:d.sessionTypeOptions,nonDefaultSessionTypeOptions:ee,isCreateMenuOpen:o,onCreateMenuOpenChange:c,onCreateSession:de,onQueryChange:i.chatSessionListManager.setQuery}),n?null:(0,I.jsx)(`div`,{className:`px-3 pb-2`,children:(0,I.jsx)(`ul`,{className:`space-y-0.5`,children:kz.map(e=>(0,I.jsx)(`li`,{children:(0,I.jsx)(ko,{to:e.target,label:e.label(),icon:e.icon,density:`compact`})},e.target))})}),n?null:(0,I.jsx)(`div`,{className:`mx-4 border-t border-gray-200/60`}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between px-5 pb-2 pt-3`,children:[(0,I.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-gray-400`,children:s(`chatSidebarTaskRecords`)}),(0,I.jsx)(_s,{isProjectFirstView:j,onSelectMode:i.chatSessionListManager.setListMode})]}),(0,I.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar px-3 py-2`,children:h?(0,I.jsx)(`div`,{className:`text-xs text-gray-500 p-3`,children:s(`sessionsLoading`)}):j?k.length===0?(0,I.jsxs)(`div`,{className:`p-4 text-center`,children:[(0,I.jsx)(ur,{className:`h-6 w-6 mx-auto mb-2 text-gray-300`}),(0,I.jsx)(`div`,{className:`text-xs text-gray-500`,children:s(`chatSidebarProjectViewEmpty`)})]}):(0,I.jsx)(Rs,{groups:k,defaultSessionType:A,sessionTypeOptions:d.sessionTypeOptions,renderSessionItem:ue,onCreateSession:de}):O.length===0?(0,I.jsxs)(`div`,{className:`p-4 text-center`,children:[(0,I.jsx)(ur,{className:`h-6 w-6 mx-auto mb-2 text-gray-300`}),(0,I.jsx)(`div`,{className:`text-xs text-gray-500`,children:s(`sessionsEmpty`)})]}):(0,I.jsx)(`div`,{className:`space-y-3`,children:O.map(e=>(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`px-2 py-1 text-[11px] font-medium text-gray-400 uppercase tracking-wider`,children:e.label}),(0,I.jsx)(`div`,{className:`space-y-0.5`,children:e.items.map(ue)})]},e.label))})}),n?null:(0,I.jsx)(`div`,{className:`px-3 py-3 border-t border-gray-200/60`,children:(0,I.jsx)(xz,{isOpen:l,onOpenChange:u,currentTheme:y,currentThemeLabel:x,themeOptions:C,onSelectTheme:b,currentLanguage:_,currentLanguageLabel:S,languageOptions:w,onSelectLanguage:le,onOpenDocs:()=>a.open(void 0,{kind:`docs`,title:s(`docBrowserHelp`)}),onOpenApps:()=>oe(a)})})]})}function Mz(){return Ve({queryKey:[`ncp-session-types`],queryFn:Be,staleTime:1e4,retry:!1})}function Nz(e){let t=e.trim();return t.length>0?t:null}function Pz(e){return e??null}var Fz=class{constructor(e){this.updateSession=e,this.inFlight=null,this.queued=null,this.syncSelectedSessionPreferences=()=>{let e=Z.getState().snapshot,t=eP.getState().snapshot,n=Q.getState().snapshot,r=t.selectedSessionKey;!r||!n.canDeleteSession||this.enqueue({sessionKey:r,patch:{preferredModel:Nz(e.selectedModel),preferredThinking:Pz(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)}}}},Iz=class{constructor(e,t,n){this.uiManager=e,this.streamActionsManager=t,this.sessionListManager=n,this.sessionPreferenceSync=new Fz(gt),this.buildAttachmentSignature=e=>[e.assetUri??``,e.url??``,e.name,e.mimeType,String(e.sizeBytes),e.contentBase64??``].join(`:`),this.hasSnapshotChanges=e=>{let t=Z.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.isRuntimeBlockedForSend=()=>aP(vt.getStatusView()),this.syncComposerSnapshot=e=>{let t=Z.getState().snapshot.attachments,n=PN(e,t);Z.getState().setSnapshot({composerNodes:e,attachments:n,draft:kN(e),selectedSkills:AN(e)})},this.syncComposerSnapshotWithAttachments=(e,t)=>{Z.getState().setSnapshot({composerNodes:e,attachments:t,draft:kN(e),selectedSkills:AN(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)&&(Z.getState().setSnapshot(e),Object.prototype.hasOwnProperty.call(e,`modelOptions`)||Object.prototype.hasOwnProperty.call(e,`selectedModel`)||Object.prototype.hasOwnProperty.call(e,`selectedThinkingLevel`))){let{selectedModel:e}=Z.getState().snapshot;this.reconcileThinkingForModel(e)}},this.setDraft=e=>{let t=Z.getState().snapshot.draft,n=this.resolveUpdateValue(t,e);n!==t&&this.syncComposerSnapshot(ON(n))},this.requestComposerFocusAtEnd=()=>{let e=Z.getState().snapshot.composerFocusRequest;Z.getState().setSnapshot({composerFocusRequest:{id:(e?.id??0)+1,placement:`end`}})},this.consumeComposerFocusRequest=e=>{Z.getState().snapshot.composerFocusRequest?.id===e&&Z.getState().setSnapshot({composerFocusRequest:null})},this.setComposerNodes=e=>{let t=Z.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}=Z.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=NN(t.composerNodes,r);return this.syncComposerSnapshotWithAttachments(a,r),i},this.restoreComposerState=(e,t)=>{let n=this.dedupeAttachments(t),r=NN(e,n);this.syncComposerSnapshotWithAttachments(r,n)},this.setPendingSessionType=e=>{let t=Z.getState().snapshot.pendingSessionType,n=this.resolveUpdateValue(t,e);n!==t&&Z.getState().setSnapshot({pendingSessionType:n})},this.send=async()=>{let e=Z.getState().snapshot,t=eP.getState().snapshot,n=Q.getState().snapshot,r=e.draft.trim(),{attachments:i}=e,a=FN(e.composerNodes,i);if(WN({snapshot:e,hasSendableDraft:a.some(e=>e.type!==`text`||e.text.trim().length>0),isRuntimeBlocked:this.isRuntimeBlockedForSend()}))return;let{selectedSkills:o,composerNodes:s}=e,c=n.sessionKey??t.selectedSessionKey??null;!c&&e.selectedSessionType?.trim()&&this.sessionListManager.ensureDraftSession(e.selectedSessionType),this.setComposerNodes(DN()),await this.streamActionsManager.sendMessage({message:r,...c?{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.stop=async()=>{await this.streamActionsManager.stopCurrentRun()},this.goToProviders=()=>{this.uiManager.goToProviders()},this.setSelectedModel=e=>{let t=Z.getState().snapshot.selectedModel,n=this.resolveUpdateValue(t,e);n!==t&&(Z.getState().setSnapshot({selectedModel:n}),this.reconcileThinkingForModel(n))},this.setSelectedThinkingLevel=e=>{let t=Z.getState().snapshot.selectedThinkingLevel,n=this.resolveUpdateValue(t,e);n!==t&&Z.getState().setSnapshot({selectedThinkingLevel:n})},this.selectSessionType=e=>{let t=jL(e);Z.getState().setSnapshot({selectedSessionType:t,pendingSessionType:t})},this.setSelectedSkills=e=>{let{snapshot:t}=Z.getState(),{selectedSkills:n}=t,r=this.resolveUpdateValue(n,e);this.isSameStringArray(r,n)||this.syncComposerSnapshot(MN(t.composerNodes,r,t.skillRecords))},this.selectModel=e=>{this.setSelectedModel(e),RN.remember(e),this.sessionPreferenceSync.syncSelectedSessionPreferences()},this.selectThinkingLevel=e=>{this.setSelectedThinkingLevel(e),this.sessionPreferenceSync.syncSelectedSessionPreferences()},this.rememberSkillSelection=e=>{zN.remember(e)},this.selectSkills=e=>{let t=Z.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}=Z.getState(),n=t.modelOptions.find(t=>t.value===e),{selectedThinkingLevel:r}=t,i=this.resolveThinkingForModel(n,r);i!==r&&Z.getState().setSnapshot({selectedThinkingLevel:i})}}},Lz=`sid_`,Rz=`/chat/draft`,zz=Rz.slice(6);function Bz(e){let t=new TextEncoder().encode(e),n=``;for(let e of t)n+=String.fromCharCode(e);return`${Lz}${btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/g,``)}`}function Vz(e){if(!e.startsWith(Lz))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 Hz(e){if(!e||e===zz)return null;let t=Vz(e);if(t)return t;try{return decodeURIComponent(e)}catch{return e}}function Uz(e){return`/chat/${Bz(e)}`}var Wz=class{constructor(e,t){this.uiManager=e,this.streamActionsManager=t,this.syncDraftThreadState=(e=!1)=>{Q.getState().setSnapshot({sessionKey:null,sessionDisplayName:void 0,canDeleteSession:!1,isHistoryLoading:!1,messages:[],isSending:!1,isAwaitingAssistantOutput:!1,hasSubmittedDraftMessage:e,parentSessionKey:null,parentSessionLabel:null,workspacePanelParentKey:null,activeWorkspacePanelKind:null,childSessionTabs:[],activeChildSessionKey:null,activeWorkspaceFileKey:null})},this.resolveUpdateValue=(e,t)=>typeof t==`function`?t(e):t,this.shouldPersistReadAt=(e,t,n)=>{let r=eP.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=eP.getState().snapshot.selectedAgentId,n=this.resolveUpdateValue(t,e);n!==t&&eP.getState().setSnapshot({selectedAgentId:n})},this.setSelectedSessionKey=e=>{let t=eP.getState().snapshot.selectedSessionKey,n=this.resolveUpdateValue(t,e);n!==t&&eP.getState().setSnapshot({selectedSessionKey:n})},this.setListMode=e=>{let t=eP.getState().snapshot.listMode,n=this.resolveUpdateValue(t,e);n!==t&&eP.getState().setSnapshot({listMode:n})},this.markSessionRead=(e,t,n)=>{let r=e?.trim(),i=t?.trim();!r||!i||this.shouldPersistReadAt(r,i,n)&&(eP.getState().markSessionRead(r,i),gt(r,{uiReadAt:i}).catch(()=>void 0))},this.createSession=(e,t)=>{let{snapshot:n}=Z.getState(),{defaultSessionType:r}=n,i=r||`native`,a=typeof e==`string`&&e.trim().length>0?e.trim():i,o=xI(t);this.streamActionsManager.resetStreamState(),eP.getState().setSnapshot({selectedSessionKey:null}),this.syncDraftThreadState(),Z.getState().setSnapshot({pendingSessionType:a,pendingProjectRoot:o,pendingProjectRootSessionKey:null}),this.uiManager.navigateTo(Rz)},this.startAgentDraftChat=(e,t)=>{let n=e.trim()||`main`;this.createSession(t),this.setSelectedAgentId(n)},this.ensureDraftSession=e=>{let{snapshot:t}=eP.getState();if(t.selectedSessionKey)return t.selectedSessionKey;let n=typeof e==`string`&&e.trim().length>0?e.trim():null;return this.syncDraftThreadState(!0),n&&Z.getState().setSnapshot({pendingSessionType:n}),null},this.materializeRootSessionRoute=e=>{let t=e.trim();t&&this.uiManager.isAtChatRoot()&&this.uiManager.goToSession(t,{replace:!0})},this.selectSession=e=>{this.uiManager.goToSession(e)},this.setQuery=e=>{let t=eP.getState().snapshot.query,n=this.resolveUpdateValue(t,e);n!==t&&eP.getState().setSnapshot({query:n})}}},Gz=async()=>{},Kz=()=>{},qz=class{constructor(){this.actions={sendMessage:Gz,stopCurrentRun:Gz,resumeRun:Gz,resetStreamState:Kz,applyHistoryMessages:Kz},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)}},Jz=async e=>!1,Yz=class{constructor(){this.state={pathname:``},this.actions={navigate:null,confirm:Jz},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.state.pathname===`/chat/draft`,this.goToSession=(e,t)=>{this.navigateTo(Uz(e),t)}}},Xz=class{constructor(e,t,n){this.uiManager=e,this.sessionListManager=t,this.streamActionsManager=n,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.syncSnapshot=e=>{this.hasSnapshotChanges(e)&&Q.getState().setSnapshot(e)},this.clearDeletedSessionState=e=>{eP.getState().snapshot.selectedSessionKey===e&&this.sessionListManager.setSelectedSessionKey(null),Q.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,activeWorkspacePanelKind:null,childSessionTabs:[],activeChildSessionKey:null,workspaceFileTabs:[],activeWorkspaceFileKey:null})},this.resolveWorkspaceParentSessionKey=()=>Q.getState().snapshot.sessionKey?.trim()||(eP.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}=Q.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}}=eP.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;Q.getState().setSnapshot({workspacePanelParentKey:t,activeWorkspacePanelKind:`child-session`,activeChildSessionKey:n,activeWorkspaceFileKey:null}),this.ensureWorkspaceParentRoute(t)},this.openFilePreview=e=>{let t=this.resolveWorkspaceParentSessionKey(),n=this.buildWorkspaceFileTab(e,t);n&&(Q.getState().setSnapshot({workspacePanelParentKey:t,activeWorkspacePanelKind:`file`,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()||eP.getState().snapshot.selectedSessionKey||null;if(t){this.openChildSessionPanel({parentSessionKey:t,activeChildSessionKey:e.sessionId});return}}Q.getState().setSnapshot({workspacePanelParentKey:null,activeWorkspacePanelKind:null,activeChildSessionKey:null,activeWorkspaceFileKey:null}),this.uiManager.goToSession(e.sessionId)}},this.selectChildSessionDetail=e=>{let t=e.trim();if(!t)return;let{childSessionTabs:n}=Q.getState().snapshot;n.some(e=>e.sessionKey===t)&&Q.getState().setSnapshot({activeChildSessionKey:t,activeWorkspaceFileKey:null,activeWorkspacePanelKind:`child-session`})},this.selectWorkspaceFile=e=>{let t=e.trim();if(!t)return;let{workspaceFileTabs:n}=Q.getState().snapshot;n.some(e=>e.key===t)&&Q.getState().setSnapshot({activeWorkspaceFileKey:t,activeChildSessionKey:null,activeWorkspacePanelKind:`file`})},this.closeWorkspaceFile=e=>{let t=e.trim();if(!t)return;let{snapshot:n}=Q.getState(),{activeWorkspaceFileKey:r,workspaceFileTabs:i}=n,a={workspaceFileTabs:i.filter(e=>e.key!==t)};r===t&&(a.activeWorkspaceFileKey=null),Q.getState().setSnapshot(a)},this.closeWorkspacePanel=()=>{Q.getState().setSnapshot({workspacePanelParentKey:null,activeWorkspacePanelKind:null,activeChildSessionKey:null,activeWorkspaceFileKey:null})},this.openSessionCronPanel=e=>{let t=e.trim();t&&(Q.getState().setSnapshot({workspacePanelParentKey:t,activeWorkspacePanelKind:`cron`,activeChildSessionKey:null,activeWorkspaceFileKey:null}),this.ensureWorkspaceParentRoute(t))},this.closeChildSessionDetail=()=>{this.closeWorkspacePanel()},this.goToParentSession=()=>{let{parentSessionKey:e,childSessionTabs:t,activeChildSessionKey:n}=Q.getState().snapshot,r=t.find(e=>e.sessionKey===n)?.parentSessionKey??null,i=e??r;i&&(this.closeWorkspacePanel(),this.uiManager.goToSession(i))},this.isCompactViewport=()=>Nr.getSnapshot().mode===`mobile`,this.deleteCurrentSession=async()=>{let{snapshot:{selectedSessionKey:e}}=eP.getState();if(e&&await this.uiManager.confirm({title:s(`chatDeleteSessionConfirm`),variant:`destructive`,confirmLabel:s(`delete`)})){Q.getState().setSnapshot({isDeletePending:!0});try{await ct(e),et(De,e),De.removeQueries({queryKey:[`ncp-session-messages`,e]}),this.streamActionsManager.resetStreamState(),this.clearDeletedSessionState(e),this.uiManager.goToChatRoot({replace:!0})}finally{Q.getState().setSnapshot({isDeletePending:!1})}}}}},Zz=class{constructor(){this.chatUiManager=new Yz,this.chatStreamActionsManager=new qz,this.chatSessionListManager=new Wz(this.chatUiManager,this.chatStreamActionsManager),this.chatInputManager=new Iz(this.chatUiManager,this.chatStreamActionsManager,this.chatSessionListManager),this.chatThreadManager=new Xz(this.chatUiManager,this.chatSessionListManager,this.chatStreamActionsManager),this.startAgentCreationDraft=e=>{this.chatSessionListManager.createSession(),this.chatSessionListManager.setSelectedAgentId(`main`),this.chatInputManager.setDraft(e),this.chatInputManager.requestComposerFocusAtEnd()}}};function Qz(e){return e?.trim().toLowerCase()||`native`}function $z(e,t){if(typeof t!=`string`)return!1;let n=t.trim();return n?e.some(e=>e.value===n):!1}function eB(e,t){return typeof t==`string`&&e.includes(t)}function tB(e){return e.length===0?null:e.includes(`off`)?`off`:e[0]??null}function nB(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 rB(e){let{modelOptions:t,currentSelectedModel:n,selectedSessionPreferredModel:r,fallbackPreferredModel:i,defaultModel:a,preferSessionPreferredModel:o,preserveCurrentSelectedModelOnSessionChange:s}=e;return t.length===0?``:nB({currentValue:n,selectedSessionPreferredValue:r,fallbackPreferredValue:i,defaultValue:a,isValueSupported:e=>$z(t,e),firstAvailableValue:t[0]?.value??``,preferSessionPreferredValue:o,preserveCurrentValueOnSessionChange:s})}function iB(e){let{supportedThinkingLevels:t,currentSelectedThinkingLevel:n,selectedSessionPreferredThinking:r,fallbackPreferredThinking:i,defaultThinkingLevel:a,preferSessionPreferredThinking:o,preserveCurrentSelectedThinkingOnSessionChange:s}=e;return t.length===0?null:nB({currentValue:n,selectedSessionPreferredValue:r,fallbackPreferredValue:i,defaultValue:a,isValueSupported:e=>eB(t,e),firstAvailableValue:tB(t)??`off`,preferSessionPreferredValue:o,preserveCurrentValueOnSessionChange:s})}function aB(e){let{sessions:t,selectedSessionKey:n,sessionType:r,readPreference:i}=e,a=Qz(r),o,s=-1/0;for(let e of t){if(e.key===n||Qz(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 oB(e){return e.map(e=>e==null?``:String(e)).join(``)}function sB(e){let{isPreferenceAvailable:t,emptyValue:n,syncKey:r,selectedSessionKey:i,selectedSessionExists:a=!1,setValue:o,resolveValue:s}=e,c=(0,F.useRef)(void 0),l=(0,F.useRef)(s),u=(0,F.useRef)(n);(0,F.useEffect)(()=>{l.current=s},[s]),(0,F.useEffect)(()=>{let e=c.current!==i;if(!t){o(n),u.current=n,c.current=i;return}o(t=>{let r=l.current({currentValue:!e&&Object.is(t,u.current)?n:t,sessionChanged:e,preserveCurrentValueOnSessionChange:e&&!!i&&!a});return u.current=r,r}),c.current=i},[n,t,a,i,o,r])}function cB(e){let{modelOptions:t,selectedSessionKey:n,selectedSessionExists:r=!1,selectedSessionPreferredModel:i,fallbackPreferredModel:a,defaultModel:o,setSelectedModel:s}=e;sB({isPreferenceAvailable:t.length>0,emptyValue:``,syncKey:oB([t.map(e=>e.value).join(``),i,a,o]),selectedSessionKey:n,selectedSessionExists:r,setValue:s,resolveValue:({currentValue:e,sessionChanged:n,preserveCurrentValueOnSessionChange:r})=>rB({currentSelectedModel:e,modelOptions:t,selectedSessionPreferredModel:i,fallbackPreferredModel:a,defaultModel:o,preferSessionPreferredModel:n,preserveCurrentSelectedModelOnSessionChange:r})})}function lB(e){let{supportedThinkingLevels:t,selectedSessionKey:n,selectedSessionExists:r=!1,selectedSessionPreferredThinking:i,fallbackPreferredThinking:a,defaultThinkingLevel:o,setSelectedThinkingLevel:s}=e;sB({isPreferenceAvailable:t.length>0,emptyValue:null,syncKey:oB([t.join(``),i,a,o]),selectedSessionKey:n,selectedSessionExists:r,setValue:s,resolveValue:({currentValue:e,sessionChanged:n,preserveCurrentValueOnSessionChange:r})=>iB({currentSelectedThinkingLevel:e,supportedThinkingLevels:t,selectedSessionPreferredThinking:i,fallbackPreferredThinking:a,defaultThinkingLevel:o,preferSessionPreferredThinking:n,preserveCurrentSelectedThinkingOnSessionChange:r})})}function uB(){let{pathname:e}=S(),t=C();return Br(e)?(0,I.jsx)(lz,{layoutMode:`mobile`,onBackToList:()=>t(`/chat`)}):(0,I.jsx)(jz,{variant:`mobile`})}var dB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{DocBrowser:e}=await import(`./doc-browser-D5FJcAyz.js`);return{DocBrowser:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11]))).DocBrowser}));function fB({pathname:e,isMobileLayout:t=!1,isDocBrowserOpen:n,docBrowserMode:i,docBrowserDockControls:a,docBrowserRenderers:o={},sideDock:s,children:c}){let l=zr(e),u=t&&!Br(e),d=ls();return(0,I.jsxs)(`div`,{className:r(`h-screen flex flex-col overflow-hidden bg-background font-sans text-foreground`,d?`rounded-[10px]`:null),style:d?{"--desktop-titlebar-height":`40px`,"--desktop-caption-safe-right":`140px`,"--desktop-sidebar-width":l?`280px`:`240px`}:void 0,children:[d?(0,I.jsx)(as,{}):null,(0,I.jsxs)(`div`,{className:`flex min-h-0 flex-1 overflow-hidden`,children:[!l&&(0,I.jsx)(rs,{mode:`settings`}),(0,I.jsxs)(`div`,{className:`flex-1 flex min-w-0 overflow-hidden relative`,children:[(0,I.jsx)(`div`,{className:`flex-1 flex flex-col min-w-0 overflow-hidden`,children:l?(0,I.jsx)(`div`,{className:`flex-1 h-full overflow-hidden`,children:c}):(0,I.jsx)(`main`,{className:`flex-1 overflow-auto p-8 pb-16 custom-scrollbar`,children:(0,I.jsx)(`div`,{className:`mx-auto h-full max-w-6xl animate-fade-in`,children:c})})}),n&&i===`docked`?(0,I.jsx)(F.Suspense,{fallback:null,children:(0,I.jsx)(dB,{customTabRenderers:o,dockControls:a})}):null,s]})]}),u?(0,I.jsx)(fs,{}):null,n&&i===`floating`?(0,I.jsx)(F.Suspense,{fallback:null,children:(0,I.jsx)(dB,{customTabRenderers:o,dockControls:a})}):null]})}var pB=`NextClaw`,mB=[{prefix:`/marketplace/mcp`,key:`marketplaceMcpPageTitle`},{prefix:`/marketplace/skills`,key:`marketplaceSkillsPageTitle`},{prefix:`/marketplace`,key:`marketplace`},{prefix:`/skills`,key:`marketplaceSkillsPageTitle`},{prefix:`/cron`,key:`cronPageTitle`},{prefix:`/agents`,key:`agentsPageTitle`},{prefix:`/chat`,key:`chat`},{prefix:`/model`,key:`modelPageTitle`},{prefix:`/search`,key:`searchPageTitle`},{prefix:`/providers`,key:`providersPageTitle`},{prefix:`/channels`,key:`channelsPageTitle`},{prefix:`/runtime`,key:`runtimePageTitle`},{prefix:`/updates`,key:`runtimeUpdatesPageTitle`},{prefix:`/remote`,key:`remotePageTitle`},{prefix:`/security`,key:`authSecurityTitle`},{prefix:`/secrets`,key:`secretsPageTitle`}];function hB(e,t){return e===t||e.startsWith(`${t}/`)}function gB(e){let t=e.toLowerCase();for(let{prefix:e,key:n}of mB)if(hB(t,e))return s(n);return s(`settings`)}function _B(e){return`${pB} - ${gB(e)}`}function vB({children:e,sideDockManager:t}){let{isOpen:n,mode:r}=Dn();Er();let{pathname:i}=S(),{language:a}=kr(),{isMobile:o}=Pr(),s=cs();A(e=>e.pinnedItems);let c={getDockState:t.getDockState,pinTab:t.pinTab,unpinTab:t.unpinTab};return(0,F.useEffect)(()=>{document.title=_B(i)},[i,a]),o&&s!==`win32`?(0,I.jsx)(hs,{pathname:i,isDocBrowserOpen:n,docBrowserDockControls:c,docBrowserRenderers:ie,topbarLeadingInset:s===`darwin`?`4.75rem`:void 0,children:e}):(0,I.jsx)(fB,{pathname:i,isMobileLayout:o,isDocBrowserOpen:n,docBrowserMode:r,docBrowserDockControls:c,docBrowserRenderers:ie,sideDock:(0,I.jsx)(j,{manager:t}),children:e})}function yB({children:e}){let t=ae();return(0,I.jsx)(kn,{manager:t.docBrowserManager,children:(0,I.jsx)(vB,{sideDockManager:t.sideDockManager,children:e})})}function bB(){let{isMobile:e}=Pr();return e?(0,I.jsx)(gs,{}):(0,I.jsx)(T,{to:`/model`,replace:!0})}function xB(e){let t=e.trim().toLowerCase();return t?!t.startsWith(`skills`):!0}function SB(e,t){t.startsWith(`mcp`)&&(e?.invalidateQueries({queryKey:[`marketplace-mcp-installed`]}),e?.invalidateQueries({queryKey:[`marketplace-mcp-items`]}),e?.invalidateQueries({queryKey:[`marketplace-mcp-doctor`]}))}function CB(e,t){e&&xB(t)&&e.invalidateQueries({queryKey:[`config`]}),SB(e,t)}function wB(e){let t=(0,F.useRef)(!1);(0,F.useEffect)(()=>{let n=Xe.eventBus.on(Re.connectionOpen,()=>{vt.handleConnectionRestored(),at.refreshAfterRealtimeReconnect(),t.current&&(t.current=!1,e?.invalidateQueries({queryKey:[`ncp-sessions`]}))}),r=Xe.eventBus.on(Re.connectionClose,()=>{vt.handleConnectionInterrupted(null),t.current=!0}),i=Xe.eventBus.on(Re.connectionError,e=>{vt.handleConnectionInterrupted(e?.message??null),t.current=!0}),a=Xe.eventBus.on(Re.configUpdated,({path:t})=>{CB(e,t)}),o=Xe.eventBus.on(Re.runtimeUpdateSnapshot,e=>{at.reportSnapshot(e)}),s=Xe.eventBus.on(Re.sessionRunStatus,t=>{Ze(e,{type:`session.run-status`,payload:t})}),c=Xe.eventBus.on(Re.sessionSummaryUpsert,t=>{Ze(e,{type:`session.summary.upsert`,payload:t})}),l=Xe.eventBus.on(Re.sessionSummaryDelete,t=>{Ze(e,{type:`session.summary.delete`,payload:t})}),u=Xe.eventBus.on(Re.error,e=>{console.error(`Realtime transport error:`,e.message)});return()=>{n(),r(),i(),a(),o(),s(),c(),l(),u()}},[e])}var TB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{ModelConfig:e}=await import(`./model-config-B-qg70S4.js`);return{ModelConfig:e}},__vite__mapDeps([12,2,13,14,3,15,16,11,17]))).ModelConfig})),EB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{ChatPage:e}=await import(`./chat-page-YKdeGoVx.js`);return{ChatPage:e}},__vite__mapDeps([18,2,19,3,20,21,5,13,10,22,4,6,14,23,8,24,25,11,26,27,28,29,30,15,16,31,32,33]))).ChatPage})),DB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{SearchConfig:e}=await import(`./search-config-BRsrQ4zK.js`);return{SearchConfig:e}},__vite__mapDeps([34,2,13,7,3,23,9,35,6]))).SearchConfig})),OB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{ProvidersList:e}=await import(`./providers-list-cBeeslbc.js`);return{ProvidersList:e}},__vite__mapDeps([36,2,3,20,21,5,13,10,22,31,23,8,9,25,35,6,27,17,16]))).ProvidersList})),kB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{ChannelsList:e}=await import(`./channels-list-page-bkKDqaO5.js`);return{ChannelsList:e}},__vite__mapDeps([37,2,3,13,14,7,23,9,10,35,6,27,33,28,30,17]))).ChannelsList})),AB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{RuntimeConfig:e}=await import(`./runtime-config-page-DYH2ejUI.js`);return{RuntimeConfig:e}},__vite__mapDeps([38,2,13,14,3,32,8,39,40,25,26]))).RuntimeConfig})),jB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{DesktopUpdateConfig:e}=await import(`./desktop-update-config-CLXdVz9r.js`);return{DesktopUpdateConfig:e}},__vite__mapDeps([41,2,13,7,3,24,39]))).DesktopUpdateConfig})),MB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{SecurityConfig:e}=await import(`./api-DmxQnm30.js`).then(e=>e.ut);return{SecurityConfig:e}},__vite__mapDeps([13,2]))).SecurityConfig})),NB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{SecretsConfig:e}=await import(`./secrets-config-eYdx5_AW.js`);return{SecretsConfig:e}},__vite__mapDeps([42,2,13,8,3,40,25]))).SecretsConfig})),PB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{RemoteAccessPage:e}=await import(`./remote-DjhVMpVd.js`);return{RemoteAccessPage:e}},__vite__mapDeps([43,19,2,3,20,21,5,13,10,22,4,6,14,23,8,24,25,11,26,27,28]))).RemoteAccessPage})),FB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{McpMarketplacePage:e}=await import(`./mcp-marketplace-page-ooEvG_bB.js`);return{McpMarketplacePage:e}},__vite__mapDeps([44,29,2,3,20,21,5,13,10,11,26,30]))).McpMarketplacePage}));function IB(){return(0,I.jsx)(`div`,{className:`h-full w-full animate-pulse rounded-2xl border border-border/40 bg-card/40`})}function LB({children:e}){return(0,I.jsx)(F.Suspense,{fallback:(0,I.jsx)(IB,{}),children:e})}function RB(e){return(0,I.jsx)(LB,{children:e})}var zB=[{path:`/chat/skills`,redirectTo:`/skills`},{path:`/chat/cron`,redirectTo:`/cron`},{path:`/chat/agents`,redirectTo:`/agents`},{path:`/chat/:sessionId?`,element:RB((0,I.jsx)(EB,{view:`chat`}))},{path:`/agents`,element:RB((0,I.jsx)(EB,{view:`agents`}))},{path:`/skills`,element:RB((0,I.jsx)(EB,{view:`skills`}))},{path:`/skills/scenes/:scene`,element:RB((0,I.jsx)(EB,{view:`skills`}))},{path:`/cron`,element:RB((0,I.jsx)(EB,{view:`cron`}))},{path:`/model`,element:RB((0,I.jsx)(TB,{}))},{path:`/search`,element:RB((0,I.jsx)(DB,{}))},{path:`/providers`,element:RB((0,I.jsx)(OB,{}))},{path:`/channels`,element:RB((0,I.jsx)(kB,{}))},{path:`/runtime`,element:RB((0,I.jsx)(AB,{}))},{path:`/updates`,element:RB((0,I.jsx)(jB,{}))},{path:`/remote`,element:RB((0,I.jsx)(PB,{}))},{path:`/security`,element:RB((0,I.jsx)(MB,{}))},{path:`/secrets`,element:RB((0,I.jsx)(NB,{}))},{path:`/language`,element:(0,I.jsx)(ns,{})},{path:`/settings`,element:(0,I.jsx)(bB,{})},{path:`/marketplace/skills`,redirectTo:`/skills`},{path:`/marketplace`,redirectTo:`/skills`},{path:`/marketplace/mcp`,element:RB((0,I.jsx)(FB,{}))},{path:`/`,redirectTo:`/chat`},{path:`*`,redirectTo:`/chat`}];function BB(e){return`redirectTo`in e?(0,I.jsx)(D,{path:e.path,element:(0,I.jsx)(T,{to:e.redirectTo,replace:!0})},e.path):(0,I.jsx)(D,{path:e.path,element:e.element},e.path)}function VB(){return(0,I.jsx)(x,{children:zB.map(BB)})}function HB(){return wB(De),Ye(),(0,F.useEffect)(()=>(at.start(),()=>{at.stop()}),[]),(0,I.jsxs)(se,{children:[(0,I.jsx)(yB,{children:(0,I.jsx)(VB,{})}),(0,I.jsx)(ce,{}),(0,I.jsx)(ee,{})]})}function UB(){let e=tt(),t=e.isError&&Qe(e.error);return e.isLoading&&!e.isError||t||e.isError?(0,I.jsx)(HB,{}):e.data?.enabled&&!e.data.authenticated?(0,I.jsx)(ne,{username:e.data.username}):(0,I.jsx)(HB,{})}function WB(){return(0,F.useEffect)(()=>{Yo()},[]),(0,I.jsxs)(Ke,{client:De,children:[(0,I.jsx)(UB,{}),(0,I.jsx)(Ko,{}),(0,I.jsx)(Le,{position:`top-right`,richColors:!0,offset:window.nextclawDesktop?.platform===`win32`?56:void 0,mobileOffset:window.nextclawDesktop?.platform===`win32`?56:void 0})]})}var GB=window.nextclawDesktop?.platform===`win32`?te:M;(0,Tr.createRoot)(document.getElementById(`root`)).render((0,I.jsx)(F.StrictMode,{children:(0,I.jsx)($o,{children:(0,I.jsx)(Or,{children:(0,I.jsx)(GB,{children:(0,I.jsx)(WB,{})})})})}));export{li as $,xI as A,lr as At,Us as B,jn as Bt,iL as C,Pr as Ct,QI as D,_r as Dt,nL as E,br as Et,eP as F,Hn as Ft,Go as G,Vs as H,Z as I,Rn as It,To as J,vo as K,cN as L,Ln as Lt,kP as M,or as Mt,aP as N,ir as Nt,ZI as O,hr as Ot,sP as P,Un as Pt,oi as Q,rc as R,In as Rt,FL as S,Fr as St,aL as T,xr as Tt,Ns as U,Xs as V,bs as W,yo as X,bo as Y,ii as Z,gR as _,fi as _t,Zz as a,vi as at,ML as b,xi as bt,jz as c,_i as ct,UR as d,Oi as dt,pi as et,WR as f,gi as ft,fR as g,ui as gt,PR as h,yi as ht,lB as i,Si as it,wP as j,sr as jt,SI as k,dr as kt,lz as l,ci as lt,IR as m,Di as mt,aB as n,Ei as nt,Hz as o,wi as ot,FR as p,hi as pt,Co as q,cB as r,mi as rt,Mz as s,Ci as st,uB as t,Ti as tt,$R as u,si as ut,PL as v,bi as vt,oL as w,kr as wt,NL as x,Ir as xt,jL as y,di as yt,ic as z,Pn as zt};
|
|
99
|
+
`):void 0}function iI(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=XF(o);if(s){let e=YF(s.status)?.toLowerCase(),t=eI(s,a),o=nI(s),c=YF(s.sessionId),l=ZP({args:a,result:s}),u=c?{kind:`open-session`,sessionId:c,sessionKind:s.isChildSession===!0?`child`:`session`,...l?{agentId:l}:{},...YF(s.title)?{label:s.title.trim()}:{},...YF(s.parentSessionId)?{parentSessionId:s.parentSessionId.trim()}:{}}:void 0;return e===`failed`?{kind:`result`,name:r,detail:t,input:$F(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:$F(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:$F(a),text:o,callId:i||void 0,hasResult:!!o,statusTone:`running`,statusLabel:n.toolStatusRunningLabel,...l?{agentId:l}:{},...u?{action:u}:{}}}let c=ZF(o);if(!c)return null;let l=tI(c,a),u=rI(c),d=YF(c.sessionId),f=ZP({args:a,result:c}),p=d?{kind:`open-session`,sessionId:d,sessionKind:c.isChildSession===!0?`child`:`session`,...f?{agentId:f}:{},...YF(c.title)?{label:c.title.trim()}:{},...YF(c.parentSessionId)?{parentSessionId:c.parentSessionId.trim()}:{}}:void 0;return{kind:`result`,name:r,detail:l,input:$F(a),text:u,callId:i||void 0,hasResult:!!u,statusTone:`success`,statusLabel:n.toolStatusCompletedLabel,...f?{agentId:f}:{},...p?{action:p}:{}}}function aI(e){let t=typeof e==`object`&&e&&!Array.isArray(e)?e.error:null;return typeof t==`object`&&t&&!Array.isArray(t)&&t.code===`invalid_tool_arguments`?t:null}function oI(e,t){let n=LP(e.reasoning);return n?{type:`reasoning`,text:n,label:t.reasoningLabel}:null}function sI(e,t){let n=e.mimeType.startsWith(`image/`),r=BP(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 cI(e,t){let n=e.toolInvocation,r=HP(n.result,t);if(r)return r;let i=iI({invocation:n,texts:{toolStatusRunningLabel:t.toolStatusRunningLabel,toolStatusCompletedLabel:t.toolStatusCompletedLabel,toolStatusFailedLabel:t.toolStatusFailedLabel}});if(i)return{type:`tool-card`,card:UP(i,t)};let a=WP({status:n.status,error:n.error,cancelled:n.cancelled,result:n.result,texts:t}),o=aI(n.result),s=Array.isArray(o?.issues)?o.issues.find(e=>typeof e==`string`&&e.trim().length>0):void 0,c=qF({toolName:n.toolName,status:n.status,toolCallId:n.toolCallId,args:n.args,parsedArgs:n.parsedArgs,result:n.result}),l=s?`Invalid arguments: ${s}`:c?.summary??CP(n.parsedArgs??n.args),u=c?void 0:KP(n.args,n.parsedArgs),d=s||(typeof n.error==`string`&&n.error.trim()?n.error.trim():n.result==null?``:xP(n.result).trim()),f=!n.error&&VP(n.result),p=(!c?.fileOperation||!!n.error)&&!f,m=ZP(n);return{type:`tool-card`,card:UP({kind:a.kind,name:n.toolName,...m?{agentId:m}:{},detail:l,...u?{input:u}:{},text:p&&d?d:void 0,outputData:n.result,callId:n.toolCallId||void 0,hasResult:a.hasResult,statusTone:o?`error`:a.statusTone,statusLabel:o?t.toolStatusFailedLabel:a.statusLabel,...c?.fileOperation?{fileOperation:c.fileOperation}:{}},t)}}function lI(e,t){return{type:`unknown`,label:t.unknownPartLabel,rawType:typeof e.type==`string`?e.type:`unknown`,text:xP(e)}}function uI(e){return e.type===`text`&&typeof e.text==`string`}function dI(e){return e.type===`reasoning`&&typeof e.reasoning==`string`}function fI(e){return e.type===`file`&&typeof e.mimeType==`string`&&typeof e.data==`string`}function pI(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 mI(e){let{inlineTokens:t,part:n,texts:r}=e;return uI(n)?IP(n,t):dI(n)?oI(n,r):fI(n)?sI(n,r):pI(n)?cI(n,r):lI(n,r)}function hI(e){let t=e.meta?.timestamp;return t&&Number.isFinite(Date.parse(t))?t:new Date().toISOString()}function gI(e,t){return e===`user`?t.user:e===`assistant`?t.assistant:e===`tool`?t.tool:e===`system`?t.system:t.fallback}function _I(e){return e===`user`||e===`assistant`||e===`tool`||e===`system`?e:`message`}function vI(e,t){return{id:e.id,role:_I(e.role),roleLabel:gI(e.role,t.texts.roleLabels),timestampLabel:t.formatTimestamp(hI(e)),status:e.meta?.status,parts:e.parts.map(n=>mI({part:n,inlineTokens:e.meta?.inlineTokens??[],texts:t.texts})).filter(e=>e!==null)}}var yI=function(e){return e.CALL=`call`,e.RESULT=`result`,e.PARTIAL_CALL=`partial-call`,e.ERROR=`error`,e.CANCELLED=`cancelled`,e}({});function bI(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function xI(e){return bI(e)}function SI(e){let t=bI(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 CI(e){return/^[A-Za-z]:[\\/]?$/.test(e)||e===`/`?e:e.replace(/[\\/]+$/,``)}function wI(e){let t=CI(e.trim().replace(/\\/g,`/`));return/^[A-Za-z]:/.test(t)?`${t.slice(0,1).toLowerCase()}${t.slice(1)}`:t}function TI(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 EI(e){let t=wI(e.path),n=wI(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 DI(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 OI(e){let{column:t,line:n}=e;return typeof n==`number`?`L${n}${typeof t==`number`?`:${t}`:``}`:null}function kI(e){let{column:t,line:n,path:r,sessionProjectRoot:i,truncated:a}=e,o=r.trim(),s=i?.trim()&&o?EI({path:o,sessionProjectRoot:i}):null,c;if(i?.trim()&&s){let e=SI(i)??i.trim();c=DI({labels:s,leading:{key:`workspace:${e}`,label:e,kind:`workspace`,isCurrent:s.length===0}})}else{let{prefix:e,segments:t}=TI(o);c=DI({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:OI({line:n,column:t}),truncated:a,segments:c}}var AI=new Set([`off`,`minimal`,`low`,`medium`,`high`,`adaptive`,`xhigh`]),jI=new Set([`running`,`completed`,`failed`,`idle`]);function MI(e){if(typeof e==`string`)return e;try{return JSON.stringify(e??{})}catch{return String(e??``)}}function NI(e){return`${he}/api/ncp/assets/content?${new URLSearchParams({uri:e}).toString()}`}function PI(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function FI(e){let{metadata:t}=e;return!t||typeof t!=`object`||Array.isArray(t)?null:t}function II(e){let t=FI(e)?.last_activity_preview;if(!t||typeof t!=`object`||Array.isArray(t))return null;let n=t,{state:r}=n,i=PI(n.timestamp);if(!jI.has(r)||!i)return null;let a=PI(n.statusText),o=PI(n.replyText);return{state:r,timestamp:i,...a?{statusText:a}:{},...o?{replyText:o}:{}}}function LI(e){let t=FI(e);return t?PI(t.preferred_model)??PI(t.preferredModel)??PI(t.model):null}function RI(e){let t=FI(e);if(!t)return null;let n=PI(t.preferred_thinking)??PI(t.thinking)??PI(t.thinking_level)??PI(t.thinkingLevel);if(!n)return null;let r=n.toLowerCase();return AI.has(r)?r:null}function zI(e){let t=FI(e);return t?PI(t.label):null}function BI(e){let t=FI(e);return t?xI(t.project_root??t.projectRoot):null}function VI(e){return PI(e.workingDir)}function HI(e){let t=FI(e);return t?PI(t.ui_last_read_at):null}function UI(e){let t=FI(e);return t?PI(t.runtime)??PI(t.session_type)??PI(t.sessionType)??`native`:`native`}function WI(e){let t=FI(e);return t?PI(t.parent_session_id)??PI(t.parentSessionId):null}function GI(e){let t=FI(e);return t?PI(t.spawned_by_request_id)??PI(t.spawnedByRequestId):null}function KI(e){let t=FI(e);return t?t.child_session_promoted===!0:!1}function qI(e){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 JI(e){return e.state===`cancelled`?yI.CANCELLED:e.state===`result`?yI.RESULT:e.state===`partial-call`?yI.PARTIAL_CALL:yI.CALL}function YI(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:NI(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:JI(n),toolCallId:n.toolCallId??`${n.toolName}-${Math.random().toString(36).slice(2,8)}`,toolName:n.toolName,args:MI(n.args),result:n.result}})}return t}function XI(e){return e===`service`?`system`:e===`tool`?`assistant`:e}function ZI(e){return{id:e.id,role:XI(e.role),parts:YI(e.parts),meta:{source:`stream`,status:e.status,sessionKey:e.sessionId,timestamp:e.timestamp}}}function QI(e){let t=zI(e),n=LI(e),r=RI(e),i=BI(e),a=VI(e)??i,o=HI(e),s=PI(e.lastMessageAt),c=SI(i),l=qI(e.sessionId),u=WI(e),d=GI(e),f=KI(e),p=II(e);return{key:e.sessionId,createdAt:e.createdAt??e.updatedAt,updatedAt:e.updatedAt,...s?{lastMessageAt:s}:{},...o?{readAt:o}:{},...typeof e.agentId==`string`&&e.agentId.trim().length>0?{agentId:e.agentId.trim()}:{},...t?{label:t}:{},...l,...n?{preferredModel:n}:{},...r?{preferredThinking:r}:{},...i?{projectRoot:i}:{},...a?{workingDir:a}:{},...c?{projectName:c}:{},sessionType:UI(e),sessionTypeMutable:!1,status:e.status??`idle`,isChildSession:!!u,...f?{isPromotedChildSession:f}:{},...u?{parentSessionId:u}:{},...d?{spawnedByRequestId:d}:{},...p?{activityPreview:p}:{},messageCount:e.messageCount}}function $I(e){return e.map(QI)}function eL(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function tL(e){if(typeof e!=`number`||!Number.isFinite(e))return null;let t=Math.trunc(e);return t>=0?t:null}function nL(e){return e===!0}function rL(e){let t=e;if(!t||typeof t!=`object`||Array.isArray(t))return null;let n=t,r=tL(n.usedContextTokens),i=tL(n.totalContextTokens),a=tL(n.prunedUsedContextTokens),o=eL(n.updatedAt);if(r===null||i===null||a===null||!o)return null;let s=tL(n.compactedUsedContextTokens);return{usedContextTokens:r,totalContextTokens:i,prunedUsedContextTokens:a,availableContextTokens:tL(n.availableContextTokens)??Math.max(0,i-r),droppedHistoryCount:tL(n.droppedHistoryCount)??0,truncatedToolResultCount:tL(n.truncatedToolResultCount)??0,truncatedSystemPrompt:nL(n.truncatedSystemPrompt),truncatedUserMessage:nL(n.truncatedUserMessage),compacted:nL(n.compacted),...eL(n.checkpointId)?{checkpointId:eL(n.checkpointId)??void 0}:{},compactedMessageCount:tL(n.compactedMessageCount)??0,...s===null?{}:{compactedUsedContextTokens:s},updatedAt:o}}function iL(e){let{metadata:t}=e;if(!t||t.nextclaw_timeline_kind!==`context_compaction`)return null;let n=t.checkpoint&&typeof t.checkpoint==`object`&&!Array.isArray(t.checkpoint)?t.checkpoint:null;if(!n)return null;let r=eL(n.id),i=n.status===`compressing`?`compressing`:n.status===`compressed`?`compressed`:null,a=eL(n.summary),o=tL(n.coveredMessageCount),s=tL(n.coveredSessionMessageCount),c=tL(n.originalEstimatedTokens),l=tL(n.projectedEstimatedTokens),u=eL(n.createdAt),d=eL(n.updatedAt);return!r||!i||!a||o===null||s===null||c===null||l===null||!u||!d?null:{id:r,status:i,summary:a,coveredMessageCount:o,coveredSessionMessageCount:s,originalEstimatedTokens:c,projectedEstimatedTokens:l,createdAt:u,updatedAt:d}}function aL(){return Ve({queryKey:[`agents`],queryFn:ut,staleTime:3e4})}function oL(){let e=Fe();return me({mutationFn:({agentId:e,data:t})=>pt(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`agents`]}),e.invalidateQueries({queryKey:[`config`]}),N.success(s(`configSavedApplied`))},onError:e=>{N.error(s(`configSaveFailed`)+`: `+e.message)}})}function sL(){let e=Fe();return me({mutationFn:({agentId:e})=>Je(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`agents`]}),e.invalidateQueries({queryKey:[`config`]}),N.success(s(`configSavedApplied`))},onError:e=>{N.error(s(`configSaveFailed`)+`: `+e.message)}})}function cL(e,t){return new Map([...t,...e].filter(e=>typeof e.id==`string`&&e.id.trim().length>0).map(e=>[e.id,e]))}function lL(e){let t=e?.trim()??``,n=Q(e=>e.snapshot.availableAgents??[]),r=aL(),i=(0,F.useMemo)(()=>cL(n,r.data?.agents??[]),[r.data?.agents,n]);return(0,F.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 uL({agentId:e,className:t}){let n=lL(e);return n?(0,I.jsx)(Vs,{agentId:n.agentId,displayName:n.displayName,avatarUrl:n.avatarUrl,className:t}):null}var dL=new WeakMap;function fL(e){return{roleLabels:{user:s(`chatRoleUser`),assistant:s(`chatRoleAssistant`),tool:s(`chatRoleTool`),system:s(`chatRoleSystem`),fallback:s(`chatRoleMessage`)},reasoningLabel:s(`chatReasoning`),toolCallLabel:s(`chatToolCall`),toolResultLabel:s(`chatToolResult`),toolInputLabel:s(`chatToolInput`),toolNoOutputLabel:s(`chatToolNoOutput`),toolOutputLabel:s(`chatToolOutput`),toolStatusPreparingLabel:s(`chatToolStatusPreparing`),toolStatusRunningLabel:s(`chatToolStatusRunning`),toolStatusCompletedLabel:s(`chatToolStatusCompleted`),toolStatusFailedLabel:s(`chatToolStatusFailed`),toolStatusCancelledLabel:s(`chatToolStatusCancelled`),imageAttachmentLabel:s(`chatImageAttachment`),fileAttachmentLabel:s(`chatFileAttachment`),unknownPartLabel:s(`chatUnknownPart`)}}function pL(e){return{copyCodeLabel:s(`chatCodeCopy`),copiedCodeLabel:s(`chatCodeCopied`),copyMessageLabel:s(`chatMessageCopy`),copiedMessageLabel:s(`chatMessageCopied`),typingLabel:s(`chatTyping`),attachmentOpenLabel:s(`chatAttachmentOpen`),attachmentAttachedLabel:s(`chatAttachmentAttached`),attachmentCategoryLabels:{archive:s(`chatAttachmentCategoryArchive`),audio:s(`chatAttachmentCategoryAudio`),code:s(`chatAttachmentCategoryCode`),data:s(`chatAttachmentCategoryData`),document:s(`chatAttachmentCategoryDocument`),generic:s(`chatAttachmentCategoryGeneric`),image:s(`chatAttachmentCategoryImage`),pdf:s(`chatAttachmentCategoryPdf`),sheet:s(`chatAttachmentCategorySheet`),video:s(`chatAttachmentCategoryVideo`)}}}function mL({checkpoint:e}){return(0,I.jsxs)(`div`,{className:`my-4 flex items-center gap-3 text-[11px] text-gray-500`,title:[`${s(`chatContextCompactionCoveredMessages`)}: ${e.coveredSessionMessageCount}`,`${s(`chatContextCompactionOriginalTokens`)}: ${e.originalEstimatedTokens}`,`${s(`chatContextCompactionProjectedTokens`)}: ${e.projectedEstimatedTokens}`].join(`
|
|
100
|
+
`),children:[(0,I.jsx)(`div`,{className:`h-px flex-1 bg-gray-200`}),(0,I.jsxs)(`div`,{className:`inline-flex items-center gap-2 rounded-full border border-gray-200 bg-gray-50 px-3 py-1`,children:[e.status===`compressing`?(0,I.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-gray-400 animate-pulse`}):(0,I.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-gray-300`}),(0,I.jsx)(`span`,{children:e.status===`compressing`?s(`chatContextCompactionCompressing`):s(`chatContextCompactionCompressed`)})]}),(0,I.jsx)(`div`,{className:`h-px flex-1 bg-gray-200`})]})}function hL(e){let{normalRawMessages:t,rawMessageId:n,rawMessages:r}=e,i=r.findIndex(e=>e.id===n);return i<0?t.length-1:r.slice(0,i).filter(e=>!iL(e)).length-1}function gL(e){let t=e.rawMessages.filter(e=>!iL(e)),n=e.rawMessages.map(e=>({rawMessageId:e.id,checkpoint:iL(e)})).filter(e=>!!e.checkpoint).map(n=>({key:n.rawMessageId,checkpoint:n.checkpoint,boundaryIndex:hL({rawMessages:e.rawMessages,normalRawMessages:t,rawMessageId:n.rawMessageId})})).sort((e,t)=>e.boundaryIndex-t.boundaryIndex),r=[],i=[],a=0,o=e=>{i.length!==0&&(r.push({kind:`messages`,key:e,messages:i}),i=[])};for(t.forEach((t,s)=>{let c=e.messages[s];for(c&&i.push(c);a<n.length&&n[a]?.boundaryIndex<=s;){let e=n[a];o(`messages-before-${e.key}`),r.push({kind:`compaction`,key:e.key,checkpoint:e.checkpoint}),a+=1}});a<n.length;){let e=n[a];o(`messages-before-${e.key}`),r.push({kind:`compaction`,key:e.key,checkpoint:e.checkpoint}),a+=1}return o(`messages-final`),r.length===0&&r.push({kind:`messages`,key:`messages-empty`,messages:[]}),r}function _L({messages:e,isSending:t,className:n,onToolAction:r,onFileOpen:i}){let{language:a}=kr(),o=(0,F.useMemo)(()=>fL(a),[a]),s=(0,F.useMemo)(()=>e.flatMap(e=>{if(iL(e))return[];let t=dL.get(e);if(t&&t.language===a)return[t.viewModel];let n=ZI(e),r=vI({id:n.id,role:n.role,meta:{timestamp:n.meta?.timestamp,status:n.meta?.status,inlineTokens:AP(e.metadata)},parts:n.parts},{formatTimestamp:e=>u(e,a),texts:o});return dL.set(e,{language:a,viewModel:r}),[r]}),[a,e,o]),c=(0,F.useMemo)(()=>s.some(e=>e.role===`assistant`&&(e.status===`streaming`||e.status===`pending`)),[s]),l=(0,F.useMemo)(()=>pL(a),[a]),d=(0,F.useMemo)(()=>gL({rawMessages:e,messages:s}),[s,e]);return(0,I.jsx)(`div`,{className:n,children:d.map((e,n)=>e.kind===`compaction`?(0,I.jsx)(mL,{checkpoint:e.checkpoint},e.key):(0,I.jsx)(wM,{messages:e.messages,isSending:n===d.length-1?t:!1,hasAssistantDraft:c,texts:l,onToolAction:r,onFileOpen:i,renderToolAgent:e=>(0,I.jsx)(uL,{agentId:e,className:`h-4 w-4 shrink-0`})},e.key))})}function vL(){let e=Fe();return async t=>{let{sessionKey:n,patch:r,successMessage:i}=t;try{dt(e,await gt(n,r)),await e.invalidateQueries({queryKey:[`ncp-session-skills`,n]}),N.success(i??s(`configSavedApplied`))}catch(e){throw N.error(s(`configSaveFailed`)+`: `+(e instanceof Error?e.message:String(e))),e}}}function yL(){let e=vL();return async t=>{let{persistToServer:n,projectRoot:r,sessionKey:i}=t,a=s(r?`chatSessionProjectUpdated`:`chatSessionProjectCleared`);if(!n){Z.getState().setSnapshot({pendingProjectRoot:r,pendingProjectRootSessionKey:i}),N.success(a);return}await e({sessionKey:i,patch:{projectRoot:r},successMessage:a})}}function bL({icon:e,label:t,onClick:n,disabled:i=!1,destructive:a=!1}){return(0,I.jsxs)(`button`,{type:`button`,className:r(`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`,a?`text-destructive hover:bg-destructive/10`:`text-gray-700 hover:bg-gray-100`),onClick:n,disabled:i,children:[(0,I.jsx)(e,{className:`h-4 w-4 shrink-0`}),(0,I.jsx)(`span`,{children:t})]})}function xL(e){return Ve({queryKey:[`server-path-browse`,e.path??null,e.includeFiles??!1],queryFn:()=>mt({path:e.path,includeFiles:e.includeFiles}),enabled:e.enabled??!0,staleTime:0})}var SL=F.forwardRef(({className:e,children:t,...n},i)=>(0,I.jsx)(`div`,{ref:i,className:r(`overflow-auto`,e),...n,children:t}));SL.displayName=`ScrollArea`;function CL({open:e,currentPath:t,isSaving:n,onOpenChange:r,onConfirm:i,title:a,description:o,pathLabel:c,pathPlaceholder:l,confirmLabel:u,hint:d}){let[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(null),[g,_]=(0,F.useState)(``);(0,F.useEffect)(()=>{if(!e)return;let n=t?.trim()||null;p(n??``),h(n),_(``)},[t,e]);let v=xL({path:m,enabled:e});(0,F.useEffect)(()=>{!e||!v.data||f.trim().length===0&&p(v.data.currentPath)},[v.data,f,e]);let y=f.trim(),b=y.length===0||n,x=(0,F.useMemo)(()=>v.error?v.error instanceof Error?v.error.message:String(v.error):null,[v.error]),S=g.trim().toLowerCase(),C=(0,F.useMemo)(()=>{let e=v.data?.entries??[];return S.length===0?e:e.filter(e=>{let t=e.name.toLowerCase(),n=e.path.toLowerCase();return t.includes(S)||n.includes(S)})},[v.data?.entries,S]),w=e=>{h(e),_(``),e&&p(e)};return(0,I.jsx)(Gt,{open:e,onOpenChange:e=>{n||r(e)},children:(0,I.jsxs)(qt,{className:`max-h-[85vh] overflow-hidden sm:h-[42rem] sm:max-w-2xl sm:grid-rows-[auto_minmax(0,1fr)]`,children:[(0,I.jsxs)(Kt,{children:[(0,I.jsx)(Jt,{children:a}),o?(0,I.jsx)(Wt,{children:o}):null]}),(0,I.jsxs)(`form`,{className:`flex min-h-0 flex-col gap-4`,onSubmit:e=>{e.preventDefault(),!b&&i(y)},children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(Ae,{htmlFor:`server-path-picker-input`,children:c}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(Ne,{id:`server-path-picker-input`,value:f,onChange:e=>p(e.target.value),placeholder:l,autoFocus:!0,disabled:n}),(0,I.jsx)(ye,{type:`button`,variant:`outline`,onClick:()=>w(y||null),disabled:n,children:s(`openPath`)})]})]}),(0,I.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,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-gray-200 px-3 py-2`,children:[(0,I.jsxs)(ye,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>w(v.data?.homePath??null),disabled:n||v.isLoading,children:[(0,I.jsx)(sr,{className:`mr-1 h-4 w-4`}),s(`homeDirectory`)]}),(0,I.jsxs)(ye,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>w(v.data?.parentPath??null),disabled:!v.data?.parentPath||n||v.isLoading,children:[(0,I.jsx)(nr,{className:`mr-1 h-4 w-4`}),s(`parentDirectory`)]}),(0,I.jsxs)(ye,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{v.refetch()},disabled:n||v.isLoading,children:[(0,I.jsx)(k,{className:`mr-1 h-4 w-4`}),s(`chatRefresh`)]})]}),(0,I.jsxs)(`div`,{className:`border-b border-gray-200 px-3 py-2`,children:[(0,I.jsx)(`div`,{className:`mb-2 text-xs font-medium text-gray-500`,children:s(`currentDirectory`)}),(0,I.jsx)(`div`,{className:`flex flex-wrap items-center gap-1 text-xs text-gray-600`,children:v.data?.breadcrumbs.map((e,t)=>(0,I.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,I.jsx)(`button`,{type:`button`,className:`rounded px-1.5 py-0.5 hover:bg-gray-200`,onClick:()=>w(e.path),disabled:n,children:e.label}),t<v.data.breadcrumbs.length-1?(0,I.jsx)(Rn,{className:`h-3 w-3 text-gray-400`}):null]},e.path))})]}),(0,I.jsx)(`div`,{className:`border-b border-gray-200 px-3 py-2`,children:(0,I.jsxs)(`div`,{className:`relative`,children:[(0,I.jsx)(mn,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,I.jsx)(Ne,{value:g,onChange:e=>_(e.target.value),placeholder:s(`pathPickerSearchPlaceholder`),disabled:n||v.isLoading,className:`pl-9`})]})}),(0,I.jsx)(SL,{className:`min-h-0 flex-1 px-2 py-2`,children:v.isLoading?(0,I.jsx)(`div`,{className:`px-2 py-6 text-sm text-gray-500`,children:s(`loading`)}):x?(0,I.jsxs)(`div`,{className:`px-2 py-4 text-sm text-destructive`,children:[s(`pathBrowseFailed`),`: `,x]}):v.data&&C.length>0?(0,I.jsx)(`div`,{className:`space-y-1`,children:C.map(e=>(0,I.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:()=>w(e.path),disabled:n,children:[(0,I.jsx)(ir,{className:`h-4 w-4 shrink-0 text-emerald-600`}),(0,I.jsx)(`span`,{className:`truncate`,children:e.name})]},e.path))}):v.data&&v.data.entries.length>0?(0,I.jsx)(`div`,{className:`px-2 py-6 text-sm text-gray-500`,children:s(`pathPickerSearchEmpty`)}):(0,I.jsx)(`div`,{className:`px-2 py-6 text-sm text-gray-500`,children:s(`emptyDirectory`)})})]}),d?(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-gray-500`,children:d}):null,(0,I.jsxs)(Ut,{children:[(0,I.jsx)(ye,{type:`button`,variant:`outline`,onClick:()=>r(!1),disabled:n,children:s(`cancel`)}),(0,I.jsx)(ye,{type:`submit`,disabled:b,children:n?s(`saving`):u})]})]})]})})}function wL({open:e,currentProjectRoot:t,isSaving:n,onOpenChange:r,onSave:i}){return(0,I.jsx)(CL,{open:e,currentPath:t,isSaving:n,onOpenChange:r,onConfirm:i,title:s(`chatSessionProjectDialogTitle`),description:s(`chatSessionProjectDialogDescription`),pathLabel:s(`chatSessionProjectPathLabel`),pathPlaceholder:s(`chatSessionProjectPathPlaceholder`),confirmLabel:s(`chatSessionSetProject`),hint:s(`chatSessionProjectUpdateHint`)})}var TL=`flex shrink-0 items-center gap-1.5`,EL=`h-7 w-7 rounded-lg shrink-0 text-gray-400 hover:text-gray-700`;function DL({sessionKey:e,canDeleteSession:t,isDeletePending:n,projectRoot:r,childSessionCount:i=0,sessionCronJobCount:a=0,onOpenChildSessions:o,onOpenSessionCronJobs:c,onDeleteSession:l}){let u=yL(),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)(!1),[h,g]=(0,F.useState)(!1),_=n||h,v=async n=>{let r=t;g(!0);try{await u({sessionKey:e,projectRoot:n,persistToServer:r}),m(!1),f(!1)}finally{g(!1)}};return(0,I.jsxs)(`div`,{className:TL,children:[i>0&&o?(0,I.jsx)(ye,{type:`button`,variant:`ghost`,size:`icon`,className:EL,"aria-label":s(`chatSessionOpenChildSessions`),title:s(`chatSessionOpenChildSessions`),onClick:o,disabled:_,children:(0,I.jsx)(ar,{className:`h-4 w-4`})}):null,a>0&&c?(0,I.jsx)(ye,{type:`button`,variant:`ghost`,size:`icon`,className:EL,"aria-label":s(`chatSessionOpenCronJobs`),title:s(`chatSessionOpenCronJobs`),onClick:c,disabled:_,children:(0,I.jsx)(jn,{className:`h-4 w-4`})}):null,(0,I.jsxs)(wn,{open:d,onOpenChange:f,children:[(0,I.jsx)(Sn,{asChild:!0,children:(0,I.jsx)(ye,{variant:`ghost`,size:`icon`,className:EL,"aria-label":s(`chatSessionMoreActions`),disabled:_,children:(0,I.jsx)(b,{className:`h-4 w-4`})})}),(0,I.jsx)(bn,{align:`end`,className:`w-56 p-2`,children:(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(bL,{icon:er,label:s(`chatSessionSetProject`),onClick:()=>{f(!1),m(!0)},disabled:_}),(0,I.jsx)(bL,{icon:hn,label:s(`chatDeleteSession`),onClick:()=>{f(!1),l()},disabled:!t||_,destructive:!0})]})})]}),(0,I.jsx)(wL,{open:p,currentProjectRoot:r,isSaving:h,onOpenChange:m,onSave:v})]})}function OL({sessionKey:e,projectName:t,projectRoot:n,persistToServer:r}){let i=yL(),[a,o]=(0,F.useState)(!1),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(!1),f=async t=>{d(!0);try{await i({sessionKey:e,projectRoot:t,persistToServer:r}),l(!1),o(!1)}finally{d(!1)}};return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(wn,{open:a,onOpenChange:o,children:[(0,I.jsx)(Sn,{asChild:!0,children:(0,I.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":s(`chatSessionSetProject`),disabled:u,children:(0,I.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,I.jsx)(er,{className:`h-3.5 w-3.5 shrink-0`}),(0,I.jsx)(`span`,{className:`truncate`,children:t}),(0,I.jsx)(Ln,{className:`h-3 w-3 shrink-0 opacity-70`})]})})}),(0,I.jsxs)(bn,{align:`start`,className:`w-72 p-2`,children:[(0,I.jsxs)(`div`,{className:`px-3 pb-2 pt-1`,children:[(0,I.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-gray-500`,children:t}),n?(0,I.jsx)(`div`,{className:`mt-1 break-all text-xs text-gray-500`,children:n}):null]}),(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(bL,{icon:hr,label:s(`chatSessionSetProject`),onClick:()=>{o(!1),l(!0)},disabled:u}),(0,I.jsx)(bL,{icon:rr,label:s(`chatSessionClearProject`),onClick:()=>{f(null)},disabled:u})]})]})]}),(0,I.jsx)(wL,{open:c,currentProjectRoot:n,isSaving:u,onOpenChange:l,onSave:f})]})}function kL({parentSessionLabel:e,onGoToParentSession:t}){if(!e)return null;let n=e.trim();return(0,I.jsx)(`div`,{className:`border-b border-gray-200/60 bg-white/75 px-4 py-2 backdrop-blur-sm sm:px-5`,children:(0,I.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,I.jsx)(Xt,{className:`h-3.5 w-3.5`}),(0,I.jsxs)(`span`,{children:[s(`chatBackToParent`),n?` · ${n}`:``]})]})})}function AL({snapshot:e,childSessionCount:t,sessionCronJobCount:n,layoutMode:i,normalizedAgentId:a,sessionHeaderTitle:o,shouldShowHeaderAgentAvatar:c,shouldShowSessionHeader:l,onBackToList:u,onOpenChildSessions:d,onOpenSessionCronJobs:f,onDeleteSession:p}){let m=i===`mobile`;return(0,I.jsxs)(`div`,{className:r(`border-b border-gray-200/60 bg-white/80 backdrop-blur-sm flex items-center justify-between shrink-0 overflow-hidden transition-colors duration-200`,m?`px-3 sm:px-3`:`px-4 sm:px-5`,l?`opacity-100`:`h-0 py-0 opacity-0 border-b-0`,l&&(m?`min-h-12 pb-2 pt-2`:`h-[52px]`)),style:m&&l?{paddingTop:`calc(env(safe-area-inset-top, 0px) + 0.5rem)`}:void 0,children:[(0,I.jsxs)(`div`,{className:`min-w-0 flex-1 flex items-center gap-2`,children:[m&&u?(0,I.jsx)(`button`,{type:`button`,onClick:u,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":s(`chat`),children:(0,I.jsx)(Xt,{className:`h-4 w-4`})}):null,c?(0,I.jsx)(`div`,{className:`inline-flex shrink-0 items-center`,children:(0,I.jsx)(Vs,{agentId:a,displayName:e.agentDisplayName,avatarUrl:e.agentAvatarUrl,className:`h-5 w-5`})}):null,(0,I.jsx)(`span`,{className:`text-sm font-medium text-gray-700 truncate`,children:o}),e.sessionTypeLabel?(0,I.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,I.jsx)(`span`,{className:`inline-flex h-[1.125rem] w-[1.125rem] items-center justify-center`,children:(0,I.jsx)(Ps,{icon:{kind:`runtime-image`,src:e.sessionTypeIcon.src,alt:e.sessionTypeIcon.alt??null,name:e.sessionTypeLabel}})}):null,e.sessionTypeLabel]}):null,e.sessionProjectName?(0,I.jsx)(OL,{sessionKey:e.sessionKey??`draft`,projectName:e.sessionProjectName,projectRoot:e.sessionProjectRoot,persistToServer:e.canDeleteSession}):null]}),e.sessionKey?(0,I.jsx)(DL,{sessionKey:e.sessionKey,canDeleteSession:e.canDeleteSession,isDeletePending:e.isDeletePending,projectRoot:e.sessionProjectRoot,childSessionCount:t,sessionCronJobCount:n,onOpenChildSessions:d,onOpenSessionCronJobs:f,onDeleteSession:p}):null]})}var jL=`native`;function ML(e){return typeof e==`string`?e.trim().toLowerCase()||`native`:jL}function NL(e,t=jL){return ML(e?.runtime?.trim()||e?.engine?.trim()||t)}function PL(e,t){return e===`native`?s(`chatSessionTypeNative`):t?.trim()||e.trim().split(/[-_]+/g).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)||e}function FL(e){let t=new Map;for(let n of e){let e=ML(n.value);t.set(e,{value:e,label:n.label?.trim()||PL(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(jL,{value:jL,label:PL(jL),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 IL(e){let{selectedSession:t,pendingSessionType:n,setPendingSessionType:r,sessionTypesData:i}=e,a=(0,F.useMemo)(()=>FL(i?.options??[]),[i?.options]),o=(0,F.useMemo)(()=>{let e=[...a],n=ML(t?.sessionType);return e.some(e=>e.value===n)||e.push({value:n,label:PL(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,F.useMemo)(()=>ML(i?.defaultType??`native`),[i?.defaultType]),l=(0,F.useRef)(null),u=(0,F.useMemo)(()=>ML(t?.sessionType??n??c),[c,n,t?.sessionType]),d=(0,F.useMemo)(()=>o.find(e=>e.value===u)??null,[u,o]);(0,F.useEffect)(()=>{if(t)return;let e=typeof n==`string`?n.trim():``,i=ML(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,F.useMemo)(()=>new Set(a.map(e=>e.value)),[a]);return{sessionTypeOptions:o,selectedSessionTypeOption:d,defaultSessionType:c,selectedSessionType:u,canEditSessionType:f,sessionTypeUnavailable:(0,F.useMemo)(()=>t&&!p.has(ML(t.sessionType))?!0:d?.ready===!1,[p,t,d?.ready]),sessionTypeUnavailableMessage:(0,F.useMemo)(()=>t&&!p.has(ML(t.sessionType))?`${PL(u)} ${s(`chatSessionTypeUnavailableSuffix`)}`:d?.ready===!1?d.reasonMessage?.trim()||`${d.label} setup required`:null,[p,t,u,d])}}function LL(e,t){return e.label?.trim()?e.label.trim():t?Us(t):e.sessionKey}function RL(e){let t=Ci({limit:200}),n=(0,F.useMemo)(()=>t.data?.sessions??[],[t.data?.sessions]),r=(0,F.useMemo)(()=>{let e=$I(n);return new Map(e.map(e=>[e.key,e]))},[n]);return(0,F.useMemo)(()=>e.map(e=>{let t=r.get(e.sessionKey)??null,n=e.agentId?.trim()||t?.agentId||null;return{sessionKey:e.sessionKey,parentSessionKey:e.parentSessionKey,title:LL(e,t),agentId:n,updatedAt:t?.updatedAt??null,lastMessageAt:t?.lastMessageAt??null,readAt:t?.readAt??null,runStatus:t?.status===`running`?`running`:void 0,sessionTypeLabel:t?.sessionType?PL(t.sessionType):null,preferredModel:t?.preferredModel?.trim()||null,projectName:t?.projectName?.trim()||null,projectRoot:t?.projectRoot?.trim()||null}}),[r,e])}function zL(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(`
|
|
101
|
+
`)}}async function*BL(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}=VL(r);r=o;for(let e of a)yield e}r+=n.decode();let{frames:e}=VL(r,!0);for(let t of e)yield t}finally{t.releaseLock()}}function VL(e,t=!1){let n=e.split(/\r?\n\r?\n/),r=n.pop()??``,i=[];for(let e of n){let t=zL(e);t&&i.push(t)}if(t&&r.trim()){let e=zL(r);return e&&i.push(e),{frames:i,rest:``}}return{frames:i,rest:r}}var HL=`/ncp/agent`,UL=class extends Error{ncpError;alreadyPublished;constructor(e,t=!1){super(e.message),this.name=`NcpHttpAgentClientError(${e.code})`,this.ncpError=e,this.alreadyPublished=t}};function WL(e){let t=e.trim();if(!t)throw Error(`NcpHttpAgentClient requires a non-empty baseUrl.`);return new URL(t)}function GL(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 KL(e){let t=(e??`/ncp/agent`).trim();if(!t)return HL;let n=t.startsWith(`/`)?t:`/${t}`;return n.endsWith(`/`)?n.slice(0,-1):n}async function qL(e){try{return(await e.text()).trim()}catch{return``}}function JL(e){if(QL(e))return e.ncpError;if(XL(e))return e;let t=e instanceof Error?e.message:String(e??`Unknown error`);return{code:eR(void 0),message:t,...e instanceof Error&&e.stack?{details:{stack:e.stack}}:{}}}function YL(e,t={}){return new UL(e,t.alreadyPublished??!1)}function XL(e){return ZL(e)&&typeof e.code==`string`&&typeof e.message==`string`}function ZL(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function QL(e){return e instanceof UL}var $L={"config-error":`config-error`,"auth-error":`auth-error`,"runtime-error":`runtime-error`,"timeout-error":`timeout-error`,"abort-error":`abort-error`};function eR(e){if(!e)return`runtime-error`;let t=$L[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 tR(e){let t=rR(e);return!t||typeof t.type!=`string`||!t.type.trim()?null:t}function nR(e){let t=rR(e);if(!t)return{code:`runtime-error`,message:e||`Unknown stream error.`};let n=typeof t.code==`string`?t.code:void 0,r=eR(n),i=ZL(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 rR(e){try{let t=JSON.parse(e);return ZL(t)?t:null}catch{return null}}var iR=[`text`,`file`,`source`,`step-start`,`reasoning`,`tool-invocation`,`card`,`rich-text`,`action`,`extension`],aR=class{manifest;baseUrl;basePath;fetchImpl;defaultHeaders;subscribers=new Set;activeControllers=new Set;started=!1;constructor(e){this.baseUrl=WL(e.baseUrl),this.basePath=KL(e.basePath),this.fetchImpl=GL(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:iR,expectedLatency:`seconds`,metadata:{transport:`http+sse`,scope:`agent`}}}async start(){this.started||(this.started=!0,this.publish({type:TM.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();let t=new AbortController;this.activeControllers.add(t);try{let n=await this.fetchImpl(this.resolveUrl(`/send`),{method:`POST`,headers:{...this.defaultHeaders,accept:`application/json`,"content-type":`application/json`},body:JSON.stringify(e),signal:t.signal});if(!n.ok)throw Error(`NCP send command failed with HTTP ${n.status}: ${await qL(n)}`);let r=await n.json();if(!r.ok||!r.data)throw Error(r.error?.message??`NCP send command returned an invalid handle.`);return r.data}catch(e){if(t.signal.aborted)throw Error(`NCP send command was cancelled.`);if(QL(e))throw e;let n=JL(e);throw this.publish({type:TM.EndpointError,payload:n}),YL(n)}finally{this.activeControllers.delete(t)}}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 qL(n)}`)}catch(e){if(t.signal.aborted)return;let n=JL(e);throw this.publish({type:TM.EndpointError,payload:n}),YL(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 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 qL(n)}`);if(!n.body)throw Error(`NCP stream response has no body.`);for await(let e of BL(n.body)){if(t.signal.aborted)return;this.handleSseFrame(e)}}catch(e){if(t.signal.aborted)return;if(QL(e))throw e;let n=JL(e);throw this.publish({type:TM.EndpointError,payload:n}),YL(n)}finally{this.activeControllers.delete(t)}}handleSseFrame(e){if(e.event===`ncp-event`){let t=tR(e.data);if(!t){this.publish({type:TM.EndpointError,payload:{code:`runtime-error`,message:`Received malformed ncp-event frame.`}});return}this.publish(t);return}if(e.event===`error`){let t=nR(e.data);throw this.publish({type:TM.EndpointError,payload:t}),YL(t,{alreadyPublished:!0})}}};function oR(e){return typeof e==`string`?e:e instanceof URL?e.toString():e.url}function sR(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 cR(e,t){let n=Error(e);return t!==void 0&&(n.cause=t),n}function lR(){return async(e,t)=>{try{return await fetch(e,{credentials:`include`,...t})}catch(n){throw vt.reportTransportFailure(sR(n)),cR(`NCP fetch failed for ${(t?.method||`GET`).toUpperCase()} ${oR(e)}: ${sR(n)}`,n)}}}var uR=300,dR=`ncp agent unavailable during startup`;function fR(e){return e instanceof Error?e.message.includes(`ncp session not found:`):!1}function pR(e){return e?.trim().toLowerCase().includes(dR)??!1}function mR(){return new aR({baseUrl:he,basePath:`/api/ncp/agent`,fetchImpl:lR()})}async function hR(e,t,n=uR){t.throwIfAborted();try{let r=await it(e,n);return t.throwIfAborted(),{messages:r.messages,status:r.status??`idle`,contextWindow:r.contextWindow??null}}catch(e){if(t.throwIfAborted(),!fR(e))throw e;return{messages:[],status:`idle`}}}function gR(e,t){let n=(0,F.useRef)(null),r=(0,F.useCallback)(e=>{if(!e){n.current=null;return}n.current!==e&&(n.current=e,t())},[t]);(0,F.useEffect)(()=>{r(e)},[e,r])}function _R(e,t={}){let[n]=(0,F.useState)(()=>mR()),r=bt(),[i,a]=(0,F.useState)(0),[o,s]=(0,F.useState)(null),c=t.messageLimit??uR;(0,F.useEffect)(()=>{s(null)},[e]);let l=rN({sessionId:e,client:n,loadSeed:(0,F.useCallback)(async(e,t)=>{let n=await hR(e,t,c);return t.aborted||s(n.contextWindow??null),{messages:n.messages,status:n.status}},[i,c])}),u=l.hydrateError?.message??l.snapshot.error?.message??null;return gR(e&&r.phase===`ready`&&pR(u)?`${e}:${r.lastReadyAt??0}`:null,()=>{a(e=>e+1)}),(0,F.useMemo)(()=>({...l,snapshot:{...l.snapshot,contextWindow:l.snapshot.contextWindow??o}}),[l,o])}function vR(e){return e.label?.trim()||e.path.split(`/`).filter(Boolean).pop()||e.path}function yR(e){let{activePanelKind:t,activeChildSessionKey:n,activeWorkspaceFileKey:r,childSessionTabs:i,workspaceFileTabs:a,sessionCronJobCount:o}=e;if(t===`cron`&&o>0)return{kind:`cron`};if(t!==`child-session`&&r){let e=a.find(e=>e.key===r);if(e)return{kind:`file`,file:e}}if(t!==`file`&&n){let e=i.find(e=>e.sessionKey===n);if(e)return{kind:`child-session`,tab:e}}return i[0]?{kind:`child-session`,tab:i[0]}:a[0]?{kind:`file`,file:a[0]}:o>0?{kind:`cron`}:null}function bR({agentId:e,kind:t}){return t===`cron`?(0,I.jsx)(jn,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):t===`file`?(0,I.jsx)(Kn,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):e?(0,I.jsx)(uL,{agentId:e,className:`h-3.5 w-3.5 shrink-0`}):(0,I.jsx)(ur,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`})}function xR({tab:e}){return(0,I.jsxs)(ln,{children:[(0,I.jsx)(nn,{asChild:!0,children:(0,I.jsxs)(`div`,{className:r(`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:[e.onClose?(0,I.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),e.onClose?.()},className:`relative inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-md text-gray-400 transition-colors hover:bg-gray-200 hover:text-gray-700`,"aria-label":s(`chatWorkspaceCloseFile`),children:[(0,I.jsx)(`span`,{className:`flex items-center justify-center group-hover:hidden`,children:(0,I.jsx)(bR,{kind:e.kind,agentId:e.agentId})}),(0,I.jsx)(gn,{className:`hidden h-3.5 w-3.5 group-hover:block`})]}):(0,I.jsx)(bR,{kind:e.kind,agentId:e.agentId}),(0,I.jsxs)(`button`,{type:`button`,onClick:e.onSelect,className:`flex min-w-0 flex-1 items-center gap-1.5 text-left`,children:[(0,I.jsx)(`span`,{className:`min-w-0 truncate text-[12px] font-medium`,children:e.title}),e.kind===`file`&&e.viewMode===`diff`?(0,I.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:s(`chatWorkspaceDiff`)}):null,e.showUnreadDot?(0,I.jsx)(`span`,{"aria-label":s(`chatSessionUnread`),className:`h-2 w-2 shrink-0 rounded-full bg-primary`}):null]})]})}),(0,I.jsx)(an,{side:`bottom`,className:`max-w-[320px] text-xs`,children:e.tooltip})]})}function SR({onBack:e,onClose:t,tabs:n}){return(0,I.jsx)(sn,{delayDuration:250,children:(0,I.jsxs)(`div`,{"data-testid":`workspace-tabs-bar`,className:`flex min-w-0 items-stretch border-b border-gray-200/70 bg-gray-50/85`,children:[(0,I.jsx)(`div`,{className:`workspace-horizontal-scrollbar min-w-0 flex-1 overflow-x-auto overflow-y-hidden`,children:(0,I.jsx)(`div`,{"data-testid":`workspace-tabs-scroll`,className:`flex min-w-max items-stretch`,children:n.map(e=>(0,I.jsx)(xR,{tab:e},e.key))})}),e?(0,I.jsx)(`button`,{type:`button`,onClick:e,className:`mx-1 flex h-7 w-7 shrink-0 self-center items-center justify-center rounded-md text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,"aria-label":s(`chatBackToParent`),children:(0,I.jsx)(Xt,{className:`h-4 w-4`})}):null,(0,I.jsx)(`button`,{type:`button`,onClick:t,className:`mx-1 flex h-7 w-7 shrink-0 self-center items-center justify-center rounded-md text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,"aria-label":s(`chatWorkspaceClosePanel`),children:(0,I.jsx)(gn,{className:`h-4 w-4`})})]})})}function CR({tone:e=`neutral`,value:t}){return(0,I.jsx)(`span`,{className:r(`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 wR({breadcrumb:e}){return(0,I.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,I.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,I.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 pr-1`,children:e.segments.map((t,n)=>(0,I.jsxs)(F.Fragment,{children:[(0,I.jsxs)(`span`,{className:r(`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,I.jsx)(tr,{className:`h-3 w-3 shrink-0`}):t.isCurrent?(0,I.jsx)(Kn,{className:`h-3 w-3 shrink-0`}):null,(0,I.jsx)(`span`,{children:t.label})]}),n<e.segments.length-1?(0,I.jsx)(Rn,{className:`h-3 w-3 shrink-0 text-gray-300`}):null]},t.key))}),e.locationLabel||e.truncated?(0,I.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-1`,children:[e.locationLabel?(0,I.jsx)(CR,{value:e.locationLabel}):null,e.truncated?(0,I.jsx)(CR,{tone:`warning`,value:s(`chatWorkspacePreviewTruncated`)}):null]}):null]})})}function TR(e){let t=e.path?.trim()??``;return Ve({queryKey:[`server-path-read`,t,e.basePath??null],queryFn:()=>lt({path:t,basePath:e.basePath}),enabled:(e.enabled??!0)&&t.length>0,staleTime:0})}function ER(e){return e.serverKind?e.serverKind:/\.mdx?$/i.test(e.path)?`markdown`:`text`}function DR(e){let{line:t,path:n,text:r}=e,i=t??1;return{key:`preview:${n}`,path:n,display:`preview`,lines:iF({text:r,kind:`context`,oldStartLine:i,newStartLine:i}),rawText:r,oldStartLine:i,newStartLine:i}}function OR(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=cF({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 kR({text:e,tone:t=`muted`}){return(0,I.jsx)(`div`,{className:r(`flex h-full items-center justify-center px-6 text-center text-sm`,t===`error`?`text-rose-600`:`text-gray-500`),children:e})}function AR({diffBlock:e}){return e?(0,I.jsx)(jR,{block:e}):(0,I.jsx)(kR,{text:s(`chatWorkspaceDiffEmpty`)})}function jR({block:e}){return(0,I.jsx)(`div`,{className:`h-full overflow-auto custom-scrollbar bg-white`,children:(0,I.jsx)(zj,{block:e,layout:`workspace`})})}function MR({onFileOpen:e,previewBlock:t,previewKind:n,previewQuery:r,previewText:i}){return r.isLoading&&!t?(0,I.jsx)(kR,{text:s(`chatWorkspaceLoadingFile`)}):r.data?.kind===`binary`?(0,I.jsx)(kR,{text:s(`chatWorkspacePreviewUnsupported`)}):r.error&&!t?(0,I.jsx)(kR,{tone:`error`,text:r.error instanceof Error?r.error.message:String(r.error)}):n===`markdown`&&i?(0,I.jsx)(`div`,{className:`h-full overflow-auto custom-scrollbar px-5 py-4`,children:(0,I.jsx)(kA,{text:i,role:`assistant`,texts:{copyCodeLabel:s(`chatCodeCopy`),copiedCodeLabel:s(`chatCodeCopied`)},onFileOpen:e})}):t?(0,I.jsx)(jR,{block:t}):(0,I.jsx)(kR,{text:s(`chatWorkspacePreviewEmpty`)})}function NR({file:e,sessionProjectRoot:t,sessionWorkingDir:n,onFileOpen:r}){let i=e.viewMode===`preview`,a=TR({path:e.path,basePath:n,enabled:i}),o=(0,F.useMemo)(()=>e.viewMode===`diff`?OR(e):null,[e]),s=i?a.data?.text??e.rawText??null:null,c=ER({path:a.data?.resolvedPath??e.path,serverKind:a.data?.kind}),l=(0,F.useMemo)(()=>!i||!s?null:DR({path:a.data?.resolvedPath??e.path,text:s,line:e.line}),[e.line,e.path,i,a.data?.resolvedPath,s]),u=a.data?.resolvedPath??e.path,d=!!a.data?.truncated,f=t??n;return(0,I.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-white`,children:[(0,I.jsx)(wR,{breadcrumb:(0,F.useMemo)(()=>kI({path:u,sessionProjectRoot:f,line:e.line,column:e.column,truncated:d}),[f,e.column,e.line,d,u])}),(0,I.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:e.viewMode===`diff`?(0,I.jsx)(AR,{diffBlock:o}):(0,I.jsx)(MR,{onFileOpen:r,previewBlock:l,previewKind:c,previewQuery:a,previewText:s})})]})}var PR={open:!1,title:``,description:``,confirmLabel:s(`confirm`),cancelLabel:s(`cancel`),variant:`default`,resolve:null};function FR(){let[e,t]=(0,F.useState)(PR),n=(0,F.useCallback)(e=>new Promise(n=>{t({open:!0,title:e.title,description:e.description??``,confirmLabel:e.confirmLabel??s(`confirm`),cancelLabel:e.cancelLabel??s(`cancel`),variant:e.variant??`default`,resolve:e=>{n(e),t(e=>({...e,open:!1,resolve:null}))}})}),[]),r=(0,F.useCallback)(e=>{t(t=>(!e&&t.resolve&&t.resolve(!1),{...t,open:e,resolve:e?t.resolve:null}))},[]);return{confirm:n,ConfirmDialog:(0,F.useCallback)(()=>(0,I.jsx)(Yt,{open:e.open,onOpenChange:r,title:e.title,description:e.description||void 0,confirmLabel:e.confirmLabel,cancelLabel:e.cancelLabel,variant:e.variant,onConfirm:()=>e.resolve?.(!0),onCancel:()=>e.resolve?.(!1)}),[e,r])}}function IR(e){return u(e??void 0)}function LR(e){if(!e)return`-`;let t=new Date(e);if(Number.isNaN(t.getTime()))return`-`;let n=Date.now(),r=t.getTime()-n,i=d(),a=Math.abs(r);if(a<6e4)return i===`zh`?`刚刚`:`just now`;if(a<36e5){let e=Math.round(a/6e4);return r>0?i===`zh`?`${e}分钟后`:`in ${e}m`:i===`zh`?`${e}分钟前`:`${e}m ago`}if(a<864e5){let e=Math.round(a/36e5);return r>0?i===`zh`?`${e}小时后`:`in ${e}h`:i===`zh`?`${e}小时前`:`${e}h ago`}let o=Math.round(a/864e5);return r>0?i===`zh`?`${o}天后`:`in ${o}d`:i===`zh`?`${o}天前`:`${o}d ago`}function RR(e){return typeof e!=`number`||!Number.isFinite(e)?`-`:u(new Date(e))}function zR(e){if(typeof e!=`number`||!Number.isFinite(e))return`-`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.round(t/60);if(n<60)return`${n}m`;let r=Math.round(n/60);return r<24?`${r}h`:`${Math.round(r/24)}d`}var BR=[`周日`,`周一`,`周二`,`周三`,`周四`,`周五`,`周六`],VR=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function HR(e){return e.padStart(2,`0`)}function UR(e,t){let n=e.trim().split(/\s+/);if(n.length!==5)return null;let[r,i,a,o,s]=n,c=t===`zh`;if(r===`*`&&i===`*`&&a===`*`&&o===`*`&&s===`*`)return c?`每分钟`:`every minute`;if(r.startsWith(`*/`)&&i===`*`&&a===`*`&&o===`*`&&s===`*`){let e=parseInt(r.slice(2),10);if(Number.isFinite(e)&&e>0)return c?`每 ${e} 分钟`:`every ${e}m`}if(r===`0`&&i===`*`&&a===`*`&&o===`*`&&s===`*`)return c?`每小时`:`every hour`;let l=`${HR(i)}:${HR(r)}`;if(r!==`*`&&i!==`*`&&a===`*`&&o===`*`&&s===`*`)return c?`每天 ${l}`:`daily ${l}`;if(r!==`*`&&i!==`*`&&a===`*`&&o===`*`&&s===`1-5`)return c?`工作日 ${l}`:`weekdays ${l}`;if(r!==`*`&&i!==`*`&&a===`*`&&o===`*`&&(s===`0,6`||s===`6,0`))return c?`周末 ${l}`:`weekends ${l}`;if(r!==`*`&&i!==`*`&&a===`*`&&o===`*`&&/^\d$/.test(s)){let e=parseInt(s,10),t=c?BR[e]:VR[e];return t?`${t} ${l}`:null}return r!==`*`&&i!==`*`&&a!==`*`&&o===`*`&&s===`*`?c?`每月 ${a} 日 ${l}`:`monthly ${a} ${l}`:null}function WR(e){let t=d(),n=t===`zh`,{schedule:r}=e;if(r.kind===`cron`)return r.expr?UR(r.expr,t)??`cron ${r.expr}`:`cron`;if(r.kind===`every`){let e=zR(r.everyMs);return n?`每 ${e}`:`every ${e}`}return r.kind===`at`?`${n?`定时`:`at`} ${RR(r.atMs)}`:`-`}function GR(e){return e.payload.sessionId?.trim()||`cron:${e.id}`}function KR(e,t){let n=t?.trim();return!!(n&&e.payload.sessionId?.trim()===n)}function qR({jobs:e}){let t=Ei(),{confirm:n,ConfirmDialog:r}=FR(),i=async e=>{await n({title:`${s(`cronDeleteConfirm`)}?`,description:e.name?`${e.name} (${e.id})`:e.id,confirmLabel:s(`delete`)})&&t.mutate({id:e.id})};return(0,I.jsxs)(`div`,{className:`h-full overflow-y-auto custom-scrollbar px-4 py-4`,children:[(0,I.jsxs)(`div`,{className:`mb-4`,children:[(0,I.jsx)(`div`,{className:`text-sm font-semibold text-gray-900`,children:s(`chatWorkspaceSessionCronJobs`)}),(0,I.jsxs)(`div`,{className:`mt-1 text-xs text-gray-500`,children:[s(`cronTotalLabel`),`: `,e.length]})]}),e.length===0?(0,I.jsx)(`div`,{className:`py-8 text-center text-sm text-gray-500`,children:s(`chatWorkspaceCronJobEmpty`)}):(0,I.jsx)(`div`,{className:`space-y-3`,children:e.map(e=>(0,I.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white px-3 py-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`div`,{className:`truncate text-sm font-semibold text-gray-900`,children:e.name||e.id}),(0,I.jsx)(`div`,{className:`mt-1 text-[11px] text-gray-400`,children:e.id})]}),(0,I.jsxs)(ye,{type:`button`,variant:`subtle`,size:`sm`,className:`h-7 gap-1 rounded-lg px-2`,onClick:()=>void i(e),disabled:t.isPending,children:[(0,I.jsx)(hn,{className:`h-3.5 w-3.5`}),s(`delete`)]})]}),(0,I.jsxs)(`div`,{className:`mt-3 space-y-1.5 text-xs text-gray-500`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`span`,{className:`font-medium text-gray-700`,children:[s(`cronScheduleLabel`),`:`]}),` `,WR(e)]}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`span`,{className:`font-medium text-gray-700`,children:[s(`cronNextRun`),`:`]}),` `,IR(e.state.nextRunAt)]}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`span`,{className:`font-medium text-gray-700`,children:[s(`cronLastRun`),`:`]}),` `,IR(e.state.lastRunAt)]}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`span`,{className:`font-medium text-gray-700`,children:[s(`cronLastStatus`),`:`]}),` `,e.state.lastStatus??`-`]}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`span`,{className:`font-medium text-gray-700`,children:[s(`cronSessionLabel`),`:`]}),` `,GR(e)]})]}),(0,I.jsx)(`div`,{className:`mt-3 whitespace-pre-wrap break-words text-sm text-gray-700`,children:e.payload.message})]},e.id))}),(0,I.jsx)(r,{})]})}function JR({sessionKey:e,onToolAction:t,onFileOpen:n}){let r=_R(e),i=r.visibleMessages,a=(0,F.useRef)(null),{onScroll:o}=mj({scrollRef:a,resetKey:e,isLoading:r.isHydrating,hasContent:i.length>0,contentVersion:i[i.length-1]??null,stickyThresholdPx:20});return(0,I.jsx)(`div`,{ref:a,onScroll:o,className:`h-full overflow-y-auto custom-scrollbar`,children:r.isHydrating?(0,I.jsxs)(`div`,{className:`flex h-full items-center justify-center text-sm text-gray-500`,children:[(0,I.jsx)($t,{className:`mr-2 h-4 w-4 animate-spin`}),s(`chatChildSessionLoading`)]}):r.hydrateError?(0,I.jsx)(`div`,{className:`px-4 py-5 text-sm text-rose-600`,children:r.hydrateError.message}):i.length===0&&!r.isRunning?(0,I.jsx)(`div`,{className:`px-4 py-5 text-sm text-gray-500`,children:s(`chatChildSessionEmpty`)}):(0,I.jsx)(`div`,{className:`px-4 py-5`,children:(0,I.jsx)(_L,{messages:i,isSending:r.isRunning,onToolAction:t,onFileOpen:n})})})}function YR({value:e}){return(0,I.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,I.jsx)(`span`,{className:`truncate`,children:e})})}function XR({tab:e}){let t=[e.sessionTypeLabel,e.preferredModel,e.projectName].filter(e=>!!e?.trim());return t.length===0&&!e.projectRoot?null:(0,I.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[t.length>0?(0,I.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(e=>(0,I.jsx)(YR,{value:e},e))}):null,e.projectRoot?(0,I.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 ZR({tab:e}){return(0,I.jsxs)(`div`,{className:`border-b border-gray-200/70 px-4 py-3`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-sm font-semibold text-gray-900`,children:[e.agentId?(0,I.jsx)(uL,{agentId:e.agentId,className:`h-4 w-4 shrink-0`}):(0,I.jsx)($n,{className:`h-4 w-4 shrink-0 text-gray-400`}),(0,I.jsx)(`span`,{className:`truncate`,children:e.title})]}),(0,I.jsx)(XR,{tab:e})]})}function QR(e){let{resolvedChildTabs:t,workspaceFileTabs:n,sessionCronJobCount:r,activeSelection:i,optimisticReadAtBySessionKey:a,onSelectSession:o,onSelectFile:c,onCloseFile:l,onSelectCronJobs:u}=e,d=t.map(e=>{let t=a[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:i?.kind===`child-session`&&i.tab.sessionKey===e.sessionKey,showUnreadDot:XN({active:i?.kind===`child-session`&&i.tab.sessionKey===e.sessionKey,lastMessageAt:e.lastMessageAt,readAt:n,runStatus:e.runStatus}),onSelect:()=>o(e.sessionKey)}}),f=n.map(e=>({key:`file:${e.key}`,kind:`file`,title:vR(e),tooltip:e.path,viewMode:e.viewMode,active:i?.kind===`file`&&i.file.key===e.key,onSelect:()=>c(e.key),onClose:()=>l(e.key)})),p=r>0?[{key:`cron:session`,kind:`cron`,title:s(`chatWorkspaceSessionCronJobs`),tooltip:s(`chatWorkspaceSessionCronJobs`),active:i?.kind===`cron`,onSelect:u}]:[];return[...d,...f,...p]}function $R({sessionKey:e,childSessionTabs:t,activeChildSessionKey:n,workspaceFileTabs:i,activeWorkspaceFileKey:a,activePanelKind:o,sessionCronJobs:s=[],sessionProjectRoot:c,sessionWorkingDir:l,displayMode:u=`docked`}){let d=ic(),f=RL(t),p=eP(e=>e.optimisticReadAtBySessionKey),m=yR({activeChildSessionKey:n,activeWorkspaceFileKey:a,activePanelKind:o,childSessionTabs:f,workspaceFileTabs:i,sessionCronJobCount:s.length}),h=f.some(e=>!!e.parentSessionKey);(0,F.useEffect)(()=>{if(m?.kind!==`child-session`||m.tab.runStatus===`running`)return;let e=m.tab.lastMessageAt?.trim()??null;e&&d.chatSessionListManager.markSessionRead(m.tab.sessionKey,e,m.tab.readAt??null)},[m,d]);let g=(0,F.useMemo)(()=>QR({resolvedChildTabs:f,workspaceFileTabs:i,sessionCronJobCount:s.length,activeSelection:m,optimisticReadAtBySessionKey:p,onSelectSession:d.chatThreadManager.selectChildSessionDetail,onSelectFile:d.chatThreadManager.selectWorkspaceFile,onCloseFile:d.chatThreadManager.closeWorkspaceFile,onSelectCronJobs:()=>{e&&d.chatThreadManager.openSessionCronPanel(e)}}),[m,p,d.chatThreadManager,f,e,i,s.length]);return m?(0,I.jsxs)(Zt,{className:r(u===`overlay`?`bg-white`:`hidden border-gray-200/70 bg-white/95 backdrop-blur-sm md:flex`),defaultWidth:480,minWidth:360,maxWidth:860,overlay:u===`overlay`,children:[(0,I.jsx)(SR,{tabs:g,onBack:h?d.chatThreadManager.goToParentSession:void 0,onClose:d.chatThreadManager.closeWorkspacePanel}),(0,I.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col bg-white`,children:m.kind===`child-session`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(ZR,{tab:m.tab}),(0,I.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,I.jsx)(JR,{sessionKey:m.tab.sessionKey,onToolAction:d.chatThreadManager.openSessionFromToolAction,onFileOpen:d.chatThreadManager.openFilePreview})})]}):m.kind===`file`?(0,I.jsx)(NR,{file:m.file,sessionProjectRoot:c,sessionWorkingDir:l,onFileOpen:d.chatThreadManager.openFilePreview}):(0,I.jsx)(qR,{jobs:s})})]}):null}function ez({className:e,...t}){return(0,I.jsx)(`div`,{className:r(`animate-pulse rounded-md bg-slate-200`,e),...t})}var tz=[{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 nz(){return(0,I.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,I.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar`,children:(0,I.jsx)(`div`,{className:`mx-auto flex min-h-full w-full max-w-[min(1120px,100%)] flex-col px-6 py-5`,children:(0,I.jsxs)(`div`,{className:`flex flex-1 flex-col gap-8`,children:[(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(ez,{className:`h-6 w-52 rounded-lg bg-gray-200/90`}),(0,I.jsx)(`div`,{className:`space-y-5`,children:tz.map(e=>(0,I.jsx)(`div`,{className:r(`flex w-full`,e.alignmentClassName),children:(0,I.jsx)(ez,{"data-testid":`chat-conversation-skeleton-bubble`,className:r(`w-full bg-gray-200/80`,e.bubbleClassName)})},e.key))})]}),(0,I.jsxs)(`div`,{className:`mt-auto grid gap-4 pb-2 sm:grid-cols-[minmax(0,1fr)_minmax(180px,240px)] sm:items-end`,children:[(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(ez,{className:`h-4 w-40 rounded-full bg-gray-200/70`}),(0,I.jsx)(ez,{className:`h-[112px] w-full rounded-[30px] bg-gray-200/70`})]}),(0,I.jsx)(`div`,{className:`hidden justify-end sm:flex`,children:(0,I.jsx)(ez,{className:`h-10 w-36 rounded-full bg-gray-200/75`})})]})]})})}),(0,I.jsx)(`div`,{className:`border-t border-gray-200/80 bg-white p-4`,children:(0,I.jsx)(`div`,{className:`mx-auto w-full max-w-[min(1120px,100%)]`,children:(0,I.jsxs)(`div`,{className:`overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-card`,children:[(0,I.jsx)(`div`,{className:`px-4 py-2.5`,children:(0,I.jsx)(ez,{className:`h-[84px] w-full rounded-[28px] bg-gray-200/80`})}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 pb-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(ez,{className:`h-8 w-20 rounded-full bg-gray-200/75`}),(0,I.jsx)(ez,{className:`h-8 w-28 rounded-full bg-gray-200/75`}),(0,I.jsx)(ez,{className:`hidden h-8 w-24 rounded-full bg-gray-200/70 sm:block`})]}),(0,I.jsx)(ez,{className:`h-8 w-8 rounded-full bg-gray-200/85`})]})]})})})]})}function rz(){let e=ic(),t=Q(e=>e.snapshot);return(0,I.jsxs)(I.Fragment,{children:[t.isProviderStateResolved&&t.modelOptions.length===0?(0,I.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,I.jsx)(`span`,{className:`text-xs text-amber-800`,children:s(`chatModelNoOptions`)}),(0,I.jsx)(`button`,{type:`button`,onClick:e.chatThreadManager.goToProviders,className:`text-xs font-semibold text-amber-900 underline-offset-2 hover:underline`,children:s(`chatGoConfigureProvider`)})]}):null,t.sessionTypeUnavailable&&t.sessionTypeUnavailableMessage?.trim()?(0,I.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,I.jsx)(`span`,{className:`text-xs text-amber-800`,children:t.sessionTypeUnavailableMessage})}):null]})}function iz(){let e=ic(),t=Z(e=>e.snapshot.defaultSessionType),n=Q(e=>e.snapshot),r=(0,F.useRef)(null),i=n.threadRef??r,a=n.availableAgents??[],o=!n.canDeleteSession&&!n.hasSubmittedDraftMessage&&n.messages.length===0&&!n.isSending,s=n.isHistoryLoading&&n.messages.length===0&&!n.isSending&&!n.isAwaitingAssistantOutput,c=e=>a.find(t=>t.id===e)??null,l=()=>{let r=NL(c(n.agentId??`main`),t);e.chatSessionListManager.createSession(r)},u=n=>{e.chatSessionListManager.setSelectedAgentId(n),e.chatInputManager.setPendingSessionType(NL(c(n),t))},{onScroll:d}=mj({scrollRef:i,resetKey:n.sessionKey,isLoading:n.isHistoryLoading,hasContent:n.messages.length>0,contentVersion:n.messages[n.messages.length-1]??null}),f=n.messages.length>0,p=f&&n.isSending&&n.isAwaitingAssistantOutput;return(0,I.jsx)(`div`,{ref:i,onScroll:d,className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar`,children:o?(0,I.jsx)(tc,{onCreateSession:l,agents:a,selectedAgentId:n.agentId??`main`,onSelectAgent:u}):s||!f?null:(0,I.jsx)(`div`,{className:`mx-auto w-full max-w-[min(1120px,100%)] px-4 py-4 sm:px-6 sm:py-5`,children:(0,I.jsx)(_L,{messages:n.messages,isSending:p,onToolAction:e.chatThreadManager.openSessionFromToolAction,onFileOpen:e.chatThreadManager.openFilePreview})})})}function az(e,t,n,r){return e.workspacePanelParentKey===e.sessionKey?t.length>0||n.length>0||r>0:!1}function oz(e){let t=(0,F.useMemo)(()=>e.childSessionTabs.filter(t=>t.parentSessionKey===e.sessionKey),[e.childSessionTabs,e.sessionKey]),n=(0,F.useMemo)(()=>e.workspaceFileTabs.filter(t=>t.parentSessionKey===e.sessionKey),[e.sessionKey,e.workspaceFileTabs]),r=Ti({all:!0}),i=(0,F.useMemo)(()=>(r.data?.jobs??[]).filter(t=>KR(t,e.sessionKey)),[r.data?.jobs,e.sessionKey]);return{childSessionTabs:t,workspaceFileTabs:n,sessionCronJobs:i,showWorkspacePanel:az(e,t,n,i.length)}}function sz(){let e=ic(),t=Q(e=>e.snapshot);return(0,I.jsx)(kL,{parentSessionLabel:t.parentSessionKey?t.parentSessionLabel??null:null,onGoToParentSession:e.chatThreadManager.goToParentSession})}function cz({layoutMode:e,onBackToList:t}){let n=ic(),r=Q(e=>e.snapshot),{childSessionTabs:i,sessionCronJobs:a}=oz(r),o=!!(r.sessionKey||r.sessionTypeLabel),c=r.sessionDisplayName||(r.canDeleteSession&&r.sessionKey?r.sessionKey:null)||s(`chatSidebarNewTask`),l=r.agentId?.trim()??``,u=l.length>0&&l.toLowerCase()!==`main`;return(0,I.jsx)(AL,{snapshot:r,childSessionCount:i.length,sessionCronJobCount:a.length,layoutMode:e,normalizedAgentId:l,sessionHeaderTitle:c,shouldShowHeaderAgentAvatar:u,shouldShowSessionHeader:o,onBackToList:t,onOpenChildSessions:()=>{r.sessionKey&&n.chatThreadManager.openChildSessionPanel({parentSessionKey:r.sessionKey,activeChildSessionKey:i[0]?.sessionKey??null})},onOpenSessionCronJobs:()=>{!r.sessionKey||a.length===0||n.chatThreadManager.openSessionCronPanel(r.sessionKey)},onDeleteSession:n.chatThreadManager.deleteSession})}function lz({layoutMode:e}){let t=Q(e=>e.snapshot),{childSessionTabs:n,workspaceFileTabs:r,sessionCronJobs:i,showWorkspacePanel:a}=oz(t);return a?(0,I.jsx)($R,{sessionKey:t.sessionKey,childSessionTabs:n,activeChildSessionKey:t.activeChildSessionKey??null,workspaceFileTabs:r,activeWorkspaceFileKey:t.activeWorkspaceFileKey??null,activePanelKind:t.activeWorkspacePanelKind??null,sessionCronJobs:i,sessionProjectRoot:t.sessionProjectRoot??null,sessionWorkingDir:t.sessionWorkingDir??t.sessionProjectRoot??null,displayMode:e===`mobile`?`overlay`:`docked`}):null}function uz({layoutMode:e=`desktop`,onBackToList:t}){return Q(e=>e.snapshot).isProviderStateResolved?(0,I.jsxs)(`section`,{className:`flex-1 min-h-0 flex overflow-hidden bg-gradient-to-b from-gray-50/60 to-white`,children:[(0,I.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[(0,I.jsx)(sz,{}),(0,I.jsx)(cz,{layoutMode:e,onBackToList:t}),(0,I.jsx)(rz,{}),(0,I.jsx)(iz,{}),(0,I.jsx)(gP,{})]}),(0,I.jsx)(lz,{layoutMode:e})]}):(0,I.jsx)(nz,{})}var dz={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 fz({status:e,className:t}){let n=dz[e],i=s(e===`connected`?`connected`:e===`disconnected`?`disconnected`:`connecting`);return(0,I.jsx)(sn,{delayDuration:250,children:(0,I.jsxs)(ln,{children:[(0,I.jsx)(nn,{asChild:!0,children:(0,I.jsx)(`span`,{role:`status`,"aria-label":i,className:r(`inline-flex h-5 w-5 items-center justify-center`,t),children:e===`connecting`?(0,I.jsx)($t,{className:r(`h-3 w-3 animate-spin`,n.dotClass)}):(0,I.jsx)(`span`,{className:r(e===`connected`?`h-2 w-2 rounded-full`:``,n.dotClass)})})}),(0,I.jsx)(an,{side:`bottom`,className:`text-xs`,children:i})]})})}function pz(){let e=vL();return async t=>{await e({sessionKey:t.sessionKey,patch:{label:t.label},successMessage:s(`configSavedApplied`)})}}function mz(){let e=pz(),[t,n]=(0,F.useState)(null),[r,i]=(0,F.useState)(``),[a,o]=(0,F.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 hz(e,t){return e.filter(e=>Xs(e,t))}function gz(e){return e.isChildSession?e.isPromotedChildSession===!0:!0}function _z(e={}){let t=eP(e=>e.snapshot.query),n=Ci({limit:e.limit??200}),r=(0,F.useMemo)(()=>hz($I(n.data?.sessions??[]).filter(gz),t).map(e=>({session:e,runStatus:e.status===`running`?`running`:void 0})),[t,n.data?.sessions]);return{isLoading:n.isLoading,items:r}}function vz(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=Z(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,I.jsx)($s,{session:g,active:y,showUnreadDot:XN({active:y,lastMessageAt:g.lastMessageAt,readAt:x,runStatus:_}),runStatus:_,context:ks(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 yz(e){let t=e.sessionTypeOptions.find(t=>t.value===e.defaultSessionType);return[...t?[t]:[],...e.nonDefaultSessionTypeOptions]}function bz(e){let{query:t,defaultSessionType:n,nonDefaultSessionTypeOptions:i,isCreateMenuOpen:a,onCreateMenuOpenChange:o,onCreateSession:c,onQueryChange:l}=e;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`px-4 pb-3`,children:(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsxs)(ye,{variant:`primary`,className:r(`min-w-0 rounded-xl`,i.length>0?`flex-1 rounded-r-md`:`w-full`),onClick:()=>{o(!1),c(n)},children:[(0,I.jsx)(pn,{className:`mr-2 h-4 w-4`}),s(`chatSidebarNewTask`)]}),i.length>0?(0,I.jsxs)(wn,{open:a,onOpenChange:o,children:[(0,I.jsx)(Sn,{asChild:!0,children:(0,I.jsx)(ye,{variant:`primary`,size:`icon`,className:`h-9 w-10 shrink-0 rounded-xl rounded-l-md`,"aria-label":s(`chatSessionTypeLabel`),children:(0,I.jsx)(Ln,{className:`h-4 w-4`})})}),(0,I.jsxs)(bn,{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,I.jsx)(`div`,{className:`px-3 pb-1 pt-2 text-[10px] font-semibold uppercase tracking-[0.18em] text-gray-400`,children:s(`chatSessionTypeLabel`)}),(0,I.jsx)(`div`,{className:`space-y-1`,children:i.map(e=>(0,I.jsx)(Is,{option:e,onSelect:()=>{c(e.value),o(!1)}},e.value))})]})]}):null]})}),(0,I.jsx)(`div`,{className:`px-4 pb-3`,children:(0,I.jsxs)(`div`,{className:`relative`,children:[(0,I.jsx)(mn,{className:`absolute left-3 top-2.5 h-3.5 w-3.5 text-gray-400`}),(0,I.jsx)(Ne,{value:t,onChange:e=>l(e.target.value),placeholder:s(`chatSidebarSearchPlaceholder`),className:`h-9 rounded-lg pl-8 text-xs`})]})})]})}function xz(e){let{query:t,defaultSessionType:n,sessionTypeOptions:r,nonDefaultSessionTypeOptions:i,isCreateMenuOpen:a,onCreateMenuOpenChange:o,onCreateSession:c,onQueryChange:l}=e,u=yz({defaultSessionType:n,sessionTypeOptions:r,nonDefaultSessionTypeOptions:i}),d=u.length>1;return(0,I.jsx)(`div`,{className:`px-4 pb-2 pt-1`,children:(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,I.jsx)(mn,{className:`absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,I.jsx)(Ne,{value:t,onChange:e=>l(e.target.value),placeholder:s(`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,I.jsxs)(wn,{open:a,onOpenChange:o,children:[(0,I.jsx)(Sn,{asChild:!0,children:(0,I.jsx)(ye,{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":s(`chatSidebarNewTask`),children:(0,I.jsx)(pn,{className:`h-4 w-4`})})}),(0,I.jsxs)(bn,{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,I.jsx)(`div`,{className:`px-3 pb-1.5 pt-2 text-[11px] font-medium text-gray-400`,children:s(`chatSidebarNewTask`)}),(0,I.jsx)(`div`,{className:`space-y-1`,children:u.map(e=>(0,I.jsx)(Is,{option:e,onSelect:()=>{c(e.value),o(!1)}},e.value))})]})]}):(0,I.jsx)(ye,{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":s(`chatSidebarNewTask`),onClick:()=>c(n),children:(0,I.jsx)(pn,{className:`h-4 w-4`})})]})})}function Sz({isOpen:e,onOpenChange:t,currentTheme:n,currentThemeLabel:r,themeOptions:i,onSelectTheme:a,currentLanguage:o,currentLanguageLabel:c,languageOptions:l,onSelectLanguage:u,onOpenDocs:d,onOpenApps:f}){let p=()=>{d(),t(!1)},m=()=>{f(),t(!1)};return(0,I.jsxs)(wn,{open:e,onOpenChange:t,children:[(0,I.jsx)(Sn,{asChild:!0,children:(0,I.jsxs)(`button`,{type:`button`,"aria-label":o===`zh`?`设置菜单`:`Settings menu`,className:`flex w-full items-center gap-2.5 rounded-xl px-3 py-2 text-[13px] font-medium text-gray-600 transition-all duration-base hover:bg-gray-200/60 hover:text-gray-800`,children:[(0,I.jsx)(_r,{className:`h-4 w-4 shrink-0 text-gray-400`}),(0,I.jsx)(`span`,{className:`min-w-0 flex-1 text-left`,children:s(`settings`)}),(0,I.jsxs)(`span`,{className:`max-w-[112px] truncate text-[13px] text-gray-500`,children:[r,` / `,c]})]})}),(0,I.jsxs)(bn,{side:`top`,align:`start`,className:`w-64 p-2`,children:[(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsxs)(w,{to:`/settings`,onClick:()=>t(!1),className:`flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-[13px] font-medium text-gray-700 transition-colors hover:bg-gray-100`,children:[(0,I.jsx)(_r,{className:`h-4 w-4 text-gray-400`}),(0,I.jsx)(`span`,{className:`flex-1 text-left`,children:s(`settings`)})]}),(0,I.jsxs)(`button`,{type:`button`,onClick:p,className:`flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-[13px] font-medium text-gray-700 transition-colors hover:bg-gray-100`,children:[(0,I.jsx)(Qt,{className:`h-4 w-4 text-gray-400`}),(0,I.jsx)(`span`,{className:`flex-1 text-left`,children:s(`docBrowserHelp`)})]}),(0,I.jsxs)(`button`,{type:`button`,onClick:m,className:`flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-[13px] font-medium text-gray-700 transition-colors hover:bg-gray-100`,children:[(0,I.jsx)(un,{className:`h-4 w-4 text-gray-400`}),(0,I.jsx)(`span`,{className:`flex-1 text-left`,children:s(`appsTitle`)})]})]}),(0,I.jsx)(`div`,{className:`my-2 h-px bg-gray-200/70`}),(0,I.jsx)(Cz,{icon:pr,label:s(`theme`),options:i,value:n,valueLabel:r,onSelect:a,onCloseMenu:()=>t(!1)}),(0,I.jsx)(Cz,{icon:cr,label:s(`language`),options:l,value:o,valueLabel:c,onSelect:u,onCloseMenu:()=>t(!1)})]})]})}function Cz({icon:e,label:t,options:n,value:r,valueLabel:i,onSelect:a,onCloseMenu:o}){return(0,I.jsxs)(vo,{value:r,onOpenChange:e=>{e||o()},onValueChange:e=>a(e),children:[(0,I.jsxs)(bo,{"aria-label":t,className:`h-auto w-full rounded-lg border-0 bg-transparent px-3 py-2 text-[13px] font-medium text-gray-700 shadow-none hover:bg-gray-100 focus:ring-0`,indicator:(0,I.jsx)(Rn,{className:`h-4 w-4 text-gray-400`}),children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2.5`,children:[(0,I.jsx)(e,{className:`h-4 w-4 shrink-0 text-gray-400`}),(0,I.jsx)(`span`,{className:`text-left`,children:t})]}),(0,I.jsx)(`span`,{className:`ml-auto max-w-[96px] truncate text-[13px] text-gray-500`,children:i})]}),(0,I.jsx)(Co,{side:`right`,align:`center`,sideOffset:6,className:`z-[var(--z-tooltip)] min-w-[7rem] rounded-lg`,viewportClassName:`h-auto min-w-[7rem] w-auto`,children:n.map(e=>(0,I.jsx)(To,{value:e.value,className:`text-[13px]`,children:e.label},e.value))})]})}function wz(e){return new Date(e.session.lastMessageAt??e.session.createdAt).getTime()}function Tz(e){return[...e].sort((e,t)=>wz(t)-wz(e))}function Ez(e){let t=new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),r=n-864e5,i=n-7*864e5,a=[],o=[],c=[],l=[];for(let t of e){let e=wz(t);e>=n?a.push(t):e>=r?o.push(t):e>=i?c.push(t):l.push(t)}let u=[];return a.length>0&&u.push({label:s(`chatSidebarToday`),items:a}),o.length>0&&u.push({label:s(`chatSidebarYesterday`),items:o}),c.length>0&&u.push({label:s(`chatSidebarPrevious7Days`),items:c}),l.length>0&&u.push({label:s(`chatSidebarOlder`),items:l}),u}function Dz(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=wz(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()||SI(e)||e,items:[n],latestUpdatedAt:i})}return[...t.values()].map(e=>({...e,items:Tz(e.items)})).sort((e,t)=>t.latestUpdatedAt-e.latestUpdatedAt)}function Oz(e){let t=new Map;for(let n of e){let e=n.session.parentSessionId?.trim();if(!e)continue;let r=t.get(e)??[];r.push(n),t.set(e,r)}for(let e of t.values())e.sort((e,t)=>wz(t)-wz(e));return t}function kz(e){if(e.label&&e.label.trim())return e.label.trim();let t=e.key.split(`:`);return t[t.length-1]||e.key}var Az=[{target:`/cron`,label:()=>s(`chatSidebarScheduledTasks`),icon:jn},{target:`/skills`,label:()=>s(`chatSidebarSkills`),icon:E},{target:`/agents`,label:()=>s(`agentsPageTitle`),icon:Pn}];function jz(e,t,n){let r=eP(e=>e.optimisticReadAtBySessionKey);return(0,F.useEffect)(()=>{(()=>{if(!t)return;let r=e.find(({session:e})=>e.key===t);if(!r||r.runStatus===`running`)return;let{session:i}=r;n(i.key,i.lastMessageAt,i.readAt)})()},[e,n,t]),r}function Mz({variant:e=`desktop`}){let n=e===`mobile`,i=ic(),a=Dn(),[o,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(!1),d=Z(e=>e.snapshot),f=eP(e=>e.snapshot),p=bt(),m=aL(),{isLoading:h,items:g}=_z(),{language:_,setLanguage:v}=kr(),{theme:y,setTheme:b}=es(),x=s(qr.find(e=>e.value===y)?.labelKey??`themeWarm`),S=t.find(e=>e.value===_)?.label??_,C=(0,F.useMemo)(()=>qr.map(e=>({value:e.value,label:s(e.labelKey)})),[]),w=(0,F.useMemo)(()=>t.map(e=>({value:e.value,label:e.label})),[]),T=(0,F.useMemo)(()=>new Map((m.data?.agents??[]).map(e=>[e.id,e])),[m.data?.agents]),E=(0,F.useMemo)(()=>Tz(g),[g]),D=(0,F.useMemo)(()=>Oz(g),[g]),O=(0,F.useMemo)(()=>Ez(E),[E]),k=(0,F.useMemo)(()=>Dz(E),[E]),A=d.defaultSessionType||`native`,ee=(0,F.useMemo)(()=>d.sessionTypeOptions.filter(e=>e.value!==A),[A,d.sessionTypeOptions]),j=f.listMode===`project-first`,te=jz(g,f.selectedSessionKey,i.chatSessionListManager.markSessionRead),{editingSessionKey:M,draftLabel:ne,savingSessionKey:re,setDraftLabel:ie,startEditingSessionLabel:ae,cancelEditingSessionLabel:se,saveSessionLabel:ce}=mz(),le=e=>{_!==e&&(v(e),window.location.reload())},ue=e=>(0,I.jsx)(vz,{item:e,selectedSessionKey:f.selectedSessionKey,optimisticReadAtBySessionKey:te,agentsById:T,childSessionsByParentKey:D,editingSessionKey:M,draftLabel:ne,savingSessionKey:re,sessionTitle:kz,onSelectSession:i.chatSessionListManager.selectSession,onOpenChildSessions:(e,t)=>i.chatThreadManager.openChildSessionPanel({parentSessionKey:e,activeChildSessionKey:t}),onStartEditingSessionLabel:ae,onDraftLabelChange:ie,onSaveSessionLabel:ce,onCancelEditingSessionLabel:se},e.session.key),de=(e,t)=>{i.chatSessionListManager.createSession(e,typeof t==`string`?t:void 0)};return(0,I.jsxs)(`aside`,{className:r(`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&&!ls()?(0,I.jsx)(`div`,{className:`px-5 py-2.5`,children:(0,I.jsx)(ji,{className:`flex min-w-0 items-center gap-2`,suffix:(0,I.jsx)(fz,{status:p.connectionStatus})})}):null,n?(0,I.jsx)(xz,{query:f.query,defaultSessionType:A,sessionTypeOptions:d.sessionTypeOptions,nonDefaultSessionTypeOptions:ee,isCreateMenuOpen:o,onCreateMenuOpenChange:c,onCreateSession:de,onQueryChange:i.chatSessionListManager.setQuery}):(0,I.jsx)(bz,{query:f.query,defaultSessionType:A,sessionTypeOptions:d.sessionTypeOptions,nonDefaultSessionTypeOptions:ee,isCreateMenuOpen:o,onCreateMenuOpenChange:c,onCreateSession:de,onQueryChange:i.chatSessionListManager.setQuery}),n?null:(0,I.jsx)(`div`,{className:`px-3 pb-2`,children:(0,I.jsx)(`ul`,{className:`space-y-0.5`,children:Az.map(e=>(0,I.jsx)(`li`,{children:(0,I.jsx)(ko,{to:e.target,label:e.label(),icon:e.icon,density:`compact`})},e.target))})}),n?null:(0,I.jsx)(`div`,{className:`mx-4 border-t border-gray-200/60`}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between px-5 pb-2 pt-3`,children:[(0,I.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-gray-400`,children:s(`chatSidebarTaskRecords`)}),(0,I.jsx)(_s,{isProjectFirstView:j,onSelectMode:i.chatSessionListManager.setListMode})]}),(0,I.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar px-3 py-2`,children:h?(0,I.jsx)(`div`,{className:`text-xs text-gray-500 p-3`,children:s(`sessionsLoading`)}):j?k.length===0?(0,I.jsxs)(`div`,{className:`p-4 text-center`,children:[(0,I.jsx)(ur,{className:`h-6 w-6 mx-auto mb-2 text-gray-300`}),(0,I.jsx)(`div`,{className:`text-xs text-gray-500`,children:s(`chatSidebarProjectViewEmpty`)})]}):(0,I.jsx)(Rs,{groups:k,defaultSessionType:A,sessionTypeOptions:d.sessionTypeOptions,renderSessionItem:ue,onCreateSession:de}):O.length===0?(0,I.jsxs)(`div`,{className:`p-4 text-center`,children:[(0,I.jsx)(ur,{className:`h-6 w-6 mx-auto mb-2 text-gray-300`}),(0,I.jsx)(`div`,{className:`text-xs text-gray-500`,children:s(`sessionsEmpty`)})]}):(0,I.jsx)(`div`,{className:`space-y-3`,children:O.map(e=>(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`px-2 py-1 text-[11px] font-medium text-gray-400 uppercase tracking-wider`,children:e.label}),(0,I.jsx)(`div`,{className:`space-y-0.5`,children:e.items.map(ue)})]},e.label))})}),n?null:(0,I.jsx)(`div`,{className:`px-3 py-3 border-t border-gray-200/60`,children:(0,I.jsx)(Sz,{isOpen:l,onOpenChange:u,currentTheme:y,currentThemeLabel:x,themeOptions:C,onSelectTheme:b,currentLanguage:_,currentLanguageLabel:S,languageOptions:w,onSelectLanguage:le,onOpenDocs:()=>a.open(void 0,{kind:`docs`,title:s(`docBrowserHelp`)}),onOpenApps:()=>oe(a)})})]})}function Nz(){return Ve({queryKey:[`ncp-session-types`],queryFn:Be,staleTime:1e4,retry:!1})}function Pz(e){let t=e.trim();return t.length>0?t:null}function Fz(e){return e??null}var Iz=class{constructor(e){this.updateSession=e,this.inFlight=null,this.queued=null,this.syncSelectedSessionPreferences=()=>{let e=Z.getState().snapshot,t=eP.getState().snapshot,n=Q.getState().snapshot,r=t.selectedSessionKey;!r||!n.canDeleteSession||this.enqueue({sessionKey:r,patch:{preferredModel:Pz(e.selectedModel),preferredThinking:Fz(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)}}}},Lz=class{constructor(e,t,n){this.uiManager=e,this.streamActionsManager=t,this.sessionListManager=n,this.sessionPreferenceSync=new Iz(gt),this.buildAttachmentSignature=e=>[e.assetUri??``,e.url??``,e.name,e.mimeType,String(e.sizeBytes),e.contentBase64??``].join(`:`),this.hasSnapshotChanges=e=>{let t=Z.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.isRuntimeBlockedForSend=()=>aP(vt.getStatusView()),this.syncComposerSnapshot=e=>{let t=Z.getState().snapshot.attachments,n=PN(e,t);Z.getState().setSnapshot({composerNodes:e,attachments:n,draft:kN(e),selectedSkills:AN(e)})},this.syncComposerSnapshotWithAttachments=(e,t)=>{Z.getState().setSnapshot({composerNodes:e,attachments:t,draft:kN(e),selectedSkills:AN(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)&&(Z.getState().setSnapshot(e),Object.prototype.hasOwnProperty.call(e,`modelOptions`)||Object.prototype.hasOwnProperty.call(e,`selectedModel`)||Object.prototype.hasOwnProperty.call(e,`selectedThinkingLevel`))){let{selectedModel:e}=Z.getState().snapshot;this.reconcileThinkingForModel(e)}},this.setDraft=e=>{let t=Z.getState().snapshot.draft,n=this.resolveUpdateValue(t,e);n!==t&&this.syncComposerSnapshot(ON(n))},this.requestComposerFocusAtEnd=()=>{let e=Z.getState().snapshot.composerFocusRequest;Z.getState().setSnapshot({composerFocusRequest:{id:(e?.id??0)+1,placement:`end`}})},this.consumeComposerFocusRequest=e=>{Z.getState().snapshot.composerFocusRequest?.id===e&&Z.getState().setSnapshot({composerFocusRequest:null})},this.setComposerNodes=e=>{let t=Z.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}=Z.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=NN(t.composerNodes,r);return this.syncComposerSnapshotWithAttachments(a,r),i},this.restoreComposerState=(e,t)=>{let n=this.dedupeAttachments(t),r=NN(e,n);this.syncComposerSnapshotWithAttachments(r,n)},this.setPendingSessionType=e=>{let t=Z.getState().snapshot.pendingSessionType,n=this.resolveUpdateValue(t,e);n!==t&&Z.getState().setSnapshot({pendingSessionType:n})},this.send=async()=>{let e=Z.getState().snapshot,t=eP.getState().snapshot,n=Q.getState().snapshot,r=e.draft.trim(),{attachments:i}=e,a=FN(e.composerNodes,i);if(WN({snapshot:e,hasSendableDraft:a.some(e=>e.type!==`text`||e.text.trim().length>0),isRuntimeBlocked:this.isRuntimeBlockedForSend()}))return;let{selectedSkills:o,composerNodes:s}=e,c=n.sessionKey??t.selectedSessionKey??null;!c&&e.selectedSessionType?.trim()&&this.sessionListManager.ensureDraftSession(e.selectedSessionType),this.setComposerNodes(DN()),await this.streamActionsManager.sendMessage({message:r,...c?{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.stop=async()=>{await this.streamActionsManager.stopCurrentRun()},this.goToProviders=()=>{this.uiManager.goToProviders()},this.setSelectedModel=e=>{let t=Z.getState().snapshot.selectedModel,n=this.resolveUpdateValue(t,e);n!==t&&(Z.getState().setSnapshot({selectedModel:n}),this.reconcileThinkingForModel(n))},this.setSelectedThinkingLevel=e=>{let t=Z.getState().snapshot.selectedThinkingLevel,n=this.resolveUpdateValue(t,e);n!==t&&Z.getState().setSnapshot({selectedThinkingLevel:n})},this.selectSessionType=e=>{let t=ML(e);Z.getState().setSnapshot({selectedSessionType:t,pendingSessionType:t})},this.setSelectedSkills=e=>{let{snapshot:t}=Z.getState(),{selectedSkills:n}=t,r=this.resolveUpdateValue(n,e);this.isSameStringArray(r,n)||this.syncComposerSnapshot(MN(t.composerNodes,r,t.skillRecords))},this.selectModel=e=>{this.setSelectedModel(e),RN.remember(e),this.sessionPreferenceSync.syncSelectedSessionPreferences()},this.selectThinkingLevel=e=>{this.setSelectedThinkingLevel(e),this.sessionPreferenceSync.syncSelectedSessionPreferences()},this.rememberSkillSelection=e=>{zN.remember(e)},this.selectSkills=e=>{let t=Z.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}=Z.getState(),n=t.modelOptions.find(t=>t.value===e),{selectedThinkingLevel:r}=t,i=this.resolveThinkingForModel(n,r);i!==r&&Z.getState().setSnapshot({selectedThinkingLevel:i})}}},Rz=`sid_`,zz=`/chat/draft`,Bz=zz.slice(6);function Vz(e){let t=new TextEncoder().encode(e),n=``;for(let e of t)n+=String.fromCharCode(e);return`${Rz}${btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/g,``)}`}function Hz(e){if(!e.startsWith(Rz))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 Uz(e){if(!e||e===Bz)return null;let t=Hz(e);if(t)return t;try{return decodeURIComponent(e)}catch{return e}}function Wz(e){return`/chat/${Vz(e)}`}var Gz=class{constructor(e,t){this.uiManager=e,this.streamActionsManager=t,this.syncDraftThreadState=(e=!1)=>{Q.getState().setSnapshot({sessionKey:null,sessionDisplayName:void 0,canDeleteSession:!1,isHistoryLoading:!1,messages:[],isSending:!1,isAwaitingAssistantOutput:!1,hasSubmittedDraftMessage:e,parentSessionKey:null,parentSessionLabel:null,workspacePanelParentKey:null,activeWorkspacePanelKind:null,childSessionTabs:[],activeChildSessionKey:null,activeWorkspaceFileKey:null})},this.resolveUpdateValue=(e,t)=>typeof t==`function`?t(e):t,this.shouldPersistReadAt=(e,t,n)=>{let r=eP.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=eP.getState().snapshot.selectedAgentId,n=this.resolveUpdateValue(t,e);n!==t&&eP.getState().setSnapshot({selectedAgentId:n})},this.setSelectedSessionKey=e=>{let t=eP.getState().snapshot.selectedSessionKey,n=this.resolveUpdateValue(t,e);n!==t&&eP.getState().setSnapshot({selectedSessionKey:n})},this.setListMode=e=>{let t=eP.getState().snapshot.listMode,n=this.resolveUpdateValue(t,e);n!==t&&eP.getState().setSnapshot({listMode:n})},this.markSessionRead=(e,t,n)=>{let r=e?.trim(),i=t?.trim();!r||!i||this.shouldPersistReadAt(r,i,n)&&(eP.getState().markSessionRead(r,i),gt(r,{uiReadAt:i}).catch(()=>void 0))},this.createSession=(e,t)=>{let{snapshot:n}=Z.getState(),{defaultSessionType:r}=n,i=r||`native`,a=typeof e==`string`&&e.trim().length>0?e.trim():i,o=xI(t);this.streamActionsManager.resetStreamState(),eP.getState().setSnapshot({selectedSessionKey:null}),this.syncDraftThreadState(),Z.getState().setSnapshot({pendingSessionType:a,pendingProjectRoot:o,pendingProjectRootSessionKey:null}),this.uiManager.navigateTo(zz)},this.startAgentDraftChat=(e,t)=>{let n=e.trim()||`main`;this.createSession(t),this.setSelectedAgentId(n)},this.ensureDraftSession=e=>{let{snapshot:t}=eP.getState();if(t.selectedSessionKey)return t.selectedSessionKey;let n=typeof e==`string`&&e.trim().length>0?e.trim():null;return this.syncDraftThreadState(!0),n&&Z.getState().setSnapshot({pendingSessionType:n}),null},this.materializeRootSessionRoute=e=>{let t=e.trim();t&&this.uiManager.isAtChatRoot()&&this.uiManager.goToSession(t,{replace:!0})},this.selectSession=e=>{this.uiManager.goToSession(e)},this.setQuery=e=>{let t=eP.getState().snapshot.query,n=this.resolveUpdateValue(t,e);n!==t&&eP.getState().setSnapshot({query:n})}}},Kz=async()=>{},qz=()=>{},Jz=class{constructor(){this.actions={sendMessage:Kz,stopCurrentRun:Kz,resumeRun:Kz,resetStreamState:qz,applyHistoryMessages:qz},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)}},Yz=async e=>!1,Xz=class{constructor(){this.state={pathname:``},this.actions={navigate:null,confirm:Yz},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.state.pathname===`/chat/draft`,this.goToSession=(e,t)=>{this.navigateTo(Wz(e),t)}}},Zz=class{constructor(e,t,n){this.uiManager=e,this.sessionListManager=t,this.streamActionsManager=n,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.syncSnapshot=e=>{this.hasSnapshotChanges(e)&&Q.getState().setSnapshot(e)},this.clearDeletedSessionState=e=>{eP.getState().snapshot.selectedSessionKey===e&&this.sessionListManager.setSelectedSessionKey(null),Q.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,activeWorkspacePanelKind:null,childSessionTabs:[],activeChildSessionKey:null,workspaceFileTabs:[],activeWorkspaceFileKey:null})},this.resolveWorkspaceParentSessionKey=()=>Q.getState().snapshot.sessionKey?.trim()||(eP.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}=Q.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}}=eP.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;Q.getState().setSnapshot({workspacePanelParentKey:t,activeWorkspacePanelKind:`child-session`,activeChildSessionKey:n,activeWorkspaceFileKey:null}),this.ensureWorkspaceParentRoute(t)},this.openFilePreview=e=>{let t=this.resolveWorkspaceParentSessionKey(),n=this.buildWorkspaceFileTab(e,t);n&&(Q.getState().setSnapshot({workspacePanelParentKey:t,activeWorkspacePanelKind:`file`,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()||eP.getState().snapshot.selectedSessionKey||null;if(t){this.openChildSessionPanel({parentSessionKey:t,activeChildSessionKey:e.sessionId});return}}Q.getState().setSnapshot({workspacePanelParentKey:null,activeWorkspacePanelKind:null,activeChildSessionKey:null,activeWorkspaceFileKey:null}),this.uiManager.goToSession(e.sessionId)}},this.selectChildSessionDetail=e=>{let t=e.trim();if(!t)return;let{childSessionTabs:n}=Q.getState().snapshot;n.some(e=>e.sessionKey===t)&&Q.getState().setSnapshot({activeChildSessionKey:t,activeWorkspaceFileKey:null,activeWorkspacePanelKind:`child-session`})},this.selectWorkspaceFile=e=>{let t=e.trim();if(!t)return;let{workspaceFileTabs:n}=Q.getState().snapshot;n.some(e=>e.key===t)&&Q.getState().setSnapshot({activeWorkspaceFileKey:t,activeChildSessionKey:null,activeWorkspacePanelKind:`file`})},this.closeWorkspaceFile=e=>{let t=e.trim();if(!t)return;let{snapshot:n}=Q.getState(),{activeWorkspaceFileKey:r,workspaceFileTabs:i}=n,a={workspaceFileTabs:i.filter(e=>e.key!==t)};r===t&&(a.activeWorkspaceFileKey=null),Q.getState().setSnapshot(a)},this.closeWorkspacePanel=()=>{Q.getState().setSnapshot({workspacePanelParentKey:null,activeWorkspacePanelKind:null,activeChildSessionKey:null,activeWorkspaceFileKey:null})},this.openSessionCronPanel=e=>{let t=e.trim();t&&(Q.getState().setSnapshot({workspacePanelParentKey:t,activeWorkspacePanelKind:`cron`,activeChildSessionKey:null,activeWorkspaceFileKey:null}),this.ensureWorkspaceParentRoute(t))},this.closeChildSessionDetail=()=>{this.closeWorkspacePanel()},this.goToParentSession=()=>{let{parentSessionKey:e,childSessionTabs:t,activeChildSessionKey:n}=Q.getState().snapshot,r=t.find(e=>e.sessionKey===n)?.parentSessionKey??null,i=e??r;i&&(this.closeWorkspacePanel(),this.uiManager.goToSession(i))},this.isCompactViewport=()=>Nr.getSnapshot().mode===`mobile`,this.deleteCurrentSession=async()=>{let{snapshot:{selectedSessionKey:e}}=eP.getState();if(e&&await this.uiManager.confirm({title:s(`chatDeleteSessionConfirm`),variant:`destructive`,confirmLabel:s(`delete`)})){Q.getState().setSnapshot({isDeletePending:!0});try{await ct(e),et(De,e),De.removeQueries({queryKey:[`ncp-session-messages`,e]}),this.streamActionsManager.resetStreamState(),this.clearDeletedSessionState(e),this.uiManager.goToChatRoot({replace:!0})}finally{Q.getState().setSnapshot({isDeletePending:!1})}}}}},Qz=class{constructor(){this.chatUiManager=new Xz,this.chatStreamActionsManager=new Jz,this.chatSessionListManager=new Gz(this.chatUiManager,this.chatStreamActionsManager),this.chatInputManager=new Lz(this.chatUiManager,this.chatStreamActionsManager,this.chatSessionListManager),this.chatThreadManager=new Zz(this.chatUiManager,this.chatSessionListManager,this.chatStreamActionsManager),this.startAgentCreationDraft=e=>{this.chatSessionListManager.createSession(),this.chatSessionListManager.setSelectedAgentId(`main`),this.chatInputManager.setDraft(e),this.chatInputManager.requestComposerFocusAtEnd()}}};function $z(e){return e?.trim().toLowerCase()||`native`}function eB(e,t){if(typeof t!=`string`)return!1;let n=t.trim();return n?e.some(e=>e.value===n):!1}function tB(e,t){return typeof t==`string`&&e.includes(t)}function nB(e){return e.length===0?null:e.includes(`off`)?`off`:e[0]??null}function rB(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 iB(e){let{modelOptions:t,currentSelectedModel:n,selectedSessionPreferredModel:r,fallbackPreferredModel:i,defaultModel:a,preferSessionPreferredModel:o,preserveCurrentSelectedModelOnSessionChange:s}=e;return t.length===0?``:rB({currentValue:n,selectedSessionPreferredValue:r,fallbackPreferredValue:i,defaultValue:a,isValueSupported:e=>eB(t,e),firstAvailableValue:t[0]?.value??``,preferSessionPreferredValue:o,preserveCurrentValueOnSessionChange:s})}function aB(e){let{supportedThinkingLevels:t,currentSelectedThinkingLevel:n,selectedSessionPreferredThinking:r,fallbackPreferredThinking:i,defaultThinkingLevel:a,preferSessionPreferredThinking:o,preserveCurrentSelectedThinkingOnSessionChange:s}=e;return t.length===0?null:rB({currentValue:n,selectedSessionPreferredValue:r,fallbackPreferredValue:i,defaultValue:a,isValueSupported:e=>tB(t,e),firstAvailableValue:nB(t)??`off`,preferSessionPreferredValue:o,preserveCurrentValueOnSessionChange:s})}function oB(e){let{sessions:t,selectedSessionKey:n,sessionType:r,readPreference:i}=e,a=$z(r),o,s=-1/0;for(let e of t){if(e.key===n||$z(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 sB(e){return e.map(e=>e==null?``:String(e)).join(``)}function cB(e){let{isPreferenceAvailable:t,emptyValue:n,syncKey:r,selectedSessionKey:i,selectedSessionExists:a=!1,setValue:o,resolveValue:s}=e,c=(0,F.useRef)(void 0),l=(0,F.useRef)(s),u=(0,F.useRef)(n);(0,F.useEffect)(()=>{l.current=s},[s]),(0,F.useEffect)(()=>{let e=c.current!==i;if(!t){o(n),u.current=n,c.current=i;return}o(t=>{let r=l.current({currentValue:!e&&Object.is(t,u.current)?n:t,sessionChanged:e,preserveCurrentValueOnSessionChange:e&&!!i&&!a});return u.current=r,r}),c.current=i},[n,t,a,i,o,r])}function lB(e){let{modelOptions:t,selectedSessionKey:n,selectedSessionExists:r=!1,selectedSessionPreferredModel:i,fallbackPreferredModel:a,defaultModel:o,setSelectedModel:s}=e;cB({isPreferenceAvailable:t.length>0,emptyValue:``,syncKey:sB([t.map(e=>e.value).join(``),i,a,o]),selectedSessionKey:n,selectedSessionExists:r,setValue:s,resolveValue:({currentValue:e,sessionChanged:n,preserveCurrentValueOnSessionChange:r})=>iB({currentSelectedModel:e,modelOptions:t,selectedSessionPreferredModel:i,fallbackPreferredModel:a,defaultModel:o,preferSessionPreferredModel:n,preserveCurrentSelectedModelOnSessionChange:r})})}function uB(e){let{supportedThinkingLevels:t,selectedSessionKey:n,selectedSessionExists:r=!1,selectedSessionPreferredThinking:i,fallbackPreferredThinking:a,defaultThinkingLevel:o,setSelectedThinkingLevel:s}=e;cB({isPreferenceAvailable:t.length>0,emptyValue:null,syncKey:sB([t.join(``),i,a,o]),selectedSessionKey:n,selectedSessionExists:r,setValue:s,resolveValue:({currentValue:e,sessionChanged:n,preserveCurrentValueOnSessionChange:r})=>aB({currentSelectedThinkingLevel:e,supportedThinkingLevels:t,selectedSessionPreferredThinking:i,fallbackPreferredThinking:a,defaultThinkingLevel:o,preferSessionPreferredThinking:n,preserveCurrentSelectedThinkingOnSessionChange:r})})}function dB(){let{pathname:e}=S(),t=C();return Br(e)?(0,I.jsx)(uz,{layoutMode:`mobile`,onBackToList:()=>t(`/chat`)}):(0,I.jsx)(Mz,{variant:`mobile`})}var fB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{DocBrowser:e}=await import(`./doc-browser-D5FJcAyz.js`);return{DocBrowser:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11]))).DocBrowser}));function pB({pathname:e,isMobileLayout:t=!1,isDocBrowserOpen:n,docBrowserMode:i,docBrowserDockControls:a,docBrowserRenderers:o={},sideDock:s,children:c}){let l=zr(e),u=t&&!Br(e),d=ls();return(0,I.jsxs)(`div`,{className:r(`h-screen flex flex-col overflow-hidden bg-background font-sans text-foreground`,d?`rounded-[10px]`:null),style:d?{"--desktop-titlebar-height":`40px`,"--desktop-caption-safe-right":`140px`,"--desktop-sidebar-width":l?`280px`:`240px`}:void 0,children:[d?(0,I.jsx)(as,{}):null,(0,I.jsxs)(`div`,{className:`flex min-h-0 flex-1 overflow-hidden`,children:[!l&&(0,I.jsx)(rs,{mode:`settings`}),(0,I.jsxs)(`div`,{className:`flex-1 flex min-w-0 overflow-hidden relative`,children:[(0,I.jsx)(`div`,{className:`flex-1 flex flex-col min-w-0 overflow-hidden`,children:l?(0,I.jsx)(`div`,{className:`flex-1 h-full overflow-hidden`,children:c}):(0,I.jsx)(`main`,{className:`flex-1 overflow-auto p-8 pb-16 custom-scrollbar`,children:(0,I.jsx)(`div`,{className:`mx-auto h-full max-w-6xl animate-fade-in`,children:c})})}),n&&i===`docked`?(0,I.jsx)(F.Suspense,{fallback:null,children:(0,I.jsx)(fB,{customTabRenderers:o,dockControls:a})}):null,s]})]}),u?(0,I.jsx)(fs,{}):null,n&&i===`floating`?(0,I.jsx)(F.Suspense,{fallback:null,children:(0,I.jsx)(fB,{customTabRenderers:o,dockControls:a})}):null]})}var mB=`NextClaw`,hB=[{prefix:`/marketplace/mcp`,key:`marketplaceMcpPageTitle`},{prefix:`/marketplace/skills`,key:`marketplaceSkillsPageTitle`},{prefix:`/marketplace`,key:`marketplace`},{prefix:`/skills`,key:`marketplaceSkillsPageTitle`},{prefix:`/cron`,key:`cronPageTitle`},{prefix:`/agents`,key:`agentsPageTitle`},{prefix:`/chat`,key:`chat`},{prefix:`/model`,key:`modelPageTitle`},{prefix:`/search`,key:`searchPageTitle`},{prefix:`/providers`,key:`providersPageTitle`},{prefix:`/channels`,key:`channelsPageTitle`},{prefix:`/runtime`,key:`runtimePageTitle`},{prefix:`/updates`,key:`runtimeUpdatesPageTitle`},{prefix:`/remote`,key:`remotePageTitle`},{prefix:`/security`,key:`authSecurityTitle`},{prefix:`/secrets`,key:`secretsPageTitle`}];function gB(e,t){return e===t||e.startsWith(`${t}/`)}function _B(e){let t=e.toLowerCase();for(let{prefix:e,key:n}of hB)if(gB(t,e))return s(n);return s(`settings`)}function vB(e){return`${mB} - ${_B(e)}`}function yB({children:e,sideDockManager:t}){let{isOpen:n,mode:r}=Dn();Er();let{pathname:i}=S(),{language:a}=kr(),{isMobile:o}=Pr(),s=cs();A(e=>e.pinnedItems);let c={getDockState:t.getDockState,pinTab:t.pinTab,unpinTab:t.unpinTab};return(0,F.useEffect)(()=>{document.title=vB(i)},[i,a]),o&&s!==`win32`?(0,I.jsx)(hs,{pathname:i,isDocBrowserOpen:n,docBrowserDockControls:c,docBrowserRenderers:ie,topbarLeadingInset:s===`darwin`?`4.75rem`:void 0,children:e}):(0,I.jsx)(pB,{pathname:i,isMobileLayout:o,isDocBrowserOpen:n,docBrowserMode:r,docBrowserDockControls:c,docBrowserRenderers:ie,sideDock:(0,I.jsx)(j,{manager:t}),children:e})}function bB({children:e}){let t=ae();return(0,I.jsx)(kn,{manager:t.docBrowserManager,children:(0,I.jsx)(yB,{sideDockManager:t.sideDockManager,children:e})})}function xB(){let{isMobile:e}=Pr();return e?(0,I.jsx)(gs,{}):(0,I.jsx)(T,{to:`/model`,replace:!0})}function SB(e){let t=e.trim().toLowerCase();return t?!t.startsWith(`skills`):!0}function CB(e,t){t.startsWith(`mcp`)&&(e?.invalidateQueries({queryKey:[`marketplace-mcp-installed`]}),e?.invalidateQueries({queryKey:[`marketplace-mcp-items`]}),e?.invalidateQueries({queryKey:[`marketplace-mcp-doctor`]}))}function wB(e,t){e&&SB(t)&&e.invalidateQueries({queryKey:[`config`]}),CB(e,t)}function TB(e){let t=(0,F.useRef)(!1);(0,F.useEffect)(()=>{let n=Xe.eventBus.on(Re.connectionOpen,()=>{vt.handleConnectionRestored(),at.refreshAfterRealtimeReconnect(),t.current&&(t.current=!1,e?.invalidateQueries({queryKey:[`ncp-sessions`]}))}),r=Xe.eventBus.on(Re.connectionClose,()=>{vt.handleConnectionInterrupted(null),t.current=!0}),i=Xe.eventBus.on(Re.connectionError,e=>{vt.handleConnectionInterrupted(e?.message??null),t.current=!0}),a=Xe.eventBus.on(Re.configUpdated,({path:t})=>{wB(e,t)}),o=Xe.eventBus.on(Re.runtimeUpdateSnapshot,e=>{at.reportSnapshot(e)}),s=Xe.eventBus.on(Re.sessionRunStatus,t=>{Ze(e,{type:`session.run-status`,payload:t})}),c=Xe.eventBus.on(Re.sessionSummaryUpsert,t=>{Ze(e,{type:`session.summary.upsert`,payload:t})}),l=Xe.eventBus.on(Re.sessionSummaryDelete,t=>{Ze(e,{type:`session.summary.delete`,payload:t})}),u=Xe.eventBus.on(Re.error,e=>{console.error(`Realtime transport error:`,e.message)});return()=>{n(),r(),i(),a(),o(),s(),c(),l(),u()}},[e])}var EB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{ModelConfig:e}=await import(`./model-config-JUsW1Khb.js`);return{ModelConfig:e}},__vite__mapDeps([12,2,13,14,3,15,16,11,17]))).ModelConfig})),DB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{ChatPage:e}=await import(`./chat-page-D1X8YNTC.js`);return{ChatPage:e}},__vite__mapDeps([18,2,19,3,20,21,5,13,10,22,4,6,14,23,8,24,25,11,26,27,28,29,30,15,16,31,32,33]))).ChatPage})),OB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{SearchConfig:e}=await import(`./search-config-CJ6OPxAf.js`);return{SearchConfig:e}},__vite__mapDeps([34,2,13,7,3,23,9,35,6]))).SearchConfig})),kB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{ProvidersList:e}=await import(`./providers-list-BsDpxNzy.js`);return{ProvidersList:e}},__vite__mapDeps([36,2,3,20,21,5,13,10,22,31,23,8,9,25,35,6,27,17,16]))).ProvidersList})),AB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{ChannelsList:e}=await import(`./channels-list-page-D-WYFmcG.js`);return{ChannelsList:e}},__vite__mapDeps([37,2,3,13,14,7,23,9,10,35,6,27,33,28,30,17]))).ChannelsList})),jB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{RuntimeConfig:e}=await import(`./runtime-config-page-DzbTVebD.js`);return{RuntimeConfig:e}},__vite__mapDeps([38,2,13,14,3,32,8,39,40,25,26]))).RuntimeConfig})),MB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{DesktopUpdateConfig:e}=await import(`./desktop-update-config-DOi5R1fX.js`);return{DesktopUpdateConfig:e}},__vite__mapDeps([41,2,13,7,3,24,39]))).DesktopUpdateConfig})),NB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{SecurityConfig:e}=await import(`./api-DmxQnm30.js`).then(e=>e.ut);return{SecurityConfig:e}},__vite__mapDeps([13,2]))).SecurityConfig})),PB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{SecretsConfig:e}=await import(`./secrets-config-CYOHWL7P.js`);return{SecretsConfig:e}},__vite__mapDeps([42,2,13,8,3,40,25]))).SecretsConfig})),FB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{RemoteAccessPage:e}=await import(`./remote-DjhVMpVd.js`);return{RemoteAccessPage:e}},__vite__mapDeps([43,19,2,3,20,21,5,13,10,22,4,6,14,23,8,24,25,11,26,27,28]))).RemoteAccessPage})),IB=(0,F.lazy)(async()=>({default:(await ue(async()=>{let{McpMarketplacePage:e}=await import(`./mcp-marketplace-page-LmMhKH5a.js`);return{McpMarketplacePage:e}},__vite__mapDeps([44,29,2,3,20,21,5,13,10,11,26,30]))).McpMarketplacePage}));function LB(){return(0,I.jsx)(`div`,{className:`h-full w-full animate-pulse rounded-2xl border border-border/40 bg-card/40`})}function RB({children:e}){return(0,I.jsx)(F.Suspense,{fallback:(0,I.jsx)(LB,{}),children:e})}function zB(e){return(0,I.jsx)(RB,{children:e})}var BB=[{path:`/chat/skills`,redirectTo:`/skills`},{path:`/chat/cron`,redirectTo:`/cron`},{path:`/chat/agents`,redirectTo:`/agents`},{path:`/chat/:sessionId?`,element:zB((0,I.jsx)(DB,{view:`chat`}))},{path:`/agents`,element:zB((0,I.jsx)(DB,{view:`agents`}))},{path:`/skills`,element:zB((0,I.jsx)(DB,{view:`skills`}))},{path:`/skills/scenes/:scene`,element:zB((0,I.jsx)(DB,{view:`skills`}))},{path:`/cron`,element:zB((0,I.jsx)(DB,{view:`cron`}))},{path:`/model`,element:zB((0,I.jsx)(EB,{}))},{path:`/search`,element:zB((0,I.jsx)(OB,{}))},{path:`/providers`,element:zB((0,I.jsx)(kB,{}))},{path:`/channels`,element:zB((0,I.jsx)(AB,{}))},{path:`/runtime`,element:zB((0,I.jsx)(jB,{}))},{path:`/updates`,element:zB((0,I.jsx)(MB,{}))},{path:`/remote`,element:zB((0,I.jsx)(FB,{}))},{path:`/security`,element:zB((0,I.jsx)(NB,{}))},{path:`/secrets`,element:zB((0,I.jsx)(PB,{}))},{path:`/language`,element:(0,I.jsx)(ns,{})},{path:`/settings`,element:(0,I.jsx)(xB,{})},{path:`/marketplace/skills`,redirectTo:`/skills`},{path:`/marketplace`,redirectTo:`/skills`},{path:`/marketplace/mcp`,element:zB((0,I.jsx)(IB,{}))},{path:`/`,redirectTo:`/chat`},{path:`*`,redirectTo:`/chat`}];function VB(e){return`redirectTo`in e?(0,I.jsx)(D,{path:e.path,element:(0,I.jsx)(T,{to:e.redirectTo,replace:!0})},e.path):(0,I.jsx)(D,{path:e.path,element:e.element},e.path)}function HB(){return(0,I.jsx)(x,{children:BB.map(VB)})}function UB(){return TB(De),Ye(),(0,F.useEffect)(()=>(at.start(),()=>{at.stop()}),[]),(0,I.jsxs)(se,{children:[(0,I.jsx)(bB,{children:(0,I.jsx)(HB,{})}),(0,I.jsx)(ce,{}),(0,I.jsx)(ee,{})]})}function WB(){let e=tt(),t=e.isError&&Qe(e.error);return e.isLoading&&!e.isError||t||e.isError?(0,I.jsx)(UB,{}):e.data?.enabled&&!e.data.authenticated?(0,I.jsx)(ne,{username:e.data.username}):(0,I.jsx)(UB,{})}function GB(){return(0,F.useEffect)(()=>{Yo()},[]),(0,I.jsxs)(Ke,{client:De,children:[(0,I.jsx)(WB,{}),(0,I.jsx)(Ko,{}),(0,I.jsx)(Le,{position:`top-right`,richColors:!0,offset:window.nextclawDesktop?.platform===`win32`?56:void 0,mobileOffset:window.nextclawDesktop?.platform===`win32`?56:void 0})]})}var KB=window.nextclawDesktop?.platform===`win32`?te:M;(0,Tr.createRoot)(document.getElementById(`root`)).render((0,I.jsx)(F.StrictMode,{children:(0,I.jsx)($o,{children:(0,I.jsx)(Or,{children:(0,I.jsx)(KB,{children:(0,I.jsx)(GB,{})})})})}));export{li as $,xI as A,lr as At,Us as B,jn as Bt,aL as C,Pr as Ct,$I as D,_r as Dt,rL as E,br as Et,eP as F,Hn as Ft,Go as G,Vs as H,Z as I,Rn as It,To as J,vo as K,cN as L,Ln as Lt,kP as M,or as Mt,aP as N,ir as Nt,QI as O,hr as Ot,sP as P,Un as Pt,oi as Q,rc as R,In as Rt,IL as S,Fr as St,oL as T,xr as Tt,Ns as U,Xs as V,bs as W,yo as X,bo as Y,ii as Z,_R as _,fi as _t,Qz as a,vi as at,NL as b,xi as bt,Mz as c,_i as ct,WR as d,Oi as dt,pi as et,GR as f,gi as ft,pR as g,ui as gt,FR as h,yi as ht,uB as i,Si as it,wP as j,sr as jt,SI as k,dr as kt,uz as l,ci as lt,LR as m,Di as mt,oB as n,Ei as nt,Uz as o,wi as ot,IR as p,hi as pt,Co as q,lB as r,mi as rt,Nz as s,Ci as st,dB as t,Ti as tt,ez as u,si as ut,FL as v,bi as vt,sL as w,kr as wt,PL as x,Ir as xt,ML as y,di as yt,ic as z,Pn as zt};
|