@hienlh/ppm 0.4.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -2
- package/bun.lock +3 -0
- package/dist/web/assets/api-client-ANLU-Irq.js +1 -0
- package/dist/web/assets/chat-tab-C6iTYbRI.js +7 -0
- package/dist/web/assets/code-editor-hnDDc8JZ.js +1 -0
- package/dist/web/assets/{diff-viewer-B9oX4DDx.js → diff-viewer-BWeMVAvK.js} +1 -1
- package/dist/web/assets/git-graph-D6oftHHC.js +1 -0
- package/dist/web/assets/index-CWwJBtaO.js +21 -0
- package/dist/web/assets/index-jmj5f_bQ.css +2 -0
- package/dist/web/assets/{input-AESbQWjx.js → input-D-F4ITU0.js} +1 -1
- package/dist/web/assets/jsx-runtime-B4BJKQ1u.js +1 -0
- package/dist/web/assets/{markdown-renderer-DdDDhQDx.js → markdown-renderer-PHBaNQ3l.js} +2 -2
- package/dist/web/assets/react-WvgCEYPV.js +1 -0
- package/dist/web/assets/rotate-ccw-BesidNnx.js +1 -0
- package/dist/web/assets/settings-store-CGtTcr8r.js +1 -0
- package/dist/web/assets/settings-tab-BpETyigv.js +1 -0
- package/dist/web/assets/tab-store-Dq1kMOkJ.js +1 -0
- package/dist/web/assets/{terminal-tab-BeFf07MH.js → terminal-tab-BTumEYyO.js} +2 -2
- package/dist/web/assets/{use-monaco-theme-Bb9W0CI2.js → use-monaco-theme-CsNwoeyj.js} +1 -1
- package/dist/web/index.html +8 -7
- package/dist/web/sw.js +1 -1
- package/package.json +2 -1
- package/src/cli/commands/stop.ts +8 -0
- package/src/providers/claude-agent-sdk.ts +36 -13
- package/src/server/index.ts +15 -0
- package/src/server/routes/chat.ts +31 -3
- package/src/server/ws/chat.ts +40 -0
- package/src/services/claude-usage.service.ts +51 -23
- package/src/services/tunnel.service.ts +4 -0
- package/src/types/api.ts +1 -0
- package/src/types/chat.ts +1 -0
- package/src/web/app.tsx +5 -0
- package/src/web/components/chat/chat-history-bar.tsx +15 -3
- package/src/web/components/chat/chat-tab.tsx +45 -50
- package/src/web/components/chat/message-input.tsx +116 -55
- package/src/web/components/chat/message-list.tsx +156 -69
- package/src/web/components/chat/usage-badge.tsx +4 -4
- package/src/web/components/layout/command-palette.tsx +37 -8
- package/src/web/components/layout/draggable-tab.tsx +4 -4
- package/src/web/components/layout/mobile-drawer.tsx +2 -2
- package/src/web/components/layout/mobile-nav.tsx +3 -2
- package/src/web/components/layout/project-bar.tsx +5 -3
- package/src/web/components/layout/project-bottom-sheet.tsx +3 -1
- package/src/web/components/layout/tab-bar.tsx +4 -4
- package/src/web/components/shared/bug-report-popup.tsx +58 -0
- package/src/web/hooks/use-chat.ts +63 -7
- package/src/web/hooks/use-usage.ts +15 -17
- package/src/web/lib/report-bug.ts +12 -3
- package/src/web/stores/project-store.ts +7 -1
- package/vite.config.ts +2 -0
- package/dist/web/assets/api-client-BsHoRDAn.js +0 -1
- package/dist/web/assets/chat-tab-Bj1hZQ4x.js +0 -6
- package/dist/web/assets/code-editor-Bj9jdnLm.js +0 -1
- package/dist/web/assets/copy-BNk4Z75P.js +0 -1
- package/dist/web/assets/external-link-CrtbmtJ6.js +0 -1
- package/dist/web/assets/git-graph-DoLRBTMk.js +0 -1
- package/dist/web/assets/index-C_yeSRZ0.css +0 -2
- package/dist/web/assets/index-D27GI6gs.js +0 -21
- package/dist/web/assets/jsx-runtime-BFALxl05.js +0 -1
- package/dist/web/assets/settings-store-DWYkr_a3.js +0 -1
- package/dist/web/assets/settings-tab-BLoiK6Nc.js +0 -1
- package/dist/web/assets/tab-store-B1wzyDLQ.js +0 -1
|
@@ -17,10 +17,16 @@ interface UseChatOptions {
|
|
|
17
17
|
onUsageEvent?: UsageEventCallback;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/** Streaming phase: connecting → streaming → idle */
|
|
21
|
+
export type StreamingStatus = "idle" | "connecting" | "streaming";
|
|
22
|
+
|
|
20
23
|
interface UseChatReturn {
|
|
21
24
|
messages: ChatMessage[];
|
|
22
25
|
messagesLoading: boolean;
|
|
23
26
|
isStreaming: boolean;
|
|
27
|
+
streamingStatus: StreamingStatus;
|
|
28
|
+
connectingElapsed: number;
|
|
29
|
+
thinkingWarningThreshold: number;
|
|
24
30
|
pendingApproval: ApprovalRequest | null;
|
|
25
31
|
sendMessage: (content: string) => void;
|
|
26
32
|
respondToApproval: (requestId: string, approved: boolean, data?: unknown) => void;
|
|
@@ -34,6 +40,11 @@ export function useChat(sessionId: string | null, providerId = "claude-sdk", pro
|
|
|
34
40
|
const [messages, setMessages] = useState<ChatMessage[]>([]);
|
|
35
41
|
const [messagesLoading, setMessagesLoading] = useState(false);
|
|
36
42
|
const [isStreaming, setIsStreaming] = useState(false);
|
|
43
|
+
const [streamingStatus, setStreamingStatus] = useState<StreamingStatus>("idle");
|
|
44
|
+
/** Elapsed seconds while connecting (sent by BE heartbeat every 5s) */
|
|
45
|
+
const [connectingElapsed, setConnectingElapsed] = useState(0);
|
|
46
|
+
/** Warning threshold in seconds — higher for deeper thinking modes */
|
|
47
|
+
const [thinkingWarningThreshold, setThinkingWarningThreshold] = useState(15);
|
|
37
48
|
const [pendingApproval, setPendingApproval] = useState<ApprovalRequest | null>(null);
|
|
38
49
|
const [isConnected, setIsConnected] = useState(false);
|
|
39
50
|
const onUsageEventRef = useRef(options?.onUsageEvent);
|
|
@@ -56,6 +67,30 @@ export function useChat(sessionId: string | null, providerId = "claude-sdk", pro
|
|
|
56
67
|
// Ignore keepalive pings
|
|
57
68
|
if ((data as any).type === "ping") return;
|
|
58
69
|
|
|
70
|
+
// Handle streaming status updates (connecting → streaming → idle)
|
|
71
|
+
if ((data as any).type === "streaming_status") {
|
|
72
|
+
const s = (data as any).status ?? "idle";
|
|
73
|
+
setStreamingStatus(s);
|
|
74
|
+
setConnectingElapsed(s === "connecting" ? ((data as any).elapsed ?? 0) : 0);
|
|
75
|
+
// Compute warning threshold based on effort/thinking budget
|
|
76
|
+
if (s === "connecting") {
|
|
77
|
+
const effort = (data as any).effort as string | undefined;
|
|
78
|
+
const budget = (data as any).thinkingBudget as number | undefined;
|
|
79
|
+
// Higher thinking = longer acceptable wait time
|
|
80
|
+
let threshold = 15; // default
|
|
81
|
+
if (budget && budget > 0) {
|
|
82
|
+
// Rough: 1k tokens ≈ 2s thinking time
|
|
83
|
+
threshold = Math.max(15, Math.round(budget / 500));
|
|
84
|
+
} else if (effort === "high") {
|
|
85
|
+
threshold = 30;
|
|
86
|
+
} else if (effort === "low") {
|
|
87
|
+
threshold = 10;
|
|
88
|
+
}
|
|
89
|
+
setThinkingWarningThreshold(threshold);
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
59
94
|
// Handle connected event (new session)
|
|
60
95
|
if ((data as any).type === "connected") {
|
|
61
96
|
setIsConnected(true);
|
|
@@ -84,20 +119,22 @@ export function useChat(sessionId: string | null, providerId = "claude-sdk", pro
|
|
|
84
119
|
|
|
85
120
|
/**
|
|
86
121
|
* Route a child event to its parent Agent/Task tool_use's children array.
|
|
122
|
+
* Creates a new parent object to ensure React detects the change on re-render.
|
|
87
123
|
* Returns true if routed (caller should skip flat append), false if no parent found.
|
|
88
124
|
*/
|
|
89
125
|
const routeToParent = (childEvent: ChatEvent, parentToolUseId: string): boolean => {
|
|
90
|
-
const
|
|
126
|
+
const idx = streamingEventsRef.current.findIndex(
|
|
91
127
|
(e) => e.type === "tool_use"
|
|
92
128
|
&& (e.tool === "Agent" || e.tool === "Task")
|
|
93
129
|
&& (e as any).toolUseId === parentToolUseId,
|
|
94
130
|
);
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
131
|
+
if (idx === -1) return false;
|
|
132
|
+
const parent = streamingEventsRef.current[idx]!;
|
|
133
|
+
if (parent.type !== "tool_use") return false;
|
|
134
|
+
// Create new object so React detects the change via shallow comparison
|
|
135
|
+
const newChildren = [...(parent.children ?? []), childEvent];
|
|
136
|
+
streamingEventsRef.current[idx] = { ...parent, children: newChildren };
|
|
137
|
+
return true;
|
|
101
138
|
};
|
|
102
139
|
|
|
103
140
|
/** Trigger re-render with latest events snapshot */
|
|
@@ -133,6 +170,17 @@ export function useChat(sessionId: string | null, providerId = "claude-sdk", pro
|
|
|
133
170
|
break;
|
|
134
171
|
}
|
|
135
172
|
|
|
173
|
+
case "thinking": {
|
|
174
|
+
const pid = (data as any).parentToolUseId as string | undefined;
|
|
175
|
+
if (pid && routeToParent(data, pid)) {
|
|
176
|
+
syncMessages();
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
streamingEventsRef.current.push(data);
|
|
180
|
+
syncMessages();
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
|
|
136
184
|
case "tool_use": {
|
|
137
185
|
const pid = (data as any).parentToolUseId as string | undefined;
|
|
138
186
|
if (pid && routeToParent(data, pid)) {
|
|
@@ -195,10 +243,13 @@ export function useChat(sessionId: string | null, providerId = "claude-sdk", pro
|
|
|
195
243
|
});
|
|
196
244
|
isStreamingRef.current = false;
|
|
197
245
|
setIsStreaming(false);
|
|
246
|
+
setStreamingStatus("idle");
|
|
198
247
|
break;
|
|
199
248
|
}
|
|
200
249
|
|
|
201
250
|
case "done": {
|
|
251
|
+
// Idempotent: may receive duplicate done (provider + stream loop finally)
|
|
252
|
+
if (!isStreamingRef.current) break;
|
|
202
253
|
// Finalize the streaming message — capture refs before clearing
|
|
203
254
|
const finalContent = streamingContentRef.current;
|
|
204
255
|
const finalEvents = [...streamingEventsRef.current];
|
|
@@ -221,6 +272,7 @@ export function useChat(sessionId: string | null, providerId = "claude-sdk", pro
|
|
|
221
272
|
streamingEventsRef.current = [];
|
|
222
273
|
isStreamingRef.current = false;
|
|
223
274
|
setIsStreaming(false);
|
|
275
|
+
setStreamingStatus("idle");
|
|
224
276
|
break;
|
|
225
277
|
}
|
|
226
278
|
}
|
|
@@ -319,6 +371,7 @@ export function useChat(sessionId: string | null, providerId = "claude-sdk", pro
|
|
|
319
371
|
pendingMessageRef.current = null;
|
|
320
372
|
isStreamingRef.current = true;
|
|
321
373
|
setIsStreaming(true);
|
|
374
|
+
setStreamingStatus("connecting");
|
|
322
375
|
setPendingApproval(null);
|
|
323
376
|
|
|
324
377
|
send(JSON.stringify({ type: "message", content }));
|
|
@@ -425,6 +478,9 @@ export function useChat(sessionId: string | null, providerId = "claude-sdk", pro
|
|
|
425
478
|
messages,
|
|
426
479
|
messagesLoading,
|
|
427
480
|
isStreaming,
|
|
481
|
+
streamingStatus,
|
|
482
|
+
connectingElapsed,
|
|
483
|
+
thinkingWarningThreshold,
|
|
428
484
|
pendingApproval,
|
|
429
485
|
sendMessage,
|
|
430
486
|
respondToApproval,
|
|
@@ -2,12 +2,13 @@ import { useState, useCallback, useEffect, useRef } from "react";
|
|
|
2
2
|
import { getAuthToken, projectUrl } from "@/lib/api-client";
|
|
3
3
|
import type { UsageInfo } from "../../types/chat";
|
|
4
4
|
|
|
5
|
-
const POLL_INTERVAL =
|
|
5
|
+
const POLL_INTERVAL = 30_000; // read cache every 30s
|
|
6
6
|
|
|
7
7
|
interface UseUsageReturn {
|
|
8
8
|
usageInfo: UsageInfo;
|
|
9
9
|
usageLoading: boolean;
|
|
10
|
-
|
|
10
|
+
/** ISO timestamp from BE — when usage was actually fetched from Anthropic API */
|
|
11
|
+
lastFetchedAt: string | null;
|
|
11
12
|
refreshUsage: () => void;
|
|
12
13
|
/** Merge partial usage from WebSocket events (cost tracking) */
|
|
13
14
|
mergeUsage: (partial: Partial<UsageInfo>) => void;
|
|
@@ -16,13 +17,13 @@ interface UseUsageReturn {
|
|
|
16
17
|
export function useUsage(projectName: string, providerId = "claude-sdk"): UseUsageReturn {
|
|
17
18
|
const [usageInfo, setUsageInfo] = useState<UsageInfo>({});
|
|
18
19
|
const [usageLoading, setUsageLoading] = useState(false);
|
|
19
|
-
const [
|
|
20
|
+
const [lastFetchedAt, setLastFetchedAt] = useState<string | null>(null);
|
|
20
21
|
const timerRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
|
21
22
|
|
|
22
|
-
const
|
|
23
|
+
const doFetch = useCallback((forceRefresh = false) => {
|
|
23
24
|
if (!projectName) return;
|
|
24
25
|
setUsageLoading(true);
|
|
25
|
-
const qs =
|
|
26
|
+
const qs = forceRefresh ? "&refresh=1" : "";
|
|
26
27
|
fetch(`${projectUrl(projectName)}/chat/usage?providerId=${providerId}${qs}`, {
|
|
27
28
|
headers: { Authorization: `Bearer ${getAuthToken()}` },
|
|
28
29
|
})
|
|
@@ -30,25 +31,22 @@ export function useUsage(projectName: string, providerId = "claude-sdk"): UseUsa
|
|
|
30
31
|
.then((json: any) => {
|
|
31
32
|
if (json.ok && json.data) {
|
|
32
33
|
setUsageInfo((prev) => ({ ...prev, ...json.data }));
|
|
33
|
-
|
|
34
|
+
if (json.data.lastFetchedAt) setLastFetchedAt(json.data.lastFetchedAt);
|
|
34
35
|
}
|
|
35
36
|
})
|
|
36
37
|
.catch(() => {})
|
|
37
38
|
.finally(() => setUsageLoading(false));
|
|
38
39
|
}, [projectName, providerId]);
|
|
39
40
|
|
|
40
|
-
//
|
|
41
|
+
// Read cache on mount + auto-read every POLL_INTERVAL
|
|
41
42
|
useEffect(() => {
|
|
42
|
-
|
|
43
|
-
timerRef.current = setInterval(() =>
|
|
44
|
-
return () => {
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
}, [fetchUsage]);
|
|
43
|
+
doFetch();
|
|
44
|
+
timerRef.current = setInterval(() => doFetch(), POLL_INTERVAL);
|
|
45
|
+
return () => { if (timerRef.current) clearInterval(timerRef.current); };
|
|
46
|
+
}, [doFetch]);
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}, [fetchUsage]);
|
|
48
|
+
/** Manual refresh — tells BE to fetch fresh from Anthropic API */
|
|
49
|
+
const refreshUsage = useCallback(() => doFetch(true), [doFetch]);
|
|
52
50
|
|
|
53
51
|
const mergeUsage = useCallback((partial: Partial<UsageInfo>) => {
|
|
54
52
|
setUsageInfo((prev) => {
|
|
@@ -61,5 +59,5 @@ export function useUsage(projectName: string, providerId = "claude-sdk"): UseUsa
|
|
|
61
59
|
});
|
|
62
60
|
}, []);
|
|
63
61
|
|
|
64
|
-
return { usageInfo, usageLoading,
|
|
62
|
+
return { usageInfo, usageLoading, lastFetchedAt, refreshUsage, mergeUsage };
|
|
65
63
|
}
|
|
@@ -69,11 +69,20 @@ export async function copyToClipboard(text: string): Promise<boolean> {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
/**
|
|
72
|
+
/** Open bug report popup globally via custom event */
|
|
73
|
+
export function openBugReportPopup(
|
|
74
|
+
version: string | null,
|
|
75
|
+
options?: { sessionId?: string; projectName?: string },
|
|
76
|
+
) {
|
|
77
|
+
buildBugReport(version, options).then((body) => {
|
|
78
|
+
window.dispatchEvent(new CustomEvent("open-bug-report", { detail: body }));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** @deprecated Use openBugReportPopup instead */
|
|
73
83
|
export async function openBugReport(
|
|
74
84
|
version: string | null,
|
|
75
85
|
options?: { sessionId?: string; projectName?: string },
|
|
76
86
|
) {
|
|
77
|
-
|
|
78
|
-
openGithubIssue(body);
|
|
87
|
+
openBugReportPopup(version, options);
|
|
79
88
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { create } from "zustand";
|
|
2
2
|
import { api } from "@/lib/api-client";
|
|
3
|
+
import { parseUrlState } from "@/hooks/use-url-sync";
|
|
3
4
|
|
|
4
5
|
export interface Project {
|
|
5
6
|
name: string;
|
|
@@ -107,9 +108,14 @@ export const useProjectStore = create<ProjectStore>((set, get) => ({
|
|
|
107
108
|
try {
|
|
108
109
|
const projects = await api.get<ProjectInfo[]>("/api/projects");
|
|
109
110
|
set({ projects, loading: false });
|
|
110
|
-
// Auto-select first
|
|
111
|
+
// Auto-select: restore from URL first, then fall back to first project
|
|
111
112
|
set((s) => {
|
|
112
113
|
if (!s.activeProject && projects.length > 0) {
|
|
114
|
+
const { projectName: urlProject } = parseUrlState();
|
|
115
|
+
if (urlProject) {
|
|
116
|
+
const match = projects.find((p) => p.name === urlProject);
|
|
117
|
+
if (match) return { activeProject: match };
|
|
118
|
+
}
|
|
113
119
|
const sorted = resolveOrder(projects, s.customOrder);
|
|
114
120
|
return { activeProject: sorted[0] };
|
|
115
121
|
}
|
package/vite.config.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as e,r as t}from"./jsx-runtime-BFALxl05.js";var n=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},r=(e=>e?n(e):n),i=e(t(),1),a=e=>e;function o(e,t=a){let n=i.useSyncExternalStore(e.subscribe,i.useCallback(()=>t(e.getState()),[e,t]),i.useCallback(()=>t(e.getInitialState()),[e,t]));return i.useDebugValue(n),n}var s=e=>{let t=r(e),n=e=>o(t,e);return Object.assign(n,t),n},c=(e=>e?s(e):s),l=`ppm-auth-token`,u=new class{baseUrl;constructor(e=``){this.baseUrl=e}getToken(){return localStorage.getItem(l)}headers(){let e={"Content-Type":`application/json`},t=this.getToken();return t&&(e.Authorization=`Bearer ${t}`),e}async get(e){let t=await fetch(`${this.baseUrl}${e}`,{headers:this.headers()});return this.handleResponse(t)}async post(e,t){let n=await fetch(`${this.baseUrl}${e}`,{method:`POST`,headers:this.headers(),body:t==null?void 0:JSON.stringify(t)});return this.handleResponse(n)}async put(e,t){let n=await fetch(`${this.baseUrl}${e}`,{method:`PUT`,headers:this.headers(),body:t==null?void 0:JSON.stringify(t)});return this.handleResponse(n)}async patch(e,t){let n=await fetch(`${this.baseUrl}${e}`,{method:`PATCH`,headers:this.headers(),body:t==null?void 0:JSON.stringify(t)});return this.handleResponse(n)}async del(e,t){let n=await fetch(`${this.baseUrl}${e}`,{method:`DELETE`,headers:this.headers(),body:t==null?void 0:JSON.stringify(t)});await this.handleResponse(n)}async handleResponse(e){if(e.status===401)throw localStorage.removeItem(l),window.location.reload(),Error(`Unauthorized`);let t=await e.json();if(t.ok===!1)throw Error(t.error??`HTTP ${e.status}`);return t.data}};function d(e){return`/api/project/${encodeURIComponent(e)}`}function f(e){localStorage.setItem(l,e)}function p(){return localStorage.getItem(l)}export{c as a,f as i,p as n,d as r,u as t};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{a as e,n as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import"./input-AESbQWjx.js";import{t as i}from"./copy-BNk4Z75P.js";import{t as a}from"./external-link-CrtbmtJ6.js";import{n as o,r as s,t as c}from"./api-client-BsHoRDAn.js";import{n as l}from"./settings-store-DWYkr_a3.js";import{n as u}from"./utils-bntUtdc7.js";import{t as d}from"./tab-store-B1wzyDLQ.js";import{A as f,C as p,F as m,M as h,N as g,O as _,P as v,S as y,T as b,a as x,k as S,n as C,r as w,t as T,w as E,x as D,y as O}from"./index-D27GI6gs.js";import{t as k}from"./markdown-renderer-DdDDhQDx.js";var A=t(`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`}]]),j=t(`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=t(`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=t(`code`,[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]),P=t(`columns-2`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M12 3v18`,key:`108xh3`}]]),F=t(`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=t(`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=t(`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=t(`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=t(`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=t(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),V=t(`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`}]]),ee=t(`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`}]]),H=t(`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`}]]),te=t(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),ne=t(`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=e(n(),1),re=3e4,ie=1e3,ae=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(ie*2**this.reconnectAttempts,re);this.reconnectAttempts++,this.reconnectTimer=setTimeout(()=>this.connect(),e)}};function oe({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,U.useRef)(null);return(0,U.useEffect)(()=>{let i=new ae(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 se(e,t=`claude-sdk`,n=``,r){let[i,a]=(0,U.useState)([]),[c,l]=(0,U.useState)(!1),[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(null),[m,h]=(0,U.useState)(!1),g=(0,U.useRef)(r?.onUsageEvent);g.current=r?.onUsageEvent;let _=(0,U.useRef)(``),v=(0,U.useRef)([]),y=(0,U.useRef)(!1),b=(0,U.useRef)(null),x=(0,U.useRef)(()=>{}),S=(0,U.useRef)(null),C=(0,U.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type===`ping`)return;if(t.type===`connected`){h(!0);return}if(t.type===`status`){h(!0);let e=t;e.isStreaming&&(y.current=!0,d(!0)),e.pendingApproval&&p({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),S.current?.();return}let n=(e,t)=>{let n=v.current.find(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);return n&&n.type===`tool_use`?(n.children||=[],n.children.push(e),!0):!1},r=()=>{let e=_.current,t=[...v.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}_.current+=t.content,v.current.push(t),r();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}v.current.push(t),r();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}v.current.push(t),r();break}case`approval_request`:v.current.push(t),p({requestId:t.requestId,tool:t.tool,input:t.input});break;case`usage`:g.current?.(t.usage);break;case`error`:{v.current.push(t);let e=[...v.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()}]}),y.current=!1,d(!1);break}case`done`:{let e=_.current,t=[...v.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}),_.current=``,v.current=[],y.current=!1,d(!1);break}}},[]),{send:w,connect:T}=oe({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:C,autoConnect:!!e&&!!n});x.current=w,(0,U.useEffect)(()=>{let r=!1;return d(!1),p(null),_.current=``,v.current=[],h(!1),e&&n?(l(!0),fetch(`${s(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${o()}`}}).then(e=>e.json()).then(e=>{r||y.current||(e.ok&&Array.isArray(e.data)&&e.data.length>0?a(e.data):a([]))}).catch(()=>{!r&&!y.current&&a([])}).finally(()=>{r||l(!1)})):a([]),()=>{r=!0}},[e,t,n]);let E=(0,U.useCallback)(e=>{if(e.trim()){if(y.current){let e=_.current,t=[...v.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}),w(JSON.stringify({type:`cancel`}))}a(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),_.current=``,v.current=[],b.current=null,y.current=!0,d(!0),p(null),w(JSON.stringify({type:`message`,content:e}))}},[w]),D=(0,U.useCallback)((e,t,n)=>{if(w(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=v.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`);if(t){let e=t.input;e&&typeof e==`object`&&(e.answers=n)}a(e=>[...e])}p(null)},[w]),O=(0,U.useCallback)(()=>{if(!y.current)return;w(JSON.stringify({type:`cancel`}));let e=_.current,t=[...v.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}),_.current=``,v.current=[],b.current=null,y.current=!1,d(!1),p(null)},[w]),k=(0,U.useCallback)(()=>{h(!1),T(),S.current?.()},[T]),A=(0,U.useCallback)(()=>{!e||!n||(l(!0),fetch(`${s(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${o()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(a(e.data),_.current=``,v.current=[])}).catch(()=>{}).finally(()=>l(!1)))},[e,t,n]);return S.current=A,{messages:i,messagesLoading:c,isStreaming:u,pendingApproval:f,sendMessage:E,respondToApproval:D,cancelStreaming:O,reconnect:k,refetchMessages:A,isConnected:m}}var W=6e4;function ce(e,t=`claude-sdk`){let[n,r]=(0,U.useState)({}),[i,a]=(0,U.useState)(!1),[c,l]=(0,U.useState)(null),u=(0,U.useRef)(null),d=(0,U.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&_t=${Date.now()}`:``;fetch(`${s(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${o()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),l(Date.now()))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,U.useEffect)(()=>(d(),u.current=setInterval(()=>d(!0),W),()=>{u.current&&clearInterval(u.current)}),[d]),{usageInfo:n,usageLoading:i,lastUpdatedAt:c,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 G=r();function K(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 q({tool:e,result:t,completed:n,projectName:r}){let[i,a]=(0,U.useState)(!1);if(e.type===`error`)return(0,G.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,G.jsx)(g,{className:`size-3`}),(0,G.jsx)(`span`,{children:e.message})]});let{toolName:o,input:s}=K(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,G.jsxs)(`div`,{className:`rounded border text-xs ${d?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,G.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,G.jsx)(m,{className:`size-3 shrink-0`}):(0,G.jsx)(v,{className:`size-3 shrink-0`}),l?(0,G.jsx)(M,{className:`size-3 text-red-400 shrink-0`}):c||u||n?(0,G.jsx)(h,{className:`size-3 text-green-400 shrink-0`}):(0,G.jsx)(b,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,G.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,G.jsx)(le,{name:o,input:s})}),p&&(0,G.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[f.length,` steps`]})]}),i&&(0,G.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,G.jsx)(J,{name:o,input:s,projectName:r}),p&&(0,G.jsx)(fe,{events:f,projectName:r}),c&&(0,G.jsx)(ue,{toolName:o,output:t.output})]})]})}function le({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,G.jsxs)(G.Fragment,{children:[e,` `,(0,G.jsx)(`span`,{className:`text-text-subtle`,children:pe(n(t.file_path))})]});case`Bash`:return(0,G.jsxs)(G.Fragment,{children:[e,` `,(0,G.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Z(n(t.command),60)})]});case`Glob`:return(0,G.jsxs)(G.Fragment,{children:[e,` `,(0,G.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,G.jsxs)(G.Fragment,{children:[e,` `,(0,G.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Z(n(t.pattern),40)})]});case`WebSearch`:return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(y,{className:`size-3 inline`}),` `,e,` `,(0,G.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.query),50)})]});case`WebFetch`:return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(F,{className:`size-3 inline`}),` `,e,` `,(0,G.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.url),50)})]});case`ToolSearch`:return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(y,{className:`size-3 inline`}),` `,e,` `,(0,G.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.query),50)})]});case`Agent`:case`Task`:return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(j,{className:`size-3 inline`}),` `,e,` `,(0,G.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.description||t.prompt),60)})]});case`TodoWrite`:{let n=t.todos??[],r=n.filter(e=>e.status===`completed`).length;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(R,{className:`size-3 inline`}),` `,e,` `,(0,G.jsxs)(`span`,{className:`text-text-subtle`,children:[r,`/`,n.length,` done`]})]})}case`AskUserQuestion`:{let n=t.questions??[],r=!!t.answers;return(0,G.jsxs)(G.Fragment,{children:[e,` `,(0,G.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,G.jsx)(G.Fragment,{children:e})}}function J({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=d(),o=e=>{n&&i({type:`editor`,title:e.split(`/`).pop()??e,metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},s=(e,t,r)=>{i({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,G.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,G.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,G.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,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.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:()=>o(n),title:`Open file in editor`,children:[(0,G.jsx)(a,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,G.jsxs)(`button`,{type:`button`,className:`text-text-subtle hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>s(n,r(t.old_string),r(t.new_string)),title:`View diff in new tab`,children:[(0,G.jsx)(P,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,G.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:Z(r(t.content),300)})]})}case`Glob`:return(0,G.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,G.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,G.jsx)(Y,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,G.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,G.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,G.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,G.jsx)(X,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,G.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.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,G.jsx)(F,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,G.jsx)(`p`,{className:`text-text-subtle`,children:Z(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,G.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,G.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,G.jsxs)(`p`,{className:`text-accent text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,G.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function Y({todos:e}){return(0,G.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,G.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,G.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function ue({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(`
|
|
2
|
-
|
|
3
|
-
`);if(t)return t}if(typeof e==`string`)return e}catch{if(t&&!t.startsWith(`[{`))return t}return null},[e,t]);return i?(0,G.jsxs)(`div`,{className:`border-t border-border pt-1.5 space-y-1`,children:[(0,G.jsx)(X,{content:i,maxHeight:`max-h-60`}),(0,G.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,G.jsx)(N,{className:`size-3`}),n?`Hide`:`Show`,` raw`]}),n&&(0,G.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono max-h-40 whitespace-pre-wrap break-all text-[10px]`,children:t})]}):(0,G.jsx)(de,{output:t})}function de({output:e}){let t=e.split(`
|
|
4
|
-
`).length,n=t>3||e.length>200,[r,i]=(0,U.useState)(n);return(0,G.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[n&&(0,G.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,G.jsx)(v,{className:`size-3`}):(0,G.jsx)(m,{className:`size-3`}),`Output (`,t,` lines)`]}),(0,G.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 fe({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,G.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,G.jsx)(`div`,{className:`text-text-secondary text-[11px]`,children:(0,G.jsx)(X,{content:e.content,maxHeight:`max-h-24`})},`st-${n}`):(0,G.jsx)(q,{tool:e.tool,result:e.result,completed:!!e.result,projectName:t},`sc-${n}`))})}function X({content:e,maxHeight:t=`max-h-48`}){return(0,G.jsx)(k,{content:e,className:`text-text-secondary overflow-auto ${t}`})}function pe(e){return e?e.split(`/`).pop()??e:``}function Z(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}function me({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,projectName:a}){let o=(0,U.useRef)(null),s=(0,U.useRef)(!0);return(0,U.useEffect)(()=>{let t=s.current?`instant`:`smooth`;o.current?.scrollIntoView({behavior:t}),s.current&&e.length>0&&(s.current=!1)},[e,n]),t?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,G.jsx)(j,{className:`size-10 text-text-subtle animate-pulse`}),(0,G.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!i?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,G.jsx)(j,{className:`size-10 text-text-subtle`}),(0,G.jsx)(`p`,{className:`text-sm`,children:`Send a message to start the conversation`})]}):(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto 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,G.jsx)(he,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:a},e.id)),n&&(n.tool===`AskUserQuestion`?(0,G.jsx)(Oe,{approval:n,onRespond:r}):(0,G.jsx)(De,{approval:n,onRespond:r})),i&&(0,G.jsx)(Te,{lastMessage:e[e.length-1]}),(0,G.jsx)(`div`,{ref:o})]})}function he({message:e,isStreaming:t,projectName:n}){return e.role===`user`?(0,G.jsx)(be,{content:e.content,projectName:n}):e.role===`system`?(0,G.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,G.jsx)(g,{className:`size-4 shrink-0`}),(0,G.jsx)(`p`,{children:e.content})]}):(0,G.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.events&&e.events.length>0?(0,G.jsx)(Ce,{events:e.events,isStreaming:t,projectName:n}):e.content&&(0,G.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,G.jsx)(Ee,{content:e.content,projectName:n})})})}var ge=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]);function _e(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(`
|
|
5
|
-
`).map(e=>e.trim()).filter(Boolean),text:e.slice(n[0].length)}:{files:[],text:e}}function Q(e,t){let n=e.split(`/`).pop()??``;return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function ve(e){let t=e.lastIndexOf(`.`);return t===-1?!1:ge.has(e.slice(t).toLowerCase())}function ye(e){return e.toLowerCase().endsWith(`.pdf`)}function be({content:e,projectName:t}){let{files:n,text:r}=(0,U.useMemo)(()=>_e(e),[e]);return(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsxs)(`div`,{className:`rounded-lg bg-primary/10 px-3 py-2 text-sm text-text-primary max-w-[85%] space-y-2`,children:[n.length>0&&(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:n.map((e,n)=>ve(e)?(0,G.jsx)(xe,{src:Q(e,t),alt:e.split(`/`).pop()??`image`},n):ye(e)?(0,G.jsx)(Se,{src:Q(e,t),filename:e.split(`/`).pop()??`document.pdf`,mimeType:`application/pdf`},n):(0,G.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,G.jsx)(f,{className:`size-3.5 shrink-0`}),(0,G.jsx)(`span`,{className:`truncate max-w-40`,children:e.split(`/`).pop()})]},n))}),r&&(0,G.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:r})]})})}function xe({src:e,alt:t}){let[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(!1);return(0,U.useEffect)(()=>{let t,n=o();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,G.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,G.jsx)(L,{className:`size-3.5 shrink-0`}),(0,G.jsx)(`span`,{className:`truncate max-w-40`,children:t})]}):n?(0,G.jsx)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`block`,children:(0,G.jsx)(`img`,{src:n,alt:t,className:`rounded-md max-h-48 max-w-full object-contain border border-border`})}):(0,G.jsx)(`div`,{className:`rounded-md bg-surface border border-border h-24 w-32 animate-pulse`})}function Se({src:e,filename:t,mimeType:n}){let[r,i]=(0,U.useState)(!1);return(0,G.jsxs)(`button`,{type:`button`,onClick:(0,U.useCallback)(async()=>{i(!0);try{let t=o(),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,G.jsx)(f,{className:`size-3.5 shrink-0 text-red-400`}),(0,G.jsx)(`span`,{className:`truncate max-w-40`,children:t}),r&&(0,G.jsx)(`span`,{className:`animate-spin text-[10px]`,children:`...`})]})}function Ce({events:e,isStreaming:t,projectName:n}){let r=[],i=``;for(let t=0;t<e.length;t++){let n=e[t];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}))}i&&r.push({kind:`text`,content:i});let a=e.filter(e=>e.type===`tool_result`);for(let e of a){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,G.jsx)(G.Fragment,{children:r.map((e,i)=>{if(e.kind===`text`){let a=t&&i===r.length-1;return(0,G.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,G.jsx)(we,{content:e.content,animate:a,projectName:n})},`text-${i}`)}return(0,G.jsx)(q,{tool:e.tool,result:e.result,completed:e.completed,projectName:n},`tool-${i}`)})})}function we({content:e,animate:t,projectName:n}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ee,{content:e,projectName:n}),t&&(0,G.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function Te({lastMessage:e}){if(!e||e.role!==`assistant`)return(0,G.jsx)(`div`,{className:`flex items-center gap-2 text-text-subtle text-sm`,children:(0,G.jsx)(`span`,{className:`animate-pulse`,children:`Thinking...`})});let t=e.events;if(t&&t.length>0){let e=t[t.length-1];if(e?.type===`tool_use`||e?.type===`tool_result`)return(0,G.jsx)(`div`,{className:`flex items-center gap-2 text-text-subtle text-sm`,children:(0,G.jsx)(`span`,{className:`animate-pulse`,children:`Thinking...`})})}return null}function Ee({content:e,projectName:t}){return(0,G.jsx)(k,{content:e,projectName:t,codeActions:!0})}function De({approval:e,onRespond:t}){return(0,G.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,G.jsx)(ee,{className:`size-4`}),(0,G.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,G.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,G.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,G.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,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.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,G.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 Oe({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,G.jsxs)(`div`,{className:`rounded-lg border-2 border-accent/40 bg-accent/5 p-3 space-y-3`,children:[n.map((e,t)=>(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),e.multiSelect&&(0,G.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`Select multiple`}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e.options.map((t,n)=>(0,G.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,G.jsx)(`span`,{className:`font-medium`,children:t.label}),t.description&&(0,G.jsxs)(`span`,{className:`text-text-subtle ml-1.5`,children:[`— `,t.description]})]},n)),a[e.question]?(0,G.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,G.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,G.jsxs)(`div`,{className:`flex gap-2 pt-1`,children:[(0,G.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,G.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 ke=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),Ae=new Set([`application/pdf`]),je=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],Me=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 Ne(e){return ke.has(e.type)}function Pe(e){if(ke.has(e.type)||Ae.has(e.type)||je.some(t=>e.type.startsWith(t)))return!0;let t=Fe(e.name);return!!(t&&Me.has(t))}function Fe(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function Ie({attachments:e,onRemove:t}){return e.length===0?null:(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-3 pt-2`,children:e.map(e=>(0,G.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,G.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,G.jsx)(L,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,G.jsx)(f,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,G.jsx)(b,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,G.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,G.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,G.jsx)(O,{className:`size-3`})})]},e.id))})}function Le(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&n(r.children)}return n(e),t}function Re({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,G.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,G.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,G.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,G.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,G.jsx)(_,{className:`size-4 text-amber-500`}):(0,G.jsx)(S,{className:`size-4 text-blue-400`})}),(0,G.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}function ze({onSend:e,isStreaming:t,onCancel:n,disabled:r,projectName:i,onSlashStateChange:a,onSlashItemsLoaded:l,slashSelected:d,onFileStateChange:f,onFileItemsLoaded:p,fileSelected:m,externalFiles:h}){let[g,_]=(0,U.useState)(``),[v,y]=(0,U.useState)([]),b=(0,U.useRef)(null),x=(0,U.useRef)(null),S=(0,U.useRef)([]),C=(0,U.useRef)([]);(0,U.useEffect)(()=>{if(!i){S.current=[],l?.([]);return}c.get(`${s(i)}/chat/slash-items`).then(e=>{S.current=e,l?.(e)}).catch(()=>{S.current=[],l?.([])})},[i]),(0,U.useEffect)(()=>{if(!i){C.current=[],p?.([]);return}c.get(`${s(i)}/files/tree?depth=5`).then(e=>{let t=Le(e);C.current=t,p?.(t)}).catch(()=>{C.current=[],p?.([])})},[i]),(0,U.useEffect)(()=>{if(!d)return;let e=b.current,t=e?.selectionStart??g.length,n=g.slice(0,t),r=g.slice(t),i=n.replace(/(?:^|\s)\/\S*$/,e=>`${e.startsWith(`/`)?``:e[0]}/${d.name} `);_(i+r),a?.(!1,``),f?.(!1,``),e&&(e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=i.length},0))},[d]),(0,U.useEffect)(()=>{if(!m)return;let e=b.current;if(!e)return;let t=e.selectionStart,n=g.slice(0,t),r=g.slice(t),i=n.match(/@(\S*)$/);if(i){let t=n.length-i[0].length;_(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=g+`@${m.path} `;_(t),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length,e.focus()},0)}f?.(!1,``)},[m]),(0,U.useEffect)(()=>{!h||h.length===0||T(h)},[h]);let w=(0,U.useCallback)(async e=>{if(!i)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=o();r&&(n.Authorization=`Bearer ${r}`);let a=await(await fetch(`${s(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]),T=(0,U.useCallback)(e=>{for(let t of e){if(!Pe(t)){_(e=>e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=u(),n=Ne(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};y(e=>[...e,i]),w(t).then(t=>{y(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}b.current?.focus()},[w]),E=(0,U.useCallback)(e=>{y(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),D=(0,U.useCallback)(()=>{let t=g.trim(),n=v.filter(e=>e.status===`ready`);if(!(!t&&n.length===0)&&!r){a?.(!1,``),f?.(!1,``),e(t,n),_(``);for(let e of v)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);y([]),b.current&&(b.current.style.height=`auto`)}},[g,v,r,e,a,f]),O=(0,U.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),D())},[D]),k=(0,U.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.match(/(?:^|\s)\/(\S*)$/);if(r&&S.current.length>0){a?.(!0,r[1]??``),f?.(!1,``);return}let i=n.match(/@(\S*)$/);if(i&&C.current.length>0){f?.(!0,i[1]??``),a?.(!1,``);return}a?.(!1,``),f?.(!1,``)},[a,f]),A=(0,U.useCallback)(e=>{_(e),setTimeout(()=>{k(e,b.current?.selectionStart??e.length)},0)},[k]),j=(0,U.useCallback)(()=>{let e=b.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,160)+`px`)},[]),M=(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(),T(n))},[T]),N=(0,U.useCallback)(e=>{e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length>0&&T(t)},[T]),P=(0,U.useCallback)(e=>{e.preventDefault()},[]),F=(0,U.useCallback)(()=>{x.current?.click()},[]),I=(0,U.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&T(t),e.target.value=``},[T]),L=g.trim().length>0||v.some(e=>e.status===`ready`),R=t&&!L;return(0,G.jsxs)(`div`,{className:`border-t border-border bg-background`,children:[(0,G.jsx)(Ie,{attachments:v,onRemove:E}),(0,G.jsxs)(`div`,{className:`flex items-end gap-2 p-3`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:F,disabled:r,className:`flex items-center justify-center rounded-lg p-2 text-text-subtle hover:text-text-primary hover:bg-surface transition-colors shrink-0 disabled:opacity-50`,"aria-label":`Attach file`,children:(0,G.jsx)(z,{className:`size-4`})}),(0,G.jsx)(`input`,{ref:x,type:`file`,multiple:!0,className:`hidden`,onChange:I}),(0,G.jsx)(`textarea`,{ref:b,value:g,onChange:e=>{A(e.target.value),j()},onKeyDown:O,onPaste:M,onDrop:N,onDragOver:P,placeholder:t?`Follow-up or Stop...`:`Message... (↵ to send)`,disabled:r,rows:1,className:`flex-1 resize-none rounded-lg border border-border bg-surface px-3 py-2 text-base md:text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-ring disabled:opacity-50 max-h-40`}),R?(0,G.jsx)(`button`,{onClick:n,className:`flex items-center justify-center rounded-lg bg-red-600 p-2 text-white hover:bg-red-500 transition-colors shrink-0`,"aria-label":`Stop response`,children:(0,G.jsx)(te,{className:`size-4`})}):(0,G.jsx)(`button`,{onClick:D,disabled:r||!L,className:`flex items-center justify-center rounded-lg bg-primary p-2 text-white hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,"aria-label":`Send message`,children:(0,G.jsx)(B,{className:`size-4`})})]})]})}function Be({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,G.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,G.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,G.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,G.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`skill`?(0,G.jsx)(H,{className:`size-4 text-amber-500`}):(0,G.jsx)(D,{className:`size-4 text-blue-500`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,G.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,G.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`user`?`global`:e.type})]}),e.description&&(0,G.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]},`${e.type}-${e.name}`))})})}function Ve(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function He(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function Ue(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=Ue(t);return(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,G.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,children:[`↻ `,r]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all ${He(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${Ve(n)}`,children:[n,`%`]})]})]})}function We(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 Ge({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastUpdatedAt:a}){if(!t)return null;let o=e.queryCostUsd!=null||e.totalCostUsd!=null,s=e.session||e.weekly||e.weeklyOpus||e.weeklySonnet;return(0,G.jsxs)(`div`,{className:`border-b border-border bg-surface px-3 py-2.5 space-y-2.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage Limits`}),a&&(0,G.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:We(a)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r&&(0,G.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,G.jsx)(p,{className:`size-3 ${i?`animate-spin`:``}`})}),(0,G.jsx)(`button`,{onClick:n,className:`text-xs text-text-subtle hover:text-text-primary px-1`,children:`✕`})]})]}),s?(0,G.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,G.jsx)($,{label:`5-Hour Session`,bucket:e.session}),(0,G.jsx)($,{label:`Weekly`,bucket:e.weekly}),(0,G.jsx)($,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,G.jsx)($,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,G.jsxs)(`p`,{className:`text-xs text-text-subtle`,children:[`No data — run `,(0,G.jsx)(`code`,{className:`bg-surface-elevated px-1 rounded`,children:`bun install`})]}),o&&(0,G.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,G.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,G.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]})]})}function Ke(e){try{return new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}catch{return``}}function qe(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function Je({projectName:e,usageInfo:t,usageLoading:n,refreshUsage:r,lastUpdatedAt:i,sessionId:a,onSelectSession:o,onBugReport:l,isConnected:u,onReconnect:f}){let[m,h]=(0,U.useState)(null),[g,_]=(0,U.useState)([]),[v,S]=(0,U.useState)(!1),[C,w]=(0,U.useState)(``),T=d(e=>e.openTab),D=e=>{h(t=>t===e?null:e)},O=(0,U.useCallback)(async()=>{if(e){S(!0);try{_(await c.get(`${s(e)}/chat/sessions`))}catch{}finally{S(!1)}}},[e]);(0,U.useEffect)(()=>{m===`history`&&g.length===0&&O()},[m]);function k(t){o?(o(t),h(null)):T({type:`chat`,title:t.title||`Chat`,projectId:e??null,metadata:{projectName:e,sessionId:t.id},closable:!0})}let j=C.trim()?g.filter(e=>(e.title||``).toLowerCase().includes(C.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?qe(Math.max(M??0,N??0)):`text-text-subtle`;return(0,G.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,G.jsxs)(`button`,{onClick:()=>D(`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,G.jsx)(I,{className:`size-3`}),(0,G.jsx)(`span`,{children:`History`})]}),(0,G.jsx)(`button`,{onClick:()=>D(`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,G.jsx)(V,{className:`size-3`})}),(0,G.jsxs)(`button`,{onClick:()=>D(`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,G.jsx)(A,{className:`size-3`}),(0,G.jsxs)(`span`,{children:[`5h:`,M==null?`--%`:`${M}%`]}),(0,G.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,G.jsxs)(`span`,{children:[`Wk:`,N==null?`--%`:`${N}%`]})]}),(0,G.jsx)(`div`,{className:`flex-1`}),a&&l&&(0,G.jsx)(`button`,{onClick:l,className:`p-1 rounded hover:bg-surface-elevated text-text-subtle hover:text-text-secondary transition-colors`,title:`Report bug`,children:(0,G.jsx)(E,{className:`size-3`})}),f&&(0,G.jsx)(`button`,{onClick:f,className:`size-4 flex items-center justify-center`,title:u?`Connected`:`Disconnected — click to reconnect`,children:(0,G.jsx)(`span`,{className:`size-2 rounded-full ${u?`bg-green-500`:`bg-red-500 animate-pulse`}`})})]}),m===`history`&&(0,G.jsxs)(`div`,{className:`border-t border-border/30 bg-surface`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 border-b border-border/30`,children:[(0,G.jsx)(y,{className:`size-3 text-text-subtle shrink-0`}),(0,G.jsx)(`input`,{type:`text`,value:C,onChange:e=>w(e.target.value),placeholder:`Search sessions...`,className:`flex-1 bg-transparent text-[11px] text-text-primary outline-none placeholder:text-text-subtle`}),(0,G.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,G.jsx)(p,{className:`size-3 ${v?`animate-spin`:``}`})})]}),(0,G.jsx)(`div`,{className:`max-h-[200px] overflow-y-auto`,children:v&&g.length===0?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,G.jsx)(b,{className:`size-3.5 animate-spin text-text-subtle`})}):j.length===0?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-3 text-[11px] text-text-subtle`,children:C?`No matching sessions`:`No sessions yet`}):j.map(e=>(0,G.jsxs)(`button`,{onClick:()=>k(e),className:`flex items-center gap-2 w-full px-3 py-1.5 text-left hover:bg-surface-elevated transition-colors`,children:[(0,G.jsx)(E,{className:`size-3 shrink-0 text-text-subtle`}),(0,G.jsx)(`span`,{className:`text-[11px] truncate flex-1`,children:e.title||`Untitled`}),e.updatedAt&&(0,G.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:Ke(e.updatedAt)})]},e.id))})]}),m===`config`&&(0,G.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2 max-h-[280px] overflow-y-auto`,children:(0,G.jsx)(x,{compact:!0})}),m===`usage`&&(0,G.jsx)(Ge,{usage:t,visible:!0,onClose:()=>h(null),onReload:r,loading:n,lastUpdatedAt:i})]})}function Ye({metadata:e,tabId:t}){let[n,r]=(0,U.useState)(e?.sessionId??null),[o,u]=(0,U.useState)(e?.providerId??`claude`),[f,p]=(0,U.useState)([]),[m,h]=(0,U.useState)(!1),[g,_]=(0,U.useState)(``),[v,y]=(0,U.useState)(null),[b,x]=(0,U.useState)([]),[S,E]=(0,U.useState)(!1),[D,k]=(0,U.useState)(``),[A,j]=(0,U.useState)(null),[M,N]=(0,U.useState)(null),[P,F]=(0,U.useState)(!1),[I,L]=(0,U.useState)(!1),[R,z]=(0,U.useState)(null),B=(0,U.useRef)(0),V=e?.projectName??``,ee=d(e=>e.updateTab),H=l(e=>e.version),{usageInfo:te,usageLoading:re,lastUpdatedAt:ie,refreshUsage:ae,mergeUsage:oe}=ce(V,o);(0,U.useEffect)(()=>{!t||!n||ee(t,{metadata:{...e,sessionId:n,providerId:o}})},[n,o]);let{messages:W,messagesLoading:K,isStreaming:q,pendingApproval:le,sendMessage:J,respondToApproval:Y,cancelStreaming:ue,reconnect:de,refetchMessages:fe,isConnected:X}=se(n,o,V,{onUsageEvent:oe});(0,U.useCallback)(()=>{d.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:V},projectId:V||null,closable:!0})},[V]);let pe=(0,U.useCallback)(e=>{r(e.id),u(e.providerId)},[]),Z=(0,U.useCallback)((e,t)=>{if(t.length===0)return e;let n=t.filter(e=>e.serverPath).map(e=>e.serverPath).join(`
|
|
6
|
-
`);return n?(t.length===1?`[Attached file: ${n}]\n\n`:`[Attached files:\n${n}\n]\n\n`)+e:e},[]),he=(0,U.useCallback)(async(e,t=[])=>{let i=Z(e,t);if(i.trim()){if(!n)try{let t=V,n=await c.post(`${s(t)}/chat/sessions`,{providerId:o,title:e.slice(0,50)});r(n.id),u(n.providerId),setTimeout(()=>{J(i)},500);return}catch(e){console.error(`Failed to create session:`,e);return}J(i)}},[n,o,V,J,Z]),ge=(0,U.useCallback)((e,t)=>{h(e),_(t)},[]),_e=(0,U.useCallback)(e=>{y(e),h(!1),_(``),setTimeout(()=>y(null),50)},[]),Q=(0,U.useCallback)(()=>{h(!1),_(``)},[]),ve=(0,U.useCallback)((e,t)=>{E(e),k(t)},[]),ye=(0,U.useCallback)(e=>{j(e),E(!1),k(``),setTimeout(()=>j(null),50)},[]),be=(0,U.useCallback)(()=>{E(!1),k(``)},[]);return(0,G.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,U.useCallback)(e=>{e.preventDefault(),B.current++,e.dataTransfer.types.includes(`Files`)&&L(!0)},[]),onDragLeave:(0,U.useCallback)(e=>{e.preventDefault(),B.current--,B.current===0&&L(!1)},[]),onDragOver:(0,U.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,U.useCallback)(e=>{e.preventDefault(),B.current=0,L(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&(z(t),setTimeout(()=>z(null),100))},[]),children:[I&&(0,G.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,G.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-primary`,children:[(0,G.jsx)(ne,{className:`size-8`}),(0,G.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),(0,G.jsx)(me,{messages:W,messagesLoading:K,pendingApproval:le,onApprovalResponse:Y,isStreaming:q,projectName:V}),(0,G.jsxs)(`div`,{className:`border-t border-border bg-background shrink-0`,children:[(0,G.jsx)(Je,{projectName:V,usageInfo:te,usageLoading:re,refreshUsage:ae,lastUpdatedAt:ie,sessionId:n,onSelectSession:pe,onBugReport:n?async()=>{N(await T(H,{sessionId:n,projectName:V})),F(!1)}:void 0,isConnected:X,onReconnect:()=>{X||de(),fe()}}),(0,G.jsx)(Be,{items:f,filter:g,onSelect:_e,onClose:Q,visible:m}),(0,G.jsx)(Re,{items:b,filter:D,onSelect:ye,onClose:be,visible:S}),(0,G.jsx)(ze,{onSend:he,isStreaming:q,onCancel:ue,projectName:V,onSlashStateChange:ge,onSlashItemsLoaded:p,slashSelected:v,onFileStateChange:ve,onFileItemsLoaded:x,fileSelected:A,externalFiles:R})]}),M&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/50`,onClick:()=>N(null)}),(0,G.jsxs)(`div`,{className:`fixed inset-x-4 top-[10%] bottom-[10%] z-50 mx-auto max-w-lg flex flex-col rounded-lg border border-border bg-background shadow-xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium`,children:`Bug Report`}),(0,G.jsx)(`button`,{onClick:()=>N(null),className:`p-1 rounded hover:bg-surface-elevated`,children:(0,G.jsx)(O,{className:`size-4`})})]}),(0,G.jsx)(`pre`,{className:`flex-1 overflow-auto px-4 py-2 text-xs font-mono whitespace-pre-wrap break-all`,children:M}),(0,G.jsxs)(`div`,{className:`flex gap-2 px-4 py-3 border-t border-border`,children:[(0,G.jsxs)(`button`,{onClick:async()=>{await C(M)&&F(!0)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 text-sm rounded-lg bg-surface hover:bg-surface-elevated border border-border transition-colors`,children:[(0,G.jsx)(i,{className:`size-4`}),P?`Copied!`:`Copy`]}),(0,G.jsxs)(`button`,{onClick:()=>{w(M),N(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 text-sm rounded-lg bg-primary text-white hover:bg-primary/90 transition-colors`,children:[(0,G.jsx)(a,{className:`size-4`}),`GitHub Issue`]})]})]})]})]})}export{Ye as ChatTab};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as e,n as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{t as i}from"./external-link-CrtbmtJ6.js";import{n as a,r as o,t as s}from"./api-client-BsHoRDAn.js";import{n as c}from"./settings-store-DWYkr_a3.js";import{t as l}from"./tab-store-B1wzyDLQ.js";import{T as u}from"./index-D27GI6gs.js";import{t as d}from"./markdown-renderer-DdDDhQDx.js";import{n as f,t as p}from"./use-monaco-theme-Bb9W0CI2.js";var m=t(`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=e(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,a]=(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}=l(),{wordWrap:F,toggleWordWrap:I}=c(),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)}`:`${o(r)}/files/read?path=${encodeURIComponent(n)}`;return s.get(e).then(e=>{a(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 s.put(`/api/fs/write`,{path:n,content:e}):await s.put(`${o(r)}/files/write`,{path:n,content:e}),k(!1)}catch{}},[n,r,G]);function q(e){let t=e??``;a(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,()=>c.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,s]=(0,h.useState)(!1);return(0,h.useEffect)(()=>{let n,i=`${o(t)}/files/raw?path=${encodeURIComponent(e)}`,c=a();return fetch(i,{headers:c?{Authorization:`Bearer ${c}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(e);n=t,r(t)}).catch(()=>s(!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),[s,c]=(0,h.useState)(!1);(0,h.useEffect)(()=>{let n,i=`${o(t)}/files/raw?path=${encodeURIComponent(e)}`,s=a();return fetch(i,{headers:s?{Authorization:`Bearer ${s}`}:{}}).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(()=>c(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]);let l=(0,h.useCallback)(()=>{n&&window.open(n,`_blank`)},[n]);return s?(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 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./jsx-runtime-BFALxl05.js";var t=e(`copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]);export{t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./jsx-runtime-BFALxl05.js";var t=e(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]);export{t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as e,n as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{t as i}from"./input-AESbQWjx.js";import{t as a}from"./copy-BNk4Z75P.js";import{t as o}from"./external-link-CrtbmtJ6.js";import{r as s,t as c}from"./api-client-BsHoRDAn.js";import{t as l}from"./tab-store-B1wzyDLQ.js";import{C as u,D as d,E as f,I as p,T as m,b as h,c as g,d as _,f as v,g as y,h as b,l as ee,m as x,o as te,p as S,s as ne,u as re}from"./index-D27GI6gs.js";var ie=t(`cherry`,[[`path`,{d:`M2 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`cvxqlc`}],[`path`,{d:`M12 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`1ostrc`}],[`path`,{d:`M7 14c3.22-2.91 4.29-8.75 5-12 1.66 2.38 4.94 9 5 12`,key:`hqx58h`}],[`path`,{d:`M22 9c-4.29 0-7.14-2.33-10-7 5.71 0 10 4.67 10 7Z`,key:`eykp1o`}]]),C=t(`git-merge`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]),ae=t(`rotate-ccw`,[[`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`}]]),w=t(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]),T=e(n(),1),E=r(),D=[`#4fc3f7`,`#81c784`,`#ffb74d`,`#e57373`,`#ba68c8`,`#4dd0e1`,`#aed581`,`#ff8a65`,`#f06292`,`#7986cb`],O=32,k=20,oe=5;function A({metadata:e}){let t=e?.projectName,[n,r]=(0,T.useState)(null),[o,p]=(0,T.useState)(!0),[h,C]=(0,T.useState)(null),[A,j]=(0,T.useState)(!1),[M,N]=(0,T.useState)({type:null}),[P,F]=(0,T.useState)(``),[I,L]=(0,T.useState)(null),[R,z]=(0,T.useState)([]),[ce,B]=(0,T.useState)(!1),{openTab:V}=l(),H=(0,T.useCallback)(async()=>{if(t)try{p(!0),r(await c.get(`${s(t)}/git/graph?max=200`)),C(null)}catch(e){C(e instanceof Error?e.message:`Failed to fetch graph`)}finally{p(!1)}},[t]);(0,T.useEffect)(()=>{H();let e=setInterval(H,1e4);return()=>clearInterval(e)},[H]);let U=async(e,n)=>{if(t){j(!0);try{await c.post(`${s(t)}${e}`,n),await H()}catch(e){C(e instanceof Error?e.message:`Action failed`)}finally{j(!1)}}},W=e=>U(`/git/checkout`,{ref:e}),le=e=>U(`/git/cherry-pick`,{hash:e}),ue=e=>U(`/git/revert`,{hash:e}),de=e=>U(`/git/merge`,{source:e}),fe=e=>U(`/git/branch/delete`,{name:e}),pe=e=>U(`/git/push`,{branch:e}),G=async(e,t)=>{if(n?.branches.some(t=>t.name===e||t.name.endsWith(`/${e}`))){if(!window.confirm(`Branch "${e}" already exists.\nDelete it and recreate from this commit?`))return;await U(`/git/branch/delete`,{name:e})}await U(`/git/branch/create`,{name:e,from:t})},K=(e,t)=>U(`/git/tag`,{name:e,hash:t}),me=async e=>{if(t)try{let n=await c.get(`${s(t)}/git/pr-url?branch=${encodeURIComponent(e)}`);n.url&&window.open(n.url,`_blank`)}catch{}},q=e=>{navigator.clipboard.writeText(e)},he=async e=>{if(I?.hash===e.hash){L(null);return}L(e),B(!0);try{let n=e.parents[0]??``,r=n?`ref1=${encodeURIComponent(n)}&`:``,i=await c.get(`${s(t)}/git/diff-stat?${r}ref2=${encodeURIComponent(e.hash)}`);z(Array.isArray(i)?i:[])}catch(e){console.error(`diff-stat error:`,e),z([])}finally{B(!1)}},ge=e=>{let n=e.parents[0];V({type:`git-diff`,title:`Diff ${e.abbreviatedHash}`,closable:!0,metadata:{projectName:t,ref1:n??void 0,ref2:e.hash},projectId:t??null})},{laneMap:J,maxLane:_e}=(0,T.useMemo)(()=>{let e=new Map;if(!n)return{laneMap:e,maxLane:0};let t=0,r=new Map;for(let i of n.commits){let n=r.get(i.hash);n===void 0&&(n=t++),e.set(i.hash,n),r.delete(i.hash);for(let e=0;e<i.parents.length;e++){let a=i.parents[e];r.has(a)||r.set(a,e===0?n:t++)}}return{laneMap:e,maxLane:Math.max(t-1,0)}},[n]),Y=n?.branches.find(e=>e.current),ve=(0,T.useMemo)(()=>{let e=new Map;if(!n)return e;for(let t of n.branches){let n=e.get(t.commitHash)??[];n.push({name:t.name,type:`branch`}),e.set(t.commitHash,n)}for(let t of n.commits)for(let n of t.refs)if(n.startsWith(`tag: `)){let r=n.replace(`tag: `,``),i=e.get(t.hash)??[];i.push({name:r,type:`tag`}),e.set(t.hash,i)}return e},[n]),ye=(0,T.useMemo)(()=>{if(!n)return[];let e=[];for(let t=0;t<n.commits.length;t++){let r=n.commits[t],i=J.get(r.hash)??0,a=D[i%D.length];for(let o of r.parents){let s=n.commits.findIndex(e=>e.hash===o);if(s<0)continue;let c=J.get(o)??0,l=D[c%D.length],u=i*k+k/2,d=t*O+O/2,f=c*k+k/2,p=s*O+O/2,m,h=r.parents.indexOf(o)>0;if(u===f)m=`M ${u} ${d} L ${f} ${p}`;else if(h){let e=d+O;m=`M ${u} ${d} C ${u} ${e} ${f} ${d} ${f} ${e} L ${f} ${p}`}else{let e=p-O;m=`M ${u} ${d} L ${u} ${e} C ${u} ${p} ${f} ${e} ${f} ${p}`}let g=r.parents.indexOf(o)===0?a:l;e.push({d:m,color:g})}}return e},[n,J]);(_e+1)*k+k;let X=(n?.commits.length??0)*O,[Z,be]=(0,T.useState)((typeof window<`u`&&window.innerWidth<768?6:10)*k+k),Q=(0,T.useRef)(!1),$=(0,T.useCallback)(e=>{Q.current=!0;let t=Z,n=n=>{if(!Q.current)return;let r=`touches`in n?n.touches[0].clientX:n.clientX;be(Math.max(40,t+r-e))},r=()=>{Q.current=!1,window.removeEventListener(`mousemove`,n),window.removeEventListener(`mouseup`,r),window.removeEventListener(`touchmove`,n),window.removeEventListener(`touchend`,r)};window.addEventListener(`mousemove`,n),window.addEventListener(`mouseup`,r),window.addEventListener(`touchmove`,n,{passive:!1}),window.addEventListener(`touchend`,r)},[Z]),xe=(0,T.useCallback)(e=>{e.preventDefault(),$(e.clientX)},[$]),Se=(0,T.useCallback)(e=>{$(e.touches[0].clientX)},[$]);if(!t)return(0,E.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`});if(o&&!n)return(0,E.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,E.jsx)(m,{className:`size-5 animate-spin`}),(0,E.jsx)(`span`,{className:`text-sm`,children:`Loading git graph...`})]});if(h&&!n)return(0,E.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-destructive text-sm`,children:[(0,E.jsx)(`p`,{children:h}),(0,E.jsx)(_,{variant:`outline`,size:`sm`,onClick:H,children:`Retry`})]});function Ce(e){let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}return(0,E.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b`,children:[(0,E.jsxs)(`span`,{className:`text-sm font-medium`,children:[`Git Graph`,Y?` - ${Y.name}`:``]}),(0,E.jsx)(_,{variant:`ghost`,size:`icon-xs`,onClick:H,disabled:A,children:(0,E.jsx)(u,{className:o?`animate-spin`:``})})]}),h&&(0,E.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-destructive bg-destructive/10`,children:h}),(0,E.jsx)(`div`,{className:`flex-1 overflow-y-auto overflow-x-auto md:overflow-x-hidden`,children:(0,E.jsxs)(`div`,{className:`flex min-w-max md:min-w-0`,style:{height:`${X}px`},children:[(0,E.jsxs)(`div`,{className:`sticky left-0 z-10 shrink-0 bg-background`,style:{width:`${Z}px`},children:[(0,E.jsxs)(`svg`,{width:Z,height:X,children:[ye.map((e,t)=>(0,E.jsx)(`path`,{d:e.d,stroke:e.color,strokeWidth:2,fill:`none`},t)),n?.commits.map((e,t)=>{let n=J.get(e.hash)??0,r=n*k+k/2,i=t*O+O/2,a=D[n%D.length];return(0,E.jsx)(`circle`,{cx:r,cy:i,r:oe,fill:a,stroke:`#0f1419`,strokeWidth:2},e.hash)})]}),(0,E.jsx)(`div`,{className:`absolute top-0 right-0 w-3 md:w-2 h-full cursor-col-resize hover:bg-primary/20 flex items-center justify-center bg-primary/10 md:bg-transparent`,onMouseDown:xe,onTouchStart:Se,children:(0,E.jsx)(f,{className:`size-3 text-muted-foreground md:opacity-0 md:hover:opacity-100`})})]}),(0,E.jsx)(`div`,{className:`flex-1 min-w-[400px]`,children:n?.commits.map((e,t)=>{let n=D[(J.get(e.hash)??0)%D.length],r=ve.get(e.hash)??[],i=r.filter(e=>e.type===`branch`),o=r.filter(e=>e.type===`tag`);return(0,E.jsxs)(v,{children:[(0,E.jsx)(y,{asChild:!0,children:(0,E.jsx)(`div`,{className:`flex items-center hover:bg-muted/50 cursor-pointer text-sm border-b border-border/30 ${I?.hash===e.hash?`bg-primary/10`:``}`,style:{height:`${O}px`},onClick:()=>he(e),children:(0,E.jsxs)(`div`,{className:`flex items-center gap-2 flex-1 min-w-0 px-2`,children:[(0,E.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground w-14 shrink-0`,children:e.abbreviatedHash}),i.map(e=>(0,E.jsx)(se,{label:e,color:n,currentBranch:Y,onCheckout:W,onMerge:de,onPush:pe,onCreatePr:me,onDelete:fe},`branch-${e.name}`)),o.map(e=>(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 bg-amber-500/20 text-amber-500 border border-amber-500/30`,children:[(0,E.jsx)(w,{className:`size-2.5`}),e.name]},`tag-${e.name}`)),(0,E.jsx)(`span`,{className:`flex-1 truncate`,children:e.subject}),(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0 hidden sm:inline`,children:e.authorName}),(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0 w-14 text-right`,children:Ce(e.authorDate)})]})})}),(0,E.jsxs)(S,{children:[(0,E.jsx)(x,{onClick:()=>W(e.hash),children:`Checkout`}),(0,E.jsxs)(x,{onClick:()=>{N({type:`branch`,hash:e.hash}),F(``)},children:[(0,E.jsx)(d,{className:`size-3`}),`Create Branch...`]}),(0,E.jsx)(b,{}),(0,E.jsxs)(x,{onClick:()=>le(e.hash),children:[(0,E.jsx)(ie,{className:`size-3`}),`Cherry Pick`]}),(0,E.jsxs)(x,{onClick:()=>ue(e.hash),children:[(0,E.jsx)(ae,{className:`size-3`}),`Revert`]}),(0,E.jsxs)(x,{onClick:()=>{N({type:`tag`,hash:e.hash}),F(``)},children:[(0,E.jsx)(w,{className:`size-3`}),`Create Tag...`]}),(0,E.jsx)(b,{}),(0,E.jsx)(x,{onClick:()=>ge(e),children:`View Diff`}),(0,E.jsxs)(x,{onClick:()=>q(e.hash),children:[(0,E.jsx)(a,{className:`size-3`}),`Copy Hash`]})]})]},e.hash)})})]})}),I&&(0,E.jsxs)(`div`,{className:`border-t bg-muted/30 max-h-[40%] overflow-auto`,children:[(0,E.jsxs)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:[(0,E.jsxs)(`span`,{className:`text-sm font-medium truncate`,children:[I.abbreviatedHash,` — `,I.subject]}),(0,E.jsx)(_,{variant:`ghost`,size:`icon-xs`,onClick:()=>L(null),children:`✕`})]}),(0,E.jsxs)(`div`,{className:`px-3 py-2 text-xs space-y-1`,children:[(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Author`}),(0,E.jsxs)(`span`,{children:[I.authorName,` <`,I.authorEmail,`>`]})]}),(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Date`}),(0,E.jsx)(`span`,{children:new Date(I.authorDate).toLocaleString()})]}),(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Hash`}),(0,E.jsx)(`span`,{className:`font-mono cursor-pointer hover:text-primary`,onClick:()=>q(I.hash),children:I.hash})]}),I.parents.length>0&&(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Parents`}),(0,E.jsx)(`span`,{className:`font-mono`,children:I.parents.map(e=>e.slice(0,7)).join(`, `)})]}),I.body&&(0,E.jsx)(`div`,{className:`mt-2 p-2 bg-background rounded text-xs whitespace-pre-wrap`,children:I.body})]}),(0,E.jsxs)(`div`,{className:`px-3 py-1 border-t`,children:[(0,E.jsx)(`div`,{className:`text-xs text-muted-foreground py-1`,children:ce?`Loading files...`:`${R.length} file${R.length===1?``:`s`} changed`}),R.map(e=>(0,E.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5 text-xs hover:bg-muted/50 rounded px-1 cursor-pointer`,onClick:()=>V({type:`git-diff`,title:`Diff ${e.path.split(`/`).pop()}`,closable:!0,metadata:{projectName:t,ref1:I.parents[0]??void 0,ref2:I.hash,filePath:e.path},projectId:t??null}),children:[(0,E.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:e.path}),e.additions>0&&(0,E.jsxs)(`span`,{className:`text-green-500`,children:[`+`,e.additions]}),e.deletions>0&&(0,E.jsxs)(`span`,{className:`text-red-500`,children:[`-`,e.deletions]})]},e.path))]})]}),(0,E.jsx)(te,{open:M.type!==null,onOpenChange:e=>{e||N({type:null})},children:(0,E.jsxs)(ne,{children:[(0,E.jsx)(ee,{children:(0,E.jsx)(re,{children:M.type===`branch`?`Create Branch`:`Create Tag`})}),(0,E.jsx)(i,{placeholder:M.type===`branch`?`Branch name`:`Tag name`,value:P,onChange:e=>F(e.target.value),onKeyDown:e=>{e.key===`Enter`&&P.trim()&&(M.type===`branch`?G(P.trim(),M.hash):K(P.trim(),M.hash),N({type:null}))},autoFocus:!0}),(0,E.jsxs)(g,{children:[(0,E.jsx)(_,{variant:`outline`,onClick:()=>N({type:null}),children:`Cancel`}),(0,E.jsx)(_,{disabled:!P.trim(),onClick:()=>{M.type===`branch`?G(P.trim(),M.hash):K(P.trim(),M.hash),N({type:null})},children:`Create`})]})]})})]})}function se({label:e,color:t,currentBranch:n,onCheckout:r,onMerge:i,onPush:a,onCreatePr:s,onDelete:c}){return(0,E.jsxs)(v,{children:[(0,E.jsx)(y,{asChild:!0,children:(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 cursor-context-menu`,style:{backgroundColor:`${t}30`,color:t,border:`1px solid ${t}50`},children:[(0,E.jsx)(d,{className:`size-2.5`}),e.name]})}),(0,E.jsxs)(S,{children:[(0,E.jsx)(x,{onClick:()=>r(e.name),children:`Checkout`}),(0,E.jsxs)(x,{onClick:()=>i(e.name),disabled:e.name===n?.name,children:[(0,E.jsx)(C,{className:`size-3`}),`Merge into current`]}),(0,E.jsx)(b,{}),(0,E.jsxs)(x,{onClick:()=>a(e.name),children:[(0,E.jsx)(p,{className:`size-3`}),`Push`]}),(0,E.jsxs)(x,{onClick:()=>s(e.name),children:[(0,E.jsx)(o,{className:`size-3`}),`Create PR`]}),(0,E.jsx)(b,{}),(0,E.jsxs)(x,{variant:`destructive`,onClick:()=>c(e.name),disabled:e.name===n?.name,children:[(0,E.jsx)(h,{className:`size-3`}),`Delete`]})]})]})}export{A as GitGraph};
|