@bigduu/lotus-next 2026.9.12
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/README.md +113 -0
- package/dist/asset-manifest.json +303 -0
- package/dist/assets/CodeBlock-dYUQ9iue.js +2 -0
- package/dist/assets/ErrorBoundary-DLCRl4Er.js +1 -0
- package/dist/assets/Markdown-DBG0vWxL.js +2 -0
- package/dist/assets/MermaidChart-U1Z5JCRh.js +1 -0
- package/dist/assets/Root-dWsRRTlH.js +7 -0
- package/dist/assets/Settings-BcsRaEDP.js +7 -0
- package/dist/assets/StreamdownMarkdown-CiLy0KJD.js +2 -0
- package/dist/assets/StreamdownMermaid-J7jSRtO6.js +1 -0
- package/dist/assets/bundle-mjs-B_AA55HL.js +1 -0
- package/dist/assets/defineProperty-o0OkIQd4.js +1 -0
- package/dist/assets/en-US-DOXBXLLy.js +3 -0
- package/dist/assets/html2canvas-ChX2ETZ3.js +1 -0
- package/dist/assets/index-CjY6eMv8.js +2 -0
- package/dist/assets/index-xUf4TnkE.css +2 -0
- package/dist/assets/index.es-BpPlqG76.js +5 -0
- package/dist/assets/lib-CFLxRXs3.js +1 -0
- package/dist/assets/renderPdf-DbvJnEQL.js +111 -0
- package/dist/assets/rolldown-runtime-QTnfLwEv.js +1 -0
- package/dist/assets/select-DYBAIyVx.js +131 -0
- package/dist/assets/strictConfig-Bf8nyKvx.js +1 -0
- package/dist/assets/unsupportedIterableToArray-BTCP7Haa.js +1 -0
- package/dist/assets/vendor-highlighter-ClvlgmIK.js +8 -0
- package/dist/assets/vendor-markdown-CfSBref-.js +30 -0
- package/dist/assets/vendor-mermaid-Da_wWrs4.js +3535 -0
- package/dist/assets/vendor-react-CCIEwYL0.js +9 -0
- package/dist/assets/vendor-streamdown-BIRX7zKm.js +113 -0
- package/dist/assets/vendor-streamdown-CXvuy5h3.css +1 -0
- package/dist/assets/vendor-streamdown-code-B6SuuZwa.js +152 -0
- package/dist/assets/zh-CN-C4xbZjjC.js +3 -0
- package/dist/bundle-ownership.json +597 -0
- package/dist/favicon.svg +1 -0
- package/dist/icons.svg +24 -0
- package/dist/index.html +27 -0
- package/dist/lotus-next-manifest.json +181 -0
- package/package.json +94 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./Settings-BcsRaEDP.js","./rolldown-runtime-QTnfLwEv.js","./vendor-react-CCIEwYL0.js","./index-CjY6eMv8.js","./index-xUf4TnkE.css","./ErrorBoundary-DLCRl4Er.js","./bundle-mjs-B_AA55HL.js","./select-DYBAIyVx.js","./renderPdf-DbvJnEQL.js","./vendor-mermaid-Da_wWrs4.js","./vendor-markdown-CfSBref-.js","./lib-CFLxRXs3.js","./unsupportedIterableToArray-BTCP7Haa.js","./strictConfig-Bf8nyKvx.js","./StreamdownMarkdown-CiLy0KJD.js","./vendor-streamdown-BIRX7zKm.js","./vendor-streamdown-CXvuy5h3.css","./Markdown-DBG0vWxL.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{i as t,t as n}from"./vendor-react-CCIEwYL0.js";import{n as r,t as i}from"./index-CjY6eMv8.js";import{c as a,d as o,f as s,i as c,l,r as u,s as d,t as f,u as p}from"./ErrorBoundary-DLCRl4Er.js";import{$ as m,$t as h,At as g,B as _,Bt as v,C as y,Ct as b,F as x,Ft as S,G as C,Gt as w,H as T,Ht as E,I as D,It as O,J as ee,Jt as k,K as te,Kt as A,L as j,M,Mt as N,N as P,Nt as F,P as I,Pt as L,Q as R,Qt as ne,R as re,Rt as ie,St as ae,T as oe,U as z,Ut as se,V as ce,Vt as B,W as le,Wt as V,X as H,Xt as ue,Y as U,Yt as W,Z as G,Zt as de,_ as fe,a as pe,at as me,b as he,bt as ge,c as _e,ct as ve,d as ye,et as be,f as xe,ft as Se,g as Ce,i as we,it as Te,j as Ee,jt as De,kt as K,l as Oe,lt as ke,m as Ae,n as je,nt as Me,ot as Ne,p as Pe,q as Fe,qt as Ie,r as Le,rt as q,s as Re,st as J,t as ze,tt as Y,u as X,ut as Be,vt as Ve,wt as He,xt as Ue,y as We,z as Ge}from"./select-DYBAIyVx.js";var Ke=s(`chart-column`,[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M18 17V9`,key:`2bz60n`}],[`path`,{d:`M13 17V5`,key:`1frdt8`}],[`path`,{d:`M8 17v-3`,key:`17ska0`}]]),Z=s(`circle-question-mark`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),qe=s(`columns-2`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M12 3v18`,key:`108xh3`}]]),Je=s(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),Ye=s(`panel-left-close`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m16 15-3-3 3-3`,key:`14y99z`}]]),Xe=s(`sparkles`,[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]]),Ze=s(`text-wrap`,[[`path`,{d:`m16 16-3 3 3 3`,key:`117b85`}],[`path`,{d:`M3 12h14.5a1 1 0 0 1 0 7H13`,key:`18xa6z`}],[`path`,{d:`M3 19h6`,key:`1ygdsz`}],[`path`,{d:`M3 5h18`,key:`1u36vt`}]]),Qe=s(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),$e=s(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),et=s(`book-text`,[[`path`,{d:`M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20`,key:`k3hazp`}],[`path`,{d:`M8 11h8`,key:`vwpz6n`}],[`path`,{d:`M8 7h6`,key:`1f0q6e`}]]),tt=s(`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`}]]),nt=s(`brain`,[[`path`,{d:`M12 18V5`,key:`adv99a`}],[`path`,{d:`M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4`,key:`1e3is1`}],[`path`,{d:`M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5`,key:`1gqd8o`}],[`path`,{d:`M17.997 5.125a4 4 0 0 1 2.526 5.77`,key:`iwvgf7`}],[`path`,{d:`M18 18a4 4 0 0 0 2-7.464`,key:`efp6ie`}],[`path`,{d:`M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517`,key:`1gq6am`}],[`path`,{d:`M6 18a4 4 0 0 1-2-7.464`,key:`k1g0md`}],[`path`,{d:`M6.003 5.125a4 4 0 0 0-2.526 5.77`,key:`q97ue3`}]]),rt=s(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),it=s(`clock-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6h4`,key:`135r8i`}]]),at=s(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]),ot=s(`code`,[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]),st=s(`cog`,[[`path`,{d:`M11 10.27 7 3.34`,key:`16pf9h`}],[`path`,{d:`m11 13.73-4 6.93`,key:`794ttg`}],[`path`,{d:`M12 22v-2`,key:`1osdcq`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M14 12h8`,key:`4f43i9`}],[`path`,{d:`m17 20.66-1-1.73`,key:`eq3orb`}],[`path`,{d:`m17 3.34-1 1.73`,key:`2wel8s`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`m20.66 17-1.73-1`,key:`sg0v6f`}],[`path`,{d:`m20.66 7-1.73 1`,key:`1ow05n`}],[`path`,{d:`m3.34 17 1.73-1`,key:`nuk764`}],[`path`,{d:`m3.34 7 1.73 1`,key:`1ulond`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}],[`circle`,{cx:`12`,cy:`12`,r:`8`,key:`46899m`}]]),ct=s(`container`,[[`path`,{d:`M22 7.7c0-.6-.4-1.2-.8-1.5l-6.3-3.9a1.72 1.72 0 0 0-1.7 0l-10.3 6c-.5.2-.9.8-.9 1.4v6.6c0 .5.4 1.2.8 1.5l6.3 3.9a1.72 1.72 0 0 0 1.7 0l10.3-6c.5-.3.9-1 .9-1.5Z`,key:`1t2lqe`}],[`path`,{d:`M10 21.9V14L2.1 9.1`,key:`o7czzq`}],[`path`,{d:`m10 14 11.9-6.9`,key:`zm5e20`}],[`path`,{d:`M14 19.8v-8.1`,key:`159ecu`}],[`path`,{d:`M18 17.5V9.4`,key:`11uown`}]]),lt=s(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),ut=s(`file-diff`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M9 10h6`,key:`9gxzsh`}],[`path`,{d:`M12 13V7`,key:`h0r20n`}],[`path`,{d:`M9 17h6`,key:`r8uit2`}]]),dt=s(`file-down`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 18v-6`,key:`17g6i2`}],[`path`,{d:`m9 15 3 3 3-3`,key:`1npd3o`}]]),ft=s(`file-search`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`circle`,{cx:`11.5`,cy:`14.5`,r:`2.5`,key:`1bq0ko`}],[`path`,{d:`M13.3 16.3 15 18`,key:`2quom7`}]]),pt=s(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),mt=s(`folder-git-2`,[[`path`,{d:`M18 19a5 5 0 0 1-5-5v8`,key:`sz5oeg`}],[`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`}],[`circle`,{cx:`20`,cy:`19`,r:`2`,key:`1obnsp`}]]),ht=s(`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`}]]),gt=s(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),_t=s(`git-compare`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M13 6h3a2 2 0 0 1 2 2v7`,key:`1yeb86`}],[`path`,{d:`M11 18H8a2 2 0 0 1-2-2V9`,key:`19pyzm`}]]),vt=s(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),yt=s(`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`}]]),bt=s(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),xt=s(`message-square`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}]]),St=s(`network`,[[`rect`,{x:`16`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`4q2zg0`}],[`rect`,{x:`2`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`8cvhb9`}],[`rect`,{x:`9`,y:`2`,width:`6`,height:`6`,rx:`1`,key:`1egb70`}],[`path`,{d:`M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3`,key:`1jsf9p`}],[`path`,{d:`M12 12V8`,key:`2874zd`}]]),Ct=s(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),wt=s(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),Tt=s(`pin-off`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89`,key:`znwnzq`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11`,key:`c9qhm2`}]]),Et=s(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]),Dt=s(`settings`,[[`path`,{d:`M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915`,key:`1i5ecw`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),Ot=s(`shield-alert`,[[`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`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),kt=s(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),At=s(`wifi-off`,[[`path`,{d:`M12 20h.01`,key:`zekei9`}],[`path`,{d:`M8.5 16.429a5 5 0 0 1 7 0`,key:`1bycff`}],[`path`,{d:`M5 12.859a10 10 0 0 1 5.17-2.69`,key:`1dl1wf`}],[`path`,{d:`M19 12.859a10 10 0 0 0-2.007-1.523`,key:`4k23kn`}],[`path`,{d:`M2 8.82a15 15 0 0 1 4.177-2.643`,key:`1grhjp`}],[`path`,{d:`M22 8.82a15 15 0 0 0-11.288-3.764`,key:`z3jwby`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),jt=s(`wrench`,[[`path`,{d:`M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z`,key:`1ngwbx`}]]),Q=e(t(),1),Mt=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Nt=e=>typeof e==`string`?e:void 0,Pt=e=>typeof e==`number`&&Number.isFinite(e)?e:void 0,Ft=e=>typeof e==`boolean`?e:void 0,It=e=>{if(!e)return null;let t=e.trim();if(!t.startsWith(`{`)||!t.endsWith(`}`))return null;try{let e=JSON.parse(t);if(!Mt(e))return null;let n=Nt(e.file_path),r=Nt(e.operation),i=e.diff;if(!n||!r||!Mt(i))return null;let a=Nt(i.unified);if(!a)return null;let o=e.checkpoint,s=Mt(o)?{created:Ft(o.created)??!1,id:Nt(o.id),path:Nt(o.path),size_bytes:Pt(o.size_bytes),reason:Nt(o.reason)}:void 0;return{operation:r,message:Nt(e.message),file_path:n,workspace:Nt(e.workspace),checkpoint:s,diff:{unified:a,old_line_count:Pt(i.old_line_count),new_line_count:Pt(i.new_line_count),added_lines:Pt(i.added_lines),removed_lines:Pt(i.removed_lines),truncated:Ft(i.truncated)}}}catch{return null}},Lt=e=>e.startsWith(`-`)&&!e.startsWith(`---`),Rt=e=>e.startsWith(`+`)&&!e.startsWith(`+++`),zt=e=>{let t=e.split(`
|
|
3
|
+
`),n=[],r=0;for(;r<t.length;){let e=t[r]??``;if(e.startsWith(`--- `)||e.startsWith(`+++ `)){n.push({kind:`meta`,text:e}),r+=1;continue}if(e.startsWith(`@@`)){n.push({kind:`hunk`,text:e}),r+=1;continue}if(Lt(e)){let e=[];for(;r<t.length&&Lt(t[r]??``);)e.push(t[r]??``),r+=1;let i=[];for(;r<t.length&&Rt(t[r]??``);)i.push(t[r]??``),r+=1;i.length>0?(e.forEach(e=>n.push({kind:`modified_remove`,text:e})),i.forEach(e=>n.push({kind:`modified_add`,text:e}))):e.forEach(e=>n.push({kind:`remove`,text:e}));continue}if(Rt(e)){n.push({kind:`add`,text:e}),r+=1;continue}n.push({kind:`context`,text:e}),r+=1}return n},Bt=e=>{let t=e.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);return t?{oldStart:Number.parseInt(t[1],10),newStart:Number.parseInt(t[2],10)}:null},Vt=e=>{if(!e)return``;let t=e[0];return t===`+`||t===`-`||t===` `?e.slice(1):e},Ht=e=>e==null?null:e+1,Ut=e=>{let t=e.split(`
|
|
4
|
+
`),n=[],r=null,i=null,a=0;for(;a<t.length;){let e=t[a]??``;if(e.startsWith(`--- `)||e.startsWith(`+++ `)){n.push({kind:`meta`,text:e}),a+=1;continue}if(e.startsWith(`@@`)){let t=Bt(e);t&&(r=t.oldStart,i=t.newStart),n.push({kind:`hunk`,text:e}),a+=1;continue}if(Lt(e)){let e=[];for(;a<t.length&&Lt(t[a]??``);)e.push(t[a]??``),a+=1;let o=[];for(;a<t.length&&Rt(t[a]??``);)o.push(t[a]??``),a+=1;if(o.length>0){let t=Math.max(e.length,o.length);for(let a=0;a<t;a+=1){let t=e[a],s=o[a];if(t&&s){n.push({kind:`modified`,oldLineNumber:r??void 0,newLineNumber:i??void 0,oldText:Vt(t),newText:Vt(s)}),r=Ht(r),i=Ht(i);continue}if(t){n.push({kind:`remove`,oldLineNumber:r??void 0,oldText:Vt(t)}),r=Ht(r);continue}s&&(n.push({kind:`add`,newLineNumber:i??void 0,newText:Vt(s)}),i=Ht(i))}}else e.forEach(e=>{n.push({kind:`remove`,oldLineNumber:r??void 0,oldText:Vt(e)}),r=Ht(r)});continue}if(Rt(e)){n.push({kind:`add`,newLineNumber:i??void 0,newText:Vt(e)}),i=Ht(i),a+=1;continue}let o=Vt(e);n.push({kind:`context`,oldLineNumber:r??void 0,newLineNumber:i??void 0,oldText:o,newText:o}),r=Ht(r),i=Ht(i),a+=1}return n},Wt=e=>{let t=0,n=0;for(let r of e.split(`
|
|
5
|
+
`)){if(Rt(r)){t+=1;continue}Lt(r)&&(n+=1)}return{added:t,removed:n}};function Gt(e){let[t,n]=(0,Q.useState)(()=>typeof window<`u`?window.matchMedia(e).matches:!1);return(0,Q.useEffect)(()=>{if(typeof window>`u`)return;let t=window.matchMedia(e);n(t.matches);let r=e=>{n(e.matches)};return t.addEventListener?t.addEventListener(`change`,r):t.addListener(r),()=>{t.removeEventListener?t.removeEventListener(`change`,r):t.removeListener(r)}},[e]),t}function Kt(){return Gt(`(min-width: 1280px)`)}var $=n(),qt={add:`bg-green-500/10 text-green-700 dark:text-green-400`,modified_add:`bg-green-500/10 text-green-700 dark:text-green-400`,remove:`bg-red-500/10 text-red-700 dark:text-red-400`,modified_remove:`bg-red-500/10 text-red-700 dark:text-red-400`,hunk:`bg-muted/70 text-muted-foreground`,meta:`text-muted-foreground`,gap:`text-muted-foreground/50`},Jt={add:`bg-green-500/10 text-green-700 dark:text-green-400`,remove:`bg-red-500/10 text-red-700 dark:text-red-400`};function Yt({payload:e}){let t=Kt(),[n,r]=(0,Q.useState)(!1),i=e.diff?.unified??``,a=(0,Q.useMemo)(()=>{let t=e.diff?.added_lines,n=e.diff?.removed_lines;return typeof t==`number`&&typeof n==`number`?{added:t,removed:n}:Wt(i)},[e.diff,i]),o=(0,Q.useMemo)(()=>zt(i),[i]),s=(0,Q.useMemo)(()=>n&&t?Ut(i):[],[n,t,i]);if(!i.trim())return null;let l=e.file_path?.split(`/`).filter(Boolean).pop()||e.file_path;return(0,$.jsxs)(`div`,{className:`overflow-hidden rounded-md border bg-background/60`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b bg-muted/40 px-2.5 py-1.5`,children:[(0,$.jsx)(ut,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[11px]`,title:e.file_path,children:l}),(0,$.jsxs)(`span`,{className:`shrink-0 text-[11px]`,children:[(0,$.jsxs)(`span`,{className:`text-green-600 dark:text-green-400`,children:[`+`,a.added]}),` `,(0,$.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`−`,a.removed]})]}),e.diff?.truncated?(0,$.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1 text-[10px] text-muted-foreground`,children:`已截断`}):null,t?(0,$.jsx)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`shrink-0 rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground`,title:n?`统一视图`:`对照视图`,"aria-label":n?`统一视图`:`对照视图`,children:n?(0,$.jsx)(Ze,{className:`size-3.5`}):(0,$.jsx)(qe,{className:`size-3.5`})}):null]}),n&&t?(0,$.jsx)(`div`,{className:`max-h-72 overflow-auto font-mono text-[11px] leading-relaxed`,children:(0,$.jsx)(`table`,{className:`w-full border-collapse`,children:(0,$.jsx)(`tbody`,{children:s.map((e,t)=>{if(e.kind===`meta`||e.kind===`hunk`)return(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:4,className:c(`px-2 py-0.5`,qt[e.kind]),children:e.text})},t);let n=e.kind===`remove`||e.kind===`modified`?Jt.remove:void 0,r=e.kind===`add`||e.kind===`modified`?Jt.add:void 0;return(0,$.jsxs)(`tr`,{className:`align-top`,children:[(0,$.jsx)(`td`,{className:`w-8 select-none border-r px-1 text-right text-muted-foreground/60`,children:e.oldLineNumber??``}),(0,$.jsx)(`td`,{className:c(`w-1/2 whitespace-pre-wrap break-all px-2`,n),children:e.kind===`add`?``:e.oldText??e.text??``}),(0,$.jsx)(`td`,{className:`w-8 select-none border-x px-1 text-right text-muted-foreground/60`,children:e.newLineNumber??``}),(0,$.jsx)(`td`,{className:c(`w-1/2 whitespace-pre-wrap break-all px-2`,r),children:e.kind===`remove`?``:e.newText??e.text??``})]},t)})})})}):(0,$.jsx)(`pre`,{className:`max-h-72 overflow-auto text-[11px] leading-relaxed`,children:o.map((e,t)=>(0,$.jsx)(`div`,{className:c(`whitespace-pre-wrap break-all px-2.5`,qt[e.kind]),children:e.text||` `},t))})]})}function Xt({sessionId:e,goldConfig:t,goalState:n}){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1),[l,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(``),g=t?.goal,_=(t?.recovery?.max_attempts??0)>0?t.recovery:{max_attempts:3,max_elapsed_seconds:900};return(0,$.jsxs)(`section`,{className:`rounded-lg border p-3`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:`目标`}),r?null:(0,$.jsx)(`button`,{onClick:()=>{o(g??``),c(t?.auto_continue_enabled??!1),d((t?.recovery?.max_attempts??0)>0),h(``),i(!0)},className:`text-xs text-primary hover:underline`,children:g?`编辑`:`设置`})]}),(0,$.jsxs)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:[`聊天指令:`,(0,$.jsx)(`code`,{children:`/goal 目标内容`}),` 设置并推进,`,(0,$.jsx)(`code`,{children:`/goal off`}),` 暂停,`,(0,$.jsx)(`code`,{children:`/goal clear`}),` 清除。`]}),r?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`textarea`,{value:a,onChange:e=>o(e.target.value),autoFocus:!0,placeholder:`描述这段会话要达成的目标…`,className:`min-h-16 w-full resize-y rounded-md border bg-background px-2.5 py-1.5 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring`}),(0,$.jsxs)(`label`,{className:`mt-2 flex items-center gap-2 text-xs`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),`自动继续推进目标`]}),(0,$.jsxs)(`label`,{className:`mt-2 flex items-center gap-2 text-xs`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:l,disabled:!s,onChange:e=>d(e.target.checked)}),`无输出超时后尝试恢复`]}),s&&l&&(0,$.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[`每个目标额外尝试最多 `,Math.min(_.max_attempts,10),` 次,恢复窗口 `,Math.min(_.max_elapsed_seconds,3600)/60,` 分钟。停止操作会结束等待。`]}),m&&(0,$.jsx)(`p`,{role:`alert`,className:`mt-1 text-xs text-destructive`,children:m}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex justify-end gap-2`,children:[(0,$.jsx)(u,{size:`sm`,variant:`secondary`,disabled:f,onClick:()=>i(!1),children:`取消`}),(0,$.jsx)(u,{size:`sm`,disabled:f,onClick:async()=>{if(f)return;let n=a.trim();p(!0),h(``);try{await K.patchSession(e,{gold_config:{...t??{enabled:!0},enabled:!0,goal:n||null,auto_continue_enabled:s,recovery:l&&s?_:{max_attempts:0,max_elapsed_seconds:0}}}),i(!1),await J.getState().loadChatHistory(e)}catch{h(`保存目标失败,请重试。`)}finally{p(!1)}},children:`保存`})]})]}):g?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`text-sm leading-relaxed`,children:g}),n?.status?(0,$.jsxs)(`div`,{className:`mt-1.5 text-xs text-muted-foreground`,children:[`状态:`,n.status]}):null]}):(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:`未设置目标。设置后,agent 会朝目标推进并自检是否达成。`})]})}var Zt={pending:{icon:`○`,cls:`text-muted-foreground`},in_progress:{icon:`◐`,cls:`text-primary`},completed:{icon:`✓`,cls:`text-emerald-500`},skipped:{icon:`–`,cls:`text-muted-foreground`},failed:{icon:`✗`,cls:`text-destructive`}};function Qt({label:e,value:t}){return(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 py-0.5 text-sm`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,$.jsx)(`span`,{className:`truncate font-medium`,children:t})]})}function $t({sessionId:e,open:t,onClose:n,workspace:r,onEditWorkspace:i,docked:a=!1,width:o}){let s=J(me),l=J(t=>e?t.taskLists[e]:void 0),d=J(t=>e?t.evaluationStates[e]:void 0),f=J(e=>e.loadTaskList),p=J(v(t=>e?Ne(e)(t)?.messages??[]:[])),m=(0,Q.useMemo)(()=>{let e=[];for(let t of p){if(t.type!==`tool_result`)continue;let n=t.result?.result;if(typeof n!=`string`)continue;let r=It(n);r&&e.push({id:t.id,payload:r})}return e},[p]),h=He(e=>e.getProviderDisplayLabel),g=J(v(t=>e?ke(e)(t):{}));if((0,Q.useEffect)(()=>{t&&e&&f(e)},[t,e,f]),!t)return null;let _=s?.config,y=_?.model_ref?.model||_?.model||`—`,b=_?.model_ref?.provider,x=b?h(b):null,S=_?.goalState,C=_?.tokenUsage,w=Object.entries(g??{}),T=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b px-4 py-3`,children:[(0,$.jsx)(`span`,{className:`text-sm font-semibold`,children:`检查器`}),(0,$.jsx)(u,{size:`icon`,variant:`ghost`,onClick:n,children:(0,$.jsx)(B,{})})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto p-4`,children:[(0,$.jsxs)(`section`,{className:`rounded-lg border p-3`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:`工作目录`}),i?(0,$.jsx)(`button`,{onClick:i,className:`text-xs text-primary hover:underline`,children:e?`更改`:`选择`}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(mt,{className:`size-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs`,title:r||void 0,children:r||`默认目录`})]}),e?(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] text-muted-foreground`,children:`会话创建时设定;更改用于新建会话与 @ 文件引用。`}):null]}),e?(0,$.jsx)(Xt,{sessionId:e,goldConfig:_?.goldConfig,goalState:S},e):null,(0,$.jsxs)(`section`,{className:`rounded-lg border p-3`,children:[(0,$.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted-foreground`,children:`任务清单`}),d?.isEvaluating?(0,$.jsxs)(`p`,{className:`mb-2 flex items-center gap-1.5 text-xs text-primary`,children:[(0,$.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-primary`}),`正在评估任务进度…`]}):d?.reasoning?(0,$.jsx)(`p`,{className:`mb-2 rounded bg-muted/60 px-2 py-1.5 text-[11px] leading-relaxed text-muted-foreground`,children:d.reasoning}):null,!l||l.items.length===0?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`暂无任务`}):(0,$.jsx)(`ul`,{className:`space-y-1.5`,children:l.items.map(e=>{let t=Zt[e.status]??Zt.pending;return(0,$.jsxs)(`li`,{className:`flex gap-2 text-sm`,children:[(0,$.jsx)(`span`,{className:c(`mt-0.5 shrink-0`,t.cls),children:t.icon}),(0,$.jsx)(`span`,{className:c(`leading-relaxed`,e.status===`completed`&&`text-muted-foreground line-through`),children:e.description})]},e.id)})})]}),m.length>0?(0,$.jsxs)(`section`,{className:`rounded-lg border p-3`,children:[(0,$.jsxs)(`div`,{className:`mb-2 text-xs font-medium text-muted-foreground`,children:[`文件变更 (`,m.length,`)`]}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:m.map(({id:e,payload:t})=>(0,$.jsxs)(`details`,{children:[(0,$.jsxs)(`summary`,{className:`flex cursor-pointer select-none items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-accent [&::-webkit-details-marker]:hidden`,children:[(0,$.jsx)(ut,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono`,title:t.file_path,children:t.file_path?.split(`/`).filter(Boolean).pop()||t.file_path}),(0,$.jsxs)(`span`,{className:`shrink-0 text-[11px]`,children:[(0,$.jsxs)(`span`,{className:`text-green-600 dark:text-green-400`,children:[`+`,t.diff?.added_lines??0]}),` `,(0,$.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`−`,t.diff?.removed_lines??0]})]})]}),(0,$.jsx)(`div`,{className:`mt-1`,children:(0,$.jsx)(Yt,{payload:t})})]},e))})]}):null,w.length>0?(0,$.jsxs)(`section`,{className:`rounded-lg border p-3`,children:[(0,$.jsxs)(`div`,{className:`mb-2 text-xs font-medium text-muted-foreground`,children:[`子代理 (`,w.length,`)`]}),(0,$.jsx)(`ul`,{className:`space-y-2`,children:w.map(([e,t])=>(0,$.jsxs)(`li`,{className:`rounded-md bg-muted/50 px-2.5 py-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`truncate text-sm font-medium`,children:t.title||e.slice(0,8)}),(0,$.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:[t.status??`—`,typeof t.roundCount==`number`?` · ${t.roundCount}轮`:``]})]}),t.outputPreview?(0,$.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs text-muted-foreground`,children:t.outputPreview}):null]},e))})]}):null,(0,$.jsxs)(`details`,{className:`rounded-lg border p-3`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer select-none text-xs font-medium text-muted-foreground`,children:`高级信息`}),(0,$.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`mb-1 text-xs text-muted-foreground`,children:`配置`}),(0,$.jsx)(Qt,{label:`模型`,value:y}),x?(0,$.jsx)(Qt,{label:`提供方`,value:x}):null,_?.reasoningEffort?(0,$.jsx)(Qt,{label:`推理强度`,value:_.reasoningEffort}):null]}),C?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`mb-1 text-xs text-muted-foreground`,children:`上下文用量`}),(0,$.jsx)(Qt,{label:`总 tokens`,value:C.totalTokens.toLocaleString()}),C.maxContextTokens?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Qt,{label:`上下文窗口`,value:C.maxContextTokens.toLocaleString()}),(0,$.jsx)(`div`,{className:`mt-2 h-1.5 w-full overflow-hidden rounded-full bg-muted`,children:(0,$.jsx)(`div`,{className:`h-full rounded-full bg-primary`,style:{width:`${Math.min(100,Math.round(C.totalTokens/C.maxContextTokens*100))}%`}})})]}):null]}):null]})]})]})]});return a?(0,$.jsx)(`aside`,{className:`flex shrink-0 flex-col border-l bg-card`,style:{width:o??384,maxWidth:`38vw`},children:T}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{className:`fixed inset-0 z-40 bg-black/50`,"aria-label":`关闭检查器`,onClick:n}),(0,$.jsx)(`aside`,{className:c(`fixed z-50 flex flex-col bg-card`,`inset-x-0 bottom-0 max-h-[85vh] rounded-t-2xl border-t`,`md:inset-y-0 md:right-0 md:left-auto md:w-96 md:max-h-none md:rounded-none md:border-l md:border-t-0`),style:{paddingBottom:`env(safe-area-inset-bottom)`},children:T})]})}function en({open:e,onClose:t,chats:n,onSelect:r,onNewChat:i,onSettings:a}){let[o,s]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(0),d=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{e&&(s(``),u(0),requestAnimationFrame(()=>d.current?.focus()))},[e]);let f=(0,Q.useMemo)(()=>{let e=o.trim().toLowerCase(),t=[{kind:`action`,id:`new`,label:`新建对话`,icon:(0,$.jsx)(w,{className:`size-4`}),run:i},{kind:`action`,id:`settings`,label:`系统设置`,icon:(0,$.jsx)(Dt,{className:`size-4`}),run:a}],s=n.filter(t=>!e||(t.title||``).toLowerCase().includes(e)).slice(0,50).map(e=>({kind:`session`,id:e.id,label:e.title||`新会话`,run:()=>r(e.id)}));return[...e?t.filter(t=>t.label.toLowerCase().includes(e)):t,...s]},[o,n,i,a,r]);if((0,Q.useEffect)(()=>{u(e=>Math.min(e,Math.max(0,f.length-1)))},[f.length]),!e)return null;let p=e=>{e.run(),t()};return(0,$.jsx)(`div`,{className:`fixed inset-0 z-[130] flex items-start justify-center bg-black/50 p-4 pt-[12vh]`,onClick:t,children:(0,$.jsxs)(`div`,{className:`w-full max-w-lg overflow-hidden rounded-2xl border bg-popover shadow-2xl`,onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3`,children:[(0,$.jsx)(V,{className:`size-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`input`,{ref:d,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{if(e.key===`ArrowDown`)e.preventDefault(),u(e=>Math.min(e+1,f.length-1));else if(e.key===`ArrowUp`)e.preventDefault(),u(e=>Math.max(e-1,0));else if(e.key===`Enter`){e.preventDefault();let t=f[l];t&&p(t)}else e.key===`Escape`&&t()},placeholder:`搜索会话或操作…`,className:`w-full bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground`})]}),(0,$.jsx)(`div`,{className:`max-h-80 overflow-y-auto p-1`,children:f.length===0?(0,$.jsx)(`p`,{className:`px-3 py-6 text-center text-sm text-muted-foreground`,children:`无匹配`}):f.map((e,t)=>(0,$.jsxs)(`button`,{onMouseEnter:()=>u(t),onClick:()=>p(e),className:c(`flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-left text-sm transition-colors`,t===l?`bg-accent`:`hover:bg-accent/60`),children:[e.kind===`action`?e.icon:(0,$.jsx)(xt,{className:`size-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.label})]},`${e.kind}-${e.id}`))})]})})}function tn(){return(0,$.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`flex min-h-0 flex-1 items-center justify-center p-6 text-sm text-muted-foreground`,children:`正在加载设置…`})}function nn({onClose:e}){return(0,$.jsxs)(`div`,{role:`alert`,className:`flex min-h-0 flex-1 flex-col items-center justify-center p-6 text-center`,children:[(0,$.jsx)(`div`,{className:`text-base font-semibold`,children:`设置加载失败`}),(0,$.jsx)(`p`,{className:`mt-2 max-w-sm text-sm leading-relaxed text-muted-foreground`,children:`设置代码未能加载,聊天仍可继续使用。请返回聊天并刷新页面后重试。`}),(0,$.jsx)(u,{className:`mt-4`,onClick:e,children:`返回聊天`})]})}var rn=()=>i(()=>import(`./Settings-BcsRaEDP.js`),__vite__mapDeps([0,1,2,3,4,5,6,7]),import.meta.url);function an({open:e,onClose:t,loadSettings:n=rn}){let[r,i]=(0,Q.useState)(`general`),[a]=(0,Q.useState)(()=>(0,Q.lazy)(async()=>({default:(await n()).SettingsContent})));return e?(0,$.jsx)(P,{open:!0,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(I,{showCloseButton:!1,className:`h-[88dvh] p-0 sm:h-[80vh] sm:max-w-3xl`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b px-4 py-3`,children:[(0,$.jsx)(D,{children:`系统设置`}),(0,$.jsx)(u,{"aria-label":`关闭设置`,size:`icon`,variant:`ghost`,onClick:t,children:(0,$.jsx)(B,{})})]}),(0,$.jsx)(f,{name:`Settings`,fallback:(0,$.jsx)(nn,{onClose:t}),children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(tn,{}),children:(0,$.jsx)(a,{tab:r,onTabChange:i})})})]})}):null}var on=`bodhi_onboarded_v1`;function sn(){let[e,t]=(0,Q.useState)(()=>{try{return localStorage.getItem(on)===`1`}catch{return!0}});return e?null:(0,$.jsx)(P,{open:!0,children:(0,$.jsxs)(I,{dismissable:!1,showCloseButton:!1,className:`p-6 text-center sm:max-w-sm`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-3 size-12 rounded-2xl bg-primary`}),(0,$.jsx)(D,{className:`text-lg`,children:`欢迎使用 Bodhi`}),(0,$.jsxs)(`p`,{className:`mt-2 text-sm leading-relaxed text-muted-foreground`,children:[`移动优先的 AI 助手。左上角菜单切换会话,输入 `,(0,$.jsx)(`code`,{children:`/`}),` 选择技能,可粘贴或选择图片, 右上角「检查器」查看任务、配置与子代理。`]}),(0,$.jsx)(u,{className:`mt-5 w-full`,onClick:()=>{try{localStorage.setItem(on,`1`)}catch{}t(!0)},children:`开始使用`})]})})}var cn=new class{cache=null;options;constructor(e={}){this.options={maxRecentWorkspaces:e.maxRecentWorkspaces??10,cacheTimeoutMs:e.cacheTimeoutMs??300*1e3,requestTimeoutMs:e.requestTimeoutMs??1e4}}async validatePath(e){return N.post(`workspace/validate`,{path:e})}async getRecent(){if(this.isCacheValid())return this.cache.recentWorkspaces;try{let e=await N.get(`workspace/recent`,{signal:AbortSignal.timeout(this.options.requestTimeoutMs)});return this.cache={recentWorkspaces:e,timestamp:Date.now()},e}catch(e){if(console.error(`Failed to get recent workspaces:`,e),this.cache?.recentWorkspaces)return this.cache.recentWorkspaces;throw e}}async addRecent(e,t){await N.post(`workspace/recent`,{path:e,metadata:t}),this.invalidateCache()}async removeRecent(e){let t=(await this.getRecent()).filter(t=>t.path!==e);this.cache={recentWorkspaces:t,timestamp:Date.now()}}async clearRecent(){this.cache=null}async getPathSuggestions(){return N.get(`workspace/suggestions`)}async browseFolder(e){return N.post(`workspace/browse-folder`,{path:e})}async getCombinedSuggestions(){let[e,t]=await Promise.all([this.getPathSuggestions().catch(()=>({suggestions:[]})),this.getRecent().catch(()=>[])]),n=[...e.suggestions.map(e=>({path:e.path,is_valid:!0,workspace_name:e.name})),...t];return this.deduplicateByPath(n).sort((e,n)=>{let r=t.findIndex(t=>t.path===e.path),i=t.findIndex(e=>e.path===n.path);return r!==-1&&i!==-1?r-i:r===-1?i===-1?(e.workspace_name||``).localeCompare(n.workspace_name||``):1:-1})}async healthCheck(){let e=Date.now();try{await N.get(`workspace/recent`,{signal:AbortSignal.timeout(2e3)});let t=this.cache?.recentWorkspaces||await this.getRecent();return{available:!0,cacheValid:this.isCacheValid(),recentCount:t.length,latency:Date.now()-e}}catch(e){return{available:!1,cacheValid:this.isCacheValid(),recentCount:this.cache?.recentWorkspaces?.length||0,error:e instanceof Error?e.message:`Unknown error`}}}validateWorkspacePath=this.validatePath.bind(this);getRecentWorkspaces=this.getRecent.bind(this);addRecentWorkspace=this.addRecent.bind(this);removeRecentWorkspace=this.removeRecent.bind(this);clearRecentWorkspaces=this.clearRecent.bind(this);getWorkspaceSuggestions=this.getCombinedSuggestions.bind(this);getHealthStatus=this.healthCheck.bind(this);async listWorkspaceFiles(e,t){return N.post(`workspace/files`,{path:e,max_depth:t?.max_depth??3,max_entries:t?.max_entries??500,include_hidden:t?.include_hidden??!1})}isCacheValid(){return this.cache?!(Date.now()-this.cache.timestamp>this.options.cacheTimeoutMs):!1}invalidateCache(){this.cache=null}deduplicateByPath(e){let t=new Set;return e.filter(e=>t.has(e.path)?!1:(t.add(e.path),!0))}};function ln({open:e,current:t,locked:n,onClose:r,onSelect:i}){let[a,o]=(0,Q.useState)([]),[s,l]=(0,Q.useState)(!0),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)([]);if((0,Q.useEffect)(()=>{e&&(l(!0),cn.getCombinedSuggestions().then(o).catch(()=>{}).finally(()=>l(!1)))},[e]),(0,Q.useEffect)(()=>{if(!e||!d.startsWith(`/`)){v([]);return}let t=d.lastIndexOf(`/`),n=t<=0?`/`:d.slice(0,t),r=d.slice(t+1).toLowerCase(),i=setTimeout(()=>{cn.browseFolder(n).then(e=>v(e.folders.filter(e=>e.name.toLowerCase().startsWith(r)).slice(0,500))).catch(()=>v([]))},180);return()=>clearTimeout(i)},[e,d]),!e)return null;let y=e=>{i(e),r()},b=async()=>{let e=d.trim();if(e.length>1&&(e=e.replace(/\/+$/,``)),e){m(!0),g(null);try{let t=await cn.validatePath(e);t.is_valid?(await cn.addRecent(e).catch(()=>{}),y(e)):g(t.error_message||`路径无效`)}catch{g(`校验失败`)}finally{m(!1)}}};return(0,$.jsx)(P,{open:!0,onOpenChange:e=>{e||r()},children:(0,$.jsxs)(I,{showCloseButton:!1,className:`p-0 sm:max-w-lg`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b px-4 py-3`,children:[(0,$.jsx)(D,{children:`选择工作目录`}),(0,$.jsx)(u,{size:`icon`,variant:`ghost`,onClick:r,children:(0,$.jsx)(B,{})})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto p-4`,children:[n?(0,$.jsxs)(`p`,{className:`rounded-md bg-muted/50 px-2.5 py-2 text-xs text-muted-foreground`,children:[`工作目录在会话创建时设定,当前会话已锁定。下面的选择会用于`,(0,$.jsx)(`strong`,{children:`新建会话`}),`。`]}):null,(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(M,{className:`flex-1`,placeholder:`绝对路径,如 /Users/you/project`,value:d,autoFocus:!0,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()}}),(0,$.jsx)(u,{size:`sm`,onClick:b,disabled:!d.trim()||p,children:p?(0,$.jsx)(ne,{className:`size-4 animate-spin`}):`使用`})]}),_.length>0?(0,$.jsx)(`ul`,{className:`-mt-1 max-h-80 overflow-y-auto rounded-md border bg-background`,children:_.map(e=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{onClick:()=>f(e.path+`/`),className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-sm hover:bg-accent`,children:[(0,$.jsx)(ht,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name}),(0,$.jsx)(`span`,{className:`ml-auto truncate text-xs text-muted-foreground`,children:e.path})]})},e.path))}):null,h?(0,$.jsx)(`p`,{className:`text-xs text-destructive`,children:h}):null,t?(0,$.jsx)(`button`,{onClick:()=>y(null),className:`text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline`,children:`清除 · 用默认目录`}):null,(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:`最近 / 建议`}),s?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`加载中…`}):a.length===0?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`暂无`}):(0,$.jsx)(`ul`,{className:`space-y-1`,children:a.map(e=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{onClick:()=>y(e.path),className:c(`flex w-full items-center gap-2 rounded-md px-2.5 py-2 text-left hover:bg-accent`,t===e.path&&`bg-accent`),children:[(0,$.jsx)(ht,{className:`size-4 shrink-0 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate text-sm`,children:e.workspace_name||e.path.split(`/`).pop()||e.path}),(0,$.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.path})]}),t===e.path?(0,$.jsx)(de,{className:`size-4 shrink-0 text-primary`}):null]})},e.path))})]})]})]})})}var un=class{samples=[];reset(){this.samples=[]}record(e,t=performance.now()){if(!e||!Number.isFinite(t))return;let n=this.samples.at(-1)?.at;n!==void 0&&(t<n||t-n>2e3)&&this.reset();let r=0;for(let t of e)r+=/[\u1100-\u11ff\u2e80-\u9fff\uac00-\ud7af\uf900-\ufaff\uff00-\uffef]/u.test(t)?.75:.25;let i=this.samples.at(-1);i&&t-i.at<50?i.tokens+=r:this.samples.push({at:t,tokens:r}),this.prune(t)}rate(e=performance.now()){this.prune(e);let t=this.samples[0],n=this.samples.at(-1);if(!t||!n||e<n.at||e-n.at>1500)return null;let r=n.at-t.at;return r<600?null:this.samples.slice(1).reduce((e,t)=>e+t.tokens,0)*1e3/r}prune(e){this.samples=this.samples.filter(t=>e-t.at<=5e3)}};function dn(e,t){let n=(0,Q.useRef)(new un),[r,i]=(0,Q.useState)(null),a=(0,Q.useCallback)(e=>n.current.record(e),[]),o=(0,Q.useCallback)(()=>{n.current.reset(),i(null)},[]);return(0,Q.useEffect)(()=>{if(!t||!e)return;let r=window.setInterval(()=>{let t=n.current.rate();i(n=>n?.sessionId===e&&n.rate===t?n:{sessionId:e,rate:t})},500);return()=>window.clearInterval(r)},[t,e]),{record:a,reset:o,rate:t&&r&&r.sessionId===e?r.rate:null}}var fn=[`development`,`debugging`,`analysis`,`documentation`,`operations`],pn={development:`开发`,debugging:`排障`,analysis:`分析`,documentation:`文档`,operations:`运维`},mn=[`You are Bodhi operating in code review mode.`,`Review code changes with emphasis on correctness, regressions, security, maintainability, tests, and rollout risk.`,`Prefer concise findings with severity, rationale, and actionable fixes.`,`Ask for missing scope or repository context before making strong assumptions.`].join(` `),hn=[`You are Bodhi operating in bug investigation mode.`,`Help diagnose issues by analyzing code, logs, stack traces, and runtime behavior.`,`Trace root causes methodically, suggest targeted fixes, and flag related risks.`,`Ask for reproduction steps or error messages if not provided.`].join(` `),gn=[`You are Bodhi operating in feature implementation mode.`,`Help plan and implement new features step by step, following existing code conventions.`,`Consider edge cases, testing strategies, and backward compatibility.`,`Propose an implementation plan before writing code when scope is large.`].join(` `),_n=[`You are Bodhi operating in architecture analysis mode.`,`Analyze the repository structure, key abstractions, data flow, and module boundaries.`,`Identify architectural patterns, coupling hotspots, and potential improvements.`,`Use diagrams to illustrate relationships when helpful.`].join(` `),vn=[`You are Bodhi operating in error explanation mode.`,`Help users understand error messages, stack traces, and unexpected behavior.`,`Explain the root cause clearly, suggest fixes, and provide prevention tips.`,`Keep explanations accessible even for less experienced developers.`].join(` `),yn=[`You are Bodhi operating in file comparison mode.`,`Compare the given files or code sections, highlighting key differences and their implications.`,`Focus on functional changes, potential regressions, and design trade-offs.`].join(` `),bn=[`You are Bodhi operating in refactoring advisor mode.`,`Suggest targeted refactoring improvements for readability, maintainability, and performance.`,`Respect existing code style, propose incremental changes, and explain the rationale.`,`Flag any risks introduced by the refactoring.`].join(` `),xn=[`You are Bodhi operating in release notes generation mode.`,`Generate clear, well-structured release notes from git history and code changes.`,`Categorize changes (features, fixes, improvements, breaking changes).`,`Write for both technical and non-technical readers.`].join(` `),Sn=[`You are Bodhi operating in work summary mode.`,`Help summarize recent work activity for standups, weeklies, or status reports.`,`Pull key accomplishments, blockers, and next steps from session history or code changes.`,`Keep output concise and actionable.`].join(` `),Cn=[`You are Bodhi operating in documentation writer mode.`,`Help create or improve technical documentation from code and project context.`,`Follow good documentation practices: clear structure, examples, and consistent terminology.`,`Produce Markdown-formatted output by default.`].join(` `),wn=[`You are Bodhi operating in scheduled task setup mode.`,`Help the user create a recurring scheduled task in Bamboo.`,`Clarify the task goal, frequency, workspace, and expected output before proceeding.`,`Guide the user through configuration and confirm before saving.`].join(` `),Tn=[`You are Bodhi operating in session review mode.`,`Help inspect and analyze past session history for patterns, insights, or issues.`,`Summarize key decisions, outcomes, and areas that may need follow-up.`].join(` `),En=[`You are Bodhi operating in context diagnostics mode.`,`Help analyze token usage, prompt bloat, context growth, truncation, and compression behavior.`,`Quantify likely causes when possible and recommend concrete, prioritized fixes.`,`Keep the output practical for engineers improving prompt and session efficiency.`].join(` `),Dn=[{id:`blank`,icon:`plus`,title:`空白会话`,description:`从零开始,默认助手 + 空白输入框。`,prefill:``,category:`development`},{id:`codeReview`,icon:`code`,title:`代码评审`,description:`以评审视角开一个会话,附带可编辑的评审说明。`,prefill:`Review the relevant code changes in this workspace or repository. Start with the overall scope, then list risks, notable diffs, and the most important fixes.`,baseSystemPrompt:mn,category:`development`},{id:`implementFeature`,icon:`wrench`,title:`实现功能`,description:`按现有代码约定,一步步规划并实现新功能。`,prefill:`Help me implement a new feature in this workspace. Start by understanding the codebase structure, then propose an implementation plan before writing code.`,baseSystemPrompt:gn,category:`development`},{id:`refactor`,icon:`gitCompare`,title:`重构建议`,description:`获取针对性的代码质量与可维护性改进建议。`,prefill:`Suggest refactoring improvements for the code in this workspace. Focus on readability, maintainability, and performance. Propose incremental changes with clear rationale.`,baseSystemPrompt:bn,category:`development`},{id:`bugInvestigation`,icon:`bug`,title:`Bug 调查`,description:`通过代码、日志与运行时行为定位问题根因。`,prefill:`Help me investigate a bug. I'll describe the symptoms and share relevant code or logs. Trace the root cause and suggest targeted fixes.`,baseSystemPrompt:hn,category:`debugging`},{id:`explainError`,icon:`helpCircle`,title:`解释报错`,description:`从错误信息或堆栈理解哪里出了问题。`,prefill:`Help me understand the following error. Explain the root cause, suggest fixes, and share prevention tips.`,baseSystemPrompt:vn,category:`debugging`},{id:`tokenUsage`,icon:`barChart`,title:`Token 用量诊断`,description:`诊断上下文增长、截断风险与 token 预算压力。`,prefill:`Help me investigate token usage, context growth, and truncation risk for this session or workflow. Summarize the likely drivers and recommend concrete next fixes.`,baseSystemPrompt:En,category:`debugging`},{id:`architectureReview`,icon:`network`,title:`读仓库架构`,description:`分析仓库结构、模块与架构模式。`,prefill:`Analyze the architecture of this repository. Map the key modules, data flow, abstractions, and dependency patterns. Identify strengths and potential improvements.`,baseSystemPrompt:_n,category:`analysis`},{id:`compareFiles`,icon:`fileSearch`,title:`对比文件`,description:`对比文件或代码片段,理解差异与影响。`,prefill:`Compare the following files or code sections. Highlight key differences, their implications, and any potential risks.`,baseSystemPrompt:yn,category:`analysis`},{id:`releaseNotes`,icon:`fileText`,title:`生成发布说明`,description:`从 git 历史与代码变更生成结构化发布说明。`,prefill:`Generate release notes for the latest changes in this workspace. Categorize into features, fixes, improvements, and breaking changes.`,baseSystemPrompt:xn,category:`documentation`},{id:`summarizeWork`,icon:`bookOpen`,title:`总结工作`,description:`为站会或周报生成工作总结。`,prefill:`Help me summarize my recent work for a status update. Pull key accomplishments, blockers, and next steps.`,baseSystemPrompt:Sn,category:`documentation`},{id:`writeDocs`,icon:`fileText`,title:`写文档`,description:`基于代码与项目上下文创建或完善技术文档。`,prefill:`Help me write technical documentation for this project. Analyze the code and produce clear, well-structured Markdown documentation.`,baseSystemPrompt:Cn,category:`documentation`},{id:`createSchedule`,icon:`clock`,title:`创建定时任务`,description:`设置一个按计划自动运行的循环任务。`,prefill:`Help me set up a recurring scheduled task. I'll describe what I want it to do, and you guide me through the configuration.`,baseSystemPrompt:wn,category:`operations`},{id:`sessionReview`,icon:`search`,title:`回顾会话历史`,description:`检视过往会话,发现模式与需要跟进的点。`,prefill:`Help me review my recent session history. Summarize key decisions, outcomes, and areas that need follow-up.`,baseSystemPrompt:Tn,category:`operations`}],On=null,kn=0,An=e=>{if(e===null){On=null;return}kn+=1,On=Object.freeze({prompt:e,revision:kn})},jn=()=>On,Mn=e=>On?.revision!==e.revision||On.prompt!==e.prompt?!1:(On=null,!0),Nn=e=>JSON.stringify([e.interaction_kind,e.tool_call_id,e.interaction_kind===`permission`?e.permission_request.request_generation:null,e.interaction_kind===`permission`?e.permission_request.policy_revision:null]),Pn=(e,t)=>e.sessionId===t.sessionId&&e.epoch===t.epoch,Fn=[];function In(e,t){let n=e!==void 0,r=J(v(e=>e.chats)),i=J(e=>e.currentSessionId),a=n?e:i,o=J(Ne(a)),s=J(v(e=>Ne(a)(e)?.messages??[])),c=J(e=>e.selectedModel),l=He(e=>e.providerSnapshot?.defaults?.chat?.model),u=c||l||``,d=He(e=>{let t=e.providerSnapshot?.defaults?.chat.provider;return Ue(e.providerSnapshot,t)}),f=He(e=>{let t=e.providerSnapshot?.defaults?.chat.provider;return t?e.getProviderType(t):void 0}),p=J(e=>e.inputStates[a??``]?.reasoningEffort)??d,[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(!1),{rate:E,record:D,reset:O}=dn(a,(w||o?.isRunning===!0)&&b===a),[ee,k]=(0,Q.useState)(!1),[te,A]=(0,Q.useState)(()=>new Map),[j,M]=(0,Q.useState)(null),P=(0,Q.useRef)(null),F=(0,Q.useRef)(!1),I=(0,Q.useRef)(0),L=(0,Q.useRef)(null),R=(0,Q.useRef)(new Map),ne=(0,Q.useRef)(new Map),re=(0,Q.useRef)(null),ae=(0,Q.useRef)(null),z=(0,Q.useRef)({sessionId:a,epoch:0});z.current.sessionId!==a&&(z.current={sessionId:a,epoch:z.current.epoch+1});let[se,ce]=(0,Q.useState)(()=>({scope:z.current,question:null,loading:!1,submitting:!1,unavailable:!1,error:null,retry:null,recordedKey:null})),B=(0,Q.useRef)(se),le=(0,Q.useRef)(0),V=(0,Q.useRef)(null),H=Pn(se.scope,z.current)?se:null,ue=H?.question??null,U=(0,Q.useCallback)(e=>{let t=e(B.current);B.current=t,ce(t)},[]),W=(0,Q.useCallback)(e=>F.current&&Pn(e,z.current),[]),G=(0,Q.useCallback)(async(e=z.current,t=!1)=>{if(!e.sessionId||!W(e))return`stale`;let n=++le.current;U(e=>({...e,loading:!0}));try{let r=await K.getPendingQuestion(e.sessionId);if(!W(e)||le.current!==n)return`stale`;let i=r.has_pending_question?r:null;return U(n=>{let r=n.question?Nn(n.question):n.recordedKey,a=!!i&&(Nn(i)!==r||n.retry&&i.interaction_kind===`permission`&&!i.permission_request.allowed_decisions.includes(n.retry.decision));a&&(V.current=null);let o=a?null:n.retry,s=a?null:n.recordedKey,c=V.current,l=c?.awaitingResponse&&Pn(c.scope,e)&&n.question&&Nn(n.question)===c.key;return{scope:e,question:i??(o||l?n.question:null),loading:!1,submitting:a?!1:n.submitting,unavailable:!1,retry:o,recordedKey:s,error:t||o||s?n.error:null}}),i?`pending`:`absent`}catch{return!W(e)||le.current!==n?`stale`:(U(e=>({...e,loading:!1,unavailable:!0,error:e.recordedKey?`决定已记录,但暂时无法读取后续状态。请刷新。`:e.retry?`上次提交结果尚未确认,当前请求也暂时无法读取。请刷新或重试上次提交。`:`暂时无法读取确认请求,请刷新后重试。`})),`unavailable`)}},[W,U]),de=(0,Q.useRef)(null),fe=(0,Q.useRef)(``),pe=(0,Q.useRef)(null),[me,he]=(0,Q.useState)(null),_e=(0,Q.useRef)(``),ve=(0,Q.useRef)(null),ye=(0,Q.useRef)({}),[be,xe]=(0,Q.useState)([]),Ce=(0,Q.useRef)([]),we=(0,Q.useRef)(null),Ee=(0,Q.useRef)(new Map),[De,Oe]=(0,Q.useState)(null),ke=(0,Q.useRef)(null),Ae=b===a?g:null,je=b===a?me:null,Me=b===a?be:Fn,Pe=b===a?De:null,Fe=S?.sid===a?S.text:null,Ie=te.get(a??null)??null,Le=(0,Q.useCallback)((e,t)=>{let n=ne.current.get(e);(n===void 0||t>n)&&ne.current.set(e,t)},[]),q=(0,Q.useCallback)(e=>{let t=ne.current.get(e.sessionId);if(t!==void 0&&t>e.operationId)return!1;let n=R.current.get(e.sessionId);if(n&&n.operationId>e.operationId)return!1;let r=new Map(R.current);return r.set(e.sessionId,e),R.current=r,F.current&&A(r),!0},[]),Re=(0,Q.useCallback)((e,t)=>{let n=R.current.get(e);if(!n||t!==void 0&&n.operationId!==t)return!1;let r=new Map(R.current);return r.delete(e),R.current=r,F.current&&A(r),!0},[]),ze=(0,Q.useCallback)(e=>R.current.get(e)??null,[]),Y=(0,Q.useCallback)(e=>{F.current&&C(t=>t?.operationId===e?null:t)},[]),X=(0,Q.useCallback)(e=>{ke.current!==e&&(ke.current=e,Oe(e))},[]),Ve=(0,Q.useCallback)(()=>{we.current??=requestAnimationFrame(()=>{we.current=null,xe(Ce.current.map(e=>e.kind===`tools`?{...e,calls:e.calls.map(e=>({...e}))}:e))})},[]),We=(0,Q.useCallback)(()=>{let e=fe.current,t=_e.current;!e.trim()&&!t.trim()||(Ce.current.push({kind:`text`,text:e,reasoning:t.trim()?t:null}),fe.current=``,_e.current=``,pe.current!=null&&(cancelAnimationFrame(pe.current),pe.current=null),ve.current!=null&&(cancelAnimationFrame(ve.current),ve.current=null),_(``),he(null))},[]),Ge=(0,Q.useCallback)(e=>{X(null),D(e),fe.current+=e,pe.current??=requestAnimationFrame(()=>{pe.current=null,_(fe.current)})},[X,D]),Ke=(0,Q.useCallback)(e=>{D(e),_e.current+=e,ve.current??=requestAnimationFrame(()=>{ve.current=null,he(_e.current)})},[D]),Z=(0,Q.useCallback)((e,t)=>{t!==void 0&&re.current!==t||(pe.current!=null&&(cancelAnimationFrame(pe.current),pe.current=null),ve.current!=null&&(cancelAnimationFrame(ve.current),ve.current=null),we.current!=null&&(cancelAnimationFrame(we.current),we.current=null),fe.current=``,_e.current=``,Ce.current=[],Ee.current.clear(),re.current=null,xe(Fn),X(null),_(e),he(null))},[X]),qe=`lotus_next_last_session`;(0,Q.useEffect)(()=>{if(n){h(!0);return}Te().finally(()=>{try{let e=localStorage.getItem(qe);e&&J.getState().chats.some(t=>t.id===e)&&(J.getState().selectSession(e),J.getState().loadChatHistory(e))}catch{}h(!0)})},[n]),(0,Q.useEffect)(()=>{if(!(n||!i))try{localStorage.setItem(qe,i)}catch{}},[i,n]);let Je=(0,Q.useCallback)(e=>{J.getState().selectSession(e),J.getState().loadChatHistory(e)},[]),Ye=(0,Q.useCallback)(async(e,t)=>{let n=t?.operationId??I.current+1;I.current=Math.max(I.current,n),Le(e,n),re.current=n;let r=()=>re.current===n,i={settlement:null,pendingRead:null};P.current?.abort(),x(e),O(),fe.current=``,_e.current=``,ye.current={},Ce.current=[],Ee.current.clear(),xe(Fn),X(null),_(``),he(null);let a=new AbortController;P.current=a;let o={operationId:n,sessionId:e};if(ae.current=o,de.current=e,t?.resume||K.execute(e,u||void 0,p).catch(()=>{r()&&(q({kind:`generation-failed`,operationId:n,sessionId:e,pendingOperationId:t?.pendingOperationId}),Z(null,n),a.abort())}),await K.subscribeToEvents(e,{onToken:Ge,onReasoningToken:Ke,onToolStart:(e,t,n)=>{We();let r={toolCallId:e,toolName:t,args:n,output:``,status:`running`};Ee.current.set(e,r);let i=Ce.current[Ce.current.length-1];i&&i.kind===`tools`?i.calls.push(r):Ce.current.push({kind:`tools`,calls:[r]}),X(`正在运行 ${t}…`),Ve()},onToolToken:(e,t)=>{let n=Ee.current.get(e);n&&(n.output+=t,Ve())},onToolComplete:(e,t)=>{let n=Ee.current.get(e);if(!n)return;n.status=`completed`;let r=t;typeof r?.result==`string`&&r.result&&(n.output=r.result),X(null),Ve()},onToolError:(e,t)=>{let n=Ee.current.get(e);n&&(n.status=`error`,n.error=t,X(null),Ve())},onTaskListUpdated:e=>{e.session_id&&J.getState().setTaskList(e.session_id,e)},onTaskListItemProgress:e=>{if(!e.session_id)return;let t=J.getState();t.taskLists[e.session_id]?t.updateTaskListDelta(e.session_id,e):t.loadTaskList(e.session_id)},onTaskEvaluationStarted:e=>{J.getState().setEvaluationState(e,{isEvaluating:!0,reasoning:null,timestamp:Date.now()})},onTaskEvaluationCompleted:(e,t,n)=>{J.getState().setEvaluationState(e,{isEvaluating:!1,reasoning:t>0?n:null,timestamp:Date.now()})},onTokenBudgetUpdated:t=>{let n=ge(t);if(!n)return;let r=J.getState();r.updateTokenUsage(e,n),r.setTruncationInfo(e,t.truncation_occurred,t.segments_removed)},onContextCompressionStatus:(e,t)=>{X(t===`started`?`正在压缩上下文…`:null)},onSubAgentStarted:(e,t,n)=>{J.getState().applyChildProgress(e,t,{title:n,status:`running`})},onSubAgentEvent:(e,t,n)=>{let r=n,i={};r.type===`token`&&r.content?(ye.current[t]=(ye.current[t]||``)+r.content,i.outputPreview=ye.current[t].slice(-400)):r.type===`tool_start`&&r.tool_name&&(i.outputPreview=`· 调用 ${r.tool_name}…`),i.outputPreview!==void 0&&J.getState().applyChildProgress(e,t,i)},onSubAgentCompleted:(e,t,n,r)=>{J.getState().applyChildProgress(e,t,{status:r?`error`:n||`completed`,error:r||void 0})},onBashCompleted:(e,t,n,r)=>{J.getState().setBashCompleted(e,r,n)},onNotification:e=>{let t=e;Se(t.title??``,t.body??``)},onNeedClarification:()=>{let t=z.current;!r()||t.sessionId!==e||!W(t)||(i.pendingRead=(async()=>{await G(t)!==`absent`||!W(t)||await G(t)===`absent`&&W(t)&&!B.current.question&&U(e=>({...e,error:e.error??`确认请求尚未准备好,请刷新。`}))})())},onChildApprovalRequested:(e,t,n)=>M({childSessionId:e,requestId:t,toolName:n.toolName,permission:n.permission,resource:n.resource}),onComplete:()=>{!r()||i.settlement||(i.settlement=(async()=>{pe.current!=null&&(cancelAnimationFrame(pe.current),pe.current=null);let i=fe.current;i&&_(i);let a=!1;try{await J.getState().loadChatHistory(e,{waitForAssistant:!0,retries:8,retryDelayMs:150}),a=!0}catch(e){console.warn(`[useChat] terminal history hydration failed`,e)}r()&&(a&&t?.pendingOperationId!==void 0&&Y(t.pendingOperationId),Z(a?null:i||null,n))})())},onError:()=>{!r()||i.settlement||(q({kind:`generation-failed`,operationId:n,sessionId:e,pendingOperationId:t?.pendingOperationId}),i.settlement=(async()=>{let i=!1;try{await J.getState().loadChatHistory(e),i=!0}catch(e){console.warn(`[useChat] failed-generation history hydration failed`,e)}r()&&(i&&t?.pendingOperationId!==void 0&&Y(t.pendingOperationId),Z(null,n))})())},onCancelled:()=>{!r()||i.settlement||(i.settlement=(async()=>{let i=!1;try{await J.getState().loadChatHistory(e),i=!0}catch(e){console.warn(`[useChat] cancelled-generation history hydration failed`,e)}r()&&(i&&t?.pendingOperationId!==void 0&&Y(t.pendingOperationId),Z(null,n))})())}},a).finally(()=>{ae.current===o&&(ae.current=null,de.current=null)}),i.settlement)await i.settlement;else if(r()){if(i.pendingRead&&await i.pendingRead,!r())return;let a=B.current;if(a.scope.sessionId===e&&W(a.scope)&&a.question){try{await J.getState().loadChatHistory(e),t?.pendingOperationId!==void 0&&Y(t.pendingOperationId)}catch{}Z(null,n);return}q({kind:`generation-failed`,operationId:n,sessionId:e,pendingOperationId:t?.pendingOperationId}),Z(null,n)}},[u,p,We,Ge,O,Ke,X,Ve,Z,Y,q,Le,W,G,U]);(0,Q.useEffect)(()=>(F.current=!0,()=>{F.current=!1,re.current=null,ae.current=null,de.current=null,P.current?.abort()}),[]);let Xe=J(e=>a?Be(a)(e):!1);(0,Q.useEffect)(()=>{!a||!Xe||L.current||de.current!==a&&Ye(a,{resume:!0})},[a,Xe,w,Ye]);let Ze=o?.isRunning??!1;(0,Q.useEffect)(()=>{if(!a||Ze||de.current!==a||w)return;let e=setTimeout(()=>{de.current===a&&(J.getState().chats.find(e=>e.id===a)?.isRunning||(P.current?.abort(),J.getState().loadChatHistory(a).then(()=>Z(null))))},2e3);return()=>clearTimeout(e)},[a,Ze,w,Z]),(0,Q.useEffect)(()=>{let e=z.current;V.current=null,U(()=>({scope:e,question:null,loading:!1,submitting:!1,unavailable:!1,error:null,retry:null,recordedKey:null})),a&&G(e)},[a,G,U]),(0,Q.useEffect)(()=>{if(n)return;let e=()=>{if(document.visibilityState!==`visible`)return;let e=J.getState();e.refreshChatsNow();let t=e.currentSessionId;t&&e.reconcileOpenSession(t,`visibility_regain`)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[n]);let Qe=(0,Q.useCallback)(async(e,t)=>{if(L.current||t?.expectedFailureOperationId!==void 0&&ze(e)?.operationId!==t.expectedFailureOperationId)return!1;let n={id:I.current+1,phase:`preparing`,originSessionId:e,originNavigationEpoch:z.current.epoch,acknowledgedSessionId:e,pendingOperationId:t?.pendingOperationId};I.current=n.id,Le(e,n.id),L.current=n,F.current&&(T(!0),k(!0));let r=!1,i=!1,a=()=>{L.current?.id===n.id&&(L.current=null,i=!0,F.current&&(k(!1),T(!1)))};try{if(await t?.prepare?.(),L.current?.id!==n.id)return!1;if(t?.expectedFailureOperationId!==void 0&&ze(e)?.operationId!==t.expectedFailureOperationId?console.warn(`[useChat] retry failure ownership changed after preparation`):Re(e,t?.expectedFailureOperationId),n.phase=`generating`,!(F.current&&z.current.sessionId===n.originSessionId&&z.current.epoch===n.originNavigationEpoch)){a();try{await K.execute(e,u||void 0,p);try{await J.getState().loadChatHistory(e),n.pendingOperationId!==void 0&&Y(n.pendingOperationId)}catch(e){console.warn(`[useChat] detached rerun history hydration failed`,e)}return!0}catch(t){return console.warn(`[useChat] detached rerun start failed`,t),q({kind:`generation-failed`,operationId:n.id,sessionId:e,pendingOperationId:n.pendingOperationId}),!1}}F.current&&k(!1);let i=Ye(e,{operationId:n.id,pendingOperationId:n.pendingOperationId});return r=!0,J.getState().loadChatHistory(e).then(()=>{n.pendingOperationId!==void 0&&Y(n.pendingOperationId)}).catch(e=>console.warn(`[useChat] rerun history hydration failed`,e)),await i,!0}catch(i){return console.error(`[useChat] rerun failed`,i),(r||!t?.preserveFailureOnPrepareError)&&q({kind:`generation-failed`,operationId:n.id,sessionId:e,pendingOperationId:n.pendingOperationId}),Z(null,n.id),!1}finally{!i&&L.current?.id===n.id&&(L.current=null,F.current&&(k(!1),T(!1)))}},[Y,Re,u,ze,Le,q,p,Ye,Z]),$e=(0,Q.useCallback)(async()=>{a&&await Qe(a,{prepare:()=>K.truncateSessionMessages(a,{mode:`after_last_user`}).catch(()=>{})})},[a,Qe]),et=(0,Q.useCallback)(async e=>{let t=ze(a??null),n=e??(t?.kind===`generation-failed`?t:void 0);!n||ze(n.sessionId)?.operationId!==n.operationId||await Qe(n.sessionId,{expectedFailureOperationId:n.operationId,pendingOperationId:n.pendingOperationId,preserveFailureOnPrepareError:!0,prepare:()=>K.truncateSessionMessages(n.sessionId,{mode:`error_retry`})})},[ze,Qe,a]),tt=(0,Q.useCallback)(async(e,t)=>{let n=t.trim();!a||!n||await Qe(a,{prepare:async()=>{await K.patchSessionMessage(a,e,{content:n}).catch(()=>{}),await K.restoreSessionState(a,{target_message_id:e,restore_files:!1}).catch(()=>{})}})},[a,Qe]),nt=(0,Q.useCallback)(async(e,r)=>{let i=e.trim();if(!i&&!r?.images?.length)return{kind:`ignored`};if(L.current)return{kind:`busy`};let o=a,s={id:I.current+1,phase:`submitting`,originSessionId:o,originNavigationEpoch:z.current.epoch};I.current=s.id,Le(o,s.id),L.current=s,F.current&&(T(!0),k(!0)),Re(o);let c=o?null:r?.templatePrompt??null,l;try{let e=y(f).trim(),t;if(!o){let e=J.getState(),n=e.lastSelectedPromptId?e.systemPrompts.find(t=>t.id===e.lastSelectedPromptId):void 0;t=c?.prompt.trim()||n?.content?.trim()||void 0}let n=await K.sendMessage({message:i,session_id:o??void 0,model:u,enhance_prompt:e||void 0,copilot_conclusion_with_options_enhancement_enabled:f===`copilot`&&oe(),system_prompt:t,selected_skill_ids:r?.skillIds?.length?r.skillIds:void 0,images:r?.images?.length?r.images:void 0,workspace_path:!o&&r?.workspacePath?r.workspacePath:void 0});if(l=typeof n?.session_id==`string`?n.session_id.trim():``,!l||o&&l!==o)throw Error(`The chat submission response did not acknowledge the expected session.`)}catch(e){return console.error(`[useChat] message submission was not acknowledged`,e),L.current?.id===s.id&&(L.current=null),F.current&&(k(!1),T(!1),q({kind:`submission-unconfirmed`,operationId:s.id,sessionId:o})),{kind:`unconfirmed`,operationId:s.id}}s.phase=`generating`,s.acknowledgedSessionId=l,s.pendingOperationId=s.id,Le(l,s.id),c&&Mn(c);let d=!1;return F.current&&z.current.sessionId===s.originSessionId&&z.current.epoch===s.originNavigationEpoch?(k(!1),i&&C({operationId:s.id,sid:l,text:i}),l!==o&&(n?t&&(t(l),d=!0):(J.getState().selectSession(l),d=!0)),Ye(l,{operationId:s.id,pendingOperationId:s.pendingOperationId}).catch(e=>{console.error(`[useChat] acknowledged generation failed`,e),q({kind:`generation-failed`,operationId:s.id,sessionId:l,pendingOperationId:s.pendingOperationId}),Z(null,s.id)}).finally(()=>{L.current?.id===s.id&&(L.current=null),F.current&&T(!1)}),(async()=>{l!==o&&await J.getState().refreshChatsNow().catch(e=>console.warn(`[useChat] acknowledged session refresh failed`,e)),await J.getState().loadChatHistory(l),Y(s.id)})().catch(e=>{console.warn(`[useChat] acknowledged message hydration failed`,e)})):(F.current&&(k(!1),T(!1)),L.current?.id===s.id&&(L.current=null),K.execute(l,u||void 0,p).catch(e=>{console.warn(`[useChat] detached generation start failed`,e),q({kind:`generation-failed`,operationId:s.id,sessionId:l})}),l!==o&&J.getState().refreshChatsNow().catch(e=>console.warn(`[useChat] detached session refresh failed`,e))),{kind:`accepted`,operationId:s.id,sessionId:l,navigated:d}},[a,n,t,u,f,p,Ye,Z,Y,Re,Le,q]),rt=(0,Q.useCallback)(()=>{let e=L.current;if(e?.phase===`submitting`||e?.phase===`preparing`)return;let t=e?.acknowledgedSessionId??a,n=e?.pendingOperationId,r=e?.id??re.current??void 0;P.current?.abort(),Z(null,r),t&&(async()=>{await K.stopGeneration(t).catch(()=>{});try{await J.getState().loadChatHistory(t),n!==void 0&&Y(n)}catch(e){console.warn(`[useChat] stopped-generation history hydration failed`,e)}})()},[Y,a,Z]),it=(0,Q.useCallback)(()=>{J.getState().selectSession(null),Z(null)},[Z]),at=(0,Q.useCallback)(async e=>{a&&(await K.deleteSessionMessage(a,e).catch(()=>{}),await J.getState().loadChatHistory(a))},[a]),ot=(0,Q.useCallback)(async e=>{if(a)try{let r=await N.post(`sessions/${encodeURIComponent(a)}/fork`,{up_to_message_id:e}),i=r?.session?.id??r?.session?.session_id;return i?(await J.getState().refreshChatsNow(),n?t?.(i):J.getState().selectSession(i),await J.getState().loadChatHistory(i),i):void 0}catch{return}},[a,n,t]),st=(0,Q.useCallback)(async(e,t,n,r=!1)=>{let i=B.current,{scope:a,question:o}=i;if(!a.sessionId||!W(a)||!o||V.current||i.loading||i.submitting)return;let s=Nn(o);if(!t||!Pn(t,a)||n!==s||i.recordedKey===s||!r&&(i.unavailable||i.retry)||r&&!i.retry)return;let c=null;if(o.interaction_kind===`permission`){let t=o.permission_request;if(r){let e=i.retry;if(e.request_id!==t.request_id||e.request_generation!==t.request_generation||e.expected_policy_revision!==t.policy_revision||!t.allowed_decisions.includes(e.decision))return;c=e}else{if(e!==`allow_once`&&e!==`deny_once`||!t.allowed_decisions.includes(e))return;c={request_id:t.request_id,request_generation:t.request_generation,expected_policy_revision:t.policy_revision,decision:e}}}else if(!e.trim()||!o.allow_custom&&!o.options.includes(e))return;let l={scope:a,key:s,awaitingResponse:!0};V.current=l;let u=()=>V.current===l&&W(a)&&B.current.question!==null&&Nn(B.current.question)===s;U(e=>({...e,submitting:!0,error:null}));try{let t,n;if(c){let e=await K.submitPermissionDecision(a.sessionId,c);t=e.autoResumeStatus,n=e.continuationConfirmed}else{let r=await N.post(`respond/${encodeURIComponent(a.sessionId)}`,{response:e,expected_tool_call_id:o.tool_call_id});if(r?.success!==!0)throw Error(`Unconfirmed clarification response`);t=r.auto_resume_status,n=[`started`,`already_running`,`completed`].includes(t??``)}if(l.awaitingResponse=!1,!u()||(++le.current,U(e=>({...e,question:null,retry:null,recordedKey:s,unavailable:!1,loading:!1,error:n?null:`回答已记录,但暂时无法确认任务是否继续。请刷新。`})),await G(a,!n),!W(a)||V.current!==l))return;J.getState().loadChatHistory(a.sessionId).catch(()=>{}),n&&(t===`started`||t===`already_running`)&&!B.current.question&&de.current!==a.sessionId&&Ye(a.sessionId,{resume:!0})}catch(e){if(l.awaitingResponse=!1,!u())return;let t=ie(e)&&e.status>=400&&e.status<500;U(e=>({...e,retry:t?null:c,unavailable:t,error:t?`当前请求或权限已变化,请按刷新后的选项重新确认。`:c?`提交结果尚未确认。请刷新,或重试上次提交以确认结果。`:`回答结果尚未确认,请刷新当前问题后重试。`})),await G(a,!0)}finally{V.current===l&&(V.current=null,W(a)&&U(e=>({...e,submitting:!1})))}},[W,G,Ye,U]),ct=H?.scope,lt=ue?Nn(ue):null,ut=(0,Q.useCallback)(e=>st(e,ct,lt),[st,ct,lt]),dt=(0,Q.useCallback)(()=>st(``,ct,lt,!0),[st,ct,lt]),ft=(0,Q.useCallback)(()=>G(),[G]),pt=(0,Q.useCallback)(async e=>{let t=j;M(null),t&&await K.respondToChildApproval(t.childSessionId,t.requestId,e).catch(()=>{})},[j]);return{booted:n?!0:m,chats:r,currentSessionId:a,currentChat:o,messages:s,streaming:Ae,streamingReasoning:je,liveSegments:Me,streamStatus:Pe,outputRate:E,pendingUserText:Fe,sending:w,submissionPending:ee,select:Je,send:nt,stop:rt,newChat:it,deleteMessage:at,fork:ot,regenerate:$e,retry:et,editMessage:tt,sendFailure:Ie,pendingQuestion:ue,questionLoading:H?.loading??!1,questionSubmitting:H?.submitting??!1,questionUnavailable:(H?.unavailable??!1)||!!ue&&H?.recordedKey===Nn(ue),questionError:H?.error??null,questionCanRetry:!!H?.retry,refreshQuestion:ft,retryQuestion:dt,pendingApproval:j,answerQuestion:ut,respondApproval:pt}}function Ln(e,t,n){let{min:r,max:i,edge:a}=n,o=e=>Math.min(i,Math.max(r,e)),[s,c]=(0,Q.useState)(()=>{try{let t=localStorage.getItem(e),n=t?parseInt(t,10):NaN;if(!Number.isNaN(n))return o(n)}catch{}return t}),l=(0,Q.useRef)(s);return l.current=s,{width:s,startResize:(0,Q.useCallback)(t=>{t.preventDefault();let n=t.clientX,r=l.current,i=e=>{let t=e.clientX-n;c(o(r+(a===`left`?-t:t)))},s=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,s),document.body.style.cursor=``,document.body.style.userSelect=``;try{localStorage.setItem(e,String(l.current))}catch{}};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,s),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`},[a,e])}}function Rn({onPointerDown:e,className:t}){return(0,$.jsxs)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:e,className:c(`group relative z-30 hidden w-px shrink-0 cursor-col-resize bg-border md:block`,t),children:[(0,$.jsx)(`span`,{className:`absolute inset-y-0 -left-1.5 -right-1.5`}),(0,$.jsx)(`span`,{className:`absolute inset-y-0 -left-px -right-px bg-primary opacity-0 transition-opacity group-hover:opacity-100 group-active:opacity-100`})]})}var zn=`lotus-next.session-read.v1`,Bn={};function Vn(e){let t=Date.parse(e.lastActivityAt??``),n=e.messageCount??e.messages?.length??0;return{at:Number.isFinite(t)?t:0,count:Number.isFinite(n)?Math.max(0,n):0}}function Hn(e){try{let t=JSON.parse(e??`null`);return!t||typeof t!=`object`||Array.isArray(t)?{}:Object.fromEntries(Object.entries(t).filter(([e,t])=>e&&t&&[t.at,t.count,t.readAt].every(e=>typeof e==`number`&&Number.isFinite(e)&&e>=0)).sort((e,t)=>t[1].readAt-e[1].readAt).slice(0,2e3))}catch{return{}}}function Un(e,t){let n=Vn(e);if(n.count===0)return!1;let r=Object.hasOwn(t,e.id)?t[e.id]:void 0;return!r||n.count>r.count||n.at>r.at}function Wn(e,t,n=Date.now()){let r=Vn(t),i=Object.hasOwn(e,t.id)?e[t.id]:void 0;if(i&&i.at>=r.at&&i.count>=r.count)return e;let a={at:Math.max(r.at,i?.at??0),count:Math.max(r.count,i?.count??0),readAt:n};return Object.fromEntries(Object.entries({...e,[t.id]:a}).sort((e,t)=>t[1].readAt-e[1].readAt).slice(0,2e3))}function Gn(){try{return Hn(localStorage.getItem(zn))}catch{return{}}}var Kn=Gn(),qn=new Set;function Jn(e){if(e!==Kn){Kn=e;for(let e of qn)e()}}function Yn(e){(e.key===zn||e.key===null)&&Jn(Gn())}function Xn(e){return qn.add(e),qn.size===1&&window.addEventListener(`storage`,Yn),()=>{qn.delete(e),qn.size||window.removeEventListener(`storage`,Yn)}}function Zn(){return(0,Q.useSyncExternalStore)(Xn,()=>Kn,()=>Bn)}function Qn(e){(0,Q.useEffect)(()=>{if(!e)return;let t=()=>{if(document.visibilityState===`hidden`)return;let t=Wn(Kn,e);if(t!==Kn){Jn(t);try{localStorage.setItem(zn,JSON.stringify(t))}catch{}}};return t(),document.addEventListener(`visibilitychange`,t),()=>document.removeEventListener(`visibilitychange`,t)},[e])}var $n=`rovingFocusGroup.onEntryFocus`,er={bubbles:!1,cancelable:!0},tr=`RovingFocusGroup`,[nr,rr,ir]=fe(tr),[ar,or]=Me(tr,[ir]),[sr,cr]=ar(tr),lr=Q.forwardRef((e,t)=>(0,$.jsx)(nr.Provider,{scope:e.__scopeRovingFocusGroup,children:(0,$.jsx)(nr.Slot,{scope:e.__scopeRovingFocusGroup,children:(0,$.jsx)(ur,{...e,ref:t})})}));lr.displayName=tr;var ur=Q.forwardRef((e,t)=>{let{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:a,currentTabStopId:o,defaultCurrentTabStopId:s,onCurrentTabStopIdChange:c,onEntryFocus:u,preventScrollOnEntryFocus:d=!1,...f}=e,p=Q.useRef(null),m=l(t,p),h=Ce(a),[g,_]=be({prop:o,defaultProp:s??null,onChange:c,caller:tr}),[v,y]=Q.useState(!1),b=G(u),x=rr(n),S=Q.useRef(!1),[C,w]=Q.useState(0);return Q.useEffect(()=>{let e=p.current;if(e)return e.addEventListener($n,b),()=>e.removeEventListener($n,b)},[b]),(0,$.jsx)(sr,{scope:n,orientation:r,dir:h,loop:i,currentTabStopId:g,onItemFocus:Q.useCallback(e=>_(e),[_]),onItemShiftTab:Q.useCallback(()=>y(!0),[]),onFocusableItemAdd:Q.useCallback(()=>w(e=>e+1),[]),onFocusableItemRemove:Q.useCallback(()=>w(e=>e-1),[]),children:(0,$.jsx)(R.div,{tabIndex:v||C===0?-1:0,"data-orientation":r,...f,ref:m,style:{outline:`none`,...e.style},onMouseDown:q(e.onMouseDown,()=>{S.current=!0}),onFocus:q(e.onFocus,e=>{let t=!S.current;if(e.target===e.currentTarget&&t&&!v){let t=new CustomEvent($n,er);if(e.currentTarget.dispatchEvent(t),!t.defaultPrevented){let e=x().filter(e=>e.focusable);gr([e.find(e=>e.active),e.find(e=>e.id===g),...e].filter(Boolean).map(e=>e.ref.current),d)}}S.current=!1}),onBlur:q(e.onBlur,()=>y(!1))})})}),dr=`RovingFocusGroupItem`,fr=Q.forwardRef((e,t)=>{let{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:a,children:o,...s}=e,c=Y(),l=a||c,u=cr(dr,n),d=u.currentTabStopId===l,f=rr(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:h}=u;return Q.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),(0,$.jsx)(nr.ItemSlot,{scope:n,id:l,focusable:r,active:i,children:(0,$.jsx)(R.span,{tabIndex:d?0:-1,"data-orientation":u.orientation,...s,ref:t,onMouseDown:q(e.onMouseDown,e=>{r?u.onItemFocus(l):e.preventDefault()}),onFocus:q(e.onFocus,()=>u.onItemFocus(l)),onKeyDown:q(e.onKeyDown,e=>{if(e.key===`Tab`&&e.shiftKey){u.onItemShiftTab();return}if(e.target!==e.currentTarget)return;let t=hr(e,u.orientation,u.dir);if(t!==void 0){if(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)return;e.preventDefault();let n=f().filter(e=>e.focusable).map(e=>e.ref.current);if(t===`last`)n.reverse();else if(t===`prev`||t===`next`){t===`prev`&&n.reverse();let r=n.indexOf(e.currentTarget);n=u.loop?_r(n,r+1):n.slice(r+1)}setTimeout(()=>gr(n))}}),children:typeof o==`function`?o({isCurrentTabStop:d,hasTabStop:h!=null}):o})})});fr.displayName=dr;var pr={ArrowLeft:`prev`,ArrowUp:`prev`,ArrowRight:`next`,ArrowDown:`next`,PageUp:`first`,Home:`first`,PageDown:`last`,End:`last`};function mr(e,t){return t===`rtl`?e===`ArrowLeft`?`ArrowRight`:e===`ArrowRight`?`ArrowLeft`:e:e}function hr(e,t,n){let r=mr(e.key,n);if(!(t===`vertical`&&[`ArrowLeft`,`ArrowRight`].includes(r))&&!(t===`horizontal`&&[`ArrowUp`,`ArrowDown`].includes(r)))return pr[r]}function gr(e,t=!1){let n=document.activeElement;for(let r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function _r(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var vr=lr,yr=fr,br=[`Enter`,` `],xr=[`ArrowDown`,`PageUp`,`Home`],Sr=[`ArrowUp`,`PageDown`,`End`],Cr=[...xr,...Sr],wr={ltr:[...br,`ArrowRight`],rtl:[...br,`ArrowLeft`]},Tr={ltr:[`ArrowLeft`],rtl:[`ArrowRight`]},Er=`Menu`,[Dr,Or,kr]=fe(Er),[Ar,jr]=Me(Er,[kr,Ae,or]),Mr=Ae(),Nr=or(),[Pr,Fr]=Ar(Er),[Ir,Lr]=Ar(Er),Rr=e=>{let{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:a,modal:o=!0}=e,s=Mr(t),[c,l]=Q.useState(null),u=Q.useRef(!1),d=G(a),f=Ce(i);return Q.useEffect(()=>{let e=()=>{u.current=!0,document.addEventListener(`pointerdown`,t,{capture:!0,once:!0}),document.addEventListener(`pointermove`,t,{capture:!0,once:!0})},t=()=>u.current=!1;return document.addEventListener(`keydown`,e,{capture:!0}),()=>{document.removeEventListener(`keydown`,e,{capture:!0}),document.removeEventListener(`pointerdown`,t,{capture:!0}),document.removeEventListener(`pointermove`,t,{capture:!0})}},[]),Q.useEffect(()=>{if(!n)return;let e=()=>d(!1);return window.addEventListener(`blur`,e),()=>window.removeEventListener(`blur`,e)},[n,d]),(0,$.jsx)(Pe,{...s,children:(0,$.jsx)(Pr,{scope:t,open:n,onOpenChange:d,content:c,onContentChange:l,children:(0,$.jsx)(Ir,{scope:t,onClose:Q.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:f,modal:o,children:r})})})};Rr.displayName=Er;var zr=`MenuAnchor`,Br=Q.forwardRef((e,t)=>{let{__scopeMenu:n,...r}=e,i=Mr(n);return(0,$.jsx)(X,{...i,...r,ref:t})});Br.displayName=zr;var Vr=`MenuPortal`,[Hr,Ur]=Ar(Vr,{forceMount:void 0}),Wr=e=>{let{__scopeMenu:t,forceMount:n,children:r,container:i}=e,a=Fr(Vr,t);return(0,$.jsx)(Hr,{scope:t,forceMount:n,children:(0,$.jsx)(Fe,{present:n||a.open,children:(0,$.jsx)(ee,{asChild:!0,container:i,children:r})})})};Wr.displayName=Vr;var Gr=`MenuContent`,[Kr,qr]=Ar(Gr),Jr=Q.forwardRef((e,t)=>{let n=Ur(Gr,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,a=Fr(Gr,e.__scopeMenu),o=Lr(Gr,e.__scopeMenu);return(0,$.jsx)(Dr.Provider,{scope:e.__scopeMenu,children:(0,$.jsx)(Fe,{present:r||a.open,children:(0,$.jsx)(Dr.Slot,{scope:e.__scopeMenu,children:o.modal?(0,$.jsx)(Yr,{...i,ref:t}):(0,$.jsx)(Xr,{...i,ref:t})})})})}),Yr=Q.forwardRef((e,t)=>{let n=Fr(Gr,e.__scopeMenu),r=Q.useRef(null),i=l(t,r);return Q.useEffect(()=>{let e=r.current;if(e)return le(e)},[]),(0,$.jsx)(Qr,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:q(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),Xr=Q.forwardRef((e,t)=>{let n=Fr(Gr,e.__scopeMenu);return(0,$.jsx)(Qr,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),Zr=d(`MenuContent.ScrollLock`),Qr=Q.forwardRef((e,t)=>{let{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:o,disableOutsidePointerEvents:s,onEntryFocus:c,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:m,disableOutsideScroll:h,...g}=e,_=Fr(Gr,n),v=Lr(Gr,n),y=Mr(n),b=Nr(n),x=Or(n),[S,w]=Q.useState(null),T=Q.useRef(null),E=l(t,T,_.onContentChange),D=Q.useRef(0),O=Q.useRef(``),ee=Q.useRef(0),k=Q.useRef(null),A=Q.useRef(`right`),j=Q.useRef(0),M=h?C:Q.Fragment,N=h?{as:Zr,allowPinchZoom:!0}:void 0,P=e=>{let t=O.current+e,n=x().filter(e=>!e.disabled),r=document.activeElement,i=n.find(e=>e.ref.current===r)?.textValue,a=Ii(n.map(e=>e.textValue),t,i),o=n.find(e=>e.textValue===a)?.ref.current;(function e(t){O.current=t,window.clearTimeout(D.current),t!==``&&(D.current=window.setTimeout(()=>e(``),1e3))})(t),o&&setTimeout(()=>o.focus())};Q.useEffect(()=>()=>window.clearTimeout(D.current),[]),te();let F=Q.useCallback(e=>A.current===k.current?.side&&Ri(e,k.current?.area),[]);return(0,$.jsx)(Kr,{scope:n,searchRef:O,onItemEnter:Q.useCallback(e=>{F(e)&&e.preventDefault()},[F]),onItemLeave:Q.useCallback(e=>{F(e)||(T.current?.focus(),w(null))},[F]),onTriggerLeave:Q.useCallback(e=>{F(e)&&e.preventDefault()},[F]),pointerGraceTimerRef:ee,onPointerGraceIntentChange:Q.useCallback(e=>{k.current=e},[]),children:(0,$.jsx)(M,{...N,children:(0,$.jsx)(U,{asChild:!0,trapped:i,onMountAutoFocus:q(a,e=>{e.preventDefault(),T.current?.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:(0,$.jsx)(H,{asChild:!0,disableOutsidePointerEvents:s,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:p,onDismiss:m,children:(0,$.jsx)(vr,{asChild:!0,...b,dir:v.dir,orientation:`vertical`,loop:r,currentTabStopId:S,onCurrentTabStopIdChange:w,onEntryFocus:q(c,e=>{v.isUsingKeyboardRef.current||e.preventDefault()}),preventScrollOnEntryFocus:!0,children:(0,$.jsx)(xe,{role:`menu`,"aria-orientation":`vertical`,"data-state":ji(_.open),"data-radix-menu-content":``,dir:v.dir,...y,...g,ref:E,style:{outline:`none`,...g.style},onKeyDown:q(g.onKeyDown,e=>{let t=e.target.closest(`[data-radix-menu-content]`)===e.currentTarget,n=e.ctrlKey||e.altKey||e.metaKey,r=e.key.length===1;t&&(e.key===`Tab`&&e.preventDefault(),!n&&r&&P(e.key));let i=T.current;if(e.target!==i||!Cr.includes(e.key))return;e.preventDefault();let a=x().filter(e=>!e.disabled).map(e=>e.ref.current);Sr.includes(e.key)&&a.reverse(),Pi(a)}),onBlur:q(e.onBlur,e=>{e.currentTarget.contains(e.target)||(window.clearTimeout(D.current),O.current=``)}),onPointerMove:q(e.onPointerMove,zi(e=>{let t=e.target,n=j.current!==e.clientX;e.currentTarget.contains(t)&&n&&(A.current=e.clientX>j.current?`right`:`left`,j.current=e.clientX)}))})})})})})})});Jr.displayName=Gr;var $r=`MenuGroup`,ei=Q.forwardRef((e,t)=>{let{__scopeMenu:n,...r}=e;return(0,$.jsx)(R.div,{role:`group`,...r,ref:t})});ei.displayName=$r;var ti=`MenuLabel`,ni=Q.forwardRef((e,t)=>{let{__scopeMenu:n,...r}=e;return(0,$.jsx)(R.div,{...r,ref:t})});ni.displayName=ti;var ri=`MenuItem`,ii=`menu.itemSelect`,ai=Q.forwardRef((e,t)=>{let{disabled:n=!1,onSelect:r,...i}=e,a=Q.useRef(null),o=Lr(ri,e.__scopeMenu),s=qr(ri,e.__scopeMenu),c=l(t,a),u=Q.useRef(!1),d=()=>{let e=a.current;if(!n&&e){let t=new CustomEvent(ii,{bubbles:!0,cancelable:!0});e.addEventListener(ii,e=>r?.(e),{once:!0}),m(e,t),t.defaultPrevented?u.current=!1:o.onClose()}};return(0,$.jsx)(oi,{...i,ref:c,disabled:n,onClick:q(e.onClick,d),onPointerDown:t=>{e.onPointerDown?.(t),u.current=!0},onPointerUp:q(e.onPointerUp,e=>{u.current||e.currentTarget?.click()}),onKeyDown:q(e.onKeyDown,e=>{let t=s.searchRef.current!==``;n||t&&e.key===` `||br.includes(e.key)&&(e.currentTarget.click(),e.preventDefault())})})});ai.displayName=ri;var oi=Q.forwardRef((e,t)=>{let{__scopeMenu:n,disabled:r=!1,textValue:i,...a}=e,o=qr(ri,n),s=Nr(n),c=Q.useRef(null),u=l(t,c),[d,f]=Q.useState(!1),[p,m]=Q.useState(``);return Q.useEffect(()=>{let e=c.current;e&&m((e.textContent??``).trim())},[a.children]),(0,$.jsx)(Dr.ItemSlot,{scope:n,disabled:r,textValue:i??p,children:(0,$.jsx)(yr,{asChild:!0,...s,focusable:!r,children:(0,$.jsx)(R.div,{role:`menuitem`,"data-highlighted":d?``:void 0,"aria-disabled":r||void 0,"data-disabled":r?``:void 0,...a,ref:u,onPointerMove:q(e.onPointerMove,zi(e=>{r?o.onItemLeave(e):(o.onItemEnter(e),e.defaultPrevented||e.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:q(e.onPointerLeave,zi(e=>o.onItemLeave(e))),onFocus:q(e.onFocus,()=>f(!0)),onBlur:q(e.onBlur,()=>f(!1))})})})}),si=`MenuCheckboxItem`,ci=Q.forwardRef((e,t)=>{let{checked:n=!1,onCheckedChange:r,...i}=e;return(0,$.jsx)(gi,{scope:e.__scopeMenu,checked:n,children:(0,$.jsx)(ai,{role:`menuitemcheckbox`,"aria-checked":Mi(n)?`mixed`:n,...i,ref:t,"data-state":Ni(n),onSelect:q(i.onSelect,()=>r?.(Mi(n)?!0:!n),{checkForDefaultPrevented:!1})})})});ci.displayName=si;var li=`MenuRadioGroup`,[ui,di]=Ar(li,{value:void 0,onValueChange:()=>{}}),fi=Q.forwardRef((e,t)=>{let{value:n,onValueChange:r,...i}=e,a=G(r);return(0,$.jsx)(ui,{scope:e.__scopeMenu,value:n,onValueChange:a,children:(0,$.jsx)(ei,{...i,ref:t})})});fi.displayName=li;var pi=`MenuRadioItem`,mi=Q.forwardRef((e,t)=>{let{value:n,...r}=e,i=di(pi,e.__scopeMenu),a=n===i.value;return(0,$.jsx)(gi,{scope:e.__scopeMenu,checked:a,children:(0,$.jsx)(ai,{role:`menuitemradio`,"aria-checked":a,...r,ref:t,"data-state":Ni(a),onSelect:q(r.onSelect,()=>i.onValueChange?.(n),{checkForDefaultPrevented:!1})})})});mi.displayName=pi;var hi=`MenuItemIndicator`,[gi,_i]=Ar(hi,{checked:!1}),vi=Q.forwardRef((e,t)=>{let{__scopeMenu:n,forceMount:r,...i}=e,a=_i(hi,n);return(0,$.jsx)(Fe,{present:r||Mi(a.checked)||a.checked===!0,children:(0,$.jsx)(R.span,{...i,ref:t,"data-state":Ni(a.checked)})})});vi.displayName=hi;var yi=`MenuSeparator`,bi=Q.forwardRef((e,t)=>{let{__scopeMenu:n,...r}=e;return(0,$.jsx)(R.div,{role:`separator`,"aria-orientation":`horizontal`,...r,ref:t})});bi.displayName=yi;var xi=`MenuArrow`,Si=Q.forwardRef((e,t)=>{let{__scopeMenu:n,...r}=e,i=Mr(n);return(0,$.jsx)(ye,{...i,...r,ref:t})});Si.displayName=xi;var Ci=`MenuSub`,[wi,Ti]=Ar(Ci),Ei=e=>{let{__scopeMenu:t,children:n,open:r=!1,onOpenChange:i}=e,a=Fr(Ci,t),o=Mr(t),[s,c]=Q.useState(null),[l,u]=Q.useState(null),d=G(i);return Q.useEffect(()=>(a.open===!1&&d(!1),()=>d(!1)),[a.open,d]),(0,$.jsx)(Pe,{...o,children:(0,$.jsx)(Pr,{scope:t,open:r,onOpenChange:d,content:l,onContentChange:u,children:(0,$.jsx)(wi,{scope:t,contentId:Y(),triggerId:Y(),trigger:s,onTriggerChange:c,children:n})})})};Ei.displayName=Ci;var Di=`MenuSubTrigger`,Oi=Q.forwardRef((e,t)=>{let n=Fr(Di,e.__scopeMenu),r=Lr(Di,e.__scopeMenu),i=Ti(Di,e.__scopeMenu),o=qr(Di,e.__scopeMenu),s=Q.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:l}=o,u={__scopeMenu:e.__scopeMenu},d=Q.useCallback(()=>{s.current&&window.clearTimeout(s.current),s.current=null},[]);return Q.useEffect(()=>d,[d]),Q.useEffect(()=>{let e=c.current;return()=>{window.clearTimeout(e),l(null)}},[c,l]),(0,$.jsx)(Br,{asChild:!0,...u,children:(0,$.jsx)(oi,{id:i.triggerId,"aria-haspopup":`menu`,"aria-expanded":n.open,"aria-controls":n.open?i.contentId:void 0,"data-state":ji(n.open),...e,ref:a(t,i.onTriggerChange),onClick:t=>{e.onClick?.(t),!(e.disabled||t.defaultPrevented)&&(t.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:q(e.onPointerMove,zi(t=>{o.onItemEnter(t),!t.defaultPrevented&&!e.disabled&&!n.open&&!s.current&&(o.onPointerGraceIntentChange(null),s.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:q(e.onPointerLeave,zi(e=>{d();let t=n.content?.getBoundingClientRect();if(t){let r=n.content?.dataset.side,i=r===`right`,a=i?-5:5,s=t[i?`left`:`right`],l=t[i?`right`:`left`];o.onPointerGraceIntentChange({area:[{x:e.clientX+a,y:e.clientY},{x:s,y:t.top},{x:l,y:t.top},{x:l,y:t.bottom},{x:s,y:t.bottom}],side:r}),window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.onPointerGraceIntentChange(null),300)}else{if(o.onTriggerLeave(e),e.defaultPrevented)return;o.onPointerGraceIntentChange(null)}})),onKeyDown:q(e.onKeyDown,t=>{let i=o.searchRef.current!==``;e.disabled||i&&t.key===` `||wr[r.dir].includes(t.key)&&(n.onOpenChange(!0),n.content?.focus(),t.preventDefault())})})})});Oi.displayName=Di;var ki=`MenuSubContent`,Ai=Q.forwardRef((e,t)=>{let n=Ur(Gr,e.__scopeMenu),{forceMount:r=n.forceMount,align:i=`start`,...a}=e,o=Fr(Gr,e.__scopeMenu),s=Lr(Gr,e.__scopeMenu),c=Ti(ki,e.__scopeMenu),u=Q.useRef(null),d=l(t,u);return(0,$.jsx)(Dr.Provider,{scope:e.__scopeMenu,children:(0,$.jsx)(Fe,{present:r||o.open,children:(0,$.jsx)(Dr.Slot,{scope:e.__scopeMenu,children:(0,$.jsx)(Qr,{id:c.contentId,"aria-labelledby":c.triggerId,...a,ref:d,align:i,side:s.dir===`rtl`?`left`:`right`,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:e=>{s.isUsingKeyboardRef.current&&u.current?.focus(),e.preventDefault()},onCloseAutoFocus:e=>e.preventDefault(),onFocusOutside:q(e.onFocusOutside,e=>{e.target!==c.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:q(e.onEscapeKeyDown,e=>{s.onClose(),e.preventDefault()}),onKeyDown:q(e.onKeyDown,e=>{let t=e.currentTarget.contains(e.target),n=Tr[s.dir].includes(e.key);t&&n&&(o.onOpenChange(!1),c.trigger?.focus(),e.preventDefault())})})})})})});Ai.displayName=ki;function ji(e){return e?`open`:`closed`}function Mi(e){return e===`indeterminate`}function Ni(e){return Mi(e)?`indeterminate`:e?`checked`:`unchecked`}function Pi(e){let t=document.activeElement;for(let n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function Fi(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function Ii(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=Fi(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}function Li(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let o=t[e],s=t[a],c=o.x,l=o.y,u=s.x,d=s.y;l>r!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}function Ri(e,t){return t?Li({x:e.clientX,y:e.clientY},t):!1}function zi(e){return t=>t.pointerType===`mouse`?e(t):void 0}var Bi=Rr,Vi=Br,Hi=Wr,Ui=Jr,Wi=ei,Gi=ni,Ki=ai,qi=ci,Ji=fi,Yi=mi,Xi=vi,Zi=bi,Qi=Si,$i=Oi,ea=Ai,ta=`DropdownMenu`,[na,ra]=Me(ta,[jr]),ia=jr(),[aa,oa]=na(ta),sa=e=>{let{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:a,onOpenChange:o,modal:s=!0}=e,c=ia(t),l=Q.useRef(null),[u,d]=be({prop:i,defaultProp:a??!1,onChange:o,caller:ta});return(0,$.jsx)(aa,{scope:t,triggerId:Y(),triggerRef:l,contentId:Y(),open:u,onOpenChange:d,onOpenToggle:Q.useCallback(()=>d(e=>!e),[d]),modal:s,children:(0,$.jsx)(Bi,{...c,open:u,onOpenChange:d,dir:r,modal:s,children:n})})};sa.displayName=ta;var ca=`DropdownMenuTrigger`,la=Q.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,o=oa(ca,n),s=ia(n);return(0,$.jsx)(Vi,{asChild:!0,...s,children:(0,$.jsx)(R.button,{type:`button`,id:o.triggerId,"aria-haspopup":`menu`,"aria-expanded":o.open,"aria-controls":o.open?o.contentId:void 0,"data-state":o.open?`open`:`closed`,"data-disabled":r?``:void 0,disabled:r,...i,ref:a(t,o.triggerRef),onPointerDown:q(e.onPointerDown,e=>{!r&&e.button===0&&e.ctrlKey===!1&&(o.onOpenToggle(),o.open||e.preventDefault())}),onKeyDown:q(e.onKeyDown,e=>{r||([`Enter`,` `].includes(e.key)&&o.onOpenToggle(),e.key===`ArrowDown`&&o.onOpenChange(!0),[`Enter`,` `,`ArrowDown`].includes(e.key)&&e.preventDefault())})})})});la.displayName=ca;var ua=`DropdownMenuPortal`,da=e=>{let{__scopeDropdownMenu:t,...n}=e,r=ia(t);return(0,$.jsx)(Hi,{...r,...n})};da.displayName=ua;var fa=`DropdownMenuContent`,pa=Q.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=oa(fa,n),a=ia(n),o=Q.useRef(!1);return(0,$.jsx)(Ui,{id:i.contentId,"aria-labelledby":i.triggerId,...a,...r,ref:t,onCloseAutoFocus:q(e.onCloseAutoFocus,e=>{o.current||i.triggerRef.current?.focus(),o.current=!1,e.preventDefault()}),onInteractOutside:q(e.onInteractOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0,r=t.button===2||n;(!i.modal||r)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-dropdown-menu-content-available-width":`var(--radix-popper-available-width)`,"--radix-dropdown-menu-content-available-height":`var(--radix-popper-available-height)`,"--radix-dropdown-menu-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-dropdown-menu-trigger-height":`var(--radix-popper-anchor-height)`}})});pa.displayName=fa;var ma=`DropdownMenuGroup`,ha=Q.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=ia(n);return(0,$.jsx)(Wi,{...i,...r,ref:t})});ha.displayName=ma;var ga=`DropdownMenuLabel`,_a=Q.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=ia(n);return(0,$.jsx)(Gi,{...i,...r,ref:t})});_a.displayName=ga;var va=`DropdownMenuItem`,ya=Q.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=ia(n);return(0,$.jsx)(Ki,{...i,...r,ref:t})});ya.displayName=va;var ba=`DropdownMenuCheckboxItem`,xa=Q.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=ia(n);return(0,$.jsx)(qi,{...i,...r,ref:t})});xa.displayName=ba;var Sa=`DropdownMenuRadioGroup`,Ca=Q.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=ia(n);return(0,$.jsx)(Ji,{...i,...r,ref:t})});Ca.displayName=Sa;var wa=`DropdownMenuRadioItem`,Ta=Q.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=ia(n);return(0,$.jsx)(Yi,{...i,...r,ref:t})});Ta.displayName=wa;var Ea=`DropdownMenuItemIndicator`,Da=Q.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=ia(n);return(0,$.jsx)(Xi,{...i,...r,ref:t})});Da.displayName=Ea;var Oa=`DropdownMenuSeparator`,ka=Q.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=ia(n);return(0,$.jsx)(Zi,{...i,...r,ref:t})});ka.displayName=Oa;var Aa=`DropdownMenuArrow`,ja=Q.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=ia(n);return(0,$.jsx)(Qi,{...i,...r,ref:t})});ja.displayName=Aa;var Ma=`DropdownMenuSubTrigger`,Na=Q.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=ia(n);return(0,$.jsx)($i,{...i,...r,ref:t})});Na.displayName=Ma;var Pa=`DropdownMenuSubContent`,Fa=Q.forwardRef((e,t)=>{let{__scopeDropdownMenu:n,...r}=e,i=ia(n);return(0,$.jsx)(ea,{...i,...r,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-dropdown-menu-content-available-width":`var(--radix-popper-available-width)`,"--radix-dropdown-menu-content-available-height":`var(--radix-popper-available-height)`,"--radix-dropdown-menu-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-dropdown-menu-trigger-height":`var(--radix-popper-anchor-height)`}})});Fa.displayName=Pa;var Ia=sa,La=la,Ra=da,za=pa,Ba=ya;function Va(e){return(0,$.jsx)(Ia,{"data-slot":`dropdown-menu`,...e})}function Ha(e){return(0,$.jsx)(La,{"data-slot":`dropdown-menu-trigger`,...e})}function Ua({className:e,sideOffset:t=4,...n}){return(0,$.jsx)(Ra,{children:(0,$.jsx)(za,{"data-slot":`dropdown-menu-content`,sideOffset:t,className:c(`bg-popover text-popover-foreground 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 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md`,e),...n})})}function Wa({className:e,inset:t,variant:n=`default`,...r}){return(0,$.jsx)(Ba,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:c(`focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,e),...r})}function Ga({chat:e,active:t,unread:n=!1,onSelect:r,onRename:i,onDelete:a,onTogglePin:o}){let[s,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(e.title??``),f=(0,Q.useRef)(null),p=(0,Q.useId)();(0,Q.useEffect)(()=>{s&&(d(e.title??``),requestAnimationFrame(()=>{f.current?.focus(),f.current?.select()}))},[s,e.title]);let m=()=>{let t=u.trim();l(!1),t&&t!==(e.title??``)&&i(t)};return s?(0,$.jsx)(`div`,{className:`mb-0.5 px-2 py-1`,children:(0,$.jsx)(`input`,{ref:f,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&l(!1)},onBlur:m,className:`w-full rounded-md border bg-background px-2 py-1.5 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring`})}):(0,$.jsxs)(`div`,{className:c(`group/row relative mb-0.5 flex items-center rounded-md transition-colors hover:bg-sidebar-accent`,t&&`bg-sidebar-accent`),children:[(0,$.jsxs)(`button`,{onClick:r,"aria-describedby":n?p:void 0,className:c(`flex min-w-0 flex-1 items-center gap-2 py-2 pl-2 pr-1 text-left text-sm`,(t||n)&&`font-medium`),children:[e.isRunning?(0,$.jsx)(`span`,{className:`size-1.5 shrink-0 animate-pulse rounded-full bg-primary`}):n?(0,$.jsx)(`span`,{"aria-hidden":`true`,title:`有新消息`,className:`size-1.5 shrink-0 rounded-full bg-primary`}):(0,$.jsx)(`span`,{className:`size-1.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.title||`新会话`})]}),n&&(0,$.jsx)(`span`,{id:p,className:`sr-only`,children:`未读消息`}),(0,$.jsxs)(Va,{children:[(0,$.jsx)(Ha,{"aria-label":`会话操作`,className:c(`mr-1 shrink-0 rounded p-1 text-muted-foreground outline-none transition-opacity hover:bg-accent hover:text-foreground`,`opacity-100 data-[state=open]:opacity-100 md:opacity-0 md:group-hover/row:opacity-100`),children:(0,$.jsx)(Je,{className:`size-4`})}),(0,$.jsxs)(Ua,{align:`end`,className:`min-w-32 rounded-xl`,children:[(0,$.jsx)(Wa,{onClick:o,className:`gap-2 rounded-lg px-2.5 py-1.5`,children:e.pinned?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Tt,{className:`size-3.5`}),` 取消置顶`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Et,{className:`size-3.5`}),` 置顶`]})}),(0,$.jsxs)(Wa,{onClick:()=>l(!0),className:`gap-2 rounded-lg px-2.5 py-1.5`,children:[(0,$.jsx)(A,{className:`size-3.5`}),` 重命名`]}),(0,$.jsxs)(Wa,{onClick:()=>{K.regenerateSessionTitle(e.id).catch(()=>{})},className:`gap-2 rounded-lg px-2.5 py-1.5`,children:[(0,$.jsx)(Xe,{className:`size-3.5`}),` AI 生成标题`]}),(0,$.jsxs)(Wa,{variant:`destructive`,onClick:a,className:`gap-2 rounded-lg px-2.5 py-1.5`,children:[(0,$.jsx)(E,{className:`size-3.5`}),` 删除`]})]})]})]})}function Ka(e){let t=e.lastActivityAt??e.updatedAt;if(t){let e=Date.parse(t);if(!Number.isNaN(e))return e}return typeof e.createdAt==`number`?e.createdAt:0}var qa=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`;function Ja(e,t){let n=new Date(e),r=new Date(t.getFullYear(),t.getMonth(),t.getDate()-1);return qa(n)===qa(t)?`今天`:qa(n)===qa(r)?`昨天`:n.getFullYear()===t.getFullYear()?`${n.getMonth()+1}月${n.getDate()}日`:`${n.getFullYear()}年${n.getMonth()+1}月${n.getDate()}日`}function Ya(e,t){let n=e.filter(e=>e.pinned),r=[...e.filter(e=>!e.pinned)].sort((e,t)=>Ka(t)-Ka(e)),i=new Map;for(let e of r){let n=Ka(e),r=qa(new Date(n)),a=i.get(r);a?a.chats.push(e):i.set(r,{key:r,label:Ja(n,t),chats:[e]})}let a=[];return n.length&&a.push({key:`__pinned`,label:`置顶`,chats:n}),a.push(...i.values()),a}function Xa({open:e,onClose:t,collapsed:n,onToggleCollapse:r,width:i,chats:a,booted:o,currentSessionId:s,onNewChat:l,onSelect:d,onRename:f,onDelete:p,onTogglePin:m,onOpenSettings:h}){let[g,_]=(0,Q.useState)(``),v=Zn(),y=(0,Q.useId)(),b=g.trim().toLowerCase(),x=(0,Q.useMemo)(()=>Ya(a.filter(e=>!e.parentSessionId),new Date),[a]),S=x.filter(e=>e.key!==`__pinned`),C=S.slice(5),T=S.find(e=>e.chats.some(e=>e.id===s)),E=C.some(e=>e.key===T?.key),D=JSON.stringify([s??null,T?.key,E]),[O,ee]=(0,Q.useState)(()=>({activePath:D,olderExpanded:E,closedDates:new Set}));if(O.activePath!==D){let e=new Set(O.closedDates);T&&e.delete(T.key),ee({activePath:D,olderExpanded:O.olderExpanded||E,closedDates:e})}let k=b?x.map(e=>({...e,chats:e.chats.filter(e=>(e.title||``).toLowerCase().includes(b))})).filter(e=>e.chats.length>0):x.filter(e=>e.key===`__pinned`||!C.includes(e)),te=C.reduce((e,t)=>e+t.chats.length,0),A=e=>{let n=e.key===`__pinned`,r=n||!!b||!O.closedDates.has(e.key),i=`${y}-${e.key}`;return(0,$.jsxs)(`div`,{className:`mb-1`,children:[n?(0,$.jsx)(`div`,{className:`px-2 pt-3 pb-1 text-xs font-medium text-muted-foreground`,children:e.label}):(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":r,"aria-controls":i,disabled:!!b,className:`flex w-full items-center gap-1 rounded-md px-2 pt-3 pb-1 text-left text-xs font-medium text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-default`,onClick:()=>ee(t=>{let n=new Set(t.closedDates);return n.has(e.key)?n.delete(e.key):n.add(e.key),{...t,closedDates:n}}),children:[(0,$.jsx)(W,{"aria-hidden":`true`,className:c(`size-3 shrink-0`,r&&`rotate-90`)}),(0,$.jsx)(`span`,{children:e.label}),(0,$.jsxs)(`span`,{className:`ml-auto whitespace-nowrap pl-2 font-normal`,children:[e.chats.length,` 个会话`]})]}),(0,$.jsx)(`div`,{id:i,hidden:!r,children:r?e.chats.map(e=>(0,$.jsx)(Ga,{chat:e,active:e.id===s,unread:e.id!==s&&Un(e,v),onSelect:()=>{d(e.id),t()},onRename:t=>f(e.id,t),onDelete:()=>p(e),onTogglePin:()=>m(e)},e.id)):null})]},e.key)};return(0,$.jsxs)($.Fragment,{children:[e&&(0,$.jsx)(`button`,{className:`fixed inset-0 z-40 bg-black/50 md:hidden`,"aria-label":`Close menu`,onClick:t}),(0,$.jsxs)(`aside`,{style:{"--sidebar-w":`${i}px`},className:c(`fixed inset-y-0 left-0 z-50 flex w-[84%] max-w-xs flex-col border-r bg-sidebar text-sidebar-foreground transition-transform md:static md:w-[var(--sidebar-w)] md:max-w-none md:translate-x-0`,e?`translate-x-0`:`-translate-x-full`,n&&`md:hidden`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-3`,children:[(0,$.jsx)(`span`,{className:`flex-1 text-sm font-semibold`,children:`会话`}),(0,$.jsx)(u,{size:`icon`,variant:`ghost`,className:`hidden size-8 text-muted-foreground md:inline-flex`,"aria-label":`收起侧栏`,onClick:r,children:(0,$.jsx)(Ye,{className:`size-4`})}),(0,$.jsxs)(u,{size:`sm`,variant:`secondary`,onClick:()=>{l(),t()},children:[(0,$.jsx)(w,{}),` 新建`]})]}),(0,$.jsx)(`div`,{className:`px-3 pb-2`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(V,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(M,{value:g,onChange:e=>_(e.target.value),placeholder:`搜索会话`,className:`py-1.5 pl-8 pr-7`}),g?(0,$.jsx)(`button`,{onClick:()=>_(``),"aria-label":`清除`,className:`absolute right-1.5 top-1/2 -translate-y-1/2 rounded p-0.5 text-muted-foreground hover:text-foreground`,children:(0,$.jsx)(B,{className:`size-3.5`})}):null]})}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-2 pb-3`,children:[a.length===0&&(0,$.jsx)(`p`,{className:`px-2 py-4 text-xs text-muted-foreground`,children:o?`暂无会话`:`加载中…`}),k.map(A),!b&&C.length>0?(0,$.jsxs)(`div`,{className:`mb-1`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":O.olderExpanded,"aria-controls":`${y}-older`,className:`mt-2 flex w-full items-center gap-1 rounded-md px-2 py-2 text-left text-xs font-medium text-muted-foreground outline-none hover:bg-sidebar-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring`,onClick:()=>ee(e=>({...e,olderExpanded:!e.olderExpanded})),children:[(0,$.jsx)(W,{"aria-hidden":`true`,className:c(`size-3 shrink-0`,O.olderExpanded&&`rotate-90`)}),(0,$.jsx)(`span`,{children:`更早`}),(0,$.jsxs)(`span`,{className:`ml-auto whitespace-nowrap pl-2 font-normal`,children:[C.length,` 天 · `,te,` 个会话`]})]}),(0,$.jsx)(`div`,{id:`${y}-older`,hidden:!O.olderExpanded,children:O.olderExpanded?C.map(A):null})]}):null]}),(0,$.jsx)(`div`,{className:`border-t p-2`,children:(0,$.jsxs)(u,{variant:`ghost`,className:`w-full justify-start gap-2`,onClick:()=>{h(),t()},children:[(0,$.jsx)(st,{className:`size-4`}),` 系统设置`]})})]})]})}function Za({pending:e,onCancel:t,onConfirm:n}){return(0,$.jsx)(P,{open:!!e,onOpenChange:e=>{e||t()},children:(0,$.jsxs)(I,{showCloseButton:!1,className:`p-5`,children:[(0,$.jsx)(D,{children:`删除会话`}),(0,$.jsxs)(`p`,{className:`mt-2 text-sm leading-relaxed text-muted-foreground`,children:[`确定删除「`,e?.title,`」?此操作无法撤销。`]}),(0,$.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,$.jsx)(u,{variant:`secondary`,onClick:t,children:`取消`}),(0,$.jsx)(u,{variant:`destructive`,onClick:()=>{e&&n(e.id)},children:`删除`})]})]})})}function Qa({q:e,onAnswer:t,loading:n=!1,submitting:r=!1,unavailable:i=!1,error:a=null,canRetry:o=!1,onRefresh:s,onRetry:c}){let l=e.interaction_kind===`permission`?e.permission_request:null,d=JSON.stringify([e.interaction_kind,e.tool_call_id,l?.request_generation]),[f,p]=(0,Q.useState)({identity:d,text:``}),m=f.identity===d?f.text:``,h=n||r||i||o,g=l?[{value:`allow_once`,label:`仅本次允许`},{value:`deny_once`,label:`仅本次拒绝`}].filter(e=>l.allowed_decisions.includes(e.value)):e.options.map(e=>({value:e,label:e}));return(0,$.jsx)(P,{open:!0,children:(0,$.jsxs)(I,{dismissable:!1,showCloseButton:!1,className:`p-5`,children:[(0,$.jsx)(D,{children:l?`需要操作授权`:`需要你确认`}),(0,$.jsx)(x,{className:`mt-2 whitespace-pre-wrap text-sm leading-relaxed text-foreground`,children:e.question}),(0,$.jsx)(`div`,{className:`mt-4 flex flex-col gap-2`,children:g.map(e=>(0,$.jsx)(u,{variant:`secondary`,className:`h-auto justify-start whitespace-normal py-2 text-left`,disabled:h,onClick:()=>t(e.value),children:e.label},e.value))}),!l&&e.allow_custom?(0,$.jsxs)(`div`,{className:`mt-3`,children:[(0,$.jsx)(Oe,{value:m,disabled:h,onChange:e=>p({identity:d,text:e.target.value}),placeholder:`或输入自定义回答…`,rows:2,className:`rounded-lg border px-3 py-2`}),(0,$.jsx)(u,{className:`mt-2 w-full`,disabled:h||!m.trim(),onClick:()=>t(m.trim()),children:`提交回答`})]}):null,r||n?(0,$.jsx)(`p`,{role:`status`,className:`mt-3 text-sm text-muted-foreground`,children:r?`正在提交…`:`正在刷新…`}):null,a?(0,$.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-destructive`,children:a}):null,l&&g.length===0?(0,$.jsx)(`p`,{className:`mt-3 text-sm text-muted-foreground`,children:`当前没有可用的本次操作选项,请刷新请求。`}):null,(0,$.jsxs)(`div`,{className:`mt-3 flex gap-2`,children:[(0,$.jsx)(u,{variant:`outline`,disabled:n||r,onClick:s,children:`刷新请求`}),o?(0,$.jsx)(u,{variant:`secondary`,disabled:n||r,onClick:c,children:`重试上次提交`}):null]})]})})}function $a({a:e,onRespond:t}){return(0,$.jsx)(P,{open:!0,children:(0,$.jsxs)(I,{dismissable:!1,showCloseButton:!1,className:`p-5`,children:[(0,$.jsx)(D,{children:`子代理请求授权`}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:`子代理请求执行需要批准的操作。`}),(0,$.jsxs)(`div`,{className:`mt-3 space-y-1 rounded-lg border p-3 text-sm`,children:[e.toolName?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`工具:`}),` `,e.toolName]}):null,e.permission?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`权限:`}),` `,e.permission]}):null,e.resource?(0,$.jsxs)(`div`,{className:`break-all`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`资源:`}),` `,e.resource]}):null]}),(0,$.jsxs)(`div`,{className:`mt-4 flex gap-2`,children:[(0,$.jsx)(u,{variant:`secondary`,className:`flex-1`,onClick:()=>t(!1),children:`拒绝`}),(0,$.jsx)(u,{className:`flex-1`,onClick:()=>t(!0),children:`批准`})]})]})})}function eo(e){return e===`user`?`用户`:e===`assistant`?`助手`:e===`system`?`系统`:e}function to(e){return`content`in e&&typeof e.content==`string`?e.content:``}function no(e,t){let n=[`# ${t}`,``];for(let t of e){let e=to(t);e&&n.push(`## ${eo(t.role)}`,``,e,``)}return n.join(`
|
|
6
|
+
`)}function ro(e,t){let n=no(e,t||`chat`),r=new Blob([n],{type:`text/markdown;charset=utf-8`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=`${t||`chat`}.md`,a.click(),URL.revokeObjectURL(i)}function io(){let e=document.createElement(`div`);e.style.position=`fixed`,e.style.inset=`0`,e.style.zIndex=`2147483647`,e.style.background=`rgba(0,0,0,0.35)`,e.style.display=`flex`,e.style.alignItems=`center`,e.style.justifyContent=`center`,e.style.fontFamily=`system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif`,e.style.fontSize=`14px`;let t=document.createElement(`div`);t.style.background=`#fff`,t.style.color=`#111`,t.style.border=`1px solid rgba(0,0,0,0.12)`,t.style.borderRadius=`10px`,t.style.padding=`12px 16px`,t.style.maxWidth=`80vw`,t.style.boxShadow=`0 8px 24px rgba(0,0,0,0.12)`,t.textContent=`正在导出 PDF…`,e.appendChild(t),document.body.appendChild(e);let n=!1,r=()=>{n||(n=!0,e.remove())};return{remove:r,fail(n){t.textContent=n,t.style.color=`#dc2626`,e.style.cursor=`pointer`,e.addEventListener(`click`,r),window.setTimeout(r,6e3)}}}async function ao(e,t){if(typeof document>`u`)return;let n=io();try{let{renderConversationPdf:r}=await i(async()=>{let{renderConversationPdf:e}=await import(`./renderPdf-DbvJnEQL.js`);return{renderConversationPdf:e}},__vite__mapDeps([8,1,2,3,4,9,10,11,12,13]),import.meta.url);await r(no(e,t||`chat`),t||`chat`),n.remove()}catch(e){console.error(`PDF export failed:`,e),n.fail(`导出 PDF 失败:${e instanceof Error?e.message:String(e)}`)}}function oo(e){let[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)(null),a=(0,Q.useRef)(!0),o=(0,Q.useRef)(0),[s,c]=(0,Q.useState)(!0),l=(0,Q.useCallback)(()=>{!t||!a.current||(t.scrollTo({top:t.scrollHeight,behavior:`instant`}),o.current=t.scrollTop,c(!0))},[t]),u=()=>{t&&(t.scrollHeight-t.scrollTop-t.clientHeight<=2?a.current=!0:t.scrollTop<o.current-1&&(a.current=!1),o.current=t.scrollTop,c(a.current))},d=()=>{a.current=!0,l()};return(0,Q.useLayoutEffect)(()=>{if(a.current=!0,c(!0),l(),!t||!r)return;let e=new ResizeObserver(l);return e.observe(r),e.observe(t),()=>e.disconnect()},[t,r,e,l]),{scrollRef:n,contentRef:i,atBottom:s,handleScroll:u,scrollToBottom:d,pinToBottom:d}}function so(e){switch(e){case`ssh`:return se;case`docker`:return ct;default:return Ie}}function co({placement:e,compact:t,className:n}){if(!e||!e.host)return null;let{kind:r,host:i}=e,a=r!==`local`,o=so(r);return(0,$.jsxs)(Re,{variant:`outline`,title:`运行于 ${r} · ${i}`,className:c(`max-w-full gap-1 font-normal text-muted-foreground`,a&&`border-transparent bg-blue-500/15 text-blue-600 dark:text-blue-400`,n),children:[(0,$.jsx)(o,{}),t?null:(0,$.jsx)(`span`,{className:`opacity-65`,children:`机器`}),(0,$.jsx)(`span`,{className:`truncate`,children:`${r} · ${i}`})]})}function lo({models:e,value:t,onChange:n,menuPlacement:r=`up`,menuAlign:i=`left`}){return e.length===0?null:(0,$.jsxs)(Va,{children:[(0,$.jsxs)(Ha,{className:`inline-flex max-w-[70vw] items-center gap-1 rounded-full border bg-card px-3 py-1 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:ring-[3px] focus-visible:ring-ring/50 md:max-w-xs`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:t||`选择模型`}),(0,$.jsx)(ue,{className:`size-3 shrink-0 opacity-60`})]}),(0,$.jsx)(Ua,{side:r===`up`?`top`:`bottom`,align:i===`right`?`end`:`start`,className:`max-h-72 w-72 max-w-[90vw] overflow-y-auto rounded-2xl`,children:e.map(e=>(0,$.jsxs)(Wa,{onClick:()=>n(e),className:`gap-2 rounded-xl px-3 py-2`,children:[(0,$.jsx)(de,{className:c(`size-4 shrink-0 text-primary`,e===t?`opacity-100`:`opacity-0`)}),(0,$.jsx)(`span`,{className:c(`truncate`,e===t&&`font-medium`),children:e})]},e))})]})}var uo=[{value:`low`,label:`低`},{value:`medium`,label:`中`},{value:`high`,label:`高`},{value:`xhigh`,label:`极高`},{value:`max`,label:`最大`}];function fo({value:e,onChange:t,menuPlacement:n=`down`,menuAlign:r=`right`}){let i=uo.find(t=>t.value===e)?.label??`中`;return(0,$.jsxs)(Va,{children:[(0,$.jsxs)(Ha,{"aria-label":`推理强度`,className:`inline-flex items-center gap-1 rounded-full border bg-card px-2.5 py-1 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:ring-[3px] focus-visible:ring-ring/50`,children:[(0,$.jsx)(gt,{className:`size-3.5 shrink-0 opacity-70`}),(0,$.jsx)(`span`,{children:i})]}),(0,$.jsx)(Ua,{side:n===`up`?`top`:`bottom`,align:r===`right`?`end`:`start`,className:`max-h-72 w-36 overflow-y-auto rounded-2xl`,children:uo.map(n=>(0,$.jsxs)(Wa,{onClick:()=>t(n.value),className:`gap-2 rounded-xl px-3 py-2`,children:[(0,$.jsx)(de,{className:c(`size-4 shrink-0 text-primary`,n.value===e?`opacity-100`:`opacity-0`)}),(0,$.jsx)(`span`,{className:c(`truncate`,n.value===e&&`font-medium`),children:n.label})]},n.value))})]})}function po({items:e}){return e.length===0?null:(0,$.jsxs)(Va,{children:[(0,$.jsx)(Ha,{"aria-label":`更多`,className:`inline-flex size-9 items-center justify-center rounded-md text-muted-foreground transition-colors outline-none hover:bg-accent hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50`,children:(0,$.jsx)(Je,{className:`size-5`})}),(0,$.jsx)(Ua,{align:`end`,className:`min-w-44 rounded-2xl`,children:e.map((e,t)=>(0,$.jsxs)(Wa,{onClick:e.onClick,className:`gap-2.5 rounded-xl px-3 py-2`,children:[e.icon,(0,$.jsx)(`span`,{children:e.label})]},t))})]})}function mo({totalTokens:e,maxContextTokens:t,onClick:n}){if(!t)return null;let r=Math.min(100,Math.round(e/t*100)),i=2*Math.PI*7,a=r>85?`text-destructive`:r>65?`text-amber-500`:`text-primary`;return(0,$.jsxs)(`button`,{onClick:n,className:`flex items-center gap-1.5`,title:`上下文 ${e.toLocaleString()} / ${t.toLocaleString()} tokens (${r}%)`,"aria-label":`上下文用量`,children:[(0,$.jsxs)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 18 18`,className:`-rotate-90`,children:[(0,$.jsx)(`circle`,{cx:`9`,cy:`9`,r:`7`,fill:`none`,strokeWidth:`2.5`,className:`stroke-muted`}),(0,$.jsx)(`circle`,{cx:`9`,cy:`9`,r:`7`,fill:`none`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeDasharray:i,strokeDashoffset:i*(1-r/100),className:c(`stroke-current transition-all`,a)})]}),(0,$.jsxs)(`span`,{className:`hidden text-xs tabular-nums text-muted-foreground sm:inline`,children:[r,`%`]})]})}function ho({title:e,hasSession:t,tokenUsage:n,reasoningEffort:r,onChangeReasoning:i,models:a,activeModel:o,onChangeModel:s,overflowItems:l,onOpenSidebar:d,onOpenInspector:f,sidebarCollapsed:p}){let m=J(v(e=>e.currentSessionId?e.chats.find(t=>t.id===e.currentSessionId)?.placement??null:null));return(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2.5`,children:[(0,$.jsx)(u,{size:`icon`,variant:`ghost`,className:c(`md:hidden`,p&&`md:inline-flex`),"aria-label":`菜单`,onClick:d,children:(0,$.jsx)(bt,{})}),(0,$.jsx)(`span`,{className:`flex-1 truncate text-sm font-semibold`,children:e}),m&&m.kind!==`local`?(0,$.jsx)(co,{placement:m,compact:!0,className:`max-w-36 shrink-0`}):null,n?(0,$.jsx)(mo,{totalTokens:n.totalTokens,maxContextTokens:n.maxContextTokens,onClick:f}):null,(0,$.jsx)(fo,{value:r,onChange:i,menuPlacement:`down`,menuAlign:`right`}),a.length>0?(0,$.jsx)(lo,{models:o&&!a.includes(o)?[o,...a]:a,value:o,onChange:s,menuPlacement:`down`,menuAlign:`right`}):null,(0,$.jsx)(po,{items:l}),t?(0,$.jsx)(u,{size:`icon`,variant:`ghost`,"aria-label":`检查器`,onClick:f,children:(0,$.jsx)(Ct,{})}):null]})}var go={plus:(0,$.jsx)(w,{className:`size-4`}),code:(0,$.jsx)(ot,{className:`size-4`}),wrench:(0,$.jsx)(jt,{className:`size-4`}),gitCompare:(0,$.jsx)(_t,{className:`size-4`}),bug:(0,$.jsx)(o,{className:`size-4`}),helpCircle:(0,$.jsx)(Z,{className:`size-4`}),barChart:(0,$.jsx)(Ke,{className:`size-4`}),network:(0,$.jsx)(St,{className:`size-4`}),fileSearch:(0,$.jsx)(ft,{className:`size-4`}),fileText:(0,$.jsx)(pt,{className:`size-4`}),bookOpen:(0,$.jsx)($e,{className:`size-4`}),clock:(0,$.jsx)(at,{className:`size-4`}),search:(0,$.jsx)(V,{className:`size-4`})};function _o(e){if(!e)return``;let t=typeof e==`number`?e:Date.parse(e);if(!Number.isFinite(t))return``;let n=Date.now()-t;return n<6e4?`刚刚`:n<36e5?`${Math.floor(n/6e4)} 分钟前`:n<864e5?`${Math.floor(n/36e5)} 小时前`:`${Math.floor(n/864e5)} 天前`}function vo({chat:e,onOpen:t}){return(0,$.jsxs)(`button`,{onClick:t,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-sm transition-colors hover:bg-accent`,children:[e.isRunning?(0,$.jsx)(ne,{className:`size-3.5 shrink-0 animate-spin text-primary`}):e.pinned?(0,$.jsx)(Et,{className:`size-3.5 shrink-0 text-muted-foreground`}):(0,$.jsx)(xt,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.title||`新会话`}),(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:_o(e.lastActivityAt??e.updatedAt)})]})}function yo({chats:e,onOpenSession:t,onPickTemplate:n}){let[r,i]=(0,Q.useState)(``),a=(0,Q.useMemo)(()=>e.filter(e=>e.isRunning).slice(0,5),[e]),o=(0,Q.useMemo)(()=>e.filter(e=>e.pinned&&!e.isRunning).slice(0,5),[e]),s=(0,Q.useMemo)(()=>e.filter(e=>!e.isRunning&&!e.pinned&&!e.parentSessionId).slice(0,5),[e]),l=r.trim().toLowerCase(),u=l?Dn.filter(e=>e.title.toLowerCase().includes(l)||e.description.toLowerCase().includes(l)):Dn,d=fn.map(e=>({cat:e,items:u.filter(t=>t.category===e)})).filter(e=>e.items.length>0),f=e=>{An(e.baseSystemPrompt??null),n(e.prefill)},p=[{label:`运行中`,items:a},{label:`置顶`,items:o},{label:`最近`,items:s}].filter(e=>e.items.length>0);return(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,$.jsxs)(`div`,{className:`mx-auto max-w-2xl px-4 py-6`,children:[(0,$.jsxs)(`div`,{className:`mb-5 flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`size-9 rounded-xl bg-primary`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-base font-semibold`,children:`开始新任务`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`选择一个模板,或直接在下方输入。`})]})]}),p.length>0?(0,$.jsx)(`div`,{className:`mb-5 grid gap-3 sm:grid-cols-2`,children:p.map(e=>(0,$.jsxs)(`section`,{className:`rounded-lg border p-2`,children:[(0,$.jsx)(`div`,{className:`mb-1 px-1 text-xs font-medium text-muted-foreground`,children:e.label}),e.items.map(e=>(0,$.jsx)(vo,{chat:e,onOpen:()=>t(e.id)},e.id))]},e.label))}):null,(0,$.jsx)(`div`,{className:`mb-3`,children:(0,$.jsx)(M,{value:r,onChange:e=>i(e.target.value),placeholder:`搜索模板…`,className:`h-9`})}),d.map(({cat:e,items:t})=>(0,$.jsxs)(`section`,{className:`mb-4`,children:[(0,$.jsx)(`div`,{className:`mb-1.5 text-xs font-medium text-muted-foreground`,children:pn[e]}),(0,$.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:t.map(e=>(0,$.jsxs)(`button`,{onClick:()=>f(e),className:c(`flex items-start gap-2.5 rounded-lg border bg-card p-3 text-left transition-colors hover:bg-accent`),children:[(0,$.jsx)(`span`,{className:`mt-0.5 shrink-0 text-primary`,children:go[e.icon]??go.plus}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block text-sm font-medium`,children:e.title}),(0,$.jsx)(`span`,{className:`mt-0.5 line-clamp-2 block text-xs leading-relaxed text-muted-foreground`,children:e.description})]})]},e.id))})]},e)),d.length===0?(0,$.jsx)(`p`,{className:`py-8 text-center text-xs text-muted-foreground`,children:`没有匹配的模板`}):null]})})}var bo=(0,Q.lazy)(()=>i(()=>import(`./StreamdownMarkdown-CiLy0KJD.js`).then(e=>({default:e.StreamdownMarkdown})),__vite__mapDeps([14,1,2,3,4,10,11,15,6,16,5]),import.meta.url));function xo({children:e,isStreaming:t}){return(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{"aria-busy":t||void 0,className:`whitespace-pre-wrap text-sm leading-relaxed [overflow-wrap:anywhere]`,"data-assistant-markdown-fallback":`true`,children:e}),children:(0,$.jsx)(bo,{isStreaming:t,children:e})})}var So=(0,Q.lazy)(()=>i(()=>import(`./Markdown-DBG0vWxL.js`).then(e=>({default:e.Markdown})),__vite__mapDeps([17,1,2,3,4,10,11,5,6]),import.meta.url));function Co({children:e}){return(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`whitespace-pre-wrap text-sm leading-relaxed`,children:e}),children:(0,$.jsx)(So,{children:e})})}function wo({name:e,body:t}){let[n,r]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{className:`my-1.5`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`inline-flex max-w-full items-center gap-1.5 rounded-full bg-muted/60 px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted`,children:[(0,$.jsx)(yt,{className:`size-3 shrink-0`}),(0,$.jsxs)(`span`,{className:`truncate`,children:[`内置工具 · `,e]}),(0,$.jsx)(W,{className:c(`size-3 shrink-0 transition-transform`,n&&`rotate-90`)})]}),n?(0,$.jsx)(`div`,{className:`mt-1.5 overflow-x-auto rounded-lg border bg-card/50 p-2.5 text-xs`,children:(0,$.jsx)(Co,{children:t})}):null]})}var To=/(?:\*\*)?\s*🌐?\s*(?:Z\.ai\s+)?Built-in Tool[::]\s*([A-Za-z0-9_]+)\s*(?:\*\*)?[\s\S]*?\*\*Output:\*\*[\s\S]*?(?=\n\n|$)/,Eo=/(?:\*\*\s*🌐?\s*(?:Z\.ai\s+)?|🌐\s*(?:Z\.ai\s+)?|Z\.ai\s+)Built-in Tool[::]\s*([A-Za-z0-9_]+)\s*(?:\*\*)?/,Do=/(?:^|\n)(?:\*\*\s*🌐?\s*(?:Z\.ai\s+)?|🌐\s*(?:Z\.ai\s+)?|Z\.ai\s+)([^\n]*)/g;function Oo(e){Do.lastIndex=0;for(let t of e.matchAll(Do)){let n=t[1].trim().replace(/\*\*\s*$/,``).trimEnd().replace(`:`,`:`).toLowerCase(),r=`built-in tool:`.startsWith(n),i=/^built-in tool:\s*[a-z0-9_]*$/i.test(n);if(!r&&!i)continue;let a=(t.index??0)+ +!!t[0].startsWith(`
|
|
7
|
+
`),o=e.slice(a).match(Eo);return{index:a,name:o?.index===0?o[1]:void 0}}return null}function ko({children:e,isStreaming:t=!1}){let n=e,r=n.match(To);if(!r||r.index===void 0){let e=t?Oo(n):null;if(e){let t=n.slice(0,e.index).trimEnd(),r=e.name?`内置工具 ${e.name} 正在运行`:`内置工具正在启动`;return(0,$.jsxs)($.Fragment,{children:[t?(0,$.jsx)(xo,{isStreaming:!1,children:t}):null,(0,$.jsx)(`div`,{"aria-label":r,className:`my-1.5 inline-flex max-w-full items-center rounded-full bg-muted/60 px-2.5 py-1 text-xs text-muted-foreground`,"data-provider-tool-state":`streaming`,role:`status`,children:(0,$.jsx)(`span`,{className:`truncate`,children:e.name?`内置工具 · ${e.name}`:`内置工具 · 正在启动`})})]})}return(0,$.jsx)(xo,{isStreaming:t,children:n})}let i=n.slice(0,r.index).trimEnd(),a=n.slice(r.index+r[0].length).replace(/^\n+/,``);return(0,$.jsxs)($.Fragment,{children:[i?(0,$.jsx)(xo,{isStreaming:!1,children:i}):null,(0,$.jsx)(wo,{name:r[1],body:r[0].trim()}),a?(0,$.jsx)(ko,{isStreaming:t,children:a}):null]})}function Ao({text:e,active:t=!1,spaced:n=!1}){let[r,i]=(0,Q.useState)(!1),a=(0,Q.useId)();return(0,$.jsxs)(`div`,{className:c((r||n)&&`mb-1.5`),children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":r,"aria-controls":a,onClick:()=>i(e=>!e),className:`inline-flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground`,children:[(0,$.jsx)(nt,{className:c(`size-3`,t&&`animate-pulse`)}),(0,$.jsx)(`span`,{children:t?`思考中…`:`思考过程`}),(0,$.jsx)(W,{className:c(`size-3 transition-transform`,r&&`rotate-90`)})]}),r?(0,$.jsx)(`div`,{id:a,tabIndex:0,role:`region`,"aria-label":t?`正在生成的思考过程`:`思考过程`,className:`mt-1 max-h-32 overflow-y-auto overscroll-contain whitespace-pre-wrap border-l-2 border-border pl-2.5 text-xs leading-relaxed text-muted-foreground [overflow-wrap:anywhere]`,children:e}):null]})}function jo(e){let t;try{t=JSON.parse(e)}catch{return null}if(t&&typeof t==`object`&&typeof t.bash_id==`string`&&t.status===`running`&&typeof t.command==`string`&&t.command.length>0){let e=t;return{bashId:e.bash_id,command:e.command}}return null}var Mo=new Set([`environment`,`env`,`cwd`,`import_shell`,`path_env`]),No=[`command`,`query`,`file_path`,`path`,`pattern`,`url`,`content`,`prompt`,`description`,`action`];function Po(e){if(!e)return{rest:[]};let t=No.find(t=>typeof e[t]==`string`&&e[t]),n=t?String(e[t]):void 0,r=[];for(let[n,i]of Object.entries(e)){if(n===t||Mo.has(n)||i==null||i===``||i===!1)continue;let e=typeof i==`string`?i:JSON.stringify(i);r.push([n,e.length>60?e.slice(0,60)+`…`:e])}return{primary:n,rest:r}}function Fo(e){let t=e.trim();if(t.startsWith(`{`)||t.startsWith(`[`))try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))for(let t of Mo)delete e[t];return JSON.stringify(e,null,2)}catch{}return e}function Io(e){let t=[],n=new Map;for(let r of e){let e=r.type;if(e===`tool_call`){let e=r.toolCalls??[];for(let n of e)t.push({id:n.toolCallId,toolName:n.toolName,params:n.parameters})}else if(e===`tool_result`){let e=r;e.toolCallId&&n.set(e.toolCallId,{text:typeof e.result?.result==`string`?e.result.result:``,isError:!!e.isError})}}return t.map(e=>{let t=n.get(e.id),r=t?jo(t.text):null;return{toolName:e.toolName,params:e.params,result:t,background:r??void 0}})}function Lo({bashId:e}){let t=ve(e);if(!t)return(0,$.jsxs)(Re,{variant:`warning`,children:[(0,$.jsx)(ne,{className:`size-3 animate-spin`}),ae.t(`chat.tools.runningInBackground`)]});let{status:n,exitCode:r}=t,i=r==null?``:` · exit ${r}`;return n===`completed`&&(r===0||r==null)?(0,$.jsxs)(Re,{variant:`success`,children:[ae.t(`chat.tools.backgroundCompleted`),i]}):n===`killed`?(0,$.jsx)(Re,{variant:`secondary`,children:ae.t(`chat.tools.backgroundKilled`)}):(0,$.jsxs)(Re,{variant:`destructive`,children:[ae.t(`chat.tools.backgroundFailed`),i]})}function Ro({e}){let{primary:t,rest:n}=Po(e.params),r=e.result?.text?It(e.result.text):null,i=e.result?.text?Fo(e.result.text):``;return(0,$.jsxs)(`div`,{className:`rounded-md bg-background/40 px-2.5 py-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:e.toolName}),e.result?.isError?(0,$.jsx)(`span`,{className:`text-[10px] text-destructive`,children:`出错`}):null,e.background?(0,$.jsx)(Lo,{bashId:e.background.bashId}):null]}),t?(0,$.jsx)(`div`,{className:`mt-1 line-clamp-3 break-all rounded bg-muted/50 px-2 py-1 font-mono text-[11px] text-foreground [overflow-wrap:anywhere]`,children:t}):null,n.length>0?(0,$.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-x-3 gap-y-0.5 text-[11px] text-muted-foreground`,children:n.map(([e,t])=>(0,$.jsxs)(`span`,{children:[(0,$.jsxs)(`span`,{className:`opacity-60`,children:[e,`:`]}),` `,t]},e))}):null,r?(0,$.jsx)(`div`,{className:`mt-1.5`,children:(0,$.jsx)(Yt,{payload:r})}):i?(0,$.jsxs)(`details`,{className:`mt-1.5`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer select-none text-[11px] text-muted-foreground hover:text-foreground`,children:`结果`}),(0,$.jsx)(`pre`,{className:`mt-1 max-h-44 overflow-auto whitespace-pre-wrap break-all rounded bg-background/60 p-2 text-[11px] text-muted-foreground`,children:i.length>1e3?i.slice(0,1e3)+`…`:i})]}):null]})}function zo({items:e,active:t}){let[n,r]=(0,Q.useState)(!!t),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{i||r(!!t)},[t,i]);let l=Io(e),u=Array.from(new Set(l.map(e=>e.toolName).filter(Boolean))),d=u.length===0?`${e.length} 次工具调用`:u.length<=2?u.join(`、`):`${u.slice(0,2).join(`、`)} 等 ${u.length} 个工具`,f=o?l:l.slice(-3),p=l.length-f.length;return(0,$.jsx)(`div`,{className:`flex justify-start`,children:(0,$.jsxs)(`div`,{className:`w-full max-w-[85%]`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{a(!0),r(e=>!e)},className:`inline-flex max-w-full items-center gap-1.5 rounded-full bg-muted/60 px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted`,children:[t?(0,$.jsx)(ne,{className:`size-3 shrink-0 animate-spin`}):(0,$.jsx)(jt,{className:`size-3 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:d}),(0,$.jsx)(W,{className:c(`size-3 shrink-0 transition-transform`,n&&`rotate-90`)})]}),n?(0,$.jsxs)(`div`,{className:`mt-1.5 space-y-2 rounded-lg border bg-card/50 p-2.5 text-xs`,children:[p>0?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`text-[11px] text-muted-foreground underline-offset-2 hover:underline`,children:[`▸ 展开更早的 `,p,` 个调用`]}):null,f.map((e,t)=>(0,$.jsx)(Ro,{e},t))]}):null]})})}function Bo({text:e,spaced:t}){return(0,$.jsx)(Ao,{text:e,active:!0,spaced:t})}function Vo(e){let t=(e.status||``).toLowerCase();return e.error||t.includes(`error`)||t.includes(`fail`)?`error`:t.includes(`complet`)||t.includes(`done`)||t.includes(`success`)||t.includes(`finish`)?`done`:`running`}var Ho={running:`运行中`,done:`完成`,error:`失败`};function Uo({child:e,onOpen:t}){let n=Vo(e),r=e.error||e.outputPreview,i=e.placement??null;return(0,$.jsxs)(`button`,{onClick:t,disabled:!t,className:c(`w-full overflow-hidden rounded-lg border text-left transition-colors`,t&&`hover:border-primary/50 hover:bg-accent/50`,n===`running`?`border-primary/40 bg-primary/5`:`bg-muted/30`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[n===`running`?(0,$.jsx)(ne,{className:`size-3.5 shrink-0 animate-spin text-primary`}):n===`error`?(0,$.jsx)(h,{className:`size-3.5 shrink-0 text-destructive`}):(0,$.jsx)(de,{className:`size-3.5 shrink-0 text-emerald-500`}),(0,$.jsx)(tt,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:e.title||`子代理`}),(0,$.jsx)(co,{placement:i,compact:!0,className:`max-w-32 shrink-0`}),(0,$.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:[Ho[n],typeof e.roundCount==`number`?` · ${e.roundCount}轮`:``]}),t?(0,$.jsx)(W,{className:`size-4 shrink-0 text-muted-foreground`}):null]}),r?(0,$.jsx)(`div`,{className:c(`line-clamp-2 whitespace-pre-wrap border-t px-3 py-1.5 text-xs leading-relaxed [overflow-wrap:anywhere]`,e.error?`text-destructive`:`text-muted-foreground`),children:r}):null]})}function Wo({agents:e,onOpen:t}){let n=Object.entries(e);return n.length===0?null:(0,$.jsx)(`div`,{className:`flex justify-start`,children:(0,$.jsxs)(`div`,{className:`ml-1 w-full max-w-[85%] space-y-1.5 border-l-2 border-border/60 pl-3`,children:[(0,$.jsxs)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:[`子代理 (`,n.length,`)`]}),n.map(([e,n])=>(0,$.jsx)(Uo,{child:n,onOpen:t?()=>t(e):void 0},e))]})})}function Go(e){let t=[];for(let n of e.calls)t.push({id:`live-call-${n.toolCallId}`,role:`assistant`,type:`tool_call`,toolCalls:[{toolCallId:n.toolCallId,toolName:n.toolName,parameters:n.args??{}}],createdAt:``}),(n.output||n.status!==`running`)&&t.push({id:`live-res-${n.toolCallId}`,role:`tool`,type:`tool_result`,toolCallId:n.toolCallId,isError:n.status===`error`,result:{result:n.status===`error`&&n.error||n.output},createdAt:``});return t}function Ko(e){return`content`in e&&typeof e.content==`string`?e.content:`displayText`in e&&typeof e.displayText==`string`?e.displayText:``}function qo(e){let t=e.type;return t===`tool_call`||t===`tool_result`}function Jo(e){let t=e.metadata?.reasoning;return typeof t==`string`?t:``}function Yo(e){let t=[];for(let n of e)if(n.role!==`system`)if(qo(n)){let e=t[t.length-1];e&&e.kind===`tools`?e.items.push(n):t.push({kind:`tools`,items:[n]})}else t.push({kind:`msg`,m:n});return t}function Xo({scrollRef:e,contentRef:t,onScroll:n,messages:r,mergedSubAgents:i,sending:a,streaming:o,streamingReasoning:s,liveSegments:l,streamStatus:d,pendingUserText:f,forking:m,onSelectSubAgent:h,onPreviewImage:g,onRegenerate:_,onFork:v,onDelete:y,onEditMessage:b}){let[x,S]=(0,Q.useState)(null),C=(0,Q.useMemo)(()=>Yo(r),[r]),w=(0,Q.useMemo)(()=>{if(Object.keys(i).length===0)return-1;for(let e=C.length-1;e>=0;--e){let t=C[e];if(t.kind===`tools`&&t.items.some(e=>e.toolCalls?.some(e=>/task|sub.?agent|spawn/i.test(e.toolName||``))))return e}return-1},[C,i]);return(0,$.jsx)(`div`,{ref:e,onScroll:n,className:`min-h-0 flex-1 overflow-y-auto`,children:(0,$.jsxs)(`div`,{ref:t,className:`mx-auto flex max-w-2xl flex-col gap-4 px-3 py-4`,children:[r.length===0&&!o&&!f&&l.length===0&&(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-20 text-center`,children:[(0,$.jsx)(`div`,{className:`size-10 rounded-xl bg-primary`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`开始一段新对话`})]}),C.map((e,t)=>{if(e.kind===`tools`){let n=t===C.length-1,r=(0,$.jsx)(zo,{items:e.items,active:n&&(a||o!==null)},e.items[0]?.id??`tools-${t}`);return t===w?(0,$.jsxs)(Q.Fragment,{children:[r,(0,$.jsx)(Wo,{agents:i,onOpen:h})]},`spawn-${t}`):r}let n=e.m,r=Ko(n),s=n.images,l=n.role===`user`,d=l?``:Jo(n);return!r.trim()&&!s?.length&&!d?null:l&&x?.id===n.id?(0,$.jsx)(`div`,{className:`flex flex-col items-end`,children:(0,$.jsxs)(`div`,{className:`w-full max-w-[85%]`,children:[(0,$.jsx)(Oe,{value:x.text,onChange:e=>S({id:n.id,text:e.target.value}),onKeyDown:e=>{e.key===`Escape`&&S(null),e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(b(n.id,x.text),S(null))},autoFocus:!0,className:`min-h-16 bg-card`}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex justify-end gap-2`,children:[(0,$.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>S(null),children:`取消`}),(0,$.jsx)(u,{size:`sm`,onClick:()=>{b(n.id,x.text),S(null)},children:`保存并重发`})]})]})},n.id):(0,$.jsxs)(`div`,{className:c(`group flex flex-col`,l?`items-end`:`items-start`),children:[(0,$.jsxs)(`div`,{className:c(`max-w-[85%] overflow-hidden rounded-2xl px-3.5 py-2 text-sm leading-relaxed [overflow-wrap:anywhere]`,l?`whitespace-pre-wrap bg-primary text-primary-foreground`:`bg-muted text-foreground`),children:[s?.length?(0,$.jsx)(`div`,{className:`mb-1.5 flex flex-wrap gap-1.5`,children:s.map((e,t)=>{let n=e.url||`data:${e.type||`image/png`};base64,${e.base64}`;return(0,$.jsx)(`img`,{src:n,alt:``,className:`max-h-48 cursor-zoom-in rounded-xl transition-opacity hover:opacity-90`,onClick:()=>g(n)},t)})}):null,d?(0,$.jsx)(Ao,{text:d}):null,l?r:r.trim()?(0,$.jsx)(ko,{isStreaming:!1,children:r}):null]}),(0,$.jsxs)(`div`,{className:`mt-1 flex gap-0.5 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100`,children:[(0,$.jsx)(`button`,{onClick:()=>void navigator.clipboard?.writeText(r),className:`rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground`,"aria-label":`复制`,children:(0,$.jsx)(k,{className:`size-3.5`})}),l?(0,$.jsx)(`button`,{onClick:()=>S({id:n.id,text:r}),className:`rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground`,"aria-label":`编辑`,title:`编辑并重发`,children:(0,$.jsx)(A,{className:`size-3.5`})}):(0,$.jsx)(`button`,{onClick:_,disabled:a,className:`rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-50`,"aria-label":`重新生成`,title:`重新生成`,children:(0,$.jsx)(p,{className:`size-3.5`})}),(0,$.jsx)(`button`,{onClick:()=>v(n.id),disabled:m,className:`rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-50`,"aria-label":`从这里分叉`,title:`从这里分叉成新会话`,children:(0,$.jsx)(vt,{className:`size-3.5`})}),(0,$.jsx)(`button`,{onClick:()=>y(n.id),className:`rounded p-1 text-muted-foreground hover:bg-accent hover:text-destructive`,"aria-label":`删除`,children:(0,$.jsx)(E,{className:`size-3.5`})})]})]},n.id)}),f?(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(`div`,{className:`max-w-[85%] overflow-hidden whitespace-pre-wrap rounded-2xl bg-primary px-3.5 py-2 text-sm leading-relaxed text-primary-foreground [overflow-wrap:anywhere]`,children:f})}):null,w===-1?(0,$.jsx)(Wo,{agents:i,onOpen:h}):null,l.map((e,t)=>e.kind===`tools`?(0,$.jsx)(zo,{items:Go(e),active:e.calls.some(e=>e.status===`running`)},`live-tools-${t}`):(0,$.jsx)(`div`,{className:`flex justify-start`,children:(0,$.jsxs)(`div`,{className:`max-w-[85%] overflow-hidden rounded-2xl bg-muted px-3.5 py-2 text-sm leading-relaxed [overflow-wrap:anywhere]`,children:[e.reasoning?(0,$.jsx)(Ao,{text:e.reasoning}):null,e.text.trim()?(0,$.jsx)(ko,{isStreaming:!1,children:e.text}):null]})},`live-text-${t}`)),o!==null&&(0,$.jsx)(`div`,{className:`flex justify-start`,children:(0,$.jsxs)(`div`,{className:`max-w-[85%] overflow-hidden rounded-2xl bg-muted px-3.5 py-2 text-sm leading-relaxed [overflow-wrap:anywhere]`,style:{transform:`translateZ(0)`},children:[s?(0,$.jsx)(Bo,{text:s,spaced:!!o}):null,o?(0,$.jsx)(ko,{isStreaming:!0,children:o}):s?null:d?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-muted-foreground`}),d]}):(0,$.jsxs)(`span`,{className:`inline-flex gap-1`,children:[(0,$.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-muted-foreground`}),(0,$.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-muted-foreground [animation-delay:150ms]`}),(0,$.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-muted-foreground [animation-delay:300ms]`})]})]})})]})})}var Zo=e=>`sessions/${encodeURIComponent(e)}/guidance`,Qo={imageUrl:(e,t)=>N.resolveUrl(`sessions/${encodeURIComponent(e)}/attachments/${encodeURIComponent(t)}`),list:e=>N.get(Zo(e)),send:(e,t,n,r=`after_round`,i=[])=>N.post(Zo(e),{id:t,text:n,mode:r,images:i}),cancel:(e,t)=>N.delete(`${Zo(e)}/${encodeURIComponent(t)}`)},$o=e=>`lotus-next.guidance-submission.${e}`,es=e=>`lotus-next.guidance-mode.${e}`;function ts(e){try{let t=JSON.parse(sessionStorage.getItem($o(e))??`null`);if(typeof t?.id==`string`&&typeof t?.fingerprint==`string`)return t}catch{}return null}function ns(e){try{if(e&&sessionStorage.getItem(es(e))===`after_run`)return`after_run`}catch{}return`after_round`}function rs(e,t){let[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)({sessionId:e,mode:ns(e)}),[u,d]=(0,Q.useState)(e&&ts(e)?e:null),f=(0,Q.useRef)(!1),p=(0,Q.useRef)(e);p.current=e;let m=(0,Q.useRef)(!0),h=(0,Q.useRef)(0),g=(0,Q.useRef)(new Map),_=c.sessionId===e?c.mode:ns(e),v=t=>{l({sessionId:e,mode:t});try{e&&sessionStorage.setItem(es(e),t)}catch{}},y=async e=>{let t=++h.current,n=await Qo.list(e);m.current&&p.current===e&&t===h.current&&r({sessionId:e,messages:n.messages})},b=()=>{++h.current};return(0,Q.useEffect)(()=>(m.current=!0,()=>{m.current=!1}),[]),(0,Q.useEffect)(()=>{if(!e)return;let n=!1,r,i=async()=>{try{await y(e)}catch{}n||(r=setTimeout(()=>void i(),t?1500:5e3))};return i(),()=>{n=!0,clearTimeout(r),b()}},[e,t]),{mode:_,setMode:v,send:async(t,n=[])=>{if(!e||!t.trim()&&!n.length)return{kind:`ignored`};if(f.current)return{kind:`busy`};f.current=!0;let r=e;s(r),a(null);try{let e=new TextEncoder().encode(JSON.stringify({text:t,images:n,mode:_})),i=Array.from(new Uint8Array(await crypto.subtle.digest(`SHA-256`,e)),e=>e.toString(16).padStart(2,`0`)).join(``),a=g.current.get(r)??ts(r),o=a?.fingerprint===i?a:{id:crypto.randomUUID(),fingerprint:i};g.current.set(r,o);try{sessionStorage.setItem($o(r),JSON.stringify(o))}catch{}if((await Qo.send(r,o.id,t,_,n)).id!==o.id)throw Error(`Queue acknowledgement identity mismatch`);g.current.delete(r);try{sessionStorage.removeItem($o(r))}catch{}if(m.current&&p.current===r){d(null);try{await y(r)}catch{}}return{kind:`accepted`,operationId:0,sessionId:r,navigated:!1}}catch{return m.current&&p.current===r&&(d(r),a({sessionId:r,text:`未能确认发送状态,文字和图片已保留;重试会沿用同一条消息。`})),{kind:`unconfirmed`,operationId:0}}finally{f.current=!1,m.current&&s(null)}},cancel:async t=>{if(!e||f.current)return;let n=e;f.current=!0,s(n),a(null);try{await Qo.cancel(n,t),++h.current,m.current&&p.current===n&&r(e=>e?.sessionId===n?{...e,messages:e.messages.filter(e=>e.id!==t)}:e)}catch{m.current&&p.current===n&&a({sessionId:n,text:`未能撤回,消息可能已经开始应用。`})}finally{f.current=!1,m.current&&s(null)}},pending:n?.sessionId===e?n.messages:[],error:i?.sessionId===e?i.text:null,busy:o!==null&&o===e,hasUnconfirmed:!!e&&(u===e||g.current.has(e)||!!ts(e))}}function is({sessionId:e,messages:t,busy:n,onCancel:r,onPreview:i}){return t.length?(0,$.jsxs)(`details`,{"aria-label":`待发送队列`,className:`group mx-auto mb-2 max-w-2xl rounded-lg border bg-card text-xs`,children:[(0,$.jsxs)(`summary`,{"aria-label":`待发 ${t.length} 条消息`,className:`cursor-pointer whitespace-nowrap rounded px-3 py-2 tabular-nums text-muted-foreground hover:bg-accent`,children:[`待发 `,t.length]}),(0,$.jsx)(`div`,{className:`max-h-[min(12rem,25dvh)] overflow-y-auto overscroll-contain border-t px-3 py-1`,children:t.map(t=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b py-2 last:border-0`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`mb-1 text-muted-foreground`,children:t.mode===`after_run`?`运行结束后`:`本轮结束后`}),t.text&&(0,$.jsx)(`div`,{className:`whitespace-pre-wrap break-words`,children:t.text}),!!t.images?.length&&(0,$.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:t.images.map((t,n)=>{let r=Qo.imageUrl(e,t);return(0,$.jsx)(`button`,{onClick:()=>i(r),"aria-label":`查看待发图片 ${n+1}`,children:(0,$.jsx)(`img`,{src:r,alt:`待发图片 ${n+1}`,className:`size-12 rounded border object-cover`})},`${t}-${n}`)})})]}),(0,$.jsx)(u,{size:`sm`,variant:`ghost`,disabled:n,onClick:()=>r(t.id),children:`撤回`})]},t.id))})]}):null}function as(e,t,n){let[r,i]=(0,Q.useState)(0),a=(0,Q.useRef)(e);a.current=e;let o=(0,Q.useRef)(t);o.current=t;let s=(0,Q.useRef)(n);s.current=n;let c=(0,Q.useRef)(r);return c.current=r,(0,Q.useEffect)(()=>{r>=e&&i(e>0?e-1:0)},[e,r]),(0,Q.useEffect)(()=>{let e=e=>{a.current!==0&&(e.isComposing||e.keyCode===229||e.target instanceof HTMLTextAreaElement&&(e.key===`ArrowDown`?(e.preventDefault(),e.stopPropagation(),i(e=>(e+1)%a.current)):e.key===`ArrowUp`?(e.preventDefault(),e.stopPropagation(),i(e=>(e-1+a.current)%a.current)):e.key===`Enter`&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey||e.key===`Tab`?(e.preventDefault(),e.stopPropagation(),o.current(c.current)):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),s.current?.())))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[]),r}function os({skills:e,workflows:t,query:n,onPick:r,onPickWorkflow:i,onPickGoal:a,onDismiss:o}){let s=n.trim().toLowerCase(),l=(e,t)=>!s||e.toLowerCase().includes(s)||t.toLowerCase().includes(s),u=[...a&&l(`goal`,`设置会话目标`)?[{kind:`goal`,id:`builtin-goal`,name:`goal`,description:`/goal 目标内容 · 单独发送 /goal 打开设置`}]:[],...e.filter(e=>l(e.name,e.description)).map(e=>({kind:`skill`,id:`skill-${e.id}`,name:e.name,description:e.description,skill:e})),...t.filter(e=>l(e.display_name||e.name,e.description)).map(e=>({kind:`workflow`,id:`workflow-${e.id}`,name:e.display_name||e.name,description:e.description,command:e}))].slice(0,8),d=e=>{e.kind===`skill`?r(e.skill):e.kind===`workflow`?i(e.command):a?.()},f=as(u.length,e=>{let t=u[e];t&&d(t)},o),p=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{p.current?.scrollIntoView({block:`nearest`})},[f]),u.length===0?null:(0,$.jsxs)(`div`,{className:`mx-auto mb-2 max-w-2xl overflow-hidden rounded-xl border bg-popover shadow-lg`,children:[(0,$.jsx)(`div`,{className:`border-b px-3 py-1.5 text-xs text-muted-foreground`,children:`指令 / 技能 / 工作流`}),(0,$.jsx)(`div`,{className:`max-h-64 overflow-y-auto p-1`,children:u.map((e,t)=>(0,$.jsxs)(`button`,{ref:t===f?p:void 0,onClick:()=>d(e),className:c(`flex w-full flex-col gap-0.5 rounded-lg px-3 py-2 text-left transition-colors hover:bg-accent`,t===f&&`bg-accent`),children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 text-sm font-medium`,children:[`/`,e.name,(0,$.jsx)(`span`,{className:c(`rounded-full px-1.5 py-0 text-[10px] font-normal`,e.kind===`workflow`?`bg-primary/15 text-primary`:`bg-muted text-muted-foreground`),children:e.kind===`goal`?`指令`:e.kind===`workflow`?`工作流`:`技能`})]}),e.description?(0,$.jsx)(`span`,{className:`line-clamp-1 text-xs text-muted-foreground`,children:e.description}):null]},e.id))})]})}function ss({files:e,query:t,onPick:n,onDismiss:r}){let i=t.trim().toLowerCase(),a=e.filter(e=>!e.is_directory&&(!i||e.path.toLowerCase().includes(i))).slice(0,8),o=as(a.length,e=>{let t=a[e];t&&n(t)},r),s=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{s.current?.scrollIntoView({block:`nearest`})},[o]),a.length===0?null:(0,$.jsxs)(`div`,{className:`mx-auto mb-2 max-w-2xl overflow-hidden rounded-xl border bg-popover shadow-lg`,children:[(0,$.jsx)(`div`,{className:`border-b px-3 py-1.5 text-xs text-muted-foreground`,children:`工作区文件`}),(0,$.jsx)(`div`,{className:`max-h-64 overflow-y-auto p-1`,children:a.map((e,t)=>(0,$.jsx)(`button`,{ref:t===o?s:void 0,onClick:()=>n(e),className:c(`block w-full truncate rounded-lg px-3 py-1.5 text-left text-sm transition-colors hover:bg-accent`,t===o&&`bg-accent`),children:e.path},e.path))})]})}function cs(){let e=J(v(e=>e.systemPrompts)),t=J(e=>e.lastSelectedPromptId),n=J(e=>e.setLastSelectedPromptId);if(e.length===0)return null;let r=e.find(e=>e.id===t);return(0,$.jsxs)(Va,{children:[(0,$.jsx)(Ha,{asChild:!0,children:(0,$.jsxs)(`button`,{className:`flex max-w-full items-center gap-1.5 rounded-full border bg-card px-2.5 py-1 text-xs text-muted-foreground hover:text-foreground`,title:r?`系统提示词:${r.name}`:`选择系统提示词`,children:[(0,$.jsx)(et,{className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:r?r.name:`默认提示词`}),(0,$.jsx)(ue,{className:`size-3 shrink-0 opacity-60`})]})}),(0,$.jsxs)(Ua,{align:`start`,children:[(0,$.jsxs)(Wa,{onClick:()=>n(``),children:[r?(0,$.jsx)(`span`,{className:`size-3.5`}):(0,$.jsx)(de,{className:`size-3.5`}),`默认提示词`]}),e.map(e=>(0,$.jsxs)(Wa,{onClick:()=>n(e.id),children:[r?.id===e.id?(0,$.jsx)(de,{className:`size-3.5`}):(0,$.jsx)(`span`,{className:`size-3.5`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))]})]})}function ls({draft:e,onDraftChange:t,onSubmit:n,onStop:r,sending:i,queueMode:a,onQueueModeChange:o,queueControls:s,submissionPending:c,inputRef:l,attachments:d,onAddFiles:f,onRemoveAttachment:p,onPreviewImage:m,selectedSkill:h,onClearSkill:g,onPickSkill:_,skills:v,workflows:y,selectedWorkflow:b,onClearWorkflow:x,onPickWorkflow:S,onPickGoal:C,slashQuery:w,atQuery:T,displayWorkspace:E,workspaceFiles:D,onPickFile:O,hasSession:ee,onOpenWorkspacePicker:k,onDismissMenus:te}){let A=(0,Q.useRef)(null),j=i&&!!o,M=!!e.trim()||d.length>0||!!b;return(0,$.jsxs)(`div`,{className:`shrink-0 border-t px-3 py-3`,children:[s,w!==null&&(0,$.jsx)(os,{skills:v,workflows:y,query:w,onPick:_,onPickWorkflow:S,onPickGoal:C,onDismiss:te}),w===null&&T!==null&&E?(0,$.jsx)(ss,{files:D,query:T,onPick:O,onDismiss:te}):null,h&&(0,$.jsx)(`div`,{className:`mx-auto mb-2 flex max-w-2xl`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/15 px-2.5 py-1 text-xs font-medium text-primary`,children:[`/`,h.name,(0,$.jsx)(`button`,{onClick:g,"aria-label":`移除技能`,className:`opacity-70 hover:opacity-100`,children:(0,$.jsx)(B,{className:`size-3`})})]})}),b&&(0,$.jsx)(`div`,{className:`mx-auto mb-2 flex max-w-2xl`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/15 px-2.5 py-1 text-xs font-medium text-primary`,children:[`工作流 /`,b.name,(0,$.jsx)(`button`,{onClick:x,"aria-label":`移除工作流`,className:`opacity-70 hover:opacity-100`,children:(0,$.jsx)(B,{className:`size-3`})})]})}),d.length>0&&(0,$.jsx)(`div`,{className:`mx-auto mb-2 flex max-w-2xl flex-wrap gap-2`,children:d.map(e=>(0,$.jsxs)(`div`,{className:`relative size-24 overflow-hidden rounded-2xl border`,children:[(0,$.jsx)(`img`,{src:e.url,alt:e.name,className:`size-full cursor-zoom-in object-cover transition-opacity hover:opacity-90`,onClick:()=>m(e.url)}),(0,$.jsx)(`button`,{onClick:()=>p(e.id),className:`absolute right-1 top-1 rounded-full bg-black/60 p-1 text-white transition-colors hover:bg-black/80`,"aria-label":`移除图片`,children:(0,$.jsx)(B,{className:`size-3.5`})})]},e.id))}),(0,$.jsx)(`input`,{ref:A,type:`file`,accept:`image/*`,multiple:!0,hidden:!0,onChange:e=>{e.target.files&&f(e.target.files),e.target.value=``}}),ee?null:(0,$.jsxs)(`div`,{className:`mx-auto mb-1.5 flex max-w-2xl items-center gap-1.5`,children:[(0,$.jsxs)(`button`,{onClick:k,className:`flex max-w-full items-center gap-1.5 rounded-full border bg-card px-2.5 py-1 text-xs text-muted-foreground hover:text-foreground`,title:E||`默认工作目录`,children:[(0,$.jsx)(mt,{className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:E?E.split(`/`).filter(Boolean).pop()||E:`选择工作目录`}),(0,$.jsx)(ue,{className:`size-3 shrink-0 opacity-60`})]}),(0,$.jsx)(cs,{})]}),(0,$.jsxs)(`div`,{className:`relative mx-auto flex max-w-2xl items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 rounded-2xl border bg-card px-2 py-1`,children:[(0,$.jsx)(u,{size:`icon`,variant:`ghost`,className:`size-8 shrink-0 text-muted-foreground`,"aria-label":`添加图片`,onClick:()=>A.current?.click(),children:(0,$.jsx)(wt,{className:`size-4`})}),(0,$.jsx)(Oe,{ref:l,value:e,"aria-label":`消息`,"aria-busy":c,onChange:e=>t(e.target.value),onPaste:e=>{let t=Array.from(e.clipboardData.files);t.length&&(e.preventDefault(),f(t))},onKeyDown:e=>{let t=e.nativeEvent;e.defaultPrevented||t.isComposing||t.keyCode===229||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),!c&&M&&(!i||j)&&n())},title:`Enter 发送,Shift+Enter 换行`,placeholder:j?`输入消息,发送后加入队列…`:`发送消息…`,rows:1,className:`max-h-40`}),j&&(0,$.jsxs)(`div`,{className:`relative h-8 w-8 shrink-0 sm:w-24`,children:[(0,$.jsx)(it,{"aria-hidden":`true`,className:`pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground sm:hidden`}),(0,$.jsxs)(`select`,{"aria-label":`发送时机`,value:a??`after_round`,disabled:c,onChange:e=>o?.(e.target.value),title:a===`after_run`?`运行结束后发送`:`本轮结束后发送`,className:`h-full w-full appearance-none rounded border-0 bg-transparent text-xs text-transparent sm:appearance-auto sm:text-foreground`,children:[(0,$.jsx)(`option`,{className:`text-foreground`,value:`after_round`,children:`本轮结束后`}),(0,$.jsx)(`option`,{className:`text-foreground`,value:`after_run`,children:`运行结束后`})]})]})]}),c?(0,$.jsx)(u,{size:`icon`,disabled:!0,"aria-label":`正在发送`,className:`rounded-full`,children:(0,$.jsx)(ne,{className:`animate-spin`})}):!i||j&&M?(0,$.jsx)(u,{size:`icon`,onClick:n,disabled:!M,className:`rounded-full`,"aria-label":j?`加入队列`:`发送消息`,title:j?`加入队列`:`发送消息`,children:(0,$.jsx)(Qe,{})}):null,i&&(!c||j)&&(0,$.jsx)(u,{size:`icon`,variant:`secondary`,onClick:r,className:`rounded-full`,"aria-label":`停止生成`,children:(0,$.jsx)(kt,{})})]})]})}function us({forking:e,toast:t}){return e?(0,$.jsx)(`div`,{className:`pointer-events-none fixed inset-x-0 bottom-28 z-[110] flex justify-center px-4`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-full border bg-card px-4 py-2 text-sm font-medium text-foreground shadow-xl animate-in fade-in slide-in-from-bottom-2`,children:[(0,$.jsx)(ne,{className:`size-4 animate-spin text-primary`}),`分叉中…`]})}):t?(0,$.jsx)(`div`,{className:`pointer-events-none fixed inset-x-0 bottom-28 z-[110] flex justify-center px-4`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-full border bg-card px-4 py-2 text-sm font-medium text-foreground shadow-xl animate-in fade-in slide-in-from-bottom-2`,children:[(0,$.jsx)(vt,{className:`size-4 text-primary`}),t]})}):null}function ds({src:e,onClose:t}){return e?(0,$.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center bg-black/85 p-4 sm:p-8`,onClick:t,children:[(0,$.jsx)(`img`,{src:e,alt:``,className:`max-h-full max-w-full rounded-xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()}),(0,$.jsx)(`button`,{onClick:t,className:`absolute right-4 top-4 rounded-full bg-white/15 p-2 text-white backdrop-blur transition-colors hover:bg-white/25`,"aria-label":`关闭预览`,children:(0,$.jsx)(B,{className:`size-5`})})]}):null}function fs(e){return(0,$.jsx)(j,{"data-slot":`dialog`,...e})}function ps(e){return(0,$.jsx)(T,{"data-slot":`dialog-portal`,...e})}function ms({className:e,...t}){return(0,$.jsx)(ce,{"data-slot":`dialog-overlay`,className:c(`data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50`,e),...t})}function hs({className:e,children:t,showCloseButton:n=!0,...r}){return(0,$.jsxs)(ps,{"data-slot":`dialog-portal`,children:[(0,$.jsx)(ms,{}),(0,$.jsxs)(Ge,{"data-slot":`dialog-content`,className:c(`bg-background 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 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg`,e),...r,children:[t,n&&(0,$.jsxs)(re,{"data-slot":`dialog-close`,className:`ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[(0,$.jsx)(B,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function gs({className:e,...t}){return(0,$.jsx)(`div`,{"data-slot":`dialog-header`,className:c(`flex flex-col gap-2 text-center sm:text-left`,e),...t})}function _s({className:e,...t}){return(0,$.jsx)(`div`,{"data-slot":`dialog-footer`,className:c(`flex flex-col-reverse gap-2 sm:flex-row sm:justify-end`,e),...t})}function vs({className:e,...t}){return(0,$.jsx)(z,{"data-slot":`dialog-title`,className:c(`text-lg leading-none font-semibold`,e),...t})}function ys({className:e,...t}){return(0,$.jsx)(_,{"data-slot":`dialog-description`,className:c(`text-muted-foreground text-sm`,e),...t})}function bs(e){return(0,$.jsx)(xs,{...e},e.sessionId)}function xs({sessionId:e,title:t}){let{t:n}=b(),r=(0,Q.useId)(),i=J(t=>t.chats.find(t=>t.id===e)?.config.permissionMode),a=J(t=>t.chats.find(t=>t.id===e)?.config.permissionModeEtag),o=J(t=>t.permissionModeRequests[e]),s=J(e=>e.refreshSessionPermissionMode),l=J(e=>e.changeSessionPermissionMode),d=!o,[f,p]=(0,Q.useState)(null),m=(0,Q.useRef)(null),h=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{d&&s(e)},[e,s,d]);let _=!!(g(i)&&De(a)!==null),v=o?.status===`ready`&&_,y=o?.status===`saving`,x=_&&(v||y),S=!o||o.status===`loading`||y,C=o?.status===`unsupported`?n(`chat.permissionMode.unavailable`):o?.status===`unconfirmed`?n(`chat.permissionMode.unconfirmed`):n(`chat.permissionMode.loading`);return(0,$.jsxs)(`section`,{className:`shrink-0 border-b px-3 py-2`,"aria-label":n(`chat.permissionMode.section`),children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:r,className:`text-xs font-medium`,children:n(`chat.permissionMode.label`)}),(0,$.jsxs)(`select`,{ref:m,id:r,"aria-label":n(`chat.permissionMode.label`),"aria-describedby":`${r}-help${o?.error?` ${r}-error`:``}`,disabled:!v,value:x?i:``,className:c(`h-9 max-w-full rounded-md border border-input bg-background px-2 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-70`,x&&i===`auto`&&`border-amber-500 text-amber-700 dark:text-amber-400`),onChange:t=>{let n=g(t.currentTarget.value);!v||!a||!n||n===i||(n===`auto`?p({etag:a}):l(e,n,a))},children:[(0,$.jsx)(`option`,{value:``,disabled:!0,children:C}),(0,$.jsx)(`option`,{value:`default`,children:`Default`}),(0,$.jsx)(`option`,{value:`bypass`,children:`Bypass`}),(0,$.jsx)(`option`,{value:`auto`,children:`Auto`})]}),(0,$.jsx)(`span`,{role:`status`,className:`text-xs text-muted-foreground`,children:y?n(`chat.permissionMode.saving`):S?n(`chat.permissionMode.loading`):null}),o?.error?(0,$.jsx)(u,{size:`sm`,variant:`ghost`,disabled:S,onClick:()=>void s(e),children:n(`chat.permissionMode.refresh`)}):null]}),(0,$.jsx)(`p`,{id:`${r}-help`,className:`mt-1.5 text-xs leading-relaxed text-muted-foreground`,children:n(x?`chat.permissionMode.help.${i}`:`chat.permissionMode.readRequired`)}),o?.error?(0,$.jsx)(`p`,{id:`${r}-error`,role:`alert`,className:`mt-1 text-xs leading-relaxed text-destructive`,children:n(`chat.permissionMode.errors.${o.error}`)}):null,(0,$.jsx)(fs,{open:!!(f&&f.etag===a),onOpenChange:e=>{e||p(null)},children:(0,$.jsxs)(hs,{onOpenAutoFocus:e=>{e.preventDefault(),h.current?.focus()},onCloseAutoFocus:e=>{e.preventDefault(),m.current?.focus()},children:[(0,$.jsxs)(gs,{children:[(0,$.jsxs)(vs,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Ot,{className:`size-5 shrink-0 text-amber-500`}),n(`chat.permissionMode.confirmTitle`)]}),(0,$.jsx)(ys,{className:`break-words`,children:n(`chat.permissionMode.confirmDescription`,{title:t})})]}),v?null:(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:n(`chat.permissionMode.readRequired`)}),(0,$.jsxs)(_s,{children:[(0,$.jsx)(u,{ref:h,variant:`outline`,onClick:()=>p(null),children:n(`chat.permissionMode.cancel`)}),(0,$.jsx)(u,{variant:`destructive`,disabled:!v,onClick:()=>{let t=f?.etag;!v||!t||t!==a||(p(null),l(e,`auto`,t))},children:n(`chat.permissionMode.confirm`)})]})]})})]})}function Ss(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let n=String(r.result),i=n.includes(`,`)?n.slice(n.indexOf(`,`)+1):n;t({id:`${e.name}-${e.size}-${n.length}`,base64:i,name:e.name,type:e.type,size:e.size,url:n})},r.onerror=()=>n(r.error),r.readAsDataURL(e)})}function Cs({chat:e,pickedWorkspace:t,onOpenWorkspacePicker:n,onOpenInspector:r,splitOpen:i,onToggleSplit:a,onOpenSidebar:o,sidebarCollapsed:s,secondary:c}){let{chats:l,currentSessionId:d,currentChat:f,messages:m,streaming:h,streamingReasoning:g,liveSegments:_,streamStatus:y,outputRate:b,pendingUserText:x,sending:S,submissionPending:C,select:w,send:T,stop:E,deleteMessage:D,fork:O,regenerate:ee,editMessage:k,retry:te,sendFailure:A,pendingQuestion:j,questionLoading:M,questionSubmitting:N,questionUnavailable:P,questionError:F,questionCanRetry:I,refreshQuestion:L,retryQuestion:R,pendingApproval:ne,answerQuestion:re,respondApproval:ie}=e,ae=S||f?.isRunning===!0,oe=rs(d,ae),z=Gt(`(min-width: 768px)`);Qn(!c||z?f:null);let se=J(e=>d?e.tokenUsages[d]:void 0),ce=d??(c?`__new_chat_pane2__`:``),le=J(e=>e.inputStates[ce]?.content??``),V=(0,Q.useRef)(null),H=(0,Q.useRef)(ce);H.current=ce;let U=e=>{let t=J.getState(),n=t.inputStates[ce]?.content??``;t.setInputContent(ce,typeof e==`function`?e(n):e)},[W,G]=(0,Q.useState)(!1),[de,fe]=(0,Q.useState)(!1),me=(0,Q.useRef)(!1),[he,ge]=(0,Q.useState)(null),[ve,ye]=(0,Q.useState)([]),[be,xe]=(0,Q.useState)(null),[Se,Ce]=(0,Q.useState)([]),Te=(0,Q.useRef)(0),Ee=(0,Q.useRef)(0),De=(0,Q.useRef)(0),Oe=e=>{Te.current+=1,Ce(e)},Ae=e=>{Ee.current+=1,ge(e)},Me=e=>{De.current+=1,xe(e)},[Ne,Pe]=(0,Q.useState)(null),[Fe,Ie]=(0,Q.useState)(null),[q,Re]=(0,Q.useState)(!1),Y=(0,Q.useRef)(null),X=e=>{Ie(e),Y.current&&clearTimeout(Y.current),Y.current=setTimeout(()=>Ie(null),2500)},{scrollRef:Be,contentRef:Ve,atBottom:We,handleScroll:Ge,scrollToBottom:Ke,pinToBottom:Z}=oo(d),Je=async e=>{let t=Array.from(e).filter(e=>e.type.startsWith(`image/`));if(t.length===0)return;let n=await Promise.all(t.map(Ss));Oe(e=>[...e,...n])},Ye=J(v(e=>e.skills)),Xe=J(v(e=>ke(d)(e))),Ze=(0,Q.useMemo)(()=>{let e={};for(let t of l)d&&t.parentSessionId===d&&(e[t.id]={title:t.title||t.subagentType||void 0,status:t.isRunning?`running`:`completed`});for(let[t,n]of Object.entries(Xe))e[t]={...e[t],...n};return e},[l,d,Xe]),Qe=J(v(e=>e.models)),$e=J(e=>e.selectedModel),et=J(e=>e.setSelectedModel),tt=He(e=>e.providerSnapshot?.defaults?.chat?.model),nt=He(e=>{let t=e.providerSnapshot?.defaults?.chat.provider;return Ue(e.providerSnapshot,t)}),it=J(e=>e.inputStates[d??``]?.reasoningEffort)??nt??`medium`,at=J(e=>e.setInputReasoningEffort),ot=$e||tt||f?.config?.model_ref?.model||f?.config?.model||``,[st,ct]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{ct(!1)},[le]);let ut=!st&&le.startsWith(`/`)?le.slice(1):null,ft=(()=>{if(st)return null;let e=le.match(/@([^\s@]*)$/);return e?e[1]:null})(),pt=f?.config?.workspacePath??t,[mt,ht]=(0,Q.useState)([]),gt=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(ft===null||!pt||gt.current===pt)return;let e=pt;gt.current=e,cn.listWorkspaceFiles(e).then(ht).catch(()=>{gt.current===e&&(gt.current=null),ht([])})},[ft,pt]);let _t=e=>{U(t=>t.replace(/@[^\s@]*$/,`@${e.path} `))},vt=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{ut===null||vt.current||(vt.current=!0,_e.listCommands().then(e=>ye((e.commands??[]).filter(e=>e.type===`workflow`))).catch(()=>{}))},[ut]);let yt=()=>{if(C||oe.busy||me.current)return;let e=J.getState(),n=e.inputStates[ce],i=n?.content??``,a=!be&&!he&&Se.length===0?/^\/goal(?:\s+([\s\S]*))?$/i.exec(i.trim()):null;if(a&&(d||!a[1]?.trim())){if(!d){X(`请先打开一个会话,再设置目标。`);return}let t=n?.contentRevision??0;if(!a[1]?.trim()){r(),e.setInputContentIfRevision(ce,t,``);return}let o=d;me.current=!0,fe(!0),K.sendMessage({message:i.trim(),session_id:o,model:f?.config?.model??``}).then(async e=>{if(e.session_id!==o||!e.goal_command)throw Error(`Goal command was not acknowledged`);if(J.getState().setInputContentIfRevision(ce,t,``),H.current===ce){let t=e.goal_command.action;X(t===`off`?`目标已暂停`:t===`clear`?`目标已清除`:t===`on_no_prompt`?`请先设置目标`:t===`status`?`已打开目标设置`:`目标已设置`),(t===`status`||t===`on_no_prompt`)&&r()}try{await J.getState().loadChatHistory(o)}catch{}if(e.goal_command.should_execute)try{await K.execute(o,f?.config?.model)}catch{H.current===ce&&X(`目标已保存,发送消息即可继续推进`)}}).catch(()=>{H.current===ce&&X(`目标保存失败,指令已保留,请重试`)}).finally(()=>{me.current=!1,fe(!1)});return}if(!i.trim()&&Se.length===0&&!be)return;if((ae||oe.hasUnconfirmed)&&he){X(`请先移除已选技能,再把消息加入队列。`);return}let o=Object.freeze({draftKey:ce,draftRevision:n?.contentRevision??0,attachmentRevision:Te.current,skillRevision:Ee.current,workflowRevision:De.current,text:i,attachments:Object.freeze(Se.map(e=>Object.freeze({...e}))),selectedSkill:he?Object.freeze({...he,tool_refs:[...he.tool_refs]}):null,selectedWorkflow:be?Object.freeze({...be}):null,workspacePath:t,templatePrompt:!d&&!c?jn():null}),s=o.selectedWorkflow?`${o.selectedWorkflow.content}${i.trim()?`\n\n${i.trim()}`:``}`:i,l=o.attachments.map(e=>({base64:e.base64,name:e.name,size:e.size,type:e.type}));(d&&(ae||oe.hasUnconfirmed)?oe.send(s,l):T(s,{skillIds:o.selectedSkill?[o.selectedSkill.id]:void 0,images:l.length?l:void 0,workspacePath:o.workspacePath,templatePrompt:o.templatePrompt})).then(e=>{if(e.kind===`unconfirmed`){H.current===o.draftKey&&V.current?.focus();return}if(e.kind===`accepted`){if(!J.getState().setInputContentIfRevision(o.draftKey,o.draftRevision,``)&&e.navigated&&o.draftKey!==e.sessionId){let t=J.getState(),n=t.inputStates[o.draftKey]?.contentRevision??0;t.moveInputContentIfRevision(o.draftKey,n,e.sessionId)}Te.current===o.attachmentRevision&&Ce([]),Ee.current===o.skillRevision&&ge(null),De.current===o.workflowRevision&&xe(null)}}).catch(e=>{console.error(`[ChatPane] submission coordinator failed`,e),H.current===o.draftKey&&V.current?.focus()}),Z()},bt=e=>{Ae(e),U(``)},xt=e=>{U(``),_e.getWorkflowCommand(e.name).then(t=>Me({name:e.display_name||e.name,content:t.content})).catch(()=>X(`加载工作流 ${e.name} 失败`))},St=e=>{Re(!0),O(e).then(e=>{Re(!1),X(e?`已从这里分叉到新会话`:`分叉失败:当前后端暂不支持会话分叉`)})},wt=[...d&&m.length>0?[{label:`导出 Markdown`,icon:(0,$.jsx)(lt,{className:`size-4`}),onClick:()=>ro(m,f?.title||`chat`)},{label:`导出 PDF`,icon:(0,$.jsx)(dt,{className:`size-4`}),onClick:()=>void ao(m,f?.title||`chat`)}]:[],{label:i?`关闭分屏对比`:`分屏对比`,icon:(0,$.jsx)(qe,{className:`size-4`}),onClick:a}];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative flex min-w-0 flex-1 flex-col`,onDragOver:e=>{e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),G(!0))},onDragLeave:e=>{e.currentTarget===e.target&&G(!1)},onDrop:e=>{e.preventDefault(),G(!1),e.dataTransfer.files.length&&Je(e.dataTransfer.files)},children:[W?(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-[60] m-3 flex items-center justify-center rounded-2xl border-2 border-dashed border-primary bg-primary/10 text-sm font-medium text-primary`,children:`松开以添加图片`}):null,c?(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b px-3 py-2`,children:[(0,$.jsxs)(ze,{value:c.sessionId??void 0,onValueChange:e=>c.onPickSession(e||null),children:[(0,$.jsx)(we,{size:`sm`,className:`min-w-0 flex-1`,children:(0,$.jsx)(pe,{placeholder:`选择会话并排…`})}),(0,$.jsx)(je,{children:c.chats.filter(e=>!e.parentSessionId).map(e=>(0,$.jsx)(Le,{value:e.id,children:e.title||`新会话`},e.id))})]}),d?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(fo,{value:it,onChange:e=>at(d??``,e),menuPlacement:`down`,menuAlign:`right`}),Qe.length>0?(0,$.jsx)(lo,{models:ot&&!Qe.includes(ot)?[ot,...Qe]:Qe,value:ot,onChange:et,menuPlacement:`down`,menuAlign:`right`}):null,(0,$.jsx)(u,{size:`icon`,variant:`ghost`,"aria-label":`检查器`,onClick:r,children:(0,$.jsx)(Ct,{})})]}):null,(0,$.jsx)(u,{size:`icon`,variant:`ghost`,"aria-label":`关闭分栏`,onClick:c.onClose,children:(0,$.jsx)(B,{})})]}):(0,$.jsx)(ho,{title:f?.title||`Bodhi`,hasSession:!!d,tokenUsage:se??f?.config?.tokenUsage,reasoningEffort:it,onChangeReasoning:e=>at(d??``,e),models:Qe,activeModel:ot,onChangeModel:et,overflowItems:wt,onOpenSidebar:o,onOpenInspector:r,sidebarCollapsed:s}),d?(0,$.jsx)(bs,{sessionId:d,title:f?.title||d}):null,f?.planMode?(0,$.jsxs)(`div`,{className:`border-b bg-primary/10 px-3 py-1.5 text-center text-xs font-medium text-primary`,children:[`计划模式`,f.planMode.status?` · ${f.planMode.status}`:``]}):null,f?.parentSessionId?(0,$.jsxs)(`button`,{onClick:()=>w(f.parentSessionId),className:`flex w-full items-center gap-1.5 border-b bg-muted/40 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground`,children:[(0,$.jsx)(rt,{className:`size-3.5`}),` 子代理 · 返回父会话`]}):null,!d&&!c&&!S&&!x?(0,$.jsx)(yo,{chats:l,onOpenSession:w,onPickTemplate:e=>U(e)}):(0,$.jsx)(Xo,{scrollRef:Be,contentRef:Ve,onScroll:Ge,messages:m,mergedSubAgents:Ze,sending:ae,streaming:h,streamingReasoning:g,liveSegments:_,streamStatus:y,pendingUserText:x,forking:q,onSelectSubAgent:w,onPreviewImage:Pe,onRegenerate:()=>void ee(),onFork:St,onDelete:e=>void D(e),onEditMessage:(e,t)=>void k(e,t)}),!We&&(0,$.jsx)(`button`,{onClick:Ke,"aria-label":`滚动到底部`,className:`absolute bottom-24 left-1/2 z-20 -translate-x-1/2 rounded-full border bg-card p-2 text-muted-foreground shadow-lg transition-colors hover:bg-accent hover:text-foreground`,children:(0,$.jsx)(ue,{className:`size-5`})}),A?.sessionId===d?(0,$.jsxs)(`div`,{role:`alert`,"aria-live":`assertive`,className:`mx-auto mb-1 flex w-[calc(100%-1.5rem)] max-w-2xl flex-wrap items-center justify-between gap-2 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm`,children:[(0,$.jsx)(`span`,{className:`text-destructive`,children:A.kind===`submission-unconfirmed`?`发送状态未确认,内容已保留`:`消息已发送,但生成中断`}),A.kind===`generation-failed`?(0,$.jsxs)(u,{size:`sm`,variant:`secondary`,disabled:S,onClick:()=>void te(A),children:[(0,$.jsx)(p,{className:`size-3.5`}),` 重试生成`]}):(0,$.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>V.current?.focus(),children:`继续编辑`})]}):null,oe.error&&(0,$.jsx)(`div`,{role:`alert`,className:`mx-auto mb-1 w-[calc(100%-1.5rem)] max-w-2xl rounded-lg border border-destructive/40 px-3 py-2 text-xs text-destructive`,children:oe.error}),typeof b==`number`&&(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-2xl px-3 text-right text-xs tabular-nums text-muted-foreground`,title:`根据流式文本估算,不用于计费`,children:[`约 `,b.toFixed(1),` token/秒`]}),(0,$.jsx)(ls,{draft:le,onDraftChange:U,onSubmit:yt,onStop:E,sending:ae,queueMode:oe.mode,onQueueModeChange:d&&!C?oe.setMode:void 0,queueControls:d?(0,$.jsx)(is,{sessionId:d,messages:oe.pending,busy:oe.busy,onCancel:e=>void oe.cancel(e),onPreview:Pe},d):null,submissionPending:C||de||oe.busy,inputRef:V,attachments:Se,onAddFiles:e=>void Je(e),onRemoveAttachment:e=>Oe(t=>t.filter(t=>t.id!==e)),onPreviewImage:Pe,selectedSkill:he,onClearSkill:()=>Ae(null),onPickSkill:bt,skills:Ye,workflows:ve,selectedWorkflow:be,onClearWorkflow:()=>Me(null),onPickWorkflow:xt,onPickGoal:d?()=>{r(),U(``),ct(!0)}:void 0,slashQuery:ut,atQuery:ft,displayWorkspace:pt,workspaceFiles:mt,onPickFile:_t,hasSession:!!d,onOpenWorkspacePicker:n,onDismissMenus:()=>ct(!0)})]}),(0,$.jsx)(us,{forking:q,toast:Fe}),(0,$.jsx)(ds,{src:Ne,onClose:()=>Pe(null)}),!j&&F?(0,$.jsxs)(`div`,{role:`alert`,className:`mx-4 mb-3 flex items-center gap-3 rounded-lg border p-3 text-sm`,children:[(0,$.jsx)(`span`,{children:F}),(0,$.jsx)(`button`,{type:`button`,className:`shrink-0 underline`,disabled:M||N,onClick:()=>void L(),children:M?`正在刷新…`:`刷新请求`})]}):null,ne?(0,$.jsx)($a,{a:ne,onRespond:e=>void ie(e)}):j?(0,$.jsx)(Qa,{q:j,onAnswer:e=>void re(e),loading:M,submitting:N,unavailable:P,error:F,canRetry:I,onRefresh:()=>void L(),onRetry:()=>void R()}):null]})}var ws=3e3;function Ts(){let e=J(e=>e.agentAvailability),[t,n]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{if(e===!1){let e=window.setTimeout(()=>n(!0),ws);return()=>window.clearTimeout(e)}n(!1)},[e]),(0,$.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`pointer-events-none fixed inset-x-0 top-0 z-[140]`,children:t?(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 bg-destructive px-3 py-1.5 pt-[max(0.375rem,env(safe-area-inset-top))] text-xs font-medium text-white`,children:[(0,$.jsx)(At,{className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{children:`连接已断开,正在重连…`})]}):null})}function Es(){let e=In(),{booted:t,chats:n,currentSessionId:r,currentChat:i,select:a,newChat:o}=e,[s,c]=(0,Q.useState)(null),l=In(s,e=>c(e)),u=e=>{c(e),e&&J.getState().loadChatHistory(e)},[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&(e.key===`k`||e.key===`K`)&&(e.preventDefault(),g(e=>!e))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(!1),x=Kt(),S=Ln(`lotus_next_sidebar_w`,288,{min:220,max:420,edge:`right`}),C=Ln(`lotus_next_inspector_w`,384,{min:280,max:640,edge:`left`}),w=Ln(`lotus_next_reference_w`,420,{min:300,max:720,edge:`left`}),[T,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(!1),[ee,k]=(0,Q.useState)(null),[te,A]=(0,Q.useState)(null),[j,M]=(0,Q.useState)(!1),N=Ee(e=>e.themeMode);(0,Q.useEffect)(()=>{document.documentElement.classList.toggle(`dark`,N===`dark`)},[N]),(0,Q.useEffect)(()=>{let e=()=>{let e=We()?`true`:`false`;document.body.setAttribute(`data-vdi-safe`,e),document.getElementById(`root`)?.setAttribute(`data-vdi-safe`,e)};return e(),he(e)},[]);let P=J(e=>e.loadSkills),F=J(e=>e.persistSessionTitle),I=J(e=>e.deleteSession),L=J(e=>e.pinSession),R=J(e=>e.unpinSession);(0,Q.useEffect)(()=>{P()},[P]);let ne=i?.config?.workspacePath,re=ne??te;return(0,$.jsxs)(`div`,{className:`relative flex h-full overflow-hidden bg-background text-foreground`,children:[(0,$.jsx)(Ts,{}),(0,$.jsx)(Xa,{open:d,onClose:()=>f(!1),collapsed:p,onToggleCollapse:()=>m(e=>!e),width:S.width,chats:n,booted:t,currentSessionId:r,onNewChat:o,onSelect:a,onRename:(e,t)=>void F(e,t),onDelete:e=>k({id:e.id,title:e.title||`新会话`}),onTogglePin:e=>e.pinned?R(e.id):L(e.id),onOpenSettings:()=>E(!0)}),p?null:(0,$.jsx)(Rn,{onPointerDown:S.startResize}),(0,$.jsx)(Cs,{chat:e,pickedWorkspace:te,onOpenWorkspacePicker:()=>M(!0),onOpenInspector:()=>v(!0),splitOpen:D,onToggleSplit:()=>O(e=>!e),onOpenSidebar:()=>{f(!0),m(!1)},sidebarCollapsed:p}),x&&_?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Rn,{onPointerDown:C.startResize}),(0,$.jsx)($t,{docked:!0,width:C.width,sessionId:r,open:_,onClose:()=>v(!1),workspace:re,onEditWorkspace:()=>M(!0)})]}):null,D?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Rn,{onPointerDown:w.startResize}),(0,$.jsx)(`div`,{className:`hidden shrink-0 flex-col border-l md:flex`,style:{width:w.width,maxWidth:`45vw`},children:(0,$.jsx)(Cs,{chat:l,secondary:{sessionId:s,chats:n,onPickSession:u,onClose:()=>O(!1)},pickedWorkspace:null,onOpenWorkspacePicker:()=>{},onOpenInspector:()=>b(!0),splitOpen:!0,onToggleSplit:()=>O(!1),onOpenSidebar:()=>{},sidebarCollapsed:!1})})]}):null,D&&y&&s?(0,$.jsx)($t,{sessionId:s,open:y,onClose:()=>b(!1),workspace:null}):null,x?null:(0,$.jsx)($t,{sessionId:r,open:_,onClose:()=>v(!1),workspace:re,onEditWorkspace:()=>M(!0)}),(0,$.jsx)(an,{open:T,onClose:()=>E(!1)}),(0,$.jsx)(sn,{}),(0,$.jsx)(ln,{open:j,current:re,locked:!!ne,onClose:()=>M(!1),onSelect:e=>A(e)}),(0,$.jsx)(en,{open:h,onClose:()=>g(!1),chats:n,onSelect:e=>{a(e),f(!1)},onNewChat:o,onSettings:()=>E(!0)}),(0,$.jsx)(Za,{pending:ee,onCancel:()=>k(null),onConfirm:e=>{I(e),k(null)}})]})}var Ds=e=>{switch(e.kind){case`rejected`:return`密码错误,请重新输入。`;case`rate-limited`:return`尝试次数过多,请稍后再试。`;case`unavailable`:return`密码验证服务暂时不可用,请稍后重试。`;case`contract-error`:return`后端密码验证接口不兼容,请升级后端后重试。`}};function Os({verifyPassword:e,onVerified:t}){let[n,r]=(0,Q.useState)(``),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(!1),c=(0,Q.useRef)(null);(0,Q.useEffect)(()=>()=>{c.current?.abort(),c.current=null},[]);let l=async r=>{if(r.preventDefault(),!n||o)return;c.current?.abort();let i=new AbortController;c.current=i,s(!0),a(null);try{let r=await e(n,i.signal);if(i.signal.aborted||c.current!==i)return;r.kind===`verified`?t():a(Ds(r))}catch{!i.signal.aborted&&c.current===i&&a(`密码验证服务暂时不可用,请稍后重试。`)}finally{!i.signal.aborted&&c.current===i&&(c.current=null,s(!1))}};return(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center bg-background p-6`,children:(0,$.jsxs)(`form`,{className:`w-full max-w-sm rounded-2xl border bg-card p-6 shadow-lg`,onSubmit:e=>void l(e),children:[(0,$.jsx)(`h1`,{className:`text-xl font-semibold`,children:`输入访问密码`}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`进入应用前需要先通过密码验证。`}),(0,$.jsx)(`label`,{className:`mt-5 block text-sm font-medium`,htmlFor:`access-password`,children:`访问密码`}),(0,$.jsx)(M,{id:`access-password`,type:`password`,value:n,onChange:e=>r(e.target.value),placeholder:`请输入访问密码`,autoComplete:`current-password`,autoFocus:!0,className:`mt-1.5 h-auto rounded-lg py-2 !text-base`}),i?(0,$.jsx)(`p`,{className:`mt-2 text-sm text-destructive`,role:`alert`,children:i}):null,(0,$.jsx)(u,{type:`submit`,disabled:!n||o,className:`mt-4 w-full`,children:o?`验证中…`:`验证并继续`})]})})}var ks=`bootstrap`,As=`bamboo/access/verify`,js=1,Ms=`bamboo`,Ns=`bamboo.agent`,Ps=`/api/v1`,Fs=1,Is=`bamboo.v2`,Ls=`/v2/stream`,Rs=2,zs=`bamboo.v2`,Bs=`/api/v1/bamboo/access/verify`,Vs=`/v2/pair`,Hs=4294967295,Us=[`auth.ws_hello_ack.v1`,`realtime.account_feed.v1`,`realtime.agent_events.v1`,`realtime.application_heartbeat.v1`,`realtime.feed_cursor.v1`,`realtime.feed_reset.v1`,`realtime.stop_control.v1`],Ws=`auth.password_cookie.v1`,Gs=`auth.device_bearer.v1`,Ks=e=>typeof e==`object`&&!!e&&!Array.isArray(e),qs=e=>typeof e==`string`&&e.length>0,Js=e=>Number.isInteger(e)&&e>=0&&e<=Hs,Ys=e=>e===`open`||e===`credential_required`||e===`repair_required`,Xs=e=>e===`local_bypass`||e===`authenticated`||e===`unauthenticated`;function Zs(e){if(e.aborted)throw new S(e.reason)}function Qs(e){if(!Ks(e))return{ok:!1,reason:`document-shape`};let t=e.server,n=e.api,r=e.realtime,i=e.auth,a=e.capabilities;if(typeof e.schema_version!=`number`||!Ks(t)||!Ks(n)||!Ks(r)||!Ks(i)||!Array.isArray(a)||!qs(t.product)||!qs(t.version)||!qs(n.name)||!qs(n.canonical_base_path)||typeof n.min_version!=`number`||typeof n.max_version!=`number`||!qs(r.name)||!qs(r.path)||typeof r.min_version!=`number`||typeof r.max_version!=`number`||!Array.isArray(r.subprotocols)||typeof i.password_enabled!=`boolean`||typeof i.device_auth_enabled!=`boolean`||!qs(i.verify_path)||!qs(i.pair_path))return{ok:!1,reason:`document-shape`};if(!Ys(i.policy)||!Xs(i.request_state))return{ok:!1,reason:`auth-enum`};if(!a.every(qs))return{ok:!1,reason:`document-shape`};let o=[];for(let e of r.subprotocols){if(!Ks(e)||!qs(e.name)||!qs(e.encoding))return{ok:!1,reason:`document-shape`};o.push({name:e.name,encoding:e.encoding})}return{ok:!0,document:{schema_version:e.schema_version,server:{product:t.product,version:t.version},api:{name:n.name,canonical_base_path:n.canonical_base_path,min_version:n.min_version,max_version:n.max_version},realtime:{name:r.name,path:r.path,min_version:r.min_version,max_version:r.max_version,subprotocols:o},capabilities:[...a],auth:{policy:i.policy,request_state:i.request_state,password_enabled:i.password_enabled,device_auth_enabled:i.device_auth_enabled,verify_path:i.verify_path,pair_path:i.pair_path}}}}function $s(e){if(![e.schema_version,e.api.min_version,e.api.max_version,e.realtime.min_version,e.realtime.max_version].every(Js)||e.api.min_version>e.api.max_version||e.realtime.min_version>e.realtime.max_version)return`invalid-range`;if(new Set(e.capabilities).size!==e.capabilities.length)return`duplicate-capability`;let t=e.realtime.subprotocols.map(({name:e})=>e);if(new Set(t).size!==t.length)return`duplicate-subprotocol`;let{policy:n,request_state:r,password_enabled:i,device_auth_enabled:a}=e.auth;return n===`open`&&(r===`authenticated`||i||a)||n===`credential_required`&&!i&&!a||n===`repair_required`&&r===`authenticated`?`invalid-auth-combination`:null}function ec(e,t,n){return e<=n&&n<=t}function tc(e){let t=Qs(e);if(!t.ok)return{kind:`invalid`,reason:t.reason};let n=t.document,r=$s(n);if(r)return{kind:`invalid`,reason:r};if(n.schema_version!==js)return{kind:`incompatible`,reason:`schema-version`};if(n.server.product!==Ms)return{kind:`incompatible`,reason:`server-product`};if(n.api.name!==Ns||n.api.canonical_base_path!==Ps||!ec(n.api.min_version,n.api.max_version,Fs))return{kind:`incompatible`,reason:`api-contract`};if(n.realtime.name!==Is||n.realtime.path!==Ls||!ec(n.realtime.min_version,n.realtime.max_version,Rs)||!n.realtime.subprotocols.some(({name:e,encoding:t})=>e===zs&&t===`json`))return{kind:`incompatible`,reason:`realtime-contract`};let i=new Set(n.capabilities);return Us.some(e=>!i.has(e))?{kind:`incompatible`,reason:`missing-capability`}:n.auth.password_enabled&&(!i.has(Ws)||n.auth.verify_path!==Bs)?{kind:`incompatible`,reason:`password-contract`}:n.auth.device_auth_enabled&&(!i.has(Gs)||n.auth.pair_path!==Vs)?{kind:`incompatible`,reason:`device-contract`}:n.auth.policy===`repair_required`?{kind:`repair`}:n.auth.request_state===`local_bypass`||n.auth.policy===`open`?{kind:`ready`}:n.auth.password_enabled?n.auth.request_state===`authenticated`?{kind:`ready`}:{kind:`auth-required`}:{kind:`auth-unsupported`,mechanism:`device`}}function nc(e){if(!e)return!1;let t=e.split(`;`,1)[0]?.trim().toLowerCase();return t===`application/json`||!!(t?.startsWith(`application/`)&&t.endsWith(`+json`))}function rc(e,t){if(e instanceof S)throw e;if(e instanceof O)return{kind:`unavailable`,reason:`timeout`};if(t.aborted)throw new S(t.reason??e);return e instanceof L?{kind:`unavailable`,reason:`network`}:e instanceof F?e.status===404?{kind:`missing`}:e.status===408||e.status===429||e.status>=500&&e.status<=599?{kind:`unavailable`,reason:`http-status`,status:e.status}:{kind:`incompatible`,reason:`http-status`,status:e.status}:{kind:`unavailable`,reason:`network`}}async function ic(e){Zs(e);let t;try{t=await N.fetchRaw(ks,{method:`GET`,signal:e,cache:`no-store`})}catch(t){return rc(t,e)}if(Zs(e),!nc(t.headers.get(`content-type`))){let e=t.body?.cancel();return e&&e.catch(()=>void 0),{kind:`invalid`,reason:`content-type`}}let n;try{n=await t.json()}catch(t){return t instanceof S||t instanceof O||t instanceof L||e.aborted?rc(t,e):{kind:`invalid`,reason:`malformed-json`}}return Zs(e),tc(n)}function ac(e,t){if(e instanceof S)throw e;if(e instanceof O)return{kind:`unavailable`,reason:`timeout`};if(t.aborted)throw new S(t.reason??e);return e instanceof L?{kind:`unavailable`,reason:`network`}:e instanceof F?e.status===401?{kind:`rejected`}:e.status===429?{kind:`rate-limited`}:e.status>=500&&e.status<=599?{kind:`unavailable`,reason:`http-status`,status:e.status}:{kind:`contract-error`,reason:`http-status`,status:e.status}:{kind:`contract-error`,reason:`invalid-response`}}async function oc(e,t){Zs(t);let n;try{n=await N.post(As,{password:e},{signal:t})}catch(e){return ac(e,t)}return Zs(t),!Ks(n)||n.success!==!0||Object.keys(n).length!==1||!Object.hasOwn(n,`success`)?{kind:`contract-error`,reason:`invalid-response`}:{kind:`verified`}}var sc=[250,500],cc=(e,t)=>new Promise(n=>{if(t.aborted){n(!1);return}let r=e=>{clearTimeout(a),t.removeEventListener(`abort`,i),n(e)},i=()=>r(!1),a=setTimeout(()=>r(!0),e);t.addEventListener(`abort`,i,{once:!0})}),lc=e=>{switch(e.kind){case`missing`:return{title:`后端缺少启动契约`,description:`当前后端没有提供 Lotus Next 所需的 canonical bootstrap。请升级 Bamboo 后端后重试。`};case`invalid`:return{title:`后端启动响应无效`,description:`后端返回了无法安全解析的启动信息。请检查部署是否完整,并升级为匹配的 Bamboo 版本。`};case`incompatible`:return{title:`后端协议不兼容`,description:`当前后端不满足 Lotus Next 所需的 HTTP v1 与 v2 stream 契约。请升级完整后端制品。`};case`auth-unsupported`:return{title:`当前认证方式尚不受支持`,description:`此部署仅接受设备凭据,而当前 Lotus Next 切片尚未接入设备配对与实时连接认证。`};case`repair`:return{title:`后端访问配置需要修复`,description:`Bamboo 已将访问控制置于安全隔离状态。请先在本机修复或重置访问配置,然后重试。`};case`unavailable`:case`internal-failure`:return{title:`暂时无法连接后端`,description:`Bamboo 服务暂时不可用。请确认服务正在运行,并在网络或启动过程恢复后重试。`}}};function uc(){let e=r(),[t,n]=(0,Q.useState)({kind:`loading`}),i=(0,Q.useRef)(0),a=(0,Q.useRef)(null),o=(0,Q.useCallback)(()=>{a.current?.controller.abort();let e={generation:i.current+1,controller:new AbortController};return i.current=e.generation,a.current=e,e},[]),s=(0,Q.useCallback)(e=>!e.controller.signal.aborted&&a.current?.generation===e.generation&&a.current.controller===e.controller,[]),c=(0,Q.useCallback)(async e=>{try{let t=await Ve.getInstance().getSetupStatus();if(!s(e))return;if(!t.is_complete){n({kind:`setup`,message:t.message||`应用尚未完成首次设置。`});return}}catch{if(!s(e))return}s(e)&&n({kind:`app`})},[s]),l=(0,Q.useCallback)(async e=>{for(let t=0;t<sc.length+1;t+=1){let r;try{r=await ic(e.controller.signal)}catch{if(!s(e))return;n({kind:`internal-failure`});return}if(!s(e))return;if(r.kind===`unavailable`&&t<sc.length){if(!await cc(sc[t],e.controller.signal)||!s(e))return;continue}if(r.kind===`ready`){await c(e);return}n(r);return}},[s,c]),d=(0,Q.useCallback)(()=>{let e=o();n({kind:`loading`}),l(e)},[o,l]),f=(0,Q.useCallback)(()=>{let e=o();n({kind:`loading`}),(async()=>{await Ve.getInstance().markSetupComplete().catch(()=>void 0),s(e)&&await c(e)})()},[o,s,c]);if((0,Q.useEffect)(()=>(d(),()=>{i.current+=1,a.current?.controller.abort(),a.current=null}),[d]),t.kind===`loading`)return(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:`加载中…`});if(t.kind===`setup`)return(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center bg-background p-6`,children:(0,$.jsxs)(`div`,{className:`w-full max-w-sm rounded-2xl border bg-card p-6 text-center shadow-lg`,children:[(0,$.jsx)(`h1`,{className:`text-xl font-semibold`,children:`首次设置`}),(0,$.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-muted-foreground`,children:t.message}),(0,$.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`请在后端 / 桌面端配置提供方与密钥;完成后点击继续。`}),(0,$.jsx)(u,{className:`mt-5 w-full`,onClick:f,children:`已完成,继续`})]})});if(t.kind===`auth-required`)return(0,$.jsx)(Os,{verifyPassword:oc,onVerified:d});if(t.kind===`app`)return(0,$.jsx)(Es,{});let p=lc(t);return(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center bg-background p-6`,children:(0,$.jsxs)(`div`,{className:`w-full max-w-sm rounded-2xl border bg-card p-6 text-center shadow-lg`,children:[(0,$.jsx)(`h1`,{className:`text-xl font-semibold`,children:p.title}),(0,$.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-muted-foreground`,children:p.description}),(0,$.jsxs)(`p`,{className:`mt-3 break-all font-mono text-xs text-muted-foreground`,children:[e.endpointSource,` · v`,e.artifact.version,e.artifact.revision?`@${e.artifact.revision}`:``]}),(0,$.jsx)(u,{className:`mt-5 w-full`,onClick:d,children:`重试`})]})})}export{uc as default};
|