mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-25 14:29:32 +00:00
refactor(agents): share thinking block predicate
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
|
||||
7
src/agents/thinking-block.ts
Normal file
7
src/agents/thinking-block.ts
Normal 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";
|
||||
}
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user