openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
31 lines (30 loc) • 1.34 kB
JavaScript
import "./src-H3RMXyFL.mjs";
import { t as stableStringify } from "./stable-stringify-vqde_3tT.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), and the spec
* requires structuredContent to be an object, so servers returning an array or scalar wrap it
* under one key ({"items": [...]}, FastMCP's {"result": ...}) while the text carries the bare
* value. A block counts as the mirror when it is complete JSON for structuredContent or for the
* only value of a single-key structuredContent; a plain-text block counts when it equals that
* only value when it is a string. Any other text, including JSON for a different value, is kept
* because it can carry recovery guidance.
*/
function createMcpStructuredContentMirrorMatcher(e) {
const [t, ...n] = Object.keys(e);
const r = t !== void 0 && n.length === 0 ? e[t] : void 0;
let i;
let a;
return (t) => {
if (typeof r === "string" && t === r) return true;
try {
const n = stableStringify(JSON.parse(t));
return n === (i ??= stableStringify(e)) || r !== void 0 && n === (a ??= stableStringify(r));
} catch {
return false;
}
};
}
//#endregion
export { createMcpStructuredContentMirrorMatcher as t };