add paste-back button to assistant action bar

This commit is contained in:
CREDO23 2026-03-26 20:30:19 +02:00
parent 5bb4f5c084
commit 2adffccd92

View file

@ -3,10 +3,11 @@ import {
AuiIf, AuiIf,
ErrorPrimitive, ErrorPrimitive,
MessagePrimitive, MessagePrimitive,
useAui,
useAuiState, useAuiState,
} from "@assistant-ui/react"; } from "@assistant-ui/react";
import { useAtomValue } from "jotai"; import { useAtomValue } from "jotai";
import { CheckIcon, CopyIcon, DownloadIcon, MessageSquare, RefreshCwIcon } from "lucide-react"; import { CheckIcon, ClipboardPaste, CopyIcon, DownloadIcon, MessageSquare, RefreshCwIcon } from "lucide-react";
import type { FC } from "react"; import type { FC } from "react";
import { useEffect, useMemo, useRef, useState } from "react"; import { useEffect, useMemo, useRef, useState } from "react";
import { commentsEnabledAtom, targetCommentIdAtom } from "@/atoms/chat/current-thread.atom"; import { commentsEnabledAtom, targetCommentIdAtom } from "@/atoms/chat/current-thread.atom";
@ -272,6 +273,8 @@ export const AssistantMessage: FC = () => {
const AssistantActionBar: FC = () => { const AssistantActionBar: FC = () => {
const isLast = useAuiState((s) => s.message.isLast); const isLast = useAuiState((s) => s.message.isLast);
const aui = useAui();
const canReplace = isLast && typeof window !== "undefined" && !!window.electronAPI?.replaceText;
return ( return (
<ActionBarPrimitive.Root <ActionBarPrimitive.Root
@ -295,7 +298,17 @@ const AssistantActionBar: FC = () => {
<DownloadIcon /> <DownloadIcon />
</TooltipIconButton> </TooltipIconButton>
</ActionBarPrimitive.ExportMarkdown> </ActionBarPrimitive.ExportMarkdown>
{/* Only allow regenerating the last assistant message */} {canReplace && (
<TooltipIconButton
tooltip="Paste back"
onClick={() => {
const text = aui.message().getCopyText();
window.electronAPI?.replaceText(text);
}}
>
<ClipboardPaste />
</TooltipIconButton>
)}
{isLast && ( {isLast && (
<ActionBarPrimitive.Reload asChild> <ActionBarPrimitive.Reload asChild>
<TooltipIconButton tooltip="Refresh"> <TooltipIconButton tooltip="Refresh">