refactor(agents): share text block extraction helper

This commit is contained in:
Peter Steinberger
2026-02-18 18:01:09 +00:00
parent 2d55cc446a
commit 85ebdf88b0
5 changed files with 42 additions and 41 deletions

View File

@@ -2,6 +2,7 @@ import { getChannelPlugin, normalizeChannelId } from "../channels/plugins/index.
import { normalizeTargetForProvider } from "../infra/outbound/target-normalization.js";
import { MEDIA_TOKEN_RE } from "../media/parse.js";
import { truncateUtf16Safe } from "../utils.js";
import { collectTextContentBlocks } from "./content-blocks.js";
import { type MessagingToolSend } from "./pi-embedded-messaging.js";
const TOOL_RESULT_MAX_CHARS = 8000;
@@ -96,20 +97,9 @@ export function extractToolResultText(result: unknown): string | undefined {
return undefined;
}
const record = result as Record<string, unknown>;
const content = Array.isArray(record.content) ? record.content : null;
if (!content) {
return undefined;
}
const texts = content
const texts = collectTextContentBlocks(record.content)
.map((item) => {
if (!item || typeof item !== "object") {
return undefined;
}
const entry = item as Record<string, unknown>;
if (entry.type !== "text" || typeof entry.text !== "string") {
return undefined;
}
const trimmed = entry.text.trim();
const trimmed = item.trim();
return trimmed ? trimmed : undefined;
})
.filter((value): value is string => Boolean(value));