gigaclaw 1.4.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 +26 -0
- package/README.md +237 -0
- package/api/CLAUDE.md +19 -0
- package/api/index.js +265 -0
- package/bin/cli.js +823 -0
- package/bin/local.sh +85 -0
- package/bin/postinstall.js +63 -0
- package/config/index.js +26 -0
- package/config/instrumentation.js +62 -0
- package/drizzle/0000_initial.sql +52 -0
- package/drizzle/0001_nostalgic_sersi.sql +11 -0
- package/drizzle/0002_black_daimon_hellstrom.sql +19 -0
- package/drizzle/0003_rename_code_workspaces.sql +5 -0
- package/drizzle/meta/0000_snapshot.json +321 -0
- package/drizzle/meta/0001_snapshot.json +390 -0
- package/drizzle/meta/0002_snapshot.json +411 -0
- package/drizzle/meta/0003_snapshot.json +419 -0
- package/drizzle/meta/_journal.json +34 -0
- package/lib/actions.js +44 -0
- package/lib/ai/agent.js +86 -0
- package/lib/ai/index.js +342 -0
- package/lib/ai/model.js +180 -0
- package/lib/ai/tools.js +269 -0
- package/lib/ai/web-search.js +42 -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 +62 -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 +579 -0
- package/lib/chat/api.js +140 -0
- package/lib/chat/components/app-sidebar.js +213 -0
- package/lib/chat/components/app-sidebar.jsx +279 -0
- package/lib/chat/components/chat-header.js +192 -0
- package/lib/chat/components/chat-header.jsx +223 -0
- package/lib/chat/components/chat-input.js +236 -0
- package/lib/chat/components/chat-input.jsx +249 -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 +99 -0
- package/lib/chat/components/chat-page.jsx +121 -0
- package/lib/chat/components/chat.js +153 -0
- package/lib/chat/components/chat.jsx +199 -0
- package/lib/chat/components/chats-page.js +367 -0
- package/lib/chat/components/chats-page.jsx +394 -0
- package/lib/chat/components/code-mode-toggle.js +132 -0
- package/lib/chat/components/code-mode-toggle.jsx +163 -0
- package/lib/chat/components/crons-page.js +172 -0
- package/lib/chat/components/crons-page.jsx +244 -0
- package/lib/chat/components/greeting.js +11 -0
- package/lib/chat/components/greeting.jsx +16 -0
- package/lib/chat/components/icons.js +805 -0
- package/lib/chat/components/icons.jsx +751 -0
- package/lib/chat/components/index.js +20 -0
- package/lib/chat/components/message.js +363 -0
- package/lib/chat/components/message.jsx +422 -0
- package/lib/chat/components/messages.js +65 -0
- package/lib/chat/components/messages.jsx +74 -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/pull-requests-page.js +103 -0
- package/lib/chat/components/pull-requests-page.jsx +113 -0
- package/lib/chat/components/settings-layout.js +39 -0
- package/lib/chat/components/settings-layout.jsx +53 -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 +138 -0
- package/lib/chat/components/sidebar-history-item.jsx +119 -0
- package/lib/chat/components/sidebar-history.js +167 -0
- package/lib/chat/components/sidebar-history.jsx +220 -0
- package/lib/chat/components/sidebar-user-nav.js +61 -0
- package/lib/chat/components/sidebar-user-nav.jsx +77 -0
- package/lib/chat/components/swarm-page.js +157 -0
- package/lib/chat/components/swarm-page.jsx +210 -0
- package/lib/chat/components/tool-call.js +89 -0
- package/lib/chat/components/tool-call.jsx +107 -0
- package/lib/chat/components/triggers-page.js +153 -0
- package/lib/chat/components/triggers-page.jsx +221 -0
- package/lib/chat/components/ui/combobox.js +98 -0
- package/lib/chat/components/ui/combobox.jsx +114 -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 +194 -0
- package/lib/chat/components/ui/dropdown-menu.jsx +215 -0
- package/lib/chat/components/ui/rename-dialog.js +78 -0
- package/lib/chat/components/ui/rename-dialog.jsx +74 -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 +228 -0
- package/lib/chat/components/ui/sidebar.jsx +246 -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/code/actions.js +153 -0
- package/lib/code/code-page.js +22 -0
- package/lib/code/code-page.jsx +25 -0
- package/lib/code/index.js +1 -0
- package/lib/code/terminal-view.js +201 -0
- package/lib/code/terminal-view.jsx +224 -0
- package/lib/code/ws-proxy.js +80 -0
- package/lib/cron.js +246 -0
- package/lib/db/api-keys.js +163 -0
- package/lib/db/chats.js +168 -0
- package/lib/db/code-workspaces.js +110 -0
- package/lib/db/index.js +52 -0
- package/lib/db/notifications.js +99 -0
- package/lib/db/schema.js +66 -0
- package/lib/db/update-check.js +96 -0
- package/lib/db/users.js +89 -0
- package/lib/paths.js +42 -0
- package/lib/tools/create-job.js +97 -0
- package/lib/tools/docker.js +146 -0
- package/lib/tools/github.js +271 -0
- package/lib/tools/openai.js +35 -0
- package/lib/tools/telegram.js +292 -0
- package/lib/triggers.js +104 -0
- package/lib/utils/render-md.js +111 -0
- package/package.json +118 -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 +105 -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-cloud.mjs +833 -0
- package/setup/setup-local.mjs +377 -0
- package/setup/setup-telegram.mjs +265 -0
- package/setup/setup.mjs +87 -0
- package/templates/.dockerignore +5 -0
- package/templates/.env.example +104 -0
- package/templates/.github/workflows/auto-merge.yml +117 -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 +308 -0
- package/templates/app/api/[...gigaclaw]/route.js +1 -0
- package/templates/app/api/auth/[...nextauth]/route.js +1 -0
- package/templates/app/chat/[chatId]/page.js +9 -0
- package/templates/app/chats/page.js +7 -0
- package/templates/app/code/[codeWorkspaceId]/page.js +9 -0
- package/templates/app/components/ascii-logo.jsx +12 -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/globals.css +90 -0
- package/templates/app/layout.js +33 -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/pull-requests/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/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/triggers/page.js +5 -0
- package/templates/config/CODE_PLANNING.md +14 -0
- package/templates/config/CRONS.json +56 -0
- package/templates/config/HEARTBEAT.md +3 -0
- package/templates/config/JOB_AGENT.md +30 -0
- package/templates/config/JOB_PLANNING.md +240 -0
- package/templates/config/JOB_SUMMARY.md +130 -0
- package/templates/config/SKILL_BUILDING_GUIDE.md +96 -0
- package/templates/config/SOUL.md +48 -0
- package/templates/config/TRIGGERS.json +58 -0
- package/templates/config/WEB_SEARCH_AVAILABLE.md +5 -0
- package/templates/config/WEB_SEARCH_UNAVAILABLE.md +3 -0
- package/templates/docker/claude-code-job/Dockerfile +34 -0
- package/templates/docker/claude-code-job/entrypoint.sh +149 -0
- package/templates/docker/claude-code-workspace/.tmux.conf +5 -0
- package/templates/docker/claude-code-workspace/Dockerfile +61 -0
- package/templates/docker/claude-code-workspace/entrypoint.sh +51 -0
- package/templates/docker/event-handler/Dockerfile +20 -0
- package/templates/docker/event-handler/ecosystem.config.cjs +7 -0
- package/templates/docker/pi-coding-agent-job/Dockerfile +51 -0
- package/templates/docker/pi-coding-agent-job/entrypoint.sh +164 -0
- package/templates/docker-compose.local.yml +78 -0
- package/templates/docker-compose.yml +64 -0
- package/templates/instrumentation.js +6 -0
- package/templates/middleware.js +23 -0
- package/templates/next.config.mjs +3 -0
- package/templates/postcss.config.mjs +5 -0
- package/templates/public/favicon.ico +0 -0
- package/templates/server.js +25 -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/google-docs/SKILL.md +23 -0
- package/templates/skills/google-docs/create.sh +69 -0
- package/templates/skills/google-drive/SKILL.md +47 -0
- package/templates/skills/google-drive/delete.sh +47 -0
- package/templates/skills/google-drive/download.sh +50 -0
- package/templates/skills/google-drive/list.sh +41 -0
- package/templates/skills/google-drive/upload.sh +76 -0
- package/templates/skills/kie-ai/SKILL.md +38 -0
- package/templates/skills/kie-ai/generate-image.sh +77 -0
- package/templates/skills/kie-ai/generate-video.sh +69 -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
- package/templates/skills/youtube-transcript/SKILL.md +41 -0
- package/templates/skills/youtube-transcript/package-lock.json +24 -0
- package/templates/skills/youtube-transcript/package.json +8 -0
- package/templates/skills/youtube-transcript/transcript.js +84 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { ChatPage } from './chat-page.js';
|
|
2
|
+
export { ChatsPage } from './chats-page.js';
|
|
3
|
+
export { NotificationsPage } from './notifications-page.js';
|
|
4
|
+
export { PullRequestsPage } from './pull-requests-page.js';
|
|
5
|
+
export { SwarmPage } from './swarm-page.js';
|
|
6
|
+
export { CronsPage } from './crons-page.js';
|
|
7
|
+
export { TriggersPage } from './triggers-page.js';
|
|
8
|
+
export { PageLayout } from './page-layout.js';
|
|
9
|
+
export { SettingsLayout } from './settings-layout.js';
|
|
10
|
+
export { SettingsSecretsPage } from './settings-secrets-page.js';
|
|
11
|
+
export { AppSidebar } from './app-sidebar.js';
|
|
12
|
+
export { SidebarHistory } from './sidebar-history.js';
|
|
13
|
+
export { SidebarHistoryItem } from './sidebar-history-item.js';
|
|
14
|
+
export { SidebarUserNav } from './sidebar-user-nav.js';
|
|
15
|
+
export { Chat } from './chat.js';
|
|
16
|
+
export { Messages } from './messages.js';
|
|
17
|
+
export { PreviewMessage, ThinkingMessage } from './message.js';
|
|
18
|
+
export { ChatInput } from './chat-input.js';
|
|
19
|
+
export { ChatHeader } from './chat-header.js';
|
|
20
|
+
export { Greeting } from './greeting.js';
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useRef, useEffect, useCallback } from "react";
|
|
4
|
+
import { Streamdown } from "streamdown";
|
|
5
|
+
import { cn } from "../utils.js";
|
|
6
|
+
import { SpinnerIcon, FileTextIcon, CopyIcon, CheckIcon, RefreshIcon, SquarePenIcon, WrenchIcon, XIcon, ChevronDownIcon } from "./icons.js";
|
|
7
|
+
function LinkSafetyModal({ url, isOpen, onClose, onConfirm }) {
|
|
8
|
+
const [copied, setCopied] = useState(false);
|
|
9
|
+
const handleCopy = useCallback(async () => {
|
|
10
|
+
try {
|
|
11
|
+
await navigator.clipboard.writeText(url);
|
|
12
|
+
setCopied(true);
|
|
13
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
14
|
+
} catch {
|
|
15
|
+
}
|
|
16
|
+
}, [url]);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!isOpen) return;
|
|
19
|
+
const onKey = (e) => {
|
|
20
|
+
if (e.key === "Escape") onClose();
|
|
21
|
+
};
|
|
22
|
+
document.addEventListener("keydown", onKey);
|
|
23
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
24
|
+
}, [isOpen, onClose]);
|
|
25
|
+
if (!isOpen) return null;
|
|
26
|
+
return /* @__PURE__ */ jsx(
|
|
27
|
+
"div",
|
|
28
|
+
{
|
|
29
|
+
className: "fixed inset-0 z-50 flex items-center justify-center bg-black/40",
|
|
30
|
+
onClick: onClose,
|
|
31
|
+
children: /* @__PURE__ */ jsxs(
|
|
32
|
+
"div",
|
|
33
|
+
{
|
|
34
|
+
className: "relative mx-4 flex w-full flex-col gap-3 rounded-lg border border-border bg-background p-4 shadow-lg",
|
|
35
|
+
style: { maxWidth: "340px" },
|
|
36
|
+
onClick: (e) => e.stopPropagation(),
|
|
37
|
+
children: [
|
|
38
|
+
/* @__PURE__ */ jsx("div", { className: "font-medium text-sm text-foreground", children: "Open external link?" }),
|
|
39
|
+
/* @__PURE__ */ jsx("div", { className: "break-all rounded bg-muted px-2.5 py-2 font-mono text-xs text-foreground", children: url }),
|
|
40
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
41
|
+
/* @__PURE__ */ jsxs(
|
|
42
|
+
"button",
|
|
43
|
+
{
|
|
44
|
+
onClick: handleCopy,
|
|
45
|
+
className: "flex flex-1 items-center justify-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-muted",
|
|
46
|
+
children: [
|
|
47
|
+
copied ? /* @__PURE__ */ jsx(CheckIcon, { size: 12 }) : /* @__PURE__ */ jsx(CopyIcon, { size: 12 }),
|
|
48
|
+
/* @__PURE__ */ jsx("span", { children: copied ? "Copied" : "Copy" })
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
),
|
|
52
|
+
/* @__PURE__ */ jsx(
|
|
53
|
+
"button",
|
|
54
|
+
{
|
|
55
|
+
onClick: () => {
|
|
56
|
+
onConfirm();
|
|
57
|
+
onClose();
|
|
58
|
+
},
|
|
59
|
+
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",
|
|
60
|
+
children: /* @__PURE__ */ jsx("span", { children: "Open" })
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
] })
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
const linkSafety = {
|
|
71
|
+
enabled: true,
|
|
72
|
+
renderModal: (props) => /* @__PURE__ */ jsx(LinkSafetyModal, { ...props })
|
|
73
|
+
};
|
|
74
|
+
const TOOL_DISPLAY_NAMES = {
|
|
75
|
+
create_job: "Create Job",
|
|
76
|
+
get_job_status: "Check Job Status",
|
|
77
|
+
get_system_technical_specs: "Read Tech Docs",
|
|
78
|
+
get_skill_building_guide: "Read Skill Docs",
|
|
79
|
+
start_coding: "Start Coding",
|
|
80
|
+
get_repository_details: "Get Repository Details"
|
|
81
|
+
};
|
|
82
|
+
function getToolDisplayName(toolName) {
|
|
83
|
+
return TOOL_DISPLAY_NAMES[toolName] || toolName.replace(/_/g, " ");
|
|
84
|
+
}
|
|
85
|
+
function formatContent(content) {
|
|
86
|
+
if (content == null) return null;
|
|
87
|
+
if (typeof content === "string") {
|
|
88
|
+
try {
|
|
89
|
+
const parsed = JSON.parse(content);
|
|
90
|
+
return JSON.stringify(parsed, null, 2);
|
|
91
|
+
} catch {
|
|
92
|
+
return content;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return JSON.stringify(content, null, 2);
|
|
96
|
+
}
|
|
97
|
+
function ToolCall({ part }) {
|
|
98
|
+
const [expanded, setExpanded] = useState(false);
|
|
99
|
+
const toolName = part.toolName || (part.type?.startsWith("tool-") ? part.type.slice(5) : "tool");
|
|
100
|
+
const displayName = getToolDisplayName(toolName);
|
|
101
|
+
const state = part.state || "input-available";
|
|
102
|
+
const isRunning = state === "input-streaming" || state === "input-available";
|
|
103
|
+
const isDone = state === "output-available";
|
|
104
|
+
const isError = state === "output-error";
|
|
105
|
+
const mountedDone = useRef(isDone);
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
if (toolName !== "start_coding" || !isDone || mountedDone.current) return;
|
|
108
|
+
try {
|
|
109
|
+
const output = typeof part.output === "string" ? JSON.parse(part.output) : part.output;
|
|
110
|
+
if (output?.success && output?.workspaceUrl) {
|
|
111
|
+
window.location.href = output.workspaceUrl;
|
|
112
|
+
}
|
|
113
|
+
} catch {
|
|
114
|
+
}
|
|
115
|
+
}, [toolName, isDone, part.output]);
|
|
116
|
+
return /* @__PURE__ */ jsxs("div", { className: "my-1 rounded-lg border border-border bg-background", children: [
|
|
117
|
+
/* @__PURE__ */ jsxs(
|
|
118
|
+
"button",
|
|
119
|
+
{
|
|
120
|
+
onClick: () => setExpanded(!expanded),
|
|
121
|
+
className: "flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-muted/50 rounded-lg",
|
|
122
|
+
children: [
|
|
123
|
+
/* @__PURE__ */ jsx(WrenchIcon, { size: 14, className: "text-muted-foreground shrink-0" }),
|
|
124
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium text-foreground", children: displayName }),
|
|
125
|
+
/* @__PURE__ */ jsxs("span", { className: "ml-auto flex items-center gap-1.5 text-xs text-muted-foreground", children: [
|
|
126
|
+
isRunning && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
127
|
+
/* @__PURE__ */ jsx(SpinnerIcon, { size: 12 }),
|
|
128
|
+
/* @__PURE__ */ jsx("span", { children: "Running..." })
|
|
129
|
+
] }),
|
|
130
|
+
isDone && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
131
|
+
/* @__PURE__ */ jsx(CheckIcon, { size: 12, className: "text-green-500" }),
|
|
132
|
+
/* @__PURE__ */ jsx("span", { children: "Done" })
|
|
133
|
+
] }),
|
|
134
|
+
isError && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
135
|
+
/* @__PURE__ */ jsx(XIcon, { size: 12, className: "text-red-500" }),
|
|
136
|
+
/* @__PURE__ */ jsx("span", { children: "Error" })
|
|
137
|
+
] })
|
|
138
|
+
] }),
|
|
139
|
+
/* @__PURE__ */ jsx(
|
|
140
|
+
ChevronDownIcon,
|
|
141
|
+
{
|
|
142
|
+
size: 14,
|
|
143
|
+
className: cn(
|
|
144
|
+
"text-muted-foreground transition-transform shrink-0",
|
|
145
|
+
expanded && "rotate-180"
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
),
|
|
152
|
+
expanded && /* @__PURE__ */ jsxs("div", { className: "border-t border-border px-3 py-2 text-xs", children: [
|
|
153
|
+
part.input != null && /* @__PURE__ */ jsxs("div", { className: "mb-2", children: [
|
|
154
|
+
/* @__PURE__ */ jsx("div", { className: "font-medium text-muted-foreground mb-1", children: "Input" }),
|
|
155
|
+
/* @__PURE__ */ jsx("pre", { className: "whitespace-pre-wrap break-all rounded bg-muted p-2 text-foreground overflow-x-auto", children: formatContent(part.input) })
|
|
156
|
+
] }),
|
|
157
|
+
part.output != null && /* @__PURE__ */ jsxs("div", { children: [
|
|
158
|
+
/* @__PURE__ */ jsx("div", { className: "font-medium text-muted-foreground mb-1", children: "Output" }),
|
|
159
|
+
/* @__PURE__ */ jsx("pre", { className: "whitespace-pre-wrap break-all rounded bg-muted p-2 text-foreground overflow-x-auto max-h-64 overflow-y-auto", children: formatContent(part.output) })
|
|
160
|
+
] }),
|
|
161
|
+
part.input == null && part.output == null && /* @__PURE__ */ jsx("div", { className: "text-muted-foreground italic", children: "Waiting for data..." })
|
|
162
|
+
] })
|
|
163
|
+
] });
|
|
164
|
+
}
|
|
165
|
+
function PreviewMessage({ message, isLoading, onRetry, onEdit }) {
|
|
166
|
+
const isUser = message.role === "user";
|
|
167
|
+
const [copied, setCopied] = useState(false);
|
|
168
|
+
const [editing, setEditing] = useState(false);
|
|
169
|
+
const [editText, setEditText] = useState("");
|
|
170
|
+
const textareaRef = useRef(null);
|
|
171
|
+
const text = message.parts?.filter((p) => p.type === "text").map((p) => p.text).join("\n") || message.content || "";
|
|
172
|
+
const fileParts = message.parts?.filter((p) => p.type === "file") || [];
|
|
173
|
+
const imageParts = fileParts.filter((p) => p.mediaType?.startsWith("image/"));
|
|
174
|
+
const otherFileParts = fileParts.filter((p) => !p.mediaType?.startsWith("image/"));
|
|
175
|
+
const hasToolParts = message.parts?.some((p) => p.type?.startsWith("tool-")) || false;
|
|
176
|
+
const handleCopy = async () => {
|
|
177
|
+
try {
|
|
178
|
+
await navigator.clipboard.writeText(text);
|
|
179
|
+
setCopied(true);
|
|
180
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
181
|
+
} catch {
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const handleEditStart = () => {
|
|
185
|
+
setEditText(text);
|
|
186
|
+
setEditing(true);
|
|
187
|
+
};
|
|
188
|
+
const handleEditCancel = () => {
|
|
189
|
+
setEditing(false);
|
|
190
|
+
setEditText("");
|
|
191
|
+
};
|
|
192
|
+
const handleEditSubmit = () => {
|
|
193
|
+
const trimmed = editText.trim();
|
|
194
|
+
if (trimmed && trimmed !== text) {
|
|
195
|
+
onEdit?.(message, trimmed);
|
|
196
|
+
}
|
|
197
|
+
setEditing(false);
|
|
198
|
+
setEditText("");
|
|
199
|
+
};
|
|
200
|
+
useEffect(() => {
|
|
201
|
+
if (editing && textareaRef.current) {
|
|
202
|
+
const ta = textareaRef.current;
|
|
203
|
+
ta.focus();
|
|
204
|
+
ta.style.height = "auto";
|
|
205
|
+
ta.style.height = `${ta.scrollHeight}px`;
|
|
206
|
+
ta.setSelectionRange(ta.value.length, ta.value.length);
|
|
207
|
+
}
|
|
208
|
+
}, [editing]);
|
|
209
|
+
return /* @__PURE__ */ jsx(
|
|
210
|
+
"div",
|
|
211
|
+
{
|
|
212
|
+
className: cn(
|
|
213
|
+
"group flex gap-4 w-full",
|
|
214
|
+
isUser ? "justify-end" : "justify-start"
|
|
215
|
+
),
|
|
216
|
+
children: /* @__PURE__ */ jsx("div", { className: cn("flex flex-col", isUser ? "max-w-[80%]" : "w-full"), children: editing ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
217
|
+
/* @__PURE__ */ jsx(
|
|
218
|
+
"textarea",
|
|
219
|
+
{
|
|
220
|
+
ref: textareaRef,
|
|
221
|
+
value: editText,
|
|
222
|
+
onChange: (e) => {
|
|
223
|
+
setEditText(e.target.value);
|
|
224
|
+
e.target.style.height = "auto";
|
|
225
|
+
e.target.style.height = `${e.target.scrollHeight}px`;
|
|
226
|
+
},
|
|
227
|
+
onKeyDown: (e) => {
|
|
228
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
229
|
+
e.preventDefault();
|
|
230
|
+
handleEditSubmit();
|
|
231
|
+
}
|
|
232
|
+
if (e.key === "Escape") {
|
|
233
|
+
handleEditCancel();
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
className: "w-full resize-none rounded-xl border border-border bg-muted px-4 py-3 text-sm leading-relaxed text-foreground focus:outline-none focus:ring-1 focus:ring-primary",
|
|
237
|
+
rows: 1
|
|
238
|
+
}
|
|
239
|
+
),
|
|
240
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
241
|
+
/* @__PURE__ */ jsx(
|
|
242
|
+
"button",
|
|
243
|
+
{
|
|
244
|
+
onClick: handleEditCancel,
|
|
245
|
+
className: "rounded-md px-3 py-1 text-xs text-muted-foreground hover:text-foreground",
|
|
246
|
+
children: "Cancel"
|
|
247
|
+
}
|
|
248
|
+
),
|
|
249
|
+
/* @__PURE__ */ jsx(
|
|
250
|
+
"button",
|
|
251
|
+
{
|
|
252
|
+
onClick: handleEditSubmit,
|
|
253
|
+
className: "rounded-md bg-primary px-3 py-1 text-xs text-primary-foreground hover:opacity-80",
|
|
254
|
+
children: "Send"
|
|
255
|
+
}
|
|
256
|
+
)
|
|
257
|
+
] })
|
|
258
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
259
|
+
/* @__PURE__ */ jsx(
|
|
260
|
+
"div",
|
|
261
|
+
{
|
|
262
|
+
className: cn(
|
|
263
|
+
"text-sm leading-relaxed",
|
|
264
|
+
isUser ? "rounded-xl px-4 py-3 bg-muted text-foreground" : "text-foreground"
|
|
265
|
+
),
|
|
266
|
+
children: isUser ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
267
|
+
imageParts.length > 0 && /* @__PURE__ */ jsx("div", { className: "mb-2 flex flex-wrap gap-2", children: imageParts.map((part, i) => /* @__PURE__ */ jsx(
|
|
268
|
+
"img",
|
|
269
|
+
{
|
|
270
|
+
src: part.url,
|
|
271
|
+
alt: "attachment",
|
|
272
|
+
className: "max-h-64 max-w-full rounded-lg object-contain"
|
|
273
|
+
},
|
|
274
|
+
i
|
|
275
|
+
)) }),
|
|
276
|
+
otherFileParts.length > 0 && /* @__PURE__ */ jsx("div", { className: "mb-2 flex flex-wrap gap-2", children: otherFileParts.map((part, i) => /* @__PURE__ */ jsxs(
|
|
277
|
+
"div",
|
|
278
|
+
{
|
|
279
|
+
className: "inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs bg-foreground/10",
|
|
280
|
+
children: [
|
|
281
|
+
/* @__PURE__ */ jsx(FileTextIcon, { size: 12 }),
|
|
282
|
+
/* @__PURE__ */ jsx("span", { className: "max-w-[150px] truncate", children: part.name || part.mediaType || "file" })
|
|
283
|
+
]
|
|
284
|
+
},
|
|
285
|
+
i
|
|
286
|
+
)) }),
|
|
287
|
+
text ? /* @__PURE__ */ jsx("div", { className: "whitespace-pre-wrap break-words", children: text }) : null
|
|
288
|
+
] }) : /* @__PURE__ */ jsx(Fragment, { children: message.parts?.length > 0 ? message.parts.map((part, i) => {
|
|
289
|
+
if (part.type === "text") {
|
|
290
|
+
return /* @__PURE__ */ jsx(Streamdown, { mode: isLoading ? "streaming" : "static", linkSafety, children: part.text }, i);
|
|
291
|
+
}
|
|
292
|
+
if (part.type === "file") {
|
|
293
|
+
if (part.mediaType?.startsWith("image/")) {
|
|
294
|
+
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);
|
|
295
|
+
}
|
|
296
|
+
return /* @__PURE__ */ jsxs("div", { className: "mb-2 inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs bg-foreground/10", children: [
|
|
297
|
+
/* @__PURE__ */ jsx(FileTextIcon, { size: 12 }),
|
|
298
|
+
/* @__PURE__ */ jsx("span", { className: "max-w-[150px] truncate", children: part.name || part.mediaType || "file" })
|
|
299
|
+
] }, i);
|
|
300
|
+
}
|
|
301
|
+
if (part.type?.startsWith("tool-")) {
|
|
302
|
+
return /* @__PURE__ */ jsx(ToolCall, { part }, part.toolCallId || i);
|
|
303
|
+
}
|
|
304
|
+
return null;
|
|
305
|
+
}) : 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: [
|
|
306
|
+
/* @__PURE__ */ jsx(SpinnerIcon, { size: 14 }),
|
|
307
|
+
/* @__PURE__ */ jsx("span", { children: "Working..." })
|
|
308
|
+
] }) : null })
|
|
309
|
+
}
|
|
310
|
+
),
|
|
311
|
+
!isLoading && text && /* @__PURE__ */ jsxs(
|
|
312
|
+
"div",
|
|
313
|
+
{
|
|
314
|
+
className: cn(
|
|
315
|
+
"flex gap-1 mt-1 opacity-0 transition-opacity group-hover:opacity-100",
|
|
316
|
+
isUser ? "justify-end" : "justify-start"
|
|
317
|
+
),
|
|
318
|
+
children: [
|
|
319
|
+
/* @__PURE__ */ jsx(
|
|
320
|
+
"button",
|
|
321
|
+
{
|
|
322
|
+
onClick: handleCopy,
|
|
323
|
+
className: "rounded-md p-1 text-muted-foreground hover:text-foreground hover:bg-muted",
|
|
324
|
+
"aria-label": "Copy message",
|
|
325
|
+
children: copied ? /* @__PURE__ */ jsx(CheckIcon, { size: 14 }) : /* @__PURE__ */ jsx(CopyIcon, { size: 14 })
|
|
326
|
+
}
|
|
327
|
+
),
|
|
328
|
+
onRetry && /* @__PURE__ */ jsx(
|
|
329
|
+
"button",
|
|
330
|
+
{
|
|
331
|
+
onClick: () => onRetry(message),
|
|
332
|
+
className: "rounded-md p-1 text-muted-foreground hover:text-foreground hover:bg-muted",
|
|
333
|
+
"aria-label": "Retry",
|
|
334
|
+
children: /* @__PURE__ */ jsx(RefreshIcon, { size: 14 })
|
|
335
|
+
}
|
|
336
|
+
),
|
|
337
|
+
isUser && onEdit && /* @__PURE__ */ jsx(
|
|
338
|
+
"button",
|
|
339
|
+
{
|
|
340
|
+
onClick: handleEditStart,
|
|
341
|
+
className: "rounded-md p-1 text-muted-foreground hover:text-foreground hover:bg-muted",
|
|
342
|
+
"aria-label": "Edit message",
|
|
343
|
+
children: /* @__PURE__ */ jsx(SquarePenIcon, { size: 14 })
|
|
344
|
+
}
|
|
345
|
+
)
|
|
346
|
+
]
|
|
347
|
+
}
|
|
348
|
+
)
|
|
349
|
+
] }) })
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
function ThinkingMessage() {
|
|
354
|
+
return /* @__PURE__ */ jsx("div", { className: "flex gap-4 w-full justify-start", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-4 py-3 text-sm text-muted-foreground", children: [
|
|
355
|
+
/* @__PURE__ */ jsx(SpinnerIcon, { size: 14 }),
|
|
356
|
+
/* @__PURE__ */ jsx("span", { children: "Thinking..." })
|
|
357
|
+
] }) });
|
|
358
|
+
}
|
|
359
|
+
export {
|
|
360
|
+
PreviewMessage,
|
|
361
|
+
ThinkingMessage,
|
|
362
|
+
linkSafety
|
|
363
|
+
};
|