openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
26 lines (25 loc) • 1.01 kB
JavaScript
import "./src-BirUqOZp.mjs";
import { t as stableStringify } from "./stable-stringify-Djn3uxNo.mjs";
//#region src/agents/mcp-structured-mirror.ts
/**
* Builds a predicate for text blocks that only mirror an MCP result's structuredContent.
* Servers serialize that mirror differently (pretty, compact, other key order), so a block
* counts as the mirror when it is complete JSON for the same value. Any other text, including
* JSON for a different value, is kept because it can carry recovery guidance.
*/
function createMcpStructuredContentMirrorMatcher(structuredContent) {
let pretty;
let canonical;
return (text) => {
if (text === (pretty ??= JSON.stringify(structuredContent, null, 2))) return true;
if (!text.trimStart().startsWith("{")) return false;
try {
const parsed = JSON.parse(text);
return stableStringify(parsed) === (canonical ??= stableStringify(structuredContent));
} catch {
return false;
}
};
}
//#endregion
export { createMcpStructuredContentMirrorMatcher as t };