@mupt-ai/dari-gateway 1.0.345 → 1.0.347

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.
@@ -168,7 +168,9 @@ function conversationStep(record, organizationId, currentRouterZdr, skillEvents)
168
168
  }
169
169
  }
170
170
  }
171
- const available = (key) => Boolean(record.blobBucket) && Boolean(key);
171
+ const zdr = record.zdr || currentRouterZdr;
172
+ // ZDR content is never served, even when an older blob is still stored.
173
+ const available = (key) => !zdr && Boolean(record.blobBucket) && Boolean(key);
172
174
  const url = (name) => `/v1/organizations/${organizationId}/routing/activity/requests/${record.id}/${name}`;
173
175
  return {
174
176
  id: record.id,
@@ -199,7 +201,7 @@ function conversationStep(record, organizationId, currentRouterZdr, skillEvents)
199
201
  has_declared_tools: record.hasTools,
200
202
  received_at: formatInstant(record.receivedAt),
201
203
  completed_at: record.completedAt === null ? null : formatInstant(record.completedAt),
202
- zdr: record.zdr || currentRouterZdr,
204
+ zdr,
203
205
  decision_source: typeof details?.decision_source === "string" ? details.decision_source : null,
204
206
  selector_reason: record.selectorReason,
205
207
  selector_policy_bypassed: bypassed,
@@ -92,6 +92,8 @@ export declare function consecutivePath(values: ReadonlyArray<string | null>): s
92
92
  export declare function decisionDetails(record: ConversationRecord): Record<string, unknown> | null;
93
93
  export declare function selectedEffort(record: ConversationRecord): ReasoningEffort | null;
94
94
  /** The conversation summary over its steps, oldest first. */
95
+ /** Titles are model-generated from content, so ZDR sessions get a fixed one. */
96
+ export declare const ZDR_SESSION_TITLE = "Zero Data Retention Session";
95
97
  export declare function conversationSummary(records: readonly ConversationRecord[], entities: Entities, title: string | undefined, switches: number | null): {
96
98
  conversation_ref: string;
97
99
  conversation_id: string | null;
@@ -203,6 +203,8 @@ export function selectedEffort(record) {
203
203
  return thinkingLevelValue(decisionDetails(record)?.selected_reasoning_effort);
204
204
  }
205
205
  /** The conversation summary over its steps, oldest first. */
206
+ /** Titles are model-generated from content, so ZDR sessions get a fixed one. */
207
+ export const ZDR_SESSION_TITLE = "Zero Data Retention Session";
206
208
  export function conversationSummary(records, entities, title, switches) {
207
209
  const first = records[0];
208
210
  const last = records.at(-1);
@@ -240,13 +242,14 @@ export function conversationSummary(records, entities, title, switches) {
240
242
  allZdr &&= record.zdr;
241
243
  anyZdr ||= record.zdr;
242
244
  }
245
+ const retention = router?.zdr || allZdr ? "zdr" : anyZdr ? "mixed" : "retained";
243
246
  return {
244
247
  conversation_ref: first.id,
245
248
  conversation_id: first.conversationId || null,
246
249
  agent_session_id: first.agentSessionId || null,
247
250
  context_runs: runs.size,
248
251
  source_protocol: first.sourceProtocol,
249
- title: title || ([...records].reverse().find((record) => record.conversationTitle)?.conversationTitle ?? null),
252
+ title: retention === "zdr" ? ZDR_SESSION_TITLE : title || ([...records].reverse().find((record) => record.conversationTitle)?.conversationTitle ?? null),
250
253
  router_id: first.routerId,
251
254
  router_name: router?.name ?? null,
252
255
  api_key_id: first.apiKeyId,
@@ -269,7 +272,7 @@ export function conversationSummary(records, entities, title, switches) {
269
272
  has_error: hasError,
270
273
  has_aborted: hasAborted,
271
274
  terminal_status: last.status,
272
- retention: router?.zdr || allZdr ? "zdr" : anyZdr ? "mixed" : "retained",
275
+ retention,
273
276
  };
274
277
  }
275
278
  /** Model changes within each context run. */
@@ -143,12 +143,11 @@ export function linkPlatform(store, users) {
143
143
  const grants = await store.grants(subject);
144
144
  // One lookup for every grant's plans, not one per grant per use.
145
145
  const plans = await users.plansWithIds([...new Set(grants.flatMap((grant) => grant.credentialIds))]);
146
- return await Promise.all(grants.map(async (grant) => {
146
+ // One grant, and one step of it, at a time: a hosted store holds a pooled connection per call.
147
+ return await inSeries(grants, async (grant) => {
147
148
  const shared = plans.filter((plan) => grant.credentialIds.includes(plan.id));
148
- const [{ byModel: _, ...usage }, standing] = await Promise.all([
149
- protocol.usage(grant.id, { tags: {} }),
150
- standings(grant, shared),
151
- ]);
149
+ const { byModel: _, ...usage } = await protocol.usage(grant.id, { tags: {} });
150
+ const standing = await standings(grant, shared);
152
151
  return {
153
152
  id: grant.id,
154
153
  clientId: grant.clientId,
@@ -159,7 +158,7 @@ export function linkPlatform(store, users) {
159
158
  subscriptions: shared,
160
159
  usage,
161
160
  };
162
- }));
161
+ });
163
162
  },
164
163
  async disconnect(subject, grantId) {
165
164
  return (await ownGrant(subject, grantId)) !== null && (await revoke(grantId));
@@ -220,7 +219,7 @@ export function linkPlatform(store, users) {
220
219
  },
221
220
  async grants(apiKey) {
222
221
  const subject = await users.manager(apiKey);
223
- return await Promise.all((await store.grants(subject)).map(managedGrant));
222
+ return await inSeries(await store.grants(subject), managedGrant);
224
223
  },
225
224
  async plans(apiKey) {
226
225
  return await users.plans(await endpointOwner(apiKey));
@@ -362,3 +361,10 @@ function endpointName(name) {
362
361
  }
363
362
  return trimmed;
364
363
  }
364
+ // Each item in turn, so a store that holds a connection per call holds one at a time.
365
+ async function inSeries(items, each) {
366
+ const results = [];
367
+ for (const item of items)
368
+ results.push(await each(item));
369
+ return results;
370
+ }
@@ -616,7 +616,7 @@ export type RequestErrorContext = {
616
616
  sourceProtocol: SourceProtocol | "openai_models" | "anthropic_models";
617
617
  status: number;
618
618
  };
619
- export type OperationalErrorCode = "background_drain_timeout" | "billing_usage_report_failed" | "routing_report_assembly_failed" | "routing_report_barrier_failed" | "server_force_stop_failed" | "session_pin_write_failed" | "stream_report_finalization_failed" | "subscription_unavailable_ingest_failed" | "subscription_usage_record_failed" | "next_subscription_lookup_failed";
619
+ export type OperationalErrorCode = "background_drain_timeout" | "billing_usage_report_failed" | "routing_report_assembly_failed" | "routing_report_barrier_failed" | "routing_resolve_failed" | "routing_resolve_shadow_failed" | "routing_resolve_shadow_mismatch" | "server_force_stop_failed" | "session_pin_write_failed" | "stream_report_finalization_failed" | "subscription_unavailable_ingest_failed" | "subscription_usage_record_failed" | "next_subscription_lookup_failed";
620
620
  export type OperationalErrorContext = {
621
621
  code: OperationalErrorCode;
622
622
  requestId?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mupt-ai/dari-gateway",
3
- "version": "1.0.345",
3
+ "version": "1.0.347",
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.345",
55
+ "@mupt-ai/dari-router": "1.0.347",
56
56
  "@mupt-ai/pi-ai": "1.5.2-mupt.3"
57
57
  },
58
58
  "devDependencies": {
@@ -192,7 +192,9 @@ function conversationStep(record: ConversationRecord, organizationId: string, cu
192
192
  }
193
193
  }
194
194
  }
195
- const available = (key: string | null) => Boolean(record.blobBucket) && Boolean(key);
195
+ const zdr = record.zdr || currentRouterZdr;
196
+ // ZDR content is never served, even when an older blob is still stored.
197
+ const available = (key: string | null) => !zdr && Boolean(record.blobBucket) && Boolean(key);
196
198
  const url = (name: string) => `/v1/organizations/${organizationId}/routing/activity/requests/${record.id}/${name}`;
197
199
  return {
198
200
  id: record.id,
@@ -223,7 +225,7 @@ function conversationStep(record: ConversationRecord, organizationId: string, cu
223
225
  has_declared_tools: record.hasTools,
224
226
  received_at: formatInstant(record.receivedAt),
225
227
  completed_at: record.completedAt === null ? null : formatInstant(record.completedAt),
226
- zdr: record.zdr || currentRouterZdr,
228
+ zdr,
227
229
  decision_source: typeof details?.decision_source === "string" ? details.decision_source : null,
228
230
  selector_reason: record.selectorReason,
229
231
  selector_policy_bypassed: bypassed,
@@ -292,6 +292,9 @@ export function selectedEffort(record: ConversationRecord): ReasoningEffort | nu
292
292
  }
293
293
 
294
294
  /** The conversation summary over its steps, oldest first. */
295
+ /** Titles are model-generated from content, so ZDR sessions get a fixed one. */
296
+ export const ZDR_SESSION_TITLE = "Zero Data Retention Session";
297
+
295
298
  export function conversationSummary(
296
299
  records: readonly ConversationRecord[],
297
300
  entities: Entities,
@@ -329,13 +332,14 @@ export function conversationSummary(
329
332
  allZdr &&= record.zdr;
330
333
  anyZdr ||= record.zdr;
331
334
  }
335
+ const retention = router?.zdr || allZdr ? "zdr" : anyZdr ? "mixed" : "retained";
332
336
  return {
333
337
  conversation_ref: first.id,
334
338
  conversation_id: first.conversationId || null,
335
339
  agent_session_id: first.agentSessionId || null,
336
340
  context_runs: runs.size,
337
341
  source_protocol: first.sourceProtocol,
338
- title: title || ([...records].reverse().find((record) => record.conversationTitle)?.conversationTitle ?? null),
342
+ title: retention === "zdr" ? ZDR_SESSION_TITLE : title || ([...records].reverse().find((record) => record.conversationTitle)?.conversationTitle ?? null),
339
343
  router_id: first.routerId,
340
344
  router_name: router?.name ?? null,
341
345
  api_key_id: first.apiKeyId,
@@ -358,7 +362,7 @@ export function conversationSummary(
358
362
  has_error: hasError,
359
363
  has_aborted: hasAborted,
360
364
  terminal_status: last.status,
361
- retention: router?.zdr || allZdr ? "zdr" : anyZdr ? "mixed" : "retained",
365
+ retention,
362
366
  };
363
367
  }
364
368
 
@@ -295,12 +295,11 @@ export function linkPlatform(store: LinkStore, users: LinkUsers): LinkPlatform {
295
295
  const grants = await store.grants(subject);
296
296
  // One lookup for every grant's plans, not one per grant per use.
297
297
  const plans = await users.plansWithIds([...new Set(grants.flatMap((grant) => grant.credentialIds))]);
298
- return await Promise.all(grants.map(async (grant) => {
298
+ // One grant, and one step of it, at a time: a hosted store holds a pooled connection per call.
299
+ return await inSeries(grants, async (grant) => {
299
300
  const shared = plans.filter((plan) => grant.credentialIds.includes(plan.id));
300
- const [{ byModel: _, ...usage }, standing] = await Promise.all([
301
- protocol.usage(grant.id, { tags: {} }),
302
- standings(grant, shared),
303
- ]);
301
+ const { byModel: _, ...usage } = await protocol.usage(grant.id, { tags: {} });
302
+ const standing = await standings(grant, shared);
304
303
  return {
305
304
  id: grant.id,
306
305
  clientId: grant.clientId,
@@ -311,7 +310,7 @@ export function linkPlatform(store: LinkStore, users: LinkUsers): LinkPlatform {
311
310
  subscriptions: shared,
312
311
  usage,
313
312
  };
314
- }));
313
+ });
315
314
  },
316
315
  async disconnect(subject, grantId) {
317
316
  return (await ownGrant(subject, grantId)) !== null && (await revoke(grantId));
@@ -369,7 +368,7 @@ export function linkPlatform(store: LinkStore, users: LinkUsers): LinkPlatform {
369
368
  },
370
369
  async grants(apiKey) {
371
370
  const subject = await users.manager(apiKey);
372
- return await Promise.all((await store.grants(subject)).map(managedGrant));
371
+ return await inSeries(await store.grants(subject), managedGrant);
373
372
  },
374
373
  async plans(apiKey) {
375
374
  return await users.plans(await endpointOwner(apiKey));
@@ -513,3 +512,10 @@ function endpointName(name: string): string {
513
512
  }
514
513
  return trimmed;
515
514
  }
515
+
516
+ // Each item in turn, so a store that holds a connection per call holds one at a time.
517
+ async function inSeries<T, R>(items: readonly T[], each: (item: T) => Promise<R>): Promise<R[]> {
518
+ const results: R[] = [];
519
+ for (const item of items) results.push(await each(item));
520
+ return results;
521
+ }
@@ -682,6 +682,9 @@ export type OperationalErrorCode =
682
682
  | "billing_usage_report_failed"
683
683
  | "routing_report_assembly_failed"
684
684
  | "routing_report_barrier_failed"
685
+ | "routing_resolve_failed"
686
+ | "routing_resolve_shadow_failed"
687
+ | "routing_resolve_shadow_mismatch"
685
688
  | "server_force_stop_failed"
686
689
  | "session_pin_write_failed"
687
690
  | "stream_report_finalization_failed"