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.
Files changed (129) hide show
  1. package/lib/_external/node_modules_@samchon_openapi_lib_utils/LlmSchemaSeparator.mjs +142 -0
  2. package/lib/_external/node_modules_@samchon_openapi_lib_utils/LlmSchemaSeparator.mjs.map +1 -0
  3. package/lib/_external/node_modules_@samchon_openapi_lib_utils/LlmTypeChecker.mjs +171 -0
  4. package/lib/_external/node_modules_@samchon_openapi_lib_utils/LlmTypeChecker.mjs.map +1 -0
  5. package/lib/_virtual/LlmSchemaSeparator.mjs +4 -0
  6. package/lib/_virtual/LlmSchemaSeparator.mjs.map +1 -0
  7. package/lib/_virtual/LlmTypeChecker.mjs +4 -0
  8. package/lib/_virtual/LlmTypeChecker.mjs.map +1 -0
  9. package/lib/_virtual/_commonjsHelpers.mjs +3 -1
  10. package/lib/_virtual/_commonjsHelpers.mjs.map +1 -1
  11. package/lib/factories/MetadataFactory.d.ts +1 -0
  12. package/lib/factories/MetadataFactory.js.map +1 -1
  13. package/lib/factories/MetadataTypeTagSchemaFactory.js +1 -1
  14. package/lib/factories/MetadataTypeTagSchemaFactory.js.map +1 -1
  15. package/lib/factories/ProtobufFactory.js +1 -1
  16. package/lib/factories/ProtobufFactory.js.map +1 -1
  17. package/lib/factories/TypeFactory.d.ts +1 -0
  18. package/lib/factories/TypeFactory.js +2 -2
  19. package/lib/factories/TypeFactory.js.map +1 -1
  20. package/lib/factories/internal/metadata/emplace_metadata_object.js +11 -6
  21. package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
  22. package/lib/factories/internal/metadata/iterate_metadata.js +2 -0
  23. package/lib/factories/internal/metadata/iterate_metadata.js.map +1 -1
  24. package/lib/factories/internal/metadata/iterate_metadata_coalesce.js +0 -5
  25. package/lib/factories/internal/metadata/iterate_metadata_coalesce.js.map +1 -1
  26. package/lib/factories/internal/metadata/iterate_metadata_function.d.ts +5 -0
  27. package/lib/factories/internal/metadata/iterate_metadata_function.js +89 -0
  28. package/lib/factories/internal/metadata/iterate_metadata_function.js.map +1 -0
  29. package/lib/functional/Namespace/index.d.ts +1 -0
  30. package/lib/functional/Namespace/index.js +2 -1
  31. package/lib/functional/Namespace/index.js.map +1 -1
  32. package/lib/functional/Namespace/index.mjs +1 -0
  33. package/lib/functional/Namespace/index.mjs.map +1 -1
  34. package/lib/functional/Namespace/llm.d.ts +4 -0
  35. package/lib/functional/Namespace/llm.js +44 -0
  36. package/lib/functional/Namespace/llm.js.map +1 -0
  37. package/lib/functional/Namespace/llm.mjs +19 -0
  38. package/lib/functional/Namespace/llm.mjs.map +1 -0
  39. package/lib/llm.d.ts +148 -2
  40. package/lib/llm.js +28 -1
  41. package/lib/llm.js.map +1 -1
  42. package/lib/llm.mjs +6 -1
  43. package/lib/llm.mjs.map +1 -1
  44. package/lib/programmers/CheckerProgrammer.js +1 -1
  45. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  46. package/lib/programmers/RandomProgrammer.js +1 -1
  47. package/lib/programmers/RandomProgrammer.js.map +1 -1
  48. package/lib/programmers/functional/internal/FunctionalGeneralProgrammer.d.ts +1 -1
  49. package/lib/programmers/functional/internal/FunctionalGeneralProgrammer.js.map +1 -1
  50. package/lib/programmers/internal/application_v30_object.js +1 -1
  51. package/lib/programmers/internal/application_v30_object.js.map +1 -1
  52. package/lib/programmers/internal/application_v31_object.js +1 -1
  53. package/lib/programmers/internal/application_v31_object.js.map +1 -1
  54. package/lib/programmers/internal/llm_schema_object.js +1 -1
  55. package/lib/programmers/internal/llm_schema_object.js.map +1 -1
  56. package/lib/programmers/internal/llm_schema_tuple.d.ts +1 -6
  57. package/lib/programmers/internal/llm_schema_tuple.js +3 -0
  58. package/lib/programmers/internal/llm_schema_tuple.js.map +1 -1
  59. package/lib/programmers/internal/stringify_regular_properties.js +4 -4
  60. package/lib/programmers/internal/stringify_regular_properties.js.map +1 -1
  61. package/lib/programmers/json/JsonStringifyProgrammer.js +2 -2
  62. package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
  63. package/lib/programmers/llm/LlmApplicationProgrammer.d.ts +7 -0
  64. package/lib/programmers/llm/LlmApplicationProgrammer.js +211 -0
  65. package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -0
  66. package/lib/programmers/misc/MiscCloneProgrammer.js +1 -1
  67. package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
  68. package/lib/programmers/notations/NotationGeneralProgrammer.js +1 -1
  69. package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
  70. package/lib/schemas/metadata/IMetadata.d.ts +2 -1
  71. package/lib/schemas/metadata/IMetadataFunction.d.ts +7 -0
  72. package/lib/schemas/metadata/IMetadataFunction.js +3 -0
  73. package/lib/schemas/metadata/IMetadataFunction.js.map +1 -0
  74. package/lib/schemas/metadata/IMetadataParameter.d.ts +8 -0
  75. package/lib/schemas/metadata/IMetadataParameter.js +3 -0
  76. package/lib/schemas/metadata/IMetadataParameter.js.map +1 -0
  77. package/lib/schemas/metadata/Metadata.d.ts +2 -1
  78. package/lib/schemas/metadata/Metadata.js +12 -11
  79. package/lib/schemas/metadata/Metadata.js.map +1 -1
  80. package/lib/schemas/metadata/MetadataFunction.d.ts +15 -0
  81. package/lib/schemas/metadata/MetadataFunction.js +38 -0
  82. package/lib/schemas/metadata/MetadataFunction.js.map +1 -0
  83. package/lib/schemas/metadata/MetadataParameter.d.ts +13 -0
  84. package/lib/schemas/metadata/MetadataParameter.js +37 -0
  85. package/lib/schemas/metadata/MetadataParameter.js.map +1 -0
  86. package/lib/transformers/CallExpressionTransformer.js +4 -0
  87. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  88. package/lib/transformers/features/llm/LlmApplicationTransformer.d.ts +5 -0
  89. package/lib/transformers/features/llm/LlmApplicationTransformer.js +86 -0
  90. package/lib/transformers/features/llm/LlmApplicationTransformer.js.map +1 -0
  91. package/lib/transformers/features/llm/LlmSchemaTransformer.js +2 -1
  92. package/lib/transformers/features/llm/LlmSchemaTransformer.js.map +1 -1
  93. package/lib/transformers/features/reflect/ReflectMetadataTransformer.js +1 -0
  94. package/lib/transformers/features/reflect/ReflectMetadataTransformer.js.map +1 -1
  95. package/package.json +2 -2
  96. package/src/factories/MetadataFactory.ts +1 -0
  97. package/src/factories/MetadataTypeTagSchemaFactory.ts +59 -59
  98. package/src/factories/ProtobufFactory.ts +1 -1
  99. package/src/factories/TypeFactory.ts +1 -1
  100. package/src/factories/internal/metadata/emplace_metadata_object.ts +10 -6
  101. package/src/factories/internal/metadata/explore_metadata.ts +28 -28
  102. package/src/factories/internal/metadata/iterate_metadata.ts +6 -0
  103. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +0 -5
  104. package/src/factories/internal/metadata/iterate_metadata_function.ts +85 -0
  105. package/src/functional/Namespace/index.ts +1 -0
  106. package/src/functional/Namespace/llm.ts +20 -0
  107. package/src/llm.ts +159 -3
  108. package/src/programmers/CheckerProgrammer.ts +1 -1
  109. package/src/programmers/RandomProgrammer.ts +1 -1
  110. package/src/programmers/functional/internal/FunctionalGeneralProgrammer.ts +3 -1
  111. package/src/programmers/internal/application_escaped.ts +74 -74
  112. package/src/programmers/internal/application_v30_object.ts +1 -1
  113. package/src/programmers/internal/application_v31_object.ts +1 -1
  114. package/src/programmers/internal/llm_schema_object.ts +1 -1
  115. package/src/programmers/internal/stringify_regular_properties.ts +4 -4
  116. package/src/programmers/json/JsonStringifyProgrammer.ts +2 -2
  117. package/src/programmers/llm/LlmApplicationProgrammer.ts +211 -0
  118. package/src/programmers/misc/MiscCloneProgrammer.ts +1 -1
  119. package/src/programmers/notations/NotationGeneralProgrammer.ts +1 -1
  120. package/src/schemas/metadata/IMetadata.ts +2 -1
  121. package/src/schemas/metadata/IMetadataFunction.ts +8 -0
  122. package/src/schemas/metadata/IMetadataParameter.ts +9 -0
  123. package/src/schemas/metadata/Metadata.ts +13 -12
  124. package/src/schemas/metadata/MetadataFunction.ts +49 -0
  125. package/src/schemas/metadata/MetadataParameter.ts +50 -0
  126. package/src/transformers/CallExpressionTransformer.ts +508 -505
  127. package/src/transformers/features/llm/LlmApplicationTransformer.ts +87 -0
  128. package/src/transformers/features/llm/LlmSchemaTransformer.ts +2 -1
  129. package/src/transformers/features/reflect/ReflectMetadataTransformer.ts +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typia",
