@hienlh/ppm 0.22.0 → 0.22.1

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 +9 -0
  2. package/CLAUDE.md +1 -1
  3. package/assets/skills/ppm/SKILL.md +1 -1
  4. package/assets/skills/ppm/references/cli-reference.md +4 -4
  5. package/assets/skills/ppm/references/http-api.md +1 -1
  6. package/dist/web/assets/accounts-settings-section-D3BylchP.js +1 -0
  7. package/dist/web/assets/{ai-resource-editor-CdDpOwjh.js → ai-resource-editor-BLPcnhTM.js} +1 -1
  8. package/dist/web/assets/{ai-settings-section-X2UOfSaS.js → ai-settings-section-BtR7rF-T.js} +1 -1
  9. package/dist/web/assets/{ai-settings-section-B1hQyjAd.js → ai-settings-section-r9JctHNM.js} +1 -1
  10. package/dist/web/assets/{appearance-settings-section-DLoPK0LD.js → appearance-settings-section-CiMdk3sb.js} +1 -1
  11. package/dist/web/assets/{branch-review-tab-G84Ojzae.js → branch-review-tab-B1pFjlKM.js} +1 -1
  12. package/dist/web/assets/chat-tab-DZagX06m.js +15 -0
  13. package/dist/web/assets/{code-editor-D04iUPsZ.js → code-editor-BJhOEsnZ.js} +4 -4
  14. package/dist/web/assets/{codex-daily-guard-BSccLRGT.js → codex-daily-guard-CaCQJ4r_.js} +1 -1
  15. package/dist/web/assets/{conflict-editor-C4ay676e.js → conflict-editor-B7u_p49h.js} +3 -3
  16. package/dist/web/assets/{csv-preview-DbwEmG7o.js → csv-preview-CttjJU1e.js} +1 -1
  17. package/dist/web/assets/{database-viewer-S6LsALjX.js → database-viewer-Ca4HxIfx.js} +1 -1
  18. package/dist/web/assets/{diff-viewer-3oBA7vgQ.js → diff-viewer-9-XjLIwa.js} +1 -1
  19. package/dist/web/assets/{editor-language-service-DJmaKVY0.js → editor-language-service-D0DuEOs_.js} +1 -1
  20. package/dist/web/assets/{explorer-body-BQ0jyAGv.js → explorer-body-VdCBqcZu.js} +2 -2
  21. package/dist/web/assets/{explorer-window-content-jdkWt34J.js → explorer-window-content-BIsbl7Th.js} +1 -1
  22. package/dist/web/assets/extension-manager-section-HkY7geS5.js +1 -0
  23. package/dist/web/assets/{extension-webview-BGSDUbdK.js → extension-webview-DZG8YHX9.js} +1 -1
  24. package/dist/web/assets/{files-settings-section-Gnyd7han.js → files-settings-section-qnRtkX05.js} +1 -1
  25. package/dist/web/assets/{general-settings-section-V6Khh15V.js → general-settings-section-BAFSZmCE.js} +1 -1
  26. package/dist/web/assets/{git-log-panel-Bi513qjT.js → git-log-panel-2sGpfEla.js} +1 -1
  27. package/dist/web/assets/{glide-data-grid-DnQwYSmQ.js → glide-data-grid-f0hyITiF.js} +1 -1
  28. package/dist/web/assets/{group-chat-tab-DpczdwyV.js → group-chat-tab-Ck6sk7yY.js} +1 -1
  29. package/dist/web/assets/index-CEZVxM4G.js +52 -0
  30. package/dist/web/assets/{jira-watcher-section-f2HUbGDY.js → jira-watcher-section-CeLmhvu1.js} +1 -1
  31. package/dist/web/assets/keybindings-store-C_3ChOEf.js +1 -0
  32. package/dist/web/assets/{keyboard-shortcuts-section-BpvVEw_Y.js → keyboard-shortcuts-section-PVz6kuh2.js} +1 -1
  33. package/dist/web/assets/markdown-renderer-C140Ijk0.js +3 -0
  34. package/dist/web/assets/{markdown-renderer-Bcaf9_bA.js → markdown-renderer-Dz7-DYUg.js} +1 -1
  35. package/dist/web/assets/{mobile-explorer-sheet-Bol3XAO1.js → mobile-explorer-sheet-CUG_owdf.js} +1 -1
  36. package/dist/web/assets/notification-store-6vib1ISy.js +1 -0
  37. package/dist/web/assets/{ppmbot-settings-section-DKJUA3Kq.js → ppmbot-settings-section-Cji-Mil-.js} +1 -1
  38. package/dist/web/assets/{problems-panel-CFcoUx8h.js → problems-panel-a6_hrWvl.js} +1 -1
  39. package/dist/web/assets/{process-table-EKr2dqG6.js → process-table-CiIqlOIK.js} +1 -1
  40. package/dist/web/assets/{proxy-settings-section-B7qRVl8w.js → proxy-settings-section-BjI4IFgp.js} +1 -1
  41. package/dist/web/assets/{remote-desktop-clipboard-notice-0WDYsyCA.js → remote-desktop-clipboard-notice-eXYvwgx7.js} +1 -1
  42. package/dist/web/assets/{remote-desktop-mobile-sheet-COYDg16H.js → remote-desktop-mobile-sheet-Doh-fci-.js} +2 -2
  43. package/dist/web/assets/{remote-desktop-mobile-view-2DqSuS2U.js → remote-desktop-mobile-view-Dt8Akc3p.js} +1 -1
  44. package/dist/web/assets/{remote-desktop-readiness-gate-Dm_qMJMH.js → remote-desktop-readiness-gate-t83fqbID.js} +1 -1
  45. package/dist/web/assets/{remote-desktop-window-content-UodhsF7W.js → remote-desktop-window-content-CguhZMmx.js} +1 -1
  46. package/dist/web/assets/{schedules-settings-section-bG2lYfGv.js → schedules-settings-section-BVkpW5ms.js} +1 -1
  47. package/dist/web/assets/{settings-body-C06bFarv.js → settings-body-CoIxYAh6.js} +2 -2
  48. package/dist/web/assets/{settings-tab-34RSaASd.js → settings-tab-7DKVUTbM.js} +1 -1
  49. package/dist/web/assets/{settings-window-content-Dr_2lmHH.js → settings-window-content-3_39TeX-.js} +1 -1
  50. package/dist/web/assets/{sql-query-editor-BgRH0cHD.js → sql-query-editor-CQB7Yp7U.js} +1 -1
  51. package/dist/web/assets/{sqlite-viewer-DUxGslpa.js → sqlite-viewer-Bd7rjr1D.js} +1 -1
  52. package/dist/web/assets/{system-monitor-body-IZuLn7Qh.js → system-monitor-body-DsRXeMyU.js} +2 -2
  53. package/dist/web/assets/{system-monitor-tab-DiSA490Z.js → system-monitor-tab-DdSZgux3.js} +1 -1
  54. package/dist/web/assets/{system-monitor-window-content-CEaFISgj.js → system-monitor-window-content-ClPo4-El.js} +1 -1
  55. package/dist/web/assets/{tab-host-window-content-D0TN8Wrq.js → tab-host-window-content-d2TAD4PU.js} +1 -1
  56. package/dist/web/assets/{team-member-sheet-DDPNcCjd.js → team-member-sheet-7d2Qp-ie.js} +2 -2
  57. package/dist/web/assets/{team-member-window-content-DCiW_1-E.js → team-member-window-content-Bctg2gmg.js} +1 -1
  58. package/dist/web/assets/{terminal-tab-4ypP0NDY.js → terminal-tab-0HQic25V.js} +3 -3
  59. package/dist/web/assets/{tool-cards-Dd6E7Q3k.js → tool-cards-CmLLRACd.js} +2 -2
  60. package/dist/web/assets/{use-inline-blame-vrfFHuaR.js → use-inline-blame-sDMjcz1-.js} +3 -3
  61. package/dist/web/assets/{use-lsp-CsuZu49X.js → use-lsp-CBgID-EU.js} +1 -1
  62. package/dist/web/assets/{use-monaco-theme-BIVYJBIn.js → use-monaco-theme-gvhJ_jZh.js} +1 -1
  63. package/dist/web/assets/{use-websocket-BMbufhX7.js → use-websocket-C9wlRliB.js} +1 -1
  64. package/dist/web/assets/{video-preview-Byj8P_jA.js → video-preview-CSDK5j6H.js} +1 -1
  65. package/dist/web/index.html +1 -1
  66. package/dist/web/sw.js +1 -1
  67. package/docs/architecture/ai-chat-and-providers.md +9 -0
  68. package/package.json +1 -1
  69. package/packages/ext-git-graph/src/webview-html.test.ts +30 -5
  70. package/packages/ext-git-graph/src/webview-html.ts +99 -31
  71. package/src/services/edge-forwarder.ts +191 -191
  72. package/src/services/windows-process-tree.ts +351 -351
  73. package/src/shared/codex-daily-guard.ts +12 -5
  74. package/src/web/components/extensions/extension-tree-view.tsx +4 -11
  75. package/src/web/components/layout/command-palette.tsx +2 -18
  76. package/src/web/components/settings/accounts/account-card.tsx +2 -2
  77. package/src/web/components/settings/accounts/codex-accounts-section.tsx +4 -4
  78. package/src/web/components/settings/extension-manager-section.tsx +8 -1
  79. package/src/web/lib/extension-icons.ts +70 -0
  80. package/src/web/lib/tab-type-icons.ts +14 -0
  81. package/dist/web/assets/accounts-settings-section-BVr9-FZJ.js +0 -1
  82. package/dist/web/assets/chat-tab-DQJfjm8E.js +0 -15
  83. package/dist/web/assets/extension-manager-section-DG1guILi.js +0 -1
  84. package/dist/web/assets/index-DU68xk06.js +0 -52
  85. package/dist/web/assets/keybindings-store-DCRsnKg5.js +0 -1
  86. package/dist/web/assets/markdown-renderer-DGJp8HC3.js +0 -3
  87. package/dist/web/assets/notification-store-BXt54VIn.js +0 -1
  88. package/packages/vscode-compat/node_modules/.bin/tsc.bunx +0 -0
  89. package/packages/vscode-compat/node_modules/.bin/tsc.exe +0 -0
  90. package/packages/vscode-compat/node_modules/.bin/tsserver.bunx +0 -0
  91. package/packages/vscode-compat/node_modules/.bin/tsserver.exe +0 -0
  92. package/src/web/hooks/use-delayed-flag.ts +0 -35
