@hienlh/ppm 0.17.24 → 0.17.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/assets/skills/ppm/SKILL.md +1 -1
  3. package/assets/skills/ppm/references/http-api.md +1 -1
  4. package/dist/web/assets/{ai-resource-editor-CwZAAlN5.js → ai-resource-editor-qnr1gXKX.js} +1 -1
  5. package/dist/web/assets/{audio-preview-C8ePPqYM.js → audio-preview-IJyTkZhv.js} +1 -1
  6. package/dist/web/assets/{chat-tab-ByfGBWbW.js → chat-tab-Bf7bP_mH.js} +2 -2
  7. package/dist/web/assets/{code-editor-BLUWMpZn.js → code-editor-DbgRk7IQ.js} +2 -2
  8. package/dist/web/assets/{conflict-editor-B1oxNu29.js → conflict-editor-7379QQTo.js} +1 -1
  9. package/dist/web/assets/{csv-preview-CrGymnn9.js → csv-preview-CkZtgJJd.js} +1 -1
  10. package/dist/web/assets/{database-viewer-BTofJwov.js → database-viewer-BOWXg1eU.js} +1 -1
  11. package/dist/web/assets/{diff-viewer-Bsp25uLy.js → diff-viewer-3q8WtMhX.js} +1 -1
  12. package/dist/web/assets/{docx-preview-BULrDLso.js → docx-preview-uAcT8IrY.js} +1 -1
  13. package/dist/web/assets/{extension-webview-gByeDwuJ.js → extension-webview-C9B286ef.js} +1 -1
  14. package/dist/web/assets/{git-log-panel-BjB3uGkM.js → git-log-panel-CWfaQmIt.js} +1 -1
  15. package/dist/web/assets/{glide-data-grid-BmofPEFh.js → glide-data-grid-BTbN5x8y.js} +1 -1
  16. package/dist/web/assets/{group-chat-tab-DczxC8y0.js → group-chat-tab-CD1tHFCt.js} +1 -1
  17. package/dist/web/assets/{image-preview-C2JNJTTR.js → image-preview-D35tUSfv.js} +1 -1
  18. package/dist/web/assets/index-DMEso_fH.js +50 -0
  19. package/dist/web/assets/{keybindings-store-DWwuOAWb.js → keybindings-store-C56hagRp.js} +1 -1
  20. package/dist/web/assets/{markdown-renderer-BGumVkCU.js → markdown-renderer-CaVoLF6f.js} +1 -1
  21. package/dist/web/assets/{markdown-renderer-CvQmV_TU.js → markdown-renderer-w7cIJc1V.js} +1 -1
  22. package/dist/web/assets/{notification-store-OaYhYp1C.js → notification-store-CijmEBze.js} +1 -1
  23. package/dist/web/assets/{pdf-preview-DjWTE3jF.js → pdf-preview-URqY4tEa.js} +1 -1
  24. package/dist/web/assets/{postgres-viewer-K6ZyFyso.js → postgres-viewer-D3iSQpJq.js} +1 -1
  25. package/dist/web/assets/settings-store-UwT_fNhg.js +2 -0
  26. package/dist/web/assets/{settings-tab-DcUZ7ln3.js → settings-tab-BMAlaxBD.js} +1 -1
  27. package/dist/web/assets/{sql-query-editor-D9pM_Dys.js → sql-query-editor-Qrom7wG2.js} +1 -1
  28. package/dist/web/assets/{sqlite-viewer-zudsiPxP.js → sqlite-viewer-CPzA2RA4.js} +1 -1
  29. package/dist/web/assets/{system-monitor-tab-C7VZxGbH.js → system-monitor-tab-DEXXqZIz.js} +1 -1
  30. package/dist/web/assets/{terminal-tab-xiwZMQLE.js → terminal-tab-Cn1szPMh.js} +1 -1
  31. package/dist/web/assets/{tool-cards-C4DU4njU.js → tool-cards-DNftJX5Y.js} +2 -2
  32. package/dist/web/assets/{use-monaco-theme-D6Z2faTR.js → use-monaco-theme-XO5ZyYBW.js} +1 -1
  33. package/dist/web/assets/{video-preview-BL-sWnxi.js → video-preview-U2aMrCxv.js} +1 -1
  34. package/dist/web/index.html +2 -2
  35. package/dist/web/sw.js +1 -1
  36. package/package.json +1 -1
  37. package/src/cli/commands/status.ts +21 -2
  38. package/src/server/routes/settings.ts +11 -0
  39. package/src/services/autostart-generator.ts +5 -0
  40. package/src/services/supervisor.ts +61 -28
  41. package/src/web/components/database/connection-list.tsx +50 -28
  42. package/src/web/components/database/use-db-tree-expansion.ts +74 -0
  43. package/src/web/stores/settings-store.ts +43 -0
  44. package/dist/web/assets/index-D6qn4rtk.js +0 -50
  45. package/dist/web/assets/settings-store-C7VeYnhf.js +0 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.17.26] - 2026-08-18
4
+
5
+ ### Fixed
6
+ - **PPM could go silently dead right after an upgrade** — once the upgrade finished, neither the local address nor the share link answered any more; the page simply spun forever instead of failing. `ppm status` insisted everything was running, and `ppm restart` changed nothing, so the only way back was `ppm stop --kill` followed by `ppm start`. Before starting the server, PPM checks that the port is free by briefly listening on it itself. That check is a real listening socket, so the browser tabs, extensions and chat windows all reconnecting after the upgrade could connect to it — and a socket with a connection open never finishes closing, so the check never returned an answer and the server was never started at all. Everything around it stayed healthy, which is why nothing reported a problem: the supervisor was alive, the share tunnel was alive, and the port was open and accepting connections — just never replying. The check now refuses connections and gives up after two seconds, and three further gaps that let this go unnoticed are closed: the health check now starts a server that was never started rather than only watching one that already exists, `ppm restart` now starts a server when there is none to restart, and `ppm status` now asks the server itself instead of trusting its own notes.
7
+ - **Upgrading dropped the share link and started over** — every upgrade was supposed to hand the running tunnel to the new version so the public address stays the same, and it did, but on macOS the replacement was killed a second later and a cold one started in its place, with a new address. The upgrade works by starting the new version and stepping aside, and macOS was treating the replacement as part of the outgoing version and shutting it down along with it. The replacement now runs in its own right, so the handover survives.
8
+
9
+ ## [0.17.25] - 2026-08-17
10
+
11
+ ### Fixed
12
+ - **The database sidebar forgot which connections and tables you had opened** — expanding a connection and a few of its tables lasted only until the page was reloaded, and even switching to another sidebar panel and back was enough to collapse the whole tree, leaving you to click your way down to the same table again and again. The open state was held only in the browser's memory for as long as that panel stayed on screen, and nothing ever wrote it down. It is now kept alongside your other interface preferences, which live on the PPM server rather than in the browser alone, so it also survives opening PPM at a different address or from another device. Restoring the tree fetches what it needs again: the table list for each connection that was open, and the columns of each table that was expanded. Connections you delete are removed from the record, so it cannot fill up with entries for things that no longer exist.
13
+
3
14
  ## [0.17.24] - 2026-08-17
4
15
 
5
16
  ### Fixed
