@mupt-ai/dari-gateway 1.0.366 → 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 (41) hide show
  1. package/dist/activity/conversation_detail.js +8 -0
  2. package/dist/link/endpoints.js +5 -25
  3. package/dist/link/service.d.ts +1 -3
  4. package/dist/link/service.js +0 -1
  5. package/dist/platform/platform.d.ts +1 -11
  6. package/dist/protocol/input/anthropic_messages.js +3 -4
  7. package/dist/providers/execution.js +1 -0
  8. package/dist/providers/provider_call.d.ts +1 -0
  9. package/dist/providers/provider_call.js +1 -0
  10. package/dist/runtime/runtime_reporter.d.ts +1 -0
  11. package/dist/runtime/runtime_reporter.js +1 -0
  12. package/dist/self_host/connected.d.ts +5 -4
  13. package/dist/self_host/hosted_sync.d.ts +14 -23
  14. package/dist/self_host/hosted_sync.js +56 -120
  15. package/dist/self_host/main.js +0 -3
  16. package/dist/self_host/platform.js +2 -0
  17. package/dist/self_host/resolve.js +2 -1
  18. package/dist/self_host/subscriptions/index.d.ts +1 -1
  19. package/dist/self_host/subscriptions/index.js +1 -1
  20. package/dist/self_host/subscriptions/store.d.ts +8 -6
  21. package/dist/self_host/subscriptions/store.js +8 -16
  22. package/dist/telemetry/report.js +8 -1
  23. package/dist/types.d.ts +1 -0
  24. package/package.json +2 -2
  25. package/src/activity/conversation_detail.ts +8 -0
  26. package/src/link/endpoints.ts +4 -29
  27. package/src/link/service.ts +0 -4
  28. package/src/platform/platform.ts +2 -9
  29. package/src/protocol/input/anthropic_messages.ts +3 -9
  30. package/src/providers/execution.ts +1 -0
  31. package/src/providers/provider_call.ts +3 -0
  32. package/src/runtime/runtime_reporter.ts +3 -1
  33. package/src/self_host/connected.ts +5 -4
  34. package/src/self_host/hosted_sync.ts +51 -121
  35. package/src/self_host/main.ts +0 -3
  36. package/src/self_host/platform.ts +2 -1
  37. package/src/self_host/resolve.ts +2 -0
  38. package/src/self_host/subscriptions/index.ts +1 -0
  39. package/src/self_host/subscriptions/store.ts +14 -18
  40. package/src/telemetry/report.ts +8 -1
  41. package/src/types.ts +3 -0
@@ -14,7 +14,7 @@ import {
14
14
  SELF_HOSTED_ORGANIZATION_ID,
15
15
  type SelfHostedResolverDeps,
16
16
  } from "./resolve.js";
17
- import { type SubscriptionStore } from "./subscriptions/index.js";
17
+ import { planAccount, type SubscriptionStore } from "./subscriptions/index.js";
18
18
  import { refreshedAccessToken } from "./subscriptions/access.js";
19
19
  import { hasBankedResets, providerBaseUrls, recoverHeldPlans } from "./subscriptions/resets.js";
20
20
 
@@ -60,6 +60,7 @@ export function createSelfHostedPlatform(deps: Omit<SelfHostedResolverDeps, "pre
60
60
  if (next === null) return undefined;
61
61
  return {
62
62
  credentialId: next.id,
63
+ ...planAccount(next),
63
64
  apiKey: await refreshedAccessToken(deps.subscriptions, next, { fetch: deps.fetch }),
64
65
  };
65
66
  },
