New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@samchon/openapi

Package Overview
Dependencies
Maintainers
0
Versions
182
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.20241113 to 2.0.0-dev.20241119

9

lib/converters/ChatGptConverter.d.ts
import { OpenApi } from "../OpenApi";
import { IChatGptSchema } from "../structures/IChatGptSchema";
export declare namespace ChatGptConverter {
const parameters: (props: {
components: OpenApi.IComponents;
schema: OpenApi.IJsonSchema.IObject;
}) => IChatGptSchema.IParameters | null;
const schema: (props: {
components: OpenApi.IComponents;
schema: OpenApi.IJsonSchema;
}) => IChatGptSchema.ITop | null;
$defs: Record<string, IChatGptSchema>;
}) => IChatGptSchema | null;
const separate: (props: {
top: IChatGptSchema.ITop;
$defs: Record<string, IChatGptSchema>;
predicate: (schema: IChatGptSchema) => boolean;

@@ -11,0 +16,0 @@ schema: IChatGptSchema;

@@ -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,5 +56,5 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;

(function (ChatGptConverter) {
ChatGptConverter.schema = function (props) {
ChatGptConverter.parameters = function (props) {
var $defs = {};
var schema = convertSchema({
var res = ChatGptConverter.schema({
components: props.components,

@@ -55,118 +64,268 @@ schema: props.schema,

});
if (schema === null)
if (res === null)
return null;
else if (Object.keys($defs).length)
schema.$defs = $defs;
return schema;
res.$defs = $defs;
return res;
};
var convertSchema = function (props) {
var _a;
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isReference(props.schema)) {
var key_1 = props.schema.$ref.split("#/components/schemas/")[1];
var target = (_a = props.components.schemas) === null || _a === void 0 ? void 0 : _a[key_1];
if (target === undefined)
return null;
var out = function () { return (__assign(__assign({}, props.schema), { $ref: "#/$defs/".concat(key_1) })); };
if (props.$defs[key_1] !== undefined)
ChatGptConverter.schema = function (props) {
var union = [];
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 _b = __read(_a, 2), key = _b[0], value = _b[1];
return key.startsWith("x-") && value !== undefined;
})));
var visit = function (input) {
var _a;
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isReference(props.schema)) {
var key_1 = props.schema.$ref.split("#/components/schemas/")[1];
var target = (_a = props.components.schemas) === null || _a === void 0 ? void 0 : _a[key_1];
if (target === undefined)
return 0;
var out = function () {
return union.push(__assign(__assign({}, props.schema), { $ref: "#/$defs/".concat(key_1) }));
};
if (props.$defs[key_1] !== undefined)
return out();
props.$defs[key_1] = {};
var converted = ChatGptConverter.schema({
components: props.components,
$defs: props.$defs,
schema: target,
});
if (converted === null)
return union.push(null);
props.$defs[key_1] = converted;
return out();
props.$defs[key_1] = {};
var converted = convertSchema({
components: props.components,
$defs: props.$defs,
schema: target,
});
if (converted === null)
return null;
props.$defs[key_1] = converted;
return out();
}
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isArray(props.schema)) {
var items = convertSchema({
components: props.components,
$defs: props.$defs,
schema: props.schema.items,
});
if (items === null)
return null;
return __assign(__assign({}, props.schema), { items: items });
}
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isTuple(props.schema)) {
var prefixItems = props.schema.prefixItems.map(function (item) {
return convertSchema({
}
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isArray(props.schema)) {
var items = ChatGptConverter.schema({
components: props.components,
$defs: props.$defs,
schema: item,
schema: props.schema.items,
});
});
if (prefixItems.some(function (v) { return v === null; }))
return null;
var additionalItems = props.schema.additionalItems === undefined
? false
: typeof props.schema.additionalItems === "object" &&
props.schema.additionalItems !== null
? convertSchema({
if (items === null)
return union.push(null);
return union.push(__assign(__assign({}, props.schema), { items: items }));
}
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isTuple(props.schema)) {
var prefixItems = props.schema.prefixItems.map(function (item) {
return ChatGptConverter.schema({
components: props.components,
$defs: props.$defs,
schema: props.schema.additionalItems,
})
: props.schema.additionalItems;
if (additionalItems === null)
return null;
return __assign(__assign({}, props.schema), { prefixItems: prefixItems.filter(function (v) { return v !== null; }), additionalItems: additionalItems });
}
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isObject(props.schema)) {
var properties = Object.entries(props.schema.properties || {}).reduce(function (acc, _a) {
var _b = __read(_a, 2), key = _b[0], value = _b[1];
var converted = convertSchema({
components: props.components,
$defs: props.$defs,
schema: value,
schema: item,
});
});
if (converted === null)
if (prefixItems.some(function (v) { return v === null; }))
return union.push(null);
var additionalItems = props.schema.additionalItems === undefined
? false
: typeof props.schema.additionalItems === "object" &&
props.schema.additionalItems !== null
? ChatGptConverter.schema({
components: props.components,
$defs: props.$defs,
schema: props.schema.additionalItems,
})
: props.schema.additionalItems;
if (additionalItems === null)
return union.push(null);
return union.push(__assign(__assign({}, props.schema), { prefixItems: prefixItems.filter(function (v) { return v !== null; }), additionalItems: additionalItems }));
}
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isObject(props.schema)) {
var properties = Object.entries(props.schema.properties || {}).reduce(function (acc, _a) {
var _b = __read(_a, 2), key = _b[0], value = _b[1];
var converted = ChatGptConverter.schema({
components: props.components,
$defs: props.$defs,
schema: value,
});
if (converted === null)
return acc;
acc[key] = converted;
return acc;
acc[key] = converted;
return acc;
}, {});
if (Object.values(properties).some(function (v) { return v === null; }))
return null;
var additionalProperties = props.schema.additionalProperties === undefined
? false
: typeof props.schema.additionalProperties === "object" &&
props.schema.additionalProperties !== null
? convertSchema({
}, {});
if (Object.values(properties).some(function (v) { return v === null; }))
return union.push(null);
var additionalProperties = props.schema.additionalProperties === undefined
? false
: typeof props.schema.additionalProperties === "object" &&
props.schema.additionalProperties !== null
? ChatGptConverter.schema({
components: props.components,
$defs: props.$defs,
schema: props.schema.additionalProperties,
})
: props.schema.additionalProperties;
if (additionalProperties === null)
return union.push(null);
return union.push(__assign(__assign({}, props.schema), { properties: properties, additionalProperties: additionalProperties }));
}
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isOneOf(props.schema)) {
var oneOf = props.schema.oneOf
.filter(function (e) { return !OpenApiTypeChecker_1.OpenApiTypeChecker.isConstant(e); })
.map(function (item) {
return ChatGptConverter.schema({
components: props.components,
$defs: props.$defs,
schema: props.schema.additionalProperties,
})
: props.schema.additionalProperties;
if (additionalProperties === null)
return null;
return __assign(__assign({}, props.schema), { properties: properties, additionalProperties: additionalProperties });
}
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isOneOf(props.schema)) {
var oneOf = props.schema.oneOf.map(function (item) {
return convertSchema({
components: props.components,
$defs: props.$defs,
schema: item,
schema: item,
});
});
});
if (oneOf.some(function (v) { return v === null; }))
return null;
return __assign(__assign({}, props.schema), { oneOf: oneOf.filter(function (v) { return v !== null; }), discriminator: props.schema.discriminator
? {
propertyName: props.schema.discriminator.propertyName,
mapping: props.schema.discriminator.mapping
? Object.fromEntries(Object.entries(props.schema.discriminator.mapping).map(function (_a) {
var _b = __read(_a, 2), key = _b[0], value = _b[1];
return [
key,
value.replace("#/components/schemas/", "#/$defs/"),
];
}))
: undefined,
return union.push.apply(union, __spreadArray([], __read(oneOf), false));
}
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isConstant(input))
return 0;
else
return union.push(input);
};
var visitConstant = function (schema) {
var e_1, _a;
var insert = function (value) {
var _a;
var matched = union.find(function (u) {
return u.type === typeof value;
});
if (matched !== undefined) {
(_a = matched.enum) !== null && _a !== void 0 ? _a : (matched.enum = []);
matched.enum.push(value);
}
else
union.push({ type: typeof value, enum: [value] });
};
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isConstant(schema))
insert(schema.const);
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isOneOf(schema))
try {
for (var _b = __values(schema.oneOf), _c = _b.next(); !_c.done; _c = _b.next()) {
var u = _c.value;
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isConstant(u))
insert(u.const);
}
: undefined });
}
return props.schema;
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
};
visit(props.schema);
visitConstant(props.schema);
if (union.some(function (u) { return u === null; }))
return null;
else if (union.length === 0)
return __assign(__assign({}, attribute), { type: undefined });
else if (union.length === 1)
return __assign(__assign({}, attribute), union[0]);
return __assign(__assign({}, attribute), { anyOf: union });
// if (OpenApiTypeChecker.isReference(props.schema)) {
// const key: string = props.schema.$ref.split("#/components/schemas/")[1];
// const target: OpenApi.IJsonSchema | undefined =
// props.components.schemas?.[key];
// if (target === undefined) return null;
// const out = () => ({
// ...props.schema,
// $ref: `#/$defs/${key}`,
// });
// if (props.$defs[key] !== undefined) return out();
// props.$defs[key] = {};
// const converted: IChatGptSchema | null = schema({
// components: props.components,
// $defs: props.$defs,
// schema: target,
// });
// if (converted === null) return null;
// props.$defs[key] = converted;
// return out();
// } else if (OpenApiTypeChecker.isArray(props.schema)) {
// const items: IChatGptSchema | null = schema({
// components: props.components,
// $defs: props.$defs,
// schema: props.schema.items,
// });
// if (items === null) return null;
// return {
// ...props.schema,
// items,
// };
// } else if (OpenApiTypeChecker.isTuple(props.schema)) {
// const prefixItems: Array<IChatGptSchema | null> =
// props.schema.prefixItems.map((item) =>
// schema({
// components: props.components,
// $defs: props.$defs,
// schema: item,
// }),
// );
// if (prefixItems.some((v) => v === null)) return null;
// const additionalItems =
// props.schema.additionalItems === undefined
// ? false
// : typeof props.schema.additionalItems === "object" &&
// props.schema.additionalItems !== null
// ? schema({
// components: props.components,
// $defs: props.$defs,
// schema: props.schema.additionalItems,
// })
// : props.schema.additionalItems;
// if (additionalItems === null) return null;
// return {
// ...props.schema,
// prefixItems: prefixItems.filter((v) => v !== null),
// additionalItems,
// };
// } else if (OpenApiTypeChecker.isObject(props.schema)) {
// const properties: Record<string, IChatGptSchema | null> = Object.entries(
// props.schema.properties || {},
// ).reduce(
// (acc, [key, value]) => {
// const converted: IChatGptSchema | null = schema({
// components: props.components,
// $defs: props.$defs,
// schema: value,
// });
// if (converted === null) return acc;
// acc[key] = converted;
// return acc;
// },
// {} as Record<string, IChatGptSchema | null>,
// );
// if (Object.values(properties).some((v) => v === null)) return null;
// const additionalProperties =
// props.schema.additionalProperties === undefined
// ? false
// : typeof props.schema.additionalProperties === "object" &&
// props.schema.additionalProperties !== null
// ? schema({
// components: props.components,
// $defs: props.$defs,
// schema: props.schema.additionalProperties,
// })
// : props.schema.additionalProperties;
// if (additionalProperties === null) return null;
// return {
// ...props.schema,
// properties: properties as Record<string, IChatGptSchema>,
// additionalProperties,
// };
// } else if (OpenApiTypeChecker.isOneOf(props.schema)) {
// const oneOf: Array<IChatGptSchema | null> = props.schema.oneOf.map(
// (item) =>
// schema({
// components: props.components,
// $defs: props.$defs,
// schema: item,
// }),
// );
// if (oneOf.some((v) => v === null)) return null;
// return {
// ...props.schema,
// anyOf: oneOf.filter((v) => v !== null),
// ...{
// oneOf: undefined,
// },
// };
// }
// return props.schema;
};

