Skip to content
TypeScript

fix(web): queued follow-ups show the quoted text instead of the citation link (#18999)

Igor Makowski8f778615f972
diff --git a/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx b/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx
index a18f1bcfdc8..18d136620e8 100644
--- a/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx
+++ b/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx
@@ -1,6 +1,9 @@
+import { EnvironmentId, MessageId, ThreadId } from "@t3tools/contracts";
+import { serializeAssistantCitation } from "@t3tools/shared/assistantCitations";
import { act, type ComponentProps } from "react";
import { createRoot, type Root } from "react-dom/client";
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
+import { page } from "vite-plus/test/browser";
const state = vi.hoisted(() => ({
projection: null as unknown,
@@ -162,3 +165,51 @@ describe("QueuedRunsControl attachments and edit mode", () => {
expect(view.textContent).toContain("Queued with a screenshot");
});
});
+
+it("previews assistant quotes as readable text and preserves the citation when editing", async () => {
+ const quotedText = "Cache the parsed config per worktree.";
+ const quote = serializeAssistantCitation({
+ version: 1,
+ environmentId: EnvironmentId.make("environment:test"),
+ threadId: ThreadId.make("thread:test"),
+ messageId: MessageId.make("message:assistant"),
+ text: quotedText,
+ start: 0,
+ end: quotedText.length,
+ prefix: "",
+ suffix: "",
+ });
+ const quoteAndText = `${quote}\n\nWhy per worktree?`;
+ state.projection = { projection: { messages: [] } };
+ state.workflow = {
+ activeRun: { id: "run:active" },
+ canPromoteToSteer: true,
+ canReorder: true,
+ queuedRuns: [
+ {
+ run: { id: "run:quote-only", userMessageId: "message:quote-only" },
+ text: quote,
+ attachments: [],
+ },
+ {
+ run: { id: "run:quote-and-text", userMessageId: "message:quote-and-text" },
+ text: quoteAndText,
+ attachments: [],
+ },
+ ],
+ };
+ const onEditQueuedRun = vi.fn();
+ await render({ onEditQueuedRun });
+
+ await expect.element(page.getByText(quotedText, { exact: true })).toBeVisible();
+ await expect
+ .element(page.getByText(`${quotedText} Why per worktree?`, { exact: true }))
+ .toBeVisible();
+
+ await act(async () => {
+ await page.getByRole("button", { name: "Edit queued message", exact: true }).nth(1).click();
+ });
+ expect(onEditQueuedRun).toHaveBeenCalledExactlyOnceWith(
+ expect.objectContaining({ text: quoteAndText }),
+ );
+});
diff --git a/apps/web/src/components/chat/QueuedRunsControl.tsx b/apps/web/src/components/chat/QueuedRunsControl.tsx
index 2cef09911f3..63d25f6bd77 100644
--- a/apps/web/src/components/chat/QueuedRunsControl.tsx
+++ b/apps/web/src/components/chat/QueuedRunsControl.tsx
@@ -1,5 +1,6 @@
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
import { deriveThreadQueueWorkflowState } from "@t3tools/client-runtime/state/thread-workflows";
+import { assistantCitationsToPlainText } from "@t3tools/shared/assistantCitations";
import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
import type {
ChatAttachment as ContractChatAttachment,
@@ -246,8 +247,10 @@ export function QueuedRunsControl({
<ComposerBanner.Scroll className={cn("max-h-32", !expanded && "hidden")}>
<ComposerBanner.Children render={<ol />} id={queueListId}>
{items.map((item) => {
- const previewText = replaceComposerContextReferences(item.text, (reference) =>
- reference.kind === "image" && item.thumbnails.length > 0 ? "" : reference.label,
+ const previewText = assistantCitationsToPlainText(
+ replaceComposerContextReferences(item.text, (reference) =>
+ reference.kind === "image" && item.thumbnails.length > 0 ? "" : reference.label,
+ ),
).trim();
const rowRunId = item.runId;
const rowServerIndex = item.serverIndex;