@hienlh/ppm 0.19.3 → 0.19.5

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 (92) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +54 -1
  3. package/assets/skills/ppm/SKILL.md +1 -1
  4. package/assets/skills/ppm/references/http-api.md +6 -1
  5. package/dist/web/assets/accounts-settings-section-CmLGNwUl.js +1 -0
  6. package/dist/web/assets/{ai-resource-editor-BqFT1EUB.js → ai-resource-editor-TVV8rOsT.js} +1 -1
  7. package/dist/web/assets/{ai-settings-section-CY6spbEx.js → ai-settings-section-CutZAI-J.js} +1 -1
  8. package/dist/web/assets/{ai-settings-section-Po3K8j-g.js → ai-settings-section-Whh5k2zL.js} +1 -1
  9. package/dist/web/assets/{appearance-settings-section-L9Z-nej_.js → appearance-settings-section-DbkXixUe.js} +1 -1
  10. package/dist/web/assets/chat-tab-BYuPaeUJ.js +15 -0
  11. package/dist/web/assets/code-editor-4Lk47HbX.js +7 -0
  12. package/dist/web/assets/{conflict-editor-BoRPwL3L.js → conflict-editor-B-HnPZX7.js} +1 -1
  13. package/dist/web/assets/{csv-preview-BpoJqZQi.js → csv-preview-CMIxkng3.js} +1 -1
  14. package/dist/web/assets/{database-viewer-I-9cER1L.js → database-viewer-CM6O4tar.js} +1 -1
  15. package/dist/web/assets/{diff-viewer-_xHZsxvr.js → diff-viewer-nL4cAp1u.js} +1 -1
  16. package/dist/web/assets/explorer-body-CuLBY282.js +2 -0
  17. package/dist/web/assets/{explorer-window-content-DD6Z15pm.js → explorer-window-content-Cr8HYEIZ.js} +1 -1
  18. package/dist/web/assets/{extension-manager-section-Cu9D9Udt.js → extension-manager-section-D_E1LteV.js} +1 -1
  19. package/dist/web/assets/{extension-webview-Diz2OzVq.js → extension-webview-BKVWrl6R.js} +1 -1
  20. package/dist/web/assets/{files-settings-section-B1e7BgKQ.js → files-settings-section-DzuWb19a.js} +1 -1
  21. package/dist/web/assets/{general-settings-section-DWdHHRDy.js → general-settings-section-c096J38r.js} +1 -1
  22. package/dist/web/assets/{git-log-panel-CMMsvU64.js → git-log-panel-DRLGWrO2.js} +1 -1
  23. package/dist/web/assets/{glide-data-grid-pKQuyYFj.js → glide-data-grid-CUtOJQyB.js} +11 -11
  24. package/dist/web/assets/{group-chat-tab-U5u0Loii.js → group-chat-tab-Cano41wo.js} +1 -1
  25. package/dist/web/assets/{index--KWVW-Ga.js → index-C_s5DxFQ.js} +4 -4
  26. package/dist/web/assets/index-nP3uxXvR.css +2 -0
  27. package/dist/web/assets/{jira-watcher-section-uA5oyB8s.js → jira-watcher-section-B2-_4QW_.js} +1 -1
  28. package/dist/web/assets/{keybindings-store-Ccf0etMJ.js → keybindings-store-ehg0D6FR.js} +1 -1
  29. package/dist/web/assets/{keyboard-shortcuts-section-B7IxJHiI.js → keyboard-shortcuts-section-DMVcFwLJ.js} +1 -1
  30. package/dist/web/assets/{markdown-renderer-CY1epGRc.js → markdown-renderer-CKIBtz-k.js} +1 -1
  31. package/dist/web/assets/{markdown-renderer-DDcIGQEd.js → markdown-renderer-pDOFHEG7.js} +1 -1
  32. package/dist/web/assets/{mobile-explorer-sheet-CqkwbCRl.js → mobile-explorer-sheet-DFGPwNp0.js} +1 -1
  33. package/dist/web/assets/{notification-store-BNSYk3E7.js → notification-store-CwLJtN2t.js} +1 -1
  34. package/dist/web/assets/{notifications-settings-section-v_628h4B.js → notifications-settings-section-C66s2JId.js} +1 -1
  35. package/dist/web/assets/{pdf-preview-CI3q1MnH.js → pdf-preview-0AwTBfeC.js} +1 -1
  36. package/dist/web/assets/{postgres-viewer-jaR0FYJ_.js → postgres-viewer-hDHYMHmG.js} +2 -2
  37. package/dist/web/assets/{ppmbot-settings-section-BET4VmKb.js → ppmbot-settings-section-DV6TMOfs.js} +1 -1
  38. package/dist/web/assets/{process-table-D1r-Gupi.js → process-table-CmvwqGrQ.js} +1 -1
  39. package/dist/web/assets/proxy-settings-section-DjtXwOV_.js +1 -0
  40. package/dist/web/assets/{query-audit-section-BA5rT6Sh.js → query-audit-section-BgXdBaE1.js} +1 -1
  41. package/dist/web/assets/{remote-desktop-mobile-sheet-CPa3XElX.js → remote-desktop-mobile-sheet-Cakf7i6s.js} +2 -2
  42. package/dist/web/assets/{remote-desktop-mobile-view-De_a4skd.js → remote-desktop-mobile-view-DO5NJufM.js} +1 -1
  43. package/dist/web/assets/{remote-desktop-readiness-gate-CPrDIv2d.js → remote-desktop-readiness-gate-CODu8fsP.js} +1 -1
  44. package/dist/web/assets/{remote-desktop-window-content-CG1StfCE.js → remote-desktop-window-content-DVhp7Y9T.js} +1 -1
  45. package/dist/web/assets/{schedules-settings-section-B2f7V7Xr.js → schedules-settings-section-IfwILuXE.js} +1 -1
  46. package/dist/web/assets/{settings-body-omv04jbb.js → settings-body-NYJVObzu.js} +2 -2
  47. package/dist/web/assets/{settings-tab-NdnBTqyj.js → settings-tab-CPOI69SL.js} +1 -1
  48. package/dist/web/assets/{settings-window-content-Chou1JGa.js → settings-window-content-BuuLt4qg.js} +1 -1
  49. package/dist/web/assets/{sql-query-editor-Dk9y3jqy.js → sql-query-editor-BSwL4jf9.js} +1 -1
  50. package/dist/web/assets/{sqlite-viewer-4xFhkLYy.js → sqlite-viewer-Cy-H-h03.js} +1 -1
  51. package/dist/web/assets/{system-monitor-body-B_1iMVOI.js → system-monitor-body-B3jG3f5P.js} +2 -2
  52. package/dist/web/assets/{system-monitor-tab-B2j9mWBW.js → system-monitor-tab-Dt4wtPR0.js} +1 -1
  53. package/dist/web/assets/{system-monitor-window-content-BOjq53uU.js → system-monitor-window-content-5Kkti6yp.js} +1 -1
  54. package/dist/web/assets/{tab-host-window-content-CW_dlYlW.js → tab-host-window-content-BnwmQM0I.js} +1 -1
  55. package/dist/web/assets/{team-member-sheet-CkR4qO7V.js → team-member-sheet-B4TEEtVT.js} +2 -2
  56. package/dist/web/assets/{team-member-window-content-CmF5ia3n.js → team-member-window-content-CHevmy9F.js} +1 -1
  57. package/dist/web/assets/{terminal-tab-HXZkicIc.js → terminal-tab-DVb1AfrI.js} +2 -2
  58. package/dist/web/assets/{tool-cards-jA1BTLZj.js → tool-cards-DIF_JcFj.js} +4 -4
  59. package/dist/web/assets/use-accounts-data--JHaCIoT.js +1 -0
  60. package/dist/web/assets/{use-monaco-theme-BcQqKVbE.js → use-monaco-theme-xqDIVJcg.js} +1 -1
  61. package/dist/web/assets/{use-remote-desktop-display-choice-DY5BWRTo.js → use-remote-desktop-display-choice-DJFX_arw.js} +1 -1
  62. package/dist/web/assets/{use-websocket-DetaY8OI.js → use-websocket-DufdN3ZA.js} +1 -1
  63. package/dist/web/assets/{video-preview-C0uH2228.js → video-preview-DExfNDxI.js} +1 -1
  64. package/dist/web/index.html +2 -2
  65. package/dist/web/sw.js +1 -1
  66. package/package.json +1 -1
  67. package/src/providers/codex-app-server/codex-event-mapper.ts +42 -1
  68. package/src/providers/codex-app-server/codex-provider.ts +22 -4
  69. package/src/server/routes/proxy.ts +60 -0
  70. package/src/services/codex-account.service.ts +4 -2
  71. package/src/services/prod-db-guard.ts +98 -0
  72. package/src/services/proxy-agent-anthropic-bridge.ts +104 -0
  73. package/src/services/proxy-agent-bridge.ts +147 -0
  74. package/src/services/proxy-agent-turn.ts +172 -0
  75. package/src/services/proxy-anthropic-format.ts +157 -0
  76. package/src/services/proxy-image-bridge.ts +186 -0
  77. package/src/services/proxy-openai-bridge.ts +4 -38
  78. package/src/services/proxy-openai-format.ts +174 -0
  79. package/src/services/proxy.service.ts +54 -0
  80. package/src/web/components/chat/usage-badge.tsx +41 -4
  81. package/src/web/components/settings/accounts/account-card.tsx +27 -3
  82. package/src/web/components/settings/accounts/accounts-pane-header.tsx +22 -2
  83. package/src/web/components/settings/accounts/claude-accounts-section.tsx +4 -3
  84. package/src/web/components/settings/accounts/codex-accounts-section.tsx +11 -4
  85. package/src/web/components/settings/proxy-settings-section.tsx +55 -23
  86. package/dist/web/assets/accounts-settings-section-LtSVxNNp.js +0 -1
  87. package/dist/web/assets/chat-tab-BIO-VhWT.js +0 -15
  88. package/dist/web/assets/code-editor-B9lVjElM.js +0 -7
  89. package/dist/web/assets/explorer-body-DapwsOnp.js +0 -2
  90. package/dist/web/assets/index-CvGx7wBQ.css +0 -2
  91. package/dist/web/assets/proxy-settings-section-0DvNh1B-.js +0 -3
  92. package/dist/web/assets/use-accounts-data-BI_5qNvr.js +0 -1
