@maximem/synap-js-sdk 0.5.9 → 0.5.11

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 (36) hide show
  1. package/dist/anticipation-cache-LPNKMRBH.cjs.map +1 -1
  2. package/dist/{chunk-BWMPKLFG.js → chunk-4GE7SORD.js} +17 -1
  3. package/dist/chunk-4GE7SORD.js.map +1 -0
  4. package/dist/chunk-ICUFS3B5.cjs.map +1 -1
  5. package/dist/{chunk-I7TWR4S6.js → chunk-LJ66WCV3.js} +2 -2
  6. package/dist/{chunk-RE4DDIWO.cjs → chunk-QHPVLTQ7.cjs} +6 -6
  7. package/dist/chunk-QHPVLTQ7.cjs.map +1 -0
  8. package/dist/{chunk-T372OL3Q.cjs → chunk-UXNVTP4D.cjs} +33 -17
  9. package/dist/chunk-UXNVTP4D.cjs.map +1 -0
  10. package/dist/chunk-ZKOJDUN4.cjs.map +1 -1
  11. package/dist/env-55ULHNJZ.cjs.map +1 -1
  12. package/dist/{errors-Bdayqlzy.d.cts → errors-BvUA5EW8.d.cts} +14 -2
  13. package/dist/{errors-Bdayqlzy.d.ts → errors-BvUA5EW8.d.ts} +14 -2
  14. package/dist/grpc/index.cjs +7 -7
  15. package/dist/grpc/index.cjs.map +1 -1
  16. package/dist/grpc/index.d.cts +1 -1
  17. package/dist/grpc/index.d.ts +1 -1
  18. package/dist/grpc/index.js +3 -3
  19. package/dist/index.cjs +200 -149
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +28 -11
  22. package/dist/index.d.ts +28 -11
  23. package/dist/index.js +76 -25
  24. package/dist/index.js.map +1 -1
  25. package/dist/onnx-encoder-4RSL6ID4.cjs.map +1 -1
  26. package/dist/stream-client-5GYUWETN.cjs +16 -0
  27. package/dist/stream-client-5GYUWETN.cjs.map +1 -0
  28. package/dist/{stream-client-3WHXGW4U.js → stream-client-ZBCKRU7S.js} +3 -3
  29. package/package.json +1 -1
  30. package/dist/chunk-BWMPKLFG.js.map +0 -1
  31. package/dist/chunk-RE4DDIWO.cjs.map +0 -1
  32. package/dist/chunk-T372OL3Q.cjs.map +0 -1
  33. package/dist/stream-client-L6OQPZN7.cjs +0 -16
  34. package/dist/stream-client-L6OQPZN7.cjs.map +0 -1
  35. /package/dist/{chunk-I7TWR4S6.js.map → chunk-LJ66WCV3.js.map} +0 -0
  36. /package/dist/{stream-client-3WHXGW4U.js.map → stream-client-ZBCKRU7S.js.map} +0 -0
package/dist/index.cjs CHANGED
@@ -39,7 +39,8 @@ var _chunkZKOJDUN4cjs = require('./chunk-ZKOJDUN4.cjs');
39
39
 
40
40
 
41
41
 
42
- var _chunkT372OL3Qcjs = require('./chunk-T372OL3Q.cjs');
42
+
43
+ var _chunkUXNVTP4Dcjs = require('./chunk-UXNVTP4D.cjs');
43
44
 
44
45
  // src/transport/endpoints.ts
