@aryee337/aery-ai 0.2.28 → 0.2.29

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 (417) hide show
  1. package/CHANGELOG.md +2914 -0
  2. package/README.md +614 -813
  3. package/package.json +140 -105
  4. package/src/api-registry.ts +96 -0
  5. package/src/auth-broker/client.ts +358 -0
  6. package/src/auth-broker/index.ts +5 -0
  7. package/src/auth-broker/refresher.ts +117 -0
  8. package/src/auth-broker/remote-store.ts +623 -0
  9. package/src/auth-broker/server.ts +644 -0
  10. package/src/auth-broker/types.ts +127 -0
  11. package/src/auth-broker/wire-schemas.ts +200 -0
  12. package/src/auth-gateway/http.ts +194 -0
  13. package/src/auth-gateway/index.ts +3 -0
  14. package/src/auth-gateway/server.ts +818 -0
  15. package/src/auth-gateway/types.ts +143 -0
  16. package/src/auth-storage.ts +4422 -0
  17. package/src/index.ts +54 -0
  18. package/src/model-cache.ts +129 -0
  19. package/src/model-manager.ts +469 -0
  20. package/src/model-thinking.ts +782 -0
  21. package/src/models.json +83530 -0
  22. package/src/models.json.d.ts +9 -0
  23. package/src/models.ts +56 -0
  24. package/src/prompts/turn-aborted-guidance.md +4 -0
  25. package/src/provider-details.ts +90 -0
  26. package/src/provider-models/bundled-references.ts +38 -0
  27. package/src/provider-models/descriptors.ts +355 -0
  28. package/src/provider-models/google.ts +88 -0
  29. package/src/provider-models/index.ts +5 -0
  30. package/src/provider-models/ollama.ts +153 -0
  31. package/src/provider-models/openai-compat.ts +2817 -0
  32. package/src/provider-models/special.ts +67 -0
  33. package/src/providers/aery-native-client.ts +228 -0
  34. package/src/providers/aery-native-server.ts +212 -0
  35. package/src/providers/amazon-bedrock.ts +873 -0
  36. package/src/providers/anthropic-client.ts +318 -0
  37. package/src/providers/anthropic-messages-server-schema.ts +243 -0
  38. package/src/providers/anthropic-messages-server.ts +683 -0
  39. package/src/providers/anthropic-wire.ts +268 -0
  40. package/src/providers/anthropic.ts +3094 -0
  41. package/src/providers/aws-credentials.ts +501 -0
  42. package/src/providers/aws-eventstream.ts +185 -0
  43. package/src/providers/aws-sigv4.ts +218 -0
  44. package/src/providers/azure-openai-responses.ts +361 -0
  45. package/src/providers/cursor/gen/agent_pb.ts +15274 -0
  46. package/src/providers/cursor/proto/agent.proto +3526 -0
  47. package/src/providers/cursor/proto/buf.gen.yaml +6 -0
  48. package/src/providers/cursor/proto/buf.yaml +17 -0
  49. package/src/providers/cursor.ts +2621 -0
  50. package/src/providers/error-message.ts +21 -0
  51. package/src/providers/github-copilot-headers.ts +140 -0
  52. package/src/providers/gitlab-duo.ts +372 -0
  53. package/src/providers/google-auth.ts +252 -0
  54. package/src/providers/google-gemini-cli.ts +809 -0
  55. package/src/providers/google-gemini-headers.ts +41 -0
  56. package/src/providers/google-shared.ts +917 -0
  57. package/src/providers/google-types.ts +167 -0
  58. package/src/providers/google-vertex.ts +91 -0
  59. package/src/providers/google.ts +41 -0
  60. package/src/providers/grammar.ts +70 -0
  61. package/src/providers/kimi.ts +52 -0
  62. package/src/providers/mock.ts +496 -0
  63. package/src/providers/ollama.ts +644 -0
  64. package/src/providers/openai-anthropic-shim.ts +138 -0
  65. package/src/providers/openai-chat-server-schema.ts +252 -0
  66. package/src/providers/openai-chat-server.ts +647 -0
  67. package/src/providers/openai-codex/constants.ts +43 -0
  68. package/src/providers/openai-codex/request-transformer.ts +161 -0
  69. package/src/providers/openai-codex/response-handler.ts +81 -0
  70. package/src/providers/openai-codex-responses.ts +3018 -0
  71. package/src/providers/openai-completions-compat.ts +300 -0
  72. package/src/providers/openai-completions.ts +1979 -0
  73. package/src/providers/openai-responses-server-schema.ts +290 -0
  74. package/src/providers/openai-responses-server.ts +1183 -0
  75. package/src/providers/openai-responses-shared.ts +873 -0
  76. package/src/providers/openai-responses.ts +679 -0
  77. package/src/providers/register-builtins.ts +436 -0
  78. package/src/providers/synthetic.ts +50 -0
  79. package/src/providers/transform-messages.ts +382 -0
  80. package/src/providers/vision-guard.ts +31 -0
  81. package/src/providers/xai-responses.ts +82 -0
  82. package/src/rate-limit-utils.ts +84 -0
  83. package/src/stream.ts +1065 -0
  84. package/src/types.ts +944 -0
  85. package/src/usage/claude.ts +482 -0
  86. package/src/usage/gemini.ts +250 -0
  87. package/src/usage/github-copilot.ts +421 -0
  88. package/src/usage/google-antigravity.ts +201 -0
  89. package/src/usage/kimi.ts +271 -0
  90. package/src/usage/minimax-code.ts +31 -0
  91. package/src/usage/openai-codex.ts +503 -0
  92. package/src/usage/shared.ts +10 -0
  93. package/src/usage/zai.ts +247 -0
  94. package/src/usage.ts +185 -0
  95. package/src/utils/abort.ts +51 -0
  96. package/src/utils/abortable-iterator.ts +69 -0
  97. package/src/utils/anthropic-auth.ts +93 -0
  98. package/src/utils/discovery/antigravity.ts +261 -0
  99. package/src/utils/discovery/codex.ts +371 -0
  100. package/src/utils/discovery/cursor.ts +306 -0
  101. package/src/utils/discovery/gemini.ts +248 -0
  102. package/src/utils/discovery/index.ts +4 -0
  103. package/src/utils/discovery/openai-compatible.ts +224 -0
  104. package/src/utils/event-stream.ts +142 -0
  105. package/src/utils/fireworks-model-id.ts +30 -0
  106. package/src/utils/foundry.ts +8 -0
  107. package/src/utils/http-inspector.ts +176 -0
  108. package/src/utils/idle-iterator.ts +267 -0
  109. package/src/utils/json-parse.ts +182 -0
  110. package/src/utils/oauth/__tests__/xai-oauth.test.ts +107 -0
  111. package/src/utils/oauth/alibaba-coding-plan.ts +59 -0
  112. package/src/utils/oauth/anthropic.ts +273 -0
  113. package/src/utils/oauth/api-key-login.ts +87 -0
  114. package/src/utils/oauth/api-key-validation.ts +92 -0
  115. package/src/utils/oauth/callback-server.ts +276 -0
  116. package/src/utils/oauth/cerebras.ts +16 -0
  117. package/src/utils/oauth/cloudflare-ai-gateway.ts +48 -0
  118. package/src/utils/oauth/cursor.ts +157 -0
  119. package/src/utils/oauth/deepseek.ts +53 -0
  120. package/src/utils/oauth/firepass.ts +24 -0
  121. package/src/utils/oauth/fireworks.ts +15 -0
  122. package/src/utils/oauth/github-copilot.ts +362 -0
  123. package/src/utils/oauth/gitlab-duo.ts +123 -0
  124. package/src/utils/oauth/google-antigravity.ts +200 -0
  125. package/src/utils/oauth/google-gemini-cli.ts +256 -0
  126. package/src/utils/oauth/google-oauth-shared.ts +110 -0
  127. package/src/utils/oauth/huggingface.ts +62 -0
  128. package/src/utils/oauth/index.ts +484 -0
  129. package/src/utils/oauth/kagi.ts +47 -0
  130. package/src/utils/oauth/kilo.ts +87 -0
  131. package/src/utils/oauth/kimi.ts +254 -0
  132. package/src/utils/oauth/litellm.ts +47 -0
  133. package/src/utils/oauth/lm-studio.ts +38 -0
  134. package/src/utils/oauth/minimax-code.ts +78 -0
  135. package/src/utils/oauth/moonshot.ts +23 -0
  136. package/src/utils/oauth/nanogpt.ts +15 -0
  137. package/src/utils/oauth/nvidia.ts +70 -0
  138. package/src/utils/oauth/oauth.html +203 -0
  139. package/src/utils/oauth/ollama-cloud.ts +28 -0
  140. package/src/utils/oauth/ollama.ts +47 -0
  141. package/src/utils/oauth/openai-codex.ts +299 -0
  142. package/src/utils/oauth/opencode.ts +49 -0
  143. package/src/utils/oauth/openrouter.ts +20 -0
  144. package/src/utils/oauth/parallel.ts +46 -0
  145. package/src/utils/oauth/perplexity.ts +206 -0
  146. package/src/utils/oauth/pkce.ts +18 -0
  147. package/src/utils/oauth/qianfan.ts +58 -0
  148. package/src/utils/oauth/qwen-portal.ts +60 -0
  149. package/src/utils/oauth/synthetic.ts +15 -0
  150. package/src/utils/oauth/tavily.ts +46 -0
  151. package/src/utils/oauth/together.ts +16 -0
  152. package/src/utils/oauth/types.ts +99 -0
  153. package/src/utils/oauth/venice.ts +59 -0
  154. package/src/utils/oauth/vercel-ai-gateway.ts +47 -0
  155. package/src/utils/oauth/vllm.ts +40 -0
  156. package/src/utils/oauth/wafer.ts +50 -0
  157. package/src/utils/oauth/xai-oauth.ts +342 -0
  158. package/src/utils/oauth/xiaomi.ts +139 -0
  159. package/src/utils/oauth/zai.ts +60 -0
  160. package/src/utils/oauth/zenmux.ts +15 -0
  161. package/src/utils/oauth/zhipu.ts +60 -0
  162. package/src/utils/overflow.ts +137 -0
  163. package/src/utils/parse-bind.ts +54 -0
  164. package/src/utils/provider-response.ts +30 -0
  165. package/src/utils/request-debug.ts +336 -0
  166. package/src/utils/retry-after.ts +110 -0
  167. package/src/utils/retry.ts +54 -0
  168. package/src/utils/schema/CONSTRAINTS.md +164 -0
  169. package/src/utils/schema/adapt.ts +36 -0
  170. package/src/utils/schema/compatibility.ts +435 -0
  171. package/src/utils/schema/dereference.ts +98 -0
  172. package/src/utils/schema/draft.ts +341 -0
  173. package/src/utils/schema/equality.ts +97 -0
  174. package/src/utils/schema/fields.ts +191 -0
  175. package/src/utils/schema/index.ts +13 -0
  176. package/src/utils/schema/json-schema-validator.ts +577 -0
  177. package/src/utils/schema/meta-validator.ts +167 -0
  178. package/src/utils/schema/normalize.ts +1588 -0
  179. package/src/utils/schema/spill.ts +43 -0
  180. package/src/utils/schema/stamps.ts +97 -0
  181. package/src/utils/schema/types.ts +10 -0
  182. package/src/utils/schema/wire.ts +293 -0
  183. package/src/utils/schema/zod-decontaminate.ts +331 -0
  184. package/src/utils/sdk-stream-timeout.ts +43 -0
  185. package/src/utils/sse-debug.ts +289 -0
  186. package/src/utils/stream-markup-healing.ts +612 -0
  187. package/src/utils/tool-choice.ts +99 -0
  188. package/src/utils/validation.ts +1024 -0
  189. package/src/utils.ts +166 -0
  190. package/dist/api-registry.d.ts +0 -20
  191. package/dist/api-registry.d.ts.map +0 -1
  192. package/dist/api-registry.js +0 -44
  193. package/dist/api-registry.js.map +0 -1
  194. package/dist/bedrock-provider.d.ts +0 -5
  195. package/dist/bedrock-provider.d.ts.map +0 -1
  196. package/dist/bedrock-provider.js +0 -6
  197. package/dist/bedrock-provider.js.map +0 -1
  198. package/dist/cli.d.ts +0 -3
  199. package/dist/cli.d.ts.map +0 -1
  200. package/dist/cli.js +0 -130
  201. package/dist/cli.js.map +0 -1
  202. package/dist/env-api-keys.d.ts +0 -18
  203. package/dist/env-api-keys.d.ts.map +0 -1
  204. package/dist/env-api-keys.js +0 -178
  205. package/dist/env-api-keys.js.map +0 -1
  206. package/dist/image-models.d.ts +0 -10
  207. package/dist/image-models.d.ts.map +0 -1
  208. package/dist/image-models.generated.d.ts +0 -440
  209. package/dist/image-models.generated.d.ts.map +0 -1
  210. package/dist/image-models.generated.js +0 -442
  211. package/dist/image-models.generated.js.map +0 -1
  212. package/dist/image-models.js +0 -23
  213. package/dist/image-models.js.map +0 -1
  214. package/dist/images-api-registry.d.ts +0 -14
  215. package/dist/images-api-registry.d.ts.map +0 -1
  216. package/dist/images-api-registry.js +0 -22
  217. package/dist/images-api-registry.js.map +0 -1
  218. package/dist/images.d.ts +0 -4
  219. package/dist/images.d.ts.map +0 -1
  220. package/dist/images.js +0 -14
  221. package/dist/images.js.map +0 -1
  222. package/dist/index.d.ts +0 -32
  223. package/dist/index.d.ts.map +0 -1
  224. package/dist/index.js +0 -20
  225. package/dist/index.js.map +0 -1
  226. package/dist/models.d.ts +0 -18
  227. package/dist/models.d.ts.map +0 -1
  228. package/dist/models.generated.d.ts +0 -17707
  229. package/dist/models.generated.d.ts.map +0 -1
  230. package/dist/models.generated.js +0 -16561
  231. package/dist/models.generated.js.map +0 -1
  232. package/dist/models.js +0 -71
  233. package/dist/models.js.map +0 -1
  234. package/dist/oauth.d.ts +0 -2
  235. package/dist/oauth.d.ts.map +0 -1
  236. package/dist/oauth.js +0 -2
  237. package/dist/oauth.js.map +0 -1
  238. package/dist/providers/aery-error-formatting.d.ts +0 -13
  239. package/dist/providers/aery-error-formatting.d.ts.map +0 -1
  240. package/dist/providers/aery-error-formatting.js +0 -112
  241. package/dist/providers/aery-error-formatting.js.map +0 -1
  242. package/dist/providers/amazon-bedrock.d.ts +0 -38
  243. package/dist/providers/amazon-bedrock.d.ts.map +0 -1
  244. package/dist/providers/amazon-bedrock.js +0 -763
  245. package/dist/providers/amazon-bedrock.js.map +0 -1
  246. package/dist/providers/anthropic.d.ts +0 -71
  247. package/dist/providers/anthropic.d.ts.map +0 -1
  248. package/dist/providers/anthropic.js +0 -949
  249. package/dist/providers/anthropic.js.map +0 -1
  250. package/dist/providers/azure-openai-responses.d.ts +0 -15
  251. package/dist/providers/azure-openai-responses.d.ts.map +0 -1
  252. package/dist/providers/azure-openai-responses.js +0 -225
  253. package/dist/providers/azure-openai-responses.js.map +0 -1
  254. package/dist/providers/cloudflare.d.ts +0 -13
  255. package/dist/providers/cloudflare.d.ts.map +0 -1
  256. package/dist/providers/cloudflare.js +0 -26
  257. package/dist/providers/cloudflare.js.map +0 -1
  258. package/dist/providers/faux.d.ts +0 -56
  259. package/dist/providers/faux.d.ts.map +0 -1
  260. package/dist/providers/faux.js +0 -368
  261. package/dist/providers/faux.js.map +0 -1
  262. package/dist/providers/github-copilot-headers.d.ts +0 -8
  263. package/dist/providers/github-copilot-headers.d.ts.map +0 -1
  264. package/dist/providers/github-copilot-headers.js +0 -29
  265. package/dist/providers/github-copilot-headers.js.map +0 -1
  266. package/dist/providers/google-gemini-cli.d.ts +0 -74
  267. package/dist/providers/google-gemini-cli.d.ts.map +0 -1
  268. package/dist/providers/google-gemini-cli.js +0 -779
  269. package/dist/providers/google-gemini-cli.js.map +0 -1
  270. package/dist/providers/google-shared.d.ts +0 -70
  271. package/dist/providers/google-shared.d.ts.map +0 -1
  272. package/dist/providers/google-shared.js +0 -329
  273. package/dist/providers/google-shared.js.map +0 -1
  274. package/dist/providers/google-vertex.d.ts +0 -15
  275. package/dist/providers/google-vertex.d.ts.map +0 -1
  276. package/dist/providers/google-vertex.js +0 -442
  277. package/dist/providers/google-vertex.js.map +0 -1
  278. package/dist/providers/google.d.ts +0 -13
  279. package/dist/providers/google.d.ts.map +0 -1
  280. package/dist/providers/google.js +0 -400
  281. package/dist/providers/google.js.map +0 -1
  282. package/dist/providers/images/openrouter.d.ts +0 -3
  283. package/dist/providers/images/openrouter.d.ts.map +0 -1
  284. package/dist/providers/images/openrouter.js +0 -129
  285. package/dist/providers/images/openrouter.js.map +0 -1
  286. package/dist/providers/images/register-builtins.d.ts +0 -4
  287. package/dist/providers/images/register-builtins.d.ts.map +0 -1
  288. package/dist/providers/images/register-builtins.js +0 -34
  289. package/dist/providers/images/register-builtins.js.map +0 -1
  290. package/dist/providers/mistral.d.ts +0 -25
  291. package/dist/providers/mistral.d.ts.map +0 -1
  292. package/dist/providers/mistral.js +0 -535
  293. package/dist/providers/mistral.js.map +0 -1
  294. package/dist/providers/openai-codex-responses.d.ts +0 -30
  295. package/dist/providers/openai-codex-responses.d.ts.map +0 -1
  296. package/dist/providers/openai-codex-responses.js +0 -1090
  297. package/dist/providers/openai-codex-responses.js.map +0 -1
  298. package/dist/providers/openai-completions.d.ts +0 -19
  299. package/dist/providers/openai-completions.d.ts.map +0 -1
  300. package/dist/providers/openai-completions.js +0 -950
  301. package/dist/providers/openai-completions.js.map +0 -1
  302. package/dist/providers/openai-prompt-cache.d.ts +0 -3
  303. package/dist/providers/openai-prompt-cache.d.ts.map +0 -1
  304. package/dist/providers/openai-prompt-cache.js +0 -10
  305. package/dist/providers/openai-prompt-cache.js.map +0 -1
  306. package/dist/providers/openai-responses-shared.d.ts +0 -18
  307. package/dist/providers/openai-responses-shared.d.ts.map +0 -1
  308. package/dist/providers/openai-responses-shared.js +0 -492
  309. package/dist/providers/openai-responses-shared.js.map +0 -1
  310. package/dist/providers/openai-responses.d.ts +0 -13
  311. package/dist/providers/openai-responses.d.ts.map +0 -1
  312. package/dist/providers/openai-responses.js +0 -237
  313. package/dist/providers/openai-responses.js.map +0 -1
  314. package/dist/providers/register-builtins.d.ts +0 -38
  315. package/dist/providers/register-builtins.d.ts.map +0 -1
  316. package/dist/providers/register-builtins.js +0 -278
  317. package/dist/providers/register-builtins.js.map +0 -1
  318. package/dist/providers/simple-options.d.ts +0 -8
  319. package/dist/providers/simple-options.d.ts.map +0 -1
  320. package/dist/providers/simple-options.js +0 -41
  321. package/dist/providers/simple-options.js.map +0 -1
  322. package/dist/providers/transform-messages.d.ts +0 -8
  323. package/dist/providers/transform-messages.d.ts.map +0 -1
  324. package/dist/providers/transform-messages.js +0 -184
  325. package/dist/providers/transform-messages.js.map +0 -1
  326. package/dist/session-resources.d.ts +0 -4
  327. package/dist/session-resources.d.ts.map +0 -1
  328. package/dist/session-resources.js +0 -22
  329. package/dist/session-resources.js.map +0 -1
  330. package/dist/stream.d.ts +0 -8
  331. package/dist/stream.d.ts.map +0 -1
  332. package/dist/stream.js +0 -27
  333. package/dist/stream.js.map +0 -1
  334. package/dist/types.d.ts +0 -498
  335. package/dist/types.d.ts.map +0 -1
  336. package/dist/types.js +0 -2
  337. package/dist/types.js.map +0 -1
  338. package/dist/utils/diagnostics.d.ts +0 -19
  339. package/dist/utils/diagnostics.d.ts.map +0 -1
  340. package/dist/utils/diagnostics.js +0 -25
  341. package/dist/utils/diagnostics.js.map +0 -1
  342. package/dist/utils/event-stream.d.ts +0 -21
  343. package/dist/utils/event-stream.d.ts.map +0 -1
  344. package/dist/utils/event-stream.js +0 -81
  345. package/dist/utils/event-stream.js.map +0 -1
  346. package/dist/utils/hash.d.ts +0 -3
  347. package/dist/utils/hash.d.ts.map +0 -1
  348. package/dist/utils/hash.js +0 -14
  349. package/dist/utils/hash.js.map +0 -1
  350. package/dist/utils/headers.d.ts +0 -2
  351. package/dist/utils/headers.d.ts.map +0 -1
  352. package/dist/utils/headers.js +0 -8
  353. package/dist/utils/headers.js.map +0 -1
  354. package/dist/utils/json-parse.d.ts +0 -16
  355. package/dist/utils/json-parse.d.ts.map +0 -1
  356. package/dist/utils/json-parse.js +0 -113
  357. package/dist/utils/json-parse.js.map +0 -1
  358. package/dist/utils/node-http-proxy.d.ts +0 -10
  359. package/dist/utils/node-http-proxy.d.ts.map +0 -1
  360. package/dist/utils/node-http-proxy.js +0 -97
  361. package/dist/utils/node-http-proxy.js.map +0 -1
  362. package/dist/utils/oauth/anthropic.d.ts +0 -25
  363. package/dist/utils/oauth/anthropic.d.ts.map +0 -1
  364. package/dist/utils/oauth/anthropic.js +0 -335
  365. package/dist/utils/oauth/anthropic.js.map +0 -1
  366. package/dist/utils/oauth/device-code.d.ts +0 -19
  367. package/dist/utils/oauth/device-code.d.ts.map +0 -1
  368. package/dist/utils/oauth/device-code.js +0 -55
  369. package/dist/utils/oauth/device-code.js.map +0 -1
  370. package/dist/utils/oauth/github-copilot.d.ts +0 -30
  371. package/dist/utils/oauth/github-copilot.d.ts.map +0 -1
  372. package/dist/utils/oauth/github-copilot.js +0 -268
  373. package/dist/utils/oauth/github-copilot.js.map +0 -1
  374. package/dist/utils/oauth/google-antigravity.d.ts +0 -26
  375. package/dist/utils/oauth/google-antigravity.d.ts.map +0 -1
  376. package/dist/utils/oauth/google-antigravity.js +0 -377
  377. package/dist/utils/oauth/google-antigravity.js.map +0 -1
  378. package/dist/utils/oauth/google-gemini-cli.d.ts +0 -26
  379. package/dist/utils/oauth/google-gemini-cli.d.ts.map +0 -1
  380. package/dist/utils/oauth/google-gemini-cli.js +0 -482
  381. package/dist/utils/oauth/google-gemini-cli.js.map +0 -1
  382. package/dist/utils/oauth/index.d.ts +0 -63
  383. package/dist/utils/oauth/index.d.ts.map +0 -1
  384. package/dist/utils/oauth/index.js +0 -131
  385. package/dist/utils/oauth/index.js.map +0 -1
  386. package/dist/utils/oauth/oauth-page.d.ts +0 -3
  387. package/dist/utils/oauth/oauth-page.d.ts.map +0 -1
  388. package/dist/utils/oauth/oauth-page.js +0 -105
  389. package/dist/utils/oauth/oauth-page.js.map +0 -1
  390. package/dist/utils/oauth/openai-codex.d.ts +0 -34
  391. package/dist/utils/oauth/openai-codex.d.ts.map +0 -1
  392. package/dist/utils/oauth/openai-codex.js +0 -385
  393. package/dist/utils/oauth/openai-codex.js.map +0 -1
  394. package/dist/utils/oauth/pkce.d.ts +0 -13
  395. package/dist/utils/oauth/pkce.d.ts.map +0 -1
  396. package/dist/utils/oauth/pkce.js +0 -31
  397. package/dist/utils/oauth/pkce.js.map +0 -1
  398. package/dist/utils/oauth/types.d.ts +0 -64
  399. package/dist/utils/oauth/types.d.ts.map +0 -1
  400. package/dist/utils/oauth/types.js +0 -2
  401. package/dist/utils/oauth/types.js.map +0 -1
  402. package/dist/utils/overflow.d.ts +0 -56
  403. package/dist/utils/overflow.d.ts.map +0 -1
  404. package/dist/utils/overflow.js +0 -151
  405. package/dist/utils/overflow.js.map +0 -1
  406. package/dist/utils/sanitize-unicode.d.ts +0 -22
  407. package/dist/utils/sanitize-unicode.d.ts.map +0 -1
  408. package/dist/utils/sanitize-unicode.js +0 -26
  409. package/dist/utils/sanitize-unicode.js.map +0 -1
  410. package/dist/utils/typebox-helpers.d.ts +0 -17
  411. package/dist/utils/typebox-helpers.d.ts.map +0 -1
  412. package/dist/utils/typebox-helpers.js +0 -21
  413. package/dist/utils/typebox-helpers.js.map +0 -1
  414. package/dist/utils/validation.d.ts +0 -18
  415. package/dist/utils/validation.d.ts.map +0 -1
  416. package/dist/utils/validation.js +0 -281
  417. package/dist/utils/validation.js.map +0 -1
