@prometheus-ai/ai 0.5.0

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 (369) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +1184 -0
  3. package/dist/types/api-registry.d.ts +30 -0
  4. package/dist/types/auth-broker/client.d.ts +66 -0
  5. package/dist/types/auth-broker/index.d.ts +6 -0
  6. package/dist/types/auth-broker/refresher.d.ts +25 -0
  7. package/dist/types/auth-broker/remote-store.d.ts +101 -0
  8. package/dist/types/auth-broker/server.d.ts +32 -0
  9. package/dist/types/auth-broker/snapshot-cache.d.ts +17 -0
  10. package/dist/types/auth-broker/types.d.ts +107 -0
  11. package/dist/types/auth-broker/wire-schemas.d.ts +412 -0
  12. package/dist/types/auth-gateway/http.d.ts +39 -0
  13. package/dist/types/auth-gateway/index.d.ts +3 -0
  14. package/dist/types/auth-gateway/server.d.ts +36 -0
  15. package/dist/types/auth-gateway/types.d.ts +117 -0
  16. package/dist/types/auth-storage.d.ts +762 -0
  17. package/dist/types/index.d.ts +49 -0
  18. package/dist/types/model-cache.d.ts +17 -0
  19. package/dist/types/model-manager.d.ts +64 -0
  20. package/dist/types/model-thinking.d.ts +100 -0
  21. package/dist/types/models.d.ts +12 -0
  22. package/dist/types/provider-details.d.ts +24 -0
  23. package/dist/types/provider-models/bundled-references.d.ts +4 -0
  24. package/dist/types/provider-models/descriptors.d.ts +50 -0
  25. package/dist/types/provider-models/google.d.ts +24 -0
  26. package/dist/types/provider-models/index.d.ts +5 -0
  27. package/dist/types/provider-models/ollama.d.ts +7 -0
  28. package/dist/types/provider-models/openai-compat.d.ts +323 -0
  29. package/dist/types/provider-models/special.d.ts +16 -0
  30. package/dist/types/providers/amazon-bedrock.d.ts +38 -0
  31. package/dist/types/providers/anthropic-client.d.ts +99 -0
  32. package/dist/types/providers/anthropic-messages-server-schema.d.ts +465 -0
  33. package/dist/types/providers/anthropic-messages-server.d.ts +17 -0
  34. package/dist/types/providers/anthropic-wire.d.ts +262 -0
  35. package/dist/types/providers/anthropic.d.ts +206 -0
  36. package/dist/types/providers/aws-credentials.d.ts +43 -0
  37. package/dist/types/providers/aws-eventstream.d.ts +38 -0
  38. package/dist/types/providers/aws-sigv4.d.ts +55 -0
  39. package/dist/types/providers/azure-openai-responses.d.ts +15 -0
  40. package/dist/types/providers/cursor/gen/agent_pb.d.ts +13022 -0
  41. package/dist/types/providers/cursor.d.ts +43 -0
  42. package/dist/types/providers/error-message.d.ts +27 -0
  43. package/dist/types/providers/github-copilot-headers.d.ts +40 -0
  44. package/dist/types/providers/gitlab-duo.d.ts +27 -0
  45. package/dist/types/providers/google-auth.d.ts +24 -0
  46. package/dist/types/providers/google-gemini-cli.d.ts +81 -0
  47. package/dist/types/providers/google-gemini-headers.d.ts +18 -0
  48. package/dist/types/providers/google-shared.d.ts +171 -0
  49. package/dist/types/providers/google-types.d.ts +138 -0
  50. package/dist/types/providers/google-vertex.d.ts +7 -0
  51. package/dist/types/providers/google.d.ts +4 -0
  52. package/dist/types/providers/grammar.d.ts +1 -0
  53. package/dist/types/providers/kimi.d.ts +27 -0
  54. package/dist/types/providers/mock.d.ts +173 -0
  55. package/dist/types/providers/ollama.d.ts +6 -0
  56. package/dist/types/providers/openai-anthropic-shim.d.ts +31 -0
  57. package/dist/types/providers/openai-chat-server-schema.d.ts +817 -0
  58. package/dist/types/providers/openai-chat-server.d.ts +16 -0
  59. package/dist/types/providers/openai-codex/constants.d.ts +26 -0
  60. package/dist/types/providers/openai-codex/request-transformer.d.ts +49 -0
  61. package/dist/types/providers/openai-codex/response-handler.d.ts +17 -0
  62. package/dist/types/providers/openai-codex-responses.d.ts +67 -0
  63. package/dist/types/providers/openai-completions-compat.d.ts +27 -0
  64. package/dist/types/providers/openai-completions.d.ts +54 -0
  65. package/dist/types/providers/openai-responses-server-schema.d.ts +392 -0
  66. package/dist/types/providers/openai-responses-server.d.ts +17 -0
  67. package/dist/types/providers/openai-responses-shared.d.ts +105 -0
  68. package/dist/types/providers/openai-responses.d.ts +66 -0
  69. package/dist/types/providers/prometheus-native-client.d.ts +13 -0
  70. package/dist/types/providers/prometheus-native-server.d.ts +68 -0
  71. package/dist/types/providers/register-builtins.d.ts +31 -0
  72. package/dist/types/providers/synthetic.d.ts +26 -0
  73. package/dist/types/providers/transform-messages.d.ts +12 -0
  74. package/dist/types/providers/vision-guard.d.ts +20 -0
  75. package/dist/types/providers/xai-responses.d.ts +23 -0
  76. package/dist/types/rate-limit-utils.d.ts +19 -0
  77. package/dist/types/stream.d.ts +28 -0
  78. package/dist/types/types.d.ts +819 -0
  79. package/dist/types/usage/claude.d.ts +4 -0
  80. package/dist/types/usage/gemini.d.ts +2 -0
  81. package/dist/types/usage/github-copilot.d.ts +7 -0
  82. package/dist/types/usage/google-antigravity.d.ts +2 -0
  83. package/dist/types/usage/kimi.d.ts +2 -0
  84. package/dist/types/usage/minimax-code.d.ts +2 -0
  85. package/dist/types/usage/openai-codex.d.ts +3 -0
  86. package/dist/types/usage/shared.d.ts +1 -0
  87. package/dist/types/usage/zai.d.ts +2 -0
  88. package/dist/types/usage.d.ts +260 -0
  89. package/dist/types/utils/abort.d.ts +19 -0
  90. package/dist/types/utils/abortable-iterator.d.ts +4 -0
  91. package/dist/types/utils/anthropic-auth.d.ts +35 -0
  92. package/dist/types/utils/discovery/antigravity.d.ts +61 -0
  93. package/dist/types/utils/discovery/codex.d.ts +38 -0
  94. package/dist/types/utils/discovery/cursor.d.ts +23 -0
  95. package/dist/types/utils/discovery/gemini.d.ts +25 -0
  96. package/dist/types/utils/discovery/index.d.ts +4 -0
  97. package/dist/types/utils/discovery/openai-compatible.d.ts +72 -0
  98. package/dist/types/utils/event-stream.d.ts +28 -0
  99. package/dist/types/utils/fireworks-model-id.d.ts +10 -0
  100. package/dist/types/utils/foundry.d.ts +1 -0
  101. package/dist/types/utils/http-inspector.d.ts +31 -0
  102. package/dist/types/utils/idle-iterator.d.ts +78 -0
  103. package/dist/types/utils/json-parse.d.ts +37 -0
  104. package/dist/types/utils/oauth/__tests__/xai-oauth.test.d.ts +1 -0
  105. package/dist/types/utils/oauth/alibaba-coding-plan.d.ts +18 -0
  106. package/dist/types/utils/oauth/anthropic.d.ts +22 -0
  107. package/dist/types/utils/oauth/api-key-login.d.ts +35 -0
  108. package/dist/types/utils/oauth/api-key-validation.d.ts +27 -0
  109. package/dist/types/utils/oauth/callback-server.d.ts +57 -0
  110. package/dist/types/utils/oauth/cerebras.d.ts +1 -0
  111. package/dist/types/utils/oauth/cloudflare-ai-gateway.d.ts +18 -0
  112. package/dist/types/utils/oauth/cursor.d.ts +15 -0
  113. package/dist/types/utils/oauth/deepseek.d.ts +10 -0
  114. package/dist/types/utils/oauth/firepass.d.ts +1 -0
  115. package/dist/types/utils/oauth/fireworks.d.ts +1 -0
  116. package/dist/types/utils/oauth/github-copilot.d.ts +38 -0
  117. package/dist/types/utils/oauth/gitlab-duo.d.ts +3 -0
  118. package/dist/types/utils/oauth/google-antigravity.d.ts +11 -0
  119. package/dist/types/utils/oauth/google-gemini-cli.d.ts +10 -0
  120. package/dist/types/utils/oauth/google-oauth-shared.d.ts +28 -0
  121. package/dist/types/utils/oauth/huggingface.d.ts +19 -0
  122. package/dist/types/utils/oauth/index.d.ts +38 -0
  123. package/dist/types/utils/oauth/kagi.d.ts +17 -0
  124. package/dist/types/utils/oauth/kilo.d.ts +5 -0
  125. package/dist/types/utils/oauth/kimi.d.ts +21 -0
  126. package/dist/types/utils/oauth/litellm.d.ts +18 -0
  127. package/dist/types/utils/oauth/lm-studio.d.ts +17 -0
  128. package/dist/types/utils/oauth/minimax-code.d.ts +28 -0
  129. package/dist/types/utils/oauth/moonshot.d.ts +1 -0
  130. package/dist/types/utils/oauth/nanogpt.d.ts +1 -0
  131. package/dist/types/utils/oauth/nvidia.d.ts +18 -0
  132. package/dist/types/utils/oauth/ollama-cloud.d.ts +2 -0
  133. package/dist/types/utils/oauth/ollama.d.ts +18 -0
  134. package/dist/types/utils/oauth/openai-codex.d.ts +21 -0
  135. package/dist/types/utils/oauth/opencode.d.ts +18 -0
  136. package/dist/types/utils/oauth/openrouter.d.ts +1 -0
  137. package/dist/types/utils/oauth/parallel.d.ts +17 -0
  138. package/dist/types/utils/oauth/perplexity.d.ts +9 -0
  139. package/dist/types/utils/oauth/pkce.d.ts +8 -0
  140. package/dist/types/utils/oauth/qianfan.d.ts +17 -0
  141. package/dist/types/utils/oauth/qwen-portal.d.ts +19 -0
  142. package/dist/types/utils/oauth/synthetic.d.ts +1 -0
  143. package/dist/types/utils/oauth/tavily.d.ts +17 -0
  144. package/dist/types/utils/oauth/together.d.ts +1 -0
  145. package/dist/types/utils/oauth/types.d.ts +44 -0
  146. package/dist/types/utils/oauth/venice.d.ts +18 -0
  147. package/dist/types/utils/oauth/vercel-ai-gateway.d.ts +18 -0
  148. package/dist/types/utils/oauth/vllm.d.ts +16 -0
  149. package/dist/types/utils/oauth/wafer.d.ts +2 -0
  150. package/dist/types/utils/oauth/xai-oauth.d.ts +60 -0
  151. package/dist/types/utils/oauth/xiaomi.d.ts +25 -0
  152. package/dist/types/utils/oauth/zai.d.ts +18 -0
  153. package/dist/types/utils/oauth/zenmux.d.ts +1 -0
  154. package/dist/types/utils/oauth/zhipu.d.ts +18 -0
  155. package/dist/types/utils/overflow.d.ts +54 -0
  156. package/dist/types/utils/parse-bind.d.ts +23 -0
  157. package/dist/types/utils/provider-response.d.ts +3 -0
  158. package/dist/types/utils/request-debug.d.ts +29 -0
  159. package/dist/types/utils/retry-after.d.ts +3 -0
  160. package/dist/types/utils/retry.d.ts +26 -0
  161. package/dist/types/utils/schema/adapt.d.ts +24 -0
  162. package/dist/types/utils/schema/compatibility.d.ts +30 -0
  163. package/dist/types/utils/schema/dereference.d.ts +11 -0
  164. package/dist/types/utils/schema/draft.d.ts +10 -0
  165. package/dist/types/utils/schema/equality.d.ts +4 -0
  166. package/dist/types/utils/schema/fields.d.ts +49 -0
  167. package/dist/types/utils/schema/index.d.ts +13 -0
  168. package/dist/types/utils/schema/json-schema-validator.d.ts +12 -0
  169. package/dist/types/utils/schema/meta-validator.d.ts +2 -0
  170. package/dist/types/utils/schema/normalize.d.ts +93 -0
  171. package/dist/types/utils/schema/spill.d.ts +8 -0
  172. package/dist/types/utils/schema/stamps.d.ts +25 -0
  173. package/dist/types/utils/schema/types.d.ts +4 -0
  174. package/dist/types/utils/schema/wire.d.ts +53 -0
  175. package/dist/types/utils/schema/zod-decontaminate.d.ts +31 -0
  176. package/dist/types/utils/sdk-stream-timeout.d.ts +33 -0
  177. package/dist/types/utils/sse-debug.d.ts +10 -0
  178. package/dist/types/utils/stream-markup-healing.d.ts +80 -0
  179. package/dist/types/utils/tool-choice.d.ts +50 -0
  180. package/dist/types/utils/validation.d.ts +17 -0
  181. package/dist/types/utils.d.ts +28 -0
  182. package/package.json +142 -0
  183. package/src/api-registry.ts +96 -0
  184. package/src/auth-broker/client.ts +358 -0
  185. package/src/auth-broker/index.ts +6 -0
  186. package/src/auth-broker/refresher.ts +117 -0
  187. package/src/auth-broker/remote-store.ts +637 -0
  188. package/src/auth-broker/server.ts +644 -0
  189. package/src/auth-broker/snapshot-cache.ts +174 -0
  190. package/src/auth-broker/types.ts +130 -0
  191. package/src/auth-broker/wire-schemas.ts +200 -0
  192. package/src/auth-gateway/http.ts +194 -0
  193. package/src/auth-gateway/index.ts +3 -0
  194. package/src/auth-gateway/server.ts +822 -0
  195. package/src/auth-gateway/types.ts +143 -0
  196. package/src/auth-storage.ts +4608 -0
  197. package/src/index.ts +54 -0
  198. package/src/model-cache.ts +129 -0
  199. package/src/model-manager.ts +469 -0
  200. package/src/model-thinking.ts +756 -0
  201. package/src/models.json +60287 -0
  202. package/src/models.json.d.ts +9 -0
  203. package/src/models.ts +56 -0
  204. package/src/prompts/turn-aborted-guidance.md +4 -0
  205. package/src/provider-details.ts +90 -0
  206. package/src/provider-models/bundled-references.ts +38 -0
  207. package/src/provider-models/descriptors.ts +364 -0
  208. package/src/provider-models/google.ts +88 -0
  209. package/src/provider-models/index.ts +5 -0
  210. package/src/provider-models/ollama.ts +153 -0
  211. package/src/provider-models/openai-compat.ts +2904 -0
  212. package/src/provider-models/special.ts +67 -0
  213. package/src/providers/amazon-bedrock.ts +873 -0
  214. package/src/providers/anthropic-client.ts +318 -0
  215. package/src/providers/anthropic-messages-server-schema.ts +243 -0
  216. package/src/providers/anthropic-messages-server.ts +681 -0
  217. package/src/providers/anthropic-wire.ts +268 -0
  218. package/src/providers/anthropic.ts +3106 -0
  219. package/src/providers/aws-credentials.ts +501 -0
  220. package/src/providers/aws-eventstream.ts +185 -0
  221. package/src/providers/aws-sigv4.ts +218 -0
  222. package/src/providers/azure-openai-responses.ts +361 -0
  223. package/src/providers/cursor/gen/agent_pb.ts +15274 -0
  224. package/src/providers/cursor/proto/agent.proto +3526 -0
  225. package/src/providers/cursor/proto/buf.gen.yaml +6 -0
  226. package/src/providers/cursor/proto/buf.yaml +17 -0
  227. package/src/providers/cursor.ts +2621 -0
  228. package/src/providers/error-message.ts +21 -0
  229. package/src/providers/github-copilot-headers.ts +140 -0
  230. package/src/providers/gitlab-duo.ts +372 -0
  231. package/src/providers/google-auth.ts +252 -0
  232. package/src/providers/google-gemini-cli.ts +809 -0
  233. package/src/providers/google-gemini-headers.ts +41 -0
  234. package/src/providers/google-shared.ts +917 -0
  235. package/src/providers/google-types.ts +167 -0
  236. package/src/providers/google-vertex.ts +91 -0
  237. package/src/providers/google.ts +41 -0
  238. package/src/providers/grammar.ts +70 -0
  239. package/src/providers/kimi.ts +52 -0
  240. package/src/providers/mock.ts +496 -0
  241. package/src/providers/ollama.ts +644 -0
  242. package/src/providers/openai-anthropic-shim.ts +138 -0
  243. package/src/providers/openai-chat-server-schema.ts +252 -0
  244. package/src/providers/openai-chat-server.ts +647 -0
  245. package/src/providers/openai-codex/constants.ts +43 -0
  246. package/src/providers/openai-codex/request-transformer.ts +161 -0
  247. package/src/providers/openai-codex/response-handler.ts +81 -0
  248. package/src/providers/openai-codex-responses.ts +3027 -0
  249. package/src/providers/openai-completions-compat.ts +320 -0
  250. package/src/providers/openai-completions.ts +2002 -0
  251. package/src/providers/openai-responses-server-schema.ts +290 -0
  252. package/src/providers/openai-responses-server.ts +1183 -0
  253. package/src/providers/openai-responses-shared.ts +956 -0
  254. package/src/providers/openai-responses.ts +679 -0
  255. package/src/providers/prometheus-native-client.ts +228 -0
  256. package/src/providers/prometheus-native-server.ts +212 -0
  257. package/src/providers/register-builtins.ts +457 -0
  258. package/src/providers/synthetic.ts +50 -0
  259. package/src/providers/transform-messages.ts +382 -0
  260. package/src/providers/vision-guard.ts +52 -0
  261. package/src/providers/xai-responses.ts +82 -0
  262. package/src/rate-limit-utils.ts +91 -0
  263. package/src/stream.ts +1068 -0
  264. package/src/types.ts +965 -0
  265. package/src/usage/claude.ts +482 -0
  266. package/src/usage/gemini.ts +250 -0
  267. package/src/usage/github-copilot.ts +421 -0
  268. package/src/usage/google-antigravity.ts +201 -0
  269. package/src/usage/kimi.ts +271 -0
  270. package/src/usage/minimax-code.ts +31 -0
  271. package/src/usage/openai-codex.ts +503 -0
  272. package/src/usage/shared.ts +10 -0
  273. package/src/usage/zai.ts +247 -0
  274. package/src/usage.ts +185 -0
  275. package/src/utils/abort.ts +51 -0
  276. package/src/utils/abortable-iterator.ts +69 -0
  277. package/src/utils/anthropic-auth.ts +93 -0
  278. package/src/utils/discovery/antigravity.ts +261 -0
  279. package/src/utils/discovery/codex.ts +371 -0
  280. package/src/utils/discovery/cursor.ts +306 -0
  281. package/src/utils/discovery/gemini.ts +248 -0
  282. package/src/utils/discovery/index.ts +4 -0
  283. package/src/utils/discovery/openai-compatible.ts +224 -0
  284. package/src/utils/event-stream.ts +142 -0
  285. package/src/utils/fireworks-model-id.ts +30 -0
  286. package/src/utils/foundry.ts +8 -0
  287. package/src/utils/http-inspector.ts +176 -0
  288. package/src/utils/idle-iterator.ts +273 -0
  289. package/src/utils/json-parse.ts +182 -0
  290. package/src/utils/oauth/__tests__/xai-oauth.test.ts +107 -0
  291. package/src/utils/oauth/alibaba-coding-plan.ts +59 -0
  292. package/src/utils/oauth/anthropic.ts +273 -0
  293. package/src/utils/oauth/api-key-login.ts +87 -0
  294. package/src/utils/oauth/api-key-validation.ts +92 -0
  295. package/src/utils/oauth/callback-server.ts +276 -0
  296. package/src/utils/oauth/cerebras.ts +16 -0
  297. package/src/utils/oauth/cloudflare-ai-gateway.ts +48 -0
  298. package/src/utils/oauth/cursor.ts +157 -0
  299. package/src/utils/oauth/deepseek.ts +53 -0
  300. package/src/utils/oauth/firepass.ts +24 -0
  301. package/src/utils/oauth/fireworks.ts +15 -0
  302. package/src/utils/oauth/github-copilot.ts +362 -0
  303. package/src/utils/oauth/gitlab-duo.ts +123 -0
  304. package/src/utils/oauth/google-antigravity.ts +200 -0
  305. package/src/utils/oauth/google-gemini-cli.ts +256 -0
  306. package/src/utils/oauth/google-oauth-shared.ts +110 -0
  307. package/src/utils/oauth/huggingface.ts +62 -0
  308. package/src/utils/oauth/index.ts +502 -0
  309. package/src/utils/oauth/kagi.ts +47 -0
  310. package/src/utils/oauth/kilo.ts +87 -0
  311. package/src/utils/oauth/kimi.ts +254 -0
  312. package/src/utils/oauth/litellm.ts +47 -0
  313. package/src/utils/oauth/lm-studio.ts +38 -0
  314. package/src/utils/oauth/minimax-code.ts +80 -0
  315. package/src/utils/oauth/moonshot.ts +23 -0
  316. package/src/utils/oauth/nanogpt.ts +15 -0
  317. package/src/utils/oauth/nvidia.ts +70 -0
  318. package/src/utils/oauth/oauth.html +199 -0
  319. package/src/utils/oauth/ollama-cloud.ts +28 -0
  320. package/src/utils/oauth/ollama.ts +47 -0
  321. package/src/utils/oauth/openai-codex.ts +299 -0
  322. package/src/utils/oauth/opencode.ts +49 -0
  323. package/src/utils/oauth/openrouter.ts +20 -0
  324. package/src/utils/oauth/parallel.ts +46 -0
  325. package/src/utils/oauth/perplexity.ts +206 -0
  326. package/src/utils/oauth/pkce.ts +18 -0
  327. package/src/utils/oauth/qianfan.ts +58 -0
  328. package/src/utils/oauth/qwen-portal.ts +60 -0
  329. package/src/utils/oauth/synthetic.ts +15 -0
  330. package/src/utils/oauth/tavily.ts +46 -0
  331. package/src/utils/oauth/together.ts +16 -0
  332. package/src/utils/oauth/types.ts +102 -0
  333. package/src/utils/oauth/venice.ts +59 -0
  334. package/src/utils/oauth/vercel-ai-gateway.ts +47 -0
  335. package/src/utils/oauth/vllm.ts +40 -0
  336. package/src/utils/oauth/wafer.ts +50 -0
  337. package/src/utils/oauth/xai-oauth.ts +342 -0
  338. package/src/utils/oauth/xiaomi.ts +194 -0
  339. package/src/utils/oauth/zai.ts +60 -0
  340. package/src/utils/oauth/zenmux.ts +15 -0
  341. package/src/utils/oauth/zhipu.ts +60 -0
  342. package/src/utils/overflow.ts +137 -0
  343. package/src/utils/parse-bind.ts +54 -0
  344. package/src/utils/provider-response.ts +30 -0
  345. package/src/utils/request-debug.ts +336 -0
  346. package/src/utils/retry-after.ts +110 -0
  347. package/src/utils/retry.ts +54 -0
  348. package/src/utils/schema/CONSTRAINTS.md +164 -0
  349. package/src/utils/schema/adapt.ts +36 -0
  350. package/src/utils/schema/compatibility.ts +435 -0
  351. package/src/utils/schema/dereference.ts +98 -0
  352. package/src/utils/schema/draft.ts +341 -0
  353. package/src/utils/schema/equality.ts +97 -0
  354. package/src/utils/schema/fields.ts +191 -0
  355. package/src/utils/schema/index.ts +13 -0
  356. package/src/utils/schema/json-schema-validator.ts +577 -0
  357. package/src/utils/schema/meta-validator.ts +167 -0
  358. package/src/utils/schema/normalize.ts +1588 -0
  359. package/src/utils/schema/spill.ts +43 -0
  360. package/src/utils/schema/stamps.ts +97 -0
  361. package/src/utils/schema/types.ts +10 -0
  362. package/src/utils/schema/wire.ts +293 -0
  363. package/src/utils/schema/zod-decontaminate.ts +331 -0
  364. package/src/utils/sdk-stream-timeout.ts +43 -0
  365. package/src/utils/sse-debug.ts +289 -0
  366. package/src/utils/stream-markup-healing.ts +612 -0
  367. package/src/utils/tool-choice.ts +99 -0
  368. package/src/utils/validation.ts +1024 -0
  369. package/src/utils.ts +166 -0
