Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@samchon/openapi

Package Overview
Dependencies
Maintainers
0
Versions
161
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@samchon/openapi - npm Package Compare versions

Comparing version 2.0.0-dev.20241201-2 to 2.0.0-dev.20241202-2

lib/composers/llm/LlmParametersComposer.d.ts

9

lib/composers/HttpLlmApplicationComposer.js

@@ -109,3 +109,4 @@ "use strict";

var cast = function (s, accessor) {
return LlmSchemaComposer_1.LlmSchemaComposer.schema(props.model)({
var _a;
var result = LlmSchemaComposer_1.LlmSchemaComposer.schema(props.model)({
config: props.options,

@@ -115,6 +116,10 @@ schema: s,

$defs: $defs,
errors: props.errors,
accessor: accessor,
refAccessor: "$input.components.schemas",
});
if (result.success === false) {
(_a = props.errors).push.apply(_a, __spreadArray([], __read(result.error.reasons.map(function (r) { return "".concat(r.accessor, ": ").concat(r.message); })), false));
return null;
}
return result.value;
};

@@ -121,0 +126,0 @@ var endpoint = "$input.paths[".concat(JSON.stringify(props.route.path), "][").concat(JSON.stringify(props.route.method), "]");

@@ -51,5 +51,5 @@ "use strict";

exports.HttpMigrateApplicationComposer = void 0;
var EndpointUtil_1 = require("../utils/EndpointUtil");
var Escaper_1 = require("../utils/Escaper");
var OpenApiTypeChecker_1 = require("../utils/OpenApiTypeChecker");
var StringUtil_1 = require("../utils/StringUtil");
var HttpMigrateApplicationComposer;

@@ -66,5 +66,5 @@ (function (HttpMigrateApplicationComposer) {

document: props.document,
name: StringUtil_1.StringUtil.pascal("I/Api/".concat(props.path)) +
name: EndpointUtil_1.EndpointUtil.pascal("I/Api/".concat(props.path)) +
"." +
StringUtil_1.StringUtil.pascal("".concat(props.method, "/Body")),
EndpointUtil_1.EndpointUtil.pascal("".concat(props.method, "/Body")),
schema: schema,

@@ -78,5 +78,5 @@ });

document: props.document,
name: StringUtil_1.StringUtil.pascal("I/Api/".concat(props.path)) +
name: EndpointUtil_1.EndpointUtil.pascal("I/Api/".concat(props.path)) +
"." +
StringUtil_1.StringUtil.pascal("".concat(props.method, "/Response")),
EndpointUtil_1.EndpointUtil.pascal("".concat(props.method, "/Response")),
schema: schema,

@@ -164,5 +164,5 @@ });

document: props.document,
name: StringUtil_1.StringUtil.pascal("I/Api/".concat(props.path)) +
name: EndpointUtil_1.EndpointUtil.pascal("I/Api/".concat(props.path)) +
"." +
StringUtil_1.StringUtil.pascal("".concat(props.method, "/").concat(type)),
EndpointUtil_1.EndpointUtil.pascal("".concat(props.method, "/").concat(type)),
schema: {

@@ -191,3 +191,3 @@ type: "object",

//----
var parameterNames = StringUtil_1.StringUtil.splitWithNormalization(props.emendedPath)
var parameterNames = EndpointUtil_1.EndpointUtil.splitWithNormalization(props.emendedPath)
.filter(function (str) { return str[0] === ":"; })

@@ -235,3 +235,3 @@ .map(function (str) { return str.substring(1); });

key: (function () {
var key = StringUtil_1.StringUtil.normalize(parameterNames[i]);
var key = EndpointUtil_1.EndpointUtil.normalize(parameterNames[i]);
if (Escaper_1.Escaper.variable(key))

@@ -259,3 +259,3 @@ return key;

key: (function () {
var key = StringUtil_1.StringUtil.normalize(parameterNames[i]);
var key = EndpointUtil_1.EndpointUtil.normalize(parameterNames[i]);
if (Escaper_1.Escaper.variable(key))

@@ -262,0 +262,0 @@ return key;

import { OpenApi } from "../../OpenApi";
import { IChatGptSchema } from "../../structures/IChatGptSchema";
import { ILlmFunction } from "../../structures/ILlmFunction";
import { IOpenApiSchemaError } from "../../structures/IOpenApiSchemaError";
import { IResult } from "../../typings/IResult";
export declare namespace ChatGptSchemaComposer {

@@ -9,5 +11,5 @@ const parameters: (props: {

schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference;
errors?: string[];
accessor?: string;
}) => IChatGptSchema.IParameters | null;
refAccessor?: string;
}) => IResult<IChatGptSchema.IParameters, IOpenApiSchemaError>;
const schema: (props: {

@@ -18,6 +20,5 @@ config: IChatGptSchema.IConfig;

schema: OpenApi.IJsonSchema;
errors?: string[];
accessor?: string;
refAccessor?: string;
}) => IChatGptSchema | null;
}) => IResult<IChatGptSchema, IOpenApiSchemaError>;
const separateParameters: (props: {

@@ -24,0 +25,0 @@ predicate: (schema: IChatGptSchema) => boolean;

@@ -50,12 +50,12 @@ "use strict";

var e_1, _a;
var params = LlmSchemaV3_1Composer_1.LlmSchemaV3_1Composer.parameters(__assign(__assign({}, props), { config: {
var result = LlmSchemaV3_1Composer_1.LlmSchemaV3_1Composer.parameters(__assign(__assign({}, props), { config: {
reference: props.config.reference,
constraint: false,
}, validate: validate(props.errors) }));
if (params === null)
return null;
}, validate: validate }));
if (result.success === false)
return result;
try {
for (var _b = __values(Object.keys(params.$defs)), _c = _b.next(); !_c.done; _c = _b.next()) {
for (var _b = __values(Object.keys(result.value.$defs)), _c = _b.next(); !_c.done; _c = _b.next()) {
var key = _c.value;
params.$defs[key] = transform(params.$defs[key]);
result.value.$defs[key] = transform(result.value.$defs[key]);
}

@@ -70,3 +70,6 @@ }

}
return transform(params);
return {
success: true,
value: transform(result.value),
};
};

@@ -76,8 +79,8 @@ ChatGptSchemaComposer.schema = function (props) {

var oldbie = new Set(Object.keys(props.$defs));
var schema = LlmSchemaV3_1Composer_1.LlmSchemaV3_1Composer.schema(__assign(__assign({}, props), { config: {
var result = LlmSchemaV3_1Composer_1.LlmSchemaV3_1Composer.schema(__assign(__assign({}, props), { config: {
reference: props.config.reference,
constraint: false,
}, validate: validate(props.errors) }));
if (schema === null)
return null;
}, validate: validate }));
if (result.success === false)
return result;
try {

@@ -97,15 +100,18 @@ for (var _b = __values(Object.keys(props.$defs)), _c = _b.next(); !_c.done; _c = _b.next()) {

}
return transform(schema);
};
var validate = function (errors) {
return function (schema, accessor) {
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isObject(schema) &&
!!schema.additionalProperties) {
if (errors)
errors.push("".concat(accessor, ".additionalProperties: ChatGPT does not allow additionalProperties, the dynamic key typed object."));
return false;
}
return true;
return {
success: true,
value: transform(result.value),
};
};
var validate = function (schema, accessor) {
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isObject(schema) && !!schema.additionalProperties)
return [
{
schema: schema,
accessor: "".concat(accessor, ".additionalProperties"),
message: "ChatGPT does not allow additionalProperties, the dynamic key typed object.",
},
];
return [];
};
var transform = function (schema) {

@@ -112,0 +118,0 @@ var union = [];

import { OpenApi } from "../../OpenApi";
import { IClaudeSchema } from "../../structures/IClaudeSchema";
import { ILlmFunction } from "../../structures/ILlmFunction";
import { IOpenApiSchemaError } from "../../structures/IOpenApiSchemaError";
import { IResult } from "../../typings/IResult";
export declare namespace ClaudeSchemaComposer {

@@ -9,5 +11,5 @@ const parameters: (props: {

schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference;
errors?: string[];
accessor?: string;
}) => IClaudeSchema.IParameters | null;
refAccessor?: string;
}) => IResult<IClaudeSchema.IParameters, IOpenApiSchemaError>;
const schema: (props: {

@@ -18,6 +20,5 @@ config: IClaudeSchema.IConfig;

schema: OpenApi.IJsonSchema;
errors?: string[];
accessor?: string;
refAccessor?: string;
}) => IClaudeSchema | null;
}) => IResult<IClaudeSchema, IOpenApiSchemaError>;
const separateParameters: (props: {

@@ -24,0 +25,0 @@ predicate: (schema: IClaudeSchema) => boolean;

import { OpenApi } from "../../OpenApi";
import { IGeminiSchema } from "../../structures/IGeminiSchema";
import { ILlmFunction } from "../../structures/ILlmFunction";
import { IOpenApiSchemaError } from "../../structures/IOpenApiSchemaError";
import { IResult } from "../../typings/IResult";
export declare namespace GeminiSchemaComposer {

@@ -9,5 +11,5 @@ const parameters: (props: {

schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference;
errors?: string[];
accessor?: string;
}) => IGeminiSchema.IParameters | null;
refAccessor?: string;
}) => IResult<IGeminiSchema.IParameters, IOpenApiSchemaError>;
const schema: (props: {

@@ -17,5 +19,5 @@ config: IGeminiSchema.IConfig;

schema: OpenApi.IJsonSchema;
errors?: string[];
accessor?: string;
}) => IGeminiSchema | null;
refAccessor?: string;
}) => IResult<IGeminiSchema, IOpenApiSchemaError>;
const separateParameters: (props: {

@@ -22,0 +24,0 @@ predicate: (schema: IGeminiSchema) => boolean;

@@ -28,3 +28,3 @@ "use strict";

var OpenApiTypeChecker_1 = require("../../utils/OpenApiTypeChecker");
var LlmParametersFinder_1 = require("../llm/LlmParametersFinder");
var LlmParametersComposer_1 = require("./LlmParametersComposer");
var LlmSchemaV3Composer_1 = require("./LlmSchemaV3Composer");

@@ -34,10 +34,10 @@ var GeminiSchemaComposer;

GeminiSchemaComposer.parameters = function (props) {
var entity = LlmParametersFinder_1.LlmParametersFinder.find(props);
if (entity === null)
return null;
return GeminiSchemaComposer.schema(__assign(__assign({}, props), { schema: entity }));
var entity = LlmParametersComposer_1.LlmParametersFinder.parameters(__assign(__assign({}, props), { method: "GeminiSchemaComposer.parameters" }));
if (entity.success === false)
return entity;
return GeminiSchemaComposer.schema(__assign(__assign({}, props), { schema: entity.value }));
};
GeminiSchemaComposer.schema = function (props) {
// TRANSFORM TO LLM SCHEMA OF V3.0
var schema = LlmSchemaV3Composer_1.LlmSchemaV3Composer.schema(__assign(__assign({}, props), { config: {
var result = LlmSchemaV3Composer_1.LlmSchemaV3Composer.schema(__assign(__assign({}, props), { config: {
recursive: props.config.recursive,

@@ -47,21 +47,27 @@ constraint: false,

if (OpenApiTypeChecker_1.OpenApiTypeChecker.isObject(next)) {
if (!!next.additionalProperties) {
if (props.errors)
props.errors.push("".concat(accessor, ".additionalProperties: Gemini does not allow additionalProperties, the dynamic key typed object."));
return false;
}
if (!!next.additionalProperties)
return [
{
schema: next,
accessor: "".concat(accessor, ".additionalProperties"),
message: "Gemini does not allow additionalProperties.",
},
];
}
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isOneOf(next) &&
isOneOf(props.components)(next)) {
if (props.errors)
props.errors.push("".concat(accessor, ": Gemini does not allow union type."));
return false;
}
return true;
isOneOf(props.components)(next))
return [
{
schema: next,
accessor: accessor,
message: "Gemini does not allow union type.",
},
];
return [];
} }));
if (schema === null)
return null;
if (result.success === false)
return result;
// SPECIALIZATIONS
LlmTypeCheckerV3_1.LlmTypeCheckerV3.visit({
schema: schema,
schema: result.value,
closure: function (v) {

@@ -86,6 +92,5 @@ if (v.title !== undefined) {

},
accessor: props.accessor,
});
// DO NOT ALLOW UNION TYPE
return schema;
return result;
};

@@ -92,0 +97,0 @@ GeminiSchemaComposer.separateParameters = function (props) {

import { OpenApi } from "../../OpenApi";
import { ILlamaSchema } from "../../structures/ILlamaSchema";
import { ILlmFunction } from "../../structures/ILlmFunction";
import { IOpenApiSchemaError } from "../../structures/IOpenApiSchemaError";
import { IResult } from "../../typings/IResult";
export declare namespace LlamaSchemaComposer {

@@ -9,5 +11,3 @@ const parameters: (props: {

schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference;
errors?: string[];
accessor?: string;
}) => ILlamaSchema.IParameters | null;
}) => IResult<ILlamaSchema.IParameters, IOpenApiSchemaError>;
const schema: (props: {

@@ -18,6 +18,3 @@ config: ILlamaSchema.IConfig;

schema: OpenApi.IJsonSchema;
errors?: string[];
accessor?: string;
refAccessor?: string;
}) => ILlamaSchema | null;
}) => IResult<ILlamaSchema, IOpenApiSchemaError>;
const separateParameters: (props: {

@@ -24,0 +21,0 @@ predicate: (schema: ILlamaSchema) => boolean;

import { OpenApi } from "../../OpenApi";
import { ILlmFunction } from "../../structures/ILlmFunction";
import { ILlmSchemaV3_1 } from "../../structures/ILlmSchemaV3_1";
import { IOpenApiSchemaError } from "../../structures/IOpenApiSchemaError";
import { IResult } from "../../typings/IResult";
export declare namespace LlmSchemaV3_1Composer {

@@ -10,5 +12,7 @@ const parameters: (props: {

errors?: string[];
/** @internal */
validate?: (input: OpenApi.IJsonSchema, accessor: string) => IOpenApiSchemaError.IReason[];
accessor?: string;
validate?: (input: OpenApi.IJsonSchema, accessor: string) => boolean;
}) => ILlmSchemaV3_1.IParameters | null;
refAccessor?: string;
}) => IResult<ILlmSchemaV3_1.IParameters, IOpenApiSchemaError>;
const schema: (props: {

@@ -19,7 +23,7 @@ config: ILlmSchemaV3_1.IConfig;

schema: OpenApi.IJsonSchema;
errors?: string[];
/** @internal */
validate?: (input: OpenApi.IJsonSchema, accessor: string) => IOpenApiSchemaError.IReason[];
accessor?: string;
refAccessor?: string;
validate?: (input: OpenApi.IJsonSchema, accessor: string) => boolean;
}) => ILlmSchemaV3_1 | null;
}) => IResult<ILlmSchemaV3_1, IOpenApiSchemaError>;
const separateParameters: (props: {

@@ -26,0 +30,0 @@ predicate: (schema: ILlmSchemaV3_1) => boolean;

@@ -29,2 +29,11 @@ "use strict";

};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __values = (this && this.__values) || function(o) {

@@ -47,25 +56,20 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;

var JsonDescriptionUtil_1 = require("../../utils/internal/JsonDescriptionUtil");
var LlmParametersFinder_1 = require("./LlmParametersFinder");
var LlmParametersComposer_1 = require("./LlmParametersComposer");
var LlmSchemaV3_1Composer;
(function (LlmSchemaV3_1Composer) {
LlmSchemaV3_1Composer.parameters = function (props) {
var _a;
var entity = LlmParametersFinder_1.LlmParametersFinder.find(props);
if (entity === null)
return null;
else if (!!entity.additionalProperties) {
if (props.errors)
props.errors.push("".concat((_a = props.accessor) !== null && _a !== void 0 ? _a : "$input", ".additionalProperties: LLM does not allow additional properties on parameters."));
return null;
}
var entity = LlmParametersComposer_1.LlmParametersFinder.parameters(__assign(__assign({}, props), { method: "LlmSchemaV3_1Composer.parameters" }));
if (entity.success === false)
return entity;
var $defs = {};
var res = LlmSchemaV3_1Composer.schema(__assign(__assign({}, props), { $defs: $defs, schema: entity, refAccessor: props.accessor ? "".concat(props.accessor, "/$defs") : undefined }));
if (res === null)
return null;
res.$defs = $defs;
res.additionalProperties = false;
return res;
var result = LlmSchemaV3_1Composer.schema(__assign(__assign({}, props), { $defs: $defs, schema: entity.value }));
if (result.success === false)
return result;
return {
success: true,
value: __assign(__assign({}, result.value), { additionalProperties: false, $defs: $defs }),
};
};
LlmSchemaV3_1Composer.schema = function (props) {
var _a, _b, _c;
var _a;
var union = [];

@@ -76,24 +80,25 @@ var attribute = __assign({ title: props.schema.title, description: props.schema.description, example: props.schema.example, examples: props.schema.examples }, Object.fromEntries(Object.entries(props.schema).filter(function (_a) {

})));
var valid = true;
var reasons = [];
OpenApiTypeChecker_1.OpenApiTypeChecker.visit({
closure: function (next, accessor) {
var _a;
if (props.validate && props.validate(next, accessor) === false) {
if (props.validate) {
// CUSTOM VALIDATION
valid && (valid = false);
reasons.push.apply(reasons, __spreadArray([], __read(props.validate(next, accessor)), false));
}
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isTuple(next)) {
// TUPLE IS BANNED
if (props.errors !== undefined)
props.errors.push("".concat(accessor, ": LLM does not allow tuple type."));
valid && (valid = false);
}
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isTuple(next))
reasons.push({
schema: next,
accessor: accessor,
message: "LLM does not allow tuple type.",
});
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isReference(next)) {
// UNABLE TO FIND MATCHED REFERENCE
var key = next.$ref.split("#/components/schemas/")[1];
if (((_a = props.components.schemas) === null || _a === void 0 ? void 0 : _a[key]) === undefined) {
if (props.errors !== undefined)
props.errors.push("".concat(accessor, ": unable to find reference type ").concat(JSON.stringify(key), "."));
valid && (valid = false);
}
if (((_a = props.components.schemas) === null || _a === void 0 ? void 0 : _a[key]) === undefined)
reasons.push({
schema: next,
accessor: accessor,
message: "unable to find reference type ".concat(JSON.stringify(key), "."),
});
}

@@ -103,7 +108,14 @@ },

schema: props.schema,
accessor: (_a = props.accessor) !== null && _a !== void 0 ? _a : "$input.schema",
refAccessor: (_b = props.refAccessor) !== null && _b !== void 0 ? _b : "$input.components.schemas",
accessor: props.accessor,
refAccessor: props.refAccessor,
});
if (valid === false)
return null;
if (reasons.length > 0)
return {
success: false,
error: {
method: "LlmSchemaV3_1Composer.schema",
message: "Failed to compose LLM schema of v3.1",
reasons: reasons,
},
};
var visit = function (input, accessor) {

@@ -140,9 +152,8 @@ var _a, _b, _c;

schema: target,
errors: props.errors,
refAccessor: props.refAccessor,
accessor: "".concat((_b = props.refAccessor) !== null && _b !== void 0 ? _b : "$def", "[").concat(JSON.stringify(key_1), "]"),
});
if (converted === null)
return union.push(null);
props.$defs[key_1] = converted;
if (converted.success === false)
return union.push(null); // UNREACHABLE
props.$defs[key_1] = converted.value;
return out();

@@ -182,7 +193,8 @@ }

schema: value,
errors: props.errors,
refAccessor: props.refAccessor,
accessor: "".concat(accessor, ".properties[").concat(JSON.stringify(key), "]"),
});
acc[key] = converted;
acc[key] = converted.success ? converted.value : null;
if (converted.success === false)
reasons.push.apply(reasons, __spreadArray([], __read(converted.error.reasons), false));
return acc;

@@ -192,14 +204,21 @@ }, {});

