diff --git a/src/agents/embedded-agent-helpers/turns.ts b/src/agents/embedded-agent-helpers/turns.ts index 5dcad183617..f74f455d505 100644 --- a/src/agents/embedded-agent-helpers/turns.ts +++ b/src/agents/embedded-agent-helpers/turns.ts @@ -3,6 +3,7 @@ */ import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; import type { AgentMessage } from "../runtime/index.js"; +import { isThinkingLikeBlock } from "../thinking-block.js"; import { extractToolCallsFromAssistant, extractToolResultId } from "../tool-call-id.js"; type AnthropicContentBlock = { @@ -22,14 +23,6 @@ function isToolCallBlock(block: AnthropicContentBlock): boolean { return block.type === "toolUse" || block.type === "toolCall" || block.type === "functionCall"; } -function isThinkingLikeBlock(block: unknown): boolean { - if (!block || typeof block !== "object") { - return false; - } - const type = (block as { type?: unknown }).type; - return type === "thinking" || type === "redacted_thinking"; -} - function isAbortedAssistantTurn(message: AgentMessage): boolean { const stopReason = (message as { stopReason?: unknown }).stopReason; return stopReason === "aborted" || stopReason === "error"; diff --git a/src/agents/session-transcript-repair.ts b/src/agents/session-transcript-repair.ts index 5a66bb815d9..5243bdccbea 100644 --- a/src/agents/session-transcript-repair.ts +++ b/src/agents/session-transcript-repair.ts @@ -10,6 +10,7 @@ import { readStringValue, } from "@openclaw/normalization-core/string-coerce"; import type { AgentMessage } from "./runtime/index.js"; +import { isThinkingLikeBlock } from "./thinking-block.js"; import { extractToolCallsFromAssistant, extractToolResultId, @@ -40,14 +41,6 @@ const RAW_TOOL_CALL_BLOCK_TYPES = new Set([ "function_call", ]); -function isThinkingLikeBlock(block: unknown): boolean { - if (!block || typeof block !== "object") { - return false; - } - const type = (block as { type?: unknown }).type; - return type === "thinking" || type === "redacted_thinking"; -} - function isRawToolCallBlock(block: unknown): block is RawToolCallBlock { if (!block || typeof block !== "object") { return false; diff --git a/src/agents/thinking-block.ts b/src/agents/thinking-block.ts new file mode 100644 index 00000000000..9480b93ff17 --- /dev/null +++ b/src/agents/thinking-block.ts @@ -0,0 +1,7 @@ +export function isThinkingLikeBlock(block: unknown): boolean { + if (!block || typeof block !== "object") { + return false; + } + const type = (block as { type?: unknown }).type; + return type === "thinking" || type === "redacted_thinking"; +} diff --git a/src/agents/tool-call-id.ts b/src/agents/tool-call-id.ts index 7362fa13606..2e58338080f 100644 --- a/src/agents/tool-call-id.ts +++ b/src/agents/tool-call-id.ts @@ -5,6 +5,7 @@ */ import { createHash } from "node:crypto"; import type { AgentMessage } from "./runtime/index.js"; +import { isThinkingLikeBlock } from "./thinking-block.js"; import { isAllowedToolCallName, normalizeAllowedToolNames } from "./tool-call-shared.js"; export type ToolCallIdMode = "strict" | "strict9"; @@ -124,14 +125,6 @@ export function extractToolResultIds(msg: Extract