@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,289 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useRef, useEffect, useCallback } from "react";
|
|
4
|
+
import { motion } from "framer-motion";
|
|
5
|
+
import { Streamdown } from "streamdown";
|
|
6
|
+
import { cn } from "../utils.js";
|
|
7
|
+
import { SpinnerIcon, FileTextIcon, CopyIcon, CheckIcon, RefreshIcon, SquarePenIcon, XIcon } from "./icons.js";
|
|
8
|
+
import { EnhancedToolCall } from "./enhanced-tool-call.js";
|
|
9
|
+
function LinkSafetyModal({ url, isOpen, onClose, onConfirm }) {
|
|
10
|
+
const [copied, setCopied] = useState(false);
|
|
11
|
+
const handleCopy = useCallback(async () => {
|
|
12
|
+
try {
|
|
13
|
+
await navigator.clipboard.writeText(url);
|
|
14
|
+
setCopied(true);
|
|
15
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
16
|
+
} catch {
|
|
17
|
+
}
|
|
18
|
+
}, [url]);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!isOpen) return;
|
|
21
|
+
const onKey = (e) => {
|
|
22
|
+
if (e.key === "Escape") onClose();
|
|
23
|
+
};
|
|
24
|
+
document.addEventListener("keydown", onKey);
|
|
25
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
26
|
+
}, [isOpen, onClose]);
|
|
27
|
+
if (!isOpen) return null;
|
|
28
|
+
return /* @__PURE__ */ jsx(
|
|
29
|
+
"div",
|
|
30
|
+
{
|
|
31
|
+
className: "fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",
|
|
32
|
+
onClick: onClose,
|
|
33
|
+
children: /* @__PURE__ */ jsxs(
|
|
34
|
+
"div",
|
|
35
|
+
{
|
|
36
|
+
className: "relative mx-4 flex w-full flex-col gap-3 rounded-lg border border-white/[0.06] bg-[--card] p-4 shadow-lg",
|
|
37
|
+
style: { maxWidth: "340px" },
|
|
38
|
+
onClick: (e) => e.stopPropagation(),
|
|
39
|
+
children: [
|
|
40
|
+
/* @__PURE__ */ jsx("div", { className: "font-medium text-sm text-foreground", children: "Open external link?" }),
|
|
41
|
+
/* @__PURE__ */ jsx("div", { className: "break-all rounded-md bg-black/30 px-2.5 py-2 font-mono text-xs text-foreground/80 border border-white/[0.04]", children: url }),
|
|
42
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
43
|
+
/* @__PURE__ */ jsxs(
|
|
44
|
+
"button",
|
|
45
|
+
{
|
|
46
|
+
onClick: handleCopy,
|
|
47
|
+
className: "flex flex-1 items-center justify-center gap-1.5 rounded-md border border-white/[0.06] px-3 py-1.5 text-xs font-medium text-foreground hover:bg-white/[0.04]",
|
|
48
|
+
children: [
|
|
49
|
+
copied ? /* @__PURE__ */ jsx(CheckIcon, { size: 12 }) : /* @__PURE__ */ jsx(CopyIcon, { size: 12 }),
|
|
50
|
+
/* @__PURE__ */ jsx("span", { children: copied ? "Copied" : "Copy" })
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
),
|
|
54
|
+
/* @__PURE__ */ jsx(
|
|
55
|
+
"button",
|
|
56
|
+
{
|
|
57
|
+
onClick: () => {
|
|
58
|
+
onConfirm();
|
|
59
|
+
onClose();
|
|
60
|
+
},
|
|
61
|
+
className: "flex flex-1 items-center justify-center gap-1.5 rounded-md bg-[--primary] px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90",
|
|
62
|
+
children: /* @__PURE__ */ jsx("span", { children: "Open" })
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
] })
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
const linkSafety = {
|
|
73
|
+
enabled: true,
|
|
74
|
+
renderModal: (props) => /* @__PURE__ */ jsx(LinkSafetyModal, { ...props })
|
|
75
|
+
};
|
|
76
|
+
function PreviewMessage({ message, isLoading, onRetry, onEdit }) {
|
|
77
|
+
const isUser = message.role === "user";
|
|
78
|
+
const [copied, setCopied] = useState(false);
|
|
79
|
+
const [editing, setEditing] = useState(false);
|
|
80
|
+
const [editText, setEditText] = useState("");
|
|
81
|
+
const textareaRef = useRef(null);
|
|
82
|
+
const text = message.parts?.filter((p) => p.type === "text").map((p) => p.text).join("\n") || message.content || "";
|
|
83
|
+
const fileParts = message.parts?.filter((p) => p.type === "file") || [];
|
|
84
|
+
const imageParts = fileParts.filter((p) => p.mediaType?.startsWith("image/"));
|
|
85
|
+
const otherFileParts = fileParts.filter((p) => !p.mediaType?.startsWith("image/"));
|
|
86
|
+
const hasToolParts = message.parts?.some((p) => p.type?.startsWith("tool-")) || false;
|
|
87
|
+
const handleCopy = async () => {
|
|
88
|
+
try {
|
|
89
|
+
await navigator.clipboard.writeText(text);
|
|
90
|
+
setCopied(true);
|
|
91
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const handleEditStart = () => {
|
|
96
|
+
setEditText(text);
|
|
97
|
+
setEditing(true);
|
|
98
|
+
};
|
|
99
|
+
const handleEditCancel = () => {
|
|
100
|
+
setEditing(false);
|
|
101
|
+
setEditText("");
|
|
102
|
+
};
|
|
103
|
+
const handleEditSubmit = () => {
|
|
104
|
+
const trimmed = editText.trim();
|
|
105
|
+
if (trimmed && trimmed !== text) {
|
|
106
|
+
onEdit?.(message, trimmed);
|
|
107
|
+
}
|
|
108
|
+
setEditing(false);
|
|
109
|
+
setEditText("");
|
|
110
|
+
};
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (editing && textareaRef.current) {
|
|
113
|
+
const ta = textareaRef.current;
|
|
114
|
+
ta.focus();
|
|
115
|
+
ta.style.height = "auto";
|
|
116
|
+
ta.style.height = `${ta.scrollHeight}px`;
|
|
117
|
+
ta.setSelectionRange(ta.value.length, ta.value.length);
|
|
118
|
+
}
|
|
119
|
+
}, [editing]);
|
|
120
|
+
return /* @__PURE__ */ jsx(
|
|
121
|
+
motion.div,
|
|
122
|
+
{
|
|
123
|
+
initial: { opacity: 0, y: 12 },
|
|
124
|
+
animate: { opacity: 1, y: 0 },
|
|
125
|
+
transition: { duration: 0.3, ease: "easeOut" },
|
|
126
|
+
className: cn(
|
|
127
|
+
"group flex gap-4 w-full",
|
|
128
|
+
isUser ? "justify-end" : "justify-start"
|
|
129
|
+
),
|
|
130
|
+
children: /* @__PURE__ */ jsx("div", { className: "flex flex-col max-w-[80%]", children: editing ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
131
|
+
/* @__PURE__ */ jsx(
|
|
132
|
+
"textarea",
|
|
133
|
+
{
|
|
134
|
+
ref: textareaRef,
|
|
135
|
+
value: editText,
|
|
136
|
+
onChange: (e) => {
|
|
137
|
+
setEditText(e.target.value);
|
|
138
|
+
e.target.style.height = "auto";
|
|
139
|
+
e.target.style.height = `${e.target.scrollHeight}px`;
|
|
140
|
+
},
|
|
141
|
+
onKeyDown: (e) => {
|
|
142
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
handleEditSubmit();
|
|
145
|
+
}
|
|
146
|
+
if (e.key === "Escape") {
|
|
147
|
+
handleEditCancel();
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
className: "w-full resize-none rounded-lg border border-[--primary]/20 bg-[--card] px-4 py-3 text-sm leading-relaxed text-foreground focus:outline-none focus:ring-1 focus:ring-[--primary]/40 font-mono",
|
|
151
|
+
rows: 1
|
|
152
|
+
}
|
|
153
|
+
),
|
|
154
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
155
|
+
/* @__PURE__ */ jsx(
|
|
156
|
+
"button",
|
|
157
|
+
{
|
|
158
|
+
onClick: handleEditCancel,
|
|
159
|
+
className: "rounded-md px-3 py-1 text-xs text-muted-foreground hover:text-foreground",
|
|
160
|
+
children: "Cancel"
|
|
161
|
+
}
|
|
162
|
+
),
|
|
163
|
+
/* @__PURE__ */ jsx(
|
|
164
|
+
"button",
|
|
165
|
+
{
|
|
166
|
+
onClick: handleEditSubmit,
|
|
167
|
+
className: "rounded-md bg-[--primary] px-3 py-1 text-xs text-primary-foreground hover:opacity-80",
|
|
168
|
+
children: "Send"
|
|
169
|
+
}
|
|
170
|
+
)
|
|
171
|
+
] })
|
|
172
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
173
|
+
/* @__PURE__ */ jsx(
|
|
174
|
+
"div",
|
|
175
|
+
{
|
|
176
|
+
className: cn(
|
|
177
|
+
"rounded-lg px-4 py-3 text-sm leading-relaxed",
|
|
178
|
+
isUser ? "bg-[--primary]/10 border border-[--primary]/20 text-foreground" : ""
|
|
179
|
+
),
|
|
180
|
+
children: isUser ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
181
|
+
imageParts.length > 0 && /* @__PURE__ */ jsx("div", { className: "mb-2 flex flex-wrap gap-2", children: imageParts.map((part, i) => /* @__PURE__ */ jsx(
|
|
182
|
+
"img",
|
|
183
|
+
{
|
|
184
|
+
src: part.url,
|
|
185
|
+
alt: "attachment",
|
|
186
|
+
className: "max-h-64 max-w-full rounded-lg object-contain"
|
|
187
|
+
},
|
|
188
|
+
i
|
|
189
|
+
)) }),
|
|
190
|
+
otherFileParts.length > 0 && /* @__PURE__ */ jsx("div", { className: "mb-2 flex flex-wrap gap-2", children: otherFileParts.map((part, i) => /* @__PURE__ */ jsxs(
|
|
191
|
+
"div",
|
|
192
|
+
{
|
|
193
|
+
className: "inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs bg-[--primary]/10 border border-[--primary]/20",
|
|
194
|
+
children: [
|
|
195
|
+
/* @__PURE__ */ jsx(FileTextIcon, { size: 12 }),
|
|
196
|
+
/* @__PURE__ */ jsx("span", { className: "max-w-[150px] truncate", children: part.name || part.mediaType || "file" })
|
|
197
|
+
]
|
|
198
|
+
},
|
|
199
|
+
i
|
|
200
|
+
)) }),
|
|
201
|
+
text ? /* @__PURE__ */ jsx("div", { className: "whitespace-pre-wrap break-words", children: text }) : null
|
|
202
|
+
] }) : /* @__PURE__ */ jsx(Fragment, { children: message.parts?.length > 0 ? message.parts.map((part, i) => {
|
|
203
|
+
if (part.type === "text") {
|
|
204
|
+
return /* @__PURE__ */ jsx(Streamdown, { mode: isLoading ? "streaming" : "static", linkSafety, children: part.text }, i);
|
|
205
|
+
}
|
|
206
|
+
if (part.type === "file") {
|
|
207
|
+
if (part.mediaType?.startsWith("image/")) {
|
|
208
|
+
return /* @__PURE__ */ jsx("div", { className: "mb-2", children: /* @__PURE__ */ jsx("img", { src: part.url, alt: "attachment", className: "max-h-64 max-w-full rounded-lg object-contain" }) }, i);
|
|
209
|
+
}
|
|
210
|
+
return /* @__PURE__ */ jsxs("div", { className: "mb-2 inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs bg-white/[0.04] border border-white/[0.06]", children: [
|
|
211
|
+
/* @__PURE__ */ jsx(FileTextIcon, { size: 12 }),
|
|
212
|
+
/* @__PURE__ */ jsx("span", { className: "max-w-[150px] truncate", children: part.name || part.mediaType || "file" })
|
|
213
|
+
] }, i);
|
|
214
|
+
}
|
|
215
|
+
if (part.type?.startsWith("tool-")) {
|
|
216
|
+
return /* @__PURE__ */ jsx(EnhancedToolCall, { part }, part.toolCallId || i);
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
219
|
+
}) : text ? /* @__PURE__ */ jsx(Streamdown, { mode: isLoading ? "streaming" : "static", linkSafety, children: text }) : isLoading && !hasToolParts ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-muted-foreground", children: [
|
|
220
|
+
/* @__PURE__ */ jsx(SpinnerIcon, { size: 14 }),
|
|
221
|
+
/* @__PURE__ */ jsx("span", { children: "Working..." })
|
|
222
|
+
] }) : null })
|
|
223
|
+
}
|
|
224
|
+
),
|
|
225
|
+
!isLoading && text && /* @__PURE__ */ jsxs(
|
|
226
|
+
"div",
|
|
227
|
+
{
|
|
228
|
+
className: cn(
|
|
229
|
+
"flex gap-1 mt-1 opacity-0 transition-opacity group-hover:opacity-100",
|
|
230
|
+
isUser ? "justify-end" : "justify-start"
|
|
231
|
+
),
|
|
232
|
+
children: [
|
|
233
|
+
/* @__PURE__ */ jsx(
|
|
234
|
+
"button",
|
|
235
|
+
{
|
|
236
|
+
onClick: handleCopy,
|
|
237
|
+
className: "rounded-md p-1 text-muted-foreground hover:text-[--cyan] hover:bg-white/[0.04]",
|
|
238
|
+
"aria-label": "Copy message",
|
|
239
|
+
children: copied ? /* @__PURE__ */ jsx(CheckIcon, { size: 14 }) : /* @__PURE__ */ jsx(CopyIcon, { size: 14 })
|
|
240
|
+
}
|
|
241
|
+
),
|
|
242
|
+
onRetry && /* @__PURE__ */ jsx(
|
|
243
|
+
"button",
|
|
244
|
+
{
|
|
245
|
+
onClick: () => onRetry(message),
|
|
246
|
+
className: "rounded-md p-1 text-muted-foreground hover:text-[--cyan] hover:bg-white/[0.04]",
|
|
247
|
+
"aria-label": "Retry",
|
|
248
|
+
children: /* @__PURE__ */ jsx(RefreshIcon, { size: 14 })
|
|
249
|
+
}
|
|
250
|
+
),
|
|
251
|
+
isUser && onEdit && /* @__PURE__ */ jsx(
|
|
252
|
+
"button",
|
|
253
|
+
{
|
|
254
|
+
onClick: handleEditStart,
|
|
255
|
+
className: "rounded-md p-1 text-muted-foreground hover:text-[--cyan] hover:bg-white/[0.04]",
|
|
256
|
+
"aria-label": "Edit message",
|
|
257
|
+
children: /* @__PURE__ */ jsx(SquarePenIcon, { size: 14 })
|
|
258
|
+
}
|
|
259
|
+
)
|
|
260
|
+
]
|
|
261
|
+
}
|
|
262
|
+
)
|
|
263
|
+
] }) })
|
|
264
|
+
}
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
function ThinkingMessage() {
|
|
268
|
+
return /* @__PURE__ */ jsx(
|
|
269
|
+
motion.div,
|
|
270
|
+
{
|
|
271
|
+
initial: { opacity: 0, y: 8 },
|
|
272
|
+
animate: { opacity: 1, y: 0 },
|
|
273
|
+
className: "flex gap-4 w-full justify-start",
|
|
274
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 rounded-lg px-4 py-3 text-sm", children: [
|
|
275
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
276
|
+
/* @__PURE__ */ jsx("span", { className: "w-1.5 h-1.5 rounded-full bg-[--cyan] animate-thinking-pulse", style: { animationDelay: "0ms" } }),
|
|
277
|
+
/* @__PURE__ */ jsx("span", { className: "w-1.5 h-1.5 rounded-full bg-[--cyan] animate-thinking-pulse", style: { animationDelay: "200ms" } }),
|
|
278
|
+
/* @__PURE__ */ jsx("span", { className: "w-1.5 h-1.5 rounded-full bg-[--cyan] animate-thinking-pulse", style: { animationDelay: "400ms" } })
|
|
279
|
+
] }),
|
|
280
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground font-mono text-xs", children: "Processing" })
|
|
281
|
+
] })
|
|
282
|
+
}
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
export {
|
|
286
|
+
PreviewMessage,
|
|
287
|
+
ThinkingMessage,
|
|
288
|
+
linkSafety
|
|
289
|
+
};
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
4
|
+
import { motion } from 'framer-motion';
|
|
5
|
+
import { Streamdown } from 'streamdown';
|
|
6
|
+
import { cn } from '../utils.js';
|
|
7
|
+
import { SpinnerIcon, FileTextIcon, CopyIcon, CheckIcon, RefreshIcon, SquarePenIcon, XIcon } from './icons.js';
|
|
8
|
+
import { EnhancedToolCall } from './enhanced-tool-call.js';
|
|
9
|
+
|
|
10
|
+
function LinkSafetyModal({ url, isOpen, onClose, onConfirm }) {
|
|
11
|
+
const [copied, setCopied] = useState(false);
|
|
12
|
+
|
|
13
|
+
const handleCopy = useCallback(async () => {
|
|
14
|
+
try {
|
|
15
|
+
await navigator.clipboard.writeText(url);
|
|
16
|
+
setCopied(true);
|
|
17
|
+
setTimeout(() => setCopied(false), 2000);
|
|
18
|
+
} catch {}
|
|
19
|
+
}, [url]);
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!isOpen) return;
|
|
23
|
+
const onKey = (e) => { if (e.key === 'Escape') onClose(); };
|
|
24
|
+
document.addEventListener('keydown', onKey);
|
|
25
|
+
return () => document.removeEventListener('keydown', onKey);
|
|
26
|
+
}, [isOpen, onClose]);
|
|
27
|
+
|
|
28
|
+
if (!isOpen) return null;
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<div
|
|
32
|
+
className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm"
|
|
33
|
+
onClick={onClose}
|
|
34
|
+
>
|
|
35
|
+
<div
|
|
36
|
+
className="relative mx-4 flex w-full flex-col gap-3 rounded-lg border border-white/[0.06] bg-[--card] p-4 shadow-lg"
|
|
37
|
+
style={{ maxWidth: '340px' }}
|
|
38
|
+
onClick={(e) => e.stopPropagation()}
|
|
39
|
+
>
|
|
40
|
+
<div className="font-medium text-sm text-foreground">Open external link?</div>
|
|
41
|
+
<div className="break-all rounded-md bg-black/30 px-2.5 py-2 font-mono text-xs text-foreground/80 border border-white/[0.04]">
|
|
42
|
+
{url}
|
|
43
|
+
</div>
|
|
44
|
+
<div className="flex gap-2">
|
|
45
|
+
<button
|
|
46
|
+
onClick={handleCopy}
|
|
47
|
+
className="flex flex-1 items-center justify-center gap-1.5 rounded-md border border-white/[0.06] px-3 py-1.5 text-xs font-medium text-foreground hover:bg-white/[0.04]"
|
|
48
|
+
>
|
|
49
|
+
{copied ? <CheckIcon size={12} /> : <CopyIcon size={12} />}
|
|
50
|
+
<span>{copied ? 'Copied' : 'Copy'}</span>
|
|
51
|
+
</button>
|
|
52
|
+
<button
|
|
53
|
+
onClick={() => { onConfirm(); onClose(); }}
|
|
54
|
+
className="flex flex-1 items-center justify-center gap-1.5 rounded-md bg-[--primary] px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90"
|
|
55
|
+
>
|
|
56
|
+
<span>Open</span>
|
|
57
|
+
</button>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const linkSafety = {
|
|
65
|
+
enabled: true,
|
|
66
|
+
renderModal: (props) => <LinkSafetyModal {...props} />,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export function PreviewMessage({ message, isLoading, onRetry, onEdit }) {
|
|
70
|
+
const isUser = message.role === 'user';
|
|
71
|
+
const [copied, setCopied] = useState(false);
|
|
72
|
+
const [editing, setEditing] = useState(false);
|
|
73
|
+
const [editText, setEditText] = useState('');
|
|
74
|
+
const textareaRef = useRef(null);
|
|
75
|
+
|
|
76
|
+
const text =
|
|
77
|
+
message.parts
|
|
78
|
+
?.filter((p) => p.type === 'text')
|
|
79
|
+
.map((p) => p.text)
|
|
80
|
+
.join('\n') ||
|
|
81
|
+
message.content ||
|
|
82
|
+
'';
|
|
83
|
+
|
|
84
|
+
const fileParts = message.parts?.filter((p) => p.type === 'file') || [];
|
|
85
|
+
const imageParts = fileParts.filter((p) => p.mediaType?.startsWith('image/'));
|
|
86
|
+
const otherFileParts = fileParts.filter((p) => !p.mediaType?.startsWith('image/'));
|
|
87
|
+
const hasToolParts = message.parts?.some((p) => p.type?.startsWith('tool-')) || false;
|
|
88
|
+
|
|
89
|
+
const handleCopy = async () => {
|
|
90
|
+
try {
|
|
91
|
+
await navigator.clipboard.writeText(text);
|
|
92
|
+
setCopied(true);
|
|
93
|
+
setTimeout(() => setCopied(false), 2000);
|
|
94
|
+
} catch {}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const handleEditStart = () => {
|
|
98
|
+
setEditText(text);
|
|
99
|
+
setEditing(true);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const handleEditCancel = () => {
|
|
103
|
+
setEditing(false);
|
|
104
|
+
setEditText('');
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const handleEditSubmit = () => {
|
|
108
|
+
const trimmed = editText.trim();
|
|
109
|
+
if (trimmed && trimmed !== text) {
|
|
110
|
+
onEdit?.(message, trimmed);
|
|
111
|
+
}
|
|
112
|
+
setEditing(false);
|
|
113
|
+
setEditText('');
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (editing && textareaRef.current) {
|
|
118
|
+
const ta = textareaRef.current;
|
|
119
|
+
ta.focus();
|
|
120
|
+
ta.style.height = 'auto';
|
|
121
|
+
ta.style.height = `${ta.scrollHeight}px`;
|
|
122
|
+
ta.setSelectionRange(ta.value.length, ta.value.length);
|
|
123
|
+
}
|
|
124
|
+
}, [editing]);
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<motion.div
|
|
128
|
+
initial={{ opacity: 0, y: 12 }}
|
|
129
|
+
animate={{ opacity: 1, y: 0 }}
|
|
130
|
+
transition={{ duration: 0.3, ease: 'easeOut' }}
|
|
131
|
+
className={cn(
|
|
132
|
+
'group flex gap-4 w-full',
|
|
133
|
+
isUser ? 'justify-end' : 'justify-start'
|
|
134
|
+
)}
|
|
135
|
+
>
|
|
136
|
+
<div className="flex flex-col max-w-[80%]">
|
|
137
|
+
{editing ? (
|
|
138
|
+
<div className="flex flex-col gap-2">
|
|
139
|
+
<textarea
|
|
140
|
+
ref={textareaRef}
|
|
141
|
+
value={editText}
|
|
142
|
+
onChange={(e) => {
|
|
143
|
+
setEditText(e.target.value);
|
|
144
|
+
e.target.style.height = 'auto';
|
|
145
|
+
e.target.style.height = `${e.target.scrollHeight}px`;
|
|
146
|
+
}}
|
|
147
|
+
onKeyDown={(e) => {
|
|
148
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
handleEditSubmit();
|
|
151
|
+
}
|
|
152
|
+
if (e.key === 'Escape') {
|
|
153
|
+
handleEditCancel();
|
|
154
|
+
}
|
|
155
|
+
}}
|
|
156
|
+
className="w-full resize-none rounded-lg border border-[--primary]/20 bg-[--card] px-4 py-3 text-sm leading-relaxed text-foreground focus:outline-none focus:ring-1 focus:ring-[--primary]/40 font-mono"
|
|
157
|
+
rows={1}
|
|
158
|
+
/>
|
|
159
|
+
<div className="flex justify-end gap-2">
|
|
160
|
+
<button
|
|
161
|
+
onClick={handleEditCancel}
|
|
162
|
+
className="rounded-md px-3 py-1 text-xs text-muted-foreground hover:text-foreground"
|
|
163
|
+
>
|
|
164
|
+
Cancel
|
|
165
|
+
</button>
|
|
166
|
+
<button
|
|
167
|
+
onClick={handleEditSubmit}
|
|
168
|
+
className="rounded-md bg-[--primary] px-3 py-1 text-xs text-primary-foreground hover:opacity-80"
|
|
169
|
+
>
|
|
170
|
+
Send
|
|
171
|
+
</button>
|
|
172
|
+
</div>
|
|
173
|
+
</div>
|
|
174
|
+
) : (
|
|
175
|
+
<>
|
|
176
|
+
<div
|
|
177
|
+
className={cn(
|
|
178
|
+
'rounded-lg px-4 py-3 text-sm leading-relaxed',
|
|
179
|
+
isUser
|
|
180
|
+
? 'bg-[--primary]/10 border border-[--primary]/20 text-foreground'
|
|
181
|
+
: ''
|
|
182
|
+
)}
|
|
183
|
+
>
|
|
184
|
+
{isUser ? (
|
|
185
|
+
<>
|
|
186
|
+
{imageParts.length > 0 && (
|
|
187
|
+
<div className="mb-2 flex flex-wrap gap-2">
|
|
188
|
+
{imageParts.map((part, i) => (
|
|
189
|
+
<img
|
|
190
|
+
key={i}
|
|
191
|
+
src={part.url}
|
|
192
|
+
alt="attachment"
|
|
193
|
+
className="max-h-64 max-w-full rounded-lg object-contain"
|
|
194
|
+
/>
|
|
195
|
+
))}
|
|
196
|
+
</div>
|
|
197
|
+
)}
|
|
198
|
+
{otherFileParts.length > 0 && (
|
|
199
|
+
<div className="mb-2 flex flex-wrap gap-2">
|
|
200
|
+
{otherFileParts.map((part, i) => (
|
|
201
|
+
<div
|
|
202
|
+
key={i}
|
|
203
|
+
className="inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs bg-[--primary]/10 border border-[--primary]/20"
|
|
204
|
+
>
|
|
205
|
+
<FileTextIcon size={12} />
|
|
206
|
+
<span className="max-w-[150px] truncate">
|
|
207
|
+
{part.name || part.mediaType || 'file'}
|
|
208
|
+
</span>
|
|
209
|
+
</div>
|
|
210
|
+
))}
|
|
211
|
+
</div>
|
|
212
|
+
)}
|
|
213
|
+
{text ? (
|
|
214
|
+
<div className="whitespace-pre-wrap break-words">{text}</div>
|
|
215
|
+
) : null}
|
|
216
|
+
</>
|
|
217
|
+
) : (
|
|
218
|
+
<>
|
|
219
|
+
{message.parts?.length > 0 ? (
|
|
220
|
+
message.parts.map((part, i) => {
|
|
221
|
+
if (part.type === 'text') {
|
|
222
|
+
return <Streamdown key={i} mode={isLoading ? 'streaming' : 'static'} linkSafety={linkSafety}>{part.text}</Streamdown>;
|
|
223
|
+
}
|
|
224
|
+
if (part.type === 'file') {
|
|
225
|
+
if (part.mediaType?.startsWith('image/')) {
|
|
226
|
+
return (
|
|
227
|
+
<div key={i} className="mb-2">
|
|
228
|
+
<img src={part.url} alt="attachment" className="max-h-64 max-w-full rounded-lg object-contain" />
|
|
229
|
+
</div>
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
return (
|
|
233
|
+
<div key={i} className="mb-2 inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs bg-white/[0.04] border border-white/[0.06]">
|
|
234
|
+
<FileTextIcon size={12} />
|
|
235
|
+
<span className="max-w-[150px] truncate">{part.name || part.mediaType || 'file'}</span>
|
|
236
|
+
</div>
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
if (part.type?.startsWith('tool-')) {
|
|
240
|
+
return <EnhancedToolCall key={part.toolCallId || i} part={part} />;
|
|
241
|
+
}
|
|
242
|
+
return null;
|
|
243
|
+
})
|
|
244
|
+
) : text ? (
|
|
245
|
+
<Streamdown mode={isLoading ? 'streaming' : 'static'} linkSafety={linkSafety}>{text}</Streamdown>
|
|
246
|
+
) : isLoading && !hasToolParts ? (
|
|
247
|
+
<div className="flex items-center gap-2 text-muted-foreground">
|
|
248
|
+
<SpinnerIcon size={14} />
|
|
249
|
+
<span>Working...</span>
|
|
250
|
+
</div>
|
|
251
|
+
) : null}
|
|
252
|
+
</>
|
|
253
|
+
)}
|
|
254
|
+
</div>
|
|
255
|
+
|
|
256
|
+
{/* Action toolbar */}
|
|
257
|
+
{!isLoading && text && (
|
|
258
|
+
<div
|
|
259
|
+
className={cn(
|
|
260
|
+
'flex gap-1 mt-1 opacity-0 transition-opacity group-hover:opacity-100',
|
|
261
|
+
isUser ? 'justify-end' : 'justify-start'
|
|
262
|
+
)}
|
|
263
|
+
>
|
|
264
|
+
<button
|
|
265
|
+
onClick={handleCopy}
|
|
266
|
+
className="rounded-md p-1 text-muted-foreground hover:text-[--cyan] hover:bg-white/[0.04]"
|
|
267
|
+
aria-label="Copy message"
|
|
268
|
+
>
|
|
269
|
+
{copied ? <CheckIcon size={14} /> : <CopyIcon size={14} />}
|
|
270
|
+
</button>
|
|
271
|
+
{onRetry && (
|
|
272
|
+
<button
|
|
273
|
+
onClick={() => onRetry(message)}
|
|
274
|
+
className="rounded-md p-1 text-muted-foreground hover:text-[--cyan] hover:bg-white/[0.04]"
|
|
275
|
+
aria-label="Retry"
|
|
276
|
+
>
|
|
277
|
+
<RefreshIcon size={14} />
|
|
278
|
+
</button>
|
|
279
|
+
)}
|
|
280
|
+
{isUser && onEdit && (
|
|
281
|
+
<button
|
|
282
|
+
onClick={handleEditStart}
|
|
283
|
+
className="rounded-md p-1 text-muted-foreground hover:text-[--cyan] hover:bg-white/[0.04]"
|
|
284
|
+
aria-label="Edit message"
|
|
285
|
+
>
|
|
286
|
+
<SquarePenIcon size={14} />
|
|
287
|
+
</button>
|
|
288
|
+
)}
|
|
289
|
+
</div>
|
|
290
|
+
)}
|
|
291
|
+
</>
|
|
292
|
+
)}
|
|
293
|
+
</div>
|
|
294
|
+
</motion.div>
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export function ThinkingMessage() {
|
|
299
|
+
return (
|
|
300
|
+
<motion.div
|
|
301
|
+
initial={{ opacity: 0, y: 8 }}
|
|
302
|
+
animate={{ opacity: 1, y: 0 }}
|
|
303
|
+
className="flex gap-4 w-full justify-start"
|
|
304
|
+
>
|
|
305
|
+
<div className="flex items-center gap-3 rounded-lg px-4 py-3 text-sm">
|
|
306
|
+
<div className="flex items-center gap-1">
|
|
307
|
+
<span className="w-1.5 h-1.5 rounded-full bg-[--cyan] animate-thinking-pulse" style={{ animationDelay: '0ms' }} />
|
|
308
|
+
<span className="w-1.5 h-1.5 rounded-full bg-[--cyan] animate-thinking-pulse" style={{ animationDelay: '200ms' }} />
|
|
309
|
+
<span className="w-1.5 h-1.5 rounded-full bg-[--cyan] animate-thinking-pulse" style={{ animationDelay: '400ms' }} />
|
|
310
|
+
</div>
|
|
311
|
+
<span className="text-muted-foreground font-mono text-xs">Processing</span>
|
|
312
|
+
</div>
|
|
313
|
+
</motion.div>
|
|
314
|
+
);
|
|
315
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useEffect, useState } from "react";
|
|
4
|
+
import { AnimatePresence } from "framer-motion";
|
|
5
|
+
import { PreviewMessage, ThinkingMessage } from "./message.js";
|
|
6
|
+
import { Greeting } from "./greeting.js";
|
|
7
|
+
import { ArrowDown } from "lucide-react";
|
|
8
|
+
function Messages({ messages, status, onRetry, onEdit }) {
|
|
9
|
+
const containerRef = useRef(null);
|
|
10
|
+
const endRef = useRef(null);
|
|
11
|
+
const [isAtBottom, setIsAtBottom] = useState(true);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (isAtBottom && endRef.current) {
|
|
14
|
+
endRef.current.scrollIntoView({ behavior: "smooth" });
|
|
15
|
+
}
|
|
16
|
+
}, [messages, status, isAtBottom]);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const container = containerRef.current;
|
|
19
|
+
if (!container) return;
|
|
20
|
+
const handleScroll = () => {
|
|
21
|
+
const { scrollTop, scrollHeight, clientHeight } = container;
|
|
22
|
+
setIsAtBottom(scrollHeight - scrollTop - clientHeight < 40);
|
|
23
|
+
};
|
|
24
|
+
container.addEventListener("scroll", handleScroll, { passive: true });
|
|
25
|
+
return () => container.removeEventListener("scroll", handleScroll);
|
|
26
|
+
}, []);
|
|
27
|
+
const scrollToBottom = () => {
|
|
28
|
+
endRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
29
|
+
};
|
|
30
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative flex-1", children: [
|
|
31
|
+
/* @__PURE__ */ jsx(
|
|
32
|
+
"div",
|
|
33
|
+
{
|
|
34
|
+
className: "absolute inset-0 touch-pan-y overflow-y-auto scrollbar-thin",
|
|
35
|
+
ref: containerRef,
|
|
36
|
+
children: /* @__PURE__ */ jsxs("div", { className: "mx-auto flex min-w-0 max-w-4xl flex-col gap-4 px-4 py-4 md:gap-6 md:px-6", children: [
|
|
37
|
+
messages.length === 0 && /* @__PURE__ */ jsx(Greeting, {}),
|
|
38
|
+
/* @__PURE__ */ jsx(AnimatePresence, { mode: "popLayout", children: messages.map((message, index) => /* @__PURE__ */ jsx(
|
|
39
|
+
PreviewMessage,
|
|
40
|
+
{
|
|
41
|
+
message,
|
|
42
|
+
isLoading: status === "streaming" && index === messages.length - 1,
|
|
43
|
+
onRetry,
|
|
44
|
+
onEdit
|
|
45
|
+
},
|
|
46
|
+
message.id
|
|
47
|
+
)) }),
|
|
48
|
+
status === "submitted" && /* @__PURE__ */ jsx(ThinkingMessage, {}),
|
|
49
|
+
/* @__PURE__ */ jsx("div", { className: "min-h-[24px] shrink-0", ref: endRef })
|
|
50
|
+
] })
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
!isAtBottom && /* @__PURE__ */ jsx(
|
|
54
|
+
"button",
|
|
55
|
+
{
|
|
56
|
+
className: "absolute bottom-4 left-1/2 z-10 -translate-x-1/2 rounded-full border border-white/[0.06] bg-[--card] p-2 shadow-lg hover:bg-white/[0.04]",
|
|
57
|
+
onClick: scrollToBottom,
|
|
58
|
+
"aria-label": "Scroll to bottom",
|
|
59
|
+
children: /* @__PURE__ */ jsx(ArrowDown, { className: "size-4" })
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
] });
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
Messages
|
|
66
|
+
};
|