@sayknow-cli/ai 0.4.6 → 0.5.0

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 (71) hide show
  1. package/README.md +6 -0
  2. package/dist/types/auth-broker/client.d.ts +2 -1
  3. package/dist/types/auth-broker/remote-store.d.ts +2 -1
  4. package/dist/types/auth-broker/types.d.ts +3 -1
  5. package/dist/types/auth-broker/wire-schemas.d.ts +68 -0
  6. package/dist/types/auth-storage.d.ts +21 -1
  7. package/dist/types/provider-models/openai-compat.d.ts +19 -2
  8. package/dist/types/providers/anthropic.d.ts +11 -1
  9. package/dist/types/providers/azure-openai-responses.d.ts +6 -1
  10. package/dist/types/providers/google-auth.d.ts +2 -0
  11. package/dist/types/providers/google-gemini-headers.d.ts +1 -1
  12. package/dist/types/providers/google-vertex.d.ts +2 -0
  13. package/dist/types/providers/openai-codex-responses.d.ts +4 -0
  14. package/dist/types/providers/openai-completions.d.ts +2 -0
  15. package/dist/types/providers/openai-responses.d.ts +2 -0
  16. package/dist/types/providers/register-builtins.d.ts +8 -0
  17. package/dist/types/providers/transform-messages.d.ts +1 -0
  18. package/dist/types/types.d.ts +3 -1
  19. package/dist/types/usage/grok-cli.d.ts +3 -1
  20. package/dist/types/usage/kimi.d.ts +2 -0
  21. package/dist/types/utils/anthropic-auth.d.ts +8 -0
  22. package/dist/types/utils/foundry.d.ts +10 -0
  23. package/dist/types/utils/http-inspector.d.ts +13 -0
  24. package/dist/types/utils/idle-iterator.d.ts +3 -2
  25. package/dist/types/utils/oauth/alibaba-token-plan.d.ts +19 -0
  26. package/dist/types/utils/oauth/bizrouter.d.ts +1 -0
  27. package/dist/types/utils/oauth/opengateway.d.ts +1 -0
  28. package/dist/types/utils/oauth/types.d.ts +1 -1
  29. package/package.json +2 -2
  30. package/src/auth-broker/client.ts +13 -0
  31. package/src/auth-broker/refresher.ts +1 -0
  32. package/src/auth-broker/remote-store.ts +25 -0
  33. package/src/auth-broker/server.ts +10 -2
  34. package/src/auth-broker/types.ts +4 -0
  35. package/src/auth-broker/wire-schemas.ts +17 -1
  36. package/src/auth-storage.ts +234 -45
  37. package/src/cli.ts +2 -0
  38. package/src/model-thinking.ts +11 -3
  39. package/src/models.json +3289 -486
  40. package/src/provider-models/descriptors.ts +19 -6
  41. package/src/provider-models/openai-compat.ts +99 -18
  42. package/src/providers/amazon-bedrock.ts +4 -0
  43. package/src/providers/anthropic.ts +131 -28
  44. package/src/providers/azure-openai-responses.ts +16 -3
  45. package/src/providers/google-auth.ts +13 -2
  46. package/src/providers/google-gemini-headers.ts +1 -1
  47. package/src/providers/google-vertex.ts +7 -2
  48. package/src/providers/openai-anthropic-shim.ts +4 -0
  49. package/src/providers/openai-codex-responses.ts +52 -10
  50. package/src/providers/openai-completions-compat.ts +2 -2
  51. package/src/providers/openai-completions.ts +20 -3
  52. package/src/providers/openai-responses.ts +17 -10
  53. package/src/providers/register-builtins.ts +21 -2
  54. package/src/providers/transform-messages.ts +25 -6
  55. package/src/stream.ts +3 -1
  56. package/src/types.ts +9 -2
  57. package/src/usage/claude.ts +21 -3
  58. package/src/usage/grok-cli.ts +12 -1
  59. package/src/usage/kimi.ts +16 -2
  60. package/src/utils/anthropic-auth.ts +11 -3
  61. package/src/utils/foundry.ts +12 -2
  62. package/src/utils/http-inspector.ts +77 -0
  63. package/src/utils/idle-iterator.ts +20 -7
  64. package/src/utils/oauth/{alibaba-coding-plan.ts → alibaba-token-plan.ts} +12 -11
  65. package/src/utils/oauth/bizrouter.ts +15 -0
  66. package/src/utils/oauth/index.ts +15 -2
  67. package/src/utils/oauth/opengateway.ts +15 -0
  68. package/src/utils/oauth/types.ts +3 -1
  69. package/src/utils/validation.ts +17 -2
  70. package/src/utils.ts +41 -4
  71. package/dist/types/utils/oauth/alibaba-coding-plan.d.ts +0 -18
package/README.md CHANGED
@@ -69,6 +69,8 @@ Unified LLM API with automatic model discovery, provider configuration, token an
69
69
  - **MiniMax Coding Plan** (requires `MINIMAX_CODE_API_KEY` or `MINIMAX_CODE_CN_API_KEY`)
70
70
  - **Xiaomi MiMo** (requires `XIAOMI_API_KEY`)
71
71
  - **ZenMux** (requires `ZENMUX_API_KEY`)
72
+ - **OpenGateway by Sionic AI** (requires `OPENGATEWAY_API_KEY`)
73
+ - **BizRouter** (requires `BIZROUTER_API_KEY`)
72
74
  - **Qwen Portal** (supports `QWEN_OAUTH_TOKEN` or `QWEN_PORTAL_API_KEY`)
73
75
  - **Cloudflare AI Gateway** (requires `CLOUDFLARE_AI_GATEWAY_API_KEY` and provider-specific gateway base URL)
74
76
  - **Ollama** (local OpenAI-compatible runtime; optional `OLLAMA_API_KEY`)
@@ -954,6 +956,8 @@ In Node.js environments, you can set environment variables to avoid passing API
954
956
  | MiniMax Code | `MINIMAX_CODE_API_KEY` (international) or `MINIMAX_CODE_CN_API_KEY` (China) |
955
957
  | Xiaomi MiMo | `XIAOMI_API_KEY` |
956
958
  | ZenMux | `ZENMUX_API_KEY` |