@@ -1,15 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/edit-diff-preview-DeHb85DN.js","assets/rolldown-runtime-FhOqtrmT.js","assets/vendor-markdown-Ls5AcU91.js","assets/libesm-DLBE59ul.js","assets/markdown-renderer-CY1epGRc.js","assets/vendor-mermaid-BKWscKt0.js","assets/vendor-ui-CaeeFO0B.js","assets/markdown-renderer-DDcIGQEd.js","assets/index--KWVW-Ga.js","assets/button-BZtEJcUv.js","assets/utils-C9OjCrou.js","assets/createLucideIcon-D8pyde1A.js","assets/arrow-left-CyFcsyzD.js","assets/bot-D6sx11y0.js","assets/check-DN75Ucvz.js","assets/chevron-down-Dp0rpHb8.js","assets/chevron-right-De-Wz5Lz.js","assets/chevron-up-8PbsNiJp.js","assets/circle-BCy0AUCo.js","assets/clock-C1CQUQPZ.js","assets/sparkles-Dh-_J2Rd.js","assets/copy-BewHj66E.js","assets/database-Y3ESDK4-.js","assets/download-DG3_9xXy.js","assets/use-coarse-long-press-BmI_GVW5.js","assets/eye-off-GjXVuAOn.js","assets/eye-gWwaF4Lg.js","assets/loader-circle-DPMrnLQ2.js","assets/monitor-C835ucWH.js","assets/x-YDu4m2Iq.js","assets/api-client-oY1tC3tM.js","assets/react-X4jUntEf.js","assets/window-store-DGKf9rPG.js","assets/window-pip-registry-BEN0QNSW.js","assets/panel-store-BRrnDO_i.js","assets/context-menu-C13b1uT3.js","assets/portal-container-context-a399Hd9F.js","assets/mobile-bottom-sheet-BD5b7KJF.js","assets/use-visual-viewport-rnvuooQZ.js","assets/use-is-mobile-CYW3FJFE.js","assets/project-store-BuY7rxn_.js","assets/ws-auth-Dawx17PM.js","assets/settings-store-Brjd0QnO.js","assets/tab-store-PZsP5ZwG.js","assets/apply-theme-DxTXOAcV.js","assets/resolve-theme-DQk_YcsT.js","assets/index-CvGx7wBQ.css","assets/image-gallery-Cj8nd4xW.js","assets/run-in-terminal-bKRwuO2z.js","assets/api-client-BogqsFna.js"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./createLucideIcon-D8pyde1A.js";import{t as i}from"./bot-D6sx11y0.js";import{t as a}from"./brain-KDa9jFRq.js";import{t as o}from"./check-DN75Ucvz.js";import{t as s}from"./chevron-down-Dp0rpHb8.js";import{t as c}from"./chevron-right-De-Wz5Lz.js";import{t as l}from"./chevron-up-8PbsNiJp.js";import{a as u,i as d,n as f,o as p,r as m}from"./tool-cards-jA1BTLZj.js";import{t as h}from"./circle-BCy0AUCo.js";import{t as g}from"./clock-C1CQUQPZ.js";import{t as _}from"./code-DJgYrFzm.js";import{t as v}from"./sparkles-Dh-_J2Rd.js";import{t as y}from"./copy-BewHj66E.js";import{n as b,r as x}from"./use-coarse-long-press-BmI_GVW5.js";import{t as S}from"./eye-gWwaF4Lg.js";import{t as C}from"./hand-x0ejq3fS.js";import{t as w}from"./loader-circle-DPMrnLQ2.js";import{t as ee}from"./shield-off-7jKWpJBD.js";import{t as te}from"./x-YDu4m2Iq.js";import{i as T,n as E,r as D,s as ne}from"./api-client-oY1tC3tM.js";import{q as re}from"./vendor-mermaid-BKWscKt0.js";import{t as O}from"./settings-store-Brjd0QnO.js";import{n as k,r as A,t as ie}from"./utils-C9OjCrou.js";import"./portal-container-context-a399Hd9F.js";import{t as ae}from"./panel-store-BRrnDO_i.js";import"./window-store-DGKf9rPG.js";import{i as j}from"./project-store-BuY7rxn_.js";import{t as oe}from"./tab-store-PZsP5ZwG.js";import"./context-menu-C13b1uT3.js";import{n as se}from"./use-is-mobile-CYW3FJFE.js";import{t as M}from"./button-BZtEJcUv.js";import{t as N}from"./mobile-bottom-sheet-BD5b7KJF.js";import"./use-visual-viewport-rnvuooQZ.js";import"./ws-auth-Dawx17PM.js";import{$t as P,An as ce,Ar as le,Bn as ue,Dr as F,En as I,Er as de,Fn as fe,Gn as L,Hn as R,In as z,It as B,Jt as pe,Kn as V,Kt as H,Ln as me,Lt as he,M as ge,N as U,Nn as W,Nr as G,On as _e,Or as K,Pn as ve,Pr as ye,Qn as be,Rn as q,Rt as J,Tn as xe,Un as Se,Xn as Ce,Yt as we,Zn as Te,_ as Ee,_n as Y,_r as De,bn as Oe,cn as ke,gn as Ae,hr as je,j as Me,jn as X,kr as Ne,lr as Pe,on as Fe,pr as Ie,r as Z,sr as Le,t as Re,tn as ze,tr as Be,vn as Ve,wn as He,wr as Ue,xr as We,zn as Ge}from"./index--KWVW-Ga.js";import{t as Ke}from"./use-websocket-DetaY8OI.js";import{getAISettings as qe}from"./api-settings-CTMdz_VF.js";import"./use-blob-url-Gfi69PtP.js";import{n as Je,r as Ye,t as Xe}from"./image-gallery-Cj8nd4xW.js";import{t as Ze}from"./libesm-DLBE59ul.js";import{t as Qe}from"./use-open-team-member-CruUTqzD.js";import{n as $e,t as et}from"./send-to-chat-S8LCNX7V.js";import{t as tt}from"./ai-settings-section-Po3K8j-g.js";import{c as nt,n as rt,o as it,t as at}from"./use-accounts-data-BI_5qNvr.js";var ot=r(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),st=r(`chevrons-down`,[[`path`,{d:`m7 6 5 5 5-5`,key:`1lc07p`}],[`path`,{d:`m7 13 5 5 5-5`,key:`1d48rs`}]]),ct=r(`clipboard-check`,[[`rect`,{width:`8`,height:`4`,x:`8`,y:`2`,rx:`1`,ry:`1`,key:`tgr4d6`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`,key:`116196`}],[`path`,{d:`m9 14 2 2 4-4`,key:`df797q`}]]),lt=r(`image-off`,[[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}],[`path`,{d:`M10.41 10.41a2 2 0 1 1-2.83-2.83`,key:`1bzlo9`}],[`line`,{x1:`13.5`,x2:`6`,y1:`13.5`,y2:`21`,key:`1q0aeu`}],[`line`,{x1:`18`,x2:`21`,y1:`12`,y2:`15`,key:`5mozeu`}],[`path`,{d:`M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59`,key:`mmje98`}],[`path`,{d:`M21 15V5a2 2 0 0 0-2-2H9`,key:`43el77`}]]),ut=r(`list-ordered`,[[`path`,{d:`M11 5h10`,key:`1cz7ny`}],[`path`,{d:`M11 12h10`,key:`1438ji`}],[`path`,{d:`M11 19h10`,key:`11t30w`}],[`path`,{d:`M4 4h1v5`,key:`10yrso`}],[`path`,{d:`M4 9h2`,key:`r1h2o0`}],[`path`,{d:`M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02`,key:`xtkcd5`}]]),dt=r(`mic-off`,[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]),ft=r(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),pt=r(`slash`,[[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}]]),Q=e(t(),1),mt={maxImages:4,maxBase64PerImage:5e6,maxBase64Total:1e7};function ht(e){let t=[],n=0;for(let r of e)if(r.imageData){if(t.length>=mt.maxImages)break;r.imageData.data.length>mt.maxBase64PerImage||n+r.imageData.data.length>mt.maxBase64Total||(n+=r.imageData.data.length,t.push(r.imageData))}return t}function gt(e,t){let n=new Set(t),r=[],i=[];for(let t of e)t.serverPath&&(t.imageData&&n.has(t.imageData)?r.push(t.serverPath):i.push(t.serverPath));return{inlineImagePaths:r,pathOnlyPaths:i}}function _t(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t).toString(36)}function vt(e,t){let n=`pc-${_t(t)}-`;return e.map(e=>e.id?{...e,id:`${n}${e.id}`}:e)}function yt(e,t){if(t.size===0)return e;let n=[];for(let r of e){let e=r.id?t.get(r.id):void 0;e&&e.length>0&&n.push(...e),n.push(r)}return n}var bt=null;function xt(){return bt||=new AudioContext,bt}function St(e,t,n,r,i=`sine`){let a=xt(),o=a.createOscillator(),s=a.createGain();o.type=i,o.frequency.value=e,s.gain.setValueAtTime(r,n),s.gain.exponentialRampToValueAtTime(.001,n+t),o.connect(s),s.connect(a.destination),o.start(n),o.stop(n+t)}function Ct(){let e=xt().currentTime;St(523,.15,e,.15),St(659,.2,e+.12,.15)}function wt(){let e=xt().currentTime;St(880,.12,e,.18,`square`),St(698,.12,e+.15,.18,`square`),St(880,.15,e+.3,.15,`square`)}function Tt(){let e=xt().currentTime;St(440,.12,e,.12),St(523,.12,e+.1,.12),St(659,.18,e+.2,.12)}var Et={done:Ct,approval_request:wt,question:Tt};function Dt(e){try{Et[e]?.()}catch{}}var Ot={hasTeams:!1,teamNames:[],messageCount:0,unreadCount:0};function kt(e){if(document.hidden)return!1;let{panels:t}=ae.getState();for(let n of Object.values(t)){let t=n.tabs.find(e=>e.id===n.activeTabId);if(t?.type===`chat`&&t.metadata?.sessionId===e)return!0}return!1}function At(e,t=`claude`,n=``,r){let[i,a]=(0,Q.useState)([]),[o,s]=(0,Q.useState)(new Map),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)({}),[f,p]=(0,Q.useState)(`idle`),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(0),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[w,ee]=(0,Q.useState)([]),te=(0,Q.useRef)([]),[re,O]=(0,Q.useState)(null),[k,A]=(0,Q.useState)(null),[ie,j]=(0,Q.useState)(!1),[oe,se]=(0,Q.useState)(null),[M,N]=(0,Q.useState)(null),P=(0,Q.useRef)(null),ce=(0,Q.useRef)(null),[le,ue]=(0,Q.useState)(null),F=(0,Q.useRef)(null),[I,de]=(0,Q.useState)(!0),fe=(0,Q.useRef)(null),L=(0,Q.useRef)(null),R=(0,Q.useRef)(``),z=(0,Q.useRef)([]),B=(0,Q.useRef)(new Map),pe=(0,Q.useRef)(null),V=(0,Q.useRef)(`idle`),H=(0,Q.useRef)(null),me=(0,Q.useRef)(()=>{}),he=(0,Q.useRef)(null),ge=(0,Q.useRef)(!1),U=(0,Q.useRef)(new Set),W=(0,Q.useRef)(0),G=(0,Q.useRef)(null),_e=(0,Q.useRef)(0),K=(0,Q.useRef)(e);K.current=e;let ve=(0,Q.useRef)(r);ve.current=r;let ye=(0,Q.useRef)([]);ye.current=i;let be=(0,Q.useRef)(n);be.current=n;let q=(0,Q.useRef)(null),J=(0,Q.useRef)(0),xe=(0,Q.useRef)({teamNames:new Set,messages:[]}),Se=(0,Q.useRef)(0),[Ce,we]=(0,Q.useState)(Ot),[Te,Ee]=(0,Q.useState)([]),Y=(0,Q.useCallback)(()=>{let e=xe.current;we({hasTeams:e.teamNames.size>0,teamNames:Array.from(e.teamNames),messageCount:e.messages.length,unreadCount:Se.current}),Ee([...e.messages])},[]),De=(0,Q.useCallback)(()=>{Se.current=0,Y()},[Y]),Oe=(0,Q.useCallback)(async e=>{try{let t=await E.get(`/api/teams/${encodeURIComponent(e)}`);if(!t?.messages)return;let n=xe.current.messages,r=t.messages.filter(e=>!n.some(t=>t.timestamp===e.timestamp&&t.from===e.from));n.push(...r),n.sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime()),n.length>500&&n.splice(0,n.length-500),Y()}catch{}},[Y]),ke=f!==`idle`;(0,Q.useEffect)(()=>{if(e)return Fe.getState().setStreaming(e,f!==`idle`,n),()=>{Fe.getState().setStreaming(e,!1)}},[e,f,n]);let Ae=(0,Q.useCallback)((e,t)=>{let n=z.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=z.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return z.current[n]={...r,children:i},!0},[]),je=(0,Q.useCallback)((e,t)=>{let n=e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t,r=ye.current,i=-1;for(let e=r.length-1;e>=0;e--)if(r[e].events?.some(n)){i=e;break}return i===-1?!1:(a(t=>{let r=-1;for(let e=t.length-1;e>=0;e--)if(t[e].events?.some(n)){r=e;break}if(r===-1)return t;let i=t[r],a=i.events.map(t=>{if(!n(t)||t.type!==`tool_use`)return t;let r=[...t.children??[]],i=e.toolUseId,a=i?r.findIndex(t=>t.type===e.type&&t.toolUseId===i):-1;return a===-1?r.push(e):r[a]=e,{...t,children:r}});return[...t.slice(0,r),{...i,events:a},...t.slice(r+1)]}),!0)},[]),Me=(0,Q.useCallback)(()=>{J.current=0;let e=R.current,t=[...z.current],n=pe.current;(0,Q.startTransition)(()=>{a(r=>{let i=r[r.length-1];return i?.role===`assistant`&&!i.id.startsWith(`final-`)?[...r.slice(0,-1),{...i,content:e,events:t,...n}]:[...r,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:t,timestamp:new Date().toISOString(),...n}]})})},[]),X=(0,Q.useCallback)(()=>{J.current||=window.setTimeout(Me,100)},[Me]),Ne=(0,Q.useCallback)((e,t)=>{let n=t=>t.type===`tool_use`&&(t.tool===`Agent`||t.tool===`Task`)&&t.toolUseId===e,r=z.current.findIndex(n);if(r!==-1){z.current[r]={...z.current[r],bgStatus:t},X();return}a(e=>{let r=-1;for(let t=e.length-1;t>=0;t--)if(e[t].events?.some(n)){r=t;break}if(r===-1)return e;let i=e[r],a=i.events.map(e=>n(e)?{...e,bgStatus:t}:e);return[...e.slice(0,r),{...i,events:a},...e.slice(r+1)]})},[X]),Pe=(0,Q.useCallback)(e=>{let t=e,n=t?.type;if(!n)return;let r=e=>{let n=z.current,r=n.findIndex(e);r===-1?n.push(t):n[r]=t};switch(n){case`account_info`:pe.current={accountId:t.accountId,accountLabel:t.accountLabel},O(null);break;case`account_retry`:t.accountId&&t.accountLabel&&(pe.current={accountId:t.accountId,accountLabel:t.accountLabel}),z.current=[t],X();break;case`status_update`:{let e=t.accountLabel?` (${t.accountLabel})`:``;O(`${t.message}${e}`);break}case`text`:{let e=t.parentToolUseId;if(e&&Ae(t,e)){X();break}if(e){je(t,e);break}R.current+=t.content,z.current.push(t),X();break}case`thinking`:{let e=t.parentToolUseId;if(e&&Ae(t,e)){X();break}if(e){je(t,e);break}z.current.push(t),X();break}case`tool_use`:{if(t.tool===`AskUserQuestion`){t.toolUseId&&U.current.add(t.toolUseId);break}let e=t.parentToolUseId;if(e&&Ae(t,e)){X();break}if(e){je(t,e);break}let n=t.toolUseId;r(e=>!!n&&e.type===`tool_use`&&e.toolUseId===n),X();break}case`tool_result`:{let e=t.toolUseId;if(e&&B.current.delete(e),e&&U.current.has(e))break;let n=t.parentToolUseId;if(n&&Ae(t,n)){X();break}if(n){je(t,n);break}r(t=>!!e&&t.type===`tool_result`&&t.toolUseId===e),X();break}case`approval_resolved`:{let e=t.requestId;if(t.approved&&t.answers){let n=z.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`),r=n&&n.input;r&&typeof r==`object`&&(r.answers=t.answers,a(e=>[...e]))}y(t=>t&&t.requestId===e?null:t),q.current!=null&&(ne.dismiss(q.current),q.current=null);break}case`approval_request`:if(r(e=>e.type===`approval_request`&&e.requestId===t.requestId),ge.current)break;if(y({requestId:t.requestId,tool:t.tool,input:t.input}),K.current&&!kt(K.current)){Dt(t.tool===`AskUserQuestion`?`question`:`approval_request`);let e=K.current,n=t.tool===`AskUserQuestion`;q.current=ne[n?`info`:`warning`](n?`AI has a question`:`${t.tool} needs permission`,{description:be.current||`Session ${e.slice(0,8)}`,duration:1/0,action:{label:`Go to session`,onClick:()=>{let{panels:t}=ae.getState();for(let[n,r]of Object.entries(t)){let t=r.tabs.find(t=>t.metadata?.sessionId===e);if(t){ae.getState().setActiveTab(t.id,n);break}}}}})}break;case`error`:a(e=>{let n=e[e.length-1];if(n?.role===`assistant`){let r=z.current,i=r[r.length-1],a=i?.type===`error`&&i.message===t.message?r:[...r,t];return z.current=a,[...e.slice(0,-1),{...n,events:a}]}return n?.role===`system`&&n.content===t.message?e:[...e,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]});break;case`team_detected`:{let e=t.teamName;e&&(xe.current.teamNames.add(e),Y(),Oe(e));break}case`team_inbox`:{let e=t.messages;if(Array.isArray(e)){let t=xe.current.messages;t.push(...e),t.length>500&&t.splice(0,t.length-500),Se.current+=e.length,Y()}break}case`team_updated`:Y();break;case`bash_output`:{let e=t.toolUseId;if(e){let n=B.current.get(e);n?(n.content+=t.content,n.content.length>5e5&&(n.content=n.content.slice(-5e5)),n.lineCount=t.lineCount):B.current.set(e,{content:t.content,lineCount:t.lineCount}),X()}break}case`subagent_status`:{let e=t.toolUseId,n=t.status;e&&n&&Ne(e,n);break}case`background_registry`:{let e=t.shells??[];te.current=e,ee(e);break}case`done`:{if(V.current===`idle`)break;t.contextWindowPct!=null&&x(t.contextWindowPct),K.current&&!kt(K.current)&&Dt(`done`),J.current&&=(clearTimeout(J.current),0);let e=R.current,n=[...z.current],r=pe.current,i=t.lastMessageUuid,o=t.usage;a(t=>{let a=t[t.length-1];return a?.role===`assistant`?[...t.slice(0,-1),{...a,id:`final-${Date.now()}`,content:e||a.content,events:n.length>0?n:a.events,...i&&{sdkUuid:i},...o&&{usage:o}}]:e||n.length>0?[...t,{id:`final-${Date.now()}`,role:`assistant`,content:e,events:n,timestamp:new Date().toISOString(),...i&&{sdkUuid:i},...o&&{usage:o},...r}]:t}),R.current=``,z.current=[],pe.current=null,G.current=null,B.current.clear(),O(null);break}}},[Ae,je,X,Ne,Y,Oe]),Ie=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`user_message`){let e=t.content;a(n=>{let r=n[n.length-1];return r?.role===`user`&&r.content===e?n:[...n,{id:`user-remote-${Date.now()}`,role:`user`,content:e,timestamp:t.timestamp??new Date().toISOString()}]});return}if(t.type===`title_updated`){A(t.title??null);return}if(t.type===`session_migrated`){let e=t.newSessionId;e&&e!==K.current&&ve.current?.(e);return}if(t.type===`compact_status`){let e=t.status;e===`compacting`?C(`compacting`):e===`done`&&C(null);return}if(t.type===`phase_changed`){let e=t.phase;p(e),V.current=e,_(e===`connecting`?t.elapsed??0:0),e===`idle`&&C(null);return}if(t.type===`session_state`){j(!0),se(t.sessionId??K.current);let e=t,n=e.phase,r=V.current===`idle`;if(p(n),V.current=n,e.sessionTitle&&A(e.sessionTitle),e.model&&(ce.current&&e.model!==ce.current||(e.model===ce.current&&(ce.current=null),N(e.model),P.current=e.model)),typeof e.effort==`string`&&(ue(e.effort),F.current=e.effort),typeof e.thinking==`boolean`&&de(e.thinking),e.pendingApproval&&y({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),C(e.compactStatus===`compacting`?`compacting`:null),n===`idle`){let e=Date.now()-_e.current<5e3;r&&e||he.current?.(),h(!1)}return}if(t.type===`turn_events`){let e=t.events,n=t.userMessage;if(!e?.length&&!n){h(!1);return}W.current&&=(cancelAnimationFrame(W.current),0),G.current=n,a(e=>{let t=[...e],r=t.length;for(;r>0&&t[r-1].role===`assistant`;)r--;if(n!=null&&r>0&&t[r-1].role===`user`&&t[r-1].content===n)t=t.slice(0,r-1);else{let e=t[t.length-1];e?.role===`assistant`&&e.id.startsWith(`streaming-`)&&(t=t.slice(0,-1))}if(n){let e=t[t.length-1];(e?.role!==`user`||e.content!==n)&&(t=[...t,{id:`user-replay-${Date.now()}`,role:`user`,content:n,timestamp:new Date().toISOString()}])}return t}),R.current=``,z.current=[],pe.current=null,ge.current=!0;let r=0,i=()=>{let t=Math.min(r+100,e.length);for(let n=r;n<t;n++)Pe(e[n]);r=t,r<e.length?W.current=requestAnimationFrame(i):(W.current=0,ge.current=!1,h(!1))};W.current=requestAnimationFrame(i);return}Pe(t)}},[Pe]),{send:Z,connect:Le}=Ke({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:Ie,autoConnect:!!e&&!!n});me.current=Z,(0,Q.useEffect)(()=>{let r=!1;L.current&&L.current!==e&&(ce.current=null,fe.current=null),L.current=e??null,p(`idle`),V.current=`idle`,y(null),q.current!=null&&(ne.dismiss(q.current),q.current=null),C(null),s(new Map),d({}),R.current=``,z.current=[],G.current=null,_e.current=0,B.current.clear(),J.current&&=(clearTimeout(J.current),0),j(!1),se(null),xe.current={teamNames:new Set,messages:[]},Se.current=0,we(Ot),Ee([]),e&&E.get(`/api/teams`).then(t=>{r||!Array.isArray(t)||t.filter(t=>(t?.name??t?.team_name)===e).length!==0&&(xe.current.teamNames.add(e),Y(),Oe(e))}).catch(()=>{});let i=new Set(ye.current.map(e=>e.id));return e&&n?(l(!0),E.get(`${T(n)}/chat/sessions/${e}/messages?providerId=${t}`).then(e=>{if(r)return;let t=Array.isArray(e)?{messages:e,versionMap:{}}:e,n=Array.isArray(t?.messages)?t.messages:[];t?.versionMap&&d(t.versionMap),t?.canonicalSessionId&&t.canonicalSessionId!==K.current&&ve.current?.(t.canonicalSessionId);let o=G.current;if(o!=null){for(let e=n.length-1;e>=0;e--)if(n[e].role===`user`&&n[e].content===o){n=n.slice(0,e);break}}a(e=>{let t=e.filter(e=>!i.has(e.id));return[...n,...t]}),_e.current=Date.now()}).catch(()=>{r||a(e=>e.filter(e=>!i.has(e.id)))}).finally(()=>{r||l(!1)})):a([]),()=>{r=!0}},[e,t,n,Y,Oe]);let ze=(0,Q.useCallback)((e,t)=>{if(!e.trim()&&!t?.images?.length)return;let n=V.current!==`idle`;if(n){J.current&&=(clearTimeout(J.current),0);let e=R.current,t=[...z.current];a(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n})}a(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),R.current=``,z.current=[],H.current=null,n?(p(`thinking`),V.current=`thinking`):(p(`initializing`),V.current=`initializing`),y(null),q.current!=null&&(ne.dismiss(q.current),q.current=null),Z(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode,priority:t?.priority,images:t?.images,imagePaths:t?.imagePaths,...P.current&&{model:P.current},...F.current&&{effort:F.current},...fe.current!==null&&{thinking:fe.current}}))},[Z]),Be=(0,Q.useCallback)(e=>{N(e),P.current=e,ce.current=e,Z(JSON.stringify({type:`set_model`,model:e}))},[Z]),Ve=(0,Q.useCallback)(e=>{ue(e),F.current=e,Z(JSON.stringify({type:`set_effort`,effort:e}))},[Z]),He=(0,Q.useCallback)(e=>{de(e),fe.current=e,Z(JSON.stringify({type:`set_thinking`,enabled:e}))},[Z]),Ue=(0,Q.useCallback)((e,t,n)=>{if(Z(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=z.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`);if(t){let e=t.input;e&&typeof e==`object`&&(e.answers=n)}a(e=>[...e])}y(null),q.current!=null&&(ne.dismiss(q.current),q.current=null)},[Z]),We=(0,Q.useCallback)(()=>{if(V.current===`idle`)return;Z(JSON.stringify({type:`cancel`}));let e=R.current,t=[...z.current];a(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),R.current=``,z.current=[],B.current.clear(),H.current=null,p(`idle`),V.current=`idle`,y(null),q.current!=null&&(ne.dismiss(q.current),q.current=null)},[Z]),Ge=(0,Q.useCallback)(e=>{e&&Z(JSON.stringify({type:`kill_background_shell`,shellId:e}))},[Z]),qe=(0,Q.useCallback)(e=>{if(!e)return;let t=e.replace(/\.output$/,``);return te.current.find(n=>n.shellId===t||n.outputPath.endsWith(e)||n.outputPath.endsWith(`${t}.output`))},[]);(0,Q.useEffect)(()=>{e&&Re.getState().setSessionShells(e,w)},[e,w]),(0,Q.useEffect)(()=>{if(e)return Re.getState().retainSession(e),()=>{Re.getState().releaseSession(e)}},[e]);let Je=(0,Q.useCallback)(()=>{j(!1),h(!0),Le()},[Le]),Ye=(0,Q.useCallback)(()=>{!e||!n||fetch(`${T(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${D()}`}}).then(e=>e.json()).then(e=>{if(V.current!==`idle`)return;let t=e.ok?Array.isArray(e.data)?{messages:e.data,versionMap:void 0}:e.data:null;t?.versionMap&&d(t.versionMap),Array.isArray(t?.messages)&&t.messages.length>0&&(a(t.messages),R.current=``,z.current=[]),_e.current=Date.now()}).catch(()=>{})},[e,t,n]);he.current=Ye;let Xe=(0,Q.useCallback)(async(e,t)=>{if(!n)throw Error(`No project context available`);let r=e.replace(/^pc-[^-]+-/,``),i=`${T(n)}/chat/pre-compact-messages?jsonlPath=${encodeURIComponent(t)}&before=${encodeURIComponent(r)}`,a=vt(await E.get(i),t);return s(t=>{let n=new Map(t);return n.set(e,a),n}),a.length},[n]),Ze=(0,Q.useCallback)(e=>o.has(e),[o]),Qe=(0,Q.useCallback)(e=>{a(t=>t.filter(t=>t.id!==e))},[]),$e=(0,Q.useCallback)(()=>{a(e=>e.filter(e=>e.role!==`system`))},[]);return{messages:i,renderedMessages:(0,Q.useMemo)(()=>yt(i,o),[i,o]),expandCompact:Xe,isCompactExpanded:Ze,dismissMessage:Qe,clearErrors:$e,messagesLoading:c,versionMap:u,isStreaming:ke,phase:f,isReconnecting:m,connectingElapsed:g,pendingApproval:v,contextWindowPct:b,compactStatus:S,statusMessage:re,sessionTitle:k,model:M,setModel:Be,effort:le,setEffort:Ve,thinking:I,setThinking:He,teamActivity:Ce,teamMessages:Te,markTeamRead:De,bashPartialOutput:B,backgroundShells:w,killBackgroundShell:Ge,findBackgroundShellByOutput:qe,sendMessage:ze,respondToApproval:Ue,cancelStreaming:We,reconnect:Je,refetchMessages:Ye,isConnected:ie&&oe===e}}var jt=12e4;function Mt(e,t=`claude`,n){let r=JSON.stringify([e,t,n]),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(!1),c=(0,Q.useRef)(null),l=(0,Q.useRef)(0),u=(0,Q.useCallback)((i=!1)=>{if(!e)return;let o=++l.current;s(!0);let c=i?`&refresh=1`:``,u=n?`&session=${encodeURIComponent(n)}`:``;E.get(`${T(e)}/chat/usage?providerId=${t}${u}${c}`).then(e=>{o===l.current&&a({scope:r,usage:e??{},fetchedAt:e?.lastFetchedAt??null})}).catch(()=>{}).finally(()=>{o===l.current&&s(!1)})},[e,t,n,r]);(0,Q.useEffect)(()=>(a(null),s(!1),u(),c.current=setInterval(()=>u(),jt),()=>{++l.current,c.current&&clearInterval(c.current)}),[u]);let d=(0,Q.useCallback)(()=>u(!0),[u]),f=i?.scope===r?i:null;return{usageInfo:f?.usage??{},usageLoading:o,lastFetchedAt:f?.fetchedAt??null,refreshUsage:d}}var Nt={damping:.7,stiffness:.05,mass:1.25},Pt=70,Ft=1e3/60,It=350,Lt=!1;globalThis.document?.addEventListener(`mousedown`,()=>{Lt=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{Lt=!1}),globalThis.document?.addEventListener(`click`,()=>{Lt=!1});var Rt=(e={})=>{let[t,n]=(0,Q.useState)(!1),[r,i]=(0,Q.useState)(e.initial!==!1),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null);s.current=e;let c=(0,Q.useCallback)(()=>{if(!Lt)return!1;let e=window.getSelection();if(!e||!e.rangeCount)return!1;let t=e.getRangeAt(0);return t.commonAncestorContainer.contains(g.current)||g.current?.contains(t.commonAncestorContainer)},[]),l=(0,Q.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,Q.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,Q.useMemo)(()=>{let n;return{escapedFromLock:t,isAtBottom:r,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return g.current?.scrollTop??0},set scrollTop(e){if(g.current){let{scrollBehavior:t}=getComputedStyle(g.current);t!==`auto`&&(g.current.style.scrollBehavior=`auto`),g.current.scrollTop=e,d.ignoreScrollToTop=g.current.scrollTop,t!==`auto`&&(g.current.style.scrollBehavior=t)}},get targetScrollTop(){return!g.current||!_.current?0:g.current.scrollHeight-1-g.current.clientHeight},get calculatedTargetScrollTop(){if(!g.current||!_.current)return 0;let{targetScrollTop:t}=this;if(!e.targetScrollTop)return t;if(n?.targetScrollTop===t)return n.calculatedScrollTop;let r=Math.max(Math.min(e.targetScrollTop(t,{scrollElement:g.current,contentElement:_.current}),t),0);return n={targetScrollTop:t,calculatedScrollTop:r},requestAnimationFrame(()=>{n=void 0}),r},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=Pt}}},[]),f=(0,Q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Vt(s.current,e.animation),{ignoreEscapes:r=!1}=e,i,a=d.calculatedTargetScrollTop;e.duration instanceof Promise?e.duration.finally(()=>{i=Date.now()}):i=t+(e.duration??0);let o=async()=>{let e=new Promise(requestAnimationFrame).then(()=>{if(!d.isAtBottom)return d.animation=void 0,!1;let{scrollTop:l}=d,u=performance.now(),p=(u-(d.lastTick??u))/Ft;if(d.animation||={behavior:n,promise:e,ignoreEscapes:r},d.animation.behavior===n&&(d.lastTick=u),c()||t>Date.now())return o();if(l<Math.min(a,d.calculatedTargetScrollTop)){if(d.animation?.behavior===n){if(n===`instant`)return d.scrollTop=d.calculatedTargetScrollTop,o();d.velocity=(n.damping*d.velocity+n.stiffness*d.scrollDifference)/n.mass,d.accumulated+=d.velocity*p,d.scrollTop+=d.accumulated,d.scrollTop!==l&&(d.accumulated=0)}return o()}return i>Date.now()?(a=d.calculatedTargetScrollTop,o()):(d.animation=void 0,d.scrollTop<d.calculatedTargetScrollTop?f({animation:Vt(s.current,s.current.resize),ignoreEscapes:r,duration:Math.max(0,i-Date.now())||void 0}):d.isAtBottom)});return e.then(e=>(requestAnimationFrame(()=>{d.animation||(d.lastTick=void 0,d.velocity=0)}),e))};return e.wait!==!0&&(d.animation=void 0),d.animation?.behavior===n?d.animation.promise:o()},[l,c,d]),p=(0,Q.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,Q.useCallback)(({target:e})=>{if(e!==g.current)return;let{scrollTop:t,ignoreScrollToTop:n}=d,{lastScrollTop:r=t}=d;d.lastScrollTop=t,d.ignoreScrollToTop=void 0,n&&n>t&&(r=n),o(d.isNearBottom),setTimeout(()=>{if(d.resizeDifference||t===n)return;if(c()){u(!0),l(!1);return}let e=t>r,i=t<r;if(d.animation?.ignoreEscapes){d.scrollTop=r;return}i&&(u(!0),l(!1)),e&&u(!1),!d.escapedFromLock&&d.isNearBottom&&l(!0)},1)},[u,l,c,d]),h=(0,Q.useCallback)(({target:e,deltaY:t})=>{let n=e;for(;![`scroll`,`auto`].includes(getComputedStyle(n).overflow);){if(!n.parentElement)return;n=n.parentElement}n===g.current&&t<0&&g.current.scrollHeight>g.current.clientHeight&&!d.animation?.ignoreEscapes&&(u(!0),l(!1))},[u,l,d]),g=zt(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=zt(e=>{if(d.resizeObserver?.disconnect(),d.resizeObserver=void 0,!e)return;let t;d.resizeObserver=new ResizeObserver(([e])=>{let{height:n}=e.contentRect,r=n-(t??n);if(d.resizeDifference=r,d.scrollTop>d.targetScrollTop&&(d.scrollTop=d.targetScrollTop),o(d.isNearBottom),r>=0){let e=Vt(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:It})}else d.isNearBottom&&(u(!1),l(!0));t=n,requestAnimationFrame(()=>{setTimeout(()=>{d.resizeDifference===r&&(d.resizeDifference=0)},1)})}),d.resizeObserver?.observe(e)},[]);return{contentRef:_,scrollRef:g,scrollToBottom:f,stopScroll:p,isAtBottom:r||a,isNearBottom:a,escapedFromLock:t,state:d}};function zt(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Bt=new Map;function Vt(...e){let t={...Nt},n=!1;for(let r of e){if(r===`instant`){n=!0;continue}typeof r==`object`&&(n=!1,t.damping=r.damping??t.damping,t.stiffness=r.stiffness??t.stiffness,t.mass=r.mass??t.mass)}let r=JSON.stringify(t);return Bt.has(r)||Bt.set(r,Object.freeze(t)),n?`instant`:Bt.get(r)}var Ht=60,Ut=8,Wt=1400;function Gt(e){if(e.scrollHeight<=e.clientHeight)return!1;let t=getComputedStyle(e).overflowY;return t===`auto`||t===`scroll`}function Kt(e,t){let n=[],r=e.parentElement;for(;r&&r!==t;)Gt(r)&&n.push(r),r=r.parentElement;return n}function qt(){return typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches}function Jt(e,t){let n=e.querySelector(`[data-edit-ref="${CSS.escape(t)}"]`);if(n)return{el:n,level:`edit`};let r=t.replace(/-\d+$/,``),i=e.querySelector(`[data-tool-ref="${CSS.escape(r)}"]`);return i?{el:i,level:`card`}:null}function Yt(e,t,n,r){let i=e.scrollTop+t.getBoundingClientRect().top-e.getBoundingClientRect().top-n;e.scrollTo({top:i,behavior:r?`smooth`:`auto`})}function Xt(e,t){let n=Jt(e,t);if(!n)return()=>{};let{el:r,level:i}=n;for(let t of Kt(r,e))Yt(t,r,Ut,!1);Yt(e,r,Ht,!qt()),r.dataset.flash=i;let a=setTimeout(()=>{delete r.dataset.flash},Wt);return()=>{clearTimeout(a),delete r.dataset.flash}}var Zt=new Set([`Write`,`Edit`,`MultiEdit`,`NotebookEdit`]),Qt={create:3,write:2,notebook:2,edit:1};function $t(e){return typeof e==`string`?e:``}function en(e,t){let n=0,r=0;for(let i of Ze(e,t))i.added?n+=i.count??0:i.removed&&(r+=i.count??0);return{added:n,removed:r}}function tn(e){return e&&/created successfully/i.test(e)?`create`:`write`}function nn(e,t,n){switch(e){case`Write`:{let e=$t(t.file_path);return e?{filePath:e,op:tn(n),fragments:[{oldStr:``,newStr:$t(t.content)}]}:null}case`Edit`:{let e=$t(t.file_path);return e?{filePath:e,op:`edit`,fragments:[{oldStr:$t(t.old_string),newStr:$t(t.new_string)}]}:null}case`MultiEdit`:{let e=$t(t.file_path);if(!e||!Array.isArray(t.edits))return null;let n=t.edits.filter(e=>!!e&&typeof e==`object`).map(e=>({oldStr:$t(e.old_string),newStr:$t(e.new_string)}));return n.length===0?null:{filePath:e,op:`edit`,fragments:n}}case`NotebookEdit`:{let e=$t(t.notebook_path)||$t(t.file_path);return e?{filePath:e,op:`notebook`,fragments:[{oldStr:``,newStr:$t(t.new_source)}]}:null}default:return null}}function rn(e,t){if(e){for(let n of e)if(n.type===`tool_result`&&n.toolUseId&&t.set(n.toolUseId,n.output??``),n.type===`tool_use`){let e=n.result;n.toolUseId&&e?.output!=null&&!t.has(n.toolUseId)&&t.set(n.toolUseId,e.output),rn(n.children,t)}}}function an(e,t,n,r){if(e)for(let i of e){if(i.type!==`tool_use`||(i.children?.length&&an(i.children,!0,n,r),!Zt.has(i.tool)))continue;let e=i.input&&typeof i.input==`object`?i.input:null;if(!e)continue;let a=nn(i.tool,e,i.toolUseId?r.get(i.toolUseId):void 0);if(!a)continue;let o=n.get(a.filePath);o||(o={filePath:a.filePath,op:a.op,editCount:0,linesAdded:0,linesRemoved:0,edits:[],viaSubagent:!1},n.set(a.filePath,o)),Qt[a.op]>Qt[o.op]&&(o.op=a.op),t&&(o.viaSubagent=!0),a.fragments.forEach((e,n)=>{let{added:r,removed:a}=en(e.oldStr,e.newStr);o.linesAdded+=r,o.linesRemoved+=a,o.editCount+=1,o.edits.push({...e,toolUseId:i.toolUseId,editIndex:n,editRef:i.toolUseId?`${i.toolUseId}-${n}`:void 0,viaSubagent:t})})}}function on(e){let t=new Map;for(let n of e)rn(n.events,t);let n=new Map;for(let r of e)an(r.events,!1,n,t);return[...n.values()]}function sn(e,t){let n=[];for(let r=t;r>=0&&e[r]?.role===`assistant`;r--)n.unshift(e[r]);return n}var $=n();function cn(e){try{return new Date(e).toLocaleString()}catch{return``}}function ln({icon:e,label:t,title:n,onClick:r}){return(0,$.jsxs)(`button`,{type:`button`,onClick:r,title:n,"aria-label":t,className:`inline-flex items-center justify-center gap-1 rounded-md px-1.5 py-1 text-text-subtle hover:text-text-primary hover:bg-surface transition-colors`,children:[e,(0,$.jsx)(`span`,{children:t})]})}function un({content:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsx)(ln,{icon:t?(0,$.jsx)(o,{className:`size-3.5`}):(0,$.jsx)(y,{className:`size-3.5`}),label:t?`Copied`:`Copy`,title:`Copy message to clipboard`,onClick:()=>{ze(e),n(!0),setTimeout(()=>n(!1),1500)}})}function dn({timestamp:e,content:t,className:n,children:r}){return(0,$.jsxs)(`div`,{className:k(`flex items-center gap-0.5 flex-wrap text-xs text-text-subtle select-none`,n),children:[(0,$.jsx)(`time`,{title:cn(e),className:`pr-1 tabular-nums`,children:I(e)}),(0,$.jsx)(un,{content:t}),r]})}function fn(e){let t=0,n=0;for(let r of e)t+=r.linesAdded,n+=r.linesRemoved;return{added:t,removed:n}}function pn({count:e,totals:t,open:n,onToggle:r,ref:i}){let a=`${e} file${e===1?``:`s`}`;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`mx-1.5 h-3.5 w-px bg-border-soft`}),(0,$.jsxs)(`button`,{ref:i,type:`button`,onClick:r,"aria-expanded":n,"aria-label":`${a} changed this turn, ${t.added} added, ${t.removed} removed`,className:k(`inline-flex items-center gap-[7px] rounded-full font-mono text-[11.5px]`,`px-3 min-h-11 md:min-h-0 md:px-[9px] md:py-[5px]`,`text-text-secondary transition-colors hover:bg-surface hover:text-text-primary`),children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`size-[5px] shrink-0 rounded-full bg-primary`}),(0,$.jsx)(`span`,{children:a}),(0,$.jsxs)(`span`,{className:`flex items-center gap-[5px] tabular-nums`,children:[(0,$.jsxs)(`span`,{className:`text-success`,children:[`+`,t.added]}),(0,$.jsxs)(`span`,{className:`text-error`,children:[`−`,t.removed]})]})]})]})}function mn(e){if(!e)return!1;let t=e.closest(`[data-tab-pool-id]`)?.dataset.tabPoolId;if(!t)return e.offsetParent!==null;let{panels:n,focusedPanelId:r}=ae.getState();return n[r]?.activeTabId===t}var hn={create:{glyph:`A`,cls:`text-success`,label:`created`},write:{glyph:`W`,cls:`text-warning`,label:`overwritten`},notebook:{glyph:`N`,cls:`text-accent-2`,label:`notebook edited`},edit:{glyph:`·`,cls:`text-text-subtle`,label:`edited`}};function gn(e){let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`));return t<0?{base:e,dir:``}:{base:e.slice(t+1),dir:e.slice(0,t)}}function _n({added:e,removed:t,editCount:n,className:r}){return(0,$.jsxs)(`span`,{className:k(`flex items-center gap-[5px] tabular-nums`,r),children:[(0,$.jsxs)(`span`,{className:`text-success`,children:[`+`,e]}),(0,$.jsxs)(`span`,{className:`text-error`,children:[`−`,t]}),n!=null&&n>1&&(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[`×`,n]})]})}function vn({change:e,dense:t,selected:n,onClick:r}){let i=hn[e.op],{base:a,dir:o}=gn(e.filePath),s=e.viaSubagent?`${i.label} · changed by a sub-agent`:i.label;return(0,$.jsxs)(`button`,{type:`button`,onClick:r,title:e.filePath,className:k(`grid w-full grid-cols-[16px_1fr_auto_10px] items-center gap-[10px] text-left font-mono`,`border-b border-border-soft hover:bg-surface transition-colors`,t?`min-h-[38px] px-2.5 py-[5px] text-xs`:`min-h-[52px] px-3 py-[7px] text-[12.5px]`,n&&`bg-surface shadow-[inset_2px_0_0_var(--accent)]`),children:[(0,$.jsx)(`span`,{"aria-label":s,title:s,className:k(`inline-flex size-4 items-center justify-center rounded bg-white/5 text-[9px] font-semibold`,i.cls,e.viaSubagent&&`bg-accent-2/20 ring-1 ring-inset ring-accent-2/35`),children:i.glyph}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block truncate text-text-primary`,children:a}),o&&(0,$.jsx)(`span`,{className:`block overflow-hidden text-ellipsis whitespace-nowrap text-[10px] text-text-subtle [direction:rtl] text-left`,children:o})]}),(0,$.jsx)(_n,{added:e.linesAdded,removed:e.linesRemoved,editCount:e.editCount,className:`text-[11px]`}),(0,$.jsx)(c,{className:`size-[11px] text-text-subtle`})]})}var yn=(0,Q.lazy)(()=>re(()=>import(`./edit-diff-preview-DeHb85DN.js`),__vite__mapDeps([0,1,2,3])));function bn({change:e,onJump:t}){return(0,$.jsx)(`div`,{children:e.edits.map((n,r)=>(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`button`,{type:`button`,disabled:!n.editRef,onClick:()=>n.editRef&&t(n.editRef),className:`group flex min-h-11 w-full items-center gap-2 px-3 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface disabled:hover:bg-transparent`,children:[(0,$.jsxs)(`span`,{children:[`edit `,r+1,` of `,e.editCount]}),(0,$.jsx)(`span`,{className:`h-px flex-1 bg-border-soft`}),n.editRef&&(0,$.jsxs)(`span`,{className:`flex items-center gap-1 group-hover:text-primary`,children:[(0,$.jsx)(ye,{className:`size-3`}),`jump`]})]}),(0,$.jsx)(`div`,{className:`mx-3 mb-1`,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`h-4`}),children:(0,$.jsx)(yn,{oldStr:n.oldStr,newStr:n.newStr,filePath:e.filePath})})})]},n.editRef??r))})}function xn(e){let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`));return t<0?{base:e,dir:``}:{base:e.slice(t+1),dir:e.slice(0,t)}}var Sn=null;function Cn(e){return e instanceof HTMLElement?e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.isContentEditable:!1}function wn({changes:e,onJump:t,onClose:n}){let[r,i]=(0,Q.useState)(0),a=(0,Q.useRef)(null),o=(0,Q.useRef)(null),s=(0,Q.useId)();(0,Q.useEffect)(()=>(Sn=s,o.current?.querySelector(`button`)?.focus(),()=>{Sn===s&&(Sn=null)}),[s]),(0,Q.useEffect)(()=>{let o=o=>{if(Sn===s&&mn(a.current)&&!Cn(document.activeElement)){if(o.key===`Escape`)o.preventDefault(),n();else if(o.key===`j`)o.preventDefault(),i(t=>Math.min(t+1,e.length-1));else if(o.key===`k`)o.preventDefault(),i(e=>Math.max(e-1,0));else if(o.key===`Enter`){let n=e[r]?.edits[0]?.editRef;n&&(o.preventDefault(),t(n))}}};return window.addEventListener(`keydown`,o),()=>window.removeEventListener(`keydown`,o)},[s,e,r,t,n]);let c=e[Math.min(r,e.length-1)];if(!c)return null;let{base:l,dir:u}=xn(c.filePath);return(0,$.jsx)(`div`,{ref:a,className:`mt-0.5 overflow-hidden rounded-[10px] border border-border-soft bg-bg`,children:(0,$.jsxs)(`div`,{className:`grid h-[356px] grid-cols-[294px_1fr] grid-rows-[minmax(0,1fr)] bg-surface-elevated`,children:[(0,$.jsxs)(`div`,{ref:o,className:`min-h-0 overflow-y-auto border-r border-border-soft`,children:[e.map((e,t)=>(0,$.jsx)(vn,{change:e,dense:!0,selected:t===r,onClick:()=>i(t)},e.filePath)),(0,$.jsx)(`p`,{className:`px-2.5 pt-2 pb-2.5 font-mono text-[10px] text-text-subtle`,children:`j / k to move · enter to jump`})]}),(0,$.jsxs)(`div`,{className:`min-h-0 overflow-y-auto`,children:[(0,$.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b border-border-soft bg-surface-elevated py-[5px] pl-2.5 pr-2`,children:[(0,$.jsx)(`span`,{className:`shrink-0 font-mono text-xs font-medium text-text-primary`,children:l}),u&&(0,$.jsx)(`span`,{title:c.filePath,className:`min-w-0 flex-1 overflow-hidden text-ellipsis whitespace-nowrap font-mono text-[10.5px] text-text-subtle [direction:rtl] text-left`,children:u}),(0,$.jsx)(_n,{added:c.linesAdded,removed:c.linesRemoved,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void ze(c.filePath),className:`shrink-0 rounded-md px-1.5 py-1 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:`copy path`}),(0,$.jsx)(`button`,{type:`button`,onClick:n,"aria-label":`Close change tray`,className:`inline-flex size-8 shrink-0 items-center justify-center rounded-lg text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:(0,$.jsx)(te,{className:`size-3.5`})})]}),(0,$.jsx)(bn,{change:c,onJump:t})]})]})})}function Tn(e){let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`));return t<0?e:e.slice(t+1)}function En({label:e,onClick:t,children:n}){return(0,$.jsx)(`button`,{type:`button`,onClick:t,"aria-label":e,className:`inline-flex size-11 shrink-0 items-center justify-center rounded-lg text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:n})}function Dn({changes:e,totals:t,open:n,onClose:r,onJump:i}){let[a,o]=(0,Q.useState)(null),s=a==null?null:e[a],c=(0,Q.useRef)(null),l=()=>{o(null),r()},u=e=>{l(),i(e)};return(0,Q.useEffect)(()=>{if(!n)return;let e=c.current,t=()=>Array.from(e?.querySelectorAll(`button:not([disabled])`)??[]);t()[0]?.focus();let r=e=>{if(e.key===`Escape`){e.preventDefault(),l();return}if(e.key!==`Tab`)return;let n=t();if(n.length===0)return;let r=n[0],i=n[n.length-1];e.shiftKey&&document.activeElement===r?(e.preventDefault(),i.focus()):!e.shiftKey&&document.activeElement===i&&(e.preventDefault(),r.focus())};return window.addEventListener(`keydown`,r),()=>window.removeEventListener(`keydown`,r)},[n,a]),(0,$.jsx)(N,{open:n,onClose:l,className:`flex max-h-[85%] flex-col rounded-t-[14px] motion-reduce:animate-none`,children:(0,$.jsx)(`div`,{ref:c,className:`flex min-h-0 flex-1 flex-col`,children:s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border-soft px-1 pb-1`,children:[(0,$.jsx)(En,{label:`Back to file list`,onClick:()=>o(null),children:(0,$.jsx)(K,{className:`size-4`})}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs font-medium text-text-primary`,children:Tn(s.filePath)}),(0,$.jsx)(_n,{added:s.linesAdded,removed:s.linesRemoved,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(En,{label:`Close`,onClick:l,children:(0,$.jsx)(te,{className:`size-4`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border-soft py-1.5 pl-3 pr-2`,children:[(0,$.jsx)(`span`,{title:s.filePath,className:`min-w-0 flex-1 overflow-hidden text-ellipsis whitespace-nowrap font-mono text-[10.5px] text-text-subtle [direction:rtl] text-left`,children:s.filePath}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void ze(s.filePath),className:`inline-flex min-h-11 shrink-0 items-center rounded-md px-2.5 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:`copy`}),s.edits[0]?.editRef&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(s.edits[0].editRef),className:`inline-flex min-h-11 shrink-0 items-center gap-1 rounded-md px-2.5 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface hover:text-primary`,children:[(0,$.jsx)(ye,{className:`size-3`}),`card`]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,$.jsx)(bn,{change:s,onJump:u})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border-soft px-3 pb-2`,children:[(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs font-medium text-text-primary`,children:[`Changed this turn · `,e.length,` file`,e.length===1?``:`s`]}),(0,$.jsx)(_n,{added:t.added,removed:t.removed,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(En,{label:`Close`,onClick:l,children:(0,$.jsx)(te,{className:`size-4`})})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:e.map((e,t)=>(0,$.jsx)(vn,{change:e,onClick:()=>o(t)},e.filePath))})]})})})}function On({timestamp:e,content:t,changes:n,onJumpToEdit:r}){let[i,a]=(0,Q.useState)(!1),o=se(),s=(0,Q.useRef)(null),c=()=>{a(!1),s.current?.focus()},l=(0,$.jsx)(dn,{timestamp:e,content:t,className:`-mt-1.5`,children:n&&n.length>0&&(0,$.jsx)(pn,{ref:s,count:n.length,totals:fn(n),open:i,onToggle:()=>i?c():a(!0)})});return!n||n.length===0?l:(0,$.jsxs)($.Fragment,{children:[l,o?(0,$.jsx)(Dn,{changes:n,totals:fn(n),open:i,onClose:c,onJump:r??(()=>{})}):i&&(0,$.jsx)(wn,{changes:n,onJump:e=>{a(!1),r?.(e)},onClose:c})]})}function kn(e){return e.inputTokens+e.cacheReadTokens+e.cacheWriteTokens}function An(e){return e.inputTokens+e.cacheWriteTokens}var jn=.5,Mn=.9,Nn={cache_expired:`the session's prompt cache had already lapsed, so PPM released its subprocess`,idle_timeout:`the session sat idle with no tab open long enough for PPM to release its subprocess`,warm_idle_cap:`too many idle sessions were holding a subprocess, so this one was released early`,tab_closed:`PPM shut the session's subprocess down when the last tab disconnected`,set_model:`the model was changed, which restarts the session`,stream_ended:`the session's subprocess had already exited`,resume:`the session was resumed on a new subprocess`};function Pn(e){let t=An(e),n=kn(e);if(!e.coldStart||n<2e4)return{level:`ok`,wastedTokens:t,reason:``};let r=e.cacheHitRate<jn?`bad`:e.cacheHitRate<Mn?`warn`:`ok`;if(r===`ok`)return{level:r,wastedTokens:t,reason:``};let i=e.coldReason?Nn[e.coldReason]??`the session restarted (${e.coldReason})`:null;return{level:r,wastedTokens:t,reason:i?`${Rn(t)} of this session's transcript was re-sent uncached because ${i}.`:`${Rn(t)} of this session's transcript was re-sent uncached.`}}var Fn=.1,In=1.25;function Ln(e){let t=kn(e);if(t===0)return 1;let n=e.inputTokens+e.cacheWriteTokens*In+e.cacheReadTokens*Fn,r=t*Fn;return r>0?Math.max(1,n/r):1}function Rn(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(e>=1e4?0:1)}k`:String(e)}function zn({usage:e}){let[t,n]=(0,Q.useState)(!1),r=Pn(e);if(r.level===`ok`)return null;let i=Ln(e),a=kn(e),o=Math.round(e.cacheHitRate*100),c=r.level===`bad`;return(0,$.jsxs)(`div`,{className:`rounded-md border px-2.5 py-2 text-[11px] ${c?`border-warning/40 bg-warning/10`:`border-border bg-surface`}`,children:[(0,$.jsxs)(`button`,{onClick:()=>n(e=>!e),"aria-expanded":t,className:`flex w-full items-start gap-2 py-1 text-left text-text-secondary transition-colors hover:text-text-primary`,children:[(0,$.jsx)(W,{className:`mt-px size-3.5 shrink-0 ${c?`text-warning`:`text-text-subtle`}`}),(0,$.jsxs)(`span`,{className:`flex-1`,children:[`Costly turn — `,o,`% of a `,Rn(a),`-token transcript came from cache, so it cost about`,` `,(0,$.jsxs)(`strong`,{className:`font-semibold`,children:[i.toFixed(1),`x`]}),` a fully cached turn.`]}),(0,$.jsx)(s,{className:`mt-px size-3.5 shrink-0 transition-transform ${t?`rotate-180`:``}`})]}),t&&(0,$.jsxs)(`div`,{className:`mt-2 flex flex-col gap-2 border-t border-border pt-2`,children:[r.reason&&(0,$.jsx)(`p`,{className:`text-text-secondary`,children:r.reason}),(0,$.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-1 font-mono text-[10.5px] text-text-subtle`,children:[(0,$.jsx)(Bn,{label:`From cache`,value:`${Rn(e.cacheReadTokens)} (${o}%)`}),(0,$.jsx)(Bn,{label:`Written to cache`,value:Rn(e.cacheWriteTokens)}),(0,$.jsx)(Bn,{label:`Fresh input`,value:Rn(e.inputTokens)}),(0,$.jsx)(Bn,{label:`Output`,value:Rn(e.outputTokens)}),(0,$.jsx)(Bn,{label:`Model`,value:e.model||`unknown`}),(0,$.jsx)(Bn,{label:`Cost`,value:`$${e.costUsd.toFixed(4)}`})]}),(0,$.jsx)(`p`,{className:`text-text-subtle`,children:`A turn stays cached while the session keeps running. Closing the last tab of an idle session, switching model, or a retry all restart it, and the next turn re-sends the transcript at full price.`})]})]})}function Bn({label:e,value:t}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`dt`,{className:`truncate`,children:e}),(0,$.jsx)(`dd`,{className:`truncate text-right text-text-secondary`,children:t})]})}function Vn(e,t,n,r){let[i,a]=(0,Q.useState)([]),o=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(!n||!e||!t){a([]);return}let r=!1;return o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{E.get(`/api/project/${encodeURIComponent(e)}/chat/sessions/${encodeURIComponent(t)}/tasks`).then(e=>{r||a(e)}).catch(()=>{})},300),()=>{r=!0,o.current&&clearTimeout(o.current)}},[e,t,n,r]),i}var Hn=new Set([`TaskCreate`,`TaskUpdate`,`TaskStop`]);function Un(e){let t=0;for(let n of e)if(n.events)for(let e of n.events)e.type===`tool_use`&&Hn.has(e.tool)&&t++;return t}var Wn={completed:{icon:`✓`,cls:`text-success`},in_progress:{icon:`▶`,cls:`text-warning`},stopped:{icon:`■`,cls:`text-text-subtle`},pending:{icon:`○`,cls:`text-text-subtle`}};function Gn({projectName:e,sessionId:t,messages:n}){let r=(0,Q.useMemo)(()=>Un(n),[n]),i=Vn(e,t,r>0,r),[a,o]=(0,Q.useState)(!0);if(i.length===0||i.every(e=>e.status===`completed`||e.status===`stopped`))return null;let l=i.filter(e=>e.status===`completed`).length,u=i.length,f=u?Math.round(l/u*100):0;return(0,$.jsxs)(`div`,{className:`shrink-0 border-b border-border bg-surface/60 backdrop-blur-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`flex items-center gap-2 w-full px-3 min-h-11 text-left text-xs hover:bg-surface transition-colors`,children:[a?(0,$.jsx)(c,{className:`size-3.5 shrink-0`}):(0,$.jsx)(s,{className:`size-3.5 shrink-0`}),(0,$.jsx)(d,{className:`size-3.5 shrink-0 text-text-secondary`}),(0,$.jsx)(`span`,{className:`text-text-primary font-medium`,children:`Tasks`}),(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[l,`/`,u,` done`]}),(0,$.jsx)(`span`,{className:`ml-auto h-1 w-16 rounded-full bg-border overflow-hidden shrink-0`,children:(0,$.jsx)(`span`,{className:`block h-full bg-success/70`,style:{width:`${f}%`}})})]}),!a&&(0,$.jsx)(`ul`,{className:`px-3 pb-2 space-y-0.5 max-h-48 overflow-y-auto`,children:i.map(e=>(0,$.jsx)(Kn,{task:e},e.id))})]})}function Kn({task:e}){let t=Wn[e.status]??Wn.pending,n=e.status===`in_progress`;return(0,$.jsxs)(`li`,{className:`flex items-start gap-1.5 text-xs rounded px-1 ${n?`bg-warning/10`:``}`,children:[(0,$.jsx)(`span`,{className:`shrink-0 mt-0.5 ${t.cls}`,children:t.icon}),(0,$.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:n?`text-text-primary font-medium`:`text-text-secondary`,children:e.subject||(0,$.jsxs)(`span`,{className:`text-text-subtle italic`,children:[`#`,e.id,` (no title)`]})})]})}var qn=/read the full transcript at:\s*(\S+\.jsonl)/i;function Jn(e){return e.match(qn)?.[1]?.trim()??null}var Yn=class extends Q.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?this.props.fallback?this.props.fallback:this.props.fallbackContent?(0,$.jsx)(`div`,{className:`text-sm whitespace-pre-wrap break-words text-text-primary opacity-80`,children:this.props.fallbackContent}):null:this.props.children}};function Xn({projectName:e,onSelectSession:t}){return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-6 text-text-secondary overflow-y-auto`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,$.jsx)(i,{className:`size-10 text-text-subtle`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Send a message to start a new conversation`})]}),(0,$.jsx)(Y,{projectName:e,onSelectSession:t,className:`w-full px-4`})]})}var Zn=3200,Qn=1e3,$n={hasAbove:!1,atBottom:!0,idx:0,total:0};function er({scrollElement:e,userIndices:t,scrollToBottom:n}){let r=se(),[i,a]=(0,Q.useState)($n),[o,c]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(0),f=(0,Q.useRef)(Zn),p=(0,Q.useRef)(null),m=(0,Q.useRef)(null),h=(0,Q.useRef)(!1),g=(0,Q.useRef)(!1),_=(e,t,n)=>t.getBoundingClientRect().top-n+e.scrollTop,v=(0,Q.useCallback)(e=>Array.from(e.querySelectorAll(`[data-msg-index]`)).filter(e=>t.includes(Number(e.dataset.msgIndex))),[t]);(0,Q.useEffect)(()=>{let t=e;if(!t)return;let n=0,r=()=>{let e=t.scrollTop,n=t.getBoundingClientRect().top,r=v(t).map(e=>_(t,e,n)),i=0;for(let t=0;t<r.length;t++)r[t]<=e+12&&(i=t+1);let o={hasAbove:r.some(t=>t<e-4),atBottom:t.scrollHeight-e-t.clientHeight<8,idx:i,total:r.length};a(e=>e.hasAbove===o.hasAbove&&e.atBottom===o.atBottom&&e.idx===o.idx&&e.total===o.total?e:o)},i=()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(r)};r(),t.addEventListener(`scroll`,i,{passive:!0});let o=new ResizeObserver(i);return o.observe(t),()=>{n&&cancelAnimationFrame(n),t.removeEventListener(`scroll`,i),o.disconnect()}},[e,v]),(0,Q.useEffect)(()=>{if(!o)return;let e=setTimeout(()=>c(!1),f.current);return()=>clearTimeout(e)},[o,i.idx,u]),(0,Q.useEffect)(()=>{if(!o||!g.current)return;g.current=!1;let e=p.current;(e?.querySelector(`button:not(:disabled)`)??e)?.focus()},[o]),(0,Q.useEffect)(()=>{o||!h.current||(h.current=!1,m.current?.focus())},[o]);let y=(0,Q.useCallback)(()=>{f.current=Zn,d(e=>e+1)},[]),b=(0,Q.useCallback)(()=>{let t=e;if(!t)return;let n=t.scrollTop,r=t.getBoundingClientRect().top,i;for(let e of v(t)){let a=_(t,e,r);if(a<n-4)i=a;else break}i!=null&&t.scrollTo({top:i,behavior:`auto`}),y()},[e,v,y]),x=(0,Q.useCallback)(()=>{let t=e;if(!t)return;let r=t.scrollTop,i=t.getBoundingClientRect().top,a=v(t).map(e=>_(t,e,i)).find(e=>e>r+4);a==null?n({animation:`instant`}):t.scrollTo({top:a,behavior:`auto`}),y()},[e,v,n,y]),S=(0,Q.useCallback)(()=>{n({animation:`instant`}),y()},[n,y]);(0,Q.useEffect)(()=>{let t=e;if(!t)return;let n=e=>()=>{mn(t)&&(e(),f.current=Qn,c(!0))},r=n(b),i=n(x);return window.addEventListener(`chat-nav-prev`,r),window.addEventListener(`chat-nav-next`,i),()=>{window.removeEventListener(`chat-nav-prev`,r),window.removeEventListener(`chat-nav-next`,i)}},[e,b,x]);let C=k(`w-[34px] flex items-center justify-center rounded-[9px] text-text-secondary`,`motion-safe:transition-colors hover:bg-surface-elevated hover:text-foreground`,`disabled:opacity-30 disabled:cursor-default disabled:hover:bg-transparent disabled:hover:text-text-secondary`,r?`h-9`:`h-[30px]`);return(0,$.jsx)(`div`,{className:`absolute bottom-3 right-2.5 z-10 flex flex-col items-end gap-1.5`,children:o?(0,$.jsxs)(`div`,{ref:p,tabIndex:-1,className:`flex flex-col p-[3px] rounded-xl border border-border bg-surface-elevated/95 backdrop-blur-[8px] shadow-lg outline-none`,onFocus:()=>{h.current=!0},onKeyDown:e=>{e.key===`Escape`&&c(!1)},children:[(0,$.jsx)(`button`,{type:`button`,onClick:b,disabled:!i.hasAbove,"aria-label":`Jump to previous message`,className:C,children:(0,$.jsx)(l,{className:`size-[15px]`})}),(0,$.jsx)(`span`,{className:`font-mono text-[10px] font-medium text-text-subtle text-center py-px`,"aria-label":`Message ${i.idx||1} of ${i.total}`,children:i.total?`${i.idx||1}/${i.total}`:`0/0`}),(0,$.jsx)(`button`,{type:`button`,onClick:x,disabled:i.atBottom,"aria-label":`Jump to next message`,className:C,children:(0,$.jsx)(s,{className:`size-[15px]`})}),(0,$.jsx)(`button`,{type:`button`,onClick:S,disabled:i.atBottom,"aria-label":`Jump to latest`,className:C,children:(0,$.jsx)(st,{className:`size-[13px]`})})]}):(0,$.jsx)(`button`,{ref:m,type:`button`,onClick:()=>{f.current=Zn,g.current=!0,c(!0)},"aria-label":`Navigate messages`,"aria-expanded":!1,title:`Navigate messages`,className:k(`group flex items-center justify-center`,r?`size-11`:`size-[30px]`),children:(0,$.jsx)(`span`,{className:k(`flex items-center justify-center rounded-full border border-border bg-surface-elevated/55 backdrop-blur-[6px] text-text-subtle`,`motion-safe:transition-colors group-hover:bg-surface-elevated group-hover:text-foreground`,r?`size-9`:`size-[30px]`),children:(0,$.jsx)(F,{className:`size-[15px]`})})})})}function tr({group:e,onNavigate:t,disabled:n}){if(!e||e.ids.length<2)return null;let{ids:r,currentIndex:i}=e,a=e=>{let i=r[e];i&&!n&&t(i)};return(0,$.jsxs)(`div`,{className:`mt-1 flex items-center gap-1 text-xs text-text-subtle select-none`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>a(i-1),disabled:n||i<=0,"aria-label":`Previous version`,className:`flex items-center justify-center rounded p-0.5 hover:text-text-primary disabled:opacity-30 disabled:cursor-default`,children:(0,$.jsx)(K,{className:`size-3.5`})}),(0,$.jsxs)(`span`,{className:`tabular-nums`,children:[i+1,`/`,r.length]}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>a(i+1),disabled:n||i>=r.length-1,"aria-label":`Next version`,className:`flex items-center justify-center rounded p-0.5 hover:text-text-primary disabled:opacity-30 disabled:cursor-default`,children:(0,$.jsx)(c,{className:`size-3.5`})})]})}function nr(e){let[t,n]=(0,Q.useState)({}),[r,i]=(0,Q.useState)({}),[a,o]=(0,Q.useState)(0),s=(0,Q.useCallback)((e,t)=>{n(n=>({...n,[e]:[t]})),i(t=>({...t,[e]:``}))},[]),c=(0,Q.useCallback)((e,t)=>{n(n=>{let r=n[e]||[];return{...n,[e]:r.includes(t)?r.filter(e=>e!==t):[...r,t]}})},[]),l=(0,Q.useCallback)((e,t)=>{i(n=>({...n,[e]:t})),t&&n(t=>({...t,[e]:[]}))},[]),u=(0,Q.useCallback)(e=>(t[e]?.length??0)>0||(r[e]?.trim().length??0)>0,[t,r]);return{answers:t,customInputs:r,activeTab:a,setActiveTab:o,handleSingleSelect:s,handleMultiSelect:c,handleCustomInput:l,hasAnswer:u,allAnswered:(0,Q.useMemo)(()=>e.every((e,t)=>u(t)),[e,u]),getFinalAnswer:(0,Q.useCallback)(e=>r[e]?.trim()||(t[e]??[]).join(`, `),[t,r]),goToNextTab:(0,Q.useCallback)(()=>o(t=>Math.min(t+1,e.length-1)),[e.length]),goToPrevTab:(0,Q.useCallback)(()=>o(e=>Math.max(e-1,0)),[])}}function rr(e){let[t,n]=(0,Q.useState)(0),r=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>n(0),[e.activeTab]),(0,Q.useEffect)(()=>{if(!e.enabled)return;let i=r=>{let i=e.customInputRef.current,a=!!i&&i.ownerDocument.activeElement===i;if(!a&&r.key>=`1`&&r.key<=`9`){r.preventDefault();let t=parseInt(r.key)-1;t<e.totalOptions-1&&(n(t),e.onSelectOption(t));return}if(!a&&(r.key===`o`||r.key===`O`||r.key===`0`)){r.preventDefault(),e.customInputRef.current?.focus(),n(e.totalOptions-1);return}if(r.key===`Tab`&&e.questions.length>1){r.preventDefault(),r.shiftKey?e.goToPrevTab():e.goToNextTab();return}if(!a){if(r.key===`ArrowLeft`){r.preventDefault(),e.goToPrevTab();return}if(r.key===`ArrowRight`){r.preventDefault(),e.goToNextTab();return}if(r.key===`ArrowUp`){r.preventDefault(),n(e=>Math.max(0,e-1));return}if(r.key===`ArrowDown`){r.preventDefault(),n(t=>Math.min(e.totalOptions-1,t+1));return}if(r.key===` `){r.preventDefault(),e.onSelectOption(t);return}}if(r.key===`Enter`){r.preventDefault(),e.allAnswered?e.onSubmit():e.hasAnswer(e.activeTab)&&e.goToNextTab();return}r.key===`Escape`&&a&&e.customInputRef.current?.blur()},a=r.current;return a&&(a.addEventListener(`keydown`,i),a.setAttribute(`tabindex`,`0`),a.contains(a.ownerDocument.activeElement)||a.focus()),()=>{a?.removeEventListener(`keydown`,i)}},[e,t]),{focusedOption:t,setFocusedOption:n,containerRef:r}}function ir({questions:e,onSubmit:t,onSkip:n}){let r=(0,Q.useRef)(null),i=nr(e),a=e[i.activeTab],o=a?a.options.length+1:0,s=e.length>1,c=(0,Q.useCallback)(()=>{if(!i.allAnswered)return;let n={};e.forEach((e,t)=>{n[e.question]=i.getFinalAnswer(t)}),t(n)},[i.allAnswered,i.getFinalAnswer,e,t]),l=(0,Q.useCallback)(e=>{if(!(!a||e<0))if(e<a.options.length){let t=a.options[e]?.label;if(!t)return;a.multiSelect?i.handleMultiSelect(i.activeTab,t):i.handleSingleSelect(i.activeTab,t)}else e===a.options.length&&r.current?.focus()},[a,i]),u=rr({questions:e,activeTab:i.activeTab,totalOptions:o,allAnswered:i.allAnswered,hasAnswer:i.hasAnswer,onSelectOption:l,goToNextTab:i.goToNextTab,goToPrevTab:i.goToPrevTab,onSubmit:c,customInputRef:r,enabled:!0}),d=(0,Q.useCallback)(e=>{l(e),u.setFocusedOption(e)},[l,u.setFocusedOption]);return(0,$.jsxs)(`div`,{ref:u.containerRef,className:`rounded-lg border-2 border-primary/30 bg-primary/5 p-3 space-y-3 outline-none animate-in slide-in-from-bottom-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,$.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,$.jsxs)(`span`,{className:`text-[10px] text-text-secondary font-normal`,children:[s?`←→ tabs · `:``,`↑↓ options · 1-`,Math.min(o-1,9),` select · Enter submit`]})]}),s&&(0,$.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,$.jsxs)(`button`,{className:`flex items-center gap-1.5 px-3 py-1.5 rounded text-xs whitespace-nowrap transition-all ${i.activeTab===t?`bg-primary text-primary-foreground`:i.hasAnswer(t)?`text-primary bg-transparent`:`text-text-secondary hover:bg-surface-elevated`}`,onClick:()=>{i.setActiveTab(t),u.setFocusedOption(0)},tabIndex:-1,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-semibold ${i.activeTab===t?`bg-white/20`:i.hasAnswer(t)?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:i.hasAnswer(t)?`✓`:t+1}),(0,$.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,$.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,$.jsx)(`div`,{className:`text-sm text-text-primary select-text`,children:a.question}),a.multiSelect&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a.options.map((e,t)=>{let n=(i.answers[i.activeTab]||[]).includes(e.label),r=u.focusedOption===t;return(0,$.jsxs)(`div`,{role:`button`,onClick:()=>d(t),className:`text-left flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border transition-all cursor-pointer select-text ${n?`border-primary bg-primary/10 text-text-primary`:`border-border bg-background text-text-secondary hover:border-primary/40 hover:bg-primary/5`} ${r?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded text-[10px] font-semibold shrink-0 mt-px ${n?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:t+1}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,$.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,$.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border border-dashed transition-all border-border bg-transparent ${u.focusedOption===o-1?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded bg-surface-elevated text-text-secondary text-[10px] font-semibold shrink-0 mt-px`,children:`O`}),(0,$.jsx)(`input`,{ref:r,type:`text`,className:`flex-1 px-2 py-1 text-xs bg-surface border border-border rounded text-text-primary outline-none placeholder:text-text-subtle focus:border-primary`,placeholder:`Other (press O to type)...`,value:i.customInputs[i.activeTab]||``,onChange:e=>i.handleCustomInput(i.activeTab,e.target.value),onFocus:()=>u.setFocusedOption(o-1)})]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToPrevTab,disabled:i.activeTab===0,tabIndex:-1,children:`← Prev`}),(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToNextTab,disabled:i.activeTab===e.length-1,tabIndex:-1,children:`Next →`})]}),(0,$.jsx)(`button`,{onClick:n,className:`px-4 py-1.5 rounded border border-border bg-background text-text-secondary text-xs hover:bg-surface-elevated transition-colors`,tabIndex:-1,children:`Skip`}),(0,$.jsxs)(`button`,{onClick:c,disabled:!i.allAnswered,className:`px-4 py-1.5 rounded bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,tabIndex:-1,children:[`Submit `,i.allAnswered?`✓`:`(${e.filter((e,t)=>i.hasAnswer(t)).length}/${e.length})`]})]})]})}var ar={"system-reminder":`Context`,claudeMd:`CLAUDE.md`,gitStatus:`Git Status`,currentDate:`Date`,fast_mode_info:`Fast Mode`,"available-deferred-tools":`Tools`,"task-notification":`Task Result`,environment_details:`Environment`,"local-command-caveat":`System`};function or(e){let t=[],n=/<(system-reminder|available-deferred-tools|antml:[\w-]+|fast_mode_info|claudeMd|gitStatus|currentDate|task-notification|environment_details|local-command-caveat)[^>]*>([\s\S]*?)<\/\1>/g,r;for(;(r=n.exec(e))!==null;){let e=r[1];t.push({name:e,label:ar[e]??e.replace(/^antml:/,``).replace(/-/g,` `),content:r[2].trim()})}return{cleanText:e.replace(n,``).trim(),tags:t}}function sr(e){let t=e.match(/<command-name>([\s\S]*?)<\/command-name>/);if(!t)return{command:null,cleanText:e};let n=t[1].trim(),r=e.match(/<command-args>([\s\S]*?)<\/command-args>/)?.[1]?.trim()||void 0,i=e.replace(/<command-name>[\s\S]*?<\/command-name>/g,``).replace(/<command-message>[\s\S]*?<\/command-message>/g,``).replace(/<command-args>[\s\S]*?<\/command-args>/g,``).trim();return{command:{name:n,args:r},cleanText:i}}function cr(e){let t=e.match(/^Use the (\S+) agent to\s?/);return t?{agent:t[1],cleanText:e.slice(t[0].length)}:{agent:null,cleanText:e}}function lr(e){let t=/<ide_opened_file>([\s\S]*?)<\/ide_opened_file>/g.exec(e);return t?{idePath:t[1].match(/opened the file (.+?) in the IDE/)?.[1]?.trim()??null,cleanText:e.replace(/<ide_opened_file>[\s\S]*?<\/ide_opened_file>/g,``).trim()}:{idePath:null,cleanText:e}}function ur(e){let t=[],n=e;for(;;){let e=n.match(/^\[Attached image \(contents included in this message\): (.+?)\]\n*/);if(e){t.push(e[1]),n=n.slice(e[0].length);continue}break}if(t.length>0){let e=ur(n);return{files:[...t,...e.files],text:e.text}}let r=n.match(/^\[Attached file: (.+?)\]\n*/);if(r)return{files:[r[1]],text:n.slice(r[0].length)};let i=n.match(/^\[Attached files:\n([\s\S]+?)\]\n*/);return i?{files:i[1].split(`
3
- `).map(e=>e.trim()).filter(Boolean),text:n.slice(i[0].length)}:{files:[],text:n}}function dr(e){let t=[],n=e,r=/^```(?:bash|sh|shell|zsh)\n([\s\S]*?)\n```\s*(?:\n\n?)?/,i;for(;(i=n.match(r))!==null;)t.push(i[1]),n=n.slice(i[0].length);return{blocks:t,remainingText:n.trim()}}function fr(e){let{idePath:t,cleanText:n}=lr(e),{blocks:r,remainingText:i}=dr(n),a=ur(i),{cleanText:o,tags:s}=or(a.text.replace(/<local-command-(?:stdout|stderr)>([\s\S]*?)<\/local-command-(?:stdout|stderr)>/g,`$1`)),{command:c,cleanText:l}=sr(o),{agent:u,cleanText:d}=cr(l),f=c?.args?d?`${c.args}\n\n${d}`:c.args:d;return{files:a.files,text:f,body:d,tags:s,command:c,terminalBlocks:r,idePath:t,agent:u}}function pr(e){let{agent:t,body:n,command:r}=fr(e);if(!r)return{agent:t,text:n};let i=`/${r.name.replace(/^\/+/,``)}${r.args?` ${r.args}`:``}`;return{agent:t,text:n?`${i}\n\n${n}`:i}}var mr=re(()=>import(`./markdown-renderer-CY1epGRc.js`),__vite__mapDeps([4,5,1,6,2,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48])),hr=(0,Q.lazy)(()=>mr.then(e=>({default:e.MarkdownRenderer})));function gr({messages:e,messagesLoading:t,keepStaleWhileLoading:n,pendingApproval:r,onApprovalResponse:a,isStreaming:o,phase:s,onSelectSession:c,connectingElapsed:l,statusMessage:u,compactStatus:d,projectName:f,onFork:m,onEdit:h,editingMsgId:g,sessionId:_,providerId:v,onNavigateVersion:y,versionMap:b,bashPartialOutput:x,onExpandCompact:S,isCompactExpanded:C,onDismissMessage:ee,onClearErrors:te}){let{scrollRef:T,contentRef:E,scrollToBottom:D,stopScroll:ne,isAtBottom:re}=Rt({initial:`instant`,resize:`instant`}),O=(0,Q.useMemo)(()=>e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return e.role===`user`?t:t||n}),[e]),k=!!r||o,[A,ie]=(0,Q.useState)(null),ae=(0,Q.useCallback)(e=>{T(e),ie(e)},[T]),j=(0,Q.useRef)(new Map),oe=(0,Q.useMemo)(()=>{let e=j.current,t=new Map;for(let n=0;n<O.length;n++){let r=O[n];if(r.role!==`assistant`||O[n+1]?.role===`assistant`)continue;let i=`${r.id}:${r.events?.length??0}`,a=e.get(i);a||(a=on(sn(O,n)),e.set(i,a)),a.length>0&&t.set(n,a)}return t},[O]),se=(0,Q.useRef)(null),M=(0,Q.useCallback)(e=>{A&&(se.current?.(),se.current=Xt(A,e))},[A]);(0,Q.useEffect)(()=>()=>se.current?.(),[]);let N=(0,Q.useRef)(null);(0,Q.useLayoutEffect)(()=>{let e=A;e&&N.current!=null&&(e.scrollTop=e.scrollHeight-N.current,N.current=null)},[O.length,A]),(0,Q.useLayoutEffect)(()=>{A&&D({animation:`instant`})},[_,A]);let P=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>{A&&A.clientHeight>0&&(P.current=re)},[re,A]),(0,Q.useEffect)(()=>{let e=A;if(!e)return;let t=e.clientHeight,n=new ResizeObserver(()=>{let n=e.clientHeight,r=t===0&&n>0;t=n,r&&!P.current&&ne()});return n.observe(e),()=>n.disconnect()},[A,ne]);let ce=(0,Q.useCallback)((e,t)=>{m?.(e,t)},[m]),le=(0,Q.useCallback)((e,t,n)=>{h?.(e,t,n)},[h]),ue=(0,Q.useCallback)(e=>{ee?.(e)},[ee]),F=(0,Q.useMemo)(()=>O.reduce((e,t)=>t.role===`system`?e+1:e,0),[O]),I=(0,Q.useMemo)(()=>O.reduce((e,t,n)=>(t.role===`user`&&e.push(n),e),[]),[O]),de=(0,Q.useCallback)(()=>{if(!S||!C)return null;for(let e of O){if(C(e.id))continue;let t=Jn(e.content||``);if(t)return{id:e.id,jsonlPath:t};if(e.events){for(let t of e.events)if(t.type===`text`){let n=Jn(t.content||``);if(n)return{id:e.id,jsonlPath:n}}}}return null},[O,S,C])(),fe=!!de,[L,R]=(0,Q.useState)(!1),z=(0,Q.useCallback)(async()=>{if(!de||!S||L)return;let e=A;N.current=e?e.scrollHeight-e.scrollTop:null,R(!0);try{await S(de.id,de.jsonlPath)}finally{R(!1)}},[de,S,L,A]);return(0,Q.useEffect)(()=>{let e=A;if(!e||!fe)return;let t=()=>{e.scrollTop<200&&!L&&z()};return e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[A,fe,L,z]),t&&(!n||e.length===0)?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,$.jsx)(i,{className:`size-10 text-text-subtle animate-pulse`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!o?(0,$.jsx)(Xn,{projectName:f||``,onSelectSession:c||(()=>{})}):(0,$.jsxs)(`div`,{className:`relative flex-1 overflow-hidden flex flex-col min-h-0`,children:[(0,$.jsx)(Gn,{projectName:f,sessionId:_,messages:e}),F>1&&te&&(0,$.jsx)(`div`,{className:`absolute top-2 left-0 right-0 z-20 flex justify-center pointer-events-none`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:te,className:`pointer-events-auto flex items-center gap-1.5 rounded-full bg-error/15 border border-error/25 px-3 py-1 text-xs text-error hover:bg-error/25 shadow-md backdrop-blur-sm`,children:[(0,$.jsx)(p,{className:`size-3.5`}),`Clear all errors (`,F,`)`]})}),L&&(0,$.jsxs)(`div`,{className:`absolute top-2 left-0 right-0 z-10 flex items-center justify-center gap-1.5 text-xs text-text-secondary pointer-events-none`,children:[(0,$.jsx)(w,{className:`size-3 animate-spin`}),`Loading previous conversation...`]}),(0,$.jsx)(`div`,{ref:ae,[Je]:``,className:`flex-1 overflow-y-auto overflow-x-hidden [overflow-anchor:none]`,style:{WebkitOverflowScrolling:`touch`,overscrollBehavior:`contain`},children:(0,$.jsxs)(`div`,{ref:E,className:`w-full`,children:[O.map((e,t)=>{let n=t>0?O[t-1]:void 0,r=e.role===`user`?O.slice(0,t+1).reduce((e,t)=>e+(t.role===`user`?1:0),0):0,i=r?b?.[r]:void 0,a=e.role===`user`&&g!=null&&e.id===g,s=O[t+1],c=e.role===`assistant`&&s?.role!==`assistant`,l;if(c){let e=[];for(let n=t;n>=0&&O[n].role===`assistant`;n--){let t=_r(O[n]);t&&e.unshift(t)}l=e.join(`
4
-
5
- `)}return(0,$.jsx)(`div`,{"data-msg-index":t,className:`px-4 pt-4 select-none`,children:(0,$.jsx)(Yn,{fallbackContent:e.content,children:(0,$.jsx)(vr,{message:e,isStreaming:o&&e.id.startsWith(`streaming-`),isLastAssistantInTurn:c,turnCopyText:l,turnChanges:c?oe.get(t):void 0,onJumpToEdit:M,projectName:f,onFork:e.role===`user`&&m?ce:void 0,onEdit:e.role===`user`&&h?le:void 0,isEditing:a,onDismiss:e.role===`system`&&ee?ue:void 0,prevMsgId:n?.sdkUuid??n?.id,sessionId:_,providerId:v,versionGroup:i,onNavigateVersion:y,versionNavDisabled:o,bashPartialOutput:x})})},e.id)}),k&&(0,$.jsxs)(`div`,{className:`px-4 pt-4 pb-4 space-y-4 select-none`,children:[r&&(r.tool===`AskUserQuestion`?(0,$.jsx)(Ur,{approval:r,onRespond:a}):(0,$.jsx)(Hr,{approval:r,onRespond:a})),o&&(0,$.jsx)(Rr,{lastMessage:e[e.length-1],phase:s,elapsed:l,statusMessage:d===`compacting`?`Compacting messages...`:u})]})]})}),(0,$.jsx)(er,{scrollElement:A,userIndices:I,scrollToBottom:D})]})}function _r(e){return e.events?.length?e.events.filter(e=>e.type===`text`).map(e=>e.content).join(``):e.content}var vr=(0,Q.memo)(function({message:e,isStreaming:t,isLastAssistantInTurn:n,turnCopyText:r,turnChanges:i,onJumpToEdit:a,projectName:o,onFork:s,onEdit:c,isEditing:l,onDismiss:u,prevMsgId:d,sessionId:f,providerId:m,versionGroup:h,onNavigateVersion:g,versionNavDisabled:_,bashPartialOutput:v}){if(e.role===`user`){let t=s?()=>s(e.content,d):void 0,n=c?()=>c(e.content,d,e.id):void 0;return(0,$.jsx)(Cr,{content:e.content,messageId:e.id,timestamp:e.timestamp,projectName:o,onFork:t,onEdit:n,isEditing:l,sessionId:f,providerId:m,versionGroup:h,onNavigateVersion:g,versionNavDisabled:_})}return e.role===`system`?(0,$.jsxs)(`div`,{className:`group flex items-center gap-2 rounded-lg bg-error/10 border border-error/20 px-3 py-2 text-sm text-error`,children:[(0,$.jsx)(de,{className:`size-4 shrink-0`}),(0,$.jsx)(`p`,{className:`flex-1`,children:e.content}),u&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>u(e.id),"aria-label":`Dismiss`,title:`Dismiss`,className:`shrink-0 rounded p-1 text-error/70 hover:text-error hover:bg-error/15 md:opacity-0 md:group-hover:opacity-100`,children:(0,$.jsx)(p,{className:`size-4`})})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.events&&e.events.length>0?(0,$.jsx)(Fr,{events:e.events,isStreaming:t,projectName:o,bashPartialOutput:v}):e.content&&(0,$.jsx)(`div`,{className:`text-sm text-text-primary select-text`,children:(0,$.jsx)(Vr,{content:e.content,projectName:o})}),!t&&n&&e.usage&&(0,$.jsx)(zn,{usage:e.usage}),!t&&n&&(0,$.jsx)(On,{timestamp:e.timestamp,content:r??_r(e),changes:i,onJumpToEdit:a})]})}),yr=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]);function br(e,t){let n=ie(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function xr(e){let t=e.lastIndexOf(`.`);return t===-1?!1:yr.has(e.slice(t).toLowerCase())}var Sr=new Set([`task-notification`,`environment_details`,`local-command-caveat`]);function Cr({content:e,messageId:t,timestamp:n,projectName:r,onFork:a,onEdit:o,isEditing:c,sessionId:u,providerId:d,versionGroup:f,onNavigateVersion:p,versionNavDisabled:m}){let{files:h,text:g,tags:_,command:v,terminalBlocks:y,idePath:b,agent:x}=(0,Q.useMemo)(()=>fr(e),[e]),S=_.some(e=>Sr.has(e.name)),[C,w]=(0,Q.useState)(!1),[ee,te]=(0,Q.useState)(!1),T=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let e=T.current;if(!e)return;let t=()=>te(e.scrollHeight>e.clientHeight+2);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[g]),(0,$.jsxs)(`div`,{className:k(`flex flex-col gap-1`,!S&&`items-end`),children:[(0,$.jsxs)(`div`,{"data-user-message":S?void 0:`true`,style:S?void 0:{borderRadius:`var(--rad) var(--rad) 4px var(--rad)`},className:k(`group/user relative px-3 py-2 text-sm border shadow-sm transition-all`,S?`rounded-lg bg-surface/40 border-border/40 text-text-secondary`:`max-w-[80%] bg-accent-wash border-accent-wash-border text-text`,c&&`ring-2 ring-primary/60 border-primary/40`),children:[_.length>0&&(0,$.jsx)(Tr,{tags:_}),x&&(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-sky-500/15 border border-sky-500/25 px-2 py-0.5 text-xs font-medium text-sky-600 dark:text-sky-400`,children:[(0,$.jsx)(i,{className:`size-3 shrink-0`}),x]})}),v&&(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-primary/15 border border-primary/20 px-2 py-0.5 text-xs font-medium text-primary`,children:[(0,$.jsx)(pt,{className:`size-3 shrink-0`}),v.name]})}),b&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-1 text-[11px] text-text-subtle`,children:[(0,$.jsx)(`span`,{className:`shrink-0`,children:`Opened in IDE:`}),(0,$.jsx)(kr,{path:b,projectName:r})]}),h.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:h.map((e,t)=>xr(e)?(0,$.jsx)(Pr,{filePath:e,projectName:r},t):(0,$.jsxs)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-background/40 px-1.5 py-0.5 text-[11px] text-text-secondary`,children:[(0,$.jsx)(De,{className:`size-3 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-32`,children:ie(e)})]},t))}),y.length>0&&(0,$.jsx)(`div`,{className:`space-y-1.5`,children:y.map((e,t)=>(0,$.jsx)(wr,{content:e},t))}),g&&(0,$.jsx)(`div`,{ref:T,className:k(`whitespace-pre-wrap break-words transition-all duration-200 select-text`,!C&&`line-clamp-2`,C&&`max-h-[50vh] overflow-y-auto`),children:S?(0,$.jsx)(jr,{text:g,projectName:r}):(0,$.jsx)(Ar,{text:g})}),(ee||C)&&(0,$.jsx)(`button`,{onClick:()=>w(!C),className:k(`flex items-center gap-1 text-xs mt-1 transition-colors`,S?`text-text-subtle hover:text-text-secondary`:`text-primary/70 hover:text-primary`),children:C?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(l,{className:`size-3`}),`Show less`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(s,{className:`size-3`}),`Show more`]})}),!S&&p&&(0,$.jsx)(tr,{group:f,onNavigate:p,disabled:m})]}),!S&&(0,$.jsxs)(dn,{timestamp:n,content:e,children:[o&&(0,$.jsx)(ln,{icon:(0,$.jsx)(be,{className:`size-3.5`}),label:`Edit`,title:`Edit this message (continue in the same tab)`,onClick:o}),a&&(0,$.jsx)(ln,{icon:(0,$.jsx)(L,{className:`size-3.5`}),label:`Fork`,title:`Retry from this message (fork into a new tab)`,onClick:a})]})]})}function wr({content:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),className:k(`flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs transition-colors`,t?`border-primary/50 bg-surface-elevated text-text-primary`:`border-border/60 bg-background/40 text-text-secondary hover:bg-surface`),children:[(0,$.jsx)(Ge,{className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{children:`Terminal output`}),(0,$.jsx)(s,{className:k(`size-3 shrink-0 transition-transform`,t&&`rotate-180`)})]}),t&&(0,$.jsx)(`pre`,{className:`mt-1 max-h-40 overflow-auto rounded-md border border-border bg-background p-2 text-xs text-text-primary font-mono whitespace-pre-wrap break-words`,children:e})]})}function Tr({tags:e}){return(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,$.jsx)(Er,{tag:e},t))})}function Er({tag:e}){let[t,n]=(0,Q.useState)(!1);return e.name===`task-notification`?(0,$.jsx)(Or,{content:e.content}):(0,$.jsxs)(`div`,{className:`text-xs`,children:[(0,$.jsxs)(`button`,{onClick:()=>n(!t),className:`flex items-center gap-1 rounded-full border border-border/60 bg-surface/50 px-2 py-0.5 text-text-subtle hover:text-text-secondary hover:bg-surface transition-colors`,children:[(0,$.jsx)(me,{className:`size-2.5`}),(0,$.jsx)(`span`,{children:e.label}),(0,$.jsx)(c,{className:k(`size-2.5 transition-transform`,t&&`rotate-90`)})]}),t&&(0,$.jsx)(`div`,{className:`mt-1 rounded border border-border/40 bg-surface/30 px-2 py-1.5 text-[11px] text-text-subtle/80 whitespace-pre-wrap max-h-40 overflow-y-auto leading-relaxed`,children:e.content})]})}function Dr(e,t){return e.match(RegExp(`<${t}>([\\s\\S]*?)</${t}>`))?.[1]?.trim()||void 0}function Or({content:e}){let[t,n]=(0,Q.useState)(!1),r=Dr(e,`status`),i=Dr(e,`summary`),a=Dr(e,`output-file`),o=Dr(e,`result`);return(0,$.jsxs)(`div`,{className:`text-xs`,children:[(0,$.jsxs)(`button`,{onClick:()=>n(!t),className:`flex items-center gap-1.5 rounded-full border border-border/60 bg-surface/50 px-2 py-0.5 text-text-subtle hover:text-text-secondary hover:bg-surface transition-colors`,children:[r===`completed`?(0,$.jsx)(Ue,{className:`size-2.5 text-success`}):(0,$.jsx)(p,{className:`size-2.5 text-warning`}),(0,$.jsx)(`span`,{className:`truncate max-w-80`,children:i??`Task notification`}),(0,$.jsx)(c,{className:k(`size-2.5 transition-transform shrink-0`,t&&`rotate-90`)})]}),t&&(0,$.jsxs)(`div`,{className:`mt-1 rounded border border-border/40 bg-surface/30 px-2 py-1.5 space-y-1.5`,children:[i&&(0,$.jsx)(`p`,{className:`text-[11px] text-text-secondary`,children:i}),a&&(0,$.jsx)(kr,{path:a}),o&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-subtle/80 max-h-60 overflow-y-auto leading-relaxed`,children:(0,$.jsx)(Vr,{content:o})})]})]})}function kr({path:e,projectName:t}){return(0,$.jsxs)(`button`,{type:`button`,onClick:(0,Q.useCallback)(()=>{let n=oe.getState().openTab,r=t??j.getState().activeProject?.name,i=ie(e),a={filePath:e};r&&(a.projectName=r),E.get(`/api/fs/read?path=${encodeURIComponent(e)}`).then(()=>{n({type:`editor`,title:i,metadata:a,projectId:null,closable:!0})}).catch(()=>{n({type:`editor`,title:i,metadata:a,projectId:null,closable:!0})})},[e,t]),className:`inline-flex items-center gap-1 rounded border border-border/50 bg-surface/50 px-1.5 py-0.5 font-mono text-[10px] text-text-secondary hover:text-text-primary hover:bg-surface transition-colors cursor-pointer`,children:[(0,$.jsx)(De,{className:`size-2.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-60`,children:ie(e)}),(0,$.jsx)(We,{className:`size-2 shrink-0 opacity-50`})]})}function Ar({text:e}){let t=(0,Q.useMemo)(()=>{let t=/(https?:\/\/[^\s<>()]+[^\s<>().,;:!?'"])/g,n=[],r=0,i;for(;(i=t.exec(e))!==null;)i.index>r&&n.push({kind:`text`,value:e.slice(r,i.index)}),n.push({kind:`url`,value:i[1]}),r=i.index+i[0].length;return r<e.length&&n.push({kind:`text`,value:e.slice(r)}),n},[e]);return t.every(e=>e.kind===`text`)?(0,$.jsx)($.Fragment,{children:e}):(0,$.jsx)($.Fragment,{children:t.map((e,t)=>e.kind===`url`?(0,$.jsx)(`a`,{href:e.value,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary underline underline-offset-2 hover:text-primary/80 break-all`,onClick:e=>e.stopPropagation(),children:e.value},t):(0,$.jsx)(`span`,{children:e.value},t))})}function jr({text:e,projectName:t}){return(0,$.jsx)($.Fragment,{children:(0,Q.useMemo)(()=>{let t=/(\/(?:[\w.\-]+\/)+[\w.\-]+)/g,n=[],r=0,i;for(;(i=t.exec(e))!==null;)i.index>r&&n.push({kind:`text`,value:e.slice(r,i.index)}),n.push({kind:`path`,value:i[1]}),r=i.index+i[0].length;return r<e.length&&n.push({kind:`text`,value:e.slice(r)}),n},[e]).map((e,n)=>e.kind===`path`?(0,$.jsx)(kr,{path:e.value,projectName:t},n):(0,$.jsx)(`span`,{children:e.value},n))})}var Mr=new Map;function Nr(e){let[t,n]=(0,Q.useState)(()=>Mr.get(e)?.url??null),[r,i]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{let t=Mr.get(e);if(t){n(t.url);return}let r=!1,a=D();return fetch(e,{headers:a?{Authorization:`Bearer ${a}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(t=>{if(r)return;let i=URL.createObjectURL(t);Mr.set(e,{url:i}),n(i)}).catch(()=>{r||i(!0)}),()=>{r=!0}},[e]),{blobUrl:t,error:r}}function Pr({filePath:e,projectName:t}){let{blobUrl:n,error:r}=Nr(br(e,t)),i=Z(e=>e.open),a=ie(e);return(0,$.jsxs)(`button`,{type:`button`,onClick:e=>n&&i(n,a,Ye(e.currentTarget)),className:`flex items-center gap-1 rounded-md border border-border/60 bg-background/40 px-1.5 py-0.5 text-[11px] text-text-secondary hover:bg-surface transition-colors cursor-pointer`,children:[n?(0,$.jsx)(`img`,{src:n,alt:a,[Xe]:``,className:`size-4 rounded-sm object-cover shrink-0`}):r?(0,$.jsx)(Le,{className:`size-3 shrink-0`}):(0,$.jsx)(`div`,{className:`size-4 rounded-sm bg-surface animate-pulse shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-32`,children:a})]})}function Fr({events:e,isStreaming:t,projectName:n,bashPartialOutput:r}){let i=[],a=``,o=``;for(let t=0;t<e.length;t++){let n=e[t];if(n.type===`thinking`){a&&=(i.push({kind:`text`,content:a}),``),o+=n.content;continue}if(o&&=(i.push({kind:`thinking`,content:o}),``),n.type===`account_retry`){a&&=(i.push({kind:`text`,content:a}),``);let e=n.accountLabel??`another account`,t=n.reason??`Auth failed`;i.push({kind:`text`,content:`\n\n> ↻ ${t} — retrying with **${e}**...\n\n`});continue}if(n.type===`text`)a+=n.content;else if(n.type===`tool_use`){let e=n.toolUseId,t=e?i.find(t=>t.kind===`tool`&&t.tool.type===`tool_use`&&t.tool.toolUseId===e):void 0;if(t){t.tool=n;continue}a&&=(i.push({kind:`text`,content:a}),``),i.push({kind:`tool`,tool:n})}else n.type===`tool_result`||(a&&=(i.push({kind:`text`,content:a}),``),i.push({kind:`tool`,tool:n}))}o&&i.push({kind:`thinking`,content:o}),a&&i.push({kind:`text`,content:a});let s=e.filter(e=>e.type===`tool_result`);for(let e of s){let t=e.toolUseId;if(t){let n=i.find(e=>e.kind===`tool`&&e.tool.type===`tool_use`&&e.tool.toolUseId===t);if(n){n.result=e;continue}}let n=i.find(e=>e.kind===`tool`&&!e.result);n&&(n.result=e)}for(let e of i)if(e.kind===`tool`&&!e.result&&e.tool.type===`tool_use`){let t=e.tool.result;t&&(e.result={type:`tool_result`,output:t.output,isError:t.isError})}for(let e=0;e<i.length;e++){let n=i[e];if(n.kind===`tool`&&!n.result){let r=!1;if(n.tool.type===`tool_use`&&n.tool.tool===`Read`){let t=n.tool.input?.file_path;t&&(r=i.slice(e+1).some(e=>e.kind===`tool`&&e.result&&e.tool.type===`tool_use`&&e.tool.tool===`Edit`&&e.tool.input?.file_path===t))}n.completed=r||!t}}return(0,$.jsx)($.Fragment,{children:i.map((e,a)=>{if(e.kind===`thinking`)return(0,$.jsx)(Ir,{content:e.content,isStreaming:t&&a===i.length-1},`think-${a}`);if(e.kind===`text`){let r=t&&a===i.length-1;return(0,$.jsx)(`div`,{className:`text-sm text-text-primary select-text`,children:(0,$.jsx)(Lr,{content:e.content,animate:r,projectName:n})},`text-${a}`)}return(0,$.jsx)(f,{tool:e.tool,result:e.result,completed:e.completed,projectName:n,bashPartialOutput:r},`tool-${a}`)})})}function Ir({content:e,isStreaming:t}){let[n,r]=(0,Q.useState)(t),i=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{!t&&e.length>0&&r(!1)},[t,e.length]),(0,Q.useEffect)(()=>{t&&n&&i.current&&(i.current.scrollTop=i.current.scrollHeight)},[e,t,n]),(0,$.jsxs)(`div`,{className:`rounded border border-border/50 bg-surface/30 text-xs`,children:[(0,$.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors text-text-subtle`,children:[t?(0,$.jsx)(w,{className:`size-3 animate-spin`}):(0,$.jsx)(c,{className:`size-3 transition-transform ${n?`rotate-90`:``}`}),(0,$.jsxs)(`span`,{children:[`Thinking`,t?`...`:``]}),!t&&(0,$.jsx)(`span`,{className:`text-text-subtle/50 ml-auto`,children:e.length>100?`${Math.round(e.length/4)} tokens`:``})]}),n&&(0,$.jsx)(`div`,{ref:i,className:`max-h-60 overflow-y-auto`,children:(0,$.jsx)(`div`,{className:`px-2 pb-2 text-text-subtle/80 whitespace-pre-wrap text-[11px] leading-relaxed`,children:e})})]})}function Lr({content:e,animate:t,projectName:n}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Vr,{content:e,projectName:n,isStreaming:t}),t&&(0,$.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function Rr({lastMessage:e,phase:t,elapsed:n,statusMessage:r}){let i=!e||e.role!==`assistant`,a=e?.events?.length?e.events[e.events.length-1].type===`tool_result`:!1;return!r&&!i&&!a?null:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-text-subtle`,children:[(0,$.jsx)(w,{className:`size-3 animate-spin`}),(0,$.jsxs)(`span`,{children:[r||(t===`initializing`?`Initializing`:t===`connecting`?`Connecting`:t===`thinking`?`Thinking`:`Processing`),i&&(n??0)>0&&(0,$.jsxs)(`span`,{className:`text-text-subtle/60`,children:[`... (`,n,`s)`]})]})]}),t===`connecting`&&(n??0)>=30&&(0,$.jsx)(`p`,{className:`text-xs text-warning/80 ml-5`,children:`Taking longer than usual — may be rate-limited or API slow. Try sending a new message to retry.`})]})}var zr=/<teammate-message[^>]*>[\s\S]*?<\/teammate-message>/g;function Br(e){return e.replace(zr,``).replace(/\n{3,}/g,`
6
-
7
- `).trim()}function Vr({content:e,projectName:t,isStreaming:n}){let r=Br(e);return r?(0,$.jsx)(Yn,{fallbackContent:r,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`animate-pulse h-4 bg-muted rounded`}),children:(0,$.jsx)(hr,{content:r,projectName:t,codeActions:!0,isStreaming:n})})}):null}function Hr({approval:e,onRespond:t}){return(0,$.jsxs)(`div`,{className:`rounded-lg border-2 border-warning/40 bg-warning/10 p-3 space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-warning text-sm font-medium`,children:[(0,$.jsx)(ue,{className:`size-4`}),(0,$.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,$.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,$.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,$.jsx)(`pre`,{className:`text-xs font-mono text-text-secondary overflow-x-auto bg-background rounded p-2 border border-border`,children:JSON.stringify(e.input,null,2)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`button`,{onClick:()=>t(e.requestId,!0),className:`px-4 py-1.5 rounded bg-success text-white text-xs font-medium hover:bg-success/80 transition-colors`,children:`Allow`}),(0,$.jsx)(`button`,{onClick:()=>t(e.requestId,!1),className:`px-4 py-1.5 rounded bg-error text-white text-xs font-medium hover:bg-error/80 transition-colors`,children:`Deny`})]})]})}function Ur({approval:e,onRespond:t}){return(0,$.jsx)(ir,{questions:e.input.questions??[],onSubmit:n=>t(e.requestId,!0,n),onSkip:()=>t(e.requestId,!1)})}function Wr({shells:e,onKill:t}){let n=Re(e=>e.openPanel),r=e.filter(e=>e.status!==`stopped`);return r.length===0?null:(0,$.jsx)(`div`,{className:`shrink-0 border-b border-border bg-surface-elevated/60 px-2 py-1.5 space-y-1`,children:r.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[e.status===`stopping`?(0,$.jsx)(w,{className:`size-3.5 shrink-0 animate-spin text-warning`}):(0,$.jsxs)(`span`,{className:`relative flex size-2 shrink-0`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex size-full animate-ping rounded-full bg-emerald-400 opacity-60`}),(0,$.jsx)(`span`,{className:`relative inline-flex size-2 rounded-full bg-emerald-500`})]}),(0,$.jsx)(Ge,{className:`size-3.5 shrink-0 text-text-secondary`}),(0,$.jsx)(`span`,{className:`flex-1 truncate font-mono text-text-primary`,title:e.command,children:e.command}),e.status===`stopping`&&(0,$.jsx)(`span`,{className:`text-[11px] text-warning shrink-0`,children:`stopping…`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>n(e.shellId),className:`flex items-center justify-center size-8 rounded hover:bg-surface text-text-secondary hover:text-text-primary transition-colors`,"aria-label":`View output`,title:`View output`,children:(0,$.jsx)(S,{className:`size-4`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>t(e.shellId),disabled:e.status===`stopping`,className:`flex items-center justify-center size-8 rounded hover:bg-surface text-text-secondary hover:text-error transition-colors disabled:opacity-40`,"aria-label":`Stop command`,title:`Stop command`,children:(0,$.jsx)(q,{className:`size-3.5`})})]},e.shellId))})}function Gr(e){if(!e)return;let t=e.split(`:`).pop();return t&&t!==`general-purpose`?t:e}function Kr(e,t){if(!e)return;let n=new Date(e).getTime(),r=t?new Date(t).getTime():Date.now();if(!Number.isFinite(n)||!Number.isFinite(r)||r<n)return;let i=Math.floor((r-n)/1e3),a=Math.floor(i/3600),o=Math.floor(i%3600/60);return a>0?`${a}h ${o}m`:o>0?`${o}m`:`${i}s`}function qr(e){return e.lastTool?e.lastToolArg?`${e.lastTool}: ${e.lastToolArg}`:e.lastTool:e.lastNarrative??e.description}function Jr({teamName:e,members:t,projectName:n}){let r=Qe(),i=t.filter(e=>e.workState===`working`);return!e||i.length===0?null:(0,$.jsx)(`div`,{className:`shrink-0 border-t border-border bg-surface-elevated/60 px-2 py-1.5 space-y-1`,children:i.map(t=>{let i=qr(t),a=Kr(t.startedAt),o=Gr(t.agentType);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r({teamName:e,memberName:t.name,projectName:n}),className:`flex w-full items-center gap-2 rounded px-1 py-1.5 min-h-[36px] text-left text-xs hover:bg-surface transition-colors`,title:`Open ${t.name}'s work session`,children:[(0,$.jsxs)(`span`,{className:`relative flex size-2 shrink-0`,children:[(0,$.jsx)(`span`,{className:`absolute inline-flex size-full animate-ping rounded-full bg-emerald-400 opacity-60`}),(0,$.jsx)(`span`,{className:`relative inline-flex size-2 rounded-full bg-emerald-500`})]}),(0,$.jsx)(ce,{className:`size-3.5 shrink-0 text-accent-2`}),(0,$.jsx)(`span`,{className:`font-medium text-text-primary shrink-0`,children:t.name}),!!o&&(0,$.jsx)(`span`,{className:`text-text-3 shrink-0 hidden sm:inline`,children:o}),!!i&&(0,$.jsx)(`span`,{className:`flex-1 truncate text-text-subtle`,title:i,children:i}),!!a&&(0,$.jsx)(`span`,{className:`ml-auto shrink-0 text-text-3 font-mono`,children:a})]},t.name)})})}var Yr=5e3;function Xr(e,t){let[n,r]=(0,Q.useState)([]),[i,a]=(0,Q.useState)([]),[o,s]=(0,Q.useState)(!1),c=(0,Q.useRef)(!1),l=(0,Q.useCallback)(async e=>{if(e){s(!0);try{let t=await E.get(`/api/teams/${encodeURIComponent(e)}/activity`);if(c.current)return;r(t?.members??[]),a(t?.outbound??[])}catch{}finally{c.current||s(!1)}}},[]);return(0,Q.useEffect)(()=>{if(c.current=!1,!t||!e)return r([]),a([]),()=>{c.current=!0};l(e);let n=setInterval(()=>void l(e),Yr);return()=>{c.current=!0,clearInterval(n)}},[e,t,l]),{members:n,outbound:i,loading:o,refresh:(0,Q.useCallback)(()=>void l(e),[l,e])}}function Zr(){let e=window;return e.SpeechRecognition??e.webkitSpeechRecognition??null}function Qr(e){let[t,n]=(0,Q.useState)(!1),[r,i]=(0,Q.useState)(``),a=(0,Q.useRef)(null),o=(0,Q.useRef)(``),s=typeof window<`u`&&Zr()!==null;return{isListening:t,interimText:r,start:(0,Q.useCallback)(t=>{let r=Zr();if(!r)return;a.current?.abort();let s=new r;s.lang=e?.lang??`vi-VN`,s.continuous=!0,s.interimResults=!0,o.current=``,s.onresult=e=>{let n=``,r=``;for(let t=0;t<e.results.length;t++){let i=e.results[t];i.isFinal?r+=i[0].transcript:n+=i[0].transcript}r&&(o.current=r);let a=(o.current+` `+n).trim();i(n),t(a,n.length===0&&o.current.length>0)},s.onend=()=>{n(!1),i(``),o.current&&t(o.current.trim(),!0)},s.onerror=e=>{e.error!==`no-speech`&&e.error!==`aborted`&&console.warn(`[voice-input] error:`,e.error),n(!1),i(``)},a.current=s,s.start(),n(!0)},[e?.lang]),stop:(0,Q.useCallback)(()=>{a.current?.stop(),a.current=null,n(!1),i(``)},[]),supported:s}}var $r=2e3;function ei(e,t,n=$r){if(!(e>0)||!(t>0))return null;let r=Math.max(e,t);if(r<n)return null;let i=n-1,a=i/r;return{width:e>=t?i:Math.max(1,Math.round(e*a)),height:t>e?i:Math.max(1,Math.round(t*a))}}var ti=4096;function ni(e,t){let n=new TextEncoder().encode(t);outer:for(let t=0;t+n.length<=e.length;t++){for(let r=0;r<n.length;r++)if(e[t+r]!==n[r])continue outer;return!0}return!1}function ri(e,t){return e===`image/gif`?!0:e===`image/webp`?ni(t,`ANIM`):e===`image/png`||e===`image/apng`?ni(t,`acTL`):!1}async function ii(e){if(e.type===`image/gif`)return!0;if(e.type!==`image/webp`&&e.type!==`image/png`&&e.type!==`image/apng`)return!1;try{let t=new Uint8Array(await e.slice(0,ti).arrayBuffer());return ri(e.type,t)}catch{return!0}}var ai=1600,oi=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]);function si(e){return e===`image/jpeg`||e===`image/webp`?e:`image/png`}async function ci(e,t=ai){let n={kind:`asis`,file:e};if(!e.type.startsWith(`image/`)||e.type===`image/svg+xml`||typeof createImageBitmap!=`function`||typeof document>`u`)return n;let r;try{r=await createImageBitmap(e)}catch{return n}let i={width:r.width,height:r.height},a=ei(i.width,i.height,t+1);if(a&&await ii(e))return r.close?.(),Math.max(i.width,i.height)<2e3&&oi.has(e.type)?{kind:`inlineable`,file:e,from:i}:{kind:`asis`,file:e,from:i};if(!a)return r.close?.(),oi.has(e.type)?{kind:`inlineable`,file:e,from:i}:{kind:`asis`,file:e,from:i};let o=r;try{try{o=await createImageBitmap(e,{resizeWidth:a.width,resizeHeight:a.height,resizeQuality:`high`}),r.close?.()}catch{o=r}let t=document.createElement(`canvas`);t.width=a.width,t.height=a.height;let n=t.getContext(`2d`);if(!n)return{kind:`asis`,file:e,from:i};n.imageSmoothingEnabled=!0,n.imageSmoothingQuality=`high`,n.drawImage(o,0,0,a.width,a.height);let s=si(e.type),c=await new Promise(e=>t.toBlob(e,s,.92));if(!c||c.size===0)return{kind:`asis`,file:e,from:i};let l=s===e.type?e.name:e.name.replace(/\.[^.]+$/,``)+`.png`;return{kind:`scaled`,file:new File([c],l,{type:s}),from:i,to:a}}catch{return{kind:`asis`,file:e,from:i}}finally{o.close?.()}}var li=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]);function ui(e){return li.has(e.type)}function di({attachments:e,onRemove:t}){let[n,r]=(0,Q.useState)(null);if(e.length===0)return null;let i=n?e.find(e=>e.id===n):null;return(0,$.jsxs)(`div`,{className:`px-2 md:px-4 pt-2`,children:[(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,$.jsxs)(`div`,{className:k(`flex items-center gap-1.5 rounded-md border border-border bg-surface px-2 py-1 text-xs text-text-secondary max-w-48`,e.textContent&&`cursor-pointer hover:border-primary/50`,n===e.id&&`border-primary/50 bg-surface-elevated`),onClick:()=>{e.textContent&&r(n===e.id?null:e.id)},children:[e.previewUrl?(0,$.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.textContent?(0,$.jsx)(Ge,{className:`size-3.5 shrink-0 text-text-subtle`}):e.isImage?(0,$.jsx)(Le,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,$.jsx)(De,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name}),e.textContent&&(0,$.jsx)(s,{className:k(`size-3 shrink-0 text-text-subtle transition-transform`,n===e.id&&`rotate-180`)}),e.status===`uploading`?(0,$.jsx)(w,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,$.jsx)(`span`,{className:`text-error shrink-0`,title:`Upload failed`,children:`!`}):e.resized?(0,$.jsxs)(`span`,{className:`shrink-0 text-[10px] text-text-subtle`,title:`Shrunk from ${e.resized.from.width}x${e.resized.from.height} to ${e.resized.to.width}x${e.resized.to.height}`,children:[e.resized.to.width,`×`,e.resized.to.height]}):null,(0,$.jsx)(`button`,{type:`button`,onClick:i=>{i.stopPropagation(),t(e.id),n===e.id&&r(null)},className:`shrink-0 rounded-sm p-0.5 hover:bg-border/50 transition-colors`,"aria-label":`Remove ${e.name}`,children:(0,$.jsx)(te,{className:`size-3`})})]},e.id))}),i?.textContent&&(0,$.jsx)(`pre`,{className:`mt-1.5 max-h-40 overflow-auto rounded-md border border-border bg-background p-2 text-xs text-text-primary font-mono whitespace-pre-wrap break-words`,children:fi(i.textContent)})]})}function fi(e){let t=e.trim(),n=t.match(/^```\w*\n([\s\S]*?)\n```$/);return n?n[1]:t}function pi(e,t,n){if(e.length===0)return null;let r=t+n;return r<-1||r>=e.length?null:{index:r,text:r===-1?``:e[e.length-1-r]}}var mi=[{id:`default`,label:`Ask before edits`,icon:C,description:`Claude will ask for approval before making each edit`},{id:`acceptEdits`,label:`Edit automatically`,icon:_,description:`Claude will edit files without asking first`},{id:`plan`,label:`Plan mode`,icon:u,description:`Claude will present a plan before editing`},{id:`bypassPermissions`,label:`Bypass permissions`,icon:ee,description:`Claude will not ask before running commands`}];function hi(e){return mi.find(t=>t.id===e)?.label??`Unknown`}function gi(e){return mi.find(t=>t.id===e)?.icon??C}function _i({value:e,onChange:t,open:n,onOpenChange:r}){let i=(0,Q.useRef)(null),a=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{if(!n)return;let e=e=>{i.current&&!i.current.contains(e.target)&&r(!1)},t=i.current?.ownerDocument??document;return t.addEventListener(`mousedown`,e),()=>t.removeEventListener(`mousedown`,e)},[n,r]),(0,Q.useEffect)(()=>{n&&(a.current=mi.findIndex(t=>t.id===e),a.current<0&&(a.current=0))},[n,e]);let s=(0,Q.useCallback)(e=>{if(e.key===`Escape`){r(!1);return}if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=e.key===`ArrowDown`?1:-1;a.current=(a.current+t+mi.length)%mi.length,(i.current?.querySelector(`[data-idx="${a.current}"]`))?.focus()}if(e.key===`Enter`){e.preventDefault();let n=mi[a.current];n&&(t(n.id),r(!1))}},[t,r]);return n?(0,$.jsxs)(`div`,{ref:i,role:`listbox`,"aria-label":`Permission modes`,onKeyDown:s,onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),className:`absolute bottom-full left-0 mb-1 z-50 w-72 md:w-80 rounded-lg border border-border popover-solid shadow-[var(--shadow-panel)]`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-text-secondary`,children:`Modes`}),(0,$.jsx)(`kbd`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-text-subtle border border-border`,children:`Shift + Tab`})]}),(0,$.jsx)(`div`,{className:`py-1`,children:mi.map((n,i)=>{let a=n.icon,s=n.id===e;return(0,$.jsxs)(`button`,{"data-idx":i,role:`option`,"aria-selected":s,tabIndex:0,onClick:()=>{t(n.id),r(!1)},className:`w-full flex items-start gap-3 px-3 py-2.5 text-left transition-colors hover:bg-surface-elevated focus:bg-surface-elevated focus:outline-none ${s?`bg-surface-elevated`:``}`,children:[(0,$.jsx)(a,{className:`size-4 mt-0.5 shrink-0 text-text-secondary`}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-text-primary`,children:n.label}),(0,$.jsx)(`div`,{className:`text-xs text-text-subtle leading-snug`,children:n.description})]}),s&&(0,$.jsx)(o,{className:`size-4 mt-0.5 shrink-0 text-primary`})]},n.id)})})]}):null}var vi=[{label:`Low`,value:`low`},{label:`Medium`,value:`medium`},{label:`High`,value:`high`,default:!0},{label:`Extra`,value:`xhigh`},{label:`Max`,value:`max`}];function yi(e){return e?vi.find(t=>t.value===e)?.label??e:``}function bi(e,t){let n=yi(t);return n?`${e} · ${n}`:e}function xi(e){return e.replace(/^Claude\s+/i,``)}var Si=vi.find(e=>e.default).value;function Ci({model:e,effort:t,thinking:n,onModelChange:r,onEffortChange:i,onThinkingChange:s,projectName:c,providerId:l,disabled:u}){let[d,f]=(0,Q.useState)([]),[p,m]=(0,Q.useState)(!1),h=(0,Q.useRef)(null),g=se();(0,Q.useEffect)(()=>{!c||!l||E.get(`${T(c)}/chat/providers/${l}/models`).then(f).catch(()=>{})},[c,l]),(0,Q.useEffect)(()=>{u&&m(!1)},[u]),(0,Q.useEffect)(()=>{if(!p||g)return;let e=e=>{h.current&&!h.current.contains(e.target)&&m(!1)},t=h.current?.ownerDocument??document;return t.addEventListener(`mousedown`,e),()=>t.removeEventListener(`mousedown`,e)},[p,g]);let _=d.find(t=>t.value===e),y=_?xi(_.label):e?xi(e):`Model`,b=t??Si,x=d.length>1,S=bi(y,b),C=e=>{e(),g||m(!1)},w=(0,$.jsxs)(`div`,{className:`flex divide-x divide-border`,children:[x&&(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 py-1`,children:[(0,$.jsx)(wi,{children:`Model`}),d.map(t=>(0,$.jsxs)(Ei,{active:t.value===e,onClick:()=>C(()=>r(t.value)),children:[(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:xi(t.label)}),t.value===e&&(0,$.jsx)(o,{className:`size-4 shrink-0 text-primary`})]},t.value))]}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 py-1`,children:[(0,$.jsx)(wi,{children:`Effort`}),vi.map(e=>(0,$.jsxs)(Ei,{active:e.value===b,onClick:()=>C(()=>i(e.value)),children:[(0,$.jsxs)(`span`,{className:`flex-1 truncate`,children:[e.label,e.default&&(0,$.jsx)(`span`,{className:`ml-2 text-xs text-text-subtle`,children:`Default`})]}),e.value===b&&(0,$.jsx)(o,{className:`size-4 shrink-0 text-primary`})]},e.value)),(0,$.jsx)(Ti,{}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>s(!n),className:`w-full flex items-center gap-3 px-3 min-h-[44px] text-left text-sm hover:bg-surface-elevated`,role:`switch`,"aria-checked":n,children:[(0,$.jsx)(a,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:`Thinking`}),(0,$.jsx)(`span`,{className:`inline-flex h-5 w-9 items-center rounded-full transition-colors ${n?`bg-primary`:`bg-border`}`,children:(0,$.jsx)(`span`,{className:`h-4 w-4 rounded-full bg-white transition-transform ${n?`translate-x-4`:`translate-x-0.5`}`})})]})]})]});return(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsxs)(`button`,{type:`button`,disabled:u,onClick:e=>{e.stopPropagation(),u||m(e=>!e)},className:`inline-flex items-center gap-1.5 px-[9px] py-1 rounded-full text-[11.5px] text-primary bg-accent-wash border border-accent-wash-border hover:brightness-110 transition-[filter] disabled:opacity-50 disabled:cursor-default`,"aria-label":`Model ${y}, effort ${b}${n?`, thinking on`:``}`,title:u?`Can't change while running`:S,children:[(0,$.jsx)(v,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`max-w-[140px] truncate`,children:S}),n&&(0,$.jsx)(a,{className:`h-3 w-3 shrink-0`})]}),p&&!u&&(g?(0,$.jsx)(N,{open:p,onClose:()=>m(!1),children:(0,$.jsx)(`div`,{className:`px-1 pb-2`,children:w})}):(0,$.jsx)(`div`,{ref:h,role:`listbox`,"aria-label":`Model and thinking`,onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),className:`absolute bottom-full left-0 mb-1 z-50 w-80 rounded-lg border border-border popover-solid shadow-[var(--shadow-panel)] max-h-[70vh] overflow-y-auto`,children:w}))]})}function wi({children:e}){return(0,$.jsx)(`div`,{className:`px-3 py-1.5 text-xs font-medium text-text-secondary`,children:e})}function Ti(){return(0,$.jsx)(`div`,{className:`my-1 border-t border-border`})}function Ei({active:e,onClick:t,children:n}){return(0,$.jsx)(`button`,{type:`button`,onClick:t,className:`w-full flex items-center gap-3 px-3 min-h-[44px] text-left text-sm text-text-primary transition-colors hover:bg-surface-elevated ${e?`bg-surface-elevated`:``}`,children:n})}var Di=new Map;function Oi(e,t,n){let r=`${e}\0${t??``}\0${n??``}`,i=Di.get(r);if(i)return i;let a=new URLSearchParams;t&&a.set(`providerId`,t),n&&a.set(`sessionId`,n);let o=a.size>0?`?${a}`:``,s=E.get(`${T(e)}/chat/slash-items${o}`).then(e=>({items:e.items??[],recentNames:e.recentNames??[]})).catch(e=>{throw Di.delete(r),e});return Di.set(r,s),s}function ki(e){if(!e){Di.clear();return}let t=`${e}\0`;for(let e of Di.keys())e.startsWith(t)&&Di.delete(e)}async function Ai(e){try{let t=await new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result??``)),r.onerror=()=>n(r.error),r.readAsDataURL(e)}),n=t.indexOf(`,`),r=n>=0?t.slice(n+1):``;return r?{data:r,mediaType:e.type||`image/png`}:void 0}catch{return}}var ji=(0,Q.memo)(function({tabId:e,onSend:t,isStreaming:n,onCancel:r,disabled:a,projectName:o,onSlashStateChange:s,onSlashItemsLoaded:c,slashSelected:l,onFileStateChange:u,onFileItemsLoaded:d,fileSelected:f,externalFiles:p,externalPaths:m,onExternalPathsConsumed:h,initialValue:g,clearSignal:_,onContentChange:v,getUserHistory:y,autoFocus:b,permissionMode:x,onModeChange:S,providerId:C,sessionId:ee,onProviderChange:E,model:ne,onModelChange:re,effort:O,onEffortChange:k,thinking:ie,onThinkingChange:ae}){let j=(0,Q.useRef)(g??``),[oe,se]=(0,Q.useState)(()=>(g??``).trim().length>0),[M,N]=(0,Q.useState)([]),[P,ce]=(0,Q.useState)(null),[le,ue]=(0,Q.useState)(!1),[F,I]=(0,Q.useState)(!1),[de,fe]=(0,Q.useState)(`next`),L=(0,Q.useRef)(null),R=(0,Q.useRef)(null),z=(0,Q.useRef)(null),B=(0,Q.useRef)([]),pe=(0,Q.useRef)([]),V=(0,Q.useRef)(0),H=(0,Q.useRef)(!1),me=(0,Q.useRef)(!1),he=(0,Q.useRef)(typeof CSS>`u`||!CSS.supports(`field-sizing`,`content`)),U=(0,Q.useCallback)(e=>{j.current=e,L.current&&(L.current.value=e),R.current&&(R.current.value=e),se(e.trim().length>0)},[]),W=(0,Q.useCallback)(()=>window.matchMedia(`(min-width: 768px)`).matches?L.current:R.current,[]),G=(0,Q.useRef)(-1),_e=(0,Q.useCallback)(e=>{let t=pi(y?.()??[],G.current,e);if(!t)return!1;G.current=t.index;let{agent:n,text:r}=pr(t.text);ce(n),U(r);let i=W();return i?(i.focus(),requestAnimationFrame(()=>{i.selectionStart=i.selectionEnd=r.length}),he.current&&(i.style.height=`auto`,i.style.height=Math.min(i.scrollHeight,i===R.current?80:160)+`px`),!0):!0},[y,U,W]),K=Qr(),ve=(0,Q.useRef)(``),be=(0,Q.useCallback)(e=>{let t=ve.current;U(t?t+` `+e:e),he.current&&requestAnimationFrame(()=>{let e=W();e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,160)+`px`)})},[U,W]),J=(0,Q.useCallback)(()=>{K.isListening?K.stop():(ve.current=j.current.trim(),K.start(be))},[K.isListening,K.start,K.stop,be]);(0,Q.useEffect)(()=>{let e=()=>{K.supported&&mn(W())&&J()};return window.addEventListener(`toggle-voice-input`,e),()=>window.removeEventListener(`toggle-voice-input`,e)},[K.supported,J,W]),(0,Q.useEffect)(()=>{let t=t=>{let{text:n,label:r,targetTabId:i}=t.detail??{};if(!n||(i?i!==e:!mn(W())))return;window.dispatchEvent(new Event(et));let a={id:A(),name:r??`Terminal output`,file:new File([],`terminal-output.txt`),isImage:!1,textContent:n,status:`ready`};N(e=>[...e,a]),W()?.focus()};return window.addEventListener($e,t),()=>window.removeEventListener($e,t)},[W,e]),(0,Q.useEffect)(()=>{g&&!j.current&&(U(g),setTimeout(()=>{let e=L.current;e&&(e.focus(),e.selectionStart=e.selectionEnd=e.value.length)},50))},[g]),(0,Q.useEffect)(()=>{_&&U(``)},[_]),(0,Q.useEffect)(()=>{b&&setTimeout(()=>{W()?.focus()},100)},[]);let xe=(0,Q.useCallback)(()=>{if(!o){B.current=[],c?.([],[]);return}Oi(o,C,ee).then(e=>{B.current=e.items,c?.(e.items,e.recentNames)}).catch(()=>{B.current=[],c?.([],[])})},[o,C,ee,c]);(0,Q.useEffect)(()=>{xe()},[xe]),(0,Q.useEffect)(()=>{let e=()=>{ki(o),xe()};return window.addEventListener(`ppm:slash-items-refresh`,e),()=>window.removeEventListener(`ppm:slash-items-refresh`,e)},[xe,o]),(0,Q.useEffect)(()=>{let e=()=>{if(!o){pe.current=[],d?.([]);return}let{fileIndex:e}=Ae.getState(),t=e.map(e=>({name:e.name,path:e.path,type:e.type}));pe.current=t,d?.(t)};e();let t=Ae.getState().fileIndex,n=Ae.getState().indexStatus;return Ae.subscribe(r=>{(r.fileIndex!==t||r.indexStatus!==n)&&(t=r.fileIndex,n=r.indexStatus,e())})},[o]),(0,Q.useEffect)(()=>{if(!l)return;let e=W();if(!e)return;let t=e.value,n=e.selectionStart,r=t.slice(0,n),i=t.slice(n),a=e=>e.startsWith(`/`)?``:e[0];if(l.type===`agent`){let t=r.replace(/(?:^|\s)\/\S*$/,a);ce(l.name),U(t+i),s?.(!1,``),H.current=!1,e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length},0);return}let o=r.replace(/(?:^|\s)\/\S*$/,e=>`${a(e)}${l.invokeSigil??`/`}${l.name} `);U(o+i),s?.(!1,``),H.current=!1,u?.(!1,``),me.current=!1,e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=o.length},0)},[l]),(0,Q.useEffect)(()=>{if(!f)return;let e=W();if(!e)return;let t=e.value,n=e.selectionStart,r=t.slice(0,n),i=t.slice(n),a=r.match(/@(\S*)$/);if(a){let t=r.length-a[0].length;U(r.slice(0,t)+`@${f.path} `+i);let n=t+f.path.length+2;setTimeout(()=>{e.selectionStart=e.selectionEnd=n,e.focus()},0)}else{let n=t+`@${f.path} `;U(n),setTimeout(()=>{e.selectionStart=e.selectionEnd=n.length,e.focus()},0)}u?.(!1,``),me.current=!1},[f]),(0,Q.useEffect)(()=>{!p||p.length===0||we(p)},[p]),(0,Q.useEffect)(()=>{if(!m||m.length===0)return;let e=m.map(e=>`@${e}`).join(` `),t=j.current;U(t+(t.length>0&&!t.endsWith(` `)?` `:``)+e+` `),W()?.focus(),h?.()},[m]);let Se=(0,Q.useCallback)(async e=>{if(!o)return;let t=e.split(/[\\/]/).pop();if(t)try{let e={},n=D();n&&(e.Authorization=`Bearer ${n}`),await fetch(`${T(o)}/chat/uploads/${encodeURIComponent(t)}`,{method:`DELETE`,headers:e})}catch{}},[o]),Ce=(0,Q.useCallback)(async e=>{if(!o)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=D();r&&(n.Authorization=`Bearer ${r}`);let i=await(await fetch(`${T(o)}/chat/upload`,{method:`POST`,headers:n,body:t})).json();return i.ok&&Array.isArray(i.data)&&i.data.length>0?i.data[0].path:null}catch{return null}},[o]),we=(0,Q.useCallback)(async e=>{for(let t of e){let e=A(),n=ui(t),r={id:e,name:t.name,file:t,isImage:n,previewUrl:n?URL.createObjectURL(t):void 0,status:`uploading`};N(e=>[...e,r]);try{let i=n?await ci(t):null,a=i?.file??t,o=n&&a!==t?URL.createObjectURL(a):void 0,s=await Ce(a),c=i&&i.kind!==`asis`?await Ai(a):void 0,l=!!c&&c.data.length<=mt.maxBase64PerImage;o&&r.previewUrl&&URL.revokeObjectURL(r.previewUrl),N(t=>t.map(t=>t.id===e?{...t,file:a,...o&&{previewUrl:o},serverPath:s??void 0,imageData:l?c:void 0,resized:i?.to?{from:i.from,to:i.to}:void 0,status:s||l?`ready`:`error`}:t))}catch{N(t=>t.map(t=>t.id===e?{...t,status:`error`}:t))}}(R.current??L.current)?.focus()},[Ce]),Te=(0,Q.useCallback)(e=>{N(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),n?.serverPath&&Se(n.serverPath),t.filter(t=>t.id!==e)})},[Se]),Ee=(0,Q.useCallback)(()=>{let e=j.current.trim(),r=M.filter(e=>e.status===`ready`);if(!e&&r.length===0&&!P){I(!1);return}let i=P?`Use the ${P} agent to ${e}`.trimEnd():e;s?.(!1,``),H.current=!1,u?.(!1,``),me.current=!1,K.isListening&&K.stop(),t(i,r,n?de:void 0),U(``);for(let e of M)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);N([]),ce(null),I(!1),fe(`next`),G.current=-1,he.current&&(L.current&&(L.current.style.height=`auto`),R.current&&(R.current.style.height=`auto`))},[M,P,t,s,u,n,de,U]),Y=(0,Q.useCallback)(()=>{if(!a){if(M.some(e=>e.status===`uploading`)){(j.current.trim()||M.some(e=>e.status!==`error`))&&I(!0);return}Ee()}},[M,a,Ee]);(0,Q.useEffect)(()=>{F&&(M.some(e=>e.status===`uploading`)||Ee())},[F,M,Ee]);let De=(0,Q.useCallback)(e=>{if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),Y();return}if((e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){if(!(G.current>=0)&&(e.key===`ArrowDown`||j.current!==``||P))return;_e(e.key===`ArrowUp`?1:-1)&&e.preventDefault();return}if(e.shiftKey&&e.key===`Tab`){e.preventDefault();let t=[`default`,`acceptEdits`,`plan`,`bypassPermissions`],n=t[(t.indexOf(x??`bypassPermissions`)+1)%t.length];S?.(n)}},[Y,x,S,_e,P]),Oe=(0,Q.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.includes(`/`),i=n.includes(`@`);if(!r&&!i){H.current&&=(s?.(!1,``),!1),me.current&&=(u?.(!1,``),!1);return}if(r){let e=n.match(/(?:^|\s)\/(\S*)$/);if(e&&B.current.length>0){let t=e[1]??``;s?.(!0,t),H.current=!0,me.current&&=(u?.(!1,``),!1);return}}if(i){let e=n.match(/@(\S*)$/);if(e&&pe.current.length>0){u?.(!0,e[1]??``),me.current=!0,H.current&&=(s?.(!1,``),!1);return}}H.current&&=(s?.(!1,``),!1),me.current&&=(u?.(!1,``),!1)},[s,u]),ke=(0,Q.useCallback)(e=>{let t=e.target,n=t.value;j.current=n,G.current=-1;let r=t===L.current?R.current:L.current;r&&(r.value=n),se(n.trim().length>0),Oe(n,t.selectionStart),v?.(n,M.filter(e=>e.status===`ready`&&e.serverPath).map(e=>({name:e.name,path:e.serverPath}))),he.current&&(V.current&&cancelAnimationFrame(V.current),V.current=requestAnimationFrame(()=>{V.current=0,t.style.height=`auto`,t.style.height=Math.min(t.scrollHeight,t===R.current?80:160)+`px`}))},[Oe,v,M]),je=(0,Q.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t)if(e.kind===`file`){let t=e.getAsFile();t&&n.push(t)}n.length>0&&(e.preventDefault(),we(n))},[we]),Me=(0,Q.useCallback)(e=>{e.preventDefault();let t=e.dataTransfer.getData(`application/x-ppm-path`);if(t){let e=j.current;U(e+(e.length>0&&!e.endsWith(` `)?` `:``)+`@${t} `),W()?.focus();return}let n=Array.from(e.dataTransfer.files);n.length>0&&we(n)},[we,U,W]),X=(0,Q.useCallback)(e=>{e.preventDefault()},[]),Ne=(0,Q.useCallback)(()=>{z.current?.click()},[]),Pe=(0,Q.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&we(t),e.target.value=``},[we]),Fe=oe||M.some(e=>e.status!==`error`)||!!P,Ie=n&&!Fe;return(0,$.jsxs)(`div`,{className:`p-2 md:p-3`,children:[(0,$.jsxs)(`div`,{className:`border border-border rounded-[var(--rad)] bg-panel shadow-[var(--shadow-float)] cursor-text`,onClick:e=>{a||e.target instanceof HTMLTextAreaElement||W()?.focus()},children:[P&&(0,$.jsx)(`div`,{className:`px-2 md:px-4 pt-2`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-md border border-sky-500/30 bg-sky-500/10 px-2 py-1 text-xs font-medium text-sky-600 dark:text-sky-400`,children:[(0,$.jsx)(i,{className:`size-3.5 shrink-0`}),P,(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ce(null),W()?.focus()},className:`shrink-0 rounded-sm p-0.5 hover:bg-sky-500/20 transition-colors`,"aria-label":`Remove ${P} agent`,children:(0,$.jsx)(te,{className:`size-3`})})]})}),(0,$.jsx)(di,{attachments:M,onRemove:Te}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-2 pt-2 md:hidden relative`,children:[(0,$.jsx)(Mi,{mode:x??`bypassPermissions`,onClick:()=>ue(e=>!e)}),(0,$.jsx)(_i,{value:x??`bypassPermissions`,onChange:e=>S?.(e),open:le,onOpenChange:ue}),E&&o&&(0,$.jsx)(ge,{value:C??`claude`,onChange:E,projectName:o}),re&&o&&(0,$.jsx)(Ci,{model:ne??null,effort:O??null,thinking:ie??!1,onModelChange:re,onEffortChange:k??(()=>{}),onThinkingChange:ae??(()=>{}),projectName:o,providerId:C??`claude`,disabled:n}),n&&(0,$.jsx)(Pi,{value:de,onChange:fe})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-1 md:hidden px-2 py-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),Ne()},disabled:a,className:`flex items-center justify-center size-8 shrink-0 rounded-[10px] text-text-3 hover:text-text-primary transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,$.jsx)(ft,{className:`size-4`})}),(0,$.jsx)(`textarea`,{ref:R,defaultValue:g??``,onChange:ke,onKeyDown:De,onPaste:je,onDrop:Me,onDragOver:X,placeholder:n?`Follow-up...`:`Ask anything...`,disabled:a,rows:1,className:`flex-1 resize-none bg-transparent py-1.5 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-20 [field-sizing:content]`}),K.supported&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),J()},disabled:a,className:`flex items-center justify-center size-8 shrink-0 rounded-[10px] transition-colors disabled:opacity-50 ${K.isListening?`bg-error text-white animate-pulse`:`text-text-3 hover:text-text-primary`}`,"aria-label":K.isListening?`Stop voice input`:`Start voice input`,children:K.isListening?(0,$.jsx)(dt,{className:`size-4`}):(0,$.jsx)(Be,{className:`size-4`})}),Ie?(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),r?.()},className:`flex items-center justify-center size-9 shrink-0 rounded-[11px] bg-error text-white hover:bg-error/80 shadow-[var(--shadow-float)] transition-colors`,"aria-label":`Stop`,children:(0,$.jsx)(q,{className:`size-3.5`})}):(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),F?I(!1):Y()},disabled:a||!Fe,className:`flex items-center justify-center size-9 shrink-0 rounded-[11px] bg-primary text-primary-foreground hover:bg-primary/90 shadow-[var(--shadow-float)] disabled:opacity-30 disabled:shadow-none transition-colors`,"aria-label":F?`Cancel queued send`:`Send`,children:F?(0,$.jsx)(w,{className:`size-4 animate-spin`}):(0,$.jsx)(ye,{className:`size-4`})})]}),(0,$.jsxs)(`div`,{className:`hidden md:block`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2.5 pt-2.5`,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Mi,{mode:x??`bypassPermissions`,onClick:()=>ue(e=>!e)}),(0,$.jsx)(_i,{value:x??`bypassPermissions`,onChange:e=>S?.(e),open:le,onOpenChange:ue})]}),E&&o&&(0,$.jsx)(ge,{value:C??`claude`,onChange:E,projectName:o}),re&&o&&(0,$.jsx)(Ci,{model:ne??null,effort:O??null,thinking:ie??!1,onModelChange:re,onEffortChange:k??(()=>{}),onThinkingChange:ae??(()=>{}),projectName:o,providerId:C??`claude`,disabled:n}),n&&(0,$.jsx)(Pi,{value:de,onChange:fe})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2 px-2.5 py-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),Ne()},disabled:a,className:`flex items-center justify-center size-[34px] shrink-0 rounded-[10px] text-text-3 hover:text-text-primary hover:bg-surface-elevated transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,$.jsx)(ft,{className:`size-[17px]`})}),(0,$.jsx)(`textarea`,{ref:L,defaultValue:g??``,onChange:ke,onKeyDown:De,onPaste:je,onDrop:Me,onDragOver:X,placeholder:n?`Follow-up or Stop...`:`Ask anything...`,disabled:a,rows:1,className:`flex-1 resize-none bg-transparent py-2 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-[90px] leading-relaxed [field-sizing:content]`}),K.supported&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),J()},disabled:a,className:`flex items-center justify-center size-[34px] shrink-0 rounded-[10px] transition-colors disabled:opacity-50 ${K.isListening?`bg-error text-white animate-pulse`:`text-text-3 hover:text-text-primary hover:bg-surface-elevated`}`,"aria-label":K.isListening?`Stop voice input`:`Start voice input`,children:K.isListening?(0,$.jsx)(dt,{className:`size-[17px]`}):(0,$.jsx)(Be,{className:`size-[17px]`})}),Ie?(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),r?.()},className:`flex items-center justify-center size-9 shrink-0 rounded-[11px] bg-error text-white hover:bg-error/80 shadow-[var(--shadow-float)] transition-colors`,"aria-label":`Stop response`,children:(0,$.jsx)(q,{className:`size-4`})}):(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),F?I(!1):Y()},disabled:a||!Fe,className:`flex items-center justify-center size-9 shrink-0 rounded-[11px] bg-primary text-primary-foreground hover:bg-primary/90 shadow-[var(--shadow-float)] disabled:opacity-30 disabled:cursor-not-allowed disabled:shadow-none transition-colors`,"aria-label":F?`Cancel queued send`:`Send message`,children:F?(0,$.jsx)(w,{className:`size-4 animate-spin`}):(0,$.jsx)(ye,{className:`size-[17px]`})})]})]})]}),(0,$.jsx)(`input`,{ref:z,type:`file`,multiple:!0,className:`hidden`,onChange:Pe})]})});function Mi({mode:e,onClick:t}){let n=gi(e),r=hi(e);return(0,$.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),t()},className:`inline-flex items-center gap-1.5 px-[9px] py-1 rounded-full text-[11.5px] text-text-2 bg-panel-2 border border-border-soft hover:text-text-primary hover:border-border transition-colors`,"aria-label":`Permission mode: ${r}`,children:[(0,$.jsx)(n,{className:`size-3`}),(0,$.jsx)(`span`,{className:`max-w-[100px] truncate`,children:r})]})}var Ni=[{value:`now`,label:`Interrupt`,Icon:_e},{value:`next`,label:`Queue`,Icon:ut},{value:`later`,label:`Later`,Icon:g}];function Pi({value:e,onChange:t}){let n=(0,Q.useCallback)(()=>{let n=[`next`,`later`,`now`];t(n[(n.indexOf(e)+1)%n.length])},[e,t]),r=Ni.find(t=>t.value===e)??Ni[1],i=r.Icon;return(0,$.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),n()},className:`inline-flex items-center gap-1.5 px-[9px] py-1 rounded-full text-[11.5px] text-text-2 bg-panel-2 border border-border-soft hover:text-text-primary hover:border-border transition-colors`,"aria-label":`Message priority: ${r.label}`,title:`Priority: ${r.label} (click to cycle)`,children:[(0,$.jsx)(i,{className:`size-3`}),(0,$.jsx)(`span`,{children:r.label})]})}function Fi(e,t){if(e===t)return 0;if(e.length===0)return t.length;if(t.length===0)return e.length;let n=Array.from({length:t.length+1},(e,t)=>t),r=Array(t.length+1);for(let i=1;i<=e.length;i++){r[0]=i;for(let a=1;a<=t.length;a++){let o=e[i-1]===t[a-1]?0:1;r[a]=Math.min(r[a-1]+1,n[a]+1,n[a-1]+o)}[n,r]=[r,n]}return n[t.length]}function Ii(e,t){let n=e.toLowerCase(),r=t.toLowerCase();if(r.startsWith(n))return{rank:0,distance:0};if(r.includes(n))return{rank:1,distance:r.indexOf(n)};let i=Math.max(Math.floor(n.length*.4),2),a=Fi(n,r.slice(0,n.length+i));return a<=i?{rank:2,distance:a}:null}var Li=1;function Ri(e,t,n=20,r=[]){if(!t)return e;t=t.slice(0,50);let i=new Map(r.map((e,t)=>[e,t])),a=[];for(let n of e){let e=Ii(t,n.name),o=[e,Ii(t,n.description)].filter(e=>e!==null).sort((e,t)=>e.rank-t.rank||e.distance-t.distance)[0];if(o){let t=i.get(n.name),s=t!==void 0&&e?.rank===o.rank;a.push({item:n,rank:o.rank-(s?Li:0),distance:o.distance,recency:t??r.length})}}return a.sort((e,t)=>e.rank-t.rank||e.recency-t.recency||e.distance-t.distance||e.item.name.localeCompare(t.item.name)),a.slice(0,n).map(e=>e.item)}function zi({items:e,filter:t,onSelect:n,onClose:r,visible:a,recentNames:o=[],projectName:s}){let[c,l]=(0,Q.useState)(0),[u,d]=(0,Q.useState)(!1),f=(0,Q.useRef)(null),p=(0,Q.useMemo)(()=>new Set(o),[o]),m=(0,Q.useMemo)(()=>{if(t)return{items:Ri(e,t,20,o),recentCount:0};if(o.length>0){let t=[],n=[];for(let r of e)p.has(r.name)?t.push(r):n.push(r);return t.sort((e,t)=>o.indexOf(e.name)-o.indexOf(t.name)),{items:[...t,...n],recentCount:t.length}}return{items:e,recentCount:0}},[e,t,o,p]),h=m.items,_=m.recentCount;(0,Q.useEffect)(()=>{l(0)},[t]),(0,Q.useEffect)(()=>{let e=f.current;e&&e.children[c]?.scrollIntoView({block:`nearest`})},[c]);let y=(0,Q.useCallback)(e=>{if(!a||h.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),l(e=>e>0?e-1:h.length-1),!0;case`ArrowDown`:return e.preventDefault(),l(e=>e<h.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),h[c]&&n(h[c]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[a,h,c,n,r]);(0,Q.useEffect)(()=>{if(!a)return;let e=e=>{y(e)&&e.stopPropagation()},t=f.current?.ownerDocument??document;return t.addEventListener(`keydown`,e,!0),()=>t.removeEventListener(`keydown`,e,!0)},[a,y]);let b=(0,Q.useCallback)(()=>{!s||u||(d(!0),E.del(`${T(s)}/chat/slash-items/cache`).then(()=>{window.dispatchEvent(new CustomEvent(`ppm:slash-items-refresh`))}).finally(()=>d(!1)))},[s,u]);return!a||h.length===0?null:(0,$.jsx)(`div`,{className:`max-h-52 overflow-y-auto overflow-x-hidden border-b border-border bg-surface`,children:(0,$.jsx)(`div`,{ref:f,className:`py-1`,children:h.map((e,t)=>{let r=_>0&&t===0,a=_>0&&t===_;return(0,$.jsxs)(`div`,{children:[r&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 pt-1 pb-0.5`,children:[(0,$.jsxs)(`span`,{className:`text-[10px] font-medium text-text-subtle uppercase tracking-wider flex items-center gap-1`,children:[(0,$.jsx)(g,{className:`size-3`}),`Recent`]}),s&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),b()},className:`text-text-subtle hover:text-text-primary transition-colors p-0.5 rounded`,title:`Refresh skill list`,"aria-label":`Refresh skill list`,children:(0,$.jsx)(V,{className:`size-3 ${u?`animate-spin`:``}`})})]}),a&&(0,$.jsx)(`div`,{className:`px-3 pt-1.5 pb-0.5`,children:(0,$.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle uppercase tracking-wider`,children:`All`})}),(0,$.jsxs)(`button`,{className:`flex items-start gap-3 w-full px-3 py-2 text-left transition-colors ${t===c?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>l(t),onClick:()=>n(e),children:[(0,$.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.iconDataUri?(0,$.jsx)(`img`,{src:e.iconDataUri,alt:``,className:`size-4 object-contain`}):e.type===`builtin`?(0,$.jsx)(_e,{className:`size-4 text-emerald-500`}):e.type===`skill`?(0,$.jsx)(v,{className:`size-4 text-warning`}):e.type===`agent`?(0,$.jsx)(i,{className:`size-4 text-sky-500`}):(0,$.jsx)(fe,{className:`size-4 text-primary`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[(0,$.jsxs)(`span`,{className:`font-medium text-sm truncate`,children:[e.invokeSigil??`/`,e.name]}),e.displayName&&e.displayName!==e.name&&(0,$.jsx)(`span`,{className:`text-xs text-text-2 truncate`,children:e.displayName}),e.argumentHint&&(0,$.jsx)(`span`,{className:`text-xs text-text-subtle truncate`,children:e.argumentHint}),(0,$.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto shrink-0 whitespace-nowrap`,children:e.invokeSigil===`$`?`Codex`:e.scope===`bundled`?`PPM`:e.scope===`user`?`global`:e.type})]}),e.description&&(0,$.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2 break-words`,children:e.description})]})]})]},`${e.type}-${e.name}`)})})})}function Bi({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,Q.useState)(0),s=(0,Q.useRef)(null),c=(()=>{if(!t)return e.slice(0,50);let n=t.toLowerCase();return e.filter(e=>e.path.toLowerCase().includes(n)||e.name.toLowerCase().includes(n)).slice(0,50)})();(0,Q.useEffect)(()=>{o(0)},[t]),(0,Q.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,Q.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,Q.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()},t=s.current?.ownerDocument??document;return t.addEventListener(`keydown`,e,!0),()=>t.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,$.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,$.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,$.jsxs)(`button`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,$.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,$.jsx)(Ie,{className:`size-4 text-warning`}):(0,$.jsx)(je,{className:`size-4 text-primary`})}),(0,$.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}var Vi=e=>`${(e/1048576).toFixed(2)} MB`;function Hi(e){return e>=1048576?`${(e/1048576).toFixed(1)} MB`:`${Math.max(1,Math.round(e/1024))} KB`}function Ui(){let e=null;for(let t of document.querySelectorAll(`.overflow-y-auto`))t.clientHeight<100||!t.querySelector(`[data-msg-index]`)||(!e||t.scrollHeight>e.scrollHeight)&&(e=t);let t=[];e&&(t.push(`Rendered messages: ${e.querySelectorAll(`[data-msg-index]`).length}`),t.push(`Transcript DOM nodes: ${e.querySelectorAll(`*`).length}`),t.push(`Transcript height: ${Math.round(e.scrollHeight)}px`));let n=performance.memory;return n&&t.push(`JS heap (page): ${(n.usedJSHeapSize/1048576).toFixed(1)} MB`),t}function Wi({sessionId:e,projectName:t}){let[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{let n=!0;return E.get(`${T(t)}/chat/sessions/${e}/images?project=${encodeURIComponent(t)}`).then(e=>{n&&r(e)}).catch(e=>{n&&a(e.message)}),()=>{n=!1}},[e,t]);let u=(n,i=!1)=>{s(n),a(null),E.post(`${T(t)}/chat/sessions/${e}/images/strip?project=${encodeURIComponent(t)}`,{mode:n,includeAttachments:i}).then(e=>{r(e.remaining),l({removed:e.removed,bytes:e.bytesFreed})}).catch(e=>a(e.message)).finally(()=>s(null))};return i&&!n?(0,$.jsx)(`p`,{className:`text-[11px] text-error`,children:i}):n?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-foreground`,children:`Transcript images`}),n.total===0?(0,$.jsxs)(`p`,{className:`text-[11px] text-text-subtle`,children:[`No images in this transcript`,c?` — it is clean.`:`.`]}):(0,$.jsxs)(`p`,{className:`text-[11px] text-text-secondary`,children:[n.total,` image`,n.total===1?``:`s`,` · `,Hi(n.bytes),` of base64, replayed on every turn`,n.attachments>0&&` · ${n.attachments} attached by you`,`.`]}),n.oversized>0&&(0,$.jsxs)(`div`,{className:`flex gap-2 rounded-md border border-warning/40 bg-warning/10 p-2 text-[11px] text-text-secondary`,children:[(0,$.jsx)(W,{className:`mt-px size-3.5 shrink-0 text-warning`}),(0,$.jsxs)(`span`,{children:[n.oversized,` image`,n.oversized===1?` reaches`:`s reach`,` the `,n.limit,`px limit (largest `,n.largestSide,`px). Once a request carries several images the API rejects those outright, which fails the whole turn — removing them loses no context.`]})]}),n.oversizedAttachments>0&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border border-error/40 bg-error/10 p-2 text-[11px] text-text-secondary`,children:[(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(W,{className:`mt-px size-3.5 shrink-0 text-error`}),(0,$.jsxs)(`span`,{children:[n.oversizedAttachments,` of those `,n.oversizedAttachments===1?`is an image you`:`are images you`,` `,`attached yourself, so the buttons below leave `,n.oversizedAttachments===1?`it`:`them`,` in place. While `,n.oversizedAttachments===1?`it stays`:`they stay`,`, every turn in this session keeps failing. Removing `,n.oversizedAttachments===1?`it`:`them`,` cannot be undone: an attachment PPM sent keeps a copy on disk with its path still in the message, but one from another client does not.`]})]}),(0,$.jsxs)(M,{size:`sm`,variant:`destructive`,disabled:o!==null,onClick:()=>u(`oversized`,!0),children:[o===`oversized`?(0,$.jsx)(w,{className:`size-3.5 animate-spin`}):(0,$.jsx)(lt,{className:`size-3.5`}),`Remove oversized, attachments included`]})]}),c&&(0,$.jsxs)(`p`,{className:`text-[11px] text-success`,children:[`Removed `,c.removed,` image`,c.removed===1?``:`s`,`, freed `,Hi(c.bytes),`.`]}),i&&(0,$.jsx)(`p`,{className:`text-[11px] text-error`,children:i}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:flex-row`,children:[(0,$.jsxs)(M,{size:`sm`,variant:`outline`,className:`flex-1`,disabled:o!==null||n.oversized===0,onClick:()=>u(`oversized`),children:[o===`oversized`?(0,$.jsx)(w,{className:`size-3.5 animate-spin`}):(0,$.jsx)(lt,{className:`size-3.5`}),`Remove oversized`,n.oversized>0?` (${n.oversized} · ${Hi(n.oversizedBytes)})`:``]}),(0,$.jsxs)(M,{size:`sm`,variant:`destructive`,className:`flex-1`,disabled:o!==null||n.total===0,onClick:()=>u(`all`),children:[o===`all`?(0,$.jsx)(w,{className:`size-3.5 animate-spin`}):(0,$.jsx)(lt,{className:`size-3.5`}),`Remove all`,n.total>0?` (${n.total} · ${Hi(n.bytes)})`:``]})]}),(0,$.jsx)(`p`,{className:`text-[11px] text-text-subtle`,children:`These two buttons cover tool images only, and leave anything you attached alone. A removed tool image is replaced by its placeholder text; the chat still shows the file, re-read from disk.`})]}):(0,$.jsx)(`p`,{className:`text-[11px] text-text-subtle`,children:`Scanning transcript for images...`})}function Gi({sessionId:e,projectName:t}){let[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(null);if((0,Q.useEffect)(()=>{let n=!0;return E.get(`${T(t)}/chat/sessions/${e}/usage?project=${encodeURIComponent(t)}`).then(e=>{n&&r(e.turns)}).catch(e=>{n&&a(e.message)}),()=>{n=!1}},[e,t]),i)return(0,$.jsx)(`p`,{className:`text-[11px] text-error`,children:i});if(!n)return(0,$.jsx)(`p`,{className:`text-[11px] text-text-subtle`,children:`Loading token history...`});if(n.length===0)return(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-foreground`,children:`Token & cache`}),(0,$.jsx)(`p`,{className:`text-[11px] text-text-subtle`,children:`No turns recorded yet. Send a message and the token split for each turn shows up here.`})]});let o=n.filter(e=>e.usage.coldStart).length,s=n.reduce((e,t)=>e+t.usage.costUsd,0),c=n.reduce((e,t)=>e+An(t.usage),0),l=new Set(n.map(e=>e.usage.accountId).filter(Boolean)).size;return(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-foreground`,children:`Token & cache`}),(0,$.jsxs)(`p`,{className:`text-[11px] text-text-secondary`,children:[`Last `,n.length,` turn`,n.length===1?``:`s`,` · `,o,` restarted the session ·`,` `,Rn(c),` of transcript re-sent uncached · $`,s.toFixed(2),l>1&&` · spread over ${l} accounts`]}),(0,$.jsx)(`div`,{className:`max-h-[30vh] overflow-y-auto rounded-md border border-border`,children:(0,$.jsxs)(`table`,{className:`w-full font-mono text-[10.5px]`,children:[(0,$.jsx)(`thead`,{className:`sticky top-0 bg-surface text-text-subtle`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`px-2 py-1 text-left font-normal`,children:`When`}),(0,$.jsx)(`th`,{className:`px-2 py-1 text-left font-normal`,children:`Account`}),(0,$.jsx)(`th`,{className:`px-2 py-1 text-right font-normal`,children:`Prefix`}),(0,$.jsx)(`th`,{className:`px-2 py-1 text-right font-normal`,children:`Cached`}),(0,$.jsx)(`th`,{className:`px-2 py-1 text-right font-normal`,children:`Cost`}),(0,$.jsx)(`th`,{className:`px-2 py-1 text-left font-normal`,children:`Start`})]})}),(0,$.jsx)(`tbody`,{children:n.map(e=>{let t=Math.round(e.usage.cacheHitRate*100),n=Pn(e.usage).level;return(0,$.jsxs)(`tr`,{className:`border-t border-border`,children:[(0,$.jsx)(`td`,{className:`px-2 py-1 text-text-subtle`,children:e.recordedAt.slice(11,16)||e.recordedAt.slice(0,10)}),(0,$.jsx)(`td`,{className:`max-w-24 truncate px-2 py-1 text-text-subtle`,title:e.usage.accountLabel??e.usage.accountId??``,children:e.usage.accountLabel??e.usage.accountId?.slice(0,8)??`—`}),(0,$.jsx)(`td`,{className:`px-2 py-1 text-right text-text-secondary`,children:Rn(kn(e.usage))}),(0,$.jsxs)(`td`,{className:`px-2 py-1 text-right ${n===`bad`?`text-warning`:n===`warn`?`text-text-primary`:`text-success`}`,children:[t,`%`]}),(0,$.jsxs)(`td`,{className:`px-2 py-1 text-right text-text-secondary`,children:[`$`,e.usage.costUsd.toFixed(3)]}),(0,$.jsx)(`td`,{className:`px-2 py-1 text-text-subtle`,children:e.usage.coldStart?e.usage.coldReason??`cold`:`warm`})]},e.id)})})]})}),(0,$.jsxs)(`p`,{className:`text-[11px] text-text-subtle`,children:[`A high "Cached" share is the cheap case. A turn marked `,(0,$.jsx)(`code`,{children:`idle_timeout`}),` paid for the whole transcript again because the session sat idle with no tab open long enough for PPM to release its subprocess. The cache is scoped per account, so a turn on a different account starts cold no matter how the session was resumed.`]})]})}function Ki({sessionId:e,projectName:t,open:n,onOpenChange:r}){let[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(!1),c=se();(0,Q.useEffect)(()=>{n&&(s(!1),a(null),E.get(`${T(t)}/chat/sessions/${e}/debug?project=${encodeURIComponent(t)}`).then(e=>{let t=e.jsonlSizeBytes==null?``:` (${Vi(e.jsonlSizeBytes)}${e.jsonlLines==null?``:`, ${e.jsonlLines} records`})`;a([`PPM Session: ${e.ppmSessionId}`,`SDK Session: ${e.sdkSessionId}`,e.jsonlPath?`JSONL: ${e.jsonlPath}${t}`:`JSONL: not found`,e.projectPath?`Project: ${e.projectPath}`:null,...Ui()].filter(Boolean).join(`
8
- `))}).catch(()=>a(`Failed to load debug info`)))},[n,e,t]);let l=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`h2`,{className:`flex items-center gap-2 text-sm font-semibold text-foreground`,children:[(0,$.jsx)(le,{className:`size-4 text-primary`}),`Session debug info`]}),(0,$.jsx)(`pre`,{className:`max-h-[35vh] overflow-y-auto whitespace-pre-wrap break-all rounded-md border border-border bg-surface p-2.5 font-mono text-[11px] leading-relaxed text-text-secondary select-text`,children:i??`Loading...`}),(0,$.jsx)(M,{size:`sm`,onClick:()=>{i&&ze(i).then(e=>{e&&(s(!0),setTimeout(()=>s(!1),1500))})},disabled:!i,className:`w-full`,children:o?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ct,{className:`size-3.5`}),` Copied!`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(y,{className:`size-3.5`}),` Copy`]})}),(0,$.jsx)(`div`,{className:`border-t border-border pt-3`,children:n&&(0,$.jsx)(Gi,{sessionId:e,projectName:t})}),(0,$.jsx)(`div`,{className:`border-t border-border pt-3`,children:n&&(0,$.jsx)(Wi,{sessionId:e,projectName:t})})]});return c?(0,$.jsx)(N,{open:n,onClose:()=>r(!1),className:`popover-solid`,children:(0,$.jsx)(`div`,{className:`max-h-[85vh] overflow-y-auto px-4 pb-4 pt-1`,children:l})}):(0,$.jsx)(pe,{open:n,onOpenChange:r,children:(0,$.jsxs)(we,{className:`sm:max-w-lg`,children:[(0,$.jsx)(P,{className:`sr-only`,children:`Session debug info`}),l]})})}function qi({hasUnread:e,onToggleUnread:t,onOpenDebug:n}){return(0,$.jsxs)(B,{children:[(0,$.jsx)(H,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`flex items-center justify-center size-5 rounded text-text-subtle hover:text-text-secondary hover:bg-surface-elevated transition-colors`,title:`More actions`,"aria-label":`More actions`,children:(0,$.jsx)(x,{className:`size-3.5`})})}),(0,$.jsxs)(he,{align:`end`,side:`top`,className:`min-w-[190px]`,children:[(0,$.jsx)(J,{onClick:t,className:`max-md:py-3`,children:e?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(G,{className:`size-3.5 text-warning`}),` Mark as read`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(h,{className:`size-3.5 fill-current text-primary`}),` Mark as unread`]})}),(0,$.jsxs)(J,{onClick:n,className:`max-md:py-3`,children:[(0,$.jsx)(le,{className:`size-3.5`}),` Session debug info`]})]})]})}function Ji({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastFetchedAt:a}){let{usages:o,accounts:s,activeAccountId:c,initialLoading:l,refreshing:u,flashIds:d,reload:f}=at(t);if(!t)return null;let p=new Map(s.map(e=>[e.id,e])),m=e.queryCostUsd!=null||e.totalCostUsd!=null,h=o.length>0;return(0,$.jsxs)(`div`,{className:`relative border-b border-border bg-surface px-3 py-2.5 space-y-2.5 max-h-[350px] overflow-y-auto`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage`}),a&&(0,$.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:nt(new Date(a).getTime())})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsxs)(`button`,{onClick:()=>ke(`accounts`),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-primary px-1 cursor-pointer`,title:`Add, remove or rotate accounts`,children:[`Manage accounts `,(0,$.jsx)(We,{className:`size-3`})]}),r&&(0,$.jsx)(`button`,{onClick:()=>{r(),f()},disabled:i||u,className:`text-xs text-text-subtle hover:text-text-primary px-1 disabled:opacity-50 cursor-pointer`,title:`Refresh`,"aria-label":`Refresh usage`,children:(0,$.jsx)(V,{className:`size-3 ${i||u?`animate-spin`:``}`})}),(0,$.jsx)(`button`,{onClick:n,className:`text-xs text-text-subtle hover:text-text-primary px-1 cursor-pointer`,"aria-label":`Close usage panel`,children:(0,$.jsx)(te,{className:`size-3`})})]})]}),h||l?(0,$.jsx)(`div`,{className:`space-y-1.5`,children:l?(0,$.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`Loading...`}):o.map(t=>(0,$.jsx)(rt,{entry:t,isActive:t.accountId===(c??e.activeAccountId),accountInfo:p.get(t.accountId),flash:d.has(t.accountId)},t.accountId))}):e.session||e.weekly||e.weeklyOpus||e.weeklySonnet?(0,$.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,$.jsx)(it,{label:`5-Hour Session`,bucket:e.session}),(0,$.jsx)(it,{label:`Weekly`,bucket:e.weekly}),(0,$.jsx)(it,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,$.jsx)(it,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,$.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`No usage data available`}),m&&(0,$.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,$.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,$.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]})]})}function Yi(e){return e>=90?`text-error`:e>=70?`text-warning`:`text-success`}function Xi(e){return e>=90?`bg-error`:e>=70?`bg-warning`:`bg-success`}function Zi({label:e,frac:t}){let n=t==null?null:Math.round(t*100);return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),(0,$.jsx)(`span`,{className:`text-xs font-medium tabular-nums ${n==null?`text-text-subtle`:Yi(n)}`,children:n==null?`—`:`${n}%`})]}),(0,$.jsx)(`div`,{className:`h-2 rounded-full bg-border overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-full rounded-full transition-all ${n==null?``:Xi(n)}`,style:{width:`${Math.min(n??0,100)}%`}})})]})}function Qi({onClose:e,usage:t}){let[n,r]=(0,Q.useState)([]),[i,a]=(0,Q.useState)({}),[o,s]=(0,Q.useState)(!1),c=(0,Q.useCallback)(async()=>{s(!0);try{r((await E.get(`/api/codex-accounts`)).accounts),a(await E.get(`/api/codex-accounts/usage`))}catch{}finally{s(!1)}},[]);return(0,Q.useEffect)(()=>{c()},[c]),(0,$.jsxs)(`div`,{className:`border-t border-border bg-surface px-3 py-2.5 space-y-2.5 max-h-[350px] overflow-y-auto`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Codex Usage`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`button`,{onClick:c,disabled:o,className:`text-text-subtle hover:text-text-primary px-1 cursor-pointer disabled:opacity-50`,title:`Refresh`,children:(0,$.jsx)(V,{className:`size-3 ${o?`animate-spin`:``}`})}),(0,$.jsx)(`button`,{onClick:e,className:`text-text-subtle hover:text-text-primary px-1 cursor-pointer`,title:`Close`,children:(0,$.jsx)(te,{className:`size-3`})})]})]}),o&&n.length===0&&(0,$.jsxs)(`div`,{className:`text-xs text-text-subtle flex items-center gap-2`,children:[(0,$.jsx)(w,{className:`size-3 animate-spin`}),` Loading…`]}),!o&&n.length===0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`rounded-md border border-border/50 bg-surface/40 p-2.5 space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm text-text-primary truncate flex-1 min-w-0`,children:t.activeAccountLabel||`Default login`}),(0,$.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-text-subtle border border-border rounded px-1`,children:`~/.codex`})]}),(0,$.jsx)(Zi,{label:`5-Hour`,frac:t.fiveHour}),(0,$.jsx)(Zi,{label:`Weekly`,frac:t.sevenDay})]}),(0,$.jsxs)(`p`,{className:`text-[11px] text-text-subtle`,children:[`Using your default `,(0,$.jsx)(`code`,{children:`~/.codex`}),` login. Add managed accounts in Settings → AI Provider → Codex.`]})]}),n.map(e=>{let t=i[e.id]??{};return(0,$.jsxs)(`div`,{className:`rounded-md border border-border/50 bg-surface/40 p-2.5 space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm text-text-primary truncate flex-1 min-w-0`,children:e.label}),(0,$.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-text-subtle border border-border rounded px-1`,children:e.type}),e.planType&&(0,$.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:e.planType})]}),(0,$.jsx)(Zi,{label:`5-Hour`,frac:t.fiveHour}),(0,$.jsx)(Zi,{label:`Weekly`,frac:t.sevenDay})]},e.id)})]})}var $i={working:`working`,paused:`paused`,"no-transcript":`no session`};function ea({member:e,onOpen:t}){let n=e.workState===`working`,r=qr(e),i=Kr(e.startedAt,n?void 0:e.lastEventAt),a=Gr(e.agentType);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>t(e.name),className:`w-full text-left min-h-[44px] px-1.5 py-1 rounded-md hover:bg-surface-elevated transition-colors group`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[n?(0,$.jsx)(w,{className:`size-3 shrink-0 animate-spin text-success`}):(0,$.jsx)(`span`,{className:k(`size-1.5 rounded-full shrink-0`,e.workState===`paused`?`bg-warning`:`bg-text-3`)}),(0,$.jsx)(`span`,{className:`font-medium truncate`,children:e.name}),a&&(0,$.jsx)(`span`,{className:`text-text-subtle text-[10px] truncate`,children:a}),e.model&&(0,$.jsxs)(`span`,{className:`text-text-subtle text-[10px]`,children:[`(`,e.model,`)`]}),(0,$.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 shrink-0 text-[10px] text-text-subtle`,children:[i&&(0,$.jsx)(`span`,{children:i}),(0,$.jsx)(`span`,{className:k(n&&`text-success`),children:$i[e.workState]}),(0,$.jsx)(c,{className:`size-3 opacity-0 group-hover:opacity-100 transition-opacity`})]})]}),r&&(0,$.jsx)(`div`,{className:`mt-0.5 pl-5 text-[11px] text-text-subtle truncate font-mono`,children:r})]})}function ta({members:e,loading:t,onOpenMember:n,className:r}){return e.length===0?(0,$.jsx)(`div`,{className:k(`flex items-center justify-center gap-2 text-xs text-text-subtle py-4`,r),children:t?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(w,{className:`size-3 animate-spin`}),`Reading member sessions…`]}):`No member sessions recorded`}):(0,$.jsx)(`div`,{className:k(`overflow-y-auto space-y-0.5`,r),children:e.map(e=>(0,$.jsx)(ea,{member:e,onOpen:n},e.name))})}var na=[`subject`,`summary`,`text`,`message`,`content`,`description`,`reason`,`feedback`],ra=[`description`,`message`,`content`,`reason`,`feedback`],ia=new Set([`type`,`taskId`,`task_id`,`assignedBy`,`assigned_by`,`timestamp`,`request_id`,`requestId`]),aa=e=>typeof e==`string`?e.trim():e==null?``:String(e);function oa(e,t,n){for(let r of t){if(r===n)continue;let t=aa(e[r]);if(t)return{key:r,value:t}}return null}function sa(e){return Object.entries(e).filter(([e,t])=>!ia.has(e)&&aa(t)).map(([e,t])=>`${e}: ${aa(t)}`).join(` · `)}function ca(e,t){let n=aa(t),r=aa(e);if(!r)return{title:n};let i;try{i=JSON.parse(r)}catch{let[e,...t]=r.split(`
9
- `),i=t.join(`
10
- `).trim();return{title:n||aa(e),...i?{detail:i}:{}}}if(!i||typeof i!=`object`||Array.isArray(i))return{title:n||r};let a=i,o=aa(a.taskId)||aa(a.task_id),s=oa(a,na),c=oa(a,ra,s?.key);return{title:n||s?.value||sa(a)||aa(a.type)||r,...c?{detail:c.value}:{},...o?{taskId:o}:{}}}function la({messages:e,className:t}){let n=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{n.current?.scrollIntoView({behavior:`smooth`})},[e.length]),e.length===0?(0,$.jsx)(`p`,{className:k(`text-xs text-text-subtle text-center py-4`,t),children:`No messages yet`}):(0,$.jsx)(`div`,{className:k(`overflow-y-auto`,t),children:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[e.map((e,t)=>{let n=e.parsedType?m[e.parsedType]:null,{title:r,detail:i,taskId:a}=ca(e.text,e.summary);return(0,$.jsxs)(`div`,{className:`text-xs`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 text-text-subtle`,children:[(0,$.jsx)(`span`,{className:`font-medium`,style:da(e.color),children:e.from}),(0,$.jsx)(`span`,{children:`→`}),(0,$.jsx)(`span`,{children:e.to}),(0,$.jsx)(`span`,{className:`ml-auto text-[10px]`,children:ua(e.timestamp)})]}),(0,$.jsxs)(`div`,{className:`mt-0.5 text-foreground/90 break-words`,children:[n&&(0,$.jsx)(`span`,{className:k(`inline-block px-1 py-0 rounded text-[9px] mr-1`,n.className),children:n.label}),a&&(0,$.jsxs)(`span`,{className:`inline-block px-1 py-0 rounded text-[9px] mr-1 bg-surface-elevated text-text-subtle`,children:[`#`,a]}),r]}),i&&(0,$.jsx)(`div`,{className:`mt-0.5 text-[11px] text-text-subtle break-words line-clamp-2`,children:i})]},`${e.timestamp}-${t}`)}),(0,$.jsx)(`div`,{ref:n})]})})}function ua(e){try{return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}catch{return``}}function da(e){if(e&&(/^#[0-9a-fA-F]{3,8}$/.test(e)||/^[a-zA-Z]{3,20}$/.test(e)))return{color:e}}function fa(e,t){return e===t?`Team (current session)`:e}function pa({teamNames:e,messages:t,sessionId:n,projectName:r}){let[i,a]=(0,Q.useState)(e[0]??``),[o,s]=(0,Q.useState)(`members`),c=Qe(),l=b();(0,Q.useEffect)(()=>{e.length>0&&!e.includes(i)&&a(e[0])},[e,i]);let{members:u,outbound:d,loading:f,refresh:p}=Xr(i,!!i),m=(0,Q.useCallback)(e=>{c({teamName:i,memberName:e,projectName:r})},[c,i,r]),h=(0,Q.useMemo)(()=>{let e=d.map(e=>({from:e.from,to:e.to,text:e.text,timestamp:e.timestamp,...e.summary?{summary:e.summary}:{}}));return[...t,...e].sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime()).slice(-200)},[t,d]),g=u.filter(e=>e.workState===`working`).length,_=e=>k(`flex items-center gap-1.5 px-2.5 rounded-md text-[11px] whitespace-nowrap transition-colors`,l?`min-h-[44px]`:`py-1`,e?`bg-primary/10 text-primary font-medium`:`text-text-subtle hover:text-text-primary`);return(0,$.jsxs)(`div`,{className:`flex flex-col min-h-0`,children:[e.length>1&&(0,$.jsx)(`div`,{className:`flex items-center gap-1 overflow-x-auto min-w-0 mb-1.5`,children:e.map(e=>(0,$.jsx)(`button`,{onClick:()=>a(e),className:k(`px-2 py-0.5 text-[11px] rounded-md whitespace-nowrap transition-colors`,i===e?`bg-primary/10 text-primary font-medium`:`text-text-subtle hover:text-text-primary`),children:fa(e,n)},e))}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 mb-1.5 shrink-0`,role:`tablist`,children:[(0,$.jsxs)(`button`,{role:`tab`,"aria-selected":o===`members`,onClick:()=>s(`members`),className:_(o===`members`),children:[(0,$.jsx)(`span`,{children:`Members`}),(0,$.jsx)(`span`,{className:`text-text-subtle`,children:u.length}),g>0&&(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-success`,children:[(0,$.jsx)(`span`,{className:`size-1.5 rounded-full bg-success animate-pulse`}),g]})]}),(0,$.jsxs)(`button`,{role:`tab`,"aria-selected":o===`messages`,onClick:()=>s(`messages`),className:_(o===`messages`),children:[(0,$.jsx)(`span`,{children:`Messages`}),(0,$.jsx)(`span`,{className:`text-text-subtle`,children:h.length})]}),(0,$.jsx)(`button`,{onClick:p,className:k(`ml-auto text-text-subtle hover:text-foreground shrink-0`,l?`p-3`:`p-1`),"aria-label":`Refresh`,children:(0,$.jsx)(V,{className:k(`size-3`,f&&`animate-spin`)})})]}),o===`members`?(0,$.jsx)(ta,{members:u,loading:f,onOpenMember:m,className:`max-h-56`}):(0,$.jsx)(la,{messages:h,className:`max-h-56`})]})}function ma(e){return e>=90?`text-error`:e>=70?`text-warning`:`text-success`}function ha({projectName:e,usageInfo:t,usageLoading:n,refreshUsage:r,lastFetchedAt:a,sessionId:s,providerId:c,onSelectSession:l,onBugReport:u,isConnected:d,onReload:f,teamActivity:p,teamMessages:m,onTeamOpen:h}){let[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)([]),[b,x]=(0,Q.useState)(!1),S=He(e=>e.notifications),C=He(e=>s?e.notifications.has(s):!1),ee=He(e=>e.clearForSession),D=He(e=>e.markUnread),[ne,re]=(0,Q.useState)(``),O=xe(ne,300),[A,ie]=(0,Q.useState)(null),[ae,j]=(0,Q.useState)(``),[se,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(!1),[le,ue]=(0,Q.useState)([]),[F,de]=(0,Q.useState)(null),[fe,L]=(0,Q.useState)({}),[B,pe]=(0,Q.useState)(!1),[H,me]=(0,Q.useState)(!1),he=(0,Q.useRef)(null),ge=oe(e=>e.openTab),W=e=>{_(t=>t===e?null:e)},G=(0,Q.useCallback)(async t=>{if(e){x(!0);try{let n=new URLSearchParams({limit:`50`,offset:`0`});t&&n.set(`q`,t);let r=await E.get(`${T(e)}/chat/sessions?${n}`);y(r.sessions),M(r.hasMore)}catch{}finally{x(!1)}}},[e]),_e=(0,Q.useCallback)(async()=>{if(!(!e||N||!se)){P(!0);try{let t=v.filter(e=>!e.pinned).length,n=new URLSearchParams({limit:`50`,offset:String(t)});O&&n.set(`q`,O);let r=await E.get(`${T(e)}/chat/sessions?${n}`);y(e=>{let t=new Set(e.map(e=>e.id)),n=r.sessions.filter(e=>!t.has(e.id));return[...e,...n]}),M(r.hasMore)}catch{}finally{P(!1)}}},[e,N,se,v,O]);(0,Q.useEffect)(()=>{g===`history`&&v.length===0&&G()},[g]),(0,Q.useEffect)(()=>{g===`history`&&G(O||void 0)},[O]);let K=(0,Q.useCallback)(async()=>{if(e)try{let t=await E.get(`${T(e)}/tags`);ue(t.tags),L(t.counts)}catch{}},[e]);(0,Q.useEffect)(()=>{g===`history`&&e&&K()},[g,e,K]);function ye(t){l?(l(t),_(null)):ge({type:`chat`,title:t.title||`Chat`,projectId:e??null,metadata:{projectName:e,sessionId:t.id,providerId:t.providerId},closable:!0})}let q=(0,Q.useCallback)((e,t)=>{t.stopPropagation(),ie(e.id),j(e.title||``),setTimeout(()=>he.current?.select(),0)},[]),J=(0,Q.useCallback)(async()=>{if(!A||!ae.trim()||!e){ie(null);return}try{await E.patch(`${T(e)}/chat/sessions/${A}`,{title:ae.trim()}),y(e=>e.map(e=>e.id===A?{...e,title:ae.trim()}:e))}catch{}ie(null)},[A,ae,e]),we=(0,Q.useCallback)(()=>ie(null),[]),Ee=(0,Q.useCallback)(async(t,n)=>{if(t.stopPropagation(),!e)return;let r=`${T(e)}/chat/sessions/${n.id}/pin`;try{n.pinned?await E.del(r):await E.put(r),y(e=>e.map(e=>e.id===n.id?{...e,pinned:!e.pinned}:e).sort((e,t)=>e.pinned&&!t.pinned?-1:!e.pinned&&t.pinned?1:new Date(t.createdAt).getTime()-new Date(e.createdAt).getTime()))}catch{}},[e]),Y=(0,Q.useCallback)(async(t,n)=>{if(t.stopPropagation(),e&&window.confirm(`Delete this session? This cannot be undone.`))try{await E.del(`${T(e)}/chat/sessions/${n.id}?providerId=${n.providerId}`),y(e=>e.filter(e=>e.id!==n.id))}catch{}},[e]),De=(0,Q.useCallback)((e,t)=>{y(n=>n.map(n=>n.id===e?{...n,tag:t}:n)),K()},[K]),ke=(0,Q.useCallback)(async()=>{if(!e)return;let t=window.prompt(`Delete sessions older than how many days? (pinned sessions are kept)`,`30`);if(!t)return;let n=parseInt(t,10);if(!(!n||n<1)&&window.confirm(`Delete all unpinned sessions older than ${n} days? This cannot be undone.`)){x(!0);try{await E.del(`${T(e)}/chat/sessions?olderThanDays=${n}`),G(O||void 0)}catch{}}},[e,G,O]);(0,Q.useEffect)(()=>{if(g!==`history`)return;let t=t=>{if(t.target instanceof HTMLInputElement||t.target instanceof HTMLTextAreaElement)return;let n=parseInt(t.key);if(n>=1&&n<=le.length&&s){let t=le[n-1];t&&(E.patch(`${T(e)}/chat/sessions/${s}/tag`,{tagId:t.id}).catch(()=>{}),De(s,{id:t.id,name:t.name,color:t.color}))}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[g,le,s,e,De]);let Ae=F===null?v:v.filter(e=>e.tag?.id===F),je=!c||c===`claude`,X=c===`codex`,Fe=t.fiveHour==null?null:Math.round(t.fiveHour*100),Ie=t.sevenDay==null?null:Math.round(t.sevenDay*100),Z=Fe!=null||Ie!=null?ma(Math.max(Fe??0,Ie??0)):`text-text-subtle`;return(0,$.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 overflow-x-auto scrollbar-none`,children:[(0,$.jsxs)(`button`,{onClick:()=>W(`history`),className:`shrink-0 flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${g===`history`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,children:[(0,$.jsx)(Pe,{className:`size-3`}),(0,$.jsx)(`span`,{children:`History`})]}),s&&c&&c!==`mock`?(0,$.jsxs)(`button`,{onClick:()=>W(`config`),className:`shrink-0 flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${g===`config`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,title:`AI Settings`,children:[(0,$.jsx)(Me,{providerId:c}),(0,$.jsx)(`span`,{className:`capitalize`,children:c})]}):(0,$.jsx)(`button`,{onClick:()=>W(`config`),className:`shrink-0 p-1 rounded transition-colors ${g===`config`?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary hover:bg-surface-elevated`}`,title:`AI Settings`,children:(0,$.jsx)(R,{className:`size-3`})}),je||X?(0,$.jsxs)(`button`,{onClick:()=>W(`usage`),className:`shrink-0 flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] font-medium tabular-nums transition-colors hover:bg-surface-elevated ${g===`usage`?`bg-primary/10`:``} ${Z}`,title:`Usage limits`,children:[(0,$.jsx)(ot,{className:`size-3`}),t.activeAccountLabel&&(0,$.jsxs)(`span`,{className:`text-text-secondary font-normal truncate max-w-[110px]`,title:t.activeAccountLabel,children:[`[`,t.activeAccountLabel,`]`]}),(0,$.jsxs)(`span`,{children:[`5h:`,Fe==null?`--%`:`${Fe}%`]}),(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,$.jsxs)(`span`,{children:[`Wk:`,Ie==null?`--%`:`${Ie}%`]})]}):null,p?.hasTeams&&(0,$.jsxs)(`button`,{onClick:()=>{W(`team`),h?.()},className:`shrink-0 relative flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${g===`team`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,title:`Team activity`,children:[(0,$.jsx)(ce,{className:`size-3`}),(0,$.jsx)(`span`,{children:`Team`}),(p.unreadCount??0)>0&&(0,$.jsx)(`span`,{className:`absolute -top-0.5 -right-0.5 size-2 bg-primary rounded-full animate-pulse`})]})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 pl-1`,children:[f&&(0,$.jsxs)(`button`,{onClick:e=>{let t=e.currentTarget.querySelector(`svg`);t&&(t.classList.add(`animate-spin`),setTimeout(()=>t.classList.remove(`animate-spin`),600)),f()},className:`relative size-4 flex items-center justify-center`,title:d?`Reload messages`:`Disconnected — click to reload`,children:[(0,$.jsx)(V,{className:`size-3 ${d?`text-muted-foreground/60`:`text-error`}`,strokeWidth:2.5}),(0,$.jsx)(`span`,{className:`absolute -top-0.5 -right-0.5 size-1.5 rounded-full ${d?`bg-success`:`bg-error animate-pulse`}`})]}),s&&(0,$.jsx)(qi,{hasUnread:C,onToggleUnread:()=>C?ee(s):D(s,e),onOpenDebug:()=>me(!0)})]})]}),s&&(0,$.jsx)(Ki,{sessionId:s,projectName:e,open:H,onOpenChange:me}),g===`history`&&(0,$.jsxs)(`div`,{className:`border-t border-border/30 bg-surface`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 border-b border-border/30`,children:[(0,$.jsx)(Se,{className:`size-3 text-text-subtle shrink-0`}),(0,$.jsx)(`input`,{type:`text`,value:ne,onChange:e=>re(e.target.value),placeholder:`Search sessions...`,className:`flex-1 bg-transparent text-[11px] text-text-primary outline-none placeholder:text-text-subtle`}),(0,$.jsx)(`button`,{onClick:ke,className:`p-0.5 rounded text-text-subtle hover:text-error transition-colors`,title:`Delete old sessions...`,children:(0,$.jsx)(Ne,{className:`size-3`})}),(0,$.jsx)(`button`,{onClick:()=>G(O||void 0),disabled:b,className:`p-0.5 rounded text-text-subtle hover:text-text-secondary transition-colors disabled:opacity-50`,title:`Refresh`,children:(0,$.jsx)(V,{className:`size-3 ${b?`animate-spin`:``}`})})]}),le.length>0&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 overflow-x-auto border-b border-border/30 scrollbar-none`,children:[(0,$.jsxs)(`button`,{onClick:()=>de(null),className:`shrink-0 rounded-md border px-2 py-1 text-[10px] transition-colors ${F===null?`bg-primary/20 border-primary text-primary`:`border-border bg-surface text-text-secondary`}`,children:[`All (`,v.length,`)`]}),le.map(e=>(0,$.jsxs)(`button`,{onClick:()=>de(F===e.id?null:e.id),className:`shrink-0 flex items-center gap-1 rounded-md border px-2 py-1 text-[10px] transition-colors ${F===e.id?`border-current`:`border-border bg-surface`}`,style:F===e.id?{backgroundColor:e.color+`20`,color:e.color,borderColor:e.color}:void 0,children:[(0,$.jsx)(`span`,{className:`size-2 rounded-full shrink-0`,style:{backgroundColor:e.color}}),e.name,` (`,fe[e.id]??0,`)`]},e.id)),(0,$.jsx)(`button`,{onClick:()=>pe(!B),className:`shrink-0 p-1 rounded transition-colors ${B?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary`}`,title:`Manage tags`,children:(0,$.jsx)(z,{className:`size-3`})})]}),B&&(0,$.jsx)(`div`,{className:`border-b border-border/30 px-2 py-2 max-h-[180px] overflow-y-auto bg-surface-elevated/50`,children:(0,$.jsx)(U,{projectName:e,onTagsChanged:K})}),(0,$.jsx)(`div`,{className:`max-h-[200px] overflow-y-auto`,children:b&&v.length===0?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,$.jsx)(w,{className:`size-3.5 animate-spin text-text-subtle`})}):Ae.length===0?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-3 text-[11px] text-text-subtle`,children:ne?`No matching sessions`:`No sessions yet`}):(0,$.jsxs)($.Fragment,{children:[Ae.map(t=>{let n=S.get(t.id),r=!!n;return(0,$.jsx)(Ve,{session:t,projectName:e,projectTags:le,onTogglePin:Ee,onStartEditing:q,onDeleteSession:Y,onTagChanged:De,children:(0,$.jsxs)(`div`,{className:k(`flex items-center gap-2 w-full px-3 py-1.5 text-left hover:bg-surface-elevated transition-colors group`,r&&`font-medium text-foreground`,r&&Oe(n.type),!r&&`text-text-secondary`),children:[(0,$.jsx)(Me,{providerId:t.providerId}),t.tag&&(0,$.jsx)(`span`,{className:`size-2 rounded-full shrink-0`,style:{backgroundColor:t.tag.color},title:t.tag.name}),A===t.id?(0,$.jsxs)(`form`,{className:`flex items-center gap-1 flex-1 min-w-0`,onSubmit:e=>{e.preventDefault(),J()},children:[(0,$.jsx)(`input`,{ref:he,value:ae,onChange:e=>j(e.target.value),onBlur:J,onKeyDown:e=>{e.key===`Escape`&&we()},className:`flex-1 min-w-0 bg-surface-elevated text-[11px] text-text-primary px-1 py-0.5 rounded border border-border outline-none focus:border-primary`,autoFocus:!0}),(0,$.jsx)(`button`,{type:`submit`,className:`p-0.5 text-success hover:text-success/80`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(o,{className:`size-3`})}),(0,$.jsx)(`button`,{type:`button`,className:`p-0.5 text-text-subtle hover:text-text-secondary`,onClick:e=>{e.stopPropagation(),we()},children:(0,$.jsx)(te,{className:`size-3`})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{onClick:()=>ye(t),className:`text-[11px] truncate flex-1 text-left flex items-center gap-1`,children:[t.title?.startsWith(`[PPM]`)&&(0,$.jsx)(i,{className:`size-3 text-muted-foreground shrink-0`}),t.title?.startsWith(`[PPM]`)?t.title.slice(7):t.title||`Untitled`]}),(0,$.jsx)(`button`,{onClick:e=>Ee(e,t),className:`p-0.5 rounded transition-all ${t.pinned?`text-primary hover:text-primary/70`:`text-text-subtle hover:text-text-secondary can-hover:opacity-0 can-hover:group-hover:opacity-100`}`,title:t.pinned?`Unpin session`:`Pin session`,children:t.pinned?(0,$.jsx)(Te,{className:`size-3`}):(0,$.jsx)(Ce,{className:`size-3`})}),(0,$.jsx)(`button`,{onClick:e=>q(t,e),className:`p-0.5 rounded text-text-subtle hover:text-text-secondary can-hover:opacity-0 can-hover:group-hover:opacity-100 transition-opacity`,title:`Rename session`,children:(0,$.jsx)(be,{className:`size-3`})}),(0,$.jsx)(`button`,{onClick:e=>Y(e,t),className:`p-0.5 rounded text-text-subtle hover:text-error hover:bg-error/20 can-hover:opacity-0 can-hover:group-hover:opacity-100 transition-opacity`,title:`Delete session`,children:(0,$.jsx)(ve,{className:`size-3`})})]}),A!==t.id&&t.updatedAt&&(0,$.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0 w-16 text-right`,children:I(t.updatedAt)})]})},t.id)}),se&&(0,$.jsxs)(`button`,{onClick:_e,disabled:N,className:`flex items-center justify-center gap-1 w-full py-1.5 text-[11px] text-text-subtle hover:text-text-secondary hover:bg-surface-elevated transition-colors`,children:[N?(0,$.jsx)(w,{className:`size-3 animate-spin`}):null,N?`Loading...`:`Load more`]})]})})]}),g===`config`&&(0,$.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2 max-h-[280px] overflow-y-auto`,children:(0,$.jsx)(tt,{compact:!0})}),g===`team`&&p?.hasTeams&&(0,$.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2`,children:(0,$.jsx)(pa,{teamNames:p.teamNames,messages:m??[],sessionId:s,projectName:e})}),g===`usage`&&je&&(0,$.jsx)(Ji,{usage:t,visible:!0,onClose:()=>_(null),onReload:r,loading:n,lastFetchedAt:a}),g===`usage`&&X&&(0,$.jsx)(Qi,{usage:t,onClose:()=>_(null)})]})}var ga=3e3;function _a(e,t){let[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(!0),o=(0,Q.useRef)(void 0),s=(0,Q.useRef)(t);s.current=t;let c=t??`__new__`;(0,Q.useEffect)(()=>{if(!e){a(!1);return}let t=!1;a(!0);let n=setTimeout(()=>{t||a(!1)},ga);return E.get(`${T(e)}/chat/drafts/${encodeURIComponent(c)}`).then(e=>{if(!t)if(e){let t=[];try{t=JSON.parse(e.attachments)}catch{}r({content:e.content,attachments:t})}else r(null)}).catch(()=>{t||r(null)}).finally(()=>{clearTimeout(n),t||a(!1)}),()=>{t=!0,clearTimeout(n)}},[e,c]);let l=(0,Q.useCallback)((t,n)=>{e&&(o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{let r=s.current??`__new__`;E.put(`${T(e)}/chat/drafts/${encodeURIComponent(r)}`,{content:t,attachments:JSON.stringify(n??[])}).catch(()=>{})},1e3))},[e]),u=(0,Q.useCallback)(()=>{if(!e)return;o.current&&clearTimeout(o.current);let t=s.current??`__new__`;E.del(`${T(e)}/chat/drafts/${encodeURIComponent(t)}`).catch(()=>{}),r(null)},[e]);return(0,Q.useEffect)(()=>()=>{o.current&&clearTimeout(o.current)},[]),{draft:n,draftLoading:i,saveDraft:l,clearDraft:u}}function va({metadata:e,tabId:t}){let[n,r]=(0,Q.useState)(e?.sessionId??null),i=(0,Q.useCallback)(e=>{r(e)},[]),[a,o]=(0,Q.useState)(e?.providerId??`claude`),[s,c]=(0,Q.useState)([]),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)([]),[_,v]=(0,Q.useState)([]),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(``),[C,ee]=(0,Q.useState)(null),[D,k]=(0,Q.useState)(e?.permissionMode??void 0),A=(0,Q.useRef)(null),[ie,j]=(0,Q.useState)(!1),[se,M]=(0,Q.useState)(null),[N,P]=(0,Q.useState)(null),[ce,le]=(0,Q.useState)(null),ue=(0,Q.useRef)(0),F=e?.projectName??``,I=oe(e=>e.updateTab),de=O(e=>e.version),{usageInfo:fe,usageLoading:L,lastFetchedAt:R,refreshUsage:z}=Mt(F,a,n??void 0),{draft:B,draftLoading:pe,saveDraft:V,clearDraft:H}=_a(F,n);(0,Q.useEffect)(()=>{D||qe().then(e=>{let t=e.providers[e.default_provider??`claude`];k(t?.permission_mode??`bypassPermissions`)}).catch(()=>{})},[]),(0,Q.useEffect)(()=>{!t||!n||I(t,{metadata:{...e,sessionId:n,providerId:a,permissionMode:D}})},[n,a,D]);let{messages:me,renderedMessages:he,expandCompact:ge,isCompactExpanded:U,dismissMessage:W,clearErrors:G,messagesLoading:_e,versionMap:K,isStreaming:ve,phase:ye,isReconnecting:be,connectingElapsed:q,pendingApproval:J,contextWindowPct:xe,compactStatus:Se,statusMessage:Ce,sessionTitle:we,model:Te,setModel:Y,effort:De,setEffort:Oe,thinking:ke,setThinking:Ae,sendMessage:je,respondToApproval:Me,cancelStreaming:Ne,reconnect:Pe,refetchMessages:Fe,isConnected:Ie,teamActivity:Z,teamMessages:Le,markTeamRead:Re,bashPartialOutput:ze,backgroundShells:Be,killBackgroundShell:Ve}=At(n,a,F,i),Ue=Z?.teamNames?.[0]??``,{members:We}=Xr(Ue,!!Ue);(0,Q.useEffect)(()=>{if(Ie&&A.current){let{content:e,permissionMode:t,images:n,imagePaths:r}=A.current;A.current=null,je(e,{permissionMode:t,...n?.length&&{images:n},...r?.length&&{imagePaths:r}})}},[Ie,je]),(0,Q.useEffect)(()=>{if(!n||!t)return;let e=()=>{if(document.hidden)return;let{panels:e}=ae.getState();Object.values(e).some(e=>e.activeTabId===t)&&(He.getState().notifications.get(n)?.manual||He.getState().clearForSession(n))};e(),document.addEventListener(`visibilitychange`,e);let r=ae.subscribe(e),i=He.subscribe(e);return()=>{document.removeEventListener(`visibilitychange`,e),r(),i()}},[n,t]),(0,Q.useEffect)(()=>{t&&we&&I(t,{title:we})},[we]);let[Ge,Ke]=(0,Q.useState)(e?.pendingMessage),[Je,Ye]=(0,Q.useState)(null),[Xe,Ze]=(0,Q.useState)(!1),[Qe,$e]=(0,Q.useState)(0),[et,tt]=(0,Q.useState)(!1),nt=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{nt.current&&!_e&&tt(!1),nt.current=!!_e},[_e]);let[rt,it]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{pe||it(!0)},[pe]),(0,Q.useEffect)(()=>{Ge&&Ie&&n&&t&&I(t,{metadata:{...e,pendingMessage:void 0}})},[Ie,n]),(0,Q.useEffect)(()=>{Xe&&ve&&Ze(!1)},[Xe,ve]),(0,Q.useEffect)(()=>{if(!Xe)return;let e=setTimeout(()=>Ze(!1),6e4);return()=>clearTimeout(e)},[Xe]);let at=(0,Q.useCallback)((e,t)=>{oe.getState().openTab({type:`chat`,title:e||`AI Chat`,metadata:{projectName:F,providerId:a,...t&&{clearedFrom:t}},projectId:F||null,closable:!0})},[F,a]),ot=(0,Q.useCallback)(e=>{Ze(!1),r(e.id),o(e.providerId),t&&I(t,{title:e.title||`Chat`}),He.getState().clearForSession(e.id)},[t,I]),st=(0,Q.useCallback)(async(e,t)=>{if(!(!n||!F))try{let{api:r,projectUrl:i}=await re(async()=>{let{api:e,projectUrl:t}=await import(`./api-client-BogqsFna.js`);return{api:e,projectUrl:t}},__vite__mapDeps([49,6,1,2,30])),o=await r.post(`${i(F)}/chat/sessions/${n}/fork?providerId=${a}`,{messageId:t});oe.getState().openTab({type:`chat`,title:`Fork: ${e.slice(0,30)}`,metadata:{projectName:F,sessionId:o.id,providerId:a,pendingMessage:e},projectId:F||null,closable:!0})}catch(e){console.error(`Fork failed:`,e);let t=e?.message||`Unknown error`;ne.error(`Cannot fork from this message`,{description:t.includes(`not found`)||t.includes(`Invalid upToMessageId`)?`The original message is no longer available in the session transcript. Try forking from a different message.`:t})}},[n,F,a]),ct=(0,Q.useCallback)((e,t,n)=>{Ke(e),Ye({anchorMsgId:t,ownMsgId:n})},[]),lt=(0,Q.useCallback)(()=>{Ye(null),Ke(void 0),Ze(!1),H(),$e(e=>e+1)},[H]),ut=(0,Q.useCallback)(async(i,o)=>{if(!(!i.trim()||!n||!F)){Ze(!0);try{let s=await E.post(`${T(F)}/chat/sessions/${n}/fork?providerId=${a}&mode=edit`,{messageId:o});A.current={content:i,permissionMode:D},tt(!0),t&&I(t,{metadata:{...e,sessionId:s.id}}),r(s.id)}catch(e){Ze(!1);let t=e?.message||`Unknown error`;ne.error(`Cannot edit from this message`,{description:t.includes(`not found`)||t.includes(`Invalid upToMessageId`)?`The original message is no longer available in the session transcript.`:t})}}},[n,F,a,D,t,I,e]),dt=(0,Q.useCallback)(i=>{!i||i===n||(Ze(!1),tt(!0),t&&I(t,{metadata:{...e,sessionId:i}}),r(i))},[n,t,I,e]),ft=(0,Q.useCallback)((e,t,n=[])=>{if(t.length===0)return e;let r=[];for(let e of t)e.textContent&&r.push(e.textContent);let{inlineImagePaths:i,pathOnlyPaths:a}=gt(t,n);for(let e of i)r.push(`[Attached image (contents included in this message): ${e}]`);if(a.length>0){let e=a.join(`
11
- `);r.push(a.length===1?`[Attached file: ${e}]`:`[Attached files:\n${e}\n]`)}return r.length===0?e:r.join(`
12
-
13
- `)+`
14
-
15
- `+e},[]),pt=(0,Q.useCallback)(async(t,i=[],s)=>{let c=ht(i),l=ft(t,i,c),u=i.filter(e=>e.isImage&&e.serverPath).map(e=>e.serverPath);if(!(!l.trim()&&c.length===0)){if(!n)try{let n=F,i=await E.post(`${T(n)}/chat/sessions`,{providerId:a,title:t.slice(0,50),clearedFrom:e?.clearedFrom});r(i.id),o(i.providerId),A.current={content:l,permissionMode:D,images:c,imagePaths:u};return}catch(e){console.error(`Failed to create session:`,e);return}je(l,{permissionMode:D,priority:s,...c.length>0&&{images:c},...u.length>0&&{imagePaths:u}})}},[n,a,F,je,ft,D,e]),mt=(0,Q.useRef)(s);mt.current=s;let _t=(0,Q.useCallback)((e,t,r)=>{let i=e.trim().match(/^\/(\S+)(?:\s+([\s\S]+))?$/);if(i&&mt.current.find(e=>e.handler===`client`&&(e.name===i[1]||e.aliases?.includes(i[1])))?.name===`clear`){H(),at(i[2]?.trim(),n??void 0);return}if(Ke(void 0),H(),Je&&n&&F){let n=Je.anchorMsgId;Ye(null),ut(ft(e,t),n);return}pt(e,t,r)},[pt,H,Je,n,F,ut,ft,at]),vt=(0,Q.useRef)(me);vt.current=me;let yt=(0,Q.useCallback)(()=>vt.current.filter(e=>e.role===`user`&&e.content.trim()).map(e=>e.content),[]),bt=(0,Q.useCallback)((e,t)=>{V(e,t)},[V]),xt=(0,Q.useCallback)((e,t)=>{c(e),t&&g(t)},[]),St=(0,Q.useCallback)((e,t)=>{u(e),f(t)},[]),Ct=(0,Q.useCallback)(e=>{m(e),u(!1),f(``),setTimeout(()=>m(null),50),F&&(E.post(`${T(F)}/chat/slash-recents`,{name:e.name,type:e.type}).catch(()=>{}),g(t=>[e.name,...t.filter(t=>t!==e.name)].slice(0,5)))},[F]),wt=(0,Q.useCallback)(()=>{u(!1),f(``)},[]),Tt=(0,Q.useCallback)(()=>P(null),[]),Et=(0,Q.useCallback)(e=>{le(e)},[]),Dt=(0,Q.useCallback)(e=>{P([e.path]),le(null)},[]),Ot=(0,Q.useCallback)((e,t)=>{b(e),S(t)},[]),kt=(0,Q.useCallback)(e=>{ee(e),b(!1),S(``),setTimeout(()=>ee(null),50)},[]),jt=(0,Q.useCallback)(()=>{b(!1),S(``)},[]);return(0,$.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,Q.useCallback)(e=>{e.preventDefault(),ue.current++,(e.dataTransfer.types.includes(`application/x-ppm-path`)||e.dataTransfer.types.includes(`Files`))&&j(!0)},[]),onDragLeave:(0,Q.useCallback)(e=>{e.preventDefault(),ue.current--,ue.current===0&&j(!1)},[]),onDragOver:(0,Q.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,Q.useCallback)(e=>{e.preventDefault(),ue.current=0,j(!1);let t=e.dataTransfer.getData(`application/x-ppm-path`);if(t){P([t]);return}let n=Array.from(e.dataTransfer.files);n.length>0&&(M(n),setTimeout(()=>M(null),100))},[]),children:[ie&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm border-2 border-dashed border-primary rounded-lg pointer-events-none`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-primary`,children:[(0,$.jsx)(X,{className:`size-8`}),(0,$.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),be&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/60 backdrop-blur-sm`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(w,{className:`size-4 animate-spin`}),(0,$.jsx)(`span`,{children:`Reconnecting...`})]})}),Xe&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/70 backdrop-blur-sm`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(w,{className:`size-4 animate-spin`}),(0,$.jsx)(`span`,{children:`Creating edited version…`})]})}),(0,$.jsx)(Wr,{shells:Be,onKill:Ve}),(0,$.jsx)(gr,{messages:he,onExpandCompact:ge,isCompactExpanded:U,messagesLoading:_e,keepStaleWhileLoading:et,pendingApproval:J,onApprovalResponse:Me,isStreaming:ve,phase:ye,connectingElapsed:q,statusMessage:Ce,compactStatus:Se,projectName:F,onFork:ve?void 0:st,onEdit:ve?void 0:ct,editingMsgId:Je?.ownMsgId,sessionId:n??void 0,providerId:a,onNavigateVersion:dt,versionMap:K,onSelectSession:ot,onDismissMessage:W,onClearErrors:G,bashPartialOutput:ze}),(0,$.jsx)(Jr,{teamName:Ue,members:We,projectName:F}),(0,$.jsxs)(`div`,{className:`border-t border-border bg-panel shrink-0`,children:[(0,$.jsx)(ha,{projectName:F,usageInfo:fe,usageLoading:L,refreshUsage:z,lastFetchedAt:R,sessionId:n,providerId:a,onSelectSession:ot,onBugReport:n?()=>Ee(de,{sessionId:n,projectName:F}):void 0,isConnected:Ie,onReload:()=>{Ie||Pe(),Fe()},teamActivity:Z,teamMessages:Le,onTeamOpen:Re}),(0,$.jsx)(zi,{items:s,filter:d,onSelect:Ct,onClose:wt,visible:l,recentNames:h,projectName:F}),(0,$.jsx)(Bi,{items:_,filter:x,onSelect:kt,onClose:jt,visible:y}),ce&&(0,$.jsx)(Bi,{items:ce,filter:``,onSelect:Dt,onClose:()=>le(null),visible:!0}),Je&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-1.5 text-xs text-muted-foreground border-t border-border bg-muted/40`,children:[(0,$.jsx)(`span`,{children:`Editing message — your next send replaces it`}),(0,$.jsxs)(`button`,{type:`button`,onClick:lt,className:`flex items-center gap-1 rounded px-2 py-1 min-h-[28px] hover:bg-accent hover:text-accent-foreground transition-colors`,title:`Cancel edit (send as a new message instead)`,children:[(0,$.jsx)(te,{className:`h-3.5 w-3.5`}),`Cancel`]})]}),(rt||!pe)&&(0,$.jsx)(ji,{tabId:t,onSend:_t,isStreaming:ve,onCancel:Ne,autoFocus:!e?.sessionId||!!Ge,initialValue:Ge??B?.content,clearSignal:Qe,projectName:F,onSlashStateChange:St,onSlashItemsLoaded:xt,slashSelected:p,onFileStateChange:Ot,onFileItemsLoaded:v,fileSelected:C,externalFiles:se,externalPaths:N,onExternalPathsConsumed:Tt,onDisambiguate:Et,onContentChange:bt,getUserHistory:yt,permissionMode:D,onModeChange:k,providerId:a,sessionId:n??void 0,onProviderChange:n?void 0:o,model:Te,onModelChange:Y,effort:De,onEffortChange:Oe,thinking:ke,onThinkingChange:Ae})]})]})}export{va as ChatTab};
@@ -1,7 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-CY1epGRc.js","assets/vendor-mermaid-BKWscKt0.js","assets/rolldown-runtime-FhOqtrmT.js","assets/vendor-ui-CaeeFO0B.js","assets/vendor-markdown-Ls5AcU91.js","assets/markdown-renderer-DDcIGQEd.js","assets/index--KWVW-Ga.js","assets/button-BZtEJcUv.js","assets/utils-C9OjCrou.js","assets/createLucideIcon-D8pyde1A.js","assets/arrow-left-CyFcsyzD.js","assets/bot-D6sx11y0.js","assets/check-DN75Ucvz.js","assets/chevron-down-Dp0rpHb8.js","assets/chevron-right-De-Wz5Lz.js","assets/chevron-up-8PbsNiJp.js","assets/circle-BCy0AUCo.js","assets/clock-C1CQUQPZ.js","assets/sparkles-Dh-_J2Rd.js","assets/copy-BewHj66E.js","assets/database-Y3ESDK4-.js","assets/download-DG3_9xXy.js","assets/use-coarse-long-press-BmI_GVW5.js","assets/eye-off-GjXVuAOn.js","assets/eye-gWwaF4Lg.js","assets/loader-circle-DPMrnLQ2.js","assets/monitor-C835ucWH.js","assets/x-YDu4m2Iq.js","assets/api-client-oY1tC3tM.js","assets/react-X4jUntEf.js","assets/window-store-DGKf9rPG.js","assets/window-pip-registry-BEN0QNSW.js","assets/panel-store-BRrnDO_i.js","assets/context-menu-C13b1uT3.js","assets/portal-container-context-a399Hd9F.js","assets/mobile-bottom-sheet-BD5b7KJF.js","assets/use-visual-viewport-rnvuooQZ.js","assets/use-is-mobile-CYW3FJFE.js","assets/project-store-BuY7rxn_.js","assets/ws-auth-Dawx17PM.js","assets/settings-store-Brjd0QnO.js","assets/tab-store-PZsP5ZwG.js","assets/apply-theme-DxTXOAcV.js","assets/resolve-theme-DQk_YcsT.js","assets/index-CvGx7wBQ.css","assets/image-gallery-Cj8nd4xW.js","assets/run-in-terminal-bKRwuO2z.js","assets/csv-preview-BpoJqZQi.js","assets/lib-xrSJ4EZX.js","assets/csv-parser-BPIDt6ni.js","assets/image-preview-DRbZ0FA2.js","assets/file-exclamation-point-JzhTU2TX.js","assets/use-blob-url-Gfi69PtP.js","assets/pdf-preview-CI3q1MnH.js","assets/video-preview-C0uH2228.js","assets/can-open-in-ppm-j3jh7fUo.js","assets/media-url-VzecHk9g.js","assets/audio-preview-CCd1jdje.js","assets/docx-preview-CWIDVNZn.js"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./createLucideIcon-D8pyde1A.js";import{t as i}from"./chevron-right-De-Wz5Lz.js";import{t as a}from"./code-DJgYrFzm.js";import{t as o}from"./database-Y3ESDK4-.js";import{t as s}from"./download-DG3_9xXy.js";import{t as c}from"./eye-gWwaF4Lg.js";import{t as l}from"./file-exclamation-point-JzhTU2TX.js";import{a as u,i as d,o as f,r as p,t as m}from"./glide-data-grid-pKQuyYFj.js";import{t as h}from"./loader-circle-DPMrnLQ2.js";import{t as ee}from"./shield-check-BsG3LV8i.js";import{t as te}from"./shield-off-7jKWpJBD.js";import{t as ne}from"./table-CRJsmfeg.js";import{t as re}from"./text-wrap-oiekm5SB.js";import{t as g}from"./x-YDu4m2Iq.js";import{i as _,n as v}from"./api-client-oY1tC3tM.js";import{q as y}from"./vendor-mermaid-BKWscKt0.js";import{t as ie}from"./settings-store-Brjd0QnO.js";import{t as b}from"./utils-C9OjCrou.js";import"./portal-container-context-a399Hd9F.js";import{t as ae}from"./panel-store-BRrnDO_i.js";import"./window-store-DGKf9rPG.js";import{i as x}from"./project-store-BuY7rxn_.js";import{t as S}from"./tab-store-PZsP5ZwG.js";import{t as C}from"./button-BZtEJcUv.js";import{$t as w,Cr as T,Ft as oe,G as se,Gt as E,It as D,Jt as ce,K as O,Kn as k,Kt as le,Lt as ue,Mn as A,Qt as de,Rt as j,Ut as M,Wt as N,Y as P,Yn as fe,Yt as pe,Zt as me,_r as F,br as he,gn as I,gr as ge,hr as _e,in as ve,nn as ye,o as be,pr as xe,ur as L,xr as R,yr as z}from"./index--KWVW-Ga.js";import"./data-grid-types-CdAg-4W1.js";import{t as Se}from"./use-monaco-theme-BcQqKVbE.js";import{i as Ce,n as we,r as Te,t as Ee}from"./can-open-in-ppm-j3jh7fUo.js";var De=r(`redo-2`,[[`path`,{d:`m15 14 5-5-5-5`,key:`12vg1m`}],[`path`,{d:`M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13`,key:`6uklza`}]]),B=e(t(),1),V=n();function Oe(e){let t=e.startsWith(`/`),n=e.split(/[/\\]/).filter(Boolean),r=e=>{let r=(t?`/`:``)+n.slice(0,e+1).join(`/`);return/^[A-Za-z]:$/.test(r)?r+`/`:r},i=t?`/`:(n[0]??``)+`/`;return n.map((e,t)=>({name:e,absPath:r(t),parentDir:t>0?r(t-1):i}))}async function ke(e){return(await v.get(`/api/fs/browse?path=${encodeURIComponent(e)}`)).entries}function Ae({filePath:e,projectName:t,tabId:n,className:r}){let{updateTab:a,openTab:o}=S(oe(e=>({updateTab:e.updateTab,openTab:e.openTab}))),s=(0,B.useRef)(null),c=(0,B.useMemo)(()=>Oe(e),[e]);(0,B.useEffect)(()=>{s.current&&(s.current.scrollLeft=s.current.scrollWidth)},[c]);let l=(0,B.useCallback)((e,r)=>{let i=b(e),s={filePath:e,projectName:t};r.metaKey||r.ctrlKey?o({type:`editor`,title:i,metadata:s,projectId:t,closable:!0}):a(n,{title:i,metadata:s})},[t,n,o,a]);return(0,V.jsx)(`div`,{ref:s,className:r,children:c.map((e,t)=>(0,V.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,V.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,V.jsx)(je,{segment:e,isLast:t===c.length-1,onFileClick:l})]},e.absPath))})}function je({segment:e,isLast:t,onFileClick:n}){let[r,i]=(0,B.useState)(null),[a,o]=(0,B.useState)(null);function s(t){t&&r===null&&ke(e.parentDir).then(i).catch(e=>{o(e.message||`Failed to browse`),i([])})}return(0,V.jsxs)(D,{onOpenChange:s,children:[(0,V.jsx)(le,{asChild:!0,children:(0,V.jsx)(`button`,{type:`button`,className:`text-xs px-1 py-0.5 rounded hover:bg-muted transition-colors truncate max-w-[120px] ${t?`text-foreground font-medium`:`text-muted-foreground`}`,children:e.name})}),(0,V.jsx)(ue,{align:`start`,className:`max-h-[300px] overflow-y-auto p-1`,children:r===null?(0,V.jsx)(j,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a?(0,V.jsx)(j,{disabled:!0,className:`text-xs text-destructive`,children:a}):r.length===0?(0,V.jsx)(j,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):r.map(t=>(0,V.jsx)(Me,{entry:t,activePath:e.absPath,onFileClick:n},t.path))})]})}function Me({entry:e,activePath:t,onFileClick:n}){let r=H(e.name,e.type===`directory`),i=e.path===t,[a,o]=(0,B.useState)(null);if(e.type===`directory`){function s(t){t&&a===null&&ke(e.path).then(o).catch(()=>o([]))}return(0,V.jsxs)(M,{onOpenChange:s,children:[(0,V.jsxs)(E,{className:`text-xs gap-1.5 ${i?`bg-muted`:``}`,children:[(0,V.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,V.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,V.jsx)(N,{className:`max-h-[300px] overflow-y-auto p-1`,children:a===null?(0,V.jsx)(j,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a.length===0?(0,V.jsx)(j,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):a.map(e=>(0,V.jsx)(Me,{entry:e,activePath:t,onFileClick:n},e.path))})]})}return(0,V.jsxs)(j,{className:`text-xs gap-1.5 cursor-pointer ${i?`bg-muted`:``}`,onClick:t=>n(e.path,t),children:[(0,V.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,V.jsx)(`span`,{className:`truncate`,children:e.name})]})}var Ne={ts:z,tsx:z,js:z,jsx:z,py:z,rs:z,go:z,html:z,css:z,scss:z,json:he,md:F,txt:F,yaml:ge,yml:ge};function H(e,t){return t?xe:Ne[e.split(`.`).pop()?.toLowerCase()??``]??_e}function U(e,t){let n=[],r=e,i=``;for(let e=0;e<t.length;e++){let a=t[e],o=t.slice(0,e+1).join(`/`),s=r.find(e=>e.name===a);if(n.push({name:a,fullPath:o,node:s??null,siblings:r,parentPath:i}),s?.children)i=s.path,r=s.children;else{for(let r=e+1;r<t.length;r++)n.push({name:t[r],fullPath:t.slice(0,r+1).join(`/`),node:null,siblings:[],parentPath:t.slice(0,r).join(`/`)});break}}return n}function Pe(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function Fe({filePath:e,projectName:t,tabId:n,className:r}){let a=I(e=>e.tree),{updateTab:o,openTab:s}=S(oe(e=>({updateTab:e.updateTab,openTab:e.openTab}))),c=x(e=>e.projects.find(e=>e.name===t)?.path??``),l=(0,B.useRef)(null),{prefixParts:u,relativePath:d,isExternal:f}=(0,B.useMemo)(()=>{let t=e.startsWith(`/`)?e.slice(1):e,n=c.startsWith(`/`)?c.slice(1):c;if(n&&t.startsWith(n+`/`)){let e=t.slice(n.length+1);return{prefixParts:n.split(`/`),relativePath:e,isExternal:!1}}return{prefixParts:[],relativePath:t,isExternal:/^(\/|[A-Za-z]:[/\\])/.test(e)}},[e,c]),p=(0,B.useMemo)(()=>U(a,d.split(`/`).filter(Boolean)),[a,d]);(0,B.useEffect)(()=>{l.current&&(l.current.scrollLeft=l.current.scrollWidth)},[p]);function m(e,r){let i=b(e);r.metaKey||r.ctrlKey?s({type:`editor`,title:i,metadata:{filePath:e,projectName:t},projectId:t,closable:!0}):o(n,{title:i,metadata:{filePath:e,projectName:t}})}return f?(0,V.jsx)(Ae,{filePath:e,projectName:t,tabId:n,className:r}):(0,V.jsxs)(`div`,{ref:l,className:r,children:[u.map((e,t)=>(0,V.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,V.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,V.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e})]},`prefix-${t}`)),p.map((e,n)=>(0,V.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[(n>0||u.length>0)&&(0,V.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,V.jsx)(W,{segment:e,isLast:n===p.length-1,projectName:t,onFileClick:m})]},e.fullPath))]})}function W({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=I(e=>e.loadChildren),a=I(e=>e.loadedPaths),o=(0,B.useMemo)(()=>Pe(e.siblings),[e.siblings]),s=a.has(e.parentPath);function c(t){if(t&&!s){let t=e.parentPath.split(`/`).filter(Boolean);(async()=>{for(let e=0;e<=t.length;e++)await i(n,t.slice(0,e).join(`/`))})()}}return(0,V.jsxs)(D,{onOpenChange:c,children:[(0,V.jsx)(le,{asChild:!0,children:(0,V.jsx)(`button`,{type:`button`,className:`text-xs px-1 py-0.5 rounded hover:bg-muted transition-colors truncate max-w-[120px] ${t?`text-foreground font-medium`:`text-muted-foreground`}`,children:e.name})}),(0,V.jsx)(ue,{align:`start`,className:`max-h-[300px] p-1`,children:o.length===0?(0,V.jsx)(j,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):o.map(t=>(0,V.jsx)(G,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function G({node:e,projectName:t,activePath:n,onFileClick:r}){let i=H(e.name,e.type===`directory`),a=e.path===n,o=I(e=>e.loadChildren),s=I(e=>e.loadedPaths);if(e.type===`directory`){let c=e.children??[],l=s.has(e.path);function u(n){n&&!l&&o(t,e.path)}return(0,V.jsxs)(M,{onOpenChange:u,children:[(0,V.jsxs)(E,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,V.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,V.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,V.jsx)(N,{className:`max-h-[300px] overflow-y-auto p-1`,children:c.length===0?(0,V.jsx)(j,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):Pe(c).map(e=>(0,V.jsx)(G,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]})}return(0,V.jsxs)(j,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{r(e.path,t)},children:[(0,V.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,V.jsx)(`span`,{className:`truncate`,children:e.name})]})}function K({active:e,onClick:t,icon:n,label:r}){return(0,V.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,V.jsx)(n,{className:`size-3`}),(0,V.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function Ie({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:i,wordWrap:o,onToggleWordWrap:l,onRefresh:u,refreshing:d,filePath:f,projectName:p,className:m}){return(0,V.jsxs)(`div`,{className:m,children:[(e===`md`||e===`mdx`)&&n&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(K,{active:t===`edit`,onClick:()=>n(`edit`),icon:a,label:`Edit`}),(0,V.jsx)(K,{active:t===`preview`,onClick:()=>n(`preview`),icon:c,label:`Preview`})]}),e===`csv`&&i&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(K,{active:r===`table`,onClick:()=>i(`table`),icon:ne,label:`Table`}),(0,V.jsx)(K,{active:r===`raw`,onClick:()=>i(`raw`),icon:a,label:`Raw`})]}),(0,V.jsx)(K,{active:o,onClick:l,icon:re,label:`Wrap`}),u&&(0,V.jsxs)(`button`,{type:`button`,onClick:u,disabled:d,title:`Reload file from disk`,className:`flex items-center gap-1 px-2 py-1 rounded text-xs text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,children:[(0,V.jsx)(k,{className:`size-3 ${d?`animate-spin`:``}`}),(0,V.jsx)(`span`,{className:`hidden sm:inline`,children:`Refresh`})]}),f&&p&&(0,V.jsx)(K,{active:!1,onClick:()=>ye(p,f),icon:s,label:`Download`})]})}var Le=[{id:`plaintext`,label:`Plain Text`},{id:`javascript`,label:`JavaScript`},{id:`typescript`,label:`TypeScript`},{id:`sql`,label:`SQL`},{id:`json`,label:`JSON`},{id:`xml`,label:`XML`},{id:`html`,label:`HTML`},{id:`css`,label:`CSS`},{id:`python`,label:`Python`},{id:`markdown`,label:`Markdown`},{id:`yaml`,label:`YAML`},{id:`shell`,label:`Shell`}];function Re({value:e,onChange:t}){return(0,V.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1 px-2 border-l border-border`,children:[(0,V.jsx)(z,{className:`size-3 text-muted-foreground`}),(0,V.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-5 text-[10px] bg-transparent border border-border rounded px-1 text-foreground outline-none max-w-[120px]`,title:`Select editor language`,children:Le.map(e=>(0,V.jsx)(`option`,{value:e.id,children:e.label},e.id))})]})}function ze({open:e,defaultName:t,content:n,onSave:r,onCancel:i}){let[a,o]=(0,B.useState)(t),[s,c]=(0,B.useState)(!1),[l,u]=(0,B.useState)(``),d=x(e=>e.activeProject),f=(0,B.useCallback)(()=>{let e=a.trim();if(!e){u(`Filename cannot be empty`);return}if(/[/\\]/.test(e)){u(`Filename cannot contain / or \\`);return}u(``),c(!0)},[a]),p=(0,B.useCallback)(e=>{let t=e.includes(`\\`)?`\\`:`/`;r(e.endsWith(t)?`${e}${a.trim()}`:`${e}${t}${a.trim()}`,n)},[a,n,r]);return s?(0,V.jsx)(O,{open:!0,mode:`folder`,root:d?.path,title:`Save "${a.trim()}" to...`,onSelect:p,onCancel:()=>c(!1)}):(0,V.jsx)(ce,{open:e,onOpenChange:e=>{e||i()},children:(0,V.jsxs)(pe,{className:`sm:max-w-md`,children:[(0,V.jsx)(de,{children:(0,V.jsx)(w,{children:`Save As`})}),(0,V.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,V.jsx)(`label`,{className:`text-sm text-muted-foreground`,children:`Filename`}),(0,V.jsx)(P,{value:a,onChange:e=>{o(e.target.value),u(``)},onKeyDown:e=>{e.key===`Enter`&&f()},placeholder:`e.g. my-file.ts`,autoFocus:!0}),l&&(0,V.jsx)(`p`,{className:`text-xs text-destructive`,children:l})]}),(0,V.jsxs)(me,{children:[(0,V.jsx)(C,{variant:`outline`,onClick:i,children:`Cancel`}),(0,V.jsx)(C,{onClick:f,children:`Choose Folder...`})]})]})})}var q=typeof window<`u`&&window.isSecureContext,Be=[`(`,`)`,`{`,`}`,`[`,`]`,`<`,`>`,`;`,`:`,`=`,`"`,`'`,"`",`/`,`\\`,`_`,`#`],Ve=`px-2 py-1.5 rounded text-xs min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,He=`px-3 py-1.5 rounded text-xs font-mono min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,Ue=`w-px h-5 bg-border mx-0.5 shrink-0`;function We({editorRef:e,readOnly:t}){let n=(0,B.useCallback)(()=>e.current,[e]),r=(0,B.useCallback)(e=>{let t=n();if(!t)return;t.focus();let r=t.getSelection();r&&t.executeEdits(`mobile-toolbar`,[{range:r,text:e}])},[n]),[i,a]=(0,B.useState)(!1),o=(0,B.useRef)(null),s=(0,B.useCallback)(async()=>{try{let e=await navigator.clipboard.readText();e&&r(e)}catch{}},[r]),c=(0,B.useCallback)(()=>{a(!0),requestAnimationFrame(()=>o.current?.focus())},[]),l=(0,B.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData(`text/plain`);t&&(a(!1),r(t))},[r]),u=(0,B.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`undo`,null))},[n]),d=(0,B.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`redo`,null))},[n]),f=(0,B.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`tab`,null))},[n]);return t?null:(0,V.jsxs)(`div`,{className:`shrink-0 border-t border-border bg-surface`,children:[!q&&i&&(0,V.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 border-b border-border bg-muted/50`,children:[(0,V.jsx)(`textarea`,{ref:o,onPaste:l,placeholder:`Long-press here → Paste`,className:`flex-1 h-8 rounded border border-border bg-background text-foreground text-xs px-2 py-1.5 resize-none focus:outline-none focus:ring-1 focus:ring-primary`}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`p-1.5 rounded text-muted-foreground active:bg-muted transition-colors`,children:(0,V.jsx)(g,{size:14})})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1.5 overflow-x-auto`,children:[(0,V.jsx)(`button`,{type:`button`,onClick:q?s:c,className:Ve,title:`Paste`,children:(0,V.jsx)(T,{size:14})}),(0,V.jsx)(`button`,{type:`button`,onClick:u,className:Ve,title:`Undo`,children:(0,V.jsx)(A,{size:14})}),(0,V.jsx)(`button`,{type:`button`,onClick:d,className:Ve,title:`Redo`,children:(0,V.jsx)(De,{size:14})}),(0,V.jsx)(`div`,{className:Ue}),(0,V.jsx)(`button`,{type:`button`,onClick:f,className:He,children:`Tab`}),(0,V.jsx)(`div`,{className:Ue}),Be.map(e=>(0,V.jsx)(`button`,{type:`button`,onClick:()=>r(e),className:He,children:e},e))]})]})}var J=(0,B.lazy)(()=>y(()=>import(`./markdown-renderer-CY1epGRc.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46]))),Ge=(0,B.lazy)(()=>y(()=>import(`./csv-preview-BpoJqZQi.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([47,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,48,49]))),Ke=(0,B.lazy)(()=>y(()=>import(`./image-preview-DRbZ0FA2.js`).then(e=>({default:e.ImagePreview})),__vite__mapDeps([50,3,2,4,51,9,25,28,52]))),qe=(0,B.lazy)(()=>y(()=>import(`./pdf-preview-CI3q1MnH.js`).then(e=>({default:e.PdfPreview})),__vite__mapDeps([53,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,51]))),Je=(0,B.lazy)(()=>y(()=>import(`./video-preview-C0uH2228.js`).then(e=>({default:e.VideoPreview})),__vite__mapDeps([54,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,51,55,56]))),Ye=(0,B.lazy)(()=>y(()=>import(`./audio-preview-CCd1jdje.js`).then(e=>({default:e.AudioPreview})),__vite__mapDeps([57,2,3,4,8,9,51,28,56]))),Xe=(0,B.lazy)(()=>y(()=>import(`./docx-preview-CWIDVNZn.js`).then(e=>({default:e.DocxPreview})),__vite__mapDeps([58,2,3,4,51,9,25,28])));function Ze(e){return e.split(`.`).pop()?.toLowerCase()??``}function Qe(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`,sql:`sql`}[Ze(e)]??`plaintext`}var $e=(0,B.memo)(function({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,i=e?.inlineContent,a=e?.inlineLanguage,[s,c]=(0,B.useState)(i??null),[m,ne]=(0,B.useState)(`utf-8`),[re,g]=(0,B.useState)(!0),[y,x]=(0,B.useState)(null),[C,w]=(0,B.useState)(!1),T=(0,B.useRef)(null),E=(0,B.useRef)(``),D=(0,B.useRef)(null),{tabs:ce,updateTab:O}=S(oe(e=>({tabs:e.tabs,updateTab:e.updateTab}))),{wordWrap:k,toggleWordWrap:le}=ie(oe(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),ue=Se(),A=e?.isUntitled===!0,de=e?.unsavedContent,[j,M]=(0,B.useState)(!1),N=ce.find(e=>e.id===t),P=n?Ze(n):``,pe=we.has(P),me=P===`pdf`,F=P===`docx`,he=Ce.has(P),I=Ee.has(P),ge=Te.has(P),_e=P===`md`||P===`mdx`,ye=P===`csv`,xe=e?.language,L=a??xe??Qe(n??``),R=L===`sql`,[z,De]=(0,B.useState)(`preview`),[Oe,ke]=(0,B.useState)(`table`),{connections:Ae,cachedTables:je,refreshTables:Me,updateConnection:Ne}=se(),H=n?`ppm:sql-conn:${n}`:t?`ppm:sql-conn:tab:${t}`:null,[U,Pe]=(0,B.useState)(()=>{if(!H)return null;let e=localStorage.getItem(H);return e?Number(e):null}),W=(0,B.useRef)(null),G=(0,B.useRef)(null),K=(0,B.useMemo)(()=>Ae.find(e=>e.id===U)??null,[Ae,U]),Le=i!=null&&(a===`json`||a===`xml`),[q,Be]=(0,B.useState)(!1),Ve=(0,B.useCallback)(()=>{if(i)if(q)c(i),Be(!1);else{let e=i.trimStart();if(a===`json`)try{c(JSON.stringify(JSON.parse(e),null,2)),Be(!0)}catch{}else if(a===`xml`){let t=0;c(e.replace(/(>)(<)(\/*)/g,`$1
3
- $2$3`).split(`
4
- `).map(e=>{let n=e.trim();n.startsWith(`</`)&&(t=Math.max(0,t-1));let r=` `.repeat(t)+n;return n.startsWith(`<`)&&!n.startsWith(`</`)&&!n.endsWith(`/>`)&&!n.includes(`</`)&&t++,r}).join(`
5
- `)),Be(!0)}}},[i,a,q]),He=(0,B.useCallback)(e=>{Pe(e),H&&localStorage.setItem(H,String(e)),Me(e).catch(()=>{})},[H,Me]),Ue=(0,B.useCallback)(n=>{t&&O(t,{metadata:{...e,language:n}})},[t,e,O]),J=(0,B.useMemo)(()=>{if(!R||!U)return;let e=(je.get(U)??[]).map(e=>({name:e.tableName,schema:e.schemaName}));if(e.length!==0)return{tables:e,getColumns:async(e,t)=>v.get(`/api/db/connections/${U}/schema?table=${encodeURIComponent(e)}${t?`&schema=${encodeURIComponent(t)}`:``}`)}},[R,U,je]);(0,B.useEffect)(()=>{if(!(!W.current||!J))return G.current?.dispose(),p(),G.current=W.current.languages.registerCompletionItemProvider(`sql`,d(W.current,J)),()=>{G.current?.dispose()}},[J]);let $e=S(e=>e.openTab),[Y,nt]=(0,B.useState)(null),[rt,it]=(0,B.useState)(null),[at,ot]=(0,B.useState)(!1),[st,ct]=(0,B.useState)(``),lt=(0,B.useCallback)(async e=>{if(K){ot(!0),it(null),ct(e);try{nt(await v.post(`/api/db/connections/${K.id}/query`,{sql:e}))}catch(e){it(e.message),nt(null)}finally{ot(!1)}}},[K]),ut=(0,B.useCallback)(()=>{!K||!st||$e({type:`database`,title:`${K.name} · Query`,projectId:null,closable:!0,metadata:{connectionId:K.id,connectionName:K.name,dbType:K.type,initialSql:st}})},[K,$e,st]),dt=(0,B.useCallback)(()=>{if(!D.current||!K)return;let e=D.current,t=e.getSelection();lt(t&&!t.isEmpty()?e.getModel()?.getValueInRange(t)??e.getValue():e.getValue())},[K,lt]),ft=typeof window<`u`&&`ontouchstart`in window,pt=(0,B.useRef)(null),[mt,ht]=(0,B.useState)(null);(0,B.useEffect)(()=>{if(!ft)return;let e=window.visualViewport;if(!e)return;let t=()=>{let t=pt.current;if(!t)return;let n=t.getBoundingClientRect().top;ht(e.height-Math.max(0,n))};return e.addEventListener(`resize`,t),e.addEventListener(`scroll`,t),()=>{e.removeEventListener(`resize`,t),e.removeEventListener(`scroll`,t)}},[ft]),(0,B.useEffect)(()=>ve(pt.current,()=>D.current?.layout()),[re,y]);let Z=(0,B.useRef)([]),gt=(0,B.useRef)(lt);gt.current=lt,(0,B.useEffect)(()=>()=>{Z.current.forEach(e=>e.dispose()),Z.current=[]},[]),(0,B.useEffect)(()=>{ge&&t&&O(t,{type:`sqlite`})},[ge,t,O]);let Q=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,B.useEffect)(()=>{if(i!=null){g(!1);return}if(A){c(de??``),E.current=de??``,g(!1),de&&w(!0);return}if(!n||!Q&&!r)return;if(pe||me||F||he||I){g(!1);return}g(!0),x(null);let e=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${_(r)}/files/read?path=${encodeURIComponent(n)}`;return v.get(e).then(e=>{c(e.content),e.encoding&&ne(e.encoding),E.current=e.content,g(!1)}).catch(e=>{x(e instanceof Error?e.message:`Failed to load file`),g(!1)}),()=>{T.current&&clearTimeout(T.current)}},[n,r,pe,me,F,Q,A]);let[_t,vt]=(0,B.useState)(!1),yt=(0,B.useCallback)(()=>{if(!n||i!=null||A||!Q&&!r)return;let e=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${_(r)}/files/read?path=${encodeURIComponent(n)}`;vt(!0),v.get(e).then(e=>{c(e.content),E.current=e.content,e.encoding&&ne(e.encoding),w(!1),x(null)}).catch(e=>x(e instanceof Error?e.message:`Failed to reload file`)).finally(()=>vt(!1))},[n,r,Q,i,A]),bt=(0,B.useRef)(C);bt.current=C,(0,B.useEffect)(()=>{if(!n||!r||i!=null||A)return;let e=e=>{let t=e.detail;if(t.projectName!==r||t.path!==n||bt.current)return;let i=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${_(r)}/files/read?path=${encodeURIComponent(n)}`;v.get(i).then(e=>{e.content!==E.current&&(c(e.content),E.current=e.content,e.encoding&&ne(e.encoding))}).catch(()=>{})};return window.addEventListener(`file:changed`,e),()=>window.removeEventListener(`file:changed`,e)},[n,r,Q,i,A]),(0,B.useEffect)(()=>{if(!N||i!=null)return;let t=A?`Untitled-${e?.untitledNumber??1}`:n?b(n):`Untitled`,r=C?`${t} \u25CF`:t;N.title!==r&&O(N.id,{title:r})},[C]);let xt=(0,B.useCallback)(async e=>{if(n&&!(!Q&&!r))try{Q?await v.put(`/api/fs/write`,{path:n,content:e}):await v.put(`${_(r)}/files/write`,{path:n,content:e}),w(!1)}catch{}},[n,r,Q]);function St(n){let r=n??``;c(r),E.current=r,w(!0),T.current&&clearTimeout(T.current),A?T.current=setTimeout(()=>{t&&O(t,{metadata:{...e,unsavedContent:E.current}})},2e3):T.current=setTimeout(()=>xt(E.current),1e3)}let Ct=(0,B.useCallback)(async(e,n)=>{try{if(T.current&&clearTimeout(T.current),await v.put(`/api/fs/write`,{path:e,content:n}),t){let{closeTab:n,openTab:r}=ae.getState();n(t),r({type:`editor`,title:b(e),projectId:null,metadata:{filePath:e},closable:!0})}w(!1),M(!1)}catch{}},[t]),$=e?.lineNumber,wt=e?.endLine,Tt=e?.revealAt,Et=(0,B.useCallback)(()=>{let e=D.current;if(!(!e||!$||$<=0)){if(e.revealLineInCenter($),e.setPosition({lineNumber:$,column:1}),wt&&wt>=$){let t=e.getModel(),n=t?.getLineCount()??$,r=Math.min(wt,n),i=t?.getLineMaxColumn(r)??1;e.setSelection({startLineNumber:$,startColumn:1,endLineNumber:r,endColumn:i})}e.focus()}},[$,wt]);(0,B.useEffect)(()=>{Tt!=null&&Et()},[Tt,Et]);let Dt=(0,B.useCallback)((e,t)=>{if(D.current=e,W.current=t,$&&$>0&&setTimeout(()=>Et(),100),A&&e.addCommand(t.KeyMod.CtrlCmd|t.KeyCode.KeyS,()=>M(!0)),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>ie.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),J&&(G.current?.dispose(),G.current=t.languages.registerCompletionItemProvider(`sql`,d(t,J))),R){e.addAction({id:`run-sql-at-cursor`,label:`Run Statement at Cursor`,keybindings:[t.KeyMod.CtrlCmd|t.KeyCode.Enter],run:e=>{let t=e.getPosition();if(!t)return;let n=u(e.getValue(),t.lineNumber);n&&gt.current(n)}}),Z.current.forEach(e=>e.dispose()),Z.current=[];let n=e.getModel(),r=e.addCommand(0,(e,t)=>{t&&gt.current(t)});if(r&&n){let e=t.languages.registerCodeLensProvider(`sql`,{provideCodeLenses:e=>{if(e!==n)return{lenses:[],dispose:()=>{}};let t=[],i=(e,n,i=`▷ Run`)=>{let a=n.trim();a&&t.push({range:{startLineNumber:e,startColumn:1,endLineNumber:e,endColumn:1},command:{id:r,title:i,arguments:[a]}})},a=/^(BEGIN|COMMIT|ROLLBACK|END)(;|\s|$)/i,o=-1,s=[];for(let{sql:t,startLine:n}of f(e.getValue())){let e=/^BEGIN(;|\s|$)/i.test(t),r=/^(COMMIT|ROLLBACK|END)(;|\s|$)/i.test(t);o===-1&&e?(o=n,s=[t]):o>-1?(s.push(t),!r&&!a.test(t)&&i(n,t),r&&(i(o,s.join(`
6
- `),`▷ Run Transaction`),o=-1,s=[])):i(n,t)}return o>-1&&s.length>1&&i(o,s.join(`
7
- `),`▷ Run Transaction`),{lenses:t,dispose:()=>{}}}});Z.current.push(e);let i=t.languages.registerFoldingRangeProvider(`sql`,{provideFoldingRanges:e=>{if(e!==n)return[];let r=[],i=e.getLineCount(),a=[];for(let n=1;n<=i;n++){let i=e.getLineContent(n).trim();if(/^BEGIN(;|\s|$)/i.test(i))a.push(n);else if(/^(COMMIT|ROLLBACK|END)(;|\s|$)/i.test(i)&&a.length>0){let e=a.pop();r.push({start:e,end:n,kind:t.languages.FoldingRangeKind.Region})}}return r}});Z.current.push(i)}}},[J,R]);if(!i&&!A&&(!n||!Q&&!r))return(0,V.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`});if(re)return(0,V.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,V.jsx)(h,{className:`size-5 animate-spin`}),(0,V.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]});if(y)return(0,V.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:y});if(pe)return(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(X,{}),children:(0,V.jsx)(Ke,{filePath:n,projectName:r})});if(me)return(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(X,{}),children:(0,V.jsx)(qe,{filePath:n,projectName:r})});if(F)return(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(X,{}),children:(0,V.jsx)(Xe,{filePath:n,projectName:r})});if(he)return(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(X,{}),children:(0,V.jsx)(Je,{filePath:n,projectName:r})});if(I)return(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(X,{}),children:(0,V.jsx)(Ye,{filePath:n,projectName:r})});if(m===`base64`)return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,V.jsx)(l,{className:`size-10 text-text-subtle`}),(0,V.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,V.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]});let Ot=R?(0,V.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1 px-2 border-l border-border`,children:[(0,V.jsx)(o,{className:`size-3 text-muted-foreground`}),(0,V.jsxs)(`select`,{value:U??``,onChange:e=>{let t=Number(e.target.value);t&&He(t)},className:`h-5 text-[10px] bg-transparent border border-border rounded px-1 text-foreground outline-none max-w-[140px]`,title:`Select connection for autocomplete`,children:[(0,V.jsx)(`option`,{value:``,children:`Connection…`}),Ae.map(e=>(0,V.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,V.jsx)(`button`,{type:`button`,onClick:dt,disabled:!K,className:`p-0.5 rounded text-muted-foreground hover:text-primary disabled:opacity-30 transition-colors`,title:`Run SQL`,children:(0,V.jsx)(fe,{className:`size-3.5`})}),K&&(0,V.jsx)(`button`,{type:`button`,onClick:()=>Ne(K.id,{readonly:K.readonly?0:1}),className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[10px] transition-colors ${K.readonly?`text-muted-foreground hover:text-foreground`:`bg-destructive/15 text-destructive`}`,title:K.readonly?`Readonly — click to allow writes`:`WRITE mode — click to enable readonly`,children:K.readonly?(0,V.jsx)(ee,{className:`size-3`}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(te,{className:`size-3`}),(0,V.jsx)(`span`,{className:`font-medium`,children:`WRITE`})]})})]}):null;return(0,V.jsxs)(`div`,{ref:pt,className:`flex flex-col h-full w-full overflow-hidden`,style:mt?{height:`${mt}px`,maxHeight:`${mt}px`}:void 0,children:[i!=null&&Le&&(0,V.jsx)(`div`,{className:`flex items-center h-7 border-b border-border bg-background shrink-0 px-2 gap-2`,children:(0,V.jsx)(`button`,{type:`button`,onClick:Ve,className:`text-[10px] px-2 py-0.5 rounded border border-border hover:bg-muted transition-colors text-foreground`,children:q?`Raw`:`Beautify`})}),n&&r&&t&&(0,V.jsxs)(`div`,{className:`hidden md:flex items-center h-7 border-b border-border bg-background shrink-0`,children:[(0,V.jsx)(Fe,{filePath:n,projectName:r,tabId:t,className:`flex items-center flex-1 min-w-0 overflow-x-auto scrollbar-none px-2 gap-0.5`}),(0,V.jsx)(Re,{value:L,onChange:Ue}),Ot,(0,V.jsx)(Ie,{ext:P,mdMode:z,onMdModeChange:De,csvMode:Oe,onCsvModeChange:ke,wordWrap:k,onToggleWordWrap:le,onRefresh:yt,refreshing:_t,filePath:n,projectName:r,className:`shrink-0 flex items-center gap-1 px-2`})]}),i==null&&t&&(A||n&&!r)&&(0,V.jsxs)(`div`,{className:`hidden md:flex items-center h-7 border-b border-border bg-background shrink-0 px-2`,children:[(0,V.jsx)(`span`,{className:`text-xs text-muted-foreground truncate flex-1`,children:A?`Untitled-${e?.untitledNumber??1}`:n?b(n):`Untitled`}),(0,V.jsx)(Re,{value:L,onChange:Ue}),Ot]}),ye&&Oe===`table`?(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,V.jsx)(h,{className:`size-5 animate-spin text-text-subtle`})}),children:(0,V.jsx)(Ge,{content:s??``,onContentChange:St,wordWrap:k})}):_e&&z===`preview`?(0,V.jsx)(tt,{content:s??``}):(0,V.jsx)(`div`,{className:`flex-1 overflow-hidden min-h-0`,children:(0,V.jsx)(be,{height:`100%`,language:L,value:s??``,onChange:i==null?St:void 0,onMount:Dt,theme:ue,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:k?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0},readOnly:i!=null},loading:(0,V.jsx)(h,{className:`size-5 animate-spin text-text-subtle`})},L)}),R&&(Y||rt||at)&&(0,V.jsx)(et,{result:Y,error:rt,loading:at,connName:K?.name,onClose:()=>{nt(null),it(null),ot(!1)},onOpenInTab:ut}),ft&&(0,V.jsx)(We,{editorRef:D,readOnly:i!=null}),j&&(0,V.jsx)(ze,{open:j,defaultName:`Untitled-${e?.untitledNumber??1}`,content:E.current,onSave:Ct,onCancel:()=>M(!1)})]})}),Y=()=>{};function et({result:e,error:t,loading:n,connName:r,onClose:i,onOpenInTab:a}){let s=(0,B.useMemo)(()=>e?.changeType===`select`&&e.rows.length>0?{columns:e.columns,rows:e.rows,total:e.rows.length,limit:e.rows.length}:null,[e]),c=(0,B.useMemo)(()=>(e?.columns??[]).map(e=>({name:e,type:`text`,nullable:!0,pk:!1,defaultValue:null})),[e?.columns]),[l,u]=(0,B.useState)(250),d=(0,B.useCallback)(e=>{e.preventDefault();let t=e.clientY,n=l,r=e.currentTarget.ownerDocument,i=e=>u(Math.max(80,n+(t-e.clientY))),a=()=>{r.removeEventListener(`mousemove`,i),r.removeEventListener(`mouseup`,a)};r.addEventListener(`mousemove`,i),r.addEventListener(`mouseup`,a)},[l]);return(0,V.jsxs)(`div`,{className:`shrink-0 border-t border-border flex flex-col`,style:{height:l},children:[(0,V.jsx)(`div`,{onMouseDown:d,className:`shrink-0 h-1.5 cursor-row-resize bg-border/50 hover:bg-primary/30 flex items-center justify-center transition-colors`,children:(0,V.jsx)(L,{className:`size-3 text-muted-foreground/50`})}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1 bg-muted/50 border-b border-border shrink-0`,children:[(0,V.jsx)(o,{className:`size-3 text-muted-foreground`}),(0,V.jsxs)(`span`,{className:`text-xs font-medium text-foreground truncate flex-1`,children:[r?`${r} · Results`:`Query Results`,e?.executionTimeMs!=null&&(0,V.jsxs)(`span`,{className:`text-muted-foreground ml-1.5 font-normal`,children:[e.executionTimeMs,`ms`]})]}),(0,V.jsxs)(`button`,{type:`button`,onClick:a,title:`Open in DB Viewer tab`,className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:[(0,V.jsx)(R,{className:`size-3`}),(0,V.jsx)(`span`,{className:`hidden sm:inline`,children:`Open in Tab`})]}),(0,V.jsx)(`button`,{type:`button`,onClick:i,title:`Close results`,className:`p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,V.jsx)(g,{className:`size-3`})})]}),(0,V.jsxs)(`div`,{className:`flex-1 overflow-hidden min-h-0`,children:[n&&(0,V.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,V.jsx)(h,{className:`size-4 animate-spin text-muted-foreground`})}),t&&(0,V.jsx)(`div`,{className:`px-3 py-2 text-xs text-destructive bg-destructive/5`,children:t}),e?.changeType===`modify`&&(0,V.jsxs)(`div`,{className:`px-3 py-2 text-xs text-success`,children:[e.rowsAffected,` row(s) affected`]}),s&&(0,V.jsx)(m,{columns:s.columns,rows:s.rows,total:s.total,limit:s.limit,schema:c,loading:!1,page:1,onPageChange:Y,onCellUpdate:Y,readOnly:!0,orderBy:null,orderDir:`ASC`,onToggleSort:Y,connectionName:r}),e?.changeType===`select`&&e.rows.length===0&&(0,V.jsx)(`div`,{className:`px-3 py-2 text-xs text-muted-foreground`,children:`No results`})]})]})}function X(){return(0,V.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,V.jsx)(h,{className:`size-5 animate-spin text-text-subtle`})})}function tt({content:e}){return(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(`div`,{className:`animate-pulse h-4 bg-muted rounded m-4`}),children:(0,V.jsx)(J,{content:e,className:`flex-1 overflow-auto p-4`})})}export{$e as CodeEditor};