@@ -0,0 +1,341 @@
1
+ import { areJsonValuesEqual } from "./equality";
2
+ import { epochNext, once } from "./stamps";
3
+ import { isJsonObject, type JsonObject } from "./types";
4
+
5
+ export const JSON_SCHEMA_DRAFT_2020_12_URI = "https://json-schema.org/draft/2020-12/schema";
6
+
7
+ /** Draft-07 schema URIs we recognise as needing an upgrade. The trailing `#` is the canonical form in the JSON Schema spec, but providers (and Zod) emit both. */
8
+ const DRAFT_07_SCHEMA_URIS: Record<string, true> = {
9
+ "http://json-schema.org/draft-07/schema#": true,
10
+ "https://json-schema.org/draft-07/schema#": true,
11
+ "http://json-schema.org/draft-07/schema": true,
12
+ "https://json-schema.org/draft-07/schema": true,
13
+ };
14
+
15
+ /**
16
+ * Keys whose values are property-name → schema maps. We recurse into each map
17
+ * entry rather than the map object itself so legacy `definitions`-style refs
18
+ * inside property schemas get rewritten.
19
+ */
20
+ const SCHEMA_MAP_KEYS: Record<string, true> = { properties: true, patternProperties: true, dependentSchemas: true };
21
+ /**
22
+ * Keys whose values are JSON-Schema *values*, not nested schemas. The upgrade
23
+ * walker must NOT descend into these — `type: ["string","null"]` is not a
24
+ * schema, and recursing would corrupt `enum`/`const`/`default` payloads.
25
+ */
26
+ const NON_SCHEMA_VALUE_KEYS: Record<string, true> = {
27
+ const: true,
28
+ default: true,
29
+ enum: true,
30
+ example: true,
31
+ examples: true,
32
+ required: true,
33
+ dependentRequired: true,
34
+ type: true,
35
+ };
36
+
37
+ /** Rewrite draft-07's `#/definitions/Foo` ref form to draft 2020-12's `#/$defs/Foo`. External refs (`http://…`) pass through. */
38
+ function convertRef(value: string): string {
39
+ return value.startsWith("#/definitions/") ? `#/$defs/${value.slice("#/definitions/".length)}` : value;
40
+ }
41
+
42
+ /** Get-or-create a child object map on `target[key]`. Used to lazily build up `$defs`/`dependentRequired`/`dependentSchemas` during conversion. */
43
+ function getObjectMap(target: JsonObject, key: string): JsonObject {
44
+ const existing = target[key];
45
+ if (isJsonObject(existing)) return existing;
46
+ const next: JsonObject = {};
47
+ target[key] = next;
48
+ return next;
49
+ }
50
+
51
+ /** Recursively upgrade every entry of a schema-map (e.g. `properties`) and merge into `target[key]`. */
52
+ function mergeSchemaMap(target: JsonObject, key: string, value: JsonObject, cache: WeakMap<object, unknown>): void {
53
+ const map = getObjectMap(target, key);
54
+ for (const name in value) {
55
+ map[name] = upgradeJsonSchemaTo202012Impl(value[name], cache);
56
+ }
57
+ }
58
+ /** Copy a schema-map field with upgrade; non-object values are passed through verbatim. */
59
+ function copySchemaMap(target: JsonObject, key: string, value: unknown, cache: WeakMap<object, unknown>): void {
60
+ if (!isJsonObject(value)) {
61
+ target[key] = value;
62
+ return;
63
+ }
64
+ mergeSchemaMap(target, key, value, cache);
65
+ }
66
+
67
+ /**
68
+ * Intersect two schemas. Used when draft-07 `dependencies` map keys collide
69
+ * with each other or with existing `dependentSchemas` entries.
70
+ * - `true`/undefined is the identity (matches anything).
71
+ * - `false` is the absorbing element (matches nothing).
72
+ * - Equal schemas collapse. Otherwise wrap in `allOf` so both still apply.
73
+ */
74
+ function combineSchemas(left: unknown, right: unknown): unknown {
75
+ if (left === undefined || left === true) return right;
76
+ if (right === undefined || right === true) return left;
77
+ if (left === false || right === false) return false;
78
+ if (areJsonValuesEqual(left, right)) return left;
79
+ return { allOf: [left, right] };
80
+ }
81
+
82
+ /** Union two arrays of JSON values, deduping by deep equality. Used to merge `dependentRequired` arrays. */
83
+ function mergeArrayValues(left: unknown[], right: unknown[]): unknown[] {
84
+ const merged = [...left];
85
+ for (const value of right) {
86
+ if (!merged.some(existing => areJsonValuesEqual(existing, value))) {
87
+ merged.push(value);
88
+ }
89
+ }
90
+ return merged;
91
+ }
92
+
93
+ /**
94
+ * Merge converted tuple items into an existing `prefixItems` array. When the
95
+ * same index already has a schema (e.g. from a prior recursive pass via the
96
+ * cache), intersect the two so both constraints survive.
97
+ */
98
+ function mergePrefixItems(existing: unknown, convertedItems: unknown[]): unknown[] {
99
+ if (!Array.isArray(existing)) return convertedItems;
100
+ const merged = [...existing];
101
+ for (let index = 0; index < convertedItems.length; index += 1) {
102
+ merged[index] = index in merged ? combineSchemas(merged[index], convertedItems[index]) : convertedItems[index];
103
+ }
104
+ return merged;
105
+ }
106
+
107
+ /** Record `key → deps` in `dependentRequired`, unioning with any existing array. */
108
+ function mergeDependentRequired(target: JsonObject, key: string, deps: unknown[]): void {
109
+ const dependentRequired = getObjectMap(target, "dependentRequired");
110
+ const existing = dependentRequired[key];
111
+ if (existing === undefined) {
112
+ dependentRequired[key] = deps;
113
+ return;
114
+ }
115
+ if (Array.isArray(existing)) {
116
+ dependentRequired[key] = mergeArrayValues(existing, deps);
117
+ }
118
+ }
119
+
120
+ /** Record `key → schema` in `dependentSchemas`, intersecting with any existing entry. */
121
+ function mergeDependentSchema(target: JsonObject, key: string, schema: unknown): void {
122
+ const dependentSchemas = getObjectMap(target, "dependentSchemas");
123
+ dependentSchemas[key] = combineSchemas(dependentSchemas[key], schema);
124
+ }
125
+
126
+ /**
127
+ * Convert draft-07's `dependencies` keyword (which mixes array deps and schema
128
+ * deps under one key) into the draft 2020-12 split:
129
+ * - array value → `dependentRequired`
130
+ * - schema value → `dependentSchemas`
131
+ */
132
+ function convertDependencies(source: JsonObject, target: JsonObject, cache: WeakMap<object, unknown>): void {
133
+ const dependencies = source.dependencies;
134
+ if (!isJsonObject(dependencies)) return;
135
+ for (const key in dependencies) {
136
+ const dependency = dependencies[key];
137
+ const converted = upgradeJsonSchemaTo202012Impl(dependency, cache);
138
+ if (Array.isArray(converted)) {
139
+ mergeDependentRequired(target, key, converted);
140
+ } else {
141
+ mergeDependentSchema(target, key, converted);
142
+ }
143
+ }
144
+ }
145
+
146
+ /** True if `type` is `"null"` or an array that includes `"null"`. */
147
+ function hasNullType(type: unknown): boolean {
148
+ return type === "null" || (Array.isArray(type) && type.includes("null"));
149
+ }
150
+
151
+ /** True if any variant in `anyOf` declares (only) a null type. Used to avoid double-adding `{type:"null"}`. */
152
+ function hasNullVariant(variants: unknown[]): boolean {
153
+ return variants.some(variant => isJsonObject(variant) && hasNullType(variant.type));
154
+ }
155
+
156
+ /**
157
+ * Mutate `schema` in place to accept `null`. Strategy depends on existing shape:
158
+ * - scalar type → expand to `[type, "null"]`.
159
+ * - type array → append `"null"` if missing.
160
+ * - existing `anyOf` → append `{type:"null"}` branch if missing.
161
+ * - otherwise → wrap the whole schema in `anyOf:[schema, {type:"null"}]`.
162
+ * Returns the resulting object (which may be a new wrapper).
163
+ */
164
+ function makeNullable(schema: JsonObject): JsonObject {
165
+ const type = schema.type;
166
+ if (typeof type === "string") {
167
+ if (type !== "null") schema.type = [type, "null"];
168
+ return schema;
169
+ }
170
+ if (Array.isArray(type)) {
171
+ if (!type.includes("null")) schema.type = [...type, "null"];
172
+ return schema;
173
+ }
174
+ if (Array.isArray(schema.anyOf)) {
175
+ if (!hasNullVariant(schema.anyOf)) schema.anyOf = [...schema.anyOf, { type: "null" }];
176
+ return schema;
177
+ }
178
+ return { anyOf: [schema, { type: "null" }] };
179
+ }
180
+
181
+ /** True if any entry in a schema-map needs upgrading. Shortcut used during pre-check to skip the full clone when nothing has changed. */
182
+ function schemaMapNeedsDraft202012Upgrade(value: unknown, epoch: number): boolean {
183
+ if (!isJsonObject(value)) return false;
184
+ for (const k in value) {
185
+ if (schemaNeedsDraft202012UpgradeImpl(value[k], epoch)) return true;
186
+ }
187
+ return false;
188
+ }
189
+
190
+ /**
191
+ * Cheap pre-check: walk the schema looking for any keyword/value that the
192
+ * upgrade pass would have to rewrite. Lets the public entrypoint short-circuit
193
+ * and return the input identity-unchanged when there is nothing to do.
194
+ *
195
+ * Uses `once(value, epoch)` to break cycles without allocating a per-call set.
196
+ */
197
+ function schemaNeedsDraft202012UpgradeImpl(value: unknown, epoch: number): boolean {
198
+ if (Array.isArray(value)) {
199
+ if (!once(value, epoch)) return false;
200
+ return value.some(entry => schemaNeedsDraft202012UpgradeImpl(entry, epoch));
201
+ }
202
+ if (!isJsonObject(value)) return false;
203
+ if (!once(value, epoch)) return false;
204
+
205
+ for (const key in value) {
206
+ const entry = value[key];
207
+ if (key === "$schema") {
208
+ if (typeof entry === "string" && entry in DRAFT_07_SCHEMA_URIS) return true;
209
+ continue;
210
+ }
211
+ if (key === "definitions" || key === "dependencies" || key === "additionalItems" || key === "nullable") {
212
+ return true;
213
+ }
214
+ if (key === "$ref") {
215
+ if (typeof entry === "string" && entry.startsWith("#/definitions/")) return true;
216
+ continue;
217
+ }
218
+ if (key === "items" && Array.isArray(entry)) return true;
219
+ if (key === "$defs" || key in SCHEMA_MAP_KEYS) {
220
+ if (schemaMapNeedsDraft202012Upgrade(entry, epoch)) return true;
221
+ continue;
222
+ }
223
+ if (key in NON_SCHEMA_VALUE_KEYS) continue;
224
+ if (schemaNeedsDraft202012UpgradeImpl(entry, epoch)) return true;
225
+ }
226
+
227
+ return false;
228
+ }
229
+
230
+ /**
231
+ * Recursive upgrade core. The `cache` WeakMap keys input objects to their
232
+ * converted output so shared subgraphs are converted once and cycles terminate
233
+ * — we insert the empty result into the cache *before* recursing so back-edges
234
+ * resolve to a (later-populated) reference rather than infinite-looping.
235
+ */
236
+ function upgradeJsonSchemaTo202012Impl(value: unknown, cache: WeakMap<object, unknown>): unknown {
237
+ if (Array.isArray(value)) {
238
+ const cached = cache.get(value);
239
+ if (cached !== undefined) return cached;
240
+ const result: unknown[] = [];
241
+ cache.set(value, result);
242
+ for (const entry of value) {
243
+ result.push(upgradeJsonSchemaTo202012Impl(entry, cache));
244
+ }
245
+ return result;
246
+ }
247
+ if (!isJsonObject(value)) return value;
248
+
249
+ const cached = cache.get(value);
250
+ if (cached !== undefined) return cached;
251
+
252
+ const result: JsonObject = {};
253
+ // Seed cache before recursion so back-edges in cyclic graphs resolve.
254
+ cache.set(value, result);
255
+ for (const key in value) {
256
+ const entry = value[key];
257
+ // `definitions` is the draft-07 name; merge under the canonical `$defs`.
258
+ // `$defs` may appear pre-upgraded — still walk entries to upgrade their bodies.
259
+ if (key === "definitions" || key === "$defs") {
260
+ if (isJsonObject(entry)) mergeSchemaMap(result, "$defs", entry, cache);
261
+ continue;
262
+ }
263
+ // Recurse into each entry; the map shape itself is preserved.
264
+ if (key in SCHEMA_MAP_KEYS) {
265
+ copySchemaMap(result, key, entry, cache);
266
+ continue;
267
+ }
268
+ // JSON-Schema *value* keywords — copy verbatim.
269
+ if (key in NON_SCHEMA_VALUE_KEYS) {
270
+ result[key] = entry;
271
+ continue;
272
+ }
273
+ // Draft-07-only keywords with no draft 2020-12 spelling — drop entirely.
274
+ // `items` arrays are handled below via `prefixItems` conversion.
275
+ if (key === "dependencies" || key === "additionalItems" || key === "nullable") {
276
+ continue;
277
+ }
278
+ // Rewrite `$schema` URI to the 2020-12 form; non-draft-07 URIs pass through.
279
+ if (key === "$schema") {
280
+ result.$schema =
281
+ typeof entry === "string" && entry in DRAFT_07_SCHEMA_URIS ? JSON_SCHEMA_DRAFT_2020_12_URI : entry;
282
+ continue;
283
+ }
284
+ // `#/definitions/Foo` → `#/$defs/Foo`.
285
+ if (key === "$ref" && typeof entry === "string") {
286
+ result.$ref = convertRef(entry);
287
+ continue;
288
+ }
289
+ // Array-valued `items` is the draft-07 tuple form — handled after the loop.
290
+ if (key === "items" && Array.isArray(entry)) {
291
+ continue;
292
+ }
293
+ result[key] = upgradeJsonSchemaTo202012Impl(entry, cache);
294
+ }
295
+
296
+ // Draft-07 tuple form: `items: [a, b]` (+ optional `additionalItems`) becomes
297
+ // draft 2020-12 `prefixItems: [a, b]` (+ optional `items` for the rest).
298
+ if (Array.isArray(value.items)) {
299
+ const convertedItems = upgradeJsonSchemaTo202012Impl(value.items, cache) as unknown[];
300
+ result.prefixItems = mergePrefixItems(result.prefixItems, convertedItems);
301
+ if (value.additionalItems !== undefined && value.additionalItems !== true) {
302
+ result.items = upgradeJsonSchemaTo202012Impl(value.additionalItems, cache);
303
+ } else {
304
+ // `additionalItems: true` (or absent) in draft-07 == no `items` in 2020-12.
305
+ delete result.items;
306
+ }
307
+ }
308
+
309
+ convertDependencies(value, result, cache);
310
+
311
+ // OpenAPI 3.0 `nullable: true` → 2020-12 nullability. `makeNullable` may
312
+ // return a fresh wrapper object, in which case update the cache so callers
313
+ // referring to the same input see the wrapper instead of the inner result.
314
+ if (value.nullable === true) {
315
+ const nullable = makeNullable(result);
316
+ if (nullable !== result) cache.set(value, nullable);
317
+ return nullable;
318
+ }
319
+
320
+ return result;
321
+ }
322
+
323
+ /** Pre-check entrypoint. Exposed so callers can decide whether to take the upgrade path at all. */
324
+ export function schemaNeedsDraft202012Upgrade(schema: unknown): boolean {
325
+ return schemaNeedsDraft202012UpgradeImpl(schema, epochNext());
326
+ }
327
+
328
+ /**
329
+ * Upgrade legacy JSON Schema shapes to the draft 2020-12 form emitted by Zod.
330
+ *
331
+ * This keeps extension/MCP/TypeBox schemas compatible with providers whose tool
332
+ * validators reject draft-07 tuple and dependency keywords.
333
+ */
334
+ // `WeakMap` is intentional: this cache is per-call and seeded *before* recursion
335
+ // (see `cache.set(value, result)` in `upgradeJsonSchemaTo202012Impl`) so cyclic
336
+ // graphs resolve to a knot-tied reference. A symbol stamp would either cache
337
+ // across calls (unsafe under input mutation) or require an epoch indirection.
338
+ export function upgradeJsonSchemaTo202012(schema: unknown): unknown {
339
+ if (!schemaNeedsDraft202012Upgrade(schema)) return schema;
340
+ return upgradeJsonSchemaTo202012Impl(schema, new WeakMap<object, unknown>());
341
+ }
@@ -0,0 +1,97 @@
1
+ import type { JsonObject } from "./types";
2
+ import { isJsonObject } from "./types";
3
+
4
+ export function areJsonValuesEqual(left: unknown, right: unknown): boolean {
5
+ if (Object.is(left, right)) {
6
+ return true;
7
+ }
8
+ if (Array.isArray(left) || Array.isArray(right)) {
9
+ if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) {
10
+ return false;
11
+ }
12
+ for (let i = 0; i < left.length; i += 1) {
13
+ if (!areJsonValuesEqual(left[i], right[i])) {
14
+ return false;
15
+ }
16
+ }
17
+ return true;
18
+ }
19
+ if (!isJsonObject(left) || !isJsonObject(right)) {
20
+ return false;
21
+ }
22
+ let rightLen = 0;
23
+ for (const _ in right) rightLen++;
24
+ let leftLen = 0;
25
+ for (const key in left) {
26
+ leftLen++;
27
+ if (!(key in right) || !areJsonValuesEqual(left[key], right[key])) return false;
28
+ }
29
+ return leftLen === rightLen;
30
+ }
31
+
32
+ export function mergeCompatibleEnumSchemas(existing: unknown, incoming: unknown): JsonObject | null {
33
+ if (!isJsonObject(existing) || !isJsonObject(incoming)) {
34
+ return null;
35
+ }
36
+ const existingEnum = Array.isArray(existing.enum) ? existing.enum : null;
37
+ const incomingEnum = Array.isArray(incoming.enum) ? incoming.enum : null;
38
+ if (!existingEnum || !incomingEnum) {
39
+ return null;
40
+ }
41
+ if (!areJsonValuesEqual(existing.type, incoming.type)) {
42
+ return null;
43
+ }
44
+ let existingNonEnumCount = 0;
45
+ for (const key in existing) {
46
+ if (key !== "enum") existingNonEnumCount++;
47
+ }
48
+ let incomingNonEnumCount = 0;
49
+ for (const key in incoming) {
50
+ if (key !== "enum") incomingNonEnumCount++;
51
+ }
52
+ if (existingNonEnumCount !== incomingNonEnumCount) {
53
+ return null;
54
+ }
55
+ for (const key in existing) {
56
+ if (key === "enum") continue;
57
+ if (!(key in incoming) || !areJsonValuesEqual(existing[key], incoming[key])) {
58
+ return null;
59
+ }
60
+ }
61
+
62
+ const mergedEnum = [...existingEnum];
63
+ for (const enumValue of incomingEnum) {
64
+ if (!mergedEnum.some(existingValue => areJsonValuesEqual(existingValue, enumValue))) {
65
+ mergedEnum.push(enumValue);
66
+ }
67
+ }
68
+ return {
69
+ ...existing,
70
+ enum: mergedEnum,
71
+ };
72
+ }
73
+
74
+ function getAnyOfVariants(schema: unknown): unknown[] {
75
+ if (isJsonObject(schema) && Array.isArray(schema.anyOf)) {
76
+ return schema.anyOf;
77
+ }
78
+ return [schema];
79
+ }
80
+
81
+ export function mergePropertySchemas(existing: unknown, incoming: unknown): unknown {
82
+ if (areJsonValuesEqual(existing, incoming)) {
83
+ return existing;
84
+ }
85
+ const mergedEnumSchema = mergeCompatibleEnumSchemas(existing, incoming);
86
+ if (mergedEnumSchema !== null) {
87
+ return mergedEnumSchema;
88
+ }
89
+
90
+ const mergedAnyOf = [...getAnyOfVariants(existing)];
91
+ for (const variant of getAnyOfVariants(incoming)) {
92
+ if (!mergedAnyOf.some(existingVariant => areJsonValuesEqual(existingVariant, variant))) {
93
+ mergedAnyOf.push(variant);
94
+ }
95
+ }
96
+ return mergedAnyOf.length === 1 ? mergedAnyOf[0] : { anyOf: mergedAnyOf };
97
+ }
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Field classification sets for JSON Schema sanitization across providers.
3
+ *
4
+ * Each set serves a different provider need. They overlap intentionally —
5
+ * co-locating them makes the overlap visible and maintainable.
6
+ *
7
+ * All keysets here are static and small (≤ ~40 entries) so they live as
8
+ * `Record<string, true>` literals — `k in REC` resolves through hidden
9
+ * class inline caches without the per-call hashtable cost of `Set.has`.
10
+ */
11
+
12
+ /**
13
+ * Google Generative AI unsupported schema fields.
14
+ * Stripped during normalizeSchemaForGoogle / normalizeSchemaForCCA.
15
+ */
16
+ export const UNSUPPORTED_SCHEMA_FIELDS: Record<string, true> = {
17
+ $schema: true,
18
+ $ref: true,
19
+ $defs: true,
20
+ $dynamicRef: true,
21
+ $dynamicAnchor: true,
22
+ examples: true,
23
+ prefixItems: true,
24
+ unevaluatedProperties: true,
25
+ unevaluatedItems: true,
26
+ patternProperties: true,
27
+ additionalProperties: true,
28
+ propertyNames: true,
29
+ minItems: true,
30
+ maxItems: true,
31
+ minLength: true,
32
+ maxLength: true,
33
+ minimum: true,
34
+ maximum: true,
35
+ exclusiveMinimum: true,
36
+ exclusiveMaximum: true,
37
+ multipleOf: true,
38
+ pattern: true,
39
+ format: true,
40
+ };
41
+
42
+ /**
43
+ * Human-meaningful validation/decorative keywords that can be preserved in a
44
+ * sibling description when a provider-specific normalizer strips them from the
45
+ * wire schema.
46
+ */
47
+ export const LIFTABLE_TO_DESCRIPTION_FIELDS: Record<string, true> = {
48
+ pattern: true,
49
+ format: true,
50
+ minLength: true,
51
+ maxLength: true,
52
+ minimum: true,
53
+ maximum: true,
54
+ exclusiveMinimum: true,
55
+ exclusiveMaximum: true,
56
+ multipleOf: true,
57
+ minItems: true,
58
+ maxItems: true,
59
+ uniqueItems: true,
60
+ minProperties: true,
61
+ maxProperties: true,
62
+ default: true,
63
+ examples: true,
64
+ };
65
+
66
+ /**
67
+ * Non-structural schema keys stripped during OpenAI strict mode sanitization.
68
+ * These are decorative/validation-only keywords that don't affect the structural
69
+ * shape OpenAI's strict mode enforces.
70
+ */
71
+ export const NON_STRUCTURAL_SCHEMA_KEYS: Record<string, true> = {
72
+ format: true,
73
+ pattern: true,
74
+ minLength: true,
75
+ maxLength: true,
76
+ minimum: true,
77
+ maximum: true,
78
+ exclusiveMinimum: true,
79
+ exclusiveMaximum: true,
80
+ minItems: true,
81
+ maxItems: true,
82
+ uniqueItems: true,
83
+ multipleOf: true,
84
+ $schema: true,
85
+ examples: true,
86
+ default: true,
87
+ title: true,
88
+ $comment: true,
89
+ if: true,
90
+ // biome-ignore lint/suspicious/noThenProperty: JSON Schema keyword
91
+ then: true,
92
+ else: true,
93
+ not: true,
94
+ unevaluatedProperties: true,
95
+ unevaluatedItems: true,
96
+ patternProperties: true,
97
+ propertyNames: true,
98
+ contains: true,
99
+ minContains: true,
100
+ maxContains: true,
101
+ dependentRequired: true,
102
+ dependentSchemas: true,
103
+ contentEncoding: true,
104
+ contentMediaType: true,
105
+ contentSchema: true,
106
+ deprecated: true,
107
+ readOnly: true,
108
+ writeOnly: true,
109
+ minProperties: true,
110
+ maxProperties: true,
111
+ $dynamicRef: true,
112
+ $dynamicAnchor: true,
113
+ };
114
+
115
+ /**
116
+ * Cloud Code Assist type-specific allowed keys per JSON Schema type.
117
+ * Used when collapsing mixed-type combiner variants for CCA Claude.
118
+ */
119
+ export const CLOUD_CODE_ASSIST_TYPE_SPECIFIC_KEYS: Record<string, Record<string, true>> = {
120
+ array: {
121
+ items: true,
122
+ prefixItems: true,
123
+ contains: true,
124
+ minContains: true,
125
+ maxContains: true,
126
+ minItems: true,
127
+ maxItems: true,
128
+ uniqueItems: true,
129
+ unevaluatedItems: true,
130
+ },
131
+ object: {
132
+ properties: true,
133
+ required: true,
134
+ additionalProperties: true,
135
+ patternProperties: true,
136
+ propertyNames: true,
137
+ minProperties: true,
138
+ maxProperties: true,
139
+ dependentRequired: true,
140
+ dependentSchemas: true,
141
+ unevaluatedProperties: true,
142
+ },
143
+ string: {
144
+ minLength: true,
145
+ maxLength: true,
146
+ pattern: true,
147
+ format: true,
148
+ contentEncoding: true,
149
+ contentMediaType: true,
150
+ },
151
+ number: { minimum: true, maximum: true, exclusiveMinimum: true, exclusiveMaximum: true, multipleOf: true },
152
+ integer: { minimum: true, maximum: true, exclusiveMinimum: true, exclusiveMaximum: true, multipleOf: true },
153
+ boolean: {},
154
+ null: {},
155
+ };
156
+
157
+ /**
158
+ * Cloud Code Assist shared schema keys allowed on any type.
159
+ * Used alongside CLOUD_CODE_ASSIST_TYPE_SPECIFIC_KEYS for CCA combiner collapsing.
160
+ */
161
+ export const CLOUD_CODE_ASSIST_SHARED_SCHEMA_KEYS: Record<string, true> = {
162
+ title: true,
163
+ description: true,
164
+ default: true,
165
+ examples: true,
166
+ deprecated: true,
167
+ readOnly: true,
168
+ writeOnly: true,
169
+ $comment: true,
170
+ };
171
+
172
+ /**
173
+ * Combinator keys used across schema sanitization modules.
174
+ * Defined once to avoid duplication in strict-mode.ts and normalize.ts.
175
+ */
176
+ export const COMBINATOR_KEYS = ["anyOf", "allOf", "oneOf"] as const;
177
+
178
+ /**
179
+ * Cloud Code Assist Claude unsupported schema fields.
180
+ * Much smaller than UNSUPPORTED_SCHEMA_FIELDS (Google) because CCA supports
181
+ * validation keywords like additionalProperties, minLength, pattern, etc.
182
+ * Meta/reference keywords plus object-key validators that CCA cannot resolve are stripped.
183
+ */
184
+ export const CCA_UNSUPPORTED_SCHEMA_FIELDS: Record<string, true> = {
185
+ $schema: true,
186
+ $ref: true,
187
+ $defs: true,
188
+ $dynamicRef: true,
189
+ $dynamicAnchor: true,
190
+ propertyNames: true,
191
+ };
@@ -0,0 +1,13 @@
1
+ export * from "./adapt";
2
+ export * from "./compatibility";
3
+ export * from "./dereference";
4
+ export * from "./draft";
5
+ export * from "./equality";
6
+ export * from "./fields";
7
+ export * from "./json-schema-validator";
8
+ export * from "./meta-validator";
9
+ export * from "./normalize";
10
+ export * from "./spill";
11
+ export * from "./types";
12
+ export * from "./wire";
13
+ export * from "./zod-decontaminate";