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

@samchon/openapi

Package Overview
Dependencies
Maintainers
1
Versions
147
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.20241129 to 2.0.0-dev.20241130

23

lib/converters/ChatGptConverter.js

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

constraint: false,
} }));
}, validate: validate(props.errors) }));
if (params === null)

@@ -78,11 +78,3 @@ return null;

constraint: false,
}, validate: function (schema, accessor) {
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isObject(schema) &&
!!schema.additionalProperties) {
if (props.errors)
props.errors.push("".concat(accessor, ".additionalProperties: ChatGPT does not allow additionalProperties, the dynamic key typed object."));
return false;
}
return true;
} }));
}, validate: validate(props.errors) }));
if (schema === null)

@@ -106,2 +98,13 @@ return null;

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

@@ -108,0 +111,0 @@ var union = [];

@@ -13,5 +13,17 @@ "use strict";

};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GeminiConverter = void 0;
var LlmTypeCheckerV3_1 = require("../utils/LlmTypeCheckerV3");
var MapUtil_1 = require("../utils/MapUtil");
var OpenApiTypeChecker_1 = require("../utils/OpenApiTypeChecker");

@@ -34,2 +46,3 @@ var LlmConverterV3_1 = require("./LlmConverterV3");

}, validate: function (next, accessor) {
var e_1, _a;
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isObject(next)) {

@@ -43,2 +56,39 @@ if (!!next.additionalProperties) {

else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isOneOf(next)) {
// NULLABLE CASE
var notNull = next.oneOf.filter(function (v) { return OpenApiTypeChecker_1.OpenApiTypeChecker.isNull(v) === false; });
if (notNull.length < 2)
return true;
// ENUM CASE
var constants = notNull.filter(function (v) { return OpenApiTypeChecker_1.OpenApiTypeChecker.isConstant(v); });
var dict = new Map();
try {
for (var constants_1 = __values(constants), constants_1_1 = constants_1.next(); !constants_1_1.done; constants_1_1 = constants_1.next()) {
var v = constants_1_1.value;
MapUtil_1.MapUtil.take(dict)(typeof v.const)(function () { return []; }).push(v.const);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (constants_1_1 && !constants_1_1.done && (_a = constants_1.return)) _a.call(constants_1);
}
finally { if (e_1) throw e_1.error; }
}
if (dict.size === 1) {
if (notNull.length === constants.length)
return true;
var atomic = notNull.filter(function (v) {
return OpenApiTypeChecker_1.OpenApiTypeChecker.isBoolean(v) ||
OpenApiTypeChecker_1.OpenApiTypeChecker.isInteger(v) ||
OpenApiTypeChecker_1.OpenApiTypeChecker.isNumber(v) ||
OpenApiTypeChecker_1.OpenApiTypeChecker.isString(v);
});
if (atomic.length === 1)
if (atomic[0].type === "integer")
return (dict.has("number") &&
dict.get("number").every(function (v) { return Number.isInteger(v); }));
else
return dict.has(atomic[0].type);
}
// REAL ONE-OF TYPE
if (props.errors)

@@ -45,0 +95,0 @@ props.errors.push("".concat(accessor, ": Gemini does not allow union type."));

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

predicate: (schema: ILlmSchema.ModelSchema[Model]) => boolean;
}) => IHttpLlmFunction.ISeparated<ILlmSchema.ModelParameters[Model]>;
}) => IHttpLlmFunction.ISeparated<Model>;
}

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

accessor?: string;
validate?: (input: OpenApi.IJsonSchema, accessor: string) => boolean;
}) => ILlmSchemaV3_1.IParameters | null;

