@mupt-ai/dari-gateway 1.0.339 → 1.0.341

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 (69) hide show
  1. package/README.md +9 -7
  2. package/dist/index.d.ts +1 -1
  3. package/dist/link/assets.js +7 -0
  4. package/dist/link/budget.d.ts +18 -7
  5. package/dist/link/budget.js +58 -16
  6. package/dist/link/endpoints.js +64 -45
  7. package/dist/link/errors.js +4 -1
  8. package/dist/link/self_hosted.d.ts +3 -1
  9. package/dist/link/self_hosted.js +25 -9
  10. package/dist/link/service.d.ts +4 -4
  11. package/dist/link/service.js +41 -22
  12. package/dist/models/catalog.js +1 -0
  13. package/dist/models/execution_provider.d.ts +6 -1
  14. package/dist/models/execution_provider.js +12 -0
  15. package/dist/models/provider_defaults.js +9 -0
  16. package/dist/models/provider_models.json +217 -0
  17. package/dist/models/subscriptions.d.ts +5 -0
  18. package/dist/models/subscriptions.js +21 -2
  19. package/dist/platform/platform.d.ts +11 -7
  20. package/dist/providers/execution.d.ts +5 -0
  21. package/dist/providers/execution.js +12 -2
  22. package/dist/providers/github_copilot.d.ts +8 -0
  23. package/dist/providers/github_copilot.js +21 -0
  24. package/dist/providers/pi.js +3 -0
  25. package/dist/providers/provider_attempt_runner.d.ts +2 -0
  26. package/dist/providers/provider_attempt_runner.js +9 -0
  27. package/dist/providers/provider_call.js +6 -2
  28. package/dist/providers/subscription_limits.d.ts +6 -5
  29. package/dist/providers/subscription_limits.js +20 -9
  30. package/dist/runtime/routed_runtime.js +68 -3
  31. package/dist/self_host/resolve.d.ts +11 -9
  32. package/dist/self_host/resolve.js +249 -182
  33. package/dist/self_host/subscriptions/index.d.ts +6 -5
  34. package/dist/self_host/subscriptions/index.js +6 -5
  35. package/dist/self_host/subscriptions/oauth.d.ts +7 -3
  36. package/dist/self_host/subscriptions/oauth.js +195 -5
  37. package/dist/self_host/subscriptions/store.js +3 -0
  38. package/dist/telemetry/prefix_state.d.ts +1 -0
  39. package/dist/telemetry/prefix_state.js +1 -1
  40. package/dist/telemetry/report.js +2 -3
  41. package/dist/types.d.ts +6 -2
  42. package/package.json +2 -2
  43. package/src/index.ts +1 -1
  44. package/src/link/assets.ts +7 -0
  45. package/src/link/budget.ts +53 -18
  46. package/src/link/endpoints.ts +66 -45
  47. package/src/link/errors.ts +4 -1
  48. package/src/link/self_hosted.ts +26 -8
  49. package/src/link/service.ts +45 -23
  50. package/src/models/catalog.ts +1 -0
  51. package/src/models/execution_provider.ts +24 -1
  52. package/src/models/provider_defaults.ts +9 -0
  53. package/src/models/provider_models.json +217 -0
  54. package/src/models/subscriptions.ts +22 -2
  55. package/src/platform/platform.ts +13 -8
  56. package/src/providers/execution.ts +22 -2
  57. package/src/providers/github_copilot.ts +24 -0
  58. package/src/providers/pi.ts +2 -0
  59. package/src/providers/provider_attempt_runner.ts +15 -0
  60. package/src/providers/provider_call.ts +6 -2
  61. package/src/providers/subscription_limits.ts +20 -10
  62. package/src/runtime/routed_runtime.ts +79 -3
  63. package/src/self_host/resolve.ts +255 -187
  64. package/src/self_host/subscriptions/index.ts +7 -4
  65. package/src/self_host/subscriptions/oauth.ts +264 -8
  66. package/src/self_host/subscriptions/store.ts +3 -0
  67. package/src/telemetry/prefix_state.ts +4 -1
  68. package/src/telemetry/report.ts +2 -3
  69. package/src/types.ts +27 -3
@@ -124,9 +124,9 @@ export declare function newLinkClientSecret(): {
124
124
  };
