@linxiraos/pi-ai 1.1.8 → 1.1.9

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 (261) hide show
  1. package/CHANGELOG.md +2 -20
  2. package/README.md +66 -66
  3. package/package.json +131 -136
  4. package/src/auth-storage.ts +11 -10
  5. package/src/error/rate-limit.ts +9 -1
  6. package/src/providers/amazon-bedrock.ts +72 -5
  7. package/src/providers/anthropic.ts +94 -21
  8. package/src/providers/cursor.ts +16 -19
  9. package/src/providers/google.ts +6 -0
  10. package/src/providers/inference-headers.ts +80 -0
  11. package/src/providers/openai-codex/request-transformer.ts +9 -15
  12. package/src/providers/openai-codex-responses.ts +57 -13
  13. package/src/providers/openai-completions.ts +3 -0
  14. package/src/providers/openai-configuration-update.ts +170 -0
  15. package/src/providers/openai-responses-wire.ts +15 -0
  16. package/src/providers/openai-responses.ts +42 -1
  17. package/src/providers/openai-shared.ts +30 -19
  18. package/src/providers/pi-native-server.ts +1 -0
  19. package/src/providers/transform-messages.ts +10 -6
  20. package/src/registry/engine/oauth-code.ts +3 -1
  21. package/src/registry/oauth/callback-server.ts +152 -24
  22. package/src/registry/oauth/native-scheme-callback.ts +62 -0
  23. package/src/registry/oauth/types.ts +2 -1
  24. package/src/stream.ts +52 -29
  25. package/src/types.ts +7 -0
  26. package/src/usage/google-antigravity.ts +236 -42
  27. package/src/utils/proxy.ts +37 -31
  28. package/src/utils/request-debug.ts +6 -29
  29. package/src/utils/transport-fetch.ts +50 -0
  30. package/src/utils.ts +21 -24
  31. package/THIRD-PARTY-NOTICES.txt +0 -22909
  32. package/dist/types/api-registry.d.ts +0 -30
  33. package/dist/types/auth/sqlite-credential-store.d.ts +0 -102
  34. package/dist/types/auth-broker/client.d.ts +0 -100
  35. package/dist/types/auth-broker/discover.d.ts +0 -39
  36. package/dist/types/auth-broker/index.d.ts +0 -7
  37. package/dist/types/auth-broker/refresher.d.ts +0 -25
  38. package/dist/types/auth-broker/remote-store.d.ts +0 -147
  39. package/dist/types/auth-broker/server.d.ts +0 -48
  40. package/dist/types/auth-broker/snapshot-cache.d.ts +0 -17
  41. package/dist/types/auth-broker/types.d.ts +0 -152
  42. package/dist/types/auth-broker/wire-schema-resource.d.ts +0 -53
  43. package/dist/types/auth-broker/wire-schemas.d.ts +0 -69
  44. package/dist/types/auth-gateway/http.d.ts +0 -70
  45. package/dist/types/auth-gateway/index.d.ts +0 -3
  46. package/dist/types/auth-gateway/server.d.ts +0 -36
  47. package/dist/types/auth-gateway/types.d.ts +0 -129
  48. package/dist/types/auth-retry.d.ts +0 -155
  49. package/dist/types/auth-storage.d.ts +0 -1286
  50. package/dist/types/dialect/anthropic.d.ts +0 -15
  51. package/dist/types/dialect/catalog.d.ts +0 -3
  52. package/dist/types/dialect/coercion.d.ts +0 -23
  53. package/dist/types/dialect/deepseek.d.ts +0 -14
  54. package/dist/types/dialect/demotion.d.ts +0 -30
  55. package/dist/types/dialect/examples.d.ts +0 -18
  56. package/dist/types/dialect/factory.d.ts +0 -3
  57. package/dist/types/dialect/fenced-thinking.d.ts +0 -53
  58. package/dist/types/dialect/gemini.d.ts +0 -17
  59. package/dist/types/dialect/gemma.d.ts +0 -15
  60. package/dist/types/dialect/glm.d.ts +0 -9
  61. package/dist/types/dialect/harmony.d.ts +0 -8
  62. package/dist/types/dialect/hermes.d.ts +0 -9
  63. package/dist/types/dialect/history.d.ts +0 -3
  64. package/dist/types/dialect/index.d.ts +0 -11
  65. package/dist/types/dialect/inventory.d.ts +0 -9
  66. package/dist/types/dialect/kimi.d.ts +0 -14
  67. package/dist/types/dialect/minimax.d.ts +0 -3
  68. package/dist/types/dialect/owned-stream.d.ts +0 -4
  69. package/dist/types/dialect/qwen-xml.d.ts +0 -6
  70. package/dist/types/dialect/qwen3.d.ts +0 -9
  71. package/dist/types/dialect/rendering.d.ts +0 -54
  72. package/dist/types/dialect/thinking-fence-strip.d.ts +0 -39
  73. package/dist/types/dialect/thinking.d.ts +0 -15
  74. package/dist/types/dialect/types.d.ts +0 -78
  75. package/dist/types/dialect/xml.d.ts +0 -9
  76. package/dist/types/error/abort.d.ts +0 -14
  77. package/dist/types/error/auth-classify.d.ts +0 -20
  78. package/dist/types/error/auth.d.ts +0 -27
  79. package/dist/types/error/aws.d.ts +0 -31
  80. package/dist/types/error/classes.d.ts +0 -106
  81. package/dist/types/error/finalize.d.ts +0 -41
  82. package/dist/types/error/flags.d.ts +0 -122
  83. package/dist/types/error/format.d.ts +0 -20
  84. package/dist/types/error/gateway.d.ts +0 -20
  85. package/dist/types/error/index.d.ts +0 -14
  86. package/dist/types/error/oauth.d.ts +0 -44
  87. package/dist/types/error/provider.d.ts +0 -44
  88. package/dist/types/error/rate-limit.d.ts +0 -85
  89. package/dist/types/error/retryable.d.ts +0 -20
  90. package/dist/types/error/validation.d.ts +0 -32
  91. package/dist/types/index.d.ts +0 -52
  92. package/dist/types/oneshot-retry.d.ts +0 -89
  93. package/dist/types/provider-details.d.ts +0 -24
  94. package/dist/types/providers/amazon-bedrock.d.ts +0 -51
  95. package/dist/types/providers/anthropic-client.d.ts +0 -106
  96. package/dist/types/providers/anthropic-messages-server-schema.d.ts +0 -1061
  97. package/dist/types/providers/anthropic-messages-server.d.ts +0 -17
  98. package/dist/types/providers/anthropic-wire.d.ts +0 -397
  99. package/dist/types/providers/anthropic.d.ts +0 -259
  100. package/dist/types/providers/aws-credentials.d.ts +0 -49
  101. package/dist/types/providers/aws-eventstream.d.ts +0 -39
  102. package/dist/types/providers/aws-sigv4.d.ts +0 -55
  103. package/dist/types/providers/azure-openai-responses.d.ts +0 -20
  104. package/dist/types/providers/bedrock-mantle.d.ts +0 -13
  105. package/dist/types/providers/claude-code-fingerprint.d.ts +0 -21
  106. package/dist/types/providers/connect-error-detail.d.ts +0 -14
  107. package/dist/types/providers/cowork-fetch.d.ts +0 -14
  108. package/dist/types/providers/cursor/exec-modern.d.ts +0 -98
  109. package/dist/types/providers/cursor/interaction-query.d.ts +0 -15
  110. package/dist/types/providers/cursor-pi-args.d.ts +0 -140
  111. package/dist/types/providers/cursor.d.ts +0 -258
  112. package/dist/types/providers/devin.d.ts +0 -12
  113. package/dist/types/providers/error-message.d.ts +0 -25
  114. package/dist/types/providers/github-copilot-headers.d.ts +0 -40
  115. package/dist/types/providers/gitlab-duo-workflow.d.ts +0 -254
  116. package/dist/types/providers/gitlab-duo.d.ts +0 -7
  117. package/dist/types/providers/google-auth.d.ts +0 -24
  118. package/dist/types/providers/google-gemini-cli.d.ts +0 -119
  119. package/dist/types/providers/google-shared.d.ts +0 -203
  120. package/dist/types/providers/google-types.d.ts +0 -161
  121. package/dist/types/providers/google-vertex.d.ts +0 -7
  122. package/dist/types/providers/google.d.ts +0 -4
  123. package/dist/types/providers/grammar.d.ts +0 -1
  124. package/dist/types/providers/kimi.d.ts +0 -27
  125. package/dist/types/providers/mock.d.ts +0 -182
  126. package/dist/types/providers/ollama.d.ts +0 -8
  127. package/dist/types/providers/openai-anthropic-shim.d.ts +0 -35
  128. package/dist/types/providers/openai-chat-server-schema.d.ts +0 -1311
  129. package/dist/types/providers/openai-chat-server.d.ts +0 -16
  130. package/dist/types/providers/openai-chat-wire.d.ts +0 -669
  131. package/dist/types/providers/openai-codex/request-transformer.d.ts +0 -111
  132. package/dist/types/providers/openai-codex/response-handler.d.ts +0 -26
  133. package/dist/types/providers/openai-codex-responses.d.ts +0 -238
  134. package/dist/types/providers/openai-completions.d.ts +0 -46
  135. package/dist/types/providers/openai-data-uri.d.ts +0 -11
  136. package/dist/types/providers/openai-reasoning-fallback.d.ts +0 -33
  137. package/dist/types/providers/openai-responses-server-schema.d.ts +0 -1458
  138. package/dist/types/providers/openai-responses-server.d.ts +0 -17
  139. package/dist/types/providers/openai-responses-wire.d.ts +0 -6099
  140. package/dist/types/providers/openai-responses.d.ts +0 -131
  141. package/dist/types/providers/openai-shared.d.ts +0 -716
  142. package/dist/types/providers/pi-native-client.d.ts +0 -13
  143. package/dist/types/providers/pi-native-server.d.ts +0 -69
  144. package/dist/types/providers/register-builtins.d.ts +0 -37
  145. package/dist/types/providers/synthetic.d.ts +0 -26
  146. package/dist/types/providers/transform-messages.d.ts +0 -32
  147. package/dist/types/providers/vision-guard.d.ts +0 -15
  148. package/dist/types/registry/amazon-bedrock.d.ts +0 -3
  149. package/dist/types/registry/api-key-validation.d.ts +0 -46
  150. package/dist/types/registry/aws.d.ts +0 -15
  151. package/dist/types/registry/bedrock-mantle.d.ts +0 -3
  152. package/dist/types/registry/build.d.ts +0 -11
  153. package/dist/types/registry/cloudflare-ai-gateway.d.ts +0 -3
  154. package/dist/types/registry/derived.d.ts +0 -5
  155. package/dist/types/registry/engine/api-key.d.ts +0 -8
  156. package/dist/types/registry/engine/common.d.ts +0 -55
  157. package/dist/types/registry/engine/device-code.d.ts +0 -9
  158. package/dist/types/registry/engine/oauth-code.d.ts +0 -27
  159. package/dist/types/registry/engine/refresh.d.ts +0 -11
  160. package/dist/types/registry/hooks/api-key.d.ts +0 -8
  161. package/dist/types/registry/hooks/custom.d.ts +0 -7
  162. package/dist/types/registry/hooks/device-code.d.ts +0 -8
  163. package/dist/types/registry/hooks/env.d.ts +0 -2
  164. package/dist/types/registry/hooks/index.d.ts +0 -3
  165. package/dist/types/registry/hooks/oauth-code.d.ts +0 -8
  166. package/dist/types/registry/hooks/types.d.ts +0 -44
  167. package/dist/types/registry/index.d.ts +0 -4
  168. package/dist/types/registry/oauth/alibaba-coding-plan.d.ts +0 -2
  169. package/dist/types/registry/oauth/alibaba-token-plan.d.ts +0 -13
  170. package/dist/types/registry/oauth/anthropic-constants.d.ts +0 -12
  171. package/dist/types/registry/oauth/anthropic.d.ts +0 -32
  172. package/dist/types/registry/oauth/callback-server.d.ts +0 -74
  173. package/dist/types/registry/oauth/cloudflare-ai-gateway.d.ts +0 -3
  174. package/dist/types/registry/oauth/coreweave.d.ts +0 -1
  175. package/dist/types/registry/oauth/cursor.d.ts +0 -18
  176. package/dist/types/registry/oauth/device-code.d.ts +0 -25
  177. package/dist/types/registry/oauth/github-copilot.d.ts +0 -33
  178. package/dist/types/registry/oauth/gitlab-duo.d.ts +0 -3
  179. package/dist/types/registry/oauth/google-antigravity.d.ts +0 -11
  180. package/dist/types/registry/oauth/google-gemini-cli.d.ts +0 -19
  181. package/dist/types/registry/oauth/google-oauth-shared.d.ts +0 -32
  182. package/dist/types/registry/oauth/index.d.ts +0 -44
  183. package/dist/types/registry/oauth/kilo.d.ts +0 -2
  184. package/dist/types/registry/oauth/kimi.d.ts +0 -12
  185. package/dist/types/registry/oauth/openai-codex.d.ts +0 -26
  186. package/dist/types/registry/oauth/perplexity.d.ts +0 -9
  187. package/dist/types/registry/oauth/pkce.d.ts +0 -8
  188. package/dist/types/registry/oauth/types.d.ts +0 -88
  189. package/dist/types/registry/oauth/xai-oauth.d.ts +0 -41
  190. package/dist/types/registry/oauth/xiaomi.d.ts +0 -17
  191. package/dist/types/registry/oauth/zai.d.ts +0 -13
  192. package/dist/types/registry/registry.d.ts +0 -14
  193. package/dist/types/registry/types.d.ts +0 -82
  194. package/dist/types/stream.d.ts +0 -56
  195. package/dist/types/types.d.ts +0 -1164
  196. package/dist/types/usage/alibaba-token-plan.d.ts +0 -3
  197. package/dist/types/usage/claude.d.ts +0 -4
  198. package/dist/types/usage/cline-pass.d.ts +0 -2
  199. package/dist/types/usage/cursor.d.ts +0 -15
  200. package/dist/types/usage/devin.d.ts +0 -12
  201. package/dist/types/usage/gemini.d.ts +0 -2
  202. package/dist/types/usage/github-copilot.d.ts +0 -7
  203. package/dist/types/usage/google-antigravity.d.ts +0 -26
  204. package/dist/types/usage/kimi.d.ts +0 -4
  205. package/dist/types/usage/minimax-code.d.ts +0 -3
  206. package/dist/types/usage/ollama.d.ts +0 -5
  207. package/dist/types/usage/openai-codex-base-url.d.ts +0 -18
  208. package/dist/types/usage/openai-codex-reset.d.ts +0 -68
  209. package/dist/types/usage/openai-codex.d.ts +0 -10
  210. package/dist/types/usage/opencode-go.d.ts +0 -13
  211. package/dist/types/usage/shared.d.ts +0 -13
  212. package/dist/types/usage/synthetic.d.ts +0 -2
  213. package/dist/types/usage/umans.d.ts +0 -2
  214. package/dist/types/usage/xai-oauth.d.ts +0 -12
  215. package/dist/types/usage/zai.d.ts +0 -3
  216. package/dist/types/usage.d.ts +0 -549
  217. package/dist/types/utils/abort.d.ts +0 -25
  218. package/dist/types/utils/anthropic-auth.d.ts +0 -35
  219. package/dist/types/utils/aws-profile.d.ts +0 -17
  220. package/dist/types/utils/block-symbols.d.ts +0 -74
  221. package/dist/types/utils/deterministic-id.d.ts +0 -16
  222. package/dist/types/utils/empty-completion-retry.d.ts +0 -31
  223. package/dist/types/utils/event-stream.d.ts +0 -50
  224. package/dist/types/utils/foundry.d.ts +0 -1
  225. package/dist/types/utils/glyph-codec.d.ts +0 -22
  226. package/dist/types/utils/google-validation.d.ts +0 -2
  227. package/dist/types/utils/harmony-leak.d.ts +0 -144
  228. package/dist/types/utils/http-inspector.d.ts +0 -67
  229. package/dist/types/utils/idle-iterator.d.ts +0 -149
  230. package/dist/types/utils/leaked-thinking-stream.d.ts +0 -39
  231. package/dist/types/utils/openai-http.d.ts +0 -48
  232. package/dist/types/utils/openrouter-headers.d.ts +0 -1
  233. package/dist/types/utils/parse-bind.d.ts +0 -23
  234. package/dist/types/utils/provider-response.d.ts +0 -3
  235. package/dist/types/utils/proxy.d.ts +0 -58
  236. package/dist/types/utils/request-debug.d.ts +0 -29
  237. package/dist/types/utils/retry-after.d.ts +0 -4
  238. package/dist/types/utils/schema/adapt.d.ts +0 -24
  239. package/dist/types/utils/schema/compatibility.d.ts +0 -30
  240. package/dist/types/utils/schema/dereference.d.ts +0 -11
  241. package/dist/types/utils/schema/draft.d.ts +0 -10
  242. package/dist/types/utils/schema/equality.d.ts +0 -4
  243. package/dist/types/utils/schema/fields.d.ts +0 -54
  244. package/dist/types/utils/schema/index.d.ts +0 -14
  245. package/dist/types/utils/schema/json-schema-validator.d.ts +0 -20
  246. package/dist/types/utils/schema/meta-validator.d.ts +0 -2
  247. package/dist/types/utils/schema/normalize.d.ts +0 -163
  248. package/dist/types/utils/schema/spill.d.ts +0 -8
  249. package/dist/types/utils/schema/stamps.d.ts +0 -17
  250. package/dist/types/utils/schema/strict-tool-validation.d.ts +0 -25
  251. package/dist/types/utils/schema/types.d.ts +0 -4
  252. package/dist/types/utils/schema/typescript.d.ts +0 -24
  253. package/dist/types/utils/schema/wire.d.ts +0 -58
  254. package/dist/types/utils/sdk-stream-timeout.d.ts +0 -33
  255. package/dist/types/utils/sse-debug.d.ts +0 -5
  256. package/dist/types/utils/stream-markup-healing.d.ts +0 -84
  257. package/dist/types/utils/thinking-loop.d.ts +0 -91
  258. package/dist/types/utils/tool-call-loop-guard.d.ts +0 -26
  259. package/dist/types/utils/tool-choice.d.ts +0 -52
  260. package/dist/types/utils/validation.d.ts +0 -28
  261. package/dist/types/utils.d.ts +0 -57
