@hienlh/ppm 0.7.8 → 0.7.10

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 (52) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/CONTRIBUTING.md +46 -0
  3. package/LICENSE +21 -0
  4. package/README.md +34 -1
  5. package/bun.lock +1 -0
  6. package/dist/web/assets/ai-settings-section-BxCMGg-I.js +1 -0
  7. package/dist/web/assets/chat-tab-R_8ZfOG8.js +7 -0
  8. package/dist/web/assets/{code-editor-1FNaZKfA.js → code-editor-BbhIHbts.js} +1 -1
  9. package/dist/web/assets/{database-viewer-Hso-EwQH.js → database-viewer-BJYmlnr2.js} +1 -1
  10. package/dist/web/assets/{diff-viewer-BG2UNjTZ.js → diff-viewer-CS-wesGq.js} +1 -1
  11. package/dist/web/assets/{git-graph-DK_yDfWe.js → git-graph-B9eaNltz.js} +1 -1
  12. package/dist/web/assets/index-qElHXk-7.js +28 -0
  13. package/dist/web/assets/index-sMxUHxFZ.css +2 -0
  14. package/dist/web/assets/input-CVIzrYsH.js +41 -0
  15. package/dist/web/assets/keybindings-store-DrBQMVKg.js +1 -0
  16. package/dist/web/assets/{markdown-renderer-Xe_wjdJH.js → markdown-renderer-DpIu7iOT.js} +1 -1
  17. package/dist/web/assets/{postgres-viewer-CguN1z3q.js → postgres-viewer-B5-tRXE2.js} +1 -1
  18. package/dist/web/assets/settings-tab-3-ewawy0.js +1 -0
  19. package/dist/web/assets/{sqlite-viewer-VrZiiegZ.js → sqlite-viewer-CfIer2x_.js} +1 -1
  20. package/dist/web/assets/{terminal-tab-CabMjIRO.js → terminal-tab-qJxp0iOK.js} +2 -2
  21. package/dist/web/index.html +4 -4
  22. package/dist/web/sw.js +1 -1
  23. package/docs/codebase-summary.md +16 -5
  24. package/docs/system-architecture.md +20 -2
  25. package/package.json +4 -1
  26. package/src/lib/account-crypto.ts +53 -0
  27. package/src/providers/claude-agent-sdk.ts +77 -3
  28. package/src/server/index.ts +8 -0
  29. package/src/server/routes/accounts.ts +165 -0
  30. package/src/server/routes/chat.ts +2 -0
  31. package/src/services/account-selector.service.ts +109 -0
  32. package/src/services/account.service.ts +411 -0
  33. package/src/services/claude-usage.service.ts +186 -124
  34. package/src/services/db.service.ts +117 -3
  35. package/src/types/chat.ts +2 -0
  36. package/src/web/app.tsx +0 -4
  37. package/src/web/components/chat/chat-history-bar.tsx +3 -0
  38. package/src/web/components/chat/usage-badge.tsx +86 -12
  39. package/src/web/components/settings/accounts-settings-section.tsx +358 -0
  40. package/src/web/components/settings/settings-tab.tsx +11 -0
  41. package/src/web/components/ui/badge.tsx +36 -0
  42. package/src/web/components/ui/switch.tsx +27 -0
  43. package/src/web/hooks/use-usage.ts +1 -1
  44. package/src/web/lib/api-settings.ts +65 -0
  45. package/dist/web/assets/ai-settings-section-ByRvOONz.js +0 -1
  46. package/dist/web/assets/chat-tab-DLfy6CBX.js +0 -7
  47. package/dist/web/assets/index-4pPCbWJp.css +0 -2
  48. package/dist/web/assets/index-DaQYRomz.js +0 -29
  49. package/dist/web/assets/input-P_K5CUiy.js +0 -41
  50. package/dist/web/assets/keybindings-store-xe6f5O18.js +0 -1
  51. package/dist/web/assets/settings-tab-CHONXRsW.js +0 -1
  52. package/src/web/hooks/use-health-check.ts +0 -95
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.7.10] - 2026-03-20
4
+
5
+ ### Changed
6
+ - **Usage panel layout**: responsive grid (1–4 columns) replaces collapsible list for account usage cards
7
+ - **Usage data**: removed legacy fallback — each account shows only its own per-account data
8
+
9
+ ### Removed
10
+ - **Health check polling**: removed `useHealthCheck` hook (5s `/api/health` ping + crash toast)
11
+
12
+ ## [0.7.9] - 2026-03-20
13
+
14
+ ### Added
15
+ - **Manual token input**: add Claude accounts via dialog — supports OAuth tokens (`claude setup-token`) and API keys with auto-detection
16
+ - **Per-account usage limits**: Usage Limits panel shows collapsible per-account sections with 5hr/weekly bars
17
+ - **Active account indicator**: chat header badge shows `[account label]`, account cards show "In use" badge and ring highlight
18
+ - **Inline usage bars**: compact 5h/Wk mini-bars on each account card in settings
19
+ - **API endpoints**: `GET /api/accounts/active`, `GET /api/accounts/usage`, `GET /api/accounts/:id/usage`, `POST /api/accounts`
20
+ - **DB migration v6**: `account_id` column on `claude_limit_snapshots` for per-account tracking
21
+
22
+ ### Changed
23
+ - **Usage polling**: rewritten for multi-account with per-token 429 cooldown (respects `retry-after` header)
24
+ - **SDK env vars**: auto-detect token type — OAuth → `CLAUDE_CODE_OAUTH_TOKEN`, API key → `ANTHROPIC_API_KEY`
25
+
3
26
  ## [0.7.8] - 2026-03-20
4
27
 
5
28
  ### Fixed
