@linxiraos/pi-ai 1.1.20 → 1.1.23

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 (298) hide show
  1. package/CHANGELOG.md +3 -13
  2. package/README.md +12 -0
  3. package/THIRD-PARTY-NOTICES.txt +3 -40
  4. package/dist/types/auth/abort.d.ts +6 -0
  5. package/dist/types/auth/affinity.d.ts +68 -0
  6. package/dist/types/auth/blocks.d.ts +106 -0
  7. package/dist/types/auth/cascade.d.ts +147 -0
  8. package/dist/types/auth/health.d.ts +66 -0
  9. package/dist/types/auth/oauth.d.ts +93 -0
  10. package/dist/types/auth/policy.d.ts +27 -0
  11. package/dist/types/auth/pool.d.ts +214 -0
  12. package/dist/types/auth/rank.d.ts +53 -0
  13. package/dist/types/auth/refresh.d.ts +59 -0
  14. package/dist/types/auth/resets.d.ts +28 -0
  15. package/dist/types/auth/rotation.d.ts +69 -0
  16. package/dist/types/auth/select.d.ts +86 -0
  17. package/dist/types/auth/sqlite-credential-store.d.ts +11 -10
  18. package/dist/types/auth/store.d.ts +197 -0
  19. package/dist/types/auth/types.d.ts +1179 -0
  20. package/dist/types/auth/usage-cache.d.ts +92 -0
  21. package/dist/types/auth/usage-report.d.ts +32 -0
  22. package/dist/types/auth/usage.d.ts +110 -0
  23. package/dist/types/auth-broker/client.d.ts +4 -3
  24. package/dist/types/auth-broker/discover.d.ts +35 -1
  25. package/dist/types/auth-broker/refresher.d.ts +1 -1
  26. package/dist/types/auth-broker/remote-store.d.ts +14 -18
  27. package/dist/types/auth-broker/types.d.ts +4 -2
  28. package/dist/types/auth-broker/wire-schemas.d.ts +2 -1
  29. package/dist/types/auth-gateway/dispatch.d.ts +80 -0
  30. package/dist/types/auth-gateway/http.d.ts +5 -6
  31. package/dist/types/auth-gateway/index.d.ts +1 -0
  32. package/dist/types/auth-gateway/routes/embeddings.d.ts +3 -0
  33. package/dist/types/auth-gateway/routes/images.d.ts +3 -0
  34. package/dist/types/auth-gateway/routes/rerank.d.ts +3 -0
  35. package/dist/types/auth-gateway/routes/speech.d.ts +2 -0
  36. package/dist/types/auth-gateway/routes/systemone.d.ts +2 -0
  37. package/dist/types/auth-gateway/routes/transcriptions.d.ts +3 -0
  38. package/dist/types/auth-gateway/routes/video.d.ts +7 -0
  39. package/dist/types/auth-gateway/server.d.ts +10 -16
  40. package/dist/types/auth-gateway/types.d.ts +7 -0
  41. package/dist/types/auth-retry.d.ts +45 -34
  42. package/dist/types/auth-storage.d.ts +53 -1326
  43. package/dist/types/embeddings/index.d.ts +7 -0
  44. package/dist/types/embeddings/openai-embeddings.d.ts +15 -0
  45. package/dist/types/embeddings/types.d.ts +15 -0
  46. package/dist/types/error/classes.d.ts +4 -1
  47. package/dist/types/error/flags.d.ts +20 -5
  48. package/dist/types/error/rate-limit.d.ts +6 -4
  49. package/dist/types/images/google-antigravity.d.ts +9 -0
  50. package/dist/types/images/google-generative-ai.d.ts +3 -0
  51. package/dist/types/images/index.d.ts +14 -0
  52. package/dist/types/images/openai-hosted.d.ts +3 -0
  53. package/dist/types/images/openai-images.d.ts +5 -0
  54. package/dist/types/images/openrouter-images.d.ts +3 -0
  55. package/dist/types/images/shared.d.ts +34 -0
  56. package/dist/types/images/types.d.ts +40 -0
  57. package/dist/types/index.d.ts +25 -12
  58. package/dist/types/judgment/types.d.ts +6 -2
  59. package/dist/types/judgment/typesafe.d.ts +18 -22
  60. package/dist/types/provider-session-state.d.ts +2 -2
  61. package/dist/types/providers/amazon-bedrock.d.ts +7 -0
  62. package/dist/types/providers/anthropic-client.d.ts +6 -0
  63. package/dist/types/providers/anthropic-compaction.d.ts +10 -0
  64. package/dist/types/providers/anthropic-identity.d.ts +18 -0
  65. package/dist/types/providers/anthropic-slow-mode.d.ts +109 -0
  66. package/dist/types/providers/anthropic-state.d.ts +13 -0
  67. package/dist/types/providers/anthropic-user-profiles.d.ts +88 -0
  68. package/dist/types/providers/anthropic-wire.d.ts +24 -14
  69. package/dist/types/providers/anthropic.d.ts +8 -60
  70. package/dist/types/providers/apple-foundation-models.d.ts +37 -0
  71. package/dist/types/providers/claude-code-fingerprint.d.ts +22 -5
  72. package/dist/types/providers/cursor/exec-modern.d.ts +1 -1
  73. package/dist/types/providers/cursor-pi-args.d.ts +23 -18
  74. package/dist/types/providers/cursor.d.ts +6 -2
  75. package/dist/types/providers/embeddings-server.d.ts +32 -0
  76. package/dist/types/providers/gitlab-duo.d.ts +0 -1
  77. package/dist/types/providers/google-gemini-cli.d.ts +0 -2
  78. package/dist/types/providers/google-shared.d.ts +13 -2
  79. package/dist/types/providers/images-server.d.ts +22 -0
  80. package/dist/types/providers/kimi.d.ts +1 -5
  81. package/dist/types/providers/mock.d.ts +3 -1
  82. package/dist/types/providers/openai-chat-server-schema.d.ts +2 -2
  83. package/dist/types/providers/openai-codex/access-programs.d.ts +13 -0
  84. package/dist/types/providers/openai-codex/live-steering.d.ts +77 -0
  85. package/dist/types/providers/openai-codex/request-transformer.d.ts +4 -0
  86. package/dist/types/providers/openai-codex-attestation.d.ts +6 -0
  87. package/dist/types/providers/openai-codex-compaction.d.ts +6 -0
  88. package/dist/types/providers/openai-codex-responses.d.ts +3 -27
  89. package/dist/types/providers/openai-codex-transport.d.ts +7 -0
  90. package/dist/types/providers/openai-shared.d.ts +0 -9
  91. package/dist/types/providers/register-builtins.d.ts +22 -22
  92. package/dist/types/providers/rerank-server.d.ts +35 -0
  93. package/dist/types/providers/speech-server.d.ts +8 -0
  94. package/dist/types/providers/synthetic.d.ts +1 -5
  95. package/dist/types/providers/systemone-server.d.ts +26 -0
  96. package/dist/types/providers/transcriptions-server.d.ts +32 -0
  97. package/dist/types/providers/transform-messages.d.ts +10 -2
  98. package/dist/types/providers/video-server.d.ts +39 -0
  99. package/dist/types/registry/oauth/types.d.ts +1 -1
  100. package/dist/types/registry/types.d.ts +1 -1
  101. package/dist/types/rerank/index.d.ts +7 -0
  102. package/dist/types/rerank/openrouter-rerank.d.ts +15 -0
  103. package/dist/types/rerank/types.d.ts +17 -0
  104. package/dist/types/speech/index.d.ts +13 -0
  105. package/dist/types/speech/openai-speech.d.ts +3 -0
  106. package/dist/types/speech/transport.d.ts +7 -0
  107. package/dist/types/speech/types.d.ts +24 -0
  108. package/dist/types/speech/xai-tts.d.ts +7 -0
  109. package/dist/types/stream.d.ts +7 -0
  110. package/dist/types/transcription/index.d.ts +7 -0
  111. package/dist/types/transcription/openai-transcriptions.d.ts +15 -0
  112. package/dist/types/transcription/types.d.ts +41 -0
  113. package/dist/types/types.d.ts +120 -36
  114. package/dist/types/usage/claude-api.d.ts +22 -0
  115. package/dist/types/usage/claude-reset.d.ts +57 -0
  116. package/dist/types/usage/claude.d.ts +6 -0
  117. package/dist/types/usage/commandcode.d.ts +4 -0
  118. package/dist/types/usage/cursor.d.ts +3 -1
  119. package/dist/types/usage/registry.d.ts +10 -0
  120. package/dist/types/usage/xai-oauth.d.ts +6 -1
  121. package/dist/types/usage/zai.d.ts +2 -0
  122. package/dist/types/usage.d.ts +138 -8
  123. package/dist/types/utils/event-stream.d.ts +7 -0
  124. package/dist/types/utils/http-inspector.d.ts +6 -0
  125. package/dist/types/utils/openai-http.d.ts +7 -1
  126. package/dist/types/utils/proxy.d.ts +2 -2
  127. package/dist/types/utils/schema/foundation-models.d.ts +15 -0
  128. package/dist/types/utils/schema/index.d.ts +1 -0
  129. package/dist/types/utils/schema/json-schema-validator.d.ts +5 -2
  130. package/dist/types/utils/tool-call-loop-guard.d.ts +1 -1
  131. package/dist/types/video/index.d.ts +11 -0
  132. package/dist/types/video/openrouter-video.d.ts +19 -0
  133. package/dist/types/video/types.d.ts +62 -0
  134. package/package.json +30 -6
  135. package/src/api-registry.ts +1 -0
  136. package/src/auth/abort.ts +17 -0
  137. package/src/auth/affinity.ts +267 -0
  138. package/src/auth/blocks.ts +614 -0
  139. package/src/auth/cascade.ts +493 -0
  140. package/src/auth/health.ts +432 -0
  141. package/src/auth/oauth.ts +353 -0
  142. package/src/auth/policy.ts +162 -0
  143. package/src/auth/pool.ts +817 -0
  144. package/src/auth/rank.ts +146 -0
  145. package/src/auth/refresh.ts +664 -0
  146. package/src/auth/resets.ts +320 -0
  147. package/src/auth/rotation.ts +537 -0
  148. package/src/auth/select.ts +1075 -0
  149. package/src/auth/sqlite-credential-store.ts +66 -21
  150. package/src/auth/store.ts +246 -0
  151. package/src/auth/types.ts +1285 -0
  152. package/src/auth/usage-cache.ts +379 -0
  153. package/src/auth/usage-report.ts +269 -0
  154. package/src/auth/usage.ts +874 -0
  155. package/src/auth-broker/client.ts +21 -3
  156. package/src/auth-broker/discover.ts +222 -42
  157. package/src/auth-broker/refresher.ts +7 -6
  158. package/src/auth-broker/remote-store.ts +150 -74
  159. package/src/auth-broker/server.ts +51 -25
  160. package/src/auth-broker/types.ts +5 -2
  161. package/src/auth-broker/wire-schemas.ts +21 -0
  162. package/src/auth-gateway/dispatch.ts +278 -0
  163. package/src/auth-gateway/http.ts +8 -8
  164. package/src/auth-gateway/index.ts +1 -0
  165. package/src/auth-gateway/routes/embeddings.ts +98 -0
  166. package/src/auth-gateway/routes/images.ts +131 -0
  167. package/src/auth-gateway/routes/rerank.ts +87 -0
  168. package/src/auth-gateway/routes/speech.ts +101 -0
  169. package/src/auth-gateway/routes/systemone.ts +116 -0
  170. package/src/auth-gateway/routes/transcriptions.ts +98 -0
  171. package/src/auth-gateway/routes/video.ts +243 -0
  172. package/src/auth-gateway/server.ts +130 -262
  173. package/src/auth-gateway/types.ts +7 -0
  174. package/src/auth-retry.ts +102 -56
  175. package/src/auth-storage.ts +233 -7458
  176. package/src/dialect/thinking.ts +24 -6
  177. package/src/embeddings/index.ts +17 -0
  178. package/src/embeddings/openai-embeddings.ts +141 -0
  179. package/src/embeddings/types.ts +14 -0
  180. package/src/error/auth-classify.ts +10 -2
  181. package/src/error/classes.ts +23 -3
  182. package/src/error/flags.ts +71 -18
  183. package/src/error/rate-limit.ts +32 -8
  184. package/src/images/google-antigravity.ts +180 -0
  185. package/src/images/google-generative-ai.ts +92 -0
  186. package/src/images/index.ts +59 -0
  187. package/src/images/openai-hosted.ts +203 -0
  188. package/src/images/openai-images.ts +110 -0
  189. package/src/images/openrouter-images.ts +33 -0
  190. package/src/images/shared.ts +193 -0
  191. package/src/images/types.ts +45 -0
  192. package/src/index.ts +26 -12
  193. package/src/judgment/types.ts +13 -6
  194. package/src/judgment/typesafe.ts +58 -48
  195. package/src/provider-session-state.ts +3 -3
  196. package/src/providers/amazon-bedrock.ts +113 -21
  197. package/src/providers/anthropic-client.ts +31 -9
  198. package/src/providers/anthropic-compaction.ts +71 -0
  199. package/src/providers/anthropic-identity.ts +136 -0
  200. package/src/providers/anthropic-messages-server.ts +2 -0
  201. package/src/providers/anthropic-slow-mode.ts +232 -0
  202. package/src/providers/anthropic-state.ts +55 -0
  203. package/src/providers/anthropic-user-profiles.ts +195 -0
  204. package/src/providers/anthropic-wire.ts +22 -12
  205. package/src/providers/anthropic.ts +1031 -914
  206. package/src/providers/apple-foundation-models.ts +406 -0
  207. package/src/providers/aws-credentials.ts +124 -11
  208. package/src/providers/aws-eventstream.ts +4 -3
  209. package/src/providers/azure-openai-responses.ts +3 -4
  210. package/src/providers/bedrock-mantle.ts +1 -1
  211. package/src/providers/claude-code-fingerprint.ts +55 -5
  212. package/src/providers/cowork-fetch.ts +56 -7
  213. package/src/providers/cursor/exec-modern.ts +2 -1
  214. package/src/providers/cursor/proto/agent.proto +5 -0
  215. package/src/providers/cursor-pi-args.ts +27 -18
  216. package/src/providers/cursor.ts +249 -88
  217. package/src/providers/devin.ts +43 -13
  218. package/src/providers/embeddings-server.ts +151 -0
  219. package/src/providers/gitlab-duo.ts +20 -8
  220. package/src/providers/google-gemini-cli.ts +13 -31
  221. package/src/providers/google-shared.ts +69 -51
  222. package/src/providers/images-server.ts +159 -0
  223. package/src/providers/inference-headers.ts +7 -1
  224. package/src/providers/kimi.ts +1 -8
  225. package/src/providers/mock.ts +4 -0
  226. package/src/providers/ollama.ts +2 -0
  227. package/src/providers/openai-chat-server-schema.ts +1 -1
  228. package/src/providers/openai-chat-server.ts +3 -1
  229. package/src/providers/openai-codex/access-programs.ts +70 -0
  230. package/src/providers/openai-codex/live-steering.ts +237 -0
  231. package/src/providers/openai-codex/request-transformer.ts +2 -0
  232. package/src/providers/openai-codex-attestation.ts +19 -0
  233. package/src/providers/openai-codex-compaction.ts +18 -0
  234. package/src/providers/openai-codex-responses.ts +474 -147
  235. package/src/providers/openai-codex-transport.ts +18 -0
  236. package/src/providers/openai-completions.ts +294 -84
  237. package/src/providers/openai-responses.ts +3 -4
  238. package/src/providers/openai-shared.ts +127 -28
  239. package/src/providers/pi-native-server.ts +4 -2
  240. package/src/providers/register-builtins.ts +118 -319
  241. package/src/providers/rerank-server.ts +166 -0
  242. package/src/providers/speech-server.ts +53 -0
  243. package/src/providers/synthetic.ts +1 -8
  244. package/src/providers/systemone-server.ts +73 -0
  245. package/src/providers/transcriptions-server.ts +243 -0
  246. package/src/providers/transform-messages.ts +36 -7
  247. package/src/providers/video-server.ts +286 -0
  248. package/src/registry/cloudflare-ai-gateway.ts +1 -1
  249. package/src/registry/engine/api-key.ts +8 -3
  250. package/src/registry/oauth/anthropic.ts +2 -3
  251. package/src/registry/oauth/oauth.html +206 -185
  252. package/src/registry/oauth/types.ts +1 -1
  253. package/src/registry/types.ts +1 -1
  254. package/src/rerank/index.ts +13 -0
  255. package/src/rerank/openrouter-rerank.ts +136 -0
  256. package/src/rerank/types.ts +20 -0
  257. package/src/speech/index.ts +35 -0
  258. package/src/speech/openai-speech.ts +26 -0
  259. package/src/speech/transport.ts +66 -0
  260. package/src/speech/types.ts +37 -0
  261. package/src/speech/xai-tts.ts +41 -0
  262. package/src/stream.ts +177 -329
  263. package/src/transcription/index.ts +17 -0
  264. package/src/transcription/openai-transcriptions.ts +133 -0
  265. package/src/transcription/types.ts +46 -0
  266. package/src/types.ts +127 -33
  267. package/src/usage/alibaba-token-plan.ts +21 -4
  268. package/src/usage/claude-api.ts +66 -0
  269. package/src/usage/claude-reset.ts +694 -0
  270. package/src/usage/claude.ts +108 -81
  271. package/src/usage/commandcode.ts +209 -0
  272. package/src/usage/cursor.ts +43 -1
  273. package/src/usage/devin.ts +8 -7
  274. package/src/usage/google-antigravity.ts +1 -0
  275. package/src/usage/kimi.ts +32 -1
  276. package/src/usage/openai-codex.ts +140 -5
  277. package/src/usage/opencode-go.ts +4 -0
  278. package/src/usage/registry.ts +77 -0
  279. package/src/usage/xai-oauth.ts +31 -1
  280. package/src/usage/zai.ts +21 -0
  281. package/src/usage.ts +80 -9
  282. package/src/utils/anthropic-auth.ts +3 -6
  283. package/src/utils/event-stream.ts +38 -2
  284. package/src/utils/http-inspector.ts +21 -2
  285. package/src/utils/openai-http.ts +10 -3
  286. package/src/utils/openrouter-headers.ts +3 -3
  287. package/src/utils/proxy.ts +3 -3
  288. package/src/utils/schema/CONSTRAINTS.md +30 -28
  289. package/src/utils/schema/foundation-models.ts +255 -0
  290. package/src/utils/schema/index.ts +1 -0
  291. package/src/utils/schema/json-schema-validator.ts +23 -10
  292. package/src/utils/schema/normalize.ts +1 -1
  293. package/src/utils/schema/wire.ts +3 -3
  294. package/src/utils/tool-call-loop-guard.ts +2 -2
  295. package/src/utils/validation.ts +145 -50
  296. package/src/video/index.ts +34 -0
  297. package/src/video/openrouter-video.ts +210 -0
  298. package/src/video/types.ts +72 -0