return union.push(null);
var additionalProperties = typeof input.additionalProperties === "object" &&
input.additionalProperties !== null
? LlmSchemaV3_1Composer.schema({
config: props.config,
components: props.components,
$defs: props.$defs,
schema: input.additionalProperties,
errors: props.errors,
refAccessor: props.refAccessor,
accessor: "".concat(accessor, ".additionalProperties"),
})
: input.additionalProperties;
var additionalProperties = (function () {
if (typeof input.additionalProperties === "object" &&
input.additionalProperties !== null) {
var converted = LlmSchemaV3_1Composer.schema({
config: props.config,
components: props.components,
$defs: props.$defs,
schema: input.additionalProperties,
refAccessor: props.refAccessor,
accessor: "".concat(accessor, ".additionalProperties"),
});
if (converted.success === false) {
reasons.push.apply(reasons, __spreadArray([], __read(converted.error.reasons), false));
return null;
}
return converted.value;
}
return input.additionalProperties;
})();
if (additionalProperties === null)

@@ -215,8 +234,9 @@ return union.push(null);

schema: input.items,
errors: props.errors,
refAccessor: props.refAccessor,
accessor: "".concat(accessor, ".items"),
});
if (items === null)
if (items.success === false) {
reasons.push.apply(reasons, __spreadArray([], __read(items.error.reasons), false));
return union.push(null);
}
return union.push((props.config.constraint

@@ -226,3 +246,3 @@ ? function (x) { return x; }

return OpenApiContraintShifter_1.OpenApiContraintShifter.shiftArray(x);
})(__assign(__assign({}, input), { items: items })));
})(__assign(__assign({}, input), { items: items.value })));
}

@@ -247,14 +267,30 @@ else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isString(input))

};
visit(props.schema, (_c = props.accessor) !== null && _c !== void 0 ? _c : "$input.schema");
visit(props.schema, (_a = props.accessor) !== null && _a !== void 0 ? _a : "$input.schema");
if (union.some(function (u) { return u === null; }))
return null;
return {
success: false,
error: {
method: "LlmSchemaV3_1Composer.schema",
message: "Failed to compose LLM schema of v3.1",
reasons: reasons,
},
};
else if (union.length === 0)
return __assign(__assign({}, attribute), { type: undefined });
return {
success: true,
value: __assign(__assign({}, attribute), { type: undefined }),
};
else if (union.length === 1)
return __assign(__assign(__assign({}, attribute), union[0]), { description: LlmTypeCheckerV3_1_1.LlmTypeCheckerV3_1.isReference(union[0])
? undefined
: union[0].description });
return __assign(__assign({}, attribute), { oneOf: union.map(function (u) { return (__assign(__assign({}, u), { description: LlmTypeCheckerV3_1_1.LlmTypeCheckerV3_1.isReference(u)
? undefined
: u.description })); }) });
return {
success: true,
value: __assign(__assign(__assign({}, attribute), union[0]), { description: LlmTypeCheckerV3_1_1.LlmTypeCheckerV3_1.isReference(union[0])
? undefined
: union[0].description }),
};
return {
success: true,
value: __assign(__assign({}, attribute), { oneOf: union.map(function (u) { return (__assign(__assign({}, u), { description: LlmTypeCheckerV3_1_1.LlmTypeCheckerV3_1.isReference(u)
? undefined
: u.description })); }) }),
};
};

