typia 9.7.2 → 10.0.0-dev.20251107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +153 -153
- package/lib/factories/ProtobufFactory.js +1 -1
- package/lib/factories/ProtobufFactory.mjs +1 -1
- package/lib/programmers/internal/json_schema_station.d.mts +2 -2
- package/lib/programmers/internal/json_schema_station.d.ts +2 -2
- package/lib/programmers/llm/LlmApplicationProgrammer.js +5 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.mjs +5 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.js +1 -4
- package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.mjs +1 -35
- package/package.json +121 -121
- package/src/AssertionGuard.ts +41 -41
- package/src/CamelCase.ts +75 -75
- package/src/IRandomGenerator.ts +337 -337
- package/src/IReadableURLSearchParams.ts +9 -9
- package/src/PascalCase.ts +71 -71
- package/src/Primitive.ts +90 -90
- package/src/Resolved.ts +72 -72
- package/src/SnakeCase.ts +127 -127
- package/src/TypeGuardError.ts +216 -216
- package/src/factories/MetadataCollection.ts +270 -270
- package/src/factories/MetadataCommentTagFactory.ts +632 -632
- package/src/factories/MetadataFactory.ts +402 -402
- package/src/factories/ProtobufFactory.ts +873 -873
- package/src/functional.ts +705 -705
- package/src/http.ts +972 -972
- package/src/internal/_ProtobufReader.ts +188 -188
- package/src/internal/_ProtobufSizer.ts +137 -137
- package/src/internal/_ProtobufWriter.ts +135 -135
- package/src/internal/_jsonStringifyString.ts +42 -42
- package/src/json.ts +643 -643
- package/src/llm.ts +615 -615
- package/src/misc.ts +594 -594
- package/src/module.ts +889 -889
- package/src/notations.ts +751 -751
- package/src/programmers/FeatureProgrammer.ts +605 -605
- package/src/programmers/ImportProgrammer.ts +179 -179
- package/src/programmers/RandomProgrammer.ts +1195 -1195
- package/src/programmers/helpers/ProtobufWire.ts +34 -34
- package/src/programmers/internal/check_array_length.ts +43 -43
- package/src/programmers/internal/check_bigint.ts +46 -46
- package/src/programmers/internal/check_dynamic_key.ts +197 -197
- package/src/programmers/internal/check_dynamic_properties.ts +231 -231
- package/src/programmers/internal/check_everything.ts +21 -21
- package/src/programmers/internal/check_native.ts +23 -23
- package/src/programmers/internal/check_number.ts +108 -108
- package/src/programmers/internal/check_object.ts +72 -72
- package/src/programmers/internal/check_string.ts +46 -46
- package/src/programmers/internal/check_template.ts +46 -46
- package/src/programmers/internal/check_union_array_like.ts +331 -331
- package/src/programmers/internal/decode_union_object.ts +110 -110
- package/src/programmers/internal/feature_object_entries.ts +59 -59
- package/src/programmers/internal/json_schema_escaped.ts +78 -78
- package/src/programmers/internal/json_schema_object.ts +150 -150
- package/src/programmers/internal/json_schema_station.ts +2 -2
- package/src/programmers/internal/metadata_to_pattern.ts +40 -40
- package/src/programmers/internal/postfix_of_tuple.ts +3 -3
- package/src/programmers/internal/prune_object_properties.ts +69 -69
- package/src/programmers/internal/stringify_dynamic_properties.ts +158 -158
- package/src/programmers/internal/stringify_native.ts +5 -5
- package/src/programmers/internal/stringify_regular_properties.ts +77 -77
- package/src/programmers/internal/template_to_pattern.ts +21 -21
- package/src/programmers/internal/wrap_metadata_rest_tuple.ts +21 -21
- package/src/programmers/json/JsonStringifyProgrammer.ts +1124 -1124
- package/src/programmers/llm/LlmApplicationProgrammer.ts +10 -1
- package/src/programmers/llm/LlmSchemaProgrammer.ts +2 -7
- package/src/protobuf.ts +820 -820
- package/src/reflect.ts +46 -46
- package/src/schemas/json/IJsonApplication.ts +77 -77
- package/src/schemas/json/IJsonSchemaCollection.ts +212 -212
- package/src/schemas/json/IJsonSchemaUnit.ts +263 -263
- package/src/schemas/metadata/IMetadataTypeTag.ts +14 -14
- package/src/schemas/metadata/Metadata.ts +669 -669
- package/src/schemas/metadata/MetadataAliasType.ts +57 -57
- package/src/schemas/metadata/MetadataApplication.ts +40 -40
- package/src/schemas/metadata/MetadataArray.ts +47 -47
- package/src/schemas/metadata/MetadataArrayType.ts +51 -51
- package/src/schemas/metadata/MetadataAtomic.ts +85 -85
- package/src/schemas/metadata/MetadataEscaped.ts +45 -45
- package/src/schemas/metadata/MetadataFunction.ts +45 -45
- package/src/schemas/metadata/MetadataObject.ts +46 -46
- package/src/schemas/metadata/MetadataObjectType.ts +137 -137
- package/src/schemas/metadata/MetadataParameter.ts +52 -52
- package/src/schemas/metadata/MetadataProperty.ts +53 -53
- package/src/schemas/metadata/MetadataTemplate.ts +78 -78
- package/src/schemas/metadata/MetadataTuple.ts +28 -28
- package/src/schemas/metadata/MetadataTupleType.ts +61 -61
- package/src/tags/Constant.ts +47 -47
- package/src/tags/ContentMediaType.ts +27 -27
- package/src/tags/Default.ts +52 -52
- package/src/tags/Example.ts +56 -56
- package/src/tags/Examples.ts +56 -56
- package/src/tags/ExclusiveMaximum.ts +44 -44
- package/src/tags/ExclusiveMinimum.ts +44 -44
- package/src/tags/Format.ts +78 -78
- package/src/tags/JsonSchemaPlugin.ts +36 -36
- package/src/tags/MaxItems.ts +31 -31
- package/src/tags/MaxLength.ts +25 -25
- package/src/tags/Maximum.ts +39 -39
- package/src/tags/MinItems.ts +31 -31
- package/src/tags/MinLength.ts +25 -25
- package/src/tags/Minimum.ts +39 -39
- package/src/tags/MultipleOf.ts +42 -42
- package/src/tags/Pattern.ts +49 -49
- package/src/tags/Sequence.ts +37 -37
- package/src/tags/TagBase.ts +102 -102
- package/src/tags/Type.ts +64 -64
- package/src/tags/UniqueItems.ts +34 -34
- package/src/tags/internal/FormatCheatSheet.ts +71 -71
- package/src/transformers/ITransformOptions.ts +70 -70
- package/src/transformers/ImportTransformer.ts +253 -253
- package/src/transformers/NoTransformConfigurationError.ts +16 -16
- package/src/transformers/features/llm/LlmApplicationTransformer.ts +224 -224
- package/src/typings/Equal.ts +18 -18
|
@@ -1,224 +1,224 @@
|
|
|
1
|
-
import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { ExpressionFactory } from "../../../factories/ExpressionFactory";
|
|
5
|
-
import { LiteralFactory } from "../../../factories/LiteralFactory";
|
|
6
|
-
import { MetadataCollection } from "../../../factories/MetadataCollection";
|
|
7
|
-
import { MetadataFactory } from "../../../factories/MetadataFactory";
|
|
8
|
-
import { StatementFactory } from "../../../factories/StatementFactory";
|
|
9
|
-
|
|
10
|
-
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
11
|
-
|
|
12
|
-
import { LlmApplicationProgrammer } from "../../../programmers/llm/LlmApplicationProgrammer";
|
|
13
|
-
import { LlmModelPredicator } from "../../../programmers/llm/LlmModelPredicator";
|
|
14
|
-
|
|
15
|
-
import { ValidationPipe } from "../../../typings/ValidationPipe";
|
|
16
|
-
|
|
17
|
-
import { ITransformProps } from "../../ITransformProps";
|
|
18
|
-
import { ITypiaContext } from "../../ITypiaContext";
|
|
19
|
-
import { TransformerError } from "../../TransformerError";
|
|
20
|
-
|
|
21
|
-
export namespace LlmApplicationTransformer {
|
|
22
|
-
export const transform = (props: ITransformProps): ts.Expression => {
|
|
23
|
-
const dec = decompose("application", props);
|
|
24
|
-
if (dec === null) return props.expression;
|
|
25
|
-
|
|
26
|
-
const literal: ts.Expression = ts.factory.createAsExpression(
|
|
27
|
-
LiteralFactory.write(dec.application),
|
|
28
|
-
props.context.importer.type({
|
|
29
|
-
file: "@samchon/openapi",
|
|
30
|
-
name: "ILlmApplication",
|
|
31
|
-
arguments: [
|
|
32
|
-
ts.factory.createLiteralTypeNode(
|
|
33
|
-
ts.factory.createStringLiteral(dec.application.model),
|
|
34
|
-
),
|
|
35
|
-
],
|
|
36
|
-
}),
|
|
37
|
-
);
|
|
38
|
-
if (!props.expression.arguments?.[0]) return literal;
|
|
39
|
-
return ExpressionFactory.selfCall(
|
|
40
|
-
ts.factory.createBlock(
|
|
41
|
-
[
|
|
42
|
-
StatementFactory.constant({
|
|
43
|
-
name: "application",
|
|
44
|
-
value: literal,
|
|
45
|
-
}),
|
|
46
|
-
ts.factory.createExpressionStatement(
|
|
47
|
-
finalize({
|
|
48
|
-
context: props.context,
|
|
49
|
-
value: ts.factory.createIdentifier("application"),
|
|
50
|
-
argument: props.expression.arguments[0]!,
|
|
51
|
-
equals: dec.config?.equals,
|
|
52
|
-
model: dec.application.model,
|
|
53
|
-
}),
|
|
54
|
-
),
|
|
55
|
-
ts.factory.createReturnStatement(
|
|
56
|
-
ts.factory.createIdentifier("application"),
|
|
57
|
-
),
|
|
58
|
-
],
|
|
59
|
-
true,
|
|
60
|
-
),
|
|
61
|
-
);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
/** @internal */
|
|
65
|
-
export const decompose = (
|
|
66
|
-
method: string,
|
|
67
|
-
props: ITransformProps,
|
|
68
|
-
): {
|
|
69
|
-
application: ILlmApplication<ILlmSchema.Model>;
|
|
70
|
-
type: ts.Type;
|
|
71
|
-
node: ts.TypeNode;
|
|
72
|
-
config:
|
|
73
|
-
| Partial<
|
|
74
|
-
ILlmSchema.IConfig & {
|
|
75
|
-
equals: boolean;
|
|
76
|
-
}
|
|
77
|
-
>
|
|
78
|
-
| undefined;
|
|
79
|
-
} | null => {
|
|
80
|
-
// GET GENERIC ARGUMENT
|
|
81
|
-
if (!props.expression.typeArguments?.length)
|
|
82
|
-
throw new TransformerError({
|
|
83
|
-
code: `typia.llm.${method}`,
|
|
84
|
-
message: "no generic argument.",
|
|
85
|
-
});
|
|
86
|
-
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
87
|
-
if (ts.isTypeNode(top) === false) return null;
|
|
88
|
-
|
|
89
|
-
// GET TYPE
|
|
90
|
-
const model: ILlmSchema.Model = LlmModelPredicator.getModel({
|
|
91
|
-
checker: props.context.checker,
|
|
92
|
-
method,
|
|
93
|
-
node: props.expression.typeArguments[1],
|
|
94
|
-
});
|
|
95
|
-
const config:
|
|
96
|
-
| Partial<
|
|
97
|
-
ILlmSchema.IConfig & {
|
|
98
|
-
equals: boolean;
|
|
99
|
-
}
|
|
100
|
-
>
|
|
101
|
-
| undefined = LlmModelPredicator.getConfig({
|
|
102
|
-
context: props.context,
|
|
103
|
-
method,
|
|
104
|
-
model,
|
|
105
|
-
node: props.expression.typeArguments[2],
|
|
106
|
-
});
|
|
107
|
-
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
108
|
-
|
|
109
|
-
// VALIDATE TYPE
|
|
110
|
-
const analyze = (validate: boolean): Metadata => {
|
|
111
|
-
const result: ValidationPipe<Metadata, MetadataFactory.IError> =
|
|
112
|
-
MetadataFactory.analyze({
|
|
113
|
-
checker: props.context.checker,
|
|
114
|
-
transformer: props.context.transformer,
|
|
115
|
-
options: {
|
|
116
|
-
absorb: validate,
|
|
117
|
-
escape: true,
|
|
118
|
-
constant: true,
|
|
119
|
-
functional: true,
|
|
120
|
-
validate:
|
|
121
|
-
validate === true
|
|
122
|
-
? LlmApplicationProgrammer.validate({
|
|
123
|
-
model,
|
|
124
|
-
config,
|
|
125
|
-
})
|
|
126
|
-
: undefined,
|
|
127
|
-
},
|
|
128
|
-
collection: new MetadataCollection({
|
|
129
|
-
replace: MetadataCollection.replace,
|
|
130
|
-
}),
|
|
131
|
-
type,
|
|
132
|
-
});
|
|
133
|
-
if (result.success === false)
|
|
134
|
-
throw TransformerError.from({
|
|
135
|
-
code: `typia.llm.${method}`,
|
|
136
|
-
errors: result.errors,
|
|
137
|
-
});
|
|
138
|
-
return result.data;
|
|
139
|
-
};
|
|
140
|
-
analyze(true);
|
|
141
|
-
|
|
142
|
-
// GENERATE LLM APPLICATION
|
|
143
|
-
return {
|
|
144
|
-
application: LlmApplicationProgrammer.write({
|
|
145
|
-
model,
|
|
146
|
-
context: props.context,
|
|
147
|
-
modulo: props.modulo,
|
|
148
|
-
metadata: analyze(false),
|
|
149
|
-
config,
|
|
150
|
-
name: top.getFullText().trim(),
|
|
151
|
-
}),
|
|
152
|
-
node: top,
|
|
153
|
-
type,
|
|
154
|
-
config,
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
export const finalize = (props: {
|
|
159
|
-
context: ITypiaContext;
|
|
160
|
-
value: ts.Expression;
|
|
161
|
-
argument: ts.Expression;
|
|
162
|
-
equals?: boolean;
|
|
163
|
-
model: ILlmSchema.Model;
|
|
164
|
-
}) => {
|
|
165
|
-
const satisfiesTypeNode: ts.TypeNode = ts.factory.createTypeReferenceNode(
|
|
166
|
-
ts.factory.createIdentifier("Partial"),
|
|
167
|
-
[
|
|
168
|
-
ts.factory.createTypeReferenceNode(
|
|
169
|
-
ts.factory.createIdentifier("Pick"),
|
|
170
|
-
[
|
|
171
|
-
ts.factory.createImportTypeNode(
|
|
172
|
-
ts.factory.createLiteralTypeNode(
|
|
173
|
-
ts.factory.createStringLiteral("@samchon/openapi"),
|
|
174
|
-
),
|
|
175
|
-
undefined,
|
|
176
|
-
ts.factory.createQualifiedName(
|
|
177
|
-
ts.factory.createIdentifier("ILlmApplication"),
|
|
178
|
-
ts.factory.createIdentifier("IOptions"),
|
|
179
|
-
),
|
|
180
|
-
[
|
|
181
|
-
ts.factory.createLiteralTypeNode(
|
|
182
|
-
ts.factory.createStringLiteral(props.model),
|
|
183
|
-
),
|
|
184
|
-
],
|
|
185
|
-
false,
|
|
186
|
-
),
|
|
187
|
-
ts.factory.createUnionTypeNode([
|
|
188
|
-
ts.factory.createLiteralTypeNode(
|
|
189
|
-
ts.factory.createStringLiteral("separate"),
|
|
190
|
-
),
|
|
191
|
-
ts.factory.createLiteralTypeNode(
|
|
192
|
-
ts.factory.createStringLiteral("validate"),
|
|
193
|
-
),
|
|
194
|
-
]),
|
|
195
|
-
],
|
|
196
|
-
),
|
|
197
|
-
],
|
|
198
|
-
);
|
|
199
|
-
return ts.factory.createCallExpression(
|
|
200
|
-
props.context.importer.internal("llmApplicationFinalize"),
|
|
201
|
-
undefined,
|
|
202
|
-
[
|
|
203
|
-
props.value,
|
|
204
|
-
ts.factory.createObjectLiteralExpression(
|
|
205
|
-
[
|
|
206
|
-
ts.factory.createSpreadAssignment(
|
|
207
|
-
ts.factory.createSatisfiesExpression(
|
|
208
|
-
props.argument,
|
|
209
|
-
satisfiesTypeNode,
|
|
210
|
-
),
|
|
211
|
-
),
|
|
212
|
-
ts.factory.createPropertyAssignment(
|
|
213
|
-
"equals",
|
|
214
|
-
props.equals === true
|
|
215
|
-
? ts.factory.createTrue()
|
|
216
|
-
: ts.factory.createFalse(),
|
|
217
|
-
),
|
|
218
|
-
],
|
|
219
|
-
true,
|
|
220
|
-
),
|
|
221
|
-
],
|
|
222
|
-
);
|
|
223
|
-
};
|
|
224
|
-
}
|
|
1
|
+
import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { ExpressionFactory } from "../../../factories/ExpressionFactory";
|
|
5
|
+
import { LiteralFactory } from "../../../factories/LiteralFactory";
|
|
6
|
+
import { MetadataCollection } from "../../../factories/MetadataCollection";
|
|
7
|
+
import { MetadataFactory } from "../../../factories/MetadataFactory";
|
|
8
|
+
import { StatementFactory } from "../../../factories/StatementFactory";
|
|
9
|
+
|
|
10
|
+
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
11
|
+
|
|
12
|
+
import { LlmApplicationProgrammer } from "../../../programmers/llm/LlmApplicationProgrammer";
|
|
13
|
+
import { LlmModelPredicator } from "../../../programmers/llm/LlmModelPredicator";
|
|
14
|
+
|
|
15
|
+
import { ValidationPipe } from "../../../typings/ValidationPipe";
|
|
16
|
+
|
|
17
|
+
import { ITransformProps } from "../../ITransformProps";
|
|
18
|
+
import { ITypiaContext } from "../../ITypiaContext";
|
|
19
|
+
import { TransformerError } from "../../TransformerError";
|
|
20
|
+
|
|
21
|
+
export namespace LlmApplicationTransformer {
|
|
22
|
+
export const transform = (props: ITransformProps): ts.Expression => {
|
|
23
|
+
const dec = decompose("application", props);
|
|
24
|
+
if (dec === null) return props.expression;
|
|
25
|
+
|
|
26
|
+
const literal: ts.Expression = ts.factory.createAsExpression(
|
|
27
|
+
LiteralFactory.write(dec.application),
|
|
28
|
+
props.context.importer.type({
|
|
29
|
+
file: "@samchon/openapi",
|
|
30
|
+
name: "ILlmApplication",
|
|
31
|
+
arguments: [
|
|
32
|
+
ts.factory.createLiteralTypeNode(
|
|
33
|
+
ts.factory.createStringLiteral(dec.application.model),
|
|
34
|
+
),
|
|
35
|
+
],
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
if (!props.expression.arguments?.[0]) return literal;
|
|
39
|
+
return ExpressionFactory.selfCall(
|
|
40
|
+
ts.factory.createBlock(
|
|
41
|
+
[
|
|
42
|
+
StatementFactory.constant({
|
|
43
|
+
name: "application",
|
|
44
|
+
value: literal,
|
|
45
|
+
}),
|
|
46
|
+
ts.factory.createExpressionStatement(
|
|
47
|
+
finalize({
|
|
48
|
+
context: props.context,
|
|
49
|
+
value: ts.factory.createIdentifier("application"),
|
|
50
|
+
argument: props.expression.arguments[0]!,
|
|
51
|
+
equals: dec.config?.equals,
|
|
52
|
+
model: dec.application.model,
|
|
53
|
+
}),
|
|
54
|
+
),
|
|
55
|
+
ts.factory.createReturnStatement(
|
|
56
|
+
ts.factory.createIdentifier("application"),
|
|
57
|
+
),
|
|
58
|
+
],
|
|
59
|
+
true,
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** @internal */
|
|
65
|
+
export const decompose = (
|
|
66
|
+
method: string,
|
|
67
|
+
props: ITransformProps,
|
|
68
|
+
): {
|
|
69
|
+
application: ILlmApplication<ILlmSchema.Model>;
|
|
70
|
+
type: ts.Type;
|
|
71
|
+
node: ts.TypeNode;
|
|
72
|
+
config:
|
|
73
|
+
| Partial<
|
|
74
|
+
ILlmSchema.IConfig & {
|
|
75
|
+
equals: boolean;
|
|
76
|
+
}
|
|
77
|
+
>
|
|
78
|
+
| undefined;
|
|
79
|
+
} | null => {
|
|
80
|
+
// GET GENERIC ARGUMENT
|
|
81
|
+
if (!props.expression.typeArguments?.length)
|
|
82
|
+
throw new TransformerError({
|
|
83
|
+
code: `typia.llm.${method}`,
|
|
84
|
+
message: "no generic argument.",
|
|
85
|
+
});
|
|
86
|
+
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
87
|
+
if (ts.isTypeNode(top) === false) return null;
|
|
88
|
+
|
|
89
|
+
// GET TYPE
|
|
90
|
+
const model: ILlmSchema.Model = LlmModelPredicator.getModel({
|
|
91
|
+
checker: props.context.checker,
|
|
92
|
+
method,
|
|
93
|
+
node: props.expression.typeArguments[1],
|
|
94
|
+
});
|
|
95
|
+
const config:
|
|
96
|
+
| Partial<
|
|
97
|
+
ILlmSchema.IConfig & {
|
|
98
|
+
equals: boolean;
|
|
99
|
+
}
|
|
100
|
+
>
|
|
101
|
+
| undefined = LlmModelPredicator.getConfig({
|
|
102
|
+
context: props.context,
|
|
103
|
+
method,
|
|
104
|
+
model,
|
|
105
|
+
node: props.expression.typeArguments[2],
|
|
106
|
+
});
|
|
107
|
+
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
108
|
+
|
|
109
|
+
// VALIDATE TYPE
|
|
110
|
+
const analyze = (validate: boolean): Metadata => {
|
|
111
|
+
const result: ValidationPipe<Metadata, MetadataFactory.IError> =
|
|
112
|
+
MetadataFactory.analyze({
|
|
113
|
+
checker: props.context.checker,
|
|
114
|
+
transformer: props.context.transformer,
|
|
115
|
+
options: {
|
|
116
|
+
absorb: validate,
|
|
117
|
+
escape: true,
|
|
118
|
+
constant: true,
|
|
119
|
+
functional: true,
|
|
120
|
+
validate:
|
|
121
|
+
validate === true
|
|
122
|
+
? LlmApplicationProgrammer.validate({
|
|
123
|
+
model,
|
|
124
|
+
config,
|
|
125
|
+
})
|
|
126
|
+
: undefined,
|
|
127
|
+
},
|
|
128
|
+
collection: new MetadataCollection({
|
|
129
|
+
replace: MetadataCollection.replace,
|
|
130
|
+
}),
|
|
131
|
+
type,
|
|
132
|
+
});
|
|
133
|
+
if (result.success === false)
|
|
134
|
+
throw TransformerError.from({
|
|
135
|
+
code: `typia.llm.${method}`,
|
|
136
|
+
errors: result.errors,
|
|
137
|
+
});
|
|
138
|
+
return result.data;
|
|
139
|
+
};
|
|
140
|
+
analyze(true);
|
|
141
|
+
|
|
142
|
+
// GENERATE LLM APPLICATION
|
|
143
|
+
return {
|
|
144
|
+
application: LlmApplicationProgrammer.write({
|
|
145
|
+
model,
|
|
146
|
+
context: props.context,
|
|
147
|
+
modulo: props.modulo,
|
|
148
|
+
metadata: analyze(false),
|
|
149
|
+
config,
|
|
150
|
+
name: top.getFullText().trim(),
|
|
151
|
+
}),
|
|
152
|
+
node: top,
|
|
153
|
+
type,
|
|
154
|
+
config,
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export const finalize = (props: {
|
|
159
|
+
context: ITypiaContext;
|
|
160
|
+
value: ts.Expression;
|
|
161
|
+
argument: ts.Expression;
|
|
162
|
+
equals?: boolean;
|
|
163
|
+
model: ILlmSchema.Model;
|
|
164
|
+
}) => {
|
|
165
|
+
const satisfiesTypeNode: ts.TypeNode = ts.factory.createTypeReferenceNode(
|
|
166
|
+
ts.factory.createIdentifier("Partial"),
|
|
167
|
+
[
|
|
168
|
+
ts.factory.createTypeReferenceNode(
|
|
169
|
+
ts.factory.createIdentifier("Pick"),
|
|
170
|
+
[
|
|
171
|
+
ts.factory.createImportTypeNode(
|
|
172
|
+
ts.factory.createLiteralTypeNode(
|
|
173
|
+
ts.factory.createStringLiteral("@samchon/openapi"),
|
|
174
|
+
),
|
|
175
|
+
undefined,
|
|
176
|
+
ts.factory.createQualifiedName(
|
|
177
|
+
ts.factory.createIdentifier("ILlmApplication"),
|
|
178
|
+
ts.factory.createIdentifier("IOptions"),
|
|
179
|
+
),
|
|
180
|
+
[
|
|
181
|
+
ts.factory.createLiteralTypeNode(
|
|
182
|
+
ts.factory.createStringLiteral(props.model),
|
|
183
|
+
),
|
|
184
|
+
],
|
|
185
|
+
false,
|
|
186
|
+
),
|
|
187
|
+
ts.factory.createUnionTypeNode([
|
|
188
|
+
ts.factory.createLiteralTypeNode(
|
|
189
|
+
ts.factory.createStringLiteral("separate"),
|
|
190
|
+
),
|
|
191
|
+
ts.factory.createLiteralTypeNode(
|
|
192
|
+
ts.factory.createStringLiteral("validate"),
|
|
193
|
+
),
|
|
194
|
+
]),
|
|
195
|
+
],
|
|
196
|
+
),
|
|
197
|
+
],
|
|
198
|
+
);
|
|
199
|
+
return ts.factory.createCallExpression(
|
|
200
|
+
props.context.importer.internal("llmApplicationFinalize"),
|
|
201
|
+
undefined,
|
|
202
|
+
[
|
|
203
|
+
props.value,
|
|
204
|
+
ts.factory.createObjectLiteralExpression(
|
|
205
|
+
[
|
|
206
|
+
ts.factory.createSpreadAssignment(
|
|
207
|
+
ts.factory.createSatisfiesExpression(
|
|
208
|
+
props.argument,
|
|
209
|
+
satisfiesTypeNode,
|
|
210
|
+
),
|
|
211
|
+
),
|
|
212
|
+
ts.factory.createPropertyAssignment(
|
|
213
|
+
"equals",
|
|
214
|
+
props.equals === true
|
|
215
|
+
? ts.factory.createTrue()
|
|
216
|
+
: ts.factory.createFalse(),
|
|
217
|
+
),
|
|
218
|
+
],
|
|
219
|
+
true,
|
|
220
|
+
),
|
|
221
|
+
],
|
|
222
|
+
);
|
|
223
|
+
};
|
|
224
|
+
}
|
package/src/typings/Equal.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compare the equivalence of the two types X and Y.
|
|
3
|
-
*
|
|
4
|
-
* The two types X and Y refer to any type that can be expressed in the
|
|
5
|
-
* TypeScript, such as the union type and the object type.
|
|
6
|
-
*
|
|
7
|
-
* @author Kyungsu Kang - https://github.com/kakasoo
|
|
8
|
-
* @template X One of the types to compare
|
|
9
|
-
* @template Y One of the types to compare
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* type Answer = Equal<1 | 2, 1 | 2>; // true
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export type Equal<X, Y> =
|
|
16
|
-
(<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
|
|
17
|
-
? true
|
|
18
|
-
: false;
|
|
1
|
+
/**
|
|
2
|
+
* Compare the equivalence of the two types X and Y.
|
|
3
|
+
*
|
|
4
|
+
* The two types X and Y refer to any type that can be expressed in the
|
|
5
|
+
* TypeScript, such as the union type and the object type.
|
|
6
|
+
*
|
|
7
|
+
* @author Kyungsu Kang - https://github.com/kakasoo
|
|
8
|
+
* @template X One of the types to compare
|
|
9
|
+
* @template Y One of the types to compare
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* type Answer = Equal<1 | 2, 1 | 2>; // true
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type Equal<X, Y> =
|
|
16
|
+
(<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
|
|
17
|
+
? true
|
|
18
|
+
: false;
|