125
125
  /**
126
126
  * The grant a link token serves a request for: null when the key is no link
127
- * token. Its plans and keys at their monthly spend limit are left out. Throws
128
- * the 401 a dead token gets, and the 424 a grant at its budget, or with every
129
- * plan and key at its limit, gets until it serves again.
127
+ * token. Its plans and keys at their limit are left out. Throws the 401 a dead
128
+ * token gets, and the 424 a grant at its budget, or with every plan and key at
129
+ * its limit, gets until it serves again.
130
130
  */
131
- export declare function linkTokenGrant(store: LinkStore, token: string, now?: Date): Promise<ActiveLinkGrant | null>;
131
+ export declare function linkTokenGrant(store: LinkStore, users: Pick<LinkUsers, "plansWithIds">, token: string, now?: Date): Promise<ActiveLinkGrant | null>;
132
132
  export {};
@@ -11,7 +11,7 @@
11
11
  `LINK_PERSONAL_CLIENT_ID`, which nothing can sign in to. */
12
12
  import { randomUUID } from "node:crypto";
13
13
  import { HttpError } from "../http/errors.js";
14
- import { budgetStandings, grantSpend, nextMonthStart, overBudgetUntil, usesSince, } from "./budget.js";
14
+ import { budgetStandings, grantSpend, overBudgetUntil, usesSince, } from "./budget.js";
15
15
  import { budgetExhausted, limitsReached, linkGrantRevoked, linkTokenExpired, linkUnavailableError } from "./errors.js";
16
16
  import { LINK_CLIENT_SECRET_PREFIX, LINK_CODE_PREFIX, LINK_CODE_TTL_MS, linkGrants, linkHash, linkSecret, LINK_TOKEN_RETENTION_MS, TOKEN_PREFIX, } from "./grants.js";
17
17
  /** The built-in app every personal endpoint's grant belongs to. */
@@ -25,13 +25,16 @@ export function linkPlatform(store, users) {
25
25
  };
26
26
  // A grant's budget windows and each granted plan or key's spend this month.
27
27
  const standings = async (grant, now = new Date()) => {
28
- const uses = await store.budgetUses(grant.id, usesSince(grant.budget, now));
28
+ const [uses, plans] = await Promise.all([
29
+ store.budgetUses(grant.id, usesSince(grant.budget, now)),
30
+ grant.limits.length === 0 ? [] : users.plansWithIds(grant.credentialIds),
31
+ ]);
29
32
  return {
30
33
  budget: budgetStandings(grant.budget, uses, now).map((standing) => ({
31
34
  ...standing,
32
35
  resetsAt: standing.resetsAt?.toISOString() ?? null,
33
36
  })),
34
- spend: grantSpend(grant.credentialIds, grant.limits, uses, now),
37
+ spend: grantSpend(grant.credentialIds, grant.limits, uses, plans, now),
35
38
  };
36
39
  };