@@ -0,0 +1,46 @@
1
+ # Contributing to PPM
2
+
3
+ Thanks for your interest in contributing!
4
+
5
+ ## Getting Started
6
+
7
+ ```bash
8
+ git clone https://github.com/hienlh/ppm.git
9
+ cd ppm && bun install
10
+
11
+ bun dev:server # Backend on port 8081
12
+ bun dev:web # Frontend on port 5173
13
+ ```
14
+
15
+ Requires: **Bun v1.3.6+**, **Git v2.0+**, **Claude Code** authenticated.
16
+
17
+ ## How to Contribute
18
+
19
+ 1. **Fork** the repo and create a branch from `main`
20
+ 2. **Make changes** — keep PRs focused and small
21
+ 3. **Test** — run `bun test` and make sure all tests pass
22
+ 4. **Commit** using [Conventional Commits](https://www.conventionalcommits.org/):
23
+ - `feat:` new feature
24
+ - `fix:` bug fix
25
+ - `docs:` documentation only
26
+ - `refactor:` code change without new feature or bug fix
27
+ - `test:` adding or updating tests
28
+ - `chore:` tooling, deps, config
29
+ 5. **Open a PR** against `main`
30
+
31
+ ## Guidelines
32
+
33
+ - Keep files under 200 lines — split into focused modules if needed
34
+ - Follow YAGNI / KISS / DRY principles
35
+ - No secrets or `.env` files in commits
36
+ - Run `bun run typecheck` before submitting
37
+
38
+ ## Reporting Bugs
39
+
40
+ Use `ppm report` to file a bug — it pre-fills environment info and logs automatically.
41
+
42
+ Or open an issue on [GitHub](https://github.com/hienlh/ppm/issues).
43
+
44
+ ## License
45
+
46
+ By contributing, you agree your contributions will be licensed under the [MIT License](LICENSE).
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 hienlh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,7 +2,10 @@
2
2
 
3
3
  A mobile-first web IDE with AI chat, terminal, git, database tools, and file explorer — all in one browser tab.
4
4
 
5
- **npm:** [@hienlh/ppm](https://www.npmjs.com/package/@hienlh/ppm) | **Version:** 0.6.7
5
+ [![npm version](https://img.shields.io/npm/v/@hienlh/ppm?style=flat-square)](https://www.npmjs.com/package/@hienlh/ppm)
6
+ [![npm downloads](https://img.shields.io/npm/dm/@hienlh/ppm?style=flat-square)](https://www.npmjs.com/package/@hienlh/ppm)
7
+ [![npm license](https://img.shields.io/npm/l/@hienlh/ppm?style=flat-square)](https://www.npmjs.com/package/@hienlh/ppm)
8
+ [![bun](https://img.shields.io/badge/runtime-bun-black?style=flat-square&logo=bun)](https://bun.sh)
6
9
 
7
10
  ## Quick Start
8
11
 
@@ -80,6 +83,36 @@ ppm init # Re-run setup wizard
80
83
  ppm report # File bug report on GitHub
81
84
  ```
82
85
 
86
+ ## Non-Interactive / AI Agent Setup
87
+
88
+ For scripts, CI environments, or AI agents that cannot interact with prompts:
89
+
90
+ ```bash
91
+ # Step 1: Init without any prompts (uses defaults, auto-generates password)
92
+ bunx @hienlh/ppm init -y
93
+
94
+ # Step 2: Start with Cloudflare tunnel in foreground
95
+ bunx @hienlh/ppm start -f --share
96
+ ```
97
+
98
+ The `-y` flag skips all prompts and applies these defaults:
99
+ - Port: `3210`
100
+ - Scan directory: `$HOME`
101
+ - Auth: enabled, password auto-generated (printed at end of `init` output)
102
+ - AI model: `claude-sonnet-4-6`
103
+
104
+ Override any default with flags:
105
+
106
+ ```bash
107
+ bunx @hienlh/ppm init -y \
108
+ --port 3210 \
109
+ --password "your-password" \
110
+ --scan /path/to/projects \
111
+ --share
112
+ ```
113
+
114
+ Once running, the Cloudflare public URL is printed to stdout — parse it to share with users.
115
+
83
116
  ## Requirements
84
117
 
85
118
  - **Bun** v1.3.6+ ([install](https://bun.sh))
package/bun.lock CHANGED
@@ -9,6 +9,7 @@
9
9
  "@codemirror/lang-sql": "^6.10.0",
10
10
  "@inquirer/prompts": "^8.3.0",
11
11
  "@monaco-editor/react": "^4.7.0",
12
+ "@radix-ui/react-switch": "^1.2.6",
12
13
  "@tanstack/react-table": "^8.21.3",
13
14
  "@uiw/react-codemirror": "^4.25.8",
14
15
  "@xterm/addon-fit": "^0.11.0",
@@ -0,0 +1 @@
1
+ import{i as e,t}from"./react-CYzKIDNi.js";import{A as n,C as r,D as i,N as a,_ as o,a as s,b as c,d as l,f as u,g as d,h as f,i as p,l as m,m as h,n as g,o as _,p as v,r as y,s as b,t as x,u as S,v as C,w,x as T,y as E}from"./input-CVIzrYsH.js";import{n as D,t as O}from"./jsx-runtime-wQxeESYQ.js";import{n as k}from"./utils-DC-bdPS3.js";import{t as A}from"./api-client-TUmacMRS.js";var j=D(`bell-off`,[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742`,key:`178tsu`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05`,key:`1hqiys`}]]),M=D(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),N=D(`chevron-down`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),P=D(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),F=e(t(),1),I=O(),L=Object.freeze({position:`absolute`,border:0,width:1,height:1,padding:0,margin:-1,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,wordWrap:`normal`}),R=`VisuallyHidden`,ee=F.forwardRef((e,t)=>(0,I.jsx)(w.span,{...e,ref:t,style:{...L,...e.style}}));ee.displayName=R;var z=ee;function B(e){let t=F.useRef({value:e,previous:e});return F.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var te=`Label`,V=F.forwardRef((e,t)=>(0,I.jsx)(w.label,{...e,ref:t,onMouseDown:t=>{t.target.closest(`button, input, select, textarea`)||(e.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}}));V.displayName=te;var H=V,ne=e(a(),1),re=[` `,`Enter`,`ArrowUp`,`ArrowDown`],ie=[` `,`Enter`],U=`Select`,[W,ae,oe]=T(U),[G,se]=r(U,[oe,b]),K=b(),[ce,q]=G(U),[le,ue]=G(U),de=e=>{let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:a,value:s,defaultValue:c,onValueChange:l,dir:u,name:f,autoComplete:p,disabled:m,required:h,form:g}=e,v=K(t),[y,b]=F.useState(null),[x,S]=F.useState(null),[w,T]=F.useState(!1),E=d(u),[D,O]=C({prop:r,defaultProp:i??!1,onChange:a,caller:U}),[k,A]=C({prop:s,defaultProp:c,onChange:l,caller:U}),j=F.useRef(null),M=y?g||!!y.closest(`form`):!0,[N,P]=F.useState(new Set),L=Array.from(N).map(e=>e.props.value).join(`;`);return(0,I.jsx)(_,{...v,children:(0,I.jsxs)(ce,{required:h,scope:t,trigger:y,onTriggerChange:b,valueNode:x,onValueNodeChange:S,valueNodeHasChildren:w,onValueNodeHasChildrenChange:T,contentId:o(),value:k,onValueChange:A,open:D,onOpenChange:O,dir:E,triggerPointerDownPosRef:j,disabled:m,children:[(0,I.jsx)(W.Provider,{scope:t,children:(0,I.jsx)(le,{scope:e.__scopeSelect,onNativeOptionAdd:F.useCallback(e=>{P(t=>new Set(t).add(e))},[]),onNativeOptionRemove:F.useCallback(e=>{P(t=>{let n=new Set(t);return n.delete(e),n})},[]),children:n})}),M?(0,I.jsxs)(tt,{"aria-hidden":!0,required:h,tabIndex:-1,name:f,autoComplete:p,value:k,onChange:e=>A(e.target.value),disabled:m,form:g,children:[k===void 0?(0,I.jsx)(`option`,{value:``}):null,Array.from(N)]},L):null]})})};de.displayName=U;var fe=`SelectTrigger`,pe=F.forwardRef((e,t)=>{let{__scopeSelect:r,disabled:i=!1,...a}=e,o=K(r),s=q(fe,r),l=s.disabled||i,u=n(t,s.onTriggerChange),d=ae(r),f=F.useRef(`touch`),[p,m,h]=rt(e=>{let t=d().filter(e=>!e.disabled),n=it(t,e,t.find(e=>e.value===s.value));n!==void 0&&s.onValueChange(n.value)}),g=e=>{l||(s.onOpenChange(!0),h()),e&&(s.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})};return(0,I.jsx)(y,{asChild:!0,...o,children:(0,I.jsx)(w.button,{type:`button`,role:`combobox`,"aria-controls":s.contentId,"aria-expanded":s.open,"aria-required":s.required,"aria-autocomplete":`none`,dir:s.dir,"data-state":s.open?`open`:`closed`,disabled:l,"data-disabled":l?``:void 0,"data-placeholder":nt(s.value)?``:void 0,...a,ref:u,onClick:c(a.onClick,e=>{e.currentTarget.focus(),f.current!==`mouse`&&g(e)}),onPointerDown:c(a.onPointerDown,e=>{f.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),e.button===0&&e.ctrlKey===!1&&e.pointerType===`mouse`&&(g(e),e.preventDefault())}),onKeyDown:c(a.onKeyDown,e=>{let t=p.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&m(e.key),!(t&&e.key===` `)&&re.includes(e.key)&&(g(),e.preventDefault())})})})});pe.displayName=fe;var me=`SelectValue`,he=F.forwardRef((e,t)=>{let{__scopeSelect:r,className:i,style:a,children:o,placeholder:s=``,...c}=e,l=q(me,r),{onValueNodeHasChildrenChange:u}=l,d=o!==void 0,f=n(t,l.onValueNodeChange);return E(()=>{u(d)},[u,d]),(0,I.jsx)(w.span,{...c,ref:f,style:{pointerEvents:`none`},children:nt(l.value)?(0,I.jsx)(I.Fragment,{children:s}):o})});he.displayName=me;var ge=`SelectIcon`,_e=F.forwardRef((e,t)=>{let{__scopeSelect:n,children:r,...i}=e;return(0,I.jsx)(w.span,{"aria-hidden":!0,...i,ref:t,children:r||`▼`})});_e.displayName=ge;var ve=`SelectPortal`,ye=e=>(0,I.jsx)(u,{asChild:!0,...e});ye.displayName=ve;var J=`SelectContent`,be=F.forwardRef((e,t)=>{let n=q(J,e.__scopeSelect),[r,i]=F.useState();if(E(()=>{i(new DocumentFragment)},[]),!n.open){let t=r;return t?ne.createPortal((0,I.jsx)(xe,{scope:e.__scopeSelect,children:(0,I.jsx)(W.Slot,{scope:e.__scopeSelect,children:(0,I.jsx)(`div`,{children:e.children})})}),t):null}return(0,I.jsx)(we,{...e,ref:t})});be.displayName=J;var Y=10,[xe,X]=G(J),Se=`SelectContentImpl`,Ce=i(`SelectContent.RemoveScroll`),we=F.forwardRef((e,t)=>{let{__scopeSelect:r,position:i=`item-aligned`,onCloseAutoFocus:a,onEscapeKeyDown:o,onPointerDownOutside:s,side:u,sideOffset:d,align:f,alignOffset:p,arrowPadding:g,collisionBoundary:_,collisionPadding:y,sticky:b,hideWhenDetached:x,avoidCollisions:C,...w}=e,T=q(J,r),[E,D]=F.useState(null),[O,k]=F.useState(null),A=n(t,e=>D(e)),[j,M]=F.useState(null),[N,P]=F.useState(null),L=ae(r),[R,ee]=F.useState(!1),z=F.useRef(!1);F.useEffect(()=>{if(E)return m(E)},[E]),l();let B=F.useCallback(e=>{let[t,...n]=L().map(e=>e.ref.current),[r]=n.slice(-1),i=document.activeElement;for(let n of e)if(n===i||(n?.scrollIntoView({block:`nearest`}),n===t&&O&&(O.scrollTop=0),n===r&&O&&(O.scrollTop=O.scrollHeight),n?.focus(),document.activeElement!==i))return},[L,O]),te=F.useCallback(()=>B([j,E]),[B,j,E]);F.useEffect(()=>{R&&te()},[R,te]);let{onOpenChange:V,triggerPointerDownPosRef:H}=T;F.useEffect(()=>{if(E){let e={x:0,y:0},t=t=>{e={x:Math.abs(Math.round(t.pageX)-(H.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(H.current?.y??0))}},n=n=>{e.x<=10&&e.y<=10?n.preventDefault():E.contains(n.target)||V(!1),document.removeEventListener(`pointermove`,t),H.current=null};return H.current!==null&&(document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,n,{capture:!0,once:!0})),()=>{document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,n,{capture:!0})}}},[E,V,H]),F.useEffect(()=>{let e=()=>V(!1);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[V]);let[ne,re]=rt(e=>{let t=L().filter(e=>!e.disabled),n=it(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current.focus())}),ie=F.useCallback((e,t,n)=>{let r=!z.current&&!n;(T.value!==void 0&&T.value===t||r)&&(M(e),r&&(z.current=!0))},[T.value]),U=F.useCallback(()=>E?.focus(),[E]),W=F.useCallback((e,t,n)=>{let r=!z.current&&!n;(T.value!==void 0&&T.value===t||r)&&P(e)},[T.value]),oe=i===`popper`?Oe:Ee,G=oe===Oe?{side:u,sideOffset:d,align:f,alignOffset:p,arrowPadding:g,collisionBoundary:_,collisionPadding:y,sticky:b,hideWhenDetached:x,avoidCollisions:C}:{};return(0,I.jsx)(xe,{scope:r,content:E,viewport:O,onViewportChange:k,itemRefCallback:ie,selectedItem:j,onItemLeave:U,itemTextRefCallback:W,focusSelectedItem:te,selectedItemText:N,position:i,isPositioned:R,searchRef:ne,children:(0,I.jsx)(S,{as:Ce,allowPinchZoom:!0,children:(0,I.jsx)(v,{asChild:!0,trapped:T.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:c(a,e=>{T.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,I.jsx)(h,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:o,onPointerDownOutside:s,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>T.onOpenChange(!1),children:(0,I.jsx)(oe,{role:`listbox`,id:T.contentId,"data-state":T.open?`open`:`closed`,dir:T.dir,onContextMenu:e=>e.preventDefault(),...w,...G,onPlaced:()=>ee(!0),ref:A,style:{display:`flex`,flexDirection:`column`,outline:`none`,...w.style},onKeyDown:c(w.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&re(e.key),[`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(e.key)){let t=L().filter(e=>!e.disabled).map(e=>e.ref.current);if([`ArrowUp`,`End`].includes(e.key)&&(t=t.slice().reverse()),[`ArrowUp`,`ArrowDown`].includes(e.key)){let n=e.target,r=t.indexOf(n);t=t.slice(r+1)}setTimeout(()=>B(t)),e.preventDefault()}})})})})})})});we.displayName=Se;var Te=`SelectItemAlignedPosition`,Ee=F.forwardRef((e,t)=>{let{__scopeSelect:r,onPlaced:i,...a}=e,o=q(J,r),s=X(J,r),[c,l]=F.useState(null),[u,d]=F.useState(null),f=n(t,e=>d(e)),p=ae(r),m=F.useRef(!1),h=F.useRef(!0),{viewport:_,selectedItem:v,selectedItemText:y,focusSelectedItem:b}=s,x=F.useCallback(()=>{if(o.trigger&&o.valueNode&&c&&u&&_&&v&&y){let e=o.trigger.getBoundingClientRect(),t=u.getBoundingClientRect(),n=o.valueNode.getBoundingClientRect(),r=y.getBoundingClientRect();if(o.dir!==`rtl`){let i=r.left-t.left,a=n.left-i,o=e.left-a,s=e.width+o,l=Math.max(s,t.width),u=window.innerWidth-Y,d=g(a,[Y,Math.max(Y,u-l)]);c.style.minWidth=s+`px`,c.style.left=d+`px`}else{let i=t.right-r.right,a=window.innerWidth-n.right-i,o=window.innerWidth-e.right-a,s=e.width+o,l=Math.max(s,t.width),u=window.innerWidth-Y,d=g(a,[Y,Math.max(Y,u-l)]);c.style.minWidth=s+`px`,c.style.right=d+`px`}let a=p(),s=window.innerHeight-Y*2,l=_.scrollHeight,d=window.getComputedStyle(u),f=parseInt(d.borderTopWidth,10),h=parseInt(d.paddingTop,10),b=parseInt(d.borderBottomWidth,10),x=parseInt(d.paddingBottom,10),S=f+h+l+x+b,C=Math.min(v.offsetHeight*5,S),w=window.getComputedStyle(_),T=parseInt(w.paddingTop,10),E=parseInt(w.paddingBottom,10),D=e.top+e.height/2-Y,O=s-D,k=v.offsetHeight/2,A=v.offsetTop+k,j=f+h+A,M=S-j;if(j<=D){let e=a.length>0&&v===a[a.length-1].ref.current;c.style.bottom=`0px`;let t=u.clientHeight-_.offsetTop-_.offsetHeight,n=j+Math.max(O,k+(e?E:0)+t+b);c.style.height=n+`px`}else{let e=a.length>0&&v===a[0].ref.current;c.style.top=`0px`;let t=Math.max(D,f+_.offsetTop+(e?T:0)+k)+M;c.style.height=t+`px`,_.scrollTop=j-D+_.offsetTop}c.style.margin=`${Y}px 0`,c.style.minHeight=C+`px`,c.style.maxHeight=s+`px`,i?.(),requestAnimationFrame(()=>m.current=!0)}},[p,o.trigger,o.valueNode,c,u,_,v,y,o.dir,i]);E(()=>x(),[x]);let[S,C]=F.useState();return E(()=>{u&&C(window.getComputedStyle(u).zIndex)},[u]),(0,I.jsx)(ke,{scope:r,contentWrapper:c,shouldExpandOnScrollRef:m,onScrollButtonChange:F.useCallback(e=>{e&&h.current===!0&&(x(),b?.(),h.current=!1)},[x,b]),children:(0,I.jsx)(`div`,{ref:l,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:S},children:(0,I.jsx)(w.div,{...a,ref:f,style:{boxSizing:`border-box`,maxHeight:`100%`,...a.style}})})})});Ee.displayName=Te;var De=`SelectPopperPosition`,Oe=F.forwardRef((e,t)=>{let{__scopeSelect:n,align:r=`start`,collisionPadding:i=Y,...a}=e,o=K(n);return(0,I.jsx)(s,{...o,...a,ref:t,align:r,collisionPadding:i,style:{boxSizing:`border-box`,...a.style,"--radix-select-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-select-content-available-width":`var(--radix-popper-available-width)`,"--radix-select-content-available-height":`var(--radix-popper-available-height)`,"--radix-select-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-select-trigger-height":`var(--radix-popper-anchor-height)`}})});Oe.displayName=De;var[ke,Ae]=G(J,{}),je=`SelectViewport`,Me=F.forwardRef((e,t)=>{let{__scopeSelect:r,nonce:i,...a}=e,o=X(je,r),s=Ae(je,r),l=n(t,o.onViewportChange),u=F.useRef(0);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`},nonce:i}),(0,I.jsx)(W.Slot,{scope:r,children:(0,I.jsx)(w.div,{"data-radix-select-viewport":``,role:`presentation`,...a,ref:l,style:{position:`relative`,flex:1,overflow:`hidden auto`,...a.style},onScroll:c(a.onScroll,e=>{let t=e.currentTarget,{contentWrapper:n,shouldExpandOnScrollRef:r}=s;if(r?.current&&n){let e=Math.abs(u.current-t.scrollTop);if(e>0){let r=window.innerHeight-Y*2,i=parseFloat(n.style.minHeight),a=parseFloat(n.style.height),o=Math.max(i,a);if(o<r){let i=o+e,a=Math.min(r,i),s=i-a;n.style.height=a+`px`,n.style.bottom===`0px`&&(t.scrollTop=s>0?s:0,n.style.justifyContent=`flex-end`)}}}u.current=t.scrollTop})})})]})});Me.displayName=je;var Ne=`SelectGroup`,[Pe,Fe]=G(Ne),Ie=F.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=o();return(0,I.jsx)(Pe,{scope:n,id:i,children:(0,I.jsx)(w.div,{role:`group`,"aria-labelledby":i,...r,ref:t})})});Ie.displayName=Ne;var Le=`SelectLabel`,Re=F.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=Fe(Le,n);return(0,I.jsx)(w.div,{id:i.id,...r,ref:t})});Re.displayName=Le;var Z=`SelectItem`,[ze,Be]=G(Z),Ve=F.forwardRef((e,t)=>{let{__scopeSelect:r,value:i,disabled:a=!1,textValue:s,...l}=e,u=q(Z,r),d=X(Z,r),f=u.value===i,[p,m]=F.useState(s??``),[h,g]=F.useState(!1),_=n(t,e=>d.itemRefCallback?.(e,i,a)),v=o(),y=F.useRef(`touch`),b=()=>{a||(u.onValueChange(i),u.onOpenChange(!1))};if(i===``)throw Error(`A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.`);return(0,I.jsx)(ze,{scope:r,value:i,disabled:a,textId:v,isSelected:f,onItemTextChange:F.useCallback(e=>{m(t=>t||(e?.textContent??``).trim())},[]),children:(0,I.jsx)(W.ItemSlot,{scope:r,value:i,disabled:a,textValue:p,children:(0,I.jsx)(w.div,{role:`option`,"aria-labelledby":v,"data-highlighted":h?``:void 0,"aria-selected":f&&h,"data-state":f?`checked`:`unchecked`,"aria-disabled":a||void 0,"data-disabled":a?``:void 0,tabIndex:a?void 0:-1,...l,ref:_,onFocus:c(l.onFocus,()=>g(!0)),onBlur:c(l.onBlur,()=>g(!1)),onClick:c(l.onClick,()=>{y.current!==`mouse`&&b()}),onPointerUp:c(l.onPointerUp,()=>{y.current===`mouse`&&b()}),onPointerDown:c(l.onPointerDown,e=>{y.current=e.pointerType}),onPointerMove:c(l.onPointerMove,e=>{y.current=e.pointerType,a?d.onItemLeave?.():y.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:c(l.onPointerLeave,e=>{e.currentTarget===document.activeElement&&d.onItemLeave?.()}),onKeyDown:c(l.onKeyDown,e=>{d.searchRef?.current!==``&&e.key===` `||(ie.includes(e.key)&&b(),e.key===` `&&e.preventDefault())})})})})});Ve.displayName=Z;var Q=`SelectItemText`,He=F.forwardRef((e,t)=>{let{__scopeSelect:r,className:i,style:a,...o}=e,s=q(Q,r),c=X(Q,r),l=Be(Q,r),u=ue(Q,r),[d,f]=F.useState(null),p=n(t,e=>f(e),l.onItemTextChange,e=>c.itemTextRefCallback?.(e,l.value,l.disabled)),m=d?.textContent,h=F.useMemo(()=>(0,I.jsx)(`option`,{value:l.value,disabled:l.disabled,children:m},l.value),[l.disabled,l.value,m]),{onNativeOptionAdd:g,onNativeOptionRemove:_}=u;return E(()=>(g(h),()=>_(h)),[g,_,h]),(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(w.span,{id:l.textId,...o,ref:p}),l.isSelected&&s.valueNode&&!s.valueNodeHasChildren?ne.createPortal(o.children,s.valueNode):null]})});He.displayName=Q;var Ue=`SelectItemIndicator`,We=F.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return Be(Ue,n).isSelected?(0,I.jsx)(w.span,{"aria-hidden":!0,...r,ref:t}):null});We.displayName=Ue;var Ge=`SelectScrollUpButton`,Ke=F.forwardRef((e,t)=>{let r=X(Ge,e.__scopeSelect),i=Ae(Ge,e.__scopeSelect),[a,o]=F.useState(!1),s=n(t,i.onScrollButtonChange);return E(()=>{if(r.viewport&&r.isPositioned){let e=function(){o(t.scrollTop>0)},t=r.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[r.viewport,r.isPositioned]),a?(0,I.jsx)(Ye,{...e,ref:s,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=r;e&&t&&(e.scrollTop-=t.offsetHeight)}}):null});Ke.displayName=Ge;var qe=`SelectScrollDownButton`,Je=F.forwardRef((e,t)=>{let r=X(qe,e.__scopeSelect),i=Ae(qe,e.__scopeSelect),[a,o]=F.useState(!1),s=n(t,i.onScrollButtonChange);return E(()=>{if(r.viewport&&r.isPositioned){let e=function(){let e=t.scrollHeight-t.clientHeight;o(Math.ceil(t.scrollTop)<e)},t=r.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[r.viewport,r.isPositioned]),a?(0,I.jsx)(Ye,{...e,ref:s,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=r;e&&t&&(e.scrollTop+=t.offsetHeight)}}):null});Je.displayName=qe;var Ye=F.forwardRef((e,t)=>{let{__scopeSelect:n,onAutoScroll:r,...i}=e,a=X(`SelectScrollButton`,n),o=F.useRef(null),s=ae(n),l=F.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return F.useEffect(()=>()=>l(),[l]),E(()=>{s().find(e=>e.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:`nearest`})},[s]),(0,I.jsx)(w.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:c(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:c(i.onPointerMove,()=>{a.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:c(i.onPointerLeave,()=>{l()})})}),Xe=`SelectSeparator`,Ze=F.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return(0,I.jsx)(w.div,{"aria-hidden":!0,...r,ref:t})});Ze.displayName=Xe;var Qe=`SelectArrow`,$e=F.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=K(n),a=q(Qe,n),o=X(Qe,n);return a.open&&o.position===`popper`?(0,I.jsx)(p,{...i,...r,ref:t}):null});$e.displayName=Qe;var et=`SelectBubbleInput`,tt=F.forwardRef(({__scopeSelect:e,value:t,...r},i)=>{let a=F.useRef(null),o=n(i,a),s=B(t);return F.useEffect(()=>{let e=a.current;if(!e)return;let n=window.HTMLSelectElement.prototype,r=Object.getOwnPropertyDescriptor(n,`value`).set;if(s!==t&&r){let n=new Event(`change`,{bubbles:!0});r.call(e,t),e.dispatchEvent(n)}},[s,t]),(0,I.jsx)(w.select,{...r,style:{...L,...r.style},ref:o,defaultValue:t})});tt.displayName=et;function nt(e){return e===``||e===void 0}function rt(e){let t=f(e),n=F.useRef(``),r=F.useRef(0),i=F.useCallback(e=>{let i=n.current+e;t(i),(function e(t){n.current=t,window.clearTimeout(r.current),t!==``&&(r.current=window.setTimeout(()=>e(``),1e3))})(i)},[t]),a=F.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return F.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}function it(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=at(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}function at(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var ot=de,st=pe,ct=he,lt=_e,ut=ye,dt=be,ft=Me,pt=Ve,mt=He,ht=We,gt=Ke,_t=Je;function $({className:e,...t}){return(0,I.jsx)(H,{"data-slot":`label`,className:k(`flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,e),...t})}function vt({...e}){return(0,I.jsx)(ot,{"data-slot":`select`,...e})}function yt({...e}){return(0,I.jsx)(ct,{"data-slot":`select-value`,...e})}function bt({className:e,size:t=`default`,children:n,...r}){return(0,I.jsxs)(st,{"data-slot":`select-trigger`,"data-size":t,className:k(`flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground`,e),...r,children:[n,(0,I.jsx)(lt,{asChild:!0,children:(0,I.jsx)(N,{className:`size-4 opacity-50`})})]})}function xt({className:e,children:t,position:n=`item-aligned`,align:r=`center`,...i}){return(0,I.jsx)(ut,{children:(0,I.jsxs)(dt,{"data-slot":`select-content`,className:k(`relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,align:r,...i,children:[(0,I.jsx)(Ct,{}),(0,I.jsx)(ft,{className:k(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1`),children:t}),(0,I.jsx)(wt,{})]})})}function St({className:e,children:t,...n}){return(0,I.jsxs)(pt,{"data-slot":`select-item`,className:k(`relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2`,e),...n,children:[(0,I.jsx)(`span`,{"data-slot":`select-item-indicator`,className:`absolute right-2 flex size-3.5 items-center justify-center`,children:(0,I.jsx)(ht,{children:(0,I.jsx)(M,{className:`size-4`})})}),(0,I.jsx)(mt,{children:t})]})}function Ct({className:e,...t}){return(0,I.jsx)(gt,{"data-slot":`select-scroll-up-button`,className:k(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(P,{className:`size-4`})})}function wt({className:e,...t}){return(0,I.jsx)(_t,{"data-slot":`select-scroll-down-button`,className:k(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(N,{className:`size-4`})})}function Tt(){return A.get(`/api/accounts`)}function Et(){return A.get(`/api/accounts/active`)}function Dt(e){return A.post(`/api/accounts`,e)}function Ot(e){return A.del(`/api/accounts/${e}`)}function kt(e,t){return A.patch(`/api/accounts/${e}`,t)}function At(){return A.get(`/api/accounts/settings`)}function jt(e){return A.put(`/api/accounts/settings`,e)}function Mt(){return A.get(`/api/accounts/usage`)}function Nt(){return A.get(`/api/settings/ai`)}function Pt(e){return A.put(`/api/settings/ai`,e)}var Ft=[{value:`claude-sonnet-4-6`,label:`Claude Sonnet 4.6`},{value:`claude-opus-4-6`,label:`Claude Opus 4.6`},{value:`claude-haiku-4-5`,label:`Claude Haiku 4.5`}],It=[{value:`low`,label:`Low`},{value:`medium`,label:`Medium`},{value:`high`,label:`High`}];function Lt({compact:e}={}){let[t,n]=(0,F.useState)(null),[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)(null),[s,c]=(0,F.useState)(0);(0,F.useEffect)(()=>{Nt().then(n).catch(e=>o(e.message))},[]);let l=t?.default_provider??`claude`,u=t?.providers[l],d=async(e,r)=>{if(t){i(!0),o(null);try{n(await Pt({providers:{[l]:{[e]:r}}})),c(e=>e+1)}catch(e){o(e.message)}finally{i(!1)}}},f=e?`text-[11px]`:`text-sm`,p=e?`text-xs`:`text-sm`,m=e?`space-y-2`:`space-y-4`,h=e?`space-y-1.5`:`space-y-3`,g=e?`space-y-1`:`space-y-1.5`;return t?(0,I.jsxs)(`div`,{className:m,children:[(0,I.jsx)(`h3`,{className:`${p} font-medium text-text-secondary`,children:`AI Provider`}),(0,I.jsxs)(`div`,{className:h,children:[(0,I.jsxs)(`div`,{className:g,children:[(0,I.jsx)($,{htmlFor:`ai-model`,className:e?f:void 0,children:`Model`}),(0,I.jsxs)(vt,{value:u?.model??`claude-sonnet-4-6`,onValueChange:e=>d(`model`,e),children:[(0,I.jsx)(bt,{id:`ai-model`,className:`w-full ${e?`h-7 text-[11px]`:``}`,children:(0,I.jsx)(yt,{})}),(0,I.jsx)(xt,{children:Ft.map(e=>(0,I.jsx)(St,{value:e.value,children:e.label},e.value))})]})]}),(0,I.jsxs)(`div`,{className:g,children:[(0,I.jsx)($,{htmlFor:`ai-effort`,className:e?f:void 0,children:`Effort`}),(0,I.jsxs)(vt,{value:u?.effort??`high`,onValueChange:e=>d(`effort`,e),children:[(0,I.jsx)(bt,{id:`ai-effort`,className:`w-full ${e?`h-7 text-[11px]`:``}`,children:(0,I.jsx)(yt,{})}),(0,I.jsx)(xt,{children:It.map(e=>(0,I.jsx)(St,{value:e.value,children:e.label},e.value))})]})]}),(0,I.jsxs)(`div`,{className:g,children:[(0,I.jsx)($,{htmlFor:`ai-max-turns`,className:e?f:void 0,children:`Max Turns (1-500)`}),(0,I.jsx)(x,{id:`ai-max-turns`,type:`number`,min:1,max:500,defaultValue:u?.max_turns??100,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseInt(e.target.value);isNaN(t)||d(`max_turns`,t)}},`turns-${s}`)]}),(0,I.jsxs)(`div`,{className:g,children:[(0,I.jsx)($,{htmlFor:`ai-budget`,className:e?f:void 0,children:`Max Budget (USD)`}),(0,I.jsx)(x,{id:`ai-budget`,type:`number`,step:.1,min:.01,max:50,defaultValue:u?.max_budget_usd??``,placeholder:`No limit`,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseFloat(e.target.value);d(`max_budget_usd`,isNaN(t)?void 0:t)}},`budget-${s}`)]}),(0,I.jsxs)(`div`,{className:g,children:[(0,I.jsx)($,{htmlFor:`ai-thinking`,className:e?f:void 0,children:`Thinking Budget (tokens)`}),(0,I.jsx)(x,{id:`ai-thinking`,type:`number`,min:0,defaultValue:u?.thinking_budget_tokens??``,placeholder:`Disabled`,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseInt(e.target.value);d(`thinking_budget_tokens`,isNaN(t)?void 0:t)}},`thinking-${s}`)]})]}),r&&(0,I.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`Saving...`}),a&&(0,I.jsx)(`p`,{className:`text-xs text-red-500`,children:a})]}):(0,I.jsxs)(`div`,{className:h,children:[(0,I.jsx)(`h3`,{className:`${p} font-medium text-text-secondary`,children:`AI Provider`}),(0,I.jsx)(`p`,{className:`${f} text-text-subtle`,children:a?`Error: ${a}`:`Loading...`})]})}export{z as _,Tt as a,M as b,kt as c,xt as d,St as f,B as g,$ as h,At as i,jt as l,yt as m,Dt as n,Et as o,bt as p,Ot as r,Mt as s,Lt as t,vt as u,P as v,j as x,N as y};
@@ -0,0 +1,7 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-client-TUmacMRS.js","assets/react-CYzKIDNi.js"])))=>i.map(i=>d[i]);
2
+ import{i as e,t}from"./react-CYzKIDNi.js";import{M as n,j as r}from"./input-CVIzrYsH.js";import{n as i,t as a}from"./jsx-runtime-wQxeESYQ.js";import{b as o,s,t as c,x as l,y as u}from"./ai-settings-section-BxCMGg-I.js";import{t as d}from"./columns-2-fz8yNaAo.js";import{a as f,n as p,t as m}from"./tab-store-0CKk8cSr.js";import{n as h}from"./settings-store-2NQzaOVJ.js";import{r as g,t as _}from"./utils-DC-bdPS3.js";import{i as v,r as y,t as b}from"./api-client-TUmacMRS.js";import{A as x,B as S,D as C,E as w,F as T,H as E,N as D,P as O,S as k,T as A,V as j,g as M,h as N,k as P,t as F,w as I}from"./index-qElHXk-7.js";import{t as L}from"./markdown-renderer-DpIu7iOT.js";var R=i(`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`}]]),z=i(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),B=i(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),V=i(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),H=i(`code`,[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]),ee=i(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),te=i(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),U=i(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),ne=i(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),W=i(`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`}]]),re=i(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),ie=i(`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`}]]),G=i(`sparkles`,[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]]),K=i(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),q=e(t(),1),J=3e4,ae=1e3,oe=class{ws=null;url;handlers=[];reconnectAttempts=0;reconnectTimer=null;intentionalClose=!1;constructor(e){this.url=e}connect(){this.intentionalClose=!1,this.cleanup();let e=window.location.protocol===`https:`?`wss:`:`ws:`,t=this.url.startsWith(`ws`)?this.url:`${e}//${window.location.host}${this.url}`;this.ws=new WebSocket(t),this.ws.onopen=()=>{this.reconnectAttempts=0;try{this.ws?.send(JSON.stringify({type:`ready`}))}catch{}},this.ws.onmessage=e=>{for(let t of this.handlers)t(e)},this.ws.onclose=()=>{this.intentionalClose||this.scheduleReconnect()},this.ws.onerror=()=>{this.ws?.close()}}disconnect(){this.intentionalClose=!0,this.cleanup(),this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null)}send(e){this.ws?.readyState===WebSocket.OPEN&&this.ws.send(e)}onMessage(e){return this.handlers.push(e),()=>{this.handlers=this.handlers.filter(t=>t!==e)}}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}cleanup(){this.ws&&=(this.ws.onopen=null,this.ws.onclose=null,this.ws.onmessage=null,this.ws.onerror=null,(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)&&this.ws.close(),null)}scheduleReconnect(){let e=Math.min(ae*2**this.reconnectAttempts,J);this.reconnectAttempts++,this.reconnectTimer=setTimeout(()=>this.connect(),e)}};function se({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,q.useRef)(null);return(0,q.useEffect)(()=>{let i=new oe(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,q.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,q.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,q.useCallback)(()=>{r.current?.disconnect()},[])}}var ce=null;function Y(){return ce||=new AudioContext,ce}function X(e,t,n,r,i=`sine`){let a=Y(),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 le(){let e=Y().currentTime;X(523,.15,e,.15),X(659,.2,e+.12,.15)}function ue(){let e=Y().currentTime;X(880,.12,e,.18,`square`),X(698,.12,e+.15,.18,`square`),X(880,.15,e+.3,.15,`square`)}function de(){let e=Y().currentTime;X(440,.12,e,.12),X(523,.12,e+.1,.12),X(659,.18,e+.2,.12)}var fe={done:le,approval_request:ue,question:de};function pe(e){try{fe[e]?.()}catch{}}function me(e){if(document.hidden)return!1;let{panels:t,focusedPanelId:n}=p.getState(),r=t[n];if(!r)return!1;let i=r.tabs.find(e=>e.id===r.activeTabId);return i?.type===`chat`&&i.metadata?.sessionId===e}function he(e,t=`claude`,n=``){let[r,i]=(0,q.useState)([]),[a,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(`idle`),[d,f]=(0,q.useState)(0),[p,m]=(0,q.useState)(15),[h,g]=(0,q.useState)(null),[_,b]=(0,q.useState)(null),[x,S]=(0,q.useState)(null),[C,w]=(0,q.useState)(!1),T=(0,q.useRef)(``),E=(0,q.useRef)([]),D=(0,q.useRef)(!1),O=(0,q.useRef)(null),k=(0,q.useRef)(()=>{}),A=(0,q.useRef)(null),j=(0,q.useRef)(e);j.current=e;let N=(0,q.useRef)(n);N.current=n;let P=(0,q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type===`ping`)return;if(t.type===`title_updated`){S(t.title??null);return}if(t.type===`streaming_status`){let e=t.status??`idle`;if(u(e),f(e===`connecting`?t.elapsed??0:0),e===`connecting`){let e=t.effort,n=t.thinkingBudget,r=15;n&&n>0?r=Math.max(15,Math.round(n/500)):e===`high`?r=30:e===`low`&&(r=10),m(r)}return}if(t.type===`connected`){w(!0),t.sessionTitle&&S(t.sessionTitle);return}if(t.type===`status`){w(!0);let e=t;e.sessionTitle&&S(e.sessionTitle),e.isStreaming&&(D.current=!0,c(!0)),e.pendingApproval&&g({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),A.current?.();return}let n=(e,t)=>{let n=E.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=E.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return E.current[n]={...r,children:i},!0},r=()=>{let e=T.current,t=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`&&!r.id.startsWith(`final-`)?[...n.slice(0,-1),{...r,content:e,events:t}]:[...n,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:t,timestamp:new Date().toISOString()}]})};switch(t.type){case`text`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}T.current+=t.content,E.current.push(t),r();break}case`thinking`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}E.current.push(t),r();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}E.current.push(t),r();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}E.current.push(t),r();break}case`approval_request`:if(E.current.push(t),g({requestId:t.requestId,tool:t.tool,input:t.input}),j.current&&!me(j.current)){let e=t.tool===`AskUserQuestion`?`question`:`approval_request`;M.getState().addNotification(j.current,e,N.current),pe(e)}break;case`error`:{E.current.push(t);let e=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,events:e}]:[...n,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]}),D.current=!1,c(!1),u(`idle`);break}case`done`:{if(!D.current)break;t.contextWindowPct!=null&&b(t.contextWindowPct),j.current&&!me(j.current)&&(M.getState().addNotification(j.current,`done`,N.current),pe(`done`));let e=T.current,n=[...E.current];i(t=>{let r=t[t.length-1];return r?.role===`assistant`?[...t.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:n.length>0?n:r.events}]:t}),T.current=``,E.current=[],D.current=!1,c(!1),u(`idle`);break}}},[]),{send:F,connect:I}=se({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:P,autoConnect:!!e&&!!n});k.current=F,(0,q.useEffect)(()=>{let r=!1;return c(!1),g(null),T.current=``,E.current=[],w(!1),e&&n?(o(!0),fetch(`${v(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${y()}`}}).then(e=>e.json()).then(e=>{r||D.current||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&!D.current&&i([])}).finally(()=>{r||o(!1)})):i([]),()=>{r=!0}},[e,t,n]);let L=(0,q.useCallback)(e=>{if(e.trim()){if(D.current){let e=T.current,t=[...E.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}),F(JSON.stringify({type:`cancel`}))}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),T.current=``,E.current=[],O.current=null,D.current=!0,c(!0),u(`connecting`),g(null),F(JSON.stringify({type:`message`,content:e}))}},[F]),R=(0,q.useCallback)((e,t,n)=>{if(F(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=E.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])}g(null)},[F]),z=(0,q.useCallback)(()=>{if(!D.current)return;F(JSON.stringify({type:`cancel`}));let e=T.current,t=[...E.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}),T.current=``,E.current=[],O.current=null,D.current=!1,c(!1),g(null)},[F]),B=(0,q.useCallback)(()=>{w(!1),I(),A.current?.()},[I]),V=(0,q.useCallback)(()=>{!e||!n||(o(!0),fetch(`${v(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${y()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(i(e.data),T.current=``,E.current=[])}).catch(()=>{}).finally(()=>o(!1)))},[e,t,n]);return A.current=V,{messages:r,messagesLoading:a,isStreaming:s,streamingStatus:l,connectingElapsed:d,thinkingWarningThreshold:p,pendingApproval:h,contextWindowPct:_,sessionTitle:x,sendMessage:L,respondToApproval:R,cancelStreaming:z,reconnect:B,refetchMessages:V,isConnected:C}}var ge=12e4;function _e(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(`${v(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${y()}`}}).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(),ge),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,q.useCallback)(()=>l(!0),[l])}}var ve={damping:.7,stiffness:.05,mass:1.25},ye=70,be=1e3/60,xe=350,Se=!1;globalThis.document?.addEventListener(`mousedown`,()=>{Se=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{Se=!1}),globalThis.document?.addEventListener(`click`,()=>{Se=!1});var Ce=(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(!Se)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){g.current&&(g.current.scrollTop=e,d.ignoreScrollToTop=g.current.scrollTop)},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<=ye}}},[]),f=(0,q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Ee(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))/be;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:Ee(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=we(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=we(e=>{if(d.resizeObserver?.disconnect(),!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=Ee(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:xe})}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 we(e,t){let n=(0,q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Te=new Map;function Ee(...e){let t={...ve},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 Te.has(r)||Te.set(r,Object.freeze(t)),n?`instant`:Te.get(r)}var De=(0,q.createContext)(null),Oe=typeof window<`u`?q.useLayoutEffect:q.useEffect;function ke({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,q.useRef)(null),d=Ce({mass:i,damping:a,stiffness:o,resize:n,initial:r,targetScrollTop:q.useCallback((e,t)=>(y?.targetScrollTop??s)?.(e,t)??e,[s])}),{scrollRef:f,contentRef:p,scrollToBottom:m,stopScroll:h,isAtBottom:g,escapedFromLock:_,state:v}=e??d,y=(0,q.useMemo)(()=>({scrollToBottom:m,stopScroll:h,scrollRef:f,isAtBottom:g,escapedFromLock:_,contentRef:p,state:v,get targetScrollTop(){return u.current},set targetScrollTop(e){u.current=e}}),[m,g,p,f,h,_,v]);return(0,q.useImperativeHandle)(c,()=>y,[y]),Oe(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),q.createElement(De.Provider,{value:y},q.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=Ae();return q.createElement(`div`,{ref:r.scrollRef,style:{height:`100%`,width:`100%`,scrollbarGutter:`stable both-edges`},className:t},q.createElement(`div`,{...n,ref:r.contentRef},typeof e==`function`?e(r):e))}e.Content=t})(ke||={});function Ae(){let e=(0,q.useContext)(De);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var Z=a();function je(e){let t=e.type===`approval_request`;return{toolName:e.type===`tool_use`?e.tool:t?e.tool??`Tool`:`Tool`,input:e.type===`tool_use`?e.input:t?e.input??{}:{}}}function Me({tool:e,result:t,completed:n,projectName:r}){let[i,a]=(0,q.useState)(!1);if(e.type===`error`)return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded bg-red-500/10 border border-red-500/20 px-2 py-1.5 text-xs text-red-400`,children:[(0,Z.jsx)(j,{className:`size-3`}),(0,Z.jsx)(`span`,{children:e.message})]});let{toolName:o,input:s}=je(e),c=t?.type===`tool_result`,l=c&&!!t.isError,d=o===`AskUserQuestion`&&!!s?.answers,f=(o===`Agent`||o===`Task`)&&e.type===`tool_use`,p=f?e.children:void 0,m=p&&p.length>0;return(0,Z.jsxs)(`div`,{className:`rounded border text-xs ${f?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,Z.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors min-w-0`,children:[i?(0,Z.jsx)(u,{className:`size-3 shrink-0`}):(0,Z.jsx)(E,{className:`size-3 shrink-0`}),l?(0,Z.jsx)(V,{className:`size-3 text-red-400 shrink-0`}):c||d||n?(0,Z.jsx)(S,{className:`size-3 text-green-400 shrink-0`}):(0,Z.jsx)(x,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,Z.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,Z.jsx)(Ne,{name:o,input:s})}),m&&(0,Z.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[p.length,` steps`]})]}),i&&(0,Z.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,Z.jsx)(Pe,{name:o,input:s,projectName:r}),m&&(0,Z.jsx)(Re,{events:p,projectName:r}),c&&(0,Z.jsx)(Ie,{toolName:o,output:t.output})]})]})}function Ne({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,Z.jsxs)(Z.Fragment,{children:[e,` `,(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:_(n(t.file_path))})]});case`Bash`:return(0,Z.jsxs)(Z.Fragment,{children:[e,` `,(0,Z.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Q(n(t.command),60)})]});case`Glob`:return(0,Z.jsxs)(Z.Fragment,{children:[e,` `,(0,Z.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,Z.jsxs)(Z.Fragment,{children:[e,` `,(0,Z.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Q(n(t.pattern),40)})]});case`WebSearch`:return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(A,{className:`size-3 inline`}),` `,e,` `,(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:Q(n(t.query),50)})]});case`WebFetch`:return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ee,{className:`size-3 inline`}),` `,e,` `,(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:Q(n(t.url),50)})]});case`ToolSearch`:return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(A,{className:`size-3 inline`}),` `,e,` `,(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:Q(n(t.query),50)})]});case`Agent`:case`Task`:return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(B,{className:`size-3 inline`}),` `,e,` `,(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:Q(n(t.description||t.prompt),60)})]});case`TodoWrite`:{let n=Array.isArray(t.todos)?t.todos:[],r=n.filter(e=>e.status===`completed`).length;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ne,{className:`size-3 inline`}),` `,e,` `,(0,Z.jsxs)(`span`,{className:`text-text-subtle`,children:[r,`/`,n.length,` done`]})]})}case`AskUserQuestion`:{let n=Array.isArray(t.questions)?t.questions:[],r=!!t.answers;return(0,Z.jsxs)(Z.Fragment,{children:[e,` `,(0,Z.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,Z.jsx)(Z.Fragment,{children:e})}}function Pe({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=m(),a=e=>{n&&i({type:`editor`,title:_(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},o=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${_(e)}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,Z.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,Z.jsx)(`pre`,{className:`font-mono text-text-secondary overflow-x-auto whitespace-pre-wrap break-all`,children:r(t.command)})]});case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:{let n=r(t.file_path);return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`font-mono text-text-secondary break-all hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>a(n),title:`Open file in editor`,children:[(0,Z.jsx)(f,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,Z.jsxs)(`button`,{type:`button`,className:`text-text-subtle hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>o(n,r(t.old_string),r(t.new_string)),title:`View diff in new tab`,children:[(0,Z.jsx)(d,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,Z.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:Q(r(t.content),300)})]})}case`Glob`:return(0,Z.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,Z.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,Z.jsx)(Fe,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,Z.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,Z.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,Z.jsx)(ze,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,Z.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsxs)(`a`,{href:r(t.url),target:`_blank`,rel:`noopener noreferrer`,className:`font-mono text-primary hover:underline break-all flex items-center gap-1`,children:[(0,Z.jsx)(ee,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,Z.jsx)(`p`,{className:`text-text-subtle`,children:Q(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,Z.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,Z.jsx)(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-xs border ${(n[e.question]??``).split(`, `).includes(t.label)?`border-accent bg-accent/20 text-text-primary`:`border-border text-text-subtle`}`,children:t.label},r))}),n[e.question]&&(0,Z.jsxs)(`p`,{className:`text-foreground text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,Z.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function Fe({todos:e}){return(0,Z.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 mt-0.5 ${e.status===`completed`?`text-green-400`:e.status===`in_progress`?`text-yellow-400`:`text-text-subtle`}`,children:e.status===`completed`?`✓`:e.status===`in_progress`?`▶`:`○`}),(0,Z.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function Ie({toolName:e,output:t}){let[n,r]=(0,q.useState)(!1),i=(0,q.useMemo)(()=>{if(e!==`Agent`&&e!==`Task`)return null;try{let e=JSON.parse(t);if(Array.isArray(e)){let t=e.filter(e=>e.type===`text`&&e.text).map(e=>e.text).join(`
3
+
4
+ `);if(t)return t}if(typeof e==`string`)return e}catch{if(t&&!t.startsWith(`[{`))return t}return null},[e,t]);return i?(0,Z.jsxs)(`div`,{className:`border-t border-border pt-1.5 space-y-1`,children:[(0,Z.jsx)(ze,{content:i,maxHeight:`max-h-60`}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>r(!n),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors`,children:[(0,Z.jsx)(H,{className:`size-3`}),n?`Hide`:`Show`,` raw`]}),n&&(0,Z.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono max-h-40 whitespace-pre-wrap break-all text-[10px]`,children:t})]}):(0,Z.jsx)(Le,{output:t})}function Le({output:e}){let t=e.split(`
5
+ `).length,n=t>3||e.length>200,[r,i]=(0,q.useState)(n);return(0,Z.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[n&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>i(!r),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors mb-1`,children:[r?(0,Z.jsx)(E,{className:`size-3`}):(0,Z.jsx)(u,{className:`size-3`}),`Output (`,t,` lines)`]}),(0,Z.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono whitespace-pre-wrap break-all ${r?`max-h-16 overflow-hidden`:`max-h-60`}`,children:e})]})}function Re({events:e,projectName:t}){let n=[],r=``;for(let t of e)if(t.type===`text`)r+=t.content;else if(t.type===`tool_use`)r&&=(n.push({kind:`text`,content:r}),``),n.push({kind:`tool`,tool:t});else if(t.type===`tool_result`){let e=t.toolUseId,r=e?n.find(t=>t.kind===`tool`&&t.tool.type===`tool_use`&&t.tool.toolUseId===e&&!t.result):n.findLast(e=>e.kind===`tool`&&!e.result);r&&(r.result=t)}return r&&n.push({kind:`text`,content:r}),(0,Z.jsx)(`div`,{className:`border-l-2 border-accent/20 pl-2 space-y-1 mt-1`,children:n.map((e,n)=>e.kind===`text`?(0,Z.jsx)(`div`,{className:`text-text-secondary text-[11px]`,children:(0,Z.jsx)(ze,{content:e.content,maxHeight:`max-h-24`})},`st-${n}`):(0,Z.jsx)(Me,{tool:e.tool,result:e.result,completed:!!e.result,projectName:t},`sc-${n}`))})}function ze({content:e,maxHeight:t=`max-h-48`}){return(0,Z.jsx)(L,{content:e,className:`text-text-secondary overflow-auto ${t}`})}function Q(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}function Be(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 Ve(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 He({questions:e,onSubmit:t,onSkip:n}){let r=(0,q.useRef)(null),i=Be(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=Ve({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,Z.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,Z.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,Z.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,Z.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,Z.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,Z.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,Z.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,Z.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,Z.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,Z.jsx)(`div`,{className:`text-sm text-text-primary`,children:a.question}),a.multiSelect&&(0,Z.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,Z.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,Z.jsxs)(`button`,{onClick:()=>d(t),className:`text-left flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border transition-all ${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,Z.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,Z.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,Z.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,Z.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,Z.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,Z.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,Z.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.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,Z.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,Z.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,Z.jsxs)(`button`,{onClick:c,disabled:!i.allAnswered,className:`px-4 py-1.5 rounded bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,tabIndex:-1,children:[`Submit `,i.allAnswered?`✓`:`(${e.filter((e,t)=>i.hasAnswer(t)).length}/${e.length})`]})]})]})}function Ue({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,streamingStatus:a,connectingElapsed:o,thinkingWarningThreshold:s,projectName:c,onFork:l}){return t?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,Z.jsx)(B,{className:`size-10 text-text-subtle animate-pulse`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!i?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,Z.jsx)(B,{className:`size-10 text-text-subtle`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:`Send a message to start the conversation`})]}):(0,Z.jsxs)(ke,{className:`flex-1 overflow-y-auto`,resize:`smooth`,initial:`instant`,children:[(0,Z.jsxs)(ke.Content,{className:`p-4 space-y-4`,children:[e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return t||n}).map(e=>(0,Z.jsx)(Ge,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:c,onFork:e.role===`user`&&l?()=>l(e.content):void 0},e.id)),n&&(n.tool===`AskUserQuestion`?(0,Z.jsx)(ot,{approval:n,onRespond:r}):(0,Z.jsx)(at,{approval:n,onRespond:r})),i&&(0,Z.jsx)(rt,{lastMessage:e[e.length-1],streamingStatus:a,elapsed:o,warningThreshold:s})]}),(0,Z.jsx)(We,{})]})}function We(){let{isAtBottom:e,scrollToBottom:t}=Ae();return e?null:(0,Z.jsxs)(`button`,{onClick:()=>t(),className:`absolute bottom-2 left-1/2 -translate-x-1/2 flex items-center gap-1 px-3 py-1 rounded-full bg-surface-elevated border border-border text-xs text-text-secondary hover:text-foreground shadow-lg transition-all`,children:[(0,Z.jsx)(u,{className:`size-3`}),`Scroll to bottom`]})}function Ge({message:e,isStreaming:t,projectName:n,onFork:r}){return e.role===`user`?(0,Z.jsx)(Ze,{content:e.content,projectName:n,onFork:r}):e.role===`system`?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-red-500/10 border border-red-500/20 px-3 py-2 text-sm text-red-400`,children:[(0,Z.jsx)(j,{className:`size-4 shrink-0`}),(0,Z.jsx)(`p`,{children:e.content})]}):(0,Z.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.events&&e.events.length>0?(0,Z.jsx)(et,{events:e.events,isStreaming:t,projectName:n}):e.content&&(0,Z.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,Z.jsx)(it,{content:e.content,projectName:n})})})}var Ke=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]);function qe(e){let t=e.match(/^\[Attached file: (.+?)\]\n\n?/);if(t)return{files:[t[1]],text:e.slice(t[0].length)};let n=e.match(/^\[Attached files:\n([\s\S]+?)\]\n\n?/);return n?{files:n[1].split(`
6
+ `).map(e=>e.trim()).filter(Boolean),text:e.slice(n[0].length)}:{files:[],text:e}}function Je(e,t){let n=_(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function Ye(e){let t=e.lastIndexOf(`.`);return t===-1?!1:Ke.has(e.slice(t).toLowerCase())}function Xe(e){return e.toLowerCase().endsWith(`.pdf`)}function Ze({content:e,projectName:t,onFork:r}){let{files:i,text:a}=(0,q.useMemo)(()=>qe(e),[e]);return(0,Z.jsx)(`div`,{className:`flex justify-end group/user`,children:(0,Z.jsxs)(`div`,{className:`rounded-lg bg-primary/10 px-3 py-2 text-sm text-text-primary max-w-[85%] space-y-2 relative`,children:[i.length>0&&(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:i.map((e,n)=>Ye(e)?(0,Z.jsx)(Qe,{src:Je(e,t),alt:_(e)||`image`},n):Xe(e)?(0,Z.jsx)($e,{src:Je(e,t),filename:_(e)||`document.pdf`,mimeType:`application/pdf`},n):(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,Z.jsx)(T,{className:`size-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate max-w-40`,children:_(e)})]},n))}),a&&(0,Z.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:a}),r&&(0,Z.jsx)(`button`,{onClick:r,title:`Retry from this message (fork session)`,className:`absolute -left-8 top-1/2 -translate-y-1/2 opacity-0 group-hover/user:opacity-100 transition-opacity size-6 flex items-center justify-center rounded bg-surface border border-border text-text-subtle hover:text-text-primary hover:bg-surface-elevated`,children:(0,Z.jsx)(n,{className:`size-3`})})]})})}function Qe({src:e,alt:t}){let[n,r]=(0,q.useState)(null),[i,a]=(0,q.useState)(!1);return(0,q.useEffect)(()=>{let t,n=y();return fetch(e,{headers:n?{Authorization:`Bearer ${n}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed to load`);return e.blob()}).then(e=>{let n=URL.createObjectURL(e);t=n,r(n)}).catch(()=>a(!0)),()=>{t&&URL.revokeObjectURL(t)}},[e]),i?(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,Z.jsx)(U,{className:`size-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate max-w-40`,children:t})]}):n?(0,Z.jsx)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`block`,children:(0,Z.jsx)(`img`,{src:n,alt:t,className:`rounded-md max-h-48 max-w-full object-contain border border-border`})}):(0,Z.jsx)(`div`,{className:`rounded-md bg-surface border border-border h-24 w-32 animate-pulse`})}function $e({src:e,filename:t,mimeType:n}){let[r,i]=(0,q.useState)(!1);return(0,Z.jsxs)(`button`,{type:`button`,onClick:(0,q.useCallback)(async()=>{i(!0);try{let t=y(),r=await fetch(e,{headers:t?{Authorization:`Bearer ${t}`}:{}});if(!r.ok)throw Error(`Failed to load`);let i=await r.blob(),a=URL.createObjectURL(new Blob([i],{type:n}));window.open(a,`_blank`),setTimeout(()=>URL.revokeObjectURL(a),6e4)}catch{window.open(e,`_blank`)}finally{i(!1)}},[e,n]),disabled:r,className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary hover:bg-surface hover:text-text-primary transition-colors cursor-pointer disabled:opacity-50`,children:[(0,Z.jsx)(T,{className:`size-3.5 shrink-0 text-red-400`}),(0,Z.jsx)(`span`,{className:`truncate max-w-40`,children:t}),r&&(0,Z.jsx)(`span`,{className:`animate-spin text-[10px]`,children:`...`})]})}function et({events:e,isStreaming:t,projectName:n}){let r=[],i=``,a=``;for(let t=0;t<e.length;t++){let n=e[t];if(n.type===`thinking`){i&&=(r.push({kind:`text`,content:i}),``),a+=n.content;continue}a&&=(r.push({kind:`thinking`,content:a}),``),n.type===`text`?i+=n.content:n.type===`tool_use`?(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n})):n.type===`tool_result`||(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n}))}a&&r.push({kind:`thinking`,content:a}),i&&r.push({kind:`text`,content:i});let o=e.filter(e=>e.type===`tool_result`);for(let e of o){let t=e.toolUseId;if(t){let n=r.find(e=>e.kind===`tool`&&e.tool.type===`tool_use`&&e.tool.toolUseId===t);if(n){n.result=e;continue}}let n=r.find(e=>e.kind===`tool`&&!e.result);n&&(n.result=e)}for(let e=0;e<r.length;e++){let n=r[e];if(n.kind===`tool`&&!n.result){let i=!1;if(n.tool.type===`tool_use`&&n.tool.tool===`Read`){let t=n.tool.input?.file_path;t&&(i=r.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=i||!t}}return(0,Z.jsx)(Z.Fragment,{children:r.map((e,i)=>{if(e.kind===`thinking`)return(0,Z.jsx)(tt,{content:e.content,isStreaming:t&&i===r.length-1},`think-${i}`);if(e.kind===`text`){let a=t&&i===r.length-1;return(0,Z.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,Z.jsx)(nt,{content:e.content,animate:a,projectName:n})},`text-${i}`)}return(0,Z.jsx)(Me,{tool:e.tool,result:e.result,completed:e.completed,projectName:n},`tool-${i}`)})})}function tt({content:e,isStreaming:t}){let[n,r]=(0,q.useState)(t);return(0,q.useEffect)(()=>{!t&&e.length>0&&r(!1)},[t,e.length]),(0,Z.jsxs)(`div`,{className:`rounded border border-border/50 bg-surface/30 text-xs`,children:[(0,Z.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,Z.jsx)(x,{className:`size-3 animate-spin`}):(0,Z.jsx)(E,{className:`size-3 transition-transform ${n?`rotate-90`:``}`}),(0,Z.jsxs)(`span`,{children:[`Thinking`,t?`...`:``]}),!t&&(0,Z.jsx)(`span`,{className:`text-text-subtle/50 ml-auto`,children:e.length>100?`${Math.round(e.length/4)} tokens`:``})]}),n&&(0,Z.jsx)(`div`,{className:`px-2 pb-2 text-text-subtle/80 whitespace-pre-wrap max-h-60 overflow-y-auto text-[11px] leading-relaxed`,children:e})]})}function nt({content:e,animate:t,projectName:n}){return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(it,{content:e,projectName:n}),t&&(0,Z.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function rt({lastMessage:e,streamingStatus:t,elapsed:n,warningThreshold:r=15}){let i=!e||e.role!==`assistant`,a=e?.events?.length?e.events[e.events.length-1].type===`tool_result`:!1;return!i&&!a?null:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-text-subtle`,children:[(0,Z.jsx)(x,{className:`size-3 animate-spin`}),(0,Z.jsxs)(`span`,{children:[`Thinking`,i&&(n??0)>0&&(0,Z.jsxs)(`span`,{className:`text-text-subtle/60`,children:[`... (`,n,`s)`]})]})]}),i&&(n??0)>=r&&(0,Z.jsx)(`p`,{className:`text-xs text-yellow-500/80 ml-5`,children:`Taking longer than usual — may be rate-limited or API slow. Try sending a new message to retry.`})]})}function it({content:e,projectName:t}){return(0,Z.jsx)(L,{content:e,projectName:t,codeActions:!0})}function at({approval:e,onRespond:t}){return(0,Z.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,Z.jsx)(ie,{className:`size-4`}),(0,Z.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,Z.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,Z.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,Z.jsx)(`pre`,{className:`text-xs font-mono text-text-secondary overflow-x-auto bg-background rounded p-2 border border-border`,children:JSON.stringify(e.input,null,2)}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(`button`,{onClick:()=>t(e.requestId,!0),className:`px-4 py-1.5 rounded bg-green-600 text-white text-xs font-medium hover:bg-green-500 transition-colors`,children:`Allow`}),(0,Z.jsx)(`button`,{onClick:()=>t(e.requestId,!1),className:`px-4 py-1.5 rounded bg-red-600 text-white text-xs font-medium hover:bg-red-500 transition-colors`,children:`Deny`})]})]})}function ot({approval:e,onRespond:t}){return(0,Z.jsx)(He,{questions:e.input.questions??[],onSubmit:n=>t(e.requestId,!0,n),onSkip:()=>t(e.requestId,!1)})}var st=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),ct=new Set([`application/pdf`]),lt=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],ut=new Set(`.ts,.tsx,.js,.jsx,.mjs,.cjs,.py,.rb,.go,.rs,.java,.kt,.swift,.c,.cpp,.h,.hpp,.cs,.json,.yaml,.yml,.toml,.xml,.md,.mdx,.txt,.csv,.tsv,.html,.css,.scss,.less,.sass,.sh,.bash,.zsh,.fish,.sql,.graphql,.gql,.env,.ini,.cfg,.conf,.dockerfile,.makefile,.vue,.svelte,.astro,.ipynb`.split(`,`));function dt(e){return st.has(e.type)}function ft(e){if(st.has(e.type)||ct.has(e.type)||lt.some(t=>e.type.startsWith(t)))return!0;let t=pt(e.name);return!!(t&&ut.has(t))}function pt(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function mt({attachments:e,onRemove:t}){return e.length===0?null:(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-2 md:px-4 pt-2`,children:e.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-surface px-2 py-1 text-xs text-text-secondary max-w-48`,children:[e.previewUrl?(0,Z.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,Z.jsx)(U,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,Z.jsx)(T,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,Z.jsx)(x,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,Z.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,Z.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`shrink-0 rounded-sm p-0.5 hover:bg-border/50 transition-colors`,"aria-label":`Remove ${e.name}`,children:(0,Z.jsx)(r,{className:`size-3`})})]},e.id))})}function ht(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&n(r.children)}return n(e),t}function gt({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,q.useState)(0),s=(0,q.useRef)(null),c=(()=>{if(!t)return e.slice(0,50);let n=t.toLowerCase();return e.filter(e=>e.path.toLowerCase().includes(n)||e.name.toLowerCase().includes(n)).slice(0,50)})();(0,q.useEffect)(()=>{o(0)},[t]),(0,q.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,q.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,q.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,Z.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,Z.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,Z.jsxs)(`button`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,Z.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,Z.jsx)(D,{className:`size-4 text-amber-500`}):(0,Z.jsx)(O,{className:`size-4 text-blue-400`})}),(0,Z.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}function _t({onSend:e,isStreaming:t,onCancel:n,disabled:r,projectName:i,onSlashStateChange:a,onSlashItemsLoaded:o,slashSelected:s,onFileStateChange:c,onFileItemsLoaded:l,fileSelected:u,externalFiles:d,initialValue:f}){let[p,m]=(0,q.useState)(f??``),[h,_]=(0,q.useState)([]),x=(0,q.useRef)(null),S=(0,q.useRef)(null),C=(0,q.useRef)(null),w=(0,q.useRef)([]),T=(0,q.useRef)([]);(0,q.useEffect)(()=>{f&&(m(f),setTimeout(()=>{let e=x.current;e&&(e.focus(),e.selectionStart=e.selectionEnd=e.value.length)},50))},[f]),(0,q.useEffect)(()=>{if(!i){w.current=[],o?.([]);return}b.get(`${v(i)}/chat/slash-items`).then(e=>{w.current=e,o?.(e)}).catch(()=>{w.current=[],o?.([])})},[i]),(0,q.useEffect)(()=>{if(!i){T.current=[],l?.([]);return}b.get(`${v(i)}/files/tree?depth=5`).then(e=>{let t=ht(e);T.current=t,l?.(t)}).catch(()=>{T.current=[],l?.([])})},[i]),(0,q.useEffect)(()=>{if(!s)return;let e=x.current,t=e?.selectionStart??p.length,n=p.slice(0,t),r=p.slice(t),i=n.replace(/(?:^|\s)\/\S*$/,e=>`${e.startsWith(`/`)?``:e[0]}/${s.name} `);m(i+r),a?.(!1,``),c?.(!1,``),e&&(e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=i.length},0))},[s]),(0,q.useEffect)(()=>{if(!u)return;let e=x.current;if(!e)return;let t=e.selectionStart,n=p.slice(0,t),r=p.slice(t),i=n.match(/@(\S*)$/);if(i){let t=n.length-i[0].length;m(n.slice(0,t)+`@${u.path} `+r);let a=t+u.path.length+2;setTimeout(()=>{e.selectionStart=e.selectionEnd=a,e.focus()},0)}else{let t=p+`@${u.path} `;m(t),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length,e.focus()},0)}c?.(!1,``)},[u]),(0,q.useEffect)(()=>{!d||d.length===0||D(d)},[d]);let E=(0,q.useCallback)(async e=>{if(!i)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=y();r&&(n.Authorization=`Bearer ${r}`);let a=await(await fetch(`${v(i)}/chat/upload`,{method:`POST`,headers:n,body:t})).json();return a.ok&&Array.isArray(a.data)&&a.data.length>0?a.data[0].path:null}catch{return null}},[i]),D=(0,q.useCallback)(e=>{for(let t of e){if(!ft(t)){m(e=>e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=g(),n=dt(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};_(e=>[...e,i]),E(t).then(t=>{_(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}(S.current??x.current)?.focus()},[E]),O=(0,q.useCallback)(e=>{_(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),k=(0,q.useCallback)(()=>{let t=p.trim(),n=h.filter(e=>e.status===`ready`);if(!(!t&&n.length===0)&&!r){a?.(!1,``),c?.(!1,``),e(t,n),m(``);for(let e of h)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);_([]),x.current&&(x.current.style.height=`auto`),S.current&&(S.current.style.height=`auto`)}},[p,h,r,e,a,c]),A=(0,q.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),k())},[k]),j=(0,q.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.match(/(?:^|\s)\/(\S*)$/);if(r&&w.current.length>0){a?.(!0,r[1]??``),c?.(!1,``);return}let i=n.match(/@(\S*)$/);if(i&&T.current.length>0){c?.(!0,i[1]??``),a?.(!1,``);return}a?.(!1,``),c?.(!1,``)},[a,c]),M=(0,q.useCallback)(e=>{m(e),setTimeout(()=>{j(e,x.current?.selectionStart??e.length)},0)},[j]),N=(0,q.useCallback)(e=>{let t=e?.target??x.current;t&&(t.style.height=`auto`,t.style.height=Math.min(t.scrollHeight,160)+`px`)},[]),P=(0,q.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t)if(e.kind===`file`){let t=e.getAsFile();t&&n.push(t)}n.length>0&&(e.preventDefault(),D(n))},[D]),F=(0,q.useCallback)(e=>{e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length>0&&D(t)},[D]),I=(0,q.useCallback)(e=>{e.preventDefault()},[]),L=(0,q.useCallback)(()=>{C.current?.click()},[]),R=(0,q.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&D(t),e.target.value=``},[D]),B=p.trim().length>0||h.some(e=>e.status===`ready`),V=t&&!B;return(0,Z.jsxs)(`div`,{className:`p-2 md:p-3 bg-background`,children:[(0,Z.jsxs)(`div`,{className:`border border-border rounded-xl md:rounded-2xl bg-surface shadow-sm cursor-text`,onClick:()=>!r&&(S.current??x.current)?.focus(),children:[(0,Z.jsx)(mt,{attachments:h,onRemove:O}),(0,Z.jsxs)(`div`,{className:`flex items-end gap-1 md:hidden px-2 py-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),L()},disabled:r,className:`flex items-center justify-center size-7 shrink-0 rounded-full text-text-subtle hover:text-text-primary transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,Z.jsx)(W,{className:`size-4`})}),(0,Z.jsx)(`textarea`,{ref:S,value:p,onChange:e=>{M(e.target.value),N(e)},onKeyDown:A,onPaste:P,onDrop:F,onDragOver:I,placeholder:t?`Follow-up...`:`Ask anything...`,disabled:r,rows:1,className:`flex-1 resize-none bg-transparent py-1.5 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-20`}),V?(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop`,children:(0,Z.jsx)(K,{className:`size-3`})}):(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),k()},disabled:r||!B,className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 transition-colors`,"aria-label":`Send`,children:(0,Z.jsx)(z,{className:`size-3.5`})})]}),(0,Z.jsxs)(`div`,{className:`hidden md:block`,children:[(0,Z.jsx)(`textarea`,{ref:x,value:p,onChange:e=>{M(e.target.value),N(e)},onKeyDown:A,onPaste:P,onDrop:F,onDragOver:I,placeholder:t?`Follow-up or Stop...`:`Ask anything...`,disabled:r,rows:1,className:`w-full resize-none bg-transparent px-4 pt-3 pb-1 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-40`}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),L()},disabled:r,className:`flex items-center justify-center size-8 rounded-full text-text-subtle hover:text-text-primary hover:bg-surface-elevated transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,Z.jsx)(W,{className:`size-4`})})}),(0,Z.jsx)(`div`,{className:`flex items-center gap-1`,children:V?(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-8 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop response`,children:(0,Z.jsx)(K,{className:`size-3.5`})}):(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),k()},disabled:r||!B,className:`flex items-center justify-center size-8 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":`Send message`,children:(0,Z.jsx)(z,{className:`size-4`})})})]})]})]}),(0,Z.jsx)(`input`,{ref:C,type:`file`,multiple:!0,className:`hidden`,onChange:R})]})}function vt({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,q.useState)(0),s=(0,q.useRef)(null),c=e.filter(e=>{let n=t.toLowerCase();return e.name.toLowerCase().includes(n)||e.description.toLowerCase().includes(n)});(0,q.useEffect)(()=>{o(0)},[t]),(0,q.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,q.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,q.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,Z.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,Z.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,Z.jsxs)(`button`,{className:`flex items-start gap-3 w-full px-3 py-2 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,Z.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`skill`?(0,Z.jsx)(G,{className:`size-4 text-amber-500`}):(0,Z.jsx)(I,{className:`size-4 text-blue-500`})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Z.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,Z.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,Z.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`user`?`global`:e.type})]}),e.description&&(0,Z.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]},`${e.type}-${e.name}`))})})}function yt(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function bt(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function xt(e){if(!e)return null;let t=null;if(e.resetsInMinutes!=null)t=e.resetsInMinutes;else if(e.resetsInHours!=null)t=Math.round(e.resetsInHours*60);else if(e.resetsAt){let n=new Date(e.resetsAt).getTime()-Date.now();t=n>0?Math.ceil(n/6e4):0}if(t==null)return null;if(t<=0)return`now`;let n=Math.floor(t/1440),r=Math.floor(t%1440/60),i=t%60;return n>0?i>0?`${n}d ${r}h ${i}m`:r>0?`${n}d ${r}h`:`${n}d`:r>0?i>0?`${r}h ${i}m`:`${r}h`:`${i}m`}function $({label:e,bucket:t}){if(!t)return null;let n=Math.round(t.utilization*100),r=xt(t);return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,Z.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,children:[`↻ `,r]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full transition-all ${bt(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,Z.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${yt(n)}`,children:[n,`%`]})]})]})}function St(e){if(!e)return null;let t=Math.round((Date.now()-e)/1e3);return t<5?`just now`:t<60?`${t}s ago`:`${Math.floor(t/60)}m ago`}function Ct({entry:e,isActive:t}){let{usage:n}=e,r=n.session||n.weekly||n.weeklyOpus||n.weeklySonnet;return(0,Z.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5 ${t?`border-primary/30 bg-primary/5`:`border-border/50`}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium truncate flex-1 min-w-0`,children:e.accountLabel??e.accountId.slice(0,8)}),t&&(0,Z.jsx)(`span`,{className:`text-[9px] px-1 py-0 rounded bg-primary/20 text-primary font-medium shrink-0`,children:`In use`}),!e.isOAuth&&(0,Z.jsx)(`span`,{className:`text-[9px] text-text-subtle shrink-0`,children:`API key`}),e.accountStatus===`disabled`&&(0,Z.jsx)(`span`,{className:`text-[9px] text-text-subtle shrink-0`,children:`disabled`})]}),r?(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)($,{label:`5-Hour Session`,bucket:n.session}),(0,Z.jsx)($,{label:`Weekly`,bucket:n.weekly}),(0,Z.jsx)($,{label:`Weekly (Opus)`,bucket:n.weeklyOpus}),(0,Z.jsx)($,{label:`Weekly (Sonnet)`,bucket:n.weeklySonnet})]}):(0,Z.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:e.isOAuth?`No usage data yet`:`Usage tracking not available for API keys`}),n.lastFetchedAt&&(0,Z.jsxs)(`p`,{className:`text-[9px] text-text-subtle`,children:[`Updated: `,St(new Date(n.lastFetchedAt).getTime())]})]})}function wt({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastFetchedAt:a}){let[o,c]=(0,q.useState)([]),[l,u]=(0,q.useState)(!1);if((0,q.useEffect)(()=>{t&&(u(!0),s().then(c).catch(()=>{}).finally(()=>u(!1)))},[t]),!t)return null;let d=e.queryCostUsd!=null||e.totalCostUsd!=null,f=o.length>0;return(0,Z.jsxs)(`div`,{className:`border-b border-border bg-surface px-3 py-2.5 space-y-2.5 max-h-[350px] overflow-y-auto`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage Limits`}),a&&(0,Z.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:St(new Date(a).getTime())})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r&&(0,Z.jsx)(`button`,{onClick:r,disabled:i,className:`text-xs text-text-subtle hover:text-text-primary px-1 disabled:opacity-50`,title:`Refresh usage data`,children:(0,Z.jsx)(w,{className:`size-3 ${i?`animate-spin`:``}`})}),(0,Z.jsx)(`button`,{onClick:n,className:`text-xs text-text-subtle hover:text-text-primary px-1`,children:`✕`})]})]}),f?(0,Z.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-1.5`,children:l?(0,Z.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`Loading accounts...`}):o.map(t=>(0,Z.jsx)(Ct,{entry:t,isActive:t.accountId===e.activeAccountId},t.accountId))}):(0,Z.jsx)(Z.Fragment,{children:e.session||e.weekly||e.weeklyOpus||e.weeklySonnet?(0,Z.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,Z.jsx)($,{label:`5-Hour Session`,bucket:e.session}),(0,Z.jsx)($,{label:`Weekly`,bucket:e.weekly}),(0,Z.jsx)($,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,Z.jsx)($,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,Z.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`No usage data available`})}),d&&(0,Z.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,Z.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,Z.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]})]})}function Tt(e){try{return new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}catch{return``}}function Et(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function Dt({projectName:e,usageInfo:t,contextWindowPct:n,usageLoading:i,refreshUsage:a,lastFetchedAt:s,sessionId:u,onSelectSession:d,onBugReport:f,isConnected:p,onReconnect:h}){let[g,_]=(0,q.useState)(null),[y,S]=(0,q.useState)([]),[T,E]=(0,q.useState)(!1),D=M(e=>u?e.notifications.has(u):!1),O=M(e=>e.clearForSession),[k,j]=(0,q.useState)(``),[N,F]=(0,q.useState)(null),[I,L]=(0,q.useState)(``),z=(0,q.useRef)(null),B=m(e=>e.openTab),V=e=>{_(t=>t===e?null:e)},H=(0,q.useCallback)(async()=>{if(e){E(!0);try{S(await b.get(`${v(e)}/chat/sessions`))}catch{}finally{E(!1)}}},[e]);(0,q.useEffect)(()=>{g===`history`&&y.length===0&&H()},[g]);function ee(t){d?(d(t),_(null)):B({type:`chat`,title:t.title||`Chat`,projectId:e??null,metadata:{projectName:e,sessionId:t.id},closable:!0})}let U=(0,q.useCallback)((e,t)=>{t.stopPropagation(),F(e.id),L(e.title||``),setTimeout(()=>z.current?.select(),0)},[]),ne=(0,q.useCallback)(async()=>{if(!N||!I.trim()||!e){F(null);return}try{await b.patch(`${v(e)}/chat/sessions/${N}`,{title:I.trim()}),S(e=>e.map(e=>e.id===N?{...e,title:I.trim()}:e))}catch{}F(null)},[N,I,e]),W=(0,q.useCallback)(()=>F(null),[]),ie=k.trim()?y.filter(e=>(e.title||``).toLowerCase().includes(k.toLowerCase())):y,G=t.fiveHour==null?null:Math.round(t.fiveHour*100),K=t.sevenDay==null?null:Math.round(t.sevenDay*100),J=G!=null||K!=null?Et(Math.max(G??0,K??0)):`text-text-subtle`;return(0,Z.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,Z.jsxs)(`button`,{onClick:()=>V(`history`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${g===`history`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,children:[(0,Z.jsx)(te,{className:`size-3`}),(0,Z.jsx)(`span`,{children:`History`})]}),(0,Z.jsx)(`button`,{onClick:()=>V(`config`),className:`p-1 rounded transition-colors ${g===`config`?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary hover:bg-surface-elevated`}`,title:`AI Settings`,children:(0,Z.jsx)(re,{className:`size-3`})}),(0,Z.jsxs)(`button`,{onClick:()=>V(`usage`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] font-medium tabular-nums transition-colors hover:bg-surface-elevated ${g===`usage`?`bg-primary/10`:``} ${J}`,title:`Usage limits`,children:[(0,Z.jsx)(R,{className:`size-3`}),t.activeAccountLabel&&(0,Z.jsxs)(`span`,{className:`text-text-secondary font-normal truncate max-w-[60px]`,children:[`[`,t.activeAccountLabel,`]`]}),(0,Z.jsxs)(`span`,{children:[`5h:`,G==null?`--%`:`${G}%`]}),(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,Z.jsxs)(`span`,{children:[`Wk:`,K==null?`--%`:`${K}%`]}),n!=null&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,Z.jsxs)(`span`,{className:Et(n),children:[`Ctx:`,n,`%`]})]})]}),(0,Z.jsx)(`div`,{className:`flex-1`}),D&&u&&(0,Z.jsx)(`button`,{onClick:()=>O(u),className:`p-1 rounded text-amber-500 hover:text-amber-400 hover:bg-surface-elevated transition-colors`,title:`Mark as read`,children:(0,Z.jsx)(l,{className:`size-3`})}),h&&(0,Z.jsx)(`button`,{onClick:h,className:`size-4 flex items-center justify-center`,title:p?`Connected`:`Disconnected — click to reconnect`,children:(0,Z.jsx)(`span`,{className:`size-2 rounded-full ${p?`bg-green-500`:`bg-red-500 animate-pulse`}`})})]}),g===`history`&&(0,Z.jsxs)(`div`,{className:`border-t border-border/30 bg-surface`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 border-b border-border/30`,children:[(0,Z.jsx)(A,{className:`size-3 text-text-subtle shrink-0`}),(0,Z.jsx)(`input`,{type:`text`,value:k,onChange:e=>j(e.target.value),placeholder:`Search sessions...`,className:`flex-1 bg-transparent text-[11px] text-text-primary outline-none placeholder:text-text-subtle`}),(0,Z.jsx)(`button`,{onClick:H,disabled:T,className:`p-0.5 rounded text-text-subtle hover:text-text-secondary transition-colors disabled:opacity-50`,title:`Refresh`,children:(0,Z.jsx)(w,{className:`size-3 ${T?`animate-spin`:``}`})})]}),(0,Z.jsx)(`div`,{className:`max-h-[200px] overflow-y-auto`,children:T&&y.length===0?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,Z.jsx)(x,{className:`size-3.5 animate-spin text-text-subtle`})}):ie.length===0?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-3 text-[11px] text-text-subtle`,children:k?`No matching sessions`:`No sessions yet`}):ie.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left hover:bg-surface-elevated transition-colors group`,children:[(0,Z.jsx)(P,{className:`size-3 shrink-0 text-text-subtle`}),N===e.id?(0,Z.jsxs)(`form`,{className:`flex items-center gap-1 flex-1 min-w-0`,onSubmit:e=>{e.preventDefault(),ne()},children:[(0,Z.jsx)(`input`,{ref:z,value:I,onChange:e=>L(e.target.value),onBlur:ne,onKeyDown:e=>{e.key===`Escape`&&W()},className:`flex-1 min-w-0 bg-surface-elevated text-[11px] text-text-primary px-1 py-0.5 rounded border border-border outline-none focus:border-primary`,autoFocus:!0}),(0,Z.jsx)(`button`,{type:`submit`,className:`p-0.5 text-green-500 hover:text-green-400`,onClick:e=>e.stopPropagation(),children:(0,Z.jsx)(o,{className:`size-3`})}),(0,Z.jsx)(`button`,{type:`button`,className:`p-0.5 text-text-subtle hover:text-text-secondary`,onClick:e=>{e.stopPropagation(),W()},children:(0,Z.jsx)(r,{className:`size-3`})})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{onClick:()=>ee(e),className:`text-[11px] truncate flex-1 text-left`,children:e.title||`Untitled`}),(0,Z.jsx)(`button`,{onClick:t=>U(e,t),className:`p-0.5 rounded text-text-subtle hover:text-text-secondary opacity-0 group-hover:opacity-100 transition-opacity`,title:`Rename session`,children:(0,Z.jsx)(C,{className:`size-3`})})]}),N!==e.id&&e.updatedAt&&(0,Z.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:Tt(e.updatedAt)})]},e.id))})]}),g===`config`&&(0,Z.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2 max-h-[280px] overflow-y-auto`,children:(0,Z.jsx)(c,{compact:!0})}),g===`usage`&&(0,Z.jsx)(wt,{usage:t,visible:!0,onClose:()=>_(null),onReload:a,loading:i,lastFetchedAt:s})]})}function Ot({metadata:e,tabId:t}){let[n,r]=(0,q.useState)(e?.sessionId??null),[i,a]=(0,q.useState)(e?.providerId??`claude`),[o,s]=(0,q.useState)([]),[c,l]=(0,q.useState)(!1),[u,d]=(0,q.useState)(``),[f,g]=(0,q.useState)(null),[_,y]=(0,q.useState)([]),[x,S]=(0,q.useState)(!1),[C,w]=(0,q.useState)(``),[T,E]=(0,q.useState)(null),[D,O]=(0,q.useState)(!1),[A,j]=(0,q.useState)(null),P=(0,q.useRef)(0),I=e?.projectName??``,L=m(e=>e.updateTab),R=h(e=>e.version),{usageInfo:z,usageLoading:B,lastFetchedAt:V,refreshUsage:H}=_e(I,i);(0,q.useEffect)(()=>{!t||!n||L(t,{metadata:{...e,sessionId:n,providerId:i}})},[n,i]);let{messages:ee,messagesLoading:te,isStreaming:U,streamingStatus:ne,connectingElapsed:W,thinkingWarningThreshold:re,pendingApproval:ie,contextWindowPct:G,sessionTitle:K,sendMessage:J,respondToApproval:ae,cancelStreaming:oe,reconnect:se,refetchMessages:ce,isConnected:Y}=he(n,i,I);(0,q.useEffect)(()=>{if(!n||!t)return;let e=()=>{if(document.hidden)return;let{panels:e,focusedPanelId:r}=p.getState();e[r]?.activeTabId===t&&M.getState().clearForSession(n)};e(),document.addEventListener(`visibilitychange`,e);let r=p.subscribe(e);return()=>{document.removeEventListener(`visibilitychange`,e),r()}},[n,t]),(0,q.useEffect)(()=>{t&&K&&L(t,{title:K})},[K]);let X=(0,q.useRef)(e?.pendingMessage);(0,q.useEffect)(()=>{if(X.current&&Y&&n){let n=X.current;X.current=void 0,t&&L(t,{metadata:{...e,pendingMessage:void 0}}),setTimeout(()=>J(n),100)}},[Y,n]),(0,q.useCallback)(()=>{m.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:I},projectId:I||null,closable:!0})},[I]);let le=(0,q.useCallback)(e=>{r(e.id),a(e.providerId),t&&L(t,{title:e.title||`Chat`})},[t,L]),ue=(0,q.useCallback)(async e=>{if(!(!n||!I))try{let{api:t,projectUrl:r}=await N(async()=>{let{api:e,projectUrl:t}=await import(`./api-client-TUmacMRS.js`).then(e=>e.n);return{api:e,projectUrl:t}},__vite__mapDeps([0,1])),a=await t.post(`${r(I)}/chat/sessions/${n}/fork?providerId=${i}`);m.getState().openTab({type:`chat`,title:`Fork: ${e.slice(0,30)}`,metadata:{projectName:I,sessionId:a.id,providerId:i,pendingMessage:e},projectId:I||null,closable:!0})}catch(e){console.error(`Fork failed:`,e)}},[n,I,i]),de=(0,q.useCallback)((e,t)=>{if(t.length===0)return e;let n=t.filter(e=>e.serverPath).map(e=>e.serverPath).join(`
7
+ `);return n?(t.length===1?`[Attached file: ${n}]\n\n`:`[Attached files:\n${n}\n]\n\n`)+e:e},[]),fe=(0,q.useCallback)(async(e,t=[])=>{let o=de(e,t);if(o.trim()){if(!n)try{let t=I,n=await b.post(`${v(t)}/chat/sessions`,{providerId:i,title:e.slice(0,50)});r(n.id),a(n.providerId),setTimeout(()=>{J(o)},500);return}catch(e){console.error(`Failed to create session:`,e);return}J(o)}},[n,i,I,J,de]),pe=(0,q.useCallback)((e,t)=>{l(e),d(t)},[]),me=(0,q.useCallback)(e=>{g(e),l(!1),d(``),setTimeout(()=>g(null),50)},[]),ge=(0,q.useCallback)(()=>{l(!1),d(``)},[]),ve=(0,q.useCallback)((e,t)=>{S(e),w(t)},[]),ye=(0,q.useCallback)(e=>{E(e),S(!1),w(``),setTimeout(()=>E(null),50)},[]),be=(0,q.useCallback)(()=>{S(!1),w(``)},[]);return(0,Z.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,q.useCallback)(e=>{e.preventDefault(),P.current++,e.dataTransfer.types.includes(`Files`)&&O(!0)},[]),onDragLeave:(0,q.useCallback)(e=>{e.preventDefault(),P.current--,P.current===0&&O(!1)},[]),onDragOver:(0,q.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,q.useCallback)(e=>{e.preventDefault(),P.current=0,O(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&(j(t),setTimeout(()=>j(null),100))},[]),children:[D&&(0,Z.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm border-2 border-dashed border-primary rounded-lg pointer-events-none`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-primary`,children:[(0,Z.jsx)(k,{className:`size-8`}),(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),(0,Z.jsx)(Ue,{messages:ee,messagesLoading:te,pendingApproval:ie,onApprovalResponse:ae,isStreaming:U,streamingStatus:ne,connectingElapsed:W,thinkingWarningThreshold:re,projectName:I,onFork:U?void 0:ue}),(0,Z.jsxs)(`div`,{className:`border-t border-border bg-background shrink-0`,children:[(0,Z.jsx)(Dt,{projectName:I,usageInfo:z,contextWindowPct:G,usageLoading:B,refreshUsage:H,lastFetchedAt:V,sessionId:n,onSelectSession:le,onBugReport:n?()=>F(R,{sessionId:n,projectName:I}):void 0,isConnected:Y,onReconnect:()=>{Y||se(),ce()}}),(0,Z.jsx)(vt,{items:o,filter:u,onSelect:me,onClose:ge,visible:c}),(0,Z.jsx)(gt,{items:_,filter:C,onSelect:ye,onClose:be,visible:x}),(0,Z.jsx)(_t,{onSend:fe,isStreaming:U,onCancel:oe,projectName:I,onSlashStateChange:pe,onSlashItemsLoaded:s,slashSelected:f,onFileStateChange:ve,onFileItemsLoaded:y,fileSelected:T,externalFiles:A})]})]})}export{Ot as ChatTab};
@@ -1 +1 @@
1
- import{i as e,t}from"./react-CYzKIDNi.js";import{n,t as r}from"./jsx-runtime-wQxeESYQ.js";import{a as i,t as a}from"./tab-store-0CKk8cSr.js";import{n as o}from"./settings-store-2NQzaOVJ.js";import{t as s}from"./utils-DC-bdPS3.js";import{i as c,r as l,t as u}from"./api-client-TUmacMRS.js";import{j as d}from"./index-DaQYRomz.js";import{t as f}from"./markdown-renderer-Xe_wjdJH.js";import{n as p,t as m}from"./use-monaco-theme-Bt1Lr3jH.js";var h=n(`file-exclamation-point`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),g=e(t(),1),_=r(),v=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),y=new Set([`db`,`sqlite`,`sqlite3`]);function b(e){return e.split(`.`).pop()?.toLowerCase()??``}function x(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`}[b(e)]??`plaintext`}function S({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,[i,l]=(0,g.useState)(null),[f,S]=(0,g.useState)(`utf-8`),[E,D]=(0,g.useState)(!0),[O,k]=(0,g.useState)(null),[A,j]=(0,g.useState)(!1),M=(0,g.useRef)(null),N=(0,g.useRef)(``),P=(0,g.useRef)(null),{tabs:F,updateTab:I}=a(),{wordWrap:L,toggleWordWrap:R}=o(),z=m(),B=F.find(e=>e.id===t),V=n?b(n):``,H=v.has(V),U=V===`pdf`,W=y.has(V),G=V===`md`||V===`mdx`,[K,q]=(0,g.useState)(`preview`);(0,g.useEffect)(()=>{W&&t&&I(t,{type:`sqlite`})},[W,t,I]);let J=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,g.useEffect)(()=>{if(!n||!J&&!r)return;if(H||U){D(!1);return}D(!0),k(null);let e=J?`/api/fs/read?path=${encodeURIComponent(n)}`:`${c(r)}/files/read?path=${encodeURIComponent(n)}`;return u.get(e).then(e=>{l(e.content),e.encoding&&S(e.encoding),N.current=e.content,D(!1)}).catch(e=>{k(e instanceof Error?e.message:`Failed to load file`),D(!1)}),()=>{M.current&&clearTimeout(M.current)}},[n,r,H,U,J]),(0,g.useEffect)(()=>{if(!B)return;let e=n?s(n):`Untitled`,t=A?`${e} \u25CF`:e;B.title!==t&&I(B.id,{title:t})},[A]);let Y=(0,g.useCallback)(async e=>{if(n&&!(!J&&!r))try{J?await u.put(`/api/fs/write`,{path:n,content:e}):await u.put(`${c(r)}/files/write`,{path:n,content:e}),j(!1)}catch{}},[n,r,J]);function X(e){let t=e??``;l(t),N.current=t,j(!0),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>Y(N.current),1e3)}let Z=e?.lineNumber,Q=(0,g.useCallback)((e,t)=>{P.current=e,Z&&Z>0&&setTimeout(()=>{e.revealLineInCenter(Z),e.setPosition({lineNumber:Z,column:1}),e.focus()},100),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>o.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0})},[]);return!n||!J&&!r?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`}):E?(0,_.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,_.jsx)(d,{className:`size-5 animate-spin`}),(0,_.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]}):O?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:O}):H?(0,_.jsx)(w,{filePath:n,projectName:r}):U?(0,_.jsx)(T,{filePath:n,projectName:r}):f===`base64`?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,_.jsx)(h,{className:`size-10 text-text-subtle`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,_.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]}):(0,_.jsx)(`div`,{className:`flex flex-col h-full w-full overflow-hidden`,children:G&&K===`preview`?(0,_.jsx)(C,{content:i??``}):(0,_.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,_.jsx)(p,{height:`100%`,language:x(n),value:i??``,onChange:X,onMount:Q,theme:z,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:L?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0}},loading:(0,_.jsx)(d,{className:`size-5 animate-spin text-text-subtle`})})})})}function C({content:e}){return(0,_.jsx)(f,{content:e,className:`flex-1 overflow-auto p-4`})}function w({filePath:e,projectName:t}){let[n,r]=(0,g.useState)(null),[i,a]=(0,g.useState)(!1);return(0,g.useEffect)(()=>{let n,i=`${c(t)}/files/raw?path=${encodeURIComponent(e)}`,o=l();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(e);n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]),i?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,_.jsx)(h,{className:`size-10 text-text-subtle`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`Failed to load image.`})]}):n?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full p-4 bg-surface overflow-auto`,children:(0,_.jsx)(`img`,{src:n,alt:e,className:`max-w-full max-h-full object-contain`})}):(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,_.jsx)(d,{className:`size-5 animate-spin text-text-subtle`})})}function T({filePath:e,projectName:t}){let[n,r]=(0,g.useState)(null),[a,o]=(0,g.useState)(!1);(0,g.useEffect)(()=>{let n,i=`${c(t)}/files/raw?path=${encodeURIComponent(e)}`,a=l();return fetch(i,{headers:a?{Authorization:`Bearer ${a}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(new Blob([e],{type:`application/pdf`}));n=t,r(t)}).catch(()=>o(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]);let s=(0,g.useCallback)(()=>{n&&window.open(n,`_blank`)},[n]);return a?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,_.jsx)(h,{className:`size-10 text-text-subtle`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`Failed to load PDF.`})]}):n?(0,_.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,_.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,_.jsx)(`span`,{className:`text-xs text-text-secondary truncate`,children:e}),(0,_.jsxs)(`button`,{onClick:s,className:`flex items-center gap-1 text-xs text-text-secondary hover:text-text-primary transition-colors`,children:[(0,_.jsx)(i,{className:`size-3`}),` Open in new tab`]})]}),(0,_.jsx)(`iframe`,{src:n,title:e,className:`flex-1 w-full border-none`})]}):(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,_.jsx)(d,{className:`size-5 animate-spin text-text-subtle`})})}export{S as CodeEditor};
1
+ import{i as e,t}from"./react-CYzKIDNi.js";import{n,t as r}from"./jsx-runtime-wQxeESYQ.js";import{a as i,t as a}from"./tab-store-0CKk8cSr.js";import{n as o}from"./settings-store-2NQzaOVJ.js";import{t as s}from"./utils-DC-bdPS3.js";import{i as c,r as l,t as u}from"./api-client-TUmacMRS.js";import{A as d}from"./index-qElHXk-7.js";import{t as f}from"./markdown-renderer-DpIu7iOT.js";import{n as p,t as m}from"./use-monaco-theme-Bt1Lr3jH.js";var h=n(`file-exclamation-point`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),g=e(t(),1),_=r(),v=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),y=new Set([`db`,`sqlite`,`sqlite3`]);function b(e){return e.split(`.`).pop()?.toLowerCase()??``}function x(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`}[b(e)]??`plaintext`}function S({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,[i,l]=(0,g.useState)(null),[f,S]=(0,g.useState)(`utf-8`),[E,D]=(0,g.useState)(!0),[O,k]=(0,g.useState)(null),[A,j]=(0,g.useState)(!1),M=(0,g.useRef)(null),N=(0,g.useRef)(``),P=(0,g.useRef)(null),{tabs:F,updateTab:I}=a(),{wordWrap:L,toggleWordWrap:R}=o(),z=m(),B=F.find(e=>e.id===t),V=n?b(n):``,H=v.has(V),U=V===`pdf`,W=y.has(V),G=V===`md`||V===`mdx`,[K,q]=(0,g.useState)(`preview`);(0,g.useEffect)(()=>{W&&t&&I(t,{type:`sqlite`})},[W,t,I]);let J=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,g.useEffect)(()=>{if(!n||!J&&!r)return;if(H||U){D(!1);return}D(!0),k(null);let e=J?`/api/fs/read?path=${encodeURIComponent(n)}`:`${c(r)}/files/read?path=${encodeURIComponent(n)}`;return u.get(e).then(e=>{l(e.content),e.encoding&&S(e.encoding),N.current=e.content,D(!1)}).catch(e=>{k(e instanceof Error?e.message:`Failed to load file`),D(!1)}),()=>{M.current&&clearTimeout(M.current)}},[n,r,H,U,J]),(0,g.useEffect)(()=>{if(!B)return;let e=n?s(n):`Untitled`,t=A?`${e} \u25CF`:e;B.title!==t&&I(B.id,{title:t})},[A]);let Y=(0,g.useCallback)(async e=>{if(n&&!(!J&&!r))try{J?await u.put(`/api/fs/write`,{path:n,content:e}):await u.put(`${c(r)}/files/write`,{path:n,content:e}),j(!1)}catch{}},[n,r,J]);function X(e){let t=e??``;l(t),N.current=t,j(!0),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>Y(N.current),1e3)}let Z=e?.lineNumber,Q=(0,g.useCallback)((e,t)=>{P.current=e,Z&&Z>0&&setTimeout(()=>{e.revealLineInCenter(Z),e.setPosition({lineNumber:Z,column:1}),e.focus()},100),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>o.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0})},[]);return!n||!J&&!r?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`}):E?(0,_.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,_.jsx)(d,{className:`size-5 animate-spin`}),(0,_.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]}):O?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:O}):H?(0,_.jsx)(w,{filePath:n,projectName:r}):U?(0,_.jsx)(T,{filePath:n,projectName:r}):f===`base64`?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,_.jsx)(h,{className:`size-10 text-text-subtle`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,_.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]}):(0,_.jsx)(`div`,{className:`flex flex-col h-full w-full overflow-hidden`,children:G&&K===`preview`?(0,_.jsx)(C,{content:i??``}):(0,_.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,_.jsx)(p,{height:`100%`,language:x(n),value:i??``,onChange:X,onMount:Q,theme:z,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:L?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0}},loading:(0,_.jsx)(d,{className:`size-5 animate-spin text-text-subtle`})})})})}function C({content:e}){return(0,_.jsx)(f,{content:e,className:`flex-1 overflow-auto p-4`})}function w({filePath:e,projectName:t}){let[n,r]=(0,g.useState)(null),[i,a]=(0,g.useState)(!1);return(0,g.useEffect)(()=>{let n,i=`${c(t)}/files/raw?path=${encodeURIComponent(e)}`,o=l();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(e);n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]),i?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,_.jsx)(h,{className:`size-10 text-text-subtle`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`Failed to load image.`})]}):n?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full p-4 bg-surface overflow-auto`,children:(0,_.jsx)(`img`,{src:n,alt:e,className:`max-w-full max-h-full object-contain`})}):(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,_.jsx)(d,{className:`size-5 animate-spin text-text-subtle`})})}function T({filePath:e,projectName:t}){let[n,r]=(0,g.useState)(null),[a,o]=(0,g.useState)(!1);(0,g.useEffect)(()=>{let n,i=`${c(t)}/files/raw?path=${encodeURIComponent(e)}`,a=l();return fetch(i,{headers:a?{Authorization:`Bearer ${a}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(new Blob([e],{type:`application/pdf`}));n=t,r(t)}).catch(()=>o(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]);let s=(0,g.useCallback)(()=>{n&&window.open(n,`_blank`)},[n]);return a?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,_.jsx)(h,{className:`size-10 text-text-subtle`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`Failed to load PDF.`})]}):n?(0,_.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,_.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,_.jsx)(`span`,{className:`text-xs text-text-secondary truncate`,children:e}),(0,_.jsxs)(`button`,{onClick:s,className:`flex items-center gap-1 text-xs text-text-secondary hover:text-text-primary transition-colors`,children:[(0,_.jsx)(i,{className:`size-3`}),` Open in new tab`]})]}),(0,_.jsx)(`iframe`,{src:n,title:e,className:`flex-1 w-full border-none`})]}):(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,_.jsx)(d,{className:`size-5 animate-spin text-text-subtle`})})}export{S as CodeEditor};
@@ -1 +1 @@
1
- import{i as e,t}from"./react-CYzKIDNi.js";import{t as n}from"./jsx-runtime-wQxeESYQ.js";import{a as r,c as i,i as a,n as o,o as s,r as c,s as l,t as u}from"./dist-D9RHR8A4.js";import{t as d}from"./api-client-TUmacMRS.js";import{D as f,R as p,U as m,W as h,j as g}from"./index-DaQYRomz.js";var _=e(t(),1);function v(e,t,n,r){return`ppm-db-${e}-${n}.${t}-p${r}`}function y(e,t,n,r){try{let i=sessionStorage.getItem(v(e,t,n,r));return i?JSON.parse(i):null}catch{return null}}function b(e,t,n,r,i,a){try{sessionStorage.setItem(v(e,t,n,r),JSON.stringify({data:i,cols:a}))}catch{}}function x(e){let t=`/api/db/connections/${e}`,[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(`public`),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)([]),[u,f]=(0,_.useState)(!0),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(1),[v,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(!1),E=(0,_.useCallback)(async(r,a,o)=>{let c=r??n,u=a??i;if(c){f(!0);try{let[n,r]=await Promise.all([d.get(`${t}/data?table=${encodeURIComponent(c)}&schema=${u}&page=${o??h}&limit=100`),d.get(`${t}/schema?table=${encodeURIComponent(c)}&schema=${u}`)]);s(n),l(r),b(e,c,u,o??h,n,r)}catch(e){m(e.message)}finally{f(!1)}}},[t,e,n,i,h]);return{selectedTable:n,selectTable:(0,_.useCallback)((t,n=`public`)=>{r(t),a(n),g(1),x(null);let i=y(e,t,n,1);i?(s(i.data),l(i.cols),f(!1),E(t,n,1)):E(t,n,1)},[e,E]),tableData:o,schema:c,loading:u,error:p,page:h,setPage:(0,_.useCallback)(e=>{g(e),E(void 0,void 0,e)},[E]),queryResult:v,queryError:S,queryLoading:w,executeQuery:(0,_.useCallback)(async e=>{T(!0),C(null);try{let r=await d.post(`${t}/query`,{sql:e});x(r),r.changeType===`modify`&&E(n??void 0,i)}catch(e){C(e.message)}finally{T(!1)}},[t,n,i,E]),updateCell:(0,_.useCallback)(async(e,r,a,o)=>{if(!n)return;let s=n,c=i;try{await d.put(`${t}/cell`,{table:s,schema:c,pkColumn:e,pkValue:r,column:a,value:o}),E(s,c)}catch(e){m(e.message)}},[t,n,i,E]),refreshData:E}}var S=n(),C={postgres:u,sqlite:o};function w({metadata:e}){let t=e?.connectionId,n=e?.connectionName,r=e?.dbType??`postgres`,i=e?.tableName,a=e?.schemaName??`public`,o=x(t),[s,c]=(0,_.useState)(!1),l=(0,_.useRef)(!1);return(0,_.useEffect)(()=>{!i||l.current||(l.current=!0,o.selectTable(i,a))},[i,a]),(0,S.jsx)(`div`,{className:`flex h-full w-full overflow-hidden`,children:(0,S.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,S.jsx)(p,{className:`size-3.5 text-muted-foreground`}),(0,S.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:n??`Database`}),o.selectedTable&&(0,S.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,o.selectedTable]}),(0,S.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,S.jsx)(`button`,{type:`button`,onClick:()=>o.refreshData(),title:`Reload data`,className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,S.jsx)(f,{className:`size-3 ${o.loading?`animate-spin`:``}`})}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`px-2 py-1 rounded text-xs transition-colors ${s?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:`SQL`})]})]}),(0,S.jsx)(`div`,{className:`flex-1 overflow-hidden ${s?`max-h-[60%]`:``}`,children:(0,S.jsx)(T,{tableData:o.tableData,schema:o.schema,loading:o.loading,page:o.page,onPageChange:o.setPage,onCellUpdate:o.updateCell})}),s&&(0,S.jsx)(`div`,{className:`border-t border-border h-[40%] shrink-0`,children:(0,S.jsx)(E,{dialect:C[r]??u,onExecute:o.executeQuery,result:o.queryResult,error:o.queryError,loading:o.queryLoading})})]})})}function T({tableData:e,schema:t,loading:n,page:i,onPageChange:a,onCellUpdate:o}){let[c,u]=(0,_.useState)(null),[d,f]=(0,_.useState)(``),p=(0,_.useMemo)(()=>t.find(e=>e.pk)?.name??null,[t]),v=(0,_.useCallback)((e,t,n)=>{u({rowIdx:e,col:t}),f(n==null?``:String(n))},[]),y=(0,_.useCallback)(()=>{if(!c||!e||!p)return;let t=e.rows[c.rowIdx];if(!t)return;let n=t[c.col];String(n??``)!==d&&o(p,t[p],c.col,d===``?null:d),u(null)},[c,d,e,p,o]),b=(0,_.useCallback)(()=>u(null),[]),x=(0,_.useMemo)(()=>(e?.columns??[]).map(e=>({id:e,accessorFn:t=>t[e],header:()=>(0,S.jsx)(`span`,{className:t.find(t=>t.name===e)?.pk?`font-bold`:``,children:e}),cell:({row:t,getValue:n})=>{let r=c?.rowIdx===t.index&&c?.col===e,i=n();return r?(0,S.jsx)(`input`,{autoFocus:!0,className:`w-full bg-transparent border border-primary/50 rounded px-1 py-0 text-xs outline-none`,value:d,onChange:e=>f(e.target.value),onBlur:y,onKeyDown:e=>{e.key===`Enter`&&y(),e.key===`Escape`&&b()}}):(0,S.jsx)(`span`,{className:`cursor-pointer truncate block ${i==null?`text-muted-foreground/40 italic`:``}`,onDoubleClick:()=>p&&v(t.index,e,i),title:i==null?`NULL`:String(i),children:i==null?`NULL`:String(i)})}})),[e?.columns,t,c,d,y,b,v,p]),C=s({data:e?.rows??[],columns:x,getCoreRowModel:l()});if(!e)return(0,S.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:n?(0,S.jsx)(g,{className:`size-4 animate-spin`}):`Select a table`});let w=Math.ceil(e.total/e.limit)||1;return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,S.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,S.jsxs)(`table`,{className:`w-full text-xs border-collapse`,children:[(0,S.jsx)(`thead`,{className:`sticky top-0 z-10 bg-muted`,children:C.getHeaderGroups().map(e=>(0,S.jsx)(`tr`,{children:e.headers.map(e=>(0,S.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:r(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,S.jsxs)(`tbody`,{children:[C.getRowModel().rows.map(e=>(0,S.jsx)(`tr`,{className:`hover:bg-muted/30 border-b border-border/50`,children:e.getVisibleCells().map(e=>(0,S.jsx)(`td`,{className:`px-2 py-1 max-w-[300px]`,children:r(e.column.columnDef.cell,e.getContext())},e.id))},e.id)),e.rows.length===0&&(0,S.jsx)(`tr`,{children:(0,S.jsx)(`td`,{colSpan:e.columns.length,className:`px-2 py-8 text-center text-muted-foreground`,children:`No data`})})]})]})}),(0,S.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-t border-border bg-background shrink-0 text-xs text-muted-foreground`,children:[(0,S.jsxs)(`span`,{children:[e.total.toLocaleString(),` rows`]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`button`,{type:`button`,disabled:i<=1,onClick:()=>a(i-1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,S.jsx)(h,{className:`size-3.5`})}),(0,S.jsxs)(`span`,{children:[i,` / `,w]}),(0,S.jsx)(`button`,{type:`button`,disabled:i>=w,onClick:()=>a(i+1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,S.jsx)(m,{className:`size-3.5`})})]})]})]})}function E({dialect:e,onExecute:t,result:n,error:r,loading:o}){let[s,l]=(0,_.useState)(`SELECT * FROM `),u=(0,_.useCallback)(()=>{let e=s.trim();e&&t(e)},[s,t]);return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-start gap-1 border-b border-border bg-background`,onKeyDown:(0,_.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),u())},[u]),children:[(0,S.jsx)(`div`,{className:`flex-1 max-h-[120px] overflow-auto`,children:(0,S.jsx)(a,{value:s,onChange:l,extensions:[c({dialect:e})],basicSetup:{lineNumbers:!1,foldGutter:!1,highlightActiveLine:!1},className:`text-xs [&_.cm-editor]:!outline-none [&_.cm-scroller]:!overflow-auto`})}),(0,S.jsx)(`button`,{type:`button`,onClick:u,disabled:o,title:`Execute (Cmd+Enter)`,className:`shrink-0 m-1 p-1.5 rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors`,children:o?(0,S.jsx)(g,{className:`size-3.5 animate-spin`}):(0,S.jsx)(i,{className:`size-3.5`})})]}),(0,S.jsxs)(`div`,{className:`flex-1 overflow-auto text-xs`,children:[r&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-destructive bg-destructive/5`,children:r}),n?.changeType===`modify`&&(0,S.jsxs)(`div`,{className:`px-3 py-2 text-green-500`,children:[`Query executed. `,n.rowsAffected,` row(s) affected.`]}),n?.changeType===`select`&&n.rows.length>0&&(0,S.jsxs)(`table`,{className:`w-full border-collapse`,children:[(0,S.jsx)(`thead`,{className:`sticky top-0 bg-muted`,children:(0,S.jsx)(`tr`,{children:n.columns.map(e=>(0,S.jsx)(`th`,{className:`px-2 py-1 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:e},e))})}),(0,S.jsx)(`tbody`,{children:n.rows.map((e,t)=>(0,S.jsx)(`tr`,{className:`hover:bg-muted/30 border-b border-border/50`,children:n.columns.map(t=>(0,S.jsx)(`td`,{className:`px-2 py-1 max-w-[300px] truncate`,title:e[t]==null?`NULL`:String(e[t]),children:e[t]==null?(0,S.jsx)(`span`,{className:`text-muted-foreground/40 italic`,children:`NULL`}):String(e[t])},t))},t))})]}),n?.changeType===`select`&&n.rows.length===0&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-muted-foreground`,children:`No results`})]})]})}export{w as DatabaseViewer};
1
+ import{i as e,t}from"./react-CYzKIDNi.js";import{t as n}from"./jsx-runtime-wQxeESYQ.js";import{a as r,c as i,i as a,n as o,o as s,r as c,s as l,t as u}from"./dist-D9RHR8A4.js";import{t as d}from"./api-client-TUmacMRS.js";import{A as f,E as p,H as m,L as h,U as g}from"./index-qElHXk-7.js";var _=e(t(),1);function v(e,t,n,r){return`ppm-db-${e}-${n}.${t}-p${r}`}function y(e,t,n,r){try{let i=sessionStorage.getItem(v(e,t,n,r));return i?JSON.parse(i):null}catch{return null}}function b(e,t,n,r,i,a){try{sessionStorage.setItem(v(e,t,n,r),JSON.stringify({data:i,cols:a}))}catch{}}function x(e){let t=`/api/db/connections/${e}`,[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(`public`),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)([]),[u,f]=(0,_.useState)(!0),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(1),[v,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(!1),E=(0,_.useCallback)(async(r,a,o)=>{let c=r??n,u=a??i;if(c){f(!0);try{let[n,r]=await Promise.all([d.get(`${t}/data?table=${encodeURIComponent(c)}&schema=${u}&page=${o??h}&limit=100`),d.get(`${t}/schema?table=${encodeURIComponent(c)}&schema=${u}`)]);s(n),l(r),b(e,c,u,o??h,n,r)}catch(e){m(e.message)}finally{f(!1)}}},[t,e,n,i,h]);return{selectedTable:n,selectTable:(0,_.useCallback)((t,n=`public`)=>{r(t),a(n),g(1),x(null);let i=y(e,t,n,1);i?(s(i.data),l(i.cols),f(!1),E(t,n,1)):E(t,n,1)},[e,E]),tableData:o,schema:c,loading:u,error:p,page:h,setPage:(0,_.useCallback)(e=>{g(e),E(void 0,void 0,e)},[E]),queryResult:v,queryError:S,queryLoading:w,executeQuery:(0,_.useCallback)(async e=>{T(!0),C(null);try{let r=await d.post(`${t}/query`,{sql:e});x(r),r.changeType===`modify`&&E(n??void 0,i)}catch(e){C(e.message)}finally{T(!1)}},[t,n,i,E]),updateCell:(0,_.useCallback)(async(e,r,a,o)=>{if(!n)return;let s=n,c=i;try{await d.put(`${t}/cell`,{table:s,schema:c,pkColumn:e,pkValue:r,column:a,value:o}),E(s,c)}catch(e){m(e.message)}},[t,n,i,E]),refreshData:E}}var S=n(),C={postgres:u,sqlite:o};function w({metadata:e}){let t=e?.connectionId,n=e?.connectionName,r=e?.dbType??`postgres`,i=e?.tableName,a=e?.schemaName??`public`,o=x(t),[s,c]=(0,_.useState)(!1),l=(0,_.useRef)(!1);return(0,_.useEffect)(()=>{!i||l.current||(l.current=!0,o.selectTable(i,a))},[i,a]),(0,S.jsx)(`div`,{className:`flex h-full w-full overflow-hidden`,children:(0,S.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,S.jsx)(h,{className:`size-3.5 text-muted-foreground`}),(0,S.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:n??`Database`}),o.selectedTable&&(0,S.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,o.selectedTable]}),(0,S.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,S.jsx)(`button`,{type:`button`,onClick:()=>o.refreshData(),title:`Reload data`,className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,S.jsx)(p,{className:`size-3 ${o.loading?`animate-spin`:``}`})}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`px-2 py-1 rounded text-xs transition-colors ${s?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:`SQL`})]})]}),(0,S.jsx)(`div`,{className:`flex-1 overflow-hidden ${s?`max-h-[60%]`:``}`,children:(0,S.jsx)(T,{tableData:o.tableData,schema:o.schema,loading:o.loading,page:o.page,onPageChange:o.setPage,onCellUpdate:o.updateCell})}),s&&(0,S.jsx)(`div`,{className:`border-t border-border h-[40%] shrink-0`,children:(0,S.jsx)(E,{dialect:C[r]??u,onExecute:o.executeQuery,result:o.queryResult,error:o.queryError,loading:o.queryLoading})})]})})}function T({tableData:e,schema:t,loading:n,page:i,onPageChange:a,onCellUpdate:o}){let[c,u]=(0,_.useState)(null),[d,p]=(0,_.useState)(``),h=(0,_.useMemo)(()=>t.find(e=>e.pk)?.name??null,[t]),v=(0,_.useCallback)((e,t,n)=>{u({rowIdx:e,col:t}),p(n==null?``:String(n))},[]),y=(0,_.useCallback)(()=>{if(!c||!e||!h)return;let t=e.rows[c.rowIdx];if(!t)return;let n=t[c.col];String(n??``)!==d&&o(h,t[h],c.col,d===``?null:d),u(null)},[c,d,e,h,o]),b=(0,_.useCallback)(()=>u(null),[]),x=(0,_.useMemo)(()=>(e?.columns??[]).map(e=>({id:e,accessorFn:t=>t[e],header:()=>(0,S.jsx)(`span`,{className:t.find(t=>t.name===e)?.pk?`font-bold`:``,children:e}),cell:({row:t,getValue:n})=>{let r=c?.rowIdx===t.index&&c?.col===e,i=n();return r?(0,S.jsx)(`input`,{autoFocus:!0,className:`w-full bg-transparent border border-primary/50 rounded px-1 py-0 text-xs outline-none`,value:d,onChange:e=>p(e.target.value),onBlur:y,onKeyDown:e=>{e.key===`Enter`&&y(),e.key===`Escape`&&b()}}):(0,S.jsx)(`span`,{className:`cursor-pointer truncate block ${i==null?`text-muted-foreground/40 italic`:``}`,onDoubleClick:()=>h&&v(t.index,e,i),title:i==null?`NULL`:String(i),children:i==null?`NULL`:String(i)})}})),[e?.columns,t,c,d,y,b,v,h]),C=s({data:e?.rows??[],columns:x,getCoreRowModel:l()});if(!e)return(0,S.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:n?(0,S.jsx)(f,{className:`size-4 animate-spin`}):`Select a table`});let w=Math.ceil(e.total/e.limit)||1;return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,S.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,S.jsxs)(`table`,{className:`w-full text-xs border-collapse`,children:[(0,S.jsx)(`thead`,{className:`sticky top-0 z-10 bg-muted`,children:C.getHeaderGroups().map(e=>(0,S.jsx)(`tr`,{children:e.headers.map(e=>(0,S.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:r(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,S.jsxs)(`tbody`,{children:[C.getRowModel().rows.map(e=>(0,S.jsx)(`tr`,{className:`hover:bg-muted/30 border-b border-border/50`,children:e.getVisibleCells().map(e=>(0,S.jsx)(`td`,{className:`px-2 py-1 max-w-[300px]`,children:r(e.column.columnDef.cell,e.getContext())},e.id))},e.id)),e.rows.length===0&&(0,S.jsx)(`tr`,{children:(0,S.jsx)(`td`,{colSpan:e.columns.length,className:`px-2 py-8 text-center text-muted-foreground`,children:`No data`})})]})]})}),(0,S.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-t border-border bg-background shrink-0 text-xs text-muted-foreground`,children:[(0,S.jsxs)(`span`,{children:[e.total.toLocaleString(),` rows`]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`button`,{type:`button`,disabled:i<=1,onClick:()=>a(i-1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,S.jsx)(g,{className:`size-3.5`})}),(0,S.jsxs)(`span`,{children:[i,` / `,w]}),(0,S.jsx)(`button`,{type:`button`,disabled:i>=w,onClick:()=>a(i+1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,S.jsx)(m,{className:`size-3.5`})})]})]})]})}function E({dialect:e,onExecute:t,result:n,error:r,loading:o}){let[s,l]=(0,_.useState)(`SELECT * FROM `),u=(0,_.useCallback)(()=>{let e=s.trim();e&&t(e)},[s,t]);return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-start gap-1 border-b border-border bg-background`,onKeyDown:(0,_.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),u())},[u]),children:[(0,S.jsx)(`div`,{className:`flex-1 max-h-[120px] overflow-auto`,children:(0,S.jsx)(a,{value:s,onChange:l,extensions:[c({dialect:e})],basicSetup:{lineNumbers:!1,foldGutter:!1,highlightActiveLine:!1},className:`text-xs [&_.cm-editor]:!outline-none [&_.cm-scroller]:!overflow-auto`})}),(0,S.jsx)(`button`,{type:`button`,onClick:u,disabled:o,title:`Execute (Cmd+Enter)`,className:`shrink-0 m-1 p-1.5 rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors`,children:o?(0,S.jsx)(f,{className:`size-3.5 animate-spin`}):(0,S.jsx)(i,{className:`size-3.5`})})]}),(0,S.jsxs)(`div`,{className:`flex-1 overflow-auto text-xs`,children:[r&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-destructive bg-destructive/5`,children:r}),n?.changeType===`modify`&&(0,S.jsxs)(`div`,{className:`px-3 py-2 text-green-500`,children:[`Query executed. `,n.rowsAffected,` row(s) affected.`]}),n?.changeType===`select`&&n.rows.length>0&&(0,S.jsxs)(`table`,{className:`w-full border-collapse`,children:[(0,S.jsx)(`thead`,{className:`sticky top-0 bg-muted`,children:(0,S.jsx)(`tr`,{children:n.columns.map(e=>(0,S.jsx)(`th`,{className:`px-2 py-1 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:e},e))})}),(0,S.jsx)(`tbody`,{children:n.rows.map((e,t)=>(0,S.jsx)(`tr`,{className:`hover:bg-muted/30 border-b border-border/50`,children:n.columns.map(t=>(0,S.jsx)(`td`,{className:`px-2 py-1 max-w-[300px] truncate`,title:e[t]==null?`NULL`:String(e[t]),children:e[t]==null?(0,S.jsx)(`span`,{className:`text-muted-foreground/40 italic`,children:`NULL`}):String(e[t])},t))},t))})]}),n?.changeType===`select`&&n.rows.length===0&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-muted-foreground`,children:`No results`})]})]})}export{w as DatabaseViewer};
@@ -1,4 +1,4 @@
1
- import{i as e,t}from"./react-CYzKIDNi.js";import{n,t as r}from"./jsx-runtime-wQxeESYQ.js";import{t as i}from"./columns-2-fz8yNaAo.js";import{n as a}from"./settings-store-2NQzaOVJ.js";import{i as o,t as s}from"./api-client-TUmacMRS.js";import{L as c,j as l,k as u}from"./index-DaQYRomz.js";import{r as d,t as f}from"./use-monaco-theme-Bt1Lr3jH.js";var p=n(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),m=n(`text-wrap`,[[`path`,{d:`m16 16-3 3 3 3`,key:`117b85`}],[`path`,{d:`M3 12h14.5a1 1 0 0 1 0 7H13`,key:`18xa6z`}],[`path`,{d:`M3 19h6`,key:`1ygdsz`}],[`path`,{d:`M3 5h18`,key:`1u36vt`}]]),h=e(t(),1),g=r();function _(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`}[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function v({metadata:e}){let t=e?.filePath,n=e?.projectName,r=e?.ref1,v=e?.ref2,b=e?.file1,x=e?.file2,S=e?.original,C=e?.modified,w=S!=null||C!=null,T=!!(b&&x),[E,D]=(0,h.useState)(null),[O,k]=(0,h.useState)(null),[A,j]=(0,h.useState)(!w),[M,N]=(0,h.useState)(null),[P,F]=(0,h.useState)(`both`),{wordWrap:I,toggleWordWrap:L}=a(),R=f(),z=(0,h.useRef)(null),[B,V]=(0,h.useState)();(0,h.useEffect)(()=>{let e=z.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&V(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[A,M]),(0,h.useEffect)(()=>{if(w||!n)return;if(j(!0),N(null),b&&x){let e=new URLSearchParams({file1:b,file2:x});s.get(`${o(n)}/files/compare?${e}`).then(e=>{k(e),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to compare files`),j(!1)});return}let e;if(t){let i=new URLSearchParams({file:t});r&&i.set(`ref`,r),e=`${o(n)}/git/file-diff?${i}`}else if(r||v){let t=new URLSearchParams;r&&t.set(`ref1`,r),v&&t.set(`ref2`,v),e=`${o(n)}/git/diff?${t}`}else e=`${o(n)}/git/diff`;s.get(e).then(e=>{D(e.diff),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to load diff`),j(!1)})},[t,n,r,v,b,x,w]);let{original:H,modified:U}=(0,h.useMemo)(()=>w?{original:S??``,modified:C??``}:T&&O?O:E?y(E):{original:``,modified:``},[E,w,S,C,T,O]),W=(0,h.useMemo)(()=>{let e=t??x??b;return e?_(e):`plaintext`},[t,b,x]),G=typeof window<`u`&&window.innerWidth<768,K=!G&&P===`both`;return!n&&!w?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`}):A?(0,g.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,g.jsx)(l,{className:`size-5 animate-spin`}),(0,g.jsx)(`span`,{className:`text-sm`,children:`Loading diff...`})]}):M?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive text-sm`,children:M}):!w&&!T&&!H&&!U?(0,g.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,g.jsx)(c,{className:`size-8`}),(0,g.jsx)(`p`,{className:`text-sm`,children:`No content changes`}),t&&(0,g.jsx)(`p`,{className:`text-xs font-mono`,children:t})]}):(0,g.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!G&&(0,g.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 px-2 py-0.5 border-b border-border shrink-0`,children:[(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(P===`left`?`both`:`left`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`left`?`bg-muted text-foreground`:``}`,title:`Expand original`,children:(0,g.jsx)(u,{className:`size-3.5`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(`both`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`both`?`bg-muted text-foreground`:``}`,title:`Side by side`,children:(0,g.jsx)(i,{className:`size-3.5`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(P===`right`?`both`:`right`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`right`?`bg-muted text-foreground`:``}`,title:`Expand modified`,children:(0,g.jsx)(p,{className:`size-3.5`})}),(0,g.jsx)(`div`,{className:`w-px h-3.5 bg-border mx-0.5 shrink-0`}),(0,g.jsx)(`button`,{type:`button`,onClick:L,title:`Toggle word wrap`,className:`p-1 rounded hover:bg-muted transition-colors ${I?`bg-muted text-foreground`:``}`,children:(0,g.jsx)(m,{className:`size-3.5`})})]}),(0,g.jsx)(`div`,{ref:z,className:`flex-1 overflow-hidden`,children:B&&B>0?(0,g.jsx)(d,{height:B,language:W,original:H,modified:U,theme:R,options:{fontSize:G?11:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:G||I?`on`:`off`,renderSideBySide:K,readOnly:!0,automaticLayout:!0,scrollBeyondLastLine:!1},loading:(0,g.jsx)(l,{className:`size-5 animate-spin text-muted-foreground`})}):(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,g.jsx)(l,{className:`size-5 animate-spin text-muted-foreground`})})})]})}function y(e){let t=e.split(`
1
+ import{i as e,t}from"./react-CYzKIDNi.js";import{n,t as r}from"./jsx-runtime-wQxeESYQ.js";import{t as i}from"./columns-2-fz8yNaAo.js";import{n as a}from"./settings-store-2NQzaOVJ.js";import{i as o,t as s}from"./api-client-TUmacMRS.js";import{A as c,I as l,O as u}from"./index-qElHXk-7.js";import{r as d,t as f}from"./use-monaco-theme-Bt1Lr3jH.js";var p=n(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),m=n(`text-wrap`,[[`path`,{d:`m16 16-3 3 3 3`,key:`117b85`}],[`path`,{d:`M3 12h14.5a1 1 0 0 1 0 7H13`,key:`18xa6z`}],[`path`,{d:`M3 19h6`,key:`1ygdsz`}],[`path`,{d:`M3 5h18`,key:`1u36vt`}]]),h=e(t(),1),g=r();function _(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`}[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function v({metadata:e}){let t=e?.filePath,n=e?.projectName,r=e?.ref1,v=e?.ref2,b=e?.file1,x=e?.file2,S=e?.original,C=e?.modified,w=S!=null||C!=null,T=!!(b&&x),[E,D]=(0,h.useState)(null),[O,k]=(0,h.useState)(null),[A,j]=(0,h.useState)(!w),[M,N]=(0,h.useState)(null),[P,F]=(0,h.useState)(`both`),{wordWrap:I,toggleWordWrap:L}=a(),R=f(),z=(0,h.useRef)(null),[B,V]=(0,h.useState)();(0,h.useEffect)(()=>{let e=z.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&V(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[A,M]),(0,h.useEffect)(()=>{if(w||!n)return;if(j(!0),N(null),b&&x){let e=new URLSearchParams({file1:b,file2:x});s.get(`${o(n)}/files/compare?${e}`).then(e=>{k(e),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to compare files`),j(!1)});return}let e;if(t){let i=new URLSearchParams({file:t});r&&i.set(`ref`,r),e=`${o(n)}/git/file-diff?${i}`}else if(r||v){let t=new URLSearchParams;r&&t.set(`ref1`,r),v&&t.set(`ref2`,v),e=`${o(n)}/git/diff?${t}`}else e=`${o(n)}/git/diff`;s.get(e).then(e=>{D(e.diff),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to load diff`),j(!1)})},[t,n,r,v,b,x,w]);let{original:H,modified:U}=(0,h.useMemo)(()=>w?{original:S??``,modified:C??``}:T&&O?O:E?y(E):{original:``,modified:``},[E,w,S,C,T,O]),W=(0,h.useMemo)(()=>{let e=t??x??b;return e?_(e):`plaintext`},[t,b,x]),G=typeof window<`u`&&window.innerWidth<768,K=!G&&P===`both`;return!n&&!w?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`}):A?(0,g.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,g.jsx)(c,{className:`size-5 animate-spin`}),(0,g.jsx)(`span`,{className:`text-sm`,children:`Loading diff...`})]}):M?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive text-sm`,children:M}):!w&&!T&&!H&&!U?(0,g.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,g.jsx)(l,{className:`size-8`}),(0,g.jsx)(`p`,{className:`text-sm`,children:`No content changes`}),t&&(0,g.jsx)(`p`,{className:`text-xs font-mono`,children:t})]}):(0,g.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!G&&(0,g.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 px-2 py-0.5 border-b border-border shrink-0`,children:[(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(P===`left`?`both`:`left`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`left`?`bg-muted text-foreground`:``}`,title:`Expand original`,children:(0,g.jsx)(u,{className:`size-3.5`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(`both`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`both`?`bg-muted text-foreground`:``}`,title:`Side by side`,children:(0,g.jsx)(i,{className:`size-3.5`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(P===`right`?`both`:`right`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`right`?`bg-muted text-foreground`:``}`,title:`Expand modified`,children:(0,g.jsx)(p,{className:`size-3.5`})}),(0,g.jsx)(`div`,{className:`w-px h-3.5 bg-border mx-0.5 shrink-0`}),(0,g.jsx)(`button`,{type:`button`,onClick:L,title:`Toggle word wrap`,className:`p-1 rounded hover:bg-muted transition-colors ${I?`bg-muted text-foreground`:``}`,children:(0,g.jsx)(m,{className:`size-3.5`})})]}),(0,g.jsx)(`div`,{ref:z,className:`flex-1 overflow-hidden`,children:B&&B>0?(0,g.jsx)(d,{height:B,language:W,original:H,modified:U,theme:R,options:{fontSize:G?11:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:G||I?`on`:`off`,renderSideBySide:K,readOnly:!0,automaticLayout:!0,scrollBeyondLastLine:!1},loading:(0,g.jsx)(c,{className:`size-5 animate-spin text-muted-foreground`})}):(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,g.jsx)(c,{className:`size-5 animate-spin text-muted-foreground`})})})]})}function y(e){let t=e.split(`
2
2
  `),n=[],r=[],i=!1;for(let e of t)if(!(e.startsWith(`diff --git`)||e.startsWith(`diff --no-index`)||e.startsWith(`index `)||e.startsWith(`new file`)||e.startsWith(`deleted file`)||e.startsWith(`old mode`)||e.startsWith(`new mode`)||e.startsWith(`---`)||e.startsWith(`+++`)||e.startsWith(`Binary files`)||e.startsWith(`\\ No newline`))){if(e.startsWith(`@@`)){i=!0;continue}if(i)if(e.startsWith(`-`))n.push(e.slice(1));else if(e.startsWith(`+`))r.push(e.slice(1));else{let t=e.startsWith(` `)?e.slice(1):e;n.push(t),r.push(t)}}return{original:n.join(`
3
3
  `),modified:r.join(`
4
4
  `)}}export{v as DiffViewer};
