refactor(runtime): consolidate followup, gateway, and provider dedupe paths

This commit is contained in:
Peter Steinberger
2026-02-22 14:06:03 +00:00
parent 38752338dc
commit d116bcfb14
36 changed files with 848 additions and 908 deletions

View File

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