@@ -261,0 +297,0 @@ LlmSchemaV3_1Composer.separateParameters = function (props) {

import { OpenApi } from "../../OpenApi";
import { ILlmFunction } from "../../structures/ILlmFunction";
import { ILlmSchemaV3 } from "../../structures/ILlmSchemaV3";
import { IOpenApiSchemaError } from "../../structures/IOpenApiSchemaError";
import { IResult } from "../../typings/IResult";
export declare namespace LlmSchemaV3Composer {

@@ -9,5 +11,7 @@ const parameters: (props: {

schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference;
errors?: string[];
/** @internal */
validate?: (schema: OpenApi.IJsonSchema, accessor: string) => IOpenApiSchemaError.IReason[];
accessor?: string;
}) => ILlmSchemaV3.IParameters | null;
refAccessor?: string;
}) => IResult<ILlmSchemaV3.IParameters, IOpenApiSchemaError>;
const schema: (props: {

@@ -17,7 +21,7 @@ config: ILlmSchemaV3.IConfig;

schema: OpenApi.IJsonSchema;
errors?: string[];
/** @internal */
validate?: (schema: OpenApi.IJsonSchema, accessor: string) => IOpenApiSchemaError.IReason[];
accessor?: string;
refAccessor?: string;
validate?: (schema: OpenApi.IJsonSchema, accessor: string) => boolean;
}) => ILlmSchemaV3 | null;
}) => IResult<ILlmSchemaV3, IOpenApiSchemaError>;
const separateParameters: (props: {

@@ -24,0 +28,0 @@ predicate: (schema: ILlmSchemaV3) => boolean;

@@ -29,2 +29,11 @@ "use strict";

};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __values = (this && this.__values) || function(o) {

@@ -47,34 +56,31 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;

var OpenApiTypeChecker_1 = require("../../utils/OpenApiTypeChecker");
var LlmParametersFinder_1 = require("./LlmParametersFinder");
var LlmParametersComposer_1 = require("./LlmParametersComposer");
var LlmSchemaV3Composer;
(function (LlmSchemaV3Composer) {
LlmSchemaV3Composer.parameters = function (props) {
var _a;
var entity = LlmParametersFinder_1.LlmParametersFinder.find(props);
if (entity === null)
return null;
else if (!!entity.additionalProperties) {
if (props.errors)
props.errors.push("".concat((_a = props.accessor) !== null && _a !== void 0 ? _a : "$input", ".additionalProperties: LLM does not allow additional properties on parameters."));
return null;
}
var res = LlmSchemaV3Composer.schema(__assign(__assign({}, props), { schema: entity }));
if (res !== null)
res.additionalProperties = false;
return res;
var entity = LlmParametersComposer_1.LlmParametersFinder.parameters(__assign(__assign({}, props), { method: "LlmSchemaV3Composer.parameters" }));
if (entity.success === false)
return entity;
var result = LlmSchemaV3Composer.schema(__assign(__assign({}, props), { schema: entity.value }));
if (result.success === false)
return result;
return {
success: true,
value: __assign(__assign({}, result.value), { additionalProperties: false }),
};
};
LlmSchemaV3Composer.schema = function (props) {
var _a, _b;
// CHECK TUPLE TYPE
var valid = true;
var reasons = [];
OpenApiTypeChecker_1.OpenApiTypeChecker.visit({
closure: function (next, accessor) {
var _a;
if (props.validate && props.validate(next, accessor) === false)
valid && (valid = false);
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isTuple(next)) {
if (props.errors)
props.errors.push("".concat(accessor !== null && accessor !== void 0 ? accessor : "$input", ": LLM does not allow tuple type."));
valid && (valid = false);
}
if (props.validate)
reasons.push.apply(reasons, __spreadArray([], __read(props.validate(next, accessor)), false));
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isTuple(next))
reasons.push({
accessor: accessor,
schema: next,
message: "LLM does not allow tuple type.",
});
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isReference(next)) {

@@ -84,5 +90,7 @@ // UNABLE TO FIND MATCHED REFERENCE

if (((_a = props.components.schemas) === null || _a === void 0 ? void 0 : _a[key]) === undefined) {
if (props.errors !== undefined)
props.errors.push("".concat(accessor, ": unable to find reference type ").concat(JSON.stringify(key), "."));
valid && (valid = false);
reasons.push({
schema: next,
message: "".concat(accessor, ": unable to find reference type ").concat(JSON.stringify(key), "."),
accessor: accessor,
});
}

@@ -93,11 +101,27 @@ }

schema: props.schema,
accessor: (_a = props.accessor) !== null && _a !== void 0 ? _a : "$input.schema",
refAccessor: (_b = props.refAccessor) !== null && _b !== void 0 ? _b : "$input.components.schemas",
accessor: props.accessor,
refAccessor: props.refAccessor,
});
if (valid === false)
return null;
// if ((valid as boolean) === false) return null;
if (reasons.length > 0)
return {
success: false,
error: {
method: "LlmSchemaV3Composer.schema",
message: "Failed to compose LLM schema of v3",
reasons: reasons,
},
};
// CHECK MISMATCHES
var schema = OpenApiTypeChecker_1.OpenApiTypeChecker.escape(__assign(__assign({}, props), { recursive: props.config.recursive }));
if (schema === null)
return null; // UNREACHABLE
var escaped = OpenApiTypeChecker_1.OpenApiTypeChecker.escape(__assign(__assign({}, props), { recursive: props.config.recursive }));
if (escaped.success === false)
// UNREACHABLE
return {
success: false,
error: {
method: "LlmSchemaV3Composer.schema",
message: "Failed to compose LLM schema of v3",
reasons: escaped.error.reasons,
},
};
// SPECIALIZATIONS

@@ -109,3 +133,3 @@ var downgraded = OpenApiV3Downgrader_1.OpenApiV3Downgrader.downgradeSchema({

downgraded: {},
})(schema);
})(escaped.value);
LlmTypeCheckerV3_1.LlmTypeCheckerV3.visit({

@@ -133,3 +157,6 @@ closure: function (next) {

});
return downgraded;
return {
success: true,
value: downgraded,
};
};

@@ -136,0 +163,0 @@ LlmSchemaV3Composer.separateParameters = function (props) {

@@ -18,5 +18,5 @@ import { IChatGptSchema } from "../structures/IChatGptSchema";

schema: import("..").OpenApi.IJsonSchema.IObject | import("..").OpenApi.IJsonSchema.IReference;
errors?: string[];
accessor?: string;
}) => IChatGptSchema.IParameters | null;
refAccessor?: string;
}) => import("..").IResult<IChatGptSchema.IParameters, import("..").IOpenApiSchemaError>;
claude: (props: {

@@ -26,5 +26,5 @@ config: IClaudeSchema.IConfig;

schema: import("..").OpenApi.IJsonSchema.IObject | import("..").OpenApi.IJsonSchema.IReference;
errors?: string[];
accessor?: string;
}) => IClaudeSchema.IParameters | null;
refAccessor?: string;
}) => import("..").IResult<IClaudeSchema.IParameters, import("..").IOpenApiSchemaError>;
gemini: (props: {

@@ -34,5 +34,5 @@ config: IGeminiSchema.IConfig;

schema: import("..").OpenApi.IJsonSchema.IObject | import("..").OpenApi.IJsonSchema.IReference;
errors?: string[];
accessor?: string;
}) => IGeminiSchema.IParameters | null;
refAccessor?: string;
}) => import("..").IResult<IGeminiSchema.IParameters, import("..").IOpenApiSchemaError>;
llama: (props: {

@@ -42,5 +42,3 @@ config: ILlamaSchema.IConfig;

schema: import("..").OpenApi.IJsonSchema.IObject | import("..").OpenApi.IJsonSchema.IReference;
errors?: string[];
accessor?: string;
}) => ILlamaSchema.IParameters | null;
}) => import("..").IResult<ILlamaSchema.IParameters, import("..").IOpenApiSchemaError>;
"3.0": (props: {

@@ -50,5 +48,6 @@ config: ILlmSchemaV3.IConfig;

schema: import("..").OpenApi.IJsonSchema.IObject | import("..").OpenApi.IJsonSchema.IReference;
errors?: string[];
validate?: (schema: import("..").OpenApi.IJsonSchema, accessor: string) => import("..").IOpenApiSchemaError.IReason[];
accessor?: string;
}) => ILlmSchemaV3.IParameters | null;
refAccessor?: string;
}) => import("..").IResult<ILlmSchemaV3.IParameters, import("..").IOpenApiSchemaError>;
"3.1": (props: {

@@ -59,5 +58,6 @@ config: ILlmSchemaV3_1.IConfig;

errors?: string[];
validate?: (input: import("..").OpenApi.IJsonSchema, accessor: string) => import("..").IOpenApiSchemaError.IReason[];
accessor?: string;
validate?: (input: import("..").OpenApi.IJsonSchema, accessor: string) => boolean;
}) => ILlmSchemaV3_1.IParameters | null;
refAccessor?: string;
}) => import("..").IResult<ILlmSchemaV3_1.IParameters, import("..").IOpenApiSchemaError>;
}[Model];

@@ -70,6 +70,5 @@ const schema: <Model extends ILlmSchema.Model>(model: Model) => {

schema: import("..").OpenApi.IJsonSchema;
errors?: string[];
accessor?: string;
refAccessor?: string;
}) => IChatGptSchema | null;
}) => import("..").IResult<IChatGptSchema, import("..").IOpenApiSchemaError>;
claude: (props: {

@@ -80,6 +79,5 @@ config: IClaudeSchema.IConfig;

schema: import("..").OpenApi.IJsonSchema;
errors?: string[];
accessor?: string;
refAccessor?: string;
}) => IClaudeSchema | null;
}) => import("..").IResult<IClaudeSchema, import("..").IOpenApiSchemaError>;
gemini: (props: {

@@ -89,5 +87,5 @@ config: IGeminiSchema.IConfig;

schema: import("..").OpenApi.IJsonSchema;
errors?: string[];
accessor?: string;
}) => IGeminiSchema | null;
refAccessor?: string;
}) => import("..").IResult<IGeminiSchema, import("..").IOpenApiSchemaError>;
llama: (props: {

@@ -98,6 +96,3 @@ config: ILlamaSchema.IConfig;

schema: import("..").OpenApi.IJsonSchema;
errors?: string[];
accessor?: string;
refAccessor?: string;
}) => ILlamaSchema | null;
}) => import("..").IResult<ILlamaSchema, import("..").IOpenApiSchemaError>;
"3.0": (props: {

@@ -107,7 +102,6 @@ config: ILlmSchemaV3.IConfig;

schema: import("..").OpenApi.IJsonSchema;
errors?: string[];
validate?: (schema: import("..").OpenApi.IJsonSchema, accessor: string) => import("..").IOpenApiSchemaError.IReason[];
accessor?: string;
refAccessor?: string;
validate?: (schema: import("..").OpenApi.IJsonSchema, accessor: string) => boolean;
}) => ILlmSchemaV3 | null;
}) => import("..").IResult<ILlmSchemaV3, import("..").IOpenApiSchemaError>;
"3.1": (props: {

@@ -118,7 +112,6 @@ config: ILlmSchemaV3_1.IConfig;

schema: import("..").OpenApi.IJsonSchema;
errors?: string[];
validate?: (input: import("..").OpenApi.IJsonSchema, accessor: string) => import("..").IOpenApiSchemaError.IReason[];
accessor?: string;
refAccessor?: string;
validate?: (input: import("..").OpenApi.IJsonSchema, accessor: string) => boolean;
}) => ILlmSchemaV3_1 | null;
}) => import("..").IResult<ILlmSchemaV3_1, import("..").IOpenApiSchemaError>;
}[Model];