@@ -177,7 +336,7 @@ ChatGptConverter.separate = function (props) {

else if (ChatGptTypeChecker_1.ChatGptTypeChecker.isUnknown(props.schema) ||
ChatGptTypeChecker_1.ChatGptTypeChecker.isOneOf(props.schema))
ChatGptTypeChecker_1.ChatGptTypeChecker.isAnyOf(props.schema))
return [props.schema, null];
else if (ChatGptTypeChecker_1.ChatGptTypeChecker.isObject(props.schema))
return separateObject({
top: props.top,
$defs: props.$defs,
predicate: props.predicate,

@@ -188,3 +347,3 @@ schema: props.schema,

return separateArray({
top: props.top,
$defs: props.$defs,
predicate: props.predicate,

@@ -195,3 +354,3 @@ schema: props.schema,

return separateReference({
top: props.top,
$defs: props.$defs,
predicate: props.predicate,

@@ -204,3 +363,3 @@ schema: props.schema,

var _a = __read(ChatGptConverter.separate({
top: props.top,
$defs: props.$defs,
predicate: props.predicate,

@@ -217,3 +376,3 @@ schema: props.schema.items,

var separateObject = function (props) {
var e_1, _a;
var e_2, _a;
var _b;

@@ -226,3 +385,3 @@ var llm = __assign(__assign({}, props.schema), { properties: {} });

var _f = __read(ChatGptConverter.separate({
top: props.top,
$defs: props.$defs,
predicate: props.predicate,

@@ -237,3 +396,3 @@ schema: value,

}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {

@@ -243,3 +402,3 @@ try {

}
finally { if (e_1) throw e_1.error; }
finally { if (e_2) throw e_2.error; }
}

@@ -249,3 +408,3 @@ if (typeof props.schema.additionalProperties === "object" &&

var _g = __read(ChatGptConverter.separate({
top: props.top,
$defs: props.$defs,
predicate: props.predicate,

@@ -278,16 +437,16 @@ schema: props.schema.additionalProperties,

// FIND EXISTING
if (((_a = props.top.$defs) === null || _a === void 0 ? void 0 : _a["".concat(key, ".Human")]) || ((_b = props.top.$defs) === null || _b === void 0 ? void 0 : _b["".concat(key, ".Llm")]))
if (((_a = props.$defs) === null || _a === void 0 ? void 0 : _a["".concat(key, ".Human")]) || ((_b = props.$defs) === null || _b === void 0 ? void 0 : _b["".concat(key, ".Llm")]))
return [
((_c = props.top.$defs) === null || _c === void 0 ? void 0 : _c["".concat(key, ".Llm")])
((_c = props.$defs) === null || _c === void 0 ? void 0 : _c["".concat(key, ".Llm")])
? __assign(__assign({}, props.schema), { $ref: "#/$defs/".concat(key, ".Llm") }) : null,
((_d = props.top.$defs) === null || _d === void 0 ? void 0 : _d["".concat(key, ".Human")])
((_d = props.$defs) === null || _d === void 0 ? void 0 : _d["".concat(key, ".Human")])
? __assign(__assign({}, props.schema), { $ref: "#/$defs/".concat(key, ".Human") }) : null,
];
// PRE-ASSIGNMENT
props.top.$defs["".concat(key, ".Llm")] = {};
props.top.$defs["".concat(key, ".Human")] = {};
props.$defs["".concat(key, ".Llm")] = {};
props.$defs["".concat(key, ".Human")] = {};
// DO COMPOSE
var schema = (_e = props.top.$defs) === null || _e === void 0 ? void 0 : _e[key];
var schema = (_e = props.$defs) === null || _e === void 0 ? void 0 : _e[key];
var _f = __read(ChatGptConverter.separate({
top: props.top,
$defs: props.$defs,
predicate: props.predicate,

@@ -297,9 +456,9 @@ schema: schema,

if (llm === null)
delete props.top.$defs["".concat(key, ".Llm")];
delete props.$defs["".concat(key, ".Llm")];
else
props.top.$defs["".concat(key, ".Llm")] = llm;
props.$defs["".concat(key, ".Llm")] = llm;
if (human === null)
delete props.top.$defs["".concat(key, ".Human")];
delete props.$defs["".concat(key, ".Human")];
else
props.top.$defs["".concat(key, ".Human")] = human;
props.$defs["".concat(key, ".Human")] = human;
// FINALIZE

@@ -306,0 +465,0 @@ return [

import { OpenApi } from "../OpenApi";
import { IChatGptSchema } from "../structures/IChatGptSchema";
import { IGeminiSchema } from "../structures/IGeminiSchema";
import { IHttpLlmApplication } from "../structures/IHttpLlmApplication";

@@ -8,21 +6,13 @@ import { IHttpLlmFunction } from "../structures/IHttpLlmFunction";

import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
import { ILlmSchemaV3 } from "../structures/ILlmSchemaV3";
import { ILlmSchemaV3_1 } from "../structures/ILlmSchemaV3_1";
export declare namespace HttpLlmConverter {
const compose: <Model extends IHttpLlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema = IHttpLlmApplication.ModelSchema[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation<OpenApi.IJsonSchema>, Route extends IHttpMigrateRoute = IHttpMigrateRoute<OpenApi.IJsonSchema, Operation>>(props: {
const compose: <Model extends IHttpLlmApplication.Model, Parameters extends IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation<OpenApi.IJsonSchema>, Route extends IHttpMigrateRoute = IHttpMigrateRoute<OpenApi.IJsonSchema, Operation>>(props: {
model: Model;
migrate: IHttpMigrateApplication<OpenApi.IJsonSchema, Operation>;
options: IHttpLlmApplication.IOptions<Model, Schema>;
}) => IHttpLlmApplication<Model, Schema, Operation, Route>;
const schema: <Model extends IHttpLlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema = IHttpLlmApplication.ModelSchema[Model]>(props: {
options: IHttpLlmApplication.IOptions<Model, Parameters["properties"][string]>;
}) => IHttpLlmApplication<Model, Parameters, Operation, Route>;
const separateParameters: <Model extends IHttpLlmApplication.Model, Parameters extends IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model]>(props: {
model: Model;
components: OpenApi.IComponents;
schema: OpenApi.IJsonSchema;
recursive: false | number;
}) => Schema | null;
const separateParameters: <Model extends IHttpLlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema>(props: {
model: Model;
parameters: Schema[];
predicate: (schema: Schema) => boolean;
}) => IHttpLlmFunction.ISeparated<Schema>;
parameters: Parameters;
predicate: (schema: Parameters["properties"][string]) => boolean;
}) => IHttpLlmFunction.ISeparated<Parameters>;
}

@@ -99,3 +99,5 @@ "use strict";

})
.filter(function (v) { return v !== null; });
.filter(function (v) {
return v !== null;
});
return {

@@ -108,42 +110,11 @@ model: props.model,

};
HttpLlmConverter.schema = function (props) {
return CASTERS[props.model]({
components: props.components,
recursive: props.recursive,
schema: props.schema,
});
};
HttpLlmConverter.separateParameters = function (props) {
var separator = SEPARATORS[props.model];
var indexes = props.parameters.map(function (schema) {
return separator({
predicate: props.predicate,
schema: schema,
});
});
var _a = __read(separator({
predicate: props.predicate,
schema: props.parameters,
}), 2), llm = _a[0], human = _a[1];
return {
llm: indexes
.map(function (_a, index) {
var _b = __read(_a, 1), llm = _b[0];
return ({
index: index,
schema: llm,
});
})
.filter(function (_a) {
var schema = _a.schema;
return schema !== null;
}),
human: indexes
.map(function (_a, index) {
var _b = __read(_a, 2), human = _b[1];
return ({
index: index,
schema: human,
});
})
.filter(function (_a) {
var schema = _a.schema;
return schema !== null;
}),
llm: llm,
human: human,
};

@@ -153,2 +124,3 @@ };

var _a, _b, _c;
var $defs = {};
var cast = function (s) {

@@ -159,2 +131,3 @@ return CASTERS[props.model]({

schema: s,
$defs: $defs,
});

@@ -194,14 +167,13 @@ };

// COMPOSE PARAMETERS
var parameters = props.options.keyword
? [
{
type: "object",
properties: Object.fromEntries(properties),
additionalProperties: false,
},
]
: properties.map(function (_a) {
var _b = __read(_a, 2), _k = _b[0], v = _b[1];
return v;
});
var parameters = {
type: "object",
properties: Object.fromEntries(properties),
additionalProperties: false,
required: properties.map(function (_a) {
var _b = __read(_a, 1), k = _b[0];
return k;
}),
};
if (Object.keys($defs).length)
parameters.$defs = $defs;
var operation = props.route.operation();

@@ -208,0 +180,0 @@ // FINALIZATION

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

}))
: undefined,
: {},
additionalProperties: schema.additionalProperties

@@ -495,0 +495,0 @@ ? typeof schema.additionalProperties === "object" &&

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

}))
: undefined,
: {},
additionalProperties: schema.additionalProperties

@@ -317,0 +317,0 @@ ? typeof schema.additionalProperties === "object" &&

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

}))
: undefined,
: {},
additionalProperties: schema.additionalProperties

@@ -354,0 +354,0 @@ ? typeof schema.additionalProperties === "object" &&

import type { HttpLlm } from "../HttpLlm";
import { OpenApi } from "../OpenApi";
import { IChatGptSchema } from "../structures/IChatGptSchema";
import { IGeminiSchema } from "../structures/IGeminiSchema";
import { IHttpLlmApplication } from "../structures/IHttpLlmApplication";
import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
import { IHttpResponse } from "../structures/IHttpResponse";
import { ILlmSchemaV3 } from "../structures/ILlmSchemaV3";
import { ILlmSchemaV3_1 } from "../structures/ILlmSchemaV3_1";
export declare namespace HttpLlmFunctionFetcher {
const execute: <Model extends IHttpLlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema = IHttpLlmApplication.ModelSchema[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation<OpenApi.IJsonSchema>, Route extends IHttpMigrateRoute = IHttpMigrateRoute<OpenApi.IJsonSchema, Operation>>(props: HttpLlm.IFetchProps<Model, Schema, Operation, Route>) => Promise<unknown>;
const propagate: <Model extends IHttpLlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema = IHttpLlmApplication.ModelSchema[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation<OpenApi.IJsonSchema>, Route extends IHttpMigrateRoute = IHttpMigrateRoute<OpenApi.IJsonSchema, Operation>>(props: HttpLlm.IFetchProps<Model, Schema, Operation, Route>) => Promise<IHttpResponse>;
const execute: <Model extends IHttpLlmApplication.Model, Parameters extends IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation<OpenApi.IJsonSchema>, Route extends IHttpMigrateRoute = IHttpMigrateRoute<OpenApi.IJsonSchema, Operation>>(props: HttpLlm.IFetchProps<Model, Parameters, Operation, Route>) => Promise<unknown>;
const propagate: <Model extends IHttpLlmApplication.Model, Parameters extends IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation<OpenApi.IJsonSchema>, Route extends IHttpMigrateRoute = IHttpMigrateRoute<OpenApi.IJsonSchema, Operation>>(props: HttpLlm.IFetchProps<Model, Parameters, Operation, Route>) => Promise<IHttpResponse>;
}

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

var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }

@@ -53,32 +53,14 @@ function step(op) {

var route = props.function.route();
if (props.application.options.keyword === true) {
var input_1 = props.arguments[0];
var valid = props.arguments.length === 1 &&
typeof input_1 === "object" &&
input_1 !== null;
if (valid === false)
throw new Error("Error on HttpLlmFunctionFetcher.".concat(from, "(): keyworded arguments must be an object"));
return {
connection: props.connection,
route: route,
parameters: Object.fromEntries(route.parameters.map(function (p) { return [p.key, input_1[p.key]]; })),
query: input_1.query,
body: input_1.body,
};
}
var parameters = props.arguments.slice(0, route.parameters.length);
var query = route.query
? props.arguments[route.parameters.length]
: undefined;
var body = route.body
? props.arguments[route.parameters.length + (route.query ? 1 : 0)]
: undefined;
var input = props.input;
var valid = typeof input === "object" && input !== null;
if (valid === false)
throw new Error("Error on HttpLlmFunctionFetcher.".concat(from, "(): keyworded arguments must be an object"));
return {
connection: props.connection,
route: route,
parameters: parameters,
query: query,
body: body,
parameters: Object.fromEntries(route.parameters.map(function (p) { return [p.key, input[p.key]]; })),
query: input.query,
body: input.body,
};
};
})(HttpLlmFunctionFetcher || (exports.HttpLlmFunctionFetcher = HttpLlmFunctionFetcher = {}));

@@ -23,4 +23,4 @@ "use strict";

var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }

@@ -27,0 +27,0 @@ function step(op) {

@@ -61,25 +61,19 @@ import { OpenApi } from "./OpenApi";

*/
const application: <Model extends IHttpLlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema = IHttpLlmApplication.ModelSchema[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation<OpenApi.IJsonSchema>>(props: {
const application: <Model extends IHttpLlmApplication.Model, Parameters extends IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation<OpenApi.IJsonSchema>>(props: {
model: Model;
document: OpenApi.IDocument<OpenApi.IJsonSchema, Operation> | IHttpMigrateApplication<OpenApi.IJsonSchema, Operation>;
options?: Partial<IHttpLlmApplication.IOptions<Model, Schema>>;
}) => IHttpLlmApplication<Model, Schema>;
const schema: <Model extends IHttpLlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema = IHttpLlmApplication.ModelSchema[Model]>(props: {
model: Model;
components: OpenApi.IComponents;
schema: OpenApi.IJsonSchema;
recursive: false | number;
}) => Schema | null;
options?: Partial<IHttpLlmApplication.IOptions<Model, Parameters["properties"][string]>>;
}) => IHttpLlmApplication<Model, Parameters>;
/**
* Properties for the LLM function call.
*/
interface IFetchProps<Model extends IHttpLlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema = IHttpLlmApplication.ModelSchema[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation, Route extends IHttpMigrateRoute = IHttpMigrateRoute<OpenApi.IJsonSchema, Operation>> {
interface IFetchProps<Model extends IHttpLlmApplication.Model, Parameters extends IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation, Route extends IHttpMigrateRoute = IHttpMigrateRoute<OpenApi.IJsonSchema, Operation>> {
/**
* Application of the LLM function calling.
*/
application: IHttpLlmApplication<Model, Schema, Operation>;
application: IHttpLlmApplication<Model, Parameters, Operation>;
/**
* LLM function schema to call.
*/
function: IHttpLlmFunction<Schema, Operation, Route>;
function: IHttpLlmFunction<Parameters, Operation, Route>;
/**

@@ -90,5 +84,5 @@ * Connection info to the HTTP server.

/**
* Arguments for the function call.
* Input arguments for the function call.
*/
arguments: any[];
input: object;
}

@@ -120,3 +114,3 @@ /**

*/
const execute: <Model extends IHttpLlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema = IHttpLlmApplication.ModelSchema[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation<OpenApi.IJsonSchema>>(props: IFetchProps<Model, Schema, Operation>) => Promise<unknown>;
const execute: <Model extends IHttpLlmApplication.Model, Parameters extends IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation<OpenApi.IJsonSchema>>(props: IFetchProps<Model, Parameters, Operation>) => Promise<unknown>;
/**

@@ -146,19 +140,19 @@ * Propagate the LLM function call.

*/
const propagate: <Model extends IHttpLlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema = IHttpLlmApplication.ModelSchema[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation<OpenApi.IJsonSchema>>(props: IFetchProps<Model, Schema, Operation>) => Promise<IHttpResponse>;
const propagate: <Model extends IHttpLlmApplication.Model, Parameters extends IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation<OpenApi.IJsonSchema>>(props: IFetchProps<Model, Parameters, Operation>) => Promise<IHttpResponse>;
/**
* Properties for the parameters' merging.
*/
interface IMergeProps<Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema> {
interface IMergeProps<Parameters extends ILlmSchemaV3.IParameters | ILlmSchemaV3_1.IParameters | IChatGptSchema.IParameters | IGeminiSchema.IParameters> {
/**
* Metadata of the target function.
*/
function: ILlmFunction<Schema>;
function: ILlmFunction<Parameters>;
/**
* Arguments composed by the LLM.
*/
llm: unknown[];
llm: object | null;
/**
* Arguments composed by the human.
*/
human: unknown[];
human: object | null;
}

@@ -180,3 +174,3 @@ /**

*/
const mergeParameters: <Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema>(props: IMergeProps<Schema>) => unknown[];
const mergeParameters: <Parameters extends ILlmSchemaV3.IParameters | ILlmSchemaV3_1.IParameters | IChatGptSchema.IParameters | IGeminiSchema.IParameters>(props: IMergeProps<Parameters>) => object;
/**

@@ -183,0 +177,0 @@ * Merge two values.

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

HttpLlm.application = function (props) {
var _a, _b, _c, _d, _e, _f;
var _a, _b, _c, _d;
// MIGRATE

@@ -71,11 +71,9 @@ var migrate = props.document["x-samchon-emended"] === true

options: {
keyword: (_b = (_a = props.options) === null || _a === void 0 ? void 0 : _a.keyword) !== null && _b !== void 0 ? _b : false,
separate: (_d = (_c = props.options) === null || _c === void 0 ? void 0 : _c.separate) !== null && _d !== void 0 ? _d : null,
separate: (_b = (_a = props.options) === null || _a === void 0 ? void 0 : _a.separate) !== null && _b !== void 0 ? _b : null,
recursive: (props.model === "chatgpt"
? undefined
: ((_f = (_e = props.options) === null || _e === void 0 ? void 0 : _e.recursive) !== null && _f !== void 0 ? _f : 3)),
: ((_d = (_c = props.options) === null || _c === void 0 ? void 0 : _c.recursive) !== null && _d !== void 0 ? _d : 3)),
},
});
};
HttpLlm.schema = function (props) { return HttpLlmConverter_1.HttpLlmConverter.schema(props); };
/**

@@ -82,0 +80,0 @@ * Execute the LLM function call.

@@ -738,3 +738,3 @@ import { OpenApiV3 } from "./OpenApiV3";

*/
properties?: Record<string, Schema>;
properties: Record<string, Schema>;
/**

@@ -741,0 +741,0 @@ * Additional properties' info.

@@ -1,17 +0,15 @@

export type IChatGptSchema = IChatGptSchema.IBoolean | IChatGptSchema.IInteger | IChatGptSchema.INumber | IChatGptSchema.IString | IChatGptSchema.IArray | IChatGptSchema.ITuple | IChatGptSchema.IObject | IChatGptSchema.IReference | IChatGptSchema.IOneOf | IChatGptSchema.INull | IChatGptSchema.IUnknown;
export type IChatGptSchema = IChatGptSchema.IBoolean | IChatGptSchema.IInteger | IChatGptSchema.INumber | IChatGptSchema.IString | IChatGptSchema.IArray | IChatGptSchema.ITuple | IChatGptSchema.IObject | IChatGptSchema.IReference | IChatGptSchema.IAnyOf | IChatGptSchema.INull | IChatGptSchema.IUnknown;
export declare namespace IChatGptSchema {
/**
* The top level schema including `$defs`.
* Type of the function parameters.
*/
type ITop<Schema extends IChatGptSchema = IChatGptSchema> = Schema & {
interface IParameters extends Omit<IObject, "additionalProperties"> {
/**
* Collection of the named types.
*/
$defs?: Record<string, IChatGptSchema | undefined>;
};
/**
* Constant value type.
*/
interface IConstant extends __IAttribute {
/**
* The constant value.
* Do not allow additional properties in the parameters.
*/
const: boolean | number | string;
additionalProperties: false;
}

@@ -23,2 +21,6 @@ /**

/**
* Enumeration values.
*/
enum?: Array<boolean>;
/**
* The default value.

@@ -33,2 +35,6 @@ */

/**
* Enumeration values.
*/
enum?: Array<number>;
/**
* Default value.

@@ -82,2 +88,6 @@ *

/**
* Enumeration values.
*/
enum?: Array<number>;
/**
* Default value.

@@ -124,2 +134,6 @@ */

/**
* Enumeration values.
*/
enum?: Array<string>;
/**
* Default value.

@@ -254,3 +268,3 @@ */

*/
properties?: Record<string, IChatGptSchema>;
properties: Record<string, IChatGptSchema>;
/**

@@ -332,32 +346,8 @@ * Additional properties' info.

*/
interface IOneOf extends __IAttribute {
interface IAnyOf extends __IAttribute {
/**
* List of the union types.
*/
oneOf: Exclude<IChatGptSchema, IChatGptSchema.IOneOf>[];
/**
* Discriminator info of the union type.
*/
discriminator?: IOneOf.IDiscriminator;
anyOf: Exclude<IChatGptSchema, IChatGptSchema.IAnyOf>[];
}
namespace IOneOf {
/**
* Discriminator info of the union type.
*/
interface IDiscriminator {
/**
* Property name for the discriminator.
*/
propertyName: string;
/**
* Mapping of the discriminator value to the schema name.
*
* This property is valid only for {@link IReference} typed
* {@link IOneOf.oneof} elements. Therefore, `key` of `mapping` is
* the discriminator value, and `value` of `mapping` is the
* schema name like `#/$defs/SomeObject`.
*/
mapping?: Record<string, string>;
}
}
/**

@@ -364,0 +354,0 @@ * Null type.

@@ -38,2 +38,11 @@ /**

/**
* Type of the function parameters.
*/
interface IParameters extends Omit<IObject, "additionalProperties"> {
/**
* Do not allow additional properties in the parameters.
*/
additionalProperties: false;
}
/**
* Boolean type schema info.

@@ -270,3 +279,3 @@ */

*/
properties?: Record<string, IGeminiSchema>;
properties: Record<string, IGeminiSchema>;
/**

@@ -273,0 +282,0 @@ * List of key values of the required properties.

@@ -71,3 +71,3 @@ import { OpenApi } from "../OpenApi";

*/
export interface IHttpLlmApplication<Model extends IHttpLlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema.ITop | IGeminiSchema = IHttpLlmApplication.ModelSchema[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation, Route extends IHttpMigrateRoute = IHttpMigrateRoute> {
export interface IHttpLlmApplication<Model extends IHttpLlmApplication.Model, Parameters extends IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model], Operation extends OpenApi.IOperation = OpenApi.IOperation, Route extends IHttpMigrateRoute = IHttpMigrateRoute> {
/**

@@ -85,3 +85,3 @@ * Model of the target LLM.

*/
functions: IHttpLlmFunction<Schema, Operation, Route>[];
functions: IHttpLlmFunction<Parameters, Operation, Route>[];
/**

@@ -97,10 +97,16 @@ * List of errors occurred during the composition.

*/
options: IHttpLlmApplication.IOptions<Model, Schema>;
options: IHttpLlmApplication.IOptions<Model, Parameters["properties"][string]>;
}
export declare namespace IHttpLlmApplication {
type Model = "3.0" | "3.1" | "chatgpt" | "gemini";
type ModelParameters = {
"3.0": ILlmSchemaV3.IParameters;
"3.1": ILlmSchemaV3_1.IParameters;
chatgpt: IChatGptSchema.IParameters;
gemini: IGeminiSchema.IParameters;
};
type ModelSchema = {
"3.0": ILlmSchemaV3;
"3.1": ILlmSchemaV3_1;
chatgpt: IChatGptSchema.ITop;
chatgpt: IChatGptSchema;
gemini: IGeminiSchema;

@@ -145,33 +151,4 @@ };

*/
interface IOptions<Model extends IHttpLlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema.ITop | IGeminiSchema = IHttpLlmApplication.ModelSchema[Model]> {
interface IOptions<Model extends IHttpLlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema = IHttpLlmApplication.ModelSchema[Model]> {
/**
* Whether the parameters are keyworded or not.
*
* If this property value is `true`, length of the
* {@link IHttpLlmApplication.IFunction.parameters} is always 1, and type of
* the pararameter is always {@link ILlmSchemaV3.IObject} type.
*
* Otherwise, the parameters would be multiple, and the sequence of the parameters
* are following below rules.
*
* ```typescript
* // KEYWORD TRUE
* {
* ...pathParameters,
* query,
* body,
* }
*
* // KEYWORD FALSE
* [
* ...pathParameters,
* ...(query ? [query] : []),
* ...(body ? [body] : []),
* ]
* ```
*
* @default false
*/
keyword: boolean;
/**
* Whether to allow recursive types or not.

@@ -178,0 +155,0 @@ *

@@ -59,3 +59,3 @@ import { OpenApi } from "../OpenApi";

*/
export interface IHttpLlmFunction<Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema.ITop | IGeminiSchema, Operation extends OpenApi.IOperation = OpenApi.IOperation, Route extends IHttpMigrateRoute = IHttpMigrateRoute> {
export interface IHttpLlmFunction<Parameters extends ILlmSchemaV3.IParameters | ILlmSchemaV3_1.IParameters | IChatGptSchema.IParameters | IGeminiSchema.IParameters, Operation extends OpenApi.IOperation = OpenApi.IOperation, Route extends IHttpMigrateRoute = IHttpMigrateRoute> {
/**

@@ -141,3 +141,3 @@ * HTTP method of the endpoint.

*/
parameters: Schema[];
parameters: Parameters;
/**

@@ -148,3 +148,3 @@ * Collection of separated parameters.

*/
separated?: IHttpLlmFunction.ISeparated<Schema>;
separated?: IHttpLlmFunction.ISeparated<Parameters>;
/**

@@ -156,3 +156,3 @@ * Expected return type.

*/
output?: Schema | undefined;
output?: Parameters | undefined;
/**

@@ -218,27 +218,12 @@ * Description of the function.

*/
interface ISeparated<Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema.ITop | IGeminiSchema> {
interface ISeparated<Parameters extends ILlmSchemaV3.IParameters | ILlmSchemaV3_1.IParameters | IChatGptSchema.IParameters | IGeminiSchema.IParameters> {
/**
* Parameters that would be composed by the LLM.
*/
llm: ISeparatedParameter<Schema>[];
llm: Parameters | null;
/**
* Parameters that would be composed by the human.
*/
human: ISeparatedParameter<Schema>[];
human: Parameters | null;
}
/**
* Separated parameter.
*/
interface ISeparatedParameter<Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema.ITop | IGeminiSchema> {
/**
* Index of the parameter.
*
* @type uint
*/
index: number;
/**
* Type schema info of the parameter.
*/
schema: Schema;
}
}

@@ -17,3 +17,3 @@ import { IChatGptSchema } from "./IChatGptSchema";

* successful. As LLM provider like OpenAI cannot understand the recursive reference
* type that is embodied by {@link OpenApi.IJsonSchema.IReference}, if there're some
* type that is embodied by {@link IOpenApiSchemachema.IReference}, if there're some
* recursive types in the TypeScript interface (or class) type, the conversion would

@@ -37,3 +37,3 @@ * be failed.

*/
export interface ILlmApplication<Model extends ILlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema.ITop | IGeminiSchema = ILlmApplication.ModelSchema[Model]> {
export interface ILlmApplication<Model extends ILlmApplication.Model, Parameters extends ILlmApplication.ModelParameters[Model] = ILlmApplication.ModelParameters[Model]> {
/**

@@ -48,14 +48,20 @@ * Model of the LLM.

*/
functions: ILlmFunction<Schema>[];
functions: ILlmFunction<Parameters>[];
/**
* Options for the application.
*/
options: ILlmApplication.IOptions<Model, Schema>;
options: ILlmApplication.IOptions<Model, Parameters["properties"][string]>;
}
export declare namespace ILlmApplication {
type Model = "3.0" | "3.1" | "chatgpt" | "gemini";
type ModelParameters = {
"3.0": ILlmSchemaV3.IParameters;
"3.1": ILlmSchemaV3_1.IParameters;
chatgpt: IChatGptSchema.IParameters;
gemini: IGeminiSchema.IParameters;
};
type ModelSchema = {
"3.0": ILlmSchemaV3;
"3.1": ILlmSchemaV3_1;
chatgpt: IChatGptSchema.ITop;
chatgpt: IChatGptSchema;
gemini: IGeminiSchema;

@@ -66,3 +72,3 @@ };

*/
interface IOptions<Model extends ILlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema.ITop | IGeminiSchema = ILlmApplication.ModelSchema[Model]> {
interface IOptions<Model extends ILlmApplication.Model, Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema = ILlmApplication.ModelSchema[Model]> {
/**

@@ -69,0 +75,0 @@ * Whether to allow recursive types or not.

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

*/
export interface ILlmFunction<Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema.ITop | IGeminiSchema> {
export interface ILlmFunction<Parameters extends ILlmSchemaV3.IParameters | ILlmSchemaV3_1.IParameters | IChatGptSchema.IParameters | IGeminiSchema.IParameters> {
/**

@@ -36,7 +36,7 @@ * Representative name of the function.

*/
parameters: Schema[];
parameters: Parameters;
/**
* Collection of separated parameters.
*/
separated?: ILlmFunction.ISeparated<Schema>;
separated?: ILlmFunction.ISeparated<Parameters>;
/**

@@ -48,4 +48,12 @@ * Expected return type.

*/
output?: Schema | undefined;
output?: Parameters["properties"][string];
/**
* Whether the function schema types are strict or not.
*
* Newly added specification to "OpenAI" at 2024-08-07.
*
* @reference https://openai.com/index/introducing-structured-outputs-in-the-api/
*/
strict: true;
/**
* Description of the function.

@@ -81,27 +89,12 @@ *

*/
interface ISeparated<Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema.ITop | IGeminiSchema> {
interface ISeparated<Parameters extends ILlmSchemaV3.IParameters | ILlmSchemaV3_1.IParameters | IChatGptSchema.IParameters | IGeminiSchema.IParameters> {
/**
* Parameters that would be composed by the LLM.
*/
llm: ISeparatedParameter<Schema>[];
llm: Parameters | null;
/**
* Parameters that would be composed by the human.
*/
human: ISeparatedParameter<Schema>[];
human: Parameters | null;
}
/**
* Separated parameter.
*/
interface ISeparatedParameter<Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema.ITop | IGeminiSchema> {
/**
* Index of the parameter.
*
* @type uint
*/
index: number;
/**
* Type schema info of the parameter.
*/
schema: Schema;
}
}
export type ILlmSchemaV3_1 = ILlmSchemaV3_1.IBoolean | ILlmSchemaV3_1.IInteger | ILlmSchemaV3_1.INumber | ILlmSchemaV3_1.IString | ILlmSchemaV3_1.IArray | ILlmSchemaV3_1.ITuple | ILlmSchemaV3_1.IObject | ILlmSchemaV3_1.IOneOf | ILlmSchemaV3_1.INull | ILlmSchemaV3_1.IUnknown;
export declare namespace ILlmSchemaV3_1 {
/**
* Type of the function parameters.
*/
interface IParameters extends Omit<IObject, "additionalProperties"> {
/**
* Do not allow additional properties in the parameters.
*/
additionalProperties: false;
}
/**
* Constant value type.

@@ -244,3 +253,3 @@ */

*/
properties?: Record<string, ILlmSchemaV3_1>;
properties: Record<string, ILlmSchemaV3_1>;
/**

@@ -247,0 +256,0 @@ * Additional properties' info.

@@ -23,2 +23,11 @@ /**

/**
* Type of the function parameters.
*/
interface IParameters extends Omit<IObject, "additionalProperties"> {
/**
* Do not allow additional properties in the parameters.
*/
additionalProperties: false;
}
/**
* Boolean type schema info.

@@ -220,3 +229,3 @@ */

*/
properties?: Record<string, Schema>;
properties: Record<string, Schema>;
/**

@@ -223,0 +232,0 @@ * List of key values of the required properties.

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

const isUnknown: (schema: IChatGptSchema) => schema is IChatGptSchema.IUnknown;
const isConstant: (schema: IChatGptSchema) => schema is IChatGptSchema.IConstant;
const isBoolean: (schema: IChatGptSchema) => schema is IChatGptSchema.IBoolean;

@@ -15,10 +14,10 @@ const isInteger: (schema: IChatGptSchema) => schema is IChatGptSchema.IInteger;

const isReference: (schema: IChatGptSchema) => schema is IChatGptSchema.IReference;
const isOneOf: (schema: IChatGptSchema) => schema is IChatGptSchema.IOneOf;
const isAnyOf: (schema: IChatGptSchema) => schema is IChatGptSchema.IAnyOf;
const visit: (props: {
closure: (schema: IChatGptSchema) => void;
top: IChatGptSchema.ITop;
$defs?: Record<string, IChatGptSchema> | undefined;
schema: IChatGptSchema;
}) => void;
const covers: (props: {
top: IChatGptSchema.ITop;
$defs?: Record<string, IChatGptSchema> | undefined;
x: IChatGptSchema;

@@ -25,0 +24,0 @@ y: IChatGptSchema;

@@ -42,9 +42,5 @@ "use strict";

return schema.type === undefined &&
!ChatGptTypeChecker.isConstant(schema) &&
!ChatGptTypeChecker.isOneOf(schema) &&
!ChatGptTypeChecker.isAnyOf(schema) &&
!ChatGptTypeChecker.isReference(schema);
};
ChatGptTypeChecker.isConstant = function (schema) {
return schema.const !== undefined;
};
ChatGptTypeChecker.isBoolean = function (schema) {

@@ -74,4 +70,4 @@ return schema.type === "boolean";

ChatGptTypeChecker.isReference = function (schema) { return schema.$ref !== undefined; };
ChatGptTypeChecker.isOneOf = function (schema) {
return schema.oneOf !== undefined;
ChatGptTypeChecker.isAnyOf = function (schema) {
return schema.anyOf !== undefined;
};

@@ -92,8 +88,8 @@ /* -----------------------------------------------------------

already.add(key);
var found = (_b = props.top.$defs) === null || _b === void 0 ? void 0 : _b[key];
var found = (_b = props.$defs) === null || _b === void 0 ? void 0 : _b[key];
if (found !== undefined)
next(found);
}
else if (ChatGptTypeChecker.isOneOf(schema))
schema.oneOf.forEach(next);
else if (ChatGptTypeChecker.isAnyOf(schema))
schema.anyOf.forEach(next);
else if (ChatGptTypeChecker.isObject(schema)) {

@@ -130,3 +126,3 @@ try {

return coverStation({
top: props.top,
$defs: props.$defs,
x: props.x,

@@ -157,4 +153,4 @@ y: props.y,

// COMPARE WITH FLATTENING
var alpha = flatSchema(p.top, p.x);
var beta = flatSchema(p.top, p.y);
var alpha = flatSchema(p.$defs, p.x);
var beta = flatSchema(p.$defs, p.y);
if (alpha.some(function (x) { return ChatGptTypeChecker.isUnknown(x); }))

@@ -167,3 +163,3 @@ return true;

return coverEscapedSchema({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -187,13 +183,10 @@ x: a,

// ATOMIC CASE
else if (ChatGptTypeChecker.isConstant(p.x))
return ChatGptTypeChecker.isConstant(p.y) && p.x.const === p.y.const;
else if (ChatGptTypeChecker.isBoolean(p.x))
return (ChatGptTypeChecker.isBoolean(p.y) || (ChatGptTypeChecker.isConstant(p.y) && typeof p.y.const === "boolean"));
return ChatGptTypeChecker.isBoolean(p.y) && coverBoolean(p.x, p.y);
else if (ChatGptTypeChecker.isInteger(p.x))
return (ChatGptTypeChecker.isInteger(p.y) || ChatGptTypeChecker.isConstant(p.y)) && coverInteger(p.x, p.y);
return ChatGptTypeChecker.isInteger(p.y) && coverInteger(p.x, p.y);
else if (ChatGptTypeChecker.isNumber(p.x))
return ((ChatGptTypeChecker.isConstant(p.y) || ChatGptTypeChecker.isInteger(p.y) || ChatGptTypeChecker.isNumber(p.y)) &&
coverNumber(p.x, p.y));
return ChatGptTypeChecker.isNumber(p.y) && coverNumber(p.x, p.y);
else if (ChatGptTypeChecker.isString(p.x))
return (ChatGptTypeChecker.isConstant(p.y) || ChatGptTypeChecker.isString(p.y)) && coverString(p.x, p.y);
return ChatGptTypeChecker.isString(p.y) && coverString(p.x, p.y);
// INSTANCE CASE

@@ -203,3 +196,3 @@ else if (ChatGptTypeChecker.isArray(p.x))

coverArray({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -212,3 +205,3 @@ x: p.x,

coverObject({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -226,3 +219,3 @@ x: p.x,

return coverStation({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -236,3 +229,3 @@ x: p.x.items,

coverStation({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -249,3 +242,3 @@ x: p.x.items,

return coverStation({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -267,3 +260,3 @@ x: p.x.items,

!coverStation({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -284,3 +277,3 @@ x: p.x.additionalProperties,

return coverStation({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -292,5 +285,12 @@ x: a,

};
var coverBoolean = function (x, y) {
var _a, _b;
if (!!((_a = x.enum) === null || _a === void 0 ? void 0 : _a.length))
return !!((_b = y.enum) === null || _b === void 0 ? void 0 : _b.length) && y.enum.every(function (v) { return x.enum.includes(v); });
return true;
};
var coverInteger = function (x, y) {
if (ChatGptTypeChecker.isConstant(y))
return typeof y.const === "number" && Number.isInteger(y.const);
var _a, _b;
if (!!((_a = x.enum) === null || _a === void 0 ? void 0 : _a.length))
return !!((_b = y.enum) === null || _b === void 0 ? void 0 : _b.length) && y.enum.every(function (v) { return x.enum.includes(v); });
return [

@@ -317,4 +317,5 @@ x.type === y.type,

var coverNumber = function (x, y) {
if (ChatGptTypeChecker.isConstant(y))
return typeof y.const === "number";
var _a, _b;
if (!!((_a = x.enum) === null || _a === void 0 ? void 0 : _a.length))
return !!((_b = y.enum) === null || _b === void 0 ? void 0 : _b.length) && y.enum.every(function (v) { return x.enum.includes(v); });
return [

@@ -341,5 +342,7 @@ x.type === y.type || (x.type === "number" && y.type === "integer"),

var coverString = function (x, y) {
if (ChatGptTypeChecker.isConstant(y))
return typeof y.const === "string";
var _a, _b;
if (!!((_a = x.enum) === null || _a === void 0 ? void 0 : _a.length))
return !!((_b = y.enum) === null || _b === void 0 ? void 0 : _b.length) && y.enum.every(function (v) { return x.enum.includes(v); });
return [
x.type === y.type,
x.format === undefined ||

@@ -362,13 +365,13 @@ (y.format !== undefined && coverFormat(x.format, y.format)),

};
var flatSchema = function (top, schema) {
schema = escapeReference(top, schema);
if (ChatGptTypeChecker.isOneOf(schema))
return schema.oneOf.map(function (v) { return flatSchema(top, v); }).flat();
var flatSchema = function ($defs, schema) {
schema = escapeReference($defs, schema);
if (ChatGptTypeChecker.isAnyOf(schema))
return schema.anyOf.map(function (v) { return flatSchema($defs, v); }).flat();
return [schema];
};
var escapeReference = function (top, schema) {
var escapeReference = function ($defs, schema) {
return ChatGptTypeChecker.isReference(schema)
? escapeReference(top, top.$defs[schema.$ref.replace("#/$defs/", "")])
? escapeReference($defs, $defs[schema.$ref.replace("#/$defs/", "")])
: schema;
};
})(ChatGptTypeChecker || (exports.ChatGptTypeChecker = ChatGptTypeChecker = {}));

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

*/
interface IProps<Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema> {
interface IProps<Parameters extends ILlmSchemaV3.IParameters | ILlmSchemaV3_1.IParameters | IChatGptSchema.IParameters | IGeminiSchema.IParameters> {
/**
* Target function to call.
*/
function: ILlmFunction<Schema>;
function: ILlmFunction<Parameters>;
/**
* Arguments composed by LLM (Large Language Model).
*/
llm: any[];
llm: object | null;
/**
* Arguments composed by human.
*/
human: any[];
human: object | null;
}

@@ -45,3 +45,3 @@ /**

*/
const parameters: <Schema extends ILlmSchemaV3 | ILlmSchemaV3_1 | IChatGptSchema | IGeminiSchema>(props: IProps<Schema>) => unknown[];
const parameters: <Parameters extends ILlmSchemaV3.IParameters | ILlmSchemaV3_1.IParameters | IChatGptSchema.IParameters | IGeminiSchema.IParameters>(props: IProps<Parameters>) => object;
/**

@@ -48,0 +48,0 @@ * Combine two values into one.

@@ -68,9 +68,3 @@ "use strict";

throw new Error("Error on OpenAiDataComposer.parameters(): the function parameters are not separated.");
return new Array(props.function.parameters.length).fill(0).map(function (_, i) {
var llm = separated.llm.findIndex(function (p) { return p.index === i; });
var human = separated.human.findIndex(function (p) { return p.index === i; });
if (llm === -1 && human === -1)
throw new Error("Error on OpenAiDataComposer.parameters(): failed to gather separated arguments, because both LLM and human sides are all empty.");
return LlmDataMerger.value(props.llm[llm], props.human[human]);
});
return LlmDataMerger.value(props.llm, props.human);
};

@@ -77,0 +71,0 @@ /**

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

@@ -35,6 +35,6 @@ "main": "./lib/index.js",

"devDependencies": {
"@nestia/core": "^3.12.0",
"@nestia/e2e": "^0.7.0",
"@nestia/fetcher": "^3.12.0",
"@nestia/sdk": "^3.12.0",
"@nestia/core": "4.0.0-dev.20241116",
"@nestia/e2e": "0.7.0",
"@nestia/fetcher": "4.0.0-dev.20241116",
"@nestia/sdk": "4.0.0-dev.20241116",
"@nestjs/common": "^10.4.1",

@@ -50,4 +50,7 @@ "@nestjs/core": "^10.4.1",

"chalk": "^4.1.2",
"dotenv": "^16.4.5",
"dotenv-expand": "^12.0.0",
"js-yaml": "^4.1.0",
"nestia": "^6.0.1",
"openai": "^4.72.0",
"prettier": "^3.2.5",

@@ -59,5 +62,6 @@ "rimraf": "^5.0.5",

"ts-patch": "^3.2.1",
"tstl": "^3.0.0",
"typescript": "^5.6.3",
"typescript-transform-paths": "^3.4.7",
"typia": "^6.9.0",
"typia": "7.0.0-dev.20241115",
"uuid": "^10.0.0"

@@ -64,0 +68,0 @@ },

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

export namespace ChatGptConverter {
export const schema = (props: {
export const parameters = (props: {
components: OpenApi.IComponents;
schema: OpenApi.IJsonSchema;
}): IChatGptSchema.ITop | null => {
schema: OpenApi.IJsonSchema.IObject;
}): IChatGptSchema.IParameters | null => {
const $defs: Record<string, IChatGptSchema> = {};
const schema: IChatGptSchema.ITop | null = convertSchema({
const res: IChatGptSchema.IParameters | null = schema({
components: props.components,
schema: props.schema,
$defs,
});
if (schema === null) return null;
else if (Object.keys($defs).length) schema.$defs = $defs;
return schema;
}) as IChatGptSchema.IParameters | null;
if (res === null) return null;
else if (Object.keys($defs).length) res.$defs = $defs;
return res;
};
const convertSchema = (props: {
export const schema = (props: {
components: OpenApi.IComponents;
schema: OpenApi.IJsonSchema;
$defs: Record<string, IChatGptSchema>;
schema: OpenApi.IJsonSchema;
}): IChatGptSchema | null => {
if (OpenApiTypeChecker.isReference(props.schema)) {
const key: string = props.schema.$ref.split("#/components/schemas/")[1];
const target: OpenApi.IJsonSchema | undefined =
props.components.schemas?.[key];
if (target === undefined) return null;
const union: Array<IChatGptSchema | null> = [];
const attribute: IChatGptSchema.__IAttribute = {
title: props.schema.title,
description: props.schema.description,
example: props.schema.example,
examples: props.schema.examples,
...Object.fromEntries(
Object.entries(props.schema).filter(
([key, value]) => key.startsWith("x-") && value !== undefined,
),
),
};
const visit = (input: OpenApi.IJsonSchema): number => {
if (OpenApiTypeChecker.isReference(props.schema)) {
const key: string = props.schema.$ref.split("#/components/schemas/")[1];
const target: OpenApi.IJsonSchema | undefined =
props.components.schemas?.[key];
if (target === undefined) return 0;
const out = () => ({
...props.schema,
$ref: `#/$defs/${key}`,
});
if (props.$defs[key] !== undefined) return out();
props.$defs[key] = {};
const converted: IChatGptSchema | null = convertSchema({
components: props.components,
$defs: props.$defs,
schema: target,
});
if (converted === null) return null;
props.$defs[key] = converted;
return out();
} else if (OpenApiTypeChecker.isArray(props.schema)) {
const items: IChatGptSchema | null = convertSchema({
components: props.components,
$defs: props.$defs,
schema: props.schema.items,
});
if (items === null) return null;
return {
...props.schema,
items,
};
} else if (OpenApiTypeChecker.isTuple(props.schema)) {
const prefixItems: Array<IChatGptSchema | null> =
props.schema.prefixItems.map((item) =>
convertSchema({
components: props.components,
$defs: props.$defs,
schema: item,
}),
);
if (prefixItems.some((v) => v === null)) return null;
const additionalItems =
props.schema.additionalItems === undefined
? false
: typeof props.schema.additionalItems === "object" &&
props.schema.additionalItems !== null
? convertSchema({
const out = () =>
union.push({
...props.schema,
$ref: `#/$defs/${key}`,
} as IChatGptSchema);
if (props.$defs[key] !== undefined) return out();
props.$defs[key] = {};
const converted: IChatGptSchema | null = schema({
components: props.components,
$defs: props.$defs,
schema: target,
});
if (converted === null) return union.push(null);
props.$defs[key] = converted;
return out();
} else if (OpenApiTypeChecker.isArray(props.schema)) {
const items: IChatGptSchema | null = schema({
components: props.components,
$defs: props.$defs,
schema: props.schema.items,
});
if (items === null) return union.push(null);
return union.push({
...props.schema,
items,
});
} else if (OpenApiTypeChecker.isTuple(props.schema)) {
const prefixItems: Array<IChatGptSchema | null> =
props.schema.prefixItems.map((item) =>
schema({
components: props.components,
$defs: props.$defs,
schema: item,
}),
);
if (prefixItems.some((v) => v === null)) return union.push(null);
const additionalItems =
props.schema.additionalItems === undefined
? false
: typeof props.schema.additionalItems === "object" &&
props.schema.additionalItems !== null
? schema({
components: props.components,
$defs: props.$defs,
schema: props.schema.additionalItems,
})
: props.schema.additionalItems;
if (additionalItems === null) return union.push(null);
return union.push({
...props.schema,
prefixItems: prefixItems.filter((v) => v !== null),
additionalItems,
});
} else if (OpenApiTypeChecker.isObject(props.schema)) {
const properties: Record<string, IChatGptSchema | null> =
Object.entries(props.schema.properties || {}).reduce(
(acc, [key, value]) => {
const converted: IChatGptSchema | null = schema({
components: props.components,
$defs: props.$defs,
schema: props.schema.additionalItems,
})
: props.schema.additionalItems;
if (additionalItems === null) return null;
return {
...props.schema,
prefixItems: prefixItems.filter((v) => v !== null),
additionalItems,
schema: value,
});
if (converted === null) return acc;
acc[key] = converted;
return acc;
},
{} as Record<string, IChatGptSchema | null>,
);
if (Object.values(properties).some((v) => v === null))
return union.push(null);
const additionalProperties =
props.schema.additionalProperties === undefined
? false
: typeof props.schema.additionalProperties === "object" &&
props.schema.additionalProperties !== null
? schema({
components: props.components,
$defs: props.$defs,
schema: props.schema.additionalProperties,
})
: props.schema.additionalProperties;
if (additionalProperties === null) return union.push(null);
return union.push({
...props.schema,
properties: properties as Record<string, IChatGptSchema>,
additionalProperties,
});
} else if (OpenApiTypeChecker.isOneOf(props.schema)) {
const oneOf: Array<IChatGptSchema | null> = props.schema.oneOf
.filter((e) => !OpenApiTypeChecker.isConstant(e))
.map((item) =>
schema({
components: props.components,
$defs: props.$defs,
schema: item,
}),
);
return union.push(...oneOf);
} else if (OpenApiTypeChecker.isConstant(input)) return 0;
else return union.push(input);
};
const visitConstant = (schema: OpenApi.IJsonSchema): void => {
const insert = (value: any): void => {
const matched: IChatGptSchema.INumber | undefined = union.find(
(u) =>
(u as IChatGptSchema.__ISignificant<any>).type === typeof value,
) as IChatGptSchema.INumber | undefined;
if (matched !== undefined) {
matched.enum ??= [];
matched.enum.push(value);
} else union.push({ type: typeof value as "number", enum: [value] });
};
} else if (OpenApiTypeChecker.isObject(props.schema)) {
const properties: Record<string, IChatGptSchema | null> = Object.entries(
props.schema.properties || {},
).reduce(
(acc, [key, value]) => {
const converted: IChatGptSchema | null = convertSchema({
components: props.components,
$defs: props.$defs,
schema: value,
});
if (converted === null) return acc;
acc[key] = converted;
return acc;
},
{} as Record<string, IChatGptSchema | null>,
);
if (Object.values(properties).some((v) => v === null)) return null;
const additionalProperties =
props.schema.additionalProperties === undefined
? false
: typeof props.schema.additionalProperties === "object" &&
props.schema.additionalProperties !== null
? convertSchema({
components: props.components,
$defs: props.$defs,
schema: props.schema.additionalProperties,
})
: props.schema.additionalProperties;
if (additionalProperties === null) return null;
if (OpenApiTypeChecker.isConstant(schema)) insert(schema.const);
else if (OpenApiTypeChecker.isOneOf(schema))
for (const u of schema.oneOf)
if (OpenApiTypeChecker.isConstant(u)) insert(u.const);
};
visit(props.schema);
visitConstant(props.schema);
if (union.some((u) => u === null)) return null;
else if (union.length === 0)
return {
...props.schema,
properties: properties as Record<string, IChatGptSchema>,
additionalProperties,
...attribute,
type: undefined,
};
} else if (OpenApiTypeChecker.isOneOf(props.schema)) {
const oneOf: Array<IChatGptSchema | null> = props.schema.oneOf.map(
(item) =>
convertSchema({
components: props.components,
$defs: props.$defs,
schema: item,
}),
);
if (oneOf.some((v) => v === null)) return null;
else if (union.length === 1)
return {
...props.schema,
oneOf: oneOf.filter((v) => v !== null),
discriminator: props.schema.discriminator
? {
propertyName: props.schema.discriminator.propertyName,
mapping: props.schema.discriminator.mapping
? Object.fromEntries(
Object.entries(props.schema.discriminator.mapping).map(
([key, value]) => [
key,
value.replace("#/components/schemas/", "#/$defs/"),
],
),
)
: undefined,
}
: undefined,
...attribute,
...union[0],
};
}
return props.schema;
return {
...attribute,
anyOf: union as IChatGptSchema[],
};
// if (OpenApiTypeChecker.isReference(props.schema)) {
// const key: string = props.schema.$ref.split("#/components/schemas/")[1];
// const target: OpenApi.IJsonSchema | undefined =
// props.components.schemas?.[key];
// if (target === undefined) return null;
// const out = () => ({
// ...props.schema,
// $ref: `#/$defs/${key}`,
// });
// if (props.$defs[key] !== undefined) return out();
// props.$defs[key] = {};
// const converted: IChatGptSchema | null = schema({
// components: props.components,
// $defs: props.$defs,
// schema: target,
// });
// if (converted === null) return null;
// props.$defs[key] = converted;
// return out();
// } else if (OpenApiTypeChecker.isArray(props.schema)) {
// const items: IChatGptSchema | null = schema({
// components: props.components,
// $defs: props.$defs,
// schema: props.schema.items,
// });
// if (items === null) return null;
// return {
// ...props.schema,
// items,
// };
// } else if (OpenApiTypeChecker.isTuple(props.schema)) {
// const prefixItems: Array<IChatGptSchema | null> =
// props.schema.prefixItems.map((item) =>
// schema({
// components: props.components,
// $defs: props.$defs,
// schema: item,
// }),
// );
// if (prefixItems.some((v) => v === null)) return null;
// const additionalItems =
// props.schema.additionalItems === undefined
// ? false
// : typeof props.schema.additionalItems === "object" &&
// props.schema.additionalItems !== null
// ? schema({
// components: props.components,
// $defs: props.$defs,
// schema: props.schema.additionalItems,
// })
// : props.schema.additionalItems;
// if (additionalItems === null) return null;
// return {
// ...props.schema,
// prefixItems: prefixItems.filter((v) => v !== null),
// additionalItems,
// };
// } else if (OpenApiTypeChecker.isObject(props.schema)) {
// const properties: Record<string, IChatGptSchema | null> = Object.entries(
// props.schema.properties || {},
// ).reduce(
// (acc, [key, value]) => {
// const converted: IChatGptSchema | null = schema({
// components: props.components,
// $defs: props.$defs,
// schema: value,
// });
// if (converted === null) return acc;
// acc[key] = converted;
// return acc;
// },
// {} as Record<string, IChatGptSchema | null>,
// );
// if (Object.values(properties).some((v) => v === null)) return null;
// const additionalProperties =
// props.schema.additionalProperties === undefined
// ? false
// : typeof props.schema.additionalProperties === "object" &&
// props.schema.additionalProperties !== null
// ? schema({
// components: props.components,
// $defs: props.$defs,
// schema: props.schema.additionalProperties,
// })
// : props.schema.additionalProperties;
// if (additionalProperties === null) return null;
// return {
// ...props.schema,
// properties: properties as Record<string, IChatGptSchema>,
// additionalProperties,
// };
// } else if (OpenApiTypeChecker.isOneOf(props.schema)) {
// const oneOf: Array<IChatGptSchema | null> = props.schema.oneOf.map(
// (item) =>
// schema({
// components: props.components,
// $defs: props.$defs,
// schema: item,
// }),
// );
// if (oneOf.some((v) => v === null)) return null;
// return {
// ...props.schema,
// anyOf: oneOf.filter((v) => v !== null),
// ...{
// oneOf: undefined,
// },
// };
// }
// return props.schema;
};
export const separate = (props: {
top: IChatGptSchema.ITop;
$defs: Record<string, IChatGptSchema>;
predicate: (schema: IChatGptSchema) => boolean;

@@ -162,3 +305,3 @@ schema: IChatGptSchema;

ChatGptTypeChecker.isUnknown(props.schema) ||
ChatGptTypeChecker.isOneOf(props.schema)
ChatGptTypeChecker.isAnyOf(props.schema)
)

@@ -168,3 +311,3 @@ return [props.schema, null];

return separateObject({
top: props.top,
$defs: props.$defs,
predicate: props.predicate,

@@ -175,3 +318,3 @@ schema: props.schema,

return separateArray({
top: props.top,
$defs: props.$defs,
predicate: props.predicate,

@@ -182,3 +325,3 @@ schema: props.schema,

return separateReference({
top: props.top,
$defs: props.$defs,
predicate: props.predicate,

@@ -191,3 +334,3 @@ schema: props.schema,

const separateArray = (props: {
top: IChatGptSchema.ITop;
$defs: Record<string, IChatGptSchema>;
predicate: (schema: IChatGptSchema) => boolean;

@@ -197,3 +340,3 @@ schema: IChatGptSchema.IArray;

const [x, y] = separate({
top: props.top,
$defs: props.$defs,
predicate: props.predicate,

@@ -219,3 +362,3 @@ schema: props.schema.items,

const separateObject = (props: {
top: IChatGptSchema.ITop;
$defs: Record<string, IChatGptSchema>;
predicate: (schema: IChatGptSchema) => boolean;

@@ -234,3 +377,3 @@ schema: IChatGptSchema.IObject;

const [x, y] = separate({
top: props.top,
$defs: props.$defs,
predicate: props.predicate,

@@ -247,3 +390,3 @@ schema: value,

const [x, y] = separate({
top: props.top,
$defs: props.$defs,
predicate: props.predicate,

@@ -271,3 +414,3 @@ schema: props.schema.additionalProperties,

const separateReference = (props: {
top: IChatGptSchema.ITop;
$defs: Record<string, IChatGptSchema>;
predicate: (schema: IChatGptSchema) => boolean;

@@ -279,5 +422,5 @@ schema: IChatGptSchema.IReference;

// FIND EXISTING
if (props.top.$defs?.[`${key}.Human`] || props.top.$defs?.[`${key}.Llm`])
if (props.$defs?.[`${key}.Human`] || props.$defs?.[`${key}.Llm`])
return [
props.top.$defs?.[`${key}.Llm`]
props.$defs?.[`${key}.Llm`]
? {

@@ -288,3 +431,3 @@ ...props.schema,

: null,
props.top.$defs?.[`${key}.Human`]
props.$defs?.[`${key}.Human`]
? {

@@ -298,16 +441,16 @@ ...props.schema,

// PRE-ASSIGNMENT
props.top.$defs![`${key}.Llm`] = {};
props.top.$defs![`${key}.Human`] = {};
props.$defs![`${key}.Llm`] = {};
props.$defs![`${key}.Human`] = {};
// DO COMPOSE
const schema: IChatGptSchema = props.top.$defs?.[key]!;
const schema: IChatGptSchema = props.$defs?.[key]!;
const [llm, human] = separate({
top: props.top,
$defs: props.$defs,
predicate: props.predicate,
schema,
});
if (llm === null) delete props.top.$defs![`${key}.Llm`];
else props.top.$defs![`${key}.Llm`] = llm;
if (human === null) delete props.top.$defs![`${key}.Human`];
else props.top.$defs![`${key}.Human`] = human;
if (llm === null) delete props.$defs![`${key}.Llm`];
else props.$defs![`${key}.Llm`] = llm;
if (human === null) delete props.$defs![`${key}.Human`];
else props.$defs![`${key}.Human`] = human;

@@ -314,0 +457,0 @@ // FINALIZE

import { OpenApi } from "../OpenApi";
import { IChatGptSchema } from "../structures/IChatGptSchema";
import { IGeminiSchema } from "../structures/IGeminiSchema";
import { IHttpLlmApplication } from "../structures/IHttpLlmApplication";

@@ -8,4 +7,2 @@ import { IHttpLlmFunction } from "../structures/IHttpLlmFunction";

import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
import { ILlmSchemaV3 } from "../structures/ILlmSchemaV3";
import { ILlmSchemaV3_1 } from "../structures/ILlmSchemaV3_1";
import { ChatGptConverter } from "./ChatGptConverter";

@@ -19,7 +16,4 @@ import { GeminiConverter } from "./GeminiConverter";

Model extends IHttpLlmApplication.Model,
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema = IHttpLlmApplication.ModelSchema[Model],
Parameters extends
IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model],
Operation extends OpenApi.IOperation = OpenApi.IOperation,

@@ -33,4 +27,7 @@ Route extends IHttpMigrateRoute = IHttpMigrateRoute<

migrate: IHttpMigrateApplication<OpenApi.IJsonSchema, Operation>;
options: IHttpLlmApplication.IOptions<Model, Schema>;
}): IHttpLlmApplication<Model, Schema, Operation, Route> => {
options: IHttpLlmApplication.IOptions<
Model,
Parameters["properties"][string]
>;
}): IHttpLlmApplication<Model, Parameters, Operation, Route> => {
// COMPOSE FUNCTIONS

@@ -45,3 +42,3 @@ const errors: IHttpLlmApplication.IError<Operation, Route>[] =

}));
const functions: IHttpLlmFunction<Schema, Operation, Route>[] =
const functions: IHttpLlmFunction<Parameters, Operation, Route>[] =
props.migrate.routes

@@ -75,3 +72,3 @@ .map((route) => {

}
const func: IHttpLlmFunction<Schema> | null = composeFunction({
const func: IHttpLlmFunction<Parameters> | null = composeFunction({
model: props.model,

@@ -93,3 +90,4 @@ options: props.options,

.filter(
(v): v is IHttpLlmFunction<Schema, Operation, Route> => v !== null,
(v): v is IHttpLlmFunction<Parameters, Operation, Route> =>
v !== null,
);

@@ -104,58 +102,25 @@ return {

export const schema = <
Model extends IHttpLlmApplication.Model,
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema = IHttpLlmApplication.ModelSchema[Model],
>(props: {
model: Model;
components: OpenApi.IComponents;
schema: OpenApi.IJsonSchema;
recursive: false | number;
}): Schema | null => {
return CASTERS[props.model]({
components: props.components,
recursive: props.recursive,
schema: props.schema,
}) as Schema | null;
};
export const separateParameters = <
Model extends IHttpLlmApplication.Model,
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema,
Parameters extends
IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model],
>(props: {
model: Model;
parameters: Schema[];
predicate: (schema: Schema) => boolean;
}): IHttpLlmFunction.ISeparated<Schema> => {
parameters: Parameters;
predicate: (schema: Parameters["properties"][string]) => boolean;
}): IHttpLlmFunction.ISeparated<Parameters> => {
const separator: (props: {
predicate: (schema: Schema) => boolean;
schema: Schema;
}) => [Schema | null, Schema | null] = SEPARATORS[props.model] as any;
const indexes: Array<[Schema | null, Schema | null]> = props.parameters.map(
(schema) =>
separator({
predicate: props.predicate,
schema,
}),
);
predicate: (schema: Parameters["properties"][string]) => boolean;
schema: Parameters["properties"][string];
}) => [
Parameters["properties"][string] | null,
Parameters["properties"][string] | null,
] = SEPARATORS[props.model] as any;
const [llm, human] = separator({
predicate: props.predicate,
schema: props.parameters as Parameters["properties"][string],
});
return {
llm: indexes
.map(([llm], index) => ({
index,
schema: llm!,
}))
.filter(({ schema }) => schema !== null),
human: indexes
.map(([, human], index) => ({
index,
schema: human!,
}))
.filter(({ schema }) => schema !== null),
llm: llm as Parameters | null,
human: human as Parameters | null,
};

@@ -166,7 +131,4 @@ };

Model extends IHttpLlmApplication.Model,
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema = IHttpLlmApplication.ModelSchema[Model],
Parameters extends
IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model],
Operation extends OpenApi.IOperation = OpenApi.IOperation,

@@ -181,5 +143,11 @@ Route extends IHttpMigrateRoute = IHttpMigrateRoute<

route: IHttpMigrateRoute<OpenApi.IJsonSchema, Operation>;
options: IHttpLlmApplication.IOptions<Model, Schema>;
}): IHttpLlmFunction<Schema, Operation, Route> | null => {
const cast = (s: OpenApi.IJsonSchema): Schema | null =>
options: IHttpLlmApplication.IOptions<
Model,
Parameters["properties"][string]
>;
}): IHttpLlmFunction<Parameters, Operation, Route> | null => {
const $defs: Record<string, IChatGptSchema> = {};
const cast = (
s: OpenApi.IJsonSchema,
): Parameters["properties"][string] | null =>
CASTERS[props.model]({

@@ -189,4 +157,5 @@ components: props.components,

schema: s,
}) as Schema | null;
const output: Schema | null | undefined =
$defs,
}) as Parameters["properties"][string] | null;
const output: Parameters["properties"][string] | null | undefined =
props.route.success && props.route.success

@@ -196,3 +165,3 @@ ? cast(props.route.success.schema)

if (output === null) return null;
const properties: [string, Schema | null][] = [
const properties: [string, Parameters["properties"][string] | null][] = [
...props.route.parameters.map((p) => ({

@@ -238,11 +207,12 @@ key: p.key,

// COMPOSE PARAMETERS
const parameters: Schema[] = props.options.keyword
? [
{
type: "object",
properties: Object.fromEntries(properties as [string, Schema][]),
additionalProperties: false,
} as any as Schema,
]
: properties.map(([_k, v]) => v!);
const parameters: Parameters = {
type: "object",
properties: Object.fromEntries(
properties as [string, Parameters["properties"][string]][],
),
additionalProperties: false,
required: properties.map(([k]) => k),
} as any as Parameters;
if (Object.keys($defs).length)
(parameters as any as IChatGptSchema.IParameters).$defs = $defs;
const operation: OpenApi.IOperation = props.route.operation();

@@ -264,3 +234,3 @@

: undefined,
output,
output: output as any,
description: (() => {

@@ -302,2 +272,3 @@ if (operation.summary && operation.description) {

recursive: false | number;
$defs: Record<string, IChatGptSchema>;
}) => ChatGptConverter.schema(props),

@@ -304,0 +275,0 @@ gemini: (props: {

@@ -535,3 +535,3 @@ import { OpenApi } from "../OpenApi";

)
: undefined,
: {},
additionalProperties: schema.additionalProperties

@@ -538,0 +538,0 @@ ? typeof schema.additionalProperties === "object" &&

@@ -332,3 +332,3 @@ import { OpenApi } from "../OpenApi";

)
: undefined,
: {},
additionalProperties: schema.additionalProperties

@@ -335,0 +335,0 @@ ? typeof schema.additionalProperties === "object" &&

@@ -344,3 +344,3 @@ import { OpenApi } from "../OpenApi";

)
: undefined,
: {},
additionalProperties: schema.additionalProperties

@@ -347,0 +347,0 @@ ? typeof schema.additionalProperties === "object" &&

import type { HttpLlm } from "../HttpLlm";
import type { HttpMigration } from "../HttpMigration";
import { OpenApi } from "../OpenApi";
import { IChatGptSchema } from "../structures/IChatGptSchema";
import { IGeminiSchema } from "../structures/IGeminiSchema";
import { IHttpLlmApplication } from "../structures/IHttpLlmApplication";
import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
import { IHttpResponse } from "../structures/IHttpResponse";
import { ILlmSchemaV3 } from "../structures/ILlmSchemaV3";
import { ILlmSchemaV3_1 } from "../structures/ILlmSchemaV3_1";
import { HttpMigrateRouteFetcher } from "./HttpMigrateRouteFetcher";

@@ -16,7 +12,4 @@

Model extends IHttpLlmApplication.Model,
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema = IHttpLlmApplication.ModelSchema[Model],
Parameters extends
IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model],
Operation extends OpenApi.IOperation = OpenApi.IOperation,

@@ -28,3 +21,3 @@ Route extends IHttpMigrateRoute = IHttpMigrateRoute<

>(
props: HttpLlm.IFetchProps<Model, Schema, Operation, Route>,
props: HttpLlm.IFetchProps<Model, Parameters, Operation, Route>,
): Promise<unknown> =>

@@ -35,7 +28,4 @@ HttpMigrateRouteFetcher.execute(getFetchArguments("execute", props));

Model extends IHttpLlmApplication.Model,
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema = IHttpLlmApplication.ModelSchema[Model],
Parameters extends
IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model],
Operation extends OpenApi.IOperation = OpenApi.IOperation,

@@ -47,3 +37,3 @@ Route extends IHttpMigrateRoute = IHttpMigrateRoute<

>(
props: HttpLlm.IFetchProps<Model, Schema, Operation, Route>,
props: HttpLlm.IFetchProps<Model, Parameters, Operation, Route>,
): Promise<IHttpResponse> =>

@@ -54,7 +44,4 @@ HttpMigrateRouteFetcher.propagate(getFetchArguments("propagate", props));

Model extends IHttpLlmApplication.Model,
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema = IHttpLlmApplication.ModelSchema[Model],
Parameters extends
IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model],
Operation extends OpenApi.IOperation = OpenApi.IOperation,

@@ -67,41 +54,21 @@ Route extends IHttpMigrateRoute = IHttpMigrateRoute<

from: string,
props: HttpLlm.IFetchProps<Model, Schema, Operation, Route>,
props: HttpLlm.IFetchProps<Model, Parameters, Operation, Route>,
): HttpMigration.IFetchProps => {
const route: Route = props.function.route();
if (props.application.options.keyword === true) {
const input: Record<string, any> = props.arguments[0];
const valid: boolean =
props.arguments.length === 1 &&
typeof input === "object" &&
input !== null;
if (valid === false)
throw new Error(
`Error on HttpLlmFunctionFetcher.${from}(): keyworded arguments must be an object`,
);
return {
connection: props.connection,
route,
parameters: Object.fromEntries(
route.parameters.map((p) => [p.key, input[p.key]] as const),
),
query: input.query,
body: input.body,
};
}
const parameters: Array<string | number | boolean | bigint | null> =
props.arguments.slice(0, route.parameters.length);
const query: object | undefined = route.query
? props.arguments[route.parameters.length]
: undefined;
const body: object | undefined = route.body
? props.arguments[route.parameters.length + (route.query ? 1 : 0)]
: undefined;
const input: Record<string, any> = props.input;
const valid: boolean = typeof input === "object" && input !== null;
if (valid === false)
throw new Error(
`Error on HttpLlmFunctionFetcher.${from}(): keyworded arguments must be an object`,
);
return {
connection: props.connection,
route,
parameters,
query,
body,
} satisfies HttpMigration.IFetchProps;
parameters: Object.fromEntries(
route.parameters.map((p) => [p.key, input[p.key]] as const),
),
query: input.query,
body: input.body,
};
};
}

@@ -71,7 +71,4 @@ import { HttpMigration } from "./HttpMigration";

Model extends IHttpLlmApplication.Model,
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema = IHttpLlmApplication.ModelSchema[Model],
Parameters extends
IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model],
Operation extends OpenApi.IOperation = OpenApi.IOperation,

@@ -83,4 +80,6 @@ >(props: {

| IHttpMigrateApplication<OpenApi.IJsonSchema, Operation>;
options?: Partial<IHttpLlmApplication.IOptions<Model, Schema>>;
}): IHttpLlmApplication<Model, Schema> => {
options?: Partial<
IHttpLlmApplication.IOptions<Model, Parameters["properties"][string]>
>;
}): IHttpLlmApplication<Model, Parameters> => {
// MIGRATE

@@ -91,7 +90,6 @@ const migrate: IHttpMigrateApplication =

: (props.document as IHttpMigrateApplication);
return HttpLlmConverter.compose<Model, Schema>({
return HttpLlmConverter.compose<Model, Parameters>({
migrate,
model: props.model,
options: {
keyword: props.options?.keyword ?? false,
separate: props.options?.separate ?? null,

@@ -102,3 +100,3 @@ recursive: (props.model === "chatgpt"

Model,
Schema
Parameters["properties"][string]
>["recursive"],

@@ -109,16 +107,2 @@ },

export const schema = <
Model extends IHttpLlmApplication.Model,
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema = IHttpLlmApplication.ModelSchema[Model],
>(props: {
model: Model;
components: OpenApi.IComponents;
schema: OpenApi.IJsonSchema;
recursive: false | number;
}): Schema | null => HttpLlmConverter.schema(props);
/* -----------------------------------------------------------

@@ -132,7 +116,4 @@ FETCHERS

Model extends IHttpLlmApplication.Model,
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema = IHttpLlmApplication.ModelSchema[Model],
Parameters extends
IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model],
Operation extends OpenApi.IOperation = OpenApi.IOperation,

@@ -147,3 +128,3 @@ Route extends IHttpMigrateRoute = IHttpMigrateRoute<

*/
application: IHttpLlmApplication<Model, Schema, Operation>;
application: IHttpLlmApplication<Model, Parameters, Operation>;

@@ -153,3 +134,3 @@ /**

*/
function: IHttpLlmFunction<Schema, Operation, Route>;
function: IHttpLlmFunction<Parameters, Operation, Route>;

@@ -162,5 +143,5 @@ /**

/**
* Arguments for the function call.
* Input arguments for the function call.
*/
arguments: any[];
input: object;
}

@@ -195,10 +176,7 @@

Model extends IHttpLlmApplication.Model,
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema = IHttpLlmApplication.ModelSchema[Model],
Parameters extends
IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model],
Operation extends OpenApi.IOperation = OpenApi.IOperation,
>(
props: IFetchProps<Model, Schema, Operation>,
props: IFetchProps<Model, Parameters, Operation>,
): Promise<unknown> => HttpLlmFunctionFetcher.execute(props);

@@ -232,10 +210,7 @@

Model extends IHttpLlmApplication.Model,
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema = IHttpLlmApplication.ModelSchema[Model],
Parameters extends
IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model],
Operation extends OpenApi.IOperation = OpenApi.IOperation,
>(
props: IFetchProps<Model, Schema, Operation>,
props: IFetchProps<Model, Parameters, Operation>,
): Promise<IHttpResponse> => HttpLlmFunctionFetcher.propagate(props);

@@ -250,7 +225,7 @@

export interface IMergeProps<
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema,
Parameters extends
| ILlmSchemaV3.IParameters
| ILlmSchemaV3_1.IParameters
| IChatGptSchema.IParameters
| IGeminiSchema.IParameters,
> {

@@ -260,3 +235,3 @@ /**

*/
function: ILlmFunction<Schema>;
function: ILlmFunction<Parameters>;

@@ -266,3 +241,3 @@ /**

*/
llm: unknown[];
llm: object | null;

@@ -272,3 +247,3 @@ /**

*/
human: unknown[];
human: object | null;
}

@@ -292,10 +267,10 @@

export const mergeParameters = <
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema,
Parameters extends
| ILlmSchemaV3.IParameters
| ILlmSchemaV3_1.IParameters
| IChatGptSchema.IParameters
| IGeminiSchema.IParameters,
>(
props: IMergeProps<Schema>,
): unknown[] => LlmDataMerger.parameters(props);
props: IMergeProps<Parameters>,
): object => LlmDataMerger.parameters(props);

@@ -302,0 +277,0 @@ /**

@@ -948,3 +948,3 @@ import { OpenApiV3 } from "./OpenApiV3";

*/
properties?: Record<string, Schema>;
properties: Record<string, Schema>;

@@ -951,0 +951,0 @@ /**

@@ -10,3 +10,3 @@ export type IChatGptSchema =

| IChatGptSchema.IReference
| IChatGptSchema.IOneOf
| IChatGptSchema.IAnyOf
| IChatGptSchema.INull

@@ -16,16 +16,14 @@ | IChatGptSchema.IUnknown;

/**
* The top level schema including `$defs`.
* Type of the function parameters.
*/
export type ITop<Schema extends IChatGptSchema = IChatGptSchema> = Schema & {
export interface IParameters extends Omit<IObject, "additionalProperties"> {
/**
* Collection of the named types.
*/
$defs?: Record<string, IChatGptSchema | undefined>;
};
/**
* Constant value type.
*/
export interface IConstant extends __IAttribute {
/**
* The constant value.
* Do not allow additional properties in the parameters.
*/
const: boolean | number | string;
additionalProperties: false;
}

@@ -38,2 +36,7 @@

/**
* Enumeration values.
*/
enum?: Array<boolean>;
/**
* The default value.

@@ -49,2 +52,7 @@ */

/**
* Enumeration values.
*/
enum?: Array<number>;
/**
* Default value.

@@ -104,2 +112,7 @@ *

/**
* Enumeration values.
*/
enum?: Array<number>;
/**
* Default value.

@@ -152,2 +165,7 @@ */

/**
* Enumeration values.
*/
enum?: Array<string>;
/**
* Default value.

@@ -321,3 +339,3 @@ */

*/
properties?: Record<string, IChatGptSchema>;
properties: Record<string, IChatGptSchema>;

@@ -403,35 +421,9 @@ /**

*/
export interface IOneOf extends __IAttribute {
export interface IAnyOf extends __IAttribute {
/**
* List of the union types.
*/
oneOf: Exclude<IChatGptSchema, IChatGptSchema.IOneOf>[];
/**
* Discriminator info of the union type.
*/
discriminator?: IOneOf.IDiscriminator;
anyOf: Exclude<IChatGptSchema, IChatGptSchema.IAnyOf>[];
}
export namespace IOneOf {
/**
* Discriminator info of the union type.
*/
export interface IDiscriminator {
/**
* Property name for the discriminator.
*/
propertyName: string;
/**
* Mapping of the discriminator value to the schema name.
*
* This property is valid only for {@link IReference} typed
* {@link IOneOf.oneof} elements. Therefore, `key` of `mapping` is
* the discriminator value, and `value` of `mapping` is the
* schema name like `#/$defs/SomeObject`.
*/
mapping?: Record<string, string>;
}
}
/**

@@ -438,0 +430,0 @@ * Null type.

@@ -46,2 +46,12 @@ /**

/**
* Type of the function parameters.
*/
export interface IParameters extends Omit<IObject, "additionalProperties"> {
/**
* Do not allow additional properties in the parameters.
*/
additionalProperties: false;
}
/**
* Boolean type schema info.

@@ -329,3 +339,3 @@ */

*/
properties?: Record<string, IGeminiSchema>;
properties: Record<string, IGeminiSchema>;

@@ -332,0 +342,0 @@ /**

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

Model extends IHttpLlmApplication.Model,
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema.ITop
| IGeminiSchema = IHttpLlmApplication.ModelSchema[Model],
Parameters extends
IHttpLlmApplication.ModelParameters[Model] = IHttpLlmApplication.ModelParameters[Model],
Operation extends OpenApi.IOperation = OpenApi.IOperation,

@@ -96,3 +93,3 @@ Route extends IHttpMigrateRoute = IHttpMigrateRoute,

*/
functions: IHttpLlmFunction<Schema, Operation, Route>[];
functions: IHttpLlmFunction<Parameters, Operation, Route>[];

@@ -110,10 +107,19 @@ /**

*/
options: IHttpLlmApplication.IOptions<Model, Schema>;
options: IHttpLlmApplication.IOptions<
Model,
Parameters["properties"][string]
>;
}
export namespace IHttpLlmApplication {
export type Model = "3.0" | "3.1" | "chatgpt" | "gemini";
export type ModelParameters = {
"3.0": ILlmSchemaV3.IParameters;
"3.1": ILlmSchemaV3_1.IParameters;
chatgpt: IChatGptSchema.IParameters;
gemini: IGeminiSchema.IParameters;
};
export type ModelSchema = {
"3.0": ILlmSchemaV3;
"3.1": ILlmSchemaV3_1;
chatgpt: IChatGptSchema.ITop;
chatgpt: IChatGptSchema;
gemini: IGeminiSchema;

@@ -172,36 +178,6 @@ };

| ILlmSchemaV3_1
| IChatGptSchema.ITop
| IChatGptSchema
| IGeminiSchema = IHttpLlmApplication.ModelSchema[Model],
> {
/**
* Whether the parameters are keyworded or not.
*
* If this property value is `true`, length of the
* {@link IHttpLlmApplication.IFunction.parameters} is always 1, and type of
* the pararameter is always {@link ILlmSchemaV3.IObject} type.
*
* Otherwise, the parameters would be multiple, and the sequence of the parameters
* are following below rules.
*
* ```typescript
* // KEYWORD TRUE
* {
* ...pathParameters,
* query,
* body,
* }
*
* // KEYWORD FALSE
* [
* ...pathParameters,
* ...(query ? [query] : []),
* ...(body ? [body] : []),
* ]
* ```
*
* @default false
*/
keyword: boolean;
/**
* Whether to allow recursive types or not.

@@ -208,0 +184,0 @@ *

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

export interface IHttpLlmFunction<
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema.ITop
| IGeminiSchema,
Parameters extends
| ILlmSchemaV3.IParameters
| ILlmSchemaV3_1.IParameters
| IChatGptSchema.IParameters
| IGeminiSchema.IParameters,
Operation extends OpenApi.IOperation = OpenApi.IOperation,

@@ -154,3 +154,3 @@ Route extends IHttpMigrateRoute = IHttpMigrateRoute,

*/
parameters: Schema[];
parameters: Parameters;

@@ -162,3 +162,3 @@ /**

*/
separated?: IHttpLlmFunction.ISeparated<Schema>;
separated?: IHttpLlmFunction.ISeparated<Parameters>;

@@ -171,3 +171,3 @@ /**

*/
output?: Schema | undefined;
output?: Parameters | undefined;

@@ -239,7 +239,7 @@ /**

export interface ISeparated<
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema.ITop
| IGeminiSchema,
Parameters extends
| ILlmSchemaV3.IParameters
| ILlmSchemaV3_1.IParameters
| IChatGptSchema.IParameters
| IGeminiSchema.IParameters,
> {

@@ -249,3 +249,3 @@ /**

*/
llm: ISeparatedParameter<Schema>[];
llm: Parameters | null;

@@ -255,27 +255,4 @@ /**

*/
human: ISeparatedParameter<Schema>[];
human: Parameters | null;
}
/**
* Separated parameter.
*/
export interface ISeparatedParameter<
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema.ITop
| IGeminiSchema,
> {
/**
* Index of the parameter.
*
* @type uint
*/
index: number;
/**
* Type schema info of the parameter.
*/
schema: Schema;
}
}

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

* successful. As LLM provider like OpenAI cannot understand the recursive reference
* type that is embodied by {@link OpenApi.IJsonSchema.IReference}, if there're some
* type that is embodied by {@link IOpenApiSchemachema.IReference}, if there're some
* recursive types in the TypeScript interface (or class) type, the conversion would

@@ -40,7 +40,4 @@ * be failed.

Model extends ILlmApplication.Model,
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema.ITop
| IGeminiSchema = ILlmApplication.ModelSchema[Model],
Parameters extends
ILlmApplication.ModelParameters[Model] = ILlmApplication.ModelParameters[Model],
> {

@@ -57,3 +54,3 @@ /**

*/
functions: ILlmFunction<Schema>[];
functions: ILlmFunction<Parameters>[];

@@ -63,10 +60,16 @@ /**

*/
options: ILlmApplication.IOptions<Model, Schema>;
options: ILlmApplication.IOptions<Model, Parameters["properties"][string]>;
}
export namespace ILlmApplication {
export type Model = "3.0" | "3.1" | "chatgpt" | "gemini";
export type ModelParameters = {
"3.0": ILlmSchemaV3.IParameters;
"3.1": ILlmSchemaV3_1.IParameters;
chatgpt: IChatGptSchema.IParameters;
gemini: IGeminiSchema.IParameters;
};
export type ModelSchema = {
"3.0": ILlmSchemaV3;
"3.1": ILlmSchemaV3_1;
chatgpt: IChatGptSchema.ITop;
chatgpt: IChatGptSchema;
gemini: IGeminiSchema;

@@ -83,3 +86,3 @@ };

| ILlmSchemaV3_1
| IChatGptSchema.ITop
| IChatGptSchema
| IGeminiSchema = ILlmApplication.ModelSchema[Model],

@@ -86,0 +89,0 @@ > {

@@ -29,7 +29,7 @@ import { IChatGptSchema } from "./IChatGptSchema";

export interface ILlmFunction<
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema.ITop
| IGeminiSchema,
Parameters extends
| ILlmSchemaV3.IParameters
| ILlmSchemaV3_1.IParameters
| IChatGptSchema.IParameters
| IGeminiSchema.IParameters,
> {

@@ -44,3 +44,3 @@ /**

*/
parameters: Schema[];
parameters: Parameters;

@@ -50,3 +50,3 @@ /**

*/
separated?: ILlmFunction.ISeparated<Schema>;
separated?: ILlmFunction.ISeparated<Parameters>;

@@ -59,5 +59,14 @@ /**

*/
output?: Schema | undefined;
output?: Parameters["properties"][string];
/**
* Whether the function schema types are strict or not.
*
* Newly added specification to "OpenAI" at 2024-08-07.
*
* @reference https://openai.com/index/introducing-structured-outputs-in-the-api/
*/
strict: true;
/**
* Description of the function.

@@ -96,7 +105,7 @@ *

export interface ISeparated<
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema.ITop
| IGeminiSchema,
Parameters extends
| ILlmSchemaV3.IParameters
| ILlmSchemaV3_1.IParameters
| IChatGptSchema.IParameters
| IGeminiSchema.IParameters,
> {

@@ -106,3 +115,3 @@ /**

*/
llm: ISeparatedParameter<Schema>[];
llm: Parameters | null;

@@ -112,27 +121,4 @@ /**

*/
human: ISeparatedParameter<Schema>[];
human: Parameters | null;
}
/**
* Separated parameter.
*/
export interface ISeparatedParameter<
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema.ITop
| IGeminiSchema,
> {
/**
* Index of the parameter.
*
* @type uint
*/
index: number;
/**
* Type schema info of the parameter.
*/
schema: Schema;
}
}

@@ -14,2 +14,12 @@ export type ILlmSchemaV3_1 =

/**
* Type of the function parameters.
*/
export interface IParameters extends Omit<IObject, "additionalProperties"> {
/**
* Do not allow additional properties in the parameters.
*/
additionalProperties: false;
}
/**
* Constant value type.

@@ -308,3 +318,3 @@ */

*/
properties?: Record<string, ILlmSchemaV3_1>;
properties: Record<string, ILlmSchemaV3_1>;

@@ -311,0 +321,0 @@ /**

@@ -32,2 +32,12 @@ /**

/**
* Type of the function parameters.
*/
export interface IParameters extends Omit<IObject, "additionalProperties"> {
/**
* Do not allow additional properties in the parameters.
*/
additionalProperties: false;
}
/**
* Boolean type schema info.

@@ -282,3 +292,3 @@ */

*/
properties?: Record<string, Schema>;
properties: Record<string, Schema>;

@@ -285,0 +295,0 @@ /**

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

(schema as IChatGptSchema.IUnknown).type === undefined &&
!isConstant(schema) &&
!isOneOf(schema) &&
!isAnyOf(schema) &&
!isReference(schema);
export const isConstant = (
schema: IChatGptSchema,
): schema is IChatGptSchema.IConstant =>
(schema as IChatGptSchema.IConstant).const !== undefined;
export const isBoolean = (

@@ -59,6 +54,6 @@ schema: IChatGptSchema,

): schema is IChatGptSchema.IReference => (schema as any).$ref !== undefined;
export const isOneOf = (
export const isAnyOf = (
schema: IChatGptSchema,
): schema is IChatGptSchema.IOneOf =>
(schema as IChatGptSchema.IOneOf).oneOf !== undefined;
): schema is IChatGptSchema.IAnyOf =>
(schema as IChatGptSchema.IAnyOf).anyOf !== undefined;

@@ -70,3 +65,3 @@ /* -----------------------------------------------------------

closure: (schema: IChatGptSchema) => void;
top: IChatGptSchema.ITop;
$defs?: Record<string, IChatGptSchema> | undefined;
schema: IChatGptSchema;

@@ -81,5 +76,5 @@ }): void => {

already.add(key);
const found: IChatGptSchema | undefined = props.top.$defs?.[key];
const found: IChatGptSchema | undefined = props.$defs?.[key];
if (found !== undefined) next(found);
} else if (ChatGptTypeChecker.isOneOf(schema)) schema.oneOf.forEach(next);
} else if (ChatGptTypeChecker.isAnyOf(schema)) schema.anyOf.forEach(next);
else if (ChatGptTypeChecker.isObject(schema)) {

@@ -106,3 +101,3 @@ for (const value of Object.values(schema.properties ?? {})) next(value);

export const covers = (props: {
top: IChatGptSchema.ITop;
$defs?: Record<string, IChatGptSchema> | undefined;
x: IChatGptSchema;

@@ -112,3 +107,3 @@ y: IChatGptSchema;

coverStation({
top: props.top,
$defs: props.$defs,
x: props.x,

@@ -120,3 +115,3 @@ y: props.y,

const coverStation = (p: {
top: IChatGptSchema.ITop;
$defs?: Record<string, IChatGptSchema> | undefined;
visited: Map<IChatGptSchema, Map<IChatGptSchema, boolean>>;

@@ -142,3 +137,3 @@ x: IChatGptSchema;

const coverSchema = (p: {
top: IChatGptSchema.ITop;
$defs?: Record<string, IChatGptSchema> | undefined;
visited: Map<IChatGptSchema, Map<IChatGptSchema, boolean>>;

@@ -154,4 +149,4 @@ x: IChatGptSchema;

// COMPARE WITH FLATTENING
const alpha: IChatGptSchema[] = flatSchema(p.top, p.x);
const beta: IChatGptSchema[] = flatSchema(p.top, p.y);
const alpha: IChatGptSchema[] = flatSchema(p.$defs, p.x);
const beta: IChatGptSchema[] = flatSchema(p.$defs, p.y);
if (alpha.some((x) => isUnknown(x))) return true;

@@ -162,3 +157,3 @@ else if (beta.some((x) => isUnknown(x))) return false;

coverEscapedSchema({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -173,3 +168,3 @@ x: a,

const coverEscapedSchema = (p: {
top: IChatGptSchema.ITop;
$defs?: Record<string, IChatGptSchema> | undefined;
visited: Map<IChatGptSchema, Map<IChatGptSchema, boolean>>;

@@ -185,16 +180,6 @@ x: IChatGptSchema;

// ATOMIC CASE
else if (isConstant(p.x)) return isConstant(p.y) && p.x.const === p.y.const;
else if (isBoolean(p.x))
return (
isBoolean(p.y) || (isConstant(p.y) && typeof p.y.const === "boolean")
);
else if (isInteger(p.x))
return (isInteger(p.y) || isConstant(p.y)) && coverInteger(p.x, p.y);
else if (isNumber(p.x))
return (
(isConstant(p.y) || isInteger(p.y) || isNumber(p.y)) &&
coverNumber(p.x, p.y)
);
else if (isString(p.x))
return (isConstant(p.y) || isString(p.y)) && coverString(p.x, p.y);
else if (isBoolean(p.x)) return isBoolean(p.y) && coverBoolean(p.x, p.y);
else if (isInteger(p.x)) return isInteger(p.y) && coverInteger(p.x, p.y);
else if (isNumber(p.x)) return isNumber(p.y) && coverNumber(p.x, p.y);
else if (isString(p.x)) return isString(p.y) && coverString(p.x, p.y);
// INSTANCE CASE

@@ -205,3 +190,3 @@ else if (isArray(p.x))

coverArray({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -216,3 +201,3 @@ x: p.x,

coverObject({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -228,3 +213,3 @@ x: p.x,

const coverArray = (p: {
top: IChatGptSchema.ITop;
$defs?: Record<string, IChatGptSchema> | undefined;
visited: Map<IChatGptSchema, Map<IChatGptSchema, boolean>>;

@@ -238,3 +223,3 @@ x: IChatGptSchema.IArray;

coverStation({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -248,3 +233,3 @@ x: p.x.items,

coverStation({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -270,3 +255,3 @@ x: p.x.items,

return coverStation({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -279,3 +264,3 @@ x: p.x.items,

const coverObject = (p: {
top: IChatGptSchema.ITop;
$defs?: Record<string, IChatGptSchema> | undefined;
visited: Map<IChatGptSchema, Map<IChatGptSchema, boolean>>;

@@ -294,3 +279,3 @@ x: IChatGptSchema.IObject;

!coverStation({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -311,3 +296,3 @@ x: p.x.additionalProperties,

return coverStation({
top: p.top,
$defs: p.$defs,
visited: p.visited,

@@ -320,8 +305,17 @@ x: a,

const coverBoolean = (
x: IChatGptSchema.IBoolean,
y: IChatGptSchema.IBoolean,
): boolean => {
if (!!x.enum?.length)
return !!y.enum?.length && y.enum.every((v) => x.enum!.includes(v));
return true;
};
const coverInteger = (
x: IChatGptSchema.IInteger,
y: IChatGptSchema.IConstant | IChatGptSchema.IInteger,
y: IChatGptSchema.IInteger,
): boolean => {
if (isConstant(y))
return typeof y.const === "number" && Number.isInteger(y.const);
if (!!x.enum?.length)
return !!y.enum?.length && y.enum.every((v) => x.enum!.includes(v));
return [

@@ -350,8 +344,6 @@ x.type === y.type,

x: IChatGptSchema.INumber,
y:
| IChatGptSchema.IConstant
| IChatGptSchema.IInteger
| IChatGptSchema.INumber,
y: IChatGptSchema.IInteger | IChatGptSchema.INumber,
): boolean => {
if (isConstant(y)) return typeof y.const === "number";
if (!!x.enum?.length)
return !!y.enum?.length && y.enum.every((v) => x.enum!.includes(v));
return [

@@ -380,6 +372,8 @@ x.type === y.type || (x.type === "number" && y.type === "integer"),

x: IChatGptSchema.IString,
y: IChatGptSchema.IConstant | IChatGptSchema.IString,
y: IChatGptSchema.IString,
): boolean => {
if (isConstant(y)) return typeof y.const === "string";
if (!!x.enum?.length)
return !!y.enum?.length && y.enum.every((v) => x.enum!.includes(v));
return [
x.type === y.type,
x.format === undefined ||

@@ -407,8 +401,8 @@ (y.format !== undefined && coverFormat(x.format, y.format)),

const flatSchema = (
top: IChatGptSchema.ITop,
$defs: Record<string, IChatGptSchema> | undefined,
schema: IChatGptSchema,
): IChatGptSchema[] => {
schema = escapeReference(top, schema);
if (isOneOf(schema))
return schema.oneOf.map((v) => flatSchema(top, v)).flat();
schema = escapeReference($defs, schema);
if (isAnyOf(schema))
return schema.anyOf.map((v) => flatSchema($defs, v)).flat();
return [schema];

@@ -418,8 +412,8 @@ };

const escapeReference = (
top: IChatGptSchema.ITop,
$defs: Record<string, IChatGptSchema> | undefined,
schema: IChatGptSchema,
): Exclude<IChatGptSchema, IChatGptSchema.IReference> =>
isReference(schema)
? escapeReference(top, top.$defs![schema.$ref.replace("#/$defs/", "")]!)
? escapeReference($defs, $defs![schema.$ref.replace("#/$defs/", "")]!)
: schema;
}
import { IChatGptSchema } from "../structures/IChatGptSchema";
import { IGeminiSchema } from "../structures/IGeminiSchema";
import { IHttpLlmFunction } from "../structures/IHttpLlmFunction";
import { ILlmFunction } from "../structures/ILlmFunction";

@@ -18,7 +17,7 @@ import { ILlmSchemaV3 } from "../structures/ILlmSchemaV3";

export interface IProps<
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema,
Parameters extends
| ILlmSchemaV3.IParameters
| ILlmSchemaV3_1.IParameters
| IChatGptSchema.IParameters
| IGeminiSchema.IParameters,
> {

@@ -28,3 +27,3 @@ /**

*/
function: ILlmFunction<Schema>;
function: ILlmFunction<Parameters>;

@@ -34,3 +33,3 @@ /**

*/
llm: any[];
llm: object | null;

@@ -40,3 +39,3 @@ /**

*/
human: any[];
human: object | null;
}

@@ -60,12 +59,11 @@

export const parameters = <
Schema extends
| ILlmSchemaV3
| ILlmSchemaV3_1
| IChatGptSchema
| IGeminiSchema,
Parameters extends
| ILlmSchemaV3.IParameters
| ILlmSchemaV3_1.IParameters
| IChatGptSchema.IParameters
| IGeminiSchema.IParameters,
>(
props: IProps<Schema>,
): unknown[] => {
const separated: IHttpLlmFunction.ISeparated<Schema> | undefined =
props.function.separated;
props: IProps<Parameters>,
): object => {
const separated = props.function.separated;
if (separated === undefined)

@@ -75,11 +73,3 @@ throw new Error(

);
return new Array(props.function.parameters.length).fill(0).map((_, i) => {
const llm: number = separated.llm.findIndex((p) => p.index === i);
const human: number = separated.human.findIndex((p) => p.index === i);
if (llm === -1 && human === -1)
throw new Error(
"Error on OpenAiDataComposer.parameters(): failed to gather separated arguments, because both LLM and human sides are all empty.",
);
return value(props.llm[llm], props.human[human]);
});
return value(props.llm, props.human) as object;
};

@@ -86,0 +76,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

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