mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-10-26 13:16:24 +00:00
fix(frontend): classify thinking-only token steps correctly (#7175)
* fix(frontend): classify thinking-only token steps correctly * docs(frontend): explain thinking-only token step classification --------- Co-authored-by: TYY-2005 <334029581+TYY-2005@users.noreply.github.com> Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
This commit is contained in:
parent
39a06b0368
commit
cc013c9680
@ -3,7 +3,7 @@ import type { Message } from "@langchain/langgraph-sdk";
|
||||
import type { Translations } from "@/core/i18n/locales/types";
|
||||
|
||||
import { getUsageMetadata, type TokenUsage } from "./usage";
|
||||
import { hasContent } from "./utils";
|
||||
import { extractContentFromMessage } from "./utils";
|
||||
|
||||
export type TokenUsageInlineMode = "off" | "per_turn" | "step_debug";
|
||||
|
||||
@ -166,7 +166,8 @@ export function buildTokenDebugSteps(
|
||||
}
|
||||
|
||||
if (actionLabels.length === 0) {
|
||||
if (hasContent(message)) {
|
||||
// Thinking-only blocks (Anthropic) carry no visible answer content.
|
||||
if (extractContentFromMessage(message).length > 0) {
|
||||
actionLabels.push(t.tokenUsage.finalAnswer);
|
||||
} else {
|
||||
actionLabels.push(t.common.thinking);
|
||||
|
||||
@ -127,6 +127,29 @@ test("uses generic todo labels when backend attribution is absent", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
test("labels Anthropic thinking-only blocks as thinking", () => {
|
||||
const messages = [
|
||||
{
|
||||
id: "ai-thinking",
|
||||
type: "ai",
|
||||
content: [{ type: "thinking", thinking: "Still checking." }],
|
||||
usage_metadata: {
|
||||
input_tokens: 20,
|
||||
output_tokens: 5,
|
||||
total_tokens: 25,
|
||||
},
|
||||
},
|
||||
] as unknown as Message[];
|
||||
|
||||
expect(buildTokenDebugSteps(messages, enUS)).toEqual([
|
||||
expect.objectContaining({
|
||||
messageId: "ai-thinking",
|
||||
label: "Thinking",
|
||||
sharedAttribution: false,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
test("marks multi-action AI steps as shared attribution", () => {
|
||||
const messages = [
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user