@@ -125,0 +118,0 @@ const defaultConfig: <Model extends ILlmSchema.Model>(model: Model) => {

@@ -31,3 +31,3 @@ "use strict";

exports.MigrateConverter = void 0;
var StringUtil_1 = require("../../utils/StringUtil");
var EndpointUtil_1 = require("../../utils/EndpointUtil");
var HttpMigrateApplicationComposer_1 = require("../HttpMigrateApplicationComposer");

@@ -51,3 +51,3 @@ var MigrateRouteAccessor_1 = require("./MigrateRouteAccessor");

path: path,
emendedPath: StringUtil_1.StringUtil.reJoinWithDecimalParameters(path),
emendedPath: EndpointUtil_1.EndpointUtil.reJoinWithDecimalParameters(path),
operation: operation,

@@ -54,0 +54,0 @@ });

@@ -40,5 +40,5 @@ "use strict";

exports.MigrateRouteAccessor = void 0;
var EndpointUtil_1 = require("../../utils/EndpointUtil");
var Escaper_1 = require("../../utils/Escaper");
var MapUtil_1 = require("../../utils/MapUtil");
var StringUtil_1 = require("../../utils/StringUtil");
var MigrateRouteAccessor;

@@ -52,3 +52,3 @@ (function (MigrateRouteAccessor) {

.filter(function (str) { return !!str.length && str[0] !== ":"; })
.map(StringUtil_1.StringUtil.normalize)
.map(EndpointUtil_1.EndpointUtil.normalize)
.map(function (str) { return (Escaper_1.Escaper.variable(str) ? str : "_".concat(str)); });

@@ -58,7 +58,7 @@ })(routes);

props.entries.forEach(function (entry, i) {
entry.alias = StringUtil_1.StringUtil.escapeDuplicate(__spreadArray(__spreadArray([], __read(props.children), false), __read(props.entries.filter(function (_, j) { return i !== j; }).map(function (e) { return e.alias; })), false).map(StringUtil_1.StringUtil.normalize))(StringUtil_1.StringUtil.normalize(entry.alias));
entry.alias = EndpointUtil_1.EndpointUtil.escapeDuplicate(__spreadArray(__spreadArray([], __read(props.children), false), __read(props.entries.filter(function (_, j) { return i !== j; }).map(function (e) { return e.alias; })), false).map(EndpointUtil_1.EndpointUtil.normalize))(EndpointUtil_1.EndpointUtil.normalize(entry.alias));
entry.route.accessor = __spreadArray(__spreadArray([], __read(props.namespace), false), [entry.alias], false);
var parameters = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(entry.route.parameters), false), __read((entry.route.body ? [entry.route.body] : [])), false), __read((entry.route.headers ? [entry.route.headers] : [])), false), __read((entry.route.query ? [entry.route.query] : [])), false);
parameters.forEach(function (p, i) {
return (p.key = StringUtil_1.StringUtil.escapeDuplicate(__spreadArray([
return (p.key = EndpointUtil_1.EndpointUtil.escapeDuplicate(__spreadArray([
"connection",

@@ -138,4 +138,4 @@ entry.alias

"By" +
op.parameters.map(function (p) { return StringUtil_1.StringUtil.capitalize(p.key); }).join("And"));
op.parameters.map(function (p) { return EndpointUtil_1.EndpointUtil.capitalize(p.key); }).join("And"));
};
})(MigrateRouteAccessor || (exports.MigrateRouteAccessor = MigrateRouteAccessor = {}));

@@ -12,2 +12,4 @@ export * from "./OpenApi";

export * from "./HttpMigration";
export * from "./typings/IResult";
export * from "./structures/IOpenApiSchemaError";
export * from "./structures/IHttpLlmApplication";

@@ -14,0 +16,0 @@ export * from "./structures/IHttpLlmFunction";

@@ -37,2 +37,4 @@ "use strict";

//----
__exportStar(require("./typings/IResult"), exports);
__exportStar(require("./structures/IOpenApiSchemaError"), exports);
__exportStar(require("./structures/IHttpLlmApplication"), exports);

@@ -39,0 +41,0 @@ __exportStar(require("./structures/IHttpLlmFunction"), exports);

@@ -72,7 +72,8 @@ "use strict";

ChatGptTypeChecker.visit = function (props) {
var _a;
var _a, _b;
var already = new Set();
var refAccessor = (_a = props.refAccessor) !== null && _a !== void 0 ? _a : "$input.$defs";
var next = function (schema, accessor) {
var e_1, _a;
var _b, _c;
var _b;
props.closure(schema, accessor);

@@ -86,3 +87,3 @@ if (ChatGptTypeChecker.isReference(schema)) {

if (found !== undefined)
next(found, "".concat((_c = props.refAccessor) !== null && _c !== void 0 ? _c : "$defs", "[").concat(key, "]"));
next(found, "".concat(refAccessor, "[").concat(key, "]"));
}

@@ -93,4 +94,4 @@ else if (ChatGptTypeChecker.isAnyOf(schema))

try {
for (var _d = __values(Object.entries(schema.properties)), _e = _d.next(); !_e.done; _e = _d.next()) {
var _f = __read(_e.value, 2), key = _f[0], value = _f[1];
for (var _c = __values(Object.entries(schema.properties)), _d = _c.next(); !_d.done; _d = _c.next()) {
var _e = __read(_d.value, 2), key = _e[0], value = _e[1];
next(value, "".concat(accessor, ".properties[").concat(JSON.stringify(key), "]"));

@@ -102,3 +103,3 @@ }

try {
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}

@@ -110,3 +111,3 @@ finally { if (e_1) throw e_1.error; }

};
next(props.schema, (_a = props.accessor) !== null && _a !== void 0 ? _a : "$input");
next(props.schema, (_b = props.accessor) !== null && _b !== void 0 ? _b : "$input.schemas");
};

@@ -113,0 +114,0 @@ ChatGptTypeChecker.covers = function (props) {

@@ -34,3 +34,3 @@ "use strict";

var _a, _b;
var accessor = (_a = props.accessor) !== null && _a !== void 0 ? _a : "$input";
var accessor = (_a = props.accessor) !== null && _a !== void 0 ? _a : "$input.schema";
props.closure(props.schema, accessor);

@@ -37,0 +37,0 @@ if (GeminiTypeChecker.isObject(props.schema))

@@ -51,2 +51,3 @@ "use strict";

exports.OpenApiTypeCheckerBase = void 0;
var AccessorUtil_1 = require("../AccessorUtil");
var MapUtil_1 = require("../MapUtil");

@@ -126,25 +127,55 @@ var JsonDescriptionUtil_1 = require("./JsonDescriptionUtil");

OpenApiTypeCheckerBase.unreference = function (props) {
var _a;
if (OpenApiTypeCheckerBase.isReference(props.schema) === false)
return props.schema;
var key = props.schema.$ref.split(props.prefix).pop();
var found = (_a = props.components.schemas) === null || _a === void 0 ? void 0 : _a[key];
if (found === undefined && props.mismatches !== undefined)
props.mismatches.add(key);
return found ? OpenApiTypeCheckerBase.unreference(__assign(__assign({}, props), { schema: found })) : null;
};
OpenApiTypeCheckerBase.escape = function (props) {
var _a, _b;
return escapeSchema(__assign(__assign({}, props), { visited: new Map(), accessor: (_a = props.accessor) !== null && _a !== void 0 ? _a : "$input", refAccessor: (_b = props.refAccessor) !== null && _b !== void 0 ? _b : props.prefix
var reasons = [];
var result = unreferenceSchema({
prefix: props.prefix,
refAccessor: (_a = props.refAccessor) !== null && _a !== void 0 ? _a : "$input.".concat(props.prefix
.substring(2)
.split("/")
.filter(function (str) { return !!str.length; })
.join(".") })) || null;
.filter(function (s) { return !!s.length; })
.join(".")),
accessor: (_b = props.accessor) !== null && _b !== void 0 ? _b : "$input.schema",
components: props.components,
schema: props.schema,
reasons: reasons,
});
if (result === null)
return {
success: false,
error: {
method: props.method,
message: "failed to unreference due to unable to find.",
reasons: reasons,
},
};
return {
success: true,
value: result,
};
};
OpenApiTypeCheckerBase.escape = function (props) {
var _a, _b;
var reasons = [];
var result = escapeSchema(__assign(__assign({}, props), { reasons: reasons, visited: new Map(), accessor: (_a = props.accessor) !== null && _a !== void 0 ? _a : "$input.schema", refAccessor: (_b = props.refAccessor) !== null && _b !== void 0 ? _b : AccessorUtil_1.AccessorUtil.reference(props.prefix) })) || null;
if (result === null)
return {
success: false,
error: {
method: props.method,
message: "failed to escape some reference type(s) due to unable to find".concat(Number(props.recursive) === 0 ? " or recursive relationship" : "", "."),
reasons: reasons,
},
};
return {
success: true,
value: result,
};
};
OpenApiTypeCheckerBase.visit = function (props) {
var _a;
var _a, _b;
var already = new Set();
var refAccessor = (_a = props.refAccessor) !== null && _a !== void 0 ? _a : "$input.".concat(AccessorUtil_1.AccessorUtil.reference(props.prefix));
var next = function (schema, accessor) {
var e_1, _a;
var _b, _c, _d, _e;
var _b, _c, _d;
props.closure(schema, accessor);

@@ -158,3 +189,3 @@ if (OpenApiTypeCheckerBase.isReference(schema)) {

if (found !== undefined)
next(found, "".concat((_c = props.refAccessor) !== null && _c !== void 0 ? _c : props.prefix, "[").concat(JSON.stringify(key), "]"));
next(found, "".concat(refAccessor, "[").concat(JSON.stringify(key), "]"));
}

@@ -165,4 +196,4 @@ else if (OpenApiTypeCheckerBase.isOneOf(schema))

try {
for (var _f = __values(Object.entries((_d = schema.properties) !== null && _d !== void 0 ? _d : {})), _g = _f.next(); !_g.done; _g = _f.next()) {
var _h = __read(_g.value, 2), key = _h[0], value = _h[1];
for (var _e = __values(Object.entries((_c = schema.properties) !== null && _c !== void 0 ? _c : {})), _f = _e.next(); !_f.done; _f = _e.next()) {
var _g = __read(_f.value, 2), key = _g[0], value = _g[1];
next(value, "".concat(accessor, ".properties[").concat(JSON.stringify(key), "]"));

@@ -174,3 +205,3 @@ }

try {
if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
}

@@ -186,3 +217,3 @@ finally { if (e_1) throw e_1.error; }

else if (OpenApiTypeCheckerBase.isTuple(schema)) {
((_e = schema.prefixItems) !== null && _e !== void 0 ? _e : []).forEach(function (s, i) {
((_d = schema.prefixItems) !== null && _d !== void 0 ? _d : []).forEach(function (s, i) {
return next(s, "".concat(accessor, ".prefixItems[").concat(i, "]"));

@@ -195,3 +226,3 @@ });

};
next(props.schema, (_a = props.accessor) !== null && _a !== void 0 ? _a : "$input");
next(props.schema, (_b = props.accessor) !== null && _b !== void 0 ? _b : "$input.schema");
};

@@ -207,2 +238,28 @@ OpenApiTypeCheckerBase.covers = function (props) {

};
var unreferenceSchema = function (props) {
var _a;
if (OpenApiTypeCheckerBase.isReference(props.schema) === false)
return props.schema;
var key = props.schema.$ref.split(props.prefix).pop();
var found = (_a = props.components.schemas) === null || _a === void 0 ? void 0 : _a[key];
if (found === undefined) {
props.reasons.push({
schema: props.schema,
accessor: props.accessor,
message: "unable to find reference type ".concat(JSON.stringify(key), "."),
});
return null;
}
else if (OpenApiTypeCheckerBase.isReference(found) === false)
return found;
else if (props.first === key) {
props.reasons.push({
schema: props.schema,
accessor: props.accessor,
message: "recursive reference type ".concat(JSON.stringify(key), "."),
});
return null;
}
return unreferenceSchema(__assign(__assign({}, props), { accessor: "".concat(props.refAccessor, "[").concat(JSON.stringify(key), "]"), first: key }));
};
var escapeSchema = function (props) {

@@ -215,4 +272,7 @@ var _a, _b, _c, _d;

if (target === undefined) {
if (props.errors !== undefined)
props.errors.push("".concat(props.accessor, ": unable to find reference type ").concat(JSON.stringify(key), "."));
props.reasons.push({
schema: props.schema,
accessor: props.accessor,
message: "unable to find reference type ".concat(JSON.stringify(key), "."),
});
return null;

@@ -224,4 +284,13 @@ }

var depth = props.visited.get(key);
if (depth > props.recursive)
if (depth > props.recursive) {
if (props.recursive === 0) {
props.reasons.push({
schema: props.schema,
accessor: props.accessor,
message: "recursive reference type ".concat(JSON.stringify(key), "."),
});
return null;
}
return undefined;
}
props.visited.set(key, depth + 1);

@@ -228,0 +297,0 @@ var res = escapeSchema(__assign(__assign({}, props), { schema: target, accessor: "".concat(props.refAccessor, "[").concat(JSON.stringify(key), "]") }));

@@ -27,5 +27,3 @@ import { ILlmSchemaV3_1 } from "../structures/ILlmSchemaV3_1";

schema: ILlmSchemaV3_1;
accessor?: string;
refAccessor?: string;
}) => void;
}

@@ -67,6 +67,4 @@ "use strict";

schema: props.schema,
accessor: props.accessor,
refAccessor: props.refAccessor,
});
};
})(LlmTypeCheckerV3_1 || (exports.LlmTypeCheckerV3_1 = LlmTypeCheckerV3_1 = {}));

@@ -21,4 +21,3 @@ import { ILlmSchemaV3 } from "../structures/ILlmSchemaV3";

*
* @param schema Target schema to visit
* @param callback Callback function to apply
* @param props Target and callback function
*/

@@ -25,0 +24,0 @@ const visit: (props: {

@@ -54,4 +54,3 @@ "use strict";

*
* @param schema Target schema to visit
* @param callback Callback function to apply
* @param props Target and callback function
*/

@@ -61,3 +60,3 @@ LlmTypeCheckerV3.visit = function (props) {

var _b;
var accessor = (_b = props.accessor) !== null && _b !== void 0 ? _b : "$input";
var accessor = (_b = props.accessor) !== null && _b !== void 0 ? _b : "$input.schema";
props.closure(props.schema, accessor);

@@ -64,0 +63,0 @@ if (LlmTypeCheckerV3.isOneOf(props.schema))

@@ -20,3 +20,2 @@ "use strict";

exports.NamingConvention = void 0;
var StringUtil_1 = require("./StringUtil");
var NamingConvention;

@@ -112,3 +111,3 @@ (function (NamingConvention) {

if (piece_1.length)
ret += StringUtil_1.StringUtil.capitalize(piece_1);
ret += capitalize(piece_1);
}

@@ -119,3 +118,3 @@ }

if (last.length)
ret += StringUtil_1.StringUtil.capitalize(piece);
ret += capitalize(piece);
return prefix + escaper(ret);

@@ -125,1 +124,4 @@ };

})(NamingConvention || (exports.NamingConvention = NamingConvention = {}));
var capitalize = function (str) {
return str.length !== 0 ? str[0].toUpperCase() + str.slice(1).toLowerCase() : str;
};
import { OpenApi } from "../OpenApi";
import { IOpenApiSchemaError } from "../structures/IOpenApiSchemaError";
import { IResult } from "../typings/IResult";
export declare namespace OpenApiTypeChecker {

@@ -23,11 +25,11 @@ const isNull: (schema: OpenApi.IJsonSchema) => schema is OpenApi.IJsonSchema.INull;

recursive: false | number;
errors?: string[];
accessor?: string;
refAccessor?: string;
}) => OpenApi.IJsonSchema | null;
}) => IResult<OpenApi.IJsonSchema, IOpenApiSchemaError>;
const unreference: (props: {
components: OpenApi.IComponents;
schema: OpenApi.IJsonSchema;
mismatches?: Set<string>;
}) => OpenApi.IJsonSchema | null;
accessor?: string;
refAccessor?: string;
}) => IResult<OpenApi.IJsonSchema, IOpenApiSchemaError>;
const visit: (props: {

@@ -34,0 +36,0 @@ closure: (schema: OpenApi.IJsonSchema, accessor: string) => void;

@@ -68,11 +68,6 @@ "use strict";

OpenApiTypeChecker.escape = function (props) {
return OpenApiTypeCheckerBase_1.OpenApiTypeCheckerBase.escape(__assign(__assign({}, props), { prefix: "#/components/schemas/" }));
return OpenApiTypeCheckerBase_1.OpenApiTypeCheckerBase.escape(__assign(__assign({}, props), { prefix: "#/components/schemas/", method: "OpenApiTypeChecker.method" }));
};
OpenApiTypeChecker.unreference = function (props) {
return OpenApiTypeCheckerBase_1.OpenApiTypeCheckerBase.unreference({
prefix: "#/components/schemas/",
components: props.components,
schema: props.schema,
mismatches: props.mismatches,
});
return OpenApiTypeCheckerBase_1.OpenApiTypeCheckerBase.unreference(__assign(__assign({}, props), { prefix: "#/components/schemas/", method: "OpenApiTypeChecker.unreference" }));
};

@@ -79,0 +74,0 @@ OpenApiTypeChecker.visit = function (props) {

{
"name": "@samchon/openapi",
"version": "2.0.0-dev.20241201-2",
"version": "2.0.0-dev.20241202-2",
"description": "OpenAPI definitions and converters for 'typia' and 'nestia'.",

@@ -66,3 +66,3 @@ "main": "./lib/index.js",

"typescript-transform-paths": "^3.4.7",
"typia": "^7.0.0-dev.20241128",
"typia": "7.0.0-dev.20241201",
"uuid": "^10.0.0"

@@ -74,4 +74,5 @@ },

"src",
"README.md"
"README.md",
"LICENSE"
]
}

@@ -93,4 +93,4 @@ import { OpenApi } from "../OpenApi";

accessor: string,
): ILlmSchema.ModelSchema[Model] | null =>
LlmSchemaComposer.schema(props.model)({
): ILlmSchema.ModelSchema[Model] | null => {
const result = LlmSchemaComposer.schema(props.model)({
config: props.options as any,

@@ -100,6 +100,13 @@ schema: s,

$defs,
errors: props.errors,
accessor,
refAccessor: `$input.components.schemas`,
}) as ILlmSchema.ModelSchema[Model] | null;
});
if (result.success === false) {
props.errors.push(
...result.error.reasons.map((r) => `${r.accessor}: ${r.message}`),
);
return null;
}
return result.value as ILlmSchema.ModelSchema[Model];
};

