@harbinger-ai/harbinger 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +406 -0
- package/agents/README.md +76 -0
- package/agents/_template/CONFIG.yaml +7 -0
- package/agents/_template/HEARTBEAT.md +59 -0
- package/agents/_template/IDENTITY.md +4 -0
- package/agents/_template/SKILLS.md +1 -0
- package/agents/_template/SOUL.md +25 -0
- package/agents/_template/TOOLS.md +3 -0
- package/agents/binary-reverser/CONFIG.yaml +21 -0
- package/agents/binary-reverser/HEARTBEAT.md +65 -0
- package/agents/binary-reverser/IDENTITY.md +1 -0
- package/agents/binary-reverser/SKILLS.md +1 -0
- package/agents/binary-reverser/SOUL.md +23 -0
- package/agents/binary-reverser/TOOLS.md +99 -0
- package/agents/browser-agent/CONFIG.yaml +20 -0
- package/agents/browser-agent/HEARTBEAT.md +79 -0
- package/agents/browser-agent/IDENTITY.md +5 -0
- package/agents/browser-agent/SKILLS.md +86 -0
- package/agents/browser-agent/SOUL.md +23 -0
- package/agents/browser-agent/TOOLS.md +186 -0
- package/agents/cloud-infiltrator/CONFIG.yaml +22 -0
- package/agents/cloud-infiltrator/HEARTBEAT.md +78 -0
- package/agents/cloud-infiltrator/IDENTITY.md +1 -0
- package/agents/cloud-infiltrator/SKILLS.md +1 -0
- package/agents/cloud-infiltrator/SOUL.md +23 -0
- package/agents/cloud-infiltrator/TOOLS.md +68 -0
- package/agents/coding-assistant/CONFIG.yaml +22 -0
- package/agents/coding-assistant/HEARTBEAT.md +57 -0
- package/agents/coding-assistant/IDENTITY.md +5 -0
- package/agents/coding-assistant/SKILLS.md +69 -0
- package/agents/coding-assistant/SOUL.md +60 -0
- package/agents/coding-assistant/TOOLS.md +168 -0
- package/agents/learning-agent/CONFIG.yaml +21 -0
- package/agents/learning-agent/HEARTBEAT.md +63 -0
- package/agents/learning-agent/IDENTITY.md +5 -0
- package/agents/learning-agent/SKILLS.md +86 -0
- package/agents/learning-agent/SOUL.md +77 -0
- package/agents/learning-agent/TOOLS.md +145 -0
- package/agents/maintainer/CONFIG.yaml +31 -0
- package/agents/maintainer/HEARTBEAT.md +28 -0
- package/agents/maintainer/IDENTITY.md +33 -0
- package/agents/maintainer/SKILLS.md +24 -0
- package/agents/maintainer/SOUL.md +61 -0
- package/agents/maintainer/TOOLS.md +29 -0
- package/agents/maintainer/lib/engine.js +279 -0
- package/agents/maintainer/lib/safe-fixer.js +183 -0
- package/agents/morning-brief/CONFIG.yaml +22 -0
- package/agents/morning-brief/HEARTBEAT.md +60 -0
- package/agents/morning-brief/IDENTITY.md +5 -0
- package/agents/morning-brief/SKILLS.md +56 -0
- package/agents/morning-brief/SOUL.md +64 -0
- package/agents/morning-brief/TOOLS.md +112 -0
- package/agents/osint-detective/CONFIG.yaml +24 -0
- package/agents/osint-detective/HEARTBEAT.md +66 -0
- package/agents/osint-detective/IDENTITY.md +1 -0
- package/agents/osint-detective/SKILLS.md +1 -0
- package/agents/osint-detective/SOUL.md +23 -0
- package/agents/osint-detective/TOOLS.md +81 -0
- package/agents/recon-scout/CONFIG.yaml +22 -0
- package/agents/recon-scout/HEARTBEAT.md +79 -0
- package/agents/recon-scout/IDENTITY.md +1 -0
- package/agents/recon-scout/SKILLS.md +1 -0
- package/agents/recon-scout/SOUL.md +23 -0
- package/agents/recon-scout/TOOLS.md +93 -0
- package/agents/report-writer/CONFIG.yaml +21 -0
- package/agents/report-writer/HEARTBEAT.md +63 -0
- package/agents/report-writer/IDENTITY.md +1 -0
- package/agents/report-writer/SKILLS.md +1 -0
- package/agents/report-writer/SOUL.md +23 -0
- package/agents/report-writer/TOOLS.md +69 -0
- package/agents/shared/README.md +13 -0
- package/agents/web-hacker/CONFIG.yaml +24 -0
- package/agents/web-hacker/HEARTBEAT.md +78 -0
- package/agents/web-hacker/IDENTITY.md +1 -0
- package/agents/web-hacker/SKILLS.md +1 -0
- package/agents/web-hacker/SOUL.md +23 -0
- package/agents/web-hacker/TOOLS.md +86 -0
- package/api/CLAUDE.md +19 -0
- package/api/index.js +274 -0
- package/bin/cli.js +620 -0
- package/bin/local.sh +31 -0
- package/bin/postinstall.js +63 -0
- package/config/index.js +24 -0
- package/config/instrumentation.js +93 -0
- package/drizzle/0000_initial.sql +52 -0
- package/drizzle/0001_bounty_and_registry.sql +82 -0
- package/drizzle/0002_sync_columns.sql +7 -0
- package/drizzle/0003_graceful_bloodscream.sql +86 -0
- package/drizzle/meta/0000_snapshot.json +321 -0
- package/drizzle/meta/0003_snapshot.json +878 -0
- package/drizzle/meta/_journal.json +34 -0
- package/drizzle/relations.ts +3 -0
- package/drizzle/schema.ts +145 -0
- package/lib/actions.js +47 -0
- package/lib/agents.js +166 -0
- package/lib/ai/agent.js +96 -0
- package/lib/ai/autonomous-engine.js +261 -0
- package/lib/ai/index.js +359 -0
- package/lib/ai/model-router.js +254 -0
- package/lib/ai/model.js +73 -0
- package/lib/ai/tools.js +84 -0
- package/lib/auth/actions.js +28 -0
- package/lib/auth/config.js +27 -0
- package/lib/auth/edge-config.js +27 -0
- package/lib/auth/index.js +27 -0
- package/lib/auth/middleware.js +53 -0
- package/lib/bounty/actions.js +119 -0
- package/lib/bounty/findings.js +64 -0
- package/lib/bounty/programs.js +34 -0
- package/lib/bounty/sync-targets.js +267 -0
- package/lib/bounty/targets.js +33 -0
- package/lib/channels/base.js +56 -0
- package/lib/channels/index.js +15 -0
- package/lib/channels/telegram.js +148 -0
- package/lib/chat/actions.js +288 -0
- package/lib/chat/api.js +135 -0
- package/lib/chat/components/app-sidebar.js +237 -0
- package/lib/chat/components/app-sidebar.jsx +289 -0
- package/lib/chat/components/chat-header.js +27 -0
- package/lib/chat/components/chat-header.jsx +37 -0
- package/lib/chat/components/chat-input.js +230 -0
- package/lib/chat/components/chat-input.jsx +228 -0
- package/lib/chat/components/chat-nav-context.js +11 -0
- package/lib/chat/components/chat-nav-context.jsx +11 -0
- package/lib/chat/components/chat-page.js +81 -0
- package/lib/chat/components/chat-page.jsx +100 -0
- package/lib/chat/components/chat.js +150 -0
- package/lib/chat/components/chat.jsx +182 -0
- package/lib/chat/components/chats-page.js +302 -0
- package/lib/chat/components/chats-page.jsx +330 -0
- package/lib/chat/components/crons-page.js +172 -0
- package/lib/chat/components/crons-page.jsx +244 -0
- package/lib/chat/components/enhanced-tool-call.js +103 -0
- package/lib/chat/components/enhanced-tool-call.jsx +139 -0
- package/lib/chat/components/findings-page.js +175 -0
- package/lib/chat/components/findings-page.jsx +214 -0
- package/lib/chat/components/greeting.js +22 -0
- package/lib/chat/components/greeting.jsx +26 -0
- package/lib/chat/components/icons.js +777 -0
- package/lib/chat/components/icons.jsx +741 -0
- package/lib/chat/components/index.js +26 -0
- package/lib/chat/components/mcp-page.js +260 -0
- package/lib/chat/components/mcp-page.jsx +355 -0
- package/lib/chat/components/message.js +289 -0
- package/lib/chat/components/message.jsx +315 -0
- package/lib/chat/components/messages.js +66 -0
- package/lib/chat/components/messages.jsx +77 -0
- package/lib/chat/components/notifications-page.js +56 -0
- package/lib/chat/components/notifications-page.jsx +87 -0
- package/lib/chat/components/page-layout.js +21 -0
- package/lib/chat/components/page-layout.jsx +28 -0
- package/lib/chat/components/registry-page.js +222 -0
- package/lib/chat/components/registry-page.jsx +255 -0
- package/lib/chat/components/settings-layout.js +40 -0
- package/lib/chat/components/settings-layout.jsx +54 -0
- package/lib/chat/components/settings-secrets-page.js +216 -0
- package/lib/chat/components/settings-secrets-page.jsx +264 -0
- package/lib/chat/components/sidebar-history-item.js +132 -0
- package/lib/chat/components/sidebar-history-item.jsx +113 -0
- package/lib/chat/components/sidebar-history.js +115 -0
- package/lib/chat/components/sidebar-history.jsx +157 -0
- package/lib/chat/components/sidebar-user-nav.js +63 -0
- package/lib/chat/components/sidebar-user-nav.jsx +73 -0
- package/lib/chat/components/status-bar.js +39 -0
- package/lib/chat/components/status-bar.jsx +51 -0
- package/lib/chat/components/swarm-page.js +157 -0
- package/lib/chat/components/swarm-page.jsx +210 -0
- package/lib/chat/components/targets-page.js +376 -0
- package/lib/chat/components/targets-page.jsx +389 -0
- package/lib/chat/components/tool-call.js +86 -0
- package/lib/chat/components/tool-call.jsx +104 -0
- package/lib/chat/components/tool-panel.js +107 -0
- package/lib/chat/components/tool-panel.jsx +145 -0
- package/lib/chat/components/triggers-page.js +153 -0
- package/lib/chat/components/triggers-page.jsx +221 -0
- package/lib/chat/components/ui/confirm-dialog.js +53 -0
- package/lib/chat/components/ui/confirm-dialog.jsx +57 -0
- package/lib/chat/components/ui/dropdown-menu.js +98 -0
- package/lib/chat/components/ui/dropdown-menu.jsx +116 -0
- package/lib/chat/components/ui/rename-dialog.js +74 -0
- package/lib/chat/components/ui/rename-dialog.jsx +72 -0
- package/lib/chat/components/ui/scroll-area.js +13 -0
- package/lib/chat/components/ui/scroll-area.jsx +17 -0
- package/lib/chat/components/ui/separator.js +21 -0
- package/lib/chat/components/ui/separator.jsx +18 -0
- package/lib/chat/components/ui/sheet.js +75 -0
- package/lib/chat/components/ui/sheet.jsx +95 -0
- package/lib/chat/components/ui/sidebar.js +227 -0
- package/lib/chat/components/ui/sidebar.jsx +245 -0
- package/lib/chat/components/ui/tooltip.js +56 -0
- package/lib/chat/components/ui/tooltip.jsx +66 -0
- package/lib/chat/components/upgrade-dialog.js +151 -0
- package/lib/chat/components/upgrade-dialog.jsx +170 -0
- package/lib/chat/utils.js +11 -0
- package/lib/cron.js +246 -0
- package/lib/db/api-keys.js +163 -0
- package/lib/db/chats.js +145 -0
- package/lib/db/index.js +52 -0
- package/lib/db/notifications.js +99 -0
- package/lib/db/schema.js +145 -0
- package/lib/db/update-check.js +96 -0
- package/lib/db/users.js +89 -0
- package/lib/mcp/actions.js +104 -0
- package/lib/mcp/client.js +79 -0
- package/lib/mcp/handler.js +57 -0
- package/lib/mcp/server.js +165 -0
- package/lib/paths.js +46 -0
- package/lib/registry/actions.js +164 -0
- package/lib/registry/catalog.js +137 -0
- package/lib/registry/tools.js +71 -0
- package/lib/tools/create-job.js +99 -0
- package/lib/tools/github.js +217 -0
- package/lib/tools/openai.js +35 -0
- package/lib/tools/telegram.js +292 -0
- package/lib/triggers.js +118 -0
- package/lib/utils/render-md.js +102 -0
- package/package.json +103 -0
- package/setup/lib/auth.mjs +81 -0
- package/setup/lib/env.mjs +21 -0
- package/setup/lib/fs-utils.mjs +20 -0
- package/setup/lib/github.mjs +149 -0
- package/setup/lib/prerequisites.mjs +155 -0
- package/setup/lib/prompts.mjs +267 -0
- package/setup/lib/providers.mjs +48 -0
- package/setup/lib/sync.mjs +125 -0
- package/setup/lib/targets.mjs +45 -0
- package/setup/lib/telegram-verify.mjs +63 -0
- package/setup/lib/telegram.mjs +76 -0
- package/setup/setup-telegram.mjs +264 -0
- package/setup/setup.mjs +842 -0
- package/templates/.dockerignore +5 -0
- package/templates/.env.example +63 -0
- package/templates/.github/workflows/auto-merge.yml +117 -0
- package/templates/.github/workflows/build-image.yml +36 -0
- package/templates/.github/workflows/notify-job-failed.yml +64 -0
- package/templates/.github/workflows/notify-pr-complete.yml +119 -0
- package/templates/.github/workflows/rebuild-event-handler.yml +121 -0
- package/templates/.github/workflows/run-job.yml +89 -0
- package/templates/.github/workflows/upgrade-event-handler.yml +62 -0
- package/templates/.gitignore.template +45 -0
- package/templates/.pi/extensions/env-sanitizer/index.ts +48 -0
- package/templates/.pi/extensions/env-sanitizer/package.json +5 -0
- package/templates/CLAUDE.md +29 -0
- package/templates/CLAUDE.md.template +307 -0
- package/templates/app/api/[...thepopebot]/route.js +1 -0
- package/templates/app/api/auth/[...nextauth]/route.js +1 -0
- package/templates/app/chat/[chatId]/page.js +8 -0
- package/templates/app/chats/page.js +7 -0
- package/templates/app/components/ascii-logo.jsx +10 -0
- package/templates/app/components/login-form.jsx +92 -0
- package/templates/app/components/setup-form.jsx +82 -0
- package/templates/app/components/theme-provider.jsx +11 -0
- package/templates/app/components/theme-toggle.jsx +38 -0
- package/templates/app/components/ui/button.jsx +21 -0
- package/templates/app/components/ui/card.jsx +23 -0
- package/templates/app/components/ui/input.jsx +10 -0
- package/templates/app/components/ui/label.jsx +10 -0
- package/templates/app/crons/page.js +5 -0
- package/templates/app/findings/page.js +7 -0
- package/templates/app/globals.css +90 -0
- package/templates/app/layout.js +19 -0
- package/templates/app/login/page.js +15 -0
- package/templates/app/notifications/page.js +7 -0
- package/templates/app/page.js +7 -0
- package/templates/app/settings/crons/page.js +5 -0
- package/templates/app/settings/layout.js +7 -0
- package/templates/app/settings/mcp/page.js +5 -0
- package/templates/app/settings/page.js +5 -0
- package/templates/app/settings/secrets/page.js +5 -0
- package/templates/app/settings/triggers/page.js +5 -0
- package/templates/app/stream/chat/route.js +1 -0
- package/templates/app/swarm/page.js +7 -0
- package/templates/app/targets/page.js +7 -0
- package/templates/app/toolbox/page.js +7 -0
- package/templates/app/triggers/page.js +5 -0
- package/templates/config/AGENT.md +34 -0
- package/templates/config/CRONS.json +56 -0
- package/templates/config/EVENT_HANDLER.md +224 -0
- package/templates/config/HEARTBEAT.md +3 -0
- package/templates/config/JOB_SUMMARY.md +130 -0
- package/templates/config/MCP_SERVERS.json +1 -0
- package/templates/config/SKILL_BUILDING_GUIDE.md +90 -0
- package/templates/config/SOUL.md +17 -0
- package/templates/config/TRIGGERS.json +58 -0
- package/templates/docker/event-handler/Dockerfile +20 -0
- package/templates/docker/event-handler/ecosystem.config.cjs +8 -0
- package/templates/docker/job-claude-code/Dockerfile +34 -0
- package/templates/docker/job-claude-code/entrypoint.sh +139 -0
- package/templates/docker/job-pi-coding-agent/Dockerfile +44 -0
- package/templates/docker/job-pi-coding-agent/entrypoint.sh +163 -0
- package/templates/docker-compose.yml +63 -0
- package/templates/instrumentation.js +6 -0
- package/templates/middleware.js +1 -0
- package/templates/next.config.mjs +3 -0
- package/templates/postcss.config.mjs +5 -0
- package/templates/skills/LICENSE +21 -0
- package/templates/skills/README.md +119 -0
- package/templates/skills/brave-search/SKILL.md +79 -0
- package/templates/skills/brave-search/content.js +86 -0
- package/templates/skills/brave-search/package-lock.json +621 -0
- package/templates/skills/brave-search/package.json +14 -0
- package/templates/skills/brave-search/search.js +199 -0
- package/templates/skills/browser-tools/SKILL.md +196 -0
- package/templates/skills/browser-tools/browser-content.js +103 -0
- package/templates/skills/browser-tools/browser-cookies.js +35 -0
- package/templates/skills/browser-tools/browser-eval.js +53 -0
- package/templates/skills/browser-tools/browser-hn-scraper.js +108 -0
- package/templates/skills/browser-tools/browser-nav.js +44 -0
- package/templates/skills/browser-tools/browser-pick.js +162 -0
- package/templates/skills/browser-tools/browser-screenshot.js +34 -0
- package/templates/skills/browser-tools/browser-start.js +87 -0
- package/templates/skills/browser-tools/package-lock.json +2556 -0
- package/templates/skills/browser-tools/package.json +19 -0
- package/templates/skills/llm-secrets/SKILL.md +34 -0
- package/templates/skills/llm-secrets/llm-secrets.js +33 -0
- package/templates/skills/modify-self/SKILL.md +12 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useChat } from "@ai-sdk/react";
|
|
4
|
+
import { DefaultChatTransport } from "ai";
|
|
5
|
+
import { useState, useEffect, useRef, useMemo, useCallback } from "react";
|
|
6
|
+
import { Messages } from "./messages.js";
|
|
7
|
+
import { ChatInput } from "./chat-input.js";
|
|
8
|
+
import { ChatHeader } from "./chat-header.js";
|
|
9
|
+
import { StatusBar } from "./status-bar.js";
|
|
10
|
+
import { ToolPanel } from "./tool-panel.js";
|
|
11
|
+
import { Greeting } from "./greeting.js";
|
|
12
|
+
function Chat({ chatId, initialMessages = [] }) {
|
|
13
|
+
const [input, setInput] = useState("");
|
|
14
|
+
const [files, setFiles] = useState([]);
|
|
15
|
+
const [showToolPanel, setShowToolPanel] = useState(false);
|
|
16
|
+
const hasNavigated = useRef(false);
|
|
17
|
+
const transport = useMemo(
|
|
18
|
+
() => new DefaultChatTransport({
|
|
19
|
+
api: "/stream/chat",
|
|
20
|
+
body: { chatId }
|
|
21
|
+
}),
|
|
22
|
+
[chatId]
|
|
23
|
+
);
|
|
24
|
+
const {
|
|
25
|
+
messages,
|
|
26
|
+
status,
|
|
27
|
+
stop,
|
|
28
|
+
error,
|
|
29
|
+
sendMessage,
|
|
30
|
+
regenerate,
|
|
31
|
+
setMessages
|
|
32
|
+
} = useChat({
|
|
33
|
+
id: chatId,
|
|
34
|
+
messages: initialMessages,
|
|
35
|
+
transport,
|
|
36
|
+
onError: (err) => console.error("Chat error:", err)
|
|
37
|
+
});
|
|
38
|
+
const toolCount = useMemo(() => {
|
|
39
|
+
let count = 0;
|
|
40
|
+
for (const msg of messages) {
|
|
41
|
+
if (!msg.parts) continue;
|
|
42
|
+
for (const part of msg.parts) {
|
|
43
|
+
if (part.type?.startsWith("tool-")) count++;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return count;
|
|
47
|
+
}, [messages]);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (toolCount > 0 && !showToolPanel) {
|
|
50
|
+
setShowToolPanel(true);
|
|
51
|
+
}
|
|
52
|
+
}, [toolCount]);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (!hasNavigated.current && messages.length >= 1 && status !== "ready" && window.location.pathname !== `/chat/${chatId}`) {
|
|
55
|
+
hasNavigated.current = true;
|
|
56
|
+
window.history.replaceState({}, "", `/chat/${chatId}`);
|
|
57
|
+
window.dispatchEvent(new Event("chatsupdated"));
|
|
58
|
+
setTimeout(() => window.dispatchEvent(new Event("chatsupdated")), 5e3);
|
|
59
|
+
}
|
|
60
|
+
}, [messages.length, status, chatId]);
|
|
61
|
+
const handleSend = () => {
|
|
62
|
+
if (!input.trim() && files.length === 0) return;
|
|
63
|
+
const text = input;
|
|
64
|
+
const currentFiles = files;
|
|
65
|
+
setInput("");
|
|
66
|
+
setFiles([]);
|
|
67
|
+
if (currentFiles.length === 0) {
|
|
68
|
+
sendMessage({ text });
|
|
69
|
+
} else {
|
|
70
|
+
const fileParts = currentFiles.map((f) => ({
|
|
71
|
+
type: "file",
|
|
72
|
+
mediaType: f.file.type || "text/plain",
|
|
73
|
+
url: f.previewUrl,
|
|
74
|
+
filename: f.file.name
|
|
75
|
+
}));
|
|
76
|
+
sendMessage({ text: text || void 0, files: fileParts });
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const handleRetry = useCallback((message) => {
|
|
80
|
+
if (message.role === "assistant") {
|
|
81
|
+
regenerate({ messageId: message.id });
|
|
82
|
+
} else {
|
|
83
|
+
const idx = messages.findIndex((m) => m.id === message.id);
|
|
84
|
+
const nextAssistant = messages.slice(idx + 1).find((m) => m.role === "assistant");
|
|
85
|
+
if (nextAssistant) {
|
|
86
|
+
regenerate({ messageId: nextAssistant.id });
|
|
87
|
+
} else {
|
|
88
|
+
const text = message.parts?.filter((p) => p.type === "text").map((p) => p.text).join("\n") || message.content || "";
|
|
89
|
+
if (text.trim()) {
|
|
90
|
+
sendMessage({ text });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}, [messages, regenerate, sendMessage]);
|
|
95
|
+
const handleEdit = useCallback((message, newText) => {
|
|
96
|
+
const idx = messages.findIndex((m) => m.id === message.id);
|
|
97
|
+
if (idx === -1) return;
|
|
98
|
+
setMessages(messages.slice(0, idx));
|
|
99
|
+
sendMessage({ text: newText });
|
|
100
|
+
}, [messages, setMessages, sendMessage]);
|
|
101
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex h-svh flex-col", children: [
|
|
102
|
+
/* @__PURE__ */ jsx(ChatHeader, { chatId }),
|
|
103
|
+
/* @__PURE__ */ jsx(
|
|
104
|
+
StatusBar,
|
|
105
|
+
{
|
|
106
|
+
status,
|
|
107
|
+
toolCount,
|
|
108
|
+
showToolPanel,
|
|
109
|
+
onToggleToolPanel: () => setShowToolPanel(!showToolPanel)
|
|
110
|
+
}
|
|
111
|
+
),
|
|
112
|
+
messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center justify-center px-4 md:px-6", children: /* @__PURE__ */ jsxs("div", { className: "w-full max-w-4xl", children: [
|
|
113
|
+
/* @__PURE__ */ jsx(Greeting, {}),
|
|
114
|
+
error && /* @__PURE__ */ jsx("div", { className: "mt-4 rounded-lg border border-[--destructive]/30 bg-[--destructive]/10 px-4 py-2 text-sm text-[--destructive]", children: error.message || "Something went wrong. Please try again." }),
|
|
115
|
+
/* @__PURE__ */ jsx("div", { className: "mt-4", children: /* @__PURE__ */ jsx(
|
|
116
|
+
ChatInput,
|
|
117
|
+
{
|
|
118
|
+
input,
|
|
119
|
+
setInput,
|
|
120
|
+
onSubmit: handleSend,
|
|
121
|
+
status,
|
|
122
|
+
stop,
|
|
123
|
+
files,
|
|
124
|
+
setFiles
|
|
125
|
+
}
|
|
126
|
+
) })
|
|
127
|
+
] }) }) : /* @__PURE__ */ jsxs("div", { className: "flex flex-1 min-h-0", children: [
|
|
128
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col min-w-0", children: [
|
|
129
|
+
/* @__PURE__ */ jsx(Messages, { messages, status, onRetry: handleRetry, onEdit: handleEdit }),
|
|
130
|
+
error && /* @__PURE__ */ jsx("div", { className: "mx-auto w-full max-w-4xl px-2 md:px-4", children: /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-[--destructive]/30 bg-[--destructive]/10 px-4 py-2 text-sm text-[--destructive]", children: error.message || "Something went wrong. Please try again." }) }),
|
|
131
|
+
/* @__PURE__ */ jsx(
|
|
132
|
+
ChatInput,
|
|
133
|
+
{
|
|
134
|
+
input,
|
|
135
|
+
setInput,
|
|
136
|
+
onSubmit: handleSend,
|
|
137
|
+
status,
|
|
138
|
+
stop,
|
|
139
|
+
files,
|
|
140
|
+
setFiles
|
|
141
|
+
}
|
|
142
|
+
)
|
|
143
|
+
] }),
|
|
144
|
+
/* @__PURE__ */ jsx(ToolPanel, { messages, show: showToolPanel })
|
|
145
|
+
] })
|
|
146
|
+
] });
|
|
147
|
+
}
|
|
148
|
+
export {
|
|
149
|
+
Chat
|
|
150
|
+
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useChat } from '@ai-sdk/react';
|
|
4
|
+
import { DefaultChatTransport } from 'ai';
|
|
5
|
+
import { useState, useEffect, useRef, useMemo, useCallback } from 'react';
|
|
6
|
+
import { Messages } from './messages.js';
|
|
7
|
+
import { ChatInput } from './chat-input.js';
|
|
8
|
+
import { ChatHeader } from './chat-header.js';
|
|
9
|
+
import { StatusBar } from './status-bar.js';
|
|
10
|
+
import { ToolPanel } from './tool-panel.js';
|
|
11
|
+
import { Greeting } from './greeting.js';
|
|
12
|
+
|
|
13
|
+
export function Chat({ chatId, initialMessages = [] }) {
|
|
14
|
+
const [input, setInput] = useState('');
|
|
15
|
+
const [files, setFiles] = useState([]);
|
|
16
|
+
const [showToolPanel, setShowToolPanel] = useState(false);
|
|
17
|
+
const hasNavigated = useRef(false);
|
|
18
|
+
|
|
19
|
+
const transport = useMemo(
|
|
20
|
+
() =>
|
|
21
|
+
new DefaultChatTransport({
|
|
22
|
+
api: '/stream/chat',
|
|
23
|
+
body: { chatId },
|
|
24
|
+
}),
|
|
25
|
+
[chatId]
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
messages,
|
|
30
|
+
status,
|
|
31
|
+
stop,
|
|
32
|
+
error,
|
|
33
|
+
sendMessage,
|
|
34
|
+
regenerate,
|
|
35
|
+
setMessages,
|
|
36
|
+
} = useChat({
|
|
37
|
+
id: chatId,
|
|
38
|
+
messages: initialMessages,
|
|
39
|
+
transport,
|
|
40
|
+
onError: (err) => console.error('Chat error:', err),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Count tool parts for status bar
|
|
44
|
+
const toolCount = useMemo(() => {
|
|
45
|
+
let count = 0;
|
|
46
|
+
for (const msg of messages) {
|
|
47
|
+
if (!msg.parts) continue;
|
|
48
|
+
for (const part of msg.parts) {
|
|
49
|
+
if (part.type?.startsWith('tool-')) count++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return count;
|
|
53
|
+
}, [messages]);
|
|
54
|
+
|
|
55
|
+
// Auto-show tool panel when tools are detected
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (toolCount > 0 && !showToolPanel) {
|
|
58
|
+
setShowToolPanel(true);
|
|
59
|
+
}
|
|
60
|
+
}, [toolCount]);
|
|
61
|
+
|
|
62
|
+
// After first message sent, update URL and notify sidebar
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (!hasNavigated.current && messages.length >= 1 && status !== 'ready' && window.location.pathname !== `/chat/${chatId}`) {
|
|
65
|
+
hasNavigated.current = true;
|
|
66
|
+
window.history.replaceState({}, '', `/chat/${chatId}`);
|
|
67
|
+
window.dispatchEvent(new Event('chatsupdated'));
|
|
68
|
+
setTimeout(() => window.dispatchEvent(new Event('chatsupdated')), 5000);
|
|
69
|
+
}
|
|
70
|
+
}, [messages.length, status, chatId]);
|
|
71
|
+
|
|
72
|
+
const handleSend = () => {
|
|
73
|
+
if (!input.trim() && files.length === 0) return;
|
|
74
|
+
const text = input;
|
|
75
|
+
const currentFiles = files;
|
|
76
|
+
setInput('');
|
|
77
|
+
setFiles([]);
|
|
78
|
+
|
|
79
|
+
if (currentFiles.length === 0) {
|
|
80
|
+
sendMessage({ text });
|
|
81
|
+
} else {
|
|
82
|
+
const fileParts = currentFiles.map((f) => ({
|
|
83
|
+
type: 'file',
|
|
84
|
+
mediaType: f.file.type || 'text/plain',
|
|
85
|
+
url: f.previewUrl,
|
|
86
|
+
filename: f.file.name,
|
|
87
|
+
}));
|
|
88
|
+
sendMessage({ text: text || undefined, files: fileParts });
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const handleRetry = useCallback((message) => {
|
|
93
|
+
if (message.role === 'assistant') {
|
|
94
|
+
regenerate({ messageId: message.id });
|
|
95
|
+
} else {
|
|
96
|
+
const idx = messages.findIndex((m) => m.id === message.id);
|
|
97
|
+
const nextAssistant = messages.slice(idx + 1).find((m) => m.role === 'assistant');
|
|
98
|
+
if (nextAssistant) {
|
|
99
|
+
regenerate({ messageId: nextAssistant.id });
|
|
100
|
+
} else {
|
|
101
|
+
const text =
|
|
102
|
+
message.parts
|
|
103
|
+
?.filter((p) => p.type === 'text')
|
|
104
|
+
.map((p) => p.text)
|
|
105
|
+
.join('\n') ||
|
|
106
|
+
message.content ||
|
|
107
|
+
'';
|
|
108
|
+
if (text.trim()) {
|
|
109
|
+
sendMessage({ text });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}, [messages, regenerate, sendMessage]);
|
|
114
|
+
|
|
115
|
+
const handleEdit = useCallback((message, newText) => {
|
|
116
|
+
const idx = messages.findIndex((m) => m.id === message.id);
|
|
117
|
+
if (idx === -1) return;
|
|
118
|
+
setMessages(messages.slice(0, idx));
|
|
119
|
+
sendMessage({ text: newText });
|
|
120
|
+
}, [messages, setMessages, sendMessage]);
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<div className="flex h-svh flex-col">
|
|
124
|
+
<ChatHeader chatId={chatId} />
|
|
125
|
+
<StatusBar
|
|
126
|
+
status={status}
|
|
127
|
+
toolCount={toolCount}
|
|
128
|
+
showToolPanel={showToolPanel}
|
|
129
|
+
onToggleToolPanel={() => setShowToolPanel(!showToolPanel)}
|
|
130
|
+
/>
|
|
131
|
+
{messages.length === 0 ? (
|
|
132
|
+
<div className="flex flex-1 flex-col items-center justify-center px-4 md:px-6">
|
|
133
|
+
<div className="w-full max-w-4xl">
|
|
134
|
+
<Greeting />
|
|
135
|
+
{error && (
|
|
136
|
+
<div className="mt-4 rounded-lg border border-[--destructive]/30 bg-[--destructive]/10 px-4 py-2 text-sm text-[--destructive]">
|
|
137
|
+
{error.message || 'Something went wrong. Please try again.'}
|
|
138
|
+
</div>
|
|
139
|
+
)}
|
|
140
|
+
<div className="mt-4">
|
|
141
|
+
<ChatInput
|
|
142
|
+
input={input}
|
|
143
|
+
setInput={setInput}
|
|
144
|
+
onSubmit={handleSend}
|
|
145
|
+
status={status}
|
|
146
|
+
stop={stop}
|
|
147
|
+
files={files}
|
|
148
|
+
setFiles={setFiles}
|
|
149
|
+
/>
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
</div>
|
|
153
|
+
) : (
|
|
154
|
+
<div className="flex flex-1 min-h-0">
|
|
155
|
+
{/* Main chat area */}
|
|
156
|
+
<div className="flex flex-1 flex-col min-w-0">
|
|
157
|
+
<Messages messages={messages} status={status} onRetry={handleRetry} onEdit={handleEdit} />
|
|
158
|
+
{error && (
|
|
159
|
+
<div className="mx-auto w-full max-w-4xl px-2 md:px-4">
|
|
160
|
+
<div className="rounded-lg border border-[--destructive]/30 bg-[--destructive]/10 px-4 py-2 text-sm text-[--destructive]">
|
|
161
|
+
{error.message || 'Something went wrong. Please try again.'}
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
)}
|
|
165
|
+
<ChatInput
|
|
166
|
+
input={input}
|
|
167
|
+
setInput={setInput}
|
|
168
|
+
onSubmit={handleSend}
|
|
169
|
+
status={status}
|
|
170
|
+
stop={stop}
|
|
171
|
+
files={files}
|
|
172
|
+
setFiles={setFiles}
|
|
173
|
+
/>
|
|
174
|
+
</div>
|
|
175
|
+
|
|
176
|
+
{/* Right tool panel */}
|
|
177
|
+
<ToolPanel messages={messages} show={showToolPanel} />
|
|
178
|
+
</div>
|
|
179
|
+
)}
|
|
180
|
+
</div>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useEffect, useRef } from "react";
|
|
4
|
+
import { PageLayout } from "./page-layout.js";
|
|
5
|
+
import { MessageIcon, TrashIcon, SearchIcon, PlusIcon, MoreHorizontalIcon, StarIcon, StarFilledIcon, PencilIcon } from "./icons.js";
|
|
6
|
+
import { getChats, deleteChat, renameChat, starChat } from "../actions.js";
|
|
7
|
+
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator } from "./ui/dropdown-menu.js";
|
|
8
|
+
import { ConfirmDialog } from "./ui/confirm-dialog.js";
|
|
9
|
+
import { cn } from "../utils.js";
|
|
10
|
+
function groupChatsByDate(chats) {
|
|
11
|
+
const now = /* @__PURE__ */ new Date();
|
|
12
|
+
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
13
|
+
const yesterday = new Date(today.getTime() - 864e5);
|
|
14
|
+
const last7Days = new Date(today.getTime() - 7 * 864e5);
|
|
15
|
+
const last30Days = new Date(today.getTime() - 30 * 864e5);
|
|
16
|
+
const groups = {
|
|
17
|
+
Starred: [],
|
|
18
|
+
Today: [],
|
|
19
|
+
Yesterday: [],
|
|
20
|
+
"Last 7 Days": [],
|
|
21
|
+
"Last 30 Days": [],
|
|
22
|
+
Older: []
|
|
23
|
+
};
|
|
24
|
+
for (const chat of chats) {
|
|
25
|
+
if (chat.starred) {
|
|
26
|
+
groups.Starred.push(chat);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const date = new Date(chat.updatedAt);
|
|
30
|
+
if (date >= today) {
|
|
31
|
+
groups.Today.push(chat);
|
|
32
|
+
} else if (date >= yesterday) {
|
|
33
|
+
groups.Yesterday.push(chat);
|
|
34
|
+
} else if (date >= last7Days) {
|
|
35
|
+
groups["Last 7 Days"].push(chat);
|
|
36
|
+
} else if (date >= last30Days) {
|
|
37
|
+
groups["Last 30 Days"].push(chat);
|
|
38
|
+
} else {
|
|
39
|
+
groups.Older.push(chat);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return groups;
|
|
43
|
+
}
|
|
44
|
+
function timeAgo(date) {
|
|
45
|
+
const seconds = Math.floor((Date.now() - new Date(date).getTime()) / 1e3);
|
|
46
|
+
if (seconds < 60) return "just now";
|
|
47
|
+
const minutes = Math.floor(seconds / 60);
|
|
48
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
49
|
+
const hours = Math.floor(minutes / 60);
|
|
50
|
+
if (hours < 24) return `${hours}h ago`;
|
|
51
|
+
const days = Math.floor(hours / 24);
|
|
52
|
+
if (days < 30) return `${days}d ago`;
|
|
53
|
+
const months = Math.floor(days / 30);
|
|
54
|
+
return `${months}mo ago`;
|
|
55
|
+
}
|
|
56
|
+
function ChatsPage({ session }) {
|
|
57
|
+
const [chats, setChats] = useState([]);
|
|
58
|
+
const [loading, setLoading] = useState(true);
|
|
59
|
+
const [query, setQuery] = useState("");
|
|
60
|
+
const navigateToChat = (id) => {
|
|
61
|
+
window.location.href = id ? `/chat/${id}` : "/";
|
|
62
|
+
};
|
|
63
|
+
const loadChats = async () => {
|
|
64
|
+
try {
|
|
65
|
+
const result = await getChats();
|
|
66
|
+
setChats(result);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
console.error("Failed to load chats:", err);
|
|
69
|
+
} finally {
|
|
70
|
+
setLoading(false);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
loadChats();
|
|
75
|
+
}, []);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
const handler = () => loadChats();
|
|
78
|
+
window.addEventListener("chatsupdated", handler);
|
|
79
|
+
return () => window.removeEventListener("chatsupdated", handler);
|
|
80
|
+
}, []);
|
|
81
|
+
const handleDelete = async (chatId) => {
|
|
82
|
+
setChats((prev) => prev.filter((c) => c.id !== chatId));
|
|
83
|
+
const { success } = await deleteChat(chatId);
|
|
84
|
+
if (!success) loadChats();
|
|
85
|
+
};
|
|
86
|
+
const handleStar = async (chatId) => {
|
|
87
|
+
setChats(
|
|
88
|
+
(prev) => prev.map((c) => c.id === chatId ? { ...c, starred: c.starred ? 0 : 1 } : c)
|
|
89
|
+
);
|
|
90
|
+
const { success } = await starChat(chatId);
|
|
91
|
+
if (!success) loadChats();
|
|
92
|
+
};
|
|
93
|
+
const handleRename = async (chatId, title) => {
|
|
94
|
+
setChats(
|
|
95
|
+
(prev) => prev.map((c) => c.id === chatId ? { ...c, title } : c)
|
|
96
|
+
);
|
|
97
|
+
const { success } = await renameChat(chatId, title);
|
|
98
|
+
if (!success) loadChats();
|
|
99
|
+
};
|
|
100
|
+
const filtered = query ? chats.filter((c) => c.title?.toLowerCase().includes(query.toLowerCase())) : chats;
|
|
101
|
+
const grouped = groupChatsByDate(filtered);
|
|
102
|
+
return /* @__PURE__ */ jsxs(PageLayout, { session, children: [
|
|
103
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-6", children: [
|
|
104
|
+
/* @__PURE__ */ jsx("h1", { className: "text-2xl font-semibold", children: "Chats" }),
|
|
105
|
+
/* @__PURE__ */ jsxs(
|
|
106
|
+
"button",
|
|
107
|
+
{
|
|
108
|
+
onClick: () => navigateToChat(null),
|
|
109
|
+
className: "inline-flex items-center gap-2 rounded-md px-3 py-2 text-sm font-medium bg-foreground text-background hover:bg-foreground/90",
|
|
110
|
+
children: [
|
|
111
|
+
/* @__PURE__ */ jsx(PlusIcon, { size: 14 }),
|
|
112
|
+
"New chat"
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
)
|
|
116
|
+
] }),
|
|
117
|
+
/* @__PURE__ */ jsxs("div", { className: "relative mb-4", children: [
|
|
118
|
+
/* @__PURE__ */ jsx(
|
|
119
|
+
"input",
|
|
120
|
+
{
|
|
121
|
+
type: "text",
|
|
122
|
+
placeholder: "Search your chats...",
|
|
123
|
+
value: query,
|
|
124
|
+
onChange: (e) => setQuery(e.target.value),
|
|
125
|
+
className: "w-full rounded-md border border-input bg-background px-9 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"
|
|
126
|
+
}
|
|
127
|
+
),
|
|
128
|
+
/* @__PURE__ */ jsx("div", { className: "absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none", children: /* @__PURE__ */ jsx(SearchIcon, { size: 16 }) })
|
|
129
|
+
] }),
|
|
130
|
+
/* @__PURE__ */ jsxs("p", { className: "text-sm text-muted-foreground mb-4", children: [
|
|
131
|
+
filtered.length,
|
|
132
|
+
" ",
|
|
133
|
+
filtered.length === 1 ? "chat" : "chats"
|
|
134
|
+
] }),
|
|
135
|
+
loading ? /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-3", children: [...Array(5)].map((_, i) => /* @__PURE__ */ jsx("div", { className: "h-14 animate-pulse rounded-md bg-border/50" }, i)) }) : filtered.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground py-8 text-center", children: query ? "No chats match your search." : "No chats yet. Start a conversation!" }) : /* @__PURE__ */ jsx("div", { className: "flex flex-col", children: Object.entries(grouped).map(
|
|
136
|
+
([label, groupChats]) => groupChats.length > 0 ? /* @__PURE__ */ jsxs("div", { className: "mb-4", children: [
|
|
137
|
+
/* @__PURE__ */ jsx("h2", { className: "text-xs font-medium text-muted-foreground uppercase tracking-wider mb-2", children: label }),
|
|
138
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col divide-y divide-border", children: groupChats.map((chat) => /* @__PURE__ */ jsx(
|
|
139
|
+
ChatRow,
|
|
140
|
+
{
|
|
141
|
+
chat,
|
|
142
|
+
onNavigate: navigateToChat,
|
|
143
|
+
onDelete: handleDelete,
|
|
144
|
+
onStar: handleStar,
|
|
145
|
+
onRename: handleRename
|
|
146
|
+
},
|
|
147
|
+
chat.id
|
|
148
|
+
)) })
|
|
149
|
+
] }, label) : null
|
|
150
|
+
) })
|
|
151
|
+
] });
|
|
152
|
+
}
|
|
153
|
+
function ChatRow({ chat, onNavigate, onDelete, onStar, onRename }) {
|
|
154
|
+
const [hovered, setHovered] = useState(false);
|
|
155
|
+
const [dropdownOpen, setDropdownOpen] = useState(false);
|
|
156
|
+
const [confirmDelete, setConfirmDelete] = useState(false);
|
|
157
|
+
const [editing, setEditing] = useState(false);
|
|
158
|
+
const [editTitle, setEditTitle] = useState(chat.title || "");
|
|
159
|
+
const inputRef = useRef(null);
|
|
160
|
+
const showMenu = hovered || dropdownOpen;
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
if (editing && inputRef.current) {
|
|
163
|
+
inputRef.current.focus();
|
|
164
|
+
inputRef.current.select();
|
|
165
|
+
}
|
|
166
|
+
}, [editing]);
|
|
167
|
+
const startRename = () => {
|
|
168
|
+
setEditTitle(chat.title || "");
|
|
169
|
+
setEditing(true);
|
|
170
|
+
};
|
|
171
|
+
const saveRename = () => {
|
|
172
|
+
const trimmed = editTitle.trim();
|
|
173
|
+
if (trimmed && trimmed !== chat.title) {
|
|
174
|
+
onRename(chat.id, trimmed);
|
|
175
|
+
}
|
|
176
|
+
setEditing(false);
|
|
177
|
+
};
|
|
178
|
+
const cancelRename = () => {
|
|
179
|
+
setEditing(false);
|
|
180
|
+
setEditTitle(chat.title || "");
|
|
181
|
+
};
|
|
182
|
+
return /* @__PURE__ */ jsxs(
|
|
183
|
+
"div",
|
|
184
|
+
{
|
|
185
|
+
className: "relative group flex items-center gap-3 px-3 py-3 cursor-pointer hover:bg-muted/50 rounded-md",
|
|
186
|
+
onMouseEnter: () => setHovered(true),
|
|
187
|
+
onMouseLeave: () => setHovered(false),
|
|
188
|
+
onClick: () => !editing && onNavigate(chat.id),
|
|
189
|
+
children: [
|
|
190
|
+
/* @__PURE__ */ jsx(MessageIcon, { size: 16 }),
|
|
191
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
|
|
192
|
+
editing ? /* @__PURE__ */ jsx(
|
|
193
|
+
"input",
|
|
194
|
+
{
|
|
195
|
+
ref: inputRef,
|
|
196
|
+
type: "text",
|
|
197
|
+
value: editTitle,
|
|
198
|
+
onChange: (e) => setEditTitle(e.target.value),
|
|
199
|
+
onKeyDown: (e) => {
|
|
200
|
+
if (e.key === "Enter") saveRename();
|
|
201
|
+
if (e.key === "Escape") cancelRename();
|
|
202
|
+
},
|
|
203
|
+
onBlur: saveRename,
|
|
204
|
+
onClick: (e) => e.stopPropagation(),
|
|
205
|
+
className: "w-full text-sm bg-background border border-input rounded px-1.5 py-0.5 focus:outline-none focus:ring-2 focus:ring-ring"
|
|
206
|
+
}
|
|
207
|
+
) : /* @__PURE__ */ jsx(
|
|
208
|
+
"span",
|
|
209
|
+
{
|
|
210
|
+
className: "text-sm truncate block",
|
|
211
|
+
onDoubleClick: (e) => {
|
|
212
|
+
e.stopPropagation();
|
|
213
|
+
startRename();
|
|
214
|
+
},
|
|
215
|
+
children: chat.title || "New Chat"
|
|
216
|
+
}
|
|
217
|
+
),
|
|
218
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
|
|
219
|
+
"Last message ",
|
|
220
|
+
timeAgo(chat.updatedAt)
|
|
221
|
+
] })
|
|
222
|
+
] }),
|
|
223
|
+
!editing && /* @__PURE__ */ jsx("div", { className: cn(
|
|
224
|
+
"shrink-0",
|
|
225
|
+
showMenu ? "opacity-100" : "opacity-0 pointer-events-none"
|
|
226
|
+
), children: /* @__PURE__ */ jsxs(DropdownMenu, { open: dropdownOpen, onOpenChange: setDropdownOpen, children: [
|
|
227
|
+
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
228
|
+
"button",
|
|
229
|
+
{
|
|
230
|
+
className: cn(
|
|
231
|
+
"rounded-md p-1.5",
|
|
232
|
+
"text-muted-foreground hover:text-foreground hover:bg-muted"
|
|
233
|
+
),
|
|
234
|
+
"aria-label": "Chat options",
|
|
235
|
+
children: /* @__PURE__ */ jsx(MoreHorizontalIcon, { size: 14 })
|
|
236
|
+
}
|
|
237
|
+
) }),
|
|
238
|
+
/* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", side: "bottom", children: [
|
|
239
|
+
/* @__PURE__ */ jsxs(
|
|
240
|
+
DropdownMenuItem,
|
|
241
|
+
{
|
|
242
|
+
onClick: (e) => {
|
|
243
|
+
e.stopPropagation();
|
|
244
|
+
onStar(chat.id);
|
|
245
|
+
},
|
|
246
|
+
children: [
|
|
247
|
+
chat.starred ? /* @__PURE__ */ jsx(StarFilledIcon, { size: 14 }) : /* @__PURE__ */ jsx(StarIcon, { size: 14 }),
|
|
248
|
+
chat.starred ? "Unstar" : "Star"
|
|
249
|
+
]
|
|
250
|
+
}
|
|
251
|
+
),
|
|
252
|
+
/* @__PURE__ */ jsxs(
|
|
253
|
+
DropdownMenuItem,
|
|
254
|
+
{
|
|
255
|
+
onClick: (e) => {
|
|
256
|
+
e.stopPropagation();
|
|
257
|
+
startRename();
|
|
258
|
+
},
|
|
259
|
+
children: [
|
|
260
|
+
/* @__PURE__ */ jsx(PencilIcon, { size: 14 }),
|
|
261
|
+
"Rename"
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
),
|
|
265
|
+
/* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
|
|
266
|
+
/* @__PURE__ */ jsxs(
|
|
267
|
+
DropdownMenuItem,
|
|
268
|
+
{
|
|
269
|
+
className: "text-destructive hover:text-destructive",
|
|
270
|
+
onClick: (e) => {
|
|
271
|
+
e.stopPropagation();
|
|
272
|
+
setConfirmDelete(true);
|
|
273
|
+
},
|
|
274
|
+
children: [
|
|
275
|
+
/* @__PURE__ */ jsx(TrashIcon, { size: 14 }),
|
|
276
|
+
"Delete"
|
|
277
|
+
]
|
|
278
|
+
}
|
|
279
|
+
)
|
|
280
|
+
] })
|
|
281
|
+
] }) }),
|
|
282
|
+
/* @__PURE__ */ jsx(
|
|
283
|
+
ConfirmDialog,
|
|
284
|
+
{
|
|
285
|
+
open: confirmDelete,
|
|
286
|
+
title: "Delete chat?",
|
|
287
|
+
description: "This will permanently delete this chat and all its messages.",
|
|
288
|
+
confirmLabel: "Delete",
|
|
289
|
+
onConfirm: () => {
|
|
290
|
+
setConfirmDelete(false);
|
|
291
|
+
onDelete(chat.id);
|
|
292
|
+
},
|
|
293
|
+
onCancel: () => setConfirmDelete(false)
|
|
294
|
+
}
|
|
295
|
+
)
|
|
296
|
+
]
|
|
297
|
+
}
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
export {
|
|
301
|
+
ChatsPage
|
|
302
|
+
};
|