45
46
  var ENDPOINTS = {
@@ -102,7 +103,7 @@ function shouldRetry(input) {
102
103
  if (attempt >= policy.maxAttempts) {
103
104
  return { retry: false, delaySeconds: 0, reason: "max_attempts_exhausted" };
104
105
  }
105
- if (!_chunkT372OL3Qcjs.isSynapError.call(void 0, error) || !error.transient) {
106
+ if (!_chunkUXNVTP4Dcjs.isSynapError.call(void 0, error) || !error.transient) {
106
107
  return { retry: false, delaySeconds: 0, reason: "not_transient" };
107
108
  }
108
109
  const idempotent = _nullishCoalesce(input.idempotent, () => ( IDEMPOTENT_METHODS.has(method.toUpperCase())));
@@ -120,7 +121,7 @@ function shouldRetry(input) {
120
121
  };
121
122
  }
122
123
  function backoffDelay(error, attempt, policy) {
123
- if (error instanceof _chunkT372OL3Qcjs.RateLimitError && error.retryAfterSeconds != null) {
124
+ if (error instanceof _chunkUXNVTP4Dcjs.RateLimitError && error.retryAfterSeconds != null) {
124
125
  return Math.min(error.retryAfterSeconds, policy.backoffMax);
125
126
  }
126
127
  const exponential = policy.backoffBase * 2 ** (attempt - 1);
@@ -194,9 +195,7 @@ var B2C_ISOLATION = "equals_customer";
194
195
  function checkCustomerId(isolation, customerId, where, instanceId) {
195
196
  if (customerId === void 0 || customerId === null || customerId === "") return;
196
197
  if (isolation !== B2C_ISOLATION) return;
197
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
198
- `${where}: customer_id is not accepted on this instance${instanceId ? ` (${instanceId})` : ""}, which is B2C (user_context_isolation='${B2C_ISOLATION}'). Send user_id only; it is the whole identity, and the server files and reads your data under it. Received customer_id=${JSON.stringify(customerId)}.`
199
- );
198
+ throw new (0, _chunkUXNVTP4Dcjs.CustomerIdNotAcceptedError)(where, String(customerId), instanceId);
200
199
  }
201
200
 
202
201
  // src/transport/http.ts
@@ -219,7 +218,7 @@ var HttpTransport = (_class2 = class {
219
218
 
220
219
 
221
220
  __init2() {this.closed = false}
222
- constructor(options) {;_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);
221
+ constructor(options) {;_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);
223
222
  this.#credentials = options.credentials;
224
223
  this.baseUrl = (_nullishCoalesce(options.baseUrl, () => ( DEFAULT_BASE_URL))).replace(/\/+$/, "");
225
224
  this.timeouts = { ...DEFAULT_TIMEOUTS, ...options.timeouts };
@@ -267,8 +266,24 @@ var HttpTransport = (_class2 = class {
267
266
  * deployment older than the field, and must mean "enforce nothing".
268
267
  */
269
268
  __init3() {this.userContextIsolation = void 0}
270
- /** Refuse a customer_id on a B2C instance, at the call site. */
271
- checkCustomerId(customerId, where) {
269
+ /**
270
+ * Set by the client to its identity resolution (`initialize()`'s whoami).
271
+ * Python refuses every call before `initialize()`; here the first request
272
+ * runs it instead, so a caller who skips it gets the same identity-dependent
273
+ * behaviour (client-scope cache hits, the B2C check) rather than an error.
274
+ */
275
+ __init4() {this.identityResolver = void 0}
276
+ /** Resolve identity once, before the first request. Never throws. */
277
+ async ready() {
278
+ if (this.identityResolver !== void 0) await this.identityResolver();
279
+ }
280
+ /**
281
+ * Refuse a customer_id on a B2C instance, at the call site. Resolves identity
282
+ * first: the isolation comes from whoami, so on the first call of a client
283
+ * that skipped initialize() the check would otherwise see nothing and pass.
284
+ */
285
+ async checkCustomerId(customerId, where) {
286
+ await this.ready();
272
287
  checkCustomerId(
273
288
  this.userContextIsolation,
274
289
  customerId,
@@ -296,8 +311,9 @@ var HttpTransport = (_class2 = class {
296
311
  }
297
312
  async request(name, options = {}) {
298
313
  const spec = ENDPOINTS[name];
299
- const correlationId = _nullishCoalesce(options.correlationId, () => ( _chunkT372OL3Qcjs.newCorrelationId.call(void 0, )));
314
+ const correlationId = _nullishCoalesce(options.correlationId, () => ( _chunkUXNVTP4Dcjs.newCorrelationId.call(void 0, )));
300
315
  const idempotent = _nullishCoalesce(options.idempotent, () => ( spec.idempotent));
316
+ if (name !== "whoami") await this.ready();
301
317
  let attempt = 0;
302
318
  let last = null;
303
319
  while (attempt < this.retryPolicy.maxAttempts) {
@@ -318,7 +334,7 @@ var HttpTransport = (_class2 = class {
318
334
  await sleep(decision.delaySeconds * 1e3, options.signal);
319
335
  }
320
336
  }
321
- throw _nullishCoalesce(_optionalChain([last, 'optionalAccess', _9 => _9.error]), () => ( new (0, _chunkT372OL3Qcjs.SynapError)("Request failed with no recorded error")));
337
+ throw _nullishCoalesce(_optionalChain([last, 'optionalAccess', _9 => _9.error]), () => ( new (0, _chunkUXNVTP4Dcjs.SynapError)("Request failed with no recorded error")));
322
338
  }
323
339
  async attempt(name, options, correlationId) {
324
340
  const spec = ENDPOINTS[name];
@@ -351,7 +367,7 @@ var HttpTransport = (_class2 = class {
351
367
  try {
352
368
  return JSON.parse(text);
353
369
  } catch (e3) {
354
- throw new (0, _chunkT372OL3Qcjs.SynapError)(`Malformed JSON in response from ${url}`, { correlationId });
370
+ throw new (0, _chunkUXNVTP4Dcjs.SynapError)(`Malformed JSON in response from ${url}`, { correlationId });
355
371
  }
356
372
  }
357
373
  buildUrl(path, query) {
@@ -385,14 +401,14 @@ var HttpTransport = (_class2 = class {
385
401
  }
386
402
  }, _class2);
387
403
  function isOutcomeUnknown(error) {
388
- if (error instanceof _chunkT372OL3Qcjs.RateLimitError) return false;
389
- if (error instanceof _chunkT372OL3Qcjs.ServiceUnavailableError) return false;
390
- if (error instanceof _chunkT372OL3Qcjs.AuthenticationError) return false;
391
- if (error instanceof _chunkT372OL3Qcjs.InvalidInputError) return false;
392
- if (error instanceof _chunkT372OL3Qcjs.ConflictError) return false;
393
- if (error instanceof _chunkT372OL3Qcjs.InsufficientCreditsError) return false;
394
- if (error instanceof _chunkT372OL3Qcjs.ContextNotFoundError) return false;
395
- if (error instanceof _chunkT372OL3Qcjs.NetworkTimeoutError) return true;
404
+ if (error instanceof _chunkUXNVTP4Dcjs.RateLimitError) return false;
405
+ if (error instanceof _chunkUXNVTP4Dcjs.ServiceUnavailableError) return false;
406
+ if (error instanceof _chunkUXNVTP4Dcjs.AuthenticationError) return false;
407
+ if (error instanceof _chunkUXNVTP4Dcjs.InvalidInputError) return false;
408
+ if (error instanceof _chunkUXNVTP4Dcjs.ConflictError) return false;
409
+ if (error instanceof _chunkUXNVTP4Dcjs.InsufficientCreditsError) return false;
410
+ if (error instanceof _chunkUXNVTP4Dcjs.ContextNotFoundError) return false;
411
+ if (error instanceof _chunkUXNVTP4Dcjs.NetworkTimeoutError) return true;
396
412
  if (isConnectionRefusal(error)) return false;
397
413
  return true;
398
414
  }
@@ -401,12 +417,12 @@ function isConnectionRefusal(error) {
401
417
  return code === "ECONNREFUSED" || code === "ENOTFOUND" || code === "EAI_AGAIN" || code === "ECONNRESET" || code === "EHOSTUNREACH";
402
418
  }
403
419
  function toTransportError(error, correlationId) {
404
- if (error instanceof _chunkT372OL3Qcjs.SynapError) return error;
420
+ if (error instanceof _chunkUXNVTP4Dcjs.SynapError) return error;
405
421
  const name = _optionalChain([error, 'optionalAccess', _13 => _13.name]);
406
422
  if (name === "AbortError" || name === "TimeoutError") {
407
- return new (0, _chunkT372OL3Qcjs.NetworkTimeoutError)("Request timed out", { correlationId, cause: error });
423
+ return new (0, _chunkUXNVTP4Dcjs.NetworkTimeoutError)("Request timed out", { correlationId, cause: error });
408
424
  }
409
- return new (0, _chunkT372OL3Qcjs.ServiceUnavailableError)(
425
+ return new (0, _chunkUXNVTP4Dcjs.ServiceUnavailableError)(
410
426
  `Network request failed: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _14 => _14.message]), () => ( String(error)))}`,
411
427
  { correlationId, cause: error }
412
428
  );
@@ -436,15 +452,15 @@ async function toHttpError(response, correlationId) {
436
452
  switch (response.status) {
437
453
  case 400:
438
454
  case 422:
439
- return new (0, _chunkT372OL3Qcjs.InvalidInputError)(message, opts);
455
+ return new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(message, opts);
440
456
  case 401:
441
457
  case 403:
442
- return new (0, _chunkT372OL3Qcjs.AuthenticationError)(message, opts);
458
+ return new (0, _chunkUXNVTP4Dcjs.AuthenticationError)(message, opts);
443
459
  case 404:
444
- return new (0, _chunkT372OL3Qcjs.ContextNotFoundError)(message, opts);
460
+ return new (0, _chunkUXNVTP4Dcjs.ContextNotFoundError)(message, opts);
445
461
  case 402: {
446
462
  const credit = creditPayload(parsed, detailObject);
447
- return new (0, _chunkT372OL3Qcjs.InsufficientCreditsError)(message, {
463
+ return new (0, _chunkUXNVTP4Dcjs.InsufficientCreditsError)(message, {
448
464
  ...opts,
449
465
  balanceCredits: numberOrNull(credit["balance_credits"]),
450
466
  requiredCredits: _nullishCoalesce(numberOrNull(credit["minimum_required_credits"]), () => ( numberOrNull(credit["required_credits"]))),
@@ -456,14 +472,14 @@ async function toHttpError(response, correlationId) {
456
472
  }
457
473
  case 409:
458
474
  if (detailObject !== null && detailObject["code"] === "transcript_conflict") {
459
- return new (0, _chunkT372OL3Qcjs.TranscriptConflictError)(message, opts);
475
+ return new (0, _chunkUXNVTP4Dcjs.TranscriptConflictError)(message, opts);
460
476
  }
461
- return new (0, _chunkT372OL3Qcjs.ConflictError)(message, opts);
477
+ return new (0, _chunkUXNVTP4Dcjs.ConflictError)(message, opts);
462
478
  case 429: {
463
479
  const header = response.headers.get("retry-after");
464
480
  const retryAfter = header !== null && header.trim() !== "" ? Number(header) : null;
465
481
  const credit = creditPayload(parsed, detailObject);
466
- return new (0, _chunkT372OL3Qcjs.RateLimitError)(message, {
482
+ return new (0, _chunkUXNVTP4Dcjs.RateLimitError)(message, {
467
483
  ...opts,
468
484
  retryAfterSeconds: retryAfter !== null && Number.isFinite(retryAfter) ? retryAfter : null,
469
485
  reason: creditReason(credit),
@@ -472,12 +488,12 @@ async function toHttpError(response, correlationId) {
472
488
  });
473
489
  }
474
490
  case 503:
475
- return new (0, _chunkT372OL3Qcjs.ServiceUnavailableError)(message, opts);
491
+ return new (0, _chunkUXNVTP4Dcjs.ServiceUnavailableError)(message, opts);
476
492
  case 504:
477
- return new (0, _chunkT372OL3Qcjs.AgentUnavailableError)(message, opts);
493
+ return new (0, _chunkUXNVTP4Dcjs.AgentUnavailableError)(message, opts);
478
494
  default:
479
- if (response.status >= 500) return new (0, _chunkT372OL3Qcjs.ServiceUnavailableError)(message, opts);
480
- return new (0, _chunkT372OL3Qcjs.SynapError)(message, opts);
495
+ if (response.status >= 500) return new (0, _chunkUXNVTP4Dcjs.ServiceUnavailableError)(message, opts);
496
+ return new (0, _chunkUXNVTP4Dcjs.SynapError)(message, opts);
481
497
  }
482
498
  }
483
499
  function numberOrNull(v) {
@@ -490,7 +506,7 @@ function withTimeout(ms, external) {
490
506
  const controller = new AbortController();
491
507
  const onExternalAbort = () => controller.abort(_optionalChain([external, 'optionalAccess', _15 => _15.reason]));
492
508
  const timer = setTimeout(() => {
493
- controller.abort(new (0, _chunkT372OL3Qcjs.NetworkTimeoutError)(`Timed out after ${ms}ms`));
509
+ controller.abort(new (0, _chunkUXNVTP4Dcjs.NetworkTimeoutError)(`Timed out after ${ms}ms`));
494
510
  }, ms);
495
511
  _optionalChain([timer, 'access', _16 => _16.unref, 'optionalCall', _17 => _17()]);
496
512
  if (external) {
@@ -619,16 +635,15 @@ function buildFetchRequest(scope, options) {
619
635
  const conversationId = opt(options, "conversation_id", "conversationId");
620
636
  const searchQuery = opt(options, "search_query", "searchQuery");
621
637
  const maxResults = _nullishCoalesce(opt(options, "max_results", "maxResults"), () => ( 10));
622
- const precisionLevel = _nullishCoalesce(opt(options, "precision_level", "precisionLevel"), () => ( "high"));
623
638
  const queryDate = opt(options, "query_date", "queryDate");
624
639
  const perQuery = opt(options, "max_results_per_query", "maxResultsPerQuery");
625
640
  const responseShape = responseShapeOf(options);
626
- const mode = _nullishCoalesce(options.mode, () => ( "fast"));
641
+ const { mode, precisionLevel } = retrievalOptionsOf(options);
627
642
  if (searchQuery !== void 0 && !Array.isArray(searchQuery)) {
628
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("search_query must be an array when provided");
643
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("search_query must be an array when provided");
629
644
  }
630
645
  if (options.types !== void 0 && !Array.isArray(options.types)) {
631
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("types must be an array when provided");
646
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("types must be an array when provided");
632
647
  }
633
648
  const body = {
634
649
  conversation_id: _nullishCoalesce(conversationId, () => ( null)),
@@ -644,25 +659,27 @@ function buildFetchRequest(scope, options) {
644
659
  if (options.include_conversation_context === false) {
645
660
  body["include_conversation_context"] = false;
646
661
  }
662
+ const scopePath = opt(options, "scope_path", "scopePath");
663
+ if (scopePath !== void 0 && scopePath !== null && Object.keys(scopePath).length > 0) {
664
+ body["scope"] = scopePath;
665
+ }
647
666
  switch (scope) {
648
667
  case "user":
649
668
  {
650
- if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
669
+ if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
651
670
  body["user_id"] = userId;
652
- const scopePath = opt(options, "scope_path", "scopePath");
653
- if (scopePath !== void 0) body["scope"] = scopePath;
654
671
  const contextMode = _nullishCoalesce(opt(options, "context_mode", "contextMode"), () => ( "in-conversation"));
655
672
  if (!VALID_CONTEXT_MODES.includes(contextMode)) {
656
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
673
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
657
674
  `Invalid context_mode '${contextMode}'. Must be one of: ${VALID_CONTEXT_MODES.join(", ")}`
658
675
  );
659
676
  }
660
677
  const lastN = _nullishCoalesce(opt(options, "last_n_conversations", "lastNConversations"), () => ( 1));
661
678
  if (!Number.isInteger(lastN)) {
662
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("last_n_conversations must be an integer");
679
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("last_n_conversations must be an integer");
663
680
  }
664
681
  if (lastN < 0 || lastN > 20) {
665
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("last_n_conversations must be between 0 and 20");
682
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("last_n_conversations must be between 0 and 20");
666
683
  }
667
684
  if (contextMode === "conversation-summary") {
668
685
  body["context_mode"] = contextMode;
@@ -674,11 +691,11 @@ function buildFetchRequest(scope, options) {
674
691
  }
675
692
  break;
676
693
  case "customer":
677
- if (!customerId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("customer_id is required");
694
+ if (!customerId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("customer_id is required");
678
695
  body["customer_id"] = customerId;
679
696
  break;
680
697
  case "conversation":
681
- if (!conversationId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("conversation_id is required");
698
+ if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
682
699
  if (userId !== void 0) body["user_id"] = userId;
683
700
  if (customerId !== void 0) body["customer_id"] = customerId;
684
701
  break;
@@ -691,25 +708,44 @@ var VALID_CONTEXT_MODES = ["in-conversation", "conversation-summary"];
691
708
  function responseShapeOf(options) {
692
709
  const shape = _nullishCoalesce(opt(options, "response_shape", "responseShape"), () => ( "by_type"));
693
710
  if (!RESPONSE_SHAPES.includes(shape)) {
694
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
711
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
695
712
  `Invalid response_shape '${shape}'. Must be one of: ${RESPONSE_SHAPES.join(", ")}`
696
713
  );
697
714
  }
698
715
  return shape;
699
716
  }
717
+ var VALID_MODES = ["fast", "accurate"];
718
+ var VALID_PRECISION = ["high", "medium"];
719
+ function retrievalOptionsOf(options) {
720
+ const mode = _nullishCoalesce(options.mode, () => ( "fast"));
721
+ if (!VALID_MODES.includes(mode)) {
722
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
723
+ `Invalid mode '${mode}'. Must be one of: ${VALID_MODES.join(", ")}`
724
+ );
725
+ }
726
+ const precisionLevel = _nullishCoalesce(opt(options, "precision_level", "precisionLevel"), () => ( "high"));
727
+ if (!VALID_PRECISION.includes(precisionLevel)) {
728
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
729
+ `Invalid precision_level '${precisionLevel}'. Must be one of: ${VALID_PRECISION.join(", ")}`
730
+ );
731
+ }
732
+ return { mode, precisionLevel };
733
+ }
700
734
  async function fetchContext(transport, scope, options = {}, hooks = {}) {
701
735
  const startedAt = Date.now();
702
- transport.checkCustomerId(
736
+ await _optionalChain([transport, 'access', _25 => _25.ready, 'optionalCall', _26 => _26()]);
737
+ await transport.checkCustomerId(
703
738
  opt(options, "customer_id", "customerId"),
704
739
  `${scope}.context.fetch`
705
740
  );
706
741
  const responseShape = responseShapeOf(options);
742
+ retrievalOptionsOf(options);
707
743
  const network = async () => {
708
744
  const { endpoint, body } = buildFetchRequest(scope, options);
709
745
  const result = await transport.request(endpoint, { body });
710
- return applyResponseShape(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _25 => _25["context"]]), () => ( {})), responseShape);
746
+ return applyResponseShape(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _27 => _27["context"]]), () => ( {})), responseShape);
711
747
  };
712
- const anticipated = await _asyncNullishCoalesce(await _optionalChain([hooks, 'access', _26 => _26.beforeFetch, 'optionalCall', _27 => _27(scope, options)]), async () => ( null));
748
+ const anticipated = await _asyncNullishCoalesce(await _optionalChain([hooks, 'access', _28 => _28.beforeFetch, 'optionalCall', _29 => _29(scope, options)]), async () => ( null));
713
749
  if (anticipated !== null && anticipated.borderline) {
714
750
  const pending = network();
715
751
  pending.catch(() => void 0);
@@ -720,17 +756,17 @@ async function fetchContext(transport, scope, options = {}, hooks = {}) {
720
756
  const won = await Promise.race([pending.then((r) => r, () => null), late]);
721
757
  if (timer !== void 0) clearTimeout(timer);
722
758
  if (won !== null) {
723
- _optionalChain([hooks, 'access', _28 => _28.onAssembled, 'optionalCall', _29 => _29(scope, options, won, startedAt)]);
759
+ _optionalChain([hooks, 'access', _30 => _30.onAssembled, 'optionalCall', _31 => _31(scope, options, won, startedAt)]);
724
760
  return won;
725
761
  }
726
762
  }
727
763
  if (anticipated !== null) {
728
- _optionalChain([hooks, 'access', _30 => _30.onServedFromCache, 'optionalCall', _31 => _31(scope, options, anticipated)]);
729
- _optionalChain([hooks, 'access', _32 => _32.onAssembled, 'optionalCall', _33 => _33(scope, options, anticipated.response, startedAt)]);
764
+ _optionalChain([hooks, 'access', _32 => _32.onServedFromCache, 'optionalCall', _33 => _33(scope, options, anticipated)]);
765
+ _optionalChain([hooks, 'access', _34 => _34.onAssembled, 'optionalCall', _35 => _35(scope, options, anticipated.response, startedAt)]);
730
766
  return applyResponseShape(anticipated.response, responseShape);
731
767
  }
732
768
  const response = await network();
733
- _optionalChain([hooks, 'access', _34 => _34.onAssembled, 'optionalCall', _35 => _35(scope, options, response, startedAt)]);
769
+ _optionalChain([hooks, 'access', _36 => _36.onAssembled, 'optionalCall', _37 => _37(scope, options, response, startedAt)]);
734
770
  return response;
735
771
  }
736
772
 
@@ -985,17 +1021,17 @@ function isoOrNull(v) {
985
1021
  return v instanceof Date ? v.toISOString() : v;
986
1022
  }
987
1023
  function buildCreateBody(options) {
988
- if (!options.document) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("document is required");
1024
+ if (!options.document) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("document is required");
989
1025
  const o2 = options;
990
1026
  const documentType = _nullishCoalesce(either(o2, "document_type", "documentType"), () => ( DEFAULT_DOCUMENT_TYPE));
991
1027
  const mode = _nullishCoalesce(options.mode, () => ( DEFAULT_INGEST_MODE));
992
1028
  if (!DOCUMENT_TYPES.includes(documentType)) {
993
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
1029
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
994
1030
  `Invalid document_type '${documentType}'. Expected one of: ${DOCUMENT_TYPES.join(", ")}`
995
1031
  );
996
1032
  }
997
1033
  if (!INGEST_MODES.includes(mode)) {
998
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
1034
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
999
1035
  `Invalid mode '${mode}'. Expected one of: ${INGEST_MODES.join(", ")}`
1000
1036
  );
1001
1037
  }
@@ -1022,13 +1058,13 @@ var FORGET_DESCRIPTION_MAX = 500;
1022
1058
  function buildForgetBody(options) {
1023
1059
  const description = options.description;
1024
1060
  if (typeof description !== "string" || description.length < FORGET_DESCRIPTION_MIN || description.length > FORGET_DESCRIPTION_MAX) {
1025
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
1061
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1026
1062
  `description must be between ${FORGET_DESCRIPTION_MIN} and ${FORGET_DESCRIPTION_MAX} characters`
1027
1063
  );
1028
1064
  }
1029
1065
  const mode = _nullishCoalesce(options.mode, () => ( "preview"));
1030
1066
  if (!FORGET_MODES.includes(mode)) {
1031
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
1067
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1032
1068
  `Invalid mode '${mode}'. Expected one of: ${FORGET_MODES.join(", ")}`
1033
1069
  );
1034
1070
  }
@@ -1046,13 +1082,13 @@ function createMemoriesInterface(transport, onForgotten) {
1046
1082
  return {
1047
1083
  async create(options) {
1048
1084
  const o2 = options;
1049
- transport.checkCustomerId(_nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])), "memories.create");
1085
+ await transport.checkCustomerId(_nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])), "memories.create");
1050
1086
  return transport.request("memories_create", { body: buildCreateBody(options) });
1051
1087
  },
1052
1088
  async batch_create(options) {
1053
1089
  const docs = options.documents;
1054
1090
  if (!Array.isArray(docs) || docs.length === 0) {
1055
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("documents must be a non-empty array");
1091
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("documents must be a non-empty array");
1056
1092
  }
1057
1093
  const failFast = _nullishCoalesce(_nullishCoalesce(options.fail_fast, () => ( options.failFast)), () => ( false));
1058
1094
  return transport.request("memories_batch", {
@@ -1062,15 +1098,15 @@ function createMemoriesInterface(transport, onForgotten) {
1062
1098
  async create_from_file(options) {
1063
1099
  const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
1064
1100
  const customerId = _nullishCoalesce(options.customer_id, () => ( options.customerId));
1065
- if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
1066
- transport.checkCustomerId(customerId, "memories.create_from_file");
1101
+ if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
1102
+ await transport.checkCustomerId(customerId, "memories.create_from_file");
1067
1103
  const filePath = _nullishCoalesce(options.file_path, () => ( options.filePath));
1068
1104
  const sources = [filePath, options.file, options.text].filter((v) => v !== void 0);
1069
1105
  if (sources.length === 0) {
1070
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("One of file_path, file, or text must be provided.");
1106
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("One of file_path, file, or text must be provided.");
1071
1107
  }
1072
1108
  if (sources.length > 1) {
1073
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
1109
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1074
1110
  "Provide exactly one of file_path, file, or text, not several."
1075
1111
  );
1076
1112
  }
@@ -1101,13 +1137,13 @@ function createMemoriesInterface(transport, onForgotten) {
1101
1137
  });
1102
1138
  },
1103
1139
  async get(memoryId) {
1104
- if (!memoryId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("memory_id is required");
1140
+ if (!memoryId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("memory_id is required");
1105
1141
  return transport.request("memories_get", { pathParams: { memory_id: memoryId } });
1106
1142
  },
1107
1143
  async update(options) {
1108
1144
  const memoryId = _nullishCoalesce(options.memory_id, () => ( options.memoryId));
1109
- if (!memoryId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("memory_id is required");
1110
- if (!options.document) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("document is required");
1145
+ if (!memoryId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("memory_id is required");
1146
+ if (!options.document) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("document is required");
1111
1147
  const body = {
1112
1148
  document: options.document,
1113
1149
  merge_strategy: _nullishCoalesce(_nullishCoalesce(options.merge_strategy, () => ( options.mergeStrategy)), () => ( "smart-merge"))
@@ -1122,7 +1158,7 @@ function createMemoriesInterface(transport, onForgotten) {
1122
1158
  },
1123
1159
  async delete(memoryId) {
1124
1160
  if (!memoryId) {
1125
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
1161
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1126
1162
  "memory_id is required. Deleting by user is no longer supported: the previous implementation tracked ids in process memory, so it silently deleted nothing in any serverless or multi-process deployment while reporting success."
1127
1163
  );
1128
1164
  }
@@ -1130,10 +1166,10 @@ function createMemoriesInterface(transport, onForgotten) {
1130
1166
  },
1131
1167
  async forget(options) {
1132
1168
  const o2 = options;
1133
- transport.checkCustomerId(_nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])), "memories.forget");
1169
+ await transport.checkCustomerId(_nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])), "memories.forget");
1134
1170
  const body = buildForgetBody(options);
1135
1171
  const result = await transport.request("memories_forget", { body });
1136
- const removed = !!_optionalChain([result, 'optionalAccess', _36 => _36.deleted_ids, 'optionalAccess', _37 => _37.length]) || _optionalChain([result, 'optionalAccess', _38 => _38.status]) === "deleted" || _optionalChain([result, 'optionalAccess', _39 => _39.status]) === "partial";
1172
+ const removed = !!_optionalChain([result, 'optionalAccess', _38 => _38.deleted_ids, 'optionalAccess', _39 => _39.length]) || _optionalChain([result, 'optionalAccess', _40 => _40.status]) === "deleted" || _optionalChain([result, 'optionalAccess', _41 => _41.status]) === "partial";
1137
1173
  if (removed && onForgotten) {
1138
1174
  try {
1139
1175
  onForgotten({
@@ -1146,13 +1182,13 @@ function createMemoriesInterface(transport, onForgotten) {
1146
1182
  return result;
1147
1183
  },
1148
1184
  async status(ingestionId) {
1149
- if (!ingestionId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("ingestion_id is required");
1185
+ if (!ingestionId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("ingestion_id is required");
1150
1186
  return transport.request("memories_status", {
1151
1187
  pathParams: { ingestion_id: ingestionId }
1152
1188
  });
1153
1189
  },
1154
1190
  async wait_for_completion(ingestionId, options = {}) {
1155
- if (!ingestionId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("ingestion_id is required");
1191
+ if (!ingestionId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("ingestion_id is required");
1156
1192
  const timeoutMs = (_nullishCoalesce(_nullishCoalesce(options.timeout_seconds, () => ( options.timeoutSeconds)), () => ( 300))) * 1e3;
1157
1193
  const pollMs = (_nullishCoalesce(_nullishCoalesce(options.poll_interval_seconds, () => ( options.pollIntervalSeconds)), () => ( 2))) * 1e3;
1158
1194
  const deadline = Date.now() + timeoutMs;
@@ -1173,14 +1209,14 @@ function sleep2(ms, signal) {
1173
1209
  if (ms <= 0) return Promise.resolve();
1174
1210
  return new Promise((resolve, reject) => {
1175
1211
  const timer = setTimeout(() => {
1176
- _optionalChain([signal, 'optionalAccess', _40 => _40.removeEventListener, 'call', _41 => _41("abort", onAbort)]);
1212
+ _optionalChain([signal, 'optionalAccess', _42 => _42.removeEventListener, 'call', _43 => _43("abort", onAbort)]);
1177
1213
  resolve();
1178
1214
  }, ms);
1179
1215
  function onAbort() {
1180
1216
  clearTimeout(timer);
1181
- reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _42 => _42.reason]), () => ( new Error("Aborted"))));
1217
+ reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _44 => _44.reason]), () => ( new Error("Aborted"))));
1182
1218
  }
1183
- _optionalChain([signal, 'optionalAccess', _43 => _43.addEventListener, 'call', _44 => _44("abort", onAbort, { once: true })]);
1219
+ _optionalChain([signal, 'optionalAccess', _45 => _45.addEventListener, 'call', _46 => _46("abort", onAbort, { once: true })]);
1184
1220
  });
1185
1221
  }
1186
1222
 
@@ -1190,13 +1226,13 @@ var UUID_RE = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9
1190
1226
  function validateConversationId(conversationId) {
1191
1227
  if (conversationId === void 0 || conversationId === null || conversationId === "") return;
1192
1228
  if (typeof conversationId !== "string" || !UUID_RE.test(conversationId)) {
1193
- throw new (0, _chunkT372OL3Qcjs.InvalidConversationIdError)(`Invalid conversation ID: ${String(conversationId)}`);
1229
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidConversationIdError)(`Invalid conversation ID: ${String(conversationId)}`);
1194
1230
  }
1195
1231
  }
1196
1232
  function validateInstanceId(instanceId) {
1197
1233
  if (instanceId === void 0 || instanceId === null || instanceId === "") return;
1198
1234
  if (typeof instanceId !== "string" || !INSTANCE_ID_RE.test(instanceId)) {
1199
- throw new (0, _chunkT372OL3Qcjs.InvalidInstanceIdError)(`Invalid instance ID: ${String(instanceId)}`);
1235
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInstanceIdError)(`Invalid instance ID: ${String(instanceId)}`);
1200
1236
  }
1201
1237
  }
1202
1238
 
@@ -1246,13 +1282,13 @@ function buildRecordMessageBody(options) {
1246
1282
  const conversationId = either2(o2, "conversation_id", "conversationId");
1247
1283
  const userId = either2(o2, "user_id", "userId");
1248
1284
  const customerId = either2(o2, "customer_id", "customerId");
1249
- if (!conversationId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("conversation_id is required");
1285
+ if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1250
1286
  validateConversationId(conversationId);
1251
- if (!options.role) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("role is required");
1287
+ if (!options.role) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("role is required");
1252
1288
  if (options.content === void 0 || options.content === null) {
1253
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("content is required");
1289
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("content is required");
1254
1290
  }
1255
- if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
1291
+ if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
1256
1292
  const body = {
1257
1293
  conversation_id: conversationId,
1258
1294
  role: options.role,
@@ -1272,10 +1308,10 @@ function buildIngestTranscriptBody(options) {
1272
1308
  const o2 = options;
1273
1309
  const conversationId = either2(o2, "conversation_id", "conversationId");
1274
1310
  const userId = either2(o2, "user_id", "userId");
1275
- if (!conversationId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("conversation_id is required");
1276
- if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
1311
+ if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1312
+ if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
1277
1313
  if (options.transcript === void 0 || options.transcript === null) {
1278
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("transcript is required");
1314
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("transcript is required");
1279
1315
  }
1280
1316
  const body = {
1281
1317
  conversation_id: conversationId,
@@ -1299,7 +1335,7 @@ function buildIngestTranscriptBody(options) {
1299
1335
  function buildCompactBody(options) {
1300
1336
  const o2 = options;
1301
1337
  const conversationId = either2(o2, "conversation_id", "conversationId");
1302
- if (!conversationId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("conversation_id is required");
1338
+ if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1303
1339
  validateConversationId(conversationId);
1304
1340
  const body = { conversation_id: conversationId, force: _nullishCoalesce(options.force, () => ( false)) };
1305
1341
  const strategy = _nullishCoalesce(options.strategy, () => ( either2(o2, "compaction_level", "compactionLevel")));
@@ -1353,7 +1389,7 @@ function storedBatchRows(bodies, result) {
1353
1389
  const r = _nullishCoalesce(result, () => ( {}));
1354
1390
  const results = Array.isArray(r["results"]) ? r["results"] : [];
1355
1391
  const errors = Array.isArray(r["errors"]) ? r["errors"] : [];
1356
- const failed = new Set(errors.map((e) => _optionalChain([e, 'optionalAccess', _45 => _45["index"]])));
1392
+ const failed = new Set(errors.map((e) => _optionalChain([e, 'optionalAccess', _47 => _47["index"]])));
1357
1393
  const stored = bodies.filter((_, index) => !failed.has(index));
1358
1394
  if (stored.length !== results.length) return [];
1359
1395
  const pairs = [];
@@ -1395,13 +1431,13 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1395
1431
  };
1396
1432
  const convId = (v) => {
1397
1433
  const id = typeof v === "string" ? v : _nullishCoalesce(v.conversation_id, () => ( v.conversationId));
1398
- if (!id) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("conversation_id is required");
1434
+ if (!id) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1399
1435
  validateConversationId(id);
1400
1436
  return id;
1401
1437
  };
1402
1438
  return {
1403
1439
  async record_message(options) {
1404
- transport.checkCustomerId(
1440
+ await transport.checkCustomerId(
1405
1441
  _nullishCoalesce(options["customer_id"], () => ( options["customerId"])),
1406
1442
  "conversation.record_message"
1407
1443
  );
@@ -1429,11 +1465,11 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1429
1465
  },
1430
1466
  async record_messages_batch(messages) {
1431
1467
  if (!Array.isArray(messages) || messages.length === 0) {
1432
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("messages must be a non-empty array");
1468
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("messages must be a non-empty array");
1433
1469
  }
1434
1470
  for (const m of messages) {
1435
1471
  const mo = m;
1436
- transport.checkCustomerId(
1472
+ await transport.checkCustomerId(
1437
1473
  _nullishCoalesce(mo["customer_id"], () => ( mo["customerId"])),
1438
1474
  "conversation.record_messages_batch"
1439
1475
  );
@@ -1499,8 +1535,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1499
1535
  pathParams: { conversation_id: id },
1500
1536
  query: { style: _nullishCoalesce(options.style, () => ( "structured")) }
1501
1537
  });
1502
- const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _46 => _46["context_for_prompt"]]), () => ( result)), () => ( {}));
1503
- _optionalChain([localShortTerm, 'access', _47 => _47.reseed, 'optionalCall', _48 => _48(id, response)]);
1538
+ const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _48 => _48["context_for_prompt"]]), () => ( result)), () => ( {}));
1539
+ _optionalChain([localShortTerm, 'access', _49 => _49.reseed, 'optionalCall', _50 => _50(id, response)]);
1504
1540
  return withHistory(response);
1505
1541
  },
1506
1542
  async compact(options) {
@@ -1540,8 +1576,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1540
1576
  * Returns an idempotent unsubscribe thunk, matching Python.
1541
1577
  */
1542
1578
  subscribe_to_compaction_updates(conversationId, callback) {
1543
- if (!conversationId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("conversation_id is required");
1544
- if (typeof callback !== "function") throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("callback is required");
1579
+ if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1580
+ if (typeof callback !== "function") throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("callback is required");
1545
1581
  return subscribers.add(conversationId, callback);
1546
1582
  },
1547
1583
  /** Remove subscribers for one conversation, or all of them. Returns the count removed. */
@@ -1557,7 +1593,7 @@ function createUserNamespace(transport, hooks = {}) {
1557
1593
  return {
1558
1594
  async get_profile(options) {
1559
1595
  const userId = typeof options === "string" ? options : _nullishCoalesce(options.user_id, () => ( options.userId));
1560
- if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
1596
+ if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
1561
1597
  const customerId = typeof options === "string" ? void 0 : _nullishCoalesce(options.customer_id, () => ( options.customerId));
1562
1598
  return transport.request("user_profile", {
1563
1599
  pathParams: { user_id: userId },
@@ -1606,7 +1642,7 @@ function createCreditsNamespace(transport) {
1606
1642
  });
1607
1643
  },
1608
1644
  async redeem(code) {
1609
- if (!code) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("code is required");
1645
+ if (!code) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("code is required");
1610
1646
  return transport.request("credits_redeem", { body: { code } });
1611
1647
  }
1612
1648
  };
@@ -1617,11 +1653,11 @@ function createCacheNamespace(cache) {
1617
1653
  return {
1618
1654
  clear: () => cache.clear(),
1619
1655
  clear_user: (userId) => {
1620
- if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
1656
+ if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
1621
1657
  cache.dropEntity(userId);
1622
1658
  },
1623
1659
  clear_customer: (customerId) => {
1624
- if (!customerId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("customer_id is required");
1660
+ if (!customerId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("customer_id is required");
1625
1661
  cache.dropEntity(customerId);
1626
1662
  },
1627
1663
  stats: () => ({ bundles: cache.size, items: cache.itemCount })
@@ -1693,8 +1729,8 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1693
1729
  let onConversationState = null;
1694
1730
  const internals = {
1695
1731
  onCompactionUpdate(conversationId, bundle) {
1696
- _optionalChain([applyCompaction, 'optionalCall', _49 => _49(bundle)]);
1697
- _optionalChain([dispatchCompaction, 'optionalCall', _50 => _50(conversationId, bundle)]);
1732
+ _optionalChain([applyCompaction, 'optionalCall', _51 => _51(bundle)]);
1733
+ _optionalChain([dispatchCompaction, 'optionalCall', _52 => _52(conversationId, bundle)]);
1698
1734
  },
1699
1735
  setCompactionApplier(apply) {
1700
1736
  applyCompaction = apply;
@@ -1706,10 +1742,10 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1706
1742
  onConversationState = handle;
1707
1743
  },
1708
1744
  sendContextUsed(event) {
1709
- _optionalChain([client, 'optionalAccess', _51 => _51.sendContextUsed, 'call', _52 => _52(event)]);
1745
+ _optionalChain([client, 'optionalAccess', _53 => _53.sendContextUsed, 'call', _54 => _54(event)]);
1710
1746
  },
1711
1747
  sendContextAssembled(event) {
1712
- _optionalChain([client, 'optionalAccess', _53 => _53.sendContextAssembled, 'call', _54 => _54(event)]);
1748
+ _optionalChain([client, 'optionalAccess', _55 => _55.sendContextAssembled, 'call', _56 => _56(event)]);
1713
1749
  },
1714
1750
  setCompactionDispatcher(dispatch) {
1715
1751
  dispatchCompaction = dispatch;
@@ -1721,7 +1757,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1721
1757
  function ensureSession(conversationId, userId, customerId) {
1722
1758
  if (!conversationId || !userId || client === null) return;
1723
1759
  if (openSessions.has(conversationId)) return;
1724
- const sessionId = _chunkT372OL3Qcjs.newCorrelationId.call(void 0, );
1760
+ const sessionId = _chunkUXNVTP4Dcjs.newCorrelationId.call(void 0, );
1725
1761
  try {
1726
1762
  client.sendSessionControl({
1727
1763
  action: "start",
@@ -1737,13 +1773,13 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1737
1773
  const namespace = {
1738
1774
  async listen(options = {}) {
1739
1775
  if (client !== null) {
1740
- throw new (0, _chunkT372OL3Qcjs.ListeningAlreadyActiveError)("Listening is already active on this instance");
1776
+ throw new (0, _chunkUXNVTP4Dcjs.ListeningAlreadyActiveError)("Listening is already active on this instance");
1741
1777
  }
1742
1778
  try {
1743
- _optionalChain([onListen, 'optionalCall', _55 => _55()]);
1779
+ _optionalChain([onListen, 'optionalCall', _57 => _57()]);
1744
1780
  } catch (e10) {
1745
1781
  }
1746
- const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-L6OQPZN7.cjs")));
1782
+ const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-5GYUWETN.cjs")));
1747
1783
  const onContext = _nullishCoalesce(options.on_context, () => ( options.onContext));
1748
1784
  const onDisconnect = _nullishCoalesce(options.on_disconnect, () => ( options.onDisconnect));
1749
1785
  const onReconnect = _nullishCoalesce(options.on_reconnect, () => ( options.onReconnect));
@@ -1758,17 +1794,17 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1758
1794
  internals.onCompactionUpdate(conversationId, bundle);
1759
1795
  },
1760
1796
  onConversationState: (conversationId, messageCount) => {
1761
- _optionalChain([onConversationState, 'optionalCall', _56 => _56(conversationId, messageCount)]);
1797
+ _optionalChain([onConversationState, 'optionalCall', _58 => _58(conversationId, messageCount)]);
1762
1798
  },
1763
1799
  onStateChange: (state) => {
1764
1800
  if (state !== "connected") openSessions.clear();
1765
1801
  if (state === "reconnecting") {
1766
1802
  reconnectAttempts += 1;
1767
- _optionalChain([onReconnect, 'optionalCall', _57 => _57(reconnectAttempts)]);
1803
+ _optionalChain([onReconnect, 'optionalCall', _59 => _59(reconnectAttempts)]);
1768
1804
  } else if (state === "disconnected") {
1769
- const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _58 => _58.lastError]), () => ( null));
1805
+ const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _60 => _60.lastError]), () => ( null));
1770
1806
  const reason = stopped === null ? "stream disconnected" : `credit_stop:${_nullishCoalesce(stopped.reason, () => ( "unknown"))}`;
1771
- _optionalChain([onDisconnect, 'optionalCall', _59 => _59(reason)]);
1807
+ _optionalChain([onDisconnect, 'optionalCall', _61 => _61(reason)]);
1772
1808
  }
1773
1809
  }
1774
1810
  });
@@ -1776,9 +1812,9 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1776
1812
  try {
1777
1813
  await created.connect();
1778
1814
  } catch (error) {
1779
- if (error instanceof _chunkT372OL3Qcjs.SynapError) throw error;
1780
- throw new (0, _chunkT372OL3Qcjs.SynapError)(
1781
- `Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _60 => _60.message]), () => ( String(error)))}`,
1815
+ if (error instanceof _chunkUXNVTP4Dcjs.SynapError) throw error;
1816
+ throw new (0, _chunkUXNVTP4Dcjs.SynapError)(
1817
+ `Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _62 => _62.message]), () => ( String(error)))}`,
1782
1818
  { cause: error }
1783
1819
  );
1784
1820
  }
@@ -1807,13 +1843,13 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1807
1843
  }
1808
1844
  },
1809
1845
  async send_message(options) {
1810
- if (client === null) throw new (0, _chunkT372OL3Qcjs.ListeningNotActiveError)("Listening is not active");
1846
+ if (client === null) throw new (0, _chunkUXNVTP4Dcjs.ListeningNotActiveError)("Listening is not active");
1811
1847
  if (options.content === void 0) {
1812
- throw new (0, _chunkT372OL3Qcjs.ListeningNotActiveError)("content is required");
1848
+ throw new (0, _chunkUXNVTP4Dcjs.ListeningNotActiveError)("content is required");
1813
1849
  }
1814
1850
  const eventType = _nullishCoalesce(_nullishCoalesce(options.event_type, () => ( options.eventType)), () => ( "user_message"));
1815
1851
  if (!KNOWN_EVENT_TYPES.has(eventType)) {
1816
- throw new (0, _chunkT372OL3Qcjs.SynapError)(
1852
+ throw new (0, _chunkUXNVTP4Dcjs.SynapError)(
1817
1853
  `unknown event_type '${eventType}'. Expected one of: ` + [...KNOWN_EVENT_TYPES].sort().join(", ")
1818
1854
  );
1819
1855
  }
@@ -1824,7 +1860,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1824
1860
  _nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( ""))
1825
1861
  );
1826
1862
  if (eventType === "user_message" || eventType === "assistant_message") {
1827
- _optionalChain([onTurn, 'optionalCall', _61 => _61({
1863
+ _optionalChain([onTurn, 'optionalCall', _63 => _63({
1828
1864
  conversationId,
1829
1865
  role: _nullishCoalesce(options.role, () => ( "user")),
1830
1866
  content: options.content
@@ -1870,7 +1906,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1870
1906
  async record_tool_result(options) {
1871
1907
  const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
1872
1908
  if (conversationId) {
1873
- _optionalChain([onToolResult, 'optionalCall', _62 => _62({ conversationId, result: options.result, toolName: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")) })]);
1909
+ _optionalChain([onToolResult, 'optionalCall', _64 => _64({ conversationId, result: options.result, toolName: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")) })]);
1874
1910
  }
1875
1911
  await namespace.send_message({
1876
1912
  content: "",
@@ -1887,7 +1923,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1887
1923
  });
1888
1924
  },
1889
1925
  async record_thinking(options) {
1890
- if (client === null) throw new (0, _chunkT372OL3Qcjs.ListeningNotActiveError)("Listening is not active");
1926
+ if (client === null) throw new (0, _chunkUXNVTP4Dcjs.ListeningNotActiveError)("Listening is not active");
1891
1927
  const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
1892
1928
  ensureSession(
1893
1929
  conversationId,
@@ -1922,7 +1958,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1922
1958
  }
1923
1959
 
1924
1960
  // src/version.ts
1925
- var SDK_VERSION = "0.5.9";
1961
+ var SDK_VERSION = "0.5.11";
1926
1962
 
1927
1963
  // src/registry.ts
1928
1964
  var instances = /* @__PURE__ */ new Map();
@@ -2269,13 +2305,13 @@ function bytesOf(text) {
2269
2305
  }
2270
2306
  var TurnStore = (_class3 = class {
2271
2307
 
2272
- __init4() {this.onDisk = false}
2308
+ __init5() {this.onDisk = false}
2273
2309
  #now;
2274
2310
  #seq = 0;
2275
2311
  #writes = 0;
2276
2312
  #conversations = /* @__PURE__ */ new Map();
2277
2313
  #vectors = /* @__PURE__ */ new Map();
2278
- constructor(options = {}) {;_class3.prototype.__init4.call(this);
2314
+ constructor(options = {}) {;_class3.prototype.__init5.call(this);
2279
2315
  this.limits = _nullishCoalesce(options.limits, () => ( { ..._chunkICUFS3B5cjs.HISTORY_SEARCH.store_limits }));
2280
2316
  this.#now = _nullishCoalesce(options.now, () => ( (() => Date.now() / 1e3)));
2281
2317
  }
@@ -2390,7 +2426,7 @@ var TurnStore = (_class3 = class {
2390
2426
  }
2391
2427
  /** Turns the server also holds: archived tool results are local only. Python: `count`. */
2392
2428
  count(conversationId) {
2393
- return (_nullishCoalesce(_optionalChain([this, 'access', _63 => _63.#conversations, 'access', _64 => _64.get, 'call', _65 => _65(conversationId), 'optionalAccess', _66 => _66.turns]), () => ( []))).filter((t) => t.role !== "tool").length;
2429
+ return (_nullishCoalesce(_optionalChain([this, 'access', _65 => _65.#conversations, 'access', _66 => _66.get, 'call', _67 => _67(conversationId), 'optionalAccess', _68 => _68.turns]), () => ( []))).filter((t) => t.role !== "tool").length;
2394
2430
  }
2395
2431
  sizeBytes() {
2396
2432
  let n2 = 0;
@@ -2569,7 +2605,7 @@ function askedKinds(query) {
2569
2605
  }
2570
2606
  function asksHowItStarted(query) {
2571
2607
  const spec = _chunkICUFS3B5cjs.HISTORY_SEARCH.early_query;
2572
- if (!_optionalChain([spec, 'optionalAccess', _67 => _67.pattern])) return false;
2608
+ if (!_optionalChain([spec, 'optionalAccess', _69 => _69.pattern])) return false;
2573
2609
  return new RegExp(spec.pattern, (_nullishCoalesce(spec.flags, () => ( ""))).includes("i") ? "i" : "").test(_nullishCoalesce(query, () => ( "")));
2574
2610
  }
2575
2611
  async function searchTurns(turns, query, options = {}) {
@@ -3585,7 +3621,7 @@ function buildTool(target, options = {}, onWarning = () => {
3585
3621
  const scope = String(_nullishCoalesce(options.scope, () => ( "user"))).toLowerCase();
3586
3622
  if (!VALID_SCOPES.includes(scope)) {
3587
3623
  const sorted = [...VALID_SCOPES].sort();
3588
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
3624
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
3589
3625
  `scope must be one of ['${sorted.join("', '")}'], got '${String(options.scope)}'`
3590
3626
  );
3591
3627
  }
@@ -3593,10 +3629,10 @@ function buildTool(target, options = {}, onWarning = () => {
3593
3629
  const customerId = _nullishCoalesce(options.customer_id, () => ( options.customerId));
3594
3630
  const conversationId = _nullishCoalesce(options.conversation_id, () => ( options.conversationId));
3595
3631
  if (scope === "user" && (userId === void 0 || userId === "")) {
3596
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("scope='user' requires user_id");
3632
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("scope='user' requires user_id");
3597
3633
  }
3598
3634
  if (scope === "customer" && (customerId === void 0 || customerId === "")) {
3599
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("scope='customer' requires customer_id");
3635
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("scope='customer' requires customer_id");
3600
3636
  }
3601
3637
  if (scope === "conversation" && (userId === void 0 || userId === "")) {
3602
3638
  onWarning(
@@ -3605,7 +3641,7 @@ function buildTool(target, options = {}, onWarning = () => {
3605
3641
  }
3606
3642
  const style = String(_nullishCoalesce(options.style, () => ( "openai")));
3607
3643
  if (style !== "openai" && style !== "anthropic") {
3608
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(`style must be 'openai' or 'anthropic', got '${style}'`);
3644
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(`style must be 'openai' or 'anthropic', got '${style}'`);
3609
3645
  }
3610
3646
  const toolName = _nullishCoalesce(options.name, () => ( `synap_fetch_${scope}_context`));
3611
3647
  const toolDesc = _nullishCoalesce(options.description, () => ( defaultToolDescription(scope)));
@@ -3648,6 +3684,7 @@ var SynapClient = (_class4 = class _SynapClient {
3648
3684
 
3649
3685
  #closed = false;
3650
3686
  #initialized = false;
3687
+ #identity;
3651
3688
  #registryKeys;
3652
3689
  #compactionSubscribers;
3653
3690
  #shortTerm;
@@ -3698,6 +3735,7 @@ var SynapClient = (_class4 = class _SynapClient {
3698
3735
  userAgent: `@maximem/synap-js-sdk/${SDK_VERSION}`
3699
3736
  });
3700
3737
  if (options.heartbeat) this.#transport.startHeartbeat();
3738
+ this.#transport.identityResolver = () => this.#resolveIdentity();
3701
3739
  this.#anticipationCache = new (0, _chunkICUFS3B5cjs.AnticipationCache)();
3702
3740
  this.#fetchHooks = {
3703
3741
  beforeFetch: async (scope, options2) => {
@@ -3757,7 +3795,7 @@ var SynapClient = (_class4 = class _SynapClient {
3757
3795
  this.#localEncoder = _nullishCoalesce(_nullishCoalesce(options.history_search_encoder, () => ( options.historySearchEncoder)), () => ( null));
3758
3796
  const modelOption = options.history_search_model !== void 0 ? options.history_search_model : options.historySearchModel;
3759
3797
  this.#localModelName = modelOption === void 0 ? "auto" : modelOption;
3760
- if (_optionalChain([this, 'access', _68 => _68.#localEncoder, 'optionalAccess', _69 => _69.model]) === _chunkICUFS3B5cjs.SEMANTIC_MATCH.model) this.#anticipationCache.setEncoder(this.#localEncoder);
3798
+ if (_optionalChain([this, 'access', _70 => _70.#localEncoder, 'optionalAccess', _71 => _71.model]) === _chunkICUFS3B5cjs.SEMANTIC_MATCH.model) this.#anticipationCache.setEncoder(this.#localEncoder);
3761
3799
  this.#turns = new TurnCounter();
3762
3800
  this.conversation = createConversationNamespace(
3763
3801
  this.#transport,
@@ -3851,9 +3889,9 @@ var SynapClient = (_class4 = class _SynapClient {
3851
3889
  */
3852
3890
  async searchMemory(options) {
3853
3891
  const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
3854
- if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
3892
+ if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
3855
3893
  if (options.query === void 0 || options.query === null) {
3856
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("query is required");
3894
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("query is required");
3857
3895
  }
3858
3896
  const context = await fetchContext(this.#transport, "user", {
3859
3897
  user_id: userId,
@@ -3874,7 +3912,7 @@ var SynapClient = (_class4 = class _SynapClient {
3874
3912
  */
3875
3913
  async getMemories(options) {
3876
3914
  const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
3877
- if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
3915
+ if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
3878
3916
  const context = await fetchContext(this.#transport, "user", {
3879
3917
  user_id: userId,
3880
3918
  ...pick3(options, "customer_id", "customerId") !== void 0 ? { customer_id: pick3(options, "customer_id", "customerId") } : {},
@@ -3903,19 +3941,30 @@ var SynapClient = (_class4 = class _SynapClient {
3903
3941
  /**
3904
3942
  * Resolve `client_id` and `instance_id` from the API key.
3905
3943
  *
3906
- * Mirrors Python's `initialize()`. Calling it is optional here (unlike
3907
- * Python, which raises "SDK not initialized" from `_ensure_initialized`)
3908
- * because every HTTP route authenticates on the API key alone. It matters
3909
- * for the anticipation cache: a bundle shared at client scope is filtered on
3910
- * `client_id`, and an empty one fails that filter for every bundle. That was
3911
- * a silent cache-scope bug in Python before whoami bootstrapping existed.
3944
+ * Mirrors Python's `initialize()`. Python raises "SDK not initialized" on
3945
+ * any call made before it; here the first request runs the same resolution
3946
+ * instead (`identityResolver` on the transport), so skipping this call costs
3947
+ * nothing and breaks no existing caller. It matters for the anticipation
3948
+ * cache: a bundle shared at client scope is filtered on `client_id`, and an
3949
+ * empty one fails that filter for every bundle.
3950
+ *
3951
+ * Calling it explicitly still locks `configure()`, as in Python. Resolving
3952
+ * on first use does not, because a caller who never called it could always
3953
+ * configure after a request, and that keeps working.
3912
3954
  *
3913
3955
  * Best-effort and idempotent. A whoami failure leaves whatever the
3914
3956
  * constructor resolved and is not fatal.
3915
3957
  */
3916
3958
  async initialize() {
3917
- if (this.#initialized) return;
3918
3959
  this.#initialized = true;
3960
+ await this.#resolveIdentity();
3961
+ }
3962
+ /** Runs whoami at most once, however many calls arrive together. */
3963
+ #resolveIdentity() {
3964
+ this.#identity ??= this.#whoami();
3965
+ return this.#identity;
3966
+ }
3967
+ async #whoami() {
3919
3968
  const credentials = this.#transport.currentCredentials();
3920
3969
  if (credentials.clientId !== "" && credentials.instanceId !== "") return;
3921
3970
  try {
@@ -3968,7 +4017,7 @@ var SynapClient = (_class4 = class _SynapClient {
3968
4017
  */
3969
4018
  configure(options = {}) {
3970
4019
  if (this.#initialized) {
3971
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("Cannot reconfigure after initialization");
4020
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("Cannot reconfigure after initialization");
3972
4021
  }
3973
4022
  if (options.timeouts !== void 0) this.#transport.setTimeouts(options.timeouts);
3974
4023
  if (options.retryPolicy !== void 0 || options.retry_policy !== void 0) {
@@ -4019,6 +4068,7 @@ var SynapClient = (_class4 = class _SynapClient {
4019
4068
  last_n_conversations: lastNConversations = 1,
4020
4069
  response_shape: responseShape = "by_type"
4021
4070
  } = options;
4071
+ await this.#transport.checkCustomerId(customerId, "sdk.fetch");
4022
4072
  validateConversationId(conversationId);
4023
4073
  responseShapeOf({ response_shape: responseShape });
4024
4074
  const wants = (scope) => scopes === void 0 || scopes.includes(scope);
@@ -4086,7 +4136,7 @@ var SynapClient = (_class4 = class _SynapClient {
4086
4136
  successful.push([label, result.value]);
4087
4137
  continue;
4088
4138
  }
4089
- if (result.reason instanceof _chunkT372OL3Qcjs.InvalidInputError) throw result.reason;
4139
+ if (result.reason instanceof _chunkUXNVTP4Dcjs.InvalidInputError) throw result.reason;
4090
4140
  this.#warn(`Scope '${label}' fetch failed in unified fetch (non-fatal): ${String(result.reason)}`);
4091
4141
  }
4092
4142
  const merged = mergeScopeResults(successful);
@@ -4165,7 +4215,7 @@ var SynapClient = (_class4 = class _SynapClient {
4165
4215
  if (!this.instance.is_listening) return;
4166
4216
  this.instance._internal.sendContextAssembled({
4167
4217
  ...buildAssembledEvent({
4168
- correlationId: _chunkT372OL3Qcjs.newCorrelationId.call(void 0, ),
4218
+ correlationId: _chunkUXNVTP4Dcjs.newCorrelationId.call(void 0, ),
4169
4219
  response,
4170
4220
  conversationId: _nullishCoalesce(options["conversation_id"], () => ( options["conversationId"])),
4171
4221
  userId: _nullishCoalesce(options["user_id"], () => ( options["userId"])),
@@ -4236,14 +4286,14 @@ var SynapClient = (_class4 = class _SynapClient {
4236
4286
  }))
4237
4287
  );
4238
4288
  const entry = this.#shortTerm.get(conversationId);
4239
- const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess', _70 => _70.serverMessageCount]), () => ( 0))) || 0);
4289
+ const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess', _72 => _72.serverMessageCount]), () => ( 0))) || 0);
4240
4290
  this.#maybeBackfillTurns(conversationId, total);
4241
4291
  if (!r["context_block"]) return response;
4242
4292
  const turns = store.turns(conversationId);
4243
4293
  let q = query;
4244
4294
  if (!q) {
4245
4295
  const latest = [...recent].reverse().find((m) => m["role"] === "user");
4246
- q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access', _71 => _71.reverse, 'call', _72 => _72(), 'access', _73 => _73.find, 'call', _74 => _74((t) => t.role === "user"), 'optionalAccess', _75 => _75.content]), () => ( ""));
4296
+ q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access', _73 => _73.reverse, 'call', _74 => _74(), 'access', _75 => _75.find, 'call', _76 => _76((t) => t.role === "user"), 'optionalAccess', _77 => _77.content]), () => ( ""));
4247
4297
  }
4248
4298
  if (!q) return response;
4249
4299
  const exclude = /* @__PURE__ */ new Set();
@@ -4387,13 +4437,13 @@ function pick3(o2, snake, camel) {
4387
4437
  function resolveBaseUrl(options) {
4388
4438
  const explicit = _nullishCoalesce(options.baseUrl, () => ( options.api_base_url));
4389
4439
  if (explicit !== void 0) return explicit;
4390
- const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _76 => _76.trim, 'call', _77 => _77()]);
4440
+ const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _78 => _78.trim, 'call', _79 => _79()]);
4391
4441
  return fromEnv !== void 0 && fromEnv !== "" ? fromEnv : void 0;
4392
4442
  }
4393
4443
  function resolveCredentials(options) {
4394
4444
  const apiKey = _nullishCoalesce(options.apiKey, () => ( _chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_API_KEY")));
4395
4445
  if (!apiKey) {
4396
- throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
4446
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
4397
4447
  "No Synap API key found. Set SYNAP_API_KEY in your environment, or pass apiKey to the SynapClient constructor."
4398
4448
  );
4399
4449
  }
@@ -4461,5 +4511,6 @@ function resolveCredentials(options) {
4461
4511
 
4462
4512
 
4463
4513
 
4464
- exports.ANY_SCOPE = _chunkICUFS3B5cjs.ANY_SCOPE; exports.AgentUnavailableError = _chunkT372OL3Qcjs.AgentUnavailableError; exports.AnticipationCache = _chunkICUFS3B5cjs.AnticipationCache; exports.AuthenticationError = _chunkT372OL3Qcjs.AuthenticationError; exports.BM25 = _chunkICUFS3B5cjs.BM25; exports.COMPACTION_LEVELS = COMPACTION_LEVELS; exports.CONTRACT = _chunkICUFS3B5cjs.CONTRACT; exports.ConflictError = _chunkT372OL3Qcjs.ConflictError; exports.ConnectionError = _chunkT372OL3Qcjs.ConnectionError; exports.ContextNotFoundError = _chunkT372OL3Qcjs.ContextNotFoundError; exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL; exports.DEFAULT_DOCUMENT_TYPE = DEFAULT_DOCUMENT_TYPE; exports.DEFAULT_INGEST_MODE = DEFAULT_INGEST_MODE; exports.DEFAULT_RETRY_POLICY = DEFAULT_RETRY_POLICY; exports.DEFAULT_TIMEOUTS = DEFAULT_TIMEOUTS; exports.DOCUMENT_TYPES = DOCUMENT_TYPES; exports.ENDPOINTS = ENDPOINTS; exports.EXCERPT_CATEGORY = EXCERPT_CATEGORY; exports.FORGET_MODES = FORGET_MODES; exports.HttpTransport = HttpTransport; exports.INGEST_MODES = INGEST_MODES; exports.ITEM_COLLECTIONS = ITEM_COLLECTIONS; exports.InsufficientCreditsError = _chunkT372OL3Qcjs.InsufficientCreditsError; exports.InvalidConversationIdError = _chunkT372OL3Qcjs.InvalidConversationIdError; exports.InvalidInputError = _chunkT372OL3Qcjs.InvalidInputError; exports.InvalidInstanceIdError = _chunkT372OL3Qcjs.InvalidInstanceIdError; exports.ListeningAlreadyActiveError = _chunkT372OL3Qcjs.ListeningAlreadyActiveError; exports.ListeningNotActiveError = _chunkT372OL3Qcjs.ListeningNotActiveError; exports.MEMORY_TYPES = MEMORY_TYPES; exports.NetworkTimeoutError = _chunkT372OL3Qcjs.NetworkTimeoutError; exports.PermanentError = _chunkT372OL3Qcjs.PermanentError; exports.RESPONSE_SHAPES = RESPONSE_SHAPES; exports.RateLimitError = _chunkT372OL3Qcjs.RateLimitError; exports.SDKError = _chunkT372OL3Qcjs.SDKError; exports.SDK_VERSION = SDK_VERSION; exports.ServiceUnavailableError = _chunkT372OL3Qcjs.ServiceUnavailableError; exports.SessionExpiredError = _chunkT372OL3Qcjs.SessionExpiredError; exports.SynapClient = SynapClient; exports.SynapError = _chunkT372OL3Qcjs.SynapError; exports.SynapPermanentError = _chunkT372OL3Qcjs.SynapPermanentError; exports.SynapTransientError = _chunkT372OL3Qcjs.SynapTransientError; exports.THRESHOLDS = _chunkICUFS3B5cjs.THRESHOLDS; exports.TranscriptConflictError = _chunkT372OL3Qcjs.TranscriptConflictError; exports.TransientError = _chunkT372OL3Qcjs.TransientError; exports.applyResponseShape = applyResponseShape; exports.flattenContextItems = flattenContextItems; exports.formatForPrompt = formatForPrompt; exports.isOutcomeUnknown = isOutcomeUnknown; exports.isRecallQuery = _chunkICUFS3B5cjs.isRecallQuery; exports.isSynapError = _chunkT372OL3Qcjs.isSynapError; exports.mergeScopeResults = mergeScopeResults; exports.rankItems = rankItems; exports.resolvePath = resolvePath; exports.shouldRetry = shouldRetry; exports.stem = _chunkICUFS3B5cjs.stem; exports.tokenize = _chunkICUFS3B5cjs.tokenize; exports.wireRankScore = wireRankScore;
4514
+
4515
+ exports.ANY_SCOPE = _chunkICUFS3B5cjs.ANY_SCOPE; exports.AgentUnavailableError = _chunkUXNVTP4Dcjs.AgentUnavailableError; exports.AnticipationCache = _chunkICUFS3B5cjs.AnticipationCache; exports.AuthenticationError = _chunkUXNVTP4Dcjs.AuthenticationError; exports.BM25 = _chunkICUFS3B5cjs.BM25; exports.COMPACTION_LEVELS = COMPACTION_LEVELS; exports.CONTRACT = _chunkICUFS3B5cjs.CONTRACT; exports.ConflictError = _chunkUXNVTP4Dcjs.ConflictError; exports.ConnectionError = _chunkUXNVTP4Dcjs.ConnectionError; exports.ContextNotFoundError = _chunkUXNVTP4Dcjs.ContextNotFoundError; exports.CustomerIdNotAcceptedError = _chunkUXNVTP4Dcjs.CustomerIdNotAcceptedError; exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL; exports.DEFAULT_DOCUMENT_TYPE = DEFAULT_DOCUMENT_TYPE; exports.DEFAULT_INGEST_MODE = DEFAULT_INGEST_MODE; exports.DEFAULT_RETRY_POLICY = DEFAULT_RETRY_POLICY; exports.DEFAULT_TIMEOUTS = DEFAULT_TIMEOUTS; exports.DOCUMENT_TYPES = DOCUMENT_TYPES; exports.ENDPOINTS = ENDPOINTS; exports.EXCERPT_CATEGORY = EXCERPT_CATEGORY; exports.FORGET_MODES = FORGET_MODES; exports.HttpTransport = HttpTransport; exports.INGEST_MODES = INGEST_MODES; exports.ITEM_COLLECTIONS = ITEM_COLLECTIONS; exports.InsufficientCreditsError = _chunkUXNVTP4Dcjs.InsufficientCreditsError; exports.InvalidConversationIdError = _chunkUXNVTP4Dcjs.InvalidConversationIdError; exports.InvalidInputError = _chunkUXNVTP4Dcjs.InvalidInputError; exports.InvalidInstanceIdError = _chunkUXNVTP4Dcjs.InvalidInstanceIdError; exports.ListeningAlreadyActiveError = _chunkUXNVTP4Dcjs.ListeningAlreadyActiveError; exports.ListeningNotActiveError = _chunkUXNVTP4Dcjs.ListeningNotActiveError; exports.MEMORY_TYPES = MEMORY_TYPES; exports.NetworkTimeoutError = _chunkUXNVTP4Dcjs.NetworkTimeoutError; exports.PermanentError = _chunkUXNVTP4Dcjs.PermanentError; exports.RESPONSE_SHAPES = RESPONSE_SHAPES; exports.RateLimitError = _chunkUXNVTP4Dcjs.RateLimitError; exports.SDKError = _chunkUXNVTP4Dcjs.SDKError; exports.SDK_VERSION = SDK_VERSION; exports.ServiceUnavailableError = _chunkUXNVTP4Dcjs.ServiceUnavailableError; exports.SessionExpiredError = _chunkUXNVTP4Dcjs.SessionExpiredError; exports.SynapClient = SynapClient; exports.SynapError = _chunkUXNVTP4Dcjs.SynapError; exports.SynapPermanentError = _chunkUXNVTP4Dcjs.SynapPermanentError; exports.SynapTransientError = _chunkUXNVTP4Dcjs.SynapTransientError; exports.THRESHOLDS = _chunkICUFS3B5cjs.THRESHOLDS; exports.TranscriptConflictError = _chunkUXNVTP4Dcjs.TranscriptConflictError; exports.TransientError = _chunkUXNVTP4Dcjs.TransientError; exports.applyResponseShape = applyResponseShape; exports.flattenContextItems = flattenContextItems; exports.formatForPrompt = formatForPrompt; exports.isOutcomeUnknown = isOutcomeUnknown; exports.isRecallQuery = _chunkICUFS3B5cjs.isRecallQuery; exports.isSynapError = _chunkUXNVTP4Dcjs.isSynapError; exports.mergeScopeResults = mergeScopeResults; exports.rankItems = rankItems; exports.resolvePath = resolvePath; exports.shouldRetry = shouldRetry; exports.stem = _chunkICUFS3B5cjs.stem; exports.tokenize = _chunkICUFS3B5cjs.tokenize; exports.wireRankScore = wireRankScore;
4465
4516
  //# sourceMappingURL=index.cjs.map