mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 19:38:28 +00:00
refactor(runtime): consolidate followup, gateway, and provider dedupe paths
This commit is contained in:
@@ -96,22 +96,26 @@ function hasImageBlocks(content: ReadonlyArray<TextContent | ImageContent>): boo
|
||||
return false;
|
||||
}
|
||||
|
||||
function estimateTextAndImageChars(content: ReadonlyArray<TextContent | ImageContent>): number {
|
||||
let chars = 0;
|
||||
for (const block of content) {
|
||||
if (block.type === "text") {
|
||||
chars += block.text.length;
|
||||
}
|
||||
if (block.type === "image") {
|
||||
chars += IMAGE_CHAR_ESTIMATE;
|
||||
}
|
||||
}
|
||||
return chars;
|
||||
}
|
||||
|
||||
function estimateMessageChars(message: AgentMessage): number {
|
||||
if (message.role === "user") {
|
||||
const content = message.content;
|
||||
if (typeof content === "string") {
|
||||
return content.length;
|
||||
}
|
||||
let chars = 0;
|
||||
for (const b of content) {
|
||||
if (b.type === "text") {
|
||||
chars += b.text.length;
|
||||
}
|
||||
if (b.type === "image") {
|
||||
chars += IMAGE_CHAR_ESTIMATE;
|
||||
}
|
||||
}
|
||||
return chars;
|
||||
return estimateTextAndImageChars(content);
|
||||
}
|
||||
|
||||
if (message.role === "assistant") {
|
||||
@@ -135,16 +139,7 @@ function estimateMessageChars(message: AgentMessage): number {
|
||||
}
|
||||
|
||||
if (message.role === "toolResult") {
|
||||
let chars = 0;
|
||||
for (const b of message.content) {
|
||||
if (b.type === "text") {
|
||||
chars += b.text.length;
|
||||
}
|
||||
if (b.type === "image") {
|
||||
chars += IMAGE_CHAR_ESTIMATE;
|
||||
}
|
||||
}
|
||||
return chars;
|
||||
return estimateTextAndImageChars(message.content);
|
||||
}
|
||||
|
||||
return 256;
|
||||
|
||||
Reference in New Issue
Block a user