mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 13:41:17 -05:00
4126698407
* test(mcp): check advertised schemas against a portable dialect in every profile * fix(mcp): re-emit advertised patterns in a portable regex grammar * fix(mcp): present discover_tools input through the selected profile The hot-cold catalog registered discover_tools directly with the SDK, so the default compact input profile still advertised its canonical schema, including page-size defaults clients apply on their own (#5322). Route every listed input schema, transport discovery included, through one server-owned presentation, and pass the selected presentation to the deferred server, which serves recorded tool schemas but not discovery. * fix(mcp): keep the Evidence union on described borrowed inputs borrowEvidenceInput installed its advertised projection on one schema instance. A call site's .describe() rebuilds the schema from its definition, so match_native_functions advertised left and right as unconstrained values in every input profile. Install the projection in the borrowed parser's constructor so derived schemas keep it, for both borrowed inputs and borrowed arrays. * fix(mcp): validate advertised dialect by selected profile * fix(mcp): preserve schema widening through references * feat(mcp): project compact input schemas into the portable advertised dialect One projection (advertisedDialectProjection.ts) owns the compact input advertisement: one type per node, items on every array, string literals as enums, oneOf widened to anyOf, allOf merged, tuples as element unions, exclusive bounds made inclusive, and every keyword outside the dialect dropped. Each rewrite is exact or widening; server validation is unchanged. The root description and sentences for dropped cross-field constraints move to the tool description, which Codex and Zed keep. The compact baseline falls to nullable values only (29), which the dialect cannot express without narrowing an input. The gateway shape repairs (typeArrayItemUnions, hasGatewayIncompatibleShape), the second dependentRequired-to-prose copy and the strict-gateway test denylist are removed; the dialect checker gates the inline presentation instead. * fix(mcp): refuse zero-padded repeat bounds and record host-specific path patterns * fix(mcp): keep projected schemas permissive * fix(mcp): keep references valid when presentation widens their targets * fix(mcp): keep a single union branch's closure scoped to its properties * fix(mcp): keep an allOf member's tuple tail with its own positions * fix(mcp): relax references into negations and conditionals presentation may remove * test(mcp): select the borrowed Evidence contract from its family * fix(mcp): keep astral literals and dynamic references widening in every mode * fix(mcp): omit astral literals and relax untracked references when presentation widens * fix(mcp): read reference pointers by schema position, not segment spelling * fix(mcp): protect references into collapsing boolean unions and keep referencing branches out of the collapse * fix(mcp): keep reduced schemas open when their root admits names by pattern * test(mcp): keep the reduced-schema pattern case outside the size-limited block * fix(mcp): omit patterns whose classes name astral characters * fix(mcp): decide union collapse and pointer protection from canonical branches * docs(mcp): document non-u astral matching and pin BMP agreement across V8 modes * fix(mcp): keep prototype-named properties as own properties in the dialect projection * test(mcp): expect the advertised base64 schema to omit the unbounded pad-bit probe * fix(mcp): protect references into unevaluated keywords lost evaluation removes * fix(mcp): emit stack-safe classes with non-ASCII members and protect draft-07 reference siblings * fix(mcp): protect references into literal siblings of relaxed draft-07 references * feat(mcp): omit output schemas from tools/list by default (#10646) * feat(mcp): omit output schemas from tools/list by default No surveyed model API reads an output schema, MCP client validators repeat REA's own result validation, and complete output schemas were about 92% of the default tools/list. REA_MCP_OUTPUT_SCHEMA_PROFILE now resolves to off through one owner (resolveMcpOutputSchemaProfile); compact and full remain selectable. structuredContent is still delivered, and the deferred server serves both off and full from the recorded catalog with the matching recorded identity. Tests and artifact verifiers that validate results against complete advertised output contracts select full explicitly. * fix(mcp): select schemas in verification workflows * fix(mcp): select complete output schemas in the Electron verifier * fix(mcp): select complete output schemas in standalone verifier probes * fix(mcp): select complete output schemas in every verifier transport * test(mcp): select full output schemas in packet and signal schema checks * fix(mcp): validate the doctor probe reply against the canonical output contract (#10655) * fix(mcp): validate the doctor probe reply against the canonical output contract * test(mcp): replay doctor probe validation under every output profile * test(mcp): accept typed-branch nullable unions in the advertised dialect (#10649) * test(mcp): select full output schemas in HTTP session workflows * fix(mcp): keep the Evidence union on described borrowed inputs (#10597) * fix(mcp): keep the Evidence union on described borrowed inputs borrowEvidenceInput installed its advertised projection on one schema instance. A call site's .describe() rebuilds the schema from its definition, so match_native_functions advertised left and right as unconstrained values in every input profile. Install the projection in the borrowed parser's constructor so derived schemas keep it, for both borrowed inputs and borrowed arrays. * test(mcp): select the borrowed Evidence contract from its family * docs(mcp): admit baseline growth only for restored contract declarations * fix(mcp): state reduced multi-type properties as typed branches, not type lists The reduced fallback derived a property's types and emitted them as a type list, which Gemini, Moonshot and Ark reject. A property whose canonical schema is anyOf string and number therefore traded a typed union for a rejected construct when the inline projection fell back. Emit one type, or anyOf typed branches, so [T, null] becomes the dialect's nullable union.
525 lines
17 KiB
TypeScript
525 lines
17 KiB
TypeScript
import {
|
|
JsonSchemaReferences,
|
|
type JsonSchemaScope,
|
|
} from "./jsonSchemaReferences.js";
|
|
import {
|
|
schemaArrays,
|
|
schemaChildren,
|
|
schemaMaps,
|
|
schemaLiteralValues,
|
|
} from "./jsonSchemaKeywords.js";
|
|
|
|
// Shared compact JSON Schema projection primitives; canonical validation stays separate.
|
|
|
|
/** Annotation keys that carry guidance but no validation semantics. */
|
|
const annotationKeys = new Set(["description", "examples", "default", "title"]);
|
|
|
|
const definitionKeys = new Set(["$defs", "definitions"]);
|
|
// An empty schema accepts every JSON value. Kimi otherwise infers string.
|
|
const jsonValueTypes = [
|
|
"null",
|
|
"boolean",
|
|
"object",
|
|
"array",
|
|
"number",
|
|
"string",
|
|
];
|
|
// An empty item schema accepts every JSON value, including arbitrarily nested
|
|
// arrays, while satisfying clients that require `items` for array types. The
|
|
// portable advertised dialect has no any-value form, so a compact input that
|
|
// needs this presentation is reduced instead.
|
|
export const jsonValueSchema = () => ({ type: [...jsonValueTypes], items: {} });
|
|
|
|
const enumValueTypes = (values: readonly unknown[]): readonly string[] => [
|
|
...new Set(
|
|
values.map((value) => {
|
|
if (value === null) return "null";
|
|
if (Array.isArray(value)) return "array";
|
|
if (typeof value === "object") return "object";
|
|
return typeof value;
|
|
}),
|
|
),
|
|
];
|
|
|
|
export const isSchemaObject = (
|
|
value: unknown,
|
|
): value is Record<string, unknown> =>
|
|
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
|
|
export const serializedBytes = (value: unknown): number =>
|
|
Buffer.byteLength(JSON.stringify(value), "utf8");
|
|
|
|
export const schemaDepth = (value: unknown, depth = 0): number => {
|
|
if (Array.isArray(value))
|
|
return Math.max(
|
|
depth,
|
|
...value.map((child) => schemaDepth(child, depth + 1)),
|
|
);
|
|
if (!isSchemaObject(value)) return depth;
|
|
return Math.max(
|
|
depth,
|
|
...Object.values(value).map((child) => schemaDepth(child, depth + 1)),
|
|
);
|
|
};
|
|
|
|
/** Strict clients commonly reject advertised schemas deeper than ten nodes. */
|
|
export const COMPACT_SCHEMA_MAX_DEPTH = 10;
|
|
|
|
/** Rewrite every schema-valued position; literal data stays opaque. */
|
|
const rebuildSchemaPositions = (
|
|
node: unknown,
|
|
rebuild: (child: unknown) => unknown,
|
|
): unknown => {
|
|
if (Array.isArray(node)) return node.map((child) => rebuild(child));
|
|
if (!isSchemaObject(node)) return node;
|
|
const out: Record<string, unknown> = {};
|
|
for (const [key, value] of Object.entries(node)) {
|
|
if (schemaLiteralValues.has(key)) {
|
|
out[key] = value;
|
|
continue;
|
|
}
|
|
if (schemaMaps.has(key) && isSchemaObject(value)) {
|
|
out[key] = Object.fromEntries(
|
|
Object.entries(value).map(([name, child]) => [name, rebuild(child)]),
|
|
);
|
|
continue;
|
|
}
|
|
if (schemaArrays.has(key) && Array.isArray(value)) {
|
|
out[key] = value.map((child) => rebuild(child));
|
|
continue;
|
|
}
|
|
if (schemaChildren.has(key)) {
|
|
out[key] = Array.isArray(value)
|
|
? value.map((child) => rebuild(child))
|
|
: rebuild(value);
|
|
continue;
|
|
}
|
|
out[key] = value;
|
|
}
|
|
return out;
|
|
};
|
|
|
|
/**
|
|
* Drop annotation prose from every subschema while preserving all validation
|
|
* keywords. The root keeps its own description because the root-union
|
|
* projection encodes accepted input groups there; the root's echoed literal
|
|
* examples leave with the rest of the annotation prose.
|
|
*/
|
|
export const stripAnnotations = (
|
|
schema: Record<string, unknown>,
|
|
): Record<string, unknown> => {
|
|
const rebuilt = rebuildSchemaPositions(
|
|
schema,
|
|
stripChildAnnotations,
|
|
) as Record<string, unknown>;
|
|
const out: Record<string, unknown> = {};
|
|
for (const [key, value] of Object.entries(rebuilt)) {
|
|
if (annotationKeys.has(key) && key !== "description") continue;
|
|
out[key] = value;
|
|
}
|
|
return out;
|
|
};
|
|
|
|
const stripChildAnnotations = (child: unknown): unknown => {
|
|
const rebuilt = rebuildSchemaPositions(child, stripChildAnnotations);
|
|
if (!isSchemaObject(rebuilt)) return rebuilt;
|
|
const kept: Record<string, unknown> = {};
|
|
for (const [key, value] of Object.entries(rebuilt))
|
|
if (!annotationKeys.has(key)) kept[key] = value;
|
|
return kept;
|
|
};
|
|
|
|
/** Stop serialization at the budget before allocating an expanded schema. */
|
|
export const inlineWithinBudget = (
|
|
root: Record<string, unknown>,
|
|
budgetBytes: number,
|
|
): Record<string, unknown> | undefined => {
|
|
const references = new JsonSchemaReferences(root);
|
|
const identity = Object.fromEntries(
|
|
["$id", "$anchor", "$schema"].flatMap((key) =>
|
|
Object.hasOwn(root, key) ? [[key, root[key]]] : [],
|
|
),
|
|
);
|
|
const identityBytes =
|
|
Object.keys(identity).length === 0 ? 0 : serializedBytes(identity) - 2;
|
|
if (identityBytes > budgetBytes) return undefined;
|
|
let resolved = true;
|
|
function* serialize(
|
|
value: unknown,
|
|
position: "schema" | "map" | "data",
|
|
scope: JsonSchemaScope | undefined,
|
|
active: ReadonlyMap<JsonSchemaScope, ReadonlySet<string>>,
|
|
): Generator<string> {
|
|
if (Array.isArray(value)) {
|
|
yield "[";
|
|
for (const [index, child] of value.entries()) {
|
|
if (index > 0) yield ",";
|
|
yield* serialize(child, position, scope, active);
|
|
}
|
|
yield "]";
|
|
} else if (isSchemaObject(value)) {
|
|
const currentScope =
|
|
position === "schema" ? references.enter(value, scope) : scope;
|
|
if (
|
|
position === "schema" &&
|
|
(currentScope === undefined ||
|
|
currentScope.dialect !== references.rootScope.dialect ||
|
|
[
|
|
"$dynamicRef",
|
|
"$recursiveRef",
|
|
"$dynamicAnchor",
|
|
"$recursiveAnchor",
|
|
].some((key) => Object.hasOwn(value, key)))
|
|
) {
|
|
resolved = false;
|
|
return;
|
|
}
|
|
if (position === "schema" && Object.keys(value).length === 0) {
|
|
yield JSON.stringify(jsonValueSchema());
|
|
return;
|
|
}
|
|
if (position === "schema" && typeof value.$ref === "string") {
|
|
const target = references.resolve(currentScope, value.$ref);
|
|
if (
|
|
target.kind !== "target" ||
|
|
currentScope === undefined ||
|
|
active.get(currentScope)?.has(value.$ref)
|
|
) {
|
|
resolved = false;
|
|
return;
|
|
}
|
|
const {
|
|
$ref,
|
|
$id: _id,
|
|
$anchor: _anchor,
|
|
$schema: _schema,
|
|
...siblings
|
|
} = value;
|
|
const nextActive = new Map(active);
|
|
nextActive.set(
|
|
currentScope,
|
|
new Set([...(active.get(currentScope) ?? []), $ref]),
|
|
);
|
|
// Draft 7 ignores siblings, while clients such as Ajv also apply them.
|
|
// Do not label either interpretation an equivalent inline advertisement.
|
|
if (
|
|
currentScope.dialect === "draft-07" &&
|
|
Object.keys(siblings).length > 0
|
|
) {
|
|
resolved = false;
|
|
return;
|
|
}
|
|
const expanded =
|
|
Object.keys(siblings).length === 0
|
|
? target.value
|
|
: { allOf: [target.value, siblings] };
|
|
yield* serialize(expanded, "schema", currentScope, nextActive);
|
|
return;
|
|
}
|
|
yield "{";
|
|
let first = true;
|
|
for (const [key, child] of Object.entries(value)) {
|
|
if (
|
|
position === "schema" &&
|
|
(definitionKeys.has(key) ||
|
|
key === "$id" ||
|
|
key === "$anchor" ||
|
|
key === "$schema")
|
|
)
|
|
continue;
|
|
if (!first) yield ",";
|
|
first = false;
|
|
yield JSON.stringify(key) + ":";
|
|
// `not: {}` forbids a value; no client infers a type for a value it
|
|
// must omit, and the any-value list would place `items` beside a
|
|
// non-array type, which Gemini function declarations reject.
|
|
if (
|
|
position === "schema" &&
|
|
key === "not" &&
|
|
isSchemaObject(child) &&
|
|
Object.keys(child).length === 0
|
|
) {
|
|
yield "{}";
|
|
continue;
|
|
}
|
|
const childPosition =
|
|
position === "map"
|
|
? "schema"
|
|
: position === "schema" && schemaMaps.has(key)
|
|
? "map"
|
|
: position === "schema" &&
|
|
(schemaArrays.has(key) || schemaChildren.has(key))
|
|
? "schema"
|
|
: "data";
|
|
yield* serialize(child, childPosition, currentScope, active);
|
|
}
|
|
yield "}";
|
|
} else {
|
|
yield JSON.stringify(value);
|
|
}
|
|
}
|
|
const chunks: string[] = [];
|
|
let bytes = identityBytes;
|
|
for (const chunk of serialize(
|
|
root,
|
|
"schema",
|
|
references.rootScope,
|
|
new Map(),
|
|
)) {
|
|
bytes += Buffer.byteLength(chunk, "utf8");
|
|
if (bytes > budgetBytes || !resolved) return undefined;
|
|
chunks.push(chunk);
|
|
}
|
|
if (!resolved) return undefined;
|
|
const expanded: unknown = JSON.parse(chunks.join(""));
|
|
if (!isSchemaObject(expanded)) return undefined;
|
|
// Every emitted dependency is now static and reference-free. Nested resource
|
|
// identifiers/anchors can leave without duplicating identities at call sites.
|
|
const schema = { ...identity, ...expanded };
|
|
return serializedBytes(schema) <= budgetBytes ? schema : undefined;
|
|
};
|
|
|
|
/** Preserve every possible type, including referenced and nullable unions. */
|
|
const detectedTypes = (
|
|
schema: unknown,
|
|
references: JsonSchemaReferences,
|
|
inherited: JsonSchemaScope | undefined,
|
|
active: ReadonlySet<object> = new Set(),
|
|
): readonly string[] | undefined => {
|
|
if (!isSchemaObject(schema)) return undefined;
|
|
const scope = references.enter(schema, inherited);
|
|
if (scope === undefined) return undefined;
|
|
if (typeof schema.$ref === "string") {
|
|
if (active.has(schema)) return undefined;
|
|
const target = references.resolve(scope, schema.$ref);
|
|
return target.kind === "target"
|
|
? detectedTypes(
|
|
target.value,
|
|
references,
|
|
scope,
|
|
new Set([...active, schema]),
|
|
)
|
|
: undefined;
|
|
}
|
|
if (typeof schema.type === "string") return [schema.type];
|
|
if (
|
|
Array.isArray(schema.type) &&
|
|
schema.type.every((type) => typeof type === "string")
|
|
)
|
|
return schema.type;
|
|
if (Array.isArray(schema.enum) && schema.enum.length > 0) {
|
|
const enumTypes = enumValueTypes(schema.enum);
|
|
if (enumTypes.every((type) => jsonValueTypes.includes(type)))
|
|
return enumTypes;
|
|
}
|
|
const alternatives = Array.isArray(schema.anyOf)
|
|
? schema.anyOf
|
|
: Array.isArray(schema.oneOf)
|
|
? schema.oneOf
|
|
: [];
|
|
if (alternatives.length === 0) return undefined;
|
|
const types = alternatives.map((branch) =>
|
|
detectedTypes(branch, references, scope, active),
|
|
);
|
|
if (types.some((type) => type === undefined)) return undefined;
|
|
return [...new Set(types.flatMap((type) => type ?? []))];
|
|
};
|
|
|
|
interface ScopedSchema {
|
|
readonly schema: Record<string, unknown>;
|
|
readonly scope: JsonSchemaScope;
|
|
}
|
|
|
|
/**
|
|
* Collect the item schema of every array alternative. Tuples, boolean item
|
|
* schemas and unresolved references are unknown because one item type would
|
|
* not describe every accepted element.
|
|
*/
|
|
const arrayItemAlternatives = (
|
|
schema: unknown,
|
|
references: JsonSchemaReferences,
|
|
inherited: JsonSchemaScope | undefined,
|
|
active: ReadonlySet<object> = new Set(),
|
|
): readonly ScopedSchema[] | undefined => {
|
|
if (!isSchemaObject(schema)) return undefined;
|
|
const scope = references.enter(schema, inherited);
|
|
if (scope === undefined) return undefined;
|
|
if (typeof schema.$ref === "string") {
|
|
if (active.has(schema)) return undefined;
|
|
const target = references.resolve(scope, schema.$ref);
|
|
return target.kind === "target"
|
|
? arrayItemAlternatives(
|
|
target.value,
|
|
references,
|
|
scope,
|
|
new Set([...active, schema]),
|
|
)
|
|
: undefined;
|
|
}
|
|
const types =
|
|
typeof schema.type === "string"
|
|
? [schema.type]
|
|
: Array.isArray(schema.type)
|
|
? schema.type
|
|
: undefined;
|
|
if (types !== undefined) {
|
|
if (!types.includes("array")) return [];
|
|
return isSchemaObject(schema.items) && schema.prefixItems === undefined
|
|
? [{ schema: schema.items, scope }]
|
|
: undefined;
|
|
}
|
|
const alternatives = Array.isArray(schema.anyOf)
|
|
? schema.anyOf
|
|
: Array.isArray(schema.oneOf)
|
|
? schema.oneOf
|
|
: [];
|
|
if (alternatives.length === 0) return undefined;
|
|
const nested = alternatives.map((branch) =>
|
|
arrayItemAlternatives(branch, references, scope, active),
|
|
);
|
|
return nested.some((items) => items === undefined)
|
|
? undefined
|
|
: nested.flatMap((items) => items ?? []);
|
|
};
|
|
|
|
/** Nested arrays beyond this level advertise an unconstrained item schema. */
|
|
const REDUCED_ITEM_MAX_DEPTH = 3;
|
|
|
|
/**
|
|
* Advertise the element types the canonical item schemas accept. Gemini
|
|
* function declarations permit `items` only beside the single `array` type,
|
|
* so an element that may be an array alongside other types, or whose type is
|
|
* unknown, uses the empty schema: it accepts every element and still gives
|
|
* clients that require `items` an item schema.
|
|
*/
|
|
/**
|
|
* One `type`, or `anyOf` typed branches for several. Gemini, Moonshot and Ark
|
|
* reject type lists (#7103, #3800); `[T, "null"]` becomes the dialect's
|
|
* nullable union, and other unions keep the typed branches every surveyed
|
|
* target accepts below the root.
|
|
*/
|
|
const typedAlternatives = (
|
|
types: readonly string[],
|
|
): Record<string, unknown> =>
|
|
types.length === 1
|
|
? { type: types[0] }
|
|
: { anyOf: types.map((type) => ({ type })) };
|
|
|
|
const reducedItemSchema = (
|
|
alternatives: readonly ScopedSchema[] | undefined,
|
|
references: JsonSchemaReferences,
|
|
depth = 1,
|
|
): Record<string, unknown> => {
|
|
if (
|
|
alternatives === undefined ||
|
|
alternatives.length === 0 ||
|
|
depth > REDUCED_ITEM_MAX_DEPTH
|
|
)
|
|
return {};
|
|
const types: string[] = [];
|
|
for (const { schema, scope } of alternatives) {
|
|
const detected = detectedTypes(schema, references, scope);
|
|
if (detected === undefined || detected.length === 0) return {};
|
|
types.push(...detected);
|
|
}
|
|
const unique = [...new Set(types)];
|
|
if (!unique.includes("array")) return typedAlternatives(unique);
|
|
if (unique.length > 1) return {};
|
|
const nested: ScopedSchema[] = [];
|
|
for (const { schema, scope } of alternatives) {
|
|
const items = arrayItemAlternatives(schema, references, scope);
|
|
if (items === undefined) return { type: "array", items: {} };
|
|
nested.push(...items);
|
|
}
|
|
return {
|
|
type: "array",
|
|
items: reducedItemSchema(nested, references, depth + 1),
|
|
};
|
|
};
|
|
|
|
/**
|
|
* Present a reduced property's reference-resolved types. Reduced inputs omit
|
|
* nested validation, but clients still require an item schema for an array
|
|
* declaration, and Gemini accepts `items` only beside the single `array` type,
|
|
* so a property that may be an array or another type lists typed branches.
|
|
*/
|
|
const reducedPropertyTypes = (
|
|
value: unknown,
|
|
references: JsonSchemaReferences,
|
|
): Record<string, unknown> => {
|
|
const types = detectedTypes(value, references, references.rootScope);
|
|
if (types === undefined || types.length === 0) return {};
|
|
if (!types.includes("array")) return typedAlternatives(types);
|
|
const array = {
|
|
type: "array",
|
|
items: reducedItemSchema(
|
|
arrayItemAlternatives(value, references, references.rootScope),
|
|
references,
|
|
),
|
|
};
|
|
return types.length === 1
|
|
? array
|
|
: {
|
|
anyOf: types.map((type) => (type === "array" ? array : { type })),
|
|
};
|
|
};
|
|
|
|
/**
|
|
* Present only the root property shape with per-property guidance. Used for
|
|
* schemas whose validation structure alone exceeds the compact budget; the
|
|
* canonical schema still rejects malformed calls server-side.
|
|
*/
|
|
export const reduceToShallowProperties = (
|
|
schema: Record<string, unknown>,
|
|
reducedAnnotation: string,
|
|
): Record<string, unknown> => {
|
|
const properties = isSchemaObject(schema.properties) ? schema.properties : {};
|
|
const description = [
|
|
typeof schema.description === "string" ? schema.description : undefined,
|
|
reducedAnnotation,
|
|
]
|
|
.filter((text) => text !== undefined)
|
|
.join(" ");
|
|
const references = new JsonSchemaReferences(schema);
|
|
const shallow = Object.fromEntries(
|
|
Object.entries(properties).map(([name, value]) => {
|
|
const description =
|
|
isSchemaObject(value) && typeof value.description === "string"
|
|
? { description: value.description }
|
|
: {};
|
|
return [
|
|
name,
|
|
{ ...reducedPropertyTypes(value, references), ...description },
|
|
];
|
|
}),
|
|
);
|
|
return {
|
|
...(typeof schema.$schema === "string" ? { $schema: schema.$schema } : {}),
|
|
type: "object",
|
|
description,
|
|
properties: shallow,
|
|
...(Array.isArray(schema.required)
|
|
? { required: [...schema.required] }
|
|
: {}),
|
|
...(typeof schema.minProperties === "number"
|
|
? { minProperties: schema.minProperties }
|
|
: {}),
|
|
// The reduced form drops `patternProperties`; closing it would then reject
|
|
// names those patterns admitted.
|
|
...(schema.additionalProperties === false &&
|
|
!(
|
|
isSchemaObject(schema.patternProperties) &&
|
|
Object.keys(schema.patternProperties).length > 0
|
|
)
|
|
? { additionalProperties: false }
|
|
: {}),
|
|
// Root property dependencies still apply to the shallow properties; a
|
|
// dialect projection states them as tool guidance.
|
|
...Object.fromEntries(
|
|
["dependentRequired", "dependencies"].flatMap((key) =>
|
|
isSchemaObject(schema[key]) ? [[key, schema[key]]] : [],
|
|
),
|
|
),
|
|
};
|
|
};
|