@typia/utils 12.0.0-dev.20260225

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 (471) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +79 -0
  3. package/lib/converters/LlmSchemaConverter.d.ts +102 -0
  4. package/lib/converters/LlmSchemaConverter.js +652 -0
  5. package/lib/converters/LlmSchemaConverter.js.map +1 -0
  6. package/lib/converters/LlmSchemaConverter.mjs +771 -0
  7. package/lib/converters/LlmSchemaConverter.mjs.map +1 -0
  8. package/lib/converters/OpenApiConverter.d.ts +135 -0
  9. package/lib/converters/OpenApiConverter.js +130 -0
  10. package/lib/converters/OpenApiConverter.js.map +1 -0
  11. package/lib/converters/OpenApiConverter.mjs +128 -0
  12. package/lib/converters/OpenApiConverter.mjs.map +1 -0
  13. package/lib/converters/index.d.ts +2 -0
  14. package/lib/converters/index.js +21 -0
  15. package/lib/converters/index.js.map +1 -0
  16. package/lib/converters/index.mjs +4 -0
  17. package/lib/converters/index.mjs.map +1 -0
  18. package/lib/converters/internal/LlmDescriptionInverter.d.ts +6 -0
  19. package/lib/converters/internal/LlmDescriptionInverter.js +141 -0
  20. package/lib/converters/internal/LlmDescriptionInverter.js.map +1 -0
  21. package/lib/converters/internal/LlmDescriptionInverter.mjs +141 -0
  22. package/lib/converters/internal/LlmDescriptionInverter.mjs.map +1 -0
  23. package/lib/converters/internal/LlmParametersComposer.d.ts +1 -0
  24. package/lib/converters/internal/LlmParametersComposer.js +39 -0
  25. package/lib/converters/internal/LlmParametersComposer.js.map +1 -0
  26. package/lib/converters/internal/LlmParametersComposer.mjs +42 -0
  27. package/lib/converters/internal/LlmParametersComposer.mjs.map +1 -0
  28. package/lib/converters/internal/OpenApiConstraintShifter.d.ts +6 -0
  29. package/lib/converters/internal/OpenApiConstraintShifter.js +103 -0
  30. package/lib/converters/internal/OpenApiConstraintShifter.js.map +1 -0
  31. package/lib/converters/internal/OpenApiConstraintShifter.mjs +102 -0
  32. package/lib/converters/internal/OpenApiConstraintShifter.mjs.map +1 -0
  33. package/lib/converters/internal/OpenApiExclusiveEmender.d.ts +4 -0
  34. package/lib/converters/internal/OpenApiExclusiveEmender.js +32 -0
  35. package/lib/converters/internal/OpenApiExclusiveEmender.js.map +1 -0
  36. package/lib/converters/internal/OpenApiExclusiveEmender.mjs +35 -0
  37. package/lib/converters/internal/OpenApiExclusiveEmender.mjs.map +1 -0
  38. package/lib/converters/internal/OpenApiV3Downgrader.d.ts +10 -0
  39. package/lib/converters/internal/OpenApiV3Downgrader.js +214 -0
  40. package/lib/converters/internal/OpenApiV3Downgrader.js.map +1 -0
  41. package/lib/converters/internal/OpenApiV3Downgrader.mjs +279 -0
  42. package/lib/converters/internal/OpenApiV3Downgrader.mjs.map +1 -0
  43. package/lib/converters/internal/OpenApiV3Upgrader.d.ts +6 -0
  44. package/lib/converters/internal/OpenApiV3Upgrader.js +285 -0
  45. package/lib/converters/internal/OpenApiV3Upgrader.js.map +1 -0
  46. package/lib/converters/internal/OpenApiV3Upgrader.mjs +349 -0
  47. package/lib/converters/internal/OpenApiV3Upgrader.mjs.map +1 -0
  48. package/lib/converters/internal/OpenApiV3_1Upgrader.d.ts +6 -0
  49. package/lib/converters/internal/OpenApiV3_1Upgrader.js +405 -0
  50. package/lib/converters/internal/OpenApiV3_1Upgrader.js.map +1 -0
  51. package/lib/converters/internal/OpenApiV3_1Upgrader.mjs +545 -0
  52. package/lib/converters/internal/OpenApiV3_1Upgrader.mjs.map +1 -0
  53. package/lib/converters/internal/SwaggerV2Downgrader.d.ts +10 -0
  54. package/lib/converters/internal/SwaggerV2Downgrader.js +294 -0
  55. package/lib/converters/internal/SwaggerV2Downgrader.js.map +1 -0
  56. package/lib/converters/internal/SwaggerV2Downgrader.mjs +332 -0
  57. package/lib/converters/internal/SwaggerV2Downgrader.mjs.map +1 -0
  58. package/lib/converters/internal/SwaggerV2Upgrader.d.ts +6 -0
  59. package/lib/converters/internal/SwaggerV2Upgrader.js +357 -0
  60. package/lib/converters/internal/SwaggerV2Upgrader.js.map +1 -0
  61. package/lib/converters/internal/SwaggerV2Upgrader.mjs +403 -0
  62. package/lib/converters/internal/SwaggerV2Upgrader.mjs.map +1 -0
  63. package/lib/http/HttpError.d.ts +61 -0
  64. package/lib/http/HttpError.js +70 -0
  65. package/lib/http/HttpError.js.map +1 -0
  66. package/lib/http/HttpError.mjs +76 -0
  67. package/lib/http/HttpError.mjs.map +1 -0
  68. package/lib/http/HttpLlm.d.ts +130 -0
  69. package/lib/http/HttpLlm.js +124 -0
  70. package/lib/http/HttpLlm.js.map +1 -0
  71. package/lib/http/HttpLlm.mjs +123 -0
  72. package/lib/http/HttpLlm.mjs.map +1 -0
  73. package/lib/http/HttpMigration.d.ts +58 -0
  74. package/lib/http/HttpMigration.js +52 -0
  75. package/lib/http/HttpMigration.js.map +1 -0
  76. package/lib/http/HttpMigration.mjs +52 -0
  77. package/lib/http/HttpMigration.mjs.map +1 -0
  78. package/lib/http/index.d.ts +3 -0
  79. package/lib/http/index.js +20 -0
  80. package/lib/http/index.js.map +1 -0
  81. package/lib/http/index.mjs +4 -0
  82. package/lib/http/index.mjs.map +1 -0
  83. package/lib/http/internal/HttpLlmApplicationComposer.d.ts +8 -0
  84. package/lib/http/internal/HttpLlmApplicationComposer.js +254 -0
  85. package/lib/http/internal/HttpLlmApplicationComposer.js.map +1 -0
  86. package/lib/http/internal/HttpLlmApplicationComposer.mjs +256 -0
  87. package/lib/http/internal/HttpLlmApplicationComposer.mjs.map +1 -0
  88. package/lib/http/internal/HttpLlmFunctionFetcher.d.ts +6 -0
  89. package/lib/http/internal/HttpLlmFunctionFetcher.js +24 -0
  90. package/lib/http/internal/HttpLlmFunctionFetcher.js.map +1 -0
  91. package/lib/http/internal/HttpLlmFunctionFetcher.mjs +24 -0
  92. package/lib/http/internal/HttpLlmFunctionFetcher.mjs.map +1 -0
  93. package/lib/http/internal/HttpMigrateApplicationComposer.d.ts +4 -0
  94. package/lib/http/internal/HttpMigrateApplicationComposer.js +45 -0
  95. package/lib/http/internal/HttpMigrateApplicationComposer.js.map +1 -0
  96. package/lib/http/internal/HttpMigrateApplicationComposer.mjs +47 -0
  97. package/lib/http/internal/HttpMigrateApplicationComposer.mjs.map +1 -0
  98. package/lib/http/internal/HttpMigrateRouteAccessor.d.ts +4 -0
  99. package/lib/http/internal/HttpMigrateRouteAccessor.js +107 -0
  100. package/lib/http/internal/HttpMigrateRouteAccessor.js.map +1 -0
  101. package/lib/http/internal/HttpMigrateRouteAccessor.mjs +106 -0
  102. package/lib/http/internal/HttpMigrateRouteAccessor.mjs.map +1 -0
  103. package/lib/http/internal/HttpMigrateRouteComposer.d.ts +11 -0
  104. package/lib/http/internal/HttpMigrateRouteComposer.js +398 -0
  105. package/lib/http/internal/HttpMigrateRouteComposer.js.map +1 -0
  106. package/lib/http/internal/HttpMigrateRouteComposer.mjs +392 -0
  107. package/lib/http/internal/HttpMigrateRouteComposer.mjs.map +1 -0
  108. package/lib/http/internal/HttpMigrateRouteFetcher.d.ts +6 -0
  109. package/lib/http/internal/HttpMigrateRouteFetcher.js +179 -0
  110. package/lib/http/internal/HttpMigrateRouteFetcher.js.map +1 -0
  111. package/lib/http/internal/HttpMigrateRouteFetcher.mjs +174 -0
  112. package/lib/http/internal/HttpMigrateRouteFetcher.mjs.map +1 -0
  113. package/lib/http/internal/LlmDataMerger.d.ts +48 -0
  114. package/lib/http/internal/LlmDataMerger.js +60 -0
  115. package/lib/http/internal/LlmDataMerger.js.map +1 -0
  116. package/lib/http/internal/LlmDataMerger.mjs +59 -0
  117. package/lib/http/internal/LlmDataMerger.mjs.map +1 -0
  118. package/lib/index.d.ts +4 -0
  119. package/lib/index.js +21 -0
  120. package/lib/index.js.map +1 -0
  121. package/lib/index.mjs +20 -0
  122. package/lib/index.mjs.map +1 -0
  123. package/lib/utils/ArrayUtil.d.ts +1 -0
  124. package/lib/utils/ArrayUtil.js +29 -0
  125. package/lib/utils/ArrayUtil.js.map +1 -0
  126. package/lib/utils/ArrayUtil.mjs +28 -0
  127. package/lib/utils/ArrayUtil.mjs.map +1 -0
  128. package/lib/utils/MapUtil.d.ts +1 -0
  129. package/lib/utils/MapUtil.js +16 -0
  130. package/lib/utils/MapUtil.js.map +1 -0
  131. package/lib/utils/MapUtil.mjs +15 -0
  132. package/lib/utils/MapUtil.mjs.map +1 -0
  133. package/lib/utils/NamingConvention.d.ts +68 -0
  134. package/lib/utils/NamingConvention.js +199 -0
  135. package/lib/utils/NamingConvention.js.map +1 -0
  136. package/lib/utils/NamingConvention.mjs +198 -0
  137. package/lib/utils/NamingConvention.mjs.map +1 -0
  138. package/lib/utils/Singleton.d.ts +1 -0
  139. package/lib/utils/Singleton.js +18 -0
  140. package/lib/utils/Singleton.js.map +1 -0
  141. package/lib/utils/Singleton.mjs +18 -0
  142. package/lib/utils/Singleton.mjs.map +1 -0
  143. package/lib/utils/StringUtil.d.ts +1 -0
  144. package/lib/utils/StringUtil.js +17 -0
  145. package/lib/utils/StringUtil.js.map +1 -0
  146. package/lib/utils/StringUtil.mjs +13 -0
  147. package/lib/utils/StringUtil.mjs.map +1 -0
  148. package/lib/utils/dedent.d.ts +12 -0
  149. package/lib/utils/dedent.js +51 -0
  150. package/lib/utils/dedent.js.map +1 -0
  151. package/lib/utils/dedent.mjs +50 -0
  152. package/lib/utils/dedent.mjs.map +1 -0
  153. package/lib/utils/index.d.ts +7 -0
  154. package/lib/utils/index.js +24 -0
  155. package/lib/utils/index.js.map +1 -0
  156. package/lib/utils/index.mjs +8 -0
  157. package/lib/utils/index.mjs.map +1 -0
  158. package/lib/utils/internal/EndpointUtil.d.ts +8 -0
  159. package/lib/utils/internal/EndpointUtil.js +37 -0
  160. package/lib/utils/internal/EndpointUtil.js.map +1 -0
  161. package/lib/utils/internal/EndpointUtil.mjs +37 -0
  162. package/lib/utils/internal/EndpointUtil.mjs.map +1 -0
  163. package/lib/utils/internal/JsonDescriptor.d.ts +10 -0
  164. package/lib/utils/internal/JsonDescriptor.js +58 -0
  165. package/lib/utils/internal/JsonDescriptor.js.map +1 -0
  166. package/lib/utils/internal/JsonDescriptor.mjs +48 -0
  167. package/lib/utils/internal/JsonDescriptor.mjs.map +1 -0
  168. package/lib/utils/internal/OpenApiTypeCheckerBase.d.ts +1 -0
  169. package/lib/utils/internal/OpenApiTypeCheckerBase.js +520 -0
  170. package/lib/utils/internal/OpenApiTypeCheckerBase.js.map +1 -0
  171. package/lib/utils/internal/OpenApiTypeCheckerBase.mjs +584 -0
  172. package/lib/utils/internal/OpenApiTypeCheckerBase.mjs.map +1 -0
  173. package/lib/utils/stringifyValidationFailure.d.ts +25 -0
  174. package/lib/utils/stringifyValidationFailure.js +326 -0
  175. package/lib/utils/stringifyValidationFailure.js.map +1 -0
  176. package/lib/utils/stringifyValidationFailure.mjs +325 -0
  177. package/lib/utils/stringifyValidationFailure.mjs.map +1 -0
  178. package/lib/validators/LlmTypeChecker.d.ts +117 -0
  179. package/lib/validators/LlmTypeChecker.js +309 -0
  180. package/lib/validators/LlmTypeChecker.js.map +1 -0
  181. package/lib/validators/LlmTypeChecker.mjs +300 -0
  182. package/lib/validators/LlmTypeChecker.mjs.map +1 -0
  183. package/lib/validators/OpenApiTypeChecker.d.ts +211 -0
  184. package/lib/validators/OpenApiTypeChecker.js +207 -0
  185. package/lib/validators/OpenApiTypeChecker.js.map +1 -0
  186. package/lib/validators/OpenApiTypeChecker.mjs +218 -0
  187. package/lib/validators/OpenApiTypeChecker.mjs.map +1 -0
  188. package/lib/validators/OpenApiV3TypeChecker.d.ts +26 -0
  189. package/lib/validators/OpenApiV3TypeChecker.js +30 -0
  190. package/lib/validators/OpenApiV3TypeChecker.js.map +1 -0
  191. package/lib/validators/OpenApiV3TypeChecker.mjs +29 -0
  192. package/lib/validators/OpenApiV3TypeChecker.mjs.map +1 -0
  193. package/lib/validators/OpenApiV3_1TypeChecker.d.ts +29 -0
  194. package/lib/validators/OpenApiV3_1TypeChecker.js +34 -0
  195. package/lib/validators/OpenApiV3_1TypeChecker.js.map +1 -0
  196. package/lib/validators/OpenApiV3_1TypeChecker.mjs +33 -0
  197. package/lib/validators/OpenApiV3_1TypeChecker.mjs.map +1 -0
  198. package/lib/validators/OpenApiValidator.d.ts +36 -0
  199. package/lib/validators/OpenApiValidator.js +71 -0
  200. package/lib/validators/OpenApiValidator.js.map +1 -0
  201. package/lib/validators/OpenApiValidator.mjs +75 -0
  202. package/lib/validators/OpenApiValidator.mjs.map +1 -0
  203. package/lib/validators/SwaggerV2TypeChecker.d.ts +27 -0
  204. package/lib/validators/SwaggerV2TypeChecker.js +31 -0
  205. package/lib/validators/SwaggerV2TypeChecker.js.map +1 -0
  206. package/lib/validators/SwaggerV2TypeChecker.mjs +30 -0
  207. package/lib/validators/SwaggerV2TypeChecker.mjs.map +1 -0
  208. package/lib/validators/functional/_isBigintString.d.ts +1 -0
  209. package/lib/validators/functional/_isBigintString.js +14 -0
  210. package/lib/validators/functional/_isBigintString.js.map +1 -0
  211. package/lib/validators/functional/_isBigintString.mjs +12 -0
  212. package/lib/validators/functional/_isBigintString.mjs.map +1 -0
  213. package/lib/validators/functional/_isFormatByte.d.ts +1 -0
  214. package/lib/validators/functional/_isFormatByte.js +10 -0
  215. package/lib/validators/functional/_isFormatByte.js.map +1 -0
  216. package/lib/validators/functional/_isFormatByte.mjs +8 -0
  217. package/lib/validators/functional/_isFormatByte.mjs.map +1 -0
  218. package/lib/validators/functional/_isFormatDate.d.ts +1 -0
  219. package/lib/validators/functional/_isFormatDate.js +7 -0
  220. package/lib/validators/functional/_isFormatDate.js.map +1 -0
  221. package/lib/validators/functional/_isFormatDate.mjs +5 -0
  222. package/lib/validators/functional/_isFormatDate.mjs.map +1 -0
  223. package/lib/validators/functional/_isFormatDateTime.d.ts +1 -0
  224. package/lib/validators/functional/_isFormatDateTime.js +7 -0
  225. package/lib/validators/functional/_isFormatDateTime.js.map +1 -0
  226. package/lib/validators/functional/_isFormatDateTime.mjs +5 -0
  227. package/lib/validators/functional/_isFormatDateTime.mjs.map +1 -0
  228. package/lib/validators/functional/_isFormatDuration.d.ts +1 -0
  229. package/lib/validators/functional/_isFormatDuration.js +7 -0
  230. package/lib/validators/functional/_isFormatDuration.js.map +1 -0
  231. package/lib/validators/functional/_isFormatDuration.mjs +5 -0
  232. package/lib/validators/functional/_isFormatDuration.mjs.map +1 -0
  233. package/lib/validators/functional/_isFormatEmail.d.ts +1 -0
  234. package/lib/validators/functional/_isFormatEmail.js +7 -0
  235. package/lib/validators/functional/_isFormatEmail.js.map +1 -0
  236. package/lib/validators/functional/_isFormatEmail.mjs +5 -0
  237. package/lib/validators/functional/_isFormatEmail.mjs.map +1 -0
  238. package/lib/validators/functional/_isFormatHostname.d.ts +1 -0
  239. package/lib/validators/functional/_isFormatHostname.js +7 -0
  240. package/lib/validators/functional/_isFormatHostname.js.map +1 -0
  241. package/lib/validators/functional/_isFormatHostname.mjs +5 -0
  242. package/lib/validators/functional/_isFormatHostname.mjs.map +1 -0
  243. package/lib/validators/functional/_isFormatIdnEmail.d.ts +1 -0
  244. package/lib/validators/functional/_isFormatIdnEmail.js +7 -0
  245. package/lib/validators/functional/_isFormatIdnEmail.js.map +1 -0
  246. package/lib/validators/functional/_isFormatIdnEmail.mjs +5 -0
  247. package/lib/validators/functional/_isFormatIdnEmail.mjs.map +1 -0
  248. package/lib/validators/functional/_isFormatIdnHostname.d.ts +1 -0
  249. package/lib/validators/functional/_isFormatIdnHostname.js +7 -0
  250. package/lib/validators/functional/_isFormatIdnHostname.js.map +1 -0
  251. package/lib/validators/functional/_isFormatIdnHostname.mjs +5 -0
  252. package/lib/validators/functional/_isFormatIdnHostname.mjs.map +1 -0
  253. package/lib/validators/functional/_isFormatIpv4.d.ts +1 -0
  254. package/lib/validators/functional/_isFormatIpv4.js +7 -0
  255. package/lib/validators/functional/_isFormatIpv4.js.map +1 -0
  256. package/lib/validators/functional/_isFormatIpv4.mjs +5 -0
  257. package/lib/validators/functional/_isFormatIpv4.mjs.map +1 -0
  258. package/lib/validators/functional/_isFormatIpv6.d.ts +1 -0
  259. package/lib/validators/functional/_isFormatIpv6.js +7 -0
  260. package/lib/validators/functional/_isFormatIpv6.js.map +1 -0
  261. package/lib/validators/functional/_isFormatIpv6.mjs +5 -0
  262. package/lib/validators/functional/_isFormatIpv6.mjs.map +1 -0
  263. package/lib/validators/functional/_isFormatIri.d.ts +1 -0
  264. package/lib/validators/functional/_isFormatIri.js +7 -0
  265. package/lib/validators/functional/_isFormatIri.js.map +1 -0
  266. package/lib/validators/functional/_isFormatIri.mjs +5 -0
  267. package/lib/validators/functional/_isFormatIri.mjs.map +1 -0
  268. package/lib/validators/functional/_isFormatIriReference.d.ts +1 -0
  269. package/lib/validators/functional/_isFormatIriReference.js +7 -0
  270. package/lib/validators/functional/_isFormatIriReference.js.map +1 -0
  271. package/lib/validators/functional/_isFormatIriReference.mjs +5 -0
  272. package/lib/validators/functional/_isFormatIriReference.mjs.map +1 -0
  273. package/lib/validators/functional/_isFormatJsonPointer.d.ts +1 -0
  274. package/lib/validators/functional/_isFormatJsonPointer.js +7 -0
  275. package/lib/validators/functional/_isFormatJsonPointer.js.map +1 -0
  276. package/lib/validators/functional/_isFormatJsonPointer.mjs +5 -0
  277. package/lib/validators/functional/_isFormatJsonPointer.mjs.map +1 -0
  278. package/lib/validators/functional/_isFormatPassword.d.ts +1 -0
  279. package/lib/validators/functional/_isFormatPassword.js +6 -0
  280. package/lib/validators/functional/_isFormatPassword.js.map +1 -0
  281. package/lib/validators/functional/_isFormatPassword.mjs +4 -0
  282. package/lib/validators/functional/_isFormatPassword.mjs.map +1 -0
  283. package/lib/validators/functional/_isFormatRegex.d.ts +1 -0
  284. package/lib/validators/functional/_isFormatRegex.js +14 -0
  285. package/lib/validators/functional/_isFormatRegex.js.map +1 -0
  286. package/lib/validators/functional/_isFormatRegex.mjs +12 -0
  287. package/lib/validators/functional/_isFormatRegex.mjs.map +1 -0
  288. package/lib/validators/functional/_isFormatRelativeJsonPointer.d.ts +1 -0
  289. package/lib/validators/functional/_isFormatRelativeJsonPointer.js +7 -0
  290. package/lib/validators/functional/_isFormatRelativeJsonPointer.js.map +1 -0
  291. package/lib/validators/functional/_isFormatRelativeJsonPointer.mjs +5 -0
  292. package/lib/validators/functional/_isFormatRelativeJsonPointer.mjs.map +1 -0
  293. package/lib/validators/functional/_isFormatTime.d.ts +1 -0
  294. package/lib/validators/functional/_isFormatTime.js +7 -0
  295. package/lib/validators/functional/_isFormatTime.js.map +1 -0
  296. package/lib/validators/functional/_isFormatTime.mjs +5 -0
  297. package/lib/validators/functional/_isFormatTime.mjs.map +1 -0
  298. package/lib/validators/functional/_isFormatUri.d.ts +1 -0
  299. package/lib/validators/functional/_isFormatUri.js +8 -0
  300. package/lib/validators/functional/_isFormatUri.js.map +1 -0
  301. package/lib/validators/functional/_isFormatUri.mjs +6 -0
  302. package/lib/validators/functional/_isFormatUri.mjs.map +1 -0
  303. package/lib/validators/functional/_isFormatUriReference.d.ts +1 -0
  304. package/lib/validators/functional/_isFormatUriReference.js +7 -0
  305. package/lib/validators/functional/_isFormatUriReference.js.map +1 -0
  306. package/lib/validators/functional/_isFormatUriReference.mjs +5 -0
  307. package/lib/validators/functional/_isFormatUriReference.mjs.map +1 -0
  308. package/lib/validators/functional/_isFormatUriTemplate.d.ts +1 -0
  309. package/lib/validators/functional/_isFormatUriTemplate.js +7 -0
  310. package/lib/validators/functional/_isFormatUriTemplate.js.map +1 -0
  311. package/lib/validators/functional/_isFormatUriTemplate.mjs +5 -0
  312. package/lib/validators/functional/_isFormatUriTemplate.mjs.map +1 -0
  313. package/lib/validators/functional/_isFormatUrl.d.ts +1 -0
  314. package/lib/validators/functional/_isFormatUrl.js +7 -0
  315. package/lib/validators/functional/_isFormatUrl.js.map +1 -0
  316. package/lib/validators/functional/_isFormatUrl.mjs +5 -0
  317. package/lib/validators/functional/_isFormatUrl.mjs.map +1 -0
  318. package/lib/validators/functional/_isFormatUuid.d.ts +1 -0
  319. package/lib/validators/functional/_isFormatUuid.js +7 -0
  320. package/lib/validators/functional/_isFormatUuid.js.map +1 -0
  321. package/lib/validators/functional/_isFormatUuid.mjs +5 -0
  322. package/lib/validators/functional/_isFormatUuid.mjs.map +1 -0
  323. package/lib/validators/functional/_isUniqueItems.d.ts +1 -0
  324. package/lib/validators/functional/_isUniqueItems.js +140 -0
  325. package/lib/validators/functional/_isUniqueItems.js.map +1 -0
  326. package/lib/validators/functional/_isUniqueItems.mjs +138 -0
  327. package/lib/validators/functional/_isUniqueItems.mjs.map +1 -0
  328. package/lib/validators/index.d.ts +2 -0
  329. package/lib/validators/index.js +27 -0
  330. package/lib/validators/index.js.map +1 -0
  331. package/lib/validators/index.mjs +7 -0
  332. package/lib/validators/index.mjs.map +1 -0
  333. package/lib/validators/internal/IOpenApiValidatorContext.d.ts +14 -0
  334. package/lib/validators/internal/IOpenApiValidatorContext.js +3 -0
  335. package/lib/validators/internal/IOpenApiValidatorContext.js.map +1 -0
  336. package/lib/validators/internal/IOpenApiValidatorContext.mjs +2 -0
  337. package/lib/validators/internal/IOpenApiValidatorContext.mjs.map +1 -0
  338. package/lib/validators/internal/OpenApiArrayValidator.d.ts +5 -0
  339. package/lib/validators/internal/OpenApiArrayValidator.js +32 -0
  340. package/lib/validators/internal/OpenApiArrayValidator.js.map +1 -0
  341. package/lib/validators/internal/OpenApiArrayValidator.mjs +47 -0
  342. package/lib/validators/internal/OpenApiArrayValidator.mjs.map +1 -0
  343. package/lib/validators/internal/OpenApiBooleanValidator.d.ts +5 -0
  344. package/lib/validators/internal/OpenApiBooleanValidator.js +10 -0
  345. package/lib/validators/internal/OpenApiBooleanValidator.js.map +1 -0
  346. package/lib/validators/internal/OpenApiBooleanValidator.mjs +9 -0
  347. package/lib/validators/internal/OpenApiBooleanValidator.mjs.map +1 -0
  348. package/lib/validators/internal/OpenApiConstantValidator.d.ts +5 -0
  349. package/lib/validators/internal/OpenApiConstantValidator.js +10 -0
  350. package/lib/validators/internal/OpenApiConstantValidator.js.map +1 -0
  351. package/lib/validators/internal/OpenApiConstantValidator.mjs +9 -0
  352. package/lib/validators/internal/OpenApiConstantValidator.mjs.map +1 -0
  353. package/lib/validators/internal/OpenApiIntegerValidator.d.ts +5 -0
  354. package/lib/validators/internal/OpenApiIntegerValidator.js +33 -0
  355. package/lib/validators/internal/OpenApiIntegerValidator.js.map +1 -0
  356. package/lib/validators/internal/OpenApiIntegerValidator.mjs +47 -0
  357. package/lib/validators/internal/OpenApiIntegerValidator.mjs.map +1 -0
  358. package/lib/validators/internal/OpenApiNumberValidator.d.ts +5 -0
  359. package/lib/validators/internal/OpenApiNumberValidator.js +33 -0
  360. package/lib/validators/internal/OpenApiNumberValidator.js.map +1 -0
  361. package/lib/validators/internal/OpenApiNumberValidator.mjs +47 -0
  362. package/lib/validators/internal/OpenApiNumberValidator.mjs.map +1 -0
  363. package/lib/validators/internal/OpenApiObjectValidator.d.ts +5 -0
  364. package/lib/validators/internal/OpenApiObjectValidator.js +58 -0
  365. package/lib/validators/internal/OpenApiObjectValidator.js.map +1 -0
  366. package/lib/validators/internal/OpenApiObjectValidator.mjs +68 -0
  367. package/lib/validators/internal/OpenApiObjectValidator.mjs.map +1 -0
  368. package/lib/validators/internal/OpenApiOneOfValidator.d.ts +5 -0
  369. package/lib/validators/internal/OpenApiOneOfValidator.js +182 -0
  370. package/lib/validators/internal/OpenApiOneOfValidator.js.map +1 -0
  371. package/lib/validators/internal/OpenApiOneOfValidator.mjs +206 -0
  372. package/lib/validators/internal/OpenApiOneOfValidator.mjs.map +1 -0
  373. package/lib/validators/internal/OpenApiSchemaNamingRule.d.ts +4 -0
  374. package/lib/validators/internal/OpenApiSchemaNamingRule.js +122 -0
  375. package/lib/validators/internal/OpenApiSchemaNamingRule.js.map +1 -0
  376. package/lib/validators/internal/OpenApiSchemaNamingRule.mjs +121 -0
  377. package/lib/validators/internal/OpenApiSchemaNamingRule.mjs.map +1 -0
  378. package/lib/validators/internal/OpenApiStationValidator.d.ts +5 -0
  379. package/lib/validators/internal/OpenApiStationValidator.js +63 -0
  380. package/lib/validators/internal/OpenApiStationValidator.js.map +1 -0
  381. package/lib/validators/internal/OpenApiStationValidator.mjs +107 -0
  382. package/lib/validators/internal/OpenApiStationValidator.mjs.map +1 -0
  383. package/lib/validators/internal/OpenApiStringValidator.d.ts +5 -0
  384. package/lib/validators/internal/OpenApiStringValidator.js +73 -0
  385. package/lib/validators/internal/OpenApiStringValidator.js.map +1 -0
  386. package/lib/validators/internal/OpenApiStringValidator.mjs +85 -0
  387. package/lib/validators/internal/OpenApiStringValidator.mjs.map +1 -0
  388. package/lib/validators/internal/OpenApiTupleValidator.d.ts +5 -0
  389. package/lib/validators/internal/OpenApiTupleValidator.js +31 -0
  390. package/lib/validators/internal/OpenApiTupleValidator.js.map +1 -0
  391. package/lib/validators/internal/OpenApiTupleValidator.mjs +46 -0
  392. package/lib/validators/internal/OpenApiTupleValidator.mjs.map +1 -0
  393. package/package.json +91 -0
  394. package/src/converters/LlmSchemaConverter.ts +924 -0
  395. package/src/converters/OpenApiConverter.ts +285 -0
  396. package/src/converters/index.ts +5 -0
  397. package/src/converters/internal/LlmDescriptionInverter.ts +178 -0
  398. package/src/converters/internal/LlmParametersComposer.ts +52 -0
  399. package/src/converters/internal/OpenApiConstraintShifter.ts +154 -0
  400. package/src/converters/internal/OpenApiExclusiveEmender.ts +46 -0
  401. package/src/converters/internal/OpenApiV3Downgrader.ts +355 -0
  402. package/src/converters/internal/OpenApiV3Upgrader.ts +470 -0
  403. package/src/converters/internal/OpenApiV3_1Upgrader.ts +685 -0
  404. package/src/converters/internal/SwaggerV2Downgrader.ts +424 -0
  405. package/src/converters/internal/SwaggerV2Upgrader.ts +523 -0
  406. package/src/http/HttpError.ts +107 -0
  407. package/src/http/HttpLlm.ts +210 -0
  408. package/src/http/HttpMigration.ts +92 -0
  409. package/src/http/index.ts +3 -0
  410. package/src/http/internal/HttpLlmApplicationComposer.ts +308 -0
  411. package/src/http/internal/HttpLlmFunctionFetcher.ts +37 -0
  412. package/src/http/internal/HttpMigrateApplicationComposer.ts +56 -0
  413. package/src/http/internal/HttpMigrateRouteAccessor.ts +135 -0
  414. package/src/http/internal/HttpMigrateRouteComposer.ts +513 -0
  415. package/src/http/internal/HttpMigrateRouteFetcher.ts +203 -0
  416. package/src/http/internal/LlmDataMerger.ts +73 -0
  417. package/src/index.ts +4 -0
  418. package/src/utils/ArrayUtil.ts +42 -0
  419. package/src/utils/MapUtil.ts +15 -0
  420. package/src/utils/NamingConvention.ts +205 -0
  421. package/src/utils/Singleton.ts +17 -0
  422. package/src/utils/StringUtil.ts +14 -0
  423. package/src/utils/dedent.ts +57 -0
  424. package/src/utils/index.ts +8 -0
  425. package/src/utils/internal/EndpointUtil.ts +44 -0
  426. package/src/utils/internal/JsonDescriptor.ts +70 -0
  427. package/src/utils/internal/OpenApiTypeCheckerBase.ts +822 -0
  428. package/src/utils/stringifyValidationFailure.ts +415 -0
  429. package/src/validators/LlmTypeChecker.ts +402 -0
  430. package/src/validators/OpenApiTypeChecker.ts +297 -0
  431. package/src/validators/OpenApiV3TypeChecker.ts +70 -0
  432. package/src/validators/OpenApiV3_1TypeChecker.ts +86 -0
  433. package/src/validators/OpenApiValidator.ts +94 -0
  434. package/src/validators/SwaggerV2TypeChecker.ts +71 -0
  435. package/src/validators/functional/_isBigintString.ts +8 -0
  436. package/src/validators/functional/_isFormatByte.ts +7 -0
  437. package/src/validators/functional/_isFormatDate.ts +3 -0
  438. package/src/validators/functional/_isFormatDateTime.ts +4 -0
  439. package/src/validators/functional/_isFormatDuration.ts +4 -0
  440. package/src/validators/functional/_isFormatEmail.ts +4 -0
  441. package/src/validators/functional/_isFormatHostname.ts +4 -0
  442. package/src/validators/functional/_isFormatIdnEmail.ts +4 -0
  443. package/src/validators/functional/_isFormatIdnHostname.ts +4 -0
  444. package/src/validators/functional/_isFormatIpv4.ts +4 -0
  445. package/src/validators/functional/_isFormatIpv6.ts +4 -0
  446. package/src/validators/functional/_isFormatIri.ts +3 -0
  447. package/src/validators/functional/_isFormatIriReference.ts +4 -0
  448. package/src/validators/functional/_isFormatJsonPointer.ts +3 -0
  449. package/src/validators/functional/_isFormatPassword.ts +1 -0
  450. package/src/validators/functional/_isFormatRegex.ts +8 -0
  451. package/src/validators/functional/_isFormatRelativeJsonPointer.ts +4 -0
  452. package/src/validators/functional/_isFormatTime.ts +4 -0
  453. package/src/validators/functional/_isFormatUri.ts +6 -0
  454. package/src/validators/functional/_isFormatUriReference.ts +5 -0
  455. package/src/validators/functional/_isFormatUriTemplate.ts +4 -0
  456. package/src/validators/functional/_isFormatUrl.ts +4 -0
  457. package/src/validators/functional/_isFormatUuid.ts +3 -0
  458. package/src/validators/functional/_isUniqueItems.ts +159 -0
  459. package/src/validators/index.ts +14 -0
  460. package/src/validators/internal/IOpenApiValidatorContext.ts +17 -0
  461. package/src/validators/internal/OpenApiArrayValidator.ts +49 -0
  462. package/src/validators/internal/OpenApiBooleanValidator.ts +11 -0
  463. package/src/validators/internal/OpenApiConstantValidator.ts +11 -0
  464. package/src/validators/internal/OpenApiIntegerValidator.ts +49 -0
  465. package/src/validators/internal/OpenApiNumberValidator.ts +48 -0
  466. package/src/validators/internal/OpenApiObjectValidator.ts +83 -0
  467. package/src/validators/internal/OpenApiOneOfValidator.ts +309 -0
  468. package/src/validators/internal/OpenApiSchemaNamingRule.ts +124 -0
  469. package/src/validators/internal/OpenApiStationValidator.ts +115 -0
  470. package/src/validators/internal/OpenApiStringValidator.ts +88 -0
  471. package/src/validators/internal/OpenApiTupleValidator.ts +55 -0