package/CHANGELOG.md CHANGED
@@ -2,10 +2,9 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
- ## [1.1.8] - 2026-09-04
5
+ ## [1.1.9] - 2026-09-05
6
6
 
7
- - OMP sync v18.1.2–v18.1.5: Copilot auth standardization, transport-error-safe retries after tool calls, and prefix-binding control state.
8
- - Fixed the Z.ai OAuth key name to the Zeta brand (`zeta`) — the merge had reintroduced upstream's `oh-my-pi` fixture rows.
7
+ - Z.ai OAuth key name sends zeta (merge restored the upstream oh-my-pi literal in tests); xAI/OpenAI-compatible requests send the zeta User-Agent again.
9
8
 
10
9
  ## [1.1.6] - 2026-08-30
11
10
 
@@ -43,20 +42,3 @@
43
42
 
44
43
  - Reset the version to 1.0.0 and republished under the `@linxiraos/*` scope, breaking from the `@linxiraos` version lineage.
45
44
  - Fixed Gemini thought summaries occasionally leaking a raw `` ```thinking `` / `` ``````thinking `` fence delimiter into the reasoning block, so it no longer shows up as fence spam in the thinking display or persisted transcripts ([#8719](https://github.com/can1357/oh-my-pi/issues/8719)).
46
- - Fixed the OpenCode Go login prompting for an "OpenCode Zen API key": the shared login flow now names the provider you selected, so connecting OpenCode Go asks for an OpenCode Go key (the `opencode.ai/auth` console is still shared, as documented upstream) ([#8738](https://github.com/can1357/oh-my-pi/issues/8738)).
47
- - Fixed Anthropic-compatible endpoints with strict prompt validation (e.g. Z.AI GLM `api.z.ai/api/anthropic`, which rejects the whole request with `400 code 1213 "The prompt parameter was not received normally"`) failing sessions once a tool returned empty output on a vision-capable model: empty successful `tool_result` blocks now encode as `content: ""` instead of `content: []`, which both the official API and strict compatible endpoints accept.
48
- - Fixed `retry.usageReservePct` (Reserve Margin) ignoring Claude Fable/Mythos weekly tier usage until it hit 100%, so a Fable model kept serving turns past the configured reserve; reserve health now honors the mapped tier row while credential-wide hard blocks still require confirmed exhaustion ([#8773](https://github.com/can1357/oh-my-pi/issues/8773)).
49
- - Fixed `cursor-agent` streams stalling with "Provider stream stalled while waiting for the next event" when Cursor asked the client to approve a hosted WebFetch / web search (reproduced on `cursor-grok-4.6-xhigh` after "I'll fetch the page…"). Those `interaction_query` frames — including the newer WebFetch field 9 this proto did not name — were dropped, so the server waited forever and the idle watchdog aborted a live connection. Permission queries are now answered; hosted search/fetch is approved, unnamed permission fields get an `approved` reply on the same field number, and prompts this client cannot serve are rejected so the turn can continue.
50
-
51
- ### Fixed
52
-
53
- - Fixed thinking effort selections being ignored for local Qwen 3.8+ models on llama.cpp and vLLM: the Qwen chat-completions dialects only toggled `enable_thinking`, so the chat template always reasoned at its `xhigh` default no matter which level was selected. The encoder now routes the requested effort onto the template's `reasoning_effort` kwarg (`chat_template_kwargs` for both Qwen dialects, plus the top-level field newer llama.cpp builds map natively).
54
- - Fixed OpenAI Completions, Amazon Bedrock, and Cursor providers ignoring `onPayload` replacement payloads. The hook now transforms the actual request body sent upstream on these providers, matching the Anthropic/Gemini/OpenAI Responses replacement contract. `devin-agent` still does not fire the hook (its payload is a protobuf object).
55
- - Fixed Codex requests failing outright when the signed-in ChatGPT account is not entitled to the requested model; the exact model denial is now classified as an account-policy error so credential rotation can reach an entitled sibling account
56
- - Fixed Perplexity email-OTP login after its verification response renamed the encrypted session token from `token` to `challenge_token`.
57
- - Cloud Code Assist Gemini 3.6/3.7 Flash requests at `minimal` now send `thinkingLevel: LOW` on the aliased `-low` SKU instead of `MINIMAL`, which the API rejects with HTTP 400.
58
- - Answer Cursor `interaction_query` permission gates (hosted web search, Exa, unnamed field-9 WebFetch) so the Run RPC continues instead of sitting silent until the 300s idle watchdog.
59
- - Fixed provider tool calls arriving with flattened array argument paths (e.g. Gemini's `questions[0].id`) being stripped and rejected by argument validation; well-formed flattened paths are now rebuilt into the nested arrays the tool schema expects ([#8886](https://github.com/can1357/oh-my-pi/issues/8886)).
60
- - Fixed opencode-go (Console Go) rejecting Responses turns with `400 No tool output found for tool call …` (naming a random call of the batch on each retry) when a model streamed a trailing text/thinking block after its tool calls: `buildResponsesInput` emitted that block as an assistant `message` item wedged between the `function_call` batch and its `function_call_output` items. Such interleaved messages are now hoisted ahead of their call batch (canonical `message(s) → calls → outputs`), which the strict gateway validator accepts; content is unchanged ([#8789](https://github.com/can1357/oh-my-pi/issues/8789)).
61
- - Fixed the OpenAI-wire transport sleeping on a LiteLLM concurrency-admission 429 (`rate_limit_type: max_parallel_requests`, `Retry-After: 60`) and retrying it up to 6 times (~300s) before session recovery saw the error. Because a 60s hint equals the transport's `maxDelayMs` cap, `fetchWithRetry` kept sleeping and retrying; the request now surfaces on the first attempt so `TurnRecovery`'s concurrency backoff/model fallback runs promptly. Genuine RPM/quota 429s (no such marker) still honor `Retry-After` ([#8854](https://github.com/can1357/oh-my-pi/issues/8854)).
62
- - Fixed OAuth login (Codex `localhost:1455`, and any `localhost` callback flow) failing on hosts with IPv6 disabled at the kernel (`ipv6.disable=1`). The `::1` companion listener added in #8081 fails there with Bun's generic "Is port X in use?" message (oven-sh/bun#7187), which the in-use check misread as a real collision — tearing down the healthy IPv4 listener and surfacing a bogus "port 1455 is in use" error. The dual-bind path now detects the missing IPv6 loopback up front and serves IPv4 alone ([#8814](https://github.com/can1357/oh-my-pi/issues/8814)).
package/README.md CHANGED
@@ -10,38 +10,38 @@ Unified LLM API with automatic model discovery, provider configuration, token an
10
10
  - [Installation](#installation)
11
11
  - [Quick Start](#quick-start)
12
12
  - [Tools](#tools)
13
- - [Defining Tools](#defining-tools)
14
- - [Handling Tool Calls](#handling-tool-calls)
15
- - [Streaming Tool Calls with Partial JSON](#streaming-tool-calls-with-partial-json)
16
- - [Validating Tool Arguments](#validating-tool-arguments)
17
- - [Complete Event Reference](#complete-event-reference)
13
+ - [Defining Tools](#defining-tools)
14
+ - [Handling Tool Calls](#handling-tool-calls)
15
+ - [Streaming Tool Calls with Partial JSON](#streaming-tool-calls-with-partial-json)
16
+ - [Validating Tool Arguments](#validating-tool-arguments)
17
+ - [Complete Event Reference](#complete-event-reference)
18
18
  - [Image Input](#image-input)
19
19
  - [Thinking/Reasoning](#thinkingreasoning)
20
- - [Unified Interface](#unified-interface-streamsimplecompletesimple)
21
- - [Provider-Specific Options](#provider-specific-options-streamcomplete)
22
- - [Streaming Thinking Content](#streaming-thinking-content)
20
+ - [Unified Interface](#unified-interface-streamsimplecompletesimple)
21
+ - [Provider-Specific Options](#provider-specific-options-streamcomplete)
22
+ - [Streaming Thinking Content](#streaming-thinking-content)
23
23
  - [Stop Reasons](#stop-reasons)
24
24
  - [Error Handling](#error-handling)
25
- - [Aborting Requests](#aborting-requests)
26
- - [Continuing After Abort](#continuing-after-abort)
25
+ - [Aborting Requests](#aborting-requests)
26
+ - [Continuing After Abort](#continuing-after-abort)
27
27
  - [APIs, Models, and Providers](#apis-models-and-providers)
28
- - [Providers and Models](#providers-and-models)
29
- - [Querying Providers and Models](#querying-providers-and-models)
30
- - [Custom Models](#custom-models)
31
- - [OpenAI Compatibility Settings](#openai-compatibility-settings)
32
- - [Type Safety](#type-safety)
28
+ - [Providers and Models](#providers-and-models)
29
+ - [Querying Providers and Models](#querying-providers-and-models)
30
+ - [Custom Models](#custom-models)
31
+ - [OpenAI Compatibility Settings](#openai-compatibility-settings)
32
+ - [Type Safety](#type-safety)
33
33
  - [Cross-Provider Handoffs](#cross-provider-handoffs)
34
34
  - [Context Serialization](#context-serialization)
35
35
  - [Browser Usage](#browser-usage)
36
- - [Environment Variables](#environment-variables-nodejs-only)
37
- - [Checking Environment Variables](#checking-environment-variables)
36
+ - [Environment Variables](#environment-variables-nodejs-only)
37
+ - [Checking Environment Variables](#checking-environment-variables)
38
38
  - [OAuth Providers](#oauth-providers)
39
- - [Vertex AI (ADC)](#vertex-ai-adc)
40
- - [CLI Login](#cli-login)
41
- - [Programmatic OAuth](#programmatic-oauth)
42
- - [Login Flow Example](#login-flow-example)
43
- - [Using OAuth Tokens](#using-oauth-tokens)
44
- - [Provider Notes](#provider-notes)
39
+ - [Vertex AI (ADC)](#vertex-ai-adc)
40
+ - [CLI Login](#cli-login)
41
+ - [Programmatic OAuth](#programmatic-oauth)
42
+ - [Login Flow Example](#login-flow-example)
43
+ - [Using OAuth Tokens](#using-oauth-tokens)
44
+ - [Provider Notes](#provider-notes)
45
45
  - [License](#license)
46
46
 
47
47
  ## Supported Providers
@@ -172,7 +172,7 @@ const finalMessage = await s.result();
172
172
  context.messages.push(finalMessage);
173
173
 
174
174
  // Handle tool calls if any
175
- const toolCalls = finalMessage.content.filter((b) => b.type === "toolCall");
175
+ const toolCalls = finalMessage.content.filter(b => b.type === "toolCall");
176
176
  for (const call of toolCalls) {
177
177
  // Execute the tool
178
178
  const result =
@@ -464,7 +464,7 @@ const response = await completeSimple(
464
464
  },
465
465
  {
466
466
  reasoning: "medium", // 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' (xhigh maps to high on non-OpenAI providers)
467
- }
467
+ },
468
468
  );
469
469
 
470
470
  // Access thinking and text blocks
@@ -583,7 +583,7 @@ const s = stream(
583
583
  },
584
584
  {
585
585
  signal,
586
- }
586
+ },
587
587
  );
588
588
 
589
589
  for await (const event of s) {
@@ -643,7 +643,7 @@ Example:
643
643
  const response = await complete(model, context, {
644
644
  apiKey: "sk-live",
645
645
  headers: { "X-Debug-Trace": "true" },
646
- onPayload: (payload) => {
646
+ onPayload: payload => {
647
647
  console.log("request payload", payload);
648
648
  },
649
649
  });
@@ -918,7 +918,7 @@ const response = await complete(
918
918
  },
919
919
  {
920
920
  apiKey: "your-api-key",
921
- }
921
+ },
922
922
  );
923
923
  ```
