@prometheus-ai/ai 0.5.4 → 0.5.8

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 (377) hide show
  1. package/dist/types/auth-broker/remote-store.d.ts +2 -1
  2. package/dist/types/auth-broker/wire-schemas.d.ts +4 -1
  3. package/dist/types/auth-gateway/server.d.ts +19 -0
  4. package/dist/types/auth-gateway/types.d.ts +9 -3
  5. package/dist/types/auth-retry.d.ts +119 -0
  6. package/dist/types/auth-storage.d.ts +217 -8
  7. package/dist/types/errors.d.ts +24 -0
  8. package/dist/types/index.d.ts +5 -9
  9. package/dist/types/provider-details.d.ts +1 -1
  10. package/dist/types/providers/amazon-bedrock.d.ts +12 -6
  11. package/dist/types/providers/anthropic-client.d.ts +10 -3
  12. package/dist/types/providers/anthropic-messages-server-schema.d.ts +2 -2
  13. package/dist/types/providers/anthropic-messages-server.d.ts +3 -3
  14. package/dist/types/providers/anthropic-wire.d.ts +3 -3
  15. package/dist/types/providers/anthropic.d.ts +41 -34
  16. package/dist/types/providers/aws-credentials.d.ts +8 -0
  17. package/dist/types/providers/azure-openai-responses.d.ts +1 -0
  18. package/dist/types/providers/google-gemini-cli.d.ts +22 -1
  19. package/dist/types/providers/google-shared.d.ts +22 -0
  20. package/dist/types/providers/google-types.d.ts +13 -1
  21. package/dist/types/providers/mock.d.ts +8 -3
  22. package/dist/types/providers/ollama.d.ts +6 -0
  23. package/dist/types/providers/openai-chat-server-schema.d.ts +6 -3
  24. package/dist/types/providers/openai-chat-server.d.ts +3 -3
  25. package/dist/types/providers/openai-chat-wire.d.ts +644 -0
  26. package/dist/types/providers/openai-codex/request-transformer.d.ts +8 -0
  27. package/dist/types/providers/openai-codex/response-handler.d.ts +9 -0
  28. package/dist/types/providers/openai-codex-responses.d.ts +31 -2
  29. package/dist/types/providers/openai-completions-compat.d.ts +2 -25
  30. package/dist/types/providers/openai-completions.d.ts +2 -10
  31. package/dist/types/providers/openai-responses-server-schema.d.ts +4 -4
  32. package/dist/types/providers/openai-responses-server.d.ts +2 -2
  33. package/dist/types/providers/openai-responses-shared.d.ts +49 -9
  34. package/dist/types/providers/openai-responses-wire.d.ts +6065 -0
  35. package/dist/types/providers/openai-responses.d.ts +13 -4
  36. package/dist/types/providers/prometheus-native-client.d.ts +9 -0
  37. package/dist/types/providers/prometheus-native-server.d.ts +4 -3
  38. package/dist/types/providers/transform-messages.d.ts +1 -2
  39. package/dist/types/rate-limit-utils.d.ts +3 -2
  40. package/dist/types/registry/aimlapi.d.ts +4 -0
  41. package/dist/types/registry/alibaba-coding-plan.d.ts +7 -0
  42. package/dist/types/registry/amazon-bedrock.d.ts +5 -0
  43. package/dist/types/registry/anthropic.d.ts +10 -0
  44. package/dist/types/{utils/oauth → registry}/api-key-login.d.ts +8 -2
  45. package/dist/types/{utils/oauth → registry}/api-key-validation.d.ts +15 -0
  46. package/dist/types/registry/cerebras.d.ts +7 -0
  47. package/dist/types/registry/cloudflare-ai-gateway.d.ts +13 -0
  48. package/dist/types/registry/cursor.d.ts +7 -0
  49. package/dist/types/registry/deepseek.d.ts +8 -0
  50. package/dist/types/registry/derived.d.ts +5 -0
  51. package/dist/types/registry/firepass.d.ts +16 -0
  52. package/dist/types/registry/fireworks.d.ts +7 -0
  53. package/dist/types/registry/github-copilot.d.ts +7 -0
  54. package/dist/types/registry/gitlab-duo.d.ts +9 -0
  55. package/dist/types/registry/google-antigravity.d.ts +9 -0
  56. package/dist/types/registry/google-gemini-cli.d.ts +9 -0
  57. package/dist/types/registry/google-vertex.d.ts +5 -0
  58. package/dist/types/registry/google.d.ts +4 -0
  59. package/dist/types/registry/groq.d.ts +4 -0
  60. package/dist/types/registry/huggingface.d.ts +7 -0
  61. package/dist/types/registry/index.d.ts +4 -0
  62. package/dist/types/registry/kagi.d.ts +14 -0
  63. package/dist/types/registry/kilo.d.ts +7 -0
  64. package/dist/types/registry/kimi-code.d.ts +7 -0
  65. package/dist/types/registry/litellm.d.ts +13 -0
  66. package/dist/types/registry/lm-studio.d.ts +8 -0
  67. package/dist/types/registry/minimax-code-cn.d.ts +6 -0
  68. package/dist/types/registry/minimax-code.d.ts +6 -0
  69. package/dist/types/registry/minimax.d.ts +4 -0
  70. package/dist/types/registry/mistral.d.ts +4 -0
  71. package/dist/types/registry/moonshot.d.ts +7 -0
  72. package/dist/types/registry/nanogpt.d.ts +7 -0
  73. package/dist/types/registry/nvidia.d.ts +7 -0
  74. package/dist/types/registry/oauth/__tests__/xai-oauth.test.d.ts +1 -0
  75. package/dist/types/{utils → registry}/oauth/anthropic.d.ts +2 -1
  76. package/dist/types/{utils → registry}/oauth/github-copilot.d.ts +15 -23
  77. package/dist/types/{utils → registry}/oauth/index.d.ts +1 -0
  78. package/dist/types/{utils → registry}/oauth/minimax-code.d.ts +5 -5
  79. package/dist/types/{utils → registry}/oauth/types.d.ts +6 -1
  80. package/dist/types/{utils → registry}/oauth/xai-oauth.d.ts +2 -1
  81. package/dist/types/registry/ollama-cloud.d.ts +7 -0
  82. package/dist/types/registry/ollama.d.ts +12 -0
  83. package/dist/types/registry/openai-codex-device.d.ts +8 -0
  84. package/dist/types/registry/openai-codex.d.ts +9 -0
  85. package/dist/types/registry/openai.d.ts +4 -0
  86. package/dist/types/registry/opencode-go.d.ts +6 -0
  87. package/dist/types/registry/opencode-zen.d.ts +6 -0
  88. package/dist/types/registry/openrouter.d.ts +13 -0
  89. package/dist/types/registry/parallel.d.ts +14 -0
  90. package/dist/types/registry/perplexity.d.ts +7 -0
  91. package/dist/types/registry/qianfan.d.ts +7 -0
  92. package/dist/types/registry/qwen-portal.d.ts +7 -0
  93. package/dist/types/registry/registry.d.ts +272 -0
  94. package/dist/types/registry/synthetic.d.ts +6 -0
  95. package/dist/types/registry/tavily.d.ts +14 -0
  96. package/dist/types/registry/together.d.ts +6 -0
  97. package/dist/types/registry/types.d.ts +51 -0
  98. package/dist/types/registry/venice.d.ts +13 -0
  99. package/dist/types/registry/vercel-ai-gateway.d.ts +7 -0
  100. package/dist/types/registry/vllm.d.ts +7 -0
  101. package/dist/types/registry/wafer-pass.d.ts +6 -0
  102. package/dist/types/registry/wafer-serverless.d.ts +6 -0
  103. package/dist/types/registry/xai-oauth.d.ts +7 -0
  104. package/dist/types/registry/xai.d.ts +4 -0
  105. package/dist/types/registry/xiaomi-token-plan-ams.d.ts +6 -0
  106. package/dist/types/registry/xiaomi-token-plan-cn.d.ts +6 -0
  107. package/dist/types/registry/xiaomi-token-plan-sgp.d.ts +6 -0
  108. package/dist/types/registry/xiaomi.d.ts +6 -0
  109. package/dist/types/registry/zai.d.ts +7 -0
  110. package/dist/types/registry/zenmux.d.ts +7 -0
  111. package/dist/types/registry/zhipu-coding-plan.d.ts +7 -0
  112. package/dist/types/stream.d.ts +9 -1
  113. package/dist/types/types.d.ts +56 -295
  114. package/dist/types/usage/google-antigravity.d.ts +15 -1
  115. package/dist/types/usage/openai-codex-reset.d.ts +79 -0
  116. package/dist/types/usage/openai-codex.d.ts +1 -0
  117. package/dist/types/usage.d.ts +77 -4
  118. package/dist/types/utils/abort.d.ts +6 -0
  119. package/dist/types/utils/event-stream.d.ts +2 -0
  120. package/dist/types/utils/http-inspector.d.ts +0 -1
  121. package/dist/types/utils/idle-iterator.d.ts +35 -0
  122. package/dist/types/utils/openai-http.d.ts +58 -0
  123. package/dist/types/utils/request-debug.d.ts +3 -0
  124. package/dist/types/utils/retry-after.d.ts +1 -0
  125. package/dist/types/utils/schema/fields.d.ts +5 -0
  126. package/dist/types/utils/schema/json-schema-validator.d.ts +8 -0
  127. package/dist/types/utils/schema/stamps.d.ts +7 -15
  128. package/dist/types/utils/sse-debug.d.ts +0 -5
  129. package/dist/types/utils/stream-markup-healing.d.ts +2 -0
  130. package/dist/types/utils.d.ts +1 -5
  131. package/package.json +17 -29
  132. package/src/auth-broker/remote-store.ts +10 -1
  133. package/src/auth-broker/snapshot-cache.ts +1 -1
  134. package/src/auth-broker/wire-schemas.ts +1 -1
  135. package/src/auth-gateway/http.ts +1 -1
  136. package/src/auth-gateway/server.ts +95 -30
  137. package/src/auth-gateway/types.ts +10 -2
  138. package/src/auth-retry.ts +238 -0
  139. package/src/auth-storage.ts +935 -430
  140. package/src/errors.ts +32 -0
  141. package/src/index.ts +9 -14
  142. package/src/provider-details.ts +1 -1
  143. package/src/providers/__tests__/google-auth.test.ts +144 -0
  144. package/src/providers/amazon-bedrock.ts +70 -40
  145. package/src/providers/anthropic-client.ts +15 -13
  146. package/src/providers/anthropic-messages-server-schema.ts +17 -7
  147. package/src/providers/anthropic-messages-server.ts +88 -20
  148. package/src/providers/anthropic-wire.ts +4 -3
  149. package/src/providers/anthropic.ts +1234 -621
  150. package/src/providers/aws-credentials.ts +47 -5
  151. package/src/providers/aws-eventstream.ts +5 -0
  152. package/src/providers/azure-openai-responses.ts +117 -67
  153. package/src/providers/cursor.ts +30 -30
  154. package/src/providers/github-copilot-headers.ts +1 -1
  155. package/src/providers/gitlab-duo.ts +36 -29
  156. package/src/providers/google-auth.ts +71 -8
  157. package/src/providers/google-gemini-cli.ts +118 -22
  158. package/src/providers/google-shared.ts +163 -43
  159. package/src/providers/google-types.ts +10 -1
  160. package/src/providers/kimi.ts +1 -1
  161. package/src/providers/mock.ts +11 -3
  162. package/src/providers/ollama.ts +64 -7
  163. package/src/providers/openai-anthropic-shim.ts +17 -8
  164. package/src/providers/openai-chat-server-schema.ts +9 -3
  165. package/src/providers/openai-chat-server.ts +82 -16
  166. package/src/providers/openai-chat-wire.ts +847 -0
  167. package/src/providers/openai-codex/request-transformer.ts +129 -34
  168. package/src/providers/openai-codex/response-handler.ts +22 -1
  169. package/src/providers/openai-codex-responses.ts +699 -247
  170. package/src/providers/openai-completions-compat.ts +8 -308
  171. package/src/providers/openai-completions.ts +416 -267
  172. package/src/providers/openai-responses-server-schema.ts +15 -9
  173. package/src/providers/openai-responses-server.ts +162 -114
  174. package/src/providers/openai-responses-shared.ts +320 -82
  175. package/src/providers/openai-responses-wire.ts +6391 -0
  176. package/src/providers/openai-responses.ts +382 -176
  177. package/src/providers/prometheus-native-client.ts +27 -11
  178. package/src/providers/prometheus-native-server.ts +44 -17
  179. package/src/providers/transform-messages.ts +311 -120
  180. package/src/providers/vision-guard.ts +5 -3
  181. package/src/rate-limit-utils.ts +13 -3
  182. package/src/registry/aimlapi.ts +6 -0
  183. package/src/{utils/oauth → registry}/alibaba-coding-plan.ts +8 -18
  184. package/src/registry/amazon-bedrock.ts +22 -0
  185. package/src/registry/anthropic.ts +26 -0
  186. package/src/{utils/oauth → registry}/api-key-login.ts +25 -3
  187. package/src/{utils/oauth → registry}/api-key-validation.ts +62 -2
  188. package/src/{utils/oauth → registry}/cerebras.ts +8 -1
  189. package/src/{utils/oauth → registry}/cloudflare-ai-gateway.ts +8 -12
  190. package/src/registry/cursor.ts +20 -0
  191. package/src/{utils/oauth → registry}/deepseek.ts +9 -17
  192. package/src/registry/derived.ts +9 -0
  193. package/src/{utils/oauth → registry}/firepass.ts +10 -2
  194. package/src/{utils/oauth → registry}/fireworks.ts +8 -1
  195. package/src/registry/github-copilot.ts +22 -0
  196. package/src/registry/gitlab-duo.ts +19 -0
  197. package/src/registry/google-antigravity.ts +21 -0
  198. package/src/registry/google-gemini-cli.ts +21 -0
  199. package/src/registry/google-vertex.ts +38 -0
  200. package/src/registry/google.ts +6 -0
  201. package/src/registry/groq.ts +6 -0
  202. package/src/{utils/oauth → registry}/huggingface.ts +8 -19
  203. package/src/registry/index.ts +4 -0
  204. package/src/{utils/oauth → registry}/kagi.ts +9 -11
  205. package/src/{utils/oauth → registry}/kilo.ts +11 -6
  206. package/src/registry/kimi-code.ts +17 -0
  207. package/src/{utils/oauth → registry}/litellm.ts +8 -12
  208. package/src/{utils/oauth → registry}/lm-studio.ts +9 -17
  209. package/src/registry/minimax-code-cn.ts +12 -0
  210. package/src/registry/minimax-code.ts +12 -0
  211. package/src/registry/minimax.ts +6 -0
  212. package/src/registry/mistral.ts +6 -0
  213. package/src/{utils/oauth → registry}/moonshot.ts +8 -9
  214. package/src/{utils/oauth → registry}/nanogpt.ts +8 -1
  215. package/src/{utils/oauth → registry}/nvidia.ts +8 -18
  216. package/src/{utils → registry}/oauth/__tests__/xai-oauth.test.ts +4 -7
  217. package/src/{utils → registry}/oauth/anthropic.ts +38 -17
  218. package/src/{utils → registry}/oauth/github-copilot.ts +79 -115
  219. package/src/registry/oauth/gitlab-duo.ts +198 -0
  220. package/src/{utils → registry}/oauth/google-antigravity.ts +1 -4
  221. package/src/{utils → registry}/oauth/google-gemini-cli.ts +1 -4
  222. package/src/registry/oauth/index.ts +164 -0
  223. package/src/{utils → registry}/oauth/minimax-code.ts +16 -14
  224. package/src/{utils → registry}/oauth/types.ts +7 -51
  225. package/src/{utils → registry}/oauth/wafer.ts +1 -1
  226. package/src/{utils → registry}/oauth/xai-oauth.ts +16 -8
  227. package/src/{utils → registry}/oauth/xiaomi.ts +9 -4
  228. package/src/{utils/oauth → registry}/ollama-cloud.ts +8 -1
  229. package/src/{utils/oauth → registry}/ollama.ts +8 -13
  230. package/src/registry/openai-codex-device.ts +18 -0
  231. package/src/registry/openai-codex.ts +19 -0
  232. package/src/registry/openai.ts +6 -0
  233. package/src/registry/opencode-go.ts +12 -0
  234. package/src/registry/opencode-zen.ts +12 -0
  235. package/src/{utils/oauth → registry}/openrouter.ts +10 -2
  236. package/src/{utils/oauth → registry}/parallel.ts +9 -11
  237. package/src/registry/perplexity.ts +13 -0
  238. package/src/{utils/oauth → registry}/qianfan.ts +8 -17
  239. package/src/{utils/oauth → registry}/qwen-portal.ts +8 -19
  240. package/src/registry/registry.ts +149 -0
  241. package/src/{utils/oauth → registry}/synthetic.ts +7 -1
  242. package/src/{utils/oauth → registry}/tavily.ts +10 -12
  243. package/src/{utils/oauth → registry}/together.ts +7 -1
  244. package/src/registry/types.ts +56 -0
  245. package/src/{utils/oauth → registry}/venice.ts +8 -12
  246. package/src/{utils/oauth → registry}/vercel-ai-gateway.ts +8 -18
  247. package/src/{utils/oauth → registry}/vllm.ts +9 -16
  248. package/src/registry/wafer-pass.ts +12 -0
  249. package/src/registry/wafer-serverless.ts +12 -0
  250. package/src/registry/xai-oauth.ts +17 -0
  251. package/src/registry/xai.ts +6 -0
  252. package/src/registry/xiaomi-token-plan-ams.ts +12 -0
  253. package/src/registry/xiaomi-token-plan-cn.ts +12 -0
  254. package/src/registry/xiaomi-token-plan-sgp.ts +12 -0
  255. package/src/registry/xiaomi.ts +12 -0
  256. package/src/{utils/oauth → registry}/zai.ts +10 -22
  257. package/src/{utils/oauth → registry}/zenmux.ts +8 -1
  258. package/src/{utils/oauth/zhipu.ts → registry/zhipu-coding-plan.ts} +9 -21
  259. package/src/stream.ts +229 -199
  260. package/src/types.ts +63 -384
  261. package/src/usage/claude.ts +4 -2
  262. package/src/usage/github-copilot.ts +4 -2
  263. package/src/usage/google-antigravity.ts +196 -28
  264. package/src/usage/kimi.ts +1 -1
  265. package/src/usage/minimax-code.ts +5 -6
  266. package/src/usage/openai-codex-reset.ts +174 -0
  267. package/src/usage/openai-codex.ts +19 -2
  268. package/src/usage/zai.ts +2 -1
  269. package/src/usage.ts +93 -4
  270. package/src/utils/abort.ts +14 -0
  271. package/src/utils/event-stream.ts +17 -0
  272. package/src/utils/http-inspector.ts +4 -12
  273. package/src/utils/idle-iterator.ts +250 -79
  274. package/src/utils/openai-http.ts +157 -0
  275. package/src/utils/request-debug.ts +67 -19
  276. package/src/utils/retry-after.ts +1 -1
  277. package/src/utils/retry.ts +23 -2
  278. package/src/utils/schema/CONSTRAINTS.md +4 -2
  279. package/src/utils/schema/fields.ts +16 -0
  280. package/src/utils/schema/json-schema-validator.ts +19 -1
  281. package/src/utils/schema/normalize.ts +80 -8
  282. package/src/utils/schema/stamps.ts +22 -10
  283. package/src/utils/schema/wire.ts +2 -2
  284. package/src/utils/sse-debug.ts +0 -271
  285. package/src/utils/stream-markup-healing.ts +50 -8
  286. package/src/utils/validation.ts +49 -13
  287. package/src/utils.ts +2 -26
  288. package/dist/types/model-cache.d.ts +0 -17
  289. package/dist/types/model-manager.d.ts +0 -64
  290. package/dist/types/model-thinking.d.ts +0 -100
  291. package/dist/types/models.d.ts +0 -12
  292. package/dist/types/provider-models/bundled-references.d.ts +0 -4
  293. package/dist/types/provider-models/descriptors.d.ts +0 -50
  294. package/dist/types/provider-models/google.d.ts +0 -24
  295. package/dist/types/provider-models/index.d.ts +0 -5
  296. package/dist/types/provider-models/ollama.d.ts +0 -7
  297. package/dist/types/provider-models/openai-compat.d.ts +0 -323
  298. package/dist/types/provider-models/special.d.ts +0 -16
  299. package/dist/types/utils/discovery/antigravity.d.ts +0 -61
  300. package/dist/types/utils/discovery/codex.d.ts +0 -38
  301. package/dist/types/utils/discovery/cursor.d.ts +0 -23
  302. package/dist/types/utils/discovery/gemini.d.ts +0 -25
  303. package/dist/types/utils/discovery/index.d.ts +0 -4
  304. package/dist/types/utils/discovery/openai-compatible.d.ts +0 -72
  305. package/dist/types/utils/oauth/alibaba-coding-plan.d.ts +0 -18
  306. package/dist/types/utils/oauth/cerebras.d.ts +0 -1
  307. package/dist/types/utils/oauth/cloudflare-ai-gateway.d.ts +0 -18
  308. package/dist/types/utils/oauth/deepseek.d.ts +0 -10
  309. package/dist/types/utils/oauth/firepass.d.ts +0 -1
  310. package/dist/types/utils/oauth/fireworks.d.ts +0 -1
  311. package/dist/types/utils/oauth/huggingface.d.ts +0 -19
  312. package/dist/types/utils/oauth/kagi.d.ts +0 -17
  313. package/dist/types/utils/oauth/kilo.d.ts +0 -5
  314. package/dist/types/utils/oauth/litellm.d.ts +0 -18
  315. package/dist/types/utils/oauth/lm-studio.d.ts +0 -17
  316. package/dist/types/utils/oauth/moonshot.d.ts +0 -1
  317. package/dist/types/utils/oauth/nanogpt.d.ts +0 -1
  318. package/dist/types/utils/oauth/nvidia.d.ts +0 -18
  319. package/dist/types/utils/oauth/ollama-cloud.d.ts +0 -2
  320. package/dist/types/utils/oauth/ollama.d.ts +0 -18
  321. package/dist/types/utils/oauth/openrouter.d.ts +0 -1
  322. package/dist/types/utils/oauth/parallel.d.ts +0 -17
  323. package/dist/types/utils/oauth/qianfan.d.ts +0 -17
  324. package/dist/types/utils/oauth/qwen-portal.d.ts +0 -19
  325. package/dist/types/utils/oauth/synthetic.d.ts +0 -1
  326. package/dist/types/utils/oauth/tavily.d.ts +0 -17
  327. package/dist/types/utils/oauth/together.d.ts +0 -1
  328. package/dist/types/utils/oauth/venice.d.ts +0 -18
  329. package/dist/types/utils/oauth/vercel-ai-gateway.d.ts +0 -18
  330. package/dist/types/utils/oauth/vllm.d.ts +0 -16
  331. package/dist/types/utils/oauth/zai.d.ts +0 -18
  332. package/dist/types/utils/oauth/zenmux.d.ts +0 -1
  333. package/dist/types/utils/oauth/zhipu.d.ts +0 -18
  334. package/src/model-cache.ts +0 -129
  335. package/src/model-manager.ts +0 -469
  336. package/src/model-thinking.ts +0 -756
  337. package/src/models.json +0 -60287
  338. package/src/models.json.d.ts +0 -9
  339. package/src/models.ts +0 -56
  340. package/src/provider-models/bundled-references.ts +0 -38
  341. package/src/provider-models/descriptors.ts +0 -364
  342. package/src/provider-models/google.ts +0 -88
  343. package/src/provider-models/index.ts +0 -5
  344. package/src/provider-models/ollama.ts +0 -153
  345. package/src/provider-models/openai-compat.ts +0 -2904
  346. package/src/provider-models/special.ts +0 -67
  347. package/src/utils/discovery/antigravity.ts +0 -261
  348. package/src/utils/discovery/codex.ts +0 -371
  349. package/src/utils/discovery/cursor.ts +0 -306
  350. package/src/utils/discovery/gemini.ts +0 -248
  351. package/src/utils/discovery/index.ts +0 -4
  352. package/src/utils/discovery/openai-compatible.ts +0 -224
  353. package/src/utils/oauth/gitlab-duo.ts +0 -123
  354. package/src/utils/oauth/index.ts +0 -502
  355. /package/dist/types/{utils/oauth/__tests__/xai-oauth.test.d.ts → providers/__tests__/google-auth.test.d.ts} +0 -0
  356. /package/dist/types/{utils → registry}/oauth/callback-server.d.ts +0 -0
  357. /package/dist/types/{utils → registry}/oauth/cursor.d.ts +0 -0
  358. /package/dist/types/{utils → registry}/oauth/gitlab-duo.d.ts +0 -0
  359. /package/dist/types/{utils → registry}/oauth/google-antigravity.d.ts +0 -0
  360. /package/dist/types/{utils → registry}/oauth/google-gemini-cli.d.ts +0 -0
  361. /package/dist/types/{utils → registry}/oauth/google-oauth-shared.d.ts +0 -0
  362. /package/dist/types/{utils → registry}/oauth/kimi.d.ts +0 -0
  363. /package/dist/types/{utils → registry}/oauth/openai-codex.d.ts +0 -0
  364. /package/dist/types/{utils → registry}/oauth/opencode.d.ts +0 -0
  365. /package/dist/types/{utils → registry}/oauth/perplexity.d.ts +0 -0
  366. /package/dist/types/{utils → registry}/oauth/pkce.d.ts +0 -0
  367. /package/dist/types/{utils → registry}/oauth/wafer.d.ts +0 -0
  368. /package/dist/types/{utils → registry}/oauth/xiaomi.d.ts +0 -0
  369. /package/src/{utils → registry}/oauth/callback-server.ts +0 -0
  370. /package/src/{utils → registry}/oauth/cursor.ts +0 -0
  371. /package/src/{utils → registry}/oauth/google-oauth-shared.ts +0 -0
  372. /package/src/{utils → registry}/oauth/kimi.ts +0 -0
  373. /package/src/{utils → registry}/oauth/oauth.html +0 -0
  374. /package/src/{utils → registry}/oauth/openai-codex.ts +0 -0
  375. /package/src/{utils → registry}/oauth/opencode.ts +0 -0
  376. /package/src/{utils → registry}/oauth/perplexity.ts +0 -0
  377. /package/src/{utils → registry}/oauth/pkce.ts +0 -0