package/CHANGELOG.md CHANGED
@@ -2,18 +2,8 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
- ## [1.1.20] - 2026-09-23
5
+ ## [1.1.23] - 2026-10-01
6
6
 
7
- - 版本线推进;本版无独立用户可见变化。
7
+ ## [1.1.22] - 2026-09-30
8
8
 
9
- ## [1.1.19] - 2026-09-22
10
-
11
- - 版本线推进;本版无独立用户可见变化。
12
-
13
- ## [1.1.18] - 2026-09-22
14
-
15
- - 包元数据:author/maintainer 更新为 Linxira-OS,LICENSE 追加 Linxira-OS 版权行(发行面变更)。
16
-
17
- ## [1.1.16] - 2026-09-19
18
-
19
- - 上游 v18.2.5 同步:stencil.so OAuth 认证回调、流式 JSON 代理解析优化。
9
+ - 随 1.1.22 版本线发布;无面向用户的行为变化。
package/README.md CHANGED
@@ -1186,6 +1186,18 @@ const response = await complete(
1186
1186
  );
1187
1187
  ```
1188
1188
 
1189
+ When an auth-broker client requests recovery after a provider rejects an OAuth
1190
+ bearer, the broker may reuse a still-fresh token that it minted in the previous
1191
+ five minutes instead of rotating the refresh token again. The process-local
1192
+ cache is bound to the credential ID and access token. Scheduled expiry refreshes,
1193
+ direct forced refreshes such as MCP recovery, ordinary hard-auth blocks, and
1194
+ sibling rotation keep their existing behavior. Cached refresh responses rebind
1195
+ by durable credential ID so concurrent row removal cannot switch a pinned
1196
+ session to another account.
1197
+ Generic `forceRefresh: true` requests do not opt into reuse. Provider-401 retry
1198
+ paths pass `refreshReason: "auth-recovery"` explicitly; expiry sentinels and
1199
+ usage polling do not imply that reason.
1200
+
1189
1201
  ### Provider Notes
1190
1202
 
1191
1203
  **OpenAI Codex**: Requires a ChatGPT Plus or Pro subscription. Provides access to GPT-5.x Codex models with extended context windows and reasoning capabilities. The library automatically handles session-based prompt caching when `sessionId` is provided in stream options.
@@ -78,8 +78,8 @@ below.
78
78
  uutils coreutils (https://github.com/uutils/coreutils), MIT
79
79
  --------------------------------------------------------------------------------
80
80
  Covers: base32, base64, basename, cat, cksum (shared checksum machinery),
81
- b2sum, md5sum, sha1sum, sha224sum, sha256sum, sha384sum, sha512sum, comm, cut,
82
- date, dirname, head, hostname, ln, ls, mkdir, mktemp, mv, nproc, paste,
81
+ b2sum, md5sum, sha1sum, sha224sum, sha256sum, sha384sum, sha512sum, comm, cp,
82
+ cut, date, dirname, head, hostname, ln, ls, mkdir, mktemp, mv, nproc, paste,
83
83
  printenv, readlink, realpath, rm, seq, sort, stat, tac, tail, tee, touch, tr,
84
84
  truncate, uname, uniq, wc, whoami, yes.
85
85
 
@@ -293,7 +293,7 @@ MIT License
293
293
  Copyright (c) 2026 Sander Land
294
294
  (measured tokenizer vocabulary data, reconstruction model, and reference
295
295
  implementation: https://github.com/sanderland/ctok)
296
- Copyright (c) 2026 Can Bölük and the Oh My Pi contributors
296
+ Copyright (c) 2026 Can Bölük and the omp contributors
297
297
  Copyright (c) 2026 Stencil Labs, Inc.
298
298
  (Rust implementation and the compact binary vocabulary encoding in
299
299
  crates/pi-natives/src/utok/claude)
@@ -335,43 +335,6 @@ This license allows the work and adaptations of it to be shared and used
335
335
  commercially, as long as it is attributed to Poppy Works. The font is bundled
336
336
  here (crates/pi-natives/src/fonts/Silver.ttf) as a CJK/Unicode bitmap fallback.
337
337
 
338
- -------------------------------------------------------------------------------
339
- packages/utils/src/vendor/mermaid-ascii/NOTICE
340
-
341
- This directory contains an in-house Mermaid-diagram-to-ASCII renderer adapted
342
- from beautiful-mermaid (https://github.com/lukilabs/beautiful-mermaid), used
343
- under the MIT License.
344
-
345
- Copyright (c) 2026 Craft Docs
346
-
347
- Only the ASCII rendering pipeline is ported (flowchart/state, sequence, class,
348
- ER, and xychart diagrams); the SVG renderer and its `elkjs` graph-layout
349
- dependency, the browser entry point, and the SVG theme/style modules were
350
- dropped. Terminal display width is reimplemented on `Bun.stringWidth`, and
351
- inline label formatting (HTML tags, markdown emphasis) is reduced to plain text
352
- for ASCII output. Layout and edge-routing logic is preserved faithfully so
353
- ASCII output matches the upstream package.
354
-
355
- MIT License
356
-
357
- Permission is hereby granted, free of charge, to any person obtaining a copy
358
- of this software and associated documentation files (the "Software"), to deal
359
- in the Software without restriction, including without limitation the rights
360
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
361
- copies of the Software, and to permit persons to whom the Software is
362
- furnished to do so, subject to the following conditions:
363
-
364
- The above copyright notice and this permission notice shall be included in all
365
- copies or substantial portions of the Software.
366
-
367
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
368
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
369
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
370
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
371
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
372
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
373
- SOFTWARE.
374
-
375
338
  -------------------------------------------------------------------------------
376
339
  packages/coding-agent/src/markit/NOTICE
377
340
 
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Race `promise` against `signal`, rejecting only this caller when the signal
3
+ * fires. The underlying promise keeps running so other awaiters on the same
4
+ * single-flight operation aren't punished by a peer's cancel.
5
+ */
6
+ export declare function raceSignal<T>(promise: Promise<T>, signal: AbortSignal | undefined, message: string): Promise<T>;
@@ -0,0 +1,68 @@
1
+ import type { AuthCredential, OAuthCredential, SessionsApi } from "./types.js";
2
+ import type { AuthCredentialStore } from "./store.js";
3
+ import type { CredentialPool } from "./pool.js";
4
+ import type { KeyOverrides } from "./cascade.js";
5
+ /** Prefix for persisted session-to-credential affinity. */
6
+ export declare const SESSION_STICKY_CACHE_PREFIX = "session:sticky:";
7
+ /** A session's pinned credential (resolved index + durable row id). */
8
+ export type SessionCredential = {
9
+ type: AuthCredential["type"];
10
+ index: number;
11
+ credentialId?: number;
12
+ lastUsedAtMs?: number;
13
+ /** Set only by the public user-facing pin API; automatic warm affinity leaves it absent. */
14
+ explicit?: true;
15
+ };
16
+ /** Session → credential affinity (pins), persisted in the store cache. */
17
+ export declare class SessionAffinity implements SessionsApi {
18
+ #private;
19
+ constructor(store: AuthCredentialStore, pool: CredentialPool, overrides: KeyOverrides);
20
+ /** Drop every pin for a provider, both in memory and in the persisted cache. */
21
+ clearProvider(provider: string): void;
22
+ /** Drop only this in-memory session pin after OAuth selection falls through. */
23
+ forget(provider: string, sessionId: string): void;
24
+ /**
25
+ * Records which credential was used for a session (for rate-limit switching).
26
+ * `lastUsedAtMs` backdates the sticky (session-file pin restores on resume);
27
+ * it defaults to now for live selections. Automatic re-recording of the same
28
+ * durable row preserves an explicit user pin.
29
+ */
30
+ record(provider: string, sessionId: string | undefined, type: AuthCredential["type"], index: number, lastUsedAtMs?: number, explicit?: boolean): void;
31
+ /** Retrieves the last credential used by a session. */
32
+ get(provider: string, sessionId: string | undefined): SessionCredential | undefined;
33
+ /** Clears the last credential used by a session for a provider. */
34
+ clear(provider: string, sessionId: string | undefined): void;
35
+ activeOAuth(provider: string, sessionId?: string): OAuthCredential | undefined;
36
+ /**
37
+ * Pin one stored OAuth account as this session's preferred credential.
38
+ *
39
+ * The durable credential id keeps the pin stable across credential refreshes,
40
+ * storage reordering, and process restarts. By default this is an explicit
41
+ * user pin: ranking and account reserve never evict it; hard unavailability
42
+ * and auth retry may still route around it.
43
+ *
44
+ * `options.restoredAtMs` instead restores an automatic affinity recorded by a
45
+ * persisted session, backdated to its last use, so it keeps the provider's
46
+ * warm-window semantics: a resume inside the prompt-cache TTL reuses the
47
+ * account, a stale resume re-ranks.
48
+ */
49
+ pin(provider: string, sessionId: string, credentialId: number, options?: {
50
+ restoredAtMs?: number;
51
+ }): boolean;
52
+ /**
53
+ * Copy every stored credential affinity from one live session to another.
54
+ *
55
+ * The target receives its own sticky entries, so request resolution, usage
56
+ * blocking, credential rotation, metadata, and persisted pins all continue
57
+ * through the target session id without retaining a live dependency on the
58
+ * source session.
59
+ */
60
+ inherit(sourceSessionId: string, targetSessionId: string): number;
61
+ /**
62
+ * Release a session's sticky credential so its next `KeyCascade.get` call
63
+ * re-runs native pool ranking. This never blocks or penalizes the released
64
+ * account; usage-aware routing uses it when another sibling has more
65
+ * headroom, before considering a model/provider fallback.
66
+ */
67
+ release(provider: string, sessionId: string): boolean;
68
+ }
@@ -0,0 +1,106 @@
1
+ import type { Provider } from "../types.js";
2
+ import type { CredentialRankingContext, CredentialRankingStrategy, UsageReport } from "../usage.js";
3
+ import type { RankingStrategyResolver } from "../usage/registry.js";
4
+ import type { CredentialPool } from "./pool.js";
5
+ import type { AuthCredentialStore } from "./store.js";
6
+ import type { UsageCache, UsageRequestDescriptor } from "./usage-cache.js";
7
+ import type { AuthCredential, BlocksApi, StoredCredentialBlock } from "./types.js";
8
+ /** Default block when no provider reset time is known; used by selectors and rate limits. */
9
+ export declare const DEFAULT_BLOCK_MS = 60000;
10
+ /** Composite key for round-robin tracking: "<provider>:oauth" or "<provider>:api_key". */
11
+ export declare function providerTypeKey(provider: string, type: AuthCredential["type"]): string;
12
+ /** Scoped backoff map key used by the credential block store. */
13
+ export declare function scopedBackoffKey(providerKey: string, blockScope: string | undefined): string;
14
+ /** Authentication backoffs apply to every model and cannot be healed by quota evidence. */
15
+ export declare const AUTH_BLOCK_SCOPE = "auth";
16
+ /** Account-policy backoffs apply to every model and survive quota resets. */
17
+ export declare const ACCOUNT_POLICY_BLOCK_SCOPE = "account-policy";
18
+ /** Scope key for one model-specific account-policy block, shared by selectors and rate limits. */
19
+ export declare function modelAccountPolicyBlockScope(provider: string, modelId: string | undefined): string | undefined;
20
+ /** Scope keys that a request must check, including model-policy constraints. */
21
+ export declare function credentialBlockScopesForRequest(provider: string, strategy: CredentialRankingStrategy | undefined, rankingContext: CredentialRankingContext, blockScope: string | undefined): readonly string[];
22
+ /** Latch for unrecoverably corrupt persisted block stores, shared with the credential pool. */
23
+ export declare class BlockStoreHealth {
24
+ #private;
25
+ constructor(sourceLabel: string | undefined);
26
+ get damaged(): boolean;
27
+ handle(err: unknown): boolean;
28
+ assertWritable(): void;
29
+ }
30
+ /** Dependencies for persisted rate-limit blocks and usage-report healing. */
31
+ export interface CredentialBlocksDeps {
32
+ store: AuthCredentialStore;
33
+ pool: CredentialPool;
34
+ health: BlockStoreHealth;
35
+ usageCache: UsageCache;
36
+ strategies: RankingStrategyResolver;
37
+ }
38
+ /** Temporary rate-limit blocks: id-keyed in memory, mirrored to the store, healed by live usage. */
39
+ export declare class CredentialBlocks implements BlocksApi {
40
+ #private;
41
+ constructor(deps: CredentialBlocksDeps);
42
+ /** Returns block expiry timestamp for a credential, checking unscoped and scoped blocks. */
43
+ blockedUntil(provider: string, providerKey: string, credentialIndex: number, blockScopeOrScopes?: string | readonly string[] | undefined): number | undefined;
44
+ /** Checks if a credential is temporarily blocked due to usage limits. */
45
+ isBlocked(provider: string, providerKey: string, credentialIndex: number, blockScope?: string | readonly string[] | undefined): boolean;
46
+ /**
47
+ * Whether the in-memory block currently sitting at exactly `deadline` for
48
+ * this credential was written with provider-stated timing. Mirrors the
49
+ * scope enumeration of {@link CredentialBlocks.blockedUntil}.
50
+ * A deadline with no matching in-memory entry came from the persisted
51
+ * store, which carries no provenance — a stale persisted heuristic guess
52
+ * (pre-restart hintless response) must not outrank a fresh complete usage
53
+ * report, so persisted-only deadlines count as untimed. Persisted
54
+ * deadlines longer than this call's own request still win through the
55
+ * merged `blockedUntilMs` comparison, which needs no provenance.
56
+ */
57
+ isTimed(providerKey: string, blockScopeOrScopes: string | readonly string[] | undefined, credentialId: number, deadline: number): boolean;
58
+ /**
59
+ * Marks a credential as blocked until the specified time. `providerTimed`
60
+ * records whether the requested deadline comes from provider-stated
61
+ * timing (a parsed retry hint or a usage-report reset) rather than a
62
+ * heuristic/default guess; the stored block keeps the provenance of
63
+ * whichever deadline wins the longest-wins merge.
64
+ */
65
+ mark(provider: string, providerKey: string, credentialIndex: number, blockedUntilMs: number, blockScope?: string | undefined, providerTimed?: boolean): void;
66
+ /**
67
+ * Lift any temporary backoff blocks on one credential (across the bare
68
+ * `provider:oauth` key and its scoped `\0`-suffixed derivatives). Called
69
+ * after a saved reset is redeemed so the just-reset account is immediately
70
+ * selectable again instead of being skipped/under-ranked by a stale block
71
+ * that `markUsageLimitReached` set for the now-obsolete reset time.
72
+ */
73
+ clearAll(provider: string, credentialId: number): void;
74
+ /** Clear exactly one quota scope, preserving unrelated account and model blocks. */
75
+ clearScope(provider: string, credentialId: number, providerKey: string, blockScope: string | undefined): boolean;
76
+ /** Providers whose stale usage-limit blocks a healthy live report may clear. */
77
+ supportsHealing(provider: Provider): boolean;
78
+ /**
79
+ * Whether a fresh report could lift what currently blocks this credential.
80
+ *
81
+ * Claude reports can heal legacy account-wide quota blocks too. Explicit
82
+ * auth/account-policy blocks never justify a usage probe.
83
+ */
84
+ canHeal(provider: Provider, providerKey: string, credentialIndex: number, blockScopeOrScopes: string | readonly string[] | undefined): boolean;
85
+ /**
86
+ * Self-heal stale usage-limit blocks: when a fresh live usage report says a
87
+ * scope is below every limit gating it, drop its persisted and in-memory
88
+ * blocks so credential selection re-includes the recovered account before
89
+ * the block expires by clock. Providers declare their scopes and any meter
90
+ * verdicts via {@link CredentialRankingStrategy.healableBlockScopes}.
91
+ */
92
+ reconcile(provider: Provider, credentialId: number, report: UsageReport): void;
93
+ reconcileRequest(request: UsageRequestDescriptor, report: UsageReport): void;
94
+ reconcileReports(reports: UsageReport[]): void;
95
+ /**
96
+ * Broker-server seam: list non-expired persisted blocks for snapshot entries.
97
+ */
98
+ list(credentialIds: readonly number[]): StoredCredentialBlock[];
99
+ /**
100
+ * Broker-server seam: persist one credential block and notify snapshot waiters.
101
+ */
102
+ upsert(block: StoredCredentialBlock): void;
103
+ /** Broker-server seam: clear exactly one persisted and local block and notify snapshot waiters. */
104
+ delete(credentialId: number, providerKey: string, blockScope: string, invalidateUsage?: boolean): void;
105
+ deleteAll(credentialId: number): void;
106
+ }
@@ -0,0 +1,147 @@
1
+ import { type ApiKeyResolver, type ResolvedApiKey } from "../auth-retry.js";
2
+ import type { SessionAffinity } from "./affinity.js";
3
+ import type { CredentialPool } from "./pool.js";
4
+ import type { CredentialSelector } from "./select.js";
5
+ import type { AuthApiKeyOptions, AuthCredential, AuthSource, AuthSourceOptions, KeysApi, LimitsApi } from "./types.js";
6
+ /** Runtime (--api-key) and config (models.yml) key overrides plus the config-value resolver. */
7
+ export declare class KeyOverrides {
8
+ #private;
9
+ constructor(resolver?: (config: string) => Promise<string | undefined>);
10
+ has(provider: string): boolean;
11
+ runtimeKey(provider: string): string | undefined;
12
+ configKey(provider: string): string | undefined;
13
+ /** Resolve a config value (env var name, "!command", literal) to the secret. */
14
+ resolve(config: string): Promise<string | undefined>;
15
+ /**
16
+ * Set a runtime API key override (not persisted to disk).
17
+ * Used for CLI --api-key flag.
18
+ */
19
+ setRuntime(provider: string, apiKey: string): void;
20
+ /**
21
+ * Remove a runtime API key override.
22
+ */
23
+ removeRuntime(provider: string): void;
24
+ /**
25
+ * Register a per-provider API key sourced from user configuration
26
+ * (e.g. `models.yml` `providers.<name>.apiKey`). Higher priority than
27
+ * stored credentials and OAuth tokens — when the user pins a key in
28
+ * config, that key is what authenticates outbound requests, regardless
29
+ * of whatever the broker happens to have loaded for that provider.
30
+ *
31
+ * Lower priority than {@link KeyOverrides.setRuntime} so a CLI `--api-key`
32
+ * still wins for the duration of a single invocation.
33
+ */
34
+ setConfig(provider: string, apiKeyConfig: string): void;
35
+ /**
36
+ * Remove a single config-sourced API key override.
37
+ */
38
+ removeConfig(provider: string): void;
39
+ /**
40
+ * Drop every config-sourced API key. Called by `ModelRegistry` before
41
+ * re-parsing `models.yml` so removed entries actually disappear.
42
+ */
43
+ clearConfig(): void;
44
+ /**
45
+ * Install the host's async config-value resolver. Coding-agent uses this so
46
+ * every stored/config credential reference shares command caching,
47
+ * failure backoff, and process hardening even when AuthStorage was created
48
+ * independently and later attached to a registry.
49
+ */
50
+ setResolver(resolver: (config: string) => Promise<string | undefined>): void;
51
+ }
52
+ /** Dependencies of the provider key precedence cascade. */
53
+ export interface KeyCascadeDeps {
54
+ pool: CredentialPool;
55
+ overrides: KeyOverrides;
56
+ selector: CredentialSelector;
57
+ affinity: SessionAffinity;
58
+ /** LimitsApi.rotate, injected to avoid a cascade↔rotation import cycle. */
59
+ rotate: LimitsApi["rotate"];
60
+ sourceLabel?: string;
61
+ }
62
+ /** The provider auth precedence cascade (runtime → config → OAuth → login key → env → stored key). */
63
+ export declare class KeyCascade implements KeysApi {
64
+ #private;
65
+ constructor(deps: KeyCascadeDeps);
66
+ /**
67
+ * True when a stored credential is the provider's KDL `empty-fallback`
68
+ * keyless-mode marker — what an empty paste at an "Optional: paste API key"
69
+ * login prompt stores (e.g. `lm-studio-local` for lm-studio). The wire layer
70
+ * never sends these as a bearer (`isDiscoveryBearerApiKey` strips them), so
71
+ * auth-status surfaces must not count them either; otherwise the model hub
72
+ * and `/login` report the provider as authenticated while every request
73
+ * goes out bare (issue #12281). The credential itself stays stored: `/logout`
74
+ * can still remove it, and availability treats the provider as keyless.
75
+ */
76
+ isKeylessFallback(provider: string, credential: AuthCredential): boolean;
77
+ /**
78
+ * True when the provider has stored credentials but none of them carries
79
+ * auth — i.e. its only credential is the KDL `empty-fallback` keyless-mode
80
+ * marker (an empty paste at an optional-key login prompt). Such a provider
81
+ * is configured-but-keyless: model availability treats it like an
82
+ * `auth: none` endpoint instead of locking it out (issue #12281).
83
+ */
84
+ keyless(provider: string): boolean;
85
+ /**
86
+ * Classify where a provider's auth comes from, following the same precedence
87
+ * as {@link KeyCascade.get}: runtime override → config override →
88
+ * stored OAuth → login-stored api_key → env var → stored api_key.
89
+ * Returns undefined when no auth is configured.
90
+ *
91
+ * Compact, structured counterpart to {@link KeyCascade.describe}; `env`
92
+ * selects dedicated-only, alias-aware, or no environment fallback.
93
+ */
94
+ source(provider: string, { env }?: AuthSourceOptions): AuthSource | undefined;
95
+ /**
96
+ * Peek at API key for a provider without refreshing OAuth tokens.
97
+ * Used for model discovery where we only need to know if credentials exist
98
+ * and get a best-effort token. GitHub Copilot's peek must preserve
99
+ * enterprise routing metadata because discovery needs a structured
100
+ * credential to reach the correct host.
101
+ */
102
+ peek(provider: string): Promise<string | undefined>;
103
+ /** Resolve a bearer together with the stored row that supplied it. */
104
+ getWithCredential(provider: string, sessionId?: string, options?: AuthApiKeyOptions): Promise<ResolvedApiKey | undefined>;
105
+ /**
106
+ * Get API key for a provider.
107
+ * Priority (first match wins): runtime override, config override, OAuth,
108
+ * login API key, environment variable, then another stored API key.
109
+ */
110
+ get(provider: string, sessionId?: string, options?: AuthApiKeyOptions, onCredentialId?: (id: number) => void): Promise<string | undefined>;
111
+ /**
112
+ * Build an {@link ApiKeyResolver} backed by this storage, implementing the
113
+ * central a/b/c auth-retry policy:
114
+ *
115
+ * - initial (`error: undefined`) → resolve the session credential.
116
+ * - step (b) `!lastChance` → force-refresh the SAME session-sticky credential.
117
+ * - step (c) `lastChance` → rotate to a sibling and re-resolve, unless quota exhaustion has no sibling.
118
+ *
119
+ * Used by web-search providers and other consumers that hold a KeyCascade
120
+ * directly (no ModelRegistry in scope).
121
+ */
122
+ resolver(provider: string, options?: {
123
+ sessionId?: string;
124
+ baseUrl?: string;
125
+ modelId?: string;
126
+ }): ApiKeyResolver;
127
+ /**
128
+ * Describe where the active credential for a provider came from.
129
+ *
130
+ * Mirrors {@link KeyCascade.get} precedence, highest first:
131
+ * 1. Runtime override (`--api-key`).
132
+ * 2. Config override (`models.yml` `providers.<name>.apiKey`).
133
+ * 3. Stored OAuth credential.
134
+ * 4. API key persisted by a successful `/login`.
135
+ * 5. Env var — overrides a stored static api_key (e.g. a stale broker copy).
136
+ * 6. Stored api_key credential.
137
+ *
138
+ * The string is purely informational; consumers must not parse it.
139
+ */
140
+ describe(provider: string, sessionId?: string): string | undefined;
141
+ setRuntime(provider: string, apiKey: string): void;
142
+ removeRuntime(provider: string): void;
143
+ setConfig(provider: string, apiKeyConfig: string): void;
144
+ removeConfig(provider: string): void;
145
+ clearConfig(): void;
146
+ setResolver(resolver: (config: string) => Promise<string | undefined>): void;
147
+ }
@@ -0,0 +1,66 @@
1
+ import type { Provider } from "../types.js";
2
+ import type { RankingStrategyResolver } from "../usage/registry.js";
3
+ import type { SessionAffinity } from "./affinity.js";
4
+ import type { CredentialBlocks } from "./blocks.js";
5
+ import type { KeyCascade, KeyOverrides } from "./cascade.js";
6
+ import type { AccountPolicies } from "./policy.js";
7
+ import type { CredentialPool } from "./pool.js";
8
+ import type { OAuthRefresher } from "./refresh.js";
9
+ import type { AuthCredentialStore } from "./store.js";
10
+ import type { CheckCredentialsOptions, CredentialHealthResult, HealthApi, ModelUsageHealth, ModelUsageHealthOptions } from "./types.js";
11
+ import type { UsageService } from "./usage.js";
12
+ /** Dependencies for model pool health and stored credential probes. */
13
+ export interface CredentialHealthDeps {
14
+ store: AuthCredentialStore;
15
+ pool: CredentialPool;
16
+ keys: KeyCascade;
17
+ policies: AccountPolicies;
18
+ blocks: CredentialBlocks;
19
+ affinity: SessionAffinity;
20
+ usage: UsageService;
21
+ refresher: OAuthRefresher;
22
+ overrides: KeyOverrides;
23
+ strategies: RankingStrategyResolver;
24
+ }
25
+ /** Model-level pool health and per-credential auth probes. */
26
+ export declare class CredentialHealth implements HealthApi {
27
+ #private;
28
+ constructor(deps: CredentialHealthDeps);
29
+ /**
30
+ * Inspect the credential pool that {@link getApiKey} would use for one model
31
+ * without advancing round-robin state or changing session stickiness.
32
+ *
33
+ * Pool aggregation is deliberately conservative: one healthy sibling makes
34
+ * the model healthy, while any unknown sibling prevents a depleted/reserve
35
+ * conclusion. Static runtime/config/env credentials return unknown because
36
+ * they bypass the managed account pool.
37
+ */
38
+ model(provider: Provider, options: ModelUsageHealthOptions): Promise<ModelUsageHealth>;
39
+ /**
40
+ * Probe each stored credential against its provider's auth-verifying usage
41
+ * endpoint and report per-credential auth health.
42
+ *
43
+ * Surfaces the identity of failing credentials so callers running a
44
+ * multi-account pool (e.g. a broker-backed auth-gateway) can tell which
45
+ * row is producing 401s. The probe mirrors the per-credential fan-out
46
+ * inside {@link UsageService.reports} (OAuth refresh-on-expiry,
47
+ * then `UsageProvider.fetchUsage`) but does NOT swallow errors — every
48
+ * credential gets either `ok: true`, `ok: false` with `reason`, or
49
+ * `ok: null` when no probe is configured for the provider.
50
+ *
51
+ * Iterates sequentially to avoid synchronized N-account fan-out that
52
+ * upstream `/usage` rate limiters (per source IP) treat as a burst.
53
+ *
54
+ * Only inspects active rows from {@link AuthCredentialStore.listAuthCredentials};
55
+ * soft-disabled rows are already known-bad and don't need a network probe.
56
+ * Environment-variable API keys are not enumerated — the caller's intent
57
+ * here is "which of my stored credentials is broken".
58
+ *
59
+ * Pass {@link CheckCredentialsOptions.completionProbe} to additionally
60
+ * exercise each credential against the provider's chat-completion endpoint
61
+ * (strict mode). The result lands on
62
+ * {@link CredentialHealthResult.completion}; the usage `ok` field is
63
+ * unchanged so callers can tell the two signals apart.
64
+ */
65
+ check(options?: CheckCredentialsOptions): Promise<CredentialHealthResult[]>;
66
+ }
@@ -0,0 +1,93 @@
1
+ import type { OAuthProviderId } from "../registry/oauth/types.js";
2
+ import type { SessionAffinity } from "./affinity.js";
3
+ import type { KeyOverrides } from "./cascade.js";
4
+ import type { AccountPolicies } from "./policy.js";
5
+ import type { CredentialPool } from "./pool.js";
6
+ import type { OAuthRefresher } from "./refresh.js";
7
+ import type { CredentialSelector } from "./select.js";
8
+ import type { AuthAccountPolicy, AuthApiKeyOptions, AuthCredentialSnapshotEntry, OAuthAccess, OAuthAccessResolution, OAuthAccountIdentity, OAuthAccountSummary, OAuthApi, OAuthCredential, OAuthLoginController, OAuthLoginIdentity, OAuthRefreshByIdOptions, StoredOAuthRefreshOptions, StoredOAuthRefreshResult } from "./types.js";
9
+ /** Dependencies used by the OAuth account operations. */
10
+ export interface OAuthAccountsDeps {
11
+ pool: CredentialPool;
12
+ overrides: KeyOverrides;
13
+ policies: AccountPolicies;
14
+ selector: CredentialSelector;
15
+ affinity: SessionAffinity;
16
+ refresher: OAuthRefresher;
17
+ }
18
+ /** OAuth login, per-account access resolution, and account listings. */
19
+ export declare class OAuthAccounts implements OAuthApi {
20
+ #private;
21
+ constructor(deps: OAuthAccountsDeps);
22
+ /**
23
+ * Login to an OAuth provider. Resolves with the stored credential's
24
+ * identity slice (or `undefined` when nothing was stored) so callers can
25
+ * surface which account — and for Anthropic, which organization — the
26
+ * login registered.
27
+ */
28
+ login(provider: OAuthProviderId, ctrl: OAuthLoginController): Promise<OAuthLoginIdentity | undefined>;
29
+ /**
30
+ * Resolve the OAuth credential for `provider`, refreshing through the same
31
+ * pipeline as API-key resolution but returning the refreshed
32
+ * {@link OAuthAccess} (raw access token + identity metadata) instead of
33
+ * the API-key bytes.
34
+ *
35
+ * Use this when the caller needs to inject identity headers alongside the
36
+ * bearer (Codex `chatgpt-account-id`, Google `project`, GitHub
37
+ * `enterpriseUrl`). For pure "give me the bytes for `Authorization`"
38
+ * scenarios, prefer API-key resolution.
39
+ *
40
+ * Returns `undefined` when no OAuth credential is available, the
41
+ * credential fails to refresh, or runtime/config overrides have replaced
42
+ * OAuth with an explicit API key.
43
+ */
44
+ access(provider: string, sessionId?: string, options?: AuthApiKeyOptions): Promise<OAuthAccess | undefined>;
45
+ /**
46
+ * Read-only list of stored OAuth accounts for `provider` in stable storage
47
+ * order, WITHOUT refreshing any token. The array position (0-based) is the
48
+ * selector displayed by a "pick the Nth account" UI as `position + 1`.
49
+ *
50
+ * When `sessionId` is supplied, the session-sticky OAuth credential is marked
51
+ * `active`. No account is active before that session has resolved or pinned a
52
+ * credential.
53
+ */
54
+ accounts(provider: string, sessionId?: string): OAuthAccountSummary[];
55
+ /**
56
+ * Resolve every stored OAuth credential for `provider` independently.
57
+ *
58
+ * Refreshes credentials through the same broker/local path as
59
+ * {@link OAuthAccounts.access}, but does not rank, round-robin, or
60
+ * stop after the first usable account. Intended for diagnostics that must
61
+ * exercise each stored account exactly once.
62
+ */
63
+ accessAll(provider: string, options?: AuthApiKeyOptions): Promise<OAuthAccessResolution[]>;
64
+ /**
65
+ * Resolve one stored OAuth credential by its durable storage row id.
66
+ *
67
+ * Unlike the normal session resolver, this method never ranks, rotates, or
68
+ * falls back to sibling credentials. A forced refresh re-mints only the
69
+ * requested row, preserving exact-account affinity for operations whose
70
+ * provenance and policy boundary are tied to one workspace.
71
+ *
72
+ * Returns `undefined` when the row does not exist for `provider` or an
73
+ * explicit runtime/config API-key override suppresses OAuth.
74
+ */
75
+ accessById(provider: string, credentialId: number, options?: AuthApiKeyOptions): Promise<OAuthAccessResolution | undefined>;
76
+ /**
77
+ * Get the OAuth account identity for a provider, preferring the credential that
78
+ * is session-sticky for `sessionId`. This is a read-only lookup for display and
79
+ * metadata paths; it does not refresh tokens, rank usage, or advance selection.
80
+ */
81
+ identity(provider: string, sessionId?: string): OAuthAccountIdentity | undefined;
82
+ /**
83
+ * Return the configured account policy matching an OAuth identity.
84
+ *
85
+ * This is a read-only diagnostics surface: it performs the same conjunctive
86
+ * selector match as routing and never refreshes, ranks, or mutates credentials.
87
+ */
88
+ policy(provider: string, identity: OAuthAccountIdentity): AuthAccountPolicy | undefined;
89
+ /** Force-refresh one stored credential by its durable row id. */
90
+ refresh(id: number, signal?: AbortSignal, options?: OAuthRefreshByIdOptions): Promise<AuthCredentialSnapshotEntry>;
91
+ /** Refresh one stored OAuth credential through the durable ownership path. */
92
+ refreshStored<T extends OAuthCredential = OAuthCredential>(provider: string, options: StoredOAuthRefreshOptions<T>): Promise<StoredOAuthRefreshResult<T>>;
93
+ }
@@ -0,0 +1,27 @@
1
+ import type { AuthAccountPolicies, AuthAccountPolicy, AuthAccountSelector, AuthCredential, OAuthAccountIdentity } from "./types.js";
2
+ /** Whether every identity field set on `selector` matches `identity`. */
3
+ export declare function matchesAuthAccountSelector(selector: AuthAccountSelector, identity: OAuthAccountIdentity): boolean;
4
+ /** Validated per-account routing policies (priority/reserve) plus the global reserve fallback. */
5
+ export declare class AccountPolicies {
6
+ #private;
7
+ constructor(policies: AuthAccountPolicies, defaultReservePct: number | undefined);
8
+ /** Global usage reserve (0–100) for accounts without a per-account `reservePct`. */
9
+ get defaultReservePct(): number;
10
+ /**
11
+ * Replace the policy set and global reserve in place (live settings change).
12
+ * Validates the configuration and every provider in `storedCredentials` before
13
+ * committing; on error the previous policies stay active.
14
+ */
15
+ replace(policies: AuthAccountPolicies, defaultReservePct: number | undefined, storedCredentials?: ReadonlyMap<string, readonly AuthCredential[]>): void;
16
+ validateUsageCapability(provider: string, canFetchUsage: boolean): void;
17
+ validateFor(provider: string, credentials: readonly AuthCredential[]): void;
18
+ /**
19
+ * Return the configured account policy matching an OAuth identity.
20
+ *
21
+ * This is a read-only diagnostics surface: it performs the same conjunctive
22
+ * selector match as routing and never refreshes, ranks, or mutates credentials.
23
+ */
24
+ find(provider: string, identity: OAuthAccountIdentity): AuthAccountPolicy | undefined;
25
+ /** Return the configured policy for a stored OAuth credential. */
26
+ forCredential(provider: string, credential: AuthCredential): AuthAccountPolicy | undefined;
27
+ }