@oh-my-pi/pi-ai 18.1.4 → 18.1.5

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 (274) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +8 -33
  3. package/dist/types/dialect/thinking.d.ts +9 -0
  4. package/dist/types/dialect/types.d.ts +10 -0
  5. package/dist/types/error/flags.d.ts +0 -7
  6. package/dist/types/error/retryable.d.ts +3 -10
  7. package/dist/types/index.d.ts +0 -1
  8. package/dist/types/providers/anthropic.d.ts +0 -7
  9. package/dist/types/providers/cursor.d.ts +3 -1
  10. package/dist/types/registry/amazon-bedrock.d.ts +3 -10
  11. package/dist/types/registry/bedrock-mantle.d.ts +3 -22
  12. package/dist/types/registry/build.d.ts +11 -0
  13. package/dist/types/registry/cloudflare-ai-gateway.d.ts +3 -13
  14. package/dist/types/registry/engine/api-key.d.ts +8 -0
  15. package/dist/types/registry/engine/common.d.ts +55 -0
  16. package/dist/types/registry/engine/device-code.d.ts +9 -0
  17. package/dist/types/registry/engine/oauth-code.d.ts +27 -0
  18. package/dist/types/registry/engine/refresh.d.ts +11 -0
  19. package/dist/types/registry/hooks/api-key.d.ts +8 -0
  20. package/dist/types/registry/hooks/custom.d.ts +7 -0
  21. package/dist/types/registry/hooks/device-code.d.ts +8 -0
  22. package/dist/types/registry/hooks/env.d.ts +2 -0
  23. package/dist/types/registry/hooks/index.d.ts +3 -0
  24. package/dist/types/registry/hooks/oauth-code.d.ts +8 -0
  25. package/dist/types/registry/hooks/types.d.ts +44 -0
  26. package/dist/types/registry/oauth/alibaba-coding-plan.d.ts +2 -0
  27. package/dist/types/registry/{alibaba-token-plan.d.ts → oauth/alibaba-token-plan.d.ts} +1 -6
  28. package/dist/types/registry/oauth/anthropic.d.ts +24 -16
  29. package/dist/types/registry/oauth/cloudflare-ai-gateway.d.ts +3 -0
  30. package/dist/types/registry/oauth/coreweave.d.ts +1 -0
  31. package/dist/types/registry/oauth/cursor.d.ts +3 -1
  32. package/dist/types/registry/oauth/github-copilot.d.ts +5 -2
  33. package/dist/types/registry/oauth/gitlab-duo.d.ts +3 -3
  34. package/dist/types/registry/oauth/google-antigravity.d.ts +3 -7
  35. package/dist/types/registry/oauth/google-gemini-cli.d.ts +3 -6
  36. package/dist/types/registry/oauth/google-oauth-shared.d.ts +0 -24
  37. package/dist/types/registry/oauth/kilo.d.ts +2 -0
  38. package/dist/types/registry/oauth/kimi.d.ts +0 -9
  39. package/dist/types/registry/oauth/openai-codex.d.ts +6 -13
  40. package/dist/types/registry/oauth/xai-oauth.d.ts +5 -10
  41. package/dist/types/registry/oauth/xiaomi.d.ts +2 -10
  42. package/dist/types/registry/oauth/zai.d.ts +3 -15
  43. package/dist/types/registry/registry.d.ts +9 -386
  44. package/dist/types/registry/types.d.ts +12 -9
  45. package/dist/types/types.d.ts +2 -0
  46. package/dist/types/usage.d.ts +12 -0
  47. package/dist/types/utils/http-inspector.d.ts +3 -4
  48. package/dist/types/utils/leaked-thinking-stream.d.ts +6 -0
  49. package/dist/types/utils/thinking-loop.d.ts +1 -1
  50. package/package.json +5 -5
  51. package/src/auth-gateway/server.ts +7 -2
  52. package/src/auth-storage.ts +315 -78
  53. package/src/dialect/owned-stream.ts +3 -0
  54. package/src/dialect/thinking.ts +44 -7
  55. package/src/dialect/types.ts +8 -0
  56. package/src/error/flags.ts +0 -45
  57. package/src/error/retryable.ts +3 -12
  58. package/src/index.ts +0 -1
  59. package/src/providers/anthropic.ts +2 -28
  60. package/src/providers/cursor-external-tool-handoff.md +1 -0
  61. package/src/providers/cursor.ts +32 -1
  62. package/src/providers/github-copilot-headers.ts +7 -2
  63. package/src/providers/google-shared.ts +11 -9
  64. package/src/providers/openai-codex-responses.ts +1 -3
  65. package/src/providers/openai-completions.ts +2 -6
  66. package/src/providers/openai-responses.ts +34 -41
  67. package/src/registry/amazon-bedrock.ts +5 -8
  68. package/src/registry/bedrock-mantle.ts +5 -8
  69. package/src/registry/build.ts +73 -0
  70. package/src/registry/cloudflare-ai-gateway.ts +4 -44
  71. package/src/registry/engine/api-key.ts +109 -0
  72. package/src/registry/engine/common.ts +306 -0
  73. package/src/registry/engine/device-code.ts +131 -0
  74. package/src/registry/engine/oauth-code.ts +227 -0
  75. package/src/registry/engine/refresh.ts +105 -0
  76. package/src/registry/hooks/api-key.ts +19 -0
  77. package/src/registry/hooks/custom.ts +15 -0
  78. package/src/registry/hooks/device-code.ts +13 -0
  79. package/src/registry/hooks/env.ts +42 -0
  80. package/src/registry/hooks/index.ts +21 -0
  81. package/src/registry/hooks/oauth-code.ts +18 -0
  82. package/src/registry/hooks/types.ts +53 -0
  83. package/src/registry/{alibaba-coding-plan.ts → oauth/alibaba-coding-plan.ts} +3 -11
  84. package/src/registry/{alibaba-token-plan.ts → oauth/alibaba-token-plan.ts} +3 -10
  85. package/src/registry/oauth/anthropic.ts +39 -272
  86. package/src/registry/oauth/cloudflare-ai-gateway.ts +39 -0
  87. package/src/registry/oauth/coreweave.ts +16 -0
  88. package/src/registry/oauth/cursor.ts +12 -1
  89. package/src/registry/oauth/github-copilot.ts +37 -21
  90. package/src/registry/oauth/gitlab-duo.ts +6 -219
  91. package/src/registry/oauth/google-antigravity.ts +32 -66
  92. package/src/registry/oauth/google-gemini-cli.ts +31 -65
  93. package/src/registry/oauth/google-oauth-shared.ts +0 -143
  94. package/src/registry/oauth/index.ts +28 -39
  95. package/src/registry/{kilo.ts → oauth/kilo.ts} +2 -9
  96. package/src/registry/oauth/kimi.ts +1 -246
  97. package/src/registry/oauth/openai-codex.ts +28 -109
  98. package/src/registry/oauth/xai-oauth.ts +7 -327
  99. package/src/registry/oauth/xiaomi.ts +9 -60
  100. package/src/registry/oauth/zai.ts +6 -100
  101. package/src/registry/registry.ts +32 -173
  102. package/src/registry/types.ts +12 -9
  103. package/src/stream.ts +1 -0
  104. package/src/types.ts +2 -0
  105. package/src/usage/github-copilot.ts +2 -2
  106. package/src/usage/google-antigravity.ts +43 -2
  107. package/src/usage.ts +9 -0
  108. package/src/utils/empty-completion-retry.ts +0 -1
  109. package/src/utils/http-inspector.ts +3 -8
  110. package/src/utils/leaked-thinking-stream.ts +37 -7
  111. package/src/utils/stream-markup-healing.ts +1 -0
  112. package/src/utils/thinking-loop.ts +1 -1
  113. package/dist/types/registry/aiand.d.ts +0 -7
  114. package/dist/types/registry/aimlapi.d.ts +0 -4
  115. package/dist/types/registry/alibaba-coding-plan.d.ts +0 -8
  116. package/dist/types/registry/anthropic.d.ts +0 -10
  117. package/dist/types/registry/api-key-login.d.ts +0 -48
  118. package/dist/types/registry/azure.d.ts +0 -4
  119. package/dist/types/registry/baseten.d.ts +0 -7
  120. package/dist/types/registry/cerebras.d.ts +0 -7
  121. package/dist/types/registry/cline-pass.d.ts +0 -7
  122. package/dist/types/registry/coreweave.d.ts +0 -7
  123. package/dist/types/registry/cursor.d.ts +0 -7
  124. package/dist/types/registry/deepinfra.d.ts +0 -6
  125. package/dist/types/registry/deepseek.d.ts +0 -8
  126. package/dist/types/registry/devin.d.ts +0 -8
  127. package/dist/types/registry/exa.d.ts +0 -8
  128. package/dist/types/registry/firepass.d.ts +0 -16
  129. package/dist/types/registry/fireworks.d.ts +0 -7
  130. package/dist/types/registry/github-copilot.d.ts +0 -7
  131. package/dist/types/registry/gitlab-duo-workflow.d.ts +0 -10
  132. package/dist/types/registry/gitlab-duo.d.ts +0 -9
  133. package/dist/types/registry/gmi-cloud.d.ts +0 -7
  134. package/dist/types/registry/google-antigravity.d.ts +0 -9
  135. package/dist/types/registry/google-gemini-cli.d.ts +0 -9
  136. package/dist/types/registry/google-vertex.d.ts +0 -5
  137. package/dist/types/registry/google.d.ts +0 -4
  138. package/dist/types/registry/groq.d.ts +0 -4
  139. package/dist/types/registry/huggingface.d.ts +0 -7
  140. package/dist/types/registry/kagi.d.ts +0 -14
  141. package/dist/types/registry/kilo.d.ts +0 -7
  142. package/dist/types/registry/kimi-code.d.ts +0 -7
  143. package/dist/types/registry/litellm.d.ts +0 -13
  144. package/dist/types/registry/llama-cpp.d.ts +0 -8
  145. package/dist/types/registry/lm-studio.d.ts +0 -8
  146. package/dist/types/registry/meta.d.ts +0 -7
  147. package/dist/types/registry/minimax-code-cn.d.ts +0 -6
  148. package/dist/types/registry/minimax-code.d.ts +0 -6
  149. package/dist/types/registry/minimax.d.ts +0 -4
  150. package/dist/types/registry/mistral.d.ts +0 -4
  151. package/dist/types/registry/moonshot.d.ts +0 -7
  152. package/dist/types/registry/nanogpt.d.ts +0 -7
  153. package/dist/types/registry/novita.d.ts +0 -6
  154. package/dist/types/registry/nvidia.d.ts +0 -7
  155. package/dist/types/registry/oauth/devin.d.ts +0 -5
  156. package/dist/types/registry/oauth/gitlab-duo-workflow.d.ts +0 -6
  157. package/dist/types/registry/oauth/minimax-code.d.ts +0 -27
  158. package/dist/types/registry/oauth/opencode.d.ts +0 -25
  159. package/dist/types/registry/oauth/openrouter.d.ts +0 -36
  160. package/dist/types/registry/oauth/wafer.d.ts +0 -1
  161. package/dist/types/registry/ollama-cloud.d.ts +0 -7
  162. package/dist/types/registry/ollama.d.ts +0 -12
  163. package/dist/types/registry/openai-codex-device.d.ts +0 -8
  164. package/dist/types/registry/openai-codex.d.ts +0 -9
  165. package/dist/types/registry/openai.d.ts +0 -4
  166. package/dist/types/registry/opencode-go.d.ts +0 -6
  167. package/dist/types/registry/opencode-zen.d.ts +0 -6
  168. package/dist/types/registry/openrouter.d.ts +0 -14
  169. package/dist/types/registry/parallel.d.ts +0 -14
  170. package/dist/types/registry/perplexity.d.ts +0 -7
  171. package/dist/types/registry/qianfan.d.ts +0 -7
  172. package/dist/types/registry/qwen-portal.d.ts +0 -7
  173. package/dist/types/registry/sakana.d.ts +0 -7
  174. package/dist/types/registry/siliconflow-cn.d.ts +0 -7
  175. package/dist/types/registry/siliconflow.d.ts +0 -7
  176. package/dist/types/registry/synthetic.d.ts +0 -6
  177. package/dist/types/registry/tavily.d.ts +0 -14
  178. package/dist/types/registry/together.d.ts +0 -6
  179. package/dist/types/registry/umans.d.ts +0 -7
  180. package/dist/types/registry/venice.d.ts +0 -13
  181. package/dist/types/registry/vercel-ai-gateway.d.ts +0 -7
  182. package/dist/types/registry/vllm.d.ts +0 -7
  183. package/dist/types/registry/wafer-serverless.d.ts +0 -6
  184. package/dist/types/registry/xai-oauth.d.ts +0 -7
  185. package/dist/types/registry/xai.d.ts +0 -7
  186. package/dist/types/registry/xiaomi-token-plan-ams.d.ts +0 -6
  187. package/dist/types/registry/xiaomi-token-plan-cn.d.ts +0 -6
  188. package/dist/types/registry/xiaomi-token-plan-sgp.d.ts +0 -6
  189. package/dist/types/registry/xiaomi.d.ts +0 -6
  190. package/dist/types/registry/yolo-auto.d.ts +0 -15
  191. package/dist/types/registry/zai.d.ts +0 -15
  192. package/dist/types/registry/zenmux.d.ts +0 -7
  193. package/dist/types/registry/zhipu-coding-plan.d.ts +0 -7
  194. package/dist/types/utils/retry.d.ts +0 -14
  195. package/src/registry/aiand.ts +0 -22
  196. package/src/registry/aimlapi.ts +0 -6
  197. package/src/registry/anthropic.ts +0 -26
  198. package/src/registry/api-key-login.ts +0 -135
  199. package/src/registry/azure.ts +0 -6
  200. package/src/registry/baseten.ts +0 -22
  201. package/src/registry/cerebras.ts +0 -23
  202. package/src/registry/cline-pass.ts +0 -27
  203. package/src/registry/coreweave.ts +0 -40
  204. package/src/registry/cursor.ts +0 -20
  205. package/src/registry/deepinfra.ts +0 -24
  206. package/src/registry/deepseek.ts +0 -46
  207. package/src/registry/devin.ts +0 -15
  208. package/src/registry/exa.ts +0 -19
  209. package/src/registry/firepass.ts +0 -32
  210. package/src/registry/fireworks.ts +0 -28
  211. package/src/registry/github-copilot.ts +0 -22
  212. package/src/registry/gitlab-duo-workflow.ts +0 -20
  213. package/src/registry/gitlab-duo.ts +0 -19
  214. package/src/registry/gmi-cloud.ts +0 -22
  215. package/src/registry/google-antigravity.ts +0 -22
  216. package/src/registry/google-gemini-cli.ts +0 -22
  217. package/src/registry/google-vertex.ts +0 -38
  218. package/src/registry/google.ts +0 -6
  219. package/src/registry/groq.ts +0 -6
  220. package/src/registry/huggingface.ts +0 -29
  221. package/src/registry/kagi.ts +0 -28
  222. package/src/registry/kimi-code.ts +0 -17
  223. package/src/registry/litellm.ts +0 -27
  224. package/src/registry/llama-cpp.ts +0 -25
  225. package/src/registry/lm-studio.ts +0 -20
  226. package/src/registry/meta.ts +0 -22
  227. package/src/registry/minimax-code-cn.ts +0 -12
  228. package/src/registry/minimax-code.ts +0 -12
  229. package/src/registry/minimax.ts +0 -6
  230. package/src/registry/mistral.ts +0 -6
  231. package/src/registry/moonshot.ts +0 -28
  232. package/src/registry/nanogpt.ts +0 -22
  233. package/src/registry/novita.ts +0 -25
  234. package/src/registry/nvidia.ts +0 -61
  235. package/src/registry/oauth/devin.ts +0 -124
  236. package/src/registry/oauth/gitlab-duo-workflow.ts +0 -146
  237. package/src/registry/oauth/minimax-code.ts +0 -53
  238. package/src/registry/oauth/opencode.ts +0 -64
  239. package/src/registry/oauth/openrouter.ts +0 -120
  240. package/src/registry/oauth/wafer.ts +0 -24
  241. package/src/registry/ollama-cloud.ts +0 -36
  242. package/src/registry/ollama.ts +0 -43
  243. package/src/registry/openai-codex-device.ts +0 -18
  244. package/src/registry/openai-codex.ts +0 -19
  245. package/src/registry/openai.ts +0 -6
  246. package/src/registry/opencode-go.ts +0 -12
  247. package/src/registry/opencode-zen.ts +0 -12
  248. package/src/registry/openrouter.ts +0 -24
  249. package/src/registry/parallel.ts +0 -27
  250. package/src/registry/perplexity.ts +0 -13
  251. package/src/registry/qianfan.ts +0 -28
  252. package/src/registry/qwen-portal.ts +0 -50
  253. package/src/registry/sakana.ts +0 -22
  254. package/src/registry/siliconflow-cn.ts +0 -22
  255. package/src/registry/siliconflow.ts +0 -22
  256. package/src/registry/synthetic.ts +0 -21
  257. package/src/registry/tavily.ts +0 -27
  258. package/src/registry/together.ts +0 -26
  259. package/src/registry/umans.ts +0 -23
  260. package/src/registry/venice.ts +0 -33
  261. package/src/registry/vercel-ai-gateway.ts +0 -20
  262. package/src/registry/vllm.ts +0 -24
  263. package/src/registry/wafer-serverless.ts +0 -12
  264. package/src/registry/xai-oauth.ts +0 -17
  265. package/src/registry/xai.ts +0 -22
  266. package/src/registry/xiaomi-token-plan-ams.ts +0 -12
  267. package/src/registry/xiaomi-token-plan-cn.ts +0 -12
  268. package/src/registry/xiaomi-token-plan-sgp.ts +0 -12
  269. package/src/registry/xiaomi.ts +0 -12
  270. package/src/registry/yolo-auto.ts +0 -30
  271. package/src/registry/zai.ts +0 -41
  272. package/src/registry/zenmux.ts +0 -22
  273. package/src/registry/zhipu-coding-plan.ts +0 -27
  274. package/src/utils/retry.ts +0 -77
