@typia/utils 13.0.0-dev.20260427-3 → 13.0.0-dev.20260430
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/converters/LlmSchemaConverter.js +6 -15
- package/lib/converters/LlmSchemaConverter.js.map +1 -1
- package/lib/converters/LlmSchemaConverter.mjs +2 -7
- package/lib/converters/LlmSchemaConverter.mjs.map +1 -1
- package/lib/converters/LlmSchemaConverter2.mjs +440 -451
- package/lib/converters/LlmSchemaConverter2.mjs.map +1 -1
- package/lib/converters/OpenApiConverter.mjs +2 -7
- package/lib/converters/OpenApiConverter.mjs.map +1 -1
- package/lib/converters/OpenApiConverter2.mjs +163 -164
- package/lib/converters/OpenApiConverter2.mjs.map +1 -1
- package/lib/converters/index.mjs +1 -7
- package/lib/converters/index.mjs.map +1 -1
- package/lib/converters/index2.mjs +31 -32
- package/lib/converters/index2.mjs.map +1 -1
- package/lib/converters/internal/LlmDescriptionInverter.mjs +2 -7
- package/lib/converters/internal/LlmDescriptionInverter.mjs.map +1 -1
- package/lib/converters/internal/LlmDescriptionInverter2.mjs +143 -150
- package/lib/converters/internal/LlmDescriptionInverter2.mjs.map +1 -1
- package/lib/converters/internal/LlmParametersComposer.mjs +2 -7
- package/lib/converters/internal/LlmParametersComposer.mjs.map +1 -1
- package/lib/converters/internal/LlmParametersComposer2.mjs +37 -44
- package/lib/converters/internal/LlmParametersComposer2.mjs.map +1 -1
- package/lib/converters/internal/OpenApiConstraintShifter.mjs +2 -7
- package/lib/converters/internal/OpenApiConstraintShifter.mjs.map +1 -1
- package/lib/converters/internal/OpenApiConstraintShifter2.mjs +105 -112
- package/lib/converters/internal/OpenApiConstraintShifter2.mjs.map +1 -1
- package/lib/converters/internal/OpenApiExclusiveEmender.mjs +2 -7
- package/lib/converters/internal/OpenApiExclusiveEmender.mjs.map +1 -1
- package/lib/converters/internal/OpenApiExclusiveEmender2.mjs +32 -40
- package/lib/converters/internal/OpenApiExclusiveEmender2.mjs.map +1 -1
- package/lib/converters/internal/OpenApiV3Downgrader.mjs +2 -7
- package/lib/converters/internal/OpenApiV3Downgrader.mjs.map +1 -1
- package/lib/converters/internal/OpenApiV3Downgrader2.mjs +237 -244
- package/lib/converters/internal/OpenApiV3Downgrader2.mjs.map +1 -1
- package/lib/converters/internal/OpenApiV3Upgrader.mjs +2 -7
- package/lib/converters/internal/OpenApiV3Upgrader.mjs.map +1 -1
- package/lib/converters/internal/OpenApiV3Upgrader2.mjs +300 -305
- package/lib/converters/internal/OpenApiV3Upgrader2.mjs.map +1 -1
- package/lib/converters/internal/OpenApiV3_1Downgrader.mjs +2 -7
- package/lib/converters/internal/OpenApiV3_1Downgrader.mjs.map +1 -1
- package/lib/converters/internal/OpenApiV3_1Downgrader2.mjs +193 -200
- package/lib/converters/internal/OpenApiV3_1Downgrader2.mjs.map +1 -1
- package/lib/converters/internal/OpenApiV3_1Upgrader.mjs +2 -7
- package/lib/converters/internal/OpenApiV3_1Upgrader.mjs.map +1 -1
- package/lib/converters/internal/OpenApiV3_1Upgrader2.mjs +424 -429
- package/lib/converters/internal/OpenApiV3_1Upgrader2.mjs.map +1 -1
- package/lib/converters/internal/OpenApiV3_2Upgrader.mjs +2 -7
- package/lib/converters/internal/OpenApiV3_2Upgrader.mjs.map +1 -1
- package/lib/converters/internal/OpenApiV3_2Upgrader2.mjs +202 -208
- package/lib/converters/internal/OpenApiV3_2Upgrader2.mjs.map +1 -1
- package/lib/converters/internal/SwaggerV2Downgrader.mjs +2 -7
- package/lib/converters/internal/SwaggerV2Downgrader.mjs.map +1 -1
- package/lib/converters/internal/SwaggerV2Downgrader2.mjs +287 -294
- package/lib/converters/internal/SwaggerV2Downgrader2.mjs.map +1 -1
- package/lib/converters/internal/SwaggerV2Upgrader.mjs +2 -7
- package/lib/converters/internal/SwaggerV2Upgrader.mjs.map +1 -1
- package/lib/converters/internal/SwaggerV2Upgrader2.mjs +370 -375
- package/lib/converters/internal/SwaggerV2Upgrader2.mjs.map +1 -1
- package/lib/http/HttpError.mjs +2 -7
- package/lib/http/HttpError.mjs.map +1 -1
- package/lib/http/HttpError2.mjs +69 -77
- package/lib/http/HttpError2.mjs.map +1 -1
- package/lib/http/HttpLlm.mjs +2 -7
- package/lib/http/HttpLlm.mjs.map +1 -1
- package/lib/http/HttpLlm2.mjs +107 -112
- package/lib/http/HttpLlm2.mjs.map +1 -1
- package/lib/http/HttpMigration.mjs +2 -7
- package/lib/http/HttpMigration.mjs.map +1 -1
- package/lib/http/HttpMigration2.mjs +58 -63
- package/lib/http/HttpMigration2.mjs.map +1 -1
- package/lib/http/index.mjs +1 -7
- package/lib/http/index.mjs.map +1 -1
- package/lib/http/index2.mjs +30 -31
- package/lib/http/index2.mjs.map +1 -1
- package/lib/http/internal/HttpLlmApplicationComposer.mjs +2 -7
- package/lib/http/internal/HttpLlmApplicationComposer.mjs.map +1 -1
- package/lib/http/internal/HttpLlmApplicationComposer2.mjs +301 -306
- package/lib/http/internal/HttpLlmApplicationComposer2.mjs.map +1 -1
- package/lib/http/internal/HttpLlmFunctionFetcher.mjs +2 -7
- package/lib/http/internal/HttpLlmFunctionFetcher.mjs.map +1 -1
- package/lib/http/internal/HttpLlmFunctionFetcher2.mjs +26 -33
- package/lib/http/internal/HttpLlmFunctionFetcher2.mjs.map +1 -1
- package/lib/http/internal/HttpMigrateApplicationComposer.mjs +2 -7
- package/lib/http/internal/HttpMigrateApplicationComposer.mjs.map +1 -1
- package/lib/http/internal/HttpMigrateApplicationComposer2.mjs +51 -56
- package/lib/http/internal/HttpMigrateApplicationComposer2.mjs.map +1 -1
- package/lib/http/internal/HttpMigrateRouteAccessor.mjs +2 -7
- package/lib/http/internal/HttpMigrateRouteAccessor.mjs.map +1 -1
- package/lib/http/internal/HttpMigrateRouteAccessor2.mjs +113 -118
- package/lib/http/internal/HttpMigrateRouteAccessor2.mjs.map +1 -1
- package/lib/http/internal/HttpMigrateRouteComposer.mjs +2 -7
- package/lib/http/internal/HttpMigrateRouteComposer.mjs.map +1 -1
- package/lib/http/internal/HttpMigrateRouteComposer2.mjs +376 -381
- package/lib/http/internal/HttpMigrateRouteComposer2.mjs.map +1 -1
- package/lib/http/internal/HttpMigrateRouteFetcher.mjs +2 -7
- package/lib/http/internal/HttpMigrateRouteFetcher.mjs.map +1 -1
- package/lib/http/internal/HttpMigrateRouteFetcher2.mjs +182 -189
- package/lib/http/internal/HttpMigrateRouteFetcher2.mjs.map +1 -1
- package/lib/index.mjs +1 -7
- package/lib/index.mjs.map +1 -1
- package/lib/index2.mjs +33 -33
- package/lib/index2.mjs.map +1 -1
- package/lib/utils/ArrayUtil.mjs +2 -7
- package/lib/utils/ArrayUtil.mjs.map +1 -1
- package/lib/utils/ArrayUtil2.mjs +29 -37
- package/lib/utils/ArrayUtil2.mjs.map +1 -1
- package/lib/utils/LlmJson.mjs +2 -7
- package/lib/utils/LlmJson.mjs.map +1 -1
- package/lib/utils/LlmJson2.mjs +166 -169
- package/lib/utils/LlmJson2.mjs.map +1 -1
- package/lib/utils/MapUtil.mjs +2 -7
- package/lib/utils/MapUtil.mjs.map +1 -1
- package/lib/utils/MapUtil2.mjs +16 -24
- package/lib/utils/MapUtil2.mjs.map +1 -1
- package/lib/utils/NamingConvention.mjs +2 -7
- package/lib/utils/NamingConvention.mjs.map +1 -1
- package/lib/utils/NamingConvention2.mjs +199 -207
- package/lib/utils/NamingConvention2.mjs.map +1 -1
- package/lib/utils/Singleton.d.ts +1 -6
- package/lib/utils/Singleton.js +1 -0
- package/lib/utils/Singleton.js.map +1 -1
- package/lib/utils/Singleton.mjs +2 -7
- package/lib/utils/Singleton.mjs.map +1 -1
- package/lib/utils/Singleton2.mjs +17 -24
- package/lib/utils/Singleton2.mjs.map +1 -1
- package/lib/utils/StringUtil.mjs +2 -7
- package/lib/utils/StringUtil.mjs.map +1 -1
- package/lib/utils/StringUtil2.mjs +14 -22
- package/lib/utils/StringUtil2.mjs.map +1 -1
- package/lib/utils/dedent.mjs +2 -7
- package/lib/utils/dedent.mjs.map +1 -1
- package/lib/utils/dedent2.mjs +50 -58
- package/lib/utils/dedent2.mjs.map +1 -1
- package/lib/utils/index.mjs +1 -7
- package/lib/utils/index.mjs.map +1 -1
- package/lib/utils/index2.mjs +42 -39
- package/lib/utils/index2.mjs.map +1 -1
- package/lib/utils/internal/EndpointUtil.mjs +2 -7
- package/lib/utils/internal/EndpointUtil.mjs.map +1 -1
- package/lib/utils/internal/EndpointUtil2.mjs +39 -46
- package/lib/utils/internal/EndpointUtil2.mjs.map +1 -1
- package/lib/utils/internal/JsonDescriptor.mjs +2 -7
- package/lib/utils/internal/JsonDescriptor.mjs.map +1 -1
- package/lib/utils/internal/JsonDescriptor2.mjs +55 -61
- package/lib/utils/internal/JsonDescriptor2.mjs.map +1 -1
- package/lib/utils/internal/OpenApiTypeCheckerBase.js +23 -14
- package/lib/utils/internal/OpenApiTypeCheckerBase.js.map +1 -1
- package/lib/utils/internal/OpenApiTypeCheckerBase.mjs +2 -7
- package/lib/utils/internal/OpenApiTypeCheckerBase.mjs.map +1 -1
- package/lib/utils/internal/OpenApiTypeCheckerBase2.mjs +539 -536
- package/lib/utils/internal/OpenApiTypeCheckerBase2.mjs.map +1 -1
- package/lib/utils/internal/coerceLlmArguments.js +27 -1
- package/lib/utils/internal/coerceLlmArguments.js.map +1 -1
- package/lib/utils/internal/coerceLlmArguments.mjs +2 -7
- package/lib/utils/internal/coerceLlmArguments.mjs.map +1 -1
- package/lib/utils/internal/coerceLlmArguments2.mjs +278 -258
- package/lib/utils/internal/coerceLlmArguments2.mjs.map +1 -1
- package/lib/utils/internal/parseLenientJson.mjs +2 -7
- package/lib/utils/internal/parseLenientJson.mjs.map +1 -1
- package/lib/utils/internal/parseLenientJson2.mjs +803 -811
- package/lib/utils/internal/parseLenientJson2.mjs.map +1 -1
- package/lib/utils/internal/stringifyValidationFailure.mjs +2 -7
- package/lib/utils/internal/stringifyValidationFailure.mjs.map +1 -1
- package/lib/utils/internal/stringifyValidationFailure2.mjs +310 -316
- package/lib/utils/internal/stringifyValidationFailure2.mjs.map +1 -1
- package/lib/validators/LlmTypeChecker.mjs +2 -7
- package/lib/validators/LlmTypeChecker.mjs.map +1 -1
- package/lib/validators/LlmTypeChecker2.mjs +314 -320
- package/lib/validators/LlmTypeChecker2.mjs.map +1 -1
- package/lib/validators/OpenApiTypeChecker.mjs +2 -7
- package/lib/validators/OpenApiTypeChecker.mjs.map +1 -1
- package/lib/validators/OpenApiTypeChecker2.mjs +209 -216
- package/lib/validators/OpenApiTypeChecker2.mjs.map +1 -1
- package/lib/validators/OpenApiV3TypeChecker.mjs +2 -7
- package/lib/validators/OpenApiV3TypeChecker.mjs.map +1 -1
- package/lib/validators/OpenApiV3TypeChecker2.mjs +30 -38
- package/lib/validators/OpenApiV3TypeChecker2.mjs.map +1 -1
- package/lib/validators/OpenApiV3_1TypeChecker.mjs +2 -7
- package/lib/validators/OpenApiV3_1TypeChecker.mjs.map +1 -1
- package/lib/validators/OpenApiV3_1TypeChecker2.mjs +34 -42
- package/lib/validators/OpenApiV3_1TypeChecker2.mjs.map +1 -1
- package/lib/validators/OpenApiValidator.mjs +2 -7
- package/lib/validators/OpenApiValidator.mjs.map +1 -1
- package/lib/validators/OpenApiValidator2.mjs +73 -80
- package/lib/validators/OpenApiValidator2.mjs.map +1 -1
- package/lib/validators/SwaggerV2TypeChecker.mjs +2 -7
- package/lib/validators/SwaggerV2TypeChecker.mjs.map +1 -1
- package/lib/validators/SwaggerV2TypeChecker2.mjs +31 -39
- package/lib/validators/SwaggerV2TypeChecker2.mjs.map +1 -1
- package/lib/validators/functional/_isBigintString.mjs +2 -7
- package/lib/validators/functional/_isBigintString.mjs.map +1 -1
- package/lib/validators/functional/_isBigintString2.mjs +14 -22
- package/lib/validators/functional/_isBigintString2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatByte.mjs +2 -7
- package/lib/validators/functional/_isFormatByte.mjs.map +1 -1
- package/lib/validators/functional/_isFormatByte2.mjs +10 -18
- package/lib/validators/functional/_isFormatByte2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatDate.mjs +2 -7
- package/lib/validators/functional/_isFormatDate.mjs.map +1 -1
- package/lib/validators/functional/_isFormatDate2.mjs +7 -15
- package/lib/validators/functional/_isFormatDate2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatDateTime.mjs +2 -7
- package/lib/validators/functional/_isFormatDateTime.mjs.map +1 -1
- package/lib/validators/functional/_isFormatDateTime2.mjs +7 -15
- package/lib/validators/functional/_isFormatDateTime2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatDuration.mjs +2 -7
- package/lib/validators/functional/_isFormatDuration.mjs.map +1 -1
- package/lib/validators/functional/_isFormatDuration2.mjs +7 -15
- package/lib/validators/functional/_isFormatDuration2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatEmail.mjs +2 -7
- package/lib/validators/functional/_isFormatEmail.mjs.map +1 -1
- package/lib/validators/functional/_isFormatEmail2.mjs +7 -15
- package/lib/validators/functional/_isFormatEmail2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatHostname.mjs +2 -7
- package/lib/validators/functional/_isFormatHostname.mjs.map +1 -1
- package/lib/validators/functional/_isFormatHostname2.mjs +7 -15
- package/lib/validators/functional/_isFormatHostname2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatIdnEmail.mjs +2 -7
- package/lib/validators/functional/_isFormatIdnEmail.mjs.map +1 -1
- package/lib/validators/functional/_isFormatIdnEmail2.mjs +7 -15
- package/lib/validators/functional/_isFormatIdnEmail2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatIdnHostname.mjs +2 -7
- package/lib/validators/functional/_isFormatIdnHostname.mjs.map +1 -1
- package/lib/validators/functional/_isFormatIdnHostname2.mjs +7 -15
- package/lib/validators/functional/_isFormatIdnHostname2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatIpv4.mjs +2 -7
- package/lib/validators/functional/_isFormatIpv4.mjs.map +1 -1
- package/lib/validators/functional/_isFormatIpv42.mjs +7 -15
- package/lib/validators/functional/_isFormatIpv42.mjs.map +1 -1
- package/lib/validators/functional/_isFormatIpv6.mjs +2 -7
- package/lib/validators/functional/_isFormatIpv6.mjs.map +1 -1
- package/lib/validators/functional/_isFormatIpv62.mjs +7 -15
- package/lib/validators/functional/_isFormatIpv62.mjs.map +1 -1
- package/lib/validators/functional/_isFormatIri.mjs +2 -7
- package/lib/validators/functional/_isFormatIri.mjs.map +1 -1
- package/lib/validators/functional/_isFormatIri2.mjs +7 -15
- package/lib/validators/functional/_isFormatIri2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatIriReference.mjs +2 -7
- package/lib/validators/functional/_isFormatIriReference.mjs.map +1 -1
- package/lib/validators/functional/_isFormatIriReference2.mjs +7 -15
- package/lib/validators/functional/_isFormatIriReference2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatJsonPointer.mjs +2 -7
- package/lib/validators/functional/_isFormatJsonPointer.mjs.map +1 -1
- package/lib/validators/functional/_isFormatJsonPointer2.mjs +7 -15
- package/lib/validators/functional/_isFormatJsonPointer2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatPassword.mjs +2 -7
- package/lib/validators/functional/_isFormatPassword.mjs.map +1 -1
- package/lib/validators/functional/_isFormatPassword2.mjs +6 -14
- package/lib/validators/functional/_isFormatPassword2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatRegex.mjs +2 -7
- package/lib/validators/functional/_isFormatRegex.mjs.map +1 -1
- package/lib/validators/functional/_isFormatRegex2.mjs +14 -22
- package/lib/validators/functional/_isFormatRegex2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatRelativeJsonPointer.mjs +2 -7
- package/lib/validators/functional/_isFormatRelativeJsonPointer.mjs.map +1 -1
- package/lib/validators/functional/_isFormatRelativeJsonPointer2.mjs +7 -15
- package/lib/validators/functional/_isFormatRelativeJsonPointer2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatTime.mjs +2 -7
- package/lib/validators/functional/_isFormatTime.mjs.map +1 -1
- package/lib/validators/functional/_isFormatTime2.mjs +7 -15
- package/lib/validators/functional/_isFormatTime2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatUri.mjs +2 -7
- package/lib/validators/functional/_isFormatUri.mjs.map +1 -1
- package/lib/validators/functional/_isFormatUri2.mjs +8 -16
- package/lib/validators/functional/_isFormatUri2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatUriReference.mjs +2 -7
- package/lib/validators/functional/_isFormatUriReference.mjs.map +1 -1
- package/lib/validators/functional/_isFormatUriReference2.mjs +7 -15
- package/lib/validators/functional/_isFormatUriReference2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatUriTemplate.mjs +2 -7
- package/lib/validators/functional/_isFormatUriTemplate.mjs.map +1 -1
- package/lib/validators/functional/_isFormatUriTemplate2.mjs +7 -15
- package/lib/validators/functional/_isFormatUriTemplate2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatUrl.mjs +2 -7
- package/lib/validators/functional/_isFormatUrl.mjs.map +1 -1
- package/lib/validators/functional/_isFormatUrl2.mjs +7 -15
- package/lib/validators/functional/_isFormatUrl2.mjs.map +1 -1
- package/lib/validators/functional/_isFormatUuid.mjs +2 -7
- package/lib/validators/functional/_isFormatUuid.mjs.map +1 -1
- package/lib/validators/functional/_isFormatUuid2.mjs +7 -15
- package/lib/validators/functional/_isFormatUuid2.mjs.map +1 -1
- package/lib/validators/functional/_isUniqueItems.mjs +2 -7
- package/lib/validators/functional/_isUniqueItems.mjs.map +1 -1
- package/lib/validators/functional/_isUniqueItems2.mjs +140 -148
- package/lib/validators/functional/_isUniqueItems2.mjs.map +1 -1
- package/lib/validators/index.mjs +1 -7
- package/lib/validators/index.mjs.map +1 -1
- package/lib/validators/index2.mjs +42 -40
- package/lib/validators/index2.mjs.map +1 -1
- package/lib/validators/internal/IOpenApiValidatorContext.mjs +2 -7
- package/lib/validators/internal/IOpenApiValidatorContext.mjs.map +1 -1
- package/lib/validators/internal/IOpenApiValidatorContext2.mjs +2 -10
- package/lib/validators/internal/IOpenApiValidatorContext2.mjs.map +1 -1
- package/lib/validators/internal/OpenApiArrayValidator.mjs +2 -7
- package/lib/validators/internal/OpenApiArrayValidator.mjs.map +1 -1
- package/lib/validators/internal/OpenApiArrayValidator2.mjs +36 -42
- package/lib/validators/internal/OpenApiArrayValidator2.mjs.map +1 -1
- package/lib/validators/internal/OpenApiBooleanValidator.mjs +2 -7
- package/lib/validators/internal/OpenApiBooleanValidator.mjs.map +1 -1
- package/lib/validators/internal/OpenApiBooleanValidator2.mjs +10 -18
- package/lib/validators/internal/OpenApiBooleanValidator2.mjs.map +1 -1
- package/lib/validators/internal/OpenApiConstantValidator.mjs +2 -7
- package/lib/validators/internal/OpenApiConstantValidator.mjs.map +1 -1
- package/lib/validators/internal/OpenApiConstantValidator2.mjs +10 -18
- package/lib/validators/internal/OpenApiConstantValidator2.mjs.map +1 -1
- package/lib/validators/internal/OpenApiIntegerValidator.mjs +2 -7
- package/lib/validators/internal/OpenApiIntegerValidator.mjs.map +1 -1
- package/lib/validators/internal/OpenApiIntegerValidator2.mjs +33 -41
- package/lib/validators/internal/OpenApiIntegerValidator2.mjs.map +1 -1
- package/lib/validators/internal/OpenApiNumberValidator.mjs +2 -7
- package/lib/validators/internal/OpenApiNumberValidator.mjs.map +1 -1
- package/lib/validators/internal/OpenApiNumberValidator2.mjs +33 -41
- package/lib/validators/internal/OpenApiNumberValidator2.mjs.map +1 -1
- package/lib/validators/internal/OpenApiObjectValidator.js +2 -3
- package/lib/validators/internal/OpenApiObjectValidator.js.map +1 -1
- package/lib/validators/internal/OpenApiObjectValidator.mjs +2 -7
- package/lib/validators/internal/OpenApiObjectValidator.mjs.map +1 -1
- package/lib/validators/internal/OpenApiObjectValidator2.mjs +55 -62
- package/lib/validators/internal/OpenApiObjectValidator2.mjs.map +1 -1
- package/lib/validators/internal/OpenApiOneOfValidator.mjs +2 -7
- package/lib/validators/internal/OpenApiOneOfValidator.mjs.map +1 -1
- package/lib/validators/internal/OpenApiOneOfValidator2.mjs +188 -193
- package/lib/validators/internal/OpenApiOneOfValidator2.mjs.map +1 -1
- package/lib/validators/internal/OpenApiSchemaNamingRule.mjs +2 -7
- package/lib/validators/internal/OpenApiSchemaNamingRule.mjs.map +1 -1
- package/lib/validators/internal/OpenApiSchemaNamingRule2.mjs +124 -131
- package/lib/validators/internal/OpenApiSchemaNamingRule2.mjs.map +1 -1
- package/lib/validators/internal/OpenApiStationValidator.mjs +2 -7
- package/lib/validators/internal/OpenApiStationValidator.mjs.map +1 -1
- package/lib/validators/internal/OpenApiStationValidator2.mjs +86 -83
- package/lib/validators/internal/OpenApiStationValidator2.mjs.map +1 -1
- package/lib/validators/internal/OpenApiStringValidator.mjs +2 -7
- package/lib/validators/internal/OpenApiStringValidator.mjs.map +1 -1
- package/lib/validators/internal/OpenApiStringValidator2.mjs +115 -102
- package/lib/validators/internal/OpenApiStringValidator2.mjs.map +1 -1
- package/lib/validators/internal/OpenApiTupleValidator.mjs +2 -7
- package/lib/validators/internal/OpenApiTupleValidator.mjs.map +1 -1
- package/lib/validators/internal/OpenApiTupleValidator2.mjs +33 -40
- package/lib/validators/internal/OpenApiTupleValidator2.mjs.map +1 -1
- package/package.json +4 -4
- package/src/converters/LlmSchemaConverter.ts +1 -8
- package/src/utils/Singleton.ts +1 -0
- package/src/utils/internal/OpenApiTypeCheckerBase.ts +12 -3
- package/src/utils/internal/coerceLlmArguments.ts +27 -1
- package/src/validators/internal/OpenApiObjectValidator.ts +1 -2
|
@@ -1,454 +1,443 @@
|
|
|
1
|
-
import { __exports as LlmSchemaConverter } from '../_virtual/LlmSchemaConverter.mjs';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
1
|
+
import { __exports as LlmSchemaConverter$1 } from '../_virtual/LlmSchemaConverter.mjs';
|
|
2
|
+
import '../utils/internal/JsonDescriptor2.mjs';
|
|
3
|
+
import '../validators/LlmTypeChecker2.mjs';
|
|
4
|
+
import '../validators/OpenApiTypeChecker2.mjs';
|
|
5
|
+
import './internal/LlmDescriptionInverter2.mjs';
|
|
6
|
+
import './internal/LlmParametersComposer2.mjs';
|
|
7
|
+
import './internal/OpenApiConstraintShifter2.mjs';
|
|
8
|
+
import { __exports as LlmParametersComposer } from '../_virtual/LlmParametersComposer.mjs';
|
|
9
|
+
import { __exports as OpenApiTypeChecker } from '../_virtual/OpenApiTypeChecker.mjs';
|
|
10
|
+
import { __exports as JsonDescriptor } from '../_virtual/JsonDescriptor.mjs';
|
|
11
|
+
import { __exports as LlmTypeChecker } from '../_virtual/LlmTypeChecker.mjs';
|
|
12
|
+
import { __exports as OpenApiConstraintShifter } from '../_virtual/OpenApiConstraintShifter.mjs';
|
|
13
|
+
import { __exports as LlmDescriptionInverter } from '../_virtual/LlmDescriptionInverter.mjs';
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
Object.defineProperty(LlmSchemaConverter$1, "__esModule", { value: true });
|
|
16
|
+
var LlmSchemaConverter_2 = LlmSchemaConverter$1.LlmSchemaConverter = void 0;
|
|
17
|
+
const JsonDescriptor_1 = JsonDescriptor;
|
|
18
|
+
const LlmTypeChecker_1 = LlmTypeChecker;
|
|
19
|
+
const OpenApiTypeChecker_1 = OpenApiTypeChecker;
|
|
20
|
+
const LlmDescriptionInverter_1 = LlmDescriptionInverter;
|
|
21
|
+
const LlmParametersComposer_1 = LlmParametersComposer;
|
|
22
|
+
const OpenApiConstraintShifter_1 = OpenApiConstraintShifter;
|
|
23
|
+
/**
|
|
24
|
+
* OpenAPI to LLM schema converter.
|
|
25
|
+
*
|
|
26
|
+
* `LlmSchemaConverter` converts OpenAPI JSON schemas to LLM-compatible
|
|
27
|
+
* {@link ILlmSchema} format. LLMs don't fully support JSON Schema, so this
|
|
28
|
+
* simplifies schemas by removing unsupported features (tuples, `const`, mixed
|
|
29
|
+
* unions).
|
|
30
|
+
*
|
|
31
|
+
* Main functions:
|
|
32
|
+
*
|
|
33
|
+
* - {@link parameters}: Convert object schema to {@link ILlmSchema.IParameters}
|
|
34
|
+
* - {@link schema}: Convert any schema to {@link ILlmSchema}
|
|
35
|
+
* - {@link invert}: Extract constraints from description back to schema
|
|
36
|
+
*
|
|
37
|
+
* Configuration options ({@link ILlmSchema.IConfig}):
|
|
38
|
+
*
|
|
39
|
+
* - `strict`: OpenAI structured output mode (all properties required)
|
|
40
|
+
*
|
|
41
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
42
|
+
*/
|
|
43
|
+
var LlmSchemaConverter;
|
|
44
|
+
(function (LlmSchemaConverter) {
|
|
45
|
+
/**
|
|
46
|
+
* Get configuration with defaults applied.
|
|
47
|
+
*
|
|
48
|
+
* @param config Partial configuration
|
|
49
|
+
* @returns Full configuration with defaults
|
|
50
|
+
*/
|
|
51
|
+
LlmSchemaConverter.getConfig = (config) => { var _a; return ({
|
|
52
|
+
strict: (_a = config === null || config === void 0 ? void 0 : config.strict) !== null && _a !== void 0 ? _a : false,
|
|
53
|
+
}); };
|
|
54
|
+
/* -----------------------------------------------------------
|
|
55
|
+
CONVERTERS
|
|
56
|
+
----------------------------------------------------------- */
|
|
57
|
+
/**
|
|
58
|
+
* Convert OpenAPI object schema to LLM parameters schema.
|
|
59
|
+
*
|
|
60
|
+
* @param props.config Conversion configuration
|
|
61
|
+
* @param props.components OpenAPI components for reference resolution
|
|
62
|
+
* @param props.schema Object or reference schema to convert
|
|
63
|
+
* @param props.accessor Error path accessor
|
|
64
|
+
* @param props.refAccessor Reference path accessor
|
|
65
|
+
* @returns Converted parameters or error
|
|
66
|
+
*/
|
|
67
|
+
LlmSchemaConverter.parameters = (props) => {
|
|
68
|
+
const config = LlmSchemaConverter.getConfig(props.config);
|
|
69
|
+
const entity = LlmParametersComposer_1.LlmParametersFinder.parameters(Object.assign(Object.assign({}, props), { method: "LlmSchemaConverter.parameters" }));
|
|
70
|
+
if (entity.success === false)
|
|
71
|
+
return entity;
|
|
72
|
+
const $defs = {};
|
|
73
|
+
const result = transform(Object.assign(Object.assign({}, props), { config,
|
|
74
|
+
$defs, schema: entity.value }));
|
|
75
|
+
if (result.success === false)
|
|
76
|
+
return result;
|
|
77
|
+
return {
|
|
78
|
+
success: true,
|
|
79
|
+
value: Object.assign(Object.assign({}, result.value), { additionalProperties: false, $defs, description: OpenApiTypeChecker_1.OpenApiTypeChecker.isReference(props.schema)
|
|
80
|
+
? JsonDescriptor_1.JsonDescriptor.cascade({
|
|
81
|
+
prefix: "#/components/schemas/",
|
|
82
|
+
components: props.components,
|
|
83
|
+
schema: Object.assign(Object.assign({}, props.schema), { description: result.value.description }),
|
|
84
|
+
escape: true,
|
|
85
|
+
})
|
|
86
|
+
: result.value.description }),
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Convert OpenAPI schema to LLM schema.
|
|
91
|
+
*
|
|
92
|
+
* @param props.config Conversion configuration
|
|
93
|
+
* @param props.components OpenAPI components for reference resolution
|
|
94
|
+
* @param props.$defs Definition store (mutated with referenced types)
|
|
95
|
+
* @param props.schema Schema to convert
|
|
96
|
+
* @param props.accessor Error path accessor
|
|
97
|
+
* @param props.refAccessor Reference path accessor
|
|
98
|
+
* @returns Converted schema or error
|
|
99
|
+
*/
|
|
100
|
+
LlmSchemaConverter.schema = (props) => transform({
|
|
101
|
+
config: LlmSchemaConverter.getConfig(props.config),
|
|
102
|
+
components: props.components,
|
|
103
|
+
$defs: props.$defs,
|
|
104
|
+
schema: props.schema,
|
|
105
|
+
accessor: props.accessor,
|
|
106
|
+
refAccessor: props.refAccessor,
|
|
107
|
+
});
|
|
108
|
+
const transform = (props) => {
|
|
109
|
+
var _a, _b;
|
|
110
|
+
// PREPARE ASSETS
|
|
111
|
+
const union = [];
|
|
112
|
+
const attribute = Object.assign({ title: props.schema.title, description: props.schema.description, deprecated: props.schema.deprecated, readOnly: props.schema.readOnly, writeOnly: props.schema.writeOnly, example: props.schema.example, examples: props.schema.examples }, Object.fromEntries(Object.entries(props.schema).filter(([key, value]) => key.startsWith("x-") && value !== undefined)));
|
|
113
|
+
// VALIDADTE SCHEMA
|
|
114
|
+
const reasons = [];
|
|
115
|
+
OpenApiTypeChecker_1.OpenApiTypeChecker.visit({
|
|
116
|
+
closure: (next, accessor) => {
|
|
117
|
+
var _a;
|
|
118
|
+
var _b;
|
|
119
|
+
if (props.config.strict === true) {
|
|
120
|
+
// STRICT MODE VALIDATION
|
|
121
|
+
reasons.push(...validateStrict(next, accessor));
|
|
122
|
+
}
|
|
123
|
+
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isTuple(next))
|
|
124
|
+
reasons.push({
|
|
125
|
+
accessor,
|
|
126
|
+
schema: next,
|
|
127
|
+
message: `LLM does not allow tuple type.`,
|
|
128
|
+
});
|
|
129
|
+
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isReference(next)) {
|
|
130
|
+
// UNABLE TO FIND MATCHED REFERENCE
|
|
131
|
+
const key = (_b = next.$ref.split("#/components/schemas/")[1]) !== null && _b !== void 0 ? _b : next.$ref.split("/").at(-1);
|
|
132
|
+
if (((_a = props.components.schemas) === null || _a === void 0 ? void 0 : _a[key]) === undefined)
|
|
133
|
+
reasons.push({
|
|
134
|
+
schema: next,
|
|
135
|
+
accessor: accessor,
|
|
136
|
+
message: `unable to find reference type ${JSON.stringify(key)}.`,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
components: props.components,
|
|
141
|
+
schema: props.schema,
|
|
142
|
+
accessor: props.accessor,
|
|
143
|
+
refAccessor: props.refAccessor,
|
|
144
|
+
});
|
|
145
|
+
if (reasons.length > 0)
|
|
146
|
+
return {
|
|
147
|
+
success: false,
|
|
148
|
+
error: {
|
|
149
|
+
method: "LlmSchemaConverter.schema",
|
|
150
|
+
message: "Failed to compose LLM schema",
|
|
151
|
+
reasons,
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
const visitConstant = (input) => {
|
|
155
|
+
const insert = (value) => {
|
|
156
|
+
var _a;
|
|
157
|
+
const matched = union.find((u) => (u === null || u === void 0 ? void 0 : u.type) === typeof value);
|
|
158
|
+
if (matched !== undefined) {
|
|
159
|
+
(_a = matched.enum) !== null && _a !== void 0 ? _a : (matched.enum = []);
|
|
160
|
+
matched.enum.push(value);
|
|
161
|
+
}
|
|
162
|
+
else
|
|
163
|
+
union.push({
|
|
164
|
+
type: typeof value,
|
|
165
|
+
enum: [value],
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isConstant(input))
|
|
169
|
+
insert(input.const);
|
|
170
|
+
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isOneOf(input))
|
|
171
|
+
input.oneOf.forEach(visitConstant);
|
|
172
|
+
};
|
|
173
|
+
const visit = (input, accessor) => {
|
|
174
|
+
var _a;
|
|
175
|
+
var _b, _c, _d, _e;
|
|
176
|
+
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isOneOf(input)) {
|
|
177
|
+
// UNION TYPE
|
|
178
|
+
input.oneOf.forEach((s, i) => visit(s, `${accessor}.oneOf[${i}]`));
|
|
179
|
+
}
|
|
180
|
+
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isReference(input)) {
|
|
181
|
+
// REFERENCE TYPE
|
|
182
|
+
const key = (_b = input.$ref.split("#/components/schemas/")[1]) !== null && _b !== void 0 ? _b : input.$ref.split("/").at(-1);
|
|
183
|
+
const target = (_a = props.components.schemas) === null || _a === void 0 ? void 0 : _a[key];
|
|
184
|
+
if (target === undefined)
|
|
185
|
+
return;
|
|
186
|
+
else {
|
|
187
|
+
// KEEP THE REFERENCE TYPE
|
|
188
|
+
const out = () => {
|
|
189
|
+
union.push(Object.assign(Object.assign({}, input), { $ref: `#/$defs/${key}` }));
|
|
190
|
+
};
|
|
191
|
+
if (props.$defs[key] !== undefined)
|
|
192
|
+
return out();
|
|
193
|
+
props.$defs[key] = {};
|
|
194
|
+
const converted = transform({
|
|
195
|
+
config: props.config,
|
|
196
|
+
components: props.components,
|
|
197
|
+
$defs: props.$defs,
|
|
198
|
+
schema: target,
|
|
199
|
+
refAccessor: props.refAccessor,
|
|
200
|
+
accessor: `${(_c = props.refAccessor) !== null && _c !== void 0 ? _c : "$def"}[${JSON.stringify(key)}]`,
|
|
201
|
+
});
|
|
202
|
+
if (converted.success === false)
|
|
203
|
+
return; // UNREACHABLE
|
|
204
|
+
props.$defs[key] = converted.value;
|
|
205
|
+
return out();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isObject(input)) {
|
|
209
|
+
// OBJECT TYPE
|
|
210
|
+
const properties = Object.fromEntries(Object.entries((_d = input.properties) !== null && _d !== void 0 ? _d : {})
|
|
211
|
+
.map(([key, value]) => {
|
|
212
|
+
var _a;
|
|
213
|
+
const converted = transform({
|
|
214
|
+
config: props.config,
|
|
215
|
+
components: props.components,
|
|
216
|
+
$defs: props.$defs,
|
|
217
|
+
schema: value,
|
|
218
|
+
refAccessor: props.refAccessor,
|
|
219
|
+
accessor: `${(_a = props.accessor) !== null && _a !== void 0 ? _a : "$input.schema"}.properties[${JSON.stringify(key)}]`,
|
|
220
|
+
});
|
|
221
|
+
if (converted.success === false) {
|
|
222
|
+
reasons.push(...converted.error.reasons);
|
|
223
|
+
return [key, null];
|
|
224
|
+
}
|
|
225
|
+
return [key, converted.value];
|
|
226
|
+
})
|
|
227
|
+
.filter(([, value]) => value !== null));
|
|
228
|
+
if (Object.values(properties).some((v) => v === null))
|
|
229
|
+
return;
|
|
230
|
+
const additionalProperties = (() => {
|
|
231
|
+
if (typeof input.additionalProperties === "object" &&
|
|
232
|
+
input.additionalProperties !== null) {
|
|
233
|
+
const converted = transform({
|
|
234
|
+
config: props.config,
|
|
235
|
+
components: props.components,
|
|
236
|
+
$defs: props.$defs,
|
|
237
|
+
schema: input.additionalProperties,
|
|
238
|
+
refAccessor: props.refAccessor,
|
|
239
|
+
accessor: `${accessor}.additionalProperties`,
|
|
240
|
+
});
|
|
241
|
+
if (converted.success === false) {
|
|
242
|
+
reasons.push(...converted.error.reasons);
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
return converted.value;
|
|
246
|
+
}
|
|
247
|
+
return props.config.strict === true
|
|
248
|
+
? false
|
|
249
|
+
: input.additionalProperties;
|
|
250
|
+
})();
|
|
251
|
+
if (additionalProperties === null)
|
|
252
|
+
return;
|
|
253
|
+
union.push(Object.assign(Object.assign({}, input), { properties,
|
|
254
|
+
additionalProperties, required: (_e = input.required) !== null && _e !== void 0 ? _e : [], description: props.config.strict === true
|
|
255
|
+
? JsonDescriptor_1.JsonDescriptor.take(input)
|
|
256
|
+
: input.description }));
|
|
257
|
+
}
|
|
258
|
+
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isArray(input)) {
|
|
259
|
+
// ARRAY TYPE
|
|
260
|
+
const items = transform({
|
|
261
|
+
config: props.config,
|
|
262
|
+
components: props.components,
|
|
263
|
+
$defs: props.$defs,
|
|
264
|
+
schema: input.items,
|
|
265
|
+
refAccessor: props.refAccessor,
|
|
266
|
+
accessor: `${accessor}.items`,
|
|
267
|
+
});
|
|
268
|
+
if (items.success === false) {
|
|
269
|
+
reasons.push(...items.error.reasons);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
union.push(props.config.strict === true
|
|
273
|
+
? OpenApiConstraintShifter_1.OpenApiConstraintShifter.shiftArray(Object.assign(Object.assign({}, input), { items: items.value }))
|
|
274
|
+
: Object.assign(Object.assign({}, input), { items: items.value }));
|
|
275
|
+
}
|
|
276
|
+
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isString(input))
|
|
277
|
+
union.push(props.config.strict === true
|
|
278
|
+
? OpenApiConstraintShifter_1.OpenApiConstraintShifter.shiftString(Object.assign({}, input))
|
|
279
|
+
: input);
|
|
280
|
+
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isNumber(input) ||
|
|
281
|
+
OpenApiTypeChecker_1.OpenApiTypeChecker.isInteger(input))
|
|
282
|
+
union.push(props.config.strict === true
|
|
283
|
+
? OpenApiConstraintShifter_1.OpenApiConstraintShifter.shiftNumeric(Object.assign({}, input))
|
|
284
|
+
: input);
|
|
285
|
+
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isTuple(input))
|
|
286
|
+
return; // UNREACHABLE
|
|
287
|
+
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isConstant(input) === false)
|
|
288
|
+
union.push(Object.assign({}, input));
|
|
289
|
+
};
|
|
290
|
+
visitConstant(props.schema);
|
|
291
|
+
visit(props.schema, (_a = props.accessor) !== null && _a !== void 0 ? _a : "$input.schema");
|
|
292
|
+
if (reasons.length > 0)
|
|
293
|
+
return {
|
|
294
|
+
success: false,
|
|
295
|
+
error: {
|
|
296
|
+
method: "LlmSchemaConverter.schema",
|
|
297
|
+
message: "Failed to compose LLM schema",
|
|
298
|
+
reasons,
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
else if (union.length === 0)
|
|
302
|
+
return {
|
|
303
|
+
// unknown type
|
|
304
|
+
success: true,
|
|
305
|
+
value: Object.assign(Object.assign({}, attribute), { type: undefined }),
|
|
306
|
+
};
|
|
307
|
+
else if (union.length === 1)
|
|
308
|
+
return {
|
|
309
|
+
// single type
|
|
310
|
+
success: true,
|
|
311
|
+
value: Object.assign(Object.assign(Object.assign({}, attribute), union[0]), { description: props.config.strict === true &&
|
|
312
|
+
LlmTypeChecker_1.LlmTypeChecker.isReference(union[0])
|
|
313
|
+
? undefined
|
|
314
|
+
: ((_b = union[0].description) !== null && _b !== void 0 ? _b : attribute.description) }),
|
|
315
|
+
};
|
|
316
|
+
return {
|
|
317
|
+
success: true,
|
|
318
|
+
value: Object.assign(Object.assign({}, attribute), { anyOf: union.map((u) => (Object.assign(Object.assign({}, u), { description: props.config.strict === true && LlmTypeChecker_1.LlmTypeChecker.isReference(u)
|
|
319
|
+
? undefined
|
|
320
|
+
: u.description }))), "x-discriminator": OpenApiTypeChecker_1.OpenApiTypeChecker.isOneOf(props.schema) &&
|
|
321
|
+
props.schema.discriminator !== undefined &&
|
|
322
|
+
props.schema.oneOf.length === union.length &&
|
|
323
|
+
union.every((e) => LlmTypeChecker_1.LlmTypeChecker.isReference(e) || LlmTypeChecker_1.LlmTypeChecker.isNull(e))
|
|
324
|
+
? {
|
|
325
|
+
propertyName: props.schema.discriminator.propertyName,
|
|
326
|
+
mapping: props.schema.discriminator.mapping !== undefined
|
|
327
|
+
? Object.fromEntries(Object.entries(props.schema.discriminator.mapping).map(([key, value]) => [
|
|
328
|
+
key,
|
|
329
|
+
`#/$defs/${value.split("/").at(-1)}`,
|
|
330
|
+
]))
|
|
331
|
+
: undefined,
|
|
332
|
+
}
|
|
333
|
+
: undefined }),
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
/* -----------------------------------------------------------
|
|
337
|
+
INVERTERS
|
|
338
|
+
----------------------------------------------------------- */
|
|
339
|
+
/**
|
|
340
|
+
* Convert LLM schema back to OpenAPI schema.
|
|
341
|
+
*
|
|
342
|
+
* Restores constraint information from description tags and converts `$defs`
|
|
343
|
+
* references to `#/components/schemas`.
|
|
344
|
+
*
|
|
345
|
+
* @param props.components Target components (mutated with definitions)
|
|
346
|
+
* @param props.schema LLM schema to invert
|
|
347
|
+
* @param props.$defs LLM schema definitions
|
|
348
|
+
* @returns OpenAPI JSON schema
|
|
349
|
+
*/
|
|
350
|
+
LlmSchemaConverter.invert = (props) => {
|
|
351
|
+
const union = [];
|
|
352
|
+
const attribute = Object.assign({ title: props.schema.title, description: props.schema.description, deprecated: props.schema.deprecated, readOnly: props.schema.readOnly, writeOnly: props.schema.writeOnly, example: props.schema.example, examples: props.schema.examples }, Object.fromEntries(Object.entries(props.schema).filter(([key, value]) => key.startsWith("x-") && value !== undefined)));
|
|
353
|
+
const next = (schema) => LlmSchemaConverter.invert({
|
|
354
|
+
components: props.components,
|
|
355
|
+
$defs: props.$defs,
|
|
356
|
+
schema,
|
|
357
|
+
});
|
|
358
|
+
const visit = (schema) => {
|
|
359
|
+
var _a, _b, _c, _d;
|
|
360
|
+
var _e, _f, _g, _h;
|
|
361
|
+
var _j;
|
|
362
|
+
if (LlmTypeChecker_1.LlmTypeChecker.isArray(schema))
|
|
363
|
+
union.push(Object.assign(Object.assign(Object.assign({}, schema), LlmDescriptionInverter_1.LlmDescriptionInverter.array(schema.description)), { items: next(schema.items) }));
|
|
364
|
+
else if (LlmTypeChecker_1.LlmTypeChecker.isObject(schema))
|
|
365
|
+
union.push(Object.assign(Object.assign({}, schema), { properties: Object.fromEntries(Object.entries((_e = schema.properties) !== null && _e !== void 0 ? _e : {}).map(([key, value]) => [
|
|
366
|
+
key,
|
|
367
|
+
next(value),
|
|
368
|
+
])), additionalProperties: typeof schema.additionalProperties === "object" &&
|
|
369
|
+
schema.additionalProperties !== null
|
|
370
|
+
? next(schema.additionalProperties)
|
|
371
|
+
: schema.additionalProperties }));
|
|
372
|
+
else if (LlmTypeChecker_1.LlmTypeChecker.isAnyOf(schema))
|
|
373
|
+
schema.anyOf.forEach(visit);
|
|
374
|
+
else if (LlmTypeChecker_1.LlmTypeChecker.isReference(schema)) {
|
|
375
|
+
const key = (_f = schema.$ref.split("#/$defs/")[1]) !== null && _f !== void 0 ? _f : schema.$ref.split("/").at(-1);
|
|
376
|
+
if (((_a = props.components.schemas) === null || _a === void 0 ? void 0 : _a[key]) === undefined) {
|
|
377
|
+
(_g = (_j = props.components).schemas) !== null && _g !== void 0 ? _g : (_j.schemas = {});
|
|
378
|
+
props.components.schemas[key] = {};
|
|
379
|
+
props.components.schemas[key] = next((_h = props.$defs[key]) !== null && _h !== void 0 ? _h : {});
|
|
380
|
+
}
|
|
381
|
+
union.push(Object.assign(Object.assign({}, schema), { $ref: `#/components/schemas/${key}` }));
|
|
382
|
+
}
|
|
383
|
+
else if (LlmTypeChecker_1.LlmTypeChecker.isBoolean(schema))
|
|
384
|
+
if (!!((_b = schema.enum) === null || _b === void 0 ? void 0 : _b.length))
|
|
385
|
+
schema.enum.forEach((v) => union.push({
|
|
386
|
+
const: v,
|
|
387
|
+
}));
|
|
388
|
+
else
|
|
389
|
+
union.push(schema);
|
|
390
|
+
else if (LlmTypeChecker_1.LlmTypeChecker.isInteger(schema) ||
|
|
391
|
+
LlmTypeChecker_1.LlmTypeChecker.isNumber(schema))
|
|
392
|
+
if (!!((_c = schema.enum) === null || _c === void 0 ? void 0 : _c.length))
|
|
393
|
+
schema.enum.forEach((v) => union.push({
|
|
394
|
+
const: v,
|
|
395
|
+
}));
|
|
396
|
+
else
|
|
397
|
+
union.push(Object.assign(Object.assign(Object.assign({}, schema), LlmDescriptionInverter_1.LlmDescriptionInverter.numeric(schema.description)), { enum: undefined }));
|
|
398
|
+
else if (LlmTypeChecker_1.LlmTypeChecker.isString(schema))
|
|
399
|
+
if (!!((_d = schema.enum) === null || _d === void 0 ? void 0 : _d.length))
|
|
400
|
+
schema.enum.forEach((v) => union.push({
|
|
401
|
+
const: v,
|
|
402
|
+
}));
|
|
403
|
+
else
|
|
404
|
+
union.push(Object.assign(Object.assign(Object.assign({}, schema), LlmDescriptionInverter_1.LlmDescriptionInverter.string(schema.description)), { enum: undefined }));
|
|
405
|
+
else
|
|
406
|
+
union.push(Object.assign({}, schema));
|
|
407
|
+
};
|
|
408
|
+
visit(props.schema);
|
|
409
|
+
return Object.assign(Object.assign({}, attribute), (union.length === 0
|
|
410
|
+
? { type: undefined }
|
|
411
|
+
: union.length === 1
|
|
412
|
+
? Object.assign({}, union[0]) : {
|
|
413
|
+
oneOf: union.map((u) => (Object.assign(Object.assign({}, u), { nullable: undefined }))),
|
|
414
|
+
discriminator: LlmTypeChecker_1.LlmTypeChecker.isAnyOf(props.schema) &&
|
|
415
|
+
props.schema["x-discriminator"] !== undefined
|
|
416
|
+
? {
|
|
417
|
+
propertyName: props.schema["x-discriminator"].propertyName,
|
|
418
|
+
mapping: props.schema["x-discriminator"].mapping !== undefined
|
|
419
|
+
? Object.fromEntries(Object.entries(props.schema["x-discriminator"].mapping).map(([key, value]) => [
|
|
420
|
+
key,
|
|
421
|
+
`#/components/schemas/${value.split("/").at(-1)}`,
|
|
422
|
+
]))
|
|
423
|
+
: undefined,
|
|
424
|
+
}
|
|
425
|
+
: undefined,
|
|
426
|
+
}));
|
|
427
|
+
};
|
|
428
|
+
})(LlmSchemaConverter || (LlmSchemaConverter_2 = LlmSchemaConverter$1.LlmSchemaConverter = LlmSchemaConverter = {}));
|
|
429
|
+
const validateStrict = (schema, accessor) => {
|
|
430
|
+
const reasons = [];
|
|
431
|
+
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isObject(schema)) {
|
|
432
|
+
if (!!schema.additionalProperties)
|
|
433
|
+
reasons.push({
|
|
434
|
+
schema: schema,
|
|
435
|
+
accessor: `${accessor}.additionalProperties`,
|
|
436
|
+
message: "LLM does not allow additionalProperties in strict mode, the dynamic key typed object.",
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
return reasons;
|
|
440
|
+
};
|
|
10
441
|
|
|
11
|
-
|
|
12
|
-
if (hasRequiredLlmSchemaConverter) return LlmSchemaConverter;
|
|
13
|
-
hasRequiredLlmSchemaConverter = 1;
|
|
14
|
-
Object.defineProperty(LlmSchemaConverter, "__esModule", { value: true });
|
|
15
|
-
LlmSchemaConverter.LlmSchemaConverter = void 0;
|
|
16
|
-
const JsonDescriptor_1 = requireJsonDescriptor();
|
|
17
|
-
const LlmTypeChecker_1 = requireLlmTypeChecker();
|
|
18
|
-
const OpenApiTypeChecker_1 = requireOpenApiTypeChecker();
|
|
19
|
-
const LlmDescriptionInverter_1 = requireLlmDescriptionInverter();
|
|
20
|
-
const LlmParametersComposer_1 = requireLlmParametersComposer();
|
|
21
|
-
const OpenApiConstraintShifter_1 = requireOpenApiConstraintShifter();
|
|
22
|
-
/**
|
|
23
|
-
* OpenAPI to LLM schema converter.
|
|
24
|
-
*
|
|
25
|
-
* `LlmSchemaConverter` converts OpenAPI JSON schemas to LLM-compatible
|
|
26
|
-
* {@link ILlmSchema} format. LLMs don't fully support JSON Schema, so this
|
|
27
|
-
* simplifies schemas by removing unsupported features (tuples, `const`, mixed
|
|
28
|
-
* unions).
|
|
29
|
-
*
|
|
30
|
-
* Main functions:
|
|
31
|
-
*
|
|
32
|
-
* - {@link parameters}: Convert object schema to {@link ILlmSchema.IParameters}
|
|
33
|
-
* - {@link schema}: Convert any schema to {@link ILlmSchema}
|
|
34
|
-
* - {@link invert}: Extract constraints from description back to schema
|
|
35
|
-
*
|
|
36
|
-
* Configuration options ({@link ILlmSchema.IConfig}):
|
|
37
|
-
*
|
|
38
|
-
* - `strict`: OpenAI structured output mode (all properties required)
|
|
39
|
-
*
|
|
40
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
41
|
-
*/
|
|
42
|
-
var LlmSchemaConverter$1;
|
|
43
|
-
(function (LlmSchemaConverter) {
|
|
44
|
-
/**
|
|
45
|
-
* Get configuration with defaults applied.
|
|
46
|
-
*
|
|
47
|
-
* @param config Partial configuration
|
|
48
|
-
* @returns Full configuration with defaults
|
|
49
|
-
*/
|
|
50
|
-
LlmSchemaConverter.getConfig = (config) => { var _a; return ({
|
|
51
|
-
strict: (_a = config === null || config === void 0 ? void 0 : config.strict) !== null && _a !== void 0 ? _a : false,
|
|
52
|
-
}); };
|
|
53
|
-
/* -----------------------------------------------------------
|
|
54
|
-
CONVERTERS
|
|
55
|
-
----------------------------------------------------------- */
|
|
56
|
-
/**
|
|
57
|
-
* Convert OpenAPI object schema to LLM parameters schema.
|
|
58
|
-
*
|
|
59
|
-
* @param props.config Conversion configuration
|
|
60
|
-
* @param props.components OpenAPI components for reference resolution
|
|
61
|
-
* @param props.schema Object or reference schema to convert
|
|
62
|
-
* @param props.accessor Error path accessor
|
|
63
|
-
* @param props.refAccessor Reference path accessor
|
|
64
|
-
* @returns Converted parameters or error
|
|
65
|
-
*/
|
|
66
|
-
LlmSchemaConverter.parameters = (props) => {
|
|
67
|
-
const config = LlmSchemaConverter.getConfig(props.config);
|
|
68
|
-
const entity = LlmParametersComposer_1.LlmParametersFinder.parameters(Object.assign(Object.assign({}, props), { method: "LlmSchemaConverter.parameters" }));
|
|
69
|
-
if (entity.success === false)
|
|
70
|
-
return entity;
|
|
71
|
-
const $defs = {};
|
|
72
|
-
const result = transform(Object.assign(Object.assign({}, props), { config,
|
|
73
|
-
$defs, schema: entity.value }));
|
|
74
|
-
if (result.success === false)
|
|
75
|
-
return result;
|
|
76
|
-
return {
|
|
77
|
-
success: true,
|
|
78
|
-
value: Object.assign(Object.assign({}, result.value), { additionalProperties: false, $defs, description: OpenApiTypeChecker_1.OpenApiTypeChecker.isReference(props.schema)
|
|
79
|
-
? JsonDescriptor_1.JsonDescriptor.cascade({
|
|
80
|
-
prefix: "#/components/schemas/",
|
|
81
|
-
components: props.components,
|
|
82
|
-
schema: Object.assign(Object.assign({}, props.schema), { description: result.value.description }),
|
|
83
|
-
escape: true,
|
|
84
|
-
})
|
|
85
|
-
: result.value.description }),
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* Convert OpenAPI schema to LLM schema.
|
|
90
|
-
*
|
|
91
|
-
* @param props.config Conversion configuration
|
|
92
|
-
* @param props.components OpenAPI components for reference resolution
|
|
93
|
-
* @param props.$defs Definition store (mutated with referenced types)
|
|
94
|
-
* @param props.schema Schema to convert
|
|
95
|
-
* @param props.accessor Error path accessor
|
|
96
|
-
* @param props.refAccessor Reference path accessor
|
|
97
|
-
* @returns Converted schema or error
|
|
98
|
-
*/
|
|
99
|
-
LlmSchemaConverter.schema = (props) => transform({
|
|
100
|
-
config: LlmSchemaConverter.getConfig(props.config),
|
|
101
|
-
components: props.components,
|
|
102
|
-
$defs: props.$defs,
|
|
103
|
-
schema: props.schema,
|
|
104
|
-
accessor: props.accessor,
|
|
105
|
-
refAccessor: props.refAccessor,
|
|
106
|
-
});
|
|
107
|
-
const transform = (props) => {
|
|
108
|
-
var _a, _b;
|
|
109
|
-
// PREPARE ASSETS
|
|
110
|
-
const union = [];
|
|
111
|
-
const attribute = Object.assign({ title: props.schema.title, description: props.schema.description, deprecated: props.schema.deprecated, readOnly: props.schema.readOnly, writeOnly: props.schema.writeOnly, example: props.schema.example, examples: props.schema.examples }, Object.fromEntries(Object.entries(props.schema).filter(([key, value]) => key.startsWith("x-") && value !== undefined)));
|
|
112
|
-
// VALIDADTE SCHEMA
|
|
113
|
-
const reasons = [];
|
|
114
|
-
OpenApiTypeChecker_1.OpenApiTypeChecker.visit({
|
|
115
|
-
closure: (next, accessor) => {
|
|
116
|
-
var _a;
|
|
117
|
-
var _b;
|
|
118
|
-
if (props.config.strict === true) {
|
|
119
|
-
// STRICT MODE VALIDATION
|
|
120
|
-
reasons.push(...validateStrict(next, accessor));
|
|
121
|
-
}
|
|
122
|
-
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isTuple(next))
|
|
123
|
-
reasons.push({
|
|
124
|
-
accessor,
|
|
125
|
-
schema: next,
|
|
126
|
-
message: `LLM does not allow tuple type.`,
|
|
127
|
-
});
|
|
128
|
-
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isReference(next)) {
|
|
129
|
-
// UNABLE TO FIND MATCHED REFERENCE
|
|
130
|
-
const key = (_b = next.$ref.split("#/components/schemas/")[1]) !== null && _b !== void 0 ? _b : next.$ref.split("/").at(-1);
|
|
131
|
-
if (((_a = props.components.schemas) === null || _a === void 0 ? void 0 : _a[key]) === undefined)
|
|
132
|
-
reasons.push({
|
|
133
|
-
schema: next,
|
|
134
|
-
accessor: accessor,
|
|
135
|
-
message: `unable to find reference type ${JSON.stringify(key)}.`,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
components: props.components,
|
|
140
|
-
schema: props.schema,
|
|
141
|
-
accessor: props.accessor,
|
|
142
|
-
refAccessor: props.refAccessor,
|
|
143
|
-
});
|
|
144
|
-
if (reasons.length > 0)
|
|
145
|
-
return {
|
|
146
|
-
success: false,
|
|
147
|
-
error: {
|
|
148
|
-
method: "LlmSchemaConverter.schema",
|
|
149
|
-
message: "Failed to compose LLM schema",
|
|
150
|
-
reasons,
|
|
151
|
-
},
|
|
152
|
-
};
|
|
153
|
-
const visitConstant = (input) => {
|
|
154
|
-
const insert = (value) => {
|
|
155
|
-
var _a;
|
|
156
|
-
const matched = union.find((u) => (u === null || u === void 0 ? void 0 : u.type) === typeof value);
|
|
157
|
-
if (matched !== undefined) {
|
|
158
|
-
(_a = matched.enum) !== null && _a !== void 0 ? _a : (matched.enum = []);
|
|
159
|
-
matched.enum.push(value);
|
|
160
|
-
}
|
|
161
|
-
else
|
|
162
|
-
union.push({
|
|
163
|
-
type: typeof value,
|
|
164
|
-
enum: [value],
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isConstant(input))
|
|
168
|
-
insert(input.const);
|
|
169
|
-
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isOneOf(input))
|
|
170
|
-
input.oneOf.forEach(visitConstant);
|
|
171
|
-
};
|
|
172
|
-
const visit = (input, accessor) => {
|
|
173
|
-
var _a;
|
|
174
|
-
var _b, _c, _d, _e;
|
|
175
|
-
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isOneOf(input)) {
|
|
176
|
-
// UNION TYPE
|
|
177
|
-
input.oneOf.forEach((s, i) => visit(s, `${accessor}.oneOf[${i}]`));
|
|
178
|
-
}
|
|
179
|
-
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isReference(input)) {
|
|
180
|
-
// REFERENCE TYPE
|
|
181
|
-
const key = (_b = input.$ref.split("#/components/schemas/")[1]) !== null && _b !== void 0 ? _b : input.$ref.split("/").at(-1);
|
|
182
|
-
const target = (_a = props.components.schemas) === null || _a === void 0 ? void 0 : _a[key];
|
|
183
|
-
if (target === undefined)
|
|
184
|
-
return;
|
|
185
|
-
else {
|
|
186
|
-
// KEEP THE REFERENCE TYPE
|
|
187
|
-
const out = () => {
|
|
188
|
-
union.push(Object.assign(Object.assign({}, input), { $ref: `#/$defs/${key}` }));
|
|
189
|
-
};
|
|
190
|
-
if (props.$defs[key] !== undefined)
|
|
191
|
-
return out();
|
|
192
|
-
props.$defs[key] = {};
|
|
193
|
-
const converted = transform({
|
|
194
|
-
config: props.config,
|
|
195
|
-
components: props.components,
|
|
196
|
-
$defs: props.$defs,
|
|
197
|
-
schema: target,
|
|
198
|
-
refAccessor: props.refAccessor,
|
|
199
|
-
accessor: `${(_c = props.refAccessor) !== null && _c !== void 0 ? _c : "$def"}[${JSON.stringify(key)}]`,
|
|
200
|
-
});
|
|
201
|
-
if (converted.success === false)
|
|
202
|
-
return; // UNREACHABLE
|
|
203
|
-
props.$defs[key] = converted.value;
|
|
204
|
-
return out();
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isObject(input)) {
|
|
208
|
-
// OBJECT TYPE
|
|
209
|
-
const properties = Object.fromEntries(Object.entries((_d = input.properties) !== null && _d !== void 0 ? _d : {})
|
|
210
|
-
.map(([key, value]) => {
|
|
211
|
-
var _a;
|
|
212
|
-
const converted = transform({
|
|
213
|
-
config: props.config,
|
|
214
|
-
components: props.components,
|
|
215
|
-
$defs: props.$defs,
|
|
216
|
-
schema: value,
|
|
217
|
-
refAccessor: props.refAccessor,
|
|
218
|
-
accessor: `${(_a = props.accessor) !== null && _a !== void 0 ? _a : "$input.schema"}.properties[${JSON.stringify(key)}]`,
|
|
219
|
-
});
|
|
220
|
-
if (converted.success === false) {
|
|
221
|
-
reasons.push(...converted.error.reasons);
|
|
222
|
-
return [key, null];
|
|
223
|
-
}
|
|
224
|
-
return [key, converted.value];
|
|
225
|
-
})
|
|
226
|
-
.filter(([, value]) => value !== null));
|
|
227
|
-
if (Object.values(properties).some((v) => v === null))
|
|
228
|
-
return;
|
|
229
|
-
const additionalProperties = (() => {
|
|
230
|
-
if (typeof input.additionalProperties === "object" &&
|
|
231
|
-
input.additionalProperties !== null) {
|
|
232
|
-
const converted = transform({
|
|
233
|
-
config: props.config,
|
|
234
|
-
components: props.components,
|
|
235
|
-
$defs: props.$defs,
|
|
236
|
-
schema: input.additionalProperties,
|
|
237
|
-
refAccessor: props.refAccessor,
|
|
238
|
-
accessor: `${accessor}.additionalProperties`,
|
|
239
|
-
});
|
|
240
|
-
if (converted.success === false) {
|
|
241
|
-
reasons.push(...converted.error.reasons);
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
244
|
-
return converted.value;
|
|
245
|
-
}
|
|
246
|
-
return props.config.strict === true
|
|
247
|
-
? false
|
|
248
|
-
: input.additionalProperties;
|
|
249
|
-
})();
|
|
250
|
-
if (additionalProperties === null)
|
|
251
|
-
return;
|
|
252
|
-
union.push(Object.assign(Object.assign({}, input), { properties,
|
|
253
|
-
additionalProperties, required: (_e = input.required) !== null && _e !== void 0 ? _e : [], description: props.config.strict === true
|
|
254
|
-
? JsonDescriptor_1.JsonDescriptor.take(input)
|
|
255
|
-
: input.description }));
|
|
256
|
-
}
|
|
257
|
-
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isArray(input)) {
|
|
258
|
-
// ARRAY TYPE
|
|
259
|
-
const items = transform({
|
|
260
|
-
config: props.config,
|
|
261
|
-
components: props.components,
|
|
262
|
-
$defs: props.$defs,
|
|
263
|
-
schema: input.items,
|
|
264
|
-
refAccessor: props.refAccessor,
|
|
265
|
-
accessor: `${accessor}.items`,
|
|
266
|
-
});
|
|
267
|
-
if (items.success === false) {
|
|
268
|
-
reasons.push(...items.error.reasons);
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
union.push(props.config.strict === true
|
|
272
|
-
? OpenApiConstraintShifter_1.OpenApiConstraintShifter.shiftArray(Object.assign(Object.assign({}, input), { items: items.value }))
|
|
273
|
-
: Object.assign(Object.assign({}, input), { items: items.value }));
|
|
274
|
-
}
|
|
275
|
-
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isString(input))
|
|
276
|
-
union.push(props.config.strict === true
|
|
277
|
-
? OpenApiConstraintShifter_1.OpenApiConstraintShifter.shiftString(Object.assign({}, input))
|
|
278
|
-
: input);
|
|
279
|
-
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isNumber(input) ||
|
|
280
|
-
OpenApiTypeChecker_1.OpenApiTypeChecker.isInteger(input))
|
|
281
|
-
union.push(props.config.strict === true
|
|
282
|
-
? OpenApiConstraintShifter_1.OpenApiConstraintShifter.shiftNumeric(Object.assign({}, input))
|
|
283
|
-
: input);
|
|
284
|
-
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isTuple(input))
|
|
285
|
-
return; // UNREACHABLE
|
|
286
|
-
else if (OpenApiTypeChecker_1.OpenApiTypeChecker.isConstant(input) === false)
|
|
287
|
-
union.push(Object.assign({}, input));
|
|
288
|
-
};
|
|
289
|
-
visitConstant(props.schema);
|
|
290
|
-
visit(props.schema, (_a = props.accessor) !== null && _a !== void 0 ? _a : "$input.schema");
|
|
291
|
-
if (reasons.length > 0)
|
|
292
|
-
return {
|
|
293
|
-
success: false,
|
|
294
|
-
error: {
|
|
295
|
-
method: "LlmSchemaConverter.schema",
|
|
296
|
-
message: "Failed to compose LLM schema",
|
|
297
|
-
reasons,
|
|
298
|
-
},
|
|
299
|
-
};
|
|
300
|
-
else if (union.length === 0)
|
|
301
|
-
return {
|
|
302
|
-
// unknown type
|
|
303
|
-
success: true,
|
|
304
|
-
value: Object.assign(Object.assign({}, attribute), { type: undefined }),
|
|
305
|
-
};
|
|
306
|
-
else if (union.length === 1)
|
|
307
|
-
return {
|
|
308
|
-
// single type
|
|
309
|
-
success: true,
|
|
310
|
-
value: Object.assign(Object.assign(Object.assign({}, attribute), union[0]), { description: props.config.strict === true &&
|
|
311
|
-
LlmTypeChecker_1.LlmTypeChecker.isReference(union[0])
|
|
312
|
-
? undefined
|
|
313
|
-
: ((_b = union[0].description) !== null && _b !== void 0 ? _b : attribute.description) }),
|
|
314
|
-
};
|
|
315
|
-
return {
|
|
316
|
-
success: true,
|
|
317
|
-
value: Object.assign(Object.assign({}, attribute), { anyOf: union.map((u) => (Object.assign(Object.assign({}, u), { description: props.config.strict === true && LlmTypeChecker_1.LlmTypeChecker.isReference(u)
|
|
318
|
-
? undefined
|
|
319
|
-
: u.description }))), "x-discriminator": OpenApiTypeChecker_1.OpenApiTypeChecker.isOneOf(props.schema) &&
|
|
320
|
-
props.schema.discriminator !== undefined &&
|
|
321
|
-
props.schema.oneOf.length === union.length &&
|
|
322
|
-
union.every((e) => LlmTypeChecker_1.LlmTypeChecker.isReference(e) || LlmTypeChecker_1.LlmTypeChecker.isNull(e))
|
|
323
|
-
? {
|
|
324
|
-
propertyName: props.schema.discriminator.propertyName,
|
|
325
|
-
mapping: props.schema.discriminator.mapping !== undefined
|
|
326
|
-
? Object.fromEntries(Object.entries(props.schema.discriminator.mapping).map(([key, value]) => [
|
|
327
|
-
key,
|
|
328
|
-
`#/$defs/${value.split("/").at(-1)}`,
|
|
329
|
-
]))
|
|
330
|
-
: undefined,
|
|
331
|
-
}
|
|
332
|
-
: undefined }),
|
|
333
|
-
};
|
|
334
|
-
};
|
|
335
|
-
/* -----------------------------------------------------------
|
|
336
|
-
INVERTERS
|
|
337
|
-
----------------------------------------------------------- */
|
|
338
|
-
/**
|
|
339
|
-
* Convert LLM schema back to OpenAPI schema.
|
|
340
|
-
*
|
|
341
|
-
* Restores constraint information from description tags and converts `$defs`
|
|
342
|
-
* references to `#/components/schemas`.
|
|
343
|
-
*
|
|
344
|
-
* @param props.components Target components (mutated with definitions)
|
|
345
|
-
* @param props.schema LLM schema to invert
|
|
346
|
-
* @param props.$defs LLM schema definitions
|
|
347
|
-
* @returns OpenAPI JSON schema
|
|
348
|
-
*/
|
|
349
|
-
LlmSchemaConverter.invert = (props) => {
|
|
350
|
-
const union = [];
|
|
351
|
-
const attribute = Object.assign({ title: props.schema.title, description: props.schema.description, deprecated: props.schema.deprecated, readOnly: props.schema.readOnly, writeOnly: props.schema.writeOnly, example: props.schema.example, examples: props.schema.examples }, Object.fromEntries(Object.entries(props.schema).filter(([key, value]) => key.startsWith("x-") && value !== undefined)));
|
|
352
|
-
const next = (schema) => LlmSchemaConverter.invert({
|
|
353
|
-
components: props.components,
|
|
354
|
-
$defs: props.$defs,
|
|
355
|
-
schema,
|
|
356
|
-
});
|
|
357
|
-
const visit = (schema) => {
|
|
358
|
-
var _a, _b, _c, _d;
|
|
359
|
-
var _e, _f, _g;
|
|
360
|
-
var _h;
|
|
361
|
-
if (LlmTypeChecker_1.LlmTypeChecker.isArray(schema))
|
|
362
|
-
union.push(Object.assign(Object.assign(Object.assign({}, schema), LlmDescriptionInverter_1.LlmDescriptionInverter.array(schema.description)), { items: next(schema.items) }));
|
|
363
|
-
else if (LlmTypeChecker_1.LlmTypeChecker.isObject(schema))
|
|
364
|
-
union.push(Object.assign(Object.assign({}, schema), { properties: Object.fromEntries(Object.entries(schema.properties).map(([key, value]) => [
|
|
365
|
-
key,
|
|
366
|
-
next(value),
|
|
367
|
-
])), additionalProperties: typeof schema.additionalProperties === "object" &&
|
|
368
|
-
schema.additionalProperties !== null
|
|
369
|
-
? next(schema.additionalProperties)
|
|
370
|
-
: schema.additionalProperties }));
|
|
371
|
-
else if (LlmTypeChecker_1.LlmTypeChecker.isAnyOf(schema))
|
|
372
|
-
schema.anyOf.forEach(visit);
|
|
373
|
-
else if (LlmTypeChecker_1.LlmTypeChecker.isReference(schema)) {
|
|
374
|
-
const key = (_e = schema.$ref.split("#/$defs/")[1]) !== null && _e !== void 0 ? _e : schema.$ref.split("/").at(-1);
|
|
375
|
-
if (((_a = props.components.schemas) === null || _a === void 0 ? void 0 : _a[key]) === undefined) {
|
|
376
|
-
(_f = (_h = props.components).schemas) !== null && _f !== void 0 ? _f : (_h.schemas = {});
|
|
377
|
-
props.components.schemas[key] = {};
|
|
378
|
-
props.components.schemas[key] = next((_g = props.$defs[key]) !== null && _g !== void 0 ? _g : {});
|
|
379
|
-
}
|
|
380
|
-
union.push(Object.assign(Object.assign({}, schema), { $ref: `#/components/schemas/${key}` }));
|
|
381
|
-
}
|
|
382
|
-
else if (LlmTypeChecker_1.LlmTypeChecker.isBoolean(schema))
|
|
383
|
-
if (!!((_b = schema.enum) === null || _b === void 0 ? void 0 : _b.length))
|
|
384
|
-
schema.enum.forEach((v) => union.push({
|
|
385
|
-
const: v,
|
|
386
|
-
}));
|
|
387
|
-
else
|
|
388
|
-
union.push(schema);
|
|
389
|
-
else if (LlmTypeChecker_1.LlmTypeChecker.isInteger(schema) ||
|
|
390
|
-
LlmTypeChecker_1.LlmTypeChecker.isNumber(schema))
|
|
391
|
-
if (!!((_c = schema.enum) === null || _c === void 0 ? void 0 : _c.length))
|
|
392
|
-
schema.enum.forEach((v) => union.push({
|
|
393
|
-
const: v,
|
|
394
|
-
}));
|
|
395
|
-
else
|
|
396
|
-
union.push(Object.assign(Object.assign(Object.assign({}, schema), LlmDescriptionInverter_1.LlmDescriptionInverter.numeric(schema.description)), { enum: undefined }));
|
|
397
|
-
else if (LlmTypeChecker_1.LlmTypeChecker.isString(schema))
|
|
398
|
-
if (!!((_d = schema.enum) === null || _d === void 0 ? void 0 : _d.length))
|
|
399
|
-
schema.enum.forEach((v) => union.push({
|
|
400
|
-
const: v,
|
|
401
|
-
}));
|
|
402
|
-
else
|
|
403
|
-
union.push(Object.assign(Object.assign(Object.assign({}, schema), LlmDescriptionInverter_1.LlmDescriptionInverter.string(schema.description)), { enum: undefined }));
|
|
404
|
-
else
|
|
405
|
-
union.push(Object.assign({}, schema));
|
|
406
|
-
};
|
|
407
|
-
visit(props.schema);
|
|
408
|
-
return Object.assign(Object.assign({}, attribute), (union.length === 0
|
|
409
|
-
? { type: undefined }
|
|
410
|
-
: union.length === 1
|
|
411
|
-
? Object.assign({}, union[0]) : {
|
|
412
|
-
oneOf: union.map((u) => (Object.assign(Object.assign({}, u), { nullable: undefined }))),
|
|
413
|
-
discriminator: LlmTypeChecker_1.LlmTypeChecker.isAnyOf(props.schema) &&
|
|
414
|
-
props.schema["x-discriminator"] !== undefined
|
|
415
|
-
? {
|
|
416
|
-
propertyName: props.schema["x-discriminator"].propertyName,
|
|
417
|
-
mapping: props.schema["x-discriminator"].mapping !== undefined
|
|
418
|
-
? Object.fromEntries(Object.entries(props.schema["x-discriminator"].mapping).map(([key, value]) => [
|
|
419
|
-
key,
|
|
420
|
-
`#/components/schemas/${value.split("/").at(-1)}`,
|
|
421
|
-
]))
|
|
422
|
-
: undefined,
|
|
423
|
-
}
|
|
424
|
-
: undefined,
|
|
425
|
-
}));
|
|
426
|
-
};
|
|
427
|
-
})(LlmSchemaConverter$1 || (LlmSchemaConverter.LlmSchemaConverter = LlmSchemaConverter$1 = {}));
|
|
428
|
-
const validateStrict = (schema, accessor) => {
|
|
429
|
-
var _a;
|
|
430
|
-
var _b;
|
|
431
|
-
const reasons = [];
|
|
432
|
-
if (OpenApiTypeChecker_1.OpenApiTypeChecker.isObject(schema)) {
|
|
433
|
-
if (!!schema.additionalProperties)
|
|
434
|
-
reasons.push({
|
|
435
|
-
schema: schema,
|
|
436
|
-
accessor: `${accessor}.additionalProperties`,
|
|
437
|
-
message: "LLM does not allow additionalProperties in strict mode, the dynamic key typed object.",
|
|
438
|
-
});
|
|
439
|
-
for (const key of Object.keys((_b = schema.properties) !== null && _b !== void 0 ? _b : {}))
|
|
440
|
-
if (((_a = schema.required) === null || _a === void 0 ? void 0 : _a.includes(key)) === false)
|
|
441
|
-
reasons.push({
|
|
442
|
-
schema: schema,
|
|
443
|
-
accessor: `${accessor}.properties.${key}`,
|
|
444
|
-
message: "LLM does not allow optional properties in strict mode.",
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
return reasons;
|
|
448
|
-
};
|
|
449
|
-
|
|
450
|
-
return LlmSchemaConverter;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
export { requireLlmSchemaConverter as __require };
|
|
442
|
+
export { LlmSchemaConverter_2 as LlmSchemaConverter, LlmSchemaConverter$1 as default };
|
|
454
443
|
//# sourceMappingURL=LlmSchemaConverter2.mjs.map
|