@@ -12,0 +13,0 @@ const schema: (props: {

@@ -50,5 +50,11 @@ "use strict";

LlmConverterV3_1.parameters = function (props) {
var _a;
var entity = LlmParametersFinder_1.LlmParametersFinder.find(props);
if (entity === null)
return null;
else if (!!entity.additionalProperties) {
if (props.errors)
props.errors.push("".concat((_a = props.accessor) !== null && _a !== void 0 ? _a : "$input", ".additionalProperties: LLM does not allow additional properties on parameters."));
return null;
}
var $defs = {};

@@ -59,2 +65,3 @@ var res = LlmConverterV3_1.schema(__assign(__assign({}, props), { $defs: $defs, schema: entity, refAccessor: props.accessor ? "".concat(props.accessor, "/$defs") : undefined }));

res.$defs = $defs;
res.additionalProperties = false;
return res;

@@ -61,0 +68,0 @@ };

@@ -50,6 +50,15 @@ "use strict";

LlmConverterV3.parameters = function (props) {
var _a;
var entity = LlmParametersFinder_1.LlmParametersFinder.find(props);
if (entity === null)
return null;
return LlmConverterV3.schema(__assign(__assign({}, props), { schema: entity }));
else if (!!entity.additionalProperties) {
if (props.errors)
props.errors.push("".concat((_a = props.accessor) !== null && _a !== void 0 ? _a : "$input", ".additionalProperties: LLM does not allow additional properties on parameters."));
return null;
}
var res = LlmConverterV3.schema(__assign(__assign({}, props), { schema: entity }));
if (res !== null)
res.additionalProperties = false;
return res;
};

@@ -107,3 +116,2 @@ LlmConverterV3.schema = function (props) {

(_b = next.required) !== null && _b !== void 0 ? _b : (next.required = []);
next.additionalProperties = false;
}

@@ -110,0 +118,0 @@ else if (props.config.constraint === false &&

import { OpenApi } from "../OpenApi";
import { IChatGptSchema } from "./IChatGptSchema";
import { IGeminiSchema } from "./IGeminiSchema";
import { IHttpMigrateRoute } from "./IHttpMigrateRoute";
import { ILlmSchema } from "./ILlmSchema";
import { ILlmSchemaV3 } from "./ILlmSchemaV3";
import { ILlmSchemaV3_1 } from "./ILlmSchemaV3_1";
/**

@@ -147,3 +143,3 @@ * LLM function calling schema from HTTP (OpenAPI) operation.

*/
separated?: IHttpLlmFunction.ISeparated<ILlmSchema.ModelParameters[Model]>;
separated?: IHttpLlmFunction.ISeparated<Model>;
/**

@@ -216,12 +212,12 @@ * Expected return type.

*/
interface ISeparated<Parameters extends ILlmSchemaV3.IParameters | ILlmSchemaV3_1.IParameters | IChatGptSchema.IParameters | IGeminiSchema.IParameters> {
interface ISeparated<Model extends ILlmSchema.Model> {
/**
* Parameters that would be composed by the LLM.
*/
llm: Parameters | null;
llm: ILlmSchema.ModelParameters[Model] | null;
/**
* Parameters that would be composed by the human.
*/
human: Parameters | null;
human: ILlmSchema.ModelParameters[Model] | null;
}
}

@@ -1,7 +0,2 @@

import { IChatGptSchema } from "./IChatGptSchema";
import { IClaudeSchema } from "./IClaudeSchema";
import { IGeminiSchema } from "./IGeminiSchema";
import { ILlmSchema } from "./ILlmSchema";
import { ILlmSchemaV3 } from "./ILlmSchemaV3";
import { ILlmSchemaV3_1 } from "./ILlmSchemaV3_1";
/**

@@ -41,3 +36,3 @@ * LLM function metadata.

*/
separated?: ILlmFunction.ISeparated<ILlmSchema.ModelParameters[Model]>;
separated?: ILlmFunction.ISeparated<Model>;
/**

@@ -89,12 +84,12 @@ * Expected return type.

*/
interface ISeparated<Parameters extends IChatGptSchema.IParameters | IClaudeSchema.IParameters | IGeminiSchema.IParameters | ILlmSchemaV3.IParameters | ILlmSchemaV3_1.IParameters> {
interface ISeparated<Model extends ILlmSchema.Model> {
/**
* Parameters that would be composed by the LLM.
*/
llm: Parameters | null;
llm: ILlmSchema.ModelParameters[Model] | null;
/**
* Parameters that would be composed by the human.
*/
human: Parameters | null;
human: ILlmSchema.ModelParameters[Model] | null;
}
}
{
"name": "@samchon/openapi",
"version": "2.0.0-dev.20241129",
"version": "2.0.0-dev.20241130",
"description": "OpenAPI definitions and converters for 'typia' and 'nestia'.",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

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

},
validate: validate(props.errors),
});

@@ -48,15 +49,3 @@ if (params === null) return null;

},
validate: (schema, accessor) => {
if (
OpenApiTypeChecker.isObject(schema) &&
!!schema.additionalProperties
) {
if (props.errors)
props.errors.push(
`${accessor}.additionalProperties: ChatGPT does not allow additionalProperties, the dynamic key typed object.`,
);
return false;
}
return true;
},
validate: validate(props.errors),
});