@@ -106,0 +113,0 @@ const endpoint: string = `$input.paths[${JSON.stringify(props.route.path)}][${JSON.stringify(props.route.method)}]`;

import { OpenApi } from "../OpenApi";
import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
import { EndpointUtil } from "../utils/EndpointUtil";
import { Escaper } from "../utils/Escaper";
import { OpenApiTypeChecker } from "../utils/OpenApiTypeChecker";
import { StringUtil } from "../utils/StringUtil";

@@ -25,5 +25,5 @@ export namespace HttpMigrateApplicationComposer {

name:
StringUtil.pascal(`I/Api/${props.path}`) +
EndpointUtil.pascal(`I/Api/${props.path}`) +
"." +
StringUtil.pascal(`${props.method}/Body`),
EndpointUtil.pascal(`${props.method}/Body`),
schema,

@@ -37,5 +37,5 @@ }),

name:
StringUtil.pascal(`I/Api/${props.path}`) +
EndpointUtil.pascal(`I/Api/${props.path}`) +
"." +
StringUtil.pascal(`${props.method}/Response`),
EndpointUtil.pascal(`${props.method}/Response`),
schema,

@@ -173,5 +173,5 @@ }),

name:
StringUtil.pascal(`I/Api/${props.path}`) +
EndpointUtil.pascal(`I/Api/${props.path}`) +
"." +
StringUtil.pascal(`${props.method}/${type}`),
EndpointUtil.pascal(`${props.method}/${type}`),
schema: {

@@ -209,3 +209,3 @@ type: "object",

//----
const parameterNames: string[] = StringUtil.splitWithNormalization(
const parameterNames: string[] = EndpointUtil.splitWithNormalization(
props.emendedPath,

@@ -254,3 +254,3 @@ )

key: (() => {
let key: string = StringUtil.normalize(parameterNames[i]);
let key: string = EndpointUtil.normalize(parameterNames[i]);
if (Escaper.variable(key)) return key;

@@ -276,3 +276,3 @@ while (true) {

key: (() => {
let key: string = StringUtil.normalize(parameterNames[i]);
let key: string = EndpointUtil.normalize(parameterNames[i]);
if (Escaper.variable(key)) return key;

@@ -279,0 +279,0 @@ while (true) {

@@ -5,2 +5,4 @@ import { OpenApi } from "../../OpenApi";

import { ILlmSchemaV3_1 } from "../../structures/ILlmSchemaV3_1";
import { IOpenApiSchemaError } from "../../structures/IOpenApiSchemaError";
import { IResult } from "../../typings/IResult";
import { ChatGptTypeChecker } from "../../utils/ChatGptTypeChecker";

@@ -16,6 +18,6 @@ import { LlmTypeCheckerV3_1 } from "../../utils/LlmTypeCheckerV3_1";

schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference;
errors?: string[];
accessor?: string;
}): IChatGptSchema.IParameters | null => {
const params: ILlmSchemaV3_1.IParameters | null =
refAccessor?: string;
}): IResult<IChatGptSchema.IParameters, IOpenApiSchemaError> => {
const result: IResult<ILlmSchemaV3_1.IParameters, IOpenApiSchemaError> =
LlmSchemaV3_1Composer.parameters({

@@ -27,8 +29,11 @@ ...props,

},
validate: validate(props.errors),
validate,
});
if (params === null) return null;
for (const key of Object.keys(params.$defs))
params.$defs[key] = transform(params.$defs[key]);
return transform(params) as IChatGptSchema.IParameters;
if (result.success === false) return result;
for (const key of Object.keys(result.value.$defs))
result.value.$defs[key] = transform(result.value.$defs[key]);
return {
success: true,
value: transform(result.value) as IChatGptSchema.IParameters,
};
};

@@ -41,37 +46,40 @@

schema: OpenApi.IJsonSchema;
errors?: string[];
accessor?: string;
refAccessor?: string;
}): IChatGptSchema | null => {
}): IResult<IChatGptSchema, IOpenApiSchemaError> => {
const oldbie: Set<string> = new Set(Object.keys(props.$defs));
const schema: ILlmSchemaV3_1 | null = LlmSchemaV3_1Composer.schema({
...props,
config: {
reference: props.config.reference,
constraint: false,
},
validate: validate(props.errors),
});
if (schema === null) return null;
const result: IResult<ILlmSchemaV3_1, IOpenApiSchemaError> =
LlmSchemaV3_1Composer.schema({
...props,
config: {
reference: props.config.reference,
constraint: false,
},
validate,
});
if (result.success === false) return result;
for (const key of Object.keys(props.$defs))
if (oldbie.has(key) === false)
props.$defs[key] = transform(props.$defs[key]);
return transform(schema);
return {
success: true,
value: transform(result.value),
};
};
const validate =
(errors: string[] | undefined) =>
(schema: OpenApi.IJsonSchema, accessor: string): boolean => {
if (
OpenApiTypeChecker.isObject(schema) &&
!!schema.additionalProperties
) {
if (errors)
errors.push(
`${accessor}.additionalProperties: ChatGPT does not allow additionalProperties, the dynamic key typed object.`,
);
return false;
}
return true;
};
const validate = (
schema: OpenApi.IJsonSchema,
accessor: string,
): IOpenApiSchemaError.IReason[] => {
if (OpenApiTypeChecker.isObject(schema) && !!schema.additionalProperties)
return [
{
schema: schema,
accessor: `${accessor}.additionalProperties`,
message:
"ChatGPT does not allow additionalProperties, the dynamic key typed object.",
},
];
return [];
};

@@ -78,0 +86,0 @@ const transform = (schema: ILlmSchemaV3_1): IChatGptSchema => {

import { OpenApi } from "../../OpenApi";
import { IClaudeSchema } from "../../structures/IClaudeSchema";
import { ILlmFunction } from "../../structures/ILlmFunction";
import { IOpenApiSchemaError } from "../../structures/IOpenApiSchemaError";
import { IResult } from "../../typings/IResult";
import { LlmSchemaV3_1Composer } from "./LlmSchemaV3_1Composer";

@@ -11,5 +13,5 @@

schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference;
errors?: string[];
accessor?: string;
}): IClaudeSchema.IParameters | null =>
refAccessor?: string;
}): IResult<IClaudeSchema.IParameters, IOpenApiSchemaError> =>
LlmSchemaV3_1Composer.parameters({

@@ -28,6 +30,5 @@ ...props,

schema: OpenApi.IJsonSchema;
errors?: string[];
accessor?: string;
refAccessor?: string;
}): IClaudeSchema | null =>
}): IResult<IClaudeSchema, IOpenApiSchemaError> =>
LlmSchemaV3_1Composer.schema({

@@ -34,0 +35,0 @@ ...props,

@@ -7,5 +7,7 @@ import { OpenApi } from "../../OpenApi";

import { ILlmSchemaV3 } from "../../structures/ILlmSchemaV3";
import { IOpenApiSchemaError } from "../../structures/IOpenApiSchemaError";
import { IResult } from "../../typings/IResult";
import { LlmTypeCheckerV3 } from "../../utils/LlmTypeCheckerV3";
import { OpenApiTypeChecker } from "../../utils/OpenApiTypeChecker";
import { LlmParametersFinder } from "../llm/LlmParametersFinder";
import { LlmParametersFinder } from "./LlmParametersComposer";
import { LlmSchemaV3Composer } from "./LlmSchemaV3Composer";

@@ -18,12 +20,15 @@

schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference;
errors?: string[];
accessor?: string;
}): IGeminiSchema.IParameters | null => {
const entity: OpenApi.IJsonSchema.IObject | null =
LlmParametersFinder.find(props);
if (entity === null) return null;
refAccessor?: string;
}): IResult<IGeminiSchema.IParameters, IOpenApiSchemaError> => {
const entity: IResult<OpenApi.IJsonSchema.IObject, IOpenApiSchemaError> =
LlmParametersFinder.parameters({
...props,
method: "GeminiSchemaComposer.parameters",
});
if (entity.success === false) return entity;
return schema({
...props,
schema: entity,
}) as IGeminiSchema.IParameters | null;
schema: entity.value,
}) as IResult<IGeminiSchema.IParameters, IOpenApiSchemaError>;
};

