@mupt-ai/dari-gateway 1.0.365 → 1.0.367

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 (52) hide show
  1. package/README.md +1 -1
  2. package/dist/activity/conversation_detail.js +8 -0
  3. package/dist/link/endpoints.js +5 -25
  4. package/dist/link/service.d.ts +1 -3
  5. package/dist/link/service.js +0 -1
  6. package/dist/models/canonical.d.ts +7 -1
  7. package/dist/models/canonical.js +9 -1
  8. package/dist/models/canonical_models.json +151 -0
  9. package/dist/models/provider_models.json +476 -0
  10. package/dist/platform/platform.d.ts +1 -11
  11. package/dist/protocol/input/anthropic_messages.js +3 -4
  12. package/dist/providers/execution.js +1 -0
  13. package/dist/providers/provider_call.d.ts +1 -0
  14. package/dist/providers/provider_call.js +1 -0
  15. package/dist/runtime/runtime_reporter.d.ts +1 -0
  16. package/dist/runtime/runtime_reporter.js +1 -0
  17. package/dist/self_host/config.d.ts +5 -0
  18. package/dist/self_host/config.js +8 -1
  19. package/dist/self_host/connected.d.ts +5 -4
  20. package/dist/self_host/hosted_sync.d.ts +14 -23
  21. package/dist/self_host/hosted_sync.js +56 -120
  22. package/dist/self_host/main.js +2 -5
  23. package/dist/self_host/platform.js +2 -0
  24. package/dist/self_host/resolve.js +24 -12
  25. package/dist/self_host/subscriptions/index.d.ts +1 -1
  26. package/dist/self_host/subscriptions/index.js +1 -1
  27. package/dist/self_host/subscriptions/store.d.ts +8 -6
  28. package/dist/self_host/subscriptions/store.js +8 -16
  29. package/dist/telemetry/report.js +8 -1
  30. package/dist/types.d.ts +1 -0
  31. package/package.json +2 -2
  32. package/src/activity/conversation_detail.ts +8 -0
  33. package/src/link/endpoints.ts +4 -29
  34. package/src/link/service.ts +0 -4
  35. package/src/models/canonical.ts +15 -1
  36. package/src/models/canonical_models.json +151 -0
  37. package/src/models/provider_models.json +476 -0
  38. package/src/platform/platform.ts +2 -9
  39. package/src/protocol/input/anthropic_messages.ts +3 -9
  40. package/src/providers/execution.ts +1 -0
  41. package/src/providers/provider_call.ts +3 -0
  42. package/src/runtime/runtime_reporter.ts +3 -1
  43. package/src/self_host/config.ts +9 -1
  44. package/src/self_host/connected.ts +5 -4
  45. package/src/self_host/hosted_sync.ts +51 -121
  46. package/src/self_host/main.ts +2 -5
  47. package/src/self_host/platform.ts +2 -1
  48. package/src/self_host/resolve.ts +19 -7
  49. package/src/self_host/subscriptions/index.ts +1 -0
  50. package/src/self_host/subscriptions/store.ts +14 -18
  51. package/src/telemetry/report.ts +8 -1
  52. package/src/types.ts +3 -0
@@ -55,6 +55,13 @@ function agentContext(record: ConversationRecord): AgentContext {
55
55
  };
56
56
  }
57
57
 
