mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-26 20:35:39 -06:00
fa03d9b913
* refactor: consolidate coercion helpers * fix: remove duplicate coercion imports * fix: preserve serialized coercion guard * chore: ratchet coercion helper carve-outs * fix(test): keep gauntlet subprocess startup lean * fix: preserve imported session timestamp semantics * fix: preserve catalog timestamp string semantics * chore: align plugin SDK surface ratchet * fix: preserve trajectory and SDK string contracts * fix(test): preserve QA record assertion semantics * fix: complete standalone record guard rename * refactor(cron): use canonical string coercion * fix(acpx): preserve Pi timestamp parsing * test(channels): adapt custody test harnesses * test(telegram): classify media harness as test support * test(acpx): split timestamp contract coverage * test(channels): support generated custody contracts * chore: ban the full coercion helper name set Extends the declaration guard to all eleven consolidated helper names and renames the cron schedule-identity readNumber wrapper to readScheduleInteger so the banned generic name cannot regrow. * fix(scripts): repair release-validation guard drift and lint cause Restores the renamed isJsonRecord guard in assertTrustedWorkflowHarness after main added isRecord call sites in parallel, and attaches the caught YAML error as the thrown error cause (preserve-caught-error was red on main). * fix: preserve Claude timestamp string semantics * fix: preserve persisted timestamp string semantics * fix: preserve date-first timestamp contracts * fix(openai): harden delegation failure formatting * chore: close coercion helper guard gaps * test(openai): model non-error delegation rejection * chore: refresh plugin SDK API contract * fix(tasks): use canonical string field reader * fix(ai): use canonical provider error field coercion * fix(browser): migrate native bootstrap coercion * docs(plugin-sdk): clarify text record export compatibility * fix(gateway): normalize approval execution identity * test(outbound): isolate message action poll harness
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
// Memory Core plugin module implements dreaming shared behavior.
|
|
import {
|
|
asNullableRecord,
|
|
normalizeOptionalString,
|
|
} from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
|
|
export { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
|
|
|
export function extractAssistantText(messages: unknown[]): string | null {
|
|
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
const message = asNullableRecord(messages[index]);
|
|
if (message?.role !== "assistant") {
|
|
continue;
|
|
}
|
|
if (typeof message.content === "string" && message.content.trim()) {
|
|
return message.content.trim();
|
|
}
|
|
if (Array.isArray(message.content)) {
|
|
const text = message.content
|
|
.flatMap((part) => {
|
|
const item = asNullableRecord(part);
|
|
return (item?.type === "text" || item?.type === "output_text") &&
|
|
typeof item.text === "string"
|
|
? [item.text]
|
|
: [];
|
|
})
|
|
.join("\n")
|
|
.trim();
|
|
if (text) {
|
|
return text;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function includesSystemEventToken(cleanedBody: string, eventText: string): boolean {
|
|
const normalizedBody = normalizeOptionalString(cleanedBody);
|
|
const normalizedEventText = normalizeOptionalString(eventText);
|
|
if (!normalizedBody || !normalizedEventText) {
|
|
return false;
|
|
}
|
|
if (normalizedBody === normalizedEventText) {
|
|
return true;
|
|
}
|
|
return normalizedBody.split(/\r?\n/).some((line) => {
|
|
const trimmed = line.trim();
|
|
if (trimmed === normalizedEventText) {
|
|
return true;
|
|
}
|
|
// Isolated cron turns wrap the payload with a `[cron:<id>] ...` prefix; strip
|
|
// that one known wrapper before matching so the dream sentinel still triggers
|
|
// without falling back to a broad substring match (which would let any user
|
|
// message embedding the token surface as a dream cron firing).
|
|
return trimmed.replace(/^\[cron:[^\]]+\]\s*/, "") === normalizedEventText;
|
|
});
|
|
}
|