package/CHANGELOG.md CHANGED
@@ -2,6 +2,26 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [18.1.5] - 2026-09-03
6
+
7
+ ### Added
8
+
9
+ - Added `/login abliteration` with API key validation against `/v1/models`, supporting the `ABLITERATION_API_KEY` and `ABLIT_KEY` environment variables.
10
+
11
+ ### Changed
12
+
13
+ - Modernized provider authentication and token refresh across the catalog, with shared support for API-key, authorization-code, and device-code sign-in flows and clearer sign-in progress messages for OpenRouter, Kimi, and xAI.
14
+
15
+ ### Fixed
16
+
17
+ - GitHub Copilot now uses the official Copilot CLI identity and OAuth application for requests and new sign-ins, restoring access to client-gated models while preserving existing credentials.
18
+ - GitHub Copilot now reports `model_not_supported` responses immediately instead of repeatedly retrying unsupported models.
19
+ - Improved account recovery after Google rate limits are lifted earlier than the reported reset time.
20
+ - Fixed unmetered autocomplete models being reported as exhausted when quota is limited.
21
+ - Fixed Gemini 3 cross-model sessions in Cloud Code Assist when replaying tool calls without a thought signature.
22
+ - Fixed Cursor models behind an authentication gateway incorrectly retrying valid client-declared tool calls.
23
+ - Fixed reasoning from models that prefill `<think>` (including DeepSeek-R1 and hosted Qwen3-Thinking) being shown in the response instead of as a separate thinking block.
24
+
5
25
  ## [18.1.3] - 2026-09-02
