import type { JsonPrimitive, JsonValue } from './common.js'; /** * Primitive JSON Schema `type` values supported by the MVP inference layer. */ export type JsonSchemaPrimitiveType = 'string' | 'number' | 'integer' | 'boolean' | 'null'; /** * JSON Schema `type` values supported by the MVP inference layer. */ export type JsonSchemaType = JsonSchemaPrimitiveType | 'object' | 'array'; /** * JSON Schema multi-type tuple (for example `["string", "null"]`). */ export type JsonSchemaTypeArray = readonly [JsonSchemaType, ...JsonSchemaType[]]; /** * Literal values supported in JSON Schema `enum`/`const`. */ export type JsonSchemaEnumValue = JsonPrimitive | JsonValue; /** * Extra JSON Schema keywords tolerated by the inference layer. * * These keys are intentionally accepted as opaque metadata. Inference only uses * the core MVP keywords and ignores these fields. */ interface SupplementalJsonSchemaKeywords { $defs?: unknown; $ref?: unknown; additionalItems?: unknown; allOf?: unknown; anyOf?: unknown; contains?: unknown; definitions?: unknown; dependentRequired?: unknown; dependentSchemas?: unknown; format?: unknown; if?: unknown; maxContains?: unknown; minContains?: unknown; not?: unknown; oneOf?: unknown; patternProperties?: unknown; prefixItems?: unknown; propertyNames?: unknown; then?: unknown; unevaluatedItems?: unknown; unevaluatedProperties?: unknown; } /** * Non-validation metadata accepted by the MVP inference subset. */ interface JsonSchemaMetadata extends SupplementalJsonSchemaKeywords { default?: JsonValue; description?: string; examples?: readonly JsonValue[]; /** * OpenAPI-compatible nullability marker. */ nullable?: boolean; title?: string; } /** * JSON Schema for `type: "string"`. */ export interface JsonSchemaString extends JsonSchemaMetadata { const?: string; enum?: readonly string[]; maxLength?: number; minLength?: number; pattern?: string; type: 'string'; } /** * JSON Schema for `type: "number"` and `type: "integer"`. */ export interface JsonSchemaNumber extends JsonSchemaMetadata { const?: number; enum?: readonly number[]; exclusiveMaximum?: number; exclusiveMinimum?: number; maximum?: number; minimum?: number; multipleOf?: number; type: 'number' | 'integer'; } /** * JSON Schema for `type: "boolean"`. */ export interface JsonSchemaBoolean extends JsonSchemaMetadata { const?: boolean; enum?: readonly boolean[]; type: 'boolean'; } /** * JSON Schema for `type: "null"`. */ export interface JsonSchemaNull extends JsonSchemaMetadata { const?: null; enum?: readonly null[]; type: 'null'; } /** * JSON Schema for `type: "array"`. */ export interface JsonSchemaArray extends JsonSchemaMetadata { items: JsonSchemaForInference; maxItems?: number; minItems?: number; type: 'array'; uniqueItems?: boolean; } /** * JSON Schema for `type: "object"`. */ export interface JsonSchemaObject extends JsonSchemaMetadata { additionalProperties?: boolean | JsonSchemaForInference; maxProperties?: number; minProperties?: number; properties?: Readonly>; required?: readonly string[]; type: 'object'; } /** * JSON Schema for multi-type unions via `type: [...]`. */ export interface JsonSchemaMultiType extends JsonSchemaMetadata { additionalProperties?: boolean | JsonSchemaForInference; const?: JsonSchemaEnumValue; enum?: readonly JsonSchemaEnumValue[]; items?: JsonSchemaForInference; properties?: Readonly>; required?: readonly string[]; type: JsonSchemaTypeArray; } /** * JSON Schema subset supported by the MVP type inference layer. */ export type JsonSchemaForInference = JsonSchemaArray | JsonSchemaBoolean | JsonSchemaMultiType | JsonSchemaNull | JsonSchemaNumber | JsonSchemaObject | JsonSchemaString; type Simplify = { [K in keyof T]: T[K]; } & {}; type EmptyObject = Record; type EnumLiteral = TSchema extends { enum: infer TEnum extends readonly unknown[]; } ? Extract : never; type ConstLiteral = TSchema extends { const: infer TConst; } ? Extract : never; type PropertiesOf = TSchema extends { properties: infer TProperties extends Readonly>; } ? TProperties : EmptyObject; type RequiredKeysOf> = TSchema extends { required: readonly (infer TRequired)[]; } ? string extends TRequired ? never : Extract : never; type RequiredProps, TRequiredKeys extends string> = { [K in keyof TProperties as K extends TRequiredKeys ? K : never]-?: InferJsonSchema; }; type OptionalProps, TRequiredKeys extends string> = { [K in keyof TProperties as K extends TRequiredKeys ? never : K]?: InferJsonSchema; }; type PropertyKeysOf = keyof PropertiesOf & string; type AdditionalSchemaOf = TSchema extends { additionalProperties: infer TAdditional; } ? TAdditional : undefined; type AdditionalPropsValue = AdditionalSchemaOf extends JsonSchemaForInference ? InferJsonSchema> : unknown; type AdditionalPropsOf = TSchema extends { additionalProperties: false; } ? EmptyObject : AdditionalSchemaOf extends JsonSchemaForInference ? PropertyKeysOf extends never ? Record> : Record : Record; type InferObject = Simplify, RequiredKeysOf>> & OptionalProps, RequiredKeysOf>> & AdditionalPropsOf>; type TypeKeywordOf = TSchema extends { type?: infer TType; } ? 'type' extends keyof TSchema ? TType : undefined : undefined; type TypeOptionsOf = [TypeKeywordOf] extends [undefined] ? 'object' : TypeKeywordOf extends readonly unknown[] ? Extract[number], JsonSchemaType> : Extract, JsonSchemaType>; type InferFromTypeOption = TType extends 'object' ? InferObject : TType extends 'array' ? TSchema extends { items: infer TItems; } ? InferJsonSchema[] : unknown[] : TType extends 'string' ? string : TType extends 'number' | 'integer' ? number : TType extends 'boolean' ? boolean : TType extends 'null' ? null : unknown; type InferFromTypeKeyword = TypeOptionsOf extends never ? unknown : InferFromTypeOption>; type ApplyNullable = TSchema extends { nullable: true; } ? TValue | null : TValue; /** * Infers a TypeScript type from the supported JSON Schema subset. * * `const` and `enum` take precedence when present. */ export type InferJsonSchema = [ConstLiteral] extends [never] ? [EnumLiteral] extends [never] ? ApplyNullable> : ApplyNullable> : ApplyNullable>; type IsWidenedTypeKeyword = string extends TTypeKeyword ? true : TTypeKeyword extends readonly unknown[] ? string extends TTypeKeyword[number] ? true : false : false; type IncludesObjectType = TypeOptionsOf extends never ? false : 'object' extends TypeOptionsOf ? true : false; /** * Infers tool argument types from a root `InputSchema`. * * If the schema is not a literal object schema (for example a widened * `InputSchema` loaded at runtime), this intentionally falls back to * `Record`. */ export type InferArgsFromInputSchema = IsWidenedTypeKeyword> extends true ? Record : IncludesObjectType extends true ? InferObject : Record; export {}; //# sourceMappingURL=json-schema.d.ts.map