@hienlh/ppm 0.9.0-beta.8 → 0.9.1

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 (159) hide show
  1. package/CHANGELOG.md +238 -0
  2. package/bun.lock +17 -0
  3. package/dist/web/assets/api-settings-BUvk6Saw.js +1 -0
  4. package/dist/web/assets/arrow-up-BYhx9ckd.js +1 -0
  5. package/dist/web/assets/browser-tab-CrkhFCaw.js +1 -0
  6. package/dist/web/assets/chat-tab-C6jpiwh7.js +8 -0
  7. package/dist/web/assets/chevron-right-5HgK6l7K.js +1 -0
  8. package/dist/web/assets/code-editor-CBIPzlP2.js +2 -0
  9. package/dist/web/assets/columns-2-cEVJHYd7.js +1 -0
  10. package/dist/web/assets/createLucideIcon-PuMiQgHl.js +1 -0
  11. package/dist/web/assets/{csv-preview-DLqYtXxt.js → csv-preview-ncSOnJSC.js} +2 -2
  12. package/dist/web/assets/database-viewer-BqOJR_zi.js +1 -0
  13. package/dist/web/assets/diff-viewer-CcLyp4eY.js +4 -0
  14. package/dist/web/assets/{dist-CALwEtco.js → dist-DIV6WgAG.js} +1 -1
  15. package/dist/web/assets/{dist-DGDPTxs1.js → dist-ovWkrgO-.js} +1 -1
  16. package/dist/web/assets/extension-webview-NiZ7Ybvv.js +3 -0
  17. package/dist/web/assets/git-graph-CoTvMrIo.js +1 -0
  18. package/dist/web/assets/index-C8byznLO.js +37 -0
  19. package/dist/web/assets/index-KwC2YrG4.css +2 -0
  20. package/dist/web/assets/jsx-runtime-kMwlnEGE.js +1 -0
  21. package/dist/web/assets/keybindings-store-DPYzBe_M.js +1 -0
  22. package/dist/web/assets/{markdown-renderer-DklUd_Gv.js → markdown-renderer-DPLdR9xc.js} +4 -4
  23. package/dist/web/assets/postgres-viewer-BeiK4lCa.js +1 -0
  24. package/dist/web/assets/settings-tab-D3AvU4lu.js +1 -0
  25. package/dist/web/assets/sqlite-viewer-nA2sD4Yv.js +1 -0
  26. package/dist/web/assets/tab-store-BOgTrqRr.js +1 -0
  27. package/dist/web/assets/table-DFevCOMd.js +1 -0
  28. package/dist/web/assets/tag-CXMT0QB6.js +1 -0
  29. package/dist/web/assets/{terminal-tab-CqRuiIFn.js → terminal-tab-BBi0pEji.js} +2 -2
  30. package/dist/web/assets/{use-monaco-theme-Dcz3aLAE.js → use-monaco-theme-B5pG2d1w.js} +1 -1
  31. package/dist/web/index.html +8 -8
  32. package/dist/web/monacoeditorwork/css.worker.bundle.js +122 -122
  33. package/dist/web/monacoeditorwork/editor.worker.bundle.js +78 -78
  34. package/dist/web/monacoeditorwork/html.worker.bundle.js +110 -110
  35. package/dist/web/monacoeditorwork/json.worker.bundle.js +108 -108
  36. package/dist/web/monacoeditorwork/ts.worker.bundle.js +81 -81
  37. package/dist/web/sw.js +1 -1
  38. package/docs/code-standards.md +128 -1
  39. package/docs/codebase-summary.md +79 -12
  40. package/docs/extension-development-guide.md +532 -0
  41. package/docs/project-changelog.md +51 -1
  42. package/docs/project-roadmap.md +9 -3
  43. package/docs/streaming-input-guide.md +267 -0
  44. package/docs/system-architecture.md +432 -3
  45. package/package.json +6 -3
  46. package/packages/ext-database/package.json +41 -0
  47. package/packages/ext-database/src/connection-tree.ts +142 -0
  48. package/packages/ext-database/src/extension.ts +346 -0
  49. package/packages/ext-database/src/query-panel.ts +120 -0
  50. package/packages/ext-database/src/table-viewer-panel.ts +410 -0
  51. package/packages/ext-database/tsconfig.json +8 -0
  52. package/packages/vscode-compat/package.json +16 -0
  53. package/packages/vscode-compat/src/commands.ts +39 -0
  54. package/packages/vscode-compat/src/context.ts +65 -0
  55. package/packages/vscode-compat/src/disposable.ts +21 -0
  56. package/packages/vscode-compat/src/env.ts +20 -0
  57. package/packages/vscode-compat/src/event-emitter.ts +28 -0
  58. package/packages/vscode-compat/src/index.ts +93 -0
  59. package/packages/vscode-compat/src/not-supported.ts +15 -0
  60. package/packages/vscode-compat/src/types.ts +167 -0
  61. package/packages/vscode-compat/src/uri.ts +65 -0
  62. package/packages/vscode-compat/src/window.ts +229 -0
  63. package/packages/vscode-compat/src/workspace.ts +76 -0
  64. package/packages/vscode-compat/tsconfig.json +10 -0
  65. package/snapshot-state.md +1526 -0
  66. package/src/cli/commands/autostart.ts +1 -1
  67. package/src/cli/commands/ext-cmd.ts +121 -0
  68. package/src/cli/commands/restart.ts +9 -1
  69. package/src/cli/commands/status.ts +19 -0
  70. package/src/index.ts +5 -3
  71. package/src/providers/claude-agent-sdk.ts +221 -17
  72. package/src/providers/cli-provider-base.ts +6 -0
  73. package/src/server/index.ts +55 -155
  74. package/src/server/routes/chat.ts +81 -11
  75. package/src/server/routes/extensions.ts +81 -0
  76. package/src/server/routes/project-scoped.ts +2 -0
  77. package/src/server/routes/settings.ts +27 -0
  78. package/src/server/routes/workspace.ts +35 -0
  79. package/src/server/ws/chat.ts +9 -3
  80. package/src/server/ws/extensions.ts +175 -0
  81. package/src/services/account-selector.service.ts +14 -5
  82. package/src/services/account.service.ts +20 -15
  83. package/src/services/claude-usage.service.ts +29 -24
  84. package/src/services/cloud-ws.service.ts +228 -0
  85. package/src/services/cloud.service.ts +11 -6
  86. package/src/services/contribution-registry.ts +110 -0
  87. package/src/services/db.service.ts +181 -4
  88. package/src/services/extension-host-worker.ts +160 -0
  89. package/src/services/extension-installer.ts +112 -0
  90. package/src/services/extension-manifest.ts +65 -0
  91. package/src/services/extension-rpc-handlers.ts +235 -0
  92. package/src/services/extension-rpc.ts +105 -0
  93. package/src/services/extension.service.ts +228 -0
  94. package/src/services/mcp-config.service.ts +15 -6
  95. package/src/services/supervisor.ts +271 -25
  96. package/src/types/api.ts +1 -0
  97. package/src/types/chat.ts +4 -0
  98. package/src/types/extension-messages.ts +64 -0
  99. package/src/types/extension.ts +131 -0
  100. package/src/web/app.tsx +69 -48
  101. package/src/web/components/chat/account-rotation-settings.tsx +163 -0
  102. package/src/web/components/chat/chat-history-bar.tsx +106 -10
  103. package/src/web/components/chat/chat-tab.tsx +15 -10
  104. package/src/web/components/chat/chat-welcome.tsx +148 -0
  105. package/src/web/components/chat/message-list.tsx +19 -6
  106. package/src/web/components/chat/session-picker.tsx +80 -32
  107. package/src/web/components/chat/usage-badge.tsx +68 -8
  108. package/src/web/components/editor/editor-breadcrumb.tsx +20 -29
  109. package/src/web/components/extensions/extension-inputbox.tsx +92 -0
  110. package/src/web/components/extensions/extension-quickpick.tsx +194 -0
  111. package/src/web/components/extensions/extension-tree-view.tsx +240 -0
  112. package/src/web/components/extensions/extension-webview.tsx +83 -0
  113. package/src/web/components/layout/command-palette.tsx +22 -2
  114. package/src/web/components/layout/editor-panel.tsx +163 -18
  115. package/src/web/components/layout/mobile-nav.tsx +2 -1
  116. package/src/web/components/layout/sidebar.tsx +21 -3
  117. package/src/web/components/layout/status-bar.tsx +64 -0
  118. package/src/web/components/layout/tab-bar.tsx +2 -0
  119. package/src/web/components/layout/tab-content.tsx +5 -0
  120. package/src/web/components/layout/upgrade-banner.tsx +15 -5
  121. package/src/web/components/settings/change-password-section.tsx +128 -0
  122. package/src/web/components/settings/extension-manager-section.tsx +214 -0
  123. package/src/web/components/settings/settings-tab.tsx +9 -2
  124. package/src/web/components/shared/connection-lost-overlay.tsx +89 -0
  125. package/src/web/hooks/use-chat.ts +28 -0
  126. package/src/web/hooks/use-extension-ws.ts +181 -0
  127. package/src/web/hooks/use-global-keybindings.ts +18 -2
  128. package/src/web/hooks/use-server-reload.ts +9 -0
  129. package/src/web/hooks/use-url-sync.ts +173 -21
  130. package/src/web/stores/connection-store.ts +39 -0
  131. package/src/web/stores/extension-store.ts +204 -0
  132. package/src/web/stores/panel-store.ts +63 -9
  133. package/src/web/stores/panel-utils.ts +145 -3
  134. package/src/web/stores/settings-store.ts +7 -2
  135. package/src/web/stores/tab-store.ts +2 -1
  136. package/test-session-ops.mjs +444 -0
  137. package/test-tokens.mjs +212 -0
  138. package/tsconfig.json +3 -1
  139. package/dist/web/assets/api-settings-D21InCnR.js +0 -1
  140. package/dist/web/assets/arrow-up--LjUXLEt.js +0 -1
  141. package/dist/web/assets/browser-tab-BEe89aSD.js +0 -1
  142. package/dist/web/assets/chat-tab-9lqvWozA.js +0 -7
  143. package/dist/web/assets/chevron-right-CHnjJt4E.js +0 -1
  144. package/dist/web/assets/code-editor-COAIZx-B.js +0 -2
  145. package/dist/web/assets/columns-2-DbesTfa7.js +0 -1
  146. package/dist/web/assets/database-viewer-aRR9n_Ui.js +0 -1
  147. package/dist/web/assets/diff-viewer-C4KMvpHr.js +0 -4
  148. package/dist/web/assets/dist-CVTST7Gc.js +0 -1
  149. package/dist/web/assets/git-graph-CfJjl4E3.js +0 -1
  150. package/dist/web/assets/index-Db8uky1a.css +0 -2
  151. package/dist/web/assets/index-DxZuwBDe.js +0 -37
  152. package/dist/web/assets/jsx-runtime-BRW_vwa9.js +0 -1
  153. package/dist/web/assets/keybindings-store-_uWVCZMv.js +0 -1
  154. package/dist/web/assets/postgres-viewer-DEAvAyaX.js +0 -1
  155. package/dist/web/assets/settings-tab-BQedc-No.js +0 -1
  156. package/dist/web/assets/sqlite-viewer-BPA5idzT.js +0 -1
  157. package/dist/web/assets/tab-store-DhK6EpBT.js +0 -1
  158. package/dist/web/assets/table-CQVQM2SB.js +0 -1
  159. package/dist/web/assets/tag-Q2dZiSPX.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,7 +1,245 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.9.1] - 2026-04-03
