@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,7 +1,7 @@
1
1
  import { type AuthCredential, type AuthCredentialStore, type OAuthCredential, type StoredAuthCredential } from "../auth-storage";
2
+ import type { OAuthCredentials } from "../registry/oauth/types";
2
3
  import type { Provider } from "../types";
3
4
  import type { UsageReport } from "../usage";
4
- import type { OAuthCredentials } from "../utils/oauth/types";
5
5
  import { type AuthBrokerClient } from "./client";
6
6
  import type { SnapshotResponse } from "./types";
7
7
  export interface RemoteAuthCredentialStoreOptions {
@@ -37,6 +37,7 @@ export declare class RemoteAuthCredentialStore implements AuthCredentialStore {
37
37
  */
38
38
  updateAuthCredential(id: number, credential: AuthCredential): void;
39
39
  deleteAuthCredential(id: number, disabledCause: string): void;
40
+ deleteAuthCredentialRemote(id: number, disabledCause: string): Promise<boolean>;
40
41
  tryDisableAuthCredentialIfMatches(id: number, _expectedData: string, disabledCause: string): boolean;
41
42
  waitForFreshSnapshot(maxWaitMs: number, opts?: {
42
43
  signal?: AbortSignal;
@@ -10,7 +10,7 @@
10
10
  * keys are rejected — the previous implementation used a hand-rolled
11
11
  * `hasOnlyFields` allowlist for the same effect.
12
12
  */
13
- import * as z from "zod/v4";
13
+ import { z } from "zod/v4";
14
14
  /** Real OAuth credential (broker-side) — refresh token is the actual upstream value. */
15
15
  export declare const oauthCredentialSchema: z.ZodObject<{
16
16
  type: z.ZodLiteral<"oauth">;
@@ -344,6 +344,9 @@ export declare const usageResponseSchema: z.ZodObject<{
344
344
  }>>;
345
345
  notes: z.ZodOptional<z.ZodArray<z.ZodString>>;
346
346
  }, z.core.$strip>>;
347
+ resetCredits: z.ZodOptional<z.ZodObject<{
348
+ availableCount: z.ZodNumber;
349
+ }, z.core.$strip>>;
347
350
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
348
351
  raw: z.ZodOptional<z.ZodUnknown>;
349
352
  }, z.core.$strip>>;
@@ -1,3 +1,22 @@
1
+ /**
2
+ * prometheus auth-gateway HTTP server.
3
+ *
4
+ * Accepts any provider-format request (OpenAI chat-completions, Anthropic
5
+ * messages, OpenAI Responses) and dispatches through Prometheus AI's `streamSimple()`
6
+ * — which handles credential injection, anthropic-beta headers, codex
7
+ * websocket transport, and all the per-provider intricacies. The gateway is
8
+ * pure protocol translation: foreign wire → prometheus Context → Prometheus AI stream() →
9
+ * prometheus events → foreign wire.
10
+ *
11
+ * Endpoints:
12
+ * GET /healthz → unauth; ok + version
13
+ * GET /v1/usage → aggregated provider usage (5-min per-credential cache via AuthStorage)
14
+ * GET /v1/credentials/check → per-credential auth probe (diagnose 401s in a multi-account pool)
15
+ * GET /v1/models → list known models from the registry
16
+ * POST /v1/chat/completions → OpenAI chat-completions in/out
17
+ * POST /v1/messages → Anthropic messages in/out
18
+ * POST /v1/responses → OpenAI Responses in/out
19
+ */
1
20
  import type { AuthStorage } from "../auth-storage";
2
21
  import type { Api, Model } from "../types";
3
22
  import type { AuthGatewayServerHandle, AuthGatewayServerOptions } from "./types";
@@ -1,4 +1,4 @@
1
- import type { Effort } from "../model-thinking";
1
+ import type { Effort } from "@prometheus-ai/catalog/effort";
2
2
  import type { AssistantMessage, AssistantMessageEventStream, CacheRetention, Context, ServiceTier, TokenTaskBudget } from "../types";
3
3
  /**
4
4
  * Wire types for the prometheus auth-gateway.
@@ -6,7 +6,7 @@ import type { AssistantMessage, AssistantMessageEventStream, CacheRetention, Con
6
6
  * The gateway sits between unauthenticated clients (containerized prometheus,
7
7
  * llm-git, …) and the broker. It accepts provider-format HTTP requests
8
8
  * (OpenAI chat-completions / Anthropic messages / OpenAI Responses),
9
- * dispatches them through @prometheus-ai/ai's `streamSimple()`, and translates the
9
+ * dispatches them through Prometheus AI's `streamSimple()`, and translates the
10
10
  * canonical event stream back to the matching wire format. The gateway
11
11
  * injects `Authorization` server-side so clients never see access tokens.
12
12
  */
@@ -90,10 +90,16 @@ export interface AuthGatewayParsedRequest {
90
90
  stream: boolean;
91
91
  options: AuthGatewayParsedRequestOptions;
92
92
  }
93
+ export interface AuthGatewayStreamControl {
94
+ /** Gateway request signal. Encoders stop producing frames when it aborts. */
95
+ signal?: AbortSignal;
96
+ /** Called when the HTTP response body is cancelled by the client. */
97
+ onCancel?: (reason?: unknown) => void;
98
+ }
93
99
  export interface AuthGatewayFormatModule {
94
100
  parseRequest(body: unknown, headers?: Headers): AuthGatewayParsedRequest;
95
101
  encodeResponse(message: AssistantMessage, requestedModelId: string): Record<string, unknown>;
96
- encodeStream(events: AssistantMessageEventStream, requestedModelId: string, options?: AuthGatewayParsedRequestOptions): ReadableStream<Uint8Array>;
102
+ encodeStream(events: AssistantMessageEventStream, requestedModelId: string, options?: AuthGatewayParsedRequestOptions, control?: AuthGatewayStreamControl): ReadableStream<Uint8Array>;
97
103
  /**
98
104
  * Emit a protocol-specific error envelope. OpenAI returns
99
105
  * `{ error: { message, type } }`; Anthropic returns
@@ -0,0 +1,119 @@
1
+ import type { OAuthAccess } from "./auth-storage";
2
+ /**
3
+ * Context passed to an {@link ApiKeyResolver} on each resolution attempt.
4
+ *
5
+ * The `error`/`lastChance` pair drives the central a/b/c retry policy shared by
6
+ * the streaming ({@link streamSimple}) and non-streaming ({@link withAuth})
7
+ * drivers:
8
+ * - `error === undefined` → **initial resolve** (no force-refresh; cheap, may
9
+ * return a locally-cached not-yet-expired token).
10
+ * - `error !== undefined && !lastChance` → **step (b): refresh the SAME
11
+ * account** (force a token re-mint / await an in-flight broker refresh).
12
+ * - `error !== undefined && lastChance` → **step (c): switch account**
13
+ * (invalidate/usage-limit the current credential and rotate to a sibling).
14
+ *
15
+ * The resolver returns the bearer to send, or `undefined` to stop retrying and
16
+ * surface the last error to the caller.
17
+ */
18
+ export interface ApiKeyResolveContext {
19
+ /** True on the final retry step — the resolver should rotate to a sibling credential. */
20
+ lastChance: boolean;
21
+ /** The auth error that triggered this re-resolution, or `undefined` on the initial resolve. */
22
+ error: unknown;
23
+ /** Caller cancel signal, threaded into any credential refresh / rotation work. */
24
+ signal?: AbortSignal;
25
+ }
26
+ /**
27
+ * Resolves the API key to send for a request, retried through the a/b/c policy
28
+ * described on {@link ApiKeyResolveContext}.
29
+ */
30
+ export type ApiKeyResolver = (ctx: ApiKeyResolveContext) => Promise<string | undefined> | string | undefined;
31
+ /** A static bearer string, or a {@link ApiKeyResolver} that mints/rotates one. */
32
+ export type ApiKey = string | ApiKeyResolver;
33
+ /** Narrows {@link ApiKey} to its resolver form. */
34
+ export declare function isApiKeyResolver(key: ApiKey | undefined): key is ApiKeyResolver;
35
+ /**
36
+ * Performs the initial resolve of an {@link ApiKey} (`error: undefined`,
37
+ * `lastChance: false`). Static keys pass through unchanged.
38
+ */
39
+ export declare function resolveApiKeyOnce(key: ApiKey | undefined, signal?: AbortSignal): Promise<string | undefined>;
40
+ /**
41
+ * Classifies whether an error should trigger a credential refresh/rotation
42
+ * retry: a hard `401`, or a rotatable usage-limit ("usage_limit_reached",
43
+ * Codex's "you have hit your ChatGPT usage limit", etc.).
44
+ */
45
+ export declare function isAuthRetryableError(error: unknown): boolean;
46
+ /**
47
+ * The ordered `lastChance` values for the retry steps after the initial
48
+ * attempt fails: `false` → step (b) refresh-same, `true` → step (c) switch.
49
+ * Shared by {@link withAuth} and the streaming retry driver so both run the
50
+ * same policy.
51
+ */
52
+ export declare const AUTH_RETRY_STEPS: readonly boolean[];
53
+ /** Resolve a single retry step, swallowing resolver failures into `undefined`. */
54
+ export declare function resolveRetryKey(resolver: ApiKeyResolver, lastChance: boolean, error: unknown, signal?: AbortSignal): Promise<string | undefined>;
55
+ /**
56
+ * Runs an auth-protected operation through the central a/b/c retry policy.
57
+ *
58
+ * - A static string key (or any non-resolver) → a single `attempt` with no
59
+ * retry (identical to the legacy static-key path).
60
+ * - A resolver → initial `attempt`, then on a retryable auth error up to two
61
+ * more attempts (refresh-same, then switch). A step is skipped when the
62
+ * resolver returns the same key it just tried or `undefined`; non-auth errors
63
+ * propagate immediately.
64
+ *
65
+ * Used by non-streaming consumers (image generation, web search, completion
66
+ * helpers). The streaming driver in `stream.ts` implements the same policy with
67
+ * its replay-safe buffering machinery.
68
+ */
69
+ export declare function withAuth<T>(key: ApiKey | undefined, attempt: (key: string) => Promise<T>, opts?: {
70
+ isAuthError?: (error: unknown) => boolean;
71
+ signal?: AbortSignal;
72
+ missingKeyMessage?: string;
73
+ }): Promise<T>;
74
+ /**
75
+ * Minimal structural slice of `AuthStorage` consumed by {@link withOAuthAccess}.
76
+ * Typed structurally (and importing only the `OAuthAccess` type) so this module
77
+ * never takes a runtime dependency on `./auth-storage`.
78
+ */
79
+ export interface OAuthAccessSource {
80
+ getOAuthAccess(provider: string, sessionId?: string, options?: {
81
+ forceRefresh?: boolean;
82
+ signal?: AbortSignal;
83
+ }): Promise<OAuthAccess | undefined>;
84
+ rotateSessionCredential(provider: string, sessionId: string | undefined, options?: {
85
+ error?: unknown;
86
+ signal?: AbortSignal;
87
+ }): Promise<boolean>;
88
+ }
89
+ export interface WithOAuthAccessOptions {
90
+ /** Session id for credential stickiness, threaded into every resolve. */
91
+ sessionId?: string;
92
+ signal?: AbortSignal;
93
+ /** Override the retryable-error classifier (default {@link isAuthRetryableError}). */
94
+ isAuthError?: (error: unknown) => boolean;
95
+ /**
96
+ * Pre-resolved access used for the initial attempt. Callers that already
97
+ * resolved access for an availability gate pass it here so the helper
98
+ * doesn't double-resolve (mirrors the gateway resolver's `initialKey`).
99
+ */
100
+ seed?: OAuthAccess;
101
+ missingAccessMessage?: string;
102
+ }
103
+ /**
104
+ * {@link withAuth} for OAuth-access consumers: runs an auth-protected
105
+ * operation through the central a/b/c retry policy, handing the attempt the
106
+ * full {@link OAuthAccess} (bearer + identity metadata: `accountId`,
107
+ * `projectId`, `enterpriseUrl`) instead of bare API-key bytes.
108
+ *
109
+ * - initial → `getOAuthAccess` (or `opts.seed`).
110
+ * - step (b) → `getOAuthAccess` with `forceRefresh: true` (re-mint the SAME
111
+ * account; picks up peer/broker rotations).
112
+ * - step (c) → `rotateSessionCredential` then re-resolve (switch to a sibling).
113
+ *
114
+ * A step is skipped when it yields no access or the same `accessToken` that
115
+ * just failed; non-auth errors propagate immediately. Use this instead of
116
+ * hand-rolled `getOAuthAccess` + fetch flows so 401s and usage-limits rotate
117
+ * credentials instead of failing the call.
118
+ */
119
+ export declare function withOAuthAccess<T>(storage: OAuthAccessSource, provider: string, attempt: (access: OAuthAccess) => Promise<T>, opts?: WithOAuthAccessOptions): Promise<T>;
@@ -8,9 +8,11 @@
8
8
  * - `SqliteAuthCredentialStore`: concrete SQLite-backed implementation
9
9
  */
10
10
  import { Database } from "bun:sqlite";
11
+ import type { ApiKeyResolver } from "./auth-retry";
12
+ import type { OAuthController, OAuthCredentials, OAuthProviderId } from "./registry/oauth/types";
11
13
  import type { Provider } from "./types";
12
- import type { CredentialRankingStrategy, UsageLogger, UsageProvider, UsageReport } from "./usage";
13
- import type { OAuthController, OAuthCredentials, OAuthProviderId } from "./utils/oauth/types";
14
+ import type { CredentialRankingStrategy, UsageHistoryEntry, UsageHistoryQuery, UsageLogger, UsageProvider, UsageReport } from "./usage";
15
+ import { type CodexResetConsumeCode, type CodexResetCredit } from "./usage/openai-codex-reset";
14
16
  export type ApiKeyCredential = {
15
17
  type: "api_key";
16
18
  key: string;
@@ -21,6 +23,21 @@ export type OAuthCredential = {
21
23
  export type AuthCredential = ApiKeyCredential | OAuthCredential;
22
24
  export type AuthCredentialEntry = AuthCredential | AuthCredential[];
23
25
  export type AuthStorageData = Record<string, AuthCredentialEntry>;
26
+ /**
27
+ * Cascade leg that supplies a provider's active credential, highest precedence
28
+ * first — mirrors {@link AuthStorage.getApiKey}'s resolution order.
29
+ */
30
+ export type CredentialOriginKind = "runtime" | "config" | "oauth" | "api_key" | "env" | "fallback";
31
+ /**
32
+ * Structured provenance for a provider's auth, for UI that needs a machine
33
+ * tag (the `/login` provider list) rather than the prose of
34
+ * {@link AuthStorage.describeCredentialSource}.
35
+ */
36
+ export interface CredentialOrigin {
37
+ kind: CredentialOriginKind;
38
+ /** Env var name when `kind === "env"` and a single named variable backs it. */
39
+ envVar?: string;
40
+ }
24
41
  /**
25
42
  * Serialized representation of AuthStorage for passing to subagent workers.
26
43
  * Contains only the essential credential data, not runtime state.
@@ -209,6 +226,14 @@ export interface AuthCredentialStore {
209
226
  }): string | null;
210
227
  setCache(key: string, value: string, expiresAtSec: number): void;
211
228
  cleanExpiredCache(): void;
229
+ /**
230
+ * Append usage-limit snapshots for trend history. Optional: stores without
231
+ * durable storage (e.g. the broker remote store) omit it and recording is
232
+ * skipped — the broker host records into its own database instead.
233
+ */
234
+ recordUsageSnapshots?(entries: UsageHistoryEntry[]): void;
235
+ /** Read recorded usage-limit snapshots, oldest first. */
236
+ listUsageHistory?(query?: UsageHistoryQuery): UsageHistoryEntry[];
212
237
  /**
213
238
  * Optional store-supplied OAuth refresh. When present, `AuthStorage` uses
214
239
  * it before the per-provider local refresh path. `RemoteAuthCredentialStore`
@@ -283,6 +308,11 @@ export interface AuthCredentialStore {
283
308
  * `replaceAuthCredentialsForProvider`.
284
309
  */
285
310
  replaceAuthCredentialsRemote?(provider: string, credentials: AuthCredential[]): Promise<StoredAuthCredential[]>;
311
+ /**
312
+ * Optional async write hook for disabling one stored credential. Remote stores
313
+ * use it to await broker persistence before AuthStorage updates its snapshot.
314
+ */
315
+ deleteAuthCredentialRemote?(id: number, disabledCause: string): Promise<boolean>;
286
316
  /**
287
317
  * Optional async write hook for clearing every credential for a provider
288
318
  * (logout). When present, `AuthStorage.remove` routes through this instead
@@ -341,7 +371,7 @@ export type AuthStorageOptions = {
341
371
  *
342
372
  * Examples:
343
373
  * - `"local ~/.prometheus/agent/agent.db"`
344
- * - `"broker http://can.internal:8765"`
374
+ * - `"broker http://auth-broker.internal:8765"`
345
375
  */
346
376
  sourceLabel?: string;
347
377
  /**
@@ -349,7 +379,7 @@ export type AuthStorageOptions = {
349
379
  * calls this instead of fanning out per-credential. The primary use case is
350
380
  * routing through a broker that egresses from a less-throttled IP — e.g. a
351
381
  * residential laptop trips Anthropic's per-IP rate limit on the usage
352
- * endpoint and drops 2-of-5 credentials, while the VPS broker gets all 5.
382
+ * endpoint and drops 2-of-5 credentials, while the broker gets all 5.
353
383
  *
354
384
  * Implementations may return null when no usage data is available; the
355
385
  * AuthStorage caller surfaces that to its own consumer unchanged.
@@ -357,6 +387,22 @@ export type AuthStorageOptions = {
357
387
  fetchUsageReports?: (signal?: AbortSignal) => Promise<UsageReport[] | null>;
358
388
  };
359
389
  export declare function isDefinitiveOAuthFailure(errorMsg: string): boolean;
390
+ /**
391
+ * Outcome of {@link AuthStorage.markUsageLimitReached}.
392
+ *
393
+ * `switched` is `true` when an unblocked same-type sibling credential is
394
+ * available right now, so the caller can retry immediately and the next
395
+ * `getApiKey` will hand it out. When `false`, `retryAtMs` (epoch ms) carries
396
+ * the earliest moment any same-type sibling's temporary block expires —
397
+ * callers should prefer waiting until then over the provider's (often
398
+ * multi-hour) retry-after when it is sooner. `retryAtMs` is `undefined` when
399
+ * no sibling credentials exist at all, or when the session has no tracked
400
+ * credential to rotate away from.
401
+ */
402
+ export interface UsageLimitMarkResult {
403
+ switched: boolean;
404
+ retryAtMs?: number;
405
+ }
360
406
  type AuthApiKeyOptions = {
361
407
  baseUrl?: string;
362
408
  modelId?: string;
@@ -366,6 +412,13 @@ type AuthApiKeyOptions = {
366
412
  * stranding the caller for `timeoutMs * (maxRetries + 1)`.
367
413
  */
368
414
  signal?: AbortSignal;
415
+ /**
416
+ * Force a re-mint of the session-preferred OAuth credential's access token,
417
+ * bypassing the not-yet-expired short-circuit. Powers step (b) of the
418
+ * auth-retry policy ("refresh the SAME account") so a locally-cached token
419
+ * that a peer/broker rotated out from under us is replaced before retrying.
420
+ */
421
+ forceRefresh?: boolean;
369
422
  };
370
423
  /**
371
424
  * Refreshed OAuth access plus identity metadata returned by
@@ -391,6 +444,17 @@ export interface OAuthAccessFailure {
391
444
  enterpriseUrl?: string;
392
445
  error: string;
393
446
  }
447
+ /**
448
+ * Identity of the OAuth credential a session is currently routed to. Read-only
449
+ * display/metadata shape: `accountId` is the provider's account UUID, `email`
450
+ * the user-facing login, `projectId` the GCP-style project for providers that
451
+ * key usage on it (Gemini CLI / Antigravity).
452
+ */
453
+ export interface OAuthAccountIdentity {
454
+ accountId?: string;
455
+ email?: string;
456
+ projectId?: string;
457
+ }
394
458
  export type OAuthAccessResolution = ({
395
459
  ok: true;
396
460
  } & OAuthAccess) | ({
@@ -400,6 +464,44 @@ export interface InvalidateCredentialMatchingOptions {
400
464
  signal?: AbortSignal;
401
465
  sessionId?: string;
402
466
  }
467
+ /**
468
+ * Identifies which stored account to redeem a saved rate-limit reset for.
469
+ * Any one field is enough; `credentialId` is the most precise.
470
+ */
471
+ export interface ResetCreditTarget {
472
+ credentialId?: number;
473
+ accountId?: string;
474
+ email?: string;
475
+ }
476
+ /** Outcome of {@link AuthStorage.redeemResetCredit}. */
477
+ export interface ResetCreditRedeemOutcome {
478
+ /** `true` only when a reset was actually applied (`code === "reset"`). */
479
+ ok: boolean;
480
+ /**
481
+ * Result code. Backend codes: `reset` (success), `already_redeemed`,
482
+ * `no_credit`, `nothing_to_reset`. Locally-synthesized: `no_account`
483
+ * (target not found), `account_unavailable` (token refresh failed),
484
+ * `http_<status>` (unexpected HTTP).
485
+ */
486
+ code: CodexResetConsumeCode;
487
+ accountId?: string;
488
+ email?: string;
489
+ /** The credit that was spent (when one was). */
490
+ creditId?: string;
491
+ }
492
+ /** One stored account's live saved-reset status, from {@link AuthStorage.listResetCredits}. */
493
+ export interface ResetCreditAccountStatus {
494
+ credentialId?: number;
495
+ accountId?: string;
496
+ email?: string;
497
+ /** Resets redeemable for this account right now (live, not cached). */
498
+ availableCount: number;
499
+ credits: CodexResetCredit[];
500
+ /** Whether this is the given session's active account. */
501
+ active: boolean;
502
+ /** Set when the account's token refresh or list call failed. */
503
+ error?: string;
504
+ }
403
505
  /**
404
506
  * Credential storage backed by an AuthCredentialStore.
405
507
  * Reads from storage on reload(), manages round-robin credential selection,
@@ -410,7 +512,7 @@ export declare class AuthStorage {
410
512
  constructor(store: AuthCredentialStore, options?: AuthStorageOptions);
411
513
  /**
412
514
  * Create an AuthStorage instance backed by a AuthCredentialStore.
413
- * Convenience factory for standalone use (e.g., @prometheus-ai/ai CLI).
515
+ * Convenience factory for standalone use (e.g., Prometheus AI CLI).
414
516
  * @param dbPath - Path to SQLite database
415
517
  */
416
518
  static create(dbPath: string, options?: AuthStorageOptions): Promise<AuthStorage>;
@@ -488,10 +590,18 @@ export declare class AuthStorage {
488
590
  * Set credential for a provider.
489
591
  */
490
592
  set(provider: string, credential: AuthCredentialEntry): Promise<void>;
593
+ /**
594
+ * List stored credential rows, optionally filtered by provider.
595
+ */
596
+ listStoredCredentials(provider?: string): StoredAuthCredential[];
491
597
  /**
492
598
  * Remove credential for a provider.
493
599
  */
494
600
  remove(provider: string): Promise<void>;
601
+ /**
602
+ * Remove one stored credential for a provider.
603
+ */
604
+ removeCredential(provider: string, credentialId: number): Promise<boolean>;
495
605
  /**
496
606
  * List all providers with credentials.
497
607
  */
@@ -517,6 +627,15 @@ export declare class AuthStorage {
517
627
  * silently satisfies xai-oauth and routes around `providers.xai.baseUrl`.
518
628
  */
519
629
  hasNonEnvCredential(provider: string): boolean;
630
+ /**
631
+ * Classify where a provider's auth comes from, following the same precedence
632
+ * as {@link AuthStorage.getApiKey}: runtime override → config override →
633
+ * stored credential (api_key before oauth, matching getApiKey) → env var →
634
+ * fallback resolver. Returns undefined when no auth is configured.
635
+ *
636
+ * Compact, structured counterpart to {@link describeCredentialSource}.
637
+ */
638
+ getCredentialOrigin(provider: string): CredentialOrigin | undefined;
520
639
  /**
521
640
  * Check if OAuth credentials are configured for a provider.
522
641
  */
@@ -533,6 +652,12 @@ export declare class AuthStorage {
533
652
  * Returns `undefined` when no OAuth credential carries an `accountId`.
534
653
  */
535
654
  getOAuthAccountId(provider: string, sessionId?: string): string | undefined;
655
+ /**
656
+ * Get the OAuth account identity for a provider, preferring the credential that
657
+ * is session-sticky for `sessionId`. This is a read-only lookup for display and
658
+ * metadata paths; it does not refresh tokens, rank usage, or advance selection.
659
+ */
660
+ getOAuthAccountIdentity(provider: string, sessionId?: string): OAuthAccountIdentity | undefined;
536
661
  /**
537
662
  * Get all credentials.
538
663
  */
@@ -556,6 +681,11 @@ export declare class AuthStorage {
556
681
  * Logout from a provider.
557
682
  */
558
683
  logout(provider: string): Promise<void>;
684
+ /**
685
+ * Recorded usage-limit snapshots, oldest first. Empty when the underlying
686
+ * store has no durable history (e.g. a broker-backed remote store).
687
+ */
688
+ listUsageHistory(query?: UsageHistoryQuery): UsageHistoryEntry[];
559
689
  ingestUsageHeaders(provider: Provider, headers: Record<string, string>, options?: {
560
690
  sessionId?: string;
561
691
  baseUrl?: string;
@@ -595,13 +725,16 @@ export declare class AuthStorage {
595
725
  /**
596
726
  * Marks the current session's credential as temporarily blocked due to usage limits.
597
727
  * Uses usage reports to determine accurate reset time when available.
598
- * Returns true if a credential was blocked, enabling automatic fallback to the next credential.
728
+ * Returns whether a sibling credential is available now; when none is, also
729
+ * reports the earliest time a blocked sibling becomes available again so
730
+ * callers can wait for the sibling instead of the provider's full window.
599
731
  */
600
732
  markUsageLimitReached(provider: string, sessionId: string | undefined, options?: {
601
733
  retryAfterMs?: number;
602
734
  baseUrl?: string;
735
+ modelId?: string;
603
736
  signal?: AbortSignal;
604
- }): Promise<boolean>;
737
+ }): Promise<UsageLimitMarkResult>;
605
738
  /**
606
739
  * Peek at API key for a provider without refreshing OAuth tokens.
607
740
  * Used for model discovery where we only need to know if credentials exist
@@ -645,8 +778,76 @@ export declare class AuthStorage {
645
778
  * exercise each stored account exactly once.
646
779
  */
647
780
  getOAuthAccesses(provider: string, options?: AuthApiKeyOptions): Promise<OAuthAccessResolution[]>;
781
+ /**
782
+ * List saved rate-limit resets for every stored OAuth account of `provider`
783
+ * (Codex), fetched LIVE from the dedicated `rate-limit-reset-credits` route.
784
+ *
785
+ * This deliberately bypasses the usage-report cache: `/wham/usage` is
786
+ * IP-rate-limited and may serve stale (or pre-feature) snapshots when many
787
+ * accounts are polled, which would hide redeemable credits. One entry per
788
+ * account, with the session's active account flagged and unreachable
789
+ * accounts carrying an `error`.
790
+ */
791
+ listResetCredits(options?: {
792
+ provider?: string;
793
+ sessionId?: string;
794
+ baseUrlResolver?: (provider: string) => string | undefined;
795
+ signal?: AbortSignal;
796
+ }): Promise<ResetCreditAccountStatus[]>;
797
+ /**
798
+ * Redeem one saved rate-limit reset (OpenAI Codex "saved resets") for a
799
+ * specific stored account.
800
+ *
801
+ * Resolves a fresh access token for the target account, picks an available
802
+ * credit (the given `creditId`, else the first redeemable one), spends it,
803
+ * and invalidates the cached usage report so the next `/usage` reflects the
804
+ * reset. Never throws for business outcomes — inspect the returned `code`.
805
+ */
806
+ redeemResetCredit(options: {
807
+ target: ResetCreditTarget;
808
+ provider?: string;
809
+ creditId?: string;
810
+ baseUrlResolver?: (provider: string) => string | undefined;
811
+ signal?: AbortSignal;
812
+ }): Promise<ResetCreditRedeemOutcome>;
648
813
  invalidateCredentialMatching(provider: string, apiKey: string, options?: InvalidateCredentialMatchingOptions): Promise<boolean>;
649
814
  invalidateCredentialMatching(provider: string, apiKey: string, signal?: AbortSignal): Promise<boolean>;
815
+ /**
816
+ * Rotate away from the session's current credential after a retryable auth
817
+ * error — step (c) of the auth-retry policy. Stateless: looks up the
818
+ * session-sticky credential (no API-key matching needed), applies the
819
+ * storage action for the error class, then clears the sticky so the next
820
+ * {@link AuthStorage.getApiKey} for this session picks a sibling.
821
+ *
822
+ * - usage-limit / account-rate-limit error → {@link AuthStorage.markUsageLimitReached}
823
+ * (temporary block via its own backoff — default plus server usage-report
824
+ * reset; sticky left intact so the next resolve re-ranks around the block).
825
+ * - otherwise (hard 401 / auth failure) → mark the credential suspect (or
826
+ * reload when no broker hook is wired) and block it, then drop the sticky.
827
+ *
828
+ * Returns whether another usable credential of the same type remains.
829
+ */
830
+ rotateSessionCredential(provider: string, sessionId: string | undefined, options?: {
831
+ error?: unknown;
832
+ modelId?: string;
833
+ signal?: AbortSignal;
834
+ }): Promise<boolean>;
835
+ /**
836
+ * Build an {@link ApiKeyResolver} backed by this storage, implementing the
837
+ * central a/b/c auth-retry policy:
838
+ *
839
+ * - initial (`error: undefined`) → resolve the session credential.
840
+ * - step (b) `!lastChance` → force-refresh the SAME session-sticky credential.
841
+ * - step (c) `lastChance` → rotate to a sibling credential, then re-resolve.
842
+ *
843
+ * Used by web-search providers and other consumers that hold an AuthStorage
844
+ * directly (no ModelRegistry in scope).
845
+ */
846
+ resolver(provider: string, options?: {
847
+ sessionId?: string;
848
+ baseUrl?: string;
849
+ modelId?: string;
850
+ }): ApiKeyResolver;
650
851
  /**
651
852
  * Build a redacted snapshot of all loaded credentials for the auth-broker
652
853
  * wire. OAuth refresh tokens are replaced with {@link REMOTE_REFRESH_SENTINEL}
@@ -702,10 +903,16 @@ export declare class AuthStorage {
702
903
  */
703
904
  describeCredentialSource(provider: string, sessionId?: string): string | undefined;
704
905
  }
906
+ /**
907
+ * SQLite's busy result code family — base `SQLITE_BUSY` plus the extended
908
+ * variants `SQLITE_BUSY_RECOVERY` (concurrent WAL recovery), `SQLITE_BUSY_SNAPSHOT`,
909
+ * and `SQLITE_BUSY_TIMEOUT`. All warrant the same backoff-and-retry treatment.
910
+ */
911
+ export declare function isSqliteBusyError(err: unknown): boolean;
705
912
  /**
706
913
  * Default SQLite-backed implementation of {@link AuthCredentialStore}.
707
914
  *
708
- * Used by the @prometheus-ai/ai CLI and as the default store for `AuthStorage.create()`.
915
+ * Used by the Prometheus AI CLI and as the default store for `AuthStorage.create()`.
709
916
  * Also exposes convenience methods (`saveOAuth`, `getOAuth`, `saveApiKey`,
710
917
  * `getApiKey`, `listProviders`, `deleteProvider`) that callers can use directly
711
918
  * without going through `AuthStorage`.
@@ -732,6 +939,8 @@ export declare class SqliteAuthCredentialStore implements AuthCredentialStore {
732
939
  }): string | null;
733
940
  setCache(key: string, value: string, expiresAtSec: number): void;
734
941
  cleanExpiredCache(): void;
942
+ recordUsageSnapshots(entries: UsageHistoryEntry[]): void;
943
+ listUsageHistory(query?: UsageHistoryQuery): UsageHistoryEntry[];
735
944
  /**
736
945
  * Save OAuth credentials for a provider.
737
946
  * Preserves unrelated identities and replaces only the matching credential.
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Structured HTTP errors thrown by provider clients.
3
+ *
4
+ * Downstream classification reads these fields structurally rather than via
5
+ * `instanceof`: `extractHttpStatusFromError` (@prometheus-ai/utils) reads `status`,
6
+ * `getHeadersFromError` (retry-after extraction) reads `headers`, and retry
7
+ * policies such as `isCopilotTransientModelError` read `code`. Per-provider
8
+ * subclasses exist so call sites can narrow with `instanceof` and logs carry
9
+ * a meaningful `error.name`.
10
+ */
11
+ export interface ProviderHttpErrorOptions {
12
+ /** Response headers; enables `retry-after`/rate-limit extraction downstream. */
13
+ headers?: Headers;
14
+ /** Machine-readable error code from the response body (`error.code` / `error.type`). */
15
+ code?: string;
16
+ cause?: unknown;
17
+ }
18
+ /** Non-2xx HTTP response from a provider endpoint. */
19
+ export declare class ProviderHttpError extends Error {
20
+ readonly status: number;
21
+ readonly headers: Headers | undefined;
22
+ readonly code: string | undefined;
23
+ constructor(message: string, status: number, options?: ProviderHttpErrorOptions);
24
+ }
@@ -1,15 +1,13 @@
1
+ export { ANTIGRAVITY_SYSTEM_INSTRUCTION, getAntigravityUserAgent, getGeminiCliHeaders, } from "@prometheus-ai/catalog/wire/gemini-headers";
1
2
  export { type ZodType, z } from "zod/v4";
2
3
  export * from "./api-registry";
3
4
  export * from "./auth-broker";
4
5
  export { type AuthGatewayBootOptions, type ModelResolver, startAuthGateway } from "./auth-gateway/server";
5
6
  export * from "./auth-gateway/types";
7
+ export * from "./auth-retry";
6
8
  export * from "./auth-storage";
7
- export * from "./model-cache";
8
- export * from "./model-manager";
9
- export * from "./model-thinking";
10
- export * from "./models";
9
+ export * from "./errors";
11
10
  export * from "./provider-details";
12
- export * from "./provider-models";
13
11
  export * from "./providers/anthropic";
14
12
  export * from "./providers/anthropic-client";
15
13
  export * from "./providers/azure-openai-responses";
@@ -17,7 +15,6 @@ export type * from "./providers/cursor";
17
15
  export * from "./providers/gitlab-duo";
18
16
  export type * from "./providers/google";
19
17
  export type * from "./providers/google-gemini-cli";
20
- export * from "./providers/google-gemini-headers";
21
18
  export type * from "./providers/google-vertex";
22
19
  export * from "./providers/kimi";
23
20
  export * from "./providers/mock";
@@ -27,6 +24,7 @@ export * from "./providers/openai-completions";
27
24
  export * from "./providers/openai-responses";
28
25
  export * from "./providers/synthetic";
29
26
  export * from "./rate-limit-utils";
27
+ export * from "./registry";
30
28
  export * from "./stream";
31
29
  export * from "./types";
32
30
  export * from "./usage";
@@ -37,12 +35,10 @@ export * from "./usage/google-antigravity";
37
35
  export * from "./usage/kimi";
38
36
  export * from "./usage/minimax-code";
39
37
  export * from "./usage/openai-codex";
38
+ export * from "./usage/openai-codex-reset";
40
39
  export * from "./usage/zai";
41
40
  export * from "./utils/anthropic-auth";
42
- export * from "./utils/discovery";
43
41
  export * from "./utils/event-stream";
44
- export * from "./utils/oauth";
45
- export type { OAuthCredentials, OAuthProvider, OAuthProviderId, OAuthProviderInfo, } from "./utils/oauth/types";
46
42
  export * from "./utils/overflow";
47
43
  export * from "./utils/retry";
48
44
  export * from "./utils/schema";
@@ -14,7 +14,7 @@ export interface ProviderDetailsContext {
14
14
  authMode?: string;
15
15
  /**
16
16
  * Human-readable description of the active credential, e.g.
17
- * `"broker http://can.internal:8765 · oauth #5 (foo@bar.com)"`.
17
+ * `"broker http://auth-broker.internal:8765 - oauth #5 (foo@bar.com)"`.
18
18
  * Rendered as a `Source` field; omitted when undefined.
19
19
  */
20
20
  credentialSource?: string;