mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-06-10 17:35:57 +00:00
fix(frontend): avoid render-time subtask context mutation
This commit is contained in:
committed by
GitHub
parent
9593214065
commit
150d03f2e7
@@ -0,0 +1,47 @@
|
||||
import type { Message } from "@langchain/langgraph-sdk";
|
||||
|
||||
import { extractTextFromMessage } from "@/core/messages/utils";
|
||||
|
||||
import { parseSubtaskResult } from "./subtask-result";
|
||||
import type { Subtask } from "./types";
|
||||
|
||||
export function buildSubtaskMapFromMessages(
|
||||
messages: Message[],
|
||||
): Record<string, Subtask> {
|
||||
const tasks: Record<string, Subtask> = {};
|
||||
|
||||
for (const message of messages) {
|
||||
if (message.type === "ai") {
|
||||
for (const toolCall of message.tool_calls ?? []) {
|
||||
if (toolCall.name !== "task" || !toolCall.id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tasks[toolCall.id] = {
|
||||
id: toolCall.id,
|
||||
status: "in_progress",
|
||||
subagent_type: String(toolCall.args?.subagent_type ?? ""),
|
||||
description: String(toolCall.args?.description ?? ""),
|
||||
prompt: String(toolCall.args?.prompt ?? ""),
|
||||
};
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (message.type !== "tool" || !message.tool_call_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const task = tasks[message.tool_call_id];
|
||||
if (!task) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tasks[message.tool_call_id] = {
|
||||
...task,
|
||||
...parseSubtaskResult(extractTextFromMessage(message)),
|
||||
};
|
||||
}
|
||||
|
||||
return tasks;
|
||||
}
|
||||
Reference in New Issue
Block a user