6
26
 
7
27
  ### Fixed
package/README.md CHANGED
@@ -1090,56 +1090,31 @@ For the current API-key onboarding flows, the library covers Together, Moonshot,
1090
1090
 
1091
1091
  ### Programmatic OAuth
1092
1092
 
1093
- The library provides login and token refresh functions. Credential storage is the caller's responsibility.
1093
+ Provider login and refresh behavior is exposed through the registry. Credential storage is the caller's responsibility.
1094
1094
 
1095
1095
  ```typescript
1096
1096
  import {
1097
- // Login functions (return credentials, do not store)
1098
- loginAnthropic,
1099
- loginOpenAICodex,
1100
- loginGitHubCopilot,
1101
- loginGeminiCli,
1102
- loginAntigravity,
1103
- loginCloudflareAiGateway,
1104
- loginHuggingface,
1105
- loginLiteLLM,
1106
- loginMoonshot,
1107
- loginNvidia,
1108
- loginNanoGPT,
1109
- loginQianfan,
1110
- loginQwenPortal,
1111
- loginTogether,
1112
- loginVenice,
1113
- loginVllm,
1114
- loginXiaomi,
1115
-
1116
- // Token management
1097
+ getProviderDefinition,
1117
1098
  refreshOAuthToken, // (provider, credentials) => new credentials
1118
1099
  getOAuthApiKey, // (provider, credentialsMap) => { newCredentials, apiKey } | null
1119
-
1120
- // Types
1121
- type OAuthProvider, // includes 'anthropic', 'openai-codex', 'github-copilot', 'google-gemini-cli', 'google-antigravity', 'together', 'moonshot', 'qianfan', 'nvidia', 'nanogpt', 'novita', 'huggingface', 'venice', 'xiaomi', 'vllm', 'litellm', 'cloudflare-ai-gateway', 'qwen-portal', ...
1100
+ type OAuthProvider,
1122
1101
  type OAuthCredentials,
1123
1102
  } from "@oh-my-pi/pi-ai";
1124
- ```
1125
1103
 