58
+ /** The name of the plan that served the request, when one did. */
59
+ function subscriptionAccount(record: ConversationRecord): string | null {
60
+ const metadata = record.requestMetadata;
61
+ if (metadata === null || typeof metadata !== "object" || Array.isArray(metadata)) return null;
62
+ return readOptionalString((metadata as Record<string, unknown>).subscription_account);
63
+ }
64
+
58
65
  function routePath(records: readonly ConversationRecord[]) {
59
66
  const path: Array<{ model: string; thinking_level: string | null }> = [];
60
67
  for (const record of records) {
@@ -211,6 +218,7 @@ function conversationStep(record: ConversationRecord, organizationId: string, cu
211
218
  selected_model: record.selectedModel,
212
219
  selected_reasoning_effort: effort,
213
220
  selected_provider: record.selectedProvider,
221
+ subscription_account: subscriptionAccount(record),
214
222
  provider_input_tokens: record.providerInputTokens,
215
223
  provider_cache_read_tokens: record.providerCacheReadTokens,
216
224
  provider_cache_write_tokens: record.providerCacheWriteTokens,
@@ -1324,32 +1324,9 @@ async function homePage(approval: LinkApprovalPage, authorize: AuthorizeRequest,
1324
1324
  if (current instanceof Response) return current;
1325
1325
  if (session === null) return introPage(approval, authorize);
1326
1326
  const subscriptions = await approval.subscriptions(session.subject);
1327
- const onComputers = await plansOnComputersNote(approval, authorize, session.subject, subscriptions);
1328
1327
  return shareable(authorize, subscriptions).length > 0
1329
- ? choosePage(authorize, session, subscriptions, current, undefined, onComputers)
1330
- : introPage(approval, authorize, onComputers);
1331
- }
1332
-
1333
- // Where the user keeps a plan the app could use on one of their computers,
1334
- // for each kind they have no plan of here: apps reach only the platform's.
1335
- async function plansOnComputersNote(
1336
- approval: LinkApprovalPage,
1337
- authorize: AuthorizeRequest,
1338
- subject: string,
1339
- subscriptions: LinkSubscription[],
1340
- ): Promise<string> {
1341
- if (approval.plansOnComputers === undefined) return "";
1342
- const here = new Set(subscriptions.map((subscription) => subscription.provider));
1343
- const usable = new Set(connectKinds(approval, authorize));
1344
- const computers = new Map<SubscriptionKind, string[]>();
1345
- for (const plan of await approval.plansOnComputers(subject)) {
1346
- if (here.has(plan.provider) || !usable.has(plan.provider)) continue;
1347
- const names = computers.get(plan.provider) ?? [];
1348
- if (!names.includes(plan.computer)) names.push(plan.computer);
1349
- computers.set(plan.provider, names);
1350
- }
1351
- return [...computers].map(([kind, names]) =>
1352
- `<p class="hint">Your ${KINDS[kind].name} plan is on ${escapeHtml(names.join(" and "))}. Apps can only use plans on Dari.</p>`).join("\n");
1328
+ ? choosePage(authorize, session, subscriptions, current)
1329
+ : introPage(approval, authorize);
1353
1330
  }
1354
1331
 
1355
1332
  // In update mode, the grant being changed. A grant this browser's user does
@@ -1887,7 +1864,7 @@ const KINDS: Record<SubscriptionKind, { name: string; plan: string; at: string;
1887
1864
  };
1888
1865
 
1889
1866
  // The first page a new user sees: what connecting means, and one button.
1890
- function introPage(approval: LinkApprovalPage, authorize: AuthorizeRequest, onComputers = ""): Response {
1867
+ function introPage(approval: LinkApprovalPage, authorize: AuthorizeRequest): Response {
1891
1868
  const app = escapeHtml(authorize.app.name);
1892
1869
  const kinds = connectKinds(approval, authorize);
1893
1870
  const keys = keyProviders(approval, authorize);
@@ -1909,7 +1886,7 @@ function introPage(approval: LinkApprovalPage, authorize: AuthorizeRequest, onCo
1909
1886
  <ul class="points">
1910
1887
  <li>${ICONS.zap}<div><strong>Connect In Seconds</strong><p>${kinds.length > 0 ? `Use what you already pay for: ${escapeHtml(ways)}.` : "Add the API key you already have."}</p></div></li>
1911
1888
  <li>${ICONS.shield}<div><strong>You Stay In Control</strong><p>${app} can only send model requests on what you share. It sees each shared plan's account email, never a key or your other plans, and you can disconnect it any time.</p></div></li>
1912
- </ul>${onComputers}`,
1889
+ </ul>`,
1913
1890
  footer: `<button class="btn primary" type="submit" name="decision" value="select">Continue</button>`,
1914
1891
  });
1915
1892
  }
@@ -2006,7 +1983,6 @@ function choosePage(
2006
1983
  subscriptions: LinkSubscription[],
2007
1984
  current: GrantToUpdate | null,
2008
1985
  error?: string,
2009
- onComputers = "",
2010
1986
  ): Response {
2011
1987
  const app = escapeHtml(authorize.app.name);
2012
1988
  const plans = shareable(authorize, subscriptions);
@@ -2021,7 +1997,6 @@ function choosePage(
2021
1997
  <!-- First in the form, so Enter in a limit field allows rather than pressing Connect Another. -->
2022
1998
  <button type="submit" name="decision" value="approve" tabindex="-1" aria-hidden="true" style="position:absolute;left:-9999px"></button>
2023
1999
  ${plans.map((plan) => planOption(authorize, plan, ticked.has(plan.id))).join("\n")}
2024
- ${onComputers}
2025
2000
  <details${current?.limits.length ? " open" : ""}><summary>Set Limits</summary>
2026
2001
  ${plans.map((plan) => {
2027
2002
  const set = current?.limits.find((limit) => limit.credentialId === plan.id);
@@ -22,7 +22,6 @@ import type {
22
22
  LinkLimit,
23
23
  LinkManagedGrant,
24
24
  LinkPlanAdded,
25
- LinkPlanOnComputer,
26
25
  LinkPlatform,
27
26
  LinkSignIn,
28
27
  LinkSpend,
@@ -150,8 +149,6 @@ export type LinkUsers = {
150
149
  completeThrough(grantId: string): string | null;
151
150
  /** A user's plans and API keys, oldest first. */
152
151
  plans(subject: string): Promise<LinkSubscription[]>;
153
- /** See `LinkApprovalPage.plansOnComputers`. */
154
- plansOnComputers?(subject: string): Promise<LinkPlanOnComputer[]>;
155
152
  /** The plans and API keys with these ids, whoever added them. */
156
153
  plansWithIds(ids: readonly string[]): Promise<LinkSubscription[]>;
157
154
  /** See `LinkApprovalPage.addKey`; the provider is one of `keyProviders`. */
@@ -241,7 +238,6 @@ export function linkPlatform(store: LinkStore, users: LinkUsers): LinkPlatform {
241
238
  connectable: users.connectable,
242
239
  keyProviders: users.keyProviders,
243
240
  subscriptions: (subject) => users.plans(subject),
244
- ...(users.plansOnComputers === undefined ? {} : { plansOnComputers: users.plansOnComputers }),
245
241
  async addKey(subject, provider, apiKey) {
246
242
  if (!users.keyProviders.some((candidate) => candidate.id === provider)) {
247
243
  throw new HttpError(400, "Choose a provider to add a key for.", "invalid_request");
@@ -1,3 +1,5 @@
1
+ import { providerForModel } from "@mupt-ai/dari-router/policy-engine";
2
+
1
3
  import canonicalModels from "./canonical_models.json" with { type: "json" };
2
4
  import providerModels from "./provider_models.json" with { type: "json" };
3
5
 
@@ -9,6 +11,10 @@ export type CanonicalModel = {
9
11
  maker: string;
10
12
  // The default provider's accepted thinking levels.
11
13
  thinking_levels: string[];
14
+ // The providers whose API keys serve it when a router spec names none, in
15
+ // order: the provider its id names, alone, when that one serves it; else
16
+ // every provider and gateway that runs it.
17
+ providers: string[];
12
18
  };
13
19
 
14
20
  /** The canonical models Dari serves, from the monorepo's router catalog. */
@@ -19,6 +25,14 @@ export function canonicalModelName(id: string): string {
19
25
  return CANONICAL_MODELS.find((model) => model.id === id)?.name ?? id;
20
26
  }
21
27
 
28
+ /**
29
+ * The providers whose API keys may serve a model a router spec names no
30
+ * provider for; a model the catalog does not list is its id's provider's.
31
+ */
32
+ export function modelKeyProviders(id: string): string[] {
33
+ return CANONICAL_MODELS.find((model) => model.id === id)?.providers ?? [providerForModel(id)];
34
+ }
35
+
22
36
  /** A canonical model as a provider other than the one its id names serves it. */
23
37
  export type ProviderModel = {
24
38
  model_id: string;
@@ -35,7 +49,7 @@ export function providerModel(modelId: string, provider: string): ProviderModel
35
49
  return PROVIDER_MODELS.find((row) => row.model_id === modelId && row.provider === provider);
36
50
  }
37
51
 
38
- /** The providers besides the one its id names that serve a model. */
52
+ /** The providers and gateways besides the one its id names that serve a model. */
39
53
  export function otherModelProviders(modelId: string): string[] {
40
54
  return PROVIDER_MODELS.filter((row) => row.model_id === modelId).map((row) => row.provider);
41
55
  }
@@ -9,6 +9,9 @@
9
9
  "high",
10
10
  "xhigh",
11
11
  "max"
12
+ ],
13
+ "providers": [
14
+ "openai"
12
15
  ]
13
16
  },
14
17
  {
@@ -21,6 +24,9 @@
21
24
  "high",
22
25
  "xhigh",
23
26
  "max"
27
+ ],
28
+ "providers": [
29
+ "openai"
24
30
  ]
25
31
  },
26
32
  {
@@ -34,6 +40,9 @@
34
40
  "high",
35
41
  "xhigh",
36
42
  "max"
43
+ ],
44
+ "providers": [
45
+ "openai"
37
46
  ]
38
47
  },
39
48
  {
@@ -46,6 +55,9 @@
46
55
  "high",
47
56
  "xhigh",
48
57
  "max"
58
+ ],
59
+ "providers": [
60
+ "openai"
49
61
  ]
50
62
  },
51
63
  {
@@ -59,6 +71,9 @@
59
71
  "high",
60
72
  "xhigh",
61
73
  "max"
74
+ ],
75
+ "providers": [
76
+ "openai"
62
77
  ]
63
78
  },
64
79
  {
@@ -72,6 +87,9 @@
72
87
  "high",
73
88
  "xhigh",
74
89
  "max"
90
+ ],
91
+ "providers": [
92
+ "openai"
75
93
  ]
76
94
  },
77
95
  {
@@ -85,6 +103,9 @@
85
103
  "high",
86
104
  "xhigh",
87
105
  "max"
106
+ ],
107
+ "providers": [
108
+ "openai"
88
109
  ]
89
110
  },
90
111
  {
@@ -98,6 +119,9 @@
98
119
  "high",
99
120
  "xhigh",
100
121
  "max"
122
+ ],
123
+ "providers": [
124
+ "openai"
101
125
  ]
102
126
  },
103
127
  {
@@ -111,6 +135,9 @@
111
135
  "high",
112
136
  "xhigh",
113
137
  "max"
138
+ ],
139
+ "providers": [
140
+ "openai"
114
141
  ]
115
142
  },
116
143
  {
@@ -124,6 +151,9 @@
124
151
  "high",
125
152
  "xhigh",
126
153
  "max"
154
+ ],
155
+ "providers": [
156
+ "openai"
127
157
  ]
128
158
  },
129
159
  {
@@ -137,6 +167,9 @@
137
167
  "high",
138
168
  "xhigh",
139
169
  "max"
170
+ ],
171
+ "providers": [
172
+ "anthropic"
140
173
  ]
141
174
  },
142
175
  {
@@ -150,6 +183,9 @@
150
183
  "high",
151
184
  "xhigh",
152
185
  "max"
186
+ ],
187
+ "providers": [
188
+ "anthropic"
153
189
  ]
154
190
  },