@@ -1,15 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/edit-diff-preview-BGGGecVw.js","assets/rolldown-runtime-FhOqtrmT.js","assets/vendor-markdown-CuWCHIVb.js","assets/libesm-CPh1Av0r.js","assets/markdown-renderer-Bcaf9_bA.js","assets/vendor-mermaid-BitiXJlL.js","assets/vendor-ui-DmZ-Mb-H.js","assets/markdown-renderer-DGJp8HC3.js","assets/index-DU68xk06.js","assets/button-B9CTrsEf.js","assets/utils-Bmf_8h7Y.js","assets/createLucideIcon-DoiEKeJ_.js","assets/api-client-C1ZwRL4Y.js","assets/react-Bghu0NUO.js","assets/settings-store-krC6bc79.js","assets/file-store-ojgMXgAw.js","assets/window-store-UC1jJeLM.js","assets/window-pip-registry-yD6esSju.js","assets/panel-store-CboGJAwh.js","assets/format-file-meta-C77h04cZ.js","assets/context-menu-C6pIsf83.js","assets/portal-container-context-BarKmT4S.js","assets/icons-DQjqk0lJ.js","assets/dialog-B84_DJQ8.js","assets/input-C7Q8FxeL.js","assets/mobile-bottom-sheet-C3TniEP-.js","assets/use-visual-viewport-Lp878uzs.js","assets/scroll-area-BzeiOd-B.js","assets/use-is-mobile-TkcwP1Gx.js","assets/file-icons-BXdvggK2.js","assets/project-framework-store-B70Q3dNM.js","assets/git-repo-store-88Z8v-pF.js","assets/project-store-B87hLRSk.js","assets/ws-auth-CEYVQ8NH.js","assets/streaming-store-BYukdB56.js","assets/tab-store-OJa1GPCq.js","assets/apply-theme-CbR31K6I.js","assets/resolve-theme-B_ukrg_8.js","assets/index-BH99TIE0.css","assets/image-gallery-CGvlv8zR.js","assets/run-in-terminal-CdefEe_R.js","assets/api-client-pQL53cDQ.js"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-DmZ-Mb-H.js";import{$n as r,A as i,Bn as a,Br as o,C as s,E as c,Et as l,F as u,G as d,Gt as f,Ht as p,J as m,K as h,N as g,Nr as _,O as ee,On as v,Qn as y,R as b,Rn as te,Rt as x,Sn as S,Sr as C,Tr as w,Un as ne,Vr as T,Wn as re,Wr as E,Wt as ie,Z as ae,_t as D,b as oe,bn as se,br as ce,cn as O,ct as k,d as A,dr as j,dt as le,g as ue,hn as de,ir as M,j as N,kr as P,ln as F,lr as fe,lt as I,mr as pe,n as L,nt as R,pr as me,sn as he,sr as ge,t as z,v as _e,w as B,wr as ve,x as V,xr as H,yn as ye,yr as be,z as xe}from"./icons-DQjqk0lJ.js";import{t as U}from"./createLucideIcon-DoiEKeJ_.js";import{i as W,n as G,r as Se,s as Ce}from"./api-client-C1ZwRL4Y.js";import{t as we}from"./settings-store-krC6bc79.js";import{q as Te}from"./vendor-mermaid-BitiXJlL.js";import{n as K,r as Ee,t as q}from"./utils-Bmf_8h7Y.js";import"./portal-container-context-BarKmT4S.js";import{t as De}from"./panel-store-CboGJAwh.js";import"./window-store-UC1jJeLM.js";import{i as J}from"./project-store-B87hLRSk.js";import"./project-framework-store-B70Q3dNM.js";import{t as Oe}from"./tab-store-OJa1GPCq.js";import"./context-menu-C6pIsf83.js";import{o as ke}from"./file-store-ojgMXgAw.js";import{n as Ae}from"./use-is-mobile-TkcwP1Gx.js";import{n as je}from"./streaming-store-BYukdB56.js";import{t as Me}from"./button-B9CTrsEf.js";import{n as Ne,o as Pe,t as Y}from"./dialog-B84_DJQ8.js";import{t as Fe}from"./mobile-bottom-sheet-C3TniEP-.js";import"./use-visual-viewport-Lp878uzs.js";import"./input-C7Q8FxeL.js";import"./ws-auth-CEYVQ8NH.js";import{Cn as Ie,Ht as Le,Qt as Re,R as ze,Sn as Be,Vt as X,Xt as Ve,bn as He,dn as Ue,fn as Z,hn as We,nn as Ge,pn as Ke,r as qe,t as Je,un as Ye,vt as Xe,w as Ze,wn as Qe,xn as $e,yn as et,zt as tt}from"./index-DU68xk06.js";import{t as nt}from"./use-websocket-BMbufhX7.js";import{getAISettings as rt,pickAccountForTab as it}from"./api-settings-_7Q-ULxp.js";import{n as at,r as ot}from"./tool-cards-Dd6E7Q3k.js";import"./use-blob-url-CPtCcY3i.js";import{n as st,r as ct,t as lt}from"./image-gallery-CGvlv8zR.js";import{t as ut}from"./libesm-CPh1Av0r.js";import{t as dt}from"./use-open-team-member-C3mrUzIC.js";import{n as ft,t as pt}from"./send-to-chat-F207yH3u.js";import{t as mt}from"./ai-settings-section-B1hQyjAd.js";import{d as ht,f as gt,i as _t,l as vt,n as yt,o as bt,r as xt,t as St}from"./codex-daily-guard-BSccLRGT.js";var Ct=U(`slash`,[[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}]]),Q=e(t(),1),wt={maxImages:4,maxBase64PerImage:5e6,maxBase64Total:1e7};function Tt(e){let t=[],n=0;for(let r of e)if(r.imageData){if(t.length>=wt.maxImages)break;r.imageData.data.length>wt.maxBase64PerImage||n+r.imageData.data.length>wt.maxBase64Total||(n+=r.imageData.data.length,t.push(r.imageData))}return t}function Et(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 Dt(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 Ot(e,t){let n=`pc-${Dt(t)}-`;return e.map(e=>e.id?{...e,id:`${n}${e.id}`}:e)}function kt(e,t){if(t.size===0)return e;let n=[],r=new Set,i=e=>{for(let a of e){let e=a.id?t.get(a.id):void 0;e&&e.length>0&&a.id&&!r.has(a.id)&&(r.add(a.id),i(e)),n.push(a)}};return i(e),n}var At=null;function jt(){return At||=new AudioContext,At}function Mt(e,t,n,r,i=`sine`){let a=jt(),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 Nt(){let e=jt().currentTime;Mt(523,.15,e,.15),Mt(659,.2,e+.12,.15)}function Pt(){let e=jt().currentTime;Mt(880,.12,e,.18,`square`),Mt(698,.12,e+.15,.18,`square`),Mt(880,.15,e+.3,.15,`square`)}function Ft(){let e=jt().currentTime;Mt(440,.12,e,.12),Mt(523,.12,e+.1,.12),Mt(659,.18,e+.2,.12)}var It={done:Nt,approval_request:Pt,question:Ft};function Lt(e){try{It[e]?.()}catch{}}var Rt={hasTeams:!1,teamNames:[],messageCount:0,unreadCount:0};function zt(e){if(document.hidden)return!1;let{panels:t}=De.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 Bt(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),[ee,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(null),[te,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)([]),w=(0,Q.useRef)([]),[ne,T]=(0,Q.useState)(null),[re,E]=(0,Q.useState)(null),[ie,ae]=(0,Q.useState)(!1),[D,oe]=(0,Q.useState)(null),[se,ce]=(0,Q.useState)(null),O=(0,Q.useRef)(null),k=(0,Q.useRef)(null),[A,j]=(0,Q.useState)(null),le=(0,Q.useRef)(null),[ue,de]=(0,Q.useState)(!0),M=(0,Q.useRef)(null),N=(0,Q.useRef)(null),P=(0,Q.useRef)(``),F=(0,Q.useRef)([]),fe=(0,Q.useRef)(new Map),I=(0,Q.useRef)(null),[pe,L]=(0,Q.useState)(null),R=(0,Q.useRef)(`idle`),me=(0,Q.useRef)(null),he=(0,Q.useRef)(()=>{}),ge=(0,Q.useRef)(null),z=(0,Q.useRef)(0),_e=(0,Q.useRef)(0),B=(0,Q.useRef)(!1),ve=(0,Q.useRef)(null),V=(0,Q.useRef)([]),H=(0,Q.useRef)(null),ye=(0,Q.useRef)(!1),be=(0,Q.useRef)(new Set),xe=(0,Q.useRef)(0),U=(0,Q.useRef)(null),Se=(0,Q.useRef)(0),we=(0,Q.useRef)(e);we.current=e;let Te=(0,Q.useRef)(r);Te.current=r;let K=(0,Q.useRef)([]);K.current=i;let Ee=(0,Q.useRef)(n);Ee.current=n;let q=(0,Q.useRef)(null),J=(0,Q.useRef)(0),Oe=(0,Q.useRef)({teamNames:new Set,messages:[]}),ke=(0,Q.useRef)(0),[Ae,Me]=(0,Q.useState)(Rt),[Ne,Pe]=(0,Q.useState)([]),Y=(0,Q.useCallback)(()=>{let e=Oe.current;Me({hasTeams:e.teamNames.size>0,teamNames:Array.from(e.teamNames),messageCount:e.messages.length,unreadCount:ke.current}),Pe([...e.messages])},[]),Fe=(0,Q.useCallback)(()=>{ke.current=0,Y()},[Y]),Ie=(0,Q.useCallback)(async e=>{try{let t=await G.get(`/api/teams/${encodeURIComponent(e)}`);if(!t?.messages)return;let n=Oe.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]),Le=f!==`idle`;(0,Q.useEffect)(()=>{if(e)return je.getState().setStreaming(e,f!==`idle`,n),()=>{je.getState().setStreaming(e,!1)}},[e,f,n]);let Re=(0,Q.useCallback)((e,t)=>{let n=r=>{for(let i=0;i<r.length;i++){let a=r[i];if(a.type===`tool_use`){if((a.tool===`Agent`||a.tool===`Task`)&&a.toolUseId===t){let t=[...a.children??[]],n=e.toolUseId,o=n?t.findIndex(t=>t.type===e.type&&t.toolUseId===n):-1;return o===-1?t.push(e):t[o]=e,[[...r.slice(0,i),{...a,children:t},...r.slice(i+1)],!0]}if(a.children?.length){let[e,t]=n(a.children);if(t)return[[...r.slice(0,i),{...a,children:e},...r.slice(i+1)],!0]}}}return[r,!1]},[r,i]=n(F.current);return i&&(F.current=r),i},[]),ze=(0,Q.useCallback)((e,t)=>{let n=e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t,r=K.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)},[]),Be=(0,Q.useCallback)(()=>{J.current=0;let e=P.current,t=[...F.current],n=I.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(Be,100)},[Be]),Ve=(0,Q.useCallback)((e,t)=>{let n=t=>t.type===`tool_use`&&(t.tool===`Agent`||t.tool===`Task`)&&t.toolUseId===e,r=F.current.findIndex(n);if(r!==-1){F.current[r]={...F.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]),He=(0,Q.useCallback)(e=>{let t=e,n=t?.type;if(!n)return;let r=e=>{let n=F.current,r=n.findIndex(e);r===-1?n.push(t):n[r]=t};switch(n){case`account_info`:I.current={accountId:t.accountId,accountLabel:t.accountLabel},L({id:t.accountId,label:t.accountLabel??null}),T(null);break;case`account_retry`:t.accountId&&t.accountLabel&&(I.current={accountId:t.accountId,accountLabel:t.accountLabel},L({id:t.accountId,label:t.accountLabel})),F.current=[t],X();break;case`status_update`:{let e=t.accountLabel?` (${t.accountLabel})`:``;T(`${t.message}${e}`);break}case`text`:{let e=t.parentToolUseId;if(e&&Re(t,e)){X();break}if(e){ze(t,e);break}P.current+=t.content,F.current.push(t),X();break}case`thinking`:{let e=t.parentToolUseId;if(e&&Re(t,e)){X();break}if(e){ze(t,e);break}F.current.push(t),X();break}case`tool_use`:{if(t.tool===`AskUserQuestion`){t.toolUseId&&be.current.add(t.toolUseId);break}let e=t.parentToolUseId;if(e&&Re(t,e)){X();break}if(e){ze(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&&fe.current.delete(e),e&&be.current.has(e))break;let n=t.parentToolUseId;if(n&&Re(t,n)){X();break}if(n){ze(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=F.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]))}v(t=>t&&t.requestId===e?null:t),q.current!=null&&(Ce.dismiss(q.current),q.current=null);break}case`approval_request`:if(r(e=>e.type===`approval_request`&&e.requestId===t.requestId),ye.current)break;if(v({requestId:t.requestId,tool:t.tool,input:t.input}),we.current&&!zt(we.current)){Lt(t.tool===`AskUserQuestion`?`question`:`approval_request`);let e=we.current,n=t.tool===`AskUserQuestion`;q.current=Ce[n?`info`:`warning`](n?`AI has a question`:`${t.tool} needs permission`,{description:Ee.current||`Session ${e.slice(0,8)}`,duration:1/0,action:{label:`Go to session`,onClick:()=>{let{panels:t}=De.getState();for(let[n,r]of Object.entries(t)){let t=r.tabs.find(t=>t.metadata?.sessionId===e);if(t){De.getState().setActiveTab(t.id,n);break}}}}})}break;case`error`:a(e=>{let n=e[e.length-1];if(n?.role===`assistant`){let r=F.current,i=r[r.length-1],a=i?.type===`error`&&i.message===t.message?r:[...r,t];return F.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&&(Oe.current.teamNames.add(e),Y(),Ie(e));break}case`team_inbox`:{let e=t.messages;if(Array.isArray(e)){let t=Oe.current.messages;t.push(...e),t.length>500&&t.splice(0,t.length-500),ke.current+=e.length,Y()}break}case`team_updated`:Y();break;case`bash_output`:{let e=t.toolUseId;if(e){let n=fe.current.get(e);n?(n.content+=t.content,n.content.length>5e5&&(n.content=n.content.slice(-5e5)),n.lineCount=t.lineCount):fe.current.set(e,{content:t.content,lineCount:t.lineCount}),X()}break}case`subagent_status`:{let e=t.toolUseId,n=t.status;e&&n&&Ve(e,n);break}case`background_registry`:{let e=t.shells??[];w.current=e,C(e);break}case`done`:{if(R.current===`idle`)break;t.contextWindowPct!=null&&b(t.contextWindowPct),we.current&&!zt(we.current)&&Lt(`done`),J.current&&=(clearTimeout(J.current),0);let e=P.current,n=[...F.current],r=I.current;B.current=!!e||n.length>0;let 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}),P.current=``,F.current=[],I.current=null,U.current=null,fe.current.clear(),T(null);break}}},[Re,ze,X,Ve,Y,Ie]),Ue=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(ye.current){V.current.push(e);return}if(t.type===`user_message`){z.current++;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`){E(t.title??null);return}if(t.type===`session_migrated`){let e=t.newSessionId;e&&e!==we.current&&Te.current?.(e);return}if(t.type===`compact_status`){let e=t.status;e===`compacting`?x(`compacting`):e===`done`&&x(null);return}if(t.type===`phase_changed`){let e=t.phase,n=R.current!==`idle`;!n&&e!==`idle`&&(B.current=!1),e!==`idle`&&z.current++,p(e),R.current=e,_(e===`connecting`?t.elapsed??0:0),e===`idle`&&(x(null),T(null),n&&!B.current&&ge.current?.());return}if(t.type===`session_state`){ae(!0),h(!1),oe(t.sessionId??we.current);let e=t,n=e.phase;n!==`idle`&&z.current++;let r=R.current===`idle`;if(r&&n!==`idle`&&(B.current=!1),p(n),R.current=n,e.sessionTitle&&E(e.sessionTitle),e.model&&(k.current&&e.model!==k.current||(e.model===k.current&&(k.current=null),ce(e.model),O.current=e.model)),typeof e.effort==`string`&&(j(e.effort),le.current=e.effort),typeof e.thinking==`boolean`&&de(e.thinking),e.pendingApproval&&v({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),x(e.compactStatus===`compacting`?`compacting`:null),n===`idle`){let e=Date.now()-Se.current<5e3;r&&e||ge.current?.(),h(!1)}return}if(t.type===`turn_events`){z.current++;let e=t.events,n=t.userMessage;if(!e?.length&&!n){h(!1);return}xe.current&&=(cancelAnimationFrame(xe.current),0),U.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}),P.current=``,F.current=[],I.current=null,ye.current=!0;let r=0,i=()=>{let t=Math.min(r+100,e.length);for(let n=r;n<t;n++)He(e[n]);if(r=t,r<e.length)xe.current=requestAnimationFrame(i);else{xe.current=0,ye.current=!1,h(!1);let e=V.current.splice(0);for(let t of e)H.current?.(t)}};xe.current=requestAnimationFrame(i);return}He(t)}},[He]);H.current=Ue;let{send:Z,connect:We}=nt({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:Ue,autoConnect:!!e&&!!n,idleTimeoutMs:45e3,onConnectionChange:e=>{e||(ae(!1),h(!0))}});he.current=Z,(0,Q.useEffect)(()=>{let r=!1,i=_e.current;B.current=!1,z.current++,N.current&&N.current!==e&&(k.current=null,M.current=null,L(null)),N.current=e??null,p(`idle`),R.current=`idle`,v(null),q.current!=null&&(Ce.dismiss(q.current),q.current=null),x(null),s(new Map),d({}),P.current=``,F.current=[],U.current=null,Se.current=0,fe.current.clear(),J.current&&=(clearTimeout(J.current),0),ae(!1),oe(null),h(!1),Oe.current={teamNames:new Set,messages:[]},ke.current=0,Me(Rt),Pe([]),e&&G.get(`/api/teams`).then(t=>{r||!Array.isArray(t)||t.filter(t=>(t?.name??t?.team_name)===e).length!==0&&(Oe.current.teamNames.add(e),Y(),Ie(e))}).catch(()=>{});let o=new Set(K.current.map(e=>e.id));return e&&n?(l(!0),G.get(`${W(n)}/chat/sessions/${e}/messages?providerId=${t}`).then(e=>{if(r||_e.current!==i)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!==we.current&&Te.current?.(t.canonicalSessionId);let s=U.current;if(s!=null){for(let e=n.length-1;e>=0;e--)if(n[e].role===`user`&&n[e].content===s){n=n.slice(0,e);break}}a(e=>{let t=e.filter(e=>!o.has(e.id));return[...n,...t]}),Se.current=Date.now()}).catch(()=>{!r&&_e.current===i&&a(e=>e.filter(e=>!o.has(e.id)))}).finally(()=>{r||l(!1)})):a([]),()=>{r=!0,ve.current?.abort(),ve.current=null,J.current&&clearTimeout(J.current),J.current=0,xe.current&&cancelAnimationFrame(xe.current),xe.current=0,ye.current=!1,V.current=[]}},[e,t,n,Y,Ie]);let Ge=(0,Q.useCallback)((e,t)=>{if(!e.trim()&&!t?.images?.length)return;z.current++;let n=R.current!==`idle`;if(B.current=!1,n){J.current&&=(clearTimeout(J.current),0);let e=P.current,t=[...F.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()}]),P.current=``,F.current=[],me.current=null,n?(p(`thinking`),R.current=`thinking`):(p(`initializing`),R.current=`initializing`),v(null),q.current!=null&&(Ce.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,...O.current&&{model:O.current},...le.current&&{effort:le.current},...M.current!==null&&{thinking:M.current}}))},[Z]),Ke=(0,Q.useCallback)(e=>{ce(e),O.current=e,k.current=e,Z(JSON.stringify({type:`set_model`,model:e}))},[Z]),qe=(0,Q.useCallback)(e=>{j(e),le.current=e,Z(JSON.stringify({type:`set_effort`,effort:e}))},[Z]),Ye=(0,Q.useCallback)(e=>{de(e),M.current=e,Z(JSON.stringify({type:`set_thinking`,enabled:e}))},[Z]),Xe=(0,Q.useCallback)((e,t,n)=>{if(Z(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=F.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])}v(null),q.current!=null&&(Ce.dismiss(q.current),q.current=null)},[Z]),Ze=(0,Q.useCallback)(()=>{if(R.current===`idle`)return;Z(JSON.stringify({type:`cancel`}));let e=P.current,t=[...F.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}),P.current=``,F.current=[],fe.current.clear(),me.current=null,p(`idle`),R.current=`idle`,v(null),q.current!=null&&(Ce.dismiss(q.current),q.current=null)},[Z]),Qe=(0,Q.useCallback)(e=>{e&&Z(JSON.stringify({type:`kill_background_shell`,shellId:e}))},[Z]),$e=(0,Q.useCallback)(e=>{if(!e)return;let t=e.replace(/\.output$/,``);return w.current.find(n=>n.shellId===t||n.outputPath.endsWith(e)||n.outputPath.endsWith(`${t}.output`))},[]);(0,Q.useEffect)(()=>{e&&Je.getState().setSessionShells(e,S)},[e,S]),(0,Q.useEffect)(()=>{if(e)return Je.getState().retainSession(e),()=>{Je.getState().releaseSession(e)}},[e]);let et=(0,Q.useCallback)(()=>{ae(!1),h(!0),We()},[We]),tt=(0,Q.useCallback)(()=>{if(!e||!n||R.current!==`idle`)return;ve.current?.abort();let r=new AbortController;ve.current=r;let i=z.current;G.get(`${W(n)}/chat/sessions/${e}/messages?providerId=${t}`,{signal:r.signal}).then(t=>{if(r.signal.aborted||ve.current!==r||z.current!==i||R.current!==`idle`||we.current!==e||Ee.current!==n||ye.current)return;let o=Array.isArray(t)?{messages:t,versionMap:void 0}:t;o?.versionMap&&d(o.versionMap),Array.isArray(o?.messages)&&o.messages.length>0&&(_e.current++,J.current&&=(clearTimeout(J.current),0),a(o.messages),P.current=``,F.current=[]),Se.current=Date.now()}).catch(()=>{})},[e,t,n]);ge.current=tt;let rt=(0,Q.useCallback)(async(e,t)=>{if(!n)throw Error(`No project context available`);let r=e.replace(/^pc-[^-]+-/,``),i=`${W(n)}/chat/pre-compact-messages?jsonlPath=${encodeURIComponent(t)}&before=${encodeURIComponent(r)}`,a=Ot(await G.get(i),t);return s(t=>{let n=new Map(t);return n.set(e,a),n}),a.length},[n]),it=(0,Q.useCallback)(e=>o.has(e),[o]),at=(0,Q.useCallback)(e=>{a(t=>t.filter(t=>t.id!==e))},[]),ot=(0,Q.useCallback)(()=>{a(e=>e.filter(e=>e.role!==`system`))},[]);return{messages:i,renderedMessages:(0,Q.useMemo)(()=>kt(i,o),[i,o]),expandCompact:rt,isCompactExpanded:it,dismissMessage:at,clearErrors:ot,messagesLoading:c,versionMap:u,isStreaming:Le,phase:f,isReconnecting:m,connectingElapsed:g,pendingApproval:ee,contextWindowPct:y,compactStatus:te,statusMessage:ne,sessionTitle:re,liveAccount:pe,model:se,setModel:Ke,effort:A,setEffort:qe,thinking:ue,setThinking:Ye,teamActivity:Ae,teamMessages:Ne,markTeamRead:Fe,bashPartialOutput:fe,backgroundShells:S,killBackgroundShell:Qe,findBackgroundShellByOutput:$e,sendMessage:Ge,respondToApproval:Xe,cancelStreaming:Ze,reconnect:et,refetchMessages:tt,isConnected:ie&&D===e}}var Vt=12e4;function Ht(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 Promise.resolve();let o=++l.current;s(!0);let c=i?`&refresh=1`:``,u=n?`&session=${encodeURIComponent(n)}`:``;return G.get(`${W(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(),Vt),()=>{++l.current,c.current&&clearInterval(c.current)}),[u]);let d=(0,Q.useCallback)(()=>u(!0),[u]),f=(0,Q.useCallback)(()=>u(),[u]),p=i?.scope===r?i:null;return{usageInfo:p?.usage??{},usageLoading:o,lastFetchedAt:p?.fetchedAt??null,refreshUsage:d,reloadUsage:f}}function Ut(e){let t=Array(e.length),n=0;for(let r=0;r<e.length;r++){let i=e[r].role===`user`;i&&n++,t[r]=i?n:0}return t}var Wt={damping:.7,stiffness:.05,mass:1.25},Gt=70,Kt=1e3/60,qt=350,Jt=!1;globalThis.document?.addEventListener(`mousedown`,()=>{Jt=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{Jt=!1}),globalThis.document?.addEventListener(`click`,()=>{Jt=!1});var Yt=(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(!Jt)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<=Gt}}},[]),f=(0,Q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Qt(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))/Kt;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:Qt(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=Xt(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=Xt(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=Qt(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:qt})}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 Xt(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Zt=new Map;function Qt(...e){let t={...Wt},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 Zt.has(r)||Zt.set(r,Object.freeze(t)),n?`instant`:Zt.get(r)}var $t=60,en=8,tn=1400;function nn(e){if(e.scrollHeight<=e.clientHeight)return!1;let t=getComputedStyle(e).overflowY;return t===`auto`||t===`scroll`}function rn(e,t){let n=[],r=e.parentElement;for(;r&&r!==t;)nn(r)&&n.push(r),r=r.parentElement;return n}function an(){return typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches}function on(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 sn(e,t,n,r){let i=e.scrollTop+t.getBoundingClientRect().top-e.getBoundingClientRect().top-n;e.scrollTo({top:i,behavior:r?`smooth`:`auto`})}function cn(e,t){let n=on(e,t);if(!n)return()=>{};let{el:r,level:i}=n;for(let t of rn(r,e))sn(t,r,en,!1);sn(e,r,$t,!an()),r.dataset.flash=i;let a=setTimeout(()=>{delete r.dataset.flash},tn);return()=>{clearTimeout(a),delete r.dataset.flash}}var ln=new Set([`Write`,`Edit`,`MultiEdit`,`NotebookEdit`]),un={create:3,write:2,notebook:2,edit:1};function dn(e){return typeof e==`string`?e:``}function fn(e,t){let n=0,r=0;for(let i of ut(e,t))i.added?n+=i.count??0:i.removed&&(r+=i.count??0);return{added:n,removed:r}}function pn(e){return e&&/created successfully/i.test(e)?`create`:`write`}function mn(e,t,n){switch(e){case`Write`:{let e=dn(t.file_path);return e?{filePath:e,op:pn(n),fragments:[{oldStr:``,newStr:dn(t.content)}]}:null}case`Edit`:{let e=dn(t.file_path);return e?{filePath:e,op:`edit`,fragments:[{oldStr:dn(t.old_string),newStr:dn(t.new_string)}]}:null}case`MultiEdit`:{let e=dn(t.file_path);if(!e||!Array.isArray(t.edits))return null;let n=t.edits.filter(e=>!!e&&typeof e==`object`).map(e=>({oldStr:dn(e.old_string),newStr:dn(e.new_string)}));return n.length===0?null:{filePath:e,op:`edit`,fragments:n}}case`NotebookEdit`:{let e=dn(t.notebook_path)||dn(t.file_path);return e?{filePath:e,op:`notebook`,fragments:[{oldStr:``,newStr:dn(t.new_source)}]}:null}default:return null}}function hn(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),hn(n.children,t)}}}function gn(e,t,n,r){if(e)for(let i of e){if(i.type!==`tool_use`||(i.children?.length&&gn(i.children,!0,n,r),!ln.has(i.tool)))continue;let e=i.input&&typeof i.input==`object`?i.input:null;if(!e)continue;let a=mn(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)),un[a.op]>un[o.op]&&(o.op=a.op),t&&(o.viaSubagent=!0),a.fragments.forEach((e,n)=>{let{added:r,removed:a}=fn(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 _n(e){let t=new Map;for(let n of e)hn(n.events,t);let n=new Map;for(let r of e)gn(r.events,!1,n,t);return[...n.values()]}function vn(e,t){let n=[];for(let r=t;r>=0&&e[r]?.role===`assistant`;r--)n.unshift(e[r]);return n}var $=n();function yn(e){try{return new Date(e).toLocaleString()}catch{return``}}function bn({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 xn({content:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsx)(bn,{icon:t?(0,$.jsx)(B,{className:`size-3.5`}):(0,$.jsx)(R,{className:`size-3.5`}),label:t?`Copied`:`Copy`,title:`Copy message to clipboard`,onClick:()=>{Re(e),n(!0),setTimeout(()=>n(!1),1500)}})}function Sn({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:yn(e),className:`pr-1 tabular-nums`,children:$e(e)}),(0,$.jsx)(xn,{content:t}),r]})}function Cn(e){let t=0,n=0;for(let r of e)t+=r.linesAdded,n+=r.linesRemoved;return{added:t,removed:n}}function wn({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 Tn(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}=De.getState();return n[r]?.activeTabId===t}var En={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 Dn(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 On({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 kn({change:e,dense:t,selected:n,onClick:r}){let i=En[e.op],{base:a,dir:o}=Dn(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)(On,{added:e.linesAdded,removed:e.linesRemoved,editCount:e.editCount,className:`text-[11px]`}),(0,$.jsx)(N,{className:`size-[11px] text-text-subtle`})]})}var An=(0,Q.lazy)(()=>Te(()=>import(`./edit-diff-preview-BGGGecVw.js`),__vite__mapDeps([0,1,2,3])));function jn({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)(A,{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)(An,{oldStr:n.oldStr,newStr:n.newStr,filePath:e.filePath})})})]},n.editRef??r))})}function Mn(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 Nn=null;function Pn(e){return e instanceof HTMLElement?e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.isContentEditable:!1}function Fn({changes:e,onJump:t,onClose:n}){let[r,i]=(0,Q.useState)(0),a=(0,Q.useRef)(null),s=(0,Q.useRef)(null),c=(0,Q.useId)();(0,Q.useEffect)(()=>(Nn=c,s.current?.querySelector(`button`)?.focus(),()=>{Nn===c&&(Nn=null)}),[c]),(0,Q.useEffect)(()=>{let o=o=>{if(Nn===c&&Tn(a.current)&&!Pn(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)},[c,e,r,t,n]);let l=e[Math.min(r,e.length-1)];if(!l)return null;let{base:u,dir:d}=Mn(l.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:s,className:`min-h-0 overflow-y-auto border-r border-border-soft`,children:[e.map((e,t)=>(0,$.jsx)(kn,{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:u}),d&&(0,$.jsx)(`span`,{title:l.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:d}),(0,$.jsx)(On,{added:l.linesAdded,removed:l.linesRemoved,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void Re(l.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)(o,{className:`size-3.5`})})]}),(0,$.jsx)(jn,{change:l,onJump:t})]})]})})}function In(e){let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`));return t<0?e:e.slice(t+1)}function Ln({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 Rn({changes:e,totals:t,open:n,onClose:r,onJump:a}){let[s,c]=(0,Q.useState)(null),l=s==null?null:e[s],u=(0,Q.useRef)(null),d=()=>{c(null),r()},f=e=>{d(),a(e)};return(0,Q.useEffect)(()=>{if(!n)return;let e=u.current,t=()=>Array.from(e?.querySelectorAll(`button:not([disabled])`)??[]);t()[0]?.focus();let r=e=>{if(e.key===`Escape`){e.preventDefault(),d();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,s]),(0,$.jsx)(Fe,{open:n,onClose:d,className:`flex max-h-[85%] flex-col rounded-t-[14px] motion-reduce:animate-none`,children:(0,$.jsx)(`div`,{ref:u,className:`flex min-h-0 flex-1 flex-col`,children:l?(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)(Ln,{label:`Back to file list`,onClick:()=>c(null),children:(0,$.jsx)(i,{className:`size-4`})}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs font-medium text-text-primary`,children:In(l.filePath)}),(0,$.jsx)(On,{added:l.linesAdded,removed:l.linesRemoved,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(Ln,{label:`Close`,onClick:d,children:(0,$.jsx)(o,{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:l.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:l.filePath}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void Re(l.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`}),l.edits[0]?.editRef&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f(l.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)(A,{className:`size-3`}),`card`]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,$.jsx)(jn,{change:l,onJump:f})})]}):(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)(On,{added:t.added,removed:t.removed,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(Ln,{label:`Close`,onClick:d,children:(0,$.jsx)(o,{className:`size-4`})})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:e.map((e,t)=>(0,$.jsx)(kn,{change:e,onClick:()=>c(t)},e.filePath))})]})})})}function zn({timestamp:e,content:t,changes:n,onJumpToEdit:r}){let[i,a]=(0,Q.useState)(!1),o=Ae(),s=(0,Q.useRef)(null),c=()=>{a(!1),s.current?.focus()},l=(0,$.jsx)(Sn,{timestamp:e,content:t,className:`-mt-1.5`,children:n&&n.length>0&&(0,$.jsx)(wn,{ref:s,count:n.length,totals:Cn(n),open:i,onToggle:()=>i?c():a(!0)})});return!n||n.length===0?l:(0,$.jsxs)($.Fragment,{children:[l,o?(0,$.jsx)(Rn,{changes:n,totals:Cn(n),open:i,onClose:c,onJump:r??(()=>{})}):i&&(0,$.jsx)(Fn,{changes:n,onJump:e=>{a(!1),r?.(e)},onClose:c})]})}function Bn(e){return e.inputTokens+e.cacheReadTokens+e.cacheWriteTokens}function Vn(e){return e.inputTokens+e.cacheWriteTokens}var Hn=.5,Un=.9,Wn={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 Gn(e){let t=Vn(e),n=Bn(e);if(!e.coldStart||n<2e4)return{level:`ok`,wastedTokens:t,reason:``};let r=e.cacheHitRate<Hn?`bad`:e.cacheHitRate<Un?`warn`:`ok`;if(r===`ok`)return{level:r,wastedTokens:t,reason:``};let i=e.coldReason?Wn[e.coldReason]??`the session restarted (${e.coldReason})`:null;return{level:r,wastedTokens:t,reason:i?`${Yn(t)} of this session's transcript was re-sent uncached because ${i}.`:`${Yn(t)} of this session's transcript was re-sent uncached.`}}var Kn=.1,qn=1.25;function Jn(e){let t=Bn(e);if(t===0)return 1;let n=e.inputTokens+e.cacheWriteTokens*qn+e.cacheReadTokens*Kn,r=t*Kn;return r>0?Math.max(1,n/r):1}function Yn(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(e>=1e4?0:1)}k`:String(e)}function Xn({usage:e}){let[t,n]=(0,Q.useState)(!1),r=Gn(e);if(r.level===`ok`)return null;let i=Jn(e),a=Bn(e),o=Math.round(e.cacheHitRate*100),s=r.level===`bad`;return(0,$.jsxs)(`div`,{className:`rounded-md border px-2.5 py-2 text-[11px] ${s?`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 ${s?`text-warning`:`text-text-subtle`}`}),(0,$.jsxs)(`span`,{className:`flex-1`,children:[`Costly turn — `,o,`% of a `,Yn(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)(ee,{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)(Zn,{label:`From cache`,value:`${Yn(e.cacheReadTokens)} (${o}%)`}),(0,$.jsx)(Zn,{label:`Written to cache`,value:Yn(e.cacheWriteTokens)}),(0,$.jsx)(Zn,{label:`Fresh input`,value:Yn(e.inputTokens)}),(0,$.jsx)(Zn,{label:`Output`,value:Yn(e.outputTokens)}),(0,$.jsx)(Zn,{label:`Model`,value:e.model||`unknown`}),(0,$.jsx)(Zn,{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 Zn({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 Qn(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(()=>{G.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 $n=new Set([`TaskCreate`,`TaskUpdate`,`TaskStop`]);function er(e){let t=0;for(let n of e)if(n.events)for(let e of n.events)e.type===`tool_use`&&$n.has(e.tool)&&t++;return t}var tr={completed:{icon:`✓`,cls:`text-success`},in_progress:{icon:`▶`,cls:`text-warning`},stopped:{icon:`■`,cls:`text-text-subtle`},pending:{icon:`○`,cls:`text-text-subtle`}};function nr({projectName:e,sessionId:t,messages:n}){let r=(0,Q.useMemo)(()=>er(n),[n]),i=Qn(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 s=i.filter(e=>e.status===`completed`).length,c=i.length,l=c?Math.round(s/c*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)(N,{className:`size-3.5 shrink-0`}):(0,$.jsx)(ee,{className:`size-3.5 shrink-0`}),(0,$.jsx)(O,{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:[s,`/`,c,` 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:`${l}%`}})})]}),!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)(rr,{task:e},e.id))})]})}function rr({task:e}){let t=tr[e.status]??tr.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 ir=/read the full transcript at:\s*(\S+\.jsonl)/i;function ar(e){return e.match(ir)?.[1]?.trim()??null}var or=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}},sr=Te(()=>import(`./markdown-renderer-Bcaf9_bA.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])),cr=(0,Q.lazy)(()=>sr.then(e=>({default:e.MarkdownRenderer}))),lr=/<teammate-message[^>]*>[\s\S]*?<\/teammate-message>/g;function ur(e){return e.replace(lr,``).replace(/\n{3,}/g,`
3
-
4
- `).trim()}function dr({content:e,projectName:t,isStreaming:n}){let r=ur(e);return r?(0,$.jsx)(or,{fallbackContent:r,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`animate-pulse h-4 bg-muted rounded`}),children:(0,$.jsx)(cr,{content:r,projectName:t,codeActions:!0,isStreaming:n})})}):null}function fr({group:e,onNavigate:t,disabled:n}){if(!e||e.ids.length<2)return null;let{ids:r,currentIndex:a}=e,o=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:()=>o(a-1),disabled:n||a<=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)(i,{className:`size-3.5`})}),(0,$.jsxs)(`span`,{className:`tabular-nums`,children:[a+1,`/`,r.length]}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>o(a+1),disabled:n||a>=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)(N,{className:`size-3.5`})})]})}var pr={"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 mr(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:pr[e]??e.replace(/^antml:/,``).replace(/-/g,` `),content:r[2].trim()})}return{cleanText:e.replace(n,``).trim(),tags:t}}function hr(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 gr(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 _r(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 vr(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=vr(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(`
5
- `).map(e=>e.trim()).filter(Boolean),text:n.slice(i[0].length)}:{files:[],text:n}}function yr(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 br(e){let{idePath:t,cleanText:n}=_r(e),{blocks:r,remainingText:i}=yr(n),a=vr(i),{cleanText:o,tags:s}=mr(a.text.replace(/<local-command-(?:stdout|stderr)>([\s\S]*?)<\/local-command-(?:stdout|stderr)>/g,`$1`)),{command:c,cleanText:l}=hr(o),{agent:u,cleanText:d}=gr(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 xr(e){let{agent:t,body:n,command:r}=br(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 Sr=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]);function Cr(e,t){let n=q(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function wr(e){let t=e.lastIndexOf(`.`);return t===-1?!1:Sr.has(e.slice(t).toLowerCase())}var Tr=new Map;function Er(e){let[t,n]=(0,Q.useState)(()=>Tr.get(e)?.url??null),[r,i]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{let t=Tr.get(e);if(t){n(t.url);return}let r=!1,a=Se();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);Tr.set(e,{url:i}),n(i)}).catch(()=>{r||i(!0)}),()=>{r=!0}},[e]),{blobUrl:t,error:r}}function Dr({filePath:e,projectName:t}){let{blobUrl:n,error:r}=Er(Cr(e,t)),i=qe(e=>e.open),a=q(e);return(0,$.jsxs)(`button`,{type:`button`,onClick:e=>n&&i(n,a,ct(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,[lt]:``,className:`size-4 rounded-sm object-cover shrink-0`}):r?(0,$.jsx)(ie,{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})]})}var Or=new Set([`task-notification`,`environment_details`,`local-command-caveat`]);function kr({content:e,messageId:t,timestamp:n,projectName:i,onFork:o,onEdit:s,isEditing:c,sessionId:l,providerId:u,versionGroup:d,onNavigateVersion:f,versionNavDisabled:p}){let{files:m,text:h,tags:_,command:v,terminalBlocks:y,idePath:b,agent:te}=(0,Q.useMemo)(()=>br(e),[e]),x=_.some(e=>Or.has(e.name)),[S,C]=(0,Q.useState)(!1),[w,ne]=(0,Q.useState)(!1),T=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let e=T.current;if(!e)return;let t=()=>ne(e.scrollHeight>e.clientHeight+2);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[h]),(0,$.jsxs)(`div`,{className:K(`flex flex-col gap-1`,!x&&`items-end`),children:[(0,$.jsxs)(`div`,{"data-user-message":x?void 0:`true`,style:x?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`,x?`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)(jr,{tags:_}),te&&(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)(_e,{className:`size-3 shrink-0`}),te]})}),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)(Ct,{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)(Fr,{path:b,projectName:i})]}),m.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:m.map((e,t)=>wr(e)?(0,$.jsx)(Dr,{filePath:e,projectName:i},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)(D,{className:`size-3 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-32`,children:q(e)})]},t))}),y.length>0&&(0,$.jsx)(`div`,{className:`space-y-1.5`,children:y.map((e,t)=>(0,$.jsx)(Ar,{content:e},t))}),h&&(0,$.jsx)(`div`,{ref:T,className:K(`whitespace-pre-wrap break-words transition-all duration-200 select-text`,!S&&`line-clamp-2`,S&&`max-h-[50vh] overflow-y-auto`),children:x?(0,$.jsx)(Lr,{text:h,projectName:i}):(0,$.jsx)(Ir,{text:h})}),(w||S)&&(0,$.jsx)(`button`,{onClick:()=>C(!S),className:K(`flex items-center gap-1 text-xs mt-1 transition-colors`,x?`text-text-subtle hover:text-text-secondary`:`text-primary/70 hover:text-primary`),children:S?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{className:`size-3`}),`Show less`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ee,{className:`size-3`}),`Show more`]})}),!x&&f&&(0,$.jsx)(fr,{group:d,onNavigate:f,disabled:p})]}),!x&&(0,$.jsxs)(Sn,{timestamp:n,content:e,children:[s&&(0,$.jsx)(bn,{icon:(0,$.jsx)(a,{className:`size-3.5`}),label:`Edit`,title:`Edit this message (continue in the same tab)`,onClick:s}),o&&(0,$.jsx)(bn,{icon:(0,$.jsx)(r,{className:`size-3.5`}),label:`Fork`,title:`Retry from this message (fork into a new tab)`,onClick:o})]})]})}function Ar({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)(C,{className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{children:`Terminal output`}),(0,$.jsx)(ee,{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 jr({tags:e}){return(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,$.jsx)(Mr,{tag:e},t))})}function Mr({tag:e}){let[t,n]=(0,Q.useState)(!1);return e.name===`task-notification`?(0,$.jsx)(Pr,{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)(be,{className:`size-2.5`}),(0,$.jsx)(`span`,{children:e.label}),(0,$.jsx)(N,{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 Nr(e,t){return e.match(RegExp(`<${t}>([\\s\\S]*?)</${t}>`))?.[1]?.trim()||void 0}function Pr({content:e}){let[t,n]=(0,Q.useState)(!1),r=Nr(e,`status`),i=Nr(e,`summary`),a=Nr(e,`output-file`),o=Nr(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)(c,{className:`size-2.5 text-success`}):(0,$.jsx)(T,{className:`size-2.5 text-warning`}),(0,$.jsx)(`span`,{className:`truncate max-w-80`,children:i??`Task notification`}),(0,$.jsx)(N,{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)(Fr,{path:a}),o&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-subtle/80 max-h-60 overflow-y-auto leading-relaxed`,children:(0,$.jsx)(dr,{content:o})})]})]})}function Fr({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=q(e),a={filePath:e};r&&(a.projectName=r),G.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)(D,{className:`size-2.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-60`,children:q(e)}),(0,$.jsx)(k,{className:`size-2 shrink-0 opacity-50`})]})}function Ir({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 Lr({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)(Fr,{path:e.value,projectName:t},n):(0,$.jsx)(`span`,{children:e.value},n))})}function Rr({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,exitCode:t.exitCode})}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)(zr,{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)(Br,{content:e.content,animate:r,projectName:n})},`text-${a}`)}return(0,$.jsx)(at,{tool:e.tool,result:e.result,completed:e.completed,projectName:n,bashPartialOutput:r},`tool-${a}`)})})}function zr({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)(F,{className:`size-3 animate-spin`}):(0,$.jsx)(N,{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 Br({content:e,animate:t,projectName:n}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(dr,{content:e,projectName:n,isStreaming:t}),t&&(0,$.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function Vr({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)(F,{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.`})]})}function Hr({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)(_e,{className:`size-10 text-text-subtle`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Send a message to start a new conversation`})]}),(0,$.jsx)(Ye,{projectName:e,onSelectSession:t,className:`w-full px-4`})]})}var Ur=3200,Wr=1e3,Gr={hasAbove:!1,atBottom:!0,idx:0,total:0};function Kr({scrollElement:e,userIndices:t,scrollToBottom:n}){let r=Ae(),[i,a]=(0,Q.useState)(Gr),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(0),d=(0,Q.useRef)(Ur),f=(0,Q.useRef)(null),p=(0,Q.useRef)(null),m=(0,Q.useRef)(!1),h=(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(()=>s(!1),d.current);return()=>clearTimeout(e)},[o,i.idx,c]),(0,Q.useEffect)(()=>{if(!o||!h.current)return;h.current=!1;let e=f.current;(e?.querySelector(`button:not(:disabled)`)??e)?.focus()},[o]),(0,Q.useEffect)(()=>{o||!m.current||(m.current=!1,p.current?.focus())},[o]);let y=(0,Q.useCallback)(()=>{d.current=Ur,l(e=>e+1)},[]),te=(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=>()=>{Tn(t)&&(e(),d.current=Wr,s(!0))},r=n(te),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,te,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:f,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:()=>{m.current=!0},onKeyDown:e=>{e.key===`Escape`&&s(!1)},children:[(0,$.jsx)(`button`,{type:`button`,onClick:te,disabled:!i.hasAbove,"aria-label":`Jump to previous message`,className:C,children:(0,$.jsx)(g,{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)(ee,{className:`size-[15px]`})}),(0,$.jsx)(`button`,{type:`button`,onClick:S,disabled:i.atBottom,"aria-label":`Jump to latest`,className:C,children:(0,$.jsx)(u,{className:`size-[13px]`})})]}):(0,$.jsx)(`button`,{ref:p,type:`button`,onClick:()=>{d.current=Ur,h.current=!0,s(!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)(b,{className:`size-[15px]`})})})})}function qr(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 Jr(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 Yr({questions:e,onSubmit:t,onSkip:n}){let r=(0,Q.useRef)(null),i=qr(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=Jr({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})`]})]})]})}function Xr(){return(0,$.jsxs)(`div`,{className:`px-4 pt-4 space-y-4`,"aria-busy":`true`,"aria-label":`Loading previous conversation`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-1.5 text-xs text-text-secondary`,children:[(0,$.jsx)(F,{className:`size-3 animate-spin`}),`Loading previous conversation…`]}),[0,1,2].map(e=>(0,$.jsx)(`div`,{className:e%2==0?`flex justify-end`:`flex justify-start`,children:(0,$.jsxs)(`div`,{className:`animate-pulse space-y-2 rounded-lg bg-surface p-3 ${e%2==0?`w-1/2`:`w-3/4`}`,children:[(0,$.jsx)(`div`,{className:`h-3 rounded bg-border`}),(0,$.jsx)(`div`,{className:`h-3 w-5/6 rounded bg-border`}),e%2==1&&(0,$.jsx)(`div`,{className:`h-3 w-2/3 rounded bg-border`})]})},e))]})}function Zr({messages:e,messagesLoading:t,keepStaleWhileLoading:n,pendingApproval:r,onApprovalResponse:i,isStreaming:a,phase:o,onSelectSession:s,connectingElapsed:c,statusMessage:l,compactStatus:u,projectName:d,onFork:f,onEdit:p,editingMsgId:m,sessionId:h,providerId:g,onNavigateVersion:_,versionMap:ee,bashPartialOutput:v,onExpandCompact:y,isCompactExpanded:b,onDismissMessage:te,onClearErrors:x}){let{scrollRef:S,contentRef:C,scrollToBottom:w,stopScroll:ne,isAtBottom:re}=Yt({initial:`instant`,resize:`instant`}),E=(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]),ie=(0,Q.useMemo)(()=>Ut(E),[E]),ae=!!r||a,[D,oe]=(0,Q.useState)(null),se=(0,Q.useCallback)(e=>{S(e),oe(e)},[S]),ce=(0,Q.useRef)(new Map),O=(0,Q.useMemo)(()=>{let e=ce.current,t=new Map;for(let n=0;n<E.length;n++){let r=E[n];if(r.role!==`assistant`||E[n+1]?.role===`assistant`)continue;let i=`${r.id}:${r.events?.length??0}`,a=e.get(i);a||(a=_n(vn(E,n)),e.set(i,a)),a.length>0&&t.set(n,a)}return t},[E]),k=(0,Q.useRef)(null),A=(0,Q.useCallback)(e=>{D&&(k.current?.(),k.current=cn(D,e))},[D]);(0,Q.useEffect)(()=>()=>k.current?.(),[]);let[j,le]=(0,Q.useState)(!1),[ue,de]=(0,Q.useState)(null),M=(0,Q.useRef)(null);(0,Q.useLayoutEffect)(()=>{let e=D;e&&M.current!=null&&(e.scrollTop=e.scrollHeight-M.current,j||(M.current=null))},[E.length,D,j]),(0,Q.useLayoutEffect)(()=>{D&&w({animation:`instant`})},[h,D]);let N=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>{D&&D.clientHeight>0&&(N.current=re)},[re,D]),(0,Q.useEffect)(()=>{let e=D;if(!e)return;let t=e.clientHeight,n=new ResizeObserver(()=>{let n=e.clientHeight,r=t===0&&n>0;t=n,r&&!N.current&&ne()});return n.observe(e),()=>n.disconnect()},[D,ne]);let P=(0,Q.useCallback)((e,t)=>{f?.(e,t)},[f]),F=(0,Q.useCallback)((e,t,n)=>{p?.(e,t,n)},[p]),fe=(0,Q.useCallback)(e=>{te?.(e)},[te]),I=(0,Q.useMemo)(()=>E.reduce((e,t)=>t.role===`system`?e+1:e,0),[E]),pe=(0,Q.useMemo)(()=>E.reduce((e,t,n)=>(t.role===`user`&&e.push(n),e),[]),[E]),R=(0,Q.useCallback)(()=>{if(!y||!b)return null;for(let e of E){if(b(e.id))continue;let t=ar(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=ar(t.content||``);if(n)return{id:e.id,jsonlPath:n}}}}return null},[E,y,b])(),me=!!R,he=R?.id??null,ge=R?.jsonlPath??null,z=(0,Q.useCallback)(async()=>{if(!he||!ge||!y||j)return;let e=D;M.current=e?e.scrollHeight-e.scrollTop:null,le(!0),de(null);try{await y(he,ge)}catch(e){de(e instanceof Error?e.message:`Could not load previous conversation`)}finally{le(!1)}},[he,ge,y,j,D]),B=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let e=D,t=B.current;if(!e||!t||!me||ue)return;let n=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&z()},{root:e,rootMargin:`400px 0px 0px 0px`});return n.observe(t),()=>n.disconnect()},[D,me,ue,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)(_e,{className:`size-10 text-text-subtle animate-pulse`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!a?(0,$.jsx)(Hr,{projectName:d||``,onSelectSession:s||(()=>{})}):(0,$.jsxs)(`div`,{className:`relative flex-1 overflow-hidden flex flex-col min-h-0`,children:[(0,$.jsx)(nr,{projectName:d,sessionId:h,messages:e}),I>1&&x&&(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:x,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)(T,{className:`size-3.5`}),`Clear all errors (`,I,`)`]})}),!j&&ue&&(0,$.jsx)(`div`,{className:`absolute top-2 left-0 right-0 z-10 flex justify-center`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{de(null),z()},className:`inline-flex items-center gap-1.5 rounded-md border border-border bg-surface px-3 py-2 text-xs text-text-primary hover:bg-surface-hover min-h-[44px] md:min-h-0`,children:[(0,$.jsx)(L,{className:`size-3.5 text-destructive`}),(0,$.jsxs)(`span`,{children:[`Could not load previous conversation: `,ue]}),(0,$.jsx)(`span`,{className:`underline`,children:`Retry`})]})}),(0,$.jsx)(`div`,{ref:se,[st]:``,className:`flex-1 overflow-y-auto overflow-x-hidden [overflow-anchor:none]`,style:{WebkitOverflowScrolling:`touch`,overscrollBehavior:`contain`},children:(0,$.jsxs)(`div`,{ref:C,className:`w-full`,children:[me&&(0,$.jsx)(`div`,{ref:B,"aria-hidden":!0,className:`h-px`}),j&&(0,$.jsx)(Xr,{}),E.map((e,t)=>{let n=t>0?E[t-1]:void 0,r=ie[t]??0,i=r?ee?.[r]:void 0,o=e.role===`user`&&m!=null&&e.id===m,s=E[t+1],c=e.role===`assistant`&&s?.role!==`assistant`,l;if(c){let e=[];for(let n=t;n>=0&&E[n].role===`assistant`;n--){let t=Qr(E[n]);t&&e.unshift(t)}l=e.join(`
6
-
7
- `)}return(0,$.jsx)(`div`,{"data-msg-index":t,className:`px-4 pt-4 select-none`,children:(0,$.jsx)(or,{fallbackContent:e.content,children:(0,$.jsx)($r,{message:e,isStreaming:a&&e.id.startsWith(`streaming-`),isLastAssistantInTurn:c,turnCopyText:l,turnChanges:c?O.get(t):void 0,onJumpToEdit:A,projectName:d,onFork:e.role===`user`&&f?P:void 0,onEdit:e.role===`user`&&p?F:void 0,isEditing:o,onDismiss:e.role===`system`&&te?fe:void 0,prevMsgId:n?.sdkUuid??n?.id,sessionId:h,providerId:g,versionGroup:i,onNavigateVersion:_,versionNavDisabled:a,bashPartialOutput:v})})},e.id)}),ae&&(0,$.jsxs)(`div`,{className:`px-4 pt-4 pb-4 space-y-4 select-none`,children:[r&&(r.tool===`AskUserQuestion`?(0,$.jsx)(ti,{approval:r,onRespond:i}):(0,$.jsx)(ei,{approval:r,onRespond:i})),a&&(0,$.jsx)(Vr,{lastMessage:e[e.length-1],phase:o,elapsed:c,statusMessage:u===`compacting`?`Compacting messages...`:l})]})]})}),(0,$.jsx)(Kr,{scrollElement:D,userIndices:pe,scrollToBottom:w})]})}function Qr(e){return e.events?.length?e.events.filter(e=>e.type===`text`).map(e=>e.content).join(``):e.content}var $r=(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:p,versionGroup:m,onNavigateVersion:h,versionNavDisabled:g,bashPartialOutput:_}){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)(kr,{content:e.content,messageId:e.id,timestamp:e.timestamp,projectName:o,onFork:t,onEdit:n,isEditing:l,sessionId:f,providerId:p,versionGroup:m,onNavigateVersion:h,versionNavDisabled:g})}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)(L,{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)(T,{className:`size-4`})})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.events&&e.events.length>0?(0,$.jsx)(Rr,{events:e.events,isStreaming:t,projectName:o,bashPartialOutput:_}):e.content&&(0,$.jsx)(`div`,{className:`text-sm text-text-primary select-text`,children:(0,$.jsx)(dr,{content:e.content,projectName:o})}),!t&&n&&e.usage&&(0,$.jsx)(Xn,{usage:e.usage}),!t&&n&&(0,$.jsx)(zn,{timestamp:e.timestamp,content:r??Qr(e),changes:i,onJumpToEdit:a})]})});function ei({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)(fe,{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 ti({approval:e,onRespond:t}){return(0,$.jsx)(Yr,{questions:e.input.questions??[],onSubmit:n=>t(e.requestId,!0,n),onSkip:()=>t(e.requestId,!1)})}function ni({shells:e,onKill:t}){let n=Je(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)(F,{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)(C,{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)(I,{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)(pe,{className:`size-3.5`})})]},e.shellId))})}function ri(e){if(!e)return;let t=e.split(`:`).pop();return t&&t!==`general-purpose`?t:e}function ii(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 ai(e){return e.lastTool?e.lastToolArg?`${e.lastTool}: ${e.lastToolArg}`:e.lastTool:e.lastNarrative??e.description}function oi({teamName:e,members:t,projectName:n}){let r=dt(),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=ai(t),a=ii(t.startedAt),o=ri(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)(_,{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 si=5e3;function ci(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 G.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),si);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 li(){let e=window;return e.SpeechRecognition??e.webkitSpeechRecognition??null}function ui(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`&&li()!==null;return{isListening:t,interimText:r,start:(0,Q.useCallback)(t=>{let r=li();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 di=2e3;function fi(e,t,n=di){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 pi=4096;function mi(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 hi(e,t){return e===`image/gif`?!0:e===`image/webp`?mi(t,`ANIM`):e===`image/png`||e===`image/apng`?mi(t,`acTL`):!1}async function gi(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,pi).arrayBuffer());return hi(e.type,t)}catch{return!0}}var _i=1600,vi=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]);function yi(e){return e===`image/jpeg`||e===`image/webp`?e:`image/png`}async function bi(e,t=_i){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=fi(i.width,i.height,t+1);if(a&&await gi(e))return r.close?.(),Math.max(i.width,i.height)<2e3&&vi.has(e.type)?{kind:`inlineable`,file:e,from:i}:{kind:`asis`,file:e,from:i};if(!a)return r.close?.(),vi.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=yi(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 xi=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]);function Si(e){return xi.has(e.type)}function Ci(e){return e.textContent?`expand`:e.previewUrl?`preview`:`none`}function wi({attachments:e,onRemove:t}){let[n,r]=(0,Q.useState)(null),i=Xe(),a=(0,Q.useRef)(new Map),s=qe(e=>e.open),c=qe(e=>e.close),l=qe(e=>e.src);if((0,Q.useEffect)(()=>{if(!l)return;let t=a.current.get(l);if(!t)return;let n=e.find(e=>e.id===t);if(!n?.previewUrl)return c();n.previewUrl!==l&&(a.current.set(n.previewUrl,n.id),s(n.previewUrl,n.name))},[e,l,s,c]),e.length===0)return null;let u=n?e.find(e=>e.id===n):null;function d(t,n){if(t.previewUrl){for(let t of e)t.previewUrl&&a.current.set(t.previewUrl,t.id);s(t.previewUrl,t.name,ct(n))}}return(0,$.jsxs)(`div`,{className:`px-2 md:px-4 pt-2`,children:[(0,$.jsx)(`div`,{className:K(`flex flex-wrap gap-1.5`,i&&`gap-y-5`),[st]:``,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`,Ci(e)!==`none`&&`cursor-pointer hover:border-primary/50`,n===e.id&&`border-primary/50 bg-surface-elevated`),onClick:t=>{let i=Ci(e);i===`expand`?r(n===e.id?null:e.id):i===`preview`&&d(e,t.currentTarget)},children:[e.previewUrl?(0,$.jsx)(`button`,{type:`button`,title:`Preview ${e.name}`,"aria-label":`Preview ${e.name}`,onClick:t=>{t.stopPropagation(),d(e,t.currentTarget)},className:K(`relative shrink-0 rounded`,`can-hover:hover:ring-2 can-hover:hover:ring-primary/60 transition-shadow`,i&&`before:absolute before:-inset-y-3 before:-inset-x-1.5 before:content-['']`),children:(0,$.jsx)(`img`,{src:e.previewUrl,alt:e.name,[lt]:``,className:`size-5 rounded object-cover`})}):e.textContent?(0,$.jsx)(C,{className:`size-3.5 shrink-0 text-text-subtle`}):e.isImage?(0,$.jsx)(ie,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,$.jsx)(D,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name}),e.textContent&&(0,$.jsx)(ee,{className:K(`size-3 shrink-0 text-text-subtle transition-transform`,n===e.id&&`rotate-180`)}),e.status===`uploading`?(0,$.jsx)(F,{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:K(`relative shrink-0 rounded-sm p-0.5 hover:bg-border/50 transition-colors`,i&&`before:absolute before:-inset-y-3.5 before:-inset-x-1.5 before:content-['']`),"aria-label":`Remove ${e.name}`,children:(0,$.jsx)(o,{className:`size-3`})})]},e.id))}),u?.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:Ti(u.textContent)})]})}function Ti(e){let t=e.trim(),n=t.match(/^```\w*\n([\s\S]*?)\n```$/);return n?n[1]:t}function Ei(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 Di=[{id:`default`,label:`Ask before edits`,icon:x,description:`Claude will ask for approval before making each edit`},{id:`acceptEdits`,label:`Edit automatically`,icon:ae,description:`Claude will edit files without asking first`},{id:`plan`,label:`Plan mode`,icon:h,description:`Claude will present a plan before editing`},{id:`bypassPermissions`,label:`Bypass permissions`,icon:j,description:`Claude will not ask before running commands`}];function Oi(e){return Di.find(t=>t.id===e)?.label??`Unknown`}function ki(e){return Di.find(t=>t.id===e)?.icon??x}function Ai({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=Di.findIndex(t=>t.id===e),a.current<0&&(a.current=0))},[n,e]);let o=(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+Di.length)%Di.length,(i.current?.querySelector(`[data-idx="${a.current}"]`))?.focus()}if(e.key===`Enter`){e.preventDefault();let n=Di[a.current];n&&(t(n.id),r(!1))}},[t,r]);return n?(0,$.jsxs)(`div`,{ref:i,role:`listbox`,"aria-label":`Permission modes`,onKeyDown:o,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:Di.map((n,i)=>{let a=n.icon,o=n.id===e;return(0,$.jsxs)(`button`,{"data-idx":i,role:`option`,"aria-selected":o,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 ${o?`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})]}),o&&(0,$.jsx)(B,{className:`size-4 mt-0.5 shrink-0 text-primary`})]},n.id)})})]}):null}var ji=[{label:`Low`,value:`low`},{label:`Medium`,value:`medium`},{label:`High`,value:`high`,default:!0},{label:`Extra`,value:`xhigh`},{label:`Max`,value:`max`}];function Mi(e){return e?ji.find(t=>t.value===e)?.label??e:``}function Ni(e,t){let n=Mi(t);return n?`${e} · ${n}`:e}function Pi(e){return e.replace(/^Claude\s+/i,``)}var Fi=ji.find(e=>e.default).value;function Ii({model:e,effort:t,thinking:n,onModelChange:r,onEffortChange:i,onThinkingChange:a,projectName:o,providerId:s,disabled:c}){let[l,u]=(0,Q.useState)([]),[d,f]=(0,Q.useState)(!1),p=(0,Q.useRef)(null),m=Ae();(0,Q.useEffect)(()=>{!o||!s||G.get(`${W(o)}/chat/providers/${s}/models`).then(u).catch(()=>{})},[o,s]),(0,Q.useEffect)(()=>{c&&f(!1)},[c]),(0,Q.useEffect)(()=>{if(!d||m)return;let e=e=>{p.current&&!p.current.contains(e.target)&&f(!1)},t=p.current?.ownerDocument??document;return t.addEventListener(`mousedown`,e),()=>t.removeEventListener(`mousedown`,e)},[d,m]);let h=l.find(t=>t.value===e),g=h?Pi(h.label):e?Pi(e):`Model`,_=t??Fi,ee=l.length>1,v=Ni(g,_),y=e=>{e(),m||f(!1)},b=(0,$.jsxs)(`div`,{className:`flex divide-x divide-border`,children:[ee&&(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 py-1`,children:[(0,$.jsx)(Li,{children:`Model`}),l.map(t=>(0,$.jsxs)(zi,{active:t.value===e,onClick:()=>y(()=>r(t.value)),children:[(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:Pi(t.label)}),t.value===e&&(0,$.jsx)(B,{className:`size-4 shrink-0 text-primary`})]},t.value))]}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 py-1`,children:[(0,$.jsx)(Li,{children:`Effort`}),ji.map(e=>(0,$.jsxs)(zi,{active:e.value===_,onClick:()=>y(()=>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===_&&(0,$.jsx)(B,{className:`size-4 shrink-0 text-primary`})]},e.value)),(0,$.jsx)(Ri,{}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>a(!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)(oe,{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:c,onClick:e=>{e.stopPropagation(),c||f(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 ${g}, effort ${_}${n?`, thinking on`:``}`,title:c?`Can't change while running`:v,children:[(0,$.jsx)(me,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`max-w-[140px] truncate`,children:v}),n&&(0,$.jsx)(oe,{className:`h-3 w-3 shrink-0`})]}),d&&!c&&(m?(0,$.jsx)(Fe,{open:d,onClose:()=>f(!1),children:(0,$.jsx)(`div`,{className:`px-1 pb-2`,children:b})}):(0,$.jsx)(`div`,{ref:p,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:b}))]})}function Li({children:e}){return(0,$.jsx)(`div`,{className:`px-3 py-1.5 text-xs font-medium text-text-secondary`,children:e})}function Ri(){return(0,$.jsx)(`div`,{className:`my-1 border-t border-border`})}function zi({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 Bi=6e4,Vi=new Map;function Hi(e,t,n){let r=`${e}\0${t??``}\0${n??``}`,i=Vi.get(r);if(i&&Date.now()<i.expiresAt)return i.promise;let a=new URLSearchParams;t&&a.set(`providerId`,t),n&&a.set(`sessionId`,n);let o=a.size>0?`?${a}`:``,s=G.get(`${W(e)}/chat/slash-items${o}`).then(e=>({items:e.items??[],recentNames:e.recentNames??[]})).catch(e=>{throw Vi.get(r)?.promise===s&&Vi.delete(r),e});return Vi.set(r,{promise:s,expiresAt:Date.now()+Bi}),s}function Ui(e){if(!e){Vi.clear();return}let t=`${e}\0`;for(let e of Vi.keys())e.startsWith(t)&&Vi.delete(e)}async function Wi(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 Gi=(0,Q.memo)(function({tabId:e,onSend:t,isStreaming:n,onCancel:r,disabled:i,projectName:a,onSlashStateChange:s,onSlashItemsLoaded:c,slashSelected:l,onFileStateChange:u,onFileItemsLoaded:d,fileSelected:f,externalFiles:p,externalPaths:m,onExternalPathsConsumed:h,initialValue:g,clearSignal:_,onContentChange:ee,getUserHistory:v,autoFocus:y,permissionMode:b,onModeChange:x,providerId:S,sessionId:C,onProviderChange:w,model:ne,onModelChange:T,effort:re,onEffortChange:E,thinking:ie,onThinkingChange:ae}){let D=(0,Q.useRef)(g??``),[oe,ce]=(0,Q.useState)(()=>(g??``).trim().length>0),[O,k]=(0,Q.useState)([]),[j,le]=(0,Q.useState)(null),[ue,de]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(!1),[P,fe]=(0,Q.useState)(`next`),I=(0,Q.useRef)(null),L=(0,Q.useRef)(null),R=(0,Q.useRef)(null),me=(0,Q.useRef)([]),he=(0,Q.useRef)([]),ge=(0,Q.useRef)(0),z=(0,Q.useRef)(!1),B=(0,Q.useRef)(!1),ve=(0,Q.useRef)(typeof CSS>`u`||!CSS.supports(`field-sizing`,`content`)),V=(0,Q.useCallback)(e=>{D.current=e,I.current&&(I.current.value=e),L.current&&(L.current.value=e),ce(e.trim().length>0)},[]),H=(0,Q.useCallback)(()=>window.matchMedia(`(min-width: 768px)`).matches?I.current:L.current,[]),be=(0,Q.useRef)(-1),xe=(0,Q.useCallback)(e=>{let t=Ei(v?.()??[],be.current,e);if(!t)return!1;be.current=t.index;let{agent:n,text:r}=xr(t.text);le(n),V(r);let i=H();return i?(i.focus(),requestAnimationFrame(()=>{i.selectionStart=i.selectionEnd=r.length}),ve.current&&(i.style.height=`auto`,i.style.height=Math.min(i.scrollHeight,i===L.current?80:160)+`px`),!0):!0},[v,V,H]),U=ui(),G=(0,Q.useRef)(``),Ce=(0,Q.useCallback)(e=>{let t=G.current;V(t?t+` `+e:e),ve.current&&requestAnimationFrame(()=>{let e=H();e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,160)+`px`)})},[V,H]),we=(0,Q.useCallback)(()=>{U.isListening?U.stop():(G.current=D.current.trim(),U.start(Ce))},[U.isListening,U.start,U.stop,Ce]);(0,Q.useEffect)(()=>{let e=()=>{U.supported&&Tn(H())&&we()};return window.addEventListener(`toggle-voice-input`,e),()=>window.removeEventListener(`toggle-voice-input`,e)},[U.supported,we,H]),(0,Q.useEffect)(()=>{let t=t=>{let{text:n,label:r,targetTabId:i}=t.detail??{};if(!n||(i?i!==e:!Tn(H())))return;window.dispatchEvent(new Event(pt));let a={id:Ee(),name:r??`Terminal output`,file:new File([],`terminal-output.txt`),isImage:!1,textContent:n,status:`ready`};k(e=>[...e,a]),H()?.focus()};return window.addEventListener(ft,t),()=>window.removeEventListener(ft,t)},[H,e]),(0,Q.useEffect)(()=>{g&&!D.current&&(V(g),setTimeout(()=>{let e=I.current;e&&(e.focus(),e.selectionStart=e.selectionEnd=e.value.length)},50))},[g]),(0,Q.useEffect)(()=>{_&&V(``)},[_]),(0,Q.useEffect)(()=>{y&&setTimeout(()=>{H()?.focus()},100)},[]);let Te=(0,Q.useCallback)(()=>{if(!a){me.current=[],c?.([],[]);return}Hi(a,S,C).then(e=>{me.current=e.items,c?.(e.items,e.recentNames)}).catch(()=>{me.current=[],c?.([],[])})},[a,S,C,c]);(0,Q.useEffect)(()=>{Te()},[Te]),(0,Q.useEffect)(()=>{let e=()=>{Ui(a),Te()};return window.addEventListener(`ppm:slash-items-refresh`,e),()=>window.removeEventListener(`ppm:slash-items-refresh`,e)},[Te,a]),(0,Q.useEffect)(()=>{let e=()=>{if(!a){he.current=[],d?.([]);return}let{fileIndex:e}=ke.getState(),t=e.map(e=>({name:e.name,path:e.path,type:e.type}));he.current=t,d?.(t)};e();let t=ke.getState().fileIndex,n=ke.getState().indexStatus;return ke.subscribe(r=>{(r.fileIndex!==t||r.indexStatus!==n)&&(t=r.fileIndex,n=r.indexStatus,e())})},[a]),(0,Q.useEffect)(()=>{if(!l)return;let e=H();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);le(l.name),V(t+i),s?.(!1,``),z.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} `);V(o+i),s?.(!1,``),z.current=!1,u?.(!1,``),B.current=!1,e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=o.length},0)},[l]),(0,Q.useEffect)(()=>{if(!f)return;let e=H();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;V(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} `;V(n),setTimeout(()=>{e.selectionStart=e.selectionEnd=n.length,e.focus()},0)}u?.(!1,``),B.current=!1},[f]),(0,Q.useEffect)(()=>{!p||p.length===0||De(p)},[p]),(0,Q.useEffect)(()=>{if(!m||m.length===0)return;let e=m.map(e=>`@${e}`).join(` `),t=D.current;V(t+(t.length>0&&!t.endsWith(` `)?` `:``)+e+` `),H()?.focus(),h?.()},[m]);let K=(0,Q.useCallback)(async e=>{if(!a)return;let t=e.split(/[\\/]/).pop();if(t)try{let e={},n=Se();n&&(e.Authorization=`Bearer ${n}`),await fetch(`${W(a)}/chat/uploads/${encodeURIComponent(t)}`,{method:`DELETE`,headers:e})}catch{}},[a]),q=(0,Q.useCallback)(async e=>{if(!a)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=Se();r&&(n.Authorization=`Bearer ${r}`);let i=await(await fetch(`${W(a)}/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}},[a]),De=(0,Q.useCallback)(async e=>{for(let t of e){let e=Ee(),n=Si(t),r={id:e,name:t.name,file:t,isImage:n,previewUrl:n?URL.createObjectURL(t):void 0,status:`uploading`};k(e=>[...e,r]);try{let i=n?await bi(t):null,a=i?.file??t,o=n&&a!==t?URL.createObjectURL(a):void 0,s=await q(a),c=i&&i.kind!==`asis`?await Wi(a):void 0,l=!!c&&c.data.length<=wt.maxBase64PerImage;o&&r.previewUrl&&URL.revokeObjectURL(r.previewUrl),k(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{k(t=>t.map(t=>t.id===e?{...t,status:`error`}:t))}}(L.current??I.current)?.focus()},[q]),J=(0,Q.useCallback)(e=>{k(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),n?.serverPath&&K(n.serverPath),t.filter(t=>t.id!==e)})},[K]),Oe=(0,Q.useCallback)(()=>{let e=D.current.trim(),r=O.filter(e=>e.status===`ready`);if(!e&&r.length===0&&!j){N(!1);return}let i=j?`Use the ${j} agent to ${e}`.trimEnd():e;s?.(!1,``),z.current=!1,u?.(!1,``),B.current=!1,U.isListening&&U.stop(),t(i,r,n?P:void 0),V(``);for(let e of O)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);k([]),le(null),N(!1),fe(`next`),be.current=-1,ve.current&&(I.current&&(I.current.style.height=`auto`),L.current&&(L.current.style.height=`auto`))},[O,j,t,s,u,n,P,V]),Ae=(0,Q.useCallback)(()=>{if(!i){if(O.some(e=>e.status===`uploading`)){(D.current.trim()||O.some(e=>e.status!==`error`))&&N(!0);return}Oe()}},[O,i,Oe]);(0,Q.useEffect)(()=>{M&&(O.some(e=>e.status===`uploading`)||Oe())},[M,O,Oe]);let je=(0,Q.useCallback)(e=>{if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),Ae();return}if((e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){if(!(be.current>=0)&&(e.key===`ArrowDown`||D.current!==``||j))return;xe(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(b??`bypassPermissions`)+1)%t.length];x?.(n)}},[Ae,b,x,xe,j]),Me=(0,Q.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.includes(`/`),i=n.includes(`@`);if(!r&&!i){z.current&&=(s?.(!1,``),!1),B.current&&=(u?.(!1,``),!1);return}if(r){let e=n.match(/(?:^|\s)\/(\S*)$/);if(e&&me.current.length>0){z.current||Te();let t=e[1]??``;s?.(!0,t),z.current=!0,B.current&&=(u?.(!1,``),!1);return}}if(i){let e=n.match(/@(\S*)$/);if(e&&he.current.length>0){u?.(!0,e[1]??``),B.current=!0,z.current&&=(s?.(!1,``),!1);return}}z.current&&=(s?.(!1,``),!1),B.current&&=(u?.(!1,``),!1)},[s,u,Te]),Ne=(0,Q.useCallback)(e=>{let t=e.target,n=t.value;D.current=n,be.current=-1;let r=t===I.current?L.current:I.current;r&&(r.value=n),ce(n.trim().length>0),Me(n,t.selectionStart),ee?.(n,O.filter(e=>e.status===`ready`&&e.serverPath).map(e=>({name:e.name,path:e.serverPath}))),ve.current&&(ge.current&&cancelAnimationFrame(ge.current),ge.current=requestAnimationFrame(()=>{ge.current=0,t.style.height=`auto`,t.style.height=Math.min(t.scrollHeight,t===L.current?80:160)+`px`}))},[Me,ee,O]),Pe=(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(),De(n))},[De]),Y=(0,Q.useCallback)(e=>{e.preventDefault();let t=e.dataTransfer.getData(`application/x-ppm-path`);if(t){let e=D.current;V(e+(e.length>0&&!e.endsWith(` `)?` `:``)+`@${t} `),H()?.focus();return}let n=Array.from(e.dataTransfer.files);n.length>0&&De(n)},[De,V,H]),Fe=(0,Q.useCallback)(e=>{e.preventDefault()},[]),Ie=(0,Q.useCallback)(()=>{R.current?.click()},[]),Le=(0,Q.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&De(t),e.target.value=``},[De]),Re=oe||O.some(e=>e.status!==`error`)||!!j,ze=n&&!Re;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=>{i||e.target instanceof HTMLTextAreaElement||H()?.focus()},children:[j&&(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)(_e,{className:`size-3.5 shrink-0`}),j,(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),le(null),H()?.focus()},className:`shrink-0 rounded-sm p-0.5 hover:bg-sky-500/20 transition-colors`,"aria-label":`Remove ${j} agent`,children:(0,$.jsx)(o,{className:`size-3`})})]})}),(0,$.jsx)(wi,{attachments:O,onRemove:J}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-2 pt-2 md:hidden relative`,children:[(0,$.jsx)(Ki,{mode:b??`bypassPermissions`,onClick:()=>de(e=>!e)}),(0,$.jsx)(Ai,{value:b??`bypassPermissions`,onChange:e=>x?.(e),open:ue,onOpenChange:de}),w&&a&&(0,$.jsx)(Z,{value:S??`claude`,onChange:w,projectName:a}),T&&a&&(0,$.jsx)(Ii,{model:ne??null,effort:re??null,thinking:ie??!1,onModelChange:T,onEffortChange:E??(()=>{}),onThinkingChange:ae??(()=>{}),projectName:a,providerId:S??`claude`,disabled:n}),n&&(0,$.jsx)(Ji,{value:P,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(),Ie()},disabled:i,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)(te,{className:`size-4`})}),(0,$.jsx)(`textarea`,{ref:L,defaultValue:g??``,onChange:Ne,onKeyDown:je,onPaste:Pe,onDrop:Y,onDragOver:Fe,placeholder:n?`Follow-up...`:`Ask anything...`,disabled:i,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]`}),U.supported&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),we()},disabled:i,className:`flex items-center justify-center size-8 shrink-0 rounded-[10px] transition-colors disabled:opacity-50 ${U.isListening?`bg-error text-white animate-pulse`:`text-text-3 hover:text-text-primary`}`,"aria-label":U.isListening?`Stop voice input`:`Start voice input`,children:U.isListening?(0,$.jsx)(se,{className:`size-4`}):(0,$.jsx)(ye,{className:`size-4`})}),ze?(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)(pe,{className:`size-3.5`})}):(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),M?N(!1):Ae()},disabled:i||!Re,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":M?`Cancel queued send`:`Send`,children:M?(0,$.jsx)(F,{className:`size-4 animate-spin`}):(0,$.jsx)(A,{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)(Ki,{mode:b??`bypassPermissions`,onClick:()=>de(e=>!e)}),(0,$.jsx)(Ai,{value:b??`bypassPermissions`,onChange:e=>x?.(e),open:ue,onOpenChange:de})]}),w&&a&&(0,$.jsx)(Z,{value:S??`claude`,onChange:w,projectName:a}),T&&a&&(0,$.jsx)(Ii,{model:ne??null,effort:re??null,thinking:ie??!1,onModelChange:T,onEffortChange:E??(()=>{}),onThinkingChange:ae??(()=>{}),projectName:a,providerId:S??`claude`,disabled:n}),n&&(0,$.jsx)(Ji,{value:P,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(),Ie()},disabled:i,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)(te,{className:`size-[17px]`})}),(0,$.jsx)(`textarea`,{ref:I,defaultValue:g??``,onChange:Ne,onKeyDown:je,onPaste:Pe,onDrop:Y,onDragOver:Fe,placeholder:n?`Follow-up or Stop...`:`Ask anything...`,disabled:i,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]`}),U.supported&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),we()},disabled:i,className:`flex items-center justify-center size-[34px] shrink-0 rounded-[10px] transition-colors disabled:opacity-50 ${U.isListening?`bg-error text-white animate-pulse`:`text-text-3 hover:text-text-primary hover:bg-surface-elevated`}`,"aria-label":U.isListening?`Stop voice input`:`Start voice input`,children:U.isListening?(0,$.jsx)(se,{className:`size-[17px]`}):(0,$.jsx)(ye,{className:`size-[17px]`})}),ze?(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)(pe,{className:`size-4`})}):(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),M?N(!1):Ae()},disabled:i||!Re,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":M?`Cancel queued send`:`Send message`,children:M?(0,$.jsx)(F,{className:`size-4 animate-spin`}):(0,$.jsx)(A,{className:`size-[17px]`})})]})]})]}),(0,$.jsx)(`input`,{ref:R,type:`file`,multiple:!0,className:`hidden`,onChange:Le})]})});function Ki({mode:e,onClick:t}){let n=ki(e),r=Oi(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 qi=[{value:`now`,label:`Interrupt`,Icon:E},{value:`next`,label:`Queue`,Icon:he},{value:`later`,label:`Later`,Icon:m}];function Ji({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=qi.find(t=>t.value===e)??qi[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 Yi(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 Xi(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=Yi(n,r.slice(0,n.length+i));return a<=i?{rank:2,distance:a}:null}var Zi=1;function Qi(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=Xi(t,n.name),o=[e,Xi(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?Zi: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 $i({items:e,filter:t,onSelect:n,onClose:r,visible:i,recentNames:a=[],projectName:o}){let[s,c]=(0,Q.useState)(0),[l,u]=(0,Q.useState)(!1),d=(0,Q.useRef)(null),f=(0,Q.useMemo)(()=>new Set(a),[a]),p=(0,Q.useMemo)(()=>{if(t)return{items:Qi(e,t,20,a),recentCount:0};if(a.length>0){let t=[],n=[];for(let r of e)f.has(r.name)?t.push(r):n.push(r);return t.sort((e,t)=>a.indexOf(e.name)-a.indexOf(t.name)),{items:[...t,...n],recentCount:t.length}}return{items:e,recentCount:0}},[e,t,a,f]),h=p.items,g=p.recentCount;(0,Q.useEffect)(()=>{c(0)},[t]),(0,Q.useEffect)(()=>{let e=d.current;e&&e.children[s]?.scrollIntoView({block:`nearest`})},[s]);let _=(0,Q.useCallback)(e=>{if(!i||h.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),c(e=>e>0?e-1:h.length-1),!0;case`ArrowDown`:return e.preventDefault(),c(e=>e<h.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),h[s]&&n(h[s]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,h,s,n,r]);(0,Q.useEffect)(()=>{if(!i)return;let e=e=>{_(e)&&e.stopPropagation()},t=d.current?.ownerDocument??document;return t.addEventListener(`keydown`,e,!0),()=>t.removeEventListener(`keydown`,e,!0)},[i,_]);let ee=(0,Q.useCallback)(()=>{!o||l||(u(!0),G.del(`${W(o)}/chat/slash-items/cache`).then(()=>{window.dispatchEvent(new CustomEvent(`ppm:slash-items-refresh`))}).finally(()=>u(!1)))},[o,l]);return!i||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:d,className:`py-1`,children:h.map((e,t)=>{let r=g>0&&t===0,i=g>0&&t===g;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)(m,{className:`size-3`}),`Recent`]}),o&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ee()},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)(y,{className:`size-3 ${l?`animate-spin`:``}`})})]}),i&&(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===s?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>c(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)(me,{className:`size-4 text-warning`}):e.type===`agent`?(0,$.jsx)(_e,{className:`size-4 text-sky-500`}):(0,$.jsx)(H,{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 ea({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 u=(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=>{u(e)&&e.stopPropagation()},t=s.current?.ownerDocument??document;return t.addEventListener(`keydown`,e,!0),()=>t.removeEventListener(`keydown`,e,!0)},[i,u]),!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)(l,{className:`size-4 text-warning`}):(0,$.jsx)(le,{className:`size-4 text-primary`})}),(0,$.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}var ta=e=>`${(e/1048576).toFixed(2)} MB`;function na(e){return e>=1048576?`${(e/1048576).toFixed(1)} MB`:`${Math.max(1,Math.round(e/1024))} KB`}function ra(){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 ia({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 G.get(`${W(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),G.post(`${W(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`,` · `,na(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)(Me,{size:`sm`,variant:`destructive`,disabled:o!==null,onClick:()=>u(`oversized`,!0),children:[o===`oversized`?(0,$.jsx)(F,{className:`size-3.5 animate-spin`}):(0,$.jsx)(f,{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 `,na(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)(Me,{size:`sm`,variant:`outline`,className:`flex-1`,disabled:o!==null||n.oversized===0,onClick:()=>u(`oversized`),children:[o===`oversized`?(0,$.jsx)(F,{className:`size-3.5 animate-spin`}):(0,$.jsx)(f,{className:`size-3.5`}),`Remove oversized`,n.oversized>0?` (${n.oversized} · ${na(n.oversizedBytes)})`:``]}),(0,$.jsxs)(Me,{size:`sm`,variant:`destructive`,className:`flex-1`,disabled:o!==null||n.total===0,onClick:()=>u(`all`),children:[o===`all`?(0,$.jsx)(F,{className:`size-3.5 animate-spin`}):(0,$.jsx)(f,{className:`size-3.5`}),`Remove all`,n.total>0?` (${n.total} · ${na(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 aa({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 G.get(`${W(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+Vn(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 ·`,` `,Yn(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=Gn(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:Yn(Bn(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 oa({sessionId:e,projectName:t,open:n,onOpenChange:r}){let[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(!1),c=Ae();(0,Q.useEffect)(()=>{n&&(s(!1),a(null),G.get(`${W(t)}/chat/sessions/${e}/debug?project=${encodeURIComponent(t)}`).then(e=>{let t=e.jsonlSizeBytes==null?``:` (${ta(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,...ra()].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)(V,{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)(Me,{size:`sm`,onClick:()=>{i&&Re(i).then(e=>{e&&(s(!0),setTimeout(()=>s(!1),1500))})},disabled:!i,className:`w-full`,children:o?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(d,{className:`size-3.5`}),` Copied!`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{className:`size-3.5`}),` Copy`]})}),(0,$.jsx)(`div`,{className:`border-t border-border pt-3`,children:n&&(0,$.jsx)(aa,{sessionId:e,projectName:t})}),(0,$.jsx)(`div`,{className:`border-t border-border pt-3`,children:n&&(0,$.jsx)(ia,{sessionId:e,projectName:t})})]});return c?(0,$.jsx)(Fe,{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)(Y,{open:n,onOpenChange:r,children:(0,$.jsxs)(Ne,{className:`sm:max-w-lg`,children:[(0,$.jsx)(Pe,{className:`sr-only`,children:`Session debug info`}),l]})})}function sa({hasUnread:e,onToggleUnread:t,onOpenDebug:n}){return(0,$.jsxs)(tt,{children:[(0,$.jsx)(Ve,{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)(v,{className:`size-3.5`})})}),(0,$.jsxs)(X,{align:`end`,side:`top`,className:`min-w-[190px]`,children:[(0,$.jsx)(Le,{onClick:t,className:`max-md:py-3`,children:e?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ue,{className:`size-3.5 text-warning`}),` Mark as read`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(xe,{className:`size-3.5 fill-current text-primary`}),` Mark as unread`]})}),(0,$.jsxs)(Le,{onClick:n,className:`max-md:py-3`,children:[(0,$.jsx)(V,{className:`size-3.5`}),` Session debug info`]})]})]})}function ca({title:e,meta:t,onClose:n,onReload:r,reloading:i,error:a,onDismissError:s,cardCount:c,children:l,fallback:u,footer:d}){let[f,p]=(0,Q.useState)(!1),m=c||1,h=Math.ceil(Math.sqrt(m)),g=Math.ceil(m/h);return(0,$.jsxs)(`div`,{className:`relative border-b border-border bg-surface px-3 py-2.5 ${f?`fixed inset-0 z-50 flex flex-col gap-2.5 overflow-hidden`:`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:e}),t]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsxs)(Be,{children:[(0,$.jsx)(Qe,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:()=>Ge(`accounts`),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-primary px-1 cursor-pointer`,children:[`Manage accounts `,(0,$.jsx)(k,{className:`size-3`})]})}),(0,$.jsx)(Ie,{side:`top`,children:`Add, remove or rotate accounts`})]}),c>0&&(0,$.jsxs)(Be,{children:[(0,$.jsx)(Qe,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:()=>p(e=>!e),className:`text-xs text-text-subtle hover:text-text-primary px-1 cursor-pointer`,"aria-label":f?`Exit fullscreen`:`Fullscreen view`,children:f?(0,$.jsx)(S,{className:`size-3`}):(0,$.jsx)(de,{className:`size-3`})})}),(0,$.jsx)(Ie,{side:`top`,children:f?`Exit fullscreen`:`Fullscreen view`})]}),r&&(0,$.jsxs)(Be,{children:[(0,$.jsx)(Qe,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:r,disabled:i,className:`text-xs text-text-subtle hover:text-text-primary px-1 disabled:opacity-50 cursor-pointer`,"aria-label":`Refresh usage`,children:(0,$.jsx)(y,{className:`size-3 ${i?`animate-spin`:``}`})})}),(0,$.jsx)(Ie,{side:`top`,children:`Refresh`})]}),(0,$.jsx)(`button`,{onClick:()=>{p(!1),n()},className:`text-xs text-text-subtle hover:text-text-primary px-1 cursor-pointer`,"aria-label":`Close usage panel`,children:(0,$.jsx)(o,{className:`size-3`})})]})]}),a&&(0,$.jsxs)(`div`,{className:`shrink-0 flex items-start gap-2 rounded border border-error/40 bg-error/10 px-2 py-1.5 text-[11px] text-error`,children:[(0,$.jsx)(`span`,{className:`flex-1`,children:a}),s&&(0,$.jsx)(`button`,{onClick:s,className:`shrink-0 text-error/70 hover:text-error cursor-pointer`,"aria-label":`Dismiss`,children:(0,$.jsx)(o,{className:`size-3`})})]}),c>0?(0,$.jsx)(`div`,{className:f?`flex-1 min-h-0 grid gap-2 overflow-hidden`:`flex gap-2 overflow-x-auto pb-1 -mx-3 px-3 snap-x snap-mandatory scrollbar-thin`,style:f?{gridTemplateColumns:`repeat(${h}, minmax(0, 1fr))`,gridTemplateRows:`repeat(${g}, minmax(0, 1fr))`}:void 0,children:l(f?`grid`:`strip`)}):u,d&&!f&&d]})}function la(e){return Math.round((e??0)*100)>=100}function ua({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastFetchedAt:a,onSelectAccount:o,selectedAccountId:s}){let[c,l]=(0,Q.useState)(null),{usages:u,accounts:d,activeAccountId:f,initialLoading:p,refreshing:m,flashIds:h,reload:g,toggle:_,togglingId:ee}=xt(t),[v,y]=(0,Q.useState)(null);if(!t)return null;let b=new Map(d.map(e=>[e.id,e]));function te(e,t){if(e){if(e.status===`disabled`)return`Disabled`;if(e.reauthRequired)return`Sign in again to use this account`;if(!e.hasRefreshToken&&e.expiresAt&&e.expiresAt<Math.floor(Date.now()/1e3))return`Token expired — sign in again`}let n=t?.usage.session;if(la(n?.utilization))return`5-hour limit reached${n?.resetsAt?` — resets ${gt(n)}`:``}`;let r=t?.usage.weekly;return la(r?.utilization)?`Weekly limit reached${r?.resetsAt?` — resets ${gt(r)}`:``}`:null}async function x(e,t){y(await _(e,t))}async function S(e){if(!o)return;let t=te(b.get(e),u.find(t=>t.accountId===e));if(t){y(`Cannot switch to this account — ${t.toLowerCase()}.`);return}l(e),y(null);try{y(await o(e,u.find(t=>t.accountId===e)?.accountLabel??null)??null)}finally{l(null)}}let C=e.queryCostUsd!=null||e.totalCostUsd!=null;return(0,$.jsx)(ca,{title:`Usage`,meta:a&&(0,$.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:ht(new Date(a).getTime())}),onClose:n,onReload:r?()=>{r(),g()}:void 0,reloading:i||m,error:v,onDismissError:()=>y(null),cardCount:u.length,fallback:p?(0,$.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`Loading...`}):e.session||e.weekly||e.weeklyOpus||e.weeklySonnet?(0,$.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,$.jsx)(vt,{label:`5-Hour Session`,bucket:e.session}),(0,$.jsx)(vt,{label:`Weekly`,bucket:e.weekly}),(0,$.jsx)(vt,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,$.jsx)(vt,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,$.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`No usage data available`}),footer:C?(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)]})]})]}):void 0,children:t=>u.map(n=>{let r=b.get(n.accountId);return(0,$.jsx)(_t,{entry:n,isActive:n.accountId===(s??e.activeAccountId??f),accountInfo:r,flash:h.has(n.accountId),layout:t,onSelect:o?S:void 0,unselectableReason:te(r,n),selecting:c===n.accountId,onToggle:x,toggling:ee===n.accountId},n.accountId)})})}function da(e){return Math.round((e??0)*100)>=100}function fa(e,t){return{accountId:e.id,accountLabel:e.label,accountStatus:e.status??`active`,isOAuth:e.type!==`apiKey`,usage:{session:t.session,weekly:t.weekly}}}function pa({onClose:e,usage:t,onReload:n,onSelectAccount:r,selectedAccountId:i}){let[a,o]=(0,Q.useState)([]),[s,c]=(0,Q.useState)({}),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(null),_=(0,Q.useCallback)(async()=>{u(!0);try{o((await G.get(`/api/codex-accounts`)).accounts),c(await G.get(`/api/codex-accounts/usage`))}catch{}finally{u(!1)}},[]);(0,Q.useEffect)(()=>{_()},[_]);let ee=(0,Q.useCallback)(async()=>{u(!0);try{await n?.(),c(await G.get(`/api/codex-accounts/usage`))}catch{}finally{u(!1)}},[n]),v=(0,Q.useCallback)((e,t)=>e.status===`disabled`?`Disabled`:da(t.fiveHour)?`5-hour limit reached${t.session?.resetsAt?` — resets ${gt(t.session)}`:``}`:da(t.sevenDay)?`Weekly limit reached${t.weekly?.resetsAt?` — resets ${gt(t.weekly)}`:``}`:null,[]),y=(0,Q.useCallback)(async e=>{if(!r)return;let t=a.find(t=>t.id===e);if(!t)return;let n=v(t,s[e]??{});if(n){g(`Cannot switch to this account — ${n.toLowerCase()}.`);return}f(e),g(null);try{g(await r(e,t.label)??null)}finally{f(null)}},[r,a,s,v]),b=(0,Q.useCallback)(async(e,t)=>{m(e),g(null);try{await G.patch(`/api/codex-accounts/${e}`,{status:t===`disabled`?`active`:`disabled`}),o((await G.get(`/api/codex-accounts`)).accounts)}catch(e){g(e.message||`Could not change the account`)}finally{m(null)}},[]),te=(0,Q.useCallback)(async(e,t)=>{m(e),g(null);try{await G.patch(`/api/codex-accounts/${e}`,{dailyGuardEnabled:!t}),o((await G.get(`/api/codex-accounts`)).accounts)}catch(e){g(e.message||`Could not change Daily guard`)}finally{m(null)}},[]),x=l&&a.length===0?(0,$.jsxs)(`div`,{className:`text-xs text-text-subtle flex items-center gap-2`,children:[(0,$.jsx)(F,{className:`size-3 animate-spin`}),` Loading…`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(bt,{active:!1,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium 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 shrink-0`,children:`~/.codex`})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(vt,{label:`5-Hour Session`,bucket:t.session}),(0,$.jsx)(vt,{label:`Weekly`,bucket:t.weekly}),!t.session&&!t.weekly&&(0,$.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`No usage data yet`})]})]}),(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.`]})]});return(0,$.jsx)(ca,{title:`Codex Usage`,onClose:e,onReload:n?()=>void ee():void 0,reloading:l,error:h,onDismissError:()=>g(null),cardCount:a.length,fallback:x,children:e=>a.map(n=>{let a=s[n.id]??{},o=a.session==null?St(a.weekly):null;return(0,$.jsx)(_t,{entry:fa(n,a),isActive:n.id===(i??t.activeAccountId),layout:e,planLabel:yt(n.planType),onSelect:r?y:void 0,unselectableReason:v(n,a),selecting:d===n.id,onToggle:b,toggling:p===n.id,dailyGuard:o?{enabled:!!n.dailyGuardEnabled,state:o}:void 0,onDailyGuardToggle:o?()=>void te(n.id,!!n.dailyGuardEnabled):void 0,dailyGuardToggling:p===n.id},n.id)})})}var ma={working:`working`,paused:`paused`,"no-transcript":`no session`};function ha({member:e,onOpen:t}){let n=e.workState===`working`,r=ai(e),i=ii(e.startedAt,n?void 0:e.lastEventAt),a=ri(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)(F,{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:ma[e.workState]}),(0,$.jsx)(N,{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 ga({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)(F,{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)(ha,{member:e,onOpen:n},e.name))})}var _a=[`subject`,`summary`,`text`,`message`,`content`,`description`,`reason`,`feedback`],va=[`description`,`message`,`content`,`reason`,`feedback`],ya=new Set([`type`,`taskId`,`task_id`,`assignedBy`,`assigned_by`,`timestamp`,`request_id`,`requestId`]),ba=e=>typeof e==`string`?e.trim():e==null?``:String(e);function xa(e,t,n){for(let r of t){if(r===n)continue;let t=ba(e[r]);if(t)return{key:r,value:t}}return null}function Sa(e){return Object.entries(e).filter(([e,t])=>!ya.has(e)&&ba(t)).map(([e,t])=>`${e}: ${ba(t)}`).join(` · `)}function Ca(e,t){let n=ba(t),r=ba(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||ba(e),...i?{detail:i}:{}}}if(!i||typeof i!=`object`||Array.isArray(i))return{title:n||r};let a=i,o=ba(a.taskId)||ba(a.task_id),s=xa(a,_a),c=xa(a,va,s?.key);return{title:n||s?.value||Sa(a)||ba(a.type)||r,...c?{detail:c.value}:{},...o?{taskId:o}:{}}}function wa({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?ot[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:Ea(e.color),children:e.from}),(0,$.jsx)(`span`,{children:`→`}),(0,$.jsx)(`span`,{children:e.to}),(0,$.jsx)(`span`,{className:`ml-auto text-[10px]`,children:Ta(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 Ta(e){try{return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}catch{return``}}function Ea(e){if(e&&(/^#[0-9a-fA-F]{3,8}$/.test(e)||/^[a-zA-Z]{3,20}$/.test(e)))return{color:e}}function Da(e,t){return e===t?`Team (current session)`:e}function Oa({teamNames:e,messages:t,sessionId:n,projectName:r}){let[i,a]=(0,Q.useState)(e[0]??``),[o,s]=(0,Q.useState)(`members`),c=dt(),l=Xe();(0,Q.useEffect)(()=>{e.length>0&&!e.includes(i)&&a(e[0])},[e,i]);let{members:u,outbound:d,loading:f,refresh:p}=ci(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:Da(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)(y,{className:K(`size-3`,f&&`animate-spin`)})})]}),o===`members`?(0,$.jsx)(ga,{members:u,loading:f,onOpenMember:m,className:`max-h-56`}):(0,$.jsx)(wa,{messages:h,className:`max-h-56`})]})}function ka(e){return e>=90?`text-error`:e>=70?`text-warning`:`text-success`}function Aa({projectName:e,usageInfo:t,usageLoading:n,refreshUsage:r,lastFetchedAt:i,sessionId:c,providerId:l,pickedAccountLabel:u,pickedAccountId:d,onSelectAccount:f,onSelectSession:m,onBugReport:h,isConnected:g,onReload:ee,teamActivity:v,teamMessages:b,onTeamOpen:te}){let[x,S]=(0,Q.useState)(null),[C,w]=(0,Q.useState)([]),[T,E]=(0,Q.useState)(!1),ie=et(e=>e.notifications),ae=et(e=>c?e.notifications.has(c):!1),D=et(e=>e.clearForSession),oe=et(e=>e.markUnread),[se,O]=(0,Q.useState)(``),k=He(se,300),[A,j]=(0,Q.useState)(null),[le,ue]=(0,Q.useState)(``),[de,N]=(0,Q.useState)(!1),[P,fe]=(0,Q.useState)(!1),[I,pe]=(0,Q.useState)([]),[L,R]=(0,Q.useState)(null),[me,he]=(0,Q.useState)({}),[V,H]=(0,Q.useState)(!1),[ye,be]=(0,Q.useState)(!1),xe=(0,Q.useRef)(null),U=Oe(e=>e.openTab),Se=e=>{S(t=>t===e?null:e)},Ce=(0,Q.useCallback)(async t=>{if(e){E(!0);try{let n=new URLSearchParams({limit:`50`,offset:`0`});t&&n.set(`q`,t);let r=await G.get(`${W(e)}/chat/sessions?${n}`);w(r.sessions),N(r.hasMore)}catch{}finally{E(!1)}}},[e]),we=(0,Q.useCallback)(async()=>{if(!(!e||P||!de)){fe(!0);try{let t=C.filter(e=>!e.pinned).length,n=new URLSearchParams({limit:`50`,offset:String(t)});k&&n.set(`q`,k);let r=await G.get(`${W(e)}/chat/sessions?${n}`);w(e=>{let t=new Set(e.map(e=>e.id)),n=r.sessions.filter(e=>!t.has(e.id));return[...e,...n]}),N(r.hasMore)}catch{}finally{fe(!1)}}},[e,P,de,C,k]);(0,Q.useEffect)(()=>{x===`history`&&C.length===0&&Ce()},[x]),(0,Q.useEffect)(()=>{x===`history`&&Ce(k||void 0)},[k]);let Te=(0,Q.useCallback)(async()=>{if(e)try{let t=await G.get(`${W(e)}/tags`);pe(t.tags),he(t.counts)}catch{}},[e]);(0,Q.useEffect)(()=>{x===`history`&&e&&Te()},[x,e,Te]);function Ee(t){m?(m(t),S(null)):U({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(),j(e.id),ue(e.title||``),setTimeout(()=>xe.current?.select(),0)},[]),De=(0,Q.useCallback)(async()=>{if(!A||!le.trim()||!e){j(null);return}try{await G.patch(`${W(e)}/chat/sessions/${A}`,{title:le.trim()}),w(e=>e.map(e=>e.id===A?{...e,title:le.trim()}:e))}catch{}j(null)},[A,le,e]),J=(0,Q.useCallback)(()=>j(null),[]),ke=(0,Q.useCallback)(async(t,n)=>{if(t.stopPropagation(),!e)return;let r=`${W(e)}/chat/sessions/${n.id}/pin`;try{n.pinned?await G.del(r):await G.put(r),w(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]),Ae=(0,Q.useCallback)(async(t,n)=>{if(t.stopPropagation(),e&&window.confirm(`Delete this session? This cannot be undone.`))try{await G.del(`${W(e)}/chat/sessions/${n.id}?providerId=${n.providerId}`),w(e=>e.filter(e=>e.id!==n.id))}catch{}},[e]),je=(0,Q.useCallback)((e,t)=>{w(n=>n.map(n=>n.id===e?{...n,tag:t}:n)),Te()},[Te]),Me=(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.`)){E(!0);try{await G.del(`${W(e)}/chat/sessions?olderThanDays=${n}`),Ce(k||void 0)}catch{}}},[e,Ce,k]);(0,Q.useEffect)(()=>{if(x!==`history`)return;let t=t=>{if(t.target instanceof HTMLInputElement||t.target instanceof HTMLTextAreaElement)return;let n=parseInt(t.key);if(n>=1&&n<=I.length&&c){let t=I[n-1];t&&(G.patch(`${W(e)}/chat/sessions/${c}/tag`,{tagId:t.id}).catch(()=>{}),je(c,{id:t.id,name:t.name,color:t.color}))}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[x,I,c,e,je]);let Ne=L===null?C:C.filter(e=>e.tag?.id===L),Pe=!l||l===`claude`,Y=l===`codex`,Fe=!d||d===t.activeAccountId,Ie=Fe&&t.fiveHour!=null?Math.round(t.fiveHour*100):null,Le=Fe&&t.sevenDay!=null?Math.round(t.sevenDay*100):null,Re=Ie!=null||Le!=null?ka(Math.max(Ie??0,Le??0)):`text-text-subtle`,Be=u??(Fe?t.activeAccountLabel:null)??null;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:()=>Se(`history`),className:`shrink-0 flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${x===`history`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,children:[(0,$.jsx)(p,{className:`size-3`}),(0,$.jsx)(`span`,{children:`History`})]}),c&&l&&l!==`mock`?(0,$.jsxs)(`button`,{onClick:()=>Se(`config`),className:`shrink-0 flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${x===`config`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,title:`AI Settings`,children:[(0,$.jsx)(Ue,{providerId:l}),(0,$.jsx)(`span`,{className:`capitalize`,children:l})]}):(0,$.jsx)(`button`,{onClick:()=>Se(`config`),className:`shrink-0 p-1 rounded transition-colors ${x===`config`?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary hover:bg-surface-elevated`}`,title:`AI Settings`,children:(0,$.jsx)(ge,{className:`size-3`})}),Pe||Y?(0,$.jsxs)(`button`,{onClick:()=>Se(`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 ${x===`usage`?`bg-primary/10`:``} ${Re}`,title:`Usage limits`,children:[(0,$.jsx)(z,{className:`size-3`}),Be&&(0,$.jsxs)(`span`,{className:`text-text-secondary font-normal truncate max-w-[110px]`,title:Be,children:[`[`,Be,`]`]}),(0,$.jsxs)(`span`,{children:[`5h:`,Ie==null?`--%`:`${Ie}%`]}),(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,$.jsxs)(`span`,{children:[`Wk:`,Le==null?`--%`:`${Le}%`]})]}):null,v?.hasTeams&&(0,$.jsxs)(`button`,{onClick:()=>{Se(`team`),te?.()},className:`shrink-0 relative flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${x===`team`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,title:`Team activity`,children:[(0,$.jsx)(_,{className:`size-3`}),(0,$.jsx)(`span`,{children:`Team`}),(v.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:[ee&&(0,$.jsxs)(`button`,{onClick:e=>{let t=e.currentTarget.querySelector(`svg`);t&&(t.classList.add(`animate-spin`),setTimeout(()=>t.classList.remove(`animate-spin`),600)),ee()},className:`relative size-4 flex items-center justify-center`,title:g?`Reload messages`:`Disconnected — click to reload`,children:[(0,$.jsx)(y,{className:`size-3 ${g?`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 ${g?`bg-success`:`bg-error animate-pulse`}`})]}),c&&(0,$.jsx)(sa,{hasUnread:ae,onToggleUnread:()=>ae?D(c):oe(c,e),onOpenDebug:()=>be(!0)})]})]}),c&&(0,$.jsx)(oa,{sessionId:c,projectName:e,open:ye,onOpenChange:be}),x===`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)(M,{className:`size-3 text-text-subtle shrink-0`}),(0,$.jsx)(`input`,{type:`text`,value:se,onChange:e=>O(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:Me,className:`p-0.5 rounded text-text-subtle hover:text-error transition-colors`,title:`Delete old sessions...`,children:(0,$.jsx)(s,{className:`size-3`})}),(0,$.jsx)(`button`,{onClick:()=>Ce(k||void 0),disabled:T,className:`p-0.5 rounded text-text-subtle hover:text-text-secondary transition-colors disabled:opacity-50`,title:`Refresh`,children:(0,$.jsx)(y,{className:`size-3 ${T?`animate-spin`:``}`})})]}),I.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:()=>R(null),className:`shrink-0 rounded-md border px-2 py-1 text-[10px] transition-colors ${L===null?`bg-primary/20 border-primary text-primary`:`border-border bg-surface text-text-secondary`}`,children:[`All (`,C.length,`)`]}),I.map(e=>(0,$.jsxs)(`button`,{onClick:()=>R(L===e.id?null:e.id),className:`shrink-0 flex items-center gap-1 rounded-md border px-2 py-1 text-[10px] transition-colors ${L===e.id?`border-current`:`border-border bg-surface`}`,style:L===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,` (`,me[e.id]??0,`)`]},e.id)),(0,$.jsx)(`button`,{onClick:()=>H(!V),className:`shrink-0 p-1 rounded transition-colors ${V?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary`}`,title:`Manage tags`,children:(0,$.jsx)(ce,{className:`size-3`})})]}),V&&(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)(ze,{projectName:e,onTagsChanged:Te})}),(0,$.jsx)(`div`,{className:`max-h-[200px] overflow-y-auto`,children:T&&C.length===0?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,$.jsx)(F,{className:`size-3.5 animate-spin text-text-subtle`})}):Ne.length===0?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-3 text-[11px] text-text-subtle`,children:se?`No matching sessions`:`No sessions yet`}):(0,$.jsxs)($.Fragment,{children:[Ne.map(t=>{let n=ie.get(t.id),r=!!n;return(0,$.jsx)(Ke,{session:t,projectName:e,projectTags:I,onTogglePin:ke,onStartEditing:q,onDeleteSession:Ae,onTagChanged:je,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&&We(n.type),!r&&`text-text-secondary`),children:[(0,$.jsx)(Ue,{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(),De()},children:[(0,$.jsx)(`input`,{ref:xe,value:le,onChange:e=>ue(e.target.value),onBlur:De,onKeyDown:e=>{e.key===`Escape`&&J()},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)(B,{className:`size-3`})}),(0,$.jsx)(`button`,{type:`button`,className:`p-0.5 text-text-subtle hover:text-text-secondary`,onClick:e=>{e.stopPropagation(),J()},children:(0,$.jsx)(o,{className:`size-3`})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{onClick:()=>Ee(t),className:`text-[11px] truncate flex-1 text-left flex items-center gap-1`,children:[t.title?.startsWith(`[PPM]`)&&(0,$.jsx)(_e,{className:`size-3 text-muted-foreground shrink-0`}),t.title?.startsWith(`[PPM]`)?t.title.slice(7):t.title||`Untitled`]}),(0,$.jsx)(`button`,{onClick:e=>ke(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)(re,{className:`size-3`}):(0,$.jsx)(ne,{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)(a,{className:`size-3`})}),(0,$.jsx)(`button`,{onClick:e=>Ae(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:$e(t.updatedAt)})]})},t.id)}),de&&(0,$.jsxs)(`button`,{onClick:we,disabled:P,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:[P?(0,$.jsx)(F,{className:`size-3 animate-spin`}):null,P?`Loading...`:`Load more`]})]})})]}),x===`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)(mt,{compact:!0})}),x===`team`&&v?.hasTeams&&(0,$.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2`,children:(0,$.jsx)(Oa,{teamNames:v.teamNames,messages:b??[],sessionId:c,projectName:e})}),x===`usage`&&Pe&&(0,$.jsx)(ua,{usage:t,onSelectAccount:f,selectedAccountId:d??t.activeAccountId??null,visible:!0,onClose:()=>S(null),onReload:r,loading:n,lastFetchedAt:i}),x===`usage`&&Y&&(0,$.jsx)(pa,{usage:t,onClose:()=>S(null),onReload:r,onSelectAccount:f,selectedAccountId:d??t.activeAccountId??null})]})}var ja=3e3;function Ma(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)},ja);return G.get(`${W(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__`;G.put(`${W(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__`;G.del(`${W(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 Na({metadata:e,tabId:t}){let[n,r]=(0,Q.useState)(e?.sessionId??null),i=(0,Q.useCallback)(e=>{r(e)},[]),[a,s]=(0,Q.useState)(e?.providerId??`claude`),[c,l]=(0,Q.useState)([]),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)([]),[ee,v]=(0,Q.useState)([]),[y,b]=(0,Q.useState)(!1),[te,x]=(0,Q.useState)(``),[S,C]=(0,Q.useState)(null),[w,ne]=(0,Q.useState)(e?.permissionMode??void 0),T=(0,Q.useRef)(null),[re,E]=(0,Q.useState)(!1),[ie,ae]=(0,Q.useState)(null),[D,oe]=(0,Q.useState)(null),[se,ce]=(0,Q.useState)(null),O=(0,Q.useRef)(0),k=e?.projectName??``,A=Oe(e=>e.updateTab),j=we(e=>e.version),{usageInfo:le,usageLoading:ue,lastFetchedAt:de,refreshUsage:M,reloadUsage:N}=Ht(k,a,n??void 0),{draft:fe,draftLoading:I,saveDraft:pe,clearDraft:L}=Ma(k,n);(0,Q.useEffect)(()=>{w||rt().then(e=>{let t=e.providers[e.default_provider??`claude`];ne(t?.permission_mode??`bypassPermissions`)}).catch(()=>{})},[]),(0,Q.useEffect)(()=>{!t||!n||A(t,{metadata:{...e,sessionId:n,providerId:a,permissionMode:w,pickedAccountId:void 0,pickedAccountLabel:void 0,pickedAccountProvider:void 0}})},[n,a,w]);let R=(0,Q.useCallback)(n=>{s(n),t&&A(t,{metadata:{...e,providerId:n}})},[t,e,A]),me=e?.pickedAccountId,he=e?.pickedAccountLabel,ge=e?.pickedAccountProvider,z=!!me&&ge===a;(0,Q.useEffect)(()=>{if(!t||n||z)return;let r=!1;return it(a).then(n=>{r||!n||A(t,{metadata:{...e,pickedAccountId:n.id,pickedAccountLabel:n.label,pickedAccountProvider:a}})}).catch(()=>{}),()=>{r=!0}},[t,n,a,z]);let _e=(0,Q.useCallback)(async(r,i)=>{if(n){try{await G.put(`${W(k)}/chat/sessions/${n}/account`,{accountId:r}),ve({id:r,label:i}),N(),Ce.success(`This chat will use the selected account from the next message.`)}catch(e){return e.message||`Could not switch account`}return null}return t&&A(t,{metadata:{...e,pickedAccountId:r,pickedAccountLabel:i,pickedAccountProvider:a}}),null},[n,k,t,e,a,A,N]),[B,ve]=(0,Q.useState)(null),{messages:V,renderedMessages:H,expandCompact:ye,isCompactExpanded:be,dismissMessage:xe,clearErrors:U,messagesLoading:Se,versionMap:K,isStreaming:Ee,phase:q,isReconnecting:J,connectingElapsed:ke,pendingApproval:Ae,contextWindowPct:je,compactStatus:Me,statusMessage:Ne,sessionTitle:Pe,liveAccount:Y,model:Fe,setModel:Ie,effort:Le,setEffort:Re,thinking:ze,setThinking:Be,sendMessage:X,respondToApproval:Ve,cancelStreaming:He,reconnect:Ue,refetchMessages:Z,isConnected:We,teamActivity:Ge,teamMessages:Ke,markTeamRead:qe,bashPartialOutput:Je,backgroundShells:Ye,killBackgroundShell:Xe}=Bt(n,a,k,i);(0,Q.useEffect)(()=>{Y&&ve(Y)},[Y]);let Qe=Y?.id;(0,Q.useEffect)(()=>{Qe&&N()},[Qe,N]),(0,Q.useEffect)(()=>{ve(null)},[n]);let $e=Ge?.teamNames?.[0]??``,{members:tt}=ci($e,!!$e);(0,Q.useEffect)(()=>{if(We&&T.current){let{content:e,permissionMode:t,images:n,imagePaths:r}=T.current;T.current=null,X(e,{permissionMode:t,...n?.length&&{images:n},...r?.length&&{imagePaths:r}})}},[We,X]),(0,Q.useEffect)(()=>{if(!n||!t)return;let e=()=>{if(document.hidden)return;let{panels:e}=De.getState();Object.values(e).some(e=>e.activeTabId===t)&&(et.getState().notifications.get(n)?.manual||et.getState().clearForSession(n))};e(),document.addEventListener(`visibilitychange`,e);let r=De.subscribe(e),i=et.subscribe(e);return()=>{document.removeEventListener(`visibilitychange`,e),r(),i()}},[n,t]),(0,Q.useEffect)(()=>{t&&Pe&&A(t,{title:Pe})},[Pe]);let[nt,at]=(0,Q.useState)(e?.pendingMessage),[ot,st]=(0,Q.useState)(null),[ct,lt]=(0,Q.useState)(!1),[ut,dt]=(0,Q.useState)(0),[ft,pt]=(0,Q.useState)(!1),mt=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{mt.current&&!Se&&pt(!1),mt.current=!!Se},[Se]);let[ht,gt]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{I||gt(!0)},[I]),(0,Q.useEffect)(()=>{nt&&We&&n&&t&&A(t,{metadata:{...e,pendingMessage:void 0}})},[We,n]),(0,Q.useEffect)(()=>{ct&&Ee&&lt(!1)},[ct,Ee]),(0,Q.useEffect)(()=>{if(!ct)return;let e=setTimeout(()=>lt(!1),6e4);return()=>clearTimeout(e)},[ct]);let _t=(0,Q.useCallback)((e,t)=>{Oe.getState().openTab({type:`chat`,title:e||`AI Chat`,metadata:{projectName:k,providerId:a,...t&&{clearedFrom:t}},projectId:k||null,closable:!0})},[k,a]),vt=(0,Q.useCallback)(e=>{lt(!1),r(e.id),s(e.providerId),t&&A(t,{title:e.title||`Chat`}),et.getState().clearForSession(e.id)},[t,A]),yt=(0,Q.useCallback)(async(e,t)=>{if(!(!n||!k))try{let{api:r,projectUrl:i}=await Te(async()=>{let{api:e,projectUrl:t}=await import(`./api-client-pQL53cDQ.js`);return{api:e,projectUrl:t}},__vite__mapDeps([41,6,1,2,12])),o=await r.post(`${i(k)}/chat/sessions/${n}/fork?providerId=${a}`,{messageId:t});Oe.getState().openTab({type:`chat`,title:`Fork: ${e.slice(0,30)}`,metadata:{projectName:k,sessionId:o.id,providerId:a,pendingMessage:e},projectId:k||null,closable:!0})}catch(e){console.error(`Fork failed:`,e);let t=e?.message||`Unknown error`;Ce.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,k,a]),bt=(0,Q.useCallback)((e,t,n)=>{at(e),st({anchorMsgId:t,ownMsgId:n})},[]),xt=(0,Q.useCallback)(()=>{st(null),at(void 0),lt(!1),L(),dt(e=>e+1)},[L]),St=(0,Q.useCallback)(async(i,o)=>{if(!(!i.trim()||!n||!k)){lt(!0);try{let s=await G.post(`${W(k)}/chat/sessions/${n}/fork?providerId=${a}&mode=edit`,{messageId:o});T.current={content:i,permissionMode:w},pt(!0),t&&A(t,{metadata:{...e,sessionId:s.id}}),r(s.id)}catch(e){lt(!1);let t=e?.message||`Unknown error`;Ce.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,k,a,w,t,A,e]),Ct=(0,Q.useCallback)(i=>{!i||i===n||(lt(!1),pt(!0),t&&A(t,{metadata:{...e,sessionId:i}}),r(i))},[n,t,A,e]),wt=(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}=Et(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},[]),Dt=(0,Q.useCallback)(async(t,i=[],o)=>{let c=Tt(i),l=wt(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=k,i=await G.post(`${W(n)}/chat/sessions`,{providerId:a,title:t.slice(0,50),clearedFrom:e?.clearedFrom,accountId:me});r(i.id),s(i.providerId),T.current={content:l,permissionMode:w,images:c,imagePaths:u};return}catch(e){console.error(`Failed to create session:`,e);return}X(l,{permissionMode:w,priority:o,...c.length>0&&{images:c},...u.length>0&&{imagePaths:u}})}},[n,a,k,X,wt,w,e]),Ot=(0,Q.useRef)(c);Ot.current=c;let kt=(0,Q.useCallback)((e,t,r)=>{let i=e.trim().match(/^\/(\S+)(?:\s+([\s\S]+))?$/);if(i&&Ot.current.find(e=>e.handler===`client`&&(e.name===i[1]||e.aliases?.includes(i[1])))?.name===`clear`){L(),_t(i[2]?.trim(),n??void 0);return}if(at(void 0),L(),ot&&n&&k){let n=ot.anchorMsgId;st(null),St(wt(e,t),n);return}Dt(e,t,r)},[Dt,L,ot,n,k,St,wt,_t]),At=(0,Q.useRef)(V);At.current=V;let jt=(0,Q.useCallback)(()=>At.current.filter(e=>e.role===`user`&&e.content.trim()).map(e=>e.content),[]),Mt=(0,Q.useCallback)((e,t)=>{pe(e,t)},[pe]),Nt=(0,Q.useCallback)((e,t)=>{l(e),t&&_(t)},[]),Pt=(0,Q.useCallback)((e,t)=>{d(e),p(t)},[]),Ft=(0,Q.useCallback)(e=>{h(e),d(!1),p(``),setTimeout(()=>h(null),50),k&&(G.post(`${W(k)}/chat/slash-recents`,{name:e.name,type:e.type}).catch(()=>{}),_(t=>[e.name,...t.filter(t=>t!==e.name)].slice(0,5)))},[k]),It=(0,Q.useCallback)(()=>{d(!1),p(``)},[]),Lt=(0,Q.useCallback)(()=>oe(null),[]),Rt=(0,Q.useCallback)(e=>{ce(e)},[]),zt=(0,Q.useCallback)(e=>{oe([e.path]),ce(null)},[]),Vt=(0,Q.useCallback)((e,t)=>{b(e),x(t)},[]),Ut=(0,Q.useCallback)(e=>{C(e),b(!1),x(``),setTimeout(()=>C(null),50)},[]),Wt=(0,Q.useCallback)(()=>{b(!1),x(``)},[]);return(0,$.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,Q.useCallback)(e=>{e.preventDefault(),O.current++,(e.dataTransfer.types.includes(`application/x-ppm-path`)||e.dataTransfer.types.includes(`Files`))&&E(!0)},[]),onDragLeave:(0,Q.useCallback)(e=>{e.preventDefault(),O.current--,O.current===0&&E(!1)},[]),onDragOver:(0,Q.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,Q.useCallback)(e=>{e.preventDefault(),O.current=0,E(!1);let t=e.dataTransfer.getData(`application/x-ppm-path`);if(t){oe([t]);return}let n=Array.from(e.dataTransfer.files);n.length>0&&(ae(n),setTimeout(()=>ae(null),100))},[]),children:[re&&(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)(P,{className:`size-8`}),(0,$.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),J&&(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)(F,{className:`size-4 animate-spin`}),(0,$.jsx)(`span`,{children:`Reconnecting...`})]})}),ct&&(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)(F,{className:`size-4 animate-spin`}),(0,$.jsx)(`span`,{children:`Creating edited version…`})]})}),(0,$.jsx)(ni,{shells:Ye,onKill:Xe}),(0,$.jsx)(Zr,{messages:H,onExpandCompact:ye,isCompactExpanded:be,messagesLoading:Se,keepStaleWhileLoading:ft,pendingApproval:Ae,onApprovalResponse:Ve,isStreaming:Ee,phase:q,connectingElapsed:ke,statusMessage:Ne,compactStatus:Me,projectName:k,onFork:Ee?void 0:yt,onEdit:Ee?void 0:bt,editingMsgId:ot?.ownMsgId,sessionId:n??void 0,providerId:a,onNavigateVersion:Ct,versionMap:K,onSelectSession:vt,onDismissMessage:xe,onClearErrors:U,bashPartialOutput:Je}),(0,$.jsx)(oi,{teamName:$e,members:tt,projectName:k}),(0,$.jsxs)(`div`,{className:`border-t border-border bg-panel shrink-0`,children:[(0,$.jsx)(Aa,{projectName:k,usageInfo:le,usageLoading:ue,refreshUsage:M,lastFetchedAt:de,sessionId:n,providerId:a,pickedAccountLabel:B?.label??(z?he:null),pickedAccountId:B?.id??(z?me??null:null),onSelectAccount:_e,onSelectSession:vt,onBugReport:n?()=>Ze(j,{sessionId:n,projectName:k}):void 0,isConnected:We,onReload:()=>{We||Ue(),Z()},teamActivity:Ge,teamMessages:Ke,onTeamOpen:qe}),(0,$.jsx)($i,{items:c,filter:f,onSelect:Ft,onClose:It,visible:u,recentNames:g,projectName:k}),(0,$.jsx)(ea,{items:ee,filter:te,onSelect:Ut,onClose:Wt,visible:y}),se&&(0,$.jsx)(ea,{items:se,filter:``,onSelect:zt,onClose:()=>ce(null),visible:!0}),ot&&(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:xt,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)(o,{className:`h-3.5 w-3.5`}),`Cancel`]})]}),(ht||!I)&&(0,$.jsx)(Gi,{tabId:t,onSend:kt,isStreaming:Ee,onCancel:He,autoFocus:!e?.sessionId||!!nt,initialValue:nt??fe?.content,clearSignal:ut,projectName:k,onSlashStateChange:Pt,onSlashItemsLoaded:Nt,slashSelected:m,onFileStateChange:Vt,onFileItemsLoaded:v,fileSelected:S,externalFiles:ie,externalPaths:D,onExternalPathsConsumed:Lt,onDisambiguate:Rt,onContentChange:Mt,getUserHistory:jt,permissionMode:w,onModeChange:ne,providerId:a,sessionId:n??void 0,onProviderChange:n?void 0:R,model:Fe,onModelChange:Ie,effort:Le,onEffortChange:Re,thinking:ze,onThinkingChange:Be})]})]})}export{Na as ChatTab};
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{C as t,S as n}from"./vendor-markdown-CuWCHIVb.js";import"./vendor-ui-DmZ-Mb-H.js";import{At as r,Jn as i,Yn as a,ln as o,qn as s,wr as c}from"./icons-DQjqk0lJ.js";import{t as l}from"./createLucideIcon-DoiEKeJ_.js";import{n as u,s as d}from"./api-client-C1ZwRL4Y.js";import{t as f}from"./button-B9CTrsEf.js";import{t as p}from"./input-C7Q8FxeL.js";var m=l(`power-off`,[[`path`,{d:`M18.36 6.64A9 9 0 0 1 20.77 15`,key:`dxknvb`}],[`path`,{d:`M6.16 6.16a9 9 0 1 0 12.68 12.68`,key:`1x7qb5`}],[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),h=e(t(),1),g=n();function _(){let[e,t]=(0,h.useState)([]),[n,l]=(0,h.useState)(!0),[_,v]=(0,h.useState)(``),[y,b]=(0,h.useState)(!1),[x,S]=(0,h.useState)(``),[C,w]=(0,h.useState)(!1),[T,E]=(0,h.useState)(null),[D,O]=(0,h.useState)(null),k=(0,h.useCallback)(async()=>{try{t(await u.get(`/api/extensions`))}catch(e){console.error(`Failed to load extensions:`,e)}finally{l(!1)}},[]);(0,h.useEffect)(()=>{k()},[k]);let A=async()=>{let e=_.trim();if(e){b(!0);try{await u.post(`/api/extensions/install`,{name:e}),d.success(`Installed ${e}`),v(``),k()}catch(e){d.error(e.message||`Install failed`)}finally{b(!1)}}},j=async e=>{E(e.id);try{await u.patch(`/api/extensions/${e.id}`,{enabled:!e.enabled}),k()}catch(e){d.error(e.message||`Toggle failed`)}finally{E(null)}},M=async e=>{O(e);try{await u.del(`/api/extensions/${e}`),d.success(`Removed ${e}`),k()}catch(e){d.error(e.message||`Remove failed`)}finally{O(null)}};return n?(0,g.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,g.jsx)(o,{className:`size-4 animate-spin text-muted-foreground`})}):(0,g.jsxs)(`div`,{className:`space-y-4`,children:[(0,g.jsxs)(`section`,{className:`space-y-2`,children:[(0,g.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:`Install Extension`}),(0,g.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,g.jsx)(p,{value:_,onChange:e=>v(e.target.value),onKeyDown:e=>{e.key===`Enter`&&A()},placeholder:`npm package name (e.g. @ppm/ext-myext)`,className:`h-8 text-xs flex-1`}),(0,g.jsxs)(f,{variant:`outline`,size:`sm`,className:`h-8 text-xs px-3 gap-1 cursor-pointer`,disabled:!_.trim()||y,onClick:A,children:[y?(0,g.jsx)(o,{className:`size-3 animate-spin`}):(0,g.jsx)(s,{className:`size-3`}),`Install`]})]}),(0,g.jsx)(`button`,{onClick:()=>w(!C),className:`text-[11px] text-muted-foreground hover:text-foreground transition-colors cursor-pointer`,children:C?`Hide`:`Dev link local extension...`}),C&&(0,g.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,g.jsx)(p,{value:x,onChange:e=>S(e.target.value),placeholder:`Local path (e.g. ./packages/ext-myext)`,className:`h-8 text-xs flex-1`}),(0,g.jsxs)(f,{variant:`outline`,size:`sm`,className:`h-8 text-xs px-3 gap-1 cursor-pointer`,disabled:!x.trim(),onClick:async()=>{try{await u.post(`/api/extensions/dev-link`,{path:x.trim()}),d.success(`Dev-linked successfully`),S(``),k()}catch(e){d.error(e.message||`Dev link failed`)}},children:[(0,g.jsx)(r,{className:`size-3`}),`Link`]})]})]}),(0,g.jsxs)(`section`,{className:`space-y-2`,children:[(0,g.jsxs)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:[`Installed (`,e.length,`)`]}),e.length===0?(0,g.jsx)(`p`,{className:`text-[11px] text-muted-foreground py-4 text-center`,children:`No extensions installed`}):(0,g.jsx)(`div`,{className:`space-y-1`,children:e.map(e=>(0,g.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 py-2 rounded-lg bg-muted/50 hover:bg-muted transition-colors`,children:[(0,g.jsx)(`div`,{className:`size-8 rounded-md bg-background flex items-center justify-center shrink-0`,children:(0,g.jsx)(a,{className:`size-4 text-muted-foreground`})}),(0,g.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,g.jsx)(`p`,{className:`text-xs font-medium truncate`,children:e.displayName||e.id}),(0,g.jsxs)(`p`,{className:`text-[11px] text-muted-foreground truncate`,children:[e.id,` v`,e.version,e.activated&&(0,g.jsx)(`span`,{className:`ml-1 text-success`,children:`active`})]})]}),(0,g.jsx)(f,{variant:`ghost`,size:`icon`,className:`size-7 shrink-0 cursor-pointer`,title:e.enabled?`Disable`:`Enable`,disabled:T===e.id,onClick:()=>j(e),children:T===e.id?(0,g.jsx)(o,{className:`size-3.5 animate-spin`}):e.enabled?(0,g.jsx)(i,{className:`size-3.5 text-success`}):(0,g.jsx)(m,{className:`size-3.5 text-muted-foreground`})}),(0,g.jsx)(f,{variant:`ghost`,size:`icon`,className:`size-7 shrink-0 cursor-pointer text-destructive hover:text-destructive`,title:`Remove`,disabled:D===e.id,onClick:()=>M(e.id),children:D===e.id?(0,g.jsx)(o,{className:`size-3.5 animate-spin`}):(0,g.jsx)(c,{className:`size-3.5`})})]},e.id))})]})]})}export{_ as ExtensionManagerSection};