dsh-opencode-go 0.1.21 → 0.1.23

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.
Files changed (60) hide show
  1. package/LICENSE +1 -0
  2. package/README.en.md +74 -194
  3. package/README.md +73 -184
  4. package/THIRD_PARTY_NOTICES.md +7 -1
  5. package/docs/advanced.en.md +137 -0
  6. package/docs/advanced.md +135 -0
  7. package/docs/assets/accounts.png +0 -0
  8. package/docs/assets/advanced-settings.png +0 -0
  9. package/docs/assets/model-settings.png +0 -0
  10. package/docs/assets/usage-panel.png +0 -0
  11. package/docs/development.md +65 -7
  12. package/docs/fork-review-2026-09-25.md +191 -0
  13. package/docs/independent-package.md +2 -2
  14. package/docs/verification.md +283 -0
  15. package/lib/build-info.json +8 -1
  16. package/lib/client.js +830 -635
  17. package/lib/index.js +52687 -856
  18. package/lib/types/account-manager.d.ts +25 -0
  19. package/lib/types/account-operations.d.ts +31 -0
  20. package/lib/types/account-policy.d.ts +16 -0
  21. package/lib/types/account-recovery.d.ts +2 -0
  22. package/lib/types/account-selection.d.ts +30 -0
  23. package/lib/types/account-service.d.ts +12 -0
  24. package/lib/types/accounts-contract.d.ts +38 -0
  25. package/lib/types/accounts.d.ts +8 -1
  26. package/lib/types/adapter.d.ts +33 -11
  27. package/lib/types/call-trace.d.ts +54 -0
  28. package/lib/types/catalog-manager.d.ts +20 -0
  29. package/lib/types/catalog.d.ts +6 -4
  30. package/lib/types/client/accounts-controller.d.ts +8 -17
  31. package/lib/types/client/hint-mark.d.ts +17 -0
  32. package/lib/types/client/host-compat.d.ts +7 -0
  33. package/lib/types/client/host-primitives.d.ts +11 -0
  34. package/lib/types/client/locales.d.ts +14 -3
  35. package/lib/types/client/section-controller.d.ts +11 -48
  36. package/lib/types/client/staged-form.d.ts +1 -3
  37. package/lib/types/client/usage.d.ts +1 -1
  38. package/lib/types/config-contract.d.ts +70 -0
  39. package/lib/types/config.d.ts +13 -54
  40. package/lib/types/conversion/context.d.ts +5 -1
  41. package/lib/types/conversion/image-pool.d.ts +24 -0
  42. package/lib/types/conversion/replay.d.ts +1 -1
  43. package/lib/types/conversion/stream.d.ts +1 -1
  44. package/lib/types/gateway-diagnostics.d.ts +22 -0
  45. package/lib/types/gateway-error.d.ts +2 -0
  46. package/lib/types/gateway-url.d.ts +7 -0
  47. package/lib/types/google-fetch.d.ts +6 -0
  48. package/lib/types/google-generative-ai.d.ts +3 -0
  49. package/lib/types/host-settings.d.ts +11 -0
  50. package/lib/types/index.d.ts +2 -2
  51. package/lib/types/model-metadata.d.ts +5 -3
  52. package/lib/types/models-contract.d.ts +7 -0
  53. package/lib/types/protocol-contract.d.ts +5 -0
  54. package/lib/types/protocol-policy.d.ts +4 -0
  55. package/lib/types/reasoning.d.ts +36 -6
  56. package/lib/types/request-control.d.ts +2 -0
  57. package/lib/types/sdk-types.d.ts +3156 -0
  58. package/lib/types/settings-bridge.d.ts +22 -0
  59. package/lib/vendor-licenses.txt +1861 -0
  60. package/package.json +7 -2