@@ -0,0 +1,43 @@
1
+ import type { JsonObject } from "./types";
2
+
3
+ export type DescriptionSpillFormat = "spill" | "paren";
4
+
5
+ function formatSpillValue(value: unknown): string {
6
+ return JSON.stringify(value);
7
+ }
8
+
9
+ function formatParenValue(value: unknown): string {
10
+ return typeof value === "string" ? value : JSON.stringify(value);
11
+ }
12
+
13
+ /**
14
+ * Demote stripped JSON Schema keywords into a node's `description` so the model
15
+ * still receives the constraint as natural-language context after the wire
16
+ * schema drops it.
17
+ */
18
+ export function spillToDescription(
19
+ node: JsonObject,
20
+ entries: ReadonlyArray<readonly [string, unknown]>,
21
+ format: DescriptionSpillFormat = "spill",
22
+ ): void {
23
+ let spilled: Array<readonly [string, unknown]> | undefined;
24
+ for (const entry of entries) {
25
+ if (entry[1] === undefined) continue;
26
+ if (spilled === undefined) spilled = [];
27
+ spilled.push(entry);
28
+ }
29
+ if (spilled === undefined || spilled.length === 0) return;
30
+
31
+ const existing = typeof node.description === "string" ? node.description : "";
32
+ if (format === "paren") {
33
+ let suffix = "";
34
+ for (const [key, value] of spilled) {
35
+ suffix += ` (${key}: ${formatParenValue(value)})`;
36
+ }
37
+ node.description = `${existing}${suffix}`;
38
+ return;
39
+ }
40
+
41
+ const formatted = `{${spilled.map(([key, value]) => `${key}: ${formatSpillValue(value)}`).join(", ")}}`;
42
+ node.description = existing ? `${existing}\n\n${formatted}` : formatted;
43
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Symbol-keyed lazy memoization stamped directly onto the host object.
3
+ *
4
+ * Faster than a module-level `WeakMap` in V8/JSC because the symbol slot is
5
+ * resolved through the object's hidden class instead of a side-table hash
6
+ * lookup. The slot is defined as a non-enumerable property so the stamp
7
+ * does not leak through `{...spread}`, `Object.keys`, `JSON.stringify`, or
8
+ * `toEqual`-style deep equality.
9
+ *
10
+ * Caveats: the stamp lives as long as the host object, even after callers
11
+ * release their references to the cached value — only use this for caches
12
+ * whose lifetime should match the host. Frozen hosts will throw on write in
13
+ * strict mode; callers that may receive frozen input must handle that.
14
+ */
15
+
16
+ function define<T extends object>(target: T, key: symbol, value: unknown): void {
17
+ Object.defineProperty(target, key, { value, writable: true, configurable: true });
18
+ }
19
+
20
+ export function stamp<T extends object, V>(target: T, key: symbol, compute: (target: T) => V): V {
21
+ const slot = target as Record<symbol, V | undefined>;
22
+ const existing = slot[key];
23
+ if (existing !== undefined) return existing;
24
+ const value = compute(target);
25
+ define(target, key, value);
26
+ return value;
27
+ }
28
+
29
+ /**
30
+ * Epoch-keyed cycle guard. Cheaper than `WeakSet` for recursive traversal
31
+ * because the marker is a single property slot on the host object, written
32
+ * once and overwritten in place on every subsequent traversal — the hidden
33
+ * class transitions once per object lifetime, not per traversal.
34
+ *
35
+ * Usage:
36
+ * function walk(node, epoch = epochNext()) {
37
+ * if (!once(node, epoch)) return; // cycle
38
+ * for (const child of node.children) walk(child, epoch);
39
+ * }
40
+ */
41
+ const kEpoch = Symbol("aery.schema.epoch");
42
+ let __epoch = 0;
43
+
44
+ export function epochNext(): number {
45
+ return ++__epoch;
46
+ }
47
+
48
+ /**
49
+ * Marks `target` as visited for this `epoch`. Returns `true` the first time
50
+ * it is called for a given (target, epoch) pair and `false` on every
51
+ * subsequent call within the same epoch.
52
+ */
53
+ export function once<T extends object>(target: T, epoch: number): boolean {
54
+ const slot = target as Record<symbol, number | undefined>;
55
+ const cur = slot[kEpoch];
56
+ if (cur !== undefined && cur >= epoch) return false;
57
+ if (cur === undefined) define(target, kEpoch, epoch);
58
+ else slot[kEpoch] = epoch;
59
+ return true;
60
+ }
61
+
62
+ /**
63
+ * Counter-based path tracker. Use when a traversal needs to distinguish
64
+ * "currently on the recursion path" from "previously visited" — i.e. cycle
65
+ * detection that throws while still allowing DAG sharing. Increment on
66
+ * entry, decrement on exit; the slot returns to 0 after a balanced walk so
67
+ * subsequent top-level calls see a fresh state without any reset.
68
+ *
69
+ * Unlike a `WeakSet` with `seen.delete(...)`, the property is never deleted
70
+ * — only incremented and decremented — so the host object's hidden class
71
+ * is never invalidated.
72
+ *
73
+ * Usage:
74
+ * function walk(node) {
75
+ * if (!enter(node)) throw new Error("cycle");
76
+ * try { for (const c of node.children) walk(c); }
77
+ * finally { exit(node); }
78
+ * }
79
+ */
80
+ const kDepth = Symbol("aery.schema.depth");
81
+
82
+ /** Returns `true` on first entry, `false` if `target` is already on the current path. */
83
+ export function enter<T extends object>(target: T): boolean {
84
+ const slot = target as Record<symbol, number | undefined>;
85
+ const cur = slot[kDepth];
86
+ if (cur === undefined) {
87
+ define(target, kDepth, 1);
88
+ return true;
89
+ }
90
+ slot[kDepth] = cur + 1;
91
+ return cur === 0;
92
+ }
93
+
94
+ export function exit<T extends object>(target: T): void {
95
+ const slot = target as Record<symbol, number>;
96
+ slot[kDepth]--;
97
+ }
@@ -0,0 +1,10 @@
1
+ export type JsonObject = Record<string, unknown>;
2
+
3
+ export function isJsonObject(value: unknown): value is JsonObject {
4
+ return !!value && typeof value === "object" && !Array.isArray(value);
5
+ }
6
+
7
+ /** True when `value` is a plain JSON object with no own enumerable keys. */
8
+ export function isJsonObjectEmpty(value: JsonObject): boolean {
9
+ return Object.keys(value).length === 0;
10
+ }
@@ -0,0 +1,293 @@
1
+ /**
2
+ * Compute the wire (JSON Schema) representation of a tool's parameters and
3
+ * convert TypeBox-style schemas into Zod for internal validation.
4
+ *
5
+ * Tools may author parameters in two shapes:
6
+ * 1. Zod (canonical going forward) — converted to JSON Schema on demand.
7
+ * 2. TypeBox / plain JSON Schema (legacy + extension compat) — upgraded to
8
+ * draft 2020-12 without converting through Zod.
9
+ *
10
+ * Both are normalized at the boundary so providers and validators see the same
11
+ * JSON Schema dialect.
12
+ */
13
+
14
+ // We import the Zod *value* (z) for runtime APIs. Marker checks rely on the
15
+ // `_zod` symbol that every Zod v4 schema instance carries.
16
+ import { type ZodType, z } from "zod/v4";
17
+ import type { Tool, TSchema } from "../../types";
18
+ import { upgradeJsonSchemaTo202012 } from "./draft";
19
+ import { stamp } from "./stamps";
20
+
21
+ /**
22
+ * True when `value` is a live Zod schema instance.
23
+ *
24
+ * The check is stricter than "has a `_zod` property" because a JSON
25
+ * round-trip preserves the `_zod` key as a plain object and would otherwise
26
+ * fool the predicate — see issue #1101, where MCP servers ship
27
+ * `JSON.stringify(zodSchemaInstance)` as a tool's `inputSchema` and the
28
+ * resulting plain object then explodes `z.toJSONSchema` because the prototype
29
+ * (and every Zod parsing method) is gone.
30
+ *
31
+ * Live Zod instances always carry a `.parse` function on the prototype;
32
+ * impostors do not.
33
+ */
34
+ export function isZodSchema(value: unknown): value is ZodType {
35
+ return (
36
+ typeof value === "object" &&
37
+ value !== null &&
38
+ // Zod v4 instances expose a `_zod` internal property with a `def` object.
39
+ // Tagging on this marker keeps the check stable across Zod minor versions.
40
+ // (`_zod` is part of Zod's documented internal contract used by introspection.)
41
+ // We avoid checking constructor name because Zod ships multiple variants
42
+ // (`ZodObject`, `ZodOptional`, etc.) and a tagged-union style check would
43
+ // have to enumerate them all.
44
+ "_zod" in value &&
45
+ typeof (value as { _zod?: { def?: unknown } })._zod === "object" &&
46
+ // Reject JSON-roundtripped objects that kept the `_zod` key but lost the
47
+ // prototype. Real instances have `.parse` on the prototype chain.
48
+ typeof (value as { parse?: unknown }).parse === "function"
49
+ );
50
+ }
51
+
52
+ /** Symbol-stamped caches keyed by schema object identity. */
53
+ const kZodWireSchema = Symbol("aery.schema.zod.wire");
54
+ const kJsonWireSchema = Symbol("aery.schema.json.wire");
55
+
56
+ /**
57
+ * Post-process Zod-emitted JSON Schema so it matches the wire shape providers
58
+ * already expect from TypeBox-authored tools:
59
+ *
60
+ * - Drop the `$schema` URL (providers parse the body, not the metadata).
61
+ * - Make fields with a `default` non-required (TypeBox/JSON-Schema semantics
62
+ * treat defaulted fields as optional; Zod inverts this and keeps them
63
+ * required at the input boundary, then materializes the default).
64
+ * - Strip the noisy safe-integer bounds Zod injects for `z.number().int()`.
65
+ *
66
+ * The empty-schema normalization (`{}` → `true`, see `normalizeEmptySchemas`)
67
+ * runs separately from `toolWireSchema` so both Zod and TypeBox tools get it.
68
+ */
69
+ function postProcess(schema: Record<string, unknown>): Record<string, unknown> {
70
+ delete schema.$schema;
71
+ walk(schema, true);
72
+ normalizeEmptySchemas(schema);
73
+ return schema;
74
+ }
75
+
76
+ function postProcessJsonSchema(schema: Record<string, unknown>): Record<string, unknown> {
77
+ walk(schema, false);
78
+ normalizeEmptySchemas(schema);
79
+ return schema;
80
+ }
81
+
82
+ const SAFE_INTEGER_MAX = Number.MAX_SAFE_INTEGER;
83
+ const SAFE_INTEGER_MIN = Number.MIN_SAFE_INTEGER;
84
+ const NULLABLE_SCALAR_TYPES = new Set(["string", "number", "integer", "boolean"]);
85
+
86
+ const SCHEMA_DEFINING_SIBLING_KEYS = new Set([
87
+ "$ref",
88
+ "additionalProperties",
89
+ "allOf",
90
+ "anyOf",
91
+ "const",
92
+ "contains",
93
+ "enum",
94
+ "if",
95
+ "items",
96
+ "not",
97
+ "oneOf",
98
+ "patternProperties",
99
+ "prefixItems",
100
+ "properties",
101
+ "propertyNames",
102
+ "then",
103
+ "else",
104
+ "unevaluatedItems",
105
+ "unevaluatedProperties",
106
+ ]);
107
+
108
+ function isSchemaRecord(value: unknown): value is Record<string, unknown> {
109
+ return value !== null && typeof value === "object" && !Array.isArray(value);
110
+ }
111
+
112
+ function hasSchemaDefiningSibling(schema: Record<string, unknown>): boolean {
113
+ for (const key in schema) {
114
+ if (key !== "anyOf" && SCHEMA_DEFINING_SIBLING_KEYS.has(key)) return true;
115
+ }
116
+ return false;
117
+ }
118
+
119
+ function isNullVariant(schema: Record<string, unknown>): boolean {
120
+ return schema.type === "null" && Object.keys(schema).length === 1;
121
+ }
122
+
123
+ function isScalarVariant(schema: Record<string, unknown>): schema is Record<string, unknown> & { type: string } {
124
+ return typeof schema.type === "string" && NULLABLE_SCALAR_TYPES.has(schema.type);
125
+ }
126
+
127
+ function hasIntegerType(type: unknown): boolean {
128
+ return type === "integer" || (Array.isArray(type) && type.includes("integer"));
129
+ }
130
+
131
+ function rewriteNullableScalarAnyOf(schema: Record<string, unknown>): void {
132
+ if (hasSchemaDefiningSibling(schema)) return;
133
+ const variants = schema.anyOf;
134
+ if (!Array.isArray(variants) || variants.length !== 2) return;
135
+
136
+ let scalarVariant: Record<string, unknown> | undefined;
137
+ let scalarType: string | undefined;
138
+ let sawNull = false;
139
+ for (const variant of variants) {
140
+ if (!isSchemaRecord(variant)) return;
141
+ if (isNullVariant(variant)) {
142
+ if (sawNull) return;
143
+ sawNull = true;
144
+ continue;
145
+ }
146
+ if (!isScalarVariant(variant) || scalarVariant) return;
147
+ scalarVariant = variant;
148
+ scalarType = variant.type;
149
+ }
150
+ if (!sawNull || !scalarVariant || !scalarType) return;
151
+
152
+ delete schema.anyOf;
153
+ for (const key in scalarVariant) {
154
+ if (key !== "type" && !Object.hasOwn(schema, key)) schema[key] = scalarVariant[key];
155
+ }
156
+ schema.type = [scalarType, "null"];
157
+ }
158
+
159
+ /** Keys whose values are a single JSON Schema (not an array or map). */
160
+ const SCHEMA_VALUE_KEYS = [
161
+ "additionalProperties",
162
+ "unevaluatedProperties",
163
+ "unevaluatedItems",
164
+ "items",
165
+ "contains",
166
+ "propertyNames",
167
+ "if",
168
+ "then",
169
+ "else",
170
+ "not",
171
+ ] as const;
172
+
173
+ /** Keys whose values are a map of `{ key: Schema }` entries. */
174
+ const SCHEMA_MAP_KEYS = ["properties", "patternProperties", "$defs", "definitions"] as const;
175
+
176
+ /** Keys whose values are an array of schemas. */
177
+ const SCHEMA_ARRAY_KEYS = ["anyOf", "oneOf", "allOf", "prefixItems"] as const;
178
+
179
+ /** True when `val` is a plain empty object `{}`. */
180
+ function isEmptyObject(val: unknown): val is Record<string, never> {
181
+ if (val === null || typeof val !== "object" || Array.isArray(val)) return false;
182
+ return Object.keys(val).length === 0;
183
+ }
184
+
185
+ function walk(node: unknown, zodCleanup: boolean): void {
186
+ if (Array.isArray(node)) {
187
+ for (const child of node) walk(child, zodCleanup);
188
+ return;
189
+ }
190
+ if (!node || typeof node !== "object") return;
191
+ const obj = node as Record<string, unknown>;
192
+ rewriteNullableScalarAnyOf(obj);
193
+
194
+ if (zodCleanup) {
195
+ // Drop noise injected for `z.number().int()`.
196
+ if (hasIntegerType(obj.type)) {
197
+ if (obj.minimum === SAFE_INTEGER_MIN) delete obj.minimum;
198
+ if (obj.maximum === SAFE_INTEGER_MAX) delete obj.maximum;
199
+ }
200
+
201
+ // Make defaulted properties non-required.
202
+ if (Array.isArray(obj.required) && obj.properties && typeof obj.properties === "object") {
203
+ const properties = obj.properties as Record<string, unknown>;
204
+ const required = obj.required as string[];
205
+ const filtered = required.filter(name => {
206
+ const propertySchema = properties[name];
207
+ if (!propertySchema || typeof propertySchema !== "object") return true;
208
+ return !("default" in (propertySchema as Record<string, unknown>));
209
+ });
210
+ if (filtered.length !== required.length) {
211
+ if (filtered.length === 0) {
212
+ delete obj.required;
213
+ } else {
214
+ obj.required = filtered;
215
+ }
216
+ }
217
+ }
218
+ }
219
+
220
+ for (const k in obj) walk(obj[k], zodCleanup);
221
+ }
222
+
223
+ /**
224
+ * Normalize `{}` (empty JSON Schema = `z.unknown()` / unconstrained value) to
225
+ * boolean `true` in every schema-valued position. JSON Schema draft 2020-12
226
+ * §4.3.1: `{}` and `true` are semantically equivalent ("any JSON value").
227
+ * Grammar-constrained samplers (llama.cpp, etc.) treat the object form as
228
+ * "generate an empty object" rather than "any JSON value", causing open-typed
229
+ * fields like `extra.title` (from `z.record(z.string(), z.unknown())`) to
230
+ * always emit `{}` instead of the intended string/number/etc. (issue #1179).
231
+ *
232
+ * Mutates in place. Provider-agnostic — applied to every tool wire schema so
233
+ * Anthropic, Google, OpenAI, Ollama, Bedrock, and Cursor all see the
234
+ * normalized form, regardless of whether the source was Zod or TypeBox.
235
+ */
236
+ export function normalizeEmptySchemas(node: unknown): void {
237
+ if (Array.isArray(node)) {
238
+ for (const child of node) normalizeEmptySchemas(child);
239
+ return;
240
+ }
241
+ if (!node || typeof node !== "object") return;
242
+ const obj = node as Record<string, unknown>;
243
+
244
+ for (const key of SCHEMA_VALUE_KEYS) {
245
+ if (Object.hasOwn(obj, key) && isEmptyObject(obj[key])) obj[key] = true;
246
+ }
247
+ for (const mapKey of SCHEMA_MAP_KEYS) {
248
+ const map = obj[mapKey];
249
+ if (map !== null && typeof map === "object" && !Array.isArray(map)) {
250
+ for (const k in map as Record<string, unknown>) {
251
+ if (isEmptyObject((map as Record<string, unknown>)[k])) (map as Record<string, unknown>)[k] = true;
252
+ }
253
+ }
254
+ }
255
+ for (const arrKey of SCHEMA_ARRAY_KEYS) {
256
+ const arr = obj[arrKey];
257
+ if (Array.isArray(arr)) {
258
+ for (let i = 0; i < arr.length; i++) {
259
+ if (isEmptyObject(arr[i])) arr[i] = true;
260
+ }
261
+ }
262
+ }
263
+
264
+ for (const k in obj) normalizeEmptySchemas(obj[k]);
265
+ }
266
+
267
+ /** Convert a Zod schema into the JSON Schema shape providers consume. */
268
+ export function zodToWireSchema(schema: ZodType): Record<string, unknown> {
269
+ return stamp(schema, kZodWireSchema, s => {
270
+ // `target: "draft-2020-12"` matches what Anthropic's `input_schema` validator
271
+ // requires out of the box; our other provider sanitizers (OpenAI strict,
272
+ // Google, Anthropic CCA) already handle the superset structurally.
273
+ const raw = z.toJSONSchema(s, { target: "draft-2020-12" }) as Record<string, unknown>;
274
+ return postProcess(raw);
275
+ });
276
+ }
277
+
278
+ /**
279
+ * Resolve a tool's parameters to a JSON Schema object suitable for sending
280
+ * over the wire. Zod schemas are converted (and cached); legacy TypeBox / raw
281
+ * JSON Schema parameters are upgraded to draft 2020-12 (and cached).
282
+ *
283
+ * Zod schemas also receive Zod-artifact cleanup; both branches normalize
284
+ * schema-valued positions and nullable scalar unions.
285
+ */
286
+ export function toolWireSchema(tool: Tool): Record<string, unknown> {
287
+ const params: TSchema = tool.parameters;
288
+ if (isZodSchema(params)) return zodToWireSchema(params);
289
+ return stamp(params as Record<string, unknown>, kJsonWireSchema, p => {
290
+ const upgraded = upgradeJsonSchemaTo202012(p) as Record<string, unknown>;
291
+ return postProcessJsonSchema(upgraded);
292
+ });
293
+ }