924
924
 
@@ -928,40 +928,40 @@ const response = await complete(
928
928
 
929
929
  In Node.js environments, you can set environment variables to avoid passing API keys:
930
930
 
931
- | Provider | Environment Variable(s) |
932
- | -------------- | ---------------------------------------------------------------------------- |
933
- | OpenAI | `OPENAI_API_KEY` |
934
- | Anthropic | `ANTHROPIC_API_KEY` or `ANTHROPIC_OAUTH_TOKEN` (or `ANTHROPIC_FOUNDRY_API_KEY` when `CLAUDE_CODE_USE_FOUNDRY=true`) |
935
- | Google | `GEMINI_API_KEY` |
936
- | Vertex AI | `GOOGLE_CLOUD_PROJECT` (or `GCLOUD_PROJECT`) + `GOOGLE_CLOUD_LOCATION` + ADC |
937
- | Mistral | `MISTRAL_API_KEY` |
938
- | Groq | `GROQ_API_KEY` |
939
- | Cerebras | `CEREBRAS_API_KEY` |
940
- | Together | `TOGETHER_API_KEY` |
941
- | Qianfan | `QIANFAN_API_KEY` |
942
- | Hugging Face | `HUGGINGFACE_HUB_TOKEN` or `HF_TOKEN` |
943
- | Synthetic | `SYNTHETIC_API_KEY` |
944
- | NVIDIA | `NVIDIA_API_KEY` |
945
- | NanoGPT | `NANO_GPT_API_KEY` |
946
- | Novita | `NOVITA_API_KEY` |
947
- | DeepInfra | `DEEPINFRA_API_KEY` |
948
- | Venice | `VENICE_API_KEY` |
949
- | Moonshot | `MOONSHOT_API_KEY` |
950
- | xAI | `XAI_API_KEY` |
951
- | OpenRouter | `OPENROUTER_API_KEY` |
952
- | LiteLLM | `LITELLM_API_KEY` |
953
- | Ollama | `OLLAMA_API_KEY` (optional for local deployments) |
954
- | Ollama Cloud | `OLLAMA_CLOUD_API_KEY` |
955
- | Qwen Portal | `QWEN_OAUTH_TOKEN` or `QWEN_PORTAL_API_KEY` |
956
- | QwenCloud Token Plan | `ALIBABA_TOKEN_PLAN_API_KEY` or `BAILIAN_TOKEN_PLAN_API_KEY` |
957
- | zAI | `ZAI_API_KEY` |
958
- | Umans AI Coding Plan | `UMANS_AI_CODING_PLAN_API_KEY` |
959
- | MiniMax Code | `MINIMAX_CODE_API_KEY` (international) or `MINIMAX_CODE_CN_API_KEY` (China) |
960
- | Xiaomi MiMo | `XIAOMI_API_KEY` |
961
- | ZenMux | `ZENMUX_API_KEY` |
962
- | vLLM | `VLLM_API_KEY` |
963
- | Cloudflare AI Gateway | `CLOUDFLARE_AI_GATEWAY_API_KEY` + `CLOUDFLARE_ACCOUNT_ID` + `CLOUDFLARE_GATEWAY_ID` |
964
- | GitHub Copilot | `COPILOT_GITHUB_TOKEN` or `GH_TOKEN` or `GITHUB_TOKEN` |
931
+ | Provider | Environment Variable(s) |
932
+ | --------------------- | ------------------------------------------------------------------------------------------------------------------- |
933
+ | OpenAI | `OPENAI_API_KEY` |
934
+ | Anthropic | `ANTHROPIC_API_KEY` or `ANTHROPIC_OAUTH_TOKEN` (or `ANTHROPIC_FOUNDRY_API_KEY` when `CLAUDE_CODE_USE_FOUNDRY=true`) |
935
+ | Google | `GEMINI_API_KEY` |
936
+ | Vertex AI | `GOOGLE_CLOUD_PROJECT` (or `GCLOUD_PROJECT`) + `GOOGLE_CLOUD_LOCATION` + ADC |
937
+ | Mistral | `MISTRAL_API_KEY` |
938
+ | Groq | `GROQ_API_KEY` |
939
+ | Cerebras | `CEREBRAS_API_KEY` |
940
+ | Together | `TOGETHER_API_KEY` |
941
+ | Qianfan | `QIANFAN_API_KEY` |
942
+ | Hugging Face | `HUGGINGFACE_HUB_TOKEN` or `HF_TOKEN` |
943
+ | Synthetic | `SYNTHETIC_API_KEY` |
944
+ | NVIDIA | `NVIDIA_API_KEY` |
945
+ | NanoGPT | `NANO_GPT_API_KEY` |
946
+ | Novita | `NOVITA_API_KEY` |
947
+ | DeepInfra | `DEEPINFRA_API_KEY` |
948
+ | Venice | `VENICE_API_KEY` |
949
+ | Moonshot | `MOONSHOT_API_KEY` |
950
+ | xAI | `XAI_API_KEY` |
951
+ | OpenRouter | `OPENROUTER_API_KEY` |
952
+ | LiteLLM | `LITELLM_API_KEY` |
953
+ | Ollama | `OLLAMA_API_KEY` (optional for local deployments) |
954
+ | Ollama Cloud | `OLLAMA_CLOUD_API_KEY` |
955
+ | Qwen Portal | `QWEN_OAUTH_TOKEN` or `QWEN_PORTAL_API_KEY` |
956
+ | QwenCloud Token Plan | `ALIBABA_TOKEN_PLAN_API_KEY` or `BAILIAN_TOKEN_PLAN_API_KEY` |
957
+ | zAI | `ZAI_API_KEY` |
958
+ | Umans AI Coding Plan | `UMANS_AI_CODING_PLAN_API_KEY` |
959
+ | MiniMax Code | `MINIMAX_CODE_API_KEY` (international) or `MINIMAX_CODE_CN_API_KEY` (China) |
960
+ | Xiaomi MiMo | `XIAOMI_API_KEY` |
961
+ | ZenMux | `ZENMUX_API_KEY` |
962
+ | vLLM | `VLLM_API_KEY` |
963
+ | Cloudflare AI Gateway | `CLOUDFLARE_AI_GATEWAY_API_KEY` + `CLOUDFLARE_ACCOUNT_ID` + `CLOUDFLARE_GATEWAY_ID` |
964
+ | GitHub Copilot | `COPILOT_GITHUB_TOKEN` or `GH_TOKEN` or `GITHUB_TOKEN` |
965
965
 
966
966
  `/login cloudflare-ai-gateway` collects and stores the gateway token, account ID, and gateway ID. For environment configuration, set all three Cloudflare values above. OMP derives provider endpoints from the account and gateway IDs.
967
967
 
@@ -997,7 +997,7 @@ Provider endpoint defaults for the current OpenAI-compatible integrations:
997
997
  - LiteLLM: `http://localhost:4000/v1`
998
998
  - Cloudflare AI Gateway: native Anthropic, OpenAI, and Workers AI routes under `https://gateway.ai.cloudflare.com/v1/<account>/<gateway>`
999
999
  - Qwen Portal: `https://portal.qwen.ai/v1`
1000
- When set, the library automatically uses these keys:
1000
+ When set, the library automatically uses these keys:
1001
1001
 
1002
1002
  ```typescript
1003
1003
  // Uses OPENAI_API_KEY from environment
@@ -1143,10 +1143,10 @@ const credentials = await loginGitHubCopilot({
1143
1143
  console.log(`Open: ${url}`);
1144
1144
  if (instructions) console.log(instructions);
1145
1145
  },
1146
- onPrompt: async (prompt) => {
1146
+ onPrompt: async prompt => {
1147
1147
  return await getUserInput(prompt.message);
1148
1148
  },
1149
- onProgress: (message) => console.log(message),
1149
+ onProgress: message => console.log(message),
1150
1150
  });
1151
1151
 
1152
1152
  // Store credentials yourself
@@ -1180,7 +1180,7 @@ const response = await complete(
1180
1180
  {
1181
1181
  messages: [{ role: "user", content: "Hello!" }],
1182
1182
  },
1183
- { apiKey: result.apiKey }
1183
+ { apiKey: result.apiKey },
1184
1184
  );
1185
1185
  ```
1186
1186
 
package/package.json CHANGED
@@ -1,138 +1,133 @@
1
1
  {
2
- "type": "module",
3
- "name": "@linxiraos/pi-ai",
4
- "version": "1.1.8",
5
- "description": "Unified LLM API with automatic model discovery and provider configuration",
6
- "homepage": "https://linxira-os.github.io/zeta/",
7
- "author": "Can Boluk",
8
- "contributors": [
9
- "Mario Zechner"
10
- ],
11
- "license": "MIT",
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/Linxira-OS/linxira-zeta.git",
15
- "directory": "packages/ai"
16
- },
17
- "bugs": {
18
- "url": "https://github.com/Linxira-OS/linxira-zeta/issues"
19
- },
20
- "keywords": [
21
- "ai",
22
- "llm",
23
- "openai",
24
- "anthropic",
25
- "gemini",
26
- "unified",
27
- "api"
28
- ],
29
- "main": "./src/index.ts",
30
- "types": "./dist/types/index.d.ts",
31
- "scripts": {
32
- "check": "biome check . && bun run check:types",
33
- "check:types": "tsgo -p tsconfig.json --noEmit",
34
- "lint": "biome lint .",
35
- "test": "bun test --parallel",
36
- "fix": "biome check --write --unsafe .",
37
- "fmt": "biome format --write ."
38
- },
39
- "dependencies": {
40
- "@linxiraos/pi-omptype": "1.1.8",
41
- "@linxiraos/pi-catalog": "1.1.8",
42
- "@linxiraos/pi-utils": "1.1.8",
43
- "@linxiraos/pi-wire": "1.1.8"
44
- },
45
- "devDependencies": {
46
- "@types/bun": "^1.3.14"
47
- },
48
- "engines": {
49
- "bun": ">=1.3.14"
50
- },
51
- "files": [
52
- "src",
53
- "README.md",
54
- "CHANGELOG.md",
55
- "LICENSE",
56
- "THIRD-PARTY-NOTICES.txt",
57
- "dist/types"
58
- ],
59
- "exports": {
60
- ".": {
61
- "types": "./dist/types/index.d.ts",
62
- "import": "./src/index.ts"
63
- },
64
- "./error": {
65
- "types": "./dist/types/error/index.d.ts",
66
- "import": "./src/error/index.ts"
67
- },
68
- "./*": {
69
- "types": "./dist/types/*.d.ts",
70
- "import": "./src/*.ts"
71
- },
72
- "./auth-broker": {
73
- "types": "./dist/types/auth-broker/index.d.ts",
74
- "import": "./src/auth-broker/index.ts"
75
- },
76
- "./auth-broker/*": {
77
- "types": "./dist/types/auth-broker/*.d.ts",
78
- "import": "./src/auth-broker/*.ts"
79
- },
80
- "./auth-gateway": {
81
- "types": "./dist/types/auth-gateway/index.d.ts",
82
- "import": "./src/auth-gateway/index.ts"
83
- },
84
- "./auth-gateway/*": {
85
- "types": "./dist/types/auth-gateway/*.d.ts",
86
- "import": "./src/auth-gateway/*.ts"
87
- },
88
- "./providers/*": {
89
- "types": "./dist/types/providers/*.d.ts",
90
- "import": "./src/providers/*.ts"
91
- },
92
- "./providers/openai-codex/*": {
93
- "types": "./dist/types/providers/openai-codex/*.d.ts",
94
- "import": "./src/providers/openai-codex/*.ts"
95
- },
96
- "./usage/*": {
97
- "types": "./dist/types/usage/*.d.ts",
98
- "import": "./src/usage/*.ts"
99
- },
100
- "./utils/harmony-leak": {
101
- "types": "./dist/types/utils/harmony-leak.d.ts",
102
- "import": "./src/utils/harmony-leak.ts"
103
- },
104
- "./dialect": {
105
- "types": "./dist/types/dialect/index.d.ts",
106
- "import": "./src/dialect/index.ts"
107
- },
108
- "./utils/*": {
109
- "types": "./dist/types/utils/*.d.ts",
110
- "import": "./src/utils/*.ts"
111
- },
112
- "./oauth": {
113
- "types": "./dist/types/registry/oauth/index.d.ts",
114
- "import": "./src/registry/oauth/index.ts"
115
- },
116
- "./oauth/*": {
117
- "types": "./dist/types/registry/oauth/*.d.ts",
118
- "import": "./src/registry/oauth/*.ts"
119
- },
120
- "./registry": {
121
- "types": "./dist/types/registry/index.d.ts",
122
- "import": "./src/registry/index.ts"
123
- },
124
- "./registry/oauth": {
125
- "types": "./dist/types/registry/oauth/index.d.ts",
126
- "import": "./src/registry/oauth/index.ts"
127
- },
128
- "./utils/schema": {
129
- "types": "./dist/types/utils/schema/index.d.ts",
130
- "import": "./src/utils/schema/index.ts"
131
- },
132
- "./utils/schema/*": {
133
- "types": "./dist/types/utils/schema/*.d.ts",
134
- "import": "./src/utils/schema/*.ts"
135
- },
136
- "./*.js": "./src/*.ts"
137
- }
2
+ "engines": {
3
+ "bun": ">=1.3.14"
4
+ },
5
+ "devDependencies": {
6
+ "@types/bun": "^1.3.14"
7
+ },
8
+ "dependencies": {
9
+ "@linxiraos/pi-wire": "1.1.9",
10
+ "@linxiraos/pi-utils": "1.1.9",
11
+ "@linxiraos/pi-catalog": "1.1.9",
12
+ "@linxiraos/pi-omptype": "1.1.9",
13
+ "@linxiraos/pi-natives": "1.1.9"
14
+ },
15
+ "scripts": {
16
+ "test": "bun test --parallel",
17
+ "check:types": "tsgo -p tsconfig.json --noEmit",
18
+ "check": "tsgo -p tsconfig.json --noEmit"
19
+ },
20
+ "exports": {
21
+ "./*.js": "./src/*.ts",
22
+ "./utils/schema/*": {
23
+ "import": "./src/utils/schema/*.ts",
24
+ "types": "./src/utils/schema/*.ts"
25
+ },
26
+ "./utils/schema": {
27
+ "import": "./src/utils/schema/index.ts",
28
+ "types": "./src/utils/schema/index.ts"
29
+ },
30
+ "./registry/oauth": {
31
+ "import": "./src/registry/oauth/index.ts",
32
+ "types": "./src/registry/oauth/index.ts"
33
+ },
34
+ "./registry": {
35
+ "import": "./src/registry/index.ts",
36
+ "types": "./src/registry/index.ts"
37
+ },
38
+ "./oauth/*": {
39
+ "import": "./src/registry/oauth/*.ts",
40
+ "types": "./src/registry/oauth/*.ts"
41
+ },
42
+ "./oauth": {
43
+ "import": "./src/registry/oauth/index.ts",
44
+ "types": "./src/registry/oauth/index.ts"
45
+ },
46
+ "./utils/*": {
47
+ "import": "./src/utils/*.ts",
48
+ "types": "./src/utils/*.ts"
49
+ },
50
+ "./dialect": {
51
+ "import": "./src/dialect/index.ts",
52
+ "types": "./src/dialect/index.ts"
53
+ },
54
+ "./utils/harmony-leak": {
55
+ "import": "./src/utils/harmony-leak.ts",
56
+ "types": "./src/utils/harmony-leak.ts"
57
+ },
58
+ "./usage/*": {
59
+ "import": "./src/usage/*.ts",
60
+ "types": "./src/usage/*.ts"
61
+ },
62
+ "./providers/openai-codex/*": {
63
+ "import": "./src/providers/openai-codex/*.ts",
64
+ "types": "./src/providers/openai-codex/*.ts"
65
+ },
66
+ "./providers/*": {
67
+ "import": "./src/providers/*.ts",
68
+ "types": "./src/providers/*.ts"
69
+ },
70
+ "./auth-gateway/*": {
71
+ "import": "./src/auth-gateway/*.ts",
72
+ "types": "./src/auth-gateway/*.ts"
73
+ },
74
+ "./auth-gateway": {
75
+ "import": "./src/auth-gateway/index.ts",
76
+ "types": "./src/auth-gateway/index.ts"
77
+ },
78
+ "./auth-broker/*": {
79
+ "import": "./src/auth-broker/*.ts",
80
+ "types": "./src/auth-broker/*.ts"
81
+ },
82
+ "./auth-broker": {
83
+ "import": "./src/auth-broker/index.ts",
84
+ "types": "./src/auth-broker/index.ts"
85
+ },
86
+ "./*": {
87
+ "import": "./src/*.ts",
88
+ "types": "./src/*.ts"
89
+ },
90
+ "./error": {
91
+ "import": "./src/error/index.ts",
92
+ "types": "./src/error/index.ts"
93
+ },
94
+ ".": {
95
+ "import": "./src/index.ts",
96
+ "types": "./src/index.ts"
97
+ }
98
+ },
99
+ "types": "./src/index.ts",
100
+ "main": "./src/index.ts",
101
+ "type": "module",
102
+ "files": [
103
+ "src",
104
+ "README.md",
105
+ "CHANGELOG.md"
106
+ ],
107
+ "repository": {
108
+ "directory": "packages/ai",
109
+ "url": "git+https://github.com/Linxira-OS/linxira-zeta.git",
110
+ "type": "git"
111
+ },
112
+ "contributors": [
113
+ "Mario Zechner"
114
+ ],
115
+ "author": "Can Boluk",
116
+ "license": "MIT",
117
+ "bugs": {
118
+ "url": "https://github.com/Linxira-OS/linxira-zeta/issues"
119
+ },
120
+ "homepage": "https://linxira-os.github.io/zeta/",
121
+ "keywords": [
122
+ "ai",
123
+ "llm",
124
+ "openai",
125
+ "anthropic",
126
+ "gemini",
127
+ "unified",
128
+ "api"
129
+ ],
130
+ "description": "Unified LLM API with automatic model discovery and provider configuration",
131
+ "version": "1.1.9",
132
+ "name": "@linxiraos/pi-ai"
138
133
  }
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import { createHash } from "node:crypto";
11
11
  import { planRequirementFor } from "@linxiraos/pi-catalog/compat/behavior";