@@ -70,2 +59,18 @@ if (schema === null) return null;

const validate =
(errors: string[] | undefined) =>
(schema: OpenApi.IJsonSchema, accessor: string): boolean => {
if (
OpenApiTypeChecker.isObject(schema) &&
!!schema.additionalProperties
) {
if (errors)
errors.push(
`${accessor}.additionalProperties: ChatGPT does not allow additionalProperties, the dynamic key typed object.`,
);
return false;
}
return true;
};
const transform = (schema: ILlmSchemaV3_1): IChatGptSchema => {

@@ -72,0 +77,0 @@ const union: Array<IChatGptSchema> = [];

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

import { LlmTypeCheckerV3 } from "../utils/LlmTypeCheckerV3";
import { MapUtil } from "../utils/MapUtil";
import { OpenApiTypeChecker } from "../utils/OpenApiTypeChecker";

@@ -51,2 +52,36 @@ import { LlmConverterV3 } from "./LlmConverterV3";

} else if (OpenApiTypeChecker.isOneOf(next)) {
// NULLABLE CASE
const notNull = next.oneOf.filter(
(v) => OpenApiTypeChecker.isNull(v) === false,
);
if (notNull.length < 2) return true;
// ENUM CASE
const constants: OpenApi.IJsonSchema.IConstant[] = notNull.filter(
(v) => OpenApiTypeChecker.isConstant(v),
);
const dict: Map<"boolean" | "number" | "string", any> = new Map();
for (const v of constants)
MapUtil.take(dict)(typeof v.const as "number")(() => []).push(
v.const,
);
if (dict.size === 1) {
if (notNull.length === constants.length) return true;
const atomic = notNull.filter(
(v) =>
OpenApiTypeChecker.isBoolean(v) ||
OpenApiTypeChecker.isInteger(v) ||
OpenApiTypeChecker.isNumber(v) ||
OpenApiTypeChecker.isString(v),
);
if (atomic.length === 1)
if (atomic[0].type === "integer")
return (
dict.has("number") &&
dict.get("number")!.every((v: number) => Number.isInteger(v))
);
else return dict.has(atomic[0].type);
}
// REAL ONE-OF TYPE
if (props.errors)

@@ -53,0 +88,0 @@ props.errors.push(`${accessor}: Gemini does not allow union type.`);

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

predicate: (schema: ILlmSchema.ModelSchema[Model]) => boolean;
}): IHttpLlmFunction.ISeparated<ILlmSchema.ModelParameters[Model]> => {
}): IHttpLlmFunction.ISeparated<Model> => {
const separator: (props: {

@@ -106,5 +106,3 @@ predicate: (schema: ILlmSchema.ModelSchema[Model]) => boolean;

human,
} satisfies IHttpLlmFunction.ISeparated<
ILlmSchema.ModelParameters[Model]
> as IHttpLlmFunction.ISeparated<ILlmSchema.ModelParameters[Model]>;
} satisfies IHttpLlmFunction.ISeparated<Model>;
};

@@ -111,0 +109,0 @@

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

