@typia/utils 13.0.0-dev.20260427-3 → 13.0.0-dev.20260501

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.
Files changed (345) hide show
  1. package/lib/converters/LlmSchemaConverter.js +6 -6
  2. package/lib/converters/LlmSchemaConverter.js.map +1 -1
  3. package/lib/converters/LlmSchemaConverter.mjs +2 -7
  4. package/lib/converters/LlmSchemaConverter.mjs.map +1 -1
  5. package/lib/converters/LlmSchemaConverter2.mjs +449 -451
  6. package/lib/converters/LlmSchemaConverter2.mjs.map +1 -1
  7. package/lib/converters/OpenApiConverter.mjs +2 -7
  8. package/lib/converters/OpenApiConverter.mjs.map +1 -1
  9. package/lib/converters/OpenApiConverter2.mjs +163 -164
  10. package/lib/converters/OpenApiConverter2.mjs.map +1 -1
  11. package/lib/converters/index.mjs +1 -7
  12. package/lib/converters/index.mjs.map +1 -1
  13. package/lib/converters/index2.mjs +31 -32
  14. package/lib/converters/index2.mjs.map +1 -1
  15. package/lib/converters/internal/LlmDescriptionInverter.mjs +2 -7
  16. package/lib/converters/internal/LlmDescriptionInverter.mjs.map +1 -1
  17. package/lib/converters/internal/LlmDescriptionInverter2.mjs +143 -150
  18. package/lib/converters/internal/LlmDescriptionInverter2.mjs.map +1 -1
  19. package/lib/converters/internal/LlmParametersComposer.mjs +2 -7
  20. package/lib/converters/internal/LlmParametersComposer.mjs.map +1 -1
  21. package/lib/converters/internal/LlmParametersComposer2.mjs +37 -44
  22. package/lib/converters/internal/LlmParametersComposer2.mjs.map +1 -1
  23. package/lib/converters/internal/OpenApiConstraintShifter.mjs +2 -7
  24. package/lib/converters/internal/OpenApiConstraintShifter.mjs.map +1 -1
  25. package/lib/converters/internal/OpenApiConstraintShifter2.mjs +105 -112
  26. package/lib/converters/internal/OpenApiConstraintShifter2.mjs.map +1 -1
  27. package/lib/converters/internal/OpenApiExclusiveEmender.mjs +2 -7
  28. package/lib/converters/internal/OpenApiExclusiveEmender.mjs.map +1 -1
  29. package/lib/converters/internal/OpenApiExclusiveEmender2.mjs +32 -40
  30. package/lib/converters/internal/OpenApiExclusiveEmender2.mjs.map +1 -1
  31. package/lib/converters/internal/OpenApiV3Downgrader.mjs +2 -7
  32. package/lib/converters/internal/OpenApiV3Downgrader.mjs.map +1 -1
  33. package/lib/converters/internal/OpenApiV3Downgrader2.mjs +237 -244
  34. package/lib/converters/internal/OpenApiV3Downgrader2.mjs.map +1 -1
  35. package/lib/converters/internal/OpenApiV3Upgrader.mjs +2 -7
  36. package/lib/converters/internal/OpenApiV3Upgrader.mjs.map +1 -1
  37. package/lib/converters/internal/OpenApiV3Upgrader2.mjs +300 -305
  38. package/lib/converters/internal/OpenApiV3Upgrader2.mjs.map +1 -1
  39. package/lib/converters/internal/OpenApiV3_1Downgrader.mjs +2 -7
  40. package/lib/converters/internal/OpenApiV3_1Downgrader.mjs.map +1 -1
  41. package/lib/converters/internal/OpenApiV3_1Downgrader2.mjs +193 -200
  42. package/lib/converters/internal/OpenApiV3_1Downgrader2.mjs.map +1 -1
  43. package/lib/converters/internal/OpenApiV3_1Upgrader.mjs +2 -7
  44. package/lib/converters/internal/OpenApiV3_1Upgrader.mjs.map +1 -1
  45. package/lib/converters/internal/OpenApiV3_1Upgrader2.mjs +424 -429
  46. package/lib/converters/internal/OpenApiV3_1Upgrader2.mjs.map +1 -1
  47. package/lib/converters/internal/OpenApiV3_2Upgrader.mjs +2 -7
  48. package/lib/converters/internal/OpenApiV3_2Upgrader.mjs.map +1 -1
  49. package/lib/converters/internal/OpenApiV3_2Upgrader2.mjs +202 -208
  50. package/lib/converters/internal/OpenApiV3_2Upgrader2.mjs.map +1 -1
  51. package/lib/converters/internal/SwaggerV2Downgrader.mjs +2 -7
  52. package/lib/converters/internal/SwaggerV2Downgrader.mjs.map +1 -1
  53. package/lib/converters/internal/SwaggerV2Downgrader2.mjs +287 -294
  54. package/lib/converters/internal/SwaggerV2Downgrader2.mjs.map +1 -1
  55. package/lib/converters/internal/SwaggerV2Upgrader.mjs +2 -7
  56. package/lib/converters/internal/SwaggerV2Upgrader.mjs.map +1 -1
  57. package/lib/converters/internal/SwaggerV2Upgrader2.mjs +370 -375
  58. package/lib/converters/internal/SwaggerV2Upgrader2.mjs.map +1 -1
  59. package/lib/http/HttpError.mjs +2 -7
  60. package/lib/http/HttpError.mjs.map +1 -1
  61. package/lib/http/HttpError2.mjs +69 -77
  62. package/lib/http/HttpError2.mjs.map +1 -1
  63. package/lib/http/HttpLlm.mjs +2 -7
  64. package/lib/http/HttpLlm.mjs.map +1 -1
  65. package/lib/http/HttpLlm2.mjs +107 -112
  66. package/lib/http/HttpLlm2.mjs.map +1 -1
  67. package/lib/http/HttpMigration.mjs +2 -7
  68. package/lib/http/HttpMigration.mjs.map +1 -1
  69. package/lib/http/HttpMigration2.mjs +58 -63
  70. package/lib/http/HttpMigration2.mjs.map +1 -1
  71. package/lib/http/index.mjs +1 -7
  72. package/lib/http/index.mjs.map +1 -1
  73. package/lib/http/index2.mjs +30 -31
  74. package/lib/http/index2.mjs.map +1 -1
  75. package/lib/http/internal/HttpLlmApplicationComposer.mjs +2 -7
  76. package/lib/http/internal/HttpLlmApplicationComposer.mjs.map +1 -1
  77. package/lib/http/internal/HttpLlmApplicationComposer2.mjs +301 -306
  78. package/lib/http/internal/HttpLlmApplicationComposer2.mjs.map +1 -1
  79. package/lib/http/internal/HttpLlmFunctionFetcher.mjs +2 -7
  80. package/lib/http/internal/HttpLlmFunctionFetcher.mjs.map +1 -1
  81. package/lib/http/internal/HttpLlmFunctionFetcher2.mjs +26 -33
  82. package/lib/http/internal/HttpLlmFunctionFetcher2.mjs.map +1 -1
  83. package/lib/http/internal/HttpMigrateApplicationComposer.mjs +2 -7
  84. package/lib/http/internal/HttpMigrateApplicationComposer.mjs.map +1 -1
  85. package/lib/http/internal/HttpMigrateApplicationComposer2.mjs +51 -56
  86. package/lib/http/internal/HttpMigrateApplicationComposer2.mjs.map +1 -1
  87. package/lib/http/internal/HttpMigrateRouteAccessor.mjs +2 -7
  88. package/lib/http/internal/HttpMigrateRouteAccessor.mjs.map +1 -1
  89. package/lib/http/internal/HttpMigrateRouteAccessor2.mjs +113 -118
  90. package/lib/http/internal/HttpMigrateRouteAccessor2.mjs.map +1 -1
  91. package/lib/http/internal/HttpMigrateRouteComposer.mjs +2 -7
  92. package/lib/http/internal/HttpMigrateRouteComposer.mjs.map +1 -1
  93. package/lib/http/internal/HttpMigrateRouteComposer2.mjs +376 -381
  94. package/lib/http/internal/HttpMigrateRouteComposer2.mjs.map +1 -1
  95. package/lib/http/internal/HttpMigrateRouteFetcher.mjs +2 -7
  96. package/lib/http/internal/HttpMigrateRouteFetcher.mjs.map +1 -1
  97. package/lib/http/internal/HttpMigrateRouteFetcher2.mjs +182 -189
  98. package/lib/http/internal/HttpMigrateRouteFetcher2.mjs.map +1 -1
  99. package/lib/index.mjs +1 -7
  100. package/lib/index.mjs.map +1 -1
  101. package/lib/index2.mjs +33 -33
  102. package/lib/index2.mjs.map +1 -1
  103. package/lib/utils/ArrayUtil.mjs +2 -7
  104. package/lib/utils/ArrayUtil.mjs.map +1 -1
  105. package/lib/utils/ArrayUtil2.mjs +29 -37
  106. package/lib/utils/ArrayUtil2.mjs.map +1 -1
  107. package/lib/utils/LlmJson.mjs +2 -7
  108. package/lib/utils/LlmJson.mjs.map +1 -1
  109. package/lib/utils/LlmJson2.mjs +166 -169
  110. package/lib/utils/LlmJson2.mjs.map +1 -1
  111. package/lib/utils/MapUtil.mjs +2 -7
  112. package/lib/utils/MapUtil.mjs.map +1 -1
  113. package/lib/utils/MapUtil2.mjs +16 -24
  114. package/lib/utils/MapUtil2.mjs.map +1 -1
  115. package/lib/utils/NamingConvention.mjs +2 -7
  116. package/lib/utils/NamingConvention.mjs.map +1 -1
  117. package/lib/utils/NamingConvention2.mjs +199 -207
  118. package/lib/utils/NamingConvention2.mjs.map +1 -1
  119. package/lib/utils/Singleton.d.ts +1 -6
  120. package/lib/utils/Singleton.js +1 -0
  121. package/lib/utils/Singleton.js.map +1 -1
  122. package/lib/utils/Singleton.mjs +2 -7
  123. package/lib/utils/Singleton.mjs.map +1 -1
  124. package/lib/utils/Singleton2.mjs +17 -24
  125. package/lib/utils/Singleton2.mjs.map +1 -1
  126. package/lib/utils/StringUtil.mjs +2 -7
  127. package/lib/utils/StringUtil.mjs.map +1 -1
  128. package/lib/utils/StringUtil2.mjs +14 -22
  129. package/lib/utils/StringUtil2.mjs.map +1 -1
  130. package/lib/utils/dedent.mjs +2 -7
  131. package/lib/utils/dedent.mjs.map +1 -1
  132. package/lib/utils/dedent2.mjs +50 -58
  133. package/lib/utils/dedent2.mjs.map +1 -1
  134. package/lib/utils/index.mjs +1 -7
  135. package/lib/utils/index.mjs.map +1 -1
  136. package/lib/utils/index2.mjs +42 -39
  137. package/lib/utils/index2.mjs.map +1 -1
  138. package/lib/utils/internal/EndpointUtil.mjs +2 -7
  139. package/lib/utils/internal/EndpointUtil.mjs.map +1 -1
  140. package/lib/utils/internal/EndpointUtil2.mjs +39 -46
  141. package/lib/utils/internal/EndpointUtil2.mjs.map +1 -1
  142. package/lib/utils/internal/JsonDescriptor.mjs +2 -7
  143. package/lib/utils/internal/JsonDescriptor.mjs.map +1 -1
  144. package/lib/utils/internal/JsonDescriptor2.mjs +55 -61
  145. package/lib/utils/internal/JsonDescriptor2.mjs.map +1 -1
  146. package/lib/utils/internal/OpenApiTypeCheckerBase.js +23 -14
  147. package/lib/utils/internal/OpenApiTypeCheckerBase.js.map +1 -1
  148. package/lib/utils/internal/OpenApiTypeCheckerBase.mjs +2 -7
  149. package/lib/utils/internal/OpenApiTypeCheckerBase.mjs.map +1 -1
  150. package/lib/utils/internal/OpenApiTypeCheckerBase2.mjs +539 -536
  151. package/lib/utils/internal/OpenApiTypeCheckerBase2.mjs.map +1 -1
  152. package/lib/utils/internal/coerceLlmArguments.js +27 -1
  153. package/lib/utils/internal/coerceLlmArguments.js.map +1 -1
  154. package/lib/utils/internal/coerceLlmArguments.mjs +2 -7
  155. package/lib/utils/internal/coerceLlmArguments.mjs.map +1 -1
  156. package/lib/utils/internal/coerceLlmArguments2.mjs +278 -258
  157. package/lib/utils/internal/coerceLlmArguments2.mjs.map +1 -1
  158. package/lib/utils/internal/parseLenientJson.mjs +2 -7
  159. package/lib/utils/internal/parseLenientJson.mjs.map +1 -1
  160. package/lib/utils/internal/parseLenientJson2.mjs +803 -811
  161. package/lib/utils/internal/parseLenientJson2.mjs.map +1 -1
  162. package/lib/utils/internal/stringifyValidationFailure.mjs +2 -7
  163. package/lib/utils/internal/stringifyValidationFailure.mjs.map +1 -1
  164. package/lib/utils/internal/stringifyValidationFailure2.mjs +310 -316
  165. package/lib/utils/internal/stringifyValidationFailure2.mjs.map +1 -1
  166. package/lib/validators/LlmTypeChecker.mjs +2 -7
  167. package/lib/validators/LlmTypeChecker.mjs.map +1 -1
  168. package/lib/validators/LlmTypeChecker2.mjs +314 -320
  169. package/lib/validators/LlmTypeChecker2.mjs.map +1 -1
  170. package/lib/validators/OpenApiTypeChecker.mjs +2 -7
  171. package/lib/validators/OpenApiTypeChecker.mjs.map +1 -1
  172. package/lib/validators/OpenApiTypeChecker2.mjs +209 -216
  173. package/lib/validators/OpenApiTypeChecker2.mjs.map +1 -1
  174. package/lib/validators/OpenApiV3TypeChecker.mjs +2 -7
  175. package/lib/validators/OpenApiV3TypeChecker.mjs.map +1 -1
  176. package/lib/validators/OpenApiV3TypeChecker2.mjs +30 -38
  177. package/lib/validators/OpenApiV3TypeChecker2.mjs.map +1 -1
  178. package/lib/validators/OpenApiV3_1TypeChecker.mjs +2 -7
  179. package/lib/validators/OpenApiV3_1TypeChecker.mjs.map +1 -1
  180. package/lib/validators/OpenApiV3_1TypeChecker2.mjs +34 -42
  181. package/lib/validators/OpenApiV3_1TypeChecker2.mjs.map +1 -1
  182. package/lib/validators/OpenApiValidator.mjs +2 -7
  183. package/lib/validators/OpenApiValidator.mjs.map +1 -1
  184. package/lib/validators/OpenApiValidator2.mjs +73 -80
  185. package/lib/validators/OpenApiValidator2.mjs.map +1 -1
  186. package/lib/validators/SwaggerV2TypeChecker.mjs +2 -7
  187. package/lib/validators/SwaggerV2TypeChecker.mjs.map +1 -1
  188. package/lib/validators/SwaggerV2TypeChecker2.mjs +31 -39
  189. package/lib/validators/SwaggerV2TypeChecker2.mjs.map +1 -1
  190. package/lib/validators/functional/_isBigintString.mjs +2 -7
  191. package/lib/validators/functional/_isBigintString.mjs.map +1 -1
  192. package/lib/validators/functional/_isBigintString2.mjs +14 -22
  193. package/lib/validators/functional/_isBigintString2.mjs.map +1 -1
  194. package/lib/validators/functional/_isFormatByte.mjs +2 -7
  195. package/lib/validators/functional/_isFormatByte.mjs.map +1 -1
  196. package/lib/validators/functional/_isFormatByte2.mjs +10 -18
  197. package/lib/validators/functional/_isFormatByte2.mjs.map +1 -1
  198. package/lib/validators/functional/_isFormatDate.mjs +2 -7
  199. package/lib/validators/functional/_isFormatDate.mjs.map +1 -1
  200. package/lib/validators/functional/_isFormatDate2.mjs +7 -15
  201. package/lib/validators/functional/_isFormatDate2.mjs.map +1 -1
  202. package/lib/validators/functional/_isFormatDateTime.mjs +2 -7
  203. package/lib/validators/functional/_isFormatDateTime.mjs.map +1 -1
  204. package/lib/validators/functional/_isFormatDateTime2.mjs +7 -15
  205. package/lib/validators/functional/_isFormatDateTime2.mjs.map +1 -1
  206. package/lib/validators/functional/_isFormatDuration.mjs +2 -7
  207. package/lib/validators/functional/_isFormatDuration.mjs.map +1 -1
  208. package/lib/validators/functional/_isFormatDuration2.mjs +7 -15
  209. package/lib/validators/functional/_isFormatDuration2.mjs.map +1 -1
  210. package/lib/validators/functional/_isFormatEmail.mjs +2 -7
  211. package/lib/validators/functional/_isFormatEmail.mjs.map +1 -1
  212. package/lib/validators/functional/_isFormatEmail2.mjs +7 -15
  213. package/lib/validators/functional/_isFormatEmail2.mjs.map +1 -1
  214. package/lib/validators/functional/_isFormatHostname.mjs +2 -7
  215. package/lib/validators/functional/_isFormatHostname.mjs.map +1 -1
  216. package/lib/validators/functional/_isFormatHostname2.mjs +7 -15
  217. package/lib/validators/functional/_isFormatHostname2.mjs.map +1 -1
  218. package/lib/validators/functional/_isFormatIdnEmail.mjs +2 -7
  219. package/lib/validators/functional/_isFormatIdnEmail.mjs.map +1 -1
  220. package/lib/validators/functional/_isFormatIdnEmail2.mjs +7 -15
  221. package/lib/validators/functional/_isFormatIdnEmail2.mjs.map +1 -1
  222. package/lib/validators/functional/_isFormatIdnHostname.mjs +2 -7
  223. package/lib/validators/functional/_isFormatIdnHostname.mjs.map +1 -1
  224. package/lib/validators/functional/_isFormatIdnHostname2.mjs +7 -15
  225. package/lib/validators/functional/_isFormatIdnHostname2.mjs.map +1 -1
  226. package/lib/validators/functional/_isFormatIpv4.mjs +2 -7
  227. package/lib/validators/functional/_isFormatIpv4.mjs.map +1 -1
  228. package/lib/validators/functional/_isFormatIpv42.mjs +7 -15
  229. package/lib/validators/functional/_isFormatIpv42.mjs.map +1 -1
  230. package/lib/validators/functional/_isFormatIpv6.mjs +2 -7
  231. package/lib/validators/functional/_isFormatIpv6.mjs.map +1 -1
  232. package/lib/validators/functional/_isFormatIpv62.mjs +7 -15
  233. package/lib/validators/functional/_isFormatIpv62.mjs.map +1 -1
  234. package/lib/validators/functional/_isFormatIri.mjs +2 -7
  235. package/lib/validators/functional/_isFormatIri.mjs.map +1 -1
  236. package/lib/validators/functional/_isFormatIri2.mjs +7 -15
  237. package/lib/validators/functional/_isFormatIri2.mjs.map +1 -1
  238. package/lib/validators/functional/_isFormatIriReference.mjs +2 -7
  239. package/lib/validators/functional/_isFormatIriReference.mjs.map +1 -1
  240. package/lib/validators/functional/_isFormatIriReference2.mjs +7 -15
  241. package/lib/validators/functional/_isFormatIriReference2.mjs.map +1 -1
  242. package/lib/validators/functional/_isFormatJsonPointer.mjs +2 -7
  243. package/lib/validators/functional/_isFormatJsonPointer.mjs.map +1 -1
  244. package/lib/validators/functional/_isFormatJsonPointer2.mjs +7 -15
  245. package/lib/validators/functional/_isFormatJsonPointer2.mjs.map +1 -1
  246. package/lib/validators/functional/_isFormatPassword.mjs +2 -7
  247. package/lib/validators/functional/_isFormatPassword.mjs.map +1 -1
  248. package/lib/validators/functional/_isFormatPassword2.mjs +6 -14
  249. package/lib/validators/functional/_isFormatPassword2.mjs.map +1 -1
  250. package/lib/validators/functional/_isFormatRegex.mjs +2 -7
  251. package/lib/validators/functional/_isFormatRegex.mjs.map +1 -1
  252. package/lib/validators/functional/_isFormatRegex2.mjs +14 -22
  253. package/lib/validators/functional/_isFormatRegex2.mjs.map +1 -1
  254. package/lib/validators/functional/_isFormatRelativeJsonPointer.mjs +2 -7
  255. package/lib/validators/functional/_isFormatRelativeJsonPointer.mjs.map +1 -1
  256. package/lib/validators/functional/_isFormatRelativeJsonPointer2.mjs +7 -15
  257. package/lib/validators/functional/_isFormatRelativeJsonPointer2.mjs.map +1 -1
  258. package/lib/validators/functional/_isFormatTime.mjs +2 -7
  259. package/lib/validators/functional/_isFormatTime.mjs.map +1 -1
  260. package/lib/validators/functional/_isFormatTime2.mjs +7 -15
  261. package/lib/validators/functional/_isFormatTime2.mjs.map +1 -1
  262. package/lib/validators/functional/_isFormatUri.mjs +2 -7
  263. package/lib/validators/functional/_isFormatUri.mjs.map +1 -1
  264. package/lib/validators/functional/_isFormatUri2.mjs +8 -16
  265. package/lib/validators/functional/_isFormatUri2.mjs.map +1 -1
  266. package/lib/validators/functional/_isFormatUriReference.mjs +2 -7
  267. package/lib/validators/functional/_isFormatUriReference.mjs.map +1 -1
  268. package/lib/validators/functional/_isFormatUriReference2.mjs +7 -15
  269. package/lib/validators/functional/_isFormatUriReference2.mjs.map +1 -1
  270. package/lib/validators/functional/_isFormatUriTemplate.mjs +2 -7
  271. package/lib/validators/functional/_isFormatUriTemplate.mjs.map +1 -1
  272. package/lib/validators/functional/_isFormatUriTemplate2.mjs +7 -15
  273. package/lib/validators/functional/_isFormatUriTemplate2.mjs.map +1 -1
  274. package/lib/validators/functional/_isFormatUrl.mjs +2 -7
  275. package/lib/validators/functional/_isFormatUrl.mjs.map +1 -1
  276. package/lib/validators/functional/_isFormatUrl2.mjs +7 -15
  277. package/lib/validators/functional/_isFormatUrl2.mjs.map +1 -1
  278. package/lib/validators/functional/_isFormatUuid.mjs +2 -7
  279. package/lib/validators/functional/_isFormatUuid.mjs.map +1 -1
  280. package/lib/validators/functional/_isFormatUuid2.mjs +7 -15
  281. package/lib/validators/functional/_isFormatUuid2.mjs.map +1 -1
  282. package/lib/validators/functional/_isUniqueItems.mjs +2 -7
  283. package/lib/validators/functional/_isUniqueItems.mjs.map +1 -1
  284. package/lib/validators/functional/_isUniqueItems2.mjs +140 -148
  285. package/lib/validators/functional/_isUniqueItems2.mjs.map +1 -1
  286. package/lib/validators/index.mjs +1 -7
  287. package/lib/validators/index.mjs.map +1 -1
  288. package/lib/validators/index2.mjs +42 -40
  289. package/lib/validators/index2.mjs.map +1 -1
  290. package/lib/validators/internal/IOpenApiValidatorContext.mjs +2 -7
  291. package/lib/validators/internal/IOpenApiValidatorContext.mjs.map +1 -1
  292. package/lib/validators/internal/IOpenApiValidatorContext2.mjs +2 -10
  293. package/lib/validators/internal/IOpenApiValidatorContext2.mjs.map +1 -1
  294. package/lib/validators/internal/OpenApiArrayValidator.mjs +2 -7
  295. package/lib/validators/internal/OpenApiArrayValidator.mjs.map +1 -1
  296. package/lib/validators/internal/OpenApiArrayValidator2.mjs +36 -42
  297. package/lib/validators/internal/OpenApiArrayValidator2.mjs.map +1 -1
  298. package/lib/validators/internal/OpenApiBooleanValidator.mjs +2 -7
  299. package/lib/validators/internal/OpenApiBooleanValidator.mjs.map +1 -1
  300. package/lib/validators/internal/OpenApiBooleanValidator2.mjs +10 -18
  301. package/lib/validators/internal/OpenApiBooleanValidator2.mjs.map +1 -1
  302. package/lib/validators/internal/OpenApiConstantValidator.mjs +2 -7
  303. package/lib/validators/internal/OpenApiConstantValidator.mjs.map +1 -1
  304. package/lib/validators/internal/OpenApiConstantValidator2.mjs +10 -18
  305. package/lib/validators/internal/OpenApiConstantValidator2.mjs.map +1 -1
  306. package/lib/validators/internal/OpenApiIntegerValidator.mjs +2 -7
  307. package/lib/validators/internal/OpenApiIntegerValidator.mjs.map +1 -1
  308. package/lib/validators/internal/OpenApiIntegerValidator2.mjs +33 -41
  309. package/lib/validators/internal/OpenApiIntegerValidator2.mjs.map +1 -1
  310. package/lib/validators/internal/OpenApiNumberValidator.mjs +2 -7
  311. package/lib/validators/internal/OpenApiNumberValidator.mjs.map +1 -1
  312. package/lib/validators/internal/OpenApiNumberValidator2.mjs +33 -41
  313. package/lib/validators/internal/OpenApiNumberValidator2.mjs.map +1 -1
  314. package/lib/validators/internal/OpenApiObjectValidator.js +2 -3
  315. package/lib/validators/internal/OpenApiObjectValidator.js.map +1 -1
  316. package/lib/validators/internal/OpenApiObjectValidator.mjs +2 -7
  317. package/lib/validators/internal/OpenApiObjectValidator.mjs.map +1 -1
  318. package/lib/validators/internal/OpenApiObjectValidator2.mjs +55 -62
  319. package/lib/validators/internal/OpenApiObjectValidator2.mjs.map +1 -1
  320. package/lib/validators/internal/OpenApiOneOfValidator.mjs +2 -7
  321. package/lib/validators/internal/OpenApiOneOfValidator.mjs.map +1 -1
  322. package/lib/validators/internal/OpenApiOneOfValidator2.mjs +188 -193
  323. package/lib/validators/internal/OpenApiOneOfValidator2.mjs.map +1 -1
  324. package/lib/validators/internal/OpenApiSchemaNamingRule.mjs +2 -7
  325. package/lib/validators/internal/OpenApiSchemaNamingRule.mjs.map +1 -1
  326. package/lib/validators/internal/OpenApiSchemaNamingRule2.mjs +124 -131
  327. package/lib/validators/internal/OpenApiSchemaNamingRule2.mjs.map +1 -1
  328. package/lib/validators/internal/OpenApiStationValidator.mjs +2 -7
  329. package/lib/validators/internal/OpenApiStationValidator.mjs.map +1 -1
  330. package/lib/validators/internal/OpenApiStationValidator2.mjs +86 -83
  331. package/lib/validators/internal/OpenApiStationValidator2.mjs.map +1 -1
  332. package/lib/validators/internal/OpenApiStringValidator.mjs +2 -7
  333. package/lib/validators/internal/OpenApiStringValidator.mjs.map +1 -1
  334. package/lib/validators/internal/OpenApiStringValidator2.mjs +115 -102
  335. package/lib/validators/internal/OpenApiStringValidator2.mjs.map +1 -1
  336. package/lib/validators/internal/OpenApiTupleValidator.mjs +2 -7
  337. package/lib/validators/internal/OpenApiTupleValidator.mjs.map +1 -1
  338. package/lib/validators/internal/OpenApiTupleValidator2.mjs +33 -40
  339. package/lib/validators/internal/OpenApiTupleValidator2.mjs.map +1 -1
  340. package/package.json +4 -4
  341. package/src/converters/LlmSchemaConverter.ts +1 -1
  342. package/src/utils/Singleton.ts +1 -0
  343. package/src/utils/internal/OpenApiTypeCheckerBase.ts +12 -3
  344. package/src/utils/internal/coerceLlmArguments.ts +27 -1
  345. package/src/validators/internal/OpenApiObjectValidator.ts +1 -2