1126
- `loginOpenAICodex` accepts an optional `originator` value used in the OAuth flow:
1127
-
1128
- ```typescript
1129
- await loginOpenAICodex({
1104
+ const provider = getProviderDefinition("openai-codex");
1105
+ const credentials = await provider?.login?.({
1130
1106
  onAuth: ({ url }) => console.log(url),
1131
- originator: "my-cli",
1132
1107
  });
1133
1108
  ```
1134
1109
 
1135
1110
  ### Login Flow Example
1136
1111
 
1137
1112
  ```typescript
1138
- import { loginGitHubCopilot } from "@oh-my-pi/pi-ai";
1113
+ import { getProviderDefinition } from "@oh-my-pi/pi-ai";
1139
1114
  import * as fs from "node:fs";
1140
1115
 
1141
- const credentials = await loginGitHubCopilot({
1142
- onAuth: (url, instructions) => {
1116
+ const credentials = await getProviderDefinition("github-copilot")?.login?.({
1117
+ onAuth: ({ url, instructions }) => {
1143
1118
  console.log(`Open: ${url}`);
1144
1119
  if (instructions) console.log(instructions);
1145
1120
  },
@@ -1,6 +1,15 @@
1
1
  import type { InbandScanEvent, InbandScanner } from "./types.js";
2
+ export interface ThinkingInbandScannerOptions {
3
+ /**
4
+ * Report a bare reasoning close tag (no open seen) as an `impliedThinkingEnd`
5
+ * event instead of passing it through as text. Off by default: only a
6
+ * consumer that owns the whole message can reclassify the text before it.
7
+ */
8
+ readonly impliedOpen?: boolean;
9
+ }
2
10
  export declare class ThinkingInbandScanner implements InbandScanner {
3
11
  #private;
12
+ constructor(options?: ThinkingInbandScannerOptions);
4
13
  feed(text: string): InbandScanEvent[];
5
14
  flush(): InbandScanEvent[];
6
15
  }
@@ -12,6 +12,16 @@ export type InbandScanEvent = {
12
12
  } | {
13
13
  type: "thinkingEnd";
14
14
  thinking: string;
15
+ }
16
+ /**
17
+ * A reasoning close tag with no open in this stream. Chat templates that
18
+ * prefill the opener into the prompt (DeepSeek-R1, Qwen3-Thinking) make the
19
+ * model stream only the close, so everything emitted as `text` before this
20
+ * event was reasoning. Only {@link ThinkingInbandScanner} with `impliedOpen`
21
+ * emits it.
22
+ */
23
+ | {
24
+ type: "impliedThinkingEnd";
15
25
  } | {
16
26
  type: "toolStart";
17
27
  id: string;
@@ -87,13 +87,6 @@ export declare function isFastModeUnsupported(error: unknown): boolean;
87
87
  * fail identically) nor surface as an auth failure.
88
88
  */
89
89
  export declare function isClinePassSurfaceGateMessage(errorMessage: string | undefined): boolean;
90
- /**
91
- * GitHub Copilot 400 `model_not_supported` response for a model advertised by
92
- * `/models` — transient fleet skew, not a malformed request. Reads the
93
- * structural `code` through the SDK/body envelopes, then falls back to the
94
- * stringified body both SDK families put in `message`.
95
- */
96
- export declare function isCopilotTransientModelError(error: unknown): boolean;
97
90
  export declare function classifyMessage(message: {
98
91
  api?: Api;
99
92
  provider?: string;
@@ -7,13 +7,6 @@
7
7
  * may match more. Use this when you only have a `status: number`.
8
8
  */
9
9
  export declare function isTransientStatus(status: number | undefined): boolean;
10
- /** Hook for provider-specific transient detection that the error module must not import directly. */
11
- export interface ProviderRetryableHooks {
12
- /** Provider id of the failing request, used to gate provider-specific checks. */
13
- provider?: string;
14
- /** Provider-specific transient predicate (e.g. Copilot model-availability 400s). */
15
- isProviderTransient?: (error: Error) => boolean;
16
- }
17
10
  /**
18
11
  * Whether a provider stream error should be retried against the same credential.
19
12
  *
@@ -21,7 +14,7 @@ export interface ProviderRetryableHooks {
21
14
  * here — they are owned by the credential-rotation layer (auth-gateway /
22
15
  * `streamSimple` a/b/c policy), not this seconds-scale provider backoff.
23
16
  *
24
- * Provider-specific transient cases are injected via {@link ProviderRetryableHooks}
25
- * so this stays free of provider imports.
17
+ * Every 4xx other than 408/429 is terminal: a request the provider rejected
18
+ * as malformed, unauthorized, or unentitled fails identically on replay.
26
19
  */
27
- export declare function isProviderRetryableError(error: unknown, hooks?: ProviderRetryableHooks): boolean;
20
+ export declare function isProviderRetryableError(error: unknown): boolean;
@@ -46,7 +46,6 @@ export * from "./utils/anthropic-auth.js";
46
46
  export * from "./utils/event-stream.js";
47
47
  export * from "./utils/glyph-codec.js";
48
48
  export * from "./utils/openrouter-headers.js";
49
- export * from "./utils/retry.js";
50
49
  export * from "./utils/schema/index.js";
51
50
  export * from "./utils/thinking-loop.js";
52
51
  export * from "./utils/tool-call-loop-guard.js";
@@ -188,13 +188,6 @@ export type AnthropicClientOptionsResult = {
188
188
  * omitted there.
189
189
  */
190
190
  export declare function resolveAnthropicCustomHeadersForBaseUrl(baseUrl: string | undefined): Record<string, string> | undefined;
191
- /**
192
- * Whether an Anthropic (or Copilot-over-Anthropic) stream error should be
193
- * retried. The classification lives in {@link AIError.isProviderRetryableError};
194
- * this wrapper injects the Copilot-specific model-availability transient check,
195
- * which the error module must not import directly.
196
- */
197
- export declare function isProviderRetryableError(error: unknown, provider?: string): boolean;
198
191
  export type AnthropicUsageLike = {
199
192
  cache_creation?: {
200
193
  ephemeral_5m_input_tokens?: number | null;
@@ -12,6 +12,8 @@ export interface CursorOptions extends StreamOptions {
12
12
  conversationId?: string;
13
13
  execHandlers?: CursorExecHandlers;
14
14
  onToolResult?: CursorToolResultHandler;
15
+ /** Treat unhandled MCP calls as accepted handoffs to an external executor. */
16
+ externalToolExecutor?: boolean;
15
17
  /** Wire model id selected after thinking-effort routing (`resolveWireModelId`). */
16
18
  wireModelId?: string;
17
19
  }
@@ -104,7 +106,7 @@ export interface UsageState {
104
106
  sawTokenDelta: boolean;
105
107
  }
106
108
  /** Exported for tests: drives one Cursor server message through the stream (exec waits mark the stream busy). */
107
- export declare function handleServerMessage(msg: AgentServerMessage, output: AssistantMessage, stream: AssistantMessageEventStream, state: BlockState, blobStore: Map<string, Uint8Array>, h2Request: http2.ClientHttp2Stream, execHandlers: CursorExecHandlers | undefined, onToolResult: CursorToolResultHandler | undefined, usageState: UsageState, requestContextTools: McpToolDefinition[], requestContextRules?: CursorRule[], onConversationCheckpoint?: (checkpoint: ConversationStateStructure) => void): Promise<void>;
109
+ export declare function handleServerMessage(msg: AgentServerMessage, output: AssistantMessage, stream: AssistantMessageEventStream, state: BlockState, blobStore: Map<string, Uint8Array>, h2Request: http2.ClientHttp2Stream, execHandlers: CursorExecHandlers | undefined, onToolResult: CursorToolResultHandler | undefined, usageState: UsageState, requestContextTools: McpToolDefinition[], requestContextRules?: CursorRule[], onConversationCheckpoint?: (checkpoint: ConversationStateStructure) => void, externalToolExecutor?: boolean): Promise<void>;
108
110
  /**
109
111
  * Exported for tests: verifies handler is invoked with correct `this` when passed as bound.
110
112
  *
@@ -1,10 +1,3 @@
1
- export declare const amazonBedrockProvider: {
2
- readonly id: "amazon-bedrock";
3
- readonly name: "Amazon Bedrock";
4
- readonly envKeys: () => string | undefined;
5
- readonly mapSimpleOptions: (options: import("../index.js").SimpleStreamOptions) => {
6
- region: string | undefined;
7
- profile: string | undefined;
8
- bearerToken: string | undefined;
9
- };
10
- };
1
+ import type { ProviderTransport } from "./build.js";
2
+ /** Amazon Bedrock request shaping; auth policy lives in `rules/auth/amazon-bedrock.kdl`. */
3
+ export declare const amazonBedrockTransport: ProviderTransport;
@@ -1,22 +1,3 @@
1
- import type { Model } from "../types.js";
2
- import { resolveAwsRegistryApiKey } from "./aws.js";
3
- export declare const bedrockMantleProvider: {
4
- readonly id: "bedrock-mantle";
5
- readonly name: "Amazon Bedrock Mantle";
6
- readonly envKeys: typeof resolveAwsRegistryApiKey;
7
- readonly allowsMissingApiKey: true;
8
- readonly prepareRequest: (model: Model<import("@oh-my-pi/pi-catalog").Api>, options: import("../index.js").StreamOptions) => import("../providers/bedrock-mantle.js").PreparedBedrockMantleRequest;
9
- readonly mapSimpleOptions: (options: import("../index.js").SimpleStreamOptions) => {
10
- providerOptions: Readonly<Record<string, unknown>> | undefined;
11
- };
12
- readonly prepareModelDiscovery: (config: import("./types.js").ProviderModelDiscoveryConfig) => {
13
- baseUrl?: string;
14
- fetch?: import("@oh-my-pi/pi-utils").FetchImpl;
15
- apiKey: undefined;
16
- authenticated: false;
17
- } | {
18
- authenticated: true;
19
- baseUrl: string;
20
- fetch: import("@oh-my-pi/pi-utils").FetchImpl;
21
- };
22
- };
1
+ import type { ProviderTransport } from "./build.js";
2
+ /** Bedrock Mantle request/discovery shaping; auth policy lives in `rules/auth/bedrock-mantle.kdl`. */
3
+ export declare const bedrockMantleTransport: ProviderTransport;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Projects one compiled auth policy (`rules/auth/<id>.kdl`) plus the
3
+ * provider's optional TypeScript transport hooks into the
4
+ * {@link ProviderDefinition} the rest of `@oh-my-pi/pi-ai` consumes.
5
+ */
6
+ import type { CompiledAuthProvider } from "@oh-my-pi/pi-catalog/compat/types";
7
+ import type { ProviderDefinition } from "./types.js";
8
+ /** Request/model shaping a provider implements in TypeScript beside its KDL auth policy. */
9
+ export type ProviderTransport = Pick<ProviderDefinition, "prepareModel" | "prepareRequest" | "mapSimpleOptions" | "prepareModelDiscovery">;
10
+ /** Materializes the registry definition for one compiled policy. */
11
+ export declare function buildProviderDefinition(policy: CompiledAuthProvider, transport?: ProviderTransport): ProviderDefinition;
@@ -1,13 +1,3 @@
1
- import type { OAuthController, OAuthLoginCallbacks } from "./oauth/types.js";
2
- /** Collect the gateway credential used by CLI, setup-wizard, and TUI login callers. */
3
- export declare function loginCloudflareAiGateway(options: OAuthController): Promise<string>;
4
- export declare const cloudflareAiGatewayProvider: {
5
- readonly id: "cloudflare-ai-gateway";
6
- readonly name: "Cloudflare AI Gateway";
7
- readonly prepareModel: (model: import("@oh-my-pi/pi-catalog").Model<import("@oh-my-pi/pi-catalog").Api>) => import("@oh-my-pi/pi-catalog").Model<import("@oh-my-pi/pi-catalog").Api>;
8
- readonly prepareRequest: (model: import("@oh-my-pi/pi-catalog").Model<import("@oh-my-pi/pi-catalog").Api>, options: import("../index.js").StreamOptions) => {
9
- model: import("@oh-my-pi/pi-catalog").Model<import("@oh-my-pi/pi-catalog").Api>;
10
- options: import("../index.js").StreamOptions;
11
- };
12
- readonly login: (cb: OAuthLoginCallbacks) => Promise<string>;
13
- };
1
+ import type { ProviderTransport } from "./build.js";
2
+ /** Cloudflare AI Gateway model/request shaping; login lives in `oauth/cloudflare-ai-gateway.ts` + its auth rule. */
3
+ export declare const cloudflareAiGatewayTransport: ProviderTransport;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * `login "api-key"` engine: open the provider's key page, prompt for a paste,
3
+ * optionally validate the key against a declared probe, return the key.
4
+ */
5
+ import type { CompiledApiKeyLogin } from "@oh-my-pi/pi-catalog/compat/types";
6
+ import type { OAuthController } from "../oauth/types.js";
7
+ /** Builds the login function for one `login "api-key"` rule; `label` is the provider display name. */
8
+ export declare function createApiKeyLogin(rule: CompiledApiKeyLogin, label: string): (options: OAuthController) => Promise<string>;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Shared machinery for the declarative login engines: resolving KDL values
3
+ * (env overrides, obfuscation, hooks), `{placeholder}` templating, token
4
+ * endpoint requests and token-response → `OAuthCredentials` projection.
5
+ */
6
+ import type { CompiledAuthValue, CompiledCredentialMap, CompiledOAuthRequest, CompiledUserinfo } from "@oh-my-pi/pi-catalog/compat/types";
7
+ import type { FetchImpl } from "../../types.js";
8
+ import type { AfterExchangeHook, ExchangeContext, HeadersHook, LoginHook, RefreshHook } from "../hooks/types.js";
9
+ import type { OAuthCredentials } from "../oauth/types.js";
10
+ /** Far-future epoch ms: credentials that never expire (durable minted keys, session JWTs). */
11
+ export declare const NEVER_EXPIRES = 8640000000000000;
12
+ /** Substitution values available to `{placeholder}` templates in KDL params/URLs. */
13
+ export type TemplateVars = Record<string, string | undefined>;
14
+ export declare function loadLoginHook(name: string): Promise<LoginHook>;
15
+ export declare function loadRefreshHook(name: string): Promise<RefreshHook>;
16
+ export declare function loadAfterExchangeHook(name: string): Promise<AfterExchangeHook>;
17
+ export declare function loadHeadersHook(name: string): Promise<HeadersHook>;
18
+ /** Resolves a KDL value node: env overrides first, then the (possibly encoded) literal or hook. */
19
+ export declare function resolveValue(value: CompiledAuthValue, signal?: AbortSignal): Promise<string>;
20
+ /** Replaces `{name}` placeholders; unknown or undefined placeholders resolve to the empty string. */
21
+ export declare function template(text: string, vars: TemplateVars): string;
22
+ /** Reads a dot path (`data.user.email`) from a parsed JSON body. */
23
+ export declare function jsonPath(body: unknown, path: string): unknown;
24
+ /** Decodes a JWT payload without verification; `null` for malformed tokens. */
25
+ export declare function decodeJwtPayload(token: string): Record<string, unknown> | null;
26
+ /** Epoch ms of a JWT `exp` claim minus `skewMs`, or undefined when absent. */
27
+ export declare function jwtExpiryMs(token: string, skewMs: number): number | undefined;
28
+ /**
29
+ * Projects a token response onto `OAuthCredentials` per the rule's
30
+ * `credential` map. A missing refresh token keeps `previous.refresh` (refresh
31
+ * grants that do not rotate) or falls back to the empty string.
32
+ */
33
+ export declare function mapCredentials(map: CompiledCredentialMap, body: unknown, provider: string, previous?: OAuthCredentials): OAuthCredentials;
34
+ export interface RequestContext {
35
+ provider: string;
36
+ fetch: FetchImpl;
37
+ signal?: AbortSignal;
38
+ /** Extra headers merged under the rule's declared headers. */
39
+ headers?: Record<string, string>;
40
+ }
41
+ /**
42
+ * Performs one declared token-style POST. `standardParams` are the grant's
43
+ * baseline (included when the rule keeps `standard=#true`), `params` the
44
+ * rule's declared extras; both are templated with `vars`.
45
+ */
46
+ export declare function postTokenRequest(request: CompiledOAuthRequest, standardParams: Record<string, string | undefined>, vars: TemplateVars, context: RequestContext, errorKind: "token-exchange" | "token-refresh" | "device-auth"): Promise<{
47
+ body: unknown;
48
+ response: Response;
49
+ }>;
50
+ /** Bearer GET declared by `userinfo`; failures leave identity fields unset. */
51
+ export declare function applyUserinfo(userinfo: CompiledUserinfo | undefined, credentials: OAuthCredentials, context: RequestContext): Promise<OAuthCredentials>;
52
+ /** Runs the rule's after-exchange / after-refresh hook, if declared. */
53
+ export declare function applyAfterExchange(hook: string | undefined, credentials: OAuthCredentials, context: ExchangeContext): Promise<OAuthCredentials>;
54
+ export declare function describeError(error: unknown): string;
55
+ export declare function throwIfCancelled(signal: AbortSignal | undefined): void;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `login "device-code"` engine: RFC 8628 device authorization — request a
3
+ * user code, show the verification URL, poll the token endpoint until the
4
+ * grant completes, then project / enrich the credentials.
5
+ */
6
+ import type { CompiledDeviceCodeLogin } from "@oh-my-pi/pi-catalog/compat/types";
7
+ import type { OAuthController, OAuthCredentials } from "../oauth/types.js";
8
+ /** Builds the login function for one `login "device-code"` rule. */
9
+ export declare function createDeviceCodeLogin(rule: CompiledDeviceCodeLogin, provider: string): (ctrl: OAuthController) => Promise<OAuthCredentials>;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `login "oauth-code"` engine: authorization-code grant (optionally PKCE)
3
+ * through the loopback callback server, followed by the declared token
4
+ * exchange, credential projection, userinfo enrichment and after-exchange hook.
5
+ */
6
+ import type { CompiledAuthProvider, CompiledCallback, CompiledOAuthCodeLogin } from "@oh-my-pi/pi-catalog/compat/types";
7
+ import { OAuthCallbackFlow, type OAuthCallbackFlowOptions } from "../oauth/callback-server.js";
8
+ import type { OAuthController, OAuthCredentials } from "../oauth/types.js";
9
+ /**
10
+ * Callback-server options for a rule. A `redirect-uri-env` override is
11
+ * advertised verbatim with random-port fallback disabled; HTTP loopback
12
+ * overrides also bind the listener to the URI's host/port/path.
13
+ */
14
+ export declare function resolveCallbackOptions(callback: CompiledCallback, provider: string, signal?: AbortSignal): Promise<OAuthCallbackFlowOptions>;
15
+ /** Generic authorization-code flow driven by one compiled rule. */
16
+ export declare class DeclarativeOAuthCodeFlow extends OAuthCallbackFlow {
17
+ #private;
18
+ constructor(ctrl: OAuthController, rule: CompiledOAuthCodeLogin, policy: CompiledAuthProvider, options: OAuthCallbackFlowOptions);
19
+ generateState(): string;
20
+ generateAuthUrl(state: string, redirectUri: string): Promise<{
21
+ url: string;
22
+ instructions?: string;
23
+ }>;
24
+ exchangeToken(code: string, state: string, redirectUri: string): Promise<OAuthCredentials>;
25
+ }
26
+ /** Builds the login function for one `login "oauth-code"` rule. */
27
+ export declare function createOAuthCodeLogin(rule: CompiledOAuthCodeLogin, policy: CompiledAuthProvider): (ctrl: OAuthController) => Promise<OAuthCredentials>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `refresh { … }` engine: refresh-token grant against the declared token
3
+ * endpoint. Unrotated refresh tokens are preserved; identity fields the
4
+ * response omits are left for the caller to merge from the stored row.
5
+ */
6
+ import type { CompiledAuthProvider } from "@oh-my-pi/pi-catalog/compat/types";
7
+ import type { OAuthCredentials } from "../oauth/types.js";
8
+ type Refresher = (credentials: OAuthCredentials, signal?: AbortSignal) => Promise<OAuthCredentials>;
9
+ /** The refresh function for a provider policy, or undefined when it never refreshes. */
10
+ export declare function createRefresh(policy: CompiledAuthProvider): Refresher | undefined;
11
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Hooks referenced by API-key style rules: `headers-hook` resolvers for
3
+ * `validate "models-endpoint"` probes needing computed headers, and
4
+ * `login "custom"` flows that paste keys but need region/endpoint prompts.
5
+ */
6
+ import type { HeadersHook, Lazy, LoginHook } from "./types.js";
7
+ export declare const API_KEY_HEADERS_HOOKS: Record<string, Lazy<HeadersHook>>;
8
+ export declare const API_KEY_LOGIN_HOOKS: Record<string, Lazy<LoginHook>>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Whole-flow hooks: `login "custom" hook=…` and `refresh hook=…` for providers
3
+ * whose flow is not expressible in the declarative grammar.
4
+ */
5
+ import type { Lazy, LoginHook, RefreshHook } from "./types.js";
6
+ export declare const CUSTOM_LOGIN_HOOKS: Record<string, Lazy<LoginHook>>;
7
+ export declare const CUSTOM_REFRESH_HOOKS: Record<string, Lazy<RefreshHook>>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Hooks referenced by `login "device-code"` rules: fingerprint headers,
3
+ * discovered endpoints and post-exchange identity steps.
4
+ */
5
+ import type { AfterExchangeHook, HeadersHook, Lazy, ValueHook } from "./types.js";
6
+ export declare const DEVICE_CODE_HEADERS_HOOKS: Record<string, Lazy<HeadersHook>>;
7
+ export declare const DEVICE_CODE_VALUE_HOOKS: Record<string, Lazy<ValueHook>>;
8
+ export declare const DEVICE_CODE_AFTER_EXCHANGE_HOOKS: Record<string, Lazy<AfterExchangeHook>>;
@@ -0,0 +1,2 @@
1
+ import type { EnvHook } from "./types.js";
2
+ export declare const ENV_HOOKS: Record<string, EnvHook>;
@@ -0,0 +1,3 @@
1
+ import type { HookTables } from "./types.js";
2
+ export declare const HOOKS: HookTables;
3
+ export type * from "./types.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Hooks referenced by `login "oauth-code"` rules: post-exchange identity /
3
+ * provisioning steps and runtime-resolved values.
4
+ */
5
+ import type { AfterExchangeHook, Lazy, LoginHook, ValueHook } from "./types.js";
6
+ export declare const OAUTH_CODE_AFTER_EXCHANGE_HOOKS: Record<string, Lazy<AfterExchangeHook>>;
7
+ export declare const OAUTH_CODE_VALUE_HOOKS: Record<string, Lazy<ValueHook>>;
8
+ export declare const OAUTH_CODE_LOGIN_HOOKS: Record<string, Lazy<LoginHook>>;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Hook contracts referenced by name from `rules/auth/*.kdl`. A hook is the
3
+ * escape hatch for the part of a login flow that is not declarative
4
+ * (identity lookups, project provisioning, key minting, bespoke polling).
5
+ * Names are validated against the compiled rule tree by
6
+ * `test/auth-hooks-registry.test.ts`.
7
+ */
8
+ import type { FetchImpl } from "../../types.js";
9
+ import type { OAuthController, OAuthCredentials, OAuthPrompt } from "../oauth/types.js";
10
+ /** Whole-flow login implementation (`login "custom" hook=…`); rejects a bare controller at runtime when it needs prompts. */
11
+ export type LoginHook = (callbacks: OAuthController) => Promise<OAuthCredentials | string>;
12
+ /** Whole-flow refresh implementation (`refresh hook=…`). */
13
+ export type RefreshHook = (credentials: OAuthCredentials, signal?: AbortSignal) => Promise<OAuthCredentials>;
14
+ /** Runtime context handed to `after-exchange` / `after-refresh` hooks. */
15
+ export interface ExchangeContext {
16
+ provider: string;
17
+ phase: "login" | "refresh";
18
+ /** Parsed JSON body of the token response. */
19
+ raw: unknown;
20
+ fetch: FetchImpl;
21
+ signal?: AbortSignal;
22
+ onProgress?: (message: string) => void;
23
+ onPrompt?: (prompt: OAuthPrompt) => Promise<string>;
24
+ /** Credential being refreshed (refresh phase only). */
25
+ stored?: OAuthCredentials;
26
+ }
27
+ /** Enrich or replace the engine-mapped credentials after a token exchange. */
28
+ export type AfterExchangeHook = (credentials: OAuthCredentials, context: ExchangeContext) => Promise<OAuthCredentials>;
29
+ /** Extra request headers (`headers-hook`); may throw a configuration error. */
30
+ export type HeadersHook = () => Record<string, string> | undefined;
31
+ /** Computed env-var fallback (`env hook=…`); must stay synchronous. */
32
+ export type EnvHook = () => string | undefined;
33
+ /** Runtime-resolved string setting (`url-hook=` / `hook=` on a value node). */
34
+ export type ValueHook = (signal?: AbortSignal) => Promise<string>;
35
+ /** Lazily loaded hook: keeps heavy flow modules out of the eager registry graph. */
36
+ export type Lazy<T> = () => Promise<T>;
37
+ export interface HookTables {
38
+ env: Record<string, EnvHook>;
39
+ headers: Record<string, Lazy<HeadersHook>>;
40
+ value: Record<string, Lazy<ValueHook>>;
41
+ login: Record<string, Lazy<LoginHook>>;
42
+ refresh: Record<string, Lazy<RefreshHook>>;
43
+ afterExchange: Record<string, Lazy<AfterExchangeHook>>;
44
+ }
@@ -0,0 +1,2 @@
1
+ import type { OAuthController, OAuthCredentials } from "./types.js";
2
+ export declare function loginAlibabaCodingPlan(options: OAuthController): Promise<OAuthCredentials>;
@@ -1,4 +1,4 @@
1
- import type { OAuthController, OAuthLoginCallbacks } from "./oauth/types.js";
1
+ import type { OAuthController } from "./types.js";
2
2
  /**
3
3
  * Log in to the QwenCloud Token Plan provider.
4
4
  *
@@ -11,8 +11,3 @@ import type { OAuthController, OAuthLoginCallbacks } from "./oauth/types.js";
11
11
  * both target it (#6682).
12
12
  */
