@hienlh/ppm 0.17.33 → 0.17.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +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-CZc98en9.js → ai-resource-editor-QNfSU0Fi.js} +1 -1
- package/dist/web/assets/{audio-preview-XkBaDV-d.js → audio-preview-IokB77Cj.js} +1 -1
- package/dist/web/assets/{chat-tab-Cpxrbm1O.js → chat-tab-BZNEvS88.js} +3 -3
- package/dist/web/assets/{code-editor-DeqsPj8M.js → code-editor-B8YiBPOX.js} +2 -2
- package/dist/web/assets/{conflict-editor-CqORnyRu.js → conflict-editor-CY1o5kBO.js} +1 -1
- package/dist/web/assets/{csv-preview-i79R-2TA.js → csv-preview-AEg0GB-V.js} +1 -1
- package/dist/web/assets/{database-viewer-ClrtBc_A.js → database-viewer-C5Meg0s_.js} +1 -1
- package/dist/web/assets/{diff-viewer-CWUjtM3T.js → diff-viewer-BRRGvZnp.js} +1 -1
- package/dist/web/assets/{docx-preview-CFjtBdLf.js → docx-preview-DqTX7NDp.js} +1 -1
- package/dist/web/assets/{edit-diff-preview-BSjgyGAL.js → edit-diff-preview-_CXUdwsF.js} +1 -1
- package/dist/web/assets/{extension-webview-DwRdXtK4.js → extension-webview-CQceYb7O.js} +1 -1
- package/dist/web/assets/{git-log-panel-DI_uaWVT.js → git-log-panel-D7QlAJqu.js} +1 -1
- package/dist/web/assets/{glide-data-grid-Q2kMqNeo.js → glide-data-grid-cGxkgluR.js} +1 -1
- package/dist/web/assets/group-chat-tab-B-eA5ytm.js +1 -0
- package/dist/web/assets/{image-preview-QyeYNiJt.js → image-preview-DRUzYptI.js} +1 -1
- package/dist/web/assets/{index-BI35sAVB.js → index-BuX7JkCt.js} +4 -4
- package/dist/web/assets/index-PX2pZ3bH.css +2 -0
- package/dist/web/assets/{keybindings-store-55cr_nFT.js → keybindings-store-B3plqyxF.js} +1 -1
- package/dist/web/assets/{markdown-renderer-DoofKFOC.js → markdown-renderer-BKDbjc3g.js} +1 -1
- package/dist/web/assets/{markdown-renderer-ClDzjZ5T.js → markdown-renderer-C9Gy8tM2.js} +1 -1
- package/dist/web/assets/{notification-store-Bwzk7bz9.js → notification-store-jFDauzse.js} +1 -1
- package/dist/web/assets/{pdf-preview-Dd65pYcK.js → pdf-preview-CzHUqXJB.js} +1 -1
- package/dist/web/assets/{postgres-viewer-BAeRjowr.js → postgres-viewer-BeantJZe.js} +1 -1
- package/dist/web/assets/{settings-tab-D_Vz5vjU.js → settings-tab-CqQHhqV1.js} +1 -1
- package/dist/web/assets/{sql-query-editor-RrxjEhFI.js → sql-query-editor-DqU9zfVy.js} +1 -1
- package/dist/web/assets/{sqlite-viewer-DULpl_6h.js → sqlite-viewer-BH891DC0.js} +1 -1
- package/dist/web/assets/{system-monitor-tab-DHOIu_5Y.js → system-monitor-tab-Bue4p4Vb.js} +1 -1
- package/dist/web/assets/{terminal-tab-B64jdELv.js → terminal-tab-BfNnKU71.js} +1 -1
- package/dist/web/assets/tool-cards-CSOwe7_i.js +7 -0
- package/dist/web/assets/use-blob-url-jSRmyXVg.js +1 -0
- package/dist/web/assets/{use-monaco-theme-Bf_8qog4.js → use-monaco-theme-5XjAzOzE.js} +1 -1
- package/dist/web/assets/{video-preview-C-ZB6w-Z.js → video-preview-DMqLOqmc.js} +1 -1
- package/dist/web/index.html +2 -2
- package/dist/web/sw.js +1 -1
- package/package.json +1 -1
- package/src/providers/claude-agent-sdk.ts +4 -3
- package/src/server/routes/fs-browse.ts +13 -2
- package/src/services/jsonl-transcript-parser.ts +2 -1
- package/src/shared/image-extensions.ts +19 -0
- package/src/shared/tool-result-content.ts +70 -0
- package/src/web/components/chat/image-preview-geometry.ts +83 -0
- package/src/web/components/chat/image-preview-states.tsx +51 -0
- package/src/web/components/chat/tool-cards.tsx +27 -2
- package/src/web/components/chat/tool-image-preview.tsx +225 -0
- package/src/web/components/editor/audio-preview.tsx +1 -1
- package/src/web/components/editor/image-preview.tsx +1 -1
- package/src/web/components/editor/video-preview.tsx +1 -1
- package/src/web/{components/editor → hooks}/use-blob-url.ts +14 -3
- package/src/web/styles/globals.css +72 -0
- package/dist/web/assets/group-chat-tab-2NJcUl_4.js +0 -1
- package/dist/web/assets/index-BW2cOdzp.css +0 -2
- package/dist/web/assets/tool-cards-DT3R2C18.js +0 -7
- package/dist/web/assets/use-blob-url-kvtWmJtt.js +0 -1
- /package/dist/web/assets/{csv-parser-BSnYgPcx.js → csv-parser-BPS94T2h.js} +0 -0
- /package/dist/web/assets/{libesm-Dd8zbj1v.js → libesm-BS7D9de3.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.17.34] - 2026-08-28
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- **Images the assistant reads now appear in the chat** — a `Read` on an image file shows the picture beside its dimensions, size and path, with actions to open it in the editor, copy the path, or view it full size. The card used to print the image's raw base64 instead, sending roughly 1.4MB of text per megabyte of image to the browser with nothing truncating it.
|
|
7
|
+
|
|
3
8
|
## [0.17.33] - 2026-08-27
|
|
4
9
|
|
|
5
10
|
### Added
|
|
@@ -71,4 +71,4 @@ This skill covers the `ppm` CLI, its HTTP API, and its config DB. It does **not*
|
|
|
71
71
|
- Third-party extensions (inspect via `ppm ext list`).
|
|
72
72
|
- The Claude Agent SDK internals (separate skill).
|
|
73
73
|
|
|
74
|
-
<!-- Generated for PPM v0.17.
|
|
74
|
+
<!-- Generated for PPM v0.17.34 at build time. Re-run `ppm export skill --install` to refresh. -->
|
|
@@ -284,4 +284,4 @@ _Base URL: `http://localhost:8080` (default; override via `ppm config set port <
|
|
|
284
284
|
- `ws://<host>/ws/terminal` — PTY terminal multiplexer
|
|
285
285
|
- `ws://<host>/ws/extensions` — extension host channel
|
|
286
286
|
|
|
287
|
-
<!-- Generated from src/server/routes/ for PPM v0.17.
|
|
287
|
+
<!-- Generated from src/server/routes/ for PPM v0.17.34 -->
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,y as n}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t as r}from"./save-BM4p9_9n.js";import{o as i}from"./api-client-DhXpjLdi.js";import"./vendor-mermaid-CYOBtZtD.js";import"./settings-store-DFMz_Oer.js";import{n as a}from"./utils-E0yyGxXt.js";import{At as o,D as s,E as c,O as l,Qt as u,T as d,Zt as f,k as p,kt as m,o as h}from"./index-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,y as n}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t as r}from"./save-BM4p9_9n.js";import{o as i}from"./api-client-DhXpjLdi.js";import"./vendor-mermaid-CYOBtZtD.js";import"./settings-store-DFMz_Oer.js";import{n as a}from"./utils-E0yyGxXt.js";import{At as o,D as s,E as c,O as l,Qt as u,T as d,Zt as f,k as p,kt as m,o as h}from"./index-BuX7JkCt.js";import{t as g}from"./use-monaco-theme-5XjAzOzE.js";var _=e(t(),1),v=n();function y({metadata:e}){let t=e?.filePath,n=e?.name,a=e?.resourceType??`skill`,y=e?.scope??`user`,x=e?.readOnly===!0,S=e?.shadowed===!0,C=e?.shadowedBy,w=e?.project??``,[T,E]=(0,_.useState)(``),[D,O]=(0,_.useState)(``),[k,A]=(0,_.useState)(!0),[j,M]=(0,_.useState)(null),[N,P]=(0,_.useState)(!1),F=g(),I=(0,_.useRef)(``),L=T!==D;(0,_.useEffect)(()=>{let e=!1;return A(!0),M(null),l(t,w).then(t=>{e||(E(t.content),O(t.content),I.current=t.content)}).catch(t=>{e||M(t.message)}).finally(()=>{e||A(!1)}),()=>{e=!0}},[t,w]);let R=(0,_.useCallback)(async()=>{if(x||N)return;let e=I.current;if(e!==D){P(!0);try{await p(t,e,w),O(e),E(e),i.success(`Saved`),s.getState().reload()}catch(e){i.error(e.message)}finally{P(!1)}}},[t,w,D,x,N]);(0,_.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&(e.preventDefault(),R())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[R]);let z=c[a];return(0,v.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border px-3 py-2 shrink-0`,children:[(0,v.jsx)(z,{className:`size-4 text-text-subtle`}),(0,v.jsx)(`span`,{className:`text-sm font-semibold`,children:n}),(0,v.jsx)(d,{scope:y}),L&&!x&&(0,v.jsx)(`span`,{className:`size-1.5 rounded-full bg-primary`,title:`Unsaved changes`}),(0,v.jsx)(`div`,{className:`flex-1`}),(0,v.jsxs)(`span`,{className:`hidden sm:block text-[11px] text-text-subtle`,children:[a,` · markdown`]}),!x&&(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(`button`,{onClick:()=>E(D),disabled:!L||N,className:`flex items-center gap-1 rounded px-2 py-1 text-xs text-text-secondary hover:bg-surface-elevated disabled:opacity-40`,children:[(0,v.jsx)(m,{className:`size-3.5`}),` Revert`]}),(0,v.jsxs)(`button`,{onClick:()=>void R(),disabled:!L||N,className:`flex items-center gap-1 rounded bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-40`,children:[N?(0,v.jsx)(u,{className:`size-3.5 animate-spin`}):(0,v.jsx)(r,{className:`size-3.5`}),` Save`]})]})]}),x&&(0,v.jsx)(b,{icon:f,tone:`muted`,children:`Bundled resource — read-only. Duplicate it (from the AI Resources panel) to make an editable copy.`}),S&&C&&(0,v.jsxs)(b,{icon:o,tone:`warn`,children:[`This `,a,` is overridden by another “`,C.name,`” from a higher-priority source (`,C.source,`). It is currently inactive.`]}),(0,v.jsx)(`div`,{className:`min-h-0 flex-1`,children:k?(0,v.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,v.jsx)(u,{className:`size-5 animate-spin text-primary`})}):j?(0,v.jsx)(`div`,{className:`p-6 text-center text-sm text-destructive`,children:j}):(0,v.jsx)(h,{height:`100%`,language:`markdown`,theme:F,value:T,onChange:e=>{let t=e??``;I.current=t,E(t)},options:{readOnly:x,minimap:{enabled:!1},fontSize:13,wordWrap:`on`,scrollBeyondLastLine:!1,lineNumbers:`on`}})})]})}function b({icon:e,tone:t,children:n}){return(0,v.jsxs)(`div`,{className:a(`flex items-start gap-2 px-3 py-2 text-[12px] shrink-0 border-b border-border`,t===`warn`?`bg-amber-500/10 text-amber-300`:`bg-surface-elevated text-text-secondary`),children:[(0,v.jsx)(e,{className:`mt-0.5 size-3.5 shrink-0`}),(0,v.jsx)(`span`,{children:n})]})}export{y as AiResourceEditor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{y as e}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t}from"./createLucideIcon-ConhwJnb.js";import{t as n}from"./file-exclamation-point-DBEC-Kst.js";import"./api-client-DhXpjLdi.js";import{t as r}from"./utils-E0yyGxXt.js";import{Qt as i}from"./index-
|
|
1
|
+
import{y as e}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t}from"./createLucideIcon-ConhwJnb.js";import{t as n}from"./file-exclamation-point-DBEC-Kst.js";import"./api-client-DhXpjLdi.js";import{t as r}from"./utils-E0yyGxXt.js";import{Qt as i}from"./index-BuX7JkCt.js";import{t as a}from"./use-blob-url-jSRmyXVg.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-
|
|
2
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,y as n}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t as r}from"./createLucideIcon-ConhwJnb.js";import{t as i}from"./bot-E9mcVZnr.js";import{g as a,h as o,p as s,t as c}from"./mobile-bottom-sheet-BwPBKZON.js";import{n as l,r as u}from"./use-is-mobile-BcuCjH19.js";import{t as d}from"./chevron-right-DeUue2aK.js";import{a as f,i as p,n as m,r as h,t as g}from"./tool-cards-DT3R2C18.js";import{a as _,c as v,i as y,n as b,o as x,r as S,t as C,u as w}from"./dialog-HHdNInEH.js";import{t as T}from"./code-TekEnDFM.js";import{n as E,t as ee}from"./sparkles-B3DmG8PJ.js";import{n as D,r as te,t as O}from"./plus-DcuJuDC3.js";import{t as k}from"./shield-off-D5tU7gQT.js";import{t as ne}from"./x-BsFLg-T8.js";import{n as A,o as j,r as M,t as N}from"./api-client-DhXpjLdi.js";import{q as re}from"./vendor-mermaid-CYOBtZtD.js";import{t as P}from"./settings-store-DFMz_Oer.js";import{n as F,r as ie,t as I}from"./utils-E0yyGxXt.js";import{t as ae}from"./panel-store-D-RxcUgH.js";import{i as L}from"./project-store-C1jInVih.js";import{t as oe}from"./tab-store-CNxCwdXw.js";import{_ as R,a as se,c as z,h as ce,i as le,l as ue,m as B,o as V,p as H,r as U,s as W,t as G,u as K}from"./api-settings-BUYvGBdi.js";import{$t as de,B as fe,Ct as q,Dt as pe,F as me,Ft as he,Gt as ge,H as _e,Ht as J,I as Y,It as ve,Jt as ye,L as be,Lt as xe,N as Se,Nt as Ce,Ot as we,P as Te,Pt as Ee,Qt as X,R as De,Rt as Oe,Sn as ke,St as Ae,Tt as Z,U as je,V as Me,Vt as Ne,Wt as Pe,Xt as Fe,Zt as Ie,_n as Le,at as Re,bn as ze,en as Be,f as Ve,gn as He,gt as Ue,hn as We,ht as Ge,in as Ke,jt as qe,ln as Je,mn as Ye,mt as Xe,nt as Ze,on as Qe,pn as $e,qt as et,r as tt,rn as nt,t as rt,un as it,vn as at,vt as ot,w as st,wt as ct,xn as lt,yn as ut,z as dt,zt as ft}from"./index-BI35sAVB.js";import{t as pt}from"./libesm-Dd8zbj1v.js";var mt=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`}]]),ht=r(`chevrons-down`,[[`path`,{d:`m7 6 5 5 5-5`,key:`1lc07p`}],[`path`,{d:`m7 13 5 5 5-5`,key:`1d48rs`}]]),gt=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`}]]),_t=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`}]]),vt=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`}]]),yt=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`}]]),bt=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`}]]),xt=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`}]]),St=r(`slash`,[[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}]]),Q=e(t(),1);function Ct(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 wt(e,t){let n=`pc-${Ct(t)}-`;return e.map(e=>e.id?{...e,id:`${n}${e.id}`}:e)}function Tt(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 Et=null;function Dt(){return Et||=new AudioContext,Et}function Ot(e,t,n,r,i=`sine`){let a=Dt(),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 kt(){let e=Dt().currentTime;Ot(523,.15,e,.15),Ot(659,.2,e+.12,.15)}function At(){let e=Dt().currentTime;Ot(880,.12,e,.18,`square`),Ot(698,.12,e+.15,.18,`square`),Ot(880,.15,e+.3,.15,`square`)}function jt(){let e=Dt().currentTime;Ot(440,.12,e,.12),Ot(523,.12,e+.1,.12),Ot(659,.18,e+.2,.12)}var Mt={done:kt,approval_request:At,question:jt};function Nt(e){try{Mt[e]?.()}catch{}}var Pt={hasTeams:!1,teamNames:[],messageCount:0,unreadCount:0};function Ft(e){if(document.hidden)return!1;let{panels:t}=ae.getState();for(let n of Object.values(t)){let t=n.tabs.find(e=>e.id===n.activeTabId);if(t?.type===`chat`&&t.metadata?.sessionId===e)return!0}return!1}function It(e,t=`claude`,n=``){let[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(new Map),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)({}),[d,f]=(0,Q.useState)(`idle`),[p,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(0),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)([]),E=(0,Q.useRef)([]),[ee,D]=(0,Q.useState)(null),[te,O]=(0,Q.useState)(null),[k,ne]=(0,Q.useState)(!1),[re,P]=(0,Q.useState)(null),[F,ie]=(0,Q.useState)(null),I=(0,Q.useRef)(null),L=(0,Q.useRef)(null),[oe,R]=(0,Q.useState)(null),se=(0,Q.useRef)(null),[z,ce]=(0,Q.useState)(!0),le=(0,Q.useRef)(null),ue=(0,Q.useRef)(null),B=(0,Q.useRef)(``),V=(0,Q.useRef)([]),H=(0,Q.useRef)(new Map),U=(0,Q.useRef)(null),W=(0,Q.useRef)(`idle`),G=(0,Q.useRef)(null),K=(0,Q.useRef)(()=>{}),de=(0,Q.useRef)(null),fe=(0,Q.useRef)(!1),q=(0,Q.useRef)(new Set),pe=(0,Q.useRef)(0),me=(0,Q.useRef)(null),he=(0,Q.useRef)(e);he.current=e;let ge=(0,Q.useRef)([]);ge.current=r;let _e=(0,Q.useRef)(n);_e.current=n;let J=(0,Q.useRef)(null),Y=(0,Q.useRef)(0),ve=(0,Q.useRef)({teamNames:new Set,messages:[]}),ye=(0,Q.useRef)(0),[be,xe]=(0,Q.useState)(Pt),[Se,Ce]=(0,Q.useState)([]),we=(0,Q.useCallback)(()=>{let e=ve.current;xe({hasTeams:e.teamNames.size>0,teamNames:Array.from(e.teamNames),messageCount:e.messages.length,unreadCount:ye.current}),Ce([...e.messages])},[]),Te=(0,Q.useCallback)(()=>{ye.current=0,we()},[we]),Ee=d!==`idle`;(0,Q.useEffect)(()=>{if(e)return Re.getState().setStreaming(e,d!==`idle`),()=>{Re.getState().setStreaming(e,!1)}},[e,d]);let X=(0,Q.useCallback)((e,t)=>{let n=V.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=V.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return V.current[n]={...r,children:i},!0},[]),De=(0,Q.useCallback)(()=>{Y.current=0;let e=B.current,t=[...V.current],n=U.current;(0,Q.startTransition)(()=>{i(r=>{let i=r[r.length-1];return i?.role===`assistant`&&!i.id.startsWith(`final-`)?[...r.slice(0,-1),{...i,content:e,events:t,...n}]:[...r,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:t,timestamp:new Date().toISOString(),...n}]})})},[]),Oe=(0,Q.useCallback)(()=>{Y.current||=window.setTimeout(De,100)},[De]),ke=(0,Q.useCallback)(e=>{let t=e,n=t?.type;if(!n)return;let r=e=>{let n=V.current,r=n.findIndex(e);r===-1?n.push(t):n[r]=t};switch(n){case`account_info`:U.current={accountId:t.accountId,accountLabel:t.accountLabel},D(null);break;case`account_retry`:t.accountId&&t.accountLabel&&(U.current={accountId:t.accountId,accountLabel:t.accountLabel}),V.current=[t],Oe();break;case`status_update`:{let e=t.accountLabel?` (${t.accountLabel})`:``;D(`${t.message}${e}`);break}case`text`:{let e=t.parentToolUseId;if(e&&X(t,e)){Oe();break}B.current+=t.content,V.current.push(t),Oe();break}case`thinking`:{let e=t.parentToolUseId;if(e&&X(t,e)){Oe();break}V.current.push(t),Oe();break}case`tool_use`:{if(t.tool===`AskUserQuestion`){t.toolUseId&&q.current.add(t.toolUseId);break}let e=t.parentToolUseId;if(e&&X(t,e)){Oe();break}let n=t.toolUseId;r(e=>!!n&&e.type===`tool_use`&&e.toolUseId===n),Oe();break}case`tool_result`:{let e=t.toolUseId;if(e&&H.current.delete(e),e&&q.current.has(e))break;let n=t.parentToolUseId;if(n&&X(t,n)){Oe();break}r(t=>!!e&&t.type===`tool_result`&&t.toolUseId===e),Oe();break}case`approval_resolved`:{let e=t.requestId;if(t.approved&&t.answers){let n=V.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`),r=n&&n.input;r&&typeof r==`object`&&(r.answers=t.answers,i(e=>[...e]))}y(t=>t&&t.requestId===e?null:t),J.current!=null&&(j.dismiss(J.current),J.current=null);break}case`approval_request`:if(r(e=>e.type===`approval_request`&&e.requestId===t.requestId),fe.current)break;if(y({requestId:t.requestId,tool:t.tool,input:t.input}),he.current&&!Ft(he.current)){Nt(t.tool===`AskUserQuestion`?`question`:`approval_request`);let e=he.current,n=t.tool===`AskUserQuestion`;J.current=j[n?`info`:`warning`](n?`AI has a question`:`${t.tool} needs permission`,{description:_e.current||`Session ${e.slice(0,8)}`,duration:1/0,action:{label:`Go to session`,onClick:()=>{let{panels:t}=ae.getState();for(let[n,r]of Object.entries(t)){let t=r.tabs.find(t=>t.metadata?.sessionId===e);if(t){ae.getState().setActiveTab(t.id,n);break}}}}})}break;case`error`:i(e=>{let n=e[e.length-1];if(n?.role===`assistant`){let r=V.current,i=r[r.length-1],a=i?.type===`error`&&i.message===t.message?r:[...r,t];return V.current=a,[...e.slice(0,-1),{...n,events:a}]}return n?.role===`system`&&n.content===t.message?e:[...e,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]});break;case`team_detected`:{let e=t.teamName;e&&(ve.current.teamNames.add(e),N.get(`/api/teams/${encodeURIComponent(e)}`).then(e=>{if(e?.messages){let t=ve.current.messages,n=e.messages.filter(e=>!t.some(t=>t.timestamp===e.timestamp&&t.from===e.from));t.push(...n),t.sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime()),t.length>500&&t.splice(0,t.length-500)}we()}).catch(()=>{}),we());break}case`team_inbox`:{let e=t.messages;if(Array.isArray(e)){let t=ve.current.messages;t.push(...e),t.length>500&&t.splice(0,t.length-500),ye.current+=e.length,we()}break}case`team_updated`:we();break;case`bash_output`:{let e=t.toolUseId;if(e){let n=H.current.get(e);n?(n.content+=t.content,n.content.length>5e5&&(n.content=n.content.slice(-5e5)),n.lineCount=t.lineCount):H.current.set(e,{content:t.content,lineCount:t.lineCount}),Oe()}break}case`background_registry`:{let e=t.shells??[];E.current=e,T(e);break}case`done`:{if(W.current===`idle`)break;t.contextWindowPct!=null&&x(t.contextWindowPct),he.current&&!Ft(he.current)&&Nt(`done`),Y.current&&=(clearTimeout(Y.current),0);let e=B.current,n=[...V.current],r=U.current,a=t.lastMessageUuid;i(t=>{let i=t[t.length-1];return i?.role===`assistant`?[...t.slice(0,-1),{...i,id:`final-${Date.now()}`,content:e||i.content,events:n.length>0?n:i.events,...a&&{sdkUuid:a}}]:e||n.length>0?[...t,{id:`final-${Date.now()}`,role:`assistant`,content:e,events:n,timestamp:new Date().toISOString(),...a&&{sdkUuid:a},...r}]:t}),B.current=``,V.current=[],U.current=null,me.current=null,H.current.clear(),D(null);break}}},[X,Oe]),Ae=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`title_updated`){O(t.title??null);return}if(t.type===`compact_status`){let e=t.status;e===`compacting`?C(`compacting`):e===`done`&&C(null);return}if(t.type===`phase_changed`){let e=t.phase;f(e),W.current=e,_(e===`connecting`?t.elapsed??0:0),e===`idle`&&C(null);return}if(t.type===`session_state`){ne(!0),P(t.sessionId??he.current);let e=t,n=e.phase;f(n),W.current=n,e.sessionTitle&&O(e.sessionTitle),e.model&&(L.current&&e.model!==L.current||(e.model===L.current&&(L.current=null),ie(e.model),I.current=e.model)),typeof e.effort==`string`&&(R(e.effort),se.current=e.effort),typeof e.thinking==`boolean`&&ce(e.thinking),e.pendingApproval&&y({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),C(e.compactStatus===`compacting`?`compacting`:null),n===`idle`&&(de.current?.(),h(!1));return}if(t.type===`turn_events`){let e=t.events,n=t.userMessage;if(!e?.length&&!n){h(!1);return}pe.current&&=(cancelAnimationFrame(pe.current),0),me.current=n,i(e=>{let t=[...e],r=t.length;for(;r>0&&t[r-1].role===`assistant`;)r--;if(n!=null&&r>0&&t[r-1].role===`user`&&t[r-1].content===n)t=t.slice(0,r-1);else{let e=t[t.length-1];e?.role===`assistant`&&e.id.startsWith(`streaming-`)&&(t=t.slice(0,-1))}if(n){let e=t[t.length-1];(e?.role!==`user`||e.content!==n)&&(t=[...t,{id:`user-replay-${Date.now()}`,role:`user`,content:n,timestamp:new Date().toISOString()}])}return t}),B.current=``,V.current=[],U.current=null,fe.current=!0;let r=0,a=()=>{let t=Math.min(r+100,e.length);for(let n=r;n<t;n++)ke(e[n]);r=t,r<e.length?pe.current=requestAnimationFrame(a):(pe.current=0,fe.current=!1,h(!1))};pe.current=requestAnimationFrame(a);return}ke(t)}},[ke]),{send:Z,connect:je}=m({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:Ae,autoConnect:!!e&&!!n});K.current=Z,(0,Q.useEffect)(()=>{let r=!1;ue.current&&ue.current!==e&&(L.current=null,le.current=null),ue.current=e??null,f(`idle`),W.current=`idle`,y(null),J.current!=null&&(j.dismiss(J.current),J.current=null),C(null),o(new Map),u({}),B.current=``,V.current=[],me.current=null,H.current.clear(),Y.current&&=(clearTimeout(Y.current),0),ne(!1),P(null),ve.current={teamNames:new Set,messages:[]},ye.current=0,xe(Pt),Ce([]);let a=new Set(ge.current.map(e=>e.id));return e&&n?(c(!0),fetch(`${M(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${A()}`}}).then(e=>e.json()).then(e=>{if(r)return;let t=e.ok?Array.isArray(e.data)?{messages:e.data,versionMap:{}}:e.data:null,n=Array.isArray(t?.messages)?t.messages:[];t?.versionMap&&u(t.versionMap);let o=me.current;if(o!=null){for(let e=n.length-1;e>=0;e--)if(n[e].role===`user`&&n[e].content===o){n=n.slice(0,e);break}}i(e=>{let t=e.filter(e=>!a.has(e.id));return[...n,...t]})}).catch(()=>{r||i(e=>e.filter(e=>!a.has(e.id)))}).finally(()=>{r||c(!1)})):i([]),()=>{r=!0}},[e,t,n]);let Me=(0,Q.useCallback)((e,t)=>{if(!e.trim())return;let n=W.current!==`idle`;if(n){Y.current&&=(clearTimeout(Y.current),0);let e=B.current,t=[...V.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n})}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),B.current=``,V.current=[],G.current=null,n?(f(`thinking`),W.current=`thinking`):(f(`initializing`),W.current=`initializing`),y(null),J.current!=null&&(j.dismiss(J.current),J.current=null),Z(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode,priority:t?.priority,images:t?.images,...I.current&&{model:I.current},...se.current&&{effort:se.current},...le.current!==null&&{thinking:le.current}}))},[Z]),Ne=(0,Q.useCallback)(e=>{ie(e),I.current=e,L.current=e,Z(JSON.stringify({type:`set_model`,model:e}))},[Z]),Pe=(0,Q.useCallback)(e=>{R(e),se.current=e,Z(JSON.stringify({type:`set_effort`,effort:e}))},[Z]),Fe=(0,Q.useCallback)(e=>{ce(e),le.current=e,Z(JSON.stringify({type:`set_thinking`,enabled:e}))},[Z]),Ie=(0,Q.useCallback)((e,t,n)=>{if(Z(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=V.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`);if(t){let e=t.input;e&&typeof e==`object`&&(e.answers=n)}i(e=>[...e])}y(null),J.current!=null&&(j.dismiss(J.current),J.current=null)},[Z]),Le=(0,Q.useCallback)(()=>{if(W.current===`idle`)return;Z(JSON.stringify({type:`cancel`}));let e=B.current,t=[...V.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),B.current=``,V.current=[],H.current.clear(),G.current=null,f(`idle`),W.current=`idle`,y(null),J.current!=null&&(j.dismiss(J.current),J.current=null)},[Z]),ze=(0,Q.useCallback)(e=>{e&&Z(JSON.stringify({type:`kill_background_shell`,shellId:e}))},[Z]),Be=(0,Q.useCallback)(e=>{if(!e)return;let t=e.replace(/\.output$/,``);return E.current.find(n=>n.shellId===t||n.outputPath.endsWith(e)||n.outputPath.endsWith(`${t}.output`))},[]);(0,Q.useEffect)(()=>{e&&rt.getState().setSessionShells(e,w)},[e,w]),(0,Q.useEffect)(()=>{if(e)return rt.getState().retainSession(e),()=>{rt.getState().releaseSession(e)}},[e]);let Ve=(0,Q.useCallback)(()=>{ne(!1),h(!0),je()},[je]),He=(0,Q.useCallback)(()=>{!e||!n||fetch(`${M(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${A()}`}}).then(e=>e.json()).then(e=>{if(W.current!==`idle`)return;let t=e.ok?Array.isArray(e.data)?{messages:e.data,versionMap:void 0}:e.data:null;t?.versionMap&&u(t.versionMap),Array.isArray(t?.messages)&&t.messages.length>0&&(i(t.messages),B.current=``,V.current=[])}).catch(()=>{})},[e,t,n]);de.current=He;let Ue=(0,Q.useCallback)(async(e,t)=>{if(!n)throw Error(`No project context available`);let r=e.replace(/^pc-[^-]+-/,``),i=`${M(n)}/chat/pre-compact-messages?jsonlPath=${encodeURIComponent(t)}&before=${encodeURIComponent(r)}`,a=wt(await N.get(i),t);return o(t=>{let n=new Map(t);return n.set(e,a),n}),a.length},[n]),We=(0,Q.useCallback)(e=>a.has(e),[a]),Ge=(0,Q.useCallback)(e=>{i(t=>t.filter(t=>t.id!==e))},[]),Ke=(0,Q.useCallback)(()=>{i(e=>e.filter(e=>e.role!==`system`))},[]);return{messages:r,renderedMessages:(0,Q.useMemo)(()=>Tt(r,a),[r,a]),expandCompact:Ue,isCompactExpanded:We,dismissMessage:Ge,clearErrors:Ke,messagesLoading:s,versionMap:l,isStreaming:Ee,phase:d,isReconnecting:p,connectingElapsed:g,pendingApproval:v,contextWindowPct:b,compactStatus:S,statusMessage:ee,sessionTitle:te,model:F,setModel:Ne,effort:oe,setEffort:Pe,thinking:z,setThinking:Fe,teamActivity:be,teamMessages:Se,markTeamRead:Te,bashPartialOutput:H,backgroundShells:w,killBackgroundShell:ze,findBackgroundShellByOutput:Be,sendMessage:Me,respondToApproval:Ie,cancelStreaming:Le,reconnect:Ve,refetchMessages:He,isConnected:k&&re===e}}var Lt=12e4;function Rt(e,t=`claude`){let[n,r]=(0,Q.useState)({}),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null),c=(0,Q.useRef)(null),l=(0,Q.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${M(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${A()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),e.data.lastFetchedAt&&s(e.data.lastFetchedAt))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,Q.useEffect)(()=>(l(),c.current=setInterval(()=>l(),Lt),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,Q.useCallback)(()=>l(!0),[l])}}var zt={damping:.7,stiffness:.05,mass:1.25},Bt=70,Vt=1e3/60,Ht=350,Ut=!1;globalThis.document?.addEventListener(`mousedown`,()=>{Ut=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{Ut=!1}),globalThis.document?.addEventListener(`click`,()=>{Ut=!1});var Wt=(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(!Ut)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<=Bt}}},[]),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))/Vt;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=Gt(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=Gt(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:Ht})}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 Gt(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Kt=new Map;function qt(...e){let t={...zt},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 Kt.has(r)||Kt.set(r,Object.freeze(t)),n?`instant`:Kt.get(r)}var Jt=60,Yt=8,Xt=1400;function Zt(e){if(e.scrollHeight<=e.clientHeight)return!1;let t=getComputedStyle(e).overflowY;return t===`auto`||t===`scroll`}function Qt(e,t){let n=[],r=e.parentElement;for(;r&&r!==t;)Zt(r)&&n.push(r),r=r.parentElement;return n}function $t(){return typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches}function en(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 tn(e,t,n,r){let i=e.scrollTop+t.getBoundingClientRect().top-e.getBoundingClientRect().top-n;e.scrollTo({top:i,behavior:r?`smooth`:`auto`})}function nn(e,t){let n=en(e,t);if(!n)return()=>{};let{el:r,level:i}=n;for(let t of Qt(r,e))tn(t,r,Yt,!1);tn(e,r,Jt,!$t()),r.dataset.flash=i;let a=setTimeout(()=>{delete r.dataset.flash},Xt);return()=>{clearTimeout(a),delete r.dataset.flash}}var rn=new Set([`Write`,`Edit`,`MultiEdit`,`NotebookEdit`]),an={create:3,write:2,notebook:2,edit:1};function on(e){return typeof e==`string`?e:``}function sn(e,t){let n=0,r=0;for(let i of pt(e,t))i.added?n+=i.count??0:i.removed&&(r+=i.count??0);return{added:n,removed:r}}function cn(e){return e&&/created successfully/i.test(e)?`create`:`write`}function ln(e,t,n){switch(e){case`Write`:{let e=on(t.file_path);return e?{filePath:e,op:cn(n),fragments:[{oldStr:``,newStr:on(t.content)}]}:null}case`Edit`:{let e=on(t.file_path);return e?{filePath:e,op:`edit`,fragments:[{oldStr:on(t.old_string),newStr:on(t.new_string)}]}:null}case`MultiEdit`:{let e=on(t.file_path);if(!e||!Array.isArray(t.edits))return null;let n=t.edits.filter(e=>!!e&&typeof e==`object`).map(e=>({oldStr:on(e.old_string),newStr:on(e.new_string)}));return n.length===0?null:{filePath:e,op:`edit`,fragments:n}}case`NotebookEdit`:{let e=on(t.notebook_path)||on(t.file_path);return e?{filePath:e,op:`notebook`,fragments:[{oldStr:``,newStr:on(t.new_source)}]}:null}default:return null}}function un(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),un(n.children,t)}}}function dn(e,t,n,r){if(e)for(let i of e){if(i.type!==`tool_use`||(i.children?.length&&dn(i.children,!0,n,r),!rn.has(i.tool)))continue;let e=i.input&&typeof i.input==`object`?i.input:null;if(!e)continue;let a=ln(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)),an[a.op]>an[o.op]&&(o.op=a.op),t&&(o.viaSubagent=!0),a.fragments.forEach((e,n)=>{let{added:r,removed:a}=sn(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 fn(e){let t=new Map;for(let n of e)un(n.events,t);let n=new Map;for(let r of e)dn(r.events,!1,n,t);return[...n.values()]}function pn(e,t){let n=[];for(let r=t;r>=0&&e[r]?.role===`assistant`;r--)n.unshift(e[r]);return n}var $=n();function mn(e){try{return new Date(e).toLocaleString()}catch{return``}}function hn({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 gn({content:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsx)(hn,{icon:t?(0,$.jsx)(o,{className:`size-3.5`}):(0,$.jsx)(it,{className:`size-3.5`}),label:t?`Copied`:`Copy`,title:`Copy message to clipboard`,onClick:()=>{Ze(e),n(!0),setTimeout(()=>n(!1),1500)}})}function _n({timestamp:e,content:t,accountLabel:n,className:r,children:i}){return(0,$.jsxs)(`div`,{className:F(`flex items-center gap-0.5 flex-wrap text-xs text-text-subtle select-none`,r),children:[(0,$.jsx)(`time`,{title:mn(e),className:`pr-1 tabular-nums`,children:ct(e)}),n&&(0,$.jsxs)(`span`,{className:`px-1 truncate max-w-40`,children:[`via `,n]}),(0,$.jsx)(gn,{content:t}),i]})}function vn(e){let t=0,n=0;for(let r of e)t+=r.linesAdded,n+=r.linesRemoved;return{added:t,removed:n}}function yn({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:F(`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 bn(e){if(!e)return!1;let t=e.closest(`[data-tab-pool-id]`)?.dataset.tabPoolId;if(!t)return e.offsetParent!==null;let{panels:n,focusedPanelId:r}=ae.getState();return n[r]?.activeTabId===t}var xn={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 Sn(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 Cn({added:e,removed:t,editCount:n,className:r}){return(0,$.jsxs)(`span`,{className:F(`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 wn({change:e,dense:t,selected:n,onClick:r}){let i=xn[e.op],{base:a,dir:o}=Sn(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:F(`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:F(`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)(Cn,{added:e.linesAdded,removed:e.linesRemoved,editCount:e.editCount,className:`text-[11px]`}),(0,$.jsx)(d,{className:`size-[11px] text-text-subtle`})]})}var Tn=(0,Q.lazy)(()=>re(()=>import(`./edit-diff-preview-BSjgyGAL.js`),__vite__mapDeps([0,1,2,3])));function En({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)(ke,{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)(Tn,{oldStr:n.oldStr,newStr:n.newStr,filePath:e.filePath})})})]},n.editRef??r))})}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)}}var On=null;function kn(e){return e instanceof HTMLElement?e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.isContentEditable:!1}function An({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)(()=>(On=s,o.current?.querySelector(`button`)?.focus(),()=>{On===s&&(On=null)}),[s]),(0,Q.useEffect)(()=>{let o=o=>{if(On===s&&bn(a.current)&&!kn(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}=Dn(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)(wn,{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)(Cn,{added:c.linesAdded,removed:c.linesRemoved,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void Ze(c.filePath),className:`shrink-0 rounded-md px-1.5 py-1 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:`copy path`}),(0,$.jsx)(`button`,{type:`button`,onClick:n,"aria-label":`Close change tray`,className:`inline-flex size-8 shrink-0 items-center justify-center rounded-lg text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:(0,$.jsx)(ne,{className:`size-3.5`})})]}),(0,$.jsx)(En,{change:c,onJump:t})]})]})})}function jn(e){let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`));return t<0?e:e.slice(t+1)}function Mn({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 Nn({changes:e,totals:t,open:n,onClose:r,onJump:i}){let[a,o]=(0,Q.useState)(null),s=a==null?null:e[a],l=(0,Q.useRef)(null),u=()=>{o(null),r()},d=e=>{u(),i(e)};return(0,Q.useEffect)(()=>{if(!n)return;let e=l.current,t=()=>Array.from(e?.querySelectorAll(`button:not([disabled])`)??[]);t()[0]?.focus();let r=e=>{if(e.key===`Escape`){e.preventDefault(),u();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)(c,{open:n,onClose:u,className:`flex max-h-[85%] flex-col rounded-t-[14px] motion-reduce:animate-none`,children:(0,$.jsx)(`div`,{ref:l,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)(Mn,{label:`Back to file list`,onClick:()=>o(null),children:(0,$.jsx)(at,{className:`size-4`})}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs font-medium text-text-primary`,children:jn(s.filePath)}),(0,$.jsx)(Cn,{added:s.linesAdded,removed:s.linesRemoved,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(Mn,{label:`Close`,onClick:u,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 Ze(s.filePath),className:`inline-flex min-h-11 shrink-0 items-center rounded-md px-2.5 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:`copy`}),s.edits[0]?.editRef&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d(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)(ke,{className:`size-3`}),`card`]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,$.jsx)(En,{change:s,onJump:d})})]}):(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)(Cn,{added:t.added,removed:t.removed,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(Mn,{label:`Close`,onClick:u,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)(wn,{change:e,onClick:()=>o(t)},e.filePath))})]})})})}function Pn({timestamp:e,content:t,accountLabel:n,changes:r,onJumpToEdit:i}){let[a,o]=(0,Q.useState)(!1),s=l(),c=(0,Q.useRef)(null),u=()=>{o(!1),c.current?.focus()},d=(0,$.jsx)(_n,{timestamp:e,content:t,accountLabel:n,className:`-mt-1.5`,children:r&&r.length>0&&(0,$.jsx)(yn,{ref:c,count:r.length,totals:vn(r),open:a,onToggle:()=>a?u():o(!0)})});return!r||r.length===0?d:(0,$.jsxs)($.Fragment,{children:[d,s?(0,$.jsx)(Nn,{changes:r,totals:vn(r),open:a,onClose:u,onJump:i??(()=>{})}):a&&(0,$.jsx)(An,{changes:r,onJump:e=>{o(!1),i?.(e)},onClose:u})]})}function Fn(e,t,n,r){let[i,a]=(0,Q.useState)([]),o=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(!n||!e||!t){a([]);return}let r=!1;return o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{N.get(`/api/project/${encodeURIComponent(e)}/chat/sessions/${encodeURIComponent(t)}/tasks`).then(e=>{r||a(e)}).catch(()=>{})},300),()=>{r=!0,o.current&&clearTimeout(o.current)}},[e,t,n,r]),i}var In=new Set([`TaskCreate`,`TaskUpdate`,`TaskStop`]);function Ln(e){let t=0;for(let n of e)if(n.events)for(let e of n.events)e.type===`tool_use`&&In.has(e.tool)&&t++;return t}var Rn={completed:{icon:`✓`,cls:`text-success`},in_progress:{icon:`▶`,cls:`text-warning`},stopped:{icon:`■`,cls:`text-text-subtle`},pending:{icon:`○`,cls:`text-text-subtle`}};function zn({projectName:e,sessionId:t,messages:n}){let r=(0,Q.useMemo)(()=>Ln(n),[n]),i=Fn(e,t,r>0,r),[a,o]=(0,Q.useState)(!0);if(i.length===0||i.every(e=>e.status===`completed`||e.status===`stopped`))return null;let s=i.filter(e=>e.status===`completed`).length,c=i.length,l=c?Math.round(s/c*100):0;return(0,$.jsxs)(`div`,{className:`shrink-0 border-b border-border bg-surface/60 backdrop-blur-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`flex items-center gap-2 w-full px-3 min-h-11 text-left text-xs hover:bg-surface transition-colors`,children:[a?(0,$.jsx)(d,{className:`size-3.5 shrink-0`}):(0,$.jsx)(u,{className:`size-3.5 shrink-0`}),(0,$.jsx)(h,{className:`size-3.5 shrink-0 text-text-secondary`}),(0,$.jsx)(`span`,{className:`text-text-primary font-medium`,children:`Tasks`}),(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[s,`/`,c,` done`]}),(0,$.jsx)(`span`,{className:`ml-auto h-1 w-16 rounded-full bg-border overflow-hidden shrink-0`,children:(0,$.jsx)(`span`,{className:`block h-full bg-success/70`,style:{width:`${l}%`}})})]}),!a&&(0,$.jsx)(`ul`,{className:`px-3 pb-2 space-y-0.5 max-h-48 overflow-y-auto`,children:i.map(e=>(0,$.jsx)(Bn,{task:e},e.id))})]})}function Bn({task:e}){let t=Rn[e.status]??Rn.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 Vn=/read the full transcript at:\s*(\S+\.jsonl)/i;function Hn(e){return e.match(Vn)?.[1]?.trim()??null}var Un=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 Wn({projectName:e,onSelectSession:t}){return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-6 text-text-secondary overflow-y-auto`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,$.jsx)(i,{className:`size-10 text-text-subtle`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Send a message to start a new conversation`})]}),(0,$.jsx)(Ge,{projectName:e,onSelectSession:t,className:`w-full px-4`})]})}var Gn=3200,Kn=1e3,qn={hasAbove:!1,atBottom:!0,idx:0,total:0};function Jn({scrollElement:e,userIndices:t,scrollToBottom:n}){let r=l(),[i,a]=(0,Q.useState)(qn),[o,s]=(0,Q.useState)(!1),[c,d]=(0,Q.useState)(0),f=(0,Q.useRef)(Gn),p=(0,Q.useRef)(null),m=(0,Q.useRef)(null),h=(0,Q.useRef)(!1),g=(0,Q.useRef)(!1),_=(e,t,n)=>t.getBoundingClientRect().top-n+e.scrollTop,v=(0,Q.useCallback)(e=>Array.from(e.querySelectorAll(`[data-msg-index]`)).filter(e=>t.includes(Number(e.dataset.msgIndex))),[t]);(0,Q.useEffect)(()=>{let t=e;if(!t)return;let n=0,r=()=>{let e=t.scrollTop,n=t.getBoundingClientRect().top,r=v(t).map(e=>_(t,e,n)),i=0;for(let t=0;t<r.length;t++)r[t]<=e+12&&(i=t+1);let o={hasAbove:r.some(t=>t<e-4),atBottom:t.scrollHeight-e-t.clientHeight<8,idx:i,total:r.length};a(e=>e.hasAbove===o.hasAbove&&e.atBottom===o.atBottom&&e.idx===o.idx&&e.total===o.total?e:o)},i=()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(r)};r(),t.addEventListener(`scroll`,i,{passive:!0});let o=new ResizeObserver(i);return o.observe(t),()=>{n&&cancelAnimationFrame(n),t.removeEventListener(`scroll`,i),o.disconnect()}},[e,v]),(0,Q.useEffect)(()=>{if(!o)return;let e=setTimeout(()=>s(!1),f.current);return()=>clearTimeout(e)},[o,i.idx,c]),(0,Q.useEffect)(()=>{if(!o||!g.current)return;g.current=!1;let e=p.current;(e?.querySelector(`button:not(:disabled)`)??e)?.focus()},[o]),(0,Q.useEffect)(()=>{o||!h.current||(h.current=!1,m.current?.focus())},[o]);let y=(0,Q.useCallback)(()=>{f.current=Gn,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=>()=>{bn(t)&&(e(),f.current=Kn,s(!0))},r=n(b),i=n(x);return window.addEventListener(`chat-nav-prev`,r),window.addEventListener(`chat-nav-next`,i),()=>{window.removeEventListener(`chat-nav-prev`,r),window.removeEventListener(`chat-nav-next`,i)}},[e,b,x]);let C=F(`w-[34px] flex items-center justify-center rounded-[9px] text-text-secondary`,`motion-safe:transition-colors hover:bg-surface-elevated hover:text-foreground`,`disabled:opacity-30 disabled:cursor-default disabled:hover:bg-transparent disabled:hover:text-text-secondary`,r?`h-9`:`h-[30px]`);return(0,$.jsx)(`div`,{className:`absolute bottom-3 right-2.5 z-10 flex flex-col items-end gap-1.5`,children:o?(0,$.jsxs)(`div`,{ref:p,tabIndex:-1,className:`flex flex-col p-[3px] rounded-xl border border-border bg-surface-elevated/95 backdrop-blur-[8px] shadow-lg outline-none`,onFocus:()=>{h.current=!0},onKeyDown:e=>{e.key===`Escape`&&s(!1)},children:[(0,$.jsx)(`button`,{type:`button`,onClick:b,disabled:!i.hasAbove,"aria-label":`Jump to previous message`,className:C,children:(0,$.jsx)(Le,{className:`size-[15px]`})}),(0,$.jsx)(`span`,{className:`font-mono text-[10px] font-medium text-text-subtle text-center py-px`,"aria-label":`Message ${i.idx||1} of ${i.total}`,children:i.total?`${i.idx||1}/${i.total}`:`0/0`}),(0,$.jsx)(`button`,{type:`button`,onClick:x,disabled:i.atBottom,"aria-label":`Jump to next message`,className:C,children:(0,$.jsx)(u,{className:`size-[15px]`})}),(0,$.jsx)(`button`,{type:`button`,onClick:S,disabled:i.atBottom,"aria-label":`Jump to latest`,className:C,children:(0,$.jsx)(ht,{className:`size-[13px]`})})]}):(0,$.jsx)(`button`,{ref:m,type:`button`,onClick:()=>{f.current=Gn,g.current=!0,s(!0)},"aria-label":`Navigate messages`,"aria-expanded":!1,title:`Navigate messages`,className:F(`group flex items-center justify-center`,r?`size-11`:`size-[30px]`),children:(0,$.jsx)(`span`,{className:F(`flex items-center justify-center rounded-full border border-border bg-surface-elevated/55 backdrop-blur-[6px] text-text-subtle`,`motion-safe:transition-colors group-hover:bg-surface-elevated group-hover:text-foreground`,r?`size-9`:`size-[30px]`),children:(0,$.jsx)(He,{className:`size-[15px]`})})})})}function Yn({group:e,onNavigate:t,disabled:n}){if(!e||e.ids.length<2)return null;let{ids:r,currentIndex:i}=e,a=e=>{let i=r[e];i&&!n&&t(i)};return(0,$.jsxs)(`div`,{className:`mt-1 flex items-center gap-1 text-xs text-text-subtle select-none`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>a(i-1),disabled:n||i<=0,"aria-label":`Previous version`,className:`flex items-center justify-center rounded p-0.5 hover:text-text-primary disabled:opacity-30 disabled:cursor-default`,children:(0,$.jsx)(at,{className:`size-3.5`})}),(0,$.jsxs)(`span`,{className:`tabular-nums`,children:[i+1,`/`,r.length]}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>a(i+1),disabled:n||i>=r.length-1,"aria-label":`Next version`,className:`flex items-center justify-center rounded p-0.5 hover:text-text-primary disabled:opacity-30 disabled:cursor-default`,children:(0,$.jsx)(d,{className:`size-3.5`})})]})}function Xn(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 Zn(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 Qn({questions:e,onSubmit:t,onSkip:n}){let r=(0,Q.useRef)(null),i=Xn(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=Zn({questions:e,activeTab:i.activeTab,totalOptions:o,allAnswered:i.allAnswered,hasAnswer:i.hasAnswer,onSelectOption:l,goToNextTab:i.goToNextTab,goToPrevTab:i.goToPrevTab,onSubmit:c,customInputRef:r,enabled:!0}),d=(0,Q.useCallback)(e=>{l(e),u.setFocusedOption(e)},[l,u.setFocusedOption]);return(0,$.jsxs)(`div`,{ref:u.containerRef,className:`rounded-lg border-2 border-primary/30 bg-primary/5 p-3 space-y-3 outline-none animate-in slide-in-from-bottom-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,$.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,$.jsxs)(`span`,{className:`text-[10px] text-text-secondary font-normal`,children:[s?`←→ tabs · `:``,`↑↓ options · 1-`,Math.min(o-1,9),` select · Enter submit`]})]}),s&&(0,$.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,$.jsxs)(`button`,{className:`flex items-center gap-1.5 px-3 py-1.5 rounded text-xs whitespace-nowrap transition-all ${i.activeTab===t?`bg-primary text-primary-foreground`:i.hasAnswer(t)?`text-primary bg-transparent`:`text-text-secondary hover:bg-surface-elevated`}`,onClick:()=>{i.setActiveTab(t),u.setFocusedOption(0)},tabIndex:-1,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-semibold ${i.activeTab===t?`bg-white/20`:i.hasAnswer(t)?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:i.hasAnswer(t)?`✓`:t+1}),(0,$.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,$.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,$.jsx)(`div`,{className:`text-sm text-text-primary select-text`,children:a.question}),a.multiSelect&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a.options.map((e,t)=>{let n=(i.answers[i.activeTab]||[]).includes(e.label),r=u.focusedOption===t;return(0,$.jsxs)(`div`,{role:`button`,onClick:()=>d(t),className:`text-left flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border transition-all cursor-pointer select-text ${n?`border-primary bg-primary/10 text-text-primary`:`border-border bg-background text-text-secondary hover:border-primary/40 hover:bg-primary/5`} ${r?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded text-[10px] font-semibold shrink-0 mt-px ${n?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:t+1}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,$.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,$.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border border-dashed transition-all border-border bg-transparent ${u.focusedOption===o-1?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded bg-surface-elevated text-text-secondary text-[10px] font-semibold shrink-0 mt-px`,children:`O`}),(0,$.jsx)(`input`,{ref:r,type:`text`,className:`flex-1 px-2 py-1 text-xs bg-surface border border-border rounded text-text-primary outline-none placeholder:text-text-subtle focus:border-primary`,placeholder:`Other (press O to type)...`,value:i.customInputs[i.activeTab]||``,onChange:e=>i.handleCustomInput(i.activeTab,e.target.value),onFocus:()=>u.setFocusedOption(o-1)})]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToPrevTab,disabled:i.activeTab===0,tabIndex:-1,children:`← Prev`}),(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToNextTab,disabled:i.activeTab===e.length-1,tabIndex:-1,children:`Next →`})]}),(0,$.jsx)(`button`,{onClick:n,className:`px-4 py-1.5 rounded border border-border bg-background text-text-secondary text-xs hover:bg-surface-elevated transition-colors`,tabIndex:-1,children:`Skip`}),(0,$.jsxs)(`button`,{onClick:c,disabled:!i.allAnswered,className:`px-4 py-1.5 rounded bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,tabIndex:-1,children:[`Submit `,i.allAnswered?`✓`:`(${e.filter((e,t)=>i.hasAnswer(t)).length}/${e.length})`]})]})]})}var $n={"system-reminder":`Context`,claudeMd:`CLAUDE.md`,gitStatus:`Git Status`,currentDate:`Date`,fast_mode_info:`Fast Mode`,"available-deferred-tools":`Tools`,"task-notification":`Task Result`,environment_details:`Environment`,"local-command-caveat":`System`};function er(e){let t=[],n=/<(system-reminder|available-deferred-tools|antml:[\w-]+|fast_mode_info|claudeMd|gitStatus|currentDate|task-notification|environment_details|local-command-caveat)[^>]*>([\s\S]*?)<\/\1>/g,r;for(;(r=n.exec(e))!==null;){let e=r[1];t.push({name:e,label:$n[e]??e.replace(/^antml:/,``).replace(/-/g,` `),content:r[2].trim()})}return{cleanText:e.replace(n,``).trim(),tags:t}}function tr(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 nr(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 rr(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 ir(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 ar(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 or(e){let{idePath:t,cleanText:n}=rr(e),{blocks:r,remainingText:i}=ar(n),a=ir(i),{cleanText:o,tags:s}=er(a.text.replace(/<local-command-(?:stdout|stderr)>([\s\S]*?)<\/local-command-(?:stdout|stderr)>/g,`$1`)),{command:c,cleanText:l}=tr(o),{agent:u,cleanText:d}=nr(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 sr(e){let{agent:t,body:n,command:r}=or(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 cr=re(()=>import(`./markdown-renderer-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/edit-diff-preview-_CXUdwsF.js","assets/rolldown-runtime-FhOqtrmT.js","assets/vendor-markdown-CKTlmXbz.js","assets/libesm-BS7D9de3.js","assets/markdown-renderer-C9Gy8tM2.js","assets/vendor-mermaid-CYOBtZtD.js","assets/vendor-ui-DMRGWRuc.js","assets/markdown-renderer-BKDbjc3g.js","assets/index-BuX7JkCt.js","assets/dialog-HHdNInEH.js","assets/utils-E0yyGxXt.js","assets/createLucideIcon-ConhwJnb.js","assets/x-BsFLg-T8.js","assets/eye-off-Rq1n2-oe.js","assets/bot-E9mcVZnr.js","assets/mobile-bottom-sheet-BwPBKZON.js","assets/chevron-right-DeUue2aK.js","assets/use-is-mobile-BcuCjH19.js","assets/sparkles-B3DmG8PJ.js","assets/database-COYAMZaw.js","assets/plus-DcuJuDC3.js","assets/api-client-DhXpjLdi.js","assets/react-8hrD3-kv.js","assets/api-settings-BUYvGBdi.js","assets/project-store-C1jInVih.js","assets/panel-store-D-RxcUgH.js","assets/settings-store-DFMz_Oer.js","assets/tab-store-CNxCwdXw.js","assets/apply-theme-BSJDABU3.js","assets/resolve-theme-B9Mgd5GG.js","assets/index-PX2pZ3bH.css","assets/api-client-DNTkryX1.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,y as n}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t as r}from"./createLucideIcon-ConhwJnb.js";import{t as i}from"./bot-E9mcVZnr.js";import{g as a,h as o,p as s,t as c}from"./mobile-bottom-sheet-BwPBKZON.js";import{n as l,r as u}from"./use-is-mobile-BcuCjH19.js";import{t as d}from"./chevron-right-DeUue2aK.js";import{a as f,i as p,n as m,r as h,t as g}from"./tool-cards-CSOwe7_i.js";import{a as _,c as v,i as y,n as b,o as x,r as S,t as C,u as w}from"./dialog-HHdNInEH.js";import{t as T}from"./code-TekEnDFM.js";import{n as E,t as ee}from"./sparkles-B3DmG8PJ.js";import{n as D,r as te,t as O}from"./plus-DcuJuDC3.js";import{t as k}from"./shield-off-D5tU7gQT.js";import{t as ne}from"./x-BsFLg-T8.js";import{n as A,o as j,r as M,t as N}from"./api-client-DhXpjLdi.js";import{q as re}from"./vendor-mermaid-CYOBtZtD.js";import{t as P}from"./settings-store-DFMz_Oer.js";import{n as F,r as ie,t as I}from"./utils-E0yyGxXt.js";import{t as ae}from"./panel-store-D-RxcUgH.js";import{i as L}from"./project-store-C1jInVih.js";import{t as oe}from"./tab-store-CNxCwdXw.js";import{_ as R,a as se,c as z,h as ce,i as le,l as ue,m as B,o as V,p as H,r as U,s as W,t as G,u as K}from"./api-settings-BUYvGBdi.js";import{$t as de,B as fe,Ct as q,Dt as pe,F as me,Ft as he,Gt as ge,H as _e,Ht as J,I as Y,It as ve,Jt as ye,L as be,Lt as xe,N as Se,Nt as Ce,Ot as we,P as Te,Pt as Ee,Qt as X,R as De,Rt as Oe,Sn as ke,St as Ae,Tt as Z,U as je,V as Me,Vt as Ne,Wt as Pe,Xt as Fe,Zt as Ie,_n as Le,at as Re,bn as ze,en as Be,f as Ve,gn as He,gt as Ue,hn as We,ht as Ge,in as Ke,jt as qe,ln as Je,mn as Ye,mt as Xe,nt as Ze,on as Qe,pn as $e,qt as et,r as tt,rn as nt,t as rt,un as it,vn as at,vt as ot,w as st,wt as ct,xn as lt,yn as ut,z as dt,zt as ft}from"./index-BuX7JkCt.js";import"./use-blob-url-jSRmyXVg.js";import{t as pt}from"./libesm-BS7D9de3.js";var mt=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`}]]),ht=r(`chevrons-down`,[[`path`,{d:`m7 6 5 5 5-5`,key:`1lc07p`}],[`path`,{d:`m7 13 5 5 5-5`,key:`1d48rs`}]]),gt=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`}]]),_t=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`}]]),vt=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`}]]),yt=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`}]]),bt=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`}]]),xt=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`}]]),St=r(`slash`,[[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}]]),Q=e(t(),1);function Ct(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 wt(e,t){let n=`pc-${Ct(t)}-`;return e.map(e=>e.id?{...e,id:`${n}${e.id}`}:e)}function Tt(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 Et=null;function Dt(){return Et||=new AudioContext,Et}function Ot(e,t,n,r,i=`sine`){let a=Dt(),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 kt(){let e=Dt().currentTime;Ot(523,.15,e,.15),Ot(659,.2,e+.12,.15)}function At(){let e=Dt().currentTime;Ot(880,.12,e,.18,`square`),Ot(698,.12,e+.15,.18,`square`),Ot(880,.15,e+.3,.15,`square`)}function jt(){let e=Dt().currentTime;Ot(440,.12,e,.12),Ot(523,.12,e+.1,.12),Ot(659,.18,e+.2,.12)}var Mt={done:kt,approval_request:At,question:jt};function Nt(e){try{Mt[e]?.()}catch{}}var Pt={hasTeams:!1,teamNames:[],messageCount:0,unreadCount:0};function Ft(e){if(document.hidden)return!1;let{panels:t}=ae.getState();for(let n of Object.values(t)){let t=n.tabs.find(e=>e.id===n.activeTabId);if(t?.type===`chat`&&t.metadata?.sessionId===e)return!0}return!1}function It(e,t=`claude`,n=``){let[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(new Map),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)({}),[d,f]=(0,Q.useState)(`idle`),[p,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(0),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)([]),E=(0,Q.useRef)([]),[ee,D]=(0,Q.useState)(null),[te,O]=(0,Q.useState)(null),[k,ne]=(0,Q.useState)(!1),[re,P]=(0,Q.useState)(null),[F,ie]=(0,Q.useState)(null),I=(0,Q.useRef)(null),L=(0,Q.useRef)(null),[oe,R]=(0,Q.useState)(null),se=(0,Q.useRef)(null),[z,ce]=(0,Q.useState)(!0),le=(0,Q.useRef)(null),ue=(0,Q.useRef)(null),B=(0,Q.useRef)(``),V=(0,Q.useRef)([]),H=(0,Q.useRef)(new Map),U=(0,Q.useRef)(null),W=(0,Q.useRef)(`idle`),G=(0,Q.useRef)(null),K=(0,Q.useRef)(()=>{}),de=(0,Q.useRef)(null),fe=(0,Q.useRef)(!1),q=(0,Q.useRef)(new Set),pe=(0,Q.useRef)(0),me=(0,Q.useRef)(null),he=(0,Q.useRef)(e);he.current=e;let ge=(0,Q.useRef)([]);ge.current=r;let _e=(0,Q.useRef)(n);_e.current=n;let J=(0,Q.useRef)(null),Y=(0,Q.useRef)(0),ve=(0,Q.useRef)({teamNames:new Set,messages:[]}),ye=(0,Q.useRef)(0),[be,xe]=(0,Q.useState)(Pt),[Se,Ce]=(0,Q.useState)([]),we=(0,Q.useCallback)(()=>{let e=ve.current;xe({hasTeams:e.teamNames.size>0,teamNames:Array.from(e.teamNames),messageCount:e.messages.length,unreadCount:ye.current}),Ce([...e.messages])},[]),Te=(0,Q.useCallback)(()=>{ye.current=0,we()},[we]),Ee=d!==`idle`;(0,Q.useEffect)(()=>{if(e)return Re.getState().setStreaming(e,d!==`idle`),()=>{Re.getState().setStreaming(e,!1)}},[e,d]);let X=(0,Q.useCallback)((e,t)=>{let n=V.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=V.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return V.current[n]={...r,children:i},!0},[]),De=(0,Q.useCallback)(()=>{Y.current=0;let e=B.current,t=[...V.current],n=U.current;(0,Q.startTransition)(()=>{i(r=>{let i=r[r.length-1];return i?.role===`assistant`&&!i.id.startsWith(`final-`)?[...r.slice(0,-1),{...i,content:e,events:t,...n}]:[...r,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:t,timestamp:new Date().toISOString(),...n}]})})},[]),Oe=(0,Q.useCallback)(()=>{Y.current||=window.setTimeout(De,100)},[De]),ke=(0,Q.useCallback)(e=>{let t=e,n=t?.type;if(!n)return;let r=e=>{let n=V.current,r=n.findIndex(e);r===-1?n.push(t):n[r]=t};switch(n){case`account_info`:U.current={accountId:t.accountId,accountLabel:t.accountLabel},D(null);break;case`account_retry`:t.accountId&&t.accountLabel&&(U.current={accountId:t.accountId,accountLabel:t.accountLabel}),V.current=[t],Oe();break;case`status_update`:{let e=t.accountLabel?` (${t.accountLabel})`:``;D(`${t.message}${e}`);break}case`text`:{let e=t.parentToolUseId;if(e&&X(t,e)){Oe();break}B.current+=t.content,V.current.push(t),Oe();break}case`thinking`:{let e=t.parentToolUseId;if(e&&X(t,e)){Oe();break}V.current.push(t),Oe();break}case`tool_use`:{if(t.tool===`AskUserQuestion`){t.toolUseId&&q.current.add(t.toolUseId);break}let e=t.parentToolUseId;if(e&&X(t,e)){Oe();break}let n=t.toolUseId;r(e=>!!n&&e.type===`tool_use`&&e.toolUseId===n),Oe();break}case`tool_result`:{let e=t.toolUseId;if(e&&H.current.delete(e),e&&q.current.has(e))break;let n=t.parentToolUseId;if(n&&X(t,n)){Oe();break}r(t=>!!e&&t.type===`tool_result`&&t.toolUseId===e),Oe();break}case`approval_resolved`:{let e=t.requestId;if(t.approved&&t.answers){let n=V.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`),r=n&&n.input;r&&typeof r==`object`&&(r.answers=t.answers,i(e=>[...e]))}y(t=>t&&t.requestId===e?null:t),J.current!=null&&(j.dismiss(J.current),J.current=null);break}case`approval_request`:if(r(e=>e.type===`approval_request`&&e.requestId===t.requestId),fe.current)break;if(y({requestId:t.requestId,tool:t.tool,input:t.input}),he.current&&!Ft(he.current)){Nt(t.tool===`AskUserQuestion`?`question`:`approval_request`);let e=he.current,n=t.tool===`AskUserQuestion`;J.current=j[n?`info`:`warning`](n?`AI has a question`:`${t.tool} needs permission`,{description:_e.current||`Session ${e.slice(0,8)}`,duration:1/0,action:{label:`Go to session`,onClick:()=>{let{panels:t}=ae.getState();for(let[n,r]of Object.entries(t)){let t=r.tabs.find(t=>t.metadata?.sessionId===e);if(t){ae.getState().setActiveTab(t.id,n);break}}}}})}break;case`error`:i(e=>{let n=e[e.length-1];if(n?.role===`assistant`){let r=V.current,i=r[r.length-1],a=i?.type===`error`&&i.message===t.message?r:[...r,t];return V.current=a,[...e.slice(0,-1),{...n,events:a}]}return n?.role===`system`&&n.content===t.message?e:[...e,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]});break;case`team_detected`:{let e=t.teamName;e&&(ve.current.teamNames.add(e),N.get(`/api/teams/${encodeURIComponent(e)}`).then(e=>{if(e?.messages){let t=ve.current.messages,n=e.messages.filter(e=>!t.some(t=>t.timestamp===e.timestamp&&t.from===e.from));t.push(...n),t.sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime()),t.length>500&&t.splice(0,t.length-500)}we()}).catch(()=>{}),we());break}case`team_inbox`:{let e=t.messages;if(Array.isArray(e)){let t=ve.current.messages;t.push(...e),t.length>500&&t.splice(0,t.length-500),ye.current+=e.length,we()}break}case`team_updated`:we();break;case`bash_output`:{let e=t.toolUseId;if(e){let n=H.current.get(e);n?(n.content+=t.content,n.content.length>5e5&&(n.content=n.content.slice(-5e5)),n.lineCount=t.lineCount):H.current.set(e,{content:t.content,lineCount:t.lineCount}),Oe()}break}case`background_registry`:{let e=t.shells??[];E.current=e,T(e);break}case`done`:{if(W.current===`idle`)break;t.contextWindowPct!=null&&x(t.contextWindowPct),he.current&&!Ft(he.current)&&Nt(`done`),Y.current&&=(clearTimeout(Y.current),0);let e=B.current,n=[...V.current],r=U.current,a=t.lastMessageUuid;i(t=>{let i=t[t.length-1];return i?.role===`assistant`?[...t.slice(0,-1),{...i,id:`final-${Date.now()}`,content:e||i.content,events:n.length>0?n:i.events,...a&&{sdkUuid:a}}]:e||n.length>0?[...t,{id:`final-${Date.now()}`,role:`assistant`,content:e,events:n,timestamp:new Date().toISOString(),...a&&{sdkUuid:a},...r}]:t}),B.current=``,V.current=[],U.current=null,me.current=null,H.current.clear(),D(null);break}}},[X,Oe]),Ae=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`title_updated`){O(t.title??null);return}if(t.type===`compact_status`){let e=t.status;e===`compacting`?C(`compacting`):e===`done`&&C(null);return}if(t.type===`phase_changed`){let e=t.phase;f(e),W.current=e,_(e===`connecting`?t.elapsed??0:0),e===`idle`&&C(null);return}if(t.type===`session_state`){ne(!0),P(t.sessionId??he.current);let e=t,n=e.phase;f(n),W.current=n,e.sessionTitle&&O(e.sessionTitle),e.model&&(L.current&&e.model!==L.current||(e.model===L.current&&(L.current=null),ie(e.model),I.current=e.model)),typeof e.effort==`string`&&(R(e.effort),se.current=e.effort),typeof e.thinking==`boolean`&&ce(e.thinking),e.pendingApproval&&y({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),C(e.compactStatus===`compacting`?`compacting`:null),n===`idle`&&(de.current?.(),h(!1));return}if(t.type===`turn_events`){let e=t.events,n=t.userMessage;if(!e?.length&&!n){h(!1);return}pe.current&&=(cancelAnimationFrame(pe.current),0),me.current=n,i(e=>{let t=[...e],r=t.length;for(;r>0&&t[r-1].role===`assistant`;)r--;if(n!=null&&r>0&&t[r-1].role===`user`&&t[r-1].content===n)t=t.slice(0,r-1);else{let e=t[t.length-1];e?.role===`assistant`&&e.id.startsWith(`streaming-`)&&(t=t.slice(0,-1))}if(n){let e=t[t.length-1];(e?.role!==`user`||e.content!==n)&&(t=[...t,{id:`user-replay-${Date.now()}`,role:`user`,content:n,timestamp:new Date().toISOString()}])}return t}),B.current=``,V.current=[],U.current=null,fe.current=!0;let r=0,a=()=>{let t=Math.min(r+100,e.length);for(let n=r;n<t;n++)ke(e[n]);r=t,r<e.length?pe.current=requestAnimationFrame(a):(pe.current=0,fe.current=!1,h(!1))};pe.current=requestAnimationFrame(a);return}ke(t)}},[ke]),{send:Z,connect:je}=m({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:Ae,autoConnect:!!e&&!!n});K.current=Z,(0,Q.useEffect)(()=>{let r=!1;ue.current&&ue.current!==e&&(L.current=null,le.current=null),ue.current=e??null,f(`idle`),W.current=`idle`,y(null),J.current!=null&&(j.dismiss(J.current),J.current=null),C(null),o(new Map),u({}),B.current=``,V.current=[],me.current=null,H.current.clear(),Y.current&&=(clearTimeout(Y.current),0),ne(!1),P(null),ve.current={teamNames:new Set,messages:[]},ye.current=0,xe(Pt),Ce([]);let a=new Set(ge.current.map(e=>e.id));return e&&n?(c(!0),fetch(`${M(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${A()}`}}).then(e=>e.json()).then(e=>{if(r)return;let t=e.ok?Array.isArray(e.data)?{messages:e.data,versionMap:{}}:e.data:null,n=Array.isArray(t?.messages)?t.messages:[];t?.versionMap&&u(t.versionMap);let o=me.current;if(o!=null){for(let e=n.length-1;e>=0;e--)if(n[e].role===`user`&&n[e].content===o){n=n.slice(0,e);break}}i(e=>{let t=e.filter(e=>!a.has(e.id));return[...n,...t]})}).catch(()=>{r||i(e=>e.filter(e=>!a.has(e.id)))}).finally(()=>{r||c(!1)})):i([]),()=>{r=!0}},[e,t,n]);let Me=(0,Q.useCallback)((e,t)=>{if(!e.trim())return;let n=W.current!==`idle`;if(n){Y.current&&=(clearTimeout(Y.current),0);let e=B.current,t=[...V.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n})}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),B.current=``,V.current=[],G.current=null,n?(f(`thinking`),W.current=`thinking`):(f(`initializing`),W.current=`initializing`),y(null),J.current!=null&&(j.dismiss(J.current),J.current=null),Z(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode,priority:t?.priority,images:t?.images,...I.current&&{model:I.current},...se.current&&{effort:se.current},...le.current!==null&&{thinking:le.current}}))},[Z]),Ne=(0,Q.useCallback)(e=>{ie(e),I.current=e,L.current=e,Z(JSON.stringify({type:`set_model`,model:e}))},[Z]),Pe=(0,Q.useCallback)(e=>{R(e),se.current=e,Z(JSON.stringify({type:`set_effort`,effort:e}))},[Z]),Fe=(0,Q.useCallback)(e=>{ce(e),le.current=e,Z(JSON.stringify({type:`set_thinking`,enabled:e}))},[Z]),Ie=(0,Q.useCallback)((e,t,n)=>{if(Z(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=V.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`);if(t){let e=t.input;e&&typeof e==`object`&&(e.answers=n)}i(e=>[...e])}y(null),J.current!=null&&(j.dismiss(J.current),J.current=null)},[Z]),Le=(0,Q.useCallback)(()=>{if(W.current===`idle`)return;Z(JSON.stringify({type:`cancel`}));let e=B.current,t=[...V.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),B.current=``,V.current=[],H.current.clear(),G.current=null,f(`idle`),W.current=`idle`,y(null),J.current!=null&&(j.dismiss(J.current),J.current=null)},[Z]),ze=(0,Q.useCallback)(e=>{e&&Z(JSON.stringify({type:`kill_background_shell`,shellId:e}))},[Z]),Be=(0,Q.useCallback)(e=>{if(!e)return;let t=e.replace(/\.output$/,``);return E.current.find(n=>n.shellId===t||n.outputPath.endsWith(e)||n.outputPath.endsWith(`${t}.output`))},[]);(0,Q.useEffect)(()=>{e&&rt.getState().setSessionShells(e,w)},[e,w]),(0,Q.useEffect)(()=>{if(e)return rt.getState().retainSession(e),()=>{rt.getState().releaseSession(e)}},[e]);let Ve=(0,Q.useCallback)(()=>{ne(!1),h(!0),je()},[je]),He=(0,Q.useCallback)(()=>{!e||!n||fetch(`${M(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${A()}`}}).then(e=>e.json()).then(e=>{if(W.current!==`idle`)return;let t=e.ok?Array.isArray(e.data)?{messages:e.data,versionMap:void 0}:e.data:null;t?.versionMap&&u(t.versionMap),Array.isArray(t?.messages)&&t.messages.length>0&&(i(t.messages),B.current=``,V.current=[])}).catch(()=>{})},[e,t,n]);de.current=He;let Ue=(0,Q.useCallback)(async(e,t)=>{if(!n)throw Error(`No project context available`);let r=e.replace(/^pc-[^-]+-/,``),i=`${M(n)}/chat/pre-compact-messages?jsonlPath=${encodeURIComponent(t)}&before=${encodeURIComponent(r)}`,a=wt(await N.get(i),t);return o(t=>{let n=new Map(t);return n.set(e,a),n}),a.length},[n]),We=(0,Q.useCallback)(e=>a.has(e),[a]),Ge=(0,Q.useCallback)(e=>{i(t=>t.filter(t=>t.id!==e))},[]),Ke=(0,Q.useCallback)(()=>{i(e=>e.filter(e=>e.role!==`system`))},[]);return{messages:r,renderedMessages:(0,Q.useMemo)(()=>Tt(r,a),[r,a]),expandCompact:Ue,isCompactExpanded:We,dismissMessage:Ge,clearErrors:Ke,messagesLoading:s,versionMap:l,isStreaming:Ee,phase:d,isReconnecting:p,connectingElapsed:g,pendingApproval:v,contextWindowPct:b,compactStatus:S,statusMessage:ee,sessionTitle:te,model:F,setModel:Ne,effort:oe,setEffort:Pe,thinking:z,setThinking:Fe,teamActivity:be,teamMessages:Se,markTeamRead:Te,bashPartialOutput:H,backgroundShells:w,killBackgroundShell:ze,findBackgroundShellByOutput:Be,sendMessage:Me,respondToApproval:Ie,cancelStreaming:Le,reconnect:Ve,refetchMessages:He,isConnected:k&&re===e}}var Lt=12e4;function Rt(e,t=`claude`){let[n,r]=(0,Q.useState)({}),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null),c=(0,Q.useRef)(null),l=(0,Q.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${M(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${A()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),e.data.lastFetchedAt&&s(e.data.lastFetchedAt))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,Q.useEffect)(()=>(l(),c.current=setInterval(()=>l(),Lt),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,Q.useCallback)(()=>l(!0),[l])}}var zt={damping:.7,stiffness:.05,mass:1.25},Bt=70,Vt=1e3/60,Ht=350,Ut=!1;globalThis.document?.addEventListener(`mousedown`,()=>{Ut=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{Ut=!1}),globalThis.document?.addEventListener(`click`,()=>{Ut=!1});var Wt=(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(!Ut)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<=Bt}}},[]),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))/Vt;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=Gt(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=Gt(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:Ht})}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 Gt(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Kt=new Map;function qt(...e){let t={...zt},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 Kt.has(r)||Kt.set(r,Object.freeze(t)),n?`instant`:Kt.get(r)}var Jt=60,Yt=8,Xt=1400;function Zt(e){if(e.scrollHeight<=e.clientHeight)return!1;let t=getComputedStyle(e).overflowY;return t===`auto`||t===`scroll`}function Qt(e,t){let n=[],r=e.parentElement;for(;r&&r!==t;)Zt(r)&&n.push(r),r=r.parentElement;return n}function $t(){return typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches}function en(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 tn(e,t,n,r){let i=e.scrollTop+t.getBoundingClientRect().top-e.getBoundingClientRect().top-n;e.scrollTo({top:i,behavior:r?`smooth`:`auto`})}function nn(e,t){let n=en(e,t);if(!n)return()=>{};let{el:r,level:i}=n;for(let t of Qt(r,e))tn(t,r,Yt,!1);tn(e,r,Jt,!$t()),r.dataset.flash=i;let a=setTimeout(()=>{delete r.dataset.flash},Xt);return()=>{clearTimeout(a),delete r.dataset.flash}}var rn=new Set([`Write`,`Edit`,`MultiEdit`,`NotebookEdit`]),an={create:3,write:2,notebook:2,edit:1};function on(e){return typeof e==`string`?e:``}function sn(e,t){let n=0,r=0;for(let i of pt(e,t))i.added?n+=i.count??0:i.removed&&(r+=i.count??0);return{added:n,removed:r}}function cn(e){return e&&/created successfully/i.test(e)?`create`:`write`}function ln(e,t,n){switch(e){case`Write`:{let e=on(t.file_path);return e?{filePath:e,op:cn(n),fragments:[{oldStr:``,newStr:on(t.content)}]}:null}case`Edit`:{let e=on(t.file_path);return e?{filePath:e,op:`edit`,fragments:[{oldStr:on(t.old_string),newStr:on(t.new_string)}]}:null}case`MultiEdit`:{let e=on(t.file_path);if(!e||!Array.isArray(t.edits))return null;let n=t.edits.filter(e=>!!e&&typeof e==`object`).map(e=>({oldStr:on(e.old_string),newStr:on(e.new_string)}));return n.length===0?null:{filePath:e,op:`edit`,fragments:n}}case`NotebookEdit`:{let e=on(t.notebook_path)||on(t.file_path);return e?{filePath:e,op:`notebook`,fragments:[{oldStr:``,newStr:on(t.new_source)}]}:null}default:return null}}function un(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),un(n.children,t)}}}function dn(e,t,n,r){if(e)for(let i of e){if(i.type!==`tool_use`||(i.children?.length&&dn(i.children,!0,n,r),!rn.has(i.tool)))continue;let e=i.input&&typeof i.input==`object`?i.input:null;if(!e)continue;let a=ln(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)),an[a.op]>an[o.op]&&(o.op=a.op),t&&(o.viaSubagent=!0),a.fragments.forEach((e,n)=>{let{added:r,removed:a}=sn(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 fn(e){let t=new Map;for(let n of e)un(n.events,t);let n=new Map;for(let r of e)dn(r.events,!1,n,t);return[...n.values()]}function pn(e,t){let n=[];for(let r=t;r>=0&&e[r]?.role===`assistant`;r--)n.unshift(e[r]);return n}var $=n();function mn(e){try{return new Date(e).toLocaleString()}catch{return``}}function hn({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 gn({content:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsx)(hn,{icon:t?(0,$.jsx)(o,{className:`size-3.5`}):(0,$.jsx)(it,{className:`size-3.5`}),label:t?`Copied`:`Copy`,title:`Copy message to clipboard`,onClick:()=>{Ze(e),n(!0),setTimeout(()=>n(!1),1500)}})}function _n({timestamp:e,content:t,accountLabel:n,className:r,children:i}){return(0,$.jsxs)(`div`,{className:F(`flex items-center gap-0.5 flex-wrap text-xs text-text-subtle select-none`,r),children:[(0,$.jsx)(`time`,{title:mn(e),className:`pr-1 tabular-nums`,children:ct(e)}),n&&(0,$.jsxs)(`span`,{className:`px-1 truncate max-w-40`,children:[`via `,n]}),(0,$.jsx)(gn,{content:t}),i]})}function vn(e){let t=0,n=0;for(let r of e)t+=r.linesAdded,n+=r.linesRemoved;return{added:t,removed:n}}function yn({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:F(`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 bn(e){if(!e)return!1;let t=e.closest(`[data-tab-pool-id]`)?.dataset.tabPoolId;if(!t)return e.offsetParent!==null;let{panels:n,focusedPanelId:r}=ae.getState();return n[r]?.activeTabId===t}var xn={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 Sn(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 Cn({added:e,removed:t,editCount:n,className:r}){return(0,$.jsxs)(`span`,{className:F(`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 wn({change:e,dense:t,selected:n,onClick:r}){let i=xn[e.op],{base:a,dir:o}=Sn(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:F(`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:F(`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)(Cn,{added:e.linesAdded,removed:e.linesRemoved,editCount:e.editCount,className:`text-[11px]`}),(0,$.jsx)(d,{className:`size-[11px] text-text-subtle`})]})}var Tn=(0,Q.lazy)(()=>re(()=>import(`./edit-diff-preview-_CXUdwsF.js`),__vite__mapDeps([0,1,2,3])));function En({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)(ke,{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)(Tn,{oldStr:n.oldStr,newStr:n.newStr,filePath:e.filePath})})})]},n.editRef??r))})}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)}}var On=null;function kn(e){return e instanceof HTMLElement?e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.isContentEditable:!1}function An({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)(()=>(On=s,o.current?.querySelector(`button`)?.focus(),()=>{On===s&&(On=null)}),[s]),(0,Q.useEffect)(()=>{let o=o=>{if(On===s&&bn(a.current)&&!kn(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}=Dn(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)(wn,{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)(Cn,{added:c.linesAdded,removed:c.linesRemoved,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void Ze(c.filePath),className:`shrink-0 rounded-md px-1.5 py-1 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:`copy path`}),(0,$.jsx)(`button`,{type:`button`,onClick:n,"aria-label":`Close change tray`,className:`inline-flex size-8 shrink-0 items-center justify-center rounded-lg text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:(0,$.jsx)(ne,{className:`size-3.5`})})]}),(0,$.jsx)(En,{change:c,onJump:t})]})]})})}function jn(e){let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`));return t<0?e:e.slice(t+1)}function Mn({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 Nn({changes:e,totals:t,open:n,onClose:r,onJump:i}){let[a,o]=(0,Q.useState)(null),s=a==null?null:e[a],l=(0,Q.useRef)(null),u=()=>{o(null),r()},d=e=>{u(),i(e)};return(0,Q.useEffect)(()=>{if(!n)return;let e=l.current,t=()=>Array.from(e?.querySelectorAll(`button:not([disabled])`)??[]);t()[0]?.focus();let r=e=>{if(e.key===`Escape`){e.preventDefault(),u();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)(c,{open:n,onClose:u,className:`flex max-h-[85%] flex-col rounded-t-[14px] motion-reduce:animate-none`,children:(0,$.jsx)(`div`,{ref:l,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)(Mn,{label:`Back to file list`,onClick:()=>o(null),children:(0,$.jsx)(at,{className:`size-4`})}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs font-medium text-text-primary`,children:jn(s.filePath)}),(0,$.jsx)(Cn,{added:s.linesAdded,removed:s.linesRemoved,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(Mn,{label:`Close`,onClick:u,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 Ze(s.filePath),className:`inline-flex min-h-11 shrink-0 items-center rounded-md px-2.5 font-mono text-[10px] text-text-subtle transition-colors hover:bg-surface hover:text-text-primary`,children:`copy`}),s.edits[0]?.editRef&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d(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)(ke,{className:`size-3`}),`card`]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,$.jsx)(En,{change:s,onJump:d})})]}):(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)(Cn,{added:t.added,removed:t.removed,className:`shrink-0 font-mono text-[11px]`}),(0,$.jsx)(Mn,{label:`Close`,onClick:u,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)(wn,{change:e,onClick:()=>o(t)},e.filePath))})]})})})}function Pn({timestamp:e,content:t,accountLabel:n,changes:r,onJumpToEdit:i}){let[a,o]=(0,Q.useState)(!1),s=l(),c=(0,Q.useRef)(null),u=()=>{o(!1),c.current?.focus()},d=(0,$.jsx)(_n,{timestamp:e,content:t,accountLabel:n,className:`-mt-1.5`,children:r&&r.length>0&&(0,$.jsx)(yn,{ref:c,count:r.length,totals:vn(r),open:a,onToggle:()=>a?u():o(!0)})});return!r||r.length===0?d:(0,$.jsxs)($.Fragment,{children:[d,s?(0,$.jsx)(Nn,{changes:r,totals:vn(r),open:a,onClose:u,onJump:i??(()=>{})}):a&&(0,$.jsx)(An,{changes:r,onJump:e=>{o(!1),i?.(e)},onClose:u})]})}function Fn(e,t,n,r){let[i,a]=(0,Q.useState)([]),o=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(!n||!e||!t){a([]);return}let r=!1;return o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{N.get(`/api/project/${encodeURIComponent(e)}/chat/sessions/${encodeURIComponent(t)}/tasks`).then(e=>{r||a(e)}).catch(()=>{})},300),()=>{r=!0,o.current&&clearTimeout(o.current)}},[e,t,n,r]),i}var In=new Set([`TaskCreate`,`TaskUpdate`,`TaskStop`]);function Ln(e){let t=0;for(let n of e)if(n.events)for(let e of n.events)e.type===`tool_use`&&In.has(e.tool)&&t++;return t}var Rn={completed:{icon:`✓`,cls:`text-success`},in_progress:{icon:`▶`,cls:`text-warning`},stopped:{icon:`■`,cls:`text-text-subtle`},pending:{icon:`○`,cls:`text-text-subtle`}};function zn({projectName:e,sessionId:t,messages:n}){let r=(0,Q.useMemo)(()=>Ln(n),[n]),i=Fn(e,t,r>0,r),[a,o]=(0,Q.useState)(!0);if(i.length===0||i.every(e=>e.status===`completed`||e.status===`stopped`))return null;let s=i.filter(e=>e.status===`completed`).length,c=i.length,l=c?Math.round(s/c*100):0;return(0,$.jsxs)(`div`,{className:`shrink-0 border-b border-border bg-surface/60 backdrop-blur-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`flex items-center gap-2 w-full px-3 min-h-11 text-left text-xs hover:bg-surface transition-colors`,children:[a?(0,$.jsx)(d,{className:`size-3.5 shrink-0`}):(0,$.jsx)(u,{className:`size-3.5 shrink-0`}),(0,$.jsx)(h,{className:`size-3.5 shrink-0 text-text-secondary`}),(0,$.jsx)(`span`,{className:`text-text-primary font-medium`,children:`Tasks`}),(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[s,`/`,c,` done`]}),(0,$.jsx)(`span`,{className:`ml-auto h-1 w-16 rounded-full bg-border overflow-hidden shrink-0`,children:(0,$.jsx)(`span`,{className:`block h-full bg-success/70`,style:{width:`${l}%`}})})]}),!a&&(0,$.jsx)(`ul`,{className:`px-3 pb-2 space-y-0.5 max-h-48 overflow-y-auto`,children:i.map(e=>(0,$.jsx)(Bn,{task:e},e.id))})]})}function Bn({task:e}){let t=Rn[e.status]??Rn.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 Vn=/read the full transcript at:\s*(\S+\.jsonl)/i;function Hn(e){return e.match(Vn)?.[1]?.trim()??null}var Un=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 Wn({projectName:e,onSelectSession:t}){return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-6 text-text-secondary overflow-y-auto`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,$.jsx)(i,{className:`size-10 text-text-subtle`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Send a message to start a new conversation`})]}),(0,$.jsx)(Ge,{projectName:e,onSelectSession:t,className:`w-full px-4`})]})}var Gn=3200,Kn=1e3,qn={hasAbove:!1,atBottom:!0,idx:0,total:0};function Jn({scrollElement:e,userIndices:t,scrollToBottom:n}){let r=l(),[i,a]=(0,Q.useState)(qn),[o,s]=(0,Q.useState)(!1),[c,d]=(0,Q.useState)(0),f=(0,Q.useRef)(Gn),p=(0,Q.useRef)(null),m=(0,Q.useRef)(null),h=(0,Q.useRef)(!1),g=(0,Q.useRef)(!1),_=(e,t,n)=>t.getBoundingClientRect().top-n+e.scrollTop,v=(0,Q.useCallback)(e=>Array.from(e.querySelectorAll(`[data-msg-index]`)).filter(e=>t.includes(Number(e.dataset.msgIndex))),[t]);(0,Q.useEffect)(()=>{let t=e;if(!t)return;let n=0,r=()=>{let e=t.scrollTop,n=t.getBoundingClientRect().top,r=v(t).map(e=>_(t,e,n)),i=0;for(let t=0;t<r.length;t++)r[t]<=e+12&&(i=t+1);let o={hasAbove:r.some(t=>t<e-4),atBottom:t.scrollHeight-e-t.clientHeight<8,idx:i,total:r.length};a(e=>e.hasAbove===o.hasAbove&&e.atBottom===o.atBottom&&e.idx===o.idx&&e.total===o.total?e:o)},i=()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(r)};r(),t.addEventListener(`scroll`,i,{passive:!0});let o=new ResizeObserver(i);return o.observe(t),()=>{n&&cancelAnimationFrame(n),t.removeEventListener(`scroll`,i),o.disconnect()}},[e,v]),(0,Q.useEffect)(()=>{if(!o)return;let e=setTimeout(()=>s(!1),f.current);return()=>clearTimeout(e)},[o,i.idx,c]),(0,Q.useEffect)(()=>{if(!o||!g.current)return;g.current=!1;let e=p.current;(e?.querySelector(`button:not(:disabled)`)??e)?.focus()},[o]),(0,Q.useEffect)(()=>{o||!h.current||(h.current=!1,m.current?.focus())},[o]);let y=(0,Q.useCallback)(()=>{f.current=Gn,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=>()=>{bn(t)&&(e(),f.current=Kn,s(!0))},r=n(b),i=n(x);return window.addEventListener(`chat-nav-prev`,r),window.addEventListener(`chat-nav-next`,i),()=>{window.removeEventListener(`chat-nav-prev`,r),window.removeEventListener(`chat-nav-next`,i)}},[e,b,x]);let C=F(`w-[34px] flex items-center justify-center rounded-[9px] text-text-secondary`,`motion-safe:transition-colors hover:bg-surface-elevated hover:text-foreground`,`disabled:opacity-30 disabled:cursor-default disabled:hover:bg-transparent disabled:hover:text-text-secondary`,r?`h-9`:`h-[30px]`);return(0,$.jsx)(`div`,{className:`absolute bottom-3 right-2.5 z-10 flex flex-col items-end gap-1.5`,children:o?(0,$.jsxs)(`div`,{ref:p,tabIndex:-1,className:`flex flex-col p-[3px] rounded-xl border border-border bg-surface-elevated/95 backdrop-blur-[8px] shadow-lg outline-none`,onFocus:()=>{h.current=!0},onKeyDown:e=>{e.key===`Escape`&&s(!1)},children:[(0,$.jsx)(`button`,{type:`button`,onClick:b,disabled:!i.hasAbove,"aria-label":`Jump to previous message`,className:C,children:(0,$.jsx)(Le,{className:`size-[15px]`})}),(0,$.jsx)(`span`,{className:`font-mono text-[10px] font-medium text-text-subtle text-center py-px`,"aria-label":`Message ${i.idx||1} of ${i.total}`,children:i.total?`${i.idx||1}/${i.total}`:`0/0`}),(0,$.jsx)(`button`,{type:`button`,onClick:x,disabled:i.atBottom,"aria-label":`Jump to next message`,className:C,children:(0,$.jsx)(u,{className:`size-[15px]`})}),(0,$.jsx)(`button`,{type:`button`,onClick:S,disabled:i.atBottom,"aria-label":`Jump to latest`,className:C,children:(0,$.jsx)(ht,{className:`size-[13px]`})})]}):(0,$.jsx)(`button`,{ref:m,type:`button`,onClick:()=>{f.current=Gn,g.current=!0,s(!0)},"aria-label":`Navigate messages`,"aria-expanded":!1,title:`Navigate messages`,className:F(`group flex items-center justify-center`,r?`size-11`:`size-[30px]`),children:(0,$.jsx)(`span`,{className:F(`flex items-center justify-center rounded-full border border-border bg-surface-elevated/55 backdrop-blur-[6px] text-text-subtle`,`motion-safe:transition-colors group-hover:bg-surface-elevated group-hover:text-foreground`,r?`size-9`:`size-[30px]`),children:(0,$.jsx)(He,{className:`size-[15px]`})})})})}function Yn({group:e,onNavigate:t,disabled:n}){if(!e||e.ids.length<2)return null;let{ids:r,currentIndex:i}=e,a=e=>{let i=r[e];i&&!n&&t(i)};return(0,$.jsxs)(`div`,{className:`mt-1 flex items-center gap-1 text-xs text-text-subtle select-none`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>a(i-1),disabled:n||i<=0,"aria-label":`Previous version`,className:`flex items-center justify-center rounded p-0.5 hover:text-text-primary disabled:opacity-30 disabled:cursor-default`,children:(0,$.jsx)(at,{className:`size-3.5`})}),(0,$.jsxs)(`span`,{className:`tabular-nums`,children:[i+1,`/`,r.length]}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>a(i+1),disabled:n||i>=r.length-1,"aria-label":`Next version`,className:`flex items-center justify-center rounded p-0.5 hover:text-text-primary disabled:opacity-30 disabled:cursor-default`,children:(0,$.jsx)(d,{className:`size-3.5`})})]})}function Xn(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 Zn(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 Qn({questions:e,onSubmit:t,onSkip:n}){let r=(0,Q.useRef)(null),i=Xn(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=Zn({questions:e,activeTab:i.activeTab,totalOptions:o,allAnswered:i.allAnswered,hasAnswer:i.hasAnswer,onSelectOption:l,goToNextTab:i.goToNextTab,goToPrevTab:i.goToPrevTab,onSubmit:c,customInputRef:r,enabled:!0}),d=(0,Q.useCallback)(e=>{l(e),u.setFocusedOption(e)},[l,u.setFocusedOption]);return(0,$.jsxs)(`div`,{ref:u.containerRef,className:`rounded-lg border-2 border-primary/30 bg-primary/5 p-3 space-y-3 outline-none animate-in slide-in-from-bottom-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,$.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,$.jsxs)(`span`,{className:`text-[10px] text-text-secondary font-normal`,children:[s?`←→ tabs · `:``,`↑↓ options · 1-`,Math.min(o-1,9),` select · Enter submit`]})]}),s&&(0,$.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,$.jsxs)(`button`,{className:`flex items-center gap-1.5 px-3 py-1.5 rounded text-xs whitespace-nowrap transition-all ${i.activeTab===t?`bg-primary text-primary-foreground`:i.hasAnswer(t)?`text-primary bg-transparent`:`text-text-secondary hover:bg-surface-elevated`}`,onClick:()=>{i.setActiveTab(t),u.setFocusedOption(0)},tabIndex:-1,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-semibold ${i.activeTab===t?`bg-white/20`:i.hasAnswer(t)?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:i.hasAnswer(t)?`✓`:t+1}),(0,$.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,$.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,$.jsx)(`div`,{className:`text-sm text-text-primary select-text`,children:a.question}),a.multiSelect&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a.options.map((e,t)=>{let n=(i.answers[i.activeTab]||[]).includes(e.label),r=u.focusedOption===t;return(0,$.jsxs)(`div`,{role:`button`,onClick:()=>d(t),className:`text-left flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border transition-all cursor-pointer select-text ${n?`border-primary bg-primary/10 text-text-primary`:`border-border bg-background text-text-secondary hover:border-primary/40 hover:bg-primary/5`} ${r?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded text-[10px] font-semibold shrink-0 mt-px ${n?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:t+1}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,$.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,$.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border border-dashed transition-all border-border bg-transparent ${u.focusedOption===o-1?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded bg-surface-elevated text-text-secondary text-[10px] font-semibold shrink-0 mt-px`,children:`O`}),(0,$.jsx)(`input`,{ref:r,type:`text`,className:`flex-1 px-2 py-1 text-xs bg-surface border border-border rounded text-text-primary outline-none placeholder:text-text-subtle focus:border-primary`,placeholder:`Other (press O to type)...`,value:i.customInputs[i.activeTab]||``,onChange:e=>i.handleCustomInput(i.activeTab,e.target.value),onFocus:()=>u.setFocusedOption(o-1)})]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToPrevTab,disabled:i.activeTab===0,tabIndex:-1,children:`← Prev`}),(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToNextTab,disabled:i.activeTab===e.length-1,tabIndex:-1,children:`Next →`})]}),(0,$.jsx)(`button`,{onClick:n,className:`px-4 py-1.5 rounded border border-border bg-background text-text-secondary text-xs hover:bg-surface-elevated transition-colors`,tabIndex:-1,children:`Skip`}),(0,$.jsxs)(`button`,{onClick:c,disabled:!i.allAnswered,className:`px-4 py-1.5 rounded bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,tabIndex:-1,children:[`Submit `,i.allAnswered?`✓`:`(${e.filter((e,t)=>i.hasAnswer(t)).length}/${e.length})`]})]})]})}var $n={"system-reminder":`Context`,claudeMd:`CLAUDE.md`,gitStatus:`Git Status`,currentDate:`Date`,fast_mode_info:`Fast Mode`,"available-deferred-tools":`Tools`,"task-notification":`Task Result`,environment_details:`Environment`,"local-command-caveat":`System`};function er(e){let t=[],n=/<(system-reminder|available-deferred-tools|antml:[\w-]+|fast_mode_info|claudeMd|gitStatus|currentDate|task-notification|environment_details|local-command-caveat)[^>]*>([\s\S]*?)<\/\1>/g,r;for(;(r=n.exec(e))!==null;){let e=r[1];t.push({name:e,label:$n[e]??e.replace(/^antml:/,``).replace(/-/g,` `),content:r[2].trim()})}return{cleanText:e.replace(n,``).trim(),tags:t}}function tr(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 nr(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 rr(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 ir(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 ar(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 or(e){let{idePath:t,cleanText:n}=rr(e),{blocks:r,remainingText:i}=ar(n),a=ir(i),{cleanText:o,tags:s}=er(a.text.replace(/<local-command-(?:stdout|stderr)>([\s\S]*?)<\/local-command-(?:stdout|stderr)>/g,`$1`)),{command:c,cleanText:l}=tr(o),{agent:u,cleanText:d}=nr(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 sr(e){let{agent:t,body:n,command:r}=or(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 cr=re(()=>import(`./markdown-renderer-C9Gy8tM2.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])),lr=(0,Q.lazy)(()=>cr.then(e=>({default:e.MarkdownRenderer})));function ur({messages:e,messagesLoading:t,keepStaleWhileLoading:n,pendingApproval:r,onApprovalResponse:a,isStreaming:o,phase:s,onSelectSession:c,connectingElapsed:l,statusMessage:u,compactStatus:d,projectName:p,onFork:m,onEdit:h,editingMsgId:g,sessionId:_,providerId:v,onNavigateVersion:y,versionMap:b,bashPartialOutput:x,onExpandCompact:S,isCompactExpanded:C,onDismissMessage:w,onClearErrors:T}){let{scrollRef:E,contentRef:ee,scrollToBottom:D,stopScroll:te,isAtBottom:O}=Wt({initial:`instant`,resize:`instant`}),k=(0,Q.useMemo)(()=>e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return e.role===`user`?t:t||n}),[e]),ne=!!r||o,[A,j]=(0,Q.useState)(null),M=(0,Q.useCallback)(e=>{E(e),j(e)},[E]),N=(0,Q.useRef)(new Map),re=(0,Q.useMemo)(()=>{let e=N.current,t=new Map;for(let n=0;n<k.length;n++){let r=k[n];if(r.role!==`assistant`||k[n+1]?.role===`assistant`)continue;let i=`${r.id}:${r.events?.length??0}`,a=e.get(i);a||(a=fn(pn(k,n)),e.set(i,a)),a.length>0&&t.set(n,a)}return t},[k]),P=(0,Q.useRef)(null),F=(0,Q.useCallback)(e=>{A&&(P.current?.(),P.current=nn(A,e))},[A]);(0,Q.useEffect)(()=>()=>P.current?.(),[]);let ie=(0,Q.useRef)(null);(0,Q.useLayoutEffect)(()=>{let e=A;e&&ie.current!=null&&(e.scrollTop=e.scrollHeight-ie.current,ie.current=null)},[k.length,A]),(0,Q.useLayoutEffect)(()=>{A&&D({animation:`instant`})},[_,A]);let I=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>{A&&A.clientHeight>0&&(I.current=O)},[O,A]),(0,Q.useEffect)(()=>{let e=A;if(!e)return;let t=e.clientHeight,n=new ResizeObserver(()=>{let n=e.clientHeight,r=t===0&&n>0;t=n,r&&!I.current&&te()});return n.observe(e),()=>n.disconnect()},[A,te]);let ae=(0,Q.useCallback)((e,t)=>{m?.(e,t)},[m]),L=(0,Q.useCallback)((e,t,n)=>{h?.(e,t,n)},[h]),oe=(0,Q.useCallback)(e=>{w?.(e)},[w]),R=(0,Q.useMemo)(()=>k.reduce((e,t)=>t.role===`system`?e+1:e,0),[k]),se=(0,Q.useMemo)(()=>k.reduce((e,t,n)=>(t.role===`user`&&e.push(n),e),[]),[k]),z=(0,Q.useCallback)(()=>{if(!S||!C)return null;for(let e of k){if(C(e.id))continue;let t=Hn(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=Hn(t.content||``);if(n)return{id:e.id,jsonlPath:n}}}}return null},[k,S,C])(),ce=!!z,[le,ue]=(0,Q.useState)(!1),B=(0,Q.useCallback)(async()=>{if(!z||!S||le)return;let e=A;ie.current=e?e.scrollHeight-e.scrollTop:null,ue(!0);try{await S(z.id,z.jsonlPath)}finally{ue(!1)}},[z,S,le,A]);return(0,Q.useEffect)(()=>{let e=A;if(!e||!ce)return;let t=()=>{e.scrollTop<200&&!le&&B()};return e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[A,ce,le,B]),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)(Wn,{projectName:p||``,onSelectSession:c||(()=>{})}):(0,$.jsxs)(`div`,{className:`relative flex-1 overflow-hidden flex flex-col min-h-0`,children:[(0,$.jsx)(zn,{projectName:p,sessionId:_,messages:e}),R>1&&T&&(0,$.jsx)(`div`,{className:`absolute top-2 left-0 right-0 z-20 flex justify-center pointer-events-none`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:T,className:`pointer-events-auto flex items-center gap-1.5 rounded-full bg-error/15 border border-error/25 px-3 py-1 text-xs text-error hover:bg-error/25 shadow-md backdrop-blur-sm`,children:[(0,$.jsx)(f,{className:`size-3.5`}),`Clear all errors (`,R,`)`]})}),le&&(0,$.jsxs)(`div`,{className:`absolute top-2 left-0 right-0 z-10 flex items-center justify-center gap-1.5 text-xs text-text-secondary pointer-events-none`,children:[(0,$.jsx)(X,{className:`size-3 animate-spin`}),`Loading previous conversation...`]}),(0,$.jsx)(`div`,{ref:M,className:`flex-1 overflow-y-auto overflow-x-hidden [overflow-anchor:none]`,style:{WebkitOverflowScrolling:`touch`,overscrollBehavior:`contain`},children:(0,$.jsxs)(`div`,{ref:ee,className:`w-full`,children:[k.map((e,t)=>{let n=t>0?k[t-1]:void 0,r=e.role===`user`?k.slice(0,t+1).reduce((e,t)=>e+(t.role===`user`?1:0),0):0,i=r?b?.[r]:void 0,a=e.role===`user`&&g!=null&&e.id===g,s=k[t+1],c=e.role===`assistant`&&s?.role!==`assistant`,l;if(c){let e=[];for(let n=t;n>=0&&k[n].role===`assistant`;n--){let t=dr(k[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)(Un,{fallbackContent:e.content,children:(0,$.jsx)(fr,{message:e,isStreaming:o&&e.id.startsWith(`streaming-`),isLastAssistantInTurn:c,turnCopyText:l,turnChanges:c?re.get(t):void 0,onJumpToEdit:F,projectName:p,onFork:e.role===`user`&&m?ae:void 0,onEdit:e.role===`user`&&h?L:void 0,isEditing:a,onDismiss:e.role===`system`&&w?oe:void 0,prevMsgId:n?.sdkUuid??n?.id,sessionId:_,providerId:v,versionGroup:i,onNavigateVersion:y,versionNavDisabled:o,bashPartialOutput:x})})},e.id)}),ne&&(0,$.jsxs)(`div`,{className:`px-4 pt-4 pb-4 space-y-4 select-none`,children:[r&&(r.tool===`AskUserQuestion`?(0,$.jsx)(Lr,{approval:r,onRespond:a}):(0,$.jsx)(Ir,{approval:r,onRespond:a})),o&&(0,$.jsx)(Mr,{lastMessage:e[e.length-1],phase:s,elapsed:l,statusMessage:d===`compacting`?`Compacting messages...`:u})]})]})}),(0,$.jsx)(Jn,{scrollElement:A,userIndices:se,scrollToBottom:D})]})}function dr(e){return e.events?.length?e.events.filter(e=>e.type===`text`).map(e=>e.content).join(``):e.content}var fr=(0,Q.memo)(function({message:e,isStreaming:t,isLastAssistantInTurn:n,turnCopyText:r,turnChanges:i,onJumpToEdit:a,projectName:o,onFork:s,onEdit:c,isEditing:l,onDismiss:u,prevMsgId:d,sessionId:p,providerId:m,versionGroup:h,onNavigateVersion:g,versionNavDisabled:_,bashPartialOutput:v}){if(e.role===`user`){let t=s?()=>s(e.content,d):void 0,n=c?()=>c(e.content,d,e.id):void 0;return(0,$.jsx)(_r,{content:e.content,messageId:e.id,timestamp:e.timestamp,projectName:o,onFork:t,onEdit:n,isEditing:l,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)(We,{className:`size-4 shrink-0`}),(0,$.jsx)(`p`,{className:`flex-1`,children:e.content}),u&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>u(e.id),"aria-label":`Dismiss`,title:`Dismiss`,className:`shrink-0 rounded p-1 text-error/70 hover:text-error hover:bg-error/15 md:opacity-0 md:group-hover:opacity-100`,children:(0,$.jsx)(f,{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)(Fr,{content:e.content,projectName:o})}),!t&&n&&(0,$.jsx)(Pn,{timestamp:e.timestamp,content:r??dr(e),accountLabel:e.accountLabel,changes:i,onJumpToEdit:a})]})}),pr=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]);function mr(e,t){let n=I(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function hr(e){let t=e.lastIndexOf(`.`);return t===-1?!1:pr.has(e.slice(t).toLowerCase())}var gr=new Set([`task-notification`,`environment_details`,`local-command-caveat`]);function _r({content:e,messageId:t,timestamp:n,projectName:r,onFork:a,onEdit:o,isEditing:c,sessionId:l,providerId:d,versionGroup:f,onNavigateVersion:p,versionNavDisabled:m}){let{files:h,text:g,tags:_,command:v,terminalBlocks:y,idePath:b,agent:x}=(0,Q.useMemo)(()=>or(e),[e]),S=_.some(e=>gr.has(e.name)),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(!1),ee=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let e=ee.current;if(!e)return;let t=()=>E(e.scrollHeight>e.clientHeight+2);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[g]),(0,$.jsxs)(`div`,{className:F(`flex flex-col gap-1`,!S&&`items-end`),children:[(0,$.jsxs)(`div`,{"data-user-message":S?void 0:`true`,style:S?void 0:{borderRadius:`var(--rad) var(--rad) 4px var(--rad)`},className:F(`group/user relative px-3 py-2 text-sm border shadow-sm transition-all`,S?`rounded-lg bg-surface/40 border-border/40 text-text-secondary`:`max-w-[80%] bg-accent-wash border-accent-wash-border text-text`,c&&`ring-2 ring-primary/60 border-primary/40`),children:[_.length>0&&(0,$.jsx)(yr,{tags:_}),x&&(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-sky-500/15 border border-sky-500/25 px-2 py-0.5 text-xs font-medium text-sky-600 dark:text-sky-400`,children:[(0,$.jsx)(i,{className:`size-3 shrink-0`}),x]})}),v&&(0,$.jsx)(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-primary/15 border border-primary/20 px-2 py-0.5 text-xs font-medium text-primary`,children:[(0,$.jsx)(St,{className:`size-3 shrink-0`}),v.name]})}),b&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-1 text-[11px] text-text-subtle`,children:[(0,$.jsx)(`span`,{className:`shrink-0`,children:`Opened in IDE:`}),(0,$.jsx)(Cr,{path:b,projectName:r})]}),h.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:h.map((e,t)=>hr(e)?(0,$.jsx)(Or,{filePath:e,projectName:r},t):(0,$.jsxs)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-background/40 px-1.5 py-0.5 text-[11px] text-text-secondary`,children:[(0,$.jsx)(Qe,{className:`size-3 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-32`,children:I(e)})]},t))}),y.length>0&&(0,$.jsx)(`div`,{className:`space-y-1.5`,children:y.map((e,t)=>(0,$.jsx)(vr,{content:e},t))}),g&&(0,$.jsx)(`div`,{ref:ee,className:F(`whitespace-pre-wrap break-words transition-all duration-200 select-text`,!C&&`line-clamp-2`,C&&`max-h-[50vh] overflow-y-auto`),children:S?(0,$.jsx)(Tr,{text:g,projectName:r}):(0,$.jsx)(wr,{text:g})}),(T||C)&&(0,$.jsx)(`button`,{onClick:()=>w(!C),className:F(`flex items-center gap-1 text-xs mt-1 transition-colors`,S?`text-text-subtle hover:text-text-secondary`:`text-primary/70 hover:text-primary`),children:C?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Le,{className:`size-3`}),`Show less`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(u,{className:`size-3`}),`Show more`]})}),!S&&p&&(0,$.jsx)(Yn,{group:f,onNavigate:p,disabled:m})]}),!S&&(0,$.jsxs)(_n,{timestamp:n,content:e,children:[o&&(0,$.jsx)(hn,{icon:(0,$.jsx)(s,{className:`size-3.5`}),label:`Edit`,title:`Edit this message (continue in the same tab)`,onClick:o}),a&&(0,$.jsx)(hn,{icon:(0,$.jsx)(Ne,{className:`size-3.5`}),label:`Fork`,title:`Retry from this message (fork into a new tab)`,onClick:a})]})]})}function vr({content:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),className:F(`flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs transition-colors`,t?`border-primary/50 bg-surface-elevated text-text-primary`:`border-border/60 bg-background/40 text-text-secondary hover:bg-surface`),children:[(0,$.jsx)(xe,{className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{children:`Terminal output`}),(0,$.jsx)(u,{className:F(`size-3 shrink-0 transition-transform`,t&&`rotate-180`)})]}),t&&(0,$.jsx)(`pre`,{className:`mt-1 max-h-40 overflow-auto rounded-md border border-border bg-background p-2 text-xs text-text-primary font-mono whitespace-pre-wrap break-words`,children:e})]})}function yr({tags:e}){return(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,$.jsx)(br,{tag:e},t))})}function br({tag:e}){let[t,n]=(0,Q.useState)(!1);return e.name===`task-notification`?(0,$.jsx)(Sr,{content:e.content}):(0,$.jsxs)(`div`,{className:`text-xs`,children:[(0,$.jsxs)(`button`,{onClick:()=>n(!t),className:`flex items-center gap-1 rounded-full border border-border/60 bg-surface/50 px-2 py-0.5 text-text-subtle hover:text-text-secondary hover:bg-surface transition-colors`,children:[(0,$.jsx)(he,{className:`size-2.5`}),(0,$.jsx)(`span`,{children:e.label}),(0,$.jsx)(d,{className:F(`size-2.5 transition-transform`,t&&`rotate-90`)})]}),t&&(0,$.jsx)(`div`,{className:`mt-1 rounded border border-border/40 bg-surface/30 px-2 py-1.5 text-[11px] text-text-subtle/80 whitespace-pre-wrap max-h-40 overflow-y-auto leading-relaxed`,children:e.content})]})}function xr(e,t){return e.match(RegExp(`<${t}>([\\s\\S]*?)</${t}>`))?.[1]?.trim()||void 0}function Sr({content:e}){let[t,n]=(0,Q.useState)(!1),r=xr(e,`status`),i=xr(e,`summary`),a=xr(e,`output-file`),o=xr(e,`result`);return(0,$.jsxs)(`div`,{className:`text-xs`,children:[(0,$.jsxs)(`button`,{onClick:()=>n(!t),className:`flex items-center gap-1.5 rounded-full border border-border/60 bg-surface/50 px-2 py-0.5 text-text-subtle hover:text-text-secondary hover:bg-surface transition-colors`,children:[r===`completed`?(0,$.jsx)(Ye,{className:`size-2.5 text-success`}):(0,$.jsx)(f,{className:`size-2.5 text-warning`}),(0,$.jsx)(`span`,{className:`truncate max-w-80`,children:i??`Task notification`}),(0,$.jsx)(d,{className:F(`size-2.5 transition-transform shrink-0`,t&&`rotate-90`)})]}),t&&(0,$.jsxs)(`div`,{className:`mt-1 rounded border border-border/40 bg-surface/30 px-2 py-1.5 space-y-1.5`,children:[i&&(0,$.jsx)(`p`,{className:`text-[11px] text-text-secondary`,children:i}),a&&(0,$.jsx)(Cr,{path:a}),o&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-subtle/80 max-h-60 overflow-y-auto leading-relaxed`,children:(0,$.jsx)(Fr,{content:o})})]})]})}function Cr({path:e,projectName:t}){return(0,$.jsxs)(`button`,{type:`button`,onClick:(0,Q.useCallback)(()=>{let n=oe.getState().openTab,r=t??L.getState().activeProject?.name,i=I(e),a={filePath:e};r&&(a.projectName=r),N.get(`/api/fs/read?path=${encodeURIComponent(e)}`).then(()=>{n({type:`editor`,title:i,metadata:a,projectId:null,closable:!0})}).catch(()=>{n({type:`editor`,title:i,metadata:a,projectId:null,closable:!0})})},[e,t]),className:`inline-flex items-center gap-1 rounded border border-border/50 bg-surface/50 px-1.5 py-0.5 font-mono text-[10px] text-text-secondary hover:text-text-primary hover:bg-surface transition-colors cursor-pointer`,children:[(0,$.jsx)(Qe,{className:`size-2.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-60`,children:I(e)}),(0,$.jsx)(Je,{className:`size-2 shrink-0 opacity-50`})]})}function wr({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 Tr({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)(Cr,{path:e.value,projectName:t},n):(0,$.jsx)(`span`,{children:e.value},n))})}var Er=new Map;function Dr(e){let[t,n]=(0,Q.useState)(()=>Er.get(e)?.url??null),[r,i]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{let t=Er.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);Er.set(e,{url:i}),n(i)}).catch(()=>{r||i(!0)}),()=>{r=!0}},[e]),{blobUrl:t,error:r}}function Or({filePath:e,projectName:t}){let{blobUrl:n,error:r}=Dr(mr(e,t)),i=tt(e=>e.open),a=I(e);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n&&i(n,a),className:`flex items-center gap-1 rounded-md border border-border/60 bg-background/40 px-1.5 py-0.5 text-[11px] text-text-secondary hover:bg-surface transition-colors cursor-pointer`,children:[n?(0,$.jsx)(`img`,{src:n,alt:a,className:`size-4 rounded-sm object-cover shrink-0`}):r?(0,$.jsx)(de,{className:`size-3 shrink-0`}):(0,$.jsx)(`div`,{className:`size-4 rounded-sm bg-surface animate-pulse shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-32`,children:a})]})}function 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)(Ar,{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)(g,{tool:e.tool,result:e.result,completed:e.completed,projectName:n,bashPartialOutput:r},`tool-${a}`)})})}function Ar({content:e,isStreaming:t}){let[n,r]=(0,Q.useState)(t),i=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{!t&&e.length>0&&r(!1)},[t,e.length]),(0,Q.useEffect)(()=>{t&&n&&i.current&&(i.current.scrollTop=i.current.scrollHeight)},[e,t,n]),(0,$.jsxs)(`div`,{className:`rounded border border-border/50 bg-surface/30 text-xs`,children:[(0,$.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors text-text-subtle`,children:[t?(0,$.jsx)(X,{className:`size-3 animate-spin`}):(0,$.jsx)(d,{className:`size-3 transition-transform ${n?`rotate-90`:``}`}),(0,$.jsxs)(`span`,{children:[`Thinking`,t?`...`:``]}),!t&&(0,$.jsx)(`span`,{className:`text-text-subtle/50 ml-auto`,children:e.length>100?`${Math.round(e.length/4)} tokens`:``})]}),n&&(0,$.jsx)(`div`,{ref:i,className:`max-h-60 overflow-y-auto`,children:(0,$.jsx)(`div`,{className:`px-2 pb-2 text-text-subtle/80 whitespace-pre-wrap text-[11px] leading-relaxed`,children:e})})]})}function jr({content:e,animate:t,projectName:n}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Fr,{content:e,projectName:n,isStreaming:t}),t&&(0,$.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function Mr({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 Nr=/<teammate-message[^>]*>[\s\S]*?<\/teammate-message>/g;function Pr(e){return e.replace(Nr,``).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{b as t,y as n}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t as r}from"./createLucideIcon-ConhwJnb.js";import{t as i}from"./chevron-right-DeUue2aK.js";import{a,c as o,i as s,n as c,o as l,t as u}from"./dialog-HHdNInEH.js";import{t as d}from"./code-TekEnDFM.js";import{t as f}from"./database-COYAMZaw.js";import{n as p,r as m}from"./plus-DcuJuDC3.js";import{t as ee}from"./file-exclamation-point-DBEC-Kst.js";import{a as h,i as te,r as ne,t as g}from"./glide-data-grid-Q2kMqNeo.js";import{t as re}from"./shield-check-C3qYSU8a.js";import{t as ie}from"./shield-off-D5tU7gQT.js";import{t as _}from"./table-Di8pv2Y_.js";import{t as v}from"./x-BsFLg-T8.js";import{r as ae,t as y}from"./api-client-DhXpjLdi.js";import{q as b}from"./vendor-mermaid-CYOBtZtD.js";import{t as oe}from"./settings-store-DFMz_Oer.js";import{t as x}from"./utils-E0yyGxXt.js";import{t as se}from"./panel-store-D-RxcUgH.js";import{i as S}from"./project-store-C1jInVih.js";import{t as C}from"./tab-store-CNxCwdXw.js";import{$ as ce,A as le,Ht as w,J as T,Mt as E,Q as ue,Qt as D,U as de,Ut as fe,X as O,Y as k,Z as A,an as j,cn as pe,et as M,fn as me,in as he,j as ge,kt as _e,ln as ve,mt as N,o as ye,on as be,rn as xe,rt as Se,sn as P,tn as F,tt as I}from"./index-BI35sAVB.js";import"./data-grid-types-BuMHLKXV.js";import{t as Ce}from"./use-monaco-theme-Bf_8qog4.js";var we=r(`redo-2`,[[`path`,{d:`m15 14 5-5-5-5`,key:`12vg1m`}],[`path`,{d:`M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13`,key:`6uklza`}]]),L=e(t(),1),R=n();function Te(e){let t=e.startsWith(`/`),n=e.split(/[/\\]/).filter(Boolean),r=e=>{let r=(t?`/`:``)+n.slice(0,e+1).join(`/`);return/^[A-Za-z]:$/.test(r)?r+`/`:r},i=t?`/`:(n[0]??``)+`/`;return n.map((e,t)=>({name:e,absPath:r(t),parentDir:t>0?r(t-1):i}))}async function Ee(e){return(await y.get(`/api/fs/browse?path=${encodeURIComponent(e)}`)).entries}function De({filePath:e,projectName:t,tabId:n,className:r}){let{updateTab:a,openTab:o}=C(T(e=>({updateTab:e.updateTab,openTab:e.openTab}))),s=(0,L.useRef)(null),c=(0,L.useMemo)(()=>Te(e),[e]);(0,L.useEffect)(()=>{s.current&&(s.current.scrollLeft=s.current.scrollWidth)},[c]);let l=(0,L.useCallback)((e,r)=>{let i=x(e),s={filePath:e,projectName:t};r.metaKey||r.ctrlKey?o({type:`editor`,title:i,metadata:s,projectId:t,closable:!0}):a(n,{title:i,metadata:s})},[t,n,o,a]);return(0,R.jsx)(`div`,{ref:s,className:r,children:c.map((e,t)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,R.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,R.jsx)(Oe,{segment:e,isLast:t===c.length-1,onFileClick:l})]},e.absPath))})}function Oe({segment:e,isLast:t,onFileClick:n}){let[r,i]=(0,L.useState)(null),[a,o]=(0,L.useState)(null);function s(t){t&&r===null&&Ee(e.parentDir).then(i).catch(e=>{o(e.message||`Failed to browse`),i([])})}return(0,R.jsxs)(k,{onOpenChange:s,children:[(0,R.jsx)(I,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,className:`text-xs px-1 py-0.5 rounded hover:bg-muted transition-colors truncate max-w-[120px] ${t?`text-foreground font-medium`:`text-muted-foreground`}`,children:e.name})}),(0,R.jsx)(O,{align:`start`,className:`max-h-[300px] overflow-y-auto p-1`,children:r===null?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-destructive`,children:a}):r.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):r.map(t=>(0,R.jsx)(ke,{entry:t,activePath:e.absPath,onFileClick:n},t.path))})]})}function ke({entry:e,activePath:t,onFileClick:n}){let r=z(e.name,e.type===`directory`),i=e.path===t,[a,o]=(0,L.useState)(null);if(e.type===`directory`){function s(t){t&&a===null&&Ee(e.path).then(o).catch(()=>o([]))}return(0,R.jsxs)(ue,{onOpenChange:s,children:[(0,R.jsxs)(M,{className:`text-xs gap-1.5 ${i?`bg-muted`:``}`,children:[(0,R.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,R.jsx)(ce,{className:`max-h-[300px] overflow-y-auto p-1`,children:a===null?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):a.map(e=>(0,R.jsx)(ke,{entry:e,activePath:t,onFileClick:n},e.path))})]})}return(0,R.jsxs)(A,{className:`text-xs gap-1.5 cursor-pointer ${i?`bg-muted`:``}`,onClick:t=>n(e.path,t),children:[(0,R.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]})}var Ae={ts:P,tsx:P,js:P,jsx:P,py:P,rs:P,go:P,html:P,css:P,scss:P,json:pe,md:be,txt:be,yaml:j,yml:j};function z(e,t){return t?xe:Ae[e.split(`.`).pop()?.toLowerCase()??``]??he}function B(e,t){let n=[],r=e,i=``;for(let e=0;e<t.length;e++){let a=t[e],o=t.slice(0,e+1).join(`/`),s=r.find(e=>e.name===a);if(n.push({name:a,fullPath:o,node:s??null,siblings:r,parentPath:i}),s?.children)i=s.path,r=s.children;else{for(let r=e+1;r<t.length;r++)n.push({name:t[r],fullPath:t.slice(0,r+1).join(`/`),node:null,siblings:[],parentPath:t.slice(0,r).join(`/`)});break}}return n}function je(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function Me({filePath:e,projectName:t,tabId:n,className:r}){let a=N(e=>e.tree),{updateTab:o,openTab:s}=C(T(e=>({updateTab:e.updateTab,openTab:e.openTab}))),c=S(e=>e.projects.find(e=>e.name===t)?.path??``),l=(0,L.useRef)(null),{prefixParts:u,relativePath:d,isExternal:f}=(0,L.useMemo)(()=>{let t=e.startsWith(`/`)?e.slice(1):e,n=c.startsWith(`/`)?c.slice(1):c;if(n&&t.startsWith(n+`/`)){let e=t.slice(n.length+1);return{prefixParts:n.split(`/`),relativePath:e,isExternal:!1}}return{prefixParts:[],relativePath:t,isExternal:/^(\/|[A-Za-z]:[/\\])/.test(e)}},[e,c]),p=(0,L.useMemo)(()=>B(a,d.split(`/`).filter(Boolean)),[a,d]);(0,L.useEffect)(()=>{l.current&&(l.current.scrollLeft=l.current.scrollWidth)},[p]);function m(e,r){let i=x(e);r.metaKey||r.ctrlKey?s({type:`editor`,title:i,metadata:{filePath:e,projectName:t},projectId:t,closable:!0}):o(n,{title:i,metadata:{filePath:e,projectName:t}})}return f?(0,R.jsx)(De,{filePath:e,projectName:t,tabId:n,className:r}):(0,R.jsxs)(`div`,{ref:l,className:r,children:[u.map((e,t)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,R.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e})]},`prefix-${t}`)),p.map((e,n)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[(n>0||u.length>0)&&(0,R.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,R.jsx)(V,{segment:e,isLast:n===p.length-1,projectName:t,onFileClick:m})]},e.fullPath))]})}function V({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=N(e=>e.loadChildren),a=N(e=>e.loadedPaths),o=(0,L.useMemo)(()=>je(e.siblings),[e.siblings]),s=a.has(e.parentPath);function c(t){if(t&&!s){let t=e.parentPath.split(`/`).filter(Boolean);(async()=>{for(let e=0;e<=t.length;e++)await i(n,t.slice(0,e).join(`/`))})()}}return(0,R.jsxs)(k,{onOpenChange:c,children:[(0,R.jsx)(I,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,className:`text-xs px-1 py-0.5 rounded hover:bg-muted transition-colors truncate max-w-[120px] ${t?`text-foreground font-medium`:`text-muted-foreground`}`,children:e.name})}),(0,R.jsx)(O,{align:`start`,className:`max-h-[300px] p-1`,children:o.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):o.map(t=>(0,R.jsx)(H,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function H({node:e,projectName:t,activePath:n,onFileClick:r}){let i=z(e.name,e.type===`directory`),a=e.path===n,o=N(e=>e.loadChildren),s=N(e=>e.loadedPaths);if(e.type===`directory`){let c=e.children??[],l=s.has(e.path);function u(n){n&&!l&&o(t,e.path)}return(0,R.jsxs)(ue,{onOpenChange:u,children:[(0,R.jsxs)(M,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,R.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,R.jsx)(ce,{className:`max-h-[300px] overflow-y-auto p-1`,children:c.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):je(c).map(e=>(0,R.jsx)(H,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]})}return(0,R.jsxs)(A,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{r(e.path,t)},children:[(0,R.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]})}function U({active:e,onClick:t,icon:n,label:r}){return(0,R.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,R.jsx)(n,{className:`size-3`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function Ne({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:i,wordWrap:a,onToggleWordWrap:o,onRefresh:s,refreshing:c,filePath:l,projectName:u,className:f}){return(0,R.jsxs)(`div`,{className:f,children:[(e===`md`||e===`mdx`)&&n&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(U,{active:t===`edit`,onClick:()=>n(`edit`),icon:d,label:`Edit`}),(0,R.jsx)(U,{active:t===`preview`,onClick:()=>n(`preview`),icon:p,label:`Preview`})]}),e===`csv`&&i&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(U,{active:r===`table`,onClick:()=>i(`table`),icon:_,label:`Table`}),(0,R.jsx)(U,{active:r===`raw`,onClick:()=>i(`raw`),icon:d,label:`Raw`})]}),(0,R.jsx)(U,{active:a,onClick:o,icon:E,label:`Wrap`}),s&&(0,R.jsxs)(`button`,{type:`button`,onClick:s,disabled:c,title:`Reload file from disk`,className:`flex items-center gap-1 px-2 py-1 rounded text-xs text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,children:[(0,R.jsx)(w,{className:`size-3 ${c?`animate-spin`:``}`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:`Refresh`})]}),l&&u&&(0,R.jsx)(U,{active:!1,onClick:()=>Se(u,l),icon:m,label:`Download`})]})}var Pe=[{id:`plaintext`,label:`Plain Text`},{id:`javascript`,label:`JavaScript`},{id:`typescript`,label:`TypeScript`},{id:`sql`,label:`SQL`},{id:`json`,label:`JSON`},{id:`xml`,label:`XML`},{id:`html`,label:`HTML`},{id:`css`,label:`CSS`},{id:`python`,label:`Python`},{id:`markdown`,label:`Markdown`},{id:`yaml`,label:`YAML`},{id:`shell`,label:`Shell`}];function Fe({value:e,onChange:t}){return(0,R.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1 px-2 border-l border-border`,children:[(0,R.jsx)(P,{className:`size-3 text-muted-foreground`}),(0,R.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-5 text-[10px] bg-transparent border border-border rounded px-1 text-foreground outline-none max-w-[120px]`,title:`Select editor language`,children:Pe.map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.label},e.id))})]})}function Ie({open:e,defaultName:t,content:n,onSave:r,onCancel:i}){let[d,f]=(0,L.useState)(t),[p,m]=(0,L.useState)(!1),[ee,h]=(0,L.useState)(``),te=S(e=>e.activeProject),ne=(0,L.useCallback)(()=>{let e=d.trim();if(!e){h(`Filename cannot be empty`);return}if(/[/\\]/.test(e)){h(`Filename cannot contain / or \\`);return}h(``),m(!0)},[d]),g=(0,L.useCallback)(e=>{let t=e.includes(`\\`)?`\\`:`/`;r(e.endsWith(t)?`${e}${d.trim()}`:`${e}${t}${d.trim()}`,n)},[d,n,r]);return p?(0,R.jsx)(ge,{open:!0,mode:`folder`,root:te?.path,title:`Save "${d.trim()}" to...`,onSelect:g,onCancel:()=>m(!1)}):(0,R.jsx)(u,{open:e,onOpenChange:e=>{e||i()},children:(0,R.jsxs)(c,{className:`sm:max-w-md`,children:[(0,R.jsx)(a,{children:(0,R.jsx)(l,{children:`Save As`})}),(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,R.jsx)(`label`,{className:`text-sm text-muted-foreground`,children:`Filename`}),(0,R.jsx)(de,{value:d,onChange:e=>{f(e.target.value),h(``)},onKeyDown:e=>{e.key===`Enter`&&ne()},placeholder:`e.g. my-file.ts`,autoFocus:!0}),ee&&(0,R.jsx)(`p`,{className:`text-xs text-destructive`,children:ee})]}),(0,R.jsxs)(s,{children:[(0,R.jsx)(o,{variant:`outline`,onClick:i,children:`Cancel`}),(0,R.jsx)(o,{onClick:ne,children:`Choose Folder...`})]})]})})}var W=typeof window<`u`&&window.isSecureContext,G=[`(`,`)`,`{`,`}`,`[`,`]`,`<`,`>`,`;`,`:`,`=`,`"`,`'`,"`",`/`,`\\`,`_`,`#`],K=`px-2 py-1.5 rounded text-xs min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,Le=`px-3 py-1.5 rounded text-xs font-mono min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,q=`w-px h-5 bg-border mx-0.5 shrink-0`;function Re({editorRef:e,readOnly:t}){let n=(0,L.useCallback)(()=>e.current,[e]),r=(0,L.useCallback)(e=>{let t=n();if(!t)return;t.focus();let r=t.getSelection();r&&t.executeEdits(`mobile-toolbar`,[{range:r,text:e}])},[n]),[i,a]=(0,L.useState)(!1),o=(0,L.useRef)(null),s=(0,L.useCallback)(async()=>{try{let e=await navigator.clipboard.readText();e&&r(e)}catch{}},[r]),c=(0,L.useCallback)(()=>{a(!0),requestAnimationFrame(()=>o.current?.focus())},[]),l=(0,L.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData(`text/plain`);t&&(a(!1),r(t))},[r]),u=(0,L.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`undo`,null))},[n]),d=(0,L.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`redo`,null))},[n]),f=(0,L.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`tab`,null))},[n]);return t?null:(0,R.jsxs)(`div`,{className:`shrink-0 border-t border-border bg-surface`,children:[!W&&i&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 border-b border-border bg-muted/50`,children:[(0,R.jsx)(`textarea`,{ref:o,onPaste:l,placeholder:`Long-press here → Paste`,className:`flex-1 h-8 rounded border border-border bg-background text-foreground text-xs px-2 py-1.5 resize-none focus:outline-none focus:ring-1 focus:ring-primary`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`p-1.5 rounded text-muted-foreground active:bg-muted transition-colors`,children:(0,R.jsx)(v,{size:14})})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1.5 overflow-x-auto`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:W?s:c,className:K,title:`Paste`,children:(0,R.jsx)(me,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:u,className:K,title:`Undo`,children:(0,R.jsx)(_e,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:d,className:K,title:`Redo`,children:(0,R.jsx)(we,{size:14})}),(0,R.jsx)(`div`,{className:q}),(0,R.jsx)(`button`,{type:`button`,onClick:f,className:Le,children:`Tab`}),(0,R.jsx)(`div`,{className:q}),G.map(e=>(0,R.jsx)(`button`,{type:`button`,onClick:()=>r(e),className:Le,children:e},e))]})]})}var J=(0,L.lazy)(()=>b(()=>import(`./markdown-renderer-ClDzjZ5T.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28]))),ze=(0,L.lazy)(()=>b(()=>import(`./csv-preview-i79R-2TA.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([29,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,30,31]))),Be=(0,L.lazy)(()=>b(()=>import(`./image-preview-QyeYNiJt.js`).then(e=>({default:e.ImagePreview})),__vite__mapDeps([32,6,2,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,33,34]))),Ve=(0,L.lazy)(()=>b(()=>import(`./pdf-preview-Dd65pYcK.js`).then(e=>({default:e.PdfPreview})),__vite__mapDeps([35,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,33]))),He=(0,L.lazy)(()=>b(()=>import(`./video-preview-C-ZB6w-Z.js`).then(e=>({default:e.VideoPreview})),__vite__mapDeps([36,6,2,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,33,34]))),Ue=(0,L.lazy)(()=>b(()=>import(`./audio-preview-XkBaDV-d.js`).then(e=>({default:e.AudioPreview})),__vite__mapDeps([37,6,2,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,33,34]))),We=(0,L.lazy)(()=>b(()=>import(`./docx-preview-CFjtBdLf.js`).then(e=>({default:e.DocxPreview})),__vite__mapDeps([38,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,33]))),Ge=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Ke=new Set([`mp4`,`webm`,`mov`,`ogg`,`avi`,`mkv`]),qe=new Set([`mp3`,`wav`,`flac`,`aac`,`m4a`,`wma`]),Je=new Set([`db`,`sqlite`,`sqlite3`]);function Ye(e){return e.split(`.`).pop()?.toLowerCase()??``}function Xe(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`,sql:`sql`}[Ye(e)]??`plaintext`}var Ze=(0,L.memo)(function({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,i=e?.inlineContent,a=e?.inlineLanguage,[o,s]=(0,L.useState)(i??null),[c,l]=(0,L.useState)(`utf-8`),[u,d]=(0,L.useState)(!0),[p,m]=(0,L.useState)(null),[g,_]=(0,L.useState)(!1),v=(0,L.useRef)(null),b=(0,L.useRef)(``),S=(0,L.useRef)(null),{tabs:ce,updateTab:w}=C(T(e=>({tabs:e.tabs,updateTab:e.updateTab}))),{wordWrap:E,toggleWordWrap:ue}=oe(T(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),de=Ce(),O=e?.isUntitled===!0,k=e?.unsavedContent,[A,j]=(0,L.useState)(!1),pe=ce.find(e=>e.id===t),M=n?Ye(n):``,me=Ge.has(M),he=M===`pdf`,ge=M===`docx`,_e=Ke.has(M),ve=qe.has(M),N=Je.has(M),be=M===`md`||M===`mdx`,xe=M===`csv`,Se=e?.language,P=a??Se??Xe(n??``),F=P===`sql`,[I,we]=(0,L.useState)(`preview`),[Te,Ee]=(0,L.useState)(`table`),{connections:De,cachedTables:Oe,refreshTables:ke,updateConnection:Ae}=le(),z=n?`ppm:sql-conn:${n}`:t?`ppm:sql-conn:tab:${t}`:null,[B,je]=(0,L.useState)(()=>{if(!z)return null;let e=localStorage.getItem(z);return e?Number(e):null}),V=(0,L.useRef)(null),H=(0,L.useRef)(null),U=(0,L.useMemo)(()=>De.find(e=>e.id===B)??null,[De,B]),Pe=i!=null&&(a===`json`||a===`xml`),[W,G]=(0,L.useState)(!1),K=(0,L.useCallback)(()=>{if(i)if(W)s(i),G(!1);else{let e=i.trimStart();if(a===`json`)try{s(JSON.stringify(JSON.parse(e),null,2)),G(!0)}catch{}else if(a===`xml`){let t=0;s(e.replace(/(>)(<)(\/*)/g,`$1
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-C9Gy8tM2.js","assets/vendor-mermaid-CYOBtZtD.js","assets/rolldown-runtime-FhOqtrmT.js","assets/vendor-ui-DMRGWRuc.js","assets/vendor-markdown-CKTlmXbz.js","assets/markdown-renderer-BKDbjc3g.js","assets/index-BuX7JkCt.js","assets/dialog-HHdNInEH.js","assets/utils-E0yyGxXt.js","assets/createLucideIcon-ConhwJnb.js","assets/x-BsFLg-T8.js","assets/eye-off-Rq1n2-oe.js","assets/bot-E9mcVZnr.js","assets/mobile-bottom-sheet-BwPBKZON.js","assets/chevron-right-DeUue2aK.js","assets/use-is-mobile-BcuCjH19.js","assets/sparkles-B3DmG8PJ.js","assets/database-COYAMZaw.js","assets/plus-DcuJuDC3.js","assets/api-client-DhXpjLdi.js","assets/react-8hrD3-kv.js","assets/api-settings-BUYvGBdi.js","assets/project-store-C1jInVih.js","assets/panel-store-D-RxcUgH.js","assets/settings-store-DFMz_Oer.js","assets/tab-store-CNxCwdXw.js","assets/apply-theme-BSJDABU3.js","assets/resolve-theme-B9Mgd5GG.js","assets/index-PX2pZ3bH.css","assets/csv-preview-AEg0GB-V.js","assets/lib-DA3QSc5_.js","assets/csv-parser-BPS94T2h.js","assets/image-preview-DRUzYptI.js","assets/file-exclamation-point-DBEC-Kst.js","assets/use-blob-url-jSRmyXVg.js","assets/pdf-preview-CzHUqXJB.js","assets/video-preview-DMqLOqmc.js","assets/audio-preview-IokB77Cj.js","assets/docx-preview-DqTX7NDp.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,y as n}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t as r}from"./createLucideIcon-ConhwJnb.js";import{t as i}from"./chevron-right-DeUue2aK.js";import{a,c as o,i as s,n as c,o as l,t as u}from"./dialog-HHdNInEH.js";import{t as d}from"./code-TekEnDFM.js";import{t as f}from"./database-COYAMZaw.js";import{n as p,r as m}from"./plus-DcuJuDC3.js";import{t as ee}from"./file-exclamation-point-DBEC-Kst.js";import{a as h,i as te,r as ne,t as g}from"./glide-data-grid-cGxkgluR.js";import{t as re}from"./shield-check-C3qYSU8a.js";import{t as ie}from"./shield-off-D5tU7gQT.js";import{t as _}from"./table-Di8pv2Y_.js";import{t as v}from"./x-BsFLg-T8.js";import{r as ae,t as y}from"./api-client-DhXpjLdi.js";import{q as b}from"./vendor-mermaid-CYOBtZtD.js";import{t as oe}from"./settings-store-DFMz_Oer.js";import{t as x}from"./utils-E0yyGxXt.js";import{t as se}from"./panel-store-D-RxcUgH.js";import{i as S}from"./project-store-C1jInVih.js";import{t as C}from"./tab-store-CNxCwdXw.js";import{$ as ce,A as le,Ht as w,J as T,Mt as E,Q as ue,Qt as D,U as de,Ut as fe,X as O,Y as k,Z as A,an as j,cn as pe,et as M,fn as me,in as he,j as ge,kt as _e,ln as ve,mt as N,o as ye,on as be,rn as xe,rt as Se,sn as P,tn as F,tt as I}from"./index-BuX7JkCt.js";import"./data-grid-types-BuMHLKXV.js";import{t as Ce}from"./use-monaco-theme-5XjAzOzE.js";var we=r(`redo-2`,[[`path`,{d:`m15 14 5-5-5-5`,key:`12vg1m`}],[`path`,{d:`M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13`,key:`6uklza`}]]),L=e(t(),1),R=n();function Te(e){let t=e.startsWith(`/`),n=e.split(/[/\\]/).filter(Boolean),r=e=>{let r=(t?`/`:``)+n.slice(0,e+1).join(`/`);return/^[A-Za-z]:$/.test(r)?r+`/`:r},i=t?`/`:(n[0]??``)+`/`;return n.map((e,t)=>({name:e,absPath:r(t),parentDir:t>0?r(t-1):i}))}async function Ee(e){return(await y.get(`/api/fs/browse?path=${encodeURIComponent(e)}`)).entries}function De({filePath:e,projectName:t,tabId:n,className:r}){let{updateTab:a,openTab:o}=C(T(e=>({updateTab:e.updateTab,openTab:e.openTab}))),s=(0,L.useRef)(null),c=(0,L.useMemo)(()=>Te(e),[e]);(0,L.useEffect)(()=>{s.current&&(s.current.scrollLeft=s.current.scrollWidth)},[c]);let l=(0,L.useCallback)((e,r)=>{let i=x(e),s={filePath:e,projectName:t};r.metaKey||r.ctrlKey?o({type:`editor`,title:i,metadata:s,projectId:t,closable:!0}):a(n,{title:i,metadata:s})},[t,n,o,a]);return(0,R.jsx)(`div`,{ref:s,className:r,children:c.map((e,t)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,R.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,R.jsx)(Oe,{segment:e,isLast:t===c.length-1,onFileClick:l})]},e.absPath))})}function Oe({segment:e,isLast:t,onFileClick:n}){let[r,i]=(0,L.useState)(null),[a,o]=(0,L.useState)(null);function s(t){t&&r===null&&Ee(e.parentDir).then(i).catch(e=>{o(e.message||`Failed to browse`),i([])})}return(0,R.jsxs)(k,{onOpenChange:s,children:[(0,R.jsx)(I,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,className:`text-xs px-1 py-0.5 rounded hover:bg-muted transition-colors truncate max-w-[120px] ${t?`text-foreground font-medium`:`text-muted-foreground`}`,children:e.name})}),(0,R.jsx)(O,{align:`start`,className:`max-h-[300px] overflow-y-auto p-1`,children:r===null?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-destructive`,children:a}):r.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):r.map(t=>(0,R.jsx)(ke,{entry:t,activePath:e.absPath,onFileClick:n},t.path))})]})}function ke({entry:e,activePath:t,onFileClick:n}){let r=z(e.name,e.type===`directory`),i=e.path===t,[a,o]=(0,L.useState)(null);if(e.type===`directory`){function s(t){t&&a===null&&Ee(e.path).then(o).catch(()=>o([]))}return(0,R.jsxs)(ue,{onOpenChange:s,children:[(0,R.jsxs)(M,{className:`text-xs gap-1.5 ${i?`bg-muted`:``}`,children:[(0,R.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,R.jsx)(ce,{className:`max-h-[300px] overflow-y-auto p-1`,children:a===null?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):a.map(e=>(0,R.jsx)(ke,{entry:e,activePath:t,onFileClick:n},e.path))})]})}return(0,R.jsxs)(A,{className:`text-xs gap-1.5 cursor-pointer ${i?`bg-muted`:``}`,onClick:t=>n(e.path,t),children:[(0,R.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]})}var Ae={ts:P,tsx:P,js:P,jsx:P,py:P,rs:P,go:P,html:P,css:P,scss:P,json:pe,md:be,txt:be,yaml:j,yml:j};function z(e,t){return t?xe:Ae[e.split(`.`).pop()?.toLowerCase()??``]??he}function B(e,t){let n=[],r=e,i=``;for(let e=0;e<t.length;e++){let a=t[e],o=t.slice(0,e+1).join(`/`),s=r.find(e=>e.name===a);if(n.push({name:a,fullPath:o,node:s??null,siblings:r,parentPath:i}),s?.children)i=s.path,r=s.children;else{for(let r=e+1;r<t.length;r++)n.push({name:t[r],fullPath:t.slice(0,r+1).join(`/`),node:null,siblings:[],parentPath:t.slice(0,r).join(`/`)});break}}return n}function je(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function Me({filePath:e,projectName:t,tabId:n,className:r}){let a=N(e=>e.tree),{updateTab:o,openTab:s}=C(T(e=>({updateTab:e.updateTab,openTab:e.openTab}))),c=S(e=>e.projects.find(e=>e.name===t)?.path??``),l=(0,L.useRef)(null),{prefixParts:u,relativePath:d,isExternal:f}=(0,L.useMemo)(()=>{let t=e.startsWith(`/`)?e.slice(1):e,n=c.startsWith(`/`)?c.slice(1):c;if(n&&t.startsWith(n+`/`)){let e=t.slice(n.length+1);return{prefixParts:n.split(`/`),relativePath:e,isExternal:!1}}return{prefixParts:[],relativePath:t,isExternal:/^(\/|[A-Za-z]:[/\\])/.test(e)}},[e,c]),p=(0,L.useMemo)(()=>B(a,d.split(`/`).filter(Boolean)),[a,d]);(0,L.useEffect)(()=>{l.current&&(l.current.scrollLeft=l.current.scrollWidth)},[p]);function m(e,r){let i=x(e);r.metaKey||r.ctrlKey?s({type:`editor`,title:i,metadata:{filePath:e,projectName:t},projectId:t,closable:!0}):o(n,{title:i,metadata:{filePath:e,projectName:t}})}return f?(0,R.jsx)(De,{filePath:e,projectName:t,tabId:n,className:r}):(0,R.jsxs)(`div`,{ref:l,className:r,children:[u.map((e,t)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,R.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e})]},`prefix-${t}`)),p.map((e,n)=>(0,R.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[(n>0||u.length>0)&&(0,R.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,R.jsx)(V,{segment:e,isLast:n===p.length-1,projectName:t,onFileClick:m})]},e.fullPath))]})}function V({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=N(e=>e.loadChildren),a=N(e=>e.loadedPaths),o=(0,L.useMemo)(()=>je(e.siblings),[e.siblings]),s=a.has(e.parentPath);function c(t){if(t&&!s){let t=e.parentPath.split(`/`).filter(Boolean);(async()=>{for(let e=0;e<=t.length;e++)await i(n,t.slice(0,e).join(`/`))})()}}return(0,R.jsxs)(k,{onOpenChange:c,children:[(0,R.jsx)(I,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,className:`text-xs px-1 py-0.5 rounded hover:bg-muted transition-colors truncate max-w-[120px] ${t?`text-foreground font-medium`:`text-muted-foreground`}`,children:e.name})}),(0,R.jsx)(O,{align:`start`,className:`max-h-[300px] p-1`,children:o.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):o.map(t=>(0,R.jsx)(H,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function H({node:e,projectName:t,activePath:n,onFileClick:r}){let i=z(e.name,e.type===`directory`),a=e.path===n,o=N(e=>e.loadChildren),s=N(e=>e.loadedPaths);if(e.type===`directory`){let c=e.children??[],l=s.has(e.path);function u(n){n&&!l&&o(t,e.path)}return(0,R.jsxs)(ue,{onOpenChange:u,children:[(0,R.jsxs)(M,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,R.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,R.jsx)(ce,{className:`max-h-[300px] overflow-y-auto p-1`,children:c.length===0?(0,R.jsx)(A,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):je(c).map(e=>(0,R.jsx)(H,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]})}return(0,R.jsxs)(A,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{r(e.path,t)},children:[(0,R.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.name})]})}function U({active:e,onClick:t,icon:n,label:r}){return(0,R.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,R.jsx)(n,{className:`size-3`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function Ne({ext:e,mdMode:t,onMdModeChange:n,csvMode:r,onCsvModeChange:i,wordWrap:a,onToggleWordWrap:o,onRefresh:s,refreshing:c,filePath:l,projectName:u,className:f}){return(0,R.jsxs)(`div`,{className:f,children:[(e===`md`||e===`mdx`)&&n&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(U,{active:t===`edit`,onClick:()=>n(`edit`),icon:d,label:`Edit`}),(0,R.jsx)(U,{active:t===`preview`,onClick:()=>n(`preview`),icon:p,label:`Preview`})]}),e===`csv`&&i&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(U,{active:r===`table`,onClick:()=>i(`table`),icon:_,label:`Table`}),(0,R.jsx)(U,{active:r===`raw`,onClick:()=>i(`raw`),icon:d,label:`Raw`})]}),(0,R.jsx)(U,{active:a,onClick:o,icon:E,label:`Wrap`}),s&&(0,R.jsxs)(`button`,{type:`button`,onClick:s,disabled:c,title:`Reload file from disk`,className:`flex items-center gap-1 px-2 py-1 rounded text-xs text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,children:[(0,R.jsx)(w,{className:`size-3 ${c?`animate-spin`:``}`}),(0,R.jsx)(`span`,{className:`hidden sm:inline`,children:`Refresh`})]}),l&&u&&(0,R.jsx)(U,{active:!1,onClick:()=>Se(u,l),icon:m,label:`Download`})]})}var Pe=[{id:`plaintext`,label:`Plain Text`},{id:`javascript`,label:`JavaScript`},{id:`typescript`,label:`TypeScript`},{id:`sql`,label:`SQL`},{id:`json`,label:`JSON`},{id:`xml`,label:`XML`},{id:`html`,label:`HTML`},{id:`css`,label:`CSS`},{id:`python`,label:`Python`},{id:`markdown`,label:`Markdown`},{id:`yaml`,label:`YAML`},{id:`shell`,label:`Shell`}];function Fe({value:e,onChange:t}){return(0,R.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1 px-2 border-l border-border`,children:[(0,R.jsx)(P,{className:`size-3 text-muted-foreground`}),(0,R.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-5 text-[10px] bg-transparent border border-border rounded px-1 text-foreground outline-none max-w-[120px]`,title:`Select editor language`,children:Pe.map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.label},e.id))})]})}function Ie({open:e,defaultName:t,content:n,onSave:r,onCancel:i}){let[d,f]=(0,L.useState)(t),[p,m]=(0,L.useState)(!1),[ee,h]=(0,L.useState)(``),te=S(e=>e.activeProject),ne=(0,L.useCallback)(()=>{let e=d.trim();if(!e){h(`Filename cannot be empty`);return}if(/[/\\]/.test(e)){h(`Filename cannot contain / or \\`);return}h(``),m(!0)},[d]),g=(0,L.useCallback)(e=>{let t=e.includes(`\\`)?`\\`:`/`;r(e.endsWith(t)?`${e}${d.trim()}`:`${e}${t}${d.trim()}`,n)},[d,n,r]);return p?(0,R.jsx)(ge,{open:!0,mode:`folder`,root:te?.path,title:`Save "${d.trim()}" to...`,onSelect:g,onCancel:()=>m(!1)}):(0,R.jsx)(u,{open:e,onOpenChange:e=>{e||i()},children:(0,R.jsxs)(c,{className:`sm:max-w-md`,children:[(0,R.jsx)(a,{children:(0,R.jsx)(l,{children:`Save As`})}),(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,R.jsx)(`label`,{className:`text-sm text-muted-foreground`,children:`Filename`}),(0,R.jsx)(de,{value:d,onChange:e=>{f(e.target.value),h(``)},onKeyDown:e=>{e.key===`Enter`&&ne()},placeholder:`e.g. my-file.ts`,autoFocus:!0}),ee&&(0,R.jsx)(`p`,{className:`text-xs text-destructive`,children:ee})]}),(0,R.jsxs)(s,{children:[(0,R.jsx)(o,{variant:`outline`,onClick:i,children:`Cancel`}),(0,R.jsx)(o,{onClick:ne,children:`Choose Folder...`})]})]})})}var W=typeof window<`u`&&window.isSecureContext,G=[`(`,`)`,`{`,`}`,`[`,`]`,`<`,`>`,`;`,`:`,`=`,`"`,`'`,"`",`/`,`\\`,`_`,`#`],K=`px-2 py-1.5 rounded text-xs min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,Le=`px-3 py-1.5 rounded text-xs font-mono min-w-[36px] min-h-[32px] bg-surface-elevated text-text-primary active:bg-primary active:text-primary-foreground transition-colors select-none`,q=`w-px h-5 bg-border mx-0.5 shrink-0`;function Re({editorRef:e,readOnly:t}){let n=(0,L.useCallback)(()=>e.current,[e]),r=(0,L.useCallback)(e=>{let t=n();if(!t)return;t.focus();let r=t.getSelection();r&&t.executeEdits(`mobile-toolbar`,[{range:r,text:e}])},[n]),[i,a]=(0,L.useState)(!1),o=(0,L.useRef)(null),s=(0,L.useCallback)(async()=>{try{let e=await navigator.clipboard.readText();e&&r(e)}catch{}},[r]),c=(0,L.useCallback)(()=>{a(!0),requestAnimationFrame(()=>o.current?.focus())},[]),l=(0,L.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData(`text/plain`);t&&(a(!1),r(t))},[r]),u=(0,L.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`undo`,null))},[n]),d=(0,L.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`redo`,null))},[n]),f=(0,L.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`tab`,null))},[n]);return t?null:(0,R.jsxs)(`div`,{className:`shrink-0 border-t border-border bg-surface`,children:[!W&&i&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 border-b border-border bg-muted/50`,children:[(0,R.jsx)(`textarea`,{ref:o,onPaste:l,placeholder:`Long-press here → Paste`,className:`flex-1 h-8 rounded border border-border bg-background text-foreground text-xs px-2 py-1.5 resize-none focus:outline-none focus:ring-1 focus:ring-primary`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`p-1.5 rounded text-muted-foreground active:bg-muted transition-colors`,children:(0,R.jsx)(v,{size:14})})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1.5 overflow-x-auto`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:W?s:c,className:K,title:`Paste`,children:(0,R.jsx)(me,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:u,className:K,title:`Undo`,children:(0,R.jsx)(_e,{size:14})}),(0,R.jsx)(`button`,{type:`button`,onClick:d,className:K,title:`Redo`,children:(0,R.jsx)(we,{size:14})}),(0,R.jsx)(`div`,{className:q}),(0,R.jsx)(`button`,{type:`button`,onClick:f,className:Le,children:`Tab`}),(0,R.jsx)(`div`,{className:q}),G.map(e=>(0,R.jsx)(`button`,{type:`button`,onClick:()=>r(e),className:Le,children:e},e))]})]})}var J=(0,L.lazy)(()=>b(()=>import(`./markdown-renderer-C9Gy8tM2.js`).then(e=>({default:e.MarkdownRenderer})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28]))),ze=(0,L.lazy)(()=>b(()=>import(`./csv-preview-AEg0GB-V.js`).then(e=>({default:e.CsvPreview})),__vite__mapDeps([29,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,30,31]))),Be=(0,L.lazy)(()=>b(()=>import(`./image-preview-DRUzYptI.js`).then(e=>({default:e.ImagePreview})),__vite__mapDeps([32,6,2,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,33,34]))),Ve=(0,L.lazy)(()=>b(()=>import(`./pdf-preview-CzHUqXJB.js`).then(e=>({default:e.PdfPreview})),__vite__mapDeps([35,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,33]))),He=(0,L.lazy)(()=>b(()=>import(`./video-preview-DMqLOqmc.js`).then(e=>({default:e.VideoPreview})),__vite__mapDeps([36,6,2,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,33,34]))),Ue=(0,L.lazy)(()=>b(()=>import(`./audio-preview-IokB77Cj.js`).then(e=>({default:e.AudioPreview})),__vite__mapDeps([37,6,2,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,33,34]))),We=(0,L.lazy)(()=>b(()=>import(`./docx-preview-DqTX7NDp.js`).then(e=>({default:e.DocxPreview})),__vite__mapDeps([38,2,6,1,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,33]))),Ge=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),Ke=new Set([`mp4`,`webm`,`mov`,`ogg`,`avi`,`mkv`]),qe=new Set([`mp3`,`wav`,`flac`,`aac`,`m4a`,`wma`]),Je=new Set([`db`,`sqlite`,`sqlite3`]);function Ye(e){return e.split(`.`).pop()?.toLowerCase()??``}function Xe(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`,sql:`sql`}[Ye(e)]??`plaintext`}var Ze=(0,L.memo)(function({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,i=e?.inlineContent,a=e?.inlineLanguage,[o,s]=(0,L.useState)(i??null),[c,l]=(0,L.useState)(`utf-8`),[u,d]=(0,L.useState)(!0),[p,m]=(0,L.useState)(null),[g,_]=(0,L.useState)(!1),v=(0,L.useRef)(null),b=(0,L.useRef)(``),S=(0,L.useRef)(null),{tabs:ce,updateTab:w}=C(T(e=>({tabs:e.tabs,updateTab:e.updateTab}))),{wordWrap:E,toggleWordWrap:ue}=oe(T(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),de=Ce(),O=e?.isUntitled===!0,k=e?.unsavedContent,[A,j]=(0,L.useState)(!1),pe=ce.find(e=>e.id===t),M=n?Ye(n):``,me=Ge.has(M),he=M===`pdf`,ge=M===`docx`,_e=Ke.has(M),ve=qe.has(M),N=Je.has(M),be=M===`md`||M===`mdx`,xe=M===`csv`,Se=e?.language,P=a??Se??Xe(n??``),F=P===`sql`,[I,we]=(0,L.useState)(`preview`),[Te,Ee]=(0,L.useState)(`table`),{connections:De,cachedTables:Oe,refreshTables:ke,updateConnection:Ae}=le(),z=n?`ppm:sql-conn:${n}`:t?`ppm:sql-conn:tab:${t}`:null,[B,je]=(0,L.useState)(()=>{if(!z)return null;let e=localStorage.getItem(z);return e?Number(e):null}),V=(0,L.useRef)(null),H=(0,L.useRef)(null),U=(0,L.useMemo)(()=>De.find(e=>e.id===B)??null,[De,B]),Pe=i!=null&&(a===`json`||a===`xml`),[W,G]=(0,L.useState)(!1),K=(0,L.useCallback)(()=>{if(i)if(W)s(i),G(!1);else{let e=i.trimStart();if(a===`json`)try{s(JSON.stringify(JSON.parse(e),null,2)),G(!0)}catch{}else if(a===`xml`){let t=0;s(e.replace(/(>)(<)(\/*)/g,`$1
|
|
3
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
|
`)),G(!0)}}},[i,a,W]),Le=(0,L.useCallback)(e=>{je(e),z&&localStorage.setItem(z,String(e)),ke(e).catch(()=>{})},[z,ke]),q=(0,L.useCallback)(n=>{t&&w(t,{metadata:{...e,language:n}})},[t,e,w]),J=(0,L.useMemo)(()=>{if(!F||!B)return;let e=(Oe.get(B)??[]).map(e=>({name:e.tableName,schema:e.schemaName}));if(e.length!==0)return{tables:e,getColumns:async(e,t)=>y.get(`/api/db/connections/${B}/schema?table=${encodeURIComponent(e)}${t?`&schema=${encodeURIComponent(t)}`:``}`)}},[F,B,Oe]);(0,L.useEffect)(()=>{if(!(!V.current||!J))return H.current?.dispose(),ne(),H.current=V.current.languages.registerCompletionItemProvider(`sql`,te(V.current,J)),()=>{H.current?.dispose()}},[J]);let Ze=C(e=>e.openTab),[Y,et]=(0,L.useState)(null),[tt,nt]=(0,L.useState)(null),[rt,it]=(0,L.useState)(!1),[at,ot]=(0,L.useState)(``),st=(0,L.useCallback)(async e=>{if(U){it(!0),nt(null),ot(e);try{et(await y.post(`/api/db/connections/${U.id}/query`,{sql:e}))}catch(e){nt(e.message),et(null)}finally{it(!1)}}},[U]),ct=(0,L.useCallback)(()=>{!U||!at||Ze({type:`database`,title:`${U.name} · Query`,projectId:null,closable:!0,metadata:{connectionId:U.id,connectionName:U.name,dbType:U.type,initialSql:at}})},[U,Ze,at]),lt=(0,L.useCallback)(()=>{if(!S.current||!U)return;let e=S.current,t=e.getSelection();st(t&&!t.isEmpty()?e.getModel()?.getValueInRange(t)??e.getValue():e.getValue())},[U,st]),ut=typeof window<`u`&&`ontouchstart`in window,dt=(0,L.useRef)(null),[ft,pt]=(0,L.useState)(null);(0,L.useEffect)(()=>{if(!ut)return;let e=window.visualViewport;if(!e)return;let t=()=>{let t=dt.current;if(!t)return;let n=t.getBoundingClientRect().top;pt(e.height-Math.max(0,n))};return e.addEventListener(`resize`,t),e.addEventListener(`scroll`,t),()=>{e.removeEventListener(`resize`,t),e.removeEventListener(`scroll`,t)}},[ut]);let Z=(0,L.useRef)([]),mt=(0,L.useRef)(st);mt.current=st,(0,L.useEffect)(()=>()=>{Z.current.forEach(e=>e.dispose()),Z.current=[]},[]),(0,L.useEffect)(()=>{N&&t&&w(t,{type:`sqlite`})},[N,t,w]);let Q=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,L.useEffect)(()=>{if(i!=null){d(!1);return}if(O){s(k??``),b.current=k??``,d(!1),k&&_(!0);return}if(!n||!Q&&!r)return;if(me||he||ge||_e||ve){d(!1);return}d(!0),m(null);let e=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${ae(r)}/files/read?path=${encodeURIComponent(n)}`;return y.get(e).then(e=>{s(e.content),e.encoding&&l(e.encoding),b.current=e.content,d(!1)}).catch(e=>{m(e instanceof Error?e.message:`Failed to load file`),d(!1)}),()=>{v.current&&clearTimeout(v.current)}},[n,r,me,he,ge,Q,O]);let[ht,gt]=(0,L.useState)(!1),_t=(0,L.useCallback)(()=>{if(!n||i!=null||O||!Q&&!r)return;let e=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${ae(r)}/files/read?path=${encodeURIComponent(n)}`;gt(!0),y.get(e).then(e=>{s(e.content),b.current=e.content,e.encoding&&l(e.encoding),_(!1),m(null)}).catch(e=>m(e instanceof Error?e.message:`Failed to reload file`)).finally(()=>gt(!1))},[n,r,Q,i,O]),vt=(0,L.useRef)(g);vt.current=g,(0,L.useEffect)(()=>{if(!n||!r||i!=null||O)return;let e=e=>{let t=e.detail;if(t.projectName!==r||t.path!==n||vt.current)return;let i=Q?`/api/fs/read?path=${encodeURIComponent(n)}`:`${ae(r)}/files/read?path=${encodeURIComponent(n)}`;y.get(i).then(e=>{e.content!==b.current&&(s(e.content),b.current=e.content,e.encoding&&l(e.encoding))}).catch(()=>{})};return window.addEventListener(`file:changed`,e),()=>window.removeEventListener(`file:changed`,e)},[n,r,Q,i,O]),(0,L.useEffect)(()=>{if(!pe||i!=null)return;let t=O?`Untitled-${e?.untitledNumber??1}`:n?x(n):`Untitled`,r=g?`${t} \u25CF`:t;pe.title!==r&&w(pe.id,{title:r})},[g]);let yt=(0,L.useCallback)(async e=>{if(n&&!(!Q&&!r))try{Q?await y.put(`/api/fs/write`,{path:n,content:e}):await y.put(`${ae(r)}/files/write`,{path:n,content:e}),_(!1)}catch{}},[n,r,Q]);function bt(n){let r=n??``;s(r),b.current=r,_(!0),v.current&&clearTimeout(v.current),O?v.current=setTimeout(()=>{t&&w(t,{metadata:{...e,unsavedContent:b.current}})},2e3):v.current=setTimeout(()=>yt(b.current),1e3)}let xt=(0,L.useCallback)(async(e,n)=>{try{if(v.current&&clearTimeout(v.current),await y.put(`/api/fs/write`,{path:e,content:n}),t){let{closeTab:n,openTab:r}=se.getState();n(t),r({type:`editor`,title:x(e),projectId:null,metadata:{filePath:e},closable:!0})}_(!1),j(!1)}catch{}},[t]),$=e?.lineNumber,St=e?.endLine,Ct=e?.revealAt,wt=(0,L.useCallback)(()=>{let e=S.current;if(!(!e||!$||$<=0)){if(e.revealLineInCenter($),e.setPosition({lineNumber:$,column:1}),St&&St>=$){let t=e.getModel(),n=t?.getLineCount()??$,r=Math.min(St,n),i=t?.getLineMaxColumn(r)??1;e.setSelection({startLineNumber:$,startColumn:1,endLineNumber:r,endColumn:i})}e.focus()}},[$,St]);(0,L.useEffect)(()=>{Ct!=null&&wt()},[Ct,wt]);let Tt=(0,L.useCallback)((e,t)=>{if(S.current=e,V.current=t,$&&$>0&&setTimeout(()=>wt(),100),O&&e.addCommand(t.KeyMod.CtrlCmd|t.KeyCode.KeyS,()=>j(!0)),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>oe.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),J&&(H.current?.dispose(),H.current=t.languages.registerCompletionItemProvider(`sql`,te(t,J))),F){e.addAction({id:`run-sql-at-cursor`,label:`Run Statement at Cursor`,keybindings:[t.KeyMod.CtrlCmd|t.KeyCode.Enter],run:e=>{let t=e.getPosition();if(!t)return;let n=h(e.getValue(),t.lineNumber);n&&mt.current(n)}}),Z.current.forEach(e=>e.dispose()),Z.current=[];let n=e.getModel(),r=e.addCommand(0,(e,t)=>{t&&mt.current(t)});if(r&&n){let e=t.languages.registerCodeLensProvider(`sql`,{provideCodeLenses:e=>{if(e!==n)return{lenses:[],dispose:()=>{}};let t=[],i=e.getValue().split(`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,y as n}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{r,t as i}from"./api-client-DhXpjLdi.js";import"./vendor-mermaid-CYOBtZtD.js";import{t as a}from"./settings-store-DFMz_Oer.js";import{J as o,Qt as s,o as c}from"./index-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,y as n}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{r,t as i}from"./api-client-DhXpjLdi.js";import"./vendor-mermaid-CYOBtZtD.js";import{t as a}from"./settings-store-DFMz_Oer.js";import{J as o,Qt as s,o as c}from"./index-BuX7JkCt.js";import{t as l}from"./use-monaco-theme-5XjAzOzE.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(o(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+`
|