155
191
  {
@@ -162,6 +198,9 @@
162
198
  "high",
163
199
  "xhigh",
164
200
  "max"
201
+ ],
202
+ "providers": [
203
+ "anthropic"
165
204
  ]
166
205
  },
167
206
  {
@@ -175,6 +214,9 @@
175
214
  "high",
176
215
  "xhigh",
177
216
  "max"
217
+ ],
218
+ "providers": [
219
+ "anthropic"
178
220
  ]
179
221
  },
180
222
  {
@@ -187,6 +229,9 @@
187
229
  "high",
188
230
  "xhigh",
189
231
  "max"
232
+ ],
233
+ "providers": [
234
+ "anthropic"
190
235
  ]
191
236
  },
192
237
  {
@@ -199,6 +244,9 @@
199
244
  "high",
200
245
  "xhigh",
201
246
  "max"
247
+ ],
248
+ "providers": [
249
+ "anthropic"
202
250
  ]
203
251
  },
204
252
  {
@@ -211,6 +259,9 @@
211
259
  "high",
212
260
  "xhigh",
213
261
  "max"
262
+ ],
263
+ "providers": [
264
+ "anthropic"
214
265
  ]
215
266
  },
216
267
  {
@@ -223,6 +274,9 @@
223
274
  "high",
224
275
  "xhigh",
225
276
  "max"
277
+ ],
278
+ "providers": [
279
+ "anthropic"
226
280
  ]
