@typia/interface 12.0.0-dev.20260312 → 12.0.0-dev.20260312-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/schema/ILlmApplication.ts +98 -98
- package/src/schema/ILlmSchema.ts +473 -473
package/package.json
CHANGED
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
import { ILlmFunction } from "./ILlmFunction";
|
|
2
|
-
import { ILlmSchema } from "./ILlmSchema";
|
|
3
|
-
import { IValidation } from "./IValidation";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* LLM function calling application.
|
|
7
|
-
*
|
|
8
|
-
* `ILlmApplication` is a collection of {@link ILlmFunction} schemas generated
|
|
9
|
-
* from a TypeScript class or interface by `typia.llm.application<App>()`. Each
|
|
10
|
-
* public method becomes an {@link ILlmFunction} that LLM agents can invoke.
|
|
11
|
-
*
|
|
12
|
-
* Configure behavior via {@link ILlmApplication.IConfig}:
|
|
13
|
-
*
|
|
14
|
-
* - {@link ILlmApplication.IConfig.validate}: Custom validation per method
|
|
15
|
-
* - {@link ILlmSchema.IConfig.strict}: OpenAI structured output mode
|
|
16
|
-
*
|
|
17
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
18
|
-
* @template Class Source class/interface type
|
|
19
|
-
*/
|
|
20
|
-
export interface ILlmApplication<Class extends object = any> {
|
|
21
|
-
/**
|
|
22
|
-
* Array of callable function schemas.
|
|
23
|
-
*
|
|
24
|
-
* Each function represents a method from the source class that the LLM can
|
|
25
|
-
* invoke. Functions include parameter schemas, descriptions, and validation
|
|
26
|
-
* logic for type-safe function calling.
|
|
27
|
-
*/
|
|
28
|
-
functions: ILlmFunction[];
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Configuration used to generate this application.
|
|
32
|
-
*
|
|
33
|
-
* Contains the settings that were applied during schema generation, including
|
|
34
|
-
* strict mode and any custom validation hooks.
|
|
35
|
-
*/
|
|
36
|
-
config: ILlmApplication.IConfig<Class>;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Phantom property for TypeScript generic type preservation.
|
|
40
|
-
*
|
|
41
|
-
* This property exists only in the type system to preserve the `Class`
|
|
42
|
-
* generic parameter at compile time. It is always `undefined` at runtime and
|
|
43
|
-
* should not be accessed or used in application code.
|
|
44
|
-
*
|
|
45
|
-
* This pattern enables type inference to recover the original class type from
|
|
46
|
-
* an `ILlmApplication` instance, useful for type-safe function routing.
|
|
47
|
-
*/
|
|
48
|
-
__class?: Class | undefined;
|
|
49
|
-
}
|
|
50
|
-
export namespace ILlmApplication {
|
|
51
|
-
/**
|
|
52
|
-
* Configuration for LLM application generation.
|
|
53
|
-
*
|
|
54
|
-
* Extends {@link ILlmSchema.IConfig} with application-specific options for
|
|
55
|
-
* custom validation. These settings control how the application schema is
|
|
56
|
-
* generated from the source class.
|
|
57
|
-
*/
|
|
58
|
-
export interface IConfig<Class extends object = any>
|
|
59
|
-
extends ILlmSchema.IConfig {
|
|
60
|
-
/**
|
|
61
|
-
* Custom validation functions per method name.
|
|
62
|
-
*
|
|
63
|
-
* Allows overriding the default type-based validation with custom business
|
|
64
|
-
* logic. Useful for complex validation rules that cannot be expressed in
|
|
65
|
-
* JSON Schema.
|
|
66
|
-
*
|
|
67
|
-
* @default null (use default type validation)
|
|
68
|
-
*/
|
|
69
|
-
validate: null | Partial<ILlmApplication.IValidationHook<Class>>;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Type-safe mapping of method names to custom validators.
|
|
74
|
-
*
|
|
75
|
-
* Maps each method name to a validation function that receives the raw input
|
|
76
|
-
* and returns a validation result. The type inference ensures validators
|
|
77
|
-
* match the expected argument types.
|
|
78
|
-
*
|
|
79
|
-
* @template Class - The source class type for type inference
|
|
80
|
-
*/
|
|
81
|
-
export type IValidationHook<Class extends object> = {
|
|
82
|
-
[K in keyof Class]?: Class[K] extends (args: infer Argument) => unknown
|
|
83
|
-
? (input: unknown) => IValidation<Argument>
|
|
84
|
-
: never;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Internal type for typia transformer.
|
|
89
|
-
*
|
|
90
|
-
* @ignore
|
|
91
|
-
*/
|
|
92
|
-
export interface __IPrimitive<Class extends object = any> extends Omit<
|
|
93
|
-
ILlmApplication<Class>,
|
|
94
|
-
"config" | "functions"
|
|
95
|
-
> {
|
|
96
|
-
functions: Omit<ILlmFunction, "parse" | "coerce">[];
|
|
97
|
-
}
|
|
98
|
-
}
|
|
1
|
+
import { ILlmFunction } from "./ILlmFunction";
|
|
2
|
+
import { ILlmSchema } from "./ILlmSchema";
|
|
3
|
+
import { IValidation } from "./IValidation";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* LLM function calling application.
|
|
7
|
+
*
|
|
8
|
+
* `ILlmApplication` is a collection of {@link ILlmFunction} schemas generated
|
|
9
|
+
* from a TypeScript class or interface by `typia.llm.application<App>()`. Each
|
|
10
|
+
* public method becomes an {@link ILlmFunction} that LLM agents can invoke.
|
|
11
|
+
*
|
|
12
|
+
* Configure behavior via {@link ILlmApplication.IConfig}:
|
|
13
|
+
*
|
|
14
|
+
* - {@link ILlmApplication.IConfig.validate}: Custom validation per method
|
|
15
|
+
* - {@link ILlmSchema.IConfig.strict}: OpenAI structured output mode
|
|
16
|
+
*
|
|
17
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
18
|
+
* @template Class Source class/interface type
|
|
19
|
+
*/
|
|
20
|
+
export interface ILlmApplication<Class extends object = any> {
|
|
21
|
+
/**
|
|
22
|
+
* Array of callable function schemas.
|
|
23
|
+
*
|
|
24
|
+
* Each function represents a method from the source class that the LLM can
|
|
25
|
+
* invoke. Functions include parameter schemas, descriptions, and validation
|
|
26
|
+
* logic for type-safe function calling.
|
|
27
|
+
*/
|
|
28
|
+
functions: ILlmFunction[];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Configuration used to generate this application.
|
|
32
|
+
*
|
|
33
|
+
* Contains the settings that were applied during schema generation, including
|
|
34
|
+
* strict mode and any custom validation hooks.
|
|
35
|
+
*/
|
|
36
|
+
config: ILlmApplication.IConfig<Class>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Phantom property for TypeScript generic type preservation.
|
|
40
|
+
*
|
|
41
|
+
* This property exists only in the type system to preserve the `Class`
|
|
42
|
+
* generic parameter at compile time. It is always `undefined` at runtime and
|
|
43
|
+
* should not be accessed or used in application code.
|
|
44
|
+
*
|
|
45
|
+
* This pattern enables type inference to recover the original class type from
|
|
46
|
+
* an `ILlmApplication` instance, useful for type-safe function routing.
|
|
47
|
+
*/
|
|
48
|
+
__class?: Class | undefined;
|
|
49
|
+
}
|
|
50
|
+
export namespace ILlmApplication {
|
|
51
|
+
/**
|
|
52
|
+
* Configuration for LLM application generation.
|
|
53
|
+
*
|
|
54
|
+
* Extends {@link ILlmSchema.IConfig} with application-specific options for
|
|
55
|
+
* custom validation. These settings control how the application schema is
|
|
56
|
+
* generated from the source class.
|
|
57
|
+
*/
|
|
58
|
+
export interface IConfig<Class extends object = any>
|
|
59
|
+
extends ILlmSchema.IConfig {
|
|
60
|
+
/**
|
|
61
|
+
* Custom validation functions per method name.
|
|
62
|
+
*
|
|
63
|
+
* Allows overriding the default type-based validation with custom business
|
|
64
|
+
* logic. Useful for complex validation rules that cannot be expressed in
|
|
65
|
+
* JSON Schema.
|
|
66
|
+
*
|
|
67
|
+
* @default null (use default type validation)
|
|
68
|
+
*/
|
|
69
|
+
validate: null | Partial<ILlmApplication.IValidationHook<Class>>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Type-safe mapping of method names to custom validators.
|
|
74
|
+
*
|
|
75
|
+
* Maps each method name to a validation function that receives the raw input
|
|
76
|
+
* and returns a validation result. The type inference ensures validators
|
|
77
|
+
* match the expected argument types.
|
|
78
|
+
*
|
|
79
|
+
* @template Class - The source class type for type inference
|
|
80
|
+
*/
|
|
81
|
+
export type IValidationHook<Class extends object> = {
|
|
82
|
+
[K in keyof Class]?: Class[K] extends (args: infer Argument) => unknown
|
|
83
|
+
? (input: unknown) => IValidation<Argument>
|
|
84
|
+
: never;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Internal type for typia transformer.
|
|
89
|
+
*
|
|
90
|
+
* @ignore
|
|
91
|
+
*/
|
|
92
|
+
export interface __IPrimitive<Class extends object = any> extends Omit<
|
|
93
|
+
ILlmApplication<Class>,
|
|
94
|
+
"config" | "functions"
|
|
95
|
+
> {
|
|
96
|
+
functions: Omit<ILlmFunction, "parse" | "coerce">[];
|
|
97
|
+
}
|
|
98
|
+
}
|
package/src/schema/ILlmSchema.ts
CHANGED
|
@@ -1,473 +1,473 @@
|
|
|
1
|
-
import { tags } from "../index";
|
|
2
|
-
import { IJsonSchemaAttribute } from "./IJsonSchemaAttribute";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Type schema for LLM function calling.
|
|
6
|
-
*
|
|
7
|
-
* `ILlmSchema` is a JSON Schema subset designed for LLM function calling
|
|
8
|
-
* compatibility. Most LLMs (OpenAI GPT, Anthropic Claude, Google Gemini, etc.)
|
|
9
|
-
* do not fully support JSON Schema, so this simplified schema omits unsupported
|
|
10
|
-
* features like tuples, `const`, and mixed union types.
|
|
11
|
-
*
|
|
12
|
-
* Generated by `typia.llm.schema<T>()` for single types or included in
|
|
13
|
-
* {@link ILlmApplication} via `typia.llm.application<Class>()`. Shared type
|
|
14
|
-
* definitions use `$defs` with `$ref` references to reduce duplication and
|
|
15
|
-
* handle recursive structures.
|
|
16
|
-
*
|
|
17
|
-
* Set {@link ILlmSchema.IConfig.strict} to `true` for OpenAI's structured output
|
|
18
|
-
* mode, which requires all properties to be `required` and
|
|
19
|
-
* `additionalProperties: false`.
|
|
20
|
-
*
|
|
21
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
22
|
-
*/
|
|
23
|
-
export type ILlmSchema =
|
|
24
|
-
| ILlmSchema.IBoolean
|
|
25
|
-
| ILlmSchema.IInteger
|
|
26
|
-
| ILlmSchema.INumber
|
|
27
|
-
| ILlmSchema.IString
|
|
28
|
-
| ILlmSchema.IArray
|
|
29
|
-
| ILlmSchema.IObject
|
|
30
|
-
| ILlmSchema.IReference
|
|
31
|
-
| ILlmSchema.IAnyOf
|
|
32
|
-
| ILlmSchema.INull
|
|
33
|
-
| ILlmSchema.IUnknown;
|
|
34
|
-
export namespace ILlmSchema {
|
|
35
|
-
/**
|
|
36
|
-
* Configuration options for LLM schema generation.
|
|
37
|
-
*
|
|
38
|
-
* Controls how TypeScript types are converted to LLM-compatible JSON schemas.
|
|
39
|
-
* These settings affect OpenAI structured output compatibility.
|
|
40
|
-
*/
|
|
41
|
-
export interface IConfig {
|
|
42
|
-
/**
|
|
43
|
-
* Whether to enable strict mode (OpenAI structured output).
|
|
44
|
-
*
|
|
45
|
-
* When `true`, all properties become required and `additionalProperties` is
|
|
46
|
-
* forced to `false`.
|
|
47
|
-
*
|
|
48
|
-
* @default false
|
|
49
|
-
*/
|
|
50
|
-
strict: boolean;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Function parameters schema with shared type definitions.
|
|
55
|
-
*
|
|
56
|
-
* Extends the object schema to include a `$defs` map for named type
|
|
57
|
-
* definitions that can be referenced via `$ref`. This structure allows
|
|
58
|
-
* recursive types and reduces schema duplication.
|
|
59
|
-
*
|
|
60
|
-
* The `additionalProperties` is always `false` for parameters to ensure
|
|
61
|
-
* strict argument validation and prevent unexpected properties.
|
|
62
|
-
*/
|
|
63
|
-
export interface IParameters extends Omit<IObject, "additionalProperties"> {
|
|
64
|
-
/**
|
|
65
|
-
* Named schema definitions for reference.
|
|
66
|
-
*
|
|
67
|
-
* Contains type definitions that can be referenced throughout the schema
|
|
68
|
-
* using `$ref: "#/$defs/TypeName"`. Essential for recursive types and
|
|
69
|
-
* shared structures.
|
|
70
|
-
*/
|
|
71
|
-
$defs: Record<string, ILlmSchema>;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Whether additional properties are allowed.
|
|
75
|
-
*
|
|
76
|
-
* Always `false` for function parameters to ensure strict type checking.
|
|
77
|
-
* This prevents LLMs from hallucinating extra properties.
|
|
78
|
-
*/
|
|
79
|
-
additionalProperties: false;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Boolean type schema.
|
|
84
|
-
*
|
|
85
|
-
* Represents a JSON Schema boolean type with optional enum constraints and
|
|
86
|
-
* default value. Used for true/false parameters and flags.
|
|
87
|
-
*/
|
|
88
|
-
export interface IBoolean extends IJsonSchemaAttribute.IBoolean {
|
|
89
|
-
/**
|
|
90
|
-
* Allowed boolean values.
|
|
91
|
-
*
|
|
92
|
-
* Restricts the value to specific boolean literals. Typically unused since
|
|
93
|
-
* booleans only have two possible values, but supported for consistency
|
|
94
|
-
* with other types.
|
|
95
|
-
*/
|
|
96
|
-
enum?: Array<boolean>;
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Default value when not provided.
|
|
100
|
-
*
|
|
101
|
-
* The boolean value to use when the LLM omits this parameter.
|
|
102
|
-
*/
|
|
103
|
-
default?: boolean;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Integer type schema.
|
|
108
|
-
*
|
|
109
|
-
* Represents a JSON Schema integer type with numeric constraints. Maps to
|
|
110
|
-
* TypeScript `number` with integer validation. Supports range constraints,
|
|
111
|
-
* enum restrictions, and divisibility checks.
|
|
112
|
-
*/
|
|
113
|
-
export interface IInteger extends IJsonSchemaAttribute.IInteger {
|
|
114
|
-
/**
|
|
115
|
-
* Allowed integer values.
|
|
116
|
-
*
|
|
117
|
-
* Restricts the value to specific integer literals. Useful for representing
|
|
118
|
-
* enum-like integer codes or limited value sets.
|
|
119
|
-
*/
|
|
120
|
-
enum?: Array<number & tags.Type<"int64">>;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Default value when not provided.
|
|
124
|
-
*
|
|
125
|
-
* The integer value to use when the LLM omits this parameter.
|
|
126
|
-
*/
|
|
127
|
-
default?: number & tags.Type<"int64">;
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Minimum value (inclusive).
|
|
131
|
-
*
|
|
132
|
-
* The value must be greater than or equal to this number.
|
|
133
|
-
*/
|
|
134
|
-
minimum?: number & tags.Type<"int64">;
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Maximum value (inclusive).
|
|
138
|
-
*
|
|
139
|
-
* The value must be less than or equal to this number.
|
|
140
|
-
*/
|
|
141
|
-
maximum?: number & tags.Type<"int64">;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Exclusive minimum value.
|
|
145
|
-
*
|
|
146
|
-
* The value must be strictly greater than this number.
|
|
147
|
-
*/
|
|
148
|
-
exclusiveMinimum?: number & tags.Type<"int64">;
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Exclusive maximum value.
|
|
152
|
-
*
|
|
153
|
-
* The value must be strictly less than this number.
|
|
154
|
-
*/
|
|
155
|
-
exclusiveMaximum?: number & tags.Type<"int64">;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Value must be divisible by this number.
|
|
159
|
-
*
|
|
160
|
-
* Used for constraints like "must be even" (multipleOf: 2) or "must be a
|
|
161
|
-
* multiple of 100" (multipleOf: 100).
|
|
162
|
-
*/
|
|
163
|
-
multipleOf?: number & tags.Type<"uint64"> & tags.ExclusiveMinimum<0>;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Number (floating-point) type schema.
|
|
168
|
-
*
|
|
169
|
-
* Represents a JSON Schema number type for floating-point values. Maps to
|
|
170
|
-
* TypeScript `number` type. Supports range constraints, enum restrictions,
|
|
171
|
-
* and precision checks via multipleOf.
|
|
172
|
-
*/
|
|
173
|
-
export interface INumber extends IJsonSchemaAttribute.INumber {
|
|
174
|
-
/**
|
|
175
|
-
* Allowed numeric values.
|
|
176
|
-
*
|
|
177
|
-
* Restricts the value to specific number literals. Useful for representing
|
|
178
|
-
* specific valid values like percentages or rates.
|
|
179
|
-
*/
|
|
180
|
-
enum?: Array<number>;
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Default value when not provided.
|
|
184
|
-
*
|
|
185
|
-
* The number to use when the LLM omits this parameter.
|
|
186
|
-
*/
|
|
187
|
-
default?: number;
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Minimum value (inclusive).
|
|
191
|
-
*
|
|
192
|
-
* The value must be greater than or equal to this number.
|
|
193
|
-
*/
|
|
194
|
-
minimum?: number;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Maximum value (inclusive).
|
|
198
|
-
*
|
|
199
|
-
* The value must be less than or equal to this number.
|
|
200
|
-
*/
|
|
201
|
-
maximum?: number;
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Exclusive minimum value.
|
|
205
|
-
*
|
|
206
|
-
* The value must be strictly greater than this number.
|
|
207
|
-
*/
|
|
208
|
-
exclusiveMinimum?: number;
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Exclusive maximum value.
|
|
212
|
-
*
|
|
213
|
-
* The value must be strictly less than this number.
|
|
214
|
-
*/
|
|
215
|
-
exclusiveMaximum?: number;
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Value must be divisible by this number.
|
|
219
|
-
*
|
|
220
|
-
* Useful for decimal precision constraints like "two decimal places"
|
|
221
|
-
* (multipleOf: 0.01) or currency amounts (multipleOf: 0.01).
|
|
222
|
-
*/
|
|
223
|
-
multipleOf?: number & tags.ExclusiveMinimum<0>;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* String type schema.
|
|
228
|
-
*
|
|
229
|
-
* Represents a JSON Schema string type with format validation, pattern
|
|
230
|
-
* matching, and length constraints. Maps to TypeScript `string` type with
|
|
231
|
-
* optional semantic format annotations.
|
|
232
|
-
*/
|
|
233
|
-
export interface IString extends IJsonSchemaAttribute.IString {
|
|
234
|
-
/**
|
|
235
|
-
* Allowed string values.
|
|
236
|
-
*
|
|
237
|
-
* Restricts the value to specific string literals. Maps directly to
|
|
238
|
-
* TypeScript string literal union types.
|
|
239
|
-
*/
|
|
240
|
-
enum?: Array<string>;
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Default value when not provided.
|
|
244
|
-
*
|
|
245
|
-
* The string to use when the LLM omits this parameter.
|
|
246
|
-
*/
|
|
247
|
-
default?: string;
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Semantic format specifier.
|
|
251
|
-
*
|
|
252
|
-
* Indicates the string represents a specific format like email, UUID, or
|
|
253
|
-
* date-time. LLMs may use this to generate appropriate values. Common
|
|
254
|
-
* formats include "email", "uri", "uuid", "date-time".
|
|
255
|
-
*/
|
|
256
|
-
format?:
|
|
257
|
-
| "binary"
|
|
258
|
-
| "byte"
|
|
259
|
-
| "password"
|
|
260
|
-
| "regex"
|
|
261
|
-
| "uuid"
|
|
262
|
-
| "email"
|
|
263
|
-
| "hostname"
|
|
264
|
-
| "idn-email"
|
|
265
|
-
| "idn-hostname"
|
|
266
|
-
| "iri"
|
|
267
|
-
| "iri-reference"
|
|
268
|
-
| "ipv4"
|
|
269
|
-
| "ipv6"
|
|
270
|
-
| "uri"
|
|
271
|
-
| "uri-reference"
|
|
272
|
-
| "uri-template"
|
|
273
|
-
| "url"
|
|
274
|
-
| "date-time"
|
|
275
|
-
| "date"
|
|
276
|
-
| "time"
|
|
277
|
-
| "duration"
|
|
278
|
-
| "json-pointer"
|
|
279
|
-
| "relative-json-pointer"
|
|
280
|
-
| (string & {});
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Regular expression pattern for validation.
|
|
284
|
-
*
|
|
285
|
-
* The string must match this regex pattern. Note that LLMs may struggle
|
|
286
|
-
* with complex regex patterns; simple patterns work best.
|
|
287
|
-
*/
|
|
288
|
-
pattern?: string;
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* MIME type of the string content.
|
|
292
|
-
*
|
|
293
|
-
* Indicates the content type when the string contains encoded binary data,
|
|
294
|
-
* such as "application/json" or "image/png".
|
|
295
|
-
*/
|
|
296
|
-
contentMediaType?: string;
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Minimum string length.
|
|
300
|
-
*
|
|
301
|
-
* The string must have at least this many characters.
|
|
302
|
-
*/
|
|
303
|
-
minLength?: number & tags.Type<"uint64">;
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Maximum string length.
|
|
307
|
-
*
|
|
308
|
-
* The string must have at most this many characters.
|
|
309
|
-
*/
|
|
310
|
-
maxLength?: number & tags.Type<"uint64">;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Array type schema.
|
|
315
|
-
*
|
|
316
|
-
* Represents a JSON Schema array type with item type validation and size
|
|
317
|
-
* constraints. Maps to TypeScript `T[]` or `Array<T>` types. Note: Tuple
|
|
318
|
-
* types are not supported by LLM schemas.
|
|
319
|
-
*/
|
|
320
|
-
export interface IArray extends IJsonSchemaAttribute.IArray {
|
|
321
|
-
/**
|
|
322
|
-
* Schema for array elements.
|
|
323
|
-
*
|
|
324
|
-
* All elements in the array must conform to this schema. For heterogeneous
|
|
325
|
-
* arrays, use an `anyOf` schema.
|
|
326
|
-
*/
|
|
327
|
-
items: ILlmSchema;
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Whether elements must be unique.
|
|
331
|
-
*
|
|
332
|
-
* When `true`, no two elements may be equal. Maps to TypeScript `Set<T>`
|
|
333
|
-
* semantics but represented as an array.
|
|
334
|
-
*/
|
|
335
|
-
uniqueItems?: boolean;
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Minimum number of elements.
|
|
339
|
-
*
|
|
340
|
-
* The array must contain at least this many items.
|
|
341
|
-
*/
|
|
342
|
-
minItems?: number & tags.Type<"uint64">;
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Maximum number of elements.
|
|
346
|
-
*
|
|
347
|
-
* The array must contain at most this many items.
|
|
348
|
-
*/
|
|
349
|
-
maxItems?: number & tags.Type<"uint64">;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Object type schema.
|
|
354
|
-
*
|
|
355
|
-
* Represents a JSON Schema object type with named properties. Maps to
|
|
356
|
-
* TypeScript interface or object type. Supports required property
|
|
357
|
-
* declarations and dynamic additional properties.
|
|
358
|
-
*/
|
|
359
|
-
export interface IObject extends IJsonSchemaAttribute.IObject {
|
|
360
|
-
/**
|
|
361
|
-
* Property name to schema mapping.
|
|
362
|
-
*
|
|
363
|
-
* Defines the type of each named property on the object. All properties are
|
|
364
|
-
* defined here regardless of whether they are required or optional.
|
|
365
|
-
*/
|
|
366
|
-
properties: Record<string, ILlmSchema>;
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Schema for dynamic/additional properties.
|
|
370
|
-
*
|
|
371
|
-
* - `false` (default): No additional properties allowed
|
|
372
|
-
* - `true`: Any additional properties allowed
|
|
373
|
-
* - Schema: Additional properties must match this schema
|
|
374
|
-
*
|
|
375
|
-
* Note: ChatGPT and Gemini do not support `additionalProperties`. Use
|
|
376
|
-
* {@link ILlmSchema.IConfig.strict} mode for OpenAI compatibility.
|
|
377
|
-
*/
|
|
378
|
-
additionalProperties?: ILlmSchema | boolean;
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* List of required property names.
|
|
382
|
-
*
|
|
383
|
-
* Properties in this array must be present in the object. In strict mode,
|
|
384
|
-
* all properties become required automatically.
|
|
385
|
-
*/
|
|
386
|
-
required: string[];
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* Reference to a named schema definition.
|
|
391
|
-
*
|
|
392
|
-
* Points to a schema defined in the `$defs` map using a JSON pointer. Used to
|
|
393
|
-
* avoid schema duplication and enable recursive type definitions. The
|
|
394
|
-
* reference path format is `#/$defs/TypeName`.
|
|
395
|
-
*/
|
|
396
|
-
export interface IReference extends IJsonSchemaAttribute {
|
|
397
|
-
/**
|
|
398
|
-
* JSON pointer to the referenced schema.
|
|
399
|
-
*
|
|
400
|
-
* Must be in the format `#/$defs/TypeName` where TypeName is a key in the
|
|
401
|
-
* parent schema's `$defs` map.
|
|
402
|
-
*/
|
|
403
|
-
$ref: string;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
/**
|
|
407
|
-
* Union type schema (A | B | C).
|
|
408
|
-
*
|
|
409
|
-
* Represents a TypeScript union type where the value can match any one of the
|
|
410
|
-
* member schemas. Note: Gemini does not support `anyOf`/`oneOf` schemas. Use
|
|
411
|
-
* discriminated unions with `x-discriminator` when possible for better LLM
|
|
412
|
-
* comprehension.
|
|
413
|
-
*/
|
|
414
|
-
export interface IAnyOf extends IJsonSchemaAttribute {
|
|
415
|
-
/**
|
|
416
|
-
* Array of possible schemas.
|
|
417
|
-
*
|
|
418
|
-
* The value must match at least one of these schemas. Nested `anyOf`
|
|
419
|
-
* schemas are flattened to avoid deep nesting.
|
|
420
|
-
*/
|
|
421
|
-
anyOf: Exclude<ILlmSchema, ILlmSchema.IAnyOf>[];
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* Discriminator for tagged/discriminated unions.
|
|
425
|
-
*
|
|
426
|
-
* Helps LLMs understand which variant to select based on a discriminating
|
|
427
|
-
* property value. Improves type inference accuracy.
|
|
428
|
-
*/
|
|
429
|
-
"x-discriminator"?: IAnyOf.IDiscriminator;
|
|
430
|
-
}
|
|
431
|
-
export namespace IAnyOf {
|
|
432
|
-
/**
|
|
433
|
-
* Discriminator configuration for tagged unions.
|
|
434
|
-
*
|
|
435
|
-
* Specifies which property distinguishes between union variants and maps
|
|
436
|
-
* discriminator values to their corresponding schemas.
|
|
437
|
-
*/
|
|
438
|
-
export interface IDiscriminator {
|
|
439
|
-
/**
|
|
440
|
-
* Name of the discriminating property.
|
|
441
|
-
*
|
|
442
|
-
* This property must exist on all union member object schemas and contain
|
|
443
|
-
* unique literal values that identify each variant.
|
|
444
|
-
*/
|
|
445
|
-
propertyName: string;
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* Mapping from discriminator values to schema references.
|
|
449
|
-
*
|
|
450
|
-
* Keys are the literal values of the discriminator property, values are
|
|
451
|
-
* `$ref` paths to the corresponding schemas.
|
|
452
|
-
*/
|
|
453
|
-
mapping?: Record<string, string>;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
/**
|
|
458
|
-
* Null type schema.
|
|
459
|
-
*
|
|
460
|
-
* Represents the JSON null value. In TypeScript union types like `T | null`,
|
|
461
|
-
* this schema appears in an `anyOf` alongside the T schema.
|
|
462
|
-
*/
|
|
463
|
-
export interface INull extends IJsonSchemaAttribute.INull {}
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* Unknown/any type schema.
|
|
467
|
-
*
|
|
468
|
-
* Represents TypeScript `any` or `unknown` types where no specific type
|
|
469
|
-
* constraint is defined. Use sparingly as LLMs may generate unexpected values
|
|
470
|
-
* for unconstrained types.
|
|
471
|
-
*/
|
|
472
|
-
export interface IUnknown extends IJsonSchemaAttribute.IUnknown {}
|
|
473
|
-
}
|
|
1
|
+
import { tags } from "../index";
|
|
2
|
+
import { IJsonSchemaAttribute } from "./IJsonSchemaAttribute";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Type schema for LLM function calling.
|
|
6
|
+
*
|
|
7
|
+
* `ILlmSchema` is a JSON Schema subset designed for LLM function calling
|
|
8
|
+
* compatibility. Most LLMs (OpenAI GPT, Anthropic Claude, Google Gemini, etc.)
|
|
9
|
+
* do not fully support JSON Schema, so this simplified schema omits unsupported
|
|
10
|
+
* features like tuples, `const`, and mixed union types.
|
|
11
|
+
*
|
|
12
|
+
* Generated by `typia.llm.schema<T>()` for single types or included in
|
|
13
|
+
* {@link ILlmApplication} via `typia.llm.application<Class>()`. Shared type
|
|
14
|
+
* definitions use `$defs` with `$ref` references to reduce duplication and
|
|
15
|
+
* handle recursive structures.
|
|
16
|
+
*
|
|
17
|
+
* Set {@link ILlmSchema.IConfig.strict} to `true` for OpenAI's structured output
|
|
18
|
+
* mode, which requires all properties to be `required` and
|
|
19
|
+
* `additionalProperties: false`.
|
|
20
|
+
*
|
|
21
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
22
|
+
*/
|
|
23
|
+
export type ILlmSchema =
|
|
24
|
+
| ILlmSchema.IBoolean
|
|
25
|
+
| ILlmSchema.IInteger
|
|
26
|
+
| ILlmSchema.INumber
|
|
27
|
+
| ILlmSchema.IString
|
|
28
|
+
| ILlmSchema.IArray
|
|
29
|
+
| ILlmSchema.IObject
|
|
30
|
+
| ILlmSchema.IReference
|
|
31
|
+
| ILlmSchema.IAnyOf
|
|
32
|
+
| ILlmSchema.INull
|
|
33
|
+
| ILlmSchema.IUnknown;
|
|
34
|
+
export namespace ILlmSchema {
|
|
35
|
+
/**
|
|
36
|
+
* Configuration options for LLM schema generation.
|
|
37
|
+
*
|
|
38
|
+
* Controls how TypeScript types are converted to LLM-compatible JSON schemas.
|
|
39
|
+
* These settings affect OpenAI structured output compatibility.
|
|
40
|
+
*/
|
|
41
|
+
export interface IConfig {
|
|
42
|
+
/**
|
|
43
|
+
* Whether to enable strict mode (OpenAI structured output).
|
|
44
|
+
*
|
|
45
|
+
* When `true`, all properties become required and `additionalProperties` is
|
|
46
|
+
* forced to `false`.
|
|
47
|
+
*
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
strict: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Function parameters schema with shared type definitions.
|
|
55
|
+
*
|
|
56
|
+
* Extends the object schema to include a `$defs` map for named type
|
|
57
|
+
* definitions that can be referenced via `$ref`. This structure allows
|
|
58
|
+
* recursive types and reduces schema duplication.
|
|
59
|
+
*
|
|
60
|
+
* The `additionalProperties` is always `false` for parameters to ensure
|
|
61
|
+
* strict argument validation and prevent unexpected properties.
|
|
62
|
+
*/
|
|
63
|
+
export interface IParameters extends Omit<IObject, "additionalProperties"> {
|
|
64
|
+
/**
|
|
65
|
+
* Named schema definitions for reference.
|
|
66
|
+
*
|
|
67
|
+
* Contains type definitions that can be referenced throughout the schema
|
|
68
|
+
* using `$ref: "#/$defs/TypeName"`. Essential for recursive types and
|
|
69
|
+
* shared structures.
|
|
70
|
+
*/
|
|
71
|
+
$defs: Record<string, ILlmSchema>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Whether additional properties are allowed.
|
|
75
|
+
*
|
|
76
|
+
* Always `false` for function parameters to ensure strict type checking.
|
|
77
|
+
* This prevents LLMs from hallucinating extra properties.
|
|
78
|
+
*/
|
|
79
|
+
additionalProperties: false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Boolean type schema.
|
|
84
|
+
*
|
|
85
|
+
* Represents a JSON Schema boolean type with optional enum constraints and
|
|
86
|
+
* default value. Used for true/false parameters and flags.
|
|
87
|
+
*/
|
|
88
|
+
export interface IBoolean extends IJsonSchemaAttribute.IBoolean {
|
|
89
|
+
/**
|
|
90
|
+
* Allowed boolean values.
|
|
91
|
+
*
|
|
92
|
+
* Restricts the value to specific boolean literals. Typically unused since
|
|
93
|
+
* booleans only have two possible values, but supported for consistency
|
|
94
|
+
* with other types.
|
|
95
|
+
*/
|
|
96
|
+
enum?: Array<boolean>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Default value when not provided.
|
|
100
|
+
*
|
|
101
|
+
* The boolean value to use when the LLM omits this parameter.
|
|
102
|
+
*/
|
|
103
|
+
default?: boolean;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Integer type schema.
|
|
108
|
+
*
|
|
109
|
+
* Represents a JSON Schema integer type with numeric constraints. Maps to
|
|
110
|
+
* TypeScript `number` with integer validation. Supports range constraints,
|
|
111
|
+
* enum restrictions, and divisibility checks.
|
|
112
|
+
*/
|
|
113
|
+
export interface IInteger extends IJsonSchemaAttribute.IInteger {
|
|
114
|
+
/**
|
|
115
|
+
* Allowed integer values.
|
|
116
|
+
*
|
|
117
|
+
* Restricts the value to specific integer literals. Useful for representing
|
|
118
|
+
* enum-like integer codes or limited value sets.
|
|
119
|
+
*/
|
|
120
|
+
enum?: Array<number & tags.Type<"int64">>;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Default value when not provided.
|
|
124
|
+
*
|
|
125
|
+
* The integer value to use when the LLM omits this parameter.
|
|
126
|
+
*/
|
|
127
|
+
default?: number & tags.Type<"int64">;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Minimum value (inclusive).
|
|
131
|
+
*
|
|
132
|
+
* The value must be greater than or equal to this number.
|
|
133
|
+
*/
|
|
134
|
+
minimum?: number & tags.Type<"int64">;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Maximum value (inclusive).
|
|
138
|
+
*
|
|
139
|
+
* The value must be less than or equal to this number.
|
|
140
|
+
*/
|
|
141
|
+
maximum?: number & tags.Type<"int64">;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Exclusive minimum value.
|
|
145
|
+
*
|
|
146
|
+
* The value must be strictly greater than this number.
|
|
147
|
+
*/
|
|
148
|
+
exclusiveMinimum?: number & tags.Type<"int64">;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Exclusive maximum value.
|
|
152
|
+
*
|
|
153
|
+
* The value must be strictly less than this number.
|
|
154
|
+
*/
|
|
155
|
+
exclusiveMaximum?: number & tags.Type<"int64">;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Value must be divisible by this number.
|
|
159
|
+
*
|
|
160
|
+
* Used for constraints like "must be even" (multipleOf: 2) or "must be a
|
|
161
|
+
* multiple of 100" (multipleOf: 100).
|
|
162
|
+
*/
|
|
163
|
+
multipleOf?: number & tags.Type<"uint64"> & tags.ExclusiveMinimum<0>;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Number (floating-point) type schema.
|
|
168
|
+
*
|
|
169
|
+
* Represents a JSON Schema number type for floating-point values. Maps to
|
|
170
|
+
* TypeScript `number` type. Supports range constraints, enum restrictions,
|
|
171
|
+
* and precision checks via multipleOf.
|
|
172
|
+
*/
|
|
173
|
+
export interface INumber extends IJsonSchemaAttribute.INumber {
|
|
174
|
+
/**
|
|
175
|
+
* Allowed numeric values.
|
|
176
|
+
*
|
|
177
|
+
* Restricts the value to specific number literals. Useful for representing
|
|
178
|
+
* specific valid values like percentages or rates.
|
|
179
|
+
*/
|
|
180
|
+
enum?: Array<number>;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Default value when not provided.
|
|
184
|
+
*
|
|
185
|
+
* The number to use when the LLM omits this parameter.
|
|
186
|
+
*/
|
|
187
|
+
default?: number;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Minimum value (inclusive).
|
|
191
|
+
*
|
|
192
|
+
* The value must be greater than or equal to this number.
|
|
193
|
+
*/
|
|
194
|
+
minimum?: number;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Maximum value (inclusive).
|
|
198
|
+
*
|
|
199
|
+
* The value must be less than or equal to this number.
|
|
200
|
+
*/
|
|
201
|
+
maximum?: number;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Exclusive minimum value.
|
|
205
|
+
*
|
|
206
|
+
* The value must be strictly greater than this number.
|
|
207
|
+
*/
|
|
208
|
+
exclusiveMinimum?: number;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Exclusive maximum value.
|
|
212
|
+
*
|
|
213
|
+
* The value must be strictly less than this number.
|
|
214
|
+
*/
|
|
215
|
+
exclusiveMaximum?: number;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Value must be divisible by this number.
|
|
219
|
+
*
|
|
220
|
+
* Useful for decimal precision constraints like "two decimal places"
|
|
221
|
+
* (multipleOf: 0.01) or currency amounts (multipleOf: 0.01).
|
|
222
|
+
*/
|
|
223
|
+
multipleOf?: number & tags.ExclusiveMinimum<0>;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* String type schema.
|
|
228
|
+
*
|
|
229
|
+
* Represents a JSON Schema string type with format validation, pattern
|
|
230
|
+
* matching, and length constraints. Maps to TypeScript `string` type with
|
|
231
|
+
* optional semantic format annotations.
|
|
232
|
+
*/
|
|
233
|
+
export interface IString extends IJsonSchemaAttribute.IString {
|
|
234
|
+
/**
|
|
235
|
+
* Allowed string values.
|
|
236
|
+
*
|
|
237
|
+
* Restricts the value to specific string literals. Maps directly to
|
|
238
|
+
* TypeScript string literal union types.
|
|
239
|
+
*/
|
|
240
|
+
enum?: Array<string>;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Default value when not provided.
|
|
244
|
+
*
|
|
245
|
+
* The string to use when the LLM omits this parameter.
|
|
246
|
+
*/
|
|
247
|
+
default?: string;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Semantic format specifier.
|
|
251
|
+
*
|
|
252
|
+
* Indicates the string represents a specific format like email, UUID, or
|
|
253
|
+
* date-time. LLMs may use this to generate appropriate values. Common
|
|
254
|
+
* formats include "email", "uri", "uuid", "date-time".
|
|
255
|
+
*/
|
|
256
|
+
format?:
|
|
257
|
+
| "binary"
|
|
258
|
+
| "byte"
|
|
259
|
+
| "password"
|
|
260
|
+
| "regex"
|
|
261
|
+
| "uuid"
|
|
262
|
+
| "email"
|
|
263
|
+
| "hostname"
|
|
264
|
+
| "idn-email"
|
|
265
|
+
| "idn-hostname"
|
|
266
|
+
| "iri"
|
|
267
|
+
| "iri-reference"
|
|
268
|
+
| "ipv4"
|
|
269
|
+
| "ipv6"
|
|
270
|
+
| "uri"
|
|
271
|
+
| "uri-reference"
|
|
272
|
+
| "uri-template"
|
|
273
|
+
| "url"
|
|
274
|
+
| "date-time"
|
|
275
|
+
| "date"
|
|
276
|
+
| "time"
|
|
277
|
+
| "duration"
|
|
278
|
+
| "json-pointer"
|
|
279
|
+
| "relative-json-pointer"
|
|
280
|
+
| (string & {});
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Regular expression pattern for validation.
|
|
284
|
+
*
|
|
285
|
+
* The string must match this regex pattern. Note that LLMs may struggle
|
|
286
|
+
* with complex regex patterns; simple patterns work best.
|
|
287
|
+
*/
|
|
288
|
+
pattern?: string;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* MIME type of the string content.
|
|
292
|
+
*
|
|
293
|
+
* Indicates the content type when the string contains encoded binary data,
|
|
294
|
+
* such as "application/json" or "image/png".
|
|
295
|
+
*/
|
|
296
|
+
contentMediaType?: string;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Minimum string length.
|
|
300
|
+
*
|
|
301
|
+
* The string must have at least this many characters.
|
|
302
|
+
*/
|
|
303
|
+
minLength?: number & tags.Type<"uint64">;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Maximum string length.
|
|
307
|
+
*
|
|
308
|
+
* The string must have at most this many characters.
|
|
309
|
+
*/
|
|
310
|
+
maxLength?: number & tags.Type<"uint64">;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Array type schema.
|
|
315
|
+
*
|
|
316
|
+
* Represents a JSON Schema array type with item type validation and size
|
|
317
|
+
* constraints. Maps to TypeScript `T[]` or `Array<T>` types. Note: Tuple
|
|
318
|
+
* types are not supported by LLM schemas.
|
|
319
|
+
*/
|
|
320
|
+
export interface IArray extends IJsonSchemaAttribute.IArray {
|
|
321
|
+
/**
|
|
322
|
+
* Schema for array elements.
|
|
323
|
+
*
|
|
324
|
+
* All elements in the array must conform to this schema. For heterogeneous
|
|
325
|
+
* arrays, use an `anyOf` schema.
|
|
326
|
+
*/
|
|
327
|
+
items: ILlmSchema;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Whether elements must be unique.
|
|
331
|
+
*
|
|
332
|
+
* When `true`, no two elements may be equal. Maps to TypeScript `Set<T>`
|
|
333
|
+
* semantics but represented as an array.
|
|
334
|
+
*/
|
|
335
|
+
uniqueItems?: boolean;
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Minimum number of elements.
|
|
339
|
+
*
|
|
340
|
+
* The array must contain at least this many items.
|
|
341
|
+
*/
|
|
342
|
+
minItems?: number & tags.Type<"uint64">;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Maximum number of elements.
|
|
346
|
+
*
|
|
347
|
+
* The array must contain at most this many items.
|
|
348
|
+
*/
|
|
349
|
+
maxItems?: number & tags.Type<"uint64">;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Object type schema.
|
|
354
|
+
*
|
|
355
|
+
* Represents a JSON Schema object type with named properties. Maps to
|
|
356
|
+
* TypeScript interface or object type. Supports required property
|
|
357
|
+
* declarations and dynamic additional properties.
|
|
358
|
+
*/
|
|
359
|
+
export interface IObject extends IJsonSchemaAttribute.IObject {
|
|
360
|
+
/**
|
|
361
|
+
* Property name to schema mapping.
|
|
362
|
+
*
|
|
363
|
+
* Defines the type of each named property on the object. All properties are
|
|
364
|
+
* defined here regardless of whether they are required or optional.
|
|
365
|
+
*/
|
|
366
|
+
properties: Record<string, ILlmSchema>;
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Schema for dynamic/additional properties.
|
|
370
|
+
*
|
|
371
|
+
* - `false` (default): No additional properties allowed
|
|
372
|
+
* - `true`: Any additional properties allowed
|
|
373
|
+
* - Schema: Additional properties must match this schema
|
|
374
|
+
*
|
|
375
|
+
* Note: ChatGPT and Gemini do not support `additionalProperties`. Use
|
|
376
|
+
* {@link ILlmSchema.IConfig.strict} mode for OpenAI compatibility.
|
|
377
|
+
*/
|
|
378
|
+
additionalProperties?: ILlmSchema | boolean;
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* List of required property names.
|
|
382
|
+
*
|
|
383
|
+
* Properties in this array must be present in the object. In strict mode,
|
|
384
|
+
* all properties become required automatically.
|
|
385
|
+
*/
|
|
386
|
+
required: string[];
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Reference to a named schema definition.
|
|
391
|
+
*
|
|
392
|
+
* Points to a schema defined in the `$defs` map using a JSON pointer. Used to
|
|
393
|
+
* avoid schema duplication and enable recursive type definitions. The
|
|
394
|
+
* reference path format is `#/$defs/TypeName`.
|
|
395
|
+
*/
|
|
396
|
+
export interface IReference extends IJsonSchemaAttribute {
|
|
397
|
+
/**
|
|
398
|
+
* JSON pointer to the referenced schema.
|
|
399
|
+
*
|
|
400
|
+
* Must be in the format `#/$defs/TypeName` where TypeName is a key in the
|
|
401
|
+
* parent schema's `$defs` map.
|
|
402
|
+
*/
|
|
403
|
+
$ref: string;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Union type schema (A | B | C).
|
|
408
|
+
*
|
|
409
|
+
* Represents a TypeScript union type where the value can match any one of the
|
|
410
|
+
* member schemas. Note: Gemini does not support `anyOf`/`oneOf` schemas. Use
|
|
411
|
+
* discriminated unions with `x-discriminator` when possible for better LLM
|
|
412
|
+
* comprehension.
|
|
413
|
+
*/
|
|
414
|
+
export interface IAnyOf extends IJsonSchemaAttribute {
|
|
415
|
+
/**
|
|
416
|
+
* Array of possible schemas.
|
|
417
|
+
*
|
|
418
|
+
* The value must match at least one of these schemas. Nested `anyOf`
|
|
419
|
+
* schemas are flattened to avoid deep nesting.
|
|
420
|
+
*/
|
|
421
|
+
anyOf: Exclude<ILlmSchema, ILlmSchema.IAnyOf>[];
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Discriminator for tagged/discriminated unions.
|
|
425
|
+
*
|
|
426
|
+
* Helps LLMs understand which variant to select based on a discriminating
|
|
427
|
+
* property value. Improves type inference accuracy.
|
|
428
|
+
*/
|
|
429
|
+
"x-discriminator"?: IAnyOf.IDiscriminator;
|
|
430
|
+
}
|
|
431
|
+
export namespace IAnyOf {
|
|
432
|
+
/**
|
|
433
|
+
* Discriminator configuration for tagged unions.
|
|
434
|
+
*
|
|
435
|
+
* Specifies which property distinguishes between union variants and maps
|
|
436
|
+
* discriminator values to their corresponding schemas.
|
|
437
|
+
*/
|
|
438
|
+
export interface IDiscriminator {
|
|
439
|
+
/**
|
|
440
|
+
* Name of the discriminating property.
|
|
441
|
+
*
|
|
442
|
+
* This property must exist on all union member object schemas and contain
|
|
443
|
+
* unique literal values that identify each variant.
|
|
444
|
+
*/
|
|
445
|
+
propertyName: string;
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Mapping from discriminator values to schema references.
|
|
449
|
+
*
|
|
450
|
+
* Keys are the literal values of the discriminator property, values are
|
|
451
|
+
* `$ref` paths to the corresponding schemas.
|
|
452
|
+
*/
|
|
453
|
+
mapping?: Record<string, string>;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Null type schema.
|
|
459
|
+
*
|
|
460
|
+
* Represents the JSON null value. In TypeScript union types like `T | null`,
|
|
461
|
+
* this schema appears in an `anyOf` alongside the T schema.
|
|
462
|
+
*/
|
|
463
|
+
export interface INull extends IJsonSchemaAttribute.INull {}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Unknown/any type schema.
|
|
467
|
+
*
|
|
468
|
+
* Represents TypeScript `any` or `unknown` types where no specific type
|
|
469
|
+
* constraint is defined. Use sparingly as LLMs may generate unexpected values
|
|
470
|
+
* for unconstrained types.
|
|
471
|
+
*/
|
|
472
|
+
export interface IUnknown extends IJsonSchemaAttribute.IUnknown {}
|
|
473
|
+
}
|