@@ -0,0 +1,771 @@
1
+ import { NamingConvention } from '../utils/NamingConvention.mjs';
2
+ import { JsonDescriptor } from '../utils/internal/JsonDescriptor.mjs';
3
+ import { LlmTypeChecker } from '../validators/LlmTypeChecker.mjs';
4
+ import { OpenApiTypeChecker } from '../validators/OpenApiTypeChecker.mjs';
5
+ import { OpenApiValidator } from '../validators/OpenApiValidator.mjs';
6
+ import { LlmDescriptionInverter } from './internal/LlmDescriptionInverter.mjs';
7
+ import { LlmParametersFinder } from './internal/LlmParametersComposer.mjs';
8
+ import { OpenApiConstraintShifter } from './internal/OpenApiConstraintShifter.mjs';
9
+
10
+ /**
11
+ * OpenAPI to LLM schema converter.
12
+ *
13
+ * `LlmSchemaConverter` converts OpenAPI JSON schemas to LLM-compatible
14
+ * {@link ILlmSchema} format. LLMs don't fully support JSON Schema, so this
15
+ * simplifies schemas by removing unsupported features (tuples, `const`, mixed
16
+ * unions).
17
+ *
18
+ * Main functions:
19
+ *
20
+ * - {@link parameters}: Convert object schema to {@link ILlmSchema.IParameters}
21
+ * - {@link schema}: Convert any schema to {@link ILlmSchema}
22
+ * - {@link separate}: Split parameters into LLM-fillable vs human-required
23
+ * - {@link invert}: Extract constraints from description back to schema
24
+ *
25
+ * Configuration options ({@link ILlmSchema.IConfig}):
26
+ *
27
+ * - `reference`: Allow `$ref` references (reduces tokens but may confuse LLM)
28
+ * - `strict`: OpenAI structured output mode (all properties required)
29
+ *
30
+ * @author Jeongho Nam - https://github.com/samchon
31
+ */
32
+ var LlmSchemaConverter;
33
+ (function (LlmSchemaConverter) {
34
+ /**
35
+ * Get configuration with defaults applied.
36
+ *
37
+ * @param config Partial configuration
38
+ * @returns Full configuration with defaults
39
+ */
40
+ LlmSchemaConverter.getConfig = (config) => ({
41
+ reference: config?.reference ?? true,
42
+ strict: config?.strict ?? false,
43
+ });
44
+ /* -----------------------------------------------------------
45
+ CONVERTERS
46
+ ----------------------------------------------------------- */
47
+ /**
48
+ * Convert OpenAPI object schema to LLM parameters schema.
49
+ *
50
+ * @param props.config Conversion configuration
51
+ * @param props.components OpenAPI components for reference resolution
52
+ * @param props.schema Object or reference schema to convert
53
+ * @param props.accessor Error path accessor
54
+ * @param props.refAccessor Reference path accessor
55
+ * @returns Converted parameters or error
56
+ */
57
+ LlmSchemaConverter.parameters = (props) => {
58
+ const config = LlmSchemaConverter.getConfig(props.config);
59
+ const entity = LlmParametersFinder.parameters({
60
+ ...props,
61
+ method: "LlmSchemaConverter.parameters",
62
+ });
63
+ if (entity.success === false)
64
+ return entity;
65
+ const $defs = {};
66
+ const result = transform({
67
+ ...props,
68
+ config,
69
+ $defs,
70
+ schema: entity.value,
71
+ });
72
+ if (result.success === false)
73
+ return result;
74
+ return {
75
+ success: true,
76
+ value: {
77
+ ...result.value,
78
+ additionalProperties: false,
79
+ $defs,
80
+ description: OpenApiTypeChecker.isReference(props.schema)
81
+ ? JsonDescriptor.cascade({
82
+ prefix: "#/components/schemas/",
83
+ components: props.components,
84
+ schema: {
85
+ ...props.schema,
86
+ description: result.value.description,
87
+ },
88
+ escape: true,
89
+ })
90
+ : result.value.description,
91
+ },
92
+ };
93
+ };
94
+ /**
95
+ * Convert OpenAPI schema to LLM schema.
96
+ *
97
+ * @param props.config Conversion configuration
98
+ * @param props.components OpenAPI components for reference resolution
99
+ * @param props.$defs Definition store (mutated with referenced types)
100
+ * @param props.schema Schema to convert
101
+ * @param props.accessor Error path accessor
102
+ * @param props.refAccessor Reference path accessor
103
+ * @returns Converted schema or error
104
+ */
105
+ LlmSchemaConverter.schema = (props) => transform({
106
+ config: LlmSchemaConverter.getConfig(props.config),
107
+ components: props.components,
108
+ $defs: props.$defs,
109
+ schema: props.schema,
110
+ accessor: props.accessor,
111
+ refAccessor: props.refAccessor,
112
+ });
113
+ const transform = (props) => {
114
+ // PREPARE ASSETS
115
+ const union = [];
116
+ const attribute = {
117
+ title: props.schema.title,
118
+ description: props.schema.description,
119
+ deprecated: props.schema.deprecated,
120
+ readOnly: props.schema.readOnly,
121
+ writeOnly: props.schema.writeOnly,
122
+ example: props.schema.example,
123
+ examples: props.schema.examples,
124
+ ...Object.fromEntries(Object.entries(props.schema).filter(([key, value]) => key.startsWith("x-") && value !== undefined)),
125
+ };
126
+ // VALIDADTE SCHEMA
127
+ const reasons = [];
128
+ OpenApiTypeChecker.visit({
129
+ closure: (next, accessor) => {
130
+ if (props.config.strict === true) {
131
+ // STRICT MODE VALIDATION
132
+ reasons.push(...validateStrict(next, accessor));
133
+ }
134
+ if (OpenApiTypeChecker.isTuple(next))
135
+ reasons.push({
136
+ accessor,
137
+ schema: next,
138
+ message: `LLM does not allow tuple type.`,
139
+ });
140
+ else if (OpenApiTypeChecker.isReference(next)) {
141
+ // UNABLE TO FIND MATCHED REFERENCE
142
+ const key = next.$ref.split("#/components/schemas/")[1] ??
143
+ next.$ref.split("/").at(-1);
144
+ if (props.components.schemas?.[key] === undefined)
145
+ reasons.push({
146
+ schema: next,
147
+ accessor: accessor,
148
+ message: `unable to find reference type ${JSON.stringify(key)}.`,
149
+ });
150
+ }
151
+ },
152
+ components: props.components,
153
+ schema: props.schema,
154
+ accessor: props.accessor,
155
+ refAccessor: props.refAccessor,
156
+ });
157
+ if (reasons.length > 0)
158
+ return {
159
+ success: false,
160
+ error: {
161
+ method: "LlmSchemaConverter.schema",
162
+ message: "Failed to compose LLM schema",
163
+ reasons,
164
+ },
165
+ };
166
+ const visitConstant = (input) => {
167
+ const insert = (value) => {
168
+ const matched = union.find((u) => u
169
+ ?.type === typeof value);
170
+ if (matched !== undefined) {
171
+ matched.enum ??= [];
172
+ matched.enum.push(value);
173
+ }
174
+ else
175
+ union.push({
176
+ type: typeof value,
177
+ enum: [value],
178
+ });
179
+ };
180
+ if (OpenApiTypeChecker.isConstant(input))
181
+ insert(input.const);
182
+ else if (OpenApiTypeChecker.isOneOf(input))
183
+ input.oneOf.forEach(visitConstant);
184
+ };
185
+ const visit = (input, accessor) => {
186
+ if (OpenApiTypeChecker.isOneOf(input)) {
187
+ // UNION TYPE
188
+ input.oneOf.forEach((s, i) => visit(s, `${accessor}.oneOf[${i}]`));
189
+ }
190
+ else if (OpenApiTypeChecker.isReference(input)) {
191
+ // REFERENCE TYPE
192
+ const key = input.$ref.split("#/components/schemas/")[1] ??
193
+ input.$ref.split("/").at(-1);
194
+ const target = props.components.schemas?.[key];
195
+ if (target === undefined)
196
+ return;
197
+ else if (
198
+ // KEEP THE REFERENCE TYPE
199
+ props.config.reference === true ||
200
+ OpenApiTypeChecker.isRecursiveReference({
201
+ components: props.components,
202
+ schema: input,
203
+ })) {
204
+ const out = () => {
205
+ union.push({
206
+ ...input,
207
+ $ref: `#/$defs/${key}`,
208
+ });
209
+ };
210
+ if (props.$defs[key] !== undefined)
211
+ return out();
212
+ props.$defs[key] = {};
213
+ const converted = transform({
214
+ config: props.config,
215
+ components: props.components,
216
+ $defs: props.$defs,
217
+ schema: target,
218
+ refAccessor: props.refAccessor,
219
+ accessor: `${props.refAccessor ?? "$def"}[${JSON.stringify(key)}]`,
220
+ });
221
+ if (converted.success === false)
222
+ return; // UNREACHABLE
223
+ props.$defs[key] = converted.value;
224
+ return out();
225
+ }
226
+ else {
227
+ // DISCARD THE REFERENCE TYPE
228
+ const length = union.length;
229
+ visit(target, accessor);
230
+ visitConstant(target);
231
+ if (length === union.length - 1)
232
+ union[union.length - 1] = {
233
+ ...union[union.length - 1],
234
+ description: JsonDescriptor.cascade({
235
+ prefix: "#/components/schemas/",
236
+ components: props.components,
237
+ schema: input,
238
+ escape: true,
239
+ }),
240
+ };
241
+ else
242
+ attribute.description = JsonDescriptor.cascade({
243
+ prefix: "#/components/schemas/",
244
+ components: props.components,
245
+ schema: input,
246
+ escape: true,
247
+ });
248
+ }
249
+ }
250
+ else if (OpenApiTypeChecker.isObject(input)) {
251
+ // OBJECT TYPE
252
+ const properties = Object.fromEntries(Object.entries(input.properties ?? {})
253
+ .map(([key, value]) => {
254
+ const converted = transform({
255
+ config: props.config,
256
+ components: props.components,
257
+ $defs: props.$defs,
258
+ schema: value,
259
+ refAccessor: props.refAccessor,
260
+ accessor: `${props.accessor ?? "$input.schema"}.properties[${JSON.stringify(key)}]`,
261
+ });
262
+ if (converted.success === false) {
263
+ reasons.push(...converted.error.reasons);
264
+ return [key, null];
265
+ }
266
+ return [key, converted.value];
267
+ })
268
+ .filter(([, value]) => value !== null));
269
+ if (Object.values(properties).some((v) => v === null))
270
+ return;
271
+ const additionalProperties = (() => {
272
+ if (typeof input.additionalProperties === "object" &&
273
+ input.additionalProperties !== null) {
274
+ const converted = transform({
275
+ config: props.config,
276
+ components: props.components,
277
+ $defs: props.$defs,
278
+ schema: input.additionalProperties,
279
+ refAccessor: props.refAccessor,
280
+ accessor: `${accessor}.additionalProperties`,
281
+ });
282
+ if (converted.success === false) {
283
+ reasons.push(...converted.error.reasons);
284
+ return null;
285
+ }
286
+ return converted.value;
287
+ }
288
+ return props.config.strict === true
289
+ ? false
290
+ : input.additionalProperties;
291
+ })();
292
+ if (additionalProperties === null)
293
+ return;
294
+ union.push({
295
+ ...input,
296
+ properties,
297
+ additionalProperties,
298
+ required: input.required ?? [],
299
+ description: props.config.strict === true
300
+ ? JsonDescriptor.take(input)
301
+ : input.description,
302
+ });
303
+ }
304
+ else if (OpenApiTypeChecker.isArray(input)) {
305
+ // ARRAY TYPE
306
+ const items = transform({
307
+ config: props.config,
308
+ components: props.components,
309
+ $defs: props.$defs,
310
+ schema: input.items,
311
+ refAccessor: props.refAccessor,
312
+ accessor: `${accessor}.items`,
313
+ });
314
+ if (items.success === false) {
315
+ reasons.push(...items.error.reasons);
316
+ return;
317
+ }
318
+ union.push(props.config.strict === true
319
+ ? OpenApiConstraintShifter.shiftArray({
320
+ ...input,
321
+ items: items.value,
322
+ })
323
+ : {
324
+ ...input,
325
+ items: items.value,
326
+ });
327
+ }
328
+ else if (OpenApiTypeChecker.isString(input))
329
+ union.push(props.config.strict === true
330
+ ? OpenApiConstraintShifter.shiftString({ ...input })
331
+ : input);
332
+ else if (OpenApiTypeChecker.isNumber(input) ||
333
+ OpenApiTypeChecker.isInteger(input))
334
+ union.push(props.config.strict === true
335
+ ? OpenApiConstraintShifter.shiftNumeric({ ...input })
336
+ : input);
337
+ else if (OpenApiTypeChecker.isTuple(input))
338
+ return; // UNREACHABLE
339
+ else if (OpenApiTypeChecker.isConstant(input) === false)
340
+ union.push({ ...input });
341
+ };
342
+ visitConstant(props.schema);
343
+ visit(props.schema, props.accessor ?? "$input.schema");
344
+ if (reasons.length > 0)
345
+ return {
346
+ success: false,
347
+ error: {
348
+ method: "LlmSchemaConverter.schema",
349
+ message: "Failed to compose LLM schema",
350
+ reasons,
351
+ },
352
+ };
353
+ else if (union.length === 0)
354
+ return {
355
+ // unknown type
356
+ success: true,
357
+ value: {
358
+ ...attribute,
359
+ type: undefined,
360
+ },
361
+ };
362
+ else if (union.length === 1)
363
+ return {
364
+ // single type
365
+ success: true,
366
+ value: {
367
+ ...attribute,
368
+ ...union[0],
369
+ description: props.config.strict === true &&
370
+ LlmTypeChecker.isReference(union[0])
371
+ ? undefined
372
+ : (union[0].description ?? attribute.description),
373
+ },
374
+ };
375
+ return {
376
+ success: true,
377
+ value: {
378
+ ...attribute,
379
+ anyOf: union.map((u) => ({
380
+ ...u,
381
+ description: props.config.strict === true && LlmTypeChecker.isReference(u)
382
+ ? undefined
383
+ : u.description,
384
+ })),
385
+ "x-discriminator": OpenApiTypeChecker.isOneOf(props.schema) &&
386
+ props.schema.discriminator !== undefined &&
387
+ props.schema.oneOf.length === union.length &&
388
+ union.every((e) => LlmTypeChecker.isReference(e) || LlmTypeChecker.isNull(e))
389
+ ? {
390
+ propertyName: props.schema.discriminator.propertyName,
391
+ mapping: props.schema.discriminator.mapping !== undefined
392
+ ? Object.fromEntries(Object.entries(props.schema.discriminator.mapping).map(([key, value]) => [
393
+ key,
394
+ `#/$defs/${value.split("/").at(-1)}`,
395
+ ]))
396
+ : undefined,
397
+ }
398
+ : undefined,
399
+ },
400
+ };
401
+ };
402
+ /* -----------------------------------------------------------
403
+ INVERTERS
404
+ ----------------------------------------------------------- */
405
+ /**
406
+ * Convert LLM schema back to OpenAPI schema.
407
+ *
408
+ * Restores constraint information from description tags and converts `$defs`
409
+ * references to `#/components/schemas`.
410
+ *
411
+ * @param props.components Target components (mutated with definitions)
412
+ * @param props.schema LLM schema to invert
413
+ * @param props.$defs LLM schema definitions
414
+ * @returns OpenAPI JSON schema
415
+ */
416
+ LlmSchemaConverter.invert = (props) => {
417
+ const union = [];
418
+ const attribute = {
419
+ title: props.schema.title,
420
+ description: props.schema.description,
421
+ deprecated: props.schema.deprecated,
422
+ readOnly: props.schema.readOnly,
423
+ writeOnly: props.schema.writeOnly,
424
+ example: props.schema.example,
425
+ examples: props.schema.examples,
426
+ ...Object.fromEntries(Object.entries(props.schema).filter(([key, value]) => key.startsWith("x-") && value !== undefined)),
427
+ };
428
+ const next = (schema) => LlmSchemaConverter.invert({
429
+ components: props.components,
430
+ $defs: props.$defs,
431
+ schema,
432
+ });
433
+ const visit = (schema) => {
434
+ if (LlmTypeChecker.isArray(schema))
435
+ union.push({
436
+ ...schema,
437
+ ...LlmDescriptionInverter.array(schema.description),
438
+ items: next(schema.items),
439
+ });
440
+ else if (LlmTypeChecker.isObject(schema))
441
+ union.push({
442
+ ...schema,
443
+ properties: Object.fromEntries(Object.entries(schema.properties).map(([key, value]) => [
444
+ key,
445
+ next(value),
446
+ ])),
447
+ additionalProperties: typeof schema.additionalProperties === "object" &&
448
+ schema.additionalProperties !== null
449
+ ? next(schema.additionalProperties)
450
+ : schema.additionalProperties,
451
+ });
452
+ else if (LlmTypeChecker.isAnyOf(schema))
453
+ schema.anyOf.forEach(visit);
454
+ else if (LlmTypeChecker.isReference(schema)) {
455
+ const key = schema.$ref.split("#/$defs/")[1] ?? schema.$ref.split("/").at(-1);
456
+ if (props.components.schemas?.[key] === undefined) {
457
+ props.components.schemas ??= {};
458
+ props.components.schemas[key] = {};
459
+ props.components.schemas[key] = next(props.$defs[key] ?? {});
460
+ }
461
+ union.push({
462
+ ...schema,
463
+ $ref: `#/components/schemas/${key}`,
464
+ });
465
+ }
466
+ else if (LlmTypeChecker.isBoolean(schema))
467
+ if (!!schema.enum?.length)
468
+ schema.enum.forEach((v) => union.push({
469
+ const: v,
470
+ }));
471
+ else
472
+ union.push(schema);
473
+ else if (LlmTypeChecker.isInteger(schema) ||
474
+ LlmTypeChecker.isNumber(schema))
475
+ if (!!schema.enum?.length)
476
+ schema.enum.forEach((v) => union.push({
477
+ const: v,
478
+ }));
479
+ else
480
+ union.push({
481
+ ...schema,
482
+ ...LlmDescriptionInverter.numeric(schema.description),
483
+ ...{ enum: undefined },
484
+ });
485
+ else if (LlmTypeChecker.isString(schema))
486
+ if (!!schema.enum?.length)
487
+ schema.enum.forEach((v) => union.push({
488
+ const: v,
489
+ }));
490
+ else
491
+ union.push({
492
+ ...schema,
493
+ ...LlmDescriptionInverter.string(schema.description),
494
+ ...{ enum: undefined },
495
+ });
496
+ else
497
+ union.push({
498
+ ...schema,
499
+ });
500
+ };
501
+ visit(props.schema);
502
+ return {
503
+ ...attribute,
504
+ ...(union.length === 0
505
+ ? { type: undefined }
506
+ : union.length === 1
507
+ ? { ...union[0] }
508
+ : {
509
+ oneOf: union.map((u) => ({ ...u, nullable: undefined })),
510
+ discriminator: LlmTypeChecker.isAnyOf(props.schema) &&
511
+ props.schema["x-discriminator"] !== undefined
512
+ ? {
513
+ propertyName: props.schema["x-discriminator"].propertyName,
514
+ mapping: props.schema["x-discriminator"].mapping !== undefined
515
+ ? Object.fromEntries(Object.entries(props.schema["x-discriminator"].mapping).map(([key, value]) => [
516
+ key,
517
+ `#/components/schemas/${value.split("/").at(-1)}`,
518
+ ]))
519
+ : undefined,
520
+ }
521
+ : undefined,
522
+ }),
523
+ };
524
+ };
525
+ /* -----------------------------------------------------------
526
+ SEPARATORS
527
+ ----------------------------------------------------------- */
528
+ /**
529
+ * Separate parameters into LLM and human parts.
530
+ *
531
+ * Splits parameters based on predicate (human-side if true). Creates separate
532
+ * schemas for LLM-fillable and human-required fields.
533
+ *
534
+ * @param props.parameters Parameters schema to separate
535
+ * @param props.predicate Returns true for human-side properties
536
+ * @param props.convention Key naming convention for separated types
537
+ * @param props.equals Whether to use strict equality validation
538
+ * @returns Separated LLM and human parameter schemas
539
+ */
540
+ LlmSchemaConverter.separate = (props) => {
541
+ const convention = props.convention ??
542
+ ((key, type) => `${key}.${NamingConvention.capitalize(type)}`);
543
+ const [llm, human] = separateObject({
544
+ predicate: props.predicate,
545
+ convention,
546
+ $defs: props.parameters.$defs,
547
+ schema: props.parameters,
548
+ });
549
+ if (llm === null || human === null)
550
+ return {
551
+ llm: llm ?? {
552
+ type: "object",
553
+ properties: {},
554
+ required: [],
555
+ additionalProperties: false,
556
+ $defs: {},
557
+ },
558
+ human: human,
559
+ };
560
+ const output = {
561
+ llm: {
562
+ ...llm,
563
+ $defs: Object.fromEntries(Object.entries(props.parameters.$defs).filter(([key]) => key.endsWith(".Llm"))),
564
+ additionalProperties: false,
565
+ },
566
+ human: {
567
+ ...human,
568
+ $defs: Object.fromEntries(Object.entries(props.parameters.$defs).filter(([key]) => key.endsWith(".Human"))),
569
+ additionalProperties: false,
570
+ },
571
+ };
572
+ for (const key of Object.keys(props.parameters.$defs))
573
+ if (key.endsWith(".Llm") === false && key.endsWith(".Human") === false)
574
+ delete props.parameters.$defs[key];
575
+ if (Object.keys(output.llm.properties).length !== 0) {
576
+ const components = {};
577
+ output.validate = OpenApiValidator.create({
578
+ components,
579
+ schema: LlmSchemaConverter.invert({
580
+ components,
581
+ schema: output.llm,
582
+ $defs: output.llm.$defs,
583
+ }),
584
+ required: true,
585
+ equals: props.equals,
586
+ });
587
+ }
588
+ return output;
589
+ };
590
+ const separateStation = (props) => {
591
+ if (props.predicate(props.schema) === true)
592
+ return [null, props.schema];
593
+ else if (LlmTypeChecker.isUnknown(props.schema) ||
594
+ LlmTypeChecker.isAnyOf(props.schema))
595
+ return [props.schema, null];
596
+ else if (LlmTypeChecker.isObject(props.schema))
597
+ return separateObject({
598
+ predicate: props.predicate,
599
+ convention: props.convention,
600
+ $defs: props.$defs,
601
+ schema: props.schema,
602
+ });
603
+ else if (LlmTypeChecker.isArray(props.schema))
604
+ return separateArray({
605
+ predicate: props.predicate,
606
+ convention: props.convention,
607
+ $defs: props.$defs,
608
+ schema: props.schema,
609
+ });
610
+ else if (LlmTypeChecker.isReference(props.schema))
611
+ return separateReference({
612
+ predicate: props.predicate,
613
+ convention: props.convention,
614
+ $defs: props.$defs,
615
+ schema: props.schema,
616
+ });
617
+ return [props.schema, null];
618
+ };
619
+ const separateArray = (props) => {
620
+ const [x, y] = separateStation({
621
+ predicate: props.predicate,
622
+ convention: props.convention,
623
+ $defs: props.$defs,
624
+ schema: props.schema.items,
625
+ });
626
+ return [
627
+ x !== null
628
+ ? {
629
+ ...props.schema,
630
+ items: x,
631
+ }
632
+ : null,
633
+ y !== null
634
+ ? {
635
+ ...props.schema,
636
+ items: y,
637
+ }
638
+ : null,
639
+ ];
640
+ };
641
+ const separateObject = (props) => {
642
+ // EMPTY OBJECT
643
+ if (Object.keys(props.schema.properties ?? {}).length === 0 &&
644
+ !!props.schema.additionalProperties === false)
645
+ return [props.schema, null];
646
+ const llm = {
647
+ ...props.schema,
648
+ properties: {},
649
+ additionalProperties: props.schema.additionalProperties,
650
+ };
651
+ const human = {
652
+ ...props.schema,
653
+ properties: {},
654
+ };
655
+ for (const [key, value] of Object.entries(props.schema.properties ?? {})) {
656
+ const [x, y] = separateStation({
657
+ predicate: props.predicate,
658
+ convention: props.convention,
659
+ $defs: props.$defs,
660
+ schema: value,
661
+ });
662
+ if (x !== null)
663
+ llm.properties[key] = x;
664
+ if (y !== null)
665
+ human.properties[key] = y;
666
+ }
667
+ if (typeof props.schema.additionalProperties === "object" &&
668
+ props.schema.additionalProperties !== null) {
669
+ const [dx, dy] = separateStation({
670
+ predicate: props.predicate,
671
+ convention: props.convention,
672
+ $defs: props.$defs,
673
+ schema: props.schema.additionalProperties,
674
+ });
675
+ llm.additionalProperties = dx ?? false;
676
+ human.additionalProperties = dy ?? false;
677
+ }
678
+ return [
679
+ !!Object.keys(llm.properties).length || !!llm.additionalProperties
680
+ ? shrinkRequired(llm)
681
+ : null,
682
+ !!Object.keys(human.properties).length || human.additionalProperties
683
+ ? shrinkRequired(human)
684
+ : null,
685
+ ];
686
+ };
687
+ const separateReference = (props) => {
688
+ const key = props.schema.$ref.split("#/$defs/")[1] ??
689
+ props.schema.$ref.split("/").at(-1);
690
+ const humanKey = props.convention(key, "human");
691
+ const llmKey = props.convention(key, "llm");
692
+ // FIND EXISTING
693
+ if (props.$defs?.[humanKey] || props.$defs?.[llmKey])
694
+ return [
695
+ props.$defs?.[llmKey]
696
+ ? {
697
+ ...props.schema,
698
+ $ref: `#/$defs/${llmKey}`,
699
+ }
700
+ : null,
701
+ props.$defs?.[humanKey]
702
+ ? {
703
+ ...props.schema,
704
+ $ref: `#/$defs/${humanKey}`,
705
+ }
706
+ : null,
707
+ ];
708
+ // PRE-ASSIGNMENT
709
+ props.$defs[llmKey] = {};
710
+ props.$defs[humanKey] = {};
711
+ // DO COMPOSE
712
+ const schema = props.$defs?.[key];
713
+ const [llm, human] = separateStation({
714
+ predicate: props.predicate,
715
+ convention: props.convention,
716
+ $defs: props.$defs,
717
+ schema,
718
+ });
719
+ if (llm !== null)
720
+ Object.assign(props.$defs[llmKey], llm);
721
+ if (human !== null)
722
+ Object.assign(props.$defs[humanKey], human);
723
+ // ONLY ONE
724
+ if (llm === null || human === null) {
725
+ delete props.$defs[llmKey];
726
+ delete props.$defs[humanKey];
727
+ return llm === null ? [null, props.schema] : [props.schema, null];
728
+ }
729
+ // BOTH OF THEM
730
+ return [
731
+ llm !== null
732
+ ? {
733
+ ...props.schema,
734
+ $ref: `#/$defs/${llmKey}`,
735
+ }
736
+ : null,
737
+ human !== null
738
+ ? {
739
+ ...props.schema,
740
+ $ref: `#/$defs/${humanKey}`,
741
+ }
742
+ : null,
743
+ ];
744
+ };
745
+ const shrinkRequired = (s) => {
746
+ s.required = s.required.filter((key) => s.properties?.[key] !== undefined);
747
+ return s;
748
+ };
749
+ })(LlmSchemaConverter || (LlmSchemaConverter = {}));
750
+ const validateStrict = (schema, accessor) => {
751
+ const reasons = [];
752
+ if (OpenApiTypeChecker.isObject(schema)) {
753
+ if (!!schema.additionalProperties)
754
+ reasons.push({
755
+ schema: schema,
756
+ accessor: `${accessor}.additionalProperties`,
757
+ message: "LLM does not allow additionalProperties in strict mode, the dynamic key typed object.",
758
+ });
759
+ for (const key of Object.keys(schema.properties ?? {}))
760
+ if (schema.required?.includes(key) === false)
761
+ reasons.push({
762
+ schema: schema,
763
+ accessor: `${accessor}.properties.${key}`,
764
+ message: "LLM does not allow optional properties in strict mode.",
765
+ });
766
+ }
767
+ return reasons;
768
+ };
769
+
770
+ export { LlmSchemaConverter };
771
+ //# sourceMappingURL=LlmSchemaConverter.mjs.map