typia 7.0.0-dev.20241009-2 → 7.0.0-dev.20241010
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/lib/factories/JsonMetadataFactory.d.ts +5 -1
- package/lib/factories/JsonMetadataFactory.js +4 -1
- package/lib/factories/JsonMetadataFactory.js.map +1 -1
- package/lib/internal/{$httpFormDataReadArray.js → $httpFormdataReadArray.js} +1 -1
- package/lib/internal/$httpFormdataReadArray.js.map +1 -0
- package/lib/programmers/CheckerProgrammer.js +4 -1
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/FeatureProgrammer.d.ts +4 -1
- package/lib/programmers/FeatureProgrammer.js +2 -2
- package/lib/programmers/FeatureProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +12 -9
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/TypiaProgrammer.js +4 -1
- package/lib/programmers/TypiaProgrammer.js.map +1 -1
- package/lib/programmers/internal/prune_object_properties.js +3 -2
- package/lib/programmers/internal/prune_object_properties.js.map +1 -1
- package/lib/programmers/json/JsonAssertParseProgrammer.js +2 -2
- package/lib/programmers/json/JsonAssertParseProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +4 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js +4 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +4 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
- package/lib/transformers/FileTransformer.js +0 -6
- package/lib/transformers/FileTransformer.js.map +1 -1
- package/lib/transformers/ImportTransformer.d.ts +4 -1
- package/lib/transformers/ImportTransformer.js +34 -30
- package/lib/transformers/ImportTransformer.js.map +1 -1
- package/package.json +1 -1
- package/src/IRandomGenerator.ts +49 -49
- package/src/factories/ExpressionFactory.ts +164 -164
- package/src/factories/JsonMetadataFactory.ts +25 -15
- package/src/factories/LiteralFactory.ts +50 -50
- package/src/factories/MetadataCommentTagFactory.ts +650 -650
- package/src/functional.ts +750 -750
- package/src/http.ts +1042 -1042
- package/src/internal/$IProtobufWriter.ts +18 -18
- package/src/internal/$ProtobufReader.ts +194 -194
- package/src/internal/$ProtobufSizer.ts +151 -151
- package/src/internal/$ProtobufWriter.ts +145 -145
- package/src/internal/$accessExpressionAsString.ts +46 -46
- package/src/internal/$assertGuard.ts +13 -13
- package/src/internal/$functionalTypeGuardErrorFactory.ts +4 -4
- package/src/internal/$httpFormDataReadBigint.ts +18 -18
- package/src/internal/$httpFormDataReadBlob.ts +10 -10
- package/src/internal/$httpFormDataReadBoolean.ts +16 -16
- package/src/internal/$httpFormDataReadFile.ts +10 -10
- package/src/internal/$httpFormDataReadNumber.ts +15 -15
- package/src/internal/$httpFormDataReadString.ts +10 -10
- package/src/internal/{$httpFormDataReadArray.ts → $httpFormdataReadArray.ts} +4 -4
- package/src/internal/$httpHeaderReadBigint.ts +10 -10
- package/src/internal/$httpHeaderReadBoolean.ts +8 -8
- package/src/internal/$httpHeaderReadNumber.ts +7 -7
- package/src/internal/$httpParameterBigint.ts +10 -10
- package/src/internal/$httpParameterBoolean.ts +8 -8
- package/src/internal/$httpParameterNumber.ts +7 -7
- package/src/internal/$httpParameterString.ts +2 -2
- package/src/internal/$httpQueryParseURLSearchParams.ts +10 -10
- package/src/internal/$httpQueryReadArray.ts +4 -4
- package/src/internal/$httpQueryReadBigint.ts +12 -12
- package/src/internal/$httpQueryReadBoolean.ts +14 -14
- package/src/internal/$httpQueryReadNumber.ts +9 -9
- package/src/internal/$httpQueryReadString.ts +4 -4
- package/src/internal/$isBetween.ts +2 -2
- package/src/internal/$isBigintString.ts +8 -8
- package/src/internal/$jsonStringifyNumber.ts +12 -12
- package/src/internal/$jsonStringifyRest.ts +3 -3
- package/src/internal/$jsonStringifyString.ts +42 -42
- package/src/internal/$jsonStringifyTail.ts +2 -2
- package/src/internal/$llmApplicationFinalize.ts +18 -18
- package/src/internal/$miscCloneAny.ts +48 -48
- package/src/internal/$notationAny.ts +37 -37
- package/src/internal/$notationCamel.ts +13 -13
- package/src/internal/$notationPascal.ts +8 -8
- package/src/internal/$notationSnake.ts +43 -43
- package/src/internal/$randomArray.ts +21 -21
- package/src/internal/$randomBigint.ts +6 -6
- package/src/internal/$randomBoolean.ts +1 -1
- package/src/internal/$randomFormatByte.ts +3 -3
- package/src/internal/$randomFormatDate.ts +18 -18
- package/src/internal/$randomFormatDatetime.ts +16 -16
- package/src/internal/$randomFormatDuration.ts +27 -27
- package/src/internal/$randomFormatEmail.ts +11 -11
- package/src/internal/$randomFormatHostname.ts +6 -6
- package/src/internal/$randomFormatIdnEmail.ts +3 -3
- package/src/internal/$randomFormatIdnHostname.ts +3 -3
- package/src/internal/$randomFormatIpv4.ts +11 -11
- package/src/internal/$randomFormatIpv6.ts +11 -11
- package/src/internal/$randomFormatIri.ts +3 -3
- package/src/internal/$randomFormatIriReference.ts +3 -3
- package/src/internal/$randomFormatJsonPointer.ts +7 -7
- package/src/internal/$randomFormatPassword.ts +8 -8
- package/src/internal/$randomFormatRegex.ts +4 -4
- package/src/internal/$randomFormatRelativeJsonPointer.ts +8 -8
- package/src/internal/$randomFormatTime.ts +14 -14
- package/src/internal/$randomFormatUri.ts +3 -3
- package/src/internal/$randomFormatUriReference.ts +3 -3
- package/src/internal/$randomFormatUriTemplate.ts +3 -3
- package/src/internal/$randomFormatUrl.ts +11 -11
- package/src/internal/$randomFormatUuid.ts +6 -6
- package/src/internal/$randomInteger.ts +47 -47
- package/src/internal/$randomNumber.ts +74 -74
- package/src/internal/$randomPattern.ts +10 -10
- package/src/internal/$randomPick.ts +9 -9
- package/src/internal/$randomString.ts +24 -24
- package/src/internal/$throwTypeGuardError.ts +5 -5
- package/src/internal/$validateReport.ts +13 -13
- package/src/internal/private/$__notationCapitalize.ts +2 -2
- package/src/internal/private/$__notationUnsnake.ts +24 -24
- package/src/json.ts +651 -651
- package/src/llm.ts +178 -178
- package/src/misc.ts +658 -658
- package/src/module.ts +933 -933
- package/src/notations.ts +827 -827
- package/src/programmers/CheckerProgrammer.ts +4 -1
- package/src/programmers/FeatureProgrammer.ts +619 -616
- package/src/programmers/RandomProgrammer.ts +24 -16
- package/src/programmers/TypiaProgrammer.ts +4 -1
- package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +153 -153
- package/src/programmers/functional/FunctionalAssertParametersProgrammer.ts +125 -125
- package/src/programmers/functional/FunctionalAssertReturnProgrammer.ts +115 -115
- package/src/programmers/functional/FunctionalValidateFunctionProgrammer.ts +119 -119
- package/src/programmers/functional/FunctionalValidateParametersProgrammer.ts +274 -274
- package/src/programmers/functional/FunctionalValidateReturnProgrammer.ts +135 -135
- package/src/programmers/helpers/FunctionProgrammer.ts +67 -67
- package/src/programmers/helpers/RandomJoiner.ts +168 -168
- package/src/programmers/helpers/StringifyJoinder.ts +115 -115
- package/src/programmers/helpers/disable_function_programmer_declare.ts +32 -32
- package/src/programmers/internal/check_dynamic_key.ts +201 -201
- package/src/programmers/internal/check_dynamic_properties.ts +208 -208
- package/src/programmers/internal/check_object.ts +75 -75
- package/src/programmers/internal/feature_object_entries.ts +61 -61
- package/src/programmers/internal/prune_object_properties.ts +71 -63
- package/src/programmers/json/JsonAssertParseProgrammer.ts +14 -11
- package/src/programmers/llm/LlmApplicationProgrammer.ts +235 -235
- package/src/programmers/llm/LlmSchemaProgrammer.ts +51 -51
- package/src/programmers/misc/MiscCloneProgrammer.ts +4 -1
- package/src/programmers/misc/MiscPruneProgrammer.ts +4 -1
- package/src/programmers/notations/NotationGeneralProgrammer.ts +4 -1
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +1 -1
- package/src/protobuf.ts +868 -868
- package/src/reflect.ts +57 -57
- package/src/transformers/FileTransformer.ts +0 -6
- package/src/transformers/ImportTransformer.ts +59 -44
- package/src/utils/NamingConvention.ts +94 -94
- package/src/utils/StringUtil.ts +16 -16
- package/lib/internal/$httpFormDataReadArray.js.map +0 -1
- /package/lib/internal/{$httpFormDataReadArray.d.ts → $httpFormdataReadArray.d.ts} +0 -0
|
@@ -1,235 +1,235 @@
|
|
|
1
|
-
import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
import { ILlmFunction } from "@samchon/openapi/lib/structures/ILlmFunction";
|
|
3
|
-
|
|
4
|
-
import { MetadataFactory } from "../../factories/MetadataFactory";
|
|
5
|
-
|
|
6
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
7
|
-
import { MetadataFunction } from "../../schemas/metadata/MetadataFunction";
|
|
8
|
-
import { MetadataObject } from "../../schemas/metadata/MetadataObject";
|
|
9
|
-
|
|
10
|
-
import { IJsDocTagInfo } from "../../module";
|
|
11
|
-
import { LlmSchemaProgrammer } from "./LlmSchemaProgrammer";
|
|
12
|
-
|
|
13
|
-
export namespace LlmApplicationProgrammer {
|
|
14
|
-
export const validate = (
|
|
15
|
-
metadata: Metadata,
|
|
16
|
-
explore: MetadataFactory.IExplore,
|
|
17
|
-
): string[] => {
|
|
18
|
-
if (explore.top === false) return LlmSchemaProgrammer.validate(metadata);
|
|
19
|
-
|
|
20
|
-
const output: string[] = [];
|
|
21
|
-
const valid: boolean =
|
|
22
|
-
metadata.size() === 1 &&
|
|
23
|
-
metadata.objects.length === 1 &&
|
|
24
|
-
metadata.isRequired() === true &&
|
|
25
|
-
metadata.nullable === false;
|
|
26
|
-
if (valid === false)
|
|
27
|
-
output.push(
|
|
28
|
-
"LLM application's generic arugment must be a class/interface type.",
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
const object: MetadataObject | undefined = metadata.objects[0];
|
|
32
|
-
if (object !== undefined) {
|
|
33
|
-
if (object.properties.some((p) => p.key.isSoleLiteral() === false))
|
|
34
|
-
output.push("LLM application does not allow dynamic keys.");
|
|
35
|
-
let least: boolean = false;
|
|
36
|
-
for (const p of object.properties) {
|
|
37
|
-
const value: Metadata = p.value;
|
|
38
|
-
if (value.functions.length) {
|
|
39
|
-
least ||= true;
|
|
40
|
-
if (valid === false) {
|
|
41
|
-
if (value.functions.length !== 1 || value.size() !== 1)
|
|
42
|
-
output.push(
|
|
43
|
-
"LLM application's function type does not allow union type.",
|
|
44
|
-
);
|
|
45
|
-
if (value.isRequired() === false)
|
|
46
|
-
output.push("LLM application's function type must be required.");
|
|
47
|
-
if (value.nullable === true)
|
|
48
|
-
output.push(
|
|
49
|
-
"LLM application's function type must not be nullable.",
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (least === false)
|
|
55
|
-
output.push(
|
|
56
|
-
"LLM application's target type must have at least a function type.",
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
return output;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export const write = (metadata: Metadata): ILlmApplication => {
|
|
63
|
-
const errors: string[] = validate(metadata, {
|
|
64
|
-
top: true,
|
|
65
|
-
object: null,
|
|
66
|
-
property: null,
|
|
67
|
-
parameter: null,
|
|
68
|
-
nested: null,
|
|
69
|
-
aliased: false,
|
|
70
|
-
escaped: false,
|
|
71
|
-
output: false,
|
|
72
|
-
});
|
|
73
|
-
if (errors.length)
|
|
74
|
-
throw new Error("Failed to write LLM application: " + errors.join("\n"));
|
|
75
|
-
|
|
76
|
-
const object: MetadataObject = metadata.objects[0]!;
|
|
77
|
-
return {
|
|
78
|
-
functions: object.properties
|
|
79
|
-
.filter(
|
|
80
|
-
(p) =>
|
|
81
|
-
p.value.functions.length === 1 &&
|
|
82
|
-
p.value.size() === 1 &&
|
|
83
|
-
p.key.isSoleLiteral(),
|
|
84
|
-
)
|
|
85
|
-
.filter(
|
|
86
|
-
(p) => p.jsDocTags.find((tag) => tag.name === "hidden") === undefined,
|
|
87
|
-
)
|
|
88
|
-
.map((p) =>
|
|
89
|
-
writeFunction({
|
|
90
|
-
name: p.key.getSoleLiteral()!,
|
|
91
|
-
function: p.value.functions[0]!,
|
|
92
|
-
description: p.description,
|
|
93
|
-
jsDocTags: p.jsDocTags,
|
|
94
|
-
}),
|
|
95
|
-
),
|
|
96
|
-
options: {
|
|
97
|
-
separate: null,
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const writeFunction = (props: {
|
|
103
|
-
name: string;
|
|
104
|
-
function: MetadataFunction;
|
|
105
|
-
description: string | null;
|
|
106
|
-
jsDocTags: IJsDocTagInfo[];
|
|
107
|
-
}): ILlmFunction => {
|
|
108
|
-
const deprecated: boolean = props.jsDocTags.some(
|
|
109
|
-
(tag) => tag.name === "deprecated",
|
|
110
|
-
);
|
|
111
|
-
const tags: string[] = props.jsDocTags
|
|
112
|
-
.map((tag) =>
|
|
113
|
-
tag.name === "tag"
|
|
114
|
-
? (tag.text?.filter((elem) => elem.kind === "text") ?? [])
|
|
115
|
-
: [],
|
|
116
|
-
)
|
|
117
|
-
.flat()
|
|
118
|
-
.map((elem) => elem.text)
|
|
119
|
-
.map((str) => str.trim().split(" ")[0] ?? "")
|
|
120
|
-
.filter((str) => !!str.length);
|
|
121
|
-
return {
|
|
122
|
-
name: props.name,
|
|
123
|
-
parameters: props.function.parameters.map((p) => {
|
|
124
|
-
const jsDocTagDescription: string | null = writeDescriptionFromJsDocTag(
|
|
125
|
-
{
|
|
126
|
-
jsDocTags: p.jsDocTags,
|
|
127
|
-
name: "param",
|
|
128
|
-
parameter: p.name,
|
|
129
|
-
},
|
|
130
|
-
);
|
|
131
|
-
return writeSchema({
|
|
132
|
-
metadata: p.type,
|
|
133
|
-
description: jsDocTagDescription ?? p.description,
|
|
134
|
-
jsDocTags: jsDocTagDescription ? [] : p.jsDocTags,
|
|
135
|
-
});
|
|
136
|
-
}),
|
|
137
|
-
output:
|
|
138
|
-
props.function.output.size() || props.function.output.nullable
|
|
139
|
-
? writeSchema({
|
|
140
|
-
metadata: props.function.output,
|
|
141
|
-
description:
|
|
142
|
-
writeDescriptionFromJsDocTag({
|
|
143
|
-
jsDocTags: props.jsDocTags,
|
|
144
|
-
name: "return",
|
|
145
|
-
}) ??
|
|
146
|
-
writeDescriptionFromJsDocTag({
|
|
147
|
-
jsDocTags: props.jsDocTags,
|
|
148
|
-
name: "returns",
|
|
149
|
-
}),
|
|
150
|
-
jsDocTags: [],
|
|
151
|
-
})
|
|
152
|
-
: undefined,
|
|
153
|
-
description: props.description ?? undefined,
|
|
154
|
-
deprecated: deprecated || undefined,
|
|
155
|
-
tags: tags.length ? tags : undefined,
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
const writeSchema = (props: {
|
|
160
|
-
metadata: Metadata;
|
|
161
|
-
description: string | null;
|
|
162
|
-
jsDocTags: IJsDocTagInfo[];
|
|
163
|
-
}): ILlmSchema => {
|
|
164
|
-
const schema: ILlmSchema = LlmSchemaProgrammer.write(props.metadata);
|
|
165
|
-
const explicit: Pick<ILlmSchema, "title" | "description"> =
|
|
166
|
-
writeDescription({
|
|
167
|
-
description: props.description,
|
|
168
|
-
jsDocTags: props.jsDocTags,
|
|
169
|
-
});
|
|
170
|
-
return {
|
|
171
|
-
...schema,
|
|
172
|
-
...(!!explicit.title?.length || !!explicit.description?.length
|
|
173
|
-
? explicit
|
|
174
|
-
: {}),
|
|
175
|
-
};
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
const writeDescription = (props: {
|
|
179
|
-
description: string | null;
|
|
180
|
-
jsDocTags: IJsDocTagInfo[];
|
|
181
|
-
}): Pick<ILlmSchema, "title" | "description"> => {
|
|
182
|
-
const title: string | undefined = (() => {
|
|
183
|
-
const [explicit] = getJsDocTexts({
|
|
184
|
-
jsDocTags: props.jsDocTags,
|
|
185
|
-
name: "title",
|
|
186
|
-
});
|
|
187
|
-
if (explicit?.length) return explicit;
|
|
188
|
-
else if (!props.description?.length) return undefined;
|
|
189
|
-
|
|
190
|
-
const index: number = props.description.indexOf("\n");
|
|
191
|
-
const top: string = (
|
|
192
|
-
index === -1 ? props.description : props.description.substring(0, index)
|
|
193
|
-
).trim();
|
|
194
|
-
return top.endsWith(".") ? top.substring(0, top.length - 1) : undefined;
|
|
195
|
-
})();
|
|
196
|
-
return {
|
|
197
|
-
title: title,
|
|
198
|
-
description: props.description?.length ? props.description : undefined,
|
|
199
|
-
} as any;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
const writeDescriptionFromJsDocTag = (props: {
|
|
203
|
-
jsDocTags: IJsDocTagInfo[];
|
|
204
|
-
name: string;
|
|
205
|
-
parameter?: string;
|
|
206
|
-
}): string | null => {
|
|
207
|
-
const parametric: (elem: IJsDocTagInfo) => boolean = props.parameter
|
|
208
|
-
? (tag) =>
|
|
209
|
-
tag.text!.find(
|
|
210
|
-
(elem) =>
|
|
211
|
-
elem.kind === "parameterName" && elem.text === props.parameter,
|
|
212
|
-
) !== undefined
|
|
213
|
-
: () => true;
|
|
214
|
-
const tag: IJsDocTagInfo | undefined = props.jsDocTags.find(
|
|
215
|
-
(tag) => tag.name === props.name && tag.text && parametric(tag),
|
|
216
|
-
);
|
|
217
|
-
return tag && tag.text
|
|
218
|
-
? (tag.text.find((elem) => elem.kind === "text")?.text ?? null)
|
|
219
|
-
: null;
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
const getJsDocTexts = (props: {
|
|
223
|
-
jsDocTags: IJsDocTagInfo[];
|
|
224
|
-
name: string;
|
|
225
|
-
}): string[] =>
|
|
226
|
-
props.jsDocTags
|
|
227
|
-
.filter(
|
|
228
|
-
(tag) =>
|
|
229
|
-
tag.name === props.name &&
|
|
230
|
-
tag.text &&
|
|
231
|
-
tag.text.find((elem) => elem.kind === "text" && elem.text.length) !==
|
|
232
|
-
undefined,
|
|
233
|
-
)
|
|
234
|
-
.map((tag) => tag.text!.find((elem) => elem.kind === "text")!.text);
|
|
235
|
-
}
|
|
1
|
+
import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
import { ILlmFunction } from "@samchon/openapi/lib/structures/ILlmFunction";
|
|
3
|
+
|
|
4
|
+
import { MetadataFactory } from "../../factories/MetadataFactory";
|
|
5
|
+
|
|
6
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
7
|
+
import { MetadataFunction } from "../../schemas/metadata/MetadataFunction";
|
|
8
|
+
import { MetadataObject } from "../../schemas/metadata/MetadataObject";
|
|
9
|
+
|
|
10
|
+
import { IJsDocTagInfo } from "../../module";
|
|
11
|
+
import { LlmSchemaProgrammer } from "./LlmSchemaProgrammer";
|
|
12
|
+
|
|
13
|
+
export namespace LlmApplicationProgrammer {
|
|
14
|
+
export const validate = (
|
|
15
|
+
metadata: Metadata,
|
|
16
|
+
explore: MetadataFactory.IExplore,
|
|
17
|
+
): string[] => {
|
|
18
|
+
if (explore.top === false) return LlmSchemaProgrammer.validate(metadata);
|
|
19
|
+
|
|
20
|
+
const output: string[] = [];
|
|
21
|
+
const valid: boolean =
|
|
22
|
+
metadata.size() === 1 &&
|
|
23
|
+
metadata.objects.length === 1 &&
|
|
24
|
+
metadata.isRequired() === true &&
|
|
25
|
+
metadata.nullable === false;
|
|
26
|
+
if (valid === false)
|
|
27
|
+
output.push(
|
|
28
|
+
"LLM application's generic arugment must be a class/interface type.",
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const object: MetadataObject | undefined = metadata.objects[0];
|
|
32
|
+
if (object !== undefined) {
|
|
33
|
+
if (object.properties.some((p) => p.key.isSoleLiteral() === false))
|
|
34
|
+
output.push("LLM application does not allow dynamic keys.");
|
|
35
|
+
let least: boolean = false;
|
|
36
|
+
for (const p of object.properties) {
|
|
37
|
+
const value: Metadata = p.value;
|
|
38
|
+
if (value.functions.length) {
|
|
39
|
+
least ||= true;
|
|
40
|
+
if (valid === false) {
|
|
41
|
+
if (value.functions.length !== 1 || value.size() !== 1)
|
|
42
|
+
output.push(
|
|
43
|
+
"LLM application's function type does not allow union type.",
|
|
44
|
+
);
|
|
45
|
+
if (value.isRequired() === false)
|
|
46
|
+
output.push("LLM application's function type must be required.");
|
|
47
|
+
if (value.nullable === true)
|
|
48
|
+
output.push(
|
|
49
|
+
"LLM application's function type must not be nullable.",
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (least === false)
|
|
55
|
+
output.push(
|
|
56
|
+
"LLM application's target type must have at least a function type.",
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return output;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const write = (metadata: Metadata): ILlmApplication => {
|
|
63
|
+
const errors: string[] = validate(metadata, {
|
|
64
|
+
top: true,
|
|
65
|
+
object: null,
|
|
66
|
+
property: null,
|
|
67
|
+
parameter: null,
|
|
68
|
+
nested: null,
|
|
69
|
+
aliased: false,
|
|
70
|
+
escaped: false,
|
|
71
|
+
output: false,
|
|
72
|
+
});
|
|
73
|
+
if (errors.length)
|
|
74
|
+
throw new Error("Failed to write LLM application: " + errors.join("\n"));
|
|
75
|
+
|
|
76
|
+
const object: MetadataObject = metadata.objects[0]!;
|
|
77
|
+
return {
|
|
78
|
+
functions: object.properties
|
|
79
|
+
.filter(
|
|
80
|
+
(p) =>
|
|
81
|
+
p.value.functions.length === 1 &&
|
|
82
|
+
p.value.size() === 1 &&
|
|
83
|
+
p.key.isSoleLiteral(),
|
|
84
|
+
)
|
|
85
|
+
.filter(
|
|
86
|
+
(p) => p.jsDocTags.find((tag) => tag.name === "hidden") === undefined,
|
|
87
|
+
)
|
|
88
|
+
.map((p) =>
|
|
89
|
+
writeFunction({
|
|
90
|
+
name: p.key.getSoleLiteral()!,
|
|
91
|
+
function: p.value.functions[0]!,
|
|
92
|
+
description: p.description,
|
|
93
|
+
jsDocTags: p.jsDocTags,
|
|
94
|
+
}),
|
|
95
|
+
),
|
|
96
|
+
options: {
|
|
97
|
+
separate: null,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const writeFunction = (props: {
|
|
103
|
+
name: string;
|
|
104
|
+
function: MetadataFunction;
|
|
105
|
+
description: string | null;
|
|
106
|
+
jsDocTags: IJsDocTagInfo[];
|
|
107
|
+
}): ILlmFunction => {
|
|
108
|
+
const deprecated: boolean = props.jsDocTags.some(
|
|
109
|
+
(tag) => tag.name === "deprecated",
|
|
110
|
+
);
|
|
111
|
+
const tags: string[] = props.jsDocTags
|
|
112
|
+
.map((tag) =>
|
|
113
|
+
tag.name === "tag"
|
|
114
|
+
? (tag.text?.filter((elem) => elem.kind === "text") ?? [])
|
|
115
|
+
: [],
|
|
116
|
+
)
|
|
117
|
+
.flat()
|
|
118
|
+
.map((elem) => elem.text)
|
|
119
|
+
.map((str) => str.trim().split(" ")[0] ?? "")
|
|
120
|
+
.filter((str) => !!str.length);
|
|
121
|
+
return {
|
|
122
|
+
name: props.name,
|
|
123
|
+
parameters: props.function.parameters.map((p) => {
|
|
124
|
+
const jsDocTagDescription: string | null = writeDescriptionFromJsDocTag(
|
|
125
|
+
{
|
|
126
|
+
jsDocTags: p.jsDocTags,
|
|
127
|
+
name: "param",
|
|
128
|
+
parameter: p.name,
|
|
129
|
+
},
|
|
130
|
+
);
|
|
131
|
+
return writeSchema({
|
|
132
|
+
metadata: p.type,
|
|
133
|
+
description: jsDocTagDescription ?? p.description,
|
|
134
|
+
jsDocTags: jsDocTagDescription ? [] : p.jsDocTags,
|
|
135
|
+
});
|
|
136
|
+
}),
|
|
137
|
+
output:
|
|
138
|
+
props.function.output.size() || props.function.output.nullable
|
|
139
|
+
? writeSchema({
|
|
140
|
+
metadata: props.function.output,
|
|
141
|
+
description:
|
|
142
|
+
writeDescriptionFromJsDocTag({
|
|
143
|
+
jsDocTags: props.jsDocTags,
|
|
144
|
+
name: "return",
|
|
145
|
+
}) ??
|
|
146
|
+
writeDescriptionFromJsDocTag({
|
|
147
|
+
jsDocTags: props.jsDocTags,
|
|
148
|
+
name: "returns",
|
|
149
|
+
}),
|
|
150
|
+
jsDocTags: [],
|
|
151
|
+
})
|
|
152
|
+
: undefined,
|
|
153
|
+
description: props.description ?? undefined,
|
|
154
|
+
deprecated: deprecated || undefined,
|
|
155
|
+
tags: tags.length ? tags : undefined,
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const writeSchema = (props: {
|
|
160
|
+
metadata: Metadata;
|
|
161
|
+
description: string | null;
|
|
162
|
+
jsDocTags: IJsDocTagInfo[];
|
|
163
|
+
}): ILlmSchema => {
|
|
164
|
+
const schema: ILlmSchema = LlmSchemaProgrammer.write(props.metadata);
|
|
165
|
+
const explicit: Pick<ILlmSchema, "title" | "description"> =
|
|
166
|
+
writeDescription({
|
|
167
|
+
description: props.description,
|
|
168
|
+
jsDocTags: props.jsDocTags,
|
|
169
|
+
});
|
|
170
|
+
return {
|
|
171
|
+
...schema,
|
|
172
|
+
...(!!explicit.title?.length || !!explicit.description?.length
|
|
173
|
+
? explicit
|
|
174
|
+
: {}),
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const writeDescription = (props: {
|
|
179
|
+
description: string | null;
|
|
180
|
+
jsDocTags: IJsDocTagInfo[];
|
|
181
|
+
}): Pick<ILlmSchema, "title" | "description"> => {
|
|
182
|
+
const title: string | undefined = (() => {
|
|
183
|
+
const [explicit] = getJsDocTexts({
|
|
184
|
+
jsDocTags: props.jsDocTags,
|
|
185
|
+
name: "title",
|
|
186
|
+
});
|
|
187
|
+
if (explicit?.length) return explicit;
|
|
188
|
+
else if (!props.description?.length) return undefined;
|
|
189
|
+
|
|
190
|
+
const index: number = props.description.indexOf("\n");
|
|
191
|
+
const top: string = (
|
|
192
|
+
index === -1 ? props.description : props.description.substring(0, index)
|
|
193
|
+
).trim();
|
|
194
|
+
return top.endsWith(".") ? top.substring(0, top.length - 1) : undefined;
|
|
195
|
+
})();
|
|
196
|
+
return {
|
|
197
|
+
title: title,
|
|
198
|
+
description: props.description?.length ? props.description : undefined,
|
|
199
|
+
} as any;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const writeDescriptionFromJsDocTag = (props: {
|
|
203
|
+
jsDocTags: IJsDocTagInfo[];
|
|
204
|
+
name: string;
|
|
205
|
+
parameter?: string;
|
|
206
|
+
}): string | null => {
|
|
207
|
+
const parametric: (elem: IJsDocTagInfo) => boolean = props.parameter
|
|
208
|
+
? (tag) =>
|
|
209
|
+
tag.text!.find(
|
|
210
|
+
(elem) =>
|
|
211
|
+
elem.kind === "parameterName" && elem.text === props.parameter,
|
|
212
|
+
) !== undefined
|
|
213
|
+
: () => true;
|
|
214
|
+
const tag: IJsDocTagInfo | undefined = props.jsDocTags.find(
|
|
215
|
+
(tag) => tag.name === props.name && tag.text && parametric(tag),
|
|
216
|
+
);
|
|
217
|
+
return tag && tag.text
|
|
218
|
+
? (tag.text.find((elem) => elem.kind === "text")?.text ?? null)
|
|
219
|
+
: null;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const getJsDocTexts = (props: {
|
|
223
|
+
jsDocTags: IJsDocTagInfo[];
|
|
224
|
+
name: string;
|
|
225
|
+
}): string[] =>
|
|
226
|
+
props.jsDocTags
|
|
227
|
+
.filter(
|
|
228
|
+
(tag) =>
|
|
229
|
+
tag.name === props.name &&
|
|
230
|
+
tag.text &&
|
|
231
|
+
tag.text.find((elem) => elem.kind === "text" && elem.text.length) !==
|
|
232
|
+
undefined,
|
|
233
|
+
)
|
|
234
|
+
.map((tag) => tag.text!.find((elem) => elem.kind === "text")!.text);
|
|
235
|
+
}
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
-
|
|
5
|
-
import { AtomicPredicator } from "../helpers/AtomicPredicator";
|
|
6
|
-
import { llm_schema_station } from "../internal/llm_schema_station";
|
|
7
|
-
|
|
8
|
-
export namespace LlmSchemaProgrammer {
|
|
9
|
-
export const validate = (metadata: Metadata): string[] => {
|
|
10
|
-
const output: string[] = [];
|
|
11
|
-
if (
|
|
12
|
-
metadata.atomics.some((a) => a.type === "bigint") ||
|
|
13
|
-
metadata.constants.some((c) => c.type === "bigint")
|
|
14
|
-
)
|
|
15
|
-
output.push("LLM schema does not support bigint type.");
|
|
16
|
-
if (
|
|
17
|
-
metadata.tuples.some((t) =>
|
|
18
|
-
t.type.elements.some((e) => e.isRequired() === false),
|
|
19
|
-
) ||
|
|
20
|
-
metadata.arrays.some((a) => a.type.value.isRequired() === false)
|
|
21
|
-
)
|
|
22
|
-
output.push("LLM schema does not support undefined type in array.");
|
|
23
|
-
if (metadata.maps.length)
|
|
24
|
-
output.push("LLM schema does not support Map type.");
|
|
25
|
-
if (metadata.sets.length)
|
|
26
|
-
output.push("LLM schema does not support Set type.");
|
|
27
|
-
for (const native of metadata.natives)
|
|
28
|
-
if (
|
|
29
|
-
AtomicPredicator.native(native) === false &&
|
|
30
|
-
native !== "Date" &&
|
|
31
|
-
native !== "Blob" &&
|
|
32
|
-
native !== "File"
|
|
33
|
-
)
|
|
34
|
-
output.push(`LLM schema does not support ${native} type.`);
|
|
35
|
-
if (
|
|
36
|
-
metadata.aliases.some((a) => a.recursive) ||
|
|
37
|
-
metadata.arrays.some((a) => a.type.recursive) ||
|
|
38
|
-
metadata.objects.some((o) => o.recursive) ||
|
|
39
|
-
metadata.tuples.some((t) => t.type.recursive)
|
|
40
|
-
)
|
|
41
|
-
output.push("LLM schema does not support recursive type.");
|
|
42
|
-
return output;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const write = (metadata: Metadata): ILlmSchema =>
|
|
46
|
-
llm_schema_station({
|
|
47
|
-
metadata,
|
|
48
|
-
blockNever: true,
|
|
49
|
-
attribute: {},
|
|
50
|
-
});
|
|
51
|
-
}
|
|
1
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
+
|
|
5
|
+
import { AtomicPredicator } from "../helpers/AtomicPredicator";
|
|
6
|
+
import { llm_schema_station } from "../internal/llm_schema_station";
|
|
7
|
+
|
|
8
|
+
export namespace LlmSchemaProgrammer {
|
|
9
|
+
export const validate = (metadata: Metadata): string[] => {
|
|
10
|
+
const output: string[] = [];
|
|
11
|
+
if (
|
|
12
|
+
metadata.atomics.some((a) => a.type === "bigint") ||
|
|
13
|
+
metadata.constants.some((c) => c.type === "bigint")
|
|
14
|
+
)
|
|
15
|
+
output.push("LLM schema does not support bigint type.");
|
|
16
|
+
if (
|
|
17
|
+
metadata.tuples.some((t) =>
|
|
18
|
+
t.type.elements.some((e) => e.isRequired() === false),
|
|
19
|
+
) ||
|
|
20
|
+
metadata.arrays.some((a) => a.type.value.isRequired() === false)
|
|
21
|
+
)
|
|
22
|
+
output.push("LLM schema does not support undefined type in array.");
|
|
23
|
+
if (metadata.maps.length)
|
|
24
|
+
output.push("LLM schema does not support Map type.");
|
|
25
|
+
if (metadata.sets.length)
|
|
26
|
+
output.push("LLM schema does not support Set type.");
|
|
27
|
+
for (const native of metadata.natives)
|
|
28
|
+
if (
|
|
29
|
+
AtomicPredicator.native(native) === false &&
|
|
30
|
+
native !== "Date" &&
|
|
31
|
+
native !== "Blob" &&
|
|
32
|
+
native !== "File"
|
|
33
|
+
)
|
|
34
|
+
output.push(`LLM schema does not support ${native} type.`);
|
|
35
|
+
if (
|
|
36
|
+
metadata.aliases.some((a) => a.recursive) ||
|
|
37
|
+
metadata.arrays.some((a) => a.type.recursive) ||
|
|
38
|
+
metadata.objects.some((o) => o.recursive) ||
|
|
39
|
+
metadata.tuples.some((t) => t.type.recursive)
|
|
40
|
+
)
|
|
41
|
+
output.push("LLM schema does not support recursive type.");
|
|
42
|
+
return output;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const write = (metadata: Metadata): ILlmSchema =>
|
|
46
|
+
llm_schema_station({
|
|
47
|
+
metadata,
|
|
48
|
+
blockNever: true,
|
|
49
|
+
attribute: {},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -982,7 +982,10 @@ export namespace MiscCloneProgrammer {
|
|
|
982
982
|
code: props.functor.method,
|
|
983
983
|
errors: result.errors,
|
|
984
984
|
});
|
|
985
|
-
return
|
|
985
|
+
return {
|
|
986
|
+
collection,
|
|
987
|
+
metadata: result.data,
|
|
988
|
+
};
|
|
986
989
|
};
|
|
987
990
|
|
|
988
991
|
const create_throw_error = (props: {
|
|
@@ -691,7 +691,10 @@ export namespace MiscPruneProgrammer {
|
|
|
691
691
|
code: props.functor.method,
|
|
692
692
|
errors: result.errors,
|
|
693
693
|
});
|
|
694
|
-
return
|
|
694
|
+
return {
|
|
695
|
+
collection,
|
|
696
|
+
metadata: result.data,
|
|
697
|
+
};
|
|
695
698
|
};
|
|
696
699
|
|
|
697
700
|
const create_throw_error = (props: {
|
|
@@ -934,7 +934,10 @@ export namespace NotationGeneralProgrammer {
|
|
|
934
934
|
code: props.functor.method,
|
|
935
935
|
errors: result.errors,
|
|
936
936
|
});
|
|
937
|
-
return
|
|
937
|
+
return {
|
|
938
|
+
collection,
|
|
939
|
+
metadata: result.data,
|
|
940
|
+
};
|
|
938
941
|
};
|
|
939
942
|
|
|
940
943
|
const create_throw_error = (props: {
|
|
@@ -295,7 +295,7 @@ export namespace ProtobufDecodeProgrammer {
|
|
|
295
295
|
? ts.factory.createNewExpression(
|
|
296
296
|
ts.factory.createIdentifier("Uint8Array"),
|
|
297
297
|
undefined,
|
|
298
|
-
[],
|
|
298
|
+
[ts.factory.createArrayLiteralExpression([])],
|
|
299
299
|
)
|
|
300
300
|
: value.atomics.some((a) => a.type === "string") ||
|
|
301
301
|
value.constants.some(
|