@hienlh/ppm 0.18.1 → 0.18.2
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/.release-run.sh +1 -1
- package/CHANGELOG.md +5 -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-Bmk4P0YS.js → ai-resource-editor-B6CODu6u.js} +1 -1
- package/dist/web/assets/{audio-preview-CikvnAOI.js → audio-preview-BkNAEqcB.js} +1 -1
- package/dist/web/assets/{chat-tab-B3-KcCn2.js → chat-tab-B-MEsHYp.js} +3 -3
- package/dist/web/assets/{code-editor-BpbZw13T.js → code-editor-bC1KAEUA.js} +2 -2
- package/dist/web/assets/{conflict-editor-DC3liBm_.js → conflict-editor-DnSltcyC.js} +1 -1
- package/dist/web/assets/{csv-preview-BhCOjgq1.js → csv-preview-DnaFdgOB.js} +1 -1
- package/dist/web/assets/{database-viewer-Z6uLyZVO.js → database-viewer-C7uLy8Z1.js} +1 -1
- package/dist/web/assets/{diff-viewer-CT1ALWt2.js → diff-viewer-BwElk4q9.js} +1 -1
- package/dist/web/assets/{docx-preview-C_fSjfy_.js → docx-preview-Dd2nTW2v.js} +1 -1
- package/dist/web/assets/{explorer-body-CQCyGEet.js → explorer-body-DzdXBlWw.js} +1 -1
- package/dist/web/assets/{explorer-window-content-EtyTAZSh.js → explorer-window-content-Dgl1WTNs.js} +1 -1
- package/dist/web/assets/{extension-webview-ePIM2fwM.js → extension-webview-Dk_zyoXZ.js} +1 -1
- package/dist/web/assets/{git-log-panel-BRWmTzX1.js → git-log-panel-BLQSy6rC.js} +1 -1
- package/dist/web/assets/{glide-data-grid-DCJCz4XB.js → glide-data-grid-QZ_fgjIa.js} +1 -1
- package/dist/web/assets/{group-chat-tab-C3UD2bcm.js → group-chat-tab-BbdVlKFv.js} +1 -1
- package/dist/web/assets/{image-preview-CP82lor8.js → image-preview-KubLSLNO.js} +1 -1
- package/dist/web/assets/{index-BYetJoXQ.js → index-wd3FSHHn.js} +5 -5
- package/dist/web/assets/{keybindings-store-yBWU8ZYT.js → keybindings-store-Bp_c_C3z.js} +1 -1
- package/dist/web/assets/{markdown-renderer-B2D4gdok.js → markdown-renderer-2asl-3Kk.js} +1 -1
- package/dist/web/assets/{markdown-renderer-DDgl5zDc.js → markdown-renderer-B4uL6GVA.js} +1 -1
- package/dist/web/assets/{mobile-explorer-sheet-BtxyynR3.js → mobile-explorer-sheet-LWUDaNBV.js} +1 -1
- package/dist/web/assets/{notification-store-DKw_mGED.js → notification-store-BasUnpt7.js} +1 -1
- package/dist/web/assets/{pdf-preview-BXDOe7bG.js → pdf-preview-xZQVUtaV.js} +1 -1
- package/dist/web/assets/{postgres-viewer-DkHYV33h.js → postgres-viewer-Ds0FxBel.js} +1 -1
- package/dist/web/assets/resolve-theme-DdB7Yo5Z.js +1 -0
- package/dist/web/assets/{settings-tab-ESL-6MAA.js → settings-tab-vhatQ51-.js} +1 -1
- package/dist/web/assets/{sql-query-editor-CZdZuawP.js → sql-query-editor-BblB2Imt.js} +1 -1
- package/dist/web/assets/{sqlite-viewer-Cpq06-nz.js → sqlite-viewer-CZYDknNa.js} +1 -1
- package/dist/web/assets/{system-monitor-tab-XR8NXHpv.js → system-monitor-tab-D8dy-RT_.js} +1 -1
- package/dist/web/assets/{terminal-tab-CCCB-_50.js → terminal-tab-CfD22q5x.js} +1 -1
- package/dist/web/assets/{tool-cards-CsTs5go2.js → tool-cards-DNgw1yI6.js} +2 -2
- package/dist/web/assets/{use-monaco-theme-CZh7xTJZ.js → use-monaco-theme-DEbn-QT3.js} +1 -1
- package/dist/web/assets/{video-preview-KbRcyuAA.js → video-preview-DcUaFYyv.js} +1 -1
- package/dist/web/index.html +2 -2
- package/dist/web/sw.js +1 -1
- package/package.json +1 -1
- package/src/web/theme/builtin/aurora.ts +8 -5
- package/dist/web/assets/resolve-theme-B0eotaPq.js +0 -1
package/.release-run.sh
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -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.18.
|
|
74
|
+
<!-- Generated for PPM v0.18.2 at build time. Re-run `ppm export skill --install` to refresh. -->
|
|
@@ -302,4 +302,4 @@ _Base URL: `http://localhost:8080` (default; override via `ppm config set port <
|
|
|
302
302
|
- `ws://<host>/ws/terminal` — PTY terminal multiplexer
|
|
303
303
|
- `ws://<host>/ws/extensions` — extension host channel
|
|
304
304
|
|
|
305
|
-
<!-- Generated from src/server/routes/ for PPM v0.18.
|
|
305
|
+
<!-- Generated from src/server/routes/ for PPM v0.18.2 -->
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./save-C4z1p51e.js";import{s as i}from"./api-client-rTAGdEKo.js";import"./vendor-mermaid-C977xNeE.js";import"./settings-store-ChqHdT2V.js";import{n as a}from"./utils-B9H0d3Fh.js";import{A as o,Hn as s,M as c,O as l,Vn as u,_n as d,j as f,k as p,o as m,vn as h}from"./index-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./save-C4z1p51e.js";import{s as i}from"./api-client-rTAGdEKo.js";import"./vendor-mermaid-C977xNeE.js";import"./settings-store-ChqHdT2V.js";import{n as a}from"./utils-B9H0d3Fh.js";import{A as o,Hn as s,M as c,O as l,Vn as u,_n as d,j as f,k as p,o as m,vn as h}from"./index-wd3FSHHn.js";import{t as g}from"./use-monaco-theme-DEbn-QT3.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),f(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 c(t,e,w),O(e),E(e),i.success(`Saved`),o.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=p[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)(l,{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)(d,{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)(s,{className:`size-3.5 animate-spin`}):(0,v.jsx)(r,{className:`size-3.5`}),` Save`]})]})]}),x&&(0,v.jsx)(b,{icon:u,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:h,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)(s,{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)(m,{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{x as e}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t}from"./createLucideIcon-D8pyde1A.js";import{t as n}from"./file-exclamation-point-COAwgNGw.js";import"./api-client-rTAGdEKo.js";import{t as r}from"./utils-B9H0d3Fh.js";import{Hn as i}from"./index-
|
|
1
|
+
import{x as e}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t}from"./createLucideIcon-D8pyde1A.js";import{t as n}from"./file-exclamation-point-COAwgNGw.js";import"./api-client-rTAGdEKo.js";import{t as r}from"./utils-B9H0d3Fh.js";import{Hn as i}from"./index-wd3FSHHn.js";import{t as a}from"./use-blob-url-DYtOHK7u.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};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/edit-diff-preview-DfX-9om9.js","assets/rolldown-runtime-FhOqtrmT.js","assets/vendor-markdown-Ls5AcU91.js","assets/libesm-tR4XlhMj.js","assets/markdown-renderer-
|
|
2
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./createLucideIcon-D8pyde1A.js";import{t as i}from"./bot-nk1k3ELu.js";import{d as a}from"./context-menu-q-RHHAWz.js";import{n as o,r as s}from"./use-is-mobile-DnFSkUG2.js";import{t as c}from"./chevron-right-BLOtX8Vy.js";import{a as l,i as u,n as d,r as f,t as p}from"./tool-cards-CsTs5go2.js";import{a as m,c as h,i as g,n as _,o as v,r as y,t as b,u as x}from"./dialog-CkI7rwrh.js";import{t as S}from"./clock-D493FU_D.js";import{t as C}from"./code-CLF5x7KK.js";import{t as w}from"./sparkles-n1hzh65o.js";import{t as T}from"./copy-BApI9v7Z.js";import{n as E,r as ee,t as te}from"./plus-9LatwJMx.js";import{t as D}from"./shield-off-DULFtyLS.js";import{t as ne}from"./x-B1qHmLdR.js";import{i as O,n as k,r as A,s as re}from"./api-client-rTAGdEKo.js";import{q as j}from"./vendor-mermaid-C977xNeE.js";import{t as M}from"./settings-store-ChqHdT2V.js";import{n as N,r as ie,t as P}from"./utils-B9H0d3Fh.js";import{t as F}from"./panel-store-s6Qx49RK.js";import{i as ae}from"./project-store-DyaEpHVG.js";import{t as oe}from"./tab-store-C42sktPo.js";import{t as I}from"./mobile-bottom-sheet-BQt45q9T.js";import{_ as L,a as se,c as R,h as z,i as B,l as ce,m as le,o as V,p as H,r as U,s as W,t as G,u as K}from"./api-settings-CAhcNpj5.js";import{An as q,B as ue,Bn as de,Cn as J,D as fe,Dn as pe,En as me,Fn as Y,G as he,H as ge,Hn as X,I as _e,Jn as ve,K as ye,Kn as be,L as xe,Ln as Se,Nn as Ce,Pn as we,Qn as Te,R as Ee,Rn as De,Sn as Oe,Tn as ke,U as Ae,Ut as je,V as Me,Vn as Z,W as Ne,_r as Pe,br as Fe,dn as Ie,dr as Le,fn as Re,fr as ze,gn as Be,gr as Ve,h as He,hn as Ue,hr as We,in as Ge,jn as Ke,kn as qe,mr as Je,nn as Ye,on as Xe,pn as Ze,pr as Qe,qt as $e,r as et,rn as tt,rr as nt,sr as rt,t as it,tr as at,un as ot,vn as st,vr as ct,wn as lt,xn as ut,yn as dt,yr as ft,z as pt}from"./index-BYetJoXQ.js";import"./use-blob-url-DYtOHK7u.js";import{n as mt,r as ht,t as gt}from"./image-gallery-BWFpZAAP.js";import{t as _t}from"./libesm-tR4XlhMj.js";var vt=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`}]]),yt=r(`chevrons-down`,[[`path`,{d:`m7 6 5 5 5-5`,key:`1lc07p`}],[`path`,{d:`m7 13 5 5 5-5`,key:`1d48rs`}]]),bt=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`}]]),xt=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`}]]),St=r(`image-off`,[[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}],[`path`,{d:`M10.41 10.41a2 2 0 1 1-2.83-2.83`,key:`1bzlo9`}],[`line`,{x1:`13.5`,x2:`6`,y1:`13.5`,y2:`21`,key:`1q0aeu`}],[`line`,{x1:`18`,x2:`21`,y1:`12`,y2:`15`,key:`5mozeu`}],[`path`,{d:`M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59`,key:`mmje98`}],[`path`,{d:`M21 15V5a2 2 0 0 0-2-2H9`,key:`43el77`}]]),Ct=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`}]]),wt=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`}]]),Tt=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`}]]),Et=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`}]]),Dt=r(`slash`,[[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}]]),Q=e(t(),1);function Ot(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 kt(e,t){let n=`pc-${Ot(t)}-`;return e.map(e=>e.id?{...e,id:`${n}${e.id}`}:e)}function At(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 jt=null;function Mt(){return jt||=new AudioContext,jt}function Nt(e,t,n,r,i=`sine`){let a=Mt(),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 Pt(){let e=Mt().currentTime;Nt(523,.15,e,.15),Nt(659,.2,e+.12,.15)}function Ft(){let e=Mt().currentTime;Nt(880,.12,e,.18,`square`),Nt(698,.12,e+.15,.18,`square`),Nt(880,.15,e+.3,.15,`square`)}function It(){let e=Mt().currentTime;Nt(440,.12,e,.12),Nt(523,.12,e+.1,.12),Nt(659,.18,e+.2,.12)}var Lt={done:Pt,approval_request:Ft,question:It};function Rt(e){try{Lt[e]?.()}catch{}}var zt={hasTeams:!1,teamNames:[],messageCount:0,unreadCount:0};function Bt(e){if(document.hidden)return!1;let{panels:t}=F.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 Vt(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)({}),[f,p]=(0,Q.useState)(`idle`),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(0),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)([]),E=(0,Q.useRef)([]),[ee,te]=(0,Q.useState)(null),[D,ne]=(0,Q.useState)(null),[j,M]=(0,Q.useState)(!1),[N,ie]=(0,Q.useState)(null),[P,ae]=(0,Q.useState)(null),oe=(0,Q.useRef)(null),I=(0,Q.useRef)(null),[L,se]=(0,Q.useState)(null),R=(0,Q.useRef)(null),[z,B]=(0,Q.useState)(!0),ce=(0,Q.useRef)(null),le=(0,Q.useRef)(null),V=(0,Q.useRef)(``),H=(0,Q.useRef)([]),U=(0,Q.useRef)(new Map),W=(0,Q.useRef)(null),G=(0,Q.useRef)(`idle`),K=(0,Q.useRef)(null),q=(0,Q.useRef)(()=>{}),ue=(0,Q.useRef)(null),de=(0,Q.useRef)(!1),J=(0,Q.useRef)(new Set),fe=(0,Q.useRef)(0),pe=(0,Q.useRef)(null),me=(0,Q.useRef)(0),Y=(0,Q.useRef)(e);Y.current=e;let he=(0,Q.useRef)([]);he.current=r;let ge=(0,Q.useRef)(n);ge.current=n;let X=(0,Q.useRef)(null),_e=(0,Q.useRef)(0),ve=(0,Q.useRef)({teamNames:new Set,messages:[]}),ye=(0,Q.useRef)(0),[be,xe]=(0,Q.useState)(zt),[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=f!==`idle`;(0,Q.useEffect)(()=>{if(e)return $e.getState().setStreaming(e,f!==`idle`,n),()=>{$e.getState().setStreaming(e,!1)}},[e,f,n]);let De=(0,Q.useCallback)((e,t)=>{let n=H.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=H.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return H.current[n]={...r,children:i},!0},[]),Oe=(0,Q.useCallback)((e,t)=>{let n=e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t,r=he.current,a=-1;for(let e=r.length-1;e>=0;e--)if(r[e].events?.some(n)){a=e;break}return a===-1?!1:(i(t=>{let r=-1;for(let e=t.length-1;e>=0;e--)if(t[e].events?.some(n)){r=e;break}if(r===-1)return t;let i=t[r],a=i.events.map(t=>{if(!n(t)||t.type!==`tool_use`)return t;let r=[...t.children??[]],i=e.toolUseId,a=i?r.findIndex(t=>t.type===e.type&&t.toolUseId===i):-1;return a===-1?r.push(e):r[a]=e,{...t,children:r}});return[...t.slice(0,r),{...i,events:a},...t.slice(r+1)]}),!0)},[]),ke=(0,Q.useCallback)(()=>{_e.current=0;let e=V.current,t=[...H.current],n=W.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}]})})},[]),Ae=(0,Q.useCallback)(()=>{_e.current||=window.setTimeout(ke,100)},[ke]),je=(0,Q.useCallback)(e=>{let t=e,n=t?.type;if(!n)return;let r=e=>{let n=H.current,r=n.findIndex(e);r===-1?n.push(t):n[r]=t};switch(n){case`account_info`:W.current={accountId:t.accountId,accountLabel:t.accountLabel},te(null);break;case`account_retry`:t.accountId&&t.accountLabel&&(W.current={accountId:t.accountId,accountLabel:t.accountLabel}),H.current=[t],Ae();break;case`status_update`:{let e=t.accountLabel?` (${t.accountLabel})`:``;te(`${t.message}${e}`);break}case`text`:{let e=t.parentToolUseId;if(e&&De(t,e)){Ae();break}if(e){Oe(t,e);break}V.current+=t.content,H.current.push(t),Ae();break}case`thinking`:{let e=t.parentToolUseId;if(e&&De(t,e)){Ae();break}if(e){Oe(t,e);break}H.current.push(t),Ae();break}case`tool_use`:{if(t.tool===`AskUserQuestion`){t.toolUseId&&J.current.add(t.toolUseId);break}let e=t.parentToolUseId;if(e&&De(t,e)){Ae();break}if(e){Oe(t,e);break}let n=t.toolUseId;r(e=>!!n&&e.type===`tool_use`&&e.toolUseId===n),Ae();break}case`tool_result`:{let e=t.toolUseId;if(e&&U.current.delete(e),e&&J.current.has(e))break;let n=t.parentToolUseId;if(n&&De(t,n)){Ae();break}if(n){Oe(t,n);break}r(t=>!!e&&t.type===`tool_result`&&t.toolUseId===e),Ae();break}case`approval_resolved`:{let e=t.requestId;if(t.approved&&t.answers){let n=H.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),X.current!=null&&(re.dismiss(X.current),X.current=null);break}case`approval_request`:if(r(e=>e.type===`approval_request`&&e.requestId===t.requestId),de.current)break;if(y({requestId:t.requestId,tool:t.tool,input:t.input}),Y.current&&!Bt(Y.current)){Rt(t.tool===`AskUserQuestion`?`question`:`approval_request`);let e=Y.current,n=t.tool===`AskUserQuestion`;X.current=re[n?`info`:`warning`](n?`AI has a question`:`${t.tool} needs permission`,{description:ge.current||`Session ${e.slice(0,8)}`,duration:1/0,action:{label:`Go to session`,onClick:()=>{let{panels:t}=F.getState();for(let[n,r]of Object.entries(t)){let t=r.tabs.find(t=>t.metadata?.sessionId===e);if(t){F.getState().setActiveTab(t.id,n);break}}}}})}break;case`error`:i(e=>{let n=e[e.length-1];if(n?.role===`assistant`){let r=H.current,i=r[r.length-1],a=i?.type===`error`&&i.message===t.message?r:[...r,t];return H.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),k.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=U.current.get(e);n?(n.content+=t.content,n.content.length>5e5&&(n.content=n.content.slice(-5e5)),n.lineCount=t.lineCount):U.current.set(e,{content:t.content,lineCount:t.lineCount}),Ae()}break}case`background_registry`:{let e=t.shells??[];E.current=e,T(e);break}case`done`:{if(G.current===`idle`)break;t.contextWindowPct!=null&&x(t.contextWindowPct),Y.current&&!Bt(Y.current)&&Rt(`done`),_e.current&&=(clearTimeout(_e.current),0);let e=V.current,n=[...H.current],r=W.current,a=t.lastMessageUuid,o=t.usage;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},...o&&{usage:o}}]:e||n.length>0?[...t,{id:`final-${Date.now()}`,role:`assistant`,content:e,events:n,timestamp:new Date().toISOString(),...a&&{sdkUuid:a},...o&&{usage:o},...r}]:t}),V.current=``,H.current=[],W.current=null,pe.current=null,U.current.clear(),te(null);break}}},[De,Oe,Ae]),Me=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`user_message`){let e=t.content;i(n=>{let r=n[n.length-1];return r?.role===`user`&&r.content===e?n:[...n,{id:`user-remote-${Date.now()}`,role:`user`,content:e,timestamp:t.timestamp??new Date().toISOString()}]});return}if(t.type===`title_updated`){ne(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;p(e),G.current=e,_(e===`connecting`?t.elapsed??0:0),e===`idle`&&C(null);return}if(t.type===`session_state`){M(!0),ie(t.sessionId??Y.current);let e=t,n=e.phase,r=G.current===`idle`;if(p(n),G.current=n,e.sessionTitle&&ne(e.sessionTitle),e.model&&(I.current&&e.model!==I.current||(e.model===I.current&&(I.current=null),ae(e.model),oe.current=e.model)),typeof e.effort==`string`&&(se(e.effort),R.current=e.effort),typeof e.thinking==`boolean`&&B(e.thinking),e.pendingApproval&&y({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),C(e.compactStatus===`compacting`?`compacting`:null),n===`idle`){let e=Date.now()-me.current<5e3;r&&e||ue.current?.(),h(!1)}return}if(t.type===`turn_events`){let e=t.events,n=t.userMessage;if(!e?.length&&!n){h(!1);return}fe.current&&=(cancelAnimationFrame(fe.current),0),pe.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}),V.current=``,H.current=[],W.current=null,de.current=!0;let r=0,a=()=>{let t=Math.min(r+100,e.length);for(let n=r;n<t;n++)je(e[n]);r=t,r<e.length?fe.current=requestAnimationFrame(a):(fe.current=0,de.current=!1,h(!1))};fe.current=requestAnimationFrame(a);return}je(t)}},[je]),{send:Z,connect:Ne}=d({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:Me,autoConnect:!!e&&!!n});q.current=Z,(0,Q.useEffect)(()=>{let r=!1;le.current&&le.current!==e&&(I.current=null,ce.current=null),le.current=e??null,p(`idle`),G.current=`idle`,y(null),X.current!=null&&(re.dismiss(X.current),X.current=null),C(null),o(new Map),u({}),V.current=``,H.current=[],pe.current=null,me.current=0,U.current.clear(),_e.current&&=(clearTimeout(_e.current),0),M(!1),ie(null),ve.current={teamNames:new Set,messages:[]},ye.current=0,xe(zt),Ce([]);let a=new Set(he.current.map(e=>e.id));return e&&n?(c(!0),k.get(`${O(n)}/chat/sessions/${e}/messages?providerId=${t}`).then(e=>{if(r)return;let t=Array.isArray(e)?{messages:e,versionMap:{}}:e,n=Array.isArray(t?.messages)?t.messages:[];t?.versionMap&&u(t.versionMap);let o=pe.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]}),me.current=Date.now()}).catch(()=>{r||i(e=>e.filter(e=>!a.has(e.id)))}).finally(()=>{r||c(!1)})):i([]),()=>{r=!0}},[e,t,n]);let Pe=(0,Q.useCallback)((e,t)=>{if(!e.trim())return;let n=G.current!==`idle`;if(n){_e.current&&=(clearTimeout(_e.current),0);let e=V.current,t=[...H.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()}]),V.current=``,H.current=[],K.current=null,n?(p(`thinking`),G.current=`thinking`):(p(`initializing`),G.current=`initializing`),y(null),X.current!=null&&(re.dismiss(X.current),X.current=null),Z(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode,priority:t?.priority,images:t?.images,...oe.current&&{model:oe.current},...R.current&&{effort:R.current},...ce.current!==null&&{thinking:ce.current}}))},[Z]),Fe=(0,Q.useCallback)(e=>{ae(e),oe.current=e,I.current=e,Z(JSON.stringify({type:`set_model`,model:e}))},[Z]),Ie=(0,Q.useCallback)(e=>{se(e),R.current=e,Z(JSON.stringify({type:`set_effort`,effort:e}))},[Z]),Le=(0,Q.useCallback)(e=>{B(e),ce.current=e,Z(JSON.stringify({type:`set_thinking`,enabled:e}))},[Z]),Re=(0,Q.useCallback)((e,t,n)=>{if(Z(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=H.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),X.current!=null&&(re.dismiss(X.current),X.current=null)},[Z]),ze=(0,Q.useCallback)(()=>{if(G.current===`idle`)return;Z(JSON.stringify({type:`cancel`}));let e=V.current,t=[...H.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}),V.current=``,H.current=[],U.current.clear(),K.current=null,p(`idle`),G.current=`idle`,y(null),X.current!=null&&(re.dismiss(X.current),X.current=null)},[Z]),Be=(0,Q.useCallback)(e=>{e&&Z(JSON.stringify({type:`kill_background_shell`,shellId:e}))},[Z]),Ve=(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&&it.getState().setSessionShells(e,w)},[e,w]),(0,Q.useEffect)(()=>{if(e)return it.getState().retainSession(e),()=>{it.getState().releaseSession(e)}},[e]);let He=(0,Q.useCallback)(()=>{M(!1),h(!0),Ne()},[Ne]),Ue=(0,Q.useCallback)(()=>{!e||!n||fetch(`${O(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${A()}`}}).then(e=>e.json()).then(e=>{if(G.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),V.current=``,H.current=[]),me.current=Date.now()}).catch(()=>{})},[e,t,n]);ue.current=Ue;let We=(0,Q.useCallback)(async(e,t)=>{if(!n)throw Error(`No project context available`);let r=e.replace(/^pc-[^-]+-/,``),i=`${O(n)}/chat/pre-compact-messages?jsonlPath=${encodeURIComponent(t)}&before=${encodeURIComponent(r)}`,a=kt(await k.get(i),t);return o(t=>{let n=new Map(t);return n.set(e,a),n}),a.length},[n]),Ge=(0,Q.useCallback)(e=>a.has(e),[a]),Ke=(0,Q.useCallback)(e=>{i(t=>t.filter(t=>t.id!==e))},[]),qe=(0,Q.useCallback)(()=>{i(e=>e.filter(e=>e.role!==`system`))},[]);return{messages:r,renderedMessages:(0,Q.useMemo)(()=>At(r,a),[r,a]),expandCompact:We,isCompactExpanded:Ge,dismissMessage:Ke,clearErrors:qe,messagesLoading:s,versionMap:l,isStreaming:Ee,phase:f,isReconnecting:m,connectingElapsed:g,pendingApproval:v,contextWindowPct:b,compactStatus:S,statusMessage:ee,sessionTitle:D,model:P,setModel:Fe,effort:L,setEffort:Ie,thinking:z,setThinking:Le,teamActivity:be,teamMessages:Se,markTeamRead:Te,bashPartialOutput:U,backgroundShells:w,killBackgroundShell:Be,findBackgroundShellByOutput:Ve,sendMessage:Pe,respondToApproval:Re,cancelStreaming:ze,reconnect:He,refetchMessages:Ue,isConnected:j&&N===e}}var Ht=12e4;function Ut(e,t=`claude`,n){let[r,i]=(0,Q.useState)({}),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),l=(0,Q.useRef)(null),u=(0,Q.useCallback)((r=!1)=>{if(!e)return;o(!0);let a=r?`&refresh=1`:``,s=n?`&session=${encodeURIComponent(n)}`:``;k.get(`${O(e)}/chat/usage?providerId=${t}${s}${a}`).then(e=>{e&&(i(t=>({...t,...e})),e.lastFetchedAt&&c(e.lastFetchedAt))}).catch(()=>{}).finally(()=>o(!1))},[e,t,n]);return(0,Q.useEffect)(()=>(u(),l.current=setInterval(()=>u(),Ht),()=>{l.current&&clearInterval(l.current)}),[u]),{usageInfo:r,usageLoading:a,lastFetchedAt:s,refreshUsage:(0,Q.useCallback)(()=>u(!0),[u])}}var Wt={damping:.7,stiffness:.05,mass:1.25},Gt=70,Kt=1e3/60,qt=350,Jt=!1;globalThis.document?.addEventListener(`mousedown`,()=>{Jt=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{Jt=!1}),globalThis.document?.addEventListener(`click`,()=>{Jt=!1});var Yt=(e={})=>{let[t,n]=(0,Q.useState)(!1),[r,i]=(0,Q.useState)(e.initial!==!1),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null);s.current=e;let c=(0,Q.useCallback)(()=>{if(!Jt)return!1;let e=window.getSelection();if(!e||!e.rangeCount)return!1;let t=e.getRangeAt(0);return t.commonAncestorContainer.contains(g.current)||g.current?.contains(t.commonAncestorContainer)},[]),l=(0,Q.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,Q.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,Q.useMemo)(()=>{let n;return{escapedFromLock:t,isAtBottom:r,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return g.current?.scrollTop??0},set scrollTop(e){if(g.current){let{scrollBehavior:t}=getComputedStyle(g.current);t!==`auto`&&(g.current.style.scrollBehavior=`auto`),g.current.scrollTop=e,d.ignoreScrollToTop=g.current.scrollTop,t!==`auto`&&(g.current.style.scrollBehavior=t)}},get targetScrollTop(){return!g.current||!_.current?0:g.current.scrollHeight-1-g.current.clientHeight},get calculatedTargetScrollTop(){if(!g.current||!_.current)return 0;let{targetScrollTop:t}=this;if(!e.targetScrollTop)return t;if(n?.targetScrollTop===t)return n.calculatedScrollTop;let r=Math.max(Math.min(e.targetScrollTop(t,{scrollElement:g.current,contentElement:_.current}),t),0);return n={targetScrollTop:t,calculatedScrollTop:r},requestAnimationFrame(()=>{n=void 0}),r},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=Gt}}},[]),f=(0,Q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Qt(s.current,e.animation),{ignoreEscapes:r=!1}=e,i,a=d.calculatedTargetScrollTop;e.duration instanceof Promise?e.duration.finally(()=>{i=Date.now()}):i=t+(e.duration??0);let o=async()=>{let e=new Promise(requestAnimationFrame).then(()=>{if(!d.isAtBottom)return d.animation=void 0,!1;let{scrollTop:l}=d,u=performance.now(),p=(u-(d.lastTick??u))/Kt;if(d.animation||={behavior:n,promise:e,ignoreEscapes:r},d.animation.behavior===n&&(d.lastTick=u),c()||t>Date.now())return o();if(l<Math.min(a,d.calculatedTargetScrollTop)){if(d.animation?.behavior===n){if(n===`instant`)return d.scrollTop=d.calculatedTargetScrollTop,o();d.velocity=(n.damping*d.velocity+n.stiffness*d.scrollDifference)/n.mass,d.accumulated+=d.velocity*p,d.scrollTop+=d.accumulated,d.scrollTop!==l&&(d.accumulated=0)}return o()}return i>Date.now()?(a=d.calculatedTargetScrollTop,o()):(d.animation=void 0,d.scrollTop<d.calculatedTargetScrollTop?f({animation:Qt(s.current,s.current.resize),ignoreEscapes:r,duration:Math.max(0,i-Date.now())||void 0}):d.isAtBottom)});return e.then(e=>(requestAnimationFrame(()=>{d.animation||(d.lastTick=void 0,d.velocity=0)}),e))};return e.wait!==!0&&(d.animation=void 0),d.animation?.behavior===n?d.animation.promise:o()},[l,c,d]),p=(0,Q.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,Q.useCallback)(({target:e})=>{if(e!==g.current)return;let{scrollTop:t,ignoreScrollToTop:n}=d,{lastScrollTop:r=t}=d;d.lastScrollTop=t,d.ignoreScrollToTop=void 0,n&&n>t&&(r=n),o(d.isNearBottom),setTimeout(()=>{if(d.resizeDifference||t===n)return;if(c()){u(!0),l(!1);return}let e=t>r,i=t<r;if(d.animation?.ignoreEscapes){d.scrollTop=r;return}i&&(u(!0),l(!1)),e&&u(!1),!d.escapedFromLock&&d.isNearBottom&&l(!0)},1)},[u,l,c,d]),h=(0,Q.useCallback)(({target:e,deltaY:t})=>{let n=e;for(;![`scroll`,`auto`].includes(getComputedStyle(n).overflow);){if(!n.parentElement)return;n=n.parentElement}n===g.current&&t<0&&g.current.scrollHeight>g.current.clientHeight&&!d.animation?.ignoreEscapes&&(u(!0),l(!1))},[u,l,d]),g=Xt(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=Xt(e=>{if(d.resizeObserver?.disconnect(),d.resizeObserver=void 0,!e)return;let t;d.resizeObserver=new ResizeObserver(([e])=>{let{height:n}=e.contentRect,r=n-(t??n);if(d.resizeDifference=r,d.scrollTop>d.targetScrollTop&&(d.scrollTop=d.targetScrollTop),o(d.isNearBottom),r>=0){let e=Qt(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:qt})}else d.isNearBottom&&(u(!1),l(!0));t=n,requestAnimationFrame(()=>{setTimeout(()=>{d.resizeDifference===r&&(d.resizeDifference=0)},1)})}),d.resizeObserver?.observe(e)},[]);return{contentRef:_,scrollRef:g,scrollToBottom:f,stopScroll:p,isAtBottom:r||a,isNearBottom:a,escapedFromLock:t,state:d}};function Xt(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Zt=new Map;function Qt(...e){let t={...Wt},n=!1;for(let r of e){if(r===`instant`){n=!0;continue}typeof r==`object`&&(n=!1,t.damping=r.damping??t.damping,t.stiffness=r.stiffness??t.stiffness,t.mass=r.mass??t.mass)}let r=JSON.stringify(t);return Zt.has(r)||Zt.set(r,Object.freeze(t)),n?`instant`:Zt.get(r)}var $t=60,en=8,tn=1400;function nn(e){if(e.scrollHeight<=e.clientHeight)return!1;let t=getComputedStyle(e).overflowY;return t===`auto`||t===`scroll`}function rn(e,t){let n=[],r=e.parentElement;for(;r&&r!==t;)nn(r)&&n.push(r),r=r.parentElement;return n}function an(){return typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches}function on(e,t){let n=e.querySelector(`[data-edit-ref="${CSS.escape(t)}"]`);if(n)return{el:n,level:`edit`};let r=t.replace(/-\d+$/,``),i=e.querySelector(`[data-tool-ref="${CSS.escape(r)}"]`);return i?{el:i,level:`card`}:null}function sn(e,t,n,r){let i=e.scrollTop+t.getBoundingClientRect().top-e.getBoundingClientRect().top-n;e.scrollTo({top:i,behavior:r?`smooth`:`auto`})}function cn(e,t){let n=on(e,t);if(!n)return()=>{};let{el:r,level:i}=n;for(let t of rn(r,e))sn(t,r,en,!1);sn(e,r,$t,!an()),r.dataset.flash=i;let a=setTimeout(()=>{delete r.dataset.flash},tn);return()=>{clearTimeout(a),delete r.dataset.flash}}var ln=new Set([`Write`,`Edit`,`MultiEdit`,`NotebookEdit`]),un={create:3,write:2,notebook:2,edit:1};function dn(e){return typeof e==`string`?e:``}function fn(e,t){let n=0,r=0;for(let i of _t(e,t))i.added?n+=i.count??0:i.removed&&(r+=i.count??0);return{added:n,removed:r}}function pn(e){return e&&/created successfully/i.test(e)?`create`:`write`}function mn(e,t,n){switch(e){case`Write`:{let e=dn(t.file_path);return e?{filePath:e,op:pn(n),fragments:[{oldStr:``,newStr:dn(t.content)}]}:null}case`Edit`:{let e=dn(t.file_path);return e?{filePath:e,op:`edit`,fragments:[{oldStr:dn(t.old_string),newStr:dn(t.new_string)}]}:null}case`MultiEdit`:{let e=dn(t.file_path);if(!e||!Array.isArray(t.edits))return null;let n=t.edits.filter(e=>!!e&&typeof e==`object`).map(e=>({oldStr:dn(e.old_string),newStr:dn(e.new_string)}));return n.length===0?null:{filePath:e,op:`edit`,fragments:n}}case`NotebookEdit`:{let e=dn(t.notebook_path)||dn(t.file_path);return e?{filePath:e,op:`notebook`,fragments:[{oldStr:``,newStr:dn(t.new_source)}]}:null}default:return null}}function hn(e,t){if(e){for(let n of e)if(n.type===`tool_result`&&n.toolUseId&&t.set(n.toolUseId,n.output??``),n.type===`tool_use`){let e=n.result;n.toolUseId&&e?.output!=null&&!t.has(n.toolUseId)&&t.set(n.toolUseId,e.output),hn(n.children,t)}}}function gn(e,t,n,r){if(e)for(let i of e){if(i.type!==`tool_use`||(i.children?.length&&gn(i.children,!0,n,r),!ln.has(i.tool)))continue;let e=i.input&&typeof i.input==`object`?i.input:null;if(!e)continue;let a=mn(i.tool,e,i.toolUseId?r.get(i.toolUseId):void 0);if(!a)continue;let o=n.get(a.filePath);o||(o={filePath:a.filePath,op:a.op,editCount:0,linesAdded:0,linesRemoved:0,edits:[],viaSubagent:!1},n.set(a.filePath,o)),un[a.op]>un[o.op]&&(o.op=a.op),t&&(o.viaSubagent=!0),a.fragments.forEach((e,n)=>{let{added:r,removed:a}=fn(e.oldStr,e.newStr);o.linesAdded+=r,o.linesRemoved+=a,o.editCount+=1,o.edits.push({...e,toolUseId:i.toolUseId,editIndex:n,editRef:i.toolUseId?`${i.toolUseId}-${n}`:void 0,viaSubagent:t})})}}function _n(e){let t=new Map;for(let n of e)hn(n.events,t);let n=new Map;for(let r of e)gn(r.events,!1,n,t);return[...n.values()]}function vn(e,t){let n=[];for(let r=t;r>=0&&e[r]?.role===`assistant`;r--)n.unshift(e[r]);return n}var $=n();function yn(e){try{return new Date(e).toLocaleString()}catch{return``}}function bn({icon:e,label:t,title:n,onClick:r}){return(0,$.jsxs)(`button`,{type:`button`,onClick:r,title:n,"aria-label":t,className:`inline-flex items-center justify-center gap-1 rounded-md px-1.5 py-1 text-text-subtle hover:text-text-primary hover:bg-surface transition-colors`,children:[e,(0,$.jsx)(`span`,{children:t})]})}function xn({content:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsx)(bn,{icon:t?(0,$.jsx)(a,{className:`size-3.5`}):(0,$.jsx)(T,{className:`size-3.5`}),label:t?`Copied`:`Copy`,title:`Copy message to clipboard`,onClick:()=>{je(e),n(!0),setTimeout(()=>n(!1),1500)}})}function Sn({timestamp:e,content:t,className:n,children:r}){return(0,$.jsxs)(`div`,{className:N(`flex items-center gap-0.5 flex-wrap text-xs text-text-subtle select-none`,n),children:[(0,$.jsx)(`time`,{title:yn(e),className:`pr-1 tabular-nums`,children:Re(e)}),(0,$.jsx)(xn,{content:t}),r]})}function Cn(e){let t=0,n=0;for(let r of e)t+=r.linesAdded,n+=r.linesRemoved;return{added:t,removed:n}}function wn({count:e,totals:t,open:n,onToggle:r,ref:i}){let a=`${e} file${e===1?``:`s`}`;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`mx-1.5 h-3.5 w-px bg-border-soft`}),(0,$.jsxs)(`button`,{ref:i,type:`button`,onClick:r,"aria-expanded":n,"aria-label":`${a} changed this turn, ${t.added} added, ${t.removed} removed`,className:N(`inline-flex items-center gap-[7px] rounded-full font-mono text-[11.5px]`,`px-3 min-h-11 md:min-h-0 md:px-[9px] md:py-[5px]`,`text-text-secondary transition-colors hover:bg-surface hover:text-text-primary`),children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`size-[5px] shrink-0 rounded-full bg-primary`}),(0,$.jsx)(`span`,{children:a}),(0,$.jsxs)(`span`,{className:`flex items-center gap-[5px] tabular-nums`,children:[(0,$.jsxs)(`span`,{className:`text-success`,children:[`+`,t.added]}),(0,$.jsxs)(`span`,{className:`text-error`,children:[`−`,t.removed]})]})]})]})}function Tn(e){if(!e)return!1;let t=e.closest(`[data-tab-pool-id]`)?.dataset.tabPoolId;if(!t)return e.offsetParent!==null;let{panels:n,focusedPanelId:r}=F.getState();return n[r]?.activeTabId===t}var En={create:{glyph:`A`,cls:`text-success`,label:`created`},write:{glyph:`W`,cls:`text-warning`,label:`overwritten`},notebook:{glyph:`N`,cls:`text-accent-2`,label:`notebook edited`},edit:{glyph:`·`,cls:`text-text-subtle`,label:`edited`}};function Dn(e){let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`));return t<0?{base:e,dir:``}:{base:e.slice(t+1),dir:e.slice(0,t)}}function On({added:e,removed:t,editCount:n,className:r}){return(0,$.jsxs)(`span`,{className:N(`flex items-center gap-[5px] tabular-nums`,r),children:[(0,$.jsxs)(`span`,{className:`text-success`,children:[`+`,e]}),(0,$.jsxs)(`span`,{className:`text-error`,children:[`−`,t]}),n!=null&&n>1&&(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[`×`,n]})]})}function kn({change:e,dense:t,selected:n,onClick:r}){let i=En[e.op],{base:a,dir:o}=Dn(e.filePath),s=e.viaSubagent?`${i.label} · changed by a sub-agent`:i.label;return(0,$.jsxs)(`button`,{type:`button`,onClick:r,title:e.filePath,className:N(`grid w-full grid-cols-[16px_1fr_auto_10px] items-center gap-[10px] text-left font-mono`,`border-b border-border-soft hover:bg-surface transition-colors`,t?`min-h-[38px] px-2.5 py-[5px] text-xs`:`min-h-[52px] px-3 py-[7px] text-[12.5px]`,n&&`bg-surface shadow-[inset_2px_0_0_var(--accent)]`),children:[(0,$.jsx)(`span`,{"aria-label":s,title:s,className:N(`inline-flex size-4 items-center justify-center rounded bg-white/5 text-[9px] font-semibold`,i.cls,e.viaSubagent&&`bg-accent-2/20 ring-1 ring-inset ring-accent-2/35`),children:i.glyph}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block truncate text-text-primary`,children:a}),o&&(0,$.jsx)(`span`,{className:`block overflow-hidden text-ellipsis whitespace-nowrap text-[10px] text-text-subtle [direction:rtl] text-left`,children:o})]}),(0,$.jsx)(On,{added:e.linesAdded,removed:e.linesRemoved,editCount:e.editCount,className:`text-[11px]`}),(0,$.jsx)(c,{className:`size-[11px] text-text-subtle`})]})}var An=(0,Q.lazy)(()=>j(()=>import(`./edit-diff-preview-DfX-9om9.js`),__vite__mapDeps([0,1,2,3])));function jn({change:e,onJump:t}){return(0,$.jsx)(`div`,{children:e.edits.map((n,r)=>(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`button`,{type:`button`,disabled:!n.editRef,onClick:()=>n.editRef&&t(n.editRef),className:`group flex min-h-11 w-full items-center gap-2 px-3 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface disabled:hover:bg-transparent`,children:[(0,$.jsxs)(`span`,{children:[`edit `,r+1,` of `,e.editCount]}),(0,$.jsx)(`span`,{className:`h-px flex-1 bg-border-soft`}),n.editRef&&(0,$.jsxs)(`span`,{className:`flex items-center gap-1 group-hover:text-primary`,children:[(0,$.jsx)(Fe,{className:`size-3`}),`jump`]})]}),(0,$.jsx)(`div`,{className:`mx-3 mb-1`,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`h-4`}),children:(0,$.jsx)(An,{oldStr:n.oldStr,newStr:n.newStr,filePath:e.filePath})})})]},n.editRef??r))})}function Mn(e){let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`));return t<0?{base:e,dir:``}:{base:e.slice(t+1),dir:e.slice(0,t)}}var Nn=null;function Pn(e){return e instanceof HTMLElement?e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.isContentEditable:!1}function Fn({changes:e,onJump:t,onClose:n}){let[r,i]=(0,Q.useState)(0),a=(0,Q.useRef)(null),o=(0,Q.useRef)(null),s=(0,Q.useId)();(0,Q.useEffect)(()=>(Nn=s,o.current?.querySelector(`button`)?.focus(),()=>{Nn===s&&(Nn=null)}),[s]),(0,Q.useEffect)(()=>{let o=o=>{if(Nn===s&&Tn(a.current)&&!Pn(document.activeElement)){if(o.key===`Escape`)o.preventDefault(),n();else if(o.key===`j`)o.preventDefault(),i(t=>Math.min(t+1,e.length-1));else if(o.key===`k`)o.preventDefault(),i(e=>Math.max(e-1,0));else if(o.key===`Enter`){let n=e[r]?.edits[0]?.editRef;n&&(o.preventDefault(),t(n))}}};return window.addEventListener(`keydown`,o),()=>window.removeEventListener(`keydown`,o)},[s,e,r,t,n]);let c=e[Math.min(r,e.length-1)];if(!c)return null;let{base:l,dir:u}=Mn(c.filePath);return(0,$.jsx)(`div`,{ref:a,className:`mt-0.5 overflow-hidden rounded-[10px] border border-border-soft bg-bg`,children:(0,$.jsxs)(`div`,{className:`grid h-[356px] grid-cols-[294px_1fr] grid-rows-[minmax(0,1fr)] bg-surface-elevated`,children:[(0,$.jsxs)(`div`,{ref:o,className:`min-h-0 overflow-y-auto border-r border-border-soft`,children:[e.map((e,t)=>(0,$.jsx)(kn,{change:e,dense:!0,selected:t===r,onClick:()=>i(t)},e.filePath)),(0,$.jsx)(`p`,{className:`px-2.5 pt-2 pb-2.5 font-mono text-[10px] text-text-subtle`,children:`j / k to move · enter to jump`})]}),(0,$.jsxs)(`div`,{className:`min-h-0 overflow-y-auto`,children:[(0,$.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b border-border-soft bg-surface-elevated py-[5px] pl-2.5 pr-2`,children:[(0,$.jsx)(`span`,{className:`shrink-0 font-mono text-xs font-medium text-text-primary`,children:l}),u&&(0,$.jsx)(`span`,{title:c.filePath,className:`min-w-0 flex-1 overflow-hidden text-ellipsis whitespace-nowrap font-mono text-[10.5px] text-text-subtle [direction:rtl] text-left`,children:u}),(0,$.jsx)(On,{added:c.linesAdded,removed:c.linesRemoved,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void je(c.filePath),className:`shrink-0 rounded-md px-1.5 py-1 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:`copy path`}),(0,$.jsx)(`button`,{type:`button`,onClick:n,"aria-label":`Close change tray`,className:`inline-flex size-8 shrink-0 items-center justify-center rounded-lg text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:(0,$.jsx)(ne,{className:`size-3.5`})})]}),(0,$.jsx)(jn,{change:c,onJump:t})]})]})})}function In(e){let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`));return t<0?e:e.slice(t+1)}function Ln({label:e,onClick:t,children:n}){return(0,$.jsx)(`button`,{type:`button`,onClick:t,"aria-label":e,className:`inline-flex size-11 shrink-0 items-center justify-center rounded-lg text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:n})}function Rn({changes:e,totals:t,open:n,onClose:r,onJump:i}){let[a,o]=(0,Q.useState)(null),s=a==null?null:e[a],c=(0,Q.useRef)(null),l=()=>{o(null),r()},u=e=>{l(),i(e)};return(0,Q.useEffect)(()=>{if(!n)return;let e=c.current,t=()=>Array.from(e?.querySelectorAll(`button:not([disabled])`)??[]);t()[0]?.focus();let r=e=>{if(e.key===`Escape`){e.preventDefault(),l();return}if(e.key!==`Tab`)return;let n=t();if(n.length===0)return;let r=n[0],i=n[n.length-1];e.shiftKey&&document.activeElement===r?(e.preventDefault(),i.focus()):!e.shiftKey&&document.activeElement===i&&(e.preventDefault(),r.focus())};return window.addEventListener(`keydown`,r),()=>window.removeEventListener(`keydown`,r)},[n,a]),(0,$.jsx)(I,{open:n,onClose:l,className:`flex max-h-[85%] flex-col rounded-t-[14px] motion-reduce:animate-none`,children:(0,$.jsx)(`div`,{ref:c,className:`flex min-h-0 flex-1 flex-col`,children:s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border-soft px-1 pb-1`,children:[(0,$.jsx)(Ln,{label:`Back to file list`,onClick:()=>o(null),children:(0,$.jsx)(We,{className:`size-4`})}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs font-medium text-text-primary`,children:In(s.filePath)}),(0,$.jsx)(On,{added:s.linesAdded,removed:s.linesRemoved,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(Ln,{label:`Close`,onClick:l,children:(0,$.jsx)(ne,{className:`size-4`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border-soft py-1.5 pl-3 pr-2`,children:[(0,$.jsx)(`span`,{title:s.filePath,className:`min-w-0 flex-1 overflow-hidden text-ellipsis whitespace-nowrap font-mono text-[10.5px] text-text-subtle [direction:rtl] text-left`,children:s.filePath}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void je(s.filePath),className:`inline-flex min-h-11 shrink-0 items-center rounded-md px-2.5 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:`copy`}),s.edits[0]?.editRef&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(s.edits[0].editRef),className:`inline-flex min-h-11 shrink-0 items-center gap-1 rounded-md px-2.5 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface hover:text-primary`,children:[(0,$.jsx)(Fe,{className:`size-3`}),`card`]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,$.jsx)(jn,{change:s,onJump:u})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border-soft px-3 pb-2`,children:[(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs font-medium text-text-primary`,children:[`Changed this turn · `,e.length,` file`,e.length===1?``:`s`]}),(0,$.jsx)(On,{added:t.added,removed:t.removed,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(Ln,{label:`Close`,onClick:l,children:(0,$.jsx)(ne,{className:`size-4`})})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:e.map((e,t)=>(0,$.jsx)(kn,{change:e,onClick:()=>o(t)},e.filePath))})]})})})}function zn({timestamp:e,content:t,changes:n,onJumpToEdit:r}){let[i,a]=(0,Q.useState)(!1),s=o(),c=(0,Q.useRef)(null),l=()=>{a(!1),c.current?.focus()},u=(0,$.jsx)(Sn,{timestamp:e,content:t,className:`-mt-1.5`,children:n&&n.length>0&&(0,$.jsx)(wn,{ref:c,count:n.length,totals:Cn(n),open:i,onToggle:()=>i?l():a(!0)})});return!n||n.length===0?u:(0,$.jsxs)($.Fragment,{children:[u,s?(0,$.jsx)(Rn,{changes:n,totals:Cn(n),open:i,onClose:l,onJump:r??(()=>{})}):i&&(0,$.jsx)(Fn,{changes:n,onJump:e=>{a(!1),r?.(e)},onClose:l})]})}function Bn(e){return e.inputTokens+e.cacheReadTokens+e.cacheWriteTokens}function Vn(e){return e.inputTokens+e.cacheWriteTokens}var Hn=.5,Un=.9,Wn={cache_expired:`the session's prompt cache had already lapsed, so PPM released its subprocess`,idle_timeout:`the session sat idle with no tab open long enough for PPM to release its subprocess`,warm_idle_cap:`too many idle sessions were holding a subprocess, so this one was released early`,tab_closed:`PPM shut the session's subprocess down when the last tab disconnected`,set_model:`the model was changed, which restarts the session`,stream_ended:`the session's subprocess had already exited`,resume:`the session was resumed on a new subprocess`};function Gn(e){let t=Vn(e),n=Bn(e);if(!e.coldStart||n<2e4)return{level:`ok`,wastedTokens:t,reason:``};let r=e.cacheHitRate<Hn?`bad`:e.cacheHitRate<Un?`warn`:`ok`;if(r===`ok`)return{level:r,wastedTokens:t,reason:``};let i=e.coldReason?Wn[e.coldReason]??`the session restarted (${e.coldReason})`:null;return{level:r,wastedTokens:t,reason:i?`${Yn(t)} of this session's transcript was re-sent uncached because ${i}.`:`${Yn(t)} of this session's transcript was re-sent uncached.`}}var Kn=.1,qn=1.25;function Jn(e){let t=Bn(e);if(t===0)return 1;let n=e.inputTokens+e.cacheWriteTokens*qn+e.cacheReadTokens*Kn,r=t*Kn;return r>0?Math.max(1,n/r):1}function Yn(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(e>=1e4?0:1)}k`:String(e)}function Xn({usage:e}){let[t,n]=(0,Q.useState)(!1),r=Gn(e);if(r.level===`ok`)return null;let i=Jn(e),a=Bn(e),o=Math.round(e.cacheHitRate*100),c=r.level===`bad`;return(0,$.jsxs)(`div`,{className:`rounded-md border px-2.5 py-2 text-[11px] ${c?`border-warning/40 bg-warning/10`:`border-border bg-surface`}`,children:[(0,$.jsxs)(`button`,{onClick:()=>n(e=>!e),"aria-expanded":t,className:`flex w-full items-start gap-2 py-1 text-left text-text-secondary transition-colors hover:text-text-primary`,children:[(0,$.jsx)(st,{className:`mt-px size-3.5 shrink-0 ${c?`text-warning`:`text-text-subtle`}`}),(0,$.jsxs)(`span`,{className:`flex-1`,children:[`Costly turn — `,o,`% of a `,Yn(a),`-token transcript came from cache, so it cost about`,` `,(0,$.jsxs)(`strong`,{className:`font-semibold`,children:[i.toFixed(1),`x`]}),` a fully cached turn.`]}),(0,$.jsx)(s,{className:`mt-px size-3.5 shrink-0 transition-transform ${t?`rotate-180`:``}`})]}),t&&(0,$.jsxs)(`div`,{className:`mt-2 flex flex-col gap-2 border-t border-border pt-2`,children:[r.reason&&(0,$.jsx)(`p`,{className:`text-text-secondary`,children:r.reason}),(0,$.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-1 font-mono text-[10.5px] text-text-subtle`,children:[(0,$.jsx)(Zn,{label:`From cache`,value:`${Yn(e.cacheReadTokens)} (${o}%)`}),(0,$.jsx)(Zn,{label:`Written to cache`,value:Yn(e.cacheWriteTokens)}),(0,$.jsx)(Zn,{label:`Fresh input`,value:Yn(e.inputTokens)}),(0,$.jsx)(Zn,{label:`Output`,value:Yn(e.outputTokens)}),(0,$.jsx)(Zn,{label:`Model`,value:e.model||`unknown`}),(0,$.jsx)(Zn,{label:`Cost`,value:`$${e.costUsd.toFixed(4)}`})]}),(0,$.jsx)(`p`,{className:`text-text-subtle`,children:`A turn stays cached while the session keeps running. Closing the last tab of an idle session, switching model, or a retry all restart it, and the next turn re-sends the transcript at full price.`})]})]})}function Zn({label:e,value:t}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`dt`,{className:`truncate`,children:e}),(0,$.jsx)(`dd`,{className:`truncate text-right text-text-secondary`,children:t})]})}function Qn(e,t,n,r){let[i,a]=(0,Q.useState)([]),o=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(!n||!e||!t){a([]);return}let r=!1;return o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{k.get(`/api/project/${encodeURIComponent(e)}/chat/sessions/${encodeURIComponent(t)}/tasks`).then(e=>{r||a(e)}).catch(()=>{})},300),()=>{r=!0,o.current&&clearTimeout(o.current)}},[e,t,n,r]),i}var $n=new Set([`TaskCreate`,`TaskUpdate`,`TaskStop`]);function er(e){let t=0;for(let n of e)if(n.events)for(let e of n.events)e.type===`tool_use`&&$n.has(e.tool)&&t++;return t}var tr={completed:{icon:`✓`,cls:`text-success`},in_progress:{icon:`▶`,cls:`text-warning`},stopped:{icon:`■`,cls:`text-text-subtle`},pending:{icon:`○`,cls:`text-text-subtle`}};function nr({projectName:e,sessionId:t,messages:n}){let r=(0,Q.useMemo)(()=>er(n),[n]),i=Qn(e,t,r>0,r),[a,o]=(0,Q.useState)(!0);if(i.length===0||i.every(e=>e.status===`completed`||e.status===`stopped`))return null;let l=i.filter(e=>e.status===`completed`).length,u=i.length,d=u?Math.round(l/u*100):0;return(0,$.jsxs)(`div`,{className:`shrink-0 border-b border-border bg-surface/60 backdrop-blur-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`flex items-center gap-2 w-full px-3 min-h-11 text-left text-xs hover:bg-surface transition-colors`,children:[a?(0,$.jsx)(c,{className:`size-3.5 shrink-0`}):(0,$.jsx)(s,{className:`size-3.5 shrink-0`}),(0,$.jsx)(f,{className:`size-3.5 shrink-0 text-text-secondary`}),(0,$.jsx)(`span`,{className:`text-text-primary font-medium`,children:`Tasks`}),(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[l,`/`,u,` done`]}),(0,$.jsx)(`span`,{className:`ml-auto h-1 w-16 rounded-full bg-border overflow-hidden shrink-0`,children:(0,$.jsx)(`span`,{className:`block h-full bg-success/70`,style:{width:`${d}%`}})})]}),!a&&(0,$.jsx)(`ul`,{className:`px-3 pb-2 space-y-0.5 max-h-48 overflow-y-auto`,children:i.map(e=>(0,$.jsx)(rr,{task:e},e.id))})]})}function rr({task:e}){let t=tr[e.status]??tr.pending,n=e.status===`in_progress`;return(0,$.jsxs)(`li`,{className:`flex items-start gap-1.5 text-xs rounded px-1 ${n?`bg-warning/10`:``}`,children:[(0,$.jsx)(`span`,{className:`shrink-0 mt-0.5 ${t.cls}`,children:t.icon}),(0,$.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:n?`text-text-primary font-medium`:`text-text-secondary`,children:e.subject||(0,$.jsxs)(`span`,{className:`text-text-subtle italic`,children:[`#`,e.id,` (no title)`]})})]})}var ir=/read the full transcript at:\s*(\S+\.jsonl)/i;function ar(e){return e.match(ir)?.[1]?.trim()??null}var or=class extends Q.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?this.props.fallback?this.props.fallback:this.props.fallbackContent?(0,$.jsx)(`div`,{className:`text-sm whitespace-pre-wrap break-words text-text-primary opacity-80`,children:this.props.fallbackContent}):null:this.props.children}};function sr({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)(tt,{projectName:e,onSelectSession:t,className:`w-full px-4`})]})}var cr=3200,lr=1e3,ur={hasAbove:!1,atBottom:!0,idx:0,total:0};function dr({scrollElement:e,userIndices:t,scrollToBottom:n}){let r=o(),[i,a]=(0,Q.useState)(ur),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(0),f=(0,Q.useRef)(cr),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(!c)return;let e=setTimeout(()=>l(!1),f.current);return()=>clearTimeout(e)},[c,i.idx,u]),(0,Q.useEffect)(()=>{if(!c||!g.current)return;g.current=!1;let e=p.current;(e?.querySelector(`button:not(:disabled)`)??e)?.focus()},[c]),(0,Q.useEffect)(()=>{c||!h.current||(h.current=!1,m.current?.focus())},[c]);let y=(0,Q.useCallback)(()=>{f.current=cr,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=>()=>{Tn(t)&&(e(),f.current=lr,l(!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=N(`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:c?(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`&&l(!1)},children:[(0,$.jsx)(`button`,{type:`button`,onClick:b,disabled:!i.hasAbove,"aria-label":`Jump to previous message`,className:C,children:(0,$.jsx)(Je,{className:`size-[15px]`})}),(0,$.jsx)(`span`,{className:`font-mono text-[10px] font-medium text-text-subtle text-center py-px`,"aria-label":`Message ${i.idx||1} of ${i.total}`,children:i.total?`${i.idx||1}/${i.total}`:`0/0`}),(0,$.jsx)(`button`,{type:`button`,onClick:x,disabled:i.atBottom,"aria-label":`Jump to next message`,className:C,children:(0,$.jsx)(s,{className:`size-[15px]`})}),(0,$.jsx)(`button`,{type:`button`,onClick:S,disabled:i.atBottom,"aria-label":`Jump to latest`,className:C,children:(0,$.jsx)(yt,{className:`size-[13px]`})})]}):(0,$.jsx)(`button`,{ref:m,type:`button`,onClick:()=>{f.current=cr,g.current=!0,l(!0)},"aria-label":`Navigate messages`,"aria-expanded":!1,title:`Navigate messages`,className:N(`group flex items-center justify-center`,r?`size-11`:`size-[30px]`),children:(0,$.jsx)(`span`,{className:N(`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)(Qe,{className:`size-[15px]`})})})})}function fr({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)(We,{className:`size-3.5`})}),(0,$.jsxs)(`span`,{className:`tabular-nums`,children:[i+1,`/`,r.length]}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>a(i+1),disabled:n||i>=r.length-1,"aria-label":`Next version`,className:`flex items-center justify-center rounded p-0.5 hover:text-text-primary disabled:opacity-30 disabled:cursor-default`,children:(0,$.jsx)(c,{className:`size-3.5`})})]})}function pr(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 mr(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 hr({questions:e,onSubmit:t,onSkip:n}){let r=(0,Q.useRef)(null),i=pr(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=mr({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 gr={"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 _r(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:gr[e]??e.replace(/^antml:/,``).replace(/-/g,` `),content:r[2].trim()})}return{cleanText:e.replace(n,``).trim(),tags:t}}function vr(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 yr(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 br(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 xr(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 Sr(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 Cr(e){let{idePath:t,cleanText:n}=br(e),{blocks:r,remainingText:i}=Sr(n),a=xr(i),{cleanText:o,tags:s}=_r(a.text.replace(/<local-command-(?:stdout|stderr)>([\s\S]*?)<\/local-command-(?:stdout|stderr)>/g,`$1`)),{command:c,cleanText:l}=vr(o),{agent:u,cleanText:d}=yr(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 wr(e){let{agent:t,body:n,command:r}=Cr(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 Tr=j(()=>import(`./markdown-renderer-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/edit-diff-preview-DfX-9om9.js","assets/rolldown-runtime-FhOqtrmT.js","assets/vendor-markdown-Ls5AcU91.js","assets/libesm-tR4XlhMj.js","assets/markdown-renderer-2asl-3Kk.js","assets/vendor-mermaid-C977xNeE.js","assets/vendor-ui-CaeeFO0B.js","assets/markdown-renderer-B4uL6GVA.js","assets/index-wd3FSHHn.js","assets/dialog-CkI7rwrh.js","assets/utils-B9H0d3Fh.js","assets/createLucideIcon-D8pyde1A.js","assets/x-B1qHmLdR.js","assets/eye-off-CUdzgmX8.js","assets/bot-nk1k3ELu.js","assets/context-menu-q-RHHAWz.js","assets/chevron-right-BLOtX8Vy.js","assets/use-is-mobile-DnFSkUG2.js","assets/clock-D493FU_D.js","assets/sparkles-n1hzh65o.js","assets/copy-BApI9v7Z.js","assets/database-B9okYLx6.js","assets/plus-9LatwJMx.js","assets/api-client-rTAGdEKo.js","assets/react-w6wINGnd.js","assets/mobile-bottom-sheet-BQt45q9T.js","assets/api-settings-CAhcNpj5.js","assets/project-store-DyaEpHVG.js","assets/panel-store-s6Qx49RK.js","assets/settings-store-ChqHdT2V.js","assets/tab-store-C42sktPo.js","assets/apply-theme-CMQXnUAa.js","assets/resolve-theme-DdB7Yo5Z.js","assets/index-D-xwjNyX.css","assets/image-gallery-BWFpZAAP.js","assets/api-client-CaRE4HYh.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./createLucideIcon-D8pyde1A.js";import{t as i}from"./bot-nk1k3ELu.js";import{d as a}from"./context-menu-q-RHHAWz.js";import{n as o,r as s}from"./use-is-mobile-DnFSkUG2.js";import{t as c}from"./chevron-right-BLOtX8Vy.js";import{a as l,i as u,n as d,r as f,t as p}from"./tool-cards-DNgw1yI6.js";import{a as m,c as h,i as g,n as _,o as v,r as y,t as b,u as x}from"./dialog-CkI7rwrh.js";import{t as S}from"./clock-D493FU_D.js";import{t as C}from"./code-CLF5x7KK.js";import{t as w}from"./sparkles-n1hzh65o.js";import{t as T}from"./copy-BApI9v7Z.js";import{n as E,r as ee,t as te}from"./plus-9LatwJMx.js";import{t as D}from"./shield-off-DULFtyLS.js";import{t as ne}from"./x-B1qHmLdR.js";import{i as O,n as k,r as A,s as re}from"./api-client-rTAGdEKo.js";import{q as j}from"./vendor-mermaid-C977xNeE.js";import{t as M}from"./settings-store-ChqHdT2V.js";import{n as N,r as ie,t as P}from"./utils-B9H0d3Fh.js";import{t as F}from"./panel-store-s6Qx49RK.js";import{i as ae}from"./project-store-DyaEpHVG.js";import{t as oe}from"./tab-store-C42sktPo.js";import{t as I}from"./mobile-bottom-sheet-BQt45q9T.js";import{_ as L,a as se,c as R,h as z,i as B,l as ce,m as le,o as V,p as H,r as U,s as W,t as G,u as K}from"./api-settings-CAhcNpj5.js";import{An as q,B as ue,Bn as de,Cn as J,D as fe,Dn as pe,En as me,Fn as Y,G as he,H as ge,Hn as X,I as _e,Jn as ve,K as ye,Kn as be,L as xe,Ln as Se,Nn as Ce,Pn as we,Qn as Te,R as Ee,Rn as De,Sn as Oe,Tn as ke,U as Ae,Ut as je,V as Me,Vn as Z,W as Ne,_r as Pe,br as Fe,dn as Ie,dr as Le,fn as Re,fr as ze,gn as Be,gr as Ve,h as He,hn as Ue,hr as We,in as Ge,jn as Ke,kn as qe,mr as Je,nn as Ye,on as Xe,pn as Ze,pr as Qe,qt as $e,r as et,rn as tt,rr as nt,sr as rt,t as it,tr as at,un as ot,vn as st,vr as ct,wn as lt,xn as ut,yn as dt,yr as ft,z as pt}from"./index-wd3FSHHn.js";import"./use-blob-url-DYtOHK7u.js";import{n as mt,r as ht,t as gt}from"./image-gallery-BWFpZAAP.js";import{t as _t}from"./libesm-tR4XlhMj.js";var vt=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`}]]),yt=r(`chevrons-down`,[[`path`,{d:`m7 6 5 5 5-5`,key:`1lc07p`}],[`path`,{d:`m7 13 5 5 5-5`,key:`1d48rs`}]]),bt=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`}]]),xt=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`}]]),St=r(`image-off`,[[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}],[`path`,{d:`M10.41 10.41a2 2 0 1 1-2.83-2.83`,key:`1bzlo9`}],[`line`,{x1:`13.5`,x2:`6`,y1:`13.5`,y2:`21`,key:`1q0aeu`}],[`line`,{x1:`18`,x2:`21`,y1:`12`,y2:`15`,key:`5mozeu`}],[`path`,{d:`M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59`,key:`mmje98`}],[`path`,{d:`M21 15V5a2 2 0 0 0-2-2H9`,key:`43el77`}]]),Ct=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`}]]),wt=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`}]]),Tt=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`}]]),Et=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`}]]),Dt=r(`slash`,[[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}]]),Q=e(t(),1);function Ot(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 kt(e,t){let n=`pc-${Ot(t)}-`;return e.map(e=>e.id?{...e,id:`${n}${e.id}`}:e)}function At(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 jt=null;function Mt(){return jt||=new AudioContext,jt}function Nt(e,t,n,r,i=`sine`){let a=Mt(),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 Pt(){let e=Mt().currentTime;Nt(523,.15,e,.15),Nt(659,.2,e+.12,.15)}function Ft(){let e=Mt().currentTime;Nt(880,.12,e,.18,`square`),Nt(698,.12,e+.15,.18,`square`),Nt(880,.15,e+.3,.15,`square`)}function It(){let e=Mt().currentTime;Nt(440,.12,e,.12),Nt(523,.12,e+.1,.12),Nt(659,.18,e+.2,.12)}var Lt={done:Pt,approval_request:Ft,question:It};function Rt(e){try{Lt[e]?.()}catch{}}var zt={hasTeams:!1,teamNames:[],messageCount:0,unreadCount:0};function Bt(e){if(document.hidden)return!1;let{panels:t}=F.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 Vt(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)({}),[f,p]=(0,Q.useState)(`idle`),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(0),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)([]),E=(0,Q.useRef)([]),[ee,te]=(0,Q.useState)(null),[D,ne]=(0,Q.useState)(null),[j,M]=(0,Q.useState)(!1),[N,ie]=(0,Q.useState)(null),[P,ae]=(0,Q.useState)(null),oe=(0,Q.useRef)(null),I=(0,Q.useRef)(null),[L,se]=(0,Q.useState)(null),R=(0,Q.useRef)(null),[z,B]=(0,Q.useState)(!0),ce=(0,Q.useRef)(null),le=(0,Q.useRef)(null),V=(0,Q.useRef)(``),H=(0,Q.useRef)([]),U=(0,Q.useRef)(new Map),W=(0,Q.useRef)(null),G=(0,Q.useRef)(`idle`),K=(0,Q.useRef)(null),q=(0,Q.useRef)(()=>{}),ue=(0,Q.useRef)(null),de=(0,Q.useRef)(!1),J=(0,Q.useRef)(new Set),fe=(0,Q.useRef)(0),pe=(0,Q.useRef)(null),me=(0,Q.useRef)(0),Y=(0,Q.useRef)(e);Y.current=e;let he=(0,Q.useRef)([]);he.current=r;let ge=(0,Q.useRef)(n);ge.current=n;let X=(0,Q.useRef)(null),_e=(0,Q.useRef)(0),ve=(0,Q.useRef)({teamNames:new Set,messages:[]}),ye=(0,Q.useRef)(0),[be,xe]=(0,Q.useState)(zt),[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=f!==`idle`;(0,Q.useEffect)(()=>{if(e)return $e.getState().setStreaming(e,f!==`idle`,n),()=>{$e.getState().setStreaming(e,!1)}},[e,f,n]);let De=(0,Q.useCallback)((e,t)=>{let n=H.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=H.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return H.current[n]={...r,children:i},!0},[]),Oe=(0,Q.useCallback)((e,t)=>{let n=e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t,r=he.current,a=-1;for(let e=r.length-1;e>=0;e--)if(r[e].events?.some(n)){a=e;break}return a===-1?!1:(i(t=>{let r=-1;for(let e=t.length-1;e>=0;e--)if(t[e].events?.some(n)){r=e;break}if(r===-1)return t;let i=t[r],a=i.events.map(t=>{if(!n(t)||t.type!==`tool_use`)return t;let r=[...t.children??[]],i=e.toolUseId,a=i?r.findIndex(t=>t.type===e.type&&t.toolUseId===i):-1;return a===-1?r.push(e):r[a]=e,{...t,children:r}});return[...t.slice(0,r),{...i,events:a},...t.slice(r+1)]}),!0)},[]),ke=(0,Q.useCallback)(()=>{_e.current=0;let e=V.current,t=[...H.current],n=W.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}]})})},[]),Ae=(0,Q.useCallback)(()=>{_e.current||=window.setTimeout(ke,100)},[ke]),je=(0,Q.useCallback)(e=>{let t=e,n=t?.type;if(!n)return;let r=e=>{let n=H.current,r=n.findIndex(e);r===-1?n.push(t):n[r]=t};switch(n){case`account_info`:W.current={accountId:t.accountId,accountLabel:t.accountLabel},te(null);break;case`account_retry`:t.accountId&&t.accountLabel&&(W.current={accountId:t.accountId,accountLabel:t.accountLabel}),H.current=[t],Ae();break;case`status_update`:{let e=t.accountLabel?` (${t.accountLabel})`:``;te(`${t.message}${e}`);break}case`text`:{let e=t.parentToolUseId;if(e&&De(t,e)){Ae();break}if(e){Oe(t,e);break}V.current+=t.content,H.current.push(t),Ae();break}case`thinking`:{let e=t.parentToolUseId;if(e&&De(t,e)){Ae();break}if(e){Oe(t,e);break}H.current.push(t),Ae();break}case`tool_use`:{if(t.tool===`AskUserQuestion`){t.toolUseId&&J.current.add(t.toolUseId);break}let e=t.parentToolUseId;if(e&&De(t,e)){Ae();break}if(e){Oe(t,e);break}let n=t.toolUseId;r(e=>!!n&&e.type===`tool_use`&&e.toolUseId===n),Ae();break}case`tool_result`:{let e=t.toolUseId;if(e&&U.current.delete(e),e&&J.current.has(e))break;let n=t.parentToolUseId;if(n&&De(t,n)){Ae();break}if(n){Oe(t,n);break}r(t=>!!e&&t.type===`tool_result`&&t.toolUseId===e),Ae();break}case`approval_resolved`:{let e=t.requestId;if(t.approved&&t.answers){let n=H.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),X.current!=null&&(re.dismiss(X.current),X.current=null);break}case`approval_request`:if(r(e=>e.type===`approval_request`&&e.requestId===t.requestId),de.current)break;if(y({requestId:t.requestId,tool:t.tool,input:t.input}),Y.current&&!Bt(Y.current)){Rt(t.tool===`AskUserQuestion`?`question`:`approval_request`);let e=Y.current,n=t.tool===`AskUserQuestion`;X.current=re[n?`info`:`warning`](n?`AI has a question`:`${t.tool} needs permission`,{description:ge.current||`Session ${e.slice(0,8)}`,duration:1/0,action:{label:`Go to session`,onClick:()=>{let{panels:t}=F.getState();for(let[n,r]of Object.entries(t)){let t=r.tabs.find(t=>t.metadata?.sessionId===e);if(t){F.getState().setActiveTab(t.id,n);break}}}}})}break;case`error`:i(e=>{let n=e[e.length-1];if(n?.role===`assistant`){let r=H.current,i=r[r.length-1],a=i?.type===`error`&&i.message===t.message?r:[...r,t];return H.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),k.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=U.current.get(e);n?(n.content+=t.content,n.content.length>5e5&&(n.content=n.content.slice(-5e5)),n.lineCount=t.lineCount):U.current.set(e,{content:t.content,lineCount:t.lineCount}),Ae()}break}case`background_registry`:{let e=t.shells??[];E.current=e,T(e);break}case`done`:{if(G.current===`idle`)break;t.contextWindowPct!=null&&x(t.contextWindowPct),Y.current&&!Bt(Y.current)&&Rt(`done`),_e.current&&=(clearTimeout(_e.current),0);let e=V.current,n=[...H.current],r=W.current,a=t.lastMessageUuid,o=t.usage;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},...o&&{usage:o}}]:e||n.length>0?[...t,{id:`final-${Date.now()}`,role:`assistant`,content:e,events:n,timestamp:new Date().toISOString(),...a&&{sdkUuid:a},...o&&{usage:o},...r}]:t}),V.current=``,H.current=[],W.current=null,pe.current=null,U.current.clear(),te(null);break}}},[De,Oe,Ae]),Me=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`user_message`){let e=t.content;i(n=>{let r=n[n.length-1];return r?.role===`user`&&r.content===e?n:[...n,{id:`user-remote-${Date.now()}`,role:`user`,content:e,timestamp:t.timestamp??new Date().toISOString()}]});return}if(t.type===`title_updated`){ne(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;p(e),G.current=e,_(e===`connecting`?t.elapsed??0:0),e===`idle`&&C(null);return}if(t.type===`session_state`){M(!0),ie(t.sessionId??Y.current);let e=t,n=e.phase,r=G.current===`idle`;if(p(n),G.current=n,e.sessionTitle&&ne(e.sessionTitle),e.model&&(I.current&&e.model!==I.current||(e.model===I.current&&(I.current=null),ae(e.model),oe.current=e.model)),typeof e.effort==`string`&&(se(e.effort),R.current=e.effort),typeof e.thinking==`boolean`&&B(e.thinking),e.pendingApproval&&y({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),C(e.compactStatus===`compacting`?`compacting`:null),n===`idle`){let e=Date.now()-me.current<5e3;r&&e||ue.current?.(),h(!1)}return}if(t.type===`turn_events`){let e=t.events,n=t.userMessage;if(!e?.length&&!n){h(!1);return}fe.current&&=(cancelAnimationFrame(fe.current),0),pe.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}),V.current=``,H.current=[],W.current=null,de.current=!0;let r=0,a=()=>{let t=Math.min(r+100,e.length);for(let n=r;n<t;n++)je(e[n]);r=t,r<e.length?fe.current=requestAnimationFrame(a):(fe.current=0,de.current=!1,h(!1))};fe.current=requestAnimationFrame(a);return}je(t)}},[je]),{send:Z,connect:Ne}=d({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:Me,autoConnect:!!e&&!!n});q.current=Z,(0,Q.useEffect)(()=>{let r=!1;le.current&&le.current!==e&&(I.current=null,ce.current=null),le.current=e??null,p(`idle`),G.current=`idle`,y(null),X.current!=null&&(re.dismiss(X.current),X.current=null),C(null),o(new Map),u({}),V.current=``,H.current=[],pe.current=null,me.current=0,U.current.clear(),_e.current&&=(clearTimeout(_e.current),0),M(!1),ie(null),ve.current={teamNames:new Set,messages:[]},ye.current=0,xe(zt),Ce([]);let a=new Set(he.current.map(e=>e.id));return e&&n?(c(!0),k.get(`${O(n)}/chat/sessions/${e}/messages?providerId=${t}`).then(e=>{if(r)return;let t=Array.isArray(e)?{messages:e,versionMap:{}}:e,n=Array.isArray(t?.messages)?t.messages:[];t?.versionMap&&u(t.versionMap);let o=pe.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]}),me.current=Date.now()}).catch(()=>{r||i(e=>e.filter(e=>!a.has(e.id)))}).finally(()=>{r||c(!1)})):i([]),()=>{r=!0}},[e,t,n]);let Pe=(0,Q.useCallback)((e,t)=>{if(!e.trim())return;let n=G.current!==`idle`;if(n){_e.current&&=(clearTimeout(_e.current),0);let e=V.current,t=[...H.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()}]),V.current=``,H.current=[],K.current=null,n?(p(`thinking`),G.current=`thinking`):(p(`initializing`),G.current=`initializing`),y(null),X.current!=null&&(re.dismiss(X.current),X.current=null),Z(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode,priority:t?.priority,images:t?.images,...oe.current&&{model:oe.current},...R.current&&{effort:R.current},...ce.current!==null&&{thinking:ce.current}}))},[Z]),Fe=(0,Q.useCallback)(e=>{ae(e),oe.current=e,I.current=e,Z(JSON.stringify({type:`set_model`,model:e}))},[Z]),Ie=(0,Q.useCallback)(e=>{se(e),R.current=e,Z(JSON.stringify({type:`set_effort`,effort:e}))},[Z]),Le=(0,Q.useCallback)(e=>{B(e),ce.current=e,Z(JSON.stringify({type:`set_thinking`,enabled:e}))},[Z]),Re=(0,Q.useCallback)((e,t,n)=>{if(Z(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=H.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),X.current!=null&&(re.dismiss(X.current),X.current=null)},[Z]),ze=(0,Q.useCallback)(()=>{if(G.current===`idle`)return;Z(JSON.stringify({type:`cancel`}));let e=V.current,t=[...H.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}),V.current=``,H.current=[],U.current.clear(),K.current=null,p(`idle`),G.current=`idle`,y(null),X.current!=null&&(re.dismiss(X.current),X.current=null)},[Z]),Be=(0,Q.useCallback)(e=>{e&&Z(JSON.stringify({type:`kill_background_shell`,shellId:e}))},[Z]),Ve=(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&&it.getState().setSessionShells(e,w)},[e,w]),(0,Q.useEffect)(()=>{if(e)return it.getState().retainSession(e),()=>{it.getState().releaseSession(e)}},[e]);let He=(0,Q.useCallback)(()=>{M(!1),h(!0),Ne()},[Ne]),Ue=(0,Q.useCallback)(()=>{!e||!n||fetch(`${O(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${A()}`}}).then(e=>e.json()).then(e=>{if(G.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),V.current=``,H.current=[]),me.current=Date.now()}).catch(()=>{})},[e,t,n]);ue.current=Ue;let We=(0,Q.useCallback)(async(e,t)=>{if(!n)throw Error(`No project context available`);let r=e.replace(/^pc-[^-]+-/,``),i=`${O(n)}/chat/pre-compact-messages?jsonlPath=${encodeURIComponent(t)}&before=${encodeURIComponent(r)}`,a=kt(await k.get(i),t);return o(t=>{let n=new Map(t);return n.set(e,a),n}),a.length},[n]),Ge=(0,Q.useCallback)(e=>a.has(e),[a]),Ke=(0,Q.useCallback)(e=>{i(t=>t.filter(t=>t.id!==e))},[]),qe=(0,Q.useCallback)(()=>{i(e=>e.filter(e=>e.role!==`system`))},[]);return{messages:r,renderedMessages:(0,Q.useMemo)(()=>At(r,a),[r,a]),expandCompact:We,isCompactExpanded:Ge,dismissMessage:Ke,clearErrors:qe,messagesLoading:s,versionMap:l,isStreaming:Ee,phase:f,isReconnecting:m,connectingElapsed:g,pendingApproval:v,contextWindowPct:b,compactStatus:S,statusMessage:ee,sessionTitle:D,model:P,setModel:Fe,effort:L,setEffort:Ie,thinking:z,setThinking:Le,teamActivity:be,teamMessages:Se,markTeamRead:Te,bashPartialOutput:U,backgroundShells:w,killBackgroundShell:Be,findBackgroundShellByOutput:Ve,sendMessage:Pe,respondToApproval:Re,cancelStreaming:ze,reconnect:He,refetchMessages:Ue,isConnected:j&&N===e}}var Ht=12e4;function Ut(e,t=`claude`,n){let[r,i]=(0,Q.useState)({}),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),l=(0,Q.useRef)(null),u=(0,Q.useCallback)((r=!1)=>{if(!e)return;o(!0);let a=r?`&refresh=1`:``,s=n?`&session=${encodeURIComponent(n)}`:``;k.get(`${O(e)}/chat/usage?providerId=${t}${s}${a}`).then(e=>{e&&(i(t=>({...t,...e})),e.lastFetchedAt&&c(e.lastFetchedAt))}).catch(()=>{}).finally(()=>o(!1))},[e,t,n]);return(0,Q.useEffect)(()=>(u(),l.current=setInterval(()=>u(),Ht),()=>{l.current&&clearInterval(l.current)}),[u]),{usageInfo:r,usageLoading:a,lastFetchedAt:s,refreshUsage:(0,Q.useCallback)(()=>u(!0),[u])}}var Wt={damping:.7,stiffness:.05,mass:1.25},Gt=70,Kt=1e3/60,qt=350,Jt=!1;globalThis.document?.addEventListener(`mousedown`,()=>{Jt=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{Jt=!1}),globalThis.document?.addEventListener(`click`,()=>{Jt=!1});var Yt=(e={})=>{let[t,n]=(0,Q.useState)(!1),[r,i]=(0,Q.useState)(e.initial!==!1),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null);s.current=e;let c=(0,Q.useCallback)(()=>{if(!Jt)return!1;let e=window.getSelection();if(!e||!e.rangeCount)return!1;let t=e.getRangeAt(0);return t.commonAncestorContainer.contains(g.current)||g.current?.contains(t.commonAncestorContainer)},[]),l=(0,Q.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,Q.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,Q.useMemo)(()=>{let n;return{escapedFromLock:t,isAtBottom:r,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return g.current?.scrollTop??0},set scrollTop(e){if(g.current){let{scrollBehavior:t}=getComputedStyle(g.current);t!==`auto`&&(g.current.style.scrollBehavior=`auto`),g.current.scrollTop=e,d.ignoreScrollToTop=g.current.scrollTop,t!==`auto`&&(g.current.style.scrollBehavior=t)}},get targetScrollTop(){return!g.current||!_.current?0:g.current.scrollHeight-1-g.current.clientHeight},get calculatedTargetScrollTop(){if(!g.current||!_.current)return 0;let{targetScrollTop:t}=this;if(!e.targetScrollTop)return t;if(n?.targetScrollTop===t)return n.calculatedScrollTop;let r=Math.max(Math.min(e.targetScrollTop(t,{scrollElement:g.current,contentElement:_.current}),t),0);return n={targetScrollTop:t,calculatedScrollTop:r},requestAnimationFrame(()=>{n=void 0}),r},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=Gt}}},[]),f=(0,Q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Qt(s.current,e.animation),{ignoreEscapes:r=!1}=e,i,a=d.calculatedTargetScrollTop;e.duration instanceof Promise?e.duration.finally(()=>{i=Date.now()}):i=t+(e.duration??0);let o=async()=>{let e=new Promise(requestAnimationFrame).then(()=>{if(!d.isAtBottom)return d.animation=void 0,!1;let{scrollTop:l}=d,u=performance.now(),p=(u-(d.lastTick??u))/Kt;if(d.animation||={behavior:n,promise:e,ignoreEscapes:r},d.animation.behavior===n&&(d.lastTick=u),c()||t>Date.now())return o();if(l<Math.min(a,d.calculatedTargetScrollTop)){if(d.animation?.behavior===n){if(n===`instant`)return d.scrollTop=d.calculatedTargetScrollTop,o();d.velocity=(n.damping*d.velocity+n.stiffness*d.scrollDifference)/n.mass,d.accumulated+=d.velocity*p,d.scrollTop+=d.accumulated,d.scrollTop!==l&&(d.accumulated=0)}return o()}return i>Date.now()?(a=d.calculatedTargetScrollTop,o()):(d.animation=void 0,d.scrollTop<d.calculatedTargetScrollTop?f({animation:Qt(s.current,s.current.resize),ignoreEscapes:r,duration:Math.max(0,i-Date.now())||void 0}):d.isAtBottom)});return e.then(e=>(requestAnimationFrame(()=>{d.animation||(d.lastTick=void 0,d.velocity=0)}),e))};return e.wait!==!0&&(d.animation=void 0),d.animation?.behavior===n?d.animation.promise:o()},[l,c,d]),p=(0,Q.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,Q.useCallback)(({target:e})=>{if(e!==g.current)return;let{scrollTop:t,ignoreScrollToTop:n}=d,{lastScrollTop:r=t}=d;d.lastScrollTop=t,d.ignoreScrollToTop=void 0,n&&n>t&&(r=n),o(d.isNearBottom),setTimeout(()=>{if(d.resizeDifference||t===n)return;if(c()){u(!0),l(!1);return}let e=t>r,i=t<r;if(d.animation?.ignoreEscapes){d.scrollTop=r;return}i&&(u(!0),l(!1)),e&&u(!1),!d.escapedFromLock&&d.isNearBottom&&l(!0)},1)},[u,l,c,d]),h=(0,Q.useCallback)(({target:e,deltaY:t})=>{let n=e;for(;![`scroll`,`auto`].includes(getComputedStyle(n).overflow);){if(!n.parentElement)return;n=n.parentElement}n===g.current&&t<0&&g.current.scrollHeight>g.current.clientHeight&&!d.animation?.ignoreEscapes&&(u(!0),l(!1))},[u,l,d]),g=Xt(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=Xt(e=>{if(d.resizeObserver?.disconnect(),d.resizeObserver=void 0,!e)return;let t;d.resizeObserver=new ResizeObserver(([e])=>{let{height:n}=e.contentRect,r=n-(t??n);if(d.resizeDifference=r,d.scrollTop>d.targetScrollTop&&(d.scrollTop=d.targetScrollTop),o(d.isNearBottom),r>=0){let e=Qt(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:qt})}else d.isNearBottom&&(u(!1),l(!0));t=n,requestAnimationFrame(()=>{setTimeout(()=>{d.resizeDifference===r&&(d.resizeDifference=0)},1)})}),d.resizeObserver?.observe(e)},[]);return{contentRef:_,scrollRef:g,scrollToBottom:f,stopScroll:p,isAtBottom:r||a,isNearBottom:a,escapedFromLock:t,state:d}};function Xt(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Zt=new Map;function Qt(...e){let t={...Wt},n=!1;for(let r of e){if(r===`instant`){n=!0;continue}typeof r==`object`&&(n=!1,t.damping=r.damping??t.damping,t.stiffness=r.stiffness??t.stiffness,t.mass=r.mass??t.mass)}let r=JSON.stringify(t);return Zt.has(r)||Zt.set(r,Object.freeze(t)),n?`instant`:Zt.get(r)}var $t=60,en=8,tn=1400;function nn(e){if(e.scrollHeight<=e.clientHeight)return!1;let t=getComputedStyle(e).overflowY;return t===`auto`||t===`scroll`}function rn(e,t){let n=[],r=e.parentElement;for(;r&&r!==t;)nn(r)&&n.push(r),r=r.parentElement;return n}function an(){return typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches}function on(e,t){let n=e.querySelector(`[data-edit-ref="${CSS.escape(t)}"]`);if(n)return{el:n,level:`edit`};let r=t.replace(/-\d+$/,``),i=e.querySelector(`[data-tool-ref="${CSS.escape(r)}"]`);return i?{el:i,level:`card`}:null}function sn(e,t,n,r){let i=e.scrollTop+t.getBoundingClientRect().top-e.getBoundingClientRect().top-n;e.scrollTo({top:i,behavior:r?`smooth`:`auto`})}function cn(e,t){let n=on(e,t);if(!n)return()=>{};let{el:r,level:i}=n;for(let t of rn(r,e))sn(t,r,en,!1);sn(e,r,$t,!an()),r.dataset.flash=i;let a=setTimeout(()=>{delete r.dataset.flash},tn);return()=>{clearTimeout(a),delete r.dataset.flash}}var ln=new Set([`Write`,`Edit`,`MultiEdit`,`NotebookEdit`]),un={create:3,write:2,notebook:2,edit:1};function dn(e){return typeof e==`string`?e:``}function fn(e,t){let n=0,r=0;for(let i of _t(e,t))i.added?n+=i.count??0:i.removed&&(r+=i.count??0);return{added:n,removed:r}}function pn(e){return e&&/created successfully/i.test(e)?`create`:`write`}function mn(e,t,n){switch(e){case`Write`:{let e=dn(t.file_path);return e?{filePath:e,op:pn(n),fragments:[{oldStr:``,newStr:dn(t.content)}]}:null}case`Edit`:{let e=dn(t.file_path);return e?{filePath:e,op:`edit`,fragments:[{oldStr:dn(t.old_string),newStr:dn(t.new_string)}]}:null}case`MultiEdit`:{let e=dn(t.file_path);if(!e||!Array.isArray(t.edits))return null;let n=t.edits.filter(e=>!!e&&typeof e==`object`).map(e=>({oldStr:dn(e.old_string),newStr:dn(e.new_string)}));return n.length===0?null:{filePath:e,op:`edit`,fragments:n}}case`NotebookEdit`:{let e=dn(t.notebook_path)||dn(t.file_path);return e?{filePath:e,op:`notebook`,fragments:[{oldStr:``,newStr:dn(t.new_source)}]}:null}default:return null}}function hn(e,t){if(e){for(let n of e)if(n.type===`tool_result`&&n.toolUseId&&t.set(n.toolUseId,n.output??``),n.type===`tool_use`){let e=n.result;n.toolUseId&&e?.output!=null&&!t.has(n.toolUseId)&&t.set(n.toolUseId,e.output),hn(n.children,t)}}}function gn(e,t,n,r){if(e)for(let i of e){if(i.type!==`tool_use`||(i.children?.length&&gn(i.children,!0,n,r),!ln.has(i.tool)))continue;let e=i.input&&typeof i.input==`object`?i.input:null;if(!e)continue;let a=mn(i.tool,e,i.toolUseId?r.get(i.toolUseId):void 0);if(!a)continue;let o=n.get(a.filePath);o||(o={filePath:a.filePath,op:a.op,editCount:0,linesAdded:0,linesRemoved:0,edits:[],viaSubagent:!1},n.set(a.filePath,o)),un[a.op]>un[o.op]&&(o.op=a.op),t&&(o.viaSubagent=!0),a.fragments.forEach((e,n)=>{let{added:r,removed:a}=fn(e.oldStr,e.newStr);o.linesAdded+=r,o.linesRemoved+=a,o.editCount+=1,o.edits.push({...e,toolUseId:i.toolUseId,editIndex:n,editRef:i.toolUseId?`${i.toolUseId}-${n}`:void 0,viaSubagent:t})})}}function _n(e){let t=new Map;for(let n of e)hn(n.events,t);let n=new Map;for(let r of e)gn(r.events,!1,n,t);return[...n.values()]}function vn(e,t){let n=[];for(let r=t;r>=0&&e[r]?.role===`assistant`;r--)n.unshift(e[r]);return n}var $=n();function yn(e){try{return new Date(e).toLocaleString()}catch{return``}}function bn({icon:e,label:t,title:n,onClick:r}){return(0,$.jsxs)(`button`,{type:`button`,onClick:r,title:n,"aria-label":t,className:`inline-flex items-center justify-center gap-1 rounded-md px-1.5 py-1 text-text-subtle hover:text-text-primary hover:bg-surface transition-colors`,children:[e,(0,$.jsx)(`span`,{children:t})]})}function xn({content:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsx)(bn,{icon:t?(0,$.jsx)(a,{className:`size-3.5`}):(0,$.jsx)(T,{className:`size-3.5`}),label:t?`Copied`:`Copy`,title:`Copy message to clipboard`,onClick:()=>{je(e),n(!0),setTimeout(()=>n(!1),1500)}})}function Sn({timestamp:e,content:t,className:n,children:r}){return(0,$.jsxs)(`div`,{className:N(`flex items-center gap-0.5 flex-wrap text-xs text-text-subtle select-none`,n),children:[(0,$.jsx)(`time`,{title:yn(e),className:`pr-1 tabular-nums`,children:Re(e)}),(0,$.jsx)(xn,{content:t}),r]})}function Cn(e){let t=0,n=0;for(let r of e)t+=r.linesAdded,n+=r.linesRemoved;return{added:t,removed:n}}function wn({count:e,totals:t,open:n,onToggle:r,ref:i}){let a=`${e} file${e===1?``:`s`}`;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`mx-1.5 h-3.5 w-px bg-border-soft`}),(0,$.jsxs)(`button`,{ref:i,type:`button`,onClick:r,"aria-expanded":n,"aria-label":`${a} changed this turn, ${t.added} added, ${t.removed} removed`,className:N(`inline-flex items-center gap-[7px] rounded-full font-mono text-[11.5px]`,`px-3 min-h-11 md:min-h-0 md:px-[9px] md:py-[5px]`,`text-text-secondary transition-colors hover:bg-surface hover:text-text-primary`),children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`size-[5px] shrink-0 rounded-full bg-primary`}),(0,$.jsx)(`span`,{children:a}),(0,$.jsxs)(`span`,{className:`flex items-center gap-[5px] tabular-nums`,children:[(0,$.jsxs)(`span`,{className:`text-success`,children:[`+`,t.added]}),(0,$.jsxs)(`span`,{className:`text-error`,children:[`−`,t.removed]})]})]})]})}function Tn(e){if(!e)return!1;let t=e.closest(`[data-tab-pool-id]`)?.dataset.tabPoolId;if(!t)return e.offsetParent!==null;let{panels:n,focusedPanelId:r}=F.getState();return n[r]?.activeTabId===t}var En={create:{glyph:`A`,cls:`text-success`,label:`created`},write:{glyph:`W`,cls:`text-warning`,label:`overwritten`},notebook:{glyph:`N`,cls:`text-accent-2`,label:`notebook edited`},edit:{glyph:`·`,cls:`text-text-subtle`,label:`edited`}};function Dn(e){let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`));return t<0?{base:e,dir:``}:{base:e.slice(t+1),dir:e.slice(0,t)}}function On({added:e,removed:t,editCount:n,className:r}){return(0,$.jsxs)(`span`,{className:N(`flex items-center gap-[5px] tabular-nums`,r),children:[(0,$.jsxs)(`span`,{className:`text-success`,children:[`+`,e]}),(0,$.jsxs)(`span`,{className:`text-error`,children:[`−`,t]}),n!=null&&n>1&&(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[`×`,n]})]})}function kn({change:e,dense:t,selected:n,onClick:r}){let i=En[e.op],{base:a,dir:o}=Dn(e.filePath),s=e.viaSubagent?`${i.label} · changed by a sub-agent`:i.label;return(0,$.jsxs)(`button`,{type:`button`,onClick:r,title:e.filePath,className:N(`grid w-full grid-cols-[16px_1fr_auto_10px] items-center gap-[10px] text-left font-mono`,`border-b border-border-soft hover:bg-surface transition-colors`,t?`min-h-[38px] px-2.5 py-[5px] text-xs`:`min-h-[52px] px-3 py-[7px] text-[12.5px]`,n&&`bg-surface shadow-[inset_2px_0_0_var(--accent)]`),children:[(0,$.jsx)(`span`,{"aria-label":s,title:s,className:N(`inline-flex size-4 items-center justify-center rounded bg-white/5 text-[9px] font-semibold`,i.cls,e.viaSubagent&&`bg-accent-2/20 ring-1 ring-inset ring-accent-2/35`),children:i.glyph}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block truncate text-text-primary`,children:a}),o&&(0,$.jsx)(`span`,{className:`block overflow-hidden text-ellipsis whitespace-nowrap text-[10px] text-text-subtle [direction:rtl] text-left`,children:o})]}),(0,$.jsx)(On,{added:e.linesAdded,removed:e.linesRemoved,editCount:e.editCount,className:`text-[11px]`}),(0,$.jsx)(c,{className:`size-[11px] text-text-subtle`})]})}var An=(0,Q.lazy)(()=>j(()=>import(`./edit-diff-preview-DfX-9om9.js`),__vite__mapDeps([0,1,2,3])));function jn({change:e,onJump:t}){return(0,$.jsx)(`div`,{children:e.edits.map((n,r)=>(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`button`,{type:`button`,disabled:!n.editRef,onClick:()=>n.editRef&&t(n.editRef),className:`group flex min-h-11 w-full items-center gap-2 px-3 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface disabled:hover:bg-transparent`,children:[(0,$.jsxs)(`span`,{children:[`edit `,r+1,` of `,e.editCount]}),(0,$.jsx)(`span`,{className:`h-px flex-1 bg-border-soft`}),n.editRef&&(0,$.jsxs)(`span`,{className:`flex items-center gap-1 group-hover:text-primary`,children:[(0,$.jsx)(Fe,{className:`size-3`}),`jump`]})]}),(0,$.jsx)(`div`,{className:`mx-3 mb-1`,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`h-4`}),children:(0,$.jsx)(An,{oldStr:n.oldStr,newStr:n.newStr,filePath:e.filePath})})})]},n.editRef??r))})}function Mn(e){let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`));return t<0?{base:e,dir:``}:{base:e.slice(t+1),dir:e.slice(0,t)}}var Nn=null;function Pn(e){return e instanceof HTMLElement?e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.isContentEditable:!1}function Fn({changes:e,onJump:t,onClose:n}){let[r,i]=(0,Q.useState)(0),a=(0,Q.useRef)(null),o=(0,Q.useRef)(null),s=(0,Q.useId)();(0,Q.useEffect)(()=>(Nn=s,o.current?.querySelector(`button`)?.focus(),()=>{Nn===s&&(Nn=null)}),[s]),(0,Q.useEffect)(()=>{let o=o=>{if(Nn===s&&Tn(a.current)&&!Pn(document.activeElement)){if(o.key===`Escape`)o.preventDefault(),n();else if(o.key===`j`)o.preventDefault(),i(t=>Math.min(t+1,e.length-1));else if(o.key===`k`)o.preventDefault(),i(e=>Math.max(e-1,0));else if(o.key===`Enter`){let n=e[r]?.edits[0]?.editRef;n&&(o.preventDefault(),t(n))}}};return window.addEventListener(`keydown`,o),()=>window.removeEventListener(`keydown`,o)},[s,e,r,t,n]);let c=e[Math.min(r,e.length-1)];if(!c)return null;let{base:l,dir:u}=Mn(c.filePath);return(0,$.jsx)(`div`,{ref:a,className:`mt-0.5 overflow-hidden rounded-[10px] border border-border-soft bg-bg`,children:(0,$.jsxs)(`div`,{className:`grid h-[356px] grid-cols-[294px_1fr] grid-rows-[minmax(0,1fr)] bg-surface-elevated`,children:[(0,$.jsxs)(`div`,{ref:o,className:`min-h-0 overflow-y-auto border-r border-border-soft`,children:[e.map((e,t)=>(0,$.jsx)(kn,{change:e,dense:!0,selected:t===r,onClick:()=>i(t)},e.filePath)),(0,$.jsx)(`p`,{className:`px-2.5 pt-2 pb-2.5 font-mono text-[10px] text-text-subtle`,children:`j / k to move · enter to jump`})]}),(0,$.jsxs)(`div`,{className:`min-h-0 overflow-y-auto`,children:[(0,$.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b border-border-soft bg-surface-elevated py-[5px] pl-2.5 pr-2`,children:[(0,$.jsx)(`span`,{className:`shrink-0 font-mono text-xs font-medium text-text-primary`,children:l}),u&&(0,$.jsx)(`span`,{title:c.filePath,className:`min-w-0 flex-1 overflow-hidden text-ellipsis whitespace-nowrap font-mono text-[10.5px] text-text-subtle [direction:rtl] text-left`,children:u}),(0,$.jsx)(On,{added:c.linesAdded,removed:c.linesRemoved,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void je(c.filePath),className:`shrink-0 rounded-md px-1.5 py-1 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:`copy path`}),(0,$.jsx)(`button`,{type:`button`,onClick:n,"aria-label":`Close change tray`,className:`inline-flex size-8 shrink-0 items-center justify-center rounded-lg text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:(0,$.jsx)(ne,{className:`size-3.5`})})]}),(0,$.jsx)(jn,{change:c,onJump:t})]})]})})}function In(e){let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`));return t<0?e:e.slice(t+1)}function Ln({label:e,onClick:t,children:n}){return(0,$.jsx)(`button`,{type:`button`,onClick:t,"aria-label":e,className:`inline-flex size-11 shrink-0 items-center justify-center rounded-lg text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:n})}function Rn({changes:e,totals:t,open:n,onClose:r,onJump:i}){let[a,o]=(0,Q.useState)(null),s=a==null?null:e[a],c=(0,Q.useRef)(null),l=()=>{o(null),r()},u=e=>{l(),i(e)};return(0,Q.useEffect)(()=>{if(!n)return;let e=c.current,t=()=>Array.from(e?.querySelectorAll(`button:not([disabled])`)??[]);t()[0]?.focus();let r=e=>{if(e.key===`Escape`){e.preventDefault(),l();return}if(e.key!==`Tab`)return;let n=t();if(n.length===0)return;let r=n[0],i=n[n.length-1];e.shiftKey&&document.activeElement===r?(e.preventDefault(),i.focus()):!e.shiftKey&&document.activeElement===i&&(e.preventDefault(),r.focus())};return window.addEventListener(`keydown`,r),()=>window.removeEventListener(`keydown`,r)},[n,a]),(0,$.jsx)(I,{open:n,onClose:l,className:`flex max-h-[85%] flex-col rounded-t-[14px] motion-reduce:animate-none`,children:(0,$.jsx)(`div`,{ref:c,className:`flex min-h-0 flex-1 flex-col`,children:s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border-soft px-1 pb-1`,children:[(0,$.jsx)(Ln,{label:`Back to file list`,onClick:()=>o(null),children:(0,$.jsx)(We,{className:`size-4`})}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs font-medium text-text-primary`,children:In(s.filePath)}),(0,$.jsx)(On,{added:s.linesAdded,removed:s.linesRemoved,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(Ln,{label:`Close`,onClick:l,children:(0,$.jsx)(ne,{className:`size-4`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border-soft py-1.5 pl-3 pr-2`,children:[(0,$.jsx)(`span`,{title:s.filePath,className:`min-w-0 flex-1 overflow-hidden text-ellipsis whitespace-nowrap font-mono text-[10.5px] text-text-subtle [direction:rtl] text-left`,children:s.filePath}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void je(s.filePath),className:`inline-flex min-h-11 shrink-0 items-center rounded-md px-2.5 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:`copy`}),s.edits[0]?.editRef&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>u(s.edits[0].editRef),className:`inline-flex min-h-11 shrink-0 items-center gap-1 rounded-md px-2.5 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface hover:text-primary`,children:[(0,$.jsx)(Fe,{className:`size-3`}),`card`]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,$.jsx)(jn,{change:s,onJump:u})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border-soft px-3 pb-2`,children:[(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs font-medium text-text-primary`,children:[`Changed this turn · `,e.length,` file`,e.length===1?``:`s`]}),(0,$.jsx)(On,{added:t.added,removed:t.removed,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(Ln,{label:`Close`,onClick:l,children:(0,$.jsx)(ne,{className:`size-4`})})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:e.map((e,t)=>(0,$.jsx)(kn,{change:e,onClick:()=>o(t)},e.filePath))})]})})})}function zn({timestamp:e,content:t,changes:n,onJumpToEdit:r}){let[i,a]=(0,Q.useState)(!1),s=o(),c=(0,Q.useRef)(null),l=()=>{a(!1),c.current?.focus()},u=(0,$.jsx)(Sn,{timestamp:e,content:t,className:`-mt-1.5`,children:n&&n.length>0&&(0,$.jsx)(wn,{ref:c,count:n.length,totals:Cn(n),open:i,onToggle:()=>i?l():a(!0)})});return!n||n.length===0?u:(0,$.jsxs)($.Fragment,{children:[u,s?(0,$.jsx)(Rn,{changes:n,totals:Cn(n),open:i,onClose:l,onJump:r??(()=>{})}):i&&(0,$.jsx)(Fn,{changes:n,onJump:e=>{a(!1),r?.(e)},onClose:l})]})}function Bn(e){return e.inputTokens+e.cacheReadTokens+e.cacheWriteTokens}function Vn(e){return e.inputTokens+e.cacheWriteTokens}var Hn=.5,Un=.9,Wn={cache_expired:`the session's prompt cache had already lapsed, so PPM released its subprocess`,idle_timeout:`the session sat idle with no tab open long enough for PPM to release its subprocess`,warm_idle_cap:`too many idle sessions were holding a subprocess, so this one was released early`,tab_closed:`PPM shut the session's subprocess down when the last tab disconnected`,set_model:`the model was changed, which restarts the session`,stream_ended:`the session's subprocess had already exited`,resume:`the session was resumed on a new subprocess`};function Gn(e){let t=Vn(e),n=Bn(e);if(!e.coldStart||n<2e4)return{level:`ok`,wastedTokens:t,reason:``};let r=e.cacheHitRate<Hn?`bad`:e.cacheHitRate<Un?`warn`:`ok`;if(r===`ok`)return{level:r,wastedTokens:t,reason:``};let i=e.coldReason?Wn[e.coldReason]??`the session restarted (${e.coldReason})`:null;return{level:r,wastedTokens:t,reason:i?`${Yn(t)} of this session's transcript was re-sent uncached because ${i}.`:`${Yn(t)} of this session's transcript was re-sent uncached.`}}var Kn=.1,qn=1.25;function Jn(e){let t=Bn(e);if(t===0)return 1;let n=e.inputTokens+e.cacheWriteTokens*qn+e.cacheReadTokens*Kn,r=t*Kn;return r>0?Math.max(1,n/r):1}function Yn(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(e>=1e4?0:1)}k`:String(e)}function Xn({usage:e}){let[t,n]=(0,Q.useState)(!1),r=Gn(e);if(r.level===`ok`)return null;let i=Jn(e),a=Bn(e),o=Math.round(e.cacheHitRate*100),c=r.level===`bad`;return(0,$.jsxs)(`div`,{className:`rounded-md border px-2.5 py-2 text-[11px] ${c?`border-warning/40 bg-warning/10`:`border-border bg-surface`}`,children:[(0,$.jsxs)(`button`,{onClick:()=>n(e=>!e),"aria-expanded":t,className:`flex w-full items-start gap-2 py-1 text-left text-text-secondary transition-colors hover:text-text-primary`,children:[(0,$.jsx)(st,{className:`mt-px size-3.5 shrink-0 ${c?`text-warning`:`text-text-subtle`}`}),(0,$.jsxs)(`span`,{className:`flex-1`,children:[`Costly turn — `,o,`% of a `,Yn(a),`-token transcript came from cache, so it cost about`,` `,(0,$.jsxs)(`strong`,{className:`font-semibold`,children:[i.toFixed(1),`x`]}),` a fully cached turn.`]}),(0,$.jsx)(s,{className:`mt-px size-3.5 shrink-0 transition-transform ${t?`rotate-180`:``}`})]}),t&&(0,$.jsxs)(`div`,{className:`mt-2 flex flex-col gap-2 border-t border-border pt-2`,children:[r.reason&&(0,$.jsx)(`p`,{className:`text-text-secondary`,children:r.reason}),(0,$.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-1 font-mono text-[10.5px] text-text-subtle`,children:[(0,$.jsx)(Zn,{label:`From cache`,value:`${Yn(e.cacheReadTokens)} (${o}%)`}),(0,$.jsx)(Zn,{label:`Written to cache`,value:Yn(e.cacheWriteTokens)}),(0,$.jsx)(Zn,{label:`Fresh input`,value:Yn(e.inputTokens)}),(0,$.jsx)(Zn,{label:`Output`,value:Yn(e.outputTokens)}),(0,$.jsx)(Zn,{label:`Model`,value:e.model||`unknown`}),(0,$.jsx)(Zn,{label:`Cost`,value:`$${e.costUsd.toFixed(4)}`})]}),(0,$.jsx)(`p`,{className:`text-text-subtle`,children:`A turn stays cached while the session keeps running. Closing the last tab of an idle session, switching model, or a retry all restart it, and the next turn re-sends the transcript at full price.`})]})]})}function Zn({label:e,value:t}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`dt`,{className:`truncate`,children:e}),(0,$.jsx)(`dd`,{className:`truncate text-right text-text-secondary`,children:t})]})}function Qn(e,t,n,r){let[i,a]=(0,Q.useState)([]),o=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(!n||!e||!t){a([]);return}let r=!1;return o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{k.get(`/api/project/${encodeURIComponent(e)}/chat/sessions/${encodeURIComponent(t)}/tasks`).then(e=>{r||a(e)}).catch(()=>{})},300),()=>{r=!0,o.current&&clearTimeout(o.current)}},[e,t,n,r]),i}var $n=new Set([`TaskCreate`,`TaskUpdate`,`TaskStop`]);function er(e){let t=0;for(let n of e)if(n.events)for(let e of n.events)e.type===`tool_use`&&$n.has(e.tool)&&t++;return t}var tr={completed:{icon:`✓`,cls:`text-success`},in_progress:{icon:`▶`,cls:`text-warning`},stopped:{icon:`■`,cls:`text-text-subtle`},pending:{icon:`○`,cls:`text-text-subtle`}};function nr({projectName:e,sessionId:t,messages:n}){let r=(0,Q.useMemo)(()=>er(n),[n]),i=Qn(e,t,r>0,r),[a,o]=(0,Q.useState)(!0);if(i.length===0||i.every(e=>e.status===`completed`||e.status===`stopped`))return null;let l=i.filter(e=>e.status===`completed`).length,u=i.length,d=u?Math.round(l/u*100):0;return(0,$.jsxs)(`div`,{className:`shrink-0 border-b border-border bg-surface/60 backdrop-blur-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`flex items-center gap-2 w-full px-3 min-h-11 text-left text-xs hover:bg-surface transition-colors`,children:[a?(0,$.jsx)(c,{className:`size-3.5 shrink-0`}):(0,$.jsx)(s,{className:`size-3.5 shrink-0`}),(0,$.jsx)(f,{className:`size-3.5 shrink-0 text-text-secondary`}),(0,$.jsx)(`span`,{className:`text-text-primary font-medium`,children:`Tasks`}),(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[l,`/`,u,` done`]}),(0,$.jsx)(`span`,{className:`ml-auto h-1 w-16 rounded-full bg-border overflow-hidden shrink-0`,children:(0,$.jsx)(`span`,{className:`block h-full bg-success/70`,style:{width:`${d}%`}})})]}),!a&&(0,$.jsx)(`ul`,{className:`px-3 pb-2 space-y-0.5 max-h-48 overflow-y-auto`,children:i.map(e=>(0,$.jsx)(rr,{task:e},e.id))})]})}function rr({task:e}){let t=tr[e.status]??tr.pending,n=e.status===`in_progress`;return(0,$.jsxs)(`li`,{className:`flex items-start gap-1.5 text-xs rounded px-1 ${n?`bg-warning/10`:``}`,children:[(0,$.jsx)(`span`,{className:`shrink-0 mt-0.5 ${t.cls}`,children:t.icon}),(0,$.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:n?`text-text-primary font-medium`:`text-text-secondary`,children:e.subject||(0,$.jsxs)(`span`,{className:`text-text-subtle italic`,children:[`#`,e.id,` (no title)`]})})]})}var ir=/read the full transcript at:\s*(\S+\.jsonl)/i;function ar(e){return e.match(ir)?.[1]?.trim()??null}var or=class extends Q.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?this.props.fallback?this.props.fallback:this.props.fallbackContent?(0,$.jsx)(`div`,{className:`text-sm whitespace-pre-wrap break-words text-text-primary opacity-80`,children:this.props.fallbackContent}):null:this.props.children}};function sr({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)(tt,{projectName:e,onSelectSession:t,className:`w-full px-4`})]})}var cr=3200,lr=1e3,ur={hasAbove:!1,atBottom:!0,idx:0,total:0};function dr({scrollElement:e,userIndices:t,scrollToBottom:n}){let r=o(),[i,a]=(0,Q.useState)(ur),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(0),f=(0,Q.useRef)(cr),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(!c)return;let e=setTimeout(()=>l(!1),f.current);return()=>clearTimeout(e)},[c,i.idx,u]),(0,Q.useEffect)(()=>{if(!c||!g.current)return;g.current=!1;let e=p.current;(e?.querySelector(`button:not(:disabled)`)??e)?.focus()},[c]),(0,Q.useEffect)(()=>{c||!h.current||(h.current=!1,m.current?.focus())},[c]);let y=(0,Q.useCallback)(()=>{f.current=cr,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=>()=>{Tn(t)&&(e(),f.current=lr,l(!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=N(`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:c?(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`&&l(!1)},children:[(0,$.jsx)(`button`,{type:`button`,onClick:b,disabled:!i.hasAbove,"aria-label":`Jump to previous message`,className:C,children:(0,$.jsx)(Je,{className:`size-[15px]`})}),(0,$.jsx)(`span`,{className:`font-mono text-[10px] font-medium text-text-subtle text-center py-px`,"aria-label":`Message ${i.idx||1} of ${i.total}`,children:i.total?`${i.idx||1}/${i.total}`:`0/0`}),(0,$.jsx)(`button`,{type:`button`,onClick:x,disabled:i.atBottom,"aria-label":`Jump to next message`,className:C,children:(0,$.jsx)(s,{className:`size-[15px]`})}),(0,$.jsx)(`button`,{type:`button`,onClick:S,disabled:i.atBottom,"aria-label":`Jump to latest`,className:C,children:(0,$.jsx)(yt,{className:`size-[13px]`})})]}):(0,$.jsx)(`button`,{ref:m,type:`button`,onClick:()=>{f.current=cr,g.current=!0,l(!0)},"aria-label":`Navigate messages`,"aria-expanded":!1,title:`Navigate messages`,className:N(`group flex items-center justify-center`,r?`size-11`:`size-[30px]`),children:(0,$.jsx)(`span`,{className:N(`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)(Qe,{className:`size-[15px]`})})})})}function fr({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)(We,{className:`size-3.5`})}),(0,$.jsxs)(`span`,{className:`tabular-nums`,children:[i+1,`/`,r.length]}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>a(i+1),disabled:n||i>=r.length-1,"aria-label":`Next version`,className:`flex items-center justify-center rounded p-0.5 hover:text-text-primary disabled:opacity-30 disabled:cursor-default`,children:(0,$.jsx)(c,{className:`size-3.5`})})]})}function pr(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 mr(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 hr({questions:e,onSubmit:t,onSkip:n}){let r=(0,Q.useRef)(null),i=pr(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=mr({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 gr={"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 _r(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:gr[e]??e.replace(/^antml:/,``).replace(/-/g,` `),content:r[2].trim()})}return{cleanText:e.replace(n,``).trim(),tags:t}}function vr(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 yr(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 br(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 xr(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 Sr(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 Cr(e){let{idePath:t,cleanText:n}=br(e),{blocks:r,remainingText:i}=Sr(n),a=xr(i),{cleanText:o,tags:s}=_r(a.text.replace(/<local-command-(?:stdout|stderr)>([\s\S]*?)<\/local-command-(?:stdout|stderr)>/g,`$1`)),{command:c,cleanText:l}=vr(o),{agent:u,cleanText:d}=yr(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 wr(e){let{agent:t,body:n,command:r}=Cr(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 Tr=j(()=>import(`./markdown-renderer-2asl-3Kk.js`),__vite__mapDeps([4,5,1,6,2,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34])),Er=(0,Q.lazy)(()=>Tr.then(e=>({default:e.MarkdownRenderer})));function Dr({messages:e,messagesLoading:t,keepStaleWhileLoading:n,pendingApproval:r,onApprovalResponse:a,isStreaming:o,phase:s,onSelectSession:c,connectingElapsed:u,statusMessage:d,compactStatus:f,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:te,stopScroll:D,isAtBottom:ne}=Yt({initial:`instant`,resize:`instant`}),O=(0,Q.useMemo)(()=>e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return e.role===`user`?t:t||n}),[e]),k=!!r||o,[A,re]=(0,Q.useState)(null),j=(0,Q.useCallback)(e=>{E(e),re(e)},[E]),M=(0,Q.useRef)(new Map),N=(0,Q.useMemo)(()=>{let e=M.current,t=new Map;for(let n=0;n<O.length;n++){let r=O[n];if(r.role!==`assistant`||O[n+1]?.role===`assistant`)continue;let i=`${r.id}:${r.events?.length??0}`,a=e.get(i);a||(a=_n(vn(O,n)),e.set(i,a)),a.length>0&&t.set(n,a)}return t},[O]),ie=(0,Q.useRef)(null),P=(0,Q.useCallback)(e=>{A&&(ie.current?.(),ie.current=cn(A,e))},[A]);(0,Q.useEffect)(()=>()=>ie.current?.(),[]);let F=(0,Q.useRef)(null);(0,Q.useLayoutEffect)(()=>{let e=A;e&&F.current!=null&&(e.scrollTop=e.scrollHeight-F.current,F.current=null)},[O.length,A]),(0,Q.useLayoutEffect)(()=>{A&&te({animation:`instant`})},[_,A]);let ae=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>{A&&A.clientHeight>0&&(ae.current=ne)},[ne,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&&!ae.current&&D()});return n.observe(e),()=>n.disconnect()},[A,D]);let oe=(0,Q.useCallback)((e,t)=>{m?.(e,t)},[m]),I=(0,Q.useCallback)((e,t,n)=>{h?.(e,t,n)},[h]),L=(0,Q.useCallback)(e=>{w?.(e)},[w]),se=(0,Q.useMemo)(()=>O.reduce((e,t)=>t.role===`system`?e+1:e,0),[O]),R=(0,Q.useMemo)(()=>O.reduce((e,t,n)=>(t.role===`user`&&e.push(n),e),[]),[O]),z=(0,Q.useCallback)(()=>{if(!S||!C)return null;for(let e of O){if(C(e.id))continue;let t=ar(e.content||``);if(t)return{id:e.id,jsonlPath:t};if(e.events){for(let t of e.events)if(t.type===`text`){let n=ar(t.content||``);if(n)return{id:e.id,jsonlPath:n}}}}return null},[O,S,C])(),B=!!z,[ce,le]=(0,Q.useState)(!1),V=(0,Q.useCallback)(async()=>{if(!z||!S||ce)return;let e=A;F.current=e?e.scrollHeight-e.scrollTop:null,le(!0);try{await S(z.id,z.jsonlPath)}finally{le(!1)}},[z,S,ce,A]);return(0,Q.useEffect)(()=>{let e=A;if(!e||!B)return;let t=()=>{e.scrollTop<200&&!ce&&V()};return e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[A,B,ce,V]),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)(sr,{projectName:p||``,onSelectSession:c||(()=>{})}):(0,$.jsxs)(`div`,{className:`relative flex-1 overflow-hidden flex flex-col min-h-0`,children:[(0,$.jsx)(nr,{projectName:p,sessionId:_,messages:e}),se>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)(l,{className:`size-3.5`}),`Clear all errors (`,se,`)`]})}),ce&&(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:j,[mt]:``,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:[O.map((e,t)=>{let n=t>0?O[t-1]:void 0,r=e.role===`user`?O.slice(0,t+1).reduce((e,t)=>e+(t.role===`user`?1:0),0):0,i=r?b?.[r]:void 0,a=e.role===`user`&&g!=null&&e.id===g,s=O[t+1],c=e.role===`assistant`&&s?.role!==`assistant`,l;if(c){let e=[];for(let n=t;n>=0&&O[n].role===`assistant`;n--){let t=Or(O[n]);t&&e.unshift(t)}l=e.join(`
|
|
4
4
|
|
|
5
5
|
`)}return(0,$.jsx)(`div`,{"data-msg-index":t,className:`px-4 pt-4 select-none`,children:(0,$.jsx)(or,{fallbackContent:e.content,children:(0,$.jsx)(kr,{message:e,isStreaming:o&&e.id.startsWith(`streaming-`),isLastAssistantInTurn:c,turnCopyText:l,turnChanges:c?N.get(t):void 0,onJumpToEdit:P,projectName:p,onFork:e.role===`user`&&m?oe:void 0,onEdit:e.role===`user`&&h?I:void 0,isEditing:a,onDismiss:e.role===`system`&&w?L:void 0,prevMsgId:n?.sdkUuid??n?.id,sessionId:_,providerId:v,versionGroup:i,onNavigateVersion:y,versionNavDisabled:o,bashPartialOutput:x})})},e.id)}),k&&(0,$.jsxs)(`div`,{className:`px-4 pt-4 pb-4 space-y-4 select-none`,children:[r&&(r.tool===`AskUserQuestion`?(0,$.jsx)(ei,{approval:r,onRespond:a}):(0,$.jsx)($r,{approval:r,onRespond:a})),o&&(0,$.jsx)(Yr,{lastMessage:e[e.length-1],phase:s,elapsed:u,statusMessage:f===`compacting`?`Compacting messages...`:d})]})]})}),(0,$.jsx)(dr,{scrollElement:A,userIndices:R,scrollToBottom:te})]})}function Or(e){return e.events?.length?e.events.filter(e=>e.type===`text`).map(e=>e.content).join(``):e.content}var kr=(0,Q.memo)(function({message:e,isStreaming:t,isLastAssistantInTurn:n,turnCopyText:r,turnChanges:i,onJumpToEdit:a,projectName:o,onFork:s,onEdit:c,isEditing:u,onDismiss:d,prevMsgId:f,sessionId:p,providerId:m,versionGroup:h,onNavigateVersion:g,versionNavDisabled:_,bashPartialOutput:v}){if(e.role===`user`){let t=s?()=>s(e.content,f):void 0,n=c?()=>c(e.content,f,e.id):void 0;return(0,$.jsx)(Pr,{content:e.content,messageId:e.id,timestamp:e.timestamp,projectName:o,onFork:t,onEdit:n,isEditing:u,sessionId:p,providerId:m,versionGroup:h,onNavigateVersion:g,versionNavDisabled:_})}return e.role===`system`?(0,$.jsxs)(`div`,{className:`group flex items-center gap-2 rounded-lg bg-error/10 border border-error/20 px-3 py-2 text-sm text-error`,children:[(0,$.jsx)(ze,{className:`size-4 shrink-0`}),(0,$.jsx)(`p`,{className:`flex-1`,children:e.content}),d&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>d(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)(l,{className:`size-4`})})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.events&&e.events.length>0?(0,$.jsx)(Kr,{events:e.events,isStreaming:t,projectName:o,bashPartialOutput:v}):e.content&&(0,$.jsx)(`div`,{className:`text-sm text-text-primary select-text`,children:(0,$.jsx)(Qr,{content:e.content,projectName:o})}),!t&&n&&e.usage&&(0,$.jsx)(Xn,{usage:e.usage}),!t&&n&&(0,$.jsx)(zn,{timestamp:e.timestamp,content:r??Or(e),changes:i,onJumpToEdit:a})]})}),Ar=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]);function jr(e,t){let n=P(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function Mr(e){let t=e.lastIndexOf(`.`);return t===-1?!1:Ar.has(e.slice(t).toLowerCase())}var Nr=new Set([`task-notification`,`environment_details`,`local-command-caveat`]);function Pr({content:e,messageId:t,timestamp:n,projectName:r,onFork:a,onEdit:o,isEditing:c,sessionId:l,providerId:u,versionGroup:d,onNavigateVersion:f,versionNavDisabled:p}){let{files:m,text:h,tags:g,command:_,terminalBlocks:v,idePath:y,agent:b}=(0,Q.useMemo)(()=>Cr(e),[e]),x=g.some(e=>Nr.has(e.name)),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(!1),E=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let e=E.current;if(!e)return;let t=()=>T(e.scrollHeight>e.clientHeight+2);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[h]),(0,$.jsxs)(`div`,{className:N(`flex flex-col gap-1`,!x&&`items-end`),children:[(0,$.jsxs)(`div`,{"data-user-message":x?void 0:`true`,style:x?void 0:{borderRadius:`var(--rad) var(--rad) 4px var(--rad)`},className:N(`group/user relative px-3 py-2 text-sm border shadow-sm transition-all`,x?`rounded-lg bg-surface/40 border-border/40 text-text-secondary`:`max-w-[80%] bg-accent-wash border-accent-wash-border text-text`,c&&`ring-2 ring-primary/60 border-primary/40`),children:[g.length>0&&(0,$.jsx)(Ir,{tags:g}),b&&(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`}),b]})}),_&&(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)(Dt,{className:`size-3 shrink-0`}),_.name]})}),y&&(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)(Br,{path:y,projectName:r})]}),m.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:m.map((e,t)=>Mr(e)?(0,$.jsx)(Gr,{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)(nt,{className:`size-3 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-32`,children:P(e)})]},t))}),v.length>0&&(0,$.jsx)(`div`,{className:`space-y-1.5`,children:v.map((e,t)=>(0,$.jsx)(Fr,{content:e},t))}),h&&(0,$.jsx)(`div`,{ref:E,className:N(`whitespace-pre-wrap break-words transition-all duration-200 select-text`,!S&&`line-clamp-2`,S&&`max-h-[50vh] overflow-y-auto`),children:x?(0,$.jsx)(Hr,{text:h,projectName:r}):(0,$.jsx)(Vr,{text:h})}),(w||S)&&(0,$.jsx)(`button`,{onClick:()=>C(!S),className:N(`flex items-center gap-1 text-xs mt-1 transition-colors`,x?`text-text-subtle hover:text-text-secondary`:`text-primary/70 hover:text-primary`),children:S?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Je,{className:`size-3`}),`Show less`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(s,{className:`size-3`}),`Show more`]})}),!x&&f&&(0,$.jsx)(fr,{group:d,onNavigate:f,disabled:p})]}),!x&&(0,$.jsxs)(Sn,{timestamp:n,content:e,children:[o&&(0,$.jsx)(bn,{icon:(0,$.jsx)(Y,{className:`size-3.5`}),label:`Edit`,title:`Edit this message (continue in the same tab)`,onClick:o}),a&&(0,$.jsx)(bn,{icon:(0,$.jsx)(q,{className:`size-3.5`}),label:`Fork`,title:`Retry from this message (fork into a new tab)`,onClick:a})]})]})}function Fr({content:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),className:N(`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)(ke,{className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{children:`Terminal output`}),(0,$.jsx)(s,{className:N(`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 Ir({tags:e}){return(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,$.jsx)(Lr,{tag:e},t))})}function Lr({tag:e}){let[t,n]=(0,Q.useState)(!1);return e.name===`task-notification`?(0,$.jsx)(zr,{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)(J,{className:`size-2.5`}),(0,$.jsx)(`span`,{children:e.label}),(0,$.jsx)(c,{className:N(`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 Rr(e,t){return e.match(RegExp(`<${t}>([\\s\\S]*?)</${t}>`))?.[1]?.trim()||void 0}function zr({content:e}){let[t,n]=(0,Q.useState)(!1),r=Rr(e,`status`),i=Rr(e,`summary`),a=Rr(e,`output-file`),o=Rr(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)(Le,{className:`size-2.5 text-success`}):(0,$.jsx)(l,{className:`size-2.5 text-warning`}),(0,$.jsx)(`span`,{className:`truncate max-w-80`,children:i??`Task notification`}),(0,$.jsx)(c,{className:N(`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)(Br,{path:a}),o&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-subtle/80 max-h-60 overflow-y-auto leading-relaxed`,children:(0,$.jsx)(Qr,{content:o})})]})]})}function Br({path:e,projectName:t}){return(0,$.jsxs)(`button`,{type:`button`,onClick:(0,Q.useCallback)(()=>{let n=oe.getState().openTab,r=t??ae.getState().activeProject?.name,i=P(e),a={filePath:e};r&&(a.projectName=r),k.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)(nt,{className:`size-2.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-60`,children:P(e)}),(0,$.jsx)(rt,{className:`size-2 shrink-0 opacity-50`})]})}function Vr({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 Hr({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)(Br,{path:e.value,projectName:t},n):(0,$.jsx)(`span`,{children:e.value},n))})}var Ur=new Map;function Wr(e){let[t,n]=(0,Q.useState)(()=>Ur.get(e)?.url??null),[r,i]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{let t=Ur.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);Ur.set(e,{url:i}),n(i)}).catch(()=>{r||i(!0)}),()=>{r=!0}},[e]),{blobUrl:t,error:r}}function Gr({filePath:e,projectName:t}){let{blobUrl:n,error:r}=Wr(jr(e,t)),i=et(e=>e.open),a=P(e);return(0,$.jsxs)(`button`,{type:`button`,onClick:e=>n&&i(n,a,ht(e.currentTarget)),className:`flex items-center gap-1 rounded-md border border-border/60 bg-background/40 px-1.5 py-0.5 text-[11px] text-text-secondary hover:bg-surface transition-colors cursor-pointer`,children:[n?(0,$.jsx)(`img`,{src:n,alt:a,[gt]:``,className:`size-4 rounded-sm object-cover shrink-0`}):r?(0,$.jsx)(be,{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 Kr({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)(qr,{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)(Jr,{content:e.content,animate:r,projectName:n})},`text-${a}`)}return(0,$.jsx)(p,{tool:e.tool,result:e.result,completed:e.completed,projectName:n,bashPartialOutput:r},`tool-${a}`)})})}function qr({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)(c,{className:`size-3 transition-transform ${n?`rotate-90`:``}`}),(0,$.jsxs)(`span`,{children:[`Thinking`,t?`...`:``]}),!t&&(0,$.jsx)(`span`,{className:`text-text-subtle/50 ml-auto`,children:e.length>100?`${Math.round(e.length/4)} tokens`:``})]}),n&&(0,$.jsx)(`div`,{ref:i,className:`max-h-60 overflow-y-auto`,children:(0,$.jsx)(`div`,{className:`px-2 pb-2 text-text-subtle/80 whitespace-pre-wrap text-[11px] leading-relaxed`,children:e})})]})}function Jr({content:e,animate:t,projectName:n}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Qr,{content:e,projectName:n,isStreaming:t}),t&&(0,$.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function Yr({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 Xr=/<teammate-message[^>]*>[\s\S]*?<\/teammate-message>/g;function Zr(e){return e.replace(Xr,``).replace(/\n{3,}/g,`
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-
|
|
2
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./createLucideIcon-D8pyde1A.js";import{t as i}from"./chevron-right-BLOtX8Vy.js";import{a,c as o,i as s,n as c,o as l,t as u}from"./dialog-CkI7rwrh.js";import{t as d}from"./code-CLF5x7KK.js";import{t as f}from"./database-B9okYLx6.js";import{n as p,r as m}from"./plus-9LatwJMx.js";import{t as ee}from"./file-exclamation-point-COAwgNGw.js";import{a as h,i as te,r as ne,t as g}from"./glide-data-grid-DCJCz4XB.js";import{t as re}from"./shield-check-C5laObJv.js";import{t as ie}from"./shield-off-DULFtyLS.js";import{t as _}from"./table-CHmxuh6M.js";import{t as v}from"./x-B1qHmLdR.js";import{i as y,n as b}from"./api-client-rTAGdEKo.js";import{q as x}from"./vendor-mermaid-C977xNeE.js";import{t as ae}from"./settings-store-ChqHdT2V.js";import{t as S}from"./utils-B9H0d3Fh.js";import{t as oe}from"./panel-store-s6Qx49RK.js";import{i as C}from"./project-store-DyaEpHVG.js";import{t as w}from"./tab-store-C42sktPo.js";import{Bt as se,Hn as T,Ht as E,K as ce,Mn as le,Mt as ue,N as de,Nt as fe,P as D,Pt as O,Qn as pe,Vt as k,Wt as me,Yn as A,_n as he,ar as j,bn as ge,jn as _e,jt as ve,nn as M,nr as N,o as ye,or as be,rr as xe,sr as Se,tr as P,ur as F,zt as I}from"./index-BYetJoXQ.js";import"./data-grid-types-CUx8cusN.js";import{t as Ce}from"./use-monaco-theme-CZh7xTJZ.js";import{i as we,n as Te,r as Ee,t as De}from"./can-open-in-ppm-BzVXoV-d.js";var Oe=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 ke(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 Ae(e){return(await b.get(`/api/fs/browse?path=${encodeURIComponent(e)}`)).entries}function z({filePath:e,projectName:t,tabId:n,className:r}){let{updateTab:a,openTab:o}=w(ve(e=>({updateTab:e.updateTab,openTab:e.openTab}))),s=(0,L.useRef)(null),c=(0,L.useMemo)(()=>ke(e),[e]);(0,L.useEffect)(()=>{s.current&&(s.current.scrollLeft=s.current.scrollWidth)},[c]);let l=(0,L.useCallback)((e,r)=>{let i=S(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)(je,{segment:e,isLast:t===c.length-1,onFileClick:l})]},e.absPath))})}function je({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&&Ae(e.parentDir).then(i).catch(e=>{o(e.message||`Failed to browse`),i([])})}return(0,R.jsxs)(ue,{onOpenChange:s,children:[(0,R.jsx)(E,{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)(fe,{align:`start`,className:`max-h-[300px] overflow-y-auto p-1`,children:r===null?(0,R.jsx)(O,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a?(0,R.jsx)(O,{disabled:!0,className:`text-xs text-destructive`,children:a}):r.length===0?(0,R.jsx)(O,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):r.map(t=>(0,R.jsx)(B,{entry:t,activePath:e.absPath,onFileClick:n},t.path))})]})}function B({entry:e,activePath:t,onFileClick:n}){let r=V(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&&Ae(e.path).then(o).catch(()=>o([]))}return(0,R.jsxs)(I,{onOpenChange:s,children:[(0,R.jsxs)(k,{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)(se,{className:`max-h-[300px] overflow-y-auto p-1`,children:a===null?(0,R.jsx)(O,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a.length===0?(0,R.jsx)(O,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):a.map(e=>(0,R.jsx)(B,{entry:e,activePath:t,onFileClick:n},e.path))})]})}return(0,R.jsxs)(O,{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 Me={ts:j,tsx:j,js:j,jsx:j,py:j,rs:j,go:j,html:j,css:j,scss:j,json:be,md:xe,txt:xe,yaml:N,yml:N};function V(e,t){return t?pe:Me[e.split(`.`).pop()?.toLowerCase()??``]??P}function H(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 Ne(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function Pe({filePath:e,projectName:t,tabId:n,className:r}){let a=M(e=>e.tree),{updateTab:o,openTab:s}=w(ve(e=>({updateTab:e.updateTab,openTab:e.openTab}))),c=C(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)(()=>H(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=S(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)(z,{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)(U,{segment:e,isLast:n===p.length-1,projectName:t,onFileClick:m})]},e.fullPath))]})}function U({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=M(e=>e.loadChildren),a=M(e=>e.loadedPaths),o=(0,L.useMemo)(()=>Ne(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)(ue,{onOpenChange:c,children:[(0,R.jsx)(E,{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)(fe,{align:`start`,className:`max-h-[300px] p-1`,children:o.length===0?(0,R.jsx)(O,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):o.map(t=>(0,R.jsx)(W,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function W({node:e,projectName:t,activePath:n,onFileClick:r}){let i=V(e.name,e.type===`directory`),a=e.path===n,o=M(e=>e.loadChildren),s=M(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)(I,{onOpenChange:u,children:[(0,R.jsxs)(k,{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)(se,{className:`max-h-[300px] overflow-y-auto p-1`,children:c.length===0?(0,R.jsx)(O,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):Ne(c).map(e=>(0,R.jsx)(W,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]})}return(0,R.jsxs)(O,{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 G({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 Fe({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)(G,{active:t===`edit`,onClick:()=>n(`edit`),icon:d,label:`Edit`}),(0,R.jsx)(G,{active:t===`preview`,onClick:()=>n(`preview`),icon:p,label:`Preview`})]}),e===`csv`&&i&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(G,{active:r===`table`,onClick:()=>i(`table`),icon:_,label:`Table`}),(0,R.jsx)(G,{active:r===`raw`,onClick:()=>i(`raw`),icon:d,label:`Raw`})]}),(0,R.jsx)(G,{active:a,onClick:o,icon:ge,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)(_e,{className:`size-3 ${c?`animate-spin`:``}`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:`Refresh`})]}),l&&u&&(0,R.jsx)(G,{active:!1,onClick:()=>me(u,l),icon:m,label:`Download`})]})}var Ie=[{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 Le({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)(j,{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:Ie.map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.label},e.id))})]})}function Re({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=C(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)(D,{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)(ce,{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 K=typeof window<`u`&&window.isSecureContext,ze=[`(`,`)`,`{`,`}`,`[`,`]`,`<`,`>`,`;`,`:`,`=`,`"`,`'`,"`",`/`,`\\`,`_`,`#`],Be=`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`,Ve=`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`,He=`w-px h-5 bg-border mx-0.5 shrink-0`;function Ue({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:[!K&&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:K?s:c,className:Be,title:`Paste`,children:(0,R.jsx)(F,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:u,className:Be,title:`Undo`,children:(0,R.jsx)(he,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:d,className:Be,title:`Redo`,children:(0,R.jsx)(Oe,{size:14})}),(0,R.jsx)(`div`,{className:He}),(0,R.jsx)(`button`,{type:`button`,onClick:f,className:Ve,children:`Tab`}),(0,R.jsx)(`div`,{className:He}),ze.map(e=>(0,R.jsx)(`button`,{type:`button`,onClick:()=>r(e),className:Ve,children:e},e))]})]})}var q=(0,L.lazy)(()=>x(()=>import(`./markdown-renderer-B2D4gdok.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]))),We=(0,L.lazy)(()=>x(()=>import(`./csv-preview-BhCOjgq1.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([33,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,34,35]))),Ge=(0,L.lazy)(()=>x(()=>import(`./image-preview-CP82lor8.js`).then(e=>({default:e.ImagePreview})),__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,29,30,31,37,38]))),Ke=(0,L.lazy)(()=>x(()=>import(`./pdf-preview-BXDOe7bG.js`).then(e=>({default:e.PdfPreview})),__vite__mapDeps([39,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,37]))),qe=(0,L.lazy)(()=>x(()=>import(`./video-preview-KbRcyuAA.js`).then(e=>({default:e.VideoPreview})),__vite__mapDeps([40,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,29,30,31,37,38]))),Je=(0,L.lazy)(()=>x(()=>import(`./audio-preview-CikvnAOI.js`).then(e=>({default:e.AudioPreview})),__vite__mapDeps([41,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,29,30,31,37,38]))),Ye=(0,L.lazy)(()=>x(()=>import(`./docx-preview-C_fSjfy_.js`).then(e=>({default:e.DocxPreview})),__vite__mapDeps([42,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,37])));function Xe(e){return e.split(`.`).pop()?.toLowerCase()??``}function Ze(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`}[Xe(e)]??`plaintext`}var Qe=(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),x=(0,L.useRef)(``),C=(0,L.useRef)(null),{tabs:se,updateTab:E}=w(ve(e=>({tabs:e.tabs,updateTab:e.updateTab}))),{wordWrap:ce,toggleWordWrap:ue}=ae(ve(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),fe=Ce(),D=e?.isUntitled===!0,O=e?.unsavedContent,[pe,k]=(0,L.useState)(!1),me=se.find(e=>e.id===t),A=n?Xe(n):``,he=Te.has(A),j=A===`pdf`,ge=A===`docx`,_e=we.has(A),M=De.has(A),N=Ee.has(A),be=A===`md`||A===`mdx`,xe=A===`csv`,Se=e?.language,P=a??Se??Ze(n??``),F=P===`sql`,[I,Oe]=(0,L.useState)(`preview`),[ke,Ae]=(0,L.useState)(`table`),{connections:z,cachedTables:je,refreshTables:B,updateConnection:Me}=de(),V=n?`ppm:sql-conn:${n}`:t?`ppm:sql-conn:tab:${t}`:null,[H,Ne]=(0,L.useState)(()=>{if(!V)return null;let e=localStorage.getItem(V);return e?Number(e):null}),U=(0,L.useRef)(null),W=(0,L.useRef)(null),G=(0,L.useMemo)(()=>z.find(e=>e.id===H)??null,[z,H]),Ie=i!=null&&(a===`json`||a===`xml`),[K,ze]=(0,L.useState)(!1),Be=(0,L.useCallback)(()=>{if(i)if(K)s(i),ze(!1);else{let e=i.trimStart();if(a===`json`)try{s(JSON.stringify(JSON.parse(e),null,2)),ze(!0)}catch{}else if(a===`xml`){let t=0;s(e.replace(/(>)(<)(\/*)/g,`$1
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-2asl-3Kk.js","assets/vendor-mermaid-C977xNeE.js","assets/rolldown-runtime-FhOqtrmT.js","assets/vendor-ui-CaeeFO0B.js","assets/vendor-markdown-Ls5AcU91.js","assets/markdown-renderer-B4uL6GVA.js","assets/index-wd3FSHHn.js","assets/dialog-CkI7rwrh.js","assets/utils-B9H0d3Fh.js","assets/createLucideIcon-D8pyde1A.js","assets/x-B1qHmLdR.js","assets/eye-off-CUdzgmX8.js","assets/bot-nk1k3ELu.js","assets/context-menu-q-RHHAWz.js","assets/chevron-right-BLOtX8Vy.js","assets/use-is-mobile-DnFSkUG2.js","assets/clock-D493FU_D.js","assets/sparkles-n1hzh65o.js","assets/copy-BApI9v7Z.js","assets/database-B9okYLx6.js","assets/plus-9LatwJMx.js","assets/api-client-rTAGdEKo.js","assets/react-w6wINGnd.js","assets/mobile-bottom-sheet-BQt45q9T.js","assets/api-settings-CAhcNpj5.js","assets/project-store-DyaEpHVG.js","assets/panel-store-s6Qx49RK.js","assets/settings-store-ChqHdT2V.js","assets/tab-store-C42sktPo.js","assets/apply-theme-CMQXnUAa.js","assets/resolve-theme-DdB7Yo5Z.js","assets/index-D-xwjNyX.css","assets/image-gallery-BWFpZAAP.js","assets/csv-preview-DnaFdgOB.js","assets/lib-BFetOULu.js","assets/csv-parser-DHvoTjMF.js","assets/image-preview-KubLSLNO.js","assets/file-exclamation-point-COAwgNGw.js","assets/use-blob-url-DYtOHK7u.js","assets/pdf-preview-xZQVUtaV.js","assets/video-preview-DcUaFYyv.js","assets/audio-preview-BkNAEqcB.js","assets/docx-preview-Dd2nTW2v.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{t as r}from"./createLucideIcon-D8pyde1A.js";import{t as i}from"./chevron-right-BLOtX8Vy.js";import{a,c as o,i as s,n as c,o as l,t as u}from"./dialog-CkI7rwrh.js";import{t as d}from"./code-CLF5x7KK.js";import{t as f}from"./database-B9okYLx6.js";import{n as p,r as m}from"./plus-9LatwJMx.js";import{t as ee}from"./file-exclamation-point-COAwgNGw.js";import{a as h,i as te,r as ne,t as g}from"./glide-data-grid-QZ_fgjIa.js";import{t as re}from"./shield-check-C5laObJv.js";import{t as ie}from"./shield-off-DULFtyLS.js";import{t as _}from"./table-CHmxuh6M.js";import{t as v}from"./x-B1qHmLdR.js";import{i as y,n as b}from"./api-client-rTAGdEKo.js";import{q as x}from"./vendor-mermaid-C977xNeE.js";import{t as ae}from"./settings-store-ChqHdT2V.js";import{t as S}from"./utils-B9H0d3Fh.js";import{t as oe}from"./panel-store-s6Qx49RK.js";import{i as C}from"./project-store-DyaEpHVG.js";import{t as w}from"./tab-store-C42sktPo.js";import{Bt as se,Hn as T,Ht as E,K as ce,Mn as le,Mt as ue,N as de,Nt as fe,P as D,Pt as O,Qn as pe,Vt as k,Wt as me,Yn as A,_n as he,ar as j,bn as ge,jn as _e,jt as ve,nn as M,nr as N,o as ye,or as be,rr as xe,sr as Se,tr as P,ur as F,zt as I}from"./index-wd3FSHHn.js";import"./data-grid-types-CUx8cusN.js";import{t as Ce}from"./use-monaco-theme-DEbn-QT3.js";import{i as we,n as Te,r as Ee,t as De}from"./can-open-in-ppm-BzVXoV-d.js";var Oe=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 ke(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 Ae(e){return(await b.get(`/api/fs/browse?path=${encodeURIComponent(e)}`)).entries}function z({filePath:e,projectName:t,tabId:n,className:r}){let{updateTab:a,openTab:o}=w(ve(e=>({updateTab:e.updateTab,openTab:e.openTab}))),s=(0,L.useRef)(null),c=(0,L.useMemo)(()=>ke(e),[e]);(0,L.useEffect)(()=>{s.current&&(s.current.scrollLeft=s.current.scrollWidth)},[c]);let l=(0,L.useCallback)((e,r)=>{let i=S(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)(je,{segment:e,isLast:t===c.length-1,onFileClick:l})]},e.absPath))})}function je({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&&Ae(e.parentDir).then(i).catch(e=>{o(e.message||`Failed to browse`),i([])})}return(0,R.jsxs)(ue,{onOpenChange:s,children:[(0,R.jsx)(E,{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)(fe,{align:`start`,className:`max-h-[300px] overflow-y-auto p-1`,children:r===null?(0,R.jsx)(O,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a?(0,R.jsx)(O,{disabled:!0,className:`text-xs text-destructive`,children:a}):r.length===0?(0,R.jsx)(O,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):r.map(t=>(0,R.jsx)(B,{entry:t,activePath:e.absPath,onFileClick:n},t.path))})]})}function B({entry:e,activePath:t,onFileClick:n}){let r=V(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&&Ae(e.path).then(o).catch(()=>o([]))}return(0,R.jsxs)(I,{onOpenChange:s,children:[(0,R.jsxs)(k,{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)(se,{className:`max-h-[300px] overflow-y-auto p-1`,children:a===null?(0,R.jsx)(O,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a.length===0?(0,R.jsx)(O,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):a.map(e=>(0,R.jsx)(B,{entry:e,activePath:t,onFileClick:n},e.path))})]})}return(0,R.jsxs)(O,{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 Me={ts:j,tsx:j,js:j,jsx:j,py:j,rs:j,go:j,html:j,css:j,scss:j,json:be,md:xe,txt:xe,yaml:N,yml:N};function V(e,t){return t?pe:Me[e.split(`.`).pop()?.toLowerCase()??``]??P}function H(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 Ne(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function Pe({filePath:e,projectName:t,tabId:n,className:r}){let a=M(e=>e.tree),{updateTab:o,openTab:s}=w(ve(e=>({updateTab:e.updateTab,openTab:e.openTab}))),c=C(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)(()=>H(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=S(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)(z,{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)(U,{segment:e,isLast:n===p.length-1,projectName:t,onFileClick:m})]},e.fullPath))]})}function U({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=M(e=>e.loadChildren),a=M(e=>e.loadedPaths),o=(0,L.useMemo)(()=>Ne(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)(ue,{onOpenChange:c,children:[(0,R.jsx)(E,{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)(fe,{align:`start`,className:`max-h-[300px] p-1`,children:o.length===0?(0,R.jsx)(O,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):o.map(t=>(0,R.jsx)(W,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function W({node:e,projectName:t,activePath:n,onFileClick:r}){let i=V(e.name,e.type===`directory`),a=e.path===n,o=M(e=>e.loadChildren),s=M(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)(I,{onOpenChange:u,children:[(0,R.jsxs)(k,{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)(se,{className:`max-h-[300px] overflow-y-auto p-1`,children:c.length===0?(0,R.jsx)(O,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):Ne(c).map(e=>(0,R.jsx)(W,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]})}return(0,R.jsxs)(O,{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 G({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 Fe({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)(G,{active:t===`edit`,onClick:()=>n(`edit`),icon:d,label:`Edit`}),(0,R.jsx)(G,{active:t===`preview`,onClick:()=>n(`preview`),icon:p,label:`Preview`})]}),e===`csv`&&i&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(G,{active:r===`table`,onClick:()=>i(`table`),icon:_,label:`Table`}),(0,R.jsx)(G,{active:r===`raw`,onClick:()=>i(`raw`),icon:d,label:`Raw`})]}),(0,R.jsx)(G,{active:a,onClick:o,icon:ge,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)(_e,{className:`size-3 ${c?`animate-spin`:``}`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:`Refresh`})]}),l&&u&&(0,R.jsx)(G,{active:!1,onClick:()=>me(u,l),icon:m,label:`Download`})]})}var Ie=[{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 Le({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)(j,{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:Ie.map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.label},e.id))})]})}function Re({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=C(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)(D,{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)(ce,{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 K=typeof window<`u`&&window.isSecureContext,ze=[`(`,`)`,`{`,`}`,`[`,`]`,`<`,`>`,`;`,`:`,`=`,`"`,`'`,"`",`/`,`\\`,`_`,`#`],Be=`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`,Ve=`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`,He=`w-px h-5 bg-border mx-0.5 shrink-0`;function Ue({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:[!K&&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:K?s:c,className:Be,title:`Paste`,children:(0,R.jsx)(F,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:u,className:Be,title:`Undo`,children:(0,R.jsx)(he,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:d,className:Be,title:`Redo`,children:(0,R.jsx)(Oe,{size:14})}),(0,R.jsx)(`div`,{className:He}),(0,R.jsx)(`button`,{type:`button`,onClick:f,className:Ve,children:`Tab`}),(0,R.jsx)(`div`,{className:He}),ze.map(e=>(0,R.jsx)(`button`,{type:`button`,onClick:()=>r(e),className:Ve,children:e},e))]})]})}var q=(0,L.lazy)(()=>x(()=>import(`./markdown-renderer-2asl-3Kk.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]))),We=(0,L.lazy)(()=>x(()=>import(`./csv-preview-DnaFdgOB.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([33,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,34,35]))),Ge=(0,L.lazy)(()=>x(()=>import(`./image-preview-KubLSLNO.js`).then(e=>({default:e.ImagePreview})),__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,29,30,31,37,38]))),Ke=(0,L.lazy)(()=>x(()=>import(`./pdf-preview-xZQVUtaV.js`).then(e=>({default:e.PdfPreview})),__vite__mapDeps([39,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,37]))),qe=(0,L.lazy)(()=>x(()=>import(`./video-preview-DcUaFYyv.js`).then(e=>({default:e.VideoPreview})),__vite__mapDeps([40,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,29,30,31,37,38]))),Je=(0,L.lazy)(()=>x(()=>import(`./audio-preview-BkNAEqcB.js`).then(e=>({default:e.AudioPreview})),__vite__mapDeps([41,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,29,30,31,37,38]))),Ye=(0,L.lazy)(()=>x(()=>import(`./docx-preview-Dd2nTW2v.js`).then(e=>({default:e.DocxPreview})),__vite__mapDeps([42,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,37])));function Xe(e){return e.split(`.`).pop()?.toLowerCase()??``}function Ze(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`}[Xe(e)]??`plaintext`}var Qe=(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),x=(0,L.useRef)(``),C=(0,L.useRef)(null),{tabs:se,updateTab:E}=w(ve(e=>({tabs:e.tabs,updateTab:e.updateTab}))),{wordWrap:ce,toggleWordWrap:ue}=ae(ve(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),fe=Ce(),D=e?.isUntitled===!0,O=e?.unsavedContent,[pe,k]=(0,L.useState)(!1),me=se.find(e=>e.id===t),A=n?Xe(n):``,he=Te.has(A),j=A===`pdf`,ge=A===`docx`,_e=we.has(A),M=De.has(A),N=Ee.has(A),be=A===`md`||A===`mdx`,xe=A===`csv`,Se=e?.language,P=a??Se??Ze(n??``),F=P===`sql`,[I,Oe]=(0,L.useState)(`preview`),[ke,Ae]=(0,L.useState)(`table`),{connections:z,cachedTables:je,refreshTables:B,updateConnection:Me}=de(),V=n?`ppm:sql-conn:${n}`:t?`ppm:sql-conn:tab:${t}`:null,[H,Ne]=(0,L.useState)(()=>{if(!V)return null;let e=localStorage.getItem(V);return e?Number(e):null}),U=(0,L.useRef)(null),W=(0,L.useRef)(null),G=(0,L.useMemo)(()=>z.find(e=>e.id===H)??null,[z,H]),Ie=i!=null&&(a===`json`||a===`xml`),[K,ze]=(0,L.useState)(!1),Be=(0,L.useCallback)(()=>{if(i)if(K)s(i),ze(!1);else{let e=i.trimStart();if(a===`json`)try{s(JSON.stringify(JSON.parse(e),null,2)),ze(!0)}catch{}else if(a===`xml`){let t=0;s(e.replace(/(>)(<)(\/*)/g,`$1
|
|
3
3
|
$2$3`).split(`
|
|
4
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
5
|
`)),ze(!0)}}},[i,a,K]),Ve=(0,L.useCallback)(e=>{Ne(e),V&&localStorage.setItem(V,String(e)),B(e).catch(()=>{})},[V,B]),He=(0,L.useCallback)(n=>{t&&E(t,{metadata:{...e,language:n}})},[t,e,E]),q=(0,L.useMemo)(()=>{if(!F||!H)return;let e=(je.get(H)??[]).map(e=>({name:e.tableName,schema:e.schemaName}));if(e.length!==0)return{tables:e,getColumns:async(e,t)=>b.get(`/api/db/connections/${H}/schema?table=${encodeURIComponent(e)}${t?`&schema=${encodeURIComponent(t)}`:``}`)}},[F,H,je]);(0,L.useEffect)(()=>{if(!(!U.current||!q))return W.current?.dispose(),ne(),W.current=U.current.languages.registerCompletionItemProvider(`sql`,te(U.current,q)),()=>{W.current?.dispose()}},[q]);let Qe=w(e=>e.openTab),[J,tt]=(0,L.useState)(null),[nt,rt]=(0,L.useState)(null),[it,at]=(0,L.useState)(!1),[ot,st]=(0,L.useState)(``),ct=(0,L.useCallback)(async e=>{if(G){at(!0),rt(null),st(e);try{tt(await b.post(`/api/db/connections/${G.id}/query`,{sql:e}))}catch(e){rt(e.message),tt(null)}finally{at(!1)}}},[G]),lt=(0,L.useCallback)(()=>{!G||!ot||Qe({type:`database`,title:`${G.name} · Query`,projectId:null,closable:!0,metadata:{connectionId:G.id,connectionName:G.name,dbType:G.type,initialSql:ot}})},[G,Qe,ot]),ut=(0,L.useCallback)(()=>{if(!C.current||!G)return;let e=C.current,t=e.getSelection();ct(t&&!t.isEmpty()?e.getModel()?.getValueInRange(t)??e.getValue():e.getValue())},[G,ct]),dt=typeof window<`u`&&`ontouchstart`in window,ft=(0,L.useRef)(null),[pt,mt]=(0,L.useState)(null);(0,L.useEffect)(()=>{if(!dt)return;let e=window.visualViewport;if(!e)return;let t=()=>{let t=ft.current;if(!t)return;let n=t.getBoundingClientRect().top;mt(e.height-Math.max(0,n))};return e.addEventListener(`resize`,t),e.addEventListener(`scroll`,t),()=>{e.removeEventListener(`resize`,t),e.removeEventListener(`scroll`,t)}},[dt]);let X=(0,L.useRef)([]),ht=(0,L.useRef)(ct);ht.current=ct,(0,L.useEffect)(()=>()=>{X.current.forEach(e=>e.dispose()),X.current=[]},[]),(0,L.useEffect)(()=>{N&&t&&E(t,{type:`sqlite`})},[N,t,E]);let Z=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,L.useEffect)(()=>{if(i!=null){d(!1);return}if(D){s(O??``),x.current=O??``,d(!1),O&&_(!0);return}if(!n||!Z&&!r)return;if(he||j||ge||_e||M){d(!1);return}d(!0),m(null);let e=Z?`/api/fs/read?path=${encodeURIComponent(n)}`:`${y(r)}/files/read?path=${encodeURIComponent(n)}`;return b.get(e).then(e=>{s(e.content),e.encoding&&l(e.encoding),x.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,he,j,ge,Z,D]);let[gt,_t]=(0,L.useState)(!1),vt=(0,L.useCallback)(()=>{if(!n||i!=null||D||!Z&&!r)return;let e=Z?`/api/fs/read?path=${encodeURIComponent(n)}`:`${y(r)}/files/read?path=${encodeURIComponent(n)}`;_t(!0),b.get(e).then(e=>{s(e.content),x.current=e.content,e.encoding&&l(e.encoding),_(!1),m(null)}).catch(e=>m(e instanceof Error?e.message:`Failed to reload file`)).finally(()=>_t(!1))},[n,r,Z,i,D]),yt=(0,L.useRef)(g);yt.current=g,(0,L.useEffect)(()=>{if(!n||!r||i!=null||D)return;let e=e=>{let t=e.detail;if(t.projectName!==r||t.path!==n||yt.current)return;let i=Z?`/api/fs/read?path=${encodeURIComponent(n)}`:`${y(r)}/files/read?path=${encodeURIComponent(n)}`;b.get(i).then(e=>{e.content!==x.current&&(s(e.content),x.current=e.content,e.encoding&&l(e.encoding))}).catch(()=>{})};return window.addEventListener(`file:changed`,e),()=>window.removeEventListener(`file:changed`,e)},[n,r,Z,i,D]),(0,L.useEffect)(()=>{if(!me||i!=null)return;let t=D?`Untitled-${e?.untitledNumber??1}`:n?S(n):`Untitled`,r=g?`${t} \u25CF`:t;me.title!==r&&E(me.id,{title:r})},[g]);let bt=(0,L.useCallback)(async e=>{if(n&&!(!Z&&!r))try{Z?await b.put(`/api/fs/write`,{path:n,content:e}):await b.put(`${y(r)}/files/write`,{path:n,content:e}),_(!1)}catch{}},[n,r,Z]);function xt(n){let r=n??``;s(r),x.current=r,_(!0),v.current&&clearTimeout(v.current),D?v.current=setTimeout(()=>{t&&E(t,{metadata:{...e,unsavedContent:x.current}})},2e3):v.current=setTimeout(()=>bt(x.current),1e3)}let St=(0,L.useCallback)(async(e,n)=>{try{if(v.current&&clearTimeout(v.current),await b.put(`/api/fs/write`,{path:e,content:n}),t){let{closeTab:n,openTab:r}=oe.getState();n(t),r({type:`editor`,title:S(e),projectId:null,metadata:{filePath:e},closable:!0})}_(!1),k(!1)}catch{}},[t]),Q=e?.lineNumber,$=e?.endLine,Ct=e?.revealAt,wt=(0,L.useCallback)(()=>{let e=C.current;if(!(!e||!Q||Q<=0)){if(e.revealLineInCenter(Q),e.setPosition({lineNumber:Q,column:1}),$&&$>=Q){let t=e.getModel(),n=t?.getLineCount()??Q,r=Math.min($,n),i=t?.getLineMaxColumn(r)??1;e.setSelection({startLineNumber:Q,startColumn:1,endLineNumber:r,endColumn:i})}e.focus()}},[Q,$]);(0,L.useEffect)(()=>{Ct!=null&&wt()},[Ct,wt]);let Tt=(0,L.useCallback)((e,t)=>{if(C.current=e,U.current=t,Q&&Q>0&&setTimeout(()=>wt(),100),D&&e.addCommand(t.KeyMod.CtrlCmd|t.KeyCode.KeyS,()=>k(!0)),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>ae.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),q&&(W.current?.dispose(),W.current=t.languages.registerCompletionItemProvider(`sql`,te(t,q))),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&&ht.current(n)}}),X.current.forEach(e=>e.dispose()),X.current=[];let n=e.getModel(),r=e.addCommand(0,(e,t)=>{t&&ht.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(`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{i as r,n as i}from"./api-client-rTAGdEKo.js";import"./vendor-mermaid-C977xNeE.js";import{t as a}from"./settings-store-ChqHdT2V.js";import{Hn as o,jt as s,o as c}from"./index-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{S as t,x as n}from"./vendor-markdown-Ls5AcU91.js";import"./vendor-ui-CaeeFO0B.js";import{i as r,n as i}from"./api-client-rTAGdEKo.js";import"./vendor-mermaid-C977xNeE.js";import{t as a}from"./settings-store-ChqHdT2V.js";import{Hn as o,jt as s,o as c}from"./index-wd3FSHHn.js";import{t as l}from"./use-monaco-theme-DEbn-QT3.js";var u=e(t(),1),d=n();function f(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`,go:`go`,rs:`rust`,java:`java`,rb:`ruby`,php:`php`,swift:`swift`,sql:`sql`,xml:`xml`,toml:`toml`}[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function p(e){let t=e.split(`
|
|
2
2
|
`),n=[],r=0,i=0;for(;r<t.length;){let e=t[r];if(e.startsWith(`<<<<<<<`)){let a=r,o=e.substring(7).trim(),s=[];for(r++;r<t.length&&!t[r].startsWith(`=======`);)s.push(t[r]),r++;if(r>=t.length)break;let c=r,l=[];for(r++;r<t.length&&!t[r].startsWith(`>>>>>>>`);)l.push(t[r]),r++;if(r>=t.length)break;let u=t[r].substring(7).trim();n.push({id:i++,startLine:a+1,separatorLine:c+1,endLine:r+1,currentContent:s.join(`
|
|
3
3
|
`),incomingContent:l.join(`
|
|
4
4
|
`),currentLabel:o,incomingLabel:u})}r++}return n}function m({metadata:e}){let t=e?.filePath,n=e?.projectName,[m,g]=(0,u.useState)(null),[_,v]=(0,u.useState)(!0),[y,b]=(0,u.useState)(null),[x,S]=(0,u.useState)(0),C=(0,u.useRef)(null),w=(0,u.useRef)(null),T=(0,u.useRef)([]),E=(0,u.useRef)(null),{wordWrap:D}=a(s(e=>({wordWrap:e.wordWrap}))),O=l(),k=(0,u.useRef)(null),[A,j]=(0,u.useState)();(0,u.useEffect)(()=>{let e=k.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&j(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[]),(0,u.useEffect)(()=>{!t||!n||(v(!0),i.get(`${r(n)}/files/read?path=${encodeURIComponent(t)}`).then(e=>{g(e.content),v(!1)}).catch(e=>{b(e.message||`Failed to load file`),v(!1)}))},[t,n]);let M=(0,u.useCallback)(()=>{let e=C.current,t=w.current;if(!e||!t)return;let n=p(e.getModel()?.getValue()||``);S(n.length);for(let t of T.current)e.removeContentWidget(t);if(T.current=[],E.current&&E.current.clear(),n.length===0)return;let r=[];for(let e of n)r.push({range:new t.Range(e.startLine,1,e.startLine,1),options:{isWholeLine:!0,className:`conflict-marker-line`,glyphMarginClassName:`conflict-glyph-current`}}),r.push({range:new t.Range(e.separatorLine,1,e.separatorLine,1),options:{isWholeLine:!0,className:`conflict-marker-line`}}),r.push({range:new t.Range(e.endLine,1,e.endLine,1),options:{isWholeLine:!0,className:`conflict-marker-line`,glyphMarginClassName:`conflict-glyph-incoming`}}),e.separatorLine-e.startLine>1&&r.push({range:new t.Range(e.startLine+1,1,e.separatorLine-1,1),options:{isWholeLine:!0,className:`conflict-current-content`}}),e.endLine-e.separatorLine>1&&r.push({range:new t.Range(e.separatorLine+1,1,e.endLine-1,1),options:{isWholeLine:!0,className:`conflict-incoming-content`}});E.current=e.createDecorationsCollection(r);for(let r of n){let n=`conflict-widget-${r.id}`,i=document.createElement(`div`);i.className=`conflict-actions`,i.innerHTML=`<span class="conflict-label">Current Change (${h(r.currentLabel||`HEAD`)})</span><button class="conflict-btn conflict-btn-current" data-action="current">Accept Current</button><button class="conflict-btn conflict-btn-incoming" data-action="incoming">Accept Incoming</button><button class="conflict-btn conflict-btn-both" data-action="both">Accept Both</button>`,i.addEventListener(`click`,e=>{let t=e.target.closest(`[data-action]`);if(!t)return;let n=t.getAttribute(`data-action`);N(r.id,n)});let a={getId:()=>n,getDomNode:()=>i,getPosition:()=>({position:{lineNumber:r.startLine,column:1},preference:[t.editor.ContentWidgetPositionPreference.ABOVE]})};e.addContentWidget(a),T.current.push(a)}},[]),N=(0,u.useCallback)((e,t)=>{let n=C.current,r=w.current;if(!n||!r)return;let i=n.getModel();if(!i)return;let a=p(i.getValue()).find(t=>t.id===e);if(!a)return;let o;switch(t){case`current`:o=a.currentContent;break;case`incoming`:o=a.incomingContent;break;case`both`:o=a.currentContent+`
|