fix: 节流会商流式写文件预览,避免 Maximum update depth
write_file 的 content 在每个 SSE chunk 中持续增长,原先会反复触发 React 状态更新并打断整页;现改为按身份入参去重、节流发布 stub,并收口第 3 步为 Markdown 报告工作台。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
dcfaa199bf
commit
30799f17be
14 files changed
+644
-703
No files matched your search
@@ -29,6 +29,42 @@ import type { TaskArtifactSubmissionController } from "@/roundtable-planning/lib
|
||||
|
||||
const CLOSE_MODE = { chat: 100, artifacts: 0 };
|
||||
const OPEN_MODE = { chat: 60, artifacts: 40 };
|
||||
|
||||
/** 从 write_file 虚拟地址反查流式工具调用中的正文,供任务产物提交直接使用。 */
|
||||
function virtualMarkdownContent(
|
||||
artifact: string | null,
|
||||
messages: unknown[] | undefined,
|
||||
): string | undefined {
|
||||
if (!artifact?.startsWith("write-file:") || !messages?.length) return undefined;
|
||||
try {
|
||||
const url = new URL(artifact);
|
||||
const toolCallId = url.searchParams.get("tool_call_id");
|
||||
const path = decodeURIComponent(url.pathname).trim();
|
||||
for (const message of messages) {
|
||||
if (!message || typeof message !== "object") continue;
|
||||
const toolCalls = (message as { tool_calls?: unknown }).tool_calls;
|
||||
if (!Array.isArray(toolCalls)) continue;
|
||||
for (const call of toolCalls) {
|
||||
if (!call || typeof call !== "object") continue;
|
||||
const toolCall = call as {
|
||||
id?: unknown;
|
||||
name?: unknown;
|
||||
args?: { path?: unknown; content?: unknown };
|
||||
};
|
||||
if (toolCall.name !== "write_file") continue;
|
||||
if (toolCallId && toolCall.id !== toolCallId) continue;
|
||||
if (!toolCallId && toolCall.args?.path !== path) continue;
|
||||
return typeof toolCall.args?.content === "string"
|
||||
? toolCall.args.content
|
||||
: undefined;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// 虚拟路径解析失败时交给提交层走它原有的真实文件读取兜底。
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
interface Step2SandboxLayoutProps {
|
||||
children?: React.ReactNode;
|
||||
/** 当前预览文件所属的席位 thread id。 */
|
||||
@@ -73,6 +109,10 @@ export function Step2SandboxLayout({
|
||||
deselect,
|
||||
} = useArtifacts();
|
||||
const artifacts = rawArtifacts ?? [];
|
||||
const selectedArtifactContent = useMemo(
|
||||
() => virtualMarkdownContent(selectedArtifact, seatMessages),
|
||||
[selectedArtifact, seatMessages],
|
||||
);
|
||||
|
||||
const artifactPanelOpen = artifactsOpen;
|
||||
// sidePanel(流程图等)非空时即使沙箱没开也要把右栏撑开。
|
||||
@@ -120,9 +160,9 @@ export function Step2SandboxLayout({
|
||||
filepath={selectedArtifact}
|
||||
threadId={previewThreadId}
|
||||
onClose={artifactsFill && onArtifactsClose ? handleArtifactsClose : undefined}
|
||||
allowVirtualMarkdownEdit
|
||||
// 会商「消息列表沙箱」按需求不脱敏产物内容(用户要拿原始文件)。
|
||||
disableDesensitize
|
||||
headerLeadingActionBare
|
||||
headerLeadingAction={(
|
||||
<TaskArtifactSubmitButton
|
||||
compact
|
||||
@@ -130,6 +170,7 @@ export function Step2SandboxLayout({
|
||||
target={taskArtifactSubmission?.targetFor({
|
||||
threadId: previewThreadId,
|
||||
path: selectedArtifact,
|
||||
content: selectedArtifactContent,
|
||||
}) ?? { threadId: previewThreadId, path: selectedArtifact }}
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user