227
281
  },
228
282
  {
@@ -234,6 +288,9 @@
234
288
  "low",
235
289
  "medium",
236
290
  "high"
291
+ ],
292
+ "providers": [
293
+ "anthropic"
237
294
  ]
238
295
  },
239
296
  {
@@ -247,6 +304,9 @@
247
304
  "high",
248
305
  "xhigh",
249
306
  "max"
307
+ ],
308
+ "providers": [
309
+ "meta"
250
310
  ]
251
311
  },
252
312
  {
@@ -260,6 +320,9 @@
260
320
  "high",
261
321
  "xhigh",
262
322
  "max"
323
+ ],
324
+ "providers": [
325
+ "meta"
263
326
  ]
264
327
  },
265
328
  {
@@ -273,6 +336,9 @@
273
336
  "high",
274
337
  "xhigh",
275
338
  "max"
339
+ ],
340
+ "providers": [
341
+ "meta"
276
342
  ]
277
343
  },
278
344
  {
@@ -284,6 +350,11 @@
284
350
  "medium",
285
351
  "high",
286
352
  "xhigh"
353
+ ],
354
+ "providers": [
355
+ "fireworks",
356
+ "openrouter",
357
+ "vercel-ai-gateway"
287
358
  ]
288
359
  },
289
360
  {
@@ -296,6 +367,9 @@
296
367
  "medium",
297
368
  "high",
298
369
  "xhigh"
370
+ ],
371
+ "providers": [
372
+ "meta"
299
373
  ]
