Files
reverse-engineering-anything/src/domain/fixedTupleSchema.ts
T
morluto 204b9f3ac1 fix(contracts): preserve array guidance across MCP schema profiles
Keep item schemas when compact inputs reduce nested structure, expose literal tuple elements to items-first renderers, and preserve SQLite table-selection guidance across compaction. Verify catalog-wide client constraints and canonical rejection before dispatch. Document the stock Pi renderer size limit and caller-selected recovery.
2026-10-15 01:41:31 +08:00

15 lines
583 B
TypeScript

import { z } from "zod";
/** Fixed tuples with explicit item and length constraints in JSON Schema. */
export const fixedTupleSchema = <
const Items extends readonly [z.ZodType, ...z.ZodType[]],
>(
items: Items,
): z.ZodTuple<Items, z.ZodUnion<Items>> =>
// Keep the positional schemas and lengths explicit. The union rest schema
// gives clients that only understand `items` useful element guidance; the
// exact maximum length means no rest element can be accepted.
z
.tuple(items, z.union(items))
.check(z.minLength(items.length), z.maxLength(items.length));