@prometheus-ai/ai 0.5.3 → 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,29 +1,12 @@
1
- /**
2
- * Hugging Face Inference login flow.
3
- *
4
- * Hugging Face Inference Providers expose an OpenAI-compatible endpoint via
5
- * https://router.huggingface.co/v1.
6
- *
7
- * This is an API key flow:
8
- * 1. Open browser to Hugging Face token settings
9
- * 2. User creates/copies a token with Inference Providers permission
10
- * 3. User pastes the token into the CLI
11
- */
12
-
13
1
  import { validateOpenAICompatibleApiKey } from "./api-key-validation";
14
- import type { OAuthController } from "./types";
2
+ import type { OAuthController, OAuthLoginCallbacks } from "./oauth/types";
3
+ import type { ProviderDefinition } from "./types";
15
4
 
16
5
  const AUTH_URL =
17
6
  "https://huggingface.co/settings/tokens/new?ownUserPermissions=inference.serverless.write&tokenType=fineGrained";
18
7
  const API_BASE_URL = "https://router.huggingface.co/v1";
19
8
  const VALIDATION_MODEL = "openai/gpt-oss-120b";
20
9
 
21
- /**
22
- * Login to Hugging Face Inference Providers.
23
- *
24
- * Opens browser to token settings, prompts user to paste their API key.
25
- * Returns the API key directly (not OAuthCredentials - this isn't OAuth).
26
- */
27
10
  export async function loginHuggingface(options: OAuthController): Promise<string> {
28
11
  if (!options.onPrompt) {
29
12
  throw new Error("Hugging Face login requires onPrompt callback");
@@ -60,3 +43,9 @@ export async function loginHuggingface(options: OAuthController): Promise<string
60
43
 
61
44
  return trimmed;
62
45
  }
46
+
47
+ export const huggingfaceProvider = {
48
+ id: "huggingface",
49
+ name: "Hugging Face Inference",
50
+ login: (cb: OAuthLoginCallbacks) => loginHuggingface(cb),
51
+ } as const satisfies ProviderDefinition;
@@ -0,0 +1,4 @@
1
+ export * from "./derived";
2
+ export * from "./oauth";
3
+ export * from "./registry";
4
+ export * from "./types";
@@ -1,14 +1,5 @@
1
- /**
2
- * Kagi login flow.
3
- *
4
- * Kagi web search uses an API key from the account settings page.
5
- * This is an API key flow:
6
- * 1. Open browser to Kagi API settings
7
- * 2. User copies API key
8
- * 3. User pastes key into CLI
9
- */
10
-
11
- import type { OAuthController } from "./types";
1
+ import type { OAuthController, OAuthLoginCallbacks } from "./oauth/types";
2
+ import type { ProviderDefinition } from "./types";
12
3
 
13
4
  const AUTH_URL = "https://kagi.com/settings/api";
14
5
 
@@ -45,3 +36,10 @@ export async function loginKagi(options: OAuthController): Promise<string> {
45
36
 
46
37
  return trimmed;
47
38
  }
39
+
40
+ export const kagiProvider = {
41
+ id: "kagi",
42
+ name: "Kagi",
43
+ envKeys: "KAGI_API_KEY",
44
+ login: (cb: OAuthLoginCallbacks) => loginKagi(cb),
45
+ } as const satisfies ProviderDefinition;
@@ -1,4 +1,5 @@
1
- import type { OAuthController, OAuthCredentials } from "./types";
1
+ import type { OAuthController, OAuthCredentials } from "./oauth/types";
2
+ import type { ProviderDefinition } from "./types";
2
3
 
3
4
  const KILO_DEVICE_AUTH_BASE_URL = "https://api.kilo.ai/api/device-auth";
4
5
  const POLL_INTERVAL_MS = 5000;
@@ -15,11 +16,9 @@ interface KiloDeviceAuthPollResponse {
15
16
  token?: string;
16
17
  }
17
18
 
18
- /**
19
- * Login with Kilo Gateway OAuth (device code flow).
20
- */
21
19
  export async function loginKilo(callbacks: OAuthController): Promise<OAuthCredentials> {
22
- const initiateResponse = await fetch(`${KILO_DEVICE_AUTH_BASE_URL}/codes`, {
20
+ const fetchImpl = callbacks.fetch ?? fetch;
21
+ const initiateResponse = await fetchImpl(`${KILO_DEVICE_AUTH_BASE_URL}/codes`, {
23
22
  method: "POST",
24
23
  headers: { "Content-Type": "application/json" },
25
24
  });
@@ -50,7 +49,7 @@ export async function loginKilo(callbacks: OAuthController): Promise<OAuthCreden
50
49
  throw new Error("Login cancelled");
51
50
  }
52
51
 
53
- const pollResponse = await fetch(`${KILO_DEVICE_AUTH_BASE_URL}/codes/${encodeURIComponent(userCode)}`);
52
+ const pollResponse = await fetchImpl(`${KILO_DEVICE_AUTH_BASE_URL}/codes/${encodeURIComponent(userCode)}`);
54
53
  if (pollResponse.status === 202) {
55
54
  await Bun.sleep(POLL_INTERVAL_MS);
56
55
  continue;
@@ -85,3 +84,9 @@ export async function loginKilo(callbacks: OAuthController): Promise<OAuthCreden
85
84
 
86
85
  throw new Error("Authentication timed out. Please try again.");
87
86
  }
87
+
88
+ export const kiloProvider = {
89
+ id: "kilo",
90
+ name: "Kilo Gateway",
91
+ login: loginKilo,
92
+ } as const satisfies ProviderDefinition;
@@ -0,0 +1,17 @@
1
+ import type { OAuthCredentials, OAuthLoginCallbacks } from "./oauth/types";
2
+ import type { ProviderDefinition } from "./types";
3
+
4
+ export const kimiCodeProvider = {
5
+ id: "kimi-code",
6
+ name: "Kimi Code",
7
+ login: async (cb: OAuthLoginCallbacks) => {
8
+ // Lazy import: keep heavy OAuth flow modules out of the eager registry graph.
9
+ const { loginKimi } = await import("./oauth/kimi");
10
+ return loginKimi(cb);
11
+ },
12
+ refreshToken: async (credentials: OAuthCredentials) => {
13
+ // Lazy import: keep heavy OAuth flow modules out of the eager registry graph.
14
+ const { refreshKimiToken } = await import("./oauth/kimi");
15
+ return refreshKimiToken(credentials.refresh);
16
+ },
17
+ } as const satisfies ProviderDefinition;
@@ -1,15 +1,5 @@
1
- /**
2
- * LiteLLM login flow.
3
- *
4
- * LiteLLM is an OpenAI-compatible proxy that routes requests to many upstream providers.
5
- *
6
- * This is not OAuth - it's a simple API key flow:
7
- * 1. Open browser to LiteLLM docs/dashboard
8
- * 2. User copies their LiteLLM API key
9
- * 3. User pastes the API key into the CLI
10
- */
11
-
12
- import type { OAuthController } from "./types";
1
+ import type { OAuthController, OAuthLoginCallbacks } from "./oauth/types";
2
+ import type { ProviderDefinition } from "./types";
13
3
 
14
4
  const AUTH_URL = "https://docs.litellm.ai/docs/proxy/deploy";
15
5
 
@@ -45,3 +35,9 @@ export async function loginLiteLLM(options: OAuthController): Promise<string> {
45
35
 
46
36
  return trimmed;
47
37
  }
38
+
39
+ export const litellmProvider = {
40
+ id: "litellm",
41
+ name: "LiteLLM",
42
+ login: (cb: OAuthLoginCallbacks) => loginLiteLLM(cb),
43
+ } as const satisfies ProviderDefinition;
@@ -1,23 +1,9 @@
1
- /**
2
- * LM Studio login flow.
3
- *
4
- * LM Studio provides an OpenAI-compatible API at a local base URL.
5
- * It usually runs unauthenticated but can be configured to require a bearer token.
6
- *
7
- * This flow stores an API-key-style credential used by `/login` and auth storage.
8
- */
1
+ import type { OAuthController, OAuthLoginCallbacks } from "./oauth/types";
2
+ import type { ProviderDefinition } from "./types";
9
3
 
10
- import type { OAuthController, OAuthProvider } from "./types";
11
-
12
- const PROVIDER_ID: OAuthProvider = "lm-studio";
4
+ const PROVIDER_ID = "lm-studio";
13
5
  export const DEFAULT_LOCAL_TOKEN = "lm-studio-local";
14
6
 
15
- /**
16
- * Login to LM Studio.
17
- *
18
- * Opens LM Studio API docs, prompts for an optional token,
19
- * and returns a stored key value.
20
- */
21
7
  export async function loginLmStudio(options: OAuthController): Promise<string> {
22
8
  if (!options.onPrompt) {
23
9
  throw new Error(`${PROVIDER_ID} login requires onPrompt callback`);
@@ -36,3 +22,9 @@ export async function loginLmStudio(options: OAuthController): Promise<string> {
36
22
  const trimmed = apiKey.trim();
37
23
  return trimmed || DEFAULT_LOCAL_TOKEN;
38
24
  }
25
+
26
+ export const lmStudioProvider = {
27
+ id: "lm-studio",
28
+ name: "LM Studio (Local OpenAI-compatible)",
29
+ login: (cb: OAuthLoginCallbacks) => loginLmStudio(cb),
30
+ } as const satisfies ProviderDefinition;
@@ -0,0 +1,12 @@
1
+ import type { OAuthLoginCallbacks } from "./oauth/types";
2
+ import type { ProviderDefinition } from "./types";
3
+
4
+ export const minimaxCodeCnProvider = {
5
+ id: "minimax-code-cn",
6
+ name: "MiniMax Token Plan (China)",
7
+ login: async (cb: OAuthLoginCallbacks) => {
8
+ // Lazy import: keep heavy OAuth flow modules out of the eager registry graph.
9
+ const { loginMiniMaxCodeCn } = await import("./oauth/minimax-code");
10
+ return loginMiniMaxCodeCn(cb);
11
+ },
12
+ } as const satisfies ProviderDefinition;
@@ -0,0 +1,12 @@
1
+ import type { OAuthLoginCallbacks } from "./oauth/types";
2
+ import type { ProviderDefinition } from "./types";
3
+
4
+ export const minimaxCodeProvider = {
5
+ id: "minimax-code",
6
+ name: "MiniMax Token Plan (International)",
7
+ login: async (cb: OAuthLoginCallbacks) => {
8
+ // Lazy import: keep heavy OAuth flow modules out of the eager registry graph.
9
+ const { loginMiniMaxCode } = await import("./oauth/minimax-code");
10
+ return loginMiniMaxCode(cb);
11
+ },
12
+ } as const satisfies ProviderDefinition;
@@ -0,0 +1,6 @@
1
+ import type { ProviderDefinition } from "./types";
2
+
3
+ export const minimaxProvider = {
4
+ id: "minimax",
5
+ name: "MiniMax",
6
+ } as const satisfies ProviderDefinition;
@@ -0,0 +1,6 @@
1
+ import type { ProviderDefinition } from "./types";
2
+
3
+ export const mistralProvider = {
4
+ id: "mistral",
5
+ name: "Mistral",
6
+ } as const satisfies ProviderDefinition;
@@ -1,13 +1,6 @@
1
- /**
2
- * Moonshot login flow (API key paste against https://api.moonshot.ai/v1).
3
- *
4
- * Validation hits `GET /v1/models` rather than a chat completion. Moonshot's
5
- * thinking models (e.g. kimi-k2.5/k2.6) reject the `temperature: 0` probe used
6
- * by the chat-completions validator with `invalid temperature: only 1 is
7
- * allowed for this model`, so a hello-world chat call cannot authenticate the
8
- * key reliably across the Moonshot catalog.
9
- */
10
1
  import { createApiKeyLogin } from "./api-key-login";
2
+ import type { OAuthLoginCallbacks } from "./oauth/types";
3
+ import type { ProviderDefinition } from "./types";
11
4
 
12
5
  export const loginMoonshot = createApiKeyLogin({
13
6
  providerLabel: "Moonshot",
@@ -21,3 +14,9 @@ export const loginMoonshot = createApiKeyLogin({
21
14
  modelsUrl: "https://api.moonshot.ai/v1/models",
22
15
  },
23
16
  });
17
+
18
+ export const moonshotProvider = {
19
+ id: "moonshot",
20
+ name: "Moonshot (Kimi API)",
21
+ login: (cb: OAuthLoginCallbacks) => loginMoonshot(cb),
22
+ } as const satisfies ProviderDefinition;
@@ -1,5 +1,6 @@
1
- /** NanoGPT login flow (API key paste, validated via /models). */
2
1
  import { createApiKeyLogin } from "./api-key-login";
2
+ import type { OAuthLoginCallbacks } from "./oauth/types";
3
+ import type { ProviderDefinition } from "./types";
3
4
 
4
5
  export const loginNanoGPT = createApiKeyLogin({
5
6
  providerLabel: "NanoGPT",
@@ -13,3 +14,9 @@ export const loginNanoGPT = createApiKeyLogin({
13
14
  modelsUrl: "https://nano-gpt.com/api/v1/models",
14
15
  },
15
16
  });
17
+
18
+ export const nanogptProvider = {
19
+ id: "nanogpt",
20
+ name: "NanoGPT",
21
+ login: (cb: OAuthLoginCallbacks) => loginNanoGPT(cb),
22
+ } as const satisfies ProviderDefinition;
@@ -1,28 +1,12 @@
1
- /**
2
- * NVIDIA login flow.
3
- *
4
- * NVIDIA provides OpenAI-compatible models via https://integrate.api.nvidia.com/v1.
5
- *
6
- * This is not OAuth - it's a simple API key flow:
7
- * 1. Open browser to NVIDIA NGC catalog
8
- * 2. User copies their API key
9
- * 3. User pastes the API key into the CLI
10
- */
11
-
12
1
  import { validateOpenAICompatibleApiKey } from "./api-key-validation";
13
- import type { OAuthController } from "./types";
2
+ import type { OAuthController, OAuthLoginCallbacks } from "./oauth/types";
3
+ import type { ProviderDefinition } from "./types";
14
4
 
15
5
  const AUTH_URL = "https://org.ngc.nvidia.com/setup/personal-keys";
16
6
  const API_BASE_URL = "https://integrate.api.nvidia.com/v1";
17
7
  const VALIDATION_MODEL = "nvidia/llama-3.1-nemotron-70b-instruct";
18
8
  const PROVIDER_ID = "nvidia";
19
9
 
20
- /**
21
- * Login to NVIDIA.
22
- *
23
- * Opens browser to NVIDIA dashboard, prompts user to paste their API key.
24
- * Returns the API key directly (not OAuthCredentials - this isn't OAuth).
25
- */
26
10
  export async function loginNvidia(options: OAuthController): Promise<string> {
27
11
  if (!options.onPrompt) {
28
12
  throw new Error("NVIDIA login requires onPrompt callback");
@@ -68,3 +52,9 @@ export async function loginNvidia(options: OAuthController): Promise<string> {
68
52
 
69
53
  return trimmed;
70
54
  }
55
+
56
+ export const nvidiaProvider = {
57
+ id: "nvidia",
58
+ name: "NVIDIA",
59
+ login: (cb: OAuthLoginCallbacks) => loginNvidia(cb),
60
+ } as const satisfies ProviderDefinition;
@@ -1,10 +1,7 @@
1
1
  import { afterEach, describe, expect, it, vi } from "bun:test";
2
2
  import { isXAIAccessTokenExpiring, refreshXAIOAuthToken, validateXAIEndpoint, XAIOAuthFlow } from "../xai-oauth";
3
3
 
4
- const originalFetch = global.fetch;
5
-
6
4
  afterEach(() => {
7
- global.fetch = originalFetch;
8
5
  vi.restoreAllMocks();
9
6
  });
10
7
 
@@ -58,9 +55,10 @@ describe("refreshXAIOAuthToken", () => {
58
55
  const fetchMock = vi.fn(async () => {
59
56
  throw new Error("fetch should not be called when refresh_token is empty");
60
57
  });
61
- global.fetch = fetchMock as unknown as typeof fetch;
62
58
 
63
- await expect(refreshXAIOAuthToken("")).rejects.toThrow(/missing refresh_token/);
59
+ await expect(refreshXAIOAuthToken("", fetchMock as unknown as typeof fetch)).rejects.toThrow(
60
+ /missing refresh_token/,
61
+ );
64
62
  expect(fetchMock).not.toHaveBeenCalled();
65
63
  });
66
64
  });
@@ -95,9 +93,8 @@ describe("XAIOAuthFlow.exchangeToken", () => {
95
93
  headers: { "Content-Type": "application/json" },
96
94
  });
97
95
  });
98
- global.fetch = fetchMock as unknown as typeof fetch;
99
96
 
100
- const flow = new XAIOAuthFlow({});
97
+ const flow = new XAIOAuthFlow({ fetch: fetchMock as unknown as typeof fetch });
101
98
  await flow.generateAuthUrl("state-abc", "http://127.0.0.1:56121/callback");
102
99
 
103
100
  await expect(flow.exchangeToken("code-xyz", "state-abc", "http://127.0.0.1:56121/callback")).rejects.toThrow(
@@ -1,6 +1,9 @@
1
1
  /**
2
2
  * Anthropic OAuth flow (Claude Pro/Max)
3
3
  */
4
+
5
+ import { claudeCodeVersion } from "../../providers/anthropic";
6
+ import type { FetchImpl } from "../../types";
4
7
  import { OAuthCallbackFlow } from "./callback-server";
5
8
  import { generatePKCE } from "./pkce";
6
9
  import type { OAuthController, OAuthCredentials } from "./types";
@@ -11,7 +14,7 @@ const AUTHORIZE_URL = "https://claude.ai/oauth/authorize";
11
14
  const TOKEN_URL = "https://api.anthropic.com/v1/oauth/token";
12
15
  const BOOTSTRAP_URL = "https://api.anthropic.com/api/claude_cli/bootstrap";
13
16
  const CLAUDE_CODE_BOOTSTRAP_MODEL = "claude-opus-4-8";
14
- const CLAUDE_CODE_BOOTSTRAP_USER_AGENT = "claude-code/2.1.160";
17
+ const CLAUDE_CODE_BOOTSTRAP_USER_AGENT = `claude-code/${claudeCodeVersion}`;
15
18
  const CALLBACK_PORT = 54545;
16
19
  const CALLBACK_PATH = "/callback";
17
20
  // Scopes required for direct OAuth-token inference (user:inference) plus account/session management.
@@ -40,9 +43,10 @@ function formatErrorDetails(error: unknown): string {
40
43
  async function postJson(
41
44
  url: string,
42
45
  body: Record<string, string | number>,
46
+ fetchImpl: FetchImpl,
43
47
  extraHeaders?: Record<string, string>,
44
48
  ): Promise<string> {
45
- const response = await fetch(url, {
49
+ const response = await fetchImpl(url, {
46
50
  method: "POST",
47
51
  headers: {
48
52
  // No Accept header: CC omits it on OAuth token requests.
@@ -109,9 +113,12 @@ function extractAccountFromTokenResponse(data: AnthropicTokenResponse): {
109
113
  };
110
114
  }
111
115
 
112
- async function fetchBootstrapIdentity(accessToken: string): Promise<{ accountId?: string; email?: string }> {
116
+ async function fetchBootstrapIdentity(
117
+ accessToken: string,
118
+ fetchImpl: FetchImpl,
119
+ ): Promise<{ accountId?: string; email?: string }> {
113
120
  const url = `${BOOTSTRAP_URL}?entrypoint=cli&model=${encodeURIComponent(CLAUDE_CODE_BOOTSTRAP_MODEL)}`;
114
- const response = await fetch(url, {
121
+ const response = await fetchImpl(url, {
115
122
  method: "GET",
116
123
  headers: {
117
124
  Accept: "application/json, text/plain, */*",
@@ -142,11 +149,14 @@ async function fetchBootstrapIdentity(accessToken: string): Promise<{ accountId?
142
149
  };
143
150
  }
144
151
 
145
- async function resolveAccountIdentity(data: AnthropicTokenResponse): Promise<{ accountId?: string; email?: string }> {
152
+ async function resolveAccountIdentity(
153
+ data: AnthropicTokenResponse,
154
+ fetchImpl: FetchImpl,
155
+ ): Promise<{ accountId?: string; email?: string }> {
146
156
  const identity = extractAccountFromTokenResponse(data);
147
157
  if (identity.accountId && identity.email) return identity;
148
158
  try {
149
- const bootstrap = await fetchBootstrapIdentity(data.access_token);
159
+ const bootstrap = await fetchBootstrapIdentity(data.access_token, fetchImpl);
150
160
  return {
151
161
  accountId: identity.accountId ?? bootstrap.accountId,
152
162
  email: identity.email ?? bootstrap.email,
@@ -159,9 +169,11 @@ async function resolveAccountIdentity(data: AnthropicTokenResponse): Promise<{ a
159
169
  export class AnthropicOAuthFlow extends OAuthCallbackFlow {
160
170
  #verifier: string = "";
161
171
  #challenge: string = "";
172
+ #fetch: FetchImpl;
162
173
 
163
174
  constructor(ctrl: OAuthController) {
164
175
  super(ctrl, CALLBACK_PORT, CALLBACK_PATH);
176
+ this.#fetch = ctrl.fetch ?? fetch;
165
177
  }
166
178
 
167
179
  async generateAuthUrl(state: string, redirectUri: string): Promise<{ url: string; instructions?: string }> {
@@ -202,14 +214,18 @@ export class AnthropicOAuthFlow extends OAuthCallbackFlow {
202
214
 
203
215
  let responseBody: string;
204
216
  try {
205
- responseBody = await postJson(TOKEN_URL, {
206
- grant_type: "authorization_code",
207
- client_id: CLIENT_ID,
208
- code: exchangeCode,
209
- state: exchangeState,
210
- redirect_uri: redirectUri,
211
- code_verifier: this.#verifier,
212
- });
217
+ responseBody = await postJson(
218
+ TOKEN_URL,
219
+ {
220
+ grant_type: "authorization_code",
221
+ client_id: CLIENT_ID,
222
+ code: exchangeCode,
223
+ state: exchangeState,
224
+ redirect_uri: redirectUri,
225
+ code_verifier: this.#verifier,
226
+ },
227
+ this.#fetch,
228
+ );
213
229
  } catch (error) {
214
230
  throw new Error(
215
231
  `Token exchange request failed. url=${TOKEN_URL}; redirect_uri=${redirectUri}; response_type=authorization_code; details=${formatErrorDetails(error)}`,
@@ -217,7 +233,7 @@ export class AnthropicOAuthFlow extends OAuthCallbackFlow {
217
233
  }
218
234
 
219
235
  const tokenData = parseOAuthTokenResponse(responseBody, "token exchange");
220
- const { accountId, email } = await resolveAccountIdentity(tokenData);
236
+ const { accountId, email } = await resolveAccountIdentity(tokenData, this.#fetch);
221
237
 
222
238
  return {
223
239
  refresh: tokenData.refresh_token,
@@ -240,7 +256,11 @@ export async function loginAnthropic(ctrl: OAuthController): Promise<OAuthCreden
240
256
  /**
241
257
  * Refresh Anthropic OAuth token
242
258
  */
243
- export async function refreshAnthropicToken(refreshToken: string): Promise<OAuthCredentials> {
259
+ export async function refreshAnthropicToken(
260
+ refreshToken: string,
261
+ fetchOverride?: FetchImpl,
262
+ ): Promise<OAuthCredentials> {
263
+ const fetchImpl = fetchOverride ?? fetch;
244
264
  let responseBody: string;
245
265
  try {
246
266
  responseBody = await postJson(
@@ -250,6 +270,7 @@ export async function refreshAnthropicToken(refreshToken: string): Promise<OAuth
250
270
  client_id: CLIENT_ID,
251
271
  refresh_token: refreshToken,
252
272
  },
273
+ fetchImpl,
253
274
  {
254
275
  // CC sends these on refresh but not on the initial code exchange
255
276
  "anthropic-beta": "oauth-2025-04-20",
@@ -261,7 +282,7 @@ export async function refreshAnthropicToken(refreshToken: string): Promise<OAuth
261
282
  }
262
283
 
263
284
  const data = parseOAuthTokenResponse(responseBody, "token refresh");
264
- const { accountId, email } = await resolveAccountIdentity(data);
285
+ const { accountId, email } = await resolveAccountIdentity(data, fetchImpl);
265
286
 
266
287
  return {
267
288
  refresh: data.refresh_token || refreshToken,