13
13
  export declare function loginAlibabaTokenPlan(options: OAuthController): Promise<string>;
14
- export declare const alibabaTokenPlanProvider: {
15
- readonly id: "alibaba-token-plan";
16
- readonly name: "QwenCloud Token Plan";
17
- readonly login: (cb: OAuthLoginCallbacks) => Promise<string>;
18
- };
@@ -1,24 +1,32 @@
1
1
  /**
2
- * Anthropic OAuth flow (Claude Pro/Max)
2
+ * Anthropic (Claude Pro/Max) sign-in residue. The OAuth flow itself is
3
+ * declared in `rules/auth/anthropic.kdl`; this module supplies the
4
+ * `anthropic-identity` after-exchange hook that recovers account /
5
+ * organization identity from `/api/claude_cli/bootstrap` when the token
6
+ * response omits it.
3
7
  */
4
8
  import type { FetchImpl } from "../../types.js";
5
- import { OAuthCallbackFlow } from "./callback-server.js";
6
- import type { OAuthController, OAuthCredentials } from "./types.js";
9
+ import type { AfterExchangeHook } from "../hooks/types.js";
7
10
  export { ANTHROPIC_OAUTH_GRANT_TTL_MS } from "./anthropic-constants.js";
8
- export declare class AnthropicOAuthFlow extends OAuthCallbackFlow {
9
- #private;
10
- constructor(ctrl: OAuthController);
11
- generateAuthUrl(state: string, redirectUri: string): Promise<{
12
- url: string;
13
- instructions?: string;
14
- }>;
15
- exchangeToken(code: string, state: string, redirectUri: string): Promise<OAuthCredentials>;
16
- }
17
11
  /**
18
- * Login with Anthropic OAuth
12
+ * Account + organization identity slice resolved from the
13
+ * `/api/claude_cli/bootstrap` endpoint. The organization is the subscription
14
+ * workspace the token draws limits from — one account email can hold several
15
+ * (e.g. a Team seat plus a personal Max plan).
19
16
  */
