@mupt-ai/dari-gateway 1.0.358 → 1.0.359

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.
@@ -46,8 +46,9 @@ export declare class HostedSync {
46
46
  private call;
47
47
  }
48
48
  /**
49
- * The user's plans hosted Dari holds on other computers and on Dari, for the
50
- * check before a sign-in connects an account: `GET /v1/gateway/accounts`
51
- * returns each one's provider, account identity, and where it lives, never a token.
49
+ * The user's plans on hosted Dari, for the check before a sign-in connects an
50
+ * account: `GET /v1/gateway/accounts` returns each one's provider, account
51
+ * identity, and name, never a token. Other computers may hold the same
52
+ * account, so only Dari's plans count.
52
53
  */
53
54
  export declare function readHostedAccounts(hosted: HostedConnection, fetchImpl: typeof globalThis.fetch): Promise<ConnectedAccount[]>;
@@ -194,12 +194,16 @@ export class HostedSync {
194
194
  }
195
195
  }
196
196
  /**
197
- * The user's plans hosted Dari holds on other computers and on Dari, for the
198
- * check before a sign-in connects an account: `GET /v1/gateway/accounts`
199
- * returns each one's provider, account identity, and where it lives, never a token.
197
+ * The user's plans on hosted Dari, for the check before a sign-in connects an
198
+ * account: `GET /v1/gateway/accounts` returns each one's provider, account
199
+ * identity, and name, never a token. Other computers may hold the same
200
+ * account, so only Dari's plans count.
200
201
  */