@@ -1,756 +0,0 @@
1
- import { resolveOpenAICompat } from "./providers/openai-completions-compat";
2
- import type { Api, Model as ApiModel, ThinkingConfig } from "./types";
3
-
4
- /** User-facing thinking levels, ordered least to most intensive. */
5
- export const enum Effort {
6
- Minimal = "minimal",
7
- Low = "low",
8
- Medium = "medium",
9
- High = "high",
10
- XHigh = "xhigh",
11
- }
12
-
13
- export const THINKING_EFFORTS: readonly Effort[] = [
14
- Effort.Minimal,
15
- Effort.Low,
16
- Effort.Medium,
17
- Effort.High,
18
- Effort.XHigh,
19
- ];
20
-
21
- const DEFAULT_REASONING_EFFORTS: readonly Effort[] = [Effort.Minimal, Effort.Low, Effort.Medium, Effort.High];
22
- const DEFAULT_REASONING_EFFORTS_WITH_XHIGH: readonly Effort[] = [
23
- Effort.Minimal,
24
- Effort.Low,
25
- Effort.Medium,
26
- Effort.High,
27
- Effort.XHigh,
28
- ];
29
- const GEMINI_3_PRO_EFFORTS: readonly Effort[] = [Effort.Low, Effort.High];
30
- const GEMINI_3_FLASH_EFFORTS: readonly Effort[] = [Effort.Minimal, Effort.Low, Effort.Medium, Effort.High];
31
- const GPT_5_2_PLUS_EFFORTS: readonly Effort[] = [Effort.Low, Effort.Medium, Effort.High, Effort.XHigh];
32
- const GPT_5_1_CODEX_MINI_EFFORTS: readonly Effort[] = [Effort.Medium, Effort.High];
33
- const CLOUDFLARE_AI_GATEWAY_BASE_URL = "https://gateway.ai.cloudflare.com/v1/<account>/<gateway>/anthropic";
34
-
35
- type SemVer = {
36
- major: number;
37
- minor: number;
38
- patch: number;
39
- };
40
-
41
- type GeminiKind = "pro" | "flash";
42
- type AnthropicKind = "opus" | "sonnet";
43
- type OpenAIVariant = "base" | "codex" | "codex-max" | "codex-mini" | "codex-spark" | "mini" | "max" | "nano";
44
-
45
- const CODEX_GPT_5_4_PRIORITY_BY_VARIANT: Partial<Record<OpenAIVariant, number>> = {
46
- base: 0,
47
- mini: 1,
48
- nano: 2,
49
- };
50
-
51
- const COPILOT_GENERATED_LIMITS: Record<string, { contextWindow: number; maxTokens: number }> = {
52
- "claude-opus-4.6": { contextWindow: 168000, maxTokens: 32000 },
53
- "gpt-5.2": { contextWindow: 272000, maxTokens: 128000 },
54
- "gpt-5.4": { contextWindow: 272000, maxTokens: 128000 },
55
- "gpt-5.4-mini": { contextWindow: 272000, maxTokens: 128000 },
56
- "grok-code-fast-1": { contextWindow: 192000, maxTokens: 64000 },
57
- };
58
-
59
- interface GeminiModel {
60
- family: "gemini";
61
- kind: GeminiKind;
62
- version: SemVer;
63
- }
64
-
65
- interface AnthropicModel {
66
- family: "anthropic";
67
- kind: AnthropicKind;
68
- version: SemVer;
69
- }
70
-
71
- interface OpenAIModel {
72
- family: "openai";
73
- variant: OpenAIVariant;
74
- version: SemVer;
75
- }
76
-
77
- interface UnknownModel {
78
- family: "unknown";
79
- id: string;
80
- }
81
-
82
- type ParsedModel = GeminiModel | AnthropicModel | OpenAIModel | UnknownModel;
83
-
84
- /**
85
- * Static fallback model injected when Cloudflare AI Gateway discovery
86
- * returns no results. Ensures the provider always has at least one usable
87
- * model entry in the catalog.
88
- */
89
- export const CLOUDFLARE_FALLBACK_MODEL: ApiModel<"anthropic-messages"> = {
90
- id: "claude-sonnet-4-5",
91
- name: "Claude Sonnet 4.5",
92
- api: "anthropic-messages",
93
- provider: "cloudflare-ai-gateway",
94
- baseUrl: CLOUDFLARE_AI_GATEWAY_BASE_URL,
95
- reasoning: true,
96
- input: ["text", "image"],
97
- cost: {
98
- input: 3,
99
- output: 15,
100
- cacheRead: 0.3,
101
- cacheWrite: 3.75,
102
- },
103
- contextWindow: 200000,
104
- maxTokens: 64000,
105
- };
106
-
107
- const kEnrichedModel = Symbol("model-thinking.enrichedModel");
108
- type ModelWithEnriched = ApiModel<Api> & { [kEnrichedModel]?: ApiModel<Api> };
109
-
110
- /**
111
- * Returns a copy of the model with canonical thinking metadata attached.
112
- *
113
- * This helper belongs to catalog enrichment only. Runtime consumers should
114
- * trust `model.thinking` and avoid inferring capabilities on demand.
115
- */
116
- export function enrichModelThinking<TApi extends Api>(model: ApiModel<TApi>): ApiModel<TApi> {
117
- const tagged = model as ModelWithEnriched;
118
- const cached = tagged[kEnrichedModel];
119
- if (cached !== undefined) {
120
- return cached as ApiModel<TApi>;
121
- }
122
- const normalizedThinking = normalizeThinkingConfig(model.thinking);
123
- let result: ApiModel<TApi>;
124
- if (!model.reasoning) {
125
- result =
126
- normalizedThinking === undefined && model.thinking === undefined ? model : { ...model, thinking: undefined };
127
- } else {
128
- const thinking = normalizedThinking ?? inferModelThinking(model);
129
- result = thinkingsEqual(normalizedThinking, thinking) ? model : { ...model, thinking };
130
- }
131
- // Stash the enriched copy on a non-enumerable slot so callers that hand us
132
- // the same reference twice skip the work. `enumerable: false` is critical:
133
- // many call sites build derived models via `{ ...model, ...overrides }`,
134
- // which would otherwise copy this cache slot and trick us into returning
135
- // the *original* enriched model — silently discarding the overrides.
136
- Object.defineProperty(tagged, kEnrichedModel, {
137
- value: result,
138
- enumerable: false,
139
- configurable: true,
140
- writable: true,
141
- });
142
- return result;
143
- }
144
-
145
- /**
146
- * Returns a copy of the model with thinking metadata recomputed from the
147
- * canonical rules, replacing any existing `thinking`.
148
- */
149
- export function refreshModelThinking<TApi extends Api>(model: ApiModel<TApi>): ApiModel<TApi> {
150
- if (!model.reasoning) {
151
- const normalizedThinking = normalizeThinkingConfig(model.thinking);
152
- return normalizedThinking === undefined && model.thinking === undefined
153
- ? model
154
- : { ...model, thinking: undefined };
155
- }
156
- return { ...model, thinking: inferModelThinking(model) };
157
- }
158
-
159
- /**
160
- * Apply upstream metadata corrections to a mutable array of models.
161
- *
162
- * Each model is first normalized through `refreshModelThinking()` so generated
163
- * catalogs keep canonical thinking metadata and policy fixes in one pass.
164
- */
165
- export function applyGeneratedModelPolicies(models: ApiModel<Api>[]): void {
166
- for (let index = 0; index < models.length; index++) {
167
- const model = refreshModelThinking(models[index]!);
168
- applyGeneratedModelPolicy(model);
169
- models[index] = model;
170
- }
171
- }
172
-
173
- /**
174
- * Link OpenAI model variants to their context promotion targets.
175
- *
176
- * When a model's context is exhausted, the agent can promote to a sibling
177
- * model with a larger context window on the same provider:
178
- * - `codex-spark` variants promote to `gpt-5.5`.
179
- * - `gpt-5.5` (270K input) promotes to `gpt-5.4` (1M input).
180
- */
181
- export function linkOpenAIPromotionTargets(models: ApiModel<Api>[]): void {
182
- for (const candidate of models) {
183
- const parsedCandidate = parseKnownModel(candidate.id);
184
- if (parsedCandidate.family !== "openai") continue;
185
- let targetId: string | undefined;
186
- if (parsedCandidate.variant === "codex-spark") {
187
- targetId = "gpt-5.5";
188
- } else if (parsedCandidate.variant === "base" && semverEqual(parsedCandidate.version, "5.5")) {
189
- targetId = "gpt-5.4";
190
- } else {
191
- continue;
192
- }
193
- const fallback = models.find(
194
- model => model.provider === candidate.provider && model.api === candidate.api && model.id === targetId,
195
- );
196
- if (!fallback) continue;
197
- candidate.contextPromotionTarget = `${fallback.provider}/${fallback.id}`;
198
- }
199
- }
200
-
201
- /**
202
- * True when the model reasons natively but rejects the wire `reasoning.effort`
203
- * param (compat.supportsReasoningEffort: false on openai-responses*). Callers
204
- * are expected to omit the effort field; the wire-side omitReasoningEffort
205
- * gate (providers/xai-responses.ts:78) is the actual strip, and this
206
- * predicate is the upstream check that prevents a redundant
207
- * requireSupportedEffort throw from defeating that gate.
208
- *
209
- * Scoped to openai-responses* because that's the only API surface where
210
- * `compat.supportsReasoningEffort: false` is meaningful today. The
211
- * `in`-narrowed access is necessary because Model.compat is
212
- * `AnthropicCompat | OpenAICompat` and the api gate doesn't narrow the
213
- * union for TS.
214
- */
215
- export function modelOmitsReasoningEffort<TApi extends Api>(model: ApiModel<TApi>): boolean {
216
- if (model.api !== "openai-responses" && model.api !== "openai-codex-responses") {
217
- return false;
218
- }
219
- const compat = model.compat;
220
- return Boolean(compat && "supportsReasoningEffort" in compat && compat.supportsReasoningEffort === false);
221
- }
222
-
223
- /**
224
- * Returns the supported thinking efforts declared on the model metadata.
225
- *
226
- * Catalog enrichment is responsible for normalizing bundled model metadata up front.
227
- * Runtime callers must treat explicit `model.thinking` on custom models as authoritative
228
- * so proxy-specific overrides from `models.yml` survive request construction.
229
- *
230
- * @throws Error when a reasoning-capable model is missing thinking metadata
231
- */
232
- export function getSupportedEfforts<TApi extends Api>(model: ApiModel<TApi>): readonly Effort[] {
233
- if (!model.reasoning) {
234
- return [];
235
- }
236
- // Models that reason natively but reject the `reasoning.effort` wire param
237
- // (xAI Grok off the GROK_EFFORT_CAPABLE_PREFIXES allowlist in
238
- // providers/xai-responses.ts: grok-build, grok-4.20-0309-reasoning) hide the
239
- // picker's effort dial. Scoped to openai-responses* by
240
- // `modelOmitsReasoningEffort` — openai-completions has its own
241
- // supportsReasoningEffort consultation at inferFallbackEfforts L536 and
242
- // changing that path's semantics is out-of-scope.
243
- if (modelOmitsReasoningEffort(model)) {
244
- return [];
245
- }
246
- if (!model.thinking) {
247
- throw new Error(`Model ${model.provider}/${model.id} is missing thinking metadata`);
248
- }
249
- return expandEffortRange(model.thinking);
250
- }
251
-
252
- /**
253
- * Clamps a requested thinking level against explicit model metadata.
254
- *
255
- * Non-reasoning models always resolve to `undefined`.
256
- */
257
- export function clampThinkingLevelForModel<TApi extends Api>(
258
- model: ApiModel<TApi> | undefined,
259
- requested: Effort | undefined,
260
- ): Effort | undefined {
261
- if (!model) {
262
- return requested;
263
- }
264
- if (!model.reasoning || requested === undefined) {
265
- return undefined;
266
- }
267
-
268
- const levels = getSupportedEfforts(model);
269
- if (levels.includes(requested)) {
270
- return requested;
271
- }
272
-
273
- const requestedIndex = THINKING_EFFORTS.indexOf(requested);
274
- if (requestedIndex === -1) {
275
- return undefined;
276
- }
277
-
278
- let clamped: Effort | undefined;
279
- for (const effort of levels) {
280
- if (THINKING_EFFORTS.indexOf(effort) > requestedIndex) {
281
- break;
282
- }
283
- clamped = effort;
284
- }
285
-
286
- return clamped ?? levels[0];
287
- }
288
-
289
- export function requireSupportedEffort<TApi extends Api>(model: ApiModel<TApi>, effort: Effort): Effort {
290
- if (!model.reasoning) {
291
- throw new Error(`Model ${model.provider}/${model.id} does not support thinking`);
292
- }
293
- const levels = getSupportedEfforts(model);
294
- if (!levels.includes(effort)) {
295
- throw new Error(
296
- `Thinking effort ${effort} is not supported by ${model.provider}/${model.id}. Supported efforts: ${levels.join(", ")}`,
297
- );
298
- }
299
- return effort;
300
- }
301
-
302
- /** Maps a normalized thinking effort to Google's `thinkingLevel` enum values. */
303
- export function mapEffortToGoogleThinkingLevel<TApi extends Api>(
304
- model: ApiModel<TApi>,
305
- effort: Effort,
306
- ): "MINIMAL" | "LOW" | "MEDIUM" | "HIGH" {
307
- switch (requireSupportedEffort(model, effort)) {
308
- case Effort.Minimal:
309
- return "MINIMAL";
310
- case Effort.Low:
311
- return "LOW";
312
- case Effort.Medium:
313
- return "MEDIUM";
314
- case Effort.High:
315
- case Effort.XHigh:
316
- return "HIGH";
317
- }
318
- }
319
-
320
- /** Maps a normalized thinking effort to Anthropic adaptive effort values. */
321
- export function mapEffortToAnthropicAdaptiveEffort<TApi extends Api>(
322
- model: ApiModel<TApi>,
323
- effort: Effort,
324
- ): "low" | "medium" | "high" | "xhigh" | "max" {
325
- const supported = requireSupportedEffort(model, effort);
326
- if (anthropicModelHasRealXHighEffort(model)) {
327
- // Opus 4.7+ on the Messages API exposes the full five-tier adaptive scale
328
- // (low/medium/high/xhigh/max). Shift our user-facing efforts up one notch so
329
- // the top tier reaches the genuine "max" and "high" lands on Anthropic's
330
- // recommended "xhigh" coding/agentic default.
331
- switch (supported) {
332
- case Effort.Minimal:
333
- return "low";
334
- case Effort.Low:
335
- return "medium";
336
- case Effort.Medium:
337
- return "high";
338
- case Effort.High:
339
- return "xhigh";
340
- case Effort.XHigh:
341
- return "max";
342
- }
343
- }
344
- // Older adaptive models (Opus 4.6) and Bedrock Converse expose only four tiers
345
- // with no real "xhigh"; XHigh is a legacy alias for the top "max" tier there.
346
- switch (supported) {
347
- case Effort.Minimal:
348
- case Effort.Low:
349
- return "low";
350
- case Effort.Medium:
351
- return "medium";
352
- case Effort.High:
353
- return "high";
354
- case Effort.XHigh:
355
- return "max";
356
- }
357
- }
358
-
359
- /**
360
- * Returns true for Anthropic models with Opus 4.7 API restrictions:
361
- * - Sampling parameters (temperature/top_p/top_k) return 400 error
362
- * - Thinking content is omitted by default (needs display: "summarized")
363
- */
364
- export function hasOpus47ApiRestrictions(modelId: string): boolean {
365
- const parsed = parseAnthropicModel(getCanonicalModelId(modelId));
366
- if (!parsed) return false;
367
- return semverGte(parsed.version, "4.7") && parsed.kind === "opus";
368
- }
369
-
370
- /**
371
- * Mid-conversation `role: "system"` messages (system instructions appended at
372
- * non-first positions in the `messages` array) are supported starting with
373
- * Claude Opus 4.8. Earlier Claude models reject the role.
374
- * @see https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages
375
- */
376
- export function supportsMidConversationSystemMessages(modelId: string): boolean {
377
- const parsed = parseAnthropicModel(getCanonicalModelId(modelId));
378
- if (!parsed) return false;
379
- return parsed.kind === "opus" && semverGte(parsed.version, "4.8");
380
- }
381
-
382
- /**
383
- * Claude Opus 4.8 must emit at most one tool call per turn: the Anthropic
384
- * Messages provider sends `tool_choice.disable_parallel_tool_use = true` for
385
- * this model. Scoped to exactly 4.8 — earlier and later Opus versions keep
386
- * Anthropic's default parallel tool-calling.
387
- */
388
- export function disablesParallelToolUse(modelId: string): boolean {
389
- const parsed = parseAnthropicModel(getCanonicalModelId(modelId));
390
- if (!parsed) return false;
391
- return parsed.kind === "opus" && semverEqual(parsed.version, "4.8");
392
- }
393
-
394
- function anthropicModelHasRealXHighEffort<TApi extends Api>(model: ApiModel<TApi>): boolean {
395
- if (model.api !== "anthropic-messages") return false;
396
- const parsedModel = parseKnownModel(model.id);
397
- if (parsedModel.family !== "anthropic" || parsedModel.kind !== "opus") return false;
398
- return semverGte(parsedModel.version, "4.7");
399
- }
400
-
401
- function applyGeneratedModelPolicy(model: ApiModel<Api>): void {
402
- const copilotLimits = model.provider === "github-copilot" ? COPILOT_GENERATED_LIMITS[model.id] : undefined;
403
- if (copilotLimits) {
404
- model.contextWindow = copilotLimits.contextWindow;
405
- model.maxTokens = copilotLimits.maxTokens;
406
- }
407
-
408
- if (
409
- model.api === "openai-completions" &&
410
- (model.provider === "minimax-code" || model.provider === "minimax-code-cn")
411
- ) {
412
- model.compat = {
413
- ...(model.compat ?? {}),
414
- supportsStore: false,
415
- supportsDeveloperRole: false,
416
- supportsReasoningEffort: false,
417
- reasoningContentField: "reasoning_content",
418
- };
419
- delete model.compat.thinkingFormat;
420
- }
421
- if (
422
- model.api === "openai-completions" &&
423
- model.provider === "opencode-go" &&
424
- (model.id === "deepseek-v4-flash" || model.id === "deepseek-v4-pro")
425
- ) {
426
- model.compat = {
427
- ...(model.compat ?? {}),
428
- supportsToolChoice: false,
429
- reasoningContentField: "reasoning_content",
430
- requiresReasoningContentForToolCalls: true,
431
- };
432
- }
433
- const parsedModel = parseKnownModel(model.id);
434
- const applyPatchToolType = inferGeneratedApplyPatchToolType(model, parsedModel);
435
- if (applyPatchToolType) {
436
- model.applyPatchToolType = applyPatchToolType;
437
- } else {
438
- delete model.applyPatchToolType;
439
- }
440
- if (parsedModel.family === "anthropic") {
441
- applyAnthropicCatalogPolicy(model, parsedModel);
442
- }
443
- if (parsedModel.family === "openai") {
444
- applyOpenAICatalogPolicy(model, parsedModel);
445
- }
446
- }
447
-
448
- function applyAnthropicCatalogPolicy(model: ApiModel<Api>, parsedModel: AnthropicModel): void {
449
- // Claude Opus 4.5: models.dev reports 3x the correct cache pricing.
450
- if (model.provider === "anthropic" && parsedModel.kind === "opus" && semverEqual(parsedModel.version, "4.5")) {
451
- model.cost.cacheRead = 0.5;
452
- model.cost.cacheWrite = 6.25;
453
- }
454
-
455
- // Bedrock Opus 4.6: upstream metadata is stale for cache pricing and context.
456
- if (model.provider === "amazon-bedrock" && parsedModel.kind === "opus" && semverEqual(parsedModel.version, "4.6")) {
457
- model.cost.cacheRead = 0.5;
458
- model.cost.cacheWrite = 6.25;
459
- model.contextWindow = 1000000;
460
- model.maxTokens = 128000;
461
- }
462
- }
463
-
464
- function inferGeneratedApplyPatchToolType(
465
- model: ApiModel<Api>,
466
- parsedModel: ParsedModel,
467
- ): ApiModel<Api>["applyPatchToolType"] {
468
- if (parsedModel.family !== "openai" || parsedModel.version.major !== 5) {
469
- return undefined;
470
- }
471
- if (model.provider === "openai" && model.api === "openai-responses") {
472
- return "freeform";
473
- }
474
- if (model.provider === "openai-codex" && model.api === "openai-codex-responses") {
475
- return "freeform";
476
- }
477
- return undefined;
478
- }
479
-
480
- function applyOpenAICatalogPolicy(model: ApiModel<Api>, parsedModel: OpenAIModel): void {
481
- // Codex models: 400K figure includes output budget; input window is 272K.
482
- if (parsedModel.variant.startsWith("codex") && parsedModel.variant !== "codex-spark") {
483
- model.contextWindow = 272000;
484
- return;
485
- }
486
- // GPT-5.4 mini/nano use plain OpenAI IDs on the Codex transport, but Codex still
487
- // enforces the lower prompt budget for these variants. Codex discovery can also
488
- // report inconsistent priorities for the GPT-5.4 family, so normalize by parsed
489
- // variant instead of special-casing raw model ids.
490
- if (model.api === "openai-codex-responses" && semverEqual(parsedModel.version, "5.4")) {
491
- const normalizedPriority = CODEX_GPT_5_4_PRIORITY_BY_VARIANT[parsedModel.variant];
492
- if (normalizedPriority !== undefined) {
493
- model.priority = normalizedPriority;
494
- }
495
- if (parsedModel.variant === "mini" || parsedModel.variant === "nano") {
496
- model.contextWindow = 272000;
497
- }
498
- }
499
- }
500
-
501
- function inferModelThinking<TApi extends Api>(model: ApiModel<TApi>): ThinkingConfig {
502
- const parsedModel = parseKnownModel(model.id);
503
- const efforts = inferSupportedEfforts(parsedModel, model);
504
- const minLevel = efforts[0];
505
- const maxLevel = efforts.at(-1);
506
- if (!minLevel || !maxLevel) {
507
- throw new Error(`Model ${model.provider}/${model.id} resolved to an empty thinking range`);
508
- }
509
- const config: ThinkingConfig = {
510
- mode: inferThinkingControlMode(model, parsedModel),
511
- minLevel,
512
- maxLevel,
513
- };
514
- // Encode explicit levels only when the inferred set has gaps the min..max range cannot represent.
515
- const minIndex = THINKING_EFFORTS.indexOf(minLevel);
516
- const maxIndex = THINKING_EFFORTS.indexOf(maxLevel);
517
- const expandedRange = THINKING_EFFORTS.slice(minIndex, maxIndex + 1);
518
- if (expandedRange.length !== efforts.length) {
519
- config.levels = efforts;
520
- }
521
- return config;
522
- }
523
-
524
- function normalizeThinkingConfig(thinking: ThinkingConfig | undefined): ThinkingConfig | undefined {
525
- if (!thinking || expandEffortRange(thinking).length === 0) {
526
- return undefined;
527
- }
528
- return thinking;
529
- }
530
-
531
- function thinkingsEqual(left: ThinkingConfig | undefined, right: ThinkingConfig | undefined): boolean {
532
- if (left === right) return true;
533
- if (!left || !right) return false;
534
- if (left.mode !== right.mode || left.minLevel !== right.minLevel || left.maxLevel !== right.maxLevel) return false;
535
- const leftLevels = left.levels;
536
- const rightLevels = right.levels;
537
- if (leftLevels === rightLevels) return true;
538
- if (!leftLevels || !rightLevels) return false;
539
- if (leftLevels.length !== rightLevels.length) return false;
540
- return leftLevels.every((level, index) => level === rightLevels[index]);
541
- }
542
-
543
- function expandEffortRange(thinking: ThinkingConfig): readonly Effort[] {
544
- if (thinking.levels && thinking.levels.length > 0) {
545
- return thinking.levels;
546
- }
547
- const minIndex = THINKING_EFFORTS.indexOf(thinking.minLevel);
548
- const maxIndex = THINKING_EFFORTS.indexOf(thinking.maxLevel);
549
- if (minIndex === -1 || maxIndex === -1 || minIndex > maxIndex) {
550
- return [];
551
- }
552
- return THINKING_EFFORTS.slice(minIndex, maxIndex + 1);
553
- }
554
-
555
- function inferSupportedEfforts<TApi extends Api>(parsedModel: ParsedModel, model: ApiModel<TApi>): readonly Effort[] {
556
- switch (parsedModel.family) {
557
- case "openai":
558
- return inferOpenAISupportedEfforts(parsedModel);
559
- case "gemini":
560
- return inferGeminiSupportedEfforts(parsedModel);
561
- case "anthropic":
562
- return inferAnthropicSupportedEfforts(parsedModel, model);
563
- case "unknown":
564
- return inferFallbackEfforts(model);
565
- }
566
- }
567
-
568
- function inferOpenAISupportedEfforts(model: OpenAIModel): readonly Effort[] {
569
- if (model.variant === "codex-mini" && semverEqual(model.version, "5.1")) {
570
- return GPT_5_1_CODEX_MINI_EFFORTS;
571
- }
572
- if (semverGte(model.version, "5.2")) {
573
- return GPT_5_2_PLUS_EFFORTS;
574
- }
575
- return DEFAULT_REASONING_EFFORTS;
576
- }
577
-
578
- function inferGeminiSupportedEfforts(model: GeminiModel): readonly Effort[] {
579
- if (!semverGte(model.version, "3.0")) {
580
- return DEFAULT_REASONING_EFFORTS;
581
- }
582
- return model.kind === "pro" ? GEMINI_3_PRO_EFFORTS : GEMINI_3_FLASH_EFFORTS;
583
- }
584
-
585
- function inferAnthropicSupportedEfforts<TApi extends Api>(
586
- parsedModel: AnthropicModel,
587
- model: ApiModel<TApi>,
588
- ): readonly Effort[] {
589
- if (
590
- (model.api === "anthropic-messages" || model.api === "bedrock-converse-stream") &&
591
- semverGte(parsedModel.version, "4.6")
592
- ) {
593
- return parsedModel.kind === "opus" ? DEFAULT_REASONING_EFFORTS_WITH_XHIGH : DEFAULT_REASONING_EFFORTS;
594
- }
595
- return inferFallbackEfforts(model);
596
- }
597
-
598
- function inferFallbackEfforts<TApi extends Api>(model: ApiModel<TApi>): readonly Effort[] {
599
- if (model.api === "anthropic-messages") {
600
- return DEFAULT_REASONING_EFFORTS_WITH_XHIGH;
601
- }
602
- if (model.name.includes("deepseek-v4")) {
603
- return DEFAULT_REASONING_EFFORTS_WITH_XHIGH;
604
- }
605
- if (model.api === "bedrock-converse-stream") {
606
- return DEFAULT_REASONING_EFFORTS;
607
- }
608
- if (model.api === "openai-completions") {
609
- const compat = resolveOpenAICompat(model as ApiModel<"openai-completions">);
610
- if (compat.thinkingFormat === "openai" && compat.supportsReasoningEffort) {
611
- return DEFAULT_REASONING_EFFORTS_WITH_XHIGH;
612
- }
613
- return DEFAULT_REASONING_EFFORTS;
614
- }
615
- // OpenAI Responses APIs encode discrete effort levels, including xhigh.
616
- if (model.api === "openai-responses" || model.api === "openai-codex-responses") {
617
- return DEFAULT_REASONING_EFFORTS_WITH_XHIGH;
618
- }
619
- return DEFAULT_REASONING_EFFORTS;
620
- }
621
-
622
- function inferThinkingControlMode<TApi extends Api>(
623
- model: ApiModel<TApi>,
624
- parsedModel: ParsedModel,
625
- ): ThinkingConfig["mode"] {
626
- switch (model.api) {
627
- case "google-generative-ai":
628
- case "google-gemini-cli":
629
- case "google-vertex":
630
- return parsedModel.family === "gemini" &&
631
- semverGte(parsedModel.version, "3.0") &&
632
- parsedModel.version.major === 3
633
- ? "google-level"
634
- : "budget";
635
-
636
- case "anthropic-messages":
637
- if (parsedModel.family === "anthropic") {
638
- if (semverGte(parsedModel.version, "4.6")) {
639
- return "anthropic-adaptive";
640
- }
641
- if (semverGte(parsedModel.version, "4.5")) {
642
- return "anthropic-budget-effort";
643
- }
644
- }
645
- return "budget";
646
-
647
- case "bedrock-converse-stream":
648
- if (parsedModel.family === "anthropic") {
649
- if (semverGte(parsedModel.version, "4.6") && parsedModel.kind === "opus") {
650
- return "anthropic-adaptive";
651
- }
652
- if (semverGte(parsedModel.version, "4.5")) {
653
- return "anthropic-budget-effort";
654
- }
655
- }
656
- return "budget";
657
-
658
- default:
659
- return "effort";
660
- }
661
- }
662
-
663
- function parseKnownModel(modelId: string): ParsedModel {
664
- const canonicalId = getCanonicalModelId(modelId);
665
- return (
666
- parseGeminiModel(canonicalId) ??
667
- parseAnthropicModel(canonicalId) ??
668
- parseOpenAIModel(canonicalId) ?? { family: "unknown", id: canonicalId }
669
- );
670
- }
671
-
672
- const GEMINI_SUFFIX = "-preview";
673
- function parseGeminiModel(modelId: string): GeminiModel | null {
674
- if (modelId.endsWith(GEMINI_SUFFIX)) {
675
- modelId = modelId.slice(0, -GEMINI_SUFFIX.length);
676
- }
677
- const match = /gemini-(\d+(?:\.\d+){0,2})-(pro|flash)\b/.exec(modelId);
678
- if (!match) {
679
- return null;
680
- }
681
- const version = parseSemVer(match[1]);
682
- if (!version) {
683
- return null;
684
- }
685
- return { family: "gemini", kind: match[2] as GeminiKind, version };
686
- }
687
-
688
- function parseAnthropicModel(modelId: string): AnthropicModel | null {
689
- const match = /claude-(opus|sonnet)-(\d{1,2}(?:[.-]\d{1,2}){0,2})\b/.exec(modelId);
690
- if (!match) {
691
- return null;
692
- }
693
- const version = parseSemVer(match[2]);
694
- if (!version) {
695
- return null;
696
- }
697
- return { family: "anthropic", kind: match[1] as AnthropicKind, version };
698
- }
699
-
700
- function parseOpenAIModel(modelId: string): OpenAIModel | null {
701
- const match = /gpt-(\d+(?:\.\d+){0,2})(?:-(codex-spark|codex-mini|codex-max|codex|mini|max|nano))?\b/.exec(modelId);
702
- if (!match) {
703
- return null;
704
- }
705
- const version = parseSemVer(match[1]);
706
- if (!version) {
707
- return null;
708
- }
709
- return { family: "openai", variant: (match[2] as OpenAIVariant | undefined) ?? "base", version };
710
- }
711
-
712
- function createSemVer(major: number, minor: number, patch = 0): SemVer {
713
- return { major, minor, patch };
714
- }
715
-
716
- // extend this table if we need anything more than 9.10
717
- const precomputeTable: Record<string, SemVer> = {};
718
- for (let major = 0; major <= 9; major++) {
719
- for (let minor = 0; minor <= 10; minor++) {
720
- const version = createSemVer(major, minor, 0);
721
- precomputeTable[`${major}.${minor}`] = version;
722
- precomputeTable[`${major}-${minor}`] = version;
723
- }
724
- precomputeTable[`${major}`] = createSemVer(major, 0, 0);
725
- }
726
-
727
- function parseSemVer(version: string): SemVer | null {
728
- return precomputeTable[version] ?? null;
729
- }
730
-
731
- function semverGte(left: SemVer | string, right: SemVer | string): boolean {
732
- return compareSemVer(left, right) >= 0;
733
- }
734
-
735
- function semverEqual(left: SemVer | string, right: SemVer | string): boolean {
736
- return compareSemVer(left, right) === 0;
737
- }
738
-
739
- function compareSemVer(left: SemVer | string | null, right: SemVer | string | null): number {
740
- left = typeof left === "string" ? parseSemVer(left) : left;
741
- right = typeof right === "string" ? parseSemVer(right) : right;
742
- if (!left || !right) return (left ? 1 : 0) - (right ? 1 : 0);
743
-
744
- if (left.major !== right.major) {
745
- return left.major - right.major;
746
- }
747
- if (left.minor !== right.minor) {
748
- return left.minor - right.minor;
749
- }
750
- return left.patch - right.patch;
751
- }
752
-
753
- function getCanonicalModelId(modelId: string): string {
754
- const p = modelId.lastIndexOf("/");
755
- return p !== -1 ? modelId.slice(p + 1) : modelId;
756
- }