37
40
  const publicGrant = ({ subject: _, ...grant }) => ({
@@ -44,13 +47,12 @@ export function linkPlatform(store, users) {
44
47
  });
45
48
  // Plans and keys the user can grant, and limits only on them.
46
49
  const ownedCredentials = async (subject, credentialIds, limits = []) => {
47
- const owned = new Set((await users.plans(subject)).map((plan) => plan.id));
50
+ const plans = await users.plans(subject);
51
+ const owned = new Set(plans.map((plan) => plan.id));
48
52
  if (credentialIds.length === 0 || !credentialIds.every((id) => owned.has(id))) {
49
53
  throw new HttpError(400, "Choose one or more of your connected plans or API keys.", "invalid_request");
50
54
  }
51
- if (!limits.every((limit) => credentialIds.includes(limit.credentialId))) {
52
- throw new HttpError(400, "Set limits only on the plans and keys the grant shares.", "invalid_request");
53
- }
55
+ requireLimitsFit(limits, credentialIds, plans);
54
56
  return [...new Set(credentialIds)].sort();
55
57
  };
56
58
  // The one user a key acts for: endpoints are personal, so an operator key
@@ -152,9 +154,6 @@ export function linkPlatform(store, users) {
152
154
  async disconnect(subject, grantId) {
153
155
  return (await ownGrant(subject, grantId)) !== null && (await revoke(grantId));
154
156
  },
155
- async setBudget(subject, grantId, budget) {
156
- return (await ownGrant(subject, grantId)) !== null && (await store.updateGrant(grantId, { budget }));
157
- },
158
157
  async setLimits(subject, grantId, limits) {
159
158
  const grant = await ownGrant(subject, grantId);
160
159
  if (grant === null)
@@ -257,9 +256,7 @@ export function linkPlatform(store, users) {
257
256
  const grant = await ownGrant(subject, grantId);
258
257
  if (grant === null)
259
258
  return false;
260
- if (!limits.every((limit) => grant.credentialIds.includes(limit.credentialId))) {
261
- throw new HttpError(400, "Set limits only on the plans and keys the grant shares.", "invalid_request");
262
- }
259
+ requireLimitsFit(limits, grant.credentialIds, await users.plansWithIds(grant.credentialIds));
263
260
  return await store.updateGrant(grantId, { limits });
264
261
  },
265
262
  async setBudget({ apiKey, grantId, budget }) {
@@ -288,6 +285,22 @@ export function newLinkApp(request) {
288
285
  };
289
286
  return { record, ...(secret === null ? {} : { clientSecret: secret.secret }) };
290
287
  }
288
+ /**
289
+ * Limits only on the grant's plans and keys, and a share of quota only on a
290
+ * plan. A plan may still carry dollars a month, as limits did before shares;
291
+ * the apps offer a share for a plan that has none.
292
+ */
293
+ function requireLimitsFit(limits, credentialIds, plans) {
294
+ if (!limits.every((limit) => credentialIds.includes(limit.credentialId))) {
295
+ throw new HttpError(400, "Set limits only on the plans and keys the grant shares.", "invalid_request");
296
+ }
297
+ for (const limit of limits) {
298
+ const key = plans.find((plan) => plan.id === limit.credentialId)?.apiKeyProvider !== undefined;
299
+ if (key && limit.monthlyUsd === undefined) {
300
+ throw new HttpError(400, "Limit an API key with monthly_usd; max_percent is for plans.", "invalid_request");
301
+ }
302
+ }
303
+ }
291
304
  /** A confidential app's client secret, and the hash that is kept of it. */
292
305
  export function newLinkClientSecret() {
293
306
  const secret = linkSecret(LINK_CLIENT_SECRET_PREFIX);
@@ -295,11 +308,11 @@ export function newLinkClientSecret() {
295
308
  }
296
309
  /**
297
310
  * The grant a link token serves a request for: null when the key is no link
298
- * token. Its plans and keys at their monthly spend limit are left out. Throws
299
- * the 401 a dead token gets, and the 424 a grant at its budget, or with every
300
- * plan and key at its limit, gets until it serves again.
311
+ * token. Its plans and keys at their limit are left out. Throws the 401 a dead
312
+ * token gets, and the 424 a grant at its budget, or with every plan and key at
313
+ * its limit, gets until it serves again.
301
314
  */
302
- export async function linkTokenGrant(store, token, now = new Date()) {
315
+ export async function linkTokenGrant(store, users, token, now = new Date()) {
303
316
  const auth = await linkGrants(store).authenticate(token, now);
304
317
  if (auth === null)
305
318
  return null;
@@ -314,12 +327,18 @@ export async function linkTokenGrant(store, token, now = new Date()) {
314
327
  const back = overBudgetUntil(budgetStandings(grant.budget, uses, now));
315
328
  if (back !== undefined)
316
329
  throw linkUnavailableError(budgetExhausted(back));
317
- const reached = new Set(grantSpend(grant.credentialIds, grant.limits, uses, now).filter((entry) => entry.reached).map((entry) => entry.credentialId));
318
- if (reached.size === 0)
330
+ if (grant.limits.length === 0)
319
331
  return grant;
320
- const credentialIds = new Set([...grant.credentialIds].filter((id) => !reached.has(id)));
321
- if (credentialIds.size === 0)
322
- throw linkUnavailableError(limitsReached(nextMonthStart(now)));
332
+ const plans = grant.limits.some((limit) => limit.maxPercent !== undefined)
333
+ ? await users.plansWithIds(grant.limits.map((limit) => limit.credentialId))
334
+ : [];
335
+ const reached = grantSpend(grant.credentialIds, grant.limits, uses, plans, now).filter((entry) => entry.reached);
336
+ if (reached.length === 0)
337
+ return grant;
338
+ const credentialIds = new Set([...grant.credentialIds].filter((id) => !reached.some((entry) => entry.credentialId === id)));
339
+ if (credentialIds.size === 0) {
340
+ throw linkUnavailableError(limitsReached(new Date(Math.min(...reached.map((entry) => Date.parse(entry.resetsAt))))));
341
+ }
323
342
  return { ...grant, credentialIds };
324
343
  }
325
344
  function endpointName(name) {
@@ -10,6 +10,7 @@ export const DEFAULT_CATALOG_PROVIDERS = [
10
10
  "google",
11
11
  "fireworks",
12
12
  "opencode-go",
13
+ "github-copilot",
13
14
  "openrouter",
14
15
  "vercel-ai-gateway",
15
16
  ];
@@ -1,4 +1,4 @@
1
- import type { ProviderKeySource, ResolvedRouter } from "../types.js";
1
+ import type { ProviderCredential, ProviderKeySource, ResolvedRouter, ResolvedRouterModelConfig } from "../types.js";
2
2
  /** Actual serving provider for a canonical model on a resolved managed router. */
3
3
  export declare function executionProviderForModel(credentials: ResolvedRouter, model: string): string;
4
4
  /**
@@ -7,3 +7,8 @@ export declare function executionProviderForModel(credentials: ResolvedRouter, m
7
7
  * user-owned so unknown platform data cannot trigger managed-key billing.
8
8
  */
9
9
  export declare function keySourceForModel(credentials: ResolvedRouter, model: string): ProviderKeySource;
10
+ /**
11
+ * The router as one of a model's fallbacks serves it: the fallback's config,
12
+ * and its plan's credential or, without one, the router's API credential.
13
+ */
14
+ export declare function credentialsServedBy(credentials: ResolvedRouter, model: string, config: ResolvedRouterModelConfig, plan: ProviderCredential | undefined): ResolvedRouter;
@@ -15,3 +15,15 @@ export function keySourceForModel(credentials, model) {
15
15
  return supplied.subscription ? "subscription" : "user";
16
16
  return credentials.provider_key_sources?.[executionProviderForModel(credentials, model)] ?? "user";
17
17
  }
18
+ /**
19
+ * The router as one of a model's fallbacks serves it: the fallback's config,
20
+ * and its plan's credential or, without one, the router's API credential.
21
+ */
22
+ export function credentialsServedBy(credentials, model, config, plan) {
23
+ const { [model]: _replaced, ...others } = credentials.provider_credentials ?? {};
24
+ return {
25
+ ...credentials,
26
+ model_configs: { ...credentials.model_configs, [model]: config },
27
+ provider_credentials: plan === undefined ? others : { ...others, [model]: plan },
28
+ };
29
+ }
@@ -10,6 +10,8 @@ const PROVIDER_LABELS = {
10
10
  xai: "xAI",
11
11
  google: "Google",
12
12
  "opencode-go": "OpenCode Go",
13
+ "github-copilot": "GitHub Copilot",
14
+ "vercel-token-pass": "Vercel Token Pass",
13
15
  dari: "Dari",
14
16
  "amazon-bedrock": "Amazon Bedrock",
15
17
  azure: "Microsoft Azure",
@@ -34,6 +36,13 @@ const PROVIDER_BASE_URLS = {
34
36
  // A flat-rate plan for open models; each model keeps its own API path
35
37
  // under https://opencode.ai/inference/go/, and this is chat completions.
36
38
  "opencode-go": "https://opencode.ai/inference/go/openai/v1",
39
+ // Flat plans served only by personal subscriptions. Each Copilot account
40
+ // has its own API origin, named in its token (see github_copilot.ts); this
41
+ // one is the individual plans'.
42
+ "github-copilot": "https://api.individual.githubcopilot.com",
43
+ // A Token Pass key on Vercel AI Gateway, which serves only the gateway's
44
+ // featured models, over Anthropic Messages.
45
+ "vercel-token-pass": "https://ai-gateway.vercel.sh",
37
46
  // Meta's Model API serves OpenAI Responses and Chat Completions here, and
38
47
  // Anthropic Messages at https://api.meta.ai.
39
48
  meta: "https://api.meta.ai/v1",
@@ -1,4 +1,137 @@
1
1
  [
2
+ {
3
+ "model_id": "openai/gpt-6.2-astra",
4
+ "provider": "github-copilot",
5
+ "native_model_id": "gpt-6.2-astra",
6
+ "api": "openai-responses",
7
+ "base_url": "https://api.individual.githubcopilot.com"
8
+ },
9
+ {
10
+ "model_id": "openai/gpt-6-astra",
11
+ "provider": "github-copilot",
12
+ "native_model_id": "gpt-6-astra",
13
+ "api": "openai-responses",
14
+ "base_url": "https://api.individual.githubcopilot.com"
15
+ },
16
+ {
17
+ "model_id": "openai/gpt-6.1-terra",
18
+ "provider": "github-copilot",
19
+ "native_model_id": "gpt-6.1-terra",
20
+ "api": "openai-responses",
21
+ "base_url": "https://api.individual.githubcopilot.com"
22
+ },
23
+ {
24
+ "model_id": "openai/gpt-6.2-sol",
25
+ "provider": "github-copilot",
26
+ "native_model_id": "gpt-6.2-sol",
27
+ "api": "openai-responses",
28
+ "base_url": "https://api.individual.githubcopilot.com"
29
+ },
30
+ {
31
+ "model_id": "openai/gpt-6.1-sol",
32
+ "provider": "github-copilot",
33
+ "native_model_id": "gpt-6.1-sol",
34
+ "api": "openai-responses",
35
+ "base_url": "https://api.individual.githubcopilot.com"
36
+ },
37
+ {
38
+ "model_id": "openai/gpt-6-sol",
39
+ "provider": "github-copilot",
40
+ "native_model_id": "gpt-6-sol",
41
+ "api": "openai-responses",
42
+ "base_url": "https://api.individual.githubcopilot.com"
43
+ },
44
+ {
45
+ "model_id": "openai/gpt-6-luna",
46
+ "provider": "github-copilot",
47
+ "native_model_id": "gpt-6-luna",
48
+ "api": "openai-responses",
49
+ "base_url": "https://api.individual.githubcopilot.com"
50
+ },
51
+ {
52
+ "model_id": "openai/gpt-5.6-sol",
53
+ "provider": "github-copilot",
54
+ "native_model_id": "gpt-5.6-sol",
55
+ "api": "openai-responses",
56
+ "base_url": "https://api.individual.githubcopilot.com"
57
+ },
58
+ {
59
+ "model_id": "openai/gpt-5.6-terra",
60
+ "provider": "github-copilot",
61
+ "native_model_id": "gpt-5.6-terra",
62
+ "api": "openai-responses",
63
+ "base_url": "https://api.individual.githubcopilot.com"
64
+ },
65
+ {
66
+ "model_id": "openai/gpt-5.6-luna",
67
+ "provider": "github-copilot",
68
+ "native_model_id": "gpt-5.6-luna",
69
+ "api": "openai-responses",
70
+ "base_url": "https://api.individual.githubcopilot.com"
71
+ },
72
+ {
73
+ "model_id": "anthropic/claude-opus-5-5",
74
+ "provider": "github-copilot",
75
+ "native_model_id": "claude-opus-5.5",
76
+ "api": "anthropic-messages",
77
+ "base_url": "https://api.individual.githubcopilot.com"
78
+ },
79
+ {
80
+ "model_id": "anthropic/claude-opus-5",
81
+ "provider": "github-copilot",
82
+ "native_model_id": "claude-opus-5",
83
+ "api": "anthropic-messages",
84
+ "base_url": "https://api.individual.githubcopilot.com"
85
+ },
86
+ {
87
+ "model_id": "anthropic/claude-sonnet-5-5",
88
+ "provider": "github-copilot",
89
+ "native_model_id": "claude-sonnet-5.5",
90
+ "api": "anthropic-messages",
91
+ "base_url": "https://api.individual.githubcopilot.com"
92
+ },
93
+ {
94
+ "model_id": "anthropic/claude-sonnet-5",
95
+ "provider": "github-copilot",
96
+ "native_model_id": "claude-sonnet-5",
97
+ "api": "anthropic-messages",
98
+ "base_url": "https://api.individual.githubcopilot.com"
99
+ },
100
+ {
101
+ "model_id": "anthropic/claude-fable-5-2",
102
+ "provider": "github-copilot",
103
+ "native_model_id": "claude-fable-5.2",
104
+ "api": "anthropic-messages",
105
+ "base_url": "https://api.individual.githubcopilot.com"
106
+ },
107
+ {
108
+ "model_id": "anthropic/claude-fable-5-1",
109
+ "provider": "github-copilot",
110
+ "native_model_id": "claude-fable-5.1",
111
+ "api": "anthropic-messages",
112
+ "base_url": "https://api.individual.githubcopilot.com"
113
+ },
114
+ {
115
+ "model_id": "anthropic/claude-fable-5",
116
+ "provider": "github-copilot",
117
+ "native_model_id": "claude-fable-5",
118
+ "api": "anthropic-messages",
119
+ "base_url": "https://api.individual.githubcopilot.com"
120
+ },
121
+ {
122
+ "model_id": "anthropic/claude-haiku-5-5",
123
+ "provider": "github-copilot",
124
+ "native_model_id": "claude-haiku-5.5",
125
+ "api": "anthropic-messages",
126
+ "base_url": "https://api.individual.githubcopilot.com"
127
+ },
128
+ {
129
+ "model_id": "anthropic/claude-haiku-4-5",
130
+ "provider": "github-copilot",
131
+ "native_model_id": "claude-haiku-4.5",
132
+ "api": "anthropic-messages",
133
+ "base_url": "https://api.individual.githubcopilot.com"
134
+ },
2
135
  {
3
136
  "model_id": "meta/muse-spark-open",
4
137
  "provider": "fireworks",
@@ -55,6 +188,13 @@
55
188
  "api": "openai-completions",
56
189
  "base_url": "https://api.fireworks.ai/inference/v1"
57
190
  },
191
+ {
192
+ "model_id": "deepseek-ai/DeepSeek-V4.1-Flash",
193
+ "provider": "vercel-token-pass",
194
+ "native_model_id": "deepseek/deepseek-v4.1-flash",
195
+ "api": "anthropic-messages",
196
+ "base_url": "https://ai-gateway.vercel.sh"
197
+ },
58
198
  {
59
199
  "model_id": "deepseek-ai/DeepSeek-V4.1-Flash-1017",
60
200
  "provider": "fireworks",
@@ -62,6 +202,20 @@
62
202
  "api": "openai-completions",
63
203
  "base_url": "https://api.fireworks.ai/inference/v1"
64
204
  },
205
+ {
206
+ "model_id": "xai/grok-4.6",
207
+ "provider": "github-copilot",
208
+ "native_model_id": "grok-4.6",
209
+ "api": "openai-responses",
210
+ "base_url": "https://api.individual.githubcopilot.com"
211
+ },
212
+ {
213
+ "model_id": "xai/grok-4.7",
214
+ "provider": "github-copilot",
215
+ "native_model_id": "grok-4.7",
216
+ "api": "openai-responses",
217
+ "base_url": "https://api.individual.githubcopilot.com"
218
+ },
65
219
  {
66
220
  "model_id": "moonshotai/Kimi-K3",
67
221
  "provider": "opencode-go",
@@ -69,6 +223,20 @@
69
223
  "api": "openai-completions",
70
224
  "base_url": "https://opencode.ai/inference/go/openai/v1"
71
225
  },
226
+ {
227
+ "model_id": "moonshotai/Kimi-K3",
228
+ "provider": "github-copilot",
229
+ "native_model_id": "kimi-k3",
230
+ "api": "openai-completions",
231
+ "base_url": "https://api.individual.githubcopilot.com"
232
+ },
233
+ {
234
+ "model_id": "moonshotai/Kimi-K3",
235
+ "provider": "vercel-token-pass",
236
+ "native_model_id": "moonshotai/kimi-k3",
237
+ "api": "anthropic-messages",
238
+ "base_url": "https://ai-gateway.vercel.sh"
239
+ },
72
240
  {
73
241
  "model_id": "moonshotai/Kimi-K3.1-Pro",
74
242
  "provider": "fireworks",
@@ -83,6 +251,13 @@
83
251
  "api": "openai-completions",
84
252
  "base_url": "https://opencode.ai/inference/go/openai/v1"
85
253
  },
254
+ {
255
+ "model_id": "moonshotai/Kimi-K3.1-Pro",
256
+ "provider": "vercel-token-pass",
257
+ "native_model_id": "moonshotai/kimi-k3.1-pro",
258
+ "api": "anthropic-messages",
259
+ "base_url": "https://ai-gateway.vercel.sh"
260
+ },
86
261
  {
87
262
  "model_id": "zai-org/GLM-5.3",
88
263
  "provider": "opencode-go",
@@ -90,6 +265,13 @@
90
265
  "api": "openai-completions",
91
266
  "base_url": "https://opencode.ai/inference/go/openai/v1"
92
267
  },
268
+ {
269
+ "model_id": "zai-org/GLM-5.3",
270
+ "provider": "vercel-token-pass",
271
+ "native_model_id": "zai/glm-5.3",
272
+ "api": "anthropic-messages",
273
+ "base_url": "https://ai-gateway.vercel.sh"
274
+ },
93
275
  {
94
276
  "model_id": "zai-org/GLM-5.3-Flash",
95
277
  "provider": "opencode-go",
@@ -97,6 +279,13 @@
97
279
  "api": "openai-completions",
98
280
  "base_url": "https://opencode.ai/inference/go/openai/v1"
99
281
  },
282
+ {
283
+ "model_id": "zai-org/GLM-5.3-Flash",
284
+ "provider": "vercel-token-pass",
285
+ "native_model_id": "zai/glm-5.3-flash",
286
+ "api": "anthropic-messages",
287
+ "base_url": "https://ai-gateway.vercel.sh"
288
+ },
100
289
  {
101
290
  "model_id": "zai-org/GLM-5.2",
102
291
  "provider": "opencode-go",
@@ -110,5 +299,33 @@
110
299
  "native_model_id": "deepseek-v4.1-flash",
111
300
  "api": "openai-completions",
112
301
  "base_url": "https://opencode.ai/inference/go/openai/v1"
302
+ },
303
+ {
304
+ "model_id": "google/gemini-4-argon",
305
+ "provider": "github-copilot",
306
+ "native_model_id": "gemini-4-argon",
307
+ "api": "openai-completions",
308
+ "base_url": "https://api.individual.githubcopilot.com"
309
+ },
310
+ {
311
+ "model_id": "google/gemini-4-carbon",
312
+ "provider": "github-copilot",
313
+ "native_model_id": "gemini-4-carbon",
314
+ "api": "openai-completions",
315
+ "base_url": "https://api.individual.githubcopilot.com"
316
+ },
317
+ {
318
+ "model_id": "google/gemini-4-hydrogen",
319
+ "provider": "github-copilot",
320
+ "native_model_id": "gemini-4-hydrogen",
321
+ "api": "openai-completions",
322
+ "base_url": "https://api.individual.githubcopilot.com"
323
+ },
324
+ {
325
+ "model_id": "google/gemini-3.8-flash",
326
+ "provider": "github-copilot",
327
+ "native_model_id": "gemini-3.8-flash",
328
+ "api": "openai-completions",
329
+ "base_url": "https://api.individual.githubcopilot.com"
113
330
  }
114
331
  ]
@@ -2,6 +2,11 @@ import { type RouterModelPrice } from "@mupt-ai/dari-router/policy-engine";
2
2
  import type { ClientHarness, ResolvedRouterModelConfig, SubscriptionKind } from "../types.js";
3
3
  /** The model provider whose models a plan serves, such as `openai`. */
4
4
  export declare function subscriptionModelProvider(kind: SubscriptionKind): string;
5
+ /**
6
+ * The plans that can serve a model, in the order they serve it: each whose
7
+ * provider is the model's maker or serves it as its own model.
8
+ */
9
+ export declare function modelSubscriptions(modelId: string): SubscriptionKind[];
5
10
  /**
6
11
  * The only client a plan may serve, or undefined when it serves any client:
7
12
  * ChatGPT plans serve any client through the Codex backend.
@@ -1,13 +1,21 @@
1
- import { nativeModelId } from "@mupt-ai/dari-router/policy-engine";
1
+ import { nativeModelId, providerForModel } from "@mupt-ai/dari-router/policy-engine";
2
+ import { providerModel } from "./canonical.js";
2
3
  const CODEX_BACKEND_URL = "https://chatgpt.com/backend-api";
3
4
  // The execution providers whose models each kind of plan serves; a ChatGPT
4
5
  // plan's OpenAI models execute as `openai-codex` once resolve points them at
5
6
  // the Codex backend.
7
+ //
8
+ // The order is the order a model's plans serve it in, maker plans first, then
9
+ // the router's API credential. It matches the control plane's
10
+ // SUBSCRIPTION_OAUTH_PROVIDERS; keep the two in sync.
6
11
  const SUBSCRIPTION_MODEL_PROVIDERS = {
7
- openai_codex: ["openai", "openai-codex"],
8
12
  anthropic_claude_code: ["anthropic"],
13
+ openai_codex: ["openai", "openai-codex"],
14
+ xai_grok: ["xai"],
9
15
  meta_muse: ["meta"],
10
16
  opencode_go: ["opencode-go"],
17
+ github_copilot: ["github-copilot"],
18
+ vercel_token_pass: ["vercel-token-pass"],
11
19
  };
12
20
  // The client each plan is limited to, as its provider limits it: a Claude Code
13
21
  // plan serves only Claude Code, and a Muse Code plan only Muse Code.
@@ -19,6 +27,17 @@ const SUBSCRIPTION_CLIENTS = {
19
27
  export function subscriptionModelProvider(kind) {
20
28
  return SUBSCRIPTION_MODEL_PROVIDERS[kind][0];
21
29
  }
30
+ /**
31
+ * The plans that can serve a model, in the order they serve it: each whose
32
+ * provider is the model's maker or serves it as its own model.
33
+ */
34
+ export function modelSubscriptions(modelId) {
35
+ const maker = providerForModel(modelId);
36
+ return Object.keys(SUBSCRIPTION_MODEL_PROVIDERS).filter((kind) => {
37
+ const provider = subscriptionModelProvider(kind);
38
+ return provider === maker || providerModel(modelId, provider) !== undefined;
39
+ });
40
+ }
22
41
  /**
23
42
  * The only client a plan may serve, or undefined when it serves any client:
24
43
  * ChatGPT plans serve any client through the Codex backend.
@@ -281,8 +281,6 @@ export type LinkApprovalPage = {
281
281
  connections(subject: string): Promise<LinkConnection[]>;
282
282
  /** The user ends one of their grants; false when they have none by that id. */
283
283
  disconnect(subject: string, grantId: string): Promise<boolean>;
284
- /** Replace one of the user's grants' budget (empty removes it); false when they have none by that id. */
285
- setBudget(subject: string, grantId: string, budget: LinkBudget[]): Promise<boolean>;
286
284
  /** Replace one of the user's grants' monthly spend limits; false when they have none by that id. */
287
285
  setLimits(subject: string, grantId: string, limits: LinkLimit[]): Promise<boolean>;
288
286
  };
@@ -336,20 +334,26 @@ export type LinkBudget = {
336
334
  maxTokens: number;
337
335
  };
338
336
  /**
339
- * The most a grant may spend on one of its plans or API keys in a calendar
340
- * month (UTC), in US dollars. A plan's spend is what its requests would have
341
- * cost at API prices. See link/budget.ts.
337
+ * A grant's limit on one of its plans or API keys; exactly one field is set.
338
+ * A plan leaves the grant while any of its plan-wide quota windows is at
339
+ * `maxPercent` used, whoever used it, until that window resets: the rest is
340
+ * the user's. An API key leaves it once the grant's spend on it this calendar
341
+ * month (UTC) reaches `monthlyUsd`. See link/budget.ts.
342
342
  */
343
343
  export type LinkLimit = {
344
344
  credentialId: string;
345
- monthlyUsd: number;
345
+ maxPercent?: number;
346
+ monthlyUsd?: number;
346
347
  };
347
- /** A granted plan or key's spend this month, and its limit when it has one. */
348
+ /** A granted plan or key's spend and standing, and its limit when it has one. */
348
349
  export type LinkSpend = {
349
350
  credentialId: string;
350
351
  spentUsd: number;
351
352
  monthlyUsd: number | null;
353
+ maxPercent: number | null;
354
+ usedPercent: number | null;
352
355
  reached: boolean;
356
+ resetsAt: string | null;
353
357
  };
354
358
  /** A budget window as it stands for a grant. */
355
359
  export type LinkBudgetStanding = {
@@ -7,7 +7,9 @@ import { type ProviderExecution, type StartedCompletion, type StartedStream } fr
7
7
  export type ProviderChoice = {
8
8
  decision: RoutingDecision;
9
9
  execution: ProviderExecution;
10
+ fallback?: number;
10
11
  };
12
+ export type NextProviderChoice = (choice: ProviderChoice) => Promise<ProviderChoice | undefined>;
11
13
  export type PreparedStreamExecution = {
12
14
  choice: ProviderChoice;
13
15
  started: StartedStream;
@@ -25,6 +27,7 @@ export declare function executeNonStreaming(args: {
25
27
  interaction: InteractionRequest;
26
28
  primary: ProviderChoice;
27
29
  primaryRetries: number;
30
+ nextChoice?: NextProviderChoice;
28
31
  reporter: RoutedRuntimeReporter;
29
32
  protocol: RoutedProtocol;
30
33
  startedCompletion?: StartedCompletion;
@@ -36,6 +39,7 @@ export declare function completeNonStreaming(args: {
36
39
  interaction: InteractionRequest;
37
40
  primary: ProviderChoice;
38
41
  primaryRetries: number;
42
+ nextChoice?: NextProviderChoice;
39
43
  reporter: RoutedRuntimeReporter;
40
44
  protocol: RoutedProtocol;
41
45
  startedCompletion?: StartedCompletion;
@@ -47,6 +51,7 @@ export declare function prepareStreamingExecution(args: {
47
51
  interaction: InteractionRequest;
48
52
  primary: ProviderChoice;
49
53
  primaryRetries: number;
54
+ nextChoice?: NextProviderChoice;
50
55
  reporter: RoutedRuntimeReporter;
51
56
  startedStream?: StartedStream;
52
57
  initialError?: unknown;