201
202
  export async function readHostedAccounts(hosted, fetchImpl) {
202
- const response = await fetchImpl(`${hosted.url}/v1/gateway/accounts?gateway_id=${encodeURIComponent(hosted.gatewayId)}`, {
203
+ const response = await fetchImpl(
204
+ // Hosted Dari before this release requires gateway_id; it leaves this
205
+ // gateway's own plans out.
206
+ `${hosted.url}/v1/gateway/accounts?gateway_id=${encodeURIComponent(hosted.gatewayId)}`, {
203
207
  headers: { authorization: `Bearer ${hosted.apiKey}` },
204
208
  signal: AbortSignal.timeout(30_000),
205
209
  });
@@ -208,20 +212,26 @@ export async function readHostedAccounts(hosted, fetchImpl) {
208
212
  const body = await response.json();
209
213
  if (!Array.isArray(body.accounts))
210
214
  throw new Error("hosted accounts response has no accounts list");
211
- return body.accounts.map((entry) => {
215
+ const accounts = [];
216
+ for (const entry of body.accounts) {
217
+ // Hosted Dari before this release also listed other computers' plans.
218
+ if (entry.where !== "dari")
219
+ continue;
212
220
  if (!SUBSCRIPTION_PROVIDERS.includes(entry.provider)) {
213
221
  throw new Error(`hosted accounts response names an unknown provider ${JSON.stringify(entry.provider)}`);
214
222
  }
215
- const dari = entry.where === "dari";
216
- return {
217
- provider: entry.provider,
218
- accountId: typeof entry.account_id === "string" ? entry.account_id : null,
219
- accountEmail: typeof entry.account_email === "string" ? entry.account_email : null,
220
- place: dari ? "dari" : "other_computer",
221
- name: typeof entry.name === "string" ? entry.name : null,
222
- gatewayName: typeof entry.gateway_name === "string" ? entry.gateway_name : null,
223
- };
224
- });
223
+ let accountId = null;
224
+ if (typeof entry.account_id === "string")
225
+ accountId = entry.account_id;
226
+ let accountEmail = null;
227
+ if (typeof entry.account_email === "string")
228
+ accountEmail = entry.account_email;
229
+ let name = null;
230
+ if (typeof entry.name === "string")
231
+ name = entry.name;
232
+ accounts.push({ provider: entry.provider, accountId, accountEmail, place: "dari", name });
233
+ }
234
+ return accounts;
225
235
  }
226
236
  function backoff(failures) {
227
237
  return Math.min(RETRY_MAX_MS, RETRY_BASE_MS * 2 ** Math.max(0, failures - 1));
@@ -74,14 +74,13 @@ export type AccountRef = {
74
74
  accountEmail: string | null;
75
75
  };
76
76
  /**
77
- * A plan of the same user that already holds an account, wherever it lives.
78
- * `name` is the plan's handle where it is known; `gatewayName` names the other
79
- * computer for an `other_computer` plan.
77
+ * A plan of the same user that already holds an account: on hosted Dari, or
78
+ * on this computer. The same account may also be on any number of the user's
79
+ * other computers. `name` is the plan's handle.
80
80
  */
81
81
  export type ConnectedAccount = AccountRef & {
82
- place: "dari" | "this_computer" | "private" | "other_computer";
82
+ place: "dari" | "this_computer" | "private";
83
83
  name: string | null;
84
- gatewayName: string | null;
85
84
  };
86
85
  /** Connecting an account the same user already has connected; the message says where it lives and how to move it. */
87
86
  export declare class SubscriptionAccountConnectedError extends Error {
@@ -40,8 +40,6 @@ function connectedAccountMessage(account) {
40
40
  return `This ${label} account is already connected on This Computer${asName}. Move it with \`dari accounts subscription move ${handle} --on dari\`, or disconnect it first.`;
41
41
  case "private":
42
42
  return `This ${label} account is already connected Private on This Computer${asName}. Move it with \`dari accounts subscription move ${handle} --on dari\` or \`--on computer\`, or disconnect it first.`;
43
- case "other_computer":
44
- return `This ${label} account is already connected on another computer${account.gatewayName ? ` (${account.gatewayName})` : ""}. Disconnect it there, or move it to Dari there with \`dari accounts subscription move\`.`;
45
43
  }
46
44
  }
47
45
  const BASE_NAMES = {
@@ -376,7 +374,6 @@ export class SubscriptionStore {
376
374
  accountEmail: local.accountEmail,
377
375
  place: local.private ? "private" : "this_computer",
378
376
  name: local.name,
379
- gatewayName: null,
380
377
  }));
381
378
  }
382
379
  const other = elsewhere.find((account) => sameConnectedAccount(account, tokens));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mupt-ai/dari-gateway",
3
- "version": "1.0.358",
3
+ "version": "1.0.359",
4
4
  "description": "Self-hostable LLM gateway for coding agents and APIs: one endpoint for Anthropic Messages, OpenAI Chat Completions, and OpenAI Responses, with subscription pooling, failover, and prompt-cache-aware routing.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -52,7 +52,7 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@aws-sdk/client-sts": "3.1063.0",
55
- "@mupt-ai/dari-router": "1.0.358",
55
+ "@mupt-ai/dari-router": "1.0.359",
56
56
  "@mupt-ai/pi-ai": "1.5.2-mupt.3"
57
57
  },
58
58
  "devDependencies": {
@@ -212,15 +212,18 @@ export class HostedSync {
212
212
  }
213
213
 
214
214
  /**
215
- * The user's plans hosted Dari holds on other computers and on Dari, for the
216
- * check before a sign-in connects an account: `GET /v1/gateway/accounts`
217
- * returns each one's provider, account identity, and where it lives, never a token.
215
+ * The user's plans on hosted Dari, for the check before a sign-in connects an
216
+ * account: `GET /v1/gateway/accounts` returns each one's provider, account
217
+ * identity, and name, never a token. Other computers may hold the same
218
+ * account, so only Dari's plans count.
218
219
  */
219
220
  export async function readHostedAccounts(
220
221
  hosted: HostedConnection,
221
222
  fetchImpl: typeof globalThis.fetch,
222
223
  ): Promise<ConnectedAccount[]> {
223
224
  const response = await fetchImpl(
225
+ // Hosted Dari before this release requires gateway_id; it leaves this
226
+ // gateway's own plans out.
224
227
  `${hosted.url}/v1/gateway/accounts?gateway_id=${encodeURIComponent(hosted.gatewayId)}`,
225
228
  {
226
229
  headers: { authorization: `Bearer ${hosted.apiKey}` },
@@ -230,20 +233,22 @@ export async function readHostedAccounts(
230
233
  if (!response.ok) throw new Error(`HTTP ${response.status}: ${(await response.text()).slice(0, 300)}`);
231
234
  const body = await response.json() as { accounts?: unknown };
232
235
  if (!Array.isArray(body.accounts)) throw new Error("hosted accounts response has no accounts list");
233
- return body.accounts.map((entry: Record<string, unknown>) => {
236
+ const accounts: ConnectedAccount[] = [];
237
+ for (const entry of body.accounts as Array<Record<string, unknown>>) {
238
+ // Hosted Dari before this release also listed other computers' plans.
239
+ if (entry.where !== "dari") continue;
234
240
  if (!SUBSCRIPTION_PROVIDERS.includes(entry.provider as SubscriptionProvider)) {
235
241
  throw new Error(`hosted accounts response names an unknown provider ${JSON.stringify(entry.provider)}`);
236
242
  }
237
- const dari = entry.where === "dari";
238
- return {
239
- provider: entry.provider as SubscriptionProvider,
240
- accountId: typeof entry.account_id === "string" ? entry.account_id : null,
241
- accountEmail: typeof entry.account_email === "string" ? entry.account_email : null,
242
- place: dari ? "dari" : "other_computer",
243
- name: typeof entry.name === "string" ? entry.name : null,
244
- gatewayName: typeof entry.gateway_name === "string" ? entry.gateway_name : null,
245
- };
246
- });
243
+ let accountId: string | null = null;
244
+ if (typeof entry.account_id === "string") accountId = entry.account_id;
245
+ let accountEmail: string | null = null;
246
+ if (typeof entry.account_email === "string") accountEmail = entry.account_email;
247
+ let name: string | null = null;
248
+ if (typeof entry.name === "string") name = entry.name;
249
+ accounts.push({ provider: entry.provider as SubscriptionProvider, accountId, accountEmail, place: "dari", name });
250
+ }
251
+ return accounts;
247
252
  }
248
253
 
249
254
  function backoff(failures: number): number {
@@ -98,14 +98,13 @@ export type AccountRef = {
98
98
  };
99
99
 
100
100
  /**
101
- * A plan of the same user that already holds an account, wherever it lives.
102
- * `name` is the plan's handle where it is known; `gatewayName` names the other
103
- * computer for an `other_computer` plan.
101
+ * A plan of the same user that already holds an account: on hosted Dari, or
102
+ * on this computer. The same account may also be on any number of the user's
103
+ * other computers. `name` is the plan's handle.
104
104
  */
105
105
  export type ConnectedAccount = AccountRef & {
106
- place: "dari" | "this_computer" | "private" | "other_computer";
106
+ place: "dari" | "this_computer" | "private";
107
107
  name: string | null;
108
- gatewayName: string | null;
109
108
  };
110
109
 
111
110
  /** Connecting an account the same user already has connected; the message says where it lives and how to move it. */
@@ -142,8 +141,6 @@ function connectedAccountMessage(account: ConnectedAccount): string {
142
141
  return `This ${label} account is already connected on This Computer${asName}. Move it with \`dari accounts subscription move ${handle} --on dari\`, or disconnect it first.`;
143
142
  case "private":
144
143
  return `This ${label} account is already connected Private on This Computer${asName}. Move it with \`dari accounts subscription move ${handle} --on dari\` or \`--on computer\`, or disconnect it first.`;
145
- case "other_computer":
146
- return `This ${label} account is already connected on another computer${account.gatewayName ? ` (${account.gatewayName})` : ""}. Disconnect it there, or move it to Dari there with \`dari accounts subscription move\`.`;
147
144
  }
148
145
  }
149
146
 
@@ -572,7 +569,6 @@ export class SubscriptionStore {
572
569
  accountEmail: local.accountEmail,
573
570
  place: local.private ? "private" : "this_computer",
574
571
  name: local.name,
575
- gatewayName: null,
576
572
  }));
577
573
  }
578
574
  const other = elsewhere.find((account) => sameConnectedAccount(account, tokens));