2 files changed
+21
-6
No files matched your search
@@ -8,6 +8,19 @@ describe("AI message copy payload", () => {
|
|||||||
expect(resolveAiMessageCopyText({ role: "user", content }, false)).toBe(content);
|
expect(resolveAiMessageCopyText({ role: "user", content }, false)).toBe(content);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("keeps table and SQL file references when copying a user message", () => {
|
||||||
|
const message = {
|
||||||
|
role: "user" as const,
|
||||||
|
content: "Explain this query",
|
||||||
|
mentions: [
|
||||||
|
{ kind: "table" as const, raw: "@public.orders" },
|
||||||
|
{ kind: "sqlFile" as const, raw: "@setup.sql" },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(resolveAiMessageCopyText(message, false)).toBe("@public.orders @setup.sql\n\nExplain this query");
|
||||||
|
});
|
||||||
|
|
||||||
it("copies only the assistant message body", () => {
|
it("copies only the assistant message body", () => {
|
||||||
const message = {
|
const message = {
|
||||||
role: "assistant" as const,
|
role: "assistant" as const,
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
export interface AiMessageCopyCandidate {
|
export interface AiMessageCopyCandidate {
|
||||||
role: "user" | "assistant";
|
role: "user" | "assistant";
|
||||||
content: string;
|
content: string;
|
||||||
|
mentions?: readonly AiMessageCopyMention[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AiMessageCopyMention {
|
||||||
|
kind: string;
|
||||||
|
raw: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Keeps message-level copy payloads scoped to the original message body.
|
|
||||||
* Reasoning, tool activity, mentions, and rendered HTML live outside this
|
|
||||||
* contract and must not be appended by the caller.
|
|
||||||
*/
|
|
||||||
export function resolveAiMessageCopyText(message: AiMessageCopyCandidate, streaming: boolean): string | null {
|
export function resolveAiMessageCopyText(message: AiMessageCopyCandidate, streaming: boolean): string | null {
|
||||||
if (!message.content || streaming) return null;
|
if (!message.content || streaming) return null;
|
||||||
return message.content;
|
const references = message.mentions?.filter((mention) => mention.kind === "table" || mention.kind === "sqlFile").map((mention) => mention.raw) ?? [];
|
||||||
|
return references.length > 0 ? `${references.join(" ")}\n\n${message.content}` : message.content;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user