pisper 0.6.2 → 0.6.3

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.
Files changed (65) hide show
  1. package/package.json +7 -7
  2. package/web/.vite/manifest.json +256 -256
  3. package/web/assets/{AppOverlays-D-yAp1vf.js → AppOverlays-CR5iJcP5.js} +1 -1
  4. package/web/assets/{AppShortcuts-CtNLVerh.js → AppShortcuts-BachmLQ3.js} +1 -1
  5. package/web/assets/{AssetsPage-DOzB9Wnk.js → AssetsPage-BltehMID.js} +1 -1
  6. package/web/assets/{ChannelsPage-DAPrpSTC.js → ChannelsPage-Tuw_qicj.js} +1 -1
  7. package/web/assets/{ChatAppearancePage-Q8jLnp7A.js → ChatAppearancePage-DME3PgDr.js} +2 -2
  8. package/web/assets/{ChatDockView-1fxZrR7W.js → ChatDockView-DoGtrBpY.js} +1 -1
  9. package/web/assets/{ChatHistoryPage-Bpyxsay_.js → ChatHistoryPage-DTXS6i3n.js} +1 -1
  10. package/web/assets/{ChatPage-CVOjCtOP.js → ChatPage-ibc_7olm.js} +3 -3
  11. package/web/assets/{ConfigPage-sVAdZytK.js → ConfigPage-CI6one5Y.js} +1 -1
  12. package/web/assets/{DecisionsPage-zq88dfkB.js → DecisionsPage-DOhLbIaD.js} +1 -1
  13. package/web/assets/{DesktopWindowControls-DYmSShHE.js → DesktopWindowControls-KmgemDO8.js} +1 -1
  14. package/web/assets/{FloatingWidgets-CFY30wFr.js → FloatingWidgets-Bs7ec6lW.js} +1 -1
  15. package/web/assets/{GitDiffViewer-BZV0A9mh.js → GitDiffViewer-xm2LnN9r.js} +1 -1
  16. package/web/assets/{MarkdownMessage-_VrT_sON.js → MarkdownMessage-H1336cMr.js} +1 -1
  17. package/web/assets/{McpPage-ROftSC8m.js → McpPage-Ck-7aLuZ.js} +1 -1
  18. package/web/assets/{MemoryPage-DkBjt-3Y.js → MemoryPage-BEdNJ3ot.js} +1 -1
  19. package/web/assets/{MobileContextScreen-BEss6aR9.js → MobileContextScreen-Dasny2J9.js} +2 -2
  20. package/web/assets/{MobileThreePane-DjyMuG9k.js → MobileThreePane-DEKMHPfN.js} +1 -1
  21. package/web/assets/{PageHeader-DyoCht8Y.js → PageHeader-C_bfu8Ir.js} +1 -1
  22. package/web/assets/{PluginsPage-DjaIps8G.js → PluginsPage-BPx5ERHL.js} +1 -1
  23. package/web/assets/{QuickPromptIdeas-B8P77vjW.js → QuickPromptIdeas-Bs-udcSZ.js} +1 -1
  24. package/web/assets/{SchedulesPage-CsJS8r9L.js → SchedulesPage-W4Mg7frl.js} +1 -1
  25. package/web/assets/{SessionContextPanel-BYlJfIxm.js → SessionContextPanel-lu9F9AJg.js} +1 -1
  26. package/web/assets/{SessionFilesPane-DWuwTplj.js → SessionFilesPane-BIRQ_hHi.js} +2 -2
  27. package/web/assets/{SidebarMoreTools-C2kAUJm0.js → SidebarMoreTools-BDqt5VTG.js} +1 -1
  28. package/web/assets/{SidebarRecentSessions-CoaY-U88.js → SidebarRecentSessions-1G_huYu9.js} +1 -1
  29. package/web/assets/{SidebarSettingsButton-BvmP3q5N.js → SidebarSettingsButton-B4_vEBS5.js} +1 -1
  30. package/web/assets/{SidebarUpdateStatus-DHxZy6-o.js → SidebarUpdateStatus-DD8f4Fxv.js} +1 -1
  31. package/web/assets/{SkillsPage-CX55drgE.js → SkillsPage-CpRRosmo.js} +1 -1
  32. package/web/assets/{TerminalPanel-gBBjaBlu.js → TerminalPanel-DVKC4htc.js} +1 -1
  33. package/web/assets/{ThemeToggleButton-D6NR_guG.js → ThemeToggleButton-CXXbLtcY.js} +1 -1
  34. package/web/assets/{WebDesktopPet-BKP_jSW2.js → WebDesktopPet-DWFspeZE.js} +1 -1
  35. package/web/assets/{WorkbenchSidebarToggle-Kxa_tpUy.js → WorkbenchSidebarToggle-AgjfcT29.js} +1 -1
  36. package/web/assets/{WorkflowsPage-CNVCHm3u.js → WorkflowsPage-bhQlHSzS.js} +1 -1
  37. package/web/assets/{api-BbC90EzT.js → api-Dzobr-o_.js} +1 -1
  38. package/web/assets/catalog-D4eaIju4.js +1 -0
  39. package/web/assets/{chat-api-BWIsQYmQ.js → chat-api-DfnvubiW.js} +1 -1
  40. package/web/assets/{client-store-CAjI7P8I.js → client-store-DPMvgPNS.js} +1 -1
  41. package/web/assets/{component-api-CQ_xu0Wa.js → component-api-Nwo2yGZI.js} +1 -1
  42. package/web/assets/{config-search-BnPZPrUR.js → config-search-CwVhh2uc.js} +1 -1
  43. package/web/assets/{events-DJwBfKGM.js → events-Bwv6HmwM.js} +1 -1
  44. package/web/assets/{floating-widgets-store-DGeXH0NK.js → floating-widgets-store-DIy4GSy4.js} +2 -2
  45. package/web/assets/{http-BrDjjNkv.js → http-DphgzWtw.js} +1 -1
  46. package/web/assets/{i18n-Bo7twSO7.js → i18n-7QvbQzOQ.js} +1 -1
  47. package/web/assets/{index-IemAtsU4.js → index-iBrSU61i.js} +2 -2
  48. package/web/assets/{local-path-reveal-BSjf-Pum.js → local-path-reveal-DWhkyox-.js} +1 -1
  49. package/web/assets/{mount-app-AtqeFC4t.js → mount-app-n_05p6iW.js} +3 -3
  50. package/web/assets/{pick-system-directory-Wa63igLM.js → pick-system-directory-R1F5WyaB.js} +1 -1
  51. package/web/assets/{public-CsBeGSro.js → public-BcTP7F3I.js} +1 -1
  52. package/web/assets/{public-components-BYWnKxmu.js → public-components-Ck5BYo6M.js} +1 -1
  53. package/web/assets/{runtime-capabilities-store-BxCUS5xR.js → runtime-capabilities-store-DaWPY5y-.js} +1 -1
  54. package/web/assets/{session-change-summary-api-x1sTdOgD.js → session-change-summary-api-DFgTzTci.js} +1 -1
  55. package/web/assets/{session-list-DPpH_zbz.js → session-list-CMaoK_ZX.js} +1 -1
  56. package/web/assets/{session-streaming-state-OU65zaiO.js → session-streaming-state-llCTupbI.js} +1 -1
  57. package/web/assets/{shortcuts-B3q7nKdq.js → shortcuts-BO-h6OmP.js} +1 -1
  58. package/web/assets/{speech-session-BB9aLyRQ.js → speech-session-DKjw0mV_.js} +1 -1
  59. package/web/assets/{startup-queries-C-Xq7N50.js → startup-queries-CAQZvUIR.js} +1 -1
  60. package/web/assets/{ui-store-3r51KJe8.js → ui-store-2wpnH8Kf.js} +1 -1
  61. package/web/assets/{use-i18n-DyzoXal-.js → use-i18n-BSZKFkMb.js} +1 -1
  62. package/web/assets/{useCustomUiComponents-B3Z-pphj.js → useCustomUiComponents-BH86kuaq.js} +1 -1
  63. package/web/assets/{web-preview-panel-DNEqdotS.js → web-preview-panel-DVQxVfig.js} +4 -4
  64. package/web/index.html +1 -1
  65. package/web/assets/catalog-BPgyo6Yf.js +0 -1