4
+
5
+ **"Open Platform"** — Multi-provider AI, MCP management, and extension architecture.
6
+
7
+ ### Added — Extension System
8
+ - **Extension architecture (Phase 1-6)**: VSCode-compatible npm extensions with Bun Worker isolation, RPC protocol, state persistence, and contribution registry
9
+ - **@ppm/vscode-compat API shim**: commands, window (showInformationMessage, showErrorMessage, showQuickPick, showInputBox, createTreeView, createWebviewPanel, createStatusBarItem), workspace, EventEmitter
10
+ - **Extension UI components**: StatusBar items, TreeView with color dots/badges/actions, WebviewPanel (iframe sandbox), QuickPick/InputBox dialogs
11
+ - **WS bridge**: Real-time extension↔browser communication for tree updates, command execution, webview messaging
12
+ - **ext-database extension**: Database viewer with connection tree (color dots, PG/DB badges, action buttons), table viewer webview (data grid, inline editing, pagination, SQL panel), add connection flow
13
+ - **Extension Manager UI**: Install/uninstall/enable/disable extensions in Settings, dev-link for local development
14
+ - **CLI support**: `ppm ext install`, `ppm ext dev-link`, extension lifecycle management
15
+
16
+ ### Added — Multi-Provider AI
17
+ - **Provider interface**: `AIProvider` with optional capabilities (`abortQuery?`, `getMessages?`, `listSessionsByDir?`)
18
+ - **CliProvider base class**: Abstract base for CLI-spawning providers (Cursor, Codex, Gemini)
19
+ - **Cursor CLI integration**: `CursorCliProvider` with NDJSON streaming, event mapping, history reader, workspace trust auto-retry
20
+ - **Provider selector UI**: Choose provider when creating chat sessions
21
+
22
+ ### Added — MCP Management
23
+ - **MCP server CRUD**: REST API, SQLite storage, Settings UI, add/edit/delete servers
24
+ - **Auto-import**: Reads `~/.claude.json` on first access, skips existing/invalid entries
25
+ - **SDK integration**: Servers passed as `mcpServers`, tools auto-allowed via `mcp__*` wildcard
26
+
27
+ ### Added — Other
28
+ - **Rate-limit auto-retry**: SDK retries on rate_limit/server_error with exponential backoff (15s, 30s, 60s) up to 3 attempts
29
+ - **Account rate-limit switching**: Auto-switch to next account on rate limit, skip 5hr-exhausted accounts
30
+ - **Increased max turns**: Default maxTurns bumped from 100 to 1000
31
+
32
+ ### Fixed
33
+ - **Streaming auth loop**: Auth errors break streaming loop, cooldown account, tear down session
34
+ - **Streaming session resource leak**: `finally` block properly closes SDK subprocess and generator
35
+ - **Session mapping on resume**: Preserve existing sdk_id mapping to prevent orphaning JSONL history
36
+ - **Extension broadcast**: Contributions update broadcast on activate/deactivate
37
+ - **Extension webview**: Open tab when extension creates a webview panel
38
+ - **Extension auto-activate**: Auto-activate after dev-link install
39
+
40
+ ## [0.8.94] - 2026-04-02
41
+
42
+ ### Fixed
43
+ - **Session JSONL "not found" after disconnect/restart**: Debug endpoint relied on in-memory `projectPath` which was lost when session cleanup timer expired or server restarted. Now persists `project_path` in `session_map` DB table (migration 11) and falls back to DB lookup when in-memory state is gone.
44
+ - **Session mapping missing project info**: `setSessionMapping` now saves `projectName` and `projectPath` at both session creation and SDK init, ensuring resumed sessions can locate their JSONL files.
45
+
46
+ ## [0.8.93] - 2026-04-02
47
+
48
+ ### Removed
49
+ - **Cloud upgrade command**: Removed remote upgrade trigger from cloud — upgrade is now local-only (CLI `ppm upgrade` or UI banner)
50
+
51
+ ## [0.8.92] - 2026-04-02
52
+
53
+ ### Fixed
54
+ - **Fork UX**: Forked session now shows conversation history up to the fork point, puts the forked user message in input for editing instead of auto-sending
55
+ - **Fork at first message**: Forking the first user message creates a fresh empty session instead of erroring
56
+
57
+ ## [0.8.91] - 2026-04-02
58
+
59
+ ### Added
60
+ - **Session delete cleanup**: Deleting a session now removes JSONL files, DB mappings, titles, and pins; kills orphaned CLI processes
61
+ - **Mid-message fork**: Fork a session at a specific message via `forkAtMessage()` SDK capability with dynamic import
62
+ - **Compact handling**: Detect SDK compact events (`status`/`compact_boundary`) and forward "compacting..." status to frontend
63
+ - **Change password UI**: Settings panel for changing password with current/new password fields
64
+
65
+ ### Fixed
66
+ - **Orphaned session on fork failure**: Restructured fork route to create PPM session only after SDK fork succeeds
67
+ - **Compact status stale badge**: Reset `compactStatus` on session change to prevent stale "compacting..." indicator
68
+ - **Cloud heartbeat device name**: Include device name in heartbeat payloads for cloud sync
69
+ - **Upgrade banner compact**: Reduced padding and fixed mobile overlap with device name badge
70
+
71
+ ## [0.8.90] - 2026-04-02
72
+
73
+ ### Fixed
74
+ - **Upgrade banner height**: Reduced padding and button sizes for a more compact banner
75
+ - **Mobile banner overlap**: Device name badge now shifts down when upgrade banner is visible, preventing overlap on mobile
76
+
77
+ ## [0.8.89] - 2026-04-02
78
+
79
+ ### Added
80
+ - **Account delete button**: Trash icon on each account card in Usage & Accounts panel with overlay confirmation popup
81
+ - **Expired account UX**: Expired temporary accounts (no refresh token) are dimmed, toggle/export hidden — only delete available
82
+
83
+ ### Fixed
84
+ - **Account panel showing all accounts**: Usage & Accounts panel now always displays all accounts including expired temporary ones (previously filtered out)
85
+ - **MCP config table missing**: `McpConfigService.list()` gracefully returns empty object when `mcp_servers` table doesn't exist yet
86
+ - **Account error logging**: Consistent error message formatting in auto-refresh and pre-flight refresh logs
87
+
88
+ ## [0.8.88] - 2026-04-01
89
+
90
+ ### Added
91
+ - **Multi-provider architecture**: Generic AI provider system — `AIProvider` interface, `CliProvider` base class, `ProviderRegistry`, Cursor CLI integration with NDJSON streaming
92
+ - **MCP server management**: Configure Model Context Protocol servers via Settings UI — SQLite storage, REST API (CRUD + import), SDK integration with `mcp__*` wildcard
93
+ - **SDK streaming input**: Persistent `AsyncGenerator`-based chat with message channel pattern replacing one-shot queries
94
+
95
+ ### Fixed
96
+ - **SDK process leak**: Prevent orphaned SDK processes on WebSocket disconnect and cancel
97
+ - **Cursor history**: Filter out `<user_info>` system context messages from imported sessions
98
+
99
+ ## [0.8.87] - 2026-04-01
100
+
101
+ ### Fixed
102
+ - **Session message loss on auth retry**: OAuth token expiry mid-query (e.g. during long bash commands) caused retry to create a new SDK session, overwriting the session mapping and losing all prior messages. Retry now resumes existing session instead.
103
+ - **Session CWD fallback to homedir**: `resumeSession()` didn't restore `projectPath` from SDK metadata, causing queries to use `$HOME` as CWD and JSONL to be stored under wrong project. Now extracts `cwd` from SDK session data.
104
+
105
+ ## [0.8.85] - 2026-04-01
106
+
107
+ ### Added
108
+ - **Connection lost overlay**: Full-screen overlay when API unreachable for >15s — tunnel mode links to PPM Cloud for new URL, localhost mode shows restart hint
109
+
110
+ ### Fixed
111
+ - **Double-Shift command palette**: Only triggers when Shift pressed alone — no longer fires during Shift+key combos (uppercase typing, shortcuts)
112
+
113
+ ## [0.8.84] - 2026-04-01
114
+
115
+ ### Fixed
116
+ - **Account import overwrite**: Import now updates tokens for existing accounts even when they already have a (possibly expired/corrupt) refresh token — previously skipped, causing "0 imported"
117
+ - **Tunnel probe adopted PID**: Supervisor now monitors adopted tunnel processes and respawns if they die
118
+
119
+ ### Added
120
+ - **Account rotation settings**: Settings gear icon in Usage & Accounts panel for rotation/retry config
121
+
122
+ ## [0.8.83] - 2026-04-01
123
+
124
+ ### Fixed
125
+ - **Account label desync**: Status bar now shows the actual streaming account label (real-time) instead of stale `lastPickedId` from usage polling — matches "via X" shown in chat messages when using multi-account round-robin
126
+
127
+ ## [0.8.82] - 2026-04-01
128
+
129
+ ### Added
130
+ - **Thinking block auto-scroll**: Thinking content now auto-scrolls to bottom during streaming using `StickToBottom`
131
+ - **Expandable recent sessions**: "Show more" / "Show less" button on chat welcome and empty panel — fetches up to 20 sessions, shows 5 initially
132
+
133
+ ## [0.8.81] - 2026-04-01
134
+
135
+ ### Fixed
136
+ - **Usage polling**: Re-wire `startUsagePolling()` into server startup — accidentally removed during supervisor refactor, causing prod to never auto-fetch usage limits (only manual refresh worked)
137
+
138
+ ## [0.8.80] - 2026-04-01
139
+
140
+ ### Added
141
+ - **Cloud command ack**: Device sends `command_ack` immediately when receiving a cloud command, before processing — allows cloud to confirm receipt and update UI
142
+
143
+ ## [0.8.79] - 2026-04-01
144
+
145
+ ### Added
146
+ - **Chat welcome screen**: New chat tabs now show pinned and recent sessions (same as empty panel) instead of a bare placeholder — quick access to continue previous conversations
147
+
148
+ ## [0.8.78] - 2026-04-01
149
+
150
+ ### Fixed
151
+ - **Cloud version reporting**: Supervisor heartbeat now reads version from running server child (via `status.json`) instead of its own captured constant — after `ppm restart` or `bunx @hienlh/ppm@latest restart`, cloud dashboard correctly reflects the updated version
152
+
153
+ ## [0.8.77] - 2026-04-01
154
+
155
+ ### Added
156
+ - **Deterministic tab IDs**: Tabs now use `{type}:{identifier}` format (e.g., `editor:src/index.ts`) instead of random UUIDs — enables deduplication, shareable URLs, and cross-device persistence
157
+ - **Type-based URLs**: URLs reflect tab content — `/project/my-app/editor/src/index.ts`, `/project/my-app/chat/claude-agent-sdk/session-abc`
158
+ - **Backend workspace sync**: New `workspace_state` table (DB v10) with GET/PUT `/api/project/:name/workspace` endpoints — tab layout persists server-side with per-project debounce and latest-wins merge
159
+ - **Deep linking**: Opening a URL auto-restores workspace from server and focuses the target tab
160
+ - **Split-duplicate support**: Same file can open in multiple panels using `@panel-id` suffix on non-singleton tab types
161
+
162
+ ### Changed
163
+ - **URL format**: From `/project/{name}/tab/{randomId}` to `/project/{name}/{type}/{path}` — old random-ID URLs gracefully ignored
164
+ - **Tab migration**: `migrateTabIds()` automatically converts old random tab IDs to deterministic format on project load
165
+ - **Singleton dedup**: Only `git-graph` and `settings` tabs are globally deduplicated; editor/chat/terminal tabs allow split duplicates
166
+
167
+ ## [0.8.76] - 2026-04-01
168
+
169
+ ### Fixed
170
+ - **SDK error messages**: 500/5xx server errors and 429 rate-limits now show correct user-facing messages instead of confusing "unknown API error" with debug instructions
171
+ - **Session title on resume**: Prioritize DB-stored title when resuming a chat session
172
+
173
+ ## [0.8.75] - 2026-04-01
174
+
175
+ ### Changed
176
+ - **Tunnel always enabled**: `ppm start` now always starts Cloudflare tunnel — `--share` flag deprecated (still accepted, no-op)
177
+
178
+ ## [0.8.74] - 2026-04-01
179
+
180
+ ### Fixed
181
+ - **Cloud WS reconnect loop**: Stale WebSocket closure handlers from replaced connections no longer reset module state
182
+ - **Cloud WS auth race**: Delay heartbeat/queue flush 500ms after auth to let server complete async DB auth — prevents 4002 rejection
183
+
184
+ ## [0.9.0-beta.10] - 2026-03-31
185
+
186
+ ### Merged from main (0.8.69 → 0.8.72)
187
+ - **Supervisor state machine**: States `running → paused → upgrading` with promise-based wait/resume
188
+ - **Cloud WebSocket client**: Persistent WS connection replacing HTTP heartbeat — auto-reconnect with backoff
189
+ - **Remote commands via Cloud**: Supervisor handles restart/stop/upgrade/resume/status via Cloud WS
190
+ - **Pin/Save sessions**: Pin important chat sessions to top of history — persisted in DB across devices
191
+ - **Editor breadcrumb scrolling**: Enable scrolling in breadcrumb dropdown menus
192
+
193
+ ## [0.9.0-beta.9] - 2026-03-31
194
+
195
+ ### Merged from main (0.8.68)
196
+ - **Hot-reload timer leak**: Background polling timers (usage fetch, account refresh, cloud heartbeat) leaked on Bun `--hot` reload — module-level vars reset but old timers kept running. Moved timer refs to `globalThis` to survive reloads.
197
+
3
198
  ## [0.9.0-beta.8] - 2026-03-30
4
199
 
200
+ ## [0.8.72] - 2026-03-31
201
+
202
+ ### Added
203
+ - **Supervisor state machine**: States `running → paused → upgrading` with promise-based wait/resume. Supervisor pauses after 10 consecutive crashes, resumes via `ppm restart --force` or SIGUSR2
204
+ - **Cloud WebSocket client**: Persistent WS connection from supervisor to PPM Cloud replacing HTTP heartbeat — auto-reconnect with exponential backoff + jitter, 60s heartbeat, 50-message offline queue
205
+ - **Remote commands via Cloud**: Supervisor handles restart/stop/upgrade/resume/status commands received from Cloud WS
206
+ - **`ppm restart --force`**: Resume a paused supervisor (crashed too many times)
207
+ - **Status CLI state display**: `ppm status` shows paused/upgrading state with reason, timestamp, and last crash error
208
+
209
+ ### Changed
210
+ - **Foreground mode removed**: `ppm start` no longer accepts `-f`/`--foreground` — always runs as supervised daemon
211
+ - **Heartbeat via WS**: Cloud heartbeat migrated from HTTP polling (5min) to WebSocket (60s), includes `appVersion`, `serverPid`, `uptime`
212
+
213
+ ### Fixed
214
+ - **Upgrade failure recovery**: `selfReplace` failure now correctly resets state from "upgrading" back to "running" and notifies Cloud
215
+
216
+ ## [0.8.71] - 2026-03-31
217
+
218
+ ### Added
219
+ - **Pin/Save sessions**: Pin important chat sessions to always appear at the top of history, empty state, and session picker — persisted in DB across devices
220
+ - Mobile-friendly: pin/rename/delete buttons always visible on mobile, hover-reveal on desktop
221
+
222
+ ### Fixed
223
+ - Fixed duplicate import in chat routes
224
+ - Fixed session action buttons misaligned when date column has variable width
225
+
226
+ ## [0.8.70] - 2026-03-31
227
+
228
+ ### Added
229
+ - **Recent chats on empty state**: When no tabs are open, show up to 5 recent chat sessions for quick access — click to reopen directly
230
+
231
+ ## [0.8.69] - 2026-03-31
232
+
233
+ ### Fixed
234
+ - **Auth 401 auto-retry**: Detect 401 errors returned as assistant text content (SDK doesn't always set error field) — refresh OAuth token and retry with fresh session automatically instead of showing raw error to user
235
+ - **Result-level 401 retry**: 401 in SDK result events now triggers token refresh + retry (previously only refreshed without retrying)
236
+
237
+ ### Added
238
+ - **Account retry notification**: FE shows inline status when auth retry happens (e.g. "↻ Token refreshed — retrying with **Alex**...")
239
+ - **Session debug button**: Bug icon in chat toolbar copies session IDs + JSONL path to clipboard for quick debugging
240
+
241
+ ## [0.8.68] - 2026-03-31
242
+
5
243
  ### Fixed
6
244
  - **SDK process leak**: Prevent claude-agent-sdk subprocess leak on WS disconnect and cancel — cleanup timer now starts regardless of streaming state, orphaned sessions cleaned up in 30s, abortQuery fully teardowns subprocess
7
245
 
package/bun.lock CHANGED
@@ -27,6 +27,7 @@
27
27
  "lucide-react": "^0.577.0",
28
28
  "marked": "^17.0.4",
29
29
  "mermaid": "^11.13.0",
30
+ "monaco-editor": "0.55.1",
30
31
  "next-themes": "^0.4.6",
31
32
  "postgres": "^3.4.8",
32
33
  "qrcode-terminal": "^0.12.0",
@@ -57,11 +58,23 @@
57
58
  "tailwindcss": "^4.2.1",
58
59
  "vite": "^8.0.0",
59
60
  "vite-plugin-pwa": "^1.2.0",
61
+ "workbox-precaching": "^7.4.0",
60
62
  },
61
63
  "peerDependencies": {
62
64
  "typescript": "^5.9.3",
63
65
  },
64
66
  },
67
+ "packages/ext-database": {
68
+ "name": "@ppm/ext-database",
69
+ "version": "0.1.0",
70
+ },
71
+ "packages/vscode-compat": {
72
+ "name": "@ppm/vscode-compat",
73
+ "version": "0.1.0",
74
+ "peerDependencies": {
75
+ "typescript": "^5.0.0",
76
+ },
77
+ },
65
78
  },