20
- export declare function loginAnthropic(ctrl: OAuthController): Promise<OAuthCredentials>;
17
+ interface AnthropicIdentity {
18
+ accountId?: string;
19
+ email?: string;
20
+ orgId?: string;
21
+ orgName?: string;
22
+ }
23
+ /** Fetches the signed-in account/org identity Claude Code's CLI bootstrap reports. */
24
+ export declare function fetchAnthropicBootstrapIdentity(accessToken: string, fetchImpl: FetchImpl): Promise<AnthropicIdentity>;
21
25
  /**
22
- * Refresh Anthropic OAuth token
26
+ * `anthropic-identity` hook: fills account (and, at login only, organization)
27
+ * identity from the bootstrap endpoint when the token response left it
28
+ * unset. The org an access token is scoped to is captured once at login and
29
+ * deliberately never refreshed — rewriting identity during background
30
+ * refreshes could silently re-key stored credentials.
23
31
  */
24
- export declare function refreshAnthropicToken(refreshToken: string, fetchOverride?: FetchImpl): Promise<OAuthCredentials>;
32
+ export declare const anthropicIdentityHook: AfterExchangeHook;
@@ -0,0 +1,3 @@
1
+ import type { OAuthController } from "./types.js";
2
+ /** Collect the gateway credential used by CLI, setup-wizard, and TUI login callers. */
3
+ export declare function loginCloudflareAiGateway(options: OAuthController): Promise<string>;
@@ -0,0 +1 @@
1
+ export declare function requireCoreWeaveProjectHeaders(): Record<string, string>;
@@ -1,4 +1,4 @@
1
- import type { OAuthCredentials } from "./types.js";
1
+ import type { OAuthController, OAuthCredentials } from "./types.js";
2
2
  export interface CursorAuthParams {
3
3
  verifier: string;
4
4
  challenge: string;
@@ -11,6 +11,8 @@ export declare function pollCursorAuth(uuid: string, verifier: string): Promise<
11
11
  refreshToken: string;
12
12
  }>;
