@hienlh/ppm 0.6.7 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +86 -313
  3. package/dist/web/assets/chat-tab-CbNbBMGw.js +7 -0
  4. package/dist/web/assets/{code-editor-BUg7alP6.js → code-editor-D6OuzcC-.js} +1 -1
  5. package/dist/web/assets/{database-viewer-CAgZOkZc.js → database-viewer-BxUpM_uA.js} +1 -1
  6. package/dist/web/assets/{diff-viewer-DVvY1aFb.js → diff-viewer-DAhrHpNM.js} +1 -1
  7. package/dist/web/assets/{dist-Jb3Tnkpc.js → dist-CNRrBoQi.js} +14 -14
  8. package/dist/web/assets/git-graph-BpTt5iOd.js +1 -0
  9. package/dist/web/assets/index-BU_07_oW.js +29 -0
  10. package/dist/web/assets/index-CBQhXXeV.css +2 -0
  11. package/dist/web/assets/keybindings-store-C0m8_V9X.js +1 -0
  12. package/dist/web/assets/{markdown-renderer-z99RjIxZ.js → markdown-renderer-CvGYO9sH.js} +2 -2
  13. package/dist/web/assets/postgres-viewer-BL99auSm.js +1 -0
  14. package/dist/web/assets/{settings-tab-BnDkeQWk.js → settings-tab-Bwsxb41F.js} +1 -1
  15. package/dist/web/assets/{sqlite-viewer-EwHWc37J.js → sqlite-viewer-DfgaCbWT.js} +1 -1
  16. package/dist/web/assets/{terminal-tab-CTN18lb6.js → terminal-tab-D27e4ZTD.js} +2 -2
  17. package/dist/web/index.html +4 -3
  18. package/dist/web/sw.js +1 -1
  19. package/package.json +1 -1
  20. package/src/lib/network-utils.ts +12 -0
  21. package/src/providers/claude-agent-sdk.ts +61 -3
  22. package/src/server/routes/chat.ts +5 -1
  23. package/src/server/routes/settings.ts +52 -0
  24. package/src/server/routes/tunnel.ts +1 -12
  25. package/src/server/ws/chat.ts +42 -12
  26. package/src/services/config.service.ts +1 -1
  27. package/src/services/notification.service.ts +42 -0
  28. package/src/services/telegram-notification.service.ts +106 -0
  29. package/src/types/config.ts +6 -0
  30. package/src/web/app.tsx +40 -1
  31. package/src/web/components/layout/draggable-tab.tsx +10 -2
  32. package/src/web/components/layout/mobile-nav.tsx +42 -3
  33. package/src/web/components/layout/project-bar.tsx +16 -8
  34. package/src/web/components/layout/tab-bar.tsx +55 -4
  35. package/src/web/components/settings/settings-tab.tsx +135 -94
  36. package/src/web/components/settings/telegram-settings-section.tsx +113 -0
  37. package/src/web/components/ui/accordion.tsx +64 -0
  38. package/src/web/hooks/use-chat.ts +29 -0
  39. package/src/web/hooks/use-notification-badge.ts +20 -0
  40. package/src/web/hooks/use-tab-overflow.ts +91 -0
  41. package/src/web/hooks/use-url-sync.ts +5 -2
  42. package/src/web/index.html +1 -0
  43. package/src/web/lib/favicon.ts +21 -0
  44. package/src/web/lib/notification-sounds.ts +61 -0
  45. package/src/web/stores/notification-store.ts +83 -0
  46. package/dist/web/assets/chat-tab-CWhxhPKH.js +0 -7
  47. package/dist/web/assets/git-graph-xD6TLRVv.js +0 -1
  48. package/dist/web/assets/index-CigdXBuQ.css +0 -2
  49. package/dist/web/assets/index-DBdw8tN_.js +0 -22
  50. package/dist/web/assets/keybindings-store-kHLASnRb.js +0 -1
  51. package/dist/web/assets/postgres-viewer-CaMySHpD.js +0 -1
  52. /package/dist/web/assets/{tab-store-DIyJSjtr.js → tab-store-Bm1Hw8OR.js} +0 -0
@@ -0,0 +1,64 @@
1
+ import * as React from "react"
2
+ import { ChevronDownIcon } from "lucide-react"
3
+ import { Accordion as AccordionPrimitive } from "radix-ui"
4
+
5
+ import { cn } from "@/lib/utils"
6
+
7
+ function Accordion({
8
+ ...props
9
+ }: React.ComponentProps<typeof AccordionPrimitive.Root>) {
10
+ return <AccordionPrimitive.Root data-slot="accordion" {...props} />
11
+ }
12
+
13
+ function AccordionItem({
14
+ className,
15
+ ...props
16
+ }: React.ComponentProps<typeof AccordionPrimitive.Item>) {
17
+ return (
18
+ <AccordionPrimitive.Item
19
+ data-slot="accordion-item"
20
+ className={cn("border-b last:border-b-0", className)}
21
+ {...props}
22
+ />
23
+ )
24
+ }
25
+
26
+ function AccordionTrigger({
27
+ className,
28
+ children,
29
+ ...props
30
+ }: React.ComponentProps<typeof AccordionPrimitive.Trigger>) {
31
+ return (
32
+ <AccordionPrimitive.Header className="flex">
33
+ <AccordionPrimitive.Trigger
34
+ data-slot="accordion-trigger"
35
+ className={cn(
36
+ "flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180",
37
+ className
38
+ )}
39
+ {...props}
40
+ >
41
+ {children}
42
+ <ChevronDownIcon className="pointer-events-none size-4 shrink-0 translate-y-0.5 text-muted-foreground transition-transform duration-200" />
43
+ </AccordionPrimitive.Trigger>
44
+ </AccordionPrimitive.Header>
45
+ )
46
+ }
47
+
48
+ function AccordionContent({
49
+ className,
50
+ children,
51
+ ...props
52
+ }: React.ComponentProps<typeof AccordionPrimitive.Content>) {
53
+ return (
54
+ <AccordionPrimitive.Content
55
+ data-slot="accordion-content"
56
+ className="overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
57
+ {...props}
58
+ >
59
+ <div className={cn("pt-0 pb-4", className)}>{children}</div>
60
+ </AccordionPrimitive.Content>
61
+ )
62
+ }
63
+
64
+ export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
@@ -1,6 +1,9 @@
1
1
  import { useState, useCallback, useRef, useEffect } from "react";
2
2
  import { useWebSocket } from "./use-websocket";
3
3
  import { getAuthToken, projectUrl } from "@/lib/api-client";
4
+ import { useNotificationStore } from "@/stores/notification-store";
5
+ import { usePanelStore } from "@/stores/panel-store";
6
+ import { playNotificationSound } from "@/lib/notification-sounds";
4
7
  import type { ChatMessage, ChatEvent } from "../../types/chat";
5
8
  import type { ChatWsServerMessage } from "../../types/api";
6
9
 
@@ -33,6 +36,16 @@ interface UseChatReturn {
33
36
  isConnected: boolean;
34
37
  }
35
38
 
