mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 17:51:22 +00:00
refactor: dedupe reader helpers
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import { readStringValue } from "./string-coerce.js";
|
||||
|
||||
export function extractFirstTextBlock(message: unknown): string | undefined {
|
||||
if (!message || typeof message !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
const content = (message as { content?: unknown }).content;
|
||||
if (typeof content === "string") {
|
||||
return content;
|
||||
const inline = readStringValue(content);
|
||||
if (inline !== undefined) {
|
||||
return inline;
|
||||
}
|
||||
if (!Array.isArray(content) || content.length === 0) {
|
||||
return undefined;
|
||||
@@ -13,8 +16,7 @@ export function extractFirstTextBlock(message: unknown): string | undefined {
|
||||
if (!first || typeof first !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
const text = (first as { text?: unknown }).text;
|
||||
return typeof text === "string" ? text : undefined;
|
||||
return readStringValue((first as { text?: unknown }).text);
|
||||
}
|
||||
|
||||
export type AssistantPhase = "commentary" | "final_answer";
|
||||
|
||||
@@ -15,6 +15,18 @@ export function normalizeTrimmedStringList(value: unknown): string[] {
|
||||
);
|
||||
}
|
||||
|
||||
export function normalizeOptionalTrimmedStringList(value: unknown): string[] | undefined {
|
||||
const normalized = normalizeTrimmedStringList(value);
|
||||
return normalized.length > 0 ? normalized : undefined;
|
||||
}
|
||||
|
||||
export function normalizeArrayBackedTrimmedStringList(value: unknown): string[] | undefined {
|
||||
if (!Array.isArray(value)) {
|
||||
return undefined;
|
||||
}
|
||||
return normalizeTrimmedStringList(value);
|
||||
}
|
||||
|
||||
export function normalizeSingleOrTrimmedStringList(value: unknown): string[] {
|
||||
if (Array.isArray(value)) {
|
||||
return normalizeTrimmedStringList(value);
|
||||
|
||||
Reference in New Issue
Block a user