@@ -1,454 +1,452 @@
1
- import { __exports as LlmSchemaConverter } from '../_virtual/LlmSchemaConverter.mjs';
2
- import { __require as requireJsonDescriptor } from '../utils/internal/JsonDescriptor2.mjs';
3
- import { __require as requireLlmTypeChecker } from '../validators/LlmTypeChecker2.mjs';
4
- import { __require as requireOpenApiTypeChecker } from '../validators/OpenApiTypeChecker2.mjs';
5
- import { __require as requireLlmDescriptionInverter } from './internal/LlmDescriptionInverter2.mjs';
6
- import { __require as requireLlmParametersComposer } from './internal/LlmParametersComposer2.mjs';
7
- import { __require as requireOpenApiConstraintShifter } from './internal/OpenApiConstraintShifter2.mjs';
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
- var hasRequiredLlmSchemaConverter;
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
+ var _a;
431
+ var _b;
432
+ const reasons = [];
433
+ if (OpenApiTypeChecker_1.OpenApiTypeChecker.isObject(schema)) {
434
+ if (!!schema.additionalProperties)
435
+ reasons.push({
436
+ schema: schema,
437
+ accessor: `${accessor}.additionalProperties`,
438
+ message: "LLM does not allow additionalProperties in strict mode, the dynamic key typed object.",
439
+ });
440
+ for (const key of Object.keys((_b = schema.properties) !== null && _b !== void 0 ? _b : {}))
441
+ if (((_a = schema.required) === null || _a === void 0 ? void 0 : _a.includes(key)) === false)
442
+ reasons.push({
443
+ schema: schema,
444
+ accessor: `${accessor}.properties.${key}`,
445
+ message: "LLM does not allow optional properties in strict mode.",
446
+ });
447
+ }
448
+ return reasons;
449
+ };
10
450
 
11
- function requireLlmSchemaConverter () {
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 };
451
+ export { LlmSchemaConverter_2 as LlmSchemaConverter, LlmSchemaConverter$1 as default };
454
452
  //# sourceMappingURL=LlmSchemaConverter2.mjs.map