39
+ /** Check if the chat tab for this session is the active foreground tab */
40
+ function isSessionTabActive(sid: string): boolean {
41
+ if (document.hidden) return false;
42
+ const { panels, focusedPanelId } = usePanelStore.getState();
43
+ const panel = panels[focusedPanelId];
44
+ if (!panel) return false;
45
+ const activeTab = panel.tabs.find((t) => t.id === panel.activeTabId);
46
+ return activeTab?.type === "chat" && activeTab.metadata?.sessionId === sid;
47
+ }
48
+
36
49
  export function useChat(sessionId: string | null, providerId = "claude", projectName = ""): UseChatReturn {
37
50
  const [messages, setMessages] = useState<ChatMessage[]>([]);
38
51
  const [messagesLoading, setMessagesLoading] = useState(false);
@@ -52,6 +65,11 @@ export function useChat(sessionId: string | null, providerId = "claude", project
52
65
  const pendingMessageRef = useRef<string | null>(null);
53
66
  const sendRef = useRef<(data: string) => void>(() => {});
54
67
  const refetchRef = useRef<(() => void) | null>(null);
68
+ // Refs for notification dispatch inside handleMessage (which has [] deps)
69
+ const sessionIdRef = useRef(sessionId);
70
+ sessionIdRef.current = sessionId;
71
+ const projectNameRef = useRef(projectName);
72
+ projectNameRef.current = projectName;
55
73
 
56
74
  const handleMessage = useCallback((event: MessageEvent) => {
57
75
  let data: ChatWsServerMessage;
@@ -215,6 +233,12 @@ export function useChat(sessionId: string | null, providerId = "claude", project
215
233
  tool: data.tool,
216
234
  input: data.input,
217
235
  });
236
+ // Local notification badge — only if this tab is NOT active
237
+ if (sessionIdRef.current && !isSessionTabActive(sessionIdRef.current)) {
238
+ const nType = data.tool === "AskUserQuestion" ? "question" : "approval_request";
239
+ useNotificationStore.getState().addNotification(sessionIdRef.current, nType, projectNameRef.current);
240
+ playNotificationSound(nType);
241
+ }
218
242
  break;
219
243
  }
220
244
 
@@ -253,6 +277,11 @@ export function useChat(sessionId: string | null, providerId = "claude", project
253
277
  if (data.contextWindowPct != null) {
254
278
  setContextWindowPct(data.contextWindowPct);
255
279
  }
280
+ // Local notification badge — only if this tab is NOT active
281
+ if (sessionIdRef.current && !isSessionTabActive(sessionIdRef.current)) {
282
+ useNotificationStore.getState().addNotification(sessionIdRef.current, "done", projectNameRef.current);
283
+ playNotificationSound("done");
284
+ }
256
285
  // Finalize the streaming message — capture refs before clearing
257
286
  const finalContent = streamingContentRef.current;
258
287
  const finalEvents = [...streamingEventsRef.current];
@@ -0,0 +1,20 @@
1
+ import { useEffect } from "react";
2
+ import { useNotificationStore, selectTotalUnread } from "@/stores/notification-store";
3
+ import { setFavicon } from "@/lib/favicon";
4
+
5
+ const DEFAULT_TITLE = "PPM — Personal Project Manager";
6
+
7
+ /** Syncs document.title and favicon with unread notification count */
8
+ export function useNotificationBadge(): void {
9
+ const totalUnread = useNotificationStore(selectTotalUnread);
10
+
11
+ useEffect(() => {
12
+ if (totalUnread > 0) {
13
+ document.title = `(${totalUnread}) PPM`;
14
+ setFavicon(true);
15
+ } else {
16
+ document.title = DEFAULT_TITLE;
17
+ setFavicon(false);
18
+ }
19
+ }, [totalUnread]);
20
+ }
@@ -0,0 +1,91 @@
1
+ import { useState, useEffect, useCallback, type RefObject } from "react";
2
+
3
+ interface TabOverflow {
4
+ canScrollLeft: boolean;
5
+ canScrollRight: boolean;
6
+ scrollLeft: () => void;
7
+ scrollRight: () => void;
8
+ }
9
+
10
+ /**
11
+ * Detects overflow on a scrollable tab container and provides scroll helpers.
12
+ * Uses scroll events + ResizeObserver for accurate, performant updates.
13
+ */
14
+ export function useTabOverflow(scrollRef: RefObject<HTMLDivElement | null>): TabOverflow {
15
+ const [canScrollLeft, setCanScrollLeft] = useState(false);
16
+ const [canScrollRight, setCanScrollRight] = useState(false);
17
+
18
+ const updateScroll = useCallback(() => {
19
+ const el = scrollRef.current;
20
+ if (!el) return;
21
+ setCanScrollLeft(el.scrollLeft > 1);
22
+ setCanScrollRight(el.scrollLeft + el.clientWidth < el.scrollWidth - 1);
23
+ }, [scrollRef]);
24
+
25
+ useEffect(() => {
26
+ const el = scrollRef.current;
27
+ if (!el) return;
28
+ updateScroll();
29
+ el.addEventListener("scroll", updateScroll, { passive: true });
30
+ const ro = new ResizeObserver(updateScroll);
31
+ ro.observe(el);
32
+ // Also observe children changes (tabs added/removed)
33
+ const mo = new MutationObserver(updateScroll);
34
+ mo.observe(el, { childList: true, subtree: true });
35
+ return () => {
36
+ el.removeEventListener("scroll", updateScroll);
37
+ ro.disconnect();
38
+ mo.disconnect();
39
+ };
40
+ }, [scrollRef, updateScroll]);
41
+
42
+ const scrollLeft = useCallback(() => {
43
+ scrollRef.current?.scrollBy({ left: -150, behavior: "smooth" });
44
+ }, [scrollRef]);
45
+
46
+ const scrollRight = useCallback(() => {
47
+ scrollRef.current?.scrollBy({ left: 150, behavior: "smooth" });
48
+ }, [scrollRef]);
49
+
50
+ return { canScrollLeft, canScrollRight, scrollLeft, scrollRight };
51
+ }
52
+
53
+ /** Priority for picking most urgent type */
54
+ const TYPE_PRIORITY: Record<string, number> = { done: 0, question: 1, approval_request: 2 };
55
+
56
+ /**
57
+ * Check if any hidden (off-screen) tab has unread notifications.
58
+ * Returns the most urgent notification type per direction (null = none).
59
+ */
60
+ export function getHiddenUnreadDirection(
61
+ scrollEl: HTMLDivElement | null,
62
+ tabRefs: Map<string, HTMLElement>,
63
+ tabs: { id: string; type: string; metadata?: Record<string, unknown> }[],
64
+ notifications: Map<string, { count: number; type: string }>,
65
+ ): { left: string | null; right: string | null } {
66
+ if (!scrollEl) return { left: null, right: null };
67
+ const viewLeft = scrollEl.scrollLeft;
68
+ const viewRight = viewLeft + scrollEl.clientWidth;
69
+ let leftType: string | null = null;
70
+ let leftPri = -1;
71
+ let rightType: string | null = null;
72
+ let rightPri = -1;
73
+
74
+ for (const tab of tabs) {
75
+ if (tab.type !== "chat") continue;
76
+ const sessionId = tab.metadata?.sessionId as string;
77
+ const entry = sessionId ? notifications.get(sessionId) : undefined;
78
+ if (!entry || entry.count === 0) continue;
79
+ const tabEl = tabRefs.get(tab.id);
80
+ if (!tabEl) continue;
81
+ const pri = TYPE_PRIORITY[entry.type] ?? 0;
82
+ if (tabEl.offsetLeft + tabEl.offsetWidth < viewLeft && pri > leftPri) {
83
+ leftPri = pri; leftType = entry.type;
84
+ }
85
+ if (tabEl.offsetLeft > viewRight && pri > rightPri) {
86
+ rightPri = pri; rightType = entry.type;
87
+ }
88
+ }
89
+
90
+ return { left: leftType, right: rightType };
91
+ }
@@ -5,13 +5,16 @@ import { useTabStore } from "@/stores/tab-store";
5
5
  * Parse the current URL to extract project name and tab ID.
6
6
  * Expected format: /project/:projectName/tab/:tabId
7
7
  */
8
- export function parseUrlState(): { projectName: string | null; tabId: string | null } {
8
+ export function parseUrlState(): { projectName: string | null; tabId: string | null; openChat: string | null } {
9
9
  const path = window.location.pathname;
10
10
  const match = path.match(/^\/project\/([^/]+)(?:\/tab\/([^/]+))?/);
11
- if (!match) return { projectName: null, tabId: null };
11
+ const params = new URLSearchParams(window.location.search);
12
+ const openChat = params.get("openChat");
13
+ if (!match) return { projectName: null, tabId: null, openChat };
12
14
  return {
13
15
  projectName: match[1] ? decodeURIComponent(match[1]) : null,
14
16
  tabId: match[2] ? decodeURIComponent(match[2]) : null,
17
+ openChat,
15
18
  };
16
19
  }
17
20
 
@@ -5,6 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
6
6
  <meta name="theme-color" content="#0f1419" />
7
7
  <title>PPM — Personal Project Manager</title>
8
+ <link rel="icon" id="ppm-favicon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2032%2032%22%3E%0A%20%20%3Crect%20width%3D%2232%22%20height%3D%2232%22%20rx%3D%226%22%20fill%3D%22%233b82f6%22%2F%3E%0A%20%20%3Ctext%20x%3D%2216%22%20y%3D%2222%22%20text-anchor%3D%22middle%22%20font-family%3D%22system-ui%2Csans-serif%22%20font-weight%3D%22700%22%20font-size%3D%2211%22%20fill%3D%22white%22%3EPPM%3C%2Ftext%3E%0A%3C%2Fsvg%3E" />
8
9
  <link rel="preconnect" href="https://fonts.googleapis.com" />
9
10
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
10
11
  <link href="https://fonts.googleapis.com/css2?family=Geist+Mono:wght@400;500;600;700&family=Geist:wght@400;500;600;700&display=swap" rel="stylesheet" />
@@ -0,0 +1,21 @@
1
+ // SVG favicon with blue rounded rect + white "PPM" text
2
+ const FAVICON_SVG_NORMAL = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
3
+ <rect width="32" height="32" rx="6" fill="#3b82f6"/>
4
+ <text x="16" y="22" text-anchor="middle" font-family="system-ui,sans-serif" font-weight="700" font-size="11" fill="white">PPM</text>
5
+ </svg>`;
6
+
7
+ // Same + red notification dot (top-right)
8
+ const FAVICON_SVG_BADGE = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
9
+ <rect width="32" height="32" rx="6" fill="#3b82f6"/>
10
+ <text x="16" y="22" text-anchor="middle" font-family="system-ui,sans-serif" font-weight="700" font-size="11" fill="white">PPM</text>
11
+ <circle cx="26" cy="6" r="5" fill="#ef4444"/>
12
+ </svg>`;
13
+
14
+ export const FAVICON_NORMAL = `data:image/svg+xml,${encodeURIComponent(FAVICON_SVG_NORMAL)}`;
15
+ export const FAVICON_BADGE = `data:image/svg+xml,${encodeURIComponent(FAVICON_SVG_BADGE)}`;
16
+
17
+ /** Swap favicon between normal and badge (red dot) variant */
18
+ export function setFavicon(hasBadge: boolean): void {
19
+ const el = document.getElementById("ppm-favicon") as HTMLLinkElement | null;
20
+ if (el) el.href = hasBadge ? FAVICON_BADGE : FAVICON_NORMAL;
21
+ }
@@ -0,0 +1,61 @@
1
+ let audioCtx: AudioContext | null = null;
2
+
3
+ function getAudioContext(): AudioContext {
4
+ if (!audioCtx) audioCtx = new AudioContext();
5
+ return audioCtx;
6
+ }
7
+
8
+ function playTone(freq: number, duration: number, startTime: number, gain: number, type: OscillatorType = "sine") {
9
+ const ctx = getAudioContext();
10
+ const osc = ctx.createOscillator();
11
+ const vol = ctx.createGain();
12
+ osc.type = type;
13
+ osc.frequency.value = freq;
14
+ vol.gain.setValueAtTime(gain, startTime);
15
+ vol.gain.exponentialRampToValueAtTime(0.001, startTime + duration);
16
+ osc.connect(vol);
17
+ vol.connect(ctx.destination);
18
+ osc.start(startTime);
19
+ osc.stop(startTime + duration);
20
+ }
21
+
22
+ /** Chat completed — pleasant double chime ascending */
23
+ function playDone() {
24
+ const ctx = getAudioContext();
25
+ const t = ctx.currentTime;
26
+ playTone(523, 0.15, t, 0.15); // C5
27
+ playTone(659, 0.2, t + 0.12, 0.15); // E5
28
+ }
29
+
30
+ /** Approval request — urgent two-tone alert */
31
+ function playApproval() {
32
+ const ctx = getAudioContext();
33
+ const t = ctx.currentTime;
34
+ playTone(880, 0.12, t, 0.18, "square"); // A5
35
+ playTone(698, 0.12, t + 0.15, 0.18, "square"); // F5
36
+ playTone(880, 0.15, t + 0.3, 0.15, "square"); // A5
37
+ }
38
+
39
+ /** Question — soft ascending triplet */
40
+ function playQuestion() {
41
+ const ctx = getAudioContext();
42
+ const t = ctx.currentTime;
43
+ playTone(440, 0.12, t, 0.12); // A4
44
+ playTone(523, 0.12, t + 0.1, 0.12); // C5
45
+ playTone(659, 0.18, t + 0.2, 0.12); // E5
46
+ }
47
+
48
+ const SOUND_MAP: Record<string, () => void> = {
49
+ done: playDone,
50
+ approval_request: playApproval,
51
+ question: playQuestion,
52
+ };
53
+
54
+ /** Play notification sound by type. No-op if type unknown or AudioContext unavailable. */
55
+ export function playNotificationSound(type: string): void {
56
+ try {
57
+ SOUND_MAP[type]?.();
58
+ } catch {
59
+ // AudioContext may be blocked if no user gesture yet — silently ignore
60
+ }
61
+ }
@@ -0,0 +1,83 @@
1
+ import { create } from "zustand";
2
+
3
+ interface NotificationEntry {
4
+ count: number;
5
+ /** Last notification type: done, approval_request, question */
6
+ type: string;
7
+ projectName: string;
8
+ }
9
+
10
+ /** Badge color per notification type (Tailwind bg class) */
11
+ const TYPE_COLORS: Record<string, string> = {
12
+ approval_request: "bg-red-500",
13
+ question: "bg-amber-500",
14
+ done: "bg-blue-500",
15
+ };
16
+
17
+ /** Priority: higher = more urgent (used to pick "worst" badge color) */
18
+ const TYPE_PRIORITY: Record<string, number> = {
19
+ done: 0,
20
+ question: 1,
21
+ approval_request: 2,
22
+ };
23
+
24
+ /** Get badge color class for a notification type */
25
+ export function notificationColor(type: string | null | undefined): string {
26
+ return (type && TYPE_COLORS[type]) || "bg-red-500";
27
+ }
28
+
29
+ interface NotificationStore {
30
+ notifications: Map<string, NotificationEntry>;
31
+ addNotification: (sessionId: string, type: string, projectName: string) => void;
32
+ clearForSession: (sessionId: string) => void;
33
+ clearAll: () => void;
34
+ }
35
+
36
+ export const useNotificationStore = create<NotificationStore>()((set) => ({
37
+ notifications: new Map(),
38
+
39
+ addNotification: (sessionId, type, projectName) => {
40
+ set((state) => {
41
+ const next = new Map(state.notifications);
42
+ const existing = next.get(sessionId);
43
+ next.set(sessionId, {
44
+ count: (existing?.count ?? 0) + 1,
45
+ type,
46
+ projectName,
47
+ });
48
+ return { notifications: next };
49
+ });
50
+ },
51
+
52
+ clearForSession: (sessionId) => {
53
+ set((state) => {
54
+ if (!state.notifications.has(sessionId)) return state;
55
+ const next = new Map(state.notifications);
56
+ next.delete(sessionId);
57
+ return { notifications: next };
58
+ });
59
+ },
60
+
61
+ clearAll: () => set({ notifications: new Map() }),
62
+ }));
63
+
64
+ /** Derived: total unread count across all sessions */
65
+ export function selectTotalUnread(state: { notifications: Map<string, NotificationEntry> }): number {
66
+ let total = 0;
67
+ for (const [, entry] of state.notifications) total += entry.count;
68
+ return total;
69
+ }
70
+
71
+ /** Derived: most urgent notification type for a project (null = no unread) */
72
+ export function selectProjectUrgentType(projectName: string) {
73
+ return (state: { notifications: Map<string, NotificationEntry> }): string | null => {
74
+ let best: string | null = null;
75
+ let bestPri = -1;
76
+ for (const [, entry] of state.notifications) {
77
+ if (entry.projectName !== projectName) continue;
78
+ const pri = TYPE_PRIORITY[entry.type] ?? 0;
79
+ if (pri > bestPri) { bestPri = pri; best = entry.type; }
80
+ }
81
+ return best;
82
+ };
83
+ }
@@ -1,7 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-client-4Ni0i4Hl.js","assets/react-CYzKIDNi.js"])))=>i.map(i=>d[i]);
2
- import{i as e,t}from"./react-CYzKIDNi.js";import{A as n}from"./input-nI4xe1Y9.js";import{n as r,t as i}from"./jsx-runtime-wQxeESYQ.js";import{a,t as o}from"./tab-store-DIyJSjtr.js";import{n as s}from"./settings-store-CfB0vCtQ.js";import{r as c,t as l}from"./utils-siJJ3uG0.js";import{i as u,r as d,t as f}from"./api-client-4Ni0i4Hl.js";import{A as p,B as m,C as h,D as g,E as _,F as v,H as y,N as b,O as x,P as S,S as C,T as w,U as T,V as E,W as D,g as O,k,r as A,t as j}from"./index-DBdw8tN_.js";import{t as M}from"./markdown-renderer-z99RjIxZ.js";var N=r(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),P=r(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),F=r(`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`}]]),I=r(`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`}]]),L=r(`code`,[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]),R=r(`columns-2`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M12 3v18`,key:`108xh3`}]]),z=r(`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`}]]),B=r(`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`}]]),V=r(`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`}]]),ee=r(`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`}]]),H=r(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),te=r(`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`}]]),U=r(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),W=r(`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`}]]),G=r(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),K=e(t(),1),ne=3e4,re=1e3,q=class{ws=null;url;handlers=[];reconnectAttempts=0;reconnectTimer=null;intentionalClose=!1;constructor(e){this.url=e}connect(){this.intentionalClose=!1,this.cleanup();let e=window.location.protocol===`https:`?`wss:`:`ws:`,t=this.url.startsWith(`ws`)?this.url:`${e}//${window.location.host}${this.url}`;this.ws=new WebSocket(t),this.ws.onopen=()=>{this.reconnectAttempts=0;try{this.ws?.send(JSON.stringify({type:`ready`}))}catch{}},this.ws.onmessage=e=>{for(let t of this.handlers)t(e)},this.ws.onclose=()=>{this.intentionalClose||this.scheduleReconnect()},this.ws.onerror=()=>{this.ws?.close()}}disconnect(){this.intentionalClose=!0,this.cleanup(),this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null)}send(e){this.ws?.readyState===WebSocket.OPEN&&this.ws.send(e)}onMessage(e){return this.handlers.push(e),()=>{this.handlers=this.handlers.filter(t=>t!==e)}}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}cleanup(){this.ws&&=(this.ws.onopen=null,this.ws.onclose=null,this.ws.onmessage=null,this.ws.onerror=null,(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)&&this.ws.close(),null)}scheduleReconnect(){let e=Math.min(re*2**this.reconnectAttempts,ne);this.reconnectAttempts++,this.reconnectTimer=setTimeout(()=>this.connect(),e)}};function ie({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,K.useRef)(null);return(0,K.useEffect)(()=>{let i=new q(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,K.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,K.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,K.useCallback)(()=>{r.current?.disconnect()},[])}}function ae(e,t=`claude`,n=``){let[r,i]=(0,K.useState)([]),[a,o]=(0,K.useState)(!1),[s,c]=(0,K.useState)(!1),[l,f]=(0,K.useState)(`idle`),[p,m]=(0,K.useState)(0),[h,g]=(0,K.useState)(15),[_,v]=(0,K.useState)(null),[y,b]=(0,K.useState)(null),[x,S]=(0,K.useState)(null),[C,w]=(0,K.useState)(!1),T=(0,K.useRef)(``),E=(0,K.useRef)([]),D=(0,K.useRef)(!1),O=(0,K.useRef)(null),k=(0,K.useRef)(()=>{}),A=(0,K.useRef)(null),j=(0,K.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type===`ping`)return;if(t.type===`title_updated`){S(t.title??null);return}if(t.type===`streaming_status`){let e=t.status??`idle`;if(f(e),m(e===`connecting`?t.elapsed??0:0),e===`connecting`){let e=t.effort,n=t.thinkingBudget,r=15;n&&n>0?r=Math.max(15,Math.round(n/500)):e===`high`?r=30:e===`low`&&(r=10),g(r)}return}if(t.type===`connected`){w(!0),t.sessionTitle&&S(t.sessionTitle);return}if(t.type===`status`){w(!0);let e=t;e.sessionTitle&&S(e.sessionTitle),e.isStreaming&&(D.current=!0,c(!0)),e.pendingApproval&&v({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),A.current?.();return}let n=(e,t)=>{let n=E.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=E.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return E.current[n]={...r,children:i},!0},r=()=>{let e=T.current,t=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`&&!r.id.startsWith(`final-`)?[...n.slice(0,-1),{...r,content:e,events:t}]:[...n,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:t,timestamp:new Date().toISOString()}]})};switch(t.type){case`text`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}T.current+=t.content,E.current.push(t),r();break}case`thinking`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}E.current.push(t),r();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}E.current.push(t),r();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}E.current.push(t),r();break}case`approval_request`:E.current.push(t),v({requestId:t.requestId,tool:t.tool,input:t.input});break;case`error`:{E.current.push(t);let e=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,events:e}]:[...n,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]}),D.current=!1,c(!1),f(`idle`);break}case`done`:{if(!D.current)break;t.contextWindowPct!=null&&b(t.contextWindowPct);let e=T.current,n=[...E.current];i(t=>{let r=t[t.length-1];return r?.role===`assistant`?[...t.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:n.length>0?n:r.events}]:t}),T.current=``,E.current=[],D.current=!1,c(!1),f(`idle`);break}}},[]),{send:M,connect:N}=ie({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:j,autoConnect:!!e&&!!n});k.current=M,(0,K.useEffect)(()=>{let r=!1;return c(!1),v(null),T.current=``,E.current=[],w(!1),e&&n?(o(!0),fetch(`${u(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${d()}`}}).then(e=>e.json()).then(e=>{r||D.current||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&!D.current&&i([])}).finally(()=>{r||o(!1)})):i([]),()=>{r=!0}},[e,t,n]);let P=(0,K.useCallback)(e=>{if(e.trim()){if(D.current){let e=T.current,t=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),M(JSON.stringify({type:`cancel`}))}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),T.current=``,E.current=[],O.current=null,D.current=!0,c(!0),f(`connecting`),v(null),M(JSON.stringify({type:`message`,content:e}))}},[M]),F=(0,K.useCallback)((e,t,n)=>{if(M(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=E.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`);if(t){let e=t.input;e&&typeof e==`object`&&(e.answers=n)}i(e=>[...e])}v(null)},[M]),I=(0,K.useCallback)(()=>{if(!D.current)return;M(JSON.stringify({type:`cancel`}));let e=T.current,t=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),T.current=``,E.current=[],O.current=null,D.current=!1,c(!1),v(null)},[M]),L=(0,K.useCallback)(()=>{w(!1),N(),A.current?.()},[N]),R=(0,K.useCallback)(()=>{!e||!n||(o(!0),fetch(`${u(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${d()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(i(e.data),T.current=``,E.current=[])}).catch(()=>{}).finally(()=>o(!1)))},[e,t,n]);return A.current=R,{messages:r,messagesLoading:a,isStreaming:s,streamingStatus:l,connectingElapsed:p,thinkingWarningThreshold:h,pendingApproval:_,contextWindowPct:y,sessionTitle:x,sendMessage:P,respondToApproval:F,cancelStreaming:I,reconnect:L,refetchMessages:R,isConnected:C}}var oe=3e4;function se(e,t=`claude`){let[n,r]=(0,K.useState)({}),[i,a]=(0,K.useState)(!1),[o,s]=(0,K.useState)(null),c=(0,K.useRef)(null),l=(0,K.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${u(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${d()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),e.data.lastFetchedAt&&s(e.data.lastFetchedAt))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,K.useEffect)(()=>(l(),c.current=setInterval(()=>l(),oe),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,K.useCallback)(()=>l(!0),[l])}}var ce={damping:.7,stiffness:.05,mass:1.25},le=70,J=1e3/60,Y=350,X=!1;globalThis.document?.addEventListener(`mousedown`,()=>{X=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{X=!1}),globalThis.document?.addEventListener(`click`,()=>{X=!1});var ue=(e={})=>{let[t,n]=(0,K.useState)(!1),[r,i]=(0,K.useState)(e.initial!==!1),[a,o]=(0,K.useState)(!1),s=(0,K.useRef)(null);s.current=e;let c=(0,K.useCallback)(()=>{if(!X)return!1;let e=window.getSelection();if(!e||!e.rangeCount)return!1;let t=e.getRangeAt(0);return t.commonAncestorContainer.contains(g.current)||g.current?.contains(t.commonAncestorContainer)},[]),l=(0,K.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,K.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,K.useMemo)(()=>{let n;return{escapedFromLock:t,isAtBottom:r,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return g.current?.scrollTop??0},set scrollTop(e){g.current&&(g.current.scrollTop=e,d.ignoreScrollToTop=g.current.scrollTop)},get targetScrollTop(){return!g.current||!_.current?0:g.current.scrollHeight-1-g.current.clientHeight},get calculatedTargetScrollTop(){if(!g.current||!_.current)return 0;let{targetScrollTop:t}=this;if(!e.targetScrollTop)return t;if(n?.targetScrollTop===t)return n.calculatedScrollTop;let r=Math.max(Math.min(e.targetScrollTop(t,{scrollElement:g.current,contentElement:_.current}),t),0);return n={targetScrollTop:t,calculatedScrollTop:r},requestAnimationFrame(()=>{n=void 0}),r},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=le}}},[]),f=(0,K.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=pe(s.current,e.animation),{ignoreEscapes:r=!1}=e,i,a=d.calculatedTargetScrollTop;e.duration instanceof Promise?e.duration.finally(()=>{i=Date.now()}):i=t+(e.duration??0);let o=async()=>{let e=new Promise(requestAnimationFrame).then(()=>{if(!d.isAtBottom)return d.animation=void 0,!1;let{scrollTop:l}=d,u=performance.now(),p=(u-(d.lastTick??u))/J;if(d.animation||={behavior:n,promise:e,ignoreEscapes:r},d.animation.behavior===n&&(d.lastTick=u),c()||t>Date.now())return o();if(l<Math.min(a,d.calculatedTargetScrollTop)){if(d.animation?.behavior===n){if(n===`instant`)return d.scrollTop=d.calculatedTargetScrollTop,o();d.velocity=(n.damping*d.velocity+n.stiffness*d.scrollDifference)/n.mass,d.accumulated+=d.velocity*p,d.scrollTop+=d.accumulated,d.scrollTop!==l&&(d.accumulated=0)}return o()}return i>Date.now()?(a=d.calculatedTargetScrollTop,o()):(d.animation=void 0,d.scrollTop<d.calculatedTargetScrollTop?f({animation:pe(s.current,s.current.resize),ignoreEscapes:r,duration:Math.max(0,i-Date.now())||void 0}):d.isAtBottom)});return e.then(e=>(requestAnimationFrame(()=>{d.animation||(d.lastTick=void 0,d.velocity=0)}),e))};return e.wait!==!0&&(d.animation=void 0),d.animation?.behavior===n?d.animation.promise:o()},[l,c,d]),p=(0,K.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,K.useCallback)(({target:e})=>{if(e!==g.current)return;let{scrollTop:t,ignoreScrollToTop:n}=d,{lastScrollTop:r=t}=d;d.lastScrollTop=t,d.ignoreScrollToTop=void 0,n&&n>t&&(r=n),o(d.isNearBottom),setTimeout(()=>{if(d.resizeDifference||t===n)return;if(c()){u(!0),l(!1);return}let e=t>r,i=t<r;if(d.animation?.ignoreEscapes){d.scrollTop=r;return}i&&(u(!0),l(!1)),e&&u(!1),!d.escapedFromLock&&d.isNearBottom&&l(!0)},1)},[u,l,c,d]),h=(0,K.useCallback)(({target:e,deltaY:t})=>{let n=e;for(;![`scroll`,`auto`].includes(getComputedStyle(n).overflow);){if(!n.parentElement)return;n=n.parentElement}n===g.current&&t<0&&g.current.scrollHeight>g.current.clientHeight&&!d.animation?.ignoreEscapes&&(u(!0),l(!1))},[u,l,d]),g=de(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=de(e=>{if(d.resizeObserver?.disconnect(),!e)return;let t;d.resizeObserver=new ResizeObserver(([e])=>{let{height:n}=e.contentRect,r=n-(t??n);if(d.resizeDifference=r,d.scrollTop>d.targetScrollTop&&(d.scrollTop=d.targetScrollTop),o(d.isNearBottom),r>=0){let e=pe(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:Y})}else d.isNearBottom&&(u(!1),l(!0));t=n,requestAnimationFrame(()=>{setTimeout(()=>{d.resizeDifference===r&&(d.resizeDifference=0)},1)})}),d.resizeObserver?.observe(e)},[]);return{contentRef:_,scrollRef:g,scrollToBottom:f,stopScroll:p,isAtBottom:r||a,isNearBottom:a,escapedFromLock:t,state:d}};function de(e,t){let n=(0,K.useCallback)(t=>(n.current=t,e(t)),t);return n}var fe=new Map;function pe(...e){let t={...ce},n=!1;for(let r of e){if(r===`instant`){n=!0;continue}typeof r==`object`&&(n=!1,t.damping=r.damping??t.damping,t.stiffness=r.stiffness??t.stiffness,t.mass=r.mass??t.mass)}let r=JSON.stringify(t);return fe.has(r)||fe.set(r,Object.freeze(t)),n?`instant`:fe.get(r)}var me=(0,K.createContext)(null),he=typeof window<`u`?K.useLayoutEffect:K.useEffect;function Z({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,K.useRef)(null),d=ue({mass:i,damping:a,stiffness:o,resize:n,initial:r,targetScrollTop:K.useCallback((e,t)=>(y?.targetScrollTop??s)?.(e,t)??e,[s])}),{scrollRef:f,contentRef:p,scrollToBottom:m,stopScroll:h,isAtBottom:g,escapedFromLock:_,state:v}=e??d,y=(0,K.useMemo)(()=>({scrollToBottom:m,stopScroll:h,scrollRef:f,isAtBottom:g,escapedFromLock:_,contentRef:p,state:v,get targetScrollTop(){return u.current},set targetScrollTop(e){u.current=e}}),[m,g,p,f,h,_,v]);return(0,K.useImperativeHandle)(c,()=>y,[y]),he(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),K.createElement(me.Provider,{value:y},K.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=ge();return K.createElement(`div`,{ref:r.scrollRef,style:{height:`100%`,width:`100%`,scrollbarGutter:`stable both-edges`},className:t},K.createElement(`div`,{...n,ref:r.contentRef},typeof e==`function`?e(r):e))}e.Content=t})(Z||={});function ge(){let e=(0,K.useContext)(me);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var Q=i();function _e(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 ve({tool:e,result:t,completed:n,projectName:r}){let[i,a]=(0,K.useState)(!1);if(e.type===`error`)return(0,Q.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,Q.jsx)(E,{className:`size-3`}),(0,Q.jsx)(`span`,{children:e.message})]});let{toolName:o,input:s}=_e(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,h=f&&f.length>0;return(0,Q.jsxs)(`div`,{className:`rounded border text-xs ${d?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,Q.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,Q.jsx)(T,{className:`size-3 shrink-0`}):(0,Q.jsx)(y,{className:`size-3 shrink-0`}),l?(0,Q.jsx)(I,{className:`size-3 text-red-400 shrink-0`}):c||u||n?(0,Q.jsx)(m,{className:`size-3 text-green-400 shrink-0`}):(0,Q.jsx)(p,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,Q.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,Q.jsx)(ye,{name:o,input:s})}),h&&(0,Q.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[f.length,` steps`]})]}),i&&(0,Q.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,Q.jsx)(be,{name:o,input:s,projectName:r}),h&&(0,Q.jsx)(we,{events:f,projectName:r}),c&&(0,Q.jsx)(Se,{toolName:o,output:t.output})]})]})}function ye({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:l(n(t.file_path))})]});case`Bash`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`font-mono text-text-subtle`,children:$(n(t.command),60)})]});case`Glob`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`font-mono text-text-subtle`,children:$(n(t.pattern),40)})]});case`WebSearch`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.query),50)})]});case`WebFetch`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(z,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.url),50)})]});case`ToolSearch`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(_,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.query),50)})]});case`Agent`:case`Task`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(F,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.description||t.prompt),60)})]});case`TodoWrite`:{let n=Array.isArray(t.todos)?t.todos:[],r=n.filter(e=>e.status===`completed`).length;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(ee,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsxs)(`span`,{className:`text-text-subtle`,children:[r,`/`,n.length,` done`]})]})}case`AskUserQuestion`:{let n=Array.isArray(t.questions)?t.questions:[],r=!!t.answers;return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,Q.jsx)(Q.Fragment,{children:e})}}function be({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=o(),s=e=>{n&&i({type:`editor`,title:l(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},c=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${l(e)}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,Q.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,Q.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,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`font-mono text-text-secondary break-all hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>s(n),title:`Open file in editor`,children:[(0,Q.jsx)(a,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,Q.jsxs)(`button`,{type:`button`,className:`text-text-subtle hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>c(n,r(t.old_string),r(t.new_string)),title:`View diff in new tab`,children:[(0,Q.jsx)(R,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,Q.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:$(r(t.content),300)})]})}case`Glob`:return(0,Q.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,Q.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,Q.jsx)(xe,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,Q.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,Q.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,Q.jsx)(Te,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,Q.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.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,Q.jsx)(z,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,Q.jsx)(`p`,{className:`text-text-subtle`,children:$(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,Q.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,Q.jsxs)(`p`,{className:`text-accent text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,Q.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function xe({todos:e}){return(0,Q.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,Q.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,Q.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function Se({toolName:e,output:t}){let[n,r]=(0,K.useState)(!1),i=(0,K.useMemo)(()=>{if(e!==`Agent`&&e!==`Task`)return null;try{let e=JSON.parse(t);if(Array.isArray(e)){let t=e.filter(e=>e.type===`text`&&e.text).map(e=>e.text).join(`
3
-
4
- `);if(t)return t}if(typeof e==`string`)return e}catch{if(t&&!t.startsWith(`[{`))return t}return null},[e,t]);return i?(0,Q.jsxs)(`div`,{className:`border-t border-border pt-1.5 space-y-1`,children:[(0,Q.jsx)(Te,{content:i,maxHeight:`max-h-60`}),(0,Q.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,Q.jsx)(L,{className:`size-3`}),n?`Hide`:`Show`,` raw`]}),n&&(0,Q.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono max-h-40 whitespace-pre-wrap break-all text-[10px]`,children:t})]}):(0,Q.jsx)(Ce,{output:t})}function Ce({output:e}){let t=e.split(`
5
- `).length,n=t>3||e.length>200,[r,i]=(0,K.useState)(n);return(0,Q.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[n&&(0,Q.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,Q.jsx)(y,{className:`size-3`}):(0,Q.jsx)(T,{className:`size-3`}),`Output (`,t,` lines)`]}),(0,Q.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 we({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,Q.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,Q.jsx)(`div`,{className:`text-text-secondary text-[11px]`,children:(0,Q.jsx)(Te,{content:e.content,maxHeight:`max-h-24`})},`st-${n}`):(0,Q.jsx)(ve,{tool:e.tool,result:e.result,completed:!!e.result,projectName:t},`sc-${n}`))})}function Te({content:e,maxHeight:t=`max-h-48`}){return(0,Q.jsx)(M,{content:e,className:`text-text-secondary overflow-auto ${t}`})}function $(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}function Ee(e){let[t,n]=(0,K.useState)({}),[r,i]=(0,K.useState)({}),[a,o]=(0,K.useState)(0),s=(0,K.useCallback)((e,t)=>{n(n=>({...n,[e]:[t]})),i(t=>({...t,[e]:``}))},[]),c=(0,K.useCallback)((e,t)=>{n(n=>{let r=n[e]||[];return{...n,[e]:r.includes(t)?r.filter(e=>e!==t):[...r,t]}})},[]),l=(0,K.useCallback)((e,t)=>{i(n=>({...n,[e]:t})),t&&n(t=>({...t,[e]:[]}))},[]),u=(0,K.useCallback)(e=>(t[e]?.length??0)>0||(r[e]?.trim().length??0)>0,[t,r]);return{answers:t,customInputs:r,activeTab:a,setActiveTab:o,handleSingleSelect:s,handleMultiSelect:c,handleCustomInput:l,hasAnswer:u,allAnswered:(0,K.useMemo)(()=>e.every((e,t)=>u(t)),[e,u]),getFinalAnswer:(0,K.useCallback)(e=>r[e]?.trim()||(t[e]??[]).join(`, `),[t,r]),goToNextTab:(0,K.useCallback)(()=>o(t=>Math.min(t+1,e.length-1)),[e.length]),goToPrevTab:(0,K.useCallback)(()=>o(e=>Math.max(e-1,0)),[])}}function De(e){let[t,n]=(0,K.useState)(0),r=(0,K.useRef)(null);return(0,K.useEffect)(()=>n(0),[e.activeTab]),(0,K.useEffect)(()=>{if(!e.enabled)return;let i=r=>{let i=document.activeElement===e.customInputRef.current;if(!i&&r.key>=`1`&&r.key<=`9`){r.preventDefault();let t=parseInt(r.key)-1;t<e.totalOptions-1&&(n(t),e.onSelectOption(t));return}if(!i&&(r.key===`o`||r.key===`O`||r.key===`0`)){r.preventDefault(),e.customInputRef.current?.focus(),n(e.totalOptions-1);return}if(r.key===`Tab`&&e.questions.length>1){r.preventDefault(),r.shiftKey?e.goToPrevTab():e.goToNextTab();return}if(!i){if(r.key===`ArrowLeft`){r.preventDefault(),e.goToPrevTab();return}if(r.key===`ArrowRight`){r.preventDefault(),e.goToNextTab();return}if(r.key===`ArrowUp`){r.preventDefault(),n(e=>Math.max(0,e-1));return}if(r.key===`ArrowDown`){r.preventDefault(),n(t=>Math.min(e.totalOptions-1,t+1));return}if(r.key===` `){r.preventDefault(),e.onSelectOption(t);return}}if(r.key===`Enter`){r.preventDefault(),e.allAnswered?e.onSubmit():e.hasAnswer(e.activeTab)&&e.goToNextTab();return}r.key===`Escape`&&i&&e.customInputRef.current?.blur()},a=r.current;return a&&(a.addEventListener(`keydown`,i),a.setAttribute(`tabindex`,`0`),a.contains(document.activeElement)||a.focus()),()=>{a?.removeEventListener(`keydown`,i)}},[e,t]),{focusedOption:t,setFocusedOption:n,containerRef:r}}function Oe({questions:e,onSubmit:t,onSkip:n}){let r=(0,K.useRef)(null),i=Ee(e),a=e[i.activeTab],o=a?a.options.length+1:0,s=e.length>1,c=(0,K.useCallback)(()=>{if(!i.allAnswered)return;let n={};e.forEach((e,t)=>{n[e.question]=i.getFinalAnswer(t)}),t(n)},[i.allAnswered,i.getFinalAnswer,e,t]),l=(0,K.useCallback)(e=>{if(!(!a||e<0))if(e<a.options.length){let t=a.options[e]?.label;if(!t)return;a.multiSelect?i.handleMultiSelect(i.activeTab,t):i.handleSingleSelect(i.activeTab,t)}else e===a.options.length&&r.current?.focus()},[a,i]),u=De({questions:e,activeTab:i.activeTab,totalOptions:o,allAnswered:i.allAnswered,hasAnswer:i.hasAnswer,onSelectOption:l,goToNextTab:i.goToNextTab,goToPrevTab:i.goToPrevTab,onSubmit:c,customInputRef:r,enabled:!0}),d=(0,K.useCallback)(e=>{l(e),u.setFocusedOption(e)},[l,u.setFocusedOption]);return(0,Q.jsxs)(`div`,{ref:u.containerRef,className:`rounded-lg border-2 border-primary/30 bg-primary/5 p-3 space-y-3 outline-none animate-in slide-in-from-bottom-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,Q.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,Q.jsxs)(`span`,{className:`text-[10px] text-text-secondary font-normal`,children:[s?`←→ tabs · `:``,`↑↓ options · 1-`,Math.min(o-1,9),` select · Enter submit`]})]}),s&&(0,Q.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,Q.jsxs)(`button`,{className:`flex items-center gap-1.5 px-3 py-1.5 rounded text-xs whitespace-nowrap transition-all ${i.activeTab===t?`bg-primary text-primary-foreground`:i.hasAnswer(t)?`text-primary bg-transparent`:`text-text-secondary hover:bg-surface-elevated`}`,onClick:()=>{i.setActiveTab(t),u.setFocusedOption(0)},tabIndex:-1,children:[(0,Q.jsx)(`span`,{className:`flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-semibold ${i.activeTab===t?`bg-white/20`:i.hasAnswer(t)?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:i.hasAnswer(t)?`✓`:t+1}),(0,Q.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,Q.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,Q.jsx)(`div`,{className:`text-sm text-text-primary`,children:a.question}),a.multiSelect&&(0,Q.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a.options.map((e,t)=>{let n=(i.answers[i.activeTab]||[]).includes(e.label),r=u.focusedOption===t;return(0,Q.jsxs)(`button`,{onClick:()=>d(t),className:`text-left flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border transition-all ${n?`border-primary bg-primary/10 text-text-primary`:`border-border bg-background text-text-secondary hover:border-primary/40 hover:bg-primary/5`} ${r?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,Q.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded text-[10px] font-semibold shrink-0 mt-px ${n?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:t+1}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,Q.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,Q.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border border-dashed transition-all border-border bg-transparent ${u.focusedOption===o-1?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,Q.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded bg-surface-elevated text-text-secondary text-[10px] font-semibold shrink-0 mt-px`,children:`O`}),(0,Q.jsx)(`input`,{ref:r,type:`text`,className:`flex-1 px-2 py-1 text-xs bg-surface border border-border rounded text-text-primary outline-none placeholder:text-text-subtle focus:border-primary`,placeholder:`Other (press O to type)...`,value:i.customInputs[i.activeTab]||``,onChange:e=>i.handleCustomInput(i.activeTab,e.target.value),onFocus:()=>u.setFocusedOption(o-1)})]})]})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToPrevTab,disabled:i.activeTab===0,tabIndex:-1,children:`← Prev`}),(0,Q.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToNextTab,disabled:i.activeTab===e.length-1,tabIndex:-1,children:`Next →`})]}),(0,Q.jsx)(`button`,{onClick:n,className:`px-4 py-1.5 rounded border border-border bg-background text-text-secondary text-xs hover:bg-surface-elevated transition-colors`,tabIndex:-1,children:`Skip`}),(0,Q.jsxs)(`button`,{onClick:c,disabled:!i.allAnswered,className:`px-4 py-1.5 rounded bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,tabIndex:-1,children:[`Submit `,i.allAnswered?`✓`:`(${e.filter((e,t)=>i.hasAnswer(t)).length}/${e.length})`]})]})]})}function ke({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,streamingStatus:a,connectingElapsed:o,thinkingWarningThreshold:s,projectName:c,onFork:l}){return t?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,Q.jsx)(F,{className:`size-10 text-text-subtle animate-pulse`}),(0,Q.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!i?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,Q.jsx)(F,{className:`size-10 text-text-subtle`}),(0,Q.jsx)(`p`,{className:`text-sm`,children:`Send a message to start the conversation`})]}):(0,Q.jsxs)(Z,{className:`flex-1 overflow-y-auto`,resize:`smooth`,initial:`instant`,children:[(0,Q.jsxs)(Z.Content,{className:`p-4 space-y-4`,children:[e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return t||n}).map(e=>(0,Q.jsx)(je,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:c,onFork:e.role===`user`&&l?()=>l(e.content):void 0},e.id)),n&&(n.tool===`AskUserQuestion`?(0,Q.jsx)(Ke,{approval:n,onRespond:r}):(0,Q.jsx)(Ge,{approval:n,onRespond:r})),i&&(0,Q.jsx)(Ue,{lastMessage:e[e.length-1],streamingStatus:a,elapsed:o,warningThreshold:s})]}),(0,Q.jsx)(Ae,{})]})}function Ae(){let{isAtBottom:e,scrollToBottom:t}=ge();return e?null:(0,Q.jsxs)(`button`,{onClick:()=>t(),className:`absolute bottom-2 left-1/2 -translate-x-1/2 flex items-center gap-1 px-3 py-1 rounded-full bg-surface-elevated border border-border text-xs text-text-secondary hover:text-foreground shadow-lg transition-all`,children:[(0,Q.jsx)(T,{className:`size-3`}),`Scroll to bottom`]})}function je({message:e,isStreaming:t,projectName:n,onFork:r}){return e.role===`user`?(0,Q.jsx)(Le,{content:e.content,projectName:n,onFork:r}):e.role===`system`?(0,Q.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,Q.jsx)(E,{className:`size-4 shrink-0`}),(0,Q.jsx)(`p`,{children:e.content})]}):(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.events&&e.events.length>0?(0,Q.jsx)(Be,{events:e.events,isStreaming:t,projectName:n}):e.content&&(0,Q.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,Q.jsx)(We,{content:e.content,projectName:n})})})}var Me=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]);function Ne(e){let t=e.match(/^\[Attached file: (.+?)\]\n\n?/);if(t)return{files:[t[1]],text:e.slice(t[0].length)};let n=e.match(/^\[Attached files:\n([\s\S]+?)\]\n\n?/);return n?{files:n[1].split(`
6
- `).map(e=>e.trim()).filter(Boolean),text:e.slice(n[0].length)}:{files:[],text:e}}function Pe(e,t){let n=l(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function Fe(e){let t=e.lastIndexOf(`.`);return t===-1?!1:Me.has(e.slice(t).toLowerCase())}function Ie(e){return e.toLowerCase().endsWith(`.pdf`)}function Le({content:e,projectName:t,onFork:r}){let{files:i,text:a}=(0,K.useMemo)(()=>Ne(e),[e]);return(0,Q.jsx)(`div`,{className:`flex justify-end group/user`,children:(0,Q.jsxs)(`div`,{className:`rounded-lg bg-primary/10 px-3 py-2 text-sm text-text-primary max-w-[85%] space-y-2 relative`,children:[i.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:i.map((e,n)=>Fe(e)?(0,Q.jsx)(Re,{src:Pe(e,t),alt:l(e)||`image`},n):Ie(e)?(0,Q.jsx)(ze,{src:Pe(e,t),filename:l(e)||`document.pdf`,mimeType:`application/pdf`},n):(0,Q.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,Q.jsx)(v,{className:`size-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate max-w-40`,children:l(e)})]},n))}),a&&(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:a}),r&&(0,Q.jsx)(`button`,{onClick:r,title:`Retry from this message (fork session)`,className:`absolute -left-8 top-1/2 -translate-y-1/2 opacity-0 group-hover/user:opacity-100 transition-opacity size-6 flex items-center justify-center rounded bg-surface border border-border text-text-subtle hover:text-text-primary hover:bg-surface-elevated`,children:(0,Q.jsx)(n,{className:`size-3`})})]})})}function Re({src:e,alt:t}){let[n,r]=(0,K.useState)(null),[i,a]=(0,K.useState)(!1);return(0,K.useEffect)(()=>{let t,n=d();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,Q.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,Q.jsx)(V,{className:`size-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate max-w-40`,children:t})]}):n?(0,Q.jsx)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`block`,children:(0,Q.jsx)(`img`,{src:n,alt:t,className:`rounded-md max-h-48 max-w-full object-contain border border-border`})}):(0,Q.jsx)(`div`,{className:`rounded-md bg-surface border border-border h-24 w-32 animate-pulse`})}function ze({src:e,filename:t,mimeType:n}){let[r,i]=(0,K.useState)(!1);return(0,Q.jsxs)(`button`,{type:`button`,onClick:(0,K.useCallback)(async()=>{i(!0);try{let t=d(),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,Q.jsx)(v,{className:`size-3.5 shrink-0 text-red-400`}),(0,Q.jsx)(`span`,{className:`truncate max-w-40`,children:t}),r&&(0,Q.jsx)(`span`,{className:`animate-spin text-[10px]`,children:`...`})]})}function Be({events:e,isStreaming:t,projectName:n}){let r=[],i=``,a=``;for(let t=0;t<e.length;t++){let n=e[t];if(n.type===`thinking`){i&&=(r.push({kind:`text`,content:i}),``),a+=n.content;continue}a&&=(r.push({kind:`thinking`,content:a}),``),n.type===`text`?i+=n.content:n.type===`tool_use`?(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n})):n.type===`tool_result`||(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n}))}a&&r.push({kind:`thinking`,content:a}),i&&r.push({kind:`text`,content:i});let o=e.filter(e=>e.type===`tool_result`);for(let e of o){let t=e.toolUseId;if(t){let n=r.find(e=>e.kind===`tool`&&e.tool.type===`tool_use`&&e.tool.toolUseId===t);if(n){n.result=e;continue}}let n=r.find(e=>e.kind===`tool`&&!e.result);n&&(n.result=e)}for(let e=0;e<r.length;e++){let n=r[e];if(n.kind===`tool`&&!n.result){let i=!1;if(n.tool.type===`tool_use`&&n.tool.tool===`Read`){let t=n.tool.input?.file_path;t&&(i=r.slice(e+1).some(e=>e.kind===`tool`&&e.result&&e.tool.type===`tool_use`&&e.tool.tool===`Edit`&&e.tool.input?.file_path===t))}n.completed=i||!t}}return(0,Q.jsx)(Q.Fragment,{children:r.map((e,i)=>{if(e.kind===`thinking`)return(0,Q.jsx)(Ve,{content:e.content,isStreaming:t&&i===r.length-1},`think-${i}`);if(e.kind===`text`){let a=t&&i===r.length-1;return(0,Q.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,Q.jsx)(He,{content:e.content,animate:a,projectName:n})},`text-${i}`)}return(0,Q.jsx)(ve,{tool:e.tool,result:e.result,completed:e.completed,projectName:n},`tool-${i}`)})})}function Ve({content:e,isStreaming:t}){let[n,r]=(0,K.useState)(t);return(0,K.useEffect)(()=>{!t&&e.length>0&&r(!1)},[t,e.length]),(0,Q.jsxs)(`div`,{className:`rounded border border-border/50 bg-surface/30 text-xs`,children:[(0,Q.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors text-text-subtle`,children:[t?(0,Q.jsx)(p,{className:`size-3 animate-spin`}):(0,Q.jsx)(y,{className:`size-3 transition-transform ${n?`rotate-90`:``}`}),(0,Q.jsxs)(`span`,{children:[`Thinking`,t?`...`:``]}),!t&&(0,Q.jsx)(`span`,{className:`text-text-subtle/50 ml-auto`,children:e.length>100?`${Math.round(e.length/4)} tokens`:``})]}),n&&(0,Q.jsx)(`div`,{className:`px-2 pb-2 text-text-subtle/80 whitespace-pre-wrap max-h-60 overflow-y-auto text-[11px] leading-relaxed`,children:e})]})}function He({content:e,animate:t,projectName:n}){return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(We,{content:e,projectName:n}),t&&(0,Q.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function Ue({lastMessage:e,streamingStatus:t,elapsed:n,warningThreshold:r=15}){let i=!e||e.role!==`assistant`,a=e?.events?.length?e.events[e.events.length-1].type===`tool_result`:!1;return!i&&!a?null:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-text-subtle`,children:[(0,Q.jsx)(p,{className:`size-3 animate-spin`}),(0,Q.jsxs)(`span`,{children:[`Thinking`,i&&(n??0)>0&&(0,Q.jsxs)(`span`,{className:`text-text-subtle/60`,children:[`... (`,n,`s)`]})]})]}),i&&(n??0)>=r&&(0,Q.jsx)(`p`,{className:`text-xs text-yellow-500/80 ml-5`,children:`Taking longer than usual — may be rate-limited or API slow. Try sending a new message to retry.`})]})}function We({content:e,projectName:t}){return(0,Q.jsx)(M,{content:e,projectName:t,codeActions:!0})}function Ge({approval:e,onRespond:t}){return(0,Q.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,Q.jsx)(U,{className:`size-4`}),(0,Q.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,Q.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,Q.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,Q.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,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.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,Q.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 Ke({approval:e,onRespond:t}){return(0,Q.jsx)(Oe,{questions:e.input.questions??[],onSubmit:n=>t(e.requestId,!0,n),onSkip:()=>t(e.requestId,!1)})}var qe=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),Je=new Set([`application/pdf`]),Ye=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],Xe=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 Ze(e){return qe.has(e.type)}function Qe(e){if(qe.has(e.type)||Je.has(e.type)||Ye.some(t=>e.type.startsWith(t)))return!0;let t=$e(e.name);return!!(t&&Xe.has(t))}function $e(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function et({attachments:e,onRemove:t}){return e.length===0?null:(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-2 md:px-4 pt-2`,children:e.map(e=>(0,Q.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,Q.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,Q.jsx)(V,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,Q.jsx)(v,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,Q.jsx)(p,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,Q.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,Q.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,Q.jsx)(C,{className:`size-3`})})]},e.id))})}function tt(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&n(r.children)}return n(e),t}function nt({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,K.useState)(0),s=(0,K.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,K.useEffect)(()=>{o(0)},[t]),(0,K.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,K.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,K.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,Q.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,Q.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,Q.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,Q.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,Q.jsx)(b,{className:`size-4 text-amber-500`}):(0,Q.jsx)(S,{className:`size-4 text-blue-400`})}),(0,Q.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}function rt({onSend:e,isStreaming:t,onCancel:n,disabled:r,projectName:i,onSlashStateChange:a,onSlashItemsLoaded:o,slashSelected:s,onFileStateChange:l,onFileItemsLoaded:p,fileSelected:m,externalFiles:h,initialValue:g}){let[_,v]=(0,K.useState)(g??``),[y,b]=(0,K.useState)([]),x=(0,K.useRef)(null),S=(0,K.useRef)(null),C=(0,K.useRef)(null),w=(0,K.useRef)([]),T=(0,K.useRef)([]);(0,K.useEffect)(()=>{g&&(v(g),setTimeout(()=>{let e=x.current;e&&(e.focus(),e.selectionStart=e.selectionEnd=e.value.length)},50))},[g]),(0,K.useEffect)(()=>{if(!i){w.current=[],o?.([]);return}f.get(`${u(i)}/chat/slash-items`).then(e=>{w.current=e,o?.(e)}).catch(()=>{w.current=[],o?.([])})},[i]),(0,K.useEffect)(()=>{if(!i){T.current=[],p?.([]);return}f.get(`${u(i)}/files/tree?depth=5`).then(e=>{let t=tt(e);T.current=t,p?.(t)}).catch(()=>{T.current=[],p?.([])})},[i]),(0,K.useEffect)(()=>{if(!s)return;let e=x.current,t=e?.selectionStart??_.length,n=_.slice(0,t),r=_.slice(t),i=n.replace(/(?:^|\s)\/\S*$/,e=>`${e.startsWith(`/`)?``:e[0]}/${s.name} `);v(i+r),a?.(!1,``),l?.(!1,``),e&&(e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=i.length},0))},[s]),(0,K.useEffect)(()=>{if(!m)return;let e=x.current;if(!e)return;let t=e.selectionStart,n=_.slice(0,t),r=_.slice(t),i=n.match(/@(\S*)$/);if(i){let t=n.length-i[0].length;v(n.slice(0,t)+`@${m.path} `+r);let a=t+m.path.length+2;setTimeout(()=>{e.selectionStart=e.selectionEnd=a,e.focus()},0)}else{let t=_+`@${m.path} `;v(t),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length,e.focus()},0)}l?.(!1,``)},[m]),(0,K.useEffect)(()=>{!h||h.length===0||D(h)},[h]);let E=(0,K.useCallback)(async e=>{if(!i)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=d();r&&(n.Authorization=`Bearer ${r}`);let a=await(await fetch(`${u(i)}/chat/upload`,{method:`POST`,headers:n,body:t})).json();return a.ok&&Array.isArray(a.data)&&a.data.length>0?a.data[0].path:null}catch{return null}},[i]),D=(0,K.useCallback)(e=>{for(let t of e){if(!Qe(t)){v(e=>e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=c(),n=Ze(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};b(e=>[...e,i]),E(t).then(t=>{b(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}(S.current??x.current)?.focus()},[E]),O=(0,K.useCallback)(e=>{b(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),k=(0,K.useCallback)(()=>{let t=_.trim(),n=y.filter(e=>e.status===`ready`);if(!(!t&&n.length===0)&&!r){a?.(!1,``),l?.(!1,``),e(t,n),v(``);for(let e of y)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);b([]),x.current&&(x.current.style.height=`auto`),S.current&&(S.current.style.height=`auto`)}},[_,y,r,e,a,l]),A=(0,K.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),k())},[k]),j=(0,K.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.match(/(?:^|\s)\/(\S*)$/);if(r&&w.current.length>0){a?.(!0,r[1]??``),l?.(!1,``);return}let i=n.match(/@(\S*)$/);if(i&&T.current.length>0){l?.(!0,i[1]??``),a?.(!1,``);return}a?.(!1,``),l?.(!1,``)},[a,l]),M=(0,K.useCallback)(e=>{v(e),setTimeout(()=>{j(e,x.current?.selectionStart??e.length)},0)},[j]),N=(0,K.useCallback)(e=>{let t=e?.target??x.current;t&&(t.style.height=`auto`,t.style.height=Math.min(t.scrollHeight,160)+`px`)},[]),F=(0,K.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t)if(e.kind===`file`){let t=e.getAsFile();t&&n.push(t)}n.length>0&&(e.preventDefault(),D(n))},[D]),I=(0,K.useCallback)(e=>{e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length>0&&D(t)},[D]),L=(0,K.useCallback)(e=>{e.preventDefault()},[]),R=(0,K.useCallback)(()=>{C.current?.click()},[]),z=(0,K.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&D(t),e.target.value=``},[D]),B=_.trim().length>0||y.some(e=>e.status===`ready`),V=t&&!B;return(0,Q.jsxs)(`div`,{className:`p-2 md:p-3 bg-background`,children:[(0,Q.jsxs)(`div`,{className:`border border-border rounded-xl md:rounded-2xl bg-surface shadow-sm cursor-text`,onClick:()=>!r&&(S.current??x.current)?.focus(),children:[(0,Q.jsx)(et,{attachments:y,onRemove:O}),(0,Q.jsxs)(`div`,{className:`flex items-end gap-1 md:hidden px-2 py-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),R()},disabled:r,className:`flex items-center justify-center size-7 shrink-0 rounded-full text-text-subtle hover:text-text-primary transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,Q.jsx)(H,{className:`size-4`})}),(0,Q.jsx)(`textarea`,{ref:S,value:_,onChange:e=>{M(e.target.value),N(e)},onKeyDown:A,onPaste:F,onDrop:I,onDragOver:L,placeholder:t?`Follow-up...`:`Ask anything...`,disabled:r,rows:1,className:`flex-1 resize-none bg-transparent py-1.5 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-20`}),V?(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop`,children:(0,Q.jsx)(G,{className:`size-3`})}):(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),k()},disabled:r||!B,className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 transition-colors`,"aria-label":`Send`,children:(0,Q.jsx)(P,{className:`size-3.5`})})]}),(0,Q.jsxs)(`div`,{className:`hidden md:block`,children:[(0,Q.jsx)(`textarea`,{ref:x,value:_,onChange:e=>{M(e.target.value),N(e)},onKeyDown:A,onPaste:F,onDrop:I,onDragOver:L,placeholder:t?`Follow-up or Stop...`:`Ask anything...`,disabled:r,rows:1,className:`w-full resize-none bg-transparent px-4 pt-3 pb-1 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-40`}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),R()},disabled:r,className:`flex items-center justify-center size-8 rounded-full text-text-subtle hover:text-text-primary hover:bg-surface-elevated transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,Q.jsx)(H,{className:`size-4`})})}),(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:V?(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-8 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop response`,children:(0,Q.jsx)(G,{className:`size-3.5`})}):(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),k()},disabled:r||!B,className:`flex items-center justify-center size-8 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":`Send message`,children:(0,Q.jsx)(P,{className:`size-4`})})})]})]})]}),(0,Q.jsx)(`input`,{ref:C,type:`file`,multiple:!0,className:`hidden`,onChange:z})]})}function it({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,K.useState)(0),s=(0,K.useRef)(null),c=e.filter(e=>{let n=t.toLowerCase();return e.name.toLowerCase().includes(n)||e.description.toLowerCase().includes(n)});(0,K.useEffect)(()=>{o(0)},[t]),(0,K.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,K.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,K.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,Q.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,Q.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,Q.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,Q.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`skill`?(0,Q.jsx)(W,{className:`size-4 text-amber-500`}):(0,Q.jsx)(w,{className:`size-4 text-blue-500`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Q.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,Q.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,Q.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`user`?`global`:e.type})]}),e.description&&(0,Q.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]},`${e.type}-${e.name}`))})})}function at(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function ot(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function st(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 ct({label:e,bucket:t}){if(!t)return null;let n=Math.round(t.utilization*100),r=st(t);return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,Q.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,children:[`↻ `,r]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-full rounded-full transition-all ${ot(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,Q.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${at(n)}`,children:[n,`%`]})]})]})}function lt(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 ut({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastFetchedAt:a}){if(!t)return null;let o=e.queryCostUsd!=null||e.totalCostUsd!=null,s=e.session||e.weekly||e.weeklyOpus||e.weeklySonnet;return(0,Q.jsxs)(`div`,{className:`border-b border-border bg-surface px-3 py-2.5 space-y-2.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage Limits`}),a&&(0,Q.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:lt(new Date(a).getTime())})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r&&(0,Q.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,Q.jsx)(g,{className:`size-3 ${i?`animate-spin`:``}`})}),(0,Q.jsx)(`button`,{onClick:n,className:`text-xs text-text-subtle hover:text-text-primary px-1`,children:`✕`})]})]}),s?(0,Q.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,Q.jsx)(ct,{label:`5-Hour Session`,bucket:e.session}),(0,Q.jsx)(ct,{label:`Weekly`,bucket:e.weekly}),(0,Q.jsx)(ct,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,Q.jsx)(ct,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,Q.jsxs)(`p`,{className:`text-xs text-text-subtle`,children:[`No data — run `,(0,Q.jsx)(`code`,{className:`bg-surface-elevated px-1 rounded`,children:`bun install`})]}),o&&(0,Q.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,Q.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,Q.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]})]})}function dt(e){try{return new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}catch{return``}}function ft(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function pt({projectName:e,usageInfo:t,contextWindowPct:n,usageLoading:r,refreshUsage:i,lastFetchedAt:a,sessionId:s,onSelectSession:c,onBugReport:l,isConnected:d,onReconnect:m}){let[h,v]=(0,K.useState)(null),[y,b]=(0,K.useState)([]),[S,w]=(0,K.useState)(!1),[T,E]=(0,K.useState)(``),[O,j]=(0,K.useState)(null),[M,P]=(0,K.useState)(``),F=(0,K.useRef)(null),I=o(e=>e.openTab),L=e=>{v(t=>t===e?null:e)},R=(0,K.useCallback)(async()=>{if(e){w(!0);try{b(await f.get(`${u(e)}/chat/sessions`))}catch{}finally{w(!1)}}},[e]);(0,K.useEffect)(()=>{h===`history`&&y.length===0&&R()},[h]);function z(t){c?(c(t),v(null)):I({type:`chat`,title:t.title||`Chat`,projectId:e??null,metadata:{projectName:e,sessionId:t.id},closable:!0})}let V=(0,K.useCallback)((e,t)=>{t.stopPropagation(),j(e.id),P(e.title||``),setTimeout(()=>F.current?.select(),0)},[]),ee=(0,K.useCallback)(async()=>{if(!O||!M.trim()||!e){j(null);return}try{await f.patch(`${u(e)}/chat/sessions/${O}`,{title:M.trim()}),b(e=>e.map(e=>e.id===O?{...e,title:M.trim()}:e))}catch{}j(null)},[O,M,e]),H=(0,K.useCallback)(()=>j(null),[]),U=T.trim()?y.filter(e=>(e.title||``).toLowerCase().includes(T.toLowerCase())):y,W=t.fiveHour==null?null:Math.round(t.fiveHour*100),G=t.sevenDay==null?null:Math.round(t.sevenDay*100),ne=W!=null||G!=null?ft(Math.max(W??0,G??0)):`text-text-subtle`;return(0,Q.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,Q.jsxs)(`button`,{onClick:()=>L(`history`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${h===`history`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,children:[(0,Q.jsx)(B,{className:`size-3`}),(0,Q.jsx)(`span`,{children:`History`})]}),(0,Q.jsx)(`button`,{onClick:()=>L(`config`),className:`p-1 rounded transition-colors ${h===`config`?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary hover:bg-surface-elevated`}`,title:`AI Settings`,children:(0,Q.jsx)(te,{className:`size-3`})}),(0,Q.jsxs)(`button`,{onClick:()=>L(`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 ${h===`usage`?`bg-primary/10`:``} ${ne}`,title:`Usage limits`,children:[(0,Q.jsx)(N,{className:`size-3`}),(0,Q.jsxs)(`span`,{children:[`5h:`,W==null?`--%`:`${W}%`]}),(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,Q.jsxs)(`span`,{children:[`Wk:`,G==null?`--%`:`${G}%`]}),n!=null&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,Q.jsxs)(`span`,{className:ft(n),children:[`Ctx:`,n,`%`]})]})]}),(0,Q.jsx)(`div`,{className:`flex-1`}),m&&(0,Q.jsx)(`button`,{onClick:m,className:`size-4 flex items-center justify-center`,title:d?`Connected`:`Disconnected — click to reconnect`,children:(0,Q.jsx)(`span`,{className:`size-2 rounded-full ${d?`bg-green-500`:`bg-red-500 animate-pulse`}`})})]}),h===`history`&&(0,Q.jsxs)(`div`,{className:`border-t border-border/30 bg-surface`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 border-b border-border/30`,children:[(0,Q.jsx)(_,{className:`size-3 text-text-subtle shrink-0`}),(0,Q.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),placeholder:`Search sessions...`,className:`flex-1 bg-transparent text-[11px] text-text-primary outline-none placeholder:text-text-subtle`}),(0,Q.jsx)(`button`,{onClick:R,disabled:S,className:`p-0.5 rounded text-text-subtle hover:text-text-secondary transition-colors disabled:opacity-50`,title:`Refresh`,children:(0,Q.jsx)(g,{className:`size-3 ${S?`animate-spin`:``}`})})]}),(0,Q.jsx)(`div`,{className:`max-h-[200px] overflow-y-auto`,children:S&&y.length===0?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,Q.jsx)(p,{className:`size-3.5 animate-spin text-text-subtle`})}):U.length===0?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-3 text-[11px] text-text-subtle`,children:T?`No matching sessions`:`No sessions yet`}):U.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left hover:bg-surface-elevated transition-colors group`,children:[(0,Q.jsx)(k,{className:`size-3 shrink-0 text-text-subtle`}),O===e.id?(0,Q.jsxs)(`form`,{className:`flex items-center gap-1 flex-1 min-w-0`,onSubmit:e=>{e.preventDefault(),ee()},children:[(0,Q.jsx)(`input`,{ref:F,value:M,onChange:e=>P(e.target.value),onBlur:ee,onKeyDown:e=>{e.key===`Escape`&&H()},className:`flex-1 min-w-0 bg-surface-elevated text-[11px] text-text-primary px-1 py-0.5 rounded border border-border outline-none focus:border-primary`,autoFocus:!0}),(0,Q.jsx)(`button`,{type:`submit`,className:`p-0.5 text-green-500 hover:text-green-400`,onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(D,{className:`size-3`})}),(0,Q.jsx)(`button`,{type:`button`,className:`p-0.5 text-text-subtle hover:text-text-secondary`,onClick:e=>{e.stopPropagation(),H()},children:(0,Q.jsx)(C,{className:`size-3`})})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{onClick:()=>z(e),className:`text-[11px] truncate flex-1 text-left`,children:e.title||`Untitled`}),(0,Q.jsx)(`button`,{onClick:t=>V(e,t),className:`p-0.5 rounded text-text-subtle hover:text-text-secondary opacity-0 group-hover:opacity-100 transition-opacity`,title:`Rename session`,children:(0,Q.jsx)(x,{className:`size-3`})})]}),O!==e.id&&e.updatedAt&&(0,Q.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:dt(e.updatedAt)})]},e.id))})]}),h===`config`&&(0,Q.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2 max-h-[280px] overflow-y-auto`,children:(0,Q.jsx)(A,{compact:!0})}),h===`usage`&&(0,Q.jsx)(ut,{usage:t,visible:!0,onClose:()=>v(null),onReload:i,loading:r,lastFetchedAt:a})]})}function mt({metadata:e,tabId:t}){let[n,r]=(0,K.useState)(e?.sessionId??null),[i,a]=(0,K.useState)(e?.providerId??`claude`),[c,l]=(0,K.useState)([]),[d,p]=(0,K.useState)(!1),[m,g]=(0,K.useState)(``),[_,v]=(0,K.useState)(null),[y,b]=(0,K.useState)([]),[x,S]=(0,K.useState)(!1),[C,w]=(0,K.useState)(``),[T,E]=(0,K.useState)(null),[D,k]=(0,K.useState)(!1),[A,M]=(0,K.useState)(null),N=(0,K.useRef)(0),P=e?.projectName??``,F=o(e=>e.updateTab),I=s(e=>e.version),{usageInfo:L,usageLoading:R,lastFetchedAt:z,refreshUsage:B}=se(P,i);(0,K.useEffect)(()=>{!t||!n||F(t,{metadata:{...e,sessionId:n,providerId:i}})},[n,i]);let{messages:V,messagesLoading:ee,isStreaming:H,streamingStatus:te,connectingElapsed:U,thinkingWarningThreshold:W,pendingApproval:G,contextWindowPct:ne,sessionTitle:re,sendMessage:q,respondToApproval:ie,cancelStreaming:oe,reconnect:ce,refetchMessages:le,isConnected:J}=ae(n,i,P);(0,K.useEffect)(()=>{t&&re&&F(t,{title:re})},[re]);let Y=(0,K.useRef)(e?.pendingMessage);(0,K.useEffect)(()=>{if(Y.current&&J&&n){let n=Y.current;Y.current=void 0,t&&F(t,{metadata:{...e,pendingMessage:void 0}}),setTimeout(()=>q(n),100)}},[J,n]),(0,K.useCallback)(()=>{o.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:P},projectId:P||null,closable:!0})},[P]);let X=(0,K.useCallback)(e=>{r(e.id),a(e.providerId),t&&F(t,{title:e.title||`Chat`})},[t,F]),ue=(0,K.useCallback)(async e=>{if(!(!n||!P))try{let{api:t,projectUrl:r}=await O(async()=>{let{api:e,projectUrl:t}=await import(`./api-client-4Ni0i4Hl.js`).then(e=>e.n);return{api:e,projectUrl:t}},__vite__mapDeps([0,1])),a=await t.post(`${r(P)}/chat/sessions/${n}/fork?providerId=${i}`);o.getState().openTab({type:`chat`,title:`Fork: ${e.slice(0,30)}`,metadata:{projectName:P,sessionId:a.id,providerId:i,pendingMessage:e},projectId:P||null,closable:!0})}catch(e){console.error(`Fork failed:`,e)}},[n,P,i]),de=(0,K.useCallback)((e,t)=>{if(t.length===0)return e;let n=t.filter(e=>e.serverPath).map(e=>e.serverPath).join(`
7
- `);return n?(t.length===1?`[Attached file: ${n}]\n\n`:`[Attached files:\n${n}\n]\n\n`)+e:e},[]),fe=(0,K.useCallback)(async(e,t=[])=>{let o=de(e,t);if(o.trim()){if(!n)try{let t=P,n=await f.post(`${u(t)}/chat/sessions`,{providerId:i,title:e.slice(0,50)});r(n.id),a(n.providerId),setTimeout(()=>{q(o)},500);return}catch(e){console.error(`Failed to create session:`,e);return}q(o)}},[n,i,P,q,de]),pe=(0,K.useCallback)((e,t)=>{p(e),g(t)},[]),me=(0,K.useCallback)(e=>{v(e),p(!1),g(``),setTimeout(()=>v(null),50)},[]),he=(0,K.useCallback)(()=>{p(!1),g(``)},[]),Z=(0,K.useCallback)((e,t)=>{S(e),w(t)},[]),ge=(0,K.useCallback)(e=>{E(e),S(!1),w(``),setTimeout(()=>E(null),50)},[]),_e=(0,K.useCallback)(()=>{S(!1),w(``)},[]);return(0,Q.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,K.useCallback)(e=>{e.preventDefault(),N.current++,e.dataTransfer.types.includes(`Files`)&&k(!0)},[]),onDragLeave:(0,K.useCallback)(e=>{e.preventDefault(),N.current--,N.current===0&&k(!1)},[]),onDragOver:(0,K.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,K.useCallback)(e=>{e.preventDefault(),N.current=0,k(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&(M(t),setTimeout(()=>M(null),100))},[]),children:[D&&(0,Q.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,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-primary`,children:[(0,Q.jsx)(h,{className:`size-8`}),(0,Q.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),(0,Q.jsx)(ke,{messages:V,messagesLoading:ee,pendingApproval:G,onApprovalResponse:ie,isStreaming:H,streamingStatus:te,connectingElapsed:U,thinkingWarningThreshold:W,projectName:P,onFork:H?void 0:ue}),(0,Q.jsxs)(`div`,{className:`border-t border-border bg-background shrink-0`,children:[(0,Q.jsx)(pt,{projectName:P,usageInfo:L,contextWindowPct:ne,usageLoading:R,refreshUsage:B,lastFetchedAt:z,sessionId:n,onSelectSession:X,onBugReport:n?()=>j(I,{sessionId:n,projectName:P}):void 0,isConnected:J,onReconnect:()=>{J||ce(),le()}}),(0,Q.jsx)(it,{items:c,filter:m,onSelect:me,onClose:he,visible:d}),(0,Q.jsx)(nt,{items:y,filter:C,onSelect:ge,onClose:_e,visible:x}),(0,Q.jsx)(rt,{onSend:fe,isStreaming:H,onCancel:oe,projectName:P,onSlashStateChange:pe,onSlashItemsLoaded:l,slashSelected:_,onFileStateChange:Z,onFileItemsLoaded:b,fileSelected:T,externalFiles:A})]})]})}export{mt as ChatTab};