959
+ | OpenGateway | `OPENGATEWAY_API_KEY` |
960
+ | BizRouter | `BIZROUTER_API_KEY` |
957
961
  | vLLM | `VLLM_API_KEY` |
958
962
  | Cloudflare AI Gateway | `CLOUDFLARE_AI_GATEWAY_API_KEY` |
959
963
  | GitHub Copilot | `COPILOT_GITHUB_TOKEN` or `GH_TOKEN` or `GITHUB_TOKEN` |
@@ -977,6 +981,8 @@ Provider endpoint defaults for the current OpenAI-compatible integrations:
977
981
  - Xiaomi MiMo: `https://api.xiaomimimo.com/anthropic`
978
982
  - ZenMux (OpenAI): `https://zenmux.ai/api/v1`
979
983
  - ZenMux (Anthropic models): `https://zenmux.ai/api/anthropic`
984
+ - OpenGateway by Sionic AI: `https://apis.opengateway.ai/v1`
985
+ - BizRouter: `https://api.bizrouter.ai/v1`
980
986
  - vLLM: `http://127.0.0.1:8000/v1`
981
987
  - Ollama: local OpenAI-compatible runtime (`http://127.0.0.1:11434/v1`)
982
988
  - Ollama Cloud: native Ollama API host (`https://ollama.com/api`, configured here as base URL `https://ollama.com`)
@@ -1,5 +1,5 @@
1
1
  import type { AuthCredential } from "../auth-storage";
2
- import type { CredentialDisableResponse, CredentialIfAbsentUploadResponse, CredentialRefreshResponse, CredentialUploadResponse, HealthzResponse, SnapshotResponse, SnapshotStreamEvent, UsageResponse } from "./types";
2
+ import type { CredentialDisableResponse, CredentialIfAbsentUploadResponse, CredentialRefreshRequest, CredentialRefreshResponse, CredentialUploadResponse, HealthzResponse, SnapshotResponse, SnapshotStreamEvent, UsageResponse } from "./types";
3
3
  export interface AuthBrokerClientOptions {
4
4
  /** Base URL (e.g. `https://broker.tailnet:8765`). Trailing slashes are trimmed. */
5
5
  url: string;
@@ -61,6 +61,7 @@ export declare class AuthBrokerClient {
61
61
  }): AsyncGenerator<SnapshotStreamEvent>;
62
62
  fetchUsage(signal?: AbortSignal): Promise<UsageResponse>;
63
63
  refreshCredential(id: number, signal?: AbortSignal): Promise<CredentialRefreshResponse>;
64
+ refreshMCPCredential(id: number, body: CredentialRefreshRequest, signal?: AbortSignal): Promise<CredentialRefreshResponse>;
64
65
  disableCredential(id: number, cause: string, signal?: AbortSignal): Promise<CredentialDisableResponse>;
65
66
  uploadCredential(provider: string, credential: AuthCredential, signal?: AbortSignal): Promise<CredentialUploadResponse>;
66
67
  uploadCredentialIfAbsent(provider: string, credential: AuthCredential, signal?: AbortSignal): Promise<CredentialIfAbsentUploadResponse>;
@@ -1,4 +1,4 @@
1
- import { type AuthCredential, type AuthCredentialIfAbsentResult, type AuthCredentialStore, type OAuthCredential, type StoredAuthCredential } from "../auth-storage";
1
+ import { type AuthCredential, type AuthCredentialIfAbsentResult, type AuthCredentialStore, type MCPOAuthRefreshClient, type OAuthCredential, type StoredAuthCredential } from "../auth-storage";
2
2
  import type { Provider } from "../types";
3
3
  import type { UsageReport } from "../usage";
4
4
  import type { OAuthCredentials } from "../utils/oauth/types";
