refactor(agents): share thinking block predicate

This commit is contained in:
Vincent Koc
2026-06-22 13:30:22 +08:00
parent 536c8a840b
commit 692c5e34f0
4 changed files with 10 additions and 24 deletions

View File

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

View File

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

View File

@@ -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";
}

View File

@@ -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<AgentMessage, { role: "toolRes
return ids;
}
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 hasToolCallInput(block: ReplaySafeToolCallBlock): boolean {
const hasInput = "input" in block ? block.input !== undefined && block.input !== null : false;
const hasArguments =