@@ -1,5 +1,5 @@
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-BB9aLyRQ.js","assets/api-BbC90EzT.js","assets/http-BrDjjNkv.js","assets/i18n-Bo7twSO7.js","assets/index-IemAtsU4.js","assets/index-CdASiNlI.css","assets/storage-BpAqa-YY.js","assets/ShinyText-DqxsUc3F.js","assets/utils-C8uzG5AZ.js","assets/react-bits-DQli9s7O.css","assets/QuickPromptIdeas-B8P77vjW.js","assets/use-i18n-DyzoXal-.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"])))=>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-IemAtsU4.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-Bo7twSO7.js";import{t as c}from"./use-i18n-DyzoXal-.js";import{a as l,i as u,o as d}from"./vendor-state-GkUciC5H.js";import"./storage-BpAqa-YY.js";import{t as f}from"./collapsible-C__hRcbA.js";import{t as p}from"./AppSelect-D149YYg1.js";import{a as m,i as h,n as g,o as _,t as v}from"./popover-BBuzaBfd.js";import{i as y,n as b,r as x,t as S}from"./progress-C_G6VqQ_.js";import{i as C,r as w,t as T}from"./tabs-DQYVDdOp.js";import{i as E,n as D,t as O}from"./tooltip-Bxq7c2mZ.js";import{t as k}from"./utils-C8uzG5AZ.js";import{t as A}from"./createLucideIcon-Cd-3GVxJ.js";import{n as j,t as M}from"./pin-Dc2zE4cS.js";import{t as N}from"./bot-B3TaBp_T.js";import{t as P}from"./check-2vYc6QaP.js";import{t as F}from"./chevron-down-CxtxIjiP.js";import{t as I}from"./chevron-left-BAtyp3_6.js";import{t as L}from"./chevron-right-C3t2Rckj.js";import{t as R}from"./circle-check-iEdCm3Pw.js";import{t as z}from"./circle-x-Ba4QL7Ec.js";import{t as ee}from"./ThemeToggleButton-D6NR_guG.js";import{t as B}from"./download-BCfIiuaL.js";import{t as te}from"./shield-alert-CvFOTe9h.js";import{t as V}from"./file-text-N9JICX6E.js";import{t as ne}from"./file-Bllajneu.js";import{t as re}from"./folder-open-FIShC5Qk.js";import{E as ie,T as H,d as ae,f as oe,g as se,i as ce,n as le,o as ue,p as de,r as fe,s as pe,t as U,v as me,w as he}from"./session-streaming-state-OU65zaiO.js";import{t as ge}from"./loader-circle-BOwQzHB-.js";import{t as _e}from"./message-square-SKjZyY3v.js";import{t as ve}from"./WorkbenchSidebarToggle-Kxa_tpUy.js";import{t as ye}from"./paperclip-BCXrwYpb.js";import{t as be}from"./pencil-U08v_vV9.js";import{t as xe}from"./play-DNDjDNGn.js";import{t as Se}from"./plus-fQbSqB1n.js";import{t as Ce}from"./refresh-cw-TbWxTY4K.js";import{t as we}from"./rotate-ccw-C0v8V77_.js";import{t as Te}from"./search-D0mqDaf_.js";import{t as Ee}from"./settings-2-CXJjXJS9.js";import{t as De}from"./settings-QX0oWnVK.js";import{t as Oe}from"./sliders-horizontal-Dryf1XyC.js";import{t as ke}from"./square-terminal-BVG6cUT1.js";import{t as Ae}from"./square-bHHVTT3G.js";import{t as je}from"./tag-CqkeJlBf.js";import{t as Me}from"./trash-2-CNrPOoPR.js";import{t as Ne}from"./triangle-alert-CE1q54ci.js";import{t as Pe}from"./undo-2-CJE_nRTk.js";import{t as Fe}from"./workflow-Bg94dy8I.js";import{t as Ie}from"./wrench-6pg6_bqI.js";import{t as Le}from"./x-07u4-129.js";import{r as Re}from"./use-mobile-YXncArOq.js";import{r as ze}from"./http-BrDjjNkv.js";import{n as Be,r as W,t as Ve}from"./abort-signal-f4JsiYKX.js";import{t as G}from"./api-BbC90EzT.js";import{n as He}from"./client-store-CAjI7P8I.js";import{t as K}from"./button-CQA36izu.js";import{t as Ue}from"./useQuery-DdcpUQhO.js";import{t as q}from"./chat-api-BWIsQYmQ.js";import{c as We,i as Ge,n as Ke,o as qe,r as Je,s as Ye,t as Xe}from"./dialog-D-ER2p-D.js";import{t as Ze}from"./input-CvjGYteF.js";import{i as Qe,n as J,t as $e}from"./format-BRFKAYMT.js";import{n as et,t as tt}from"./app-primitives-BBXY6U2S.js";import{i as nt,o as rt,r as it,s as at,t as ot}from"./shortcuts-B3q7nKdq.js";import{r as st}from"./ui-store-3r51KJe8.js";import{T as ct,f as lt,m as ut}from"./events-DJwBfKGM.js";import{i as dt,t as ft}from"./runtime-capabilities-store-BxCUS5xR.js";import{i as pt,r as mt}from"./tool-labels-DJzY62Yr.js";import{r as ht}from"./GitDiffViewer-BZV0A9mh.js";import{a as gt,c as _t,i as vt,l as yt,n as bt,o as xt,s as St,t as Ct,u as wt}from"./speech-session-BB9aLyRQ.js";var Tt=A(`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`}]]),Et=A(`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`}]]),Dt=A(`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`}]]),Ot=A(`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`}]]),kt=A(`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`}]]),At=A(`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`}]]),jt=A(`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`}]]),Y=A(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),X=A(`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`}]]),Mt=A(`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`}]]),Nt=A(`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`}]]),Pt=A(`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`}]]),Ft=A(`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`}]]),It=A(`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`}]]),Lt=A(`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`}]]),Rt=A(`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`}]]),zt=A(`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`}]]),Z=e(r(),1),Q=a();function Bt({label:e,menu:t=!1,children:n,className:r,...i}){return(0,Q.jsxs)(K,{type:`button`,variant:`ghost`,size:t?`default`:`icon`,"aria-label":e,title:e,...i,className:k(`relative shrink-0 rounded-lg font-normal text-foreground [&>svg]:size-4`,t?`h-10 w-full justify-start gap-3 px-3 text-sm max-sm:h-11`:`size-9 bg-transparent`,r),children:[n,t&&(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left`,children:e})]})}var Vt=10485760,Ht=20971520,Ut=new Set([`txt`,`md`,`json`,`js`,`jsx`,`ts`,`tsx`,`css`,`html`,`xml`,`yaml`,`yml`,`csv`,`log`,`py`,`java`,`go`,`rs`,`sh`,`ps1`,`toml`,`sql`]),Wt=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`svg`]),Gt=new Set([`pdf`,`docx`,`pptx`,`xlsx`,`odt`,`odp`,`ods`,`rtf`,`epub`]),Kt=[`image/*`,`text/*`,`application/json`,...[...Wt,...Ut,...Gt].map(e=>`.${e}`)].join(`,`);function qt(e){let t=[...e?.files||[]];return t.length?t:[...e?.items||[]].filter(e=>e.kind===`file`).map(e=>e.getAsFile?.()).filter(e=>!!e)}function Jt(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 Yt(e){return e.toLowerCase().split(`.`).at(-1)||``}async function Xt(e,t){let n=[...e].slice(0,8),r=[];for(let e of n){if(e.size>Vt)throw Error(t(`chat:attachments.nameExceedsThe10MBLimit`,{name:e.name}));let n=Yt(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/`)||Wt.has(n))r.push({...i,kind:`image`,data:await Jt(e,t)});else if(e.type.startsWith(`text/`)||e.type===`application/json`||Ut.has(n))r.push({...i,kind:`text`,text:await e.text()});else if(Gt.has(n))r.push({...i,kind:`document`,extension:n,data:await Jt(e,t)});else throw Error(t(`chat:attachments.nameIsNotSupportedChooseAnImageOrTextCodeFile`,{name:e.name}))}return r}function Zt(e){return e.split(/[\\/]/).filter(Boolean).at(-1)||e}function Qt(e){return[...e].map(e=>String(e||``).trim()).filter(Boolean).slice(0,8).map(e=>({id:`path:${e}`,kind:`path`,name:Zt(e),path:e}))}function $t(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 Xt(e||[],n),r=[...l.current,...t].slice(0,8);if(r.filter(e=>e.kind!==`path`).reduce((e,t)=>e+(t.size||0),0)>Ht)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=qt(e.clipboardData);t.length&&(e.preventDefault(),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 en({cwd:e,selection:t,menu:n=!1}){let{t:r}=c(),i=He(),[a,o]=(0,Z.useState)(!1),s=(0,Z.useRef)(!1),l=(0,Z.useRef)(null),u=async()=>{if(i||!window.pisperDesktop?.pickFiles){l.current?.click();return}if(!s.current&&(s.current=!0,o(!0),window.pisperDesktop?.pickFiles)){try{let n=await window.pisperDesktop.pickFiles(e);t.addAttachments(Qt(n||[]))}catch(e){t.setError(e)}finally{s.current=!1,o(!1)}return}};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`input`,{ref:l,type:`file`,className:`hidden`,accept:Kt,multiple:!0,"aria-label":r(`chat:focusSession.addAttachment`),onChange:e=>{let n=[...e.currentTarget.files||[]];e.currentTarget.value=``,n.length&&t.addFiles(n)}}),(0,Q.jsxs)(Bt,{menu:n,label:r(`chat:focusSession.addAttachment`),className:`attach-trigger`,disabled:a,onClick:()=>void u(),children:[(0,Q.jsx)(ye,{size:17}),t.attachments.length>0&&(0,Q.jsx)(`span`,{className:`absolute -right-1 -top-1 grid min-w-4 place-items-center rounded-full bg-primary px-1 text-[10px] text-primary-foreground`,children:t.attachments.length})]})]})}function tn({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)(ne,{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`?``:` · ${$e(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)(Le,{size:12})})]},e.id))}):null}function nn({open:e,sessionId:t,onClose:n,onSelect:r,onCommandSelect:i}){let{t:a}=c(),o=ft(e=>e.capabilities),s=dt(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)({}),[b,x]=(0,Z.useState)(!1),[S,E]=(0,Z.useState)(``);(0,Z.useEffect)(()=>{if(!e)return;let n=!0;return f(`all`),m(``),g(null),v({}),x(!0),E(``),Promise.all([q.getSessionCommands(t),s?G(`/api/workflows`):Promise.resolve({workflows:[]}),G(`/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?pt(t,a):String(t.label||t.name),description:t.id?mt(t,a):t.description,inputs:[],sourceName:e.name})))])}).catch(e=>{n&&(u([]),E(e instanceof Error?e.message:String(e)))}).finally(()=>n&&x(!1)),()=>{n=!1}},[e,t,a,s]);let D=(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]),O=(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]),k=e=>{let t=e;f(t),h&&t!==`all`&&h.kind!==t&&g(null)},A=e=>{g(e),v(Object.fromEntries(e.inputs.map(e=>[e.name,e.defaultValue??``])))};return(0,Q.jsx)(Xe,{open:e,onOpenChange:e=>!e&&n(),children:(0,Q.jsxs)(Je,{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)(Ye,{children:a(`chat:resourcePicker.title`)}),(0,Q.jsx)(Ge,{children:a(`chat:resourcePicker.description`)})]}),(0,Q.jsx)(K,{size:`icon-sm`,variant:`ghost`,"aria-label":a(`chat:resourcePicker.close`),onClick:n,children:(0,Q.jsx)(Le,{})})]}),(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)(T,{value:d,onValueChange:k,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)(w,{"aria-label":a(`chat:resourcePicker.categories`),children:[(0,Q.jsxs)(C,{value:`all`,children:[a(`chat:resourcePicker.all`),(0,Q.jsx)(`small`,{children:D.all})]}),(0,Q.jsxs)(C,{value:`prompt`,children:[a(`chat:resourcePicker.prompt`),(0,Q.jsx)(`small`,{children:D.prompt})]}),(0,Q.jsxs)(C,{value:`skill`,children:[a(`chat:resourcePicker.skill`),(0,Q.jsx)(`small`,{children:D.skill})]}),(0,Q.jsxs)(C,{value:`tool`,children:[a(`chat:resourcePicker.tool`),(0,Q.jsx)(`small`,{children:D.tool})]}),s&&(0,Q.jsxs)(C,{value:`workflow`,children:[a(`chat:resourcePicker.workflow`),(0,Q.jsx)(`small`,{children:D.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)(Te,{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:[O.map(e=>{let t=e.kind===`prompt`?V:e.kind===`skill`?y:e.kind===`tool`?Ie:Fe;return(0,Q.jsxs)(`button`,{type:`button`,className:h?.kind===e.kind&&h.id===e.id?`active`:``,onClick:()=>A(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}`)}),!O.length&&(0,Q.jsx)(`p`,{children:b?a(`chat:resourcePicker.loading`):S||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)(Ze,{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)(K,{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 rn=64,an=new Map;function on(e,t){let n=t.match(/^\/[^\s]*(?:\s+([\s\S]*))?$/),r=(n?n[1]||``:t).trim();return`${e}${r?` ${r}`:` `}`}function sn(e){return{text:e?.text||``,attachments:[...e?.attachments||[]]}}function cn(e){return sn(an.get(e))}function ln(e,t){if(!e)return;let n={...cn(e),...t};if(n.attachments=[...n.attachments],an.delete(e),!(!n.text&&!n.attachments.length))for(an.set(e,n);an.size>rn;){let e=an.keys().next().value;if(typeof e!=`string`)break;an.delete(e)}}function un(e){an.delete(e)}function dn(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 fn(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)(cn(e)),[i,a]=(0,Z.useState)(r.current.text),o=(0,Z.useCallback)(t=>ln(e,{attachments:t}),[e]),s=$t(r.current.attachments,o),c=s.replaceAttachments,l=s.clearAttachments;return(0,Z.useEffect)(()=>{let t=cn(e);a(t.text),c(t.attachments)},[c,e]),{value:i,updateValue:(0,Z.useCallback)(t=>{a(t),ln(e,{text:t})},[e]),selection:s,clearDraft:(0,Z.useCallback)(()=>{let r=cn(e);r.text!==i||r.attachments.length!==s.attachments.length||r.attachments.some((e,t)=>e!==s.attachments[t])||(un(e),!(!n.current||t.current!==e)&&(a(``),l()))},[l,s.attachments,e,i]),restoreDraft:(0,Z.useCallback)(r=>{let i=dn(cn(e),r);return ln(e,i),!n.current||t.current!==e?!1:(a(i.text),c(i.attachments),!0)},[c,e])}}var pn=e(i(),1);function mn({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 hn({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=mn({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,pn.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 gn({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),[b,x]=(0,Z.useState)(0),S=!!(u&&d!==t),C=u?.[1]||``;(0,Z.useEffect)(()=>{f(``),m(null),v(!1)},[e]),(0,Z.useEffect)(()=>{if(!S||p)return;let t=!0;return g(!0),v(!1),q.getSessionCommands(e).then(e=>{t&&m(e.commands||[])}).catch(()=>{t&&(m([]),v(!0))}).finally(()=>t&&g(!1)),()=>{t=!1}},[p,S,e]);let w=(0,Z.useMemo)(()=>{let e=C.toLocaleLowerCase(o);return e?(p||[]).filter(t=>`${t.invocation} ${t.name} ${t.description}`.toLocaleLowerCase(o).includes(e)):p||[]},[p,o,C]);(0,Z.useEffect)(()=>{x(0)},[C,p]);let T=()=>{f(t)},E=e=>{let i=on(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(!S)return;let e=e=>{if(document.activeElement===r.current){if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),T();return}w.length&&(e.key===`ArrowDown`?(e.preventDefault(),e.stopPropagation(),x(e=>(e+1)%w.length)):e.key===`ArrowUp`?(e.preventDefault(),e.stopPropagation(),x(e=>(e-1+w.length)%w.length)):(e.key===`Tab`||e.key===`Enter`&&!e.shiftKey)&&(e.preventDefault(),e.stopPropagation(),E(w[Math.min(b,w.length-1)])))}};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)}),(0,Z.useEffect)(()=>{let e=r.current;if(!S||!e)return;let t={role:`combobox`,"aria-autocomplete":`list`,"aria-expanded":`true`,"aria-controls":s,"aria-activedescendant":w.length?`${s}-${Math.min(b,w.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))}},[b,r,s,S,w.length]);let D={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)(hn,{open:S,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:[w.map((e,t)=>{let n=e.source===`prompt`?V:y;return(0,Q.jsxs)(`button`,{type:`button`,role:`option`,id:`${s}-${t}`,"aria-selected":t===b,className:t===b?`active`:``,onMouseEnter:()=>x(t),onMouseDown:e=>e.preventDefault(),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)(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`),` · `,D[e.scope]]})]},e.invocation)}),!w.length&&(0,Q.jsx)(`p`,{children:a(h?`chat:commands.loading`:_?`chat:commands.loadError`:`chat:commands.empty`)})]})})}var _n=[`attachment`,`resource`,`visual`,`model`,`permission`,`run-mode`,`commands`,`compact-context`],vn=new Set(_n),yn=new Set([`model`,`permission`,`run-mode`]),bn={inline:[`permission`,`run-mode`,`model`],overflow:_n.filter(e=>![`permission`,`run-mode`,`model`].includes(e))};function xn(e){return Array.isArray(e)?e.filter((e,t,n)=>typeof e==`string`&&vn.has(e)&&n.indexOf(e)===t):[]}function $(e){let t=e&&typeof e==`object`?e:{};if(!Array.isArray(t.inline)&&!Array.isArray(t.overflow))return{inline:[...bn.inline],overflow:[...bn.overflow]};let n=xn(t.inline),r=new Set(n),i=xn(t.overflow).filter(e=>!r.has(e)),a=new Set([...n,...i]);for(let e of _n)a.has(e)||(yn.has(e)?n.push(e):i.push(e));return{inline:n,overflow:i}}function Sn(e,t,n){let r=$(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 Cn(e,t){let n=$(e),r=[...n.inline,...n.overflow];return t===`inline`?{inline:r,overflow:[]}:{inline:[],overflow:r}}function wn(e,t,n){let r=$(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 Tn(e,t,n,r={}){let i=$(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 En({open:e,children:t,label:n,trayId:r,anchorRef:i,menuRef:a,placement:o=`top`}){return(0,Q.jsx)(hn,{open:e,anchorRef:i,menuRef:a,placement:o,align:`start`,className:`composer-tool-tray-shell w-[248px] 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-0.5 [&>.composer-toolbar-slot]:w-full overflow-x-hidden overflow-y-auto overscroll-contain`,children:t})})}var Dn=`pisper-zcode-composer-toolbar`,On=u(()=>({getItem:e=>{let t=n.getItem(e);if(t!==null)return t;let r=n.getItem(Dn);if(r===null)return null;try{return JSON.parse(r),n.setItem(e,r),n.removeItem(Dn),r}catch{return null}},setItem:(e,t)=>n.setItem(e,t),removeItem:e=>n.removeItem(e)})),kn=d()(l(e=>({layout:$(void 0),setToolLocation:(t,n)=>e(e=>({layout:Sn(e.layout,t,n)})),setAllToolsLocation:t=>e(e=>({layout:Cn(e.layout,t)})),moveTool:(t,n)=>e(e=>({layout:wn(e.layout,t,n)})),resetLayout:()=>e({layout:$(void 0)})}),{name:`pisper-composer-toolbar`,storage:On,version:1,partialize:({layout:e})=>({layout:e}),merge:(e,t)=>({...t,layout:$(e&&typeof e==`object`&&`layout`in e?e.layout:void 0)})}));function An(e,t){return e.inline.join(`\0`)===t.inline.join(`\0`)&&e.overflow.join(`\0`)===t.overflow.join(`\0`)}function jn({ids:e,location:t,labels:n,onMove:r,onReorder:i,onMoveButtonRef:a}){let{t:o}=c(),s=t===`inline`?`overflow`:`inline`,l=t===`inline`?j:M,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)(K,{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)(m,{})}),(0,Q.jsx)(K,{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)(_,{})}),(0,Q.jsxs)(K,{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 Mn({labels:e,labeled:t=!1}){let{t:n}=c(),r=kn(e=>e.layout),i=kn(e=>e.setToolLocation),a=kn(e=>e.setAllToolsLocation),o=kn(e=>e.moveTool),s=kn(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)(Xe,{children:[(0,Q.jsx)(We,{asChild:!0,children:(0,Q.jsx)(Bt,{menu:t,label:n(`chat:focusSession.customizeShortcuts`),children:(0,Q.jsx)(Ee,{})})}),(0,Q.jsxs)(Je,{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)(qe,{className:`min-w-0 flex-1 gap-2 pt-1`,children:[(0,Q.jsx)(Ye,{children:n(`chat:focusSession.customizeShortcuts`)}),(0,Q.jsx)(Ge,{className:`text-xs leading-5`,children:n(`chat:focusSession.customizeShortcutsDescription`)})]}),(0,Q.jsx)(Ke,{asChild:!0,children:(0,Q.jsx)(K,{type:`button`,variant:`ghost`,size:`icon-sm`,className:`size-11`,"aria-label":n(`common:ui.closeDialog`),children:(0,Q.jsx)(Le,{})})})]}),(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)(M,{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)(jn,{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)(j,{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)(jn,{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)(K,{type:`button`,variant:`ghost`,size:`sm`,className:`h-11 text-xs`,disabled:r.overflow.length===0,onClick:()=>a(`inline`),children:[(0,Q.jsx)(M,{}),n(`chat:focusSession.showAllShortcuts`)]}),(0,Q.jsxs)(K,{type:`button`,variant:`ghost`,size:`sm`,className:`h-11 text-xs`,disabled:r.inline.length===0,onClick:()=>a(`overflow`),children:[(0,Q.jsx)(j,{}),n(`chat:focusSession.storeAllShortcuts`)]}),(0,Q.jsxs)(K,{type:`button`,variant:`ghost`,size:`sm`,className:`ml-auto h-11 text-xs text-[var(--text-muted)]`,disabled:An(r,bn),onClick:s,children:[(0,Q.jsx)(we,{}),n(`chat:focusSession.restoreShortcutDefaults`)]})]})]})]})}function Nn(e,t){let n=t.find(t=>t.key===e);return n?`${n.providerName} · ${n.label}`:e.split(`/`).at(-1)||e}function Pn({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?Nn(e,t||[]):`—`],[i(`chat:focusSession.statContextTokens`),f==null?`—`:`${J(f)} / ${J(r?.contextWindow)}`],[i(`chat:focusSession.statInputTokens`),J(n?.input)],[i(`chat:focusSession.statOutputTokens`),J(n?.output)],[i(`chat:focusSession.statCacheReadTokens`),p?J(n?.cacheRead):`—`],[i(`chat:focusSession.statCacheWriteTokens`),p?J(n?.cacheWrite):`—`],[i(`chat:focusSession.statReasoningTokens`),J(n?.reasoning)],[i(`chat:focusSession.statProcessedTokens`),J(n?.processedTokens)],[i(`chat:focusSession.statRequests`),String(Math.max(0,Number(n?.requests)||0))],[i(`chat:focusSession.statAvgFirstToken`),u==null?`—`:pe(u,a)],[i(`chat:focusSession.statAvgDuration`),d==null?`—`:pe(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 Fn({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:J(i),input:J(e?.input),output:J(e?.output),cacheRead:J(e?.cacheRead),cacheWrite:J(e?.cacheWrite),reasoning:J(e?.reasoning),requests:Math.max(0,Number(e?.requests)||0)}),f,s].filter(Boolean).join(`
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-DKjw0mV_.js","assets/api-Dzobr-o_.js","assets/http-DphgzWtw.js","assets/i18n-7QvbQzOQ.js","assets/index-iBrSU61i.js","assets/index-CdASiNlI.css","assets/storage-BpAqa-YY.js","assets/ShinyText-DqxsUc3F.js","assets/utils-C8uzG5AZ.js","assets/react-bits-DQli9s7O.css","assets/QuickPromptIdeas-Bs-udcSZ.js","assets/use-i18n-BSZKFkMb.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"])))=>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-iBrSU61i.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-7QvbQzOQ.js";import{t as c}from"./use-i18n-BSZKFkMb.js";import{a as l,i as u,o as d}from"./vendor-state-GkUciC5H.js";import"./storage-BpAqa-YY.js";import{t as f}from"./collapsible-C__hRcbA.js";import{t as p}from"./AppSelect-D149YYg1.js";import{a as m,i as h,n as g,o as _,t as v}from"./popover-BBuzaBfd.js";import{i as y,n as b,r as x,t as S}from"./progress-C_G6VqQ_.js";import{i as C,r as w,t as T}from"./tabs-DQYVDdOp.js";import{i as E,n as D,t as O}from"./tooltip-Bxq7c2mZ.js";import{t as k}from"./utils-C8uzG5AZ.js";import{t as A}from"./createLucideIcon-Cd-3GVxJ.js";import{n as j,t as M}from"./pin-Dc2zE4cS.js";import{t as N}from"./bot-B3TaBp_T.js";import{t as P}from"./check-2vYc6QaP.js";import{t as F}from"./chevron-down-CxtxIjiP.js";import{t as I}from"./chevron-left-BAtyp3_6.js";import{t as L}from"./chevron-right-C3t2Rckj.js";import{t as R}from"./circle-check-iEdCm3Pw.js";import{t as z}from"./circle-x-Ba4QL7Ec.js";import{t as ee}from"./ThemeToggleButton-CXXbLtcY.js";import{t as B}from"./download-BCfIiuaL.js";import{t as te}from"./shield-alert-CvFOTe9h.js";import{t as V}from"./file-text-N9JICX6E.js";import{t as ne}from"./file-Bllajneu.js";import{t as re}from"./folder-open-FIShC5Qk.js";import{E as ie,T as H,d as ae,f as oe,g as se,i as ce,n as le,o as ue,p as de,r as fe,s as pe,t as U,v as me,w as he}from"./session-streaming-state-llCTupbI.js";import{t as ge}from"./loader-circle-BOwQzHB-.js";import{t as _e}from"./message-square-SKjZyY3v.js";import{t as ve}from"./WorkbenchSidebarToggle-AgjfcT29.js";import{t as ye}from"./paperclip-BCXrwYpb.js";import{t as be}from"./pencil-U08v_vV9.js";import{t as xe}from"./play-DNDjDNGn.js";import{t as Se}from"./plus-fQbSqB1n.js";import{t as Ce}from"./refresh-cw-TbWxTY4K.js";import{t as we}from"./rotate-ccw-C0v8V77_.js";import{t as Te}from"./search-D0mqDaf_.js";import{t as Ee}from"./settings-2-CXJjXJS9.js";import{t as De}from"./settings-QX0oWnVK.js";import{t as Oe}from"./sliders-horizontal-Dryf1XyC.js";import{t as ke}from"./square-terminal-BVG6cUT1.js";import{t as Ae}from"./square-bHHVTT3G.js";import{t as je}from"./tag-CqkeJlBf.js";import{t as Me}from"./trash-2-CNrPOoPR.js";import{t as Ne}from"./triangle-alert-CE1q54ci.js";import{t as Pe}from"./undo-2-CJE_nRTk.js";import{t as Fe}from"./workflow-Bg94dy8I.js";import{t as Ie}from"./wrench-6pg6_bqI.js";import{t as Le}from"./x-07u4-129.js";import{r as Re}from"./use-mobile-YXncArOq.js";import{r as ze}from"./http-DphgzWtw.js";import{n as Be,r as W,t as Ve}from"./abort-signal-f4JsiYKX.js";import{t as G}from"./api-Dzobr-o_.js";import{n as He}from"./client-store-DPMvgPNS.js";import{t as K}from"./button-CQA36izu.js";import{t as Ue}from"./useQuery-DdcpUQhO.js";import{t as q}from"./chat-api-DfnvubiW.js";import{c as We,i as Ge,n as Ke,o as qe,r as Je,s as Ye,t as Xe}from"./dialog-D-ER2p-D.js";import{t as Ze}from"./input-CvjGYteF.js";import{i as Qe,n as J,t as $e}from"./format-BRFKAYMT.js";import{n as et,t as tt}from"./app-primitives-BBXY6U2S.js";import{i as nt,o as rt,r as it,s as at,t as ot}from"./shortcuts-BO-h6OmP.js";import{r as st}from"./ui-store-2wpnH8Kf.js";import{T as ct,f as lt,m as ut}from"./events-Bwv6HmwM.js";import{i as dt,t as ft}from"./runtime-capabilities-store-DaWPY5y-.js";import{i as pt,r as mt}from"./tool-labels-DJzY62Yr.js";import{r as ht}from"./GitDiffViewer-xm2LnN9r.js";import{a as gt,c as _t,i as vt,l as yt,n as bt,o as xt,s as St,t as Ct,u as wt}from"./speech-session-DKjw0mV_.js";var Tt=A(`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`}]]),Et=A(`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`}]]),Dt=A(`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`}]]),Ot=A(`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`}]]),kt=A(`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`}]]),At=A(`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`}]]),jt=A(`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`}]]),Y=A(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),X=A(`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`}]]),Mt=A(`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`}]]),Nt=A(`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`}]]),Pt=A(`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`}]]),Ft=A(`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`}]]),It=A(`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`}]]),Lt=A(`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`}]]),Rt=A(`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`}]]),zt=A(`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`}]]),Z=e(r(),1),Q=a();function Bt({label:e,menu:t=!1,children:n,className:r,...i}){return(0,Q.jsxs)(K,{type:`button`,variant:`ghost`,size:t?`default`:`icon`,"aria-label":e,title:e,...i,className:k(`relative shrink-0 rounded-lg font-normal text-foreground [&>svg]:size-4`,t?`h-10 w-full justify-start gap-3 px-3 text-sm max-sm:h-11`:`size-9 bg-transparent`,r),children:[n,t&&(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left`,children:e})]})}var Vt=10485760,Ht=20971520,Ut=new Set([`txt`,`md`,`json`,`js`,`jsx`,`ts`,`tsx`,`css`,`html`,`xml`,`yaml`,`yml`,`csv`,`log`,`py`,`java`,`go`,`rs`,`sh`,`ps1`,`toml`,`sql`]),Wt=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`svg`]),Gt=new Set([`pdf`,`docx`,`pptx`,`xlsx`,`odt`,`odp`,`ods`,`rtf`,`epub`]),Kt=[`image/*`,`text/*`,`application/json`,...[...Wt,...Ut,...Gt].map(e=>`.${e}`)].join(`,`);function qt(e){let t=[...e?.files||[]];return t.length?t:[...e?.items||[]].filter(e=>e.kind===`file`).map(e=>e.getAsFile?.()).filter(e=>!!e)}function Jt(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 Yt(e){return e.toLowerCase().split(`.`).at(-1)||``}async function Xt(e,t){let n=[...e].slice(0,8),r=[];for(let e of n){if(e.size>Vt)throw Error(t(`chat:attachments.nameExceedsThe10MBLimit`,{name:e.name}));let n=Yt(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/`)||Wt.has(n))r.push({...i,kind:`image`,data:await Jt(e,t)});else if(e.type.startsWith(`text/`)||e.type===`application/json`||Ut.has(n))r.push({...i,kind:`text`,text:await e.text()});else if(Gt.has(n))r.push({...i,kind:`document`,extension:n,data:await Jt(e,t)});else throw Error(t(`chat:attachments.nameIsNotSupportedChooseAnImageOrTextCodeFile`,{name:e.name}))}return r}function Zt(e){return e.split(/[\\/]/).filter(Boolean).at(-1)||e}function Qt(e){return[...e].map(e=>String(e||``).trim()).filter(Boolean).slice(0,8).map(e=>({id:`path:${e}`,kind:`path`,name:Zt(e),path:e}))}function $t(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 Xt(e||[],n),r=[...l.current,...t].slice(0,8);if(r.filter(e=>e.kind!==`path`).reduce((e,t)=>e+(t.size||0),0)>Ht)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=qt(e.clipboardData);t.length&&(e.preventDefault(),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 en({cwd:e,selection:t,menu:n=!1}){let{t:r}=c(),i=He(),[a,o]=(0,Z.useState)(!1),s=(0,Z.useRef)(!1),l=(0,Z.useRef)(null),u=async()=>{if(i||!window.pisperDesktop?.pickFiles){l.current?.click();return}if(!s.current&&(s.current=!0,o(!0),window.pisperDesktop?.pickFiles)){try{let n=await window.pisperDesktop.pickFiles(e);t.addAttachments(Qt(n||[]))}catch(e){t.setError(e)}finally{s.current=!1,o(!1)}return}};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`input`,{ref:l,type:`file`,className:`hidden`,accept:Kt,multiple:!0,"aria-label":r(`chat:focusSession.addAttachment`),onChange:e=>{let n=[...e.currentTarget.files||[]];e.currentTarget.value=``,n.length&&t.addFiles(n)}}),(0,Q.jsxs)(Bt,{menu:n,label:r(`chat:focusSession.addAttachment`),className:`attach-trigger`,disabled:a,onClick:()=>void u(),children:[(0,Q.jsx)(ye,{size:17}),t.attachments.length>0&&(0,Q.jsx)(`span`,{className:`absolute -right-1 -top-1 grid min-w-4 place-items-center rounded-full bg-primary px-1 text-[10px] text-primary-foreground`,children:t.attachments.length})]})]})}function tn({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)(ne,{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`?``:` · ${$e(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)(Le,{size:12})})]},e.id))}):null}function nn({open:e,sessionId:t,onClose:n,onSelect:r,onCommandSelect:i}){let{t:a}=c(),o=ft(e=>e.capabilities),s=dt(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)({}),[b,x]=(0,Z.useState)(!1),[S,E]=(0,Z.useState)(``);(0,Z.useEffect)(()=>{if(!e)return;let n=!0;return f(`all`),m(``),g(null),v({}),x(!0),E(``),Promise.all([q.getSessionCommands(t),s?G(`/api/workflows`):Promise.resolve({workflows:[]}),G(`/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?pt(t,a):String(t.label||t.name),description:t.id?mt(t,a):t.description,inputs:[],sourceName:e.name})))])}).catch(e=>{n&&(u([]),E(e instanceof Error?e.message:String(e)))}).finally(()=>n&&x(!1)),()=>{n=!1}},[e,t,a,s]);let D=(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]),O=(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]),k=e=>{let t=e;f(t),h&&t!==`all`&&h.kind!==t&&g(null)},A=e=>{g(e),v(Object.fromEntries(e.inputs.map(e=>[e.name,e.defaultValue??``])))};return(0,Q.jsx)(Xe,{open:e,onOpenChange:e=>!e&&n(),children:(0,Q.jsxs)(Je,{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)(Ye,{children:a(`chat:resourcePicker.title`)}),(0,Q.jsx)(Ge,{children:a(`chat:resourcePicker.description`)})]}),(0,Q.jsx)(K,{size:`icon-sm`,variant:`ghost`,"aria-label":a(`chat:resourcePicker.close`),onClick:n,children:(0,Q.jsx)(Le,{})})]}),(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)(T,{value:d,onValueChange:k,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)(w,{"aria-label":a(`chat:resourcePicker.categories`),children:[(0,Q.jsxs)(C,{value:`all`,children:[a(`chat:resourcePicker.all`),(0,Q.jsx)(`small`,{children:D.all})]}),(0,Q.jsxs)(C,{value:`prompt`,children:[a(`chat:resourcePicker.prompt`),(0,Q.jsx)(`small`,{children:D.prompt})]}),(0,Q.jsxs)(C,{value:`skill`,children:[a(`chat:resourcePicker.skill`),(0,Q.jsx)(`small`,{children:D.skill})]}),(0,Q.jsxs)(C,{value:`tool`,children:[a(`chat:resourcePicker.tool`),(0,Q.jsx)(`small`,{children:D.tool})]}),s&&(0,Q.jsxs)(C,{value:`workflow`,children:[a(`chat:resourcePicker.workflow`),(0,Q.jsx)(`small`,{children:D.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)(Te,{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:[O.map(e=>{let t=e.kind===`prompt`?V:e.kind===`skill`?y:e.kind===`tool`?Ie:Fe;return(0,Q.jsxs)(`button`,{type:`button`,className:h?.kind===e.kind&&h.id===e.id?`active`:``,onClick:()=>A(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}`)}),!O.length&&(0,Q.jsx)(`p`,{children:b?a(`chat:resourcePicker.loading`):S||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)(Ze,{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)(K,{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 rn=64,an=new Map;function on(e,t){let n=t.match(/^\/[^\s]*(?:\s+([\s\S]*))?$/),r=(n?n[1]||``:t).trim();return`${e}${r?` ${r}`:` `}`}function sn(e){return{text:e?.text||``,attachments:[...e?.attachments||[]]}}function cn(e){return sn(an.get(e))}function ln(e,t){if(!e)return;let n={...cn(e),...t};if(n.attachments=[...n.attachments],an.delete(e),!(!n.text&&!n.attachments.length))for(an.set(e,n);an.size>rn;){let e=an.keys().next().value;if(typeof e!=`string`)break;an.delete(e)}}function un(e){an.delete(e)}function dn(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 fn(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)(cn(e)),[i,a]=(0,Z.useState)(r.current.text),o=(0,Z.useCallback)(t=>ln(e,{attachments:t}),[e]),s=$t(r.current.attachments,o),c=s.replaceAttachments,l=s.clearAttachments;return(0,Z.useEffect)(()=>{let t=cn(e);a(t.text),c(t.attachments)},[c,e]),{value:i,updateValue:(0,Z.useCallback)(t=>{a(t),ln(e,{text:t})},[e]),selection:s,clearDraft:(0,Z.useCallback)(()=>{let r=cn(e);r.text!==i||r.attachments.length!==s.attachments.length||r.attachments.some((e,t)=>e!==s.attachments[t])||(un(e),!(!n.current||t.current!==e)&&(a(``),l()))},[l,s.attachments,e,i]),restoreDraft:(0,Z.useCallback)(r=>{let i=dn(cn(e),r);return ln(e,i),!n.current||t.current!==e?!1:(a(i.text),c(i.attachments),!0)},[c,e])}}var pn=e(i(),1);function mn({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 hn({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=mn({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,pn.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 gn({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),[b,x]=(0,Z.useState)(0),S=!!(u&&d!==t),C=u?.[1]||``;(0,Z.useEffect)(()=>{f(``),m(null),v(!1)},[e]),(0,Z.useEffect)(()=>{if(!S||p)return;let t=!0;return g(!0),v(!1),q.getSessionCommands(e).then(e=>{t&&m(e.commands||[])}).catch(()=>{t&&(m([]),v(!0))}).finally(()=>t&&g(!1)),()=>{t=!1}},[p,S,e]);let w=(0,Z.useMemo)(()=>{let e=C.toLocaleLowerCase(o);return e?(p||[]).filter(t=>`${t.invocation} ${t.name} ${t.description}`.toLocaleLowerCase(o).includes(e)):p||[]},[p,o,C]);(0,Z.useEffect)(()=>{x(0)},[C,p]);let T=()=>{f(t)},E=e=>{let i=on(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(!S)return;let e=e=>{if(document.activeElement===r.current){if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),T();return}w.length&&(e.key===`ArrowDown`?(e.preventDefault(),e.stopPropagation(),x(e=>(e+1)%w.length)):e.key===`ArrowUp`?(e.preventDefault(),e.stopPropagation(),x(e=>(e-1+w.length)%w.length)):(e.key===`Tab`||e.key===`Enter`&&!e.shiftKey)&&(e.preventDefault(),e.stopPropagation(),E(w[Math.min(b,w.length-1)])))}};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)}),(0,Z.useEffect)(()=>{let e=r.current;if(!S||!e)return;let t={role:`combobox`,"aria-autocomplete":`list`,"aria-expanded":`true`,"aria-controls":s,"aria-activedescendant":w.length?`${s}-${Math.min(b,w.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))}},[b,r,s,S,w.length]);let D={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)(hn,{open:S,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:[w.map((e,t)=>{let n=e.source===`prompt`?V:y;return(0,Q.jsxs)(`button`,{type:`button`,role:`option`,id:`${s}-${t}`,"aria-selected":t===b,className:t===b?`active`:``,onMouseEnter:()=>x(t),onMouseDown:e=>e.preventDefault(),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)(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`),` · `,D[e.scope]]})]},e.invocation)}),!w.length&&(0,Q.jsx)(`p`,{children:a(h?`chat:commands.loading`:_?`chat:commands.loadError`:`chat:commands.empty`)})]})})}var _n=[`attachment`,`resource`,`visual`,`model`,`permission`,`run-mode`,`commands`,`compact-context`],vn=new Set(_n),yn=new Set([`model`,`permission`,`run-mode`]),bn={inline:[`permission`,`run-mode`,`model`],overflow:_n.filter(e=>![`permission`,`run-mode`,`model`].includes(e))};function xn(e){return Array.isArray(e)?e.filter((e,t,n)=>typeof e==`string`&&vn.has(e)&&n.indexOf(e)===t):[]}function $(e){let t=e&&typeof e==`object`?e:{};if(!Array.isArray(t.inline)&&!Array.isArray(t.overflow))return{inline:[...bn.inline],overflow:[...bn.overflow]};let n=xn(t.inline),r=new Set(n),i=xn(t.overflow).filter(e=>!r.has(e)),a=new Set([...n,...i]);for(let e of _n)a.has(e)||(yn.has(e)?n.push(e):i.push(e));return{inline:n,overflow:i}}function Sn(e,t,n){let r=$(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 Cn(e,t){let n=$(e),r=[...n.inline,...n.overflow];return t===`inline`?{inline:r,overflow:[]}:{inline:[],overflow:r}}function wn(e,t,n){let r=$(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 Tn(e,t,n,r={}){let i=$(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 En({open:e,children:t,label:n,trayId:r,anchorRef:i,menuRef:a,placement:o=`top`}){return(0,Q.jsx)(hn,{open:e,anchorRef:i,menuRef:a,placement:o,align:`start`,className:`composer-tool-tray-shell w-[248px] 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-0.5 [&>.composer-toolbar-slot]:w-full overflow-x-hidden overflow-y-auto overscroll-contain`,children:t})})}var Dn=`pisper-zcode-composer-toolbar`,On=u(()=>({getItem:e=>{let t=n.getItem(e);if(t!==null)return t;let r=n.getItem(Dn);if(r===null)return null;try{return JSON.parse(r),n.setItem(e,r),n.removeItem(Dn),r}catch{return null}},setItem:(e,t)=>n.setItem(e,t),removeItem:e=>n.removeItem(e)})),kn=d()(l(e=>({layout:$(void 0),setToolLocation:(t,n)=>e(e=>({layout:Sn(e.layout,t,n)})),setAllToolsLocation:t=>e(e=>({layout:Cn(e.layout,t)})),moveTool:(t,n)=>e(e=>({layout:wn(e.layout,t,n)})),resetLayout:()=>e({layout:$(void 0)})}),{name:`pisper-composer-toolbar`,storage:On,version:1,partialize:({layout:e})=>({layout:e}),merge:(e,t)=>({...t,layout:$(e&&typeof e==`object`&&`layout`in e?e.layout:void 0)})}));function An(e,t){return e.inline.join(`\0`)===t.inline.join(`\0`)&&e.overflow.join(`\0`)===t.overflow.join(`\0`)}function jn({ids:e,location:t,labels:n,onMove:r,onReorder:i,onMoveButtonRef:a}){let{t:o}=c(),s=t===`inline`?`overflow`:`inline`,l=t===`inline`?j:M,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)(K,{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)(m,{})}),(0,Q.jsx)(K,{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)(_,{})}),(0,Q.jsxs)(K,{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 Mn({labels:e,labeled:t=!1}){let{t:n}=c(),r=kn(e=>e.layout),i=kn(e=>e.setToolLocation),a=kn(e=>e.setAllToolsLocation),o=kn(e=>e.moveTool),s=kn(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)(Xe,{children:[(0,Q.jsx)(We,{asChild:!0,children:(0,Q.jsx)(Bt,{menu:t,label:n(`chat:focusSession.customizeShortcuts`),children:(0,Q.jsx)(Ee,{})})}),(0,Q.jsxs)(Je,{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)(qe,{className:`min-w-0 flex-1 gap-2 pt-1`,children:[(0,Q.jsx)(Ye,{children:n(`chat:focusSession.customizeShortcuts`)}),(0,Q.jsx)(Ge,{className:`text-xs leading-5`,children:n(`chat:focusSession.customizeShortcutsDescription`)})]}),(0,Q.jsx)(Ke,{asChild:!0,children:(0,Q.jsx)(K,{type:`button`,variant:`ghost`,size:`icon-sm`,className:`size-11`,"aria-label":n(`common:ui.closeDialog`),children:(0,Q.jsx)(Le,{})})})]}),(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)(M,{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)(jn,{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)(j,{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)(jn,{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)(K,{type:`button`,variant:`ghost`,size:`sm`,className:`h-11 text-xs`,disabled:r.overflow.length===0,onClick:()=>a(`inline`),children:[(0,Q.jsx)(M,{}),n(`chat:focusSession.showAllShortcuts`)]}),(0,Q.jsxs)(K,{type:`button`,variant:`ghost`,size:`sm`,className:`h-11 text-xs`,disabled:r.inline.length===0,onClick:()=>a(`overflow`),children:[(0,Q.jsx)(j,{}),n(`chat:focusSession.storeAllShortcuts`)]}),(0,Q.jsxs)(K,{type:`button`,variant:`ghost`,size:`sm`,className:`ml-auto h-11 text-xs text-[var(--text-muted)]`,disabled:An(r,bn),onClick:s,children:[(0,Q.jsx)(we,{}),n(`chat:focusSession.restoreShortcutDefaults`)]})]})]})]})}function Nn(e,t){let n=t.find(t=>t.key===e);return n?`${n.providerName} · ${n.label}`:e.split(`/`).at(-1)||e}function Pn({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?Nn(e,t||[]):`—`],[i(`chat:focusSession.statContextTokens`),f==null?`—`:`${J(f)} / ${J(r?.contextWindow)}`],[i(`chat:focusSession.statInputTokens`),J(n?.input)],[i(`chat:focusSession.statOutputTokens`),J(n?.output)],[i(`chat:focusSession.statCacheReadTokens`),p?J(n?.cacheRead):`—`],[i(`chat:focusSession.statCacheWriteTokens`),p?J(n?.cacheWrite):`—`],[i(`chat:focusSession.statReasoningTokens`),J(n?.reasoning)],[i(`chat:focusSession.statProcessedTokens`),J(n?.processedTokens)],[i(`chat:focusSession.statRequests`),String(Math.max(0,Number(n?.requests)||0))],[i(`chat:focusSession.statAvgFirstToken`),u==null?`—`:pe(u,a)],[i(`chat:focusSession.statAvgDuration`),d==null?`—`:pe(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 Fn({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:J(i),input:J(e?.input),output:J(e?.output),cacheRead:J(e?.cacheRead),cacheWrite:J(e?.cacheWrite),reasoning:J(e?.reasoning),requests:Math.max(0,Number(e?.requests)||0)}),f,s].filter(Boolean).join(`
3
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)(At,{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)(It,{size:12}),(0,Q.jsx)(`small`,{children:r(`chat:focusSession.processedTokens`)}),(0,Q.jsx)(`strong`,{children:J(i)})]}),s&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`i`,{"aria-hidden":`true`}),(0,Q.jsxs)(v,{children:[(0,Q.jsx)(h,{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)(ie,{size:12}),(0,Q.jsx)(`strong`,{children:s})]})}),(0,Q.jsx)(g,{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)(ae,{plan:t??null})})]})]})]})}function In({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),[_,y]=(0,Z.useState)(``),b=(0,Z.useRef)(u),x=(0,Z.useRef)(void 0);if((0,Z.useEffect)(()=>{window.clearTimeout(x.current),f(u),b.current=u},[u]),(0,Z.useEffect)(()=>()=>window.clearTimeout(x.current),[]),!s)return null;let S=e?.percent!=null&&Number.isFinite(Number(e.percent)),C=S?Math.max(0,Number(e.percent)):null,w=C==null?null:Math.round(C),T=Math.max(10,u-15),E=C==null?`unknown`:C>=u?`danger`:C>=T?`warning`:`normal`,D=S?e.estimated?o(`chat:focusSession.estimatedContextUsageTokensLimitTokensPercent`,{tokens:J(e.tokens),limit:J(s),percent:w}):o(`chat:focusSession.contextUsageTokensLimitTokensPercent`,{tokens:J(e.tokens),limit:J(s),percent:w}):o(`chat:focusSession.contextUsageWillUpdateAfterTheNextModelResponseLimitLimitTokens`,{limit:J(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:J(e.remainingBeforeCompaction)}):``,A=`${D} · ${O}${k?` · ${k}`:``}`,j=`${e?.tokens==null?`—`:J(e.tokens)} / ${J(s)}`,M=async e=>{let t=Math.min(95,Math.max(10,Math.round(e)));if(f(t),!(!i||t===b.current)){m(!0),y(``);try{await i(t),b.current=t}catch(e){y(e instanceof Error?e.message:String(e))}finally{m(!1)}}},N=e=>{window.clearTimeout(x.current),f(e),x.current=window.setTimeout(()=>void M(e),250)},P=e=>{window.clearTimeout(x.current),M(e)};return(0,Q.jsxs)(v,{children:[(0,Q.jsx)(h,{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)]`:``} ${E}`,"aria-label":A,title:A,children:[(0,Q.jsx)(Y,{size:12}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`strong`,{children:a?w==null?`—`:`${w}%`:j}),!a&&(0,Q.jsx)(`small`,{children:w==null?`—`:`${w}%`})]}),!a&&(0,Q.jsx)(`i`,{"aria-hidden":`true`,children:(0,Q.jsx)(`b`,{style:{width:`${Math.min(100,C||0)}%`}})})]})}),(0,Q.jsxs)(g,{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)(Pn,{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:_?`error`:``,children:_||(p?o(`chat:focusSession.savingCompactionThreshold`):`\xA0`)})]})]})}var Ln=`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`,Rn=`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 zn({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:k(a?Ln:Rn,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)(N,{size:i?11:14}),(0,Q.jsxs)(p,{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,disabled:!0,children:u(`chat:focusSession.selectAvailableModel`)}),t.map(e=>(0,Q.jsxs)(`option`,{value:e.key,children:[e.providerName,` · `,e.label]},e.key))]})]})}function Bn(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 Vn({model:e,models:t,onModelChange:n,thinkingLevel:r,levels:i,status:a,message:o,onThinkingChange:s,onRefreshThinking:l,modelDisabled:u,thinkingDisabled:d,deferred:f=!1,pendingModel:p=!1}){let{t:m}=c(),[_,y]=(0,Z.useState)(null),[b,x]=(0,Z.useState)(!1),S=(0,Z.useRef)(!1),C=t.find(t=>t.key===e),w=!C&&!p,T=C?.label||e.split(`/`).at(-1)||m(`chat:focusSession.toolbarModel`),E=a===`loading`||!a&&i.length===0,D=!w&&!E&&a!==`error`&&a!==`unsupported`&&i.length>0,O=Math.max(0,i.indexOf(r)),k=_??O,A=w?m(`chat:focusSession.modelUnavailable`):D?Bn(m,i[k]||r):`—`,j=w?m(`chat:focusSession.selectAvailableModel`):p?m(`chat:focusSession.thinkingAfterModelSwitch`):D?A:o||m(a===`unsupported`?`chat:focusSession.thinkingLevelUnsupported`:`chat:focusSession.loadingThinkingLevels`),M=d||b||!D||i.length<2,N=`${m(`chat:focusSession.modelAndThinking`)} · ${Nn(e,t)} · ${j}`,P=i.join(`|`);(0,Z.useEffect)(()=>{y(null)},[e,r,P]);let F=async e=>{let t=i[e];if(!(M||S.current||!t||t===r)){S.current=!0,x(!0);try{await s(t)}finally{S.current=!1,x(!1),y(null)}}};return(0,Q.jsxs)(v,{onOpenChange:e=>{e&&!w&&!p&&!d&&l?.()},children:[(0,Q.jsx)(h,{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-lg bg-foreground/5 px-2.5 text-xs font-medium text-foreground transition-colors hover:bg-foreground/10 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":N,title:N,children:[(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:T}),(0,Q.jsx)(`span`,{className:`shrink-0`,children:A})]})}),(0,Q.jsxs)(g,{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)(zn,{showLabel:!0,value:e,models:t,onChange:n,disabled:u||b,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:A}),(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:T}),(0,Q.jsx)(L,{size:14,className:`shrink-0`,"aria-hidden":`true`})]})]})})}),D&&(0,Q.jsxs)(`div`,{className:`relative h-7`,style:{"--effort-fill":`${i.length>1?k/(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:k,disabled:M,"aria-label":m(`chat:focusSession.currentThinkingLevel`),"aria-valuetext":A,onChange:e=>y(Number(e.currentTarget.value)),onPointerUp:e=>void F(Number(e.currentTarget.value)),onBlur:e=>void F(Number(e.currentTarget.value)),onKeyUp:e=>{[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`].includes(e.key)&&F(Number(e.currentTarget.value))}})]}),f&&(0,Q.jsx)(`p`,{className:`pt-2 text-center text-xs leading-4 text-muted-foreground`,role:`status`,children:m(`chat:focusSession.runtimeSelectionDeferred`)}),(!D||i.length===1)&&(0,Q.jsx)(`p`,{className:`pt-2 text-center text-xs leading-relaxed text-muted-foreground`,role:`status`,children:D?m(`chat:focusSession.thinkingLevelFixed`,{level:A}):j})]})]})}function Hn(e){return[[`approval-required`,e(`chat:focusSession.approvalRequired`),e(`chat:focusSession.approvalRequiredShowsADiffBeforeWriting`),jt],[`workspace-write`,e(`chat:focusSession.workspaceWrite`),e(`chat:focusSession.workspaceWriteRunsCommandsWithAutomaticApproval`),Et],[`full-access`,e(`chat:focusSession.fullAccess`),e(`chat:focusSession.fullAccessRunsShellWithoutPerCommandApproval`),te]]}function Un({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=Hn(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,pn.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)(P,{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-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 Wn=1e3;function Gn({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:ie},{value:`goal`,label:l(`chat:focusSession.goalMode`),description:l(`chat:focusSession.goalModeDescription`),icon:Lt},...o?[{value:`team`,label:l(`chat:focusSession.teamMode`),description:l(`chat:focusSession.teamModeDescription`),icon:zt}]:[]],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:J(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-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)(hn,{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)(P,{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:Wn,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(Wn,Math.round(n)))}}),v&&S&&(0,Q.jsxs)(K,{type:`button`,variant:`outline`,className:`bg-surface-subtle`,disabled:f,onClick:()=>void M(),children:[f?(0,Q.jsx)(Ce,{className:`animate-spin`,size:12}):(0,Q.jsx)(P,{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 Kn=new Set([`user`,`assistant`,`summary`,`compaction`,`position`]),qn=new Set([`tool`,`tool-call`]);function Jn(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 Yn(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 Xn(e,t){let n=[],r=new Map;for(let i of Yn(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 Zn(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 Qn(e){return e.kind===`user`?he:e.kind===`assistant`?N:e.kind===`tool`||e.kind===`tool-call`?Ie:e.kind===`settings`?De:e.kind===`label`?je:e.kind===`summary`||e.kind===`compaction`?V:e.kind===`position`?x:e.label?Ot:_e}function $n({nodes:e,viewportRef:t,selectedId:n,typeLabel:r,stateLabel:i,onSelect:a}){let o=ht({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=Qn(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)(Ot,{size:12}),i(o)]})]})},t.key)})})}function er({segment:e,viewportRef:t,selectedId:n,typeLabel:r,stateLabel:i,onSelect:a}){let{nodes:o,children:s}=e,c=o.length>120,l=ht({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=Qn(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)(Ot,{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)(er,{segment:e,viewportRef:t,selectedId:n,typeLabel:r,stateLabel:i,onSelect:a})},e.id))})]})}function tr({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)(T,{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)(w,{children:[(0,Q.jsx)(C,{value:`conversation`,children:y(`chat:sessionTree.conversation`)}),(0,Q.jsx)(C,{value:`labeled`,children:y(`chat:sessionTree.labeled`)}),(0,Q.jsx)(C,{value:`all`,children:y(`chat:sessionTree.all`)}),(0,Q.jsx)(C,{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)(Te,{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)(ge,{className:`size-3.5 animate-spin`,"aria-hidden":`true`}):(0,Q.jsx)(je,{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)($n,{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)(er,{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 nr({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:S,onSummarizeChange:C,onSaveLabel:w,onRemoveLabel:T,onCreateChild:E,onNavigate:D,onRefresh:O,onOpenRelated:k}){let{t:A,language:j}=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)(K,{variant:`ghost`,className:`min-h-[40px] justify-start px-[8px]`,onClick:b,children:[(0,Q.jsx)(I,{size:17}),A(`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:A(`chat:sessionTree.conversationLineage`)}),o&&(0,Q.jsxs)(K,{variant:`outline`,disabled:!!_,onClick:()=>k(o,s),children:[(0,Q.jsx)(_e,{size:13}),A(`chat:sessionTree.returnToOriginalChat`,{name:o.name||A(`chat:chatPage.newChat`)})]}),l.map(e=>(0,Q.jsxs)(K,{variant:`outline`,disabled:!!_,onClick:()=>k(e),children:[(0,Q.jsx)(_e,{size:13}),A(`chat:sessionTree.openSeparateChat`,{name:e.name||A(`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||A(`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:A(`chat:sessionTree.nodeLabel`)}),(0,Q.jsx)(Ze,{value:f,maxLength:80,placeholder:A(`chat:sessionTree.labelPlaceholder`),onChange:e=>S(e.target.value)})]}),(0,Q.jsxs)(K,{variant:`outline`,disabled:m||i||a,onClick:w,children:[(0,Q.jsx)(je,{size:14}),A(m?`chat:sessionTree.savingLabel`:`chat:sessionTree.saveLabel`)]}),!!t.label&&(0,Q.jsxs)(K,{variant:`outline`,disabled:m||i||a,onClick:T,children:[(0,Q.jsx)(Me,{size:14}),A(`chat:sessionTree.removeLabel`)]})]}),u&&(0,Q.jsxs)(K,{variant:`outline`,disabled:h||i||a,onClick:E,children:[(0,Q.jsx)(H,{size:14}),A(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:A(`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:A(`chat:sessionTree.abandonedBranchSummaryHint`)})]})]}),d&&(0,Q.jsx)(`p`,{children:A(`chat:sessionTree.sideEffectsRemain`)}),t.timestamp&&(0,Q.jsx)(`p`,{children:new Intl.DateTimeFormat(j,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(t.timestamp))}),r&&(0,Q.jsx)(`p`,{className:`danger-text`,children:r}),d&&(0,Q.jsxs)(K,{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)(x,{size:15}),g?A(`chat:sessionTree.navigating`):t.leaf?A(`chat:sessionTree.currentPosition`):A(`chat:sessionTree.continueFromNode`)]})]}):(0,Q.jsx)(`p`,{children:n?A(`chat:sessionTree.loading`):r||A(`chat:sessionTree.chooseNode`)}),r&&!t&&(0,Q.jsx)(K,{variant:`outline`,onClick:O,children:A(`chat:sessionTree.retry`)})]})}function rr({open:e,sessionId:t,streaming:n,onClose:r,onNavigated:i,onCreateChildSession:a}){let{t:o,language:s}=c(),l=He(),u=Re(),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),[ee,B]=(0,Z.useState)(!1),[te,V]=(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([q.getSessionTree(t),q.listSessions()]).then(([e,t])=>{n||(p(e),h(t.sessions||[]),C(e.leafId||e.nodes[0]?.id||``))}).catch(e=>{n||H(ce(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(``),q.listSessionTreeLabels(500).then(e=>{t&&(D(e.labels||[]),k(!0))}).catch(e=>t&&H(ce(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 q.navigateSessionTreeTarget(e.sessionId,e.entryId),ut(e.sessionId,`open`,e.entryId),r()}catch(e){H(ce(e)),N(null)}}},le=(0,Z.useMemo)(()=>Jn(f?.nodes||[]),[f]),ue=(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]),de=(0,Z.useMemo)(()=>{let e=b.trim().toLocaleLowerCase(s);return Xn(le,t=>(g===`conversation`?Kn.has(t.kind):g!==`labeled`||t.label)?!e||`${t.label} ${t.text} ${ue(t)}`.toLocaleLowerCase(s).includes(e):!1)},[le,s,b,ue,g]),fe=(0,Z.useMemo)(()=>de.map(Zn),[de]),pe=(0,Z.useMemo)(()=>Yn(de),[de]),U=(0,Z.useMemo)(()=>Yn(le),[le]).find(e=>e.id===S)||null,me=f?.lineage?.parentSessionId?m.find(e=>e.id===f.lineage?.parentSessionId):null,he=(f?.lineage?.childSessionIds||[]).map(e=>m.find(t=>t.id===e)).filter(e=>!!e),ge=U?.kind===`assistant`&&U.status===`completed`,_e=ge,ve=U?!qn.has(U.kind):!1;(0,Z.useEffect)(()=>{T(U?.label||``),F(!1)},[U?.id,U?.label]),(0,Z.useEffect)(()=>{if(S&&pe.some(e=>e.id===S))return;let e=[...pe].reverse().find(e=>e.active);C(e?.id||pe[0]?.id||``)},[S,pe]),(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,pe.length]);let ye=async()=>{L(!0),H(``);try{let e=await q.getSessionTree(t);p(e),C(e.leafId||e.nodes[0]?.id||``)}catch(e){H(ce(e))}finally{L(!1)}},be=async()=>{if(!(!U||R)){z(!0),H(``);try{p(await q.setSessionTreeLabel(t,U.id,w))}catch(e){H(ce(e))}finally{z(!1)}}},xe=async()=>{if(!(!U||R)){z(!0),H(``);try{p(await q.setSessionTreeLabel(t,U.id,``))}catch(e){H(ce(e))}finally{z(!1)}}},Se=async()=>{if(!(!U||!_e||te)){V(!0),H(``);try{await a(U.id),r()}catch(e){H(ce(e))}finally{V(!1)}}},Ce=async(e,t=``)=>{if(!(!e.id||ne)){re(e.id),H(``);try{t&&await q.navigateSessionTreeTarget(e.id,t),ut(e.id,`open`,t),r()}catch(e){H(ce(e))}finally{re(``)}}},we=async()=>{if(!(!U||ee||U.leaf||n||f?.streaming)){B(!0),H(``);try{let e=await q.navigateSessionTree(t,U.id,P);p(e),e.cancelled||(await i(e.editorText),r())}catch(e){H(ce(e))}finally{B(!1)}}},Te=e=>e.leaf?o(`chat:sessionTree.current`):e.branchPoint?o(`chat:sessionTree.fork`):e.active?o(`chat:sessionTree.active`):``;return(0,Q.jsx)(Xe,{open:e,onOpenChange:e=>!e&&r(),children:(0,Q.jsxs)(Je,{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)(Rt,{size:17})}),(0,Q.jsx)(Ye,{children:o(`chat:sessionTree.title`)})]}),(0,Q.jsx)(Ge,{children:o(`chat:sessionTree.description`,{nodes:f?.nodeCount||0,branches:f?.branchCount||0})})]}),(0,Q.jsx)(K,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":o(`common:ui.closeDialog`),title:o(`common:ui.closeDialog`),onClick:r,children:(0,Q.jsx)(Le,{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)(tr,{view:g,onViewChange:e=>{_(e),y(`list`)},query:b,onQueryChange:x,loading:I,error:ie,mobileLayout:d,viewportRef:ae,segments:fe,visibleNodes:pe,selectedId:S,typeLabel:ue,stateLabel:Te,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)(nr,{mobileLayout:d,selected:U,loading:I,error:ie,streaming:n,dataStreaming:!!f?.streaming,parentSession:me??null,parentEntryId:f?.lineage?.sourceEntryId||``,childSessions:he,canLabel:ge,canDerive:ve,label:w,summarize:P,savingLabel:R,creatingChild:te,navigating:ee,openingRelatedId:ne,typeLabel:ue,stateLabel:Te,onBackToList:()=>y(`list`),onLabelChange:T,onSummarizeChange:F,onSaveLabel:()=>void be(),onRemoveLabel:()=>void xe(),onCreateChild:()=>void Se(),onNavigate:()=>void we(),onRefresh:()=>void ye(),onOpenRelated:(e,t)=>void Ce(e,t??``)})]})]})})}function ir({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 q.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)(K,{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)(Rt,{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)(rr,{open:t,sessionId:n,streaming:r,onClose:()=>o(!1),onNavigated:s,onCreateChildSession:l})]}):null}function ar(e){return[`running`,`waiting_approval`].includes(String(e.status||``))}function or(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 sr({sessionId:e}){let{t}=c(),[n,r]=(0,Z.useState)(``),i=Ue({queryKey:[`session-workflow-runs`,e],queryFn:({signal:t})=>q.getSessionWorkflowRuns(e,t),enabled:!!e,refetchInterval:1500,refetchIntervalInBackground:!1}),a=i.data?.runs||[],o=()=>i.refetch();return a.length?(0,Q.jsx)(`div`,{className:`flex max-h-[210px] flex-col gap-[5px] overflow-auto`,children:[...a].sort((e,t)=>Date.parse(t.startedAt)-Date.parse(e.startedAt)).slice(0,5).map(e=>{let i=n===e.id,a=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:()=>r(i?``: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)(Fe,{size:14})}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`strong`,{children:e.workflowName}),(0,Q.jsxs)(`small`,{children:[or(e.status,t),` · v`,e.workflowRevision||1]})]}),(0,Q.jsx)(S,{value:e.status===`completed`?100:a}),i?(0,Q.jsx)(F,{size:14}):(0,Q.jsx)(L,{size:14})]}),i&&(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)(P,{size:13}):n.status===`failed`?(0,Q.jsx)(z,{size:13}):n.status===`running`?(0,Q.jsx)(Ce,{className:`animate-spin`,size:13}):(0,Q.jsx)(Ae,{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)(K,{size:`xs`,onClick:async()=>{await q.resolveWorkflowApproval(e.id,n.id,!0),await o()},children:t(`chat:workflowRun.approve`)}),(0,Q.jsx)(K,{size:`xs`,variant:`destructive`,onClick:async()=>{await q.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}),ar(e)&&(0,Q.jsxs)(K,{size:`xs`,variant:`destructive`,onClick:async()=>{await q.stopWorkflowRun(e.id),await o()},children:[(0,Q.jsx)(Ae,{"data-icon":`inline-start`}),t(`chat:workflowRun.stop`)]})]})]},e.id)})}):null}function cr({menu:e=!1,notify:t,onOpenModelSettings:n,onInsertPrompt:r}){let{t:i}=c(),a=async()=>{try{let e=await G(`/api/visual/models`);e.image||e.video?r(i(`chat:focusSession.visualPromptTemplate`)):(t?.(i(`chat:focusSession.configureVisualModelFirst`)),n?.())}catch{r(i(`chat:focusSession.visualPromptTemplate`))}};return(0,Q.jsx)(Bt,{menu:e,label:i(`chat:focusSession.generateImage`),className:`visual-entry-trigger`,onClick:()=>void a(),children:(0,Q.jsx)(b,{size:16})})}function lr(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 ur(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`||lr(n)||!it(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 dr(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 fr(e=.35){let t=0;return{push(n){return t=t*(1-e)+n*e,t},reset(){t=0}}}function pr(e,t=140){let n=e.trim();return n.length>t?`${n.slice(0,t-1)}…`:n}var mr=16e3,hr=20,gr=mr*hr/1e3;function _r(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(gr),o=0,s=0,c=0,l=0,u=!1,d=!1,f=!1,p=()=>u&&c*hr>=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!==gr)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*hr>=t&&(u=!0);else if(s=0,l+=1,u||(c=0),l*hr>=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 vr(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 _r(()=>new i(e.mode??r.AGGRESSIVE,mr),e)}var yr=()=>new DOMException(`Speech setup cancelled.`,`AbortError`);function br(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&&wt(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 _t(e);r()&&g(t)}catch(e){if(r())throw e}},[g]);(0,Z.useEffect)(()=>(u.current=!0,_().catch(()=>{}),()=>{u.current=!1,h(yr())}),[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(W(e),!u.current)throw yr();h(yr());let t=++f.current;return new Promise((n,r)=>{let a=()=>{l.current===o&&h(e.reason||yr())},o={signal:e,abort:a,resolve:n,reject:r};if(l.current=o,e.addEventListener(`abort`,a,{once:!0}),e.aborted){a();return}_t(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?wt(t,e):[],show:()=>{h(yr()),i(!0),c(``)},close:()=>h(yr()),download:e=>y(()=>St(e)),cancelDownload:e=>y(()=>xt(e)),downloadAll:()=>y(async()=>{if(t)for(let e of wt(t,m.current))[`installed`,`downloading`,`verifying`].includes(e.status)||await St(e.id)})}}var xr=8388608;function Sr(e,t){return W(t),new Promise((n,r)=>{let i=()=>r(Ve(t));t.addEventListener(`abort`,i,{once:!0}),e.then(n,r).finally(()=>t.removeEventListener(`abort`,i))})}var Cr=10,wr=500;async function Tr(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>=Cr)return a;let o=await a.json().catch(()=>({}));if(!o.error||!/busy/i.test(o.error))return a;await Sr(new Promise(e=>setTimeout(e,wr)),r)}}async function Er(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>xr)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 Dr(e,t,n,r){W(n);let i=Be(n);try{await Or(e,t,i,r)}finally{i.abort(new DOMException(`Speech playback ended.`,`AbortError`)),i.dispose()}}async function Or(e,n,r,i){let{signal:a}=r,{speechSegments:o}=await Sr(t(()=>import(`./speech-text-Cpe8K6uv.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8])),a);W(a);let s=(typeof e==`string`?(async function*(){yield*o(e)})():(await Sr(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?yt(`mobile_cancel_speech`,{requestId:e}):G(`/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=>{W(a);let t=crypto.randomUUID();l.add(t);let r=(async()=>{if(c){let r=await yt(`mobile_synthesize_speech`,{text:e,voiceId:n,requestId:t});if(a.aborted&&(p(t),W(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=Be(a,6e4);try{let i=await Tr(e,n,t,r.signal);return{requestId:t,wav:await Er(i)}}finally{r.dispose()}})();return r.catch(()=>{}),r};try{if(!c){u=new AudioContext({sampleRate:24e3});let e;try{await Sr(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 Sr(s.next(),a);return e.done?void 0:h(e.value)},t=e(),n=!1;for(;;){let r=await Sr(t,a);if(W(a),!r)break;if(t=e(),t.catch(()=>{}),n=!0,i?.(),r.native){if((await Sr(yt(`mobile_play_speech`,{audioId:r.native.audioId,requestId:r.requestId}),a))?.completed!==!0)throw Error(`Speech playback was interrupted.`)}else{let e=await Sr(u.decodeAudioData(r.wav),a);if(W(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),W(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 kr={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
4
  Version 2.0, January 2004
5
5
  http://www.apache.org/licenses/
@@ -509,7 +509,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
509
509
  ## Dictionary. Further addictions and improvements are planned
510
510
  ## for forthcoming releases.
511
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:[]}]},Ar=kr,jr=e=>kr.models.some(t=>t.id===e);function Mr({modelId:e,modelName:t,returnFocus:n,onClose:r}){let{t:i}=c(),a=Ar.models.find(t=>t.id===e);if(!a)return null;let o=new Set(a.groups.flatMap(e=>e.licenseIds)),s=Ar.licenses.filter(e=>o.has(e.id));return(0,Q.jsx)(Xe,{open:!0,onOpenChange:e=>{e||r()},children:(0,Q.jsxs)(Je,{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)(qe,{children:[(0,Q.jsx)(Ye,{children:i(`chat:speechModels.notices`)}),(0,Q.jsxs)(Ge,{className:`break-words`,children:[t,` (`,a.revision,`)`]})]}),(0,Q.jsx)(`p`,{className:`break-words text-sm text-muted-foreground`,children:Ar.scope}),(0,Q.jsx)(`p`,{className:`break-words text-sm text-muted-foreground`,children:Ar.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)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{size:`icon-sm`,variant:`outline`,onClick:()=>{let e=new Blob([JSON.stringify({...Ar,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)(B,{})})}),(0,Q.jsx)(D,{children:i(`chat:speechModels.downloadNotices`)})]})})]})})}var Nr=e=>`${new Intl.NumberFormat(void 0,{maximumFractionDigits:1}).format(e/1048576)} MiB`;function Pr({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 Dr(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)(Xe,{open:e.open,onOpenChange:e=>{e||y()},children:[(0,Q.jsxs)(Je,{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)(qe,{children:[(0,Q.jsx)(Ye,{children:n(`chat:speechModels.title`)}),(0,Q.jsx)(Ge,{className:`sr-only`,children:n(`chat:speechModels.title`)})]}),!e.catalog&&!e.error&&(0,Q.jsx)(ge,{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)(R,{className:`size-5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-label":p.installed}):(0,Q.jsxs)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{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)(Ae,{}):(0,Q.jsx)(B,{})})}),(0,Q.jsx)(D,{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?`${Nr(t.downloadedBytes)} / ${Nr(t.totalBytes)}`:Nr(t.totalBytes)})]}),r&&(0,Q.jsx)(S,{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}),jr(t.id)&&(0,Q.jsxs)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{size:`icon-sm`,variant:`ghost`,"aria-label":n(`chat:speechModels.notices`),onClick:e=>{d.current=e.currentTarget,f(),l(t)},children:(0,Q.jsx)(Dt,{})})}),(0,Q.jsx)(D,{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)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{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)(Ae,{}):(0,Q.jsx)(xe,{})})}),(0,Q.jsx)(D,{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)(K,{disabled:e.loading||v,onClick:()=>void e.downloadAll(),children:[(0,Q.jsx)(B,{}),n(`chat:speechModels.downloadAll`)]}):(0,Q.jsx)(K,{disabled:!e.catalog,onClick:y,children:n(`chat:speechModels.done`)})})]}),e.open&&s&&(0,Q.jsx)(Mr,{modelId:s.id,modelName:s.name,returnFocus:d,onClose:()=>l(null)})]})}var Fr=16e3,Ir=Fr*60;function Lr(e,t){let n=window.__TAURI__?.core?.invoke??window.__TAURI_INTERNALS__?.invoke;return n?n(e,t):Promise.reject(Error(`移动端原生桥不可用。`))}async function Rr(){if(!(typeof window>`u`||!window.__PISPER_MOBILE_APP__)&&(await Lr(`mobile_request_microphone_permission`)).state!==`granted`)throw Error(`microphone_permission_denied`)}async function zr(e){let t=await e.text().catch(()=>``);try{return JSON.parse(t).error||`语音转写失败 (${e.status})`}catch{return t||`语音转写失败 (${e.status})`}}function Br(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 Vr=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 ze(),W(e.signal);let{loadSpeechHotwords:n,prepareSpeechSession:r}=await t(async()=>{let{loadSpeechHotwords:e,prepareSpeechSession:t}=await import(`./speech-session-BB9aLyRQ.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(W(o.signal),o.signal.addEventListener(`abort`,()=>{this.controller===e&&!e.signal.aborted&&this.cancel()},{once:!0}),window.__PISPER_MOBILE_APP__)return;let s=Be(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 zr(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(()=>{}),W(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=Ir-this.retainedSamples;if(t<=0)return!0;let n=e.slice(0,t);return this.chunks.push(n),this.retainedSamples+=n.length,this.retainedSamples>=Ir}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=Br(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(Fr),"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 zr(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`);W(i.signal);let a=crypto.randomUUID();this.nativeRequestId=a;let o=await Lr(`mobile_transcribe_pcm`,{pcmBase64:btoa(n),hotwords:gt(this.terms),requestId:a});if(W(i.signal),this.controller!==i)throw new DOMException(`Speech recognition cancelled.`,`AbortError`);let s=vt(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(Fr),"X-Pisper-Chat-Session":this.chatSessionId},body:e.buffer,signal:this.controller?.signal});if(!t.ok)throw Error(await zr(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=Br(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 Lr(`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 Hr({chatSessionId:e=``}={}){return new Vr(e)}var Ur=`
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:[]}]},Ar=kr,jr=e=>kr.models.some(t=>t.id===e);function Mr({modelId:e,modelName:t,returnFocus:n,onClose:r}){let{t:i}=c(),a=Ar.models.find(t=>t.id===e);if(!a)return null;let o=new Set(a.groups.flatMap(e=>e.licenseIds)),s=Ar.licenses.filter(e=>o.has(e.id));return(0,Q.jsx)(Xe,{open:!0,onOpenChange:e=>{e||r()},children:(0,Q.jsxs)(Je,{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)(qe,{children:[(0,Q.jsx)(Ye,{children:i(`chat:speechModels.notices`)}),(0,Q.jsxs)(Ge,{className:`break-words`,children:[t,` (`,a.revision,`)`]})]}),(0,Q.jsx)(`p`,{className:`break-words text-sm text-muted-foreground`,children:Ar.scope}),(0,Q.jsx)(`p`,{className:`break-words text-sm text-muted-foreground`,children:Ar.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)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{size:`icon-sm`,variant:`outline`,onClick:()=>{let e=new Blob([JSON.stringify({...Ar,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)(B,{})})}),(0,Q.jsx)(D,{children:i(`chat:speechModels.downloadNotices`)})]})})]})})}var Nr=e=>`${new Intl.NumberFormat(void 0,{maximumFractionDigits:1}).format(e/1048576)} MiB`;function Pr({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 Dr(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)(Xe,{open:e.open,onOpenChange:e=>{e||y()},children:[(0,Q.jsxs)(Je,{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)(qe,{children:[(0,Q.jsx)(Ye,{children:n(`chat:speechModels.title`)}),(0,Q.jsx)(Ge,{className:`sr-only`,children:n(`chat:speechModels.title`)})]}),!e.catalog&&!e.error&&(0,Q.jsx)(ge,{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)(R,{className:`size-5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-label":p.installed}):(0,Q.jsxs)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{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)(Ae,{}):(0,Q.jsx)(B,{})})}),(0,Q.jsx)(D,{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?`${Nr(t.downloadedBytes)} / ${Nr(t.totalBytes)}`:Nr(t.totalBytes)})]}),r&&(0,Q.jsx)(S,{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}),jr(t.id)&&(0,Q.jsxs)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{size:`icon-sm`,variant:`ghost`,"aria-label":n(`chat:speechModels.notices`),onClick:e=>{d.current=e.currentTarget,f(),l(t)},children:(0,Q.jsx)(Dt,{})})}),(0,Q.jsx)(D,{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)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{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)(Ae,{}):(0,Q.jsx)(xe,{})})}),(0,Q.jsx)(D,{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)(K,{disabled:e.loading||v,onClick:()=>void e.downloadAll(),children:[(0,Q.jsx)(B,{}),n(`chat:speechModels.downloadAll`)]}):(0,Q.jsx)(K,{disabled:!e.catalog,onClick:y,children:n(`chat:speechModels.done`)})})]}),e.open&&s&&(0,Q.jsx)(Mr,{modelId:s.id,modelName:s.name,returnFocus:d,onClose:()=>l(null)})]})}var Fr=16e3,Ir=Fr*60;function Lr(e,t){let n=window.__TAURI__?.core?.invoke??window.__TAURI_INTERNALS__?.invoke;return n?n(e,t):Promise.reject(Error(`移动端原生桥不可用。`))}async function Rr(){if(!(typeof window>`u`||!window.__PISPER_MOBILE_APP__)&&(await Lr(`mobile_request_microphone_permission`)).state!==`granted`)throw Error(`microphone_permission_denied`)}async function zr(e){let t=await e.text().catch(()=>``);try{return JSON.parse(t).error||`语音转写失败 (${e.status})`}catch{return t||`语音转写失败 (${e.status})`}}function Br(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 Vr=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 ze(),W(e.signal);let{loadSpeechHotwords:n,prepareSpeechSession:r}=await t(async()=>{let{loadSpeechHotwords:e,prepareSpeechSession:t}=await import(`./speech-session-DKjw0mV_.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(W(o.signal),o.signal.addEventListener(`abort`,()=>{this.controller===e&&!e.signal.aborted&&this.cancel()},{once:!0}),window.__PISPER_MOBILE_APP__)return;let s=Be(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 zr(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(()=>{}),W(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=Ir-this.retainedSamples;if(t<=0)return!0;let n=e.slice(0,t);return this.chunks.push(n),this.retainedSamples+=n.length,this.retainedSamples>=Ir}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=Br(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(Fr),"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 zr(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`);W(i.signal);let a=crypto.randomUUID();this.nativeRequestId=a;let o=await Lr(`mobile_transcribe_pcm`,{pcmBase64:btoa(n),hotwords:gt(this.terms),requestId:a});if(W(i.signal),this.controller!==i)throw new DOMException(`Speech recognition cancelled.`,`AbortError`);let s=vt(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(Fr),"X-Pisper-Chat-Session":this.chatSessionId},body:e.buffer,signal:this.controller?.signal});if(!t.ok)throw Error(await zr(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=Br(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 Lr(`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 Hr({chatSessionId:e=``}={}){return new Vr(e)}var Ur=`
513
513
  class PisperVoiceInputProcessor extends AudioWorkletProcessor {
514
514
  constructor(options) {
515
515
  super()
@@ -549,4 +549,4 @@ class PisperVoiceInputProcessor extends AudioWorkletProcessor {
549
549
  }
550
550
  }
551
551
  registerProcessor('pisper-voice-input', PisperVoiceInputProcessor)
552
- `;async function Wr(e){let t=new Blob([Ur],{type:`application/javascript`}),n=URL.createObjectURL(t);try{await e.audioWorklet.addModule(n)}finally{URL.revokeObjectURL(n)}}async function Gr(e,t){if(W(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(W(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 Wr(r),f(),a=r.createMediaStreamSource(n),i=new AudioWorkletNode(r,`pisper-voice-input`,{numberOfInputs:1,numberOfOutputs:1,outputChannelCount:[1],processorOptions:{targetSampleRate:Fr}}),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 Kr=32,qr=50;function Jr(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 Yr({onInsert:e,onLiveText:t,sessionId:n,disabled:r=!1,shortcutEnabled:i=!1}){let{t:a}=c(),o=br([`asr`]),s=at(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)(fr()),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<Kr;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,qr);return()=>window.clearInterval(t)},[l]);let ee=()=>!r&&(p.current===`idle`||p.current===`error`),B=async()=>{if(!ee())return;let e=++y.current,t=new AbortController;_.current=t,S.current=!1,m(`requesting`),f(``),D.current.reset();let r=Hr({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=Jr(t,a(`chat:voiceInput.failed`));L(r===`permission`?a(`chat:voiceInput.permissionDenied`):r)};try{window.__PISPER_MOBILE_APP__&&(w.current=e);try{await Rr()}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 vr(),e!==y.current){i.dispose();return}M.current=i;let n=i,c=await Gr(t=>{if(e!==y.current)return;O.current=D.current.push(dr(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)}},te=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=Jr(t,a(`chat:voiceInput.failed`));L(n===`permission`?a(`chat:voiceInput.permissionDenied`):n),S.current=!1}};x.current=()=>void te(),ur({enabled:i&&!r,binding:s,onStart:()=>ee()?(B(),C.current=y.current,!0):!1,onRelease:()=>{C.current===y.current&&(g.current?te():z())},onCancel:()=>{C.current===y.current&&z()}});let V=l===`recording`?a(`chat:voiceInput.stop`):l===`requesting`?a(`chat:voiceInput.close`):l===`error`?d:a(`chat:voiceInput.open`),ne=s&&l!==`error`?`${V} (${ot(s)})`:V;return(0,Q.jsxs)(`div`,{className:`relative flex flex-none items-center`,children:[l===`recording`&&(0,pn.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,pn.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)(X,{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 te():l===`requesting`?()=>z():()=>void B(),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)(X,{size:17}):l===`transcribing`||l===`requesting`?(0,Q.jsx)(ge,{className:`animate-spin`,size:17}):l===`error`?(0,Q.jsx)(X,{size:17}):(0,Q.jsx)(Mt,{size:17})]}),(0,Q.jsx)(Pr,{manager:o,onClose:()=>{}})]})}var Xr={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`}},Zr=64,Qr=96,$r=2.6,ei=Math.PI*2,ti={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 ni(e,t,n){let r=Math.sin(e*127.1+t*311.7+n*74.7)*43758.5453123;return r-Math.floor(r)}function ri(e){return e*e*(3-2*e)}function ii(e,t,n){let r=Math.floor(e),i=Math.floor(t),a=Math.floor(n),o=ri(e-r),s=ri(t-i),c=ri(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)*ni(r+e,i+t,a+n);return l}function ai(e){return 1+2.70158*(e-1)**3+1.70158*(e-1)**2}function oi(e){let t=e*.9%1;return Math.exp(-(((t-.12)*9)**2))+.45*Math.exp(-(((t-.34)*9)**2))}function si({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(Zr),l=new Float32Array(Zr);for(let e=0;e<Zr;e+=1){let t=-Math.PI/2+(e+.5)/Zr*Math.PI;c[e]=Math.sin(t),l[e]=Math.cos(t)}let u=new Float32Array(Qr),d=new Float32Array(Qr);for(let e=0;e<Qr;e+=1){let t=e/Qr*ei;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={...Xr[a.current]},x=0,S=0,C=0,w=e=>{let r=Math.min((e-g)/1e3,.05);g=e;let i=Xr[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=ai(Math.min(1,Math.max(0,(e-_)/900))),A=b.behavior===`beat`?O:oi(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=ti[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,ee=b.freq,B=b.amp*j,te=b.spike*(O+C),V=p*j,ne=Math.floor(v*15),re=b.dim*(.72+.5*A)+C*.3;t.globalCompositeOperation=M.composite;for(let e=0;e<Zr;e+=1){let n=c[e],r=l[e];for(let i=0;i<Qr;i+=1){let a=r*u[i],o=n,s=r*d[i],c=ii(a*ee+z,o*ee+z*.7,s*ee)-.5,l=1+c*2*B;b.behavior===`reactive`?l+=Math.max(c,0)**2*1.7*te:b.behavior===`swirl`?l+=.03*Math.sin(9*a+v*4.6):b.behavior===`jitter`&&(l+=.02*(ni(e*Qr+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=$r/($r-x),C=f+g*S*V,w=f+y*S*V,T=(x+1)/2,E=ii(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+te*.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 ci=new Map;function li(e,t){let n=ci.get(e)??new Set;return n.add(t),ci.set(e,n),()=>{n.delete(t),n.size||ci.delete(e)}}function ui(e){for(let t of ci.get(e.sessionId)??[])t(e)}function di(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);ui({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 fi(e){let t=``,n=0,r=!1,i,a,o=()=>{a?.(),a=void 0},s=()=>{i=Ve(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(W(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 pi(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),W(e.signal),!0);let{hotwords:r}=await Ct(t,e.signal);await bt({kinds:[`asr`,`tts`],hotwords:r},e.signal),W(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=fi(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=li(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(()=>(W(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 ee(){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 B(){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=fr(),r=0;try{if(await x.current,!k(e)||(await M(),!k(e)))return;if(A()){I();return}e.permissionPending=!0;try{await Rr()}finally{e.permissionPending=!1}if(!k(e))return;if(document.hidden||A()){I();return}let n=await vr();if(!k(e)){n.dispose();return}e.endpoint=n;let i=Hr({chatSessionId:e.sessionId});if(e.recognizer=i,e.unsubscribe=i.onPartial(t=>{k(e)&&l(t)}),await i.start(),!k(e)||(e.capturePending=Gr(a=>{if(!(!k(e)||e.committed||e.microphone.signal.aborted))try{let s=t.push(dr(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:B,commit:ee,stop:I};let te=(0,Z.useCallback)(()=>D.current.commit(),[]),V=(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`?V():(v.current===`idle`||v.current===`error`)&&(T.current=!1,h(!1),D.current.start())},[V]),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:te,interrupt:V}}function mi(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 hi(e){let t=Math.floor(e/60),n=e%60;return`${t.toString().padStart(2,`0`)}:${n.toString().padStart(2,`0`)}`}function gi(){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 _i(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 vi({open:e,sessionId:t,messages:n,streaming:r,sendPrompt:i,onAbort:a,onClose:o}){let{t:s}=c(),l=gi(),u=br([`asr`,`tts`]),d=pi({open:e,sessionId:t,messages:n,streaming:r,sendPrompt:i,onAbort:a,ensureReady:u.ensureReady,speakText:(e,t,n)=>Dr(e,u.selectedVoice,t,n)}),{stage:f,level:p,partial:m,turns:h,error:g,elapsed:_}=d,v=_i(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=mi(s),C=h[h.length-1],w=f===`listening`&&m?m:C?`${C.role,``}${pr(C.text,120)}`:``,T=f===`error`?g||s(`chat:voiceMode.failed`):S[f];return(0,pn.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)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{variant:`ghost`,size:`icon-sm`,"aria-label":s(`chat:speechModels.title`),onClick:()=>{d.hangUp(),u.show()},children:(0,Q.jsx)(Tt,{})})}),(0,Q.jsx)(D,{children:s(`chat:speechModels.title`)})]}),(0,Q.jsxs)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{variant:`ghost`,size:`icon-sm`,className:`size-11 flex-none`,"aria-label":s(`chat:speechModels.close`),onClick:b,children:(0,Q.jsx)(Le,{})})}),(0,Q.jsx)(D,{children:s(`chat:speechModels.close`)})]})]}),(0,Q.jsx)(Pr,{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)(si,{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:hi(_)})]}),(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)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{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)(Ae,{}):d.muted?(0,Q.jsx)(X,{}):(0,Q.jsx)(Mt,{})})}),(0,Q.jsx)(D,{children:f===`speaking`||f===`thinking`?s(`chat:voiceMode.interrupt`):d.muted?s(`chat:voiceMode.unmute`):s(`chat:voiceMode.mute`)})]})})]}),document.body)}var yi=({className:e,defaultOpen:t=!0,...n})=>(0,Q.jsx)(f,{className:k(e),defaultOpen:t,...n}),bi=(0,Z.lazy)(()=>t(()=>import(`./ShinyText-DqxsUc3F.js`).then(e=>({default:e.ShinyText})),__vite__mapDeps([18,4,2,19,8,20])));function xi({queuedInputs:e,withdrawingInputIds:t=[],onWithdraw:n}){let{t:r}=c(),i=r(`chat:focusSession.sentToTheRunningAgent`),a=r(`chat:focusSession.withdrawQueuedInput`);return(0,Q.jsx)(yi,{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)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{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)(Pe,{size:16,"aria-hidden":`true`})})}),(0,Q.jsx)(D,{children:a})]})]},i||`${e.behavior}-${r}`)})})]})})}function Si({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)(Ie,{size:13}):(0,Q.jsx)(y,{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)(Le,{size:13})})]})}function Ci({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)(bi,{children:n||r(`chat:focusSession.running`)},n||`running`)}):r(`chat:focusSession.waitingForInput`)})]})}function wi({menu:e=!1,streaming:t,compactingManually:n,compactionActive:r,disabled:i,onCompact:a}){let{t:o}=c();return(0,Q.jsx)(Bt,{menu:e,label:o(`chat:focusSession.compactContextNow`),className:`compact-context-trigger`,title:o(t?`chat:focusSession.manualCompactionWaitForRun`:n||r?`chat:focusSession.compactingContext`:`chat:focusSession.compactContextNow`),"aria-label":o(`chat:focusSession.compactContextNow`),disabled:i,onClick:a,children:n||r?(0,Q.jsx)(Ce,{className:`animate-spin`,size:14}):(0,Q.jsx)(Nt,{size:14})})}function Ti({streaming:e,queueing:t,disabled:n,onAbort:r}){let{t:i}=c(),a=rt(`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)(Ae,{size:12,fill:`currentColor`}):t?(0,Q.jsx)(Ce,{className:`animate-spin`,size:17}):(0,Q.jsx)(m,{size:17})})}function Ei({streaming:e,messages:t,currentActivity:n,thinkingText:r,compaction:i,error:a,runStopped:o,runNotice:s,lastActivityAt:c},l){return(0,Z.useMemo)(()=>ue({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 Di=36,Oi=40;function ki(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:Di);n(Math.max(0,r/Oi))};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 Ai=560;function ji(){let e=(0,Z.useRef)(null),[t,n]=(0,Z.useState)(!1);return(0,Z.useLayoutEffect)(()=>{let t=e.current;if(!t)return;let r=()=>{let e=t.clientHeight;e<=0||(t.style.setProperty(`--session-viewport-height`,`${e}px`),n(e<Ai))};if(r(),typeof ResizeObserver>`u`)return window.addEventListener(`resize`,r),()=>window.removeEventListener(`resize`,r);let i=new ResizeObserver(r);return i.observe(t),()=>i.disconnect()},[]),{ref:e,compact:t}}var Mi=[`plan`,`goal`,`team`];function Ni(e){return Mi.includes(e)?e:`plan`}function Pi({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)(()=>Ni(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(Ni(b.current)),T.current=null,S(null),w(null),D(!1),k(!1),j(null)},[e]),(0,Z.useEffect)(()=>{y(Ni(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 Fi=(0,Z.lazy)(()=>t(()=>import(`./QuickPromptIdeas-B8P77vjW.js`),__vite__mapDeps([21,4,2,22,14,3,15,16,17,23,24,25,26,27,28,29]))),Ii=[`.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(`, `),Li=[`.composer-tools-trigger`,`.composer-tool-tray-shell`,Ii].join(`, `),Ri=(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:b,tools:x,thinkingText:S,queuedInputs:C,withdrawingInputIds:w,compaction:T,contextUsage:E,sessionUsage:D,sessionTreeRevision:O,sessionTreePulse:A,cwd:j,availableModels:M,pendingRuntimeSelection:N,switchingModel:P,switchingThinking:F,switchingCwd:I,switchingPermission:L,streaming:R,runStartedAt:z,lastActivityAt:B,runFinishedAt:te,runStopped:V,runNotice:ne,approvals:ie,error:H,pendingAsset:ae,contextOpen:se,contextCompact:ce,contextPanelId:ue,onToggleContext:de,notify:pe,onOpenModelSettings:U,onAssetConsumed:me,onLoadOlder:he,onModelChange:ge,onThinkingLevelChange:_e,onLoadThinkingLevel:ye,onExecutionModeChange:xe,onRunModeChange:Ce,onCompact:we,onCompactionThresholdChange:Te,onGoalPause:Ee,onGoalBudgetChange:De,onApproval:Ae,onWorkspace:je,onRename:Me,onBranchFromHere:Ne,onCreateChildSession:Pe,onRetryLastTurn:Fe,onTreeNavigated:Ie,onSend:ze,onQueue:Be,onWithdrawQueuedInput:W,onAbort:Ve}){let{t:G,language:K}=c(),Ue=st(e=>e.cycleTheme),q=st(e=>e.theme),We=at(e=>e.bindings),Ge=rt(`commandPalette`),Ke=He(),qe=Re(),Je=Ke||qe,Ye=ft(e=>e.capabilities),Xe=dt(Ye,`goals`),Ze=dt(Ye,`multiAgent`),J=dt(Ye,`plans`),$e=dt(Ye,`workflows`),ot=dt(Ye,`visualGeneration`),{value:ct,updateValue:ut,selection:pt,clearDraft:mt,restoreDraft:ht}=fn(e.id),[gt,_t]=(0,Z.useState)(!1),[vt,yt]=(0,Z.useState)(!1),[bt,xt]=(0,Z.useState)(!1),[St,Ct]=(0,Z.useState)(!1),[wt,Et]=(0,Z.useState)(!1),[Dt,Ot]=(0,Z.useState)(0),At=(0,Z.useRef)(null),jt=pt.addAttachments,Y=(0,Z.useRef)(null),X=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!t)return;let e=e=>{!nt(e)&&it(e,We.voiceInput)&&Et(!0),!nt(e)&&it(e,We.focusComposer)&&(e.preventDefault(),Y.current?.focus())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,We.focusComposer,We.voiceInput]);let Mt=(0,Z.useRef)(null),Nt=(0,Z.useRef)(null),It=(0,Z.useRef)(null),Lt=ki(Mt),Rt=kn(e=>e.layout),zt=(0,Z.useRef)(!1),Vt=r!==`ready`||n.length>0,Ht=ji(),Ut=!Vt&&Ht.compact,Wt=!Vt&&!Ut,Gt=Ei({streaming:R,messages:n,currentActivity:v,thinkingText:S,compaction:T,error:H,runStopped:V,runNotice:ne,lastActivityAt:B},G),Kt=`composer-tool-tray-${e.id}`,qt=G(St?`chat:focusSession.collapseQuickActions`:`chat:focusSession.expandQuickActions`),Jt=G(Je?R?`chat:focusSession.addGuidanceForTheRunningAgent`:`chat:workbench.composerPlaceholder`:R?`chat:focusSession.runningAgentComposerHint`:`chat:focusSession.composerHint`),Yt=()=>Ot(e=>e+1),Xt=e=>{ut(e),requestAnimationFrame(()=>{let e=Y.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,220)}px`)})},{composerExecutionMode:Zt,setComposerExecutionMode:Qt,goalTokenBudget:$t,setGoalTokenBudget:rn,teamTokenBudget:an,setTeamTokenBudget:sn,queueing:cn,compactingManually:ln,invocation:un,setInvocation:dn,requestGoalPause:pn,compactContext:mn,submit:hn}=Pi({sessionId:e.id,runMode:e.runMode,goalsAvailable:Xe,teamAvailable:Ze,workflowsAvailable:$e,goal:h,streaming:R,compaction:T,value:ct,selection:pt,clearDraft:mt,promptRef:Y,onCompact:we,onGoalPause:Ee,onSend:ze,onQueue:Be,setToolsOpen:Ct,requestTranscriptBottom:Yt}),vn=n.at(-1)?.role===`agent`?n.at(-1):null,yn=H||(R?``:String(vn?.error||``)),bn=!R&&n.some(e=>e.role===`user`);(0,Z.useEffect)(()=>{_t(!1),yt(!1),Ct(!1)},[e.id]),(0,Z.useEffect)(()=>{ae&&(jt([ae]),me?.())},[ae,me,jt]),(0,Z.useEffect)(()=>{if(!St)return;let e=e=>{e.key!==`Escape`||e.defaultPrevented||document.querySelector(Ii)||(Ct(!1),Nt.current?.focus())},t=e=>{let t=e.target;t instanceof Element&&!t.closest(Li)&&Ct(!1)};return document.addEventListener(`keydown`,e),document.addEventListener(`pointerdown`,t),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`pointerdown`,t)}},[St]);let xn=async e=>{let t=await W?.(e);if(!t||!ht(t))return;let n=Y.current;requestAnimationFrame(()=>{!n||Y.current!==n||!n.isConnected||(n.focus(),n.style.height=`auto`,n.style.height=`${Math.min(n.scrollHeight,220)}px`)})},$=e=>{ut(e),requestAnimationFrame(()=>{let e=Y.current;e&&(e.focus(),e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,220)}px`)})},Sn={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`)},Cn={attachment:e=>(0,Q.jsx)(en,{cwd:j,selection:pt,menu:e}),resource:e=>(0,Q.jsx)(Bt,{menu:e,label:G(`chat:focusSession.resourcesAndTools`),className:`resource-picker-trigger`,title:G(`chat:resourcePicker.open`),"aria-label":G(`chat:resourcePicker.open`),onClick:()=>_t(!0),children:(0,Q.jsx)(y,{size:16})}),visual:ot?e=>(0,Q.jsx)(cr,{menu:e,notify:pe,onOpenModelSettings:U,onInsertPrompt:$}):null,model:()=>(0,Q.jsx)(Vn,{model:N?.model||l,models:M,onModelChange:ge,thinkingLevel:N?.thinkingLevel||u||`medium`,levels:N?.model?[]:d||[],status:f,message:p,onThinkingChange:_e,onRefreshThinking:ye,modelDisabled:P||F,thinkingDisabled:F||P,deferred:R,pendingModel:!!N?.model}),permission:()=>(0,Q.jsx)(Un,{showLabel:!0,value:m,onChange:xe,disabled:L}),"run-mode":Xe?()=>(0,Q.jsx)(Gn,{mode:Zt,goal:h,teamAvailable:Ze,disabled:R,tokenBudget:Zt===`team`?an:$t,onTokenBudgetChange:Zt===`team`?sn:rn,onSaveTokenBudget:e=>De?.(e),onChange:e=>{h?.status===`active`&&(e===`plan`||e!==h.mode)&&pn().catch(()=>{}),Qt(e),Ce(e)}}):null,commands:e=>(0,Q.jsx)(Bt,{menu:e,label:G(`chat:focusSession.commands`),className:`command-palette-trigger`,title:Ge?G(`chat:focusSession.openCommandPaletteShortcut`,{shortcut:Ge}):G(`chat:focusSession.commands`),"aria-label":Ge?G(`chat:focusSession.openCommandPaletteShortcut`,{shortcut:Ge}):G(`chat:focusSession.commands`),onClick:lt,children:(0,Q.jsx)(kt,{size:16})}),"compact-context":e=>(0,Q.jsx)(wi,{menu:e,streaming:R,compactingManually:ln,compactionActive:!!T?.active,disabled:!we||R||ln||!!T?.active||n.length===0,onCompact:()=>void mn()})},wn=Tn(Rt,_n.filter(e=>Cn[e]!==null),Lt,Je?{permission:2.3,"run-mode":1.8,model:3.6}:{permission:2.6,"run-mode":2,model:3.9}),Dn=(e,t=!1)=>(0,Q.jsx)(`div`,{className:k(`composer-toolbar-slot flex min-w-0 flex-none items-center`,t&&`w-full [&>div]:w-full [&>div>button]:w-full [&>div>button]:justify-start`,e===`model`&&`ml-auto [.composer-tool-tray_&]:ml-0`,!t&&![`model`,`permission`,`run-mode`].includes(e)&&`h-10 [&>button]:!size-10 [&>div]:!size-10 [&>div>button]:!size-10`),"data-composer-tool-id":e,children:Cn[e]?.(t)},e),On=(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-foreground hover:bg-muted disabled:opacity-50 @max-[520px]:size-8 @max-[520px]:shrink-0 @max-[520px]:justify-center @max-[520px]:[&_span]:hidden`,title:j,"aria-label":G(`chat:focusSession.changeWorkingDirectoryWorkspace`,{workspace:j?Qe(j,K):G(`chat:focusSession.noWorkspace`)}),onClick:je,disabled:R||I,children:[(0,Q.jsx)(re,{size:12}),(0,Q.jsx)(`span`,{className:`truncate`,children:j?Qe(j,K):G(`chat:focusSession.noWorkspace`)})]}),An=(0,Q.jsxs)(et,{"data-window-drag-region":!0,"data-context-aside":se&&!ce||void 0,className:k(`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)(ve,{}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1`,"data-window-drag-region":!0,children:[On,(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:Me,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:e.name||G(`navigation:pageHeader.newChat`)}),(0,Q.jsx)(be,{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&&dt(Ye,`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)(ke,{size:16})}),(0,Q.jsx)(ir,{visible:n.length>0,open:vt,sessionId:e.id,streaming:!!R,revision:O,pulseToken:A,onOpenChange:yt,onNavigated:async e=>{e!==null&&$(e),await Ie?.(),Yt()},onCreateChildSession:e=>Pe(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(se?`chat:sessionContext.close`:`chat:sessionContext.open`),title:G(se?`chat:sessionContext.close`:`chat:sessionContext.open`),"aria-expanded":se,"aria-controls":ue,"aria-haspopup":ce?`dialog`:void 0,onPointerDown:()=>{At.current=se},onPointerCancel:()=>{At.current=null},onClick:()=>{let e=At.current??se;At.current=null,de(!e)},children:se?(0,Q.jsx)(Pt,{size:16}):(0,Q.jsx)(Ft,{size:16})}),(0,Q.jsx)(ee,{compact:!0,theme:q,onCycle:Ue})]})]}),jn=(0,Q.jsx)(fe,{emptyState:!Ut&&void 0,layoutMeasurementKey:`fixed`,sessionId:e.id,messages:n,transcriptLoadState:r,messageStart:i,hasOlder:a,loadingOlder:o,olderError:s,currentActivity:v,team:g,activityFeed:b,tools:x,thinkingText:S,compaction:T,streaming:R,runStartedAt:z,lastActivityAt:B,runFinishedAt:te,runStopped:V,runNotice:ne,error:H,scrollRequest:Dt,cwd:j,lineage:e.lineage,switchingCwd:I,onLoadOlder:he,onBranchFromHere:Ne,onCreateChildSession:Pe,onRetryLastTurn:Fe,onPromptSelect:$,onWorkspace:je},`transcript`),Nn=(0,Q.jsxs)(`div`,{ref:Mt,className:`focus-composer-quick-actions flex min-w-0 flex-1 items-end gap-1`,children:[(0,Q.jsx)(`button`,{ref:Nt,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-foreground transition-colors hover:bg-foreground/5 hover:text-foreground ${St?`active bg-foreground/5 text-foreground`:``}`,title:qt,"aria-label":qt,"aria-expanded":St,"aria-controls":Kt,onClick:()=>Ct(e=>!e),children:St?(0,Q.jsx)(Le,{size:17}):(0,Q.jsx)(Se,{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:wn.inline.map(e=>Dn(e))}),(0,Q.jsxs)(En,{placement:`top`,open:St,label:G(`chat:focusSession.quickActions`),trayId:Kt,anchorRef:Nt,menuRef:It,children:[wn.overflow.map(e=>Dn(e,!0)),(0,Q.jsx)(`div`,{className:`my-1 border-t border-border/60`}),(0,Q.jsx)(Bt,{menu:!0,label:G(wt?`chat:focusSession.hideDetails`:`chat:focusSession.details`),"aria-expanded":wt,onClick:()=>{Et(e=>!e),Ct(!1)},children:(0,Q.jsx)(Oe,{size:15})}),(0,Q.jsx)(Mn,{labels:Sn,labeled:!0})]})]}),Pn=(0,Q.jsx)(Fn,{usage:D,plan:J?_:null,compact:Je}),Ln=(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&&(N||P||F)){e.preventDefault();return}hn(e)},children:[(0,Q.jsx)(le,{approvals:ie,onResolve:Ae}),C.length>0&&(0,Q.jsx)(xi,{queuedInputs:C,withdrawingInputIds:w,onWithdraw:W?xn:void 0}),$e&&(0,Q.jsx)(sr,{sessionId:e.id}),un&&(0,Q.jsx)(Si,{invocation:un,onRemove:()=>dn(null)}),(0,Q.jsx)(tn,{attachments:pt.attachments,onRemove:pt.removeAttachment}),pt.attachmentError&&(0,Q.jsx)(`span`,{className:`text-[var(--danger)] text-[13px]`,children:pt.attachmentError}),yn&&(0,Q.jsx)(oe,{error:yn,onRetry:bn?Fe:void 0,className:`w-full`}),(0,Q.jsx)(Ci,{compaction:T,streaming:R,statusLabel:Gt}),(0,Q.jsxs)(`div`,{className:`focus-composer relative flex min-w-0 flex-col gap-2 rounded-[18px] border border-border bg-card p-2.5 shadow-sm 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`,children:[(0,Q.jsx)(gn,{placement:`top`,sessionId:e.id,value:ct,onChange:ut,inputRef:Y}),(0,Q.jsx)(`textarea`,{ref:Y,rows:1,"aria-label":G(`chat:focusSession.taskDescription`),value:ct,onChange:e=>{ut(e.target.value),e.currentTarget.style.height=`auto`,e.currentTarget.style.height=`${Math.min(e.currentTarget.scrollHeight,220)}px`},onPaste:pt.pasteFiles,onCompositionStart:()=>zt.current=!0,onCompositionEnd:()=>window.setTimeout(()=>zt.current=!1,0),onKeyDown:e=>{!(e.nativeEvent.isComposing||zt.current)&&it(e.nativeEvent,We.sendMessage)&&(e.preventDefault(),e.currentTarget.form?.requestSubmit())},"data-mobile-composer-input":Je||void 0,enterKeyHint:Je&&We.sendMessage===`Enter`?`send`:`enter`,placeholder:Jt}),(0,Q.jsxs)(`div`,{className:`focus-composer-footer flex min-w-0 items-end gap-1`,children:[Nn,(0,Q.jsx)(Ti,{streaming:R,queueing:cn,disabled:!R&&(!!N||P||F||cn||!ct.trim()&&!pt.attachments.length&&!un),onAbort:Ve})]})]}),(0,Q.jsxs)(`div`,{className:k(`composer-details flex min-h-9 min-w-0 flex-wrap items-center gap-2 px-2 py-1 text-xs text-muted-foreground`,!wt&&`!hidden`),children:[Vt&&Pn,(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:()=>Et(!1),children:(0,Q.jsx)(Le,{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)(In,{usage:E,sessionUsage:D,model:l,availableModels:M,onThresholdChange:Te,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:()=>xt(!0),children:(0,Q.jsx)(Tt,{size:17})}),(0,Q.jsx)(Yr,{sessionId:e.id,shortcutEnabled:t,onLiveText:e=>{if(e===null){X.current!==null&&(Xt(X.current),X.current=null);return}X.current===null&&(X.current=(Y.current?.value??ct).trimEnd());let t=X.current;Xt(t&&e?`${t}\n${e}`:t||e)},onInsert:e=>{let t=X.current??(Y.current?.value??ct).trimEnd();X.current=null,Xt(t?`${t}\n${e}`:e),requestAnimationFrame(()=>Y.current?.focus())}})]})]})]}),!Vt&&!Ut&&!R&&(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(Fi,{plansAvailable:J,onPromptSelect:$})})]},`composer`);return(0,Q.jsxs)(tt,{ref:Ht.ref,className:k(`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 ${Vt?`has-conversation`:`is-empty`}`,Wt&&`[&_[data-chat-region=messages]]:!flex-none [&_[data-chat-region=messages]]:mt-[max(48px,calc((var(--session-viewport-height,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:k(`flex h-full min-h-0 min-w-0 flex-1 flex-col`,Vt?`overflow-hidden`:`overflow-auto`),children:[(0,Q.jsx)(`div`,{className:`shrink-0`,"data-chat-region":`header`,children:An}),(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,"data-chat-region":`messages`,children:jn}),(0,Q.jsx)(`div`,{className:`shrink-0`,"data-chat-region":`composer`,children:Ln})]}),(0,Q.jsx)(nn,{open:gt,sessionId:e.id,onClose:()=>_t(!1),onSelect:dn,onCommandSelect:e=>$(on(e,ct))}),(0,Q.jsx)(vi,{open:bt,sessionId:e.id,sessionName:e.name||e.id,messages:n,streaming:R,sendPrompt:ze,onAbort:Ve,onClose:()=>xt(!1)})]})}),zi=(0,Z.createContext)(null),Bi=40,Vi=[];function Hi({params:e,api:t}){let n=(0,Z.useContext)(zi),r=e?.sessionId||ct(t?.id),[i,a]=(0,Z.useState)(()=>t.isVisible),[o,s]=(0,Z.useState)(()=>t.isActive);return(0,Z.useEffect)(()=>{s(t.isActive);let e=t.onDidActiveChange(({isActive:e})=>s(e));return()=>e.dispose()},[t]),(0,Z.useEffect)(()=>{a(t.isVisible);let e=t.onDidVisibilityChange(({isVisible:e})=>a(e));return()=>e.dispose()},[t]),i?(0,Q.jsx)(Wi,{sessionId:r,panelId:t.id,shortcutEnabled:o,onFocusCapture:()=>t.setActive(),canSplitPanel:n?.compactDock===!1&&t.group.size>1,canClosePanel:!0}):null}function Ui({onCreateSession:e}){let t=(0,Z.useContext)(zi)?.activeId||``;return t?(0,Q.jsx)(Wi,{sessionId:t,panelId:`single-${t}`,shortcutEnabled:!0,canSplitPanel:!1,canClosePanel:!1},t):(0,Q.jsx)(Gi,{onNewSession:e})}function Wi({sessionId:e,panelId:t,shortcutEnabled:n,onFocusCapture:r,canSplitPanel:i,canClosePanel:a}){let o=(0,Z.useContext)(zi),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||de,m=U(p,f),h=me(d,f),g=d&&Object.hasOwn(d,`team`)?d.team:f?.team??null,_=se(h,{streaming:m})?h:null,v=o?.sessionTreePulseSessionId===e?o.sessionTreePulseToken:0,y=o?.loadSessionMessages,b=o?.loadSessionThinkingLevel,x=p.model||f?.model||o?.defaultModel||``,S=p.thinkingModel===x;(0,Z.useEffect)(()=>{e&&y?.(e,{limit:Bi})},[y,e]),(0,Z.useEffect)(()=>{!e||!f||!b||p.switchingModel||p.switchingThinking||S&&p.thinkingStatus||b(e,x)},[b,x,S,p.switchingModel,p.switchingThinking,f,e,p.availableThinkingLevels,p.thinkingStatus,m]);let C=(0,Z.useMemo)(()=>({onLoadOlder:()=>o?.loadOlderMessages(e)??!1,onModelChange:t=>o?.switchSessionModel(e,t),onThinkingLevelChange:t=>o?.switchSessionThinkingLevel(e,t),onLoadThinkingLevel:()=>b?.(e,x),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,b,x]);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)(Ne,{size:16}),o?`Session unavailable`:`Loading session`]});let w=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)(Ri,{session:f,shortcutEnabled:n,messages:p.messages||Vi,transcriptLoadState:p.loaded?`ready`:p.loading||!p.error?`loading`:`error`,messageStart:p.messageStart,hasOlder:p.hasOlder,loadingOlder:p.loadingOlder,olderError:p.olderError,model:x,thinkingLevel:p.thinkingLevel||f.thinkingLevel||`medium`,availableThinkingLevels:S&&p.availableThinkingLevels||Vi,thinkingStatus:S&&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||Vi,tools:p.tools||Vi,thinkingText:p.thinkingText||``,queuedInputs:p.queuedInputs||Vi,withdrawingInputIds:p.withdrawingInputIds||Vi,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||Vi,error:p.error||(o.activeId===e?o.globalError:``),pendingAsset:w,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,...C})})}function Gi({onNewSession:e,newSessionShortcut:t}){let{t:n}=c(),r=(0,Z.useContext)(zi),[i,a]=(0,Z.useState)(!1),o=(0,Z.useRef)(!1),s=(0,Z.useRef)(!0);(0,Z.useEffect)(()=>(s.current=!0,()=>{s.current=!1}),[]);let l=async()=>{if(!(!e||o.current)){o.current=!0,a(!0);try{await e()}finally{o.current=!1,s.current&&a(!1)}}};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)(_e,{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`)}),r?.globalError&&(0,Q.jsx)(oe,{error:r.globalError,className:`w-[min(420px,calc(100%_-_32px))]`}),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)]`,disabled:i,"aria-busy":i,onClick:()=>void l(),children:[i?(0,Q.jsx)(ge,{size:14,"aria-hidden":`true`,className:`animate-spin`}):(0,Q.jsx)(Se,{size:14,"aria-hidden":`true`}),i?n(`chat:chatDock.creatingChat`):r?.globalError?n(`chat:chatDock.retryNewChat`):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]})}var Ki=`web-preview`;function qi(e,t=`Web preview`){try{return new URL(e).hostname.replace(/^www\./i,``)||t}catch{return t}}export{Ui as a,di as c,Hi as i,un as l,qi as n,zi as o,Gi as r,ui as s,Ki as t};
552
+ `;async function Wr(e){let t=new Blob([Ur],{type:`application/javascript`}),n=URL.createObjectURL(t);try{await e.audioWorklet.addModule(n)}finally{URL.revokeObjectURL(n)}}async function Gr(e,t){if(W(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(W(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 Wr(r),f(),a=r.createMediaStreamSource(n),i=new AudioWorkletNode(r,`pisper-voice-input`,{numberOfInputs:1,numberOfOutputs:1,outputChannelCount:[1],processorOptions:{targetSampleRate:Fr}}),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 Kr=32,qr=50;function Jr(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 Yr({onInsert:e,onLiveText:t,sessionId:n,disabled:r=!1,shortcutEnabled:i=!1}){let{t:a}=c(),o=br([`asr`]),s=at(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)(fr()),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<Kr;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,qr);return()=>window.clearInterval(t)},[l]);let ee=()=>!r&&(p.current===`idle`||p.current===`error`),B=async()=>{if(!ee())return;let e=++y.current,t=new AbortController;_.current=t,S.current=!1,m(`requesting`),f(``),D.current.reset();let r=Hr({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=Jr(t,a(`chat:voiceInput.failed`));L(r===`permission`?a(`chat:voiceInput.permissionDenied`):r)};try{window.__PISPER_MOBILE_APP__&&(w.current=e);try{await Rr()}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 vr(),e!==y.current){i.dispose();return}M.current=i;let n=i,c=await Gr(t=>{if(e!==y.current)return;O.current=D.current.push(dr(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)}},te=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=Jr(t,a(`chat:voiceInput.failed`));L(n===`permission`?a(`chat:voiceInput.permissionDenied`):n),S.current=!1}};x.current=()=>void te(),ur({enabled:i&&!r,binding:s,onStart:()=>ee()?(B(),C.current=y.current,!0):!1,onRelease:()=>{C.current===y.current&&(g.current?te():z())},onCancel:()=>{C.current===y.current&&z()}});let V=l===`recording`?a(`chat:voiceInput.stop`):l===`requesting`?a(`chat:voiceInput.close`):l===`error`?d:a(`chat:voiceInput.open`),ne=s&&l!==`error`?`${V} (${ot(s)})`:V;return(0,Q.jsxs)(`div`,{className:`relative flex flex-none items-center`,children:[l===`recording`&&(0,pn.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,pn.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)(X,{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 te():l===`requesting`?()=>z():()=>void B(),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)(X,{size:17}):l===`transcribing`||l===`requesting`?(0,Q.jsx)(ge,{className:`animate-spin`,size:17}):l===`error`?(0,Q.jsx)(X,{size:17}):(0,Q.jsx)(Mt,{size:17})]}),(0,Q.jsx)(Pr,{manager:o,onClose:()=>{}})]})}var Xr={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`}},Zr=64,Qr=96,$r=2.6,ei=Math.PI*2,ti={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 ni(e,t,n){let r=Math.sin(e*127.1+t*311.7+n*74.7)*43758.5453123;return r-Math.floor(r)}function ri(e){return e*e*(3-2*e)}function ii(e,t,n){let r=Math.floor(e),i=Math.floor(t),a=Math.floor(n),o=ri(e-r),s=ri(t-i),c=ri(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)*ni(r+e,i+t,a+n);return l}function ai(e){return 1+2.70158*(e-1)**3+1.70158*(e-1)**2}function oi(e){let t=e*.9%1;return Math.exp(-(((t-.12)*9)**2))+.45*Math.exp(-(((t-.34)*9)**2))}function si({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(Zr),l=new Float32Array(Zr);for(let e=0;e<Zr;e+=1){let t=-Math.PI/2+(e+.5)/Zr*Math.PI;c[e]=Math.sin(t),l[e]=Math.cos(t)}let u=new Float32Array(Qr),d=new Float32Array(Qr);for(let e=0;e<Qr;e+=1){let t=e/Qr*ei;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={...Xr[a.current]},x=0,S=0,C=0,w=e=>{let r=Math.min((e-g)/1e3,.05);g=e;let i=Xr[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=ai(Math.min(1,Math.max(0,(e-_)/900))),A=b.behavior===`beat`?O:oi(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=ti[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,ee=b.freq,B=b.amp*j,te=b.spike*(O+C),V=p*j,ne=Math.floor(v*15),re=b.dim*(.72+.5*A)+C*.3;t.globalCompositeOperation=M.composite;for(let e=0;e<Zr;e+=1){let n=c[e],r=l[e];for(let i=0;i<Qr;i+=1){let a=r*u[i],o=n,s=r*d[i],c=ii(a*ee+z,o*ee+z*.7,s*ee)-.5,l=1+c*2*B;b.behavior===`reactive`?l+=Math.max(c,0)**2*1.7*te:b.behavior===`swirl`?l+=.03*Math.sin(9*a+v*4.6):b.behavior===`jitter`&&(l+=.02*(ni(e*Qr+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=$r/($r-x),C=f+g*S*V,w=f+y*S*V,T=(x+1)/2,E=ii(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+te*.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 ci=new Map;function li(e,t){let n=ci.get(e)??new Set;return n.add(t),ci.set(e,n),()=>{n.delete(t),n.size||ci.delete(e)}}function ui(e){for(let t of ci.get(e.sessionId)??[])t(e)}function di(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);ui({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 fi(e){let t=``,n=0,r=!1,i,a,o=()=>{a?.(),a=void 0},s=()=>{i=Ve(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(W(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 pi(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),W(e.signal),!0);let{hotwords:r}=await Ct(t,e.signal);await bt({kinds:[`asr`,`tts`],hotwords:r},e.signal),W(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=fi(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=li(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(()=>(W(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 ee(){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 B(){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=fr(),r=0;try{if(await x.current,!k(e)||(await M(),!k(e)))return;if(A()){I();return}e.permissionPending=!0;try{await Rr()}finally{e.permissionPending=!1}if(!k(e))return;if(document.hidden||A()){I();return}let n=await vr();if(!k(e)){n.dispose();return}e.endpoint=n;let i=Hr({chatSessionId:e.sessionId});if(e.recognizer=i,e.unsubscribe=i.onPartial(t=>{k(e)&&l(t)}),await i.start(),!k(e)||(e.capturePending=Gr(a=>{if(!(!k(e)||e.committed||e.microphone.signal.aborted))try{let s=t.push(dr(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:B,commit:ee,stop:I};let te=(0,Z.useCallback)(()=>D.current.commit(),[]),V=(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`?V():(v.current===`idle`||v.current===`error`)&&(T.current=!1,h(!1),D.current.start())},[V]),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:te,interrupt:V}}function mi(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 hi(e){let t=Math.floor(e/60),n=e%60;return`${t.toString().padStart(2,`0`)}:${n.toString().padStart(2,`0`)}`}function gi(){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 _i(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 vi({open:e,sessionId:t,messages:n,streaming:r,sendPrompt:i,onAbort:a,onClose:o}){let{t:s}=c(),l=gi(),u=br([`asr`,`tts`]),d=pi({open:e,sessionId:t,messages:n,streaming:r,sendPrompt:i,onAbort:a,ensureReady:u.ensureReady,speakText:(e,t,n)=>Dr(e,u.selectedVoice,t,n)}),{stage:f,level:p,partial:m,turns:h,error:g,elapsed:_}=d,v=_i(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=mi(s),C=h[h.length-1],w=f===`listening`&&m?m:C?`${C.role,``}${pr(C.text,120)}`:``,T=f===`error`?g||s(`chat:voiceMode.failed`):S[f];return(0,pn.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)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{variant:`ghost`,size:`icon-sm`,"aria-label":s(`chat:speechModels.title`),onClick:()=>{d.hangUp(),u.show()},children:(0,Q.jsx)(Tt,{})})}),(0,Q.jsx)(D,{children:s(`chat:speechModels.title`)})]}),(0,Q.jsxs)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{variant:`ghost`,size:`icon-sm`,className:`size-11 flex-none`,"aria-label":s(`chat:speechModels.close`),onClick:b,children:(0,Q.jsx)(Le,{})})}),(0,Q.jsx)(D,{children:s(`chat:speechModels.close`)})]})]}),(0,Q.jsx)(Pr,{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)(si,{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:hi(_)})]}),(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)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{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)(Ae,{}):d.muted?(0,Q.jsx)(X,{}):(0,Q.jsx)(Mt,{})})}),(0,Q.jsx)(D,{children:f===`speaking`||f===`thinking`?s(`chat:voiceMode.interrupt`):d.muted?s(`chat:voiceMode.unmute`):s(`chat:voiceMode.mute`)})]})})]}),document.body)}var yi=({className:e,defaultOpen:t=!0,...n})=>(0,Q.jsx)(f,{className:k(e),defaultOpen:t,...n}),bi=(0,Z.lazy)(()=>t(()=>import(`./ShinyText-DqxsUc3F.js`).then(e=>({default:e.ShinyText})),__vite__mapDeps([18,4,2,19,8,20])));function xi({queuedInputs:e,withdrawingInputIds:t=[],onWithdraw:n}){let{t:r}=c(),i=r(`chat:focusSession.sentToTheRunningAgent`),a=r(`chat:focusSession.withdrawQueuedInput`);return(0,Q.jsx)(yi,{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)(O,{children:[(0,Q.jsx)(E,{asChild:!0,children:(0,Q.jsx)(K,{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)(Pe,{size:16,"aria-hidden":`true`})})}),(0,Q.jsx)(D,{children:a})]})]},i||`${e.behavior}-${r}`)})})]})})}function Si({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)(Ie,{size:13}):(0,Q.jsx)(y,{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)(Le,{size:13})})]})}function Ci({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)(bi,{children:n||r(`chat:focusSession.running`)},n||`running`)}):r(`chat:focusSession.waitingForInput`)})]})}function wi({menu:e=!1,streaming:t,compactingManually:n,compactionActive:r,disabled:i,onCompact:a}){let{t:o}=c();return(0,Q.jsx)(Bt,{menu:e,label:o(`chat:focusSession.compactContextNow`),className:`compact-context-trigger`,title:o(t?`chat:focusSession.manualCompactionWaitForRun`:n||r?`chat:focusSession.compactingContext`:`chat:focusSession.compactContextNow`),"aria-label":o(`chat:focusSession.compactContextNow`),disabled:i,onClick:a,children:n||r?(0,Q.jsx)(Ce,{className:`animate-spin`,size:14}):(0,Q.jsx)(Nt,{size:14})})}function Ti({streaming:e,queueing:t,disabled:n,onAbort:r}){let{t:i}=c(),a=rt(`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)(Ae,{size:12,fill:`currentColor`}):t?(0,Q.jsx)(Ce,{className:`animate-spin`,size:17}):(0,Q.jsx)(m,{size:17})})}function Ei({streaming:e,messages:t,currentActivity:n,thinkingText:r,compaction:i,error:a,runStopped:o,runNotice:s,lastActivityAt:c},l){return(0,Z.useMemo)(()=>ue({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 Di=36,Oi=40;function ki(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:Di);n(Math.max(0,r/Oi))};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 Ai=560;function ji(){let e=(0,Z.useRef)(null),[t,n]=(0,Z.useState)(!1);return(0,Z.useLayoutEffect)(()=>{let t=e.current;if(!t)return;let r=()=>{let e=t.clientHeight;e<=0||(t.style.setProperty(`--session-viewport-height`,`${e}px`),n(e<Ai))};if(r(),typeof ResizeObserver>`u`)return window.addEventListener(`resize`,r),()=>window.removeEventListener(`resize`,r);let i=new ResizeObserver(r);return i.observe(t),()=>i.disconnect()},[]),{ref:e,compact:t}}var Mi=[`plan`,`goal`,`team`];function Ni(e){return Mi.includes(e)?e:`plan`}function Pi({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)(()=>Ni(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(Ni(b.current)),T.current=null,S(null),w(null),D(!1),k(!1),j(null)},[e]),(0,Z.useEffect)(()=>{y(Ni(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 Fi=(0,Z.lazy)(()=>t(()=>import(`./QuickPromptIdeas-Bs-udcSZ.js`),__vite__mapDeps([21,4,2,22,14,3,15,16,17,23,24,25,26,27,28,29]))),Ii=[`.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(`, `),Li=[`.composer-tools-trigger`,`.composer-tool-tray-shell`,Ii].join(`, `),Ri=(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:b,tools:x,thinkingText:S,queuedInputs:C,withdrawingInputIds:w,compaction:T,contextUsage:E,sessionUsage:D,sessionTreeRevision:O,sessionTreePulse:A,cwd:j,availableModels:M,pendingRuntimeSelection:N,switchingModel:P,switchingThinking:F,switchingCwd:I,switchingPermission:L,streaming:R,runStartedAt:z,lastActivityAt:B,runFinishedAt:te,runStopped:V,runNotice:ne,approvals:ie,error:H,pendingAsset:ae,contextOpen:se,contextCompact:ce,contextPanelId:ue,onToggleContext:de,notify:pe,onOpenModelSettings:U,onAssetConsumed:me,onLoadOlder:he,onModelChange:ge,onThinkingLevelChange:_e,onLoadThinkingLevel:ye,onExecutionModeChange:xe,onRunModeChange:Ce,onCompact:we,onCompactionThresholdChange:Te,onGoalPause:Ee,onGoalBudgetChange:De,onApproval:Ae,onWorkspace:je,onRename:Me,onBranchFromHere:Ne,onCreateChildSession:Pe,onRetryLastTurn:Fe,onTreeNavigated:Ie,onSend:ze,onQueue:Be,onWithdrawQueuedInput:W,onAbort:Ve}){let{t:G,language:K}=c(),Ue=st(e=>e.cycleTheme),q=st(e=>e.theme),We=at(e=>e.bindings),Ge=rt(`commandPalette`),Ke=He(),qe=Re(),Je=Ke||qe,Ye=ft(e=>e.capabilities),Xe=dt(Ye,`goals`),Ze=dt(Ye,`multiAgent`),J=dt(Ye,`plans`),$e=dt(Ye,`workflows`),ot=dt(Ye,`visualGeneration`),{value:ct,updateValue:ut,selection:pt,clearDraft:mt,restoreDraft:ht}=fn(e.id),[gt,_t]=(0,Z.useState)(!1),[vt,yt]=(0,Z.useState)(!1),[bt,xt]=(0,Z.useState)(!1),[St,Ct]=(0,Z.useState)(!1),[wt,Et]=(0,Z.useState)(!1),[Dt,Ot]=(0,Z.useState)(0),At=(0,Z.useRef)(null),jt=pt.addAttachments,Y=(0,Z.useRef)(null),X=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!t)return;let e=e=>{!nt(e)&&it(e,We.voiceInput)&&Et(!0),!nt(e)&&it(e,We.focusComposer)&&(e.preventDefault(),Y.current?.focus())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,We.focusComposer,We.voiceInput]);let Mt=(0,Z.useRef)(null),Nt=(0,Z.useRef)(null),It=(0,Z.useRef)(null),Lt=ki(Mt),Rt=kn(e=>e.layout),zt=(0,Z.useRef)(!1),Vt=r!==`ready`||n.length>0,Ht=ji(),Ut=!Vt&&Ht.compact,Wt=!Vt&&!Ut,Gt=Ei({streaming:R,messages:n,currentActivity:v,thinkingText:S,compaction:T,error:H,runStopped:V,runNotice:ne,lastActivityAt:B},G),Kt=`composer-tool-tray-${e.id}`,qt=G(St?`chat:focusSession.collapseQuickActions`:`chat:focusSession.expandQuickActions`),Jt=G(Je?R?`chat:focusSession.addGuidanceForTheRunningAgent`:`chat:workbench.composerPlaceholder`:R?`chat:focusSession.runningAgentComposerHint`:`chat:focusSession.composerHint`),Yt=()=>Ot(e=>e+1),Xt=e=>{ut(e),requestAnimationFrame(()=>{let e=Y.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,220)}px`)})},{composerExecutionMode:Zt,setComposerExecutionMode:Qt,goalTokenBudget:$t,setGoalTokenBudget:rn,teamTokenBudget:an,setTeamTokenBudget:sn,queueing:cn,compactingManually:ln,invocation:un,setInvocation:dn,requestGoalPause:pn,compactContext:mn,submit:hn}=Pi({sessionId:e.id,runMode:e.runMode,goalsAvailable:Xe,teamAvailable:Ze,workflowsAvailable:$e,goal:h,streaming:R,compaction:T,value:ct,selection:pt,clearDraft:mt,promptRef:Y,onCompact:we,onGoalPause:Ee,onSend:ze,onQueue:Be,setToolsOpen:Ct,requestTranscriptBottom:Yt}),vn=n.at(-1)?.role===`agent`?n.at(-1):null,yn=H||(R?``:String(vn?.error||``)),bn=!R&&n.some(e=>e.role===`user`);(0,Z.useEffect)(()=>{_t(!1),yt(!1),Ct(!1)},[e.id]),(0,Z.useEffect)(()=>{ae&&(jt([ae]),me?.())},[ae,me,jt]),(0,Z.useEffect)(()=>{if(!St)return;let e=e=>{e.key!==`Escape`||e.defaultPrevented||document.querySelector(Ii)||(Ct(!1),Nt.current?.focus())},t=e=>{let t=e.target;t instanceof Element&&!t.closest(Li)&&Ct(!1)};return document.addEventListener(`keydown`,e),document.addEventListener(`pointerdown`,t),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`pointerdown`,t)}},[St]);let xn=async e=>{let t=await W?.(e);if(!t||!ht(t))return;let n=Y.current;requestAnimationFrame(()=>{!n||Y.current!==n||!n.isConnected||(n.focus(),n.style.height=`auto`,n.style.height=`${Math.min(n.scrollHeight,220)}px`)})},$=e=>{ut(e),requestAnimationFrame(()=>{let e=Y.current;e&&(e.focus(),e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,220)}px`)})},Sn={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`)},Cn={attachment:e=>(0,Q.jsx)(en,{cwd:j,selection:pt,menu:e}),resource:e=>(0,Q.jsx)(Bt,{menu:e,label:G(`chat:focusSession.resourcesAndTools`),className:`resource-picker-trigger`,title:G(`chat:resourcePicker.open`),"aria-label":G(`chat:resourcePicker.open`),onClick:()=>_t(!0),children:(0,Q.jsx)(y,{size:16})}),visual:ot?e=>(0,Q.jsx)(cr,{menu:e,notify:pe,onOpenModelSettings:U,onInsertPrompt:$}):null,model:()=>(0,Q.jsx)(Vn,{model:N?.model||l,models:M,onModelChange:ge,thinkingLevel:N?.thinkingLevel||u||`medium`,levels:N?.model?[]:d||[],status:f,message:p,onThinkingChange:_e,onRefreshThinking:ye,modelDisabled:P||F,thinkingDisabled:F||P,deferred:R,pendingModel:!!N?.model}),permission:()=>(0,Q.jsx)(Un,{showLabel:!0,value:m,onChange:xe,disabled:L}),"run-mode":Xe?()=>(0,Q.jsx)(Gn,{mode:Zt,goal:h,teamAvailable:Ze,disabled:R,tokenBudget:Zt===`team`?an:$t,onTokenBudgetChange:Zt===`team`?sn:rn,onSaveTokenBudget:e=>De?.(e),onChange:e=>{h?.status===`active`&&(e===`plan`||e!==h.mode)&&pn().catch(()=>{}),Qt(e),Ce(e)}}):null,commands:e=>(0,Q.jsx)(Bt,{menu:e,label:G(`chat:focusSession.commands`),className:`command-palette-trigger`,title:Ge?G(`chat:focusSession.openCommandPaletteShortcut`,{shortcut:Ge}):G(`chat:focusSession.commands`),"aria-label":Ge?G(`chat:focusSession.openCommandPaletteShortcut`,{shortcut:Ge}):G(`chat:focusSession.commands`),onClick:lt,children:(0,Q.jsx)(kt,{size:16})}),"compact-context":e=>(0,Q.jsx)(wi,{menu:e,streaming:R,compactingManually:ln,compactionActive:!!T?.active,disabled:!we||R||ln||!!T?.active||n.length===0,onCompact:()=>void mn()})},wn=Tn(Rt,_n.filter(e=>Cn[e]!==null),Lt,Je?{permission:2.3,"run-mode":1.8,model:3.6}:{permission:2.6,"run-mode":2,model:3.9}),Dn=(e,t=!1)=>(0,Q.jsx)(`div`,{className:k(`composer-toolbar-slot flex min-w-0 flex-none items-center`,t&&`w-full [&>div]:w-full [&>div>button]:w-full [&>div>button]:justify-start`,e===`model`&&`ml-auto [.composer-tool-tray_&]:ml-0`,!t&&![`model`,`permission`,`run-mode`].includes(e)&&`h-10 [&>button]:!size-10 [&>div]:!size-10 [&>div>button]:!size-10`),"data-composer-tool-id":e,children:Cn[e]?.(t)},e),On=(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-foreground hover:bg-muted disabled:opacity-50 @max-[520px]:size-8 @max-[520px]:shrink-0 @max-[520px]:justify-center @max-[520px]:[&_span]:hidden`,title:j,"aria-label":G(`chat:focusSession.changeWorkingDirectoryWorkspace`,{workspace:j?Qe(j,K):G(`chat:focusSession.noWorkspace`)}),onClick:je,disabled:R||I,children:[(0,Q.jsx)(re,{size:12}),(0,Q.jsx)(`span`,{className:`truncate`,children:j?Qe(j,K):G(`chat:focusSession.noWorkspace`)})]}),An=(0,Q.jsxs)(et,{"data-window-drag-region":!0,"data-context-aside":se&&!ce||void 0,className:k(`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)(ve,{}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1`,"data-window-drag-region":!0,children:[On,(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:Me,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:e.name||G(`navigation:pageHeader.newChat`)}),(0,Q.jsx)(be,{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&&dt(Ye,`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)(ke,{size:16})}),(0,Q.jsx)(ir,{visible:n.length>0,open:vt,sessionId:e.id,streaming:!!R,revision:O,pulseToken:A,onOpenChange:yt,onNavigated:async e=>{e!==null&&$(e),await Ie?.(),Yt()},onCreateChildSession:e=>Pe(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(se?`chat:sessionContext.close`:`chat:sessionContext.open`),title:G(se?`chat:sessionContext.close`:`chat:sessionContext.open`),"aria-expanded":se,"aria-controls":ue,"aria-haspopup":ce?`dialog`:void 0,onPointerDown:()=>{At.current=se},onPointerCancel:()=>{At.current=null},onClick:()=>{let e=At.current??se;At.current=null,de(!e)},children:se?(0,Q.jsx)(Pt,{size:16}):(0,Q.jsx)(Ft,{size:16})}),(0,Q.jsx)(ee,{compact:!0,theme:q,onCycle:Ue})]})]}),jn=(0,Q.jsx)(fe,{emptyState:!Ut&&void 0,layoutMeasurementKey:`fixed`,sessionId:e.id,messages:n,transcriptLoadState:r,messageStart:i,hasOlder:a,loadingOlder:o,olderError:s,currentActivity:v,team:g,activityFeed:b,tools:x,thinkingText:S,compaction:T,streaming:R,runStartedAt:z,lastActivityAt:B,runFinishedAt:te,runStopped:V,runNotice:ne,error:H,scrollRequest:Dt,cwd:j,lineage:e.lineage,switchingCwd:I,onLoadOlder:he,onBranchFromHere:Ne,onCreateChildSession:Pe,onRetryLastTurn:Fe,onPromptSelect:$,onWorkspace:je},`transcript`),Nn=(0,Q.jsxs)(`div`,{ref:Mt,className:`focus-composer-quick-actions flex min-w-0 flex-1 items-end gap-1`,children:[(0,Q.jsx)(`button`,{ref:Nt,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-foreground transition-colors hover:bg-foreground/5 hover:text-foreground ${St?`active bg-foreground/5 text-foreground`:``}`,title:qt,"aria-label":qt,"aria-expanded":St,"aria-controls":Kt,onClick:()=>Ct(e=>!e),children:St?(0,Q.jsx)(Le,{size:17}):(0,Q.jsx)(Se,{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:wn.inline.map(e=>Dn(e))}),(0,Q.jsxs)(En,{placement:`top`,open:St,label:G(`chat:focusSession.quickActions`),trayId:Kt,anchorRef:Nt,menuRef:It,children:[wn.overflow.map(e=>Dn(e,!0)),(0,Q.jsx)(`div`,{className:`my-1 border-t border-border/60`}),(0,Q.jsx)(Bt,{menu:!0,label:G(wt?`chat:focusSession.hideDetails`:`chat:focusSession.details`),"aria-expanded":wt,onClick:()=>{Et(e=>!e),Ct(!1)},children:(0,Q.jsx)(Oe,{size:15})}),(0,Q.jsx)(Mn,{labels:Sn,labeled:!0})]})]}),Pn=(0,Q.jsx)(Fn,{usage:D,plan:J?_:null,compact:Je}),Ln=(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&&(N||P||F)){e.preventDefault();return}hn(e)},children:[(0,Q.jsx)(le,{approvals:ie,onResolve:Ae}),C.length>0&&(0,Q.jsx)(xi,{queuedInputs:C,withdrawingInputIds:w,onWithdraw:W?xn:void 0}),$e&&(0,Q.jsx)(sr,{sessionId:e.id}),un&&(0,Q.jsx)(Si,{invocation:un,onRemove:()=>dn(null)}),(0,Q.jsx)(tn,{attachments:pt.attachments,onRemove:pt.removeAttachment}),pt.attachmentError&&(0,Q.jsx)(`span`,{className:`text-[var(--danger)] text-[13px]`,children:pt.attachmentError}),yn&&(0,Q.jsx)(oe,{error:yn,onRetry:bn?Fe:void 0,className:`w-full`}),(0,Q.jsx)(Ci,{compaction:T,streaming:R,statusLabel:Gt}),(0,Q.jsxs)(`div`,{className:`focus-composer relative flex min-w-0 flex-col gap-2 rounded-[18px] border border-border bg-card p-2.5 shadow-sm 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`,children:[(0,Q.jsx)(gn,{placement:`top`,sessionId:e.id,value:ct,onChange:ut,inputRef:Y}),(0,Q.jsx)(`textarea`,{ref:Y,rows:1,"aria-label":G(`chat:focusSession.taskDescription`),value:ct,onChange:e=>{ut(e.target.value),e.currentTarget.style.height=`auto`,e.currentTarget.style.height=`${Math.min(e.currentTarget.scrollHeight,220)}px`},onPaste:pt.pasteFiles,onCompositionStart:()=>zt.current=!0,onCompositionEnd:()=>window.setTimeout(()=>zt.current=!1,0),onKeyDown:e=>{!(e.nativeEvent.isComposing||zt.current)&&it(e.nativeEvent,We.sendMessage)&&(e.preventDefault(),e.currentTarget.form?.requestSubmit())},"data-mobile-composer-input":Je||void 0,enterKeyHint:Je&&We.sendMessage===`Enter`?`send`:`enter`,placeholder:Jt}),(0,Q.jsxs)(`div`,{className:`focus-composer-footer flex min-w-0 items-end gap-1`,children:[Nn,(0,Q.jsx)(Ti,{streaming:R,queueing:cn,disabled:!R&&(!!N||P||F||cn||!ct.trim()&&!pt.attachments.length&&!un),onAbort:Ve})]})]}),(0,Q.jsxs)(`div`,{className:k(`composer-details flex min-h-9 min-w-0 flex-wrap items-center gap-2 px-2 py-1 text-xs text-muted-foreground`,!wt&&`!hidden`),children:[Vt&&Pn,(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:()=>Et(!1),children:(0,Q.jsx)(Le,{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)(In,{usage:E,sessionUsage:D,model:l,availableModels:M,onThresholdChange:Te,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:()=>xt(!0),children:(0,Q.jsx)(Tt,{size:17})}),(0,Q.jsx)(Yr,{sessionId:e.id,shortcutEnabled:t,onLiveText:e=>{if(e===null){X.current!==null&&(Xt(X.current),X.current=null);return}X.current===null&&(X.current=(Y.current?.value??ct).trimEnd());let t=X.current;Xt(t&&e?`${t}\n${e}`:t||e)},onInsert:e=>{let t=X.current??(Y.current?.value??ct).trimEnd();X.current=null,Xt(t?`${t}\n${e}`:e),requestAnimationFrame(()=>Y.current?.focus())}})]})]})]}),!Vt&&!Ut&&!R&&(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(Fi,{plansAvailable:J,onPromptSelect:$})})]},`composer`);return(0,Q.jsxs)(tt,{ref:Ht.ref,className:k(`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 ${Vt?`has-conversation`:`is-empty`}`,Wt&&`[&_[data-chat-region=messages]]:!flex-none [&_[data-chat-region=messages]]:mt-[max(48px,calc((var(--session-viewport-height,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:k(`flex h-full min-h-0 min-w-0 flex-1 flex-col`,Vt?`overflow-hidden`:`overflow-auto`),children:[(0,Q.jsx)(`div`,{className:`shrink-0`,"data-chat-region":`header`,children:An}),(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,"data-chat-region":`messages`,children:jn}),(0,Q.jsx)(`div`,{className:`shrink-0`,"data-chat-region":`composer`,children:Ln})]}),(0,Q.jsx)(nn,{open:gt,sessionId:e.id,onClose:()=>_t(!1),onSelect:dn,onCommandSelect:e=>$(on(e,ct))}),(0,Q.jsx)(vi,{open:bt,sessionId:e.id,sessionName:e.name||e.id,messages:n,streaming:R,sendPrompt:ze,onAbort:Ve,onClose:()=>xt(!1)})]})}),zi=(0,Z.createContext)(null),Bi=40,Vi=[];function Hi({params:e,api:t}){let n=(0,Z.useContext)(zi),r=e?.sessionId||ct(t?.id),[i,a]=(0,Z.useState)(()=>t.isVisible),[o,s]=(0,Z.useState)(()=>t.isActive);return(0,Z.useEffect)(()=>{s(t.isActive);let e=t.onDidActiveChange(({isActive:e})=>s(e));return()=>e.dispose()},[t]),(0,Z.useEffect)(()=>{a(t.isVisible);let e=t.onDidVisibilityChange(({isVisible:e})=>a(e));return()=>e.dispose()},[t]),i?(0,Q.jsx)(Wi,{sessionId:r,panelId:t.id,shortcutEnabled:o,onFocusCapture:()=>t.setActive(),canSplitPanel:n?.compactDock===!1&&t.group.size>1,canClosePanel:!0}):null}function Ui({onCreateSession:e}){let t=(0,Z.useContext)(zi)?.activeId||``;return t?(0,Q.jsx)(Wi,{sessionId:t,panelId:`single-${t}`,shortcutEnabled:!0,canSplitPanel:!1,canClosePanel:!1},t):(0,Q.jsx)(Gi,{onNewSession:e})}function Wi({sessionId:e,panelId:t,shortcutEnabled:n,onFocusCapture:r,canSplitPanel:i,canClosePanel:a}){let o=(0,Z.useContext)(zi),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||de,m=U(p,f),h=me(d,f),g=d&&Object.hasOwn(d,`team`)?d.team:f?.team??null,_=se(h,{streaming:m})?h:null,v=o?.sessionTreePulseSessionId===e?o.sessionTreePulseToken:0,y=o?.loadSessionMessages,b=o?.loadSessionThinkingLevel,x=p.model||f?.model||o?.defaultModel||``,S=p.thinkingModel===x;(0,Z.useEffect)(()=>{e&&y?.(e,{limit:Bi})},[y,e]),(0,Z.useEffect)(()=>{!e||!f||!b||p.switchingModel||p.switchingThinking||S&&p.thinkingStatus||b(e,x)},[b,x,S,p.switchingModel,p.switchingThinking,f,e,p.availableThinkingLevels,p.thinkingStatus,m]);let C=(0,Z.useMemo)(()=>({onLoadOlder:()=>o?.loadOlderMessages(e)??!1,onModelChange:t=>o?.switchSessionModel(e,t),onThinkingLevelChange:t=>o?.switchSessionThinkingLevel(e,t),onLoadThinkingLevel:()=>b?.(e,x),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,b,x]);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)(Ne,{size:16}),o?`Session unavailable`:`Loading session`]});let w=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)(Ri,{session:f,shortcutEnabled:n,messages:p.messages||Vi,transcriptLoadState:p.loaded?`ready`:p.loading||!p.error?`loading`:`error`,messageStart:p.messageStart,hasOlder:p.hasOlder,loadingOlder:p.loadingOlder,olderError:p.olderError,model:x,thinkingLevel:p.thinkingLevel||f.thinkingLevel||`medium`,availableThinkingLevels:S&&p.availableThinkingLevels||Vi,thinkingStatus:S&&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||Vi,tools:p.tools||Vi,thinkingText:p.thinkingText||``,queuedInputs:p.queuedInputs||Vi,withdrawingInputIds:p.withdrawingInputIds||Vi,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||Vi,error:p.error||(o.activeId===e?o.globalError:``),pendingAsset:w,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,...C})})}function Gi({onNewSession:e,newSessionShortcut:t}){let{t:n}=c(),r=(0,Z.useContext)(zi),[i,a]=(0,Z.useState)(!1),o=(0,Z.useRef)(!1),s=(0,Z.useRef)(!0);(0,Z.useEffect)(()=>(s.current=!0,()=>{s.current=!1}),[]);let l=async()=>{if(!(!e||o.current)){o.current=!0,a(!0);try{await e()}finally{o.current=!1,s.current&&a(!1)}}};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)(_e,{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`)}),r?.globalError&&(0,Q.jsx)(oe,{error:r.globalError,className:`w-[min(420px,calc(100%_-_32px))]`}),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)]`,disabled:i,"aria-busy":i,onClick:()=>void l(),children:[i?(0,Q.jsx)(ge,{size:14,"aria-hidden":`true`,className:`animate-spin`}):(0,Q.jsx)(Se,{size:14,"aria-hidden":`true`}),i?n(`chat:chatDock.creatingChat`):r?.globalError?n(`chat:chatDock.retryNewChat`):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]})}var Ki=`web-preview`;function qi(e,t=`Web preview`){try{return new URL(e).hostname.replace(/^www\./i,``)||t}catch{return t}}export{Ui as a,di as c,Hi as i,un as l,qi as n,zi as o,Gi as r,ui as s,Ki as t};