mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 08:01:23 +00:00
refactor(shared): reuse chat content extractor for assistant text
This commit is contained in:
@@ -24,6 +24,7 @@ export {
|
||||
resolveSessionReference,
|
||||
shouldResolveSessionIdInput,
|
||||
} from "./sessions-resolution.js";
|
||||
import { extractTextFromChatContent } from "../../shared/chat-content.js";
|
||||
import { sanitizeUserFacingText } from "../pi-embedded-helpers.js";
|
||||
import {
|
||||
stripDowngradedToolCallText,
|
||||
@@ -152,23 +153,12 @@ export function extractAssistantText(message: unknown): string | undefined {
|
||||
if (!Array.isArray(content)) {
|
||||
return undefined;
|
||||
}
|
||||
const chunks: string[] = [];
|
||||
for (const block of content) {
|
||||
if (!block || typeof block !== "object") {
|
||||
continue;
|
||||
}
|
||||
if ((block as { type?: unknown }).type !== "text") {
|
||||
continue;
|
||||
}
|
||||
const text = (block as { text?: unknown }).text;
|
||||
if (typeof text === "string") {
|
||||
const sanitized = sanitizeTextContent(text);
|
||||
if (sanitized.trim()) {
|
||||
chunks.push(sanitized);
|
||||
}
|
||||
}
|
||||
}
|
||||
const joined = chunks.join("").trim();
|
||||
const joined =
|
||||
extractTextFromChatContent(content, {
|
||||
sanitizeText: sanitizeTextContent,
|
||||
joinWith: "",
|
||||
normalizeText: (text) => text.trim(),
|
||||
}) ?? "";
|
||||
const stopReason = (message as { stopReason?: unknown }).stopReason;
|
||||
const errorMessage = (message as { errorMessage?: unknown }).errorMessage;
|
||||
const errorContext =
|
||||
|
||||
Reference in New Issue
Block a user