@@ -35,37 +40,42 @@

schema: OpenApi.IJsonSchema;
errors?: string[];
accessor?: string;
}): IGeminiSchema | null => {
refAccessor?: string;
}): IResult<IGeminiSchema, IOpenApiSchemaError> => {
// TRANSFORM TO LLM SCHEMA OF V3.0
const schema: ILlmSchemaV3 | null = LlmSchemaV3Composer.schema({
...props,
config: {
recursive: props.config.recursive,
constraint: false,
},
validate: (next, accessor): boolean => {
if (OpenApiTypeChecker.isObject(next)) {
if (!!next.additionalProperties) {
if (props.errors)
props.errors.push(
`${accessor}.additionalProperties: Gemini does not allow additionalProperties, the dynamic key typed object.`,
);
return false;
}
} else if (
OpenApiTypeChecker.isOneOf(next) &&
isOneOf(props.components)(next)
) {
if (props.errors)
props.errors.push(`${accessor}: Gemini does not allow union type.`);
return false;
}
return true;
},
});
if (schema === null) return null;
const result: IResult<ILlmSchemaV3, IOpenApiSchemaError> =
LlmSchemaV3Composer.schema({
...props,
config: {
recursive: props.config.recursive,
constraint: false,
},
validate: (next, accessor): IOpenApiSchemaError.IReason[] => {
if (OpenApiTypeChecker.isObject(next)) {
if (!!next.additionalProperties)
return [
{
schema: next,
accessor: `${accessor}.additionalProperties`,
message: "Gemini does not allow additionalProperties.",
},
];
} else if (
OpenApiTypeChecker.isOneOf(next) &&
isOneOf(props.components)(next)
)
return [
{
schema: next,
accessor: accessor,
message: "Gemini does not allow union type.",
},
];
return [];
},
});
if (result.success === false) return result;
// SPECIALIZATIONS
LlmTypeCheckerV3.visit({
schema,
schema: result.value,
closure: (v) => {

@@ -91,7 +101,6 @@ if (v.title !== undefined) {

},
accessor: props.accessor,
});
// DO NOT ALLOW UNION TYPE
return schema as IGeminiSchema;
return result;
};

@@ -98,0 +107,0 @@

import { OpenApi } from "../../OpenApi";
import { ILlamaSchema } from "../../structures/ILlamaSchema";
import { ILlmFunction } from "../../structures/ILlmFunction";
import { IOpenApiSchemaError } from "../../structures/IOpenApiSchemaError";
import { IResult } from "../../typings/IResult";
import { LlmSchemaV3_1Composer } from "./LlmSchemaV3_1Composer";

@@ -11,5 +13,3 @@

schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference;
errors?: string[];
accessor?: string;
}): ILlamaSchema.IParameters | null =>
}): IResult<ILlamaSchema.IParameters, IOpenApiSchemaError> =>
LlmSchemaV3_1Composer.parameters({

@@ -28,6 +28,3 @@ ...props,

schema: OpenApi.IJsonSchema;
errors?: string[];
accessor?: string;
refAccessor?: string;
}): ILlamaSchema | null =>
}): IResult<ILlamaSchema, IOpenApiSchemaError> =>
LlmSchemaV3_1Composer.schema({

@@ -34,0 +31,0 @@ ...props,

import { OpenApi } from "../../OpenApi";
import { ILlmFunction } from "../../structures/ILlmFunction";
import { ILlmSchemaV3_1 } from "../../structures/ILlmSchemaV3_1";
import { IOpenApiSchemaError } from "../../structures/IOpenApiSchemaError";
import { IResult } from "../../typings/IResult";
import { LlmTypeCheckerV3_1 } from "../../utils/LlmTypeCheckerV3_1";

@@ -8,3 +10,3 @@ import { OpenApiContraintShifter } from "../../utils/OpenApiContraintShifter";

import { JsonDescriptionUtil } from "../../utils/internal/JsonDescriptionUtil";
import { LlmParametersFinder } from "./LlmParametersFinder";
import { LlmParametersFinder } from "./LlmParametersComposer";

@@ -17,27 +19,32 @@ export namespace LlmSchemaV3_1Composer {

errors?: string[];
/** @internal */
validate?: (
input: OpenApi.IJsonSchema,
accessor: string,
) => IOpenApiSchemaError.IReason[];
accessor?: string;
validate?: (input: OpenApi.IJsonSchema, accessor: string) => boolean;
}): ILlmSchemaV3_1.IParameters | null => {
const entity: OpenApi.IJsonSchema.IObject | null =
LlmParametersFinder.find(props);
if (entity === null) return null;
else if (!!entity.additionalProperties) {
if (props.errors)
props.errors.push(
`${props.accessor ?? "$input"}.additionalProperties: LLM does not allow additional properties on parameters.`,
);
return null;
}
refAccessor?: string;
}): IResult<ILlmSchemaV3_1.IParameters, IOpenApiSchemaError> => {
const entity: IResult<OpenApi.IJsonSchema.IObject, IOpenApiSchemaError> =
LlmParametersFinder.parameters({
...props,
method: "LlmSchemaV3_1Composer.parameters",
});
if (entity.success === false) return entity;
const $defs: Record<string, ILlmSchemaV3_1> = {};
const res: ILlmSchemaV3_1.IParameters | null = schema({
const result: IResult<ILlmSchemaV3_1, IOpenApiSchemaError> = schema({
...props,
$defs,
schema: entity,
refAccessor: props.accessor ? `${props.accessor}/$defs` : undefined,
}) as ILlmSchemaV3_1.IParameters | null;
if (res === null) return null;
res.$defs = $defs;
res.additionalProperties = false;
return res;
schema: entity.value,
});
if (result.success === false) return result;
return {
success: true,
value: {
...(result.value as ILlmSchemaV3_1.IObject),
additionalProperties: false,
$defs,
} satisfies ILlmSchemaV3_1.IParameters,
};
};

@@ -50,7 +57,10 @@