@@ -50,6 +50,7 @@ import { refreshedAccessToken } from "./subscriptions/access.js";
50
50
  import {
51
51
  activeModelHolds,
52
52
  freshAccessToken,
53
+ planAccount,
53
54
  type OAuthFetch,
54
55
  type SubscriptionCredential,
55
56
  type SubscriptionProvider,
@@ -285,6 +286,7 @@ export async function resolveSelfHostedRouter(
285
286
  apiKey: await planToken(first.plan),
286
287
  subscription: first.plan.provider,
287
288
  credentialId: first.plan.id,
289
+ ...planAccount(first.plan),
288
290
  };
289
291
  } else {
290
292
  resolved.provider_keys[first!.provider] = first!.key;
@@ -50,6 +50,7 @@ export {
50
50
  activeModelHolds,
51
51
  currentUsage,
52
52
  isHeld,
53
+ planAccount,
53
54
  sameConnectedAccount,
54
55
  type AccountRef,
55
56
  type ConnectedAccount,
@@ -50,8 +50,8 @@ export type SubscriptionCredential = {
50
50
  // The Dari Link user who connected the plan on the approval page; null for
51
51
  // the gateway owner's own plans, which alone serve the gateway's keys.
52
52
  owner: string | null;
53
- // Kept off hosted Dari: a gateway connected to it neither serves nor
54
- // reports the plan.
53
+ // Its requests stay on this computer: a gateway connected to hosted Dari
54
+ // never sends them to Activity.
55
55
  private: boolean;
56
56
  accessToken: string;
57
57
  refreshToken: string;
@@ -90,6 +90,15 @@ export type PendingOAuthSession = {
90
90
  expiresAt: Date;
91
91
  };
92
92
 
93
+ /**
94
+ * A plan's name, as Activity shows the request it served: the user's label,
95
+ * else its account's email; none when it has neither.
96
+ */
97
+ export function planAccount(plan: Pick<SubscriptionCredential, "label" | "accountEmail">): { account?: string } {
98
+ const account = plan.label ?? plan.accountEmail;
99
+ return account ? { account } : {};
100
+ }
101
+
93
102
  /** The parts of a plan that say which provider account it is. */
94
103
  export type AccountRef = {
95
104
  provider: SubscriptionProvider;
@@ -105,6 +114,9 @@ export type AccountRef = {
105
114
  export type ConnectedAccount = AccountRef & {
106
115
  place: "dari" | "this_computer" | "private";
107
116
  name: string | null;
117
+ // When a plan on Dari was connected; hosted Dari before this release does
118
+ // not say.
119
+ connectedAt?: Date;
108
120
  };
109
121
 
110
122
  /** Connecting an account the same user already has connected; the message says where it lives and how to move it. */
@@ -200,13 +212,6 @@ type SessionRow = {
200
212
  };
201
213
 
202
214
  export class SubscriptionStore {
203
- /**
204
- * Told of each change hosted Dari's copy of the plans would show: `plans`
205
- * for a plan connected, removed, renamed, moved, held, or released, and
206
- * `usage` for reported usage or use.
207
- */
208
- onChange: ((change: "plans" | "usage") => void) | undefined;
209
-
210
215
  constructor(
211
216
  private readonly db: Database,
212
217
  private readonly box: SecretBox | null = null,
@@ -424,7 +429,6 @@ export class SubscriptionStore {
424
429
  usage_windows = ? WHERE id = ?`,
425
430
  [usage.utilization, usage.resetsAt.getTime(), now.getTime(), windowsJson(usage), id],
426
431
  );
427
- this.onChange?.("usage");
428
432
  }
429
433
 
430
434
  // A pin idle past CONVERSATION_PIN_TTL_MS is forgotten: the conversation is
@@ -539,7 +543,6 @@ export class SubscriptionStore {
539
543
  );
540
544
  return this.get(id);
541
545
  })();
542
- if (connected !== null) this.onChange?.("plans");
543
546
  return connected;
544
547
  }
545
548
 
@@ -579,7 +582,6 @@ export class SubscriptionStore {
579
582
 
580
583
  touch(id: string, now = new Date()): void {
581
584
  this.db.run("UPDATE subscription_credentials SET last_used_at = ? WHERE id = ?", [now.getTime(), id]);
582
- this.onChange?.("usage");
583
585
  }
584
586
 
585
587
  /** An empty label clears it. Null when the subscription is not connected. */
@@ -595,7 +597,6 @@ export class SubscriptionStore {
595
597
  now.getTime(),
596
598
  credential.id,
597
599
  ]);
598
- this.onChange?.("plans");
599
600
  return this.get(credential.id);
600
601
  }
601
602
 
@@ -608,7 +609,6 @@ export class SubscriptionStore {
608
609
  now.getTime(),
609
610
  credential.id,
610
611
  ]);
611
- this.onChange?.("plans");
612
612
  return this.get(credential.id);
613
613
  }
614
614
 
@@ -618,7 +618,6 @@ export class SubscriptionStore {
618
618
  if (credential === null) return null;
619
619
  this.db.run("DELETE FROM subscription_credentials WHERE id = ?", [credential.id]);
620
620
  this.db.run("DELETE FROM subscription_conversation_pins WHERE credential_id = ?", [credential.id]);
621
- this.onChange?.("plans");
622
621
  return credential;
623
622
  }
624
623
 
@@ -635,7 +634,6 @@ export class SubscriptionStore {
635
634
  "UPDATE subscription_credentials SET unavailable_until = ?, unavailable_reason = ?, updated_at = ? WHERE id = ?",
636
635
  [until.getTime(), reason, now.getTime(), id],
637
636
  );
638
- this.onChange?.("plans");
639
637
  }
640
638
  return this.activeCredential(credential.provider, now) !== null;
641
639
  }
@@ -657,7 +655,6 @@ export class SubscriptionStore {
657
655
  now.getTime(),
658
656
  id,
659
657
  ]);
660
- this.onChange?.("plans");
661
658
  }
662
659
  return true;
663
660
  }
@@ -671,7 +668,6 @@ export class SubscriptionStore {
671
668
  updated_at = ? WHERE id = ?`,
672
669
  [now.getTime(), credential.id],
673
670
  );
674
- this.onChange?.("plans");
675
671
  return this.get(credential.id);
676
672
  }
677
673
 
@@ -523,6 +523,11 @@ export class RequestReporter {
523
523
  : selectedProvider ? a.credentials.link_key_credential_ids?.[selectedProvider] ?? null : null,
524
524
  }
525
525
  : undefined;
526
+ // The plan that served the request, by name, so Activity says which;
527
+ // ingest refuses metadata with a longer one.
528
+ const subscriptionAccount = keySource === "subscription"
529
+ ? outcome.providerExecution?.subscriptionAccount?.slice(0, 320)
530
+ : undefined;
526
531
  const ingestPayload = {
527
532
  request_id: this.args.requestId,
528
533
  client_request_id: a.clientRequestId,
@@ -547,7 +552,9 @@ export class RequestReporter {
547
552
  prefix_warm_tokens: selectedEstimate?.warm_tokens ?? null,
548
553
  message_count: observability.messageCount,
549
554
  has_tools: observability.hasTools,
550
- request_metadata: observability.metadata,
555
+ request_metadata: subscriptionAccount === undefined
556
+ ? observability.metadata
557
+ : { ...observability.metadata, subscription_account: subscriptionAccount },
551
558
  selected_model: selectedModel,
552
559
  selected_provider: selectedProvider,
553
560
  provider_key_source: keySource,
package/src/types.ts CHANGED
@@ -75,6 +75,9 @@ export type ProviderCredential = {
75
75
  subscription?: SubscriptionKind;
76
76
  // A resolved personal plan: quota holds and usage belong to this credential.
77
77
  credentialId?: string;
78
+ // That plan's name, as Activity shows it: its owner's label, else its
79
+ // account's email.
80
+ account?: string;
78
81
  // Dari's managed key: billed to the organization's credits.
79
82
  managed?: true;
80
83
  };