13
13
  export declare function loginCursor(onAuthUrl: (url: string) => void, onPollStart?: () => void): Promise<OAuthCredentials>;
14
+ export declare function loginCursorHook(callbacks: OAuthController): Promise<OAuthCredentials>;
14
15
  export declare function refreshCursorToken(apiKeyOrRefreshToken: string): Promise<OAuthCredentials>;
16
+ export declare function refreshCursorHook(credentials: OAuthCredentials): Promise<OAuthCredentials>;
15
17
  export declare function extractCursorAccessTokenUserId(accessToken: string): string | undefined;
16
18
  export declare function isCursorTokenExpiringSoon(token: string, thresholdSeconds?: number): boolean;
@@ -1,5 +1,5 @@
1
1
  import type { FetchImpl } from "../../types.js";
2
- import type { OAuthCredentials } from "./types.js";
2
+ import type { OAuthController, OAuthCredentials } from "./types.js";
3
3
  type GitHubCopilotLoginOptions = {
4
4
  onAuth: (url: string, instructions?: string) => void;
5
5
  onPrompt: (prompt: {
@@ -15,9 +15,11 @@ type GitHubCopilotLoginOptions = {
15
15
  };
16
16
  /**
17
17
  * Refresh GitHub Copilot token.
18
- * With the opencode OAuth flow, the GitHub token is used directly — no JWT exchange needed.
18
+ * GitHub OAuth tokens from both the former OpenCode app and the Copilot CLI app
19
+ * remain directly usable, so existing logins need no token exchange or migration.
19
20
  */
20
21
  export declare function refreshGitHubCopilotToken(refreshToken: string, enterpriseDomain?: string, apiEndpoint?: string): OAuthCredentials;
22
+ export declare function refreshGitHubCopilotHook(credentials: OAuthCredentials): Promise<OAuthCredentials>;
21
23
  /**
22
24
  * Login with GitHub Copilot OAuth (device code flow)
23
25
  *
@@ -27,4 +29,5 @@ export declare function refreshGitHubCopilotToken(refreshToken: string, enterpri
27
29
  * @param options.signal - Optional AbortSignal for cancellation
28
30
  */
29
31
  export declare function loginGitHubCopilot(options: GitHubCopilotLoginOptions): Promise<OAuthCredentials>;
32
+ export declare function loginGitHubCopilotHook(callbacks: OAuthController): Promise<OAuthCredentials>;
30
33
  export {};
@@ -1,3 +1,3 @@
1
- import type { OAuthCredentials, OAuthLoginCallbacks } from "./types.js";
2
- export declare function loginGitLabDuo(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;
3
- export declare function refreshGitLabDuoToken(credentials: OAuthCredentials): Promise<OAuthCredentials>;
1
+ /** GitLab Duo OAuth residue: invalidate direct-access credentials after token rotation. */
2
+ import type { AfterExchangeHook } from "../hooks/types.js";
3
+ export declare const gitLabDuoClearCacheHook: AfterExchangeHook;