mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 08:21:26 +00:00
refactor(agents): share text block extraction helper
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user