300
374
  },
301
375
  {
@@ -306,6 +380,13 @@
306
380
  "low",
307
381
  "high",
308
382
  "max"
383
+ ],
384
+ "providers": [
385
+ "fireworks",
386
+ "opencode-go",
387
+ "vercel-token-pass",
388
+ "openrouter",
389
+ "vercel-ai-gateway"
309
390
  ]
310
391
  },
311
392
  {
@@ -316,6 +397,13 @@
316
397
  "low",
317
398
  "high",
318
399
  "max"
400
+ ],
401
+ "providers": [
402
+ "fireworks",
403
+ "opencode-go",
404
+ "vercel-token-pass",
405
+ "openrouter",
406
+ "vercel-ai-gateway"
319
407
  ]
320
408
  },
321
409
  {
@@ -326,6 +414,13 @@
326
414
  "low",
327
415
  "high",
328
416
  "max"
417
+ ],
418
+ "providers": [
419
+ "fireworks",
420
+ "opencode-go",
421
+ "vercel-token-pass",
422
+ "openrouter",
423
+ "vercel-ai-gateway"
329
424
  ]
330
425
  },
331
426
  {
@@ -336,6 +431,13 @@
336
431
  "low",
337
432
  "high",
338
433
  "max"
434
+ ],
435
+ "providers": [
436
+ "fireworks",
437
+ "opencode-go",
438
+ "vercel-token-pass",
439
+ "openrouter",
440
+ "vercel-ai-gateway"
339
441
  ]
