@hienlh/ppm 0.5.1 → 0.5.3

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 (70) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/web/assets/{api-client-ANLU-Irq.js → api-client-BxCvlogn.js} +1 -1
  3. package/dist/web/assets/chat-tab-AwRs7rWS.js +7 -0
  4. package/dist/web/assets/code-editor-BviTme00.js +1 -0
  5. package/dist/web/assets/diff-viewer-CCZM_VBl.js +4 -0
  6. package/dist/web/assets/git-graph-UCZZ6fX6.js +1 -0
  7. package/dist/web/assets/index-BxHR8fUA.css +2 -0
  8. package/dist/web/assets/index-yvVRZ65D.js +21 -0
  9. package/dist/web/assets/{input-D-F4ITU0.js → input-Bzyi1GeB.js} +1 -1
  10. package/dist/web/assets/{jsx-runtime-B4BJKQ1u.js → jsx-runtime-Bzk8w7Zh.js} +1 -1
  11. package/dist/web/assets/markdown-renderer-DzVh1Ft8.js +59 -0
  12. package/dist/web/assets/{rotate-ccw-BesidNnx.js → rotate-ccw-ZqeedZLA.js} +1 -1
  13. package/dist/web/assets/settings-store-DikslxSJ.js +1 -0
  14. package/dist/web/assets/settings-tab-C-AGuxll.js +1 -0
  15. package/dist/web/assets/tab-store-BNgVKR5w.js +1 -0
  16. package/dist/web/assets/terminal-tab-CnbdkUFt.js +36 -0
  17. package/dist/web/assets/{use-monaco-theme-CsNwoeyj.js → use-monaco-theme-BFv4d2_j.js} +2 -2
  18. package/dist/web/assets/{utils-bntUtdc7.js → utils-EM9hC5pN.js} +1 -1
  19. package/dist/web/index.html +8 -9
  20. package/dist/web/sw.js +1 -1
  21. package/package.json +1 -1
  22. package/src/cli/commands/init.ts +2 -2
  23. package/src/cli/commands/status.ts +66 -1
  24. package/src/cli/commands/stop.ts +39 -2
  25. package/src/index.ts +4 -2
  26. package/src/providers/claude-agent-sdk.ts +30 -21
  27. package/src/server/helpers/resolve-project.ts +2 -2
  28. package/src/server/index.ts +2 -1
  29. package/src/server/routes/chat.ts +1 -0
  30. package/src/server/ws/chat.ts +4 -2
  31. package/src/services/claude-usage.service.ts +34 -0
  32. package/src/services/config.service.ts +11 -1
  33. package/src/types/api.ts +1 -2
  34. package/src/types/chat.ts +1 -2
  35. package/src/web/components/chat/attachment-chips.tsx +1 -1
  36. package/src/web/components/chat/chat-history-bar.tsx +7 -3
  37. package/src/web/components/chat/chat-tab.tsx +4 -2
  38. package/src/web/components/chat/message-input.tsx +13 -14
  39. package/src/web/components/chat/message-list.tsx +5 -4
  40. package/src/web/components/chat/tool-cards.tsx +3 -6
  41. package/src/web/components/editor/code-editor.tsx +2 -1
  42. package/src/web/components/editor/diff-viewer.tsx +43 -22
  43. package/src/web/components/explorer/file-tree.tsx +3 -3
  44. package/src/web/components/git/git-graph.tsx +2 -1
  45. package/src/web/components/git/git-status-panel.tsx +166 -89
  46. package/src/web/components/layout/command-palette.tsx +2 -1
  47. package/src/web/components/layout/mobile-drawer.tsx +2 -2
  48. package/src/web/components/layout/mobile-nav.tsx +1 -1
  49. package/src/web/components/layout/panel-layout.tsx +16 -16
  50. package/src/web/components/layout/split-drop-overlay.tsx +3 -3
  51. package/src/web/components/shared/markdown-renderer.tsx +16 -10
  52. package/src/web/hooks/use-chat.ts +10 -17
  53. package/src/web/hooks/use-terminal.ts +66 -23
  54. package/src/web/hooks/use-usage.ts +1 -14
  55. package/src/web/lib/utils.ts +5 -0
  56. package/src/web/stores/panel-store.ts +15 -14
  57. package/src/web/stores/panel-utils.ts +12 -10
  58. package/src/web/stores/settings-store.ts +1 -1
  59. package/dist/web/assets/chat-tab-d_HzPDhE.js +0 -7
  60. package/dist/web/assets/code-editor-DFAu3knd.js +0 -1
  61. package/dist/web/assets/diff-viewer-Bue0mOJY.js +0 -4
  62. package/dist/web/assets/git-graph-Cjq-lK5h.js +0 -1
  63. package/dist/web/assets/index-D_IIxtVN.js +0 -21
  64. package/dist/web/assets/index-DhsWierF.css +0 -2
  65. package/dist/web/assets/markdown-renderer-B9l76G5h.js +0 -59
  66. package/dist/web/assets/react-WvgCEYPV.js +0 -1
  67. package/dist/web/assets/settings-store-CGtTcr8r.js +0 -1
  68. package/dist/web/assets/settings-tab-BDPgdHPI.js +0 -1
  69. package/dist/web/assets/tab-store-Dq1kMOkJ.js +0 -1
  70. package/dist/web/assets/terminal-tab-BEOvTEai.js +0 -36
@@ -4,6 +4,7 @@ import { useTabStore } from "@/stores/tab-store";
4
4
  import { useFileStore, type FileNode } from "@/stores/file-store";
5
5
  import { openCommandPalette } from "@/hooks/use-global-keybindings";
6
6
  import { api, projectUrl } from "@/lib/api-client";
7
+ import { basename } from "@/lib/utils";
7
8
 
8
9
  // Configure marked globally
9
10
  marked.use({ gfm: true, breaks: true });
@@ -11,6 +12,8 @@ marked.use({ gfm: true, breaks: true });
11
12
  /** Common text file extensions that PPM can open as editor tabs */
12
13
  const FILE_EXTS = "ts|tsx|js|jsx|mjs|cjs|py|json|md|mdx|yaml|yml|toml|css|scss|less|html|htm|sh|bash|zsh|go|rs|sql|rb|java|kt|swift|c|cpp|h|hpp|cs|vue|svelte|txt|env|cfg|conf|ini|xml|csv|log|dockerfile|makefile|gradle";
13
14
  const FILE_EXT_RE = new RegExp(`\\.(${FILE_EXTS})$`, "i");
15
+ /** Glob/regex chars that indicate a pattern, not a real file */
16
+ const GLOB_CHARS_RE = /[*?{}\[\]]/;
14
17
 
15
18
  interface MarkdownRendererProps {
16
19
  content: string;
@@ -39,11 +42,12 @@ function transformHtml(raw: string): string {
39
42
  '<a href="$1" target="_blank" rel="noopener noreferrer"',
40
43
  );
41
44
 
42
- // <a> with file paths → add data-file-path
45
+ // <a> with file paths → add data-file-path (only files, not folders or glob patterns)
43
46
  html = html.replace(/<a\s+href="([^"]+)"/g, (match, href: string) => {
44
47
  if (/^https?:\/\//.test(href)) return match; // already handled
45
- const isFile = /^(\/|\.\/|\.\.\/)/.test(href) || FILE_EXT_RE.test(href);
46
- return isFile ? `<a href="${href}" data-file-path="${href}"` : match;
48
+ if (GLOB_CHARS_RE.test(href)) return match; // skip glob/regex patterns
49
+ if (!FILE_EXT_RE.test(href)) return match; // must have a file extension
50
+ return `<a href="${href}" data-file-path="${href}"`;
47
51
  });
48
52
 
49
53
  // Inline <code> with file-like names → make clickable
@@ -58,7 +62,8 @@ function transformHtml(raw: string): string {
58
62
  (match, text: string) => {
59
63
  const trimmed = text.trim();
60
64
  if (!trimmed || trimmed.includes(" ")) return match;
61
- if (!FILE_EXT_RE.test(trimmed) && !/^(\/|\.\/|\.\.\/)/.test(trimmed)) return match;
65
+ if (GLOB_CHARS_RE.test(trimmed)) return match; // skip glob/regex patterns
66
+ if (!FILE_EXT_RE.test(trimmed)) return match; // must have a file extension
62
67
  return `<code data-file-clickable="${trimmed}" style="cursor:pointer;text-decoration:underline;text-decoration-style:dotted">${text}</code>`;
63
68
  },
64
69
  );
