import fs from "node:fs/promises"; import path from "node:path"; import Ajv from "ajv"; import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime"; import { Type } from "typebox"; import {
formatThinkingLevels,
isThinkingLevelSupported,
normalizeThinkLevel,
resolvePreferredOpenClawTmpDir,
} from "../api.js"; import type { OpenClawPluginApi } from "../api.js";
const AjvCtor = Ajv as unknown as typeofimport("ajv").default;
function stripCodeFences(s: string): string { const trimmed = s.trim(); const m = trimmed.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i); if (m) { return (m[1] ?? "").trim();
} return trimmed;
}
const input = params.input;
let inputJson: string; try {
inputJson = JSON.stringify(input ?? null, null, 2);
} catch { thrownew Error("input must be JSON-serializable");
}
const system = [ "You are a JSON-only function.", "Return ONLY a valid JSON value.", "Do not wrap in markdown fences.", "Do not include commentary.", "Do not call tools.",
].join(" ");
const text = collectText( typeof result === "object" && result !== null && "payloads" in result
? (result as { payloads?: Array<{ text?: string; isError?: boolean }> }).payloads
: undefined,
); if (!text) { thrownew Error("LLM returned empty output");
}
const raw = stripCodeFences(text);
let parsed: unknown; try {
parsed = JSON.parse(raw);
} catch { thrownew Error("LLM returned invalid JSON");
}
const schema = params.schema; if (schema && typeof schema === "object" && !Array.isArray(schema)) { const ajv = new AjvCtor({ allErrors: true, strict: false }); const validate = ajv.compile(schema); const ok = validate(parsed); if (!ok) { const msg =
validate.errors
?.map(
(e: { instancePath?: string; message?: string }) =>
`${e.instancePath || "<root>"} ${e.message || "invalid"}`,
)
.join("; ") ?? "invalid"; thrownew Error(`LLM JSON did not match schema: ${msg}`);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.