@@ -78,6 +78,7 @@ export declare class RemoteAuthCredentialStore implements AuthCredentialStore {
78
78
  * the `refresh` slot.
79
79
  */
80
80
  refreshOAuthCredential(_provider: Provider, credentialId: number, _credential: OAuthCredential, signal?: AbortSignal): Promise<OAuthCredentials>;
81
+ refreshMCPOAuthCredential(credentialId: number, credential: OAuthCredential, client: MCPOAuthRefreshClient, signal?: AbortSignal): Promise<OAuthCredential>;
81
82
  /**
82
83
  * Store-level hook consumed by `AuthStorage.fetchUsageReports()` — proxies
83
84
  * to the broker's `/v1/usage` endpoint. The broker's egress IP isn't
@@ -5,7 +5,7 @@
5
5
  * clients use `access` tokens directly and call back to the broker when a
6
6
  * credential expires or a 401 surfaces on a supposedly-fresh credential.
7
7
  */
8
- import type { AuthCredential, AuthCredentialIfAbsentReason, AuthCredentialSnapshot, AuthCredentialSnapshotEntry } from "../auth-storage";
8
+ import type { AuthCredential, AuthCredentialIfAbsentReason, AuthCredentialSnapshot, AuthCredentialSnapshotEntry, MCPOAuthRefreshClient } from "../auth-storage";
9
9
  import type { UsageReport } from "../usage";
10
10
  /** GET /v1/healthz response body. */
11
11
  export interface HealthzResponse {
@@ -36,6 +36,8 @@ export interface UsageResponse {
36
36
  export interface CredentialRefreshResponse {
37
37
  entry: AuthCredentialSnapshotEntry;
38
38
  }
39
+ /** Optional MCP client metadata; the broker still selects the stored token endpoint. */
40
+ export type CredentialRefreshRequest = MCPOAuthRefreshClient;
39
41
  /** POST /v1/credential/:id/disable request body. */
40
42
  export interface CredentialDisableRequest {
41
43
  cause: string;
@@ -11,6 +11,10 @@
11
11
  * `hasOnlyFields` allowlist for the same effect.
12
12
  */
13
13
  import * as z from "zod/v4";
14
+ export declare const mcpOAuthBindingSchema: z.ZodObject<{
15
+ resourceOrigin: z.ZodString;
16
+ tokenEndpoint: z.ZodString;
17
+ }, z.core.$strict>;
14
18
  /** Real OAuth credential (broker-side) — refresh token is the actual upstream value. */
15
19
  export declare const oauthCredentialSchema: z.ZodObject<{
16
20
  type: z.ZodLiteral<"oauth">;
@@ -21,6 +25,10 @@ export declare const oauthCredentialSchema: z.ZodObject<{
21
25
  projectId: z.ZodOptional<z.ZodString>;
22
26
  email: z.ZodOptional<z.ZodString>;
23
27
  accountId: z.ZodOptional<z.ZodString>;
28
+ mcpBinding: z.ZodOptional<z.ZodObject<{
29
+ resourceOrigin: z.ZodString;
30
+ tokenEndpoint: z.ZodString;
31
+ }, z.core.$strict>>;
24
32
  }, z.core.$strict>;
25
33
  /** OAuth credential as it appears in broker snapshots — refresh replaced with sentinel. */
26
34
  export declare const remoteOauthCredentialSchema: z.ZodObject<{
@@ -31,6 +39,10 @@ export declare const remoteOauthCredentialSchema: z.ZodObject<{
31
39
  projectId: z.ZodOptional<z.ZodString>;
32
40
  email: z.ZodOptional<z.ZodString>;
33
41
  accountId: z.ZodOptional<z.ZodString>;
42
+ mcpBinding: z.ZodOptional<z.ZodObject<{
43
+ resourceOrigin: z.ZodString;
44
+ tokenEndpoint: z.ZodString;
45
+ }, z.core.$strict>>;
34
46
  refresh: z.ZodLiteral<"__remote__">;
35
47
  }, z.core.$strict>;
36
48
  export declare const apiKeyCredentialSchema: z.ZodObject<{
@@ -47,6 +59,10 @@ export declare const writableAuthCredentialSchema: z.ZodDiscriminatedUnion<[z.Zo
47
59
  projectId: z.ZodOptional<z.ZodString>;
48
60
  email: z.ZodOptional<z.ZodString>;
49
61
  accountId: z.ZodOptional<z.ZodString>;
62
+ mcpBinding: z.ZodOptional<z.ZodObject<{
63
+ resourceOrigin: z.ZodString;
64
+ tokenEndpoint: z.ZodString;
65
+ }, z.core.$strict>>;
50
66
  }, z.core.$strict>, z.ZodObject<{
51
67
  type: z.ZodLiteral<"api_key">;
52
68
  key: z.ZodString;
@@ -60,6 +76,10 @@ export declare const snapshotCredentialSchema: z.ZodDiscriminatedUnion<[z.ZodObj
60
76
  projectId: z.ZodOptional<z.ZodString>;
61
77
  email: z.ZodOptional<z.ZodString>;
62
78
  accountId: z.ZodOptional<z.ZodString>;
79
+ mcpBinding: z.ZodOptional<z.ZodObject<{
80
+ resourceOrigin: z.ZodString;
81
+ tokenEndpoint: z.ZodString;
82
+ }, z.core.$strict>>;
63
83
  refresh: z.ZodLiteral<"__remote__">;
64
84
  }, z.core.$strict>, z.ZodObject<{
65
85
  type: z.ZodLiteral<"api_key">;
@@ -76,6 +96,10 @@ export declare const credentialSnapshotEntrySchema: z.ZodObject<{
76
96
  projectId: z.ZodOptional<z.ZodString>;
77
97
  email: z.ZodOptional<z.ZodString>;
78
98
  accountId: z.ZodOptional<z.ZodString>;
99
+ mcpBinding: z.ZodOptional<z.ZodObject<{
100
+ resourceOrigin: z.ZodString;
101
+ tokenEndpoint: z.ZodString;
102
+ }, z.core.$strict>>;
79
103
  refresh: z.ZodLiteral<"__remote__">;
80
104
  }, z.core.$strict>, z.ZodObject<{
81
105
  type: z.ZodLiteral<"api_key">;
@@ -94,6 +118,10 @@ export declare const snapshotEntrySchema: z.ZodObject<{
94
118
  projectId: z.ZodOptional<z.ZodString>;
95
119
  email: z.ZodOptional<z.ZodString>;
96
120
  accountId: z.ZodOptional<z.ZodString>;
121
+ mcpBinding: z.ZodOptional<z.ZodObject<{
122
+ resourceOrigin: z.ZodString;
123
+ tokenEndpoint: z.ZodString;
124
+ }, z.core.$strict>>;
97
125
  refresh: z.ZodLiteral<"__remote__">;
98
126
  }, z.core.$strict>, z.ZodObject<{
99
127
  type: z.ZodLiteral<"api_key">;
@@ -129,6 +157,10 @@ export declare const snapshotResponseSchema: z.ZodObject<{
129
157
  projectId: z.ZodOptional<z.ZodString>;
130
158
  email: z.ZodOptional<z.ZodString>;
131
159
  accountId: z.ZodOptional<z.ZodString>;
160
+ mcpBinding: z.ZodOptional<z.ZodObject<{
161
+ resourceOrigin: z.ZodString;
162
+ tokenEndpoint: z.ZodString;
163
+ }, z.core.$strict>>;
132
164
  refresh: z.ZodLiteral<"__remote__">;
133
165
  }, z.core.$strict>, z.ZodObject<{
134
166
  type: z.ZodLiteral<"api_key">;
@@ -160,6 +192,10 @@ export declare const snapshotStreamSnapshotEventSchema: z.ZodObject<{
160
192
  projectId: z.ZodOptional<z.ZodString>;
161
193
  email: z.ZodOptional<z.ZodString>;
162
194
  accountId: z.ZodOptional<z.ZodString>;
195
+ mcpBinding: z.ZodOptional<z.ZodObject<{
196
+ resourceOrigin: z.ZodString;
197
+ tokenEndpoint: z.ZodString;
198
+ }, z.core.$strict>>;
163
199
  refresh: z.ZodLiteral<"__remote__">;
164
200
  }, z.core.$strict>, z.ZodObject<{
165
201
  type: z.ZodLiteral<"api_key">;
@@ -192,6 +228,10 @@ export declare const snapshotStreamEntryEventSchema: z.ZodObject<{
192
228
  projectId: z.ZodOptional<z.ZodString>;
193
229
  email: z.ZodOptional<z.ZodString>;
194
230
  accountId: z.ZodOptional<z.ZodString>;
231
+ mcpBinding: z.ZodOptional<z.ZodObject<{
232
+ resourceOrigin: z.ZodString;
233
+ tokenEndpoint: z.ZodString;
234
+ }, z.core.$strict>>;
195
235
  refresh: z.ZodLiteral<"__remote__">;
196
236
  }, z.core.$strict>, z.ZodObject<{
197
237
  type: z.ZodLiteral<"api_key">;
@@ -236,6 +276,10 @@ export declare const snapshotStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodOb
236
276
  projectId: z.ZodOptional<z.ZodString>;
237
277
  email: z.ZodOptional<z.ZodString>;
238
278
  accountId: z.ZodOptional<z.ZodString>;
279
+ mcpBinding: z.ZodOptional<z.ZodObject<{
280
+ resourceOrigin: z.ZodString;
281
+ tokenEndpoint: z.ZodString;
282
+ }, z.core.$strict>>;
239
283
  refresh: z.ZodLiteral<"__remote__">;
240
284
  }, z.core.$strict>, z.ZodObject<{
241
285
  type: z.ZodLiteral<"api_key">;
@@ -266,6 +310,10 @@ export declare const snapshotStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodOb
266
310
  projectId: z.ZodOptional<z.ZodString>;
267
311
  email: z.ZodOptional<z.ZodString>;
268
312
  accountId: z.ZodOptional<z.ZodString>;
313
+ mcpBinding: z.ZodOptional<z.ZodObject<{
314
+ resourceOrigin: z.ZodString;
315
+ tokenEndpoint: z.ZodString;
316
+ }, z.core.$strict>>;
269
317
  refresh: z.ZodLiteral<"__remote__">;
270
318
  }, z.core.$strict>, z.ZodObject<{
271
319
  type: z.ZodLiteral<"api_key">;
@@ -348,6 +396,10 @@ export declare const usageResponseSchema: z.ZodObject<{
348
396
  raw: z.ZodOptional<z.ZodUnknown>;
349
397
  }, z.core.$strip>>;
350
398
  }, z.core.$strict>;
399
+ export declare const credentialRefreshRequestSchema: z.ZodObject<{
400
+ clientId: z.ZodOptional<z.ZodString>;
401
+ clientSecret: z.ZodOptional<z.ZodString>;
402
+ }, z.core.$strict>;
351
403
  export declare const credentialRefreshResponseSchema: z.ZodObject<{
352
404
  entry: z.ZodObject<{
353
405
  id: z.ZodNumber;
@@ -360,6 +412,10 @@ export declare const credentialRefreshResponseSchema: z.ZodObject<{
360
412
  projectId: z.ZodOptional<z.ZodString>;
361
413
  email: z.ZodOptional<z.ZodString>;
362
414
  accountId: z.ZodOptional<z.ZodString>;
415
+ mcpBinding: z.ZodOptional<z.ZodObject<{
416
+ resourceOrigin: z.ZodString;
417
+ tokenEndpoint: z.ZodString;
418
+ }, z.core.$strict>>;
363
419
  refresh: z.ZodLiteral<"__remote__">;
364
420
  }, z.core.$strict>, z.ZodObject<{
365
421
  type: z.ZodLiteral<"api_key">;
@@ -385,6 +441,10 @@ export declare const credentialUploadRequestSchema: z.ZodObject<{
385
441
  projectId: z.ZodOptional<z.ZodString>;
386
442
  email: z.ZodOptional<z.ZodString>;
387
443
  accountId: z.ZodOptional<z.ZodString>;
444
+ mcpBinding: z.ZodOptional<z.ZodObject<{
445
+ resourceOrigin: z.ZodString;
446
+ tokenEndpoint: z.ZodString;
447
+ }, z.core.$strict>>;
388
448
  }, z.core.$strict>, z.ZodObject<{
389
449
  type: z.ZodLiteral<"api_key">;
390
450
  key: z.ZodString;
@@ -402,6 +462,10 @@ export declare const credentialUploadResponseSchema: z.ZodObject<{
402
462
  projectId: z.ZodOptional<z.ZodString>;
403
463
  email: z.ZodOptional<z.ZodString>;
404
464
  accountId: z.ZodOptional<z.ZodString>;
465
+ mcpBinding: z.ZodOptional<z.ZodObject<{
466
+ resourceOrigin: z.ZodString;
467
+ tokenEndpoint: z.ZodString;
468
+ }, z.core.$strict>>;
405
469
  refresh: z.ZodLiteral<"__remote__">;
406
470
  }, z.core.$strict>, z.ZodObject<{
407
471
  type: z.ZodLiteral<"api_key">;
@@ -433,6 +497,10 @@ export declare const credentialIfAbsentUploadResponseSchema: z.ZodObject<{
433
497
  projectId: z.ZodOptional<z.ZodString>;
434
498
  email: z.ZodOptional<z.ZodString>;
435
499
  accountId: z.ZodOptional<z.ZodString>;
500
+ mcpBinding: z.ZodOptional<z.ZodObject<{
501
+ resourceOrigin: z.ZodString;
502
+ tokenEndpoint: z.ZodString;
503
+ }, z.core.$strict>>;
436
504
  refresh: z.ZodLiteral<"__remote__">;
437
505
  }, z.core.$strict>, z.ZodObject<{
438
506
  type: z.ZodLiteral<"api_key">;
@@ -15,10 +15,26 @@ export type ApiKeyCredential = {
15
15
  type: "api_key";
16
16
  key: string;
17
17
  };
18
+ export interface MCPOAuthBinding {
19
+ /** Exact HTTP(S) origin of the MCP resource endpoint. */
20
+ resourceOrigin: string;
21
+ /** Exact canonical HTTP(S) token endpoint used to create and refresh the credential. */
22
+ tokenEndpoint: string;
23
+ }
24
+ export declare function resolveMCPOAuthResourceOrigin(value: string): string | undefined;
25
+ export declare function resolveMCPOAuthTokenEndpoint(value: string): string | undefined;
26
+ export declare function isCanonicalMCPOAuthBinding(binding: MCPOAuthBinding): boolean;
27
+ export declare function assertCanonicalMCPOAuthBinding(binding: MCPOAuthBinding | undefined): asserts binding is MCPOAuthBinding;
18
28
  export type OAuthCredential = {
19
29
  type: "oauth";
30
+ /** Present only for credentials created by runtime MCP OAuth. */
31
+ mcpBinding?: MCPOAuthBinding;
20
32
  } & OAuthCredentials;
21
33
  export type AuthCredential = ApiKeyCredential | OAuthCredential;
34
+ export interface MCPOAuthRefreshClient {
35
+ clientId?: string;
36
+ clientSecret?: string;
37
+ }
22
38
  export type AuthCredentialEntry = AuthCredential | AuthCredential[];
23
39
  export type AuthStorageData = Record<string, AuthCredentialEntry>;
24
40
  /**
@@ -161,6 +177,8 @@ export interface AuthCredentialStore {
161
177
  * for `timeoutMs * (maxRetries + 1)`.
162
178
  */
163
179
  refreshOAuthCredential?(provider: Provider, credentialId: number, credential: OAuthCredential, signal?: AbortSignal): Promise<OAuthCredentials>;
180
+ /** Broker-backed MCP refresh using the broker's stored token endpoint and refresh secret. */
181
+ refreshMCPOAuthCredential?(credentialId: number, credential: OAuthCredential, client: MCPOAuthRefreshClient, signal?: AbortSignal): Promise<OAuthCredential>;
164
182
  /**
165
183
  * Optional async pre-read hook invoked after AuthStorage selects a stored
166
184
  * credential but before it returns that credential for an outbound request.
@@ -597,7 +615,7 @@ export declare class AuthStorage {
597
615
  * refresh attempt, which is required for providers that rotate refresh tokens
598
616
  * on every successful refresh.
599
617
  */
600
- refreshCredentialById(id: number, signal?: AbortSignal): Promise<AuthCredentialSnapshotEntry>;
618
+ refreshCredentialById(id: number, signal?: AbortSignal, mcpClient?: MCPOAuthRefreshClient): Promise<AuthCredentialSnapshotEntry>;
601
619
  /**
602
620
  * Force-refresh the OAuth credential with the given id, bypassing the
603
621
  * not-yet-expired guard. Used by the auth-broker server to honour
@@ -607,6 +625,8 @@ export declare class AuthStorage {
607
625
  * Throws when no OAuth credential with that id is loaded.
608
626
  */
609
627
  forceRefreshCredentialById(id: number, signal?: AbortSignal): Promise<AuthCredentialSnapshotEntry>;
628
+ /** Force-refresh the first OAuth credential stored for a provider. */
629
+ forceRefreshOAuthCredential(provider: string, expected: OAuthCredential, client?: MCPOAuthRefreshClient, signal?: AbortSignal): Promise<OAuthCredential>;
610
630
  /**
611
631
  * Disable the credential with the given id and emit a
612
632
  * {@link CredentialDisabledEvent}. Used by the auth-broker server to honour
@@ -27,6 +27,8 @@ export interface OpenAIModelManagerConfig {
27
27
  apiKey?: string;
28
28
  baseUrl?: string;
29
29
  }
30
+ /** Test seam: the model-manager base URL as resolved from trusted env. */
31
+ export declare function resolveOpenAIModelManagerBaseUrlForTest(config?: OpenAIModelManagerConfig): string;
30
32
  export declare function openaiModelManagerOptions(config?: OpenAIModelManagerConfig): ModelManagerOptions<"openai-responses">;
31
33
  export interface GroqModelManagerConfig {
32
34
  apiKey?: string;
@@ -111,16 +113,31 @@ export interface ZenMuxModelManagerConfig {
111
113
  baseUrl?: string;
112
114
  }
113
115
  export declare function zenmuxModelManagerOptions(config?: ZenMuxModelManagerConfig): ModelManagerOptions<Api>;
116
+ export interface OpenGatewayModelManagerConfig {
117
+ apiKey?: string;
118
+ baseUrl?: string;
119
+ }
120
+ /**
121
+ * OpenGateway by Sionic AI — an OpenAI-compatible gateway that fronts OpenAI,
122
+ * Anthropic, and Google models behind one API key. Models are discovered from
123
+ * the OpenAI-compatible `/v1/models` endpoint.
124
+ */
125
+ export declare function opengatewayModelManagerOptions(config?: OpenGatewayModelManagerConfig): ModelManagerOptions<"openai-completions">;
126
+ export interface BizRouterModelManagerConfig {
127
+ apiKey?: string;
128
+ baseUrl?: string;
129
+ }
130
+ export declare function bizrouterModelManagerOptions(config?: BizRouterModelManagerConfig): ModelManagerOptions<"openai-completions">;
114
131
  export interface KiloModelManagerConfig {
115
132
  apiKey?: string;
116
133
  baseUrl?: string;
117
134
  }
118
135
  export declare function kiloModelManagerOptions(config?: KiloModelManagerConfig): ModelManagerOptions<"openai-completions">;
119
- export interface AlibabaCodingPlanModelManagerConfig {
136
+ export interface AlibabaTokenPlanModelManagerConfig {
120
137
  apiKey?: string;
121
138
  baseUrl?: string;
122
139
  }
123
- export declare function alibabaCodingPlanModelManagerOptions(config?: AlibabaCodingPlanModelManagerConfig): ModelManagerOptions<"openai-completions">;
140
+ export declare function alibabaTokenPlanModelManagerOptions(config?: AlibabaTokenPlanModelManagerConfig): ModelManagerOptions<"openai-completions">;
124
141
  export interface VercelAiGatewayModelManagerConfig {
125
142
  apiKey?: string;
126
143
  baseUrl?: string;
@@ -42,7 +42,16 @@ type AnthropicCacheControl = {
42
42
  export declare function clearAnthropicFastModeFallback(providerSessionState: Map<string, ProviderSessionState> | undefined): void;
43
43
  export declare function isAnthropicFastModeUnsupportedError(error: unknown): boolean;
44
44
  export declare function isAnthropicThinkingBlockMutationError(error: unknown): boolean;
45
- export declare const claudeCodeVersion = "2.1.63";
45
+ /**
46
+ * 400 shape where a replayed `thinking`/`redacted_thinking` block fails signature
47
+ * validation, e.g. `messages.5.content.24: Invalid \`signature\` in \`thinking\` block`.
48
+ * Unlike the latest-assistant mutation error above, the cited block can sit anywhere
49
+ * in the replayed history, so recovery must repair every assistant message rather
50
+ * than only the latest one.
51
+ */
52
+ export declare function isAnthropicThinkingSignatureInvalidError(error: unknown): boolean;
53
+ export declare const claudeCodeVersion = "2.1.219";
54
+ export declare const claudeCodeEntrypoint = "sdk-cli";
46
55
  export declare const claudeToolPrefix: string;
47
56
  export declare const claudeCodeSystemInstruction = "You are a Claude agent, built on Anthropic's Claude Agent SDK.";
48
57
  export declare function mapStainlessOs(platform: string): "MacOS" | "Windows" | "Linux" | "FreeBSD" | `Other::${string}`;
@@ -184,6 +193,7 @@ export declare function buildAnthropicClientOptions(args: AnthropicClientOptions
184
193
  export declare function normalizeCacheControlTtlOrdering(params: MessageCreateParamsStreaming): void;
185
194
  export declare function convertAnthropicMessages(messages: Message[], model: Model<"anthropic-messages">, isOAuthToken: boolean, options?: {
186
195
  repairLatestAssistantThinking?: boolean;
196
+ repairAllAssistantThinking?: boolean;
187
197
  }): MessageParam[];
188
198
  /**
189
199
  * Normalize a JSON Schema node for Anthropic tool `input_schema`.
@@ -1,4 +1,4 @@
1
- import type { ServiceTier, StreamFunction, StreamOptions, ToolChoice } from "../types";
1
+ import type { Model, ServiceTier, StreamFunction, StreamOptions, ToolChoice } from "../types";
2
2
  export interface AzureOpenAIResponsesOptions extends StreamOptions {
3
3
  reasoning?: "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
4
4
  reasoningSummary?: "auto" | "detailed" | "concise" | null;
@@ -13,3 +13,8 @@ export interface AzureOpenAIResponsesOptions extends StreamOptions {
13
13
  * Generate function for Azure OpenAI Responses API
14
14
  */
15
15
  export declare const streamAzureOpenAIResponses: StreamFunction<"azure-openai-responses">;
16
+ /** Test seam: the Azure endpoint config as resolved from trusted env. */
17
+ export declare function resolveAzureConfigForTest(model: Model<"azure-openai-responses">, options?: AzureOpenAIResponsesOptions): {
18
+ baseUrl: string;
19
+ apiVersion: string;
20
+ };
@@ -12,6 +12,8 @@
12
12
  * (default 60s). Concurrent callers waiting on a refresh share the same in-flight promise.
13
13
  */
14
14
  import type { FetchImpl } from "../types";
15
+ /** Test seam: the ADC credentials file path as resolved from trusted env. */
16
+ export declare function resolveAdcCredentialsPathForTest(): string | undefined;
15
17
  /**
16
18
  * Returns a Bearer access token suitable for the `Authorization` header on Vertex AI calls.
17
19
  * The token is cached in module scope and refreshed `GOOGLE_VERTEX_REFRESH_SKEW_MS` ms before it expires.
@@ -5,7 +5,7 @@
5
5
  */
6
6
  export declare const GEMINI_CLI_VERSION_ENV = "SKC_AI_GEMINI_CLI_VERSION";
7
7
  export declare const LEGACY_GEMINI_CLI_VERSION_ENV = "PI_AI_GEMINI_CLI_VERSION";
8
- export declare const DEFAULT_GEMINI_CLI_VERSION = "0.50.0";
8
+ export declare const DEFAULT_GEMINI_CLI_VERSION = "0.52.0";
9
9
  export declare function getGeminiCliUserAgent(modelId?: string): string;
10
10
  export declare const getGeminiCliHeaders: (modelId?: string) => {
11
11
  "User-Agent": string;
@@ -5,3 +5,5 @@ export interface GoogleVertexOptions extends GoogleSharedStreamOptions {
5
5
  location?: string;
6
6
  }
7
7
  export declare const streamGoogleVertex: StreamFunction<"google-vertex">;
8
+ /** Test seam: the Vertex API key as resolved from options plus trusted env. */
9
+ export declare function resolveVertexApiKeyForTest(options?: GoogleVertexOptions): string | undefined;
@@ -10,6 +10,10 @@ export interface OpenAICodexResponsesOptions extends StreamOptions {
10
10
  preferWebsockets?: boolean;
11
11
  serviceTier?: ServiceTier;
12
12
  }
13
+ /** Maps a canonical tool name to the name Codex accepts on the wire. */
14
+ export declare function codexToolWireName(name: string): string;
15
+ /** Maps a Codex wire tool name back to the canonical harness tool name. */
16
+ export declare function codexToolCanonicalName(wireName: string): string;
13
17
  type CodexTransport = "sse" | "websocket";
14
18
  export interface OpenAICodexWebSocketDebugStats {
15
19
  fullContextRequests: number;
@@ -1,6 +1,8 @@
1
1
  import type { ChatCompletionMessageParam } from "openai/resources/chat/completions";
2
2
  import { type AssistantMessage, type Context, type Model, type ServiceTier, type StreamFunction, type StreamOptions, type ToolChoice } from "../types";
3
3
  import { type ResolvedOpenAICompat } from "./openai-completions-compat";
4
+ /** Test seam: the provider base URL as resolved from trusted env. */
5
+ export declare function resolveOpenAICompletionsBaseUrlForTest(baseUrl: string | undefined, authCredentialType: "api_key" | "oauth" | undefined): string;
4
6
  /**
5
7
  * Identify "real progress" stream chunks vs. keepalives, role-only preambles,
6
8
  * and empty `{choices:[]}` no-ops emitted by some OpenAI-compatible endpoints.
@@ -13,6 +13,8 @@ export interface OpenAIResponsesOptions extends StreamOptions {
13
13
  */
14
14
  strictResponsesPairing?: boolean;
15
15
  }
16
+ /** Test seam: the provider base URL as resolved from trusted env. */
17
+ export declare function resolveOpenAIProviderBaseUrlForTest(baseUrl: string | undefined, authCredentialType: "api_key" | "oauth" | undefined): string;
16
18
  /**
17
19
  * Generate function for OpenAI Responses API
18
20
  */
@@ -17,6 +17,14 @@ interface BedrockProviderModule {
17
17
  streamBedrock: (model: Model<"bedrock-converse-stream">, context: Context, options: BedrockOptions) => AssistantMessageEventStream;
18
18
  }
19
19
  export declare function setBedrockProviderModule(module: BedrockProviderModule): void;
20
+ /**
21
+ * Resolves the first-event timeout fallback for the outer lazy-stream watchdog.
22
+ * A configured wrapper-specific fallback (from `LazyStreamLimits`) always wins;
23
+ * otherwise providers known to have slow first events get a five-minute floor
24
+ * matching their inner provider-level override. Returns `undefined` for
25
+ * providers that should use the shared default.
26
+ */
27
+ export declare function resolveLazyStreamFirstEventFallbackMs(provider: string, configuredFallbackMs?: number): number | undefined;
20
28
  export declare const streamAnthropic: (model: Model<"anthropic-messages">, context: Context, options: OptionsForApi<"anthropic-messages">) => EventStreamImpl;
21
29
  export declare const streamAzureOpenAIResponses: (model: Model<"azure-openai-responses">, context: Context, options: OptionsForApi<"azure-openai-responses">) => EventStreamImpl;
22
30
  export declare const streamGoogle: (model: Model<"google-generative-ai">, context: Context, options: OptionsForApi<"google-generative-ai">) => EventStreamImpl;
@@ -11,4 +11,5 @@ import type { Api, AssistantMessage, Message, Model } from "../types";
11
11
  */
12
12
  export declare function transformMessages<TApi extends Api>(messages: Message[], model: Model<TApi>, normalizeToolCallId?: (id: string, model: Model<TApi>, source: AssistantMessage) => string, options?: {
13
13
  repairLatestAssistantThinking?: boolean;
14
+ repairAllAssistantThinking?: boolean;
14
15
  }): Message[];
@@ -51,7 +51,7 @@ export interface ThinkingConfig {
51
51
  /** Provider-specific transport used to encode the selected effort. */
52
52
  mode: ThinkingControlMode;
53
53
  }
54
- export type KnownProvider = "alibaba-coding-plan" | "amazon-bedrock" | "azure-openai" | "anthropic" | "google" | "google-gemini-cli" | "google-antigravity" | "google-vertex" | "openai" | "openai-codex" | "kimi-code" | "minimax-code" | "minimax-code-cn" | "github-copilot" | "fireworks" | "firepass" | "fugu" | "gitlab-duo" | "cursor" | "deepseek" | "deepinfra" | "xai" | "groq" | "cerebras" | "openrouter" | "kilo" | "vercel-ai-gateway" | "zai" | "glm-zcode" | "mistral" | "minimax" | "opencode-go" | "opencode-zen" | "synthetic" | "cloudflare-ai-gateway" | "huggingface" | "litellm" | "moonshot" | "nvidia" | "nanogpt" | "ollama" | "ollama-cloud" | "qianfan" | "qwen-portal" | "together" | "venice" | "vllm" | "xiaomi" | "xiaomi-token-plan-sgp" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-cn" | "zenmux" | "lm-studio";
54
+ export type KnownProvider = "alibaba-token-plan" | "amazon-bedrock" | "azure-openai" | "anthropic" | "google" | "google-gemini-cli" | "google-antigravity" | "google-vertex" | "openai" | "openai-codex" | "kimi-code" | "minimax-code" | "minimax-code-cn" | "github-copilot" | "fireworks" | "firepass" | "fugu" | "gitlab-duo" | "cursor" | "deepseek" | "deepinfra" | "xai" | "groq" | "cerebras" | "openrouter" | "kilo" | "vercel-ai-gateway" | "zai" | "glm-zcode" | "mistral" | "minimax" | "opencode-go" | "opencode-zen" | "opengateway" | "bizrouter" | "synthetic" | "cloudflare-ai-gateway" | "huggingface" | "litellm" | "moonshot" | "nvidia" | "nanogpt" | "ollama" | "ollama-cloud" | "qianfan" | "qwen-portal" | "together" | "venice" | "vllm" | "xiaomi" | "xiaomi-token-plan-sgp" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-cn" | "zenmux" | "lm-studio";
55
55
  export type Provider = KnownProvider | string;
56
56
  import type { Effort } from "./model-thinking";
57
57
  /** Token budgets for each thinking level (token-based providers only) */
@@ -519,6 +519,7 @@ export type TSchema = ZodType | TJsonSchema;
519
519
  export type Static<S> = S extends ZodType ? z.infer<S> : S extends {
520
520
  static: infer T;
521
521
  } ? T : unknown;
522
+ export type RawArgumentRejectionCode = "ask-intent-review-requires-positive-round" | "ask-intent-contract-requires-non-empty-authority" | "ask-deep-interview-metadata-requires-deep-interview-gate";
522
523
  export type RawArgumentValidationResult = {
523
524
  outcome: "passthrough";
524
525
  } | {
@@ -526,6 +527,7 @@ export type RawArgumentValidationResult = {
526
527
  arguments: ToolCall["arguments"];
527
528
  } | {
528
529
  outcome: "reject";
530
+ code?: RawArgumentRejectionCode;
529
531
  };
530
532
  export interface Tool<TParameters extends TSchema = TSchema> {
531
533
  name: string;
@@ -1,10 +1,12 @@
1
- import type { CredentialRankingStrategy, UsageProvider } from "../usage";
1
+ import type { CredentialRankingStrategy, UsageFetchParams, UsageProvider } from "../usage";
2
2
  interface BillingUsage {
3
3
  monthlyLimit: number;
4
4
  used: number;
5
5
  billingPeriodEnd: string;
6
6
  }
7
7
  export declare function parseGrokCliBillingUsage(payload: unknown): BillingUsage;
8
+ /** Test seam: the usage access token as resolved from a credential plus trusted env. */
9
+ export declare function resolveGrokAccessTokenForTest(params: UsageFetchParams): string | undefined;
8
10
  export declare const grokCliUsageProvider: UsageProvider;
9
11
  export declare const grokCliRankingStrategy: CredentialRankingStrategy;
10
12
  export {};
@@ -1,2 +1,4 @@
1
1
  import type { UsageProvider } from "../usage";
2
+ /** Test seam: the usage base URL as resolved from a caller value plus trusted env. */
3
+ export declare function normalizeKimiUsageBaseUrlForTest(baseUrl?: string): string;
2
4
  export declare const kimiUsageProvider: UsageProvider;
@@ -4,6 +4,14 @@ export interface AnthropicAuthConfig {
4
4
  baseUrl: string;
5
5
  isOAuth: boolean;
6
6
  }
7
+ /**
8
+ * Resolve the Anthropic base URL from the environment.
9
+ *
10
+ * Trusted sources only: the result becomes the request URL that carries the
11
+ * Anthropic API key / OAuth token, so whatever can set it can redirect
12
+ * authenticated traffic. `$env` merges the caller's `cwd/.env`, so reading it
13
+ * there would let repository content choose where credentials are sent.
14
+ */
7
15
  export declare function resolveAnthropicBaseUrlFromEnv(): string | undefined;
8
16
  /**
9
17
  * Checks if a token is an OAuth token by looking for sk-ant-oat prefix.
@@ -1 +1,11 @@
1
+ /**
2
+ * Whether Anthropic requests run in Foundry gateway mode.
3
+ *
4
+ * Resolved from trusted environment sources only. Enabling Foundry switches the
5
+ * request base URL and injects TLS client material, so whatever can set this
6
+ * redirects authenticated traffic. `$env` merges the caller's `cwd/.env`, so
7
+ * reading it there would let repository content flip the mode; resolve it the
8
+ * same way the credentials themselves are (launching shell plus SKC/user-owned
9
+ * `.env` files, never the project `.env`).
10
+ */
1
11
  export declare function isFoundryEnabled(): boolean;
@@ -18,6 +18,19 @@ export declare function isModelUnavailableError(message: string, error: unknown)
18
18
  /** Actionable guidance for selecting an available model/provider. */
19
19
  export declare function formatModelUnavailableGuidance(dump: RawHttpRequestDump | undefined): string;
20
20
  export declare function appendRawHttpRequestDumpFor400(message: string, error: unknown, dump: RawHttpRequestDump | undefined): Promise<string>;
21
+ /**
22
+ * Name the failed connection when the request never produced an HTTP status.
23
+ *
24
+ * Bun raises DNS and socket failures as a bare `Error` whose message is a
25
+ * standalone hint ("Was there a typo in the url or port?", "Unable to connect.
26
+ * Is the computer able to access the url?") while the actionable facts live on
27
+ * `code` and `path`. Those properties are dropped when only `message` reaches
28
+ * the assistant message, so a provider outage, a local DNS failure, and a
29
+ * mistyped custom base URL all render as the same context-free sentence.
30
+ * Appending the code and the target URL tells the user which host failed and
31
+ * whether the fault is theirs.
32
+ */
33
+ export declare function appendTransportFailureContext(message: string, error: unknown, rawRequestDump: RawHttpRequestDump | undefined): string;
21
34
  export declare function finalizeErrorMessage(error: unknown, rawRequestDump: RawHttpRequestDump | undefined, capturedErrorResponse?: CapturedHttpErrorResponse): Promise<string>;
22
35
  export declare function withHttpStatus(error: unknown, status: number): Error;
23
36
  /**
@@ -1,7 +1,8 @@
1
+ export declare function getProviderFirstEventTimeoutFallbackMs(provider: string): number | undefined;
1
2
  /**
2
3
  * Returns the idle timeout used for provider streaming transports.
3
4
  *
4
- * `PI_OPENAI_STREAM_IDLE_TIMEOUT_MS` is accepted as a backward-compatible alias.
5
+ * `SKC_OPENAI_STREAM_IDLE_TIMEOUT_MS` is honored first; `PI_OPENAI_STREAM_IDLE_TIMEOUT_MS` is a backward-compatible alias.
5
6
  * Set `PI_STREAM_IDLE_TIMEOUT_MS=0` to disable the watchdog.
6
7
  *
7
8
  * Providers that legitimately stream much slower than the global default can pass
@@ -12,7 +13,7 @@ export declare function getStreamIdleTimeoutMs(fallbackMs?: number): number | un
12
13
  /**
13
14
  * Returns the idle timeout used for OpenAI-family streaming transports.
14
15
  *
15
- * Set `PI_OPENAI_STREAM_IDLE_TIMEOUT_MS=0` to disable the watchdog.
16
+ * Honors `SKC_OPENAI_STREAM_IDLE_TIMEOUT_MS` first (`PI_OPENAI_STREAM_IDLE_TIMEOUT_MS` is the legacy alias). Set `=0` to disable.
16
17
  */
17
18
  export declare function getOpenAIStreamIdleTimeoutMs(): number | undefined;
18
19
  /**
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Alibaba Token Plan login flow.
3
+ *
4
+ * Alibaba Token Plan provides OpenAI-compatible models via
5
+ * https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1.
6
+ *
7
+ * This is not OAuth - it's a simple API key flow:
8
+ * 1. Open browser to Alibaba Cloud Model Studio console
9
+ * 2. User copies their API key
10
+ * 3. User pastes the API key into the CLI
11
+ */
12
+ import type { OAuthController } from "./types";
13
+ /**
14
+ * Login to Alibaba Token Plan.
15
+ *
16
+ * Opens browser to API keys page, prompts user to paste their API key.
17
+ * Returns the API key directly (not OAuthCredentials - this isn't OAuth).
18
+ */
19
+ export declare function loginAlibabaTokenPlan(options: OAuthController): Promise<string>;
@@ -0,0 +1 @@
1
+ export declare const loginBizRouter: (options: import("./types").OAuthController) => Promise<string>;
@@ -0,0 +1 @@
1
+ export declare const loginOpenGateway: (options: import("./types").OAuthController) => Promise<string>;