@@ -119,7 +124,7 @@ export function MarkdownRenderer({ content, projectName, className = "", codeAct
119
124
  if (!filePath) return;
120
125
  const isAbsolute = /^(\/|[A-Za-z]:[/\\])/.test(filePath);
121
126
  const isRelative = /^(\.\/|\.\.\/)/.test(filePath);
122
- const fileName = filePath.split("/").pop() ?? filePath;
127
+ const fileName = basename(filePath);
123
128
 
124
129
  // Absolute path → verify then open
125
130
  if (isAbsolute) {
@@ -138,16 +143,17 @@ export function MarkdownRenderer({ content, projectName, className = "", codeAct
138
143
  .then(() => {
139
144
  openTab({ type: "editor", title: fileName, metadata: meta, projectId: projectName, closable: true });
140
145
  })
141
- .catch(() => searchAndOpen(fileName));
146
+ .catch(() => searchAndOpen(filePath));
142
147
  return;
143
148
  }
144
149
 
145
150
  // Just a filename → search in project tree
146
- searchAndOpen(fileName);
151
+ searchAndOpen(filePath);
147
152
  }
148
153
 
149
- /** Search project file tree; if 1 match → open directly, else → command palette */
150
- function searchAndOpen(fileName: string) {
154
+ /** Search project file tree; if 1 match → open directly, else → command palette with full path */
155
+ function searchAndOpen(filePath: string) {
156
+ const fileName = basename(filePath);
151
157
  const matches = findInTree(fileTree, fileName);
152
158
  if (matches.length === 1) {
153
159
  const match = matches[0]!;
@@ -159,7 +165,7 @@ export function MarkdownRenderer({ content, projectName, className = "", codeAct
159
165
  closable: true,
160
166
  });
161
167
  } else {
162
- openCommandPalette(fileName);
168
+ openCommandPalette(filePath);
163
169
  }
164
170
  }
165
171
 
@@ -1,22 +1,15 @@
1
1
  import { useState, useCallback, useRef, useEffect } from "react";
2
2
  import { useWebSocket } from "./use-websocket";
3
3
  import { getAuthToken, projectUrl } from "@/lib/api-client";
4
- import type { ChatMessage, ChatEvent, UsageInfo } from "../../types/chat";
4
+ import type { ChatMessage, ChatEvent } from "../../types/chat";
5
5
  import type { ChatWsServerMessage } from "../../types/api";
6
6
 
7
- /** Callback to forward WS usage events to the external useUsage hook */
8
- export type UsageEventCallback = (usage: Partial<UsageInfo>) => void;
9
-
10
7
  interface ApprovalRequest {
11
8
  requestId: string;
12
9
  tool: string;
13
10
  input: unknown;
14
11
  }
15
12
 
16
- interface UseChatOptions {
17
- onUsageEvent?: UsageEventCallback;
18
- }
19
-
20
13
  /** Streaming phase: connecting → streaming → idle */
21
14
  export type StreamingStatus = "idle" | "connecting" | "streaming";
22
15
 
@@ -28,6 +21,8 @@ interface UseChatReturn {
28
21
  connectingElapsed: number;
29
22
  thinkingWarningThreshold: number;
30
23
  pendingApproval: ApprovalRequest | null;
24
+ /** Context window usage % from last completed query (0–100) */
25
+ contextWindowPct: number | null;
31
26
  sendMessage: (content: string) => void;
32
27
  respondToApproval: (requestId: string, approved: boolean, data?: unknown) => void;
33
28
  cancelStreaming: () => void;
@@ -36,7 +31,7 @@ interface UseChatReturn {
36
31
  isConnected: boolean;
37
32
  }
38
33
 
39
- export function useChat(sessionId: string | null, providerId = "claude-sdk", projectName = "", options?: UseChatOptions): UseChatReturn {
34
+ export function useChat(sessionId: string | null, providerId = "claude-sdk", projectName = ""): UseChatReturn {
40
35
  const [messages, setMessages] = useState<ChatMessage[]>([]);
41
36
  const [messagesLoading, setMessagesLoading] = useState(false);
42
37
  const [isStreaming, setIsStreaming] = useState(false);
@@ -46,9 +41,8 @@ export function useChat(sessionId: string | null, providerId = "claude-sdk", pro
46
41
  /** Warning threshold in seconds — higher for deeper thinking modes */
47
42
  const [thinkingWarningThreshold, setThinkingWarningThreshold] = useState(15);
48
43
  const [pendingApproval, setPendingApproval] = useState<ApprovalRequest | null>(null);
44
+ const [contextWindowPct, setContextWindowPct] = useState<number | null>(null);
49
45
  const [isConnected, setIsConnected] = useState(false);
50
- const onUsageEventRef = useRef(options?.onUsageEvent);
51
- onUsageEventRef.current = options?.onUsageEvent;
52
46
  const streamingContentRef = useRef("");
53
47
  const streamingEventsRef = useRef<ChatEvent[]>([]);
54
48
  const isStreamingRef = useRef(false);
@@ -213,12 +207,6 @@ export function useChat(sessionId: string | null, providerId = "claude-sdk", pro
213
207
  break;
214
208
  }
215
209
 
216
- case "usage": {
217
- // Forward to external usage hook
218
- onUsageEventRef.current?.(data.usage);
219
- break;
220
- }
221
-
222
210
  case "error": {
223
211
  streamingEventsRef.current.push(data);
224
212
  const errEvents = [...streamingEventsRef.current];
@@ -250,6 +238,10 @@ export function useChat(sessionId: string | null, providerId = "claude-sdk", pro
250
238
  case "done": {
251
239
  // Idempotent: may receive duplicate done (provider + stream loop finally)
252
240
  if (!isStreamingRef.current) break;
241
+ // Capture context window usage from SDK result
242
+ if (data.contextWindowPct != null) {
243
+ setContextWindowPct(data.contextWindowPct);
244
+ }
253
245
  // Finalize the streaming message — capture refs before clearing
254
246
  const finalContent = streamingContentRef.current;
255
247
  const finalEvents = [...streamingEventsRef.current];
@@ -482,6 +474,7 @@ export function useChat(sessionId: string | null, providerId = "claude-sdk", pro
482
474
  connectingElapsed,
483
475
  thinkingWarningThreshold,
484
476
  pendingApproval,
477
+ contextWindowPct,
485
478
  sendMessage,
486
479
  respondToApproval,
487
480
  cancelStreaming,
@@ -1,7 +1,61 @@
1
1
  import { useEffect, useRef, useCallback, useState } from "react";
2
- import { Terminal } from "@xterm/xterm";
2
+ import { Terminal, type ITheme } from "@xterm/xterm";
3
3
  import { FitAddon } from "@xterm/addon-fit";
4
4
  import { WebLinksAddon } from "@xterm/addon-web-links";
5
+ import { useSettingsStore, type Theme } from "@/stores/settings-store";
6
+
7
+ const DARK_THEME: ITheme = {
8
+ background: "#0f1419",
9
+ foreground: "#e5e7eb",
10
+ cursor: "#e5e7eb",
11
+ selectionBackground: "#3b82f640",
12
+ black: "#1a1f2e",
13
+ red: "#ef4444",
14
+ green: "#10b981",
15
+ yellow: "#f59e0b",
16
+ blue: "#3b82f6",
17
+ magenta: "#a855f7",
18
+ cyan: "#06b6d4",
19
+ white: "#e5e7eb",
20
+ brightBlack: "#6b7280",
21
+ brightRed: "#f87171",
22
+ brightGreen: "#34d399",
23
+ brightYellow: "#fbbf24",
24
+ brightBlue: "#60a5fa",
25
+ brightMagenta: "#c084fc",
26
+ brightCyan: "#22d3ee",
27
+ brightWhite: "#f9fafb",
28
+ };
29
+
30
+ const LIGHT_THEME: ITheme = {
31
+ background: "#ffffff",
32
+ foreground: "#1a1f2e",
33
+ cursor: "#1a1f2e",
34
+ selectionBackground: "#2563eb30",
35
+ black: "#1a1f2e",
36
+ red: "#dc2626",
37
+ green: "#059669",
38
+ yellow: "#d97706",
39
+ blue: "#2563eb",
40
+ magenta: "#9333ea",
41
+ cyan: "#0891b2",
42
+ white: "#f8fafc",
43
+ brightBlack: "#64748b",
44
+ brightRed: "#ef4444",
45
+ brightGreen: "#10b981",
46
+ brightYellow: "#f59e0b",
47
+ brightBlue: "#3b82f6",
48
+ brightMagenta: "#a855f7",
49
+ brightCyan: "#06b6d4",
50
+ brightWhite: "#ffffff",
51
+ };
52
+
53
+ function resolveTheme(theme: Theme): ITheme {
54
+ if (theme === "system") {
55
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? DARK_THEME : LIGHT_THEME;
56
+ }
57
+ return theme === "light" ? LIGHT_THEME : DARK_THEME;
58
+ }
5
59
 
6
60
  interface UseTerminalOptions {
7
61
  sessionId: string;
@@ -123,28 +177,7 @@ export function useTerminal(
123
177
  cursorBlink: true,
124
178
  fontSize: 13,
125
179
  fontFamily: "var(--font-mono)",
126
- theme: {
127
- background: "#0f1419",
128
- foreground: "#e5e7eb",
129
- cursor: "#e5e7eb",
130
- selectionBackground: "#3b82f640",
131
- black: "#1a1f2e",
132
- red: "#ef4444",
133
- green: "#10b981",
134
- yellow: "#f59e0b",
135
- blue: "#3b82f6",
136
- magenta: "#a855f7",
137
- cyan: "#06b6d4",
138
- white: "#e5e7eb",
139
- brightBlack: "#6b7280",
140
- brightRed: "#f87171",
141
- brightGreen: "#34d399",
142
- brightYellow: "#fbbf24",
143
- brightBlue: "#60a5fa",
144
- brightMagenta: "#c084fc",
145
- brightCyan: "#22d3ee",
146
- brightWhite: "#f9fafb",
147
- },
180
+ theme: resolveTheme(useSettingsStore.getState().theme),
148
181
  });
149
182
 
150
183
  const fitAddon = new FitAddon();
@@ -180,7 +213,17 @@ export function useTerminal(
180
213
  });
181
214
  resizeObserver.observe(container);
182
215
 
216
+ // React to theme changes
217
+ let prevTheme = useSettingsStore.getState().theme;
218
+ const unsubTheme = useSettingsStore.subscribe((state) => {
219
+ if (state.theme !== prevTheme) {
220
+ prevTheme = state.theme;
221
+ term.options.theme = resolveTheme(state.theme);
222
+ }
223
+ });
224
+
183
225
  return () => {
226
+ unsubTheme();
184
227
  resizeObserver.disconnect();
185
228
  if (reconnectTimer.current) clearTimeout(reconnectTimer.current);
186
229
  wsRef.current?.close();
@@ -10,8 +10,6 @@ interface UseUsageReturn {
10
10
  /** ISO timestamp from BE — when usage was actually fetched from Anthropic API */
11
11
  lastFetchedAt: string | null;
12
12
  refreshUsage: () => void;
13
- /** Merge partial usage from WebSocket events (cost tracking) */
14
- mergeUsage: (partial: Partial<UsageInfo>) => void;
15
13
  }
16
14
 
17
15
  export function useUsage(projectName: string, providerId = "claude-sdk"): UseUsageReturn {
@@ -48,16 +46,5 @@ export function useUsage(projectName: string, providerId = "claude-sdk"): UseUsa
48
46
  /** Manual refresh — tells BE to fetch fresh from Anthropic API */
49
47
  const refreshUsage = useCallback(() => doFetch(true), [doFetch]);
50
48
 
51
- const mergeUsage = useCallback((partial: Partial<UsageInfo>) => {
52
- setUsageInfo((prev) => {
53
- const next = { ...prev, ...partial };
54
- if (partial.totalCostUsd != null) {
55
- next.queryCostUsd = partial.totalCostUsd;
56
- next.totalCostUsd = (prev.totalCostUsd ?? 0) + partial.totalCostUsd;
57
- }
58
- return next;
59
- });
60
- }, []);
61
-
62
- return { usageInfo, usageLoading, lastFetchedAt, refreshUsage, mergeUsage };
49
+ return { usageInfo, usageLoading, lastFetchedAt, refreshUsage };
63
50
  }
@@ -5,6 +5,11 @@ export function cn(...inputs: ClassValue[]) {
5
5
  return twMerge(clsx(inputs));
6
6
  }
7
7
 
8
+ /** Cross-platform basename — handles both / and \ separators */
9
+ export function basename(filePath: string): string {
10
+ return filePath.split(/[/\\]/).pop() ?? filePath;
11
+ }
12
+
8
13
  /** crypto.randomUUID() fallback for non-secure contexts (HTTP) */
9
14
  export function randomId(): string {
10
15
  if (typeof crypto !== "undefined" && crypto.randomUUID) {
@@ -371,11 +371,11 @@ export const usePanelStore = create<PanelStore>()((set, get) => {
371
371
  const pos = findPanelPosition(grid, positionPanelId);
372
372
  if (!pos) return false;
373
373
 
374
- // Check constraints
374
+ // Check constraints — grid is row-major: grid[row][col]
375
375
  const isHorizontal = direction === "left" || direction === "right";
376
376
  const isVertical = direction === "up" || direction === "down";
377
- if (isHorizontal && grid.length >= maxColumns(mobile)) return false;
378
- if (isVertical && (grid[pos.col]?.length ?? 0) >= MAX_ROWS) return false;
377
+ if (isHorizontal && (grid[pos.row]?.length ?? 0) >= maxColumns(mobile)) return false;
378
+ if (isVertical && grid.length >= MAX_ROWS) return false;
379
379
 
380
380
  const newPanel = createPanel([tab], tab.id);
381
381
  newPanel.tabHistory = [tab.id];
@@ -389,18 +389,19 @@ export const usePanelStore = create<PanelStore>()((set, get) => {
389
389
 
390
390
  let newGrid: string[][];
391
391
  if (isHorizontal) {
392
- newGrid = [...grid];
393
- const insertCol = direction === "right" ? pos.col + 1 : pos.col;
394
- newGrid.splice(insertCol, 0, [newPanel.id]);
395
- } else {
396
- // up: insert before current row, down: insert after
397
- newGrid = grid.map((col, c) => {
398
- if (c !== pos.col) return col;
399
- const newCol = [...col];
400
- const insertRow = direction === "down" ? pos.row + 1 : pos.row;
401
- newCol.splice(insertRow, 0, newPanel.id);
402
- return newCol;
392
+ // Add column within the same row
393
+ newGrid = grid.map((row, r) => {
394
+ if (r !== pos.row) return row;
395
+ const newRow = [...row];
396
+ const insertCol = direction === "right" ? pos.col + 1 : pos.col;
397
+ newRow.splice(insertCol, 0, newPanel.id);
398
+ return newRow;
403
399
  });
400
+ } else {
401
+ // Add new row to the grid
402
+ newGrid = [...grid];
403
+ const insertRow = direction === "down" ? pos.row + 1 : pos.row;
404
+ newGrid.splice(insertRow, 0, [newPanel.id]);
404
405
  }
405
406
 
406
407
  set((s) => {
@@ -13,7 +13,7 @@ export interface Panel {
13
13
 
14
14
  export interface PanelLayout {
15
15
  panels: Record<string, Panel>;
16
- /** grid[col][row] = panelId */
16
+ /** grid[row][col] = panelId */
17
17
  grid: string[][];
18
18
  focusedPanelId: string;
19
19
  }
@@ -39,18 +39,20 @@ export function maxColumns(isMobile: boolean): number {
39
39
  return isMobile ? 1 : 3;
40
40
  }
41
41
 
42
- /** Max rows per column */
43
- export const MAX_ROWS = 2;
42
+ /** Max rows in the grid */
43
+ export const MAX_ROWS = 3;
44
44
 
45
45
  // ---------------------------------------------------------------------------
46
46
  // Grid manipulation
47
47
  // ---------------------------------------------------------------------------
48
- export function gridAddColumn(grid: string[][], panelId: string): string[][] {
48
+ /** Add a new row to the grid (outer array) */
49
+ export function gridAddRow(grid: string[][], panelId: string): string[][] {
49
50
  return [...grid, [panelId]];
50
51
  }
51
52
 
52
- export function gridAddRow(grid: string[][], colIndex: number, panelId: string): string[][] {
53
- return grid.map((col, i) => (i === colIndex ? [...col, panelId] : col));
53
+ /** Add a column within an existing row (inner array) */
54
+ export function gridAddColumn(grid: string[][], rowIndex: number, panelId: string): string[][] {
55
+ return grid.map((row, i) => (i === rowIndex ? [...row, panelId] : row));
54
56
  }
55
57
 
56
58
  export function gridRemovePanel(grid: string[][], panelId: string): string[][] {
@@ -59,10 +61,10 @@ export function gridRemovePanel(grid: string[][], panelId: string): string[][] {
59
61
  .filter((col) => col.length > 0);
60
62
  }
61
63
 
62
- export function findPanelPosition(grid: string[][], panelId: string): { col: number; row: number } | null {
63
- for (let c = 0; c < grid.length; c++) {
64
- const r = grid[c]!.indexOf(panelId);
65
- if (r !== -1) return { col: c, row: r };
64
+ export function findPanelPosition(grid: string[][], panelId: string): { row: number; col: number } | null {
65
+ for (let r = 0; r < grid.length; r++) {
66
+ const c = grid[r]!.indexOf(panelId);
67
+ if (c !== -1) return { row: r, col: c };
66
68
  }
67
69
  return null;
68
70
  }
@@ -76,7 +76,7 @@ export const useSettingsStore = create<SettingsState>((set, get) => ({
76
76
  theme: (_initial.theme === "light" || _initial.theme === "dark" || _initial.theme === "system") ? _initial.theme : "system",
77
77
  sidebarCollapsed: _initial.sidebarCollapsed ?? false,
78
78
  sidebarWidth: _initial.sidebarWidth ?? 280,
79
- gitStatusViewMode: _initial.gitStatusViewMode === "tree" ? "tree" : "flat",
79
+ gitStatusViewMode: _initial.gitStatusViewMode === "flat" ? "flat" : "tree",
80
80
  wordWrap: _initial.wordWrap ?? false,
81
81
  sidebarActiveTab: (_initial.sidebarActiveTab === "git" || _initial.sidebarActiveTab === "settings") ? _initial.sidebarActiveTab : "explorer",
82
82
  deviceName: null,
@@ -1,7 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-client-ANLU-Irq.js","assets/jsx-runtime-B4BJKQ1u.js"])))=>i.map(i=>d[i]);
2
- import{n as e,o as t,r as n,t as r}from"./jsx-runtime-B4BJKQ1u.js";import"./input-D-F4ITU0.js";import{a as i,t as a}from"./tab-store-Dq1kMOkJ.js";import{t as o}from"./rotate-ccw-BesidNnx.js";import{n as s}from"./settings-store-CGtTcr8r.js";import{n as c}from"./utils-bntUtdc7.js";import{i as l,r as u,t as d}from"./api-client-ANLU-Irq.js";import{C as f,D as p,F as m,M as h,N as g,O as _,P as v,S as y,b,g as x,k as S,r as C,t as w,v as T,w as E,x as D}from"./index-D_IIxtVN.js";import{t as O}from"./markdown-renderer-B9l76G5h.js";var k=e(`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`}]]),A=e(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),j=e(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),M=e(`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`}]]),N=e(`code`,[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]),P=e(`columns-2`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M12 3v18`,key:`108xh3`}]]),F=e(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),I=e(`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`}]]),L=e(`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`}]]),R=e(`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`}]]),z=e(`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`}]]),B=e(`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`}]]),V=e(`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`}]]),ee=e(`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`}]]),H=e(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),te=e(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),U=t(n(),1),ne=3e4,re=1e3,ie=class{ws=null;url;handlers=[];reconnectAttempts=0;reconnectTimer=null;intentionalClose=!1;constructor(e){this.url=e}connect(){this.intentionalClose=!1,this.cleanup();let e=window.location.protocol===`https:`?`wss:`:`ws:`,t=this.url.startsWith(`ws`)?this.url:`${e}//${window.location.host}${this.url}`;this.ws=new WebSocket(t),this.ws.onopen=()=>{this.reconnectAttempts=0},this.ws.onmessage=e=>{for(let t of this.handlers)t(e)},this.ws.onclose=()=>{this.intentionalClose||this.scheduleReconnect()},this.ws.onerror=()=>{this.ws?.close()}}disconnect(){this.intentionalClose=!0,this.cleanup(),this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null)}send(e){this.ws?.readyState===WebSocket.OPEN&&this.ws.send(e)}onMessage(e){return this.handlers.push(e),()=>{this.handlers=this.handlers.filter(t=>t!==e)}}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}cleanup(){this.ws&&=(this.ws.onopen=null,this.ws.onclose=null,this.ws.onmessage=null,this.ws.onerror=null,(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)&&this.ws.close(),null)}scheduleReconnect(){let e=Math.min(re*2**this.reconnectAttempts,ne);this.reconnectAttempts++,this.reconnectTimer=setTimeout(()=>this.connect(),e)}};function ae({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,U.useRef)(null);return(0,U.useEffect)(()=>{let i=new ie(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,U.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,U.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,U.useCallback)(()=>{r.current?.disconnect()},[])}}function oe(e,t=`claude-sdk`,n=``,r){let[i,a]=(0,U.useState)([]),[o,s]=(0,U.useState)(!1),[c,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(`idle`),[m,h]=(0,U.useState)(0),[g,_]=(0,U.useState)(15),[v,y]=(0,U.useState)(null),[b,x]=(0,U.useState)(!1),S=(0,U.useRef)(r?.onUsageEvent);S.current=r?.onUsageEvent;let C=(0,U.useRef)(``),w=(0,U.useRef)([]),T=(0,U.useRef)(!1),E=(0,U.useRef)(null),D=(0,U.useRef)(()=>{}),O=(0,U.useRef)(null),k=(0,U.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type===`ping`)return;if(t.type===`streaming_status`){let e=t.status??`idle`;if(p(e),h(e===`connecting`?t.elapsed??0:0),e===`connecting`){let e=t.effort,n=t.thinkingBudget,r=15;n&&n>0?r=Math.max(15,Math.round(n/500)):e===`high`?r=30:e===`low`&&(r=10),_(r)}return}if(t.type===`connected`){x(!0);return}if(t.type===`status`){x(!0);let e=t;e.isStreaming&&(T.current=!0,d(!0)),e.pendingApproval&&y({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),O.current?.();return}let n=(e,t)=>{let n=w.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=w.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return w.current[n]={...r,children:i},!0},r=()=>{let e=C.current,t=[...w.current];a(n=>{let r=n[n.length-1];return r?.role===`assistant`&&!r.id.startsWith(`final-`)?[...n.slice(0,-1),{...r,content:e,events:t}]:[...n,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:t,timestamp:new Date().toISOString()}]})};switch(t.type){case`text`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}C.current+=t.content,w.current.push(t),r();break}case`thinking`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}w.current.push(t),r();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}w.current.push(t),r();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}w.current.push(t),r();break}case`approval_request`:w.current.push(t),y({requestId:t.requestId,tool:t.tool,input:t.input});break;case`usage`:S.current?.(t.usage);break;case`error`:{w.current.push(t);let e=[...w.current];a(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()}]}),T.current=!1,d(!1),p(`idle`);break}case`done`:{if(!T.current)break;let e=C.current,t=[...w.current];a(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}),C.current=``,w.current=[],T.current=!1,d(!1),p(`idle`);break}}},[]),{send:A,connect:j}=ae({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:k,autoConnect:!!e&&!!n});D.current=A,(0,U.useEffect)(()=>{let r=!1;return d(!1),y(null),C.current=``,w.current=[],x(!1),e&&n?(s(!0),fetch(`${l(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${u()}`}}).then(e=>e.json()).then(e=>{r||T.current||(e.ok&&Array.isArray(e.data)&&e.data.length>0?a(e.data):a([]))}).catch(()=>{!r&&!T.current&&a([])}).finally(()=>{r||s(!1)})):a([]),()=>{r=!0}},[e,t,n]);let M=(0,U.useCallback)(e=>{if(e.trim()){if(T.current){let e=C.current,t=[...w.current];a(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}),A(JSON.stringify({type:`cancel`}))}a(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),C.current=``,w.current=[],E.current=null,T.current=!0,d(!0),p(`connecting`),y(null),A(JSON.stringify({type:`message`,content:e}))}},[A]),N=(0,U.useCallback)((e,t,n)=>{if(A(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=w.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)}a(e=>[...e])}y(null)},[A]),P=(0,U.useCallback)(()=>{if(!T.current)return;A(JSON.stringify({type:`cancel`}));let e=C.current,t=[...w.current];a(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}),C.current=``,w.current=[],E.current=null,T.current=!1,d(!1),y(null)},[A]),F=(0,U.useCallback)(()=>{x(!1),j(),O.current?.()},[j]),I=(0,U.useCallback)(()=>{!e||!n||(s(!0),fetch(`${l(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${u()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(a(e.data),C.current=``,w.current=[])}).catch(()=>{}).finally(()=>s(!1)))},[e,t,n]);return O.current=I,{messages:i,messagesLoading:o,isStreaming:c,streamingStatus:f,connectingElapsed:m,thinkingWarningThreshold:g,pendingApproval:v,sendMessage:M,respondToApproval:N,cancelStreaming:P,reconnect:F,refetchMessages:I,isConnected:b}}var W=3e4;function se(e,t=`claude-sdk`){let[n,r]=(0,U.useState)({}),[i,a]=(0,U.useState)(!1),[o,s]=(0,U.useState)(null),c=(0,U.useRef)(null),d=(0,U.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${l(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${u()}`}}).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,U.useEffect)(()=>(d(),c.current=setInterval(()=>d(),W),()=>{c.current&&clearInterval(c.current)}),[d]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,U.useCallback)(()=>d(!0),[d]),mergeUsage:(0,U.useCallback)(e=>{r(t=>{let n={...t,...e};return e.totalCostUsd!=null&&(n.queryCostUsd=e.totalCostUsd,n.totalCostUsd=(t.totalCostUsd??0)+e.totalCostUsd),n})},[])}}var ce={damping:.7,stiffness:.05,mass:1.25},le=70,ue=1e3/60,de=350,G=!1;globalThis.document?.addEventListener(`mousedown`,()=>{G=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{G=!1}),globalThis.document?.addEventListener(`click`,()=>{G=!1});var K=(e={})=>{let[t,n]=(0,U.useState)(!1),[r,i]=(0,U.useState)(e.initial!==!1),[a,o]=(0,U.useState)(!1),s=(0,U.useRef)(null);s.current=e;let c=(0,U.useCallback)(()=>{if(!G)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,U.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,U.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,U.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<=le}}},[]),f=(0,U.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Y(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))/ue;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:Y(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,U.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,U.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,U.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=q(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=q(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=Y(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:de})}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 q(e,t){let n=(0,U.useCallback)(t=>(n.current=t,e(t)),t);return n}var J=new Map;function Y(...e){let t={...ce},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 J.has(r)||J.set(r,Object.freeze(t)),n?`instant`:J.get(r)}var fe=(0,U.createContext)(null),pe=typeof window<`u`?U.useLayoutEffect:U.useEffect;function X({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,U.useRef)(null),d=K({mass:i,damping:a,stiffness:o,resize:n,initial:r,targetScrollTop:U.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,U.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,U.useImperativeHandle)(c,()=>y,[y]),pe(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),U.createElement(fe.Provider,{value:y},U.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=me();return U.createElement(`div`,{ref:r.scrollRef,style:{height:`100%`,width:`100%`,scrollbarGutter:`stable both-edges`},className:t},U.createElement(`div`,{...n,ref:r.contentRef},typeof e==`function`?e(r):e))}e.Content=t})(X||={});function me(){let e=(0,U.useContext)(fe);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var Z=r();function he(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 ge({tool:e,result:t,completed:n,projectName:r}){let[i,a]=(0,U.useState)(!1);if(e.type===`error`)return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded bg-red-500/10 border border-red-500/20 px-2 py-1.5 text-xs text-red-400`,children:[(0,Z.jsx)(g,{className:`size-3`}),(0,Z.jsx)(`span`,{children:e.message})]});let{toolName:o,input:s}=he(e),c=t?.type===`tool_result`,l=c&&!!t.isError,u=o===`AskUserQuestion`&&!!s?.answers,d=(o===`Agent`||o===`Task`)&&e.type===`tool_use`,f=d?e.children:void 0,p=f&&f.length>0;return(0,Z.jsxs)(`div`,{className:`rounded border text-xs ${d?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,Z.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors min-w-0`,children:[i?(0,Z.jsx)(m,{className:`size-3 shrink-0`}):(0,Z.jsx)(v,{className:`size-3 shrink-0`}),l?(0,Z.jsx)(M,{className:`size-3 text-red-400 shrink-0`}):c||u||n?(0,Z.jsx)(h,{className:`size-3 text-green-400 shrink-0`}):(0,Z.jsx)(E,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,Z.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,Z.jsx)(_e,{name:o,input:s})}),p&&(0,Z.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[f.length,` steps`]})]}),i&&(0,Z.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,Z.jsx)(ve,{name:o,input:s,projectName:r}),p&&(0,Z.jsx)(Se,{events:f,projectName:r}),c&&(0,Z.jsx)(be,{toolName:o,output:t.output})]})]})}function _e({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,Z.jsxs)(Z.Fragment,{children:[e,` `,(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:we(n(t.file_path))})]});case`Bash`:return(0,Z.jsxs)(Z.Fragment,{children:[e,` `,(0,Z.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Q(n(t.command),60)})]});case`Glob`:return(0,Z.jsxs)(Z.Fragment,{children:[e,` `,(0,Z.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,Z.jsxs)(Z.Fragment,{children:[e,` `,(0,Z.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Q(n(t.pattern),40)})]});case`WebSearch`:return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(D,{className:`size-3 inline`}),` `,e,` `,(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:Q(n(t.query),50)})]});case`WebFetch`:return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(F,{className:`size-3 inline`}),` `,e,` `,(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:Q(n(t.url),50)})]});case`ToolSearch`:return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(D,{className:`size-3 inline`}),` `,e,` `,(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:Q(n(t.query),50)})]});case`Agent`:case`Task`:return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(j,{className:`size-3 inline`}),` `,e,` `,(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:Q(n(t.description||t.prompt),60)})]});case`TodoWrite`:{let n=t.todos??[],r=n.filter(e=>e.status===`completed`).length;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(R,{className:`size-3 inline`}),` `,e,` `,(0,Z.jsxs)(`span`,{className:`text-text-subtle`,children:[r,`/`,n.length,` done`]})]})}case`AskUserQuestion`:{let n=t.questions??[],r=!!t.answers;return(0,Z.jsxs)(Z.Fragment,{children:[e,` `,(0,Z.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,Z.jsx)(Z.Fragment,{children:e})}}function ve({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:o}=a(),s=e=>{n&&o({type:`editor`,title:e.split(`/`).pop()??e,metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},c=(e,t,r)=>{o({type:`git-diff`,title:`Diff ${e.split(`/`).pop()??e}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,Z.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,Z.jsx)(`pre`,{className:`font-mono text-text-secondary overflow-x-auto whitespace-pre-wrap break-all`,children:r(t.command)})]});case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:{let n=r(t.file_path);return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`font-mono text-text-secondary break-all hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>s(n),title:`Open file in editor`,children:[(0,Z.jsx)(i,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,Z.jsxs)(`button`,{type:`button`,className:`text-text-subtle hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>c(n,r(t.old_string),r(t.new_string)),title:`View diff in new tab`,children:[(0,Z.jsx)(P,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,Z.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:Q(r(t.content),300)})]})}case`Glob`:return(0,Z.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,Z.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,Z.jsx)(ye,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,Z.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,Z.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,Z.jsx)(Ce,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,Z.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsxs)(`a`,{href:r(t.url),target:`_blank`,rel:`noopener noreferrer`,className:`font-mono text-primary hover:underline break-all flex items-center gap-1`,children:[(0,Z.jsx)(F,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,Z.jsx)(`p`,{className:`text-text-subtle`,children:Q(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,Z.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,Z.jsx)(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-xs border ${(n[e.question]??``).split(`, `).includes(t.label)?`border-accent bg-accent/20 text-text-primary`:`border-border text-text-subtle`}`,children:t.label},r))}),n[e.question]&&(0,Z.jsxs)(`p`,{className:`text-accent text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,Z.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function ye({todos:e}){return(0,Z.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 mt-0.5 ${e.status===`completed`?`text-green-400`:e.status===`in_progress`?`text-yellow-400`:`text-text-subtle`}`,children:e.status===`completed`?`✓`:e.status===`in_progress`?`▶`:`○`}),(0,Z.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function be({toolName:e,output:t}){let[n,r]=(0,U.useState)(!1),i=(0,U.useMemo)(()=>{if(e!==`Agent`&&e!==`Task`)return null;try{let e=JSON.parse(t);if(Array.isArray(e)){let t=e.filter(e=>e.type===`text`&&e.text).map(e=>e.text).join(`
3
-
4
- `);if(t)return t}if(typeof e==`string`)return e}catch{if(t&&!t.startsWith(`[{`))return t}return null},[e,t]);return i?(0,Z.jsxs)(`div`,{className:`border-t border-border pt-1.5 space-y-1`,children:[(0,Z.jsx)(Ce,{content:i,maxHeight:`max-h-60`}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>r(!n),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors`,children:[(0,Z.jsx)(N,{className:`size-3`}),n?`Hide`:`Show`,` raw`]}),n&&(0,Z.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono max-h-40 whitespace-pre-wrap break-all text-[10px]`,children:t})]}):(0,Z.jsx)(xe,{output:t})}function xe({output:e}){let t=e.split(`
5
- `).length,n=t>3||e.length>200,[r,i]=(0,U.useState)(n);return(0,Z.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[n&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>i(!r),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors mb-1`,children:[r?(0,Z.jsx)(v,{className:`size-3`}):(0,Z.jsx)(m,{className:`size-3`}),`Output (`,t,` lines)`]}),(0,Z.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono whitespace-pre-wrap break-all ${r?`max-h-16 overflow-hidden`:`max-h-60`}`,children:e})]})}function Se({events:e,projectName:t}){let n=[],r=``;for(let t of e)if(t.type===`text`)r+=t.content;else if(t.type===`tool_use`)r&&=(n.push({kind:`text`,content:r}),``),n.push({kind:`tool`,tool:t});else if(t.type===`tool_result`){let e=t.toolUseId,r=e?n.find(t=>t.kind===`tool`&&t.tool.type===`tool_use`&&t.tool.toolUseId===e&&!t.result):n.findLast(e=>e.kind===`tool`&&!e.result);r&&(r.result=t)}return r&&n.push({kind:`text`,content:r}),(0,Z.jsx)(`div`,{className:`border-l-2 border-accent/20 pl-2 space-y-1 mt-1`,children:n.map((e,n)=>e.kind===`text`?(0,Z.jsx)(`div`,{className:`text-text-secondary text-[11px]`,children:(0,Z.jsx)(Ce,{content:e.content,maxHeight:`max-h-24`})},`st-${n}`):(0,Z.jsx)(ge,{tool:e.tool,result:e.result,completed:!!e.result,projectName:t},`sc-${n}`))})}function Ce({content:e,maxHeight:t=`max-h-48`}){return(0,Z.jsx)(O,{content:e,className:`text-text-secondary overflow-auto ${t}`})}function we(e){return e?e.split(`/`).pop()??e:``}function Q(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}function Te({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,streamingStatus:a,connectingElapsed:o,thinkingWarningThreshold:s,projectName:c,onFork:l}){return t?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,Z.jsx)(j,{className:`size-10 text-text-subtle animate-pulse`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!i?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,Z.jsx)(j,{className:`size-10 text-text-subtle`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:`Send a message to start the conversation`})]}):(0,Z.jsxs)(X,{className:`flex-1 overflow-y-auto`,resize:`smooth`,initial:`instant`,children:[(0,Z.jsxs)(X.Content,{className:`p-4 space-y-4`,children:[e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return t||n}).map(e=>(0,Z.jsx)(De,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:c,onFork:e.role===`user`&&l?()=>l(e.content):void 0},e.id)),n&&(n.tool===`AskUserQuestion`?(0,Z.jsx)(He,{approval:n,onRespond:r}):(0,Z.jsx)(Ve,{approval:n,onRespond:r})),i&&(0,Z.jsx)(ze,{lastMessage:e[e.length-1],streamingStatus:a,elapsed:o,warningThreshold:s})]}),(0,Z.jsx)(Ee,{})]})}function Ee(){let{isAtBottom:e,scrollToBottom:t}=me();return e?null:(0,Z.jsxs)(`button`,{onClick:()=>t(),className:`absolute bottom-2 left-1/2 -translate-x-1/2 flex items-center gap-1 px-3 py-1 rounded-full bg-surface-elevated border border-border text-xs text-text-secondary hover:text-foreground shadow-lg transition-all`,children:[(0,Z.jsx)(m,{className:`size-3`}),`Scroll to bottom`]})}function De({message:e,isStreaming:t,projectName:n,onFork:r}){return e.role===`user`?(0,Z.jsx)(Ne,{content:e.content,projectName:n,onFork:r}):e.role===`system`?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-red-500/10 border border-red-500/20 px-3 py-2 text-sm text-red-400`,children:[(0,Z.jsx)(g,{className:`size-4 shrink-0`}),(0,Z.jsx)(`p`,{children:e.content})]}):(0,Z.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.events&&e.events.length>0?(0,Z.jsx)(Ie,{events:e.events,isStreaming:t,projectName:n}):e.content&&(0,Z.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,Z.jsx)(Be,{content:e.content,projectName:n})})})}var Oe=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]);function ke(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 Ae(e,t){let n=e.split(`/`).pop()??``;return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function je(e){let t=e.lastIndexOf(`.`);return t===-1?!1:Oe.has(e.slice(t).toLowerCase())}function Me(e){return e.toLowerCase().endsWith(`.pdf`)}function Ne({content:e,projectName:t,onFork:n}){let{files:r,text:i}=(0,U.useMemo)(()=>ke(e),[e]);return(0,Z.jsx)(`div`,{className:`flex justify-end group/user`,children:(0,Z.jsxs)(`div`,{className:`rounded-lg bg-primary/10 px-3 py-2 text-sm text-text-primary max-w-[85%] space-y-2 relative`,children:[r.length>0&&(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:r.map((e,n)=>je(e)?(0,Z.jsx)(Pe,{src:Ae(e,t),alt:e.split(`/`).pop()??`image`},n):Me(e)?(0,Z.jsx)(Fe,{src:Ae(e,t),filename:e.split(`/`).pop()??`document.pdf`,mimeType:`application/pdf`},n):(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,Z.jsx)(S,{className:`size-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate max-w-40`,children:e.split(`/`).pop()})]},n))}),i&&(0,Z.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:i}),n&&(0,Z.jsx)(`button`,{onClick:n,title:`Retry from this message (fork session)`,className:`absolute -left-8 top-1/2 -translate-y-1/2 opacity-0 group-hover/user:opacity-100 transition-opacity size-6 flex items-center justify-center rounded bg-surface border border-border text-text-subtle hover:text-text-primary hover:bg-surface-elevated`,children:(0,Z.jsx)(o,{className:`size-3`})})]})})}function Pe({src:e,alt:t}){let[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(!1);return(0,U.useEffect)(()=>{let t,n=u();return fetch(e,{headers:n?{Authorization:`Bearer ${n}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed to load`);return e.blob()}).then(e=>{let n=URL.createObjectURL(e);t=n,r(n)}).catch(()=>a(!0)),()=>{t&&URL.revokeObjectURL(t)}},[e]),i?(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,Z.jsx)(L,{className:`size-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate max-w-40`,children:t})]}):n?(0,Z.jsx)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`block`,children:(0,Z.jsx)(`img`,{src:n,alt:t,className:`rounded-md max-h-48 max-w-full object-contain border border-border`})}):(0,Z.jsx)(`div`,{className:`rounded-md bg-surface border border-border h-24 w-32 animate-pulse`})}function Fe({src:e,filename:t,mimeType:n}){let[r,i]=(0,U.useState)(!1);return(0,Z.jsxs)(`button`,{type:`button`,onClick:(0,U.useCallback)(async()=>{i(!0);try{let t=u(),r=await fetch(e,{headers:t?{Authorization:`Bearer ${t}`}:{}});if(!r.ok)throw Error(`Failed to load`);let i=await r.blob(),a=URL.createObjectURL(new Blob([i],{type:n}));window.open(a,`_blank`),setTimeout(()=>URL.revokeObjectURL(a),6e4)}catch{window.open(e,`_blank`)}finally{i(!1)}},[e,n]),disabled:r,className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary hover:bg-surface hover:text-text-primary transition-colors cursor-pointer disabled:opacity-50`,children:[(0,Z.jsx)(S,{className:`size-3.5 shrink-0 text-red-400`}),(0,Z.jsx)(`span`,{className:`truncate max-w-40`,children:t}),r&&(0,Z.jsx)(`span`,{className:`animate-spin text-[10px]`,children:`...`})]})}function Ie({events:e,isStreaming:t,projectName:n}){let r=[],i=``,a=``;for(let t=0;t<e.length;t++){let n=e[t];if(n.type===`thinking`){i&&=(r.push({kind:`text`,content:i}),``),a+=n.content;continue}a&&=(r.push({kind:`thinking`,content:a}),``),n.type===`text`?i+=n.content:n.type===`tool_use`?(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n})):n.type===`tool_result`||(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n}))}a&&r.push({kind:`thinking`,content:a}),i&&r.push({kind:`text`,content:i});let o=e.filter(e=>e.type===`tool_result`);for(let e of o){let t=e.toolUseId;if(t){let n=r.find(e=>e.kind===`tool`&&e.tool.type===`tool_use`&&e.tool.toolUseId===t);if(n){n.result=e;continue}}let n=r.find(e=>e.kind===`tool`&&!e.result);n&&(n.result=e)}for(let e=0;e<r.length;e++){let n=r[e];if(n.kind===`tool`&&!n.result){let i=!1;if(n.tool.type===`tool_use`&&n.tool.tool===`Read`){let t=n.tool.input?.file_path;t&&(i=r.slice(e+1).some(e=>e.kind===`tool`&&e.result&&e.tool.type===`tool_use`&&e.tool.tool===`Edit`&&e.tool.input?.file_path===t))}n.completed=i||!t}}return(0,Z.jsx)(Z.Fragment,{children:r.map((e,i)=>{if(e.kind===`thinking`)return(0,Z.jsx)(Le,{content:e.content,isStreaming:t&&i===r.length-1},`think-${i}`);if(e.kind===`text`){let a=t&&i===r.length-1;return(0,Z.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,Z.jsx)(Re,{content:e.content,animate:a,projectName:n})},`text-${i}`)}return(0,Z.jsx)(ge,{tool:e.tool,result:e.result,completed:e.completed,projectName:n},`tool-${i}`)})})}function Le({content:e,isStreaming:t}){let[n,r]=(0,U.useState)(t);return(0,U.useEffect)(()=>{!t&&e.length>0&&r(!1)},[t,e.length]),(0,Z.jsxs)(`div`,{className:`rounded border border-border/50 bg-surface/30 text-xs`,children:[(0,Z.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors text-text-subtle`,children:[t?(0,Z.jsx)(E,{className:`size-3 animate-spin`}):(0,Z.jsx)(v,{className:`size-3 transition-transform ${n?`rotate-90`:``}`}),(0,Z.jsxs)(`span`,{children:[`Thinking`,t?`...`:``]}),!t&&(0,Z.jsx)(`span`,{className:`text-text-subtle/50 ml-auto`,children:e.length>100?`${Math.round(e.length/4)} tokens`:``})]}),n&&(0,Z.jsx)(`div`,{className:`px-2 pb-2 text-text-subtle/80 whitespace-pre-wrap max-h-60 overflow-y-auto text-[11px] leading-relaxed`,children:e})]})}function Re({content:e,animate:t,projectName:n}){return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Be,{content:e,projectName:n}),t&&(0,Z.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function ze({lastMessage:e,streamingStatus:t,elapsed:n,warningThreshold:r=15}){let i=!e||e.role!==`assistant`,a=e?.events?.length?e.events[e.events.length-1].type===`tool_result`:!1;return!i&&!a?null:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-text-subtle`,children:[(0,Z.jsx)(E,{className:`size-3 animate-spin`}),(0,Z.jsxs)(`span`,{children:[`Thinking`,i&&(n??0)>0&&(0,Z.jsxs)(`span`,{className:`text-text-subtle/60`,children:[`... (`,n,`s)`]})]})]}),i&&(n??0)>=r&&(0,Z.jsx)(`p`,{className:`text-xs text-yellow-500/80 ml-5`,children:`Taking longer than usual — may be rate-limited or API slow. Try sending a new message to retry.`})]})}function Be({content:e,projectName:t}){return(0,Z.jsx)(O,{content:e,projectName:t,codeActions:!0})}function Ve({approval:e,onRespond:t}){return(0,Z.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,Z.jsx)(V,{className:`size-4`}),(0,Z.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,Z.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,Z.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,Z.jsx)(`pre`,{className:`text-xs font-mono text-text-secondary overflow-x-auto bg-background rounded p-2 border border-border`,children:JSON.stringify(e.input,null,2)}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(`button`,{onClick:()=>t(e.requestId,!0),className:`px-4 py-1.5 rounded bg-green-600 text-white text-xs font-medium hover:bg-green-500 transition-colors`,children:`Allow`}),(0,Z.jsx)(`button`,{onClick:()=>t(e.requestId,!1),className:`px-4 py-1.5 rounded bg-red-600 text-white text-xs font-medium hover:bg-red-500 transition-colors`,children:`Deny`})]})]})}function He({approval:e,onRespond:t}){let n=e.input.questions??[],[r,i]=(0,U.useState)({}),[a,o]=(0,U.useState)({}),s=(e,t,n)=>{o(t=>({...t,[e]:!1})),i(r=>{if(!n)return{...r,[e]:t};let i=r[e]??``,a=i?i.split(`, `):[],o=a.indexOf(t);return o>=0?a.splice(o,1):a.push(t),{...r,[e]:a.join(`, `)}})},c=e=>{o(t=>({...t,[e]:!0})),i(t=>({...t,[e]:``}))},l=(e,t)=>{i(n=>({...n,[e]:t}))},u=n.every(e=>r[e.question]?.trim());return(0,Z.jsxs)(`div`,{className:`rounded-lg border-2 border-accent/40 bg-accent/5 p-3 space-y-3`,children:[n.map((e,t)=>(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`p`,{className:`text-sm text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),e.multiSelect&&(0,Z.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`Select multiple`}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e.options.map((t,n)=>(0,Z.jsxs)(`button`,{onClick:()=>s(e.question,t.label,e.multiSelect),className:`text-left rounded px-2.5 py-1.5 text-xs border transition-colors ${!a[e.question]&&(r[e.question]??``).split(`, `).includes(t.label)?`border-accent bg-accent/20 text-text-primary`:`border-border bg-background text-text-secondary hover:bg-surface-elevated`}`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:t.label}),t.description&&(0,Z.jsxs)(`span`,{className:`text-text-subtle ml-1.5`,children:[`— `,t.description]})]},n)),a[e.question]?(0,Z.jsx)(`input`,{type:`text`,autoFocus:!0,placeholder:`Type your answer...`,value:r[e.question]??``,onChange:t=>l(e.question,t.target.value),className:`rounded px-2.5 py-1.5 text-xs border border-accent bg-accent/10 text-text-primary outline-none placeholder:text-text-subtle`}):(0,Z.jsx)(`button`,{onClick:()=>c(e.question),className:`text-left rounded px-2.5 py-1.5 text-xs border border-dashed border-border text-text-subtle hover:bg-surface-elevated transition-colors`,children:`Other — type your own answer`})]})]},t)),(0,Z.jsxs)(`div`,{className:`flex gap-2 pt-1`,children:[(0,Z.jsx)(`button`,{onClick:()=>t(e.requestId,!0,r),disabled:!u,className:`px-4 py-1.5 rounded bg-accent text-white text-xs font-medium hover:bg-accent/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:`Submit`}),(0,Z.jsx)(`button`,{onClick:()=>t(e.requestId,!1),className:`px-4 py-1.5 rounded bg-surface-elevated text-text-secondary text-xs hover:bg-surface transition-colors`,children:`Skip`})]})]})}var Ue=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),We=new Set([`application/pdf`]),Ge=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],Ke=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 qe(e){return Ue.has(e.type)}function Je(e){if(Ue.has(e.type)||We.has(e.type)||Ge.some(t=>e.type.startsWith(t)))return!0;let t=Ye(e.name);return!!(t&&Ke.has(t))}function Ye(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function Xe({attachments:e,onRemove:t}){return e.length===0?null:(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-3 pt-2`,children:e.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-surface px-2 py-1 text-xs text-text-secondary max-w-48`,children:[e.previewUrl?(0,Z.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,Z.jsx)(L,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,Z.jsx)(S,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,Z.jsx)(E,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,Z.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,Z.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`shrink-0 rounded-sm p-0.5 hover:bg-border/50 transition-colors`,"aria-label":`Remove ${e.name}`,children:(0,Z.jsx)(T,{className:`size-3`})})]},e.id))})}function Ze(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&n(r.children)}return n(e),t}function Qe({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,U.useState)(0),s=(0,U.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,U.useEffect)(()=>{o(0)},[t]),(0,U.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,U.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,U.useEffect)(()=>{if(!i)return;let e=e=>{l(e)};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,Z.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,Z.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,Z.jsxs)(`button`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,Z.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,Z.jsx)(p,{className:`size-4 text-amber-500`}):(0,Z.jsx)(_,{className:`size-4 text-blue-400`})}),(0,Z.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}function $e({onSend:e,isStreaming:t,onCancel:n,disabled:r,projectName:i,onSlashStateChange:a,onSlashItemsLoaded:o,slashSelected:s,onFileStateChange:f,onFileItemsLoaded:p,fileSelected:m,externalFiles:h,initialValue:g}){let[_,v]=(0,U.useState)(g??``),[y,b]=(0,U.useState)([]),x=(0,U.useRef)(null),S=(0,U.useRef)(null),C=(0,U.useRef)([]),w=(0,U.useRef)([]);(0,U.useEffect)(()=>{g&&(v(g),setTimeout(()=>{let e=x.current;e&&(e.focus(),e.selectionStart=e.selectionEnd=e.value.length)},50))},[g]),(0,U.useEffect)(()=>{if(!i){C.current=[],o?.([]);return}d.get(`${l(i)}/chat/slash-items`).then(e=>{C.current=e,o?.(e)}).catch(()=>{C.current=[],o?.([])})},[i]),(0,U.useEffect)(()=>{if(!i){w.current=[],p?.([]);return}d.get(`${l(i)}/files/tree?depth=5`).then(e=>{let t=Ze(e);w.current=t,p?.(t)}).catch(()=>{w.current=[],p?.([])})},[i]),(0,U.useEffect)(()=>{if(!s)return;let e=x.current,t=e?.selectionStart??_.length,n=_.slice(0,t),r=_.slice(t),i=n.replace(/(?:^|\s)\/\S*$/,e=>`${e.startsWith(`/`)?``:e[0]}/${s.name} `);v(i+r),a?.(!1,``),f?.(!1,``),e&&(e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=i.length},0))},[s]),(0,U.useEffect)(()=>{if(!m)return;let e=x.current;if(!e)return;let t=e.selectionStart,n=_.slice(0,t),r=_.slice(t),i=n.match(/@(\S*)$/);if(i){let t=n.length-i[0].length;v(n.slice(0,t)+`@${m.path} `+r);let a=t+m.path.length+2;setTimeout(()=>{e.selectionStart=e.selectionEnd=a,e.focus()},0)}else{let t=_+`@${m.path} `;v(t),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length,e.focus()},0)}f?.(!1,``)},[m]),(0,U.useEffect)(()=>{!h||h.length===0||E(h)},[h]);let T=(0,U.useCallback)(async e=>{if(!i)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=u();r&&(n.Authorization=`Bearer ${r}`);let a=await(await fetch(`${l(i)}/chat/upload`,{method:`POST`,headers:n,body:t})).json();return a.ok&&Array.isArray(a.data)&&a.data.length>0?a.data[0].path:null}catch{return null}},[i]),E=(0,U.useCallback)(e=>{for(let t of e){if(!Je(t)){v(e=>e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=c(),n=qe(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};b(e=>[...e,i]),T(t).then(t=>{b(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}x.current?.focus()},[T]),D=(0,U.useCallback)(e=>{b(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),O=(0,U.useCallback)(()=>{let t=_.trim(),n=y.filter(e=>e.status===`ready`);if(!(!t&&n.length===0)&&!r){a?.(!1,``),f?.(!1,``),e(t,n),v(``);for(let e of y)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);b([]),x.current&&(x.current.style.height=`auto`)}},[_,y,r,e,a,f]),k=(0,U.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),O())},[O]),j=(0,U.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.match(/(?:^|\s)\/(\S*)$/);if(r&&C.current.length>0){a?.(!0,r[1]??``),f?.(!1,``);return}let i=n.match(/@(\S*)$/);if(i&&w.current.length>0){f?.(!0,i[1]??``),a?.(!1,``);return}a?.(!1,``),f?.(!1,``)},[a,f]),M=(0,U.useCallback)(e=>{v(e),setTimeout(()=>{j(e,x.current?.selectionStart??e.length)},0)},[j]),N=(0,U.useCallback)(()=>{let e=x.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,160)+`px`)},[]),P=(0,U.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(),E(n))},[E]),F=(0,U.useCallback)(e=>{e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length>0&&E(t)},[E]),I=(0,U.useCallback)(e=>{e.preventDefault()},[]),L=(0,U.useCallback)(()=>{S.current?.click()},[]),R=(0,U.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&E(t),e.target.value=``},[E]),B=_.trim().length>0||y.some(e=>e.status===`ready`),V=t&&!B;return(0,Z.jsxs)(`div`,{className:`p-2 md:p-3 bg-background`,children:[(0,Z.jsx)(Xe,{attachments:y,onRemove:D}),(0,Z.jsxs)(`div`,{className:`border border-border rounded-xl md:rounded-2xl bg-surface shadow-sm cursor-text`,onClick:()=>!r&&x.current?.focus(),children:[(0,Z.jsxs)(`div`,{className:`flex items-end gap-1 md:hidden px-2 py-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),L()},disabled:r,className:`flex items-center justify-center size-7 shrink-0 rounded-full text-text-subtle hover:text-text-primary transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,Z.jsx)(z,{className:`size-4`})}),(0,Z.jsx)(`textarea`,{ref:x,value:_,onChange:e=>{M(e.target.value),N()},onKeyDown:k,onPaste:P,onDrop:F,onDragOver:I,placeholder:t?`Follow-up...`:`Ask anything...`,disabled:r,rows:1,className:`flex-1 resize-none bg-transparent py-1.5 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-32`}),V?(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop`,children:(0,Z.jsx)(H,{className:`size-3`})}):(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),O()},disabled:r||!B,className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 transition-colors`,"aria-label":`Send`,children:(0,Z.jsx)(A,{className:`size-3.5`})})]}),(0,Z.jsxs)(`div`,{className:`hidden md:block`,children:[(0,Z.jsx)(`textarea`,{ref:x,value:_,onChange:e=>{M(e.target.value),N()},onKeyDown:k,onPaste:P,onDrop:F,onDragOver:I,placeholder:t?`Follow-up or Stop...`:`Ask anything...`,disabled:r,rows:1,className:`w-full resize-none bg-transparent px-4 pt-3 pb-1 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-40`}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),L()},disabled:r,className:`flex items-center justify-center size-8 rounded-full text-text-subtle hover:text-text-primary hover:bg-surface-elevated transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,Z.jsx)(z,{className:`size-4`})})}),(0,Z.jsx)(`div`,{className:`flex items-center gap-1`,children:V?(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-8 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop response`,children:(0,Z.jsx)(H,{className:`size-3.5`})}):(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),O()},disabled:r||!B,className:`flex items-center justify-center size-8 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":`Send message`,children:(0,Z.jsx)(A,{className:`size-4`})})})]})]})]}),(0,Z.jsx)(`input`,{ref:S,type:`file`,multiple:!0,className:`hidden`,onChange:R})]})}function et({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,U.useState)(0),s=(0,U.useRef)(null),c=e.filter(e=>{let n=t.toLowerCase();return e.name.toLowerCase().includes(n)||e.description.toLowerCase().includes(n)});(0,U.useEffect)(()=>{o(0)},[t]),(0,U.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,U.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,U.useEffect)(()=>{if(!i)return;let e=e=>{l(e)};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,Z.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,Z.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,Z.jsxs)(`button`,{className:`flex items-start gap-3 w-full px-3 py-2 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,Z.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`skill`?(0,Z.jsx)(ee,{className:`size-4 text-amber-500`}):(0,Z.jsx)(b,{className:`size-4 text-blue-500`})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Z.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,Z.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,Z.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`user`?`global`:e.type})]}),e.description&&(0,Z.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]},`${e.type}-${e.name}`))})})}function tt(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function nt(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function rt(e){if(!e)return null;let t=null;if(e.resetsInMinutes!=null)t=e.resetsInMinutes;else if(e.resetsInHours!=null)t=Math.round(e.resetsInHours*60);else if(e.resetsAt){let n=new Date(e.resetsAt).getTime()-Date.now();t=n>0?Math.ceil(n/6e4):0}if(t==null)return null;if(t<=0)return`now`;let n=Math.floor(t/1440),r=Math.floor(t%1440/60),i=t%60;return n>0?i>0?`${n}d ${r}h ${i}m`:r>0?`${n}d ${r}h`:`${n}d`:r>0?i>0?`${r}h ${i}m`:`${r}h`:`${i}m`}function $({label:e,bucket:t}){if(!t)return null;let n=Math.round(t.utilization*100),r=rt(t);return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,Z.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,children:[`↻ `,r]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full transition-all ${nt(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,Z.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${tt(n)}`,children:[n,`%`]})]})]})}function it(e){if(!e)return null;let t=Math.round((Date.now()-e)/1e3);return t<5?`just now`:t<60?`${t}s ago`:`${Math.floor(t/60)}m ago`}function at({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastFetchedAt:a}){if(!t)return null;let o=e.queryCostUsd!=null||e.totalCostUsd!=null,s=e.session||e.weekly||e.weeklyOpus||e.weeklySonnet;return(0,Z.jsxs)(`div`,{className:`border-b border-border bg-surface px-3 py-2.5 space-y-2.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage Limits`}),a&&(0,Z.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:it(new Date(a).getTime())})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r&&(0,Z.jsx)(`button`,{onClick:r,disabled:i,className:`text-xs text-text-subtle hover:text-text-primary px-1 disabled:opacity-50`,title:`Refresh usage data`,children:(0,Z.jsx)(y,{className:`size-3 ${i?`animate-spin`:``}`})}),(0,Z.jsx)(`button`,{onClick:n,className:`text-xs text-text-subtle hover:text-text-primary px-1`,children:`✕`})]})]}),s?(0,Z.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,Z.jsx)($,{label:`5-Hour Session`,bucket:e.session}),(0,Z.jsx)($,{label:`Weekly`,bucket:e.weekly}),(0,Z.jsx)($,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,Z.jsx)($,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,Z.jsxs)(`p`,{className:`text-xs text-text-subtle`,children:[`No data — run `,(0,Z.jsx)(`code`,{className:`bg-surface-elevated px-1 rounded`,children:`bun install`})]}),o&&(0,Z.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,Z.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,Z.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]})]})}function ot(e){try{return new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}catch{return``}}function st(e){let t=Math.round((Date.now()-new Date(e).getTime())/1e3);if(t<5)return`now`;if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m`:`${Math.floor(n/60)}h`}function ct(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function lt({projectName:e,usageInfo:t,usageLoading:n,refreshUsage:r,lastFetchedAt:i,sessionId:o,onSelectSession:s,onBugReport:c,isConnected:u,onReconnect:p}){let[m,h]=(0,U.useState)(null),[g,_]=(0,U.useState)([]),[v,b]=(0,U.useState)(!1),[x,S]=(0,U.useState)(``),w=a(e=>e.openTab),T=e=>{h(t=>t===e?null:e)},O=(0,U.useCallback)(async()=>{if(e){b(!0);try{_(await d.get(`${l(e)}/chat/sessions`))}catch{}finally{b(!1)}}},[e]);(0,U.useEffect)(()=>{m===`history`&&g.length===0&&O()},[m]);function A(t){s?(s(t),h(null)):w({type:`chat`,title:t.title||`Chat`,projectId:e??null,metadata:{projectName:e,sessionId:t.id},closable:!0})}let j=x.trim()?g.filter(e=>(e.title||``).toLowerCase().includes(x.toLowerCase())):g,M=t.fiveHour==null?null:Math.round(t.fiveHour*100),N=t.sevenDay==null?null:Math.round(t.sevenDay*100),P=M!=null||N!=null?ct(Math.max(M??0,N??0)):`text-text-subtle`;return(0,Z.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,Z.jsxs)(`button`,{onClick:()=>T(`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,Z.jsx)(I,{className:`size-3`}),(0,Z.jsx)(`span`,{children:`History`})]}),(0,Z.jsx)(`button`,{onClick:()=>T(`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,Z.jsx)(B,{className:`size-3`})}),(0,Z.jsxs)(`button`,{onClick:()=>T(`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`:``} ${P}`,title:`Usage limits`,children:[(0,Z.jsx)(k,{className:`size-3`}),(0,Z.jsxs)(`span`,{children:[`5h:`,M==null?`--%`:`${M}%`]}),(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,Z.jsxs)(`span`,{children:[`Wk:`,N==null?`--%`:`${N}%`]}),i&&(0,Z.jsx)(`span`,{className:`text-text-subtle/50 font-normal text-[9px] ml-0.5`,children:st(i)})]}),(0,Z.jsx)(`div`,{className:`flex-1`}),p&&(0,Z.jsx)(`button`,{onClick:p,className:`size-4 flex items-center justify-center`,title:u?`Connected`:`Disconnected — click to reconnect`,children:(0,Z.jsx)(`span`,{className:`size-2 rounded-full ${u?`bg-green-500`:`bg-red-500 animate-pulse`}`})})]}),m===`history`&&(0,Z.jsxs)(`div`,{className:`border-t border-border/30 bg-surface`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 border-b border-border/30`,children:[(0,Z.jsx)(D,{className:`size-3 text-text-subtle shrink-0`}),(0,Z.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),placeholder:`Search sessions...`,className:`flex-1 bg-transparent text-[11px] text-text-primary outline-none placeholder:text-text-subtle`}),(0,Z.jsx)(`button`,{onClick:O,disabled:v,className:`p-0.5 rounded text-text-subtle hover:text-text-secondary transition-colors disabled:opacity-50`,title:`Refresh`,children:(0,Z.jsx)(y,{className:`size-3 ${v?`animate-spin`:``}`})})]}),(0,Z.jsx)(`div`,{className:`max-h-[200px] overflow-y-auto`,children:v&&g.length===0?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,Z.jsx)(E,{className:`size-3.5 animate-spin text-text-subtle`})}):j.length===0?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-3 text-[11px] text-text-subtle`,children:x?`No matching sessions`:`No sessions yet`}):j.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>A(e),className:`flex items-center gap-2 w-full px-3 py-1.5 text-left hover:bg-surface-elevated transition-colors`,children:[(0,Z.jsx)(f,{className:`size-3 shrink-0 text-text-subtle`}),(0,Z.jsx)(`span`,{className:`text-[11px] truncate flex-1`,children:e.title||`Untitled`}),e.updatedAt&&(0,Z.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:ot(e.updatedAt)})]},e.id))})]}),m===`config`&&(0,Z.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2 max-h-[280px] overflow-y-auto`,children:(0,Z.jsx)(C,{compact:!0})}),m===`usage`&&(0,Z.jsx)(at,{usage:t,visible:!0,onClose:()=>h(null),onReload:r,loading:n,lastFetchedAt:i})]})}function ut({metadata:e,tabId:t}){let[n,r]=(0,U.useState)(e?.sessionId??null),[i,o]=(0,U.useState)(e?.providerId??`claude`),[c,u]=(0,U.useState)([]),[f,p]=(0,U.useState)(!1),[m,h]=(0,U.useState)(``),[g,_]=(0,U.useState)(null),[v,y]=(0,U.useState)([]),[b,S]=(0,U.useState)(!1),[C,T]=(0,U.useState)(``),[E,D]=(0,U.useState)(null),[O,k]=(0,U.useState)(!1),[A,j]=(0,U.useState)(null),M=(0,U.useRef)(0),N=e?.projectName??``,P=a(e=>e.updateTab),F=s(e=>e.version),{usageInfo:I,usageLoading:L,lastFetchedAt:R,refreshUsage:z,mergeUsage:B}=se(N,i);(0,U.useEffect)(()=>{!t||!n||P(t,{metadata:{...e,sessionId:n,providerId:i}})},[n,i]);let{messages:V,messagesLoading:ee,isStreaming:H,streamingStatus:ne,connectingElapsed:re,thinkingWarningThreshold:ie,pendingApproval:ae,sendMessage:W,respondToApproval:ce,cancelStreaming:le,reconnect:ue,refetchMessages:de,isConnected:G}=oe(n,i,N,{onUsageEvent:B}),K=(0,U.useRef)(e?.pendingMessage);(0,U.useEffect)(()=>{if(K.current&&G&&n){let n=K.current;K.current=void 0,t&&P(t,{metadata:{...e,pendingMessage:void 0}}),setTimeout(()=>W(n),100)}},[G,n]),(0,U.useCallback)(()=>{a.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:N},projectId:N||null,closable:!0})},[N]);let q=(0,U.useCallback)(e=>{r(e.id),o(e.providerId)},[]),J=(0,U.useCallback)(async e=>{if(!(!n||!N))try{let{api:t,projectUrl:r}=await x(async()=>{let{api:e,projectUrl:t}=await import(`./api-client-ANLU-Irq.js`).then(e=>e.n);return{api:e,projectUrl:t}},__vite__mapDeps([0,1])),o=await t.post(`${r(N)}/chat/sessions/${n}/fork?providerId=${i}`);a.getState().openTab({type:`chat`,title:`Fork: ${e.slice(0,30)}`,metadata:{projectName:N,sessionId:o.id,providerId:i,pendingMessage:e},projectId:N||null,closable:!0})}catch(e){console.error(`Fork failed:`,e)}},[n,N,i]),Y=(0,U.useCallback)((e,t)=>{if(t.length===0)return e;let n=t.filter(e=>e.serverPath).map(e=>e.serverPath).join(`
7
- `);return n?(t.length===1?`[Attached file: ${n}]\n\n`:`[Attached files:\n${n}\n]\n\n`)+e:e},[]),fe=(0,U.useCallback)(async(e,t=[])=>{let a=Y(e,t);if(a.trim()){if(!n)try{let t=N,n=await d.post(`${l(t)}/chat/sessions`,{providerId:i,title:e.slice(0,50)});r(n.id),o(n.providerId),setTimeout(()=>{W(a)},500);return}catch(e){console.error(`Failed to create session:`,e);return}W(a)}},[n,i,N,W,Y]),pe=(0,U.useCallback)((e,t)=>{p(e),h(t)},[]),X=(0,U.useCallback)(e=>{_(e),p(!1),h(``),setTimeout(()=>_(null),50)},[]),me=(0,U.useCallback)(()=>{p(!1),h(``)},[]),he=(0,U.useCallback)((e,t)=>{S(e),T(t)},[]),ge=(0,U.useCallback)(e=>{D(e),S(!1),T(``),setTimeout(()=>D(null),50)},[]),_e=(0,U.useCallback)(()=>{S(!1),T(``)},[]);return(0,Z.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,U.useCallback)(e=>{e.preventDefault(),M.current++,e.dataTransfer.types.includes(`Files`)&&k(!0)},[]),onDragLeave:(0,U.useCallback)(e=>{e.preventDefault(),M.current--,M.current===0&&k(!1)},[]),onDragOver:(0,U.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,U.useCallback)(e=>{e.preventDefault(),M.current=0,k(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&(j(t),setTimeout(()=>j(null),100))},[]),children:[O&&(0,Z.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm border-2 border-dashed border-primary rounded-lg pointer-events-none`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-primary`,children:[(0,Z.jsx)(te,{className:`size-8`}),(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),(0,Z.jsx)(Te,{messages:V,messagesLoading:ee,pendingApproval:ae,onApprovalResponse:ce,isStreaming:H,streamingStatus:ne,connectingElapsed:re,thinkingWarningThreshold:ie,projectName:N,onFork:H?void 0:J}),(0,Z.jsxs)(`div`,{className:`border-t border-border bg-background shrink-0`,children:[(0,Z.jsx)(lt,{projectName:N,usageInfo:I,usageLoading:L,refreshUsage:z,lastFetchedAt:R,sessionId:n,onSelectSession:q,onBugReport:n?()=>w(F,{sessionId:n,projectName:N}):void 0,isConnected:G,onReconnect:()=>{G||ue(),de()}}),(0,Z.jsx)(et,{items:c,filter:m,onSelect:X,onClose:me,visible:f}),(0,Z.jsx)(Qe,{items:v,filter:C,onSelect:ge,onClose:_e,visible:b}),(0,Z.jsx)($e,{onSend:fe,isStreaming:H,onCancel:le,projectName:N,onSlashStateChange:pe,onSlashItemsLoaded:u,slashSelected:g,onFileStateChange:he,onFileItemsLoaded:y,fileSelected:E,externalFiles:A})]})]})}export{ut as ChatTab};
@@ -1 +0,0 @@
1
- import{n as e,o as t,r as n,t as r}from"./jsx-runtime-B4BJKQ1u.js";import{a as i,t as a}from"./tab-store-Dq1kMOkJ.js";import{n as o}from"./settings-store-CGtTcr8r.js";import{i as s,r as c,t as l}from"./api-client-ANLU-Irq.js";import{w as u}from"./index-D_IIxtVN.js";import{t as d}from"./markdown-renderer-B9l76G5h.js";import{n as f,t as p}from"./use-monaco-theme-CsNwoeyj.js";var m=e(`file-exclamation-point`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),h=t(n(),1),g=r(),_=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]);function v(e){return e.split(`.`).pop()?.toLowerCase()??``}function y(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`}[v(e)]??`plaintext`}function b({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,[i,c]=(0,h.useState)(null),[d,b]=(0,h.useState)(`utf-8`),[w,T]=(0,h.useState)(!0),[E,D]=(0,h.useState)(null),[O,k]=(0,h.useState)(!1),A=(0,h.useRef)(null),j=(0,h.useRef)(``),M=(0,h.useRef)(null),{tabs:N,updateTab:P}=a(),{wordWrap:F,toggleWordWrap:I}=o(),L=p(),R=N.find(e=>e.id===t),z=n?v(n):``,B=_.has(z),V=z===`pdf`,H=z===`md`||z===`mdx`,[U,W]=(0,h.useState)(`preview`),G=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,h.useEffect)(()=>{if(!n||!G&&!r)return;if(B||V){T(!1);return}T(!0),D(null);let e=G?`/api/fs/read?path=${encodeURIComponent(n)}`:`${s(r)}/files/read?path=${encodeURIComponent(n)}`;return l.get(e).then(e=>{c(e.content),e.encoding&&b(e.encoding),j.current=e.content,T(!1)}).catch(e=>{D(e instanceof Error?e.message:`Failed to load file`),T(!1)}),()=>{A.current&&clearTimeout(A.current)}},[n,r,B,V,G]),(0,h.useEffect)(()=>{if(!R)return;let e=n?.split(`/`).pop()??`Untitled`,t=O?`${e} \u25CF`:e;R.title!==t&&P(R.id,{title:t})},[O]);let K=(0,h.useCallback)(async e=>{if(n&&!(!G&&!r))try{G?await l.put(`/api/fs/write`,{path:n,content:e}):await l.put(`${s(r)}/files/write`,{path:n,content:e}),k(!1)}catch{}},[n,r,G]);function q(e){let t=e??``;c(t),j.current=t,k(!0),A.current&&clearTimeout(A.current),A.current=setTimeout(()=>K(j.current),1e3)}let J=(0,h.useCallback)((e,t)=>{M.current=e,e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>o.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0})},[]);return!n||!G&&!r?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`}):w?(0,g.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,g.jsx)(u,{className:`size-5 animate-spin`}),(0,g.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]}):E?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:E}):B?(0,g.jsx)(S,{filePath:n,projectName:r}):V?(0,g.jsx)(C,{filePath:n,projectName:r}):d===`base64`?(0,g.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,g.jsx)(m,{className:`size-10 text-text-subtle`}),(0,g.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,g.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]}):(0,g.jsx)(`div`,{className:`flex flex-col h-full w-full overflow-hidden`,children:H&&U===`preview`?(0,g.jsx)(x,{content:i??``}):(0,g.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,g.jsx)(f,{height:`100%`,language:y(n),value:i??``,onChange:q,onMount:J,theme:L,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:F?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0}},loading:(0,g.jsx)(u,{className:`size-5 animate-spin text-text-subtle`})})})})}function x({content:e}){return(0,g.jsx)(d,{content:e,className:`flex-1 overflow-auto p-4`})}function S({filePath:e,projectName:t}){let[n,r]=(0,h.useState)(null),[i,a]=(0,h.useState)(!1);return(0,h.useEffect)(()=>{let n,i=`${s(t)}/files/raw?path=${encodeURIComponent(e)}`,o=c();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(e);n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]),i?(0,g.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,g.jsx)(m,{className:`size-10 text-text-subtle`}),(0,g.jsx)(`p`,{className:`text-sm`,children:`Failed to load image.`})]}):n?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full p-4 bg-surface overflow-auto`,children:(0,g.jsx)(`img`,{src:n,alt:e,className:`max-w-full max-h-full object-contain`})}):(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,g.jsx)(u,{className:`size-5 animate-spin text-text-subtle`})})}function C({filePath:e,projectName:t}){let[n,r]=(0,h.useState)(null),[a,o]=(0,h.useState)(!1);(0,h.useEffect)(()=>{let n,i=`${s(t)}/files/raw?path=${encodeURIComponent(e)}`,a=c();return fetch(i,{headers:a?{Authorization:`Bearer ${a}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(new Blob([e],{type:`application/pdf`}));n=t,r(t)}).catch(()=>o(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]);let l=(0,h.useCallback)(()=>{n&&window.open(n,`_blank`)},[n]);return a?(0,g.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,g.jsx)(m,{className:`size-10 text-text-subtle`}),(0,g.jsx)(`p`,{className:`text-sm`,children:`Failed to load PDF.`})]}):n?(0,g.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,g.jsx)(`span`,{className:`text-xs text-text-secondary truncate`,children:e}),(0,g.jsxs)(`button`,{onClick:l,className:`flex items-center gap-1 text-xs text-text-secondary hover:text-text-primary transition-colors`,children:[(0,g.jsx)(i,{className:`size-3`}),` Open in new tab`]})]}),(0,g.jsx)(`iframe`,{src:n,title:e,className:`flex-1 w-full border-none`})]}):(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,g.jsx)(u,{className:`size-5 animate-spin text-text-subtle`})})}export{b as CodeEditor};
@@ -1,4 +0,0 @@
1
- import{o as e,r as t,t as n}from"./jsx-runtime-B4BJKQ1u.js";import{n as r}from"./settings-store-CGtTcr8r.js";import{i,t as a}from"./api-client-ANLU-Irq.js";import{A as o,w as s}from"./index-D_IIxtVN.js";import{r as c,t as l}from"./use-monaco-theme-CsNwoeyj.js";var u=e(t(),1),d=n();function f(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`}[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function p({metadata:e}){let t=e?.filePath,n=e?.projectName,p=e?.ref1,h=e?.ref2,g=e?.file1,_=e?.file2,v=e?.original,y=e?.modified,b=v!=null||y!=null,x=!!(g&&_),[S,C]=(0,u.useState)(null),[w,T]=(0,u.useState)(null),[E,D]=(0,u.useState)(!b),[O,k]=(0,u.useState)(null),[A,j]=(0,u.useState)(`both`),{wordWrap:M,toggleWordWrap:N}=r(),P=l();(0,u.useEffect)(()=>{if(b||!n)return;if(D(!0),k(null),g&&_){let e=new URLSearchParams({file1:g,file2:_});a.get(`${i(n)}/files/compare?${e}`).then(e=>{T(e),D(!1)}).catch(e=>{k(e instanceof Error?e.message:`Failed to compare files`),D(!1)});return}let e;if(t){let r=new URLSearchParams({file:t});p&&r.set(`ref`,p),e=`${i(n)}/git/file-diff?${r}`}else if(p||h){let t=new URLSearchParams;p&&t.set(`ref1`,p),h&&t.set(`ref2`,h),e=`${i(n)}/git/diff?${t}`}else e=`${i(n)}/git/diff`;a.get(e).then(e=>{C(e.diff),D(!1)}).catch(e=>{k(e instanceof Error?e.message:`Failed to load diff`),D(!1)})},[t,n,p,h,g,_,b]);let{original:F,modified:I}=(0,u.useMemo)(()=>b?{original:v??``,modified:y??``}:x&&w?w:S?m(S):{original:``,modified:``},[S,b,v,y,x,w]),L=(0,u.useMemo)(()=>{let e=t??_??g;return e?f(e):`plaintext`},[t,g,_]);return!n&&!b?(0,d.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`}):E?(0,d.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,d.jsx)(s,{className:`size-5 animate-spin`}),(0,d.jsx)(`span`,{className:`text-sm`,children:`Loading diff...`})]}):O?(0,d.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive text-sm`,children:O}):!b&&!x&&(!S||S.trim()===``)&&!F&&!I?(0,d.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,d.jsx)(o,{className:`size-8`}),(0,d.jsx)(`p`,{className:`text-sm`,children:`No changes detected`}),t&&(0,d.jsx)(`p`,{className:`text-xs font-mono`,children:t})]}):(0,d.jsx)(`div`,{className:`flex flex-col h-full`,children:(0,d.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,d.jsx)(c,{height:`100%`,language:L,original:F,modified:I,theme:P,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:M?`on`:`off`,renderSideBySide:A===`both`,readOnly:!0,automaticLayout:!0,scrollBeyondLastLine:!1},loading:(0,d.jsx)(s,{className:`size-5 animate-spin text-text-subtle`})})})})}function m(e){let t=e.split(`
2
- `),n=[],r=[],i=!1;for(let e of t)if(!(e.startsWith(`diff --git`)||e.startsWith(`diff --no-index`)||e.startsWith(`index `)||e.startsWith(`new file`)||e.startsWith(`deleted file`)||e.startsWith(`old mode`)||e.startsWith(`new mode`)||e.startsWith(`---`)||e.startsWith(`+++`)||e.startsWith(`Binary files`)||e.startsWith(`\\ No newline`))){if(e.startsWith(`@@`)){i=!0;continue}if(i)if(e.startsWith(`-`))n.push(e.slice(1));else if(e.startsWith(`+`))r.push(e.slice(1));else{let t=e.startsWith(` `)?e.slice(1):e;n.push(t),r.push(t)}}return{original:n.join(`
3
- `),modified:r.join(`
4
- `)}}export{p as DiffViewer};