12
- import { $env, $envExact, extractRetryHint, getAgentDbPath, logger } from "@linxiraos/pi-utils";
12
+ import { $env, $envExact, extractRetryHint, getAgentDbPath, logger, untilAborted } from "@linxiraos/pi-utils";
13
13
  import {
14
14
  isSqliteCorruptionError,
15
15
  resolveCredentialIdentityKey,
@@ -622,7 +622,7 @@ export type AuthStorageOptions = {
622
622
  * so the TUI can show where a token came from (broker URL or local SQLite path).
623
623
  *
624
624
  * Examples:
625
- * - `"local ~/.omp/agent/agent.db"`
625
+ * - `"local ~/.zeta/agent/agent.db"`
626
626
  * - `"broker http://omp.internal:8765"`
627
627
  */
628
628
  sourceLabel?: string;
@@ -3025,17 +3025,18 @@ export class AuthStorage {
3025
3025
  ): Promise<OAuthLoginIdentity | undefined> {
3026
3026
  // Only paste-code providers (fixed non-loopback redirect, e.g. GitLab Duo
3027
3027
  // Agent's vscode:// URI) get a default manual-code prompt. For loopback OAuth
3028
- // providers the `OAuthCallbackFlow` would otherwise race this readline prompt
3029
- // against the HTTP callback and, when the callback wins, leave the prompt
3030
- // outstanding a dirty/blocked terminal. Synthesizing the default only for
3031
- // paste-code providers is the authoritative gate (it covers every caller, not
3028
+ // providers an eager paste prompt adds noise to a flow that normally completes
3029
+ // through HTTP. Synthesizing the default only for paste-code providers is the
3030
+ // authoritative gate (it covers every caller, not
3032
3031
  // just the CLI); an explicit caller-supplied `onManualCodeInput` is still
3033
3032
  // honored for any provider as an escape hatch.
3034
3033
  const manualCodeInput = PASTE_CODE_LOGIN_PROVIDERS.has(provider)
3035
- ? () =>
3036
- ctrl.onPrompt({
3037
- message: "Paste the authorization code (or full redirect URL):",
3038
- })
3034
+ ? (signal?: AbortSignal) =>
3035
+ untilAborted(signal, () =>
3036
+ ctrl.onPrompt({
3037
+ message: "Paste the authorization code (or full redirect URL):",
3038
+ }),
3039
+ )
3039
3040
  : undefined;
3040
3041
  // Built-in registry first, then runtime-registered extension providers.
3041
3042
  const def = getProviderDefinition(provider) ?? getOAuthProvider(provider);
@@ -24,6 +24,12 @@ const SERVER_ERROR_BACKOFF_MS = 20 * 1000; // 20s
24
24
  const ACCOUNT_RATE_LIMIT_PATTERN =
25
25
  /\baccount(?:'s)?\b[^\n]{0,80}\brate.?limit\b|\brate.?limit\b[^\n]{0,80}\baccount\b/i;
26
26
  const INSUFFICIENT_BALANCE_PATTERN = /insufficient.?balance/i;
27
+ // Prepaid-credit exhaustion phrased around the credit balance rather than a
28
+ // quota: Anthropic "This request would exceed your available credits given
29
+ // your current in-flight requests" (402), OpenRouter "Insufficient credits",
30
+ // "credits exhausted". Account-local, so rotate to a sibling credential.
31
+ const CREDITS_EXHAUSTED_PATTERN =
32
+ /\b(?:exceed\w*|insufficient|not enough)\b[^\n]{0,40}\bcredits?\b|\bcredits?\b[^\n]{0,40}\b(?:exhausted|depleted)\b/i;
27
33
  const SPEND_LIMIT_PATTERN = /spend.?limit/i;
28
34
  const SUBSCRIPTION_CAP_PATTERN =
29
35
  /\b(?:subscription|plan|membership)\b[^\n]{0,80}\b(?:rate.?limits?|quota|cap)\b|\b(?:rate.?limits?|quota|cap)\b[^\n]{0,80}\b(?:subscription|plan|membership)\b/i;
@@ -247,7 +253,8 @@ export function parseRateLimitReason(errorMessage: string): RateLimitReason {
247
253
  lower.includes("out of credits") ||
248
254
  lower.includes("spending-limit") ||
249
255
  lower.includes("spending limit") ||
250
- INSUFFICIENT_BALANCE_PATTERN.test(errorMessage)
256
+ INSUFFICIENT_BALANCE_PATTERN.test(errorMessage) ||
257
+ CREDITS_EXHAUSTED_PATTERN.test(errorMessage)
251
258
  ) {
252
259
  return "QUOTA_EXHAUSTED";
253
260
  }
@@ -390,6 +397,7 @@ export function matchesUsageLimitText(errorMessage: string): boolean {
390
397
  if (isDashScopeTokenLimitText(errorMessage)) return false;
391
398
  return (
392
399
  USAGE_LIMIT_PATTERN.test(errorMessage) ||
400
+ CREDITS_EXHAUSTED_PATTERN.test(errorMessage) ||
393
401
  (CN_QUOTA_EXHAUSTED_PATTERN.test(errorMessage) && !CN_TRANSIENT_CAP_PATTERN.test(errorMessage)) ||
394
402
  SPEND_LIMIT_PATTERN.test(errorMessage) ||
395
403
  ACCOUNT_RATE_LIMIT_PATTERN.test(errorMessage) ||