Add aligned assistant timestamps and Copy/Fork actions
This commit is contained in:
+37
-74
@@ -121,12 +121,6 @@ type ContextMenuState = {
|
||||
item: SidebarSelection;
|
||||
x: number;
|
||||
y: number;
|
||||
} | {
|
||||
kind: "message";
|
||||
chatId: string;
|
||||
messageId: string;
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
type RenameChatDialogState = {
|
||||
chatId: string;
|
||||
@@ -2199,24 +2193,6 @@ export default function App() {
|
||||
setContextMenu({ kind: "sidebar", item, x: Math.max(padding, x), y: Math.max(padding, y) });
|
||||
};
|
||||
|
||||
const openMessageContextMenu = (event: MouseEvent, messageId: string) => {
|
||||
if (selectedItem?.kind !== "chat" || messageId.startsWith("temp-")) return;
|
||||
event.preventDefault();
|
||||
const menuWidth = 176;
|
||||
const menuHeight = 48;
|
||||
const padding = 8;
|
||||
const anchor = (event.currentTarget as HTMLElement).getBoundingClientRect();
|
||||
const x = Math.min(anchor.left, window.innerWidth - menuWidth - padding);
|
||||
const y = Math.min(anchor.bottom, window.innerHeight - menuHeight - padding);
|
||||
setContextMenu({
|
||||
kind: "message",
|
||||
chatId: selectedItem.id,
|
||||
messageId,
|
||||
x: Math.max(padding, x),
|
||||
y: Math.max(padding, y),
|
||||
});
|
||||
};
|
||||
|
||||
const handleRenameChatSubmit = async (event?: Event) => {
|
||||
event?.preventDefault();
|
||||
if (!renameChatDialog || isRenamingChat) return;
|
||||
@@ -3819,7 +3795,8 @@ export default function App() {
|
||||
messages={displayMessages}
|
||||
isLoading={isLoadingSelection}
|
||||
isSending={isSendingActiveChat}
|
||||
onMessageActions={openMessageContextMenu}
|
||||
onForkMessage={selectedItem?.kind === "chat" ? messageId => void handleForkChat(selectedItem.id, messageId) : undefined}
|
||||
isForking={isForkingChat}
|
||||
/>
|
||||
) : (
|
||||
<SearchResultsPanel
|
||||
@@ -3906,65 +3883,51 @@ export default function App() {
|
||||
style={{ left: contextMenu.x, top: contextMenu.y }}
|
||||
onContextMenu={(event) => event.preventDefault()}
|
||||
>
|
||||
{contextMenu.kind === "message" ? (
|
||||
<button
|
||||
type="button"
|
||||
className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-violet-100 transition hover:bg-violet-400/12 disabled:text-muted-foreground"
|
||||
onClick={() => void handleForkChat(contextMenu.chatId, contextMenu.messageId)}
|
||||
disabled={isForkingChat}
|
||||
>
|
||||
<GitFork className="h-3.5 w-3.5" />
|
||||
Fork
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-violet-100 transition hover:bg-violet-400/12"
|
||||
onClick={() => void handleToggleStar(contextMenu.item)}
|
||||
>
|
||||
<Star
|
||||
className={cn(
|
||||
"h-3.5 w-3.5",
|
||||
isSidebarTargetStarred(contextMenu.item)
|
||||
? "fill-amber-300 text-amber-300"
|
||||
: ""
|
||||
)}
|
||||
/>
|
||||
{isSidebarTargetStarred(contextMenu.item) ? "Unstar" : "Star"}
|
||||
</button>
|
||||
{contextMenu.item.kind === "chat" ? (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-violet-100 transition hover:bg-violet-400/12"
|
||||
onClick={() => void handleToggleStar(contextMenu.item)}
|
||||
className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-violet-100 transition hover:bg-violet-400/12 disabled:text-muted-foreground"
|
||||
onClick={() => void handleForkChat(contextMenu.item.id)}
|
||||
disabled={isForkingChat || isItemRunning(contextMenu.item)}
|
||||
>
|
||||
<Star
|
||||
className={cn(
|
||||
"h-3.5 w-3.5",
|
||||
isSidebarTargetStarred(contextMenu.item)
|
||||
? "fill-amber-300 text-amber-300"
|
||||
: ""
|
||||
)}
|
||||
/>
|
||||
{isSidebarTargetStarred(contextMenu.item) ? "Unstar" : "Star"}
|
||||
<GitFork className="h-3.5 w-3.5" />
|
||||
Fork
|
||||
</button>
|
||||
{contextMenu.item.kind === "chat" ? (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-violet-100 transition hover:bg-violet-400/12 disabled:text-muted-foreground"
|
||||
onClick={() => void handleForkChat(contextMenu.item.id)}
|
||||
disabled={isForkingChat || isItemRunning(contextMenu.item)}
|
||||
>
|
||||
<GitFork className="h-3.5 w-3.5" />
|
||||
Fork
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-violet-100 transition hover:bg-violet-400/12"
|
||||
onClick={() => openRenameChatDialog(contextMenu.item.id)}
|
||||
>
|
||||
<Pencil className="h-3.5 w-3.5" />
|
||||
Rename
|
||||
</button>
|
||||
</>
|
||||
) : null}
|
||||
<button
|
||||
type="button"
|
||||
className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-rose-300 transition hover:bg-rose-500/12 disabled:text-muted-foreground"
|
||||
onClick={() => void handleDeleteFromContextMenu()}
|
||||
disabled={isDeleteBlocked(contextMenu.item)}
|
||||
className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-violet-100 transition hover:bg-violet-400/12"
|
||||
onClick={() => openRenameChatDialog(contextMenu.item.id)}
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5" />
|
||||
{isRootChat(contextMenu.item) ? "Delete group" : "Delete"}
|
||||
<Pencil className="h-3.5 w-3.5" />
|
||||
Rename
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
) : null}
|
||||
<button
|
||||
type="button"
|
||||
className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-rose-300 transition hover:bg-rose-500/12 disabled:text-muted-foreground"
|
||||
onClick={() => void handleDeleteFromContextMenu()}
|
||||
disabled={isDeleteBlocked(contextMenu.item)}
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5" />
|
||||
{isRootChat(contextMenu.item) ? "Delete group" : "Delete"}
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
{isChatSettingsOpen ? (
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { useEffect, useRef, useState } from "preact/hooks";
|
||||
import { Check, Copy, GitFork } from "lucide-preact";
|
||||
import type { Message } from "@/lib/api";
|
||||
|
||||
const receivedFormat = new Intl.DateTimeFormat(undefined, {
|
||||
year: "numeric", month: "short", day: "numeric", hour: "numeric", minute: "2-digit",
|
||||
});
|
||||
const actionClass = "inline-flex h-10 items-center gap-1.5 rounded-md px-2 text-xs transition-colors hover:bg-violet-400/12 hover:text-violet-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-ring disabled:cursor-wait disabled:opacity-50";
|
||||
|
||||
export function AssistantMessageFooter({ message, onFork, isForking = false }: {
|
||||
message: Message;
|
||||
onFork?: (messageId: string) => void;
|
||||
isForking?: boolean;
|
||||
}) {
|
||||
const [copyState, setCopyState] = useState<"idle" | "copied" | "failed">("idle");
|
||||
const resetTimer = useRef<ReturnType<typeof setTimeout>>();
|
||||
useEffect(() => () => clearTimeout(resetTimer.current), []);
|
||||
|
||||
const copy = async () => {
|
||||
clearTimeout(resetTimer.current);
|
||||
try {
|
||||
await navigator.clipboard.writeText(message.content);
|
||||
setCopyState("copied");
|
||||
resetTimer.current = setTimeout(() => setCopyState("idle"), 2000);
|
||||
} catch {
|
||||
setCopyState("failed");
|
||||
}
|
||||
};
|
||||
const received = new Date(message.createdAt);
|
||||
const hasDate = Number.isFinite(received.getTime());
|
||||
|
||||
return (
|
||||
<div className="text-muted-foreground" data-assistant-footer={message.id} data-mobile-swipe-ignore>
|
||||
{hasDate ? <time className="block text-xs leading-5" dateTime={message.createdAt} title={`Received ${received.toLocaleString()}`}>
|
||||
{receivedFormat.format(received)}
|
||||
</time> : null}
|
||||
<div className="-ml-2 flex flex-wrap items-center gap-1" role="group" aria-label="Message actions">
|
||||
{message.content.trim() ? <button type="button" className={actionClass} onClick={() => void copy()} title="Copy message" aria-label="Copy message">
|
||||
{copyState === "copied" ? <Check className="h-3.5 w-3.5" aria-hidden="true" /> : <Copy className="h-3.5 w-3.5" aria-hidden="true" />}
|
||||
<span>{copyState === "copied" ? "Copied" : "Copy"}</span>
|
||||
</button> : null}
|
||||
{onFork ? <button type="button" className={actionClass} onClick={() => onFork(message.id)} disabled={isForking} title="Fork chat from this message" aria-label="Fork chat from this message">
|
||||
<GitFork className="h-3.5 w-3.5" aria-hidden="true" />
|
||||
<span>Fork</span>
|
||||
</button> : null}
|
||||
</div>
|
||||
<span className={copyState === "failed" ? "block text-xs leading-5" : "sr-only"} role="status" aria-live="polite">
|
||||
{copyState === "copied" ? "Message copied." : copyState === "failed" ? "Could not copy. Select the message text and use your browser’s Copy command." : ""}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -2,17 +2,19 @@ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/ho
|
||||
import type { ComponentChildren, JSX } from "preact";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { ChatAttachmentList } from "@/components/chat/chat-attachment-list";
|
||||
import { AssistantMessageFooter } from "@/components/chat/assistant-message-footer";
|
||||
import { getMessageAttachments, type Message } from "@/lib/api";
|
||||
import { asStreamingAssistantMetadata, isInlineAgentReplyPending } from "@/lib/chat-stream-presentation";
|
||||
import { AgentBubble } from "@/components/agent/agent-conversation";
|
||||
import { MarkdownContent } from "@/components/markdown/markdown-content";
|
||||
import { ChevronDown, ChevronUp, Globe2, Link2, MoreHorizontal, Wrench } from "lucide-preact";
|
||||
import { ChevronDown, ChevronUp, Globe2, Link2, Wrench } from "lucide-preact";
|
||||
|
||||
type Props = {
|
||||
messages: Message[];
|
||||
isLoading: boolean;
|
||||
isSending: boolean;
|
||||
onMessageActions?: (event: MouseEvent, messageId: string) => void;
|
||||
onForkMessage?: (messageId: string) => void;
|
||||
isForking?: boolean;
|
||||
};
|
||||
|
||||
type ToolLogMetadata = {
|
||||
@@ -538,7 +540,7 @@ export function StreamingAssistantPresentation({ message, isSending }: { message
|
||||
);
|
||||
}
|
||||
|
||||
export function ChatMessagesPanel({ messages, isLoading, isSending, onMessageActions }: Props) {
|
||||
export function ChatMessagesPanel({ messages, isLoading, isSending, onForkMessage, isForking }: Props) {
|
||||
const hasPendingAssistant = messages.some((message) => message.id.startsWith("temp-assistant-"));
|
||||
const renderItems = useMemo(() => buildMessageRenderItems(messages), [messages]);
|
||||
const toolCallMessageIDs = useMemo(() => getToolCallMessageIDs(messages), [messages]);
|
||||
@@ -637,12 +639,8 @@ export function ChatMessagesPanel({ messages, isLoading, isSending, onMessageAct
|
||||
className={cn("[&_a]:text-inherit [&_a]:underline", !isUser && "leading-[1.82] text-violet-50")}
|
||||
/>
|
||||
) : null}
|
||||
{message.role === "assistant" && !message.id.startsWith("temp-") && onMessageActions ? (
|
||||
<button type="button" aria-label="Message actions" title="Message actions"
|
||||
className="flex h-9 w-9 items-center justify-center rounded text-muted-foreground hover:bg-violet-400/12 hover:text-violet-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-ring"
|
||||
onClick={event => onMessageActions(event, message.id)}>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</button>
|
||||
{message.role === "assistant" && !message.id.startsWith("temp-") ? (
|
||||
<AssistantMessageFooter message={message} onFork={onForkMessage} isForking={isForking} />
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user