refactor(agents): share thinking block predicate · openclaw/openclaw@692c5e3
vincentkoc
·
2026-06-22
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@
|
3 | 3 | */ |
4 | 4 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
5 | 5 | import type { AgentMessage } from "../runtime/index.js"; |
| 6 | +import { isThinkingLikeBlock } from "../thinking-block.js"; |
6 | 7 | import { extractToolCallsFromAssistant, extractToolResultId } from "../tool-call-id.js"; |
7 | 8 | |
8 | 9 | type AnthropicContentBlock = { |
@@ -22,14 +23,6 @@ function isToolCallBlock(block: AnthropicContentBlock): boolean {
|
22 | 23 | return block.type === "toolUse" || block.type === "toolCall" || block.type === "functionCall"; |
23 | 24 | } |
24 | 25 | |
25 | | -function isThinkingLikeBlock(block: unknown): boolean { |
26 | | -if (!block || typeof block !== "object") { |
27 | | -return false; |
28 | | -} |
29 | | -const type = (block as { type?: unknown }).type; |
30 | | -return type === "thinking" || type === "redacted_thinking"; |
31 | | -} |
32 | | - |
33 | 26 | function isAbortedAssistantTurn(message: AgentMessage): boolean { |
34 | 27 | const stopReason = (message as { stopReason?: unknown }).stopReason; |
35 | 28 | return stopReason === "aborted" || stopReason === "error"; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,7 @@ import {
|
10 | 10 | readStringValue, |
11 | 11 | } from "@openclaw/normalization-core/string-coerce"; |
12 | 12 | import type { AgentMessage } from "./runtime/index.js"; |
| 13 | +import { isThinkingLikeBlock } from "./thinking-block.js"; |
13 | 14 | import { |
14 | 15 | extractToolCallsFromAssistant, |
15 | 16 | extractToolResultId, |
@@ -40,14 +41,6 @@ const RAW_TOOL_CALL_BLOCK_TYPES = new Set([
|
40 | 41 | "function_call", |
41 | 42 | ]); |
42 | 43 | |
43 | | -function isThinkingLikeBlock(block: unknown): boolean { |
44 | | -if (!block || typeof block !== "object") { |
45 | | -return false; |
46 | | -} |
47 | | -const type = (block as { type?: unknown }).type; |
48 | | -return type === "thinking" || type === "redacted_thinking"; |
49 | | -} |
50 | | - |
51 | 44 | function isRawToolCallBlock(block: unknown): block is RawToolCallBlock { |
52 | 45 | if (!block || typeof block !== "object") { |
53 | 46 | return false; |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +export function isThinkingLikeBlock(block: unknown): boolean { |
| 2 | +if (!block || typeof block !== "object") { |
| 3 | +return false; |
| 4 | +} |
| 5 | +const type = (block as { type?: unknown }).type; |
| 6 | +return type === "thinking" || type === "redacted_thinking"; |
| 7 | +} |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,7 @@
|
5 | 5 | */ |
6 | 6 | import { createHash } from "node:crypto"; |
7 | 7 | import type { AgentMessage } from "./runtime/index.js"; |
| 8 | +import { isThinkingLikeBlock } from "./thinking-block.js"; |
8 | 9 | import { isAllowedToolCallName, normalizeAllowedToolNames } from "./tool-call-shared.js"; |
9 | 10 | |
10 | 11 | export type ToolCallIdMode = "strict" | "strict9"; |
@@ -124,14 +125,6 @@ export function extractToolResultIds(msg: Extract<AgentMessage, { role: "toolRes
|
124 | 125 | return ids; |
125 | 126 | } |
126 | 127 | |
127 | | -function isThinkingLikeBlock(block: unknown): boolean { |
128 | | -if (!block || typeof block !== "object") { |
129 | | -return false; |
130 | | -} |
131 | | -const type = (block as { type?: unknown }).type; |
132 | | -return type === "thinking" || type === "redacted_thinking"; |
133 | | -} |
134 | | - |
135 | 128 | function hasToolCallInput(block: ReplaySafeToolCallBlock): boolean { |
136 | 129 | const hasInput = "input" in block ? block.input !== undefined && block.input !== null : false; |
137 | 130 | const hasArguments = |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。