import { useState, type ReactNode } from "react";
import { Check, Copy, LoaderCircle, CircleAlert } from "lucide-react";
import { MessageAction, MessageActions } from "@/shared/ai-elements/message";
import { getAnswerPartsTranscript } from "../answer-ui/answer-presentation";
import type { AnswerUiPart } from "../answer-ui/contract";
export function AgentChatMessageHeader({ running }: { running: boolean }) {
if (!running) return null;
return (
正在回复
);
}
export const AGENT_MESSAGE_ACTION_CLASS_NAME =
"h-8 min-w-8 gap-1.5 px-2 text-sm font-normal text-muted-foreground shadow-none after:inset-0";
export const AGENT_MESSAGE_ACTION_LABEL_CLASS_NAME = "hidden @[320px]/agent-message-actions:inline";
export function AgentChatMessageToolbar({
speech,
copy,
children
}: {
speech?: ReactNode;
copy?: ReactNode;
children?: ReactNode;
}) {
return (
{children}
{speech}
{copy}
);
}
export function AgentChatMessageActions({ parts }: { parts: AnswerUiPart[] }) {
const [copied, setCopied] = useState(false);
const [error, setError] = useState(false);
const text = getAnswerPartsTranscript(parts);
if (!text.trim()) return null;
return (
{
try {
await navigator.clipboard.writeText(text);
setCopied(true);
setError(false);
} catch {
setCopied(false);
setError(true);
}
}}
>
{error ? (
) : copied ? (
) : (
)}
{error ? "重试复制" : copied ? "已复制" : "复制"}
{error ? "复制失败,请选择文字复制" : copied ? "已复制回复文字与交互内容摘要" : ""}
);
}