schema: OpenApi.IJsonSchema;
errors?: string[];
/** @internal */
validate?: (
input: OpenApi.IJsonSchema,
accessor: string,
) => IOpenApiSchemaError.IReason[];
accessor?: string;
refAccessor?: string;
validate?: (input: OpenApi.IJsonSchema, accessor: string) => boolean;
}): ILlmSchemaV3_1 | null => {
}): IResult<ILlmSchemaV3_1, IOpenApiSchemaError> => {
const union: Array<ILlmSchemaV3_1 | null> = [];

@@ -69,24 +79,24 @@ const attribute: ILlmSchemaV3_1.__IAttribute = {

let valid: boolean = true;
const reasons: IOpenApiSchemaError.IReason[] = [];
OpenApiTypeChecker.visit({
closure: (next, accessor) => {
if (props.validate && props.validate(next, accessor) === false) {
if (props.validate) {
// CUSTOM VALIDATION
valid &&= false;
reasons.push(...props.validate(next, accessor));
}
if (OpenApiTypeChecker.isTuple(next)) {
// TUPLE IS BANNED
if (props.errors !== undefined)
props.errors.push(`${accessor}: LLM does not allow tuple type.`);
valid &&= false;
} else if (OpenApiTypeChecker.isReference(next)) {
if (OpenApiTypeChecker.isTuple(next))
reasons.push({
schema: next,
accessor: accessor,
message: `LLM does not allow tuple type.`,
});
else if (OpenApiTypeChecker.isReference(next)) {
// UNABLE TO FIND MATCHED REFERENCE
const key = next.$ref.split("#/components/schemas/")[1];
if (props.components.schemas?.[key] === undefined) {
if (props.errors !== undefined)
props.errors.push(
`${accessor}: unable to find reference type ${JSON.stringify(key)}.`,
);
valid &&= false;
}
if (props.components.schemas?.[key] === undefined)
reasons.push({
schema: next,
accessor: accessor,
message: `unable to find reference type ${JSON.stringify(key)}.`,
});
}

@@ -96,6 +106,14 @@ },

schema: props.schema,
accessor: props.accessor ?? "$input.schema",
refAccessor: props.refAccessor ?? "$input.components.schemas",
accessor: props.accessor,
refAccessor: props.refAccessor,
});
if ((valid as boolean) === false) return null;
if (reasons.length > 0)
return {
success: false,
error: {
method: "LlmSchemaV3_1Composer.schema",
message: "Failed to compose LLM schema of v3.1",
reasons,
},
};

@@ -129,13 +147,13 @@ const visit = (input: OpenApi.IJsonSchema, accessor: string): number => {

props.$defs[key] = {};
const converted: ILlmSchemaV3_1 | null = schema({
config: props.config,
components: props.components,
$defs: props.$defs,
schema: target,
errors: props.errors,
refAccessor: props.refAccessor,
accessor: `${props.refAccessor ?? "$def"}[${JSON.stringify(key)}]`,
});
if (converted === null) return union.push(null);
props.$defs[key] = converted;
const converted: IResult<ILlmSchemaV3_1, IOpenApiSchemaError> =
schema({
config: props.config,
components: props.components,
$defs: props.$defs,
schema: target,
refAccessor: props.refAccessor,
accessor: `${props.refAccessor ?? "$def"}[${JSON.stringify(key)}]`,
});
if (converted.success === false) return union.push(null); // UNREACHABLE
props.$defs[key] = converted.value;
return out();

@@ -172,12 +190,14 @@ } else {

(acc, [key, value]) => {
const converted: ILlmSchemaV3_1 | null = schema({
config: props.config,
components: props.components,
$defs: props.$defs,
schema: value,
errors: props.errors,
refAccessor: props.refAccessor,
accessor: `${accessor}.properties[${JSON.stringify(key)}]`,
});
acc[key] = converted;
const converted: IResult<ILlmSchemaV3_1, IOpenApiSchemaError> =
schema({
config: props.config,
components: props.components,
$defs: props.$defs,
schema: value,
refAccessor: props.refAccessor,
accessor: `${accessor}.properties[${JSON.stringify(key)}]`,
});
acc[key] = converted.success ? converted.value : null;
if (converted.success === false)
reasons.push(...converted.error.reasons);
return acc;

@@ -193,6 +213,9 @@ },

| null
| undefined =
typeof input.additionalProperties === "object" &&
input.additionalProperties !== null
? schema({
| undefined = (() => {
if (
typeof input.additionalProperties === "object" &&
input.additionalProperties !== null
) {
const converted: IResult<ILlmSchemaV3_1, IOpenApiSchemaError> =
schema({
config: props.config,

@@ -202,7 +225,13 @@ components: props.components,

schema: input.additionalProperties,
errors: props.errors,
refAccessor: props.refAccessor,
accessor: `${accessor}.additionalProperties`,
})
: input.additionalProperties;
});
if (converted.success === false) {
reasons.push(...converted.error.reasons);
return null;
}
return converted.value;
}
return input.additionalProperties;
})();
if (additionalProperties === null) return union.push(null);

@@ -216,3 +245,3 @@ return union.push({

} else if (OpenApiTypeChecker.isArray(input)) {
const items: ILlmSchemaV3_1 | null = schema({
const items: IResult<ILlmSchemaV3_1, IOpenApiSchemaError> = schema({
config: props.config,

@@ -222,7 +251,9 @@ components: props.components,

schema: input.items,
errors: props.errors,
refAccessor: props.refAccessor,
accessor: `${accessor}.items`,
});
if (items === null) return union.push(null);
if (items.success === false) {
reasons.push(...items.error.reasons);
return union.push(null);
}
return union.push(

@@ -234,3 +265,3 @@ (props.config.constraint

...input,
items,
items: items.value,
}),

@@ -265,24 +296,41 @@ );

if (union.some((u) => u === null)) return null;
if (union.some((u) => u === null))
return {
success: false,
error: {
method: "LlmSchemaV3_1Composer.schema",
message: "Failed to compose LLM schema of v3.1",
reasons,
},
};
else if (union.length === 0)
return {
...attribute,
type: undefined,
success: true,
value: {
...attribute,
type: undefined,
},
};
else if (union.length === 1)
return {
...attribute,
...union[0]!,
description: LlmTypeCheckerV3_1.isReference(union[0]!)
? undefined
: union[0]!.description,
success: true,
value: {
...attribute,
...union[0]!,
description: LlmTypeCheckerV3_1.isReference(union[0]!)
? undefined
: union[0]!.description,
},
};
return {
...attribute,
oneOf: union.map((u) => ({
...u!,
description: LlmTypeCheckerV3_1.isReference(u!)
? undefined
: u!.description,
})),
success: true,
value: {
...attribute,
oneOf: union.map((u) => ({
...u!,
description: LlmTypeCheckerV3_1.isReference(u!)
? undefined
: u!.description,
})),
},
};

@@ -289,0 +337,0 @@ };

@@ -5,6 +5,8 @@ import { OpenApi } from "../../OpenApi";

import { ILlmSchemaV3 } from "../../structures/ILlmSchemaV3";
import { IOpenApiSchemaError } from "../../structures/IOpenApiSchemaError";
import { IResult } from "../../typings/IResult";
import { LlmTypeCheckerV3 } from "../../utils/LlmTypeCheckerV3";
import { OpenApiContraintShifter } from "../../utils/OpenApiContraintShifter";
import { OpenApiTypeChecker } from "../../utils/OpenApiTypeChecker";
import { LlmParametersFinder } from "./LlmParametersFinder";
import { LlmParametersFinder } from "./LlmParametersComposer";

@@ -16,21 +18,29 @@ export namespace LlmSchemaV3Composer {

schema: OpenApi.IJsonSchema.IObject | OpenApi.IJsonSchema.IReference;
errors?: string[];
/** @internal */
validate?: (
schema: OpenApi.IJsonSchema,
accessor: string,
) => IOpenApiSchemaError.IReason[];
accessor?: string;
}): ILlmSchemaV3.IParameters | null => {
const entity: OpenApi.IJsonSchema.IObject | null =
LlmParametersFinder.find(props);
if (entity === null) return null;
else if (!!entity.additionalProperties) {
if (props.errors)
props.errors.push(
`${props.accessor ?? "$input"}.additionalProperties: LLM does not allow additional properties on parameters.`,
);
return null;
}
const res = schema({
refAccessor?: string;
}): IResult<ILlmSchemaV3.IParameters, IOpenApiSchemaError> => {
const entity: IResult<OpenApi.IJsonSchema.IObject, IOpenApiSchemaError> =
LlmParametersFinder.parameters({
...props,
method: "LlmSchemaV3Composer.parameters",
});
if (entity.success === false) return entity;
const result: IResult<ILlmSchemaV3, IOpenApiSchemaError> = schema({
...props,
schema: entity,
}) as ILlmSchemaV3.IParameters | null;
if (res !== null) res.additionalProperties = false;
return res;
schema: entity.value,
});
if (result.success === false) return result;
return {
success: true,
value: {
...(result.value as ILlmSchemaV3.IObject),
additionalProperties: false,
} satisfies ILlmSchemaV3.IParameters,
};
};

@@ -42,28 +52,30 @@

schema: OpenApi.IJsonSchema;
errors?: string[];
/** @internal */
validate?: (
schema: OpenApi.IJsonSchema,
accessor: string,
) => IOpenApiSchemaError.IReason[];
accessor?: string;
refAccessor?: string;
validate?: (schema: OpenApi.IJsonSchema, accessor: string) => boolean;
}): ILlmSchemaV3 | null => {
}): IResult<ILlmSchemaV3, IOpenApiSchemaError> => {
// CHECK TUPLE TYPE
let valid: boolean = true;
const reasons: IOpenApiSchemaError.IReason[] = [];
OpenApiTypeChecker.visit({
closure: (next, accessor) => {
if (props.validate && props.validate(next, accessor) === false)
valid &&= false;
if (OpenApiTypeChecker.isTuple(next)) {
if (props.errors)
props.errors.push(
`${accessor ?? "$input"}: LLM does not allow tuple type.`,
);
valid &&= false;
} else if (OpenApiTypeChecker.isReference(next)) {
if (props.validate) reasons.push(...props.validate(next, accessor));
if (OpenApiTypeChecker.isTuple(next))
reasons.push({
accessor: accessor,
schema: next,
message: "LLM does not allow tuple type.",
});
else if (OpenApiTypeChecker.isReference(next)) {
// UNABLE TO FIND MATCHED REFERENCE
const key = next.$ref.split("#/components/schemas/")[1];
if (props.components.schemas?.[key] === undefined) {
if (props.errors !== undefined)
props.errors.push(
`${accessor}: unable to find reference type ${JSON.stringify(key)}.`,
);
valid &&= false;
reasons.push({
schema: next,
message: `${accessor}: unable to find reference type ${JSON.stringify(key)}.`,
accessor: accessor,
});
}

@@ -74,13 +86,32 @@ }

schema: props.schema,
accessor: props.accessor ?? "$input.schema",
refAccessor: props.refAccessor ?? "$input.components.schemas",
accessor: props.accessor,
refAccessor: props.refAccessor,
});
if ((valid as boolean) === false) return null;
// if ((valid as boolean) === false) return null;
if (reasons.length > 0)
return {
success: false,
error: {
method: "LlmSchemaV3Composer.schema",
message: "Failed to compose LLM schema of v3",
reasons,
},
};
// CHECK MISMATCHES
const schema: OpenApi.IJsonSchema | null = OpenApiTypeChecker.escape({
...props,
recursive: props.config.recursive,
});
if (schema === null) return null; // UNREACHABLE
const escaped: IResult<OpenApi.IJsonSchema, IOpenApiSchemaError> =
OpenApiTypeChecker.escape({
...props,
recursive: props.config.recursive,
});
if (escaped.success === false)
// UNREACHABLE
return {
success: false,
error: {
method: "LlmSchemaV3Composer.schema",
message: "Failed to compose LLM schema of v3",
reasons: escaped.error.reasons,
},
};

@@ -93,3 +124,3 @@ // SPECIALIZATIONS

downgraded: {},
})(schema) as ILlmSchemaV3;
})(escaped.value) as ILlmSchemaV3;
LlmTypeCheckerV3.visit({

@@ -128,3 +159,6 @@ closure: (next) => {

});
return downgraded;
return {
success: true,
value: downgraded,
};
};

@@ -131,0 +165,0 @@

import { OpenApi } from "../../OpenApi";
import { IHttpMigrateApplication } from "../../structures/IHttpMigrateApplication";
import { IHttpMigrateRoute } from "../../structures/IHttpMigrateRoute";
import { StringUtil } from "../../utils/StringUtil";
import { EndpointUtil } from "../../utils/EndpointUtil";
import { HttpMigrateApplicationComposer } from "../HttpMigrateApplicationComposer";

@@ -27,3 +27,3 @@ import { MigrateRouteAccessor } from "./MigrateRouteAccessor";

path,
emendedPath: StringUtil.reJoinWithDecimalParameters(path),
emendedPath: EndpointUtil.reJoinWithDecimalParameters(path),
operation,

@@ -30,0 +30,0 @@ });

import { IHttpMigrateRoute } from "../../structures/IHttpMigrateRoute";
import { EndpointUtil } from "../../utils/EndpointUtil";
import { Escaper } from "../../utils/Escaper";
import { MapUtil } from "../../utils/MapUtil";
import { StringUtil } from "../../utils/StringUtil";

