Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 5x 4x 1x | import { z } from "zod";
export interface SchemaDefinition {
name: string;
schema: z.ZodType<unknown> | Record<string, unknown>; // Support Zod or raw JSON Schema
description?: string;
strict?: boolean; // For OpenAI's strict mode
}
export class Schema {
constructor(public readonly definition: SchemaDefinition) {}
static fromZod(
name: string,
schema: z.ZodType<unknown>,
options?: { description?: string; strict?: boolean }
): Schema {
return new Schema({
name,
schema,
description: options?.description,
strict: options?.strict
});
}
static fromJson(
name: string,
schema: Record<string, unknown>,
options?: { description?: string; strict?: boolean }
): Schema {
return new Schema({
name,
schema,
description: options?.description,
strict: options?.strict
});
}
}
|