@typia/utils 12.0.0-dev.20260309 → 12.0.0-dev.20260311
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/converters/LlmSchemaConverter.d.ts +0 -1
- package/lib/converters/LlmSchemaConverter.js +4 -31
- package/lib/converters/LlmSchemaConverter.js.map +1 -1
- package/lib/converters/LlmSchemaConverter.mjs +2 -32
- package/lib/converters/LlmSchemaConverter.mjs.map +1 -1
- package/lib/http/HttpLlm.js +4 -5
- package/lib/http/HttpLlm.js.map +1 -1
- package/lib/http/HttpLlm.mjs +0 -1
- package/lib/http/HttpLlm.mjs.map +1 -1
- package/lib/http/internal/HttpLlmApplicationComposer.js +3 -4
- package/lib/http/internal/HttpLlmApplicationComposer.js.map +1 -1
- package/lib/http/internal/HttpLlmApplicationComposer.mjs +5 -2
- package/lib/http/internal/HttpLlmApplicationComposer.mjs.map +1 -1
- package/lib/index.mjs +9 -9
- package/lib/utils/LlmJson.mjs +9 -2
- package/lib/utils/LlmJson.mjs.map +1 -1
- package/lib/utils/internal/stringifyValidationFailure.js +17 -15
- package/lib/utils/internal/stringifyValidationFailure.js.map +1 -1
- package/lib/utils/internal/stringifyValidationFailure.mjs +17 -15
- package/lib/utils/internal/stringifyValidationFailure.mjs.map +1 -1
- package/lib/validators/internal/OpenApiOneOfValidator.mjs +5 -1
- package/lib/validators/internal/OpenApiOneOfValidator.mjs.map +1 -1
- package/package.json +2 -2
- package/src/converters/LlmSchemaConverter.ts +617 -647
- package/src/converters/OpenApiConverter.ts +285 -285
- package/src/converters/index.ts +5 -5
- package/src/converters/internal/LlmDescriptionInverter.ts +178 -178
- package/src/converters/internal/LlmParametersComposer.ts +52 -52
- package/src/converters/internal/OpenApiConstraintShifter.ts +154 -154
- package/src/converters/internal/OpenApiExclusiveEmender.ts +46 -46
- package/src/converters/internal/OpenApiV3Downgrader.ts +355 -355
- package/src/converters/internal/OpenApiV3Upgrader.ts +470 -470
- package/src/converters/internal/OpenApiV3_1Upgrader.ts +685 -685
- package/src/converters/internal/SwaggerV2Downgrader.ts +424 -424
- package/src/converters/internal/SwaggerV2Upgrader.ts +523 -523
- package/src/http/HttpError.ts +107 -107
- package/src/http/HttpLlm.ts +166 -167
- package/src/http/HttpMigration.ts +92 -92
- package/src/http/index.ts +3 -3
- package/src/http/internal/HttpLlmApplicationComposer.ts +360 -361
- package/src/http/internal/HttpLlmFunctionFetcher.ts +37 -37
- package/src/http/internal/HttpMigrateApplicationComposer.ts +56 -56
- package/src/http/internal/HttpMigrateRouteAccessor.ts +135 -135
- package/src/http/internal/HttpMigrateRouteComposer.ts +505 -505
- package/src/http/internal/HttpMigrateRouteFetcher.ts +203 -203
- package/src/index.ts +4 -4
- package/src/utils/ArrayUtil.ts +42 -42
- package/src/utils/LlmJson.ts +141 -141
- package/src/utils/MapUtil.ts +15 -15
- package/src/utils/NamingConvention.ts +205 -205
- package/src/utils/Singleton.ts +17 -17
- package/src/utils/StringUtil.ts +14 -14
- package/src/utils/dedent.ts +57 -57
- package/src/utils/index.ts +8 -8
- package/src/utils/internal/EndpointUtil.ts +44 -44
- package/src/utils/internal/JsonDescriptor.ts +70 -70
- package/src/utils/internal/OpenApiTypeCheckerBase.ts +822 -822
- package/src/utils/internal/coerceLlmArguments.ts +314 -314
- package/src/utils/internal/parseLenientJson.ts +894 -894
- package/src/utils/internal/stringifyValidationFailure.ts +415 -411
- package/src/validators/LlmTypeChecker.ts +402 -402
- package/src/validators/OpenApiTypeChecker.ts +297 -297
- package/src/validators/OpenApiV3TypeChecker.ts +70 -70
- package/src/validators/OpenApiV3_1TypeChecker.ts +86 -86
- package/src/validators/OpenApiValidator.ts +94 -94
- package/src/validators/SwaggerV2TypeChecker.ts +71 -71
- package/src/validators/functional/_isBigintString.ts +8 -8
- package/src/validators/functional/_isFormatByte.ts +7 -7
- package/src/validators/functional/_isFormatDate.ts +3 -3
- package/src/validators/functional/_isFormatDateTime.ts +4 -4
- package/src/validators/functional/_isFormatDuration.ts +4 -4
- package/src/validators/functional/_isFormatEmail.ts +4 -4
- package/src/validators/functional/_isFormatHostname.ts +4 -4
- package/src/validators/functional/_isFormatIdnEmail.ts +4 -4
- package/src/validators/functional/_isFormatIdnHostname.ts +4 -4
- package/src/validators/functional/_isFormatIpv4.ts +4 -4
- package/src/validators/functional/_isFormatIpv6.ts +4 -4
- package/src/validators/functional/_isFormatIri.ts +3 -3
- package/src/validators/functional/_isFormatIriReference.ts +4 -4
- package/src/validators/functional/_isFormatJsonPointer.ts +3 -3
- package/src/validators/functional/_isFormatPassword.ts +1 -1
- package/src/validators/functional/_isFormatRegex.ts +8 -8
- package/src/validators/functional/_isFormatRelativeJsonPointer.ts +4 -4
- package/src/validators/functional/_isFormatTime.ts +4 -4
- package/src/validators/functional/_isFormatUri.ts +6 -6
- package/src/validators/functional/_isFormatUriReference.ts +5 -5
- package/src/validators/functional/_isFormatUriTemplate.ts +4 -4
- package/src/validators/functional/_isFormatUrl.ts +4 -4
- package/src/validators/functional/_isFormatUuid.ts +3 -3
- package/src/validators/functional/_isUniqueItems.ts +159 -159
- package/src/validators/index.ts +14 -14
- package/src/validators/internal/IOpenApiValidatorContext.ts +17 -17
- package/src/validators/internal/OpenApiArrayValidator.ts +49 -49
- package/src/validators/internal/OpenApiBooleanValidator.ts +11 -11
- package/src/validators/internal/OpenApiConstantValidator.ts +11 -11
- package/src/validators/internal/OpenApiIntegerValidator.ts +49 -49
- package/src/validators/internal/OpenApiNumberValidator.ts +48 -48
- package/src/validators/internal/OpenApiObjectValidator.ts +83 -83
- package/src/validators/internal/OpenApiOneOfValidator.ts +309 -309
- package/src/validators/internal/OpenApiSchemaNamingRule.ts +124 -124
- package/src/validators/internal/OpenApiStationValidator.ts +115 -115
- package/src/validators/internal/OpenApiStringValidator.ts +88 -88
- package/src/validators/internal/OpenApiTupleValidator.ts +55 -55
|
@@ -1,178 +1,178 @@
|
|
|
1
|
-
import { OpenApi } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
import { OpenApiExclusiveEmender } from "./OpenApiExclusiveEmender";
|
|
4
|
-
|
|
5
|
-
export namespace LlmDescriptionInverter {
|
|
6
|
-
export const numeric = (
|
|
7
|
-
description: string | undefined,
|
|
8
|
-
): Pick<
|
|
9
|
-
OpenApi.IJsonSchema.INumber,
|
|
10
|
-
| "minimum"
|
|
11
|
-
| "maximum"
|
|
12
|
-
| "exclusiveMinimum"
|
|
13
|
-
| "exclusiveMaximum"
|
|
14
|
-
| "multipleOf"
|
|
15
|
-
| "description"
|
|
16
|
-
> => {
|
|
17
|
-
if (description === undefined) return {};
|
|
18
|
-
|
|
19
|
-
const lines: string[] = description.split("\n");
|
|
20
|
-
return OpenApiExclusiveEmender.emend({
|
|
21
|
-
minimum: find({
|
|
22
|
-
type: "number",
|
|
23
|
-
name: "minimum",
|
|
24
|
-
lines,
|
|
25
|
-
}),
|
|
26
|
-
maximum: find({
|
|
27
|
-
type: "number",
|
|
28
|
-
name: "maximum",
|
|
29
|
-
lines,
|
|
30
|
-
}),
|
|
31
|
-
exclusiveMinimum: find({
|
|
32
|
-
type: "number",
|
|
33
|
-
name: "exclusiveMinimum",
|
|
34
|
-
lines,
|
|
35
|
-
}),
|
|
36
|
-
exclusiveMaximum: find({
|
|
37
|
-
type: "number",
|
|
38
|
-
name: "exclusiveMaximum",
|
|
39
|
-
lines,
|
|
40
|
-
}),
|
|
41
|
-
multipleOf: find({
|
|
42
|
-
type: "number",
|
|
43
|
-
name: "multipleOf",
|
|
44
|
-
lines,
|
|
45
|
-
}),
|
|
46
|
-
description: describe(lines, [
|
|
47
|
-
"minimum",
|
|
48
|
-
"maximum",
|
|
49
|
-
"exclusiveMinimum",
|
|
50
|
-
"exclusiveMaximum",
|
|
51
|
-
"multipleOf",
|
|
52
|
-
]),
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const string = (
|
|
57
|
-
description: string | undefined,
|
|
58
|
-
): Pick<
|
|
59
|
-
OpenApi.IJsonSchema.IString,
|
|
60
|
-
| "format"
|
|
61
|
-
| "pattern"
|
|
62
|
-
| "contentMediaType"
|
|
63
|
-
| "minLength"
|
|
64
|
-
| "maxLength"
|
|
65
|
-
| "description"
|
|
66
|
-
> => {
|
|
67
|
-
if (description === undefined) return {};
|
|
68
|
-
|
|
69
|
-
const lines: string[] = description.split("\n");
|
|
70
|
-
return {
|
|
71
|
-
format: find({
|
|
72
|
-
type: "string",
|
|
73
|
-
name: "format",
|
|
74
|
-
lines,
|
|
75
|
-
}),
|
|
76
|
-
pattern: find({
|
|
77
|
-
type: "string",
|
|
78
|
-
name: "pattern",
|
|
79
|
-
lines,
|
|
80
|
-
}),
|
|
81
|
-
contentMediaType: find({
|
|
82
|
-
type: "string",
|
|
83
|
-
name: "contentMediaType",
|
|
84
|
-
lines,
|
|
85
|
-
}),
|
|
86
|
-
minLength: find({
|
|
87
|
-
type: "number",
|
|
88
|
-
name: "minLength",
|
|
89
|
-
lines,
|
|
90
|
-
}),
|
|
91
|
-
maxLength: find({
|
|
92
|
-
type: "number",
|
|
93
|
-
name: "maxLength",
|
|
94
|
-
lines,
|
|
95
|
-
}),
|
|
96
|
-
description: describe(lines, [
|
|
97
|
-
"format",
|
|
98
|
-
"pattern",
|
|
99
|
-
"contentMediaType",
|
|
100
|
-
"minLength",
|
|
101
|
-
"maxLength",
|
|
102
|
-
]),
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export const array = (
|
|
107
|
-
description: string | undefined,
|
|
108
|
-
): Pick<
|
|
109
|
-
OpenApi.IJsonSchema.IArray,
|
|
110
|
-
"minItems" | "maxItems" | "uniqueItems" | "description"
|
|
111
|
-
> => {
|
|
112
|
-
if (description === undefined) return {};
|
|
113
|
-
|
|
114
|
-
const lines: string[] = description.split("\n");
|
|
115
|
-
return {
|
|
116
|
-
minItems: find({
|
|
117
|
-
type: "number",
|
|
118
|
-
name: "minItems",
|
|
119
|
-
lines,
|
|
120
|
-
}),
|
|
121
|
-
maxItems: find({
|
|
122
|
-
type: "number",
|
|
123
|
-
name: "maxItems",
|
|
124
|
-
lines,
|
|
125
|
-
}),
|
|
126
|
-
uniqueItems: find({
|
|
127
|
-
type: "boolean",
|
|
128
|
-
name: "uniqueItems",
|
|
129
|
-
lines,
|
|
130
|
-
}),
|
|
131
|
-
description: describe(lines, ["minItems", "maxItems", "uniqueItems"]),
|
|
132
|
-
};
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const find = <Type extends "boolean" | "number" | "string">(props: {
|
|
136
|
-
type: Type;
|
|
137
|
-
name: string;
|
|
138
|
-
lines: string[];
|
|
139
|
-
}):
|
|
140
|
-
| (Type extends "boolean" ? true : Type extends "number" ? number : string)
|
|
141
|
-
| undefined => {
|
|
142
|
-
if (props.type === "boolean")
|
|
143
|
-
return props.lines.some((line) => line.startsWith(`@${props.name}`))
|
|
144
|
-
? (true as any)
|
|
145
|
-
: (undefined as any);
|
|
146
|
-
for (const line of props.lines) {
|
|
147
|
-
if (line.startsWith(`@${props.name} `) === false) continue;
|
|
148
|
-
const value: string = line.replace(`@${props.name} `, "").trim();
|
|
149
|
-
if (props.type === "number")
|
|
150
|
-
return (isNaN(Number(value)) ? undefined : Number(value)) satisfies
|
|
151
|
-
| number
|
|
152
|
-
| undefined as any;
|
|
153
|
-
return value as any;
|
|
154
|
-
}
|
|
155
|
-
return undefined as any;
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
const describe = (lines: string[], tags: string[]): string | undefined => {
|
|
159
|
-
const ret: string = trimArray(
|
|
160
|
-
lines
|
|
161
|
-
.map((str) => str.trim())
|
|
162
|
-
.filter((str) =>
|
|
163
|
-
tags.every((tag) => str.startsWith(`@${tag}`) === false),
|
|
164
|
-
),
|
|
165
|
-
).join("\n");
|
|
166
|
-
return ret.length === 0 ? undefined : ret;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
const trimArray = (array: string[]): string[] => {
|
|
170
|
-
let first: number = 0;
|
|
171
|
-
let last: number = array.length - 1;
|
|
172
|
-
|
|
173
|
-
for (; first < array.length; ++first)
|
|
174
|
-
if (array[first]!.trim().length !== 0) break;
|
|
175
|
-
for (; last >= 0; --last) if (array[last]!.trim().length !== 0) break;
|
|
176
|
-
return array.slice(first, last + 1);
|
|
177
|
-
};
|
|
178
|
-
}
|
|
1
|
+
import { OpenApi } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
import { OpenApiExclusiveEmender } from "./OpenApiExclusiveEmender";
|
|
4
|
+
|
|
5
|
+
export namespace LlmDescriptionInverter {
|
|
6
|
+
export const numeric = (
|
|
7
|
+
description: string | undefined,
|
|
8
|
+
): Pick<
|
|
9
|
+
OpenApi.IJsonSchema.INumber,
|
|
10
|
+
| "minimum"
|
|
11
|
+
| "maximum"
|
|
12
|
+
| "exclusiveMinimum"
|
|
13
|
+
| "exclusiveMaximum"
|
|
14
|
+
| "multipleOf"
|
|
15
|
+
| "description"
|
|
16
|
+
> => {
|
|
17
|
+
if (description === undefined) return {};
|
|
18
|
+
|
|
19
|
+
const lines: string[] = description.split("\n");
|
|
20
|
+
return OpenApiExclusiveEmender.emend({
|
|
21
|
+
minimum: find({
|
|
22
|
+
type: "number",
|
|
23
|
+
name: "minimum",
|
|
24
|
+
lines,
|
|
25
|
+
}),
|
|
26
|
+
maximum: find({
|
|
27
|
+
type: "number",
|
|
28
|
+
name: "maximum",
|
|
29
|
+
lines,
|
|
30
|
+
}),
|
|
31
|
+
exclusiveMinimum: find({
|
|
32
|
+
type: "number",
|
|
33
|
+
name: "exclusiveMinimum",
|
|
34
|
+
lines,
|
|
35
|
+
}),
|
|
36
|
+
exclusiveMaximum: find({
|
|
37
|
+
type: "number",
|
|
38
|
+
name: "exclusiveMaximum",
|
|
39
|
+
lines,
|
|
40
|
+
}),
|
|
41
|
+
multipleOf: find({
|
|
42
|
+
type: "number",
|
|
43
|
+
name: "multipleOf",
|
|
44
|
+
lines,
|
|
45
|
+
}),
|
|
46
|
+
description: describe(lines, [
|
|
47
|
+
"minimum",
|
|
48
|
+
"maximum",
|
|
49
|
+
"exclusiveMinimum",
|
|
50
|
+
"exclusiveMaximum",
|
|
51
|
+
"multipleOf",
|
|
52
|
+
]),
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const string = (
|
|
57
|
+
description: string | undefined,
|
|
58
|
+
): Pick<
|
|
59
|
+
OpenApi.IJsonSchema.IString,
|
|
60
|
+
| "format"
|
|
61
|
+
| "pattern"
|
|
62
|
+
| "contentMediaType"
|
|
63
|
+
| "minLength"
|
|
64
|
+
| "maxLength"
|
|
65
|
+
| "description"
|
|
66
|
+
> => {
|
|
67
|
+
if (description === undefined) return {};
|
|
68
|
+
|
|
69
|
+
const lines: string[] = description.split("\n");
|
|
70
|
+
return {
|
|
71
|
+
format: find({
|
|
72
|
+
type: "string",
|
|
73
|
+
name: "format",
|
|
74
|
+
lines,
|
|
75
|
+
}),
|
|
76
|
+
pattern: find({
|
|
77
|
+
type: "string",
|
|
78
|
+
name: "pattern",
|
|
79
|
+
lines,
|
|
80
|
+
}),
|
|
81
|
+
contentMediaType: find({
|
|
82
|
+
type: "string",
|
|
83
|
+
name: "contentMediaType",
|
|
84
|
+
lines,
|
|
85
|
+
}),
|
|
86
|
+
minLength: find({
|
|
87
|
+
type: "number",
|
|
88
|
+
name: "minLength",
|
|
89
|
+
lines,
|
|
90
|
+
}),
|
|
91
|
+
maxLength: find({
|
|
92
|
+
type: "number",
|
|
93
|
+
name: "maxLength",
|
|
94
|
+
lines,
|
|
95
|
+
}),
|
|
96
|
+
description: describe(lines, [
|
|
97
|
+
"format",
|
|
98
|
+
"pattern",
|
|
99
|
+
"contentMediaType",
|
|
100
|
+
"minLength",
|
|
101
|
+
"maxLength",
|
|
102
|
+
]),
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const array = (
|
|
107
|
+
description: string | undefined,
|
|
108
|
+
): Pick<
|
|
109
|
+
OpenApi.IJsonSchema.IArray,
|
|
110
|
+
"minItems" | "maxItems" | "uniqueItems" | "description"
|
|
111
|
+
> => {
|
|
112
|
+
if (description === undefined) return {};
|
|
113
|
+
|
|
114
|
+
const lines: string[] = description.split("\n");
|
|
115
|
+
return {
|
|
116
|
+
minItems: find({
|
|
117
|
+
type: "number",
|
|
118
|
+
name: "minItems",
|
|
119
|
+
lines,
|
|
120
|
+
}),
|
|
121
|
+
maxItems: find({
|
|
122
|
+
type: "number",
|
|
123
|
+
name: "maxItems",
|
|
124
|
+
lines,
|
|
125
|
+
}),
|
|
126
|
+
uniqueItems: find({
|
|
127
|
+
type: "boolean",
|
|
128
|
+
name: "uniqueItems",
|
|
129
|
+
lines,
|
|
130
|
+
}),
|
|
131
|
+
description: describe(lines, ["minItems", "maxItems", "uniqueItems"]),
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const find = <Type extends "boolean" | "number" | "string">(props: {
|
|
136
|
+
type: Type;
|
|
137
|
+
name: string;
|
|
138
|
+
lines: string[];
|
|
139
|
+
}):
|
|
140
|
+
| (Type extends "boolean" ? true : Type extends "number" ? number : string)
|
|
141
|
+
| undefined => {
|
|
142
|
+
if (props.type === "boolean")
|
|
143
|
+
return props.lines.some((line) => line.startsWith(`@${props.name}`))
|
|
144
|
+
? (true as any)
|
|
145
|
+
: (undefined as any);
|
|
146
|
+
for (const line of props.lines) {
|
|
147
|
+
if (line.startsWith(`@${props.name} `) === false) continue;
|
|
148
|
+
const value: string = line.replace(`@${props.name} `, "").trim();
|
|
149
|
+
if (props.type === "number")
|
|
150
|
+
return (isNaN(Number(value)) ? undefined : Number(value)) satisfies
|
|
151
|
+
| number
|
|
152
|
+
| undefined as any;
|
|
153
|
+
return value as any;
|
|
154
|
+
}
|
|
155
|
+
return undefined as any;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const describe = (lines: string[], tags: string[]): string | undefined => {
|
|
159
|
+
const ret: string = trimArray(
|
|
160
|
+
lines
|
|
161
|
+
.map((str) => str.trim())
|
|
162
|
+
.filter((str) =>
|
|
163
|
+
tags.every((tag) => str.startsWith(`@${tag}`) === false),
|
|
164
|
+
),
|
|
165
|
+
).join("\n");
|
|
166
|
+
return ret.length === 0 ? undefined : ret;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const trimArray = (array: string[]): string[] => {
|
|
170
|
+
let first: number = 0;
|
|
171
|
+
let last: number = array.length - 1;
|
|
172
|
+
|
|
173
|
+
for (; first < array.length; ++first)
|
|
174
|
+
if (array[first]!.trim().length !== 0) break;
|
|
175
|
+
for (; last >= 0; --last) if (array[last]!.trim().length !== 0) break;
|
|
176
|
+
return array.slice(first, last + 1);
|
|
177
|
+
};
|
|
178
|
+
}
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { IJsonSchemaTransformError, IResult, OpenApi } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
import { OpenApiTypeChecker } from "../../validators/OpenApiTypeChecker";
|
|
4
|
-
|
|
5
|
-
/** @internal */
|
|
6
|
-
export namespace LlmParametersFinder {
|
|
7
|
-
export const parameters = (props: {
|
|
8
|
-
components: OpenApi.IComponents;
|
|
9
|
-
schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference;
|
|
10
|
-
method: string;
|
|
11
|
-
accessor?: string;
|
|
12
|
-
refAccessor?: string;
|
|
13
|
-
}): IResult<OpenApi.IJsonSchema.IObject, IJsonSchemaTransformError> => {
|
|
14
|
-
const entity: IResult<OpenApi.IJsonSchema, IJsonSchemaTransformError> =
|
|
15
|
-
OpenApiTypeChecker.unreference(props);
|
|
16
|
-
if (entity.success === false) return entity;
|
|
17
|
-
else if (OpenApiTypeChecker.isObject(entity.value) === false)
|
|
18
|
-
return reportError({
|
|
19
|
-
...props,
|
|
20
|
-
message: "LLM only accepts object type as parameters.",
|
|
21
|
-
});
|
|
22
|
-
else if (!!entity.value.additionalProperties)
|
|
23
|
-
return reportError({
|
|
24
|
-
...props,
|
|
25
|
-
message: "LLM does not allow additional properties on parameters.",
|
|
26
|
-
});
|
|
27
|
-
return {
|
|
28
|
-
success: true,
|
|
29
|
-
value: entity.value,
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const reportError = (props: {
|
|
34
|
-
method: string;
|
|
35
|
-
message: string;
|
|
36
|
-
schema: OpenApi.IJsonSchema;
|
|
37
|
-
accessor?: string;
|
|
38
|
-
}): IResult.IFailure<IJsonSchemaTransformError> => ({
|
|
39
|
-
success: false,
|
|
40
|
-
error: {
|
|
41
|
-
method: props.method,
|
|
42
|
-
message: `failed to compose LLM schema.`,
|
|
43
|
-
reasons: [
|
|
44
|
-
{
|
|
45
|
-
schema: props.schema,
|
|
46
|
-
message: props.message,
|
|
47
|
-
accessor: props.accessor ?? "$input.schema",
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
}
|
|
1
|
+
import { IJsonSchemaTransformError, IResult, OpenApi } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
import { OpenApiTypeChecker } from "../../validators/OpenApiTypeChecker";
|
|
4
|
+
|
|
5
|
+
/** @internal */
|
|
6
|
+
export namespace LlmParametersFinder {
|
|
7
|
+
export const parameters = (props: {
|
|
8
|
+
components: OpenApi.IComponents;
|
|
9
|
+
schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference;
|
|
10
|
+
method: string;
|
|
11
|
+
accessor?: string;
|
|
12
|
+
refAccessor?: string;
|
|
13
|
+
}): IResult<OpenApi.IJsonSchema.IObject, IJsonSchemaTransformError> => {
|
|
14
|
+
const entity: IResult<OpenApi.IJsonSchema, IJsonSchemaTransformError> =
|
|
15
|
+
OpenApiTypeChecker.unreference(props);
|
|
16
|
+
if (entity.success === false) return entity;
|
|
17
|
+
else if (OpenApiTypeChecker.isObject(entity.value) === false)
|
|
18
|
+
return reportError({
|
|
19
|
+
...props,
|
|
20
|
+
message: "LLM only accepts object type as parameters.",
|
|
21
|
+
});
|
|
22
|
+
else if (!!entity.value.additionalProperties)
|
|
23
|
+
return reportError({
|
|
24
|
+
...props,
|
|
25
|
+
message: "LLM does not allow additional properties on parameters.",
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
success: true,
|
|
29
|
+
value: entity.value,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const reportError = (props: {
|
|
34
|
+
method: string;
|
|
35
|
+
message: string;
|
|
36
|
+
schema: OpenApi.IJsonSchema;
|
|
37
|
+
accessor?: string;
|
|
38
|
+
}): IResult.IFailure<IJsonSchemaTransformError> => ({
|
|
39
|
+
success: false,
|
|
40
|
+
error: {
|
|
41
|
+
method: props.method,
|
|
42
|
+
message: `failed to compose LLM schema.`,
|
|
43
|
+
reasons: [
|
|
44
|
+
{
|
|
45
|
+
schema: props.schema,
|
|
46
|
+
message: props.message,
|
|
47
|
+
accessor: props.accessor ?? "$input.schema",
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|