3
- "version": "6.10.0-dev.20240906",
3
+ "version": "6.10.0-dev.20240908",
4
4
  "description": "Superfast runtime validators with only one line",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -83,7 +83,7 @@
83
83
  "@trivago/prettier-plugin-sort-imports": "^4.3.0",
84
84
  "@types/inquirer": "^8.2.5",
85
85
  "@types/node": "^18.15.12",
86
- "@types/ts-expose-internals": "npm:ts-expose-internals@5.5.3",
86
+ "@types/ts-expose-internals": "npm:ts-expose-internals@5.5.4",
87
87
  "@typescript-eslint/eslint-plugin": "^7.1.1",
88
88
  "@typescript-eslint/parser": "^7.1.1",
89
89
  "chalk": "^4.0.0",
@@ -22,6 +22,7 @@ export namespace MetadataFactory {
22
22
  escape: boolean;
23
23
  constant: boolean;
24
24
  absorb: boolean;
25
+ functional?: boolean;
25
26
  validate?: Validator;
26
27
  onError?: (node: ts.Node | undefined, message: string) => void;
27
28
  }
@@ -1,59 +1,59 @@
1
- import { Metadata } from "../schemas/metadata/Metadata";
2
- import { MetadataObject } from "../schemas/metadata/MetadataObject";
3
-
4
- export namespace MetadataTypeTagSchemaFactory {
5
- export const object =
6
- (report: (msg: string) => false) =>
7
- (obj: MetadataObject): object | undefined => {
8
- if (obj.recursive) {
9
- report(`${obj.name} has recursive type`);
10
- return undefined;
11
- }
12
- const output: any = {};
13
- for (const p of obj.properties) {
14
- const key: string | null = p.key.getSoleLiteral()!;
15
- if (key === null) {
16
- report(`${obj.name} has non-literal key type: ${p.key.getName()}`);
17
- continue;
18
- }
19
- output[key] = iterate(report)({ object: obj, key })(p.value);
20
- }
21
- return output;
22
- };
23
-
24
- const iterate =
25
- (report: (msg: string) => false) =>
26
- (parent: { object: MetadataObject; key: string }) =>
27
- (meta: Metadata): any => {
28
- if (
29
- meta.any ||
30
- meta.atomics.length ||
31
- meta.arrays.length ||
32
- meta.natives.length ||
33
- meta.functional
34
- )
35
- report(`${parent.object.name}.${parent.key} has non-literal type`);
36
- else if (meta.size() > 1)
37
- report(`${parent.object.name}.${parent.key} has union type`);
38
- else if (meta.size() === 0)
39
- if (meta.nullable) return null;
40
- else if (meta.isRequired() === true)
41
- report(`${parent.object.name}.${parent.key} has non-literal type`);
42
- else return undefined;
43
- else if (meta.constants.length)
44
- return meta.constants[0]!.values[0]!.value;
45
- else if (meta.tuples.length) {
46
- const tuple = meta.tuples[0]!;
47
- if (tuple.type.isRest())
48
- report(`${parent.object.name}.${parent.key} has rest tuple type`);
49
- else if (tuple.type.recursive)
50
- report(
51
- `${parent.object.name}.${parent.key} has recursive tuple type`,
52
- );
53
- else if (tuple.type.elements.some((e) => e.required === false))
54
- report(`${parent.object.name}.${parent.key} has optional tuple type`);
55
- return tuple.type.elements.map(iterate(report)(parent));
56
- } else if (meta.objects.length) return object(report)(meta.objects[0]!);
57
- else report(`${parent.object.name}.${parent.key} has non-literal type`);
58
- };
59
- }
1
+ import { Metadata } from "../schemas/metadata/Metadata";
2
+ import { MetadataObject } from "../schemas/metadata/MetadataObject";
3
+
4
+ export namespace MetadataTypeTagSchemaFactory {
5
+ export const object =
6
+ (report: (msg: string) => false) =>
7
+ (obj: MetadataObject): object | undefined => {
8
+ if (obj.recursive) {
9
+ report(`${obj.name} has recursive type`);
10
+ return undefined;
11
+ }
12
+ const output: any = {};
13
+ for (const p of obj.properties) {
14
+ const key: string | null = p.key.getSoleLiteral()!;
15
+ if (key === null) {
16
+ report(`${obj.name} has non-literal key type: ${p.key.getName()}`);
17
+ continue;
18
+ }
19
+ output[key] = iterate(report)({ object: obj, key })(p.value);
20
+ }
21
+ return output;
22
+ };
23
+
24
+ const iterate =
25
+ (report: (msg: string) => false) =>
26
+ (parent: { object: MetadataObject; key: string }) =>
27
+ (meta: Metadata): any => {
28
+ if (
29
+ meta.any ||
30
+ meta.atomics.length ||
31
+ meta.arrays.length ||
32
+ meta.natives.length ||
33
+ meta.functions.length
34
+ )
35
+ report(`${parent.object.name}.${parent.key} has non-literal type`);
36
+ else if (meta.size() > 1)
37
+ report(`${parent.object.name}.${parent.key} has union type`);
38
+ else if (meta.size() === 0)
39
+ if (meta.nullable) return null;
40
+ else if (meta.isRequired() === true)
41
+ report(`${parent.object.name}.${parent.key} has non-literal type`);
42
+ else return undefined;
43
+ else if (meta.constants.length)
44
+ return meta.constants[0]!.values[0]!.value;
45
+ else if (meta.tuples.length) {
46
+ const tuple = meta.tuples[0]!;
47
+ if (tuple.type.isRest())
48
+ report(`${parent.object.name}.${parent.key} has rest tuple type`);
49
+ else if (tuple.type.recursive)
50
+ report(
51
+ `${parent.object.name}.${parent.key} has recursive tuple type`,
52
+ );
53
+ else if (tuple.type.elements.some((e) => e.required === false))
54
+ report(`${parent.object.name}.${parent.key} has optional tuple type`);
55
+ return tuple.type.elements.map(iterate(report)(parent));
56
+ } else if (meta.objects.length) return object(report)(meta.objects[0]!);
57
+ else report(`${parent.object.name}.${parent.key} has non-literal type`);
58
+ };
59
+ }
@@ -62,7 +62,7 @@ export namespace ProtobufFactory {
62
62
  // PROHIBIT ANY TYPE
63
63
  if (meta.any) noSupport("any type");
64
64
  // PROHIBIT FUNCTIONAL TYPE
65
- if (meta.functional) noSupport("functional type");
65
+ if (meta.functions.length) noSupport("functional type");
66
66
  // PROHIBIT TUPLE TYPE
67
67
  if (meta.tuples.length) noSupport("tuple type");
68
68
  // PROHIBIT SET TYPE
@@ -4,7 +4,7 @@ export namespace TypeFactory {
4
4
  export const isFunction = (type: ts.Type): boolean =>
5
5
  getFunction(type) !== null;
6
6
 
7
- const getFunction = (type: ts.Type) => {
7
+ export const getFunction = (type: ts.Type) => {
8
8
  const node = type.symbol?.declarations?.[0];
9
9
  if (node === undefined) return null;
10
10
 
@@ -29,6 +29,7 @@ export const emplace_metadata_object =
29
29
 
30
30
  // PREPARE ASSETS
31
31
  const isClass: boolean = parent.isClass();
32
+ const isProperty = significant(!!options.functional);
32
33
  const pred: (node: ts.Declaration) => boolean = isClass
33
34
  ? (node) => {
34
35
  const kind: ts.SyntaxKind | undefined = node
@@ -162,12 +163,15 @@ export const emplace_metadata_object =
162
163
  return obj;
163
164
  };
164
165
 
165
- const isProperty = (node: ts.Declaration) =>
166
- ts.isParameter(node) ||
167
- ts.isPropertyDeclaration(node) ||
168
- ts.isPropertyAssignment(node) ||
169
- ts.isPropertySignature(node) ||
170
- ts.isTypeLiteralNode(node);
166
+ const significant = (functional: boolean) =>
167
+ functional
168
+ ? (node: ts.Declaration) => !ts.isAccessor(node)
169
+ : (node: ts.Declaration) =>
170
+ ts.isParameter(node) ||
171
+ ts.isPropertyDeclaration(node) ||
172
+ ts.isPropertyAssignment(node) ||
173
+ ts.isPropertySignature(node) ||
174
+ ts.isTypeLiteralNode(node);
171
175
 
172
176
  const iterate_optional_coalesce = (meta: Metadata, type: ts.Type): void => {
173
177
  if (type.isUnionOrIntersection())
@@ -1,28 +1,28 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../../schemas/metadata/Metadata";
4
-
5
- import { MetadataCollection } from "../../MetadataCollection";
6
- import { MetadataFactory } from "../../MetadataFactory";
7
- import { emend_metadata_atomics } from "./emend_metadata_atomics";
8
- import { iterate_metadata } from "./iterate_metadata";
9
-
10
- export const explore_metadata =
11
- (checker: ts.TypeChecker) =>
12
- (options: MetadataFactory.IOptions) =>
13
- (collection: MetadataCollection) =>
14
- (errors: MetadataFactory.IError[]) =>
15
- (type: ts.Type | null, explore: MetadataFactory.IExplore): Metadata => {
16
- // CONSTRUCT METADATA
17
- const meta: Metadata = Metadata.initialize(explore.escaped);
18
- if (type === null) return meta;
19
-
20
- // ITERATE TYPESCRIPT TYPES
21
- iterate_metadata(checker)(options)(collection)(errors)(meta, type, explore);
22
- emend_metadata_atomics(meta);
23
- if (meta.escaped) {
24
- emend_metadata_atomics(meta.escaped.original);
25
- emend_metadata_atomics(meta.escaped.returns);
26
- }
27
- return meta;
28
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../../schemas/metadata/Metadata";
4
+
5
+ import { MetadataCollection } from "../../MetadataCollection";
6
+ import { MetadataFactory } from "../../MetadataFactory";
7
+ import { emend_metadata_atomics } from "./emend_metadata_atomics";
8
+ import { iterate_metadata } from "./iterate_metadata";
9
+
10
+ export const explore_metadata =
11
+ (checker: ts.TypeChecker) =>
12
+ (options: MetadataFactory.IOptions) =>
13
+ (collection: MetadataCollection) =>
14
+ (errors: MetadataFactory.IError[]) =>
15
+ (type: ts.Type | null, explore: MetadataFactory.IExplore): Metadata => {
16
+ // CONSTRUCT METADATA
17
+ const meta: Metadata = Metadata.initialize(explore.escaped);
18
+ if (type === null) return meta;
19
+
20
+ // ITERATE TYPESCRIPT TYPES
21
+ iterate_metadata(checker)(options)(collection)(errors)(meta, type, explore);
22
+ emend_metadata_atomics(meta);
23
+ if (meta.escaped) {
24
+ emend_metadata_atomics(meta.escaped.original);
25
+ emend_metadata_atomics(meta.escaped.returns);
26
+ }
27
+ return meta;
28
+ };
@@ -11,6 +11,7 @@ import { iterate_metadata_atomic } from "./iterate_metadata_atomic";
11
11
  import { iterate_metadata_coalesce } from "./iterate_metadata_coalesce";
12
12
  import { iterate_metadata_constant } from "./iterate_metadata_constant";
13
13
  import { iterate_metadata_escape } from "./iterate_metadata_escape";
14
+ import { iterate_metadata_function } from "./iterate_metadata_function";
14
15
  import { iterate_metadata_intersection } from "./iterate_metadata_intersection";
15
16
  import { iterate_metadata_map } from "./iterate_metadata_map";
16
17
  import { iterate_metadata_native } from "./iterate_metadata_native";
@@ -62,6 +63,11 @@ export const iterate_metadata =
62
63
 
63
64
  // ITERATE CASES
64
65
  iterate_metadata_coalesce(meta, type) ||
66
+ iterate_metadata_function(checker)(options)(collection)(errors)(
67
+ meta,
68
+ type,
69
+ explore,
70
+ ) ||
65
71
  iterate_metadata_constant(checker)(options)(meta, type) ||
66
72
  iterate_metadata_template(checker)(options)(collection)(errors)(
67
73
  meta,
@@ -4,8 +4,6 @@ import { Metadata } from "../../../schemas/metadata/Metadata";
4
4
 
5
5
  import { Writable } from "../../../typings/Writable";
6
6
 
7
- import { TypeFactory } from "../../TypeFactory";
8
-
9
7
  export const iterate_metadata_coalesce = (
10
8
  meta: Metadata,
11
9
  type: ts.Type,
@@ -25,9 +23,6 @@ export const iterate_metadata_coalesce = (
25
23
  ) {
26
24
  Writable(meta).required = false;
27
25
  return true;
28
- } else if (TypeFactory.isFunction(type) === true) {
29
- Writable(meta).functional = true;
30
- return true;
31
26
  }
32
27
  return false;
33
28
  };
@@ -0,0 +1,85 @@
1
+ import ts from "typescript";
2
+
3
+ import { FunctionalGeneralProgrammer } from "../../../programmers/functional/internal/FunctionalGeneralProgrammer";
4
+
5
+ import { Metadata } from "../../../schemas/metadata/Metadata";
6
+ import { MetadataFunction } from "../../../schemas/metadata/MetadataFunction";
7
+ import { MetadataParameter } from "../../../schemas/metadata/MetadataParameter";
8
+
9
+ import { CommentFactory } from "../../CommentFactory";
10
+ import { MetadataCollection } from "../../MetadataCollection";
11
+ import { MetadataFactory } from "../../MetadataFactory";
12
+ import { TypeFactory } from "../../TypeFactory";
13
+ import { explore_metadata } from "./explore_metadata";
14
+
15
+ export const iterate_metadata_function =
16
+ (checker: ts.TypeChecker) =>
17
+ (options: MetadataFactory.IOptions) =>
18
+ (collection: MetadataCollection) =>
19
+ (errors: MetadataFactory.IError[]) =>
20
+ (
21
+ metadata: Metadata,
22
+ type: ts.Type,
23
+ explore: MetadataFactory.IExplore,
24
+ ): boolean => {
25
+ const declaration: ts.SignatureDeclaration | null =
26
+ TypeFactory.getFunction(type);
27
+ if (declaration === null) return false;
28
+ else if (!options.functional) {
29
+ if (metadata.functions.length === 0)
30
+ metadata.functions.push(
31
+ MetadataFunction.create({
32
+ parameters: [],
33
+ output: Metadata.initialize(),
34
+ async: false,
35
+ }),
36
+ );
37
+ } else {
38
+ const [signature] = type.getCallSignatures();
39
+ if (signature === undefined || signature.declaration === undefined)
40
+ metadata.functions.push(
41
+ MetadataFunction.create({
42
+ parameters: [],
43
+ output: Metadata.initialize(),
44
+ async: false,
45
+ }),
46
+ );
47
+ else {
48
+ const { async }: FunctionalGeneralProgrammer.IOutput =
49
+ FunctionalGeneralProgrammer.getReturnType(checker)(declaration);
50
+ metadata.functions.push(
51
+ MetadataFunction.create({
52
+ parameters: signature.parameters.map((p) =>
53
+ MetadataParameter.create({
54
+ name: p.name,
55
+ type: explore_metadata(checker)(options)(collection)(errors)(
56
+ checker.getTypeOfSymbol(p),
57
+ {
58
+ ...explore,
59
+ top: false,
60
+ },
61
+ ),
62
+ description: CommentFactory.description(p) ?? null,
63
+ jsDocTags: p?.getJsDocTags() ?? [],
64
+ }),
65
+ ),
66
+ async,
67
+ output: explore_metadata(checker)({
68
+ ...options,
69
+ functional: false,
70
+ })(collection)(errors)(
71
+ async
72
+ ? (signature.getReturnType().aliasTypeArguments?.[0] ??
73
+ checker.getTypeFromTypeNode(TypeFactory.keyword("any")))
74
+ : signature.getReturnType(),
75
+ {
76
+ ...explore,
77
+ top: false,
78
+ },
79
+ ),
80
+ }),
81
+ );
82
+ }
83
+ }
84
+ return true;
85
+ };
@@ -14,6 +14,7 @@ export * as http from "./http";
14
14
  export * as notations from "./notations";
15
15
  export * as misc from "./misc";
16
16
  export * as protobuf from "./protobuf";
17
+ export * as llm from "./llm";
17
18
 
18
19
  export { is };
19
20
 
@@ -0,0 +1,20 @@
1
+ import { ILlmApplication } from "@samchon/openapi";
2
+
3
+ import { LlmSchemaSeparator } from "@samchon/openapi/lib/utils/LlmSchemaSeparator";
4
+
5
+ export const application = () => ({
6
+ finalize: (
7
+ app: ILlmApplication,
8
+ options?: ILlmApplication.IOptions,
9
+ ): void => {
10
+ app.options = {
11
+ separate: options?.separate ?? null,
12
+ };
13
+ if (app.options.separate === null) return;
14
+ for (const func of app.functions)
15
+ func.separated = LlmSchemaSeparator.parameters({
16
+ parameters: func.parameters,
17
+ predicator: app.options.separate,
18
+ });
19
+ },
20
+ });
package/src/llm.ts CHANGED
@@ -1,16 +1,172 @@
1
1
  import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
2
2
 
3
- export function application(): never;
4
- export function application<T extends object>(): ILlmApplication;
3
+ import * as Namespace from "./functional/Namespace";
4
+
5
+ /**
6
+ * > You must configure the generic argument `App`.
7
+ *
8
+ * TypeScript functions to LLM function schemas.
9
+ *
10
+ * Creates an application of LLM (Large Language Model) function calling schemas from
11
+ * a TypeScript class or interface type containig the target functions to be called by
12
+ * the LLM function calling feature.
13
+ *
14
+ * If you put the returned {@link ILlmApplication.functions} objects to the LLM provider
15
+ * like [OpenAI (ChatGPT)](https://openai.com/), the LLM will automatically select the
16
+ * proper function and fill its arguments from the conversation (maybe chatting text)
17
+ * with user (human). This is the concept of the LLM function calling.
18
+ *
19
+ * By the way, there can be some parameters (or their nested properties) which must be
20
+ * composed by human, not by LLM. File uploading feature or some sensitive information
21
+ * like secrety key (password) are the examples. In that case, you can separate the
22
+ * function parameters to both LLM and human sides by configuring the
23
+ * {@link ILlmApplication.IOptions.separate} property. The separated parameters are
24
+ * assigned to the {@link ILlmFunction.separated} property.
25
+ *
26
+ * For reference, the actual function call execution is not by LLM, but by you.
27
+ * When the LLM selects the proper function and fills the arguments, you just call
28
+ * the function with the LLM prepared arguments. And then informs the return value to
29
+ * the LLM by system prompt. The LLM will continue the next conversation based on
30
+ * the return value.
31
+ *
32
+ * Additionally, if you've configured {@link ILlmApplication.IOptions.separate},
33
+ * so that the parameters are separated to human and LLM sides, you can merge these
34
+ * humand and LLM sides' parameters into one through {@link HttpLlm.mergeParameters}
35
+ * before the actual LLM function call execution.
36
+ *
37
+ * @template App Target class or interface type collecting the functions to call
38
+ * @param options Options for the LLM application construction
39
+ * @returns Application of LLM function calling schemas
40
+ * @reference https://platform.openai.com/docs/guides/function-calling
41
+ * @author Jeongho Nam - https://github.com/samchon
42
+ */
43
+ function application(options?: ILlmApplication.IOptions): never;
44
+
45
+ /**
46
+ * TypeScript functions to LLM function schemas.
47
+ *
48
+ * Creates an application of LLM (Large Language Model) function calling schemas from
49
+ * a TypeScript class or interface type containig the target functions to be called by
50
+ * the LLM function calling feature.
51
+ *
52
+ * If you put the returned {@link ILlmApplication.functions} objects to the LLM provider
53
+ * like [OpenAI (ChatGPT)](https://openai.com/), the LLM will automatically select the
54
+ * proper function and fill its arguments from the conversation (maybe chatting text)
55
+ * with user (human). This is the concept of the LLM function calling.
56
+ *
57
+ * By the way, there can be some parameters (or their nested properties) which must be
58
+ * composed by human, not by LLM. File uploading feature or some sensitive information
59
+ * like secrety key (password) are the examples. In that case, you can separate the
60
+ * function parameters to both LLM and human sides by configuring the
61
+ * {@link ILlmApplication.IOptions.separate} property. The separated parameters are
62
+ * assigned to the {@link ILlmFunction.separated} property.
63
+ *
64
+ * For reference, the actual function call execution is not by LLM, but by you.
65
+ * When the LLM selects the proper function and fills the arguments, you just call
66
+ * the function with the LLM prepared arguments. And then informs the return value to
67
+ * the LLM by system prompt. The LLM will continue the next conversation based on
68
+ * the return value.
69
+ *
70
+ * Additionally, if you've configured {@link ILlmApplication.IOptions.separate},
71
+ * so that the parameters are separated to human and LLM sides, you can merge these
72
+ * humand and LLM sides' parameters into one through {@link HttpLlm.mergeParameters}
73
+ * before the actual LLM function call execution.
74
+ *
75
+ * @template App Target class or interface type collecting the functions to call
76
+ * @param options Options for the LLM application construction
77
+ * @returns Application of LLM function calling schemas
78
+ * @reference https://platform.openai.com/docs/guides/function-calling
79
+ * @author Jeongho Nam - https://github.com/samchon
80
+ */
81
+ function application<App extends object>(
82
+ options?: ILlmApplication.IOptions,
83
+ ): ILlmApplication;
5
84
 
6
85
  /**
7
86
  * @internal
8
87
  */
9
- export function application(): never {
88
+ function application(): never {
10
89
  halt("application");
11
90
  }
12
91
 
92
+ const applicationPure = /** @__PURE__ */ Object.assign<typeof application, {}>(
93
+ application,
94
+ /** @__PURE__ */ Namespace.llm.application(),
95
+ );
96
+ export { applicationPure as application };
97
+
98
+ /**
99
+ * > You must configure the generic argument `T`.
100
+ *
101
+ * TypeScript type to LLM type schema.
102
+ *
103
+ * Creates an LLM (Large Language Model) type schema, a type metadata that is used in the
104
+ * [LLM function calling](@reference https://platform.openai.com/docs/guides/function-calling),
105
+ * from a TypeScript type.
106
+ *
107
+ * The returned {@link ILlmSchema} type is similar to the OpenAPI v3.0 based JSON schema
108
+ * definition, but it is more simplified for the LLM function calling by remmoving the
109
+ * {@link OpenApiV3.IJson.IReference reference} type embodied by the
110
+ * {@link OpenApiV3.IJson.IReference.$ref `$ref`} proeprty.
111
+ *
112
+ * If you actually want to perform the LLM function calling with TypeScript functions,
113
+ * you can do it with the {@link application} function. Let's enjoy the
114
+ * LLM function calling with native TypeScript functions and types.
115
+ *
116
+ * > **What LLM function calling is?
117
+ * >
118
+ * > LLM (Large Language Model) selects propert function and fill the arguments,
119
+ * > but actuall function call execution is not by LLM, but by you.
120
+ * >
121
+ * > In nowadays, most LLM (Large Language Model) like OpenAI are supporting
122
+ * > "function calling" feature. The "function calling" means that LLM automatically selects
123
+ * > a proper function and compose parameter values from the user's chatting text.
124
+ * >
125
+ * > When LLM selects the proper function and its arguments, you just call the function
126
+ * > with the arguments. And then informs the return value to the LLM by system prompt,
127
+ * > LLM will continue the next conversation based on the return value.
128
+ *
129
+ * @template T Target type
130
+ * @returns LLM schema
131
+ * @reference https://platform.openai.com/docs/guides/function-calling
132
+ * @author Jeongho Nam - https://github.com/samchon
133
+ */
13
134
  export function schema(): never;
135
+
136
+ /**
137
+ * TypeScript type to LLM type schema.
138
+ *
139
+ * Creates an LLM (Large Language Model) type schema, a type metadata that is used in the
140
+ * [LLM function calling](@reference https://platform.openai.com/docs/guides/function-calling),
141
+ * from a TypeScript type.
142
+ *
143
+ * The returned {@link ILlmSchema} type is similar to the OpenAPI v3.0 based JSON schema
144
+ * definition, but it is more simplified for the LLM function calling by remmoving the
145
+ * {@link OpenApiV3.IJson.IReference reference} type embodied by the
146
+ * {@link OpenApiV3.IJson.IReference.$ref `$ref`} proeprty.
147
+ *
148
+ * If you actually want to perform the LLM function calling with TypeScript functions,
149
+ * you can do it with the {@link application} function. Let's enjoy the
150
+ * LLM function calling with native TypeScript functions and types.
151
+ *
152
+ * > **What LLM function calling is?
153
+ * >
154
+ * > LLM (Large Language Model) selects propert function and fill the arguments,
155
+ * > but actuall function call execution is not by LLM, but by you.
156
+ * >
157
+ * > In nowadays, most LLM (Large Language Model) like OpenAI are supporting
158
+ * > "function calling" feature. The "function calling" means that LLM automatically selects
159
+ * > a proper function and compose parameter values from the user's chatting text.
160
+ * >
161
+ * > When LLM selects the proper function and its arguments, you just call the function
162
+ * > with the arguments. And then informs the return value to the LLM by system prompt,
163
+ * > LLM will continue the next conversation based on the return value.
164
+ *
165
+ * @template T Target type
166
+ * @returns LLM schema
167
+ * @reference https://platform.openai.com/docs/guides/function-calling
168
+ * @author Jeongho Nam - https://github.com/samchon
169
+ */
14
170
  export function schema<T>(): ILlmSchema;
15
171
 
16
172
  /**
@@ -331,7 +331,7 @@ export namespace CheckerProgrammer {
331
331
  );
332
332
 
333
333
  // FUNCTIONAL
334
- if (meta.functional === true)
334
+ if (meta.functions.length)
335
335
  if (OptionPredicator.functional(project.options) || meta.size() !== 1)
336
336
  add(
337
337
  true,
@@ -276,7 +276,7 @@ export namespace RandomProgrammer {
276
276
  expressions.push(ts.factory.createStringLiteral("any type used..."));
277
277
 
278
278
  // NULL COALESCING
279
- if (meta.isRequired() === false || meta.functional === true)
279
+ if (meta.isRequired() === false || meta.functions.length)
280
280
  expressions.push(ts.factory.createIdentifier("undefined"));
281
281
  if (meta.nullable === true) expressions.push(ts.factory.createNull());
282
282
 
@@ -9,7 +9,9 @@ export namespace FunctionalGeneralProgrammer {
9
9
  }
10
10
  export const getReturnType =
11
11
  (checker: ts.TypeChecker) =>
12
- (declaration: ts.FunctionDeclaration): IOutput => {
12
+ (
13
+ declaration: ts.FunctionDeclaration | ts.SignatureDeclaration,
14
+ ): IOutput => {
13
15
  const signature: ts.Signature | undefined =
14
16
  checker.getSignatureFromDeclaration(declaration);
15
17
  const type: ts.Type =