fix(agent-threads): hide prompt reference directives in thread titles
Add a shared visiblePromptText helper and strip reference tokens, image-generator directives, and model-selection lines from agent thread summaries and the assistant panel header, so titles show the user's actual prompt instead of internal directives. Covered by a server test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -75,6 +75,22 @@ export function serializePromptImageReference(reference: Pick<PromptImageReferen
|
||||
return `[@image:#${fallbackIndex}:${name}:${reference.url}]`;
|
||||
}
|
||||
|
||||
export function visiblePromptText(content: string) {
|
||||
const text = parsePromptImageReferences(content)
|
||||
.map((part) => (part.type === "text" ? part.text : ""))
|
||||
.join("");
|
||||
return text
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => {
|
||||
const lower = line.toLowerCase();
|
||||
return line && !lower.startsWith("image generator target node:") && !lower.startsWith("selected model:") && !line.startsWith("模型选择");
|
||||
})
|
||||
.join(" ")
|
||||
.replace(/\s{2,}/g, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
function collectReferenceMatches(content: string) {
|
||||
const matches: ReferenceMatch[] = [];
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import { loadMotevaFontCatalog } from "@/ui/components/TextStyleToolbar/fontCata
|
||||
import { WorkspaceTitle } from "@/ui/components/WorkspaceTitle";
|
||||
import { autoImageAdjustments, defaultImageAdjustments, parseImageAdjustments, serializeImageAdjustments } from "@/ui/lib/imageAdjustments";
|
||||
import { canvasImageUrl } from "@/ui/lib/imageDelivery";
|
||||
import { visiblePromptText } from "@/ui/lib/promptImageReferences";
|
||||
import { isImageGeneratorThreadMessage, visibleAgentMessages } from "./canvas/agentMessageFilters";
|
||||
import { CanvasColorPopover } from "./canvas/CanvasColorPopover";
|
||||
import { buildAlignmentGuides, clamp, minGroupNodeScale, nodeBounds, nodeIntersectsRect, normalizeScreenRect, pointInsideNode, scaleGroupNode, screenBoundsForNodes, screenRectToWorldRect, type AlignmentGuide, type NodeAlignment, type NodeDistribution, type NodeTransform, type ResizeHandle, type SelectionBox } from "@/ui/pages/CanvasWorkspace/canvas/canvasGeometry";
|
||||
@@ -3756,7 +3757,7 @@ export function CanvasWorkspace({ projectId }: { projectId: string }) {
|
||||
<aside className="assistant-panel">
|
||||
<div className="assistant-header">
|
||||
<div className="assistant-header-title">
|
||||
<strong>{project.brief || project.title || t("canvasUntitled")}</strong>
|
||||
<strong>{agentHeaderTitle(messages, project, t("canvasUntitled"))}</strong>
|
||||
</div>
|
||||
<div className="assistant-header-actions">
|
||||
<button className="assistant-header-icon" type="button" aria-label={t("newChat")} title={t("newChat")} onClick={beginNewAgentConversation} disabled={!hasCurrentConversation}>
|
||||
@@ -5289,7 +5290,7 @@ function fallbackAgentThreads(project: Project | null, hiddenThreadIds: Readonly
|
||||
}
|
||||
|
||||
function agentThreadTitle(thread: AgentThreadSummary) {
|
||||
return thread.text.trim() || "新对话";
|
||||
return visiblePromptText(thread.text) || "新对话";
|
||||
}
|
||||
|
||||
function latestAgentThreadId(project: Project | null, hiddenThreadIds: ReadonlySet<string>) {
|
||||
@@ -5298,14 +5299,14 @@ function latestAgentThreadId(project: Project | null, hiddenThreadIds: ReadonlyS
|
||||
}
|
||||
|
||||
function agentThreadTitleText(content: string) {
|
||||
const lines = content
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => {
|
||||
const lower = line.toLowerCase();
|
||||
return line && !lower.startsWith("image generator target node:") && !lower.startsWith("selected model:") && !line.startsWith("模型选择");
|
||||
});
|
||||
return lines.join(" ").trim() || content.trim();
|
||||
return visiblePromptText(content);
|
||||
}
|
||||
|
||||
function agentHeaderTitle(messages: AgentMessage[], project: Project, fallback: string) {
|
||||
const firstUserMessage = messages.find((message) => message.role === "user");
|
||||
const firstUserText = firstUserMessage ? visiblePromptText(firstUserMessage.content) : "";
|
||||
if (firstUserText) return firstUserText;
|
||||
return visiblePromptText(project.brief) || project.title.trim() || fallback;
|
||||
}
|
||||
|
||||
function isProjectGenerating(project: Project) {
|
||||
|
||||
Reference in New Issue
Block a user