accessor?: string;
validate?: (input: OpenApi.IJsonSchema, accessor: string) => boolean;
}): ILlmSchemaV3_1.IParameters | null => {

@@ -21,2 +22,9 @@ const entity: OpenApi.IJsonSchema.IObject | null =

if (entity === null) return null;
else if (!!entity.additionalProperties) {
if (props.errors)
props.errors.push(
`${props.accessor ?? "$input"}.additionalProperties: LLM does not allow additional properties on parameters.`,
);
return null;
}

@@ -32,2 +40,3 @@ const $defs: Record<string, ILlmSchemaV3_1> = {};

res.$defs = $defs;
res.additionalProperties = false;
return res;

@@ -34,0 +43,0 @@ };

@@ -20,6 +20,15 @@ import { OpenApi } from "../OpenApi";

if (entity === null) return null;
return schema({
else if (!!entity.additionalProperties) {
if (props.errors)
props.errors.push(
`${props.accessor ?? "$input"}.additionalProperties: LLM does not allow additional properties on parameters.`,
);
return null;
}
const res = schema({
...props,
schema: entity,
}) as ILlmSchemaV3.IParameters | null;
if (res !== null) res.additionalProperties = false;
return res;
};

@@ -91,3 +100,2 @@

next.required ??= [];
next.additionalProperties = false;
} else if (

@@ -94,0 +102,0 @@ props.config.constraint === false &&

import { OpenApi } from "../OpenApi";
import { IChatGptSchema } from "./IChatGptSchema";
import { IGeminiSchema } from "./IGeminiSchema";
import { IHttpMigrateRoute } from "./IHttpMigrateRoute";
import { ILlmSchema } from "./ILlmSchema";
import { ILlmSchemaV3 } from "./ILlmSchemaV3";
import { ILlmSchemaV3_1 } from "./ILlmSchemaV3_1";

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

*/
separated?: IHttpLlmFunction.ISeparated<ILlmSchema.ModelParameters[Model]>;
separated?: IHttpLlmFunction.ISeparated<Model>;

@@ -228,13 +224,7 @@ /**

*/
export interface ISeparated<
Parameters extends
| ILlmSchemaV3.IParameters
| ILlmSchemaV3_1.IParameters
| IChatGptSchema.IParameters
| IGeminiSchema.IParameters,
> {
export interface ISeparated<Model extends ILlmSchema.Model> {
/**
* Parameters that would be composed by the LLM.
*/
llm: Parameters | null;
llm: ILlmSchema.ModelParameters[Model] | null;

@@ -244,4 +234,4 @@ /**

*/
human: Parameters | null;
human: ILlmSchema.ModelParameters[Model] | null;
}
}

@@ -1,7 +0,2 @@

import { IChatGptSchema } from "./IChatGptSchema";
import { IClaudeSchema } from "./IClaudeSchema";
import { IGeminiSchema } from "./IGeminiSchema";
import { ILlmSchema } from "./ILlmSchema";
import { ILlmSchemaV3 } from "./ILlmSchemaV3";
import { ILlmSchemaV3_1 } from "./ILlmSchemaV3_1";

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

*/
separated?: ILlmFunction.ISeparated<ILlmSchema.ModelParameters[Model]>;
separated?: ILlmFunction.ISeparated<Model>;

@@ -97,14 +92,7 @@ /**

*/
export interface ISeparated<
Parameters extends
| IChatGptSchema.IParameters
| IClaudeSchema.IParameters
| IGeminiSchema.IParameters
| ILlmSchemaV3.IParameters
| ILlmSchemaV3_1.IParameters,
> {
export interface ISeparated<Model extends ILlmSchema.Model> {
/**
* Parameters that would be composed by the LLM.
*/
llm: Parameters | null;
llm: ILlmSchema.ModelParameters[Model] | null;

@@ -114,4 +102,4 @@ /**

*/
human: Parameters | null;
human: ILlmSchema.ModelParameters[Model] | null;
}
}

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