export type GbnfJsonSchemaImmutableType = "string" | "number" | "integer" | "boolean" | "null"; export type GbnfJsonSchema = Record> = GbnfJsonBasicSchema | GbnfJsonConstSchema | GbnfJsonEnumSchema | GbnfJsonOneOfSchema | GbnfJsonStringSchema | GbnfJsonObjectSchema | GbnfJsonArraySchema | (keyof Defs extends string ? keyof NoInfer extends never ? never : GbnfJsonRefSchema : never); export type GbnfJsonDefList> = {}> = { readonly [key: string]: GbnfJsonSchema>; }; export type GbnfJsonBasicSchema = { readonly type: GbnfJsonSchemaImmutableType | readonly GbnfJsonSchemaImmutableType[]; /** * A description of what you expect the model to set this value to. * * Only passed to the model when using function calling, and has no effect when using JSON Schema grammar directly. */ readonly description?: string; }; export type GbnfJsonConstSchema = { readonly const: string | number | boolean | null; /** * A description of what you expect the model to set this value to. * * Only passed to the model when using function calling, and has no effect when using JSON Schema grammar directly. */ readonly description?: string; }; export type GbnfJsonEnumSchema = { readonly enum: readonly (string | number | boolean | null)[]; /** * A description of what you expect the model to set this value to. * * Only passed to the model when using function calling, and has no effect when using JSON Schema grammar directly. */ readonly description?: string; }; export type GbnfJsonOneOfSchema> = {}> = { readonly oneOf: readonly GbnfJsonSchema>[]; /** * A description of what you expect the model to set this value to. * * Only passed to the model when using function calling, and has no effect when using JSON Schema grammar directly. */ readonly description?: string; readonly $defs?: Defs; }; export type GbnfJsonStringSchema = GbnfJsonBasicStringSchema | GbnfJsonFormatStringSchema; export type GbnfJsonBasicStringSchema = { readonly type: "string"; /** * When using `minLength` and/or `maxLength`, * ensure to inform the model as part of the prompt what your expectations are regarding the length of the string. * Not doing this may lead to hallucinations. */ readonly minLength?: number; /** * When using `minLength` and/or `maxLength`, * ensure to inform the model as part of the prompt what your expectations are regarding the length of the string. * Not doing this may lead to hallucinations. */ readonly maxLength?: number; /** * A description of what you expect the model to set this value to. * * Only passed to the model when using function calling, and has no effect when using JSON Schema grammar directly. */ readonly description?: string; }; export type GbnfJsonFormatStringSchema = { readonly type: "string"; readonly format: "date-time" | "time" | "date"; /** * A description of what you expect the model to set this value to. * * Only passed to the model when using function calling, and has no effect when using JSON Schema grammar directly. */ readonly description?: string; }; export type GbnfJsonObjectSchema> = {}> = { readonly type: "object"; readonly properties?: { readonly [key in Keys]: GbnfJsonSchema>; }; /** * Unlike the JSON Schema spec, `additionalProperties` defaults to `false` to avoid breaking existing code. */ readonly additionalProperties?: boolean | GbnfJsonSchema>; /** * Make sure you define `additionalProperties` for this to have any effect. * * When using `minProperties` and/or `maxProperties`, * ensure to inform the model as part of the prompt what your expectations are regarding the number of keys in the object. * Not doing this may lead to hallucinations. */ readonly minProperties?: number; /** * Make sure you define `additionalProperties` for this to have any effect. * * When using `minProperties` and/or `maxProperties`, * ensure to inform the model as part of the prompt what your expectations are regarding the number of keys in the object. * Not doing this may lead to hallucinations. */ readonly maxProperties?: number; /** * `required` is always set to all keys in `properties`, and setting it has no effect. * * This limitation is due to how the generation works, and may be fixed in the future. * * This key is part of the type to avoid breaking exiting code (though it was never actually used in the past), * and will be removed in the future. * @deprecated */ readonly required?: readonly Keys[]; /** * A description of what you expect the model to set this value to. * * Only passed to the model when using function calling, and has no effect when using JSON Schema grammar directly. */ readonly description?: string; readonly $defs?: Defs; }; export type GbnfJsonArraySchema> = {}> = { readonly type: "array"; readonly items?: GbnfJsonSchema>; readonly prefixItems?: readonly GbnfJsonSchema>[]; /** * When using `minItems` and/or `maxItems`, * ensure to inform the model as part of the prompt what your expectations are regarding the length of the array. * Not doing this may lead to hallucinations. */ readonly minItems?: number; /** * When using `minItems` and/or `maxItems`, * ensure to inform the model as part of the prompt what your expectations are regarding the length of the array. * Not doing this may lead to hallucinations. */ readonly maxItems?: number; /** * A description of what you expect the model to set this value to. * * Only passed to the model when using function calling, and has no effect when using JSON Schema grammar directly. */ readonly description?: string; readonly $defs?: Defs; }; export type GbnfJsonRefSchema> = {}> = { readonly $ref: keyof NoInfer extends never ? never : `#/$defs/${OnlyStringKeys>}`; /** * A description of what you expect the model to set this value to. * * Only passed to the model when using function calling, and has no effect when using JSON Schema grammar directly. */ readonly description?: string; readonly $defs?: Defs; }; /** * Converts a GBNF JSON schema to a TypeScript type */ export type GbnfJsonSchemaToType = 0 extends 1 & T ? any : GbnfJsonSchemaToTSType; export type GbnfJsonSchemaToTSType> = {}> = Readonly extends T ? undefined : undefined extends T ? undefined : T extends GbnfJsonBasicStringSchema ? GbnfJsonBasicStringSchemaToType : T extends GbnfJsonFormatStringSchema ? string : T extends GbnfJsonBasicSchema ? GbnfJsonBasicSchemaToType : T extends GbnfJsonConstSchema ? T["const"] : T extends GbnfJsonEnumSchema ? T["enum"][number] : T extends GbnfJsonOneOfSchema> ? GbnfJsonSchemaToTSType, T["$defs"]>> : T extends GbnfJsonObjectSchema> ? GbnfJsonObjectSchemaToType> : T extends GbnfJsonArraySchema> ? ArrayTypeToType, T["$defs"]>> : T extends GbnfJsonRefSchema ? GbnfJsonRefSchemaToType, T["$defs"]>> : undefined; type GbnfJsonBasicStringSchemaToType = T["maxLength"] extends 0 ? "" : string; type GbnfJsonBasicSchemaToType = T extends GbnfJsonSchemaImmutableType ? ImmutableTypeToType : T[number] extends GbnfJsonSchemaImmutableType ? ImmutableTypeToType : never; type ImmutableTypeToType = T extends "string" ? string : T extends "number" ? number : T extends "integer" ? number : T extends "boolean" ? boolean : T extends "null" ? null : never; type ArrayTypeToType>, Defs extends GbnfJsonDefList = {}, MinItems extends number = T["minItems"] extends number ? T["prefixItems"] extends readonly GbnfJsonSchema[] ? keyof T["prefixItems"] extends T["minItems"] ? T["prefixItems"]["length"] : T["minItems"] : T["minItems"] : T["prefixItems"] extends readonly GbnfJsonSchema[] ? T["prefixItems"]["length"] : 0> = T["prefixItems"] extends readonly GbnfJsonSchema[] ? (MinItems extends T["prefixItems"]["length"] ? (T["maxItems"] extends MinItems ? [ ...GbnfJsonOrderedArrayTypes>, ...IndexRangeWithSkip> : GbnfJsonAnyValue> ] : [ ...GbnfJsonOrderedArrayTypes>, ...(T["items"] extends GbnfJsonSchema ? GbnfJsonSchemaToTSType> : GbnfJsonAnyValue)[] ]) : T["maxItems"] extends MinItems ? [ ...GbnfJsonOrderedArrayTypes>, ...(T["items"] extends GbnfJsonSchema ? IndexRangeWithSkip>> : IndexRangeWithSkip) ] : [ ...GbnfJsonOrderedArrayTypes>, ...IndexRangeWithSkip> : GbnfJsonAnyValue>, ...(T["items"] extends GbnfJsonSchema ? GbnfJsonSchemaToTSType> : GbnfJsonAnyValue)[] ]) : T["items"] extends GbnfJsonSchema ? (MinItems extends 0 ? GbnfJsonSchemaToTSType>[] : T["maxItems"] extends MinItems ? IndexRange>> : [ ...IndexRange>>, ...GbnfJsonSchemaToTSType>[] ]) : (MinItems extends 0 ? GbnfJsonAnyValue[] : T["maxItems"] extends MinItems ? IndexRange : [ ...IndexRange, ...GbnfJsonAnyValue[] ]); type GbnfJsonObjectSchemaToType>, Defs extends GbnfJsonDefList = {}, Props extends Readonly> | undefined = T["properties"], AdditionalProps extends true | false | GbnfJsonSchema | undefined = T["additionalProperties"], PropsMap = Props extends undefined ? {} : { -readonly [P in keyof Props]: GbnfJsonSchemaToTSType>; }, Res = AdditionalProps extends undefined | false ? PropsMap : AdditionalProps extends true ? PropsMap & { [key: string]: GbnfJsonAnyValue; } : AdditionalProps extends GbnfJsonSchema ? PropsMap & { [key: string]: GbnfJsonSchemaToTSType>; } : PropsMap> = Res; type GbnfJsonRefSchemaToType, Defs extends GbnfJsonDefList = {}> = T["$ref"] extends `#/$defs/${infer Key}` ? Key extends keyof Defs ? GbnfJsonSchemaToTSType : never : never; type GbnfJsonAnyValue = string | number | boolean | null | GbnfJsonAnyValue[] | { [key: string]: GbnfJsonAnyValue; }; export declare function isGbnfJsonConstSchema(schema: GbnfJsonSchema): schema is GbnfJsonConstSchema; export declare function isGbnfJsonEnumSchema(schema: GbnfJsonSchema): schema is GbnfJsonEnumSchema; export declare function isGbnfJsonOneOfSchema(schema: GbnfJsonSchema): schema is GbnfJsonOneOfSchema; export declare function isGbnfJsonBasicStringSchema(schema: GbnfJsonSchema): schema is GbnfJsonBasicStringSchema; export declare function isGbnfJsonFormatStringSchema(schema: GbnfJsonSchema): schema is GbnfJsonFormatStringSchema; export declare function isGbnfJsonObjectSchema(schema: GbnfJsonSchema): schema is GbnfJsonObjectSchema; export declare function isGbnfJsonArraySchema(schema: GbnfJsonSchema): schema is GbnfJsonArraySchema; export declare function isGbnfJsonRefSchema(schema: GbnfJsonSchema): schema is GbnfJsonRefSchema>; export declare function isGbnfJsonBasicSchemaIncludesType(schema: GbnfJsonBasicSchema, type: T): schema is GbnfJsonBasicSchema & { type: T | (T | GbnfJsonSchemaImmutableType)[]; }; type OnlyStringKeys = { [K in keyof T]: K extends string ? K : never; }[keyof T]; type CombineDefs, Param2 extends Defs1 | Defs2 | undefined, Defs2 extends GbnfJsonDefList = {}> = undefined extends NoInfer ? Defs1 : Defs1 & Param2; type IndexRange> = Res; type _IndexRange = Value["length"] extends MaxLength ? Value : _IndexRange<[...Value, FillType], MaxLength, FillType>; type IndexRangeWithSkip, Length, FillType>> = Res; type _IndexRangeWithSkip = ConditionValue["length"] extends MaxLength ? Value : _IndexRangeWithSkip<[...Value, FillType], [...ConditionValue, ConditionValue["length"]], MaxLength, FillType>; type GbnfJsonOrderedArrayTypes = {}> = { -readonly [P in keyof T]: GbnfJsonSchemaToTSType; }; export {};