@forsion/unit 2.12.2 → 2.13.0
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 +61 -0
- package/backendWorker.mjs +6 -2
- package/main.mjs +987 -495
- package/package.json +1 -1
- package/release.json +5 -5
- package/web/assets/ArtificialView-BSv3Mx5C.js +1 -0
- package/web/assets/{AutomationBuilder-sxWdUa0L.js → AutomationBuilder-BuiHtVB-.js} +1 -1
- package/web/assets/CalendarConfigView-BJtG6cqN.js +1 -0
- package/web/assets/CalendarView-C-FX1RED.js +1 -0
- package/web/assets/CapabilityMenu-kx1TIJYN.js +1 -0
- package/web/assets/{CheckboxInput-BsaoUHZ0.js → CheckboxInput-eW7xdiRS.js} +1 -1
- package/web/assets/Chrome-B77-lQyh.js +1 -0
- package/web/assets/{CodeView-j065KtVh.js → CodeView-Df3AiSIi.js} +3 -3
- package/web/assets/DashboardGridView-MlO1dpuo.js +17 -0
- package/web/assets/{EventCard-BmDQkEj9.js → EventCard-CDmeCbI8.js} +1 -1
- package/web/assets/ExcalidrawCanvas-D9vkBh_5.js +1 -0
- package/web/assets/{FloatingToc-CENybkAA.js → FloatingToc-tART_jC4.js} +1 -1
- package/web/assets/HomepageView-Trqmd3RV.js +1 -0
- package/web/assets/ImageStudioPanels-BfCVTnKC.js +3 -0
- package/web/assets/ImageStudioView-KJhx0wJk.js +1 -0
- package/web/assets/InlineFiles-BHwivGbQ.js +1 -0
- package/web/assets/MarkdownBlock--__nPQGh.css +1 -0
- package/web/assets/MarkdownBlock-D8LgHFYY.js +58 -0
- package/web/assets/ModelPill-DrW2cG0l.js +2 -0
- package/web/assets/MuseLibraryView-CW78Uivf.js +2 -0
- package/web/assets/{MuseView-d-iBk3sc.js → MuseView-Cb6R_l4i.js} +2 -2
- package/web/assets/{PageHistoryPanel-CR-k1AM7.js → PageHistoryPanel-BQs9IWTP.js} +2 -2
- package/web/assets/PdfAnnotator-BFTBkxvO.js +505 -0
- package/web/assets/PdfAnnotator-C_kglLCA.css +1 -0
- package/web/assets/{ProductView-u2aezVsl.js → ProductView-mB-S0j81.js} +1 -1
- package/web/assets/RightPanel-BVZeVO3c.js +4 -0
- package/web/assets/RunLocationPicker-BE5mxnab.css +1 -0
- package/web/assets/RunLocationPicker-CyVa0RJa.js +38 -0
- package/web/assets/{SidebarRow-BuSkKH5q.js → SidebarRow-D77yrSLf.js} +1 -1
- package/web/assets/{SketchCard-D87GADyG.js → SketchCard-CAAr_cqF.js} +5 -5
- package/web/assets/{StudioGuestSurface-BijU_EEb.js → StudioGuestSurface-DthpuVGg.js} +1 -1
- package/web/assets/{TodoListView-DPPVpPUn.js → TodoListView-C3ZkMIIf.js} +1 -1
- package/web/assets/{Tooltip-DY4ISA-e.js → Tooltip-D9Dt9ZTr.js} +1 -1
- package/web/assets/UnifiedPage-C75y-MKT.js +68 -0
- package/web/assets/UnifiedPage-CWXc_mo1.css +1 -0
- package/web/assets/{amadeus-manual.en-DWaN2fPs.js → amadeus-manual.en-D5wZKuag.js} +3 -3
- package/web/assets/{amadeus-manual.zh--7D5TS8X.js → amadeus-manual.zh-Br5fidrj.js} +3 -3
- package/web/assets/{appStore-Dg9WALEA.js → appStore-B1ynyt42.js} +186 -120
- package/web/assets/appStore-BC_CQv-L.css +1 -0
- package/web/assets/{arrow-up-right-CpQs92mu.js → arrow-up-right-R10mR2I6.js} +1 -1
- package/web/assets/{astryxBridge-BZhaZPs4.js → astryxBridge-CU_kQTEl.js} +3 -3
- package/web/assets/automationListSource-B8EIRmDW.js +1 -0
- package/web/assets/book-open-DBJ3dDpw.js +1 -0
- package/web/assets/{calendarNavStore-C7fGRpoH.js → calendarNavStore-DGvUlU5N.js} +1 -1
- package/web/assets/{canvasPrefs-BeG4oEgP.js → canvasPrefs-DwL_OAAo.js} +1 -1
- package/web/assets/chatBoxSurface-Lq-2qfd3.js +1 -0
- package/web/assets/{circle-question-mark-WL3vbp-Z.js → circle-question-mark-HPZpZQxd.js} +1 -1
- package/web/assets/{circle-x-D7s-M5sB.js → circle-x-BZfe7d6S.js} +1 -1
- package/web/assets/{client-BSKpsyAw.js → client-DxGbwZLy.js} +1 -1
- package/web/assets/{code-xml-BALV9u_c.js → code-xml-joKQ-qGS.js} +1 -1
- package/web/assets/{codeStudioStore-C2mWfm32.js → codeStudioStore-C7rGKlOC.js} +1 -1
- package/web/assets/codingNavigation-CZB4v1ZW.css +1 -0
- package/web/assets/codingNavigation-CjeWG4xm.js +47 -0
- package/web/assets/{create-4xUyKtAF.js → create-BjBRKATq.js} +4 -4
- package/web/assets/dashboardSurface-Cojgf_-U.js +1 -0
- package/web/assets/{deskCapture-Df701U8L.js → deskCapture-DnGWk1iq.js} +1 -1
- package/web/assets/{diff2html-BV-zCH4d.js → diff2html-Cd1rVi_Z.js} +1 -1
- package/web/assets/{docx-preview-DW4IyU_Q.js → docx-preview-CK0k1mUD.js} +1 -1
- package/web/assets/{emoji-DGaxpCIu.js → emoji-Cjm3bKiF.js} +1 -1
- package/web/assets/floatingTocSurface-Dd1pT5j5.js +1 -0
- package/web/assets/foldActions-Dm-uAt3L.js +1 -0
- package/web/assets/folder-CvZyHIgb.js +1 -0
- package/web/assets/{folder-plus-D1TDb7k9.js → folder-plus-BRScGQ9m.js} +1 -1
- package/web/assets/gestures-CZQVefU0.js +1 -0
- package/web/assets/{hand-Crrw-nSn.js → hand-D3QspKYq.js} +1 -1
- package/web/assets/{hard-drive-BbyVSbfP.js → hard-drive-BQsHSala.js} +1 -1
- package/web/assets/i18n-ecQQxiMQ.css +1 -0
- package/web/assets/i18n.generated-BZRHO2Nc.js +15 -0
- package/web/assets/imageStudio--KF9gwHA.css +1 -0
- package/web/assets/imageStudio-Cy3_437s.js +2 -0
- package/web/assets/{index-CflzrdSt.js → index-0AYHATDX.js} +1 -1
- package/web/assets/{index-Dg9oixs4.js → index-1FhRiJ_X.js} +1 -1
- package/web/assets/{index-CqyM6tQ0.js → index-4E9nrhwf.js} +1 -1
- package/web/assets/{index-Cmr7gVZQ.js → index-8ag1K7AZ.js} +1 -1
- package/web/assets/{index-SZ5waGAq.js → index-9BmmlTjY.js} +1 -1
- package/web/assets/{index-CzM-C2Sd.js → index-B5GxvbNm.js} +1 -1
- package/web/assets/{index-DKhyDkGB.js → index-BPhwi4-v.js} +1 -1
- package/web/assets/index-BaRySZ-M.js +1 -0
- package/web/assets/{index-Brik2pf9.js → index-BcVGjCAJ.js} +1 -1
- package/web/assets/{index-OHi69jDq.js → index-BdZaheMZ.js} +1 -1
- package/web/assets/{index-D1f_JwPH.js → index-BgDZGDqt.js} +1 -1
- package/web/assets/{index-C6GJulug.js → index-BgtO11q8.js} +1 -1
- package/web/assets/{index-CF4RV4mh.js → index-Bh_nLVTc.js} +90 -90
- package/web/assets/{index-DjzSBM0U.js → index-BnWj6ggb.js} +1 -1
- package/web/assets/{index-BRW82CsP.js → index-Bpc3R3DS.js} +1 -1
- package/web/assets/{index-BCZZVJ_w.js → index-C9yo04Ck.js} +1 -1
- package/web/assets/{index--drOLtq7.js → index-CcOag8eb.js} +1 -1
- package/web/assets/{index-Czu_bbDM.js → index-D0FLFLfh.js} +1 -1
- package/web/assets/{index-KL5Rj9kP.js → index-D6mpAJ9S.js} +1 -1
- package/web/assets/{index-tAXBa_fN.js → index-DElrDw66.js} +1 -1
- package/web/assets/{index-DUWR2nZi.js → index-DJLWTPtq.js} +1 -1
- package/web/assets/{index-gPSbFSUn.js → index-DNE_PBJt.js} +1 -1
- package/web/assets/index-Dj-PygjB.js +1 -0
- package/web/assets/{index-BYsdKR_1.js → index-Dkd-nl1u.js} +1 -1
- package/web/assets/{index-C7U6T-k8.js → index-GjLSlygt.js} +1 -1
- package/web/assets/{invitePage-lLQ-e0pj.js → invitePage-B4gMvEKi.js} +1 -1
- package/web/assets/{ipc-DQOD2UKk.js → ipc-CPhL3bPp.js} +1 -1
- package/web/assets/{jszip.min-DZxV9uZ_.js → jszip.min-DAJT9RUA.js} +1 -1
- package/web/assets/launchpad-C2c1MSVX.css +1 -0
- package/web/assets/{layout-grid-B_pjJwz4.js → layout-grid-DfUfnvDS.js} +1 -1
- package/web/assets/{linkFollow-C0_3k_PC.js → linkFollow-C6PHGUxk.js} +5 -5
- package/web/assets/{list-tree-DkAJYEXd.js → list-tree-DaGpnIYu.js} +1 -1
- package/web/assets/{listFold-BsOVn9UZ.js → listFold-Q_8mh5ZG.js} +1 -1
- package/web/assets/{lock-BnGHxjeE.js → lock-DQ_yL4nF.js} +1 -1
- package/web/assets/{log-out-DBuMeqik.js → log-out-DFwTeh2X.js} +1 -1
- package/web/assets/main-CwqZ_ymb.js +19 -0
- package/web/assets/markdownEditorSurface-e_oMhqx-.js +3 -0
- package/web/assets/mdMarkStore-DjN4bf1T.js +2 -0
- package/web/assets/{mdMarks-Bq7Hl-4C.js → mdMarks-cmL6vzR-.js} +1 -1
- package/web/assets/{message-square-plus-BiAZAvcw.js → message-square-plus-CEHkduIL.js} +1 -1
- package/web/assets/{messages-BH5MfQdZ.js → messages-CBtmbpur.js} +1 -1
- package/web/assets/minus-BUT48dAC.js +1 -0
- package/web/assets/mobileEntry-qR7BAROr.js +13 -0
- package/web/assets/nativeDownload-CziEyW_p.js +1 -0
- package/web/assets/{pageChrome-xLNdFaSg.css → pageChrome-CovzZPdb.css} +1 -1
- package/web/assets/pageChrome-DFz_AAzZ.js +1 -0
- package/web/assets/{pageTree-CZH2J6cc.js → pageTree-yVO1_fSy.js} +2 -2
- package/web/assets/{pen-tool-lkmBqliH.js → pen-tool-uxsFELYC.js} +1 -1
- package/web/assets/{pencil-Cvk91P_Z.js → pencil-BSbra1Ra.js} +1 -1
- package/web/assets/pluginChat-BMFnf_j2.js +2 -0
- package/web/assets/{redo-2-DSi54z4e.js → redo-2-BK5LMNa5.js} +1 -1
- package/web/assets/{rotate-ccw-CUlnplr0.js → rotate-ccw-HedfU4na.js} +1 -1
- package/web/assets/{sharePage-MM6UpPJ9.js → sharePage-CpzDpuU1.js} +2 -2
- package/web/assets/{shareViewer-CDZ8lTdy.js → shareViewer-BwzH2bIs.js} +1 -1
- package/web/assets/{star-CwDiGyUW.js → star-CgYon3z4.js} +1 -1
- package/web/assets/tableSurface-CmDwnKnd.js +1 -0
- package/web/assets/{terminal-DIXogYJY.js → terminal-krsPf1mc.js} +1 -1
- package/web/assets/{terminalView-B3aZSsrQ.js → terminalView-4e2_u5_I.js} +1 -1
- package/web/assets/theme-C6D3tMGV.css +1 -0
- package/web/assets/type-GJYLEhY-.js +1 -0
- package/web/assets/{undo-2-tUKCv5Gs.js → undo-2-DCTs4Ro4.js} +1 -1
- package/web/assets/{unitAccount-D8lVwaaT.js → unitAccount-D3xjX3cu.js} +1 -1
- package/web/assets/{unitBridge-D547ublk.js → unitBridge-D5JcIkAP.js} +1 -1
- package/web/assets/{unitCloudTransport-BVF6lVp4.js → unitCloudTransport-B44L3x6M.js} +1 -1
- package/web/assets/{unitOwnerAccess-BfnEjsZb.js → unitOwnerAccess-CRUHWGpf.js} +1 -1
- package/web/assets/{unitShim-DxetRgmP.js → unitShim-_VzxvdEG.js} +3 -3
- package/web/assets/{upload-BbeAsMuD.js → upload-MVVRQtkj.js} +1 -1
- package/web/assets/userSpaces-CI4eqEgh.js +1 -0
- package/web/assets/viewportLock-BH26xHQO.js +611 -0
- package/web/assets/viewportLock-IP1zaVkz.css +1 -0
- package/web/assets/{workflow-DuoVRSSX.js → workflow-DzeW9OXR.js} +1 -1
- package/web/assets/{zoom-in-hr5bRpDL.js → zoom-in-CovPsw4g.js} +1 -1
- package/web/index.html +212 -13
- package/web/assets/ArtificialView-B4ESD4iK.js +0 -1
- package/web/assets/CalendarConfigView-cCfo_EvZ.js +0 -1
- package/web/assets/CalendarView-wgLapctk.js +0 -1
- package/web/assets/CapabilityMenu-BQBsM638.js +0 -1
- package/web/assets/ChatView-BIUk0OJd.css +0 -1
- package/web/assets/ChatView-C-jCJnyS.js +0 -47
- package/web/assets/Chrome-CwFiDmre.js +0 -1
- package/web/assets/DashboardGridView-DXqe0vPd.js +0 -17
- package/web/assets/ExcalidrawCanvas-C3egkikA.js +0 -1
- package/web/assets/HomepageView-CRdhjLXu.js +0 -1
- package/web/assets/ImageStudioPanels-Dke7xf8E.js +0 -3
- package/web/assets/ImageStudioView-g38V8gaj.js +0 -1
- package/web/assets/InlineFiles-C_hjvn3u.js +0 -1
- package/web/assets/MarkdownBlock-DIjYEhTK.js +0 -56
- package/web/assets/ModelPill-BPlgovPo.js +0 -1
- package/web/assets/MuseLibraryView-CenyTTim.js +0 -2
- package/web/assets/PdfAnnotator-CGzC_o1Q.css +0 -1
- package/web/assets/PdfAnnotator-D79ip27w.js +0 -560
- package/web/assets/RightPanel-C3OJTIqT.js +0 -4
- package/web/assets/RunLocationPicker-BNcZ7KKF.css +0 -1
- package/web/assets/RunLocationPicker-CTYXUH2z.js +0 -34
- package/web/assets/UnifiedPage-CKNtVD_n.js +0 -57
- package/web/assets/UnifiedPage-DX_sTpyZ.css +0 -1
- package/web/assets/appStore-Di8LXuJ9.css +0 -1
- package/web/assets/automationListSource-DP5xZBxo.js +0 -1
- package/web/assets/chatBoxSurface-zvcyfrxE.js +0 -1
- package/web/assets/dashboardSurface-CFTH5z4c.js +0 -1
- package/web/assets/ellipsis-r1EcXsFq.js +0 -1
- package/web/assets/floatingTocSurface-C6RJ6i41.js +0 -1
- package/web/assets/foldActions-B7KByFdN.js +0 -1
- package/web/assets/folder-DlxnPmWY.js +0 -1
- package/web/assets/frame-_xBVYe3P.js +0 -1
- package/web/assets/gestures-CkW1Kfs9.js +0 -1
- package/web/assets/i18n-D-eU58uw.css +0 -1
- package/web/assets/i18n.generated-Bbsz16cl.js +0 -15
- package/web/assets/imageStudio-BqbNOvpu.css +0 -1
- package/web/assets/imageStudio-C_Rs630L.js +0 -2
- package/web/assets/index-BCubCwdT.js +0 -1
- package/web/assets/index-DZfZTksa.js +0 -1
- package/web/assets/main-Dki8NlsT.js +0 -21
- package/web/assets/markdownEditorSurface-B4PeUzed.js +0 -3
- package/web/assets/mdMarkStore-CsKl7C8O.js +0 -2
- package/web/assets/minus-Cyv1YzOU.js +0 -1
- package/web/assets/mobileEntry-Bd_nKr0D.js +0 -13
- package/web/assets/nativeDownload-D-f1_L2S.js +0 -1
- package/web/assets/pageChrome-C9_azUYW.js +0 -1
- package/web/assets/panel-left-rOc8As0s.js +0 -1
- package/web/assets/pen-line-m6_HvWZ9.js +0 -1
- package/web/assets/sticky-note-BIuPUSOU.js +0 -1
- package/web/assets/tableSurface-Y_JBQsuz.js +0 -1
- package/web/assets/theme-DfEi_DND.css +0 -1
- package/web/assets/type-Cqoabh7H.js +0 -1
- package/web/assets/userSpaces-DyyAn7vj.js +0 -1
- package/web/assets/viewportLock-C4SX-9PO.js +0 -103
- package/web/assets/viewportLock-DYSe7Jsn.css +0 -1
- package/web/assets/waves-horizontal-B8ZpHQ5H.js +0 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import{d as u,t as Te,r as xe,j as t,u as Ce,T as Pn,R as mn,M as wr,N as br,O as jr,v as oi}from"./index-Bh_nLVTc.js";import{F as We,u as D,lz as Sr,s as it,lA as Nr,lB as Cr,lC as zr,K as Hi,lD as Mr,aM as Kt,cN as Vi,bG as Ar,bo as ea,fd as Ki,U as Is,aE as at,aJ as ot,bI as $s,ap as Bn,kM as Er,lE as Rr,lF as Tr,lG as Ir,kN as $r,kU as Lr,kV as Pr,lH as Dr,lI as _r,lJ as Or,fr as Yt,p as Dn,b as hn,ec as Un,ak as ri,aB as fs,bd as Fr,X as Wr,Y as Br,ar as yn,aP as Ht,c4 as Et,R as Yi,ag as Xi,lK as Gi,ih as Ur,Z as ta,G as gs,lL as qr,aI as Xn,lM as Hr,cK as Vr,i4 as Kr,i0 as ci,co as Yr,lN as Xr,kT as Gr,h as Jr,bE as Zr,dX as Qr,e5 as ec,ej as tc,kG as li,cM as nc,a2 as sc,lO as ac,lP as ic,lQ as oc,lk as rc,cO as cc,lR as vs,lS as Ji,lT as lc,lU as uc,lV as dc,kl as hc,ch as ui,cg as pc,aq as qn,lW as mc,aS as fc,lX as gc,hk as vc,lY as yc,T as Zi,hp as di,cq as Vt,cp as kc,H as xc,lZ as wc,hn as Rt,l_ as bc,l$ as jc,m0 as Xt,lo as kn,bA as Sc,hL as Nc,m1 as hi,n as ys,m2 as xn,lm as fn,m3 as Qi,m4 as na,ks as Cc,a5 as Hn,aa as eo,bB as to,hS as zc,hQ as Mc,m5 as Ac,m6 as Ec,gR as sa,o as Rc,f as Tc,m7 as no,c as Ic,g as $c,l4 as so,m8 as Lc,ic as Pc,dk as pi,gS as ks,ah as Ls,cc as Dc,d$ as _c,m9 as Oc,ma as Fc,mb as Wc,a4 as Bc,al as Uc,iw as ao,e6 as io,lh as mi,li as qc}from"./appStore-B1ynyt42.js";import{u as fi,n as gi}from"./codeStudioStore-C7rGKlOC.js";import{a as Hc,u as vi,C as Vc,j as Kc}from"./RightPanel-BVZeVO3c.js";import{c as Gn,n as Rn}from"./nativeDownload-CziEyW_p.js";import"./client-DxGbwZLy.js";import{t as Ps,c as Yc,g as Xc,a as Gc}from"./ModelPill-DrW2cG0l.js";import{P as Vn}from"./pencil-BSbra1Ra.js";import{c as Jc,D as Zc}from"./create-BjBRKATq.js";import{S as Qc,W as el}from"./approvalText-Cy2UAUAQ.js";import{c as tl,C as nl,g as sl,t as oo,u as al,A as il,m as ol,d as rl,S as cl,P as xs,a as ll,f as ro,b as co}from"./SidebarRow-D77yrSLf.js";import{M as ul}from"./message-square-plus-CEHkduIL.js";import{F as Kn}from"./folder-CvZyHIgb.js";import{H as dl}from"./hand-D3QspKYq.js";import{F as lo}from"./folder-plus-BRScGQ9m.js";import{i as hl}from"./ipc-CPhL3bPp.js";import{a as pl,S as uo,I as ml}from"./pageChrome-DFz_AAzZ.js";const fl=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]],gl=We("archive-restore",fl);const vl=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]],Ds=We("archive",vl);const yl=[["path",{d:"M2 10v3",key:"1fnikh"}],["path",{d:"M6 6v11",key:"11sgs0"}],["path",{d:"M10 3v18",key:"yhl04a"}],["path",{d:"M14 8v7",key:"3a1oy3"}],["path",{d:"M18 5v13",key:"123xd1"}],["path",{d:"M22 10v3",key:"154ddg"}]],kl=We("audio-lines",yl);const xl=[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}],["path",{d:"m9.5 10.5 5 5",key:"ra9qjz"}],["path",{d:"m14.5 10.5-5 5",key:"l2rkpq"}]],yi=We("folder-x",xl);const wl=[["path",{d:"M13.4 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7.4",key:"re6nr2"}],["path",{d:"M2 6h4",key:"aawbzj"}],["path",{d:"M2 10h4",key:"l0bgd4"}],["path",{d:"M2 14h4",key:"1gsvsf"}],["path",{d:"M2 18h4",key:"1bu2t1"}],["path",{d:"M21.378 5.626a1 1 0 1 0-3.004-3.004l-5.01 5.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z",key:"pqwjuv"}]],bl=We("notebook-pen",wl);const jl=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M9 21V9",key:"1oto5p"}]],_n=We("panels-top-left",jl);const Sl=[["circle",{cx:"11",cy:"4",r:"2",key:"vol9p0"}],["circle",{cx:"18",cy:"8",r:"2",key:"17gozi"}],["circle",{cx:"20",cy:"16",r:"2",key:"1v9bxh"}],["path",{d:"M9 10a5 5 0 0 1 5 5v3.5a3.5 3.5 0 0 1-6.84 1.045Q6.52 17.48 4.46 16.84A3.5 3.5 0 0 1 5.5 10Z",key:"1ydw1z"}]],Nl=We("paw-print",Sl);const Cl=[["line",{x1:"9",x2:"9",y1:"4",y2:"20",key:"ovs5a5"}],["path",{d:"M4 7c0-1.7 1.3-3 3-3h13",key:"10pag4"}],["path",{d:"M18 20c-1.7 0-3-1.3-3-3V4",key:"1gaosr"}]],zl=We("pi",Cl);const Ml=[["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"}]],Al=We("pin-off",Ml);const El=[["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:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]],Rl=We("shield-question-mark",El);const Tl=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],ho=We("user-plus",Tl);const Il=[["path",{d:"M2 12q2.5 2 5 0t5 0 5 0 5 0",key:"8ddzzs"}],["path",{d:"M2 19q2.5 2 5 0t5 0 5 0 5 0",key:"1wj4st"}],["path",{d:"M2 5q2.5 2 5 0t5 0 5 0 5 0",key:"69x50u"}]],$l=We("waves-horizontal",Il);function aa(e,n={}){return!1}function _s(e,n,a){const[o,i]=u.useState(null),c=u.useRef({build:n,onClose:a});c.current={build:n,onClose:a};const r=e!=null&&e!==!1,l=r&&o!==e&&!1;return u.useEffect(()=>{if(!r){o!==null&&i(null);return}},[e,o,r]),!l}let un=null,ws=null;function Ll(e){const n=D.getState().tr;return n(`channel.name.${e}`)}function Pl(e){const n=e.filter(i=>i.enabled&&i.workspace).map(i=>({key:i.workspace,name:Ll(i.kind),kind:"channel",channel:i.kind,path:i.workspace,system:!0})),a=D.getState().channelWorkspaces;a.length===n.length&&a.every((i,c)=>i.key===n[c].key&&i.name===n[c].name&&i.channel===n[c].channel)||D.setState({channelWorkspaces:n})}const Dl=Gn((e,n)=>({channels:[],available:!1,loaded:!1,refresh:async()=>{if(window.tangu?.backendStatus)try{const a=await zr(it()),o=Array.isArray(a.channels)?a.channels:[];e({channels:o,available:!!a.available,loaded:!0}),Pl(o)}catch{}},save:async(a,o)=>{await Cr(it(),a,o),await n().refresh()},connect:async a=>{const o=await Nr(it(),a);return await n().refresh(),D.getState().refreshSessions(D.getState().cfg),o},disconnect:async(a,o)=>{await Sr(it(),a,o),await n().refresh()},startPolling:()=>{if(un!=null)return;const a=()=>{D.getState().connState==="ok"&&n().refresh()};un=window.setInterval(a,15e3);let o=D.getState().connState;ws=D.subscribe(i=>{i.connState==="ok"&&o!=="ok"&&n().refresh(),o=i.connState}),a()},stopPolling:()=>{un!=null&&(window.clearInterval(un),un=null),ws?.(),ws=null}}));xe({"voiceinput.silent":{zh:"没采集到声音(输入电平≈0):检查系统输入设备是否选对、麦克风没被静音",en:"No audio captured (input level ≈ 0): check that the right input device is selected and that the microphone is not muted"},"voiceinput.unsupported":{zh:"此环境不支持语音输入",en:"Voice input is not supported in this environment"},"voiceinput.denied":{zh:"麦克风权限被拒绝(打开 系统设置 › 隐私与安全 › 麦克风,允许本 App)",en:"Microphone access was denied (open System Settings › Privacy & Security › Microphone and allow this app)"},"voiceinput.silentPhone":{zh:"没录到声音,再试一次",en:"No sound was recorded — try again"},"voiceinput.deniedPhone":{zh:"麦克风权限被拒绝(到系统设置 › 应用 › 权限里允许麦克风)",en:"Microphone access was denied (allow it in system Settings › Apps › Permissions)"},"voiceinput.noDevice":{zh:"没检测到麦克风设备",en:"No microphone found"},"voiceinput.openFailed":{zh:"麦克风打不开:{e}",en:"Could not open the microphone: {e}"},"voiceinput.unclear":{zh:"没听清,再试一次",en:"Didn't catch that — try again"}});async function _l(e){const n=await e.arrayBuffer(),a=new AudioContext,o=await a.decodeAudioData(n);await a.close();const i=Math.max(1,Math.round(o.duration*16e3)),c=new OfflineAudioContext(1,i,16e3),r=c.createBufferSource();r.buffer=o,r.connect(c.destination),r.start();const l=(await c.startRendering()).getChannelData(0);let h=0,p=0;for(let f=0;f<l.length;f++){const k=Math.abs(l[f]);k>h&&(h=k),p+=l[f]*l[f]}if(console.warn(`[voice] captured ${l.length} samples @16k, ${(l.length/16e3).toFixed(2)}s, peak=${h.toFixed(4)} rms=${Math.sqrt(p/(l.length||1)).toFixed(4)}`),h<.005)throw new Error(window.tangu?.mobile?Te("voiceinput.silentPhone"):Te("voiceinput.silent"));return Ol(l,16e3)}function Ol(e,n){const a=e.length,o=new ArrayBuffer(44+a*2),i=new DataView(o),c=(p,f)=>{for(let k=0;k<f.length;k++)i.setUint8(p+k,f.charCodeAt(k))};c(0,"RIFF"),i.setUint32(4,36+a*2,!0),c(8,"WAVE"),c(12,"fmt "),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,1,!0),i.setUint32(24,n,!0),i.setUint32(28,n*2,!0),i.setUint16(32,2,!0),i.setUint16(34,16,!0),c(36,"data"),i.setUint32(40,a*2,!0);for(let p=0;p<a;p++){const f=Math.max(-1,Math.min(1,e[p]));i.setInt16(44+p*2,f<0?f*32768:f*32767,!0)}const r=new Uint8Array(o);let l="";const h=32768;for(let p=0;p<r.length;p+=h)l+=String.fromCharCode(...r.subarray(p,p+h));return btoa(l)}function Fl(e,n){const[a,o]=u.useState(!1),[i,c]=u.useState(!1),[r,l]=u.useState(null),h=u.useRef(null),p=u.useRef([]),f=u.useRef(!1),[k,x]=u.useState(null),A=u.useRef(null),E=u.useCallback(()=>{x(null),A.current?.close().catch(()=>{}),A.current=null},[]);u.useEffect(()=>E,[E]);const M=typeof navigator<"u"&&!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<"u"&&!!window.tangu?.transcribeAudio,z=u.useCallback(U=>{f.current=U,h.current?.stop()},[]),B=u.useCallback(async()=>{if(l(null),!M){l(Te("voiceinput.unsupported"));return}let U;try{U=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(C){console.warn("[voice] getUserMedia failed:",C?.name,C?.message||C),l(C?.name==="NotAllowedError"?window.tangu?.mobile?Te("voiceinput.deniedPhone"):Te("voiceinput.denied"):C?.name==="NotFoundError"?Te("voiceinput.noDevice"):Te("voiceinput.openFailed",{e:C?.name||C?.message||C}));return}try{const C=new AudioContext,g=C.createAnalyser();g.fftSize=128,g.smoothingTimeConstant=.7,C.createMediaStreamSource(U).connect(g),A.current=C,x(g)}catch{}const J=new MediaRecorder(U);h.current=J,p.current=[],f.current=!1,J.ondataavailable=C=>{C.data.size&&p.current.push(C.data)},J.onstop=async()=>{if(U.getTracks().forEach(g=>g.stop()),E(),o(!1),h.current=null,f.current||!p.current.length)return;const C=new Blob(p.current,{type:J.mimeType||"audio/webm"});c(!0);try{const g=await window.tangu.transcribeAudio({audioBase64:await _l(C),mime:"audio/wav",modelId:n});g?e(g):l(Te("voiceinput.unclear"))}catch(g){console.warn("[voice] transcribe failed:",g?.message||g),l(g?.message||String(g))}finally{c(!1)}},J.start(),o(!0)},[M,n,e,E]),_=u.useCallback(()=>{i||(a?z(!1):B())},[i,a,B,z]),L=u.useCallback(()=>{a&&z(!0)},[a,z]);return{recording:a,busy:i,error:r,toggle:_,cancel:L,supported:M,analyser:k}}const Wl=({size:e})=>t.jsx("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"currentColor","aria-hidden":"true",children:t.jsx("path",{d:"M10.931 3.34a.112.112 0 0 0-.069-.104l-.038-.007c-1.537.05-2.45.318-3.714 1.002v6.683c.48-.248.936-.44 1.414-.58.695-.203 1.417-.292 2.303-.305l.038-.008a.113.113 0 0 0 .066-.104V3.341ZM2.363 9.919c0 .064.051.11.105.111l.33.008c1.162.046 2.042.243 2.975.662-.403-.585-1.008-1.075-1.654-1.292a.991.991 0 0 1-.674-.941v-5.14a6.36 6.36 0 0 0-.59-.076l-.37-.02a.115.115 0 0 0-.122.111v6.577Zm9.455-.001a.998.998 0 0 1-.877.992l-.101.007c-.832.012-1.47.095-2.066.27-.599.174-1.176.448-1.883.863a.444.444 0 0 1-.449 0c-1.299-.763-2.229-1.07-3.689-1.125l-.299-.008a.997.997 0 0 1-.977-.998V3.342c0-.573.478-1.017 1.038-.999l.417.023c.188.015.35.037.513.062v-.754c0-.708.749-1.244 1.429-.903.984.492 1.836 1.449 2.15 2.505 1.216-.617 2.222-.884 3.771-.934l.105.003a.998.998 0 0 1 .918.996v6.576ZM4.332 8.466c0 .049.03.087.07.1l.24.091a4.319 4.319 0 0 1 1.581 1.176V3.721c-.164-.803-.799-1.617-1.584-2.07l-.162-.088c-.025-.012-.054-.013-.088.009a.12.12 0 0 0-.057.102v6.792Z"})}),Bl=({size:e})=>t.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:t.jsx("path",{d:"m4.7144 15.9555 4.7174-2.6471.079-.2307-.079-.1275h-.2307l-.7893-.0486-2.6956-.0729-2.3375-.0971-2.2646-.1214-.5707-.1215-.5343-.7042.0546-.3522.4797-.3218.686.0608 1.5179.1032 2.2767.1578 1.6514.0972 2.4468.255h.3886l.0546-.1579-.1336-.0971-.1032-.0972L6.973 9.8356l-2.55-1.6879-1.3356-.9714-.7225-.4918-.3643-.4614-.1578-1.0078.6557-.7225.8803.0607.2246.0607.8925.686 1.9064 1.4754 2.4893 1.8336.3643.3035.1457-.1032.0182-.0728-.164-.2733-1.3539-2.4467-1.445-2.4893-.6435-1.032-.17-.6194c-.0607-.255-.1032-.4674-.1032-.7285L6.287.1335 6.6997 0l.9957.1336.419.3642.6192 1.4147 1.0018 2.2282 1.5543 3.0296.4553.8985.2429.8318.091.255h.1579v-.1457l.1275-1.706.2368-2.0947.2307-2.6957.0789-.7589.3764-.9107.7468-.4918.5828.2793.4797.686-.0668.4433-.2853 1.8517-.5586 2.9021-.3643 1.9429h.2125l.2429-.2429.9835-1.3053 1.6514-2.0643.7286-.8196.85-.9046.5464-.4311h1.0321l.759 1.1293-.34 1.1657-1.0625 1.3478-.8804 1.1414-1.2628 1.7-.7893 1.36.0729.1093.1882-.0183 2.8535-.607 1.5421-.2794 1.8396-.3157.8318.3886.091.3946-.3278.8075-1.967.4857-2.3072.4614-3.4364.8136-.0425.0304.0486.0607 1.5482.1457.6618.0364h1.621l3.0175.2247.7892.522.4736.6376-.079.4857-1.2142.6193-1.6393-.3886-3.825-.9107-1.3113-.3279h-.1822v.1093l1.0929 1.0686 2.0035 1.8092 2.5075 2.3314.1275.5768-.3218.4554-.34-.0486-2.2039-1.6575-.85-.7468-1.9246-1.621h-.1275v.17l.4432.6496 2.3436 3.5214.1214 1.0807-.17.3521-.6071.2125-.6679-.1214-1.3721-1.9246L14.38 17.959l-1.1414-1.9428-.1397.079-.674 7.2552-.3156.3703-.7286.2793-.6071-.4614-.3218-.7468.3218-1.4753.3886-1.9246.3157-1.53.2853-1.9004.17-.6314-.0121-.0425-.1397.0182-1.4328 1.9672-2.1796 2.9446-1.7243 1.8456-.4128.164-.7164-.3704.0667-.6618.4008-.5889 2.386-3.0357 1.4389-1.882.929-1.0868-.0062-.1579h-.0546l-6.3385 4.1164-1.1293.1457-.4857-.4554.0608-.7467.2307-.2429 1.9064-1.3114Z"})}),ki=({engineId:e,size:n=16})=>{const a=e.toLowerCase();return a.includes("claude")?t.jsx(Bl,{size:n}):a.includes("codex")||a.includes("openai")?t.jsx(Wl,{size:n}):a.includes("claw")?t.jsx(Nl,{size:n}):a==="pi"||a.startsWith("pi-")?t.jsx(zl,{size:n}):a.includes("dsh")||a.includes("deepseek")?t.jsx($l,{size:n}):t.jsx(Hi,{size:n})},Os="forsion_voice_call_voice",Ul=50,ql=1e3,Hl=300,Vl=2500;function xi(e){try{e?localStorage.setItem(Os,JSON.stringify({...e,t:Date.now()})):localStorage.removeItem(Os)}catch{}}let tt=null,po=0,wi,bi=!1;const Fs=new Set;function mo(e){clearTimeout(wi);let n=null;try{n=e?JSON.parse(e):null}catch{n=null}const a=tt;if(n&&typeof n.sessionId=="string"&&typeof n.phase=="string"){const o=a?.sessionId===n.sessionId&&a.phase===n.phase;tt={sessionId:n.sessionId,phase:n.phase,level:Math.min(1,Math.max(0,Number(n.level)||0)),since:o?a.since:Date.now()},po=Date.now(),wi=setTimeout(()=>mo(null),Vl)}else tt=null;(a?.sessionId!==tt?.sessionId||a?.phase!==tt?.phase)&&Fs.forEach(o=>o())}function fo(){bi||typeof window>"u"||typeof window.addEventListener!="function"||(bi=!0,window.addEventListener("storage",e=>{(e.key===Os||e.key===null)&&mo(e.key?e.newValue:null)}))}function oh(){return fo(),tt&&tt.level>0&&Date.now()-po>Hl&&(tt={...tt,level:0}),tt}function rh(e){return fo(),Fs.add(e),()=>{Fs.delete(e)}}const Kl="forsion_realtime_cfg_rev";let On={model:"",voice:""},ji=!1;const Ws=new Set;function bs(){window.tangu?.getConfig?.().then(e=>{const n={model:e.realtimeModelId?.trim()||"",voice:e.realtimeVoice?.trim()||""};n.model===On.model&&n.voice===On.voice||(On=n,Ws.forEach(a=>a()))}).catch(()=>{})}function Yl(){return u.useSyncExternalStore(e=>(ji||(ji=!0,bs(),window.addEventListener("storage",n=>{n.key===Kl&&bs()}),window.addEventListener("focus",bs)),Ws.add(e),()=>{Ws.delete(e)}),()=>On)}const go="forsion_voice_call_evt";function Xl(e){try{localStorage.setItem(go,JSON.stringify({...e,n:`${Date.now()}-${Math.random()}`}))}catch{}}const Yn="forsion_voice_call_active",Fn=new Set;let Si=!1;function Gl(e){try{e?localStorage.setItem(Yn,e):localStorage.removeItem(Yn)}catch{}Fn.forEach(n=>n())}function vo(){try{return localStorage.getItem(Yn)}catch{return null}}function Jl(e){return Si||(Si=!0,window.addEventListener("storage",n=>{(n.key===Yn||n.key===null)&&Fn.forEach(a=>a())})),Fn.add(e),()=>{Fn.delete(e)}}const Zl=4e3,ch=1500;function Ql(e,n,a=2e3){const o=`${Date.now()}-${Math.random()}`;return new Promise(i=>{const c=yo(l=>{l.kind==="text-ack"&&l.id===o&&(c(),clearTimeout(r),i(!0))}),r=setTimeout(()=>{c(),vo()===e&&Gl(null),i(!1)},a);Xl({kind:"text",sessionId:e,text:n,id:o,at:Date.now()})})}function yo(e){const n=a=>{if(!(a.key!==go||!a.newValue))try{e(JSON.parse(a.newValue))}catch{}};return window.addEventListener("storage",n),()=>window.removeEventListener("storage",n)}const eu=.04,Ni=24e3;let je=null,Bs=null;const Us=new Set;let Wn=null,Gt=null;const qs=()=>Us.forEach(e=>e()),ko=e=>{je&&(je={...je,...e},qs())};function lh(e){return Us.add(e),()=>{Us.delete(e)}}const uh=()=>je,dh=()=>Bs;function tu(e){Wn?.(e)}function hh(){je&&ko({muted:!je.muted})}const ph=e=>Gt?.mic(e)??Promise.resolve(),mh=e=>Gt?.speaker(e)??Promise.resolve(),fh=e=>Gt?.run(e),gh=e=>Gt?.text(e)??!1;async function vh(e){je&&tu(),Bs=null,je={sessionId:e.sessionId,phase:"connecting",muted:!1,working:null,analyser:null,connectedAt:null},qs();let n=null,a=null;const o=new AudioContext({sampleRate:16e3}),i=new AudioContext({sampleRate:Ni}),c=o.createAnalyser(),r=i.createAnalyser();r.connect(i.destination);const l=new Set;let h=0,p=!1,f=null,k=null;const x=F=>({echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0,channelCount:1,...F?{deviceId:F}:{}}),A=()=>{f=o.createMediaStreamSource(n),f.connect(c),k&&f.connect(k)},E=F=>(i.setSinkId?.(F)??Promise.resolve()).catch(P=>console.warn("[realtime] setSinkId failed:",P)),M=F=>{p||ko(F)},z=(F=500)=>{e.onActivity&&window.setTimeout(e.onActivity,F)},B=()=>{l.forEach(F=>{try{F.stop()}catch{}}),l.clear(),h=0},_=F=>{const P=new Int16Array(F,0,F.byteLength>>1);if(!P.length)return;const $=i.createBuffer(1,P.length,Ni),W=$.getChannelData(0);for(let Z=0;Z<P.length;Z++)W[Z]=P[Z]/32768;const K=i.createBufferSource();K.buffer=$,K.connect(r);const Q=Math.max(i.currentTime+.05,h);K.start(Q),h=Q+$.duration,l.add(K),K.onended=()=>{l.delete(K),!l.size&&je?.phase==="speaking"&&M({phase:"listening",analyser:c})},je?.phase!=="speaking"&&M({phase:"speaking",analyser:r})},L=new Uint8Array(r.fftSize);let U="",J=0;const C=window.setInterval(()=>{if(p||!je)return;const F=l.size>0,P=F?"speaking":je.phase,$=Date.now();if(!F&&P===U&&$-J<ql)return;let W=0;if(F){r.getByteTimeDomainData(L);const K=L.length>>1;let Q=0;for(let Z=K;Z<L.length;Z++){const T=(L[Z]-128)/128;Q+=T*T}W=Math.min(1,Math.sqrt(Q/(L.length-K))*4)}U=P,J=$,xi({sessionId:e.sessionId,phase:P,level:W})},Ul),g=()=>xi(null);window.addEventListener("pagehide",g);const O=F=>{if(p)return;p=!0;const P=Wn===O;P&&(Wn=null),window.clearInterval(C),window.removeEventListener("pagehide",g),P&&g(),B();try{a?.close()}catch{}n?.getTracks().forEach($=>$.stop()),o.close().catch(()=>{}),i.close().catch(()=>{}),P&&(Gt=null,Bs=F||null,je=null,qs()),z(300)};Wn=O,Gt={mic:async F=>{const P=await navigator.mediaDevices.getUserMedia({audio:x(F)});if(p){P.getTracks().forEach($=>$.stop());return}f?.disconnect(),n?.getTracks().forEach($=>$.stop()),n=P,f&&A()},speaker:E,run:F=>{e.run=F,a?.readyState===WebSocket.OPEN&&a.send(JSON.stringify({type:"run",run:F}))},text:F=>p||!je?.connectedAt||je.phase==="reconnecting"||a?.readyState!==WebSocket.OPEN?!1:(B(),M({phase:"thinking",analyser:c}),a.send(JSON.stringify({type:"text",text:F})),z(),!0)};try{if(n=await navigator.mediaDevices.getUserMedia({audio:x(e.micId)}),p){n.getTracks().forEach(P=>P.stop());return}e.speakerId&&await E(e.speakerId);const F=await Mr(e.target);if(p)return;a=new WebSocket(F),a.binaryType="arraybuffer"}catch(F){O(F?.message||String(F));return}const Y=a;Y.onopen=()=>Y.send(JSON.stringify({type:"start",session_id:e.sessionId,model:e.model,voice:e.voice||void 0,title:e.title,run:e.run})),Y.onclose=F=>O(F.reason||(F.code===1e3?void 0:`connection closed (${F.code})`)),Y.onmessage=F=>{if(p)return;if(F.data instanceof ArrayBuffer){_(F.data);return}let P;try{P=JSON.parse(String(F.data))}catch{return}switch(P.type){case"ready":{if(k){M(l.size?{phase:"speaking",analyser:r}:{phase:"listening",analyser:c});break}k=o.createScriptProcessor(1024,1,1),k.connect(o.destination),k.onaudioprocess=$=>{if(p||!je||je.muted||Y.readyState!==WebSocket.OPEN)return;const W=$.inputBuffer.getChannelData(0);let K=0;for(let T=0;T<W.length;T++)K+=W[T]*W[T];const Q=l.size>0&&Math.sqrt(K/W.length)<eu,Z=new Int16Array(W.length);if(!Q)for(let T=0;T<W.length;T++)Z[T]=Math.max(-32768,Math.min(32767,Math.round(W[T]*32767)));Y.send(Z.buffer)},A(),M({phase:"listening",analyser:c,connectedAt:Date.now()});break}case"input_audio_buffer.speech_started":B(),M({phase:"hearing",analyser:c});break;case"input_audio_buffer.speech_stopped":M({phase:"thinking"});break;case"conversation.item.input_audio_transcription.completed":case"response.audio_transcript.done":z();break;case"response.done":!l.size&&je?.phase==="thinking"&&P.response?.status!=="completed"&&M({phase:"listening",analyser:c});break;case"transcript.corrected":typeof P.message_id=="string"&&typeof P.text=="string"&&e.onTranscriptFix?.(P.message_id,P.text);break;case"tangu.run":M({working:P.status==="started"?String(P.task||""):null}),z(P.status==="started"?300:800);break;case"error":console.warn("[realtime] upstream error:",P.error?.message||P.error);break;case"reconnecting":P.replay&&B(),M({phase:"reconnecting"});break;case"end":O(P.reason&&P.reason!=="client closed"?String(P.reason):void 0);break}}}const Ci=Gn((e,n)=>({pending:[],queue:(a,o)=>e(i=>({pending:[...i.pending,{sessionId:a,text:o}]})),take:a=>{const o=n().pending.filter(i=>i.sessionId===a);return o.length&&e(i=>({pending:i.pending.filter(c=>c.sessionId!==a)})),o.map(i=>i.text)}})),zi=40,Mi=.1,nu=3.2;function su({analyser:e,recording:n,busy:a,onStop:o,onSend:i,status:c,stopTitle:r,t:l}){const h=u.useRef(null),[p,f]=u.useState(0),k=u.useRef(0);u.useEffect(()=>{if(!n)return;k.current=Date.now(),f(0);const A=window.setInterval(()=>f(Math.floor((Date.now()-k.current)/1e3)),250);return()=>window.clearInterval(A)},[n]),u.useEffect(()=>{const A=h.current;if(!e||!n||!A)return;const E=A.getContext("2d");if(!E)return;const M=window.devicePixelRatio||1;A.width=Math.max(1,A.clientWidth)*M,A.height=Math.max(1,A.clientHeight)*M,E.setTransform(M,0,0,M,0,0);const z=getComputedStyle(document.documentElement),B=(z.getPropertyValue("--accent-ink")||z.getPropertyValue("--accent")||"#7c3aed").trim(),_=(z.getPropertyValue("--border")||"rgba(127,127,127,0.4)").trim(),L=new Uint8Array(e.fftSize),U=[];let J=Date.now(),C=0;const g=()=>{C=requestAnimationFrame(g);const O=Date.now();e.getByteTimeDomainData(L);let Y=0;for(let K=0;K<L.length;K++){const Q=(L[K]-128)/128;Y+=Q*Q}const F=Math.min(1,Math.sqrt(Y/L.length)*nu);for(;O-J>=zi;)U.push({t:J,level:F}),J+=zi;const P=A.clientWidth,$=A.clientHeight,W=$/2;for(E.clearRect(0,0,P,$),E.strokeStyle=_,E.lineWidth=1,E.setLineDash([2,3]),E.beginPath(),E.moveTo(0,W),E.lineTo(P,W),E.stroke(),E.setLineDash([]);U.length&&P-(O-U[0].t)*Mi<-4;)U.shift();E.fillStyle=B;for(const K of U){const Q=P-(O-K.t)*Mi;if(Q<-4||Q>P)continue;const Z=Math.max(2,K.level*($-4));E.globalAlpha=Q<P*.15?Math.max(0,Q/(P*.15)):1,E.beginPath(),E.roundRect(Q-1.1,W-Z/2,2.2,Z,1.1),E.fill()}E.globalAlpha=1};return g(),()=>cancelAnimationFrame(C)},[e,n]);const x=`${Math.floor(p/60)}:${String(p%60).padStart(2,"0")}`;return a?t.jsxs("div",{className:"t2c-voicebar",children:[t.jsx(Kt,{size:14,className:"spin"}),t.jsx("span",{className:"t2c-voicelabel",children:l("input.micBusy")}),t.jsx("span",{className:"t2c-grow"})]}):t.jsxs("div",{className:"t2c-voicebar",children:[t.jsx("canvas",{ref:h,className:"t2c-voicewave"}),t.jsx("span",{className:"t2c-voicetime",children:c??x}),t.jsx("button",{className:"t2c-voicestop",title:r??l("input.micStop"),onClick:o,children:t.jsx(Vi,{size:12})}),i&&t.jsx("button",{className:"t2c-send",title:l("input.send"),onClick:i,children:t.jsx(Ar,{size:16})})]})}xe({"ultraConfirm.title":{zh:"开启 Ultra?",en:"Turn on Ultra?"},"ultraConfirm.msg":{zh:"Ultra 会把思考拉满、上下文用到模型支持的上限,并主动把能并行的活拆给多个子代理同时做。一次任务的 token 消耗可能是平时的数倍,适合大任务。",en:"Ultra maxes out thinking, uses the model's full context window, and proactively splits parallelizable work across several subagents. One task can use several times the usual tokens, so it suits big jobs."},"ultraConfirm.recommend":{zh:"推荐配合「完全放行」使用:多个子代理并行时,每个需要确认的操作都会停下来等你批准。",en:"Full access is recommended: with several subagents running in parallel, every action that needs approval stops and waits for you."},"ultraConfirm.fullAccess":{zh:"同时把本会话切到「完全放行」",en:"Also switch this session to Full access"},"ultraConfirm.skip":{zh:"以后不再显示",en:"Don't show this again"},"ultraConfirm.confirm":{zh:"开启 Ultra",en:"Turn on Ultra"}});const xo="forsion_ultra_confirm_off";function au(){try{return localStorage.getItem(xo)==="1"}catch{return!1}}function iu({offerFullAccess:e,onConfirm:n,onClose:a}){const{t:o}=Ce(),[i,c]=u.useState(!1),[r,l]=u.useState(!1),h=u.useRef(typeof document<"u"?document.activeElement:null);u.useEffect(()=>()=>{const f=h.current;f?.isConnected&&typeof f.focus=="function"&&f.focus({preventScroll:!0})},[]);const p=f=>{if(f.key!=="Tab")return;const k=f.currentTarget.querySelector(".dialog"),x=k?[...k.querySelectorAll('button, input, [tabindex]:not([tabindex="-1"])')].filter(M=>!M.disabled):[];if(!x.length)return;const A=x[0],E=x[x.length-1];f.shiftKey&&document.activeElement===A?(f.preventDefault(),E.focus()):!f.shiftKey&&document.activeElement===E&&(f.preventDefault(),A.focus())};return ea.createPortal(t.jsx("div",{className:"am-app tangu-lovable",style:{display:"contents"},"data-ultra-confirm":!0,"data-keep-menus":!0,onKeyDown:p,children:t.jsxs(Ki,{title:o("ultraConfirm.title"),message:o("ultraConfirm.msg"),confirmLabel:o("ultraConfirm.confirm"),danger:!1,onConfirm:()=>{if(r)try{localStorage.setItem(xo,"1")}catch{}n({fullAccess:e&&i})},onClose:a,children:[e&&t.jsx("div",{className:"dialog-msg",children:o("ultraConfirm.recommend")}),e&&t.jsxs("label",{className:"dialog-check","data-ultra-full-access":!0,children:[t.jsx("input",{type:"checkbox",checked:i,onChange:f=>c(f.target.checked)}),t.jsx("span",{children:o("ultraConfirm.fullAccess")})]}),t.jsxs("label",{className:"dialog-check","data-ultra-skip":!0,children:[t.jsx("input",{type:"checkbox",checked:r,onChange:f=>l(f.target.checked)}),t.jsx("span",{children:o("ultraConfirm.skip")})]})]})}),document.body)}xe({"session.untitled":{zh:"新会话",en:"New session"},"session.rootlessGroup":{zh:"无项目会话",en:"No project"}});const ou="New Chat";function yt(e,n){const a=(e||"").trim();return!a||a===ou?n("session.untitled"):e}function Tn(e,n){return e.kind==="rootless"?n("session.rootlessGroup"):e.name}xe({"group.setup.selfPacedHint":{zh:"发消息后成员同时开工,可相互 @ 交接;每位成员自己决定何时收尾,全员完成即结束,没有轮数上限。",en:"After you send, members work in parallel and can @-mention each other; each decides when they are done, and the team stops once everyone is — no round limit."}});const ru=()=>({name:"",description:"",model:"",systemPrompt:"",thinkingLevel:"",maxIterations:"",approvalMode:""}),cu=()=>`temp-${Date.now().toString(36)}-${Math.floor(Math.random()*46656).toString(36)}`,lu=({agents:e,models:n,initialAgents:a,initialTempAgents:o,active:i,hideDisable:c,onConfirm:r,onDisable:l,onClose:h})=>{const{t:p}=Ce(),f=u.useMemo(()=>new Set(e.map(g=>g.slug)),[e]),[k,x]=u.useState(()=>a.filter(g=>f.has(g))),[A,E]=u.useState(o||[]),[M,z]=u.useState(null),B=u.useMemo(()=>(n||[]).map(g=>({id:g.id,label:g.name||g.id})),[n]),L=k.length+A.length>=2,U=g=>x(O=>O.includes(g)?O.filter(Y=>Y!==g):[...O,g]),J=()=>{if(!M||!M.name.trim()||!M.systemPrompt.trim())return;const g=M.slug||cu(),O={slug:g,name:M.name.trim(),description:M.description.trim(),model:M.model,tools:[],thinkingLevel:M.thinkingLevel,maxIterations:M.maxIterations?Number(M.maxIterations):null,approvalMode:M.approvalMode,createdBy:"user",createdAt:"",systemPrompt:M.systemPrompt.trim()};E(Y=>{const F=Y.findIndex(P=>P.slug===g);if(F>=0){const P=Y.slice();return P[F]=O,P}return[...Y,O]}),z(null)},C=()=>{L&&r({groupAgents:[...k,...A.map(g=>g.slug)],groupTempAgents:A})};return t.jsx("div",{onClick:h,style:{position:"fixed",inset:0,background:"var(--overlay-scrim)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},children:t.jsxs("div",{"data-team-setup":!0,onClick:g=>g.stopPropagation(),style:{width:480,maxWidth:"92vw",maxHeight:"86vh",overflow:"auto",borderRadius:"var(--radius-md, 12px)",background:"var(--bg)",color:"var(--text)",border:"1px solid var(--border)",boxShadow:"var(--card-shadow)",padding:18},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[t.jsx(Is,{size:18}),t.jsx("strong",{style:{fontSize:"var(--ui-font-heading, 14px)",flex:1},children:p("group.setup.title")}),t.jsx("button",{className:"icon-btn",onClick:h,title:p("group.setup.close"),children:t.jsx(at,{size:16})})]}),M?t.jsxs("div",{className:"field",children:[t.jsx("div",{className:"hint",style:{marginBottom:8},children:p("group.setup.tempFormHint")}),t.jsxs("div",{className:"field",children:[t.jsx("label",{children:p("settings.agents.name")}),t.jsx("input",{type:"text",value:M.name,placeholder:p("settings.agents.namePlaceholder"),onChange:g=>z({...M,name:g.target.value})})]}),t.jsxs("div",{className:"field",children:[t.jsx("label",{children:p("settings.agents.desc")}),t.jsx("input",{type:"text",value:M.description,onChange:g=>z({...M,description:g.target.value})})]}),t.jsxs("div",{className:"field",children:[t.jsx("label",{children:p("settings.agents.model")}),t.jsxs("select",{value:M.model,onChange:g=>z({...M,model:g.target.value}),children:[t.jsx("option",{value:"",children:p("settings.agents.modelDefault")}),B.map(g=>t.jsx("option",{value:g.id,children:g.label},g.id))]})]}),t.jsxs("div",{className:"field",children:[t.jsx("label",{children:p("settings.agents.systemPrompt")}),t.jsx("textarea",{rows:6,value:M.systemPrompt,placeholder:p("settings.agents.systemPromptPlaceholder"),onChange:g=>z({...M,systemPrompt:g.target.value})})]}),t.jsxs("div",{className:"field-row",children:[t.jsxs("div",{className:"field",children:[t.jsx("label",{children:p("settings.agents.thinking")}),t.jsxs("select",{value:M.thinkingLevel,onChange:g=>z({...M,thinkingLevel:g.target.value}),children:[t.jsx("option",{value:"",children:p("settings.agents.inherit")}),Pn.map(g=>t.jsx("option",{value:g,children:Ps(g,p)},g))]})]}),t.jsxs("div",{className:"field",children:[t.jsx("label",{children:p("settings.agents.maxIter")}),t.jsx("input",{type:"number",min:10,max:200,value:M.maxIterations,onChange:g=>z({...M,maxIterations:g.target.value})})]}),t.jsxs("div",{className:"field",children:[t.jsx("label",{children:p("settings.agents.approval")}),t.jsxs("select",{value:M.approvalMode,onChange:g=>z({...M,approvalMode:g.target.value}),children:[t.jsx("option",{value:"",children:p("settings.agents.inherit")}),t.jsx("option",{value:"readonly",children:"readonly"}),t.jsx("option",{value:"auto-edit",children:"auto-edit"}),t.jsx("option",{value:"full-auto",children:"full-auto"}),t.jsx("option",{value:"custom",children:"custom"})]})]})]}),t.jsxs("div",{style:{display:"flex",gap:8},children:[t.jsxs("button",{className:"btn primary sm",disabled:!M.name.trim()||!M.systemPrompt.trim(),onClick:J,children:[t.jsx(ot,{size:13})," ",p("group.setup.tempSave")]}),t.jsx("button",{className:"btn ghost sm",onClick:()=>z(null),children:p("group.setup.close")})]})]}):t.jsxs(t.Fragment,{children:[e.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{fontSize:"var(--ui-font-meta, 12px)",fontWeight:600,margin:"8px 0 6px",color:"var(--text-dim)"},children:p("group.setup.savedAgents")}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4,marginBottom:12},children:e.map(g=>{const O=k.includes(g.slug);return t.jsxs("button",{onClick:()=>U(g.slug),style:{display:"flex",alignItems:"center",gap:10,textAlign:"left",padding:"8px 10px",borderRadius:"var(--radius-sm, 6px)",border:`1px solid ${O?"var(--accent-ink)":"var(--border)"}`,background:O?"var(--accent-soft)":"transparent",color:"inherit",cursor:"pointer"},children:[t.jsx("span",{style:{width:16,height:16,borderRadius:4,flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",border:`1px solid ${O?"var(--accent-ink)":"var(--border)"}`,background:O?"var(--accent-ink)":"transparent"},children:O&&t.jsx(ot,{size:12,color:"var(--on-accent-ink, var(--on-accent))"})}),t.jsxs("span",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:"var(--ui-font-body, 13px)",fontWeight:600},children:g.name}),g.description&&t.jsx("div",{style:{fontSize:"var(--ui-font-caption, 11px)",color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:g.description})]})]},g.slug)})})]}),t.jsx("div",{style:{fontSize:"var(--ui-font-meta, 12px)",fontWeight:600,margin:"8px 0 6px",color:"var(--text-dim)"},children:p("group.setup.tempAgents")}),A.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4,marginBottom:8},children:A.map(g=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 10px",borderRadius:"var(--radius-sm, 6px)",border:"1px solid var(--accent-ink)",background:"var(--accent-soft)"},children:[t.jsx(ho,{size:14,style:{flexShrink:0,opacity:.8}}),t.jsxs("span",{style:{flex:1,minWidth:0},children:[t.jsx("span",{style:{fontSize:"var(--ui-font-body, 13px)",fontWeight:600},children:g.name}),t.jsx("span",{style:{fontSize:"var(--ui-font-caption, 11px)",color:"var(--text-dim)",marginLeft:6},children:p("group.setup.tempBadge")})]}),t.jsx("button",{className:"icon-btn",title:p("common.edit"),onClick:()=>z({slug:g.slug,name:g.name,description:g.description,model:g.model,systemPrompt:g.systemPrompt,thinkingLevel:g.thinkingLevel,maxIterations:g.maxIterations!=null?String(g.maxIterations):"",approvalMode:g.approvalMode}),children:t.jsx(Vn,{size:13})}),t.jsx("button",{className:"icon-btn",title:p("common.delete"),onClick:()=>E(O=>O.filter(Y=>Y.slug!==g.slug)),children:t.jsx($s,{size:13})})]},g.slug))}),t.jsxs("button",{className:"btn ghost sm",style:{marginBottom:14},onClick:()=>z(ru()),children:[t.jsx(Bn,{size:13})," ",p("group.setup.addTemp")]}),t.jsx("div",{style:{fontSize:"var(--ui-font-meta, 12px)",color:"var(--text-dim)",margin:"6px 0 14px"},children:p("group.setup.selfPacedHint")}),t.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[i&&!c&&t.jsx("button",{className:"btn sm",onClick:()=>{l(),h()},children:p("group.setup.disable")}),t.jsx("button",{className:"btn primary sm",onClick:C,disabled:!L,children:p(i?"group.setup.update":"group.setup.start")})]}),!L&&t.jsx("div",{style:{fontSize:"var(--ui-font-caption, 11px)",color:"var(--danger)",textAlign:"right",marginTop:6},children:p("group.setup.needTwo")})]})]})})},In=2e5,js=(e,n,a)=>Jc(e,e,n,a,void 0,void 0,{context:3});function uu(e){if(!/^\*\*\* (Begin Patch|(Add|Update|Delete) File:)/m.test(e))return null;const n=e.replace(/\r\n/g,`
|
|
2
|
+
`).split(`
|
|
3
|
+
`),a=/^\*\*\* (Add|Update|Delete) File: (.+)$/,o=r=>a.test(r)||/^\*\*\* (Begin|End) Patch$/.test(r.trim()),i=[];let c=0;for(;c<n.length;){const r=a.exec(n[c]);if(!r){c++;continue}const l=r[1],h=r[2].trim();c++;let p="";const f=l==="Update"?/^\*\*\* Move to: (.+)$/.exec(n[c]??""):null;f&&(p=f[1].trim(),c++);const k=[];for(;c<n.length&&!o(n[c]);)k.push(n[c]),c++;if(l==="Delete"){i.push(`--- ${h}`,"+++ /dev/null","@@ -1,1 +0,0 @@","-(deleted)");continue}if(l==="Add"){const z=k.filter(B=>B.startsWith("+")).map(B=>B.slice(1));if(!z.length)continue;i.push("--- /dev/null",`+++ ${h}`,`@@ -0,0 +1,${z.length} @@`,...z.map(B=>"+"+B));continue}const x=[`--- ${h}`,`+++ ${p||h}`];let A=[],E="";const M=()=>{if(!A.length)return;const z=A.filter(_=>_[0]!=="+").length,B=A.filter(_=>_[0]!=="-").length;x.push(`@@ -1,${z} +1,${B} @@${E?" "+E:""}`,...A),A=[]};for(const z of k){const B=/^@@ ?(.*)$/.exec(z);if(B){M(),E=B[1]||"";continue}z.startsWith("+")||z.startsWith("-")||z.startsWith(" ")?A.push(z):A.push(" "+z)}M(),x.length>2&&i.push(...x)}return i.length?i.join(`
|
|
4
|
+
`)+`
|
|
5
|
+
`:null}function du(e,n){if(!n)return null;let a;try{a=JSON.parse(n)}catch{return null}if(!a||typeof a!="object")return null;const o=typeof a.path=="string"&&a.path?a.path:"file";try{switch(e){case"edit_file":{const i=String(a.old_string??""),c=String(a.new_string??"");return!i&&!c||i.length+c.length>In?null:js(o,i,c)}case"multi_edit":{if(!Array.isArray(a.edits)||!a.edits.length)return null;let i=0;const c=[];for(let r=0;r<a.edits.length;r++){const l=a.edits[r],h=String(l?.old_string??""),p=String(l?.new_string??"");if(i+=h.length+p.length,i>In)return null;c.push(js(a.edits.length>1?`${o} · #${r+1}`:o,h,p))}return c.join(`
|
|
6
|
+
`)}case"write_file":{const i=String(a.content??"");return!i||i.length>In?null:js(o,"",i)}case"apply_patch":{const i=String(a.patch??a.input??a.diff??"");return i.length>In?null:/^@@[ -]/m.test(i)&&/^(--- |\+\+\+ )/m.test(i)?i:uu(i)}default:return null}}catch{return null}}xe({"approval.remoteReadOnly":{zh:"远程连接下只能原样批准或拒绝,要改命令请在那台设备本机上操作",en:"Over a remote connection you can only approve or reject as is. To change the command, use that device itself"},"approval.remote.caller":{zh:"来自远程会话 · {name}",en:"From a remote session · {name}"},"approval.remote.device":{zh:"来自远程会话 · 已登记设备",en:"From a remote session · a registered device"},"approval.remote.account":{zh:"来自远程会话 · 账号下未识别的客户端",en:"From a remote session · an unidentified client on your account"},"approval.remote.lan":{zh:"来自远程会话 · 局域网配对设备",en:"From a remote session · a LAN-paired device"},"approval.remote.p2p":{zh:"来自远程会话 · 点对点直连",en:"From a remote session · a peer-to-peer connection"},"approval.remote.unknown":{zh:"来自远程会话",en:"From a remote session"},"approval.localOnly":{zh:"这项操作涉及受保护的配置,只能在执行它的电脑上批准",en:"This touches protected configuration and can only be approved on the computer running it"},"approval.byHost":{zh:"在执行的电脑上",en:"on the host computer"},"approval.byHostNamed":{zh:"在执行的电脑上({device})",en:"on the host computer ({device})"},"approval.byDevice":{zh:"在 {device} 上",en:"on {device}"},"approval.byRegisteredDevice":{zh:"在已登记设备上",en:"on a registered device"},"approval.byOther":{zh:"在另一台设备上",en:"on another device"},"approval.byChannel":{zh:"经消息通道",en:"via a messaging channel"}});const Hs=new Set,yh=e=>Hs.has(e),hu=e=>Lr(Pr(e)).remoteApprover,Ai=480,kh=({req:e,onDecide:n,sessionId:a})=>{const{t:o}=Ce(),i=hu(a),c=Er(a),r=e.name==="run_bash",l=(()=>{if(!r||!e.arguments)return"";try{return String(JSON.parse(e.arguments).command??"")}catch{return""}})(),[h,p]=u.useState(l),f=u.useRef(null),[k,x]=u.useState(!1);u.useLayoutEffect(()=>{const g=f.current;if(!g)return;g.style.height="auto";const O=g.scrollHeight;g.style.height=`${Math.min(O,Ai)}px`,x(O>Ai)},[h]);const A=Qc.test(h),E=el.test(h),M=e.status!=="pending",z=u.useMemo(()=>r?null:du(e.name,e.arguments),[r,e.name,e.arguments]),B=Rr(e.reason)&&!i,_=Tr(e.reason,o),L=Ir(e.remote,o),U=!(e.localOnly&&i),J=M?$r(e.answeredBy,{remotePage:i,answeredHere:Hs.has(e.approvalId),hostName:c},o):"",C=g=>{if(M||g!=="reject"&&!U)return;Hs.add(e.approvalId);const O=r&&!i&&h.trim()&&h!==l?{command:h}:void 0;n(g,g==="reject"?void 0:O)};return t.jsxs("div",{className:`approval-card${M?" resolved":""}`,children:[t.jsxs("div",{className:"approval-title",children:[t.jsx(Rl,{size:15,style:{color:"var(--accent-ink)"}}),o("approval.requestExec",{name:e.name}),M&&t.jsxs("span",{style:{fontWeight:400,fontSize:"var(--ui-font-meta, 12px)",color:"var(--text-faint)"},children:[e.status==="approved"?o("approval.statusApproved"):e.status==="rejected"?o("approval.statusRejected"):o("approval.statusExpired"),J&&t.jsxs("span",{"data-answered-by":!0,children:[" · ",J]})]})]}),L&&t.jsx("div",{className:"approval-why","data-approval-remote":!0,children:L}),_&&t.jsx("div",{className:"approval-why",children:_}),r&&!M&&!i?t.jsx("textarea",{className:"approval-edit",value:h,onChange:g=>p(g.target.value),ref:f,rows:1,spellCheck:!1}):null,r&&!M&&(k||A||E)&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"approval-why",children:[k&&t.jsx("div",{children:o("approval.cmdOverflow")}),A&&t.jsx("div",{children:o("approval.cmdHiddenChars")}),E&&t.jsx("div",{children:o("approval.cmdWideBlank")})]}),(A||E)&&t.jsx("div",{className:"approval-preview",children:e.preview})]}),r&&!M&&!i?null:t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"approval-preview",children:e.preview}),z&&t.jsx("div",{className:"approval-diff",children:t.jsx(Zc,{text:z,side:!1})}),i&&!M&&U&&t.jsx("div",{className:"approval-why","data-remote-readonly":!0,children:o("approval.remoteReadOnly")}),!M&&!U&&t.jsx("div",{className:"approval-why","data-local-only":!0,children:o("approval.localOnly")})]}),!M&&t.jsxs("div",{className:"approval-actions",children:[U&&t.jsxs("button",{className:"btn primary sm",onClick:()=>C("approve"),children:[t.jsx(ot,{size:13})," ",o("approval.approve")]}),B&&U&&t.jsxs("button",{className:"btn ghost sm",onClick:()=>C("approve_always"),children:[t.jsx(Hc,{size:13})," ",o("approval.approveAlways")]}),t.jsxs("button",{className:"btn danger sm",onClick:()=>C("reject"),children:[t.jsx(at,{size:13})," ",o("approval.reject")]})]})]})},pu=["readonly","auto-edit","full-auto"],mu={base:"auto-edit"},Ss=e=>e.join(`
|
|
7
|
+
`),Ns=e=>e.split(`
|
|
8
|
+
`).map(n=>n.trim()).filter(Boolean),fu=({cfg:e,onClose:n})=>{const{t:a}=Ce(),[o,i]=u.useState(mu.base),[c,r]=u.useState({deny:"",ask:"",allow:""}),[l,h]=u.useState(!0),[p,f]=u.useState(!1),[k,x]=u.useState(!1),[A,E]=u.useState(""),M=mn.useRef(e);M.current=e;const z=mn.useCallback(()=>{h(!0),E(""),Dr(it()).then(L=>{i(L.base),r({deny:Ss(L.deny),ask:Ss(L.ask),allow:Ss(L.allow)}),f(!0),h(!1)}).catch(L=>{E(String(L?.message||L)),f(!1),h(!1)})},[]);u.useEffect(()=>{z()},[z]);const B=async()=>{if(p){x(!0),E("");try{await Or(it(),{base:o,deny:Ns(c.deny),ask:Ns(c.ask),allow:Ns(c.allow)}),n()}catch(L){E(String(L?.message||L)),x(!1)}}},_=L=>t.jsxs("div",{className:"field",children:[t.jsx("label",{children:t.jsx("b",{children:a(`approvalRules.${L}`)})}),t.jsx("div",{className:"hint",children:a(`approvalRules.${L}Hint`)}),t.jsx("textarea",{value:c[L],onChange:U=>r(J=>({...J,[L]:U.target.value})),rows:3,spellCheck:!1,placeholder:a(`approvalRules.${L}Ph`),style:{width:"100%",fontFamily:"var(--font-mono)",fontSize:"var(--ui-font-meta, 12px)"}})]},L);return t.jsx("div",{className:"apvr-modal",onClick:n,style:{position:"fixed",inset:0,background:"var(--overlay-scrim)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},children:t.jsxs("div",{onClick:L=>L.stopPropagation(),style:{background:"var(--bg-card)",border:"var(--border-width) solid var(--border)",borderRadius:"var(--radius-lg, 12px)",padding:18,width:"min(620px, 92vw)",maxHeight:"86vh",overflow:"auto",boxShadow:"var(--card-shadow)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:10},children:[t.jsx("b",{children:a("approvalRules.title")}),t.jsx("button",{className:"icon-btn",onClick:n,children:t.jsx(at,{size:15})})]}),l?t.jsx("div",{className:"field",children:t.jsxs("div",{className:"hint",children:[t.jsx(Kt,{size:14,className:"spin"})," ",a("common.loading")]})}):p?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"field",children:[t.jsx("div",{className:"hint",children:a("approvalRules.scopeNote")}),t.jsx("div",{className:"hint",style:{marginTop:4},children:a("approvalRules.syntax")})]}),t.jsxs("div",{className:"field",children:[t.jsx("label",{children:t.jsx("b",{children:a("approvalRules.base")})}),t.jsx("div",{className:"hint",children:a("approvalRules.baseHint")}),t.jsx("div",{style:{display:"flex",gap:6,marginTop:6},children:pu.map(L=>t.jsx("button",{className:`btn sm${o===L?" primary":" ghost"}`,onClick:()=>i(L),children:a(_r[L])},L))})]}),["deny","ask","allow"].map(_),A&&t.jsx("div",{className:"field",children:t.jsx("div",{className:"hint",style:{color:"var(--danger)"},children:A})})]}):t.jsxs("div",{className:"field",children:[t.jsx("div",{className:"hint",style:{color:"var(--danger)"},children:a("approvalRules.loadFailed")}),t.jsx("div",{className:"hint",children:A}),t.jsx("div",{style:{marginTop:8},children:t.jsx("button",{className:"btn sm ghost",onClick:z,children:a("common.retry")})})]}),t.jsxs("div",{style:{display:"flex",gap:6,justifyContent:"flex-end",marginTop:14},children:[t.jsx("button",{className:"btn ghost sm",onClick:n,children:a("common.cancel")}),t.jsxs("button",{className:"btn primary sm",disabled:!p||k,onClick:()=>{B()},children:[k?t.jsx(Kt,{size:13,className:"spin"}):null," ",a("common.save")]})]})]})})},gu=[{name:"/help",key:"help",zh:"显示帮助与命令列表",en:"Show help and the command list",surfaces:["tui","desktop","channel"]},{name:"/feedback",key:"feedback",zh:"提交问题或建议,可在命令后填写反馈内容",en:"Report an issue or suggestion; optionally add your feedback after the command",surfaces:["desktop"]},{name:"/new",key:"new",zh:"开始新会话",en:"Start a new session",surfaces:["tui","desktop","channel"]},{name:"/clear",key:"clear",zh:"清屏(保留会话历史)",en:"Clear the screen (history is kept)",surfaces:["tui"]},{name:"/sessions",key:"sessions",aliases:["/list"],zh:"列出最近会话",en:"List recent sessions",surfaces:["tui","desktop","channel"]},{name:"/resume",key:"resume",aliases:["/switch"],zh:"恢复会话并续聊",en:"Resume a session and continue",arg:"<id|序号>",surfaces:["tui","channel"]},{name:"/rename",key:"rename",arg:"<标题>",zh:"重命名本会话",en:"Rename this session",surfaces:["tui"]},{name:"/branch",key:"branch",arg:"[序号]",aliases:["/fork"],zh:"从某条回复后分支新会话(继承历史),缺省最近",en:"Branch a new session from a reply (inherits history); defaults to the latest",surfaces:["tui","desktop"]},{name:"/btw",key:"btw",arg:"[问题]",aliases:["/side"],zh:"顺便问一句:带着本会话上下文旁聊,不进主对话、不打断正在跑的任务",en:"Ask a side question with this session as context; not added to the conversation and never interrupts a running task",surfaces:["desktop"]},{name:"/compact",key:"compact",arg:"[关注点]",zh:"压缩上下文:总结后精简续接(同会话;可附本次摘要的关注点)",en:"Compact context: summarize, then continue compactly (optional focus for this summary)",surfaces:["tui","desktop","channel"]},{name:"/status",key:"status",zh:"本会话概况:模型 / 思考档 / 审批档 / 工作目录 / 用量",en:"Session overview: model, thinking level, approval mode, cwd, usage",surfaces:["tui","desktop","channel"]},{name:"/export",key:"export",zh:"导出本会话为 Markdown",en:"Export this session as Markdown",surfaces:["tui","desktop"]},{name:"/cost",key:"cost",zh:"本会话 token 用量与费用",en:"Token usage and cost for this session",surfaces:["tui","desktop","channel"]},{name:"/diff",key:"diff",zh:"查看工作目录的 git 改动(含未跟踪文件)",en:"Show git changes in the working directory (including untracked files)",surfaces:["tui"]},{name:"/copy",key:"copy",zh:"复制上一条回复到剪贴板",en:"Copy the last reply to the clipboard",surfaces:["tui","desktop"]},{name:"/retry",key:"retry",zh:"重跑上一条用户消息",en:"Re-run the last user message",surfaces:["tui","desktop"]},{name:"/edit",key:"edit",zh:"编辑最近一条消息并重跑($EDITOR)",en:"Edit the last message and re-run ($EDITOR)",surfaces:["tui"]},{name:"/delete",key:"delete",zh:"删除最近一轮对话",en:"Delete the last turn",surfaces:["tui"]},{name:"/queue",key:"queue",arg:"[clear]",zh:"查看排队项:运行中发的消息与 /compact 等命令排到本轮结束后依次执行(/queue clear 清空)",en:"Show queued items: messages and commands like /compact sent while running run in order after this turn (/queue clear to empty)",surfaces:["tui"]},{name:"/stop",key:"stop",zh:"停止当前运行",en:"Stop the current run",surfaces:["desktop","channel"]},{name:"/model",key:"model",arg:"[名称|序号]",zh:"切换模型(不带参数列出可选模型)",en:"Switch model (no argument lists the available models)",surfaces:["tui","desktop","channel"]},{name:"/think",key:"think",arg:"<档位>",aliases:["/effort"],zh:"思考强度:off|minimal|low|medium|high|xhigh|max(模型不支持的档自动降档)",en:"Thinking level: off|minimal|low|medium|high|xhigh|max (auto-clamped to what the model supports)",surfaces:["tui","desktop","channel"]},{name:"/approval",key:"approval",arg:"<档位>",aliases:["/permissions"],zh:"查看或切换审批档:readonly|auto-edit|full-auto|custom",en:"Show or switch the approval mode: readonly|auto-edit|full-auto|custom",surfaces:["tui","desktop","channel"]},{name:"/loop",key:"loop",arg:"<1-200>",zh:"最大循环轮数(默认 90;耗尽会提示)",en:"Max loop iterations (default 90; you get a prompt when exhausted)",surfaces:["tui","desktop","channel"]},{name:"/verify",key:"verify",arg:"<命令|off>",zh:"本会话验证命令:收尾前自动跑,不绿不许收(off 关闭)",en:"Session verify command — runs before the turn may end; must pass (off to clear)",surfaces:["desktop"]},{name:"/plan",key:"plan",zh:"切换计划模式:只读调研 → 提交计划求批准",en:"Toggle plan mode: read-only research, then submit a plan for approval",surfaces:["tui","desktop"]},{name:"/chat",key:"chat",zh:"切到 Chat 模式(轻量:答完即停、临时工作区、不写笔记;侧栏只列聊天会话,新会话按此模式创建,已创建的会话不可切换)",en:"Switch to Chat mode (light: answers and stops, temporary workspace, never writes your notes; the sidebar lists chat sessions only, new sessions use it, existing sessions are fixed)",surfaces:["desktop"]},{name:"/work",key:"work",zh:"切到 Work 模式(完整工具面:文件、命令、技能、子代理;侧栏列出全部项目)",en:"Switch to Work mode (full toolset: files, commands, skills, subagents; the sidebar lists all projects)",surfaces:["desktop"]},{name:"/voice",key:"voice",zh:"切到语音消息(该 Agent 回复变语音)",en:"Switch to voice messages (this agent replies as voice)",surfaces:["desktop","channel"]},{name:"/text",key:"text",zh:"切回文字消息",en:"Switch back to text messages",surfaces:["channel"]},{name:"/cwd",key:"cwd",arg:"[path]",zh:"查看或切换工作目录",en:"Show or change the working directory",surfaces:["tui"]},{name:"/config",key:"config",zh:"查看当前设置",en:"Show current settings",surfaces:["tui","desktop"]},{name:"/login",key:"login",zh:"重新登录 Forsion",en:"Sign in to Forsion again",surfaces:["tui","desktop"]},{name:"/hotkeys",key:"hotkeys",zh:"查看快捷键",en:"Show keyboard shortcuts",surfaces:["tui"]},{name:"/exit",key:"exit",zh:"退出 Tangu",en:"Quit Tangu",surfaces:["tui"]},{name:"/tools",key:"tools",zh:"列出当前模式可用工具",en:"List tools available in the current mode",surfaces:["tui","desktop"]},{name:"/skills",key:"skills",zh:"列出可用技能(✓=本会话启用)",en:"List available skills (✓ = enabled for this session)",surfaces:["tui","desktop"]},{name:"/skill",key:"skill",arg:"<id>",zh:"启用/停用技能",en:"Enable or disable a skill",surfaces:["tui"]},{name:"/agents",key:"agents",zh:"列出本地 Normal Agent(自定义人格)",en:"List local normal agents (custom personas)",surfaces:["tui","desktop","channel"]},{name:"/agent",key:"agent",arg:"<slug>",zh:"启用 Agent;管理:/agent new|edit|rm <slug>",en:"Activate an agent; manage with /agent new|edit|rm <slug>",surfaces:["tui","desktop","channel"]},{name:"/groupchat",key:"groupchat",arg:"<slug…>",zh:"团队模式(/groupchat off 退出)",en:"Team mode (/groupchat off to leave)",surfaces:["tui","desktop"]},{name:"/historian",key:"historian",zh:"Historian 状态/活动;/historian on|off 开关",en:"Historian status/activity; /historian on|off to toggle",surfaces:["tui","desktop"]},{name:"/muse",key:"muse",zh:"Muse 状态/TODO;/muse on|off 开关",en:"Muse status/TODOs; /muse on|off to toggle",surfaces:["tui","desktop"]},{name:"/memory",key:"memory",arg:"[edit]",zh:"查看/编辑长期记忆",en:"View or edit long-term memory",surfaces:["tui","desktop"]},{name:"/refine",key:"refine",arg:"[focus]",zh:"复盘本会话,沉淀 Agent 的进化记录(可回滚)",en:"Reflect on this conversation and refine the agent's evolution record (reversible)",surfaces:["tui","desktop"]},{name:"/log",key:"log",arg:"[YYYY-MM-DD]",zh:"查看每日日志",en:"View the daily log",surfaces:["tui"]},{name:"/mcp",key:"mcp",zh:"列出 MCP server 状态",en:"List MCP server status",surfaces:["tui","desktop"]},{name:"/plugins",key:"plugins",zh:"列出已发现插件",en:"List discovered plugins",surfaces:["tui","desktop"]}];function Ei(e){return gu.filter(n=>n.surfaces.includes(e))}xe({"addMenu.label":{zh:"添加",en:"Add"},"addMenu.newChat":{zh:"新会话",en:"New session"},"addMenu.agent":{zh:"添加 Agent",en:"Add agent"},"addMenu.files":{zh:"添加文件或文件夹",en:"Add files or folders"},"addMenu.camera":{zh:"拍照",en:"Take photo"},"addMenu.photos":{zh:"相册",en:"Photos"},"addMenu.file":{zh:"文件",en:"Files"},"addMenu.conversation":{zh:"添加会话",en:"Add session"},"addMenu.view":{zh:"添加正在使用的 View",en:"Add an active View"},"addMenu.searchChats":{zh:"搜索全部会话",en:"Search all sessions"},"addMenu.searchViews":{zh:"搜索全部 View",en:"Search all Views"},"addMenu.recent":{zh:"最近使用",en:"Recent"},"addMenu.allChats":{zh:"全部会话",en:"All sessions"},"addMenu.inUse":{zh:"正在使用",en:"In use"},"addMenu.allViews":{zh:"全部 View",en:"All Views"},"addMenu.noMatches":{zh:"没有匹配项",en:"No matches"}});const Cs=new Set(["chat","chat-panel","home","launcher","sidebar-empty"]),vu=300;function yu(e,n,a=vu){const o=new Set(e.map(c=>c.id)),i=n.filter(c=>!o.has(c.id));return i.length>a?null:{recent:[...e],rest:i}}function $n(e){const n=new Set;return e.filter(a=>n.has(a.key)?!1:(n.add(a.key),!0))}const ku=({open:e,disabled:n,activeSessionId:a,canUsePathPicker:o,onOpenChange:i,onNewSession:c,onAddAgent:r,onPickPaths:l,onPickFiles:h,onAddReference:p})=>{const{t:f}=Ce(),[k,x]=u.useState(null),[A,E]=u.useState(""),[M,z]=u.useState("right"),[B,_]=u.useState(0),L=u.useRef(null),U=u.useRef(null),J=u.useRef(null),C=u.useRef(null),g=Yt(e,{boundary:".t2-chat-view"}),O=Yt(k?`${k}:${M}`:"",{boundary:".t2-chat-view"}),Y=D(b=>b.sessions),F=D(b=>b.archivedSessions),P=tl(b=>b.items),$=Dn(b=>b.mainTabs),W=Dn(b=>b.leftTabs),K=Dn(b=>b.rightTabs),Q=hn(b=>b.vaultRoot);u.useEffect(()=>{e||(x(null),E(""))},[e]),u.useEffect(()=>{E(""),k&&requestAnimationFrame(()=>J.current?.focus())},[k]),u.useLayoutEffect(()=>{const b=L.current,V=U.current;if(!k||!b||!V)return;const H=()=>{const qe=b.getBoundingClientRect(),lt=(b.closest(".t2c-card")||b.closest(".t2-chat-view"))?.getBoundingClientRect(),He=Xi(V),Ve=lt?Gi(qe.left,qe.right,V.offsetWidth,lt.left,lt.right,He):"right";z(m=>m===Ve?m:Ve),_(m=>m===b.offsetHeight+6?m:b.offsetHeight+6)};H(),window.addEventListener("resize",H),window.addEventListener(Un,H);const se=new ResizeObserver(H);se.observe(b),se.observe(V);const Ne=b.closest(".t2c-card")||b.closest(".t2-chat-view");return Ne&&se.observe(Ne),()=>{window.removeEventListener("resize",H),window.removeEventListener(Un,H),se.disconnect()}},[k]);const Z=u.useMemo(()=>{const b=new Set;return[...Y,...F].filter(V=>V.id===a||b.has(V.id)?!1:(b.add(V.id),!0))},[Y,F,a]),T=u.useMemo(()=>{const b=new Map(Z.map(H=>[H.id,H])),V=P.filter(H=>H.kind==="chat").map(H=>b.get(H.id)).filter(Boolean);return(V.length?V:Z).slice(0,6)},[Z,P]),ae=u.useMemo(()=>{const b=A.trim().toLocaleLowerCase();return b?Z.filter(V=>`${V.title||""}
|
|
9
|
+
${V.summary||""}`.toLocaleLowerCase().includes(b)).slice(0,12):T},[A,T,Z]),y=u.useMemo(()=>{const b=$.flatMap(H=>{if(Cs.has(H.type))return[];const se=H.title||ri(fs(H.type)?.displayName||H.type);if(H.filePath){const Ne=H.type==="amadeus-editor"&&!!Q;return[{key:`${Ne?"note":"file"}:${H.filePath}`,type:H.type,title:se,ref:Ne?{kind:"note",path:H.filePath}:{kind:"file",path:H.filePath},meta:H.filePath}]}return[{key:`view:${H.type}`,type:H.type,title:se,ref:{kind:"view",type:H.type,title:se}}]}),V=[...W,...K].flatMap(H=>Cs.has(H.type)?[]:[{key:`view:${H.type}`,type:H.type,title:H.title,ref:{kind:"view",type:H.type,title:H.title}}]);return $n([...b,...V]).slice(0,8)},[$,W,K,Q]),q=u.useMemo(()=>$n(P.flatMap(b=>b.kind==="chat"?[]:b.kind==="note"?[{key:b.key,type:"amadeus-editor",title:b.title,ref:{kind:"note",path:b.id},meta:b.id}]:b.kind==="file"&&b.viewType?[{key:b.key,type:b.viewType,title:b.title,ref:{kind:"file",path:b.id},meta:b.id}]:b.kind==="view"&&b.viewType&&fs(b.viewType)?[{key:b.key,type:b.viewType,title:b.title,ref:{kind:"view",type:b.viewType,title:b.title}}]:[])).slice(0,6),[P]),te=Fr().filter(b=>!Cs.has(b.type)).map(b=>{const V=ri(b.displayName);return{key:`view:${b.type}`,type:b.type,title:V,ref:{kind:"view",type:b.type,title:V}}}),Se=(()=>{const b=A.trim().toLocaleLowerCase();return b?$n([...y,...q,...te]).filter(V=>`${V.title}
|
|
10
|
+
${V.type}
|
|
11
|
+
${V.meta||""}`.toLocaleLowerCase().includes(b)).slice(0,12):[]})(),ge=b=>{p(b),i(!1)},ye=async b=>{i(!1);const V=await b();if(!V.length)return;const H=new DataTransfer;V.forEach(se=>H.items.add(se)),await h(H.files)},Be=async()=>{if(o&&window.tangu?.pickPaths){i(!1);const b=await window.tangu.pickPaths();b.length&&await l(b);return}if(window.tangu?.pickFiles)return ye(()=>window.tangu.pickFiles());C.current?.click()},Ie=b=>fs(b)?.icon||_n,Ae=b=>{const V=b.ref.kind==="file"||b.ref.kind==="note"?ta:Ie(b.type);return{id:`ref:${b.key}`,label:b.title,detail:b.meta,icon:t.jsx(V,{size:14}),run:()=>ge(b.ref)}},Le=b=>({id:`session:${b.id}`,label:b.title||"Chat",detail:b.summary||void 0,icon:t.jsx(Ht,{size:14}),run:()=>ge({kind:"session",id:b.id,title:b.title||"Chat"})}),Ee={id:"new-chat",label:f("addMenu.newChat"),icon:t.jsx(ul,{size:14}),run:()=>{c?.(),i(!1)}},Pe=r?{id:"add-agent",act:"add-agent",label:f("addMenu.agent"),icon:t.jsx(ho,{size:14}),run:()=>{r(),i(!1)}}:null,De={id:"files",label:f("addMenu.files"),icon:t.jsx(Ur,{size:14}),run:()=>{Be()}},_e=window.tangu,Ue=_e?.takePhoto&&_e.pickPhotos&&_e.pickFiles?[{id:"camera",label:f("addMenu.camera"),icon:t.jsx(Wr,{size:14}),run:()=>{ye(()=>_e.takePhoto())}},{id:"photos",label:f("addMenu.photos"),icon:t.jsx(Br,{size:14}),run:()=>{ye(()=>_e.pickPhotos())}},{...De,label:f("addMenu.file")}]:[De],ct=()=>{const b=yu(T,Z),V=$n([...y,...q]),H=new Set(V.map(Ne=>Ne.key)),se=f("addMenu.noMatches");return{title:f("addMenu.label"),back:f("common.back"),sections:[{items:[Ee,...Pe?[Pe]:[],...Ue,b?{id:"conversation",label:f("addMenu.conversation"),icon:t.jsx(Ht,{size:14}),search:{placeholder:f("addMenu.searchChats"),empty:se},children:[{title:f("addMenu.recent"),items:b.recent.map(Le)},{title:f("addMenu.allChats"),items:b.rest.map(Le)}]}:{id:"conversation",label:f("addMenu.conversation"),icon:t.jsx(Ht,{size:14}),run:()=>{i(!0),x("conversation")}},{id:"view",label:f("addMenu.view"),icon:t.jsx(_n,{size:14}),search:{placeholder:f("addMenu.searchViews"),empty:se},children:[{title:f("addMenu.inUse"),items:y.map(Ae)},{title:f("addMenu.recent"),items:q.filter(Ne=>!y.some(qe=>qe.key===Ne.key)).map(Ae)},{title:f("addMenu.allViews"),items:te.filter(Ne=>!H.has(Ne.key)).map(Ae)}]}]}]}},Tt=b=>b.map(V=>{const H=Ae(V);return t.jsxs("button",{className:"menu-item add-menu-result",title:V.meta||V.title,onClick:H.run,children:[H.icon,t.jsxs("span",{className:"grow add-menu-result-main",children:[t.jsx("span",{className:"add-menu-result-title",children:H.label}),H.detail&&t.jsx("span",{className:"add-menu-result-meta",children:H.detail})]})]},V.key)});return t.jsxs("span",{className:`add-pill-wrap t2c-capsule-peer${e?" is-open":""}`,"data-cmenu":!0,children:[t.jsxs("button",{className:`t2c-pill add-pill-btn${e?" is-open":""}`,title:f("input.addContent"),"aria-expanded":e,disabled:n,onClick:()=>{!e&&aa(ct,{})||i(!e)},children:[t.jsx(Bn,{size:16,className:"add-pill-plus"}),t.jsx("span",{className:"add-pill-label",children:f("addMenu.label")}),t.jsx(yn,{size:10,className:"add-pill-chevron"})]}),e&&t.jsxs("div",{ref:b=>{L.current=b,g.ref.current=b},className:"composer-menu composer-menu--add",style:g.style,children:[t.jsxs("button",{className:"menu-item",onClick:Ee.run,children:[Ee.icon,t.jsx("span",{className:"grow",children:Ee.label})]}),Pe&&t.jsxs("button",{className:"menu-item","data-add-agent":!0,onClick:Pe.run,children:[Pe.icon,t.jsx("span",{className:"grow",children:Pe.label})]}),t.jsxs("button",{className:"menu-item",onClick:De.run,children:[De.icon,t.jsx("span",{className:"grow",children:De.label})]}),t.jsxs("button",{className:`menu-item add-menu-parent${k==="conversation"?" active":""}`,"aria-expanded":k==="conversation",onPointerEnter:()=>x("conversation"),onFocus:()=>x("conversation"),onClick:()=>x("conversation"),children:[t.jsx(Ht,{size:14}),t.jsx("span",{className:"grow",children:f("addMenu.conversation")}),t.jsx(Et,{size:13})]}),t.jsxs("button",{className:`menu-item add-menu-parent${k==="view"?" active":""}`,"aria-expanded":k==="view",onPointerEnter:()=>x("view"),onFocus:()=>x("view"),onClick:()=>x("view"),children:[t.jsx(_n,{size:14}),t.jsx("span",{className:"grow",children:f("addMenu.view")}),t.jsx(Et,{size:13})]})]}),e&&k&&t.jsxs("div",{ref:b=>{U.current=b,O.ref.current=b},className:`composer-menu add-menu-sub ${M}`,"data-pane":k,style:{...O.style,bottom:M==="stacked"?`calc(100% + ${B}px)`:void 0},children:[t.jsxs("label",{className:"add-menu-search",children:[t.jsx(Yi,{size:13}),t.jsx("input",{ref:J,value:A,onChange:b=>E(b.currentTarget.value),placeholder:f(k==="conversation"?"addMenu.searchChats":"addMenu.searchViews")})]}),t.jsx("div",{className:"add-menu-sub-scroll",children:k==="conversation"?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"menu-section",children:f(A.trim()?"addMenu.allChats":"addMenu.recent")}),ae.map(b=>{const V=Le(b);return t.jsxs("button",{className:"menu-item add-menu-result",title:b.summary||b.title||"",onClick:V.run,children:[V.icon,t.jsxs("span",{className:"grow add-menu-result-main",children:[t.jsx("span",{className:"add-menu-result-title",children:V.label}),V.detail&&t.jsx("span",{className:"add-menu-result-meta",children:V.detail})]})]},b.id)}),!ae.length&&t.jsx("div",{className:"add-menu-empty",children:f("addMenu.noMatches")})]}):A.trim()?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"menu-section",children:f("addMenu.allViews")}),Tt(Se),!Se.length&&t.jsx("div",{className:"add-menu-empty",children:f("addMenu.noMatches")})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"menu-section",children:f("addMenu.inUse")}),Tt(y),!y.length&&t.jsx("div",{className:"add-menu-empty",children:f("addMenu.noMatches")}),!!q.length&&t.jsx("div",{className:"menu-section add-menu-section-gap",children:f("addMenu.recent")}),Tt(q)]})})]}),t.jsx("input",{ref:C,type:"file",multiple:!0,hidden:!0,onChange:b=>{h(b.currentTarget.files),b.currentTarget.value="",i(!1)}})]})};function wo(e,n){const a=e.agents.filter(l=>l.createdBy!=="system"),o=e.agents.find(l=>l.slug===e.currentAgentSlug),i={id:"normal-work",label:n("input.normalWork"),icon:t.jsx(gs,{size:14}),checked:e.active,disabled:e.disabled,run:()=>{e.onNormalWork(),e.onClose()}},c=e.onAgentSwitch?a.map(l=>({id:`agent:${l.slug}`,label:l.name,icon:t.jsx(gs,{size:14}),checked:e.currentAgentSlug===l.slug,run:()=>{e.onAgentSwitch(l.slug),e.onClose()}})):[],r=c.length?{id:"agent-switch",label:n("input.agentSwitch.section"),detail:o?.name,icon:t.jsx(gs,{size:14}),children:[{items:c}]}:null;return{normal:i,agentSwitch:r,agents:c}}function xu(e){const{currentAgentSlug:n,agents:a}=e,{t:o}=Ce(),[i,c]=u.useState(!1),[r,l]=u.useState("right"),[h,p]=u.useState(0),f=u.useRef(null),k=u.useRef(null),x=Yt(i?r:"",{boundary:".t2-chat-view"}),A=wo(e,o),E=A.agentSwitch?()=>c(!0):void 0,M=a.find(z=>z.slug===n);return u.useLayoutEffect(()=>{const z=f.current,B=k.current,_=z?.closest(".composer-menu");if(!i||!z||!B||!_)return;const L=()=>{const C=_.getBoundingClientRect(),g=(_.closest(".t2c-card")||_.closest(".t2-chat-view"))?.getBoundingClientRect(),O=_.closest(".t2-chat-view")?.getBoundingClientRect(),Y=Xi(B),F=g?Gi(C.left,C.right,B.offsetWidth,g.left,g.right,Y):"right";l($=>$===F?$:F);const P=qr(z.getBoundingClientRect().top,B.offsetHeight,C.top,C.bottom,O?.top??0,O?.bottom??window.innerHeight,Y);p($=>Math.abs($-P)<.5?$:P)};L(),window.addEventListener("resize",L),window.addEventListener(Un,L);const U=new ResizeObserver(L);U.observe(_),U.observe(B);const J=_.closest(".t2c-card")||_.closest(".t2-chat-view");return J&&U.observe(J),()=>{window.removeEventListener("resize",L),window.removeEventListener(Un,L),U.disconnect()}},[i]),u.useEffect(()=>{const z=f.current?.closest(".composer-menu");if(!i||!z)return;const B=_=>{const L=_.target?.closest?.(".menu-item");L&&!f.current?.contains(L)&&c(!1)};return z.addEventListener("pointerover",B),z.addEventListener("focusin",B),()=>{z.removeEventListener("pointerover",B),z.removeEventListener("focusin",B)}},[i]),t.jsxs("div",{ref:f,className:"mode-normal-row",onPointerEnter:E,children:[t.jsxs("button",{className:`menu-item${A.normal.checked?" active":""}`,"data-normal-work":!0,disabled:A.normal.disabled,onClick:A.normal.run,children:[A.normal.icon,t.jsx("span",{className:"grow",children:A.normal.label}),A.normal.checked&&t.jsx(ot,{size:13})]}),E&&t.jsxs("button",{className:"menu-item mode-agent-trigger","data-agent-switch":!0,"aria-haspopup":"menu","aria-expanded":i,title:o("input.agentSwitch.section"),onFocus:E,onClick:E,children:[M&&t.jsx("span",{className:"mode-agent-name",children:M.name}),t.jsx(Et,{size:13})]}),i&&E&&t.jsxs("div",{ref:z=>{k.current=z,x.ref.current=z},className:`cm-sub ${r}`,"data-pane":"agents",role:"menu",style:{...x.style,"--cm-sub-top":`${h}px`},children:[t.jsx("div",{className:"menu-section",children:o("input.agentSwitch.section")}),A.agents.map(z=>t.jsxs("button",{role:"menuitemradio","aria-checked":!!z.checked,className:`menu-item${z.checked?" active":""}`,onClick:z.run,children:[z.icon,t.jsx("span",{className:"grow",children:z.label}),z.checked&&t.jsx(ot,{size:13})]},z.id))]})]})}function wu(e){const n=e.find(o=>o.active),a=(n?.filePath?n:void 0)??e.find(o=>o.front&&o.filePath)??e.find(o=>o.type==="amadeus-editor"&&o.filePath)??e.find(o=>o.filePath);return a?a.type==="amadeus-editor"?a.filePath?`note:${a.filePath}`:"note":a.filePath?`file:${a.filePath}`:"":""}const Ln={color:"var(--accent-ink)",flexShrink:0};function bu({chip:e,onRemove:n,removeTitle:a,children:o}){return t.jsxs("span",{className:"attach-chip",title:e.token,"data-ref-kind":e.kind,children:[e.kind==="session"?t.jsx(Xn,{size:13,style:Ln}):e.kind==="folder"?t.jsx(Kn,{size:13,style:Ln}):e.kind==="view"?t.jsx(_n,{size:13,style:Ln}):t.jsx(ta,{size:13,style:Ln}),t.jsx("span",{children:o??e.name}),n&&t.jsx("button",{type:"button",title:a,"aria-label":a,onClick:n,children:t.jsx(at,{size:12})})]})}const zs=e=>e.replace(/[\\/]+$/,"").split(/[\\/]/).pop()||e,ju=e=>e.replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&");function Su(e){if(/[\s"<>[\]]/.test(e)||e.includes("://"))return!1;const n=/^(~?\/|[A-Za-z]:[\\/])/.test(e),a=e.split(/[\\/]/).filter(Boolean);return n?a.length>=(/^[A-Za-z]:/.test(e)?3:2):a.length>=2&&/\.[A-Za-z0-9]{1,10}$/.test(a[a.length-1])}const Nu=/^\[\[([^[\]\n]+)\]\]/,Cu=/^"([^"\n]+)"/,zu=/^<forsion-view type="([^"\n]*)" title="([^"\n]*)" \/>/,Mu=/^[^\s]+/;function Au(e,n){const a=e.slice(n);let o=Nu.exec(a);if(o){const i=o[1],c=i.indexOf("|"),r=(c===-1?i:i.slice(0,c)).trim(),l=(c===-1?"":i.slice(c+1)).trim();return r?{ref:Hr(r)?{token:o[0],name:l||"Chat",kind:"session",wiki:i}:{token:o[0],name:l||zs(r).replace(/\.md$/i,""),kind:"note",wiki:i},end:n+o[0].length,strong:!0}:null}if(o=zu.exec(a),o)return{ref:{token:o[0],name:ju(o[2]),kind:"view"},end:n+o[0].length,strong:!0};if(o=Cu.exec(a),o){const i=o[1];return!/\s/.test(i)||!/[\\/]/.test(i)?null:{ref:{token:o[0],name:zs(i),kind:"file"},end:n+o[0].length,strong:!0}}return o=Mu.exec(a),o&&Su(o[0])?{ref:{token:o[0],name:zs(o[0]),kind:"file"},end:n+o[0].length,strong:!1}:null}function xh(e){if(!e)return null;const n=e.indexOf(`
|
|
12
|
+
`),a=n===-1?e:e.slice(0,n),o=[];let i=!0,c=0;for(;c<a.length;){const r=Au(a,c);if(!r)return null;if(o.push(r.ref),i=i&&r.strong,c=r.end,c===a.length)break;if(a[c]!==" "||(c+=1,c===a.length))return null}return!o.length||n===-1&&!i?null:{refs:o,body:n===-1?"":e.slice(n+1)}}const Eu=({tier:e})=>{const n=(e||"free").toLowerCase();if(n==="free"||!n)return null;const a=n==="pro"?{background:"linear-gradient(135deg, #8B5CF6, #A855F7)",color:"#fff",border:"none"}:{background:"linear-gradient(135deg, #F59E0B, #F97316)",color:"#fff",border:"none"};return t.jsx("span",{className:"tier-badge",style:a,children:n})};xe({"ctx.pop.title":{zh:"上下文窗口",en:"Context window"},"ctx.pop.compact":{zh:"立即压缩",en:"Compact now"},"ctx.grp.tools":{zh:"工具与本轮",en:"Tools & this run"},"ctx.grp.system":{zh:"系统提示",en:"System prompt"},"ctx.sec.human":{zh:"协作说明",en:"Collaboration handbook"},"ctx.grp.memory":{zh:"记忆",en:"Memory"},"ctx.grp.project":{zh:"项目与资料",en:"Project & files"},"ctx.grp.skills":{zh:"技能",en:"Skills"},"ctx.grp.used":{zh:"已用",en:"Used"},"ctx.grp.buffer":{zh:"自动压缩预留",en:"Auto-compact buffer"},"ctx.grp.free":{zh:"剩余可用",en:"Free space"},"ctx.untilCompact":{zh:"还剩 {left} 触发自动压缩({n},{pct}%)",en:"{left} until auto-compact ({n}, {pct}%)"},"ctx.limit.title":{zh:"Forsion 额度",en:"Forsion usage limits"},"ctx.limit.resetsIn":{zh:"{h} 小时 {m} 分钟后重置",en:"Resets in {h} hr {m} min"},"ctx.limit.resetsAt":{zh:"{when} 重置",en:"Resets {when}"},"ctx.limit.used":{zh:"已用 {pct}%",en:"{pct}% used"}});const Ye=e=>e>=1e6?`${Math.floor(e/1e5)/10}M`:e>=1e3?`${Math.floor(e/100)/10}k`:String(e),Ri=new Set(["persona","harness","human","guidance","profile","project","agentFolder","memory","skills","environment","hooks","plan"]),Ti="var(--model-tag-blue)",Ru=[{id:"system",keys:["persona","guidance","environment","hooks","plan"],color:"var(--warning)"},{id:"memory",keys:["memory","profile","harness","human"],color:"var(--green)"},{id:"project",keys:["project","agentFolder"],color:"color-mix(in srgb, var(--accent-ink) 55%, transparent)"},{id:"skills",keys:["skills"],color:"color-mix(in srgb, var(--model-tag-blue) 45%, var(--green))"}];function Tu(e,n,a){if(!n)return e>0?[{id:"used",label:a("ctx.grp.used"),tokens:e,color:Ti}]:[];let o=Math.max(0,e);const i=h=>{const p=Math.min(o,Math.max(0,h));return o-=p,p},c=Ru.map(h=>{const p=n.sections.filter(x=>h.keys.includes(x.k)||h.id==="system"&&!Ri.has(x.k)),f=p.reduce((x,A)=>x+A.tokens,0),k=i(f);return{id:h.id,label:a(`ctx.grp.${h.id}`),color:h.color,tokens:k,parts:k===f?p.map(x=>({label:Ri.has(x.k)?a(`ctx.sec.${x.k}`):x.k,tokens:x.tokens})):void 0}}),r={id:"messages",label:a("ctx.sec.history",{n:n.historyCount}),tokens:i(n.historyTokens),color:Ti},l={id:"tools",label:a("ctx.grp.tools"),tokens:o,color:"var(--model-tag-purple)"};return[r,l,...c].filter(h=>h.tokens>0)}const bo=8*36e5,Iu=e=>864e5-(e+bo)%864e5;function $u(e){const n=/^(\d{4})-(\d{2})-(\d{2})/.exec(e||"");return n?new Date(Date.UTC(Number(n[1]),Number(n[2])-1,Number(n[3]))-bo):null}function Lu({open:e,contextWindow:n,ctxTokens:a,sessionTokens:o,runCost:i,costLimit:c,ctxInfo:r,onCompact:l}){const{t:h}=Ce(),[p,f]=u.useState(!1),k=a||0,x=_=>_/n*100,A=_=>`${Math.round(x(_)*10)/10}%`,E=Tu(Math.min(k,n),r??null,h),M=r?.compactAt&&r.compactAt<n?r.compactAt:0,z=M?Math.max(0,n-Math.max(M,k)):0,B=Math.max(0,n-k-z);return t.jsxs(t.Fragment,{children:[t.jsxs("button",{type:"button",className:"t2c-cu-head","aria-expanded":p,onClick:()=>f(_=>!_),children:[t.jsx("span",{className:"t2c-cu-title",children:h("ctx.pop.title")}),t.jsxs("span",{className:"t2c-cu-num",children:[Ye(k)," / ",Ye(n)," tokens (",Math.min(100,Math.round(x(k))),"%)"]}),t.jsx(Et,{size:13,className:"t2c-cu-chev","aria-hidden":"true"})]}),t.jsxs("span",{className:"t2c-cu-bar","aria-hidden":"true",children:[E.map(_=>t.jsx("span",{style:{width:`${x(_.tokens)}%`,background:_.color}},_.id)),z>0&&t.jsx("span",{className:"t2c-cu-buffer",style:{width:`${x(z)}%`}})]}),r&&r.ctxWindowSource!=="override"&&(r.ctxWindowMax??0)>r.ctxWindow&&t.jsx("span",{className:"t2c-ctxinfo-src",children:h("ctx.windowCapped",{max:Ye(r.ctxWindowMax),n:Ye(r.ctxWindow)})}),p&&t.jsxs("span",{className:"t2c-cu-detail",children:[t.jsxs("span",{className:"t2c-cu-legend",children:[E.map(_=>t.jsxs(u.Fragment,{children:[t.jsxs("span",{className:"t2c-cu-row",children:[t.jsx("i",{style:{background:_.color}}),t.jsx("span",{children:_.label}),t.jsx("span",{children:Ye(_.tokens)}),t.jsx("span",{children:A(_.tokens)})]}),_.parts&&_.parts.length>1&&_.parts.map(L=>t.jsxs("span",{className:"t2c-cu-row is-sub",children:[t.jsx("i",{}),t.jsx("span",{children:L.label}),t.jsxs("span",{children:["~",Ye(L.tokens)]}),t.jsx("span",{})]},L.label))]},_.id)),z>0&&t.jsxs("span",{className:"t2c-cu-row",children:[t.jsx("i",{className:"t2c-cu-buffer"}),t.jsx("span",{children:h("ctx.grp.buffer")}),t.jsx("span",{children:Ye(z)}),t.jsx("span",{children:A(z)})]}),t.jsxs("span",{className:"t2c-cu-row",children:[t.jsx("i",{className:"is-free"}),t.jsx("span",{children:h("ctx.grp.free")}),t.jsx("span",{children:Ye(B)}),t.jsx("span",{children:A(B)})]})]}),r&&t.jsx("span",{className:"t2c-ctxinfo-src",children:h(`ctx.windowSource.${["override","model","learned","family","default"].includes(r.ctxWindowSource)?r.ctxWindowSource:"default"}`)}),!!o&&o>0&&t.jsx("span",{className:"t2c-ctxinfo-src",children:h("input.sessionTokens",{n:Ye(o)})}),r&&t.jsxs("span",{className:"t2c-ctxinfo-files",children:[t.jsxs("span",{className:"t2c-ctxinfo-label",children:[h("ctx.files.label"),r.filesTruncated?` ${h("ctx.files.truncated")}`:""]}),r.files.length>0?r.files.map(_=>t.jsx("span",{className:"t2c-ctxinfo-file",title:_,children:_.split(/[/\\]/).slice(-2).join("/")},_)):t.jsx("span",{className:"t2c-ctxinfo-file dim",children:h("ctx.files.none")})]})]}),t.jsxs("span",{className:"t2c-cu-foot",children:[M>0&&t.jsx("span",{children:h("ctx.untilCompact",{left:Ye(Math.max(0,M-k)),n:Ye(M),pct:Math.round(x(M))})}),l&&t.jsx("button",{type:"button",className:"t2c-ctxring-compact",onClick:l,title:h("input.slash.compact"),children:h("ctx.pop.compact")})]}),i!=null&&c!=null&&c>0&&t.jsx("span",{className:"t2c-ctxinfo-src","data-warn":i>=c*.8||void 0,children:h("input.runCost",{used:Math.round(i).toLocaleString(),limit:c.toLocaleString()})}),t.jsx(Pu,{open:e})]})}function Pu({open:e}){const{t:n,locale:a}=Ce(),o=D(x=>x.authInfo?.loggedIn&&x.authInfo.tokenValid!==!1?`${x.authInfo.accountId??""}:${x.authInfo.username??""}`:null),i=o!==null&&!!window.tangu?.accountQuota,c=D(x=>x.authInfo?.membershipTier),[r,l]=u.useState(null),h=u.useRef(0);if(u.useEffect(()=>Vr(x=>{h.current++,l(x)}),[]),u.useEffect(()=>{l(null)},[o]),u.useEffect(()=>{if(!i||!e)return;let x=!0;const A=++h.current;return window.tangu.accountQuota().then(E=>{!x||A!==h.current||E?.status!==200||!E.json||(l(E.json),Kr(E.json))}).catch(()=>{}),()=>{x=!1}},[e,o,i]),!i||!r)return null;const p=Iu(Date.now()),f=$u(r.weeklyResetAt),k=[{key:"daily",label:n("sidebar.account.menu.daily"),limit:Number(r.dailyLimit),rem:ci(r.dailyLimit,r.dailyRemaining,r.dailyPercent),reset:n("ctx.limit.resetsIn",{h:Math.floor(p/36e5),m:Math.floor(p%36e5/6e4)})},{key:"weekly",label:n("sidebar.account.menu.weekly"),limit:Number(r.weeklyLimit),rem:ci(r.weeklyLimit,r.weeklyRemaining,r.weeklyPercent),reset:f?n("ctx.limit.resetsAt",{when:Yr(f,{locale:a})}):""}].filter(x=>x.limit<0||x.rem!==null);return k.length?t.jsxs("span",{className:"t2c-cu-limits",children:[t.jsxs("span",{className:"t2c-cu-limits-title",children:[n("ctx.limit.title"),t.jsx(Eu,{tier:c})]}),k.map(x=>t.jsxs("span",{className:"t2c-cu-limit","data-limit":x.key,children:[t.jsxs("span",{className:"t2c-cu-limit-line",children:[t.jsx("span",{className:"t2c-cu-limit-name",children:x.label}),x.rem!==null&&t.jsx("span",{className:"t2c-cu-limit-reset",children:x.reset}),t.jsx("span",{children:x.rem===null?n("sidebar.account.menu.unlimited"):n("ctx.limit.used",{pct:Math.round(100-x.rem)})})]}),x.rem!==null&&t.jsx("span",{className:"t2c-cu-bar","data-warn":x.rem<=15||void 0,"aria-hidden":"true",children:t.jsx("span",{style:{width:`${100-x.rem}%`}})})]},x.key))]}):null}xe({"livecall.start":{zh:"语音通话",en:"Voice call"},"livecall.return":{zh:"回到通话",en:"Back to the call"},"livecall.localOnly":{zh:"语音通话只能在本机的会话里用",en:"Voice calls only work in sessions on this computer"},"livecall.typeHint":{zh:"通话中:打的字会直接送进电话",en:"In a call: typed messages go straight into the call"},"livecall.textFallback":{zh:"通话没接上,这条改发给 Tangu 了",en:"The call did not pick this up, so it was sent to Tangu instead"}});xe({"input.modeSheetTitle":{zh:"模式",en:"Mode"},"input.agentSwitch.section":{zh:"切换 Agent",en:"Switch agent"},"input.mention.projectNote":{zh:"派往项目 · 在该项目新建会话开工",en:"Dispatch to project · starts a new session there"},"input.normalWork":{zh:"普通模式",en:"Normal mode"},"input.presetChat":{zh:"Chat",en:"Chat"},"input.presetWork":{zh:"Work",en:"Work"},"input.presetLocked":{zh:"模式在创建会话时确定;换模式请新建会话",en:"Mode is fixed when the session is created; start a new session to change it"},"input.approvalSection.team":{zh:"团队审批档 · 改动对全队生效",en:"Approval mode for the whole team"},"input.planModeTeamOff":{zh:"团队模式下不可用",en:"Not available in team mode"},"composer2.exportRoleUser":{zh:"我",en:"Me"},"composer2.listSep":{zh:"、",en:", "}});const Du=8e3,ia="input.tip.steer",Ii=[ia,"input.tip.switchChat","input.tip.quote","input.tip.dropFiles","input.tip.wikiRef","input.tip.dragSession","input.tip.branch","input.tip.newTab","input.tip.palette","input.tip.quickFind","input.tip.findInChat","input.tip.toc"],_u=[ia,"input.tip.wikiRef"];xe({"input.tip":{zh:"小贴士:{tip}",en:"Tip: {tip}"},"input.runningPlaceholder":{zh:"运行中,可继续输入…",en:"Working… You can keep typing"},"input.steer.queuedHint":{zh:"排队项在本轮结束后依次执行 · ↑ 取回编辑",en:"Queued items run in order after this turn · ↑ to recall"},"input.tip.steer":{zh:"运行中也能继续发消息,会在下一步交给 Agent",en:"You can send while it runs: the agent reads it at the next step"},"input.tip.switchChat":{zh:"可以先切去别的会话,运行不会中断,侧栏圆点标出运行中",en:"Switch chats meanwhile; this run keeps going, marked by a sidebar dot"},"input.tip.quote":{zh:"划选回复里的文字,点「引用」即可带进下一条消息",en:"Select text in a reply and click Quote to cite it in your next message"},"input.tip.dropFiles":{zh:"文件可拖到聊天区任意位置,截图可直接粘贴进输入框",en:"Drop files anywhere in the chat, or paste a screenshot into the box"},"input.tip.wikiRef":{zh:"输入 [[ 可引用历史会话,本机项目里还能引用笔记和文件",en:"Type [[ to reference past chats, or notes and files in local projects"},"input.tip.dragSession":{zh:"把侧栏的会话拖进对话区,即可挂为引用随消息发送",en:"Drag a chat from the sidebar into the conversation to cite it"},"input.tip.branch":{zh:"悬停已完成的回复,点分支图标即可从此处开出新会话",en:"Hover a finished reply and click the branch icon to fork a new chat"},"input.tip.newTab":{zh:"⌘/Ctrl 点击侧栏里的会话,会在新标签页打开",en:"⌘/Ctrl-click a session in the sidebar to open it in a new tab"},"input.tip.palette":{zh:"按 ⌘/Ctrl+K 打开命令面板,搜索并执行命令",en:"Press ⌘/Ctrl+K to open the command palette and run commands"},"input.tip.quickFind":{zh:"⌘/Ctrl+P 快速查找,按名称跳到会话",en:"⌘/Ctrl+P opens quick find: jump to a session by name"},"input.tip.findInChat":{zh:"⌘/Ctrl+F 在当前对话里查找文字",en:"Press ⌘/Ctrl+F to find text in the current conversation"},"input.tip.toc":{zh:"悬停对话左侧的短横线展开目录,点击即可跳回任意一轮提问",en:"Hover the bars on the chat's left edge, then click to jump to a turn"}});const Ms=5*1024*1024,$i=15e4,As=25*1024*1024,Es=[{id:"readonly",Icon:dl,key:"input.approval.readonly",desc:"input.approval.readonlyDesc"},{id:"auto-edit",Icon:Qr,key:"input.approval.autoEdit",desc:"input.approval.autoEditDesc"},{id:"full-auto",Icon:ec,key:"input.approval.fullAuto",desc:"input.approval.fullAutoDesc",danger:!0},{id:"custom",Icon:tc,key:"input.approval.custom",desc:"input.approval.customDesc"}],gn=e=>e.split(/[\\/]/).pop()||e,Ou=".t2-chat-view";function Fu(e,n,a){const o=e.closest(Ou)??e,i=p=>Array.from(p.dataTransfer?.types??[]).includes("Files"),c=p=>{o===e?a(p):o.toggleAttribute("data-filedrop",p)},r=p=>{i(p)&&(p.preventDefault(),p.dataTransfer&&(p.dataTransfer.dropEffect="copy"),c(!0))},l=p=>{o.contains(p.relatedTarget)||c(!1)},h=p=>{i(p)&&(p.preventDefault(),c(!1),p.dataTransfer?.files?.length&&n(p.dataTransfer.files))};return o.addEventListener("dragover",r),o.addEventListener("dragleave",l),o.addEventListener("drop",h),()=>{o.removeEventListener("dragover",r),o.removeEventListener("dragleave",l),o.removeEventListener("drop",h),c(!1)}}const At=e=>({token:/\s/.test(e)?`"${e}"`:e,name:gn(e),kind:"file"}),Wu=e=>({token:/\s/.test(e)?`"${e}"`:e,name:gn(e),kind:"folder"}),Bu=(e,n)=>{const a=o=>String(o).replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">");return{token:`<forsion-view type="${a(e)}" title="${a(n)}" />`,name:n,kind:"view"}};function Rs(e,n){const a=Ji(e,n).trim();return e.kind==="session"?{token:a,name:e.title||"Chat",kind:"session"}:e.kind==="note"?{token:a,name:gn(e.path),kind:"note"}:At(e.path)}function Uu(e,n,a,o){if(a){if(n>=e.length)return null;const c=n+1;return{pos:c,val:e[e.length-c]}}if(n===0)return null;const i=n-1;return{pos:i,val:i===0?o:e[e.length-i]}}function qu(e,n,a){return/^\/refine(\s|$)/i.test(a)&&(a="/refine"+a.slice(7)),/^\/refine(\s|$)/.test(a)&&(e||n)?`${a}
|
|
13
|
+
|
|
14
|
+
${e}${n}`.trimEnd():e+n+a}function Hu(e,n=200){return e>0?`${Math.min(e,n)}px`:"auto"}function Vu(e,n){const a=/(?:^|\s)(\/\S*)$/.exec(e.slice(0,n));return a?{start:n-a[1].length,token:a[1]}:null}const wh=({sessionId:e,advisory:n,approvalTray:a,autoFocus:o,disabled:i,disabledPlaceholder:c,running:r,execConfig:l,teamApproval:h,models:p,modelsResponse:f,modelId:k,onModelChange:x,engines:A,engineId:E,engineModels:M,engineModelId:z,onEngineModelChange:B,engineCommands:_,thinkingLevel:L,onThinkingChange:U,ultra:J,defaultModelIds:C,onDefaultModelChange:g,onContextWindowChange:O,maxIterations:Y,onMaxIterationsChange:F,verifyCommand:P,onVerifyCommandChange:$,preset:W,onPresetChange:K,planMode:Q,onPlanModeChange:Z,voiceMode:T,onVoiceModeChange:ae,liveOwner:y,liveSessionKey:q,prepareLiveSession:te,skills:Se,groupChat:ge,groupAgents:ye,groupTempAgents:Be,onGroupChange:Ie,onAddAgent:Ae,onNormalWork:Le,agents:Ee,onAgentSwitch:Pe,currentAgentSlug:De,mentionProjects:_e,onNewSession:Ue,onBranch:ct,onOpenSettings:Tt,onExecConfigChange:b,onSend:V,onStop:H,quotedText:se,onClearQuote:Ne,onBtw:qe,contextWindow:lt,ctxTokens:He,sessionTokens:Ve,runCost:m,costLimit:R,ctxInfo:N,onCompact:X,seedText:ce,onSeedConsumed:ne,seedShare:$e,takeSeedShare:ut,appendRefs:It,onAppendRefsConsumed:Jn,autoRefFromMain:re,sentHistory:dt,pendingSteer:kt,onCancelSteer:Oo,onWithdrawSteer:ca,onSteerNow:la})=>{const{t:j,locale:Zn}=Ce(),[pe,me]=u.useState(""),[ua,da]=u.useState(0),[ha]=u.useState(()=>!!window.tangu?.mobile||!!window.matchMedia?.("(hover: none)").matches),pa=(ha?_u:Ii).filter(s=>!E||s!==ia),[Fo,Qn]=u.useState(!1),[xt,Wo]=u.useState(!1),[es,ma]=u.useState(!1);u.useEffect(()=>{if(!r||xt)return;da(Math.floor(Math.random()*Ii.length));let s=0;const d=window.setInterval(()=>{Qn(!0),s=window.setTimeout(()=>{da(v=>v+1),Qn(!1)},300)},Du);return()=>{window.clearInterval(d),window.clearTimeout(s),Qn(!1),ma(!1)}},[r,xt]);const[ts,Bo]=u.useState([]),[$t,Jt]=u.useState([]),[Lt,wn]=u.useState([]),[bn,ns]=u.useState([]),[fa,Uo]=u.useState(null),Pt=s=>ns(d=>{const v=new Set(d.map(S=>S.token)),w=[];for(const S of s)v.has(S.token)||(v.add(S.token),w.push(S));return w.length?[...d,...w]:d}),[Dt,ss]=u.useState([]),[ga,ze]=u.useState(null),[va,Oe]=u.useState(0),[Zt,jn]=u.useState(null),[ya,ka]=u.useState(!1),xa=u.useRef(null),[Re,Ke]=u.useState(null),[qo,Qt]=u.useState(!1),[Fe,wt]=u.useState(0),[wa,Sn]=u.useState(0),[ba,ja]=u.useState(!1),[Ho,as]=u.useState(""),[Sa,is]=u.useState([]),[Na,Nn]=u.useState(0),[Ca,za]=u.useState(!1),[Ma,Aa]=u.useState(null),os=u.useRef(""),[Vo,Ko]=u.useState(!1),[en,tn]=u.useState(0),Ea=u.useRef(""),we=u.useRef(null),bt=u.useRef(null);u.useLayoutEffect(()=>{const s=bt.current;if(!s)return;const d=new ResizeObserver(([v])=>Wo(v.contentRect.width<=360));return d.observe(s),()=>d.disconnect()},[]);const nn=u.useMemo(()=>{const s=new Map(Ei("desktop").map(d=>[d.name,d]));return d=>{const v=s.get(d);return v?Zn==="en"?v.en:v.zh:d}},[Zn]);u.useEffect(()=>{let s=!0;return Xr(it()).then(d=>{s&&Bo(d)}),()=>{s=!1}},[]);const Yo=async()=>{const s=D.getState(),d=fe,S=([...d?s.messagesBySession[d]||[]:[]].reverse().find(I=>I.role==="assistant")?.content||"").trim();if(!S){s.toast(j("input.slash.nothingToCopy"),!0);return}try{await navigator.clipboard.writeText(S),s.toast(j("input.slash.copied"))}catch{s.toast(j("input.slash.nothingToCopy"),!0)}},Xo=async()=>{const s=D.getState(),d=fe;if(![...d?s.messagesBySession[d]||[]:[]].reverse().find(S=>S.role==="user")){s.toast(j("input.slash.nothingToRetry"),!0);return}await s.retry(d)},Go=async()=>{const s=D.getState(),d=fe;if(!d){s.toast(j("input.slash.nothingToExport"),!0);return}const v=s.sessions.find(he=>he.id===d);let w=[];try{let he=0;for(let ve=0;ve<20;ve++){const Qe=await pc(ui(d),d,500,he||void 0);if(!Qe.length||(w=[...Qe,...w],Qe.length<500)||(he=Number(Qe[0]?.timestamp)||0,!he))break}}catch{}if(w.length||(w=s.messagesBySession[d]||[]),!w.length){s.toast(j("input.slash.nothingToExport"),!0);return}const S=v?.title||"Tangu Session",I=["---",`id: ${d}`,`title: ${JSON.stringify(S)}`,...v?.summary?[`summary: ${JSON.stringify(v.summary)}`]:[],...v?.model_id?[`model: ${v.model_id}`]:[],`exported_at: ${new Date().toISOString()}`,"---","",`# ${S}`,""];for(const he of w){const ve=he.role==="model"?"assistant":he.role;if(ve!=="user"&&ve!=="assistant")continue;const Qe=(he.content||"").trim(),ln=Array.isArray(he.tool_calls)?he.tool_calls:[];if(!Qe&&!ln.length)continue;I.push(ve==="user"?`## ${j("composer2.exportRoleUser")}`:"## Tangu",""),Qe&&I.push(Qe,"");for(const Mt of ln){const ee=Mt?.function?.name||Mt?.name||"tool";let Me="";try{Me=String(typeof Mt?.function?.arguments=="string"?Mt.function.arguments:JSON.stringify(Mt?.function?.arguments??""))}catch{Me=""}Me=Me.replace(/\s+/g," ").trim(),I.push(`> 🔧 \`${ee}\`${Me&&Me!=="{}"?` ${Me.length>200?Me.slice(0,200)+"…":Me}`:""}`)}ln.length&&I.push("");const zt=Array.isArray(he.attachments)?he.attachments:[];zt.length&&I.push(`> 📎 ${zt.length} attachment(s)`,"")}const G=new Blob([I.join(`
|
|
15
|
+
`)],{type:"text/markdown"}),oe=document.createElement("a");oe.href=URL.createObjectURL(G),oe.download=`tangu-${String(d).slice(0,8)}.md`,oe.click(),setTimeout(()=>URL.revokeObjectURL(oe.href),1e3)},ue=Fl(s=>{me(d=>d?d.replace(/\s+$/,"")+" "+s:s),tn(0),requestAnimationFrame(ie)}),Jo=ue.recording||ue.busy,rs=u.useRef(!1),Zo=()=>{rs.current=!0,ue.toggle()};u.useEffect(()=>{!rs.current||ue.recording||ue.busy||(rs.current=!1,pe.trim()&&An())},[ue.recording,ue.busy]);const Qo=D(s=>s.activeId),fe=e===void 0?Qo:e,er=Gr(fe),Cn=y??e===null,{model:Ra,voice:tr}=Yl(),[cs,Ta]=u.useState(!1),[Ia,$a]=u.useState(""),nr=u.useSyncExternalStore(Jl,vo),zn=!!fe&&nr===fe;u.useEffect(()=>{if(Cn)return yo(s=>{if(s.kind==="activity"){D.getState().pollSession(s.sessionId);return}if(s.kind==="transcript"){const d=()=>{const S=D.getState().messagesBySession[s.sessionId]?.find(I=>I.id===s.messageId);return S?(S.content!==s.text&&D.setState(I=>({messagesBySession:{...I.messagesBySession,[s.sessionId]:(I.messagesBySession[s.sessionId]||[]).map(G=>G.id===s.messageId?{...G,content:s.text}:G)}})),!0):!1};if(d())return;const v=D.subscribe(()=>{d()&&(v(),clearTimeout(w))}),w=setTimeout(v,3e4);return}s.kind==="effort"&&D.setState(d=>d.configBySession[s.sessionId]?{configBySession:{...d.configBySession,[s.sessionId]:{...d.configBySession[s.sessionId],thinkingLevel:s.level,...s.level!=="max"?{ultra:void 0}:{}}}}:{})})},[Cn]);const sr=async()=>{if(!cs){Ta(!0),$a("");try{let s=q!==void 0?q:fe;if(!s){const I=D.getState().activeId;s=te?await te():await D.getState().newSession().then(()=>D.getState().activeId),s===I&&(s=null)}if(!s)return;if(ui(s).key!=="home"){$a(j("livecall.localOnly"));return}const{modelId:v,agentConfig:w}=D.getState().voiceRunParams(s),S={type:"voice-call",params:{sessionId:s,model:Ra,voice:tr,title:j("livecall.title"),agentSlug:w.agentSlug,run:{model_id:v,agent_config:w}}};window.tangu?.openMini?.({view:S,mainView:{type:"chat",params:{sessionId:s}},title:j("livecall.title")})}finally{Ta(!1)}}},de=l.execMode==="host",ke=W==="chat",sn=E?void 0:Ee?.find(s=>s.slug===De),an=l.approvalMode||sn?.approvalMode||"auto-edit",jt=L||(ge?void 0:sn?.thinkingLevel)||void 0,ht=de&&!ke&&!E&&!ge,_t=ht&&!!J&&jt==="max",{window:St,stale:ar}=Yc({ctxInfo:N,contextWindow:lt,running:r,ultra:_t,model:f?.models.find(s=>s.id===k),engineUncapped:f?.ultraUncapped}),ls=ar&&N?{...N,ctxWindow:St||N.ctxWindow,compactAt:void 0}:N,[ir,La]=u.useState(!1),on=(s,d)=>U?d===!0&&!_t&&!au()?(La(!0),!1):(U(s,d),!0):!1,Pa=Yt(Re==="mode",{boundary:".t2-chat-view"}),Da=Yt(Re==="ctx",{boundary:".t2-chat-view"});u.useEffect(()=>{if(!Re)return;const s=v=>{v.target?.closest?.("[data-cmenu], [data-keep-menus]")||Ke(null)},d=v=>{v.key==="Escape"&&!document.querySelector("[data-keep-menus]")&&Ke(null)};return document.addEventListener("mousedown",s),document.addEventListener("keydown",d),()=>{document.removeEventListener("mousedown",s),document.removeEventListener("keydown",d)}},[Re]);const ie=()=>{const s=we.current;if(s){if(!s.value){s.style.height="";return}s.style.height="auto",s.style.height=Hu(s.scrollHeight)}};u.useEffect(()=>{const s=we.current;if(!s||typeof ResizeObserver>"u")return;let d=s.clientWidth;const v=new ResizeObserver(()=>{s.clientWidth!==d&&(d=s.clientWidth,ie())});return v.observe(s),()=>v.disconnect()},[]),u.useLayoutEffect(ie,[pe]),u.useLayoutEffect(()=>{const s=we.current;r&&!xt&&!es&&s&&!s.value&&s.scrollHeight>s.clientHeight+2&&ma(!0)},[r,ua,Zn,es,pe,xt]);const _a=s=>{s&&en===0&&(Ea.current=pe);const d=Uu(dt||[],en,s,Ea.current);d&&(tn(d.pos),me(d.val),requestAnimationFrame(()=>{const v=we.current;v&&(v.focus(),v.selectionStart=v.selectionEnd=d.val.length,wt(d.val.length)),ie()}))};u.useEffect(()=>{ce&&(me(ce),ne?.(),requestAnimationFrame(()=>{we.current?.focus(),ie()}))},[ce]),u.useEffect(()=>{se&&requestAnimationFrame(()=>we.current?.focus())},[se]),u.useEffect(()=>{It?.refs.length&&(Pt(It.refs.map(s=>Rs(s,gt||""))),Jn?.(),requestAnimationFrame(()=>{we.current?.focus(),ie()}))},[It?.seq]);const Ge=s=>{const d=xa.current,v=d?.start??0,w=d?.end??1/0;me(I=>I.slice(0,v)+s+I.slice(w));const S=v+s.length;return requestAnimationFrame(()=>{const I=we.current;I&&(!D.getState().feedbackOpen&&!document.querySelector("[data-keep-menus]")&&I.focus(),I.selectionStart=I.selectionEnd=S,wt(S)),ie()}),v},Oa=u.useMemo(()=>{const s=()=>{Ge(""),jn(null)},d=D.getState,v={"/stop":r?()=>{H(),s()}:void 0,"/new":Ue?()=>{Ue(),s()}:void 0,"/branch":ct?()=>{ct(),s()}:void 0,"/compact":X?()=>{X(),s()}:void 0,"/plan":Z&&!ke?()=>{Z(!Q),s()}:void 0,"/chat":K?()=>{K("chat"),s()}:()=>{d().toast(j("input.presetLocked")),s()},"/work":K?()=>{K("work"),s()}:()=>{d().toast(j("input.presetLocked")),s()},"/voice":ae?()=>{ae(!T),s()}:void 0,"/model":x&&p?.length?()=>{jn({start:Ge("/model ")}),Oe(0)}:void 0,"/loop":F?()=>{Ge("/loop "),Oe(0)}:void 0,"/verify":de&&$?()=>{Ge("/verify "),Oe(0)}:void 0,"/think":U?()=>{Ge("/think"),Oe(0)}:void 0,"/refine":de?()=>{Ge("/refine "),Oe(0)}:void 0,"/approval":()=>{Ke("mode"),s()},"/help":()=>{d().openSettings("about"),s()},"/feedback":window.tangu?.submitFeedback?()=>{d().openFeedback()&&s()}:void 0,"/btw":qe?()=>{Ge("/btw "),Oe(0)}:void 0,"/skills":()=>{d().openSettings("skills"),s()},"/tools":()=>{d().openSettings("agents"),s()},"/agents":()=>{d().openSettings("agents"),s()},"/agent":()=>{d().openSettings("agents"),s()},"/mcp":()=>{d().openSettings("mcp"),s()},"/plugins":()=>{d().openSettings("plugins"),s()},"/memory":()=>{d().openSettings("forsion/f-sync"),s()},"/config":()=>{d().openSettings("general"),s()},"/login":window.tangu?.forsionLogin?()=>{d().openSettings("forsion"),s()}:void 0,"/historian":()=>{d().setActiveSpecial("agents"),s()},"/muse":()=>{d().setActiveSpecial("agents"),s()},"/groupchat":Ie&&!ke?()=>{Qt(!0),s()}:void 0,"/sessions":()=>{d().setActiveId(null),s()},"/cost":()=>{d().pushNotice(`${(Ve??0).toLocaleString()} tokens · ${j("input.ctxLabel")} ${(He??0).toLocaleString()}/${(St??0).toLocaleString()}`+(m!=null&&R!=null&&R>0?` · ${j("input.runCost",{used:Math.round(m).toLocaleString(),limit:R.toLocaleString()})}`:"")),s()},"/status":()=>{d().pushNotice([`${j("input.slash.status")}`,`model=${k||"-"}`,`think=${jt||"medium"}${N?.thinkingRequested===(jt||"medium")&&N.thinkingEffective&&N.thinkingEffective!==N.thinkingRequested?`→${N.thinkingEffective}`:""}`,`approval=${l.approvalMode||sn?.approvalMode||(l.execMode==="host"?"auto-edit":"full-auto")} (${l.approvalMode?"session":sn?.approvalMode?"agent":"default"})`,`cwd=${l.cwd||"-"}`,`loop=${Y||N?.maxIterations||90} (${Y?"session":N?.maxIterationsSource||"default"})`,`verify=${P||"-"}`,`tokens=${(Ve??0).toLocaleString()}`,`cost=${m!=null?Math.round(m).toLocaleString():"-"}${R!=null&&R>0?`/${R.toLocaleString()}`:""}`].join(`
|
|
16
|
+
`)),s()},"/copy":()=>{Yo(),s()},"/retry":()=>{Xo(),s()},"/export":()=>{Go(),s()}},w=[];if(r){const S=v["/stop"];S&&w.push({cmd:"/stop",desc:nn("/stop"),run:S})}if(E){Ue&&w.push({cmd:"/new",desc:nn("/new"),run:()=>{Ue(),s()}}),v["/feedback"]&&w.push({cmd:"/feedback",desc:nn("/feedback"),run:v["/feedback"]});for(const S of _||[])S.name.replace(/^\//,"").toLowerCase()==="feedback"&&v["/feedback"]||w.push({cmd:`/${S.name}`,desc:S.hint?`${S.description} · ${S.hint}`:S.description,run:()=>{Ge(`/${S.name} `),Oe(0)}});return w}if(U){const S=E?void 0:p?.find(I=>I.id===k)?.thinkingLevels;for(const I of Pn){const G=!!S&&!S.includes(I);w.push({cmd:`/think ${I}`,desc:`${j("input.slash.thinkDesc",{level:Ps(I,j)})}${G?` ${j("pill.thinkUnsupported")}`:""}${!_t&&jt===I?j("input.slash.current"):""}`,run:()=>{on(I,ht?!1:void 0),s()}})}ht&&w.push({cmd:"/think ultra",desc:`${j("pill.ultraTitle")}${_t?j("input.slash.current"):""}`,run:()=>{on("max",!0),s()}})}for(const S of Ei("desktop")){if(S.name==="/stop")continue;const I=v[S.name];I&&w.push({cmd:S.arg?`${S.name} ${S.arg}`:S.name,desc:nn(S.name),run:I})}for(const S of ts)w.push({cmd:S.argHint?`/${S.name} ${S.argHint}`:`/${S.name}`,desc:S.description,run:()=>{Ge(`/${S.name} `),Oe(0)}});if(Se?.length)for(const S of Se)w.push({cmd:`/skill:${S.id}`,desc:j("input.slash.skillUse",{name:S.name}),run:()=>{ss(I=>I.some(G=>G.id===S.id)?I:[...I,S]),s()}});return w},[r,H,Q,T,ae,jt,Y,F,P,$,p,k,Se,Z,U,x,Ue,ct,X,Ie,ke,K,E,_,ts,nn,l,sn,Ve,He,St,m,R,N,!!qe,ht,_t]),Je=u.useMemo(()=>{if(i||ya)return null;const s=pe.slice(0,Fe);if(Zt&&s.startsWith("/model ",Zt.start))return{start:Zt.start,token:s.slice(Zt.start),sub:"model"};const d=Vu(pe,Fe);return d?{...d,sub:null}:null},[pe,Fe,i,ya,Zt]);xa.current=Je?{start:Je.start,end:Fe}:null;const pt=u.useMemo(()=>{if(!Je)return[];if(Je.sub==="model"){const v=Je.token.slice(7).toLowerCase();return(p||[]).filter(w=>!v||w.id.toLowerCase().includes(v)||w.name.toLowerCase().includes(v)).slice(0,12).map(w=>({cmd:w.id===k?`● ${w.name}`:w.name,desc:`${w.source==="direct"?j("input.directPrefix"):""}${w.provider} · ${w.id}`,run:()=>{x?.(w.id),Ge(""),jn(null)}}))}const s=Je.token.toLowerCase(),d=s.startsWith("/th");return Oa.filter(v=>(d||!v.cmd.startsWith("/think "))&&(v.cmd.toLowerCase().startsWith(s)||s.length>1&&v.desc.toLowerCase().includes(s.slice(1)))).slice(0,10)},[Je,Oa,p,k]),Ot=!!Je&&pt.length>0;u.useEffect(()=>{Oe(0)},[Je?.start,Je?.token]);const rn=!!ge&&(ye?.length||0)>=2,[or,Fa]=u.useState([]),cn=!!_e?.length,Wa=u.useMemo(()=>{if(cn)return(_e||[]).map(v=>({slug:v.path,name:v.name,description:v.path}));if(!rn)return Ee||[];const s=(Ee||[]).filter(v=>ye.includes(v.slug)),d=new Set(s.map(v=>v.slug));return[...s,...(Be||[]).filter(v=>!d.has(v.slug))]},[rn,Ee,ye,Be,cn,_e]),mt=u.useMemo(()=>{if(i||Ot||ba)return null;const s=/(?:^|\s)@([^\s@]*)$/.exec(pe.slice(0,Fe));return s?{query:s[1],start:Fe-s[1].length-1}:null},[pe,Fe,i,Ot,ba]),ft=u.useMemo(()=>{if(!mt)return[];const s=mt.query.toLowerCase();return Wa.filter(d=>!s||d.name.toLowerCase().includes(s)||d.slug.toLowerCase().includes(s)).slice(0,10)},[mt,Wa]),Ba=!!mt&&ft.length>0;u.useEffect(()=>{Sn(0)},[mt?.start,mt?.query]);const Ua=s=>{if(!mt)return;const d=pe.slice(0,mt.start),v=`@${s.name} `,w=d+v+pe.slice(Fe);me(w),cn?Fa(I=>I.some(G=>G.path===s.slug)?I:[...I,{name:s.name,path:s.slug}]):rn?as(s.slug):is(I=>I.includes(s.slug)?I:[...I,s.slug]);const S=d.length+v.length;requestAnimationFrame(()=>{const I=we.current;I&&(I.focus(),I.selectionStart=I.selectionEnd=S,wt(S)),ie()})},Ze=u.useMemo(()=>{if(i||Ot||Ca)return null;const s=/\[\[([^\]\n]*)$/.exec(pe.slice(0,Fe));return s?{query:s[1],start:Fe-s[1].length-2}:null},[pe,Fe,i,Ot,Ca]);u.useEffect(()=>{if(!Ze||!de)return;window.amadeus&&Jr();const s=l.cwd;if(!s||os.current===s)return;os.current=s,Aa(null);const d=new Set(["node_modules","dist","build","out","target",".git",".venv","venv","__pycache__"]);(async()=>{const w=[],S=[{dir:s,rel:"",depth:0}];for(;S.length&&w.length<2e3;){const{dir:I,rel:G,depth:oe}=S.shift();let he=[];try{he=await window.tangu?.listDir?.(I)||[]}catch{continue}for(const ve of he)if(!ve.name.startsWith(".")){if(ve.isDir)oe<8&&!d.has(ve.name)&&S.push({dir:ve.path,rel:G?`${G}/${ve.name}`:ve.name,depth:oe+1});else if(w.push(G?`${G}/${ve.name}`:ve.name),w.length>=2e3)break}}return w})().then(w=>{os.current===s&&Aa(w)}).catch(()=>{})},[Ze,l.cwd,de]);const qa=hn(s=>s.pages),gt=hn(s=>s.vaultRoot),Ha=hn(s=>s.icons),Va=D(s=>s.sessions),Ft=fi(s=>s.pendingPrompt),Nt=vi(s=>s.pending);u.useEffect(()=>{!Nt||Nt.sessionId!==fe||!bt.current?.closest("[data-image-studio-chat]")||!bt.current.getClientRects().length||vi.getState().consume(Nt.seq)&&(me(s=>s.trim()?`${s}
|
|
17
|
+
|
|
18
|
+
${Nt.text}`:Nt.text),Jt(s=>[...s,...Nt.attachments]),requestAnimationFrame(()=>{we.current?.focus(),ie()}))},[Nt,fe]);const Ka=Ci(s=>s.pending);u.useEffect(()=>{if(!fe||!Ka.some(d=>d.sessionId===fe)||!bt.current?.closest("[data-plugin-chat]"))return;const s=Ci.getState().take(fe);s.length&&(me(d=>[...d.trim()?[d]:[],...s].join(`
|
|
19
|
+
|
|
20
|
+
`)),requestAnimationFrame(()=>{we.current?.focus(),ie()}))},[Ka,fe]),u.useEffect(()=>{if(!Ft||!bt.current?.getClientRects().length)return;const s=D.getState(),d=fe?s.sessions.find(v=>v.id===fe)?.project_path:s.newChatWs?.path;gi(d||"")!==gi(Ft.project)||!fi.getState().consumePrompt(Ft.seq)||(me(v=>v.trim()?`${v}
|
|
21
|
+
|
|
22
|
+
${Ft.text}`:Ft.text),requestAnimationFrame(()=>{we.current?.focus(),ie()}))},[Ft,fe]);const vt=u.useMemo(()=>{if(!Ze)return[];const s=Ze.query.toLowerCase(),d=[...de?qa.map(S=>({p:S,note:!0})):[],...de?(Ma??[]).map(S=>({p:S})):[],...Va.filter(S=>S.id!==fe).slice(0,300).map(S=>({p:yt(S.title,j),session:{id:S.id,title:yt(S.title,j),summary:S.summary}}))],v=s?d.filter(S=>S.p.toLowerCase().includes(s)):d,w=S=>{const I=(S.note?S.p.replace(/\.md$/i,""):S.p).split("/").pop().toLowerCase();return(I.startsWith(s)?0:I.includes(s)?1:2)*1e4+S.p.length};return[...v].sort((S,I)=>w(S)-w(I)).slice(0,10)},[Ze,Ma,qa,Va,fe,de,j]),us=!!Ze&&vt.length>0;u.useEffect(()=>{Nn(0)},[Ze?.start,Ze?.query]);const Ya=s=>{if(!Ze)return;const d=(s.session?Ji({kind:"session",id:s.session.id,title:s.session.title},gt||""):s.note&>?dc(gt,s.p):/\s/.test(s.p)?`"${s.p}"`:s.p).trim();Pt([{token:d,name:s.session?s.session.title:gn(s.p),kind:s.session?"session":s.note?"note":"file"}]);const v=pe.slice(0,Ze.start);me(v+pe.slice(Fe)),requestAnimationFrame(()=>{const w=we.current;w&&(w.focus(),w.selectionStart=w.selectionEnd=v.length,wt(v.length)),ie()})},Xa=hn(s=>s.activePage??s.activeNotePath),Wt=Dn(s=>wu(s.mainTabs)),Mn=u.useMemo(()=>{if(!de||!re||!Wt)return null;const s=Wt==="note"?Xa:Wt.startsWith("note:")?Wt.slice(5):"",d=s?gt?Rs({kind:"note",path:s},gt):null:At(Wt.slice(5));return!d||fa===d.token||bn.some(v=>v.token===d.token)?null:d},[de,re,Wt,Xa,gt,fa,bn]),nt=Mn?[Mn,...bn]:bn,Ga=s=>{const d=(s??pe).trim(),v=s==null?d:"",w=/^\/feedback(?:\s+([\s\S]*))?$/i.exec(v);if(w&&window.tangu?.submitFeedback){D.getState().openFeedback(w[1]?.trim())&&(me(""),requestAnimationFrame(ie));return}const S=/^\/(?:btw|side)(?:\s+([\s\S]*))?$/i.exec(v);if(S&&qe){qe(S[1]?.trim()||void 0,se||void 0),se&&Ne?.(),me(""),requestAnimationFrame(ie);return}if(!d&&!nt.length)return;const I=/^\/compact(?:\s+([\s\S]+))?$/i.exec(v);if(I&&X){X((I[1]||"").trim()||void 0),me(""),requestAnimationFrame(ie);return}const G=/^\/loop(?:\s+(\d+))?$/i.exec(v);if(G&&F){if(G[1]){const ee=Math.min(Math.max(1,parseInt(G[1],10)),200);F(ee),ze(j("input.slash.loopSet",{n:ee}))}else ze(j("input.slash.loop",{current:Y||N?.maxIterations||90}));me(""),requestAnimationFrame(ie);return}const oe=/^\/verify(?:\s+([\s\S]+))?$/i.exec(v);if(oe&&de&&$){const ee=(oe[1]||"").trim();ee?/^(off|clear|关闭)$/i.test(ee)?($(""),ze(j("input.slash.verifyCleared"))):($(ee),ze(j("input.slash.verifySet",{cmd:ee}))):ze(j("input.slash.verifyUsage",{current:P||j("input.slash.verifyNone")})),me(""),requestAnimationFrame(ie);return}if(ae&&/^\/(voice|text)$/i.test(v)){const ee=/^\/voice$/i.test(d);ae(ee),ze(j(ee?"input.slash.voiceOnHint":"input.slash.voiceOffHint")),me(""),requestAnimationFrame(ie);return}const he=/^\/(?:think|effort)(?:\s+(\S+))?$/i.exec(v);if(he&&U){const ee=(he[1]||"").toLowerCase();ht&&ee==="ultra"?on("max",!0)&&ze(j("input.slash.thinkSet",{level:j("pill.ultra")})):Pn.includes(ee)?(on(ee,ht?!1:void 0),ze(j("input.slash.thinkSet",{level:Ps(ee,j)}))):ze(j("input.slash.thinkUsage",{levels:[...Pn,...ht?["ultra"]:[]].join("|")})),me(""),requestAnimationFrame(ie);return}const ve=/^\/([a-z0-9][a-z0-9-]*)(?:\s+([\s\S]*))?$/i.exec(v);if(ve&&ts.some(ee=>ee.name===ve[1].toLowerCase())){const ee=ve[1].toLowerCase(),Me=ve[2]||"";me(""),requestAnimationFrame(ie),lc(it(),ee,Me).then(Bt=>V(Bt,[],[],void 0,void 0)).catch(Bt=>ze(String(Bt?.message||Bt)));return}if(i)return;if(zn&&!s&&d&&d.length<=Zl&&!$t.length&&!Lt.length&&!nt.length&&!se&&!Dt.length)return me(""),tn(0),ze(null),requestAnimationFrame(ie),Ql(fe,d).then(async ee=>{if(ee)return!0;const Me=await Promise.resolve(Ga(d)).catch(()=>!1)??!1;return Me?ze(j("livecall.textFallback")):me(Bt=>Bt||d),Me});const Qe=se?`${se.split(`
|
|
23
|
+
`).map(ee=>`> ${ee}`).join(`
|
|
24
|
+
`)}
|
|
25
|
+
|
|
26
|
+
`:"",ln=nt.length?nt.map(ee=>ee.token).join(" ")+`
|
|
27
|
+
`:"",zt=qu(ln,Qe,d);if(zt.length>$i){ze(j("input.tooLong",{len:zt.length.toLocaleString(),max:$i.toLocaleString()}));return}ze(null);const Mt=cn?{mentionProjects:(()=>{const ee=or.filter(Me=>zt.includes(`@${Me.name}`));return ee.length?ee:void 0})()}:rn?{priorityAgent:Ho||void 0}:{mentionAgents:Sa.length?Sa:void 0};return V(zt,$t,Lt,Dt.map(ee=>ee.id),Mt).then(ee=>ee?(s||(me(""),tn(0),uc("tick")),Jt([]),wn([]),ns([]),ss([]),as(""),is([]),Fa([]),Ne?.(),requestAnimationFrame(ie),!0):!1)},An=()=>{Ga()},Ja=async s=>{if(!s)return;const d=[],v=[];for(const w of Array.from(s)){if(!w.type.startsWith("image/")){v.push(j("input.skip.notImage",{name:w.name}));continue}if(w.size>Ms){v.push(j("input.skip.tooBig",{name:w.name,mb:String(Math.round(Ms/1024/1024))}));continue}const S=await w.arrayBuffer();let I="";const G=new Uint8Array(S);for(let oe=0;oe<G.length;oe+=32768)I+=String.fromCharCode(...G.subarray(oe,oe+32768));d.push({name:w.name,mimeType:w.type,data:btoa(I),size:w.size})}ze(v.length?j("input.skip.imageHint",{items:v.join(j("composer2.listSep"))}):null),Jt(w=>[...w,...d])},ds=async s=>{if(!s)return;const d=[],v=[];for(const w of Array.from(s)){if(w.size>As){v.push(j("input.skip.tooBig",{name:w.name,mb:String(Math.round(As/1024/1024))}));continue}const S=await w.arrayBuffer();let I="";const G=new Uint8Array(S);for(let oe=0;oe<G.length;oe+=32768)I+=String.fromCharCode(...G.subarray(oe,oe+32768));d.push({name:w.name,mimeType:w.type||"application/octet-stream",data:btoa(I),size:w.size})}ze(v.length?j("input.skip.simple",{items:v.join(j("composer2.listSep"))}):null),wn(w=>[...w,...d])},Za=s=>{if(s.length){if(de&&window.tangu?.getPathForFile){const d=Array.from(s).map(v=>{try{return window.tangu.getPathForFile(v)}catch{return""}}).filter(Boolean);if(d.length){Pt(d.map(At)),requestAnimationFrame(()=>{we.current?.focus(),ie()});return}}ds(s)}},Qa=u.useRef(Za);Qa.current=Za,u.useEffect(()=>{const s=bt.current;return s?Fu(s,d=>Qa.current(d),Ko):void 0},[]);const ei=async s=>{if(!s?.length)return;const d=Array.from(s).filter(w=>w.type.startsWith("image/")),v=Array.from(s).filter(w=>!w.type.startsWith("image/"));if(d.length){const w=new DataTransfer;d.forEach(S=>w.items.add(S)),await Ja(w.files)}if(v.length){const w=new DataTransfer;v.forEach(S=>w.items.add(S)),await ds(w.files)}};u.useEffect(()=>{if(!$e)return;const s=ut?.();if(s&&(s.text&&(me(d=>d.trim()?`${d.replace(/\s+$/,"")}
|
|
28
|
+
|
|
29
|
+
${s.text}`:s.text),requestAnimationFrame(()=>ie())),s.files.length)){const d=new DataTransfer;s.files.forEach(v=>d.items.add(v)),ei(d.files)}},[$e]);const rr=async s=>{const d=[],v=[],w=[];for(const S of s){if(S.isDirectory){w.push(Wu(S.path));continue}try{const I=await window.tangu?.readHostFile?.(S.path);if(!I||I.tooLarge){w.push(At(S.path));continue}const G={name:gn(S.path),mimeType:I.mimeType,data:I.content,size:I.size};I.mimeType.startsWith("image/")&&I.size<=Ms?d.push(G):I.size<=As?v.push(G):w.push(At(S.path))}catch{w.push(At(S.path))}}d.length&&Jt(S=>[...S,...d]),v.length&&wn(S=>[...S,...v]),w.length&&Pt(w)},cr=s=>{Pt([s.kind==="view"?Bu(s.type,s.title):Rs(s,gt||"")]),requestAnimationFrame(()=>we.current?.focus())},[lr,ti]=u.useState(!1),ur=D(s=>s.cfg),dr=s=>{b({execMode:"host",approvalMode:s,cwd:l.cwd}),Ke(null)},ni=Zr(),hr=u.useMemo(()=>Xc(p||[],ni),[p,ni]),st=!!ge&&(ye?.length||0)>=2,pr=!!Ra&&Cn&&!!window.tangu?.openMini&&!(Q&&!ke)&&!st&&!ke&&!E,hs=Es.find(s=>s.id===an)||Es[1],mr=st?j("group.modeLabel",{n:ye.length}):j(Q&&!ke?"input.planMode":ke?"input.presetChat":de?hs.key:"input.normal"),fr=st?Is:Q&&!ke?li:de?hs.Icon:Xn,si=!st&&!(Q&&!ke)&&!ke&&de&&hs.id==="full-auto",gr=!ke&&(!!Z||de||!!Ie||!!Pe),vr=(A||[]).find(s=>s.id===E)?.name||j("input.engineDefault"),be=!!E,yr=be?[{label:vr,options:M||[]}]:hr.map(s=>({key:s.key,label:s.provider,source:s.source,options:s.models.map(d=>({...d,description:`${d.provider} · ${d.id}`}))})),kr=be||!!x||!!U,En=()=>Ke(null),ai={active:!Q&&!st&&an==="auto-edit",disabled:r,agents:Ee||[],currentAgentSlug:De,onNormalWork:Le||(()=>{}),onAgentSwitch:!be&&!st?Pe:void 0,onClose:En},ps=Z&&!ke?{title:j("input.planMode"),items:[{id:"plan-mode",icon:t.jsx(li,{size:14}),label:j(ge?"input.planModeTeamOff":Q?"input.planModeOn":"input.planModeEnable"),checked:!!Q&&!ge,disabled:!!ge,run:()=>{Z(!Q),En()}}]}:null,ms=Ie&&!be&&!ke?{title:j("group.menu.section"),items:[{id:"group-chat",label:st?j("group.menu.configured",{n:ye.length}):j("group.menu.enable"),icon:t.jsx(Is,{size:14}),checked:st,run:()=>{Qt(!0),En()}}]}:null,ii=de?Es.map(({id:s,Icon:d,key:v,desc:w,...S})=>({id:`approval:${s}`,approvalId:s,label:j(v),detail:j(w),icon:t.jsx(d,{size:15,className:"approval-ic"}),checked:an===s,danger:"danger"in S,run:()=>dr(s)})):[],Ct=de&&an==="custom"?{id:"approval-rules",label:j("input.approval.editRules"),detail:j("input.approval.editRulesDesc"),icon:t.jsx(hc,{size:15,className:"approval-ic"}),run:()=>{ti(!0),En()}}:null,xr=()=>{const s=Le&&!ke?wo(ai,j):null;return{title:j("input.modeSheetTitle"),back:j("common.back"),sections:[{items:s?[s.normal,...s.agentSwitch?[s.agentSwitch]:[]]:[]},...ps?[ps]:[],...ms?[ms]:[],...de?[{title:j(h?"input.approvalSection.team":"input.approvalSection"),items:[...ii,...Ct?[Ct]:[]]}]:[]]}};return t.jsxs("div",{className:"t2c",children:[qo&&t.jsx(lu,{agents:Ee||[],models:p,initialAgents:ye||[],initialTempAgents:Be,active:st,hideDisable:!0,onConfirm:s=>{Ie?.({groupChat:!0,...s}),Qt(!1),nc("chat.group")},onDisable:()=>Ie?.({groupChat:!1}),onClose:()=>Qt(!1)}),t.jsxs("div",{className:"t2c-inner",children:[!!kt?.length&&t.jsxs("div",{className:"t2c-steer",role:"status","aria-label":j("input.steer.waiting"),children:[kt.map(s=>t.jsxs("div",{className:"t2c-steer-item",children:[t.jsx(nl,{size:12,className:"t2c-steer-ic"}),t.jsx("span",{className:"t2c-steer-text",title:s.text,children:s.text}),t.jsx("button",{className:"t2c-steer-x",title:j("input.steer.remove"),onClick:()=>Oo?.(s.id),children:t.jsx(at,{size:12})})]},s.id)),t.jsxs("div",{className:"t2c-steer-foot",children:[t.jsx("span",{className:"t2c-steer-hint",children:j(kt.some(s=>s.localOnly)?"input.steer.queuedHint":"input.steer.hint")}),la&&kt.some(s=>!s.localOnly)&&t.jsxs("button",{className:"t2c-steer-now",onClick:la,children:[t.jsx(sc,{size:11})," ",j("input.steer.now")]})]})]}),a,t.jsxs(ac,{ref:bt,className:Vo?"dragover":void 0,children:[n,ga&&t.jsx("div",{className:"t2c-hint",children:ga}),se&&t.jsxs("div",{className:"t2c-quote",children:[t.jsx("span",{className:"t2c-quote-text",children:se.length>280?`${se.slice(0,280)}…`:se}),t.jsx("button",{title:j("input.remove"),onClick:()=>Ne?.(),className:"t2c-quote-x",children:t.jsx(at,{size:12})})]}),nt.length>0&&t.jsxs("div",{className:"t2c-chiprow t2c-refrow",role:"group","aria-label":j("input.ref.selected"),children:[t.jsx("span",{className:"t2c-reflabel",children:j("input.ref.selected")}),nt.map(s=>t.jsx(bu,{chip:s,removeTitle:j("input.remove"),onRemove:()=>{Mn&&s.token===Mn.token?Uo(s.token):ns(d=>d.filter(v=>v.token!==s.token))}},s.token))]}),$t.length>0&&t.jsx("div",{className:"t2c-chiprow",children:$t.map((s,d)=>t.jsxs("span",{className:"attach-chip",children:[s.mimeType.startsWith("image/")&&t.jsx("img",{src:`data:${s.mimeType};base64,${s.data}`,alt:s.name}),t.jsx("span",{children:s.name}),t.jsx("button",{title:j("input.remove"),onClick:()=>Jt($t.filter((v,w)=>w!==d)),children:t.jsx(at,{size:12})})]},`${s.name}-${d}`))}),Lt.length>0&&t.jsx("div",{className:"t2c-chiprow",children:Lt.map((s,d)=>t.jsxs("span",{className:"attach-chip",title:j("input.wsUploadTitle",{name:s.name}),children:[s.mimeType.startsWith("image/")?t.jsx("img",{src:`data:${s.mimeType};base64,${s.data}`,alt:s.name}):t.jsx(ta,{size:14,style:{color:"var(--accent-ink)",flexShrink:0}}),t.jsx("span",{children:s.name}),t.jsx("span",{style:{fontSize:"var(--ui-font-caption, 11px)",color:"var(--text-faint)",flexShrink:0},children:j("input.toWorkspace")}),t.jsx("button",{title:j("input.remove"),onClick:()=>wn(Lt.filter((v,w)=>w!==d)),children:t.jsx(at,{size:12})})]},`ws-${s.name}-${d}`))}),Dt.length>0&&t.jsx("div",{className:"t2c-chiprow",children:Dt.map(s=>t.jsxs("span",{className:"attach-chip",title:j("input.skillChipTitle"),children:[t.jsx(Hi,{size:13,style:{color:"var(--accent-ink)",flexShrink:0}}),t.jsx("span",{children:s.name}),t.jsx("button",{title:j("input.remove"),onClick:()=>ss(Dt.filter(d=>d.id!==s.id)),children:t.jsx(at,{size:12})})]},`skill-${s.id}`))}),t.jsx(ic,{autoSize:!1,ref:we,className:"t2c-ta",rows:1,autoFocus:o,value:pe,placeholder:i?c||j("input.placeholderDisabled"):zn?j("livecall.typeHint"):r?xt?j("input.runningPlaceholder"):j("input.tip",{tip:j(pa[ua%pa.length])}):j(ha?"input.placeholderTouch":"input.placeholder"),"data-tip-fade":r&&!xt&&Fo||void 0,"data-tip-tall":r&&!xt&&es||void 0,disabled:i,onChange:s=>{me(s.target.value),wt(s.target.selectionStart||0),ka(!1),ja(!1),za(!1),en&&tn(0),s.target.value.includes("@")||(as(""),is([])),ie()},onSelect:s=>wt(s.target.selectionStart||0),onPaste:s=>{const d=s.clipboardData?.files;if(!d?.length)return;s.preventDefault();const v=Array.from(d),w=v.filter(G=>G.type.startsWith("image/")),S=v.filter(G=>!G.type.startsWith("image/")),I=[];if(S.length){const G=[];for(const oe of S){let he="";if(de)try{he=window.tangu?.getPathForFile?.(oe)||""}catch{he=""}he?G.push(he):I.push(oe)}G.length&&(Pt(G.map(At)),requestAnimationFrame(()=>{we.current?.focus(),ie()}))}if(w.length){const G=new DataTransfer;w.forEach(oe=>G.items.add(oe)),Ja(G.files)}if(I.length){const G=new DataTransfer;I.forEach(oe=>G.items.add(oe)),ds(G.files)}},onKeyDown:s=>{if(us){if(s.key==="ArrowDown"){s.preventDefault(),Nn(d=>(d+1)%vt.length);return}if(s.key==="ArrowUp"){s.preventDefault(),Nn(d=>(d-1+vt.length)%vt.length);return}if((s.key==="Enter"||s.key==="Tab")&&!s.nativeEvent.isComposing){s.preventDefault(),Ya(vt[Math.min(Na,vt.length-1)]);return}if(s.key==="Escape"){s.preventDefault(),za(!0);return}}if(Ba){if(s.key==="ArrowDown"){s.preventDefault(),Sn(d=>(d+1)%ft.length);return}if(s.key==="ArrowUp"){s.preventDefault(),Sn(d=>(d-1+ft.length)%ft.length);return}if((s.key==="Enter"||s.key==="Tab")&&!s.nativeEvent.isComposing){s.preventDefault(),Ua(ft[Math.min(wa,ft.length-1)]);return}if(s.key==="Escape"){s.preventDefault(),ja(!0);return}}if(Ot){if(s.key==="ArrowDown"){s.preventDefault(),Oe(d=>(d+1)%pt.length);return}if(s.key==="ArrowUp"){s.preventDefault(),Oe(d=>(d-1+pt.length)%pt.length);return}if((s.key==="Enter"||s.key==="Tab")&&!s.nativeEvent.isComposing){s.preventDefault(),pt[Math.min(va,pt.length-1)]?.run();return}if(s.key==="Escape"){s.preventDefault(),ka(!0),jn(null);return}}if(s.key==="ArrowUp"&&kt?.length&&ca&&en===0&&s.currentTarget.selectionStart===s.currentTarget.selectionEnd&&pe.slice(0,s.currentTarget.selectionStart).indexOf(`
|
|
30
|
+
`)===-1){s.preventDefault();const d=kt[kt.length-1];ca(d.id).then(v=>{v&&(me(w=>w.trim()?`${v}
|
|
31
|
+
|
|
32
|
+
${w}`:v),requestAnimationFrame(()=>{const w=we.current;w&&(w.focus(),w.selectionStart=w.selectionEnd=v.length,wt(v.length)),ie()}))});return}if(s.key==="ArrowUp"&&s.currentTarget.selectionStart===s.currentTarget.selectionEnd&&pe.slice(0,s.currentTarget.selectionStart).indexOf(`
|
|
33
|
+
`)===-1&&dt?.length){s.preventDefault(),_a(!0);return}if(s.key==="ArrowDown"&&en>0&&s.currentTarget.selectionStart===s.currentTarget.selectionEnd&&pe.slice(s.currentTarget.selectionStart).indexOf(`
|
|
34
|
+
`)===-1){s.preventDefault(),_a(!1);return}s.key==="Enter"&&!s.shiftKey&&!s.nativeEvent.isComposing&&(s.preventDefault(),An())}}),Ot&&t.jsx("div",{className:"t2c-menu",children:pt.map((s,d)=>t.jsxs("button",{className:"t2c-menu-item","data-active":d===Math.min(va,pt.length-1)||void 0,onMouseEnter:()=>Oe(d),onClick:()=>s.run(),children:[t.jsx("span",{className:"t2c-menu-cmd",children:s.cmd}),t.jsx("span",{className:"t2c-menu-desc",children:s.desc})]},`${s.cmd}-${d}`))}),Ba&&!us&&t.jsxs("div",{className:"t2c-menu",children:[t.jsx("div",{className:"t2c-menu-sec",children:j(cn?"input.mention.projectNote":rn?"input.mention.groupNote":"input.mention.delegateNote")}),ft.map((s,d)=>t.jsxs("button",{className:"t2c-menu-item","data-active":d===Math.min(wa,ft.length-1)||void 0,onMouseEnter:()=>Sn(d),onClick:()=>Ua(s),children:[t.jsxs("span",{className:"t2c-menu-cmd",children:["@",s.name]}),t.jsx("span",{className:"t2c-menu-desc",children:s.description||s.slug})]},s.slug))]}),us&&t.jsxs("div",{className:"t2c-menu",children:[t.jsx("div",{className:"t2c-menu-sec",children:j("input.fileref.note")}),vt.map((s,d)=>t.jsxs("button",{className:"t2c-menu-item","data-active":d===Math.min(Na,vt.length-1)||void 0,onMouseEnter:()=>Nn(d),onClick:()=>Ya(s),children:[t.jsx("span",{className:"t2c-menu-cmd",children:s.session?`💬 ${s.session.title}`:s.note?`${Ha[s.p]?`${Ha[s.p]} `:""}${s.p.split("/").pop().replace(/\.md$/i,"")}`:s.p.split("/").pop()}),t.jsx("span",{className:"t2c-menu-desc",children:s.session?s.session.summary||j("input.fileref.session"):s.p})]},s.session?`s:${s.session.id}`:(s.note?"n:":"f:")+s.p))]}),t.jsxs(oc,{children:[t.jsx(ku,{open:Re==="add",disabled:i,activeSessionId:fe,canUsePathPicker:de,onOpenChange:s=>Ke(s?"add":null),onNewSession:Ue,onAddAgent:!r&&!ke&&!be?Ae||(Ie?()=>Qt(!0):void 0):void 0,onPickPaths:rr,onPickFiles:ei,onAddReference:cr}),Jo?t.jsx(su,{analyser:ue.analyser,recording:ue.recording,busy:ue.busy,onStop:ue.toggle,onSend:Zo,t:j}):t.jsxs(t.Fragment,{children:[gr&&t.jsxs("span",{className:`mode-pill-wrap t2c-capsule-peer${Re==="mode"?" is-open":""}`,"data-cmenu":!0,children:[t.jsxs("button",{className:`t2c-pill mode-pill-btn${Re==="mode"?" is-open":""}${Q&&!ke?" active":""}`,"data-danger":si||void 0,title:j(si?"input.approval.fullAutoDesc":"input.modeChipTitle"),"aria-expanded":Re==="mode",onClick:()=>{if(Re!=="mode"&&aa(xr,{})){Ke(null);return}Ke(s=>s==="mode"?null:"mode")},children:[t.jsx(fr,{size:13}),t.jsx("span",{className:"t2c-pill-label",children:mr}),t.jsx(yn,{size:10})]}),Re==="mode"&&t.jsxs("div",{ref:Pa.ref,className:"composer-menu composer-menu--mode",style:Pa.style,children:[Le&&!ke&&t.jsx(xu,{...ai}),[ps,ms].map(s=>s&&t.jsxs(mn.Fragment,{children:[t.jsx("div",{className:"menu-section",children:s.title}),s.items.map(d=>t.jsxs("button",{className:`menu-item${d.checked?" active":""}`,disabled:d.disabled,onClick:d.run,children:[d.icon,t.jsx("span",{className:"grow",children:d.label}),d.checked&&t.jsx(ot,{size:13})]},d.id))]},s.items[0].id)),de&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"menu-section",children:j(h?"input.approvalSection.team":"input.approvalSection")}),ii.map(s=>t.jsxs("button",{className:`menu-item approval-item${s.checked?" active":""}${s.danger?" danger":""}`,"aria-describedby":`approval-mode-desc-${s.approvalId}`,onClick:s.run,children:[s.icon,t.jsx("span",{className:"grow approval-title",children:s.label}),s.checked&&t.jsx(ot,{size:13,className:"approval-ck"}),t.jsx("span",{id:`approval-mode-desc-${s.approvalId}`,role:"tooltip",className:"approval-hover-desc",children:s.detail})]},s.approvalId)),Ct&&t.jsxs("button",{className:"menu-item approval-item","aria-describedby":"approval-edit-rules-desc",onClick:Ct.run,children:[Ct.icon,t.jsx("span",{className:"grow approval-title",children:Ct.label}),t.jsx("span",{id:"approval-edit-rules-desc",role:"tooltip",className:"approval-hover-desc",children:Ct.detail})]})]})]})]}),t.jsx("span",{className:"t2c-grow"}),!ke&&!!St&&St>0&&(()=>{const s=Math.min(100,Math.round((He||0)/St*100)),d=ls?.compactAt?(He||0)>=ls.compactAt*.8:s>=80,v=9,w=2*Math.PI*v;return t.jsxs("span",{className:`t2c-ctxring t2c-collapse-on-capsule-open${Re==="ctx"?" is-open":""}`,"data-warn":d||void 0,"data-cmenu":!0,children:[t.jsx("button",{type:"button",className:"t2c-ctxring-btn","aria-expanded":Re==="ctx","aria-label":`${j("input.ctxLabel")} ${s}%`,...oo(()=>Re==="ctx"?null:[`${j("input.ctxLabel")} ${s}%`]),onClick:()=>{sl(),Ke(S=>S==="ctx"?null:"ctx")},children:t.jsxs("svg",{viewBox:"0 0 24 24",width:"20",height:"20","aria-hidden":"true",children:[t.jsx("circle",{className:"t2c-ctxring-track",cx:"12",cy:"12",r:v}),t.jsx("circle",{className:"t2c-ctxring-fill",cx:"12",cy:"12",r:v,style:{strokeDasharray:w,strokeDashoffset:w*(1-s/100)}})]})}),t.jsx("span",{ref:Da.ref,className:"t2c-ctxring-pop",style:Da.style,children:t.jsx(Lu,{open:Re==="ctx",contextWindow:St,ctxTokens:He,sessionTokens:Ve,runCost:m,costLimit:R,ctxInfo:ls,onCompact:X?()=>{X(),Ke(null)}:void 0})})]})})(),kr&&t.jsx(Gc,{scopeKey:`${fe??"draft"}:${rc(er)}:${be?"engine":"tangu"}`,className:"t2c-capsule-peer",open:Re==="model",onOpenChange:s=>Ke(s?"model":null),disabled:i,modelId:be?z:k,groups:yr,onSelect:be?s=>B?.(s):s=>x?.(s),thinkingLevel:be?void 0:jt,onThinkingChange:be||!U?void 0:(s,d)=>{on(s,d)},allowUltra:ht,ultra:_t,running:r,supportedThinking:be?void 0:p?.find(s=>s.id===k)?.thinkingLevels,effectiveThinking:be?void 0:N?.thinkingRequested===(jt||"medium")?N?.thinkingEffective:void 0,modelsResponse:be?void 0:f,defaultModelIds:be?void 0:C,onDefaultModelChange:be?void 0:g,onContextWindowChange:be?void 0:O,emptyLabel:be?j("input.engineModelDefault"):void 0,footnote:!be&&!de&&!p?.some(s=>s.source==="direct")?j("input.cloudModelHint"):void 0}),t.jsx("button",{className:`t2c-iconbtn t2c-mic-control t2c-collapse-on-capsule-open${ue.recording?" recording":""}`,title:ue.busy?j("input.micBusy"):ue.recording?j("input.micStop"):ue.error||j("input.micStart"),disabled:i||ue.busy||!ue.supported,onClick:ue.toggle,children:ue.busy?t.jsx(Kt,{size:14,className:"spin"}):t.jsx(cc,{size:14})}),r?t.jsxs(t.Fragment,{children:[(!!pe.trim()||nt.length>0)&&t.jsx(vs,{onClick:An,disabled:i,title:j("input.send"),"aria-label":j("input.send")}),t.jsxs("button",{className:"t2c-stop",onClick:H,title:j("input.stop"),"aria-label":j("input.stop"),children:[t.jsx(Vi,{size:10}),t.jsx("span",{className:"t2c-stop-label",children:j("input.stop")})]})]}):pr&&!pe.trim()&&!nt.length&&!$t.length&&!Lt.length&&!se&&!Dt.length?t.jsx(vs,{className:"t2c-live-control",onClick:()=>{sr()},disabled:!!i||cs,title:j(zn?"livecall.return":"livecall.start"),"aria-label":j(zn?"livecall.return":"livecall.start"),children:cs?t.jsx(Kt,{size:16,className:"spin"}):t.jsx(kl,{size:16})}):t.jsx(vs,{onClick:An,disabled:i||!pe.trim()&&!nt.length,title:j("input.send"),"aria-label":j("input.send")})]})]}),ue.error&&!ue.recording&&!ue.busy&&t.jsx("div",{className:"t2c-hint",style:{marginTop:6,marginBottom:0},children:ue.error}),Ia&&Cn&&!ue.error&&t.jsx("div",{className:"t2c-hint",style:{marginTop:6,marginBottom:0},children:Ia})]})]}),lr&&t.jsx(fu,{cfg:ur,onClose:()=>ti(!1)}),ir&&t.jsx(iu,{offerFullAccess:de&&!h&&an!=="full-auto",onConfirm:({fullAccess:s})=>{s&&b({execMode:"host",approvalMode:"full-auto",cwd:l.cwd}),U?.("max",!0)},onClose:()=>La(!1)})]})};function Ku(e,n){const a=Math.max(0,e.content-e.width);if(e.left>=a-1)return 0;const o=e.left+e.width,i=n.find(r=>r.end>o+1),c=i?Math.min(i.start,a):a;return c>e.left+1?c:Math.min(o,a)}function Yu(e,n){return e-n>1}xe({"chatPicker.engine":{zh:"引擎",en:"Engine"},"chatPicker.agent":{zh:"Agent",en:"Agent"}});function Xu({label:e,value:n,icon:a,options:o,onChange:i,busy:c=!1}){const r=o.find(l=>l.value===n);return t.jsxs("label",{className:"compact-chat-picker","aria-busy":c||void 0,title:r?.name,children:[t.jsx("span",{className:"compact-chat-picker-kind",children:e}),t.jsx("span",{className:"compact-chat-picker-icon",children:a}),t.jsx("span",{className:"compact-chat-picker-name",children:r?.name||e}),t.jsx(yn,{size:13}),t.jsxs("select",{"aria-label":e,value:r?n:"",onChange:l=>i(l.target.value),children:[!r&&t.jsx("option",{value:"",disabled:!0,children:e}),o.map(l=>t.jsx("option",{value:l.value,disabled:l.disabled,children:l.description?`${l.name} — ${l.description}`:l.name},l.value))]})]})}const Gu=({label:e,children:n,role:a="radiogroup"})=>{const{t:o}=Ce(),i=u.useRef(null),[c,r]=u.useState(!1);u.useLayoutEffect(()=>{const h=i.current;if(!h)return;const p=()=>{const k=h.parentElement,x=k&&getComputedStyle(k),A=k&&x?k.clientWidth-parseFloat(x.paddingLeft)-parseFloat(x.paddingRight):h.clientWidth;r(Yu(h.scrollWidth,A))};p();const f=new ResizeObserver(p);f.observe(h);for(const k of Array.from(h.children))f.observe(k);return()=>f.disconnect()},[n]),u.useEffect(()=>{const h=i.current,p=h?.querySelector('[aria-checked="true"],[aria-pressed="true"]');if(!h||!p)return;const f=h.getBoundingClientRect(),k=p.getBoundingClientRect();k.right>f.right?h.scrollLeft+=k.right-f.right+6:k.left<f.left&&(h.scrollLeft-=f.left-k.left+6)},[]);const l=u.useCallback(()=>{const h=i.current;if(!h)return;const p=h.getBoundingClientRect(),f=Array.from(h.children).map(k=>{const x=k.getBoundingClientRect();return{start:x.left-p.left+h.scrollLeft,end:x.right-p.left+h.scrollLeft}});h.scrollTo({left:Ku({left:h.scrollLeft,width:h.clientWidth,content:h.scrollWidth},f),behavior:"smooth"})},[]);return t.jsxs("div",{className:"engine-picker-bar","data-more":c||void 0,children:[t.jsx("div",{className:"engine-picker-scroll",ref:i,role:a,"aria-label":e,children:n}),c&&t.jsx("button",{type:"button",className:"engine-picker-more",onClick:l,title:o("pill.more"),"aria-label":o("pill.more"),children:t.jsx(qn,{size:16})})]})};function Ju(e,n,a){const o=mc(e,n),i=o.groupAgents??[];return o.groupChat&&i.length>=2?{kind:"team",count:i.length}:{kind:"agent",slug:o.agentSlug||a||null}}const Vs=e=>Array.from((e||"").trim());function Zu(e,n){const a=e.map(r=>r.toLowerCase()),o=a.join("");let i=0;for(const r of n){if(!r.length||r.join("")===o||r[0]!==a[0])continue;let l=0;for(;l<a.length&&l<r.length&&a[l]===r[l];)l++;i=Math.max(i,l)}const c=[];for(let r=i;i&&r<e.length;r++)e[r].trim()&&c.push(e[r]);return{first:e[0],picks:c,collides:i>0}}function Qu(e){const n=e.map(l=>Vs(l)),a=n.map(l=>l.map(h=>h.toLowerCase())),o=n.map(()=>"?"),i=new Set,c=[];n.forEach((l,h)=>{if(!l.length)return;const{first:p,picks:f,collides:k}=Zu(l,a);if(!k||!f.length){o[h]=p.toUpperCase(),i.add(p.toLowerCase());return}c.push({index:h,key:a[h].join(""),picks:f,first:p})}),c.sort((l,h)=>l.key<h.key?-1:l.key>h.key?1:l.index-h.index);const r=new Map;for(const l of c){const h=r.get(l.key);if(h){o[l.index]=h;continue}const f=(l.picks.find(k=>!i.has(k.toLowerCase()))??l.first).toUpperCase();i.add(f.toLowerCase()),r.set(l.key,f),o[l.index]=f}return o}function ed(e,n=[]){const a=Vs(e);if(!a.length)return"?";const o=a.join("").toLowerCase();let i=n.findIndex(r=>Vs(r).join("").toLowerCase()===o);const c=i>=0?n:[e,...n];return i<0&&(i=0),Qu(c)[i]}const Li=(...e)=>e.filter(Boolean).join(" ")||void 0;function td({name:e,url:n,siblings:a,className:o,imgClassName:i,initialClassName:c,size:r,fill:l,title:h,style:p,...f}){return n?t.jsx("img",{...f,className:Li(o,i),src:n,alt:"",title:h,draggable:!1,width:r,height:r,style:p}):t.jsx("span",{...f,className:Li("agent-avatar-initial",l&&"agent-avatar-fill",o,c),title:h,"aria-hidden":"true",style:p,children:t.jsx("span",{className:"agent-avatar-glyph",children:ed(e,a)})})}xe({"agentSelect.title":{zh:"选择 Agent",en:"Pick agents"},"agentSelect.hintDefault":{zh:"由默认 Agent {name} 处理",en:"Handled by the default agent, {name}"},"agentSelect.hintDefaultAnon":{zh:"由默认 Agent 处理",en:"Handled by the default agent"},"agentSelect.hintOne":{zh:"{name} 将处理这条消息",en:"{name} will handle this message"},"agentSelect.removeHint":{zh:"再次点击移除",en:"Click again to remove"},"agentSelect.team":{zh:"团队模式 · {n} 人",en:"Team mode · {n} people"},"agentSelect.picked":{zh:"已选",en:"Picked"},"agentSelect.default":{zh:"默认 Agent",en:"Default agent"},"agentSelect.defaultTag":{zh:"默认",en:"Default"},"agentSelect.direct":{zh:"私聊",en:"Direct chat"}});const Ut=2,qt=e=>`agent:${e}`,dn=e=>`engine:${e}`,nd=(e,n)=>e.length===n.length&&e.every((a,o)=>a===n[o]);function sd(e){if(e.engineId)return[];const n=e.groupAgents??[];return e.groupChat&&n.length>=2?[...n]:e.agentSlug?[e.agentSlug]:[]}function bh({sessionId:e,cfg:n}){const{t:a}=Ce(),[o,i]=u.useState(null),c=D(fc(y=>({agentDefs:y.agentDefs,agentAvatars:y.agentAvatars,defaultAgentSlug:y.defaultAgentSlug,engines:y.engines,engineCaps:y.engineCaps,teams:y.teams}))),r=D(y=>e?null:gc(y,vc())),l=D(y=>r?y.projectSettingsByPath[r]??null:null),h=D(y=>!r||r in y.projectSettingsByPath);u.useEffect(()=>{r&&!h&&D.getState().ensureProjectSettings(r).catch(()=>null)},[r,h]);const p=n.engineId||"",f=sd(n),k=p?[dn(p)]:f.map(qt),x=p&&!c.engineCaps[p]?p:"",A=u.useMemo(()=>{const y=c.agentDefs.map(q=>({id:qt(q.slug),kind:"agent",slug:q.slug,name:q.name,description:q.description,system:q.createdBy==="system"}));for(const q of n.groupAgents??[]){if(y.some(Se=>Se.id===qt(q)))continue;const te=n.groupTempAgents?.find(Se=>Se.slug===q);y.push({id:qt(q),kind:"agent",slug:q,name:te?.name||q,description:te?.description})}if(n.agentSlug&&!y.some(q=>q.id===qt(n.agentSlug))&&y.push({id:qt(n.agentSlug),kind:"agent",slug:n.agentSlug,name:n.agentSlug}),n.execMode==="host")for(const q of c.engines)q.available&&y.push({id:dn(q.id),kind:"engine",engineId:q.id,name:q.name});return p&&!y.some(q=>q.id===dn(p))&&y.push({id:dn(p),kind:"engine",engineId:p,name:c.engines.find(q=>q.id===p)?.name||p}),y},[c.agentDefs,c.engines,p,n.execMode,n.groupAgents,n.groupTempAgents,n.agentSlug]),E=u.useMemo(()=>new Map(A.map(y=>[y.id,y])),[A]),M=u.useMemo(()=>A.filter(y=>y.kind==="agent").map(y=>y.name),[A]),z=k.map(y=>E.get(y)).filter(y=>!!y),B=A.filter(y=>!k.includes(y.id)),_=n.groupChat?f.length:0,L=y=>{const q=!!n.groupChat&&f.length<Ut;if(!p&&!q&&nd(f,y))return;const te=D.getState(),Se=!!p,ge=(n.groupTempAgents||[]).filter(Ae=>y.includes(Ae.slug)),ye=Se?{engineId:void 0,engineModelId:void 0}:{};if(y.length>=Ut){const Ae={groupChat:!0,groupAgents:y,groupTempAgents:ge.length?ge:void 0,...ye};e?te.patchSessionConfig(Ae,e):te.setNewChatCfg(Le=>({...Le,...Ae}));return}const Be=y[0]||"",Ie={groupChat:!1,groupAgents:void 0,groupTempAgents:void 0,...ye};e?te.selectSessionAgent(Be,e,Ie):(te.setNewChatCfg(Ae=>({...Ae,...Ie})),te.selectNewChatAgent(Be))},U=y=>{const q=D.getState();e?q.setSessionEngine(y,e):q.setNewChatCfg(te=>({...te,engineId:y||void 0,engineModelId:void 0,...y?{groupChat:!1,groupAgents:void 0,agentSlug:void 0}:{}}))},J=u.useRef(null),C=u.useRef(null);u.useEffect(()=>{const y=J.current;if(!y)return;J.current=null,C.current?.querySelector(`[data-pill-id="${CSS.escape(y)}"]`)?.focus()});const g=y=>{if(J.current=y.id,y.kind==="engine"){U(y.engineId===p?"":y.engineId);return}const q=f.includes(y.slug)?f.filter(te=>te!==y.slug):[...f,y.slug];L(q)},O=()=>{p?U(""):L([])},Y=y=>{y.kind==="agent"?di("agent",y.slug):di("engine",y.engineId)},F=y=>y.kind==="engine"?x===y.engineId?t.jsx(Kt,{size:16,className:"spin"}):t.jsx(ki,{engineId:y.engineId,size:16}):t.jsx(td,{name:y.name,url:c.agentAvatars[y.slug],siblings:M,imgClassName:"agent-pill-avatar",initialClassName:"agent-pill-initial"}),P=(y,q)=>{const te=y.kind==="agent"&&y.description?`${y.name} — ${y.description}`:y.name;return q?`${te} · ${a("agentSelect.removeHint")}`:y.kind==="agent"&&y.slug===c.defaultAgentSlug?`${te} · ${a("agentSelect.defaultTag")}`:te},$=(y,q)=>{const te=q!==null,Se=y.kind==="engine"&&x===y.engineId;return t.jsxs("button",{type:"button","aria-pressed":te,"data-pill-id":y.id,className:`engine-pill agent-pill${te?" selected":""}`,"data-agent-slug":y.kind==="agent"?y.slug:void 0,"data-engine-id":y.kind==="engine"?y.engineId:void 0,title:P(y,te),disabled:!!x&&!Se,onClick:()=>{(!x||Se)&&g(y)},onContextMenu:ge=>{ge.preventDefault(),i({...Kc(ge),items:[{label:a("agentSelect.direct"),icon:t.jsx(Zi,{size:13}),run:()=>Y(y)}]})},children:[te&&z.length>=Ut&&t.jsx("span",{className:"agent-pill-index",children:q+1}),t.jsx("span",{className:"engine-pill-icon",children:F(y)}),t.jsx("span",{className:"engine-pill-label",children:y.name}),y.kind==="agent"&&y.system&&t.jsx("span",{className:"agent-badge-system",children:a("agent.badge.system")})]},y.id)};if(n.preset==="chat"||!A.length)return null;const W=Ju(n,e?{}:yc(l,Array.isArray(c.teams)?c.teams:[]).config,c.defaultAgentSlug),K=W.kind==="agent"&&W.slug?c.agentDefs.find(y=>y.slug===W.slug)?.name:void 0,Q=_>=Ut?a("agentSelect.team",{n:_}):z.length===1?a("agentSelect.hintOne",{name:z[0].name}):W.kind==="team"?a("agentSelect.team",{n:W.count}):K?a("agentSelect.hintDefault",{name:K}):a("agentSelect.hintDefaultAnon"),Z=_<Ut&&z.length!==1&&W.kind!=="team",T=k[0]||"",ae=z[0]?F(z[0]):t.jsx(ki,{engineId:"",size:16});return t.jsxs("div",{ref:C,className:"engine-picker agent-picker agent-select-strip",role:"group","aria-label":a("agentSelect.title"),children:[t.jsx(Xu,{label:a("chatPicker.agent"),value:T,icon:ae,options:[{value:"",name:a("agentSelect.default")},...A.map(y=>({value:y.id,name:y.name,description:k.includes(y.id)?a("agentSelect.picked"):y.kind==="agent"?y.description:void 0,disabled:!!x&&y.id!==dn(x)}))],onChange:y=>{if(!y){O();return}const q=E.get(y);q&&g(q)},busy:!!x}),t.jsx(Gu,{label:a("agentSelect.title"),role:"group",children:[...z.map((y,q)=>$(y,q)),...z.length>0?[t.jsx("span",{className:"agent-select-sep","aria-hidden":"true"},"sep")]:[],...B.map(y=>$(y,null))]}),t.jsx("div",{className:`engine-picker-hint${_>=Ut?" agent-select-team":""}${Z?" is-default":""}`,children:Q}),o&&t.jsx(Vc,{menu:o,onClose:()=>i(null)})]})}const ad=e=>`${e.name} ${e.path||""} ${e.project||""}`,id=e=>[e.path,e.project].filter(n=>!!n&&n!==e.name).join(" · ")||void 0,jh=({workspaces:e,value:n,onChange:a,onAddProject:o,onAddCloudProject:i})=>{const{t:c}=Ce(),[r,l]=u.useState(!1),[h,p]=u.useState(""),[f,k]=u.useState(!1),[x,A]=u.useState(""),E=u.useRef(null),M=u.useRef(null),z=Yt(r);u.useEffect(()=>{if(!r)return;const T=y=>{E.current&&!E.current.contains(y.target)&&(l(!1),p(""),k(!1),A(""))},ae=y=>{y.key==="Escape"&&(l(!1),p(""),k(!1),A(""),E.current?.querySelector(".project-pill")?.focus())};return window.addEventListener("mousedown",T),window.addEventListener("keydown",ae),()=>{window.removeEventListener("mousedown",T),window.removeEventListener("keydown",ae)}},[r]);const B=e.filter(T=>T.kind!=="channel"),_=B.find(T=>T.key===n||!!n&&T.sessionKeys?.includes(n))||B.find(T=>T.kind==="local"&&T.system)||B[0]||null,L=B.find(T=>T.kind==="rootless")||null,U=B.filter(T=>T.kind!=="rootless"),J=h.trim().toLowerCase(),C=U.filter(T=>!J||ad(T).toLowerCase().includes(J)),g=U.length>=6,O=_?.kind==="cloud"?Vt:_?.kind==="rootless"?yi:Kn,Y=()=>{l(!1),p(""),k(!1),A("")},F=T=>{a(T),Y()},P=T=>({id:`ws:${T.key}`,label:T.name,detail:id(T),icon:T.kind==="cloud"?t.jsx(Vt,{size:14}):t.jsx(Kn,{size:14}),checked:T.key===_?.key,run:()=>F(T)}),$=L?{id:`ws:${L.key}`,label:c("input.project.dontWork"),icon:t.jsx(yi,{size:14}),checked:L.key===_?.key,run:()=>F(L)}:null,W=i?{id:"add-cloud",label:c("input.project.addCloud"),icon:t.jsx(Vt,{size:14}),run:()=>{{k(!0);return}}}:null,K=o?{id:"add-local",label:c("input.project.add"),icon:t.jsx(lo,{size:14}),run:()=>{o(),Y()}}:null,Q=()=>({title:c("input.project.label"),back:c("common.back"),...g?{search:{placeholder:c("input.project.search"),empty:c("input.project.noMatches")}}:{},sections:[{items:U.map(P)},{items:$?[$]:[]},{items:[W,K].filter(T=>!!T)}]});u.useEffect(()=>{if(!r||kc())return;const T=requestAnimationFrame(()=>{(g?M.current?.querySelector(".project-menu-search input"):M.current?.querySelector(".project-menu-item.active"))?.focus()});return()=>cancelAnimationFrame(T)},[r,g]);const Z=T=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(T.key))return;const ae=[...M.current?.querySelectorAll(".project-menu-item:not(:disabled)")||[]];if(!ae.length)return;T.preventDefault();const y=ae.indexOf(document.activeElement),q=T.key==="Home"?0:T.key==="End"?ae.length-1:y<0?T.key==="ArrowDown"?0:ae.length-1:T.key==="ArrowDown"?(y+1)%ae.length:(y-1+ae.length)%ae.length;ae[q]?.focus()};return t.jsxs("div",{className:`project-selector${r?" is-open":""}`,ref:E,children:[t.jsxs("button",{className:`composer-chip project-pill${r?" is-open":""}`,onClick:()=>{if(r){Y();return}aa(Q,{})||l(!0)},title:c("input.project.label"),"aria-haspopup":"menu","aria-expanded":r,children:[t.jsx(O,{size:13}),t.jsx("span",{className:"project-pill-name",children:_?.name||c("input.project.none")}),t.jsx(yn,{size:12})]}),r&&t.jsxs("div",{ref:T=>{M.current=T,z.ref.current=T},className:"composer-menu project-menu",style:z.style,role:"menu","aria-label":c("input.project.label"),onKeyDown:Z,children:[g&&t.jsxs("label",{className:"project-menu-search",children:[t.jsx(Yi,{size:13}),t.jsx("input",{value:h,onChange:T=>p(T.target.value),placeholder:c("input.project.search")})]}),t.jsxs("div",{className:"project-menu-list",children:[C.map(P).map(T=>t.jsxs("button",{className:`menu-item project-menu-item${T.checked?" active":""}`,role:"menuitemradio","aria-checked":!!T.checked,onClick:T.run,children:[T.icon,t.jsx("span",{className:"grow project-menu-name",children:T.label}),t.jsx("span",{className:"project-menu-check",children:T.checked?t.jsx(ot,{size:13}):null})]},T.id)),!C.length&&t.jsx("div",{className:"project-menu-empty",children:c("input.project.noMatches")})]}),$&&t.jsx("div",{className:"project-menu-section project-menu-projectless-section",role:"group",children:t.jsxs("button",{className:`menu-item project-menu-item project-menu-projectless${$.checked?" active":""}`,role:"menuitemradio","aria-checked":$.checked,onClick:$.run,children:[$.icon,t.jsx("span",{className:"grow project-menu-name",children:$.label}),t.jsx("span",{className:"project-menu-check",children:$.checked?t.jsx(ot,{size:13}):null})]})}),(W||K)&&t.jsxs("div",{className:"project-menu-section project-menu-actions",role:"group",children:[i&&W&&(f?t.jsxs("label",{className:"project-menu-search project-menu-naming",children:[t.jsx(Vt,{size:13}),t.jsx("input",{autoFocus:!0,value:x,onChange:T=>A(T.target.value),placeholder:c("input.project.cloudName"),onKeyDown:T=>{T.key==="Enter"&&x.trim()&&(i(x.trim()),Y()),T.key==="Escape"&&(T.stopPropagation(),A(""),k(!1))}})]}):t.jsxs("button",{className:"menu-item project-menu-item project-menu-add",role:"menuitem",onClick:W.run,children:[W.icon,t.jsx("span",{className:"grow",children:W.label})]})),K&&t.jsxs("button",{className:"menu-item project-menu-item project-menu-add",role:"menuitem",onClick:K.run,children:[K.icon,t.jsx("span",{className:"grow",children:K.label})]})]})]})]})},Ks=xc,Pi=/^[0-9a-zA-Z-]{8,64}$/;function jo(e){return e.kind==="unit"?`unit:${e.unitId.toLowerCase()}`:""}function od(e){if(typeof e=="string"){const a=/^unit:(.+)$/.exec(e);return a&&Pi.test(a[1])?Object.freeze({kind:"unit",unitId:a[1].toLowerCase()}):Ks}const n=e;return n&&typeof n=="object"&&n.kind==="unit"&&typeof n.unitId=="string"&&Pi.test(n.unitId)?Object.freeze({kind:"unit",unitId:n.unitId.toLowerCase()}):Ks}const rd=5*6e4,Di=new Set(["remoteOff","awaitingConfirm","denied","callerBlocked"]);function Ys(e){if(e==null)return null;const n=typeof e=="object"?e:{},a=typeof n.code=="string"?n.code:"",o=typeof n.status=="number"?n.status:NaN;switch(a){case"ENGINE_NOT_READY":return"starting";case"UNIT_OFFLINE":case"UNIT_DISCONNECTED":return"offline";case"UNIT_TIMEOUT":return"unreachable";case"REMOTE_SESSIONS_OFF":return"remoteOff";case"REMOTE_CALLER_UNCONFIRMED":return hl(n.reason)?"callerBlocked":n.state==="denied"?"denied":"awaitingConfirm";case"CALLER_UNAVAILABLE":case"CALLER_UNSUPPORTED":case"UNIT_CALLER_INVALID":case"UNIT_CALLER_EXPIRED":return"unreachable"}return a?o>=500?"unreachable":null:n.name==="TypeError"||n.name==="AbortError"||o===0||o>=500?"unreachable":null}const _i=e=>e.state||e.reason?{...e.state?{state:e.state}:{},...e.reason?{reason:e.reason}:{}}:void 0;function cd(e,n,a,o=Date.now()){if(!e.online)return{status:"offline"};if(e.capsLive&&e.caps){const i=e.caps.engine;if(i==="external")return{status:"noEngine"};if(i==="stopped")return{status:"engineStopped"};if(i==="starting")return{status:"starting"}}if(n&&!n.ok){const i=Ys(n)??"unreachable",c=Di.has(i)?_i(n):void 0;return c?{status:i,refusal:c}:{status:i}}if(a&&o-a.at>=0&&o-a.at<rd){const i=Ys({status:403,code:a.code,state:a.state,reason:a.reason});if(i&&Di.has(i)){const c=_i(a);return c?{status:i,refusal:c}:{status:i}}}return n?.ok?{status:"ready"}:{status:"checking"}}function ld(e){return!!(e.online&&e.capsLive&&e.caps?.engine==="ready")}const ud=1e4,dd=8e3,hd=50,pd={sessions:[],fetchedAt:null,loading:!1};async function md(){if(typeof window.tangu?.unitSelf=="function")try{const e=await window.tangu.unitSelf();return{id:e?.unitId?e.unitId.toLowerCase():null,registered:!!e?.registered}}catch{}try{const e=await window.tangu?.unitHostStatus?.();if(e?.unitId)return{id:e.unitId.toLowerCase(),registered:null}}catch{}return{id:null,registered:null}}function fd(e,n){return e.filter(a=>!!a&&typeof a.id=="string"&&na(a.id)&&(a.kind??"desktop")==="desktop"&&a.id.toLowerCase()!==n)}function gd(e){const n=e?.sessions;if(!Array.isArray(n))return[];const a=[];for(const o of n){if(!o||typeof o!="object")continue;const i=o;if(typeof i.id!="string"||!i.id||i.id.length>200||i.archived)continue;const{location:c,...r}=i;a.push({...r,title:typeof r.title=="string"?r.title:""})}return a}function rt(e){return{kind:"unit",unitId:e.toLowerCase()}}const le=Gn((e,n)=>({gen:0,units:null,byUnit:{},refreshedAt:0,selfRegistered:null,refreshRoster:async()=>{if(!bc()||!window.tangu?.unitsList)return null;const a=n().gen;let o=null;try{const r=await window.tangu.unitsList();r?.status===200&&Array.isArray(r.json?.units)&&(o=r.json.units)}catch{}if(a!==n().gen)return null;if(!o)return n().units;const i=await md(),c=fd(o,i.id);if(a!==n().gen)return null;for(const r of c)jc(rt(r.id),r.name);return e({units:c,selfRegistered:i.registered}),c},refresh:async(a={})=>{if(!Rt())return;const o=n().gen,i=await n().refreshRoster();if(!i||o!==n().gen||(await Promise.all(i.map(l=>vd(l,o,!!a.force,!!a.periodic))),o!==n().gen))return;const c=new Set(i.map(l=>l.id.toLowerCase())),r=Object.fromEntries(Object.entries(n().byUnit).filter(([l])=>c.has(l)));e({byUnit:r,refreshedAt:Date.now()}),kd()},reset:()=>{e(a=>({gen:a.gen+1,units:null,byUnit:{},refreshedAt:0,selfRegistered:null})),wc()}}));function et(e,n){const a=e.toLowerCase();le.setState(o=>({byUnit:{...o.byUnit,[a]:{...o.byUnit[a]??pd,...n}}}))}async function vd(e,n,a,o=!1){const i=e.id.toLowerCase(),c=le.getState().byUnit[i];if(o&&yd(Xt.getState().probes[i]))return;if(!e.online){et(i,{sessions:[],loading:!1});return}if(le.getState().selfRegistered===!1){et(i,{sessions:[],loading:!1});return}if(e.capsLive&&e.caps?.engine&&e.caps.engine!=="ready"){et(i,{sessions:[],loading:!1});return}if(!a&&c?.fetchedAt&&Date.now()-c.fetchedAt<ud)return;const r=kn(rt(i));if(r){et(i,{loading:!0});try{const l=await Sc(r,`/agent/sessions?archived=false&limit=${hd}&app_id=${encodeURIComponent(Nc)}`,{},{timeoutMs:dd});let h=null;try{h=await l.json()}catch{}if(n!==le.getState().gen)return;if(!l.ok){const k=h??{},x=hi({status:l.status,code:k.code,state:k.state,reason:k.reason});ys(i,x),et(i,{sessions:Oi(i,x),fetchedAt:Date.now(),loading:!1});return}const p=rt(i),f=gd(h).filter(k=>xn(k.id,p)?(console.warn(`[device-sessions] dropped session ${k.id} listed by ${i}: that id already belongs to another location`),!1):!0);ys(i,{ok:!0}),et(i,{sessions:f,fetchedAt:Date.now(),loading:!1})}catch(l){if(n!==le.getState().gen)return;const h=hi(l);ys(i,h),et(i,{sessions:Oi(i,h),fetchedAt:Date.now(),loading:!1})}}}function yd(e){if(!e||e.ok)return!1;const n=Cc(e.status,{code:e.code});return n==="caller-unavailable"||n==="gone"||n==="account-auth?"}function Oi(e,n){return Ys(n)==="unreachable"?le.getState().byUnit[e]?.sessions??[]:[]}function kd(){const e=le.getState().byUnit,n=new Map;for(const[c,r]of Object.entries(e))for(const l of r.sessions)fn(Qi(l.id),rt(c))&&n.set(l.id,l);if(!n.size)return;const a=D.getState();let o=!1;const i=a.sessions.map(c=>{const r=c.location?.kind==="unit"?n.get(c.id):void 0;return!r||r.title===c.title&&r.updated_at===c.updated_at&&r.summary===c.summary?c:(o=!0,{...c,title:r.title,updated_at:r.updated_at,summary:r.summary})});o&&D.setState({sessions:i})}function oa(e,n=Date.now()){const a=Xt.getState(),o=e.id.toLowerCase(),i=cd(e,a.probes[o]??null,a.sticky[o]??null,n);return i.status==="checking"&&le.getState().selfRegistered===!1&&ld(e)?{status:"ready"}:i}function So(e){const n=e.toLowerCase();return le.getState().units?.find(a=>a.id.toLowerCase()===n)??null}function Xs(e,n){if(!e?.id||!na(n.unitId))return!1;const a=rt(n.unitId);if(Mc(e.id,a)==="conflict")return console.warn(`[device-sessions] refused to open ${e.id} on ${a.unitId}: that id already belongs to another location`),!1;const{location:o,...i}=e,c=Ac(i);return D.setState(r=>({sessions:[c,...r.sessions.filter(l=>l.id!==e.id)],configBySession:r.configBySession[e.id]||!e.agent_config?r.configBySession:{...r.configBySession,[e.id]:e.agent_config}})),(Hn.getState().activeSpaceId==="home"||Hn.getState().activeSpaceId==="inbox")&&eo("tangu"),to(e.id),!0}async function Sh(e,n){if(!Rt()||!na(e)||!n)return!1;const a=rt(e);if(xn(n,a))return!1;const o=D.getState();if((o.sessions.find(l=>l.id===n)??o.archivedSessions.find(l=>l.id===n))&&fn(Qi(n),a))return(Hn.getState().activeSpaceId==="home"||Hn.getState().activeSpaceId==="inbox")&&eo("tangu"),to(n),!0;const c=le.getState().byUnit[a.unitId]?.sessions.find(l=>l.id===n);if(c)return Xs(c,a);const r=kn(a);if(!r)return!1;try{const l=await zc(r,n);return!l||l.id!==n?!1:Xs(l,a)}catch{return!1}}async function xd(e,n,a){const o=rt(e),i=kn(o);if(!i||xn(n,o))return;const c=l=>l.id===n?{...l,title:a}:l,r=le.getState().byUnit[o.unitId];r&&et(o.unitId,{sessions:r.sessions.map(c)}),D.setState(l=>({sessions:l.sessions.map(h=>h.location?.kind==="unit"?c(h):h)}));try{await sa(i,n,{title:a})}catch(l){D.getState().toast(D.getState().tr("app.renameFail",{e:l?.message||l}),!0)}}async function wd(e,n,a){const o=rt(e),i=kn(o);if(!i||xn(n,o))return!1;const c=Ec(a);if(a!==null&&!c)return D.getState().toast(D.getState().tr("session.icon.invalid"),!0),!1;try{const r=await sa(i,n,{emoji:c}),l=p=>p.id===n?{...p,emoji:r.emoji}:p,h=le.getState().byUnit[o.unitId];return h&&et(o.unitId,{sessions:h.sessions.map(l)}),D.setState(p=>({sessions:p.sessions.map(f=>f.location&&fn(f.location,o)?l(f):f),archivedSessions:p.archivedSessions.map(f=>f.location&&fn(f.location,o)?l(f):f)})),!0}catch(r){return D.getState().toast(D.getState().tr("session.icon.saveFail",{e:r?.message||r}),!0),!1}}async function bd(e,n){const a=rt(e),o=kn(a);if(!o||xn(n,a))return;try{await sa(o,n,{archived:!0})}catch(c){D.getState().toast(c?.message||String(c),!0);return}const i=le.getState().byUnit[a.unitId];i&&et(a.unitId,{sessions:i.sessions.filter(c=>c.id!==n)}),D.setState(c=>({sessions:c.sessions.filter(r=>!(r.id===n&&r.location?.kind==="unit"))})),D.getState().activeId===n&&D.getState().setActiveId(null)}let Fi=D.getState().cfg?.token??"";D.subscribe(e=>{const n=e.cfg?.token??"";n!==Fi&&(Fi=n,le.getState().reset())});const Xe=Gn(()=>({draftSeq:0,explicitSeq:null,reconciledSeq:null,explicitPending:!1,chooser:null}));function Nh(e){return Xe.setState({chooser:e}),()=>{Xe.getState().chooser===e&&Xe.setState({chooser:null})}}const jd="forsion_run_location:";function No(){const e=wr(Ic(),D.getState().cfg?.token||"");return e?`${jd}${e}`:null}function Sd(){const e=No();if(!e)return null;try{const n=localStorage.getItem(e);return n===null?null:od(n)}catch{return null}}function Co(e){const n=No();if(n)try{localStorage.setItem(n,jo(e))}catch{}}async function Ch(e,n){Co(e),Xe.setState({explicitPending:!0});try{await no(e,{name:n.name??null})}finally{Xe.setState(a=>({explicitSeq:a.draftSeq,explicitPending:!1}))}}let Wi=!1,Gs=!1;function zo(){if(!Rt())return!1;const e=Xe.getState();if(D.getState().activeId||e.explicitPending||e.explicitSeq===e.draftSeq||e.reconciledSeq===e.draftSeq)return!1;const n=Tc();let a=Sd();Wi||(Wi=!0,a===null&&n.kind==="unit"&&(a=n,Co(n)));let o=Ks,i=null;if(a?.kind==="unit"){if(le.getState().units===null)return!1;const c=So(a.unitId);if(c){const r=oa(c).status;if(r==="checking")return!1;r==="ready"&&(o=a,i=c.name)}}if(Xe.setState({reconciledSeq:e.draftSeq}),!fn(o,n)){Gs=!0;let c;try{c=no(o,{name:i})}finally{Gs=!1}c.catch(()=>{})}return!0}Rc(()=>{if(Gs)return;const e=Xe.getState();Xe.setState({explicitSeq:D.getState().activeId?e.draftSeq+1:e.draftSeq})});const Nd=1e4;let Ts=D.getState().activeId;D.subscribe(e=>{if(e.activeId===Ts)return;const n=Ts;if(Ts=e.activeId,n&&!e.activeId){Xe.setState(o=>({draftSeq:o.draftSeq+1}));const a=le.getState();Date.now()-a.refreshedAt<Nd?zo():a.refresh().catch(()=>{})}});le.subscribe((e,n)=>{e.refreshedAt!==n.refreshedAt&&zo()});xe({"session.icon.set":{zh:"设置图标",en:"Set icon"},"session.icon.invalid":{zh:"请选择一个 Emoji 作为会话图标",en:"Choose one emoji for the session icon"},"session.icon.saveFail":{zh:"图标未能保存:{e}",en:"Could not save the icon: {e}"}});function ra({emoji:e,fallback:n,size:a=17}){return e?t.jsx("span",{"data-session-emoji":e,"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:a,height:a,flexShrink:0,fontSize:a,lineHeight:1},children:e}):t.jsx(t.Fragment,{children:n??t.jsx(Zi,{size:a})})}function zh({params:e,size:n}){const a=D(o=>{const i=e.followActive!==!1?o.activeId:e.sessionId;return o.sessions.find(c=>c.id===i)?.emoji??o.archivedSessions.find(c=>c.id===i)?.emoji});return t.jsx(ra,{emoji:a,size:n})}function Mo({sessionId:e,current:n,x:a,y:o,onClose:i,onSave:c}){const r=u.useRef(!1),l=async h=>{if(!r.current){r.current=!0;try{await(c?c(h):D.getState().setSessionEmoji(e,h))&&i()}finally{r.current=!1}}};return ea.createPortal(t.jsx(pl,{x:a,y:o,current:n,onPick:h=>{l(h)},onClose:i}),document.body)}function Js({items:e}){return t.jsx(t.Fragment,{children:e.map(n=>t.jsxs("button",{type:"button",className:n.danger?"danger":void 0,"data-act":n.act,disabled:n.disabled,onClick:n.run,children:[n.icon," ",n.label]},n.id))})}const Ao=({open:e,children:n})=>{const a=al();return t.jsx(il,{initial:!1,children:e&&t.jsx(ol.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:a?0:.24,ease:[.2,.8,.3,1]},style:{overflow:"hidden"},children:n})})};function Cd({path:e,fallback:n,className:a}){const o=D(l=>l.projectSettingsByPath[e]?.icon),i=D(l=>l.projectIconUrls[e]),c=D(l=>l.connState==="ok"),r=br(o);return u.useEffect(()=>{c&&D.getState().ensureProjectSettings(e)},[e,c]),u.useEffect(()=>{c&&r&&D.getState().loadProjectIcon(e)},[e,c,r]),r?i?t.jsx("img",{className:a,src:i,alt:"",draggable:!1}):t.jsx(t.Fragment,{children:n}):o?t.jsx("span",{className:a,"aria-hidden":"true",children:o}):t.jsx(t.Fragment,{children:n})}xe({"agentRemove.title":{zh:"删除 Agent「{name}」?",en:'Delete agent "{name}"?'},"agentRemove.msg":{zh:"会从 Agent 名册和侧栏移除,历史私聊保留(只读)。它的记忆与 Library 默认保留在 Tangu 数据目录的 agents/.removed/ 里。",en:"It is removed from the agent roster and the sidebar; past direct chats are kept (read-only). By default its memory and Library are kept in agents/.removed/ in the Tangu data folder."},"agentRemove.msgCloud":{zh:"会从 Agent 名册移除,历史会话保留(只读)。",en:"It is removed from the agent roster; past sessions are kept (read-only)."},"agentRemove.files":{zh:"同时删除相关文件:它的记忆、Library 等,移到废纸篓",en:"Also delete related files: its memory, Library and the rest, moved to the Trash"},"agentRemove.confirm":{zh:"删除",en:"Delete"},"agentRemove.done":{zh:"已删除 Agent「{name}」",en:'Agent "{name}" deleted'}});function Eo({title:e,message:n,confirmLabel:a,filesLabel:o,onConfirm:i,onClose:c}){const[r,l]=u.useState(!1);return ea.createPortal(t.jsx("div",{className:"am-app tangu-lovable",style:{display:"contents"},"data-remove-dialog":!0,children:t.jsx(Ki,{title:e,message:n,confirmLabel:a,onConfirm:()=>i(!!o&&r),onClose:c,children:o&&t.jsxs("label",{className:"dialog-check",children:[t.jsx("input",{type:"checkbox",checked:r,onChange:h=>l(h.target.checked)}),t.jsx("span",{children:o})]})})}),document.body)}function Mh({agent:e,onDone:n,onClose:a}){const{t:o}=Ce(),i=!!e.libraryDir,c=e.name||e.slug;return t.jsx(Eo,{title:o("agentRemove.title",{name:c}),message:o(i?"agentRemove.msg":"agentRemove.msgCloud"),confirmLabel:o("agentRemove.confirm"),filesLabel:i&&window.tangu?.trashHostPath?o("agentRemove.files"):void 0,onConfirm:r=>{const l=D.getState();l.removeAgent(e,r).then(()=>{l.toast(o("agentRemove.done",{name:c})),n?.()}).catch(h=>l.toast(String(h?.message||h),!0))},onClose:a})}const Ro="forsion_orbits_pinned_entries_v1",vn=(e,n)=>Object.prototype.hasOwnProperty.call(e,n);function Bi(e,n){return vn(e,n)}function To(e,n){let a=0;for(const o of Object.values(e))Number.isFinite(o)&&(a=Math.max(a,o));return Math.max(n,a+1)}function Ah(e,n,a=Date.now()){if(vn(e,n)){const o={...e};return delete o[n],o}return{...e,[n]:To(e,a)}}function Eh(e,n,a=Date.now()){return vn(e,n)?{...e,[n]:To(e,a)}:e}function Rh(e=typeof localStorage>"u"?null:localStorage){if(!e)return{};try{const n=JSON.parse(e.getItem(Ro)||"{}");if(!n||typeof n!="object"||Array.isArray(n))return{};const a={};for(const[o,i]of Object.entries(n))o&&Number.isFinite(i)&&Number(i)>0&&(a[o]=Number(i));return a}catch{return{}}}function Th(e,n=typeof localStorage>"u"?null:localStorage){try{n?.setItem(Ro,JSON.stringify(e))}catch{}}function zd(e,n){return e.map((a,o)=>({entry:a,index:o})).sort((a,o)=>{const i=vn(n,a.entry.key),c=vn(n,o.entry.key);return i!==c?i?-1:1:i&&c?n[o.entry.key]-n[a.entry.key]||a.index-o.index:o.entry.at-a.entry.at||a.index-o.index}).map(({entry:a})=>a)}xe({"sidebar.attention":{zh:"{n} 项等你处理",en:"{n} waiting for you"},"sidebar.attentionLocalOnly":{zh:"{n} 项等你处理 · 含只能在那台电脑上批准的操作",en:"{n} waiting for you · includes actions that can only be approved on that computer"}});const Io=({n:e,localOnly:n})=>{const{t:a}=Ce();return t.jsx("span",{className:"t2s-dot attention","data-attention":e,title:a(n?"sidebar.attentionLocalOnly":"sidebar.attention",{n:e})})};xe({"chat.toNote.action":{zh:"整理成笔记",en:"Turn into note"},"chat.toNote.working":{zh:"正在把对话整理成笔记…",en:"Turning the chat into a note…"},"chat.toNote.empty":{zh:"这段对话还没有可整理的内容",en:"This chat has nothing to turn into a note yet"},"chat.toNote.done":{zh:"已整理成笔记「{name}」",en:"Saved as the note “{name}”"},"chat.toNote.failed":{zh:"没能整理成笔记:{reason}",en:"Couldn’t turn the chat into a note: {reason}"},"chat.toNote.workingTail":{zh:"对话较长,只整理最近的部分…",en:"This chat is long; only the most recent part will be turned into a note…"},"chat.toNote.emptyAnswer":{zh:"模型没有返回内容",en:"the model returned nothing"},"chat.toNote.nameTaken":{zh:"同名笔记太多(已试到 -20)",en:"too many notes with that name (tried up to -20)"}});const Md=["The text in <selection> is a chat transcript between a user and an AI assistant.","Turn it into a standalone, well-organized note that someone can reread later without the chat.",'Start with exactly one "# " heading that names the topic.',"Keep the conclusions, decisions, facts, numbers, code and step-by-step instructions; drop greetings, filler, retries and back-and-forth.","Use headings, lists and tables where they help. Do not mention that it came from a chat.","Write in the language the user wrote in."].join(" "),Zs=2e4;function $o(e){const n=[];for(const a of e){if(a.role!=="user"&&a.role!=="assistant")continue;const o=(a.role==="assistant"?Pc(a.content).text:a.content).trim();o&&n.push(`${a.role==="user"?"User":"Assistant"}:
|
|
35
|
+
${o}`)}return n.join(`
|
|
36
|
+
|
|
37
|
+
`)}function Ad(e){const n=$o(e);return n.length>Zs?n.slice(-Zs):n}function Ed(e,n){const a=/^\s*#[ \t]+(.+?)[ \t]*#*[ \t]*(?:\r?\n|$)/.exec(e);return{title:(a?a[1]:n).replace(/[\\/:*?"<>|#^[\]]/g," ").replace(/\s+/g," ").trim().slice(0,80)||n,body:(a?e.slice(a[0].length):e).replace(/^\s*\n/,"")}}function Rd(){return $c()&&!!so()?.complete}async function Td(e,n){for(let a=1;a<=20;a++){const o=`${a===1?e:`${e}-${a}`}.md`;if(await pi.readTextFile?.(o)?.catch(()=>null)!=null)continue;const i=await pi.writeTextFile(o,n,{create:!0,base:jr("")});if(!(i&&i.ok===!1))return o}return null}async function Id(e){const n=so()?.complete;if(!n)return!1;const a=D.getState(),o=[...a.sessions,...a.archivedSessions].find(i=>i.id===e);try{a.messagesBySession[e]?.length||await a.loadSessionHistory(e);const i=D.getState().messagesBySession[e]||[],c=Ad(i);if(!c)return Rn({text:Te("chat.toNote.empty"),level:"info",inAppOnly:!0}),!1;Rn({text:Te($o(i).length>Zs?"chat.toNote.workingTail":"chat.toNote.working"),level:"info",inAppOnly:!0});const r=await n({action:"custom",instruction:Md,selection:c,title:o?.title||void 0});if(!r.text.trim())throw new Error(Te("chat.toNote.emptyAnswer"));const{title:l,body:h}=Ed(r.text,o?.title?.trim()||Te("amadeus.default.note")),p=await Td(l,h.trimEnd()+`
|
|
38
|
+
`);if(!p)throw new Error(Te("chat.toNote.nameTaken"));return Rn({text:Te("chat.toNote.done",{name:l}),level:"success",receipt:!0}),Lc(p),!0}catch(i){return Rn({text:Te("chat.toNote.failed",{reason:i instanceof Error?i.message:String(i)}),level:"error",inAppOnly:!0}),!1}}const Ui={wechat:_c,telegram:Dc,qq:Ht};xe({"sidebar.openInNewTab":{zh:"在新标签页打开",en:"Open in new tab"},"sidebar.archiveN":{zh:"归档 {n} 项",en:"Archive {n}"},"sidebar.unarchiveN":{zh:"取消归档 {n} 项",en:"Unarchive {n}"},"sidebar.deleteN":{zh:"删除 {n} 项",en:"Delete {n}"},"sidebar.deleteConfirmN":{zh:"删除选中的 {n} 个会话?不可撤销。",en:"Delete {n} selected chats? This cannot be undone."},"sidebar.mode.chat":{zh:"Chat",en:"Chat"},"sidebar.mode.work":{zh:"Work",en:"Work"},"sidebar.mode.tip":{zh:"Chat:轻聊天,只列聊天会话;Work:完整工具面,列出全部项目",en:"Chat: light conversations, chat sessions only. Work: full toolset, all projects"},"sidebar.pin":{zh:"置顶",en:"Pin to top"},"sidebar.unpin":{zh:"取消置顶",en:"Unpin"},"sidebar.ws.details":{zh:"查看详情",en:"View details"},"sidebar.ws.removeTitle":{zh:"移除项目「{name}」?",en:'Remove project "{name}"?'},"sidebar.ws.removeMsg":{zh:"会从侧栏移除它,并删除其中的 {count} 个会话,不可撤销。磁盘上的项目文件夹不会删除。",en:"It is removed from the sidebar and its {count} session(s) are deleted. This cannot be undone. The project folder on disk is not deleted."},"sidebar.ws.removeFiles":{zh:"同时删除相关文件:项目里的 .tangu 文件夹(Tangu 的指令、技能、计划),移到废纸篓",en:"Also delete related files: the project's .tangu folder (Tangu instructions, skills and plans), moved to the Trash"},"sidebar.ws.removeAction":{zh:"移除",en:"Remove"}});const Lo="forsion_tangu_collapsed_projects",Po="forsion_tangu_workspace_order";function $d(){try{return new Set(JSON.parse(localStorage.getItem(Lo)||"[]"))}catch{return new Set}}function qi(e){try{localStorage.setItem(Lo,JSON.stringify([...e]))}catch{}}function Ld(){try{const e=JSON.parse(localStorage.getItem(Po)||"[]");return Array.isArray(e)?e.filter(n=>typeof n=="string"):[]}catch{return[]}}function Pd(e){try{localStorage.setItem(Po,JSON.stringify(e))}catch{}}function Qs(e){const n=String(e||"").trim();if(!n)return 0;const a=Date.parse(n.includes("T")?n:n.replace(" ","T"));return Number.isFinite(a)?a:0}const Dd=({icon:e,title:n,active:a,onClick:o,onExpand:i,act:c})=>t.jsxs("button",{className:`t2s-special${a?" active":""}`,"data-act":c,onClick:o,children:[t.jsx("span",{className:"t2s-special-ic",children:e}),t.jsx("span",{className:"t2s-special-title",children:n}),i&&t.jsx("span",{className:"t2s-special-go",onClick:r=>{r.stopPropagation(),i()},children:t.jsx(Et,{size:14})})]}),Ih=e=>{const{t:n}=Ce(),a=u.useRef(null),o=e.allSessions??e.sessions,i=e.allArchived??e.archivedSessions,c=rl(a),[r,l]=u.useState(null),[h,p]=u.useState(null),[f,k]=u.useState(null),[x,A]=u.useState(""),[E,M]=u.useState(()=>{try{return Math.max(1,Number(localStorage.getItem("tangu_ws_session_limit"))||5)}catch{return 5}});u.useEffect(()=>{const m=()=>{try{M(Math.max(1,Number(localStorage.getItem("tangu_ws_session_limit"))||5))}catch{}};return window.addEventListener("tangu:wslimit",m),()=>window.removeEventListener("tangu:wslimit",m)},[]);const[z,B]=u.useState(!1),[_,L]=u.useState($d),[U,J]=u.useState(Ld),[C,g]=u.useState(null),[O,Y]=u.useState(null),F=u.useRef(null),P=u.useRef(!1),[$,W]=u.useState(null),[K,Q]=u.useState(null),[Z,T]=u.useState(null),[ae,y]=u.useState(""),q=u.useRef(null),te=Dl(m=>m.channels),Se=u.useMemo(()=>{const m=new Map;for(const R of te)m.set(R.kind,R.runtime.some(N=>N.running));return m},[te]),ge=u.useMemo(()=>{const m=new Map;for(const R of e.workspaces)m.set(R.key,[]);for(const R of e.sessions){const N=oi(R,e.workspaces);m.has(N)||m.set(N,[]),m.get(N).push(R)}return m},[e.workspaces,e.sessions]),ye=u.useMemo(()=>{const m=new Map(e.workspaces.map(X=>[X.key,X])),R=[];for(const X of U){const ce=m.get(X);ce&&(R.push(ce),m.delete(X))}const N=[...m.values()].sort((X,ce)=>(X.kind==="channel"?-1:0)-(ce.kind==="channel"?-1:0));return[...R,...N]},[e.workspaces,U]),Be=C?ye.findIndex(m=>m.key===C):-1,Ie=u.useMemo(()=>{const m=ye.map(N=>({key:`ws:${N.key}`,ws:N,at:(ge.get(N.key)||[]).reduce((X,ce)=>Math.max(X,Qs(ce.updated_at)),0)}));if(e.orderBy!=="activity")return m;const R=(e.extraRows||[]).map(N=>({key:`row:${N.key}`,at:N.at,node:N.node}));return zd([...R,...m],e.pinnedEntries||{})},[ye,ge,e.orderBy,e.extraRows,e.pinnedEntries]),Ae=e.orderBy!=="activity",Le=m=>{const R=C;if(g(null),Y(null),!R||R===m)return;const N=ye.map(ne=>ne.key),X=N.indexOf(m);if(X<0||!N.includes(R))return;const ce=Uc(N,R,X);J(ce),Pd(ce)},Ee=m=>{L(R=>{const N=new Set(R);return N.has(m)?N.delete(m):N.add(m),qi(N),N})},Pe=m=>{L(R=>{if(!R.has(m))return R;const N=new Set(R);return N.delete(m),qi(N),N})},De=m=>{e.onEnterWorkspace?.(m),Pe(m)};u.useEffect(()=>{if(!P.current){P.current=!0;return}e.activeWorkspaceKey!=null&&Pe(e.activeWorkspaceKey)},[e.activeWorkspaceKey]),u.useEffect(()=>{f&&F.current?.select()},[f]),u.useEffect(()=>{Z&&q.current?.select()},[Z]),u.useEffect(()=>{if(!r&&!$)return;const m=()=>{l(null),W(null)};return window.addEventListener("click",m),window.addEventListener("contextmenu",m),()=>{window.removeEventListener("click",m),window.removeEventListener("contextmenu",m)}},[r,$]);const _e=(m,R)=>{m.preventDefault(),m.stopPropagation(),W(null);const N=c.batch(R.id);N.length===1&&c.only(R.id),l({id:R.id,ids:N,x:m.clientX,y:m.clientY,archived:!!R.archived})},Ue=(m,R)=>{m.preventDefault(),m.stopPropagation(),l(null),W({ws:R,x:m.clientX,y:m.clientY})},ct=()=>{f&&x.trim()&&e.onRename(f,x.trim()),k(null)},Tt=m=>{const R=[...o,...i].find(X=>X.id===m),N=()=>{A(R?.title||""),k(m)};{N();return}},b=m=>{const R=()=>{y(m.name),T(m.key)};{R();return}},V=m=>{const R=[],N=m.ids.length===1,X=N?[...o,...i].find(ne=>ne.id===m.id):void 0;N&&R.push({id:"open-new-tab",label:n("sidebar.openInNewTab"),icon:t.jsx(Bn,{size:13}),run:()=>{e.onSelect(m.id,{newTab:!0}),l(null)}}),N&&R.push({id:"set-icon",label:n("session.icon.set"),icon:t.jsx(uo,{size:13}),run:()=>{p({id:m.id,current:X?.emoji??null,x:m.x,y:m.y}),l(null)}}),N&&R.push({id:"rename",label:n("sidebar.rename"),icon:t.jsx(Vn,{size:13}),run:()=>{l(null),Tt(m.id)}}),N&&Rd()&&R.push({id:"to-note",label:n("chat.toNote.action"),icon:t.jsx(bl,{size:13}),run:()=>{Id(m.id),l(null)}}),R.push({id:m.archived?"unarchive":"archive",label:m.ids.length>1?n(m.archived?"sidebar.unarchiveN":"sidebar.archiveN",{n:String(m.ids.length)}):m.archived?n("sidebar.unarchive"):n("sidebar.archive"),icon:m.archived?t.jsx(gl,{size:13}):t.jsx(Ds,{size:13}),run:()=>{for(const ne of m.ids)e.onArchive(ne,!m.archived);c.clear(),l(null)}});const ce=X?.project_path?e.workspaces.find(ne=>ne.kind==="channel"&&ne.key===X.project_path):null;if(X&&ce?.channel){const ne=Ui[ce.channel];R.push({id:"channel-connect",label:n("sidebar.channel.setAsConnected"),icon:t.jsx(ne,{size:13}),run:()=>{l(null),Oc(it(),ce.channel,m.id).then(()=>e.onToast?.(n("sidebar.wechat.setConnectedOk"))).catch($e=>e.onToast?.(n("sidebar.wechat.setConnectedFail",{e:$e?.message||$e}),!0))}})}return m.ids.every(ne=>e.archivedSessions.some($e=>$e.id===ne))&&R.push({id:"delete",danger:!0,icon:t.jsx($s,{size:13}),label:m.ids.length>1?n("sidebar.deleteN",{n:String(m.ids.length)}):n("sidebar.delete"),run:()=>{const ne=m.ids;if(l(null),!!(ne.length>1?window.confirm(n("sidebar.deleteConfirmN",{n:String(ne.length)})):window.confirm(n("sidebar.deleteConfirm",{name:yt(X?.title,n)})))){for(const ut of ne)e.onDelete(ut);c.clear()}}}),R},H=m=>{const R=[];if(e.onTogglePinned){const N=`ws:${m.ws.key}`,X=Bi(e.pinnedEntries||{},N);R.push({id:X?"unpin":"pin",label:n(X?"sidebar.unpin":"sidebar.pin"),icon:X?t.jsx(Al,{size:13}):t.jsx(xs,{size:13}),run:()=>{W(null),e.onTogglePinned?.(N)}})}return e.onShowWorkspaceDetails&&ks(m.ws)&&[...o,...i].some(N=>N.project_path===m.ws.path&&!N.projectless)&&R.push({id:"ws-details",act:"ws-details",label:n("sidebar.ws.details"),icon:t.jsx(ml,{size:13}),run:()=>{const N=m.ws;W(null),e.onShowWorkspaceDetails?.(N)}}),m.ws.system||(R.push({id:"ws-rename",label:n("sidebar.ws.rename"),icon:t.jsx(Vn,{size:13}),run:()=>{const N=m.ws;W(null),b(N)}}),R.push({id:"ws-remove",act:"ws-remove",danger:!0,label:n("sidebar.ws.remove"),icon:t.jsx($s,{size:13}),run:()=>{Q(m.ws),W(null)}})),R},se=m=>{if(m.ids.length!==1)return;const R=[...o,...i].find(N=>N.id===m.id);return yt(R?.title,n)},Ne=_s(r,()=>r&&{title:se(r),sections:[{items:V(r)}]},()=>l(null)),qe=_s($,()=>$&&{title:Tn($.ws,n),sections:[{items:H($)}]},()=>W(null)),lt=()=>{if(Z&&ae.trim()){const m=e.workspaces.find(R=>R.key===Z);m&&e.onRenameWorkspace(m,ae.trim())}T(null)},He=(m,R)=>{const N=m.kind==="channel"?Ui[m.channel||"wechat"]:m.kind==="cloud"?Vt:m.kind==="rootless"?Ht:R?Kn:Bc;return t.jsxs("span",{className:"t2s-lead",children:[ks(m)?t.jsx(Cd,{path:m.path,className:"amx-page-emoji t2s-project-icon",fallback:t.jsx(N,{className:"t2s-lead-icon"})}):t.jsx(N,{className:"t2s-lead-icon"}),t.jsx("span",{className:`t2s-chev t2s-lead-chev${R?"":" open"}`,onClick:X=>{X.stopPropagation(),Ee(m.key)},children:t.jsx(Et,{size:12})})]})},Ve=m=>t.jsx(co,{as:"button",className:`${m.id===e.activeId?"active":""}${c.has(m.id)?" sel":""}`.trim()||void 0,selId:m.id,title:m.summary||m.title||void 0,depth:e.flat?0:1,lead:t.jsxs(t.Fragment,{children:[t.jsx(ra,{emoji:m.emoji,fallback:e.rowIcon?.(m)??t.jsx(Xn,{className:"t2s-lead-icon t2s-dim"})}),e.attentionIds?.get(m.id)?t.jsx(Io,{n:e.attentionIds.get(m.id).n,localOnly:e.attentionIds.get(m.id).localOnly}):e.runningIds.has(m.id)?t.jsx("span",{className:"t2s-dot running",title:n("sidebar.running")}):e.unreadIds.has(m.id)?t.jsx("span",{className:"t2s-dot unread",title:n("sidebar.unread")}):null]}),trailing:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"t2s-srow-time",children:Wc(m.updated_at)}),t.jsx("span",{className:"t2s-srow-menu",onClick:R=>_e(R,m),children:t.jsx(qn,{size:14})})]}),onClick:R=>{const N=c.click(m.id,R);if(N.open==="none")return;e.onSelect(m.id,N.open==="new"?{newTab:!0}:void 0);const X=e.sessionWorkspaceKeyOf?e.sessionWorkspaceKeyOf(m):oi(m,e.workspaces);X&&(e.onActivateEntry?.(`ws:${X}`),De(X))},onContextMenu:R=>_e(R,m),draggable:f!==m.id,onDragStart:R=>{const N=R.currentTarget.getBoundingClientRect();R.dataTransfer.setDragImage(R.currentTarget,R.clientX-N.left,R.clientY-N.top),R.dataTransfer.effectAllowed="copy";const X=[...o,...i],ce=c.batch(m.id).map(ne=>{const $e=X.find(ut=>ut.id===ne);return{kind:"session",id:ne,title:yt($e?.title,n)}});Fc(R.dataTransfer,ce)},children:f===m.id?t.jsx("input",{ref:F,className:"t2s-rename",value:x,onChange:R=>A(R.target.value),onBlur:ct,onKeyDown:R=>{R.key==="Enter"&&ct(),R.key==="Escape"&&k(null)},onClick:R=>R.stopPropagation()}):t.jsx("span",{className:"t2s-srow-title",children:yt(m.title,n)})},m.id);return t.jsxs("aside",{className:"t2s-side",ref:a,children:[t.jsxs("div",{className:"t2s-scroll",onDragOver:m=>{C&&(m.preventDefault(),m.dataTransfer.dropEffect="move")},onDrop:m=>{C&&O&&(m.preventDefault(),Le(O))},children:[e.showSpecial&&t.jsx("div",{className:"t2s-special-group",children:t.jsxs("div",{className:"t2s-special-row",children:[t.jsx(Dd,{icon:t.jsx(cl,{}),title:n("sidebar.newChat"),active:!1,onClick:e.onNewChat,act:"new-chat"}),e.mode&&e.onModeChange&&t.jsxs("div",{className:"t2s-vaultseg t2s-mode",role:"tablist","aria-label":n("sidebar.mode.tip"),title:n("sidebar.mode.tip"),children:[t.jsx("div",{className:"t2s-vaultseg-thumb","data-side":e.mode}),["chat","work"].map(m=>t.jsx("button",{type:"button",role:"tab","aria-selected":e.mode===m,"data-mode":m,className:e.mode===m?"on":void 0,onClick:()=>e.onModeChange(m),children:n(m==="chat"?"sidebar.mode.chat":"sidebar.mode.work")},m))]})]})}),Ie.map((m,R)=>{if(m.node)return t.jsx(mn.Fragment,{children:m.node},m.key);const N=m.ws,X=Bi(e.pinnedEntries||{},m.key),ce=ge.get(N.key)||[];if(e.flat)return t.jsx("div",{className:"t2s-group-sessions t2s-flat",children:ce.map(Ve)},N.key);const ne=_.has(N.key),$e={onDragOver:re=>{if(!C)return;re.preventDefault(),re.dataTransfer.dropEffect="move";const dt=C===N.key?null:N.key;O!==dt&&Y(dt)},onDrop:re=>{C&&(re.preventDefault(),re.stopPropagation(),Le(N.key))}},ut=!!C&&O===N.key&&C!==N.key,It=ut&&Be>=0&&Be<R,Jn=It?ne?" drag-over below":"":ut?" drag-over":"";return t.jsxs(mn.Fragment,{children:[t.jsxs("div",{className:`t2s-group${Jn}${C===N.key?" dragging":""}`,"data-workspace-key":N.key,"data-pinned":X?"true":void 0,"data-active":e.activeWorkspaceKey===N.key?"true":void 0,style:{paddingLeft:ro(0)},...oo(()=>[N.path||"",ll("tip.sessions",{count:ce.length})].filter(Boolean)),draggable:Ae&&Z!==N.key,onContextMenu:re=>Ue(re,N),onDragStart:re=>{const dt=re.currentTarget.getBoundingClientRect();re.dataTransfer.setDragImage(re.currentTarget,re.clientX-dt.left,re.clientY-dt.top),re.dataTransfer.effectAllowed="move",g(N.key)},...$e,onDragEnd:()=>{g(null),Y(null)},children:[Z===N.key?t.jsxs("div",{className:"t2s-group-toggle t2s-folder-row",style:{cursor:"default"},children:[He(N,ne),t.jsx("input",{ref:q,className:"t2s-rename",value:ae,onChange:re=>y(re.target.value),onBlur:lt,onKeyDown:re=>{re.key==="Enter"&<(),re.key==="Escape"&&T(null)},onClick:re=>re.stopPropagation()})]}):N.kind==="channel"?t.jsxs("button",{className:"t2s-group-toggle t2s-folder-row",onClick:()=>{e.onActivateEntry?.(m.key),ne?De(N.key):Ee(N.key)},children:[He(N,ne),t.jsx("span",{className:"t2s-group-label",children:Tn(N,n)}),X&&t.jsx(xs,{className:"t2o-pin-mark","aria-hidden":"true"}),t.jsx("span",{className:`t2s-mini-dot${Se.get(N.channel||"wechat")?" ok":""}`})]}):t.jsxs("button",{className:"t2s-group-toggle t2s-folder-row",onClick:()=>{e.onActivateEntry?.(m.key),ne?De(N.key):Ee(N.key)},children:[He(N,ne),t.jsx("span",{className:"t2s-group-label",children:Tn(N,n)}),X&&t.jsx(xs,{className:"t2o-pin-mark","aria-hidden":"true"})]}),(!N.system||e.onTogglePinned||e.onShowWorkspaceDetails&&ks(N))&&t.jsx("button",{type:"button",className:"t2s-group-add",title:n("sidebar.ws.menu"),onClick:re=>Ue(re,N),children:t.jsx(qn,{size:14})}),t.jsx("button",{type:"button",className:"t2s-group-add",title:n("sidebar.newChatIn",{name:Tn(N,n)}),onClick:()=>e.onNewInWorkspace(N),children:t.jsx(Bn,{size:14})})]}),t.jsx(Ao,{open:!ne,children:t.jsxs("div",{className:`t2s-group-sessions${It&&!ne?" drag-over-end":""}`,...$e,children:[ce.slice(0,E).map(Ve),ce.length>E&&t.jsxs("button",{className:"t2s-viewmore",onClick:()=>e.onOpenWorkspace(N.key),children:[n("sidebar.viewMore")," · ",ce.length-E]})]})})]},N.key)}),e.deviceSections]}),(window.tangu?.pickDirectory&&!e.flat||e.archivedSessions.length>0)&&t.jsxs("div",{className:"t2s-foot",children:[window.tangu?.pickDirectory&&!e.flat&&t.jsxs("button",{className:"t2s-add-ws",onClick:e.onAddWorkspace,children:[t.jsx(lo,{size:14})," ",n("sidebar.addLocalWorkspace")]}),e.archivedSessions.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{className:"t2s-srow t2s-archived-toggle",onClick:()=>B(!z),children:[t.jsx("span",{className:"t2s-chev",children:t.jsx(Ds,{size:13})}),t.jsx("span",{className:"t2s-srow-title t2s-faint",children:n("sidebar.archived")}),t.jsx("span",{className:"t2s-count",children:e.archivedSessions.length})]}),z&&e.archivedSessions.map(Ve)]})]}),r&&Ne&&t.jsx(Ls,{className:"ctx-menu",x:r.x,y:r.y,onClick:m=>m.stopPropagation(),children:t.jsx(Js,{items:V(r)})}),h&&t.jsx(Mo,{sessionId:h.id,current:h.current,x:h.x,y:h.y,onClose:()=>p(null)}),$&&qe&&t.jsx(Ls,{className:"ctx-menu",x:$.x,y:$.y,onClick:m=>m.stopPropagation(),children:t.jsx(Js,{items:H($)})}),K&&t.jsx(Eo,{title:n("sidebar.ws.removeTitle",{name:K.name}),message:n("sidebar.ws.removeMsg",{count:[...o,...i].filter(m=>m.project_path===K.key).length}),confirmLabel:n("sidebar.ws.removeAction"),filesLabel:K.kind==="local"&&window.tangu?.trashHostPath?n("sidebar.ws.removeFiles"):void 0,onConfirm:m=>e.onRemoveWorkspace(K,{deleteFiles:m}),onClose:()=>Q(null)})]})};xe({"devstatus.checking":{zh:"正在连接…",en:"Connecting…"},"devstatus.ready":{zh:"在线",en:"Online"},"devstatus.starting":{zh:"引擎正在启动",en:"Engine is starting"},"devstatus.engineStopped":{zh:"引擎没有运行",en:"Engine isn't running"},"devstatus.noEngine":{zh:"没有 Agent 引擎",en:"No agent engine"},"devstatus.offline":{zh:"离线",en:"Offline"},"devstatus.unreachable":{zh:"暂时连不上",en:"Can't reach it"},"devstatus.remoteOff":{zh:"未开启远程会话",en:"Remote sessions off"},"devstatus.awaitingConfirm":{zh:"等待那台电脑允许",en:"Waiting for approval there"},"devstatus.denied":{zh:"拒绝了这台手机",en:"Declined this phone"},"devstatus.callerBlocked":{zh:"不允许这台手机运行",en:"Doesn't allow this phone"},"devstatus.long.checking":{zh:"正在连接这台电脑…",en:"Connecting to this computer…"},"devstatus.long.ready":{zh:"在线,可以在上面运行会话",en:"Online. Sessions can run here"},"devstatus.long.starting":{zh:"这台电脑在线,Agent 引擎正在启动",en:"This computer is online and its agent engine is starting"},"devstatus.long.engineStopped":{zh:"Forsion 已打开,但 Agent 引擎没有运行",en:"Forsion is open, but its agent engine isn't running"},"devstatus.long.noEngine":{zh:"这台设备上的 Forsion 没有 Agent 引擎",en:"Forsion on this device has no agent engine"},"devstatus.long.offline":{zh:"离线,重新上线后这里会显示它的会话",en:"Offline. Its sessions show up here when it's back"},"devstatus.long.unreachable":{zh:"暂时连不上,稍后重试",en:"Can't reach it right now. Try again shortly"},"devstatus.long.remoteOff":{zh:"这台电脑没有开启「允许远程会话」",en:"Remote sessions are turned off on this computer"},"devstatus.long.awaitingConfirm":{zh:"请在那台电脑上允许这台手机",en:"Allow this phone on that computer to continue"},"devstatus.long.denied":{zh:"那台电脑拒绝了这台手机",en:"That computer declined this phone"},"devstatus.long.callerBlocked":{zh:"那台电脑不允许这台手机运行会话,请在它的「设置 › 远程会话」中调整",en:"That computer doesn't let this phone run sessions. Change it in Settings › Remote sessions there"},"sidebar.device.label":{zh:"{name} 上的会话",en:"Sessions on {name}"},"sidebar.device.empty":{zh:"还没有会话",en:"No sessions yet"},"sidebar.device.pickFirst":{zh:"在「在哪运行」里选过这台电脑后,这里会显示它的会话",en:"Pick this computer under Run on to see its sessions here"},"sidebar.device.menu":{zh:"更多操作",en:"More actions"}});function pn(e,n){const a=typeof e=="string"?e.trim():"";return a.length>n?`${a.slice(0,n-1)}…`:a}const Do="forsion_device_sections_collapsed";function _d(){try{const e=JSON.parse(localStorage.getItem(Do)||"[]");return new Set(Array.isArray(e)?e.filter(n=>typeof n=="string").slice(0,200):[])}catch{return new Set}}function Od(e){try{localStorage.setItem(Do,JSON.stringify([...e]))}catch{}}function Fd({u:e}){return e.icon?t.jsx("span",{className:"t2d-emoji","aria-hidden":!0,children:pn(e.icon,4)}):e.platform==="win32"||e.platform==="linux"?t.jsx(ao,{className:"t2s-lead-icon"}):t.jsx(io,{className:"t2s-lead-icon"})}function $h(e,n){const a=e?.get(n);return a?t.jsx(Io,{n:a.n,localOnly:a.localOnly}):null}function _o(){const e=D(n=>n.connState);u.useEffect(()=>{if(!Rt())return;const n=()=>{le.getState().refresh()},a=()=>{le.getState().refresh({periodic:!0})};n();let o=null;const i=()=>{o&&(clearInterval(o),o=null),(typeof document>"u"||document.visibilityState==="visible")&&(o=setInterval(a,3e4))},c=()=>{document.visibilityState==="visible"&&n(),i()};return i(),document.addEventListener("visibilitychange",c),()=>{document.removeEventListener("visibilitychange",c),o&&clearInterval(o)}},[]),u.useEffect(()=>{e==="ok"&&Rt()&&le.getState().refresh()},[e])}function Lh(e){const{t:n}=Ce();_o();const a=le(C=>C.units),o=le(C=>C.byUnit);Xt(C=>C.probes),Xt(C=>C.sticky);const i=D(C=>C.sessions),c=le(C=>C.selfRegistered),[r,l]=u.useState(_d),[h,p]=u.useState(null),[f,k]=u.useState(null),[x,A]=u.useState(null),[E,M]=u.useState(""),z=u.useRef(null);u.useEffect(()=>{x&&z.current?.select()},[x]),u.useEffect(()=>{if(!h)return;const C=()=>p(null),g=O=>{O.key==="Escape"&&p(null)};return window.addEventListener("click",C),window.addEventListener("contextmenu",C),window.addEventListener("keydown",g),()=>{window.removeEventListener("click",C),window.removeEventListener("contextmenu",C),window.removeEventListener("keydown",g)}},[h]);const B=u.useMemo(()=>{const C={};for(const g of a||[]){const O=g.id.toLowerCase();if(!g.online){C[O]=[];continue}const Y=o[O]?.sessions??[],F=new Set(Y.map(W=>W.id)),$=[...i.filter(W=>W.location?.kind==="unit"&&W.location.unitId===O&&!F.has(W.id)&&!W.archived),...Y].sort((W,K)=>Qs(K.updated_at)-Qs(W.updated_at));C[O]=e.filter?e.filter($):$}return C},[a,o,i,e.filter]),_=C=>{const g=B[C.unitId]?.find(O=>O.id===C.id);return[{id:"set-icon",label:n("session.icon.set"),icon:t.jsx(uo,{size:13}),run:()=>{k({...C,current:g?.emoji??null}),p(null)}},{id:"rename",label:n("sidebar.rename"),icon:t.jsx(Vn,{size:13}),run:()=>{p(null);const O=()=>{M(g?.title||""),A({unitId:C.unitId,id:C.id})};{O();return}}},{id:"archive",label:n("sidebar.archive"),icon:t.jsx(Ds,{size:13}),run:()=>{p(null),bd(C.unitId,C.id)}}]},L=_s(h,()=>h&&{title:yt(pn(B[h.unitId]?.find(C=>C.id===h.id)?.title,200),n),sections:[{items:_(h)}]},()=>p(null));if(!Rt()||!a?.length)return null;const U=C=>{l(g=>{const O=new Set(g);return O.has(C)?O.delete(C):O.add(C),Od(O),O})},J=()=>{x&&E.trim()&&xd(x.unitId,x.id,E.trim()),A(null)};return t.jsxs("div",{className:"t2d-sections","data-device-sections":!0,children:[a.map(C=>{const g=C.id.toLowerCase(),O=oa(C).status,Y=B[g]??[],F=r.has(g),P=pn(C.name,60)||n("engine.target.defaultName");return t.jsxs("div",{className:"t2d-section","data-device-section":g,"data-device-status":O,children:[t.jsx("div",{className:"t2s-group t2d-head",style:{paddingLeft:ro(0)},title:n(`devstatus.long.${O}`),children:t.jsxs("button",{type:"button",className:"t2s-group-toggle t2s-folder-row t2d-toggle","aria-expanded":!F,"aria-label":n("sidebar.device.label",{name:P}),onClick:()=>U(g),children:[t.jsxs("span",{className:"t2s-lead",children:[t.jsx(Fd,{u:C}),t.jsx("span",{className:`t2s-chev t2s-lead-chev${F?"":" open"}`,children:t.jsx(Et,{size:12})})]}),t.jsx("span",{className:"t2s-group-label t2d-name",children:P}),t.jsx("span",{className:"t2d-status","data-tone":O==="ready"?"ok":O==="checking"?"wait":"warn",role:"status",children:n(`devstatus.${O}`)})]})}),t.jsx(Ao,{open:!F,children:t.jsxs("div",{className:"t2s-group-sessions",children:[Y.map($=>t.jsx(co,{as:x?.id===$.id?"div":"button",className:$.id===e.activeId?"active":void 0,depth:1,title:$.summary||$.title||void 0,lead:t.jsxs(t.Fragment,{children:[t.jsx(ra,{emoji:$.emoji,fallback:t.jsx(Xn,{className:"t2s-lead-icon t2s-dim"})}),e.rowBadge?.($)??(e.runningIds.has($.id)?t.jsx("span",{className:"t2s-dot running"}):e.unreadIds.has($.id)?t.jsx("span",{className:"t2s-dot unread"}):null)]}),trailing:x?.id===$.id?void 0:t.jsx("span",{className:"t2s-srow-menu",role:"button","aria-label":n("sidebar.device.menu"),onClick:W=>{W.stopPropagation(),p({unitId:g,id:$.id,x:W.clientX,y:W.clientY})},children:t.jsx(qn,{size:14})}),onClick:()=>{x?.id!==$.id&&Xs($,{unitId:g})},onContextMenu:W=>{W.preventDefault(),W.stopPropagation(),p({unitId:g,id:$.id,x:W.clientX,y:W.clientY})},children:x?.id===$.id?t.jsx("input",{ref:z,className:"t2s-rename",value:E,onChange:W=>M(W.target.value),onBlur:J,onKeyDown:W=>{W.key==="Enter"&&J(),W.key==="Escape"&&A(null)},onClick:W=>W.stopPropagation()}):t.jsx("span",{className:"t2s-srow-title","data-remote-session":$.id,children:yt(pn($.title,200),n)})},$.id)),O==="ready"&&!Y.length&&t.jsx("div",{className:"t2d-empty",children:n(c===!1?"sidebar.device.pickFirst":"sidebar.device.empty")})]})})]},g)}),h&&L&&t.jsx(Ls,{className:"ctx-menu",x:h.x,y:h.y,onClick:C=>C.stopPropagation(),children:t.jsx(Js,{items:_(h)})}),f&&t.jsx(Mo,{sessionId:f.id,current:f.current,x:f.x,y:f.y,onSave:C=>wd(f.unitId,f.id,C),onClose:()=>k(null)})]})}xe({"runloc.label":{zh:"运行位置",en:"Run on"},"runloc.cloud":{zh:"云端",en:"Cloud"},"runloc.thisDevice":{zh:"这台电脑",en:"This computer"},"runloc.pillTitle":{zh:"新会话在哪运行:{where}",en:"New sessions run on: {where}"}});function Wd(){const e=le(n=>n.units);return Rt()&&!!e?.length}function Ph(){const{t:e}=Ce();_o();const n=Wd(),a=mi(h=>h.ref);mi(h=>h.name),le(h=>h.units),Xt(h=>h.probes),Xt(h=>h.sticky);const o=Xe(h=>h.chooser);if(!n)return null;const i=a.kind==="unit"?So(a.unitId):null,c=i?oa(i).status:null,r=a.kind==="unit"?pn(qc(a)||i?.name,60)||e("engine.target.defaultName"):e("runloc.cloud"),l=a.kind==="home"?Vt:i?.platform==="win32"||i?.platform==="linux"?ao:io;return t.jsx("div",{className:"project-selector runloc","data-run-location-picker":!0,"data-run-location":jo(a)||"home","data-device-status":c??void 0,children:t.jsxs("button",{type:"button",className:"composer-chip project-pill runloc-pill",title:e("runloc.pillTitle",{where:r}),"aria-label":e("runloc.pillTitle",{where:r}),"aria-haspopup":"dialog",disabled:!o,onClick:()=>o?.(),children:[t.jsx(l,{size:13}),t.jsx("span",{className:"project-pill-name",children:r}),c&&c!=="ready"&&t.jsx("span",{className:"runloc-status","data-tone":c==="checking"?"wait":"warn",children:e(`devstatus.${c}`)}),o&&t.jsx(yn,{size:12})]})})}export{bh as $,Ds as A,dh as B,wh as C,Lh as D,ki as E,vh as F,tu as G,Gl as H,yo as I,ch as J,gh as K,Xl as L,hh as M,bl as N,vo as O,Cd as P,ph as Q,Kl as R,Ih as S,mh as T,ho as U,fh as V,Ci as W,rh as X,oh as Y,Eu as Z,Sh as _,Tn as a,Ph as a0,jh as a1,Ao as a2,du as a3,xh as a4,bu as a5,Rl as a6,yh as a7,hu as a8,kh as a9,Ye as aa,Wd as ab,gl as b,yt as c,cd as d,Mo as e,ra as f,ed as g,td as h,Nh as i,Mh as j,zh as k,$h as l,Qs as m,Bi as n,_s as o,Js as p,Al as q,Rh as r,Ch as s,Th as t,Dl as u,Ah as v,Ol as w,Eh as x,lh as y,uh as z};
|