typia 6.10.0-dev.20240906 → 6.10.0-dev.20240908
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/_external/node_modules_@samchon_openapi_lib_utils/LlmSchemaSeparator.mjs +142 -0
- package/lib/_external/node_modules_@samchon_openapi_lib_utils/LlmSchemaSeparator.mjs.map +1 -0
- package/lib/_external/node_modules_@samchon_openapi_lib_utils/LlmTypeChecker.mjs +171 -0
- package/lib/_external/node_modules_@samchon_openapi_lib_utils/LlmTypeChecker.mjs.map +1 -0
- package/lib/_virtual/LlmSchemaSeparator.mjs +4 -0
- package/lib/_virtual/LlmSchemaSeparator.mjs.map +1 -0
- package/lib/_virtual/LlmTypeChecker.mjs +4 -0
- package/lib/_virtual/LlmTypeChecker.mjs.map +1 -0
- package/lib/_virtual/_commonjsHelpers.mjs +3 -1
- package/lib/_virtual/_commonjsHelpers.mjs.map +1 -1
- package/lib/factories/MetadataFactory.d.ts +1 -0
- package/lib/factories/MetadataFactory.js.map +1 -1
- package/lib/factories/MetadataTypeTagSchemaFactory.js +1 -1
- package/lib/factories/MetadataTypeTagSchemaFactory.js.map +1 -1
- package/lib/factories/ProtobufFactory.js +1 -1
- package/lib/factories/ProtobufFactory.js.map +1 -1
- package/lib/factories/TypeFactory.d.ts +1 -0
- package/lib/factories/TypeFactory.js +2 -2
- package/lib/factories/TypeFactory.js.map +1 -1
- package/lib/factories/internal/metadata/emplace_metadata_object.js +11 -6
- package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata.js +2 -0
- package/lib/factories/internal/metadata/iterate_metadata.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_coalesce.js +0 -5
- package/lib/factories/internal/metadata/iterate_metadata_coalesce.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_function.d.ts +5 -0
- package/lib/factories/internal/metadata/iterate_metadata_function.js +89 -0
- package/lib/factories/internal/metadata/iterate_metadata_function.js.map +1 -0
- package/lib/functional/Namespace/index.d.ts +1 -0
- package/lib/functional/Namespace/index.js +2 -1
- package/lib/functional/Namespace/index.js.map +1 -1
- package/lib/functional/Namespace/index.mjs +1 -0
- package/lib/functional/Namespace/index.mjs.map +1 -1
- package/lib/functional/Namespace/llm.d.ts +4 -0
- package/lib/functional/Namespace/llm.js +44 -0
- package/lib/functional/Namespace/llm.js.map +1 -0
- package/lib/functional/Namespace/llm.mjs +19 -0
- package/lib/functional/Namespace/llm.mjs.map +1 -0
- package/lib/llm.d.ts +148 -2
- package/lib/llm.js +28 -1
- package/lib/llm.js.map +1 -1
- package/lib/llm.mjs +6 -1
- package/lib/llm.mjs.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +1 -1
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +1 -1
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/functional/internal/FunctionalGeneralProgrammer.d.ts +1 -1
- package/lib/programmers/functional/internal/FunctionalGeneralProgrammer.js.map +1 -1
- package/lib/programmers/internal/application_v30_object.js +1 -1
- package/lib/programmers/internal/application_v30_object.js.map +1 -1
- package/lib/programmers/internal/application_v31_object.js +1 -1
- package/lib/programmers/internal/application_v31_object.js.map +1 -1
- package/lib/programmers/internal/llm_schema_object.js +1 -1
- package/lib/programmers/internal/llm_schema_object.js.map +1 -1
- package/lib/programmers/internal/llm_schema_tuple.d.ts +1 -6
- package/lib/programmers/internal/llm_schema_tuple.js +3 -0
- package/lib/programmers/internal/llm_schema_tuple.js.map +1 -1
- package/lib/programmers/internal/stringify_regular_properties.js +4 -4
- package/lib/programmers/internal/stringify_regular_properties.js.map +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +2 -2
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.d.ts +7 -0
- package/lib/programmers/llm/LlmApplicationProgrammer.js +211 -0
- package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -0
- package/lib/programmers/misc/MiscCloneProgrammer.js +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/schemas/metadata/IMetadata.d.ts +2 -1
- package/lib/schemas/metadata/IMetadataFunction.d.ts +7 -0
- package/lib/schemas/metadata/IMetadataFunction.js +3 -0
- package/lib/schemas/metadata/IMetadataFunction.js.map +1 -0
- package/lib/schemas/metadata/IMetadataParameter.d.ts +8 -0
- package/lib/schemas/metadata/IMetadataParameter.js +3 -0
- package/lib/schemas/metadata/IMetadataParameter.js.map +1 -0
- package/lib/schemas/metadata/Metadata.d.ts +2 -1
- package/lib/schemas/metadata/Metadata.js +12 -11
- package/lib/schemas/metadata/Metadata.js.map +1 -1
- package/lib/schemas/metadata/MetadataFunction.d.ts +15 -0
- package/lib/schemas/metadata/MetadataFunction.js +38 -0
- package/lib/schemas/metadata/MetadataFunction.js.map +1 -0
- package/lib/schemas/metadata/MetadataParameter.d.ts +13 -0
- package/lib/schemas/metadata/MetadataParameter.js +37 -0
- package/lib/schemas/metadata/MetadataParameter.js.map +1 -0
- package/lib/transformers/CallExpressionTransformer.js +4 -0
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/llm/LlmApplicationTransformer.d.ts +5 -0
- package/lib/transformers/features/llm/LlmApplicationTransformer.js +86 -0
- package/lib/transformers/features/llm/LlmApplicationTransformer.js.map +1 -0
- package/lib/transformers/features/llm/LlmSchemaTransformer.js +2 -1
- package/lib/transformers/features/llm/LlmSchemaTransformer.js.map +1 -1
- package/lib/transformers/features/reflect/ReflectMetadataTransformer.js +1 -0
- package/lib/transformers/features/reflect/ReflectMetadataTransformer.js.map +1 -1
- package/package.json +2 -2
- package/src/factories/MetadataFactory.ts +1 -0
- package/src/factories/MetadataTypeTagSchemaFactory.ts +59 -59
- package/src/factories/ProtobufFactory.ts +1 -1
- package/src/factories/TypeFactory.ts +1 -1
- package/src/factories/internal/metadata/emplace_metadata_object.ts +10 -6
- package/src/factories/internal/metadata/explore_metadata.ts +28 -28
- package/src/factories/internal/metadata/iterate_metadata.ts +6 -0
- package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +0 -5
- package/src/factories/internal/metadata/iterate_metadata_function.ts +85 -0
- package/src/functional/Namespace/index.ts +1 -0
- package/src/functional/Namespace/llm.ts +20 -0
- package/src/llm.ts +159 -3
- package/src/programmers/CheckerProgrammer.ts +1 -1
- package/src/programmers/RandomProgrammer.ts +1 -1
- package/src/programmers/functional/internal/FunctionalGeneralProgrammer.ts +3 -1
- package/src/programmers/internal/application_escaped.ts +74 -74
- package/src/programmers/internal/application_v30_object.ts +1 -1
- package/src/programmers/internal/application_v31_object.ts +1 -1
- package/src/programmers/internal/llm_schema_object.ts +1 -1
- package/src/programmers/internal/stringify_regular_properties.ts +4 -4
- package/src/programmers/json/JsonStringifyProgrammer.ts +2 -2
- package/src/programmers/llm/LlmApplicationProgrammer.ts +211 -0
- package/src/programmers/misc/MiscCloneProgrammer.ts +1 -1
- package/src/programmers/notations/NotationGeneralProgrammer.ts +1 -1
- package/src/schemas/metadata/IMetadata.ts +2 -1
- package/src/schemas/metadata/IMetadataFunction.ts +8 -0
- package/src/schemas/metadata/IMetadataParameter.ts +9 -0
- package/src/schemas/metadata/Metadata.ts +13 -12
- package/src/schemas/metadata/MetadataFunction.ts +49 -0
- package/src/schemas/metadata/MetadataParameter.ts +50 -0
- package/src/transformers/CallExpressionTransformer.ts +508 -505
- package/src/transformers/features/llm/LlmApplicationTransformer.ts +87 -0
- package/src/transformers/features/llm/LlmSchemaTransformer.ts +2 -1
- package/src/transformers/features/reflect/ReflectMetadataTransformer.ts +1 -0
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import { OpenApi, OpenApiV3 } from "@samchon/openapi";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
-
import { MetadataEscaped } from "../../schemas/metadata/MetadataEscaped";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export const application_escaped =
|
|
10
|
-
<Version extends "3.0" | "3.1">(
|
|
11
|
-
generator: (meta: Metadata) => Schema<Version>,
|
|
12
|
-
) =>
|
|
13
|
-
(escaped: MetadataEscaped): Schema<Version>[] => {
|
|
14
|
-
const output: Schema<Version> | null = generator(escaped.returns);
|
|
15
|
-
if (output === null) return [];
|
|
16
|
-
|
|
17
|
-
if (is_date(new Set())(escaped.original)) {
|
|
18
|
-
const string: StringSchema<Version> | undefined = is_string(output)
|
|
19
|
-
? output
|
|
20
|
-
: is_one_of(output)
|
|
21
|
-
? (output.oneOf.find(is_string) as StringSchema<Version>)
|
|
22
|
-
: undefined;
|
|
23
|
-
if (
|
|
24
|
-
string !== undefined &&
|
|
25
|
-
string.format !== "date" &&
|
|
26
|
-
string.format !== "date-time"
|
|
27
|
-
)
|
|
28
|
-
string.format = "date-time";
|
|
29
|
-
}
|
|
30
|
-
return is_one_of(output) ? (output.oneOf as Schema<Version>[]) : [output];
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
const is_string = <Version extends "3.0" | "3.1">(
|
|
37
|
-
elem: Schema<Version>,
|
|
38
|
-
): elem is StringSchema<Version> =>
|
|
39
|
-
(elem as StringSchema<Version>).type === "string";
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @internal
|
|
43
|
-
*/
|
|
44
|
-
const is_one_of = <Version extends "3.0" | "3.1">(
|
|
45
|
-
elem: Schema<Version>,
|
|
46
|
-
): elem is OneOfSchema<Version> =>
|
|
47
|
-
Array.isArray((elem as OneOfSchema<Version>).oneOf);
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @internal
|
|
51
|
-
*/
|
|
52
|
-
const is_date =
|
|
53
|
-
(visited: Set<Metadata>) =>
|
|
54
|
-
(meta: Metadata): boolean => {
|
|
55
|
-
if (visited.has(meta)) return false;
|
|
56
|
-
visited.add(meta);
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
meta.natives.some((name) => name === "Date") ||
|
|
60
|
-
meta.arrays.some((array) => is_date(visited)(array.type.value)) ||
|
|
61
|
-
meta.tuples.some((tuple) => tuple.type.elements.some(is_date(visited))) ||
|
|
62
|
-
meta.aliases.some((alias) => is_date(visited)(alias.value))
|
|
63
|
-
);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
type Schema<Version extends "3.0" | "3.1"> = Version extends "3.0"
|
|
67
|
-
? OpenApiV3.IJsonSchema
|
|
68
|
-
: OpenApi.IJsonSchema;
|
|
69
|
-
type StringSchema<Version extends "3.0" | "3.1"> = Version extends "3.0"
|
|
70
|
-
? OpenApiV3.IJsonSchema.IString
|
|
71
|
-
: OpenApi.IJsonSchema.IString;
|
|
72
|
-
type OneOfSchema<Version extends "3.0" | "3.1"> = Version extends "3.0"
|
|
73
|
-
? OpenApiV3.IJsonSchema.IOneOf
|
|
74
|
-
: OpenApi.IJsonSchema.IOneOf;
|
|
1
|
+
import { OpenApi, OpenApiV3 } from "@samchon/openapi";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
+
import { MetadataEscaped } from "../../schemas/metadata/MetadataEscaped";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export const application_escaped =
|
|
10
|
+
<Version extends "3.0" | "3.1">(
|
|
11
|
+
generator: (meta: Metadata) => Schema<Version>,
|
|
12
|
+
) =>
|
|
13
|
+
(escaped: MetadataEscaped): Schema<Version>[] => {
|
|
14
|
+
const output: Schema<Version> | null = generator(escaped.returns);
|
|
15
|
+
if (output === null) return [];
|
|
16
|
+
|
|
17
|
+
if (is_date(new Set())(escaped.original)) {
|
|
18
|
+
const string: StringSchema<Version> | undefined = is_string(output)
|
|
19
|
+
? output
|
|
20
|
+
: is_one_of(output)
|
|
21
|
+
? (output.oneOf.find(is_string) as StringSchema<Version>)
|
|
22
|
+
: undefined;
|
|
23
|
+
if (
|
|
24
|
+
string !== undefined &&
|
|
25
|
+
string.format !== "date" &&
|
|
26
|
+
string.format !== "date-time"
|
|
27
|
+
)
|
|
28
|
+
string.format = "date-time";
|
|
29
|
+
}
|
|
30
|
+
return is_one_of(output) ? (output.oneOf as Schema<Version>[]) : [output];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
const is_string = <Version extends "3.0" | "3.1">(
|
|
37
|
+
elem: Schema<Version>,
|
|
38
|
+
): elem is StringSchema<Version> =>
|
|
39
|
+
(elem as StringSchema<Version>).type === "string";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
const is_one_of = <Version extends "3.0" | "3.1">(
|
|
45
|
+
elem: Schema<Version>,
|
|
46
|
+
): elem is OneOfSchema<Version> =>
|
|
47
|
+
Array.isArray((elem as OneOfSchema<Version>).oneOf);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
const is_date =
|
|
53
|
+
(visited: Set<Metadata>) =>
|
|
54
|
+
(meta: Metadata): boolean => {
|
|
55
|
+
if (visited.has(meta)) return false;
|
|
56
|
+
visited.add(meta);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
meta.natives.some((name) => name === "Date") ||
|
|
60
|
+
meta.arrays.some((array) => is_date(visited)(array.type.value)) ||
|
|
61
|
+
meta.tuples.some((tuple) => tuple.type.elements.some(is_date(visited))) ||
|
|
62
|
+
meta.aliases.some((alias) => is_date(visited)(alias.value))
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
type Schema<Version extends "3.0" | "3.1"> = Version extends "3.0"
|
|
67
|
+
? OpenApiV3.IJsonSchema
|
|
68
|
+
: OpenApi.IJsonSchema;
|
|
69
|
+
type StringSchema<Version extends "3.0" | "3.1"> = Version extends "3.0"
|
|
70
|
+
? OpenApiV3.IJsonSchema.IString
|
|
71
|
+
: OpenApi.IJsonSchema.IString;
|
|
72
|
+
type OneOfSchema<Version extends "3.0" | "3.1"> = Version extends "3.0"
|
|
73
|
+
? OpenApiV3.IJsonSchema.IOneOf
|
|
74
|
+
: OpenApi.IJsonSchema.IOneOf;
|
|
@@ -53,7 +53,7 @@ const create_object_schema =
|
|
|
53
53
|
for (const property of obj.properties) {
|
|
54
54
|
if (
|
|
55
55
|
// FUNCTIONAL TYPE
|
|
56
|
-
property.value.
|
|
56
|
+
property.value.functions.length &&
|
|
57
57
|
property.value.nullable === false &&
|
|
58
58
|
property.value.isRequired() === true &&
|
|
59
59
|
property.value.size() === 0
|
|
@@ -51,7 +51,7 @@ const create_object_schema =
|
|
|
51
51
|
for (const property of obj.properties) {
|
|
52
52
|
if (
|
|
53
53
|
// FUNCTIONAL TYPE
|
|
54
|
-
property.value.
|
|
54
|
+
property.value.functions.length &&
|
|
55
55
|
property.value.nullable === false &&
|
|
56
56
|
property.value.isRequired() === true &&
|
|
57
57
|
property.value.size() === 0
|
|
@@ -30,7 +30,7 @@ export const llm_schema_object = (props: {
|
|
|
30
30
|
for (const property of props.object.properties) {
|
|
31
31
|
if (
|
|
32
32
|
// FUNCTIONAL TYPE
|
|
33
|
-
property.value.
|
|
33
|
+
property.value.functions.length &&
|
|
34
34
|
property.value.nullable === false &&
|
|
35
35
|
property.value.isRequired() === true &&
|
|
36
36
|
property.value.size() === 0
|
|
@@ -31,14 +31,14 @@ export const stringify_regular_properties = (
|
|
|
31
31
|
(entry.meta.isRequired() === false &&
|
|
32
32
|
entry.meta.nullable === false &&
|
|
33
33
|
entry.meta.size() === 0) ||
|
|
34
|
-
(entry.meta.
|
|
34
|
+
(!!entry.meta.functions.length &&
|
|
35
35
|
entry.meta.nullable === false &&
|
|
36
36
|
entry.meta.size() === 1);
|
|
37
37
|
|
|
38
38
|
if (empty === true) return;
|
|
39
39
|
else if (
|
|
40
40
|
entry.meta.isRequired() === false ||
|
|
41
|
-
entry.meta.
|
|
41
|
+
entry.meta.functions.length ||
|
|
42
42
|
entry.meta.any === true
|
|
43
43
|
)
|
|
44
44
|
output.push(
|
|
@@ -52,7 +52,7 @@ export const stringify_regular_properties = (
|
|
|
52
52
|
entry.input,
|
|
53
53
|
),
|
|
54
54
|
);
|
|
55
|
-
if (entry.meta.
|
|
55
|
+
if (entry.meta.functions.length || entry.meta.any)
|
|
56
56
|
conditions.push(
|
|
57
57
|
ts.factory.createStrictEquality(
|
|
58
58
|
ts.factory.createStringLiteral("function"),
|
|
@@ -78,4 +78,4 @@ export const stringify_regular_properties = (
|
|
|
78
78
|
* @internal
|
|
79
79
|
*/
|
|
80
80
|
const sequence = (meta: Metadata): number =>
|
|
81
|
-
meta.any || !meta.isRequired() || meta.
|
|
81
|
+
meta.any || !meta.isRequired() || meta.functions.length ? 0 : 1;
|
|
@@ -233,7 +233,7 @@ export namespace JsonStringifyProgrammer {
|
|
|
233
233
|
explore,
|
|
234
234
|
),
|
|
235
235
|
});
|
|
236
|
-
else if (meta.
|
|
236
|
+
else if (meta.functions.length)
|
|
237
237
|
unions.push({
|
|
238
238
|
type: "functional",
|
|
239
239
|
is: () => IsProgrammer.decode_functional(input),
|
|
@@ -797,7 +797,7 @@ export namespace JsonStringifyProgrammer {
|
|
|
797
797
|
meta: Metadata,
|
|
798
798
|
explore: FeatureProgrammer.IExplore,
|
|
799
799
|
): ((expression: ts.Expression) => ts.Expression) => {
|
|
800
|
-
if (meta.
|
|
800
|
+
if (meta.functions.length === 0) return (expression) => expression;
|
|
801
801
|
return (expression) =>
|
|
802
802
|
ts.factory.createConditionalExpression(
|
|
803
803
|
ts.factory.createStrictInequality(
|
|
@@ -0,0 +1,211 @@
|
|
|
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
|
+
meta: Metadata,
|
|
16
|
+
explore: MetadataFactory.IExplore,
|
|
17
|
+
): string[] => {
|
|
18
|
+
if (explore.top === false) return LlmSchemaProgrammer.validate(meta);
|
|
19
|
+
|
|
20
|
+
const output: string[] = [];
|
|
21
|
+
const valid: boolean =
|
|
22
|
+
meta.size() === 1 &&
|
|
23
|
+
meta.objects.length === 1 &&
|
|
24
|
+
meta.isRequired() === true &&
|
|
25
|
+
meta.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 = meta.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
|
+
nested: null,
|
|
68
|
+
escaped: false,
|
|
69
|
+
aliased: false,
|
|
70
|
+
});
|
|
71
|
+
if (errors.length)
|
|
72
|
+
throw new Error("Failed to write LLM application: " + errors.join("\n"));
|
|
73
|
+
|
|
74
|
+
const object: MetadataObject = metadata.objects[0]!;
|
|
75
|
+
return {
|
|
76
|
+
functions: object.properties
|
|
77
|
+
.filter(
|
|
78
|
+
(p) =>
|
|
79
|
+
p.value.functions.length === 1 &&
|
|
80
|
+
p.value.size() === 1 &&
|
|
81
|
+
p.key.isSoleLiteral(),
|
|
82
|
+
)
|
|
83
|
+
.map((p) =>
|
|
84
|
+
writeFunction({
|
|
85
|
+
name: p.key.getSoleLiteral()!,
|
|
86
|
+
function: p.value.functions[0]!,
|
|
87
|
+
description: p.description,
|
|
88
|
+
jsDocTags: p.jsDocTags,
|
|
89
|
+
}),
|
|
90
|
+
),
|
|
91
|
+
options: {
|
|
92
|
+
separate: null,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const writeFunction = (props: {
|
|
98
|
+
name: string;
|
|
99
|
+
function: MetadataFunction;
|
|
100
|
+
description: string | null;
|
|
101
|
+
jsDocTags: IJsDocTagInfo[];
|
|
102
|
+
}): ILlmFunction => ({
|
|
103
|
+
name: props.name,
|
|
104
|
+
parameters: props.function.parameters.map((p) => {
|
|
105
|
+
const jsDocTagDescription = writeDescriptionFromJsDocTag({
|
|
106
|
+
jsDocTags: p.jsDocTags,
|
|
107
|
+
tag: "param",
|
|
108
|
+
parameter: p.name,
|
|
109
|
+
});
|
|
110
|
+
return writeSchema({
|
|
111
|
+
metadata: p.type,
|
|
112
|
+
description: jsDocTagDescription ?? p.description,
|
|
113
|
+
jsDocTags: jsDocTagDescription ? [] : p.jsDocTags,
|
|
114
|
+
});
|
|
115
|
+
}),
|
|
116
|
+
output:
|
|
117
|
+
props.function.output.size() || props.function.output.nullable
|
|
118
|
+
? writeSchema({
|
|
119
|
+
metadata: props.function.output,
|
|
120
|
+
description:
|
|
121
|
+
writeDescriptionFromJsDocTag({
|
|
122
|
+
jsDocTags: props.jsDocTags,
|
|
123
|
+
tag: "return",
|
|
124
|
+
}) ??
|
|
125
|
+
writeDescriptionFromJsDocTag({
|
|
126
|
+
jsDocTags: props.jsDocTags,
|
|
127
|
+
tag: "returns",
|
|
128
|
+
}),
|
|
129
|
+
jsDocTags: [],
|
|
130
|
+
})
|
|
131
|
+
: undefined,
|
|
132
|
+
description: props.description ?? undefined,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const writeSchema = (props: {
|
|
136
|
+
metadata: Metadata;
|
|
137
|
+
description: string | null;
|
|
138
|
+
jsDocTags: IJsDocTagInfo[];
|
|
139
|
+
}): ILlmSchema => {
|
|
140
|
+
const schema: ILlmSchema = LlmSchemaProgrammer.write(props.metadata);
|
|
141
|
+
const explicit: Pick<ILlmSchema, "title" | "description"> =
|
|
142
|
+
writeDescription({
|
|
143
|
+
description: props.description,
|
|
144
|
+
jsDocTags: props.jsDocTags,
|
|
145
|
+
});
|
|
146
|
+
return {
|
|
147
|
+
...schema,
|
|
148
|
+
...(!!explicit.title?.length || !!explicit.description?.length
|
|
149
|
+
? explicit
|
|
150
|
+
: {}),
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const writeDescription = (props: {
|
|
155
|
+
description: string | null;
|
|
156
|
+
jsDocTags: IJsDocTagInfo[];
|
|
157
|
+
}): Pick<ILlmSchema, "title" | "description"> => {
|
|
158
|
+
const title: string | undefined = (() => {
|
|
159
|
+
const [explicit] = getJsDocTexts({
|
|
160
|
+
jsDocTags: props.jsDocTags,
|
|
161
|
+
name: "title",
|
|
162
|
+
});
|
|
163
|
+
if (explicit?.length) return explicit;
|
|
164
|
+
else if (!props.description?.length) return undefined;
|
|
165
|
+
|
|
166
|
+
const index: number = props.description.indexOf("\n");
|
|
167
|
+
const top: string = (
|
|
168
|
+
index === -1 ? props.description : props.description.substring(0, index)
|
|
169
|
+
).trim();
|
|
170
|
+
return top.endsWith(".") ? top.substring(0, top.length - 1) : undefined;
|
|
171
|
+
})();
|
|
172
|
+
return {
|
|
173
|
+
title: title,
|
|
174
|
+
description: props.description?.length ? props.description : undefined,
|
|
175
|
+
} as any;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const writeDescriptionFromJsDocTag = (props: {
|
|
179
|
+
jsDocTags: IJsDocTagInfo[];
|
|
180
|
+
tag: string;
|
|
181
|
+
parameter?: string;
|
|
182
|
+
}): string | null => {
|
|
183
|
+
const parametric: (elem: IJsDocTagInfo) => boolean = props.parameter
|
|
184
|
+
? (tag) =>
|
|
185
|
+
tag.text!.find(
|
|
186
|
+
(elem) =>
|
|
187
|
+
elem.kind === "parameterName" && elem.text === props.parameter,
|
|
188
|
+
) !== undefined
|
|
189
|
+
: () => true;
|
|
190
|
+
const tag: IJsDocTagInfo | undefined = props.jsDocTags.find(
|
|
191
|
+
(tag) => tag.name === props.tag && tag.text && parametric(tag),
|
|
192
|
+
);
|
|
193
|
+
return tag && tag.text
|
|
194
|
+
? (tag.text.find((elem) => elem.kind === "text")?.text ?? null)
|
|
195
|
+
: null;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const getJsDocTexts = (props: {
|
|
199
|
+
jsDocTags: IJsDocTagInfo[];
|
|
200
|
+
name: string;
|
|
201
|
+
}): string[] =>
|
|
202
|
+
props.jsDocTags
|
|
203
|
+
.filter(
|
|
204
|
+
(tag) =>
|
|
205
|
+
tag.name === props.name &&
|
|
206
|
+
tag.text &&
|
|
207
|
+
tag.text.find((elem) => elem.kind === "text" && elem.text.length) !==
|
|
208
|
+
undefined,
|
|
209
|
+
)
|
|
210
|
+
.map((tag) => tag.text!.find((elem) => elem.kind === "text")!.text);
|
|
211
|
+
}
|
|
@@ -2,6 +2,7 @@ import { IMetadataAtomic } from "./IMetadataAtomic";
|
|
|
2
2
|
import { IMetadataConstant } from "./IMetadataConstant";
|
|
3
3
|
import { IMetadataEntry } from "./IMetadataEntry";
|
|
4
4
|
import { IMetadataEscaped } from "./IMetadataEscaped";
|
|
5
|
+
import { IMetadataFunction } from "./IMetadataFunction";
|
|
5
6
|
import { IMetadataTemplate } from "./IMetadataTemplate";
|
|
6
7
|
import { IMetadataTypeTag } from "./IMetadataTypeTag";
|
|
7
8
|
|
|
@@ -10,7 +11,7 @@ export interface IMetadata {
|
|
|
10
11
|
required: boolean;
|
|
11
12
|
optional: boolean;
|
|
12
13
|
nullable: boolean;
|
|
13
|
-
|
|
14
|
+
functions: IMetadataFunction[];
|
|
14
15
|
|
|
15
16
|
atomics: IMetadataAtomic[];
|
|
16
17
|
constants: IMetadataConstant[];
|
|
@@ -10,6 +10,7 @@ import { MetadataArray } from "./MetadataArray";
|
|
|
10
10
|
import { MetadataAtomic } from "./MetadataAtomic";
|
|
11
11
|
import { MetadataConstant } from "./MetadataConstant";
|
|
12
12
|
import { MetadataEscaped } from "./MetadataEscaped";
|
|
13
|
+
import { MetadataFunction } from "./MetadataFunction";
|
|
13
14
|
import { MetadataObject } from "./MetadataObject";
|
|
14
15
|
import { MetadataTemplate } from "./MetadataTemplate";
|
|
15
16
|
import { MetadataTuple } from "./MetadataTuple";
|
|
@@ -19,7 +20,6 @@ export class Metadata {
|
|
|
19
20
|
public required: boolean;
|
|
20
21
|
public optional: boolean;
|
|
21
22
|
public nullable: boolean;
|
|
22
|
-
public functional: boolean;
|
|
23
23
|
|
|
24
24
|
public escaped: MetadataEscaped | null;
|
|
25
25
|
public atomics: MetadataAtomic[];
|
|
@@ -31,6 +31,7 @@ export class Metadata {
|
|
|
31
31
|
public arrays: MetadataArray[];
|
|
32
32
|
public tuples: MetadataTuple[];
|
|
33
33
|
public objects: MetadataObject[];
|
|
34
|
+
public functions: MetadataFunction[];
|
|
34
35
|
|
|
35
36
|
public natives: string[];
|
|
36
37
|
public sets: Metadata[];
|
|
@@ -53,7 +54,7 @@ export class Metadata {
|
|
|
53
54
|
this.required = props.required;
|
|
54
55
|
this.optional = props.optional;
|
|
55
56
|
this.nullable = props.nullable;
|
|
56
|
-
this.
|
|
57
|
+
this.functions = props.functions;
|
|
57
58
|
|
|
58
59
|
this.escaped = props.escaped;
|
|
59
60
|
this.atomics = props.atomics;
|
|
@@ -87,7 +88,6 @@ export class Metadata {
|
|
|
87
88
|
nullable: false,
|
|
88
89
|
required: true,
|
|
89
90
|
optional: false,
|
|
90
|
-
functional: false,
|
|
91
91
|
|
|
92
92
|
escaped: null,
|
|
93
93
|
constants: [],
|
|
@@ -97,6 +97,7 @@ export class Metadata {
|
|
|
97
97
|
tuples: [],
|
|
98
98
|
objects: [],
|
|
99
99
|
aliases: [],
|
|
100
|
+
functions: [],
|
|
100
101
|
|
|
101
102
|
rest: null,
|
|
102
103
|
natives: [],
|
|
@@ -113,7 +114,7 @@ export class Metadata {
|
|
|
113
114
|
required: this.required,
|
|
114
115
|
optional: this.optional,
|
|
115
116
|
nullable: this.nullable,
|
|
116
|
-
|
|
117
|
+
functions: this.functions.map((f) => f.toJSON()),
|
|
117
118
|
|
|
118
119
|
atomics: this.atomics.map((a) => a.toJSON()),
|
|
119
120
|
constants: this.constants.map((c) => c.toJSON()),
|
|
@@ -147,7 +148,7 @@ export class Metadata {
|
|
|
147
148
|
required: meta.required,
|
|
148
149
|
optional: meta.optional,
|
|
149
150
|
nullable: meta.nullable,
|
|
150
|
-
|
|
151
|
+
functions: meta.functions.map((f) => MetadataFunction.from(f, dict)),
|
|
151
152
|
|
|
152
153
|
constants: meta.constants.map(MetadataConstant.from),
|
|
153
154
|
atomics: meta.atomics.map(MetadataAtomic.from),
|
|
@@ -218,7 +219,6 @@ export class Metadata {
|
|
|
218
219
|
return (
|
|
219
220
|
(this.any ? 1 : 0) +
|
|
220
221
|
(this.escaped ? 1 : 0) +
|
|
221
|
-
(this.functional ? 1 : 0) +
|
|
222
222
|
(this.rest ? this.rest.size() : 0) +
|
|
223
223
|
this.templates.length +
|
|
224
224
|
this.atomics.length +
|
|
@@ -229,6 +229,7 @@ export class Metadata {
|
|
|
229
229
|
this.maps.length +
|
|
230
230
|
this.sets.length +
|
|
231
231
|
this.objects.length +
|
|
232
|
+
this.functions.length +
|
|
232
233
|
this.aliases.length
|
|
233
234
|
);
|
|
234
235
|
}
|
|
@@ -237,7 +238,6 @@ export class Metadata {
|
|
|
237
238
|
return (
|
|
238
239
|
(this.any ? 1 : 0) +
|
|
239
240
|
(this.escaped ? 1 : 0) +
|
|
240
|
-
(this.functional ? 1 : 0) +
|
|
241
241
|
(this.templates.length ? 1 : 0) +
|
|
242
242
|
(this.atomics.length ? 1 : 0) +
|
|
243
243
|
(this.constants.length ? 1 : 0) +
|
|
@@ -248,6 +248,7 @@ export class Metadata {
|
|
|
248
248
|
(this.sets.length ? 1 : 0) +
|
|
249
249
|
(this.maps.length ? 1 : 0) +
|
|
250
250
|
(this.objects.length ? 1 : 0) +
|
|
251
|
+
(this.functions.length ? 1 : 0) +
|
|
251
252
|
(this.aliases.length ? 1 : 0)
|
|
252
253
|
);
|
|
253
254
|
}
|
|
@@ -301,7 +302,7 @@ export namespace Metadata {
|
|
|
301
302
|
if (x.any || y.any) return true;
|
|
302
303
|
if (x.isRequired() === false && false === y.isRequired()) return true;
|
|
303
304
|
if (x.nullable === true && true === y.nullable) return true;
|
|
304
|
-
if (x.
|
|
305
|
+
if (!!x.functions.length && !!y.functions.length === true) return true;
|
|
305
306
|
|
|
306
307
|
//----
|
|
307
308
|
// INSTANCES
|
|
@@ -459,7 +460,7 @@ export namespace Metadata {
|
|
|
459
460
|
}
|
|
460
461
|
|
|
461
462
|
// FUNCTIONAL
|
|
462
|
-
if (x.
|
|
463
|
+
if (!!x.functions.length === false && !!y.functions.length) return false;
|
|
463
464
|
|
|
464
465
|
// SUCCESS
|
|
465
466
|
return true;
|
|
@@ -474,7 +475,7 @@ export namespace Metadata {
|
|
|
474
475
|
nullable: x.nullable || y.nullable,
|
|
475
476
|
required: x.required && y.required,
|
|
476
477
|
optional: x.optional || y.optional,
|
|
477
|
-
|
|
478
|
+
functions: x.functions.length ? x.functions : y.functions, // @todo
|
|
478
479
|
|
|
479
480
|
escaped:
|
|
480
481
|
x.escaped !== null && y.escaped !== null
|
|
@@ -482,7 +483,7 @@ export namespace Metadata {
|
|
|
482
483
|
original: merge(x.escaped.original, y.escaped.original),
|
|
483
484
|
returns: merge(x.escaped.returns, y.escaped.returns),
|
|
484
485
|
})
|
|
485
|
-
: x.escaped ?? y.escaped,
|
|
486
|
+
: (x.escaped ?? y.escaped),
|
|
486
487
|
atomics: mergeTaggedTypes({
|
|
487
488
|
container: x.atomics,
|
|
488
489
|
equals: (x, y) => x.type === y.type,
|
|
@@ -494,7 +495,7 @@ export namespace Metadata {
|
|
|
494
495
|
rest:
|
|
495
496
|
x.rest !== null && y.rest !== null
|
|
496
497
|
? merge(x.rest, y.rest)
|
|
497
|
-
: x.rest ?? y.rest,
|
|
498
|
+
: (x.rest ?? y.rest),
|
|
498
499
|
// arrays: x.arrays.slice(),
|
|
499
500
|
arrays: mergeTaggedTypes({
|
|
500
501
|
container: x.arrays,
|