@@ -1 +1 @@
1
- import{i as e,t}from"./react-CYzKIDNi.js";import{A as n,t as r}from"./input-P_K5CUiy.js";import{n as i,t as a}from"./jsx-runtime-wQxeESYQ.js";import{a as o,t as s}from"./tab-store-0CKk8cSr.js";import{t as c}from"./utils-DC-bdPS3.js";import{i as l,t as u}from"./api-client-TUmacMRS.js";import{D as d,G as f,M as p,N as m,a as h,c as g,d as _,f as v,i as ee,j as te,l as y,o as ne,p as b,r as re,s as ie,u as x,w as S,z as ae}from"./index-DaQYRomz.js";var oe=i(`cherry`,[[`path`,{d:`M2 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`cvxqlc`}],[`path`,{d:`M12 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`1ostrc`}],[`path`,{d:`M7 14c3.22-2.91 4.29-8.75 5-12 1.66 2.38 4.94 9 5 12`,key:`hqx58h`}],[`path`,{d:`M22 9c-4.29 0-7.14-2.33-10-7 5.71 0 10 4.67 10 7Z`,key:`eykp1o`}]]),C=i(`git-merge`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]),w=i(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]),T=e(t(),1),E=a(),D=[`#4fc3f7`,`#81c784`,`#ffb74d`,`#e57373`,`#ba68c8`,`#4dd0e1`,`#aed581`,`#ff8a65`,`#f06292`,`#7986cb`],O=32,k=20,se=5;function A({metadata:e}){let t=e?.projectName,[i,a]=(0,T.useState)(null),[o,f]=(0,T.useState)(!0),[S,C]=(0,T.useState)(null),[A,j]=(0,T.useState)(!1),[M,N]=(0,T.useState)({type:null}),[P,F]=(0,T.useState)(``),[I,L]=(0,T.useState)(null),[R,z]=(0,T.useState)([]),[le,B]=(0,T.useState)(!1),{openTab:V}=s(),H=(0,T.useCallback)(async()=>{if(t)try{f(!0),a(await u.get(`${l(t)}/git/graph?max=200`)),C(null)}catch(e){C(e instanceof Error?e.message:`Failed to fetch graph`)}finally{f(!1)}},[t]);(0,T.useEffect)(()=>{H();let e=setInterval(H,1e4);return()=>clearInterval(e)},[H]);let U=async(e,n)=>{if(t){j(!0);try{await u.post(`${l(t)}${e}`,n),await H()}catch(e){C(e instanceof Error?e.message:`Action failed`)}finally{j(!1)}}},W=e=>U(`/git/checkout`,{ref:e}),ue=e=>U(`/git/cherry-pick`,{hash:e}),de=e=>U(`/git/revert`,{hash:e}),fe=e=>U(`/git/merge`,{source:e}),pe=e=>U(`/git/branch/delete`,{name:e}),me=e=>U(`/git/push`,{branch:e}),G=async(e,t)=>{if(i?.branches.some(t=>t.name===e||t.name.endsWith(`/${e}`))){if(!window.confirm(`Branch "${e}" already exists.\nDelete it and recreate from this commit?`))return;await U(`/git/branch/delete`,{name:e})}await U(`/git/branch/create`,{name:e,from:t})},K=(e,t)=>U(`/git/tag`,{name:e,hash:t}),he=async e=>{if(t)try{let n=await u.get(`${l(t)}/git/pr-url?branch=${encodeURIComponent(e)}`);n.url&&window.open(n.url,`_blank`)}catch{}},q=e=>{navigator.clipboard.writeText(e)},ge=async e=>{if(I?.hash===e.hash){L(null);return}L(e),B(!0);try{let n=e.parents[0]??``,r=n?`ref1=${encodeURIComponent(n)}&`:``,i=await u.get(`${l(t)}/git/diff-stat?${r}ref2=${encodeURIComponent(e.hash)}`);z(Array.isArray(i)?i:[])}catch(e){console.error(`diff-stat error:`,e),z([])}finally{B(!1)}},_e=e=>{let n=e.parents[0];V({type:`git-diff`,title:`Diff ${e.abbreviatedHash}`,closable:!0,metadata:{projectName:t,ref1:n??void 0,ref2:e.hash},projectId:t??null})},{laneMap:J,maxLane:ve}=(0,T.useMemo)(()=>{let e=new Map;if(!i)return{laneMap:e,maxLane:0};let t=0,n=new Map;for(let r of i.commits){let i=n.get(r.hash);i===void 0&&(i=t++),e.set(r.hash,i),n.delete(r.hash);for(let e=0;e<r.parents.length;e++){let a=r.parents[e];n.has(a)||n.set(a,e===0?i:t++)}}return{laneMap:e,maxLane:Math.max(t-1,0)}},[i]),Y=i?.branches.find(e=>e.current),ye=(0,T.useMemo)(()=>{let e=new Map;if(!i)return e;for(let t of i.branches){let n=e.get(t.commitHash)??[];n.push({name:t.name,type:`branch`}),e.set(t.commitHash,n)}for(let t of i.commits)for(let n of t.refs)if(n.startsWith(`tag: `)){let r=n.replace(`tag: `,``),i=e.get(t.hash)??[];i.push({name:r,type:`tag`}),e.set(t.hash,i)}return e},[i]),be=(0,T.useMemo)(()=>{if(!i)return[];let e=[];for(let t=0;t<i.commits.length;t++){let n=i.commits[t],r=J.get(n.hash)??0,a=D[r%D.length];for(let o of n.parents){let s=i.commits.findIndex(e=>e.hash===o);if(s<0)continue;let c=J.get(o)??0,l=D[c%D.length],u=r*k+k/2,d=t*O+O/2,f=c*k+k/2,p=s*O+O/2,m,h=n.parents.indexOf(o)>0;if(u===f)m=`M ${u} ${d} L ${f} ${p}`;else if(h){let e=d+O;m=`M ${u} ${d} C ${u} ${e} ${f} ${d} ${f} ${e} L ${f} ${p}`}else{let e=p-O;m=`M ${u} ${d} L ${u} ${e} C ${u} ${p} ${f} ${e} ${f} ${p}`}let g=n.parents.indexOf(o)===0?a:l;e.push({d:m,color:g})}}return e},[i,J]);(ve+1)*k+k;let X=(i?.commits.length??0)*O,[Z,xe]=(0,T.useState)((typeof window<`u`&&window.innerWidth<768?6:10)*k+k),Q=(0,T.useRef)(!1),$=(0,T.useCallback)(e=>{Q.current=!0;let t=Z,n=n=>{if(!Q.current)return;let r=`touches`in n?n.touches[0].clientX:n.clientX;xe(Math.max(40,t+r-e))},r=()=>{Q.current=!1,window.removeEventListener(`mousemove`,n),window.removeEventListener(`mouseup`,r),window.removeEventListener(`touchmove`,n),window.removeEventListener(`touchend`,r)};window.addEventListener(`mousemove`,n),window.addEventListener(`mouseup`,r),window.addEventListener(`touchmove`,n,{passive:!1}),window.addEventListener(`touchend`,r)},[Z]),Se=(0,T.useCallback)(e=>{e.preventDefault(),$(e.clientX)},[$]),Ce=(0,T.useCallback)(e=>{$(e.touches[0].clientX)},[$]);if(!t)return(0,E.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`});if(o&&!i)return(0,E.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,E.jsx)(te,{className:`size-5 animate-spin`}),(0,E.jsx)(`span`,{className:`text-sm`,children:`Loading git graph...`})]});if(S&&!i)return(0,E.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-destructive text-sm`,children:[(0,E.jsx)(`p`,{children:S}),(0,E.jsx)(g,{variant:`outline`,size:`sm`,onClick:H,children:`Retry`})]});function we(e){let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}return(0,E.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b`,children:[(0,E.jsxs)(`span`,{className:`text-sm font-medium`,children:[`Git Graph`,Y?` - ${Y.name}`:``]}),(0,E.jsx)(g,{variant:`ghost`,size:`icon-xs`,onClick:H,disabled:A,children:(0,E.jsx)(d,{className:o?`animate-spin`:``})})]}),S&&(0,E.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-destructive bg-destructive/10`,children:S}),(0,E.jsx)(`div`,{className:`flex-1 overflow-y-auto overflow-x-auto md:overflow-x-hidden`,children:(0,E.jsxs)(`div`,{className:`flex min-w-max md:min-w-0`,style:{height:`${X}px`},children:[(0,E.jsxs)(`div`,{className:`sticky left-0 z-10 shrink-0 bg-background`,style:{width:`${Z}px`},children:[(0,E.jsxs)(`svg`,{width:Z,height:X,children:[be.map((e,t)=>(0,E.jsx)(`path`,{d:e.d,stroke:e.color,strokeWidth:2,fill:`none`},t)),i?.commits.map((e,t)=>{let n=J.get(e.hash)??0,r=n*k+k/2,i=t*O+O/2,a=D[n%D.length];return(0,E.jsx)(`circle`,{cx:r,cy:i,r:se,fill:a,stroke:`#0f1419`,strokeWidth:2},e.hash)})]}),(0,E.jsx)(`div`,{className:`absolute top-0 right-0 w-3 md:w-2 h-full cursor-col-resize hover:bg-primary/20 flex items-center justify-center bg-primary/10 md:bg-transparent`,onMouseDown:Se,onTouchStart:Ce,children:(0,E.jsx)(p,{className:`size-3 text-muted-foreground md:opacity-0 md:hover:opacity-100`})})]}),(0,E.jsx)(`div`,{className:`flex-1 min-w-[400px]`,children:i?.commits.map((e,t)=>{let r=D[(J.get(e.hash)??0)%D.length],i=ye.get(e.hash)??[],a=i.filter(e=>e.type===`branch`),o=i.filter(e=>e.type===`tag`);return(0,E.jsxs)(y,{children:[(0,E.jsx)(b,{asChild:!0,children:(0,E.jsx)(`div`,{className:`flex items-center hover:bg-muted/50 cursor-pointer text-sm border-b border-border/30 ${I?.hash===e.hash?`bg-primary/10`:``}`,style:{height:`${O}px`},onClick:()=>ge(e),children:(0,E.jsxs)(`div`,{className:`flex items-center gap-2 flex-1 min-w-0 px-2`,children:[(0,E.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground w-14 shrink-0`,children:e.abbreviatedHash}),a.map(e=>(0,E.jsx)(ce,{label:e,color:r,currentBranch:Y,onCheckout:W,onMerge:fe,onPush:me,onCreatePr:he,onDelete:pe},`branch-${e.name}`)),o.map(e=>(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 bg-amber-500/20 text-amber-500 border border-amber-500/30`,children:[(0,E.jsx)(w,{className:`size-2.5`}),e.name]},`tag-${e.name}`)),(0,E.jsx)(`span`,{className:`flex-1 truncate`,children:e.subject}),(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0 hidden sm:inline`,children:e.authorName}),(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0 w-14 text-right`,children:we(e.authorDate)})]})})}),(0,E.jsxs)(x,{children:[(0,E.jsx)(_,{onClick:()=>W(e.hash),children:`Checkout`}),(0,E.jsxs)(_,{onClick:()=>{N({type:`branch`,hash:e.hash}),F(``)},children:[(0,E.jsx)(m,{className:`size-3`}),`Create Branch...`]}),(0,E.jsx)(v,{}),(0,E.jsxs)(_,{onClick:()=>ue(e.hash),children:[(0,E.jsx)(oe,{className:`size-3`}),`Cherry Pick`]}),(0,E.jsxs)(_,{onClick:()=>de(e.hash),children:[(0,E.jsx)(n,{className:`size-3`}),`Revert`]}),(0,E.jsxs)(_,{onClick:()=>{N({type:`tag`,hash:e.hash}),F(``)},children:[(0,E.jsx)(w,{className:`size-3`}),`Create Tag...`]}),(0,E.jsx)(v,{}),(0,E.jsx)(_,{onClick:()=>_e(e),children:`View Diff`}),(0,E.jsxs)(_,{onClick:()=>q(e.hash),children:[(0,E.jsx)(ae,{className:`size-3`}),`Copy Hash`]})]})]},e.hash)})})]})}),I&&(0,E.jsxs)(`div`,{className:`border-t bg-muted/30 max-h-[40%] overflow-auto`,children:[(0,E.jsxs)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:[(0,E.jsxs)(`span`,{className:`text-sm font-medium truncate`,children:[I.abbreviatedHash,` — `,I.subject]}),(0,E.jsx)(g,{variant:`ghost`,size:`icon-xs`,onClick:()=>L(null),children:`✕`})]}),(0,E.jsxs)(`div`,{className:`px-3 py-2 text-xs space-y-1`,children:[(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Author`}),(0,E.jsxs)(`span`,{children:[I.authorName,` <`,I.authorEmail,`>`]})]}),(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Date`}),(0,E.jsx)(`span`,{children:new Date(I.authorDate).toLocaleString()})]}),(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Hash`}),(0,E.jsx)(`span`,{className:`font-mono cursor-pointer hover:text-primary`,onClick:()=>q(I.hash),children:I.hash})]}),I.parents.length>0&&(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Parents`}),(0,E.jsx)(`span`,{className:`font-mono`,children:I.parents.map(e=>e.slice(0,7)).join(`, `)})]}),I.body&&(0,E.jsx)(`div`,{className:`mt-2 p-2 bg-background rounded text-xs whitespace-pre-wrap`,children:I.body})]}),(0,E.jsxs)(`div`,{className:`px-3 py-1 border-t`,children:[(0,E.jsx)(`div`,{className:`text-xs text-muted-foreground py-1`,children:le?`Loading files...`:`${R.length} file${R.length===1?``:`s`} changed`}),R.map(e=>(0,E.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5 text-xs hover:bg-muted/50 rounded px-1 cursor-pointer`,onClick:()=>V({type:`git-diff`,title:`Diff ${c(e.path)}`,closable:!0,metadata:{projectName:t,ref1:I.parents[0]??void 0,ref2:I.hash,filePath:e.path},projectId:t??null}),children:[(0,E.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:e.path}),e.additions>0&&(0,E.jsxs)(`span`,{className:`text-green-500`,children:[`+`,e.additions]}),e.deletions>0&&(0,E.jsxs)(`span`,{className:`text-red-500`,children:[`-`,e.deletions]})]},e.path))]})]}),(0,E.jsx)(re,{open:M.type!==null,onOpenChange:e=>{e||N({type:null})},children:(0,E.jsxs)(ee,{children:[(0,E.jsx)(ne,{children:(0,E.jsx)(ie,{children:M.type===`branch`?`Create Branch`:`Create Tag`})}),(0,E.jsx)(r,{placeholder:M.type===`branch`?`Branch name`:`Tag name`,value:P,onChange:e=>F(e.target.value),onKeyDown:e=>{e.key===`Enter`&&P.trim()&&(M.type===`branch`?G(P.trim(),M.hash):K(P.trim(),M.hash),N({type:null}))},autoFocus:!0}),(0,E.jsxs)(h,{children:[(0,E.jsx)(g,{variant:`outline`,onClick:()=>N({type:null}),children:`Cancel`}),(0,E.jsx)(g,{disabled:!P.trim(),onClick:()=>{M.type===`branch`?G(P.trim(),M.hash):K(P.trim(),M.hash),N({type:null})},children:`Create`})]})]})})]})}function ce({label:e,color:t,currentBranch:n,onCheckout:r,onMerge:i,onPush:a,onCreatePr:s,onDelete:c}){return(0,E.jsxs)(y,{children:[(0,E.jsx)(b,{asChild:!0,children:(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 cursor-context-menu`,style:{backgroundColor:`${t}30`,color:t,border:`1px solid ${t}50`},children:[(0,E.jsx)(m,{className:`size-2.5`}),e.name]})}),(0,E.jsxs)(x,{children:[(0,E.jsx)(_,{onClick:()=>r(e.name),children:`Checkout`}),(0,E.jsxs)(_,{onClick:()=>i(e.name),disabled:e.name===n?.name,children:[(0,E.jsx)(C,{className:`size-3`}),`Merge into current`]}),(0,E.jsx)(v,{}),(0,E.jsxs)(_,{onClick:()=>a(e.name),children:[(0,E.jsx)(f,{className:`size-3`}),`Push`]}),(0,E.jsxs)(_,{onClick:()=>s(e.name),children:[(0,E.jsx)(o,{className:`size-3`}),`Create PR`]}),(0,E.jsx)(v,{}),(0,E.jsxs)(_,{variant:`destructive`,onClick:()=>c(e.name),disabled:e.name===n?.name,children:[(0,E.jsx)(S,{className:`size-3`}),`Delete`]})]})]})}export{A as GitGraph};
1
+ import{i as e,t}from"./react-CYzKIDNi.js";import{M as n,t as r}from"./input-CVIzrYsH.js";import{n as i,t as a}from"./jsx-runtime-wQxeESYQ.js";import{a as o,t as s}from"./tab-store-0CKk8cSr.js";import{t as c}from"./utils-DC-bdPS3.js";import{i as l,t as u}from"./api-client-TUmacMRS.js";import{A as d,C as f,E as p,M as m,R as h,W as g,a as ee,c as _,d as v,f as y,i as te,j as ne,l as b,o as re,p as x,r as ie,s as ae,u as S}from"./index-qElHXk-7.js";var oe=i(`cherry`,[[`path`,{d:`M2 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`cvxqlc`}],[`path`,{d:`M12 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`1ostrc`}],[`path`,{d:`M7 14c3.22-2.91 4.29-8.75 5-12 1.66 2.38 4.94 9 5 12`,key:`hqx58h`}],[`path`,{d:`M22 9c-4.29 0-7.14-2.33-10-7 5.71 0 10 4.67 10 7Z`,key:`eykp1o`}]]),C=i(`git-merge`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]),w=i(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]),T=e(t(),1),E=a(),D=[`#4fc3f7`,`#81c784`,`#ffb74d`,`#e57373`,`#ba68c8`,`#4dd0e1`,`#aed581`,`#ff8a65`,`#f06292`,`#7986cb`],O=32,k=20,se=5;function A({metadata:e}){let t=e?.projectName,[i,a]=(0,T.useState)(null),[o,f]=(0,T.useState)(!0),[g,C]=(0,T.useState)(null),[A,j]=(0,T.useState)(!1),[M,N]=(0,T.useState)({type:null}),[P,F]=(0,T.useState)(``),[I,L]=(0,T.useState)(null),[R,z]=(0,T.useState)([]),[le,B]=(0,T.useState)(!1),{openTab:V}=s(),H=(0,T.useCallback)(async()=>{if(t)try{f(!0),a(await u.get(`${l(t)}/git/graph?max=200`)),C(null)}catch(e){C(e instanceof Error?e.message:`Failed to fetch graph`)}finally{f(!1)}},[t]);(0,T.useEffect)(()=>{H();let e=setInterval(H,1e4);return()=>clearInterval(e)},[H]);let U=async(e,n)=>{if(t){j(!0);try{await u.post(`${l(t)}${e}`,n),await H()}catch(e){C(e instanceof Error?e.message:`Action failed`)}finally{j(!1)}}},W=e=>U(`/git/checkout`,{ref:e}),ue=e=>U(`/git/cherry-pick`,{hash:e}),de=e=>U(`/git/revert`,{hash:e}),fe=e=>U(`/git/merge`,{source:e}),pe=e=>U(`/git/branch/delete`,{name:e}),me=e=>U(`/git/push`,{branch:e}),G=async(e,t)=>{if(i?.branches.some(t=>t.name===e||t.name.endsWith(`/${e}`))){if(!window.confirm(`Branch "${e}" already exists.\nDelete it and recreate from this commit?`))return;await U(`/git/branch/delete`,{name:e})}await U(`/git/branch/create`,{name:e,from:t})},K=(e,t)=>U(`/git/tag`,{name:e,hash:t}),he=async e=>{if(t)try{let n=await u.get(`${l(t)}/git/pr-url?branch=${encodeURIComponent(e)}`);n.url&&window.open(n.url,`_blank`)}catch{}},q=e=>{navigator.clipboard.writeText(e)},ge=async e=>{if(I?.hash===e.hash){L(null);return}L(e),B(!0);try{let n=e.parents[0]??``,r=n?`ref1=${encodeURIComponent(n)}&`:``,i=await u.get(`${l(t)}/git/diff-stat?${r}ref2=${encodeURIComponent(e.hash)}`);z(Array.isArray(i)?i:[])}catch(e){console.error(`diff-stat error:`,e),z([])}finally{B(!1)}},_e=e=>{let n=e.parents[0];V({type:`git-diff`,title:`Diff ${e.abbreviatedHash}`,closable:!0,metadata:{projectName:t,ref1:n??void 0,ref2:e.hash},projectId:t??null})},{laneMap:J,maxLane:ve}=(0,T.useMemo)(()=>{let e=new Map;if(!i)return{laneMap:e,maxLane:0};let t=0,n=new Map;for(let r of i.commits){let i=n.get(r.hash);i===void 0&&(i=t++),e.set(r.hash,i),n.delete(r.hash);for(let e=0;e<r.parents.length;e++){let a=r.parents[e];n.has(a)||n.set(a,e===0?i:t++)}}return{laneMap:e,maxLane:Math.max(t-1,0)}},[i]),Y=i?.branches.find(e=>e.current),ye=(0,T.useMemo)(()=>{let e=new Map;if(!i)return e;for(let t of i.branches){let n=e.get(t.commitHash)??[];n.push({name:t.name,type:`branch`}),e.set(t.commitHash,n)}for(let t of i.commits)for(let n of t.refs)if(n.startsWith(`tag: `)){let r=n.replace(`tag: `,``),i=e.get(t.hash)??[];i.push({name:r,type:`tag`}),e.set(t.hash,i)}return e},[i]),be=(0,T.useMemo)(()=>{if(!i)return[];let e=[];for(let t=0;t<i.commits.length;t++){let n=i.commits[t],r=J.get(n.hash)??0,a=D[r%D.length];for(let o of n.parents){let s=i.commits.findIndex(e=>e.hash===o);if(s<0)continue;let c=J.get(o)??0,l=D[c%D.length],u=r*k+k/2,d=t*O+O/2,f=c*k+k/2,p=s*O+O/2,m,h=n.parents.indexOf(o)>0;if(u===f)m=`M ${u} ${d} L ${f} ${p}`;else if(h){let e=d+O;m=`M ${u} ${d} C ${u} ${e} ${f} ${d} ${f} ${e} L ${f} ${p}`}else{let e=p-O;m=`M ${u} ${d} L ${u} ${e} C ${u} ${p} ${f} ${e} ${f} ${p}`}let g=n.parents.indexOf(o)===0?a:l;e.push({d:m,color:g})}}return e},[i,J]);(ve+1)*k+k;let X=(i?.commits.length??0)*O,[Z,xe]=(0,T.useState)((typeof window<`u`&&window.innerWidth<768?6:10)*k+k),Q=(0,T.useRef)(!1),$=(0,T.useCallback)(e=>{Q.current=!0;let t=Z,n=n=>{if(!Q.current)return;let r=`touches`in n?n.touches[0].clientX:n.clientX;xe(Math.max(40,t+r-e))},r=()=>{Q.current=!1,window.removeEventListener(`mousemove`,n),window.removeEventListener(`mouseup`,r),window.removeEventListener(`touchmove`,n),window.removeEventListener(`touchend`,r)};window.addEventListener(`mousemove`,n),window.addEventListener(`mouseup`,r),window.addEventListener(`touchmove`,n,{passive:!1}),window.addEventListener(`touchend`,r)},[Z]),Se=(0,T.useCallback)(e=>{e.preventDefault(),$(e.clientX)},[$]),Ce=(0,T.useCallback)(e=>{$(e.touches[0].clientX)},[$]);if(!t)return(0,E.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`});if(o&&!i)return(0,E.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,E.jsx)(d,{className:`size-5 animate-spin`}),(0,E.jsx)(`span`,{className:`text-sm`,children:`Loading git graph...`})]});if(g&&!i)return(0,E.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-destructive text-sm`,children:[(0,E.jsx)(`p`,{children:g}),(0,E.jsx)(_,{variant:`outline`,size:`sm`,onClick:H,children:`Retry`})]});function we(e){let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}return(0,E.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b`,children:[(0,E.jsxs)(`span`,{className:`text-sm font-medium`,children:[`Git Graph`,Y?` - ${Y.name}`:``]}),(0,E.jsx)(_,{variant:`ghost`,size:`icon-xs`,onClick:H,disabled:A,children:(0,E.jsx)(p,{className:o?`animate-spin`:``})})]}),g&&(0,E.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-destructive bg-destructive/10`,children:g}),(0,E.jsx)(`div`,{className:`flex-1 overflow-y-auto overflow-x-auto md:overflow-x-hidden`,children:(0,E.jsxs)(`div`,{className:`flex min-w-max md:min-w-0`,style:{height:`${X}px`},children:[(0,E.jsxs)(`div`,{className:`sticky left-0 z-10 shrink-0 bg-background`,style:{width:`${Z}px`},children:[(0,E.jsxs)(`svg`,{width:Z,height:X,children:[be.map((e,t)=>(0,E.jsx)(`path`,{d:e.d,stroke:e.color,strokeWidth:2,fill:`none`},t)),i?.commits.map((e,t)=>{let n=J.get(e.hash)??0,r=n*k+k/2,i=t*O+O/2,a=D[n%D.length];return(0,E.jsx)(`circle`,{cx:r,cy:i,r:se,fill:a,stroke:`#0f1419`,strokeWidth:2},e.hash)})]}),(0,E.jsx)(`div`,{className:`absolute top-0 right-0 w-3 md:w-2 h-full cursor-col-resize hover:bg-primary/20 flex items-center justify-center bg-primary/10 md:bg-transparent`,onMouseDown:Se,onTouchStart:Ce,children:(0,E.jsx)(ne,{className:`size-3 text-muted-foreground md:opacity-0 md:hover:opacity-100`})})]}),(0,E.jsx)(`div`,{className:`flex-1 min-w-[400px]`,children:i?.commits.map((e,t)=>{let r=D[(J.get(e.hash)??0)%D.length],i=ye.get(e.hash)??[],a=i.filter(e=>e.type===`branch`),o=i.filter(e=>e.type===`tag`);return(0,E.jsxs)(b,{children:[(0,E.jsx)(x,{asChild:!0,children:(0,E.jsx)(`div`,{className:`flex items-center hover:bg-muted/50 cursor-pointer text-sm border-b border-border/30 ${I?.hash===e.hash?`bg-primary/10`:``}`,style:{height:`${O}px`},onClick:()=>ge(e),children:(0,E.jsxs)(`div`,{className:`flex items-center gap-2 flex-1 min-w-0 px-2`,children:[(0,E.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground w-14 shrink-0`,children:e.abbreviatedHash}),a.map(e=>(0,E.jsx)(ce,{label:e,color:r,currentBranch:Y,onCheckout:W,onMerge:fe,onPush:me,onCreatePr:he,onDelete:pe},`branch-${e.name}`)),o.map(e=>(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 bg-amber-500/20 text-amber-500 border border-amber-500/30`,children:[(0,E.jsx)(w,{className:`size-2.5`}),e.name]},`tag-${e.name}`)),(0,E.jsx)(`span`,{className:`flex-1 truncate`,children:e.subject}),(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0 hidden sm:inline`,children:e.authorName}),(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0 w-14 text-right`,children:we(e.authorDate)})]})})}),(0,E.jsxs)(S,{children:[(0,E.jsx)(v,{onClick:()=>W(e.hash),children:`Checkout`}),(0,E.jsxs)(v,{onClick:()=>{N({type:`branch`,hash:e.hash}),F(``)},children:[(0,E.jsx)(m,{className:`size-3`}),`Create Branch...`]}),(0,E.jsx)(y,{}),(0,E.jsxs)(v,{onClick:()=>ue(e.hash),children:[(0,E.jsx)(oe,{className:`size-3`}),`Cherry Pick`]}),(0,E.jsxs)(v,{onClick:()=>de(e.hash),children:[(0,E.jsx)(n,{className:`size-3`}),`Revert`]}),(0,E.jsxs)(v,{onClick:()=>{N({type:`tag`,hash:e.hash}),F(``)},children:[(0,E.jsx)(w,{className:`size-3`}),`Create Tag...`]}),(0,E.jsx)(y,{}),(0,E.jsx)(v,{onClick:()=>_e(e),children:`View Diff`}),(0,E.jsxs)(v,{onClick:()=>q(e.hash),children:[(0,E.jsx)(h,{className:`size-3`}),`Copy Hash`]})]})]},e.hash)})})]})}),I&&(0,E.jsxs)(`div`,{className:`border-t bg-muted/30 max-h-[40%] overflow-auto`,children:[(0,E.jsxs)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:[(0,E.jsxs)(`span`,{className:`text-sm font-medium truncate`,children:[I.abbreviatedHash,` — `,I.subject]}),(0,E.jsx)(_,{variant:`ghost`,size:`icon-xs`,onClick:()=>L(null),children:`✕`})]}),(0,E.jsxs)(`div`,{className:`px-3 py-2 text-xs space-y-1`,children:[(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Author`}),(0,E.jsxs)(`span`,{children:[I.authorName,` <`,I.authorEmail,`>`]})]}),(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Date`}),(0,E.jsx)(`span`,{children:new Date(I.authorDate).toLocaleString()})]}),(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Hash`}),(0,E.jsx)(`span`,{className:`font-mono cursor-pointer hover:text-primary`,onClick:()=>q(I.hash),children:I.hash})]}),I.parents.length>0&&(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Parents`}),(0,E.jsx)(`span`,{className:`font-mono`,children:I.parents.map(e=>e.slice(0,7)).join(`, `)})]}),I.body&&(0,E.jsx)(`div`,{className:`mt-2 p-2 bg-background rounded text-xs whitespace-pre-wrap`,children:I.body})]}),(0,E.jsxs)(`div`,{className:`px-3 py-1 border-t`,children:[(0,E.jsx)(`div`,{className:`text-xs text-muted-foreground py-1`,children:le?`Loading files...`:`${R.length} file${R.length===1?``:`s`} changed`}),R.map(e=>(0,E.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5 text-xs hover:bg-muted/50 rounded px-1 cursor-pointer`,onClick:()=>V({type:`git-diff`,title:`Diff ${c(e.path)}`,closable:!0,metadata:{projectName:t,ref1:I.parents[0]??void 0,ref2:I.hash,filePath:e.path},projectId:t??null}),children:[(0,E.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:e.path}),e.additions>0&&(0,E.jsxs)(`span`,{className:`text-green-500`,children:[`+`,e.additions]}),e.deletions>0&&(0,E.jsxs)(`span`,{className:`text-red-500`,children:[`-`,e.deletions]})]},e.path))]})]}),(0,E.jsx)(ie,{open:M.type!==null,onOpenChange:e=>{e||N({type:null})},children:(0,E.jsxs)(te,{children:[(0,E.jsx)(re,{children:(0,E.jsx)(ae,{children:M.type===`branch`?`Create Branch`:`Create Tag`})}),(0,E.jsx)(r,{placeholder:M.type===`branch`?`Branch name`:`Tag name`,value:P,onChange:e=>F(e.target.value),onKeyDown:e=>{e.key===`Enter`&&P.trim()&&(M.type===`branch`?G(P.trim(),M.hash):K(P.trim(),M.hash),N({type:null}))},autoFocus:!0}),(0,E.jsxs)(ee,{children:[(0,E.jsx)(_,{variant:`outline`,onClick:()=>N({type:null}),children:`Cancel`}),(0,E.jsx)(_,{disabled:!P.trim(),onClick:()=>{M.type===`branch`?G(P.trim(),M.hash):K(P.trim(),M.hash),N({type:null})},children:`Create`})]})]})})]})}function ce({label:e,color:t,currentBranch:n,onCheckout:r,onMerge:i,onPush:a,onCreatePr:s,onDelete:c}){return(0,E.jsxs)(b,{children:[(0,E.jsx)(x,{asChild:!0,children:(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 cursor-context-menu`,style:{backgroundColor:`${t}30`,color:t,border:`1px solid ${t}50`},children:[(0,E.jsx)(m,{className:`size-2.5`}),e.name]})}),(0,E.jsxs)(S,{children:[(0,E.jsx)(v,{onClick:()=>r(e.name),children:`Checkout`}),(0,E.jsxs)(v,{onClick:()=>i(e.name),disabled:e.name===n?.name,children:[(0,E.jsx)(C,{className:`size-3`}),`Merge into current`]}),(0,E.jsx)(y,{}),(0,E.jsxs)(v,{onClick:()=>a(e.name),children:[(0,E.jsx)(g,{className:`size-3`}),`Push`]}),(0,E.jsxs)(v,{onClick:()=>s(e.name),children:[(0,E.jsx)(o,{className:`size-3`}),`Create PR`]}),(0,E.jsx)(y,{}),(0,E.jsxs)(v,{variant:`destructive`,onClick:()=>c(e.name),disabled:e.name===n?.name,children:[(0,E.jsx)(f,{className:`size-3`}),`Delete`]})]})]})}export{A as GitGraph};