340
442
  },
341
443
  {
@@ -346,6 +448,11 @@
346
448
  "off",
347
449
  "high",
348
450
  "max"
451
+ ],
452
+ "providers": [
453
+ "fireworks",
454
+ "openrouter",
455
+ "vercel-ai-gateway"
349
456
  ]
350
457
  },
351
458
  {
@@ -356,6 +463,12 @@
356
463
  "off",
357
464
  "high",
358
465
  "max"
466
+ ],
467
+ "providers": [
468
+ "fireworks",
469
+ "opencode-go",
470
+ "openrouter",
471
+ "vercel-ai-gateway"
359
472
  ]
360
473
  },
361
474
  {
@@ -366,6 +479,11 @@
366
479
  "off",
367
480
  "high",
368
481
  "max"
482
+ ],
483
+ "providers": [
484
+ "fireworks",
485
+ "openrouter",
486
+ "vercel-ai-gateway"
369
487
  ]
370
488
  },
371
489
  {
@@ -376,6 +494,12 @@
376
494
  "off",
377
495
  "high",
378
496
  "max"
497
+ ],
498
+ "providers": [
499
+ "fireworks",
500
+ "opencode-go",
501
+ "openrouter",
502
+ "vercel-ai-gateway"
379
503
  ]
380
504
  },
381
505
  {
@@ -386,6 +510,12 @@
386
510
  "off",
387
511
  "high",
388
512
  "max"
513
+ ],
514
+ "providers": [
515
+ "fireworks",
516
+ "vercel-token-pass",
517
+ "openrouter",
518
+ "vercel-ai-gateway"
389
519
  ]
390
520
  },
391
521
  {
@@ -397,6 +527,9 @@
397
527
  "medium",
398
528
  "high",
399
529
  "xhigh"
530
+ ],
531
+ "providers": [
532
+ "xai"
400
533
  ]
401
534
  },
402
535
  {
@@ -408,6 +541,9 @@
408
541
  "medium",
409
542
  "high",
410
543
  "xhigh"
544
+ ],
545
+ "providers": [
546
+ "xai"
411
547
  ]
412
548
  },
413
549
  {
@@ -418,6 +554,9 @@
418
554
  "low",
419
555
  "medium",
420
556
  "high"
557
+ ],
558
+ "providers": [
559
+ "google"
421
560
  ]
422
561
  },
423
562
  {
@@ -428,6 +567,9 @@
428
567
  "low",
429
568
  "medium",
430
569
  "high"
570
+ ],
571
+ "providers": [
572
+ "google"
431
573
  ]
432
574
  },
433
575
  {
@@ -439,6 +581,9 @@
439
581
  "medium",
440
582
  "high",
441
583
  "xhigh"
584
+ ],
585
+ "providers": [
586
+ "google"
442
587
  ]
443
588
  },
444
589
  {
@@ -450,6 +595,9 @@
450
595
  "medium",
451
596
  "high",
452
597
  "xhigh"
598
+ ],
599
+ "providers": [
600
+ "google"
453
601
  ]
454
602
  },
455
603
  {
@@ -460,6 +608,9 @@
460
608
  "low",
461
609
  "medium",
462
610
  "high"
611
+ ],
612
+ "providers": [
613
+ "google"
463
614
  ]
464
615
  }
465
616
  ]