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:
TYY-2005 2026-10-23 11:24:26 +08:00 committed by GitHub
parent 39a06b0368
commit cc013c9680
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 2 deletions

View File

@ -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);

View File

@ -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 = [
{