@@ -12,3 +12,3 @@ export namespace MigrateRouteAccessor {

.filter((str) => !!str.length && str[0] !== ":")
.map(StringUtil.normalize)
.map(EndpointUtil.normalize)
.map((str) => (Escaper.variable(str) ? str : `_${str}`)),

@@ -18,8 +18,8 @@ )(routes) as Map<string, IElement>;

props.entries.forEach((entry, i) => {
entry.alias = StringUtil.escapeDuplicate(
entry.alias = EndpointUtil.escapeDuplicate(
[
...props.children,
...props.entries.filter((_, j) => i !== j).map((e) => e.alias),
].map(StringUtil.normalize),
)(StringUtil.normalize(entry.alias));
].map(EndpointUtil.normalize),
)(EndpointUtil.normalize(entry.alias));
entry.route.accessor = [...props.namespace, entry.alias];

@@ -35,3 +35,3 @@

(p, i) =>
(p.key = StringUtil.escapeDuplicate([
(p.key = EndpointUtil.escapeDuplicate([
"connection",

@@ -87,3 +87,3 @@ entry.alias,

"By" +
op.parameters.map((p) => StringUtil.capitalize(p.key)).join("And")
op.parameters.map((p) => EndpointUtil.capitalize(p.key)).join("And")
);

@@ -90,0 +90,0 @@ };

@@ -26,2 +26,5 @@ //----

//----
export * from "./typings/IResult";
export * from "./structures/IOpenApiSchemaError";
export * from "./structures/IHttpLlmApplication";

@@ -28,0 +31,0 @@ export * from "./structures/IHttpLlmFunction";

@@ -71,2 +71,3 @@ import { IChatGptSchema } from "../structures/IChatGptSchema";

const already: Set<string> = new Set();
const refAccessor: string = props.refAccessor ?? "$input.$defs";
const next = (schema: IChatGptSchema, accessor: string): void => {

@@ -79,4 +80,3 @@ props.closure(schema, accessor);

const found: IChatGptSchema | undefined = props.$defs?.[key];
if (found !== undefined)
next(found, `${props.refAccessor ?? "$defs"}[${key}]`);
if (found !== undefined) next(found, `${refAccessor}[${key}]`);
} else if (ChatGptTypeChecker.isAnyOf(schema))

@@ -90,3 +90,3 @@ schema.anyOf.forEach((s, i) => next(s, `${accessor}.anyOf[${i}]`));

};
next(props.schema, props.accessor ?? "$input");
next(props.schema, props.accessor ?? "$input.schemas");
};

@@ -93,0 +93,0 @@

@@ -19,3 +19,3 @@ import { IGeminiSchema } from "../structures/IGeminiSchema";

}): void => {
const accessor: string = props.accessor ?? "$input";
const accessor: string = props.accessor ?? "$input.schema";
props.closure(props.schema, accessor);

@@ -22,0 +22,0 @@ if (isObject(props.schema))

import { OpenApi } from "../../OpenApi";
import { IOpenApiSchemaError } from "../../structures/IOpenApiSchemaError";
import { IResult } from "../../typings/IResult";
import { AccessorUtil } from "../AccessorUtil";
import { MapUtil } from "../MapUtil";

@@ -104,13 +107,36 @@ import { JsonDescriptionUtil } from "./JsonDescriptionUtil";

prefix: string;
method: string;
components: OpenApi.IComponents;
schema: OpenApi.IJsonSchema;
mismatches: Set<string> | undefined;
}): OpenApi.IJsonSchema | null => {
if (isReference(props.schema) === false) return props.schema;
const key: string = props.schema.$ref.split(props.prefix).pop()!;
const found: OpenApi.IJsonSchema | undefined =
props.components.schemas?.[key];
if (found === undefined && props.mismatches !== undefined)
props.mismatches.add(key);
return found ? unreference({ ...props, schema: found }) : null;
accessor?: string;
refAccessor?: string;
}): IResult<OpenApi.IJsonSchema, IOpenApiSchemaError> => {
const reasons: IOpenApiSchemaError.IReason[] = [];
const result: OpenApi.IJsonSchema | null = unreferenceSchema({
prefix: props.prefix,
refAccessor:
props.refAccessor ??
`$input.${props.prefix
.substring(2)
.split("/")
.filter((s) => !!s.length)
.join(".")}`,
accessor: props.accessor ?? "$input.schema",
components: props.components,
schema: props.schema,
reasons,
});
if (result === null)
return {
success: false,
error: {
method: props.method,
message: `failed to unreference due to unable to find.`,
reasons,
},
};
return {
success: true,
value: result,
};
};

@@ -120,21 +146,32 @@

prefix: string;
method: string;
components: OpenApi.IComponents;
schema: OpenApi.IJsonSchema;
recursive: false | number;
errors?: string[];
accessor?: string;
refAccessor?: string;
}): OpenApi.IJsonSchema | null =>
escapeSchema({
...props,
visited: new Map(),
accessor: props.accessor ?? "$input",
refAccessor:
props.refAccessor ??
props.prefix
.substring(2)
.split("/")
.filter((str) => !!str.length)
.join("."),
}) || null;
}): IResult<OpenApi.IJsonSchema, IOpenApiSchemaError> => {
const reasons: IOpenApiSchemaError.IReason[] = [];
const result: OpenApi.IJsonSchema | null =
escapeSchema({
...props,
reasons,
visited: new Map(),
accessor: props.accessor ?? "$input.schema",
refAccessor: props.refAccessor ?? AccessorUtil.reference(props.prefix),
}) || null;
if (result === null)
return {
success: false,
error: {
method: props.method,
message: `failed to escape some reference type(s) due to unable to find${Number(props.recursive) === 0 ? " or recursive relationship" : ""}.`,
reasons,
},
};
return {
success: true,
value: result,
};
};

@@ -150,2 +187,4 @@ export const visit = (props: {

const already: Set<string> = new Set();
const refAccessor: string =
props.refAccessor ?? `$input.${AccessorUtil.reference(props.prefix)}`;
const next = (schema: OpenApi.IJsonSchema, accessor: string): void => {

@@ -160,6 +199,3 @@ props.closure(schema, accessor);

if (found !== undefined)
next(
found,
`${props.refAccessor ?? props.prefix}[${JSON.stringify(key)}]`,
);
next(found, `${refAccessor}[${JSON.stringify(key)}]`);
} else if (isOneOf(schema))

@@ -187,3 +223,3 @@ schema.oneOf.forEach((s, i) => next(s, `${accessor}.oneOf[${i}]`));

};
next(props.schema, props.accessor ?? "$input");
next(props.schema, props.accessor ?? "$input.schema");
};

@@ -205,2 +241,38 @@

const unreferenceSchema = (props: {
prefix: string;
refAccessor: string;
accessor: string;
components: OpenApi.IComponents;
schema: OpenApi.IJsonSchema;
reasons: IOpenApiSchemaError.IReason[];
first?: string;
}): OpenApi.IJsonSchema | null => {
if (isReference(props.schema) === false) return props.schema;
const key: string = props.schema.$ref.split(props.prefix).pop()!;
const found: OpenApi.IJsonSchema | undefined =
props.components.schemas?.[key];
if (found === undefined) {
props.reasons.push({
schema: props.schema,
accessor: props.accessor,
message: `unable to find reference type ${JSON.stringify(key)}.`,
});
return null;
} else if (isReference(found) === false) return found;
else if (props.first === key) {
props.reasons.push({
schema: props.schema,
accessor: props.accessor,
message: `recursive reference type ${JSON.stringify(key)}.`,
});
return null;
}
return unreferenceSchema({
...props,
accessor: `${props.refAccessor}[${JSON.stringify(key)}]`,
first: key,
});
};
const escapeSchema = (props: {

@@ -212,3 +284,3 @@ components: OpenApi.IComponents;

visited: Map<string, number>;
errors?: string[];
reasons: IOpenApiSchemaError.IReason[];
accessor: string;

@@ -223,6 +295,7 @@ refAccessor: string;

if (target === undefined) {
if (props.errors !== undefined)
props.errors.push(
`${props.accessor}: unable to find reference type ${JSON.stringify(key)}.`,
);
props.reasons.push({
schema: props.schema,
accessor: props.accessor,
message: `unable to find reference type ${JSON.stringify(key)}.`,
});
return null;

@@ -232,3 +305,13 @@ } else if (props.visited.has(key) === true) {

const depth: number = props.visited.get(key)!;
if (depth > props.recursive) return undefined;
if (depth > props.recursive) {
if (props.recursive === 0) {
props.reasons.push({
schema: props.schema,
accessor: props.accessor,
message: `recursive reference type ${JSON.stringify(key)}.`,
});
return null;
}
return undefined;
}
props.visited.set(key, depth + 1);

@@ -235,0 +318,0 @@ const res: OpenApi.IJsonSchema | null | undefined = escapeSchema({

@@ -93,4 +93,2 @@ import { ILlmSchemaV3_1 } from "../structures/ILlmSchemaV3_1";

schema: ILlmSchemaV3_1;
accessor?: string;
refAccessor?: string;
}): void =>

@@ -104,5 +102,3 @@ OpenApiTypeCheckerBase.visit({

schema: props.schema,
accessor: props.accessor,
refAccessor: props.refAccessor,
});
}

@@ -25,4 +25,3 @@ import { ILlmSchemaV3 } from "../structures/ILlmSchemaV3";

*
* @param schema Target schema to visit
* @param callback Callback function to apply
* @param props Target and callback function
*/

@@ -34,3 +33,3 @@ export const visit = (props: {

}): void => {
const accessor: string = props.accessor ?? "$input";
const accessor: string = props.accessor ?? "$input.schema";
props.closure(props.schema, accessor);

@@ -37,0 +36,0 @@ if (isOneOf(props.schema))

@@ -1,3 +0,1 @@

import { StringUtil } from "./StringUtil";
export namespace NamingConvention {

@@ -80,3 +78,3 @@ export function snake(str: string): string {

const piece: string = str.substring(prevFirst + prevLength, first);
if (piece.length) ret += StringUtil.capitalize(piece);
if (piece.length) ret += capitalize(piece);
}

@@ -86,5 +84,8 @@ }

const piece: string = str.substring(last[0] + last[1]);
if (last.length) ret += StringUtil.capitalize(piece);
if (last.length) ret += capitalize(piece);
return prefix + escaper(ret);
};
}
const capitalize = (str: string): string =>
str.length !== 0 ? str[0].toUpperCase() + str.slice(1).toLowerCase() : str;
import { OpenApi } from "../OpenApi";
import { IOpenApiSchemaError } from "../structures/IOpenApiSchemaError";
import { IResult } from "../typings/IResult";
import { OpenApiTypeCheckerBase } from "./internal/OpenApiTypeCheckerBase";

@@ -85,9 +87,9 @@

recursive: false | number;
errors?: string[];
accessor?: string;
refAccessor?: string;
}): OpenApi.IJsonSchema | null =>
}): IResult<OpenApi.IJsonSchema, IOpenApiSchemaError> =>
OpenApiTypeCheckerBase.escape({
...props,
prefix: "#/components/schemas/",
method: "OpenApiTypeChecker.method",
});

@@ -98,9 +100,9 @@

schema: OpenApi.IJsonSchema;
mismatches?: Set<string>;
}): OpenApi.IJsonSchema | null =>
accessor?: string;
refAccessor?: string;
}): IResult<OpenApi.IJsonSchema, IOpenApiSchemaError> =>
OpenApiTypeCheckerBase.unreference({
...props,
prefix: "#/components/schemas/",
components: props.components,
schema: props.schema,
mismatches: props.mismatches,
method: "OpenApiTypeChecker.unreference",
});

@@ -107,0 +109,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc