@hienlh/ppm 0.17.28 → 0.17.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/assets/skills/ppm/SKILL.md +1 -1
- package/assets/skills/ppm/references/http-api.md +1 -1
- package/dist/web/assets/{ai-resource-editor-BCgyv1KF.js → ai-resource-editor-D1efMh5f.js} +1 -1
- package/dist/web/assets/{audio-preview-BPuiX8ma.js → audio-preview-BfaIfDsY.js} +1 -1
- package/dist/web/assets/chat-tab-CVfcHLiQ.js +13 -0
- package/dist/web/assets/code-editor-hKFw2M2d.js +10 -0
- package/dist/web/assets/{conflict-editor-BuLnwxFE.js → conflict-editor-BRDEJEq6.js} +1 -1
- package/dist/web/assets/{csv-preview-DdA_IpTo.js → csv-preview-D32vaKWU.js} +1 -1
- package/dist/web/assets/{database-viewer-BcF3uuk5.js → database-viewer-B-ukNIhW.js} +1 -1
- package/dist/web/assets/{diff-viewer-tyMHX20V.js → diff-viewer-DfFzvZND.js} +1 -1
- package/dist/web/assets/{docx-preview-BTclTd2v.js → docx-preview-B1kTBbEc.js} +1 -1
- package/dist/web/assets/{extension-webview-CBLWXhjt.js → extension-webview-mQPWwlxb.js} +1 -1
- package/dist/web/assets/{git-log-panel-tmGgY2kK.js → git-log-panel-CIB6xuoc.js} +1 -1
- package/dist/web/assets/glide-data-grid-DM0v58AP.js +138 -0
- package/dist/web/assets/group-chat-tab-pfDZpGO_.js +1 -0
- package/dist/web/assets/{image-preview-CQ57RN6l.js → image-preview-Dxvk6fiw.js} +1 -1
- package/dist/web/assets/index-Cp6hb7uj.js +50 -0
- package/dist/web/assets/keybindings-store-BDQFSrPz.js +1 -0
- package/dist/web/assets/{markdown-renderer-devgS0zw.js → markdown-renderer-TCeFZDxj.js} +2 -2
- package/dist/web/assets/{markdown-renderer-C7clwuDe.js → markdown-renderer-zRn368SN.js} +1 -1
- package/dist/web/assets/notification-store-BcEM83wQ.js +1 -0
- package/dist/web/assets/{pdf-preview-Cw_GRd7e.js → pdf-preview-Bx_RsWdB.js} +1 -1
- package/dist/web/assets/{postgres-viewer-DN40Bdc-.js → postgres-viewer-DJXDXZbE.js} +2 -2
- package/dist/web/assets/{settings-tab-DkpOd_kU.js → settings-tab-CAJ4skP0.js} +1 -1
- package/dist/web/assets/{sql-query-editor-Df1pzXAj.js → sql-query-editor-UDQo7Bck.js} +1 -1
- package/dist/web/assets/{sqlite-viewer-Dbh3LluT.js → sqlite-viewer-BaQq64OX.js} +1 -1
- package/dist/web/assets/{system-monitor-tab-bbct9aEk.js → system-monitor-tab-P1uy84Os.js} +1 -1
- package/dist/web/assets/terminal-tab-mI-vAmOV.js +3 -0
- package/dist/web/assets/{tool-cards-BonPvpUI.js → tool-cards-B6jz0GZE.js} +2 -2
- package/dist/web/assets/{use-monaco-theme-Cqo17yKA.js → use-monaco-theme-CZKIw2ZG.js} +1 -1
- package/dist/web/assets/{video-preview-kZgggFAn.js → video-preview-TGDSUs0J.js} +1 -1
- package/dist/web/index.html +1 -1
- package/dist/web/sw.js +1 -1
- package/package.json +2 -2
- package/src/services/supervisor.ts +45 -24
- package/src/services/windows-process-tree.ts +24 -3
- package/src/web/components/chat/account-dialogs.tsx +3 -3
- package/src/web/components/chat/chat-history-bar.tsx +4 -2
- package/src/web/components/chat/message-action-bar.tsx +2 -1
- package/src/web/components/database/connection-import-export.tsx +5 -2
- package/src/web/components/database/export-button.tsx +4 -3
- package/src/web/components/explorer/file-tree.tsx +3 -2
- package/src/web/components/layout/cloud-share-popover.tsx +2 -1
- package/src/web/components/layout/mobile-nav.tsx +3 -2
- package/src/web/components/layout/project-bottom-sheet.tsx +2 -1
- package/src/web/components/layout/project-switcher.tsx +2 -1
- package/src/web/components/layout/tab-bar.tsx +3 -2
- package/src/web/components/settings/accounts-settings-section.tsx +3 -3
- package/src/web/components/settings/proxy-settings-section.tsx +8 -7
- package/src/web/components/shared/bug-report-popup.tsx +2 -1
- package/src/web/components/shared/markdown-code-block.tsx +3 -2
- package/src/web/components/terminal/terminal-tab.tsx +2 -1
- package/src/web/components/tunnels/tunnel-manager-tab.tsx +4 -2
- package/src/web/lib/clipboard.ts +52 -0
- package/src/web/lib/report-bug.ts +0 -10
- package/dist/web/assets/chat-tab-WnnM6GKA.js +0 -13
- package/dist/web/assets/code-editor-CnGUyOuU.js +0 -10
- package/dist/web/assets/glide-data-grid-CkCW7sFw.js +0 -138
- package/dist/web/assets/group-chat-tab-D_x5CRae.js +0 -1
- package/dist/web/assets/index-Cp3e9olf.js +0 -50
- package/dist/web/assets/keybindings-store-CpgEwnFA.js +0 -1
- package/dist/web/assets/notification-store-BohufOcS.js +0 -1
- package/dist/web/assets/terminal-tab-Cqs7xZJt.js +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.17.30] - 2026-08-26
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- **Every copy button did nothing when PPM was opened at a plain address** — reaching PPM over `http://` rather than `https://`, which is what happens with a Tailscale machine name or a bare LAN address, left every Copy in the interface inert: copying a chat message, a code block, a file path, a project path, a share link, a proxy setting, a set of database rows. Worse, most of them still reported success — the button flipped to a tick, the toast said "URL copied" — while nothing had reached the clipboard. Browsers only hand out the clipboard interface to pages served over a secure connection, of which `localhost` counts as one and a plain address does not, so on those addresses the interface was simply absent; PPM asked for it anyway and quietly discarded the resulting error. Copies now go through one shared routine that falls back to the older selection-based method, which browsers still allow on plain addresses, so the same buttons work at whatever address you happen to be using. The ones that report an outcome now report the real one, and the two account-backup buttons still fall back to downloading a file. Pasting *from* the clipboard is a separate permission that plain addresses genuinely cannot be granted, so terminal paste and importing database connections from the clipboard still need a secure address; the mobile editor's paste button already offers a long-press box for that case.
|
|
7
|
+
|
|
8
|
+
## [0.17.29] - 2026-08-25
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- **PPM said it had started but nothing answered** — `ppm start` printed the local address and a share link, yet neither localhost nor the link ever responded, and the status file kept insisting everything was running while every process it referred to was already dead. Two things went wrong in sequence, both on Windows. First, before starting the server, PPM briefly listens on the port itself to make sure it is free; starting the share tunnel at the same moment made Windows hand the tunnel a copy of that short-lived listening socket — a copy the tunnel never closes — so the port stayed occupied and the real server could never take it, timing out after ten seconds on every attempt. Second, the supervisor then went looking for whichever process was hogging the port so it could clear it out, and the answer came back as the supervisor itself — which it dutifully killed, taking the server, the tunnel and its own status reporting down with it. That is why the status file still said "running": nothing was left alive to correct it. The port check and the starting of child processes now take turns instead of overlapping, so the socket can no longer leak into a child; and if the port ever does show up as held by the supervisor itself, it restarts the tunnel — the only thing that can actually be holding the leaked copy — rather than killing itself.
|
|
12
|
+
- **PPM's reserved memory could grow without limit on Windows** — the supervisor takes a periodic inventory of the helper processes the server has started, so that after a crash it knows exactly what to clean up. Each inventory launches a PowerShell and builds a list of every process on the machine, which is fine on its own — but on a busy machine one inventory could still be running when the next fired, and every simultaneous run permanently reserved a chunk of memory that was never returned to the system. Left long enough this ratcheted up to an observed 19GB of reserved memory against 1GB actually in use. Inventories now run one at a time — a tick that finds the previous one still running simply skips its turn — and a PowerShell that gets stuck is cut off after twenty seconds instead of lingering forever.
|
|
13
|
+
|
|
3
14
|
## [0.17.28] - 2026-08-21
|
|
4
15
|
|
|
5
16
|
### Added
|
|
@@ -71,4 +71,4 @@ This skill covers the `ppm` CLI, its HTTP API, and its config DB. It does **not*
|
|
|
71
71
|
- Third-party extensions (inspect via `ppm ext list`).
|
|
72
72
|
- The Claude Agent SDK internals (separate skill).
|
|
73
73
|
|
|
74
|
-
<!-- Generated for PPM v0.17.
|
|
74
|
+
<!-- Generated for PPM v0.17.30 at build time. Re-run `ppm export skill --install` to refresh. -->
|
|
@@ -282,4 +282,4 @@ _Base URL: `http://localhost:8080` (default; override via `ppm config set port <
|
|
|
282
282
|
- `ws://<host>/ws/terminal` — PTY terminal multiplexer
|
|
283
283
|
- `ws://<host>/ws/extensions` — extension host channel
|
|
284
284
|
|
|
285
|
-
<!-- Generated from src/server/routes/ for PPM v0.17.
|
|
285
|
+
<!-- Generated from src/server/routes/ for PPM v0.17.30 -->
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,y as n}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t as r}from"./save-BM4p9_9n.js";import{o as i}from"./api-client-DhXpjLdi.js";import"./vendor-mermaid-CYOBtZtD.js";import"./settings-store-UwT_fNhg.js";import{n as a}from"./utils-E0yyGxXt.js";import{
|
|
1
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,y as n}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t as r}from"./save-BM4p9_9n.js";import{o as i}from"./api-client-DhXpjLdi.js";import"./vendor-mermaid-CYOBtZtD.js";import"./settings-store-UwT_fNhg.js";import{n as a}from"./utils-E0yyGxXt.js";import{At as o,D as s,E as c,O as l,Qt as u,T as d,Zt as f,k as p,kt as m,o as h}from"./index-Cp6hb7uj.js";import{t as g}from"./use-monaco-theme-CZKIw2ZG.js";var _=e(t(),1),v=n();function y({metadata:e}){let t=e?.filePath,n=e?.name,a=e?.resourceType??`skill`,y=e?.scope??`user`,x=e?.readOnly===!0,S=e?.shadowed===!0,C=e?.shadowedBy,w=e?.project??``,[T,E]=(0,_.useState)(``),[D,O]=(0,_.useState)(``),[k,A]=(0,_.useState)(!0),[j,M]=(0,_.useState)(null),[N,P]=(0,_.useState)(!1),F=g(),I=(0,_.useRef)(``),L=T!==D;(0,_.useEffect)(()=>{let e=!1;return A(!0),M(null),l(t,w).then(t=>{e||(E(t.content),O(t.content),I.current=t.content)}).catch(t=>{e||M(t.message)}).finally(()=>{e||A(!1)}),()=>{e=!0}},[t,w]);let R=(0,_.useCallback)(async()=>{if(x||N)return;let e=I.current;if(e!==D){P(!0);try{await p(t,e,w),O(e),E(e),i.success(`Saved`),s.getState().reload()}catch(e){i.error(e.message)}finally{P(!1)}}},[t,w,D,x,N]);(0,_.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&(e.preventDefault(),R())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[R]);let z=c[a];return(0,v.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border px-3 py-2 shrink-0`,children:[(0,v.jsx)(z,{className:`size-4 text-text-subtle`}),(0,v.jsx)(`span`,{className:`text-sm font-semibold`,children:n}),(0,v.jsx)(d,{scope:y}),L&&!x&&(0,v.jsx)(`span`,{className:`size-1.5 rounded-full bg-primary`,title:`Unsaved changes`}),(0,v.jsx)(`div`,{className:`flex-1`}),(0,v.jsxs)(`span`,{className:`hidden sm:block text-[11px] text-text-subtle`,children:[a,` · markdown`]}),!x&&(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(`button`,{onClick:()=>E(D),disabled:!L||N,className:`flex items-center gap-1 rounded px-2 py-1 text-xs text-text-secondary hover:bg-surface-elevated disabled:opacity-40`,children:[(0,v.jsx)(m,{className:`size-3.5`}),` Revert`]}),(0,v.jsxs)(`button`,{onClick:()=>void R(),disabled:!L||N,className:`flex items-center gap-1 rounded bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-40`,children:[N?(0,v.jsx)(u,{className:`size-3.5 animate-spin`}):(0,v.jsx)(r,{className:`size-3.5`}),` Save`]})]})]}),x&&(0,v.jsx)(b,{icon:f,tone:`muted`,children:`Bundled resource — read-only. Duplicate it (from the AI Resources panel) to make an editable copy.`}),S&&C&&(0,v.jsxs)(b,{icon:o,tone:`warn`,children:[`This `,a,` is overridden by another “`,C.name,`” from a higher-priority source (`,C.source,`). It is currently inactive.`]}),(0,v.jsx)(`div`,{className:`min-h-0 flex-1`,children:k?(0,v.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,v.jsx)(u,{className:`size-5 animate-spin text-primary`})}):j?(0,v.jsx)(`div`,{className:`p-6 text-center text-sm text-destructive`,children:j}):(0,v.jsx)(h,{height:`100%`,language:`markdown`,theme:F,value:T,onChange:e=>{let t=e??``;I.current=t,E(t)},options:{readOnly:x,minimap:{enabled:!1},fontSize:13,wordWrap:`on`,scrollBeyondLastLine:!1,lineNumbers:`on`}})})]})}function b({icon:e,tone:t,children:n}){return(0,v.jsxs)(`div`,{className:a(`flex items-start gap-2 px-3 py-2 text-[12px] shrink-0 border-b border-border`,t===`warn`?`bg-amber-500/10 text-amber-300`:`bg-surface-elevated text-text-secondary`),children:[(0,v.jsx)(e,{className:`mt-0.5 size-3.5 shrink-0`}),(0,v.jsx)(`span`,{children:n})]})}export{y as AiResourceEditor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{y as e}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t}from"./createLucideIcon-ConhwJnb.js";import{t as n}from"./file-exclamation-point-DBEC-Kst.js";import"./api-client-DhXpjLdi.js";import{t as r}from"./utils-E0yyGxXt.js";import{
|
|
1
|
+
import{y as e}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t}from"./createLucideIcon-ConhwJnb.js";import{t as n}from"./file-exclamation-point-DBEC-Kst.js";import"./api-client-DhXpjLdi.js";import{t as r}from"./utils-E0yyGxXt.js";import{Qt as i}from"./index-Cp6hb7uj.js";import{t as a}from"./use-blob-url-BMZ0zo_4.js";var o=t(`music`,[[`path`,{d:`M9 18V5l12-2v13`,key:`1jmyc2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`circle`,{cx:`18`,cy:`16`,r:`3`,key:`1hluhg`}]]),s=e();function c({filePath:e,projectName:t}){let{blobUrl:c,error:l}=a(e,t);return l?(0,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,s.jsx)(n,{className:`size-10 text-text-subtle`}),(0,s.jsx)(`p`,{className:`text-sm`,children:`Failed to load audio.`})]}):c?(0,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 p-4 bg-surface`,children:[(0,s.jsx)(o,{className:`size-16 text-text-subtle`}),(0,s.jsx)(`p`,{className:`text-sm text-text-secondary truncate max-w-xs`,children:r(e)}),(0,s.jsx)(`audio`,{src:c,controls:!0,className:`w-full max-w-md`})]}):(0,s.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,s.jsx)(i,{className:`size-5 animate-spin text-text-subtle`})})}export{c as AudioPreview};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-zRn368SN.js","assets/vendor-mermaid-CYOBtZtD.js","assets/rolldown-runtime-FhOqtrmT.js","assets/vendor-ui-DMRGWRuc.js","assets/vendor-markdown-CKTlmXbz.js","assets/markdown-renderer-TCeFZDxj.js","assets/index-Cp6hb7uj.js","assets/dialog-HHdNInEH.js","assets/utils-E0yyGxXt.js","assets/createLucideIcon-ConhwJnb.js","assets/x-BsFLg-T8.js","assets/eye-off-Rq1n2-oe.js","assets/bot-E9mcVZnr.js","assets/mobile-bottom-sheet-BwPBKZON.js","assets/chevron-right-DeUue2aK.js","assets/use-is-mobile-CE6AamG6.js","assets/sparkles-B3DmG8PJ.js","assets/database-COYAMZaw.js","assets/plus-DcuJuDC3.js","assets/api-client-DhXpjLdi.js","assets/react-8hrD3-kv.js","assets/api-settings-BUYvGBdi.js","assets/project-store-C1jInVih.js","assets/panel-store-DsDZX8Mi.js","assets/settings-store-UwT_fNhg.js","assets/tab-store-ByORqglW.js","assets/apply-theme-BSJDABU3.js","assets/resolve-theme-B9Mgd5GG.js","assets/index-DCJ29LBG.css","assets/api-client-DNTkryX1.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,y as n}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t as r}from"./createLucideIcon-ConhwJnb.js";import{t as i}from"./bot-E9mcVZnr.js";import{g as a,h as o,p as s,t as c}from"./mobile-bottom-sheet-BwPBKZON.js";import{n as l,t as u}from"./use-is-mobile-CE6AamG6.js";import{t as d}from"./chevron-right-DeUue2aK.js";import{a as f,i as p,n as m,r as h,t as g}from"./tool-cards-B6jz0GZE.js";import{a as _,c as v,i as y,n as b,o as x,r as S,t as C,u as w}from"./dialog-HHdNInEH.js";import{t as T}from"./code-TekEnDFM.js";import{n as E,t as ee}from"./sparkles-B3DmG8PJ.js";import{n as D,r as te,t as O}from"./plus-DcuJuDC3.js";import{t as k}from"./shield-off-D5tU7gQT.js";import{t as ne}from"./x-BsFLg-T8.js";import{n as A,o as j,r as M,t as N}from"./api-client-DhXpjLdi.js";import{q as re}from"./vendor-mermaid-CYOBtZtD.js";import{t as P}from"./settings-store-UwT_fNhg.js";import{n as F,r as ie,t as I}from"./utils-E0yyGxXt.js";import{t as ae}from"./panel-store-DsDZX8Mi.js";import{i as L}from"./project-store-C1jInVih.js";import{t as oe}from"./tab-store-ByORqglW.js";import{_ as R,a as z,c as se,h as ce,i as le,l as ue,m as B,o as V,p as H,r as U,s as W,t as G,u as K}from"./api-settings-BUYvGBdi.js";import{$t as de,B as fe,Ct as q,Dt as pe,F as me,Ft as he,Gt as ge,H as _e,Ht as J,I as Y,It as ve,Jt as ye,L as be,Lt as xe,N as Se,Nt as Ce,Ot as we,P as Te,Pt as Ee,Qt as X,R as De,Rt as Oe,Sn as ke,St as Ae,Tt as Z,U as je,V as Me,Vt as Ne,Wt as Pe,Xt as Fe,Zt as Ie,_n as Le,at as Re,bn as ze,en as Be,f as Ve,gn as He,gt as Ue,hn as We,ht as Ge,in as Ke,jt as qe,ln as Je,mn as Ye,mt as Xe,nt as Ze,on as Qe,pn as $e,qt as et,r as tt,rn as nt,t as rt,un as it,vn as at,vt as ot,w as st,wt as ct,xn as lt,yn as ut,z as dt,zt as ft}from"./index-Cp6hb7uj.js";var pt=r(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),mt=r(`chevrons-down`,[[`path`,{d:`m7 6 5 5 5-5`,key:`1lc07p`}],[`path`,{d:`m7 13 5 5 5-5`,key:`1d48rs`}]]),ht=r(`clipboard-check`,[[`rect`,{width:`8`,height:`4`,x:`8`,y:`2`,rx:`1`,ry:`1`,key:`tgr4d6`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`,key:`116196`}],[`path`,{d:`m9 14 2 2 4-4`,key:`df797q`}]]),gt=r(`hand`,[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]),_t=r(`list-ordered`,[[`path`,{d:`M11 5h10`,key:`1cz7ny`}],[`path`,{d:`M11 12h10`,key:`1438ji`}],[`path`,{d:`M11 19h10`,key:`11t30w`}],[`path`,{d:`M4 4h1v5`,key:`10yrso`}],[`path`,{d:`M4 9h2`,key:`r1h2o0`}],[`path`,{d:`M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02`,key:`xtkcd5`}]]),vt=r(`mic-off`,[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]),yt=r(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),bt=r(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),xt=r(`slash`,[[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}]]),Q=e(t(),1);function St(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 Ct(e,t){let n=`pc-${St(t)}-`;return e.map(e=>e.id?{...e,id:`${n}${e.id}`}:e)}function wt(e,t){if(t.size===0)return e;let n=[];for(let r of e){let e=r.id?t.get(r.id):void 0;e&&e.length>0&&n.push(...e),n.push(r)}return n}var Tt=null;function Et(){return Tt||=new AudioContext,Tt}function Dt(e,t,n,r,i=`sine`){let a=Et(),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 Ot(){let e=Et().currentTime;Dt(523,.15,e,.15),Dt(659,.2,e+.12,.15)}function kt(){let e=Et().currentTime;Dt(880,.12,e,.18,`square`),Dt(698,.12,e+.15,.18,`square`),Dt(880,.15,e+.3,.15,`square`)}function At(){let e=Et().currentTime;Dt(440,.12,e,.12),Dt(523,.12,e+.1,.12),Dt(659,.18,e+.2,.12)}var jt={done:Ot,approval_request:kt,question:At};function Mt(e){try{jt[e]?.()}catch{}}var Nt={hasTeams:!1,teamNames:[],messageCount:0,unreadCount:0};function Pt(e){if(document.hidden)return!1;let{panels:t}=ae.getState();for(let n of Object.values(t)){let t=n.tabs.find(e=>e.id===n.activeTabId);if(t?.type===`chat`&&t.metadata?.sessionId===e)return!0}return!1}function Ft(e,t=`claude`,n=``){let[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(new Map),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)({}),[d,f]=(0,Q.useState)(`idle`),[p,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(0),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)([]),E=(0,Q.useRef)([]),[ee,D]=(0,Q.useState)(null),[te,O]=(0,Q.useState)(null),[k,ne]=(0,Q.useState)(!1),[re,P]=(0,Q.useState)(null),[F,ie]=(0,Q.useState)(null),I=(0,Q.useRef)(null),L=(0,Q.useRef)(null),[oe,R]=(0,Q.useState)(null),z=(0,Q.useRef)(null),[se,ce]=(0,Q.useState)(!0),le=(0,Q.useRef)(null),ue=(0,Q.useRef)(null),B=(0,Q.useRef)(``),V=(0,Q.useRef)([]),H=(0,Q.useRef)(new Map),U=(0,Q.useRef)(null),W=(0,Q.useRef)(`idle`),G=(0,Q.useRef)(null),K=(0,Q.useRef)(()=>{}),de=(0,Q.useRef)(null),fe=(0,Q.useRef)(!1),q=(0,Q.useRef)(new Set),pe=(0,Q.useRef)(0),me=(0,Q.useRef)(null),he=(0,Q.useRef)(e);he.current=e;let ge=(0,Q.useRef)([]);ge.current=r;let _e=(0,Q.useRef)(n);_e.current=n;let J=(0,Q.useRef)(null),Y=(0,Q.useRef)(0),ve=(0,Q.useRef)({teamNames:new Set,messages:[]}),ye=(0,Q.useRef)(0),[be,xe]=(0,Q.useState)(Nt),[Se,Ce]=(0,Q.useState)([]),we=(0,Q.useCallback)(()=>{let e=ve.current;xe({hasTeams:e.teamNames.size>0,teamNames:Array.from(e.teamNames),messageCount:e.messages.length,unreadCount:ye.current}),Ce([...e.messages])},[]),Te=(0,Q.useCallback)(()=>{ye.current=0,we()},[we]),Ee=d!==`idle`;(0,Q.useEffect)(()=>{if(e)return Re.getState().setStreaming(e,d!==`idle`),()=>{Re.getState().setStreaming(e,!1)}},[e,d]);let X=(0,Q.useCallback)((e,t)=>{let n=V.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=V.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return V.current[n]={...r,children:i},!0},[]),De=(0,Q.useCallback)(()=>{Y.current=0;let e=B.current,t=[...V.current],n=U.current;(0,Q.startTransition)(()=>{i(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}]})})},[]),Oe=(0,Q.useCallback)(()=>{Y.current||=window.setTimeout(De,100)},[De]),ke=(0,Q.useCallback)(e=>{let t=e,n=t?.type;if(!n)return;let r=e=>{let n=V.current,r=n.findIndex(e);r===-1?n.push(t):n[r]=t};switch(n){case`account_info`:U.current={accountId:t.accountId,accountLabel:t.accountLabel},D(null);break;case`account_retry`:t.accountId&&t.accountLabel&&(U.current={accountId:t.accountId,accountLabel:t.accountLabel}),V.current=[t],Oe();break;case`status_update`:{let e=t.accountLabel?` (${t.accountLabel})`:``;D(`${t.message}${e}`);break}case`text`:{let e=t.parentToolUseId;if(e&&X(t,e)){Oe();break}B.current+=t.content,V.current.push(t),Oe();break}case`thinking`:{let e=t.parentToolUseId;if(e&&X(t,e)){Oe();break}V.current.push(t),Oe();break}case`tool_use`:{if(t.tool===`AskUserQuestion`){t.toolUseId&&q.current.add(t.toolUseId);break}let e=t.parentToolUseId;if(e&&X(t,e)){Oe();break}let n=t.toolUseId;r(e=>!!n&&e.type===`tool_use`&&e.toolUseId===n),Oe();break}case`tool_result`:{let e=t.toolUseId;if(e&&H.current.delete(e),e&&q.current.has(e))break;let n=t.parentToolUseId;if(n&&X(t,n)){Oe();break}r(t=>!!e&&t.type===`tool_result`&&t.toolUseId===e),Oe();break}case`approval_resolved`:{let e=t.requestId;if(t.approved&&t.answers){let n=V.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,i(e=>[...e]))}y(t=>t&&t.requestId===e?null:t),J.current!=null&&(j.dismiss(J.current),J.current=null);break}case`approval_request`:if(r(e=>e.type===`approval_request`&&e.requestId===t.requestId),fe.current)break;if(y({requestId:t.requestId,tool:t.tool,input:t.input}),he.current&&!Pt(he.current)){Mt(t.tool===`AskUserQuestion`?`question`:`approval_request`);let e=he.current,n=t.tool===`AskUserQuestion`;J.current=j[n?`info`:`warning`](n?`AI has a question`:`${t.tool} needs permission`,{description:_e.current||`Session ${e.slice(0,8)}`,duration:1/0,action:{label:`Go to session`,onClick:()=>{let{panels:t}=ae.getState();for(let[n,r]of Object.entries(t)){let t=r.tabs.find(t=>t.metadata?.sessionId===e);if(t){ae.getState().setActiveTab(t.id,n);break}}}}})}break;case`error`:i(e=>{let n=e[e.length-1];if(n?.role===`assistant`){let r=V.current,i=r[r.length-1],a=i?.type===`error`&&i.message===t.message?r:[...r,t];return V.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&&(ve.current.teamNames.add(e),N.get(`/api/teams/${encodeURIComponent(e)}`).then(e=>{if(e?.messages){let t=ve.current.messages,n=e.messages.filter(e=>!t.some(t=>t.timestamp===e.timestamp&&t.from===e.from));t.push(...n),t.sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime()),t.length>500&&t.splice(0,t.length-500)}we()}).catch(()=>{}),we());break}case`team_inbox`:{let e=t.messages;if(Array.isArray(e)){let t=ve.current.messages;t.push(...e),t.length>500&&t.splice(0,t.length-500),ye.current+=e.length,we()}break}case`team_updated`:we();break;case`bash_output`:{let e=t.toolUseId;if(e){let n=H.current.get(e);n?(n.content+=t.content,n.content.length>5e5&&(n.content=n.content.slice(-5e5)),n.lineCount=t.lineCount):H.current.set(e,{content:t.content,lineCount:t.lineCount}),Oe()}break}case`background_registry`:{let e=t.shells??[];E.current=e,T(e);break}case`done`:{if(W.current===`idle`)break;t.contextWindowPct!=null&&x(t.contextWindowPct),he.current&&!Pt(he.current)&&Mt(`done`),Y.current&&=(clearTimeout(Y.current),0);let e=B.current,n=[...V.current],r=U.current,a=t.lastMessageUuid;i(t=>{let i=t[t.length-1];return i?.role===`assistant`?[...t.slice(0,-1),{...i,id:`final-${Date.now()}`,content:e||i.content,events:n.length>0?n:i.events,...a&&{sdkUuid:a}}]:e||n.length>0?[...t,{id:`final-${Date.now()}`,role:`assistant`,content:e,events:n,timestamp:new Date().toISOString(),...a&&{sdkUuid:a},...r}]:t}),B.current=``,V.current=[],U.current=null,me.current=null,H.current.clear(),D(null);break}}},[X,Oe]),Ae=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`title_updated`){O(t.title??null);return}if(t.type===`compact_status`){let e=t.status;e===`compacting`?C(`compacting`):e===`done`&&C(null);return}if(t.type===`phase_changed`){let e=t.phase;f(e),W.current=e,_(e===`connecting`?t.elapsed??0:0),e===`idle`&&C(null);return}if(t.type===`session_state`){ne(!0),P(t.sessionId??he.current);let e=t,n=e.phase;f(n),W.current=n,e.sessionTitle&&O(e.sessionTitle),e.model&&(L.current&&e.model!==L.current||(e.model===L.current&&(L.current=null),ie(e.model),I.current=e.model)),typeof e.effort==`string`&&(R(e.effort),z.current=e.effort),typeof e.thinking==`boolean`&&ce(e.thinking),e.pendingApproval&&y({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),C(e.compactStatus===`compacting`?`compacting`:null),n===`idle`&&(de.current?.(),h(!1));return}if(t.type===`turn_events`){let e=t.events,n=t.userMessage;if(!e?.length&&!n){h(!1);return}pe.current&&=(cancelAnimationFrame(pe.current),0),me.current=n,i(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}),B.current=``,V.current=[],U.current=null,fe.current=!0;let r=0,a=()=>{let t=Math.min(r+100,e.length);for(let n=r;n<t;n++)ke(e[n]);r=t,r<e.length?pe.current=requestAnimationFrame(a):(pe.current=0,fe.current=!1,h(!1))};pe.current=requestAnimationFrame(a);return}ke(t)}},[ke]),{send:Z,connect:je}=m({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:Ae,autoConnect:!!e&&!!n});K.current=Z,(0,Q.useEffect)(()=>{let r=!1;ue.current&&ue.current!==e&&(L.current=null,le.current=null),ue.current=e??null,f(`idle`),W.current=`idle`,y(null),J.current!=null&&(j.dismiss(J.current),J.current=null),C(null),o(new Map),u({}),B.current=``,V.current=[],me.current=null,H.current.clear(),Y.current&&=(clearTimeout(Y.current),0),ne(!1),P(null),ve.current={teamNames:new Set,messages:[]},ye.current=0,xe(Nt),Ce([]);let a=new Set(ge.current.map(e=>e.id));return e&&n?(c(!0),fetch(`${M(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${A()}`}}).then(e=>e.json()).then(e=>{if(r)return;let t=e.ok?Array.isArray(e.data)?{messages:e.data,versionMap:{}}:e.data:null,n=Array.isArray(t?.messages)?t.messages:[];t?.versionMap&&u(t.versionMap);let o=me.current;if(o!=null){for(let e=n.length-1;e>=0;e--)if(n[e].role===`user`&&n[e].content===o){n=n.slice(0,e);break}}i(e=>{let t=e.filter(e=>!a.has(e.id));return[...n,...t]})}).catch(()=>{r||i(e=>e.filter(e=>!a.has(e.id)))}).finally(()=>{r||c(!1)})):i([]),()=>{r=!0}},[e,t,n]);let Me=(0,Q.useCallback)((e,t)=>{if(!e.trim())return;let n=W.current!==`idle`;if(n){Y.current&&=(clearTimeout(Y.current),0);let e=B.current,t=[...V.current];i(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})}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),B.current=``,V.current=[],G.current=null,n?(f(`thinking`),W.current=`thinking`):(f(`initializing`),W.current=`initializing`),y(null),J.current!=null&&(j.dismiss(J.current),J.current=null),Z(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode,priority:t?.priority,images:t?.images,...I.current&&{model:I.current},...z.current&&{effort:z.current},...le.current!==null&&{thinking:le.current}}))},[Z]),Ne=(0,Q.useCallback)(e=>{ie(e),I.current=e,L.current=e,Z(JSON.stringify({type:`set_model`,model:e}))},[Z]),Pe=(0,Q.useCallback)(e=>{R(e),z.current=e,Z(JSON.stringify({type:`set_effort`,effort:e}))},[Z]),Fe=(0,Q.useCallback)(e=>{ce(e),le.current=e,Z(JSON.stringify({type:`set_thinking`,enabled:e}))},[Z]),Ie=(0,Q.useCallback)((e,t,n)=>{if(Z(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=V.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)}i(e=>[...e])}y(null),J.current!=null&&(j.dismiss(J.current),J.current=null)},[Z]),Le=(0,Q.useCallback)(()=>{if(W.current===`idle`)return;Z(JSON.stringify({type:`cancel`}));let e=B.current,t=[...V.current];i(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}),B.current=``,V.current=[],H.current.clear(),G.current=null,f(`idle`),W.current=`idle`,y(null),J.current!=null&&(j.dismiss(J.current),J.current=null)},[Z]),ze=(0,Q.useCallback)(e=>{e&&Z(JSON.stringify({type:`kill_background_shell`,shellId:e}))},[Z]),Be=(0,Q.useCallback)(e=>{if(!e)return;let t=e.replace(/\.output$/,``);return E.current.find(n=>n.shellId===t||n.outputPath.endsWith(e)||n.outputPath.endsWith(`${t}.output`))},[]);(0,Q.useEffect)(()=>{e&&rt.getState().setSessionShells(e,w)},[e,w]),(0,Q.useEffect)(()=>{if(e)return rt.getState().retainSession(e),()=>{rt.getState().releaseSession(e)}},[e]);let Ve=(0,Q.useCallback)(()=>{ne(!1),h(!0),je()},[je]),He=(0,Q.useCallback)(()=>{!e||!n||fetch(`${M(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${A()}`}}).then(e=>e.json()).then(e=>{if(W.current!==`idle`)return;let t=e.ok?Array.isArray(e.data)?{messages:e.data,versionMap:void 0}:e.data:null;t?.versionMap&&u(t.versionMap),Array.isArray(t?.messages)&&t.messages.length>0&&(i(t.messages),B.current=``,V.current=[])}).catch(()=>{})},[e,t,n]);de.current=He;let Ue=(0,Q.useCallback)(async(e,t)=>{if(!n)throw Error(`No project context available`);let r=e.replace(/^pc-[^-]+-/,``),i=`${M(n)}/chat/pre-compact-messages?jsonlPath=${encodeURIComponent(t)}&before=${encodeURIComponent(r)}`,a=Ct(await N.get(i),t);return o(t=>{let n=new Map(t);return n.set(e,a),n}),a.length},[n]),We=(0,Q.useCallback)(e=>a.has(e),[a]),Ge=(0,Q.useCallback)(e=>{i(t=>t.filter(t=>t.id!==e))},[]),Ke=(0,Q.useCallback)(()=>{i(e=>e.filter(e=>e.role!==`system`))},[]);return{messages:r,renderedMessages:(0,Q.useMemo)(()=>wt(r,a),[r,a]),expandCompact:Ue,isCompactExpanded:We,dismissMessage:Ge,clearErrors:Ke,messagesLoading:s,versionMap:l,isStreaming:Ee,phase:d,isReconnecting:p,connectingElapsed:g,pendingApproval:v,contextWindowPct:b,compactStatus:S,statusMessage:ee,sessionTitle:te,model:F,setModel:Ne,effort:oe,setEffort:Pe,thinking:se,setThinking:Fe,teamActivity:be,teamMessages:Se,markTeamRead:Te,bashPartialOutput:H,backgroundShells:w,killBackgroundShell:ze,findBackgroundShellByOutput:Be,sendMessage:Me,respondToApproval:Ie,cancelStreaming:Le,reconnect:Ve,refetchMessages:He,isConnected:k&&re===e}}var It=12e4;function Lt(e,t=`claude`){let[n,r]=(0,Q.useState)({}),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null),c=(0,Q.useRef)(null),l=(0,Q.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${M(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${A()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),e.data.lastFetchedAt&&s(e.data.lastFetchedAt))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,Q.useEffect)(()=>(l(),c.current=setInterval(()=>l(),It),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,Q.useCallback)(()=>l(!0),[l])}}var Rt={damping:.7,stiffness:.05,mass:1.25},zt=70,Bt=1e3/60,Vt=350,Ht=!1;globalThis.document?.addEventListener(`mousedown`,()=>{Ht=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{Ht=!1}),globalThis.document?.addEventListener(`click`,()=>{Ht=!1});var Ut=(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(!Ht)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<=zt}}},[]),f=(0,Q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Kt(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))/Bt;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:Kt(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=Wt(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=Wt(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=Kt(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:Vt})}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 Wt(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Gt=new Map;function Kt(...e){let t={...Rt},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 Gt.has(r)||Gt.set(r,Object.freeze(t)),n?`instant`:Gt.get(r)}function qt(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(()=>{N.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(),Jt=new Set([`TaskCreate`,`TaskUpdate`,`TaskStop`]);function Yt(e){let t=0;for(let n of e)if(n.events)for(let e of n.events)e.type===`tool_use`&&Jt.has(e.tool)&&t++;return t}var Xt={completed:{icon:`✓`,cls:`text-success`},in_progress:{icon:`▶`,cls:`text-warning`},stopped:{icon:`■`,cls:`text-text-subtle`},pending:{icon:`○`,cls:`text-text-subtle`}};function Zt({projectName:e,sessionId:t,messages:n}){let r=(0,Q.useMemo)(()=>Yt(n),[n]),i=qt(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,u=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)(d,{className:`size-3.5 shrink-0`}):(0,$.jsx)(l,{className:`size-3.5 shrink-0`}),(0,$.jsx)(h,{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:`${u}%`}})})]}),!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)(Qt,{task:e},e.id))})]})}function Qt({task:e}){let t=Xt[e.status]??Xt.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 $t=/read the full transcript at:\s*(\S+\.jsonl)/i;function en(e){return e.match($t)?.[1]?.trim()??null}var tn=class extends Q.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?this.props.fallback?this.props.fallback:this.props.fallbackContent?(0,$.jsx)(`div`,{className:`text-sm whitespace-pre-wrap break-words text-text-primary opacity-80`,children:this.props.fallbackContent}):null:this.props.children}};function nn({projectName:e,onSelectSession:t}){return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-6 text-text-secondary overflow-y-auto`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,$.jsx)(i,{className:`size-10 text-text-subtle`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Send a message to start a new conversation`})]}),(0,$.jsx)(Ge,{projectName:e,onSelectSession:t,className:`w-full px-4`})]})}function rn(e){if(!e)return!1;let t=e.closest(`[data-tab-pool-id]`)?.dataset.tabPoolId;if(!t)return e.offsetParent!==null;let{panels:n,focusedPanelId:r}=ae.getState();return n[r]?.activeTabId===t}var an=3200,on=1e3,sn={hasAbove:!1,atBottom:!0,idx:0,total:0};function cn({scrollElement:e,userIndices:t,scrollToBottom:n}){let r=u(),[i,a]=(0,Q.useState)(sn),[o,s]=(0,Q.useState)(!1),[c,d]=(0,Q.useState)(0),f=(0,Q.useRef)(an),p=(0,Q.useRef)(null),m=(0,Q.useRef)(null),h=(0,Q.useRef)(!1),g=(0,Q.useRef)(!1),_=(e,t,n)=>t.getBoundingClientRect().top-n+e.scrollTop,v=(0,Q.useCallback)(e=>Array.from(e.querySelectorAll(`[data-msg-index]`)).filter(e=>t.includes(Number(e.dataset.msgIndex))),[t]);(0,Q.useEffect)(()=>{let t=e;if(!t)return;let n=0,r=()=>{let e=t.scrollTop,n=t.getBoundingClientRect().top,r=v(t).map(e=>_(t,e,n)),i=0;for(let t=0;t<r.length;t++)r[t]<=e+12&&(i=t+1);let o={hasAbove:r.some(t=>t<e-4),atBottom:t.scrollHeight-e-t.clientHeight<8,idx:i,total:r.length};a(e=>e.hasAbove===o.hasAbove&&e.atBottom===o.atBottom&&e.idx===o.idx&&e.total===o.total?e:o)},i=()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(r)};r(),t.addEventListener(`scroll`,i,{passive:!0});let o=new ResizeObserver(i);return o.observe(t),()=>{n&&cancelAnimationFrame(n),t.removeEventListener(`scroll`,i),o.disconnect()}},[e,v]),(0,Q.useEffect)(()=>{if(!o)return;let e=setTimeout(()=>s(!1),f.current);return()=>clearTimeout(e)},[o,i.idx,c]),(0,Q.useEffect)(()=>{if(!o||!g.current)return;g.current=!1;let e=p.current;(e?.querySelector(`button:not(:disabled)`)??e)?.focus()},[o]),(0,Q.useEffect)(()=>{o||!h.current||(h.current=!1,m.current?.focus())},[o]);let y=(0,Q.useCallback)(()=>{f.current=an,d(e=>e+1)},[]),b=(0,Q.useCallback)(()=>{let t=e;if(!t)return;let n=t.scrollTop,r=t.getBoundingClientRect().top,i;for(let e of v(t)){let a=_(t,e,r);if(a<n-4)i=a;else break}i!=null&&t.scrollTo({top:i,behavior:`auto`}),y()},[e,v,y]),x=(0,Q.useCallback)(()=>{let t=e;if(!t)return;let r=t.scrollTop,i=t.getBoundingClientRect().top,a=v(t).map(e=>_(t,e,i)).find(e=>e>r+4);a==null?n({animation:`instant`}):t.scrollTo({top:a,behavior:`auto`}),y()},[e,v,n,y]),S=(0,Q.useCallback)(()=>{n({animation:`instant`}),y()},[n,y]);(0,Q.useEffect)(()=>{let t=e;if(!t)return;let n=e=>()=>{rn(t)&&(e(),f.current=on,s(!0))},r=n(b),i=n(x);return window.addEventListener(`chat-nav-prev`,r),window.addEventListener(`chat-nav-next`,i),()=>{window.removeEventListener(`chat-nav-prev`,r),window.removeEventListener(`chat-nav-next`,i)}},[e,b,x]);let C=F(`w-[34px] flex items-center justify-center rounded-[9px] text-text-secondary`,`motion-safe:transition-colors hover:bg-surface-elevated hover:text-foreground`,`disabled:opacity-30 disabled:cursor-default disabled:hover:bg-transparent disabled:hover:text-text-secondary`,r?`h-9`:`h-[30px]`);return(0,$.jsx)(`div`,{className:`absolute bottom-3 right-2.5 z-10 flex flex-col items-end gap-1.5`,children:o?(0,$.jsxs)(`div`,{ref:p,tabIndex:-1,className:`flex flex-col p-[3px] rounded-xl border border-border bg-surface-elevated/95 backdrop-blur-[8px] shadow-lg outline-none`,onFocus:()=>{h.current=!0},onKeyDown:e=>{e.key===`Escape`&&s(!1)},children:[(0,$.jsx)(`button`,{type:`button`,onClick:b,disabled:!i.hasAbove,"aria-label":`Jump to previous message`,className:C,children:(0,$.jsx)(Le,{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)(l,{className:`size-[15px]`})}),(0,$.jsx)(`button`,{type:`button`,onClick:S,disabled:i.atBottom,"aria-label":`Jump to latest`,className:C,children:(0,$.jsx)(mt,{className:`size-[13px]`})})]}):(0,$.jsx)(`button`,{ref:m,type:`button`,onClick:()=>{f.current=an,g.current=!0,s(!0)},"aria-label":`Navigate messages`,"aria-expanded":!1,title:`Navigate messages`,className:F(`group flex items-center justify-center`,r?`size-11`:`size-[30px]`),children:(0,$.jsx)(`span`,{className:F(`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)(He,{className:`size-[15px]`})})})})}function ln(e){try{return new Date(e).toLocaleString()}catch{return``}}function un({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 dn({content:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsx)(un,{icon:t?(0,$.jsx)(o,{className:`size-3.5`}):(0,$.jsx)(it,{className:`size-3.5`}),label:t?`Copied`:`Copy`,title:`Copy message to clipboard`,onClick:()=>{Ze(e),n(!0),setTimeout(()=>n(!1),1500)}})}function fn({timestamp:e,content:t,accountLabel:n,className:r,children:i}){return(0,$.jsxs)(`div`,{className:F(`flex items-center gap-0.5 flex-wrap text-xs text-text-subtle select-none`,r),children:[(0,$.jsx)(`time`,{title:ln(e),className:`pr-1 tabular-nums`,children:ct(e)}),n&&(0,$.jsxs)(`span`,{className:`px-1 truncate max-w-40`,children:[`via `,n]}),(0,$.jsx)(dn,{content:t}),i]})}function pn({group:e,onNavigate:t,disabled:n}){if(!e||e.ids.length<2)return null;let{ids:r,currentIndex:i}=e,a=e=>{let i=r[e];i&&!n&&t(i)};return(0,$.jsxs)(`div`,{className:`mt-1 flex items-center gap-1 text-xs text-text-subtle select-none`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>a(i-1),disabled:n||i<=0,"aria-label":`Previous version`,className:`flex items-center justify-center rounded p-0.5 hover:text-text-primary disabled:opacity-30 disabled:cursor-default`,children:(0,$.jsx)(at,{className:`size-3.5`})}),(0,$.jsxs)(`span`,{className:`tabular-nums`,children:[i+1,`/`,r.length]}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>a(i+1),disabled:n||i>=r.length-1,"aria-label":`Next version`,className:`flex items-center justify-center rounded p-0.5 hover:text-text-primary disabled:opacity-30 disabled:cursor-default`,children:(0,$.jsx)(d,{className:`size-3.5`})})]})}function mn(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 hn(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=document.activeElement===e.customInputRef.current;if(!i&&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(!i&&(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(!i){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`&&i&&e.customInputRef.current?.blur()},a=r.current;return a&&(a.addEventListener(`keydown`,i),a.setAttribute(`tabindex`,`0`),a.contains(document.activeElement)||a.focus()),()=>{a?.removeEventListener(`keydown`,i)}},[e,t]),{focusedOption:t,setFocusedOption:n,containerRef:r}}function gn({questions:e,onSubmit:t,onSkip:n}){let r=(0,Q.useRef)(null),i=mn(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=hn({questions:e,activeTab:i.activeTab,totalOptions:o,allAnswered:i.allAnswered,hasAnswer:i.hasAnswer,onSelectOption:l,goToNextTab:i.goToNextTab,goToPrevTab:i.goToPrevTab,onSubmit:c,customInputRef:r,enabled:!0}),d=(0,Q.useCallback)(e=>{l(e),u.setFocusedOption(e)},[l,u.setFocusedOption]);return(0,$.jsxs)(`div`,{ref:u.containerRef,className:`rounded-lg border-2 border-primary/30 bg-primary/5 p-3 space-y-3 outline-none animate-in slide-in-from-bottom-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,$.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,$.jsxs)(`span`,{className:`text-[10px] text-text-secondary font-normal`,children:[s?`←→ tabs · `:``,`↑↓ options · 1-`,Math.min(o-1,9),` select · Enter submit`]})]}),s&&(0,$.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,$.jsxs)(`button`,{className:`flex items-center gap-1.5 px-3 py-1.5 rounded text-xs whitespace-nowrap transition-all ${i.activeTab===t?`bg-primary text-primary-foreground`:i.hasAnswer(t)?`text-primary bg-transparent`:`text-text-secondary hover:bg-surface-elevated`}`,onClick:()=>{i.setActiveTab(t),u.setFocusedOption(0)},tabIndex:-1,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-semibold ${i.activeTab===t?`bg-white/20`:i.hasAnswer(t)?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:i.hasAnswer(t)?`✓`:t+1}),(0,$.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,$.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,$.jsx)(`div`,{className:`text-sm text-text-primary select-text`,children:a.question}),a.multiSelect&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a.options.map((e,t)=>{let n=(i.answers[i.activeTab]||[]).includes(e.label),r=u.focusedOption===t;return(0,$.jsxs)(`div`,{role:`button`,onClick:()=>d(t),className:`text-left flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border transition-all cursor-pointer select-text ${n?`border-primary bg-primary/10 text-text-primary`:`border-border bg-background text-text-secondary hover:border-primary/40 hover:bg-primary/5`} ${r?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded text-[10px] font-semibold shrink-0 mt-px ${n?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:t+1}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,$.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,$.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border border-dashed transition-all border-border bg-transparent ${u.focusedOption===o-1?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded bg-surface-elevated text-text-secondary text-[10px] font-semibold shrink-0 mt-px`,children:`O`}),(0,$.jsx)(`input`,{ref:r,type:`text`,className:`flex-1 px-2 py-1 text-xs bg-surface border border-border rounded text-text-primary outline-none placeholder:text-text-subtle focus:border-primary`,placeholder:`Other (press O to type)...`,value:i.customInputs[i.activeTab]||``,onChange:e=>i.handleCustomInput(i.activeTab,e.target.value),onFocus:()=>u.setFocusedOption(o-1)})]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToPrevTab,disabled:i.activeTab===0,tabIndex:-1,children:`← Prev`}),(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToNextTab,disabled:i.activeTab===e.length-1,tabIndex:-1,children:`Next →`})]}),(0,$.jsx)(`button`,{onClick:n,className:`px-4 py-1.5 rounded border border-border bg-background text-text-secondary text-xs hover:bg-surface-elevated transition-colors`,tabIndex:-1,children:`Skip`}),(0,$.jsxs)(`button`,{onClick:c,disabled:!i.allAnswered,className:`px-4 py-1.5 rounded bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,tabIndex:-1,children:[`Submit `,i.allAnswered?`✓`:`(${e.filter((e,t)=>i.hasAnswer(t)).length}/${e.length})`]})]})]})}var _n={"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 vn(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:_n[e]??e.replace(/^antml:/,``).replace(/-/g,` `),content:r[2].trim()})}return{cleanText:e.replace(n,``).trim(),tags:t}}function yn(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 bn(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 xn(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 Sn(e){let t=e.match(/^\[Attached file: (.+?)\]\n*/);if(t)return{files:[t[1]],text:e.slice(t[0].length)};let n=e.match(/^\[Attached files:\n([\s\S]+?)\]\n*/);return n?{files:n[1].split(`
|
|
3
|
+
`).map(e=>e.trim()).filter(Boolean),text:e.slice(n[0].length)}:{files:[],text:e}}function Cn(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 wn(e){let{idePath:t,cleanText:n}=xn(e),{blocks:r,remainingText:i}=Cn(n),a=Sn(i),{cleanText:o,tags:s}=vn(a.text.replace(/<local-command-(?:stdout|stderr)>([\s\S]*?)<\/local-command-(?:stdout|stderr)>/g,`$1`)),{command:c,cleanText:l}=yn(o),{agent:u,cleanText:d}=bn(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 Tn(e){let{agent:t,body:n,command:r}=wn(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 En=re(()=>import(`./markdown-renderer-zRn368SN.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28])),Dn=(0,Q.lazy)(()=>En.then(e=>({default:e.MarkdownRenderer})));function On({messages:e,messagesLoading:t,keepStaleWhileLoading:n,pendingApproval:r,onApprovalResponse:a,isStreaming:o,phase:s,onSelectSession:c,connectingElapsed:l,statusMessage:u,compactStatus:d,projectName:p,onFork:m,onEdit:h,editingMsgId:g,sessionId:_,providerId:v,onNavigateVersion:y,versionMap:b,bashPartialOutput:x,onExpandCompact:S,isCompactExpanded:C,onDismissMessage:w,onClearErrors:T}){let{scrollRef:E,contentRef:ee,scrollToBottom:D,stopScroll:te,isAtBottom:O}=Ut({initial:`instant`,resize:`instant`}),k=(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]),ne=!!r||o,[A,j]=(0,Q.useState)(null),M=(0,Q.useCallback)(e=>{E(e),j(e)},[E]),N=(0,Q.useRef)(null);(0,Q.useLayoutEffect)(()=>{let e=A;e&&N.current!=null&&(e.scrollTop=e.scrollHeight-N.current,N.current=null)},[k.length,A]),(0,Q.useLayoutEffect)(()=>{A&&D({animation:`instant`})},[_,A]);let re=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>{A&&A.clientHeight>0&&(re.current=O)},[O,A]),(0,Q.useEffect)(()=>{let e=A;if(!e)return;let t=e.clientHeight,n=new ResizeObserver(()=>{let n=e.clientHeight,r=t===0&&n>0;t=n,r&&!re.current&&te()});return n.observe(e),()=>n.disconnect()},[A,te]);let P=(0,Q.useCallback)((e,t)=>{m?.(e,t)},[m]),F=(0,Q.useCallback)((e,t,n)=>{h?.(e,t,n)},[h]),ie=(0,Q.useCallback)(e=>{w?.(e)},[w]),I=(0,Q.useMemo)(()=>k.reduce((e,t)=>t.role===`system`?e+1:e,0),[k]),ae=(0,Q.useMemo)(()=>k.reduce((e,t,n)=>(t.role===`user`&&e.push(n),e),[]),[k]),L=(0,Q.useCallback)(()=>{if(!S||!C)return null;for(let e of k){if(C(e.id))continue;let t=en(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=en(t.content||``);if(n)return{id:e.id,jsonlPath:n}}}}return null},[k,S,C])(),oe=!!L,[R,z]=(0,Q.useState)(!1),se=(0,Q.useCallback)(async()=>{if(!L||!S||R)return;let e=A;N.current=e?e.scrollHeight-e.scrollTop:null,z(!0);try{await S(L.id,L.jsonlPath)}finally{z(!1)}},[L,S,R,A]);return(0,Q.useEffect)(()=>{let e=A;if(!e||!oe)return;let t=()=>{e.scrollTop<200&&!R&&se()};return e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[A,oe,R,se]),t&&(!n||e.length===0)?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,$.jsx)(i,{className:`size-10 text-text-subtle animate-pulse`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!o?(0,$.jsx)(nn,{projectName:p||``,onSelectSession:c||(()=>{})}):(0,$.jsxs)(`div`,{className:`relative flex-1 overflow-hidden flex flex-col min-h-0`,children:[(0,$.jsx)(Zt,{projectName:p,sessionId:_,messages:e}),I>1&&T&&(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:T,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)(f,{className:`size-3.5`}),`Clear all errors (`,I,`)`]})}),R&&(0,$.jsxs)(`div`,{className:`absolute top-2 left-0 right-0 z-10 flex items-center justify-center gap-1.5 text-xs text-text-secondary pointer-events-none`,children:[(0,$.jsx)(X,{className:`size-3 animate-spin`}),`Loading previous conversation...`]}),(0,$.jsx)(`div`,{ref:M,className:`flex-1 overflow-y-auto overflow-x-hidden [overflow-anchor:none]`,style:{WebkitOverflowScrolling:`touch`,overscrollBehavior:`contain`},children:(0,$.jsxs)(`div`,{ref:ee,className:`w-full`,children:[k.map((e,t)=>{let n=t>0?k[t-1]:void 0,r=e.role===`user`?k.slice(0,t+1).reduce((e,t)=>e+(t.role===`user`?1:0),0):0,i=r?b?.[r]:void 0,a=e.role===`user`&&g!=null&&e.id===g,s=k[t+1],c=e.role===`assistant`&&s?.role!==`assistant`,l;if(c){let e=[];for(let n=t;n>=0&&k[n].role===`assistant`;n--){let t=kn(k[n]);t&&e.unshift(t)}l=e.join(`
|
|
4
|
+
|
|
5
|
+
`)}return(0,$.jsx)(`div`,{"data-msg-index":t,className:`px-4 pt-4 select-none`,children:(0,$.jsx)(tn,{fallbackContent:e.content,children:(0,$.jsx)(An,{message:e,isStreaming:o&&e.id.startsWith(`streaming-`),isLastAssistantInTurn:c,turnCopyText:l,projectName:p,onFork:e.role===`user`&&m?P:void 0,onEdit:e.role===`user`&&h?F:void 0,isEditing:a,onDismiss:e.role===`system`&&w?ie:void 0,prevMsgId:n?.sdkUuid??n?.id,sessionId:_,providerId:v,versionGroup:i,onNavigateVersion:y,versionNavDisabled:o,bashPartialOutput:x})})},e.id)}),ne&&(0,$.jsxs)(`div`,{className:`px-4 pt-4 pb-4 space-y-4 select-none`,children:[r&&(r.tool===`AskUserQuestion`?(0,$.jsx)(tr,{approval:r,onRespond:a}):(0,$.jsx)(er,{approval:r,onRespond:a})),o&&(0,$.jsx)(Xn,{lastMessage:e[e.length-1],phase:s,elapsed:l,statusMessage:d===`compacting`?`Compacting messages...`:u})]})]})}),(0,$.jsx)(cn,{scrollElement:A,userIndices:ae,scrollToBottom:D})]})}function kn(e){return e.events?.length?e.events.filter(e=>e.type===`text`).map(e=>e.content).join(``):e.content}var An=(0,Q.memo)(function({message:e,isStreaming:t,isLastAssistantInTurn:n,turnCopyText:r,projectName:i,onFork:a,onEdit:o,isEditing:s,onDismiss:c,prevMsgId:l,sessionId:u,providerId:d,versionGroup:p,onNavigateVersion:m,versionNavDisabled:h,bashPartialOutput:g}){if(e.role===`user`){let t=a?()=>a(e.content,l):void 0,n=o?()=>o(e.content,l,e.id):void 0;return(0,$.jsx)(Fn,{content:e.content,messageId:e.id,timestamp:e.timestamp,projectName:i,onFork:t,onEdit:n,isEditing:s,sessionId:u,providerId:d,versionGroup:p,onNavigateVersion:m,versionNavDisabled:h})}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)(We,{className:`size-4 shrink-0`}),(0,$.jsx)(`p`,{className:`flex-1`,children:e.content}),c&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>c(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)(f,{className:`size-4`})})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.events&&e.events.length>0?(0,$.jsx)(qn,{events:e.events,isStreaming:t,projectName:i,bashPartialOutput:g}):e.content&&(0,$.jsx)(`div`,{className:`text-sm text-text-primary select-text`,children:(0,$.jsx)($n,{content:e.content,projectName:i})}),!t&&n&&(0,$.jsx)(fn,{timestamp:e.timestamp,content:r??kn(e),accountLabel:e.accountLabel,className:`-mt-1.5`})]})}),jn=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]);function Mn(e,t){let n=I(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function Nn(e){let t=e.lastIndexOf(`.`);return t===-1?!1:jn.has(e.slice(t).toLowerCase())}var Pn=new Set([`task-notification`,`environment_details`,`local-command-caveat`]);function Fn({content:e,messageId:t,timestamp:n,projectName:r,onFork:a,onEdit:o,isEditing:c,sessionId:u,providerId:d,versionGroup:f,onNavigateVersion:p,versionNavDisabled:m}){let{files:h,text:g,tags:_,command:v,terminalBlocks:y,idePath:b,agent:x}=(0,Q.useMemo)(()=>wn(e),[e]),S=_.some(e=>Pn.has(e.name)),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(!1),ee=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let e=ee.current;if(!e)return;let t=()=>E(e.scrollHeight>e.clientHeight+2);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[g]),(0,$.jsxs)(`div`,{className:F(`flex flex-col gap-1`,!S&&`items-end`),children:[(0,$.jsxs)(`div`,{"data-user-message":S?void 0:`true`,style:S?void 0:{borderRadius:`var(--rad) var(--rad) 4px var(--rad)`},className:F(`group/user relative px-3 py-2 text-sm border shadow-sm transition-all`,S?`rounded-lg bg-surface/40 border-border/40 text-text-secondary`:`max-w-[80%] bg-accent-wash border-accent-wash-border text-text`,c&&`ring-2 ring-primary/60 border-primary/40`),children:[_.length>0&&(0,$.jsx)(Ln,{tags:_}),x&&(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-sky-500/15 border border-sky-500/25 px-2 py-0.5 text-xs font-medium text-sky-600 dark:text-sky-400`,children:[(0,$.jsx)(i,{className:`size-3 shrink-0`}),x]})}),v&&(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-primary/15 border border-primary/20 px-2 py-0.5 text-xs font-medium text-primary`,children:[(0,$.jsx)(xt,{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)(Vn,{path:b,projectName:r})]}),h.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:h.map((e,t)=>Nn(e)?(0,$.jsx)(Kn,{filePath:e,projectName:r},t):(0,$.jsxs)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-background/40 px-1.5 py-0.5 text-[11px] text-text-secondary`,children:[(0,$.jsx)(Qe,{className:`size-3 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-32`,children:I(e)})]},t))}),y.length>0&&(0,$.jsx)(`div`,{className:`space-y-1.5`,children:y.map((e,t)=>(0,$.jsx)(In,{content:e},t))}),g&&(0,$.jsx)(`div`,{ref:ee,className:F(`whitespace-pre-wrap break-words transition-all duration-200 select-text`,!C&&`line-clamp-2`,C&&`max-h-[50vh] overflow-y-auto`),children:S?(0,$.jsx)(Un,{text:g,projectName:r}):(0,$.jsx)(Hn,{text:g})}),(T||C)&&(0,$.jsx)(`button`,{onClick:()=>w(!C),className:F(`flex items-center gap-1 text-xs mt-1 transition-colors`,S?`text-text-subtle hover:text-text-secondary`:`text-primary/70 hover:text-primary`),children:C?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Le,{className:`size-3`}),`Show less`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(l,{className:`size-3`}),`Show more`]})}),!S&&p&&(0,$.jsx)(pn,{group:f,onNavigate:p,disabled:m})]}),!S&&(0,$.jsxs)(fn,{timestamp:n,content:e,children:[o&&(0,$.jsx)(un,{icon:(0,$.jsx)(s,{className:`size-3.5`}),label:`Edit`,title:`Edit this message (continue in the same tab)`,onClick:o}),a&&(0,$.jsx)(un,{icon:(0,$.jsx)(Ne,{className:`size-3.5`}),label:`Fork`,title:`Retry from this message (fork into a new tab)`,onClick:a})]})]})}function In({content:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),className:F(`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)(xe,{className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{children:`Terminal output`}),(0,$.jsx)(l,{className:F(`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 Ln({tags:e}){return(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,$.jsx)(Rn,{tag:e},t))})}function Rn({tag:e}){let[t,n]=(0,Q.useState)(!1);return e.name===`task-notification`?(0,$.jsx)(Bn,{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)(he,{className:`size-2.5`}),(0,$.jsx)(`span`,{children:e.label}),(0,$.jsx)(d,{className:F(`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 zn(e,t){return e.match(RegExp(`<${t}>([\\s\\S]*?)</${t}>`))?.[1]?.trim()||void 0}function Bn({content:e}){let[t,n]=(0,Q.useState)(!1),r=zn(e,`status`),i=zn(e,`summary`),a=zn(e,`output-file`),o=zn(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)(Ye,{className:`size-2.5 text-success`}):(0,$.jsx)(f,{className:`size-2.5 text-warning`}),(0,$.jsx)(`span`,{className:`truncate max-w-80`,children:i??`Task notification`}),(0,$.jsx)(d,{className:F(`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)(Vn,{path:a}),o&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-subtle/80 max-h-60 overflow-y-auto leading-relaxed`,children:(0,$.jsx)($n,{content:o})})]})]})}function Vn({path:e,projectName:t}){return(0,$.jsxs)(`button`,{type:`button`,onClick:(0,Q.useCallback)(()=>{let n=oe.getState().openTab,r=t??L.getState().activeProject?.name,i=I(e),a={filePath:e};r&&(a.projectName=r),N.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)(Qe,{className:`size-2.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-60`,children:I(e)}),(0,$.jsx)(Je,{className:`size-2 shrink-0 opacity-50`})]})}function Hn({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 Un({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)(Vn,{path:e.value,projectName:t},n):(0,$.jsx)(`span`,{children:e.value},n))})}var Wn=new Map;function Gn(e){let[t,n]=(0,Q.useState)(()=>Wn.get(e)?.url??null),[r,i]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{let t=Wn.get(e);if(t){n(t.url);return}let r=!1,a=A();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);Wn.set(e,{url:i}),n(i)}).catch(()=>{r||i(!0)}),()=>{r=!0}},[e]),{blobUrl:t,error:r}}function Kn({filePath:e,projectName:t}){let{blobUrl:n,error:r}=Gn(Mn(e,t)),i=tt(e=>e.open),a=I(e);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n&&i(n,a),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,className:`size-4 rounded-sm object-cover shrink-0`}):r?(0,$.jsx)(de,{className:`size-3 shrink-0`}):(0,$.jsx)(`div`,{className:`size-4 rounded-sm bg-surface animate-pulse shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-32`,children:a})]})}function qn({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}n.type===`text`?a+=n.content:n.type===`tool_use`?(a&&=(i.push({kind:`text`,content:a}),``),i.push({kind:`tool`,tool:n})):n.type===`tool_result`||(a&&=(i.push({kind:`text`,content:a}),``),i.push({kind:`tool`,tool:n}))}o&&i.push({kind:`thinking`,content:o}),a&&i.push({kind:`text`,content:a});let s=e.filter(e=>e.type===`tool_result`);for(let e of s){let t=e.toolUseId;if(t){let n=i.find(e=>e.kind===`tool`&&e.tool.type===`tool_use`&&e.tool.toolUseId===t);if(n){n.result=e;continue}}let n=i.find(e=>e.kind===`tool`&&!e.result);n&&(n.result=e)}for(let e of i)if(e.kind===`tool`&&!e.result&&e.tool.type===`tool_use`){let t=e.tool.result;t&&(e.result={type:`tool_result`,output:t.output,isError:t.isError})}for(let e=0;e<i.length;e++){let n=i[e];if(n.kind===`tool`&&!n.result){let r=!1;if(n.tool.type===`tool_use`&&n.tool.tool===`Read`){let t=n.tool.input?.file_path;t&&(r=i.slice(e+1).some(e=>e.kind===`tool`&&e.result&&e.tool.type===`tool_use`&&e.tool.tool===`Edit`&&e.tool.input?.file_path===t))}n.completed=r||!t}}return(0,$.jsx)($.Fragment,{children:i.map((e,a)=>{if(e.kind===`thinking`)return(0,$.jsx)(Jn,{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)(Yn,{content:e.content,animate:r,projectName:n})},`text-${a}`)}return(0,$.jsx)(g,{tool:e.tool,result:e.result,completed:e.completed,projectName:n,bashPartialOutput:r},`tool-${a}`)})})}function Jn({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)(X,{className:`size-3 animate-spin`}):(0,$.jsx)(d,{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 Yn({content:e,animate:t,projectName:n}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)($n,{content:e,projectName:n,isStreaming:t}),t&&(0,$.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function Xn({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)(X,{className:`size-3 animate-spin`}),(0,$.jsxs)(`span`,{children:[r||(t===`initializing`?`Initializing`:t===`connecting`?`Connecting`:t===`thinking`?`Thinking`:`Processing`),i&&(n??0)>0&&(0,$.jsxs)(`span`,{className:`text-text-subtle/60`,children:[`... (`,n,`s)`]})]})]}),t===`connecting`&&(n??0)>=30&&(0,$.jsx)(`p`,{className:`text-xs text-warning/80 ml-5`,children:`Taking longer than usual — may be rate-limited or API slow. Try sending a new message to retry.`})]})}var Zn=/<teammate-message[^>]*>[\s\S]*?<\/teammate-message>/g;function Qn(e){return e.replace(Zn,``).replace(/\n{3,}/g,`
|
|
6
|
+
|
|
7
|
+
`).trim()}function $n({content:e,projectName:t,isStreaming:n}){let r=Qn(e);return r?(0,$.jsx)(tn,{fallbackContent:r,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`animate-pulse h-4 bg-muted rounded`}),children:(0,$.jsx)(Dn,{content:r,projectName:t,codeActions:!0,isStreaming:n})})}):null}function er({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)(bt,{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 tr({approval:e,onRespond:t}){return(0,$.jsx)(gn,{questions:e.input.questions??[],onSubmit:n=>t(e.requestId,!0,n),onSkip:()=>t(e.requestId,!1)})}function nr({shells:e,onKill:t}){let n=rt(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)(X,{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)(xe,{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)(D,{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)(ve,{className:`size-3.5`})})]},e.shellId))})}function rr(){let e=window;return e.SpeechRecognition??e.webkitSpeechRecognition??null}function ir(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`&&rr()!==null;return{isListening:t,interimText:r,start:(0,Q.useCallback)(t=>{let r=rr();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 ar=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]);function or(e){return ar.has(e.type)}function sr({attachments:e,onRemove:t}){let[n,r]=(0,Q.useState)(null);if(e.length===0)return null;let i=n?e.find(e=>e.id===n):null;return(0,$.jsxs)(`div`,{className:`px-2 md:px-4 pt-2`,children:[(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,$.jsxs)(`div`,{className:F(`flex items-center gap-1.5 rounded-md border border-border bg-surface px-2 py-1 text-xs text-text-secondary max-w-48`,e.textContent&&`cursor-pointer hover:border-primary/50`,n===e.id&&`border-primary/50 bg-surface-elevated`),onClick:()=>{e.textContent&&r(n===e.id?null:e.id)},children:[e.previewUrl?(0,$.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.textContent?(0,$.jsx)(xe,{className:`size-3.5 shrink-0 text-text-subtle`}):e.isImage?(0,$.jsx)(de,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,$.jsx)(Qe,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name}),e.textContent&&(0,$.jsx)(l,{className:F(`size-3 shrink-0 text-text-subtle transition-transform`,n===e.id&&`rotate-180`)}),e.status===`uploading`?(0,$.jsx)(X,{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:`!`}):null,(0,$.jsx)(`button`,{type:`button`,onClick:i=>{i.stopPropagation(),t(e.id),n===e.id&&r(null)},className:`shrink-0 rounded-sm p-0.5 hover:bg-border/50 transition-colors`,"aria-label":`Remove ${e.name}`,children:(0,$.jsx)(ne,{className:`size-3`})})]},e.id))}),i?.textContent&&(0,$.jsx)(`pre`,{className:`mt-1.5 max-h-40 overflow-auto rounded-md border border-border bg-background p-2 text-xs text-text-primary font-mono whitespace-pre-wrap break-words`,children:cr(i.textContent)})]})}function cr(e){let t=e.trim(),n=t.match(/^```\w*\n([\s\S]*?)\n```$/);return n?n[1]:t}function lr(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 ur=[{id:`default`,label:`Ask before edits`,icon:gt,description:`Claude will ask for approval before making each edit`},{id:`acceptEdits`,label:`Edit automatically`,icon:T,description:`Claude will edit files without asking first`},{id:`plan`,label:`Plan mode`,icon:p,description:`Claude will present a plan before editing`},{id:`bypassPermissions`,label:`Bypass permissions`,icon:k,description:`Claude will not ask before running commands`}];function dr(e){return ur.find(t=>t.id===e)?.label??`Unknown`}function fr(e){return ur.find(t=>t.id===e)?.icon??gt}function pr({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)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[n,r]),(0,Q.useEffect)(()=>{n&&(a.current=ur.findIndex(t=>t.id===e),a.current<0&&(a.current=0))},[n,e]);let s=(0,Q.useCallback)(e=>{if(e.key===`Escape`){r(!1);return}if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=e.key===`ArrowDown`?1:-1;a.current=(a.current+t+ur.length)%ur.length,(i.current?.querySelector(`[data-idx="${a.current}"]`))?.focus()}if(e.key===`Enter`){e.preventDefault();let n=ur[a.current];n&&(t(n.id),r(!1))}},[t,r]);return n?(0,$.jsxs)(`div`,{ref:i,role:`listbox`,"aria-label":`Permission modes`,onKeyDown:s,onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),className:`absolute bottom-full left-0 mb-1 z-50 w-72 md:w-80 rounded-lg border border-border popover-solid shadow-[var(--shadow-panel)]`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-text-secondary`,children:`Modes`}),(0,$.jsx)(`kbd`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-text-subtle border border-border`,children:`Shift + Tab`})]}),(0,$.jsx)(`div`,{className:`py-1`,children:ur.map((n,i)=>{let a=n.icon,s=n.id===e;return(0,$.jsxs)(`button`,{"data-idx":i,role:`option`,"aria-selected":s,tabIndex:0,onClick:()=>{t(n.id),r(!1)},className:`w-full flex items-start gap-3 px-3 py-2.5 text-left transition-colors hover:bg-surface-elevated focus:bg-surface-elevated focus:outline-none ${s?`bg-surface-elevated`:``}`,children:[(0,$.jsx)(a,{className:`size-4 mt-0.5 shrink-0 text-text-secondary`}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-text-primary`,children:n.label}),(0,$.jsx)(`div`,{className:`text-xs text-text-subtle leading-snug`,children:n.description})]}),s&&(0,$.jsx)(o,{className:`size-4 mt-0.5 shrink-0 text-primary`})]},n.id)})})]}):null}var mr=[{label:`Low`,value:`low`},{label:`Medium`,value:`medium`},{label:`High`,value:`high`,default:!0},{label:`Extra`,value:`xhigh`},{label:`Max`,value:`max`}];function hr(e){return e?mr.find(t=>t.value===e)?.label??e:``}function gr(e,t){let n=hr(t);return n?`${e} · ${n}`:e}function _r(e){return e.replace(/^Claude\s+/i,``)}var vr=mr.find(e=>e.default).value;function yr({model:e,effort:t,thinking:n,onModelChange:r,onEffortChange:i,onThinkingChange:s,projectName:l,providerId:d,disabled:f}){let[p,m]=(0,Q.useState)([]),[h,g]=(0,Q.useState)(!1),_=(0,Q.useRef)(null),v=u();(0,Q.useEffect)(()=>{!l||!d||N.get(`${M(l)}/chat/providers/${d}/models`).then(m).catch(()=>{})},[l,d]),(0,Q.useEffect)(()=>{f&&g(!1)},[f]),(0,Q.useEffect)(()=>{if(!h||v)return;let e=e=>{_.current&&!_.current.contains(e.target)&&g(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[h,v]);let y=p.find(t=>t.value===e),b=y?_r(y.label):e?_r(e):`Model`,x=t??vr,S=p.length>1,C=gr(b,x),w=e=>{e(),v||g(!1)},T=(0,$.jsxs)(`div`,{className:`flex divide-x divide-border`,children:[S&&(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 py-1`,children:[(0,$.jsx)(br,{children:`Model`}),p.map(t=>(0,$.jsxs)(Sr,{active:t.value===e,onClick:()=>w(()=>r(t.value)),children:[(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:_r(t.label)}),t.value===e&&(0,$.jsx)(o,{className:`size-4 shrink-0 text-primary`})]},t.value))]}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 py-1`,children:[(0,$.jsx)(br,{children:`Effort`}),mr.map(e=>(0,$.jsxs)(Sr,{active:e.value===x,onClick:()=>w(()=>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===x&&(0,$.jsx)(o,{className:`size-4 shrink-0 text-primary`})]},e.value)),(0,$.jsx)(xr,{}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>s(!n),className:`w-full flex items-center gap-3 px-3 min-h-[44px] text-left text-sm hover:bg-surface-elevated`,role:`switch`,"aria-checked":n,children:[(0,$.jsx)(a,{className:`size-4 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1`,children:`Thinking`}),(0,$.jsx)(`span`,{className:`inline-flex h-5 w-9 items-center rounded-full transition-colors ${n?`bg-primary`:`bg-border`}`,children:(0,$.jsx)(`span`,{className:`h-4 w-4 rounded-full bg-white transition-transform ${n?`translate-x-4`:`translate-x-0.5`}`})})]})]})]});return(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsxs)(`button`,{type:`button`,disabled:f,onClick:e=>{e.stopPropagation(),f||g(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 ${b}, effort ${x}${n?`, thinking on`:``}`,title:f?`Can't change while running`:C,children:[(0,$.jsx)(ee,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`max-w-[140px] truncate`,children:C}),n&&(0,$.jsx)(a,{className:`h-3 w-3 shrink-0`})]}),h&&!f&&(v?(0,$.jsx)(c,{open:h,onClose:()=>g(!1),children:(0,$.jsx)(`div`,{className:`px-1 pb-2`,children:T})}):(0,$.jsx)(`div`,{ref:_,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:T}))]})}function br({children:e}){return(0,$.jsx)(`div`,{className:`px-3 py-1.5 text-xs font-medium text-text-secondary`,children:e})}function xr(){return(0,$.jsx)(`div`,{className:`my-1 border-t border-border`})}function Sr({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 Cr=new Map;function wr(e){let t=Cr.get(e);if(t)return t;let n=N.get(`${M(e)}/chat/slash-items`).then(e=>({items:e.items??[],recentNames:e.recentNames??[]})).catch(t=>{throw Cr.delete(e),t});return Cr.set(e,n),n}function Tr(e){e?Cr.delete(e):Cr.clear()}var Er=(0,Q.memo)(function({onSend:e,isStreaming:t,onCancel:n,disabled:r,projectName:a,onSlashStateChange:o,onSlashItemsLoaded:s,slashSelected:c,onFileStateChange:l,onFileItemsLoaded:u,fileSelected:d,externalFiles:f,externalPaths:p,onExternalPathsConsumed:m,initialValue:h,clearSignal:g,onContentChange:_,getUserHistory:v,autoFocus:y,permissionMode:b,onModeChange:x,providerId:S,onProviderChange:C,model:w,onModelChange:T,effort:E,onEffortChange:ee,thinking:D,onThinkingChange:te}){let O=(0,Q.useRef)(h??``),[k,j]=(0,Q.useState)(()=>(h??``).trim().length>0),[N,re]=(0,Q.useState)([]),[P,F]=(0,Q.useState)(null),[I,ae]=(0,Q.useState)(!1),[L,oe]=(0,Q.useState)(!1),[R,z]=(0,Q.useState)(`next`),se=(0,Q.useRef)(null),ce=(0,Q.useRef)(null),le=(0,Q.useRef)(null),ue=(0,Q.useRef)([]),B=(0,Q.useRef)([]),V=(0,Q.useRef)(0),H=(0,Q.useRef)(!1),U=(0,Q.useRef)(!1),W=(0,Q.useRef)(typeof CSS>`u`||!CSS.supports(`field-sizing`,`content`)),G=(0,Q.useCallback)(e=>{O.current=e,se.current&&(se.current.value=e),ce.current&&(ce.current.value=e),j(e.trim().length>0)},[]),K=(0,Q.useCallback)(()=>window.matchMedia(`(min-width: 768px)`).matches?se.current:ce.current,[]),de=(0,Q.useRef)(-1),fe=(0,Q.useCallback)(e=>{let t=lr(v?.()??[],de.current,e);if(!t)return!1;de.current=t.index;let{agent:n,text:r}=Tn(t.text);F(n),G(r);let i=K();return i?(i.focus(),requestAnimationFrame(()=>{i.selectionStart=i.selectionEnd=r.length}),W.current&&(i.style.height=`auto`,i.style.height=Math.min(i.scrollHeight,i===ce.current?80:160)+`px`),!0):!0},[v,G,K]),q=ir(),pe=(0,Q.useRef)(``),he=(0,Q.useCallback)(e=>{let t=pe.current;G(t?t+` `+e:e),W.current&&requestAnimationFrame(()=>{let e=K();e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,160)+`px`)})},[G,K]),ge=(0,Q.useCallback)(()=>{q.isListening?q.stop():(pe.current=O.current.trim(),q.start(he))},[q.isListening,q.start,q.stop,he]);(0,Q.useEffect)(()=>{let e=()=>{q.supported&&rn(K())&&ge()};return window.addEventListener(`toggle-voice-input`,e),()=>window.removeEventListener(`toggle-voice-input`,e)},[q.supported,ge,K]),(0,Q.useEffect)(()=>{let e=e=>{let{text:t,label:n}=e.detail??{};if(!t)return;window.dispatchEvent(new Event(`ppm:send-to-chat:ack`));let r={id:ie(),name:n??`Terminal output`,file:new File([],`terminal-output.txt`),isImage:!1,textContent:t,status:`ready`};re(e=>[...e,r]),K()?.focus()};return window.addEventListener(`ppm:send-to-chat`,e),()=>window.removeEventListener(`ppm:send-to-chat`,e)},[K]),(0,Q.useEffect)(()=>{h&&(G(h),setTimeout(()=>{let e=se.current;e&&(e.focus(),e.selectionStart=e.selectionEnd=e.value.length)},50))},[h]),(0,Q.useEffect)(()=>{g&&G(``)},[g]),(0,Q.useEffect)(()=>{y&&setTimeout(()=>{K()?.focus()},100)},[]);let _e=(0,Q.useCallback)(()=>{if(!a){ue.current=[],s?.([],[]);return}wr(a).then(e=>{ue.current=e.items,s?.(e.items,e.recentNames)}).catch(()=>{ue.current=[],s?.([],[])})},[a,s]);(0,Q.useEffect)(()=>{_e()},[_e]),(0,Q.useEffect)(()=>{let e=()=>{Tr(a),_e()};return window.addEventListener(`ppm:slash-items-refresh`,e),()=>window.removeEventListener(`ppm:slash-items-refresh`,e)},[_e,a]),(0,Q.useEffect)(()=>{let e=()=>{if(!a){B.current=[],u?.([]);return}let{fileIndex:e}=Xe.getState(),t=e.map(e=>({name:e.name,path:e.path,type:e.type}));B.current=t,u?.(t)};e();let t=Xe.getState().fileIndex,n=Xe.getState().indexStatus;return Xe.subscribe(r=>{(r.fileIndex!==t||r.indexStatus!==n)&&(t=r.fileIndex,n=r.indexStatus,e())})},[a]),(0,Q.useEffect)(()=>{if(!c)return;let e=K();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(c.type===`agent`){let t=r.replace(/(?:^|\s)\/\S*$/,a);F(c.name),G(t+i),o?.(!1,``),H.current=!1,e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length},0);return}let s=r.replace(/(?:^|\s)\/\S*$/,e=>`${a(e)}/${c.name} `);G(s+i),o?.(!1,``),H.current=!1,l?.(!1,``),U.current=!1,e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=s.length},0)},[c]),(0,Q.useEffect)(()=>{if(!d)return;let e=K();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;G(r.slice(0,t)+`@${d.path} `+i);let n=t+d.path.length+2;setTimeout(()=>{e.selectionStart=e.selectionEnd=n,e.focus()},0)}else{let n=t+`@${d.path} `;G(n),setTimeout(()=>{e.selectionStart=e.selectionEnd=n.length,e.focus()},0)}l?.(!1,``),U.current=!1},[d]),(0,Q.useEffect)(()=>{!f||f.length===0||Y(f)},[f]),(0,Q.useEffect)(()=>{if(!p||p.length===0)return;let e=p.map(e=>`@${e}`).join(` `),t=O.current;G(t+(t.length>0&&!t.endsWith(` `)?` `:``)+e+` `),K()?.focus(),m?.()},[p]);let J=(0,Q.useCallback)(async e=>{if(!a)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=A();r&&(n.Authorization=`Bearer ${r}`);let i=await(await fetch(`${M(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]),Y=(0,Q.useCallback)(async e=>{for(let t of e){let e=ie(),n=or(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};re(e=>[...e,i]),J(t).then(t=>{re(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}(ce.current??se.current)?.focus()},[J]),be=(0,Q.useCallback)(e=>{re(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),xe=(0,Q.useCallback)(()=>{let n=O.current.trim(),r=N.filter(e=>e.status===`ready`);if(!n&&r.length===0&&!P){oe(!1);return}let i=P?`Use the ${P} agent to ${n}`.trimEnd():n;o?.(!1,``),H.current=!1,l?.(!1,``),U.current=!1,q.isListening&&q.stop(),e(i,r,t?R:void 0),G(``);for(let e of N)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);re([]),F(null),oe(!1),z(`next`),de.current=-1,W.current&&(se.current&&(se.current.style.height=`auto`),ce.current&&(ce.current.style.height=`auto`))},[N,P,e,o,l,t,R,G]),Se=(0,Q.useCallback)(()=>{if(!r){if(N.some(e=>e.status===`uploading`)){(O.current.trim()||N.some(e=>e.status!==`error`))&&oe(!0);return}xe()}},[N,r,xe]);(0,Q.useEffect)(()=>{L&&(N.some(e=>e.status===`uploading`)||xe())},[L,N,xe]);let Ce=(0,Q.useCallback)(e=>{if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),Se();return}if((e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){if(!(de.current>=0)&&(e.key===`ArrowDown`||O.current!==``||P))return;fe(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)}},[Se,b,x,fe,P]),we=(0,Q.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.includes(`/`),i=n.includes(`@`);if(!r&&!i){H.current&&=(o?.(!1,``),!1),U.current&&=(l?.(!1,``),!1);return}if(r){let e=n.match(/(?:^|\s)\/(\S*)$/);if(e&&ue.current.length>0){let t=e[1]??``;o?.(!0,t),H.current=!0,U.current&&=(l?.(!1,``),!1);return}}if(i){let e=n.match(/@(\S*)$/);if(e&&B.current.length>0){l?.(!0,e[1]??``),U.current=!0,H.current&&=(o?.(!1,``),!1);return}}H.current&&=(o?.(!1,``),!1),U.current&&=(l?.(!1,``),!1)},[o,l]),Te=(0,Q.useCallback)(e=>{let t=e.target,n=t.value;O.current=n,de.current=-1;let r=t===se.current?ce.current:se.current;r&&(r.value=n),j(n.trim().length>0),we(n,t.selectionStart),_?.(n,N.filter(e=>e.status===`ready`&&e.serverPath).map(e=>({name:e.name,path:e.serverPath}))),W.current&&(V.current&&cancelAnimationFrame(V.current),V.current=requestAnimationFrame(()=>{V.current=0,t.style.height=`auto`,t.style.height=Math.min(t.scrollHeight,t===ce.current?80:160)+`px`}))},[we,_,N]),Ee=(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(),Y(n))},[Y]),De=(0,Q.useCallback)(e=>{e.preventDefault();let t=e.dataTransfer.getData(`application/x-ppm-path`);if(t){let e=O.current;G(e+(e.length>0&&!e.endsWith(` `)?` `:``)+`@${t} `),K()?.focus();return}let n=Array.from(e.dataTransfer.files);n.length>0&&Y(n)},[Y,G,K]),Oe=(0,Q.useCallback)(e=>{e.preventDefault()},[]),Ae=(0,Q.useCallback)(()=>{le.current?.click()},[]),Z=(0,Q.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&Y(t),e.target.value=``},[Y]),je=k||N.some(e=>e.status!==`error`)||!!P,Me=t&&!je;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=>{r||e.target instanceof HTMLTextAreaElement||K()?.focus()},children:[P&&(0,$.jsx)(`div`,{className:`px-2 md:px-4 pt-2`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-md border border-sky-500/30 bg-sky-500/10 px-2 py-1 text-xs font-medium text-sky-600 dark:text-sky-400`,children:[(0,$.jsx)(i,{className:`size-3.5 shrink-0`}),P,(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),F(null),K()?.focus()},className:`shrink-0 rounded-sm p-0.5 hover:bg-sky-500/20 transition-colors`,"aria-label":`Remove ${P} agent`,children:(0,$.jsx)(ne,{className:`size-3`})})]})}),(0,$.jsx)(sr,{attachments:N,onRemove:be}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-2 pt-2 md:hidden relative`,children:[(0,$.jsx)(Dr,{mode:b??`bypassPermissions`,onClick:()=>ae(e=>!e)}),(0,$.jsx)(pr,{value:b??`bypassPermissions`,onChange:e=>x?.(e),open:I,onOpenChange:ae}),C&&a&&(0,$.jsx)(me,{value:S??`claude`,onChange:C,projectName:a}),T&&a&&(0,$.jsx)(yr,{model:w??null,effort:E??null,thinking:D??!1,onModelChange:T,onEffortChange:ee??(()=>{}),onThinkingChange:te??(()=>{}),projectName:a,providerId:S??`claude`,disabled:t}),t&&(0,$.jsx)(kr,{value:R,onChange:z})]}),(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(),Ae()},disabled:r,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)(yt,{className:`size-4`})}),(0,$.jsx)(`textarea`,{ref:ce,defaultValue:h??``,onChange:Te,onKeyDown:Ce,onPaste:Ee,onDrop:De,onDragOver:Oe,placeholder:t?`Follow-up...`:`Ask anything...`,disabled:r,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]`}),q.supported&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ge()},disabled:r,className:`flex items-center justify-center size-8 shrink-0 rounded-[10px] transition-colors disabled:opacity-50 ${q.isListening?`bg-error text-white animate-pulse`:`text-text-3 hover:text-text-primary`}`,"aria-label":q.isListening?`Stop voice input`:`Start voice input`,children:q.isListening?(0,$.jsx)(vt,{className:`size-4`}):(0,$.jsx)(ye,{className:`size-4`})}),Me?(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},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)(ve,{className:`size-3.5`})}):(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),L?oe(!1):Se()},disabled:r||!je,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":L?`Cancel queued send`:`Send`,children:L?(0,$.jsx)(X,{className:`size-4 animate-spin`}):(0,$.jsx)(ke,{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)(Dr,{mode:b??`bypassPermissions`,onClick:()=>ae(e=>!e)}),(0,$.jsx)(pr,{value:b??`bypassPermissions`,onChange:e=>x?.(e),open:I,onOpenChange:ae})]}),C&&a&&(0,$.jsx)(me,{value:S??`claude`,onChange:C,projectName:a}),T&&a&&(0,$.jsx)(yr,{model:w??null,effort:E??null,thinking:D??!1,onModelChange:T,onEffortChange:ee??(()=>{}),onThinkingChange:te??(()=>{}),projectName:a,providerId:S??`claude`,disabled:t}),t&&(0,$.jsx)(kr,{value:R,onChange:z})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-2 px-2.5 py-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),Ae()},disabled:r,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)(yt,{className:`size-[17px]`})}),(0,$.jsx)(`textarea`,{ref:se,defaultValue:h??``,onChange:Te,onKeyDown:Ce,onPaste:Ee,onDrop:De,onDragOver:Oe,placeholder:t?`Follow-up or Stop...`:`Ask anything...`,disabled:r,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]`}),q.supported&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ge()},disabled:r,className:`flex items-center justify-center size-[34px] shrink-0 rounded-[10px] transition-colors disabled:opacity-50 ${q.isListening?`bg-error text-white animate-pulse`:`text-text-3 hover:text-text-primary hover:bg-surface-elevated`}`,"aria-label":q.isListening?`Stop voice input`:`Start voice input`,children:q.isListening?(0,$.jsx)(vt,{className:`size-[17px]`}):(0,$.jsx)(ye,{className:`size-[17px]`})}),Me?(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},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)(ve,{className:`size-4`})}):(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),L?oe(!1):Se()},disabled:r||!je,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":L?`Cancel queued send`:`Send message`,children:L?(0,$.jsx)(X,{className:`size-4 animate-spin`}):(0,$.jsx)(ke,{className:`size-[17px]`})})]})]})]}),(0,$.jsx)(`input`,{ref:le,type:`file`,multiple:!0,className:`hidden`,onChange:Z})]})});function Dr({mode:e,onClick:t}){let n=fr(e),r=dr(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 Or=[{value:`now`,label:`Interrupt`,Icon:Z},{value:`next`,label:`Queue`,Icon:_t},{value:`later`,label:`Later`,Icon:w}];function kr({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=Or.find(t=>t.value===e)??Or[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 Ar(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 jr(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=Ar(n,r.slice(0,n.length+i));return a<=i?{rank:2,distance:a}:null}function Mr(e,t,n=20,r=[]){if(!t)return e;t=t.slice(0,50);let i=new Set(r),a=[];for(let n of e){let e=[jr(t,n.name),jr(t,n.description)].filter(e=>e!==null).sort((e,t)=>e.rank-t.rank||e.distance-t.distance)[0];e&&a.push({item:n,rank:e.rank,distance:e.distance,recent:i.has(n.name)})}return a.sort((e,t)=>e.rank-t.rank||e.distance-t.distance||(e.recent===t.recent?0:e.recent?-1:1)||e.item.name.localeCompare(t.item.name)),a.slice(0,n).map(e=>e.item)}function Nr({items:e,filter:t,onSelect:n,onClose:r,visible:a,recentNames:o=[],projectName:s}){let[c,l]=(0,Q.useState)(0),[u,d]=(0,Q.useState)(!1),f=(0,Q.useRef)(null),p=(0,Q.useMemo)(()=>new Set(o),[o]),m=(0,Q.useMemo)(()=>{if(t)return{items:Mr(e,t,20,o),recentCount:0};if(o.length>0){let t=[],n=[];for(let r of e)p.has(r.name)?t.push(r):n.push(r);return t.sort((e,t)=>o.indexOf(e.name)-o.indexOf(t.name)),{items:[...t,...n],recentCount:t.length}}return{items:e,recentCount:0}},[e,t,o,p]),h=m.items,g=m.recentCount;(0,Q.useEffect)(()=>{l(0)},[t]),(0,Q.useEffect)(()=>{let e=f.current;e&&e.children[c]?.scrollIntoView({block:`nearest`})},[c]);let _=(0,Q.useCallback)(e=>{if(!a||h.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),l(e=>e>0?e-1:h.length-1),!0;case`ArrowDown`:return e.preventDefault(),l(e=>e<h.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),h[c]&&n(h[c]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[a,h,c,n,r]);(0,Q.useEffect)(()=>{if(!a)return;let e=e=>{_(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[a,_]);let v=(0,Q.useCallback)(()=>{!s||u||(d(!0),N.del(`${M(s)}/chat/slash-items/cache`).then(()=>{window.dispatchEvent(new CustomEvent(`ppm:slash-items-refresh`))}).finally(()=>d(!1)))},[s,u]);return!a||h.length===0?null:(0,$.jsx)(`div`,{className:`max-h-52 overflow-y-auto overflow-x-hidden border-b border-border bg-surface`,children:(0,$.jsx)(`div`,{ref:f,className:`py-1`,children:h.map((e,t)=>{let r=g>0&&t===0,a=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)(w,{className:`size-3`}),`Recent`]}),s&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),v()},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)(J,{className:`size-3 ${u?`animate-spin`:``}`})})]}),a&&(0,$.jsx)(`div`,{className:`px-3 pt-1.5 pb-0.5`,children:(0,$.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle uppercase tracking-wider`,children:`All`})}),(0,$.jsxs)(`button`,{className:`flex items-start gap-3 w-full px-3 py-2 text-left transition-colors ${t===c?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>l(t),onClick:()=>n(e),children:[(0,$.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`builtin`?(0,$.jsx)(Z,{className:`size-4 text-emerald-500`}):e.type===`skill`?(0,$.jsx)(ee,{className:`size-4 text-warning`}):e.type===`agent`?(0,$.jsx)(i,{className:`size-4 text-sky-500`}):(0,$.jsx)(Ce,{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.name]}),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.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 Pr({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,Q.useState)(0),s=(0,Q.useRef)(null),c=(()=>{if(!t)return e.slice(0,50);let n=t.toLowerCase();return e.filter(e=>e.path.toLowerCase().includes(n)||e.name.toLowerCase().includes(n)).slice(0,50)})();(0,Q.useEffect)(()=>{o(0)},[t]),(0,Q.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,Q.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,Q.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,$.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,$.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,$.jsxs)(`button`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,$.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,$.jsx)(nt,{className:`size-4 text-warning`}):(0,$.jsx)(Ke,{className:`size-4 text-primary`})}),(0,$.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}var Fr=`ppm-hienlh`;function Ir({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(`idle`);function E(){f(null),m(``),T(`idle`),u(null)}function ee(){t(!1),E(),i(``),o(``),u(null)}async function D(){g(!0),u(null);try{let{url:e,state:t}=await K();f(t),T(`waiting`),window.open(e,`_blank`)}catch(e){u(e.message)}g(!1)}async function te(){if(!(!p.trim()||!d)){g(!0),u(null);try{let e=p.trim();e.includes(`#`)&&(e=e.split(`#`)[0]??e),await le(e,d),ee(),n(`Account connected via OAuth!`)}catch(e){u(e.message)}g(!1)}}async function O(){if(r.trim()){c(!0),u(null);try{await G({apiKey:r.trim(),label:a.trim()||void 0}),ee(),n(`Account added!`)}catch(e){u(e.message)}c(!1)}}let k=r.trim()?r.trim().startsWith(`sk-ant-oat`)?`OAuth token (Claude Max/Pro)`:r.trim().startsWith(`sk-ant-api`)?`API key`:`Unknown format`:``;return(0,$.jsx)(C,{open:e,onOpenChange:e=>{e||ee()},children:(0,$.jsxs)(b,{className:`sm:max-w-md`,children:[(0,$.jsxs)(_,{children:[(0,$.jsx)(x,{className:`text-sm`,children:`Add Claude Account`}),(0,$.jsx)(S,{className:`text-xs leading-relaxed`,children:`Connect via OAuth (recommended) or paste a token manually.`})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,$.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Recommended: Login with Claude`}),w===`idle`?(0,$.jsx)(v,{size:`sm`,className:`w-full h-8 text-xs`,onClick:D,disabled:h,children:h?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{className:`size-3 animate-spin mr-1`}),` Opening...`]}):`Login with Claude`}):(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Authorize in the opened tab, then paste the code:`}),(0,$.jsx)(je,{placeholder:`Paste code here...`,value:p,onChange:e=>m(e.target.value),className:`text-xs h-8 font-mono`,autoFocus:!0}),(0,$.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,$.jsx)(v,{size:`sm`,className:`flex-1 h-7 text-xs`,onClick:te,disabled:!p.trim()||h,children:h?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{className:`size-3 animate-spin mr-1`}),` Connecting...`]}):`Connect`}),(0,$.jsx)(v,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:E,children:`Cancel`})]})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`flex-1 border-t`}),(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`or paste token`}),(0,$.jsx)(`div`,{className:`flex-1 border-t`})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(_e,{htmlFor:`add-token`,className:`text-xs`,children:`Token`}),(0,$.jsx)(je,{id:`add-token`,type:`password`,placeholder:`sk-ant-...`,value:r,onChange:e=>i(e.target.value),className:`text-xs h-8 font-mono`}),k&&(0,$.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Detected: `,k]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(_e,{htmlFor:`add-label`,className:`text-xs`,children:`Label (optional)`}),(0,$.jsx)(je,{id:`add-label`,placeholder:`e.g. Personal, Work`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`})]})]}),l&&(0,$.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:l}),(0,$.jsxs)(y,{children:[(0,$.jsx)(v,{size:`sm`,variant:`outline`,className:`text-xs h-7`,onClick:ee,children:`Cancel`}),(0,$.jsx)(v,{size:`sm`,className:`text-xs h-7`,onClick:O,disabled:!r.trim()||s,children:s?`Adding...`:`Add Token`})]})]})})}function Lr({open:e,onOpenChange:t,accounts:n,preselectId:r,onMessage:i}){let a=n.filter(e=>e.hasRefreshToken),[o,s]=(0,Q.useState)(new Set),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(!1),[g,w]=(0,Q.useState)(!1);e&&!g&&(s(r?new Set([r]):new Set(a.map(e=>e.id))),w(!0)),!e&&g&&w(!1);function T(){t(!1),l(``),d(!1),p(!1)}async function E(e){if(o.size===0)return;h(!0);let t=c.trim()||Fr;try{let n={"Content-Type":`application/json`},r=A();r&&(n.Authorization=`Bearer ${r}`);let a=await fetch(`/api/accounts/export`,{method:`POST`,headers:n,body:JSON.stringify({password:t,accountIds:[...o],includeRefreshToken:u,refreshBeforeExport:f})});if(!a.ok){let e=await a.json();throw Error(e.error??`Export failed: ${a.status}`)}let s=await a.text();e&&await Ze(s)?i?.(`Backup copied to clipboard!`):(zr(s),i?.(`Backup downloaded.`)),T()}catch{}h(!1)}let ee=o.size>0&&!m;return(0,$.jsx)(C,{open:e,onOpenChange:e=>{e||T()},children:(0,$.jsxs)(b,{className:`sm:max-w-md`,children:[(0,$.jsxs)(_,{children:[(0,$.jsxs)(x,{className:`text-sm flex items-center gap-1.5`,children:[(0,$.jsx)(Ie,{className:`size-3.5`}),` Export Accounts`]}),(0,$.jsx)(S,{className:`text-xs`,children:`Select accounts and set a password to protect the backup.`})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,$.jsx)(`p`,{className:`text-[11px] font-medium text-muted-foreground`,children:`Accounts to export`}),(0,$.jsx)(`button`,{className:`text-[10px] text-primary hover:underline cursor-pointer`,onClick:()=>s(o.size===a.length?new Set:new Set(a.map(e=>e.id))),children:o.size===a.length?`Deselect all`:`Select all`})]}),a.length===0?(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground p-2 border rounded`,children:`No exportable accounts.`}):(0,$.jsx)(`div`,{className:`max-h-36 overflow-y-auto space-y-1 border rounded p-2`,children:a.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,id:`exp-${e.id}`,checked:o.has(e.id),onChange:t=>{let n=new Set(o);t.target.checked?n.add(e.id):n.delete(e.id),s(n)},className:`size-3.5 accent-primary cursor-pointer`}),(0,$.jsx)(`label`,{htmlFor:`exp-${e.id}`,className:`text-xs cursor-pointer truncate`,children:e.label??e.email??e.id.slice(0,8)})]},e.id))})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(_e,{className:`text-xs`,children:[`Password `,(0,$.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,$.jsx)(je,{type:`password`,placeholder:`Leave empty for default`,value:c,onChange:e=>l(e.target.value),className:`text-xs h-8`,autoComplete:`new-password`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,id:`exp-full`,checked:u,onChange:e=>d(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,$.jsx)(`label`,{htmlFor:`exp-full`,className:`text-[11px] cursor-pointer`,children:`Include refresh tokens (full transfer)`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,id:`exp-refresh`,checked:f,onChange:e=>p(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,$.jsx)(`label`,{htmlFor:`exp-refresh`,className:`text-[11px] cursor-pointer`,children:`Refresh tokens before export`})]}),u?(0,$.jsxs)(`div`,{className:`rounded-md border border-error/30 bg-error/5 p-2.5`,children:[(0,$.jsx)(`p`,{className:`text-[10px] font-medium text-error`,children:`Full transfer — source accounts will expire`}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Refresh tokens included. Source machine expires in ~1h after target refreshes.`})]}):f?(0,$.jsx)(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 p-2.5`,children:(0,$.jsx)(`p`,{className:`text-[10px] font-medium text-warning`,children:`Refresh before export — invalidates previous shares`})}):(0,$.jsx)(`div`,{className:`rounded-md border border-success/30 bg-success/5 p-2.5`,children:(0,$.jsx)(`p`,{className:`text-[10px] font-medium text-success`,children:`Share current token (safe)`})}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Encrypted with AES-256-GCM + scrypt.`})]}),(0,$.jsxs)(y,{className:`gap-1.5 flex-col sm:flex-row`,children:[(0,$.jsx)(v,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:T,children:`Cancel`}),(0,$.jsxs)(v,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,disabled:!ee,onClick:()=>E(!0),children:[(0,$.jsx)(it,{className:`size-3 mr-1`}),` Copy`]}),(0,$.jsx)(v,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!ee,onClick:()=>E(!1),children:m?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{className:`size-3 animate-spin mr-1`}),` Exporting...`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(te,{className:`size-3 mr-1`}),` Download`]})})]})]})})}function Rr({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(null);function d(){t(!1),i(``),o(``),u(null)}async function f(){if(r.trim()){c(!0),u(null);try{let e=await B({data:r.trim(),password:a.trim()||Fr});d(),n(`Imported ${e.imported} account(s)`)}catch(e){u(e.message||`Import failed`)}c(!1)}}return(0,$.jsx)(C,{open:e,onOpenChange:e=>{e||d()},children:(0,$.jsxs)(b,{className:`sm:max-w-md`,children:[(0,$.jsxs)(_,{children:[(0,$.jsxs)(x,{className:`text-sm flex items-center gap-1.5`,children:[(0,$.jsx)(Ie,{className:`size-3.5`}),` Import Accounts`]}),(0,$.jsx)(S,{className:`text-xs`,children:`Paste backup data and enter the export password. Imported accounts are temporary (~1h).`})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(_e,{className:`text-xs`,children:`Backup data`}),(0,$.jsx)(`textarea`,{value:r,onChange:e=>i(e.target.value),placeholder:`Paste backup JSON here...`,rows:4,className:`w-full text-xs p-2 rounded border border-border bg-background font-mono resize-none focus:outline-none focus:ring-1 focus:ring-primary`})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(_e,{className:`text-xs`,children:[`Password `,(0,$.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,$.jsx)(je,{type:`password`,placeholder:`Leave empty for default`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`,autoComplete:`current-password`})]})]}),l&&(0,$.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-error/10 text-error`,children:l}),(0,$.jsxs)(y,{children:[(0,$.jsx)(v,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:d,children:`Cancel`}),(0,$.jsx)(v,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!r.trim()||s,onClick:f,children:s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{className:`size-3 animate-spin mr-1`}),` Importing...`]}):`Import`})]})]})})}function zr(e){let t=new Blob([e],{type:`application/json`}),n=document.createElement(`a`);n.href=URL.createObjectURL(t),n.download=`ppm-accounts-backup.json`,n.click(),URL.revokeObjectURL(n.href)}var Br=typeof window<`u`?window.matchMedia(`(min-width: 768px)`):null;function Vr(e){return Br?.addEventListener(`change`,e),()=>Br?.removeEventListener(`change`,e)}function Hr(){return Br?.matches??!0}function Ur(){let[e,t]=(0,Q.useState)(null),[n,r]=(0,Q.useState)(!0);return(0,Q.useEffect)(()=>{r(!0),V().then(t).finally(()=>r(!1))},[]),n?(0,$.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Loading...`}):e?(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Rotation Strategy`}),(0,$.jsxs)(Y,{value:e.strategy,onValueChange:async e=>{t(await R({strategy:e}))},children:[(0,$.jsx)(dt,{className:`w-full h-9 text-xs`,children:(0,$.jsx)(fe,{})}),(0,$.jsxs)(be,{children:[(0,$.jsx)(De,{value:`round-robin`,children:`Round-robin`}),(0,$.jsx)(De,{value:`fill-first`,children:`Fill-first`}),(0,$.jsx)(De,{value:`lowest-usage`,children:`Lowest usage`})]})]}),(0,$.jsxs)(`p`,{className:`text-[10px] text-text-subtle`,children:[e.strategy===`round-robin`&&`Cycles through accounts evenly`,e.strategy===`fill-first`&&`Uses one account until its limit, then moves on`,e.strategy===`lowest-usage`&&`Picks the account with the lowest current usage`]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Max Retry`}),(0,$.jsx)(`input`,{type:`number`,min:0,value:e.maxRetry,className:`w-full h-9 text-xs border rounded-md px-3 bg-background`,onChange:async e=>{let n=parseInt(e.target.value,10);!isNaN(n)&&n>=0&&t(await R({maxRetry:n}))}}),(0,$.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`How many accounts to try on failure. 0 = try all available accounts.`})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Cooldown parking`}),(0,$.jsx)(Me,{checked:e.cooldownEnabled,onCheckedChange:async e=>{t(await R({cooldownEnabled:e}))}})]}),(0,$.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`Park a failing account (rate limit / usage limit / auth error) until it recovers. Off: accounts stay selectable — rotation still skips accounts already ≥95% on the 5-hour limit.`})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs border-t border-border pt-3`,children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Active accounts`}),(0,$.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.activeCount})]})]}):(0,$.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Failed to load settings`})}function Wr({open:e,onOpenChange:t}){let n=(0,Q.useSyncExternalStore)(Vr,Hr);return e?n?(0,$.jsx)(C,{open:e,onOpenChange:t,children:(0,$.jsxs)(b,{className:`sm:max-w-sm`,children:[(0,$.jsx)(_,{children:(0,$.jsxs)(x,{className:`text-sm flex items-center gap-2`,children:[(0,$.jsx)(Oe,{className:`size-4`}),` Rotation & Retry`]})}),(0,$.jsx)(Ur,{})]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-50 transition-opacity duration-200 opacity-100`,onClick:()=>t(!1),style:{backgroundColor:`rgba(0,0,0,0.5)`}}),(0,$.jsxs)(`div`,{className:F(`fixed bottom-0 left-0 right-0 z-50 bg-background rounded-t-2xl border-t border-border shadow-2xl`,`transition-transform duration-300 ease-out max-h-[85vh] overflow-y-auto`,`translate-y-0`),children:[(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-border`})}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,$.jsxs)(`span`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,$.jsx)(Oe,{className:`size-4`}),` Rotation & Retry`]}),(0,$.jsx)(`button`,{onClick:()=>t(!1),className:`flex items-center justify-center size-7 rounded-md hover:bg-surface-elevated transition-colors`,children:(0,$.jsx)(ne,{className:`size-4`})})]}),(0,$.jsx)(`div`,{className:`px-4 py-4 pb-8`,children:(0,$.jsx)(Ur,{})})]})]}):null}var Gr=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],Kr=Array.from({length:24},(e,t)=>t);function qr(e,t){let n=Array.from({length:7},()=>Array.from({length:24},()=>({sum:0,count:0,avg:0})));for(let r of e){let e=t===`5h`?r.five_hour_util:r.weekly_util;if(e==null)continue;let i=new Date(r.recorded_at+(r.recorded_at.endsWith(`Z`)?``:`Z`)),a=(i.getDay()+6)%7,o=i.getHours();n[a][o].sum+=e,n[a][o].count+=1}for(let e of n)for(let t of e)t.avg=t.count>0?t.sum/t.count:0;return n}function Jr(e){return e.map(e=>{let t=e.reduce((e,t)=>e+t.sum,0),n=e.reduce((e,t)=>e+t.count,0);return n>0?t/n:0})}function Yr(e){return Kr.map(t=>{let n=0,r=0;for(let i of e)n+=i[t].sum,r+=i[t].count;return r>0?n/r:0})}function Xr(e){return e===0?`bg-surface-elevated`:e<.3?`bg-success/30`:e<.5?`bg-success/60`:e<.7?`bg-warning/50`:e<.9?`bg-warning/80`:`bg-error/80`}function Zr(e){return e<.3?`bg-success`:e<.7?`bg-warning`:`bg-error`}function Qr({accountId:e}){let[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)(!0),[a,o]=(0,Q.useState)(`5h`);(0,Q.useEffect)(()=>{i(!0),H(e).then(n).catch(()=>n([])).finally(()=>i(!1))},[e]);let s=(0,Q.useMemo)(()=>t?qr(t,a):null,[t,a]),c=(0,Q.useMemo)(()=>s?Jr(s):[],[s]),l=(0,Q.useMemo)(()=>s?Yr(s):[],[s]),u=Math.max(...c,.01);if(Math.max(...l,.01),r)return(0,$.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,$.jsx)(X,{className:`size-3 animate-spin text-text-subtle`})});if(!t||t.length===0)return(0,$.jsx)(`div`,{className:`text-[10px] text-text-subtle py-2 text-center`,children:`No usage history yet`});let d=t.length,f=new Set(t.map(e=>new Date(e.recorded_at+(e.recorded_at.endsWith(`Z`)?``:`Z`)).toDateString())).size;return(0,$.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle`,children:`Usage Pattern (7d)`}),(0,$.jsxs)(`div`,{className:`flex gap-0.5 text-[9px]`,children:[(0,$.jsx)(`button`,{onClick:()=>o(`5h`),className:`px-1.5 py-0.5 rounded cursor-pointer transition-colors ${a===`5h`?`bg-primary/15 text-primary`:`text-text-subtle hover:text-text-secondary`}`,title:`5-hour rolling window limit — resets every 5 hours`,children:`5h`}),(0,$.jsx)(`button`,{onClick:()=>o(`weekly`),className:`px-1.5 py-0.5 rounded cursor-pointer transition-colors ${a===`weekly`?`bg-primary/15 text-primary`:`text-text-subtle hover:text-text-secondary`}`,title:`Weekly limit — resets every 7 days`,children:`Wk`})]})]}),(0,$.jsxs)(`p`,{className:`text-[9px] text-text-subtle leading-tight`,children:[`Avg `,a===`5h`?`5-hour`:`weekly`,` limit usage over `,f,`d (`,d,` samples). Higher % = closer to rate limit. Hover cells for details.`]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Avg usage by day of week`}),(0,$.jsx)(`div`,{className:`flex flex-col gap-[2px] mt-0.5`,children:Gr.map((e,t)=>{let n=c[t]??0;return(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`text-[8px] text-text-subtle w-5 shrink-0 text-right tabular-nums`,children:e}),(0,$.jsx)(`div`,{className:`flex-1 h-2.5 bg-surface-elevated rounded-sm overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-full rounded-sm transition-all ${Zr(n)}`,style:{width:`${Math.round(n/u*100)}%`}})}),(0,$.jsxs)(`span`,{className:`text-[8px] text-text-subtle w-6 shrink-0 text-right tabular-nums`,children:[Math.round(n*100),`%`]})]},e)})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Avg usage by hour (0h-23h)`}),(0,$.jsx)(`div`,{className:`flex gap-[1px] mt-0.5`,children:Kr.map(e=>{let t=l[e]??0;return(0,$.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-[1px]`,children:[(0,$.jsx)(`div`,{className:`w-full aspect-square rounded-[2px] ${Xr(t)}`,title:`${e}:00 — avg ${Math.round(t*100)}% usage`}),e%6==0&&(0,$.jsx)(`span`,{className:`text-[7px] text-text-subtle tabular-nums`,children:e})]},e)})})]}),s&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`text-[9px] text-text-subtle`,children:`Day x Hour heatmap`}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-[1px] mt-0.5`,children:[Gr.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-[1px]`,children:[(0,$.jsx)(`span`,{className:`text-[7px] text-text-subtle w-4 shrink-0 text-right`,children:e.charAt(0)}),Kr.map(n=>{let r=s[t][n];return(0,$.jsx)(`div`,{className:`flex-1 aspect-square rounded-[1px] ${Xr(r.avg)}`,title:`${e} ${n}:00 — ${r.count>0?`avg ${Math.round(r.avg*100)}% (${r.count} samples)`:`no data`}`},n)})]},e)),(0,$.jsxs)(`div`,{className:`flex items-center gap-[1px]`,children:[(0,$.jsx)(`span`,{className:`w-4 shrink-0`}),Kr.map(e=>(0,$.jsx)(`div`,{className:`flex-1 text-center`,children:e%6==0&&(0,$.jsx)(`span`,{className:`text-[7px] text-text-subtle tabular-nums`,children:e})},e))]})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[8px] text-text-subtle`,children:[(0,$.jsx)(`span`,{children:`Low`}),(0,$.jsxs)(`div`,{className:`flex gap-[2px]`,children:[(0,$.jsx)(`div`,{className:`size-2 rounded-[1px] bg-success/30`}),(0,$.jsx)(`div`,{className:`size-2 rounded-[1px] bg-success/60`}),(0,$.jsx)(`div`,{className:`size-2 rounded-[1px] bg-warning/50`}),(0,$.jsx)(`div`,{className:`size-2 rounded-[1px] bg-warning/80`}),(0,$.jsx)(`div`,{className:`size-2 rounded-[1px] bg-error/80`})]}),(0,$.jsx)(`span`,{children:`High`}),(0,$.jsx)(`span`,{className:`ml-1`,children:`|`}),(0,$.jsx)(`div`,{className:`size-2 rounded-[1px] bg-surface-elevated border border-border/30`}),(0,$.jsx)(`span`,{children:`No data`})]})]})}function $r(e){return e>=90?`text-error`:e>=70?`text-warning`:`text-success`}function ei(e){return e>=90?`bg-error`:e>=70?`bg-warning`:`bg-success`}function ti(e){if(!e)return null;let t=null;if(e.resetsInMinutes!=null)t=e.resetsInMinutes;else if(e.resetsInHours!=null)t=Math.round(e.resetsInHours*60);else if(e.resetsAt){let n=new Date(e.resetsAt).getTime()-Date.now();t=n>0?Math.ceil(n/6e4):0}if(t==null)return null;if(t<=0)return`now`;let n=Math.floor(t/1440),r=Math.floor(t%1440/60),i=t%60;return n>0?i>0?`${n}d ${r}h ${i}m`:r>0?`${n}d ${r}h`:`${n}d`:r>0?i>0?`${r}h ${i}m`:`${r}h`:`${i}m`}function ni({label:e,bucket:t}){if(!t)return null;let n=Math.round(t.utilization*100),r=ti(t);return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,$.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,title:`Resets in`,children:[`↻ `,r]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-full rounded-full transition-all ${ei(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,$.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${$r(n)}`,children:[n,`%`]})]})]})}function ri(e){let t=e-Date.now();if(t<=0)return`expired`;let n=Math.ceil(t/6e4),r=Math.floor(n/60),i=Math.floor(r/24);return i>0?`${i}d ${r%24}h`:r>0?`${r}h ${n%60}m`:`${n}m`}function ii(e){if(!e)return{label:`unknown`,tip:`No account info available`,color:`text-text-subtle`};if(!e.expiresAt)return{label:`key`,tip:`API key (no expiry)`,color:`text-text-subtle`};let t=e.expiresAt*1e3<Date.now();return t&&e.hasRefreshToken?{label:`expired`,tip:`Token expired but has refresh token — will auto-renew`,color:`text-warning`}:t?{label:`expired`,tip:`Token expired, no refresh token`,color:`text-error`}:e.hasRefreshToken?{label:`long-lived`,tip:`OAuth token with refresh — long-lived`,color:`text-success`}:{label:`temp`,tip:`Temporary token without refresh — will expire`,color:`text-warning`}}function ai(e){if(!e)return null;let t=Math.round((Date.now()-e)/1e3);if(t<5)return`just now`;if(t<60)return`${t}s ago`;let n=Math.floor(t/60);if(n<60)return`${n}m ago`;let r=Math.floor(n/60),i=n%60;return r<24?i>0?`${r}h ${i}m ago`:`${r}h ago`:`${Math.floor(r/24)}d ago`}function oi({entry:e,isActive:t,accountInfo:n,onToggle:r,onDelete:i,onExport:a,onViewProfile:o,flash:s,fullscreen:c}){let{usage:l}=e,u=l.session||l.weekly||l.weeklyOpus||l.weeklySonnet,d=n?.status??e.accountStatus,f=!!(n&&!n.hasRefreshToken&&n.expiresAt&&n.expiresAt<Math.floor(Date.now()/1e3));return(0,$.jsxs)(`div`,{className:`rounded-md border p-2 transition-colors duration-500 ${c?`flex flex-col gap-1.5 overflow-hidden`:`space-y-1.5 min-w-[200px] shrink-0 snap-start`} ${f?`opacity-50`:``} ${s?`bg-primary/10 border-primary/40`:``} ${t?`border-primary/30 bg-primary/5`:`border-border/50`}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium truncate flex-1 min-w-0`,children:e.accountLabel??e.accountId.slice(0,8)}),f&&(0,$.jsx)(`span`,{className:`text-[9px] text-error shrink-0 font-medium`,children:`Expired`}),!e.isOAuth&&!f&&(0,$.jsx)(`span`,{className:`text-[9px] text-text-subtle shrink-0`,children:`API key`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[!f&&o&&n?.profileData&&(0,$.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-foreground hover:bg-surface-elevated transition-colors`,onClick:()=>o(n.profileData,e.accountId),title:`View profile`,children:(0,$.jsx)(D,{className:`size-3`})}),!f&&a&&e.isOAuth&&(0,$.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-primary hover:bg-surface-elevated transition-colors`,onClick:()=>a(e.accountId),title:`Export this account`,children:(0,$.jsx)(te,{className:`size-3`})}),!f&&r&&(0,$.jsx)(Me,{checked:d!==`disabled`,onCheckedChange:()=>r(e.accountId,d),disabled:d===`cooldown`,className:`scale-[0.6] cursor-pointer`}),i&&(0,$.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-error hover:bg-surface-elevated transition-colors`,onClick:()=>i(e.accountId,e.accountLabel??e.accountId.slice(0,8)),title:`Remove account`,children:(0,$.jsx)(qe,{className:`size-3`})})]})]}),u?(0,$.jsxs)(`div`,{className:c?`flex-1 flex flex-col justify-evenly min-h-0`:`space-y-1.5`,children:[(0,$.jsx)(ni,{label:`5-Hour Session`,bucket:l.session}),(0,$.jsx)(ni,{label:`Weekly`,bucket:l.weekly}),(0,$.jsx)(ni,{label:`Weekly (Opus)`,bucket:l.weeklyOpus}),(0,$.jsx)(ni,{label:`Weekly (Sonnet)`,bucket:l.weeklySonnet})]}):(0,$.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:e.isOAuth?`No usage data yet`:`Usage tracking not available for API keys`}),(()=>{let e=ii(n);return(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[9px] text-text-subtle flex-wrap`,children:[l.lastFetchedAt&&(0,$.jsxs)(`span`,{title:`Last usage data update`,children:[`↻ `,ai(new Date(l.lastFetchedAt).getTime())]}),n?.expiresAt&&n.expiresAt*1e3>Date.now()&&(0,$.jsxs)(`span`,{title:`Token expires in`,children:[`⏱ `,ri(n.expiresAt*1e3)]}),(0,$.jsxs)(`span`,{className:e.color,title:e.tip,children:[`© `,e.label]})]})})()]})}function si({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastFetchedAt:a}){let[o,s]=(0,Q.useState)([]),[c,l]=(0,Q.useState)([]),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(!0),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(new Set),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(!1),[E,ee]=(0,Q.useState)(!1),[D,k]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(null),[M,N]=(0,Q.useState)(!1),[re,P]=(0,Q.useState)(null),F=(0,Q.useRef)(void 0),ie=(0,Q.useRef)([]);function I(e){F.current&&clearTimeout(F.current),P(e),F.current=setTimeout(()=>P(null),4e3)}function ae(e){L(),e&&I(e)}async function L(){let e=o.length>0;e?h(!0):p(!0);let[t,n,r]=await Promise.allSettled([ue(),W(),se()]);if(t.status===`fulfilled`){let n=t.value;if(e&&ie.current.length>0){let e=new Set,t=new Map(ie.current.map(e=>[e.accountId,e]));for(let r of n){let n=t.get(r.accountId);if(!n){e.add(r.accountId);continue}let i=n.usage,a=r.usage;(i.session?.utilization!==a.session?.utilization||i.weekly?.utilization!==a.weekly?.utilization||i.weeklyOpus?.utilization!==a.weeklyOpus?.utilization||i.weeklySonnet?.utilization!==a.weeklySonnet?.utilization)&&e.add(r.accountId)}e.size>0&&(_(e),setTimeout(()=>_(new Set),1500))}ie.current=n,s(n)}n.status===`fulfilled`&&l(n.value),r.status===`fulfilled`&&d(r.value?.id??null),p(!1),h(!1)}if((0,Q.useEffect)(()=>{t&&L()},[t]),(0,Q.useEffect)(()=>{!t||!a||L()},[a]),!t)return null;let oe=new Map(c.map(e=>[e.id,e])),R=e.queryCostUsd!=null||e.totalCostUsd!=null,z=o.length>0,le=o.length||1,B=Math.ceil(Math.sqrt(le)),V=Math.ceil(le/B);async function H(e,t){await ce(e,{status:t===`disabled`?`active`:`disabled`}),L(),r?.()}async function G(){if(D){try{await U(D.id),I(`Account "${D.display}" removed.`),L(),r?.()}catch(e){I(`Failed to remove: ${e.message}`)}k(null)}}function K(){j(null),C(!0)}return(0,$.jsxs)(`div`,{className:`relative border-b border-border bg-surface px-3 py-2.5 ${M?`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:`Usage & Accounts`}),a&&(0,$.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:ai(new Date(a).getTime())})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`button`,{onClick:()=>ee(!0),className:`text-xs text-text-subtle hover:text-text-primary px-1 cursor-pointer`,title:`Rotation & retry settings`,children:(0,$.jsx)(Oe,{className:`size-3`})}),z&&(0,$.jsx)(`button`,{onClick:()=>N(e=>!e),className:`text-xs text-text-subtle hover:text-text-primary px-1 cursor-pointer`,title:M?`Exit fullscreen`:`Fullscreen view`,children:M?(0,$.jsx)(et,{className:`size-3`}):(0,$.jsx)(Fe,{className:`size-3`})}),r&&(0,$.jsx)(`button`,{onClick:()=>{r(),L()},disabled:i||m,className:`text-xs text-text-subtle hover:text-text-primary px-1 disabled:opacity-50 cursor-pointer`,title:`Refresh`,children:(0,$.jsx)(J,{className:`size-3 ${i||m?`animate-spin`:``}`})}),(0,$.jsx)(`button`,{onClick:()=>{N(!1),n()},className:`text-xs text-text-subtle hover:text-text-primary px-1 cursor-pointer`,children:(0,$.jsx)(ne,{className:`size-3`})})]})]}),re&&(0,$.jsx)(`div`,{className:`text-[11px] p-1.5 rounded bg-success/10 text-success text-center animate-in fade-in duration-200`,children:re}),z||f?(0,$.jsx)(`div`,{className:M?`flex-1 min-h-0 grid gap-2 overflow-hidden`:`flex gap-1.5 overflow-x-auto pb-1 -mx-3 px-3 snap-x snap-mandatory scrollbar-thin`,style:M?{gridTemplateColumns:`repeat(${B}, minmax(0, 1fr))`,gridTemplateRows:`repeat(${V}, minmax(0, 1fr))`}:void 0,children:f?(0,$.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`Loading...`}):o.map(t=>(0,$.jsx)(oi,{entry:t,isActive:t.accountId===(u??e.activeAccountId),accountInfo:oe.get(t.accountId),onToggle:H,onDelete:(e,t)=>k({id:e,display:t}),onExport:e=>{j(e),C(!0)},onViewProfile:(e,t)=>y({profile:e,accountId:t}),flash:g.has(t.accountId),fullscreen:M},t.accountId))}):(0,$.jsx)($.Fragment,{children:e.session||e.weekly||e.weeklyOpus||e.weeklySonnet?(0,$.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,$.jsx)(ni,{label:`5-Hour Session`,bucket:e.session}),(0,$.jsx)(ni,{label:`Weekly`,bucket:e.weekly}),(0,$.jsx)(ni,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,$.jsx)(ni,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,$.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`No usage data available`})}),R&&(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)]})]})]}),v&&(0,$.jsxs)(`div`,{className:`border-t border-border pt-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle`,children:`Profile`}),(0,$.jsx)(`button`,{className:`text-text-subtle hover:text-foreground cursor-pointer`,onClick:()=>y(null),children:(0,$.jsx)(ne,{className:`size-3`})})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-[70px_1fr] gap-x-2 gap-y-0.5 text-[10px]`,children:[v.profile.account?.display_name&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Name`}),(0,$.jsx)(`span`,{children:v.profile.account.display_name})]}),v.profile.account?.email&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Email`}),(0,$.jsx)(`span`,{children:v.profile.account.email})]}),v.profile.organization?.name&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Org`}),(0,$.jsx)(`span`,{children:v.profile.organization.name})]}),v.profile.organization?.organization_type&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Type`}),(0,$.jsx)(`span`,{children:v.profile.organization.organization_type})]}),v.profile.organization?.rate_limit_tier&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Tier`}),(0,$.jsx)(`span`,{children:v.profile.organization.rate_limit_tier})]}),v.profile.organization?.subscription_status&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Status`}),(0,$.jsx)(`span`,{children:v.profile.organization.subscription_status})]})]}),(0,$.jsx)(Qr,{accountId:v.accountId})]}),(0,$.jsxs)(`div`,{className:`border-t border-border pt-2 flex gap-1.5 shrink-0`,children:[(0,$.jsxs)(`button`,{onClick:()=>x(!0),className:`flex-1 flex items-center justify-center gap-1 rounded-md border border-border px-2 py-1 text-[11px] text-text-secondary hover:bg-surface-hover transition-colors cursor-pointer`,children:[(0,$.jsx)(O,{className:`size-3`}),` Add`]}),(0,$.jsxs)(`button`,{onClick:K,className:`flex-1 flex items-center justify-center gap-1 rounded-md border border-border px-2 py-1 text-[11px] text-text-secondary hover:bg-surface-hover transition-colors cursor-pointer`,children:[(0,$.jsx)(te,{className:`size-3`}),` Export`]}),(0,$.jsxs)(`button`,{onClick:()=>T(!0),className:`flex-1 flex items-center justify-center gap-1 rounded-md border border-border px-2 py-1 text-[11px] text-text-secondary hover:bg-surface-hover transition-colors cursor-pointer`,children:[(0,$.jsx)(we,{className:`size-3`}),` Import`]})]}),D&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/80 backdrop-blur-sm rounded-md`,children:(0,$.jsxs)(`div`,{className:`bg-surface border border-border rounded-lg shadow-lg p-4 mx-4 max-w-[280px] w-full space-y-3`,children:[(0,$.jsxs)(`p`,{className:`text-xs text-text-primary text-center`,children:[`Remove `,(0,$.jsx)(`strong`,{className:`text-foreground`,children:D.display}),`?`]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`button`,{onClick:()=>k(null),className:`flex-1 px-3 py-1.5 rounded-md text-xs border border-border text-text-secondary hover:bg-surface-hover cursor-pointer transition-colors`,children:`Cancel`}),(0,$.jsx)(`button`,{onClick:G,className:`flex-1 px-3 py-1.5 rounded-md text-xs bg-error text-white hover:bg-error/80 cursor-pointer transition-colors`,children:`Remove`})]})]})}),(0,$.jsx)(Ir,{open:b,onOpenChange:x,onSuccess:ae}),(0,$.jsx)(Lr,{open:S,onOpenChange:e=>{C(e),e||j(null)},accounts:c,preselectId:A,onMessage:I}),(0,$.jsx)(Rr,{open:w,onOpenChange:T,onSuccess:ae}),(0,$.jsx)(Wr,{open:E,onOpenChange:ee})]})}function ci(e){return e>=90?`text-error`:e>=70?`text-warning`:`text-success`}function li(e){return e>=90?`bg-error`:e>=70?`bg-warning`:`bg-success`}function ui({label:e,frac:t}){let n=t==null?null:Math.round(t*100);return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),(0,$.jsx)(`span`,{className:`text-xs font-medium tabular-nums ${n==null?`text-text-subtle`:ci(n)}`,children:n==null?`—`:`${n}%`})]}),(0,$.jsx)(`div`,{className:`h-2 rounded-full bg-border overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-full rounded-full transition-all ${n==null?``:li(n)}`,style:{width:`${Math.min(n??0,100)}%`}})})]})}function di({onClose:e,usage:t}){let[n,r]=(0,Q.useState)([]),[i,a]=(0,Q.useState)({}),[o,s]=(0,Q.useState)(!1),c=(0,Q.useCallback)(async()=>{s(!0);try{r((await N.get(`/api/codex-accounts`)).accounts),a(await N.get(`/api/codex-accounts/usage`))}catch{}finally{s(!1)}},[]);return(0,Q.useEffect)(()=>{c()},[c]),(0,$.jsxs)(`div`,{className:`border-t border-border bg-surface px-3 py-2.5 space-y-2.5 max-h-[350px] overflow-y-auto`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Codex Usage`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`button`,{onClick:c,disabled:o,className:`text-text-subtle hover:text-text-primary px-1 cursor-pointer disabled:opacity-50`,title:`Refresh`,children:(0,$.jsx)(J,{className:`size-3 ${o?`animate-spin`:``}`})}),(0,$.jsx)(`button`,{onClick:e,className:`text-text-subtle hover:text-text-primary px-1 cursor-pointer`,title:`Close`,children:(0,$.jsx)(ne,{className:`size-3`})})]})]}),o&&n.length===0&&(0,$.jsxs)(`div`,{className:`text-xs text-text-subtle flex items-center gap-2`,children:[(0,$.jsx)(X,{className:`size-3 animate-spin`}),` Loading…`]}),!o&&n.length===0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`rounded-md border border-border/50 bg-surface/40 p-2.5 space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm text-text-primary truncate flex-1 min-w-0`,children:t.activeAccountLabel||`Default login`}),(0,$.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-text-subtle border border-border rounded px-1`,children:`~/.codex`})]}),(0,$.jsx)(ui,{label:`5-Hour`,frac:t.fiveHour}),(0,$.jsx)(ui,{label:`Weekly`,frac:t.sevenDay})]}),(0,$.jsxs)(`p`,{className:`text-[11px] text-text-subtle`,children:[`Using your default `,(0,$.jsx)(`code`,{children:`~/.codex`}),` login. Add managed accounts in Settings → AI Provider → Codex.`]})]}),n.map(e=>{let t=i[e.id]??{};return(0,$.jsxs)(`div`,{className:`rounded-md border border-border/50 bg-surface/40 p-2.5 space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm text-text-primary truncate flex-1 min-w-0`,children:e.label}),(0,$.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-text-subtle border border-border rounded px-1`,children:e.type}),e.planType&&(0,$.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:e.planType})]}),(0,$.jsx)(ui,{label:`5-Hour`,frac:t.fiveHour}),(0,$.jsx)(ui,{label:`Weekly`,frac:t.sevenDay})]},e.id)})]})}var fi={active:`bg-success`,idle:`bg-warning`,shutdown:`bg-text-3`},pi={task_assignment:{label:`task`,className:`bg-primary/20 text-primary`},idle_notification:{label:`idle`,className:`bg-warning/20 text-warning`},completion:{label:`done`,className:`bg-success/20 text-success`},shutdown_request:{label:`shutdown`,className:`bg-error/20 text-error`},shutdown_approved:{label:`shutdown ✓`,className:`bg-text-3/20 text-text-3`}};function mi({teamNames:e,messages:t}){let[n,r]=(0,Q.useState)(e[0]??``),[i,a]=(0,Q.useState)([]),[o,s]=(0,Q.useState)(!1),c=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{e.length>0&&!e.includes(n)&&r(e[0])},[e,n]);let l=(0,Q.useCallback)(async e=>{s(!0);try{a((await N.get(`/api/teams/${encodeURIComponent(e)}`))?.members??[])}catch{a([])}s(!1)},[]);(0,Q.useEffect)(()=>{n&&l(n)},[n,l]),(0,Q.useEffect)(()=>{c.current?.scrollIntoView({behavior:`smooth`})},[t.length]);let u=t.slice(-200);return(0,$.jsxs)(`div`,{className:`space-y-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 mb-2`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1 overflow-x-auto min-w-0 flex-1`,children:e.map(e=>(0,$.jsx)(`button`,{onClick:()=>r(e),className:F(`px-2 py-0.5 text-[11px] rounded-md whitespace-nowrap transition-colors`,n===e?`bg-primary/10 text-primary font-medium`:`text-text-subtle hover:text-text-primary`),children:e},e))}),(0,$.jsx)(`button`,{onClick:()=>n&&l(n),className:`text-text-subtle hover:text-foreground p-1 shrink-0`,"aria-label":`Refresh`,children:(0,$.jsx)(J,{className:F(`size-3`,o&&`animate-spin`)})})]}),i.length>0&&(0,$.jsxs)(`div`,{className:`pb-2 mb-2 border-b border-border/30`,children:[(0,$.jsx)(`div`,{className:`text-[10px] text-text-subtle uppercase tracking-wider mb-1`,children:`Members`}),(0,$.jsx)(`div`,{className:`space-y-1`,children:i.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,$.jsx)(`span`,{className:F(`size-1.5 rounded-full shrink-0`,fi[e.status]??`bg-text-3`)}),(0,$.jsx)(`span`,{className:`font-medium truncate`,children:e.name}),e.model&&e.model!==`unknown`&&(0,$.jsxs)(`span`,{className:`text-text-subtle text-[10px]`,children:[`(`,e.model,`)`]}),(0,$.jsx)(`span`,{className:`ml-auto text-text-subtle text-[10px]`,children:e.status})]},e.name))})]}),(0,$.jsx)(`div`,{className:`max-h-40 overflow-y-auto`,children:u.length===0?(0,$.jsx)(`p`,{className:`text-xs text-text-subtle text-center py-2`,children:`No messages yet`}):(0,$.jsxs)(`div`,{className:`space-y-2`,children:[u.map((e,t)=>{let n=e.parsedType?pi[e.parsedType]:null,r=hi(e.timestamp);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:gi(e.color),children:e.from}),(0,$.jsx)(`span`,{children:`→`}),(0,$.jsx)(`span`,{children:e.to}),(0,$.jsx)(`span`,{className:`ml-auto text-[10px]`,children:r})]}),(0,$.jsxs)(`div`,{className:`mt-0.5 text-foreground/90 break-words`,children:[n&&(0,$.jsx)(`span`,{className:F(`inline-block px-1 py-0 rounded text-[9px] mr-1`,n.className),children:n.label}),e.summary??_i(e.text)]})]},`${e.timestamp}-${t}`)}),(0,$.jsx)(`div`,{ref:c})]})})]})}function hi(e){try{return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}catch{return``}}function gi(e){if(e&&(/^#[0-9a-fA-F]{3,8}$/.test(e)||/^[a-zA-Z]{3,20}$/.test(e)))return{color:e}}function _i(e,t=120){if(!e)return``;try{let n=JSON.parse(e);return n.summary??n.text??e.slice(0,t)}catch{}return e.length>t?e.slice(0,t)+`...`:e}function vi(e){return e>=90?`text-error`:e>=70?`text-warning`:`text-success`}function yi(){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}var bi=e=>`${(e/1048576).toFixed(2)} MB`;function xi({sessionId:e,projectName:t}){let[n,r]=(0,Q.useState)(!1),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(!1),l=u(),d=()=>{r(!0),s(!1),a(null),N.get(`${M(t)}/chat/sessions/${e}/debug?project=${encodeURIComponent(t)}`).then(e=>{let t=e.jsonlSizeBytes==null?``:` (${bi(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,...yi()].filter(Boolean).join(`
|
|
8
|
+
`))}).catch(()=>a(`Failed to load debug info`))},f=(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)(ze,{className:`size-4 text-primary`}),`Session debug info`]}),(0,$.jsx)(`pre`,{className:`max-h-[50vh] 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)(v,{size:`sm`,onClick:()=>{i&&Ze(i).then(e=>{e&&(s(!0),setTimeout(()=>s(!1),1500))})},disabled:!i,className:`w-full`,children:o?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ht,{className:`size-3.5`}),` Copied!`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(it,{className:`size-3.5`}),` Copy`]})})]});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:d,className:`p-1 rounded text-text-subtle hover:text-text-secondary hover:bg-surface-elevated transition-colors`,title:`Session debug info`,children:(0,$.jsx)(ze,{className:`size-3`})}),l?(0,$.jsx)(c,{open:n,onClose:()=>r(!1),className:`popover-solid`,children:(0,$.jsx)(`div`,{className:`px-4 pb-4 pt-1`,children:f})}):(0,$.jsx)(C,{open:n,onOpenChange:r,children:(0,$.jsxs)(b,{className:`sm:max-w-lg`,children:[(0,$.jsx)(x,{className:`sr-only`,children:`Session debug info`}),f]})})]})}function Si({projectName:e,usageInfo:t,usageLoading:n,refreshUsage:r,lastFetchedAt:a,sessionId:c,providerId:l,onSelectSession:u,onBugReport:d,isConnected:f,onReload:p,teamActivity:m,teamMessages:h,onTeamOpen:g}){let[_,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)([]),[x,S]=(0,Q.useState)(!1),C=Ae(e=>e.notifications),w=Ae(e=>c?e.notifications.has(c):!1),T=Ae(e=>e.clearForSession),ee=Ae(e=>e.markUnread),[D,te]=(0,Q.useState)(``),O=q(D,300),[k,A]=(0,Q.useState)(null),[j,re]=(0,Q.useState)(``),[P,ie]=(0,Q.useState)(!1),[I,ae]=(0,Q.useState)(!1),[L,R]=(0,Q.useState)([]),[z,se]=(0,Q.useState)(null),[ce,le]=(0,Q.useState)({}),[ue,B]=(0,Q.useState)(!1),V=(0,Q.useRef)(null),H=oe(e=>e.openTab),U=e=>{v(t=>t===e?null:e)},W=(0,Q.useCallback)(async t=>{if(e){S(!0);try{let n=new URLSearchParams({limit:`50`,offset:`0`});t&&n.set(`q`,t);let r=await N.get(`${M(e)}/chat/sessions?${n}`);b(r.sessions),ie(r.hasMore)}catch{}finally{S(!1)}}},[e]),G=(0,Q.useCallback)(async()=>{if(!(!e||I||!P)){ae(!0);try{let t=y.filter(e=>!e.pinned).length,n=new URLSearchParams({limit:`50`,offset:String(t)});O&&n.set(`q`,O);let r=await N.get(`${M(e)}/chat/sessions?${n}`);b(e=>{let t=new Set(e.map(e=>e.id)),n=r.sessions.filter(e=>!t.has(e.id));return[...e,...n]}),ie(r.hasMore)}catch{}finally{ae(!1)}}},[e,I,P,y,O]);(0,Q.useEffect)(()=>{_===`history`&&y.length===0&&W()},[_]),(0,Q.useEffect)(()=>{_===`history`&&W(O||void 0)},[O]);let K=(0,Q.useCallback)(async()=>{if(e)try{let t=await N.get(`${M(e)}/tags`);R(t.tags),le(t.counts)}catch{}},[e]);(0,Q.useEffect)(()=>{_===`history`&&e&&K()},[_,e,K]);function de(t){u?(u(t),v(null)):H({type:`chat`,title:t.title||`Chat`,projectId:e??null,metadata:{projectName:e,sessionId:t.id,providerId:t.providerId},closable:!0})}let fe=(0,Q.useCallback)((e,t)=>{t.stopPropagation(),A(e.id),re(e.title||``),setTimeout(()=>V.current?.select(),0)},[]),me=(0,Q.useCallback)(async()=>{if(!k||!j.trim()||!e){A(null);return}try{await N.patch(`${M(e)}/chat/sessions/${k}`,{title:j.trim()}),b(e=>e.map(e=>e.id===k?{...e,title:j.trim()}:e))}catch{}A(null)},[k,j,e]),he=(0,Q.useCallback)(()=>A(null),[]),_e=(0,Q.useCallback)(async(t,n)=>{if(t.stopPropagation(),!e)return;let r=`${M(e)}/chat/sessions/${n.id}/pin`;try{n.pinned?await N.del(r):await N.put(r),b(e=>e.map(e=>e.id===n.id?{...e,pinned:!e.pinned}:e).sort((e,t)=>e.pinned&&!t.pinned?-1:!e.pinned&&t.pinned?1:new Date(t.createdAt).getTime()-new Date(e.createdAt).getTime()))}catch{}},[e]),Y=(0,Q.useCallback)(async(t,n)=>{if(t.stopPropagation(),e&&window.confirm(`Delete this session? This cannot be undone.`))try{await N.del(`${M(e)}/chat/sessions/${n.id}?providerId=${n.providerId}`),b(e=>e.filter(e=>e.id!==n.id))}catch{}},[e]),ve=(0,Q.useCallback)((e,t)=>{b(n=>n.map(n=>n.id===e?{...n,tag:t}:n)),K()},[K]),ye=(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.`)){S(!0);try{await N.del(`${M(e)}/chat/sessions?olderThanDays=${n}`),W(O||void 0)}catch{}}},[e,W,O]);(0,Q.useEffect)(()=>{if(_!==`history`)return;let t=t=>{if(t.target instanceof HTMLInputElement||t.target instanceof HTMLTextAreaElement)return;let n=parseInt(t.key);if(n>=1&&n<=L.length&&c){let t=L[n-1];t&&(N.patch(`${M(e)}/chat/sessions/${c}/tag`,{tagId:t.id}).catch(()=>{}),ve(c,{id:t.id,name:t.name,color:t.color}))}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[_,L,c,e,ve]);let be=z===null?y:y.filter(e=>e.tag?.id===z),xe=!l||l===`claude`,Ce=l===`codex`,we=t.fiveHour==null?null:Math.round(t.fiveHour*100),De=t.sevenDay==null?null:Math.round(t.sevenDay*100),Oe=we!=null||De!=null?vi(Math.max(we??0,De??0)):`text-text-subtle`;return(0,$.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsxs)(`button`,{onClick:()=>U(`history`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${_===`history`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,children:[(0,$.jsx)(Be,{className:`size-3`}),(0,$.jsx)(`span`,{children:`History`})]}),c&&l&&l!==`mock`?(0,$.jsxs)(`button`,{onClick:()=>U(`config`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${_===`config`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,title:`AI Settings`,children:[(0,$.jsx)(Te,{providerId:l}),(0,$.jsx)(`span`,{className:`capitalize`,children:l})]}):(0,$.jsx)(`button`,{onClick:()=>U(`config`),className:`p-1 rounded transition-colors ${_===`config`?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary hover:bg-surface-elevated`}`,title:`AI Settings`,children:(0,$.jsx)(ft,{className:`size-3`})}),xe||Ce?(0,$.jsxs)(`button`,{onClick:()=>U(`usage`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] font-medium tabular-nums transition-colors hover:bg-surface-elevated ${_===`usage`?`bg-primary/10`:``} ${Oe}`,title:`Usage limits`,children:[(0,$.jsx)(pt,{className:`size-3`}),t.activeAccountLabel&&(0,$.jsxs)(`span`,{className:`text-text-secondary font-normal truncate max-w-[60px]`,children:[`[`,t.activeAccountLabel,`]`]}),(0,$.jsxs)(`span`,{children:[`5h:`,we==null?`--%`:`${we}%`]}),(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,$.jsxs)(`span`,{children:[`Wk:`,De==null?`--%`:`${De}%`]})]}):null,m?.hasTeams&&(0,$.jsxs)(`button`,{onClick:()=>{U(`team`),g?.()},className:`relative flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${_===`team`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,title:`Team activity`,children:[(0,$.jsx)(pe,{className:`size-3`}),(0,$.jsx)(`span`,{children:`Team`}),(m.unreadCount??0)>0&&(0,$.jsx)(`span`,{className:`absolute -top-0.5 -right-0.5 size-2 bg-primary rounded-full animate-pulse`})]}),(0,$.jsx)(`div`,{className:`flex-1`}),w&&c&&(0,$.jsx)(`button`,{onClick:()=>T(c),className:`p-1 rounded text-warning hover:text-warning/80 hover:bg-surface-elevated transition-colors`,title:`Mark as read`,children:(0,$.jsx)(lt,{className:`size-3`})}),!w&&c&&(0,$.jsx)(`button`,{onClick:()=>ee(c,e),className:`p-1 rounded text-primary hover:text-primary/80 hover:bg-surface-elevated transition-colors`,title:`Mark as unread`,children:(0,$.jsx)($e,{className:`size-3 fill-current`})}),c&&(0,$.jsx)(xi,{sessionId:c,projectName:e}),p&&(0,$.jsxs)(`button`,{onClick:e=>{let t=e.currentTarget.querySelector(`svg`);t&&(t.classList.add(`animate-spin`),setTimeout(()=>t.classList.remove(`animate-spin`),600)),p()},className:`relative size-4 flex items-center justify-center`,title:f?`Reload messages`:`Disconnected — click to reload`,children:[(0,$.jsx)(J,{className:`size-3 ${f?`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 ${f?`bg-success`:`bg-error animate-pulse`}`})]})]}),_===`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)(E,{className:`size-3 text-text-subtle shrink-0`}),(0,$.jsx)(`input`,{type:`text`,value:D,onChange:e=>te(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:ye,className:`p-0.5 rounded text-text-subtle hover:text-error transition-colors`,title:`Delete old sessions...`,children:(0,$.jsx)(ut,{className:`size-3`})}),(0,$.jsx)(`button`,{onClick:()=>W(O||void 0),disabled:x,className:`p-0.5 rounded text-text-subtle hover:text-text-secondary transition-colors disabled:opacity-50`,title:`Refresh`,children:(0,$.jsx)(J,{className:`size-3 ${x?`animate-spin`:``}`})})]}),L.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:()=>se(null),className:`shrink-0 rounded-md border px-2 py-1 text-[10px] transition-colors ${z===null?`bg-primary/20 border-primary text-primary`:`border-border bg-surface text-text-secondary`}`,children:[`All (`,y.length,`)`]}),L.map(e=>(0,$.jsxs)(`button`,{onClick:()=>se(z===e.id?null:e.id),className:`shrink-0 flex items-center gap-1 rounded-md border px-2 py-1 text-[10px] transition-colors ${z===e.id?`border-current`:`border-border bg-surface`}`,style:z===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,` (`,ce[e.id]??0,`)`]},e.id)),(0,$.jsx)(`button`,{onClick:()=>B(!ue),className:`shrink-0 p-1 rounded transition-colors ${ue?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary`}`,title:`Manage tags`,children:(0,$.jsx)(Ee,{className:`size-3`})})]}),ue&&(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)(st,{projectName:e,onTagsChanged:K})}),(0,$.jsx)(`div`,{className:`max-h-[200px] overflow-y-auto`,children:x&&y.length===0?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,$.jsx)(X,{className:`size-3.5 animate-spin text-text-subtle`})}):be.length===0?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-3 text-[11px] text-text-subtle`,children:D?`No matching sessions`:`No sessions yet`}):(0,$.jsxs)($.Fragment,{children:[be.map(t=>{let n=C.get(t.id),r=!!n;return(0,$.jsx)(Ue,{session:t,projectName:e,projectTags:L,onTogglePin:_e,onStartEditing:fe,onDeleteSession:Y,onTagChanged:ve,children:(0,$.jsxs)(`div`,{className:F(`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&&ot(n.type),!r&&`text-text-secondary`),children:[(0,$.jsx)(Te,{providerId:t.providerId}),t.tag&&(0,$.jsx)(`span`,{className:`size-2 rounded-full shrink-0`,style:{backgroundColor:t.tag.color},title:t.tag.name}),k===t.id?(0,$.jsxs)(`form`,{className:`flex items-center gap-1 flex-1 min-w-0`,onSubmit:e=>{e.preventDefault(),me()},children:[(0,$.jsx)(`input`,{ref:V,value:j,onChange:e=>re(e.target.value),onBlur:me,onKeyDown:e=>{e.key===`Escape`&&he()},className:`flex-1 min-w-0 bg-surface-elevated text-[11px] text-text-primary px-1 py-0.5 rounded border border-border outline-none focus:border-primary`,autoFocus:!0}),(0,$.jsx)(`button`,{type:`submit`,className:`p-0.5 text-success hover:text-success/80`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(o,{className:`size-3`})}),(0,$.jsx)(`button`,{type:`button`,className:`p-0.5 text-text-subtle hover:text-text-secondary`,onClick:e=>{e.stopPropagation(),he()},children:(0,$.jsx)(ne,{className:`size-3`})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{onClick:()=>de(t),className:`text-[11px] truncate flex-1 text-left flex items-center gap-1`,children:[t.title?.startsWith(`[PPM]`)&&(0,$.jsx)(i,{className:`size-3 text-muted-foreground shrink-0`}),t.title?.startsWith(`[PPM]`)?t.title.slice(7):t.title||`Untitled`]}),(0,$.jsx)(`button`,{onClick:e=>_e(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)(ge,{className:`size-3`}):(0,$.jsx)(Pe,{className:`size-3`})}),(0,$.jsx)(`button`,{onClick:e=>fe(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)(s,{className:`size-3`})}),(0,$.jsx)(`button`,{onClick:e=>Y(e,t),className:`p-0.5 rounded text-text-subtle hover:text-error hover:bg-error/20 can-hover:opacity-0 can-hover:group-hover:opacity-100 transition-opacity`,title:`Delete session`,children:(0,$.jsx)(qe,{className:`size-3`})})]}),k!==t.id&&t.updatedAt&&(0,$.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0 w-16 text-right`,children:ct(t.updatedAt)})]})},t.id)}),P&&(0,$.jsxs)(`button`,{onClick:G,disabled:I,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:[I?(0,$.jsx)(X,{className:`size-3 animate-spin`}):null,I?`Loading...`:`Load more`]})]})})]}),_===`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)(Se,{compact:!0})}),_===`team`&&m?.hasTeams&&(0,$.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2 max-h-[280px] overflow-y-auto`,children:(0,$.jsx)(mi,{teamNames:m.teamNames,messages:h??[]})}),_===`usage`&&xe&&(0,$.jsx)(si,{usage:t,visible:!0,onClose:()=>v(null),onReload:r,loading:n,lastFetchedAt:a}),_===`usage`&&Ce&&(0,$.jsx)(di,{usage:t,onClose:()=>v(null)})]})}function Ci(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;return a(!0),N.get(`${M(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(()=>{t||a(!1)}),()=>{t=!0}},[e,c]);let l=(0,Q.useCallback)((t,n)=>{e&&(o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{let r=s.current??`__new__`;N.put(`${M(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__`;N.del(`${M(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 wi({metadata:e,tabId:t}){let[n,r]=(0,Q.useState)(e?.sessionId??null),[i,a]=(0,Q.useState)(e?.providerId??`claude`),[o,s]=(0,Q.useState)([]),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)([]),[g,_]=(0,Q.useState)([]),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(``),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(e?.permissionMode??void 0),E=(0,Q.useRef)(null),[ee,D]=(0,Q.useState)(!1),[te,O]=(0,Q.useState)(null),[k,A]=(0,Q.useState)(null),[F,ie]=(0,Q.useState)(null),I=(0,Q.useRef)(0),L=e?.projectName??``,R=oe(e=>e.updateTab),se=P(e=>e.version),{usageInfo:ce,usageLoading:le,lastFetchedAt:ue,refreshUsage:B}=Lt(L,i),{draft:V,draftLoading:H,saveDraft:U,clearDraft:W}=Ci(L,n);(0,Q.useEffect)(()=>{w||z().then(e=>{let t=e.providers[e.default_provider??`claude`];T(t?.permission_mode??`bypassPermissions`)}).catch(()=>{})},[]),(0,Q.useEffect)(()=>{!t||!n||R(t,{metadata:{...e,sessionId:n,providerId:i,permissionMode:w}})},[n,i,w]);let{messages:G,renderedMessages:K,expandCompact:de,isCompactExpanded:fe,dismissMessage:q,clearErrors:pe,messagesLoading:me,versionMap:he,isStreaming:ge,phase:_e,isReconnecting:J,connectingElapsed:Y,pendingApproval:ve,contextWindowPct:ye,compactStatus:be,statusMessage:xe,sessionTitle:Se,model:Ce,setModel:Te,effort:Ee,setEffort:De,thinking:Oe,setThinking:ke,sendMessage:Z,respondToApproval:je,cancelStreaming:Me,reconnect:Ne,refetchMessages:Pe,isConnected:Fe,teamActivity:Ie,teamMessages:Le,markTeamRead:Re,bashPartialOutput:ze,backgroundShells:Be,killBackgroundShell:He}=Ft(n,i,L);(0,Q.useEffect)(()=>{if(Fe&&E.current){let{content:e,permissionMode:t}=E.current;E.current=null,Z(e,{permissionMode:t})}},[Fe,Z]),(0,Q.useEffect)(()=>{if(!n||!t)return;let e=()=>{if(document.hidden)return;let{panels:e}=ae.getState();Object.values(e).some(e=>e.activeTabId===t)&&(Ae.getState().notifications.get(n)?.manual||Ae.getState().clearForSession(n))};e(),document.addEventListener(`visibilitychange`,e);let r=ae.subscribe(e),i=Ae.subscribe(e);return()=>{document.removeEventListener(`visibilitychange`,e),r(),i()}},[n,t]),(0,Q.useEffect)(()=>{t&&Se&&R(t,{title:Se})},[Se]);let[Ue,We]=(0,Q.useState)(e?.pendingMessage),[Ge,Ke]=(0,Q.useState)(null),[qe,Je]=(0,Q.useState)(!1),[Ye,Xe]=(0,Q.useState)(0),[Ze,Qe]=(0,Q.useState)(!1),$e=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{$e.current&&!me&&Qe(!1),$e.current=!!me},[me]);let[et,tt]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{H||tt(!0)},[H]),(0,Q.useEffect)(()=>{Ue&&Fe&&n&&t&&R(t,{metadata:{...e,pendingMessage:void 0}})},[Fe,n]),(0,Q.useEffect)(()=>{qe&&ge&&Je(!1)},[qe,ge]),(0,Q.useEffect)(()=>{if(!qe)return;let e=setTimeout(()=>Je(!1),6e4);return()=>clearTimeout(e)},[qe]),(0,Q.useCallback)(()=>{oe.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:L,providerId:i},projectId:L||null,closable:!0})},[L,i]);let nt=(0,Q.useCallback)(e=>{Je(!1),r(e.id),a(e.providerId),t&&R(t,{title:e.title||`Chat`}),Ae.getState().clearForSession(e.id)},[t,R]),rt=(0,Q.useCallback)(async(e,t)=>{if(!(!n||!L))try{let{api:r,projectUrl:a}=await re(async()=>{let{api:e,projectUrl:t}=await import(`./api-client-DNTkryX1.js`);return{api:e,projectUrl:t}},__vite__mapDeps([29,3,2,4,19])),o=await r.post(`${a(L)}/chat/sessions/${n}/fork?providerId=${i}`,{messageId:t});oe.getState().openTab({type:`chat`,title:`Fork: ${e.slice(0,30)}`,metadata:{projectName:L,sessionId:o.id,providerId:i,pendingMessage:e},projectId:L||null,closable:!0})}catch(e){console.error(`Fork failed:`,e);let t=e?.message||`Unknown error`;j.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,L,i]),it=(0,Q.useCallback)((e,t,n)=>{We(e),Ke({anchorMsgId:t,ownMsgId:n})},[]),at=(0,Q.useCallback)(()=>{Ke(null),We(void 0),Je(!1),W(),Xe(e=>e+1)},[W]),ot=(0,Q.useCallback)(async(a,o)=>{if(!(!a.trim()||!n||!L)){Je(!0);try{let s=await N.post(`${M(L)}/chat/sessions/${n}/fork?providerId=${i}&mode=edit`,{messageId:o});E.current={content:a,permissionMode:w},Qe(!0),t&&R(t,{metadata:{...e,sessionId:s.id}}),r(s.id)}catch(e){Je(!1);let t=e?.message||`Unknown error`;j.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,L,i,w,t,R,e]),st=(0,Q.useCallback)(i=>{!i||i===n||(Je(!1),Qe(!0),t&&R(t,{metadata:{...e,sessionId:i}}),r(i))},[n,t,R,e]),ct=(0,Q.useCallback)((e,t)=>{if(t.length===0)return e;let n=[];for(let e of t)e.textContent&&n.push(e.textContent);let r=t.filter(e=>e.serverPath);if(r.length>0){let e=r.map(e=>e.serverPath).join(`
|
|
9
|
+
`);n.push(r.length===1?`[Attached file: ${e}]`:`[Attached files:\n${e}\n]`)}return n.length===0?e:n.join(`
|
|
10
|
+
|
|
11
|
+
`)+`
|
|
12
|
+
|
|
13
|
+
`+e},[]),lt=(0,Q.useCallback)(async(e,t=[],o)=>{let s=ct(e,t);if(s.trim()){if(!n)try{let t=L,n=await N.post(`${M(t)}/chat/sessions`,{providerId:i,title:e.slice(0,50)});r(n.id),a(n.providerId),E.current={content:s,permissionMode:w};return}catch(e){console.error(`Failed to create session:`,e);return}Z(s,{permissionMode:w,priority:o})}},[n,i,L,Z,ct,w]),ut=(0,Q.useCallback)((e,t,r)=>{if(We(void 0),W(),Ge&&n&&L){let n=Ge.anchorMsgId;Ke(null),ot(ct(e,t),n);return}lt(e,t,r)},[lt,W,Ge,n,L,ot,ct]),dt=(0,Q.useRef)(G);dt.current=G;let ft=(0,Q.useCallback)(()=>dt.current.filter(e=>e.role===`user`&&e.content.trim()).map(e=>e.content),[]),pt=(0,Q.useCallback)((e,t)=>{U(e,t)},[U]),mt=(0,Q.useCallback)((e,t)=>{s(e),t&&h(t)},[]),ht=(0,Q.useCallback)((e,t)=>{l(e),d(t)},[]),gt=(0,Q.useCallback)(e=>{p(e),l(!1),d(``),setTimeout(()=>p(null),50),L&&(N.post(`${M(L)}/chat/slash-recents`,{name:e.name,type:e.type}).catch(()=>{}),h(t=>[e.name,...t.filter(t=>t!==e.name)].slice(0,5)))},[L]),_t=(0,Q.useCallback)(()=>{l(!1),d(``)},[]),vt=(0,Q.useCallback)(()=>A(null),[]),yt=(0,Q.useCallback)(e=>{ie(e)},[]),bt=(0,Q.useCallback)(e=>{A([e.path]),ie(null)},[]),xt=(0,Q.useCallback)((e,t)=>{y(e),x(t)},[]),St=(0,Q.useCallback)(e=>{C(e),y(!1),x(``),setTimeout(()=>C(null),50)},[]),Ct=(0,Q.useCallback)(()=>{y(!1),x(``)},[]);return(0,$.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,Q.useCallback)(e=>{e.preventDefault(),I.current++,(e.dataTransfer.types.includes(`application/x-ppm-path`)||e.dataTransfer.types.includes(`Files`))&&D(!0)},[]),onDragLeave:(0,Q.useCallback)(e=>{e.preventDefault(),I.current--,I.current===0&&D(!1)},[]),onDragOver:(0,Q.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,Q.useCallback)(e=>{e.preventDefault(),I.current=0,D(!1);let t=e.dataTransfer.getData(`application/x-ppm-path`);if(t){A([t]);return}let n=Array.from(e.dataTransfer.files);n.length>0&&(O(n),setTimeout(()=>O(null),100))},[]),children:[ee&&(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)(we,{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)(X,{className:`size-4 animate-spin`}),(0,$.jsx)(`span`,{children:`Reconnecting...`})]})}),qe&&(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)(X,{className:`size-4 animate-spin`}),(0,$.jsx)(`span`,{children:`Creating edited version…`})]})}),(0,$.jsx)(nr,{shells:Be,onKill:He}),(0,$.jsx)(On,{messages:K,onExpandCompact:de,isCompactExpanded:fe,messagesLoading:me,keepStaleWhileLoading:Ze,pendingApproval:ve,onApprovalResponse:je,isStreaming:ge,phase:_e,connectingElapsed:Y,statusMessage:xe,compactStatus:be,projectName:L,onFork:ge?void 0:rt,onEdit:ge?void 0:it,editingMsgId:Ge?.ownMsgId,sessionId:n??void 0,providerId:i,onNavigateVersion:st,versionMap:he,onSelectSession:nt,onDismissMessage:q,onClearErrors:pe,bashPartialOutput:ze}),(0,$.jsxs)(`div`,{className:`border-t border-border bg-panel shrink-0`,children:[(0,$.jsx)(Si,{projectName:L,usageInfo:ce,usageLoading:le,refreshUsage:B,lastFetchedAt:ue,sessionId:n,providerId:i,onSelectSession:nt,onBugReport:n?()=>Ve(se,{sessionId:n,projectName:L}):void 0,isConnected:Fe,onReload:()=>{Fe||Ne(),Pe()},teamActivity:Ie,teamMessages:Le,onTeamOpen:Re}),(0,$.jsx)(Nr,{items:o,filter:u,onSelect:gt,onClose:_t,visible:c,recentNames:m,projectName:L}),(0,$.jsx)(Pr,{items:g,filter:b,onSelect:St,onClose:Ct,visible:v}),F&&(0,$.jsx)(Pr,{items:F,filter:``,onSelect:bt,onClose:()=>ie(null),visible:!0}),Ge&&(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:at,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)(ne,{className:`h-3.5 w-3.5`}),`Cancel`]})]}),(et||!H)&&(0,$.jsx)(Er,{onSend:ut,isStreaming:ge,onCancel:Me,autoFocus:!e?.sessionId||!!Ue,initialValue:Ue??V?.content,clearSignal:Ye,projectName:L,onSlashStateChange:ht,onSlashItemsLoaded:mt,slashSelected:f,onFileStateChange:xt,onFileItemsLoaded:_,fileSelected:S,externalFiles:te,externalPaths:k,onExternalPathsConsumed:vt,onDisambiguate:yt,onContentChange:pt,getUserHistory:ft,permissionMode:w,onModeChange:T,providerId:i,onProviderChange:n?void 0:a,model:Ce,onModelChange:Te,effort:Ee,onEffortChange:De,thinking:Oe,onThinkingChange:ke})]})]})}export{wi as ChatTab};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-zRn368SN.js","assets/vendor-mermaid-CYOBtZtD.js","assets/rolldown-runtime-FhOqtrmT.js","assets/vendor-ui-DMRGWRuc.js","assets/vendor-markdown-CKTlmXbz.js","assets/markdown-renderer-TCeFZDxj.js","assets/index-Cp6hb7uj.js","assets/dialog-HHdNInEH.js","assets/utils-E0yyGxXt.js","assets/createLucideIcon-ConhwJnb.js","assets/x-BsFLg-T8.js","assets/eye-off-Rq1n2-oe.js","assets/bot-E9mcVZnr.js","assets/mobile-bottom-sheet-BwPBKZON.js","assets/chevron-right-DeUue2aK.js","assets/use-is-mobile-CE6AamG6.js","assets/sparkles-B3DmG8PJ.js","assets/database-COYAMZaw.js","assets/plus-DcuJuDC3.js","assets/api-client-DhXpjLdi.js","assets/react-8hrD3-kv.js","assets/api-settings-BUYvGBdi.js","assets/project-store-C1jInVih.js","assets/panel-store-DsDZX8Mi.js","assets/settings-store-UwT_fNhg.js","assets/tab-store-ByORqglW.js","assets/apply-theme-BSJDABU3.js","assets/resolve-theme-B9Mgd5GG.js","assets/index-DCJ29LBG.css","assets/csv-preview-D32vaKWU.js","assets/lib-CvYn0SaB.js","assets/csv-parser-BOlh-1bz.js","assets/image-preview-Dxvk6fiw.js","assets/file-exclamation-point-DBEC-Kst.js","assets/use-blob-url-BMZ0zo_4.js","assets/pdf-preview-Bx_RsWdB.js","assets/video-preview-TGDSUs0J.js","assets/audio-preview-BfaIfDsY.js","assets/docx-preview-B1kTBbEc.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,y as n}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t as r}from"./createLucideIcon-ConhwJnb.js";import{t as i}from"./chevron-right-DeUue2aK.js";import{a,c as o,i as s,n as c,o as l,t as u}from"./dialog-HHdNInEH.js";import{t as d}from"./code-TekEnDFM.js";import{t as f}from"./database-COYAMZaw.js";import{n as p,r as m}from"./plus-DcuJuDC3.js";import{t as ee}from"./file-exclamation-point-DBEC-Kst.js";import{a as h,i as te,r as ne,t as g}from"./glide-data-grid-DM0v58AP.js";import{t as re}from"./shield-check-C3qYSU8a.js";import{t as ie}from"./shield-off-D5tU7gQT.js";import{t as _}from"./table-Di8pv2Y_.js";import{t as v}from"./x-BsFLg-T8.js";import{r as ae,t as y}from"./api-client-DhXpjLdi.js";import{q as b}from"./vendor-mermaid-CYOBtZtD.js";import{t as oe}from"./settings-store-UwT_fNhg.js";import{t as x}from"./utils-E0yyGxXt.js";import{t as se}from"./panel-store-DsDZX8Mi.js";import{i as S}from"./project-store-C1jInVih.js";import{t as C}from"./tab-store-ByORqglW.js";import{$ as ce,A as le,Ht as w,J as T,Mt as E,Q as ue,Qt as D,U as de,Ut as fe,X as O,Y as k,Z as A,an as j,cn as pe,et as M,fn as me,in as he,j as ge,kt as _e,ln as ve,mt as N,o as ye,on as be,rn as xe,rt as Se,sn as P,tn as F,tt as I}from"./index-Cp6hb7uj.js";import"./data-grid-types-BuMHLKXV.js";import{t as Ce}from"./use-monaco-theme-CZKIw2ZG.js";var we=r(`redo-2`,[[`path`,{d:`m15 14 5-5-5-5`,key:`12vg1m`}],[`path`,{d:`M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13`,key:`6uklza`}]]),L=e(t(),1),R=n();function Te(e){let t=e.startsWith(`/`),n=e.split(/[/\\]/).filter(Boolean),r=e=>{let r=(t?`/`:``)+n.slice(0,e+1).join(`/`);return/^[A-Za-z]:$/.test(r)?r+`/`:r},i=t?`/`:(n[0]??``)+`/`;return n.map((e,t)=>({name:e,absPath:r(t),parentDir:t>0?r(t-1):i}))}async function Ee(e){return(await y.get(`/api/fs/browse?path=${encodeURIComponent(e)}`)).entries}function De({filePath:e,projectName:t,tabId:n,className:r}){let{updateTab:a,openTab:o}=C(T(e=>({updateTab:e.updateTab,openTab:e.openTab}))),s=(0,L.useRef)(null),c=(0,L.useMemo)(()=>Te(e),[e]);(0,L.useEffect)(()=>{s.current&&(s.current.scrollLeft=s.current.scrollWidth)},[c]);let l=(0,L.useCallback)((e,r)=>{let i=x(e),s={filePath:e,projectName:t};r.metaKey||r.ctrlKey?o({type:`editor`,title:i,metadata:s,projectId:t,closable:!0}):a(n,{title:i,metadata:s})},[t,n,o,a]);return(0,R.jsx)(`div`,{ref:s,className:r,children:c.map((e,t)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,R.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,R.jsx)(Oe,{segment:e,isLast:t===c.length-1,onFileClick:l})]},e.absPath))})}function Oe({segment:e,isLast:t,onFileClick:n}){let[r,i]=(0,L.useState)(null),[a,o]=(0,L.useState)(null);function s(t){t&&r===null&&Ee(e.parentDir).then(i).catch(e=>{o(e.message||`Failed to browse`),i([])})}return(0,R.jsxs)(k,{onOpenChange:s,children:[(0,R.jsx)(I,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,className:`text-xs px-1 py-0.5 rounded hover:bg-muted transition-colors truncate max-w-[120px] ${t?`text-foreground font-medium`:`text-muted-foreground`}`,children:e.name})}),(0,R.jsx)(O,{align:`start`,className:`max-h-[300px] overflow-y-auto p-1`,children:r===null?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-destructive`,children:a}):r.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):r.map(t=>(0,R.jsx)(ke,{entry:t,activePath:e.absPath,onFileClick:n},t.path))})]})}function ke({entry:e,activePath:t,onFileClick:n}){let r=z(e.name,e.type===`directory`),i=e.path===t,[a,o]=(0,L.useState)(null);if(e.type===`directory`){function s(t){t&&a===null&&Ee(e.path).then(o).catch(()=>o([]))}return(0,R.jsxs)(ue,{onOpenChange:s,children:[(0,R.jsxs)(M,{className:`text-xs gap-1.5 ${i?`bg-muted`:``}`,children:[(0,R.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,R.jsx)(ce,{className:`max-h-[300px] overflow-y-auto p-1`,children:a===null?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):a.map(e=>(0,R.jsx)(ke,{entry:e,activePath:t,onFileClick:n},e.path))})]})}return(0,R.jsxs)(A,{className:`text-xs gap-1.5 cursor-pointer ${i?`bg-muted`:``}`,onClick:t=>n(e.path,t),children:[(0,R.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]})}var Ae={ts:P,tsx:P,js:P,jsx:P,py:P,rs:P,go:P,html:P,css:P,scss:P,json:pe,md:be,txt:be,yaml:j,yml:j};function z(e,t){return t?xe:Ae[e.split(`.`).pop()?.toLowerCase()??``]??he}function B(e,t){let n=[],r=e,i=``;for(let e=0;e<t.length;e++){let a=t[e],o=t.slice(0,e+1).join(`/`),s=r.find(e=>e.name===a);if(n.push({name:a,fullPath:o,node:s??null,siblings:r,parentPath:i}),s?.children)i=s.path,r=s.children;else{for(let r=e+1;r<t.length;r++)n.push({name:t[r],fullPath:t.slice(0,r+1).join(`/`),node:null,siblings:[],parentPath:t.slice(0,r).join(`/`)});break}}return n}function je(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function Me({filePath:e,projectName:t,tabId:n,className:r}){let a=N(e=>e.tree),{updateTab:o,openTab:s}=C(T(e=>({updateTab:e.updateTab,openTab:e.openTab}))),c=S(e=>e.projects.find(e=>e.name===t)?.path??``),l=(0,L.useRef)(null),{prefixParts:u,relativePath:d,isExternal:f}=(0,L.useMemo)(()=>{let t=e.startsWith(`/`)?e.slice(1):e,n=c.startsWith(`/`)?c.slice(1):c;if(n&&t.startsWith(n+`/`)){let e=t.slice(n.length+1);return{prefixParts:n.split(`/`),relativePath:e,isExternal:!1}}return{prefixParts:[],relativePath:t,isExternal:/^(\/|[A-Za-z]:[/\\])/.test(e)}},[e,c]),p=(0,L.useMemo)(()=>B(a,d.split(`/`).filter(Boolean)),[a,d]);(0,L.useEffect)(()=>{l.current&&(l.current.scrollLeft=l.current.scrollWidth)},[p]);function m(e,r){let i=x(e);r.metaKey||r.ctrlKey?s({type:`editor`,title:i,metadata:{filePath:e,projectName:t},projectId:t,closable:!0}):o(n,{title:i,metadata:{filePath:e,projectName:t}})}return f?(0,R.jsx)(De,{filePath:e,projectName:t,tabId:n,className:r}):(0,R.jsxs)(`div`,{ref:l,className:r,children:[u.map((e,t)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,R.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e})]},`prefix-${t}`)),p.map((e,n)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[(n>0||u.length>0)&&(0,R.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,R.jsx)(V,{segment:e,isLast:n===p.length-1,projectName:t,onFileClick:m})]},e.fullPath))]})}function V({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=N(e=>e.loadChildren),a=N(e=>e.loadedPaths),o=(0,L.useMemo)(()=>je(e.siblings),[e.siblings]),s=a.has(e.parentPath);function c(t){if(t&&!s){let t=e.parentPath.split(`/`).filter(Boolean);(async()=>{for(let e=0;e<=t.length;e++)await i(n,t.slice(0,e).join(`/`))})()}}return(0,R.jsxs)(k,{onOpenChange:c,children:[(0,R.jsx)(I,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,className:`text-xs px-1 py-0.5 rounded hover:bg-muted transition-colors truncate max-w-[120px] ${t?`text-foreground font-medium`:`text-muted-foreground`}`,children:e.name})}),(0,R.jsx)(O,{align:`start`,className:`max-h-[300px] p-1`,children:o.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):o.map(t=>(0,R.jsx)(H,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function H({node:e,projectName:t,activePath:n,onFileClick:r}){let i=z(e.name,e.type===`directory`),a=e.path===n,o=N(e=>e.loadChildren),s=N(e=>e.loadedPaths);if(e.type===`directory`){let c=e.children??[],l=s.has(e.path);function u(n){n&&!l&&o(t,e.path)}return(0,R.jsxs)(ue,{onOpenChange:u,children:[(0,R.jsxs)(M,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,R.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,R.jsx)(ce,{className:`max-h-[300px] overflow-y-auto p-1`,children:c.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):je(c).map(e=>(0,R.jsx)(H,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]})}return(0,R.jsxs)(A,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{r(e.path,t)},children:[(0,R.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]})}function U({active:e,onClick:t,icon:n,label:r}){return(0,R.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,R.jsx)(n,{className:`size-3`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function Ne({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:i,wordWrap:a,onToggleWordWrap:o,onRefresh:s,refreshing:c,filePath:l,projectName:u,className:f}){return(0,R.jsxs)(`div`,{className:f,children:[(e===`md`||e===`mdx`)&&n&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(U,{active:t===`edit`,onClick:()=>n(`edit`),icon:d,label:`Edit`}),(0,R.jsx)(U,{active:t===`preview`,onClick:()=>n(`preview`),icon:p,label:`Preview`})]}),e===`csv`&&i&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(U,{active:r===`table`,onClick:()=>i(`table`),icon:_,label:`Table`}),(0,R.jsx)(U,{active:r===`raw`,onClick:()=>i(`raw`),icon:d,label:`Raw`})]}),(0,R.jsx)(U,{active:a,onClick:o,icon:E,label:`Wrap`}),s&&(0,R.jsxs)(`button`,{type:`button`,onClick:s,disabled:c,title:`Reload file from disk`,className:`flex items-center gap-1 px-2 py-1 rounded text-xs text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,children:[(0,R.jsx)(w,{className:`size-3 ${c?`animate-spin`:``}`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:`Refresh`})]}),l&&u&&(0,R.jsx)(U,{active:!1,onClick:()=>Se(u,l),icon:m,label:`Download`})]})}var Pe=[{id:`plaintext`,label:`Plain Text`},{id:`javascript`,label:`JavaScript`},{id:`typescript`,label:`TypeScript`},{id:`sql`,label:`SQL`},{id:`json`,label:`JSON`},{id:`xml`,label:`XML`},{id:`html`,label:`HTML`},{id:`css`,label:`CSS`},{id:`python`,label:`Python`},{id:`markdown`,label:`Markdown`},{id:`yaml`,label:`YAML`},{id:`shell`,label:`Shell`}];function Fe({value:e,onChange:t}){return(0,R.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1 px-2 border-l border-border`,children:[(0,R.jsx)(P,{className:`size-3 text-muted-foreground`}),(0,R.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-5 text-[10px] bg-transparent border border-border rounded px-1 text-foreground outline-none max-w-[120px]`,title:`Select editor language`,children:Pe.map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.label},e.id))})]})}function Ie({open:e,defaultName:t,content:n,onSave:r,onCancel:i}){let[d,f]=(0,L.useState)(t),[p,m]=(0,L.useState)(!1),[ee,h]=(0,L.useState)(``),te=S(e=>e.activeProject),ne=(0,L.useCallback)(()=>{let e=d.trim();if(!e){h(`Filename cannot be empty`);return}if(/[/\\]/.test(e)){h(`Filename cannot contain / or \\`);return}h(``),m(!0)},[d]),g=(0,L.useCallback)(e=>{let t=e.includes(`\\`)?`\\`:`/`;r(e.endsWith(t)?`${e}${d.trim()}`:`${e}${t}${d.trim()}`,n)},[d,n,r]);return p?(0,R.jsx)(ge,{open:!0,mode:`folder`,root:te?.path,title:`Save "${d.trim()}" to...`,onSelect:g,onCancel:()=>m(!1)}):(0,R.jsx)(u,{open:e,onOpenChange:e=>{e||i()},children:(0,R.jsxs)(c,{className:`sm:max-w-md`,children:[(0,R.jsx)(a,{children:(0,R.jsx)(l,{children:`Save As`})}),(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,R.jsx)(`label`,{className:`text-sm text-muted-foreground`,children:`Filename`}),(0,R.jsx)(de,{value:d,onChange:e=>{f(e.target.value),h(``)},onKeyDown:e=>{e.key===`Enter`&&ne()},placeholder:`e.g. my-file.ts`,autoFocus:!0}),ee&&(0,R.jsx)(`p`,{className:`text-xs text-destructive`,children:ee})]}),(0,R.jsxs)(s,{children:[(0,R.jsx)(o,{variant:`outline`,onClick:i,children:`Cancel`}),(0,R.jsx)(o,{onClick:ne,children:`Choose Folder...`})]})]})})}var W=typeof window<`u`&&window.isSecureContext,G=[`(`,`)`,`{`,`}`,`[`,`]`,`<`,`>`,`;`,`:`,`=`,`"`,`'`,"`",`/`,`\\`,`_`,`#`],K=`px-2 py-1.5 rounded text-xs min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,Le=`px-3 py-1.5 rounded text-xs font-mono min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,q=`w-px h-5 bg-border mx-0.5 shrink-0`;function Re({editorRef:e,readOnly:t}){let n=(0,L.useCallback)(()=>e.current,[e]),r=(0,L.useCallback)(e=>{let t=n();if(!t)return;t.focus();let r=t.getSelection();r&&t.executeEdits(`mobile-toolbar`,[{range:r,text:e}])},[n]),[i,a]=(0,L.useState)(!1),o=(0,L.useRef)(null),s=(0,L.useCallback)(async()=>{try{let e=await navigator.clipboard.readText();e&&r(e)}catch{}},[r]),c=(0,L.useCallback)(()=>{a(!0),requestAnimationFrame(()=>o.current?.focus())},[]),l=(0,L.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData(`text/plain`);t&&(a(!1),r(t))},[r]),u=(0,L.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`undo`,null))},[n]),d=(0,L.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`redo`,null))},[n]),f=(0,L.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`tab`,null))},[n]);return t?null:(0,R.jsxs)(`div`,{className:`shrink-0 border-t border-border bg-surface`,children:[!W&&i&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 border-b border-border bg-muted/50`,children:[(0,R.jsx)(`textarea`,{ref:o,onPaste:l,placeholder:`Long-press here → Paste`,className:`flex-1 h-8 rounded border border-border bg-background text-foreground text-xs px-2 py-1.5 resize-none focus:outline-none focus:ring-1 focus:ring-primary`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`p-1.5 rounded text-muted-foreground active:bg-muted transition-colors`,children:(0,R.jsx)(v,{size:14})})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1.5 overflow-x-auto`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:W?s:c,className:K,title:`Paste`,children:(0,R.jsx)(me,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:u,className:K,title:`Undo`,children:(0,R.jsx)(_e,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:d,className:K,title:`Redo`,children:(0,R.jsx)(we,{size:14})}),(0,R.jsx)(`div`,{className:q}),(0,R.jsx)(`button`,{type:`button`,onClick:f,className:Le,children:`Tab`}),(0,R.jsx)(`div`,{className:q}),G.map(e=>(0,R.jsx)(`button`,{type:`button`,onClick:()=>r(e),className:Le,children:e},e))]})]})}var J=(0,L.lazy)(()=>b(()=>import(`./markdown-renderer-zRn368SN.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28]))),ze=(0,L.lazy)(()=>b(()=>import(`./csv-preview-D32vaKWU.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([29,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,30,31]))),Be=(0,L.lazy)(()=>b(()=>import(`./image-preview-Dxvk6fiw.js`).then(e=>({default:e.ImagePreview})),__vite__mapDeps([32,6,2,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,33,34]))),Ve=(0,L.lazy)(()=>b(()=>import(`./pdf-preview-Bx_RsWdB.js`).then(e=>({default:e.PdfPreview})),__vite__mapDeps([35,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,33]))),He=(0,L.lazy)(()=>b(()=>import(`./video-preview-TGDSUs0J.js`).then(e=>({default:e.VideoPreview})),__vite__mapDeps([36,6,2,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,33,34]))),Ue=(0,L.lazy)(()=>b(()=>import(`./audio-preview-BfaIfDsY.js`).then(e=>({default:e.AudioPreview})),__vite__mapDeps([37,6,2,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,33,34]))),We=(0,L.lazy)(()=>b(()=>import(`./docx-preview-B1kTBbEc.js`).then(e=>({default:e.DocxPreview})),__vite__mapDeps([38,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,33]))),Ge=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Ke=new Set([`mp4`,`webm`,`mov`,`ogg`,`avi`,`mkv`]),qe=new Set([`mp3`,`wav`,`flac`,`aac`,`m4a`,`wma`]),Je=new Set([`db`,`sqlite`,`sqlite3`]);function Ye(e){return e.split(`.`).pop()?.toLowerCase()??``}function Xe(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`,sql:`sql`}[Ye(e)]??`plaintext`}var Ze=(0,L.memo)(function({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,i=e?.inlineContent,a=e?.inlineLanguage,[o,s]=(0,L.useState)(i??null),[c,l]=(0,L.useState)(`utf-8`),[u,d]=(0,L.useState)(!0),[p,m]=(0,L.useState)(null),[g,_]=(0,L.useState)(!1),v=(0,L.useRef)(null),b=(0,L.useRef)(``),S=(0,L.useRef)(null),{tabs:ce,updateTab:w}=C(T(e=>({tabs:e.tabs,updateTab:e.updateTab}))),{wordWrap:E,toggleWordWrap:ue}=oe(T(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),de=Ce(),O=e?.isUntitled===!0,k=e?.unsavedContent,[A,j]=(0,L.useState)(!1),pe=ce.find(e=>e.id===t),M=n?Ye(n):``,me=Ge.has(M),he=M===`pdf`,ge=M===`docx`,_e=Ke.has(M),ve=qe.has(M),N=Je.has(M),be=M===`md`||M===`mdx`,xe=M===`csv`,Se=e?.language,P=a??Se??Xe(n??``),F=P===`sql`,[I,we]=(0,L.useState)(`preview`),[Te,Ee]=(0,L.useState)(`table`),{connections:De,cachedTables:Oe,refreshTables:ke,updateConnection:Ae}=le(),z=n?`ppm:sql-conn:${n}`:t?`ppm:sql-conn:tab:${t}`:null,[B,je]=(0,L.useState)(()=>{if(!z)return null;let e=localStorage.getItem(z);return e?Number(e):null}),V=(0,L.useRef)(null),H=(0,L.useRef)(null),U=(0,L.useMemo)(()=>De.find(e=>e.id===B)??null,[De,B]),Pe=i!=null&&(a===`json`||a===`xml`),[W,G]=(0,L.useState)(!1),K=(0,L.useCallback)(()=>{if(i)if(W)s(i),G(!1);else{let e=i.trimStart();if(a===`json`)try{s(JSON.stringify(JSON.parse(e),null,2)),G(!0)}catch{}else if(a===`xml`){let t=0;s(e.replace(/(>)(<)(\/*)/g,`$1
|
|
3
|
+
$2$3`).split(`
|
|
4
|
+
`).map(e=>{let n=e.trim();n.startsWith(`</`)&&(t=Math.max(0,t-1));let r=` `.repeat(t)+n;return n.startsWith(`<`)&&!n.startsWith(`</`)&&!n.endsWith(`/>`)&&!n.includes(`</`)&&t++,r}).join(`
|
|
5
|
+
`)),G(!0)}}},[i,a,W]),Le=(0,L.useCallback)(e=>{je(e),z&&localStorage.setItem(z,String(e)),ke(e).catch(()=>{})},[z,ke]),q=(0,L.useCallback)(n=>{t&&w(t,{metadata:{...e,language:n}})},[t,e,w]),J=(0,L.useMemo)(()=>{if(!F||!B)return;let e=(Oe.get(B)??[]).map(e=>({name:e.tableName,schema:e.schemaName}));if(e.length!==0)return{tables:e,getColumns:async(e,t)=>y.get(`/api/db/connections/${B}/schema?table=${encodeURIComponent(e)}${t?`&schema=${encodeURIComponent(t)}`:``}`)}},[F,B,Oe]);(0,L.useEffect)(()=>{if(!(!V.current||!J))return H.current?.dispose(),ne(),H.current=V.current.languages.registerCompletionItemProvider(`sql`,te(V.current,J)),()=>{H.current?.dispose()}},[J]);let Ze=C(e=>e.openTab),[Y,et]=(0,L.useState)(null),[tt,nt]=(0,L.useState)(null),[rt,it]=(0,L.useState)(!1),[at,ot]=(0,L.useState)(``),st=(0,L.useCallback)(async e=>{if(U){it(!0),nt(null),ot(e);try{et(await y.post(`/api/db/connections/${U.id}/query`,{sql:e}))}catch(e){nt(e.message),et(null)}finally{it(!1)}}},[U]),ct=(0,L.useCallback)(()=>{!U||!at||Ze({type:`database`,title:`${U.name} · Query`,projectId:null,closable:!0,metadata:{connectionId:U.id,connectionName:U.name,dbType:U.type,initialSql:at}})},[U,Ze,at]),lt=(0,L.useCallback)(()=>{if(!S.current||!U)return;let e=S.current,t=e.getSelection();st(t&&!t.isEmpty()?e.getModel()?.getValueInRange(t)??e.getValue():e.getValue())},[U,st]),ut=typeof window<`u`&&`ontouchstart`in window,dt=(0,L.useRef)(null),[ft,pt]=(0,L.useState)(null);(0,L.useEffect)(()=>{if(!ut)return;let e=window.visualViewport;if(!e)return;let t=()=>{let t=dt.current;if(!t)return;let n=t.getBoundingClientRect().top;pt(e.height-Math.max(0,n))};return e.addEventListener(`resize`,t),e.addEventListener(`scroll`,t),()=>{e.removeEventListener(`resize`,t),e.removeEventListener(`scroll`,t)}},[ut]);let Z=(0,L.useRef)([]),mt=(0,L.useRef)(st);mt.current=st,(0,L.useEffect)(()=>()=>{Z.current.forEach(e=>e.dispose()),Z.current=[]},[]),(0,L.useEffect)(()=>{N&&t&&w(t,{type:`sqlite`})},[N,t,w]);let Q=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,L.useEffect)(()=>{if(i!=null){d(!1);return}if(O){s(k??``),b.current=k??``,d(!1),k&&_(!0);return}if(!n||!Q&&!r)return;if(me||he||ge||_e||ve){d(!1);return}d(!0),m(null);let e=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${ae(r)}/files/read?path=${encodeURIComponent(n)}`;return y.get(e).then(e=>{s(e.content),e.encoding&&l(e.encoding),b.current=e.content,d(!1)}).catch(e=>{m(e instanceof Error?e.message:`Failed to load file`),d(!1)}),()=>{v.current&&clearTimeout(v.current)}},[n,r,me,he,ge,Q,O]);let[ht,gt]=(0,L.useState)(!1),_t=(0,L.useCallback)(()=>{if(!n||i!=null||O||!Q&&!r)return;let e=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${ae(r)}/files/read?path=${encodeURIComponent(n)}`;gt(!0),y.get(e).then(e=>{s(e.content),b.current=e.content,e.encoding&&l(e.encoding),_(!1),m(null)}).catch(e=>m(e instanceof Error?e.message:`Failed to reload file`)).finally(()=>gt(!1))},[n,r,Q,i,O]),vt=(0,L.useRef)(g);vt.current=g,(0,L.useEffect)(()=>{if(!n||!r||i!=null||O)return;let e=e=>{let t=e.detail;if(t.projectName!==r||t.path!==n||vt.current)return;let i=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${ae(r)}/files/read?path=${encodeURIComponent(n)}`;y.get(i).then(e=>{e.content!==b.current&&(s(e.content),b.current=e.content,e.encoding&&l(e.encoding))}).catch(()=>{})};return window.addEventListener(`file:changed`,e),()=>window.removeEventListener(`file:changed`,e)},[n,r,Q,i,O]),(0,L.useEffect)(()=>{if(!pe||i!=null)return;let t=O?`Untitled-${e?.untitledNumber??1}`:n?x(n):`Untitled`,r=g?`${t} \u25CF`:t;pe.title!==r&&w(pe.id,{title:r})},[g]);let yt=(0,L.useCallback)(async e=>{if(n&&!(!Q&&!r))try{Q?await y.put(`/api/fs/write`,{path:n,content:e}):await y.put(`${ae(r)}/files/write`,{path:n,content:e}),_(!1)}catch{}},[n,r,Q]);function bt(n){let r=n??``;s(r),b.current=r,_(!0),v.current&&clearTimeout(v.current),O?v.current=setTimeout(()=>{t&&w(t,{metadata:{...e,unsavedContent:b.current}})},2e3):v.current=setTimeout(()=>yt(b.current),1e3)}let xt=(0,L.useCallback)(async(e,n)=>{try{if(v.current&&clearTimeout(v.current),await y.put(`/api/fs/write`,{path:e,content:n}),t){let{closeTab:n,openTab:r}=se.getState();n(t),r({type:`editor`,title:x(e),projectId:null,metadata:{filePath:e},closable:!0})}_(!1),j(!1)}catch{}},[t]),$=e?.lineNumber,St=e?.endLine,Ct=e?.revealAt,wt=(0,L.useCallback)(()=>{let e=S.current;if(!(!e||!$||$<=0)){if(e.revealLineInCenter($),e.setPosition({lineNumber:$,column:1}),St&&St>=$){let t=e.getModel(),n=t?.getLineCount()??$,r=Math.min(St,n),i=t?.getLineMaxColumn(r)??1;e.setSelection({startLineNumber:$,startColumn:1,endLineNumber:r,endColumn:i})}e.focus()}},[$,St]);(0,L.useEffect)(()=>{Ct!=null&&wt()},[Ct,wt]);let Tt=(0,L.useCallback)((e,t)=>{if(S.current=e,V.current=t,$&&$>0&&setTimeout(()=>wt(),100),O&&e.addCommand(t.KeyMod.CtrlCmd|t.KeyCode.KeyS,()=>j(!0)),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>oe.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),J&&(H.current?.dispose(),H.current=t.languages.registerCompletionItemProvider(`sql`,te(t,J))),F){e.addAction({id:`run-sql-at-cursor`,label:`Run Statement at Cursor`,keybindings:[t.KeyMod.CtrlCmd|t.KeyCode.Enter],run:e=>{let t=e.getPosition();if(!t)return;let n=h(e.getValue(),t.lineNumber);n&&mt.current(n)}}),Z.current.forEach(e=>e.dispose()),Z.current=[];let n=e.getModel(),r=e.addCommand(0,(e,t)=>{t&&mt.current(t)});if(r&&n){let e=t.languages.registerCodeLensProvider(`sql`,{provideCodeLenses:e=>{if(e!==n)return{lenses:[],dispose:()=>{}};let t=[],i=e.getValue().split(`
|
|
6
|
+
`),a=-1,o=[],s=!1,c=/^(BEGIN|COMMIT|ROLLBACK|END)(;|\s|$)/i,l=-1,u=[],d=(e,n,i=`▷ Run`)=>{let a=n.trim();!a||a.startsWith(`--`)||t.push({range:{startLineNumber:e,startColumn:1,endLineNumber:e,endColumn:1},command:{id:r,title:i,arguments:[a]}})};for(let e=0;e<i.length;e++){let t=i[e].trim();if(a===-1){if(!t||t.startsWith(`--`))continue;a=e+1,o=[]}if(o.push(i[e]),(t.match(/\$\$/g)||[]).length%2==1&&(s=!s),!s&&t.endsWith(`;`)){let e=o.join(`
|
|
7
|
+
`).trim(),t=/^BEGIN(;|\s|$)/i.test(e),n=/^(COMMIT|ROLLBACK|END)(;|\s|$)/i.test(e);l===-1&&t?(l=a,u=[e]):l>-1?(u.push(e),!n&&!c.test(e)&&d(a,e),n&&(d(l,u.join(`
|
|
8
|
+
`),`▷ Run Transaction`),l=-1,u=[])):d(a,e),a=-1,o=[]}}return l>-1&&u.length>1&&d(l,u.join(`
|
|
9
|
+
`),`▷ Run Transaction`),a>0&&o.join(``).trim()&&d(a,o.join(`
|
|
10
|
+
`)),{lenses:t,dispose:()=>{}}}});Z.current.push(e);let i=t.languages.registerFoldingRangeProvider(`sql`,{provideFoldingRanges:e=>{if(e!==n)return[];let r=[],i=e.getLineCount(),a=[];for(let n=1;n<=i;n++){let i=e.getLineContent(n).trim();if(/^BEGIN(;|\s|$)/i.test(i))a.push(n);else if(/^(COMMIT|ROLLBACK|END)(;|\s|$)/i.test(i)&&a.length>0){let e=a.pop();r.push({start:e,end:n,kind:t.languages.FoldingRangeKind.Region})}}return r}});Z.current.push(i)}}},[J,F]);if(!i&&!O&&(!n||!Q&&!r))return(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`});if(u)return(0,R.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,R.jsx)(D,{className:`size-5 animate-spin`}),(0,R.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]});if(p)return(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:p});if(me)return(0,R.jsx)(L.Suspense,{fallback:(0,R.jsx)(X,{}),children:(0,R.jsx)(Be,{filePath:n,projectName:r})});if(he)return(0,R.jsx)(L.Suspense,{fallback:(0,R.jsx)(X,{}),children:(0,R.jsx)(Ve,{filePath:n,projectName:r})});if(ge)return(0,R.jsx)(L.Suspense,{fallback:(0,R.jsx)(X,{}),children:(0,R.jsx)(We,{filePath:n,projectName:r})});if(_e)return(0,R.jsx)(L.Suspense,{fallback:(0,R.jsx)(X,{}),children:(0,R.jsx)(He,{filePath:n,projectName:r})});if(ve)return(0,R.jsx)(L.Suspense,{fallback:(0,R.jsx)(X,{}),children:(0,R.jsx)(Ue,{filePath:n,projectName:r})});if(c===`base64`)return(0,R.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,R.jsx)(ee,{className:`size-10 text-text-subtle`}),(0,R.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,R.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]});let Et=F?(0,R.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1 px-2 border-l border-border`,children:[(0,R.jsx)(f,{className:`size-3 text-muted-foreground`}),(0,R.jsxs)(`select`,{value:B??``,onChange:e=>{let t=Number(e.target.value);t&&Le(t)},className:`h-5 text-[10px] bg-transparent border border-border rounded px-1 text-foreground outline-none max-w-[140px]`,title:`Select connection for autocomplete`,children:[(0,R.jsx)(`option`,{value:``,children:`Connection…`}),De.map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,R.jsx)(`button`,{type:`button`,onClick:lt,disabled:!U,className:`p-0.5 rounded text-muted-foreground hover:text-primary disabled:opacity-30 transition-colors`,title:`Run SQL`,children:(0,R.jsx)(fe,{className:`size-3.5`})}),U&&(0,R.jsx)(`button`,{type:`button`,onClick:()=>Ae(U.id,{readonly:U.readonly?0:1}),className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[10px] transition-colors ${U.readonly?`text-muted-foreground hover:text-foreground`:`bg-destructive/15 text-destructive`}`,title:U.readonly?`Readonly — click to allow writes`:`WRITE mode — click to enable readonly`,children:U.readonly?(0,R.jsx)(re,{className:`size-3`}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(ie,{className:`size-3`}),(0,R.jsx)(`span`,{className:`font-medium`,children:`WRITE`})]})})]}):null;return(0,R.jsxs)(`div`,{ref:dt,className:`flex flex-col h-full w-full overflow-hidden`,style:ft?{height:`${ft}px`,maxHeight:`${ft}px`}:void 0,children:[i!=null&&Pe&&(0,R.jsx)(`div`,{className:`flex items-center h-7 border-b border-border bg-background shrink-0 px-2 gap-2`,children:(0,R.jsx)(`button`,{type:`button`,onClick:K,className:`text-[10px] px-2 py-0.5 rounded border border-border hover:bg-muted transition-colors text-foreground`,children:W?`Raw`:`Beautify`})}),n&&r&&t&&(0,R.jsxs)(`div`,{className:`hidden md:flex items-center h-7 border-b border-border bg-background shrink-0`,children:[(0,R.jsx)(Me,{filePath:n,projectName:r,tabId:t,className:`flex items-center flex-1 min-w-0 overflow-x-auto scrollbar-none px-2 gap-0.5`}),(0,R.jsx)(Fe,{value:P,onChange:q}),Et,(0,R.jsx)(Ne,{ext:M,mdMode:I,onMdModeChange:we,csvMode:Te,onCsvModeChange:Ee,wordWrap:E,onToggleWordWrap:ue,onRefresh:_t,refreshing:ht,filePath:n,projectName:r,className:`shrink-0 flex items-center gap-1 px-2`})]}),i==null&&t&&(O||n&&!r)&&(0,R.jsxs)(`div`,{className:`hidden md:flex items-center h-7 border-b border-border bg-background shrink-0 px-2`,children:[(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground truncate flex-1`,children:O?`Untitled-${e?.untitledNumber??1}`:n?x(n):`Untitled`}),(0,R.jsx)(Fe,{value:P,onChange:q}),Et]}),xe&&Te===`table`?(0,R.jsx)(L.Suspense,{fallback:(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,R.jsx)(D,{className:`size-5 animate-spin text-text-subtle`})}),children:(0,R.jsx)(ze,{content:o??``,onContentChange:bt,wordWrap:E})}):be&&I===`preview`?(0,R.jsx)($e,{content:o??``}):(0,R.jsx)(`div`,{className:`flex-1 overflow-hidden min-h-0`,children:(0,R.jsx)(ye,{height:`100%`,language:P,value:o??``,onChange:i==null?bt:void 0,onMount:Tt,theme:de,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:E?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0},readOnly:i!=null},loading:(0,R.jsx)(D,{className:`size-5 animate-spin text-text-subtle`})},P)}),F&&(Y||tt||rt)&&(0,R.jsx)(Qe,{result:Y,error:tt,loading:rt,connName:U?.name,onClose:()=>{et(null),nt(null),it(!1)},onOpenInTab:ct}),ut&&(0,R.jsx)(Re,{editorRef:S,readOnly:i!=null}),A&&(0,R.jsx)(Ie,{open:A,defaultName:`Untitled-${e?.untitledNumber??1}`,content:b.current,onSave:xt,onCancel:()=>j(!1)})]})}),Y=()=>{};function Qe({result:e,error:t,loading:n,connName:r,onClose:i,onOpenInTab:a}){let o=(0,L.useMemo)(()=>e?.changeType===`select`&&e.rows.length>0?{columns:e.columns,rows:e.rows,total:e.rows.length,limit:e.rows.length}:null,[e]),s=(0,L.useMemo)(()=>(e?.columns??[]).map(e=>({name:e,type:`text`,nullable:!0,pk:!1,defaultValue:null})),[e?.columns]),[c,l]=(0,L.useState)(250),u=(0,L.useCallback)(e=>{e.preventDefault();let t=e.clientY,n=c,r=e=>l(Math.max(80,n+(t-e.clientY))),i=()=>{document.removeEventListener(`mousemove`,r),document.removeEventListener(`mouseup`,i)};document.addEventListener(`mousemove`,r),document.addEventListener(`mouseup`,i)},[c]);return(0,R.jsxs)(`div`,{className:`shrink-0 border-t border-border flex flex-col`,style:{height:c},children:[(0,R.jsx)(`div`,{onMouseDown:u,className:`shrink-0 h-1.5 cursor-row-resize bg-border/50 hover:bg-primary/30 flex items-center justify-center transition-colors`,children:(0,R.jsx)(F,{className:`size-3 text-muted-foreground/50`})}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1 bg-muted/50 border-b border-border shrink-0`,children:[(0,R.jsx)(f,{className:`size-3 text-muted-foreground`}),(0,R.jsxs)(`span`,{className:`text-xs font-medium text-foreground truncate flex-1`,children:[r?`${r} · Results`:`Query Results`,e?.executionTimeMs!=null&&(0,R.jsxs)(`span`,{className:`text-muted-foreground ml-1.5 font-normal`,children:[e.executionTimeMs,`ms`]})]}),(0,R.jsxs)(`button`,{type:`button`,onClick:a,title:`Open in DB Viewer tab`,className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:[(0,R.jsx)(ve,{className:`size-3`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:`Open in Tab`})]}),(0,R.jsx)(`button`,{type:`button`,onClick:i,title:`Close results`,className:`p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,R.jsx)(v,{className:`size-3`})})]}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-hidden min-h-0`,children:[n&&(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,R.jsx)(D,{className:`size-4 animate-spin text-muted-foreground`})}),t&&(0,R.jsx)(`div`,{className:`px-3 py-2 text-xs text-destructive bg-destructive/5`,children:t}),e?.changeType===`modify`&&(0,R.jsxs)(`div`,{className:`px-3 py-2 text-xs text-success`,children:[e.rowsAffected,` row(s) affected`]}),o&&(0,R.jsx)(g,{columns:o.columns,rows:o.rows,total:o.total,limit:o.limit,schema:s,loading:!1,page:1,onPageChange:Y,onCellUpdate:Y,orderBy:null,orderDir:`ASC`,onToggleSort:Y,connectionName:r}),e?.changeType===`select`&&e.rows.length===0&&(0,R.jsx)(`div`,{className:`px-3 py-2 text-xs text-muted-foreground`,children:`No results`})]})]})}function X(){return(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,R.jsx)(D,{className:`size-5 animate-spin text-text-subtle`})})}function $e({content:e}){return(0,R.jsx)(L.Suspense,{fallback:(0,R.jsx)(`div`,{className:`animate-pulse h-4 bg-muted rounded m-4`}),children:(0,R.jsx)(J,{content:e,className:`flex-1 overflow-auto p-4`})})}export{Ze as CodeEditor};
|