@@ -0,0 +1,3156 @@
1
+ import Anthropic from '@anthropic-ai/sdk';
2
+ import { ResponseCreateParamsStreaming } from 'openai/resources/responses/responses.js';
3
+ import OpenAI from 'openai';
4
+ import { RemoteResult } from '@deepseek-ai/dsh-typert-protocol';
5
+
6
+ interface TSchema {
7
+ }
8
+ interface TSchemaOptions {
9
+ /**
10
+ * Allows for additional, unlisted properties to be included, typically for extensibility.
11
+ */
12
+ [key: PropertyKey]: unknown;
13
+ /**
14
+ * Specifies the URI of a JSON Schema that the current schema adheres to.
15
+ */
16
+ $schema?: string;
17
+ /**
18
+ * A URI that serves as a unique identifier for the schema.
19
+ */
20
+ $id?: string;
21
+ /**
22
+ * A short explanation about the purpose of the data described by the schema.
23
+ */
24
+ title?: string;
25
+ /**
26
+ * A detailed explanation of the data described by the schema.
27
+ */
28
+ description?: string;
29
+ /**
30
+ * A default value for the data, used when no value is provided.
31
+ */
32
+ default?: unknown;
33
+ /**
34
+ * Provides one or more examples of valid data conforming to the schema.
35
+ */
36
+ examples?: unknown;
37
+ /**
38
+ * Indicates that the data should only be readable and not modified.
39
+ */
40
+ readOnly?: boolean;
41
+ /**
42
+ * Indicates that the data should only be writable and not read back.
43
+ */
44
+ writeOnly?: boolean;
45
+ /**
46
+ * A schema to apply conditionally: if the data validates against this schema, 'then' applies.
47
+ */
48
+ if?: TSchema;
49
+ /**
50
+ * A schema to apply if the data validates against the 'if' schema.
51
+ */
52
+ then?: TSchema;
53
+ /**
54
+ * A schema to apply if the data does not validate against the 'if' schema.
55
+ */
56
+ else?: TSchema;
57
+ }
58
+ interface TObjectOptions extends TSchemaOptions {
59
+ /**
60
+ * Defines whether additional properties are allowed beyond those explicitly defined in `properties`.
61
+ */
62
+ additionalProperties?: TSchema | boolean;
63
+ /**
64
+ * The minimum number of properties required in the object.
65
+ */
66
+ minProperties?: number;
67
+ /**
68
+ * The maximum number of properties allowed in the object.
69
+ */
70
+ maxProperties?: number;
71
+ /**
72
+ * Defines conditional requirements for properties.
73
+ */
74
+ dependencies?: Record<string, boolean | TSchema | string[]>;
75
+ /**
76
+ * Specifies properties that *must* be present if a given property is present.
77
+ */
78
+ dependentRequired?: Record<string, string[]>;
79
+ /**
80
+ * Defines schemas that apply if a specific property is present.
81
+ */
82
+ dependentSchemas?: Record<string, TSchema>;
83
+ /**
84
+ * Maps regular expressions to schemas properties matching a pattern must validate against the schema.
85
+ */
86
+ patternProperties?: Record<string, TSchema>;
87
+ /**
88
+ * A schema that all property names within the object must validate against.
89
+ */
90
+ propertyNames?: TSchema;
91
+ }
92
+
93
+ /** Represents a deferred action. */
94
+ interface TDeferred<Action extends string = string, Types extends TSchema[] = TSchema[]> extends TSchema {
95
+ '~kind': 'Deferred';
96
+ type: 'deferred';
97
+ action: Action;
98
+ parameters: Types;
99
+ options: TSchemaOptions;
100
+ }
101
+
102
+ type StaticCodec<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Decoded extends unknown> = (Direction extends 'Decode' ? Decoded : StaticType<Stack, Direction, Context, This, Omit<Type, '~codec'>>);
103
+ type TDecodeCallback<Encoded extends unknown, Decoded = unknown> = (input: Encoded) => Decoded;
104
+ type TEncodeCallback<Encoded extends unknown, Decoded = unknown> = (input: Decoded) => Encoded;
105
+ type TCodec<Type extends TSchema = TSchema, Decoded extends unknown = unknown> = Type & {
106
+ '~codec': {
107
+ encode: TDecodeCallback<unknown, Decoded>;
108
+ decode: TEncodeCallback<unknown, Decoded>;
109
+ };
110
+ };
111
+
112
+ type StaticAny = any;
113
+ /** Represents a Any type. */
114
+ interface TAny extends TSchema {
115
+ '~kind': 'Any';
116
+ }
117
+
118
+ type TImmutable<Type extends TSchema = TSchema> = (Type & {
119
+ '~immutable': true;
120
+ });
121
+
122
+ type StaticArray<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Array extends TSchema, Item extends TSchema, Result extends readonly unknown[] = Array extends TImmutable ? readonly StaticType<Stack, Direction, Context, This, Item>[] : StaticType<Stack, Direction, Context, This, Item>[]> = Result;
123
+ /** Represents an Array type. */
124
+ interface TArray<Type extends TSchema = TSchema> extends TSchema {
125
+ '~kind': 'Array';
126
+ type: 'array';
127
+ items: Type;
128
+ }
129
+
130
+ declare const BigIntPattern = "-?(?:0|[1-9][0-9]*)n";
131
+ type StaticBigInt = bigint;
132
+ /** Represents a BigInt type. */
133
+ interface TBigInt extends TSchema {
134
+ '~kind': 'BigInt';
135
+ type: 'bigint';
136
+ }
137
+
138
+ type StaticBoolean = boolean;
139
+ /** Represents a Boolean type. */
140
+ interface TBoolean extends TSchema {
141
+ '~kind': 'Boolean';
142
+ type: 'boolean';
143
+ }
144
+
145
+ /** Applies an AddReadonly action to a type. */
146
+ type TAddReadonly<Type extends TSchema> = (TAddReadonlyAction<Type>);
147
+
148
+ type TReadonly<Type extends TSchema = TSchema> = (Type & {
149
+ '~readonly': true;
150
+ });
151
+
152
+ type TAddReadonlyOperation<Type extends TSchema, Result extends TSchema = `~readonly` extends keyof Type ? Type : TReadonly<Type>> = Result;
153
+ type TAddReadonlyAction<Type extends TSchema, Result extends TSchema = TAddReadonlyOperation<Type>> = Result;
154
+ type TAddReadonlyInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TAddReadonlyAction<InstantiateType>;
155
+
156
+ type StaticUnknown = unknown;
157
+ /** Represents an Unknown type. */
158
+ interface TUnknown extends TSchema {
159
+ '~kind': 'Unknown';
160
+ }
161
+
162
+ /** Represents a Generic parameter. */
163
+ interface TParameter<Name extends string = string, Extends extends TSchema = TSchema, Equals extends TSchema = TSchema> extends TSchema {
164
+ '~kind': 'Parameter';
165
+ name: Name;
166
+ extends: Extends;
167
+ equals: Equals;
168
+ }
169
+
170
+ type StaticObject<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, _This extends TProperties, Properties extends TProperties, Result = keyof Properties extends never ? object : StaticProperties<Stack, Direction, Context, Properties, Properties>> = Result;
171
+ /** Represents an Object type. */
172
+ interface TObject<Properties extends TProperties = TProperties> extends TSchema {
173
+ '~kind': 'Object';
174
+ type: 'object';
175
+ properties: Properties;
176
+ required: TRequiredArray<Properties>;
177
+ }
178
+
179
+ type CyclicStackLength<Stack extends unknown[], MaxLength extends number, Buffer extends unknown[] = []> = (Stack extends [infer Left, ...infer Right] ? Buffer['length'] extends MaxLength ? false : CyclicStackLength<Right, MaxLength, [...Buffer, Left]> : true);
180
+ type CyclicGuard<Stack extends unknown[], Ref extends string> = (Ref extends Stack[number] ? CyclicStackLength<Stack, 2> : true);
181
+ type StaticGuardedRef<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Ref extends string, Type extends TSchema> = (CyclicGuard<Stack, Ref> extends true ? StaticType<[...Stack, Ref], Direction, Context, This, Type> : any);
182
+ type StaticRef<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Ref extends string, Target extends TSchema = Ref extends keyof Context ? Context[Ref] : TUnknown, Result extends unknown = Target extends TObject ? StaticType<[], Direction, Context, This, Target> : StaticGuardedRef<Stack, Direction, Context, This, Ref, Target>> = Result;
183
+ /** Represents a type reference. */
184
+ interface TRef<Ref extends string = string> extends TSchema {
185
+ '~kind': 'Ref';
186
+ $ref: Ref;
187
+ }
188
+
189
+ /** Represents a callable Generic type. */
190
+ interface TGeneric<Parameters extends TParameter[] = TParameter[], Expression extends TSchema = TSchema> extends TSchema {
191
+ '~kind': 'Generic';
192
+ type: 'generic';
193
+ parameters: Parameters;
194
+ expression: Expression;
195
+ }
196
+
197
+ declare const NeverPattern = "(?!)";
198
+ type StaticNever = never;
199
+ /** Represents a Never type. */
200
+ interface TNever extends TSchema {
201
+ '~kind': 'Never';
202
+ not: {};
203
+ }
204
+
205
+ type StaticCyclic<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Defs extends TProperties, Ref extends string, Result extends unknown = (Ref extends keyof Defs ? StaticType<[...Stack, Ref], Direction, Defs, This, Defs[Ref]> : never)> = Result;
206
+ /** Represents a Cyclic type. */
207
+ interface TCyclic<Defs extends TProperties = TProperties, Ref extends string = string> extends TSchema {
208
+ '~kind': 'Cyclic';
209
+ $defs: Defs;
210
+ $ref: Ref;
211
+ }
212
+
213
+ type TUnionToIntersect<U> = (U extends unknown ? (arg: U) => 0 : never) extends (arg: infer I) => 0 ? I : never;
214
+ type TUnionLast<U> = TUnionToIntersect<U extends unknown ? (x: U) => 0 : never> extends (x: infer L) => 0 ? L : never;
215
+ type TUnionToTuple<U, Result extends unknown[] = [], R = TUnionLast<U>> = [U] extends [never] ? Result : TUnionToTuple<Exclude<U, R>, [Extract<U, R>, ...Result]>;
216
+
217
+ type StaticEnum<Values extends TEnumValue[]> = (Values[number]);
218
+ type TEnumValue = string | number;
219
+ /** Represents an Enum type. */
220
+ interface TEnum<Values extends TEnumValue[] = TEnumValue[]> extends TSchema {
221
+ '~kind': 'Enum';
222
+ enum: Values;
223
+ }
224
+
225
+ /** Represents a Identifier. */
226
+ interface TIdentifier<Name extends string = string> extends TSchema {
227
+ '~kind': 'Identifier';
228
+ type: 'identifier';
229
+ name: Name;
230
+ }
231
+
232
+ type StaticDependent<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, If extends TSchema, Then extends TSchema, Else extends TSchema, StaticIf extends unknown = StaticType<Stack, Direction, Context, This, If>, StaticThen extends unknown = StaticType<Stack, Direction, Context, This, Then>, StaticElse extends unknown = StaticType<Stack, Direction, Context, This, Else>, Result extends unknown = (StaticIf & StaticThen) | Exclude<StaticElse, StaticIf>> = Result;
233
+ /** Represents a Dependent Type */
234
+ interface TDependent<If extends TSchema = TSchema, Then extends TSchema = TSchema, Else extends TSchema = TSchema> extends TSchema {
235
+ '~kind': 'Dependent';
236
+ if: If;
237
+ then: Then;
238
+ else: Else;
239
+ }
240
+
241
+ /** Represents an Infer instruction. */
242
+ interface TInfer<Name extends string = string, Extends extends TSchema = TSchema> extends TSchema {
243
+ '~kind': 'Infer';
244
+ type: 'infer';
245
+ name: Name;
246
+ extends: Extends;
247
+ }
248
+
249
+ declare const IntegerPattern = "-?(?:0|[1-9][0-9]*)";
250
+ type StaticInteger = number;
251
+ /** Represents an integer type. */
252
+ interface TInteger extends TSchema {
253
+ '~kind': 'Integer';
254
+ type: 'integer';
255
+ }
256
+
257
+ type StaticIntersect<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Types extends TSchema[], Result extends unknown = unknown> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? StaticIntersect<Stack, Direction, Context, This, Right, Result & StaticType<Stack, Direction, Context, This, Left>> : Result);
258
+ /** Represents a logical Intersect type. */
259
+ interface TIntersect<Types extends TSchema[] = TSchema[]> extends TSchema {
260
+ '~kind': 'Intersect';
261
+ allOf: Types;
262
+ }
263
+
264
+ type StaticLiteral<Value extends TLiteralValue> = (Value);
265
+ type TLiteralTypeName<Value extends TLiteralValue> = (Value extends bigint ? 'bigint' : Value extends boolean ? 'boolean' : Value extends number ? 'number' : Value extends string ? 'string' : never);
266
+ type TLiteralValue = string | number | boolean | bigint;
267
+ /** Represents a Literal type. */
268
+ interface TLiteral<Value extends TLiteralValue = TLiteralValue> extends TSchema {
269
+ '~kind': 'Literal';
270
+ type: TLiteralTypeName<Value>;
271
+ const: Value;
272
+ }
273
+
274
+ type StaticNull = null;
275
+ /** Represents a Null type. */
276
+ interface TNull extends TSchema {
277
+ '~kind': 'Null';
278
+ type: 'null';
279
+ }
280
+
281
+ declare const NumberPattern = "-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?";
282
+ type StaticNumber = number;
283
+ /** Represents a Number type. */
284
+ interface TNumber extends TSchema {
285
+ '~kind': 'Number';
286
+ type: 'number';
287
+ }
288
+
289
+ type StaticSymbol = symbol;
290
+ /** Represents a Symbol type. */
291
+ interface TSymbol extends TSchema {
292
+ '~kind': 'Symbol';
293
+ type: 'symbol';
294
+ }
295
+
296
+ declare const StringPattern = ".*";
297
+ type StaticString = string;
298
+ /** Represents a String type. */
299
+ interface TString extends TSchema {
300
+ '~kind': 'String';
301
+ type: 'string';
302
+ }
303
+
304
+ type TUnreachable = never;
305
+
306
+ type ObjectLike = Record<PropertyKey, any>;
307
+ /**
308
+ * Performs an Object assign using the Left and Right object types. We track this operation as it
309
+ * creates a new GC handle per assignment.
310
+ */
311
+ type TAssign<Left extends ObjectLike, Right extends ObjectLike, Assigned extends ObjectLike = Omit<Left, keyof Right> & Right> = {
312
+ [Key in keyof Assigned]: Assigned[Key];
313
+ } & {};
314
+
315
+ type TPatternBigIntMapping<Input extends '-?(?:0|[1-9][0-9]*)n'> = (TBigInt);
316
+ type TPatternStringMapping<Input extends '.*'> = (TString);
317
+ type TPatternNumberMapping<Input extends '-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?'> = (TNumber);
318
+ type TPatternIntegerMapping<Input extends '-?(?:0|[1-9][0-9]*)'> = (TInteger);
319
+ type TPatternNeverMapping<Input extends '(?!)'> = (TNever);
320
+ type TPatternTextMapping<Input extends string, Result extends TSchema = TLiteral<Input>> = Result;
321
+ type TPatternBaseMapping<Input extends unknown> = (Input);
322
+ type TPatternGroupMapping<Input extends [unknown, unknown, unknown]> = (Input extends ['(', infer Body extends TSchema[], ')'] ? TUnion<Body> : never);
323
+ type TPatternUnionMapping<Input extends [unknown, unknown, unknown] | [unknown] | []> = (Input extends [infer Term extends TSchema[], '|', infer Union extends TSchema[]] ? [...Term, ...Union] : Input extends [infer Term extends TSchema[]] ? [...Term] : [
324
+ ]);
325
+ type TPatternTermMapping<Input extends [unknown, unknown]> = (Input extends [infer Left extends TSchema, infer Right extends TSchema[]] ? [Left, ...Right] : never);
326
+ type TPatternBodyMapping<Input extends unknown> = (Input);
327
+ type TPatternMapping<Input extends [unknown, unknown, unknown]> = (Input extends ['^', infer Body extends TSchema[], '$'] ? Body : never);
328
+
329
+ type TTakeVariant<Variant extends string, Input extends string> = (Input extends `${Variant}${infer Rest extends string}` ? [Variant, Rest] : []);
330
+ /** Takes one of the given variants or fail */
331
+ type TTake<Variants extends string[], Input extends string> = (Variants extends [infer ValueLeft extends string, ...infer ValueRight extends string[]] ? TTakeVariant<ValueLeft, Input> extends [infer Take extends string, infer Rest extends string] ? [Take, Rest] : TTake<ValueRight, Input> : []);
332
+
333
+ declare const WhiteSpace = " ";
334
+ declare const NewLine = "\n";
335
+ declare const TabSpace = "\t";
336
+ type TWhiteSpace = typeof WhiteSpace;
337
+ type TNewLine = typeof NewLine;
338
+ type TTabSpace = typeof TabSpace;
339
+
340
+ type LineComment = typeof LineComment;
341
+ declare const LineComment = "//";
342
+ type OpenComment = typeof OpenComment;
343
+ declare const OpenComment = "/*";
344
+ type CloseComment = typeof CloseComment;
345
+ declare const CloseComment = "*/";
346
+ type TDiscardMultiLineComment<Input extends string> = (Input extends `${string}${CloseComment}${infer Rest extends string}` ? Rest : '');
347
+ type TDiscardLineComment<Input extends string> = (Input extends `${string}${TNewLine}${infer Rest extends string}` ? TTrimWhitespace<`${TNewLine}${Rest}`> : '');
348
+ type W4 = `${W3}${W3}`;
349
+ type W3 = `${W2}${W2}`;
350
+ type W2 = `${W1}${W1}`;
351
+ type W1 = `${W0}${W0}`;
352
+ type W0 = ` `;
353
+ type TTrimWhitespace<Input extends string> = (Input extends `${OpenComment}${infer Rest extends string}` ? TTrimWhitespace<TDiscardMultiLineComment<Rest>> : Input extends `${LineComment}${infer Rest extends string}` ? TTrimWhitespace<TDiscardLineComment<Rest>> : Input extends `${W4}${infer Rest extends string}` ? TTrimWhitespace<Rest> : Input extends `${W3}${infer Rest extends string}` ? TTrimWhitespace<Rest> : Input extends `${W1}${infer Rest extends string}` ? TTrimWhitespace<Rest> : Input extends `${W0}${infer Rest extends string}` ? TTrimWhitespace<Rest> : Input);
354
+ type TTrim<Input extends string> = (Input extends `${OpenComment}${infer Rest extends string}` ? TTrim<TDiscardMultiLineComment<Rest>> : Input extends `${LineComment}${infer Rest extends string}` ? TTrim<TDiscardLineComment<Rest>> : Input extends `${TNewLine}${infer Rest extends string}` ? TTrim<Rest> : Input extends `${TTabSpace}${infer Rest extends string}` ? TTrim<Rest> : Input extends `${W4}${infer Rest extends string}` ? TTrim<Rest> : Input extends `${W3}${infer Rest extends string}` ? TTrim<Rest> : Input extends `${W1}${infer Rest extends string}` ? TTrim<Rest> : Input extends `${W0}${infer Rest extends string}` ? TTrim<Rest> : Input);
355
+
356
+ type TTakeConst<Const extends string, Input extends string> = (TTake<[Const], Input>);
357
+ /** Matches if next is the given Const value */
358
+ type TConst<Const extends string, Input extends string> = (Const extends '' ? ['', Input] : Const extends `${infer First extends string}${string}` ? (First extends TNewLine ? TTakeConst<Const, TTrimWhitespace<Input>> : First extends TWhiteSpace ? TTakeConst<Const, Input> : TTakeConst<Const, TTrim<Input>>) : never);
359
+
360
+ type TTakeOne<Input extends string> = (Input extends `${infer Left extends string}${infer Right extends string}` ? [Left, Right] : []);
361
+ type TIsInputMatchSentinal<End extends string[], Input extends string> = (End extends [infer Left extends string, ...infer Right extends string[]] ? Input extends `${Left}${string}` ? true : TIsInputMatchSentinal<Right, Input> : false);
362
+ /** Match Input until but not including End. No match if End not found. */
363
+ type TUntil<End extends string[], Input extends string, Result extends string = ''> = (TTakeOne<Input> extends [infer One extends string, infer Rest extends string] ? TIsInputMatchSentinal<End, Input> extends true ? [Result, Input] : TUntil<End, Rest, `${Result}${One}`> : []);
364
+
365
+ /** Match Input until but not including End. No match if End not found or match is zero-length. */
366
+ type TUntil_1<End extends string[], Input extends string> = (TUntil<End, Input> extends [infer Until extends string, infer UntilRest extends string] ? Until extends '' ? [] : [Until, UntilRest] : []);
367
+
368
+ type TPatternBigInt<Input extends string> = TConst<'-?(?:0|[1-9][0-9]*)n', Input> extends [infer _0 extends '-?(?:0|[1-9][0-9]*)n', infer Input extends string] ? [TPatternBigIntMapping<_0>, Input] : [];
369
+ type TPatternString<Input extends string> = TConst<'.*', Input> extends [infer _0 extends '.*', infer Input extends string] ? [TPatternStringMapping<_0>, Input] : [];
370
+ type TPatternNumber<Input extends string> = TConst<'-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?', Input> extends [infer _0 extends '-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?', infer Input extends string] ? [TPatternNumberMapping<_0>, Input] : [];
371
+ type TPatternInteger<Input extends string> = TConst<'-?(?:0|[1-9][0-9]*)', Input> extends [infer _0 extends '-?(?:0|[1-9][0-9]*)', infer Input extends string] ? [TPatternIntegerMapping<_0>, Input] : [];
372
+ type TPatternNever<Input extends string> = TConst<'(?!)', Input> extends [infer _0 extends '(?!)', infer Input extends string] ? [TPatternNeverMapping<_0>, Input] : [];
373
+ type TPatternText<Input extends string> = TUntil_1<['-?(?:0|[1-9][0-9]*)n', '.*', '-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?', '-?(?:0|[1-9][0-9]*)', '(?!)', '(', ')', '$', '|'], Input> extends [infer _0 extends string, infer Input extends string] ? [TPatternTextMapping<_0>, Input] : [];
374
+ type TPatternBase<Input extends string> = (TPatternBigInt<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TPatternString<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TPatternNumber<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TPatternInteger<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TPatternNever<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TPatternGroup<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TPatternText<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _0 extends unknown, infer Input extends string] ? [TPatternBaseMapping<_0>, Input] : [];
375
+ type TPatternGroup<Input extends string> = (TConst<'(', Input> extends [infer _0, infer Input extends string] ? (TPatternBody<Input> extends [infer _1, infer Input extends string] ? (TConst<')', Input> extends [infer _2, infer Input extends string] ? [[_0, _1, _2], Input] : []) : []) : []) extends [infer _0 extends [unknown, unknown, unknown], infer Input extends string] ? [TPatternGroupMapping<_0>, Input] : [];
376
+ type TPatternUnion<Input extends string> = ((TPatternTerm<Input> extends [infer _0, infer Input extends string] ? (TConst<'|', Input> extends [infer _1, infer Input extends string] ? (TPatternUnion<Input> extends [infer _2, infer Input extends string] ? [[_0, _1, _2], Input] : []) : []) : []) extends [infer _0, infer Input extends string] ? [_0, Input] : (TPatternTerm<Input> extends [infer _0, infer Input extends string] ? [[_0], Input] : []) extends [infer _0, infer Input extends string] ? [_0, Input] : [[], Input] extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _0 extends [unknown, unknown, unknown] | [unknown] | [], infer Input extends string] ? [TPatternUnionMapping<_0>, Input] : [];
377
+ type TPatternTerm<Input extends string> = (TPatternBase<Input> extends [infer _0, infer Input extends string] ? (TPatternBody<Input> extends [infer _1, infer Input extends string] ? [[_0, _1], Input] : []) : []) extends [infer _0 extends [unknown, unknown], infer Input extends string] ? [TPatternTermMapping<_0>, Input] : [];
378
+ type TPatternBody<Input extends string> = (TPatternUnion<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : TPatternTerm<Input> extends [infer _0, infer Input extends string] ? [_0, Input] : []) extends [infer _0 extends unknown, infer Input extends string] ? [TPatternBodyMapping<_0>, Input] : [];
379
+ type TPattern<Input extends string> = (TConst<'^', Input> extends [infer _0, infer Input extends string] ? (TPatternBody<Input> extends [infer _1, infer Input extends string] ? (TConst<'$', Input> extends [infer _2, infer Input extends string] ? [[_0, _1, _2], Input] : []) : []) : []) extends [infer _0 extends [unknown, unknown, unknown], infer Input extends string] ? [TPatternMapping<_0>, Input] : [];
380
+
381
+ type StaticUnion<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Types extends TSchema[], Result extends unknown = never> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? StaticUnion<Stack, Direction, Context, This, Right, Result | StaticType<Stack, Direction, Context, This, Left>> : Result);
382
+ /** Represents a logical Union type. */
383
+ interface TUnion<Types extends TSchema[] = TSchema[]> extends TSchema {
384
+ '~kind': 'Union';
385
+ anyOf: Types;
386
+ }
387
+
388
+ /** Parses a Pattern into a sequence of TemplateLiteral types. A result of [] indicates failure to parse. */
389
+ type TParsePatternIntoTypes<Pattern extends string, Parsed extends [TSchema[], string] | [] = TPattern<Pattern>, Result extends TSchema[] = Parsed extends [infer Types extends TSchema[], string] ? Types : []> = Result;
390
+
391
+ type TFromLiteral$5<Template extends string, Value extends TLiteralValue> = `${Template}${Value}`;
392
+ type TFromBigInt<Template extends string> = `${Template}${bigint}`;
393
+ type TFromString<Template extends string> = `${Template}${string}`;
394
+ type TFromNumber<Template extends string> = `${Template}${number}`;
395
+ type TFromInteger<Template extends string> = `${Template}${number}`;
396
+ type TFromUnion$8<Template extends string, Types extends TSchema[], Result extends string = never> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromUnion$8<Template, Right, Result | TFromType$i<'', Left>> : `${Template}${Result}`);
397
+ type TFromType$i<Template extends string, Type extends TSchema, Result extends string = (Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion$8<Template, Types> : Type extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteral$5<Template, Value> : Type extends TBigInt ? TFromBigInt<Template> : Type extends TString ? TFromString<Template> : Type extends TNumber ? TFromNumber<Template> : Type extends TInteger ? TFromInteger<Template> : never)> = Result;
398
+ type TFromSpan<Template extends string, Types extends TSchema[]> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromSpan<TFromType$i<Template, Left>, Right> : Template);
399
+ type TTemplateLiteralStatic<Pattern extends string, Types extends TSchema[] = TParsePatternIntoTypes<Pattern>> = TFromSpan<'', Types>;
400
+
401
+ type TRemoveReadonlyOperation<Type extends TSchema, Result extends TSchema = Type extends TReadonly<infer Type extends TSchema> ? TRemoveReadonlyOperation<Type> : Type> = Result;
402
+ type TRemoveReadonlyAction<Type extends TSchema, Result extends TSchema = TRemoveReadonlyOperation<Type>> = Result;
403
+ type TRemoveReadonlyInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TRemoveReadonlyAction<InstantiateType>;
404
+
405
+ /** Applies an RemoveReadonly action to a type. */
406
+ type TRemoveReadonly<Type extends TSchema> = (TRemoveReadonlyAction<Type>);
407
+
408
+ type TRemoveOptionalOperation<Type extends TSchema, Result extends TSchema = Type extends TOptional<infer Type extends TSchema> ? TRemoveOptionalOperation<Type> : Type> = Result;
409
+ type TRemoveOptionalAction<Type extends TSchema, Result extends TSchema = TRemoveOptionalOperation<Type>> = Result;
410
+ type TRemoveOptionalInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TRemoveOptionalAction<InstantiateType>;
411
+
412
+ /** Applies an RemoveOptional action to a type. */
413
+ type TRemoveOptional<Type extends TSchema> = (TRemoveOptionalAction<Type>);
414
+
415
+ type TTupleElementsToProperties<Types extends TSchema[], Result extends TProperties = {}> = (Types extends [...infer Left extends TSchema[], infer Right extends TSchema] ? TTupleElementsToProperties<Left, {
416
+ [_ in Left['length']]: Right;
417
+ } & Result> : {
418
+ [Key in keyof Result]: Result[Key];
419
+ });
420
+ type TTupleToObject<Type extends TTuple, Properties extends TProperties = TTupleElementsToProperties<Type['items']>, Result extends TSchema = TObject<Properties>> = Result;
421
+
422
+ /** Returns true if the type is a valid operand to Composite. */
423
+ type TCanComposite<Type extends TSchema> = (Type extends TObject<infer _ extends TProperties> ? true : Type extends TTuple<infer _ extends TSchema[]> ? true : false);
424
+ type TIsReadonlyProperty<Left extends TSchema, Right extends TSchema> = (Left extends TReadonly<Left> ? Right extends TReadonly<Right> ? true : false : false);
425
+ type TIsOptionalProperty<Left extends TSchema, Right extends TSchema> = (Left extends TOptional<Left> ? Right extends TOptional<Right> ? true : false : false);
426
+ type TCompositeProperty<Left extends TSchema, Right extends TSchema, IsReadonly extends boolean = TIsReadonlyProperty<Left, Right>, IsOptional extends boolean = TIsOptionalProperty<Left, Right>, Evaluated extends TSchema = TEvaluateIntersect<[Left, Right]>, Property extends TSchema = TRemoveReadonly<TRemoveOptional<Evaluated>>> = ([
427
+ IsReadonly,
428
+ IsOptional
429
+ ] extends [true, true] ? TAddReadonly<TAddOptional<Property>> : [
430
+ IsReadonly,
431
+ IsOptional
432
+ ] extends [true, false] ? TAddReadonly<Property> : [
433
+ IsReadonly,
434
+ IsOptional
435
+ ] extends [false, true] ? TAddOptional<Property> : Property);
436
+ type TCompositePropertyKey<Left extends TProperties, Right extends TProperties, Key extends PropertyKey, Result extends TSchema = (Key extends keyof Left ? Key extends keyof Right ? TCompositeProperty<Left[Key], Right[Key]> : Left[Key] : Key extends keyof Right ? Right[Key] : TNever)> = Result;
437
+ type TCompositeProperties<Left extends TProperties, Right extends TProperties, Keys extends PropertyKey = keyof (Left & Right), Result extends TProperties = {
438
+ [Key in Keys]: TCompositePropertyKey<Left, Right, Key>;
439
+ }> = Result;
440
+ type TGetProperties<Type extends TSchema, Result extends TProperties = (Type extends TObject<infer Properties extends TProperties> ? Properties : Type extends TTuple<infer Types extends TSchema[]> ? TTupleElementsToProperties<Types> : {})> = Result;
441
+ type TComposite<Left extends TSchema, Right extends TSchema, LeftProperties extends TProperties = TGetProperties<Left>, RightProperties extends TProperties = TGetProperties<Right>, Properties extends TProperties = TCompositeProperties<LeftProperties, RightProperties>, Result extends TSchema = TObject<Properties>> = Result;
442
+
443
+ type TNarrowCompareRule<Left extends TSchema, Right extends TSchema, Result extends TCompareResult = TCompare<Left, Right>> = (Result extends typeof CompareResultLeftInside ? Left : Result extends typeof CompareResultRightInside ? Right : Result extends typeof CompareResultEqual ? Right : TNever);
444
+ type TNarrowCompositeRule<Left extends TSchema, Right extends TSchema, CanCompositeLeft extends boolean = TCanComposite<Left>, CanCompositeRight extends boolean = TCanComposite<Right>> = ([
445
+ CanCompositeLeft,
446
+ CanCompositeRight
447
+ ] extends [true, true] ? TComposite<Left, Right> : [
448
+ CanCompositeLeft,
449
+ CanCompositeRight
450
+ ] extends [true, false] ? Left : [
451
+ CanCompositeLeft,
452
+ CanCompositeRight
453
+ ] extends [false, true] ? Right : TNarrowCompareRule<Left, Right>);
454
+ type TNarrow<Left extends TSchema, Right extends TSchema> = (Left extends TNever ? TNever : Left extends TAny ? TAny : Left extends TUnknown ? Right : Right extends TNever ? TNever : Right extends TAny ? TAny : Right extends TUnknown ? Left : TNarrowCompositeRule<Left, Right>);
455
+
456
+ type TShouldEvaluate<Left extends TSchema, Right extends TSchema, IsUnionLeft extends boolean = Left extends TUnion ? true : false, IsUnionRight extends boolean = Right extends TUnion ? true : false, Result extends boolean = IsUnionLeft extends true ? true : IsUnionRight extends true ? true : false> = Result;
457
+ type TDistributeOperation<Left extends TSchema, Right extends TSchema, EvaluatedLeft extends TSchema = TEvaluateType<Left>, EvaluatedRight extends TSchema = TEvaluateType<Right>, ShouldEvaluate extends boolean = TShouldEvaluate<EvaluatedLeft, EvaluatedRight>, Result extends TSchema = [ShouldEvaluate] extends [true] ? TEvaluateIntersect<[EvaluatedLeft, EvaluatedRight]> : TNarrow<EvaluatedLeft, EvaluatedRight>> = Result;
458
+ type TDistributeType<Type extends TSchema, Distribution extends TSchema[], Result extends TSchema[] = []> = (Distribution extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TDistributeType<Type, Right, [...Result, TDistributeOperation<Left, Type>]> : Result extends [] ? [Type] : Result);
459
+ type TDistributeUnion<Types extends TSchema[], Distribution extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TDistributeUnion<Right, Distribution, [...Result, ...TDistribute$1<[Left], Distribution>]> : Result);
460
+ type TDistribute$1<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TUnion<infer UnionTypes extends TSchema[]> ? TDistribute$1<Right, TDistributeUnion<UnionTypes, Result>> : TDistribute$1<Right, TDistributeType<Left, Result>> : Result);
461
+
462
+ type StaticUnsafe<Type extends unknown> = Type;
463
+ /** Represents an Unsafe type. */
464
+ interface TUnsafe<Type extends unknown = unknown> extends TSchema {
465
+ '~unsafe': Type;
466
+ }
467
+
468
+ type TResult = TExtendsUnion$1 | TExtendsTrue | TExtendsFalse;
469
+ interface TExtendsUnion$1<Inferred extends TProperties = TProperties> {
470
+ '~kind': 'ExtendsUnion';
471
+ inferred: Inferred;
472
+ }
473
+ interface TExtendsTrue<Inferred extends TProperties = TProperties> {
474
+ '~kind': 'ExtendsTrue';
475
+ inferred: Inferred;
476
+ }
477
+ interface TExtendsFalse {
478
+ type: 'ExtendsFalse';
479
+ }
480
+ type TExtendsTrueLike<Inferred extends TProperties = TProperties> = TExtendsUnion$1<Inferred> | TExtendsTrue<Inferred>;
481
+
482
+ type TExtendsRightInfer<Inferred extends TProperties, Name extends string, Left extends TSchema, Right extends TSchema, Result extends TResult = (TExtendsLeft<Inferred, Left, Right> extends TExtendsTrueLike<infer CheckInferred extends TProperties> ? TExtendsTrue<TAssign<TAssign<Inferred, CheckInferred>, {
483
+ [_ in Name]: Left;
484
+ }>> : TExtendsFalse)> = Result;
485
+ type TExtendsRightAny<Inferred extends TProperties, _Left extends TSchema, Result extends TResult = TExtendsTrue<Inferred>> = Result;
486
+ type TExtendsRightDependent<Inferred extends TProperties, Left extends TSchema, If extends TSchema, Then extends TSchema, Else extends TSchema, Result extends TResult = TExtendsLeft<Inferred, Left, If> extends TExtendsTrueLike<infer Inferred extends TProperties> ? (TExtendsLeft<Inferred, Left, Then> extends TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsTrue<Inferred> : TExtendsFalse) : (TExtendsLeft<Inferred, Left, Else> extends TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsTrue<Inferred> : TExtendsFalse)> = Result;
487
+ type TExtendsRightEnum<Inferred extends TProperties, Left extends TSchema, Right extends TEnumValue[], Evaluated extends TSchema = TEvaluateEnum<Right>> = TExtendsLeft<Inferred, Left, Evaluated>;
488
+ type TExtendsRightIntersect<Inferred extends TProperties, Left extends TSchema, Right extends TSchema[]> = (Right extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExtendsLeft<Inferred, Left, Head> extends TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsRightIntersect<Inferred, Left, Tail> : TExtendsFalse : TExtendsTrue<Inferred>);
489
+ type TExtendsRightTemplateLiteral<Inferred extends TProperties, Left extends TSchema, Right extends string, Evaluated extends TSchema = TEvaluateTemplateLiteral<Right>> = TExtendsLeft<Inferred, Left, Evaluated>;
490
+ type TExtendsRightUnion<Inferred extends TProperties, Left extends TSchema, Right extends TSchema[]> = (Right extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExtendsLeft<Inferred, Left, Head> extends TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsTrue<Inferred> : TExtendsRightUnion<Inferred, Left, Tail> : TExtendsFalse);
491
+ type TExtendsRight<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Right extends TAny ? TExtendsRightAny<Inferred, Left> : Right extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TExtendsRightDependent<Inferred, Left, If, Then, Else> : Right extends TEnum<infer Values extends TEnumValue[]> ? TExtendsRightEnum<Inferred, Left, Values> : Right extends TInfer<infer Name extends string, infer Type extends TSchema> ? TExtendsRightInfer<Inferred, Name, Left, Type> : Right extends TTemplateLiteral<infer Pattern extends string> ? TExtendsRightTemplateLiteral<Inferred, Left, Pattern> : Right extends TIntersect<infer Types extends TSchema[]> ? TExtendsRightIntersect<Inferred, Left, Types> : Right extends TUnion<infer Types extends TSchema[]> ? TExtendsRightUnion<Inferred, Left, Types> : Right extends TUnknown ? TExtendsTrue<Inferred> : TExtendsFalse);
492
+
493
+ type TExtendsAny<Inferred extends TProperties, Left extends TAny, Right extends TSchema> = (Right extends TInfer ? TExtendsRight<Inferred, Left, Right> : Right extends TAny ? TExtendsTrue<Inferred> : Right extends TUnknown ? TExtendsTrue<Inferred> : TExtendsUnion$1<Inferred>);
494
+
495
+ type TExtendsImmutable<Left extends TSchema, Right extends TSchema, IsImmutableLeft extends boolean = Left extends TImmutable ? true : false, IsImmutableRight extends boolean = Right extends TImmutable ? true : false, Result extends boolean = [
496
+ IsImmutableLeft,
497
+ IsImmutableRight
498
+ ] extends [true, true] ? true : [
499
+ IsImmutableLeft,
500
+ IsImmutableRight
501
+ ] extends [false, true] ? true : [
502
+ IsImmutableLeft,
503
+ IsImmutableRight
504
+ ] extends [true, false] ? false : true> = Result;
505
+ type TExtendsArray<Inferred extends TProperties, ArrayLeft extends TSchema, Left extends TSchema, Right extends TSchema> = (Right extends TArray<infer Type extends TSchema> ? TExtendsImmutable<ArrayLeft, Right> extends true ? TExtendsLeft<Inferred, Left, Type> : TExtendsFalse : TExtendsRight<Inferred, ArrayLeft, Right>);
506
+
507
+ type TExtendsBigInt<Inferred extends TProperties, Left extends TBigInt, Right extends TSchema> = (Right extends TBigInt ? TExtendsTrue<Inferred> : TExtendsRight<Inferred, Left, Right>);
508
+
509
+ type TExtendsBoolean<Inferred extends TProperties, Left extends TBoolean, Right extends TSchema> = (Right extends TBoolean ? TExtendsTrue<Inferred> : TExtendsRight<Inferred, Left, Right>);
510
+
511
+ type TParameterCompare<Inferred extends TProperties, Left extends TSchema, LeftRest extends TSchema[], Right extends TSchema, RightRest extends TSchema[], CheckLeft extends TSchema = Right extends TInfer ? Left : Right, CheckRight extends TSchema = Right extends TInfer ? Right : Left, IsLeftOptional extends boolean = Left extends TOptional ? true : false, IsRightOptional extends boolean = Right extends TOptional ? true : false> = ([
512
+ IsLeftOptional,
513
+ IsRightOptional
514
+ ] extends [false, true] ? TExtendsFalse : TExtendsLeft<Inferred, CheckLeft, CheckRight> extends TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsParameters<Inferred, LeftRest, RightRest> : TExtendsFalse);
515
+ type TParameterRight<Inferred extends TProperties, Left extends TSchema, LeftRest extends TSchema[], RightRest extends TSchema[]> = (RightRest extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TParameterCompare<Inferred, Left, LeftRest, Head, Tail> : Left extends TOptional ? TExtendsTrue<Inferred> : TExtendsFalse);
516
+ type TParameterLeft<Inferred extends TProperties, LeftRest extends TSchema[], RightRest extends TSchema[]> = (LeftRest extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TParameterRight<Inferred, Head, Tail, RightRest> : TExtendsTrue<Inferred>);
517
+ type TExtendsParameters<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema[]> = TParameterLeft<Inferred, Left, Right>;
518
+
519
+ type StaticVoid = void;
520
+ /** Represents a Void type. */
521
+ interface TVoid extends TSchema {
522
+ '~kind': 'Void';
523
+ type: 'void';
524
+ }
525
+
526
+ type TExtendsReturnType<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Right extends TVoid ? TExtendsTrue<Inferred> : TExtendsLeft<Inferred, Left, Right>);
527
+
528
+ type TExtendsConstructor<Inferred extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema, Right extends TSchema> = (Right extends TAny ? TExtendsTrue<Inferred> : Right extends TUnknown ? TExtendsTrue<Inferred> : Right extends TConstructor ? TExtendsParameters<Inferred, Parameters, Right['parameters']> extends TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsReturnType<Inferred, InstanceType, Right['instanceType']> : TExtendsFalse : TExtendsFalse);
529
+
530
+ type TExtendsDependent<Inferred extends TProperties, If extends TSchema, Then extends TSchema, Else extends TSchema, Right extends TSchema> = (TExtendsLeft<Inferred, If, Right> extends TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsLeft<Inferred, Then, Right> : TExtendsLeft<Inferred, Else, Right>);
531
+
532
+ type TExtendsEnum<Inferred extends TProperties, Left extends TEnumValue[], Right extends TSchema, Evaluated extends TSchema = TEvaluateEnum<Left>> = TExtendsLeft<Inferred, Evaluated, Right>;
533
+
534
+ type TExtendsFunction<Inferred extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema, Right extends TSchema> = (Right extends TAny ? TExtendsTrue<Inferred> : Right extends TUnknown ? TExtendsTrue<Inferred> : Right extends TFunction ? TExtendsParameters<Inferred, Parameters, Right['parameters']> extends TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsReturnType<Inferred, ReturnType, Right['returnType']> : TExtendsFalse : TExtendsFalse);
535
+
536
+ type TExtendsInteger<Inferred extends TProperties, Left extends TInteger, Right extends TSchema> = (Right extends TInteger ? TExtendsTrue<Inferred> : Right extends TNumber ? TExtendsTrue<Inferred> : TExtendsRight<Inferred, Left, Right>);
537
+
538
+ type TExtendsIntersect<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema, Evaluated extends TSchema = TEvaluateIntersect<Left>> = TExtendsLeft<Inferred, Evaluated, Right>;
539
+
540
+ type TExtendsLiteralValue<Inferred extends TProperties, Left extends TLiteralValue, Right extends TLiteralValue> = (Left extends Right ? TExtendsTrue<Inferred> : TExtendsFalse);
541
+ type TExtendsLiteralBigInt<Inferred extends TProperties, Left extends bigint, Right extends TSchema> = (Right extends TLiteral<infer Value extends bigint> ? TExtendsLiteralValue<Inferred, Left, Value> : Right extends TBigInt ? TExtendsTrue<Inferred> : TExtendsRight<Inferred, TLiteral<Left>, Right>);
542
+ type TExtendsLiteralBoolean<Inferred extends TProperties, Left extends boolean, Right extends TSchema> = (Right extends TLiteral<infer Value extends boolean> ? TExtendsLiteralValue<Inferred, Left, Value> : Right extends TBoolean ? TExtendsTrue<Inferred> : TExtendsRight<Inferred, TLiteral<Left>, Right>);
543
+ type TExtendsLiteralNumber<Inferred extends TProperties, Left extends number, Right extends TSchema> = (Right extends TLiteral<infer Value extends number> ? TExtendsLiteralValue<Inferred, Left, Value> : Right extends TNumber ? TExtendsTrue<Inferred> : TExtendsRight<Inferred, TLiteral<Left>, Right>);
544
+ type TExtendsLiteralString<Inferred extends TProperties, Left extends string, Right extends TSchema> = (Right extends TLiteral<infer Value extends string> ? TExtendsLiteralValue<Inferred, Left, Value> : Right extends TString ? TExtendsTrue<Inferred> : TExtendsRight<Inferred, TLiteral<Left>, Right>);
545
+ type TExtendsLiteral<Inferred extends TProperties, Left extends TLiteral, Right extends TSchema> = (Left extends TLiteral<infer Value extends bigint> ? TExtendsLiteralBigInt<Inferred, Value, Right> : Left extends TLiteral<infer Value extends boolean> ? TExtendsLiteralBoolean<Inferred, Value, Right> : Left extends TLiteral<infer Value extends number> ? TExtendsLiteralNumber<Inferred, Value, Right> : Left extends TLiteral<infer Value extends string> ? TExtendsLiteralString<Inferred, Value, Right> : TUnreachable);
546
+
547
+ type TExtendsNever<Inferred extends TProperties, Left extends TNever, Right extends TSchema> = (Right extends TInfer ? TExtendsRight<Inferred, Left, Right> : TExtendsTrue<Inferred>);
548
+
549
+ type TExtendsNull<Inferred extends TProperties, Left extends TNull, Right extends TSchema> = (Right extends TNull ? TExtendsTrue<Inferred> : TExtendsRight<Inferred, Left, Right>);
550
+
551
+ type TExtendsNumber<Inferred extends TProperties, Left extends TNumber, Right extends TSchema> = (Right extends TNumber ? TExtendsTrue<Inferred> : TExtendsRight<Inferred, Left, Right>);
552
+
553
+ type TExtendsPropertyOptional<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Left extends TOptional<Left> ? Right extends TOptional<Right> ? TExtendsTrue<Inferred> : TExtendsFalse : TExtendsTrue<Inferred>);
554
+ type TExtendsProperty<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Right extends TInfer<string, TNever> ? TExtendsFalse : TExtendsLeft<Inferred, Left, Right> extends TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsPropertyOptional<Inferred, Left, Right> : TExtendsFalse);
555
+ type TExtractInferredProperties<Keys extends PropertyKey[], Properties extends Record<PropertyKey, TResult>, Result extends TProperties = {}> = (Keys extends [infer Left extends PropertyKey, ...infer Right extends PropertyKey[]] ? Left extends keyof Properties ? Properties[Left] extends Result.TExtendsTrueLike<infer Inferred extends TProperties> ? TExtractInferredProperties<Right, Properties, Result & Inferred> : TExtractInferredProperties<Right, Properties, Result> : TUnreachable : Result);
556
+ type TExtendsPropertiesComparer<Inferred extends TProperties, Left extends TProperties, Right extends TProperties, Properties extends Record<PropertyKey, TExtendsTrue | TExtendsFalse> = {
557
+ [RightKey in keyof Right]: (RightKey extends keyof Left ? TExtendsProperty<{}, Left[RightKey], Right[RightKey]> : Right[RightKey] extends TOptional<Right[RightKey]> ? Right[RightKey] extends TInfer ? TExtendsTrue<TAssign<Inferred, {
558
+ [_ in Right[RightKey]['name']]: Right[RightKey]['extends'];
559
+ }>> : TExtendsTrue<Inferred> : TExtendsFalse);
560
+ }, Checked extends boolean = Properties[keyof Right] extends TExtendsTrueLike ? true : false, Extracted extends TProperties = Checked extends true ? TExtractInferredProperties<TUnionToTuple<keyof Properties>, Properties> : {}> = (Checked extends true ? TExtendsTrue<Extracted> : TExtendsFalse);
561
+ type TExtendsProperties<Inferred extends TProperties, Left extends TProperties, Right extends TProperties, Compared extends TResult = TExtendsPropertiesComparer<Inferred, Left, Right>> = (Compared extends TExtendsTrueLike<infer ComparedInferred extends TProperties> ? TExtendsTrue<TAssign<Inferred, ComparedInferred>> : TExtendsFalse);
562
+ type TExtendsObjectToObject<Inferred extends TProperties, Left extends TProperties, Right extends TProperties> = (TExtendsProperties<Inferred, Left, Right>);
563
+ type TRecordMergeInferred<Left extends TProperties, Right extends TProperties, Result extends TProperties = {
564
+ [Key in keyof Right]: Key extends keyof Left ? Left[Key] extends TUnion<infer Types extends TSchema[]> ? TUnion<[...Types, Right[Key]]> : TUnion<[Left[Key], Right[Key]]> : Right[Key];
565
+ }> = Result;
566
+ type TExtendsRecordComparer<Properties extends TProperties, Keys extends (keyof Properties)[], Type extends TSchema, Result extends TProperties> = (Keys extends [infer Left extends (keyof Properties), ...infer Right extends (keyof Properties)[]] ? TExtendsLeft<{}, Properties[Left], Type> extends Result.TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsRecordComparer<Properties, Right, Type, TRecordMergeInferred<Result, Inferred>> : Result.TExtendsFalse : Result.TExtendsTrue<Result>);
567
+ type TExtendsObjectToRecord<Inferred extends TProperties, Properties extends TProperties, _Pattern extends string, Value extends TSchema, Keys extends (keyof Properties)[] = TUnionToTuple<keyof Properties>, Result extends TResult = TExtendsRecordComparer<Properties, Keys, Value, Inferred>> = Result;
568
+ type TExtendsObject<Inferred extends TProperties, Left extends TProperties, Right extends TSchema> = (Right extends TRecord<infer Pattern extends string, infer Value extends TSchema> ? TExtendsObjectToRecord<Inferred, Left, Pattern, Value> : Right extends TObject<infer Properties extends TProperties> ? TExtendsObjectToObject<Inferred, Left, Properties> : TExtendsRight<Inferred, TObject<Left>, Right>);
569
+
570
+ type TFromObject$6<Inferred extends TProperties, Properties extends TProperties> = keyof Properties extends never ? TExtendsTrue<Inferred> : TExtendsFalse;
571
+ type TFromRecord$1<Inferred extends TProperties, _LeftKey extends TSchema, LeftValue extends TSchema, _RightKey extends TSchema, RightValue extends TSchema> = (TExtendsLeft<Inferred, LeftValue, RightValue>);
572
+ type TExtendsRecord<Inferred extends TProperties, LeftPattern extends string, LeftValue extends TSchema, Right extends TSchema> = (Right extends TRecord<infer Pattern extends string, infer Value extends TSchema> ? TFromRecord$1<Inferred, TRecordPatternToType<LeftPattern>, LeftValue, TRecordPatternToType<Pattern>, Value> : Right extends TObject<infer Properties extends TProperties> ? TFromObject$6<Inferred, Properties> : Right extends TAny ? TExtendsTrue<Inferred> : Right extends TUnknown ? TExtendsTrue<Inferred> : TExtendsFalse);
573
+
574
+ type TExtendsString<Inferred extends TProperties, Left extends TString, Right extends TSchema> = (Right extends TString ? TExtendsTrue<Inferred> : TExtendsRight<Inferred, Left, Right>);
575
+
576
+ type TExtendsSymbol<Inferred extends TProperties, Left extends TSymbol, Right extends TSchema> = (Right extends TSymbol ? TExtendsTrue<Inferred> : TExtendsRight<Inferred, Left, Right>);
577
+
578
+ type TExtendsTemplateLiteral<Inferred extends TProperties, Pattern extends string, Right extends TSchema, Evaluated extends TSchema = TEvaluateTemplateLiteral<Pattern>> = TExtendsLeft<Inferred, Evaluated, Right>;
579
+
580
+ /** Represents a Rest instruction. */
581
+ interface TRest<Type extends TSchema = TSchema> extends TSchema {
582
+ '~kind': 'Rest';
583
+ type: 'rest';
584
+ items: Type;
585
+ }
586
+
587
+ interface TInferable<Name extends string = string, Type extends TSchema = TSchema> {
588
+ '~kind': 'Inferrable';
589
+ name: Name;
590
+ type: Type;
591
+ }
592
+ type TTryRestInferable<Type extends TSchema, Result extends TInferable | undefined = (Type extends TRest<infer RestType extends TSchema> ? RestType extends TInfer<infer Name extends string, infer Type extends TSchema> ? Type extends TArray<infer Type extends TSchema> ? TInferable<Name, Type> : Type extends TUnknown ? TInferable<Name, Type> : undefined : TUnreachable : undefined)> = Result;
593
+ type TTryInferable<Type extends TSchema, Result extends TInferable | undefined = (Type extends TInfer<infer Name extends string, infer Type extends TSchema> ? TInferable<Name, Type> : undefined)> = Result;
594
+ type TryInferResults<Rest extends TSchema[], Right extends TSchema, Result extends TSchema[] = []> = (Rest extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExtendsLeft<{}, Head, Right> extends Result.TExtendsTrueLike ? TryInferResults<Tail, Right, [...Result, Head]> : undefined : Result);
595
+ declare function TryInferResults<Rest extends TSchema[], Right extends TSchema>(rest: [...Rest], right: Right, result?: TSchema[]): TryInferResults<Rest, Right>;
596
+ type TInferTupleResult<Inferred extends TProperties, Name extends string, Left extends TSchema[], Right extends TSchema, Results extends TSchema[] | undefined = TryInferResults<Left, Right>> = (Results extends [...infer Results extends TSchema[]] ? TExtendsTrue<TAssign<Inferred, {
597
+ [_ in Name]: TTuple<Results>;
598
+ }>> : TExtendsFalse);
599
+ type TInferUnionResult<Inferred extends TProperties, Name extends string, Left extends TSchema[], Right extends TSchema, Results extends TSchema[] | undefined = TryInferResults<Left, Right>> = (Results extends [...infer Results extends TSchema[]] ? TExtendsTrue<TAssign<Inferred, {
600
+ [_ in Name]: TUnion<Results>;
601
+ }>> : TExtendsFalse);
602
+
603
+ type TReverse<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TReverse<Right, [Left, ...Result]> : Result);
604
+ type TApplyReverse<Types extends TSchema[], Reversed extends boolean> = Reversed extends true ? TReverse<Types> : Types;
605
+ type TReversed<Types extends TSchema[], First extends TSchema | undefined = Types extends [infer Left extends TSchema, ...infer _ extends TSchema[]] ? Left : undefined, Inferable extends TSchema | undefined = First extends TSchema ? TTryRestInferable<First> : undefined, Result extends boolean = Inferable extends TSchema ? true : false> = Result;
606
+ type TElementsCompare<Inferred extends TProperties, Reversed extends boolean, Left extends TSchema, LeftRest extends TSchema[], Right extends TSchema, RightRest extends TSchema[]> = (TExtendsLeft<Inferred, Left, Right> extends TExtendsTrueLike<infer CheckInferred extends TProperties> ? TElements<CheckInferred, Reversed, LeftRest, RightRest> : TExtendsFalse);
607
+ type TElementsLeft<Inferred extends TProperties, Reversed extends boolean, LeftRest extends TSchema[], Right extends TSchema, RightRest extends TSchema[], Inferable extends TInferable | undefined = TTryRestInferable<Right>> = (Inferable extends TInferable ? TInferTupleResult<Inferred, Inferable['name'], TApplyReverse<LeftRest, Reversed>, Inferable['type']> : LeftRest extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TElementsCompare<Inferred, Reversed, Head, Tail, Right, RightRest> : TExtendsFalse);
608
+ type TElementsRight<Inferred extends TProperties, Reversed extends boolean, LeftRest extends TSchema[], RightRest extends TSchema[]> = (RightRest extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TElementsLeft<Inferred, Reversed, LeftRest, Head, Tail> : LeftRest['length'] extends 0 ? TExtendsTrue<Inferred> : TExtendsFalse);
609
+ type TElements<Inferred extends TProperties, Reversed extends boolean, LeftRest extends TSchema[], RightRest extends TSchema[]> = TElementsRight<Inferred, Reversed, LeftRest, RightRest>;
610
+ type TExtendsTupleToTuple<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema[], InstantiatedRight extends TSchema[] = TInstantiateElements<Inferred, TState<[], []>, Right>, Reversed extends boolean = TReversed<InstantiatedRight>> = TElements<Inferred, Reversed, TApplyReverse<Left, Reversed>, TApplyReverse<InstantiatedRight, Reversed>>;
611
+ type TExtendsTupleToArray<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema, Inferrable extends TInferable | undefined = TTryInferable<Right>> = (Inferrable extends TInferable ? TInferUnionResult<Inferred, Inferrable['name'], Left, Inferrable['type']> : Left extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExtendsLeft<Inferred, Head, Right> extends TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsTupleToArray<Inferred, Tail, Right> : TExtendsFalse : TExtendsTrue<Inferred>);
612
+ type TExtendsTuple<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema, InstantiatedLeft extends TSchema[] = TInstantiateElements<Inferred, TState<[], []>, Left>> = (Right extends TTuple<infer Types extends TSchema[]> ? TExtendsTupleToTuple<Inferred, InstantiatedLeft, Types> : Right extends TArray<infer Type extends TSchema> ? TExtendsTupleToArray<Inferred, InstantiatedLeft, Type> : TExtendsRight<Inferred, TTuple<InstantiatedLeft>, Right>);
613
+
614
+ type StaticUndefined = undefined;
615
+ /** Represents a Undefined type. */
616
+ interface TUndefined extends TSchema {
617
+ '~kind': 'Undefined';
618
+ type: 'undefined';
619
+ }
620
+
621
+ type TExtendsUndefined<Inferred extends TProperties, Left extends TUndefined, Right extends TSchema> = (Right extends TVoid ? TExtendsTrue<Inferred> : Right extends TUndefined ? TExtendsTrue<Inferred> : TExtendsRight<Inferred, Left, Right>);
622
+
623
+ type TExtendsUnionSome<Inferred extends TProperties, Type extends TSchema, UnionTypes extends TSchema[]> = (UnionTypes extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExtendsLeft<Inferred, Type, Head> extends TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsTrue<Inferred> : TExtendsUnionSome<Inferred, Type, Tail> : TExtendsFalse);
624
+ type TExtendsUnionLeft<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema[]> = (Left extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExtendsUnionSome<Inferred, Head, Right> extends TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsUnionLeft<Inferred, Tail, Right> : TExtendsFalse : TExtendsTrue<Inferred>);
625
+ type TExtendsUnion<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema, Inferrable extends TInferable | undefined = TTryInferable<Right>> = (Inferrable extends TInferable<infer Name extends string, infer Type extends TSchema> ? TInferUnionResult<Inferred, Name, Left, Type> : Right extends TUnion<infer Types extends TSchema[]> ? TExtendsUnionLeft<Inferred, Left, Types> : TExtendsUnionLeft<Inferred, Left, [Right]>);
626
+
627
+ type TExtendsUnknown<Inferred extends TProperties, Left extends TUnknown, Right extends TSchema> = (Right extends TInfer ? TExtendsRight<Inferred, Left, Right> : Right extends TAny ? TExtendsTrue<Inferred> : Right extends TUnknown ? TExtendsTrue<Inferred> : TExtendsFalse);
628
+
629
+ type TExtendsVoid<Inferred extends TProperties, Left extends TVoid, Right extends TSchema> = (Right extends TVoid ? TExtendsTrue<Inferred> : TExtendsRight<Inferred, Left, Right>);
630
+
631
+ type TExtendsLeft<Inferred extends TProperties, Left extends TSchema, Right extends TSchema> = (Left extends TAny ? TExtendsAny<Inferred, Left, Right> : Left extends TArray<infer Items extends TSchema> ? TExtendsArray<Inferred, Left, Items, Right> : Left extends TBigInt ? TExtendsBigInt<Inferred, Left, Right> : Left extends TBoolean ? TExtendsBoolean<Inferred, Left, Right> : Left extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TExtendsConstructor<Inferred, Parameters, InstanceType, Right> : Left extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TExtendsDependent<Inferred, If, Then, Else, Right> : Left extends TEnum<infer Values extends TEnumValue[]> ? TExtendsEnum<Inferred, Values, Right> : Left extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TExtendsFunction<Inferred, Parameters, ReturnType, Right> : Left extends TInteger ? TExtendsInteger<Inferred, Left, Right> : Left extends TIntersect<infer Types extends TSchema[]> ? TExtendsIntersect<Inferred, Types, Right> : Left extends TLiteral ? TExtendsLiteral<Inferred, Left, Right> : Left extends TNever ? TExtendsNever<Inferred, Left, Right> : Left extends TNull ? TExtendsNull<Inferred, Left, Right> : Left extends TNumber ? TExtendsNumber<Inferred, Left, Right> : Left extends TObject<infer Properties extends TProperties> ? TExtendsObject<Inferred, Properties, Right> : Left extends TRecord<infer Pattern extends string, infer Value extends TSchema> ? TExtendsRecord<Inferred, Pattern, Value, Right> : Left extends TString ? TExtendsString<Inferred, Left, Right> : Left extends TSymbol ? TExtendsSymbol<Inferred, Left, Right> : Left extends TTemplateLiteral<infer Pattern extends string> ? TExtendsTemplateLiteral<Inferred, Pattern, Right> : Left extends TTuple<infer Types extends TSchema[]> ? TExtendsTuple<Inferred, Types, Right> : Left extends TUndefined ? TExtendsUndefined<Inferred, Left, Right> : Left extends TUnion<infer Types extends TSchema[]> ? TExtendsUnion<Inferred, Types, Right> : Left extends TUnknown ? TExtendsUnknown<Inferred, Left, Right> : Left extends TVoid ? TExtendsVoid<Inferred, Left, Right> : TExtendsFalse);
632
+
633
+ type TInterfaceOperation<Heritage extends TSchema[], Properties extends TProperties, Result extends TSchema = TEvaluateIntersect<[...Heritage, TObject<Properties>]>> = Result;
634
+ type TInterfaceAction<Heritage extends TSchema[], Properties extends TProperties, Result extends TSchema = TCanInstantiate<Heritage> extends true ? TInterfaceOperation<Heritage, Properties> : TInterfaceDeferred<Heritage, Properties>> = Result;
635
+ type TInterfaceInstantiate<Context extends TProperties, State extends TState, Heritage extends TSchema[], Properties extends TProperties, InstantiatedHeritage extends TSchema[] = TInstantiateTypes<Context, State, Heritage>, InstantiatedProperties extends TProperties = TInstantiateProperties<Context, State, Properties>> = TInterfaceAction<InstantiatedHeritage, InstantiatedProperties>;
636
+
637
+ /** Creates a deferred Interface action. */
638
+ type TInterfaceDeferred<Heritage extends TSchema[] = TSchema[], Properties extends TProperties = TProperties> = (TDeferred<'Interface', [Heritage, Properties]>);
639
+
640
+ type TFromRef$3<Stack extends (keyof Context)[], Context extends TProperties, Ref extends (keyof Context)> = Ref extends Stack[number] ? true : TFromType$h<[...Stack, Ref], Context, Context[Ref]>;
641
+ type TFromProperties$2<Stack extends (keyof Context)[], Context extends TProperties, Properties extends TProperties, Types extends TSchema[] = TPropertyValues<Properties>> = TFromTypes$4<Stack, Context, Types>;
642
+ type TFromTypes$4<Stack extends (keyof Context)[], Context extends TProperties, Types extends TSchema[]> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromType$h<Stack, Context, Left> extends true ? true : TFromTypes$4<Stack, Context, Right> : false;
643
+ type TFromType$h<Stack extends (keyof Context)[], Context extends TProperties, Type extends TSchema> = (Type extends TRef<infer Ref extends string> ? TFromRef$3<Stack, Context, Ref> : Type extends TArray<infer Type extends TSchema> ? TFromType$h<Stack, Context, Type> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromTypes$4<Stack, Context, [...Parameters, InstanceType]> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromTypes$4<Stack, Context, [...Parameters, ReturnType]> : Type extends TInterfaceDeferred<TSchema[], infer Properties extends TProperties> ? TFromProperties$2<Stack, Context, Properties> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromTypes$4<Stack, Context, Types> : Type extends TObject<infer Properties extends TProperties> ? TFromProperties$2<Stack, Context, Properties> : Type extends TUnion<infer Types extends TSchema[]> ? TFromTypes$4<Stack, Context, Types> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTypes$4<Stack, Context, Types> : Type extends TRecord<string, infer Type extends TSchema> ? TFromType$h<Stack, Context, Type> : false);
644
+ /** Performs a cyclic check on the given type. Initial key stack can be empty, but faster if specified */
645
+ type TCyclicCheck<Stack extends (keyof Context)[], Context extends TProperties, Type extends TSchema, Result extends boolean = TFromType$h<Stack, Context, Type>> = Result;
646
+
647
+ type TResolveCandidateKeys<Context extends TProperties, Keys extends (keyof Context)[], Result extends (keyof Context)[] = []> = (Keys extends [infer Left extends keyof Context, ...infer Right extends (keyof Context)[]] ? TCyclicCheck<[Left], Context, Context[Left]> extends true ? TResolveCandidateKeys<Context, Right, [...Result, Left]> : TResolveCandidateKeys<Context, Right, Result> : Result);
648
+ /** Returns keys for context types that need to be transformed to TCyclic. */
649
+ type TCyclicCandidates<Context extends TProperties, Keys extends (keyof Context)[] = TPropertyKeys<Context>, Result extends (keyof Context)[] = TResolveCandidateKeys<Context, Keys>> = Result;
650
+
651
+ type TFromRef$2<Context extends TProperties, Ref extends string, Dependencies extends string[]> = Ref extends Dependencies[number] ? Dependencies : Ref extends keyof Context ? TFromType$g<Context, Context[Ref], [...Dependencies, Ref]> : TUnreachable;
652
+ type TFromProperties$1<Context extends TProperties, Properties extends TProperties, Dependencies extends string[], Types extends TSchema[] = TPropertyValues<Properties>> = TFromTypes$3<Context, Types, Dependencies>;
653
+ type TFromTypes$3<Context extends TProperties, Types extends TSchema[], Dependencies extends string[]> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromTypes$3<Context, Right, TFromType$g<Context, Left, Dependencies>> : Dependencies;
654
+ type TFromType$g<Context extends TProperties, Type extends TSchema, Result extends string[]> = (Type extends TRef<infer Ref extends string> ? TFromRef$2<Context, Ref, Result> : Type extends TArray<infer Type extends TSchema> ? TFromType$g<Context, Type, Result> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromTypes$3<Context, [...Parameters, InstanceType], Result> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromTypes$3<Context, [...Parameters, ReturnType], Result> : Type extends TInterfaceDeferred<TSchema[], infer Properties extends TProperties> ? TFromProperties$1<Context, Properties, Result> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromTypes$3<Context, Types, Result> : Type extends TObject<infer Properties extends TProperties> ? TFromProperties$1<Context, Properties, Result> : Type extends TUnion<infer Types extends TSchema[]> ? TFromTypes$3<Context, Types, Result> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTypes$3<Context, Types, Result> : Type extends TRecord<string, infer Type extends TSchema> ? TFromType$g<Context, Type, Result> : Result);
655
+ /** Returns dependent cyclic keys for the given type. This function is used to dead-type-eliminate (DTE) for initializing TCyclic types. */
656
+ type TCyclicDependencies<Context extends TProperties, Key extends string, Type extends TSchema, Result extends string[] = TFromType$g<Context, Type, [Key]>> = Result;
657
+
658
+ type TFromRef$1<_Ref extends string> = (TAny);
659
+ type TFromProperties<Properties extends TProperties, Result extends TProperties = {
660
+ [Key in keyof Properties]: TFromType$f<Properties[Key]>;
661
+ }> = {
662
+ [Key in keyof Result]: Result[Key];
663
+ };
664
+ type TFromTypes$2<Types extends TSchema[], Result extends TSchema[] = []> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromTypes$2<Right, [...Result, TFromType$f<Left>]> : Result;
665
+ type TFromType$f<Type extends TSchema> = (Type extends TRef<infer Ref extends string> ? TFromRef$1<Ref> : Type extends TArray<infer Type extends TSchema> ? TArray<TFromType$f<Type>> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFunction<TFromTypes$2<Parameters>, TFromType$f<InstanceType>> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TFromTypes$2<Parameters>, TFromType$f<ReturnType>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromTypes$2<Types>> : Type extends TObject<infer Properties extends TProperties> ? TObject<TFromProperties<Properties>> : Type extends TRecord<infer Pattern extends string, infer Value extends TSchema> ? TRecord<Pattern, TFromType$f<Value>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromTypes$2<Types>> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TFromTypes$2<Types>> : Type);
666
+ type TCyclicAnyFromParameters<Defs extends TProperties, Ref extends string> = (Ref extends keyof Defs ? TFromType$f<Defs[Ref]> : TUnknown);
667
+ /** Transforms TCyclic TRef's into TAny's. This function is used prior to TExtends checks to enable cyclics to be structurally checked and terminated (with TAny) at first point of recursion, what would otherwise be a recursive TRef.*/
668
+ type TCyclicExtends<Type extends TCyclic, Result extends TSchema = TCyclicAnyFromParameters<Type['$defs'], Type['$ref']>> = Result;
669
+
670
+ type TCyclicInterface<Context extends TProperties, Heritage extends TSchema[], Properties extends TProperties, InstantiatedHeritage extends TSchema[] = TInstantiateTypes<Context, TState<[], []>, Heritage>, instantiatedProperties extends TProperties = TInstantiateProperties<{}, TState<[], []>, Properties>, EvaluatedInterface extends TSchema = TEvaluateIntersect<[...InstantiatedHeritage, TObject<instantiatedProperties>]>> = EvaluatedInterface;
671
+ type TCyclicDefinitions<Context extends TProperties, Dependencies extends string[], Result extends TProperties = {
672
+ [Key in Extract<keyof Context, Dependencies[number]>]: Context[Key] extends TInterfaceDeferred<infer Heritage extends TSchema[], infer Properties extends TProperties> ? TCyclicInterface<Context, Heritage, Properties> : Context[Key];
673
+ }> = Result;
674
+ type TInstantiateCyclic<Context extends TProperties, Ref extends string, Type extends TSchema, Dependencies extends string[] = TCyclicDependencies<Context, Ref, Type>, Definitions extends TProperties = TCyclicDefinitions<Context, Dependencies>, Result extends TSchema = TCyclic<Definitions, Ref>> = Result;
675
+
676
+ type TResolve$1<Defs extends TProperties, Ref extends string> = (Ref extends keyof Defs ? Defs[Ref] extends TRef<infer Ref extends string> ? TResolve$1<Defs, Ref> : Defs[Ref] : TNever);
677
+ /** Returns the target Type from the Defs or Never if target is non-resolvable */
678
+ type TCyclicTarget<Defs extends TProperties, Ref extends string, Result extends TSchema = TResolve$1<Defs, Ref>> = Result;
679
+
680
+ type TCanonical<Type extends TSchema> = (Type extends TCyclic ? TCyclicExtends<Type> : Type extends TUnsafe ? TUnknown : Type);
681
+ /** Performs a structural extends check on left and right types and yields inferred types on right if specified. */
682
+ type TExtends<Inferred extends TProperties, Left extends TSchema, Right extends TSchema, CanonicalLeft extends TSchema = TCanonical<Left>, CanonicalRight extends TSchema = TCanonical<Right>> = TExtendsLeft<Inferred, CanonicalLeft, CanonicalRight>;
683
+
684
+ type TExcludeType<Left extends TSchema, Right extends TSchema, Check extends TResult = TExtends<{}, Left, Right>, Result extends TSchema[] = Check extends TExtendsTrueLike ? [] : [Left]> = Result;
685
+ type TExcludeUnion<Left extends TSchema[], Right extends TSchema, Result extends TSchema[] = []> = (Left extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExcludeUnion<Tail, Right, [...Result, ...TExcludeType<Head, Right>]> : Result);
686
+ type TExcludeOperation<Left extends TSchema, Right extends TSchema, Evaluated extends TSchema = TEvaluateType<Left>, Canonical extends TSchema[] = Evaluated extends TUnion<infer Types extends TSchema[]> ? Types : [Evaluated], Remaining extends TSchema[] = TExcludeUnion<Canonical, Right>, Result extends TSchema = TEvaluateUnion<Remaining>> = Result;
687
+
688
+ type TEvaluateDependent<If extends TSchema, Then extends TSchema, Else extends TSchema, Intersected extends TSchema = TEvaluateIntersect<[If, Then]>, Excluded extends TSchema = TExcludeOperation<Else, If>, Result extends TSchema = TEvaluateUnion<[Intersected, Excluded]>> = Result;
689
+ type TEvaluateEnum<Values extends TEnumValue[], Result extends TSchema[] = []> = (Values extends [infer Left extends TEnumValue, ...infer Right extends TEnumValue[]] ? TEvaluateEnum<Right, [...Result, TLiteral<Left>]> : TEvaluateUnion<Result>);
690
+ type TEvaluateIntersect<Types extends TSchema[], Distribution extends TSchema[] = TDistribute$1<Types>, Broadend extends TSchema[] = TBroaden<Distribution>, Result extends TSchema = TEvaluateUnion<Broadend>> = Result;
691
+ type TEvaluateTemplateLiteral<Pattern extends string, Evaluated extends TSchema = TTemplateLiteralDecode<Pattern>, Result extends TSchema = TEvaluateType<Evaluated>> = Result;
692
+ type TEvaluateUnion<Types extends TSchema[], Broadend extends TSchema[] = TBroaden<Types>, Result extends TSchema = TEvaluateUnionFast<Broadend>> = Result;
693
+ type TEvaluateType<Type extends TSchema, Result extends TSchema = (Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TEvaluateDependent<If, Then, Else> : Type extends TEnum<infer Values extends TEnumValue[]> ? TEvaluateEnum<Values> : Type extends TIntersect<infer Types extends TSchema[]> ? TEvaluateIntersect<Types> : Type extends TTemplateLiteral<infer Pattern extends string> ? TEvaluateTemplateLiteral<Pattern> : Type extends TUnion<infer Types extends TSchema[]> ? TEvaluateUnion<Types> : Type)> = Result;
694
+ type TEvaluateUnionFast<Types extends TSchema[], Result extends TSchema = (Types extends [infer Type extends TSchema] ? Type : Types extends [] ? TNever : TUnion<Types>)> = Result;
695
+
696
+ type TJoinString<Input extends string[], Result extends string = ''> = (Input extends [infer Left extends string, ...infer Right extends string[]] ? Result extends '' ? TJoinString<Right, Left> : TJoinString<Right, `${Result}|${Left}`> : Result);
697
+ type TUnwrapTemplateLiteralPattern<Pattern extends string> = (Pattern extends `^${infer Pattern extends string}$` ? Pattern : never);
698
+ type TEncodeLiteral<Value extends TLiteralValue, Right extends TSchema[], Pattern extends string> = (TEncodeTypes<Right, `${Pattern}${Value}`>);
699
+ type TEncodeBigInt<Right extends TSchema[], Pattern extends string> = (TEncodeTypes<Right, `${Pattern}${typeof BigIntPattern}`>);
700
+ type TEncodeInteger<Right extends TSchema[], Pattern extends string> = (TEncodeTypes<Right, `${Pattern}${typeof IntegerPattern}`>);
701
+ type TEncodeNumber<Right extends TSchema[], Pattern extends string> = (TEncodeTypes<Right, `${Pattern}${typeof NumberPattern}`>);
702
+ type TEncodeBoolean<Right extends TSchema[], Pattern extends string> = (TEncodeType<TUnion<[TLiteral<'false'>, TLiteral<'true'>]>, Right, Pattern>);
703
+ type TEncodeString<Right extends TSchema[], Pattern extends string> = (TEncodeTypes<Right, `${Pattern}${typeof StringPattern}`>);
704
+ type TEncodeTemplateLiteral<TemplatePattern extends string, Right extends TSchema[], Pattern extends string> = (TEncodeTypes<Right, `${Pattern}${TUnwrapTemplateLiteralPattern<TemplatePattern>}`>);
705
+ type TEncodeTemplateLiteralDeferred<Types extends TSchema[], Right extends TSchema[], Pattern extends string, TemplateLiteral extends TSchema = TTemplateLiteralAction<Types>, Result extends TSchema = TEncodeType<TemplateLiteral, Right, Pattern>> = Result;
706
+ type TEncodeEnum<Values extends TEnumValue[], Right extends TSchema[], Pattern extends string, Evaluated extends TSchema = TEvaluateEnum<Values>> = TEncodeType<Evaluated, Right, Pattern>;
707
+ type TEncodeUnion<Types extends TSchema[], Right extends TSchema[], Pattern extends string, Result extends string[] = []> = Types extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TEncodeUnion<Tail, Right, Pattern, [...Result, TEncodeType<Head, [], ''>]> : TEncodeTypes<Right, `${Pattern}(${TJoinString<Result>})`>;
708
+ type TEncodeType<Type extends TSchema, Right extends TSchema[], Pattern extends string> = (Type extends TEnum<infer Values extends TEnumValue[]> ? TEncodeEnum<Values, Right, Pattern> : Type extends TInteger ? TEncodeInteger<Right, Pattern> : Type extends TLiteral<infer Value extends TLiteralValue> ? TEncodeLiteral<Value, Right, Pattern> : Type extends TBigInt ? TEncodeBigInt<Right, Pattern> : Type extends TBoolean ? TEncodeBoolean<Right, Pattern> : Type extends TNumber ? TEncodeNumber<Right, Pattern> : Type extends TString ? TEncodeString<Right, Pattern> : Type extends TTemplateLiteral<infer TemplatePattern extends string> ? TEncodeTemplateLiteral<TemplatePattern, Right, Pattern> : Type extends TTemplateLiteralDeferred<infer Types extends TSchema[]> ? TEncodeTemplateLiteralDeferred<Types, Right, Pattern> : Type extends TUnion<infer Types extends TSchema[]> ? TEncodeUnion<Types, Right, Pattern> : typeof NeverPattern);
709
+ type TEncodeTypes<Types extends TSchema[], Pattern extends string> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TEncodeType<Left, Right, Pattern> : Pattern);
710
+ type TEncodePattern<Types extends TSchema[], Encoded extends string = TEncodeTypes<Types, ''>, Result extends string = `^${Encoded}$`> = Result;
711
+ /** Encodes a TemplateLiteral type sequence into a TemplateLiteral */
712
+ type TTemplateLiteralEncode<Types extends TSchema[], Pattern extends string = TEncodePattern<Types>, Result extends TSchema = TTemplateLiteral<Pattern>> = Result;
713
+
714
+ type TTemplateLiteralAction<Types extends TSchema[], Result extends TSchema = TCanInstantiate<Types> extends true ? TTemplateLiteralEncode<Types> : TTemplateLiteralDeferred<Types>> = Result;
715
+ type TTemplateLiteralInstantiate<Context extends TProperties, State extends TState, Types extends TSchema[], InstantiatedTypes extends TSchema[] = TInstantiateTypes<Context, State, Types>> = TTemplateLiteralAction<InstantiatedTypes>;
716
+
717
+ type StaticTemplateLiteral<Pattern extends string> = (TTemplateLiteralStatic<Pattern>);
718
+ /** Represents a TemplateLiteral type. */
719
+ interface TTemplateLiteral<Pattern extends string = string> extends TSchema {
720
+ '~kind': 'TemplateLiteral';
721
+ type: 'string';
722
+ pattern: Pattern;
723
+ }
724
+ /** Creates a deferred TemplateLiteral action. */
725
+ type TTemplateLiteralDeferred<Types extends TSchema[] = TSchema[]> = (TDeferred<'TemplateLiteral', [Types]>);
726
+
727
+ type TFromLiteral$4<_Value extends TLiteralValue> = true;
728
+ type TFromTypesReduce<Types extends TSchema[]> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromType$e<Left> extends true ? TFromTypesReduce<Right> : false : true);
729
+ type TFromTypes$1<Types extends TSchema[], Result extends boolean = Types extends [] ? false : TFromTypesReduce<Types>> = Result;
730
+ type TFromType$e<Type extends TSchema> = Type extends TUnion<infer Types extends TSchema[]> ? TFromTypes$1<Types> : Type extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteral$4<Value> : false;
731
+ /** Returns true if the given TemplateLiteral types yields a finite variant set */
732
+ type TIsTemplateLiteralFinite<Types extends TSchema[], Result extends boolean = TFromTypes$1<Types>> = Result;
733
+
734
+ type TFromLiteralPush<Variants extends string[], Value extends TLiteralValue, Result extends string[] = []> = Variants extends [infer Left extends string, ...infer Right extends string[]] ? TFromLiteralPush<Right, Value, [...Result, `${Left}${Value}`]> : Result;
735
+ type TFromLiteral$3<Variants extends string[], Value extends TLiteralValue> = Variants extends [] ? [`${Value}`] : TFromLiteralPush<Variants, Value>;
736
+ type TFromUnion$7<Variants extends string[], Types extends TSchema[], Result extends string[] = []> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromUnion$7<Variants, Right, [...Result, ...TFromType$d<Variants, Left>]> : Result;
737
+ type TFromType$d<Variants extends string[], Type extends TSchema, Result extends string[] = (Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion$7<Variants, Types> : Type extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteral$3<Variants, Value> : TUnreachable)> = Result;
738
+ type TDecodeFromSpan<Variants extends string[], Types extends TSchema[]> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TDecodeFromSpan<TFromType$d<Variants, Left>, Right> : Variants;
739
+ type TVariantsToLiterals<Variants extends string[], Result extends TSchema[] = []> = Variants extends [infer Left extends string, ...infer Right extends string[]] ? TVariantsToLiterals<Right, [...Result, TLiteral<Left>]> : Result;
740
+ type TDecodeTypesAsUnion<Types extends TSchema[], Variants extends string[] = TDecodeFromSpan<[], Types>, Literals extends TSchema[] = TVariantsToLiterals<Variants>, Result extends TSchema = TUnion<Literals>> = Result;
741
+ type TDecodeTypes<Types extends TSchema[], Result extends TSchema = (Types extends [] ? TUnreachable : Types extends [infer Type extends TLiteral] ? Type : TDecodeTypesAsUnion<Types>)> = Result;
742
+ /** Decodes a TemplateLiteral into a Type. */
743
+ type TTemplateLiteralDecodeUnsafe<Pattern extends string, Types extends TSchema[] = TParsePatternIntoTypes<Pattern>, Result extends TSchema = (Types extends [] ? TString : TIsTemplateLiteralFinite<Types> extends true ? TDecodeTypes<Types> : TTemplateLiteral<Pattern>)> = Result;
744
+ /** Decodes a TemplateLiteral pattern but returns TString if the pattern in non-finite. */
745
+ type TTemplateLiteralDecode<Pattern extends string, Decoded extends TSchema = TTemplateLiteralDecodeUnsafe<Pattern>, Result extends TSchema = Decoded extends TTemplateLiteral ? TString : Decoded> = Result;
746
+
747
+ type TFromAnyKey<Value extends TSchema, Result extends TSchema = TRecord<typeof StringKey, Value>> = Result;
748
+
749
+ type TFromBooleanKey<Value extends TSchema, Result extends TSchema = TObject<{
750
+ true: Value;
751
+ false: Value;
752
+ }>> = Result;
753
+
754
+ type TFromEnumKey<Values extends TEnumValue[], Value extends TSchema, UnionKey extends TSchema = TEvaluateEnum<Values>, Result extends TSchema = TFromKey<UnionKey, Value>> = Result;
755
+
756
+ type TFromIntegerKey<_Key extends TInteger, Value extends TSchema, Result extends TSchema = TRecord<typeof IntegerKey, Value>> = Result;
757
+
758
+ type TFromIntersectKey<Types extends TSchema[], Value extends TSchema, EvaluatedKey extends TSchema = TEvaluateIntersect<Types>, Result extends TSchema = TFromKey<EvaluatedKey, Value>> = Result;
759
+
760
+ type TFromLiteralKey<Key extends TLiteralValue, Value extends TSchema, Result extends TSchema = (Key extends string | number ? TObject<{
761
+ [_ in Key]: Value;
762
+ }> : Key extends false ? TObject<{
763
+ false: Value;
764
+ }> : Key extends true ? TObject<{
765
+ true: Value;
766
+ }> : TObject<{}>)> = Result;
767
+
768
+ type TFromNumberKey<Key extends TNumber, Value extends TSchema, Result extends TSchema = TRecord<typeof NumberKey, Value>> = Result;
769
+
770
+ type TFromStringKey<_Key extends TSchema, Value extends TSchema, Result extends TSchema = TRecord<typeof StringKey, Value>> = Result;
771
+
772
+ type TFromTemplateKey<Pattern extends string, Value extends TSchema, Types extends TSchema[] = TParsePatternIntoTypes<Pattern>, Finite extends boolean = TIsTemplateLiteralFinite<Types>, Result extends TSchema = Finite extends true ? TFromKey<TEvaluateTemplateLiteral<Pattern>, Value> : TRecord<Pattern, Value>> = Result;
773
+
774
+ type TFlattenType<Type extends TSchema, Result extends TSchema[] = Type extends TUnion<infer Types extends TSchema[]> ? TFlatten<Types> : [Type]> = Result;
775
+ type TFlatten<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFlatten<Right, [...Result, ...TFlattenType<Left>]> : Result);
776
+
777
+ type TStringOrNumberCheck<Types extends TSchema[]> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TString | TNumber | TInteger ? true : TStringOrNumberCheck<Right> : false);
778
+ type TTryBuildRecord<Types extends TSchema[], Value extends TSchema, Result extends TSchema | undefined = (TStringOrNumberCheck<Types> extends true ? TRecord<typeof StringKey, Value> : undefined)> = Result;
779
+ type TCreateProperties<Variants extends TSchema[], Value extends TSchema, Result extends TProperties = {}> = (Variants extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TLiteral<string | number> ? TCreateProperties<Right, Value, Result & {
780
+ [_ in Left['const']]: Value;
781
+ }> : TCreateProperties<Right, Value, Result> : {
782
+ [Key in keyof Result]: Result[Key];
783
+ });
784
+ type TCreateObject<Variants extends TSchema[], Value extends TSchema, Properties extends TProperties = TCreateProperties<Variants, Value>, Result extends TSchema = TObject<Properties>> = Result;
785
+ type TFromUnionKey<Types extends TSchema[], Value extends TSchema, Flattened extends TSchema[] = TFlatten<Types>, Record extends TSchema | undefined = TTryBuildRecord<Flattened, Value>, Result extends TSchema = (Record extends TSchema ? Record : TCreateObject<Flattened, Value>)> = Result;
786
+
787
+ type TFromKey<Key extends TSchema, Value extends TSchema, Result extends TSchema = (Key extends TAny ? TFromAnyKey<Value> : Key extends TBoolean ? TFromBooleanKey<Value> : Key extends TEnum<infer Values extends TEnumValue[]> ? TFromEnumKey<Values, Value> : Key extends TInteger ? TFromIntegerKey<Key, Value> : Key extends TIntersect<infer Types extends TSchema[]> ? TFromIntersectKey<Types, Value> : Key extends TLiteral<infer LiteralValue extends TLiteralValue> ? TFromLiteralKey<LiteralValue, Value> : Key extends TNumber ? TFromNumberKey<Key, Value> : Key extends TString ? TFromStringKey<Key, Value> : Key extends TTemplateLiteral<infer Pattern extends string> ? TFromTemplateKey<Pattern, Value> : Key extends TUnion<infer Types extends TSchema[]> ? TFromUnionKey<Types, Value> : TObject<{}>)> = Result;
788
+
789
+ type TRecordAction<Key extends TSchema, Value extends TSchema, Result extends TSchema = TCanInstantiate<[Key]> extends true ? TFromKey<Key, Value> : TRecordDeferred<Key, Value>> = Result;
790
+ type TRecordInstantiate<Context extends TProperties, State extends TState, Key extends TSchema, Value extends TSchema, InstantiatedKey extends TSchema = TInstantiateType<Context, State, Key>, InstantiatedValue extends TSchema = TInstantiateType<Context, State, Value>> = TRecordAction<InstantiatedKey, InstantiatedValue>;
791
+
792
+ type StaticPropertyKey<Key extends string, Result extends PropertyKey = (Key extends TStringKey ? string : Key extends TIntegerKey ? number : Key extends TNumberKey ? number : Key extends `^${string}$` ? TTemplateLiteralStatic<Key> : string)> = Result;
793
+ type StaticRecord<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Key extends string, Value extends TSchema, StaticKey extends PropertyKey = StaticPropertyKey<Key>, StaticValue extends unknown = StaticType<Stack, Direction, Context, This, Value>, Result extends Record$1<PropertyKey, unknown> = Record$1<StaticKey, StaticValue>> = Result;
794
+ type TStringKey = typeof StringKey;
795
+ type TIntegerKey = typeof IntegerKey;
796
+ type TNumberKey = typeof NumberKey;
797
+ declare const IntegerKey = "^-?(?:0|[1-9][0-9]*)$";
798
+ declare const NumberKey = "^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$";
799
+ declare const StringKey = "^.*$";
800
+ interface TRecord<Key extends string = string, Value extends TSchema = TSchema> extends TSchema {
801
+ '~kind': 'Record';
802
+ type: 'object';
803
+ patternProperties: {
804
+ [_ in Key]: Value;
805
+ };
806
+ }
807
+ /** Represents a deferred Record action. */
808
+ type TRecordDeferred<Key extends TSchema = TSchema, Value extends TSchema = TSchema> = (TDeferred<'Record', [Key, Value]>);
809
+ /** Creates a Record type. */
810
+ declare function Record$1<Key extends TSchema, Value extends TSchema>(key: Key, value: Value, options?: TObjectOptions): TRecordAction<Key, Value>;
811
+ /** Transforms a Record Pattern to a Type */
812
+ type TRecordPatternToType<Pattern extends string, Result extends TSchema = (Pattern extends typeof StringKey ? TString : Pattern extends typeof IntegerKey ? TInteger : Pattern extends typeof NumberKey ? TNumber : TTemplateLiteralDecodeUnsafe<Pattern>)> = Result;
813
+ /** Extracts the Pattern from a Record type */
814
+ type TRecordPattern<Type extends TRecord, Result extends string = Extract<keyof Type['patternProperties'], string>> = Result;
815
+ /** Extracts the Key from a Record type */
816
+ type TRecordKey<Type extends TRecord, Pattern extends string = TRecordPattern<Type>, Result extends TSchema = TRecordPatternToType<Pattern>> = Result;
817
+
818
+ type StaticThis<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties> = (StaticType<Stack, Direction, Context, This, TObject<This>>);
819
+ /** Represents a This type. */
820
+ interface TThis extends TSchema {
821
+ '~kind': 'This';
822
+ $ref: '#';
823
+ }
824
+
825
+ declare const CompareResultEqual = 0;
826
+ declare const CompareResultDisjoint = 1;
827
+ declare const CompareResultLeftInside = 2;
828
+ declare const CompareResultRightInside = 3;
829
+ type TCompareResult = (typeof CompareResultEqual | typeof CompareResultDisjoint | typeof CompareResultLeftInside | typeof CompareResultRightInside);
830
+ /** Compares left and right types and determines their set relationship */
831
+ type TCompare<Left extends TSchema, Right extends TSchema, Extends extends [TResult, TResult] = [TExtends<{}, Left, Right>, TExtends<{}, Right, Left>]> = (Extends extends [TExtendsTrueLike, TExtendsTrueLike] ? typeof CompareResultEqual : Extends extends [TExtendsTrueLike, TExtendsFalse] ? typeof CompareResultLeftInside : Extends extends [TExtendsFalse, TExtendsTrueLike] ? typeof CompareResultRightInside : typeof CompareResultDisjoint);
832
+
833
+ type TBroadenFilter<Type extends TSchema, Types extends TSchema[], Result extends TSchema[] = [], All extends TSchema[] = Types> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TCompare<Type, Left> extends typeof CompareResultLeftInside | typeof CompareResultEqual ? All : TCompare<Type, Left> extends typeof CompareResultDisjoint ? TBroadenFilter<Type, Right, [...Result, Left], All> : TBroadenFilter<Type, Right, Result, All> : [...Result, Type]);
834
+ type TBroadenType<Type extends TSchema, Types extends TSchema[], Result extends TSchema[], Evaluated extends TSchema = TEvaluateType<Type>> = (Evaluated extends TAny ? [Evaluated] : Evaluated extends TUnknown ? [Evaluated] : Evaluated extends TNever ? TBroadenTypes<Types, Result> : Evaluated extends TObject ? TBroadenTypes<Types, [...Result, Evaluated]> : TBroadenTypes<Types, TBroadenFilter<Evaluated, Result>>);
835
+ type TBroadenTypes<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TBroadenType<Left, Right, Result> : Result);
836
+ type TBroaden<Types extends TSchema[], Broadened extends TSchema[] = TBroadenTypes<Types>, Flattened extends TSchema[] = TFlatten<Broadened>> = Flattened;
837
+
838
+ type TEvaluateAction<Type extends TSchema, Result extends TSchema = TEvaluateType<Type>> = Result;
839
+ type TEvaluateInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TEvaluateAction<InstantiatedType>;
840
+
841
+ type TCollectDistributionNames<Expression extends TSchema, Result extends string[] = []> = (Expression extends TDeferred<'Conditional', [infer Left extends TSchema, infer _Right extends TSchema, infer True extends TSchema, infer False extends TSchema]> ? Left extends TRef ? TCollectDistributionNames<True, TCollectDistributionNames<False, [...Result, Left['$ref']]>> : TCollectDistributionNames<True, TCollectDistributionNames<False, Result>> : Expression extends TDeferred<'Mapped', [infer _Identifier extends TSchema, infer Type extends TSchema, infer _As extends TSchema, infer _Property extends TSchema]> ? (Type extends TDeferred<'KeyOf', [infer Ref extends TRef]> ? [...Result, Ref['$ref']] : Result) : Result);
842
+ type TBuildDistributionArray<Parameters extends TParameter[], Names extends string[], Result extends boolean[] = []> = (Parameters extends [infer Left extends TParameter, ...infer Right extends TParameter[]] ? Left['name'] extends Names[number] ? TBuildDistributionArray<Right, Names, [...Result, true]> : TBuildDistributionArray<Right, Names, [...Result, false]> : Result);
843
+ type TZipDistributionArray<Arguments extends TSchema[], DistributionArray extends boolean[], Result extends [boolean, TSchema][] = []> = (Arguments extends [infer ArgumentLeft extends TSchema, ...infer ArgumentRight extends TSchema[]] ? DistributionArray extends [infer BooleanLeft extends boolean, ...infer BooleanRight extends boolean[]] ? TZipDistributionArray<ArgumentRight, BooleanRight, [...Result, [BooleanLeft, ArgumentLeft]]> : Result : Result);
844
+ type TCanonicalArgument<Type extends TSchema> = (Type extends TTemplateLiteral<infer Pattern extends string> ? TEvaluateTemplateLiteral<Pattern> : Type extends TEnum<infer Values extends TEnumValue[]> ? TEvaluateEnum<Values> : Type);
845
+ type TExpand<Argument extends TSchema, CanonicalArgument extends TSchema = TCanonicalArgument<Argument>> = (CanonicalArgument extends TUnion<infer Types extends TSchema[]> ? [...Types] : [CanonicalArgument]);
846
+ type TAppend<Current extends TSchema[][], Type extends TSchema, Result extends TSchema[][] = []> = (Current extends [infer Left extends TSchema[], ...infer Right extends TSchema[][]] ? TAppend<Right, Type, [...Result, [...Left, Type]]> : Result);
847
+ type TCross<Current extends TSchema[][], Variants extends TSchema[], Result extends TSchema[][] = []> = (Variants extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TCross<Current, Right, [...Result, ...TAppend<Current, Left>]> : Result);
848
+ type TDistribute<ZippedArguments extends [boolean, TSchema][], Result extends TSchema[][] = [[]]> = (ZippedArguments extends [infer Left extends [boolean, TSchema], ...infer Right extends [boolean, TSchema][]] ? Left[0] extends true ? TDistribute<Right, TCross<Result, TExpand<Left[1]>>> : TDistribute<Right, TCross<Result, [Left[1]]>> : Result);
849
+ type TDistributeArguments<Parameters extends TParameter[], Arguments extends TSchema[], Expression extends TSchema, DistributionNames extends string[] = TCollectDistributionNames<Expression>, DistributionArray extends boolean[] = TBuildDistributionArray<Parameters, DistributionNames>, ZippedArguments extends [boolean, TSchema][] = TZipDistributionArray<Arguments, DistributionArray>, Result extends TSchema[][] = (Expression extends TDeferred<'Conditional', TSchema[]> ? TDistribute<ZippedArguments> : Expression extends TDeferred<'Mapped', TSchema[]> ? TDistribute<ZippedArguments> : [Arguments])> = Result;
850
+
851
+ type TFromNotResolvable = ([
852
+ '(not-resolvable)',
853
+ TNever
854
+ ]);
855
+ type TFromNotGeneric = ([
856
+ '(not-generic)',
857
+ TNever
858
+ ]);
859
+ type TFromGeneric<Name extends string, Parameters extends TParameter[], Expression extends TSchema> = ([
860
+ Name,
861
+ TGeneric<Parameters, Expression>
862
+ ]);
863
+ type TFromRef<Context extends TProperties, Ref extends string, Arguments extends TSchema[]> = (Ref extends keyof Context ? TFromType$c<Context, Ref, Context[Ref], Arguments> : TFromNotResolvable);
864
+ type TFromType$c<Context extends TProperties, Name extends string, Type extends TSchema, Arguments extends TSchema[]> = (Type extends TGeneric<infer Parameters extends TParameter[], infer Expression extends TSchema> ? TFromGeneric<Name, Parameters, Expression> : Type extends TRef<infer Ref extends string> ? TFromRef<Context, Ref, Arguments> : TFromNotGeneric);
865
+ /** Resolves a named generic target from the context, or returns TNever if it cannot be resolved or is not generic. */
866
+ type TResolveTarget<Context extends TProperties, Target extends TSchema, Arguments extends TSchema[], Result extends [string, TSchema] = TFromType$c<Context, '(anonymous)', Target, Arguments>> = Result;
867
+
868
+ type TBindArgument<Context extends TProperties, State extends TState, Name extends string, Extends extends TSchema, Type extends TSchema, InstantiatedArgument extends TSchema = TInstantiateType<Context, State, Type>> = TAssign<Context, {
869
+ [_ in Name]: InstantiatedArgument;
870
+ }>;
871
+ type TBindArguments<Context extends TProperties, State extends TState, ParameterLeft extends TParameter, ParameterRight extends TParameter[], Arguments extends TSchema[], InstantiatedExtends extends TSchema = TInstantiateType<Context, State, ParameterLeft['extends']>, InstantiatedEquals extends TSchema = TInstantiateType<Context, State, ParameterLeft['equals']>> = (Arguments extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TBindParameters<TBindArgument<Context, State, ParameterLeft['name'], InstantiatedExtends, Left>, State, ParameterRight, Right> : TBindParameters<TBindArgument<Context, State, ParameterLeft['name'], InstantiatedExtends, InstantiatedEquals>, State, ParameterRight, []>);
872
+ type TBindParameters<Context extends TProperties, State extends TState, Parameters extends TParameter[], Arguments extends TSchema[]> = (Parameters extends [infer Left extends TParameter, ...infer Right extends TParameter[]] ? TBindArguments<Context, State, Left, Right, Arguments> : Context);
873
+ type TResolveArgumentsContext<Context extends TProperties, State extends TState, Parameters extends TParameter[], Arguments extends TSchema[], Result extends TProperties = TBindParameters<Context, State, Parameters, Arguments>> = Result;
874
+
875
+ type TPeek<State extends TState, Result extends string = State['callstack'] extends [...infer _ extends string[], infer Top extends string] ? Top : ''> = Result;
876
+ type TIsTailCall<State extends TState, Name extends string, Result extends boolean = TPeek<State> extends Name ? true : false> = Result;
877
+ type TCallDispatch<Context extends TProperties, State extends TState, Target extends TRef, Parameters extends TParameter[], Expression extends TSchema, Arguments extends TSchema[], ArgumentsContext extends TProperties = TResolveArgumentsContext<Context, State, Parameters, Arguments>, ReturnType extends TSchema = TInstantiateType<ArgumentsContext, TState<[...State['callstack'], Target['$ref']], State['visited']>, Expression>> = TInstantiateType<ArgumentsContext, TState<[], []>, ReturnType>;
878
+ type TCallDistributed<Context extends TProperties, State extends TState, Target extends TRef, Parameters extends TParameter[], Expression extends TSchema, DistributedArguments extends TSchema[][], Result extends TSchema[] = []> = (DistributedArguments extends [infer Arguments extends TSchema[], ...infer DistributedArguments extends TSchema[][]] ? TCallDispatch<Context, State, Target, Parameters, Expression, Arguments> extends infer ReturnType extends TSchema ? TCallDistributed<Context, State, Target, Parameters, Expression, DistributedArguments, [...Result, ReturnType]> : never : Result);
879
+ type TCallImmediate<Context extends TProperties, State extends TState, Target extends TRef, Parameters extends TParameter[], Expression extends TSchema, InstantiatedArguments extends TSchema[], DistributedArguments extends TSchema[][] = TDistributeArguments<Parameters, InstantiatedArguments, Expression>, ReturnTypes extends TSchema[] = TCallDistributed<Context, State, Target, Parameters, Expression, DistributedArguments>, Result extends TSchema = ReturnTypes['length'] extends 1 ? ReturnTypes[0] : TEvaluateUnion<ReturnTypes>> = Result;
880
+ type TCallInstantiate<Context extends TProperties, State extends TState, Target extends TSchema, Arguments extends TSchema[], InstantiatedArguments extends TSchema[] = TInstantiateTypes<Context, State, Arguments>, Resolved extends [string, TSchema] = TResolveTarget<Context, Target, Arguments>, Name extends string = Resolved[0], Type extends TSchema = Resolved[1], Result extends TSchema = (Type extends TGeneric<infer Parameters extends TParameter[], infer Expression extends TSchema> ? TIsTailCall<State, Name> extends true ? TCallConstruct<TRef<Name>, InstantiatedArguments> : TCallImmediate<Context, State, TRef<Name>, Parameters, Expression, InstantiatedArguments> : TCallConstruct<Target, InstantiatedArguments>)> = Result;
881
+
882
+ /** Represents a deferred generic Call */
883
+ interface TCall<Target extends TSchema = TSchema, Arguments extends TSchema[] = TSchema[]> extends TSchema {
884
+ '~kind': 'Call';
885
+ type: 'call';
886
+ target: Target;
887
+ arguments: Arguments;
888
+ }
889
+ type TCallConstruct<Target extends TSchema, Arguments extends TSchema[], Result extends TSchema = TCall<Target, Arguments>> = Result;
890
+
891
+ type TRemoveImmutableOperation<Type extends TSchema, Result extends TSchema = Type extends TImmutable<infer Type extends TSchema> ? TRemoveImmutableOperation<Type> : Type> = Result;
892
+ type TRemoveImmutableAction<Type extends TSchema, Result extends TSchema = TRemoveImmutableOperation<Type>> = Result;
893
+ type TRemoveImmutableInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TRemoveImmutableAction<InstantiateType>;
894
+
895
+ interface TMappingType {
896
+ input: string;
897
+ output: string;
898
+ }
899
+ type TApplyMapping<Mapping extends TMappingType, Value extends string> = ((Mapping & {
900
+ input: Value;
901
+ })['output']);
902
+
903
+ type TFromLiteral$2<Mapping extends TMappingType, Value extends TLiteralValue> = (Value extends string ? TLiteral<TApplyMapping<Mapping, Value>> : TLiteral<Value>);
904
+
905
+ type TFromTemplateLiteral$2<Mapping extends TMappingType, Pattern extends string, Evaluated extends TSchema = TEvaluateTemplateLiteral<Pattern>, Result extends TSchema = TFromType$b<Mapping, Evaluated>> = Result;
906
+
907
+ type TFromUnion$6<Mapping extends TMappingType, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromUnion$6<Mapping, Right, [...Result, TFromType$b<Mapping, Left>]> : TUnion<Result>);
908
+
909
+ type TFromType$b<Mapping extends TMappingType, Type extends TSchema> = (Type extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteral$2<Mapping, Value> : Type extends TTemplateLiteral<infer Pattern extends string> ? TFromTemplateLiteral$2<Mapping, Pattern> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion$6<Mapping, Types> : Type);
910
+
911
+ /** Creates a deferred Capitalize action. */
912
+ type TCapitalizeDeferred<Type extends TSchema> = (TDeferred<'Capitalize', [Type]>);
913
+
914
+ /** Creates a deferred Lowercase action. */
915
+ type TLowercaseDeferred<Type extends TSchema> = (TDeferred<'Lowercase', [Type]>);
916
+
917
+ /** Creates a deferred Uncapitalize action. */
918
+ type TUncapitalizeDeferred<Type extends TSchema> = (TDeferred<'Uncapitalize', [Type]>);
919
+
920
+ /** Creates a deferred Uppercase action. */
921
+ type TUppercaseDeferred<Type extends TSchema> = (TDeferred<'Uppercase', [Type]>);
922
+
923
+ interface TCapitalizeMapping extends TMappingType {
924
+ output: Capitalize<this['input']>;
925
+ }
926
+ interface TLowercaseMapping extends TMappingType {
927
+ output: Lowercase<this['input']>;
928
+ }
929
+ interface TUncapitalizeMapping extends TMappingType {
930
+ output: Uncapitalize<this['input']>;
931
+ }
932
+ interface TUppercaseMapping extends TMappingType {
933
+ output: Uppercase<this['input']>;
934
+ }
935
+ type TCapitalizeAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TFromType$b<TCapitalizeMapping, Type> : TCapitalizeDeferred<Type>> = Result;
936
+ type TLowercaseAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TFromType$b<TLowercaseMapping, Type> : TLowercaseDeferred<Type>> = Result;
937
+ type TUncapitalizeAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TFromType$b<TUncapitalizeMapping, Type> : TUncapitalizeDeferred<Type>> = Result;
938
+ type TUppercaseAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TFromType$b<TUppercaseMapping, Type> : TUppercaseDeferred<Type>> = Result;
939
+ type TCapitalizeInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TCapitalizeAction<InstantiatedType>;
940
+ type TLowercaseInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TLowercaseAction<InstantiatedType>;
941
+ type TUncapitalizeInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TUncapitalizeAction<InstantiatedType>;
942
+ type TUppercaseInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TUppercaseAction<InstantiatedType>;
943
+
944
+ /** Creates a deferred Conditional action. */
945
+ type TConditionalDeferred<Left extends TSchema, Right extends TSchema, True extends TSchema, False extends TSchema> = (TDeferred<'Conditional', [Left, Right, True, False]>);
946
+
947
+ type TConditionalOperation<Context extends TProperties, State extends TState, Left extends TSchema, Right extends TSchema, True extends TSchema, False extends TSchema, ExtendsResult extends TResult = TExtends<Context, Left, Right>> = (ExtendsResult extends ExtendsResult.TExtendsUnion<infer InferredContext extends TProperties> ? TUnion<[TInstantiateType<InferredContext, State, True>, TInstantiateType<Context, State, False>]> : ExtendsResult extends ExtendsResult.TExtendsTrue<infer InferredContext extends TProperties> ? TInstantiateType<InferredContext, State, True> : TInstantiateType<Context, State, False>);
948
+ type TConditionalAction<Context extends TProperties, State extends TState, Left extends TSchema, Right extends TSchema, True extends TSchema, False extends TSchema, Result extends TSchema = TCanInstantiate<[Left, Right]> extends true ? TConditionalOperation<Context, State, Left, Right, True, False> : TConditionalDeferred<Left, Right, True, False>> = Result;
949
+ type TConditionalInstantiate<Context extends TProperties, State extends TState, Left extends TSchema, Right extends TSchema, True extends TSchema, False extends TSchema, InstaniatedLeft extends TSchema = TInstantiateType<Context, State, Left>, InstaniatedRight extends TSchema = TInstantiateType<Context, State, Right>> = TConditionalAction<Context, State, InstaniatedLeft, InstaniatedRight, True, False>;
950
+
951
+ /** Creates a deferred ConstructorParameters action. */
952
+ type TConstructorParametersDeferred<Type extends TSchema> = (TDeferred<'ConstructorParameters', [Type]>);
953
+
954
+ type TConstructorParametersOperation<Type extends TSchema, Parameters extends TSchema[] = Type extends TConstructor ? Type['parameters'] : [], InstantiatedParameters extends TSchema[] = TInstantiateElements<{}, TState<[], []>, Parameters>, Result extends TSchema = TTuple<InstantiatedParameters>> = Result;
955
+ type TConstructorParametersAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TConstructorParametersOperation<Type> : TConstructorParametersDeferred<Type>> = Result;
956
+ type TConstructorParametersInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TConstructorParametersAction<InstantiatedType>;
957
+
958
+ /** Creates a deferred Exclude action. */
959
+ type TExcludeDeferred<Left extends TSchema, Right extends TSchema> = (TDeferred<'Exclude', [Left, Right]>);
960
+
961
+ type TExcludeAction<Left extends TSchema, Right extends TSchema, Result extends TSchema = TCanInstantiate<[Left, Right]> extends true ? TExcludeOperation<Left, Right> : TExcludeDeferred<Left, Right>> = Result;
962
+ type TExcludeInstantiate<Context extends TProperties, State extends TState, Left extends TSchema, Right extends TSchema, InstantiatedLeft extends TSchema = TInstantiateType<Context, State, Left>, InstantiatedRight extends TSchema = TInstantiateType<Context, State, Right>> = TExcludeAction<InstantiatedLeft, InstantiatedRight>;
963
+
964
+ /** Creates a deferred Extract action. */
965
+ type TExtractDeferred<Left extends TSchema, Right extends TSchema> = (TDeferred<'Extract', [Left, Right]>);
966
+
967
+ type TExtractType<Left extends TSchema, Right extends TSchema, Check extends TResult = TExtends<{}, Left, Right>, Result extends TSchema[] = Check extends TExtendsTrueLike ? [Left] : []> = Result;
968
+ type TExtractUnion<Left extends TSchema[], Right extends TSchema, Result extends TSchema[] = []> = (Left extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExtractUnion<Tail, Right, [...Result, ...TExtractType<Head, Right>]> : Result);
969
+ type TExtractOperation<Left extends TSchema, Right extends TSchema, Evaluated extends TSchema = TEvaluateType<Left>, Canonical extends TSchema[] = Evaluated extends TUnion<infer Types extends TSchema[]> ? Types : [Evaluated], Remaining extends TSchema[] = TExtractUnion<Canonical, Right>, Result extends TSchema = TEvaluateUnion<Remaining>> = Result;
970
+
971
+ type TExtractAction<Left extends TSchema, Right extends TSchema, Result extends TSchema = TCanInstantiate<[Left, Right]> extends true ? TExtractOperation<Left, Right> : TExtractDeferred<Left, Right>> = Result;
972
+ type TExtractInstantiate<Context extends TProperties, State extends TState, Left extends TSchema, Right extends TSchema, InstantiatedLeft extends TSchema = TInstantiateType<Context, State, Left>, InstantiatedRight extends TSchema = TInstantiateType<Context, State, Right>> = TExtractAction<InstantiatedLeft, InstantiatedRight>;
973
+
974
+ /** Creates a deferred Index action. */
975
+ type TIndexDeferred<Type extends TSchema, Indexer extends TSchema> = (TDeferred<'Index', [Type, Indexer]>);
976
+
977
+ type TFromCyclic$4<Defs extends TProperties, Ref extends string, Target extends TSchema = TCyclicTarget<Defs, Ref>, Result extends TProperties = TFromType$a<Target>> = Result;
978
+
979
+ type TFromDependent$4<If extends TSchema, Then extends TSchema, Else extends TSchema, Evaluated extends TSchema = TEvaluateDependent<If, Then, Else>, Result extends TSchema = TFromType$a<Evaluated>> = Result;
980
+
981
+ type TCollapseIntersectProperties<Left extends TProperties, Right extends TProperties, LeftKeys extends keyof Left = Exclude<keyof Left, keyof Right>, RightKeys extends keyof Right = Exclude<keyof Right, keyof Left>, SharedKeys extends keyof Left & keyof Right = Extract<keyof Left, keyof Right>, LeftProperties extends TProperties = {
982
+ [Key in LeftKeys]: Left[Key];
983
+ }, RightProperties extends TProperties = {
984
+ [Key in RightKeys]: Right[Key];
985
+ }, SharedProperties extends TProperties = {
986
+ [Key in SharedKeys]: TEvaluateIntersect<[Left[Key], Right[Key]]>;
987
+ }, Unique extends TProperties = TAssign<LeftProperties, RightProperties>, Shared extends TProperties = TAssign<Unique, SharedProperties>> = Shared;
988
+ type TFromIntersect$4<Types extends TSchema[], Result extends TProperties = {}> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromIntersect$4<Right, TCollapseIntersectProperties<Result, TFromType$a<Left>>> : {
989
+ [Key in keyof Result]: Result[Key];
990
+ });
991
+
992
+ type TFromObject$5<Properties extends TProperties> = (Properties);
993
+
994
+ type TFromTuple$3<Types extends TSchema[], Object extends TSchema = TTupleToObject<TTuple<Types>>, Result extends TSchema = TFromType$a<Object>> = Result;
995
+
996
+ type TCollapseUnionProperties<Left extends TProperties, Right extends TProperties, SharedKeys extends PropertyKey = keyof Left & keyof Right, Result extends TProperties = {
997
+ [Key in SharedKeys]: TEvaluateUnion<[Left[Key], Right[Key]]>;
998
+ }> = Result;
999
+ type TReduceVariants<Types extends TSchema[], Result extends TProperties> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TReduceVariants<Right, TCollapseUnionProperties<Result, TFromType$a<Left>>> : Result);
1000
+ type TFromUnion$5<Types extends TSchema[]> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TReduceVariants<Right, TFromType$a<Left>> : TUnreachable);
1001
+
1002
+ type TFromType$a<Type extends TSchema, Result extends TProperties = (Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? TFromCyclic$4<Defs, Ref> : Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TFromDependent$4<If, Then, Else> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect$4<Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion$5<Types> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple$3<Types> : Type extends TObject<infer Properties extends TProperties> ? TFromObject$5<Properties> : {})> = Result;
1003
+
1004
+ type TCollapseToObject<Type extends TSchema, Properties extends TProperties = TFromType$a<Type>, Result extends TSchema = TObject<Properties>> = Result;
1005
+
1006
+ type TConvertToIntegerKey<Value extends TLiteralValue, Normal extends string = `${Value}`, Result extends TLiteralValue = (Normal extends ` ${infer _ extends number}` ? Normal : Normal extends `${infer _ extends number} ` ? Normal : Normal extends `0${infer _ extends number}` ? Normal : Normal extends `-${infer _ extends number}` ? Normal : Normal extends `${infer Value extends number}` ? Value : Value)> = Result;
1007
+
1008
+ type TNormalizeLiteral<Value extends TLiteralValue, Result extends TSchema = TLiteral<TConvertToIntegerKey<Value>>> = Result;
1009
+ type TNormalizeIndexerTypes<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TNormalizeIndexerTypes<Right, [...Result, TNormalizeIndexer<Left>]> : Result);
1010
+ type TNormalizeIndexer<Type extends TSchema, Result extends TSchema = (Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TNormalizeIndexerTypes<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TNormalizeIndexerTypes<Types>> : Type extends TLiteral<infer Value extends TLiteralValue> ? TNormalizeLiteral<Value> : Type)> = Result;
1011
+ type TFromArray$2<Type extends TSchema, Indexer extends TSchema, NormalizedIndexer extends TSchema = TNormalizeIndexer<Indexer>, Check extends TResult = TExtends<{}, NormalizedIndexer, TNumber>, Result extends TSchema = (Check extends TExtendsTrueLike ? Type : Indexer extends TLiteral<infer _ extends 'length'> ? TNumber : TNever)> = Result;
1012
+
1013
+ type TFromCyclic$3<Defs extends TProperties, Ref extends string, Target extends TSchema = TCyclicTarget<Defs, Ref>, Result extends string[] = TFromType$9<Target>> = Result;
1014
+
1015
+ type TFromDependent$3<If extends TSchema, Then extends TSchema, Else extends TSchema, Evaluated extends TSchema = TEvaluateDependent<If, Then, Else>, Result extends string[] = TFromType$9<Evaluated>> = Result;
1016
+
1017
+ type TFromEnum$1<Values extends TEnumValue[], Evaluated extends TSchema = TEvaluateEnum<Values>, Result extends string[] = TFromType$9<Evaluated>> = Result;
1018
+
1019
+ type TFromIntersect$3<Types extends TSchema[], Evaluated extends TSchema = TEvaluateIntersect<Types>, Result extends string[] = TFromType$9<Evaluated>> = Result;
1020
+
1021
+ type TFromLiteral$1<Value extends TLiteralValue, Result extends string[] = [`${Value}`]> = Result;
1022
+
1023
+ type TFromTemplateLiteral$1<Pattern extends string, Evaluated extends TSchema = TEvaluateTemplateLiteral<Pattern>, Result extends string[] = TFromType$9<Evaluated>> = Result;
1024
+
1025
+ type TFromUnion$4<Types extends TSchema[], Result extends string[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromUnion$4<Right, [...Result, ...TFromType$9<Left>]> : Result);
1026
+
1027
+ type TFromType$9<Indexer extends TSchema, Result extends string[] = (Indexer extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? TFromCyclic$3<Defs, Ref> : Indexer extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TFromDependent$3<If, Then, Else> : Indexer extends TEnum<infer Values extends TEnumValue[]> ? TFromEnum$1<Values> : Indexer extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect$3<Types> : Indexer extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteral$1<Value> : Indexer extends TTemplateLiteral<infer Pattern extends string> ? TFromTemplateLiteral$1<Pattern> : Indexer extends TUnion<infer Types extends TSchema[]> ? TFromUnion$4<Types> : [
1028
+ ])> = Result;
1029
+
1030
+ type TToIndexableKeys<Indexer extends TSchema, Result extends string[] = TFromType$9<Indexer>> = Result;
1031
+
1032
+ type TFromTypes<Properties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromTypes<Properties, Right, [...Result, TFromType$8<Properties, Left>]> : Result);
1033
+ type TFromType$8<Properties extends TProperties, Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TArray<TFromType$8<Properties, Type>> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TConstructor<TFromTypes<Properties, Parameters>, TFromType$8<Properties, InstanceType>> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TFromTypes<Properties, Parameters>, TFromType$8<Properties, ReturnType>> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TFromTypes<Properties, Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromTypes<Properties, Types>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromTypes<Properties, Types>> : Type extends TThis ? TObject<Properties> : Type);
1034
+ type TExpandThis<Properties extends TProperties, Type extends TSchema, Result extends TSchema = TFromType$8<Properties, Type>> = Result;
1035
+
1036
+ type TIndexProperty<Properties extends TProperties, Key extends string, CanonicalKey extends string = keyof Properties extends string | number ? `${keyof Properties}` : never, SelectedType extends TSchema = Key extends CanonicalKey ? Properties[Key] : TNever, Result extends TSchema = TExpandThis<Properties, SelectedType>> = Result;
1037
+ type TIndexProperties<Properties extends TProperties, Keys extends string[], Result extends TSchema[] = []> = (Keys extends [infer Left extends string, ...infer Right extends string[]] ? TIndexProperties<Properties, Right, [...Result, TIndexProperty<Properties, Left>]> : Result);
1038
+ type TFromIndexer<Properties extends TProperties, Indexer extends TSchema, Keys extends string[] = TToIndexableKeys<Indexer>, Variants extends TSchema[] = TIndexProperties<Properties, Keys>, Result extends TSchema = TEvaluateUnion<Variants>> = Result;
1039
+ type TNumericKeys<Keys extends string[], Result extends string[] = []> = (Keys extends [infer Left extends string, ...infer Right extends string[]] ? Left extends `${infer _ extends number}` ? TNumericKeys<Right, [...Result, Left]> : TNumericKeys<Right, Result> : Result);
1040
+ type TFromIndexerNumber<Properties extends TProperties, Keys extends string[] = TPropertyKeys<Properties>, NumericKeys extends string[] = TNumericKeys<Keys>, Variants extends TSchema[] = TIndexProperties<Properties, NumericKeys>, Result extends TSchema = TEvaluateUnion<Variants>> = Result;
1041
+ type TFromObject$4<Properties extends TProperties, Indexer extends TSchema, Result extends TSchema = Indexer extends TNumber ? TFromIndexerNumber<Properties> : TFromIndexer<Properties, Indexer>> = Result;
1042
+
1043
+ type TConvertLiteral<Value extends TLiteralValue, Result extends TSchema = TLiteral<TConvertToIntegerKey<Value>>> = Result;
1044
+ type TArrayIndexerTypes<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TArrayIndexerTypes<Right, [...Result, TFormatArrayIndexer<Left>]> : Result);
1045
+ /** Formats embedded integer-like strings on an Indexer to be number values inline with TS indexing | coercion behaviors. */
1046
+ type TFormatArrayIndexer<Type extends TSchema, Result extends TSchema = (Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TArrayIndexerTypes<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TArrayIndexerTypes<Types>> : Type extends TLiteral<infer Value extends TLiteralValue> ? TConvertLiteral<Value> : Type)> = Result;
1047
+
1048
+ type TIndexElementsWithIndexer<Types extends TSchema[], Indexer extends TSchema, Result extends TSchema[] = []> = (Types extends [...infer Left extends TSchema[], infer Right extends TSchema] ? TExtends<{}, TLiteral<Left['length']>, Indexer> extends TExtendsTrueLike ? TIndexElementsWithIndexer<Left, Indexer, [Right, ...Result]> : TIndexElementsWithIndexer<Left, Indexer, Result> : Result);
1049
+ type TFromTupleWithIndexer<Types extends TSchema[], Indexer extends TSchema, ArrayIndexer extends TSchema = TFormatArrayIndexer<Indexer>, Elements extends TSchema[] = TIndexElementsWithIndexer<Types, ArrayIndexer>, Result extends TSchema = TEvaluateUnionFast<Elements>> = Result;
1050
+ type TFromTupleWithoutIndexer<Types extends TSchema[], Result extends TSchema = TEvaluateUnionFast<Types>> = Result;
1051
+ type TFromTuple$2<Types extends TSchema[], Indexer extends TSchema, Result extends TSchema = (Indexer extends TLiteral<infer _ extends 'length'> ? TLiteral<Types['length']> : Indexer extends TNumber | TInteger ? TFromTupleWithoutIndexer<Types> : TFromTupleWithIndexer<Types, Indexer>)> = Result;
1052
+
1053
+ type TFromType$7<Type extends TSchema, Indexer extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TFromArray$2<Type, Indexer> : Type extends TObject<infer Properties extends TProperties> ? TFromObject$4<Properties, Indexer> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple$2<Types, Indexer> : TNever);
1054
+
1055
+ type TNormalizeType$1<Type extends TSchema, Result extends TSchema = (Type extends TCyclic ? TCollapseToObject<Type> : Type extends TDependent ? TCollapseToObject<Type> : Type extends TIntersect ? TCollapseToObject<Type> : Type extends TUnion ? TCollapseToObject<Type> : Type)> = Result;
1056
+ type TIndexAction<Type extends TSchema, Indexer extends TSchema, Result extends TSchema = TCanInstantiate<[Type, Indexer]> extends true ? TFromType$7<TNormalizeType$1<Type>, Indexer> : TIndexDeferred<Type, Indexer>> = Result;
1057
+ type TIndexInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, Indexer extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>, InstantiatedIndexer extends TSchema = TInstantiateType<Context, State, Indexer>> = TIndexAction<InstantiatedType, InstantiatedIndexer>;
1058
+
1059
+ /** Creates a deferred InstanceType action. */
1060
+ type TInstanceTypeDeferred<Type extends TSchema> = (TDeferred<'InstanceType', [Type]>);
1061
+
1062
+ type TInstanceTypeOperation<Type extends TSchema> = (Type extends TConstructor ? Type['instanceType'] : TNever);
1063
+ type TInstanceTypeAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TInstanceTypeOperation<Type> : TInstanceTypeDeferred<Type>> = Result;
1064
+ type TInstanceTypeInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TInstanceTypeAction<InstantiatedType>;
1065
+
1066
+ /** Creates a deferred KeyOf action. */
1067
+ type TKeyOfDeferred<Type extends TSchema> = (TDeferred<'KeyOf', [Type]>);
1068
+
1069
+ type TFromAny<Result = TUnion<[TNumber, TString, TSymbol]>> = Result;
1070
+
1071
+ type TFromArray$1<_Type extends TSchema> = TNumber;
1072
+
1073
+ type TFromPropertyKeys<Keys extends PropertyKey[], Result extends TSchema[] = []> = (Keys extends [infer Left extends PropertyKey, ...infer Right extends PropertyKey[]] ? Left extends TLiteralValue ? TFromPropertyKeys<Right, [...Result, TLiteral<Left>]> : TUnreachable : Result);
1074
+ type TFromObject$3<Properties extends TProperties, PropertyKeys extends PropertyKey[] = TUnionToTuple<keyof Properties>, Variants extends TSchema[] = TFromPropertyKeys<PropertyKeys>, Result extends TSchema = TEvaluateUnionFast<Variants>> = Result;
1075
+
1076
+ type TFromRecord<Type extends TRecord, Result extends TSchema = TRecordKey<Type>> = Result;
1077
+
1078
+ type TFromTuple$1<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [...infer Left extends TSchema[], infer _ extends TSchema] ? TFromTuple$1<Left, [TLiteral<Left['length']>, ...Result]> : TEvaluateUnionFast<Result>);
1079
+
1080
+ type TFromType$6<Type extends TSchema> = (Type extends TAny ? TFromAny : Type extends TArray<infer Type extends TSchema> ? TFromArray$1<Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject$3<Properties> : Type extends TRecord ? TFromRecord<Type> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple$1<Types> : TNever);
1081
+
1082
+ type TNormalizeType<Type extends TSchema, Result extends TSchema = (Type extends TCyclic ? TCollapseToObject<Type> : Type extends TDependent ? TCollapseToObject<Type> : Type extends TIntersect ? TCollapseToObject<Type> : Type extends TUnion ? TCollapseToObject<Type> : Type)> = Result;
1083
+ type TKeyOfAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TFromType$6<TNormalizeType<Type>> : TKeyOfDeferred<Type>> = Result;
1084
+ type TKeyOfInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TKeyOfAction<InstantiatedType>;
1085
+
1086
+ /** Creates a deferred Mapped action. */
1087
+ type TMappedDeferred<Identifier extends TIdentifier, Type extends TSchema, As extends TSchema, Property extends TSchema> = (TDeferred<'Mapped', [Identifier, Type, As, Property]>);
1088
+
1089
+ type TFromTemplateLiteral<Pattern extends string, Evaluated extends TSchema = TEvaluateTemplateLiteral<Pattern>, Result extends TSchema[] = TFromType$5<Evaluated>> = Result;
1090
+ type TFromUnion$3<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromUnion$3<Right, [...Result, ...TFromType$5<Left>]> : Result);
1091
+ type TFromEnum<Values extends TEnumValue[], Evaluated extends TSchema = TEvaluateEnum<Values>, Result extends TSchema[] = TFromType$5<Evaluated>> = Result;
1092
+ type TFromLiteral<Value extends TLiteralValue, Result extends TSchema[] = Value extends number ? [TLiteral<`${Value}`>] : [TLiteral<Value>]> = Result;
1093
+ type TFromType$5<Type extends TSchema, Result extends TSchema[] = (Type extends TEnum<infer Values extends TEnumValue[]> ? TFromEnum<Values> : Type extends TLiteral<infer Value extends number> ? TFromLiteral<Value> : Type extends TTemplateLiteral<infer Pattern extends string> ? TFromTemplateLiteral<Pattern> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion$3<Types> : [
1094
+ Type
1095
+ ])> = Result;
1096
+ type TMappedVariants<Type extends TSchema, Result extends TSchema[] = TFromType$5<Type>> = Result;
1097
+
1098
+ type TCanonicalAs<InstantiatedAs extends TSchema, Result extends TSchema = InstantiatedAs extends TTemplateLiteral<infer Pattern extends string> ? TEvaluateTemplateLiteral<Pattern> : InstantiatedAs> = Result;
1099
+ type TMappedVariant<Context extends TProperties, State extends TState, Identifier extends TIdentifier, Variant extends TSchema, As extends TSchema, Property extends TSchema, VariantContext extends TProperties = TAssign<Context, {
1100
+ [_ in Identifier['name']]: Variant;
1101
+ }>, InstantiatedAs extends TSchema = TInstantiateType<VariantContext, State, As>, CanonicalAs extends TSchema = TCanonicalAs<InstantiatedAs>, InstantiatedProperty extends TSchema = TInstantiateType<VariantContext, State, Property>, Result extends TProperties = CanonicalAs extends TLiteral<string | number> ? {
1102
+ [_ in CanonicalAs['const']]: InstantiatedProperty;
1103
+ } : {}> = Result;
1104
+ type TMappedProperties<Context extends TProperties, State extends TState, Identifier extends TIdentifier, Variants extends TSchema[], As extends TSchema, Property extends TSchema, Result extends TProperties[] = []> = (Variants extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TMappedProperties<Context, State, Identifier, Right, As, Property, [...Result, TMappedVariant<Context, State, Identifier, Left, As, Property>]> : Result);
1105
+ type TReduceProperties<Properties extends TProperties[], Result extends TSchema[] = []> = (Properties extends [infer Left extends TProperties, ...infer Right extends TProperties[]] ? TReduceProperties<Right, [...Result, TObject<Left>]> : Result);
1106
+ type TMappedOperation<Context extends TProperties, State extends TState, Identifier extends TIdentifier, Type extends TSchema, As extends TSchema, Property extends TSchema, Variants extends TSchema[] = TMappedVariants<Type>, MappedProperties extends TProperties[] = TMappedProperties<Context, State, Identifier, Variants, As, Property>, MappedObjects extends TSchema[] = TReduceProperties<MappedProperties>, Result extends TSchema = TEvaluateIntersect<MappedObjects>> = Result;
1107
+
1108
+ type TMappedAction<Context extends TProperties, State extends TState, Identifier extends TIdentifier, Type extends TSchema, As extends TSchema, Property extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TMappedOperation<Context, State, Identifier, Type, As, Property> : TMappedDeferred<Identifier, Type, As, Property>> = Result;
1109
+ type TMappedInstantiate<Context extends TProperties, State extends TState, Identifier extends TIdentifier, Type extends TSchema, As extends TSchema, Property extends TSchema, InstaniatedType extends TSchema = TInstantiateType<Context, State, Type>> = TMappedAction<Context, State, Identifier, InstaniatedType, As, Property>;
1110
+
1111
+ type TInstantiateCyclics<Context extends TProperties, Declarations extends TProperties, CyclicKeys extends string[], DeclarationContext extends TProperties = TAssign<Context, Declarations>, Result extends TProperties = {
1112
+ [Key in Extract<keyof Declarations, CyclicKeys[number]>]: TInstantiateCyclic<DeclarationContext, Key, Declarations[Key]>;
1113
+ }> = Result;
1114
+ type TInstantiateNonCyclics<Context extends TProperties, Declarations extends TProperties, CyclicKeys extends string[], DeclarationContext extends TProperties = TAssign<Context, Declarations>, Result extends TProperties = {
1115
+ [Key in Exclude<keyof Declarations, CyclicKeys[number]>]: TInstantiateType<DeclarationContext, TState<[], []>, Declarations[Key]>;
1116
+ }> = Result;
1117
+ type TInstantiateModule<Context extends TProperties, Declarations extends TProperties, CyclicCandidates extends string[] = TCyclicCandidates<Declarations>, InstantiatedCyclics extends TProperties = TInstantiateCyclics<Context, Declarations, CyclicCandidates>, InstantiatedNonCyclics extends TProperties = TInstantiateNonCyclics<Context, Declarations, CyclicCandidates>, InstantiatedModule extends TProperties = InstantiatedCyclics & InstantiatedNonCyclics> = {
1118
+ [Key in keyof InstantiatedModule]: InstantiatedModule[Key];
1119
+ } & {};
1120
+ type TModuleInstantiate<Context extends TProperties, _State extends TState, Declarations extends TProperties, InstantiatedModule extends TProperties = TInstantiateModule<Context, Declarations>> = InstantiatedModule;
1121
+
1122
+ /** Creates a deferred NonNullable action. */
1123
+ type TNonNullableDeferred<Type extends TSchema> = (TDeferred<'NonNullable', [Type]>);
1124
+
1125
+ type TNonNullableOperation<Type extends TSchema, Excluded extends TSchema = TUnion<[TNull, TUndefined]>> = TExcludeAction<Type, Excluded>;
1126
+ type TNonNullableAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TNonNullableOperation<Type> : TNonNullableDeferred<Type>> = Result;
1127
+ type TNonNullableInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TNonNullableAction<InstantiatedType>;
1128
+
1129
+ /** Creates a deferred Omit action. */
1130
+ type TOmitDeferred<Type extends TSchema, Indexer extends TSchema> = (TDeferred<'Omit', [Type, Indexer]>);
1131
+
1132
+ /** Transforms a type into a TProperties used for indexing operations */
1133
+ type TToIndexable<Type extends TSchema, Collapsed extends TSchema = TCollapseToObject<Type>, Result extends TProperties = (Collapsed extends TObject<infer Properties extends TProperties> ? Properties : TUnreachable)> = Result;
1134
+
1135
+ type TNormalKeys<Keys extends string[], UnionKeys extends string = Keys[number], Result extends string | number = (UnionKeys extends `${infer Value extends number}` ? UnionKeys | Value : UnionKeys)> = Result;
1136
+ type TFromKeys$1<Properties extends TProperties, Keys extends string[], Omitted extends TProperties = Omit<Properties, TNormalKeys<Keys>>, Result extends TProperties = {
1137
+ [Key in keyof Omitted]: Omitted[Key];
1138
+ }> = Result;
1139
+ type TFromType$4<Type extends TSchema, Indexer extends TSchema, Indexable extends TProperties = TToIndexable<Type>, IndexableKeys extends string[] = TToIndexableKeys<Indexer>, Omitted extends TProperties = TFromKeys$1<Indexable, IndexableKeys>, Result extends TSchema = TObject<Omitted>> = Result;
1140
+
1141
+ type TOmitAction<Type extends TSchema, Indexer extends TSchema, Result extends TSchema = TCanInstantiate<[Type, Indexer]> extends true ? TFromType$4<Type, Indexer> : TOmitDeferred<Type, Indexer>> = Result;
1142
+ type TOmitInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, Indexer extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>, InstantiatedIndexer extends TSchema = TInstantiateType<Context, State, Indexer>> = TOmitAction<InstantiatedType, InstantiatedIndexer>;
1143
+
1144
+ /** Creates a deferred Parameters action. */
1145
+ type TParametersDeferred<Type extends TSchema> = (TDeferred<'Parameters', [Type]>);
1146
+
1147
+ type TParametersOperation<Type extends TSchema, Parameters extends TSchema[] = Type extends TFunction ? Type['parameters'] : [], InstantiatedParameters extends TSchema[] = TInstantiateElements<{}, TState<[], []>, Parameters>, Result extends TSchema = TTuple<InstantiatedParameters>> = Result;
1148
+ type TParametersAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TParametersOperation<Type> : TParametersDeferred<Type>> = Result;
1149
+ type TParametersInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TParametersAction<InstantiatedType>;
1150
+
1151
+ /** Creates a deferred Partial action. */
1152
+ type TPartialDeferred<Type extends TSchema> = (TDeferred<'Partial', [Type]>);
1153
+
1154
+ type TFromCyclic$2<Defs extends TProperties, Ref extends string, Target extends TSchema = TCyclicTarget<Defs, Ref>, Partial extends TSchema = TFromType$3<Target>, Result extends TSchema = TCyclic<TAssign<Defs, {
1155
+ [_ in Ref]: Partial;
1156
+ }>, Ref>> = Result;
1157
+
1158
+ type TFromDependent$2<If extends TSchema, Then extends TSchema, Else extends TSchema, Evaluated extends TSchema = TEvaluateDependent<If, Then, Else>, Result extends TSchema = TFromType$3<Evaluated>> = Result;
1159
+
1160
+ type TFromIntersect$2<Types extends TSchema[], Evaluated extends TSchema = TEvaluateIntersect<Types>, Result extends TSchema = TFromType$3<Evaluated>> = Result;
1161
+
1162
+ type TFromUnion$2<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromUnion$2<Right, [...Result, TFromType$3<Left>]> : TUnion<Result>);
1163
+
1164
+ type TFromObject$2<Properties extends TProperties, Mapped extends TProperties = {
1165
+ [Key in keyof Properties]: TAddOptional<Properties[Key]>;
1166
+ }, Result extends TSchema = TObject<Mapped>> = Result;
1167
+
1168
+ type TFromType$3<Type extends TSchema> = (Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? TFromCyclic$2<Defs, Ref> : Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TFromDependent$2<If, Then, Else> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect$2<Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion$2<Types> : Type extends TObject<infer Properties extends TProperties> ? TFromObject$2<Properties> : TObject<{}>);
1169
+
1170
+ type TPartialAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TFromType$3<Type> : TPartialDeferred<Type>> = Result;
1171
+ type TPartialInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TPartialAction<InstantiatedType>;
1172
+
1173
+ /** Creates a deferred Pick action. */
1174
+ type TPickDeferred<Type extends TSchema, Indexer extends TSchema> = (TDeferred<'Pick', [Type, Indexer]>);
1175
+
1176
+ type TComparable<Indexable extends TProperties> = (keyof Indexable extends string | number ? `${keyof Indexable}` : never);
1177
+ type TFromKeys<Indexable extends TProperties, Keys extends string[], Result extends TProperties = {}> = (Keys extends [infer Left extends string, ...infer Right extends string[]] ? Left extends TComparable<Indexable> ? TFromKeys<Indexable, Right, TAssign<Result, {
1178
+ [_ in Left]: Indexable[Left];
1179
+ }>> : TFromKeys<Indexable, Right, Result> : Result);
1180
+ type TFromType$2<Type extends TSchema, Indexer extends TSchema, Indexable extends TProperties = TToIndexable<Type>, Keys extends string[] = TToIndexableKeys<Indexer>, Applied extends TProperties = TFromKeys<Indexable, Keys>, Result extends TSchema = TObject<Applied>> = Result;
1181
+
1182
+ type TPickAction<Type extends TSchema, Indexer extends TSchema, Result extends TSchema = TCanInstantiate<[Type, Indexer]> extends true ? TFromType$2<Type, Indexer> : TPickDeferred<Type, Indexer>> = Result;
1183
+ type TPickInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, Indexer extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>, InstantiatedIndexer extends TSchema = TInstantiateType<Context, State, Indexer>> = TPickAction<InstantiatedType, InstantiatedIndexer>;
1184
+
1185
+ /** Creates a deferred ReadonlyType action. */
1186
+ type TReadonlyObjectDeferred<Type extends TSchema> = (TDeferred<'ReadonlyObject', [Type]>);
1187
+
1188
+ type TFromArray<Type extends TSchema, Result extends TSchema = TAddImmutable<TArray<Type>>> = Result;
1189
+
1190
+ type TFromCyclic$1<Defs extends TProperties, Ref extends string, Target extends TSchema = TCyclicTarget<Defs, Ref>, Partial extends TSchema = TFromType$1<Target>, Result extends TSchema = TCyclic<TAssign<Defs, {
1191
+ [_ in Ref]: Partial;
1192
+ }>, Ref>> = Result;
1193
+
1194
+ type TFromDependent$1<If extends TSchema, Then extends TSchema, Else extends TSchema, Evaluated extends TSchema = TEvaluateDependent<If, Then, Else>, Result extends TSchema = TFromType$1<Evaluated>> = Result;
1195
+
1196
+ type TFromIntersect$1<Types extends TSchema[], Evaluated extends TSchema = TEvaluateIntersect<Types>, Result extends TSchema = TFromType$1<Evaluated>> = Result;
1197
+
1198
+ type TFromObject$1<Properties extends TProperties, Mapped extends TProperties = {
1199
+ [Key in keyof Properties]: TAddReadonly<Properties[Key]>;
1200
+ }, Result extends TSchema = TObject<Mapped>> = Result;
1201
+
1202
+ type TFromTuple<Types extends TSchema[], Result extends TSchema = TAddImmutable<TTuple<Types>>> = Result;
1203
+
1204
+ type TFromUnion$1<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromUnion$1<Right, [...Result, TFromType$1<Left>]> : TUnion<Result>);
1205
+
1206
+ type TFromType$1<Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TFromArray<Type> : Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? TFromCyclic$1<Defs, Ref> : Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TFromDependent$1<If, Then, Else> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect$1<Types> : Type extends TObject<infer Properties extends TProperties> ? TFromObject$1<Properties> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion$1<Types> : Type);
1207
+
1208
+ type TReadonlyObjectAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TFromType$1<Type> : TReadonlyObjectDeferred<Type>> = Result;
1209
+ type TReadonlyObjectInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TReadonlyObjectAction<InstantiateType>;
1210
+
1211
+ type TRefInstantiate<Context extends TProperties, State extends TState, Type extends TRef, Ref extends string> = (Ref extends State['visited'][number] ? Type : Ref extends keyof Context ? TInstantiateType<Context, TState<State['callstack'], [...State['visited'], Ref]>, Context[Ref]> : Type);
1212
+
1213
+ type TFromCyclic<Defs extends TProperties, Ref extends string, Target extends TSchema = TCyclicTarget<Defs, Ref>, Partial extends TSchema = TFromType<Target>, Result extends TSchema = TCyclic<TAssign<Defs, {
1214
+ [_ in Ref]: Partial;
1215
+ }>, Ref>> = Result;
1216
+
1217
+ type TFromDependent<If extends TSchema, Then extends TSchema, Else extends TSchema, Evaluated extends TSchema = TEvaluateDependent<If, Then, Else>, Result extends TSchema = TFromType<Evaluated>> = Result;
1218
+
1219
+ type TFromIntersect<Types extends TSchema[], Evaluated extends TSchema = TEvaluateIntersect<Types>, Result extends TSchema = TFromType<Evaluated>> = Result;
1220
+
1221
+ type TFromUnion<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromUnion<Right, [...Result, TFromType<Left>]> : TUnion<Result>);
1222
+
1223
+ type TFromObject<Properties extends TProperties, Mapped extends TProperties = {
1224
+ [Key in keyof Properties]: TRemoveOptional<Properties[Key]>;
1225
+ }, Result extends TSchema = TObject<Mapped>> = Result;
1226
+
1227
+ type TFromType<Type extends TSchema> = (Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? TFromCyclic<Defs, Ref> : Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TFromDependent<If, Then, Else> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<Properties> : TObject<{}>);
1228
+
1229
+ /** Creates a deferred Required action. */
1230
+ type TRequiredDeferred<Type extends TSchema> = (TDeferred<'Required', [Type]>);
1231
+
1232
+ type TRequiredAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TFromType<Type> : TRequiredDeferred<Type>> = Result;
1233
+ type TRequiredInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TRequiredAction<InstantiatedType>;
1234
+
1235
+ /** Creates a deferred ReturnType action. */
1236
+ type TReturnTypeDeferred<Type extends TSchema> = (TDeferred<'ReturnType', [Type]>);
1237
+
1238
+ type TReturnTypeOperation<Type extends TSchema> = (Type extends TFunction ? Type['returnType'] : TNever);
1239
+ type TReturnTypeAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TReturnTypeOperation<Type> : TReturnTypeDeferred<Type>> = Result;
1240
+ type TReturnTypeInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TReturnTypeAction<InstantiatedType>;
1241
+
1242
+ /** Creates a deferred With action. */
1243
+ type TWithDeferred<Type extends TSchema, Options extends TSchema> = (TDeferred<'With', [Type, Options]>);
1244
+ /** Applies annotation options to the given type. */
1245
+ type TWith<Type extends TSchema, Options extends TSchema> = (Type & Options);
1246
+
1247
+ type TWithAction<Type extends TSchema, Options extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TWith<Type, Options> : TWithDeferred<Type, Options>> = Result;
1248
+ type TWithInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, Options extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TWithAction<InstantiatedType, Options>;
1249
+
1250
+ type TSpreadElement<Type extends TSchema, Result extends TSchema[] = (Type extends TRest<infer Rest extends TSchema> ? (Rest extends TTuple<infer Elements extends TSchema[]> ? TRestSpread<Elements> : Rest extends TInfer<string, TSchema> ? [Type] : Rest extends TRef<string> ? [Type] : [
1251
+ TNever
1252
+ ]) : [Type])> = Result;
1253
+ type TRestSpread<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TRestSpread<Right, [...Result, ...TSpreadElement<Left>]> : Result);
1254
+
1255
+ interface TState<CallStack extends string[] = string[], Visited extends string[] = string[]> {
1256
+ callstack: CallStack;
1257
+ visited: Visited;
1258
+ }
1259
+ type TCanInstantiate<Types extends TSchema[]> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TRef ? false : TCanInstantiate<Right> : true;
1260
+ type TInstantiateProperties<Context extends TProperties, State extends TState, Properties extends TProperties, Result extends TProperties = {
1261
+ [Key in keyof Properties]: TInstantiateType<Context, State, Properties[Key]>;
1262
+ }> = Result;
1263
+ type TInstantiateElements<Context extends TProperties, State extends TState, Types extends TSchema[], Elements extends TSchema[] = TInstantiateTypes<Context, State, Types>, Result extends TSchema[] = TRestSpread<Elements>> = Result;
1264
+ type TInstantiateTypes<Context extends TProperties, State extends TState, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TInstantiateTypes<Context, State, Right, [...Result, TInstantiateType<Context, State, Left>]> : Result);
1265
+ type TWithModifiers<Type extends TSchema, InstantiatedType extends TSchema, WithOptional extends TSchema = Type extends TOptional ? TAddOptionalAction<InstantiatedType> : InstantiatedType, WithReadonly extends TSchema = Type extends TReadonly ? TAddReadonlyAction<WithOptional> : WithOptional, WithImmutable extends TSchema = Type extends TImmutable ? TAddImmutableAction<WithReadonly> : WithReadonly> = WithImmutable;
1266
+ type TInstantiateDeferred<Context extends TProperties, State extends TState, Action extends string, Parameters extends TSchema[]> = ([
1267
+ Action,
1268
+ Parameters
1269
+ ] extends ['AddImmutable', [infer Type extends TSchema]] ? TAddImmutableInstantiate<Context, State, Type> : [
1270
+ Action,
1271
+ Parameters
1272
+ ] extends ['RemoveImmutable', [infer Type extends TSchema]] ? TRemoveImmutableInstantiate<Context, State, Type> : [
1273
+ Action,
1274
+ Parameters
1275
+ ] extends ['AddReadonly', [infer Type extends TSchema]] ? TAddReadonlyInstantiate<Context, State, Type> : [
1276
+ Action,
1277
+ Parameters
1278
+ ] extends ['RemoveReadonly', [infer Type extends TSchema]] ? TRemoveReadonlyInstantiate<Context, State, Type> : [
1279
+ Action,
1280
+ Parameters
1281
+ ] extends ['AddOptional', [infer Type extends TSchema]] ? TAddOptionalInstantiate<Context, State, Type> : [
1282
+ Action,
1283
+ Parameters
1284
+ ] extends ['RemoveOptional', [infer Type extends TSchema]] ? TRemoveOptionalInstantiate<Context, State, Type> : [
1285
+ Action,
1286
+ Parameters
1287
+ ] extends ['Capitalize', [infer Type extends TSchema]] ? TCapitalizeInstantiate<Context, State, Type> : [
1288
+ Action,
1289
+ Parameters
1290
+ ] extends ['Conditional', [infer Left extends TSchema, infer Right extends TSchema, infer True extends TSchema, infer False extends TSchema]] ? TConditionalInstantiate<Context, State, Left, Right, True, False> : [
1291
+ Action,
1292
+ Parameters
1293
+ ] extends ['ConstructorParameters', [infer Type extends TSchema]] ? TConstructorParametersInstantiate<Context, State, Type> : [
1294
+ Action,
1295
+ Parameters
1296
+ ] extends ['Evaluate', [infer Type extends TSchema]] ? TEvaluateInstantiate<Context, State, Type> : [
1297
+ Action,
1298
+ Parameters
1299
+ ] extends ['Exclude', [infer Left extends TSchema, infer Right extends TSchema]] ? TExcludeInstantiate<Context, State, Left, Right> : [
1300
+ Action,
1301
+ Parameters
1302
+ ] extends ['Extract', [infer Left extends TSchema, infer Right extends TSchema]] ? TExtractInstantiate<Context, State, Left, Right> : [
1303
+ Action,
1304
+ Parameters
1305
+ ] extends ['Index', [infer Type extends TSchema, infer Indexer extends TSchema]] ? TIndexInstantiate<Context, State, Type, Indexer> : [
1306
+ Action,
1307
+ Parameters
1308
+ ] extends ['InstanceType', [infer Type extends TSchema]] ? TInstanceTypeInstantiate<Context, State, Type> : [
1309
+ Action,
1310
+ Parameters
1311
+ ] extends ['Interface', [infer Heritage extends TSchema[], infer Properties extends TProperties]] ? TInterfaceInstantiate<Context, State, Heritage, Properties> : [
1312
+ Action,
1313
+ Parameters
1314
+ ] extends ['KeyOf', [infer Type extends TSchema]] ? TKeyOfInstantiate<Context, State, Type> : [
1315
+ Action,
1316
+ Parameters
1317
+ ] extends ['Lowercase', [infer Type extends TSchema]] ? TLowercaseInstantiate<Context, State, Type> : [
1318
+ Action,
1319
+ Parameters
1320
+ ] extends ['Mapped', [infer Name extends TIdentifier, infer Key extends TSchema, infer As extends TSchema, infer Property extends TSchema]] ? TMappedInstantiate<Context, State, Name, Key, As, Property> : [
1321
+ Action,
1322
+ Parameters
1323
+ ] extends ['Module', [infer Declarations extends TProperties]] ? TModuleInstantiate<Context, State, Declarations> : [
1324
+ Action,
1325
+ Parameters
1326
+ ] extends ['NonNullable', [infer Type extends TSchema]] ? TNonNullableInstantiate<Context, State, Type> : [
1327
+ Action,
1328
+ Parameters
1329
+ ] extends ['Pick', [infer Type extends TSchema, infer Indexer extends TSchema]] ? TPickInstantiate<Context, State, Type, Indexer> : [
1330
+ Action,
1331
+ Parameters
1332
+ ] extends ['Parameters', [infer Type extends TSchema]] ? TParametersInstantiate<Context, State, Type> : [
1333
+ Action,
1334
+ Parameters
1335
+ ] extends ['Partial', [infer Type extends TSchema]] ? TPartialInstantiate<Context, State, Type> : [
1336
+ Action,
1337
+ Parameters
1338
+ ] extends ['Omit', [infer Type extends TSchema, infer Indexer extends TSchema]] ? TOmitInstantiate<Context, State, Type, Indexer> : [
1339
+ Action,
1340
+ Parameters
1341
+ ] extends ['ReadonlyObject', [infer Type extends TSchema]] ? TReadonlyObjectInstantiate<Context, State, Type> : [
1342
+ Action,
1343
+ Parameters
1344
+ ] extends ['Record', [infer Key extends TSchema, infer Value extends TSchema]] ? TRecordInstantiate<Context, State, Key, Value> : [
1345
+ Action,
1346
+ Parameters
1347
+ ] extends ['Required', [infer Type extends TSchema]] ? TRequiredInstantiate<Context, State, Type> : [
1348
+ Action,
1349
+ Parameters
1350
+ ] extends ['ReturnType', [infer Type extends TSchema]] ? TReturnTypeInstantiate<Context, State, Type> : [
1351
+ Action,
1352
+ Parameters
1353
+ ] extends ['TemplateLiteral', [infer Types extends TSchema[]]] ? TTemplateLiteralInstantiate<Context, State, Types> : [
1354
+ Action,
1355
+ Parameters
1356
+ ] extends ['Uncapitalize', [infer Type extends TSchema]] ? TUncapitalizeInstantiate<Context, State, Type> : [
1357
+ Action,
1358
+ Parameters
1359
+ ] extends ['Uppercase', [infer Type extends TSchema]] ? TUppercaseInstantiate<Context, State, Type> : [
1360
+ Action,
1361
+ Parameters
1362
+ ] extends ['With', [infer Type extends TSchema, infer Options extends TSchema]] ? TWithInstantiate<Context, State, Type, Options> : TDeferred<Action, Parameters>);
1363
+ type TInstantiateImmediate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = (Type extends TRef<infer Ref extends string> ? TRefInstantiate<Context, State, Type, Ref> : Type extends TArray<infer Type extends TSchema> ? TArray<TInstantiateType<Context, State, Type>> : Type extends TCall<infer Target extends TSchema, infer Parameters extends TSchema[]> ? TCallInstantiate<Context, State, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TConstructor<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, InstanceType>> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TInstantiateTypes<Context, State, Parameters>, TInstantiateType<Context, State, ReturnType>> : Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? TDependent<TInstantiateType<Context, State, If>, TInstantiateType<Context, State, Then>, TInstantiateType<Context, State, Else>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TInstantiateTypes<Context, State, Types>> : Type extends TObject<infer Properties extends TProperties> ? TObject<TInstantiateProperties<Context, State, Properties>> : Type extends TRecord<infer Key extends string, infer Type extends TSchema> ? TRecord<Key, TInstantiateType<Context, State, Type>> : Type extends TRest<infer Type extends TSchema> ? TRest<TInstantiateType<Context, State, Type>> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TInstantiateElements<Context, State, Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TInstantiateTypes<Context, State, Types>> : Type), WithModifiers extends TSchema = TWithModifiers<Type, InstantiatedType>> = WithModifiers;
1364
+ type TInstantiateType<Context extends TProperties, State extends TState, Type extends TSchema, Result extends TSchema = Type extends TDeferred<infer Action extends string, infer Types extends TSchema[]> ? TInstantiateDeferred<Context, State, Action, Types> : TInstantiateImmediate<Context, State, Type>> = Result;
1365
+ /** Instantiates computed schematics using the given context and type. */
1366
+ type TInstantiate<Context extends TProperties, Type extends TSchema> = (TInstantiateType<Context, TState<[], []>, Type>);
1367
+
1368
+ type TAddOptionalOperation<Type extends TSchema, Result extends TSchema = `~optional` extends keyof Type ? Type : TOptional<Type>> = Result;
1369
+ type TAddOptionalAction<Type extends TSchema, Result extends TSchema = TAddOptionalOperation<Type>> = Result;
1370
+ type TAddOptionalInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TAddOptionalAction<InstantiateType>;
1371
+
1372
+ /** Applies an AddOptional action to a type. */
1373
+ type TAddOptional<Type extends TSchema> = (TAddOptionalAction<Type>);
1374
+
1375
+ type TOptional<Type extends TSchema = TSchema> = (Type & {
1376
+ '~optional': true;
1377
+ });
1378
+
1379
+ type StaticLast<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, Result extends unknown[]> = (Type extends TRest<infer RestType extends TSchema> ? RestType extends TArray<infer ArrayType extends TSchema> ? [...Result, ...TStaticElement<Stack, Direction, Context, This, ArrayType>[0][]] : [...Result, never] : [...Result, ...TStaticElement<Stack, Direction, Context, This, Type>]);
1380
+ type TStaticElement<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema, IsReadonly extends boolean = Type extends TReadonly ? true : false, IsOptional extends boolean = Type extends TOptional ? true : false, Inferred extends unknown = StaticType<Stack, Direction, Context, This, Type>, Result extends [unknown?] = ([
1381
+ IsReadonly,
1382
+ IsOptional
1383
+ ] extends [true, true] ? [Readonly<Inferred>?] : [
1384
+ IsReadonly,
1385
+ IsOptional
1386
+ ] extends [false, true] ? [Inferred?] : [
1387
+ IsReadonly,
1388
+ IsOptional
1389
+ ] extends [true, false] ? [Readonly<Inferred>] : [
1390
+ Inferred
1391
+ ])> = Result;
1392
+ type TStaticElements<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Types extends TSchema[], Result extends unknown[] = []> = (Types extends [infer Last extends TSchema] ? StaticLast<Stack, Direction, Context, This, Last, Result> : Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TStaticElements<Stack, Direction, Context, This, Right, [...Result, ...TStaticElement<Stack, Direction, Context, This, Left>]> : Result);
1393
+ type StaticTuple<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Tuple extends TSchema, Items extends TSchema[], Elements extends unknown[] = TStaticElements<Stack, Direction, Context, This, Items>, Result extends readonly unknown[] = (Tuple extends TImmutable ? readonly [...Elements] : Elements)> = Result;
1394
+ /** Represents a Tuple type. */
1395
+ interface TTuple<Types extends TSchema[] = TSchema[]> extends TSchema {
1396
+ '~kind': 'Tuple';
1397
+ type: 'array';
1398
+ additionalItems: false;
1399
+ items: Types;
1400
+ minItems: Types['length'];
1401
+ }
1402
+
1403
+ type StaticInstantiatedParameters<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Parameters extends TSchema[], Evaluated extends TSchema = TInstantiate<Context, TTuple<Parameters>>, Static extends unknown = StaticType<Stack, Direction, Context, This, Evaluated>, Result extends unknown[] = Static extends unknown[] ? Static : []> = Result;
1404
+ type StaticFunction<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema, StaticParameters extends unknown[] = StaticInstantiatedParameters<Stack, Direction, Context, This, Parameters>, StaticReturnType extends unknown = StaticType<Stack, Direction, Context, This, ReturnType>, Result = (...args: StaticParameters) => StaticReturnType> = Result;
1405
+ /** Represents a Function type. */
1406
+ interface TFunction<Parameters extends TSchema[] = TSchema[], ReturnType extends TSchema = TSchema> extends TSchema {
1407
+ '~kind': 'Function';
1408
+ type: 'function';
1409
+ parameters: Parameters;
1410
+ returnType: ReturnType;
1411
+ }
1412
+
1413
+ type StaticConstructor<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema, StaticParameters extends unknown[] = StaticInstantiatedParameters<Stack, Direction, Context, This, Parameters>, StaticReturnType extends unknown = StaticType<Stack, Direction, Context, This, InstanceType>, Result = new (...args: StaticParameters) => StaticReturnType> = Result;
1414
+ /** Represents a Constructor type. */
1415
+ interface TConstructor<Parameters extends TSchema[] = TSchema[], InstanceType extends TSchema = TSchema> extends TSchema {
1416
+ '~kind': 'Constructor';
1417
+ type: 'constructor';
1418
+ parameters: Parameters;
1419
+ instanceType: InstanceType;
1420
+ }
1421
+
1422
+ type XSchemaObject = object;
1423
+ type XSchemaBoolean = boolean;
1424
+ type XSchema = XSchemaObject | XSchemaBoolean;
1425
+
1426
+ type XCanonicalTuple<Value extends readonly unknown[]> = (Value extends [infer Left, ...infer Right extends unknown[]] ? [XCanonical<Left>, ...XCanonicalTuple<Right>] : []);
1427
+ type XCanonicalArray<Value extends unknown, Result extends unknown[] = XCanonical<Value>[]> = Result;
1428
+ type XCanonicalObject<Value extends object, Result extends Record<PropertyKey, unknown> = {
1429
+ -readonly [Key in keyof Value]: XCanonical<Value[Key]>;
1430
+ }> = Result;
1431
+ type XCanonical<Schema extends unknown> = (Schema extends readonly [...infer Schemas extends unknown[]] ? XCanonicalTuple<Schemas> : Schema extends readonly (infer Schema)[] ? XCanonicalArray<Schema> : Schema extends object ? XCanonicalObject<Schema> : Schema);
1432
+
1433
+ interface XAdditionalProperties<AdditionalProperties extends XSchema = XSchema> {
1434
+ additionalProperties: AdditionalProperties;
1435
+ }
1436
+
1437
+ interface XAnyOf<AnyOf extends XSchema[] = XSchema[]> {
1438
+ anyOf: AnyOf;
1439
+ }
1440
+
1441
+ interface XAllOf<AllOf extends XSchema[] = XSchema[]> {
1442
+ allOf: AllOf;
1443
+ }
1444
+
1445
+ interface XConst<Const extends unknown = unknown> {
1446
+ const: Const;
1447
+ }
1448
+
1449
+ interface XEnum<Enum extends unknown[] = unknown[]> {
1450
+ enum: Enum;
1451
+ }
1452
+
1453
+ interface XIf<If extends XSchema = XSchema> {
1454
+ if: If;
1455
+ }
1456
+
1457
+ interface XItems<Items extends (XSchema | XSchema[]) = (XSchema | XSchema[])> {
1458
+ items: Items;
1459
+ }
1460
+
1461
+ interface XOneOf<OneOf extends XSchema[] = XSchema[]> {
1462
+ oneOf: OneOf;
1463
+ }
1464
+
1465
+ interface XPatternProperties<PatternProperties extends Record<PropertyKey, XSchema> = Record<PropertyKey, XSchema>> {
1466
+ patternProperties: PatternProperties;
1467
+ }
1468
+
1469
+ interface XPrefixItems<PrefixItems extends XSchema[] = XSchema[]> {
1470
+ prefixItems: PrefixItems;
1471
+ }
1472
+
1473
+ interface XProperties<Properties extends Record<PropertyKey, XSchema> = Record<PropertyKey, XSchema>> {
1474
+ properties: Properties;
1475
+ }
1476
+
1477
+ interface XPropertyNames<PropertyNames extends XSchema = XSchema> {
1478
+ propertyNames: PropertyNames;
1479
+ }
1480
+
1481
+ interface XRef<Ref extends string = string> {
1482
+ $ref: Ref;
1483
+ }
1484
+
1485
+ interface XRequired<Required extends string[] = string[]> {
1486
+ required: Required;
1487
+ }
1488
+
1489
+ interface XType<Type extends string | string[] = string | string[]> {
1490
+ type: Type;
1491
+ }
1492
+
1493
+ interface XUnevaluatedProperties<UnevaluatedProperties extends XSchema = XSchema> {
1494
+ unevaluatedProperties: UnevaluatedProperties;
1495
+ }
1496
+
1497
+ type XStaticAdditionalProperties<Stack extends string[], Root extends XSchema, Schema extends XSchema, Result extends Record<PropertyKey, unknown> = (Schema extends true ? {
1498
+ [key: string]: unknown;
1499
+ } : Schema extends false ? {} : {
1500
+ [key: string]: XStaticSchema<Stack, Root, Schema>;
1501
+ })> = Result;
1502
+
1503
+ type XStaticAllOf<Stack extends string[], Root extends XSchema, Schemas extends XSchema[], Result extends unknown = unknown> = (Schemas extends readonly [infer Left extends XSchema, ...infer Right extends XSchema[]] ? XStaticAllOf<Stack, Root, Right, Result & XStaticSchema<Stack, Root, Left>> : Result);
1504
+
1505
+ type XStaticAnyOf<Stack extends string[], Root extends XSchema, Schemas extends XSchema[], Result extends unknown = never> = (Schemas extends [infer Left extends XSchema, ...infer Right extends XSchema[]] ? XStaticAnyOf<Stack, Root, Right, XStaticSchema<Stack, Root, Left> | Result> : Result);
1506
+
1507
+ type XStaticConst<Value extends unknown> = Value;
1508
+
1509
+ type XStaticEnum<Values extends unknown[], Result extends unknown = never> = (Values extends [infer Left extends unknown, ...infer Right extends unknown[]] ? XStaticEnum<Right, Left | Result> : Result);
1510
+
1511
+ interface XElse<Else extends XSchema = XSchema> {
1512
+ else: Else;
1513
+ }
1514
+
1515
+ interface XThen<Then extends XSchema = XSchema> {
1516
+ then: Then;
1517
+ }
1518
+
1519
+ type XStaticIf<Stack extends string[], Root extends XSchema, Schema extends XIf, IfSchema extends XSchema, If extends unknown = XStaticSchema<Stack, Root, IfSchema>, Then extends unknown = Schema extends XThen<infer ThenSchema extends XSchema> ? XStaticSchema<Stack, Root, ThenSchema> : never, Else extends unknown = Schema extends XElse<infer ElseSchema extends XSchema> ? XStaticSchema<Stack, Root, ElseSchema> : never, IsThen extends boolean = Schema extends XThen ? true : false, IsElse extends boolean = Schema extends XElse ? true : false, Result extends unknown = ([
1520
+ IsThen,
1521
+ IsElse
1522
+ ] extends [true, true] ? (If & Then) | Exclude<Else, If> : [
1523
+ IsThen,
1524
+ IsElse
1525
+ ] extends [true, false] ? (If & Then) : [
1526
+ IsThen,
1527
+ IsElse
1528
+ ] extends [false, true] ? Exclude<Else, If> : unknown)> = Result;
1529
+
1530
+ interface XMinItems<MinItems extends number = number> {
1531
+ minItems: MinItems;
1532
+ }
1533
+
1534
+ interface XMaxItems<MaxItems extends number = number> {
1535
+ maxItems: MaxItems;
1536
+ }
1537
+
1538
+ interface XAdditionalItems<AdditionalItems extends XSchema = XSchema> {
1539
+ additionalItems: AdditionalItems;
1540
+ }
1541
+
1542
+ type XBuildTuple<Size extends number, Tuple extends unknown[] = []> = (Tuple['length'] extends Size ? Tuple : XBuildTuple<Size, [...Tuple, unknown]>);
1543
+ type XLessThan<Left extends number, Right extends number> = Left extends Right ? false : XBuildTuple<Left> extends [...XBuildTuple<Right>, ...infer _Rest] ? false : true;
1544
+
1545
+ type XWithElements<Stack extends string[], Root extends XSchema, Schemas extends XSchema[], Result extends unknown[] = []> = (Schemas extends [infer Left extends XSchema, ...infer Right extends XSchema[]] ? XWithElements<Stack, Root, Right, [...Result, XStaticSchema<Stack, Root, Left>]> : Result);
1546
+ type XWithMaxItemsRemap<Elements extends unknown[], MaxItems extends number, Result extends unknown[] = []> = (Elements extends [infer Left extends unknown, ...infer Right extends unknown[]] ? XLessThan<Result['length'], MaxItems> extends true ? XWithMaxItemsRemap<Right, MaxItems, [...Result, Left]> : Result : Result);
1547
+ type XWithMaxItems<Schema extends XSchema, Elements extends unknown[], Result extends unknown[] = Schema extends XMaxItems<infer MaxItems extends number> ? XWithMaxItemsRemap<Elements, MaxItems> : Elements> = Result;
1548
+ type XNeedsAdditionalItems<Schema extends XSchema, Elements extends unknown[], Result extends boolean = (Schema extends XMaxItems<infer MaxItems extends number> ? XLessThan<Elements['length'], MaxItems> : true)> = Result;
1549
+ type XWithMinItemsRemap<Elements extends unknown[], MinItems extends number, Result extends unknown[] = []> = (Elements extends [infer Left, ...infer Right] ? XLessThan<Result['length'], MinItems> extends true ? XWithMinItemsRemap<Right, MinItems, [...Result, Left]> : XWithMinItemsRemap<Right, MinItems, [...Result, Left?]> : Result);
1550
+ type XWithMinItems<Schema extends XSchema, Values extends unknown[], MinItems extends number = Schema extends XMinItems<infer MinItems extends number> ? MinItems : 0, Result extends unknown[] = XWithMinItemsRemap<Values, MinItems>> = Result;
1551
+ type XWithAdditionalItems<Stack extends string[], Root extends XSchema, Schema extends XSchema, Elements extends unknown[], Result extends unknown[] = Schema extends XAdditionalItems<infer Schema extends XSchema> ? (Schema extends true ? [...Elements, ...unknown[]] : Schema extends false ? [...Elements] : [
1552
+ ...Elements,
1553
+ ...XStaticSchema<Stack, Root, Schema>[]
1554
+ ]) : [...Elements, ...unknown[]]> = Result;
1555
+ type XStaticElements<Stack extends string[], Root extends XSchema, Schema extends XSchema, PrefixItems extends XSchema[], WithElements extends unknown[] = XWithElements<Stack, Root, PrefixItems>, WithMaxItems extends unknown[] = XWithMaxItems<Schema, WithElements>, NeedsAdditional extends boolean = XNeedsAdditionalItems<Schema, WithMaxItems>, WithMinItems extends unknown[] = XWithMinItems<Schema, WithMaxItems>, WithAdditionalItems extends unknown[] = NeedsAdditional extends true ? XWithAdditionalItems<Stack, Root, Schema, WithMinItems> : WithMinItems> = WithAdditionalItems;
1556
+
1557
+ type XFromSized<Stack extends string[], Root extends XSchema, Schema extends XSchema, Items extends XSchema[]> = (XStaticElements<Stack, Root, Schema, Items>);
1558
+ type XFromUnsized<Stack extends string[], Root extends XSchema, Schema extends XSchema> = (XStaticSchema<Stack, Root, Schema>[]);
1559
+ type XStaticItems<Stack extends string[], Root extends XSchema, Schema extends XSchema, Items extends XSchema[] | XSchema, Result extends unknown = (Items extends XSchema[] ? XFromSized<Stack, Root, Schema, [...Items]> : Items extends XSchema ? XFromUnsized<Stack, Root, Items> : never)> = Result;
1560
+
1561
+ type XStaticOneOf<Stack extends string[], Root extends XSchema, Schemas extends XSchema[], Result extends unknown = never> = (Schemas extends [infer Left extends XSchema, ...infer Right extends XSchema[]] ? XStaticOneOf<Stack, Root, Right, XStaticSchema<Stack, Root, Left> | Result> : Result);
1562
+
1563
+ type XStaticPatternProperties<Stack extends string[], Root extends XSchema, Properties extends Record<PropertyKey, XSchema> = Record<PropertyKey, XSchema>, InferredProperties extends Record<PropertyKey, unknown> = {
1564
+ [Key in keyof Properties]: XStaticSchema<Stack, Root, Properties[Key]>;
1565
+ }, EvaluatedProperties extends unknown = {
1566
+ [key: string]: InferredProperties[keyof InferredProperties];
1567
+ }> = EvaluatedProperties;
1568
+
1569
+ type XStaticPrefixItems<Stack extends string[], Root extends XSchema, Schema extends XSchema, PrefixItems extends XSchema[], Result extends unknown[] = XStaticElements<Stack, Root, Schema, PrefixItems>> = Result;
1570
+
1571
+ type XIsReadonly<Schema extends XSchema> = (Schema extends {
1572
+ readOnly: true;
1573
+ } ? true : Schema extends {
1574
+ '~readonly': true;
1575
+ } ? true : false);
1576
+ type XRequiredArray<Schema extends XSchema, Result extends PropertyKey[] = Schema extends XRequired<infer Keys extends string[]> ? Keys : []> = Result;
1577
+ type XReadonlyKeys<Properties extends Record<PropertyKey, XSchema>, ReadonlyProperties extends Record<PropertyKey, unknown> = {
1578
+ [Key in keyof Properties as XIsReadonly<Properties[Key]> extends true ? Key : never]: unknown;
1579
+ }, Result extends PropertyKey = keyof ReadonlyProperties> = Result;
1580
+ type XRequiredKeys<Properties extends Record<PropertyKey, XSchema>, RequiredArray extends string[], Result extends PropertyKey = RequiredArray extends [] ? never : Extract<keyof Properties, RequiredArray[number]>> = Result;
1581
+ type XUnknownKeys<Properties extends Record<PropertyKey, XSchema>, RequiredArray extends string[], Result extends PropertyKey = Exclude<RequiredArray[number], keyof Properties>> = Result;
1582
+ type XOptionalKeys<Properties extends Record<PropertyKey, XSchema>, RequiredArray extends string[], Result extends PropertyKey = RequiredArray extends [] ? keyof Properties : Exclude<keyof Properties, RequiredArray[number]>> = Result;
1583
+ type XReadonlyOptionalProperties<Stack extends string[], Root extends XSchema, OptionalKeys extends PropertyKey, Properties extends Record<PropertyKey, XSchema>> = {
1584
+ readonly [Key in Extract<keyof Properties, OptionalKeys>]?: XStaticSchema<Stack, Root, Properties[Key]>;
1585
+ };
1586
+ type XReadonlyRequiredProperties<Stack extends string[], Root extends XSchema, RequiredKeys extends PropertyKey, Properties extends Record<PropertyKey, XSchema>> = {
1587
+ readonly [Key in Extract<keyof Properties, RequiredKeys>]: XStaticSchema<Stack, Root, Properties[Key]>;
1588
+ };
1589
+ type XOptionalProperties<Stack extends string[], Root extends XSchema, OptionalKeys extends PropertyKey, Properties extends Record<PropertyKey, XSchema>> = {
1590
+ [Key in Extract<keyof Properties, OptionalKeys>]?: XStaticSchema<Stack, Root, Properties[Key]>;
1591
+ };
1592
+ type XRequiredProperties<Stack extends string[], Root extends XSchema, RequiredKeys extends PropertyKey, Properties extends Record<PropertyKey, XSchema>> = {
1593
+ [Key in Extract<keyof Properties, RequiredKeys>]: XStaticSchema<Stack, Root, Properties[Key]>;
1594
+ };
1595
+ type XUnknownProperties<UnknownKeys extends PropertyKey> = {
1596
+ [Key in UnknownKeys]: unknown;
1597
+ };
1598
+ type XStaticProperties<Stack extends string[], Root extends XSchema, Schema extends XSchema, Properties extends Record<PropertyKey, XSchema>, RequiredArray extends string[] = XRequiredArray<Schema>, ReadonlyKeys extends PropertyKey = XReadonlyKeys<Properties>, OptionalKeys extends PropertyKey = XOptionalKeys<Properties, RequiredArray>, RequiredKeys extends PropertyKey = XRequiredKeys<Properties, RequiredArray>, UnknownKeys extends PropertyKey = XUnknownKeys<Properties, RequiredArray>, ReadonlyOptionalProperties extends Record<PropertyKey, unknown> = XReadonlyOptionalProperties<Stack, Root, Extract<OptionalKeys, ReadonlyKeys>, Properties>, ReadonlyRequiredProperties extends Record<PropertyKey, unknown> = XReadonlyRequiredProperties<Stack, Root, Extract<RequiredKeys, ReadonlyKeys>, Properties>, OptionalProperties extends Record<PropertyKey, unknown> = XOptionalProperties<Stack, Root, Exclude<OptionalKeys, ReadonlyKeys>, Properties>, RequiredProperties extends Record<PropertyKey, unknown> = XRequiredProperties<Stack, Root, Exclude<RequiredKeys, ReadonlyKeys>, Properties>, UnknownProperties extends Record<PropertyKey, unknown> = XUnknownProperties<UnknownKeys>, Result extends Record<PropertyKey, unknown> = (ReadonlyOptionalProperties & ReadonlyRequiredProperties & OptionalProperties & RequiredProperties & UnknownProperties)> = Result;
1599
+
1600
+ type XStaticPropertyNames<Stack extends string[], Root extends XSchema, Schema extends XSchema, StaticKey extends unknown = XStaticSchema<Stack, Root, Schema>, Result extends Record<string, unknown> = [StaticKey] extends [PropertyKey] ? {
1601
+ [Key in StaticKey]?: unknown;
1602
+ } : {}> = Result;
1603
+
1604
+ type TEscape0<Index extends string> = Index extends `${infer Left}~0${infer Right}` ? `${Left}~${TEscape<Right>}` : Index;
1605
+ type TEscape1<Index extends string> = Index extends `${infer Left}~1${infer Right}` ? `${Left}/${TEscape<Right>}` : Index;
1606
+ type TEscape<Index extends string, Escaped0 extends string = TEscape0<Index>, Escaped1 extends string = TEscape1<Escaped0>> = Escaped1;
1607
+ type IndicesReduce<Pointer extends string, Result extends string[] = []> = (Pointer extends `${infer Left extends string}/${infer Right extends string}` ? Left extends '' ? IndicesReduce<Right, Result> : IndicesReduce<Right, [...Result, TEscape<Left>]> : [...Result, TEscape<Pointer>]);
1608
+ type TIndices<Pointer extends string, Result extends string[] = Pointer extends '' ? [] : IndicesReduce<Pointer>> = Result;
1609
+ type TResolve<Value extends unknown, Indices extends string[]> = (Indices extends [infer Left extends string, ...infer Right extends string[]] ? Left extends keyof Value ? TResolve<Value[Left], Right> : undefined : Value);
1610
+ /** Type Level RFC 6901 Json Pointer Resolver */
1611
+ type XPointerGet<Value extends unknown, Pointer extends string, Indices extends string[] = TIndices<Pointer>, Result extends unknown = TResolve<Value, Indices>> = Result;
1612
+
1613
+ type XCyclicCheck<Stack extends unknown[], MaxLength extends number, Buffer extends unknown[] = []> = (Stack extends [infer Left, ...infer Right] ? Buffer['length'] extends MaxLength ? false : XCyclicCheck<Right, MaxLength, [...Buffer, Left]> : true);
1614
+ type XCyclicGuard<Stack extends unknown[], Ref extends string> = (Ref extends Stack[number] ? XCyclicCheck<Stack, 2> : true);
1615
+ type XNormal<Pointer extends string, Result extends string = (Pointer extends `#${infer Rest extends string}` ? Rest : Pointer)> = Result;
1616
+ type XStaticRef<Stack extends string[], Root extends XSchema, Ref extends string, Normal extends string = XNormal<Ref>, Target extends unknown = XPointerGet<Root, Normal>, Schema extends XSchema = Target extends XSchema ? Target : {}, Result extends unknown = (XCyclicGuard<Stack, Ref> extends true ? XStaticSchema<[...Stack, Ref], Root, Schema> : any)> = Result;
1617
+
1618
+ type XStaticRequired<_Stack extends string[], _Root extends XSchema, Schema extends XSchema, Keys extends string[], Result extends Record<PropertyKey, unknown> = Schema extends XProperties ? {} : Record<Keys[number], unknown>> = Result;
1619
+
1620
+ type XFromTypeNames<TypeNames extends string[], Result extends unknown = never> = (TypeNames extends readonly [infer Left extends string, ...infer Right extends string[]] ? XFromTypeNames<Right, Result | XFromTypeName<Left>> : Result);
1621
+ type XFromTypeName<TypeName extends string> = (TypeName extends 'object' ? object : TypeName extends 'array' ? {} : TypeName extends 'boolean' ? boolean : TypeName extends 'integer' ? number : TypeName extends 'number' ? number : TypeName extends 'null' ? null : TypeName extends 'string' ? string : TypeName extends 'bigint' ? bigint : TypeName extends 'symbol' ? symbol : TypeName extends 'undefined' ? undefined : TypeName extends 'void' ? void : TypeName extends 'asyncIterator' ? {} : TypeName extends 'constructor' ? {} : TypeName extends 'function' ? {} : TypeName extends 'iterator' ? {} : unknown);
1622
+ type XStaticType<TypeName extends string[] | string> = (TypeName extends string[] ? XFromTypeNames<TypeName> : TypeName extends string ? XFromTypeName<TypeName> : unknown);
1623
+
1624
+ type XStaticUnevaluatedProperties<Stack extends string[], Root extends XSchema, Schema extends XSchema, Result extends Record<PropertyKey, unknown> = (Schema extends true ? {
1625
+ [key: string]: unknown;
1626
+ } : Schema extends false ? {} : {
1627
+ [key: string]: XStaticSchema<Stack, Root, Schema>;
1628
+ })> = Result;
1629
+
1630
+ type XFromKeywords<Stack extends string[], Root extends XSchema, Schema extends XSchema, Result extends unknown[] = [
1631
+ Schema extends XAdditionalProperties<infer Type extends XSchema> ? XStaticAdditionalProperties<Stack, Root, Type> : unknown,
1632
+ Schema extends XAllOf<infer Types extends XSchema[]> ? XStaticAllOf<Stack, Root, Types> : unknown,
1633
+ Schema extends XAnyOf<infer Types extends XSchema[]> ? XStaticAnyOf<Stack, Root, Types> : unknown,
1634
+ Schema extends XConst<infer Value extends unknown> ? XStaticConst<Value> : unknown,
1635
+ Schema extends XIf<infer Type extends XSchema> ? XStaticIf<Stack, Root, Schema, Type> : unknown,
1636
+ Schema extends XEnum<infer Values extends unknown[]> ? XStaticEnum<Values> : unknown,
1637
+ Schema extends XItems<infer Types extends XSchema[] | XSchema> ? XStaticItems<Stack, Root, Schema, Types> : unknown,
1638
+ Schema extends XOneOf<infer Types extends XSchema[]> ? XStaticOneOf<Stack, Root, Types> : unknown,
1639
+ Schema extends XPatternProperties<infer Properties extends Record<PropertyKey, XSchema>> ? XStaticPatternProperties<Stack, Root, Properties> : unknown,
1640
+ Schema extends XPrefixItems<infer Types extends XSchema[]> ? XStaticPrefixItems<Stack, Root, Schema, Types> : unknown,
1641
+ Schema extends XProperties<infer Properties extends Record<PropertyKey, XSchema>> ? XStaticProperties<Stack, Root, Schema, Properties> : unknown,
1642
+ Schema extends XPropertyNames<infer Type extends XSchema> ? XStaticPropertyNames<Stack, Root, Type> : unknown,
1643
+ Schema extends XRef<infer Ref extends string> ? XStaticRef<Stack, Root, Ref> : unknown,
1644
+ Schema extends XRequired<infer Keys extends string[]> ? XStaticRequired<Stack, Root, Schema, Keys> : unknown,
1645
+ Schema extends XType<infer TypeName extends string[] | string> ? XStaticType<TypeName> : unknown,
1646
+ Schema extends XUnevaluatedProperties<infer Type extends XSchema> ? XStaticUnevaluatedProperties<Stack, Root, Type> : unknown
1647
+ ]> = Result;
1648
+ type XKeywordsIntersected<Schemas extends unknown[], Result extends unknown = unknown> = (Schemas extends [infer Left extends unknown, ...infer Right extends unknown[]] ? XKeywordsIntersected<Right, Result & Left> : Result);
1649
+ type XKeywordsEvaluated<Schema extends unknown, Result extends unknown = Schema extends object ? {
1650
+ [Key in keyof Schema]: Schema[Key];
1651
+ } : Schema> = Result;
1652
+ type XStaticObject<Stack extends string[], Root extends XSchema, Schema extends XSchema, Keywords extends unknown[] = XFromKeywords<Stack, Root, Schema>, Intersected extends unknown = XKeywordsIntersected<Keywords>, Evaluated extends unknown = XKeywordsEvaluated<Intersected>> = Evaluated;
1653
+ type XStaticBoolean<Schema extends boolean, Result extends unknown = Schema extends false ? never : unknown> = Result;
1654
+ type XStaticSchema<Stack extends string[], Root extends XSchema, Schema extends XSchema, Result extends unknown = Schema extends boolean ? XStaticBoolean<Schema> : XStaticObject<Stack, Root, Schema>> = Result;
1655
+
1656
+ type XStatic<Value extends unknown, Schema extends XSchema = Value extends XSchema ? Value : {}, Canonical extends XSchema = XCanonical<Schema>, Result extends unknown = XStaticSchema<[], Canonical, Canonical>> = Result;
1657
+
1658
+ type StaticEvaluate<T> = {
1659
+ [K in keyof T]: T[K];
1660
+ } & {};
1661
+ type StaticDirection = 'Encode' | 'Decode';
1662
+ type StaticType<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Type extends TSchema> = (Type extends TCodec<infer Type extends TSchema, infer Decoded extends unknown> ? StaticCodec<Stack, Direction, Context, This, Type, Decoded> : Type extends TAny ? StaticAny : Type extends TArray<infer Items extends TSchema> ? StaticArray<Stack, Direction, Context, This, Type, Items> : Type extends TBigInt ? StaticBigInt : Type extends TBoolean ? StaticBoolean : Type extends TConstructor<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? StaticConstructor<Stack, Direction, Context, This, Parameters, ReturnType> : Type extends TEnum<infer Values extends TEnumValue[]> ? StaticEnum<Values> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? StaticFunction<Stack, Direction, Context, This, Parameters, ReturnType> : Type extends TDependent<infer If extends TSchema, infer Then extends TSchema, infer Else extends TSchema> ? StaticDependent<Stack, Direction, Context, This, If, Then, Else> : Type extends TInteger ? StaticInteger : Type extends TIntersect<infer Types extends TSchema[]> ? StaticIntersect<Stack, Direction, Context, This, Types> : Type extends TLiteral<infer Value extends TLiteralValue> ? StaticLiteral<Value> : Type extends TNever ? StaticNever : Type extends TNull ? StaticNull : Type extends TNumber ? StaticNumber : Type extends TObject<infer Properties extends TProperties> ? StaticObject<Stack, Direction, Context, This, Properties> : Type extends TRecord<infer Key extends string, infer Value extends TSchema> ? StaticRecord<Stack, Direction, Context, This, Key, Value> : Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? StaticCyclic<Stack, Direction, Context, This, Defs, Ref> : Type extends TRef<infer Ref extends string> ? StaticRef<Stack, Direction, Context, This, Ref> : Type extends TString ? StaticString : Type extends TSymbol ? StaticSymbol : Type extends TTemplateLiteral<infer Pattern extends string> ? StaticTemplateLiteral<Pattern> : Type extends TThis ? StaticThis<Stack, Direction, Context, This> : Type extends TTuple<infer Items extends TSchema[]> ? StaticTuple<Stack, Direction, Context, This, Type, Items> : Type extends TUndefined ? StaticUndefined : Type extends TUnion<infer Types extends TSchema[]> ? StaticUnion<Stack, Direction, Context, This, Types> : Type extends TUnknown ? StaticUnknown : Type extends TUnsafe<infer Type extends unknown> ? StaticUnsafe<Type> : Type extends TVoid ? StaticVoid : XStatic<Type>);
1663
+ /** Infers a static type from a TypeBox type. */
1664
+ type Static<Type extends TSchema, Context extends TProperties = {}, Result extends unknown = StaticType<[], 'Encode', Context, {}, Type>> = Result;
1665
+
1666
+ type ReadonlyOptionalKeys<Properties extends TProperties, Result extends PropertyKey = {
1667
+ [Key in keyof Properties]: Properties[Key] extends TReadonly<TSchema> ? (Properties[Key] extends TOptional<Properties[Key]> ? Key : never) : never;
1668
+ }[keyof Properties]> = Result;
1669
+ type ReadonlyKeys<Properties extends TProperties, Result extends PropertyKey = {
1670
+ [Key in keyof Properties]: Properties[Key] extends TReadonly<TSchema> ? (Properties[Key] extends TOptional<Properties[Key]> ? never : Key) : never;
1671
+ }[keyof Properties]> = Result;
1672
+ type OptionalKeys<Properties extends TProperties, Result extends PropertyKey = {
1673
+ [Key in keyof Properties]: Properties[Key] extends TOptional<TSchema> ? (Properties[Key] extends TReadonly<Properties[Key]> ? never : Key) : never;
1674
+ }[keyof Properties]> = Result;
1675
+ type RequiredKeys<Properties extends TProperties, Result extends PropertyKey = keyof Omit<Properties, ReadonlyOptionalKeys<Properties> | ReadonlyKeys<Properties> | OptionalKeys<Properties>>> = Result;
1676
+ type StaticPropertiesWithModifiers<Properties extends TProperties, PropertiesWithoutModifiers extends Record<PropertyKey, unknown>> = StaticEvaluate<Readonly<Partial<Pick<PropertiesWithoutModifiers, ReadonlyOptionalKeys<Properties>>>> & Readonly<Pick<PropertiesWithoutModifiers, ReadonlyKeys<Properties>>> & Partial<Pick<PropertiesWithoutModifiers, OptionalKeys<Properties>>> & Required<Pick<PropertiesWithoutModifiers, RequiredKeys<Properties>>>>;
1677
+ type StaticPropertiesWithoutModifiers<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Properties extends TProperties, Result extends Record<PropertyKey, unknown> = {
1678
+ [Key in keyof Properties]: StaticType<Stack, Direction, Context, This, Properties[Key]>;
1679
+ }> = Result;
1680
+ type StaticProperties<Stack extends string[], Direction extends StaticDirection, Context extends TProperties, This extends TProperties, Properties extends TProperties, PropertiesWithoutModifiers extends Record<PropertyKey, unknown> = StaticPropertiesWithoutModifiers<Stack, Direction, Context, This, Properties>, PropertiesWithModifiers extends Record<PropertyKey, unknown> = StaticPropertiesWithModifiers<Properties, PropertiesWithoutModifiers>, Result extends Record<PropertyKey, unknown> = {
1681
+ [Key in keyof PropertiesWithModifiers]: PropertiesWithModifiers[Key];
1682
+ }> = Result;
1683
+ /** Represents a Record<PropertyKey, TSchema> structure. */
1684
+ interface TProperties extends TSchema {
1685
+ [key: PropertyKey]: TSchema;
1686
+ }
1687
+ /** Creates a RequiredArray derived from the given TProperties value. */
1688
+ type TRequiredArray<Properties extends TProperties, RequiredProperties extends TProperties = {
1689
+ [Key in keyof Properties as Properties[Key] extends TOptional<Properties[Key]> ? never : Key]: Properties[Key];
1690
+ }, RequiredKeys extends string[] = TUnionToTuple<Extract<keyof RequiredProperties, string>>, Result extends string[] | undefined = RequiredKeys extends [] ? undefined : RequiredKeys> = Result;
1691
+ type TKeyToString<Key extends number | string> = `${Key}`;
1692
+ /** Extracts a tuple of keys from a TProperties value. */
1693
+ type TPropertyKeys<Properties extends TProperties, ExtractKey extends number | string = Extract<keyof Properties, number | string>, StringKey extends string = TKeyToString<ExtractKey>, Result extends string[] = TUnionToTuple<StringKey>> = Result;
1694
+ type TPropertyValuesReduce<Properties extends TProperties, Keys extends string[], Result extends TSchema[] = []> = Keys extends [infer Left extends string, ...infer Right extends string[]] ? Left extends keyof Properties ? TPropertyValuesReduce<Properties, Right, [...Result, Properties[Left]]> : TPropertyValuesReduce<Properties, Right, Result> : Result;
1695
+ /** Extracts a tuple of property values from a TProperties value. */
1696
+ type TPropertyValues<Properties extends TProperties, Keys extends string[] = TPropertyKeys<Properties>, Result extends TSchema[] = TPropertyValuesReduce<Properties, Keys>> = Result;
1697
+
1698
+ type TAddImmutableOperation<Type extends TSchema, Result extends TSchema = '~immutable' extends keyof Type ? Type : TImmutable<Type>> = Result;
1699
+ type TAddImmutableAction<Type extends TSchema, Result extends TSchema = TAddImmutableOperation<Type>> = Result;
1700
+ type TAddImmutableInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TAddImmutableAction<InstantiateType>;
1701
+
1702
+ /** Applies an AddImmutable action to a type. */
1703
+ type TAddImmutable<Type extends TSchema> = (TAddImmutableAction<Type>);
1704
+
1705
+ type AttributeValue = string | number | boolean | readonly string[] | readonly number[] | readonly boolean[];
1706
+ interface SpanAttributes {
1707
+ [name: string]: AttributeValue | undefined;
1708
+ }
1709
+ interface SpanOptions {
1710
+ name: string;
1711
+ attributes?: SpanAttributes;
1712
+ }
1713
+ type SpanStatus = {
1714
+ status: "ok";
1715
+ } | {
1716
+ status: "error";
1717
+ error?: {
1718
+ name: string;
1719
+ message: string;
1720
+ };
1721
+ };
1722
+ interface TelemetryContext {
1723
+ startSpan<T>(options: SpanOptions, callback: (span: TelemetrySpan) => T | Promise<T>): Promise<T>;
1724
+ }
1725
+ interface TelemetrySpan extends TelemetryContext {
1726
+ addEvent(name: string, attributes?: SpanAttributes): void;
1727
+ setAttributes(attributes: SpanAttributes): void;
1728
+ setStatus(status: SpanStatus): void;
1729
+ }
1730
+
1731
+ /** Azure models ship without a baseUrl: one resource per user, resolved per request. */
1732
+ interface AzureEndpointOptions extends StreamOptions {
1733
+ azureApiVersion?: string;
1734
+ azureResourceName?: string;
1735
+ azureBaseUrl?: string;
1736
+ azureDeploymentName?: string;
1737
+ }
1738
+
1739
+ interface AzureOpenAIResponsesOptions extends AzureEndpointOptions {
1740
+ reasoningEffort?: "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
1741
+ toolChoice?: ResponseCreateParamsStreaming["tool_choice"];
1742
+ reasoningSummary?: "auto" | "detailed" | "concise" | null;
1743
+ }
1744
+
1745
+ type BedrockThinkingDisplay = "summarized" | "omitted";
1746
+ interface BedrockOptions extends StreamOptions {
1747
+ region?: string;
1748
+ profile?: string;
1749
+ toolChoice?: "auto" | "any" | "none" | {
1750
+ type: "tool";
1751
+ name: string;
1752
+ };
1753
+ reasoning?: ThinkingLevel;
1754
+ thinkingBudgets?: ThinkingBudgets;
1755
+ interleavedThinking?: boolean;
1756
+ /**
1757
+ * Controls how Claude's thinking content is returned in responses.
1758
+ * - "summarized": Thinking blocks contain summarized thinking text (default here).
1759
+ * - "omitted": Thinking content is redacted but the signature still travels back
1760
+ * for multi-turn continuity, reducing time-to-first-text-token.
1761
+ *
1762
+ * Note: Anthropic's API default for Claude Opus 4.8 and Mythos Preview is
1763
+ * "omitted". We default to "summarized" here to keep behavior consistent with
1764
+ * older Claude 4 models. Only applies to Claude models on Bedrock.
1765
+ */
1766
+ thinkingDisplay?: BedrockThinkingDisplay;
1767
+ /** Key-value pairs attached to the inference request for cost allocation tagging.
1768
+ * Keys: max 64 chars, no `aws:` prefix. Values: max 256 chars. Max 50 pairs.
1769
+ * Tags appear in AWS Cost Explorer split cost allocation data.
1770
+ * @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html */
1771
+ requestMetadata?: Record<string, string>;
1772
+ /** Bearer token for Bedrock API key authentication.
1773
+ * When set, bypasses SigV4 signing and sends Authorization: Bearer <token> instead.
1774
+ * Requires `bedrock:CallWithBearerToken` IAM permission on the token's identity.
1775
+ * Set via AWS_BEARER_TOKEN_BEDROCK env var or pass directly.
1776
+ * @see https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonbedrock.html */
1777
+ bearerToken?: string;
1778
+ }
1779
+
1780
+ /**
1781
+ * Shared utilities for Google Generative AI and Google Vertex providers.
1782
+ */
1783
+
1784
+ /**
1785
+ * Thinking level for Gemini 3 models.
1786
+ * Mirrors Google's ThinkingLevel enum values.
1787
+ */
1788
+ type GoogleApiThinkingLevel = "THINKING_LEVEL_UNSPECIFIED" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH";
1789
+
1790
+ interface GoogleOptions extends StreamOptions {
1791
+ toolChoice?: "auto" | "none" | "any";
1792
+ thinking?: {
1793
+ enabled: boolean;
1794
+ budgetTokens?: number;
1795
+ level?: GoogleApiThinkingLevel;
1796
+ };
1797
+ }
1798
+
1799
+ interface GoogleVertexOptions extends StreamOptions {
1800
+ toolChoice?: "auto" | "none" | "any";
1801
+ thinking?: {
1802
+ enabled: boolean;
1803
+ budgetTokens?: number;
1804
+ level?: GoogleApiThinkingLevel;
1805
+ };
1806
+ project?: string;
1807
+ location?: string;
1808
+ }
1809
+
1810
+ /**
1811
+ * Provider-specific options for the Mistral API.
1812
+ */
1813
+ type MistralReasoningEffort = "none" | "low" | "medium" | "high" | "max";
1814
+ interface MistralOptions extends StreamOptions {
1815
+ toolChoice?: "auto" | "none" | "any" | "required" | {
1816
+ type: "function";
1817
+ function: {
1818
+ name: string;
1819
+ };
1820
+ };
1821
+ promptMode?: "reasoning";
1822
+ reasoningEffort?: MistralReasoningEffort;
1823
+ }
1824
+
1825
+ interface OpenAICodexResponsesOptions extends StreamOptions {
1826
+ reasoningEffort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
1827
+ reasoningSummary?: "auto" | "concise" | "detailed" | "off" | "on" | null;
1828
+ serviceTier?: ResponseCreateParamsStreaming["service_tier"];
1829
+ textVerbosity?: "low" | "medium" | "high";
1830
+ toolChoice?: "auto" | "none" | "required";
1831
+ }
1832
+
1833
+ interface OpenAICompletionsOptions extends StreamOptions {
1834
+ toolChoice?: OpenAI.Chat.Completions.ChatCompletionToolChoiceOption;
1835
+ reasoningEffort?: "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
1836
+ /** Token budgets per thinking level. Used when `compat.thinkingTokenBudgetField` or `compat.supportsThinkingTokenBudget` is set, or by `{ "$var": "thinking.budget" }`. */
1837
+ thinkingBudgets?: ThinkingBudgets;
1838
+ }
1839
+
1840
+ interface OpenAIResponsesOptions extends StreamOptions {
1841
+ reasoningEffort?: "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
1842
+ reasoningSummary?: "auto" | "detailed" | "concise" | null;
1843
+ serviceTier?: ResponseCreateParamsStreaming["service_tier"];
1844
+ toolChoice?: ResponseCreateParamsStreaming["tool_choice"];
1845
+ }
1846
+
1847
+ /**
1848
+ * pi-messages API implementation.
1849
+ *
1850
+ * Streams pi's own message protocol directly to a backend: the request is a
1851
+ * single POST of `{ model, context, options }` to `<baseUrl>/messages`, the
1852
+ * response is an SSE stream of serialized assistant-message events plus a
1853
+ * terminal `done`/`error` event. This is the wire protocol spoken by the
1854
+ * Radius gateway, but any backend implementing it can be used, e.g. via a
1855
+ * models.json custom provider with `"api": "pi-messages"`.
1856
+ */
1857
+
1858
+ interface PiMessagesOptions extends StreamOptions {
1859
+ reasoning?: ThinkingLevel;
1860
+ toolChoice?: "auto" | "none" | "required" | {
1861
+ type: "function";
1862
+ function: {
1863
+ name: string;
1864
+ };
1865
+ };
1866
+ /** Ask the backend for debug metadata (e.g. routing response headers). */
1867
+ debug?: boolean;
1868
+ }
1869
+
1870
+ declare const OpenAICompletionsCompatSchema: TObject<{
1871
+ supportsStore: TOptional<TBoolean>;
1872
+ supportsDeveloperRole: TOptional<TBoolean>;
1873
+ supportsReasoningEffort: TOptional<TBoolean>;
1874
+ supportsUsageInStreaming: TOptional<TBoolean>;
1875
+ supportsFinishReason: TOptional<TBoolean>;
1876
+ maxTokensField: TOptional<TUnion<[TLiteral<"max_completion_tokens">, TLiteral<"max_tokens">]>>;
1877
+ requiresToolResultName: TOptional<TBoolean>;
1878
+ requiresAssistantAfterToolResult: TOptional<TBoolean>;
1879
+ requiresThinkingAsText: TOptional<TBoolean>;
1880
+ requiresReasoningContentOnAssistantMessages: TOptional<TBoolean>;
1881
+ thinkingFormat: TOptional<TUnion<[TLiteral<"openai">, TLiteral<"openrouter">, TLiteral<"deepseek">, TLiteral<"together">, TLiteral<"baseten">, TLiteral<"zai">, TLiteral<"qwen">, TLiteral<"chat-template">, TLiteral<"qwen-chat-template">, TLiteral<"string-thinking">, TLiteral<"ant-ling">]>>;
1882
+ chatTemplateKwargs: TOptional<TRecord<"^.*$", TUnion<[TString, TNumber, TBoolean, TNull, TObject<{
1883
+ $var: TUnion<[TLiteral<"thinking.enabled">, TLiteral<"thinking.effort">, TLiteral<"thinking.budget">]>;
1884
+ omitWhenOff: TOptional<TBoolean>;
1885
+ }>]>>>;
1886
+ chatTemplateArgs: TOptional<TRecord<"^.*$", TUnion<[TString, TNumber, TBoolean, TNull, TObject<{
1887
+ $var: TUnion<[TLiteral<"thinking.enabled">, TLiteral<"thinking.effort">, TLiteral<"thinking.budget">]>;
1888
+ omitWhenOff: TOptional<TBoolean>;
1889
+ }>]>>>;
1890
+ openRouterRouting: TOptional<TObject<{
1891
+ allow_fallbacks: TOptional<TBoolean>;
1892
+ require_parameters: TOptional<TBoolean>;
1893
+ data_collection: TOptional<TUnion<[TLiteral<"deny">, TLiteral<"allow">]>>;
1894
+ zdr: TOptional<TBoolean>;
1895
+ enforce_distillable_text: TOptional<TBoolean>;
1896
+ order: TOptional<TArray<TString>>;
1897
+ only: TOptional<TArray<TString>>;
1898
+ ignore: TOptional<TArray<TString>>;
1899
+ quantizations: TOptional<TArray<TString>>;
1900
+ sort: TOptional<TUnion<[TString, TObject<{
1901
+ by: TOptional<TString>;
1902
+ partition: TOptional<TUnion<[TString, TNull]>>;
1903
+ }>]>>;
1904
+ max_price: TOptional<TObject<{
1905
+ prompt: TOptional<TUnion<[TNumber, TString]>>;
1906
+ completion: TOptional<TUnion<[TNumber, TString]>>;
1907
+ image: TOptional<TUnion<[TNumber, TString]>>;
1908
+ audio: TOptional<TUnion<[TNumber, TString]>>;
1909
+ request: TOptional<TUnion<[TNumber, TString]>>;
1910
+ }>>;
1911
+ preferred_min_throughput: TOptional<TUnion<[TNumber, TObject<{
1912
+ p50: TOptional<TNumber>;
1913
+ p75: TOptional<TNumber>;
1914
+ p90: TOptional<TNumber>;
1915
+ p99: TOptional<TNumber>;
1916
+ }>]>>;
1917
+ preferred_max_latency: TOptional<TUnion<[TNumber, TObject<{
1918
+ p50: TOptional<TNumber>;
1919
+ p75: TOptional<TNumber>;
1920
+ p90: TOptional<TNumber>;
1921
+ p99: TOptional<TNumber>;
1922
+ }>]>>;
1923
+ }>>;
1924
+ vercelGatewayRouting: TOptional<TObject<{
1925
+ only: TOptional<TArray<TString>>;
1926
+ order: TOptional<TArray<TString>>;
1927
+ }>>;
1928
+ zaiToolStream: TOptional<TBoolean>;
1929
+ thinkingTokenBudgetField: TOptional<TUnion<[TLiteral<"thinking_token_budget">, TLiteral<"thinking_budget">, TLiteral<"thinking_budget_tokens">]>>;
1930
+ supportsThinkingTokenBudget: TOptional<TBoolean>;
1931
+ supportsOpenAIGrammarTools: TOptional<TBoolean>;
1932
+ supportsMidConvoSystemMessages: TOptional<TBoolean>;
1933
+ supportsMidConvoToolAdditions: TOptional<TBoolean>;
1934
+ supportsStrictMode: TOptional<TBoolean>;
1935
+ cacheControlFormat: TOptional<TLiteral<"anthropic">>;
1936
+ sendSessionAffinityHeaders: TOptional<TBoolean>;
1937
+ sessionAffinityFormat: TOptional<TUnion<[TLiteral<"openai">, TLiteral<"openai-nosession">, TLiteral<"openrouter">]>>;
1938
+ supportsLongCacheRetention: TOptional<TBoolean>;
1939
+ vllmPriority: TOptional<TNumber>;
1940
+ }>;
1941
+ declare const OpenAIResponsesCompatSchema: TObject<{
1942
+ supportsDeveloperRole: TOptional<TBoolean>;
1943
+ supportsMidConvoSystemMessages: TOptional<TBoolean>;
1944
+ sessionAffinityFormat: TOptional<TUnion<[TLiteral<"openai">, TLiteral<"openai-nosession">, TLiteral<"openrouter">]>>;
1945
+ supportsLongCacheRetention: TOptional<TBoolean>;
1946
+ supportsStrictMode: TOptional<TBoolean>;
1947
+ supportsOpenAIGrammarTools: TOptional<TBoolean>;
1948
+ supportsAdditionalTools: TOptional<TBoolean>;
1949
+ supportsToolSearch: TOptional<TBoolean>;
1950
+ supportsExplicitPromptCacheMode: TOptional<TBoolean>;
1951
+ supportsMaxOutputTokens: TOptional<TBoolean>;
1952
+ }>;
1953
+ declare const AnthropicMessagesCompatSchema: TObject<{
1954
+ supportsEagerToolInputStreaming: TOptional<TBoolean>;
1955
+ supportsLongCacheRetention: TOptional<TBoolean>;
1956
+ sendSessionAffinityHeaders: TOptional<TBoolean>;
1957
+ sessionAffinityFormat: TOptional<TLiteral<"openrouter">>;
1958
+ supportsCacheControlOnTools: TOptional<TBoolean>;
1959
+ supportsTemperature: TOptional<TBoolean>;
1960
+ forceAdaptiveThinking: TOptional<TBoolean>;
1961
+ allowEmptySignature: TOptional<TBoolean>;
1962
+ supportsStrictTools: TOptional<TBoolean>;
1963
+ supportsMidConvoEffort: TOptional<TBoolean>;
1964
+ supportsMidConvoSystemMessages: TOptional<TBoolean>;
1965
+ supportsMidConvoToolChanges: TOptional<TBoolean>;
1966
+ allowedFallbackModels: TOptional<TArray<TObject<{
1967
+ provider: TString;
1968
+ model: TString;
1969
+ cost: TObject<{
1970
+ input: TNumber;
1971
+ output: TNumber;
1972
+ cacheRead: TNumber;
1973
+ cacheWrite: TNumber;
1974
+ tiers: TOptional<TArray<TObject<{
1975
+ input: TNumber;
1976
+ output: TNumber;
1977
+ cacheRead: TNumber;
1978
+ cacheWrite: TNumber;
1979
+ inputTokensAbove: TNumber;
1980
+ }>>>;
1981
+ }>;
1982
+ }>>>;
1983
+ }>;
1984
+ declare const BedrockCompatSchema: TObject<{
1985
+ supportsStrictMode: TOptional<TBoolean>;
1986
+ }>;
1987
+ declare const MistralConversationsCompatSchema: TObject<{
1988
+ supportsMidConvoSystemMessages: TOptional<TBoolean>;
1989
+ }>;
1990
+ /** Compatibility settings for OpenAI-compatible completions APIs. */
1991
+ interface OpenAICompletionsCompat extends Static<typeof OpenAICompletionsCompatSchema> {
1992
+ }
1993
+ /** Compatibility settings for OpenAI Responses APIs. */
1994
+ interface OpenAIResponsesCompat extends Static<typeof OpenAIResponsesCompatSchema> {
1995
+ }
1996
+ /** Compatibility settings for Anthropic Messages-compatible APIs. */
1997
+ interface AnthropicMessagesCompat extends Static<typeof AnthropicMessagesCompatSchema> {
1998
+ }
1999
+ /** Compatibility settings for Amazon Bedrock models. */
2000
+ interface BedrockCompat extends Static<typeof BedrockCompatSchema> {
2001
+ }
2002
+ /** Compatibility settings for the Mistral chat API. */
2003
+ interface MistralConversationsCompat extends Static<typeof MistralConversationsCompatSchema> {
2004
+ }
2005
+
2006
+ declare const ThinkingLevelSchema: TEnum<["minimal", "low", "medium", "high", "xhigh", "max"]>;
2007
+ declare const ModelThinkingLevelSchema: TEnum<["off", "minimal", "low", "medium", "high", "xhigh", "max"]>;
2008
+ declare const ModelInputModalitySchema: TEnum<["text", "image"]>;
2009
+ declare const CacheRetentionSchema: TEnum<["none", "short", "long"]>;
2010
+ declare const ThinkingLevelMapSchema: TObject<{
2011
+ high: TOptional<TUnion<[TString, TNull]>>;
2012
+ low: TOptional<TUnion<[TString, TNull]>>;
2013
+ max: TOptional<TUnion<[TString, TNull]>>;
2014
+ medium: TOptional<TUnion<[TString, TNull]>>;
2015
+ minimal: TOptional<TUnion<[TString, TNull]>>;
2016
+ off: TOptional<TUnion<[TString, TNull]>>;
2017
+ xhigh: TOptional<TUnion<[TString, TNull]>>;
2018
+ }>;
2019
+ declare const ModelPromptCacheSchema: TObject<{
2020
+ long: TOptional<TNumber>;
2021
+ short: TOptional<TNumber>;
2022
+ }>;
2023
+ declare const ModelCostSchema: TObject<{
2024
+ input: TNumber;
2025
+ output: TNumber;
2026
+ cacheRead: TNumber;
2027
+ cacheWrite: TNumber;
2028
+ tiers: TOptional<TArray<TObject<{
2029
+ input: TNumber;
2030
+ output: TNumber;
2031
+ cacheRead: TNumber;
2032
+ cacheWrite: TNumber;
2033
+ inputTokensAbove: TNumber;
2034
+ }>>>;
2035
+ }>;
2036
+ declare const ModelInputLimitsSchema: TObject<{
2037
+ maxRequestBytes: TOptional<TInteger>;
2038
+ images: TOptional<TObject<{
2039
+ resize: TOptional<TObject<{
2040
+ maxWidth: TOptional<TInteger>;
2041
+ maxHeight: TOptional<TInteger>;
2042
+ maxBytes: TOptional<TInteger>;
2043
+ jpegQuality: TOptional<TInteger>;
2044
+ }>>;
2045
+ maxPerMessage: TOptional<TInteger>;
2046
+ maxPerRequest: TOptional<TInteger>;
2047
+ }>>;
2048
+ }>;
2049
+ type ThinkingLevel = Static<typeof ThinkingLevelSchema>;
2050
+ type ModelThinkingLevel = Static<typeof ModelThinkingLevelSchema>;
2051
+ type ThinkingLevelMap = Static<typeof ThinkingLevelMapSchema>;
2052
+ type ModelInputModality = Static<typeof ModelInputModalitySchema>;
2053
+ type CacheRetention = Static<typeof CacheRetentionSchema>;
2054
+ type ModelPromptCache = Static<typeof ModelPromptCacheSchema>;
2055
+ type ModelCost = Static<typeof ModelCostSchema>;
2056
+ type ModelInputLimits = Static<typeof ModelInputLimitsSchema>;
2057
+
2058
+ interface DiagnosticErrorInfo {
2059
+ name?: string;
2060
+ message: string;
2061
+ stack?: string;
2062
+ code?: string | number;
2063
+ }
2064
+ interface AssistantMessageDiagnostic {
2065
+ type: string;
2066
+ timestamp: number;
2067
+ error?: DiagnosticErrorInfo;
2068
+ details?: JsonObject;
2069
+ }
2070
+
2071
+ declare class EventStream<T, R = T> implements AsyncIterable<T> {
2072
+ private queue;
2073
+ private waiting;
2074
+ protected done: boolean;
2075
+ private finalResultPromise;
2076
+ private resolveFinalResult;
2077
+ private isComplete;
2078
+ private extractResult;
2079
+ constructor(isComplete: (event: T) => boolean, extractResult: (event: T) => R);
2080
+ push(event: T): void;
2081
+ end(result?: R): void;
2082
+ [Symbol.asyncIterator](): AsyncIterator<T>;
2083
+ result(): Promise<R>;
2084
+ }
2085
+ /**
2086
+ * Event stream of one assistant response. It also times the response: the final message (`done` or `error` event, or
2087
+ * the result passed to `end()`) gets `durationMs`, measured with a monotonic clock from the stream's creation, unless
2088
+ * the message already has one or its `timestamp` predates the stream. A stream that forwards a response which started
2089
+ * elsewhere, such as a deferred result fetched later, therefore leaves it untimed.
2090
+ */
2091
+ declare class AssistantMessageEventStream extends EventStream<AssistantMessageEvent, AssistantMessage> {
2092
+ #private;
2093
+ constructor();
2094
+ push(event: AssistantMessageEvent): void;
2095
+ end(result?: AssistantMessage): void;
2096
+ }
2097
+
2098
+ type KnownApi = "openai-completions" | "mistral-conversations" | "openai-responses" | "azure-openai-responses" | "openai-codex-responses" | "anthropic-messages" | "bedrock-converse-stream" | "google-generative-ai" | "google-vertex" | "pi-messages";
2099
+ type Api = KnownApi | (string & {});
2100
+ type KnownImageApi = "openrouter-images";
2101
+ type ImageApi = KnownImageApi | (string & {});
2102
+ type KnownClassifierApi = "typesafe-system-one" | "cloudflare-workers-ai-system-one" | "llama-cpp-classify" | "openai-decisions";
2103
+ type ClassifierApi = KnownClassifierApi | (string & {});
2104
+ type KnownProvider = "amazon-bedrock" | "ant-ling" | "anthropic" | "google" | "google-vertex" | "openai" | "azure" | "openai-codex" | "radius" | "typesafe" | "nvidia" | "deepseek" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "zai-coding-cn" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "together" | "baseten" | "opencode" | "opencode-go" | "kimi-coding" | "meta" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "qwen-token-plan" | "qwen-token-plan-cn" | "qwen-token-plan-individual" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp";
2105
+ type ProviderId = KnownProvider | string;
2106
+ type ToolChoice = "auto" | "none";
2107
+ type SamplingParams = Record<string, unknown>;
2108
+ type SamplingParamsByThinkingLevel = Partial<Record<ModelThinkingLevel, SamplingParams>>;
2109
+ /** Token budgets for each thinking level (token-based providers only) */
2110
+ interface ThinkingBudgets {
2111
+ minimal?: number;
2112
+ low?: number;
2113
+ medium?: number;
2114
+ high?: number;
2115
+ }
2116
+ type Transport = "sse" | "websocket" | "websocket-cached" | "auto";
2117
+ /** Provider-scoped environment overrides. Values take precedence over process.env. */
2118
+ type ProviderEnv = Record<string, string>;
2119
+ type ProviderHeaders = Record<string, string | null>;
2120
+ type FetchFunction = typeof globalThis.fetch;
2121
+ interface ProviderResponse {
2122
+ status: number;
2123
+ headers: Record<string, string>;
2124
+ }
2125
+ /** Authentication, HTTP transport, and lifecycle callbacks shared by provider requests. */
2126
+ interface ProviderRequestOptions<TModel = Model$1<Api>> {
2127
+ signal?: AbortSignal;
2128
+ /** Explicit parent context for telemetry produced by this logical request. */
2129
+ telemetryContext?: TelemetryContext;
2130
+ apiKey?: string;
2131
+ /**
2132
+ * Optional fetch implementation for provider HTTP requests.
2133
+ * Defaults to `globalThis.fetch`. Provider adapters that cannot inject a custom implementation may reject it.
2134
+ * This does not affect WebSocket transports.
2135
+ */
2136
+ fetch?: FetchFunction;
2137
+ /**
2138
+ * Provider-scoped environment values. These take precedence over process.env for
2139
+ * provider configuration such as regional settings, endpoint placeholders, and
2140
+ * proxy variables.
2141
+ */
2142
+ env?: ProviderEnv;
2143
+ /**
2144
+ * Optional callback for inspecting or replacing provider payloads before sending.
2145
+ * Return undefined to keep the payload unchanged.
2146
+ */
2147
+ onPayload?: (payload: unknown, model: TModel) => unknown | undefined | Promise<unknown | undefined>;
2148
+ /**
2149
+ * Optional callback invoked after an HTTP response is received.
2150
+ */
2151
+ onResponse?: (response: ProviderResponse, model: TModel) => void | Promise<void>;
2152
+ /**
2153
+ * Optional custom HTTP headers to include in API requests.
2154
+ * Merged with provider defaults; caller values override default headers.
2155
+ * On AWS Bedrock these are injected via a Smithy `build`-step middleware so
2156
+ * they are covered by SigV4 signing; reserved headers (`x-amz-*`,
2157
+ * `authorization`, `host`) are silently ignored to preserve SigV4 / bearer auth.
2158
+ * A null value suppresses a provider/API default header with the same name.
2159
+ */
2160
+ headers?: ProviderHeaders;
2161
+ /**
2162
+ * HTTP request timeout in milliseconds for providers/SDKs that support it.
2163
+ * For example, OpenAI and Anthropic SDK clients default to 10 minutes.
2164
+ */
2165
+ timeoutMs?: number;
2166
+ /**
2167
+ * Maximum retry attempts for providers/SDKs that support client-side retries.
2168
+ * For example, OpenAI and Anthropic SDK clients default to 2.
2169
+ */
2170
+ maxRetries?: number;
2171
+ /**
2172
+ * Maximum delay in milliseconds to wait for a retry when the server requests a long wait.
2173
+ * If the server's requested delay exceeds this value, the request fails immediately
2174
+ * with an error containing the requested delay, allowing higher-level retry logic
2175
+ * to handle it with user visibility.
2176
+ * Default: 60000 (60 seconds). Set to 0 to disable the cap.
2177
+ */
2178
+ maxRetryDelayMs?: number;
2179
+ }
2180
+ interface StreamOptions extends ProviderRequestOptions<Model$1<Api>> {
2181
+ /**
2182
+ * Optional callback invoked after an HTTP response is received and before
2183
+ * its body stream is consumed.
2184
+ */
2185
+ onResponse?: (response: ProviderResponse, model: Model$1<Api>) => void | Promise<void>;
2186
+ /**
2187
+ * Optional observer for each parsed provider stream event before Pi normalization.
2188
+ * Event data is adapter-owned and must be treated as read-only.
2189
+ * Adapter support is explicit; unsupported adapters do not invoke it.
2190
+ */
2191
+ onProviderStreamEvent?: (data: unknown, model: Model$1<Api>) => void | Promise<void>;
2192
+ temperature?: number;
2193
+ /**
2194
+ * Arbitrary sampling parameters merged into the request body as-is, after the named request
2195
+ * fields, so keys here override them. Lets custom OpenAI-compatible servers (llama.cpp, vLLM,
2196
+ * SGLang, ...) receive parameters pi does not model, e.g. `top_p`, `top_k`, `min_p`,
2197
+ * `repetition_penalty`. Merged over `Model.samplingParams` per key. Only applied by
2198
+ * OpenAI-compatible adapters (completions, responses, Azure responses); other APIs ignore it.
2199
+ */
2200
+ samplingParams?: SamplingParams;
2201
+ maxTokens?: number;
2202
+ /**
2203
+ * Preferred transport for providers that support multiple transports.
2204
+ * Providers that do not support this option ignore it.
2205
+ */
2206
+ transport?: Transport;
2207
+ /**
2208
+ * Prompt cache retention preference. Providers map this to their supported values.
2209
+ * Default: "short".
2210
+ */
2211
+ cacheRetention?: CacheRetention;
2212
+ /**
2213
+ * Optional session identifier for providers that support session-based caching.
2214
+ * Providers can use this to enable prompt caching, request routing, or other
2215
+ * session-aware features. Ignored by providers that don't support it.
2216
+ */
2217
+ sessionId?: string;
2218
+ /**
2219
+ * WebSocket connect timeout in milliseconds for providers that support
2220
+ * WebSocket transports. This covers the connection/open handshake only;
2221
+ * stream idleness after connection uses timeoutMs.
2222
+ */
2223
+ websocketConnectTimeoutMs?: number;
2224
+ /**
2225
+ * Optional metadata to include in API requests.
2226
+ * Providers extract the fields they understand and ignore the rest.
2227
+ * For example, Anthropic uses `user_id` for abuse tracking and rate limiting.
2228
+ */
2229
+ metadata?: Record<string, unknown>;
2230
+ }
2231
+ interface DeferredFetchOptions extends ProviderRequestOptions<Model$1<Api>> {
2232
+ /**
2233
+ * Maximum provider long-poll duration in milliseconds.
2234
+ * Defaults to 0, which performs one status check.
2235
+ */
2236
+ wait?: number;
2237
+ }
2238
+ /** Request options for best-effort deferred-response cancellation. */
2239
+ type DeferredCancelOptions = ProviderRequestOptions<Model$1<Api>>;
2240
+ /**
2241
+ * Maps known APIs to their full provider-specific stream option types.
2242
+ * Type-only imports from API implementation modules are erased at emit, so
2243
+ * this is tree-shake safe.
2244
+ */
2245
+ interface ApiOptionsMap {
2246
+ "anthropic-messages": AnthropicOptions;
2247
+ "openai-completions": OpenAICompletionsOptions;
2248
+ "openai-responses": OpenAIResponsesOptions;
2249
+ "openai-codex-responses": OpenAICodexResponsesOptions;
2250
+ "azure-openai-responses": AzureOpenAIResponsesOptions;
2251
+ "google-generative-ai": GoogleOptions;
2252
+ "google-vertex": GoogleVertexOptions;
2253
+ "mistral-conversations": MistralOptions;
2254
+ "bedrock-converse-stream": BedrockOptions;
2255
+ "pi-messages": PiMessagesOptions;
2256
+ }
2257
+ /**
2258
+ * Full stream options for an API. Known APIs resolve to their concrete option
2259
+ * type; custom API strings fall back to the generic shape.
2260
+ */
2261
+ type ApiStreamOptions<TApi extends Api> = TApi extends keyof ApiOptionsMap ? ApiOptionsMap[TApi] : StreamOptions & Record<string, unknown>;
2262
+ interface ClassifierOptions extends ProviderRequestOptions<ClassifierModel<ClassifierApi>> {
2263
+ /**
2264
+ * Divides the answer logits by this value before they are normalized into probabilities.
2265
+ * Values above 1 soften the distribution; values below 1 sharpen it. Must be positive.
2266
+ * APIs that cannot apply it ignore it.
2267
+ */
2268
+ temperature?: number;
2269
+ }
2270
+ interface ImagesOptions extends ProviderRequestOptions<ImageModel<ImageApi>> {
2271
+ /**
2272
+ * Optional metadata to include in API requests.
2273
+ * Providers extract the fields they understand and ignore the rest.
2274
+ */
2275
+ metadata?: Record<string, unknown>;
2276
+ }
2277
+ interface SimpleStreamOptions extends StreamOptions {
2278
+ /** Provider-neutral tool selection for simple requests. When omitted, adapters use provider-specific behavior. */
2279
+ toolChoice?: ToolChoice;
2280
+ reasoning?: ThinkingLevel;
2281
+ /** Ask a capable provider to return a durable handle and continue the request asynchronously. */
2282
+ deferred?: boolean | {
2283
+ window?: "15m" | "1h" | "24h";
2284
+ };
2285
+ /** Custom token budgets for thinking levels (token-based providers only) */
2286
+ thinkingBudgets?: ThinkingBudgets;
2287
+ }
2288
+ type StreamFunction<TApi extends Api = Api, TOptions extends StreamOptions = StreamOptions> = (model: Model$1<TApi>, context: TranscriptContext, options?: TOptions) => AssistantMessageEventStream;
2289
+ interface TextContent {
2290
+ type: "text";
2291
+ text: string;
2292
+ textSignature?: string;
2293
+ }
2294
+ interface ThinkingContent {
2295
+ type: "thinking";
2296
+ thinking: string;
2297
+ thinkingSignature?: string;
2298
+ /** When true, the thinking content was redacted by safety filters. The opaque
2299
+ * encrypted payload is stored in `thinkingSignature` so it can be passed back
2300
+ * to the API for multi-turn continuity. */
2301
+ redacted?: boolean;
2302
+ }
2303
+ interface ImageContent {
2304
+ type: "image";
2305
+ data: string;
2306
+ mimeType: string;
2307
+ }
2308
+ interface ToolCall {
2309
+ type: "toolCall";
2310
+ id: string;
2311
+ name: string;
2312
+ arguments: JsonObject;
2313
+ thoughtSignature?: string;
2314
+ /** OpenAI Responses namespace for calls to dynamically loaded or namespaced tools. */
2315
+ namespace?: string;
2316
+ }
2317
+ interface Usage {
2318
+ input: number;
2319
+ output: number;
2320
+ cacheRead: number;
2321
+ cacheWrite: number;
2322
+ /** Subset of `cacheWrite` written with 1h retention. Only Anthropic reports this split. */
2323
+ cacheWrite1h?: number;
2324
+ /**
2325
+ * Reasoning/thinking tokens, when the provider reports them. This is a subset of
2326
+ * `output`: `output` already includes these tokens. Set to a number (possibly 0) by
2327
+ * providers that expose a reasoning breakdown; left undefined by providers that don't.
2328
+ */
2329
+ reasoning?: number;
2330
+ totalTokens: number;
2331
+ cost: {
2332
+ input: number;
2333
+ output: number;
2334
+ cacheRead: number;
2335
+ cacheWrite: number;
2336
+ total: number;
2337
+ };
2338
+ }
2339
+ type StopReason = "pending" | "stop" | "length" | "toolUse" | "error" | "aborted" | "deferred";
2340
+ type JsonValue = null | boolean | number | string | readonly JsonValue[] | JsonObject;
2341
+ type JsonObject = {
2342
+ [key: string]: JsonValue;
2343
+ };
2344
+ type IsAny<T> = 0 extends 1 & T ? true : false;
2345
+ type IsExactlyJsonValue<T> = [T] extends [JsonValue] ? ([JsonValue] extends [T] ? true : false) : false;
2346
+ type IsJsonProperty<T> = IsAny<T> extends true ? false : unknown extends T ? false : [Exclude<T, undefined>] extends [never] ? true : IsJsonCompatible<Exclude<T, undefined>>;
2347
+ type InvalidJsonKeys<T extends object> = {
2348
+ [TKey in keyof T]-?: TKey extends string | number ? (IsJsonProperty<T[TKey]> extends true ? never : TKey) : TKey;
2349
+ }[keyof T];
2350
+ type IsJsonCompatible<T> = IsAny<T> extends true ? false : unknown extends T ? false : IsExactlyJsonValue<T> extends true ? true : T extends null | boolean | number | string ? true : T extends undefined ? false : T extends readonly (infer TItem)[] ? IsJsonCompatible<TItem> : T extends (...args: never[]) => unknown ? false : T extends object ? [InvalidJsonKeys<T>] extends [never] ? true : false : false;
2351
+ /** The JSON representation of a typed in-memory value. Optional object properties remain optional. */
2352
+ type JsonRepresentation<T> = IsAny<T> extends true ? JsonValue : unknown extends T ? JsonValue : [T] extends [JsonValue] ? T : T extends readonly unknown[] ? {
2353
+ [TKey in keyof T]: JsonRepresentation<Exclude<T[TKey], undefined>>;
2354
+ } : T extends object ? {
2355
+ [TKey in keyof T]: JsonRepresentation<Exclude<T[TKey], undefined>>;
2356
+ } : never;
2357
+ interface DeferredHandle {
2358
+ provider: string;
2359
+ modelId: string;
2360
+ api: string;
2361
+ /** Provider token, such as a response id or batch id plus row id. */
2362
+ id: string;
2363
+ expiresAt?: number;
2364
+ pollAfterMs?: number;
2365
+ /** Provider conversion data required to reconstruct the final assistant message. */
2366
+ data?: JsonValue;
2367
+ }
2368
+ /**
2369
+ * System instructions and tool declarations at one point in the transcript.
2370
+ *
2371
+ * The leading system message is the system prompt. Later system messages change it:
2372
+ * `content` adds instructions from that point on, `sections` replace or remove named
2373
+ * prompt sections, and `toolsAdded`/`toolsRemoved` change the tool set. Replaying
2374
+ * every system message in order yields the current prompt and tools. Providers that
2375
+ * accept system messages mid-conversation send each one in place; other providers
2376
+ * rebuild the leading system message from the replayed state.
2377
+ */
2378
+ interface SystemMessage {
2379
+ role: "system";
2380
+ /** Instruction text. On the leading message this is the base prompt; later, additional instructions. */
2381
+ content: string | TextContent[];
2382
+ /**
2383
+ * Named, ordered prompt sections rendered verbatim after `content`. The leading message
2384
+ * declares them; later messages replace sections by name, and `null` removes one. Keep
2385
+ * each section self-delimiting (a tag, a heading) so the model can relate an update to
2386
+ * the original. Avoid integer-like names; JSON objects reorder those.
2387
+ */
2388
+ sections?: Record<string, string | null>;
2389
+ /** Complete definitions of tools that become available at this point. */
2390
+ toolsAdded?: Tool[];
2391
+ /** Tools that stop being available at this point. */
2392
+ toolsRemoved?: ToolReference[];
2393
+ timestamp: number;
2394
+ }
2395
+ interface UserMessage {
2396
+ role: "user";
2397
+ content: string | (TextContent | ImageContent)[];
2398
+ timestamp: number;
2399
+ }
2400
+ interface AssistantMessage {
2401
+ role: "assistant";
2402
+ content: (TextContent | ThinkingContent | ToolCall)[];
2403
+ api: Api;
2404
+ provider: ProviderId;
2405
+ model: string;
2406
+ responseModel?: string;
2407
+ responseId?: string;
2408
+ /** Exact provider-native effort level used for this response. Absent for legacy or unmanaged responses. */
2409
+ providerThinkingLevel?: string;
2410
+ /** Pi thinking level the agent loop requested for this response. Absent outside the agent loop and for legacy responses. */
2411
+ thinkingLevel?: ModelThinkingLevel;
2412
+ diagnostics?: AssistantMessageDiagnostic[];
2413
+ usage: Usage;
2414
+ stopReason: StopReason;
2415
+ deferred?: DeferredHandle;
2416
+ errorMessage?: string;
2417
+ rawStopReason?: string;
2418
+ /**
2419
+ * Provider indication of whether the model explicitly ended its turn.
2420
+ * Preserved for debugging and does not currently affect agent control flow.
2421
+ */
2422
+ endTurn?: boolean;
2423
+ /** Unix timestamp in milliseconds when the request started. */
2424
+ timestamp: number;
2425
+ /**
2426
+ * Milliseconds from `timestamp` until the response ended, measured with a monotonic clock. Set by
2427
+ * `AssistantMessageEventStream` on the final message of a response it saw start; absent for legacy messages and
2428
+ * for deferred results fetched later.
2429
+ */
2430
+ durationMs?: number;
2431
+ }
2432
+ /** A tool call that another tool made while it ran, for example from a codemode script. */
2433
+ interface NestedToolCallRecord {
2434
+ id: string;
2435
+ name: string;
2436
+ /** Omitted when over the size limits; `argumentsBytes` then gives their size. */
2437
+ arguments?: JsonObject;
2438
+ /** UTF-8 size of the arguments as JSON, set when `arguments` is omitted. */
2439
+ argumentsBytes?: number;
2440
+ /** `unfinished`: the call was still running when the calling tool finished. */
2441
+ status: "ok" | "error" | "unfinished";
2442
+ durationMs?: number;
2443
+ /** Error text, truncated. */
2444
+ error?: string;
2445
+ }
2446
+ /** Bounded record of the nested calls a tool made. Results are not recorded. */
2447
+ interface NestedToolCalls {
2448
+ calls: NestedToolCallRecord[];
2449
+ /** False when calls were dropped, arguments omitted, or calls had not finished. */
2450
+ complete: boolean;
2451
+ }
2452
+ type ToolResultMessage<TDetails = JsonValue> = IsJsonCompatible<TDetails> extends true ? {
2453
+ role: "toolResult";
2454
+ toolCallId: string;
2455
+ toolName: string;
2456
+ content: (TextContent | ImageContent)[];
2457
+ details?: JsonRepresentation<TDetails>;
2458
+ /** Usage from the tool execution itself, if available. Not part of main LLM context accounting. */
2459
+ usage?: Usage;
2460
+ /** Calls this tool made to other tools. Kept for the session record; not sent to the model. */
2461
+ nestedCalls?: NestedToolCalls;
2462
+ isError: boolean;
2463
+ /** Unix timestamp in milliseconds when the result was created. */
2464
+ timestamp: number;
2465
+ /** Milliseconds the tool's execution took, measured with a monotonic clock. Absent for legacy results. */
2466
+ durationMs?: number;
2467
+ } : never;
2468
+ type Message = SystemMessage | UserMessage | AssistantMessage | ToolResultMessage;
2469
+ type ImagesInputContent = TextContent | ImageContent;
2470
+ type ImagesOutputContent = TextContent | ImageContent;
2471
+ interface ImagesContext {
2472
+ input: ImagesInputContent[];
2473
+ }
2474
+ type ImagesStopReason = "stop" | "error" | "aborted";
2475
+ interface AssistantImages {
2476
+ api: ImageApi;
2477
+ provider: ProviderId;
2478
+ model: string;
2479
+ output: ImagesOutputContent[];
2480
+ responseId?: string;
2481
+ usage?: Usage;
2482
+ stopReason: ImagesStopReason;
2483
+ errorMessage?: string;
2484
+ timestamp: number;
2485
+ }
2486
+ interface ClassifierChoiceQuestion {
2487
+ type: "choice";
2488
+ instructions: string;
2489
+ criteria: Record<string, string>;
2490
+ }
2491
+ interface ClassifierScoreQuestion {
2492
+ type: "score";
2493
+ instructions: string;
2494
+ criteria: string[];
2495
+ }
2496
+ interface ClassifierBoolQuestion {
2497
+ type: "bool";
2498
+ instructions: string;
2499
+ criteria: {
2500
+ true: string;
2501
+ false: string;
2502
+ };
2503
+ }
2504
+ type ClassifierQuestion = ClassifierChoiceQuestion | ClassifierScoreQuestion | ClassifierBoolQuestion;
2505
+ interface ClassifierContext {
2506
+ state: JsonObject;
2507
+ /**
2508
+ * Images judged together with `state`. Only models whose `input` includes `"image"` accept them;
2509
+ * other models return an error result.
2510
+ */
2511
+ images?: ImageContent[];
2512
+ questions: Record<string, ClassifierQuestion>;
2513
+ }
2514
+ interface ClassifierChoiceAnswer {
2515
+ type: "choice";
2516
+ choice: string;
2517
+ probabilities: Record<string, number>;
2518
+ confidence: number;
2519
+ }
2520
+ interface ClassifierScoreAnswer {
2521
+ type: "score";
2522
+ score: number;
2523
+ confidence: number;
2524
+ }
2525
+ interface ClassifierBoolAnswer {
2526
+ type: "bool";
2527
+ probability: number;
2528
+ }
2529
+ type ClassifierAnswer = ClassifierChoiceAnswer | ClassifierScoreAnswer | ClassifierBoolAnswer;
2530
+ type ClassifierStopReason = "stop" | "error" | "aborted";
2531
+ interface ClassifierResult {
2532
+ api: ClassifierApi;
2533
+ provider: ProviderId;
2534
+ model: string;
2535
+ answers: Record<string, ClassifierAnswer>;
2536
+ /** Token usage and its cost at the model's catalog price, when the service reports token counts. */
2537
+ usage?: Usage;
2538
+ stopReason: ClassifierStopReason;
2539
+ errorMessage?: string;
2540
+ timestamp: number;
2541
+ }
2542
+
2543
+ /** OpenAI grammar variants for constrained sampling. */
2544
+ type GrammarFormat = "openai_lark" | "openai_regex";
2545
+ type GrammarVariants = Partial<Record<GrammarFormat, string>>;
2546
+ /**
2547
+ * Optional provider-side constrained sampling configs for a tool.
2548
+ *
2549
+ * The `json_schema` value roughly maps to the concept of `strict` in APIs which is
2550
+ * implemented as json-schema constrained sampling by APIs. Grammar variants let
2551
+ * callers provide provider-specific encodings of the same intended language.
2552
+ */
2553
+ type ConstrainedSamplingConfig = {
2554
+ type: "json_schema";
2555
+ strict: "prefer" | "require";
2556
+ } | {
2557
+ type: "grammar";
2558
+ variants: GrammarVariants;
2559
+ };
2560
+ interface Tool<TParameters extends TSchema = TSchema> {
2561
+ name: string;
2562
+ description: string;
2563
+ parameters: TParameters;
2564
+ constrainedSampling?: false | ConstrainedSamplingConfig;
2565
+ }
2566
+ interface ToolReference {
2567
+ name: string;
2568
+ }
2569
+ /**
2570
+ * Request input accepted by the public stream entry points (`Models.stream()`,
2571
+ * `streamSimple()`, ...). `systemPrompt` and `tools` are shorthand for a leading
2572
+ * system message; `normalizeContext()` folds them into one before the request
2573
+ * reaches a provider.
2574
+ */
2575
+ interface Context$1 {
2576
+ systemPrompt?: string;
2577
+ messages: Message[];
2578
+ tools?: Tool[];
2579
+ }
2580
+ declare const transcriptContextBrand: unique symbol;
2581
+ /**
2582
+ * Normalized request context passed to providers and API implementations. The
2583
+ * prompt and tool declarations are carried by the transcript's system messages.
2584
+ * Only `normalizeContext()` produces this type, so a raw `Context` cannot reach
2585
+ * provider code by accident.
2586
+ */
2587
+ type TranscriptContext = {
2588
+ messages: Message[];
2589
+ readonly [transcriptContextBrand]: true;
2590
+ };
2591
+ /**
2592
+ * Event protocol for AssistantMessageEventStream.
2593
+ *
2594
+ * Successful streams emit `start` before partial updates and terminate with
2595
+ * `done`. A stream may terminate directly with `error` when request setup fails
2596
+ * before generation starts; after `start`, failures also terminate with `error`.
2597
+ * Direct `streamSimple()` calls throw synchronously when request auth is missing.
2598
+ * Updates and `done` must never appear before `start`.
2599
+ *
2600
+ * `partial` is the shared live response-so-far helper, not an event-time
2601
+ * snapshot. Text and thinking blocks are empty when their `*_start` event is
2602
+ * emitted and grow only through their corresponding `*_delta` events until the
2603
+ * authoritative `*_end`. Redacted thinking may be complete at start and emit no
2604
+ * deltas. Tool-call arguments at `toolcall_start` are provider-specific;
2605
+ * `toolcall_delta` carries subsequent JSON updates.
2606
+ */
2607
+ type AssistantMessageEvent = {
2608
+ type: "start";
2609
+ partial: AssistantMessage;
2610
+ } | {
2611
+ type: "text_start";
2612
+ contentIndex: number;
2613
+ partial: AssistantMessage;
2614
+ } | {
2615
+ type: "text_delta";
2616
+ contentIndex: number;
2617
+ delta: string;
2618
+ partial: AssistantMessage;
2619
+ } | {
2620
+ type: "text_end";
2621
+ contentIndex: number;
2622
+ content: string;
2623
+ partial: AssistantMessage;
2624
+ } | {
2625
+ type: "thinking_start";
2626
+ contentIndex: number;
2627
+ partial: AssistantMessage;
2628
+ } | {
2629
+ type: "thinking_delta";
2630
+ contentIndex: number;
2631
+ delta: string;
2632
+ partial: AssistantMessage;
2633
+ } | {
2634
+ type: "thinking_end";
2635
+ contentIndex: number;
2636
+ content: string;
2637
+ partial: AssistantMessage;
2638
+ } | {
2639
+ type: "toolcall_start";
2640
+ contentIndex: number;
2641
+ partial: AssistantMessage;
2642
+ } | {
2643
+ type: "toolcall_delta";
2644
+ contentIndex: number;
2645
+ delta: string;
2646
+ partial: AssistantMessage;
2647
+ } | {
2648
+ type: "toolcall_end";
2649
+ contentIndex: number;
2650
+ toolCall: ToolCall;
2651
+ partial: AssistantMessage;
2652
+ } | {
2653
+ type: "done";
2654
+ reason: Extract<StopReason, "stop" | "length" | "toolUse" | "deferred">;
2655
+ message: AssistantMessage;
2656
+ } | {
2657
+ type: "error";
2658
+ reason: Extract<StopReason, "aborted" | "error">;
2659
+ error: AssistantMessage;
2660
+ };
2661
+ /** Fields shared by every catalog entry, regardless of what you can do with it. */
2662
+ interface BaseModel<TApi extends string> {
2663
+ id: string;
2664
+ name: string;
2665
+ api: TApi;
2666
+ provider: ProviderId;
2667
+ baseUrl: string;
2668
+ input: ModelInputModality[];
2669
+ /** Provider input limits and cache-safe preprocessing metadata. */
2670
+ inputLimits?: ModelInputLimits;
2671
+ cost: ModelCost;
2672
+ headers?: Record<string, string>;
2673
+ }
2674
+ /** Chat model: usable with `stream()` and friends. */
2675
+ interface Model$1<TApi extends Api> extends BaseModel<TApi> {
2676
+ /**
2677
+ * Optional: chat is the default model type, so models without `type` are chat
2678
+ * models. Narrow mixed model lists with `isModelType()` instead of comparing
2679
+ * `type` directly.
2680
+ */
2681
+ type?: "chat";
2682
+ reasoning: boolean;
2683
+ /**
2684
+ * Maps pi thinking levels to provider/model-specific values.
2685
+ * Missing keys use provider defaults. null marks a level as unsupported.
2686
+ */
2687
+ thinkingLevelMap?: ThinkingLevelMap;
2688
+ /** Prompt cache lifetimes per retention tier. Unset when the provider's cache behavior is unknown. */
2689
+ promptCache?: ModelPromptCache;
2690
+ contextWindow: number;
2691
+ maxTokens: number;
2692
+ /** Default sampling parameters for this model. See {@link StreamOptions.samplingParams}; per-request keys override these. */
2693
+ samplingParams?: SamplingParams;
2694
+ /** Sampling parameter overrides selected by the effective pi thinking level. */
2695
+ samplingParamsByThinkingLevel?: SamplingParamsByThinkingLevel;
2696
+ /** Compatibility overrides for OpenAI-compatible APIs. If not set, auto-detected from baseUrl. */
2697
+ compat?: TApi extends "openai-completions" ? OpenAICompletionsCompat : TApi extends "openai-responses" | "azure-openai-responses" | "openai-codex-responses" ? OpenAIResponsesCompat : TApi extends "anthropic-messages" ? AnthropicMessagesCompat : TApi extends "bedrock-converse-stream" ? BedrockCompat : TApi extends "mistral-conversations" ? MistralConversationsCompat : never;
2698
+ }
2699
+ /** Image-generation model: usable with `generateImages()` only. */
2700
+ interface ImageModel<TApi extends ImageApi> extends BaseModel<TApi> {
2701
+ type: "image";
2702
+ /** Output modalities. Always includes `"image"`; `"text"` means the model can also return text blocks. */
2703
+ output: ("text" | "image")[];
2704
+ }
2705
+ /** Structured classifier model: usable with `classify()` only. */
2706
+ interface ClassifierModel<TApi extends ClassifierApi> extends BaseModel<TApi> {
2707
+ type: "classifier";
2708
+ contextWindow: number;
2709
+ }
2710
+ /** Model shape for each model type. */
2711
+ interface ModelTypeMap {
2712
+ chat: Model$1<Api>;
2713
+ image: ImageModel<ImageApi>;
2714
+ classifier: ClassifierModel<ClassifierApi>;
2715
+ }
2716
+ /** What a catalog entry is for. Decides which `Models` operation accepts it. */
2717
+ type ModelType = keyof ModelTypeMap;
2718
+ /** Anything a provider can list. Narrow with `isModelType()`. */
2719
+ type AnyModel = ModelTypeMap[ModelType];
2720
+
2721
+ type AnthropicEffort = "low" | "medium" | "high" | "xhigh" | "max";
2722
+ type AnthropicThinkingDisplay = "summarized" | "omitted";
2723
+ interface AnthropicOptions extends StreamOptions {
2724
+ /**
2725
+ * Enable extended thinking.
2726
+ * For adaptive thinking models: the model decides when/how much to think.
2727
+ * For older models: uses budget-based thinking with thinkingBudgetTokens.
2728
+ * Default: undefined (thinking is omitted unless `streamSimple()` maps
2729
+ * a simple reasoning level to this option, or callers set it explicitly).
2730
+ */
2731
+ thinkingEnabled?: boolean;
2732
+ /**
2733
+ * Token budget for extended thinking (older models only).
2734
+ * Ignored for adaptive thinking models.
2735
+ * Default: 1024 when `thinkingEnabled` is true and no budget is provided.
2736
+ */
2737
+ thinkingBudgetTokens?: number;
2738
+ /**
2739
+ * Effort level for adaptive thinking models.
2740
+ * Controls how much thinking Claude allocates:
2741
+ * - "max": Always thinks with no constraints (Opus 4.6 only)
2742
+ * - "xhigh": Highest reasoning level (Opus 4.7+, Fable 5)
2743
+ * - "high": Always thinks, deep reasoning
2744
+ * - "medium": Moderate thinking, may skip for simple queries
2745
+ * - "low": Minimal thinking, skips for simple tasks
2746
+ * Ignored for older models.
2747
+ * Default: omitted unless `streamSimple()` maps a simple reasoning
2748
+ * level to this option.
2749
+ */
2750
+ effort?: AnthropicEffort;
2751
+ /**
2752
+ * Controls how thinking content is returned in API responses.
2753
+ * - "summarized": Thinking blocks contain summarized thinking text.
2754
+ * - "omitted": Thinking blocks return an empty thinking field; the encrypted
2755
+ * signature still travels back for multi-turn continuity. Use for faster
2756
+ * time-to-first-text-token when your UI does not surface thinking.
2757
+ *
2758
+ * Note: Anthropic's API default for Claude Opus 4.7 and Claude Mythos Preview
2759
+ * is "omitted". We default to "summarized" here to keep behavior consistent
2760
+ * with older Claude 4 models. Set this explicitly to "omitted" to opt in.
2761
+ * Default: "summarized" when thinking is enabled.
2762
+ */
2763
+ thinkingDisplay?: AnthropicThinkingDisplay;
2764
+ /**
2765
+ * Whether to request the interleaved thinking beta header for non-adaptive
2766
+ * thinking models. Adaptive thinking models have interleaved thinking built in,
2767
+ * so the header is skipped for them regardless of this setting.
2768
+ * Default: true.
2769
+ */
2770
+ interleavedThinking?: boolean;
2771
+ /**
2772
+ * Anthropic tool choice behavior. String values map to Anthropic's built-in
2773
+ * choices; `{ type: "tool", name }` forces a specific tool.
2774
+ * Default: omitted (Anthropic default behavior, currently equivalent to auto).
2775
+ */
2776
+ toolChoice?: "auto" | "any" | "none" | {
2777
+ type: "tool";
2778
+ name: string;
2779
+ };
2780
+ /**
2781
+ * Pre-built Anthropic client instance. When provided, skips internal client
2782
+ * construction entirely. Use this to inject alternative SDK clients such as
2783
+ * `AnthropicVertex` that shares the same messaging API.
2784
+ */
2785
+ client?: Anthropic;
2786
+ }
2787
+
2788
+ /**
2789
+ * Request auth for a single model request. If a value cannot be expressed as
2790
+ * `apiKey`, `headers`, or `baseUrl`, it is provider config, not auth.
2791
+ */
2792
+ interface ModelAuth {
2793
+ apiKey?: string;
2794
+ headers?: ProviderHeaders;
2795
+ baseUrl?: string;
2796
+ }
2797
+ /**
2798
+ * Stored api-key credential. `env` holds provider-scoped environment/config
2799
+ * values such as Cloudflare account/gateway ids.
2800
+ */
2801
+ interface ApiKeyCredential {
2802
+ type: "api_key";
2803
+ key?: string;
2804
+ env?: ProviderEnv;
2805
+ }
2806
+ /** OAuth token data returned by extension compatibility flows. */
2807
+ interface OAuthCredentials {
2808
+ refresh: string;
2809
+ access: string;
2810
+ expires: number;
2811
+ [key: string]: unknown;
2812
+ }
2813
+ /** Stored canonical OAuth credential. */
2814
+ interface OAuthCredential extends OAuthCredentials {
2815
+ type: "oauth";
2816
+ }
2817
+ /** One type-tagged credential per provider — the shape of today's auth.json. */
2818
+ type Credential = ApiKeyCredential | OAuthCredential;
2819
+ /** Environment access for auth resolution. Injectable for tests and browsers. */
2820
+ interface AuthContext {
2821
+ env(name: string): Promise<string | undefined>;
2822
+ /** Check whether a file exists. Supports a leading `~`. Always false in browsers. */
2823
+ fileExists(path: string): Promise<boolean>;
2824
+ }
2825
+ /** Result of resolving auth for a model. */
2826
+ interface AuthResult {
2827
+ auth: ModelAuth;
2828
+ /** Provider-scoped environment/config values resolved from credentials and ambient context. */
2829
+ env?: ProviderEnv;
2830
+ /** Human-readable label for status UI: "ANTHROPIC_API_KEY", "OAuth", "~/.aws/credentials". */
2831
+ source?: string;
2832
+ }
2833
+ interface AuthCheck {
2834
+ source?: string;
2835
+ type: "api_key" | "oauth";
2836
+ }
2837
+ /**
2838
+ * Prompt shown to the user during login. `signal` lets the flow cancel a
2839
+ * pending prompt when an out-of-band event resolves the step, e.g. a
2840
+ * `manual_code` prompt raced against a callback server, aborted when the
2841
+ * callback wins.
2842
+ */
2843
+ type AuthPrompt = {
2844
+ signal?: AbortSignal;
2845
+ } & ({
2846
+ type: "text";
2847
+ message: string;
2848
+ placeholder?: string;
2849
+ } | {
2850
+ type: "secret";
2851
+ message: string;
2852
+ placeholder?: string;
2853
+ } | {
2854
+ type: "select";
2855
+ message: string;
2856
+ options: readonly {
2857
+ id: string;
2858
+ label: string;
2859
+ description?: string;
2860
+ }[];
2861
+ } | {
2862
+ type: "manual_code";
2863
+ message: string;
2864
+ placeholder?: string;
2865
+ });
2866
+ interface AuthInfoLink {
2867
+ url: string;
2868
+ label?: string;
2869
+ }
2870
+ type AuthEvent = {
2871
+ type: "info";
2872
+ message: string;
2873
+ links?: readonly AuthInfoLink[];
2874
+ } | {
2875
+ type: "auth_url";
2876
+ url: string;
2877
+ instructions?: string;
2878
+ } | {
2879
+ type: "device_code";
2880
+ userCode: string;
2881
+ verificationUri: string;
2882
+ intervalSeconds?: number;
2883
+ expiresInSeconds?: number;
2884
+ } | {
2885
+ type: "progress";
2886
+ message: string;
2887
+ };
2888
+ /**
2889
+ * Login interaction callbacks serving both api-key and OAuth flows.
2890
+ *
2891
+ * `prompt()` returns the entered/selected string (`select` returns the option
2892
+ * id). Rejects on cancel/abort. `signal` aborts the whole login flow;
2893
+ * per-prompt cancellation uses `AuthPrompt.signal`.
2894
+ */
2895
+ interface AuthInteraction {
2896
+ signal?: AbortSignal;
2897
+ prompt(prompt: AuthPrompt): Promise<string>;
2898
+ notify(event: AuthEvent): void;
2899
+ }
2900
+ /** Normalized interaction passed to provider login implementations. */
2901
+ type ProviderAuthInteraction = AuthInteraction & {
2902
+ signal: AbortSignal;
2903
+ };
2904
+ /**
2905
+ * Api-key auth: stored key/provider env plus ambient sources (env vars, AWS
2906
+ * profiles, ADC files). Ambient-only providers omit `login`.
2907
+ */
2908
+ interface ApiKeyAuth {
2909
+ /** Display name, e.g. "Anthropic API key". */
2910
+ name: string;
2911
+ /** Interactive setup (prompt for key/provider env). Absent = ambient-only. */
2912
+ login?(interaction: ProviderAuthInteraction): Promise<ApiKeyCredential>;
2913
+ /**
2914
+ * Optional side-effect-free availability check. Use this when `resolve()` may
2915
+ * execute commands or perform other request-time work. Missing means Models
2916
+ * checks availability by resolving auth.
2917
+ */
2918
+ check?(input: {
2919
+ ctx: AuthContext;
2920
+ credential?: ApiKeyCredential;
2921
+ signal: AbortSignal;
2922
+ }): Promise<AuthCheck | undefined>;
2923
+ /**
2924
+ * Resolve auth from the stored credential and/or ambient sources, merging
2925
+ * per field (`credential.key ?? env("...")`, `credential.env?.NAME ?? env("...")`).
2926
+ * undefined = not configured. Resolution is provider-scoped; model-specific
2927
+ * endpoint preparation happens after auth has been resolved.
2928
+ */
2929
+ resolve(input: {
2930
+ ctx: AuthContext;
2931
+ credential?: ApiKeyCredential;
2932
+ signal: AbortSignal;
2933
+ }): Promise<AuthResult | undefined>;
2934
+ }
2935
+ /** App-supplied context for `Models.login`. */
2936
+ interface LoginOptions {
2937
+ /**
2938
+ * Returns the stable ID of this app installation, e.g. sent to OpenAI as its
2939
+ * agent host ID. Called only by login flows that need it, so apps can create
2940
+ * the ID on first use and must return the same ID on every later call.
2941
+ */
2942
+ getDeviceId?: () => string;
2943
+ /**
2944
+ * Name this app introduces itself with during login, e.g. OpenAI's agent name hint and
2945
+ * Codex originator. Defaults to pi's own name.
2946
+ */
2947
+ agentName?: string;
2948
+ }
2949
+ /**
2950
+ * OAuth auth. The `refresh`/`toAuth` split lets `Models` own the locked
2951
+ * refresh pattern: `refresh` produces a credential, `toAuth` derives request
2952
+ * auth from whatever credential ends up stored.
2953
+ */
2954
+ interface OAuthAuth {
2955
+ /** Display name, e.g. "Anthropic (Claude Pro/Max)". */
2956
+ name: string;
2957
+ /** Whether access through this auth method is backed by a provider subscription. */
2958
+ isSubscription?: boolean;
2959
+ /** Selector label for the OAuth login option, e.g. "Sign in with SuperGrok or X Premium". */
2960
+ loginLabel?: string;
2961
+ login(interaction: ProviderAuthInteraction, options?: LoginOptions): Promise<OAuthCredential>;
2962
+ /**
2963
+ * Exchange the refresh token. Network call; throws on failure
2964
+ * (invalid_grant etc.). `Models` runs this under the store lock.
2965
+ */
2966
+ refresh(credential: OAuthCredential, signal: AbortSignal): Promise<OAuthCredential>;
2967
+ /**
2968
+ * Side-effect-free derivation of request auth from a valid credential.
2969
+ * Covers per-credential baseUrl (GitHub Copilot). Async so lazy wrappers
2970
+ * can load the implementation on first use.
2971
+ */
2972
+ toAuth(credential: OAuthCredential): Promise<ModelAuth>;
2973
+ }
2974
+ /**
2975
+ * Provider auth. At least one of `apiKey`/`oauth` must be present: even
2976
+ * ambient-credential providers and keyless local servers provide `apiKey`
2977
+ * auth whose `resolve()` reports whether the provider is configured.
2978
+ */
2979
+ interface ProviderAuth {
2980
+ apiKey?: ApiKeyAuth;
2981
+ oauth?: OAuthAuth;
2982
+ }
2983
+
2984
+ interface ModelsStoreEntry {
2985
+ /** Persisted models of every type. */
2986
+ models: readonly AnyModel[];
2987
+ /** Unix timestamp from the remote catalog's Last-Modified header. */
2988
+ lastModified?: number;
2989
+ /** Unix timestamp of the last completed remote check. */
2990
+ checkedAt?: number;
2991
+ /**
2992
+ * Opaque validator from the remote catalog's ETag header, stored verbatim
2993
+ * (quotes included) and echoed back as If-None-Match.
2994
+ */
2995
+ etag?: string;
2996
+ }
2997
+
2998
+ interface ModelsPublication {
2999
+ /** Provider-selected persisted catalog. Omit to leave storage unchanged; null deletes it. */
3000
+ persist?: ModelsStoreEntry | null;
3001
+ /** Optional synchronous update of provider-private in-memory catalog state. */
3002
+ update?: () => void;
3003
+ }
3004
+ interface RefreshModelsContext {
3005
+ /** Effective configured credential. OAuth credentials are refreshed before network access. */
3006
+ credential?: Credential;
3007
+ /** Immutable provider-scoped catalog snapshot captured before this refresh phase. */
3008
+ stored?: Readonly<ModelsStoreEntry>;
3009
+ /**
3010
+ * Generation-checked publication. Persistence policy remains provider-owned;
3011
+ * the update runs synchronously only after the selected persistence mutation.
3012
+ */
3013
+ publish(publication: ModelsPublication): Promise<boolean>;
3014
+ /** False during offline/cache-only initialization. */
3015
+ allowNetwork: boolean;
3016
+ /** Bypass provider freshness checks and fetch immediately when network access is allowed. */
3017
+ force?: boolean;
3018
+ /** Always present, including when the public refresh caller omits its optional signal. */
3019
+ signal: AbortSignal;
3020
+ /**
3021
+ * Base URL of the registered provider, including configuration overrides that wrappers apply
3022
+ * outside the provider receiving this context.
3023
+ */
3024
+ baseUrl?: string;
3025
+ }
3026
+ /** Any model a provider with chat APIs `TApi` can list. */
3027
+ type ProviderModel<TApi extends Api> = Model$1<TApi> | ImageModel<ImageApi> | ClassifierModel<ClassifierApi>;
3028
+ /**
3029
+ * A provider is the concrete runtime unit. It owns id/name/base metadata,
3030
+ * auth methods, model listing, and the operations its models support
3031
+ * (streaming, image generation, classification).
3032
+ *
3033
+ * `TApi` lets concrete provider factories declare which chat APIs their models
3034
+ * use (e.g. `openaiProvider(): Provider<"openai-responses" | "openai-completions">`),
3035
+ * giving typed chat model lists to direct factory users. Other model types use
3036
+ * their operation-specific API unions. Inside a `Models` collection providers
3037
+ * are held as `Provider<Api>`.
3038
+ */
3039
+ interface Provider<TApi extends Api = Api> {
3040
+ readonly id: string;
3041
+ readonly name: string;
3042
+ readonly baseUrl?: string;
3043
+ readonly headers?: ProviderHeaders;
3044
+ /**
3045
+ * Required: at least one of `apiKey`/`oauth`. Every provider has auth
3046
+ * semantics — even providers with only ambient credentials (env vars, AWS
3047
+ * profiles, ADC files) and keyless local servers provide `apiKey` auth
3048
+ * whose `resolve()` reports whether the provider is configured.
3049
+ * `Models.getAuth()` returns undefined when the provider is unconfigured.
3050
+ */
3051
+ readonly auth: ProviderAuth;
3052
+ /**
3053
+ * Current known chat models, sync. Static providers return their catalog;
3054
+ * dynamic providers return the list as of the last `refreshModels()` (empty
3055
+ * before the first). Must not throw; `Models` treats a throwing
3056
+ * implementation as having no models.
3057
+ */
3058
+ getModels(): readonly Model$1<TApi>[];
3059
+ /**
3060
+ * Current known models of every type, sync, with the same contract as
3061
+ * `getModels()`. Providers with only chat models may omit it; `Models` then
3062
+ * uses `getModels()`. Model ids are unique within each type; one upstream
3063
+ * model may have separate entries for different operations.
3064
+ */
3065
+ getAllModels?(): readonly ProviderModel<TApi>[];
3066
+ /**
3067
+ * Dynamic providers only: restore `context.stored` and optionally fetch a newer list using
3068
+ * the effective credential. Implementations retain their previous list on failure, publish
3069
+ * persistence and synchronous state changes through `context.publish()`, and honor the
3070
+ * shared abort signal for blocking work.
3071
+ */
3072
+ refreshModels?(context: RefreshModelsContext): Promise<void>;
3073
+ /**
3074
+ * Optional provider policy for credential-specific model availability.
3075
+ * `getModels()` remains the complete synchronous chat catalog; `Models.getAvailable()`
3076
+ * applies this filter after confirming that provider auth is configured.
3077
+ */
3078
+ filterModels?(models: readonly Model$1<TApi>[], credential: Credential | undefined): readonly Model$1<TApi>[];
3079
+ /**
3080
+ * Optional credential-specific availability policy across every model type.
3081
+ * Without it, `Models.getAllAvailable()` applies `filterModels` to chat models
3082
+ * and keeps every other model.
3083
+ */
3084
+ filterAllModels?(models: readonly ProviderModel<TApi>[], credential: Credential | undefined): readonly ProviderModel<TApi>[];
3085
+ /** Stream a normalized transcript. `Models` normalizes the caller's `Context` before dispatching here. */
3086
+ stream<T extends TApi>(model: Model$1<T>, context: TranscriptContext, options?: ApiStreamOptions<T>): AssistantMessageEventStream;
3087
+ streamSimple(model: Model$1<TApi>, context: TranscriptContext, options?: SimpleStreamOptions): AssistantMessageEventStream;
3088
+ fetchDeferred?(model: Model$1<TApi>, handle: DeferredHandle, options?: DeferredFetchOptions): AssistantMessageEventStream;
3089
+ cancelDeferred?(model: Model$1<TApi>, handle: DeferredHandle, options?: DeferredCancelOptions): Promise<void>;
3090
+ /** Present when the provider supports dedicated image models. Never rejects. */
3091
+ generateImages?(model: ImageModel<ImageApi>, context: ImagesContext, options?: ImagesOptions): Promise<AssistantImages>;
3092
+ /** Present when the provider supports structured classifier models. Never rejects. */
3093
+ classify?(model: ClassifierModel<ClassifierApi>, context: ClassifierContext, options?: ClassifierOptions): Promise<ClassifierResult>;
3094
+ }
3095
+
3096
+ /** Settings discovery includes lifecycle data that the host's generic model DTO omits. */
3097
+
3098
+ interface GoModel {
3099
+ id: string;
3100
+ name?: string;
3101
+ contextWindow?: number;
3102
+ maxTokens?: number;
3103
+ /** Token budget controls available to this model, including their catalog bounds. */
3104
+ reasoningBudget?: ThinkingBudgetRange;
3105
+ deprecated?: boolean;
3106
+ releaseDate?: string;
3107
+ /** Input modalities models.dev declares, in {@link INPUT_MODALITIES} order. */
3108
+ inputModalities?: readonly InputModality[];
3109
+ /** Advertised by the gateway but lacking a usable protocol and capability configuration. */
3110
+ configurationMissing?: boolean;
3111
+ }
3112
+ interface ThinkingBudgetRange {
3113
+ min: number;
3114
+ max: number;
3115
+ }
3116
+ /**
3117
+ * Input modalities this page can name. models.dev uses these same five tokens, so
3118
+ * an unknown token is dropped rather than rendered as an untranslatable chip.
3119
+ */
3120
+ declare const INPUT_MODALITIES: readonly ["text", "image", "audio", "video", "pdf"];
3121
+ type InputModality = typeof INPUT_MODALITIES[number];
3122
+ /** Last successful check of one catalog source, plus any current refresh failure. */
3123
+ interface GoCatalogSourceStatus {
3124
+ readonly updatedAt?: number;
3125
+ readonly error?: string;
3126
+ readonly warning?: string;
3127
+ }
3128
+ /** A failed refresh retains the Host's usable data with an explicit diagnostic. */
3129
+ interface GoModelCatalog {
3130
+ readonly models: readonly GoModel[];
3131
+ readonly stale: boolean;
3132
+ readonly error?: string;
3133
+ /** Optional for clients reading an older Host response. Timestamps are Unix milliseconds. */
3134
+ readonly sources?: {
3135
+ readonly listing: GoCatalogSourceStatus;
3136
+ readonly metadata: GoCatalogSourceStatus;
3137
+ };
3138
+ }
3139
+ declare module '@deepseek-ai/dsh-typert-protocol' {
3140
+ interface TypertRemoteNamespaceMap {
3141
+ opencodeGoModels: {
3142
+ read(): Promise<RemoteResult<GoModelCatalog>>;
3143
+ };
3144
+ }
3145
+ }
3146
+
3147
+ /** Public SDK types are bundled at build time, alongside the private implementation. */
3148
+
3149
+ /** User controls are independent of the SDK's internal level used to enable a switch. */
3150
+ type Model<TApi extends Api> = Model$1<TApi> & {
3151
+ reasoningControl?: 'toggle' | 'effort' | 'budget';
3152
+ reasoningBudget?: ThinkingBudgetRange;
3153
+ reasoningBudgetPresets?: readonly number[];
3154
+ };
3155
+
3156
+ export type { Api, AssistantMessage, AssistantMessageEvent, Context$1 as Context, ImageContent, Message, Model, ModelCost, ModelThinkingLevel, Provider, SimpleStreamOptions, StreamFunction, TextContent, ThinkingBudgets, ThinkingLevelMap, Tool, ToolCall, Usage };