@@ -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.24 at build time. Re-run `ppm export skill --install` to refresh. -->
74
+ <!-- Generated for PPM v0.17.26 at build time. Re-run `ppm export skill --install` to refresh. -->
@@ -282,4 +282,4 @@ _Base URL: `http://localhost:8080` (default; override via `ppm config set port <
282
282
  - `ws://<host>/ws/terminal` — PTY terminal multiplexer
283
283
  - `ws://<host>/ws/extensions` — extension host channel
284
284
 
285
- <!-- Generated from src/server/routes/ for PPM v0.17.24 -->
285
+ <!-- Generated from src/server/routes/ for PPM v0.17.26 -->
@@ -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-C7VeYnhf.js";import{n as a}from"./utils-E0yyGxXt.js";import{D as o,E as s,O as c,Ot as l,T as u,Xt as d,Zt as f,k as p,kt as m,o as h}from"./index-D6qn4rtk.js";import{t as g}from"./use-monaco-theme-D6Z2faTR.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),c(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`),o.getState().reload()}catch(e){i.error(e.message)}finally{P(!1)}}},[t,w,D,x,N]);(0,_.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&(e.preventDefault(),R())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[R]);let z=s[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)(u,{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)(l,{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)(f,{className:`size-3.5 animate-spin`}):(0,v.jsx)(r,{className:`size-3.5`}),` Save`]})]})]}),x&&(0,v.jsx)(b,{icon:d,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:m,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)(f,{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
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,y as n}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t as r}from"./save-BM4p9_9n.js";import{o as i}from"./api-client-DhXpjLdi.js";import"./vendor-mermaid-CYOBtZtD.js";import"./settings-store-UwT_fNhg.js";import{n as a}from"./utils-E0yyGxXt.js";import{D as o,E as s,O as c,Ot as l,T as u,Xt as d,Zt as f,k as p,kt as m,o as h}from"./index-DMEso_fH.js";import{t as g}from"./use-monaco-theme-XO5ZyYBW.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),c(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`),o.getState().reload()}catch(e){i.error(e.message)}finally{P(!1)}}},[t,w,D,x,N]);(0,_.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`s`&&(e.preventDefault(),R())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[R]);let z=s[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)(u,{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)(l,{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)(f,{className:`size-3.5 animate-spin`}):(0,v.jsx)(r,{className:`size-3.5`}),` Save`]})]})]}),x&&(0,v.jsx)(b,{icon:d,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:m,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)(f,{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{Zt as i}from"./index-D6qn4rtk.js";import{t as a}from"./use-blob-url-BMZ0zo_4.js";var o=t(`music`,[[`path`,{d:`M9 18V5l12-2v13`,key:`1jmyc2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`circle`,{cx:`18`,cy:`16`,r:`3`,key:`1hluhg`}]]),s=e();function c({filePath:e,projectName:t}){let{blobUrl:c,error:l}=a(e,t);return l?(0,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,s.jsx)(n,{className:`size-10 text-text-subtle`}),(0,s.jsx)(`p`,{className:`text-sm`,children:`Failed to load audio.`})]}):c?(0,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 p-4 bg-surface`,children:[(0,s.jsx)(o,{className:`size-16 text-text-subtle`}),(0,s.jsx)(`p`,{className:`text-sm text-text-secondary truncate max-w-xs`,children:r(e)}),(0,s.jsx)(`audio`,{src:c,controls:!0,className:`w-full max-w-md`})]}):(0,s.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,s.jsx)(i,{className:`size-5 animate-spin text-text-subtle`})})}export{c as AudioPreview};
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{Zt as i}from"./index-DMEso_fH.js";import{t as a}from"./use-blob-url-BMZ0zo_4.js";var o=t(`music`,[[`path`,{d:`M9 18V5l12-2v13`,key:`1jmyc2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`circle`,{cx:`18`,cy:`16`,r:`3`,key:`1hluhg`}]]),s=e();function c({filePath:e,projectName:t}){let{blobUrl:c,error:l}=a(e,t);return l?(0,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,s.jsx)(n,{className:`size-10 text-text-subtle`}),(0,s.jsx)(`p`,{className:`text-sm`,children:`Failed to load audio.`})]}):c?(0,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 p-4 bg-surface`,children:[(0,s.jsx)(o,{className:`size-16 text-text-subtle`}),(0,s.jsx)(`p`,{className:`text-sm text-text-secondary truncate max-w-xs`,children:r(e)}),(0,s.jsx)(`audio`,{src:c,controls:!0,className:`w-full max-w-md`})]}):(0,s.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,s.jsx)(i,{className:`size-5 animate-spin text-text-subtle`})})}export{c as AudioPreview};
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-CvQmV_TU.js","assets/vendor-mermaid-CYOBtZtD.js","assets/rolldown-runtime-FhOqtrmT.js","assets/vendor-ui-DMRGWRuc.js","assets/vendor-markdown-CKTlmXbz.js","assets/markdown-renderer-BGumVkCU.js","assets/index-D6qn4rtk.js","assets/dialog-HHdNInEH.js","assets/utils-E0yyGxXt.js","assets/createLucideIcon-ConhwJnb.js","assets/x-BsFLg-T8.js","assets/eye-off-Rq1n2-oe.js","assets/bot-E9mcVZnr.js","assets/mobile-bottom-sheet-BwPBKZON.js","assets/chevron-right-DeUue2aK.js","assets/use-is-mobile-CE6AamG6.js","assets/sparkles-B3DmG8PJ.js","assets/database-COYAMZaw.js","assets/plus-DcuJuDC3.js","assets/api-client-DhXpjLdi.js","assets/react-8hrD3-kv.js","assets/api-settings-BUYvGBdi.js","assets/project-store-C1jInVih.js","assets/panel-store-DsDZX8Mi.js","assets/settings-store-C7VeYnhf.js","assets/tab-store-ByORqglW.js","assets/apply-theme-BSJDABU3.js","assets/resolve-theme-B9Mgd5GG.js","assets/index-DjkJR3PP.css","assets/api-client-DNTkryX1.js"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,y as n}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t as r}from"./createLucideIcon-ConhwJnb.js";import{t as i}from"./bot-E9mcVZnr.js";import{g as a,h as o,p as s,t as c}from"./mobile-bottom-sheet-BwPBKZON.js";import{n as l,t as u}from"./use-is-mobile-CE6AamG6.js";import{t as d}from"./chevron-right-DeUue2aK.js";import{a as f,i as p,n as m,r as h,t as g}from"./tool-cards-C4DU4njU.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 D}from"./sparkles-B3DmG8PJ.js";import{n as O,r as ee,t as te}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 ie}from"./settings-store-C7VeYnhf.js";import{n as P,r as ae,t as F}from"./utils-E0yyGxXt.js";import{t as I}from"./panel-store-DsDZX8Mi.js";import{i as L}from"./project-store-C1jInVih.js";import{t as oe}from"./tab-store-ByORqglW.js";import{_ as R,a as z,c as se,h as ce,i as le,l as ue,m as B,o as V,p as H,r as U,s as W,t as G,u as K}from"./api-settings-BUYvGBdi.js";import{$t as de,At as fe,B as pe,Bt as me,Ct as he,Dt as q,Et as ge,F as _e,Ft as J,H as Y,I as ve,It as ye,Kt as be,L as xe,Lt as Se,Mt as Ce,N as we,Nt as Te,P as Ee,Pt as De,Qt as Oe,R as ke,Rt as Ae,St as je,U as X,Ut as Me,V as Ne,Vt as Pe,Wt as Fe,Xt as Ie,Yt as Le,Zt as Z,_n as Re,_t as ze,an as Be,bn as Ve,cn as He,f as Ue,fn as We,gn as Ge,hn as Ke,ht as qe,it as Je,ln as Ye,mn as Xe,mt as Ze,nn as Qe,pn as $e,pt as et,qt as tt,r as nt,rn as rt,t as it,vn as at,w as ot,wt as st,xt as ct,yn as lt,z as ut}from"./index-D6qn4rtk.js";var dt=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`}]]),ft=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`}]]),pt=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`}]]),mt=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`}]]),ht=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`}]]),gt=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`}]]),_t=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`}]]),vt=r(`slash`,[[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}]]),Q=e(t(),1);function yt(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 bt(e,t){let n=`pc-${yt(t)}-`;return e.map(e=>e.id?{...e,id:`${n}${e.id}`}:e)}function xt(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 St=null;function Ct(){return St||=new AudioContext,St}function wt(e,t,n,r,i=`sine`){let a=Ct(),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 Tt(){let e=Ct().currentTime;wt(523,.15,e,.15),wt(659,.2,e+.12,.15)}function Et(){let e=Ct().currentTime;wt(880,.12,e,.18,`square`),wt(698,.12,e+.15,.18,`square`),wt(880,.15,e+.3,.15,`square`)}function Dt(){let e=Ct().currentTime;wt(440,.12,e,.12),wt(523,.12,e+.1,.12),wt(659,.18,e+.2,.12)}var Ot={done:Tt,approval_request:Et,question:Dt};function kt(e){try{Ot[e]?.()}catch{}}var At={hasTeams:!1,teamNames:[],messageCount:0,unreadCount:0};function jt(e){if(document.hidden)return!1;let{panels:t}=I.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 Mt(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)([]),[D,O]=(0,Q.useState)(null),[ee,te]=(0,Q.useState)(null),[k,ne]=(0,Q.useState)(!1),[re,ie]=(0,Q.useState)(null),[P,ae]=(0,Q.useState)(null),F=(0,Q.useRef)(null),L=(0,Q.useRef)(null),[oe,R]=(0,Q.useState)(null),z=(0,Q.useRef)(null),[se,ce]=(0,Q.useState)(!0),le=(0,Q.useRef)(null),ue=(0,Q.useRef)(null),B=(0,Q.useRef)(``),V=(0,Q.useRef)([]),H=(0,Q.useRef)(new Map),U=(0,Q.useRef)(null),W=(0,Q.useRef)(`idle`),G=(0,Q.useRef)(null),K=(0,Q.useRef)(()=>{}),de=(0,Q.useRef)(null),fe=(0,Q.useRef)(!1),pe=(0,Q.useRef)(new Set),me=(0,Q.useRef)(0),he=(0,Q.useRef)(null),q=(0,Q.useRef)(e);q.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)(At),[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 Je.getState().setStreaming(e,d!==`idle`),()=>{Je.getState().setStreaming(e,!1)}},[e,d]);let De=(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},[]),Oe=(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}]})})},[]),ke=(0,Q.useCallback)(()=>{Y.current||=window.setTimeout(Oe,100)},[Oe]),Ae=(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},O(null);break;case`account_retry`:t.accountId&&t.accountLabel&&(U.current={accountId:t.accountId,accountLabel:t.accountLabel}),V.current=[t],ke();break;case`status_update`:{let e=t.accountLabel?` (${t.accountLabel})`:``;O(`${t.message}${e}`);break}case`text`:{let e=t.parentToolUseId;if(e&&De(t,e)){ke();break}B.current+=t.content,V.current.push(t),ke();break}case`thinking`:{let e=t.parentToolUseId;if(e&&De(t,e)){ke();break}V.current.push(t),ke();break}case`tool_use`:{if(t.tool===`AskUserQuestion`){t.toolUseId&&pe.current.add(t.toolUseId);break}let e=t.parentToolUseId;if(e&&De(t,e)){ke();break}let n=t.toolUseId;r(e=>!!n&&e.type===`tool_use`&&e.toolUseId===n),ke();break}case`tool_result`:{let e=t.toolUseId;if(e&&H.current.delete(e),e&&pe.current.has(e))break;let n=t.parentToolUseId;if(n&&De(t,n)){ke();break}r(t=>!!e&&t.type===`tool_result`&&t.toolUseId===e),ke();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}),q.current&&!jt(q.current)){kt(t.tool===`AskUserQuestion`?`question`:`approval_request`);let e=q.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}=I.getState();for(let[n,r]of Object.entries(t)){let t=r.tabs.find(t=>t.metadata?.sessionId===e);if(t){I.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}),ke()}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),q.current&&!jt(q.current)&&kt(`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,he.current=null,H.current.clear(),O(null);break}}},[De,ke]),je=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`title_updated`){te(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),ie(t.sessionId??q.current);let e=t,n=e.phase;f(n),W.current=n,e.sessionTitle&&te(e.sessionTitle),e.model&&(L.current&&e.model!==L.current||(e.model===L.current&&(L.current=null),ae(e.model),F.current=e.model)),typeof e.effort==`string`&&(R(e.effort),z.current=e.effort),typeof e.thinking==`boolean`&&ce(e.thinking),e.pendingApproval&&y({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),C(e.compactStatus===`compacting`?`compacting`:null),n===`idle`&&(de.current?.(),h(!1));return}if(t.type===`turn_events`){let e=t.events,n=t.userMessage;if(!e?.length&&!n){h(!1);return}me.current&&=(cancelAnimationFrame(me.current),0),he.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++)Ae(e[n]);r=t,r<e.length?me.current=requestAnimationFrame(a):(me.current=0,fe.current=!1,h(!1))};me.current=requestAnimationFrame(a);return}Ae(t)}},[Ae]),{send:X,connect:Me}=m({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:je,autoConnect:!!e&&!!n});K.current=X,(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=[],he.current=null,H.current.clear(),Y.current&&=(clearTimeout(Y.current),0),ne(!1),ie(null),ve.current={teamNames:new Set,messages:[]},ye.current=0,xe(At),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=he.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 Ne=(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),X(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode,priority:t?.priority,images:t?.images,...F.current&&{model:F.current},...z.current&&{effort:z.current},...le.current!==null&&{thinking:le.current}}))},[X]),Pe=(0,Q.useCallback)(e=>{ae(e),F.current=e,L.current=e,X(JSON.stringify({type:`set_model`,model:e}))},[X]),Fe=(0,Q.useCallback)(e=>{R(e),z.current=e,X(JSON.stringify({type:`set_effort`,effort:e}))},[X]),Ie=(0,Q.useCallback)(e=>{ce(e),le.current=e,X(JSON.stringify({type:`set_thinking`,enabled:e}))},[X]),Le=(0,Q.useCallback)((e,t,n)=>{if(X(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)},[X]),Z=(0,Q.useCallback)(()=>{if(W.current===`idle`)return;X(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)},[X]),Re=(0,Q.useCallback)(e=>{e&&X(JSON.stringify({type:`kill_background_shell`,shellId:e}))},[X]),ze=(0,Q.useCallback)(e=>{if(!e)return;let t=e.replace(/\.output$/,``);return E.current.find(n=>n.shellId===t||n.outputPath.endsWith(e)||n.outputPath.endsWith(`${t}.output`))},[]);(0,Q.useEffect)(()=>{e&&it.getState().setSessionShells(e,w)},[e,w]),(0,Q.useEffect)(()=>{if(e)return it.getState().retainSession(e),()=>{it.getState().releaseSession(e)}},[e]);let Be=(0,Q.useCallback)(()=>{ne(!1),h(!0),Me()},[Me]),Ve=(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=Ve;let He=(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=bt(await N.get(i),t);return o(t=>{let n=new Map(t);return n.set(e,a),n}),a.length},[n]),Ue=(0,Q.useCallback)(e=>a.has(e),[a]),We=(0,Q.useCallback)(e=>{i(t=>t.filter(t=>t.id!==e))},[]),Ge=(0,Q.useCallback)(()=>{i(e=>e.filter(e=>e.role!==`system`))},[]);return{messages:r,renderedMessages:(0,Q.useMemo)(()=>xt(r,a),[r,a]),expandCompact:He,isCompactExpanded:Ue,dismissMessage:We,clearErrors:Ge,messagesLoading:s,versionMap:l,isStreaming:Ee,phase:d,isReconnecting:p,connectingElapsed:g,pendingApproval:v,contextWindowPct:b,compactStatus:S,statusMessage:D,sessionTitle:ee,model:P,setModel:Pe,effort:oe,setEffort:Fe,thinking:se,setThinking:Ie,teamActivity:be,teamMessages:Se,markTeamRead:Te,bashPartialOutput:H,backgroundShells:w,killBackgroundShell:Re,findBackgroundShellByOutput:ze,sendMessage:Ne,respondToApproval:Le,cancelStreaming:Z,reconnect:Be,refetchMessages:Ve,isConnected:k&&re===e}}var Nt=12e4;function Pt(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(),Nt),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,Q.useCallback)(()=>l(!0),[l])}}var Ft={damping:.7,stiffness:.05,mass:1.25},It=70,Lt=1e3/60,Rt=350,zt=!1;globalThis.document?.addEventListener(`mousedown`,()=>{zt=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{zt=!1}),globalThis.document?.addEventListener(`click`,()=>{zt=!1});var Bt=(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(!zt)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<=It}}},[]),f=(0,Q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Ut(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))/Lt;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:Ut(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=Vt(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=Vt(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=Ut(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:Rt})}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 Vt(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Ht=new Map;function Ut(...e){let t={...Ft},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 Ht.has(r)||Ht.set(r,Object.freeze(t)),n?`instant`:Ht.get(r)}function Wt(e,t,n,r){let[i,a]=(0,Q.useState)([]),o=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(!n||!e||!t){a([]);return}let r=!1;return o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{N.get(`/api/project/${encodeURIComponent(e)}/chat/sessions/${encodeURIComponent(t)}/tasks`).then(e=>{r||a(e)}).catch(()=>{})},300),()=>{r=!0,o.current&&clearTimeout(o.current)}},[e,t,n,r]),i}var $=n(),Gt=new Set([`TaskCreate`,`TaskUpdate`,`TaskStop`]);function Kt(e){let t=0;for(let n of e)if(n.events)for(let e of n.events)e.type===`tool_use`&&Gt.has(e.tool)&&t++;return t}var qt={completed:{icon:`✓`,cls:`text-success`},in_progress:{icon:`▶`,cls:`text-warning`},stopped:{icon:`■`,cls:`text-text-subtle`},pending:{icon:`○`,cls:`text-text-subtle`}};function Jt({projectName:e,sessionId:t,messages:n}){let r=(0,Q.useMemo)(()=>Kt(n),[n]),i=Wt(e,t,r>0,r),[a,o]=(0,Q.useState)(!0);if(i.length===0||i.every(e=>e.status===`completed`||e.status===`stopped`))return null;let s=i.filter(e=>e.status===`completed`).length,c=i.length,u=c?Math.round(s/c*100):0;return(0,$.jsxs)(`div`,{className:`shrink-0 border-b border-border bg-surface/60 backdrop-blur-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`flex items-center gap-2 w-full px-3 min-h-11 text-left text-xs hover:bg-surface transition-colors`,children:[a?(0,$.jsx)(d,{className:`size-3.5 shrink-0`}):(0,$.jsx)(l,{className:`size-3.5 shrink-0`}),(0,$.jsx)(h,{className:`size-3.5 shrink-0 text-text-secondary`}),(0,$.jsx)(`span`,{className:`text-text-primary font-medium`,children:`Tasks`}),(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[s,`/`,c,` done`]}),(0,$.jsx)(`span`,{className:`ml-auto h-1 w-16 rounded-full bg-border overflow-hidden shrink-0`,children:(0,$.jsx)(`span`,{className:`block h-full bg-success/70`,style:{width:`${u}%`}})})]}),!a&&(0,$.jsx)(`ul`,{className:`px-3 pb-2 space-y-0.5 max-h-48 overflow-y-auto`,children:i.map(e=>(0,$.jsx)(Yt,{task:e},e.id))})]})}function Yt({task:e}){let t=qt[e.status]??qt.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 Xt=/read the full transcript at:\s*(\S+\.jsonl)/i;function Zt(e){return e.match(Xt)?.[1]?.trim()??null}var Qt=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 $t({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)(Ze,{projectName:e,onSelectSession:t,className:`w-full px-4`})]})}function en(e){try{return new Date(e).toLocaleString()}catch{return``}}function tn({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 nn({content:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsx)(tn,{icon:t?(0,$.jsx)(o,{className:`size-3.5`}):(0,$.jsx)(Ye,{className:`size-3.5`}),label:t?`Copied`:`Copy`,title:`Copy message to clipboard`,onClick:()=>{navigator.clipboard?.writeText(e).catch(()=>{}),n(!0),setTimeout(()=>n(!1),1500)}})}function rn({timestamp:e,content:t,accountLabel:n,className:r,children:i}){return(0,$.jsxs)(`div`,{className:P(`flex items-center gap-0.5 flex-wrap text-xs text-text-subtle select-none`,r),children:[(0,$.jsx)(`time`,{title:en(e),className:`pr-1 tabular-nums`,children:he(e)}),n&&(0,$.jsxs)(`span`,{className:`px-1 truncate max-w-40`,children:[`via `,n]}),(0,$.jsx)(nn,{content:t}),i]})}function an({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)(Ge,{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 on(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 sn(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 cn({questions:e,onSubmit:t,onSkip:n}){let r=(0,Q.useRef)(null),i=on(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=sn({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 ln=re(()=>import(`./markdown-renderer-CvQmV_TU.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28])),un=(0,Q.lazy)(()=>ln.then(e=>({default:e.MarkdownRenderer})));function dn({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:D,scrollToBottom:O,stopScroll:ee,isAtBottom:te}=Bt({initial:`instant`,resize:`instant`}),k=(0,Q.useMemo)(()=>e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return e.role===`user`?t:t||n}),[e]),ne=!!r||o,[A,j]=(0,Q.useState)(null),M=(0,Q.useCallback)(e=>{E(e),j(e)},[E]),N=(0,Q.useRef)(null);(0,Q.useLayoutEffect)(()=>{let e=A;e&&N.current!=null&&(e.scrollTop=e.scrollHeight-N.current,N.current=null)},[k.length,A]),(0,Q.useLayoutEffect)(()=>{A&&O({animation:`instant`})},[_,A]);let re=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>{A&&A.clientHeight>0&&(re.current=te)},[te,A]),(0,Q.useEffect)(()=>{let e=A;if(!e)return;let t=e.clientHeight,n=new ResizeObserver(()=>{let n=e.clientHeight,r=t===0&&n>0;t=n,r&&!re.current&&ee()});return n.observe(e),()=>n.disconnect()},[A,ee]);let ie=(0,Q.useCallback)((e,t)=>{m?.(e,t)},[m]),P=(0,Q.useCallback)((e,t,n)=>{h?.(e,t,n)},[h]),ae=(0,Q.useCallback)(e=>{w?.(e)},[w]),F=(0,Q.useMemo)(()=>k.reduce((e,t)=>t.role===`system`?e+1:e,0),[k]),I=(0,Q.useMemo)(()=>k.reduce((e,t,n)=>(t.role===`user`&&e.push(n),e),[]),[k]),L=(0,Q.useCallback)(()=>{if(!S||!C)return null;for(let e of k){if(C(e.id))continue;let t=Zt(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=Zt(t.content||``);if(n)return{id:e.id,jsonlPath:n}}}}return null},[k,S,C])(),oe=!!L,[R,z]=(0,Q.useState)(!1),se=(0,Q.useCallback)(async()=>{if(!L||!S||R)return;let e=A;N.current=e?e.scrollHeight-e.scrollTop:null,z(!0);try{await S(L.id,L.jsonlPath)}finally{z(!1)}},[L,S,R,A]);return(0,Q.useEffect)(()=>{let e=A;if(!e||!oe)return;let t=()=>{e.scrollTop<200&&!R&&se()};return e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[A,oe,R,se]),t&&(!n||e.length===0)?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,$.jsx)(i,{className:`size-10 text-text-subtle animate-pulse`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!o?(0,$.jsx)($t,{projectName:p||``,onSelectSession:c||(()=>{})}):(0,$.jsxs)(`div`,{className:`relative flex-1 overflow-hidden flex flex-col min-h-0`,children:[(0,$.jsx)(Jt,{projectName:p,sessionId:_,messages:e}),F>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 (`,F,`)`]})}),R&&(0,$.jsxs)(`div`,{className:`absolute top-2 left-0 right-0 z-10 flex items-center justify-center gap-1.5 text-xs text-text-secondary pointer-events-none`,children:[(0,$.jsx)(Z,{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:D,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=pn(k[n]);t&&e.unshift(t)}l=e.join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-w7cIJc1V.js","assets/vendor-mermaid-CYOBtZtD.js","assets/rolldown-runtime-FhOqtrmT.js","assets/vendor-ui-DMRGWRuc.js","assets/vendor-markdown-CKTlmXbz.js","assets/markdown-renderer-CaVoLF6f.js","assets/index-DMEso_fH.js","assets/dialog-HHdNInEH.js","assets/utils-E0yyGxXt.js","assets/createLucideIcon-ConhwJnb.js","assets/x-BsFLg-T8.js","assets/eye-off-Rq1n2-oe.js","assets/bot-E9mcVZnr.js","assets/mobile-bottom-sheet-BwPBKZON.js","assets/chevron-right-DeUue2aK.js","assets/use-is-mobile-CE6AamG6.js","assets/sparkles-B3DmG8PJ.js","assets/database-COYAMZaw.js","assets/plus-DcuJuDC3.js","assets/api-client-DhXpjLdi.js","assets/react-8hrD3-kv.js","assets/api-settings-BUYvGBdi.js","assets/project-store-C1jInVih.js","assets/panel-store-DsDZX8Mi.js","assets/settings-store-UwT_fNhg.js","assets/tab-store-ByORqglW.js","assets/apply-theme-BSJDABU3.js","assets/resolve-theme-B9Mgd5GG.js","assets/index-DjkJR3PP.css","assets/api-client-DNTkryX1.js"])))=>i.map(i=>d[i]);
2
+ import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,y as n}from"./vendor-markdown-CKTlmXbz.js";import"./vendor-ui-DMRGWRuc.js";import{t as r}from"./createLucideIcon-ConhwJnb.js";import{t as i}from"./bot-E9mcVZnr.js";import{g as a,h as o,p as s,t as c}from"./mobile-bottom-sheet-BwPBKZON.js";import{n as l,t as u}from"./use-is-mobile-CE6AamG6.js";import{t as d}from"./chevron-right-DeUue2aK.js";import{a as f,i as p,n as m,r as h,t as g}from"./tool-cards-DNftJX5Y.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 D}from"./sparkles-B3DmG8PJ.js";import{n as O,r as ee,t as te}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 ie}from"./settings-store-UwT_fNhg.js";import{n as P,r as ae,t as F}from"./utils-E0yyGxXt.js";import{t as I}from"./panel-store-DsDZX8Mi.js";import{i as L}from"./project-store-C1jInVih.js";import{t as oe}from"./tab-store-ByORqglW.js";import{_ as R,a as z,c as se,h as ce,i as le,l as ue,m as B,o as V,p as H,r as U,s as W,t as G,u as K}from"./api-settings-BUYvGBdi.js";import{$t as de,At as fe,B as pe,Bt as me,Ct as he,Dt as q,Et as ge,F as _e,Ft as J,H as Y,I as ve,It as ye,Kt as be,L as xe,Lt as Se,Mt as Ce,N as we,Nt as Te,P as Ee,Pt as De,Qt as Oe,R as ke,Rt as Ae,St as je,U as X,Ut as Me,V as Ne,Vt as Pe,Wt as Fe,Xt as Ie,Yt as Le,Zt as Z,_n as Re,_t as ze,an as Be,bn as Ve,cn as He,f as Ue,fn as We,gn as Ge,hn as Ke,ht as qe,it as Je,ln as Ye,mn as Xe,mt as Ze,nn as Qe,pn as $e,pt as et,qt as tt,r as nt,rn as rt,t as it,vn as at,w as ot,wt as st,xt as ct,yn as lt,z as ut}from"./index-DMEso_fH.js";var dt=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`}]]),ft=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`}]]),pt=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`}]]),mt=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`}]]),ht=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`}]]),gt=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`}]]),_t=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`}]]),vt=r(`slash`,[[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}]]),Q=e(t(),1);function yt(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 bt(e,t){let n=`pc-${yt(t)}-`;return e.map(e=>e.id?{...e,id:`${n}${e.id}`}:e)}function xt(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 St=null;function Ct(){return St||=new AudioContext,St}function wt(e,t,n,r,i=`sine`){let a=Ct(),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 Tt(){let e=Ct().currentTime;wt(523,.15,e,.15),wt(659,.2,e+.12,.15)}function Et(){let e=Ct().currentTime;wt(880,.12,e,.18,`square`),wt(698,.12,e+.15,.18,`square`),wt(880,.15,e+.3,.15,`square`)}function Dt(){let e=Ct().currentTime;wt(440,.12,e,.12),wt(523,.12,e+.1,.12),wt(659,.18,e+.2,.12)}var Ot={done:Tt,approval_request:Et,question:Dt};function kt(e){try{Ot[e]?.()}catch{}}var At={hasTeams:!1,teamNames:[],messageCount:0,unreadCount:0};function jt(e){if(document.hidden)return!1;let{panels:t}=I.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 Mt(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)([]),[D,O]=(0,Q.useState)(null),[ee,te]=(0,Q.useState)(null),[k,ne]=(0,Q.useState)(!1),[re,ie]=(0,Q.useState)(null),[P,ae]=(0,Q.useState)(null),F=(0,Q.useRef)(null),L=(0,Q.useRef)(null),[oe,R]=(0,Q.useState)(null),z=(0,Q.useRef)(null),[se,ce]=(0,Q.useState)(!0),le=(0,Q.useRef)(null),ue=(0,Q.useRef)(null),B=(0,Q.useRef)(``),V=(0,Q.useRef)([]),H=(0,Q.useRef)(new Map),U=(0,Q.useRef)(null),W=(0,Q.useRef)(`idle`),G=(0,Q.useRef)(null),K=(0,Q.useRef)(()=>{}),de=(0,Q.useRef)(null),fe=(0,Q.useRef)(!1),pe=(0,Q.useRef)(new Set),me=(0,Q.useRef)(0),he=(0,Q.useRef)(null),q=(0,Q.useRef)(e);q.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)(At),[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 Je.getState().setStreaming(e,d!==`idle`),()=>{Je.getState().setStreaming(e,!1)}},[e,d]);let De=(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},[]),Oe=(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}]})})},[]),ke=(0,Q.useCallback)(()=>{Y.current||=window.setTimeout(Oe,100)},[Oe]),Ae=(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},O(null);break;case`account_retry`:t.accountId&&t.accountLabel&&(U.current={accountId:t.accountId,accountLabel:t.accountLabel}),V.current=[t],ke();break;case`status_update`:{let e=t.accountLabel?` (${t.accountLabel})`:``;O(`${t.message}${e}`);break}case`text`:{let e=t.parentToolUseId;if(e&&De(t,e)){ke();break}B.current+=t.content,V.current.push(t),ke();break}case`thinking`:{let e=t.parentToolUseId;if(e&&De(t,e)){ke();break}V.current.push(t),ke();break}case`tool_use`:{if(t.tool===`AskUserQuestion`){t.toolUseId&&pe.current.add(t.toolUseId);break}let e=t.parentToolUseId;if(e&&De(t,e)){ke();break}let n=t.toolUseId;r(e=>!!n&&e.type===`tool_use`&&e.toolUseId===n),ke();break}case`tool_result`:{let e=t.toolUseId;if(e&&H.current.delete(e),e&&pe.current.has(e))break;let n=t.parentToolUseId;if(n&&De(t,n)){ke();break}r(t=>!!e&&t.type===`tool_result`&&t.toolUseId===e),ke();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}),q.current&&!jt(q.current)){kt(t.tool===`AskUserQuestion`?`question`:`approval_request`);let e=q.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}=I.getState();for(let[n,r]of Object.entries(t)){let t=r.tabs.find(t=>t.metadata?.sessionId===e);if(t){I.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}),ke()}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),q.current&&!jt(q.current)&&kt(`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,he.current=null,H.current.clear(),O(null);break}}},[De,ke]),je=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`title_updated`){te(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),ie(t.sessionId??q.current);let e=t,n=e.phase;f(n),W.current=n,e.sessionTitle&&te(e.sessionTitle),e.model&&(L.current&&e.model!==L.current||(e.model===L.current&&(L.current=null),ae(e.model),F.current=e.model)),typeof e.effort==`string`&&(R(e.effort),z.current=e.effort),typeof e.thinking==`boolean`&&ce(e.thinking),e.pendingApproval&&y({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),C(e.compactStatus===`compacting`?`compacting`:null),n===`idle`&&(de.current?.(),h(!1));return}if(t.type===`turn_events`){let e=t.events,n=t.userMessage;if(!e?.length&&!n){h(!1);return}me.current&&=(cancelAnimationFrame(me.current),0),he.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++)Ae(e[n]);r=t,r<e.length?me.current=requestAnimationFrame(a):(me.current=0,fe.current=!1,h(!1))};me.current=requestAnimationFrame(a);return}Ae(t)}},[Ae]),{send:X,connect:Me}=m({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:je,autoConnect:!!e&&!!n});K.current=X,(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=[],he.current=null,H.current.clear(),Y.current&&=(clearTimeout(Y.current),0),ne(!1),ie(null),ve.current={teamNames:new Set,messages:[]},ye.current=0,xe(At),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=he.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 Ne=(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),X(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode,priority:t?.priority,images:t?.images,...F.current&&{model:F.current},...z.current&&{effort:z.current},...le.current!==null&&{thinking:le.current}}))},[X]),Pe=(0,Q.useCallback)(e=>{ae(e),F.current=e,L.current=e,X(JSON.stringify({type:`set_model`,model:e}))},[X]),Fe=(0,Q.useCallback)(e=>{R(e),z.current=e,X(JSON.stringify({type:`set_effort`,effort:e}))},[X]),Ie=(0,Q.useCallback)(e=>{ce(e),le.current=e,X(JSON.stringify({type:`set_thinking`,enabled:e}))},[X]),Le=(0,Q.useCallback)((e,t,n)=>{if(X(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)},[X]),Z=(0,Q.useCallback)(()=>{if(W.current===`idle`)return;X(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)},[X]),Re=(0,Q.useCallback)(e=>{e&&X(JSON.stringify({type:`kill_background_shell`,shellId:e}))},[X]),ze=(0,Q.useCallback)(e=>{if(!e)return;let t=e.replace(/\.output$/,``);return E.current.find(n=>n.shellId===t||n.outputPath.endsWith(e)||n.outputPath.endsWith(`${t}.output`))},[]);(0,Q.useEffect)(()=>{e&&it.getState().setSessionShells(e,w)},[e,w]),(0,Q.useEffect)(()=>{if(e)return it.getState().retainSession(e),()=>{it.getState().releaseSession(e)}},[e]);let Be=(0,Q.useCallback)(()=>{ne(!1),h(!0),Me()},[Me]),Ve=(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=Ve;let He=(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=bt(await N.get(i),t);return o(t=>{let n=new Map(t);return n.set(e,a),n}),a.length},[n]),Ue=(0,Q.useCallback)(e=>a.has(e),[a]),We=(0,Q.useCallback)(e=>{i(t=>t.filter(t=>t.id!==e))},[]),Ge=(0,Q.useCallback)(()=>{i(e=>e.filter(e=>e.role!==`system`))},[]);return{messages:r,renderedMessages:(0,Q.useMemo)(()=>xt(r,a),[r,a]),expandCompact:He,isCompactExpanded:Ue,dismissMessage:We,clearErrors:Ge,messagesLoading:s,versionMap:l,isStreaming:Ee,phase:d,isReconnecting:p,connectingElapsed:g,pendingApproval:v,contextWindowPct:b,compactStatus:S,statusMessage:D,sessionTitle:ee,model:P,setModel:Pe,effort:oe,setEffort:Fe,thinking:se,setThinking:Ie,teamActivity:be,teamMessages:Se,markTeamRead:Te,bashPartialOutput:H,backgroundShells:w,killBackgroundShell:Re,findBackgroundShellByOutput:ze,sendMessage:Ne,respondToApproval:Le,cancelStreaming:Z,reconnect:Be,refetchMessages:Ve,isConnected:k&&re===e}}var Nt=12e4;function Pt(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(),Nt),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,Q.useCallback)(()=>l(!0),[l])}}var Ft={damping:.7,stiffness:.05,mass:1.25},It=70,Lt=1e3/60,Rt=350,zt=!1;globalThis.document?.addEventListener(`mousedown`,()=>{zt=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{zt=!1}),globalThis.document?.addEventListener(`click`,()=>{zt=!1});var Bt=(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(!zt)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<=It}}},[]),f=(0,Q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Ut(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))/Lt;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:Ut(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=Vt(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=Vt(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=Ut(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:Rt})}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 Vt(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Ht=new Map;function Ut(...e){let t={...Ft},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 Ht.has(r)||Ht.set(r,Object.freeze(t)),n?`instant`:Ht.get(r)}function Wt(e,t,n,r){let[i,a]=(0,Q.useState)([]),o=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(!n||!e||!t){a([]);return}let r=!1;return o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{N.get(`/api/project/${encodeURIComponent(e)}/chat/sessions/${encodeURIComponent(t)}/tasks`).then(e=>{r||a(e)}).catch(()=>{})},300),()=>{r=!0,o.current&&clearTimeout(o.current)}},[e,t,n,r]),i}var $=n(),Gt=new Set([`TaskCreate`,`TaskUpdate`,`TaskStop`]);function Kt(e){let t=0;for(let n of e)if(n.events)for(let e of n.events)e.type===`tool_use`&&Gt.has(e.tool)&&t++;return t}var qt={completed:{icon:`✓`,cls:`text-success`},in_progress:{icon:`▶`,cls:`text-warning`},stopped:{icon:`■`,cls:`text-text-subtle`},pending:{icon:`○`,cls:`text-text-subtle`}};function Jt({projectName:e,sessionId:t,messages:n}){let r=(0,Q.useMemo)(()=>Kt(n),[n]),i=Wt(e,t,r>0,r),[a,o]=(0,Q.useState)(!0);if(i.length===0||i.every(e=>e.status===`completed`||e.status===`stopped`))return null;let s=i.filter(e=>e.status===`completed`).length,c=i.length,u=c?Math.round(s/c*100):0;return(0,$.jsxs)(`div`,{className:`shrink-0 border-b border-border bg-surface/60 backdrop-blur-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`flex items-center gap-2 w-full px-3 min-h-11 text-left text-xs hover:bg-surface transition-colors`,children:[a?(0,$.jsx)(d,{className:`size-3.5 shrink-0`}):(0,$.jsx)(l,{className:`size-3.5 shrink-0`}),(0,$.jsx)(h,{className:`size-3.5 shrink-0 text-text-secondary`}),(0,$.jsx)(`span`,{className:`text-text-primary font-medium`,children:`Tasks`}),(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[s,`/`,c,` done`]}),(0,$.jsx)(`span`,{className:`ml-auto h-1 w-16 rounded-full bg-border overflow-hidden shrink-0`,children:(0,$.jsx)(`span`,{className:`block h-full bg-success/70`,style:{width:`${u}%`}})})]}),!a&&(0,$.jsx)(`ul`,{className:`px-3 pb-2 space-y-0.5 max-h-48 overflow-y-auto`,children:i.map(e=>(0,$.jsx)(Yt,{task:e},e.id))})]})}function Yt({task:e}){let t=qt[e.status]??qt.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 Xt=/read the full transcript at:\s*(\S+\.jsonl)/i;function Zt(e){return e.match(Xt)?.[1]?.trim()??null}var Qt=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 $t({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)(Ze,{projectName:e,onSelectSession:t,className:`w-full px-4`})]})}function en(e){try{return new Date(e).toLocaleString()}catch{return``}}function tn({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 nn({content:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsx)(tn,{icon:t?(0,$.jsx)(o,{className:`size-3.5`}):(0,$.jsx)(Ye,{className:`size-3.5`}),label:t?`Copied`:`Copy`,title:`Copy message to clipboard`,onClick:()=>{navigator.clipboard?.writeText(e).catch(()=>{}),n(!0),setTimeout(()=>n(!1),1500)}})}function rn({timestamp:e,content:t,accountLabel:n,className:r,children:i}){return(0,$.jsxs)(`div`,{className:P(`flex items-center gap-0.5 flex-wrap text-xs text-text-subtle select-none`,r),children:[(0,$.jsx)(`time`,{title:en(e),className:`pr-1 tabular-nums`,children:he(e)}),n&&(0,$.jsxs)(`span`,{className:`px-1 truncate max-w-40`,children:[`via `,n]}),(0,$.jsx)(nn,{content:t}),i]})}function an({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)(Ge,{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 on(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 sn(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 cn({questions:e,onSubmit:t,onSkip:n}){let r=(0,Q.useRef)(null),i=on(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=sn({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 ln=re(()=>import(`./markdown-renderer-w7cIJc1V.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28])),un=(0,Q.lazy)(()=>ln.then(e=>({default:e.MarkdownRenderer})));function dn({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:D,scrollToBottom:O,stopScroll:ee,isAtBottom:te}=Bt({initial:`instant`,resize:`instant`}),k=(0,Q.useMemo)(()=>e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return e.role===`user`?t:t||n}),[e]),ne=!!r||o,[A,j]=(0,Q.useState)(null),M=(0,Q.useCallback)(e=>{E(e),j(e)},[E]),N=(0,Q.useRef)(null);(0,Q.useLayoutEffect)(()=>{let e=A;e&&N.current!=null&&(e.scrollTop=e.scrollHeight-N.current,N.current=null)},[k.length,A]),(0,Q.useLayoutEffect)(()=>{A&&O({animation:`instant`})},[_,A]);let re=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>{A&&A.clientHeight>0&&(re.current=te)},[te,A]),(0,Q.useEffect)(()=>{let e=A;if(!e)return;let t=e.clientHeight,n=new ResizeObserver(()=>{let n=e.clientHeight,r=t===0&&n>0;t=n,r&&!re.current&&ee()});return n.observe(e),()=>n.disconnect()},[A,ee]);let ie=(0,Q.useCallback)((e,t)=>{m?.(e,t)},[m]),P=(0,Q.useCallback)((e,t,n)=>{h?.(e,t,n)},[h]),ae=(0,Q.useCallback)(e=>{w?.(e)},[w]),F=(0,Q.useMemo)(()=>k.reduce((e,t)=>t.role===`system`?e+1:e,0),[k]),I=(0,Q.useMemo)(()=>k.reduce((e,t,n)=>(t.role===`user`&&e.push(n),e),[]),[k]),L=(0,Q.useCallback)(()=>{if(!S||!C)return null;for(let e of k){if(C(e.id))continue;let t=Zt(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=Zt(t.content||``);if(n)return{id:e.id,jsonlPath:n}}}}return null},[k,S,C])(),oe=!!L,[R,z]=(0,Q.useState)(!1),se=(0,Q.useCallback)(async()=>{if(!L||!S||R)return;let e=A;N.current=e?e.scrollHeight-e.scrollTop:null,z(!0);try{await S(L.id,L.jsonlPath)}finally{z(!1)}},[L,S,R,A]);return(0,Q.useEffect)(()=>{let e=A;if(!e||!oe)return;let t=()=>{e.scrollTop<200&&!R&&se()};return e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[A,oe,R,se]),t&&(!n||e.length===0)?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,$.jsx)(i,{className:`size-10 text-text-subtle animate-pulse`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!o?(0,$.jsx)($t,{projectName:p||``,onSelectSession:c||(()=>{})}):(0,$.jsxs)(`div`,{className:`relative flex-1 overflow-hidden flex flex-col min-h-0`,children:[(0,$.jsx)(Jt,{projectName:p,sessionId:_,messages:e}),F>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 (`,F,`)`]})}),R&&(0,$.jsxs)(`div`,{className:`absolute top-2 left-0 right-0 z-10 flex items-center justify-center gap-1.5 text-xs text-text-secondary pointer-events-none`,children:[(0,$.jsx)(Z,{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:D,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=pn(k[n]);t&&e.unshift(t)}l=e.join(`
3
3
 
4
4
  `)}return(0,$.jsx)(`div`,{"data-msg-index":t,className:`px-4 pt-4 select-none`,children:(0,$.jsx)(Qt,{fallbackContent:e.content,children:(0,$.jsx)(mn,{message:e,isStreaming:o&&e.id.startsWith(`streaming-`),isLastAssistantInTurn:c,turnCopyText:l,projectName:p,onFork:e.role===`user`&&m?ie:void 0,onEdit:e.role===`user`&&h?P:void 0,isEditing:a,onDismiss:e.role===`system`&&w?ae: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)(Kn,{approval:r,onRespond:a}):(0,$.jsx)(Gn,{approval:r,onRespond:a})),o&&(0,$.jsx)(Vn,{lastMessage:e[e.length-1],phase:s,elapsed:l,statusMessage:d===`compacting`?`Compacting messages...`:u})]})]})}),(0,$.jsx)(fn,{scrollElement:A,userIndices:I,scrollToBottom:O})]})}function fn({scrollElement:e,userIndices:t,scrollToBottom:n}){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!0),s=(e,t)=>t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop,c=(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=c(t).some(n=>s(t,n)<e-4);i(e=>e===n?e:n);let r=t.scrollHeight-t.scrollTop-t.clientHeight<8;o(e=>e===r?e:r)},a=()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(r)};r(),t.addEventListener(`scroll`,a,{passive:!0});let l=new ResizeObserver(a);return l.observe(t),()=>{n&&cancelAnimationFrame(n),t.removeEventListener(`scroll`,a),l.disconnect()}},[e,c]);let u=(0,Q.useCallback)(()=>{let t=e;if(!t)return;let n=t.scrollTop,r;for(let e of c(t)){let i=s(t,e);if(i<n-4)r=i;else break}r!=null&&t.scrollTo({top:r,behavior:`auto`})},[e,c]),d=(0,Q.useCallback)(()=>{let t=e;if(!t)return;let r=t.scrollTop,i=c(t).map(e=>s(t,e)).find(e=>e>r+4);i==null?n({animation:`instant`}):t.scrollTo({top:i,behavior:`auto`})},[e,c,n]),f=`size-8 flex items-center justify-center rounded-full bg-surface-elevated/60 border border-border/60 text-text-secondary shadow-md backdrop-blur-sm transition-all hover:bg-surface-elevated hover:text-foreground disabled:opacity-30 disabled:cursor-default disabled:hover:bg-surface-elevated/60 disabled:hover:text-text-secondary`;return(0,$.jsxs)(`div`,{className:`absolute bottom-4 right-4 z-10 flex flex-col gap-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:u,disabled:!r,"aria-label":`Jump to previous message`,className:f,children:(0,$.jsx)(Ke,{className:`size-4`})}),(0,$.jsx)(`button`,{type:`button`,onClick:d,disabled:a,"aria-label":`Jump to next message`,className:f,children:(0,$.jsx)(l,{className:`size-4`})})]})}function pn(e){return e.events?.length?e.events.filter(e=>e.type===`text`).map(e=>e.content).join(``):e.content}var mn=(0,Q.memo)(function({message:e,isStreaming:t,isLastAssistantInTurn:n,turnCopyText:r,projectName:i,onFork:a,onEdit:o,isEditing:s,onDismiss:c,prevMsgId:l,sessionId:u,providerId:d,versionGroup:p,onNavigateVersion:m,versionNavDisabled:h,bashPartialOutput:g}){if(e.role===`user`){let t=a?()=>a(e.content,l):void 0,n=o?()=>o(e.content,l,e.id):void 0;return(0,$.jsx)(En,{content:e.content,messageId:e.id,timestamp:e.timestamp,projectName:i,onFork:t,onEdit:n,isEditing:s,sessionId:u,providerId:d,versionGroup:p,onNavigateVersion:m,versionNavDisabled:h})}return e.role===`system`?(0,$.jsxs)(`div`,{className:`group flex items-center gap-2 rounded-lg bg-error/10 border border-error/20 px-3 py-2 text-sm text-error`,children:[(0,$.jsx)(Xe,{className:`size-4 shrink-0`}),(0,$.jsx)(`p`,{className:`flex-1`,children:e.content}),c&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>c(e.id),"aria-label":`Dismiss`,title:`Dismiss`,className:`shrink-0 rounded p-1 text-error/70 hover:text-error hover:bg-error/15 md:opacity-0 md:group-hover:opacity-100`,children:(0,$.jsx)(f,{className:`size-4`})})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.events&&e.events.length>0?(0,$.jsx)(Rn,{events:e.events,isStreaming:t,projectName:i,bashPartialOutput:g}):e.content&&(0,$.jsx)(`div`,{className:`text-sm text-text-primary select-text`,children:(0,$.jsx)(Wn,{content:e.content,projectName:i})}),!t&&n&&(0,$.jsx)(rn,{timestamp:e.timestamp,content:r??pn(e),accountLabel:e.accountLabel,className:`-mt-1.5`})]})}),hn=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]),gn={"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 _n(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:gn[e]??e.replace(/^antml:/,``).replace(/-/g,` `),content:r[2].trim()})}return{cleanText:e.replace(n,``).trim(),tags:t}}function vn(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 yn(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 bn(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 xn(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(`
5
5
  `).map(e=>e.trim()).filter(Boolean),text:e.slice(n[0].length)}:{files:[],text:e}}function Sn(e,t){let n=F(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function Cn(e){let t=e.lastIndexOf(`.`);return t===-1?!1:hn.has(e.slice(t).toLowerCase())}var wn=new Set([`task-notification`,`environment_details`,`local-command-caveat`]);function Tn(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 En({content:e,messageId:t,timestamp:n,projectName:r,onFork:a,onEdit:o,isEditing:c,sessionId:u,providerId:d,versionGroup:f,onNavigateVersion:p,versionNavDisabled:m}){let{files:h,text:g,tags:_,command:v,terminalBlocks:y,idePath:b,agent:x}=(0,Q.useMemo)(()=>{let{idePath:t,cleanText:n}=bn(e),{blocks:r,remainingText:i}=Tn(n),a=xn(i),{cleanText:o,tags:s}=_n(a.text.replace(/<local-command-(?:stdout|stderr)>([\s\S]*?)<\/local-command-(?:stdout|stderr)>/g,`$1`)),{command:c,cleanText:l}=vn(o),{agent:u,cleanText:d}=yn(l),f=c?.args?d?`${c.args}\n\n${d}`:c.args:d;return{files:a.files,text:f,tags:s,command:c,terminalBlocks:r,idePath:t,agent:u}},[e]),S=_.some(e=>wn.has(e.name)),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(!1),D=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let e=D.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:P(`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:P(`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)(On,{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)(vt,{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)(Mn,{path:b,projectName:r})]}),h.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:h.map((e,t)=>Cn(e)?(0,$.jsx)(Ln,{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)(Be,{className:`size-3 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-32`,children:F(e)})]},t))}),y.length>0&&(0,$.jsx)(`div`,{className:`space-y-1.5`,children:y.map((e,t)=>(0,$.jsx)(Dn,{content:e},t))}),g&&(0,$.jsx)(`div`,{ref:D,className:P(`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)(Pn,{text:g,projectName:r}):(0,$.jsx)(Nn,{text:g})}),(T||C)&&(0,$.jsx)(`button`,{onClick:()=>w(!C),className:P(`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)(Ke,{className:`size-3`}),`Show less`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(l,{className:`size-3`}),`Show more`]})}),!S&&p&&(0,$.jsx)(an,{group:f,onNavigate:p,disabled:m})]}),!S&&(0,$.jsxs)(rn,{timestamp:n,content:e,children:[o&&(0,$.jsx)(tn,{icon:(0,$.jsx)(s,{className:`size-3.5`}),label:`Edit`,title:`Edit this message (continue in the same tab)`,onClick:o}),a&&(0,$.jsx)(tn,{icon:(0,$.jsx)(me,{className:`size-3.5`}),label:`Fork`,title:`Retry from this message (fork into a new tab)`,onClick:a})]})]})}function Dn({content:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),className:P(`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)(ye,{className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{children:`Terminal output`}),(0,$.jsx)(l,{className:P(`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 On({tags:e}){return(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,$.jsx)(kn,{tag:e},t))})}function kn({tag:e}){let[t,n]=(0,Q.useState)(!1);return e.name===`task-notification`?(0,$.jsx)(jn,{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)(De,{className:`size-2.5`}),(0,$.jsx)(`span`,{children:e.label}),(0,$.jsx)(d,{className:P(`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 An(e,t){return e.match(RegExp(`<${t}>([\\s\\S]*?)</${t}>`))?.[1]?.trim()||void 0}function jn({content:e}){let[t,n]=(0,Q.useState)(!1),r=An(e,`status`),i=An(e,`summary`),a=An(e,`output-file`),o=An(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)($e,{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:P(`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)(Mn,{path:a}),o&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-subtle/80 max-h-60 overflow-y-auto leading-relaxed`,children:(0,$.jsx)(Wn,{content:o})})]})]})}function Mn({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=F(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)(Be,{className:`size-2.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-60`,children:F(e)}),(0,$.jsx)(He,{className:`size-2 shrink-0 opacity-50`})]})}function Nn({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 Pn({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)(Mn,{path:e.value,projectName:t},n):(0,$.jsx)(`span`,{children:e.value},n))})}var Fn=new Map;function In(e){let[t,n]=(0,Q.useState)(()=>Fn.get(e)?.url??null),[r,i]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{let t=Fn.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);Fn.set(e,{url:i}),n(i)}).catch(()=>{r||i(!0)}),()=>{r=!0}},[e]),{blobUrl:t,error:r}}function Ln({filePath:e,projectName:t}){let{blobUrl:n,error:r}=In(Sn(e,t)),i=nt(e=>e.open),a=F(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)(Oe,{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 Rn({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)(zn,{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)(Bn,{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 zn({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)(Z,{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 Bn({content:e,animate:t,projectName:n}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Wn,{content:e,projectName:n,isStreaming:t}),t&&(0,$.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function Vn({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)(Z,{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 Hn=/<teammate-message[^>]*>[\s\S]*?<\/teammate-message>/g;function Un(e){return e.replace(Hn,``).replace(/\n{3,}/g,`
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/markdown-renderer-CvQmV_TU.js","assets/vendor-mermaid-CYOBtZtD.js","assets/rolldown-runtime-FhOqtrmT.js","assets/vendor-ui-DMRGWRuc.js","assets/vendor-markdown-CKTlmXbz.js","assets/markdown-renderer-BGumVkCU.js","assets/index-D6qn4rtk.js","assets/dialog-HHdNInEH.js","assets/utils-E0yyGxXt.js","assets/createLucideIcon-ConhwJnb.js","assets/x-BsFLg-T8.js","assets/eye-off-Rq1n2-oe.js","assets/bot-E9mcVZnr.js","assets/mobile-bottom-sheet-BwPBKZON.js","assets/chevron-right-DeUue2aK.js","assets/use-is-mobile-CE6AamG6.js","assets/sparkles-B3DmG8PJ.js","assets/database-COYAMZaw.js","assets/plus-DcuJuDC3.js","assets/api-client-DhXpjLdi.js","assets/react-8hrD3-kv.js","assets/api-settings-BUYvGBdi.js","assets/project-store-C1jInVih.js","assets/panel-store-DsDZX8Mi.js","assets/settings-store-C7VeYnhf.js","assets/tab-store-ByORqglW.js","assets/apply-theme-BSJDABU3.js","assets/resolve-theme-B9Mgd5GG.js","assets/index-DjkJR3PP.css","assets/csv-preview-CrGymnn9.js","assets/lib-CvYn0SaB.js","assets/csv-parser-BOlh-1bz.js","assets/image-preview-C2JNJTTR.js","assets/file-exclamation-point-DBEC-Kst.js","assets/use-blob-url-BMZ0zo_4.js","assets/pdf-preview-DjWTE3jF.js","assets/video-preview-BL-sWnxi.js","assets/audio-preview-C8ePPqYM.js","assets/docx-preview-BULrDLso.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-BmofPEFh.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-C7VeYnhf.js";import{t as x}from"./utils-E0yyGxXt.js";import{t as se}from"./panel-store-DsDZX8Mi.js";import{i as S}from"./project-store-C1jInVih.js";import{t as ce}from"./tab-store-ByORqglW.js";import{$ as le,A as ue,Ht as de,J as fe,Ot as C,Q as w,U as pe,Vt as me,X as T,Y as E,Z as D,Zt as O,an as k,cn as he,dn as A,en as ge,et as j,in as M,j as _e,jt as ve,nn as ye,nt as be,o as xe,on as N,pt as P,rn as F,sn as I,tt as L}from"./index-D6qn4rtk.js";import"./data-grid-types-BuMHLKXV.js";import{t as Se}from"./use-monaco-theme-D6Z2faTR.js";var Ce=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`}]]),R=e(t(),1),z=n();function we(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 Te(e){return(await y.get(`/api/fs/browse?path=${encodeURIComponent(e)}`)).entries}function B({filePath:e,projectName:t,tabId:n,className:r}){let{updateTab:a,openTab:o}=ce(fe(e=>({updateTab:e.updateTab,openTab:e.openTab}))),s=(0,R.useRef)(null),c=(0,R.useMemo)(()=>we(e),[e]);(0,R.useEffect)(()=>{s.current&&(s.current.scrollLeft=s.current.scrollWidth)},[c]);let l=(0,R.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,z.jsx)(`div`,{ref:s,className:r,children:c.map((e,t)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,z.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,z.jsx)(Ee,{segment:e,isLast:t===c.length-1,onFileClick:l})]},e.absPath))})}function Ee({segment:e,isLast:t,onFileClick:n}){let[r,i]=(0,R.useState)(null),[a,o]=(0,R.useState)(null);function s(t){t&&r===null&&Te(e.parentDir).then(i).catch(e=>{o(e.message||`Failed to browse`),i([])})}return(0,z.jsxs)(E,{onOpenChange:s,children:[(0,z.jsx)(L,{asChild:!0,children:(0,z.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,z.jsx)(T,{align:`start`,className:`max-h-[300px] overflow-y-auto p-1`,children:r===null?(0,z.jsx)(D,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a?(0,z.jsx)(D,{disabled:!0,className:`text-xs text-destructive`,children:a}):r.length===0?(0,z.jsx)(D,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):r.map(t=>(0,z.jsx)(V,{entry:t,activePath:e.absPath,onFileClick:n},t.path))})]})}function V({entry:e,activePath:t,onFileClick:n}){let r=H(e.name,e.type===`directory`),i=e.path===t,[a,o]=(0,R.useState)(null);if(e.type===`directory`){function s(t){t&&a===null&&Te(e.path).then(o).catch(()=>o([]))}return(0,z.jsxs)(w,{onOpenChange:s,children:[(0,z.jsxs)(j,{className:`text-xs gap-1.5 ${i?`bg-muted`:``}`,children:[(0,z.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,z.jsx)(le,{className:`max-h-[300px] overflow-y-auto p-1`,children:a===null?(0,z.jsx)(D,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a.length===0?(0,z.jsx)(D,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):a.map(e=>(0,z.jsx)(V,{entry:e,activePath:t,onFileClick:n},e.path))})]})}return(0,z.jsxs)(D,{className:`text-xs gap-1.5 cursor-pointer ${i?`bg-muted`:``}`,onClick:t=>n(e.path,t),children:[(0,z.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]})}var De={ts:N,tsx:N,js:N,jsx:N,py:N,rs:N,go:N,html:N,css:N,scss:N,json:I,md:k,txt:k,yaml:M,yml:M};function H(e,t){return t?ye:De[e.split(`.`).pop()?.toLowerCase()??``]??F}function U(e,t){let n=[],r=e,i=``;for(let e=0;e<t.length;e++){let a=t[e],o=t.slice(0,e+1).join(`/`),s=r.find(e=>e.name===a);if(n.push({name:a,fullPath:o,node:s??null,siblings:r,parentPath:i}),s?.children)i=s.path,r=s.children;else{for(let r=e+1;r<t.length;r++)n.push({name:t[r],fullPath:t.slice(0,r+1).join(`/`),node:null,siblings:[],parentPath:t.slice(0,r).join(`/`)});break}}return n}function Oe(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function ke({filePath:e,projectName:t,tabId:n,className:r}){let a=P(e=>e.tree),{updateTab:o,openTab:s}=ce(fe(e=>({updateTab:e.updateTab,openTab:e.openTab}))),c=S(e=>e.projects.find(e=>e.name===t)?.path??``),l=(0,R.useRef)(null),{prefixParts:u,relativePath:d,isExternal:f}=(0,R.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,R.useMemo)(()=>U(a,d.split(`/`).filter(Boolean)),[a,d]);(0,R.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,z.jsx)(B,{filePath:e,projectName:t,tabId:n,className:r}):(0,z.jsxs)(`div`,{ref:l,className:r,children:[u.map((e,t)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,z.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,z.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e})]},`prefix-${t}`)),p.map((e,n)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[(n>0||u.length>0)&&(0,z.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,z.jsx)(W,{segment:e,isLast:n===p.length-1,projectName:t,onFileClick:m})]},e.fullPath))]})}function W({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=P(e=>e.loadChildren),a=P(e=>e.loadedPaths),o=(0,R.useMemo)(()=>Oe(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,z.jsxs)(E,{onOpenChange:c,children:[(0,z.jsx)(L,{asChild:!0,children:(0,z.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,z.jsx)(T,{align:`start`,className:`max-h-[300px] p-1`,children:o.length===0?(0,z.jsx)(D,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):o.map(t=>(0,z.jsx)(G,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function G({node:e,projectName:t,activePath:n,onFileClick:r}){let i=H(e.name,e.type===`directory`),a=e.path===n,o=P(e=>e.loadChildren),s=P(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,z.jsxs)(w,{onOpenChange:u,children:[(0,z.jsxs)(j,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,z.jsx)(le,{className:`max-h-[300px] overflow-y-auto p-1`,children:c.length===0?(0,z.jsx)(D,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):Oe(c).map(e=>(0,z.jsx)(G,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]})}return(0,z.jsxs)(D,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{r(e.path,t)},children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]})}function K({active:e,onClick:t,icon:n,label:r}){return(0,z.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,z.jsx)(n,{className:`size-3`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function Ae({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,z.jsxs)(`div`,{className:f,children:[(e===`md`||e===`mdx`)&&n&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(K,{active:t===`edit`,onClick:()=>n(`edit`),icon:d,label:`Edit`}),(0,z.jsx)(K,{active:t===`preview`,onClick:()=>n(`preview`),icon:p,label:`Preview`})]}),e===`csv`&&i&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(K,{active:r===`table`,onClick:()=>i(`table`),icon:_,label:`Table`}),(0,z.jsx)(K,{active:r===`raw`,onClick:()=>i(`raw`),icon:d,label:`Raw`})]}),(0,z.jsx)(K,{active:a,onClick:o,icon:ve,label:`Wrap`}),s&&(0,z.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,z.jsx)(me,{className:`size-3 ${c?`animate-spin`:``}`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:`Refresh`})]}),l&&u&&(0,z.jsx)(K,{active:!1,onClick:()=>be(u,l),icon:m,label:`Download`})]})}var je=[{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 Me({value:e,onChange:t}){return(0,z.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1 px-2 border-l border-border`,children:[(0,z.jsx)(N,{className:`size-3 text-muted-foreground`}),(0,z.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:je.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.label},e.id))})]})}function Ne({open:e,defaultName:t,content:n,onSave:r,onCancel:i}){let[d,f]=(0,R.useState)(t),[p,m]=(0,R.useState)(!1),[ee,h]=(0,R.useState)(``),te=S(e=>e.activeProject),ne=(0,R.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,R.useCallback)(e=>{let t=e.includes(`\\`)?`\\`:`/`;r(e.endsWith(t)?`${e}${d.trim()}`:`${e}${t}${d.trim()}`,n)},[d,n,r]);return p?(0,z.jsx)(_e,{open:!0,mode:`folder`,root:te?.path,title:`Save "${d.trim()}" to...`,onSelect:g,onCancel:()=>m(!1)}):(0,z.jsx)(u,{open:e,onOpenChange:e=>{e||i()},children:(0,z.jsxs)(c,{className:`sm:max-w-md`,children:[(0,z.jsx)(a,{children:(0,z.jsx)(l,{children:`Save As`})}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,z.jsx)(`label`,{className:`text-sm text-muted-foreground`,children:`Filename`}),(0,z.jsx)(pe,{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,z.jsx)(`p`,{className:`text-xs text-destructive`,children:ee})]}),(0,z.jsxs)(s,{children:[(0,z.jsx)(o,{variant:`outline`,onClick:i,children:`Cancel`}),(0,z.jsx)(o,{onClick:ne,children:`Choose Folder...`})]})]})})}var q=typeof window<`u`&&window.isSecureContext,Pe=[`(`,`)`,`{`,`}`,`[`,`]`,`<`,`>`,`;`,`:`,`=`,`"`,`'`,"`",`/`,`\\`,`_`,`#`],Fe=`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`,Ie=`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`,Le=`w-px h-5 bg-border mx-0.5 shrink-0`;function Re({editorRef:e,readOnly:t}){let n=(0,R.useCallback)(()=>e.current,[e]),r=(0,R.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,R.useState)(!1),o=(0,R.useRef)(null),s=(0,R.useCallback)(async()=>{try{let e=await navigator.clipboard.readText();e&&r(e)}catch{}},[r]),c=(0,R.useCallback)(()=>{a(!0),requestAnimationFrame(()=>o.current?.focus())},[]),l=(0,R.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData(`text/plain`);t&&(a(!1),r(t))},[r]),u=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`undo`,null))},[n]),d=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`redo`,null))},[n]),f=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`tab`,null))},[n]);return t?null:(0,z.jsxs)(`div`,{className:`shrink-0 border-t border-border bg-surface`,children:[!q&&i&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 border-b border-border bg-muted/50`,children:[(0,z.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,z.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`p-1.5 rounded text-muted-foreground active:bg-muted transition-colors`,children:(0,z.jsx)(v,{size:14})})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1.5 overflow-x-auto`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:q?s:c,className:Fe,title:`Paste`,children:(0,z.jsx)(A,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:u,className:Fe,title:`Undo`,children:(0,z.jsx)(C,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:d,className:Fe,title:`Redo`,children:(0,z.jsx)(Ce,{size:14})}),(0,z.jsx)(`div`,{className:Le}),(0,z.jsx)(`button`,{type:`button`,onClick:f,className:Ie,children:`Tab`}),(0,z.jsx)(`div`,{className:Le}),Pe.map(e=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>r(e),className:Ie,children:e},e))]})]})}var J=(0,R.lazy)(()=>b(()=>import(`./markdown-renderer-CvQmV_TU.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,R.lazy)(()=>b(()=>import(`./csv-preview-CrGymnn9.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,R.lazy)(()=>b(()=>import(`./image-preview-C2JNJTTR.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,R.lazy)(()=>b(()=>import(`./pdf-preview-DjWTE3jF.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,R.lazy)(()=>b(()=>import(`./video-preview-BL-sWnxi.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,R.lazy)(()=>b(()=>import(`./audio-preview-C8ePPqYM.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,R.lazy)(()=>b(()=>import(`./docx-preview-BULrDLso.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,R.memo)(function({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,i=e?.inlineContent,a=e?.inlineLanguage,[o,s]=(0,R.useState)(i??null),[c,l]=(0,R.useState)(`utf-8`),[u,d]=(0,R.useState)(!0),[p,m]=(0,R.useState)(null),[g,_]=(0,R.useState)(!1),v=(0,R.useRef)(null),b=(0,R.useRef)(``),S=(0,R.useRef)(null),{tabs:le,updateTab:C}=ce(fe(e=>({tabs:e.tabs,updateTab:e.updateTab}))),{wordWrap:w,toggleWordWrap:pe}=oe(fe(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),me=Se(),T=e?.isUntitled===!0,E=e?.unsavedContent,[D,k]=(0,R.useState)(!1),he=le.find(e=>e.id===t),A=n?Ye(n):``,ge=Ge.has(A),j=A===`pdf`,M=A===`docx`,_e=Ke.has(A),ve=qe.has(A),ye=Je.has(A),be=A===`md`||A===`mdx`,N=A===`csv`,P=e?.language,F=a??P??Xe(n??``),I=F===`sql`,[L,Ce]=(0,R.useState)(`preview`),[we,Te]=(0,R.useState)(`table`),{connections:B,cachedTables:Ee,refreshTables:V,updateConnection:De}=ue(),H=n?`ppm:sql-conn:${n}`:t?`ppm:sql-conn:tab:${t}`:null,[U,Oe]=(0,R.useState)(()=>{if(!H)return null;let e=localStorage.getItem(H);return e?Number(e):null}),W=(0,R.useRef)(null),G=(0,R.useRef)(null),K=(0,R.useMemo)(()=>B.find(e=>e.id===U)??null,[B,U]),je=i!=null&&(a===`json`||a===`xml`),[q,Pe]=(0,R.useState)(!1),Fe=(0,R.useCallback)(()=>{if(i)if(q)s(i),Pe(!1);else{let e=i.trimStart();if(a===`json`)try{s(JSON.stringify(JSON.parse(e),null,2)),Pe(!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-w7cIJc1V.js","assets/vendor-mermaid-CYOBtZtD.js","assets/rolldown-runtime-FhOqtrmT.js","assets/vendor-ui-DMRGWRuc.js","assets/vendor-markdown-CKTlmXbz.js","assets/markdown-renderer-CaVoLF6f.js","assets/index-DMEso_fH.js","assets/dialog-HHdNInEH.js","assets/utils-E0yyGxXt.js","assets/createLucideIcon-ConhwJnb.js","assets/x-BsFLg-T8.js","assets/eye-off-Rq1n2-oe.js","assets/bot-E9mcVZnr.js","assets/mobile-bottom-sheet-BwPBKZON.js","assets/chevron-right-DeUue2aK.js","assets/use-is-mobile-CE6AamG6.js","assets/sparkles-B3DmG8PJ.js","assets/database-COYAMZaw.js","assets/plus-DcuJuDC3.js","assets/api-client-DhXpjLdi.js","assets/react-8hrD3-kv.js","assets/api-settings-BUYvGBdi.js","assets/project-store-C1jInVih.js","assets/panel-store-DsDZX8Mi.js","assets/settings-store-UwT_fNhg.js","assets/tab-store-ByORqglW.js","assets/apply-theme-BSJDABU3.js","assets/resolve-theme-B9Mgd5GG.js","assets/index-DjkJR3PP.css","assets/csv-preview-CkZtgJJd.js","assets/lib-CvYn0SaB.js","assets/csv-parser-BOlh-1bz.js","assets/image-preview-D35tUSfv.js","assets/file-exclamation-point-DBEC-Kst.js","assets/use-blob-url-BMZ0zo_4.js","assets/pdf-preview-URqY4tEa.js","assets/video-preview-U2aMrCxv.js","assets/audio-preview-IJyTkZhv.js","assets/docx-preview-uAcT8IrY.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-BTbN5x8y.js";import{t as re}from"./shield-check-C3qYSU8a.js";import{t as ie}from"./shield-off-D5tU7gQT.js";import{t as _}from"./table-Di8pv2Y_.js";import{t as v}from"./x-BsFLg-T8.js";import{r as ae,t as y}from"./api-client-DhXpjLdi.js";import{q as b}from"./vendor-mermaid-CYOBtZtD.js";import{t as oe}from"./settings-store-UwT_fNhg.js";import{t as x}from"./utils-E0yyGxXt.js";import{t as se}from"./panel-store-DsDZX8Mi.js";import{i as S}from"./project-store-C1jInVih.js";import{t as ce}from"./tab-store-ByORqglW.js";import{$ as le,A as ue,Ht as de,J as fe,Ot as C,Q as w,U as pe,Vt as me,X as T,Y as E,Z as D,Zt as O,an as k,cn as he,dn as A,en as ge,et as j,in as M,j as _e,jt as ve,nn as ye,nt as be,o as xe,on as N,pt as P,rn as F,sn as I,tt as L}from"./index-DMEso_fH.js";import"./data-grid-types-BuMHLKXV.js";import{t as Se}from"./use-monaco-theme-XO5ZyYBW.js";var Ce=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`}]]),R=e(t(),1),z=n();function we(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 Te(e){return(await y.get(`/api/fs/browse?path=${encodeURIComponent(e)}`)).entries}function B({filePath:e,projectName:t,tabId:n,className:r}){let{updateTab:a,openTab:o}=ce(fe(e=>({updateTab:e.updateTab,openTab:e.openTab}))),s=(0,R.useRef)(null),c=(0,R.useMemo)(()=>we(e),[e]);(0,R.useEffect)(()=>{s.current&&(s.current.scrollLeft=s.current.scrollWidth)},[c]);let l=(0,R.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,z.jsx)(`div`,{ref:s,className:r,children:c.map((e,t)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,z.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,z.jsx)(Ee,{segment:e,isLast:t===c.length-1,onFileClick:l})]},e.absPath))})}function Ee({segment:e,isLast:t,onFileClick:n}){let[r,i]=(0,R.useState)(null),[a,o]=(0,R.useState)(null);function s(t){t&&r===null&&Te(e.parentDir).then(i).catch(e=>{o(e.message||`Failed to browse`),i([])})}return(0,z.jsxs)(E,{onOpenChange:s,children:[(0,z.jsx)(L,{asChild:!0,children:(0,z.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,z.jsx)(T,{align:`start`,className:`max-h-[300px] overflow-y-auto p-1`,children:r===null?(0,z.jsx)(D,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a?(0,z.jsx)(D,{disabled:!0,className:`text-xs text-destructive`,children:a}):r.length===0?(0,z.jsx)(D,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):r.map(t=>(0,z.jsx)(V,{entry:t,activePath:e.absPath,onFileClick:n},t.path))})]})}function V({entry:e,activePath:t,onFileClick:n}){let r=H(e.name,e.type===`directory`),i=e.path===t,[a,o]=(0,R.useState)(null);if(e.type===`directory`){function s(t){t&&a===null&&Te(e.path).then(o).catch(()=>o([]))}return(0,z.jsxs)(w,{onOpenChange:s,children:[(0,z.jsxs)(j,{className:`text-xs gap-1.5 ${i?`bg-muted`:``}`,children:[(0,z.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,z.jsx)(le,{className:`max-h-[300px] overflow-y-auto p-1`,children:a===null?(0,z.jsx)(D,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):a.length===0?(0,z.jsx)(D,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Empty`}):a.map(e=>(0,z.jsx)(V,{entry:e,activePath:t,onFileClick:n},e.path))})]})}return(0,z.jsxs)(D,{className:`text-xs gap-1.5 cursor-pointer ${i?`bg-muted`:``}`,onClick:t=>n(e.path,t),children:[(0,z.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]})}var De={ts:N,tsx:N,js:N,jsx:N,py:N,rs:N,go:N,html:N,css:N,scss:N,json:I,md:k,txt:k,yaml:M,yml:M};function H(e,t){return t?ye:De[e.split(`.`).pop()?.toLowerCase()??``]??F}function U(e,t){let n=[],r=e,i=``;for(let e=0;e<t.length;e++){let a=t[e],o=t.slice(0,e+1).join(`/`),s=r.find(e=>e.name===a);if(n.push({name:a,fullPath:o,node:s??null,siblings:r,parentPath:i}),s?.children)i=s.path,r=s.children;else{for(let r=e+1;r<t.length;r++)n.push({name:t[r],fullPath:t.slice(0,r+1).join(`/`),node:null,siblings:[],parentPath:t.slice(0,r).join(`/`)});break}}return n}function Oe(e){return[...e].sort((e,t)=>e.type===t.type?e.name.localeCompare(t.name):e.type===`directory`?-1:1)}function ke({filePath:e,projectName:t,tabId:n,className:r}){let a=P(e=>e.tree),{updateTab:o,openTab:s}=ce(fe(e=>({updateTab:e.updateTab,openTab:e.openTab}))),c=S(e=>e.projects.find(e=>e.name===t)?.path??``),l=(0,R.useRef)(null),{prefixParts:u,relativePath:d,isExternal:f}=(0,R.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,R.useMemo)(()=>U(a,d.split(`/`).filter(Boolean)),[a,d]);(0,R.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,z.jsx)(B,{filePath:e,projectName:t,tabId:n,className:r}):(0,z.jsxs)(`div`,{ref:l,className:r,children:[u.map((e,t)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[t>0&&(0,z.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,z.jsx)(`span`,{className:`text-xs text-muted-foreground px-1 py-0.5`,children:e})]},`prefix-${t}`)),p.map((e,n)=>(0,z.jsxs)(`div`,{className:`flex items-center shrink-0`,children:[(n>0||u.length>0)&&(0,z.jsx)(i,{className:`size-3 text-muted-foreground shrink-0 mx-0.5`}),(0,z.jsx)(W,{segment:e,isLast:n===p.length-1,projectName:t,onFileClick:m})]},e.fullPath))]})}function W({segment:e,isLast:t,projectName:n,onFileClick:r}){let i=P(e=>e.loadChildren),a=P(e=>e.loadedPaths),o=(0,R.useMemo)(()=>Oe(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,z.jsxs)(E,{onOpenChange:c,children:[(0,z.jsx)(L,{asChild:!0,children:(0,z.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,z.jsx)(T,{align:`start`,className:`max-h-[300px] p-1`,children:o.length===0?(0,z.jsx)(D,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):o.map(t=>(0,z.jsx)(G,{node:t,projectName:n,activePath:e.fullPath,onFileClick:r},t.path))})]})}function G({node:e,projectName:t,activePath:n,onFileClick:r}){let i=H(e.name,e.type===`directory`),a=e.path===n,o=P(e=>e.loadChildren),s=P(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,z.jsxs)(w,{onOpenChange:u,children:[(0,z.jsxs)(j,{className:`text-xs gap-1.5 ${a?`bg-muted`:``}`,children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]}),(0,z.jsx)(le,{className:`max-h-[300px] overflow-y-auto p-1`,children:c.length===0?(0,z.jsx)(D,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading…`}):Oe(c).map(e=>(0,z.jsx)(G,{node:e,projectName:t,activePath:n,onFileClick:r},e.path))})]})}return(0,z.jsxs)(D,{className:`text-xs gap-1.5 cursor-pointer ${a?`bg-muted`:``}`,onSelect:e=>{},onClick:t=>{r(e.path,t)},children:[(0,z.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]})}function K({active:e,onClick:t,icon:n,label:r}){return(0,z.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,z.jsx)(n,{className:`size-3`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function Ae({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,z.jsxs)(`div`,{className:f,children:[(e===`md`||e===`mdx`)&&n&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(K,{active:t===`edit`,onClick:()=>n(`edit`),icon:d,label:`Edit`}),(0,z.jsx)(K,{active:t===`preview`,onClick:()=>n(`preview`),icon:p,label:`Preview`})]}),e===`csv`&&i&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(K,{active:r===`table`,onClick:()=>i(`table`),icon:_,label:`Table`}),(0,z.jsx)(K,{active:r===`raw`,onClick:()=>i(`raw`),icon:d,label:`Raw`})]}),(0,z.jsx)(K,{active:a,onClick:o,icon:ve,label:`Wrap`}),s&&(0,z.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,z.jsx)(me,{className:`size-3 ${c?`animate-spin`:``}`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:`Refresh`})]}),l&&u&&(0,z.jsx)(K,{active:!1,onClick:()=>be(u,l),icon:m,label:`Download`})]})}var je=[{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 Me({value:e,onChange:t}){return(0,z.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1 px-2 border-l border-border`,children:[(0,z.jsx)(N,{className:`size-3 text-muted-foreground`}),(0,z.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:je.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.label},e.id))})]})}function Ne({open:e,defaultName:t,content:n,onSave:r,onCancel:i}){let[d,f]=(0,R.useState)(t),[p,m]=(0,R.useState)(!1),[ee,h]=(0,R.useState)(``),te=S(e=>e.activeProject),ne=(0,R.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,R.useCallback)(e=>{let t=e.includes(`\\`)?`\\`:`/`;r(e.endsWith(t)?`${e}${d.trim()}`:`${e}${t}${d.trim()}`,n)},[d,n,r]);return p?(0,z.jsx)(_e,{open:!0,mode:`folder`,root:te?.path,title:`Save "${d.trim()}" to...`,onSelect:g,onCancel:()=>m(!1)}):(0,z.jsx)(u,{open:e,onOpenChange:e=>{e||i()},children:(0,z.jsxs)(c,{className:`sm:max-w-md`,children:[(0,z.jsx)(a,{children:(0,z.jsx)(l,{children:`Save As`})}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,z.jsx)(`label`,{className:`text-sm text-muted-foreground`,children:`Filename`}),(0,z.jsx)(pe,{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,z.jsx)(`p`,{className:`text-xs text-destructive`,children:ee})]}),(0,z.jsxs)(s,{children:[(0,z.jsx)(o,{variant:`outline`,onClick:i,children:`Cancel`}),(0,z.jsx)(o,{onClick:ne,children:`Choose Folder...`})]})]})})}var q=typeof window<`u`&&window.isSecureContext,Pe=[`(`,`)`,`{`,`}`,`[`,`]`,`<`,`>`,`;`,`:`,`=`,`"`,`'`,"`",`/`,`\\`,`_`,`#`],Fe=`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`,Ie=`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`,Le=`w-px h-5 bg-border mx-0.5 shrink-0`;function Re({editorRef:e,readOnly:t}){let n=(0,R.useCallback)(()=>e.current,[e]),r=(0,R.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,R.useState)(!1),o=(0,R.useRef)(null),s=(0,R.useCallback)(async()=>{try{let e=await navigator.clipboard.readText();e&&r(e)}catch{}},[r]),c=(0,R.useCallback)(()=>{a(!0),requestAnimationFrame(()=>o.current?.focus())},[]),l=(0,R.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData(`text/plain`);t&&(a(!1),r(t))},[r]),u=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`undo`,null))},[n]),d=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`redo`,null))},[n]),f=(0,R.useCallback)(()=>{let e=n();e&&(e.focus(),e.trigger(`mobile-toolbar`,`tab`,null))},[n]);return t?null:(0,z.jsxs)(`div`,{className:`shrink-0 border-t border-border bg-surface`,children:[!q&&i&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 border-b border-border bg-muted/50`,children:[(0,z.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,z.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`p-1.5 rounded text-muted-foreground active:bg-muted transition-colors`,children:(0,z.jsx)(v,{size:14})})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1.5 overflow-x-auto`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:q?s:c,className:Fe,title:`Paste`,children:(0,z.jsx)(A,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:u,className:Fe,title:`Undo`,children:(0,z.jsx)(C,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:d,className:Fe,title:`Redo`,children:(0,z.jsx)(Ce,{size:14})}),(0,z.jsx)(`div`,{className:Le}),(0,z.jsx)(`button`,{type:`button`,onClick:f,className:Ie,children:`Tab`}),(0,z.jsx)(`div`,{className:Le}),Pe.map(e=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>r(e),className:Ie,children:e},e))]})]})}var J=(0,R.lazy)(()=>b(()=>import(`./markdown-renderer-w7cIJc1V.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,R.lazy)(()=>b(()=>import(`./csv-preview-CkZtgJJd.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,R.lazy)(()=>b(()=>import(`./image-preview-D35tUSfv.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,R.lazy)(()=>b(()=>import(`./pdf-preview-URqY4tEa.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,R.lazy)(()=>b(()=>import(`./video-preview-U2aMrCxv.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,R.lazy)(()=>b(()=>import(`./audio-preview-IJyTkZhv.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,R.lazy)(()=>b(()=>import(`./docx-preview-uAcT8IrY.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,R.memo)(function({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,i=e?.inlineContent,a=e?.inlineLanguage,[o,s]=(0,R.useState)(i??null),[c,l]=(0,R.useState)(`utf-8`),[u,d]=(0,R.useState)(!0),[p,m]=(0,R.useState)(null),[g,_]=(0,R.useState)(!1),v=(0,R.useRef)(null),b=(0,R.useRef)(``),S=(0,R.useRef)(null),{tabs:le,updateTab:C}=ce(fe(e=>({tabs:e.tabs,updateTab:e.updateTab}))),{wordWrap:w,toggleWordWrap:pe}=oe(fe(e=>({wordWrap:e.wordWrap,toggleWordWrap:e.toggleWordWrap}))),me=Se(),T=e?.isUntitled===!0,E=e?.unsavedContent,[D,k]=(0,R.useState)(!1),he=le.find(e=>e.id===t),A=n?Ye(n):``,ge=Ge.has(A),j=A===`pdf`,M=A===`docx`,_e=Ke.has(A),ve=qe.has(A),ye=Je.has(A),be=A===`md`||A===`mdx`,N=A===`csv`,P=e?.language,F=a??P??Xe(n??``),I=F===`sql`,[L,Ce]=(0,R.useState)(`preview`),[we,Te]=(0,R.useState)(`table`),{connections:B,cachedTables:Ee,refreshTables:V,updateConnection:De}=ue(),H=n?`ppm:sql-conn:${n}`:t?`ppm:sql-conn:tab:${t}`:null,[U,Oe]=(0,R.useState)(()=>{if(!H)return null;let e=localStorage.getItem(H);return e?Number(e):null}),W=(0,R.useRef)(null),G=(0,R.useRef)(null),K=(0,R.useMemo)(()=>B.find(e=>e.id===U)??null,[B,U]),je=i!=null&&(a===`json`||a===`xml`),[q,Pe]=(0,R.useState)(!1),Fe=(0,R.useCallback)(()=>{if(i)if(q)s(i),Pe(!1);else{let e=i.trimStart();if(a===`json`)try{s(JSON.stringify(JSON.parse(e),null,2)),Pe(!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
  `)),Pe(!0)}}},[i,a,q]),Ie=(0,R.useCallback)(e=>{Oe(e),H&&localStorage.setItem(H,String(e)),V(e).catch(()=>{})},[H,V]),Le=(0,R.useCallback)(n=>{t&&C(t,{metadata:{...e,language:n}})},[t,e,C]),J=(0,R.useMemo)(()=>{if(!I||!U)return;let e=(Ee.get(U)??[]).map(e=>({name:e.tableName,schema:e.schemaName}));if(e.length!==0)return{tables:e,getColumns:async(e,t)=>y.get(`/api/db/connections/${U}/schema?table=${encodeURIComponent(e)}${t?`&schema=${encodeURIComponent(t)}`:``}`)}},[I,U,Ee]);(0,R.useEffect)(()=>{if(!(!W.current||!J))return G.current?.dispose(),ne(),G.current=W.current.languages.registerCompletionItemProvider(`sql`,te(W.current,J)),()=>{G.current?.dispose()}},[J]);let Ze=ce(e=>e.openTab),[Y,et]=(0,R.useState)(null),[tt,nt]=(0,R.useState)(null),[rt,it]=(0,R.useState)(!1),[at,ot]=(0,R.useState)(``),st=(0,R.useCallback)(async e=>{if(K){it(!0),nt(null),ot(e);try{et(await y.post(`/api/db/connections/${K.id}/query`,{sql:e}))}catch(e){nt(e.message),et(null)}finally{it(!1)}}},[K]),ct=(0,R.useCallback)(()=>{!K||!at||Ze({type:`database`,title:`${K.name} · Query`,projectId:null,closable:!0,metadata:{connectionId:K.id,connectionName:K.name,dbType:K.type,initialSql:at}})},[K,Ze,at]),lt=(0,R.useCallback)(()=>{if(!S.current||!K)return;let e=S.current,t=e.getSelection();st(t&&!t.isEmpty()?e.getModel()?.getValueInRange(t)??e.getValue():e.getValue())},[K,st]),ut=typeof window<`u`&&`ontouchstart`in window,dt=(0,R.useRef)(null),[ft,pt]=(0,R.useState)(null);(0,R.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,R.useRef)([]),mt=(0,R.useRef)(st);mt.current=st,(0,R.useEffect)(()=>()=>{Z.current.forEach(e=>e.dispose()),Z.current=[]},[]),(0,R.useEffect)(()=>{ye&&t&&C(t,{type:`sqlite`})},[ye,t,C]);let Q=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,R.useEffect)(()=>{if(i!=null){d(!1);return}if(T){s(E??``),b.current=E??``,d(!1),E&&_(!0);return}if(!n||!Q&&!r)return;if(ge||j||M||_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,ge,j,M,Q,T]);let[ht,gt]=(0,R.useState)(!1),_t=(0,R.useCallback)(()=>{if(!n||i!=null||T||!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,T]),vt=(0,R.useRef)(g);vt.current=g,(0,R.useEffect)(()=>{if(!n||!r||i!=null||T)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,T]),(0,R.useEffect)(()=>{if(!he||i!=null)return;let t=T?`Untitled-${e?.untitledNumber??1}`:n?x(n):`Untitled`,r=g?`${t} \u25CF`:t;he.title!==r&&C(he.id,{title:r})},[g]);let yt=(0,R.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),T?v.current=setTimeout(()=>{t&&C(t,{metadata:{...e,unsavedContent:b.current}})},2e3):v.current=setTimeout(()=>yt(b.current),1e3)}let xt=(0,R.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),k(!1)}catch{}},[t]),$=e?.lineNumber,St=e?.endLine,Ct=e?.revealAt,wt=(0,R.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,R.useEffect)(()=>{Ct!=null&&wt()},[Ct,wt]);let Tt=(0,R.useCallback)((e,t)=>{if(S.current=e,W.current=t,$&&$>0&&setTimeout(()=>wt(),100),T&&e.addCommand(t.KeyMod.CtrlCmd|t.KeyCode.KeyS,()=>k(!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&&(G.current?.dispose(),G.current=t.languages.registerCompletionItemProvider(`sql`,te(t,J))),I){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-C7VeYnhf.js";import{J as o,Zt as s,o as c}from"./index-D6qn4rtk.js";import{t as l}from"./use-monaco-theme-D6Z2faTR.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(`
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-UwT_fNhg.js";import{J as o,Zt as s,o as c}from"./index-DMEso_fH.js";import{t as l}from"./use-monaco-theme-XO5ZyYBW.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+`