pisper 0.6.3 → 0.6.4
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.en.md +0 -6
- package/README.md +0 -6
- package/bin/pisper.mjs +7 -15
- package/lib/install.mjs +9 -49
- package/lib/npm-platform.mjs +0 -12
- package/package.json +8 -9
- package/web/.vite/manifest.json +713 -737
- package/web/assets/AppDialog-BOGrPFbo.js +1 -0
- package/web/assets/{AppOverlays-CR5iJcP5.js → AppOverlays-D1vfPPIC.js} +1 -1
- package/web/assets/AppSelect-BCexz4Ty.js +1 -0
- package/web/assets/{AppShortcuts-BachmLQ3.js → AppShortcuts-Dd4gu7qz.js} +1 -1
- package/web/assets/{AssetsPage-BltehMID.js → AssetsPage-BPhPo5eU.js} +1 -1
- package/web/assets/ChannelsPage-Cu4v-GU2.js +1 -0
- package/web/assets/ChatAppearancePage-BLRQ7aH6.js +2 -0
- package/web/assets/ChatHistoryPage-BYqJFbY5.js +1 -0
- package/web/assets/ChatPage-tqAIj2Go.js +554 -0
- package/web/assets/ConfigPage-Z-BQwP2X.js +1 -0
- package/web/assets/{DecisionsPage-DOhLbIaD.js → DecisionsPage-Db6MIGD2.js} +1 -1
- package/web/assets/{DesktopWindowControls-KmgemDO8.js → DesktopWindowControls-CBYGv94u.js} +1 -1
- package/web/assets/{FloatingWidgets-Bs7ec6lW.js → FloatingWidgets-dzsQIxAO.js} +1 -1
- package/web/assets/{GitDiffViewer-xm2LnN9r.js → GitDiffViewer-m5aLB7Li.js} +1 -1
- package/web/assets/MarkdownMessage-CA9ODRKk.js +2 -0
- package/web/assets/McpPage-rerFxjYZ.js +1 -0
- package/web/assets/MemoryPage-cukfU824.js +1 -0
- package/web/assets/MobileContextScreen-W8V4H3Xv.js +2 -0
- package/web/assets/MobileNavigation-CEVgs1Ke.js +1 -0
- package/web/assets/MobileShellContext-D8qX-BlM.js +1 -0
- package/web/assets/{PageHeader-C_bfu8Ir.js → PageHeader-DIs9bESb.js} +1 -1
- package/web/assets/{PluginsPage-BPx5ERHL.js → PluginsPage-09Um3mY4.js} +1 -1
- package/web/assets/QueryClientProvider-CHJtxoX1.js +1 -0
- package/web/assets/{QuickPromptIdeas-Bs-udcSZ.js → QuickPromptIdeas-DGIL0nN7.js} +1 -1
- package/web/assets/SchedulesPage-C75QUeB5.js +1 -0
- package/web/assets/SessionContextPanel-oaKXyi7k.js +1 -0
- package/web/assets/{SessionFilesPane-BIRQ_hHi.js → SessionFilesPane-DPijesqH.js} +2 -2
- package/web/assets/{SidebarMoreTools-BDqt5VTG.js → SidebarMoreTools-D1nDS3i0.js} +1 -1
- package/web/assets/SidebarRecentSessions-a7z2ZvDv.js +2 -0
- package/web/assets/{SidebarSettingsButton-B4_vEBS5.js → SidebarSettingsButton-CRdV0Vft.js} +1 -1
- package/web/assets/{SidebarUpdateStatus-DD8f4Fxv.js → SidebarUpdateStatus-DgNJBwgT.js} +1 -1
- package/web/assets/SkillsPage-DLirgTyX.js +1 -0
- package/web/assets/TerminalPanel-CJPy4Qhs.js +18 -0
- package/web/assets/{ThemeToggleButton-CXXbLtcY.js → ThemeToggleButton-C5QA5Kf2.js} +1 -1
- package/web/assets/{WebDesktopPet-DWFspeZE.js → WebDesktopPet-DgyHLE9y.js} +1 -1
- package/web/assets/{WorkbenchSidebarToggle-AgjfcT29.js → WorkbenchSidebarToggle-CcO1Al5A.js} +1 -1
- package/web/assets/WorkflowsPage-DrKHzJvb.js +1 -0
- package/web/assets/WorkspacePicker-B3liZkwe.js +1 -0
- package/web/assets/{api-Dzobr-o_.js → api-YI8_cHpR.js} +1 -1
- package/web/assets/{app-primitives-BBXY6U2S.js → app-primitives-SxfoFmHc.js} +1 -1
- package/web/assets/app-update-Bg6w1SOW.js +32 -0
- package/web/assets/arrow-up-DST6-qVQ.js +1 -0
- package/web/assets/catalog-BPCnu3F8.js +1 -0
- package/web/assets/channels-messages-DgWnmzUo.js +1 -0
- package/web/assets/chat-api-CqF-FICX.js +1 -0
- package/web/assets/{client-store-DPMvgPNS.js → client-store-BP_3-plw.js} +1 -1
- package/web/assets/{component-api-Nwo2yGZI.js → component-api-CN9Tcn5p.js} +1 -1
- package/web/assets/config-search-DOIJENN1.js +1 -0
- package/web/assets/dist-B7rNRXig.js +1 -0
- package/web/assets/dist-C3P9WH0T.js +1 -0
- package/web/assets/dist-CXiO_DNx.js +1 -0
- package/web/assets/dist-D8Wfxh48.js +1 -0
- package/web/assets/{dropdown-menu-DmL4pJTo.js → dropdown-menu-pKRdLJUe.js} +1 -1
- package/web/assets/{events-Bwv6HmwM.js → events-KqdUtjsm.js} +1 -1
- package/web/assets/{floating-widgets-store-DIy4GSy4.js → floating-widgets-store-Pjm1AdvO.js} +2 -2
- package/web/assets/folder-DPM8D8cf.js +1 -0
- package/web/assets/house-BNrzTkx9.js +1 -0
- package/web/assets/{http-DphgzWtw.js → http-Be2GB6DH.js} +1 -1
- package/web/assets/i18n-8nTnthu6.js +1 -0
- package/web/assets/{index-iBrSU61i.js → index-AF29hfx9.js} +2 -2
- package/web/assets/index-BAmsg90v.css +2 -0
- package/web/assets/monitor-ORxecA9m.js +1 -0
- package/web/assets/mount-app-WW5hteuX.js +9 -0
- package/web/assets/panels-top-left-BlZftvhg.js +1 -0
- package/web/assets/pick-system-directory-BnIFt85A.js +1 -0
- package/web/assets/{popover-BBuzaBfd.js → popover-CQqAaq-c.js} +1 -1
- package/web/assets/public-c36e4881.js +1 -0
- package/web/assets/public-components-C4ndcOCF.js +1 -0
- package/web/assets/{runtime-capabilities-store-DaWPY5y-.js → runtime-capabilities-store-CiL3ZPEo.js} +1 -1
- package/web/assets/scale-D0LcHVmf.js +1 -0
- package/web/assets/{session-change-summary-api-DFgTzTci.js → session-change-summary-api--7cl4LDn.js} +1 -1
- package/web/assets/session-context-store-DJnHgWwb.js +1 -0
- package/web/assets/session-list-DkNhT87s.js +1 -0
- package/web/assets/settings-navigation-CI7Yt4Or.js +1 -0
- package/web/assets/{shortcuts-BO-h6OmP.js → shortcuts-C_Cph88H.js} +1 -1
- package/web/assets/side-chat-context-Dn8w9ut8.js +3 -0
- package/web/assets/{sidebar-CfWEKOIK.js → sidebar-C3YJQV72.js} +1 -1
- package/web/assets/{speech-session-DKjw0mV_.js → speech-session-CoUr4n9Q.js} +1 -1
- package/web/assets/{startup-queries-CAQZvUIR.js → startup-queries-ByepQfGF.js} +1 -1
- package/web/assets/tabs-B60r4YwO.js +1 -0
- package/web/assets/{ui-store-2wpnH8Kf.js → ui-store-BGs-dEVz.js} +1 -1
- package/web/assets/{use-i18n-BSZKFkMb.js → use-i18n-a84Zp9dV.js} +1 -1
- package/web/assets/{useCustomUiComponents-BH86kuaq.js → useCustomUiComponents-BaQ_fwbr.js} +1 -1
- package/web/assets/useQuery-D3P5wO_Z.js +1 -0
- package/web/assets/web-preview-B7L-G6kp.js +1 -0
- package/web/assets/web-preview-events-C4AW4-It.js +1 -0
- package/web/index.html +2 -2
- package/web/assets/AppSelect-D149YYg1.js +0 -1
- package/web/assets/ChannelsPage-Tuw_qicj.js +0 -1
- package/web/assets/ChatAppearancePage-DME3PgDr.js +0 -2
- package/web/assets/ChatDockView-DoGtrBpY.js +0 -2
- package/web/assets/ChatHistoryPage-DTXS6i3n.js +0 -1
- package/web/assets/ChatPage-ibc_7olm.js +0 -4
- package/web/assets/ConfigPage-CI6one5Y.js +0 -1
- package/web/assets/MarkdownMessage-H1336cMr.js +0 -2
- package/web/assets/McpPage-Ck-7aLuZ.js +0 -1
- package/web/assets/MemoryPage-BEdNJ3ot.js +0 -1
- package/web/assets/MobileContextScreen-Dasny2J9.js +0 -2
- package/web/assets/MobileThreePane-DEKMHPfN.js +0 -1
- package/web/assets/SchedulesPage-W4Mg7frl.js +0 -1
- package/web/assets/SessionContextPanel-lu9F9AJg.js +0 -1
- package/web/assets/SidebarRecentSessions-1G_huYu9.js +0 -1
- package/web/assets/SkillsPage-CpRRosmo.js +0 -1
- package/web/assets/TerminalPanel-DVKC4htc.js +0 -18
- package/web/assets/Threads-B8ij_QtI.js +0 -1
- package/web/assets/WorkflowsPage-bhQlHSzS.js +0 -1
- package/web/assets/app-update-DppJNspd.js +0 -32
- package/web/assets/arrow-right-DqLOhpA2.js +0 -1
- package/web/assets/catalog-D4eaIju4.js +0 -1
- package/web/assets/channels-messages-CeRKS_DE.js +0 -1
- package/web/assets/chat-api-DfnvubiW.js +0 -1
- package/web/assets/chevron-left-BAtyp3_6.js +0 -1
- package/web/assets/config-search-CwVhh2uc.js +0 -1
- package/web/assets/dist-DAs5KRGl.js +0 -1
- package/web/assets/dist-swnK7PHk.js +0 -1
- package/web/assets/i18n-7QvbQzOQ.js +0 -1
- package/web/assets/index-CdASiNlI.css +0 -2
- package/web/assets/local-path-reveal-DWhkyox-.js +0 -1
- package/web/assets/mobile-shell-layout-CMpTmYRX.js +0 -1
- package/web/assets/mount-app-n_05p6iW.js +0 -9
- package/web/assets/panel-left-C_lYsiIA.js +0 -1
- package/web/assets/panel-right-BSUtqUd8.js +0 -1
- package/web/assets/pick-system-directory-R1F5WyaB.js +0 -1
- package/web/assets/pin-Dc2zE4cS.js +0 -1
- package/web/assets/public-BcTP7F3I.js +0 -1
- package/web/assets/public-components-Ck5BYo6M.js +0 -1
- package/web/assets/session-list-CMaoK_ZX.js +0 -1
- package/web/assets/session-streaming-state-llCTupbI.js +0 -3
- package/web/assets/side-chat-context-Dr2QLUJA.js +0 -1
- package/web/assets/tabs-DQYVDdOp.js +0 -1
- package/web/assets/use-animation-visibility-_Xe7jeUy.js +0 -1
- package/web/assets/useQuery-DdcpUQhO.js +0 -1
- package/web/assets/vendor-dockview-Bf3Gg83W.js +0 -1
- package/web/assets/vendor-dockview-D5adAaCg.css +0 -1
- package/web/assets/web-preview-BPNd1LUd.js +0 -1
- package/web/assets/web-preview-CQbpHjt1.js +0 -1
- package/web/assets/web-preview-events-o845ErdA.js +0 -1
- package/web/assets/web-preview-panel-DVQxVfig.js +0 -552
- package/web/assets/workflow-Bg94dy8I.js +0 -1
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/speech-text-Cpe8K6uv.js","assets/vendor-markdown-Ck4Y_w0n.js","assets/rolldown-runtime-B0Z9INg1.js","assets/vendor-router-CZg2bCPV.js","assets/vendor-react-DwNgTV1j.js","assets/vendor-markdown-plugins-DisoihU3.js","assets/vendor-shiki-runtime-UFMr0O-Q.js","assets/vendor-markdown-plugins-DEcVZfaU.css","assets/vendor-ui-DvrYggeS.js","assets/speech-stream-text-Bh_0kguU.js","assets/abort-signal-f4JsiYKX.js","assets/speech-session-CoUr4n9Q.js","assets/api-YI8_cHpR.js","assets/http-Be2GB6DH.js","assets/i18n-8nTnthu6.js","assets/index-AF29hfx9.js","assets/index-BAmsg90v.css","assets/storage-BpAqa-YY.js","assets/ShinyText-DqxsUc3F.js","assets/utils-C8uzG5AZ.js","assets/react-bits-DQli9s7O.css","assets/QuickPromptIdeas-DGIL0nN7.js","assets/use-i18n-a84Zp9dV.js","assets/vendor-state-GkUciC5H.js","assets/createLucideIcon-Cd-3GVxJ.js","assets/code-xml-BrUXrBax.js","assets/file-text-N9JICX6E.js","assets/flask-conical-DhW5v7Zz.js","assets/list-checks-B5Jl4aiO.js","assets/wand-sparkles-DdQneChm.js","assets/mobile-remote-fallback-JlHu_hz6.js","assets/SessionContextPanel-oaKXyi7k.js","assets/collapsible-C__hRcbA.js","assets/dist-Cfh4kzCK.js","assets/dist-B_a0oV4U.js","assets/dropdown-menu-pKRdLJUe.js","assets/dist-CXiO_DNx.js","assets/dist-B7rNRXig.js","assets/dist-C3P9WH0T.js","assets/es2015-0QT3KgdC.js","assets/dist-alOyD2Bh.js","assets/dist-TksYpDID.js","assets/tooltip-Bxq7c2mZ.js","assets/dist-BlIIpW6W.js","assets/arrow-up-DST6-qVQ.js","assets/earth-Ddy13fHh.js","assets/external-link-CEQqPcqc.js","assets/side-chat-context-Dn8w9ut8.js","assets/popover-CQqAaq-c.js","assets/tabs-B60r4YwO.js","assets/check-2vYc6QaP.js","assets/chevron-down-CxtxIjiP.js","assets/chevron-right-C3t2Rckj.js","assets/circle-dot-nVrXgDaG.js","assets/clock-3-CBHGbD_G.js","assets/download-BCfIiuaL.js","assets/shield-alert-CvFOTe9h.js","assets/file-diff-GxOMJkLj.js","assets/file-Bllajneu.js","assets/folder-open-FIShC5Qk.js","assets/info-DATxy0fb.js","assets/loader-circle-BOwQzHB-.js","assets/monitor-ORxecA9m.js","assets/refresh-cw-TbWxTY4K.js","assets/rotate-ccw-C0v8V77_.js","assets/shield-check-Gvek4RJ7.js","assets/square-bHHVTT3G.js","assets/tag-CqkeJlBf.js","assets/trash-2-CNrPOoPR.js","assets/triangle-alert-CE1q54ci.js","assets/undo-2-CJE_nRTk.js","assets/x-07u4-129.js","assets/button-CQA36izu.js","assets/chat-api-CqF-FICX.js","assets/startup-queries-ByepQfGF.js","assets/query-Bj-DUNYq.js","assets/mutation-CEbxdVYy.js","assets/alert-QoPGoIY6.js","assets/dialog-D-ER2p-D.js","assets/dist-BdkTa5R3.js","assets/input-CvjGYteF.js","assets/format-BRFKAYMT.js","assets/card-BdUpL1KB.js","assets/events-KqdUtjsm.js","assets/vendor-motion-DSW3wzXK.js","assets/MarkdownMessage-CA9ODRKk.js","assets/copy-DHmIFc52.js","assets/route-context-DvWDul4T.js","assets/web-preview-B7L-G6kp.js","assets/GitDiffViewer-m5aLB7Li.js","assets/message-square-SKjZyY3v.js","assets/plus-fQbSqB1n.js","assets/SessionFilesPane-DPijesqH.js","assets/session-change-summary-api--7cl4LDn.js","assets/shortcuts-C_Cph88H.js","assets/sheet--Om3LZxh.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{p as t}from"./vendor-router-CZg2bCPV.js";import{t as n}from"./index-AF29hfx9.js";import{i as r,n as i,r as a}from"./vendor-react-DwNgTV1j.js";import{l as o,u as s}from"./i18n-8nTnthu6.js";import{t as c}from"./use-i18n-a84Zp9dV.js";import{a as l,i as u,o as d}from"./vendor-state-GkUciC5H.js";import{t as f}from"./storage-BpAqa-YY.js";import{i as p}from"./dist-Cfh4kzCK.js";import{c as m,i as h,o as g,r as _,s as v}from"./dist-B_a0oV4U.js";import{t as y}from"./collapsible-C__hRcbA.js";import{t as b}from"./dist-TksYpDID.js";import{t as x}from"./AppSelect-BCexz4Ty.js";import{a as S,i as C,n as w,o as T,t as E}from"./popover-CQqAaq-c.js";import{i as D,n as O,r as k,t as A}from"./progress-C_G6VqQ_.js";import{i as j,r as M,t as N}from"./tabs-B60r4YwO.js";import{i as P,n as F,t as I}from"./tooltip-Bxq7c2mZ.js";import{t as L}from"./utils-C8uzG5AZ.js";import{t as R}from"./createLucideIcon-Cd-3GVxJ.js";import{d as z,i as B,l as ee,n as V,o as te,r as ne,s as re,t as ie,u as H}from"./session-list-DkNhT87s.js";import{t as ae}from"./arrow-up-DST6-qVQ.js";import{t as oe}from"./bot-B3TaBp_T.js";import{t as se}from"./check-2vYc6QaP.js";import{t as ce}from"./chevron-down-CxtxIjiP.js";import{t as le}from"./chevron-right-C3t2Rckj.js";import{t as ue}from"./circle-check-iEdCm3Pw.js";import{t as de}from"./circle-x-Ba4QL7Ec.js";import{t as fe}from"./ThemeToggleButton-C5QA5Kf2.js";import{t as U}from"./download-BCfIiuaL.js";import{t as pe}from"./shield-alert-CvFOTe9h.js";import{t as me}from"./file-text-N9JICX6E.js";import{t as he}from"./file-Bllajneu.js";import{t as W}from"./folder-open-FIShC5Qk.js";import{t as ge}from"./folder-DPM8D8cf.js";import{C as _e,D as ve,E as ye,O as be,S as xe,T as Se,_ as Ce,a as we,b as Te,c as Ee,d as De,f as Oe,g as ke,h as Ae,i as je,k as Me,l as G,m as Ne,n as Pe,o as Fe,p as Ie,s as K,t as Le,u as Re,v as ze,w as Be,x as Ve,y as He}from"./side-chat-context-Dn8w9ut8.js";import{t as Ue}from"./loader-circle-BOwQzHB-.js";import{t as We}from"./message-square-SKjZyY3v.js";import{t as Ge}from"./WorkbenchSidebarToggle-CcO1Al5A.js";import{t as Ke}from"./paperclip-BCXrwYpb.js";import{t as qe}from"./pencil-U08v_vV9.js";import{t as Je}from"./play-DNDjDNGn.js";import{t as Ye}from"./plus-fQbSqB1n.js";import{t as Xe}from"./refresh-cw-TbWxTY4K.js";import{t as Ze}from"./rotate-ccw-C0v8V77_.js";import{t as Qe}from"./search-D0mqDaf_.js";import{t as $e}from"./settings-QX0oWnVK.js";import{t as et}from"./sliders-horizontal-Dryf1XyC.js";import{t as tt}from"./square-terminal-BVG6cUT1.js";import{t as nt}from"./square-bHHVTT3G.js";import{t as rt}from"./tag-CqkeJlBf.js";import{t as it}from"./trash-2-CNrPOoPR.js";import{t as at}from"./triangle-alert-CE1q54ci.js";import{t as ot}from"./undo-2-CJE_nRTk.js";import{i as st,n as ct,t as lt}from"./web-preview-events-C4AW4-It.js";import{t as ut}from"./wrench-6pg6_bqI.js";import{t as dt}from"./x-07u4-129.js";import{r as ft}from"./use-mobile-YXncArOq.js";import{i as pt,n as mt,o as ht,r as gt}from"./http-Be2GB6DH.js";import{n as _t,r as q,t as vt}from"./abort-signal-f4JsiYKX.js";import{n as yt,t as bt}from"./api-YI8_cHpR.js";import{n as xt,t as St}from"./client-store-BP_3-plw.js";import{t as J}from"./button-CQA36izu.js";import{n as Ct}from"./QueryClientProvider-CHJtxoX1.js";import{t as Y}from"./chat-api-CqF-FICX.js";import{n as wt}from"./MobileShellContext-D8qX-BlM.js";import{n as Tt,t as Et}from"./alert-QoPGoIY6.js";import{a as Dt,c as Ot,i as kt,n as At,o as jt,r as Mt,s as Nt,t as Pt}from"./dialog-D-ER2p-D.js";import{t as Ft}from"./input-CvjGYteF.js";import{WorkspacePicker as It,t as Lt}from"./WorkspacePicker-B3liZkwe.js";import{i as Rt,n as X,t as zt}from"./format-BRFKAYMT.js";import{n as Bt,r as Vt,t as Ht}from"./app-primitives-SxfoFmHc.js";import{i as Ut,o as Wt,r as Gt,s as Kt,t as qt}from"./shortcuts-C_Cph88H.js";import{i as Jt,t as Yt}from"./runtime-capabilities-store-CiL3ZPEo.js";import{r as Xt}from"./ui-store-BGs-dEVz.js";import{C as Zt,E as Qt,S as $t,T as en,_ as tn,a as nn,b as rn,f as an,i as on,l as sn,m as cn,o as ln,s as un,u as dn,v as fn,w as pn,x as mn,y as hn}from"./events-KqdUtjsm.js";import{t as gn}from"./usePagePrimaryAction-CWPC0C_f.js";import{t as _n}from"./brand-DIEc3fK8.js";import{i as vn,r as yn}from"./tool-labels-DJzY62Yr.js";import{r as bn}from"./GitDiffViewer-m5aLB7Li.js";import{a as xn,c as Sn,i as Cn,l as wn,n as Tn,o as En,s as Dn,t as On,u as kn}from"./speech-session-CoUr4n9Q.js";import{n as An,t as jn}from"./pick-system-directory-BnIFt85A.js";import{n as Mn,r as Nn,t as Pn,useSessionContextStore as Fn}from"./session-context-store-DJnHgWwb.js";var Z=e(r(),1),Q=a(),In=Object.defineProperty,Ln=(e,t)=>In(e,`name`,{value:t,configurable:!0}),Rn=`Checkbox`,[zn,Bn]=v(Rn),[Vn,Hn]=zn(Rn);function Un(e){let{__scopeCheckbox:t,checked:n,children:r,defaultChecked:i,disabled:a,form:o,name:s,onCheckedChange:c,required:l,value:u=`on`,internal_do_not_use_render:d}=e,[f,p]=h({prop:n,defaultProp:i??!1,onChange:c,caller:Rn}),[m,g]=Z.useState(null),[_,v]=Z.useState(null),y=Z.useRef(!1),[b,x]=Z.useReducer(e=>e+1,0),S=!m||!!o||!!m.closest(`form`),C={checked:f,disabled:a,setChecked:p,control:m,setControl:g,name:s,form:o,value:u,hasConsumerStoppedPropagationRef:y,userInteractionCount:b,onUserInteraction:x,required:l,defaultChecked:!Qn(i)&&i,isFormControl:S,bubbleInput:_,setBubbleInput:v};return(0,Q.jsx)(Vn,{scope:t,...C,children:Zn(d)?d(C):r})}Ln(Un,`CheckboxProvider`);var Wn=`CheckboxTrigger`,Gn=Z.forwardRef(Ln(function({__scopeCheckbox:e,onKeyDown:t,onClick:n,...r},i){let{control:a,value:o,disabled:s,checked:c,required:l,setControl:u,setChecked:d,hasConsumerStoppedPropagationRef:f,onUserInteraction:h,isFormControl:_,bubbleInput:v}=Hn(Wn,e),y=p(i,u),b=Z.useRef(c);return Z.useEffect(()=>{let e=a?.form;if(e){let t=Ln(()=>d(b.current),`reset`);return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)}},[a,d]),(0,Q.jsx)(m.button,{type:`button`,role:`checkbox`,"aria-checked":Qn(c)?`mixed`:c,"aria-required":l,"data-state":$n(c),"data-disabled":s?``:void 0,disabled:s,value:o,...r,ref:y,onKeyDown:g(t,e=>{e.key===`Enter`&&e.preventDefault()}),onClick:g(n,e=>{h(),d(e=>Qn(e)?!0:!e),v&&_&&(f.current=e.isPropagationStopped(),f.current||e.stopPropagation())})})},`CheckboxTrigger`)),Kn=Z.forwardRef(Ln(function(e,t){let{__scopeCheckbox:n,name:r,checked:i,defaultChecked:a,required:o,disabled:s,value:c,onCheckedChange:l,form:u,...d}=e;return(0,Q.jsx)(Un,{__scopeCheckbox:n,checked:i,defaultChecked:a,disabled:s,required:o,onCheckedChange:l,name:r,form:u,value:c,internal_do_not_use_render:({isFormControl:e})=>(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Gn,{...d,ref:t,__scopeCheckbox:n}),e&&(0,Q.jsx)(Xn,{__scopeCheckbox:n})]})})},`Checkbox`)),qn=`CheckboxIndicator`,Jn=Z.forwardRef(Ln(function(e,t){let{__scopeCheckbox:n,forceMount:r,...i}=e,a=Hn(qn,n);return(0,Q.jsx)(_,{present:r||Qn(a.checked)||a.checked===!0,children:(0,Q.jsx)(m.span,{"data-state":$n(a.checked),"data-disabled":a.disabled?``:void 0,...i,ref:t,style:{pointerEvents:`none`,...e.style}})})},`CheckboxIndicator`)),Yn=`CheckboxBubbleInput`,Xn=Z.forwardRef(Ln(function({__scopeCheckbox:e,onClick:t,...n},r){let{control:i,hasConsumerStoppedPropagationRef:a,userInteractionCount:o,checked:s,defaultChecked:c,required:l,disabled:u,name:d,value:f,form:h,bubbleInput:_,setBubbleInput:v}=Hn(Yn,e),y=p(r,v),x=b(i),S=Z.useRef(!1),C=Z.useRef(s),w=Z.useRef(o);Z.useEffect(()=>{let e=_;if(!e)return;let t=window.HTMLInputElement.prototype,n=Object.getOwnPropertyDescriptor(t,`checked`).set,r=o!==w.current;w.current=o;let i=C.current!==s;C.current=s;let c=!(r&&a.current);if(i&&n){S.current=!r;let t=new Event(`click`,{bubbles:c});e.indeterminate=Qn(s),n.call(e,!Qn(s)&&s),e.dispatchEvent(t),S.current=!1}},[_,s,a,o]);let T=Z.useRef(!Qn(s)&&s);return(0,Q.jsx)(m.input,{type:`checkbox`,"aria-hidden":!0,defaultChecked:c??T.current,required:l,disabled:u,name:d,value:f,form:h,...n,tabIndex:-1,ref:y,onClick:g(t,e=>{S.current&&e.stopPropagation()}),style:{...n.style,...x,position:`absolute`,pointerEvents:`none`,opacity:0,margin:0,transform:`translateX(-100%)`}})},`CheckboxBubbleInput`));function Zn(e){return typeof e==`function`}Ln(Zn,`isFunction`);function Qn(e){return e===`indeterminate`}Ln(Qn,`isIndeterminate`);function $n(e){return Qn(e)?`indeterminate`:e?`checked`:`unchecked`}Ln($n,`getState`);var er=R(`audio-lines`,[[`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`}]]),tr=R(`badge-check`,[[`path`,{d:`M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z`,key:`3c2336`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),nr=R(`book-open`,[[`path`,{d:`M12 5v16`,key:`1f6ucr`}],[`path`,{d:`M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z`,key:`1fyvmf`}]]),rr=R(`bookmark`,[[`path`,{d:`M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z`,key:`oz39mx`}]]),ir=R(`command`,[[`path`,{d:`M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3`,key:`11bfej`}]]),ar=R(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),or=R(`file-check-corner`,[[`path`,{d:`M10.5 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v6`,key:`g5mvt7`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`m14 20 2 2 4-4`,key:`15kota`}]]),sr=R(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),cr=R(`mic-off`,[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]),lr=R(`mic`,[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`,key:`1vc78b`}],[`rect`,{x:`9`,y:`2`,width:`6`,height:`13`,rx:`3`,key:`s6n7sd`}]]),ur=R(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),dr=R(`panel-right-close`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m8 9 3 3-3 3`,key:`12hl5m`}]]),fr=R(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),pr=R(`sigma`,[[`path`,{d:`M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2`,key:`wuwx1p`}]]),mr=R(`target`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`6`,key:`1vlfrh`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),hr=R(`tree-pine`,[[`path`,{d:`m17 14 3 3.3a1 1 0 0 1-.7 1.7H4.7a1 1 0 0 1-.7-1.7L7 14h-.3a1 1 0 0 1-.7-1.7L9 9h-.2A1 1 0 0 1 8 7.3L12 3l4 4.3a1 1 0 0 1-.8 1.7H15l3 3.3a1 1 0 0 1-.7 1.7H17Z`,key:`cpyugq`}],[`path`,{d:`M12 22v-3`,key:`kmzjlo`}]]),gr=R(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),_r=e(i(),1),vr=10485760,yr=20971520,br=new Set([`txt`,`md`,`json`,`js`,`jsx`,`ts`,`tsx`,`css`,`html`,`xml`,`yaml`,`yml`,`csv`,`log`,`py`,`java`,`go`,`rs`,`sh`,`ps1`,`toml`,`sql`]),xr=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`svg`]),Sr=new Set([`pdf`,`docx`,`pptx`,`xlsx`,`odt`,`odp`,`ods`,`rtf`,`epub`]),Cr=[`image/*`,`text/*`,`application/json`,...[...xr,...br,...Sr].map(e=>`.${e}`)].join(`,`);function wr(e){let t=[...e?.files||[]];return t.length?t:[...e?.items||[]].filter(e=>e.kind===`file`).map(e=>e.getAsFile?.()).filter(e=>!!e)}function Tr(e){return[...e?.types||[]].includes(`Files`)}function Er(e,t){return new Promise((n,r)=>{let i=new FileReader;i.onload=()=>n(String(i.result).split(`,`)[1]||``),i.onerror=()=>r(i.error||Error(t(`chat:attachments.couldNotReadFile`))),i.readAsDataURL(e)})}function Dr(e){return e.toLowerCase().split(`.`).at(-1)||``}async function Or(e,t){let n=[...e].slice(0,8),r=[];for(let e of n){if(e.size>vr)throw Error(t(`chat:attachments.nameExceedsThe10MBLimit`,{name:e.name}));let n=Dr(e.name),i={id:`${e.name}-${e.lastModified}-${e.size}`,name:e.name,mimeType:e.type||`application/octet-stream`,size:e.size};if(e.type.startsWith(`image/`)||xr.has(n))r.push({...i,kind:`image`,data:await Er(e,t)});else if(e.type.startsWith(`text/`)||e.type===`application/json`||br.has(n))r.push({...i,kind:`text`,text:await e.text()});else if(Sr.has(n))r.push({...i,kind:`document`,extension:n,data:await Er(e,t)});else throw Error(t(`chat:attachments.nameIsNotSupportedChooseAnImageOrTextCodeFile`,{name:e.name}))}return r}function kr(e){return e.split(/[\\/]/).filter(Boolean).at(-1)||e}function Ar(e){return[...e].map(e=>String(e||``).trim()).filter(Boolean).slice(0,8).map(e=>({id:`path:${e}`,kind:`path`,name:kr(e),path:e}))}function jr(e=[],t){let n=(0,Z.useCallback)((e,t)=>s(e,o(),t),[]),[r,i]=(0,Z.useState)(()=>[...e]),[a,c]=(0,Z.useState)(``),l=(0,Z.useRef)([...e]),u=(0,Z.useCallback)(e=>{l.current=e,i(e),t?.(e)},[t]),d=(0,Z.useCallback)(async e=>{try{c(``);let t=await Or(e||[],n),r=[...l.current,...t].slice(0,8);if(r.filter(e=>e.kind!==`path`).reduce((e,t)=>e+(t.size||0),0)>yr)throw Error(n(`chat:attachments.totalAttachmentSizeCannotExceed20MB`));return u(r),!0}catch(e){return c(e instanceof Error?e.message:String(e)),!1}},[u,n]);return{attachments:r,attachmentError:a,addFiles:d,pasteFiles:(0,Z.useCallback)(e=>{let t=wr(e.clipboardData);t.length&&(e.preventDefault(),d(t))},[d]),dropFiles:(0,Z.useCallback)(e=>{if(!Tr(e.dataTransfer))return;e.preventDefault();let t=wr(e.dataTransfer);t.length&&d(t)},[d]),removeAttachment:(0,Z.useCallback)(e=>{u(l.current.filter(t=>t.id!==e))},[u]),clearAttachments:(0,Z.useCallback)(()=>u([]),[u]),addAttachments:(0,Z.useCallback)(e=>{c(``);let t=[...l.current];for(let n of e)t.some(e=>e.id===n.id)||t.push(n);u(t.slice(0,8))},[u]),replaceAttachments:u,setError:(0,Z.useCallback)(e=>{c(e instanceof Error?e.message:String(e||``))},[])}}function Mr({className:e,...t}){return(0,Q.jsx)(Kn,{"data-slot":`checkbox`,className:L(`peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors outline-none group-has-disabled/field:opacity-50 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary`,e),...t,children:(0,Q.jsx)(Jn,{"data-slot":`checkbox-indicator`,className:`grid place-content-center text-current transition-none [&>svg]:size-3.5`,children:(0,Q.jsx)(se,{})})})}function Nr({open:e,initialPath:t,onOpenChange:n,onSelect:r}){let{t:i}=c(),[a,o]=(0,Z.useState)(t||``),[s,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)([]),[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(``),g=(0,Z.useRef)(0),_=(0,Z.useCallback)(async e=>{let t=++g.current;p(!0),h(``);try{let n=await bt(`/api/workspace-entries?path=${encodeURIComponent(e.trim())}`);if(t!==g.current)return;o(n.path),l(n),d([])}catch(e){if(t!==g.current)return;h(e instanceof Error?e.message:String(e))}finally{t===g.current&&p(!1)}},[]);(0,Z.useEffect)(()=>{if(!e){g.current+=1;return}o(t||``),l(null),d([]),_(t||``)},[_,t,e]);let v=e=>{e.preventDefault(),_(a)},y=(e,t)=>{d(n=>t?[...n.filter(t=>t!==e),e].slice(-8):n.filter(t=>t!==e))};return(0,Q.jsx)(Pt,{open:e,onOpenChange:n,children:(0,Q.jsxs)(Mt,{className:`max-w-[calc(100vw-24px)]! gap-0 overflow-hidden p-0 sm:max-w-[680px]!`,children:[(0,Q.jsxs)(jt,{className:`border-b px-4 py-3 pr-12`,children:[(0,Q.jsx)(Nt,{children:i(`chat:pathAttachmentPicker.title`)}),(0,Q.jsx)(kt,{children:i(`chat:pathAttachmentPicker.description`)})]}),(0,Q.jsxs)(`form`,{className:`flex min-w-0 items-center gap-2 px-4 py-3`,onSubmit:v,children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,size:`icon`,title:i(`common:workspacePicker.parentFolder`),"aria-label":i(`common:workspacePicker.parentFolder`),disabled:f||!s?.parent,onClick:()=>s?.parent&&void _(s.parent),children:(0,Q.jsx)(ae,{})}),(0,Q.jsx)(Ft,{className:`min-w-0 flex-1 font-mono text-[12px]`,value:a,"aria-label":i(`chat:pathAttachmentPicker.directoryPath`),onChange:e=>o(e.target.value)}),(0,Q.jsxs)(J,{type:`submit`,variant:`secondary`,disabled:f||!a.trim(),children:[f?(0,Q.jsx)(Ue,{className:`animate-spin`}):(0,Q.jsx)(le,{}),i(`common:workspacePicker.go`)]})]}),(0,Q.jsx)(Lt,{className:`h-[min(400px,50dvh)] border-y bg-muted/20`,children:(0,Q.jsxs)(`div`,{className:`p-2`,children:[s?.directories.map(e=>(0,Q.jsxs)(`button`,{type:`button`,className:`grid h-9 w-full grid-cols-[24px_minmax(0,1fr)_20px] items-center rounded-md px-2 text-left text-[13px] hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none`,title:e.path,disabled:f,onClick:()=>void _(e.path),children:[(0,Q.jsx)(ge,{className:`size-4 text-content-muted`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.name}),(0,Q.jsx)(le,{className:`size-4 text-content-muted`})]},e.path)),s?.files.map(e=>{let t=u.includes(e.path);return(0,Q.jsxs)(`label`,{className:`grid h-9 cursor-pointer grid-cols-[24px_minmax(0,1fr)_24px] items-center rounded-md px-2 text-[13px] hover:bg-muted`,title:e.path,children:[(0,Q.jsx)(he,{className:`size-4 text-content-muted`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.name}),(0,Q.jsx)(Mr,{checked:t,"aria-label":i(`chat:pathAttachmentPicker.selectName`,{name:e.name}),onCheckedChange:t=>y(e.path,t===!0)})]},e.path)}),f&&(0,Q.jsxs)(`div`,{className:`flex h-32 items-center justify-center gap-2 text-content-muted`,children:[(0,Q.jsx)(Ue,{className:`size-4 animate-spin`}),(0,Q.jsx)(`span`,{children:i(`common:workspacePicker.readingFolder`)})]}),!f&&s&&!s.directories.length&&!s.files.length&&(0,Q.jsx)(`div`,{className:`flex h-32 items-center justify-center text-content-muted`,children:i(`chat:pathAttachmentPicker.empty`)})]})}),m&&(0,Q.jsxs)(Et,{variant:`destructive`,className:`mx-4 mt-3 w-auto`,children:[(0,Q.jsx)(at,{}),(0,Q.jsx)(Tt,{children:m})]}),(0,Q.jsxs)(Dt,{className:`m-0 border-t-0 bg-transparent px-4 py-3`,children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>n(!1),children:i(`common:ui.cancel`)}),(0,Q.jsx)(J,{type:`button`,variant:`secondary`,disabled:!u.length,onClick:()=>{u.length&&(r(u),n(!1))},children:i(`chat:pathAttachmentPicker.attachCount`,{count:u.length})})]})]})})}function Pr({cwd:e,selection:t}){let{t:n}=c(),r=xt(),[i,a]=(0,Z.useState)(!1),o=(0,Z.useRef)(null),s=async()=>{if(r){o.current?.click();return}if(window.pisperDesktop?.pickFiles){try{let n=await window.pisperDesktop.pickFiles(e);t.addAttachments(Ar(n||[]))}catch(e){t.setError(e)}return}a(!0)};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`input`,{ref:o,type:`file`,className:`hidden`,accept:Cr,multiple:!0,"aria-label":n(`chat:focusSession.addAttachment`),onChange:e=>{let n=[...e.currentTarget.files||[]];e.currentTarget.value=``,n.length&&t.addFiles(n)}}),(0,Q.jsxs)(`button`,{type:`button`,className:`attach-trigger [.focus-composer_&]:h-[38px] [.focus-composer_&]:border-0 [.focus-composer_&]:rounded-[var(--r-sm)] [.focus-composer_&]:bg-[var(--surface-subtle)] [.focus-composer_&]:text-[12px] [.focus-composer_&]:w-[38px] [.focus-composer_&]:min-w-[38px] [.focus-session.has-conversation_.focus-composer_&]:w-[36px] [.focus-session.has-conversation_.focus-composer_&]:min-w-[36px] [.focus-session.has-conversation_.focus-composer_&]:h-[36px] relative grid place-items-center border-0 rounded-[var(--r-xs)] bg-transparent text-[var(--text-muted)] cursor-pointer hover:bg-[var(--surface-hover)] hover:text-[var(--star-strong)] [&_i]:absolute [&_i]:top-[-4px] [&_i]:right-[-4px] [&_i]:grid [&_i]:min-w-[14px] [&_i]:h-[14px] [&_i]:place-items-center [&_i]:[border:2px_solid_var(--solid)] [&_i]:rounded-[var(--r-pill)] [&_i]:bg-[var(--blue)] [&_i]:text-[var(--on-accent)] [&_i]:p-[0_3px] [&_i]:text-[13px] [&_i]:[font-style:normal]`,title:n(`chat:focusSession.addAttachment`),"aria-label":n(`chat:focusSession.addAttachment`),onClick:()=>void s(),children:[(0,Q.jsx)(Ke,{size:17}),t.attachments.length>0&&(0,Q.jsx)(`i`,{children:t.attachments.length})]}),(0,Q.jsx)(Nr,{open:i,initialPath:e,onOpenChange:a,onSelect:e=>t.addAttachments(Ar(e))})]})}function Fr({attachments:e,onRemove:t,compact:n=!1}){let{t:r}=c();return e.length?(0,Q.jsx)(`div`,{className:`attachment-tray [&.compact]:max-h-[58px] flex max-h-[116px] flex-wrap gap-[6px] overflow-auto ${n?`compact`:``}`,children:e.map(e=>(0,Q.jsxs)(`div`,{className:`attachment-chip [&_>_img]:w-[30px] [&_>_img]:h-[30px] [&_>_img]:rounded-[var(--r-xs)] [&_>_img]:object-cover [&_>_span:nth-child(2)]:flex [&_>_span:nth-child(2)]:min-w-0 [&_>_span:nth-child(2)]:flex-col [&_>_span:nth-child(2)]:gap-[2px] [&_strong]:overflow-hidden [&_strong]:text-[13px] [&_strong]:text-ellipsis [&_strong]:whitespace-nowrap [&_small]:text-[var(--text-muted)] [&_small]:text-[13px] [&_>_button]:grid [&_>_button]:w-[32px] [&_>_button]:h-[32px] [&_>_button]:place-items-center [&_>_button]:border-0 [&_>_button]:rounded-[var(--r-xs)] [&_>_button]:bg-transparent [&_>_button]:text-[var(--text-muted)] [&_>_button:hover]:bg-[var(--danger-soft)] [&_>_button:hover]:text-[var(--danger)] dark:bg-[var(--surface-subtle)] grid min-w-[150px] max-w-[250px] grid-cols-[30px_minmax(0,1fr)_auto] items-center gap-[7px] [border:1px_solid_var(--stroke)] rounded-[var(--r-sm)] bg-[var(--surface-subtle)] [padding:5px]`,children:[e.kind===`image`?(0,Q.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.data}`,alt:``}):(0,Q.jsx)(`span`,{className:`grid w-[30px] h-[30px] place-items-center rounded-[var(--r-xs)] bg-[var(--violet-soft)] text-[var(--violet-strong)]`,children:(0,Q.jsx)(he,{size:13})}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`strong`,{children:e.name}),(0,Q.jsxs)(`small`,{children:[e.kind===`path`?r(`chat:focusSession.localPath`):e.kind===`image`?r(`chat:focusSession.image`):e.kind===`document`?r(`chat:focusSession.document`):r(`chat:focusSession.text`),e.kind===`path`?``:` · ${zt(e.size)}`,e.truncated?` · ${r(`chat:focusSession.truncated`)}`:``]})]}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":r(`chat:focusSession.removeName`,{name:e.name}),onClick:()=>t(String(e.id||``)),children:(0,Q.jsx)(dt,{size:12})})]},e.id))}):null}function Ir({open:e,sessionId:t,onClose:n,onSelect:r,onCommandSelect:i}){let{t:a}=c(),o=Yt(e=>e.capabilities),s=Jt(o,`workflows`),[l,u]=(0,Z.useState)([]),[d,f]=(0,Z.useState)(`all`),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)({}),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(``);(0,Z.useEffect)(()=>{if(!e)return;let n=!0;return f(`all`),m(``),g(null),v({}),b(!0),S(``),Promise.all([Y.getSessionCommands(t),s?bt(`/api/workflows`):Promise.resolve({workflows:[]}),bt(`/api/plugins?sessionId=${encodeURIComponent(t)}`)]).then(([e,t,r])=>{if(!n)return;let i=new Set(r.callableToolNames||[]);u([...(e.commands||[]).map(e=>({kind:e.source,id:e.name,name:e.name,description:e.description||``,inputs:[],argumentHint:e.argumentHint,invocation:e.invocation})),...(t.workflows||[]).filter(e=>e.status===`published`).map(e=>({kind:`workflow`,id:e.id,name:e.name,description:e.description||``,inputs:e.inputs||[]})),...(r.plugins||[]).flatMap(e=>(e.capabilities||[]).filter(e=>i.has(e.name)).map(t=>({kind:`tool`,id:t.name,name:t.id?vn(t,a):String(t.label||t.name),description:t.id?yn(t,a):t.description,inputs:[],sourceName:e.name})))])}).catch(e=>{n&&(u([]),S(e instanceof Error?e.message:String(e)))}).finally(()=>n&&b(!1)),()=>{n=!1}},[e,t,a,s]);let C=(0,Z.useMemo)(()=>({all:l.length,prompt:l.filter(e=>e.kind===`prompt`).length,skill:l.filter(e=>e.kind===`skill`).length,tool:l.filter(e=>e.kind===`tool`).length,workflow:l.filter(e=>e.kind===`workflow`).length}),[l]),w=(0,Z.useMemo)(()=>{let e=p.trim().toLowerCase();return l.filter(t=>(d===`all`||t.kind===d)&&(!e||`${t.name} ${t.id} ${t.description} ${t.kind===`tool`?t.sourceName:``}`.toLowerCase().includes(e)))},[d,p,l]),T=e=>{let t=e;f(t),h&&t!==`all`&&h.kind!==t&&g(null)},E=e=>{g(e),v(Object.fromEntries(e.inputs.map(e=>[e.name,e.defaultValue??``])))};return(0,Q.jsx)(Pt,{open:e,onOpenChange:e=>!e&&n(),children:(0,Q.jsxs)(Mt,{className:`chat-resource-dialog w-[min(820px,calc(100vw_-_32px))] h-[min(600px,calc(100dvh_-_32px))] max-w-[820px] sm:max-w-[820px] grid-rows-[auto_minmax(0,1fr)] overflow-hidden max-[650px]:w-[calc(100vw_-_16px)] max-[650px]:h-[calc(100dvh_-_16px)] z-[220] gap-0 p-0 ring-0`,overlayClassName:`z-[220]`,showCloseButton:!1,children:[(0,Q.jsxs)(`div`,{className:`chat-resource-head [&_[data-slot='dialog-title']]:text-[16px] [&_[data-slot='dialog-description']]:mt-[3px] [&_[data-slot='dialog-description']]:text-[12px] max-[650px]:p-[14px] flex items-start justify-between gap-[16px] [border-bottom:1px_solid_var(--stroke-soft)] [padding:17px_18px_14px]`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(Nt,{children:a(`chat:resourcePicker.title`)}),(0,Q.jsx)(kt,{children:a(`chat:resourcePicker.description`)})]}),(0,Q.jsx)(J,{size:`icon-sm`,variant:`ghost`,"aria-label":a(`chat:resourcePicker.close`),onClick:n,children:(0,Q.jsx)(dt,{})})]}),(0,Q.jsxs)(`div`,{className:`chat-resource-body grid min-h-0 grid-cols-[minmax(0,1.1fr)_minmax(260px,.9fr)] overflow-hidden max-[650px]:grid-cols-[1fr] max-[650px]:grid-rows-[minmax(0,1fr)_minmax(190px,auto)] max-[650px]:overflow-hidden`,children:[(0,Q.jsxs)(`div`,{className:`chat-resource-browser flex min-w-0 min-h-0 flex-col [border-right:1px_solid_var(--stroke-soft)] p-[12px] max-[650px]:min-h-0 max-[650px]:[border-right:0] max-[650px]:[border-bottom:1px_solid_var(--stroke-soft)]`,children:[(0,Q.jsx)(N,{value:d,onValueChange:T,className:`chat-resource-tabs [&_[data-slot='tabs-list']]:grid [&_[data-slot='tabs-list']]:w-full [&_[data-slot='tabs-list']]:h-[36px] [&_[data-slot='tabs-list']]:[border:1px_solid_var(--stroke-soft)] [&_[data-slot='tabs-list']]:rounded-[var(--r-sm)] [&_[data-slot='tabs-list']]:bg-[var(--surface-muted)] [&_[data-slot='tabs-trigger']]:min-w-0 [&_[data-slot='tabs-trigger']]:gap-[5px] [&_[data-slot='tabs-trigger']]:rounded-[var(--r-xs)] [&_[data-slot='tabs-trigger']]:[padding-inline:6px] [&_[data-slot='tabs-trigger']]:text-[11px] [&_[data-slot='tabs-trigger'][data-state='active']]:bg-[var(--solid)] [&_[data-slot='tabs-trigger'][data-state='active']]:text-[var(--text)] [&_[data-slot='tabs-trigger']_small]:text-[var(--text-muted)] [&_[data-slot='tabs-trigger']_small]:text-[10px] [&_[data-slot='tabs-trigger']_small]:font-[500] w-full ${s?`[&_[data-slot='tabs-list']]:grid-cols-[repeat(5,minmax(0,1fr))]`:`[&_[data-slot='tabs-list']]:grid-cols-[repeat(4,minmax(0,1fr))]`}`,children:(0,Q.jsxs)(M,{"aria-label":a(`chat:resourcePicker.categories`),children:[(0,Q.jsxs)(j,{value:`all`,children:[a(`chat:resourcePicker.all`),(0,Q.jsx)(`small`,{children:C.all})]}),(0,Q.jsxs)(j,{value:`prompt`,children:[a(`chat:resourcePicker.prompt`),(0,Q.jsx)(`small`,{children:C.prompt})]}),(0,Q.jsxs)(j,{value:`skill`,children:[a(`chat:resourcePicker.skill`),(0,Q.jsx)(`small`,{children:C.skill})]}),(0,Q.jsxs)(j,{value:`tool`,children:[a(`chat:resourcePicker.tool`),(0,Q.jsx)(`small`,{children:C.tool})]}),s&&(0,Q.jsxs)(j,{value:`workflow`,children:[a(`chat:resourcePicker.workflow`),(0,Q.jsx)(`small`,{children:C.workflow})]})]})}),(0,Q.jsxs)(`label`,{className:`chat-resource-search [&:focus-within]:border-[var(--focus)] [&:focus-within]:shadow-[0_0_0_2px_var(--focus-ring)] [&_input]:w-full [&_input]:h-[36px] [&_input]:border-0 [&_input]:[outline:0]! [&_input]:bg-transparent [&_input]:text-[var(--text)] [&_input]:text-[13px] flex items-center gap-[7px] [margin-top:8px] [border:1px_solid_var(--stroke)] rounded-[var(--r-sm)] [padding:0_10px] text-[var(--text-muted)]`,children:[(0,Q.jsx)(Qe,{size:15}),(0,Q.jsx)(`input`,{autoFocus:!0,value:p,onChange:e=>m(e.target.value),placeholder:a(`chat:resourcePicker.search`)})]}),(0,Q.jsxs)(`div`,{className:`chat-resource-list [&_>_button]:grid [&_>_button]:w-full [&_>_button]:grid-cols-[30px_minmax(0,1fr)_auto] [&_>_button]:items-center [&_>_button]:gap-[8px] [&_>_button]:[border:1px_solid_transparent] [&_>_button]:rounded-[var(--r-sm)] [&_>_button]:bg-transparent [&_>_button]:p-[8px] [&_>_button]:text-[var(--text)] [&_>_button]:text-left [&_>_button]:cursor-pointer [&_>_button:hover]:bg-[var(--surface-hover)] [&_>_button.active]:border-[var(--focus)] [&_>_button.active]:bg-[var(--blue-soft)] [&_button_>_span:nth-child(2)]:flex [&_button_>_span:nth-child(2)]:min-w-0 [&_button_>_span:nth-child(2)]:flex-col [&_button_>_span:nth-child(2)]:gap-[2px] [&_strong]:overflow-hidden [&_strong]:text-[13px] [&_strong]:text-ellipsis [&_strong]:whitespace-nowrap [&_small]:overflow-hidden [&_small]:text-[var(--text-muted)] [&_small]:text-[11px] [&_small]:text-ellipsis [&_small]:whitespace-nowrap [&_em]:text-[var(--text-muted)] [&_em]:text-[10px] [&_em]:[font-style:normal] [&_>_p]:m-[auto] [&_>_p]:text-[var(--text-muted)] [&_>_p]:text-[12px] flex min-h-0 [flex:1_1_0] flex-col gap-[3px] overflow-y-auto [overscroll-behavior:contain] [scrollbar-gutter:stable] [touch-action:pan-y] [margin-top:9px]`,children:[w.map(e=>{let t=e.kind===`prompt`?me:e.kind===`skill`?D:e.kind===`tool`?ut:st;return(0,Q.jsxs)(`button`,{type:`button`,className:h?.kind===e.kind&&h.id===e.id?`active`:``,onClick:()=>E(e),children:[(0,Q.jsx)(`span`,{className:`list-icon [.chat-resource-list_&]:grid [.chat-resource-list_&]:w-[28px] [.chat-resource-list_&]:h-[28px] [.chat-resource-list_&]:place-items-center [.chat-resource-list_&]:rounded-[var(--r-sm)] [.chat-resource-list_&]:bg-[var(--surface-subtle)] [.chat-resource-list_&]:text-[var(--star-strong)] [.session-workflow-summary_&]:grid [.session-workflow-summary_&]:w-[28px] [.session-workflow-summary_&]:h-[28px] [.session-workflow-summary_&]:place-items-center [.session-workflow-summary_&]:rounded-[var(--r-sm)] [.session-workflow-summary_&]:bg-[var(--surface-subtle)] [.session-workflow-summary_&]:text-[var(--star-strong)] grid w-[27px] h-[27px] place-items-center rounded-[var(--r-sm)] bg-[var(--accent-soft)] text-[var(--star-strong)] [.workflow-template-gallery_&]:grid [.workflow-template-gallery_&]:w-[32px] [.workflow-template-gallery_&]:h-[32px] [.workflow-template-gallery_&]:place-items-center [.workflow-template-gallery_&]:rounded-[var(--r-sm)] [.workflow-template-gallery_&]:bg-[var(--surface-subtle)] [.workflow-template-gallery_&]:text-[var(--star-strong)]`,children:(0,Q.jsx)(t,{size:15})}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`strong`,{children:e.name}),(0,Q.jsx)(`small`,{children:e.description})]}),(0,Q.jsx)(`em`,{children:e.kind===`prompt`?a(`chat:resourcePicker.prompt`):e.kind===`skill`?`Skill`:e.kind===`tool`?a(`chat:resourcePicker.tool`):a(`chat:resourcePicker.workflow`)})]},`${e.kind}:${e.id}`)}),!w.length&&(0,Q.jsx)(`p`,{children:y?a(`chat:resourcePicker.loading`):x||a(`chat:resourcePicker.empty`)})]})]}),(0,Q.jsx)(`div`,{className:`chat-resource-config [&_>_p]:m-[auto] [&_>_p]:text-[var(--text-muted)] [&_>_p]:text-[12px] [&_>_div:first-child]:flex [&_>_div:first-child]:flex-col [&_>_div:first-child]:gap-[4px] [&_strong]:text-[14px] [&_p]:text-[var(--text-muted)] [&_p]:text-[12px] max-[650px]:min-h-0 max-[650px]:max-h-[230px] flex min-w-0 min-h-0 flex-col gap-[16px] overflow-y-auto [overscroll-behavior:contain] [padding:18px]`,children:h?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`strong`,{children:h.name}),(0,Q.jsx)(`p`,{children:h.description||a(`chat:resourcePicker.noDescription`)})]}),h.kind===`workflow`&&h.inputs.length>0&&(0,Q.jsx)(`div`,{className:`chat-resource-inputs [&_label]:grid [&_label]:gap-[5px] [&_label]:text-[12px] [&_label]:font-[600] [&_input[type='checkbox']]:w-[16px] [&_input[type='checkbox']]:h-[16px] [&_input[type='checkbox']]:[accent-color:var(--blue)] flex flex-col gap-[11px]`,children:h.inputs.map(e=>(0,Q.jsxs)(`label`,{children:[(0,Q.jsxs)(`span`,{children:[e.label,e.required?` *`:``]}),e.type===`boolean`?(0,Q.jsx)(`input`,{type:`checkbox`,checked:!!_[e.name],onChange:t=>v(n=>({...n,[e.name]:t.target.checked}))}):(0,Q.jsx)(Ft,{type:e.type===`number`?`number`:`text`,required:e.required,value:String(_[e.name]??``),onChange:t=>v(n=>({...n,[e.name]:t.target.value}))})]},e.id))}),h.kind===`prompt`&&h.argumentHint&&(0,Q.jsx)(`code`,{className:`w-fit max-w-[100%] [overflow-wrap:anywhere] rounded-[var(--r-xs)] bg-[var(--surface-muted)] text-[var(--text-secondary)] [padding:5px_7px] text-[11px]`,children:h.argumentHint}),(0,Q.jsx)(J,{className:`chat-resource-confirm hover:bg-[var(--star-hover)] hover:text-[var(--on-accent)] min-w-[112px] min-h-[36px] self-start bg-[var(--star)] text-[var(--on-accent)] font-[650]`,onClick:()=>{if(h){if(h.kind===`prompt`){i(h.invocation||`/${h.name}`),n();return}r({kind:h.kind,resourceId:h.id,resourceName:h.name,arguments:h.kind===`workflow`?_:void 0,behavior:h.kind===`workflow`?`background`:`foreground`}),n()}},children:h.kind===`prompt`?a(`chat:resourcePicker.insertPrompt`):a(`chat:resourcePicker.useResource`)})]}):(0,Q.jsx)(`p`,{children:a(`chat:resourcePicker.chooseResource`)})})]})]})})}var Lr=64,Rr=new Map;function zr(e,t){let n=t.match(/^\/[^\s]*(?:\s+([\s\S]*))?$/),r=(n?n[1]||``:t).trim();return`${e}${r?` ${r}`:` `}`}function Br(e){return{text:e?.text||``,attachments:[...e?.attachments||[]]}}function Vr(e){return Br(Rr.get(e))}function Hr(e,t){if(!e)return;let n={...Vr(e),...t};if(n.attachments=[...n.attachments],Rr.delete(e),!(!n.text&&!n.attachments.length))for(Rr.set(e,n);Rr.size>Lr;){let e=Rr.keys().next().value;if(typeof e!=`string`)break;Rr.delete(e)}}function Ur(e){Rr.delete(e)}function Wr(e,t){let n=[...e.attachments],r=new Set(n.map(e=>e.id));for(let e of t.attachments){let t=e.id;if(!t||r.has(t)){let n=1;do t=`${e.id||`attachment`}-restored-${n++}`;while(r.has(t))}r.add(t),n.push({...e,id:t})}return{text:e.text&&t.text?`${e.text}\n${t.text}`:e.text||t.text,attachments:n}}function Gr(e){let t=(0,Z.useRef)(e);t.current=e;let n=(0,Z.useRef)(!0);(0,Z.useEffect)(()=>(n.current=!0,()=>{n.current=!1}),[]);let r=(0,Z.useRef)(Vr(e)),[i,a]=(0,Z.useState)(r.current.text),o=(0,Z.useCallback)(t=>Hr(e,{attachments:t}),[e]),s=jr(r.current.attachments,o),c=s.replaceAttachments,l=s.clearAttachments;return(0,Z.useEffect)(()=>{let t=Vr(e);a(t.text),c(t.attachments)},[c,e]),{value:i,updateValue:(0,Z.useCallback)(t=>{a(t),Hr(e,{text:t})},[e]),selection:s,clearDraft:(0,Z.useCallback)(()=>{let r=Vr(e);r.text!==i||r.attachments.length!==s.attachments.length||r.attachments.some((e,t)=>e!==s.attachments[t])||(Ur(e),!(!n.current||t.current!==e)&&(a(``),l()))},[l,s.attachments,e,i]),restoreDraft:(0,Z.useCallback)(r=>{let i=Wr(Vr(e),r);return Hr(e,i),!n.current||t.current!==e?!1:(a(i.text),c(i.attachments),!0)},[c,e])}}function Kr({anchor:e,menu:t,viewport:n,placement:r=`top`,align:i=`start`,maxHeight:a=1/0}){let o=n.top+8,s=Math.max(o,n.top+n.height-8),c=n.left+8,l=Math.max(c,n.left+n.width-8),u={top:Math.max(0,Math.min(e.top,s)-o-8),bottom:Math.max(0,s-Math.max(e.bottom,o)-8)},d=Math.min(t.height,a),f=r===`top`?`bottom`:`top`,p=d>u[r]&&u[f]>u[r]?f:r,m=Math.min(a,u[p]),h=Math.min(d,m),g=Math.min(t.width,l-c);return{side:p,left:Math.max(c,Math.min(i===`end`?e.right-g:e.left,l-g)),top:Math.max(o,Math.min(p===`top`?e.top-8-h:e.bottom+8,s-h)),width:g,maxHeight:m}}function qr({open:e,anchorRef:t,menuRef:n,placement:r=`top`,align:i=`start`,matchAnchorWidth:a=!1,maxHeight:o,id:s,className:c,role:l,ariaLabel:u,onClose:d,children:f}){return(0,Z.useEffect)(()=>{if(!e||!d)return;let t=e=>{e.key===`Escape`&&(e.stopPropagation(),d())};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,d]),(0,Z.useLayoutEffect)(()=>{if(!e)return;let s=()=>{let e=n.current,s=t.current;if(!e||!s)return;let c=s.getBoundingClientRect(),l=window.visualViewport;e.style.width=a?`${c.width}px`:``;let u=Kr({anchor:c,menu:{width:e.getBoundingClientRect().width,height:e.scrollHeight},viewport:{left:l?.offsetLeft??0,top:l?.offsetTop??0,width:l?.width??window.innerWidth,height:l?.height??window.innerHeight},placement:r,align:i,maxHeight:o});e.dataset.side=u.side,e.style.maxHeight=`${u.maxHeight}px`,e.style.overflowY=`auto`,e.style.width=`${u.width}px`,e.style.top=`${u.top}px`,e.style.bottom=`auto`,e.style.right=`auto`,e.style.left=`${u.left}px`};s();let c=null,l=()=>{c===null&&(c=window.requestAnimationFrame(()=>{c=null,s()}))},u=typeof ResizeObserver>`u`?null:new ResizeObserver(l);return n.current&&u?.observe(n.current),t.current&&u?.observe(t.current),window.addEventListener(`resize`,s),window.addEventListener(`scroll`,s,!0),window.visualViewport?.addEventListener(`resize`,l),window.visualViewport?.addEventListener(`scroll`,l),()=>{u?.disconnect(),c!==null&&window.cancelAnimationFrame(c),window.removeEventListener(`resize`,s),window.removeEventListener(`scroll`,s,!0),window.visualViewport?.removeEventListener(`resize`,l),window.visualViewport?.removeEventListener(`scroll`,l)}},[e,t,n,r,i,a,o]),e?(0,_r.createPortal)((0,Q.jsx)(`div`,{ref:n,id:s,className:c,style:{position:`fixed`,zIndex:65},role:l,"aria-label":u,children:f}),document.body):null}function Jr({sessionId:e,value:t,onChange:n,inputRef:r,placement:i=`top`}){let{t:a,language:o}=c(),s=(0,Z.useId)(),l=(0,Z.useRef)(null),u=t.match(/^\/([^\s]*)$/),[d,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(!1),[y,b]=(0,Z.useState)(0),x=!!(u&&d!==t),S=u?.[1]||``;(0,Z.useEffect)(()=>{f(``),m(null),v(!1)},[e]),(0,Z.useEffect)(()=>{if(!x||p)return;let t=!0;return g(!0),v(!1),Y.getSessionCommands(e).then(e=>{t&&m(e.commands||[])}).catch(()=>{t&&(m([]),v(!0))}).finally(()=>t&&g(!1)),()=>{t=!1}},[p,x,e]);let C=(0,Z.useMemo)(()=>{let e=S.toLocaleLowerCase(o);return e?(p||[]).filter(t=>`${t.invocation} ${t.name} ${t.description}`.toLocaleLowerCase(o).includes(e)):p||[]},[p,o,S]);(0,Z.useEffect)(()=>{b(0)},[S,p]);let w=()=>{f(t)},T=e=>{let i=zr(e.invocation,t);n(i),f(i),requestAnimationFrame(()=>{let e=r.current;e&&(e.focus(),e.setSelectionRange(i.length,i.length),e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,220)}px`)})};(0,Z.useEffect)(()=>{if(!x)return;let e=e=>{if(document.activeElement===r.current){if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),w();return}C.length&&(e.key===`ArrowDown`?(e.preventDefault(),e.stopPropagation(),b(e=>(e+1)%C.length)):e.key===`ArrowUp`?(e.preventDefault(),e.stopPropagation(),b(e=>(e-1+C.length)%C.length)):(e.key===`Tab`||e.key===`Enter`&&!e.shiftKey)&&(e.preventDefault(),e.stopPropagation(),T(C[Math.min(y,C.length-1)])))}};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)}),(0,Z.useEffect)(()=>{let e=r.current;if(!x||!e)return;let t={role:`combobox`,"aria-autocomplete":`list`,"aria-expanded":`true`,"aria-controls":s,"aria-activedescendant":C.length?`${s}-${Math.min(y,C.length-1)}`:``},n=Object.keys(t).map(t=>[t,e.getAttribute(t)]);for(let[n,r]of Object.entries(t))r?e.setAttribute(n,r):e.removeAttribute(n);return()=>{for(let[t,r]of n)t&&(r===null?e.removeAttribute(t):e.setAttribute(t,r))}},[y,r,s,x,C.length]);let E={user:a(`chat:commands.scope.user`),project:a(`chat:commands.scope.project`),package:a(`chat:commands.scope.package`),custom:a(`chat:commands.scope.custom`)};return(0,Q.jsx)(qr,{open:x,anchorRef:r,menuRef:l,placement:i,matchAnchorWidth:!0,maxHeight:330,id:s,role:`listbox`,ariaLabel:a(`chat:commands.open`),className:`permission-mode-menu composer-command-menu overflow-y-auto rounded-[var(--r-md)] border border-[var(--stroke)] bg-[var(--solid)] p-1.5 shadow-[0_18px_42px_-18px_var(--menu-shadow)]`,children:(0,Q.jsxs)(`div`,{className:`chat-resource-list [&_>_button]:grid [&_>_button]:w-full [&_>_button]:grid-cols-[30px_minmax(0,1fr)_auto] [&_>_button]:items-center [&_>_button]:gap-[8px] [&_>_button]:[border:1px_solid_transparent] [&_>_button]:rounded-[var(--r-sm)] [&_>_button]:bg-transparent [&_>_button]:p-[8px] [&_>_button]:text-[var(--text)] [&_>_button]:text-left [&_>_button]:cursor-pointer [&_>_button:hover]:bg-[var(--surface-hover)] [&_>_button.active]:border-[var(--focus)] [&_>_button.active]:bg-[var(--blue-soft)] [&_button_>_span:nth-child(2)]:flex [&_button_>_span:nth-child(2)]:min-w-0 [&_button_>_span:nth-child(2)]:flex-col [&_button_>_span:nth-child(2)]:gap-[2px] [&_strong]:overflow-hidden [&_strong]:text-[13px] [&_strong]:text-ellipsis [&_strong]:whitespace-nowrap [&_small]:overflow-hidden [&_small]:text-[var(--text-muted)] [&_small]:text-[11px] [&_small]:text-ellipsis [&_small]:whitespace-nowrap [&_em]:text-[var(--text-muted)] [&_em]:text-[10px] [&_em]:[font-style:normal] [&_>_p]:m-[auto] [&_>_p]:text-[var(--text-muted)] [&_>_p]:text-[12px] flex min-h-0 [flex:1_1_0] flex-col gap-[3px] overflow-y-auto [overscroll-behavior:contain] [scrollbar-gutter:stable] [touch-action:pan-y] [margin-top:9px] composer-command-list`,style:{marginTop:0},children:[C.map((e,t)=>{let n=e.source===`prompt`?me:D;return(0,Q.jsxs)(`button`,{type:`button`,role:`option`,id:`${s}-${t}`,"aria-selected":t===y,className:t===y?`active`:``,onMouseEnter:()=>b(t),onMouseDown:e=>e.preventDefault(),onClick:()=>T(e),children:[(0,Q.jsx)(`span`,{className:`list-icon [.chat-resource-list_&]:grid [.chat-resource-list_&]:w-[28px] [.chat-resource-list_&]:h-[28px] [.chat-resource-list_&]:place-items-center [.chat-resource-list_&]:rounded-[var(--r-sm)] [.chat-resource-list_&]:bg-[var(--surface-subtle)] [.chat-resource-list_&]:text-[var(--star-strong)] [.session-workflow-summary_&]:grid [.session-workflow-summary_&]:w-[28px] [.session-workflow-summary_&]:h-[28px] [.session-workflow-summary_&]:place-items-center [.session-workflow-summary_&]:rounded-[var(--r-sm)] [.session-workflow-summary_&]:bg-[var(--surface-subtle)] [.session-workflow-summary_&]:text-[var(--star-strong)] grid w-[27px] h-[27px] place-items-center rounded-[var(--r-sm)] bg-[var(--accent-soft)] text-[var(--star-strong)] [.workflow-template-gallery_&]:grid [.workflow-template-gallery_&]:w-[32px] [.workflow-template-gallery_&]:h-[32px] [.workflow-template-gallery_&]:place-items-center [.workflow-template-gallery_&]:rounded-[var(--r-sm)] [.workflow-template-gallery_&]:bg-[var(--surface-subtle)] [.workflow-template-gallery_&]:text-[var(--star-strong)]`,children:(0,Q.jsx)(n,{size:15})}),(0,Q.jsxs)(`span`,{className:`composer-command-copy`,children:[(0,Q.jsxs)(`strong`,{children:[e.invocation,e.argumentHint&&(0,Q.jsxs)(`small`,{children:[` `,e.argumentHint]})]}),(0,Q.jsx)(`small`,{children:e.description||a(`chat:commands.noDescription`)})]}),(0,Q.jsxs)(`em`,{children:[e.source===`prompt`?a(`chat:commands.prompt`):a(`chat:commands.skill`),` · `,E[e.scope]]})]},e.invocation)}),!C.length&&(0,Q.jsx)(`p`,{children:a(h?`chat:commands.loading`:_?`chat:commands.loadError`:`chat:commands.empty`)})]})})}var Yr=[`attachment`,`resource`,`visual`,`model`,`permission`,`run-mode`,`commands`,`compact-context`],Xr=new Set(Yr),Zr=new Set([`model`,`permission`,`run-mode`]),Qr={inline:[`permission`,`run-mode`,`model`],overflow:Yr.filter(e=>![`permission`,`run-mode`,`model`].includes(e))};function $r(e){return Array.isArray(e)?e.filter((e,t,n)=>typeof e==`string`&&Xr.has(e)&&n.indexOf(e)===t):[]}function ei(e){let t=e&&typeof e==`object`?e:{};if(!Array.isArray(t.inline)&&!Array.isArray(t.overflow))return{inline:[...Qr.inline],overflow:[...Qr.overflow]};let n=$r(t.inline),r=new Set(n),i=$r(t.overflow).filter(e=>!r.has(e)),a=new Set([...n,...i]);for(let e of Yr)a.has(e)||(Zr.has(e)?n.push(e):i.push(e));return{inline:n,overflow:i}}function ti(e,t,n){let r=ei(e),i=r.inline.filter(e=>e!==t),a=r.overflow.filter(e=>e!==t);return n===`inline`?i.push(t):a.push(t),{inline:i,overflow:a}}function ni(e,t){let n=ei(e),r=[...n.inline,...n.overflow];return t===`inline`?{inline:r,overflow:[]}:{inline:[],overflow:r}}function ri(e,t,n){let r=ei(e),i=r.inline.includes(t)?`inline`:`overflow`,a=[...r[i]],o=a.indexOf(t),s=o+n;return o<0||s<0||s>=a.length?r:([a[o],a[s]]=[a[s],a[o]],{...r,[i]:a})}function ii(e,t,n,r={}){let i=ei(e),a=new Set(t),o=i.inline.filter(e=>a.has(e)),s=i.overflow.filter(e=>a.has(e)),c=Number.isFinite(n)?Math.max(0,n):1/0,l=0,u=0;for(let e of o){let t=r[e]??1;if(l+t>c)break;l+=t,u+=1}let d=o.slice(0,u),f=o.slice(u);return{inline:d,automaticallyOverflowed:f,overflow:[...f,...s]}}function ai({open:e,children:t,label:n,trayId:r,anchorRef:i,menuRef:a,placement:o=`top`}){return(0,Q.jsx)(qr,{open:e,anchorRef:i,menuRef:a,placement:o,align:`start`,className:`composer-tool-tray-shell w-[272px] max-w-[calc(100vw-16px)] overflow-visible rounded-[var(--r-md)] border border-[var(--stroke)] bg-[var(--solid)] p-1.5 shadow-[0_18px_42px_-18px_var(--menu-shadow)] motion-safe:animate-in motion-safe:fade-in-0 data-[side=top]:motion-safe:slide-in-from-bottom-1 data-[side=bottom]:motion-safe:slide-in-from-top-1`,role:`toolbar`,ariaLabel:n,children:(0,Q.jsx)(`div`,{id:r,className:`composer-tool-tray flex max-h-[min(52vh,360px)] min-h-9 w-full min-w-0 flex-col items-stretch gap-1 [&>.composer-toolbar-slot]:w-full overflow-x-hidden overflow-y-auto overscroll-contain`,children:t})})}var oi=`pisper-zcode-composer-toolbar`,si=u(()=>({getItem:e=>{let t=n.getItem(e);if(t!==null)return t;let r=n.getItem(oi);if(r===null)return null;try{return JSON.parse(r),n.setItem(e,r),n.removeItem(oi),r}catch{return null}},setItem:(e,t)=>n.setItem(e,t),removeItem:e=>n.removeItem(e)})),ci=d()(l(e=>({layout:ei(void 0),setToolLocation:(t,n)=>e(e=>({layout:ti(e.layout,t,n)})),setAllToolsLocation:t=>e(e=>({layout:ni(e.layout,t)})),moveTool:(t,n)=>e(e=>({layout:ri(e.layout,t,n)})),resetLayout:()=>e({layout:ei(void 0)})}),{name:`pisper-composer-toolbar`,storage:si,version:1,partialize:({layout:e})=>({layout:e}),merge:(e,t)=>({...t,layout:ei(e&&typeof e==`object`&&`layout`in e?e.layout:void 0)})}));function li(e,t){return e.inline.join(`\0`)===t.inline.join(`\0`)&&e.overflow.join(`\0`)===t.overflow.join(`\0`)}function ui({ids:e,location:t,labels:n,onMove:r,onReorder:i,onMoveButtonRef:a}){let{t:o}=c(),s=t===`inline`?`overflow`:`inline`,l=t===`inline`?z:H,u=o(t===`inline`?`chat:focusSession.moveShortcutToOverflow`:`chat:focusSession.pinShortcutToComposer`);return(0,Q.jsx)(`ul`,{className:`divide-y divide-[var(--stroke-soft)]`,children:e.map((c,d)=>(0,Q.jsxs)(`li`,{className:`flex min-h-12 min-w-0 items-center gap-1 py-0.5`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 px-1 text-xs leading-5 text-[var(--text)]`,children:n[c]}),(0,Q.jsxs)(`div`,{className:`flex flex-none items-center`,children:[(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-sm`,className:`size-11 text-[var(--text-muted)]`,title:o(`chat:focusSession.moveShortcutEarlier`),"aria-label":o(`chat:focusSession.moveShortcutEarlierName`,{name:n[c]}),disabled:d===0,onClick:()=>i(c,-1),children:(0,Q.jsx)(ae,{})}),(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-sm`,className:`size-11 text-[var(--text-muted)]`,title:o(`chat:focusSession.moveShortcutLater`),"aria-label":o(`chat:focusSession.moveShortcutLaterName`,{name:n[c]}),disabled:d===e.length-1,onClick:()=>i(c,1),children:(0,Q.jsx)(T,{})}),(0,Q.jsxs)(J,{ref:e=>a(c,e),type:`button`,variant:`ghost`,size:`sm`,className:`h-11 min-w-11 gap-1 px-2 text-xs`,title:u,"aria-label":o(`chat:focusSession.moveShortcutName`,{name:n[c],location:u}),onClick:()=>r(c,s),children:[(0,Q.jsx)(l,{}),o(t===`inline`?`chat:focusSession.storeShortcut`:`chat:focusSession.showShortcut`)]})]})]},c))})}function di({labels:e,labeled:t=!1}){let{t:n}=c(),r=ci(e=>e.layout),i=ci(e=>e.setToolLocation),a=ci(e=>e.setAllToolsLocation),o=ci(e=>e.moveTool),s=ci(e=>e.resetLayout),l=(0,Z.useRef)(new Map),u=(0,Z.useRef)(null);(0,Z.useLayoutEffect)(()=>{u.current&&=(l.current.get(u.current)?.focus(),null)},[r]);let d=(e,t)=>{u.current=e,i(e,t)},f=(e,t)=>{t?l.current.set(e,t):l.current.delete(e)};return(0,Q.jsxs)(Pt,{children:[(0,Q.jsx)(Ot,{asChild:!0,children:(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,className:L(`h-11 gap-2 text-[var(--text-muted)]`,t?`w-full justify-start px-2 text-xs`:`w-11 px-0`),title:n(`chat:focusSession.customizeShortcuts`),"aria-label":n(`chat:focusSession.customizeShortcuts`),children:[(0,Q.jsx)(et,{}),t&&(0,Q.jsx)(`span`,{children:n(`chat:focusSession.customizeShortcuts`)})]})}),(0,Q.jsxs)(Mt,{showCloseButton:!1,overlayClassName:`z-[70]`,className:`z-[71] flex max-h-[calc(100dvh-24px)] w-[calc(100vw-24px)] max-w-[720px] flex-col gap-0 overflow-hidden rounded-xl p-0 sm:max-w-[720px]`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-none items-start gap-3 border-b border-[var(--stroke-soft)] p-4`,children:[(0,Q.jsxs)(jt,{className:`min-w-0 flex-1 gap-2 pt-1`,children:[(0,Q.jsx)(Nt,{children:n(`chat:focusSession.customizeShortcuts`)}),(0,Q.jsx)(kt,{className:`text-xs leading-5`,children:n(`chat:focusSession.customizeShortcutsDescription`)})]}),(0,Q.jsx)(At,{asChild:!0,children:(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-sm`,className:`size-11`,"aria-label":n(`common:ui.closeDialog`),children:(0,Q.jsx)(dt,{})})})]}),(0,Q.jsxs)(`div`,{className:`grid min-h-0 min-w-0 grid-cols-1 gap-5 overflow-y-auto overscroll-contain p-4 sm:grid-cols-2`,children:[(0,Q.jsxs)(`section`,{className:`min-w-0`,"aria-label":n(`chat:focusSession.composerShortcuts`),children:[(0,Q.jsxs)(`h3`,{className:`mb-1 flex h-8 items-center gap-2 text-xs font-medium text-[var(--text-secondary)]`,children:[(0,Q.jsx)(H,{size:14}),n(`chat:focusSession.composerShortcuts`),(0,Q.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:r.inline.length})]}),r.inline.length?(0,Q.jsx)(ui,{ids:r.inline,location:`inline`,labels:e,onMove:d,onReorder:o,onMoveButtonRef:f}):(0,Q.jsx)(`p`,{className:`py-4 text-xs leading-5 text-[var(--text-muted)]`,children:n(`chat:focusSession.noInlineShortcuts`)})]}),(0,Q.jsxs)(`section`,{className:`min-w-0`,"aria-label":n(`chat:focusSession.overflowShortcuts`),children:[(0,Q.jsxs)(`h3`,{className:`mb-1 flex h-8 items-center gap-2 text-xs font-medium text-[var(--text-secondary)]`,children:[(0,Q.jsx)(z,{size:14}),n(`chat:focusSession.overflowShortcuts`),(0,Q.jsx)(`span`,{className:`text-[var(--text-muted)]`,children:r.overflow.length})]}),r.overflow.length?(0,Q.jsx)(ui,{ids:r.overflow,location:`overflow`,labels:e,onMove:d,onReorder:o,onMoveButtonRef:f}):(0,Q.jsx)(`p`,{className:`py-4 text-xs leading-5 text-[var(--text-muted)]`,children:n(`chat:focusSession.noOverflowShortcuts`)})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-none flex-wrap items-center gap-x-1 border-t border-[var(--stroke-soft)] px-3 py-2`,children:[(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,className:`h-11 text-xs`,disabled:r.overflow.length===0,onClick:()=>a(`inline`),children:[(0,Q.jsx)(H,{}),n(`chat:focusSession.showAllShortcuts`)]}),(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,className:`h-11 text-xs`,disabled:r.inline.length===0,onClick:()=>a(`overflow`),children:[(0,Q.jsx)(z,{}),n(`chat:focusSession.storeAllShortcuts`)]}),(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,className:`ml-auto h-11 text-xs text-[var(--text-muted)]`,disabled:li(r,Qr),onClick:s,children:[(0,Q.jsx)(Ze,{}),n(`chat:focusSession.restoreShortcutDefaults`)]})]})]})]})}function fi(e,t){let n=t.find(t=>t.key===e);return n?`${n.providerName} · ${n.label}`:e.split(`/`).at(-1)||e}function pi({model:e,availableModels:t,sessionUsage:n,contextUsage:r}){let{t:i,language:a}=c(),o=n?.timing&&typeof n.timing==`object`?n.timing:null,s=Math.max(0,Number(o?.firstTokenSamples)||0),l=Math.max(0,Number(o?.requests)||0),u=s>0?Number(o?.firstTokenTotalMs)/s:null,d=l>0?Number(o?.durationTotalMs)/l:null,f=r?.tokens==null?null:Math.max(0,Number(r.tokens)||0),p=!!n?.cacheReported,m=[[i(`chat:focusSession.statCurrentModel`),e?fi(e,t||[]):`—`],[i(`chat:focusSession.statContextTokens`),f==null?`—`:`${X(f)} / ${X(r?.contextWindow)}`],[i(`chat:focusSession.statInputTokens`),X(n?.input)],[i(`chat:focusSession.statOutputTokens`),X(n?.output)],[i(`chat:focusSession.statCacheReadTokens`),p?X(n?.cacheRead):`—`],[i(`chat:focusSession.statCacheWriteTokens`),p?X(n?.cacheWrite):`—`],[i(`chat:focusSession.statReasoningTokens`),X(n?.reasoning)],[i(`chat:focusSession.statProcessedTokens`),X(n?.processedTokens)],[i(`chat:focusSession.statRequests`),String(Math.max(0,Number(n?.requests)||0))],[i(`chat:focusSession.statAvgFirstToken`),u==null?`—`:Re(u,a)],[i(`chat:focusSession.statAvgDuration`),d==null?`—`:Re(d,a)]];return(0,Q.jsxs)(`div`,{className:`session-stats-panel grid gap-[3px]`,"aria-label":i(`chat:focusSession.sessionStats`),children:[(0,Q.jsx)(`div`,{className:`text-[var(--text)] text-[length:var(--app-font-size)] font-semibold`,children:i(`chat:focusSession.sessionStats`)}),m.map(([e,t])=>(0,Q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-[10px] text-[length:var(--app-small-size)]`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 shrink-0 text-[var(--text-muted)]`,children:e}),(0,Q.jsx)(`strong`,{className:`min-w-0 truncate text-right font-[500] text-[var(--text)] [font-variant-numeric:tabular-nums]`,children:t})]},e)),(0,Q.jsx)(`small`,{className:`text-[var(--text-secondary)] text-[length:var(--app-small-size)] leading-normal`,children:i(`chat:focusSession.sessionStatsHint`)})]})}function mi({usage:e,plan:t,compact:n=!1}){let{t:r}=c(),i=Math.max(0,Number(e?.processedTokens)||0),a=Array.isArray(t?.items)?t.items:[],o=a.filter(e=>e?.status===`completed`).length,s=a.length?r(`chat:planBoard.progress`,{completed:o,total:a.length}):``,l=Number(e?.cacheHitRate),u=e?.cacheHitRate!=null&&Number.isFinite(l),d=u?`${Math.round(Math.max(0,l))}%`:`—`,f=u?``:r(`chat:focusSession.cacheHitRateUnavailable`),p=[r(`chat:focusSession.sessionUsageDetail`,{processed:X(i),input:X(e?.input),output:X(e?.output),cacheRead:X(e?.cacheRead),cacheWrite:X(e?.cacheWrite),reasoning:X(e?.reasoning),requests:Math.max(0,Number(e?.requests)||0)}),f,s].filter(Boolean).join(`
|
|
3
|
+
`);return(0,Q.jsxs)(`div`,{className:`session-usage-metrics [&_>_span]:inline-flex [&_>_span]:min-w-0 [&_>_span]:items-center [&_>_span]:gap-[4px] [&_>_span]:whitespace-nowrap [&_small]:text-inherit [&_small]:font-normal [&_strong]:text-[var(--text-secondary)] [&_strong]:text-[length:var(--app-small-size)] [&_strong]:[font-variant-numeric:tabular-nums] [&_strong]:font-medium [&_svg]:text-[var(--text-tertiary)] [&_svg]:opacity-[.9] [&_>_i]:w-[1px] [&_>_i]:h-[10px] [&_>_i]:bg-[var(--border-subtle,var(--stroke-soft,#ddd))] @max-[470px]:[&_small]:hidden flex min-w-0 min-h-[26px] items-center justify-start gap-[10px] m-0 text-[var(--text-secondary)] text-[length:var(--app-small-size)] ${n?`[&_small]:hidden gap-[7px]`:``}`,title:p,"aria-label":p,children:[!n&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(ar,{size:12}),(0,Q.jsx)(`small`,{children:r(`chat:focusSession.cacheHitRate`)}),(0,Q.jsx)(`strong`,{children:d})]}),(0,Q.jsx)(`i`,{"aria-hidden":`true`})]}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(pr,{size:12}),(0,Q.jsx)(`small`,{children:r(`chat:focusSession.processedTokens`)}),(0,Q.jsx)(`strong`,{children:X(i)})]}),s&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`i`,{"aria-hidden":`true`}),(0,Q.jsxs)(E,{children:[(0,Q.jsx)(C,{asChild:!0,children:(0,Q.jsxs)(`button`,{type:`button`,className:`session-plan-progress inline-flex min-w-0 items-center gap-[4px] whitespace-nowrap hover:bg-[var(--surface-hover)] hover:text-[var(--star-strong)] data-[state=open]:bg-[var(--surface-hover)] data-[state=open]:text-[var(--star-strong)] focus-visible:[outline:2px_solid_var(--accent-border)] focus-visible:[outline-offset:1px] min-h-[24px] border-0 rounded-[var(--r-xs)] bg-transparent [padding:2px_5px] text-inherit cursor-pointer`,title:r(`chat:planBoard.openCurrentPlan`,{progress:s}),"aria-label":r(`chat:planBoard.openCurrentPlan`,{progress:s}),children:[(0,Q.jsx)(Me,{size:12}),(0,Q.jsx)(`strong`,{children:s})]})}),(0,Q.jsx)(w,{className:`session-plan-popover w-[min(440px,calc(100vw_-_24px))] max-h-[min(360px,55dvh)] overflow-auto [padding:6px]`,align:`start`,side:`top`,sideOffset:7,children:(0,Q.jsx)(Ne,{plan:t??null})})]})]})]})}function hi({usage:e,sessionUsage:t,model:n,availableModels:r,onThresholdChange:i,compact:a=!1}){let{t:o}=c(),s=Number(e?.contextWindow)||0,l=e?.compactAtPercent==null?80:Number(e.compactAtPercent),u=Number.isFinite(l)?Math.round(l):80,[d,f]=(0,Z.useState)(u),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(``),_=(0,Z.useRef)(u),v=(0,Z.useRef)(void 0);if((0,Z.useEffect)(()=>{window.clearTimeout(v.current),f(u),_.current=u},[u]),(0,Z.useEffect)(()=>()=>window.clearTimeout(v.current),[]),!s)return null;let y=e?.percent!=null&&Number.isFinite(Number(e.percent)),b=y?Math.max(0,Number(e.percent)):null,x=b==null?null:Math.round(b),S=Math.max(10,u-15),T=b==null?`unknown`:b>=u?`danger`:b>=S?`warning`:`normal`,D=y?e.estimated?o(`chat:focusSession.estimatedContextUsageTokensLimitTokensPercent`,{tokens:X(e.tokens),limit:X(s),percent:x}):o(`chat:focusSession.contextUsageTokensLimitTokensPercent`,{tokens:X(e.tokens),limit:X(s),percent:x}):o(`chat:focusSession.contextUsageWillUpdateAfterTheNextModelResponseLimitLimitTokens`,{limit:X(s)}),O=e?.autoCompactEnabled?o(`chat:focusSession.autoCompactionThresholdAboutPercent`,{percent:u}):o(`chat:focusSession.automaticContextCompactionIsDisabled`),k=e?.autoCompactEnabled&&e.compactionCapacityPercent!=null?o(`chat:focusSession.contextUsageToCompactionTokensPercent`,{percent:Math.round(Number(e.compactionCapacityPercent)),tokens:X(e.remainingBeforeCompaction)}):``,A=`${D} · ${O}${k?` · ${k}`:``}`,j=`${e?.tokens==null?`—`:X(e.tokens)} / ${X(s)}`,M=async e=>{let t=Math.min(95,Math.max(10,Math.round(e)));if(f(t),!(!i||t===_.current)){m(!0),g(``);try{await i(t),_.current=t}catch(e){g(e instanceof Error?e.message:String(e))}finally{m(!1)}}},N=e=>{window.clearTimeout(v.current),f(e),v.current=window.setTimeout(()=>void M(e),250)},P=e=>{window.clearTimeout(v.current),M(e)};return(0,Q.jsxs)(E,{children:[(0,Q.jsx)(C,{asChild:!0,children:(0,Q.jsxs)(`button`,{type:`button`,className:`context-usage-chip hover:opacity-100 [&_>_svg]:opacity-[.72] [&_>_span]:inline-flex [&_>_span]:[align-items:baseline] [&_>_span]:gap-[4px] [&_>_span]:whitespace-nowrap [&_>_span_strong]:text-inherit [&_>_span_strong]:text-[length:var(--app-small-size)] [&_>_span_strong]:font-medium [&_>_span_small]:text-inherit [&_>_span_small]:font-medium [&_>_i]:block [&_>_i]:w-[24px] [&_>_i]:h-[2px] [&_>_i]:overflow-hidden [&_>_i]:rounded-[var(--r-pill)] [&_>_i]:bg-[var(--stroke-soft)] [&_>_i_>_b]:block [&_>_i_>_b]:h-full [&_>_i_>_b]:rounded-[inherit] [&_>_i_>_b]:bg-[var(--text-muted)] [&_>_i_>_b]:[transition:width_var(--d2)_var(--ease-out)] [&.warning_>_span_small]:text-[var(--warning-strong)] [&.warning_>_i_>_b]:bg-[var(--warning-strong)] [&.danger_>_span_small]:text-[var(--danger)] [&.danger_>_i_>_b]:bg-[var(--danger)] [&.unknown_>_i_>_b]:!w-[0] @max-[470px]:grid-cols-[auto_auto] @max-[470px]:[&_>_i]:hidden grid h-[24px] flex-none grid-cols-[auto_auto_24px] items-center gap-[4px] border-0 bg-transparent [padding:0_2px] text-[var(--text-secondary)] text-[length:var(--app-small-size)] cursor-pointer [transition:opacity_var(--d1)_var(--ease-out)] ${a?`!h-11 grid-cols-[auto_auto] rounded-[var(--r-sm)] bg-[var(--surface-subtle)] px-2 opacity-100 [&.warning_>_span_strong]:text-[var(--warning-strong)] [&.danger_>_span_strong]:text-[var(--danger)]`:``} ${T}`,"aria-label":A,title:A,children:[(0,Q.jsx)(sr,{size:12}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`strong`,{children:a?x==null?`—`:`${x}%`:j}),!a&&(0,Q.jsx)(`small`,{children:x==null?`—`:`${x}%`})]}),!a&&(0,Q.jsx)(`i`,{"aria-hidden":`true`,children:(0,Q.jsx)(`b`,{style:{width:`${Math.min(100,b||0)}%`}})})]})}),(0,Q.jsxs)(w,{className:`context-usage-popover [&_input[type='range']]:w-full [&_input[type='range']]:h-[20px] [&_input[type='range']]:m-0 [&_input[type='range']]:[accent-color:var(--brand-blue-strong)] [&_input[type='range']]:cursor-pointer [&_>_small]:min-h-[16px] [&_>_small]:text-[var(--text-secondary)] [&_>_small]:text-[length:var(--app-small-size)] [&_>_small]:leading-normal [&_>_small.error]:text-[var(--danger)] w-[272px] gap-[8px] [padding:12px]`,align:`end`,sideOffset:8,children:[(0,Q.jsx)(pi,{model:n,availableModels:r,sessionUsage:t,contextUsage:e}),(0,Q.jsx)(`div`,{role:`separator`,className:`h-px w-full bg-[var(--stroke-soft)]`}),k&&(0,Q.jsx)(`small`,{className:`text-[var(--text-muted)]`,children:k}),(0,Q.jsxs)(`div`,{className:`context-threshold-heading flex items-center justify-between [&_output]:text-[var(--brand-blue-strong)] [&_output]:[font-variant-numeric:tabular-nums] text-[var(--text)] text-[length:var(--app-small-size)] font-medium`,children:[(0,Q.jsx)(`span`,{children:o(`chat:focusSession.autoCompactionThreshold`)}),(0,Q.jsxs)(`output`,{children:[d,`%`]})]}),(0,Q.jsx)(`input`,{type:`range`,min:`10`,max:`95`,step:`1`,value:d,"aria-label":o(`chat:focusSession.autoCompactionThreshold`),disabled:p,onChange:e=>N(Number(e.currentTarget.value)),onBlur:e=>P(Number(e.currentTarget.value)),onPointerUp:e=>P(Number(e.currentTarget.value)),onKeyUp:e=>{[`ArrowLeft`,`ArrowRight`,`Home`,`End`,`PageUp`,`PageDown`].includes(e.key)&&P(Number(e.currentTarget.value))}}),(0,Q.jsxs)(`div`,{className:`context-threshold-scale flex items-center justify-between text-[var(--text-secondary)] text-[length:var(--app-small-size)]`,"aria-hidden":`true`,children:[(0,Q.jsx)(`span`,{children:`10%`}),(0,Q.jsx)(`span`,{children:`95%`})]}),(0,Q.jsx)(`small`,{className:h?`error`:``,children:h||(p?o(`chat:focusSession.savingCompactionThreshold`):`\xA0`)})]})]})}var gi=`relative flex h-10 min-w-0 items-center gap-1 rounded-lg px-1.5 text-[13px] text-muted-foreground hover:bg-foreground/5 hover:text-foreground focus-within:ring-2 focus-within:ring-ring`,_i=`session-model-select relative grid size-[38px] min-w-[38px] place-items-center rounded-[var(--r-sm)] bg-[var(--surface-muted)] text-[var(--text-muted)] hover:bg-[var(--star-soft)] hover:text-[var(--star-strong)] focus-within:ring-2 focus-within:ring-[var(--focus-ring)] [&.compact]:size-8 [&.compact]:min-w-8`;function vi({value:e,models:t,onChange:n,disabled:r,compact:i=!1,showLabel:a=!1,modelLabelOnly:o=!1,displayLabel:s,className:l}){let{t:u}=c(),d=t.find(t=>t.key===e),f=d?`${d.providerName} · ${d.label}`:e.split(`/`).at(-1);return(0,Q.jsxs)(`div`,{className:L(a?gi:_i,i&&`compact`,l),title:u(r?`chat:focusSession.currentModelModelCannotSwitchWhileRunning`:`chat:focusSession.currentModelModelClickToSwitch`,{model:f}),children:[a?(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:s??((o?d?.label||e.split(`/`).at(-1):f)||u(`chat:focusSession.toolbarModel`))}):(0,Q.jsx)(oe,{size:i?11:14}),(0,Q.jsxs)(x,{className:`absolute inset-0 !size-full cursor-pointer !opacity-0`,value:e,onChange:e=>n(e.target.value),disabled:r||t.length===0,"aria-label":u(`chat:focusSession.currentChatModel`),children:[!d&&(0,Q.jsx)(`option`,{value:e,children:e.split(`/`).at(-1)}),t.map(e=>(0,Q.jsxs)(`option`,{value:e.key,children:[e.providerName,` · `,e.label]},e.key))]})]})}function yi(e,t){return{off:e(`chat:focusSession.thinkingLabel.off`),minimal:e(`chat:focusSession.thinkingLabel.minimal`),low:e(`chat:focusSession.thinkingLabel.low`),medium:e(`chat:focusSession.thinkingLabel.medium`),high:e(`chat:focusSession.thinkingLabel.high`),xhigh:e(`chat:focusSession.thinkingLabel.xhigh`)}[t]||t}function bi({model:e,models:t,onModelChange:n,thinkingLevel:r,levels:i,status:a,message:o,onThinkingChange:s,modelDisabled:l,thinkingDisabled:u,deferred:d=!1,pendingModel:f=!1}){let{t:p}=c(),[m,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(!1),v=(0,Z.useRef)(!1),y=t.find(t=>t.key===e)?.label||e.split(`/`).at(-1)||p(`chat:focusSession.toolbarModel`),b=a!==`unsupported`&&i.length>0,x=Math.max(0,i.indexOf(r)),S=m??x,T=b?yi(p,i[S]||r):`—`,D=f?p(`chat:focusSession.thinkingAfterModelSwitch`):b?T:o||p(a===`unsupported`?`chat:focusSession.thinkingLevelUnsupported`:`chat:focusSession.loadingThinkingLevels`),O=u||g||!b||i.length<2,k=`${p(`chat:focusSession.modelAndThinking`)} · ${fi(e,t)} · ${D}`,A=i.join(`|`);(0,Z.useEffect)(()=>{h(null)},[e,r,A]);let j=async e=>{let t=i[e];if(!(O||v.current||!t||t===r)){v.current=!0,_(!0);try{await s(t)}finally{v.current=!1,_(!1),h(null)}}};return(0,Q.jsxs)(E,{children:[(0,Q.jsx)(C,{asChild:!0,children:(0,Q.jsxs)(`button`,{type:`button`,className:`model-effort-pill inline-flex h-8 min-w-0 max-w-[220px] items-center gap-1.5 rounded-full bg-foreground/5 px-2.5 text-xs text-muted-foreground transition-colors hover:bg-foreground/10 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":k,title:k,children:[(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:y}),(0,Q.jsx)(`span`,{className:`shrink-0`,children:b?yi(p,r||i[0]):`—`})]})}),(0,Q.jsxs)(w,{align:`end`,side:`top`,sideOffset:8,className:`model-effort-popover w-[224px] max-w-[calc(100vw_-_24px)] rounded-2xl border-border/70 bg-popover p-3 shadow-xl`,children:[(0,Q.jsx)(`div`,{className:`model-effort-model flex justify-center pb-2.5`,children:(0,Q.jsx)(vi,{showLabel:!0,value:e,models:t,onChange:n,disabled:l||g,className:`h-auto min-w-20 max-w-full bg-foreground/5 px-3 py-1.5 hover:bg-foreground/10`,displayLabel:(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-col items-center gap-0.5`,children:[(0,Q.jsx)(`span`,{className:`model-effort-heading text-base leading-5 font-semibold text-[#329bff]`,"aria-live":`polite`,children:T}),(0,Q.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-0.5 text-sm leading-5`,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:y}),(0,Q.jsx)(le,{size:14,className:`shrink-0`,"aria-hidden":`true`})]})]})})}),b&&(0,Q.jsxs)(`div`,{className:`relative h-7`,style:{"--effort-fill":`${i.length>1?S/(i.length-1)*100:0}%`},children:[(0,Q.jsxs)(`div`,{"aria-hidden":`true`,className:`effort-track absolute inset-y-1 inset-x-0 overflow-hidden rounded-full bg-foreground/10`,children:[(0,Q.jsx)(`div`,{className:`h-full bg-[#329bff]`,style:{width:`var(--effort-fill)`}}),(0,Q.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-between px-2.5`,children:i.map(e=>(0,Q.jsx)(`i`,{className:`size-1.5 rounded-full bg-foreground/20`},e))})]}),(0,Q.jsx)(`input`,{className:`effort-slider relative m-0 h-7 w-full cursor-pointer appearance-none bg-transparent disabled:cursor-default disabled:opacity-60`,type:`range`,min:0,max:Math.max(1,i.length-1),step:1,value:S,disabled:O,"aria-label":p(`chat:focusSession.currentThinkingLevel`),"aria-valuetext":T,onChange:e=>h(Number(e.currentTarget.value)),onPointerUp:e=>void j(Number(e.currentTarget.value)),onBlur:e=>void j(Number(e.currentTarget.value)),onKeyUp:e=>{[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`].includes(e.key)&&j(Number(e.currentTarget.value))}})]}),d&&(0,Q.jsx)(`p`,{className:`pt-2 text-center text-xs leading-4 text-muted-foreground`,role:`status`,children:p(`chat:focusSession.runtimeSelectionDeferred`)}),(!b||i.length===1)&&(0,Q.jsx)(`p`,{className:`pt-2 text-center text-xs leading-relaxed text-muted-foreground`,role:`status`,children:b?p(`chat:focusSession.thinkingLevelFixed`,{level:T}):D})]})]})}function xi(e){return[[`approval-required`,e(`chat:focusSession.approvalRequired`),e(`chat:focusSession.approvalRequiredShowsADiffBeforeWriting`),or],[`workspace-write`,e(`chat:focusSession.workspaceWrite`),e(`chat:focusSession.workspaceWriteRunsCommandsWithAutomaticApproval`),tr],[`full-access`,e(`chat:focusSession.fullAccess`),e(`chat:focusSession.fullAccessRunsShellWithoutPerCommandApproval`),pe]]}function Si({value:e,onChange:t,disabled:n,compact:r=!1,showLabel:i=!1}){let{t:a}=c(),[o,s]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)({left:0,top:0,width:270}),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=xi(a),m=p.find(t=>t[0]===e)||p[0],h=m[3],g=(0,Z.useCallback)(()=>{let e=d.current?.querySelector(`button`);if(!e)return;let t=e.getBoundingClientRect(),n=Math.min(270,window.innerWidth-16),r=f.current?.offsetHeight||190,i=Math.max(8,Math.min(t.right-n,window.innerWidth-n-8)),a=t.top>=r+8+8?t.top-r-8:Math.min(t.bottom+8,window.innerHeight-r-8);u({left:i,top:Math.max(8,a),width:n})},[]);(0,Z.useLayoutEffect)(()=>{if(o)return g(),window.addEventListener(`resize`,g),window.addEventListener(`scroll`,g,!0),()=>{window.removeEventListener(`resize`,g),window.removeEventListener(`scroll`,g,!0)}},[o,g]),(0,Z.useEffect)(()=>{if(!o)return;let e=e=>{let t=e.target instanceof Node?e.target:null;!d.current?.contains(t)&&!f.current?.contains(t)&&s(!1)},t=e=>{e.key===`Escape`&&s(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[o]);let _=o&&(0,_r.createPortal)((0,Q.jsxs)(`div`,{ref:f,className:`permission-mode-menu [&_>_button]:grid [&_>_button]:w-full [&_>_button]:min-h-[48px] [&_>_button]:grid-cols-[auto_minmax(0,1fr)_auto] [&_>_button]:items-center [&_>_button]:gap-[8px] [&_>_button]:border-0 [&_>_button]:rounded-[var(--r-sm)] [&_>_button]:bg-transparent [&_>_button]:text-[var(--text)] [&_>_button]:p-[6px_7px] [&_>_button]:text-left [&_>_button:hover]:bg-[var(--accent-soft)] [&_>_button.active]:bg-[var(--accent-soft)] [&_>_button_>_span:nth-child(2)]:flex [&_>_button_>_span:nth-child(2)]:min-w-0 [&_>_button_>_span:nth-child(2)]:flex-col [&_>_button_>_span:nth-child(2)]:gap-[2px] [&_strong]:text-[length:var(--app-font-size)] [&_strong]:font-medium [&_small]:text-[var(--text-secondary)] [&_small]:font-normal [&_small]:text-[length:var(--app-small-size)] [&_small]:leading-normal [&_>_button_>_svg]:text-[var(--star-strong)] absolute z-[35] right-0 [bottom:calc(100%_+_8px)] w-[250px] overflow-hidden [border:1px_solid_var(--stroke)] rounded-[var(--r-md)] bg-[var(--solid)] [padding:5px] shadow-[0_18px_42px_-18px_var(--menu-shadow)] execution-mode-menu !fixed !right-auto !bottom-auto z-[80]`,style:l,role:`menu`,children:[(0,Q.jsx)(`div`,{className:`[padding:6px_8px_4px] text-[var(--text-secondary)] text-[length:var(--app-small-size)] font-semibold`,children:a(`chat:focusSession.approvalMode`)}),p.map(([e,n,r,i])=>(0,Q.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e===m[0],className:e===m[0]?`active`:``,onClick:()=>{t(e),s(!1)},children:[(0,Q.jsx)(`span`,{className:`permission-level [&.level-auto]:bg-[var(--accent-soft)] [&.level-auto]:text-[var(--star-strong)] [&.level-ignore]:bg-[var(--danger-soft)] [&.level-ignore]:text-[var(--danger)] [&.level-full-access]:bg-[var(--danger-soft)] [&.level-full-access]:text-[var(--danger)] grid w-[32px] h-[32px] place-items-center rounded-[var(--r-sm)] bg-[var(--surface-muted)] text-[var(--text-muted)] level-${e}`,children:(0,Q.jsx)(i,{size:13})}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`strong`,{children:n}),(0,Q.jsx)(`small`,{children:r})]}),e===m[0]&&(0,Q.jsx)(se,{size:13})]},e))]}),document.body);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{ref:d,className:`permission-mode-select relative min-w-0 shrink-0 ${r?`compact`:``} ${o?`open`:``}`,children:(0,Q.jsxs)(`button`,{type:`button`,className:`permission-mode-trigger inline-flex h-10 min-w-0 items-center justify-center gap-1.5 rounded-lg bg-transparent px-1.5 text-[13px] transition-colors hover:bg-foreground/5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-55 ${i?`max-w-[104px] min-[651px]:max-w-[124px]`:`w-[38px]`} ${m[0]===`full-access`?`text-orange-600 dark:text-orange-400`:`text-muted-foreground`} mode-${m[0]}`,title:a(`chat:focusSession.approvalModeModeDescription`,{mode:m[1],description:m[2]}),disabled:n,"aria-haspopup":`menu`,"aria-expanded":o,"aria-label":a(`chat:focusSession.approvalModeMode`,{mode:m[1]}),onClick:()=>s(e=>!e),children:[(0,Q.jsx)(h,{className:`shrink-0 ${i?`max-[650px]:hidden`:``}`,size:i?16:r?11:14}),i&&(0,Q.jsx)(`span`,{className:`truncate`,children:m[1]})]})}),_]})}var Ci=1e3;function wi({mode:e,goal:t,tokenBudget:n,onTokenBudgetChange:r,onSaveTokenBudget:i,onChange:a,teamAvailable:o=!1,disabled:s=!1}){let{t:l}=c(),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(!1),m=(0,Z.useRef)(null),h=(0,Z.useRef)(null),g=(0,Z.useRef)(null),_=t?.status===`active`,v=!!t?.id,y=_?t?.mode===`team`&&o?`team`:`goal`:e,b=y===`team`?t?.teamTokenBudget:t?.tokenBudget,x=b==null?null:Number(b)>0?Number(b):null,S=n!==x,C=[{value:`plan`,label:l(`chat:focusSession.planMode`),description:l(`chat:focusSession.planModeDescription`),icon:Me},{value:`goal`,label:l(`chat:focusSession.goalMode`),description:l(`chat:focusSession.goalModeDescription`),icon:mr},...o?[{value:`team`,label:l(`chat:focusSession.teamMode`),description:l(`chat:focusSession.teamModeDescription`),icon:gr}]:[]],w=C.find(e=>e.value===y)||C[0],T=w.icon,E=y===`plan`?w.description:_?l(y===`team`?`chat:focusSession.runningAsTeam`:`chat:focusSession.runningAutonomously`):t?.status===`paused`?l(`chat:focusSession.theNextMessageWillResumeTheGoal`):t?.status===`complete`?l(`chat:focusSession.goalComplete`):t?.status===`budget_limited`?l(`chat:focusSession.goalReachedItsBudget`):l(`chat:focusSession.theNextMessageWillStartAGoal`),D=y===`plan`?w.description:E,O=l(`chat:focusSession.goalTokenBudgetUnlimited`),k=v?x==null?l(`chat:focusSession.usedUnlimitedGoalTokens`,{used:X(t?.tokensUsed)}):l(`chat:focusSession.usedBudgetTokensUsed`,{used:t?.tokensUsed||0,budget:x||0}):``,A=[l(`chat:focusSession.executionMode`),w.label,D,k].filter(Boolean).join(` · `),j=(0,Z.useCallback)(()=>{d(!1),h.current?.focus()},[]);(0,Z.useLayoutEffect)(()=>{u&&g.current?.querySelector(`[aria-checked="true"]`)?.focus()},[u]),(0,Z.useEffect)(()=>{if(!u)return;let e=e=>{let t=e.target instanceof Node?e.target:null;!m.current?.contains(t)&&!g.current?.contains(t)&&d(!1)};return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[u]);let M=async()=>{if(!(f||!S||!v||!i)){p(!0);try{await i(n)}finally{p(!1)}}};return(0,Q.jsxs)(`div`,{ref:m,className:`task-execution-mode-select relative h-10 min-w-0 text-muted-foreground ${u?`open`:``} ${y===`plan`?``:`active`}`,children:[(0,Q.jsxs)(`button`,{ref:h,type:`button`,className:`task-execution-mode-trigger hover:border-[var(--accent-border)] hover:bg-[var(--accent-soft)] hover:text-[var(--star-strong)] [.task-execution-mode-select.open_&]:border-[var(--accent-border)] [.task-execution-mode-select.open_&]:bg-[var(--accent-soft)] [.task-execution-mode-select.open_&]:text-[var(--star-strong)] [.task-execution-mode-select.active_&]:text-[var(--star-strong)] inline-flex w-full h-full items-center justify-center gap-1.5 px-1.5 rounded-lg border-0 bg-transparent text-[13px] text-inherit cursor-pointer disabled:cursor-not-allowed disabled:opacity-[.55]`,title:A,"aria-label":A,"aria-haspopup":`menu`,"aria-expanded":u,disabled:s,onClick:()=>d(e=>!e),children:[(0,Q.jsx)(T,{className:`shrink-0 max-[650px]:hidden`,size:15}),(0,Q.jsx)(`span`,{className:`truncate`,children:w.label})]}),u&&(0,Q.jsxs)(qr,{open:u,anchorRef:h,menuRef:g,placement:`top`,className:`anchored-popup-menu task-execution-mode-menu [&_strong]:text-[length:var(--app-font-size)] [&_strong]:font-medium [&_small]:overflow-hidden [&_small]:text-[var(--text-secondary)] [&_small]:text-[length:var(--app-small-size)] [&_small]:font-normal [&_small]:text-ellipsis [&_small]:whitespace-nowrap [&_p]:m-[1px_7px_4px_47px] [&_p]:text-[var(--text-secondary)] [&_p]:text-[length:var(--app-small-size)] w-[min(270px,calc(100vw_-_28px))] overflow-hidden [border:1px_solid_var(--stroke)] rounded-[var(--r-md)] bg-[var(--solid)] [padding:5px] shadow-[0_18px_42px_-18px_var(--menu-shadow)]`,role:`menu`,ariaLabel:l(`chat:focusSession.executionMode`),onClose:j,children:[(0,Q.jsx)(`div`,{className:`[padding:6px_8px_4px] text-[var(--text-secondary)] text-[length:var(--app-small-size)] font-semibold`,children:l(`chat:focusSession.executionMode`)}),C.map(e=>{let t=e.icon,n=e.value===y;return(0,Q.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":n,className:`task-execution-mode-option hover:bg-[var(--accent-soft)] [&_>_span:nth-child(2)]:flex [&_>_span:nth-child(2)]:min-w-0 [&_>_span:nth-child(2)]:flex-col [&_>_span:nth-child(2)]:gap-[2px] grid w-full min-h-[48px] grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-[8px] border-0 rounded-[var(--r-sm)] bg-transparent [padding:6px_7px] text-left ${n?`bg-[var(--accent-soft)]`:``}`,onClick:()=>{a(e.value),j()},children:[(0,Q.jsx)(`span`,{className:`grid w-[32px] h-[32px] place-items-center rounded-[var(--r-sm)] bg-[var(--surface-muted)] text-[var(--text-muted)]`,children:(0,Q.jsx)(t,{size:14})}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`strong`,{children:e.label}),(0,Q.jsx)(`small`,{children:e.description})]}),n&&(0,Q.jsx)(se,{size:13})]},e.value)}),(y===`goal`||y===`team`||v)&&(0,Q.jsxs)(Q.Fragment,{children:[k&&(0,Q.jsx)(`p`,{children:k}),(0,Q.jsxs)(`div`,{className:`goal-mode-budget-row [&_label]:text-[var(--text-secondary)] [&_label]:text-[length:var(--app-small-size)] [&_label]:font-medium [&_input]:w-full [&_input]:min-w-0 [&_input]:[border:1px_solid_var(--stroke)] [&_input]:rounded-[var(--r-sm)] [&_input]:bg-[var(--surface-muted)] [&_input]:p-[5px_7px] [&_input]:text-inherit [&_input]:text-[length:var(--app-font-size)] [&_input:focus]:border-[var(--focus)] [&_input:focus]:[outline:none] grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-[6px] [margin:2px_7px_2px]`,children:[(0,Q.jsx)(`label`,{htmlFor:`goal-token-budget-input`,children:l(y===`team`?`chat:focusSession.teamTokenBudget`:`chat:focusSession.goalTokenBudget`)}),(0,Q.jsx)(`input`,{id:`goal-token-budget-input`,type:`number`,min:Ci,step:1e3,value:n??``,placeholder:O,"aria-label":l(y===`team`?`chat:focusSession.teamTokenBudget`:`chat:focusSession.goalTokenBudget`),disabled:f,onChange:e=>{let t=e.target.value.trim();if(!t){r(null);return}let n=Number(t);Number.isFinite(n)&&r(Math.max(Ci,Math.round(n)))}}),v&&S&&(0,Q.jsxs)(J,{type:`button`,variant:`outline`,className:`bg-surface-subtle`,disabled:f,onClick:()=>void M(),children:[f?(0,Q.jsx)(Xe,{className:`animate-spin`,size:12}):(0,Q.jsx)(se,{size:12}),l(`chat:focusSession.goalBudgetSave`)]})]}),(0,Q.jsx)(`small`,{className:`block [margin:0_7px_5px] text-[var(--text-secondary)] text-[length:var(--app-small-size)]`,children:l(y===`team`?`chat:focusSession.teamTokenBudgetHint`:v?`chat:focusSession.goalTokenBudgetUpdateHint`:`chat:focusSession.goalTokenBudgetHint`)})]})]})]})}var Ti=new Set([`user`,`assistant`,`summary`,`compaction`,`position`]),Ei=new Set([`tool`,`tool-call`]);function Di(e){let t=[],n=new Map;for(let r of e){let e=r.parentId?n.get(r.parentId):void 0,i={...r,children:[]};n.set(r.id,i),e?e.children.push(i):t.push(i)}return t}function Oi(e){let t=[],n=[...e].reverse();for(;n.length>0;){let e=n.pop();if(e){t.push(e);for(let t=e.children.length-1;t>=0;--t)n.push(e.children[t])}}return t}function ki(e,t){let n=[],r=new Map;for(let i of Oi(e)){let e=i.parentId&&r.get(i.parentId)||null;if(!t(i)){r.set(i.id,e);continue}let a={...i,children:[]};r.set(i.id,a),e?e.children.push(a):n.push(a)}return n}function Ai(e){let t=[e],n=e;for(;n.children.length===1;)n=n.children[0],t.push(n);let r={id:e.id,nodes:t,children:[],active:t.some(e=>e.active)},i=[{segment:r,children:n.children}];for(;i.length>0;){let e=i.pop();if(e)for(let t of e.children){let n=[t],r=t;for(;r.children.length===1;)r=r.children[0],n.push(r);let a={id:t.id,nodes:n,children:[],active:n.some(e=>e.active)};e.segment.children.push(a),i.push({segment:a,children:r.children})}}return r}function ji(e){return e.kind===`user`?ve:e.kind===`assistant`?oe:e.kind===`tool`||e.kind===`tool-call`?ut:e.kind===`settings`?$e:e.kind===`label`?rt:e.kind===`summary`||e.kind===`compaction`?me:e.kind===`position`?k:e.label?rr:We}function Mi({nodes:e,viewportRef:t,selectedId:n,typeLabel:r,stateLabel:i,onSelect:a}){let o=bn({count:e.length,getScrollElement:()=>t.current,estimateSize:()=>64,getItemKey:t=>e[t]?.id??`mobile-tree-node-${t}`,overscan:12,useAnimationFrameWithResizeObserver:!0});return(0,Z.useEffect)(()=>{if(!n)return;let t=e.findIndex(e=>e.id===n);t>=0&&o.scrollToIndex(t,{align:`center`})},[e,n,o]),(0,Q.jsx)(`div`,{className:`relative w-full`,style:{height:`${o.getTotalSize()}px`},children:o.getVirtualItems().map(t=>{let o=e[t.index],s=ji(o);return(0,Q.jsx)(`div`,{className:`absolute top-0 left-0 w-full px-[12px] py-[4px]`,style:{transform:`translateY(${t.start}px)`},children:(0,Q.jsxs)(`button`,{type:`button`,className:`session-tree-node hover:border-[var(--stroke-hover)] hover:bg-[var(--solid)] [&.selected]:border-[var(--focus)] [&.selected]:bg-[var(--solid)] [&.selected]:shadow-[0_0_0_2px_var(--focus-ring)] grid min-h-[56px] w-full grid-cols-[34px_minmax(0,1fr)_auto] items-center gap-[8px] [border:1px_solid_var(--stroke-soft)] rounded-[var(--r-sm)] bg-[var(--solid)] p-[7px_9px_7px_4px] text-left ${o.id===n?` selected`:``}${o.active?` active`:``}${o.leaf?` leaf`:``}`,"data-kind":o.kind,"data-pisper-tree-entry":o.id,onClick:()=>a(o.id),children:[(0,Q.jsx)(`span`,{className:`session-tree-marker [.session-tree-node[data-kind='user']_&]:bg-[var(--star-soft)] [.session-tree-node[data-kind='user']_&]:text-[var(--star-strong)] [.session-tree-node[data-kind='assistant']_&]:bg-[var(--brand-blue-soft)] [.session-tree-node[data-kind='assistant']_&]:text-[var(--brand-blue-strong)] [.session-tree-node[data-kind='tool']_&]:bg-[var(--warning-soft)] [.session-tree-node[data-kind='tool']_&]:text-[var(--warning-strong)] [.session-tree-node.active_&]:border-[var(--brand-blue-border)] [.session-tree-node.leaf_&]:bg-[var(--star)] [.session-tree-node.leaf_&]:text-[var(--on-accent)] grid size-[28px] place-items-center justify-self-center [border:2px_solid_var(--surface-subtle)] rounded-full bg-[var(--surface-muted)] text-[var(--text-muted)]`,children:(0,Q.jsx)(s,{size:14})}),(0,Q.jsxs)(`span`,{className:`session-tree-node-copy flex min-w-0 flex-col gap-[2px] [&_small]:overflow-hidden [&_small]:text-ellipsis [&_small]:whitespace-nowrap [&_small]:text-[10px] [&_small]:text-[var(--text-muted)] [&_strong]:overflow-hidden [&_strong]:text-ellipsis [&_strong]:whitespace-nowrap [&_strong]:text-[12px] [&_strong]:font-[650]`,children:[(0,Q.jsx)(`strong`,{children:o.label||o.text||r(o)}),(0,Q.jsx)(`small`,{children:o.label&&o.text?o.text:r(o)})]}),(0,Q.jsxs)(`span`,{className:`session-tree-node-state [.session-tree-node.active_&]:text-[var(--brand-blue-strong)] [.session-tree-node.leaf_&]:text-[var(--brand-blue-strong)] inline-flex items-center gap-[4px] text-[9px] text-[var(--text-muted)] [text-transform:uppercase]`,children:[o.label&&(0,Q.jsx)(rr,{size:12}),i(o)]})]})},t.key)})})}function Ni({segment:e,viewportRef:t,selectedId:n,typeLabel:r,stateLabel:i,onSelect:a}){let{nodes:o,children:s}=e,c=o.length>120,l=bn({count:o.length,getScrollElement:()=>t.current,estimateSize:()=>56,getItemKey:e=>o[e]?.id??`tree-node-${e}`,overscan:12,scrollMargin:26,enabled:c,useAnimationFrameWithResizeObserver:!0}),u=e=>{let t=ji(e);return(0,Q.jsxs)(`button`,{type:`button`,className:`session-tree-node hover:border-[var(--stroke-hover)] hover:bg-[var(--solid)] [&.selected]:border-[var(--focus)] [&.selected]:bg-[var(--solid)] [&.selected]:shadow-[0_0_0_2px_var(--focus-ring),0_8px_20px_-18px_var(--shadow)] relative z-[1] grid w-[220px] min-h-[48px] grid-cols-[30px_minmax(0,1fr)_auto] items-center gap-[8px] [border:1px_solid_var(--stroke-soft)] rounded-[var(--r-sm)] bg-[color-mix(in_srgb,var(--solid)_94%,transparent)] text-[var(--text)] [padding:6px_8px_6px_2px] text-left shadow-[0_4px_14px_-13px_var(--shadow)] cursor-pointer ${e.id===n?` selected`:``}${e.active?` active`:``}${e.leaf?` leaf`:``}`,"data-kind":e.kind,"data-pisper-tree-entry":e.id,onClick:()=>a(e.id),children:[(0,Q.jsx)(`span`,{className:`session-tree-marker [.session-tree-node[data-kind='user']_&]:bg-[var(--star-soft)] [.session-tree-node[data-kind='user']_&]:text-[var(--star-strong)] [.session-tree-node[data-kind='assistant']_&]:bg-[var(--brand-blue-soft)] [.session-tree-node[data-kind='assistant']_&]:text-[var(--brand-blue-strong)] [.session-tree-node[data-kind='tool']_&]:bg-[var(--warning-soft)] [.session-tree-node[data-kind='tool']_&]:text-[var(--warning-strong)] [.session-tree-node[data-kind='summary']_&]:bg-[var(--violet-soft)] [.session-tree-node[data-kind='summary']_&]:text-[var(--violet-strong)] [.session-tree-node[data-kind='compaction']_&]:bg-[var(--violet-soft)] [.session-tree-node[data-kind='compaction']_&]:text-[var(--violet-strong)] [.session-tree-node.active_&]:border-[var(--brand-blue-border)] [.session-tree-node.active_&]:shadow-[0_0_0_2px_var(--brand-blue-soft)] [.session-tree-node.leaf_&]:bg-[var(--star)] [.session-tree-node.leaf_&]:text-[var(--on-accent)] [.session-tree-mark.active_&]:border-[var(--brand-blue-border)] [.session-tree-mark.active_&]:shadow-[0_0_0_2px_var(--brand-blue-soft)] relative z-[2] grid w-[26px] h-[26px] place-items-center [justify-self:center] [border:2px_solid_var(--surface-subtle)] rounded-[50%] bg-[var(--surface-muted)] text-[var(--text-muted)]`,children:(0,Q.jsx)(t,{size:14})}),(0,Q.jsxs)(`span`,{className:`session-tree-node-copy [&_strong]:overflow-hidden [&_strong]:text-ellipsis [&_strong]:whitespace-nowrap [&_small]:overflow-hidden [&_small]:text-ellipsis [&_small]:whitespace-nowrap [&_strong]:text-[12px] [&_strong]:font-[650] [&_small]:text-[var(--text-muted)] [&_small]:text-[10px] flex min-w-0 flex-col gap-[2px]`,children:[(0,Q.jsx)(`strong`,{children:e.label||e.text||r(e)}),(0,Q.jsx)(`small`,{children:e.label&&e.text?e.text:r(e)})]}),(0,Q.jsxs)(`span`,{className:`session-tree-node-state [.session-tree-node.active_&]:text-[var(--brand-blue-strong)] [.session-tree-node.leaf_&]:text-[var(--brand-blue-strong)] inline-flex min-w-0 items-center gap-[4px] text-[var(--text-muted)] text-[9px] [text-transform:uppercase]`,children:[e.label&&(0,Q.jsx)(rr,{size:12}),i(e)]})]},e.id)};return(0,Z.useEffect)(()=>{if(!c||!n)return;let e=o.findIndex(e=>e.id===n);e<0||l.scrollToIndex(e,{align:`center`})},[n,o,c,l]),(0,Q.jsxs)(`div`,{className:`session-tree-segment relative flex min-w-[220px] flex-col items-center ${e.active?` active`:``}`,children:[(0,Q.jsx)(`div`,{className:`session-tree-track before:absolute before:z-[0] before:top-[22px] before:bottom-[22px] before:left-[50%] before:w-[2px] before:rounded-[var(--r-pill)] before:bg-[var(--stroke)] before:[content:''] before:[transform:translateX(-1px)] [.session-tree-segment.active_>_&::before]:bg-[color-mix(in_srgb,var(--brand-blue)_64%,var(--stroke))] relative z-[1] grid w-[220px] gap-[8px]`,children:c?(0,Q.jsx)(`div`,{className:`relative w-[220px]`,style:{height:`${l.getTotalSize()}px`},children:l.getVirtualItems().map(e=>(0,Q.jsx)(`div`,{className:`absolute top-0 left-0 w-[220px]`,style:{top:`${e.start-26}px`},children:u(o[e.index])},e.key))}):o.map(u)}),s.length>0&&(0,Q.jsx)(`div`,{className:`session-tree-children before:absolute before:top-0 before:left-[50%] before:w-[2px] before:h-[14px] before:rounded-[var(--r-pill)] before:bg-[var(--stroke)] before:[content:''] before:[transform:translateX(-1px)] [.session-tree-segment.active_>_&::before]:bg-[color-mix(in_srgb,var(--brand-blue)_64%,var(--stroke))] relative flex items-start justify-center [margin-top:0] [padding-top:28px]`,children:s.map(e=>(0,Q.jsx)(`div`,{className:`session-tree-child before:absolute before:top-0 before:w-[50%] before:h-[14px] before:[border-top:2px_solid_var(--stroke)] before:[content:''] after:absolute after:top-0 after:w-[50%] after:h-[14px] after:[border-top:2px_solid_var(--stroke)] after:[content:''] before:right-[50%] after:left-[50%] after:[border-left:2px_solid_var(--stroke)] [&:first-child::before]:[border-top-color:transparent] [&:last-child::after]:[border-top-color:transparent] [&.active::before]:border-[color-mix(in_srgb,var(--brand-blue)_64%,var(--stroke))] [&.active::after]:border-[color-mix(in_srgb,var(--brand-blue)_64%,var(--stroke))] [&.active:first-child::before]:[border-top-color:transparent] [&.active:last-child::after]:[border-top-color:transparent] relative flex [padding:14px_12px_0]${e.active?` active`:``}`,children:(0,Q.jsx)(Ni,{segment:e,viewportRef:t,selectedId:n,typeLabel:r,stateLabel:i,onSelect:a})},e.id))})]})}function Pi({view:e,onViewChange:t,query:n,onQueryChange:r,loading:i,error:a,mobileLayout:o,viewportRef:s,segments:l,visibleNodes:u,selectedId:d,typeLabel:f,stateLabel:p,onSelect:m,visibleMarks:h,marksLoading:g,openingMark:_,onOpenMark:v}){let{t:y,language:b}=c(),x=e=>{let t=Date.parse(e);return Number.isFinite(t)?new Intl.DateTimeFormat(b,{dateStyle:`medium`,timeStyle:`short`}).format(t):y(`navigation:appOverlays.unknownTime`)};return(0,Q.jsxs)(`div`,{className:`chat-resource-browser flex min-h-0 min-w-0 flex-col bg-transparent session-tree-browser`,children:[(0,Q.jsx)(N,{className:`chat-resource-tabs w-full [padding:12px_12px_0] session-tree-tabs [&_[data-slot='tabs-list']]:grid [&_[data-slot='tabs-list']]:h-[36px] [&_[data-slot='tabs-list']]:w-full [&_[data-slot='tabs-list']]:grid-cols-[repeat(4,minmax(0,1fr))] [&_[data-slot='tabs-list']]:[border:1px_solid_var(--stroke-soft)] [&_[data-slot='tabs-list']]:rounded-[var(--r-sm)] [&_[data-slot='tabs-list']]:bg-[var(--surface-muted)] [&_[data-slot='tabs-trigger']]:min-w-0 [&_[data-slot='tabs-trigger']]:gap-[5px] [&_[data-slot='tabs-trigger']]:rounded-[var(--r-xs)] [&_[data-slot='tabs-trigger']]:[padding-inline:6px] [&_[data-slot='tabs-trigger']]:text-[11px] [&_[data-slot='tabs-trigger'][data-state='active']]:bg-[var(--solid)] [&_[data-slot='tabs-trigger'][data-state='active']]:text-[var(--text)]`,value:e,onValueChange:e=>t(e),children:(0,Q.jsxs)(M,{children:[(0,Q.jsx)(j,{value:`conversation`,children:y(`chat:sessionTree.conversation`)}),(0,Q.jsx)(j,{value:`labeled`,children:y(`chat:sessionTree.labeled`)}),(0,Q.jsx)(j,{value:`all`,children:y(`chat:sessionTree.all`)}),(0,Q.jsx)(j,{value:`marks`,children:y(`chat:sessionTree.allMarks`)})]})}),(0,Q.jsxs)(`label`,{className:`chat-resource-search [&:focus-within]:border-[var(--focus)] [&:focus-within]:shadow-[0_0_0_2px_var(--focus-ring)] [&_input]:w-full [&_input]:h-[36px] [&_input]:border-0 [&_input]:[outline:0]! [&_input]:bg-transparent [&_input]:text-[var(--text)] [&_input]:text-[13px] flex items-center gap-[7px] [margin-top:8px] [border:1px_solid_var(--stroke)] rounded-[var(--r-sm)] [padding:0_10px] text-[var(--text-muted)] flex-none [margin:8px_12px_0] bg-[var(--solid)]`,children:[(0,Q.jsx)(Qe,{size:15}),(0,Q.jsx)(`input`,{value:n,disabled:!!_,onChange:e=>r(e.target.value),placeholder:y(`chat:sessionTree.searchPlaceholder`)})]}),e===`marks`?(0,Q.jsxs)(`div`,{className:`flex min-w-0 min-h-0 [flex:1_1_0] flex-col gap-[8px] overflow-auto [overscroll-behavior:contain] [padding:12px_14px]`,"data-testid":`session-tree-marks-list`,children:[a&&(0,Q.jsx)(`p`,{className:`danger-text [margin:0_2px]`,children:a}),g?(0,Q.jsx)(`p`,{className:`grid min-h-[180px] place-items-center text-[var(--text-muted)] text-[12px]`,children:y(`chat:sessionTree.loadingMarks`)}):h.length?h.map(e=>(0,Q.jsxs)(`button`,{type:`button`,className:`session-tree-mark hover:border-[var(--stroke-hover)] hover:bg-[var(--solid)] [&.active]:border-[var(--brand-blue-border)] [&_>_em]:rounded-[var(--r-xs)] [&_>_em]:bg-[var(--brand-blue-soft)] [&_>_em]:text-[var(--brand-blue-strong)] [&_>_em]:p-[2px_6px] [&_>_em]:text-[10px] [&_>_em]:[font-style:normal] grid grid-cols-[30px_minmax(0,1fr)_auto] items-center gap-[8px] [border:1px_solid_var(--stroke-soft)] rounded-[var(--r-sm)] bg-[color-mix(in_srgb,var(--solid)_94%,transparent)] text-[var(--text)] [padding:8px_10px_8px_4px] text-left cursor-pointer ${e.active?` active`:``}`,disabled:!!_,"aria-busy":_===e,onClick:()=>v(e),children:[(0,Q.jsx)(`span`,{className:`session-tree-marker [.session-tree-node[data-kind='user']_&]:bg-[var(--star-soft)] [.session-tree-node[data-kind='user']_&]:text-[var(--star-strong)] [.session-tree-node[data-kind='assistant']_&]:bg-[var(--brand-blue-soft)] [.session-tree-node[data-kind='assistant']_&]:text-[var(--brand-blue-strong)] [.session-tree-node[data-kind='tool']_&]:bg-[var(--warning-soft)] [.session-tree-node[data-kind='tool']_&]:text-[var(--warning-strong)] [.session-tree-node[data-kind='summary']_&]:bg-[var(--violet-soft)] [.session-tree-node[data-kind='summary']_&]:text-[var(--violet-strong)] [.session-tree-node[data-kind='compaction']_&]:bg-[var(--violet-soft)] [.session-tree-node[data-kind='compaction']_&]:text-[var(--violet-strong)] [.session-tree-node.active_&]:border-[var(--brand-blue-border)] [.session-tree-node.active_&]:shadow-[0_0_0_2px_var(--brand-blue-soft)] [.session-tree-node.leaf_&]:bg-[var(--star)] [.session-tree-node.leaf_&]:text-[var(--on-accent)] [.session-tree-mark.active_&]:border-[var(--brand-blue-border)] [.session-tree-mark.active_&]:shadow-[0_0_0_2px_var(--brand-blue-soft)] relative z-[2] grid w-[26px] h-[26px] place-items-center [justify-self:center] [border:2px_solid_var(--surface-subtle)] rounded-[50%] bg-[var(--surface-muted)] text-[var(--text-muted)]`,children:_===e?(0,Q.jsx)(Ue,{className:`size-3.5 animate-spin`,"aria-hidden":`true`}):(0,Q.jsx)(rt,{size:14})}),(0,Q.jsxs)(`span`,{className:`session-tree-node-copy [&_strong]:overflow-hidden [&_strong]:text-ellipsis [&_strong]:whitespace-nowrap [&_small]:overflow-hidden [&_small]:text-ellipsis [&_small]:whitespace-nowrap [&_strong]:text-[12px] [&_strong]:font-[650] [&_small]:text-[var(--text-muted)] [&_small]:text-[10px] flex min-w-0 flex-col gap-[2px]`,children:[(0,Q.jsx)(`strong`,{children:e.label}),(0,Q.jsx)(`small`,{children:e.sessionName||y(`navigation:appOverlays.untitledChat`)}),(0,Q.jsx)(`small`,{children:y(`chat:sessionTree.markTimes`,{sessionTime:x(e.sessionModified),nodeTime:x(e.nodeTimestamp)})})]}),_===e?(0,Q.jsx)(`em`,{children:y(`chat:sessionTree.navigating`)}):e.active&&(0,Q.jsx)(`em`,{children:y(`chat:sessionTree.markActive`)})]},`${e.sessionId}:${e.entryId}`)):(0,Q.jsx)(`p`,{className:`grid min-h-[180px] place-items-center text-[var(--text-muted)] text-[12px]`,children:y(`chat:sessionTree.noMarksYet`)})]}):(0,Q.jsx)(`div`,{className:`min-w-0 min-h-0 [flex:1_1_0] overflow-auto [overscroll-behavior:contain] [scrollbar-gutter:stable]`,"data-testid":`session-tree-list`,ref:s,children:l.length>0?o?(0,Q.jsx)(Mi,{nodes:u,viewportRef:s,selectedId:d,typeLabel:f,stateLabel:p,onSelect:m}):(0,Q.jsx)(`div`,{className:`session-tree-canvas flex w-[max-content] min-w-[100%] items-start justify-center gap-[36px] [padding:26px_28px_48px]`,children:l.map(e=>(0,Q.jsx)(Ni,{segment:e,viewportRef:s,selectedId:d,typeLabel:f,stateLabel:p,onSelect:m},e.id))}):(0,Q.jsx)(`p`,{className:`grid min-h-[180px] place-items-center text-[var(--text-muted)] text-[12px]`,children:i?y(`chat:sessionTree.loading`):a||y(`chat:sessionTree.empty`)})})]})}function Fi({mobileLayout:e,selected:t,loading:n,error:r,streaming:i,dataStreaming:a,parentSession:o,parentEntryId:s,childSessions:l,canLabel:u,canDerive:d,label:f,summarize:p,savingLabel:m,creatingChild:h,navigating:g,openingRelatedId:_,typeLabel:v,stateLabel:y,onBackToList:b,onLabelChange:x,onSummarizeChange:C,onSaveLabel:w,onRemoveLabel:T,onCreateChild:E,onNavigate:D,onRefresh:O,onOpenRelated:A}){let{t:j,language:M}=c();return(0,Q.jsxs)(`div`,{className:`chat-resource-config flex min-h-0 min-w-0 flex-col gap-[16px] overflow-y-auto [overscroll-behavior:contain] [padding:18px] session-tree-inspector [&_>_p]:m-[auto] [&_>_p]:text-[12px] [&_>_p]:text-[var(--text-muted)] [&_strong]:text-[14px] [&_p]:text-[12px] [&_p]:text-[var(--text-muted)] ${e?`bg-[var(--solid)]`:`[margin:12px_12px_12px_0] rounded-[var(--r-md)] bg-[color-mix(in_srgb,var(--solid)_88%,var(--surface-subtle))] shadow-[0_10px_28px_-26px_var(--shadow)]`}`,children:[e&&(0,Q.jsx)(`div`,{className:`sticky top-0 z-[2] -mx-[6px] -mt-[8px] flex border-b border-[var(--stroke-soft)] bg-[var(--solid)] px-[2px] pb-[8px]`,children:(0,Q.jsxs)(J,{variant:`ghost`,className:`min-h-[40px] justify-start px-[8px]`,onClick:b,children:[(0,Q.jsx)(S,{size:17}),j(`chat:sessionTree.backToNodes`)]})}),t?(0,Q.jsxs)(Q.Fragment,{children:[(o||l.length>0)&&(0,Q.jsxs)(`div`,{className:`session-tree-lineage [&_>_strong]:text-[12px] [&_>_strong]:font-[650] [&_button]:justify-start [&_button]:text-left [&_button]:text-[11px] flex flex-col gap-[6px] [border-bottom:1px_solid_var(--stroke-soft)] [padding-bottom:12px]`,children:[(0,Q.jsx)(`strong`,{children:j(`chat:sessionTree.conversationLineage`)}),o&&(0,Q.jsxs)(J,{variant:`outline`,disabled:!!_,onClick:()=>A(o,s),children:[(0,Q.jsx)(We,{size:13}),j(`chat:sessionTree.returnToOriginalChat`,{name:o.name||j(`chat:chatPage.newChat`)})]}),l.map(e=>(0,Q.jsxs)(J,{variant:`outline`,disabled:!!_,onClick:()=>A(e),children:[(0,Q.jsx)(We,{size:13}),j(`chat:sessionTree.openSeparateChat`,{name:e.name||j(`chat:chatPage.newChat`)})]},e.id))]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`span`,{className:`session-tree-selection-kind [&_em]:rounded-[var(--r-xs)] [&_em]:bg-[var(--brand-blue-soft)] [&_em]:text-[var(--brand-blue-strong)] [&_em]:p-[2px_5px] [&_em]:[font-style:normal] flex items-center justify-between gap-[8px] text-[var(--text-muted)] text-[10px] [text-transform:uppercase]`,children:[v(t),y(t)&&(0,Q.jsx)(`em`,{children:y(t)})]}),(0,Q.jsx)(`strong`,{children:t.label||v(t)}),(0,Q.jsx)(`p`,{children:t.text||j(`chat:sessionTree.noPreview`)})]}),(0,Q.jsxs)(`div`,{className:`chat-resource-inputs [&_label]:grid [&_label]:gap-[5px] [&_label]:text-[12px] [&_label]:font-[600] [&_input[type='checkbox']]:w-[16px] [&_input[type='checkbox']]:h-[16px] [&_input[type='checkbox']]:[accent-color:var(--blue)] flex flex-col gap-[11px]`,children:[u&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`label`,{children:[(0,Q.jsx)(`span`,{children:j(`chat:sessionTree.nodeLabel`)}),(0,Q.jsx)(Ft,{value:f,maxLength:80,placeholder:j(`chat:sessionTree.labelPlaceholder`),onChange:e=>x(e.target.value)})]}),(0,Q.jsxs)(J,{variant:`outline`,disabled:m||i||a,onClick:w,children:[(0,Q.jsx)(rt,{size:14}),j(m?`chat:sessionTree.savingLabel`:`chat:sessionTree.saveLabel`)]}),!!t.label&&(0,Q.jsxs)(J,{variant:`outline`,disabled:m||i||a,onClick:T,children:[(0,Q.jsx)(it,{size:14}),j(`chat:sessionTree.removeLabel`)]})]}),u&&(0,Q.jsxs)(J,{variant:`outline`,disabled:h||i||a,onClick:E,children:[(0,Q.jsx)(be,{size:14}),j(h?`chat:sessionTree.creatingChildChat`:`chat:sessionTree.createChildChat`)]}),d&&(0,Q.jsxs)(`label`,{className:`session-tree-summary-option [&_small]:[grid-column:1/-1] [&_small]:text-[var(--text-muted)] [&_small]:font-[400] [&_small]:leading-[1.45] grid-cols-[minmax(0,1fr)_auto] items-center`,children:[(0,Q.jsx)(`span`,{children:j(`chat:sessionTree.abandonedBranchSummary`)}),(0,Q.jsx)(`input`,{type:`checkbox`,checked:p,disabled:t.leaf||i||a,onChange:e=>C(e.target.checked)}),(0,Q.jsx)(`small`,{children:j(`chat:sessionTree.abandonedBranchSummaryHint`)})]})]}),d&&(0,Q.jsx)(`p`,{children:j(`chat:sessionTree.sideEffectsRemain`)}),t.timestamp&&(0,Q.jsx)(`p`,{children:new Intl.DateTimeFormat(M,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(t.timestamp))}),r&&(0,Q.jsx)(`p`,{className:`danger-text`,children:r}),d&&(0,Q.jsxs)(J,{className:`chat-resource-confirm hover:bg-[var(--star-hover)] hover:text-[var(--on-accent)] min-w-[112px] min-h-[36px] self-start bg-[var(--star)] text-[var(--on-accent)] font-[650]`,disabled:g||t.leaf||i||a,onClick:D,children:[(0,Q.jsx)(k,{size:15}),g?j(`chat:sessionTree.navigating`):t.leaf?j(`chat:sessionTree.currentPosition`):j(`chat:sessionTree.continueFromNode`)]})]}):(0,Q.jsx)(`p`,{children:n?j(`chat:sessionTree.loading`):r||j(`chat:sessionTree.chooseNode`)}),r&&!t&&(0,Q.jsx)(J,{variant:`outline`,onClick:O,children:j(`chat:sessionTree.retry`)})]})}function Ii({open:e,sessionId:t,streaming:n,onClose:r,onNavigated:i,onCreateChildSession:a}){let{t:o,language:s}=c(),l=xt(),u=ft(),d=l||u,[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)([]),[g,_]=(0,Z.useState)(`conversation`),[v,y]=(0,Z.useState)(`list`),[b,x]=(0,Z.useState)(``),[S,C]=(0,Z.useState)(``),[w,T]=(0,Z.useState)(``),[E,D]=(0,Z.useState)([]),[O,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(!1),[M,N]=(0,Z.useState)(null),[P,F]=(0,Z.useState)(!1),[I,L]=(0,Z.useState)(!1),[R,z]=(0,Z.useState)(!1),[B,ee]=(0,Z.useState)(!1),[V,te]=(0,Z.useState)(!1),[ne,re]=(0,Z.useState)(``),[ie,H]=(0,Z.useState)(``),ae=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!e||!t)return;let n=!1;return _(`conversation`),y(`list`),x(``),L(!0),H(``),Promise.all([Y.getSessionTree(t),Y.listSessions()]).then(([e,t])=>{n||(p(e),h(t.sessions||[]),C(e.leafId||e.nodes[0]?.id||``))}).catch(e=>{n||H(K(e))}).finally(()=>{n||L(!1)}),()=>{n=!0}},[e,t]),(0,Z.useEffect)(()=>{e||(p(null),h([]),C(``),y(`list`),T(``),N(null),F(!1),H(``))},[e]),(0,Z.useEffect)(()=>{if(!e||g!==`marks`||O)return;let t=!0;return j(!0),H(``),Y.listSessionTreeLabels(500).then(e=>{t&&(D(e.labels||[]),k(!0))}).catch(e=>t&&H(K(e))).finally(()=>t&&j(!1)),()=>{t=!1}},[e,g,O]);let oe=(0,Z.useMemo)(()=>{let e=b.trim().toLocaleLowerCase(s);return e?E.filter(t=>`${t.label} ${t.sessionName}`.toLocaleLowerCase(s).includes(e)):E},[E,s,b]),se=async e=>{if(!M){N(e),H(``);try{e.active||await Y.navigateSessionTreeTarget(e.sessionId,e.entryId),cn(e.sessionId,`open`,e.entryId),r()}catch(e){H(K(e)),N(null)}}},ce=(0,Z.useMemo)(()=>Di(f?.nodes||[]),[f]),le=(0,Z.useCallback)(e=>({user:o(`chat:sessionTree.userMessage`),assistant:o(`chat:sessionTree.agentMessage`),tool:o(`chat:sessionTree.toolResult`),"tool-call":o(`chat:sessionTree.toolCall`),summary:o(`chat:sessionTree.branchSummary`),compaction:o(`chat:sessionTree.compactionSummary`),settings:o(`chat:sessionTree.settingsChange`),label:o(`chat:sessionTree.labelChange`),position:o(`chat:sessionTree.branchPosition`),extension:o(`chat:sessionTree.extensionEntry`),metadata:o(`chat:sessionTree.metadataEntry`),message:o(`chat:sessionTree.message`)})[e.kind]||e.type,[o]),ue=(0,Z.useMemo)(()=>{let e=b.trim().toLocaleLowerCase(s);return ki(ce,t=>(g===`conversation`?Ti.has(t.kind):g!==`labeled`||t.label)?!e||`${t.label} ${t.text} ${le(t)}`.toLocaleLowerCase(s).includes(e):!1)},[ce,s,b,le,g]),de=(0,Z.useMemo)(()=>ue.map(Ai),[ue]),fe=(0,Z.useMemo)(()=>Oi(ue),[ue]),U=(0,Z.useMemo)(()=>Oi(ce),[ce]).find(e=>e.id===S)||null,pe=f?.lineage?.parentSessionId?m.find(e=>e.id===f.lineage?.parentSessionId):null,me=(f?.lineage?.childSessionIds||[]).map(e=>m.find(t=>t.id===e)).filter(e=>!!e),he=U?.kind===`assistant`&&U.status===`completed`,W=he,ge=U?!Ei.has(U.kind):!1;(0,Z.useEffect)(()=>{T(U?.label||``),F(!1)},[U?.id,U?.label]),(0,Z.useEffect)(()=>{if(S&&fe.some(e=>e.id===S))return;let e=[...fe].reverse().find(e=>e.active);C(e?.id||fe[0]?.id||``)},[S,fe]),(0,Z.useEffect)(()=>{if(!e||!S)return;let t=requestAnimationFrame(()=>{document.querySelector(`[data-testid="session-tree-list"] .session-tree-node.selected`)?.scrollIntoView({block:`center`})});return()=>cancelAnimationFrame(t)},[e,b,S,g,fe.length]);let _e=async()=>{L(!0),H(``);try{let e=await Y.getSessionTree(t);p(e),C(e.leafId||e.nodes[0]?.id||``)}catch(e){H(K(e))}finally{L(!1)}},ve=async()=>{if(!(!U||R)){z(!0),H(``);try{p(await Y.setSessionTreeLabel(t,U.id,w))}catch(e){H(K(e))}finally{z(!1)}}},ye=async()=>{if(!(!U||R)){z(!0),H(``);try{p(await Y.setSessionTreeLabel(t,U.id,``))}catch(e){H(K(e))}finally{z(!1)}}},be=async()=>{if(!(!U||!W||V)){te(!0),H(``);try{await a(U.id),r()}catch(e){H(K(e))}finally{te(!1)}}},xe=async(e,t=``)=>{if(!(!e.id||ne)){re(e.id),H(``);try{t&&await Y.navigateSessionTreeTarget(e.id,t),cn(e.id,`open`,t),r()}catch(e){H(K(e))}finally{re(``)}}},Se=async()=>{if(!(!U||B||U.leaf||n||f?.streaming)){ee(!0),H(``);try{let e=await Y.navigateSessionTree(t,U.id,P);p(e),e.cancelled||(await i(e.editorText),r())}catch(e){H(K(e))}finally{ee(!1)}}},Ce=e=>e.leaf?o(`chat:sessionTree.current`):e.branchPoint?o(`chat:sessionTree.fork`):e.active?o(`chat:sessionTree.active`):``;return(0,Q.jsx)(Pt,{open:e,onOpenChange:e=>!e&&r(),children:(0,Q.jsxs)(Mt,{className:`chat-resource-dialog grid-rows-[auto_minmax(0,1fr)] overflow-hidden session-tree-dialog ${d?`!h-[calc(100dvh_-_16px)] !w-[calc(100vw_-_16px)] !max-w-none !gap-0 !p-0`:`!h-[min(760px,calc(100dvh_-_32px))] !w-[min(1120px,calc(100vw_-_32px))] !max-w-[1120px]`}`,showCloseButton:!1,children:[(0,Q.jsxs)(`div`,{className:`chat-resource-head flex items-start justify-between gap-[16px] [border-bottom:1px_solid_var(--stroke-soft)] session-tree-head [&_[data-slot='dialog-description']]:mt-[3px] [&_[data-slot='dialog-description']]:text-[12px] [&_[data-slot='dialog-title']]:text-[16px] ${d?`p-[14px]`:`[padding:17px_18px_14px]`}`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`session-tree-title [&_>_span]:grid [&_>_span]:w-[30px] [&_>_span]:h-[30px] [&_>_span]:place-items-center [&_>_span]:rounded-[var(--r-sm)] [&_>_span]:bg-[var(--success-soft)] [&_>_span]:text-[var(--success)] flex items-center gap-[9px]`,children:[(0,Q.jsx)(`span`,{children:(0,Q.jsx)(hr,{size:17})}),(0,Q.jsx)(Nt,{children:o(`chat:sessionTree.title`)})]}),(0,Q.jsx)(kt,{children:o(`chat:sessionTree.description`,{nodes:f?.nodeCount||0,branches:f?.branchCount||0})})]}),(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":o(`common:ui.closeDialog`),title:o(`common:ui.closeDialog`),onClick:r,children:(0,Q.jsx)(dt,{size:17})})]}),(0,Q.jsxs)(`div`,{className:`chat-resource-body grid min-h-0 overflow-hidden bg-[var(--surface-subtle)] session-tree-layout ${d?`grid-cols-1 grid-rows-[minmax(0,1fr)]`:`!grid-cols-[minmax(0,1fr)_292px]`}`,children:[(!d||v===`list`)&&(0,Q.jsx)(Pi,{view:g,onViewChange:e=>{_(e),y(`list`)},query:b,onQueryChange:x,loading:I,error:ie,mobileLayout:d,viewportRef:ae,segments:de,visibleNodes:fe,selectedId:S,typeLabel:le,stateLabel:Ce,onSelect:e=>{C(e),d&&y(`detail`)},visibleMarks:oe,marksLoading:A,openingMark:M,onOpenMark:e=>void se(e)}),g!==`marks`&&(!d||v===`detail`)&&(0,Q.jsx)(Fi,{mobileLayout:d,selected:U,loading:I,error:ie,streaming:n,dataStreaming:!!f?.streaming,parentSession:pe??null,parentEntryId:f?.lineage?.sourceEntryId||``,childSessions:me,canLabel:he,canDerive:ge,label:w,summarize:P,savingLabel:R,creatingChild:V,navigating:B,openingRelatedId:ne,typeLabel:le,stateLabel:Ce,onBackToList:()=>y(`list`),onLabelChange:T,onSummarizeChange:F,onSaveLabel:()=>void ve(),onRemoveLabel:()=>void ye(),onCreateChild:()=>void be(),onNavigate:()=>void Se(),onRefresh:()=>void _e(),onOpenRelated:(e,t)=>void xe(e,t??``)})]})]})})}function Li({visible:e,open:t,sessionId:n,streaming:r,revision:i,pulseToken:a,onOpenChange:o,onNavigated:s,onCreateChildSession:l}){let{t:u}=c(),[d,f]=(0,Z.useState)(0),[p,m]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{if(!a)return;m(!0);let e=window.setTimeout(()=>m(!1),1800);return()=>window.clearTimeout(e)},[a]),(0,Z.useEffect)(()=>{if(!e||r)return;let t=!0;return Y.getSessionTree(n).then(e=>t&&f(e.branchCount||0)).catch(()=>{}),()=>{t=!1}},[i,n,r,e]),e?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`icon`,className:`focus-session-tree-entry relative !size-8 !min-w-8 rounded-md border-0 bg-transparent p-0 text-muted-foreground shadow-none hover:bg-muted hover:text-foreground motion-reduce:animate-none ${p?`[animation:session-tree-new-node-pulse_1.8s_var(--ease-out)]`:``}`,title:u(`chat:sessionTree.menuDescription`),"data-pisper-recall-pulse":p||void 0,"aria-label":u(`chat:sessionTree.menu`),"aria-haspopup":`dialog`,"aria-expanded":t,onClick:()=>o(!0),children:[(0,Q.jsx)(hr,{size:16}),d>0&&(0,Q.jsx)(`i`,{"aria-hidden":`true`,className:`absolute right-1 top-1 size-1 rounded-full bg-blue-500`})]}),(0,Q.jsx)(Ii,{open:t,sessionId:n,streaming:r,onClose:()=>o(!1),onNavigated:s,onCreateChildSession:l})]}):null}function Ri(e){return[`running`,`waiting_approval`].includes(String(e.status||``))}function zi(e,t){return t(e===`running`?`chat:workflowRun.running`:e===`waiting_approval`?`chat:workflowRun.waitingApproval`:e===`completed`?`chat:workflowRun.completed`:e===`failed`?`chat:workflowRun.failed`:e===`cancelled`?`chat:workflowRun.stopped`:`chat:workflowRun.interrupted`)}function Bi({sessionId:e}){let{t}=c(),[n,r]=(0,Z.useState)([]),[i,a]=(0,Z.useState)(``),o=(0,Z.useCallback)(async()=>{try{let t=await Y.getSessionWorkflowRuns(e);r(t.runs||[])}catch{}},[e]);return(0,Z.useEffect)(()=>{o();let e=window.setInterval(o,1500);return()=>window.clearInterval(e)},[o]),n.length?(0,Q.jsx)(`div`,{className:`flex max-h-[210px] flex-col gap-[5px] overflow-auto`,children:[...n].sort((e,t)=>Date.parse(t.startedAt)-Date.parse(e.startedAt)).slice(0,5).map(e=>{let n=i===e.id,r=Math.round((Number(e.completedNodes)||0)/Math.max(1,Number(e.totalNodes)||1)*100);return(0,Q.jsxs)(`div`,{className:`session-workflow-run [&.failed]:border-[color-mix(in_srgb,var(--danger)_40%,var(--stroke-soft))] [&.waiting_approval]:border-[color-mix(in_srgb,var(--warning)_45%,var(--stroke-soft))] [border:1px_solid_var(--stroke-soft)] rounded-[var(--r-sm)] bg-[var(--solid)] ${e.status}`,children:[(0,Q.jsxs)(`button`,{className:`session-workflow-summary [&_>_span:nth-child(2)]:flex [&_>_span:nth-child(2)]:min-w-0 [&_>_span:nth-child(2)]:flex-col [&_>_span:nth-child(2)]:gap-[1px] [&_strong]:overflow-hidden [&_strong]:text-ellipsis [&_strong]:whitespace-nowrap [&_small]:overflow-hidden [&_small]:text-ellipsis [&_small]:whitespace-nowrap [&_strong]:text-[12px] [&_small]:text-[var(--text-muted)] [&_small]:text-[10px] [&_[data-slot='progress']]:h-[4px] max-[650px]:grid-cols-[28px_minmax(0,1fr)_16px] max-[650px]:[&_[data-slot='progress']]:[grid-column:2/4] grid w-full grid-cols-[28px_minmax(120px,1fr)_minmax(80px,160px)_16px] items-center gap-[9px] border-0 bg-transparent [padding:7px_9px] text-[var(--text)] text-left cursor-pointer`,onClick:()=>a(n?``:e.id),children:[(0,Q.jsx)(`span`,{className:`list-icon [.chat-resource-list_&]:grid [.chat-resource-list_&]:w-[28px] [.chat-resource-list_&]:h-[28px] [.chat-resource-list_&]:place-items-center [.chat-resource-list_&]:rounded-[var(--r-sm)] [.chat-resource-list_&]:bg-[var(--surface-subtle)] [.chat-resource-list_&]:text-[var(--star-strong)] [.session-workflow-summary_&]:grid [.session-workflow-summary_&]:w-[28px] [.session-workflow-summary_&]:h-[28px] [.session-workflow-summary_&]:place-items-center [.session-workflow-summary_&]:rounded-[var(--r-sm)] [.session-workflow-summary_&]:bg-[var(--surface-subtle)] [.session-workflow-summary_&]:text-[var(--star-strong)] grid w-[27px] h-[27px] place-items-center rounded-[var(--r-sm)] bg-[var(--accent-soft)] text-[var(--star-strong)] [.workflow-template-gallery_&]:grid [.workflow-template-gallery_&]:w-[32px] [.workflow-template-gallery_&]:h-[32px] [.workflow-template-gallery_&]:place-items-center [.workflow-template-gallery_&]:rounded-[var(--r-sm)] [.workflow-template-gallery_&]:bg-[var(--surface-subtle)] [.workflow-template-gallery_&]:text-[var(--star-strong)]`,children:(0,Q.jsx)(st,{size:14})}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`strong`,{children:e.workflowName}),(0,Q.jsxs)(`small`,{children:[zi(e.status,t),` · v`,e.workflowRevision||1]})]}),(0,Q.jsx)(A,{value:e.status===`completed`?100:r}),n?(0,Q.jsx)(ce,{size:14}):(0,Q.jsx)(le,{size:14})]}),n&&(0,Q.jsxs)(`div`,{className:`session-workflow-detail [&_>_p]:text-[var(--text-muted)] [&_>_p]:text-[11px] max-[650px]:pl-[12px] flex flex-col gap-[5px] [border-top:1px_solid_var(--stroke-soft)] [padding:7px_9px_9px_46px]`,children:[e.sourceMessage&&(0,Q.jsxs)(`div`,{className:`session-workflow-context [&_strong]:text-[var(--text-muted)] [&_strong]:text-[10px] [&_strong]:[text-transform:uppercase] [&_p]:max-h-[84px] [&_p]:overflow-auto [&_p]:m-0 [&_p]:text-[var(--text-secondary)] [&_p]:text-[11px] [&_p]:leading-[1.45] [&_p]:whitespace-pre-wrap [&_p]:[overflow-wrap:anywhere] [&_pre]:max-h-[84px] [&_pre]:overflow-auto [&_pre]:m-0 [&_pre]:text-[var(--text-secondary)] [&_pre]:text-[11px] [&_pre]:leading-[1.45] [&_pre]:whitespace-pre-wrap [&_pre]:[overflow-wrap:anywhere] [&_pre]:rounded-[var(--r-xs)] [&_pre]:bg-[var(--surface-subtle)] [&_pre]:p-[5px_6px] [&_pre]:font-[ui-monospace,_SFMono-Regular,_Consolas,_'Liberation_Mono',_monospace] grid min-w-0 gap-[3px] [border-bottom:1px_solid_var(--stroke-soft)] [padding-bottom:6px]`,children:[(0,Q.jsx)(`strong`,{children:t(`chat:workflowRun.request`)}),(0,Q.jsx)(`p`,{children:e.sourceMessage})]}),e.inputs&&Object.keys(e.inputs).length>0&&(0,Q.jsxs)(`div`,{className:`session-workflow-context [&_strong]:text-[var(--text-muted)] [&_strong]:text-[10px] [&_strong]:[text-transform:uppercase] [&_p]:max-h-[84px] [&_p]:overflow-auto [&_p]:m-0 [&_p]:text-[var(--text-secondary)] [&_p]:text-[11px] [&_p]:leading-[1.45] [&_p]:whitespace-pre-wrap [&_p]:[overflow-wrap:anywhere] [&_pre]:max-h-[84px] [&_pre]:overflow-auto [&_pre]:m-0 [&_pre]:text-[var(--text-secondary)] [&_pre]:text-[11px] [&_pre]:leading-[1.45] [&_pre]:whitespace-pre-wrap [&_pre]:[overflow-wrap:anywhere] [&_pre]:rounded-[var(--r-xs)] [&_pre]:bg-[var(--surface-subtle)] [&_pre]:p-[5px_6px] [&_pre]:font-[ui-monospace,_SFMono-Regular,_Consolas,_'Liberation_Mono',_monospace] grid min-w-0 gap-[3px] [border-bottom:1px_solid_var(--stroke-soft)] [padding-bottom:6px]`,children:[(0,Q.jsx)(`strong`,{children:t(`chat:workflowRun.inputs`)}),(0,Q.jsx)(`pre`,{children:JSON.stringify(e.inputs,null,2)})]}),(e.nodes||[]).map(n=>(0,Q.jsxs)(`div`,{className:`session-workflow-node [&.completed]:text-[var(--success)] [&.failed]:text-[var(--danger)] [&_>_span]:flex [&_>_span]:min-w-0 [&_>_span]:flex-col [&_strong]:text-[var(--text)] [&_strong]:text-[11px] [&_small]:overflow-hidden [&_small]:text-[var(--text-muted)] [&_small]:text-[10px] [&_small]:text-ellipsis [&_small]:whitespace-nowrap [&_>_div]:flex [&_>_div]:gap-[4px] grid grid-cols-[15px_minmax(0,1fr)_auto] items-center gap-[6px] min-h-[24px] text-[var(--text-muted)] ${n.status}`,children:[n.status===`completed`?(0,Q.jsx)(se,{size:13}):n.status===`failed`?(0,Q.jsx)(de,{size:13}):n.status===`running`?(0,Q.jsx)(Xe,{className:`animate-spin`,size:13}):(0,Q.jsx)(nt,{size:11}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`strong`,{children:n.label}),(n.error||n.summary)&&(0,Q.jsx)(`small`,{children:n.error||n.summary})]}),n.status===`waiting_approval`&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(J,{size:`xs`,onClick:async()=>{await Y.resolveWorkflowApproval(e.id,n.id,!0),await o()},children:t(`chat:workflowRun.approve`)}),(0,Q.jsx)(J,{size:`xs`,variant:`destructive`,onClick:async()=>{await Y.resolveWorkflowApproval(e.id,n.id,!1),await o()},children:t(`chat:workflowRun.reject`)})]})]},n.id)),(e.error||e.summary)&&(0,Q.jsx)(`p`,{children:e.error||e.summary}),Ri(e)&&(0,Q.jsxs)(J,{size:`xs`,variant:`destructive`,onClick:async()=>{await Y.stopWorkflowRun(e.id),await o()},children:[(0,Q.jsx)(nt,{"data-icon":`inline-start`}),t(`chat:workflowRun.stop`)]})]})]},e.id)})}):null}function Vi({notify:e,onOpenModelSettings:t,onInsertPrompt:n}){let{t:r}=c(),i=async()=>{try{let i=await bt(`/api/visual/models`);i.image||i.video?n(r(`chat:focusSession.visualPromptTemplate`)):(e?.(r(`chat:focusSession.configureVisualModelFirst`)),t?.())}catch{n(r(`chat:focusSession.visualPromptTemplate`))}};return(0,Q.jsx)(`button`,{type:`button`,className:`visual-entry-trigger [.focus-composer_&]:h-[38px] [.focus-composer_&]:border-0 [.focus-composer_&]:rounded-[var(--r-sm)] [.focus-composer_&]:bg-[var(--surface-subtle)] [.focus-composer_&]:text-[12px] [.focus-composer_&]:w-[38px] [.focus-composer_&]:min-w-[38px] [.focus-session.has-conversation_.focus-composer_&]:w-[36px] [.focus-session.has-conversation_.focus-composer_&]:min-w-[36px] [.focus-session.has-conversation_.focus-composer_&]:h-[36px] relative grid place-items-center border-0 rounded-[var(--r-xs)] bg-transparent text-[var(--text-muted)] cursor-pointer hover:bg-[var(--surface-hover)] hover:text-[var(--star-strong)]`,title:r(`chat:focusSession.generateImage`),"aria-label":r(`chat:focusSession.generateImage`),onClick:()=>void i(),children:(0,Q.jsx)(O,{size:16})})}function Hi(e){return(e.target instanceof Element?e.target:null)?.closest(`[data-shortcut-recorder], [role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"], .xterm, .terminal-xterm, .terminal-panel, [data-terminal]`)?!0:Array.from(document.querySelectorAll(`[role="dialog"], [role="alertdialog"], dialog[open]`)).some(e=>e.getClientRects().length>0)}function Ui(e){let t=(0,Z.useRef)(e);t.current=e;let{enabled:n,binding:r}=e;(0,Z.useEffect)(()=>{if(!n||!r)return;let e=null,i=null,a=()=>{e=null,i&&(i=null,t.current.onCancel())},o=n=>{if(i&&n.key===`Escape`&&!n.isComposing){a(),n.preventDefault();return}!t.current.enabled||n.defaultPrevented||n.isComposing||n.keyCode===229||n.repeat||e||document.visibilityState===`hidden`||Hi(n)||!Gt(n,r)||(e=n.code,t.current.onStart()&&(i={code:n.code,ctrl:n.ctrlKey,meta:n.metaKey,alt:n.altKey,shift:n.shiftKey},n.preventDefault()))},s=n=>{n.code===e&&(e=null),i&&(n.code===i.code||i.ctrl&&(!n.ctrlKey||n.code.startsWith(`Control`))||i.meta&&(!n.metaKey||n.code.startsWith(`Meta`))||i.alt&&(!n.altKey||n.code.startsWith(`Alt`))||i.shift&&(!n.shiftKey||n.code.startsWith(`Shift`)))&&(i=null,t.current.onRelease())},c=()=>{document.visibilityState===`hidden`&&a()};return window.addEventListener(`keydown`,o),window.addEventListener(`keyup`,s,!0),window.addEventListener(`blur`,a),document.addEventListener(`visibilitychange`,c),()=>{window.removeEventListener(`keydown`,o),window.removeEventListener(`keyup`,s,!0),window.removeEventListener(`blur`,a),document.removeEventListener(`visibilitychange`,c),a()}},[n,r])}function Wi(e){if(!e.length)return 0;let t=0;for(let n=0;n<e.length;n+=1)t+=e[n]*e[n];let n=Math.sqrt(t/e.length);return n<.0056?0:Math.min(1,Math.sqrt(n)*2.6)}function Gi(e=.35){let t=0;return{push(n){return t=t*(1-e)+n*e,t},reset(){t=0}}}function Ki(e,t=140){let n=e.trim();return n.length>t?`${n.slice(0,t-1)}…`:n}var qi=16e3,Ji=20,Yi=qi*Ji/1e3;function Xi(e,{onsetMs:t=80,minVoicedMs:n=160,silenceMs:r=900}={}){for(let e of[t,n,r])if(!Number.isFinite(e)||e<=0)throw Error(`Invalid VAD endpoint duration`);let i=e(),a=new Int16Array(Yi),o=0,s=0,c=0,l=0,u=!1,d=!1,f=!1,p=()=>u&&c*Ji>=n;return{get hasSpeech(){return p()},acceptPcm(e){if(f||d)return!1;for(let n=0;n<e.length;n+=1){let f=Number.isFinite(e[n])?Math.max(-1,Math.min(1,e[n])):0;if(a[o++]=f*(f<0?32768:32767),o!==Yi)continue;o=0;let m=i.processFrame(a);if(m<0)throw Error(`VAD frame processing failed`);if(m===1)s+=1,c+=1,l=0,s*Ji>=t&&(u=!0);else if(s=0,l+=1,u||(c=0),l*Ji>=r){if(p())return d=!0,!0;u=!1,c=0}}return!1},reset(){f||(i.destroy(),i=e(),o=s=c=l=0,u=d=!1,a.fill(0))},dispose(){f||(f=!0,o=0,i.destroy())}}}async function Zi(e={}){let{default:n,VADMode:r}=await t(async()=>{let{default:e,VADMode:t}=await import(`./embedded-D2rqyswH.js`);return{default:e,VADMode:t}},[]),i=await n();return Xi(()=>new i(e.mode??r.AGGRESSIVE,qi),e)}var Qi=()=>new DOMException(`Speech setup cancelled.`,`AbortError`);function $i(e){let[t,n]=(0,Z.useState)(null),[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(``),l=(0,Z.useRef)(null),u=(0,Z.useRef)(!1),d=(0,Z.useRef)(0),f=(0,Z.useRef)(0),p=(0,Z.useRef)(0),m=(0,Z.useRef)(e);m.current=e;let h=(0,Z.useCallback)(e=>{d.current++,f.current++;let t=l.current;l.current=null,t&&(t.signal.removeEventListener(`abort`,t.abort),e?t.reject(e):t.resolve()),u.current&&(i(!1),o(!1))},[]),g=(0,Z.useCallback)(e=>{u.current&&(n(e),c(``),l.current&&kn(e,m.current).every(e=>e.status===`installed`)&&h())},[h]),_=(0,Z.useCallback)(async e=>{let t=d.current,n=++f.current,r=()=>u.current&&t===d.current&&n===f.current&&!e?.aborted;try{let t=await Sn(e);r()&&g(t)}catch(e){if(r())throw e}},[g]);(0,Z.useEffect)(()=>(u.current=!0,_().catch(()=>{}),()=>{u.current=!1,h(Qi())}),[h,_]),(0,Z.useEffect)(()=>{if(!r)return;let e=new AbortController,t,n=async()=>{try{await _(e.signal)}catch(t){e.signal.aborted||c(t instanceof Error?t.message:String(t))}finally{e.signal.aborted||(t=setTimeout(()=>void n(),750))}};return n(),()=>{e.abort(),clearTimeout(t)}},[r,_]);let v=(0,Z.useCallback)(async e=>{if(q(e),!u.current)throw Qi();h(Qi());let t=++f.current;return new Promise((n,r)=>{let a=()=>{l.current===o&&h(e.reason||Qi())},o={signal:e,abort:a,resolve:n,reject:r};if(l.current=o,e.addEventListener(`abort`,a,{once:!0}),e.aborted){a();return}Sn(e).then(n=>{!u.current||l.current!==o||e.aborted||(t===f.current&&g(n),l.current===o&&i(!0))},e=>{l.current===o&&h(e)})})},[g,h]),y=(0,Z.useCallback)(async e=>{let t=d.current,n=++p.current,r=()=>u.current&&t===d.current&&n===p.current;o(!0),c(``);try{await e(),r()&&await _()}catch(e){r()&&c(e instanceof Error?e.message:String(e))}finally{r()&&o(!1)}},[_]);return{catalog:t,open:r,loading:a,error:s,selectedVoice:t?.defaults.voice||``,ensureReady:v,models:t?kn(t,e):[],show:()=>{h(Qi()),i(!0),c(``)},close:()=>h(Qi()),download:e=>y(()=>Dn(e)),cancelDownload:e=>y(()=>En(e)),downloadAll:()=>y(async()=>{if(t)for(let e of kn(t,m.current))[`installed`,`downloading`,`verifying`].includes(e.status)||await Dn(e.id)})}}var ea=8388608;function ta(e,t){return q(t),new Promise((n,r)=>{let i=()=>r(vt(t));t.addEventListener(`abort`,i,{once:!0}),e.then(n,r).finally(()=>t.removeEventListener(`abort`,i))})}var na=10,ra=500;async function ia(e,t,n,r){for(let i=0;;i+=1){let a=await fetch(`/api/speech/synthesize`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e,voiceId:t,requestId:n}),signal:r});if(a.status!==409||i>=na)return a;let o=await a.json().catch(()=>({}));if(!o.error||!/busy/i.test(o.error))return a;await ta(new Promise(e=>setTimeout(e,ra)),r)}}async function aa(e){if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Speech synthesis failed (${e.status}).`)}if(!e.headers.get(`content-type`)?.startsWith(`audio/wav`)||!e.body)throw Error(`Invalid speech audio response.`);let t=e.body.getReader(),n=[],r=0;try{for(;;){let{done:e,value:i}=await t.read();if(e)break;if(r+=i.byteLength,r>ea)throw Error(`Speech audio exceeds the supported limit.`);n.push(i)}}finally{await t.cancel().catch(()=>{}),t.releaseLock()}if(r<44)throw Error(`Speech audio is empty.`);let i=new Uint8Array(r),a=0;for(let e of n)i.set(e,a),a+=e.length;return i.buffer}async function oa(e,t,n,r){q(n);let i=_t(n);try{await sa(e,t,i,r)}finally{i.abort(new DOMException(`Speech playback ended.`,`AbortError`)),i.dispose()}}async function sa(e,n,r,i){let{signal:a}=r,{speechSegments:o}=await ta(t(()=>import(`./speech-text-Cpe8K6uv.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8])),a);q(a);let s=(typeof e==`string`?(async function*(){yield*o(e)})():(await ta(t(()=>import(`./speech-stream-text-Bh_0kguU.js`),__vite__mapDeps([9,1,2,3,4,5,6,7,8,10,0])),a)).streamingSpeechSegments(e,a))[Symbol.asyncIterator](),c=!!window.__PISPER_MOBILE_APP__,l=new Set,u,d,f,p=e=>{(c?wn(`mobile_cancel_speech`,{requestId:e}):bt(`/api/speech/cancel`,{method:`POST`,body:{requestId:e},timeout:3e3})).catch(()=>{})},m=()=>{for(let e of l)p(e);try{d?.stop()}catch{}f?.(a.reason||new DOMException(`Speech playback cancelled.`,`AbortError`))};a.addEventListener(`abort`,m,{once:!0});let h=e=>{q(a);let t=crypto.randomUUID();l.add(t);let r=(async()=>{if(c){let r=await wn(`mobile_synthesize_speech`,{text:e,voiceId:n,requestId:t});if(a.aborted&&(p(t),q(a)),!r||typeof r.audioId!=`string`||!r.audioId.trim()||r.audioId.length>128||!Number.isInteger(r.sampleRate)||r.sampleRate<8e3||r.sampleRate>48e3||!Number.isFinite(r.durationMs)||r.durationMs<=0||r.durationMs>45e3)throw Error(`Invalid native speech audio.`);return{requestId:t,native:r}}let r=_t(a,6e4);try{let i=await ia(e,n,t,r.signal);return{requestId:t,wav:await aa(i)}}finally{r.dispose()}})();return r.catch(()=>{}),r};try{if(!c){u=new AudioContext({sampleRate:24e3});let e;try{await ta(Promise.race([u.resume(),new Promise((t,n)=>{e=setTimeout(()=>n(Error(`Audio playback is unavailable.`)),5e3)})]),a)}finally{clearTimeout(e)}}let e=async()=>{let e=await ta(s.next(),a);return e.done?void 0:h(e.value)},t=e(),n=!1;for(;;){let r=await ta(t,a);if(q(a),!r)break;if(t=e(),t.catch(()=>{}),n=!0,i?.(),r.native){if((await ta(wn(`mobile_play_speech`,{audioId:r.native.audioId,requestId:r.requestId}),a))?.completed!==!0)throw Error(`Speech playback was interrupted.`)}else{let e=await ta(u.decodeAudioData(r.wav),a);if(q(a),e.numberOfChannels!==1||!Number.isFinite(e.duration)||e.duration<=0||e.duration>45)throw Error(`Invalid speech audio duration.`);let t=u.createBufferSource();d=t,t.buffer=e,t.connect(u.destination);try{await new Promise((e,n)=>{f=n,t.onended=()=>e(),t.start()})}finally{f=void 0,t.onended=null,t.disconnect(),d=void 0}}l.delete(r.requestId),q(a)}if(!n)throw Error(`The reply has no speakable text.`)}finally{a.removeEventListener(`abort`,m),r.abort(new DOMException(`Speech playback ended.`,`AbortError`)),s.return?.(void 0).catch(()=>{});for(let e of l)p(e);try{d?.stop()}catch{}await u?.close().catch(()=>{})}}var ca={schemaVersion:1,scope:`Offline license texts and provenance notices for the catalogued speech resources and local derivatives. This document is not legal advice, commercial-use clearance, a complete training-data rights audit, or approval for redistribution or formal release. Packaging this small notice file does not package the large models or resolve pending obligations. Native sherpa binaries and their compiled or embedded dependencies require a separate license/linkage and source-delivery audit; switching TTS models does not prove the binaries contain no GPL components or satisfy their obligations.`,licenseIdsMeaning:`References identify retained license documents applicable to the described components or their stated source projects. Multiple references are not alternative dual-license choices and are not a complete SPDX expression. A repository declaration does not relicense unrelated bundled data.`,statusDefinitions:{confirmed:`The specific content or source match described in summary was verified; this is not a whole-chain rights guarantee.`,declared:`An upstream license declaration supports the classification, without a complete reproducible provenance proof.`,pending:`The listed provenance, rights, or distribution obligations remain unresolved even where a license declaration exists.`},pathScopes:{model:`Paths are relative to the original downloaded model root. A terminal /** matches every descendant; all other paths are exact.`,shared:`Paths are relative to the application's shared resource root.`},licenses:[{id:`apache-2.0`,name:`Apache License 2.0 (X-ASR source text)`,text:` Apache License
|
|
4
|
+
Version 2.0, January 2004
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
24
|
+
|
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
26
|
+
exercising permissions granted by this License.
|
|
27
|
+
|
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
29
|
+
including but not limited to software source code, documentation
|
|
30
|
+
source, and configuration files.
|
|
31
|
+
|
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
|
33
|
+
transformation or translation of a Source form, including but
|
|
34
|
+
not limited to compiled object code, generated documentation,
|
|
35
|
+
and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
38
|
+
Object form, made available under the License, as indicated by a
|
|
39
|
+
copyright notice that is included in or attached to the work
|
|
40
|
+
(an example is provided in the Appendix below).
|
|
41
|
+
|
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
48
|
+
the Work and Derivative Works thereof.
|
|
49
|
+
|
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
|
51
|
+
the original version of the Work and any modifications or additions
|
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
66
|
+
subsequently incorporated within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent claims licensable
|
|
81
|
+
by such Contributor that are necessarily infringed by their
|
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
84
|
+
institute patent litigation against any entity (including a
|
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate
|
|
89
|
+
as of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License. You may add Your own attribution
|
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
122
|
+
that such additional attribution notices cannot be construed
|
|
123
|
+
as modifying the License.
|
|
124
|
+
|
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
|
126
|
+
may provide additional or different license terms and conditions
|
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
130
|
+
the conditions stated in this License.
|
|
131
|
+
|
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
135
|
+
this License, without any additional terms or conditions.
|
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
137
|
+
the terms of any separate license agreement you may have executed
|
|
138
|
+
with Licensor regarding such Contributions.
|
|
139
|
+
|
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
142
|
+
except as required for reasonable and customary use in describing the
|
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
|
154
|
+
|
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
|
160
|
+
incidental, or consequential damages of any character arising as a
|
|
161
|
+
result of this License or out of the use or inability to use the
|
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
164
|
+
other commercial damages or losses), even if such Contributor
|
|
165
|
+
has been advised of the possibility of such damages.
|
|
166
|
+
|
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
170
|
+
or other liability obligations and/or rights consistent with this
|
|
171
|
+
License. However, in accepting such obligations, You may act only
|
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
176
|
+
of your accepting any such warranty or additional liability.
|
|
177
|
+
|
|
178
|
+
END OF TERMS AND CONDITIONS
|
|
179
|
+
|
|
180
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
181
|
+
|
|
182
|
+
To apply the Apache License to your work, attach the following
|
|
183
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
184
|
+
replaced with your own identifying information. (Don't include
|
|
185
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
186
|
+
comment syntax for the file format. We also recommend that a
|
|
187
|
+
file or class name and description of purpose be included on the
|
|
188
|
+
same "printed page" as the copyright notice for easier
|
|
189
|
+
identification within third-party archives.
|
|
190
|
+
|
|
191
|
+
Copyright [yyyy] [name of copyright owner]
|
|
192
|
+
|
|
193
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
194
|
+
you may not use this file except in compliance with the License.
|
|
195
|
+
You may obtain a copy of the License at
|
|
196
|
+
|
|
197
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
198
|
+
|
|
199
|
+
Unless required by applicable law or agreed to in writing, software
|
|
200
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
201
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
202
|
+
See the License for the specific language governing permissions and
|
|
203
|
+
limitations under the License.
|
|
204
|
+
`,sourceUrl:`https://raw.githubusercontent.com/Gilgamesh-J/X-ASR/838297cd47fed858e6cf72eaf5a52f948a3edd73/LICENSE`,sha256:`c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4`},{id:`mit-melo`,name:`MIT License (MeloTTS source and conversion package)`,text:`Copyright (c) 2024 MyShell.ai
|
|
205
|
+
|
|
206
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
207
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
208
|
+
in the Software without restriction, including without limitation the rights
|
|
209
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
210
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
211
|
+
furnished to do so, subject to the following conditions:
|
|
212
|
+
|
|
213
|
+
The above copyright notice and this permission notice shall be included in all
|
|
214
|
+
copies or substantial portions of the Software.
|
|
215
|
+
|
|
216
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
217
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
218
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
219
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
220
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
221
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
222
|
+
SOFTWARE.`,sourceUrl:`https://raw.githubusercontent.com/myshell-ai/MeloTTS/209145371cff8fc3bd60d7be902ea69cbdb7965a/LICENSE`,sha256:`88a50e5a02bbc2a5c2f084dc19da751aa97b1690f5fda76cd8005c8634d1ca70`},{id:`apache-2.0-sherpa`,name:`Apache License 2.0 (sherpa conversion code; FST source declaration)`,text:`
|
|
223
|
+
Apache License
|
|
224
|
+
Version 2.0, January 2004
|
|
225
|
+
http://www.apache.org/licenses/
|
|
226
|
+
|
|
227
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
228
|
+
|
|
229
|
+
1. Definitions.
|
|
230
|
+
|
|
231
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
232
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
233
|
+
|
|
234
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
235
|
+
the copyright owner that is granting the License.
|
|
236
|
+
|
|
237
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
238
|
+
other entities that control, are controlled by, or are under common
|
|
239
|
+
control with that entity. For the purposes of this definition,
|
|
240
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
241
|
+
direction or management of such entity, whether by contract or
|
|
242
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
243
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
244
|
+
|
|
245
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
246
|
+
exercising permissions granted by this License.
|
|
247
|
+
|
|
248
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
249
|
+
including but not limited to software source code, documentation
|
|
250
|
+
source, and configuration files.
|
|
251
|
+
|
|
252
|
+
"Object" form shall mean any form resulting from mechanical
|
|
253
|
+
transformation or translation of a Source form, including but
|
|
254
|
+
not limited to compiled object code, generated documentation,
|
|
255
|
+
and conversions to other media types.
|
|
256
|
+
|
|
257
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
258
|
+
Object form, made available under the License, as indicated by a
|
|
259
|
+
copyright notice that is included in or attached to the work
|
|
260
|
+
(an example is provided in the Appendix below).
|
|
261
|
+
|
|
262
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
263
|
+
form, that is based on (or derived from) the Work and for which the
|
|
264
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
265
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
266
|
+
of this License, Derivative Works shall not include works that remain
|
|
267
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
268
|
+
the Work and Derivative Works thereof.
|
|
269
|
+
|
|
270
|
+
"Contribution" shall mean any work of authorship, including
|
|
271
|
+
the original version of the Work and any modifications or additions
|
|
272
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
273
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
274
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
275
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
276
|
+
means any form of electronic, verbal, or written communication sent
|
|
277
|
+
to the Licensor or its representatives, including but not limited to
|
|
278
|
+
communication on electronic mailing lists, source code control systems,
|
|
279
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
280
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
281
|
+
excluding communication that is conspicuously marked or otherwise
|
|
282
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
283
|
+
|
|
284
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
285
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
286
|
+
subsequently incorporated within the Work.
|
|
287
|
+
|
|
288
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
289
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
290
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
291
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
292
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
293
|
+
Work and such Derivative Works in Source or Object form.
|
|
294
|
+
|
|
295
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
296
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
297
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
298
|
+
(except as stated in this section) patent license to make, have made,
|
|
299
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
300
|
+
where such license applies only to those patent claims licensable
|
|
301
|
+
by such Contributor that are necessarily infringed by their
|
|
302
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
303
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
304
|
+
institute patent litigation against any entity (including a
|
|
305
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
306
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
307
|
+
or contributory patent infringement, then any patent licenses
|
|
308
|
+
granted to You under this License for that Work shall terminate
|
|
309
|
+
as of the date such litigation is filed.
|
|
310
|
+
|
|
311
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
312
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
313
|
+
modifications, and in Source or Object form, provided that You
|
|
314
|
+
meet the following conditions:
|
|
315
|
+
|
|
316
|
+
(a) You must give any other recipients of the Work or
|
|
317
|
+
Derivative Works a copy of this License; and
|
|
318
|
+
|
|
319
|
+
(b) You must cause any modified files to carry prominent notices
|
|
320
|
+
stating that You changed the files; and
|
|
321
|
+
|
|
322
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
323
|
+
that You distribute, all copyright, patent, trademark, and
|
|
324
|
+
attribution notices from the Source form of the Work,
|
|
325
|
+
excluding those notices that do not pertain to any part of
|
|
326
|
+
the Derivative Works; and
|
|
327
|
+
|
|
328
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
329
|
+
distribution, then any Derivative Works that You distribute must
|
|
330
|
+
include a readable copy of the attribution notices contained
|
|
331
|
+
within such NOTICE file, excluding those notices that do not
|
|
332
|
+
pertain to any part of the Derivative Works, in at least one
|
|
333
|
+
of the following places: within a NOTICE text file distributed
|
|
334
|
+
as part of the Derivative Works; within the Source form or
|
|
335
|
+
documentation, if provided along with the Derivative Works; or,
|
|
336
|
+
within a display generated by the Derivative Works, if and
|
|
337
|
+
wherever such third-party notices normally appear. The contents
|
|
338
|
+
of the NOTICE file are for informational purposes only and
|
|
339
|
+
do not modify the License. You may add Your own attribution
|
|
340
|
+
notices within Derivative Works that You distribute, alongside
|
|
341
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
342
|
+
that such additional attribution notices cannot be construed
|
|
343
|
+
as modifying the License.
|
|
344
|
+
|
|
345
|
+
You may add Your own copyright statement to Your modifications and
|
|
346
|
+
may provide additional or different license terms and conditions
|
|
347
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
348
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
349
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
350
|
+
the conditions stated in this License.
|
|
351
|
+
|
|
352
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
353
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
354
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
355
|
+
this License, without any additional terms or conditions.
|
|
356
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
357
|
+
the terms of any separate license agreement you may have executed
|
|
358
|
+
with Licensor regarding such Contributions.
|
|
359
|
+
|
|
360
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
361
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
362
|
+
except as required for reasonable and customary use in describing the
|
|
363
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
364
|
+
|
|
365
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
366
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
367
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
368
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
369
|
+
implied, including, without limitation, any warranties or conditions
|
|
370
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
371
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
372
|
+
appropriateness of using or redistributing the Work and assume any
|
|
373
|
+
risks associated with Your exercise of permissions under this License.
|
|
374
|
+
|
|
375
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
376
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
377
|
+
unless required by applicable law (such as deliberate and grossly
|
|
378
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
379
|
+
liable to You for damages, including any direct, indirect, special,
|
|
380
|
+
incidental, or consequential damages of any character arising as a
|
|
381
|
+
result of this License or out of the use or inability to use the
|
|
382
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
383
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
384
|
+
other commercial damages or losses), even if such Contributor
|
|
385
|
+
has been advised of the possibility of such damages.
|
|
386
|
+
|
|
387
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
388
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
389
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
390
|
+
or other liability obligations and/or rights consistent with this
|
|
391
|
+
License. However, in accepting such obligations, You may act only
|
|
392
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
393
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
394
|
+
defend, and hold each Contributor harmless for any liability
|
|
395
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
396
|
+
of your accepting any such warranty or additional liability.
|
|
397
|
+
|
|
398
|
+
END OF TERMS AND CONDITIONS
|
|
399
|
+
|
|
400
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
401
|
+
|
|
402
|
+
To apply the Apache License to your work, attach the following
|
|
403
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
404
|
+
replaced with your own identifying information. (Don't include
|
|
405
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
406
|
+
comment syntax for the file format. We also recommend that a
|
|
407
|
+
file or class name and description of purpose be included on the
|
|
408
|
+
same "printed page" as the copyright notice for easier
|
|
409
|
+
identification within third-party archives.
|
|
410
|
+
|
|
411
|
+
Copyright [yyyy] [name of copyright owner]
|
|
412
|
+
|
|
413
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
414
|
+
you may not use this file except in compliance with the License.
|
|
415
|
+
You may obtain a copy of the License at
|
|
416
|
+
|
|
417
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
418
|
+
|
|
419
|
+
Unless required by applicable law or agreed to in writing, software
|
|
420
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
421
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
422
|
+
See the License for the specific language governing permissions and
|
|
423
|
+
limitations under the License.
|
|
424
|
+
`,sourceUrl:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/917bed95c8e5c7c18aa4d69fea42e9ef8ef0a60e/LICENSE`,sha256:`cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30`},{id:`mit-cppjieba`,name:`MIT License (CppJieba release source)`,text:`The MIT License (MIT)
|
|
425
|
+
|
|
426
|
+
Copyright (c) 2013
|
|
427
|
+
|
|
428
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
429
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
430
|
+
the Software without restriction, including without limitation the rights to
|
|
431
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
432
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
433
|
+
subject to the following conditions:
|
|
434
|
+
|
|
435
|
+
The above copyright notice and this permission notice shall be included in all
|
|
436
|
+
copies or substantial portions of the Software.
|
|
437
|
+
|
|
438
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
439
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
440
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
441
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
442
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
443
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
444
|
+
`,sourceUrl:`https://raw.githubusercontent.com/csukuangfj/cppjieba/f03dd931a00330c279c8590275850fd1f6749a18/LICENSE`,sha256:`ba898a14f729ba5e9965da34e3eecd5edd3795f2cc5d7c923b815ba79bb851b0`},{id:`mit-pypinyin`,name:`MIT License (pypinyin project; historical data provenance pending)`,text:`The MIT License (MIT)
|
|
445
|
+
|
|
446
|
+
Copyright (c) 2016 mozillazg, 闲耘 <hotoo.cn@gmail.com>
|
|
447
|
+
|
|
448
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
449
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
450
|
+
the Software without restriction, including without limitation the rights to
|
|
451
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
452
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
453
|
+
subject to the following conditions:
|
|
454
|
+
|
|
455
|
+
The above copyright notice and this permission notice shall be included in all
|
|
456
|
+
copies or substantial portions of the Software.
|
|
457
|
+
|
|
458
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
459
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
460
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
461
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
462
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
463
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
464
|
+
`,sourceUrl:`https://raw.githubusercontent.com/mozillazg/python-pinyin/8595294b1a97845e30f11ecfdb3caa4e61ac3988/LICENSE.txt`,sha256:`1e6c90014b4912815c296ee64bb6f6280af47e6d4c5d80e86232dfc5defe764c`},{id:`cmudict-0.6-1998`,name:`CMU Pronouncing Dictionary 0.6 historical permission and attribution notice (1998)`,text:`## Date: August 8, 1998
|
|
465
|
+
##
|
|
466
|
+
## The Carnegie Mellon Pronouncing Dictionary [cmudict.0.6] is Copyright 1998
|
|
467
|
+
## by Carnegie Mellon University. Use of this dictionary, for any research or
|
|
468
|
+
## commercial purpose, is completely unrestricted. If you make use of or
|
|
469
|
+
## redistribute this material, we would appreciate acknowlegement of its
|
|
470
|
+
## origin.
|
|
471
|
+
##
|
|
472
|
+
## cmudict.0.6 is the fifth release of cmudict, first released as cmudict.0.1
|
|
473
|
+
## in September of 1993. There was no generally available public release
|
|
474
|
+
## of version 0.5.
|
|
475
|
+
##
|
|
476
|
+
## See the README in this directory before you use this dictionary.
|
|
477
|
+
##
|
|
478
|
+
## Thanks to Bill Huggins at BBN; Bill Fisher at NIST; Alex Hauptman,
|
|
479
|
+
## Alex Rudnicky, Jack Mostow, Roni Rosenfeld, Richard Stern,
|
|
480
|
+
## Matthew Siegler, Kevin Lenzo, Maxine Eskenazi, Mosur Ravishankar,
|
|
481
|
+
## Eric Thayer, Kristie Seymore, and Raj Reddy at CMU; Lin Chase at
|
|
482
|
+
## LIMSI; Doug Paul at MIT Lincoln Labs; Ben Serridge at MIT SLS; Murray
|
|
483
|
+
## Spiegel at Bellcore; Tony Robinson at Cambridge UK; David Bowness of
|
|
484
|
+
## CAE Electronics Ltd. and CRIM; Stephen Hocking; Jerry Quinn at BNR
|
|
485
|
+
## Canada, and Marshal Midden for bringing to our attention problems and
|
|
486
|
+
## inadequacies with the first releases. Most special thanks to Bob Weide
|
|
487
|
+
## for all his work on prior versions of the dictionary.
|
|
488
|
+
##
|
|
489
|
+
## We welcome input from users and will continue to acknowledge such input
|
|
490
|
+
## in subsequent releases. If I failed to acknowledge your input in this
|
|
491
|
+
## release, please remind me and I will update these comments. If I failed to
|
|
492
|
+
## fix things that you brought to my attention, please remind me and have
|
|
493
|
+
## patience. If I actually fixed things that you brought to my attention and
|
|
494
|
+
## you appreciate it, I wouldn't mind a pat on the back.
|
|
495
|
+
##
|
|
496
|
+
## This version differs from previous releases of cmudict most significantly
|
|
497
|
+
## in the addition of new words from the common ARPA tasks for 1996 and 1997.
|
|
498
|
+
##
|
|
499
|
+
## There are undoubtedly still errors and inconsistencies in this dictionary
|
|
500
|
+
## so keep your eyes open for problems and mail them to me.
|
|
501
|
+
##
|
|
502
|
+
## We hope this dictionary is an improvement over cmudict.0.4.
|
|
503
|
+
##
|
|
504
|
+
## email: cmudict@cs.cmu.edu
|
|
505
|
+
## web: http://www.speech.cs.cmu.edu/cgi-bin/cmudict
|
|
506
|
+
## ftp: ftp://ftp.cs.cmu.edu/project/speech/dict/
|
|
507
|
+
##
|
|
508
|
+
## Thank you for your continued interest in the CMU Pronouncing
|
|
509
|
+
## Dictionary. Further addictions and improvements are planned
|
|
510
|
+
## for forthcoming releases.
|
|
511
|
+
##
|
|
512
|
+
`,sourceUrl:`https://raw.githubusercontent.com/myshell-ai/MeloTTS/209145371cff8fc3bd60d7be902ea69cbdb7965a/melo/text/cmudict.rep`,sha256:`08ee91f3c05c55160bdc599247ba53e5de8cc2597766fdb22b54a81cb24dd954`}],models:[{id:`x-asr-480ms-int8`,revision:`2026-06-05`,attribution:`X-ASR by Gilgamesh-J / GilgameshWind; trained using icefall and deployed with sherpa-onnx. The locked HF model card expressly covers model artifacts and declares Apache-2.0. The separately discovered GitHub license commit is not the locked HF revision. No root LICENSE or NOTICE was listed in the inspected HF tree; this is not proof that every historical distribution lacks NOTICE. Retain applicable upstream notices when found.`,archive:{url:`https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-x-asr-480ms-streaming-zipformer-transducer-zh-en-punct-int8-2026-06-05.tar.bz2`,sha256:`fa5f63d618e5a01526e275a358bb7772e403f84808a4769fba52cffd8160bf74`},groups:[{id:`xasr-weights`,pathScope:`model`,paths:[`encoder.int8.onnx`,`decoder.onnx`,`joiner.int8.onnx`],licenseIds:[`apache-2.0`],status:`pending`,summary:`Apache-2.0 is explicitly declared for X-ASR model artifacts. The sherpa export script describes icefall streaming ONNX export and INT8 quantization; installed file hashes match the catalog, but the 2026-06-05 archive-to-checkpoint/build identity is not established.`,pendingReasons:[`Exact checkpoint and source commits used to build the 2026-06-05 INT8 archive remain unverified; the export script downloads moving main URLs. Training-data rights are not fully audited.`],evidence:[{url:`https://hf-mirror.com/GilgameshWind/X-ASR-zh-en/resolve/689ff18c584d29910da37b6fe904db0c1489c9d1/README.md`,sha256:`7acc6f439d3e39e46de4298ccf8a8f6a483fdc5f9f5d08e61422b63760ec37b1`},{url:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/v1.13.7/scripts/zipformer-transducer/x-asr/export-streaming.sh`,sha256:`63b018fe72a29e9a41c6d4e358085b5ad1614e021c0d9f3c05a2d11f1dff0d81`}]},{id:`xasr-tokens`,pathScope:`model`,paths:[`tokens.txt`],licenseIds:[`apache-2.0`],status:`pending`,summary:`X-ASR token resource, not the SentencePiece or sherpa software. The punctuation export block downloads X-ASR-zh-en/zipformer/data/lang_5000_with_punctuation/tokens.txt. Catalog content SHA256: b818a60878b9aae978cbb8ad594acbd403d76d1af2e31ef4197c84e2dbdba27c.`,pendingReasons:[`The historical source revision for the token file in the 2026-06-05 archive is not pinned by the export script.`],evidence:[{url:`https://hf-mirror.com/GilgameshWind/X-ASR-zh-en/resolve/689ff18c584d29910da37b6fe904db0c1489c9d1/README.md`,sha256:`7acc6f439d3e39e46de4298ccf8a8f6a483fdc5f9f5d08e61422b63760ec37b1`},{url:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/v1.13.7/scripts/zipformer-transducer/x-asr/export-streaming.sh`,sha256:`63b018fe72a29e9a41c6d4e358085b5ad1614e021c0d9f3c05a2d11f1dff0d81`}]},{id:`xasr-bpe`,pathScope:`model`,paths:[`bpe.model`],licenseIds:[`apache-2.0`],status:`pending`,summary:`X-ASR BPE resource. The export script renames X-ASR-zh-en/zipformer/data/lang_5000_with_punctuation/bpe_punc.model to bpe.model. Its license classification comes from X-ASR, not from the software that reads the SentencePiece format.`,pendingReasons:[`The historical BPE source commit and exact archive build provenance remain unverified.`],evidence:[{url:`https://hf-mirror.com/GilgameshWind/X-ASR-zh-en/resolve/689ff18c584d29910da37b6fe904db0c1489c9d1/README.md`,sha256:`7acc6f439d3e39e46de4298ccf8a8f6a483fdc5f9f5d08e61422b63760ec37b1`},{url:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/v1.13.7/scripts/zipformer-transducer/x-asr/export-streaming.sh`,sha256:`63b018fe72a29e9a41c6d4e358085b5ad1614e021c0d9f3c05a2d11f1dff0d81`}]},{id:`xasr-bpe-vocab`,pathScope:`shared`,paths:[`speech-resources/xasr-bpe.vocab`],licenseIds:[`apache-2.0`],status:`pending`,summary:`Modified by Pisper: extracted the ordered SentencePiece pieces and scores as UTF-8 piece<TAB>score<LF> lines. This local text derivative retains the source resource license classification; it is not newly licensed as Pisper-owned model data. Original and derived hashes and generator are bound by xasr-bpe-extraction below.`,pendingReasons:[`The source BPE historical provenance remains pending as described in xasr-bpe. A text extraction does not resolve upstream rights.`],evidence:[{url:`https://hf-mirror.com/GilgameshWind/X-ASR-zh-en/resolve/689ff18c584d29910da37b6fe904db0c1489c9d1/README.md`,sha256:`7acc6f439d3e39e46de4298ccf8a8f6a483fdc5f9f5d08e61422b63760ec37b1`}]}],modifications:[{id:`xasr-bpe-extraction`,groupIds:[`xasr-bpe-vocab`],modifiedBy:`Pisper`,summary:`Local BPE text extraction, not retraining. The generator identity records the inspected repository implementation, not a claim about a historical upstream build date.`,source:{path:`bpe.model`,bytes:119265,sha256:`f87a38025a5fdd1e4e9591f6a44bb81295097ce0b80df6f4ab9f44e52c64ca5f`},derived:{path:`speech-resources/xasr-bpe.vocab`,bytes:61562,sha256:`01381aa0c3065832cb8d7462d529e3079a99be56c955ce93b4cb9b78e8aa34e5`},generator:{path:`scripts/speech-bpe.mjs`,sha256:`a1c85731aa3e0be89f04acc79830db784a9d43edb8af9f4fb723bb45bd725786`,method:`sentencePieceModelToVocab decodes ordered protobuf ModelProto.pieces and emits each piece, a tab, its finite score, and a newline without changing the BPE model.`}}]},{id:`vits-melo-tts-zh_en`,revision:`a0d5c6a264c0ef92d70d8661d8cc502d79627cd6`,archive:{url:`https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-melo-tts-zh_en.tar.bz2`,bytes:167006755,sha256:`e58351ed7149f290a54534538badd4077cdbe6fddc964b24d0bee870415d1514`},attribution:`MeloTTS by MyShell.ai; sherpa-onnx ONNX conversion. The retained software license is Copyright (c) 2024 MyShell.ai, MIT. The neural-weight repository separately declares MIT; dictionary and FST resources have separate declarations and pending provenance. Pisper selects the original single female voice via public sid 0 and uses the same original FP32 ONNX, tokens, mixed-language lexicon, dictionary and normalization files on Desktop, Android and iOS. No retraining, quantization, graph/metadata patch or voice-subset derivative is made. The unused new_heteronym.fst and 133-byte model.int8.onnx Git LFS pointer in the transport archive are drained but not installed; retained model files are unchanged. These choices do not imply upstream/speaker endorsement, redistribution approval or completed native-platform acceptance.`,groups:[{id:`melo-weights`,pathScope:`model`,paths:[`model.onnx`],licenseIds:[`mit-melo`],status:`pending`,summary:`The myshell-ai/MeloTTS-Chinese model card at af5d207a364ea4208c6f589c89f57f88414bdd16 declares license: mit for the model repository; this is separate evidence from the MeloTTS software MIT license. The sherpa conversion package carries the exact MyShell.ai MIT text, and original ONNX metadata declares MIT license, melo-vits version 2, Chinese + English, n_speakers=1 and speaker_id=1. The conversion README explicitly describes a single female Chinese+English speaker. sherpa maps public sid 0 to the internal metadata speaker_id; Pisper does not change the graph, metadata or speaker embedding.`,pendingReasons:[`Exact historical checkpoint, training/conversion commits and reproducible archive build identity have not been established; the inspected conversion workflow uses moving upstream references. Training-data permissions, individual speaker consent and applicable personality/publicity rights are not fully audited. The discovered model card revision is evidence of a declaration, not proof of the historical conversion input.`],evidence:[{url:`https://hf-mirror.com/myshell-ai/MeloTTS-Chinese/resolve/af5d207a364ea4208c6f589c89f57f88414bdd16/README.md`,sha256:`40b5b860bacbb3947cbef838719e660d2fe4961eba5b484290b4bedc0253e208`},{url:`https://raw.githubusercontent.com/myshell-ai/MeloTTS/209145371cff8fc3bd60d7be902ea69cbdb7965a/LICENSE`,sha256:`88a50e5a02bbc2a5c2f084dc19da751aa97b1690f5fda76cd8005c8634d1ca70`},{url:`https://hf-mirror.com/csukuangfj/vits-melo-tts-zh_en/resolve/a0d5c6a264c0ef92d70d8661d8cc502d79627cd6/README.md`,sha256:`ae6e44dead53dfdbd5b4a77106226f3118eb910222b46cb5533a3860773fc6c7`},{url:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/917bed95c8e5c7c18aa4d69fea42e9ef8ef0a60e/scripts/melo-tts/export-onnx.py`,sha256:`c0be7727d59ad6ceaf39e909b4560b57e704091c69ac3fab6f2f2abfd931c916`},{url:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/917bed95c8e5c7c18aa4d69fea42e9ef8ef0a60e/scripts/melo-tts/run.sh`,sha256:`e2afb98d9028eded2983f780468337fc019a8306db926f89e3bdeed18af867bb`},{url:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/917bed95c8e5c7c18aa4d69fea42e9ef8ef0a60e/sherpa-onnx/csrc/offline-tts-vits-model.cc`,sha256:`060907349036d63b60d035843defe7078b83c8099e0d4de323446c7db0d653d0`}]},{id:`melo-tokens`,pathScope:`model`,paths:[`tokens.txt`],licenseIds:[`mit-melo`,`apache-2.0-sherpa`],status:`declared`,summary:`The sherpa Melo export writes enumerated model.hps symbols to tokens.txt. The original 655-byte token file is retained unchanged. Melo software is MIT; sherpa conversion code is Apache-2.0. These code declarations do not independently establish all underlying training-data rights.`,pendingReasons:[],evidence:[{url:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/917bed95c8e5c7c18aa4d69fea42e9ef8ef0a60e/scripts/melo-tts/export-onnx.py`,sha256:`c0be7727d59ad6ceaf39e909b4560b57e704091c69ac3fab6f2f2abfd931c916`},{url:`https://raw.githubusercontent.com/myshell-ai/MeloTTS/209145371cff8fc3bd60d7be902ea69cbdb7965a/LICENSE`,sha256:`88a50e5a02bbc2a5c2f084dc19da751aa97b1690f5fda76cd8005c8634d1ca70`},{url:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/917bed95c8e5c7c18aa4d69fea42e9ef8ef0a60e/LICENSE`,sha256:`cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30`}]},{id:`melo-cppjieba-dictionary`,pathScope:`model`,paths:[`dict/hmm_model.utf8`,`dict/idf.utf8`,`dict/jieba.dict.utf8`,`dict/pos_dict/char_state_tab.utf8`,`dict/pos_dict/prob_emit.utf8`,`dict/pos_dict/prob_start.utf8`,`dict/pos_dict/prob_trans.utf8`,`dict/README.md`,`dict/stop_words.utf8`],licenseIds:[`mit-cppjieba`],status:`confirmed`,summary:`Nine ordinary dictionary/README files are byte-identical to the separately HTTPS-downloaded CppJieba sherpa-onnx-2024-04-19 dict archive. The exact release source MIT license retains Copyright (c) 2013. This confirms the documented source-content match, not a whole-chain data-rights guarantee. The small Melo user.dict.utf8 is separately classified and is NOT the 829194-byte pypinyin-derived user dictionary from that source archive.`,pendingReasons:[],evidence:[{url:`https://ghfast.top/https://github.com/csukuangfj/cppjieba/releases/download/sherpa-onnx-2024-04-19/dict.tar.bz2`,sha256:`35c3877c9b9221a5b2d69bbf57d5dbf1ccbe5b7684c60eb42f93db6b2d494f26`},{url:`https://raw.githubusercontent.com/csukuangfj/cppjieba/f03dd931a00330c279c8590275850fd1f6749a18/LICENSE`,sha256:`ba898a14f729ba5e9965da34e3eecd5edd3795f2cc5d7c923b815ba79bb851b0`},{url:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/917bed95c8e5c7c18aa4d69fea42e9ef8ef0a60e/.github/workflows/export-melo-tts-to-onnx.yaml`,sha256:`fc90fc412fd6f3c8a7d593743372a077dd63b2c8ce0780ed9c3a7e05cc8b659e`}]},{id:`melo-user-dictionary`,pathScope:`model`,paths:[`dict/user.dict.utf8`],licenseIds:[`mit-cppjieba`,`mit-melo`],status:`pending`,summary:`Melo ships an unchanged 49-byte user dictionary containing four entries. It matches the locked Melo HF file but differs from the separately downloaded CppJieba release user dictionary. The package MIT text and CppJieba project MIT declaration are retained as source declarations, not proof that either automatically licenses every edit. This file is not attributed to the unrelated historical pypinyin-derived dictionary.`,pendingReasons:[`The exact historical source commit, modifier and license coverage for this 49-byte replacement have not been identified. Retain applicable modifier notices when established.`],evidence:[{url:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/917bed95c8e5c7c18aa4d69fea42e9ef8ef0a60e/.github/workflows/export-melo-tts-to-onnx.yaml`,sha256:`fc90fc412fd6f3c8a7d593743372a077dd63b2c8ce0780ed9c3a7e05cc8b659e`},{url:`https://raw.githubusercontent.com/csukuangfj/cppjieba/f03dd931a00330c279c8590275850fd1f6749a18/LICENSE`,sha256:`ba898a14f729ba5e9965da34e3eecd5edd3795f2cc5d7c923b815ba79bb851b0`},{url:`https://raw.githubusercontent.com/myshell-ai/MeloTTS/209145371cff8fc3bd60d7be902ea69cbdb7965a/LICENSE`,sha256:`88a50e5a02bbc2a5c2f084dc19da751aa97b1690f5fda76cd8005c8634d1ca70`},{url:`https://huggingface.co/csukuangfj/vits-melo-tts-zh_en/resolve/a0d5c6a264c0ef92d70d8661d8cc502d79627cd6/dict/user.dict.utf8`,sha256:`495bbf49270408a1234690e1e6a97328f30a482a7a72aa769e8a12e8714b0c62`}]},{id:`melo-english-lexicon`,pathScope:`model`,paths:[`lexicon.txt`],licenseIds:[`cmudict-0.6-1998`,`mit-melo`,`apache-2.0-sherpa`],status:`pending`,summary:`The English portion is generated by the sherpa Melo export from melo.text.english.eng_dict and refine_syllables, lowercasing words and adding language tone offsets plus kaldi/SF entries. The inspected Melo source reads cmudict.rep or a cached pickle. cmudict.rep contains its own Copyright 1998 Carnegie Mellon University unrestricted research/commercial permission and attribution notice, retained verbatim in cmudict-0.6-1998. This is NOT a substitution of a modern CMUdict BSD license. The retained notice hash covers the complete original comment header; the evidence hash covers the complete 3969309-byte source file. No package script or pickle was executed.`,pendingReasons:[`The precise historical dictionary/cache inputs and all intervening modifications used for this lexicon have not been pinned or reproduced. Trace cached-data equivalence and retain applicable original and modifier notices.`],evidence:[{url:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/917bed95c8e5c7c18aa4d69fea42e9ef8ef0a60e/scripts/melo-tts/export-onnx.py`,sha256:`c0be7727d59ad6ceaf39e909b4560b57e704091c69ac3fab6f2f2abfd931c916`},{url:`https://raw.githubusercontent.com/myshell-ai/MeloTTS/209145371cff8fc3bd60d7be902ea69cbdb7965a/melo/text/english.py`,sha256:`28527f574511bfc13fe1f2f6bbb5bfe4072c06e1c7e9b69598138aef81b9905b`},{url:`https://raw.githubusercontent.com/myshell-ai/MeloTTS/209145371cff8fc3bd60d7be902ea69cbdb7965a/melo/text/cmudict.rep`,sha256:`d127b5ce8b8e695732701e8efde04b9b0fa11991218b1fb9d21bd0c9264636aa`},{url:`https://raw.githubusercontent.com/myshell-ai/MeloTTS/209145371cff8fc3bd60d7be902ea69cbdb7965a/LICENSE`,sha256:`88a50e5a02bbc2a5c2f084dc19da751aa97b1690f5fda76cd8005c8634d1ca70`},{url:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/917bed95c8e5c7c18aa4d69fea42e9ef8ef0a60e/LICENSE`,sha256:`cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30`}]},{id:`melo-chinese-lexicon`,pathScope:`model`,paths:[`lexicon.txt`],licenseIds:[`mit-pypinyin`,`mit-melo`,`apache-2.0-sherpa`],status:`pending`,summary:`The Chinese portion is generated by the sherpa Melo export from pypinyin character/phrase dictionaries, lazy_pinyin and the Melo pinyin-to-symbol map. Melo code is MIT, sherpa conversion code Apache-2.0, and pypinyin declares MIT. Those software declarations do not relicense external dictionary inputs. The same 6837671-byte mixed-language lexicon is used unchanged on every platform.`,pendingReasons:[`Pin historical pypinyin versions, character/phrase JSON data and Melo phoneme mapping, reproduce the output and trace the actual underlying source-data terms. No particular Zdic, CC-CEDICT or Unihan license is asserted without proof of the actual input chain.`],evidence:[{url:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/917bed95c8e5c7c18aa4d69fea42e9ef8ef0a60e/scripts/melo-tts/export-onnx.py`,sha256:`c0be7727d59ad6ceaf39e909b4560b57e704091c69ac3fab6f2f2abfd931c916`},{url:`https://raw.githubusercontent.com/mozillazg/python-pinyin/8595294b1a97845e30f11ecfdb3caa4e61ac3988/pypinyin/pinyin_dict.py`,sha256:`245c1f70509432b289cde1f938157cd5ff1372d1d083b577d5fab72b4dfcda08`},{url:`https://raw.githubusercontent.com/mozillazg/python-pinyin/8595294b1a97845e30f11ecfdb3caa4e61ac3988/pypinyin/phrases_dict.py`,sha256:`3f6f39bbca68d8d1676ea463cd4620b934b03160cc5042fb9d9007b8f3a80b9e`},{url:`https://raw.githubusercontent.com/mozillazg/python-pinyin/8595294b1a97845e30f11ecfdb3caa4e61ac3988/LICENSE.txt`,sha256:`1e6c90014b4912815c296ee64bb6f6280af47e6d4c5d80e86232dfc5defe764c`},{url:`https://raw.githubusercontent.com/myshell-ai/MeloTTS/209145371cff8fc3bd60d7be902ea69cbdb7965a/LICENSE`,sha256:`88a50e5a02bbc2a5c2f084dc19da751aa97b1690f5fda76cd8005c8634d1ca70`}]},{id:`melo-normalization-fsts`,pathScope:`model`,paths:[`date.fst`,`number.fst`,`phone.fst`],licenseIds:[`apache-2.0-sherpa`],status:`pending`,summary:`All three FSTs are byte-identical to the separately downloaded data/date.fst, data/number.fst and data/phone.fst at csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06 revision 57345c004e13ed640e408c4c29ab56187b18f065, the source repository named by the Melo packaging workflow. That source model card declares Apache-2.0; the full Apache text is retained from sherpa. Neither the OpenFst software license nor the Melo neural-weight MIT declaration independently grants rights to these FST data.`,pendingReasons:[`Exact editable generation rules, compiler/source revisions, underlying data provenance and applicable author/modifier notices remain unverified. No standalone FST LICENSE/NOTICE or complete reproducible source chain was found in the inspected source tree.`],evidence:[{url:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/917bed95c8e5c7c18aa4d69fea42e9ef8ef0a60e/.github/workflows/export-melo-tts-to-onnx.yaml`,sha256:`fc90fc412fd6f3c8a7d593743372a077dd63b2c8ce0780ed9c3a7e05cc8b659e`},{url:`https://hf-mirror.com/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/57345c004e13ed640e408c4c29ab56187b18f065/README.md`,sha256:`98b45ea81164d1e1a1dd82255207053b15cd6c69d922a1c5cf3387ce604d4b74`},{url:`https://hf-mirror.com/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/57345c004e13ed640e408c4c29ab56187b18f065/data/date.fst`,sha256:`eb8aa079ae3cb81d8f4404992f39d61a0cb990947512b5b8d1e54d1f6980e718`},{url:`https://hf-mirror.com/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/57345c004e13ed640e408c4c29ab56187b18f065/data/number.fst`,sha256:`743f402181fcfebf76cc2f0546b71fa26476e626fbe4e460fb7b4c3a7a8bd5bd`},{url:`https://hf-mirror.com/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/57345c004e13ed640e408c4c29ab56187b18f065/data/phone.fst`,sha256:`1ac2b6fa56b1442320c4de7db08353bab8963a2b57f365eebcdd3a2d3562f8d7`},{url:`https://raw.githubusercontent.com/k2-fsa/sherpa-onnx/917bed95c8e5c7c18aa4d69fea42e9ef8ef0a60e/LICENSE`,sha256:`cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30`}]},{id:`melo-package-notices`,pathScope:`model`,paths:[`LICENSE`,`README.md`],licenseIds:[`mit-melo`],status:`confirmed`,summary:`LICENSE is byte-identical to the original MyShell.ai MIT text (Copyright (c) 2024 MyShell.ai), including its exact final newline behavior. README explicitly identifies the single female Chinese+English speaker. The package-level MIT file is not a blanket grant for every bundled dictionary or FST. No upstream NOTICE was listed in the inspected conversion and weight repository trees; this is not proof that none ever existed.`,pendingReasons:[],evidence:[{url:`https://raw.githubusercontent.com/myshell-ai/MeloTTS/209145371cff8fc3bd60d7be902ea69cbdb7965a/LICENSE`,sha256:`88a50e5a02bbc2a5c2f084dc19da751aa97b1690f5fda76cd8005c8634d1ca70`},{url:`https://hf-mirror.com/csukuangfj/vits-melo-tts-zh_en/resolve/a0d5c6a264c0ef92d70d8661d8cc502d79627cd6/README.md`,sha256:`ae6e44dead53dfdbd5b4a77106226f3118eb910222b46cb5533a3860773fc6c7`}]}],modifications:[]}]},la=ca,ua=e=>ca.models.some(t=>t.id===e);function da({modelId:e,modelName:t,returnFocus:n,onClose:r}){let{t:i}=c(),a=la.models.find(t=>t.id===e);if(!a)return null;let o=new Set(a.groups.flatMap(e=>e.licenseIds)),s=la.licenses.filter(e=>o.has(e.id));return(0,Q.jsx)(Pt,{open:!0,onOpenChange:e=>{e||r()},children:(0,Q.jsxs)(Mt,{className:`z-[130] max-h-[85dvh] min-w-0 grid-cols-1 overflow-y-auto rounded-lg sm:max-w-2xl`,overlayClassName:`z-[129]`,onEscapeKeyDown:e=>e.stopPropagation(),onCloseAutoFocus:e=>{e.preventDefault(),n.current?.isConnected&&n.current.focus()},children:[(0,Q.jsxs)(jt,{children:[(0,Q.jsx)(Nt,{children:i(`chat:speechModels.notices`)}),(0,Q.jsxs)(kt,{className:`break-words`,children:[t,` (`,a.revision,`)`]})]}),(0,Q.jsx)(`p`,{className:`break-words text-sm text-muted-foreground`,children:la.scope}),(0,Q.jsx)(`p`,{className:`break-words text-sm text-muted-foreground`,children:la.licenseIdsMeaning}),(0,Q.jsx)(`div`,{className:`min-w-0 divide-y`,children:a.groups.map(e=>(0,Q.jsxs)(`details`,{className:`min-w-0 py-3`,children:[(0,Q.jsxs)(`summary`,{className:`cursor-pointer break-words text-sm font-medium`,children:[e.id,e.status===`pending`&&(0,Q.jsx)(`span`,{className:`ml-2 text-xs font-normal text-amber-700 dark:text-amber-400`,children:i(`chat:speechModels.provenancePending`)})]}),(0,Q.jsxs)(`div`,{className:`mt-3 min-w-0 space-y-3 text-sm`,children:[(0,Q.jsx)(`p`,{className:`break-words`,children:e.summary}),e.pendingReasons.map(e=>(0,Q.jsx)(`p`,{className:`break-words text-muted-foreground`,children:e},e)),(0,Q.jsx)(`pre`,{className:`whitespace-pre-wrap break-all text-xs`,children:JSON.stringify({pathScope:e.pathScope,paths:e.paths,licenseIds:e.licenseIds,evidence:e.evidence},null,2)})]})]},e.id))}),(0,Q.jsxs)(`details`,{className:`min-w-0 border-t pt-3`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium`,children:i(`chat:speechModels.modifications`)}),(0,Q.jsx)(`pre`,{className:`mt-3 whitespace-pre-wrap break-all text-xs`,children:JSON.stringify(a.modifications,null,2)})]}),s.map(e=>(0,Q.jsxs)(`details`,{className:`min-w-0 border-t pt-3`,children:[(0,Q.jsxs)(`summary`,{className:`cursor-pointer break-words text-sm font-medium`,children:[e.name,` (`,e.id,`)`]}),(0,Q.jsx)(`pre`,{className:`mt-3 whitespace-pre-wrap break-words text-xs`,children:e.text})]},e.id)),(0,Q.jsx)(`div`,{className:`flex justify-end border-t pt-3`,children:(0,Q.jsxs)(I,{children:[(0,Q.jsx)(P,{asChild:!0,children:(0,Q.jsx)(J,{size:`icon-sm`,variant:`outline`,onClick:()=>{let e=new Blob([JSON.stringify({...la,models:[a],licenses:s},null,2)],{type:`application/json;charset=utf-8`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${a.id}-notices.json`,n.click(),window.setTimeout(()=>URL.revokeObjectURL(t),0)},"aria-label":i(`chat:speechModels.downloadNotices`),children:(0,Q.jsx)(U,{})})}),(0,Q.jsx)(F,{children:i(`chat:speechModels.downloadNotices`)})]})})]})})}var fa=e=>`${new Intl.NumberFormat(void 0,{maximumFractionDigits:1}).format(e/1048576)} MiB`;function pa({manager:e,onClose:t}){let{t:n}=c(),[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(``),[s,l]=(0,Z.useState)(null),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=()=>{u.current?.abort(),u.current=null,i(!1)};(0,Z.useEffect)(()=>(e.open||(u.current?.abort(),u.current=null,i(!1),l(null)),()=>{u.current?.abort(),u.current=null}),[e.open]);let p={"not-installed":n(`chat:speechModels.notInstalled`),downloading:n(`chat:speechModels.downloading`),verifying:n(`chat:speechModels.verifying`),installed:n(`chat:speechModels.installed`),cancelled:n(`chat:speechModels.cancelled`),error:n(`chat:speechModels.failed`)},m=e.models.flatMap(e=>e.voices||[]),h=m.find(t=>t.id===e.selectedVoice),g=e.models.some(e=>e.kind===`tts`&&e.status===`installed`),_=e.models.filter(e=>e.status!==`installed`),v=_.some(e=>[`downloading`,`verifying`].includes(e.status)),y=()=>{l(null),f(),e.close(),t()},b=async()=>{if(u.current){f();return}if(!h||!g||_.length)return;let e=new AbortController;u.current=e,i(!0),o(``);try{await oa(h.language===`en`?n(`chat:speechModels.previewEnglish`):n(`chat:speechModels.previewChinese`),h.id,e.signal)}catch(t){e.signal.aborted||o(t instanceof Error?t.message:String(t))}finally{u.current===e&&(u.current=null,i(!1))}};return(0,Q.jsxs)(Pt,{open:e.open,onOpenChange:e=>{e||y()},children:[(0,Q.jsxs)(Mt,{className:`z-[110] max-h-[85dvh] overflow-y-auto rounded-lg sm:max-w-md`,overlayClassName:`z-[109]`,onEscapeKeyDown:e=>e.stopPropagation(),children:[(0,Q.jsxs)(jt,{children:[(0,Q.jsx)(Nt,{children:n(`chat:speechModels.title`)}),(0,Q.jsx)(kt,{className:`sr-only`,children:n(`chat:speechModels.title`)})]}),!e.catalog&&!e.error&&(0,Q.jsx)(Ue,{className:`mx-auto my-4 size-5 animate-spin`,"aria-label":n(`chat:speechModels.loading`)}),(0,Q.jsx)(`div`,{className:`min-w-0 divide-y`,children:e.models.map(t=>{let r=[`downloading`,`verifying`].includes(t.status),i=t.totalBytes?Math.min(100,Math.floor(t.downloadedBytes/t.totalBytes*100)):0,a=t.license?.url.startsWith(`https://`)?t.license.url:void 0;return(0,Q.jsxs)(`section`,{className:`min-w-0 space-y-2 py-3 first:pt-0`,"aria-label":t.name,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t.kind===`asr`?n(`chat:speechModels.recognition`):n(`chat:speechModels.synthesis`)}),(0,Q.jsx)(`div`,{className:`break-words font-medium`,children:t.name})]}),t.status===`installed`?(0,Q.jsx)(ue,{className:`size-5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-label":p.installed}):(0,Q.jsxs)(I,{children:[(0,Q.jsx)(P,{asChild:!0,children:(0,Q.jsx)(J,{size:`icon-sm`,variant:`outline`,disabled:e.loading,onClick:()=>{r?e.cancelDownload(t.id):e.download(t.id)},"aria-label":n(r?`chat:speechModels.cancelDownload`:`chat:speechModels.download`),children:r?(0,Q.jsx)(nt,{}):(0,Q.jsx)(U,{})})}),(0,Q.jsx)(F,{children:n(r?`chat:speechModels.cancelDownload`:`chat:speechModels.download`)})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-3 gap-y-1 text-xs text-muted-foreground`,children:[(0,Q.jsx)(`span`,{children:p[t.status]}),(0,Q.jsx)(`span`,{className:`tabular-nums`,children:r?`${fa(t.downloadedBytes)} / ${fa(t.totalBytes)}`:fa(t.totalBytes)})]}),r&&(0,Q.jsx)(A,{value:i,"aria-label":t.name,"aria-valuenow":i,"aria-valuemin":0,"aria-valuemax":100}),t.error&&(0,Q.jsx)(`p`,{role:`alert`,className:`break-words text-xs text-destructive`,children:t.error}),t.license&&(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[(0,Q.jsx)(`a`,{href:a,target:`_blank`,rel:`noreferrer`,className:`block break-words text-[11px] text-muted-foreground underline underline-offset-2`,children:t.license.name}),ua(t.id)&&(0,Q.jsxs)(I,{children:[(0,Q.jsx)(P,{asChild:!0,children:(0,Q.jsx)(J,{size:`icon-sm`,variant:`ghost`,"aria-label":n(`chat:speechModels.notices`),onClick:e=>{d.current=e.currentTarget,f(),l(t)},children:(0,Q.jsx)(nr,{})})}),(0,Q.jsx)(F,{children:n(`chat:speechModels.notices`)})]})]})]},t.id)})}),m.length>0&&(0,Q.jsx)(`div`,{className:`space-y-2 border-t pt-3`,children:(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 text-sm`,children:n(`chat:speechModels.voice`)}),(0,Q.jsxs)(I,{children:[(0,Q.jsx)(P,{asChild:!0,children:(0,Q.jsx)(J,{size:`icon`,variant:`outline`,disabled:!g||_.length>0,onClick:()=>void b(),"aria-label":n(r?`chat:speechModels.stopPreview`:`chat:speechModels.preview`),children:r?(0,Q.jsx)(nt,{}):(0,Q.jsx)(Je,{})})}),(0,Q.jsx)(F,{children:n(r?`chat:speechModels.stopPreview`:`chat:speechModels.preview`)})]})]})}),(e.error||a)&&(0,Q.jsx)(`p`,{role:`alert`,className:`break-words text-sm text-destructive`,children:e.error||a}),(0,Q.jsx)(`div`,{className:`flex justify-end border-t pt-3`,children:_.length?(0,Q.jsxs)(J,{disabled:e.loading||v,onClick:()=>void e.downloadAll(),children:[(0,Q.jsx)(U,{}),n(`chat:speechModels.downloadAll`)]}):(0,Q.jsx)(J,{disabled:!e.catalog,onClick:y,children:n(`chat:speechModels.done`)})})]}),e.open&&s&&(0,Q.jsx)(da,{modelId:s.id,modelName:s.name,returnFocus:d,onClose:()=>l(null)})]})}var ma=16e3,ha=ma*60;function ga(e,t){let n=window.__TAURI__?.core?.invoke??window.__TAURI_INTERNALS__?.invoke;return n?n(e,t):Promise.reject(Error(`移动端原生桥不可用。`))}async function _a(){if(!(typeof window>`u`||!window.__PISPER_MOBILE_APP__)&&(await ga(`mobile_request_microphone_permission`)).state!==`granted`)throw Error(`microphone_permission_denied`)}async function va(e){let t=await e.text().catch(()=>``);try{return JSON.parse(t).error||`语音转写失败 (${e.status})`}catch{return t||`语音转写失败 (${e.status})`}}function ya(e){let t=e.reduce((e,t)=>e+t.length,0),n=new Float32Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}var ba=class{chatSessionId;chunks=[];pending=[];listeners=new Set;controller=null;sessionId=``;nativeRequestId=``;legacy=!1;flushTimer=0;sendChain=Promise.resolve();finished=!1;retainedSamples=0;terms=[];initializing=null;constructor(e=``){this.chatSessionId=e}start(){return this.initializing=this.initialize().catch(async e=>{throw await this.cancel(),e}),this.initializing}async initialize(){this.chunks=[],this.pending=[],this.finished=!1,this.retainedSamples=0;let e=new AbortController;this.controller=e,await gt(),q(e.signal);let{loadSpeechHotwords:n,prepareSpeechSession:r}=await t(async()=>{let{loadSpeechHotwords:e,prepareSpeechSession:t}=await import(`./speech-session-CoUr4n9Q.js`).then(e=>e.r);return{loadSpeechHotwords:e,prepareSpeechSession:t}},__vite__mapDeps([11,2,3,4,10,12,13,14,15,16,17])),{terms:i,hotwords:a}=await n(this.chatSessionId,e.signal);this.terms=i;let o=await r({kinds:[`asr`],hotwords:a},e.signal);if(q(o.signal),o.signal.addEventListener(`abort`,()=>{this.controller===e&&!e.signal.aborted&&this.cancel()},{once:!0}),window.__PISPER_MOBILE_APP__)return;let s=_t(e.signal,3e4);try{let t=await fetch(`/api/speech/stream/start`,{method:`POST`,headers:{"X-Pisper-Chat-Session":this.chatSessionId},signal:s.signal});if(!t.ok){if(t.status===404){this.legacy=!0;return}throw Error(await va(t))}let n=await t.json();if(!n.id)throw Error(`语音识别会话创建失败。`);e.signal.aborted&&(await fetch(`/api/speech/stream/cancel`,{method:`POST`,headers:{"X-Pisper-Speech-Session":n.id}}).catch(()=>{}),q(e.signal)),this.sessionId=n.id,this.pending.push(...this.chunks.splice(0)),this.retainedSamples=0,this.flushTimer=window.setInterval(()=>void this.flushPending(),1e3)}finally{s.dispose()}}acceptPcm(e){if(!e.length||this.finished)return!1;if(window.__PISPER_MOBILE_APP__||!this.sessionId){let t=ha-this.retainedSamples;if(t<=0)return!0;let n=e.slice(0,t);return this.chunks.push(n),this.retainedSamples+=n.length,this.retainedSamples>=ha}let t=e.slice();return this.sessionId&&!this.legacy?this.pending.push(t):this.chunks.push(t),!1}onPartial(e){return this.listeners.add(e),()=>this.listeners.delete(e)}emitPartial(e){if(e)for(let t of this.listeners)t(e)}flushPending(){return this.sendChain=this.sendChain.then(async()=>{if(!this.sessionId||this.legacy||this.finished||!this.pending.length)return;let e=ya(this.pending.splice(0));try{let t=await fetch(`/api/speech/stream/chunk`,{method:`POST`,headers:{"Content-Type":`application/octet-stream`,"X-Pisper-Sample-Rate":String(ma),"X-Pisper-Speech-Session":this.sessionId},body:e.buffer,signal:this.controller?.signal});if(!t.ok)return;let n=await t.json();typeof n.text==`string`&&this.emitPartial(n.text.trim())}catch{}}),this.sendChain}async finishStreaming(){window.clearInterval(this.flushTimer),this.flushTimer=0,await this.flushPending(),this.finished=!0;let e=await fetch(`/api/speech/stream/finish`,{method:`POST`,headers:{"X-Pisper-Speech-Session":this.sessionId},signal:this.controller?.signal});if(!e.ok)throw Error(await va(e));let t=await e.json(),n=typeof t.text==`string`?t.text.trim():``;if(!n)throw Error(`未识别到语音内容。`);return this.emitPartial(n),n}async finishOneShot(e){if(window.__PISPER_MOBILE_APP__){let t=new Uint8Array(e.buffer),n=``,r=32768;for(let e=0;e<t.length;e+=r)n+=String.fromCharCode(...t.subarray(e,e+r));let i=this.controller;if(!i)throw new DOMException(`Speech recognition cancelled.`,`AbortError`);q(i.signal);let a=crypto.randomUUID();this.nativeRequestId=a;let o=await ga(`mobile_transcribe_pcm`,{pcmBase64:btoa(n),hotwords:xn(this.terms),requestId:a});if(q(i.signal),this.controller!==i)throw new DOMException(`Speech recognition cancelled.`,`AbortError`);let s=Cn(typeof o.text==`string`?o.text.trim():``,this.terms);if(!s)throw Error(`未识别到语音内容。`);return this.emitPartial(s),s}let t=await fetch(`/api/speech/transcribe`,{method:`POST`,headers:{"Content-Type":`application/octet-stream`,"X-Pisper-Sample-Rate":String(ma),"X-Pisper-Chat-Session":this.chatSessionId},body:e.buffer,signal:this.controller?.signal});if(!t.ok)throw Error(await va(t));let n=await t.json(),r=typeof n.text==`string`?n.text.trim():``;if(!r)throw Error(`未识别到语音内容。`);return this.emitPartial(r),r}async finish(){if(await this.initializing,!this.controller)throw Error(`语音识别尚未启动。`);if(this.sessionId&&!this.legacy)return this.finishStreaming();this.finished=!0;let e=ya(this.chunks);if(!e.length)throw Error(`没有采集到语音。`);return this.finishOneShot(e)}async cancel(){if(this.finished=!0,window.clearInterval(this.flushTimer),this.flushTimer=0,this.controller?.abort(),this.controller=null,this.chunks=[],this.pending=[],this.retainedSamples=0,this.nativeRequestId){let e=this.nativeRequestId;this.nativeRequestId=``,await ga(`mobile_cancel_speech`,{requestId:e}).catch(()=>{})}if(this.sessionId&&!this.legacy){let e=this.sessionId;this.sessionId=``,await fetch(`/api/speech/stream/cancel`,{method:`POST`,headers:{"X-Pisper-Speech-Session":e}}).catch(()=>{})}}async dispose(){await this.cancel(),this.listeners.clear()}};function xa({chatSessionId:e=``}={}){return new ba(e)}var Sa=`
|
|
513
|
+
class PisperVoiceInputProcessor extends AudioWorkletProcessor {
|
|
514
|
+
constructor(options) {
|
|
515
|
+
super()
|
|
516
|
+
this.targetSampleRate = Number(options?.processorOptions?.targetSampleRate) || 16000
|
|
517
|
+
this.inputSampleRate = sampleRate
|
|
518
|
+
this.ratio = this.inputSampleRate / this.targetSampleRate
|
|
519
|
+
this.inputBuffer = []
|
|
520
|
+
this.readPosition = 0
|
|
521
|
+
this.outputBuffer = []
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
process(inputs, outputs) {
|
|
525
|
+
const channel = inputs[0]?.[0]
|
|
526
|
+
if (channel?.length) {
|
|
527
|
+
for (const sample of channel) this.inputBuffer.push(sample)
|
|
528
|
+
while (this.readPosition + 1 < this.inputBuffer.length) {
|
|
529
|
+
const index = Math.floor(this.readPosition)
|
|
530
|
+
const fraction = this.readPosition - index
|
|
531
|
+
const current = this.inputBuffer[index]
|
|
532
|
+
const next = this.inputBuffer[index + 1]
|
|
533
|
+
this.outputBuffer.push(current + (next - current) * fraction)
|
|
534
|
+
this.readPosition += this.ratio
|
|
535
|
+
}
|
|
536
|
+
const consumed = Math.min(Math.floor(this.readPosition), this.inputBuffer.length)
|
|
537
|
+
if (consumed > 0) {
|
|
538
|
+
this.inputBuffer = this.inputBuffer.slice(consumed)
|
|
539
|
+
this.readPosition -= consumed
|
|
540
|
+
}
|
|
541
|
+
while (this.outputBuffer.length >= 320) {
|
|
542
|
+
const chunk = new Float32Array(this.outputBuffer.splice(0, 320))
|
|
543
|
+
this.port.postMessage(chunk.buffer, [chunk.buffer])
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
const output = outputs[0]?.[0]
|
|
547
|
+
if (output) output.fill(0)
|
|
548
|
+
return true
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
registerProcessor('pisper-voice-input', PisperVoiceInputProcessor)
|
|
552
|
+
`;async function Ca(e){let t=new Blob([Sa],{type:`application/javascript`}),n=URL.createObjectURL(t);try{await e.audioWorklet.addModule(n)}finally{URL.revokeObjectURL(n)}}async function wa(e,t){if(q(t),!navigator.mediaDevices?.getUserMedia)throw Error(`当前环境不支持麦克风采集。`);if(!window.AudioContext&&!window.webkitAudioContext)throw Error(`当前环境不支持音频处理。`);let n=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0},video:!1}),r=null,i=null,a=null,o=null,s=!1,c=null,l=()=>{if(s)return c??Promise.resolve();s=!0,t?.removeEventListener(`abort`,u);for(let e of n.getTracks())e.removeEventListener?.(`ended`,d),e.removeEventListener?.(`mute`,d),e.stop();return c=r?.close().catch(()=>{})??Promise.resolve(),i&&(i.port.onmessage=null,i.port.close()),a?.disconnect(),i?.disconnect(),o?.disconnect(),c},u=()=>{l()},d=()=>{s||(l(),window.dispatchEvent(new Event(`pisper:speech-interrupted`)))},f=()=>{if(q(t),s)throw new DOMException(`Microphone capture was interrupted.`,`AbortError`)};t?.addEventListener(`abort`,u,{once:!0});for(let e of n.getTracks()){if(s)break;e.addEventListener?.(`ended`,d),e.addEventListener?.(`mute`,d),e.readyState===`ended`&&d()}try{f(),r=new(window.AudioContext||window.webkitAudioContext)({latencyHint:`interactive`}),await Ca(r),f(),a=r.createMediaStreamSource(n),i=new AudioWorkletNode(r,`pisper-voice-input`,{numberOfInputs:1,numberOfOutputs:1,outputChannelCount:[1],processorOptions:{targetSampleRate:ma}}),o=r.createGain(),o.gain.value=0,i.port.onmessage=n=>{!s&&!t?.aborted&&e(new Float32Array(n.data))},a.connect(i),i.connect(o),o.connect(r.destination),await r.resume(),f()}catch(e){throw await l(),e}return{stop:l}}var Ta=32,Ea=50;function Da(e,t){if(e instanceof DOMException&&e.name===`NotAllowedError`)return`permission`;let n=typeof e==`string`?e:e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):``;return n.includes(`microphone_permission_denied`)?`permission`:n||t}function Oa({onInsert:e,onLiveText:t,sessionId:n,disabled:r=!1,shortcutEnabled:i=!1}){let{t:a}=c(),o=$i([`asr`]),s=Kt(e=>e.bindings.voiceInput),[l,u]=(0,Z.useState)(`idle`),[d,f]=(0,Z.useState)(``),p=(0,Z.useRef)(`idle`),m=e=>{p.current=e,u(e)},h=(0,Z.useRef)(null),g=(0,Z.useRef)(null),_=(0,Z.useRef)(null),v=(0,Z.useRef)(null),y=(0,Z.useRef)(0),b=(0,Z.useRef)(0),x=(0,Z.useRef)(()=>{}),S=(0,Z.useRef)(!1),C=(0,Z.useRef)(null),w=(0,Z.useRef)(null),T=(0,Z.useRef)(()=>{}),E=(0,Z.useRef)(0),D=(0,Z.useRef)(Gi()),O=(0,Z.useRef)(0),[k,A]=(0,Z.useState)([]),j=(0,Z.useRef)([]),M=(0,Z.useRef)(null),N=(0,Z.useRef)(e),P=(0,Z.useRef)(t);N.current=e,P.current=t;let F=()=>{window.clearTimeout(b.current),b.current=0},I=async()=>{F();let e=_.current;_.current=null,e?.abort(),v.current?.(),v.current=null,M.current?.dispose(),M.current=null;let t=g.current;g.current=null;let n=h.current;h.current=null,await Promise.allSettled([t?.stop(),n?.dispose()])},L=e=>{console.warn(`[voice-input]`,e),f(e),m(`error`),window.clearTimeout(E.current),E.current=window.setTimeout(()=>{p.current===`error`&&(f(``),m(`idle`))},4e3)},R=()=>{F(),S.current=!1,m(`idle`),f(``)},z=()=>{C.current=null,w.current=null,y.current+=1,I(),P.current?.(null),R()};T.current=z,(0,Z.useEffect)(()=>{let e=()=>{(w.current!==y.current||C.current===y.current)&&T.current()},t=()=>{document.visibilityState===`hidden`&&e()},n=()=>T.current();return window.addEventListener(`blur`,e),window.addEventListener(`pisper:speech-interrupted`,n),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`pisper:speech-interrupted`,n),document.removeEventListener(`visibilitychange`,t),window.clearTimeout(E.current),e()}},[n,i,r]),(0,Z.useEffect)(()=>{if(l!==`recording`){A([]),j.current=[];return}let e=()=>{let e=performance.now()/1e3,t=O.current,n=j.current,r=[];for(let i=0;i<Ta;i+=1){let a=i/31*2-1,o=Math.cos(a*Math.PI/2)**1.3,s=.1+.06*Math.sin(e*2.2+i*.55)+.04*Math.sin(e*3.7+i*.21),c=.75+.5*Math.abs(Math.sin(e*9+i*1.7)),l=Math.min(1,Math.max(.05,s+t*o*c*1.15)),u=n[i]??l,d=l>u?.55:.28;r.push(u+(l-u)*d)}j.current=r,A(r)};e();let t=window.setInterval(e,Ea);return()=>window.clearInterval(t)},[l]);let B=()=>!r&&(p.current===`idle`||p.current===`error`),ee=async()=>{if(!B())return;let e=++y.current,t=new AbortController;_.current=t,S.current=!1,m(`requesting`),f(``),D.current.reset();let r=xa({chatSessionId:n});h.current=r,v.current=r.onPartial(e=>{h.current===r&&P.current?.(e)});let i=null,s=async t=>{if(i?.dispose(),i=null,e!==y.current)return;if(t instanceof DOMException&&t.name===`AbortError`){let e=++y.current;if(await I(),e!==y.current)return;R();return}let n=++y.current;if(await I(),n!==y.current)return;let r=Da(t,a(`chat:voiceInput.failed`));L(r===`permission`?a(`chat:voiceInput.permissionDenied`):r)};try{window.__PISPER_MOBILE_APP__&&(w.current=e);try{await _a()}finally{w.current===e&&(w.current=null)}if(e!==y.current)return;if(window.__PISPER_MOBILE_APP__&&document.visibilityState===`hidden`){z();return}if(await o.ensureReady(t.signal),e!==y.current)return;if(r.start().then(()=>{},()=>s(Error(a(`chat:voiceInput.failed`)))),i=await Zi(),e!==y.current){i.dispose();return}M.current=i;let n=i,c=await wa(t=>{if(e!==y.current)return;O.current=D.current.push(Wi(t));let i=n.acceptPcm(t);(r.acceptPcm(t)||i)&&x.current()},t.signal);if(e!==y.current){await c.stop();return}g.current=c,m(`recording`),window.__PISPER_MOBILE_APP__&&(b.current=window.setTimeout(()=>x.current(),6e4))}catch(e){await s(e)}},V=async()=>{if(p.current!==`recording`||S.current)return;C.current=null,S.current=!0,F();let e=++y.current;m(`transcribing`);let t=_.current;_.current=null,t?.abort();let n=g.current;g.current=null;let r=M.current;M.current=null;let i=h.current;try{if(await n?.stop(),e!==y.current)return;if(r&&!r.hasSpeech){if(r.dispose(),P.current?.(null),await I(),e!==y.current)return;R();return}r?.dispose();let t=await i?.finish();if(e!==y.current)return;if(!t)throw Error(a(`chat:voiceInput.empty`));if(N.current(t),await I(),e!==y.current)return;R()}catch(t){if(e!==y.current||(await I(),e!==y.current))return;P.current?.(null);let n=Da(t,a(`chat:voiceInput.failed`));L(n===`permission`?a(`chat:voiceInput.permissionDenied`):n),S.current=!1}};x.current=()=>void V(),Ui({enabled:i&&!r,binding:s,onStart:()=>B()?(ee(),C.current=y.current,!0):!1,onRelease:()=>{C.current===y.current&&(g.current?V():z())},onCancel:()=>{C.current===y.current&&z()}});let te=l===`recording`?a(`chat:voiceInput.stop`):l===`requesting`?a(`chat:voiceInput.close`):l===`error`?d:a(`chat:voiceInput.open`),ne=s&&l!==`error`?`${te} (${qt(s)})`:te;return(0,Q.jsxs)(`div`,{className:`relative flex flex-none items-center`,children:[l===`recording`&&(0,_r.createPortal)((0,Q.jsx)(`div`,{"aria-hidden":`true`,className:`voice-capsule-pop pointer-events-none fixed bottom-4 left-1/2 z-[80] flex h-10 -translate-x-1/2 items-center gap-[3px] rounded-full border border-[rgba(125,211,252,.35)] bg-[#10141c]/95 px-4`,style:{boxShadow:`0 8px 30px -8px rgba(0,0,0,.55), 0 0 ${14+O.current*26}px rgba(80,180,255,${(.18+O.current*.4).toFixed(3)})`},children:k.map((e,t)=>(0,Q.jsx)(`span`,{className:`w-[3px] rounded-full`,style:{height:`${(3+e*19).toFixed(1)}px`,background:`linear-gradient(180deg, hsl(${210-e*45} 92% ${62+e*10}%), hsl(${222-e*30} 85% ${48+e*8}%))`,transition:`height 70ms linear, background 200ms linear`}},t))}),document.body),l===`error`&&(0,_r.createPortal)((0,Q.jsxs)(`button`,{type:`button`,className:`voice-capsule-pop fixed bottom-4 left-1/2 z-[80] flex h-9 max-w-[min(480px,calc(100vw-32px))] -translate-x-1/2 cursor-pointer items-center gap-2 rounded-full border border-[rgba(248,113,113,.4)] bg-[#1c1012]/95 px-4 text-[12px] text-[#fca5a5] shadow-[0_10px_30px_-10px_rgba(0,0,0,.5)]`,onClick:()=>{window.clearTimeout(E.current),f(``),m(`idle`)},children:[(0,Q.jsx)(cr,{size:13,className:`flex-none`}),(0,Q.jsx)(`span`,{className:`truncate`,children:d})]}),document.body),(0,Q.jsxs)(`button`,{type:`button`,className:`relative grid !size-11 !min-w-11 place-items-center rounded-[var(--r-sm)] border transition-[background-color,color,border-color,box-shadow,transform] duration-200 hover:scale-105 disabled:cursor-not-allowed disabled:opacity-45 ${l===`recording`?`border-[var(--danger)] bg-[var(--danger-soft)] text-[var(--danger-strong)] shadow-[0_0_0_3px_var(--danger-soft)]`:l===`transcribing`||l===`requesting`?`border-transparent bg-[var(--brand-blue-soft)] text-[var(--brand-blue-strong)]`:l===`error`?`border-transparent bg-[var(--danger-soft)] text-[var(--danger-strong)]`:`border-transparent bg-[var(--surface-subtle)] text-[var(--text-muted)] hover:border-[var(--brand-blue)] hover:bg-[var(--brand-blue-soft)] hover:text-[var(--brand-blue-strong)]`}`,title:ne,"aria-label":a(l===`recording`?`chat:voiceInput.stop`:`chat:voiceInput.open`),"aria-pressed":l===`recording`,disabled:r||l===`transcribing`,onClick:l===`recording`?()=>void V():l===`requesting`?()=>z():()=>void ee(),children:[l===`recording`&&(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`absolute inset-0 animate-ping rounded-[var(--r-sm)] bg-[var(--danger)] opacity-25`}),l===`recording`?(0,Q.jsx)(cr,{size:17}):l===`transcribing`||l===`requesting`?(0,Q.jsx)(Ue,{className:`animate-spin`,size:17}):l===`error`?(0,Q.jsx)(cr,{size:17}):(0,Q.jsx)(lr,{size:17})]}),(0,Q.jsx)(pa,{manager:o,onClose:()=>{}})]})}var ka={idle:{amp:.14,freq:1.7,speed:.22,spike:0,rot:.22,dim:.8,behavior:`calm`},requesting:{amp:.08,freq:1.6,speed:.3,spike:0,rot:.4,dim:.5,behavior:`calm`},listening:{amp:.15,freq:2,speed:.55,spike:.55,rot:.4,dim:1,behavior:`reactive`},transcribing:{amp:.08,freq:1.8,speed:1,spike:0,rot:1.5,dim:.95,behavior:`converge`},thinking:{amp:.2,freq:2.3,speed:.8,spike:0,rot:.85,dim:1,behavior:`swirl`},speaking:{amp:.13,freq:1.9,speed:.5,spike:.1,rot:.35,dim:1,behavior:`beat`},error:{amp:.12,freq:2.2,speed:1.2,spike:0,rot:.1,dim:.9,behavior:`jitter`}},Aa=64,ja=96,Ma=2.6,Na=Math.PI*2,Pa={dark:{base:[223,233,255],cyan:[89,230,255],magenta:[255,95,210],haloInner:[70,110,170],haloMid:[50,80,140],haloAlpha:.1,composite:`lighter`,alphaBase:.1,alphaFront:.68},light:{base:[34,44,76],cyan:[6,132,180],magenta:[176,48,150],haloInner:[110,140,210],haloMid:[130,160,220],haloAlpha:.16,composite:`source-over`,alphaBase:.18,alphaFront:.85}};function Fa(e,t,n){let r=Math.sin(e*127.1+t*311.7+n*74.7)*43758.5453123;return r-Math.floor(r)}function Ia(e){return e*e*(3-2*e)}function La(e,t,n){let r=Math.floor(e),i=Math.floor(t),a=Math.floor(n),o=Ia(e-r),s=Ia(t-i),c=Ia(n-a),l=0;for(let e=0;e<=1;e+=1)for(let t=0;t<=1;t+=1)for(let n=0;n<=1;n+=1)l+=(e?o:1-o)*(t?s:1-s)*(n?c:1-c)*Fa(r+e,i+t,a+n);return l}function Ra(e){return 1+2.70158*(e-1)**3+1.70158*(e-1)**2}function za(e){let t=e*.9%1;return Math.exp(-(((t-.12)*9)**2))+.45*Math.exp(-(((t-.34)*9)**2))}function Ba({stage:e,level:t,size:n=380,dark:r=!0}){let i=(0,Z.useRef)(null),a=(0,Z.useRef)(e),o=(0,Z.useRef)(t),s=(0,Z.useRef)(r);return a.current=e,o.current=t,s.current=r,(0,Z.useEffect)(()=>{let e=i.current;if(!e)return;let t=e.getContext(`2d`);if(!t)return;let r=Math.min(window.devicePixelRatio||1,2);e.width=n*r,e.height=n*r,t.scale(r,r);let c=new Float32Array(Aa),l=new Float32Array(Aa);for(let e=0;e<Aa;e+=1){let t=-Math.PI/2+(e+.5)/Aa*Math.PI;c[e]=Math.sin(t),l[e]=Math.cos(t)}let u=new Float32Array(ja),d=new Float32Array(ja);for(let e=0;e<ja;e+=1){let t=e/ja*Na;u[e]=Math.cos(t),d[e]=Math.sin(t)}let f=n/2,p=n*.31,m=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,h=0,g=performance.now(),_=g,v=0,y=0,b={...ka[a.current]},x=0,S=0,C=0,w=e=>{let r=Math.min((e-g)/1e3,.05);g=e;let i=ka[a.current],T=Math.min(1,r*5);b={...i,amp:b.amp+(i.amp-b.amp)*T,freq:b.freq+(i.freq-b.freq)*T,speed:b.speed+(i.speed-b.speed)*T,spike:b.spike+(i.spike-b.spike)*T,rot:b.rot+(i.rot-b.rot)*T,dim:b.dim+(i.dim-b.dim)*T};let E=m?.35:1;v+=r*E,y+=b.rot*r*E,x+=(o.current-x)*Math.min(1,r*14);let D=Math.max(0,x-S-.02);S=x,C=Math.min(.6,C*.02**r+D*2.4);let O=x;b.behavior===`beat`?O=Math.max(.08,.4+.28*Math.abs(Math.sin(v*5.2))*Math.sin(v*1.6)+.12*Math.sin(v*9.1)):b.behavior===`converge`?O=.18:b.behavior===`jitter`?O=.3+.2*Math.sin(v*17):b.behavior!==`reactive`&&(O=.1+.05*Math.sin(v*1.3));let k=Ra(Math.min(1,Math.max(0,(e-_)/900))),A=b.behavior===`beat`?O:za(v)*.5+O*.5,j=k*(1+A*.04+C*.1);b.behavior===`converge`&&(j*=.9+.1*Math.sin(v*4.2)),t.clearRect(0,0,n,n);let M=Pa[s.current?`dark`:`light`],N=t.createRadialGradient(f,f,0,f,f,p*1.7);N.addColorStop(0,`rgba(${M.haloInner[0]},${M.haloInner[1]},${M.haloInner[2]},${(M.haloAlpha*b.dim).toFixed(3)})`),N.addColorStop(.6,`rgba(${M.haloMid[0]},${M.haloMid[1]},${M.haloMid[2]},${(M.haloAlpha*.5*b.dim).toFixed(3)})`),N.addColorStop(1,`rgba(0,0,0,0)`),t.fillStyle=N,t.fillRect(0,0,n,n);let P=Math.sin(y),F=Math.cos(y),I=.38,L=Math.sin(I),R=Math.cos(I),z=v*b.speed,B=b.freq,ee=b.amp*j,V=b.spike*(O+C),te=p*j,ne=Math.floor(v*15),re=b.dim*(.72+.5*A)+C*.3;t.globalCompositeOperation=M.composite;for(let e=0;e<Aa;e+=1){let n=c[e],r=l[e];for(let i=0;i<ja;i+=1){let a=r*u[i],o=n,s=r*d[i],c=La(a*B+z,o*B+z*.7,s*B)-.5,l=1+c*2*ee;b.behavior===`reactive`?l+=Math.max(c,0)**2*1.7*V:b.behavior===`swirl`?l+=.03*Math.sin(9*a+v*4.6):b.behavior===`jitter`&&(l+=.02*(Fa(e*ja+i,ne,3)-.5));let p=a*l,m=o*l,h=s*l,g=p*F-h*P,_=p*P+h*F,y=m*R-_*L,x=m*L+_*R,S=Ma/(Ma-x),C=f+g*S*te,w=f+y*S*te,T=(x+1)/2,E=La(a*1.25+31,o*1.25+z*.12,s*1.25-17),D=M.base;E>.62?D=M.magenta:E<.38&&(D=M.cyan);let O=(M.alphaBase+M.alphaFront*T*T)*re;if(O<.015)continue;let k=(1+1.4*T+V*.4)*(.55+.45*S);t.fillStyle=`rgba(${D[0]},${D[1]},${D[2]},${O.toFixed(3)})`,t.fillRect(C,w,k,k)}}t.globalCompositeOperation=`source-over`,h=requestAnimationFrame(w)};return h=requestAnimationFrame(w),()=>cancelAnimationFrame(h)},[n]),(0,Q.jsx)(`canvas`,{ref:i,className:`pointer-events-none block`,style:{width:n,height:n},"aria-hidden":`true`})}var Va=new Map;function Ha(e,t){let n=Va.get(e)??new Set;return n.add(t),Va.set(e,n),()=>{n.delete(t),n.size||Va.delete(e)}}function Ua(e){for(let t of Va.get(e.sessionId)??[])t(e)}function Wa(e,t){let n=t.messages.length-1;for(;n>=0&&t.messages[n].role!==`user`;)--n;let r=t.messages.slice(n+1).filter(e=>e.role===`agent`||e.role===`assistant`),i=r.find(e=>e.streaming)??r.at(-1);Ua({sessionId:e,messageId:i?.id??``,prompt:t.messages[n]?.text,startedAt:t.startedAt??void 0,source:`snapshot`,users:t.messages.filter(e=>e.role===`user`),text:i?.text??``,status:t.error||i?.error?`failed`:t.streaming?i?`streaming`:`started`:`completed`,error:t.error||i?.error})}function Ga(e){let t=``,n=0,r=!1,i,a,o=()=>{a?.(),a=void 0},s=()=>{i=vt(e),o()};return e.addEventListener(`abort`,s,{once:!0}),e.aborted&&s(),{get text(){return t},update(e){if(!(r||i)){if(e.length>32e3)throw Error(`Speech text exceeds the supported limit.`);if(!e.startsWith(t))throw Error(`The streamed speech response was rewritten.`);t=e,o()}},finish(e){r&&e===void 0||(r=!0,e!==void 0&&(i=e),o())},async*[Symbol.asyncIterator](){try{for(;;){if(q(e),i)throw i;if(n<t.length){let e=t.slice(n);n=t.length,yield e}else if(r)return;else await new Promise(e=>{a=e})}}finally{e.removeEventListener(`abort`,s),r=!0,o()}}}}function Ka(e){let{t}=c(),n=(0,Z.useRef)({...e,t});n.current={...e,t};let[r,i]=(0,Z.useState)(`idle`),[a,o]=(0,Z.useState)(0),[s,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)([]),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(0),v=(0,Z.useRef)(`idle`),y=(0,Z.useRef)(0),b=(0,Z.useRef)(null),x=(0,Z.useRef)(Promise.resolve()),S=(0,Z.useRef)(!1),C=(0,Z.useRef)(null),w=(0,Z.useRef)(!1),T=(0,Z.useRef)(!1),E=(0,Z.useRef)(!1),D=(0,Z.useRef)({start:async()=>{},commit:async()=>{},stop:()=>{}}),O=(0,Z.useCallback)(e=>{v.current=e,i(e)},[]),k=e=>w.current&&n.current.open&&e.sessionId===n.current.sessionId&&b.current===e&&y.current===e.generation&&!e.controller.signal.aborted,A=()=>!!(n.current.streaming||n.current.messages.some(e=>e.streaming));function j(){let e=C.current;C.current=null,e?.controller.abort()}function M(){if(C.current)return C.current.preparing;let e=new AbortController,t=n.current.sessionId,r=(async()=>{S.current||=(await n.current.ensureReady?.(e.signal),q(e.signal),!0);let{hotwords:r}=await On(t,e.signal);await Tn({kinds:[`asr`,`tts`],hotwords:r},e.signal),q(e.signal)})().catch(t=>{throw C.current?.controller===e&&(C.current=null),e.abort(),t});return C.current={controller:e,preparing:r},r}function N(e){window.clearTimeout(e.limitTimer),e.limitTimer=void 0,e.microphone.abort(),e.endpoint?.dispose(),e.endpoint=void 0;let t=e.capture;return e.capture=void 0,t&&(e.captureStopping=t.stop()),e.captureStopping??Promise.resolve()}function P(e){if(e.cleanup)return e.cleanup;e.controller.abort(),e.unsubscribe?.(),e.unsubscribe=void 0,e.responseSubscription?.(),e.responseSubscription=void 0,e.checkOwnership=void 0;let t=N(e),n=e.recognizer;return e.recognizer=void 0,e.cleanup=Promise.allSettled([t,e.capturePending,e.recognizerDisposing,e.playback,n?.dispose()]).then(()=>{}),e.cleanup}function F(){y.current+=1;let e=b.current;if(b.current=null,!e)return;let t=Promise.resolve(),r=n.current.messages.filter(t=>t.role===`user`&&!e.baseline?.has(t.id)),i=n.current.sessionId===e.sessionId&&(r.length>1||r.length===1&&r[0].text?.trim()!==e.prompt);if(e.ownsRun&&!i){e.ownsRun=!1;try{t=Promise.resolve(e.abortRun?.()).catch(()=>{})}catch{}}x.current=Promise.allSettled([x.current,P(e),t]).then(()=>{})}function I(){E.current=!1,F(),O(`idle`),l(``),o(0),d(e=>e.filter(e=>!e.pending))}function L(e,t){if(!k(e))return;let r=t instanceof Error?t.message:typeof t==`string`?t:t&&typeof t==`object`&&`message`in t?t.message:void 0,i=typeof r==`string`&&r.trim()?r:n.current.t(`chat:voiceMode.failed`),a=t instanceof DOMException&&t.name===`NotAllowedError`||i.includes(`microphone_permission_denied`)?n.current.t(`chat:voiceInput.permissionDenied`):i;I(),p(a),O(`error`),n.current.notifyError?.(a)}function R(e){return new Promise(t=>{let n=e.controller.signal,r=()=>{window.clearTimeout(i),n.removeEventListener(`abort`,r),t()},i=window.setTimeout(r,50);n.addEventListener(`abort`,r,{once:!0}),n.aborted&&r()})}async function z(e,t,r){let i=e.controller.signal,a=Ga(i),o,s,c,l=!1,u=!1,f=!1,p=!1,m=!1,h=1/0,g=n=>{let r=n.filter(e=>e.role===`user`&&!t.has(e.id));return r.length>1||r.length===1&&r[0].text?.trim()!==e.prompt};e.checkOwnership=()=>{k(e)&&g(n.current.messages)&&(e.ownsRun=!1,L(e,Error(n.current.t(`chat:voiceMode.failed`))))};let _=e=>{a.update(e),d(t=>t.map(t=>t.id===r?{...t,text:e,pending:!e.trim()}:t))};e.responseSubscription=Ha(e.sessionId,r=>{if(!(!k(e)||r.source!==`snapshot`&&t.has(r.messageId)))try{let t=r.source===`snapshot`,i=!!(c&&r.startedAt===c);if(r.users&&g(r.users)||r.prompt!==void 0&&r.prompt.trim()!==e.prompt||s&&r.runId&&s!==r.runId||c&&r.startedAt&&c!==r.startedAt||t&&!i&&!(p&&!r.startedAt&&r.status===`completed`)||!t&&o&&o!==r.messageId)throw e.ownsRun=!1,Error(n.current.t(`chat:voiceMode.failed`));if(p&&t)return;if(s||=r.runId,c||=r.startedAt,r.messageId&&(o=r.messageId),r.status===`recovering`){l=!0;return}if(t&&(l=!0,u=r.status===`streaming`||r.status===`started`),r.status===`started`)return;if(f=!0,r.status===`failed`)throw e.ownsRun=!1,Error(r.error||n.current.t(`chat:voiceMode.failed`));_(r.text),r.status===`completed`&&(p=!0,e.ownsRun=!1,a.finish())}catch(t){a.finish(t),L(e,t)}});let v=Promise.resolve().then(()=>(q(i),n.current.sendPrompt(e.prompt,[],!1,!1,null))).catch(t=>{throw e.ownsRun=!1,a.finish(t),t}).finally(()=>{!f&&!s&&!c&&(e.ownsRun=!1),m=!0,h=Date.now()+15e3}),y=async()=>{for(;k(e);){if(await R(e),!k(e))return;let r=n.current.messages.filter(e=>!t.has(e.id)),i=r.filter(e=>e.role===`user`);if(i.length>1||i.length===1&&i[0].text?.trim()!==e.prompt)throw Error(n.current.t(`chat:voiceMode.failed`));let s=r.filter(e=>e.role===`assistant`||e.role===`agent`),c=s.find(e=>e.error);if(c)throw Error(String(c.error));if(p&&m&&!A())return;let d=s.at(-1);if(!l&&d?.text&&(!f||m&&!A())){if(o&&o!==d.id)throw Error(n.current.t(`chat:voiceMode.failed`));o=d.id,_(d.text)}if(!l&&m&&!A()&&d?.text?.trim()){e.ownsRun=!1,a.finish();return}if(m&&(A()||u)&&(h=Date.now()+15e3),Date.now()>=h)throw Error(n.current.t(`chat:voiceMode.emptyReply`))}};try{e.playback=Promise.resolve().then(()=>n.current.speakText(a,i,()=>{k(e)&&O(`speaking`)})),await Promise.all([v,y(),e.playback])}catch(e){throw a.finish(e),e}finally{e.responseSubscription?.(),e.responseSubscription=void 0,e.checkOwnership=void 0,a.finish()}}async function B(){let e=b.current;if(!e||!k(e)||e.committed||v.current!==`listening`)return;e.committed=!0;let t=e.endpoint?.hasSpeech;O(`transcribing`),o(0);try{if(await N(e),!k(e))return;if(!t){I();return}let r=(await e.recognizer?.finish())?.trim();if(!k(e))return;e.unsubscribe?.(),e.unsubscribe=void 0;let i=e.recognizer;if(e.recognizer=void 0,e.recognizerDisposing=i?.dispose(),await e.recognizerDisposing,!k(e))return;if(l(``),!r)throw Error(n.current.t(`chat:voiceMode.emptyReply`));if(A()){I();return}let a=new Set(n.current.messages.map(e=>e.id));e.baseline=a,e.prompt=r;let o=`voice-agent-${e.generation}`;if(d(t=>[...t.slice(-4),{id:`voice-user-${e.generation}`,role:`user`,text:r},{id:o,role:`agent`,text:``,pending:!0}]),O(`thinking`),e.abortRun=n.current.onAbort,e.ownsRun=!0,await z(e,a,o),!k(e))return;E.current&&!T.current?(O(`idle`),await D.current.start()):I()}catch(t){L(e,t)}}async function ee(){if(!w.current||!n.current.open||T.current||document.hidden||![`idle`,`error`,`speaking`].includes(v.current))return;F();let e={generation:++y.current,sessionId:n.current.sessionId,controller:new AbortController,microphone:new AbortController,permissionPending:!1,committed:!1,commitRequested:!1,ownsRun:!1};b.current=e,E.current=!0,p(``),l(``),o(0),O(`requesting`);let t=Gi(),r=0;try{if(await x.current,!k(e)||(await M(),!k(e)))return;if(A()){I();return}e.permissionPending=!0;try{await _a()}finally{e.permissionPending=!1}if(!k(e))return;if(document.hidden||A()){I();return}let n=await Zi();if(!k(e)){n.dispose();return}e.endpoint=n;let i=xa({chatSessionId:e.sessionId});if(e.recognizer=i,e.unsubscribe=i.onPartial(t=>{k(e)&&l(t)}),await i.start(),!k(e)||(e.capturePending=wa(a=>{if(!(!k(e)||e.committed||e.microphone.signal.aborted))try{let s=t.push(Wi(a)),c=performance.now();c-r>=66&&(r=c,o(s));let l=i.acceptPcm(a),u=n.acceptPcm(a);(l||u)&&(e.commitRequested=!0,v.current===`listening`?D.current.commit():e.microphone.abort())}catch(t){L(e,t)}},e.microphone.signal).then(async t=>(!k(e)||e.microphone.signal.aborted?await t.stop():e.capture=t,t)),await e.capturePending,!k(e)))return;if(O(`listening`),e.commitRequested){await D.current.commit();return}e.limitTimer=window.setTimeout(()=>void D.current.commit(),6e4)}catch(t){k(e)&&e.commitRequested&&e.microphone.signal.aborted?(O(`listening`),await D.current.commit()):L(e,t)}}D.current={start:ee,commit:B,stop:I};let V=(0,Z.useCallback)(()=>D.current.commit(),[]),te=(0,Z.useCallback)(()=>{D.current.stop();let e=y.current;x.current.then(()=>{y.current===e&&w.current&&D.current.start()})},[]),ne=(0,Z.useCallback)(()=>{v.current===`listening`?D.current.commit():v.current===`thinking`||v.current===`speaking`?te():(v.current===`idle`||v.current===`error`)&&(T.current=!1,h(!1),D.current.start())},[te]),re=(0,Z.useCallback)(()=>{let e=!T.current;T.current=e,h(e),e?D.current.stop():D.current.start()},[]),ie=(0,Z.useCallback)(()=>{j(),D.current.stop(),p(``),_(0)},[]);return(0,Z.useEffect)(()=>{if(!e.open)return;w.current=!0,S.current=!1,T.current=!1,h(!1),d([]),_(0),O(`idle`),D.current.start();let t=()=>{b.current?.permissionPending&&window.__PISPER_MOBILE_APP__||(j(),D.current.stop())},n=()=>{document.hidden&&t()},r=()=>{j(),D.current.stop()};return window.addEventListener(`blur`,t),window.addEventListener(`pisper:speech-interrupted`,r),document.addEventListener(`visibilitychange`,n),()=>{w.current=!1,j(),D.current.stop(),window.removeEventListener(`blur`,t),window.removeEventListener(`pisper:speech-interrupted`,r),document.removeEventListener(`visibilitychange`,n)}},[e.open,e.sessionId,O]),(0,Z.useEffect)(()=>{b.current?.checkOwnership?.()},[e.messages,e.streaming]),(0,Z.useEffect)(()=>{if(![`listening`,`transcribing`,`thinking`,`speaking`].includes(r))return;let e=window.setInterval(()=>_(e=>e+1),1e3);return()=>window.clearInterval(e)},[r]),{stage:r,level:a,partial:s,turns:u,error:f,muted:m,elapsed:g,toggleMain:ne,toggleMute:re,hangUp:ie,commitListening:V,interrupt:te}}function qa(e){return{idle:e(`chat:voiceMode.idle`),requesting:e(`chat:voiceMode.requesting`),listening:e(`chat:voiceMode.listening`),transcribing:e(`chat:voiceMode.transcribing`),thinking:e(`chat:voiceMode.thinking`),speaking:e(`chat:voiceMode.speaking`),error:e(`chat:voiceMode.failed`)}}function Ja(e){let t=Math.floor(e/60),n=e%60;return`${t.toString().padStart(2,`0`)}:${n.toString().padStart(2,`0`)}`}function Ya(){let[e,t]=(0,Z.useState)(()=>document.documentElement.dataset.theme!==`light`);return(0,Z.useEffect)(()=>{let e=document.documentElement,n=()=>t(e.dataset.theme!==`light`);n();let r=new MutationObserver(n);return r.observe(e,{attributes:!0,attributeFilter:[`data-theme`]}),()=>r.disconnect()},[]),e}function Xa(e){let[t,n]=(0,Z.useState)(()=>typeof window>`u`?380:Math.max(48,Math.min(window.innerWidth*.52,window.innerHeight-304,460)));return(0,Z.useEffect)(()=>{if(!e)return;let t=()=>n(Math.max(48,Math.min(window.innerWidth*.52,window.innerHeight-304,460)));return t(),window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t)},[e]),Math.floor(t)}function Za({open:e,sessionId:t,messages:n,streaming:r,sendPrompt:i,onAbort:a,onClose:o}){let{t:s}=c(),l=Ya(),u=$i([`asr`,`tts`]),d=Ka({open:e,sessionId:t,messages:n,streaming:r,sendPrompt:i,onAbort:a,ensureReady:u.ensureReady,speakText:(e,t,n)=>oa(e,u.selectedVoice,t,n)}),{stage:f,level:p,partial:m,turns:h,error:g,elapsed:_}=d,v=Xa(e),y=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!e)return;let t=document.activeElement;return y.current?.focus({preventScroll:!0}),()=>{t instanceof HTMLElement&&t.isConnected&&t.focus({preventScroll:!0})}},[e]);let b=()=>{try{d.hangUp()}finally{u.close(),o()}},x=f===`listening`||f===`transcribing`||f===`thinking`||f===`speaking`||f===`requesting`;if((0,Z.useEffect)(()=>{if(!e)return;let t=e=>{if(!(u.open||e.defaultPrevented||e.isComposing)){if(e.key===`Escape`){e.preventDefault(),b();return}if(e.key===`Tab`){let t=[...y.current?.querySelectorAll(`button:not(:disabled)`)||[]],n=t[0],r=t[t.length-1];e.shiftKey&&(document.activeElement===n||document.activeElement===y.current)?(e.preventDefault(),r?.focus()):!e.shiftKey&&document.activeElement===r&&(e.preventDefault(),n?.focus())}e.target instanceof Element&&e.target.closest(`input, textarea, select, button, [contenteditable="true"]`)||e.key===` `&&!e.repeat&&(e.preventDefault(),x?d.hangUp():d.toggleMain())}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,o,x,u.open]),!e)return null;let S=qa(s),C=h[h.length-1],w=f===`listening`&&m?m:C?`${C.role,``}${Ki(C.text,120)}`:``,T=f===`error`?g||s(`chat:voiceMode.failed`):S[f];return(0,_r.createPortal)((0,Q.jsxs)(`div`,{className:`fixed inset-0 z-[90] grid grid-cols-[minmax(0,1fr)] grid-rows-[minmax(0,1fr)_100px_108px] overflow-hidden select-none pt-[env(safe-area-inset-top)] pr-[env(safe-area-inset-right)] pb-[env(safe-area-inset-bottom)] pl-[env(safe-area-inset-left)] ${l?`bg-[#030304] text-[#cfe8ff]`:`bg-[#f2f5fa] text-[#1e2c42]`}`,ref:y,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":s(`chat:voiceMode.title`),children:[(0,Q.jsxs)(`header`,{className:`pointer-events-none absolute left-[calc(env(safe-area-inset-left)_+_28px)] top-[calc(env(safe-area-inset-top)_+_24px)] flex items-center gap-3`,children:[(0,Q.jsx)(`span`,{className:`inline-block size-2 rounded-full ${x?`animate-pulse bg-[#59e6ff]`:l?`bg-[#3b4a5c]`:`bg-[#b6c3d4]`}`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-bold tracking-[0.42em] ${l?`text-[#9be7ff] [text-shadow:0_0_14px_rgba(89,230,255,.45)]`:`text-[#0d6ac9]`}`,children:`PISPER`})]}),(0,Q.jsxs)(`div`,{className:`absolute top-[calc(env(safe-area-inset-top)_+_16px)] right-[calc(env(safe-area-inset-right)_+_16px)] z-10 flex items-center gap-1`,children:[(0,Q.jsxs)(I,{children:[(0,Q.jsx)(P,{asChild:!0,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon-sm`,"aria-label":s(`chat:speechModels.title`),onClick:()=>{d.hangUp(),u.show()},children:(0,Q.jsx)(er,{})})}),(0,Q.jsx)(F,{children:s(`chat:speechModels.title`)})]}),(0,Q.jsxs)(I,{children:[(0,Q.jsx)(P,{asChild:!0,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon-sm`,className:`size-11 flex-none`,"aria-label":s(`chat:speechModels.close`),onClick:b,children:(0,Q.jsx)(dt,{})})}),(0,Q.jsx)(F,{children:s(`chat:speechModels.close`)})]})]}),(0,Q.jsx)(pa,{manager:u,onClose:()=>d.hangUp()}),(0,Q.jsx)(`div`,{className:`flex min-h-0 items-center justify-center pt-16 pb-6`,children:(0,Q.jsx)(Ba,{stage:f,level:p,size:v,dark:l})}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-col items-center justify-center gap-2 px-6 text-center`,children:[(0,Q.jsx)(`div`,{className:`max-w-full text-[11px] font-semibold uppercase tracking-normal ${f===`error`?`max-h-full overflow-y-auto break-words text-[#f87171]`:`line-clamp-2 ${l?`text-[#5f7a94]`:`text-[#7488a0]`}`}`,role:`status`,"aria-live":`polite`,children:T}),(0,Q.jsx)(`p`,{className:`m-0 line-clamp-2 min-h-[22px] max-w-[640px] text-[15px] leading-[1.6] ${l?`text-[#d7e6f7]`:`text-[#24344d]`}`,children:w})]}),(0,Q.jsx)(`div`,{className:`relative flex justify-center pt-3 sm:items-center sm:pt-0`,children:(0,Q.jsx)(`button`,{type:`button`,className:`h-11 cursor-pointer rounded-full border bg-transparent px-9 text-[11px] font-semibold uppercase tracking-[0.3em] transition-[box-shadow,background-color,border-color] duration-300 ${l?`border-[rgba(140,220,255,.4)] text-[#9be7ff] hover:border-[rgba(140,220,255,.8)] hover:bg-[rgba(89,230,255,.08)] hover:shadow-[0_0_28px_rgba(89,230,255,.25)]`:`border-[rgba(13,106,201,.45)] text-[#0d6ac9] hover:border-[rgba(13,106,201,.85)] hover:bg-[rgba(13,106,201,.07)] hover:shadow-[0_0_28px_rgba(13,106,201,.18)]`}`,onClick:()=>x?d.hangUp():d.toggleMain(),children:s(x?`chat:voiceMode.endConversation`:`chat:voiceMode.startConversation`)})}),(0,Q.jsxs)(`div`,{className:`pointer-events-none absolute bottom-[calc(env(safe-area-inset-bottom)_+_12px)] right-[calc(env(safe-area-inset-right)_+_20px)] flex items-center gap-2.5 sm:bottom-[calc(env(safe-area-inset-bottom)_+_36px)] sm:right-[calc(env(safe-area-inset-right)_+_28px)]`,children:[(0,Q.jsx)(`span`,{className:`hidden size-9 place-items-center rounded-full sm:grid bg-[linear-gradient(135deg,#2563eb,#38bdf8)] text-[10px] font-bold text-white shadow-[0_0_18px_rgba(56,189,248,.4)]`,"aria-hidden":`true`,children:x?`●`:`○`}),(0,Q.jsx)(`span`,{className:`font-mono text-[13px] tabular-nums tracking-[0.12em] ${l?`text-[#7d93ad]`:`text-[#61748c]`}`,children:Ja(_)})]}),(0,Q.jsx)(`div`,{className:`absolute bottom-[env(safe-area-inset-bottom)] left-[calc(env(safe-area-inset-left)_+_20px)] sm:bottom-[calc(env(safe-area-inset-bottom)_+_36px)] sm:left-[calc(env(safe-area-inset-left)_+_28px)]`,children:(0,Q.jsxs)(I,{children:[(0,Q.jsx)(P,{asChild:!0,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`size-11 flex-none`,disabled:!x&&!d.muted,"aria-label":f===`speaking`||f===`thinking`?s(`chat:voiceMode.interrupt`):d.muted?s(`chat:voiceMode.unmute`):s(`chat:voiceMode.mute`),onClick:()=>f===`speaking`||f===`thinking`?d.interrupt():d.toggleMute(),children:f===`speaking`||f===`thinking`?(0,Q.jsx)(nt,{}):d.muted?(0,Q.jsx)(cr,{}):(0,Q.jsx)(lr,{})})}),(0,Q.jsx)(F,{children:f===`speaking`||f===`thinking`?s(`chat:voiceMode.interrupt`):d.muted?s(`chat:voiceMode.unmute`):s(`chat:voiceMode.mute`)})]})})]}),document.body)}var Qa=({className:e,defaultOpen:t=!0,...n})=>(0,Q.jsx)(y,{className:L(e),defaultOpen:t,...n}),$a=(0,Z.lazy)(()=>t(()=>import(`./ShinyText-DqxsUc3F.js`).then(e=>({default:e.ShinyText})),__vite__mapDeps([18,4,2,19,8,20])));function eo({queuedInputs:e,withdrawingInputIds:t=[],onWithdraw:n}){let{t:r}=c(),i=r(`chat:focusSession.sentToTheRunningAgent`),a=r(`chat:focusSession.withdrawQueuedInput`);return(0,Q.jsx)(Qa,{asChild:!0,defaultOpen:!0,children:(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1 text-xs text-[var(--text-secondary)]`,"data-pisper-queue-size":e.length,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-[11px] font-semibold text-[var(--star-strong)]`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 [overflow-wrap:anywhere]`,children:i}),(0,Q.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:e.length})]}),(0,Q.jsx)(`ul`,{className:`m-0 max-h-36 min-w-0 list-none overflow-x-hidden overflow-y-auto overscroll-contain p-0`,"aria-label":i,tabIndex:e.length>3?0:void 0,children:e.map((e,r)=>{let i=typeof e.id==`string`?e.id:``,o=t.includes(i);return(0,Q.jsxs)(`li`,{className:`grid min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2 border-b border-[var(--stroke-soft)] py-0.5 last:border-0`,children:[(0,Q.jsx)(`span`,{className:`line-clamp-2 min-w-0 whitespace-pre-wrap [overflow-wrap:anywhere]`,title:e.text,children:e.text}),(0,Q.jsxs)(I,{children:[(0,Q.jsx)(P,{asChild:!0,children:(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`icon-lg`,className:`rounded-md text-[var(--text-muted)] hover:text-[var(--text)]`,"aria-label":a,"aria-busy":o||void 0,disabled:!i||!n||o,onClick:()=>void n?.(i),children:(0,Q.jsx)(ot,{size:16,"aria-hidden":`true`})})}),(0,Q.jsx)(F,{children:a})]})]},i||`${e.behavior}-${r}`)})})]})})}function to({invocation:e,onRemove:t}){let{t:n}=c();return(0,Q.jsxs)(`div`,{className:`composer-resource-chip [&.workflow]:border-[var(--success)] [&.workflow]:bg-[var(--success-soft)] [&_button]:grid [&_button]:w-[20px] [&_button]:h-[20px] [&_button]:place-items-center [&_button]:border-0 [&_button]:rounded-[var(--r-xs)] [&_button]:bg-transparent [&_button]:text-[var(--text-muted)] [&_button]:cursor-pointer [&_button:hover]:bg-[var(--surface-hover)] [&_button:hover]:text-[var(--text)] inline-flex min-h-[28px] self-start items-center gap-[6px] [border:1px_solid_var(--blue)] rounded-[var(--r-sm)] bg-[var(--blue-soft)] text-[var(--text)] [padding:4px_6px_4px_8px] text-[12px] font-[600] ${e.kind}`,children:[e.kind===`tool`?(0,Q.jsx)(ut,{size:13}):(0,Q.jsx)(D,{size:13}),(0,Q.jsxs)(`span`,{children:[e.kind===`skill`?`Skill`:e.kind===`tool`?n(`chat:resourcePicker.tool`):n(`chat:resourcePicker.workflow`),` `,`· `,e.resourceName]}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":n(`chat:resourcePicker.remove`),onClick:t,children:(0,Q.jsx)(dt,{size:13})})]})}function no({compaction:e,streaming:t,statusLabel:n}){let{t:r}=c();return(0,Q.jsxs)(`div`,{className:`focus-composer-status [&.idle]:hidden [&_>_i]:w-[7px] [&_>_i]:h-[7px] [&_>_i]:flex-none [&_>_i]:rounded-[50%] [&_>_i]:bg-[var(--text-muted)] [&.running]:text-[var(--success-strong)] [&.running_>_i]:bg-[var(--success)] [&.running_>_i]:shadow-[0_0_0_3px_var(--success-soft)] [&.running_>_i]:[animation:star-twinkle_1.1s_ease-in-out_infinite] inline-flex min-h-[22px] self-start items-center gap-[7px] [margin:0_0_-2px_5px] [border:1px_solid_var(--stroke-soft)] rounded-[var(--r-pill)] bg-[var(--solid)] [padding:3px_9px_3px_7px] text-[var(--text-muted)] text-[11px] font-[600] shadow-[0_8px_18px_-16px_var(--shadow-strong)] ${e?.active?`compacting [.focus-composer-status&]:text-[var(--warning-strong)] [.focus-composer-status&_>_i]:bg-[var(--warning-strong)] [.focus-composer-status&_>_i]:shadow-[0_0_0_3px_var(--warning-soft)] [.focus-composer-status&_>_i]:[animation:star-twinkle_1.1s_ease-in-out_infinite]`:t?`running`:`idle`}`,role:`status`,"aria-live":`polite`,children:[(0,Q.jsx)(`i`,{"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`min-w-0 max-w-[min(420px,60vw)] overflow-hidden text-ellipsis whitespace-nowrap`,children:e?.active?r(`chat:focusSession.compactingContext`):t?(0,Q.jsx)(Z.Suspense,{fallback:n||r(`chat:focusSession.running`),children:(0,Q.jsx)($a,{children:n||r(`chat:focusSession.running`)},n||`running`)}):r(`chat:focusSession.waitingForInput`)})]})}function ro({streaming:e,compactingManually:t,compactionActive:n,disabled:r,onCompact:i}){let{t:a}=c();return(0,Q.jsx)(`button`,{type:`button`,className:`compact-context-trigger [&:hover:not(:disabled)]:border-[var(--accent-border)] [&:hover:not(:disabled)]:bg-[var(--accent-soft)] [&:hover:not(:disabled)]:text-[var(--star-strong)] disabled:[cursor:not-allowed] disabled:opacity-[.5] [.composer-tool-tray_&]:w-[38px] [.composer-tool-tray_&]:min-w-[38px] [.composer-tool-tray_&]:h-[38px] [.composer-tool-tray_&]:flex-none @max-[700px]:[.composer-tool-tray_&]:w-[32px] @max-[700px]:[.composer-tool-tray_&]:min-w-[32px] @max-[700px]:[.composer-tool-tray_&]:h-[32px] @max-[700px]:[.composer-tool-tray_&]:p-0 @max-[470px]:[.composer-tool-tray_&]:w-[28px] @max-[470px]:[.composer-tool-tray_&]:min-w-[28px] @max-[470px]:[.composer-tool-tray_&]:h-[28px] grid w-[38px] h-[38px] flex-none place-items-center [border:1px_solid_transparent] rounded-[var(--r-sm)] bg-[var(--surface-muted)] text-[var(--text-tertiary)] cursor-pointer`,title:a(e?`chat:focusSession.manualCompactionWaitForRun`:t||n?`chat:focusSession.compactingContext`:`chat:focusSession.compactContextNow`),"aria-label":a(`chat:focusSession.compactContextNow`),disabled:r,onClick:i,children:t||n?(0,Q.jsx)(Xe,{className:`animate-spin`,size:14}):(0,Q.jsx)(ur,{size:14})})}function io({streaming:e,queueing:t,disabled:n,onAbort:r}){let{t:i}=c(),a=Wt(`sendMessage`),o=i(`chat:focusSession.sendMessage`);return(0,Q.jsx)(`button`,{type:e?`button`:`submit`,className:`send-button grid !size-8 !min-w-8 flex-none place-items-center rounded-full border-0 bg-foreground text-background transition-[var(--d1)] cursor-pointer hover:not(:disabled):opacity-85 active:not(:disabled):scale-[.96] disabled:cursor-not-allowed disabled:bg-foreground/20 disabled:text-background/70 ${e?`stop !bg-[var(--danger)] hover:not(:disabled):shadow-[0_0_0_3px_var(--danger-soft)]`:``}`,title:e?i(`chat:focusSession.stop`):a?`${o} (${a})`:o,"aria-label":i(e?`chat:focusSession.stop`:`chat:focusSession.sendMessage`),onClick:e?r:void 0,disabled:n,children:e?(0,Q.jsx)(nt,{size:12,fill:`currentColor`}):t?(0,Q.jsx)(Xe,{className:`animate-spin`,size:17}):(0,Q.jsx)(ae,{size:17})})}function ao({streaming:e,messages:t,currentActivity:n,thinkingText:r,compaction:i,error:a,runStopped:o,runNotice:s,lastActivityAt:c},l){return(0,Z.useMemo)(()=>G({streaming:e,text:t.at(-1)?.role===`agent`&&t.at(-1)?.text||``,currentActivity:n,thinkingText:r,compaction:i,error:a,stopped:o,notice:s,lastActivityAt:c},l),[e,t,n,r,i,a,o,s,c,l])}var oo=36,so=40;function co(e){let[t,n]=(0,Z.useState)(1/0);return(0,Z.useLayoutEffect)(()=>{let t=e.current;if(!t)return;let r=()=>{let e=window.innerWidth<=650,r=t.getBoundingClientRect().width-(e?44:oo);n(Math.max(0,r/so))};if(r(),window.addEventListener(`resize`,r),typeof ResizeObserver>`u`)return()=>window.removeEventListener(`resize`,r);let i=new ResizeObserver(r);return i.observe(t),()=>{i.disconnect(),window.removeEventListener(`resize`,r)}},[e]),t}var lo=[`plan`,`goal`,`team`];function uo(e){return lo.includes(e)?e:`plan`}function fo({sessionId:e,runMode:t,goalsAvailable:n,teamAvailable:r,workflowsAvailable:i,goal:a,streaming:o,compaction:s,value:c,selection:l,clearDraft:u,promptRef:d,onCompact:f,onGoalPause:p,onSend:m,onQueue:h,setToolsOpen:g,requestTranscriptBottom:_}){let[v,y]=(0,Z.useState)(()=>uo(t)),b=(0,Z.useRef)(t);b.current=t;let[x,S]=(0,Z.useState)(null),[C,w]=(0,Z.useState)(null),T=(0,Z.useRef)(null),[E,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{y(uo(b.current)),T.current=null,S(null),w(null),D(!1),k(!1),j(null)},[e]),(0,Z.useEffect)(()=>{y(uo(t))},[e,t]),(0,Z.useEffect)(()=>{n||y(`plan`),!r&&v===`team`&&y(`goal`),!i&&A?.kind===`workflow`&&j(null)},[v,n,A?.kind,r,i]),(0,Z.useEffect)(()=>{a?.status===`active`&&y(a.mode===`team`&&r?`team`:`goal`)},[a?.id,a?.mode,a?.status,r]),(0,Z.useEffect)(()=>{if(!a?.id){S(null);return}let e=a.mode===`team`?a.teamTokenBudget:a.tokenBudget,t=e==null?null:Number(e),n=t!==null&&Number.isFinite(t)&&t>0?t:null;a.mode===`team`?w(n):S(n)},[a?.id,a?.mode,a?.teamTokenBudget,a?.tokenBudget]),{composerExecutionMode:v,setComposerExecutionMode:y,goalTokenBudget:x,setGoalTokenBudget:S,teamTokenBudget:C,setTeamTokenBudget:w,queueing:E,compactingManually:O,invocation:A,setInvocation:j,requestGoalPause:()=>{if(T.current)return T.current;let e=Promise.resolve().then(()=>p?.());return T.current=e,e.catch(()=>{}),e},compactContext:async()=>{if(!(!f||o||O||s?.active)){k(!0);try{await f()}finally{k(!1)}}},submit:async e=>{if(e.preventDefault(),!c.trim()&&!l.attachments.length&&!A)return;if(o){if(!c.trim()&&!l.attachments.length||E)return;D(!0);let e=await h?.(c,l.attachments,`steer`);if(D(!1),!e)return;u(),y(`plan`),g(!1),_(),d.current&&(d.current.style.height=`auto`);return}let t=T.current;if(t){try{await t}catch{T.current=null;return}T.current=null}else a?.status===`active`&&(v===`plan`||v!==a.mode)&&await p?.();m(c,l.attachments,v===`goal`||v===`team`,v===`team`,v===`team`?C:v===`goal`?x:null,A),_(),u(),y(`plan`),g(!1),j(null),d.current&&(d.current.style.height=`auto`)}}}var po=(0,Z.lazy)(()=>t(()=>import(`./QuickPromptIdeas-DGIL0nN7.js`),__vite__mapDeps([21,4,2,22,14,3,15,16,17,23,24,25,26,27,28,29]))),mo=[`.anchored-popup-menu`,`.permission-mode-menu`,`.voice-input-popup`,`.git-diff-dialog-backdrop`,`[data-slot='dialog-content']`,`[data-slot='dialog-overlay']`,`[data-slot='alert-dialog-content']`,`[data-slot='alert-dialog-overlay']`,`[data-slot='popover-content']`,`[data-slot='dropdown-menu-content']`,`[data-slot='dropdown-menu-sub-content']`,`[data-slot='select-content']`,`[data-slot='sheet-content']`,`[data-slot='sheet-overlay']`].join(`, `),ho=[`.composer-tools-trigger`,`.composer-tool-tray-shell`,mo].join(`, `),go=(0,Z.memo)(function({session:e,shortcutEnabled:t=!1,messages:n,transcriptLoadState:r=`ready`,messageStart:i,hasOlder:a,loadingOlder:o,olderError:s,model:l,thinkingLevel:u,availableThinkingLevels:d,thinkingStatus:f,thinkingMessage:p,executionMode:m,goal:h,team:g,plan:_,currentActivity:v,activityFeed:y,tools:b,thinkingText:x,queuedInputs:S,withdrawingInputIds:C,compaction:w,contextUsage:T,sessionUsage:E,sessionTreeRevision:O,sessionTreePulse:k,cwd:A,availableModels:j,pendingRuntimeSelection:M,switchingModel:N,switchingThinking:P,switchingCwd:F,switchingPermission:I,streaming:R,runStartedAt:z,lastActivityAt:B,runFinishedAt:ee,runStopped:V,runNotice:te,approvals:ne,error:re,pendingAsset:ie,contextOpen:H,contextCompact:ae,contextPanelId:oe,onToggleContext:se,notify:ce,onOpenModelSettings:le,onAssetConsumed:ue,onLoadOlder:de,onModelChange:U,onThinkingLevelChange:pe,onExecutionModeChange:me,onRunModeChange:he,onCompact:ge,onCompactionThresholdChange:_e,onGoalPause:ve,onGoalBudgetChange:ye,onApproval:be,onWorkspace:xe,onRename:Se,onBranchFromHere:Ce,onCreateChildSession:Te,onRetryLastTurn:Ee,onTreeNavigated:De,onSend:Oe,onQueue:ke,onWithdrawQueuedInput:je,onAbort:Me}){let{t:G,language:Ne}=c(),Pe=Xt(e=>e.cycleTheme),Ie=Xt(e=>e.theme),K=Kt(e=>e.bindings),Le=Wt(`commandPalette`),Re=xt(),ze=ft(),Be=Re||ze,Ve=Yt(e=>e.capabilities),He=Jt(Ve,`goals`),Ue=Jt(Ve,`multiAgent`),We=Jt(Ve,`plans`),Ke=Jt(Ve,`workflows`),Je=Jt(Ve,`visualGeneration`),{value:Xe,updateValue:Ze,selection:Qe,clearDraft:$e,restoreDraft:nt}=Gr(e.id),[rt,it]=(0,Z.useState)(!1),[at,ot]=(0,Z.useState)(!1),[st,ct]=(0,Z.useState)(!1),[lt,ut]=(0,Z.useState)(!1),[pt,mt]=(0,Z.useState)(!1),[ht,gt]=(0,Z.useState)(!1),[_t,q]=(0,Z.useState)(0),vt=(0,Z.useRef)(null),yt=Qe.addAttachments,bt=(0,Z.useRef)(null),St=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!t)return;let e=e=>{!Ut(e)&&Gt(e,K.voiceInput)&&mt(!0),!Ut(e)&&Gt(e,K.focusComposer)&&(e.preventDefault(),bt.current?.focus())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,K.focusComposer,K.voiceInput]);let J=(0,Z.useRef)(null),Ct=(0,Z.useRef)(null),Y=(0,Z.useRef)(null),wt=co(J),Tt=ci(e=>e.layout),Et=(0,Z.useRef)(!1),Dt=r!==`ready`||n.length>0,Ot=!Dt,kt=ao({streaming:R,messages:n,currentActivity:v,thinkingText:x,compaction:w,error:re,runStopped:V,runNotice:te,lastActivityAt:B},G),At=`composer-tool-tray-${e.id}`,jt=G(lt?`chat:focusSession.collapseQuickActions`:`chat:focusSession.expandQuickActions`),Mt=G(Be?R?`chat:focusSession.addGuidanceForTheRunningAgent`:`chat:workbench.composerPlaceholder`:R?`chat:focusSession.runningAgentComposerHint`:`chat:focusSession.composerHint`),Nt=()=>q(e=>e+1),Pt=e=>{Ze(e),requestAnimationFrame(()=>{let e=bt.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,220)}px`)})},{composerExecutionMode:Ft,setComposerExecutionMode:It,goalTokenBudget:Lt,setGoalTokenBudget:X,teamTokenBudget:zt,setTeamTokenBudget:Vt,queueing:qt,compactingManually:Zt,invocation:Qt,setInvocation:$t,requestGoalPause:en,compactContext:tn,submit:nn}=fo({sessionId:e.id,runMode:e.runMode,goalsAvailable:He,teamAvailable:Ue,workflowsAvailable:Ke,goal:h,streaming:R,compaction:w,value:Xe,selection:Qe,clearDraft:$e,promptRef:bt,onCompact:ge,onGoalPause:ve,onSend:Oe,onQueue:ke,setToolsOpen:ut,requestTranscriptBottom:Nt}),rn=n.at(-1)?.role===`agent`?n.at(-1):null,on=re||(R?``:String(rn?.error||``)),sn=!R&&n.some(e=>e.role===`user`);(0,Z.useEffect)(()=>{it(!1),ot(!1),ut(!1)},[e.id]),(0,Z.useEffect)(()=>{ie&&(yt([ie]),ue?.())},[ie,ue,yt]),(0,Z.useEffect)(()=>{if(!lt)return;let e=e=>{e.key!==`Escape`||e.defaultPrevented||document.querySelector(mo)||(ut(!1),Ct.current?.focus())},t=e=>{let t=e.target;t instanceof Element&&!t.closest(ho)&&ut(!1)};return document.addEventListener(`keydown`,e),document.addEventListener(`pointerdown`,t),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`pointerdown`,t)}},[lt]);let cn=async e=>{let t=await je?.(e);if(!t||!nt(t))return;let n=bt.current;requestAnimationFrame(()=>{!n||bt.current!==n||!n.isConnected||(n.focus(),n.style.height=`auto`,n.style.height=`${Math.min(n.scrollHeight,220)}px`)})},ln=e=>{Ze(e),requestAnimationFrame(()=>{let e=bt.current;e&&(e.focus(),e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,220)}px`)})},un={attachment:G(`chat:focusSession.addAttachment`),resource:G(`chat:resourcePicker.open`),visual:G(`chat:focusSession.generateImage`),model:G(`chat:focusSession.modelAndThinking`),permission:G(`chat:focusSession.approvalMode`),"run-mode":G(`chat:focusSession.executionMode`),commands:G(`chat:focusSession.commands`),"compact-context":G(`chat:focusSession.compactContextNow`)},dn={attachment:(0,Q.jsx)(Pr,{cwd:A,selection:Qe}),resource:(0,Q.jsx)(`button`,{type:`button`,className:`resource-picker-trigger grid size-9 min-w-9 place-items-center rounded-[var(--r-sm)] border-0 bg-[var(--surface-subtle)] text-[var(--text-muted)] hover:bg-[var(--surface-hover)] hover:text-[var(--star-strong)]`,title:G(`chat:resourcePicker.open`),"aria-label":G(`chat:resourcePicker.open`),onClick:()=>it(!0),children:(0,Q.jsx)(D,{size:16})}),visual:Je?(0,Q.jsx)(Vi,{notify:ce,onOpenModelSettings:le,onInsertPrompt:ln}):null,model:(0,Q.jsx)(bi,{model:M?.model||l,models:j,onModelChange:U,thinkingLevel:M?.thinkingLevel||u||`medium`,levels:M?.model?[]:d||[],status:f,message:p,onThinkingChange:pe,modelDisabled:N||P,thinkingDisabled:P||N,deferred:R,pendingModel:!!M?.model}),permission:(0,Q.jsx)(Si,{showLabel:!0,value:m,onChange:me,disabled:I}),"run-mode":He?(0,Q.jsx)(wi,{mode:Ft,goal:h,teamAvailable:Ue,disabled:R,tokenBudget:Ft===`team`?zt:Lt,onTokenBudgetChange:Ft===`team`?Vt:X,onSaveTokenBudget:e=>ye?.(e),onChange:e=>{h?.status===`active`&&(e===`plan`||e!==h.mode)&&en().catch(()=>{}),It(e),he(e)}}):null,commands:(0,Q.jsxs)(`button`,{type:`button`,className:`command-palette-trigger relative grid size-9 min-w-9 place-items-center rounded-[var(--r-sm)] border-0 bg-[var(--surface-subtle)] text-[var(--text-muted)] hover:bg-[var(--surface-hover)] hover:text-[var(--star-strong)] [&_kbd]:sr-only`,title:Le?G(`chat:focusSession.openCommandPaletteShortcut`,{shortcut:Le}):G(`chat:focusSession.commands`),"aria-label":Le?G(`chat:focusSession.openCommandPaletteShortcut`,{shortcut:Le}):G(`chat:focusSession.commands`),onClick:an,children:[(0,Q.jsx)(ir,{size:16}),(0,Q.jsx)(`kbd`,{children:Le})]}),"compact-context":(0,Q.jsx)(ro,{streaming:R,compactingManually:Zt,compactionActive:!!w?.active,disabled:!ge||R||Zt||!!w?.active||n.length===0,onCompact:()=>void tn()})},fn=ii(Tt,Yr.filter(e=>dn[e]!==null),Math.max(wt,Be?5:8.5),Be?{permission:2.3,"run-mode":1.8,model:3.6}:{permission:2.6,"run-mode":2,model:3.9}),pn=e=>(0,Q.jsxs)(`div`,{className:L(`composer-toolbar-slot flex min-w-0 flex-none items-center gap-2`,e===`model`&&`ml-auto [.composer-tool-tray_&]:ml-0`,![`model`,`permission`,`run-mode`].includes(e)&&`h-10 [&>button]:!size-10 [&>div]:!size-10 [&>div>button]:!size-10`),"data-composer-tool-id":e,children:[dn[e],![`model`,`permission`,`run-mode`].includes(e)&&(0,Q.jsx)(`span`,{className:`hidden text-xs text-muted-foreground [.composer-tool-tray_&]:block`,children:un[e]})]},e),mn=(0,Q.jsxs)(`button`,{type:`button`,className:`header-workspace inline-flex h-8 min-w-0 max-w-[150px] shrink items-center gap-1.5 rounded-md px-1.5 text-xs text-muted-foreground hover:bg-muted disabled:opacity-50 @max-[520px]:size-8 @max-[520px]:shrink-0 @max-[520px]:justify-center @max-[520px]:[&_span]:hidden`,title:A,"aria-label":G(`chat:focusSession.changeWorkingDirectoryWorkspace`,{workspace:Rt(A,Ne)}),onClick:xe,disabled:R||F,children:[(0,Q.jsx)(W,{size:12}),(0,Q.jsx)(`span`,{className:`truncate`,children:Rt(A,Ne)})]}),hn=(0,Q.jsxs)(Bt,{"data-window-drag-region":!0,"data-context-aside":H&&!ae||void 0,className:L(`workbench-chat-header relative z-4 h-12 shrink-0 items-center gap-2 border-0 bg-transparent px-4 py-1`,window.pisperDesktop?.platform===`darwin`&&`pl-[74px]`),children:[(0,Q.jsx)(Ge,{}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1`,"data-window-drag-region":!0,children:[mn,(0,Q.jsx)(`span`,{className:`text-muted-foreground/40`,"aria-hidden":`true`,children:`/`}),(0,Q.jsxs)(`button`,{type:`button`,className:`group inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-md px-1.5 py-1 text-[13px] font-medium hover:bg-muted`,title:G(`chat:focusSession.renameChat`),"aria-label":G(`chat:focusSession.renameChat`),onClick:Se,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:e.name||G(`navigation:pageHeader.newChat`)}),(0,Q.jsx)(qe,{size:12,"aria-hidden":`true`,className:`shrink-0 opacity-0 group-hover:opacity-60 group-focus-visible:opacity-60`})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-none items-center gap-1`,children:[window.pisperDesktop?.terminalProfiles&&Jt(Ve,`terminal`)&&(0,Q.jsx)(`button`,{type:`button`,className:`grid size-8 place-items-center rounded-md text-muted-foreground hover:bg-muted`,"aria-label":G(`navigation:pageHeader.toggleTerminal`),title:G(`navigation:pageHeader.toggleTerminal`),onClick:()=>window.dispatchEvent(new Event(`pisper:toggle-terminal`)),children:(0,Q.jsx)(tt,{size:16})}),(0,Q.jsx)(Li,{visible:n.length>0,open:at,sessionId:e.id,streaming:!!R,revision:O,pulseToken:k,onOpenChange:ot,onNavigated:async e=>{e!==null&&ln(e),await De?.(),Nt()},onCreateChildSession:e=>Te(e)}),(0,Q.jsx)(`button`,{type:`button`,className:`grid size-8 place-items-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":G(H?`chat:sessionContext.close`:`chat:sessionContext.open`),title:G(H?`chat:sessionContext.close`:`chat:sessionContext.open`),"aria-expanded":H,"aria-controls":oe,"aria-haspopup":ae?`dialog`:void 0,onPointerDown:()=>{vt.current=H},onPointerCancel:()=>{vt.current=null},onClick:()=>{let e=vt.current??H;vt.current=null,se(!e)},children:H?(0,Q.jsx)(dr,{size:16}):(0,Q.jsx)(fr,{size:16})}),(0,Q.jsx)(fe,{compact:!0,theme:Ie,onCycle:Pe})]})]}),gn=(0,Q.jsx)(Fe,{layoutMeasurementKey:`fixed`,sessionId:e.id,messages:n,transcriptLoadState:r,messageStart:i,hasOlder:a,loadingOlder:o,olderError:s,currentActivity:v,team:g,activityFeed:y,tools:b,thinkingText:x,compaction:w,streaming:R,runStartedAt:z,lastActivityAt:B,runFinishedAt:ee,runStopped:V,runNotice:te,error:re,scrollRequest:_t,cwd:A,lineage:e.lineage,switchingCwd:F,onLoadOlder:de,onBranchFromHere:Ce,onCreateChildSession:Te,onRetryLastTurn:Ee,onPromptSelect:ln,onWorkspace:xe},`transcript`),_n=(0,Q.jsxs)(`div`,{ref:J,className:`focus-composer-quick-actions flex min-w-0 flex-1 items-end gap-1`,children:[(0,Q.jsx)(`button`,{ref:Ct,type:`button`,className:`composer-tools-trigger grid size-9 min-w-9 max-[650px]:w-11 max-[650px]:min-w-11 h-10 flex-none place-items-center rounded-lg border-0 bg-transparent text-muted-foreground transition-colors hover:bg-foreground/5 hover:text-foreground ${lt?`active bg-foreground/5 text-foreground`:``}`,title:jt,"aria-label":jt,"aria-expanded":lt,"aria-controls":At,onClick:()=>ut(e=>!e),children:lt?(0,Q.jsx)(dt,{size:17}):(0,Q.jsx)(Ye,{size:18})}),(0,Q.jsx)(`div`,{className:`focus-composer-visible-tools flex min-w-0 flex-1 flex-wrap items-center gap-0.5`,children:fn.inline.map(pn)}),(0,Q.jsxs)(ai,{placement:`top`,open:lt,label:G(`chat:focusSession.quickActions`),trayId:At,anchorRef:Ct,menuRef:Y,children:[fn.overflow.map(pn),(0,Q.jsxs)(`button`,{type:`button`,className:`flex h-9 w-full items-center gap-2 rounded-md px-2 text-xs text-muted-foreground hover:bg-muted`,"aria-expanded":pt,onClick:()=>{mt(e=>!e),ut(!1)},children:[(0,Q.jsx)(et,{size:15}),G(pt?`chat:focusSession.hideDetails`:`chat:focusSession.details`)]}),(0,Q.jsx)(`div`,{className:`w-full border-t border-[var(--stroke-soft)] pt-1`,children:(0,Q.jsx)(di,{labels:un,labeled:!0})})]})]}),vn=(0,Q.jsx)(mi,{usage:E,plan:We?_:null,compact:Be}),yn=e=>Tr(e.dataTransfer)?(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`),gt(!0),!0):!1,bn=(0,Q.jsxs)(`form`,{className:`focus-composer-shell relative z-20 mx-auto flex w-[min(600px,calc(100%_-_40px))] shrink-0 flex-col gap-2 pt-2 pb-4 @max-[700px]:w-[calc(100%_-_24px)]`,onSubmit:e=>{if(!R&&(M||N||P)){e.preventDefault();return}nn(e)},children:[(0,Q.jsx)(we,{approvals:ne,onResolve:be}),S.length>0&&(0,Q.jsx)(eo,{queuedInputs:S,withdrawingInputIds:C,onWithdraw:je?cn:void 0}),Ke&&(0,Q.jsx)(Bi,{sessionId:e.id}),Qt&&(0,Q.jsx)(to,{invocation:Qt,onRemove:()=>$t(null)}),(0,Q.jsx)(Fr,{attachments:Qe.attachments,onRemove:Qe.removeAttachment}),Qe.attachmentError&&(0,Q.jsx)(`span`,{className:`text-[var(--danger)] text-[13px]`,children:Qe.attachmentError}),on&&(0,Q.jsx)(Ae,{error:on,onRetry:sn?Ee:void 0,className:`w-full`}),(0,Q.jsx)(no,{compaction:w,streaming:R,statusLabel:kt}),(0,Q.jsxs)(`div`,{className:L(`focus-composer relative flex min-w-0 flex-col gap-2 rounded-[18px] border border-border/70 bg-muted/45 p-2.5 shadow-xs transition-[border-color,box-shadow] focus-within:border-ring/50 focus-within:shadow-md dark:bg-[#242424] [&_textarea]:w-full [&_textarea]:min-w-0 [&_textarea]:min-h-[40px] [&_textarea]:max-h-[220px] [&_textarea]:resize-none [&_textarea]:overflow-y-auto [&_textarea]:border-0 [&_textarea]:[outline:0]! [&_textarea]:bg-transparent [&_textarea]:px-1 [&_textarea]:py-1.5 [&_textarea]:text-[length:var(--app-message-font-size)] [&_textarea]:font-normal [&_textarea]:leading-relaxed [&_textarea]:text-foreground [&_textarea]:placeholder:text-muted-foreground`,ht&&`border-ring ring-2 ring-ring/30`),onDragEnter:yn,onDragOver:yn,onDragLeave:e=>{let t=e.relatedTarget;t instanceof Node&&e.currentTarget.contains(t)||gt(!1)},onDrop:e=>{gt(!1),Qe.dropFiles(e)},children:[ht&&(0,Q.jsx)(`div`,{role:`status`,className:`pointer-events-none absolute inset-0 z-10 grid place-items-center rounded-[18px] border border-dashed border-ring bg-background/85 px-4 text-center text-sm text-foreground`,children:G(`chat:focusSession.dropAttachment`)}),(0,Q.jsx)(Jr,{placement:`top`,sessionId:e.id,value:Xe,onChange:Ze,inputRef:bt}),(0,Q.jsx)(`textarea`,{ref:bt,rows:1,"aria-label":G(`chat:focusSession.taskDescription`),value:Xe,onChange:e=>{Ze(e.target.value),e.currentTarget.style.height=`auto`,e.currentTarget.style.height=`${Math.min(e.currentTarget.scrollHeight,220)}px`},onPaste:Qe.pasteFiles,onCompositionStart:()=>Et.current=!0,onCompositionEnd:()=>window.setTimeout(()=>Et.current=!1,0),onKeyDown:e=>{!(e.nativeEvent.isComposing||Et.current)&&Gt(e.nativeEvent,K.sendMessage)&&(e.preventDefault(),e.currentTarget.form?.requestSubmit())},"data-mobile-composer-input":Be||void 0,enterKeyHint:Be&&K.sendMessage===`Enter`?`send`:`enter`,placeholder:Mt}),(0,Q.jsxs)(`div`,{className:`focus-composer-footer flex min-w-0 items-end gap-1`,children:[_n,(0,Q.jsx)(io,{streaming:R,queueing:qt,disabled:!R&&(!!M||N||P||qt||!Xe.trim()&&!Qe.attachments.length&&!Qt),onAbort:Me})]})]}),(0,Q.jsxs)(`div`,{className:L(`composer-details flex min-h-9 min-w-0 flex-wrap items-center gap-2 px-2 py-1 text-xs text-muted-foreground`,!pt&&`!hidden`),children:[Dt&&vn,(0,Q.jsx)(`button`,{type:`button`,className:`grid size-7 place-items-center rounded-md hover:bg-muted`,"aria-label":G(`chat:focusSession.hideDetails`),onClick:()=>mt(!1),children:(0,Q.jsx)(dt,{size:14})}),(0,Q.jsxs)(`div`,{className:`ml-auto flex items-center gap-1 [&_.voice-input-control_button]:!size-8`,children:[(0,Q.jsx)(`div`,{className:`focus-composer-secondary flex h-8 min-w-0 flex-none items-center justify-end`,children:(0,Q.jsx)(hi,{usage:T,sessionUsage:E,model:l,availableModels:j,onThresholdChange:_e,compact:!0})}),(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{type:`button`,className:`grid !size-8 !min-w-8 place-items-center rounded-[var(--r-sm)] border border-transparent bg-[var(--surface-subtle)] text-[var(--text-muted)] transition-[background-color,color,border-color,box-shadow,transform] duration-200 hover:scale-105 hover:border-[var(--brand-blue)] hover:bg-[var(--brand-blue-soft)] hover:text-[var(--brand-blue-strong)]`,title:G(`chat:voiceMode.open`),"aria-label":G(`chat:voiceMode.open`),onClick:()=>ct(!0),children:(0,Q.jsx)(er,{size:17})}),(0,Q.jsx)(Oa,{sessionId:e.id,shortcutEnabled:t,onLiveText:e=>{if(e===null){St.current!==null&&(Pt(St.current),St.current=null);return}St.current===null&&(St.current=(bt.current?.value??Xe).trimEnd());let t=St.current;Pt(t&&e?`${t}\n${e}`:t||e)},onInsert:e=>{let t=St.current??(bt.current?.value??Xe).trimEnd();St.current=null,Pt(t?`${t}\n${e}`:e),requestAnimationFrame(()=>bt.current?.focus())}})]})]})]}),!Dt&&!R&&(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(po,{plansAvailable:We,onPromptSelect:ln})})]},`composer`);return(0,Q.jsxs)(Ht,{className:L(`focus-session [--chat-content-width:768px] [.session-dock-panel_&]:overflow-hidden [.session-dock-panel_&]:min-h-0 [.session-dock-panel_&]:border-0 [.session-dock-panel_&]:rounded-[0] [.session-dock-panel_&]:bg-[var(--panel)] [.session-dock-panel_&]:p-0 [.session-dock-panel_&]:shadow-[none] [[data-theme='dark']_.session-dock-panel_&]:bg-[var(--main-surface-bg)] min-[651px]:[[data-density='compact']_.app-card:not(&)]:p-[10px] max-[650px]:min-h-[460px] max-[650px]:[.session-dock-panel_&]:min-h-0 relative flex h-full min-h-0 flex-col ${Dt?`has-conversation`:`is-empty`}`,Ot&&`[&_[data-chat-region=messages]]:!flex-none [&_[data-chat-region=messages]]:mt-[max(48px,calc((100dvh-560px)/2))] [&_[data-chat-region=messages]]:h-[160px] [&_[data-chat-region=messages]]:!overflow-visible [&_.transcript]:!overflow-visible [&_.transcript]:!p-0 max-[650px]:[&_[data-chat-region=messages]]:mt-8 max-[650px]:[&_[data-chat-region=messages]]:h-[150px]`),"data-chat-message-style":`bubble`,children:[(0,Q.jsxs)(`div`,{className:L(`flex h-full min-h-0 min-w-0 flex-1 flex-col`,Dt?`overflow-hidden`:`overflow-auto`),children:[(0,Q.jsx)(`div`,{className:`shrink-0`,"data-chat-region":`header`,children:hn}),(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,"data-chat-region":`messages`,children:gn}),(0,Q.jsx)(`div`,{className:`shrink-0`,"data-chat-region":`composer`,children:bn})]}),(0,Q.jsx)(Ir,{open:rt,sessionId:e.id,onClose:()=>it(!1),onSelect:$t,onCommandSelect:e=>ln(zr(e,Xe))}),(0,Q.jsx)(Za,{open:st,sessionId:e.id,sessionName:e.name||e.id,messages:n,streaming:R,sendPrompt:Oe,onAbort:Me,onClose:()=>ct(!1)})]})}),_o=(0,Z.createContext)(null),vo=40,yo=[];function bo({onCreateSession:e}){let t=(0,Z.useContext)(_o)?.activeId||``;return t?(0,Q.jsx)(xo,{sessionId:t,panelId:`single-${t}`,shortcutEnabled:!0,canSplitPanel:!1,canClosePanel:!1},t):(0,Q.jsx)(So,{onNewSession:e})}function xo({sessionId:e,panelId:t,shortcutEnabled:n,onFocusCapture:r,canSplitPanel:i,canClosePanel:a}){let o=(0,Z.useContext)(_o),s=o?.subscribeSessionState,c=o?.getSessionState,l=(0,Z.useMemo)(()=>t=>s?.(e,t)??(()=>{}),[s,e]),u=(0,Z.useMemo)(()=>()=>c?.(e),[c,e]),d=(0,Z.useSyncExternalStore)(l,u),f=o?.sessions.find(t=>t.id===e),p=d||ke,m=je(p,f),h=Ve(d,f),g=d&&Object.hasOwn(d,`team`)?d.team:f?.team??null,_=He(h,{streaming:m})?h:null,v=o?.sessionTreePulseSessionId===e?o.sessionTreePulseToken:0,y=o?.loadSessionMessages,b=o?.loadSessionThinkingLevel,x=(0,Z.useRef)(``);(0,Z.useEffect)(()=>{e&&y?.(e,{limit:vo})},[y,e]),(0,Z.useEffect)(()=>{!e||!f||!b||p.thinkingStatus||(p.availableThinkingLevels||[]).length||x.current!==e&&(x.current=e,b(e))},[b,f,e,p.availableThinkingLevels,p.thinkingStatus,m]);let S=(0,Z.useMemo)(()=>({onLoadOlder:()=>o?.loadOlderMessages(e)??!1,onModelChange:t=>o?.switchSessionModel(e,t),onThinkingLevelChange:t=>o?.switchSessionThinkingLevel(e,t),onExecutionModeChange:t=>o?.switchSessionExecutionMode(e,t)??!1,onRunModeChange:t=>o?.switchSessionRunMode(e,t)??!1,onGoalPause:()=>o?.pauseGoal(e),onGoalBudgetChange:t=>o?.setGoalBudget(e,t),onCompact:()=>o?.compactSession(e),onApproval:(t,n)=>o?.resolveToolApproval(e,t,n),onWorkspace:()=>{f&&o?.selectSessionWorkspace(f)},onRename:()=>{f&&o?.renameSession(f)},onBranchFromHere:e=>{if(f)return o?.branchFromEntry(f,e)},onCreateChildSession:e=>{if(f)return o?.createChildSession(f,e)},onRetryLastTurn:()=>o?.retryLastTurn(e),onTreeNavigated:()=>o?.reloadSessionBranch(e),onSplitLeft:()=>o?.splitDockPanel(t,`left`),onSplitRight:()=>o?.splitDockPanel(t,`right`),onSplitTop:()=>o?.splitDockPanel(t,`above`),onSplitBottom:()=>o?.splitDockPanel(t,`below`),onClosePanel:()=>o?.closeDockPanel(t),onToggleContext:t=>o?.toggleSessionContext(e,t),onSend:(t,n,r,i,a,s)=>o?.sendPrompt(t,e,n,r,i,a,s),onQueue:(t,n,r)=>o?.queuePrompt(t,e,n,r)??!1,onWithdrawQueuedInput:t=>o?.withdrawQueuedInput(e,t)??Promise.resolve(null),onAbort:()=>o?.abort(e)}),[o,e,f,t]);if(!o||!f)return(0,Q.jsxs)(`div`,{className:`session-dock-missing flex h-full min-h-[180px] items-center justify-center gap-[8px] text-[var(--text-secondary)] text-[length:var(--app-font-size)]`,children:[(0,Q.jsx)(at,{size:16}),o?`Session unavailable`:`Loading session`]});let C=o.pendingAsset?.asset&&(!o.pendingAsset.targetSessionId||o.pendingAsset.targetSessionId===e)?o.pendingAsset.asset:null;return(0,Q.jsx)(`div`,{className:`session-dock-panel w-full h-full min-w-0 min-h-0 overflow-hidden [container-type:inline-size] bg-[var(--panel)]`,onFocusCapture:r,children:(0,Q.jsx)(go,{session:f,shortcutEnabled:n,messages:p.messages||yo,transcriptLoadState:p.loaded?`ready`:p.loading||!p.error?`loading`:`error`,messageStart:p.messageStart,hasOlder:p.hasOlder,loadingOlder:p.loadingOlder,olderError:p.olderError,model:p.model||f.model||o.defaultModel,thinkingLevel:p.thinkingLevel||f.thinkingLevel||`medium`,availableThinkingLevels:p.availableThinkingLevels||yo,thinkingStatus:p.thinkingStatus||``,thinkingMessage:p.thinkingMessage||``,executionMode:p.executionMode||f.executionMode||`approval-required`,runMode:p.runMode||f.runMode||`plan`,goal:p.goal??f.goal??null,team:g,plan:_,currentActivity:p.currentActivity,activityFeed:p.activityFeed||yo,tools:p.tools||yo,thinkingText:p.thinkingText||``,queuedInputs:p.queuedInputs||yo,withdrawingInputIds:p.withdrawingInputIds||yo,compaction:p.compaction,contextUsage:p.contextUsage,sessionUsage:p.sessionUsage,sessionTreeRevision:p.sessionTreeRevision,sessionTreePulse:v,cwd:p.cwd||f.cwd,availableModels:o.availableModels,pendingRuntimeSelection:p.pendingRuntimeSelection,switchingModel:p.switchingModel,switchingThinking:p.switchingThinking,switchingCwd:p.switchingCwd,switchingPermission:p.switchingPermission,streaming:m,runStartedAt:p.runStartedAt,lastActivityAt:p.lastActivityAt,runFinishedAt:p.runFinishedAt,runStopped:p.runStopped,runNotice:p.runNotice,approvals:p.approvals||yo,error:p.error||(o.activeId===e?o.globalError:``),pendingAsset:C,onAssetConsumed:o.onAssetConsumed,notify:o.notify,onOpenModelSettings:o.openModelSettings,onCompactionThresholdChange:o.setCompactionThreshold,canSplit:i,canClosePanel:a,contextOpen:!!(o.contextTab&&o.activeId===e),contextCompact:o.contextCompact,contextPanelId:o.contextPanelId,...S})})}function So({onNewSession:e,newSessionShortcut:t}){let{t:n}=c();return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-[180px] flex-col items-center justify-center gap-[8px] text-center text-[length:var(--app-font-size)] text-[var(--text-secondary)]`,children:[(0,Q.jsx)(We,{size:34}),(0,Q.jsx)(`strong`,{className:`text-[14px] font-semibold text-[var(--text)]`,children:n(`chat:chatDock.openAChatToBegin`)}),(0,Q.jsx)(`span`,{className:`max-w-[320px] leading-[1.55]`,children:n(`chat:chatDock.openAChatFromTheSessionListOrSplitItInAnyDirection`)}),e?(0,Q.jsxs)(`button`,{type:`button`,className:`mt-[10px] inline-flex cursor-pointer items-center gap-[6px] rounded-[var(--r-sm)] border-0 bg-[var(--brand-blue)] px-[16px] py-[8px] text-[length:var(--app-font-size)] font-medium text-white transition-colors duration-[var(--d1)] hover:bg-[var(--brand-blue-hover)] focus-visible:outline-[2px] focus-visible:outline-offset-2 focus-visible:outline-[var(--focus)]`,onClick:()=>void e(),children:[(0,Q.jsx)(Ye,{size:14,"aria-hidden":`true`}),n(`chat:chatDock.newChat`),t?(0,Q.jsx)(`kbd`,{className:`ml-[2px] rounded-[4px] border border-white/35 bg-white/10 px-[5px] py-[1px] font-sans text-[length:var(--app-small-size)] font-medium leading-[1.4]`,children:t}):null]}):null]})}function Co({notify:e}){let{t:r}=c(),i=Ct(),[a,o]=(0,Z.useState)([]),[s,l]=(0,Z.useState)(()=>n.getItem(f.activeSession)||``),[u,d]=(0,Z.useState)({}),[p,m]=(0,Z.useState)(!0),[h,g]=(0,Z.useState)(``),[_,v]=(0,Z.useState)(()=>r(`chat:chatPage.waitingForConfiguration`)),[y,b]=(0,Z.useState)([]),x=(0,Z.useRef)(a),S=(0,Z.useRef)(u),C=(0,Z.useRef)(new Map),w=(0,Z.useRef)(null),T=(0,Z.useRef)(new Map),E=(0,Z.useRef)(new Set),[D]=(0,Z.useState)(ne),O=(0,Z.useCallback)(e=>{let t=x.current,n=typeof e==`function`?e(t):e;return x.current=n,o(n),n},[]);(0,Z.useEffect)(()=>hn(window,e=>{D.record(e),O(t=>V(t,e))}),[D,O]),(0,Z.useEffect)(()=>fn(window,e=>{O(t=>ie(t,e))}),[O]);let k=(0,Z.useCallback)(e=>{let t=E.current.size?Object.fromEntries(Object.entries(e).filter(([e])=>!E.current.has(e))):e,n=S.current;S.current=t,d(t);let r=Object.keys(t).filter(e=>t[e].streaming!==n[e]?.streaming);if(r.length){let e=new Set(r);i.setQueryData([`sessions`],n=>n&&{...n,sessions:n.sessions.map(n=>e.has(n.id)?{...n,streaming:t[n.id].streaming}:n)})}let a=new Set([...Object.keys(n),...Object.keys(t)]);for(let e of a){if(n[e]===t[e])continue;let r=C.current.get(e);if(r)for(let e of[...r])e()}},[i]);(0,Z.useEffect)(()=>tn(window,({deletedIds:e})=>{D.remove(e);let t=new Set(e),n=O(e=>e.filter(e=>!t.has(e.id)));l(e=>t.has(e)?n[0]?.id||``:e);let r=S.current;e.some(e=>e in r)&&k(Object.fromEntries(Object.entries(r).filter(([e])=>!t.has(e))))}),[k,D,O]);let A=(0,Z.useCallback)((e,t)=>{let n=C.current.get(e)||new Set;return n.add(t),C.current.set(e,n),()=>{n.delete(t),n.size||C.current.delete(e)}},[]),j=(0,Z.useCallback)(e=>S.current[e]||ke,[]),M=(0,Z.useCallback)((e,t)=>{if(!e||E.current.has(e))return;let n=S.current,r=n[e]||ke,i=Ce(r,t);i!==r&&k({...n,[e]:i})},[k]),N=(0,Z.useCallback)((e,{panelOpen:t=!1,localStreamOwned:n=!1}={})=>{if(!e||t||n||T.current.has(e))return!1;let r=S.current,i=r[e];if(!i||xe(i))return!1;let a={...r};return delete a[e],k(a),!0},[k]),P=(0,Z.useCallback)(e=>{if(!e)return;E.current.add(e);let t={...S.current};delete t[e],k(t)},[k]),F=(0,Z.useCallback)(e=>{if(E.current.has(e))return()=>{};let t=T.current;t.set(e,(t.get(e)??0)+1);let n=!1;return()=>{if(n)return;n=!0;let r=t.get(e)??0;r>1?t.set(e,r-1):(t.delete(e),N(e))}},[N]),I=(0,Z.useCallback)(async(e,{preserveExistingOnEmpty:t=!1}={})=>{let n=D.getRevision(),r=await Y.listSessions(),i=t&&!r.sessions.length&&x.current.length?x.current:D.reconcile(r.sessions,n);return O(i),l(e||(e=>i.some(t=>t.id===e)?e:i[0]?.id||``)),un(),i},[D,O]),L=(0,Z.useCallback)((t=``,{inheritRecentCwd:n=!0}={})=>{if(w.current)return w.current;let i=(async()=>{try{g(``);let i=await Y.createSession(r(`chat:chatPage.newChat`),te(t,x.current,n));l(i.id),O(e=>B(e,[i])),M(i.id,{messages:[],tools:[],approvals:[],queuedInputs:[],permissionMode:i.permissionMode||`ask`,executionMode:i.executionMode||`approval-required`,runMode:i.runMode||`plan`,goal:i.goal||null,plan:ye(i,null),contextUsage:i.contextUsage||null,sessionUsage:i.sessionUsage||null,compaction:null,streaming:!1,error:``,loaded:!0,pageSize:40,messageStart:0,hasOlder:!1,olderCursor:null,runStartedAt:null,lastActivityAt:null,runFinishedAt:null,runStopped:!1,runNotice:``});try{await I(i.id)}catch(e){g(r(`chat:chatPage.theChatWasCreatedButTheListCouldNotBeRefreshedError`,{error:K(e)}))}return e(r(`chat:chatPage.newChatCreated`)),i.id}catch(e){return g(K(e)),``}})();return w.current=i,i.finally(()=>{w.current===i&&(w.current=null)}),i},[e,I,r,M,O]);(0,Z.useEffect)(()=>{let i=!0,a=D.getRevision();return Promise.all([Y.listSessions({refresh:!1}),Y.getConfig()]).then(async([o,s])=>{if(!i)return;v(s.model?`${s.provider}/${s.model}`:r(`chat:chatPage.noModelConfigured`)),b(s.providers.flatMap(e=>e.configured&&e.enabled?e.models.filter(e=>e.kind===`chat`).map(t=>({key:`${e.id}/${t.id}`,provider:e.id,modelId:t.id,label:t.name||t.id,providerName:e.name||e.id})):[]));let c=o.sessions;if(!c.length&&(w.current||Object.keys(S.current).length)){if(await w.current,!i)return;a=D.getRevision(),c=(await Y.listSessions()).sessions}if(c.length||(c=[await Y.createSession(r(`chat:chatPage.newChat`))]),!i)return;c=D.reconcile(c,a),O(e=>B(e,c));for(let e of c)M(e.id,{team:e.team||null,agents:e.agents||[],plan:ye(e,null),...e.streaming?{streaming:!0,recovering:!0,loaded:!1,error:``}:{}});let u=n.getItem(f.activeSession),d=new Set([...c.map(e=>e.id),...Object.keys(S.current)]);if(l(e=>d.has(e)?e:u&&d.has(u)?u:c[0]?.id||``),typeof window<`u`&&window.__PISPER_MOBILE_APP__)try{let{consumeRemoteFallbackNotice:n}=await t(async()=>{let{consumeRemoteFallbackNotice:e}=await import(`./mobile-remote-fallback-JlHu_hz6.js`);return{consumeRemoteFallbackNotice:e}},__vite__mapDeps([30,17]));n()&&e(r(`chat:chatPage.remoteUnavailableSwitchedToLocal`))}catch{}}).catch(async e=>{if(i){if(typeof window<`u`&&window.__PISPER_MOBILE_APP__)try{let{fallbackRemoteToLocalAfterFailure:n}=await t(async()=>{let{fallbackRemoteToLocalAfterFailure:e}=await import(`./mobile-remote-fallback-JlHu_hz6.js`);return{fallbackRemoteToLocalAfterFailure:e}},__vite__mapDeps([30,17]));if(await n(e))return}catch{}i&&g(K(e))}}).finally(()=>i&&m(!1)),()=>{i=!1}},[e,r,D,M,O]),(0,Z.useEffect)(()=>{s?n.setItem(f.activeSession,s):n.removeItem(f.activeSession)},[s]);let R=a.find(e=>e.id===s),z=(u[s]||ke).model||R?.model||``;return(0,Z.useEffect)(()=>{ln(s,z)},[s,z]),(0,Z.useEffect)(()=>(document.title=R?.name?`${R.name} · ${_n}`:_n,()=>{document.title=_n}),[R?.name]),{sessions:a,sessionsRef:x,activeId:s,setActiveId:l,sessionStates:u,sessionStatesRef:S,loading:p,globalError:h,setGlobalError:g,defaultModel:_,availableModels:y,updateSessions:O,replaceSessionStates:k,updateSessionState:M,releaseSessionState:N,retainSessionState:F,discardSessionState:P,subscribeSessionState:A,getSessionState:j,refreshSessions:I,createSessionRecord:L}}var wo=`web-preview`;function To(e,t=`Web preview`){try{return new URL(e).hostname.replace(/^www\./i,``)||t}catch{return t}}function Eo({sessions:e,sessionsRef:t,sessionStates:n,activeId:r,setActiveId:i,loading:a,localStreamSessionsRef:o,loadSessionMessages:s,releaseSessionState:l,singleSessionLayout:u,notify:d}){let{t:p}=c(),[m,h]=(0,Z.useState)(0),g=(0,Z.useRef)(u);g.current=u;let[_,v]=(0,Z.useState)(()=>window.matchMedia(`(max-width: 900px)`).matches),y=(0,Z.useRef)(null),b=(0,Z.useRef)(!1),x=(0,Z.useRef)([]),S=(0,Z.useRef)(void 0),C=(0,Z.useRef)(null),w=(0,Z.useRef)(null),T=(0,Z.useRef)(null),E=(0,Z.useRef)(_),D=(0,Z.useRef)(null),O=(0,Z.useRef)(!1),[k,A]=(0,Z.useState)(null),[j,M]=(0,Z.useState)(!1),[N,P]=(0,Z.useState)([]);(0,Z.useEffect)(()=>{!u||!r||P(e=>e.includes(r)?e:[...e,r])},[r,u]);let F=(0,Z.useMemo)(()=>{let t=new Set(e.map(e=>e.id));return[...N,...Qt(k?.layout),r].filter((e,n,r)=>e&&t.has(e)&&r.indexOf(e)===n)},[r,N,e,k]);(0,Z.useEffect)(()=>{let e=!0;return bt(`/api/settings/chat-dock-layout`).then(t=>{e&&(A(pn(t)),M(!0))}).catch(()=>{e&&M(!0)}),()=>{e=!1}},[]),(0,Z.useEffect)(()=>{let e=window.matchMedia(`(max-width: 900px)`),t=()=>{E.current=e.matches,v(e.matches)};return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let I=(0,Z.useCallback)(()=>{O.current||(O.current=!0,(async()=>{do{for(;D.current;){let e=D.current;D.current=null;try{await bt(`/api/settings/chat-dock-layout`,{method:`PUT`,body:e})}catch{}}O.current=!1,D.current&&(O.current=!0)}while(O.current)})())},[]),L=(0,Z.useCallback)(e=>{D.current=e,I()},[I]),R=(0,Z.useCallback)((e=y.current)=>{if(!b.current)return!1;window.clearTimeout(S.current),S.current=void 0;let t=C.current;if(e)try{let n=rn(e.toJSON(),e.activePanel?.id||``);t=JSON.stringify(n)}catch{}return t?(L(t),C.current=null,!0):!1},[L]),z=(0,Z.useCallback)((e=y.current)=>{if(!e||!b.current)return;let t;try{t=JSON.stringify(rn(e.toJSON(),e.activePanel?.id||``))}catch{return}C.current=t,window.clearTimeout(S.current),S.current=window.setTimeout(()=>{S.current=void 0,!(!b.current||y.current!==e)&&(L(t),C.current===t&&(C.current=null))},180)},[L]),B=(0,Z.useCallback)((e,n=`open`)=>{if(g.current)return e&&P(t=>t.includes(e)?t:[...t,e]),i(e),!0;let r=t.current.find(t=>t.id===e),a=y.current;if(!r||!a||!b.current)return w.current={sessionId:e,disposition:n},!1;let o=E.current?`open`:n,c=Zt(e),l=a.getPanel(c),u=a.activePanel;if(l)return o!==`open`&&(u&&l.id!==u.id?l.api.moveTo({group:u.group,position:mn(o)}):l.group.size>1&&l.api.moveTo({group:l.group,position:mn(o)})),l.api.setActive(),i(e),!0;let d=o===`open`?a.activeGroup?{referenceGroup:a.activeGroup}:void 0:u?{referencePanel:u,direction:o}:{direction:o};return a.addPanel({id:c,component:`session`,title:r.name||p(`chat:chatPage.untitledChat`),params:{sessionId:e},renderer:`always`,minimumWidth:300,minimumHeight:240,...d?{position:d}:{}}),i(e),s(e,{limit:40}),!0},[s,t,i,p]),ee=(0,Z.useCallback)(e=>{let t=y.current;if(!t||!b.current)return T.current=e,!1;let n=t.getPanel(wo),r=To(e.url,p(`common:webPreview.title`));if(n)return n.api.updateParameters({url:e.url}),n.api.setTitle(r),n.api.setActive(),!0;let i=t.activePanel,a=E.current?t.activeGroup?{referenceGroup:t.activeGroup}:void 0:i?{referencePanel:i,direction:`right`}:{direction:`right`};return t.addPanel({id:wo,component:`webPreview`,title:r,params:{url:e.url},renderer:`always`,minimumWidth:360,...a?{position:a}:{}}),!0},[p]),V=(0,Z.useCallback)((e,t)=>{let n=y.current?.getPanel(e);if(n){if(E.current){d(p(`chat:chatPage.onNarrowScreensChatsStayInASingleTabGroup`),`info`);return}if(n.group.size<=1){d(p(`chat:chatPage.thisGroupHasOnlyOneChatChooseAnotherChatFromTheSessionListToCreateASplit`),`info`);return}n.api.moveTo({group:n.group,position:mn(t)}),n.api.setActive()}},[d,p]),te=(0,Z.useCallback)(e=>{y.current?.getPanel(e)?.api.close()},[]),ne=(0,Z.useCallback)((e,t)=>{if(!t)return;let n=y.current?.getPanel(Zt(e));n&&n.group!==t&&n.api.moveTo({group:t})},[]),re=(0,Z.useCallback)(e=>l(e,{panelOpen:!!y.current?.getPanel(Zt(e)),localStreamOwned:o.current.has(e)}),[o,l]),ie=(0,Z.useCallback)(({api:e})=>{y.current&&y.current!==e&&(b.current=!1);for(let e of x.current)e.dispose();x.current=[],y.current=e,x.current.push(e.onDidActivePanelChange(({panel:t})=>{let n=en(t);n&&i(n),z(e)}),e.onDidLayoutChange(()=>z(e)),e.onDidAddPanel(e=>{let t=en(e);t&&s(t,{limit:40})}),e.onDidRemovePanel(e=>{let t=en(e);t&&queueMicrotask(()=>re(t))})),h(e=>e+1)},[s,re,z,i]);return(0,Z.useEffect)(()=>{if(b.current)for(let e of Object.keys(n))re(e)},[re,n]),(0,Z.useEffect)(()=>{let e=e=>{let t=e.detail,n=t?.sessionId||t?.id;n&&(localStorage.removeItem(f.sessionOpenRequest),B(n,t?.disposition||`open`),t?.targetEntryId&&s(n,{force:!0,limit:40}))};return window.addEventListener(nn,e),()=>window.removeEventListener(nn,e)},[s,B]),(0,Z.useEffect)(()=>tn(window,({deletedIds:e})=>{let n=new Set(e);P(e=>e.filter(e=>!n.has(e))),w.current&&n.has(w.current.sessionId)&&(w.current=null);let r=y.current;if(!r||!b.current)return;let a=e.flatMap(e=>{let t=r.getPanel(Zt(e));return t?[t]:[]});for(let e of a)e.api.close();if(a.length&&!r.panels.some(e=>en(e))){let e=t.current.find(e=>!n.has(e.id));e?B(e.id):i(``)}}),[B,t,i]),(0,Z.useEffect)(()=>{let e=e=>{let t=e.detail;t?.url&&(localStorage.removeItem(f.webPreviewRequest),ee(t))};return window.addEventListener(lt,e),()=>window.removeEventListener(lt,e)},[ee]),(0,Z.useEffect)(()=>{let e=()=>{document.visibilityState===`hidden`&&R()},t=()=>R();return document.addEventListener(`visibilitychange`,e),window.addEventListener(`pagehide`,t),()=>{document.removeEventListener(`visibilitychange`,e),window.removeEventListener(`pagehide`,t)}},[R]),(0,Z.useEffect)(()=>()=>{let e=y.current;R(e),b.current=!1,window.clearTimeout(S.current),S.current=void 0;for(let e of x.current)e.dispose();x.current=[],y.current=null},[R]),(0,Z.useEffect)(()=>{if(!m||!j||a||b.current||!y.current)return;let t=y.current,n=new Set(e.map(e=>e.id)),i=k;if(i)try{t.fromJSON(i.layout);for(let e of[...t.panels]){if(e.api.component!==`session`)continue;let r=en(e);n.has(r)||t.removePanel(e)}}catch{t.clear()}if(!t.panels.length){let n=$t({activeSessionId:r,validSessionIds:e.map(e=>e.id)}),i;for(let r of n){let n=e.find(e=>e.id===r);if(!n)continue;let a=t.addPanel({id:Zt(r),component:`session`,title:n.name||p(`chat:chatPage.untitledChat`),params:{sessionId:r},renderer:`always`,minimumWidth:300,...i?{position:{referenceGroup:i}}:{},inactive:!!i});i||=a.group}}for(let n of t.panels){let t=e.find(e=>e.id===en(n));t&&n.api.setTitle(t.name||p(`chat:chatPage.untitledChat`))}b.current=!0,localStorage.removeItem(f.chatMode);let o=w.current||dn();w.current=null,o?(B(o.sessionId,o.disposition),o.targetEntryId&&s(o.sessionId,{force:!0,limit:40})):(t.getPanel(i?.activePanelId||Zt(r))||t.panels[0])?.api.setActive();let c=T.current||ct();T.current=null,c&&ee(c),z(t)},[r,j,m,s,a,B,ee,z,e,k,p]),(0,Z.useEffect)(()=>{if(!(!b.current||!y.current))for(let t of e)y.current.getPanel(Zt(t.id))?.api.setTitle(t.name||p(`chat:chatPage.untitledChat`))},[e,p]),{compactDock:_,mobileSessionIds:F,openSessionInDock:B,splitDockPanel:V,closeDockPanel:te,moveSessionToGroup:ne,onDockReady:ie,getTabContextMenuItems:(0,Z.useCallback)(({panel:e})=>{let t={label:p(`chat:focusSession.closeTab`),action:()=>te(e.id)};return _||e.group.size<=1?[t]:[{label:p(`chat:chatPage.splitToLeft`),action:()=>V(e.id,`left`)},{label:p(`chat:chatPage.splitToRight`),action:()=>V(e.id,`right`)},{label:p(`chat:chatPage.splitToTop`),action:()=>V(e.id,`above`)},{label:p(`chat:chatPage.splitToBottom`),action:()=>V(e.id,`below`)},`separator`,t]},[te,_,V,p])}}function Do(e){return!!e?.agents?.some(e=>[`queued`,`starting`,`running`].includes(String(e.status)))}function Oo(e,{localStreamOwned:t=!1}={}){return!e||t?!1:!!(e.recovering||e.streaming||e.approvals?.length||Do(e))}function ko(e,t){return Object.hasOwn(e,`team`)?e.team??null:t??null}function Ao(e,t){let n=new Map(e.map(e=>[e.id,e]));return t.map(e=>{let t=n.get(e.id);return t&&JSON.stringify(t)===JSON.stringify(e)?t:e})}function jo(e,t){let n=Number(t.pageInfo?.start)||0,r=Number.isInteger(e.messageStart)?e.messageStart:null,i=r!=null&&r<=n,a=i?Math.max(0,n-r):0,o=i?r:n,s=i?[...e.messages.slice(0,a),...Ao(e.messages,t.messages)]:Ao(e.messages,t.messages),c=Math.max(0,s.length-200);return c&&(s=s.slice(c),o+=c),{messages:s,messageStart:o,hasOlder:o>0,olderCursor:o>0?String(o):null}}function Mo(e,t,n){if(t.streaming||!e.error&&!t.error)return{page:n,error:t.error||``};let r=e.messages.at(-2),i=e.messages.at(-1);if(r?.role!==`user`||!/^user-\d+$/.test(r.id)||i?.role!==`agent`||!/^agent-\d+$/.test(i.id))return{page:n,error:t.error||``};let a=Date.parse(e.runStartedAt||``),o=n.messages.findIndex(e=>{if(e.id===r.id)return!0;if(e.role!==`user`||!Number.isFinite(a))return!1;let t=new Date(e.timestamp).getTime();return Number.isFinite(t)&&t>=a});if(o>=0&&n.messages.slice(o+1).some(e=>e.role===`agent`))return{page:n,error:t.error||``};let s=[...n.messages,...o<0?[r]:[],{...i,streaming:!1,error:t.error||e.error||i.error}],c=Math.max(0,s.length-200),l=n.messageStart+c;return{page:{...n,messages:c?s.slice(c):s,messageStart:l,hasOlder:l>0,olderCursor:l>0?String(l):null},error:t.error||e.error||``}}function No(e,t,n=new Date().toISOString(),r=e.runtimeSelectionRevision||0){let i=r!==(e.runtimeSelectionRevision||0),a=!!(e.switchingModel||e.switchingThinking||i),o=t.finishedAt||e.runFinishedAt||n,s=Mo(e,t,jo(e,t));return{...Te({...e,...s.page},t),tools:t.streaming?t.tools||[]:Ie(t.tools||[],{finishedAt:o,error:t.error||``}),streaming:t.streaming,recovering:t.streaming,runStartedAt:t.startedAt||e.runStartedAt||null,lastActivityAt:t.lastActivityAt||e.lastActivityAt||t.startedAt||null,runFinishedAt:t.streaming?null:o,runNotice:t.streaming&&e.runNotice||``,loaded:!0,loading:!1,error:a?e.error:s.error,model:a?e.model:t.model||e.model,cwd:t.cwd||e.cwd,permissionMode:t.permissionMode||e.permissionMode,executionMode:t.executionMode||e.executionMode,runMode:t.runMode||e.runMode,goal:t.goal??e.goal??null,team:ko(t,e.team),plan:ye(t,e.plan??null),contextUsage:a?e.contextUsage:t.contextUsage??e.contextUsage??null,sessionUsage:t.sessionUsage??e.sessionUsage??null,compaction:t.compaction??e.compaction??null,approvals:t.approvals||[],agents:t.agents||[],currentActivity:t.streaming?t.currentActivity||e.currentActivity||null:t.currentActivity?.type===`agent`?t.currentActivity:null,lifecycle:t.lifecycle??e.lifecycle??null,sessionTreeRevision:Number(t.sessionTreeRevision??e.sessionTreeRevision??0),activityFeed:t.streaming?t.activityFeed||e.activityFeed||[]:(t.activityFeed||[]).filter(e=>e.type===`agent`),thinkingText:t.streaming?t.thinkingText??e.thinkingText??``:``,...t.streaming?{}:{hadQueuedInput:!1}}}function Po({sessionStates:e,sessionStatesRef:t,localStreamSessionsRef:n,streamGenerationRef:r,updateSessionState:i,updateSessions:a}){let o=(0,Z.useRef)(new Set),s=(0,Z.useRef)({timer:null,activeSessions:new Set}),c=(0,Z.useCallback)(async(e,{force:s=!1}={})=>{if(!e||!s&&n.current.has(e)||o.current.has(e))return;o.current.add(e);let c=t.current[e]?.runtimeSelectionRevision||0;try{let o=await Y.getLiveSession(e);if(!s&&n.current.has(e))return;if(s&&n.current.has(e)){let t=r.current.get(e)||0;r.current.set(e,t+1),n.current.delete(e)}Wa(e,o),i(e,e=>No(e,o,void 0,c)),a(n=>n.map(n=>n.id===e?{...n,streaming:o.streaming,model:t.current[e]?.model||o.model||n.model,cwd:o.cwd||n.cwd,permissionMode:o.permissionMode||n.permissionMode,executionMode:o.executionMode||n.executionMode,runMode:o.runMode||n.runMode,goal:o.goal??n.goal??null,team:ko(o,n.team),plan:ye(o,n.plan??null)}:n))}catch(t){n.current.has(e)||i(e,{recovering:!1,loading:!1,error:K(t)})}finally{o.current.delete(e)}},[n,t,r,i,a]),l=(0,Z.useCallback)(async(e,{force:n=!1,limit:r=40}={})=>{if(!e)return;let o=t.current[e];if(o?.recovering){await c(e);return}if(!(!n&&(o?.loading||o?.streaming||o?.loaded&&(o.pageSize||0)>=r))){i(e,{loading:!0});try{let n=await Y.getMessages(e,{limit:r});i(e,e=>e.streaming?{...e,loaded:!0,loading:!1,pageSize:Math.max(e.pageSize||0,r)}:{...e,...jo(e,n),model:e.model||n.model||void 0,contextUsage:n.contextUsage??e.contextUsage??null,sessionUsage:n.sessionUsage??e.sessionUsage??null,loaded:!0,loading:!1,pageSize:Math.max(e.pageSize||0,r),error:``,olderError:``});let o=t.current[e]?.model||(typeof n.model==`string`?n.model:``);o&&a(t=>t.map(t=>t.id===e&&t.model!==o?{...t,model:o}:t))}catch(t){i(e,{loading:!1,error:K(t)})}}},[t,c,i,a]),u=(0,Z.useCallback)(async e=>{let n=t.current[e];if(!e||!n?.hasOlder||!n.olderCursor||n.loadingOlder)return!1;i(e,{loadingOlder:!0,olderError:``});try{let t=await Y.getMessages(e,{limit:40,before:n.olderCursor});return i(e,e=>{let n=new Set(e.messages.map(e=>e.id)),r=[...t.messages.filter(e=>!n.has(e.id)),...e.messages],i=Math.max(0,r.length-200);return{...e,messages:i?r.slice(i):r,messageStart:t.pageInfo.start+i,hasOlder:t.pageInfo.hasMore,olderCursor:t.pageInfo.nextCursor,loadingOlder:!1,olderError:``}}),t.messages.length>0}catch(t){return i(e,{loadingOlder:!1,olderError:K(t)}),!1}},[t,i]),d=(0,Z.useCallback)(()=>{s.current.timer&&window.clearInterval(s.current.timer),s.current.timer=null,s.current.activeSessions.clear()},[]),f=(0,Z.useCallback)(()=>{s.current.timer||!s.current.activeSessions.size||(s.current.timer=window.setInterval(()=>{if(typeof document<`u`&&document.hidden)return;let e=Array.from(s.current.activeSessions).map(async e=>{let r=t.current[e];if(!Oo(r,{localStreamOwned:n.current.has(e)})){s.current.activeSessions.delete(e);return}await c(e)});Promise.allSettled(e).then(()=>{s.current.activeSessions.size||d()})},2e3))},[n,t,d,c]);return(0,Z.useEffect)(()=>{let t=new Set(Object.keys(e));for(let e of s.current.activeSessions)t.has(e)||s.current.activeSessions.delete(e);for(let[t,r]of Object.entries(e))Oo(r,{localStreamOwned:n.current.has(t)})?s.current.activeSessions.add(t):s.current.activeSessions.delete(t);s.current.activeSessions.size?f():d()},[f,n,e,d]),(0,Z.useEffect)(()=>d,[d]),{syncLiveSession:c,loadSessionMessages:l,loadOlderMessages:u,liveSyncInFlightRef:o}}function Fo(e,t){let n=null,r=!1,i=typeof document<`u`,a=()=>!i||document.visibilityState===`visible`,o=()=>{r&&=(document.removeEventListener(`visibilitychange`,c),!1)},s=()=>{n=setTimeout(()=>{n=null,e()},t)},c=()=>{!a()||n!=null||(o(),s())},l=()=>{!i||r||(document.addEventListener(`visibilitychange`,c),r=!0)};return{schedule(){n!=null||r||(a()?s():l())},flushNow(){n!=null&&(clearTimeout(n),n=null),o(),e()},cancel(){n!=null&&clearTimeout(n),n=null,o()},get active(){return n!=null||r}}}function Io(e,{intervalMs:t=48}={}){let n=null,r=null,i=Fo(()=>{if(n==null)return;let t=n,i=r;n=null,r=null,e(t,i)},t);return{push(e,t=new Date().toISOString()){n=e,r=t,i.schedule()},flush(){i.flushNow()},cancel(){i.cancel(),n=null,r=null}}}function Lo(e,{intervalMs:t=80}={}){let n=new Map,r=null,i=Fo(()=>{if(!n.size)return;let t=n,i=r;n=new Map,r=null,e(t,i)},t);return{push(e,t,a=new Date().toISOString()){e&&(n.set(e,{...n.get(e)||{},...t}),r=a,i.schedule())},flush(){i.flushNow()},cancel(){i.cancel(),n=new Map,r=null}}}function Ro(e){return e>=55296&&e<=56319}function zo(e,t){let n=Math.min(e.length,t.length),r=0;for(;r<n&&e.charCodeAt(r)===t.charCodeAt(r);)r+=1;return r>0&&Ro(e.charCodeAt(r-1))?r-1:r}var Bo=50;function Vo(e,{minCharsPerSecond:t=36,maxCharsPerSecond:n=1200,catchUpRemaining:r=160,requestFrame:i,cancelFrame:a,isCurrent:o=()=>!0,now:s=()=>typeof performance<`u`&&performance.now?performance.now():Date.now()}={}){let c=!i&&typeof globalThis.requestAnimationFrame==`function`&&typeof globalThis.cancelAnimationFrame==`function`,l=i||(c?globalThis.requestAnimationFrame.bind(globalThis):e=>setTimeout(()=>e(s()),Math.ceil(Bo))),u=a||(c?globalThis.cancelAnimationFrame.bind(globalThis):clearTimeout),d=typeof document<`u`?document:null,f=()=>!d||d.visibilityState===`visible`,p=``,m=``,h=null,g=null,_=0,v=null,y=0,b=!1,x=new Set,S=e=>{let t=[...x];x.clear();for(let n of t)n(e)},C=()=>{m.length,e(m,h)},w=()=>{b=!0,g!=null&&u(g),d?.removeEventListener(`visibilitychange`,O),g=null,y=0,S(!1)},T=()=>{if(!b){if(!o()){w();return}g!=null&&u(g),g=null,y=0,m=p,v=s(),C(),m===p&&S(!0)}},E=e=>{if(g=null,b)return;if(!o()){w();return}if(!f()){x.size&&T();return}if(p===m){S(!0);return}let i=e-_;if(i+.001<Bo||v!=null&&e-v+.001<Bo){g=l(E);return}_=e;let a=m;p.startsWith(m)||(m=p.slice(0,zo(m,p)),y=0);let s=p.length-m.length;if(s>=480)m=p,y=0;else{let e=Math.max(0,Math.min(n,t+s*(s>=r?10:4))),a=y+e*Math.min(.08,Math.max(0,i/1e3)),o=Math.floor(a+1e-9);y=Math.max(0,a-o);let c=m.length;for(let e=0;e<o&&c<p.length;e+=1){let e=p.codePointAt(c)??0;if(Ro(e)&&c+1===p.length&&!x.size)break;c+=e>65535?2:1}m=p.slice(0,c)}m!==a&&(v=e,C()),m===p&&S(!0);let c=!x.size&&m.length+1===p.length&&Ro(p.charCodeAt(m.length));!b&&g==null&&m!==p&&!c&&f()?g=l(E):g??(y=0)},D=()=>{b||g!=null||!f()||p===m||(_=s(),g=l(E))},O=()=>{f()?D():x.size?T():(g!=null&&u(g),g=null,y=0)};return d?.addEventListener(`visibilitychange`,O),{setTarget(e,t=new Date().toISOString()){b||(p=String(e||``),h=t,D())},drain(){return b||!o()?(w(),Promise.resolve(!1)):m===p?Promise.resolve(!0):new Promise(e=>{x.add(e),f()?D():T()})},flush:T,cancel:w,getShown:()=>m,getTarget:()=>p}}var Ho=new Set(`contacts.search,camera.capture,location.current,device.info,device.capabilities,device.battery,device.storage,device.memory,device.network,device.display,device.locale,device.status,device.clipboard.get,device.clipboard.set,device.vibrate,device.flashlight,device.notify,photos.list,photos.create_album,photos.add_to_album,photos.delete,apps.open_url,apps.open_map,apps.open_system_settings,apps.open_dialer,apps.compose_sms,apps.open_app,apps.share_text`.split(`,`)),Uo=new Map,Wo=[];function Go(e,t){let n=window.__TAURI__?.core?.invoke??window.__TAURI_INTERNALS__?.invoke;return n?n(e,t):Promise.reject(Error(`native bridge unavailable`))}async function Ko(e,t){let n=String(t.id||``),r=String(t.operation||``);if(!n||!Ho.has(r))return;let i=Date.parse(String(t.expiresAt||``));if(Number.isFinite(i)&&i<=Date.now()){await Y.resolveMobileOperation(e,n,{ok:!1,error:`移动设备操作请求已过期。`});return}try{let i=await Go(`mobile_execute_device_operation`,{request:{id:n,operation:r,parameters:t.parameters&&typeof t.parameters==`object`?t.parameters:void 0}});await Y.resolveMobileOperation(e,n,{ok:!0,result:i})}catch(t){await Y.resolveMobileOperation(e,n,{ok:!1,error:t instanceof Error?t.message:String(t)})}finally{Wo.push(n),Wo.length>128&&Wo.splice(0,Wo.length-128)}}function qo(e){let t=String(e.id||``);!t||Wo.includes(t)||(Wo.push(t),Wo.length>128&&Wo.splice(0,Wo.length-128))}function Jo(e,t){let n=String(t.id||``);if(!n||Wo.includes(n)||Uo.has(n))return;let r=Ko(e,t).catch(()=>{}).finally(()=>Uo.delete(n));Uo.set(n,r)}function Yo(e){let t=String(e.path||``).trim().replaceAll(`\\`,`/`).toLowerCase();return t?`path:${t}`:`id:${e.id}`}function Xo(e,t){return Object.hasOwn(e,`team`)?e.team??null:t??null}function Zo(e,{agentId:t,responseText:n,data:r,finishedAt:i,error:a,preserveDisplayedText:o}){let s=!!a,c=r.lifecycle||e.lifecycle||{},l=Te(e,r);return{...l,streaming:!1,runFinishedAt:i,lastActivityAt:i,...s?{}:{runNotice:``},currentActivity:r.currentActivity?.type===`agent`?r.currentActivity:null,lifecycle:{...c,phase:s?`failed`:`completed`,event:s?`runtime_error`:`runtime_done`,updatedAt:i},sessionTreeRevision:Number(r.sessionTreeRevision??e.sessionTreeRevision??0),activityFeed:(r.activityFeed||[]).filter(e=>e.type===`agent`),goal:s?e.goal:r.goal??e.goal??null,plan:s?e.plan:ye(r,e.plan),team:Xo(r,e.team),agents:r.agents||e.agents||[],contextUsage:r.contextUsage??e.contextUsage??null,sessionUsage:r.sessionUsage??e.sessionUsage??null,compaction:r.compaction??e.compaction??null,approvals:s?[]:r.approvals||[],tools:Ie(r.tools||e.tools,{finishedAt:i,...a?{error:a}:{}}),messages:l.messages.map(e=>e.id===t?{...e,text:o?e.text:typeof r.text==`string`?r.text:n||e.text,streaming:o?e.text!==n:!1,...s?{}:r.turnBoundaryEntryId?{turnBoundaryEntryId:String(r.turnBoundaryEntryId)}:{},...s?{}:r.assets?.length?{attachments:r.assets}:{}}:e)}}function Qo({sessionId:e,agentId:t,sessionStatesRef:n,updateSessionState:r,updateSessions:i,typewriter:a,thinkingScheduler:o,toolScheduler:s,t:c}){let l={responseText:``,responseRenderingStreaming:!0,thinkingText:``,thinkingPrefix:``,queuedDuringRun:!1},u=t=>{i(n=>n.map(n=>n.id===e?t(n):n))},d=(r,i)=>{let a=n.current[e]?.messages??[],o=a.findIndex(e=>e.id===t),s=a.slice(0,Math.max(0,o)).filter(e=>e.role===`user`).at(-1)?.text;Ua({sessionId:e,messageId:t,prompt:s,text:l.responseText,runId:l.runId,startedAt:l.startedAt,status:r,error:i})};return{dispatch:(i,f)=>{let p=new Date().toISOString();if(i===`run`)l.runId=typeof f.runId==`string`?f.runId:void 0,d(`started`);else if(i===`resync_required`)d(`recovering`);else if(i===`meta`)l.startedAt=typeof f.startedAt==`string`?f.startedAt:void 0,d(`started`),r(e,e=>({...Te(e,f),model:f.model||e.model,thinkingLevel:f.thinkingLevel||e.thinkingLevel,cwd:f.cwd,permissionMode:f.permissionMode,executionMode:f.executionMode,runMode:f.runMode||e.runMode,goal:f.goal??null,plan:ye(f,e.plan),team:Xo(f,e.team),agents:f.agents||e.agents||[],currentActivity:f.currentActivity||e.currentActivity||null,activityFeed:f.activityFeed||e.activityFeed||[],lifecycle:f.lifecycle??e.lifecycle??null,sessionTreeRevision:Number(f.sessionTreeRevision??e.sessionTreeRevision??0),thinkingText:f.thinkingText??e.thinkingText??``,contextUsage:f.contextUsage??e.contextUsage??null,sessionUsage:f.sessionUsage??e.sessionUsage??null,runStartedAt:f.startedAt||e.runStartedAt,lastActivityAt:f.lastActivityAt||p})),(f.model||f.thinkingLevel||f.cwd||f.permissionMode||f.executionMode||f.goal!==void 0||f.team!==void 0||Se(f)!==void 0)&&u(e=>({...e,model:f.model||e.model,thinkingLevel:f.thinkingLevel||e.thinkingLevel,cwd:f.cwd||e.cwd,permissionMode:f.permissionMode||e.permissionMode,executionMode:f.executionMode||e.executionMode,runMode:f.runMode||e.runMode,goal:f.goal??e.goal??null,team:Xo(f,e.team),plan:ye(f,e.plan??null)}));else if(i===`queue_update`)f.queuedInputs?.length&&(l.queuedDuringRun=!0),r(e,e=>Te(e,{...f,queuedInputs:f.queuedInputs||[]}));else if(i===`agent_update`)r(e,e=>{let t=f.currentActivity||(f.agent?{type:`agent`,agent:f.agent,updatedAt:f.agent.lastActivityAt||p}:null);return{...e,team:Xo(f,e.team),agents:f.agents||[],currentActivity:e.currentActivity?.type===`tool`?e.currentActivity:t||e.currentActivity,activityFeed:t?Oe(e.activityFeed,t):e.activityFeed,lastActivityAt:f.agent?.lastActivityAt||p}}),Object.hasOwn(f,`team`)&&u(e=>({...e,team:Xo(f,e.team)}));else if(i===`agent_lifecycle`)r(e,e=>{let t=f.lifecycle||e.lifecycle,n=t?.event===`auto_retry_end`,r=t?.event===`turn_start`&&(e.lifecycle?.phase===`retrying`||e.currentActivity?.type===`retry`);return{...e,lifecycle:t,currentActivity:f.currentActivity||e.currentActivity,lastActivityAt:t?.updatedAt||p,runNotice:n&&t?.retry?.success?``:n&&t?.retry?.message?t.retry.message:r?``:e.runNotice}});else if(i===`session_tree_changed`)r(e,{sessionTreeRevision:Number(f.revision||0),lastActivityAt:p});else if(i===`thinking_level_changed`)r(e,{thinkingLevel:f.level,lastActivityAt:p}),u(e=>({...e,thinkingLevel:f.level}));else if(i===`context_usage`)r(e,{contextUsage:f});else if(i===`session_usage`)r(e,{sessionUsage:f});else if(i===`compaction_start`)s.flush(),r(e,e=>{let t={type:`compaction`,compaction:f,updatedAt:f.startedAt||p};return{...e,compaction:f,currentActivity:t,activityFeed:Oe(e.activityFeed,t),lastActivityAt:f.startedAt||p}});else if(i===`compaction_end`)r(e,e=>{let t={type:`model`,stage:`processing_result`,updatedAt:f.finishedAt||p};return{...e,compaction:f,currentActivity:t,activityFeed:Oe(e.activityFeed,t),lastActivityAt:f.finishedAt||p}});else if(i===`text_patch`)l.responseRenderingStreaming=!0,l.responseText=yt(l.responseText,f),d(`streaming`),a.setTarget(l.responseText,p);else if(i===`text_delta`)l.responseText.length,l.responseRenderingStreaming=!0,l.responseText+=f.delta||``,d(`streaming`),a.setTarget(l.responseText,p);else if(i===`text_end`)l.responseText.length,typeof f.text==`string`&&(l.responseText=f.text),l.responseRenderingStreaming=!1,d(`streaming`),a.setTarget(l.responseText,f.updatedAt||p),r(e,e=>({...e,messages:e.messages.map(e=>e.id===t?{...e,streaming:e.text!==l.responseText}:e)}));else if(i===`thinking_reset`)l.thinkingText=``,l.thinkingPrefix=String(f.thinkingText||``).slice(-6e3),o.cancel(),r(e,{thinkingText:l.thinkingPrefix,currentActivity:{type:`model`,stage:`thinking`,updatedAt:f.updatedAt||p},lastActivityAt:f.updatedAt||p});else if(i===`thinking_patch`){l.thinkingText=yt(l.thinkingText,f).slice(-6e3);let e=[l.thinkingPrefix,l.thinkingText].filter(Boolean).join(`
|
|
553
|
+
|
|
554
|
+
`);o.push(e.slice(-6e3),p)}else if(i===`tool_start`)o.flush(),s.flush(),r(e,e=>{let t={type:`tool`,id:f.id,name:f.name,args:f.args,status:`running`,startedAt:f.startedAt||p,updatedAt:p,...f.output===void 0?{}:{output:f.output}};return{...e,lastActivityAt:p,runNotice:``,tools:Oe(e.tools,t),currentActivity:t,activityFeed:Oe(e.activityFeed,t)}});else if(i===`tool_update`)s.push(f.id,{message:f.message||``,updatedAt:f.updatedAt||p,...f.output===void 0?{}:{output:f.output},...f.agent?{agent:f.agent}:{},...f.previewImage?{previewImage:f.previewImage}:{},...f.target?{target:f.target}:{}},f.updatedAt||p);else if(i===`tool_end`)s.flush(),r(e,e=>{let t=e.tools.find(e=>e.id===f.id),n=f.finishedAt||p,r=String(t?.name||``),i=(Be(r)||[`spawn_agent`,`list_agents`,`send_message`,`followup_task`,`wait_agent`,`interrupt_agent`].includes(r))&&[`plan`,`agent`].includes(e.currentActivity?.type),a={...t||{},type:`tool`,status:f.error?`error`:`done`,message:f.message||t?.message||``,updatedAt:n,finishedAt:n,...f.output===void 0?{}:{output:f.output},...f.previewImage?{previewImage:f.previewImage}:{},...f.target?{target:f.target}:{}},o=f.agent?{type:`agent`,agent:f.agent,updatedAt:f.agent.lastActivityAt||n}:null,s=e.activityFeed||[];return(f.error||!i&&!o)&&(s=Oe(s,a)),o&&(s=Oe(s,o)),{...e,lastActivityAt:n,tools:e.tools.map(e=>e.id===f.id?{...e,status:f.error?`error`:`done`,message:f.message||``,updatedAt:n,finishedAt:n,...f.output===void 0?{}:{output:f.output},...f.previewImage?{previewImage:f.previewImage}:{},...f.target?{target:f.target}:{}}:e),currentActivity:f.error?a:o||(i?e.currentActivity:a),activityFeed:s}});else if(i===`mobile_operation_request`)Jo(e,f);else if(i===`mobile_operation_cancel`)qo(f);else if(i===`permission_request`)s.flush(),r(e,e=>({...e,lastActivityAt:p,approvals:[...(e.approvals||[]).filter(e=>e.id!==f.id),f]}));else if(i===`permission_resolved`)r(e,e=>({...e,lastActivityAt:p,approvals:(e.approvals||[]).filter(e=>e.id!==f.id)}));else if(i===`generated_asset`)r(e,e=>({...e,lastActivityAt:p,messages:e.messages.map(e=>e.id===t?{...e,attachments:[...(e.attachments||[]).filter(e=>Yo(e)!==Yo(f)),f]}:e)}));else if(i===`goal_update`)r(e,e=>({...e,goal:f.goal??null,team:Xo(f,e.team)})),u(e=>({...e,goal:f.goal??null,team:Xo(f,e.team)}));else if(_e(i))s.flush(),r(e,e=>{let t=ye(f,e.plan),n=f.currentActivity||{type:`plan`,plan:t,changes:De(e.plan,t),updatedAt:t?.updatedAt||p};return{...e,lastActivityAt:p,plan:t,currentActivity:n,activityFeed:Oe(e.activityFeed,n)}}),u(e=>({...e,plan:ye(f,e.plan??null)}));else if(i===`session_title`)u(e=>({...e,name:f.name}));else if(i===`retry`){let t=c(`chat:requestNotice.retryingAttempt`,{attempt:f.attempt,maxAttempts:f.maxAttempts});r(e,e=>{let n={type:`retry`,message:f.message,summary:t,updatedAt:p};return{...e,runNotice:t,currentActivity:n,activityFeed:Oe(e.activityFeed,n),lastActivityAt:p}})}else if(i===`done`||i===`error`){l.queuedDuringRun||=!!(n.current[e]?.hadQueuedInput||n.current[e]?.queuedInputs?.length);let c=f.finishedAt||p;if(typeof f.text==`string`&&(l.responseText=f.text),l.responseRenderingStreaming=!1,l.terminal=!0,d(i===`done`?`completed`:`failed`,i===`error`?f.message||`Speech response failed.`:void 0),a.setTarget(l.responseText,c),i===`error`&&a.flush(),o.flush(),s.cancel(),r(e,e=>Zo(e,{agentId:t,responseText:l.responseText,data:f,finishedAt:c,preserveDisplayedText:i===`done`,...i===`error`?{error:f.message}:{}})),i===`done`)return u(e=>({...e,streaming:!1,goal:f.goal??e.goal??null,team:Xo(f,e.team),plan:ye(f,e.plan??null)})),!1;throw Error(f.message)}},state:l}}var $o=`pisper:usage-updated`;function es({browserNotify:e,notify:t,defaultModel:n,localStreamSessionsRef:r,streamGenerationRef:i,sessionStatesRef:a,setActiveId:o,setGlobalError:s,updateSessionState:l,updateSessions:u,createSession:d,loadSessionMessages:f,refreshSessions:p,syncLiveSession:m}){let{t:h}=c(),g=(0,Z.useRef)(new Map),_=(0,Z.useRef)(new Set),v=(0,Z.useRef)(new Map),y=(0,Z.useCallback)(async(t,c,_=[],v=!1,y=!1,b=null,x=null,S={})=>{let C=S.retryFromIndex,w=C==null?t.trim()||(_.length?h(`chat:chatPage.pleaseAnalyzeTheseAttachments`):``)||(x?x.resourceName:``):t;if(!w&&!x)return;let T=c;if(T||=await d(),!T||a.current[T]?.streaming)return;let E=a.current[T];if(E?.pendingRuntimeSelection||E?.switchingModel||E?.switchingThinking)return;let D=(i.current.get(T)||0)+1;i.current.set(T,D);let O=!1,k=()=>!O&&i.current.get(T)===D,A=()=>{},j=new Promise(e=>{A=e});g.current.set(T,{promise:j,resolve:A}),S.activate!==!1&&(o(T),s(``));let M={id:`user-${Date.now()}`,role:`user`,text:w,invocation:x,attachments:_.map(({id:e,kind:t,name:n,mimeType:r,size:i,data:a})=>({id:e,kind:t,name:n,mimeType:r,size:i,data:t===`image`?a:void 0}))},N=`agent-${Date.now()}`,P=new Date().toISOString(),F={responseText:``,responseRenderingStreaming:!0,thinkingText:``,thinkingPrefix:``,queuedDuringRun:!1},I=Io((e,t)=>{k()&&l(T,n=>k()?{...n,thinkingText:e,lastActivityAt:t||n.lastActivityAt,currentActivity:{type:`model`,stage:`thinking`,updatedAt:t||n.lastActivityAt}}:n)},{intervalMs:80}),L=Vo((e,t)=>{k()&&l(T,n=>{if(!k())return n;let r=n.messages.map(t=>t.id===N?{...t,text:e,streaming:F.responseRenderingStreaming||e!==F.responseText}:t);if(F.terminal||!F.responseRenderingStreaming||n.currentActivity&&n.currentActivity.type!==`model`)return{...n,messages:r};let i={type:`model`,stage:`responding`,updatedAt:t||n.lastActivityAt};return{...n,lastActivityAt:t||n.lastActivityAt,runNotice:``,currentActivity:i,activityFeed:Oe(n.activityFeed,i),messages:r}})},{isCurrent:k}),R=Lo((e,t)=>{k()&&l(T,n=>{if(!k())return n;let r=n.activityFeed||[];for(let[n,i]of e){let e=r.find(e=>e.type===`tool`&&e.id===n);e&&(r=Oe(r,{...e,...i,updatedAt:t||e.updatedAt}))}let i=n.currentActivity?.type===`tool`&&e.has(n.currentActivity.id)?{...n.currentActivity,...e.get(n.currentActivity.id),updatedAt:t||n.currentActivity.updatedAt}:n.currentActivity;return{...n,lastActivityAt:t||n.lastActivityAt,tools:n.tools.map(t=>{let n=e.get(String(t.id||``));return n?{...t,...n}:t}),currentActivity:i,activityFeed:r}})}),z=Qo({sessionId:T,agentId:N,sessionStatesRef:a,updateSessionState:l,updateSessions:u,typewriter:L,thinkingScheduler:I,toolScheduler:R,t:h}),B=(e,t)=>k()?e===`resync_required`?(z.dispatch(e,t),O=!0,i.current.delete(T),r.current.delete(T),m(T),!1):z.dispatch(e,t):!1;F=z.state,l(T,e=>{let t=v||y||e.goal?.status===`active`;return{...e,messages:[...C==null?e.messages:e.messages.slice(0,C),M,{id:N,role:`agent`,text:``,streaming:!0}],tools:[],approvals:[],error:``,streaming:!0,loaded:!0,runStartedAt:P,lastActivityAt:P,runFinishedAt:null,runStopped:!1,runNotice:``,currentActivity:{type:`model`,stage:`thinking`,updatedAt:P},activityFeed:[],lifecycle:{phase:`starting`,event:`prompt_submitted`,turn:0,updatedAt:P},thinkingText:``,hadQueuedInput:!1,withdrawnInputIds:[],queuedInputRunId:N,compaction:null,plan:t?e.plan:null}}),!v&&!y&&u(e=>e.map(e=>e.id!==T||e.goal?.status===`active`?e:{...e,plan:null})),r.current.add(T);let ee=!1;try{if(C==null?await Y.openStream({sessionId:T,message:w,attachments:_,goalMode:v,teamMode:y,goalTokenBudget:b,invocation:x},B):await Y.retryLastTurn(T,B),!k())return;F.responseRenderingStreaming=!1,F.terminal=!0,L.setTarget(F.responseText),I.flush(),R.flush();let t=new Date().toISOString();if(a.current[T]?.streaming&&l(T,e=>{let n=e.runFinishedAt||t;return{...e,streaming:!1,runFinishedAt:n,lastActivityAt:n,runNotice:``,currentActivity:null,activityFeed:[],approvals:[],tools:Ie(e.tools,{finishedAt:n}),messages:e.messages.map(e=>e.id===N?{...e,streaming:e.text!==F.responseText}:e)}}),!await L.drain()||!k()||(l(T,e=>({...e,messages:e.messages.map(e=>e.id===N?{...e,text:F.responseText,streaming:!1}:e)})),!k()))return;(v||y||F.queuedDuringRun||a.current[T]?.hadQueuedInput||a.current[T]?.goal||a.current[T]?.queuedInputs?.length)&&l(T,{queuedInputs:[],hadQueuedInput:!1});let r;try{r=(await p()).find(e=>e.id===T)}catch{m(T)}if(!k())return;S.activate!==!1&&e?.(`chat.completed`,{chat:{title:r?.name||h(`chat:chatPage.appChat`,{app:`Pisper`}),summary:F.responseText.trim().slice(0,260)||h(`chat:chatPage.theAgentHasFinishedResponding`),model:a.current[T]?.model||n}})}catch(e){if(!k())return;if((F.runId||F.startedAt)&&!F.terminal){z.dispatch(`resync_required`,{}),O=!0,i.current.delete(T),r.current.delete(T),m(T);return}ee=!0,L.cancel(),I.flush(),R.cancel();let t=new Date().toISOString(),n=K(e);if(l(T,e=>({...e,streaming:!1,error:n,runFinishedAt:t,lastActivityAt:t,runNotice:``,currentActivity:null,activityFeed:[],approvals:[],tools:Ie(e.tools,{finishedAt:t,error:n}),messages:e.messages.map(e=>e.id===N?{...e,streaming:!1,error:n,text:e.text||F.responseText}:e)})),F.queuedDuringRun||a.current[T]?.hadQueuedInput||a.current[T]?.queuedInputs?.length){try{await f(T,{force:!0})}catch{}l(T,{queuedInputs:[],hadQueuedInput:!1})}u(e=>e.map(e=>e.id===T?{...e,streaming:!1}:e))}finally{let e=k();O=!0,e&&(r.current.delete(T),i.current.delete(T),l(T,{streaming:!1,hadQueuedInput:!1}),g.current.get(T)?.promise===j&&g.current.delete(T)),L.cancel(),I.cancel(),R.cancel(),A(),window.dispatchEvent(new Event($o)),ee&&e&&m(T)}},[e,d,n,f,r,p,i,a,o,s,m,h,l,u]),b=(0,Z.useCallback)(async(e,n,r=[],i=`steer`)=>{let o=String(e||``).trim()||(r.length?h(`chat:chatPage.pleaseAnalyzeTheseAttachments`):``);if(!n||!o)return!1;let s=a.current[n]?.queuedInputRunId;try{let e=await Y.queueInput(n,o,r,i),t=new Date().toISOString(),a={id:`interactive-user-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,role:`user`,text:o,queuedAt:t,queuedInputId:e.inputId||void 0,streamingBehavior:e.behavior||i,attachments:r.map(({id:e,kind:t,name:n,mimeType:r,size:i,data:a})=>({id:e,kind:t,name:n,mimeType:r,size:i,data:t===`image`?a:void 0}))};return l(n,n=>{let r=Te(n,e),i=!r.withdrawnInputIds?.includes(e.inputId)&&n.queuedInputRunId===s;return{...r,messages:i?ze(r.messages,a):r.messages,hadQueuedInput:!0,lastActivityAt:t}}),!0}catch(e){if(Ee(e)){let e=g.current.get(n);return e?await e.promise:await m(n),l(n,{streaming:!1,recovering:!1,queuedInputs:[],hadQueuedInput:!1}),await f(n,{force:!0}),y(o,n,r),!0}return t(K(e),`error`),!1}},[f,t,y,a,m,h,l]),x=(0,Z.useCallback)(e=>{if(!e)return Promise.resolve();let n=a.current[e],r=v.current.get(e);if(r?.matchesRun(n))return r.promise;let i=n?.runStartedAt,o=n?.queuedInputRunId,s=!!n?.runStopped,c=e=>!!(e&&(o?e.queuedInputRunId===o:!e.queuedInputRunId&&e.runStartedAt===i));l(e,{runStopped:!0});let d=(async()=>{let n;try{n=await Y.abort(e)}catch(t){let n=a.current[e];throw c(n)&&n?.runStopped&&l(e,{runStopped:s}),t}if(!c(a.current[e])||(await m(e,{force:!0}),!c(a.current[e])))return;let r=new Date().toISOString();l(e,e=>({...e,streaming:!1,queuedInputs:[],hadQueuedInput:!1,goal:n.goal??null,team:Object.hasOwn(n,`team`)?n.team??null:e.team,compaction:e.compaction?.active?{...e.compaction,active:!1,status:`aborted`,aborted:!0,finishedAt:r}:e.compaction,runFinishedAt:r,lastActivityAt:r,runStopped:!0,runNotice:``,approvals:[],tools:Ie(e.tools,{finishedAt:r,error:h(`chat:chatPage.stopped`)}),messages:e.messages.map(e=>e.streaming?{...e,streaming:!1}:e)})),u(t=>t.map(t=>t.id===e?{...t,streaming:!1,goal:n.goal??t.goal??null,team:Object.hasOwn(n,`team`)?n.team??null:t.team}:t)),t(h(`chat:chatPage.currentRunStopped`),`info`)})().finally(()=>{v.current.get(e)?.promise===d&&v.current.delete(e)});return v.current.set(e,{matchesRun:c,promise:d}),d},[t,a,m,h,l,u]),S=(0,Z.useCallback)(async(e,n)=>{let r=`${e}/${n}`;if(!e||!n||_.current.has(r))return null;_.current.add(r),l(e,e=>({...e,withdrawingInputIds:[...e.withdrawingInputIds||[],n]}));try{let r=await Y.withdrawQueuedInput(e,n);return l(e,e=>Te(e,{...r,removedInputId:r.removed?n:void 0})),r.removed?r.withdrawnInput||null:(t(h(`chat:focusSession.queuedInputAlreadyConsumed`),`info`),null)}catch(e){return t(K(e),`error`),null}finally{_.current.delete(r),l(e,e=>({...e,withdrawingInputIds:(e.withdrawingInputIds||[]).filter(e=>e!==n)}))}},[t,h,l]);return{sendPrompt:y,retryLastTurn:(0,Z.useCallback)(async(e,t={})=>{let n=a.current[e];if(!n||n.streaming)return;let r=n.messages||[],i=-1;for(let e=r.length-1;e>=0;--e)if(r[e]?.role===`user`){i=e;break}if(i<0)return;let o=r[i];await y(o.text||``,e,o.attachments||[],!1,!1,null,null,{retryFromIndex:i,...t})},[y,a]),queuePrompt:b,withdrawQueuedInput:S,abort:x}}function ts(e,t){return new Promise(n=>{let r=()=>{clearTimeout(i),t.removeEventListener(`abort`,r),n()},i=setTimeout(r,e);t.addEventListener(`abort`,r,{once:!0}),t.aborted&&r()})}function ns({isStreaming:e,apply:t,intervalMs:n=750}){let r=new Map,i=new Map,a=new Set,o=e=>{let t=r.get(e);for(let n of a)n(e,t);a.size&&r.get(e)===t&&(t?.status===`success`||t?.status===`error`)&&r.delete(e)},s=e=>{i.get(e)?.controller.abort(),i.delete(e),r.delete(e),o(e)};return{select:(a,c)=>{if(r.get(a)?.status===`applying`)return!1;if(!c)return s(a),!0;if(r.set(a,{selection:c,status:`pending`}),o(a),i.has(a))return!0;let l=new AbortController,{signal:u}=l,d={controller:l,promise:Promise.resolve()};return i.set(a,d),d.promise=(async()=>{try{for(;!u.aborted;){let s=await e(a,u);if(u.aborted)return;if(s){await ts(n,u);continue}let c=r.get(a);if(!c)return;r.set(a,{...c,status:`applying`}),o(a);let l=await t(a,c.selection);u.aborted||(i.get(a)===d&&i.delete(a),r.set(a,{...c,status:`success`,result:l}),o(a));return}}catch(e){let t=r.get(a);!u.aborted&&t&&(i.get(a)===d&&i.delete(a),r.set(a,{...t,status:`error`,error:e}),o(a))}finally{i.get(a)===d&&i.delete(a)}})(),!0},subscribe(e){a.add(e);for(let[t,n]of r)e(t,n),r.get(t)===n&&(n.status===`success`||n.status===`error`)&&r.delete(t);return()=>{a.delete(e)}},async dispose(){let e=[...i.values()];a.clear();for(let e of i.keys())s(e);r.clear(),await Promise.all(e.map(e=>e.promise))}}}var rs=ns({isStreaming:async(e,t)=>{let n=await Y.getLiveSession(e,{signal:t});return!!(n.configurationBusy??n.streaming)},apply:(e,t)=>t.model?Y.updateModel(e,t.model.provider,t.model.modelId):Y.setThinkingLevel(e,t.thinkingLevel)});function is({notify:e,requestText:t,requestConfirm:n,availableModels:r,sessionStatesRef:i,updateSessionState:a,updateSessions:o,replaceSessionStates:s,setGlobalError:l,syncLiveSession:u}){let{t:d,language:f}=c(),[p,m]=(0,Z.useState)(null),h=(0,Z.useCallback)(e=>{a(e,e=>({...e,runtimeSelectionRevision:(e.runtimeSelectionRevision||0)+1}))},[a]),g=(0,Z.useCallback)((e,t)=>{o(n=>n.map(n=>n.id===e?t(n):n))},[o]),_=(0,Z.useCallback)(async t=>{if(t)try{let n=await Y.pauseGoal(t);a(t,{goal:n.goal||null}),g(t,e=>({...e,goal:n.goal||null})),e(d(`chat:chatPage.goalPaused`),`info`)}catch(e){a(t,{error:K(e)})}},[e,d,a,g]),v=(0,Z.useCallback)(async(t,n)=>{if(t)try{let r=await Y.setGoalBudget(t,n);a(t,{goal:r.goal||null}),g(t,e=>({...e,goal:r.goal||null})),e(d(`chat:chatPage.goalTokenBudgetUpdated`),`info`)}catch(e){a(t,{error:K(e)})}},[e,d,a,g]),y=(0,Z.useCallback)(async t=>{let n=i.current[t];if(!(!t||n?.streaming||n?.compaction?.active)){a(t,{compaction:{...n?.compaction||{},active:!0,status:`running`,reason:`manual`},error:``});try{let n=await Y.compactSession(t);a(t,{compaction:n.compaction||null,contextUsage:n.contextUsage||null}),e(d(`chat:chatPage.contextCompacted`))}catch(e){await u(t).catch(()=>{}),a(t,{error:K(e)})}}},[e,i,u,d,a]),b=(0,Z.useCallback)(async e=>{let t=await Y.updateCompactionPreference(e);s(Object.fromEntries(Object.entries(i.current).map(([e,n])=>{let r=Number(n.contextUsage?.contextWindow)||0;return r?[e,{...n,contextUsage:{...n.contextUsage,compactAtPercent:t.thresholdPercent,compactAtTokens:Math.floor(r*t.thresholdPercent/100)}}]:[e,n]})))},[s,i]),x=(0,Z.useCallback)((e,t={})=>{let n=String(t.model||``),r=String(i.current[e]?.model||``);if(n&&r&&n!==r)return;let o=Array.isArray(t.availableThinkingLevels)?t.availableThinkingLevels.map(e=>String(e)):Array.isArray(t.availableLevels)?t.availableLevels.map(e=>String(e)):[],s=String(t.thinkingLevel||``);a(e,{thinkingLevel:s||void 0,availableThinkingLevels:o,thinkingStatus:String(t.thinkingStatus||t.status||``),thinkingMessage:String(t.thinkingMessage||t.message||``),switchingThinking:!1}),s&&g(e,e=>({...e,thinkingLevel:s}))},[i,a,g]),S=(0,Z.useCallback)(async e=>{if(!e)return;let t=i.current[e]?.runtimeSelectionRevision,n=i.current[e];if(!(n?.switchingModel||n?.switchingThinking))try{let n=await Y.getThinkingLevel(e);if(i.current[e]?.runtimeSelectionRevision!==t)return;x(e,n)}catch{if(i.current[e]?.runtimeSelectionRevision!==t)return;a(e,{thinkingStatus:`error`,thinkingMessage:d(`chat:focusSession.thinkingLevelsLoadFailed`)})}},[x,i,d,a]),C=(0,Z.useCallback)(async(t,o)=>{let s=r.find(e=>e.key===o);if(!t||!s)return;let c=i.current[t];if(c?.switchingModel||c?.switchingThinking)return;if(c?.streaming||c?.pendingRuntimeSelection){rs.select(t,s.key===c.model?void 0:{model:s});return}h(t);let l=c?.model||``,u=!!c?.messages?.length&&!c?.compaction?.active;a(t,{switchingModel:!0,model:s.key,error:``}),g(t,e=>({...e,model:s.key}));try{let r=await Y.updateModel(t,s.provider,s.modelId);h(t),a(t,{model:r.model||s.key,contextUsage:r.contextUsage??null,switchingModel:!1}),g(t,e=>({...e,model:r.model||s.key})),x(t,r),e(d(`chat:chatPage.switchedToModel`,{model:s.label})),u&&await n({title:d(`chat:chatPage.compactAfterModelSwitch`),message:d(`chat:chatPage.compactAfterModelSwitchDescription`),confirmLabel:d(`chat:chatPage.compactNow`),tone:`primary`})&&await y(t)}catch(e){h(t),a(t,{switchingModel:!1,model:l||void 0,error:K(e)}),l&&g(t,e=>({...e,model:l}))}},[x,r,y,h,e,n,i,d,a,g]),w=(0,Z.useCallback)(async(t,n)=>{let r=String(n||``).trim();if(!t||!r)return;let o=i.current[t]||{};if(o.switchingModel||o.switchingThinking)return;if(o.streaming||o.pendingRuntimeSelection){if(o.pendingRuntimeSelection?.model)return;rs.select(t,r===o.thinkingLevel?void 0:{thinkingLevel:r});return}h(t);let s=String(o.thinkingLevel||``);a(t,{switchingThinking:!0,thinkingLevel:r,error:``}),g(t,e=>({...e,thinkingLevel:r}));try{let n=await Y.setThinkingLevel(t,r);h(t),x(t,n),e(d(`chat:chatPage.switchedToThinkingLevel`,{level:String(n.thinkingLevel||r)}))}catch(e){h(t),a(t,{switchingThinking:!1,thinkingLevel:s||void 0,error:K(e)}),s&&g(t,e=>({...e,thinkingLevel:s}))}},[x,h,e,i,d,a,g]);(0,Z.useEffect)(()=>rs.subscribe((t,n)=>{if(!n){a(t,{pendingRuntimeSelection:void 0});return}let{selection:r,status:i}=n;if(i===`pending`||i===`applying`){h(t),a(t,{pendingRuntimeSelection:{model:r.model?.key,thinkingLevel:r.thinkingLevel},switchingModel:i===`applying`&&!!r.model,switchingThinking:i===`applying`&&!!r.thinkingLevel,error:``});return}if(h(t),a(t,{pendingRuntimeSelection:void 0,switchingModel:!1,switchingThinking:!1,...n.error?{error:K(n.error)}:{}}),i===`error`)return;let o=n.result||{};if(r.model){let e=String(o.model||r.model.key);a(t,{model:e,contextUsage:o.contextUsage??null}),g(t,t=>({...t,model:e}))}x(t,o),e(r.model?d(`chat:chatPage.switchedToModel`,{model:r.model.label}):d(`chat:chatPage.switchedToThinkingLevel`,{level:String(o.thinkingLevel||r.thinkingLevel)}))}),[x,h,e,d,a,g]);let T=(0,Z.useCallback)(async(t,r)=>{if(!t)return!1;a(t,{switchingPermission:!0,error:``});try{if(r===`full-access`&&!await n({title:d(`chat:chatPage.enableFullAccess`),message:d(`chat:chatPage.fullAccessAllowsTheAgentToUseFilesAndNetworkServicesOutsideTheWorkspaceAndShellCommandsWillNoLon`),confirmLabel:d(`chat:chatPage.enableFullAccess`)}))return a(t,{switchingPermission:!1}),!1;let i=await Y.updateExecutionMode(t,r);return a(t,{executionMode:i.executionMode,permissionMode:i.permissionMode,switchingPermission:!1}),g(t,e=>({...e,executionMode:i.executionMode,permissionMode:i.permissionMode})),e(d(`chat:chatPage.executionModeChangedToMode`,{mode:i.executionMode===`approval-required`?d(`chat:chatPage.approvalRequired`):i.executionMode===`workspace-write`?d(`chat:focusSession.workspaceWrite`):d(`chat:chatPage.fullAccess`)})),!0}catch(e){return a(t,{switchingPermission:!1,error:K(e)}),!1}},[e,n,d,a,g]),E=(0,Z.useCallback)(async(e,t)=>{if(!e)return!1;try{let n=await Y.updateRunMode(e,t),r=String(n.runMode||t);return a(e,{runMode:r}),g(e,e=>({...e,runMode:r})),!0}catch(t){return a(e,{error:K(t)}),!1}},[a,g]),D=(0,Z.useCallback)(async(t,n,r)=>{a(t,{error:``});try{let e=await Y.resolveApproval(t,n,r);a(t,e=>({...e,approvals:(e.approvals||[]).filter(e=>e.id!==n)})),e.alreadyResolved&&u(t,{force:!0})}catch(n){if(await u(t,{force:!0}),n instanceof ht&&n.status===404){e(d(`chat:chatPage.approvalStatusUpdated`),`info`);return}throw a(t,{error:K(n)}),n}},[e,u,d,a]),O=(0,Z.useCallback)(async(t,n)=>{if(!(!t?.id||i.current[t.id]?.streaming)){a(t.id,{switchingCwd:!0,error:``});try{let r=await Y.updateCwd(t.id,n);a(t.id,{cwd:r.cwd,switchingCwd:!1}),g(t.id,e=>({...e,cwd:r.cwd})),m(null),e(d(`chat:chatPage.workingDirectoryChangedToWorkspace`,{workspace:Rt(r.cwd,f)}))}catch(e){throw a(t.id,{switchingCwd:!1,error:K(e)}),e}}},[f,e,i,d,a,g]);return{workspaceSession:p,setWorkspaceSession:m,switchSessionCwd:O,selectSessionWorkspace:(0,Z.useCallback)(async t=>{if(t?.id){if(i.current[t.id]?.streaming){e(d(`chat:chatPage.stopTheActiveRunBeforeChangingTheWorkspace`),`info`);return}if(!jn()){m(t);return}try{let e=await An(t.cwd);e&&await O(t,e)}catch(e){a(t.id,{switchingCwd:!1,error:K(e)})}}},[e,i,O,d,a]),renameSession:(0,Z.useCallback)(async n=>{if(!n?.id)return;if(i.current[n.id]?.streaming){e(d(`chat:chatPage.stopTheActiveRunBeforeRenamingTheChat`),`info`);return}let r=await t({title:d(`chat:chatPage.renameChat`),inputLabel:d(`chat:chatPage.chatTitle`),value:n.name,confirmLabel:d(`chat:chatPage.save`)});if(r!==null&&r!==n.name)try{let t=await Y.renameSession(n.id,r);g(n.id,e=>({...e,name:t.name})),un({id:n.id,name:t.name}),e(d(`chat:chatPage.chatTitleUpdated`))}catch(e){l(K(e))}},[e,t,i,l,d,g]),pauseGoal:_,setGoalBudget:v,compactSession:y,setCompactionThreshold:b,loadSessionThinkingLevel:S,switchSessionModel:C,switchSessionThinkingLevel:w,switchSessionExecutionMode:T,switchSessionRunMode:E,resolveToolApproval:D}}function as({sessionId:e,streaming:t,completed:n,runStartedAt:r,enabled:i,open:a,onReveal:o}){let s=(0,Z.useRef)(null),c=(0,Z.useRef)(o);(0,Z.useLayoutEffect)(()=>{c.current=o},[o]),(0,Z.useEffect)(()=>{let o=s.current,l={sessionId:e,streaming:t,completed:n,runStartedAt:r};if(s.current=l,!i||a||!Pn(o,l))return;let u=new AbortController,d=!0;return Y.getSessionFileChanges(e,{signal:u.signal}).then(({files:e})=>{d&&Nn(o,l,e)&&c.current()}).catch(()=>{}),()=>{d=!1,u.abort()}},[n,i,a,r,e,t])}function os(e,t){let n=getComputedStyle(e);return t*parseFloat(n.fontSize)}function ss(e,t){let n=getComputedStyle(e.ownerDocument.documentElement);return t*parseFloat(n.fontSize)}function cs(e){return e/100*window.innerHeight}function ls(e){return e/100*window.innerWidth}function us(e){switch(typeof e){case`number`:return[e,`px`];case`string`:{let t=parseFloat(e);return e.endsWith(`%`)?[t,`%`]:e.endsWith(`px`)?[t,`px`]:e.endsWith(`rem`)?[t,`rem`]:e.endsWith(`em`)?[t,`em`]:e.endsWith(`vh`)?[t,`vh`]:e.endsWith(`vw`)?[t,`vw`]:[t,`%`]}}}function ds({groupSize:e,panelElement:t,styleProp:n}){let r,[i,a]=us(n);switch(a){case`%`:r=i/100*e;break;case`px`:r=i;break;case`rem`:r=ss(t,i);break;case`em`:r=os(t,i);break;case`vh`:r=cs(i);break;case`vw`:r=ls(i)}return r}function fs(e){return parseFloat(e.toFixed(3))}function ps({group:e}){let{orientation:t,panels:n}=e;return n.reduce((e,n)=>(e+=t===`horizontal`?n.element.offsetWidth:n.element.offsetHeight,e),0)}function ms(e){let{panels:t}=e,n=ps({group:e});return n===0?t.map(e=>({groupResizeBehavior:e.panelConstraints.groupResizeBehavior,collapsedSize:0,collapsible:e.panelConstraints.collapsible===!0,defaultSize:void 0,disabled:e.panelConstraints.disabled,minSize:0,maxSize:100,panelId:e.id})):t.map(e=>{let{element:t,panelConstraints:r}=e,i=0;r.collapsedSize!==void 0&&(i=fs(ds({groupSize:n,panelElement:t,styleProp:r.collapsedSize})/n*100));let a;r.defaultSize!==void 0&&(a=fs(ds({groupSize:n,panelElement:t,styleProp:r.defaultSize})/n*100));let o=0;r.minSize!==void 0&&(o=fs(ds({groupSize:n,panelElement:t,styleProp:r.minSize})/n*100));let s=100;return r.maxSize!==void 0&&(s=fs(ds({groupSize:n,panelElement:t,styleProp:r.maxSize})/n*100)),{groupResizeBehavior:r.groupResizeBehavior,collapsedSize:i,collapsible:r.collapsible===!0,defaultSize:a,disabled:r.disabled,minSize:o,maxSize:s,panelId:e.id}})}function $(e,t=`Assertion error`){if(!e)throw Error(t)}function hs(e,t){return Array.from(t).sort(e===`horizontal`?gs:_s)}function gs(e,t){let n=e.element.offsetLeft-t.element.offsetLeft;return n===0?e.element.offsetWidth-t.element.offsetWidth:n}function _s(e,t){let n=e.element.offsetTop-t.element.offsetTop;return n===0?e.element.offsetHeight-t.element.offsetHeight:n}function vs(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.ELEMENT_NODE}function ys(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function bs({orientation:e,rects:t,targetRect:n}){let r={x:n.x+n.width/2,y:n.y+n.height/2},i,a=Number.MAX_VALUE;for(let n of t){let{x:t,y:o}=ys(r,n),s=e===`horizontal`?t:o;s<a&&(a=s,i=n)}return $(i,`No rect found`),i}var xs;function Ss(){return xs===void 0&&(xs=typeof matchMedia==`function`&&!!matchMedia(`(pointer:coarse)`).matches),xs}function Cs(e){let{element:t,orientation:n,panels:r,separators:i}=e,a=hs(n,Array.from(t.children).filter(vs).map(e=>({element:e}))).map(({element:e})=>e),o=[],s=!1,c=!1,l=-1,u=-1,d=0,f,p=[];{let e=-1;for(let t of a)t.hasAttribute(`data-panel`)&&(e++,t.hasAttribute(`data-disabled`)||(d++,l===-1&&(l=e),u=e))}if(d>1){let t=-1;for(let d of a)if(d.hasAttribute(`data-panel`)){t++;let i=r.find(e=>e.element===d);if(i){if(f){let r=f.element.getBoundingClientRect(),a=d.getBoundingClientRect(),m;if(c){let e=n===`horizontal`?new DOMRect(r.right,r.top,0,r.height):new DOMRect(r.left,r.bottom,r.width,0),t=n===`horizontal`?new DOMRect(a.left,a.top,0,a.height):new DOMRect(a.left,a.top,a.width,0);switch(p.length){case 0:m=[e,t];break;case 1:{let i=p[0];m=[i,bs({orientation:n,rects:[r,a],targetRect:i.element.getBoundingClientRect()})===r?t:e];break}default:m=p}}else m=p.length?p:[n===`horizontal`?new DOMRect(r.right,a.top,a.left-r.right,a.height):new DOMRect(a.left,r.bottom,a.width,a.top-r.bottom)];for(let n of m){let r=`width`in n?n:n.element.getBoundingClientRect(),a=Ss()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(r.width<a){let e=a-r.width;r=new DOMRect(r.x-e/2,r.y,r.width+e,r.height)}if(r.height<a){let e=a-r.height;r=new DOMRect(r.x,r.y-e/2,r.width,r.height+e)}!s&&!(t<=l||t>u)&&o.push({group:e,groupSize:ps({group:e}),panels:[f,i],separator:`width`in n?void 0:n,rect:r}),s=!1}}c=!1,f=i,p=[]}}else if(d.hasAttribute(`data-separator`)){d.ariaDisabled!==null&&(s=!0);let e=i.find(e=>e.element===d);e?p.push(e):(f=void 0,p=[])}else c=!0}return o}var ws=class{#e={};addListener(e,t){let n=this.#e[e];return n===void 0?this.#e[e]=[t]:n.includes(t)||n.push(t),()=>{this.removeListener(e,t)}}emit(e,t){let n=this.#e[e];if(n!==void 0){if(n.length===1)n[0].call(null,t);else{let e=!1,r=null,i=Array.from(n);for(let n=0;n<i.length;n++){let a=i[n];try{a.call(null,t)}catch(t){r===null&&(e=!0,r=t)}}if(e)throw r}}}removeAllListeners(){this.#e={}}removeListener(e,t){let n=this.#e[e];if(n!==void 0){let e=n.indexOf(t);e>=0&&n.splice(e,1)}}},Ts={cursorFlags:0,state:`inactive`},Es=new ws;function Ds(){return Ts}function Os(e){return Es.addListener(`change`,e)}function ks(e){let t=Ts,n={...Ts};n.cursorFlags=e,Ts=n,Es.emit(`change`,{prev:t,next:n})}function As(e){let t=Ts;Ts=e,Es.emit(`change`,{prev:t,next:e})}var js=e=>e,Ms=()=>{},Ns=1,Ps=2,Fs=4,Is=8,Ls=3,Rs=12,zs;function Bs(){return zs===void 0&&(zs=!1,typeof window<`u`&&(window.navigator.userAgent.includes(`Chrome`)||window.navigator.userAgent.includes(`Firefox`))&&(zs=!0)),zs}function Vs({cursorFlags:e,groups:t,state:n}){let r=0,i=0;switch(n){case`active`:case`hover`:t.forEach(e=>{if(!e.mutableState.disableCursor)switch(e.orientation){case`horizontal`:r++;break;case`vertical`:i++;break}})}if(r!==0||i!==0){if(n===`active`&&e&&Bs()){let t=(e&Ns)!==0,n=(e&Ps)!==0,r=(e&Fs)!==0,i=(e&Is)!==0;if(t)return r?`se-resize`:i?`ne-resize`:`e-resize`;if(n)return r?`sw-resize`:i?`nw-resize`:`w-resize`;if(r)return`s-resize`;if(i)return`n-resize`}return Bs()?r>0&&i>0?`move`:r>0?`ew-resize`:`ns-resize`:r>0&&i>0?`grab`:r>0?`col-resize`:`row-resize`}}var Hs=new WeakMap;function Us(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=Hs.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&(Object.isExtensible(e.adoptedStyleSheets)?e.adoptedStyleSheets.push(n):e.adoptedStyleSheets=[...e.adoptedStyleSheets,n]));let r=Ds();switch(r.state){case`active`:case`hover`:{let e=Vs({cursorFlags:r.cursorFlags,groups:r.hitRegions.map(e=>e.group),state:r.state}),i=`*, *:hover {cursor: ${e} !important; }`;if(t===i)return;t=i,e?n.cssRules.length===0?n.insertRule(i):n.replaceSync(i):n.cssRules.length===1&&n.deleteRule(0);break}case`inactive`:t=void 0,n.cssRules.length===1&&n.deleteRule(0)}Hs.set(e,{prevStyle:t,styleSheet:n})}var Ws=new Map,Gs=new ws;function Ks(e){Ws=new Map(Ws),Ws.delete(e)}function qs(e,t){for(let[t]of Ws)if(t.id===e)return t}function Js(e,t){for(let[t,n]of Ws)if(t.id===e)return n;if(t)throw Error(`Could not find data for Group with id ${e}`)}function Ys(){return Ws}function Xs(e,t){return Gs.addListener(`groupChange`,n=>{n.group.id===e&&t(n)})}function Zs(e,t,n){let r=Ws.get(e);Ws=new Map(Ws),Ws.set(e,t),Gs.emit(`groupChange`,{group:e,isUserInteraction:n?.isUserInteraction===!0,prev:r,next:t})}function Qs(e){let t=Ds(),n=!1;return t.state===`active`&&(As({cursorFlags:0,state:`inactive`}),t.hitRegions.length>0&&(Us(e),n=!0,t.hitRegions.forEach(e=>{let t=Js(e.group.id,!0);Zs(e.group,t,{isUserInteraction:!0})}))),n}function $s(e){e.defaultPrevented||Qs(e.currentTarget)}function ec(e,t,n){let r,i={x:1/0,y:1/0};for(let a of t){let t=ys(n,a.rect);switch(e){case`horizontal`:t.x<=i.x&&(r=a,i=t);break;case`vertical`:t.y<=i.y&&(r=a,i=t)}}return r?{distance:i,hitRegion:r}:void 0}function tc(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function nc(e,t){if(e===t)throw Error(`Cannot compare node with itself`);let n={a:cc(e),b:cc(t)},r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();$(r,`Stacking order can only be calculated for elements with a common ancestor`);let i={a:sc(oc(n.a)),b:sc(oc(n.b))};if(i.a===i.b){let e=r.childNodes,t={a:n.a.at(-1),b:n.b.at(-1)},i=e.length;for(;i--;){let n=e[i];if(n===t.a)return 1;if(n===t.b)return-1}}return Math.sign(i.a-i.b)}var rc=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function ic(e){let t=getComputedStyle(lc(e)??e).display;return t===`flex`||t===`inline-flex`}function ac(e){let t=getComputedStyle(e);return!!(t.position===`fixed`||t.zIndex!==`auto`&&(t.position!==`static`||ic(e))||+t.opacity<1||`transform`in t&&t.transform!==`none`||`webkitTransform`in t&&t.webkitTransform!==`none`||`mixBlendMode`in t&&t.mixBlendMode!==`normal`||`filter`in t&&t.filter!==`none`||`webkitFilter`in t&&t.webkitFilter!==`none`||`isolation`in t&&t.isolation===`isolate`||rc.test(t.willChange)||t.webkitOverflowScrolling===`touch`)}function oc(e){let t=e.length;for(;t--;){let n=e[t];if($(n,`Missing node`),ac(n))return n}return null}function sc(e){return e&&Number(getComputedStyle(e).zIndex)||0}function cc(e){let t=[];for(;e;)t.push(e),e=lc(e);return t}function lc(e){let{parentNode:t}=e;return tc(t)?t.host:t}function uc(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function dc({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!vs(n)||n.contains(e)||e.contains(n))return!0;if(nc(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(uc(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function fc(e,t){let n=[];return t.forEach((t,r)=>{if(r.disabled)return;let i=Cs(r),a=ec(r.orientation,i,{x:e.clientX,y:e.clientY});a&&a.distance.x<=0&&a.distance.y<=0&&dc({groupElement:r.element,hitRegion:a.hitRegion.rect,pointerEventTarget:e.target})&&n.push(a.hitRegion)}),n}function pc(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function mc(e,t,n=0){return Math.abs(fs(e)-fs(t))<=n}function hc(e,t){return mc(e,t)?0:e>t?1:-1}function gc({overrideDisabledPanels:e,panelConstraints:t,prevSize:n,size:r}){let{collapsedSize:i=0,collapsible:a,disabled:o,maxSize:s=100,minSize:c=0}=t;if(o&&!e)return n;if(hc(r,c)<0){if(a){let e=(i+c)/2;r=hc(r,e)<0?i:c}else r=c}return r=Math.min(s,r),r=fs(r),r}function _c({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:a}){if(mc(e,0))return t;let o=a===`imperative-api`,s=Object.values(t),c=Object.values(i),l=[...s],[u,d]=r;$(u!=null,`Invalid first pivot index`),$(d!=null,`Invalid second pivot index`);let f=0;switch(a){case`keyboard`:{let t=e<0?d:u,r=n[t];$(r,`Panel constraints not found for index ${t}`);let{collapsedSize:i=0,collapsible:a,minSize:o=0}=r;if(a){let n=s[t];if($(n!=null,`Previous layout not found for panel index ${t}`),mc(n,i)){let t=o-n;hc(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}{let t=e<0?u:d,r=n[t];$(r,`No panel constraints found for index ${t}`);let{collapsedSize:i=0,collapsible:a,minSize:o=0}=r;if(a){let n=s[t];if($(n!=null,`Previous layout not found for panel index ${t}`),mc(n,o)){let t=n-i;hc(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}break;default:{let t=e<0?d:u,r=n[t];$(r,`Panel constraints not found for index ${t}`);let i=s[t],{collapsible:a,collapsedSize:o,minSize:c}=r;if(a&&hc(i,c)<0){if(e>0){let t=c-o,n=t/2;hc(i+e,c)<0&&(e=hc(e,n)<=0?0:t)}else{let t=c-o,n=100-t/2;hc(i-e,c)<0&&(e=hc(100+e,n)>0?0:-t)}}break}}{let t=e<0?1:-1,r=e<0?d:u,i=0;for(;;){let e=s[r];$(e!=null,`Previous layout not found for panel index ${r}`);let a=gc({overrideDisabledPanels:o,panelConstraints:n[r],prevSize:e,size:100})-e;if(i+=a,r+=t,r<0||r>=n.length)break}let a=Math.min(Math.abs(e),Math.abs(i));e=e<0?0-a:a}{let t=e<0?u:d;for(;t>=0&&t<n.length;){let r=Math.abs(e)-Math.abs(f),i=s[t];$(i!=null,`Previous layout not found for panel index ${t}`);let a=i-r,c=gc({overrideDisabledPanels:o,panelConstraints:n[t],prevSize:i,size:a});if(!mc(i,c)&&(f+=i-c,l[t]=c,f.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?t--:t++}}if(pc(c,l))return i;{let t=e<0?d:u,r=s[t];$(r!=null,`Previous layout not found for panel index ${t}`);let i=r+f,a=gc({overrideDisabledPanels:o,panelConstraints:n[t],prevSize:r,size:i});if(l[t]=a,!mc(a,i)){let t=i-a,r=e<0?d:u;for(;r>=0&&r<n.length;){let i=l[r];$(i!=null,`Previous layout not found for panel index ${r}`);let a=i+t,s=gc({overrideDisabledPanels:o,panelConstraints:n[r],prevSize:i,size:a});if(mc(i,s)||(t-=s-i,l[r]=s),mc(t,0))break;e>0?r--:r++}}}if(!mc(Object.values(l).reduce((e,t)=>t+e,0),100,.1))return i;let p=Object.keys(i);return l.reduce((e,t,n)=>(e[p[n]]=t,e),{})}function vc(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(t[n]===void 0||hc(e[n],t[n])!==0)return!1;return!0}function yc({layout:e,panelConstraints:t}){let n=Object.values(e),r=[...n],i=r.reduce((e,t)=>e+t,0);if(r.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${r.map(e=>`${e}%`).join(`, `)}`);if(!mc(i,100)&&r.length>0)for(let e=0;e<t.length;e++){let t=r[e];$(t!=null,`No layout data found for index ${e}`);let n=100/i*t;r[e]=n}let a=0;for(let e=0;e<t.length;e++){let i=n[e];$(i!=null,`No layout data found for index ${e}`);let o=r[e];$(o!=null,`No layout data found for index ${e}`);let s=gc({overrideDisabledPanels:!0,panelConstraints:t[e],prevSize:i,size:o});o!=s&&(a+=o-s,r[e]=s)}if(!mc(a,0))for(let e=0;e<t.length;e++){let n=r[e];$(n!=null,`No layout data found for index ${e}`);let i=n+a,o=gc({overrideDisabledPanels:!0,panelConstraints:t[e],prevSize:n,size:i});if(n!==o&&(a-=o-n,r[e]=o,mc(a,0)))break}let o=Object.keys(e);return r.reduce((e,t,n)=>(e[o[n]]=t,e),{})}function bc({groupId:e,panelId:t}){let n=()=>{let t=Ys();for(let[n,{defaultLayoutDeferred:r,derivedPanelConstraints:i,layout:a,groupSize:o,separatorToPanels:s}]of t)if(n.id===e)return{defaultLayoutDeferred:r,derivedPanelConstraints:i,group:n,groupSize:o,layout:a,separatorToPanels:s};throw Error(`Group ${e} not found`)},r=()=>{let e=n().derivedPanelConstraints.find(e=>e.panelId===t);if(e!==void 0)return e;throw Error(`Panel constraints not found for Panel ${t}`)},i=()=>{let e=n().group.panels.find(e=>e.id===t);if(e!==void 0)return e;throw Error(`Layout not found for Panel ${t}`)},a=()=>{let e=n().layout[t];if(e!==void 0)return e;throw Error(`Layout not found for Panel ${t}`)},o=({nextSize:e,panels:n,prevLayout:r,derivedPanelConstraints:i})=>{let o=a(),s=n.findIndex(e=>e.id===t),c=s===0,l=s===n.length-1;if(l&&e<o&&(c||n.slice(0,s).every((e,t)=>{let n=i[t];return n?.collapsible&&mc(n.collapsedSize,r[n.panelId])}))){let e=n.slice(0,s).reduce((e,t)=>e+r[t.id],0);return{...r,[t]:fs(100-e)}}return _c({delta:l?o-e:e-o,initialLayout:r,panelConstraints:i,pivotIndices:l?[s-1,s]:[s,s+1],prevLayout:r,trigger:`imperative-api`})},s=e=>{if(e===a())return;let{defaultLayoutDeferred:t,derivedPanelConstraints:r,group:i,groupSize:s,layout:c,separatorToPanels:l}=n(),u=yc({layout:o({nextSize:e,panels:i.panels,prevLayout:c,derivedPanelConstraints:r}),panelConstraints:r});vc(c,u)||Zs(i,{defaultLayoutDeferred:t,derivedPanelConstraints:r,groupSize:s,layout:u,separatorToPanels:l})};return{collapse:()=>{let{collapsible:e,collapsedSize:t}=r(),{mutableValues:n}=i(),o=a();e&&o!==t&&(n.expandToSize=o,s(t))},expand:()=>{let{collapsible:e,collapsedSize:t,minSize:n}=r(),{mutableValues:o}=i(),c=a();if(e&&c===t){let e=o.expandToSize??n;e===0&&(e=1),s(e)}},getSize:()=>{let{group:e}=n(),t=a(),{element:r}=i();return{asPercentage:t,inPixels:e.orientation===`horizontal`?r.offsetWidth:r.offsetHeight}},isCollapsed:()=>{let{collapsible:e,collapsedSize:t}=r(),n=a();return e&&mc(t,n)},resize:e=>{let{group:t}=n(),{element:r}=i(),a=ps({group:t}),o=fs(ds({groupSize:a,panelElement:r,styleProp:e})/a*100);s(o)}}}function xc(e){e.defaultPrevented||fc(e,Ys()).forEach(t=>{if(t.separator&&!t.separator.disableDoubleClick){let n=t.panels.find(e=>e.panelConstraints.defaultSize!==void 0);if(n){let r=n.panelConstraints.defaultSize,i=bc({groupId:t.group.id,panelId:n.id});i&&r!==void 0&&(i.resize(r),e.preventDefault())}}})}function Sc(e){let t=Ys();for(let[n]of t)if(n.separators.some(t=>t.element===e))return n;throw Error(`Could not find parent Group for separator element`)}function Cc({groupId:e}){let t=()=>{let t=Ys();for(let[n,r]of t)if(n.id===e)return{group:n,...r};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){let{defaultLayoutDeferred:e,layout:n}=t();return e?{}:n},setLayout(e){let{defaultLayoutDeferred:n,derivedPanelConstraints:r,group:i,groupSize:a,layout:o,separatorToPanels:s}=t(),c=yc({layout:e,panelConstraints:r});return n?o:(vc(o,c)||Zs(i,{defaultLayoutDeferred:n,derivedPanelConstraints:r,groupSize:a,layout:c,separatorToPanels:s}),c)}}}function wc(e,t){let n=Sc(e),r=Js(n.id,!0),i=n.separators.find(t=>t.element===e);$(i,`Matching separator not found`);let a=r.separatorToPanels.get(i);$(a,`Matching panels not found`);let o=a.map(e=>n.panels.indexOf(e)),s=Cc({groupId:n.id}).getLayout(),c=yc({layout:_c({delta:t,initialLayout:s,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:s,trigger:`keyboard`}),panelConstraints:r.derivedPanelConstraints});vc(s,c)||Zs(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:c,separatorToPanels:r.separatorToPanels},{isUserInteraction:!0})}function Tc(e){if(e.defaultPrevented)return;let t=e.currentTarget,n=Sc(t);if(!n.disabled)switch(e.key){case`ArrowDown`:e.preventDefault(),n.orientation===`vertical`&&wc(t,5);break;case`ArrowLeft`:e.preventDefault(),n.orientation===`horizontal`&&wc(t,-5);break;case`ArrowRight`:e.preventDefault(),n.orientation===`horizontal`&&wc(t,5);break;case`ArrowUp`:e.preventDefault(),n.orientation===`vertical`&&wc(t,-5);break;case`End`:e.preventDefault(),wc(t,100);break;case`Enter`:{e.preventDefault();let n=Sc(t),{derivedPanelConstraints:r,layout:i,separatorToPanels:a}=Js(n.id,!0),o=n.separators.find(e=>e.element===t);$(o,`Matching separator not found`);let s=a.get(o);$(s,`Matching panels not found`);let c=s[0],l=r.find(e=>e.panelId===c.id);if($(l,`Panel metadata not found`),l.collapsible){let e=i[c.id];wc(t,(l.collapsedSize===e?n.mutableState.expandedPanelSizes[c.id]??l.minSize:l.collapsedSize)-e)}break}case`F6`:{e.preventDefault();let n=Sc(t).separators.map(e=>e.element),r=Array.from(n).findIndex(t=>t===e.currentTarget);$(r!==null,`Index not found`),n[e.shiftKey?r>0?r-1:n.length-1:r+1<n.length?r+1:0].focus({preventScroll:!0});break}case`Home`:e.preventDefault(),wc(t,-100);break}}function Ec(e){if(e.defaultPrevented||e.pointerType===`mouse`&&e.button>0)return;let t=Ys(),n=fc(e,t),r=new Map,i=!1;n.forEach(e=>{e.separator&&(i||(i=!0,e.separator.element.focus({focusVisible:!1,preventScroll:!0})));let n=t.get(e.group);n&&r.set(e.group,n.layout)}),As({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:`active`}),n.length&&e.preventDefault()}function Dc({document:e,event:t,hitRegions:n,initialLayoutMap:r,mountedGroups:i,pointerDownAtPoint:a,prevCursorFlags:o}){let s=0;n.forEach(e=>{let{group:n,groupSize:o}=e,{orientation:c,panels:l}=n,{disableCursor:u}=n.mutableState,d=0;d=a?c===`horizontal`?(t.clientX-a.x)/o*100:(t.clientY-a.y)/o*100:c===`horizontal`?t.clientX<0?-100:100:t.clientY<0?-100:100;let f=r.get(n),p=i.get(n);if(!f||!p)return;let{defaultLayoutDeferred:m,derivedPanelConstraints:h,groupSize:g,layout:_,separatorToPanels:v}=p;if(h&&_&&v){let t=_c({delta:d,initialLayout:f,panelConstraints:h,pivotIndices:e.panels.map(e=>l.indexOf(e)),prevLayout:_,trigger:`mouse-or-touch`});if(vc(t,_)){if(d!==0&&!u)switch(c){case`horizontal`:s|=d<0?Ns:Ps;break;case`vertical`:s|=d<0?Fs:Is;break}}else Zs(e.group,{defaultLayoutDeferred:m,derivedPanelConstraints:h,groupSize:g,layout:t,separatorToPanels:v})}});let c=0;t.movementX===0?c|=o&Ls:c|=s&Ls,t.movementY===0?c|=o&Rs:c|=s&Rs,ks(c),Us(e)}function Oc(e){let t=Ys(),n=Ds();n.state===`active`&&Dc({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}function kc(e){if(e.defaultPrevented)return;let t=Ds(),n=Ys();switch(t.state){case`active`:if(e.buttons===0){As({cursorFlags:0,state:`inactive`}),t.hitRegions.forEach(e=>{let t=Js(e.group.id,!0);Zs(e.group,t,{isUserInteraction:!0})});return}for(let n of t.hitRegions)if(n.separator){let{element:t}=n.separator;t.hasPointerCapture?.(e.pointerId)||t.setPointerCapture?.(e.pointerId)}Dc({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break;default:{let r=fc(e,n);r.length===0?t.state!==`inactive`&&As({cursorFlags:0,state:`inactive`}):As({cursorFlags:0,hitRegions:r,state:`hover`}),Us(e.currentTarget);break}}}function Ac(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(Ds().state){case`hover`:As({cursorFlags:0,state:`inactive`})}}function jc(e){e.defaultPrevented||e.pointerType===`mouse`&&e.button>0||Qs(e.currentTarget)&&e.preventDefault()}function Mc(e){let t=0,n=0,r={};for(let i of e)if(i.defaultSize!==void 0){t++;let e=fs(i.defaultSize);n+=e,r[i.panelId]=e}else r[i.panelId]=void 0;let i=e.length-t;if(i!==0){let t=fs((100-n)/i);for(let n of e)n.defaultSize===void 0&&(r[n.panelId]=t)}return r}function Nc(e,t,n){if(!n[0])return;let r=e.panels.find(e=>e.element===t);if(!r||!r.onResize)return;let i=ps({group:e}),a=e.orientation===`horizontal`?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,s={asPercentage:fs(a/i*100),inPixels:a};r.mutableValues.prevSize=s,r.onResize(s,r.id,o)}function Pc(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(e[n]!==t[n])return!1;return!0}function Fc({group:e,nextGroupSize:t,prevGroupSize:n,prevLayout:r}){if(n<=0||t<=0||n===t)return r;let i=0,a=0,o=!1,s=new Map,c=[];for(let l of e.panels){let e=r[l.id]??0;switch(l.panelConstraints.groupResizeBehavior){case`preserve-pixel-size`:{o=!0;let r=fs(e/100*n/t*100);s.set(l.id,r),i+=r;break}default:c.push(l.id),a+=e}}if(!o||c.length===0)return r;let l=100-i,u={...r};if(s.forEach((e,t)=>{u[t]=e}),a>0)for(let e of c)u[e]=fs((r[e]??0)/a*l);else{let e=fs(l/c.length);for(let t of c)u[t]=e}return u}function Ic(e,t){let n=e.map(e=>e.id),r=Object.keys(t);if(n.length!==r.length)return!1;for(let e of n)if(!r.includes(e))return!1;return!0}var Lc=new Map;function Rc(e){let t=!0;$(e.element.ownerDocument.defaultView,`Cannot register an unmounted Group`);let n=e.element.ownerDocument.defaultView.ResizeObserver,r=new Set,i=new Set,a=new n(n=>{for(let r of n){let{borderBoxSize:n,target:i}=r;if(i===e.element){if(t){let t=ps({group:e});if(t===0)return;let n=Js(e.id);if(!n)return;let r=ms(e),i=n.defaultLayoutDeferred?Mc(r):n.layout,a=yc({layout:Fc({group:e,nextGroupSize:t,prevGroupSize:n.groupSize,prevLayout:i}),panelConstraints:r});if(!n.defaultLayoutDeferred&&vc(n.layout,a)&&Pc(n.derivedPanelConstraints,r)&&n.groupSize===t)return;Zs(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:r,groupSize:t,layout:a,separatorToPanels:n.separatorToPanels})}}else Nc(e,i,n)}});a.observe(e.element),e.panels.forEach(e=>{$(!r.has(e.id),`Panel ids must be unique; id "${e.id}" was used more than once`),r.add(e.id),e.onResize&&a.observe(e.element)});let o=ps({group:e}),s=ms(e),c=e.panels.map(({id:e})=>e).join(`,`),l=e.mutableState.defaultLayout;l&&(Ic(e.panels,l)||(l=void 0));let u=yc({layout:e.mutableState.layouts[c]??l??Mc(s),panelConstraints:s}),d=e.element.ownerDocument;Lc.set(d,(Lc.get(d)??0)+1);let f=new Map;return Cs(e).forEach(e=>{e.separator&&f.set(e.separator,e.panels)}),Zs(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:s,groupSize:o,layout:u,separatorToPanels:f}),e.separators.forEach(e=>{$(!i.has(e.id),`Separator ids must be unique; id "${e.id}" was used more than once`),i.add(e.id),e.element.addEventListener(`keydown`,Tc)}),Lc.get(d)===1&&(d.addEventListener(`contextmenu`,$s,!0),d.addEventListener(`dblclick`,xc,!0),d.addEventListener(`pointerdown`,Ec,!0),d.addEventListener(`pointerleave`,Oc),d.addEventListener(`pointermove`,kc),d.addEventListener(`pointerout`,Ac),d.addEventListener(`pointerup`,jc,!0)),function(){t=!1,Lc.set(d,Math.max(0,(Lc.get(d)??0)-1)),Ks(e),e.separators.forEach(e=>{e.element.removeEventListener(`keydown`,Tc)}),Lc.get(d)||(d.removeEventListener(`contextmenu`,$s,!0),d.removeEventListener(`dblclick`,xc,!0),d.removeEventListener(`pointerdown`,Ec,!0),d.removeEventListener(`pointerleave`,Oc),d.removeEventListener(`pointermove`,kc),d.removeEventListener(`pointerout`,Ac),d.removeEventListener(`pointerup`,jc,!0)),a.disconnect()}}function zc(){let[e,t]=(0,Z.useState)({});return[e,(0,Z.useCallback)(()=>t({}),[])]}function Bc(e){let t=(0,Z.useId)();return`${e??t}`}var Vc=typeof window<`u`?Z.useLayoutEffect:Z.useEffect;function Hc(e){let t=(0,Z.useRef)(e);return Vc(()=>{t.current=e},[e]),(0,Z.useCallback)((...e)=>t.current?.(...e),[t])}function Uc(...e){return Hc(t=>{e.forEach(e=>{if(e)switch(typeof e){case`function`:e(t);break;case`object`:e.current=t;break}})})}function Wc(e){let t=(0,Z.useRef)({...e});return Vc(()=>{for(let n in e)t.current[n]=e[n]},[e]),t.current}var Gc=(0,Z.createContext)(null);function Kc(e,t){let n=(0,Z.useRef)({getLayout:()=>({}),setLayout:js});(0,Z.useImperativeHandle)(t,()=>n.current,[]),Vc(()=>{Object.assign(n.current,Cc({groupId:e}))})}function qc({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:a,groupRef:o,id:s,onLayoutChange:c,onLayoutChanged:l,orientation:u=`horizontal`,resizeTargetMinimumSize:d={coarse:20,fine:10},style:f,...p}){let m=(0,Z.useRef)({onLayoutChange:{},onLayoutChanged:{}}),h=Hc(e=>{vc(m.current.onLayoutChange,e)||(m.current.onLayoutChange=e,c?.(e))}),g=Hc((e,t)=>{vc(m.current.onLayoutChanged,e)||(m.current.onLayoutChanged=e,l?.(e,{isUserInteraction:t}))}),_=Bc(s),v=(0,Z.useRef)(null),[y,b]=zc(),x=(0,Z.useRef)({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:d,separators:[]}),S=Uc(v,a);Kc(_,o);let C=Hc((e,t)=>{let r=Ds(),i=qs(e),a=Js(e);if(a){let e=!1;return r.state===`active`&&(e=r.hitRegions.some(e=>e.group===i)),{flexGrow:a.layout[t]??1,pointerEvents:e?`none`:void 0}}if(n?.[t])return{flexGrow:n?.[t]}}),w=Wc({defaultLayout:n,disableCursor:r}),T=(0,Z.useMemo)(()=>({get disableCursor(){return!!w.disableCursor},getPanelStyles:C,id:_,orientation:u,registerPanel:e=>{let t=x.current;return t.panels=hs(u,[...t.panels,e]),b(),()=>{t.panels=t.panels.filter(t=>t!==e),b()}},registerSeparator:e=>{let t=x.current;return t.separators=hs(u,[...t.separators,e]),b(),()=>{t.separators=t.separators.filter(t=>t!==e),b()}},updatePanelProps:(e,{disabled:t})=>{let n=x.current.panels.find(t=>t.id===e);n&&(n.panelConstraints.disabled=t);let r=qs(_),i=Js(_);r&&i&&Zs(r,{...i,derivedPanelConstraints:ms(r)})},updateSeparatorProps:(e,{disabled:t,disableDoubleClick:n})=>{let r=x.current.separators.find(t=>t.id===e);r&&(r.disabled=t,r.disableDoubleClick=n)}}),[C,_,b,u,w]),E=(0,Z.useRef)(null);return Vc(()=>{let e=v.current;if(e===null)return;let t=x.current,n;if(w.defaultLayout!==void 0&&Object.keys(w.defaultLayout).length===t.panels.length){n={};for(let e of t.panels){let t=w.defaultLayout[e.id];t!==void 0&&(n[e.id]=t)}}let r={disabled:!!i,element:e,id:_,mutableState:{defaultLayout:n,disableCursor:!!w.disableCursor,expandedPanelSizes:x.current.lastExpandedPanelSizes,layouts:x.current.layouts},orientation:u,panels:t.panels,resizeTargetMinimumSize:t.resizeTargetMinimumSize,separators:t.separators};E.current=r;let a=Rc(r),{defaultLayoutDeferred:o,derivedPanelConstraints:s,layout:c}=Js(r.id,!0);!o&&s.length>0&&(h(c),g(c,!1));let l=Xs(_,e=>{let{defaultLayoutDeferred:t,derivedPanelConstraints:n,layout:i}=e.next;if(t||n.length===0)return;let a=r.panels.map(({id:e})=>e).join(`,`);r.mutableState.layouts[a]=i,n.forEach(t=>{if(t.collapsible){let{layout:n}=e.prev??{};if(n){let e=mc(t.collapsedSize,i[t.panelId]),a=mc(t.collapsedSize,n[t.panelId]);e&&!a&&(r.mutableState.expandedPanelSizes[t.panelId]=n[t.panelId])}}});let o=Ds().state!==`active`;h(i),o&&g(i,e.isUserInteraction)});return()=>{E.current=null,a(),l()}},[i,_,g,h,u,y,w]),(0,Z.useEffect)(()=>{let e=E.current;e&&(e.mutableState.defaultLayout=n,e.mutableState.disableCursor=!!r)}),(0,Q.jsx)(Gc.Provider,{value:T,children:(0,Q.jsx)(`div`,{...p,className:t,"data-group":!0,"data-testid":_,id:_,ref:S,style:{height:`100%`,width:`100%`,overflow:`hidden`,...f,display:`flex`,flexDirection:u===`horizontal`?`row`:`column`,flexWrap:`nowrap`,touchAction:u===`horizontal`?`pan-y`:`pan-x`},children:e})})}qc.displayName=`Group`;function Jc(){let e=(0,Z.useContext)(Gc);return $(e,`Group Context not found; did you render a Panel or Separator outside of a Group?`),e}function Yc(e,t){let{id:n}=Jc(),r=(0,Z.useRef)({collapse:Ms,expand:Ms,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:Ms});(0,Z.useImperativeHandle)(t,()=>r.current,[]),Vc(()=>{Object.assign(r.current,bc({groupId:n,panelId:e}))})}function Xc({children:e,className:t,collapsedSize:n=`0%`,collapsible:r=!1,defaultSize:i,disabled:a,elementRef:o,groupResizeBehavior:s=`preserve-relative-size`,id:c,maxSize:l=`100%`,minSize:u=`0%`,onResize:d,panelRef:f,style:p,...m}){let h=!!c,g=Bc(c),_=Wc({disabled:a}),v=(0,Z.useRef)(null),y=Uc(v,o),{getPanelStyles:b,id:x,orientation:S,registerPanel:C,updatePanelProps:w}=Jc(),T=d!==null,E=Hc((e,t,n)=>{d?.(e,c,n)});Vc(()=>{let e=v.current;if(e!==null){let t={element:e,id:g,idIsStable:h,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:T?E:void 0,panelConstraints:{groupResizeBehavior:s,collapsedSize:n,collapsible:r,defaultSize:i,disabled:_.disabled,maxSize:l,minSize:u}};return C(t)}},[s,n,r,i,T,g,h,l,u,E,C,_]),(0,Z.useEffect)(()=>{w(g,{disabled:a})},[a,g,w]),Yc(g,f);let D=()=>{let e=b(x,g);if(e)return JSON.stringify(e)},O=(0,Z.useSyncExternalStore)(e=>Xs(x,e),D,D),k;return k=O?JSON.parse(O):i===void 0?{flexGrow:1}:{flexGrow:void 0,flexShrink:void 0,flexBasis:i},(0,Q.jsx)(`div`,{...m,"data-disabled":a||void 0,"data-panel":!0,"data-testid":g,id:g,ref:y,style:{...Zc,display:`flex`,flexBasis:0,flexShrink:1,overflow:`visible`,...k},children:(0,Q.jsx)(`div`,{className:t,style:{maxHeight:`100%`,maxWidth:`100%`,flexGrow:1,overflow:`auto`,...p,touchAction:S===`horizontal`?`pan-y`:`pan-x`},children:e})})}Xc.displayName=`Panel`;var Zc={minHeight:0,maxHeight:`100%`,height:`auto`,minWidth:0,maxWidth:`100%`,width:`auto`,border:`none`,borderWidth:0,padding:0,margin:0};function Qc(){return(0,Z.useRef)(null)}function $c({layout:e,panelConstraints:t,panelId:n,panelIndex:r}){let i,a,o=e[n],s=t.find(e=>e.panelId===n);if(s){let c=s.maxSize,l=s.collapsible?s.collapsedSize:s.minSize,u=[r,r+1];a=yc({layout:_c({delta:l-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n],i=yc({layout:_c({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:a,valueNow:o}}function el({children:e,className:t,disabled:n,disableDoubleClick:r,elementRef:i,id:a,style:o,...s}){let c=Bc(a),l=Wc({disabled:n,disableDoubleClick:r}),[u,d]=(0,Z.useState)({}),[f,p]=(0,Z.useState)(`inactive`),[m,h]=(0,Z.useState)(!1),g=(0,Z.useRef)(null),_=Uc(g,i),{disableCursor:v,id:y,orientation:b,registerSeparator:x,updateSeparatorProps:S}=Jc(),C=b===`horizontal`?`vertical`:`horizontal`;Vc(()=>{let e=g.current;if(e!==null){let t={disabled:l.disabled,disableDoubleClick:l.disableDoubleClick,element:e,id:c},n=x(t),r=Os(e=>{p(e.next.state!==`inactive`&&e.next.hitRegions.some(e=>e.separator===t)?e.next.state:`inactive`)}),i=Xs(y,e=>{let{derivedPanelConstraints:n,layout:r,separatorToPanels:i}=e.next,a=i.get(t);if(a){let e=a[0],t=a.indexOf(e);d($c({layout:r,panelConstraints:n,panelId:e.id,panelIndex:t}))}});return()=>{r(),i(),n()}}},[y,c,x,l]),(0,Z.useEffect)(()=>{S(c,{disabled:n,disableDoubleClick:r})},[n,r,c,S]);let w;n&&!v&&(w=`not-allowed`);let T;if(n)T=`disabled`;else switch(f){case`active`:T=`active`;break;default:T=m?`focus`:f}return(0,Q.jsx)(`div`,{...s,"aria-controls":u.valueControls,"aria-disabled":n||void 0,"aria-orientation":C,"aria-valuemax":u.valueMax,"aria-valuemin":u.valueMin,"aria-valuenow":u.valueNow,children:e,className:t,"data-separator":T,"data-testid":c,id:c,onBlur:()=>h(!1),onFocus:()=>h(!0),ref:_,role:`separator`,style:{flexBasis:`auto`,cursor:w,...o,flexGrow:0,flexShrink:0,touchAction:`none`},tabIndex:n?void 0:0})}el.displayName=`Separator`;function tl({className:e,...t}){return(0,Q.jsx)(qc,{"data-slot":`resizable-panel-group`,className:L(`flex h-full w-full aria-[orientation=vertical]:flex-col`,e),...t})}function nl({...e}){return(0,Q.jsx)(Xc,{"data-slot":`resizable-panel`,...e})}function rl({withHandle:e,className:t,...n}){return(0,Q.jsx)(el,{"data-slot":`resizable-handle`,className:L(`relative flex w-px items-center justify-center bg-border ring-offset-background after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-hidden aria-[orientation=horizontal]:h-px aria-[orientation=horizontal]:w-full aria-[orientation=horizontal]:after:left-0 aria-[orientation=horizontal]:after:h-1 aria-[orientation=horizontal]:after:w-full aria-[orientation=horizontal]:after:translate-x-0 aria-[orientation=horizontal]:after:-translate-y-1/2 [&[aria-orientation=horizontal]>div]:rotate-90`,t),...n,children:e&&(0,Q.jsx)(`div`,{className:`z-10 flex h-6 w-1 shrink-0 rounded-lg bg-border`})})}function il({availableWidth:e,presentation:t,children:n,context:r,side:i=`right`}){let{t:a}=c(),o=Fn(e=>e.width),s=Fn(e=>e.setWidth),l=Qc(),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),f=t===`aside`;(0,Z.useLayoutEffect)(()=>{f&&e>0&&l.current?.resize(o)},[f,e,l,o,i]);let p=(0,Q.jsx)(nl,{id:`chat-conversation`,minSize:f?400:0,children:n},`conversation`),m=(0,Q.jsx)(rl,{elementRef:d,"aria-label":a(`chat:sessionContext.resize`),title:a(`chat:sessionContext.resizeHint`),withHandle:!0,disableDoubleClick:!0,onDoubleClick:()=>{s(360),l.current?.resize(360)},className:`w-2 bg-transparent after:w-2 focus-visible:ring-inset [&>div]:h-10 [&>div]:bg-[var(--stroke-soft)] hover:[&>div]:bg-[var(--brand-blue)] focus-visible:[&>div]:bg-[var(--brand-blue)]`},`separator`),h=(0,Q.jsx)(nl,{id:`chat-context`,panelRef:l,defaultSize:o,minSize:280,maxSize:720,groupResizeBehavior:`preserve-pixel-size`,children:r},`context`);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(tl,{id:`chat-context-layout`,elementRef:u,orientation:`horizontal`,className:`min-h-0 min-w-0 flex-1`,disabled:!f,onLayoutChanged:(e,{isUserInteraction:t})=>{if(!f||!t)return;let n=u.current,r=d.current,i=e[`chat-context`];if(!n||!r||!Number.isFinite(i))return;let a=n.clientWidth-r.getBoundingClientRect().width;a>0&&s(a*i/100)},children:f?i===`left`?[h,m,p]:[p,m,h]:[p]}),t===`sheet`&&r]})}function al(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ol(e){if(!al(e)||typeof e.created!=`boolean`)throw pt();if(e.session===null){if(e.expiresAt!==null||e.created)throw pt();return{session:null,expiresAt:null,created:!1}}let t=e.session;if(!al(t)||typeof t.id!=`string`||!t.id||typeof e.expiresAt!=`string`||!Number.isFinite(Date.parse(e.expiresAt)))throw pt();let n={id:t.id};for(let e of[`name`,`cwd`,`model`,`thinkingLevel`,`executionMode`,`permissionMode`,`runMode`]){let r=t[e];if(r!=null&&typeof r!=`string`)throw pt();typeof r==`string`&&(n[e]=r)}if(t.streaming!==void 0&&typeof t.streaming!=`boolean`)throw pt();return typeof t.streaming==`boolean`&&(n.streaming=t.streaming),{session:n,expiresAt:e.expiresAt,created:e.created}}async function sl(e,t){return ol(await mt(`/api/sessions/${encodeURIComponent(e)}/side-chat`,{signal:t}))}async function cl(e,t){let n=ol(await mt(`/api/sessions/${encodeURIComponent(e)}/side-chat`,{method:`POST`,signal:t}));if(!n.session)throw pt();return n}function ll({runtime:e,children:t}){let[n,r]=(0,Z.useState)({}),i=(0,Z.useRef)(n),a=(0,Z.useRef)(!0),o=(0,Z.useRef)(e),s=(0,Z.useRef)(new Map),c=(0,Z.useRef)(new Map);(0,Z.useLayoutEffect)(()=>{o.current=e},[e]),(0,Z.useLayoutEffect)(()=>(a.current=!0,()=>{a.current=!1}),[]);let l=(0,Z.useCallback)((e,t)=>{let n={...i.current,[e]:{...i.current[e]??Le,...t}};i.current=n,r(n)},[]),u=(0,Z.useCallback)(async(e,t=!1)=>{if(!a.current)return null;let n=c.current.get(e);if(n){let r=await n.promise;return!t||n.create?r:u(e,!0)}let r=new AbortController;l(e,{loading:!0,error:``});let d=(async()=>{try{let n=await(t?cl:sl)(e,r.signal);if(r.signal.aborted)return null;let a=i.current[e]?.session?.id;if(a&&a!==n.session?.id&&(o.current.discard(a),s.current.get(a)?.(),s.current.delete(a),Ur(a)),l(e,{...n,expired:!n.session&&!!(a||i.current[e]?.expired)}),n.session){if(s.current.has(n.session.id)||s.current.set(n.session.id,o.current.retainSessionState(n.session.id)),await o.current.syncLiveSession(n.session.id),r.signal.aborted)return null;await o.current.loadSessionMessages(n.session.id)}return r.signal.aborted?null:n}catch(t){return r.signal.aborted||l(e,{error:K(t)}),null}finally{r.signal.aborted||l(e,{loading:!1}),c.current.get(e)?.controller===r&&c.current.delete(e)}})();return c.current.set(e,{create:t,controller:r,promise:d}),d},[l]);(0,Z.useEffect)(()=>{a.current=!0;let e=c.current,t=s.current,n=()=>{for(let[e,t]of Object.entries(i.current))t.expiresAt&&Date.parse(t.expiresAt)<=Date.now()&&!c.current.has(e)&&u(e)},r=window.setInterval(n,6e4),o=()=>{document.visibilityState===`visible`&&n()};return document.addEventListener(`visibilitychange`,o),()=>{a.current=!1,window.clearInterval(r),document.removeEventListener(`visibilitychange`,o);for(let t of e.values())t.controller.abort();e.clear();for(let e of t.values())e();t.clear()}},[u]);let d=(0,Z.useCallback)((e,t)=>l(e,{draft:t}),[l]),f=(0,Z.useMemo)(()=>({entries:n,runtime:e,load:u,setDraft:d}),[n,e,u,d]);return(0,Q.jsx)(Pe.Provider,{value:f,children:t})}var ul=(0,Z.lazy)(()=>t(()=>import(`./SessionContextPanel-oaKXyi7k.js`).then(e=>({default:e.SessionContextPanel})),__vite__mapDeps([31,2,4,22,14,3,15,16,17,23,32,33,34,35,36,37,38,39,40,41,19,8,42,43,24,44,45,46,47,48,49,50,51,52,53,54,25,55,56,57,58,59,60,28,61,62,63,64,65,66,67,68,69,70,71,12,13,10,72,73,74,75,76,77,78,79,80,81,82,83,84,85,5,6,7,1,86,87,88,89,90,91,92,93,94,95]))),dl=`chat-session-context-panel`;function fl(e){let t=window.__TAURI__?.core?.invoke??window.__TAURI_INTERNALS__?.invoke;return t?t(e):Promise.reject(Error(`native bridge unavailable`))}function pl({notify:e,navigate:t,browserNotify:n,reportActiveSessionRun:r,registerPrimaryAction:i,pendingAsset:a,onAssetConsumed:o,requestText:s,requestConfirm:l}){let{t:u}=c(),d=St(e=>e.client===`mobile-app`),f=St(e=>e.loaded),p=ft(),m=d||p,h=Yt(e=>e.capabilities),g=(0,Z.useRef)(null),[_,v]=(0,Z.useState)(0),y=Fn(e=>e.open),b=Fn(e=>e.setOpen),[x,S]=(0,Z.useState)(`files`);(0,Z.useLayoutEffect)(()=>{let e=g.current;if(!e)return;let t=()=>v(e.clientWidth);if(t(),typeof ResizeObserver>`u`)return window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t);let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let C=(0,Z.useRef)(new Set),w=(0,Z.useRef)(new Map),T=(0,Z.useRef)(null),E=Co({notify:e}),D=(0,Z.useRef)(new Set);(0,Z.useEffect)(()=>{let e=()=>{let e=E.activeId;!e||document.visibilityState!==`visible`||!E.sessions.some(t=>t.id===e&&t.unread)||D.current.has(e)||(D.current.add(e),ee(e,{read:!0}).catch(()=>void 0).finally(()=>D.current.delete(e)))};return e(),document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[E.activeId,E.sessions]);let O=Po({sessionStates:E.sessionStates,sessionStatesRef:E.sessionStatesRef,localStreamSessionsRef:C,streamGenerationRef:w,updateSessionState:E.updateSessionState,updateSessions:E.updateSessions}),k=Eo({sessions:E.sessions,sessionsRef:E.sessionsRef,sessionStates:E.sessionStates,activeId:E.activeId,setActiveId:E.setActiveId,loading:E.loading,localStreamSessionsRef:C,loadSessionMessages:O.loadSessionMessages,releaseSessionState:E.releaseSessionState,singleSessionLayout:!0,notify:e}),A=E.sessions.find(e=>e.id===E.activeId),j=E.sessionStates[E.activeId],M=je(j,A);(0,Z.useLayoutEffect)(()=>(r({sessionId:E.activeId,streaming:M}),()=>r(null)),[M,E.activeId,r]);let N=j?.lifecycle?.phase===`completed`&&!j.error&&!j.runStopped,P=Ve(j,A),F=He(P,{streaming:M})?P:null,I=wt(),L=I.active?`closed`:Mn({availableWidth:_,mobileLayout:m,hasSession:!!A,preference:y?`open`:`closed`}),R=m||_<800,z=I.active&&I.tab===`session-tools`&&(I.mode===`pad`||I.pane===`context`),[B,V]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{z&&V(!0)},[z]),as({sessionId:E.activeId,streaming:M,completed:N,runStartedAt:typeof j?.runStartedAt==`string`?j.runStartedAt:null,enabled:!0,open:I.active?z:L!==`closed`,onReveal:()=>{S(`files`),I.active?I.openContext(`session-tools`):b(!0)}});let te=E.setActiveId,ne=(0,Z.useCallback)((e,t)=>{if(e){if(I.active){t?(te(e),V(!0),I.openContext(`session-tools`)):I.mode===`pad`?I.openContext(`assets`):I.setPane(`chat`);return}t?(te(e),b(!0)):b(!1)}},[te,b,I]),ie=E.createSessionRecord,H=O.loadSessionMessages,ae=E.refreshSessions,oe=E.sessionStatesRef,se=O.syncLiveSession,ce=E.setGlobalError,le=k.openSessionInDock,ue=k.moveSessionToGroup,[de,fe]=(0,Z.useState)({sessionId:``,token:0}),U=(0,Z.useCallback)(async(e,t=``)=>{let n=null;d&&(n=await fl(`mobile_state`).catch(()=>null));let r=re(d,n),i=await ie(t,{inheritRecentCwd:r});return i?(le(i)&&ue(i,e),i):``},[ie,d,ue,le]);gn(i,U);let pe=es({browserNotify:n,notify:e,defaultModel:E.defaultModel,localStreamSessionsRef:C,streamGenerationRef:w,sessionStatesRef:E.sessionStatesRef,setActiveId:E.setActiveId,setGlobalError:E.setGlobalError,updateSessionState:E.updateSessionState,updateSessions:E.updateSessions,createSession:U,loadSessionMessages:O.loadSessionMessages,refreshSessions:E.refreshSessions,syncLiveSession:O.syncLiveSession}),{sendPrompt:me,retryLastTurn:he}=pe;(0,Z.useEffect)(()=>{let e=()=>{let e=sn();e&&(async()=>{let t=await U(void 0,e.cwd);t&&e.prompt&&me(e.prompt,t)})()};return window.addEventListener(on,e),e(),()=>window.removeEventListener(on,e)},[U,me]);let W=is({notify:e,requestText:s,requestConfirm:l,availableModels:E.availableModels,sessionStatesRef:E.sessionStatesRef,updateSessionState:E.updateSessionState,updateSessions:E.updateSessions,replaceSessionStates:E.replaceSessionStates,setGlobalError:E.setGlobalError,syncLiveSession:O.syncLiveSession}),ge=(0,Z.useCallback)(()=>{if(document.visibilityState!==`visible`||T.current)return;let e=(async()=>{d&&await gt().catch(()=>void 0);let e=[];try{e=await ae(void 0,{preserveExistingOnEmpty:!0})}catch{}let t=new Set([...Object.keys(oe.current),...E.activeId?[E.activeId]:[],...e.filter(e=>e.streaming).map(e=>e.id)]);await Promise.allSettled(Array.from(t).map(e=>se(e,{force:!0})))})().finally(()=>{T.current=null});T.current=e},[E.activeId,d,ae,oe,se]);(0,Z.useEffect)(()=>{let e=()=>ge();return document.addEventListener(`visibilitychange`,e),window.addEventListener(`pageshow`,e),window.addEventListener(`online`,e),()=>{document.removeEventListener(`visibilitychange`,e),window.removeEventListener(`pageshow`,e),window.removeEventListener(`online`,e)}},[ge]);let _e=(0,Z.useCallback)(async e=>{await H(e,{force:!0}),await ae(e)},[H,ae]),ve=(0,Z.useCallback)(async(t,n)=>{if(!(!t?.id||!n))try{if(ce(``),(await Y.navigateSessionTree(t.id,n,!1)).cancelled)return;await _e(t.id),fe(e=>({sessionId:t.id,token:e.token+1})),e(u(`chat:chatPage.branchedFromNode`))}catch(e){ce(e instanceof Error?e.message:String(e))}},[e,_e,ce,u]),ye=(0,Z.useCallback)(async(t,n)=>{if(!t?.id||!n)return;let r=await s({title:u(`chat:chatPage.createChildChat`),inputLabel:u(`chat:chatPage.chatTitle`),value:`${u(`chat:chatPage.separateChatSuffix`)} · ${t.name||u(`chat:chatPage.newChat`)}`,confirmLabel:u(`chat:chatPage.create`)});if(r!==null)try{ce(``);let i=await Y.deriveSession(t.id,n,r);await ae(),le(i.id),fe(e=>({sessionId:i.id,token:e.token+1})),e(u(`chat:chatPage.childChatCreated`))}catch(e){ce(e instanceof Error?e.message:String(e))}},[e,le,ae,s,ce,u]),be=(0,Z.useCallback)(()=>t(`config`),[t]),xe=(0,Z.useMemo)(()=>({sessions:E.sessions,subscribeSessionState:E.subscribeSessionState,getSessionState:E.getSessionState,defaultModel:E.defaultModel,availableModels:E.availableModels,globalError:E.globalError,activeId:E.activeId,compactDock:k.compactDock,contextTab:I.active?z?x:null:L===`closed`?null:x,contextCompact:R,contextPanelId:dl,toggleSessionContext:ne,sessionTreePulseSessionId:de.sessionId,sessionTreePulseToken:de.token,pendingAsset:a,onAssetConsumed:o,notify:e,openModelSettings:be,loadSessionMessages:O.loadSessionMessages,loadOlderMessages:O.loadOlderMessages,sendPrompt:pe.sendPrompt,retryLastTurn:pe.retryLastTurn,queuePrompt:pe.queuePrompt,withdrawQueuedInput:pe.withdrawQueuedInput,abort:pe.abort,pauseGoal:W.pauseGoal,setGoalBudget:W.setGoalBudget,compactSession:W.compactSession,setCompactionThreshold:W.setCompactionThreshold,switchSessionModel:W.switchSessionModel,loadSessionThinkingLevel:W.loadSessionThinkingLevel,switchSessionThinkingLevel:W.switchSessionThinkingLevel,switchSessionExecutionMode:W.switchSessionExecutionMode,switchSessionRunMode:W.switchSessionRunMode,resolveToolApproval:W.resolveToolApproval,selectSessionWorkspace:W.selectSessionWorkspace,renameSession:W.renameSession,branchFromEntry:ve,createChildSession:ye,reloadSessionBranch:_e,splitDockPanel:k.splitDockPanel,closeDockPanel:k.closeDockPanel}),[E.sessions,E.subscribeSessionState,E.getSessionState,E.defaultModel,E.availableModels,E.globalError,E.activeId,k.compactDock,L,x,R,I,z,ne,k.splitDockPanel,k.closeDockPanel,de.sessionId,de.token,a,o,e,be,O.loadSessionMessages,O.loadOlderMessages,pe.sendPrompt,pe.retryLastTurn,pe.queuePrompt,pe.withdrawQueuedInput,pe.abort,W.pauseGoal,W.setGoalBudget,W.compactSession,W.setCompactionThreshold,W.switchSessionModel,W.loadSessionThinkingLevel,W.switchSessionThinkingLevel,W.switchSessionExecutionMode,W.switchSessionRunMode,W.resolveToolApproval,W.selectSessionWorkspace,W.renameSession,ve,ye,_e]),Se=E.discardSessionState,Ce=(0,Z.useMemo)(()=>({subscribeSessionState:E.subscribeSessionState,getSessionState:E.getSessionState,retainSessionState:E.retainSessionState,discard:e=>{w.current.set(e,(w.current.get(e)??0)+1),C.current.delete(e),Se(e)},loadSessionMessages:O.loadSessionMessages,loadOlderMessages:O.loadOlderMessages,syncLiveSession:O.syncLiveSession,send:(e,t)=>me(t,e,[],!1,!1,null,null,{activate:!1}),retry:e=>he(e,{activate:!1}),abort:pe.abort,approve:W.resolveToolApproval}),[E.subscribeSessionState,E.getSessionState,E.retainSessionState,Se,O.loadSessionMessages,O.loadOlderMessages,O.syncLiveSession,me,he,pe.abort,W.resolveToolApproval]),we=A&&(I.active?B||z:L!==`closed`)&&(0,Q.jsx)(Z.Suspense,{fallback:L===`aside`?(0,Q.jsx)(`aside`,{className:`h-full min-h-0 w-full rounded-[var(--r-md)] border border-[var(--stroke-soft)] bg-[var(--panel)] p-4 text-sm text-[var(--text-muted)]`,role:`status`,children:u(`chat:focusSession.gitLoading`)}):null,children:(0,Q.jsx)(ul,{panelId:dl,compact:!I.active&&L===`sheet`,embedded:I.active,sessionId:A.id,tab:x,plan:Jt(h,`plans`)?F:null,streaming:M,plansAvailable:Jt(h,`plans`),requestConfirm:l,onTabChange:S,onClose:()=>ne(A.id,!1)},A.id)});return(0,Q.jsxs)(ll,{runtime:Ce,children:[I.active&&I.sessionToolsHost&&(0,_r.createPortal)(we,I.sessionToolsHost),(0,Q.jsx)(`div`,{ref:g,className:`chat-layout dock-layout relative flex w-full min-w-0 min-h-0 flex-1`,children:(0,Q.jsx)(il,{availableWidth:_,presentation:L,context:I.active?null:we,side:`right`,children:E.loading?(0,Q.jsxs)(Vt,{children:[(0,Q.jsx)(Xe,{className:`animate-spin`,size:24}),(0,Q.jsx)(`h2`,{children:u(`chat:chatPage.wakingTheAgent`)}),(0,Q.jsx)(`p`,{children:u(`chat:chatPage.modelsSessionsAndContextAreSettlingIntoPlace`)})]}):(0,Q.jsx)(`div`,{className:`chat-dock-workspace relative h-full w-full min-w-0 min-h-0 flex-1 [isolation:isolate] overflow-hidden border-0 rounded-none bg-background`,children:(0,Q.jsx)(_o.Provider,{value:xe,children:f&&(0,Q.jsx)(bo,{onCreateSession:U})})})})}),W.workspaceSession&&(0,Q.jsx)(It,{open:!0,initialPath:W.workspaceSession.cwd,description:u(`common:workspacePicker.selectWorkspaceForChat`,{name:W.workspaceSession.name}),onOpenChange:e=>!e&&W.setWorkspaceSession(null),onSelect:e=>W.switchSessionCwd(W.workspaceSession,e)})]})}export{pl as ChatPage};
|