66
79
  "packages": {
67
80
  "@antfu/install-pkg": ["@antfu/install-pkg@1.1.0", "", { "dependencies": { "package-manager-detector": "^1.3.0", "tinyexec": "^1.0.1" } }, "sha512-MGQsmw10ZyI+EJo45CdSER4zEb+p31LpDAFp2Z3gkSd1yqVZGi0Ebx++YTEMonJy4oChEMLsxZ64j8FH6sSqtQ=="],
@@ -452,6 +465,10 @@
452
465
 
453
466
  "@oxc-project/types": ["@oxc-project/types@0.115.0", "", {}, "sha512-4n91DKnebUS4yjUHl2g3/b2T+IUdCfmoZGhmwsovZCDaJSs+QkVAM+0AqqTxHSsHfeiMuueT75cZaZcT/m0pSw=="],
454
467
 
468
+ "@ppm/ext-database": ["@ppm/ext-database@workspace:packages/ext-database"],
469
+
470
+ "@ppm/vscode-compat": ["@ppm/vscode-compat@workspace:packages/vscode-compat"],
471
+
455
472
  "@profoundlogic/hogan": ["@profoundlogic/hogan@3.0.4", "", { "dependencies": { "nopt": "1.0.10" }, "bin": { "hulk": "bin/hulk" } }, "sha512-pmNVGuooS30Mm7YbZd5T7E5zYVO6D5Ct91sn4T39mUvMUc3sCGridcnhAufL1/Bz2QzAtzEn0agNrdk3+5yWzw=="],
456
473
 
457
474
  "@radix-ui/number": ["@radix-ui/number@1.1.1", "", {}, "sha512-MkKCwxlXTgz6CFoJx3pCwn07GKp36+aZyu/u2Ln2VrA5DcdyCZkASEDBTd8x5whTQQL5CiYf4prXKLcgQdv29g=="],
@@ -0,0 +1 @@
1
+ import{r as e}from"./chunk-CFjPhJqf.js";import{t}from"./api-client-BfBM3I7n.js";var n=e({addAccount:()=>a,deleteAccount:()=>o,exchangeOAuthCode:()=>d,getAISettings:()=>h,getAccountSettings:()=>c,getAccounts:()=>r,getActiveAccount:()=>i,getAllAccountUsages:()=>f,getOAuthUrl:()=>u,getProxySettings:()=>_,importAccounts:()=>p,patchAccount:()=>s,updateAISettings:()=>g,updateAccountSettings:()=>l,updateDeviceName:()=>m,updateProxySettings:()=>v});function r(){return t.get(`/api/accounts`)}function i(){return t.get(`/api/accounts/active`)}function a(e){return t.post(`/api/accounts`,e)}function o(e){return t.del(`/api/accounts/${e}`)}function s(e,n){return t.patch(`/api/accounts/${e}`,n)}function c(){return t.get(`/api/accounts/settings`)}function l(e){return t.put(`/api/accounts/settings`,e)}function u(){return t.get(`/api/accounts/oauth/url`)}function d(e,n){return t.post(`/api/accounts/oauth/exchange`,{code:e,state:n})}function f(){return t.get(`/api/accounts/usage`)}function p(e){return t.post(`/api/accounts/import`,e)}function m(e){return t.put(`/api/settings/device-name`,{device_name:e})}function h(){return t.get(`/api/settings/ai`)}function g(e){return t.put(`/api/settings/ai`,e)}function _(){return t.get(`/api/settings/proxy`)}function v(e){return t.put(`/api/settings/proxy`,e)}export{h as a,i as c,_ as d,p as f,v as g,l as h,d as i,f as l,g as m,n,c as o,s as p,o as r,r as s,a as t,u};
@@ -0,0 +1 @@
1
+ import{t as e}from"./createLucideIcon-PuMiQgHl.js";var t=e(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]);export{t};
@@ -0,0 +1 @@
1
+ import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{l as n,t as r}from"./tab-store-BOgTrqRr.js";import{t as i}from"./jsx-runtime-kMwlnEGE.js";import{t as a}from"./api-client-BfBM3I7n.js";import{$ as o,K as s,ct as c,st as l}from"./index-C8byznLO.js";var u=e(t(),1),d=i();function f({metadata:e,tabId:t}){let i=e?.port||0,[f,p]=(0,u.useState)(i?String(i):``),[m,h]=(0,u.useState)(null),[g,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(null),b=(0,u.useRef)(null),x=r(e=>e.updateTab),S=(0,u.useCallback)(async n=>{_(!0),y(null),h(null);try{h((await a.post(`/api/preview/tunnel`,{port:n})).url),t&&x(t,{title:`localhost:${n}`,metadata:{...e,port:n}})}catch(e){y(e.message||`Failed to start tunnel for port ${n}`)}finally{_(!1)}},[t,e,x]),C=(0,u.useCallback)(async()=>{let e=parseInt(f,10);if(e){try{await a.del(`/api/preview/tunnel/${e}`)}catch{}h(null),t&&x(t,{title:`Browser`})}},[f,t,x]);return m?(0,d.jsxs)(`div`,{className:`flex flex-col h-full w-full bg-background`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1.5 border-b border-border bg-surface shrink-0`,children:[(0,d.jsx)(c,{className:`size-4 text-text-subtle shrink-0`}),(0,d.jsxs)(`span`,{className:`text-xs text-text-primary font-medium`,children:[`localhost:`,f]}),(0,d.jsxs)(`span`,{className:`text-xs text-text-subtle truncate ml-1`,children:[`(`,m,`)`]}),(0,d.jsx)(`div`,{className:`flex-1`}),(0,d.jsx)(`button`,{onClick:()=>{if(b.current){let e=b.current.src;b.current.src=``,requestAnimationFrame(()=>{b.current&&(b.current.src=e)})}},className:`p-1.5 rounded hover:bg-surface-elevated transition-colors`,title:`Reload`,children:(0,d.jsx)(o,{className:`size-3.5`})}),(0,d.jsx)(`button`,{onClick:()=>window.open(m,`_blank`),className:`p-1.5 rounded hover:bg-surface-elevated transition-colors`,title:`Open in browser`,children:(0,d.jsx)(n,{className:`size-3.5`})}),(0,d.jsx)(`button`,{onClick:C,className:`p-1.5 rounded hover:bg-surface-elevated text-red-400 transition-colors`,title:`Stop tunnel`,children:(0,d.jsx)(s,{className:`size-3.5`})})]}),(0,d.jsxs)(`div`,{className:`flex-1 relative min-h-0`,children:[(0,d.jsx)(`iframe`,{ref:b,src:m,className:`w-full h-full border-0`,sandbox:`allow-scripts allow-forms allow-same-origin allow-popups allow-modals`,onLoad:()=>_(!1)}),g&&(0,d.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-background/50`,children:(0,d.jsx)(l,{className:`size-5 animate-spin text-text-secondary`})})]})]}):(0,d.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 p-6`,children:[(0,d.jsx)(c,{className:`size-12 text-text-subtle`}),(0,d.jsx)(`h2`,{className:`text-lg font-medium text-text-primary`,children:`Open Localhost`}),(0,d.jsx)(`p`,{className:`text-sm text-text-secondary text-center max-w-sm`,children:`Enter the port of your local dev server to preview it here.`}),(0,d.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=parseInt(f,10);t>=1&&t<=65535?S(t):y(`Port must be 1-65535`)},className:`flex items-center gap-2 w-full max-w-xs`,children:[(0,d.jsxs)(`div`,{className:`flex-1 flex items-center gap-2 px-3 py-2.5 rounded-lg bg-surface border border-border focus-within:border-accent/50 transition-colors`,children:[(0,d.jsx)(`span`,{className:`text-sm text-text-subtle shrink-0`,children:`localhost:`}),(0,d.jsx)(`input`,{type:`number`,value:f,onChange:e=>p(e.target.value),placeholder:`3000`,min:1,max:65535,autoFocus:!0,className:`flex-1 bg-transparent text-sm text-text-primary outline-none placeholder:text-text-subtle min-w-0 [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none`})]}),(0,d.jsx)(`button`,{type:`submit`,disabled:g||!f,className:`px-4 py-2.5 rounded-lg bg-accent text-white text-sm font-medium hover:bg-accent/90 disabled:opacity-50 transition-colors shrink-0`,children:g?(0,d.jsx)(l,{className:`size-4 animate-spin`}):`Open`})]}),v&&(0,d.jsx)(`p`,{className:`text-sm text-red-400`,children:v}),g&&(0,d.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-text-secondary`,children:[(0,d.jsx)(l,{className:`size-4 animate-spin`}),(0,d.jsx)(`span`,{children:`Starting tunnel... (may take a few seconds)`})]})]})}export{f as BrowserTab};
@@ -0,0 +1,8 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-client-BfBM3I7n.js","assets/chunk-CFjPhJqf.js"])))=>i.map(i=>d[i]);
2
+ import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import"./react-dom-Bpkvzu3U.js";import{t as n}from"./createLucideIcon-PuMiQgHl.js";import{t as r}from"./arrow-up-BYhx9ckd.js";import{t as i}from"./chevron-right-5HgK6l7K.js";import{n as a,t as o}from"./markdown-renderer-DPLdR9xc.js";import{t as s}from"./columns-2-cEVJHYd7.js";import{l as c,n as l,t as u}from"./tab-store-BOgTrqRr.js";import{t as d}from"./tag-CXMT0QB6.js";import{t as f}from"./preload-helper-Bf_JiD2A.js";import{t as p}from"./jsx-runtime-kMwlnEGE.js";import"./dist-DIV6WgAG.js";import{n as m,r as h,t as g}from"./utils-BNytJOb1.js";import{i as _,r as v,t as y}from"./api-client-BfBM3I7n.js";import{a as b,c as x,f as S,h as C,i as w,l as T,o as E,p as D,r as O,s as k,t as A,u as j}from"./api-settings-BUvk6Saw.js";import{$ as ee,A as M,At as N,C as P,Ct as F,D as I,Dt as L,E as R,Et as z,G as B,J as V,K as H,O as U,Ot as W,Q as G,R as K,St as q,T as J,W as te,X as ne,Y as re,Z as Y,_t as X,at as ie,bt as ae,c as oe,ct as se,d as ce,dt as le,et as ue,f as de,gt as fe,h as pe,i as me,k as he,kt as ge,l as _e,m as ve,nt as ye,o as be,ot as xe,p as Se,pt as Ce,q as we,r as Te,rt as Ee,s as De,st as Z,t as Oe,tt as ke,u as Ae,ut as je,w as Me,wt as Ne,yt as Pe}from"./index-C8byznLO.js";import"./chunk-GEFDOKGD-D-pKjlVd.js";import"./src-BqX54PbV.js";import"./chunk-7R4GIKGN-Dv-4cAYn.js";import"./chunk-HHEYEP7N-C7vxA5i9.js";import"./dist-CSJdAyA9.js";import"./chunk-PU5JKC2W-ek7k4QVB.js";import"./chunk-MX3YWQON-BpS_PtKp.js";import"./chunk-YBOYWFTD-rQG3QH5s.js";import"./chunk-PQ6SQG4A-TF58UVMU.js";import"./chunk-KYZI473N-Bb0MCaIO.js";import"./chunk-O4XLMI2P-nDhi_cVu.js";import"./chunk-GLR3WWYH-DKikpoJM.js";import"./chunk-XPW4576I-BPQQBakK.js";var Fe=n(`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`}]]),Ie=n(`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`}]]),Le=n(`clipboard-check`,[[`rect`,{width:`8`,height:`4`,x:`8`,y:`2`,rx:`1`,ry:`1`,key:`tgr4d6`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`,key:`116196`}],[`path`,{d:`m9 14 2 2 4-4`,key:`df797q`}]]),Re=n(`clipboard-list`,[[`rect`,{width:`8`,height:`4`,x:`8`,y:`2`,rx:`1`,ry:`1`,key:`tgr4d6`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`,key:`116196`}],[`path`,{d:`M12 11h4`,key:`1jrz19`}],[`path`,{d:`M12 16h4`,key:`n85exb`}],[`path`,{d:`M8 11h.01`,key:`1dfujw`}],[`path`,{d:`M8 16h.01`,key:`18s6g9`}]]),ze=n(`hand`,[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]),Be=n(`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`}]]),Ve=n(`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`}]]),He=n(`list-ordered`,[[`path`,{d:`M11 5h10`,key:`1cz7ny`}],[`path`,{d:`M11 12h10`,key:`1438ji`}],[`path`,{d:`M11 19h10`,key:`11t30w`}],[`path`,{d:`M4 4h1v5`,key:`10yrso`}],[`path`,{d:`M4 9h2`,key:`r1h2o0`}],[`path`,{d:`M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02`,key:`xtkcd5`}]]),Ue=n(`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`}]]),We=n(`mic-off`,[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]),Ge=n(`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`}]]),Ke=n(`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`}]]),qe=n(`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`}]]),Je=n(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]),Ye=n(`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`}]]),Xe=n(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),Ze=n(`zap`,[[`path`,{d:`M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z`,key:`1xq2db`}]]),Q=e(t(),1);function Qe({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 $e=null;function et(){return $e||=new AudioContext,$e}function tt(e,t,n,r,i=`sine`){let a=et(),o=a.createOscillator(),s=a.createGain();o.type=i,o.frequency.value=e,s.gain.setValueAtTime(r,n),s.gain.exponentialRampToValueAtTime(.001,n+t),o.connect(s),s.connect(a.destination),o.start(n),o.stop(n+t)}function nt(){let e=et().currentTime;tt(523,.15,e,.15),tt(659,.2,e+.12,.15)}function rt(){let e=et().currentTime;tt(880,.12,e,.18,`square`),tt(698,.12,e+.15,.18,`square`),tt(880,.15,e+.3,.15,`square`)}function it(){let e=et().currentTime;tt(440,.12,e,.12),tt(523,.12,e+.1,.12),tt(659,.18,e+.2,.12)}var at={done:nt,approval_request:rt,question:it};function ot(e){try{at[e]?.()}catch{}}function st(e){if(document.hidden)return!1;let{panels:t,focusedPanelId:n}=l.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 ct(e,t=`claude`,n=``){let[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(`idle`),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(0),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(null),[x,S]=(0,Q.useState)(null),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(null),D=(0,Q.useRef)(``),O=(0,Q.useRef)([]),k=(0,Q.useRef)(null),A=(0,Q.useRef)(`idle`),j=(0,Q.useRef)(null),ee=(0,Q.useRef)(()=>{}),M=(0,Q.useRef)(null),N=(0,Q.useRef)(e);N.current=e;let P=(0,Q.useRef)(n);P.current=n;let F=s!==`idle`,I=(0,Q.useCallback)((e,t)=>{let n=O.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=O.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return O.current[n]={...r,children:i},!0},[]),L=(0,Q.useCallback)(()=>{let e=D.current,t=[...O.current],n=k.current;i(r=>{let i=r[r.length-1];return i?.role===`assistant`&&!i.id.startsWith(`final-`)?[...r.slice(0,-1),{...i,content:e,events:t,...n}]:[...r,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:t,timestamp:new Date().toISOString(),...n}]})},[]),R=(0,Q.useCallback)(e=>{let t=e,n=t?.type;if(n)switch(n){case`account_info`:k.current={accountId:t.accountId,accountLabel:t.accountLabel};break;case`account_retry`:t.accountId&&t.accountLabel&&(k.current={accountId:t.accountId,accountLabel:t.accountLabel}),O.current.push(t),L();break;case`text`:{let e=t.parentToolUseId;if(e&&I(t,e)){L();break}D.current+=t.content,O.current.push(t),L();break}case`thinking`:{let e=t.parentToolUseId;if(e&&I(t,e)){L();break}O.current.push(t),L();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&I(t,e)){L();break}O.current.push(t),L();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&I(t,e)){L();break}O.current.push(t),L();break}case`approval_request`:if(O.current.push(t),m({requestId:t.requestId,tool:t.tool,input:t.input}),N.current&&!st(N.current)){let e=t.tool===`AskUserQuestion`?`question`:`approval_request`;K.getState().addNotification(N.current,e,P.current),ot(e)}break;case`error`:{O.current.push(t);let e=[...O.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()}]});break}case`done`:{if(A.current===`idle`)break;t.contextWindowPct!=null&&g(t.contextWindowPct),N.current&&!st(N.current)&&(K.getState().addNotification(N.current,`done`,P.current),ot(`done`));let e=D.current,n=[...O.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}),D.current=``,O.current=[],k.current=null;break}}},[I,L]),z=(0,Q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`session_migrated`){let e=t.newSessionId;e&&E(e);return}if(t.type===`title_updated`){S(t.title??null);return}if(t.type===`compact_status`){let e=t.status;e===`compacting`?b(`compacting`):e===`done`&&(b(null),M.current?.());return}if(t.type===`phase_changed`){let e=t.phase;c(e),A.current=e,f(e===`connecting`?t.elapsed??0:0);return}if(t.type===`session_state`){w(!0);let e=t,n=e.phase;c(n),A.current=n,e.sessionTitle&&S(e.sessionTitle),e.pendingApproval&&m({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),n===`idle`&&(M.current?.(),u(!1));return}if(t.type===`turn_events`){let e=t.events;if(!e?.length){u(!1);return}i(e=>{let t=e.findLastIndex(e=>e.role===`user`);return t>=0?e.slice(0,t+1):e}),D.current=``,O.current=[],k.current=null;let n=0,r=()=>{let t=Math.min(n+100,e.length);for(let r=n;r<t;r++)R(e[r]);n=t,n<e.length?requestAnimationFrame(r):u(!1)};requestAnimationFrame(r);return}R(t)}},[R]),{send:B,connect:V}=Qe({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:z,autoConnect:!!e&&!!n});ee.current=B,(0,Q.useEffect)(()=>{let r=!1;return c(`idle`),A.current=`idle`,m(null),b(null),D.current=``,O.current=[],w(!1),e&&n?(o(!0),fetch(`${_(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${v()}`}}).then(e=>e.json()).then(e=>{r||A.current!==`idle`||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&A.current===`idle`&&i([])}).finally(()=>{r||o(!1)})):i([]),()=>{r=!0}},[e,t,n]);let H=(0,Q.useCallback)((e,t)=>{if(!e.trim())return;let n=A.current!==`idle`;if(n){let e=D.current,t=[...O.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n})}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),D.current=``,O.current=[],j.current=null,n?(c(`thinking`),A.current=`thinking`):(c(`initializing`),A.current=`initializing`),m(null),B(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode,priority:t?.priority,images:t?.images}))},[B]),U=(0,Q.useCallback)((e,t,n)=>{if(B(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=O.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])}m(null)},[B]),W=(0,Q.useCallback)(()=>{if(A.current===`idle`)return;B(JSON.stringify({type:`cancel`}));let e=D.current,t=[...O.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}),D.current=``,O.current=[],j.current=null,c(`idle`),A.current=`idle`,m(null)},[B]),G=(0,Q.useCallback)(()=>{w(!1),u(!0),V()},[V]),q=(0,Q.useCallback)(()=>{!e||!n||(o(!0),fetch(`${_(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${v()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(i(e.data),D.current=``,O.current=[])}).catch(()=>{}).finally(()=>o(!1)))},[e,t,n]);return M.current=q,{messages:r,messagesLoading:a,isStreaming:F,phase:s,isReconnecting:l,connectingElapsed:d,pendingApproval:p,contextWindowPct:h,compactStatus:y,sessionTitle:x,migratedSessionId:T,sendMessage:H,respondToApproval:U,cancelStreaming:W,reconnect:G,refetchMessages:q,isConnected:C}}var lt=12e4;function ut(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(`${_(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${v()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),e.data.lastFetchedAt&&s(e.data.lastFetchedAt))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,Q.useEffect)(()=>(l(),c.current=setInterval(()=>l(),lt),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,Q.useCallback)(()=>l(!0),[l])}}var dt={damping:.7,stiffness:.05,mass:1.25},ft=70,pt=1e3/60,mt=350,ht=!1;globalThis.document?.addEventListener(`mousedown`,()=>{ht=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{ht=!1}),globalThis.document?.addEventListener(`click`,()=>{ht=!1});var gt=(e={})=>{let[t,n]=(0,Q.useState)(!1),[r,i]=(0,Q.useState)(e.initial!==!1),[a,o]=(0,Q.useState)(!1),s=(0,Q.useRef)(null);s.current=e;let c=(0,Q.useCallback)(()=>{if(!ht)return!1;let e=window.getSelection();if(!e||!e.rangeCount)return!1;let t=e.getRangeAt(0);return t.commonAncestorContainer.contains(g.current)||g.current?.contains(t.commonAncestorContainer)},[]),l=(0,Q.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,Q.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,Q.useMemo)(()=>{let n;return{escapedFromLock:t,isAtBottom:r,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return g.current?.scrollTop??0},set scrollTop(e){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<=ft}}},[]),f=(0,Q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=yt(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))/pt;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:yt(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=_t(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=_t(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=yt(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:mt})}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 _t(e,t){let n=(0,Q.useCallback)(t=>(n.current=t,e(t)),t);return n}var vt=new Map;function yt(...e){let t={...dt},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 vt.has(r)||vt.set(r,Object.freeze(t)),n?`instant`:vt.get(r)}var bt=(0,Q.createContext)(null),xt=typeof window<`u`?Q.useLayoutEffect:Q.useEffect;function St({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=gt({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]),xt(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),Q.createElement(bt.Provider,{value:y},Q.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=Ct();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})(St||={});function Ct(){let e=(0,Q.useContext)(bt);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var $=p();function wt(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 Tt({tool:e,result:t,completed:n,projectName:r}){let[a,o]=(0,Q.useState)(!1);if(e.type===`error`)return(0,$.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,$.jsx)(F,{className:`size-3`}),(0,$.jsx)(`span`,{children:e.message})]});let{toolName:s,input:c}=wt(e),l=t?.type===`tool_result`,u=l&&!!t.isError,d=s===`AskUserQuestion`&&!!c?.answers,f=(s===`Agent`||s===`Task`)&&e.type===`tool_use`,p=f?e.children:void 0,m=p&&p.length>0;return(0,$.jsxs)(`div`,{className:`rounded border text-xs ${f?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,$.jsxs)(`button`,{onClick:()=>o(!a),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors min-w-0`,children:[a?(0,$.jsx)(z,{className:`size-3 shrink-0`}):(0,$.jsx)(i,{className:`size-3 shrink-0`}),u?(0,$.jsx)(Ie,{className:`size-3 text-red-400 shrink-0`}):l||d||n?(0,$.jsx)(q,{className:`size-3 text-green-400 shrink-0`}):(0,$.jsx)(Z,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,$.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,$.jsx)(Et,{name:s,input:c})}),m&&(0,$.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[p.length,` steps`]})]}),a&&(0,$.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,$.jsx)(Dt,{name:s,input:c,projectName:r}),m&&(0,$.jsx)(jt,{events:p,projectName:r}),l&&(0,$.jsx)(kt,{toolName:s,output:t.output})]})]})}function Et({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:g(n(t.file_path))})]});case`Bash`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Nt(n(t.command),60)})]});case`Glob`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Nt(n(t.pattern),40)})]});case`WebSearch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Y,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Nt(n(t.query),50)})]});case`WebFetch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(se,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Nt(n(t.url),50)})]});case`ToolSearch`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Y,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Nt(n(t.query),50)})]});case`Agent`:case`Task`:return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ge,{className:`size-3 inline`}),` `,e,` `,(0,$.jsx)(`span`,{className:`text-text-subtle`,children:Nt(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,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ue,{className:`size-3 inline`}),` `,e,` `,(0,$.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,$.jsxs)($.Fragment,{children:[e,` `,(0,$.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,$.jsx)($.Fragment,{children:e})}}function Dt({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=u(),a=e=>{n&&i({type:`editor`,title:g(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},o=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${g(e)}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,$.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,$.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,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.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,$.jsx)(c,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,$.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,$.jsx)(s,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,$.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:Nt(r(t.content),300)})]})}case`Glob`:return(0,$.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,$.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,$.jsx)(Ot,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,$.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,$.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,$.jsx)(Mt,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,$.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.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,$.jsx)(se,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,$.jsx)(`p`,{className:`text-text-subtle`,children:Nt(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,$.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,$.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,$.jsxs)(`p`,{className:`text-foreground text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,$.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function Ot({todos:e}){return(0,$.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,$.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,$.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function kt({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,$.jsxs)(`div`,{className:`border-t border-border pt-1.5 space-y-1`,children:[(0,$.jsx)(Mt,{content:i,maxHeight:`max-h-60`}),(0,$.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,$.jsx)(a,{className:`size-3`}),n?`Hide`:`Show`,` raw`]}),n&&(0,$.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono max-h-40 whitespace-pre-wrap break-all text-[10px]`,children:t})]}):(0,$.jsx)(At,{output:t})}function At({output:e}){let t=e.split(`
5
+ `).length,n=t>3||e.length>200,[r,a]=(0,Q.useState)(n);return(0,$.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[n&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>a(!r),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors mb-1`,children:[r?(0,$.jsx)(i,{className:`size-3`}):(0,$.jsx)(z,{className:`size-3`}),`Output (`,t,` lines)`]}),(0,$.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 jt({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,$.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,$.jsx)(`div`,{className:`text-text-secondary text-[11px]`,children:(0,$.jsx)(Mt,{content:e.content,maxHeight:`max-h-24`})},`st-${n}`):(0,$.jsx)(Tt,{tool:e.tool,result:e.result,completed:!!e.result,projectName:t},`sc-${n}`))})}function Mt({content:e,maxHeight:t=`max-h-48`}){return(0,$.jsx)(o,{content:e,className:`text-text-secondary overflow-auto ${t}`})}function Nt(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}function Pt(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 Ft(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 It({questions:e,onSubmit:t,onSkip:n}){let r=(0,Q.useRef)(null),i=Pt(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=Ft({questions:e,activeTab:i.activeTab,totalOptions:o,allAnswered:i.allAnswered,hasAnswer:i.hasAnswer,onSelectOption:l,goToNextTab:i.goToNextTab,goToPrevTab:i.goToPrevTab,onSubmit:c,customInputRef:r,enabled:!0}),d=(0,Q.useCallback)(e=>{l(e),u.setFocusedOption(e)},[l,u.setFocusedOption]);return(0,$.jsxs)(`div`,{ref:u.containerRef,className:`rounded-lg border-2 border-primary/30 bg-primary/5 p-3 space-y-3 outline-none animate-in slide-in-from-bottom-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,$.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,$.jsxs)(`span`,{className:`text-[10px] text-text-secondary font-normal`,children:[s?`←→ tabs · `:``,`↑↓ options · 1-`,Math.min(o-1,9),` select · Enter submit`]})]}),s&&(0,$.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,$.jsxs)(`button`,{className:`flex items-center gap-1.5 px-3 py-1.5 rounded text-xs whitespace-nowrap transition-all ${i.activeTab===t?`bg-primary text-primary-foreground`:i.hasAnswer(t)?`text-primary bg-transparent`:`text-text-secondary hover:bg-surface-elevated`}`,onClick:()=>{i.setActiveTab(t),u.setFocusedOption(0)},tabIndex:-1,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-semibold ${i.activeTab===t?`bg-white/20`:i.hasAnswer(t)?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:i.hasAnswer(t)?`✓`:t+1}),(0,$.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,$.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,$.jsx)(`div`,{className:`text-sm text-text-primary`,children:a.question}),a.multiSelect&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a.options.map((e,t)=>{let n=(i.answers[i.activeTab]||[]).includes(e.label),r=u.focusedOption===t;return(0,$.jsxs)(`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,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded text-[10px] font-semibold shrink-0 mt-px ${n?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:t+1}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,$.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,$.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border border-dashed transition-all border-border bg-transparent ${u.focusedOption===o-1?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,$.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded bg-surface-elevated text-text-secondary text-[10px] font-semibold shrink-0 mt-px`,children:`O`}),(0,$.jsx)(`input`,{ref:r,type:`text`,className:`flex-1 px-2 py-1 text-xs bg-surface border border-border rounded text-text-primary outline-none placeholder:text-text-subtle focus:border-primary`,placeholder:`Other (press O to type)...`,value:i.customInputs[i.activeTab]||``,onChange:e=>i.handleCustomInput(i.activeTab,e.target.value),onFocus:()=>u.setFocusedOption(o-1)})]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToPrevTab,disabled:i.activeTab===0,tabIndex:-1,children:`← Prev`}),(0,$.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToNextTab,disabled:i.activeTab===e.length-1,tabIndex:-1,children:`Next →`})]}),(0,$.jsx)(`button`,{onClick:n,className:`px-4 py-1.5 rounded border border-border bg-background text-text-secondary text-xs hover:bg-surface-elevated transition-colors`,tabIndex:-1,children:`Skip`}),(0,$.jsxs)(`button`,{onClick:c,disabled:!i.allAnswered,className:`px-4 py-1.5 rounded bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,tabIndex:-1,children:[`Submit `,i.allAnswered?`✓`:`(${e.filter((e,t)=>i.hasAnswer(t)).length}/${e.length})`]})]})]})}function Lt({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,phase:a,connectingElapsed:o,projectName:s,onFork:c}){if(t)return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,$.jsx)(ge,{className:`size-10 text-text-subtle animate-pulse`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]});if(e.length===0&&!i)return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,$.jsx)(ge,{className:`size-10 text-text-subtle`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Send a message to start the conversation`})]});let l=(0,Q.useMemo)(()=>e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return e.role===`user`?t:t||n}),[e]);return(0,$.jsx)(`div`,{className:`relative flex-1 overflow-hidden flex flex-col min-h-0`,children:(0,$.jsxs)(St,{className:`flex-1 overflow-y-auto overflow-x-hidden`,resize:`smooth`,initial:`instant`,children:[(0,$.jsxs)(St.Content,{className:`p-4 space-y-4`,children:[l.map((e,t)=>(0,$.jsx)(zt,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:s,onFork:e.role===`user`&&c?()=>{let n=t>0?l[t-1]:void 0;c(e.content,n?.id)}:void 0},e.id)),n&&(n.tool===`AskUserQuestion`?(0,$.jsx)(ln,{approval:n,onRespond:r}):(0,$.jsx)(cn,{approval:n,onRespond:r})),i&&(0,$.jsx)(on,{lastMessage:e[e.length-1],phase:a,elapsed:o})]}),(0,$.jsx)(Rt,{})]})})}function Rt(){let{isAtBottom:e,scrollToBottom:t}=Ct();return e?null:(0,$.jsxs)(`button`,{onClick:()=>t(),className:`absolute bottom-4 left-1/2 -translate-x-1/2 z-10 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,$.jsx)(z,{className:`size-3`}),`Scroll to bottom`]})}function zt({message:e,isStreaming:t,projectName:n,onFork:r}){return e.role===`user`?(0,$.jsx)(qt,{content:e.content,projectName:n,onFork:r}):e.role===`system`?(0,$.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,$.jsx)(F,{className:`size-4 shrink-0`}),(0,$.jsx)(`p`,{children:e.content})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.events&&e.events.length>0?(0,$.jsx)(nn,{events:e.events,isStreaming:t,projectName:n}):e.content&&(0,$.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,$.jsx)(sn,{content:e.content,projectName:n})}),e.accountLabel&&(0,$.jsxs)(`p`,{className:`text-[10px] select-none`,style:{color:`var(--color-text-subtle)`},children:[`via `,e.accountLabel]})]})}var Bt=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]),Vt={"system-reminder":`Context`,claudeMd:`CLAUDE.md`,gitStatus:`Git Status`,currentDate:`Date`,fast_mode_info:`Fast Mode`,"available-deferred-tools":`Tools`,"task-notification":`Task Result`,environment_details:`Environment`};function Ht(e){let t=[],n=/<(system-reminder|available-deferred-tools|antml:[\w-]+|fast_mode_info|claudeMd|gitStatus|currentDate|task-notification|environment_details)[^>]*>([\s\S]*?)<\/\1>/g,r;for(;(r=n.exec(e))!==null;){let e=r[1];t.push({name:e,label:Vt[e]??e.replace(/^antml:/,``).replace(/-/g,` `),content:r[2].trim()})}return{cleanText:e.replace(n,``).trim(),tags:t}}function Ut(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 Wt(e,t){let n=g(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function Gt(e){let t=e.lastIndexOf(`.`);return t===-1?!1:Bt.has(e.slice(t).toLowerCase())}var Kt=new Set([`task-notification`,`environment_details`]);function qt({content:e,projectName:t,onFork:n}){let{files:r,text:i,tags:a}=(0,Q.useMemo)(()=>{let t=Ut(e),{cleanText:n,tags:r}=Ht(t.text);return{files:t.files,text:n,tags:r}},[e]),o=a.some(e=>Kt.has(e.name)),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(!1),d=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{let e=d.current;if(!e)return;let t=()=>u(e.scrollHeight>e.clientHeight+2);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[i]),(0,$.jsxs)(`div`,{className:m(`group/user relative rounded-lg px-3 py-2 text-sm border shadow-sm`,o?`bg-surface/40 border-border/40 text-text-secondary`:`bg-primary/10 border-primary/15 text-text-primary`),children:[a.length>0&&(0,$.jsx)(Jt,{tags:a}),r.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.map((e,n)=>Gt(e)?(0,$.jsx)(tn,{filePath:e,projectName:t},n):(0,$.jsxs)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-background/40 px-1.5 py-0.5 text-[11px] text-text-secondary`,children:[(0,$.jsx)(Ce,{className:`size-3 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-32`,children:g(e)})]},n))}),i&&(0,$.jsx)(`div`,{ref:d,className:m(`whitespace-pre-wrap break-words transition-all duration-200`,!s&&`line-clamp-2`,s&&`max-h-[50vh] overflow-y-auto`),children:o?(0,$.jsx)($t,{text:i,projectName:t}):i}),(l||s)&&(0,$.jsx)(`button`,{onClick:()=>c(!s),className:m(`flex items-center gap-1 text-xs mt-1 transition-colors`,o?`text-text-subtle hover:text-text-secondary`:`text-primary/70 hover:text-primary`),children:s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ne,{className:`size-3`}),`Show less`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(z,{className:`size-3`}),`Show more`]})}),!o&&n&&(0,$.jsx)(`button`,{onClick:n,title:`Retry from this message (fork session)`,className:`absolute top-1.5 right-1.5 opacity-0 group-hover/user:opacity-100 transition-opacity size-5 flex items-center justify-center rounded text-text-subtle hover:text-text-primary`,children:(0,$.jsx)(G,{className:`size-3`})})]})}function Jt({tags:e}){return(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,$.jsx)(Yt,{tag:e},t))})}function Yt({tag:e}){let[t,n]=(0,Q.useState)(!1);return e.name===`task-notification`?(0,$.jsx)(Zt,{content:e.content}):(0,$.jsxs)(`div`,{className:`text-xs`,children:[(0,$.jsxs)(`button`,{onClick:()=>n(!t),className:`flex items-center gap-1 rounded-full border border-border/60 bg-surface/50 px-2 py-0.5 text-text-subtle hover:text-text-secondary hover:bg-surface transition-colors`,children:[(0,$.jsx)(d,{className:`size-2.5`}),(0,$.jsx)(`span`,{children:e.label}),(0,$.jsx)(i,{className:m(`size-2.5 transition-transform`,t&&`rotate-90`)})]}),t&&(0,$.jsx)(`div`,{className:`mt-1 rounded border border-border/40 bg-surface/30 px-2 py-1.5 text-[11px] text-text-subtle/80 whitespace-pre-wrap max-h-40 overflow-y-auto leading-relaxed`,children:e.content})]})}function Xt(e,t){return e.match(RegExp(`<${t}>([\\s\\S]*?)</${t}>`))?.[1]?.trim()||void 0}function Zt({content:e}){let[t,n]=(0,Q.useState)(!1),r=Xt(e,`status`),a=Xt(e,`summary`),o=Xt(e,`output-file`),s=Xt(e,`result`);return(0,$.jsxs)(`div`,{className:`text-xs`,children:[(0,$.jsxs)(`button`,{onClick:()=>n(!t),className:`flex items-center gap-1.5 rounded-full border border-border/60 bg-surface/50 px-2 py-0.5 text-text-subtle hover:text-text-secondary hover:bg-surface transition-colors`,children:[r===`completed`?(0,$.jsx)(q,{className:`size-2.5 text-green-500`}):(0,$.jsx)(Ie,{className:`size-2.5 text-yellow-500`}),(0,$.jsx)(`span`,{className:`truncate max-w-80`,children:a??`Task notification`}),(0,$.jsx)(i,{className:m(`size-2.5 transition-transform shrink-0`,t&&`rotate-90`)})]}),t&&(0,$.jsxs)(`div`,{className:`mt-1 rounded border border-border/40 bg-surface/30 px-2 py-1.5 space-y-1.5`,children:[a&&(0,$.jsx)(`p`,{className:`text-[11px] text-text-secondary`,children:a}),o&&(0,$.jsx)(Qt,{path:o}),s&&(0,$.jsx)(`div`,{className:`text-[11px] text-text-subtle/80 max-h-60 overflow-y-auto leading-relaxed`,children:(0,$.jsx)(sn,{content:s})})]})]})}function Qt({path:e,projectName:t}){return(0,$.jsxs)(`button`,{type:`button`,onClick:(0,Q.useCallback)(()=>{let n=u.getState().openTab,r=t??te.getState().activeProject?.name,i=g(e),a={filePath:e};r&&(a.projectName=r),y.get(`/api/fs/read?path=${encodeURIComponent(e)}`).then(()=>{n({type:`editor`,title:i,metadata:a,projectId:null,closable:!0})}).catch(()=>{n({type:`editor`,title:i,metadata:a,projectId:null,closable:!0})})},[e,t]),className:`inline-flex items-center gap-1 rounded border border-border/50 bg-surface/50 px-1.5 py-0.5 font-mono text-[10px] text-text-secondary hover:text-text-primary hover:bg-surface transition-colors cursor-pointer`,children:[(0,$.jsx)(Ce,{className:`size-2.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-60`,children:g(e)}),(0,$.jsx)(c,{className:`size-2 shrink-0 opacity-50`})]})}function $t({text:e,projectName:t}){return(0,$.jsx)($.Fragment,{children:(0,Q.useMemo)(()=>{let t=/(\/(?:[\w.\-]+\/)+[\w.\-]+)/g,n=[],r=0,i;for(;(i=t.exec(e))!==null;)i.index>r&&n.push({kind:`text`,value:e.slice(r,i.index)}),n.push({kind:`path`,value:i[1]}),r=i.index+i[0].length;return r<e.length&&n.push({kind:`text`,value:e.slice(r)}),n},[e]).map((e,n)=>e.kind===`path`?(0,$.jsx)(Qt,{path:e.value,projectName:t},n):(0,$.jsx)(`span`,{children:e.value},n))})}function en(e){let[t,n]=(0,Q.useState)(null),[r,i]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{let t=!1,r,a=v();return fetch(e,{headers:a?{Authorization:`Bearer ${a}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{t||(r=URL.createObjectURL(e),n(r))}).catch(()=>{t||i(!0)}),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),{blobUrl:t,error:r}}function tn({filePath:e,projectName:t}){let{blobUrl:n,error:r}=en(Wt(e,t)),i=Te(e=>e.open),a=g(e);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n&&i(n,a),className:`flex items-center gap-1 rounded-md border border-border/60 bg-background/40 px-1.5 py-0.5 text-[11px] text-text-secondary hover:bg-surface transition-colors cursor-pointer`,children:[n?(0,$.jsx)(`img`,{src:n,alt:a,className:`size-4 rounded-sm object-cover shrink-0`}):r?(0,$.jsx)(Ve,{className:`size-3 shrink-0`}):(0,$.jsx)(`div`,{className:`size-4 rounded-sm bg-surface animate-pulse shrink-0`}),(0,$.jsx)(`span`,{className:`truncate max-w-32`,children:a})]})}function nn({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}if(a&&=(r.push({kind:`thinking`,content:a}),``),n.type===`account_retry`){i&&=(r.push({kind:`text`,content:i}),``);let e=n.accountLabel??`another account`,t=n.reason??`Auth failed`;r.push({kind:`text`,content:`\n\n> ↻ ${t} — retrying with **${e}**...\n\n`});continue}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,$.jsx)($.Fragment,{children:r.map((e,i)=>{if(e.kind===`thinking`)return(0,$.jsx)(rn,{content:e.content,isStreaming:t&&i===r.length-1},`think-${i}`);if(e.kind===`text`){let a=t&&i===r.length-1;return(0,$.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,$.jsx)(an,{content:e.content,animate:a,projectName:n})},`text-${i}`)}return(0,$.jsx)(Tt,{tool:e.tool,result:e.result,completed:e.completed,projectName:n},`tool-${i}`)})})}function rn({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,$.jsxs)(`div`,{className:`rounded border border-border/50 bg-surface/30 text-xs`,children:[(0,$.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors text-text-subtle`,children:[t?(0,$.jsx)(Z,{className:`size-3 animate-spin`}):(0,$.jsx)(i,{className:`size-3 transition-transform ${n?`rotate-90`:``}`}),(0,$.jsxs)(`span`,{children:[`Thinking`,t?`...`:``]}),!t&&(0,$.jsx)(`span`,{className:`text-text-subtle/50 ml-auto`,children:e.length>100?`${Math.round(e.length/4)} tokens`:``})]}),n&&(0,$.jsx)(St,{className:`max-h-60 overflow-y-auto`,resize:`smooth`,initial:`instant`,children:(0,$.jsx)(St.Content,{className:`px-2 pb-2 text-text-subtle/80 whitespace-pre-wrap text-[11px] leading-relaxed`,children:e})})]})}function an({content:e,animate:t,projectName:n}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(sn,{content:e,projectName:n}),t&&(0,$.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function on({lastMessage:e,phase:t,elapsed:n}){let r=!e||e.role!==`assistant`,i=e?.events?.length?e.events[e.events.length-1].type===`tool_result`:!1;return!r&&!i?null:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-text-subtle`,children:[(0,$.jsx)(Z,{className:`size-3 animate-spin`}),(0,$.jsxs)(`span`,{children:[t===`initializing`?`Initializing`:t===`connecting`?`Connecting`:t===`thinking`?`Thinking`:`Processing`,r&&(n??0)>0&&(0,$.jsxs)(`span`,{className:`text-text-subtle/60`,children:[`... (`,n,`s)`]})]})]}),t===`connecting`&&(n??0)>=30&&(0,$.jsx)(`p`,{className:`text-xs text-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 sn({content:e,projectName:t}){return(0,$.jsx)(o,{content:e,projectName:t,codeActions:!0})}function cn({approval:e,onRespond:t}){return(0,$.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,$.jsx)(qe,{className:`size-4`}),(0,$.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,$.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,$.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,$.jsx)(`pre`,{className:`text-xs font-mono text-text-secondary overflow-x-auto bg-background rounded p-2 border border-border`,children:JSON.stringify(e.input,null,2)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`button`,{onClick:()=>t(e.requestId,!0),className:`px-4 py-1.5 rounded bg-green-600 text-white text-xs font-medium hover:bg-green-500 transition-colors`,children:`Allow`}),(0,$.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 ln({approval:e,onRespond:t}){return(0,$.jsx)(It,{questions:e.input.questions??[],onSubmit:n=>t(e.requestId,!0,n),onSkip:()=>t(e.requestId,!1)})}function un(){let e=window;return e.SpeechRecognition??e.webkitSpeechRecognition??null}function dn(e){let[t,n]=(0,Q.useState)(!1),[r,i]=(0,Q.useState)(``),a=(0,Q.useRef)(null),o=(0,Q.useRef)(``),s=typeof window<`u`&&un()!==null;return{isListening:t,interimText:r,start:(0,Q.useCallback)(t=>{let r=un();if(!r)return;a.current?.abort();let s=new r;s.lang=e?.lang??`vi-VN`,s.continuous=!0,s.interimResults=!0,o.current=``,s.onresult=e=>{let n=``,r=``;for(let t=0;t<e.results.length;t++){let i=e.results[t];i.isFinal?r+=i[0].transcript:n+=i[0].transcript}r&&(o.current=r);let a=(o.current+` `+n).trim();i(n),t(a,n.length===0&&o.current.length>0)},s.onend=()=>{n(!1),i(``),o.current&&t(o.current.trim(),!0)},s.onerror=e=>{e.error!==`no-speech`&&e.error!==`aborted`&&console.warn(`[voice-input] error:`,e.error),n(!1),i(``)},a.current=s,s.start(),n(!0)},[e?.lang]),stop:(0,Q.useCallback)(()=>{a.current?.stop(),a.current=null,n(!1),i(``)},[]),supported:s}}var fn=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),pn=new Set([`application/pdf`]),mn=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],hn=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 gn(e){return fn.has(e.type)}function _n(e){if(fn.has(e.type)||pn.has(e.type)||mn.some(t=>e.type.startsWith(t)))return!0;let t=vn(e.name);return!!(t&&hn.has(t))}function vn(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function yn({attachments:e,onRemove:t}){return e.length===0?null:(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-2 md:px-4 pt-2`,children:e.map(e=>(0,$.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,$.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,$.jsx)(Ve,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,$.jsx)(Ce,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,$.jsx)(Z,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,$.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,$.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,$.jsx)(H,{className:`size-3`})})]},e.id))})}var bn=[{id:`default`,label:`Ask before edits`,icon:ze,description:`Claude will ask for approval before making each edit`},{id:`acceptEdits`,label:`Edit automatically`,icon:a,description:`Claude will edit files without asking first`},{id:`plan`,label:`Plan mode`,icon:Re,description:`Claude will present a plan before editing`},{id:`bypassPermissions`,label:`Bypass permissions`,icon:Je,description:`Claude will not ask before running commands`}];function xn(e){return bn.find(t=>t.id===e)?.label??`Unknown`}function Sn(e){return bn.find(t=>t.id===e)?.icon??ze}function Cn({value:e,onChange:t,open:n,onOpenChange:r}){let i=(0,Q.useRef)(null),a=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{if(!n)return;let e=e=>{i.current&&!i.current.contains(e.target)&&r(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[n,r]),(0,Q.useEffect)(()=>{n&&(a.current=bn.findIndex(t=>t.id===e),a.current<0&&(a.current=0))},[n,e]);let o=(0,Q.useCallback)(e=>{if(e.key===`Escape`){r(!1);return}if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=e.key===`ArrowDown`?1:-1;a.current=(a.current+t+bn.length)%bn.length,(i.current?.querySelector(`[data-idx="${a.current}"]`))?.focus()}if(e.key===`Enter`){e.preventDefault();let n=bn[a.current];n&&(t(n.id),r(!1))}},[t,r]);return n?(0,$.jsxs)(`div`,{ref:i,role:`listbox`,"aria-label":`Permission modes`,onKeyDown:o,onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),className:`absolute bottom-full left-0 mb-1 z-50 w-72 md:w-80 rounded-lg border border-border bg-surface shadow-lg`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-text-secondary`,children:`Modes`}),(0,$.jsx)(`kbd`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-text-subtle border border-border`,children:`Shift + Tab`})]}),(0,$.jsx)(`div`,{className:`py-1`,children:bn.map((n,i)=>{let a=n.icon,o=n.id===e;return(0,$.jsxs)(`button`,{"data-idx":i,role:`option`,"aria-selected":o,tabIndex:0,onClick:()=>{t(n.id),r(!1)},className:`w-full flex items-start gap-3 px-3 py-2.5 text-left transition-colors hover:bg-surface-elevated focus:bg-surface-elevated focus:outline-none ${o?`bg-surface-elevated`:``}`,children:[(0,$.jsx)(a,{className:`size-4 mt-0.5 shrink-0 text-text-secondary`}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-text-primary`,children:n.label}),(0,$.jsx)(`div`,{className:`text-xs text-text-subtle leading-snug`,children:n.description})]}),o&&(0,$.jsx)(L,{className:`size-4 mt-0.5 shrink-0 text-primary`})]},n.id)})})]}):null}function wn(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&n(r.children)}return n(e),t}function Tn({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,Q.useState)(0),s=(0,Q.useRef)(null),c=(()=>{if(!t)return e.slice(0,50);let n=t.toLowerCase();return e.filter(e=>e.path.toLowerCase().includes(n)||e.name.toLowerCase().includes(n)).slice(0,50)})();(0,Q.useEffect)(()=>{o(0)},[t]),(0,Q.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,Q.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,Q.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,$.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,$.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,$.jsxs)(`button`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,$.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,$.jsx)(je,{className:`size-4 text-amber-500`}):(0,$.jsx)(le,{className:`size-4 text-blue-400`})}),(0,$.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}var En=(0,Q.memo)(function({onSend:e,isStreaming:t,onCancel:n,disabled:i,projectName:a,onSlashStateChange:o,onSlashItemsLoaded:s,slashSelected:c,onFileStateChange:l,onFileItemsLoaded:u,fileSelected:d,externalFiles:f,initialValue:p,autoFocus:m,permissionMode:g,onModeChange:b,providerId:x,onProviderChange:S}){let[C,w]=(0,Q.useState)(p??``),[T,E]=(0,Q.useState)([]),[D,O]=(0,Q.useState)(!1),[k,A]=(0,Q.useState)(!1),[j,ee]=(0,Q.useState)(`next`),M=(0,Q.useRef)(null),N=(0,Q.useRef)(null),P=(0,Q.useRef)(null),F=(0,Q.useRef)([]),I=(0,Q.useRef)([]),L=dn(),R=(0,Q.useRef)(``),z=(0,Q.useCallback)(e=>{let t=R.current;w(t?t+` `+e:e),requestAnimationFrame(()=>{let e=window.matchMedia(`(min-width: 768px)`).matches?M.current:N.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,160)+`px`)})},[]),B=(0,Q.useCallback)(()=>{L.isListening?L.stop():(R.current=C.trim(),L.start(z))},[L.isListening,L.start,L.stop,C,z]);(0,Q.useEffect)(()=>{let e=()=>{L.supported&&B()};return window.addEventListener(`toggle-voice-input`,e),()=>window.removeEventListener(`toggle-voice-input`,e)},[L.supported,B]),(0,Q.useEffect)(()=>{p&&(w(p),setTimeout(()=>{let e=M.current;e&&(e.focus(),e.selectionStart=e.selectionEnd=e.value.length)},50))},[p]),(0,Q.useEffect)(()=>{m&&setTimeout(()=>{(window.matchMedia(`(min-width: 768px)`).matches?M.current:N.current)?.focus()},100)},[]),(0,Q.useEffect)(()=>{if(!a){F.current=[],s?.([]);return}y.get(`${_(a)}/chat/slash-items`).then(e=>{F.current=e,s?.(e)}).catch(()=>{F.current=[],s?.([])})},[a]),(0,Q.useEffect)(()=>{if(!a){I.current=[],u?.([]);return}y.get(`${_(a)}/files/tree?depth=5`).then(e=>{let t=wn(e);I.current=t,u?.(t)}).catch(()=>{I.current=[],u?.([])})},[a]),(0,Q.useEffect)(()=>{if(!c)return;let e=M.current,t=e?.selectionStart??C.length,n=C.slice(0,t),r=C.slice(t),i=n.replace(/(?:^|\s)\/\S*$/,e=>`${e.startsWith(`/`)?``:e[0]}/${c.name} `);w(i+r),o?.(!1,``),l?.(!1,``),e&&(e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=i.length},0))},[c]),(0,Q.useEffect)(()=>{if(!d)return;let e=M.current;if(!e)return;let t=e.selectionStart,n=C.slice(0,t),r=C.slice(t),i=n.match(/@(\S*)$/);if(i){let t=n.length-i[0].length;w(n.slice(0,t)+`@${d.path} `+r);let a=t+d.path.length+2;setTimeout(()=>{e.selectionStart=e.selectionEnd=a,e.focus()},0)}else{let t=C+`@${d.path} `;w(t),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length,e.focus()},0)}l?.(!1,``)},[d]),(0,Q.useEffect)(()=>{!f||f.length===0||H(f)},[f]);let V=(0,Q.useCallback)(async e=>{if(!a)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=v();r&&(n.Authorization=`Bearer ${r}`);let i=await(await fetch(`${_(a)}/chat/upload`,{method:`POST`,headers:n,body:t})).json();return i.ok&&Array.isArray(i.data)&&i.data.length>0?i.data[0].path:null}catch{return null}},[a]),H=(0,Q.useCallback)(e=>{for(let t of e){if(!_n(t)){w(e=>e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=h(),n=gn(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};E(e=>[...e,i]),V(t).then(t=>{E(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}(N.current??M.current)?.focus()},[V]),U=(0,Q.useCallback)(e=>{E(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),W=(0,Q.useCallback)(()=>{let n=C.trim(),r=T.filter(e=>e.status===`ready`);if(!n&&r.length===0){A(!1);return}o?.(!1,``),l?.(!1,``),L.isListening&&L.stop(),e(n,r,t?j:void 0),w(``);for(let e of T)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);E([]),A(!1),ee(`next`),M.current&&(M.current.style.height=`auto`),N.current&&(N.current.style.height=`auto`)},[C,T,e,o,l,t,j]),G=(0,Q.useCallback)(()=>{if(!i){if(T.some(e=>e.status===`uploading`)){(C.trim()||T.some(e=>e.status!==`error`))&&A(!0);return}W()}},[C,T,i,W]);(0,Q.useEffect)(()=>{k&&(T.some(e=>e.status===`uploading`)||W())},[k,T,W]);let K=(0,Q.useCallback)(e=>{if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),G();return}if(e.shiftKey&&e.key===`Tab`){e.preventDefault();let t=[`default`,`acceptEdits`,`plan`,`bypassPermissions`],n=t[(t.indexOf(g??`bypassPermissions`)+1)%t.length];b?.(n)}},[G,g,b]),q=(0,Q.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.match(/(?:^|\s)\/(\S*)$/);if(r&&F.current.length>0){o?.(!0,r[1]??``),l?.(!1,``);return}let i=n.match(/@(\S*)$/);if(i&&I.current.length>0){l?.(!0,i[1]??``),o?.(!1,``);return}o?.(!1,``),l?.(!1,``)},[o,l]),J=(0,Q.useCallback)((e,t)=>{w(e),q(e,t)},[q]),te=(0,Q.useCallback)(e=>{let t=e?.target??M.current;t&&(t.style.height=`auto`,t.style.height=Math.min(t.scrollHeight,160)+`px`)},[]),ne=(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(),H(n))},[H]),re=(0,Q.useCallback)(e=>{e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length>0&&H(t)},[H]),Y=(0,Q.useCallback)(e=>{e.preventDefault()},[]),X=(0,Q.useCallback)(()=>{P.current?.click()},[]),ae=(0,Q.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&H(t),e.target.value=``},[H]),oe=C.trim().length>0||T.some(e=>e.status!==`error`),se=t&&!oe;return(0,$.jsxs)(`div`,{className:`p-2 md:p-3 bg-background`,children:[(0,$.jsxs)(`div`,{className:`border border-border rounded-xl md:rounded-2xl bg-surface shadow-sm cursor-text`,onClick:e=>{i||e.target instanceof HTMLTextAreaElement||(window.matchMedia(`(min-width: 768px)`).matches?M.current:N.current)?.focus()},children:[(0,$.jsx)(yn,{attachments:T,onRemove:U}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-2 pt-2 md:hidden relative`,children:[(0,$.jsx)(Dn,{mode:g??`bypassPermissions`,onClick:()=>O(e=>!e)}),(0,$.jsx)(Cn,{value:g??`bypassPermissions`,onChange:e=>b?.(e),open:D,onOpenChange:O}),S&&a&&(0,$.jsx)(_e,{value:x??`claude`,onChange:S,projectName:a}),t&&(0,$.jsx)(kn,{value:j,onChange:ee})]}),(0,$.jsxs)(`div`,{className:`flex items-end gap-1 md:hidden px-2 py-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),X()},disabled:i,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,$.jsx)(Ge,{className:`size-4`})}),L.supported&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),B()},disabled:i,className:`flex items-center justify-center size-7 shrink-0 rounded-full transition-colors disabled:opacity-50 ${L.isListening?`bg-red-600 text-white animate-pulse`:`text-text-subtle hover:text-text-primary`}`,"aria-label":L.isListening?`Stop voice input`:`Start voice input`,children:L.isListening?(0,$.jsx)(We,{className:`size-4`}):(0,$.jsx)(ie,{className:`size-4`})}),(0,$.jsx)(`textarea`,{ref:N,value:C,onChange:e=>{J(e.target.value,e.target.selectionStart),te(e)},onKeyDown:K,onPaste:ne,onDrop:re,onDragOver:Y,placeholder:t?`Follow-up...`:`Ask anything...`,disabled:i,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`}),se?(0,$.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,$.jsx)(Xe,{className:`size-3`})}):(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),k?A(!1):G()},disabled:i||!oe,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":k?`Cancel queued send`:`Send`,children:k?(0,$.jsx)(Z,{className:`size-3.5 animate-spin`}):(0,$.jsx)(r,{className:`size-3.5`})})]}),(0,$.jsxs)(`div`,{className:`hidden md:block`,children:[(0,$.jsx)(`textarea`,{ref:M,value:C,onChange:e=>{J(e.target.value,e.target.selectionStart),te(e)},onKeyDown:K,onPaste:ne,onDrop:re,onDragOver:Y,placeholder:t?`Follow-up or Stop...`:`Ask anything...`,disabled:i,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,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),X()},disabled:i,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,$.jsx)(Ge,{className:`size-4`})}),L.supported&&(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),B()},disabled:i,className:`flex items-center justify-center size-8 rounded-full transition-colors disabled:opacity-50 ${L.isListening?`bg-red-600 text-white animate-pulse`:`text-text-subtle hover:text-text-primary hover:bg-surface-elevated`}`,"aria-label":L.isListening?`Stop voice input`:`Start voice input`,children:L.isListening?(0,$.jsx)(We,{className:`size-4`}):(0,$.jsx)(ie,{className:`size-4`})}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Dn,{mode:g??`bypassPermissions`,onClick:()=>O(e=>!e)}),(0,$.jsx)(Cn,{value:g??`bypassPermissions`,onChange:e=>b?.(e),open:D,onOpenChange:O})]}),S&&a&&(0,$.jsx)(_e,{value:x??`claude`,onChange:S,projectName:a}),t&&(0,$.jsx)(kn,{value:j,onChange:ee})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:se?(0,$.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,$.jsx)(Xe,{className:`size-3.5`})}):(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),k?A(!1):G()},disabled:i||!oe,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":k?`Cancel queued send`:`Send message`,children:k?(0,$.jsx)(Z,{className:`size-4 animate-spin`}):(0,$.jsx)(r,{className:`size-4`})})})]})]})]}),(0,$.jsx)(`input`,{ref:P,type:`file`,multiple:!0,className:`hidden`,onChange:ae})]})});function Dn({mode:e,onClick:t}){let n=Sn(e),r=xn(e);return(0,$.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),t()},className:`inline-flex items-center gap-1 px-2 py-1 rounded-md text-[11px] text-text-subtle hover:text-text-primary hover:bg-surface-elevated transition-colors border border-transparent hover:border-border`,"aria-label":`Permission mode: ${r}`,children:[(0,$.jsx)(n,{className:`size-3`}),(0,$.jsx)(`span`,{className:`max-w-[100px] truncate`,children:r})]})}var On=[{value:`now`,label:`Interrupt`,Icon:Ze},{value:`next`,label:`Queue`,Icon:He},{value:`later`,label:`Later`,Icon:ae}];function kn({value:e,onChange:t}){let n=(0,Q.useCallback)(()=>{let n=[`next`,`later`,`now`];t(n[(n.indexOf(e)+1)%n.length])},[e,t]),r=On.find(t=>t.value===e)??On[1],i=r.Icon;return(0,$.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),n()},className:`inline-flex items-center gap-1 px-2 py-1 rounded-md text-[11px] text-text-subtle hover:text-text-primary hover:bg-surface-elevated transition-colors border border-transparent hover:border-border`,"aria-label":`Message priority: ${r.label}`,title:`Priority: ${r.label} (click to cycle)`,children:[(0,$.jsx)(i,{className:`size-3`}),(0,$.jsx)(`span`,{children:r.label})]})}function An({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,$.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,$.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,$.jsxs)(`button`,{className:`flex items-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,$.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`skill`?(0,$.jsx)(Ye,{className:`size-4 text-amber-500`}):(0,$.jsx)(re,{className:`size-4 text-blue-500`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,$.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,$.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,$.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`user`?`global`:e.type})]}),e.description&&(0,$.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]},`${e.type}-${e.name}`))})})}var jn=`ppm-hienlh`;function Mn({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(`idle`);function y(){f(null),m(``),v(`idle`),u(null)}function b(){t(!1),y(),i(``),o(``),u(null)}async function x(){g(!0),u(null);try{let{url:e,state:t}=await j();f(t),v(`waiting`),window.open(e,`_blank`)}catch(e){u(e.message)}g(!1)}async function S(){if(!(!p.trim()||!d)){g(!0),u(null);try{let e=p.trim();e.includes(`#`)&&(e=e.split(`#`)[0]??e),await w(e,d),b(),n(`Account connected via OAuth!`)}catch(e){u(e.message)}g(!1)}}async function C(){if(r.trim()){c(!0),u(null);try{await A({apiKey:r.trim(),label:a.trim()||void 0}),b(),n(`Account added!`)}catch(e){u(e.message)}c(!1)}}let T=r.trim()?r.trim().startsWith(`sk-ant-oat`)?`OAuth token (Claude Max/Pro)`:r.trim().startsWith(`sk-ant-api`)?`API key`:`Unknown format`:``;return(0,$.jsx)(Me,{open:e,onOpenChange:e=>{e||b()},children:(0,$.jsxs)(J,{className:`sm:max-w-md`,children:[(0,$.jsxs)(U,{children:[(0,$.jsx)(he,{className:`text-sm`,children:`Add Claude Account`}),(0,$.jsx)(R,{className:`text-xs leading-relaxed`,children:`Connect via OAuth (recommended) or paste a token manually.`})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,$.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Recommended: Login with Claude`}),_===`idle`?(0,$.jsx)(M,{size:`sm`,className:`w-full h-8 text-xs`,onClick:x,disabled:h,children:h?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{className:`size-3 animate-spin mr-1`}),` Opening...`]}):`Login with Claude`}):(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Authorize in the opened tab, then paste the code:`}),(0,$.jsx)(P,{placeholder:`Paste code here...`,value:p,onChange:e=>m(e.target.value),className:`text-xs h-8 font-mono`,autoFocus:!0}),(0,$.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,$.jsx)(M,{size:`sm`,className:`flex-1 h-7 text-xs`,onClick:S,disabled:!p.trim()||h,children:h?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{className:`size-3 animate-spin mr-1`}),` Connecting...`]}):`Connect`}),(0,$.jsx)(M,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:y,children:`Cancel`})]})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`flex-1 border-t`}),(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`or paste token`}),(0,$.jsx)(`div`,{className:`flex-1 border-t`})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(pe,{htmlFor:`add-token`,className:`text-xs`,children:`Token`}),(0,$.jsx)(P,{id:`add-token`,type:`password`,placeholder:`sk-ant-...`,value:r,onChange:e=>i(e.target.value),className:`text-xs h-8 font-mono`}),T&&(0,$.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Detected: `,T]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(pe,{htmlFor:`add-label`,className:`text-xs`,children:`Label (optional)`}),(0,$.jsx)(P,{id:`add-label`,placeholder:`e.g. Personal, Work`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`})]})]}),l&&(0,$.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-red-500/10 text-red-600`,children:l}),(0,$.jsxs)(I,{children:[(0,$.jsx)(M,{size:`sm`,variant:`outline`,className:`text-xs h-7`,onClick:b,children:`Cancel`}),(0,$.jsx)(M,{size:`sm`,className:`text-xs h-7`,onClick:C,disabled:!r.trim()||s,children:s?`Adding...`:`Add Token`})]})]})})}function Nn({open:e,onOpenChange:t,accounts:n,preselectId:r,onMessage:i}){let a=n.filter(e=>e.hasRefreshToken),[o,s]=(0,Q.useState)(new Set),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(!1);e&&!g&&(s(r?new Set([r]):new Set(a.map(e=>e.id))),_(!0)),!e&&g&&_(!1);function y(){t(!1),l(``),d(!1),p(!1)}async function b(e){if(o.size===0)return;h(!0);let t=c.trim()||jn;try{let n={"Content-Type":`application/json`},r=v();r&&(n.Authorization=`Bearer ${r}`);let a=await fetch(`/api/accounts/export`,{method:`POST`,headers:n,body:JSON.stringify({password:t,accountIds:[...o],includeRefreshToken:u,refreshBeforeExport:f})});if(!a.ok){let e=await a.json();throw Error(e.error??`Export failed: ${a.status}`)}let s=await a.text();if(e)try{await navigator.clipboard.writeText(s),i?.(`Backup copied to clipboard!`)}catch{Fn(s),i?.(`Backup downloaded.`)}else Fn(s),i?.(`Backup downloaded.`);y()}catch{}h(!1)}let x=o.size>0&&!m;return(0,$.jsx)(Me,{open:e,onOpenChange:e=>{e||y()},children:(0,$.jsxs)(J,{className:`sm:max-w-md`,children:[(0,$.jsxs)(U,{children:[(0,$.jsxs)(he,{className:`text-sm flex items-center gap-1.5`,children:[(0,$.jsx)(xe,{className:`size-3.5`}),` Export Accounts`]}),(0,$.jsx)(R,{className:`text-xs`,children:`Select accounts and set a password to protect the backup.`})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,$.jsx)(`p`,{className:`text-[11px] font-medium text-muted-foreground`,children:`Accounts to export`}),(0,$.jsx)(`button`,{className:`text-[10px] text-primary hover:underline cursor-pointer`,onClick:()=>s(o.size===a.length?new Set:new Set(a.map(e=>e.id))),children:o.size===a.length?`Deselect all`:`Select all`})]}),a.length===0?(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground p-2 border rounded`,children:`No exportable accounts.`}):(0,$.jsx)(`div`,{className:`max-h-36 overflow-y-auto space-y-1 border rounded p-2`,children:a.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,id:`exp-${e.id}`,checked:o.has(e.id),onChange:t=>{let n=new Set(o);t.target.checked?n.add(e.id):n.delete(e.id),s(n)},className:`size-3.5 accent-primary cursor-pointer`}),(0,$.jsx)(`label`,{htmlFor:`exp-${e.id}`,className:`text-xs cursor-pointer truncate`,children:e.label??e.email??e.id.slice(0,8)})]},e.id))})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(pe,{className:`text-xs`,children:[`Password `,(0,$.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,$.jsx)(P,{type:`password`,placeholder:`Leave empty for default`,value:c,onChange:e=>l(e.target.value),className:`text-xs h-8`,autoComplete:`new-password`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,id:`exp-full`,checked:u,onChange:e=>d(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,$.jsx)(`label`,{htmlFor:`exp-full`,className:`text-[11px] cursor-pointer`,children:`Include refresh tokens (full transfer)`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,id:`exp-refresh`,checked:f,onChange:e=>p(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,$.jsx)(`label`,{htmlFor:`exp-refresh`,className:`text-[11px] cursor-pointer`,children:`Refresh tokens before export`})]}),u?(0,$.jsxs)(`div`,{className:`rounded-md border border-red-500/30 bg-red-500/5 p-2.5`,children:[(0,$.jsx)(`p`,{className:`text-[10px] font-medium text-red-600`,children:`Full transfer — source accounts will expire`}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Refresh tokens included. Source machine expires in ~1h after target refreshes.`})]}):f?(0,$.jsx)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/5 p-2.5`,children:(0,$.jsx)(`p`,{className:`text-[10px] font-medium text-amber-600`,children:`Refresh before export — invalidates previous shares`})}):(0,$.jsx)(`div`,{className:`rounded-md border border-green-500/30 bg-green-500/5 p-2.5`,children:(0,$.jsx)(`p`,{className:`text-[10px] font-medium text-green-600`,children:`Share current token (safe)`})}),(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Encrypted with AES-256-GCM + scrypt.`})]}),(0,$.jsxs)(I,{className:`gap-1.5 flex-col sm:flex-row`,children:[(0,$.jsx)(M,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:y,children:`Cancel`}),(0,$.jsxs)(M,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,disabled:!x,onClick:()=>b(!0),children:[(0,$.jsx)(Pe,{className:`size-3 mr-1`}),` Copy`]}),(0,$.jsx)(M,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!x,onClick:()=>b(!1),children:m?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{className:`size-3 animate-spin mr-1`}),` Exporting...`]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{className:`size-3 mr-1`}),` Download`]})})]})]})})}function Pn({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(null);function d(){t(!1),i(``),o(``),u(null)}async function f(){if(r.trim()){c(!0),u(null);try{let e=await S({data:r.trim(),password:a.trim()||jn});d(),n(`Imported ${e.imported} account(s)`)}catch(e){u(e.message||`Import failed`)}c(!1)}}return(0,$.jsx)(Me,{open:e,onOpenChange:e=>{e||d()},children:(0,$.jsxs)(J,{className:`sm:max-w-md`,children:[(0,$.jsxs)(U,{children:[(0,$.jsxs)(he,{className:`text-sm flex items-center gap-1.5`,children:[(0,$.jsx)(xe,{className:`size-3.5`}),` Import Accounts`]}),(0,$.jsx)(R,{className:`text-xs`,children:`Paste backup data and enter the export password. Imported accounts are temporary (~1h).`})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(pe,{className:`text-xs`,children:`Backup data`}),(0,$.jsx)(`textarea`,{value:r,onChange:e=>i(e.target.value),placeholder:`Paste backup JSON here...`,rows:4,className:`w-full text-xs p-2 rounded border border-border bg-background font-mono resize-none focus:outline-none focus:ring-1 focus:ring-primary`})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsxs)(pe,{className:`text-xs`,children:[`Password `,(0,$.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,$.jsx)(P,{type:`password`,placeholder:`Leave empty for default`,value:a,onChange:e=>o(e.target.value),className:`text-xs h-8`,autoComplete:`current-password`})]})]}),l&&(0,$.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-red-500/10 text-red-600`,children:l}),(0,$.jsxs)(I,{children:[(0,$.jsx)(M,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:d,children:`Cancel`}),(0,$.jsx)(M,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!r.trim()||s,onClick:f,children:s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{className:`size-3 animate-spin mr-1`}),` Importing...`]}):`Import`})]})]})})}function Fn(e){let t=new Blob([e],{type:`application/json`}),n=document.createElement(`a`);n.href=URL.createObjectURL(t),n.download=`ppm-accounts-backup.json`,n.click(),URL.revokeObjectURL(n.href)}var In=typeof window<`u`?window.matchMedia(`(min-width: 768px)`):null;function Ln(e){return In?.addEventListener(`change`,e),()=>In?.removeEventListener(`change`,e)}function Rn(){return In?.matches??!0}function zn(){let[e,t]=(0,Q.useState)(null),[n,r]=(0,Q.useState)(!0);return(0,Q.useEffect)(()=>{r(!0),E().then(t).finally(()=>r(!1))},[]),n?(0,$.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Loading...`}):e?(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Rotation Strategy`}),(0,$.jsxs)(Ae,{value:e.strategy,onValueChange:async e=>{t(await C({strategy:e}))},children:[(0,$.jsx)(Se,{className:`w-full h-9 text-xs`,children:(0,$.jsx)(ve,{})}),(0,$.jsxs)(ce,{children:[(0,$.jsx)(de,{value:`round-robin`,children:`Round-robin`}),(0,$.jsx)(de,{value:`fill-first`,children:`Fill-first`}),(0,$.jsx)(de,{value:`lowest-usage`,children:`Lowest usage`})]})]}),(0,$.jsxs)(`p`,{className:`text-[10px] text-text-subtle`,children:[e.strategy===`round-robin`&&`Cycles through accounts evenly`,e.strategy===`fill-first`&&`Uses one account until its limit, then moves on`,e.strategy===`lowest-usage`&&`Picks the account with the lowest current usage`]})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`text-xs font-medium text-text-primary`,children:`Max Retry`}),(0,$.jsx)(`input`,{type:`number`,min:0,value:e.maxRetry,className:`w-full h-9 text-xs border rounded-md px-3 bg-background`,onChange:async e=>{let n=parseInt(e.target.value,10);!isNaN(n)&&n>=0&&t(await C({maxRetry:n}))}}),(0,$.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`How many accounts to try on failure. 0 = try all available accounts.`})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs border-t border-border pt-3`,children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Active accounts`}),(0,$.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.activeCount})]})]}):(0,$.jsx)(`p`,{className:`text-xs text-text-subtle py-4 text-center`,children:`Failed to load settings`})}function Bn({open:e,onOpenChange:t}){let n=(0,Q.useSyncExternalStore)(Ln,Rn);return e?n?(0,$.jsx)(Me,{open:e,onOpenChange:t,children:(0,$.jsxs)(J,{className:`sm:max-w-sm`,children:[(0,$.jsx)(U,{children:(0,$.jsxs)(he,{className:`text-sm flex items-center gap-2`,children:[(0,$.jsx)(ne,{className:`size-4`}),` Rotation & Retry`]})}),(0,$.jsx)(zn,{})]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-50 transition-opacity duration-200 opacity-100`,onClick:()=>t(!1),style:{backgroundColor:`rgba(0,0,0,0.5)`}}),(0,$.jsxs)(`div`,{className:m(`fixed bottom-0 left-0 right-0 z-50 bg-background rounded-t-2xl border-t border-border shadow-2xl`,`transition-transform duration-300 ease-out max-h-[85vh] overflow-y-auto`,`translate-y-0`),children:[(0,$.jsx)(`div`,{className:`flex justify-center pt-3 pb-1`,children:(0,$.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-border`})}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,$.jsxs)(`span`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,$.jsx)(ne,{className:`size-4`}),` Rotation & Retry`]}),(0,$.jsx)(`button`,{onClick:()=>t(!1),className:`flex items-center justify-center size-7 rounded-md hover:bg-surface-elevated transition-colors`,children:(0,$.jsx)(H,{className:`size-4`})})]}),(0,$.jsx)(`div`,{className:`px-4 py-4 pb-8`,children:(0,$.jsx)(zn,{})})]})]}):null}function Vn(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function Hn(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function Un(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 Wn({label:e,bucket:t}){if(!t)return null;let n=Math.round(t.utilization*100),r=Un(t);return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,$.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,title:`Resets in`,children:[`↻ `,r]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-full rounded-full transition-all ${Hn(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,$.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${Vn(n)}`,children:[n,`%`]})]})]})}function Gn(e){let t=e-Date.now();if(t<=0)return`expired`;let n=Math.ceil(t/6e4),r=Math.floor(n/60),i=Math.floor(r/24);return i>0?`${i}d ${r%24}h`:r>0?`${r}h ${n%60}m`:`${n}m`}function Kn(e){if(!e)return{label:`unknown`,tip:`No account info available`,color:`text-text-subtle`};if(!e.expiresAt)return{label:`key`,tip:`API key (no expiry)`,color:`text-text-subtle`};let t=e.expiresAt*1e3<Date.now();return t&&e.hasRefreshToken?{label:`expired`,tip:`Token expired but has refresh token — will auto-renew`,color:`text-amber-500`}:t?{label:`expired`,tip:`Token expired, no refresh token`,color:`text-red-500`}:e.hasRefreshToken?{label:`long-lived`,tip:`OAuth token with refresh — long-lived`,color:`text-green-500`}:{label:`temp`,tip:`Temporary token without refresh — will expire`,color:`text-amber-500`}}function qn(e){if(!e)return null;let t=Math.round((Date.now()-e)/1e3);if(t<5)return`just now`;if(t<60)return`${t}s ago`;let n=Math.floor(t/60);if(n<60)return`${n}m ago`;let r=Math.floor(n/60),i=n%60;return r<24?i>0?`${r}h ${i}m ago`:`${r}h ago`:`${Math.floor(r/24)}d ago`}function Jn({entry:e,isActive:t,accountInfo:n,onToggle:r,onDelete:i,onExport:a,onViewProfile:o,flash:s}){let{usage:c}=e,l=c.session||c.weekly||c.weeklyOpus||c.weeklySonnet,u=n?.status??e.accountStatus,d=!!(n&&!n.hasRefreshToken&&n.expiresAt&&n.expiresAt<Math.floor(Date.now()/1e3));return(0,$.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5 transition-colors duration-500 min-w-[200px] shrink-0 snap-start ${d?`opacity-50`:``} ${s?`bg-primary/10 border-primary/40`:``} ${t?`border-primary/30 bg-primary/5`:`border-border/50`}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium truncate flex-1 min-w-0`,children:e.accountLabel??e.accountId.slice(0,8)}),d&&(0,$.jsx)(`span`,{className:`text-[9px] text-red-500 shrink-0 font-medium`,children:`Expired`}),!e.isOAuth&&!d&&(0,$.jsx)(`span`,{className:`text-[9px] text-text-subtle shrink-0`,children:`API key`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[!d&&o&&n?.profileData&&(0,$.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-foreground hover:bg-surface-elevated transition-colors`,onClick:()=>o(n.profileData),title:`View profile`,children:(0,$.jsx)(fe,{className:`size-3`})}),!d&&a&&e.isOAuth&&(0,$.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-blue-500 hover:bg-surface-elevated transition-colors`,onClick:()=>a(e.accountId),title:`Export this account`,children:(0,$.jsx)(X,{className:`size-3`})}),!d&&r&&(0,$.jsx)(be,{checked:u!==`disabled`,onCheckedChange:()=>r(e.accountId,u),disabled:u===`cooldown`,className:`scale-[0.6] cursor-pointer`}),i&&(0,$.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-red-500 hover:bg-surface-elevated transition-colors`,onClick:()=>i(e.accountId,e.accountLabel??e.accountId.slice(0,8)),title:`Remove account`,children:(0,$.jsx)(V,{className:`size-3`})})]})]}),l?(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(Wn,{label:`5-Hour Session`,bucket:c.session}),(0,$.jsx)(Wn,{label:`Weekly`,bucket:c.weekly}),(0,$.jsx)(Wn,{label:`Weekly (Opus)`,bucket:c.weeklyOpus}),(0,$.jsx)(Wn,{label:`Weekly (Sonnet)`,bucket:c.weeklySonnet})]}):(0,$.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:e.isOAuth?`No usage data yet`:`Usage tracking not available for API keys`}),(()=>{let e=Kn(n);return(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[9px] text-text-subtle flex-wrap`,children:[c.lastFetchedAt&&(0,$.jsxs)(`span`,{title:`Last usage data update`,children:[`↻ `,qn(new Date(c.lastFetchedAt).getTime())]}),n?.expiresAt&&n.expiresAt*1e3>Date.now()&&(0,$.jsxs)(`span`,{title:`Token expires in`,children:[`⏱ `,Gn(n.expiresAt*1e3)]}),(0,$.jsxs)(`span`,{className:e.color,title:e.tip,children:[`© `,e.label]})]})})()]})}function Yn({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastFetchedAt:a}){let[o,s]=(0,Q.useState)([]),[c,l]=(0,Q.useState)([]),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(!0),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(new Set),[v,y]=(0,Q.useState)(null),[b,S]=(0,Q.useState)(!1),[C,w]=(0,Q.useState)(!1),[E,A]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(null),[F,I]=(0,Q.useState)(null),[L,R]=(0,Q.useState)(null),z=(0,Q.useRef)(void 0),B=(0,Q.useRef)([]);function V(e){z.current&&clearTimeout(z.current),R(e),z.current=setTimeout(()=>R(null),4e3)}function U(e){W(),e&&V(e)}async function W(){let e=o.length>0;e?h(!0):p(!0);let[t,n,r]=await Promise.allSettled([T(),k(),x()]);if(t.status===`fulfilled`){let n=t.value;if(e&&B.current.length>0){let e=new Set,t=new Map(B.current.map(e=>[e.accountId,e]));for(let r of n){let n=t.get(r.accountId);if(!n){e.add(r.accountId);continue}let i=n.usage,a=r.usage;(i.session?.utilization!==a.session?.utilization||i.weekly?.utilization!==a.weekly?.utilization||i.weeklyOpus?.utilization!==a.weeklyOpus?.utilization||i.weeklySonnet?.utilization!==a.weeklySonnet?.utilization)&&e.add(r.accountId)}e.size>0&&(_(e),setTimeout(()=>_(new Set),1500))}B.current=n,s(n)}n.status===`fulfilled`&&l(n.value),r.status===`fulfilled`&&d(r.value?.id??null),p(!1),h(!1)}if((0,Q.useEffect)(()=>{t&&W()},[t]),(0,Q.useEffect)(()=>{!t||!a||W()},[a]),!t)return null;let G=new Map(c.map(e=>[e.id,e])),K=e.queryCostUsd!=null||e.totalCostUsd!=null,q=o.length>0;async function J(e,t){await D(e,{status:t===`disabled`?`active`:`disabled`}),W(),r?.()}async function te(){if(N){try{await O(N.id),V(`Account "${N.display}" removed.`),W(),r?.()}catch(e){V(`Failed to remove: ${e.message}`)}P(null)}}function re(){I(null),w(!0)}return(0,$.jsxs)(`div`,{className:`relative border-b border-border bg-surface px-3 py-2.5 space-y-2.5 max-h-[350px] overflow-y-auto`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage & Accounts`}),a&&(0,$.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:qn(new Date(a).getTime())})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`button`,{onClick:()=>M(!0),className:`text-xs text-text-subtle hover:text-text-primary px-1 cursor-pointer`,title:`Rotation & retry settings`,children:(0,$.jsx)(ne,{className:`size-3`})}),r&&(0,$.jsx)(`button`,{onClick:()=>{r(),W()},disabled:i||m,className:`text-xs text-text-subtle hover:text-text-primary px-1 disabled:opacity-50 cursor-pointer`,title:`Refresh`,children:(0,$.jsx)(ee,{className:`size-3 ${i||m?`animate-spin`:``}`})}),(0,$.jsx)(`button`,{onClick:n,className:`text-xs text-text-subtle hover:text-text-primary px-1 cursor-pointer`,children:(0,$.jsx)(H,{className:`size-3`})})]})]}),L&&(0,$.jsx)(`div`,{className:`text-[11px] p-1.5 rounded bg-green-500/10 text-green-600 text-center animate-in fade-in duration-200`,children:L}),q||f?(0,$.jsx)(`div`,{className:`flex gap-1.5 overflow-x-auto pb-1 -mx-3 px-3 snap-x snap-mandatory scrollbar-thin`,children:f?(0,$.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`Loading...`}):o.map(t=>(0,$.jsx)(Jn,{entry:t,isActive:t.accountId===(u??e.activeAccountId),accountInfo:G.get(t.accountId),onToggle:J,onDelete:(e,t)=>P({id:e,display:t}),onExport:e=>{I(e),w(!0)},onViewProfile:y,flash:g.has(t.accountId)},t.accountId))}):(0,$.jsx)($.Fragment,{children:e.session||e.weekly||e.weeklyOpus||e.weeklySonnet?(0,$.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,$.jsx)(Wn,{label:`5-Hour Session`,bucket:e.session}),(0,$.jsx)(Wn,{label:`Weekly`,bucket:e.weekly}),(0,$.jsx)(Wn,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,$.jsx)(Wn,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,$.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`No usage data available`})}),K&&(0,$.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,$.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,$.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]}),v&&(0,$.jsxs)(`div`,{className:`border-t border-border pt-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle`,children:`Profile`}),(0,$.jsx)(`button`,{className:`text-text-subtle hover:text-foreground cursor-pointer`,onClick:()=>y(null),children:(0,$.jsx)(H,{className:`size-3`})})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-[70px_1fr] gap-x-2 gap-y-0.5 text-[10px]`,children:[v.account?.display_name&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Name`}),(0,$.jsx)(`span`,{children:v.account.display_name})]}),v.account?.email&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Email`}),(0,$.jsx)(`span`,{children:v.account.email})]}),v.organization?.name&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Org`}),(0,$.jsx)(`span`,{children:v.organization.name})]}),v.organization?.organization_type&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Type`}),(0,$.jsx)(`span`,{children:v.organization.organization_type})]}),v.organization?.rate_limit_tier&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Tier`}),(0,$.jsx)(`span`,{children:v.organization.rate_limit_tier})]}),v.organization?.subscription_status&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`Status`}),(0,$.jsx)(`span`,{children:v.organization.subscription_status})]})]})]}),(0,$.jsxs)(`div`,{className:`border-t border-border pt-2 flex gap-1.5`,children:[(0,$.jsxs)(`button`,{onClick:()=>S(!0),className:`flex-1 flex items-center justify-center gap-1 rounded-md border border-border px-2 py-1 text-[11px] text-text-secondary hover:bg-surface-hover transition-colors cursor-pointer`,children:[(0,$.jsx)(ue,{className:`size-3`}),` Add`]}),(0,$.jsxs)(`button`,{onClick:re,className:`flex-1 flex items-center justify-center gap-1 rounded-md border border-border px-2 py-1 text-[11px] text-text-secondary hover:bg-surface-hover transition-colors cursor-pointer`,children:[(0,$.jsx)(X,{className:`size-3`}),` Export`]}),(0,$.jsxs)(`button`,{onClick:()=>A(!0),className:`flex-1 flex items-center justify-center gap-1 rounded-md border border-border px-2 py-1 text-[11px] text-text-secondary hover:bg-surface-hover transition-colors cursor-pointer`,children:[(0,$.jsx)(we,{className:`size-3`}),` Import`]})]}),N&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/80 backdrop-blur-sm rounded-md`,children:(0,$.jsxs)(`div`,{className:`bg-surface border border-border rounded-lg shadow-lg p-4 mx-4 max-w-[280px] w-full space-y-3`,children:[(0,$.jsxs)(`p`,{className:`text-xs text-text-primary text-center`,children:[`Remove `,(0,$.jsx)(`strong`,{className:`text-foreground`,children:N.display}),`?`]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`button`,{onClick:()=>P(null),className:`flex-1 px-3 py-1.5 rounded-md text-xs border border-border text-text-secondary hover:bg-surface-hover cursor-pointer transition-colors`,children:`Cancel`}),(0,$.jsx)(`button`,{onClick:te,className:`flex-1 px-3 py-1.5 rounded-md text-xs bg-red-500 text-white hover:bg-red-600 cursor-pointer transition-colors`,children:`Remove`})]})]})}),(0,$.jsx)(Mn,{open:b,onOpenChange:S,onSuccess:U}),(0,$.jsx)(Nn,{open:C,onOpenChange:e=>{w(e),e||I(null)},accounts:c,preselectId:F,onMessage:V}),(0,$.jsx)(Pn,{open:E,onOpenChange:A,onSuccess:U}),(0,$.jsx)(Bn,{open:j,onOpenChange:M})]})}function Xn(e){try{return new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}catch{return``}}function Zn(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function Qn({sessionId:e,projectName:t}){let[n,r]=(0,Q.useState)(!1);return(0,$.jsx)(`button`,{onClick:async()=>{try{let n=await y.get(`${_(t)}/chat/sessions/${e}/debug?project=${encodeURIComponent(t)}`),i=[`PPM Session: ${n.ppmSessionId}`,`SDK Session: ${n.sdkSessionId}`,n.jsonlPath?`JSONL: ${n.jsonlPath}`:`JSONL: not found`,n.projectPath?`Project: ${n.projectPath}`:null].filter(Boolean).join(`
7
+ `);await navigator.clipboard.writeText(i),r(!0),setTimeout(()=>r(!1),1500)}catch{}},className:`p-1 rounded transition-colors ${n?`text-green-500 bg-green-500/10`:`text-text-subtle hover:text-text-secondary hover:bg-surface-elevated`}`,title:n?`Copied!`:`Copy session debug info`,children:n?(0,$.jsx)(Le,{className:`size-3`}):(0,$.jsx)(W,{className:`size-3`})})}function $n({projectName:e,usageInfo:t,contextWindowPct:n,compactStatus:r,usageLoading:i,refreshUsage:a,lastFetchedAt:o,sessionId:s,providerId:c,onSelectSession:l,onBugReport:d,isConnected:f,onReconnect:p}){let[m,h]=(0,Q.useState)(null),[g,v]=(0,Q.useState)([]),[b,x]=(0,Q.useState)(!1),S=K(e=>s?e.notifications.has(s):!1),C=K(e=>e.clearForSession),[w,T]=(0,Q.useState)(``),[E,D]=(0,Q.useState)(null),[O,k]=(0,Q.useState)(``),A=(0,Q.useRef)(null),j=u(e=>e.openTab),M=e=>{h(t=>t===e?null:e)},P=(0,Q.useCallback)(async()=>{if(e){x(!0);try{v(await y.get(`${_(e)}/chat/sessions`))}catch{}finally{x(!1)}}},[e]);(0,Q.useEffect)(()=>{m===`history`&&g.length===0&&P()},[m]);function F(t){l?(l(t),h(null)):j({type:`chat`,title:t.title||`Chat`,projectId:e??null,metadata:{projectName:e,sessionId:t.id,providerId:t.providerId},closable:!0})}let I=(0,Q.useCallback)((e,t)=>{t.stopPropagation(),D(e.id),k(e.title||``),setTimeout(()=>A.current?.select(),0)},[]),R=(0,Q.useCallback)(async()=>{if(!E||!O.trim()||!e){D(null);return}try{await y.patch(`${_(e)}/chat/sessions/${E}`,{title:O.trim()}),v(e=>e.map(e=>e.id===E?{...e,title:O.trim()}:e))}catch{}D(null)},[E,O,e]),z=(0,Q.useCallback)(()=>D(null),[]),B=(0,Q.useCallback)(async(t,n)=>{if(t.stopPropagation(),!e)return;let r=`${_(e)}/chat/sessions/${n.id}/pin`;try{n.pinned?await y.del(r):await y.put(r),v(e=>e.map(e=>e.id===n.id?{...e,pinned:!e.pinned}:e).sort((e,t)=>e.pinned&&!t.pinned?-1:!e.pinned&&t.pinned?1:new Date(t.createdAt).getTime()-new Date(e.createdAt).getTime()))}catch{}},[e]),U=(0,Q.useCallback)(async(t,n)=>{if(t.stopPropagation(),e&&window.confirm(`Delete this session? This cannot be undone.`))try{await y.del(`${_(e)}/chat/sessions/${n.id}?providerId=${n.providerId}`),v(e=>e.filter(e=>e.id!==n.id))}catch{}},[e]),W=w.trim()?g.filter(e=>(e.title||``).toLowerCase().includes(w.toLowerCase())):g,G=!c||c===`claude`,q=t.fiveHour==null?null:Math.round(t.fiveHour*100),J=t.sevenDay==null?null:Math.round(t.sevenDay*100),te=q!=null||J!=null?Zn(Math.max(q??0,J??0)):`text-text-subtle`;return(0,$.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsxs)(`button`,{onClick:()=>M(`history`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${m===`history`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,children:[(0,$.jsx)(Be,{className:`size-3`}),(0,$.jsx)(`span`,{children:`History`})]}),s&&c&&c!==`mock`&&(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-1.5 py-0.5 text-[11px] text-text-secondary`,children:[(0,$.jsx)(oe,{providerId:c}),(0,$.jsx)(`span`,{className:`capitalize`,children:c})]}),(0,$.jsx)(`button`,{onClick:()=>M(`config`),className:`p-1 rounded transition-colors ${m===`config`?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary hover:bg-surface-elevated`}`,title:`AI Settings`,children:(0,$.jsx)(Ke,{className:`size-3`})}),G?(0,$.jsxs)(`button`,{onClick:()=>M(`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 ${m===`usage`?`bg-primary/10`:``} ${te}`,title:`Usage limits`,children:[(0,$.jsx)(Fe,{className:`size-3`}),t.activeAccountLabel&&(0,$.jsxs)(`span`,{className:`text-text-secondary font-normal truncate max-w-[60px]`,children:[`[`,t.activeAccountLabel,`]`]}),(0,$.jsxs)(`span`,{children:[`5h:`,q==null?`--%`:`${q}%`]}),(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,$.jsxs)(`span`,{children:[`Wk:`,J==null?`--%`:`${J}%`]}),n!=null&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,$.jsxs)(`span`,{className:Zn(n),children:[`Ctx:`,n,`%`]})]}),r===`compacting`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,$.jsx)(`span`,{className:`text-blue-400 animate-pulse`,children:`compacting...`})]})]}):(0,$.jsxs)($.Fragment,{children:[n!=null&&(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-1.5 py-0.5 text-[11px] font-medium tabular-nums ${Zn(n)}`,children:[(0,$.jsx)(Fe,{className:`size-3`}),(0,$.jsxs)(`span`,{children:[`Ctx:`,n,`%`]})]}),r===`compacting`&&(0,$.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 text-blue-400 animate-pulse`,children:`compacting...`})]}),(0,$.jsx)(`div`,{className:`flex-1`}),S&&s&&(0,$.jsx)(`button`,{onClick:()=>C(s),className:`p-1 rounded text-amber-500 hover:text-amber-400 hover:bg-surface-elevated transition-colors`,title:`Mark as read`,children:(0,$.jsx)(N,{className:`size-3`})}),s&&(0,$.jsx)(Qn,{sessionId:s,projectName:e}),p&&(0,$.jsx)(`button`,{onClick:p,className:`size-4 flex items-center justify-center`,title:f?`Connected`:`Disconnected — click to reconnect`,children:(0,$.jsx)(`span`,{className:`size-2 rounded-full ${f?`bg-green-500`:`bg-red-500 animate-pulse`}`})})]}),m===`history`&&(0,$.jsxs)(`div`,{className:`border-t border-border/30 bg-surface`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 border-b border-border/30`,children:[(0,$.jsx)(Y,{className:`size-3 text-text-subtle shrink-0`}),(0,$.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:`Search sessions...`,className:`flex-1 bg-transparent text-[11px] text-text-primary outline-none placeholder:text-text-subtle`}),(0,$.jsx)(`button`,{onClick:P,disabled:b,className:`p-0.5 rounded text-text-subtle hover:text-text-secondary transition-colors disabled:opacity-50`,title:`Refresh`,children:(0,$.jsx)(ee,{className:`size-3 ${b?`animate-spin`:``}`})})]}),(0,$.jsx)(`div`,{className:`max-h-[200px] overflow-y-auto`,children:b&&g.length===0?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,$.jsx)(Z,{className:`size-3.5 animate-spin text-text-subtle`})}):W.length===0?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-3 text-[11px] text-text-subtle`,children:w?`No matching sessions`:`No sessions yet`}):W.map(e=>(0,$.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,$.jsx)(oe,{providerId:e.providerId}),E===e.id?(0,$.jsxs)(`form`,{className:`flex items-center gap-1 flex-1 min-w-0`,onSubmit:e=>{e.preventDefault(),R()},children:[(0,$.jsx)(`input`,{ref:A,value:O,onChange:e=>k(e.target.value),onBlur:R,onKeyDown:e=>{e.key===`Escape`&&z()},className:`flex-1 min-w-0 bg-surface-elevated text-[11px] text-text-primary px-1 py-0.5 rounded border border-border outline-none focus:border-primary`,autoFocus:!0}),(0,$.jsx)(`button`,{type:`submit`,className:`p-0.5 text-green-500 hover:text-green-400`,onClick:e=>e.stopPropagation(),children:(0,$.jsx)(L,{className:`size-3`})}),(0,$.jsx)(`button`,{type:`button`,className:`p-0.5 text-text-subtle hover:text-text-secondary`,onClick:e=>{e.stopPropagation(),z()},children:(0,$.jsx)(H,{className:`size-3`})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:()=>F(e),className:`text-[11px] truncate flex-1 text-left`,children:e.title||`Untitled`}),(0,$.jsx)(`button`,{onClick:t=>B(t,e),className:`p-0.5 rounded transition-all ${e.pinned?`text-primary hover:text-primary/70`:`text-text-subtle hover:text-text-secondary md:opacity-0 md:group-hover:opacity-100`}`,title:e.pinned?`Unpin session`:`Pin session`,children:e.pinned?(0,$.jsx)(ye,{className:`size-3`}):(0,$.jsx)(ke,{className:`size-3`})}),(0,$.jsx)(`button`,{onClick:t=>I(e,t),className:`p-0.5 rounded text-text-subtle hover:text-text-secondary md:opacity-0 md:group-hover:opacity-100 transition-opacity`,title:`Rename session`,children:(0,$.jsx)(Ee,{className:`size-3`})}),(0,$.jsx)(`button`,{onClick:t=>U(t,e),className:`p-0.5 rounded text-text-subtle hover:text-red-400 hover:bg-red-500/20 md:opacity-0 md:group-hover:opacity-100 transition-opacity`,title:`Delete session`,children:(0,$.jsx)(V,{className:`size-3`})})]}),E!==e.id&&e.updatedAt&&(0,$.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0 w-10 text-right`,children:Xn(e.updatedAt)})]},e.id))})]}),m===`config`&&(0,$.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2 max-h-[280px] overflow-y-auto`,children:(0,$.jsx)(De,{compact:!0})}),m===`usage`&&G&&(0,$.jsx)(Yn,{usage:t,visible:!0,onClose:()=>h(null),onReload:a,loading:i,lastFetchedAt:o})]})}function er({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,d]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(null),[v,x]=(0,Q.useState)([]),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(``),[E,D]=(0,Q.useState)(null),[O,k]=(0,Q.useState)(e?.permissionMode??void 0),[A,j]=(0,Q.useState)(!1),[ee,M]=(0,Q.useState)(null),N=(0,Q.useRef)(0),P=e?.projectName??``,F=u(e=>e.updateTab),I=B(e=>e.version),{usageInfo:L,usageLoading:R,lastFetchedAt:z,refreshUsage:V}=ut(P,i);(0,Q.useEffect)(()=>{O||b().then(e=>{let t=e.providers[e.default_provider??`claude`];k(t?.permission_mode??`bypassPermissions`)}).catch(()=>{})},[]),(0,Q.useEffect)(()=>{!t||!n||F(t,{metadata:{...e,sessionId:n,providerId:i,permissionMode:O}})},[n,i,O]);let{messages:H,messagesLoading:U,isStreaming:W,phase:G,isReconnecting:q,connectingElapsed:J,pendingApproval:te,contextWindowPct:ne,compactStatus:re,sessionTitle:Y,migratedSessionId:X,sendMessage:ie,respondToApproval:ae,cancelStreaming:oe,reconnect:se,refetchMessages:ce,isConnected:le}=ct(n,i,P);(0,Q.useEffect)(()=>{X&&X!==n&&r(X)},[X]),(0,Q.useEffect)(()=>{if(!n||!t)return;let e=()=>{if(document.hidden)return;let{panels:e,focusedPanelId:r}=l.getState();e[r]?.activeTabId===t&&K.getState().clearForSession(n)};e(),document.addEventListener(`visibilitychange`,e);let r=l.subscribe(e);return()=>{document.removeEventListener(`visibilitychange`,e),r()}},[n,t]),(0,Q.useEffect)(()=>{t&&Y&&F(t,{title:Y})},[Y]);let[ue,de]=(0,Q.useState)(e?.pendingMessage);(0,Q.useEffect)(()=>{ue&&le&&n&&t&&F(t,{metadata:{...e,pendingMessage:void 0}})},[le,n]),(0,Q.useCallback)(()=>{u.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:P,providerId:i},projectId:P||null,closable:!0})},[P,i]);let fe=(0,Q.useCallback)(e=>{r(e.id),a(e.providerId),t&&F(t,{title:e.title||`Chat`})},[t,F]),pe=(0,Q.useCallback)(async(e,t)=>{if(!(!n||!P))try{let{api:r,projectUrl:a}=await f(async()=>{let{api:e,projectUrl:t}=await import(`./api-client-BfBM3I7n.js`).then(e=>e.n);return{api:e,projectUrl:t}},__vite__mapDeps([0,1])),o=await r.post(`${a(P)}/chat/sessions/${n}/fork?providerId=${i}`,{messageId:t});u.getState().openTab({type:`chat`,title:`Fork: ${e.slice(0,30)}`,metadata:{projectName:P,sessionId:o.id,providerId:i,pendingMessage:e},projectId:P||null,closable:!0})}catch(e){console.error(`Fork failed:`,e)}},[n,P,i]),he=(0,Q.useCallback)((e,t)=>{if(t.length===0)return e;let n=t.filter(e=>e.serverPath).map(e=>e.serverPath).join(`
8
+ `);return n?(t.length===1?`[Attached file: ${n}]\n\n`:`[Attached files:\n${n}\n]\n\n`)+e:e},[]),ge=(0,Q.useCallback)(async(e,t=[],o)=>{let s=he(e,t);if(s.trim()){if(!n)try{let t=P,n=await y.post(`${_(t)}/chat/sessions`,{providerId:i,title:e.slice(0,50)});r(n.id),a(n.providerId),setTimeout(()=>{ie(s,{permissionMode:O})},500);return}catch(e){console.error(`Failed to create session:`,e);return}ie(s,{permissionMode:O,priority:o})}},[n,i,P,ie,he,O]),_e=(0,Q.useCallback)((e,t)=>{d(e),m(t)},[]),ve=(0,Q.useCallback)(e=>{g(e),d(!1),m(``),setTimeout(()=>g(null),50)},[]),ye=(0,Q.useCallback)(()=>{d(!1),m(``)},[]),be=(0,Q.useCallback)((e,t)=>{C(e),T(t)},[]),xe=(0,Q.useCallback)(e=>{D(e),C(!1),T(``),setTimeout(()=>D(null),50)},[]),Se=(0,Q.useCallback)(()=>{C(!1),T(``)},[]);return(0,$.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,Q.useCallback)(e=>{e.preventDefault(),N.current++,e.dataTransfer.types.includes(`Files`)&&j(!0)},[]),onDragLeave:(0,Q.useCallback)(e=>{e.preventDefault(),N.current--,N.current===0&&j(!1)},[]),onDragOver:(0,Q.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,Q.useCallback)(e=>{e.preventDefault(),N.current=0,j(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&(M(t),setTimeout(()=>M(null),100))},[]),children:[A&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm border-2 border-dashed border-primary rounded-lg pointer-events-none`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-primary`,children:[(0,$.jsx)(we,{className:`size-8`}),(0,$.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),q&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/60 backdrop-blur-sm`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(Z,{className:`size-4 animate-spin`}),(0,$.jsx)(`span`,{children:`Reconnecting...`})]})}),(0,$.jsx)(Lt,{messages:H,messagesLoading:U,pendingApproval:te,onApprovalResponse:ae,isStreaming:W,phase:G,connectingElapsed:J,projectName:P,onFork:W?void 0:pe}),(0,$.jsxs)(`div`,{className:`border-t border-border bg-background shrink-0`,children:[(0,$.jsx)($n,{projectName:P,usageInfo:L,contextWindowPct:ne,compactStatus:re,usageLoading:R,refreshUsage:V,lastFetchedAt:z,sessionId:n,providerId:i,onSelectSession:fe,onBugReport:n?()=>me(I,{sessionId:n,projectName:P}):void 0,isConnected:le,onReconnect:()=>{le||se(),ce()}}),(0,$.jsx)(An,{items:o,filter:p,onSelect:ve,onClose:ye,visible:c}),(0,$.jsx)(Tn,{items:v,filter:w,onSelect:xe,onClose:Se,visible:S}),(0,$.jsx)(En,{onSend:(e,t,n)=>{ue&&de(void 0),ge(e,t,n)},isStreaming:W,onCancel:oe,autoFocus:!e?.sessionId||!!ue,initialValue:ue,projectName:P,onSlashStateChange:_e,onSlashItemsLoaded:s,slashSelected:h,onFileStateChange:be,onFileItemsLoaded:x,fileSelected:E,externalFiles:ee,permissionMode:O,onModeChange:k,providerId:i,onProviderChange:n?void 0:a})]})]})}export{er as ChatTab};
@@ -0,0 +1 @@
1
+ import{t as e}from"./createLucideIcon-PuMiQgHl.js";var t=e(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]);export{t};