@maximem/synap-js-sdk 0.5.21 → 0.6.1

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.
package/dist/index.cjs CHANGED
@@ -40,7 +40,9 @@ var _chunkZKOJDUN4cjs = require('./chunk-ZKOJDUN4.cjs');
40
40
 
41
41
 
42
42
 
43
- var _chunkUXNVTP4Dcjs = require('./chunk-UXNVTP4D.cjs');
43
+
44
+
45
+ var _chunk7IZHVYO2cjs = require('./chunk-7IZHVYO2.cjs');
44
46
 
45
47
  // src/transport/endpoints.ts
46
48
  var ENDPOINTS = {
@@ -103,10 +105,10 @@ function shouldRetry(input) {
103
105
  if (attempt >= policy.maxAttempts) {
104
106
  return { retry: false, delaySeconds: 0, reason: "max_attempts_exhausted" };
105
107
  }
106
- if (!_chunkUXNVTP4Dcjs.isSynapError.call(void 0, error) || !error.transient) {
108
+ if (!_chunk7IZHVYO2cjs.isSynapError.call(void 0, error) || !error.transient) {
107
109
  return { retry: false, delaySeconds: 0, reason: "not_transient" };
108
110
  }
109
- if (error instanceof _chunkUXNVTP4Dcjs.RateLimitError && error.reason) {
111
+ if (error instanceof _chunk7IZHVYO2cjs.RateLimitError && error.reason) {
110
112
  return { retry: false, delaySeconds: 0, reason: "credit_stop" };
111
113
  }
112
114
  const idempotent = _nullishCoalesce(input.idempotent, () => ( IDEMPOTENT_METHODS.has(method.toUpperCase())));
@@ -124,7 +126,7 @@ function shouldRetry(input) {
124
126
  };
125
127
  }
126
128
  function backoffDelay(error, attempt, policy) {
127
- if (error instanceof _chunkUXNVTP4Dcjs.RateLimitError && error.retryAfterSeconds != null) {
129
+ if (error instanceof _chunk7IZHVYO2cjs.RateLimitError && error.retryAfterSeconds != null) {
128
130
  return Math.min(error.retryAfterSeconds, policy.backoffMax);
129
131
  }
130
132
  const exponential = policy.backoffBase * 2 ** (attempt - 1);
@@ -198,11 +200,41 @@ var B2C_ISOLATION = "equals_customer";
198
200
  function checkCustomerId(isolation, customerId, where, instanceId) {
199
201
  if (customerId === void 0 || customerId === null || customerId === "") return;
200
202
  if (isolation !== B2C_ISOLATION) return;
201
- throw new (0, _chunkUXNVTP4Dcjs.CustomerIdNotAcceptedError)(where, String(customerId), instanceId);
203
+ throw new (0, _chunk7IZHVYO2cjs.CustomerIdNotAcceptedError)(where, String(customerId), instanceId);
202
204
  }
203
205
 
204
206
  // src/transport/http.ts
205
207
  var DEFAULT_BASE_URL = "https://synap-cloud-prod.maximem.ai";
208
+ var GATED_POST_PATHS = [
209
+ "/v1/context/conversation/fetch",
210
+ // sdk_context.py
211
+ "/v1/context/user/fetch",
212
+ // sdk_context.py
213
+ "/v1/context/customer/fetch",
214
+ // sdk_context.py
215
+ "/v1/context/client/fetch",
216
+ // sdk_context.py
217
+ "/v1/conversations/messages",
218
+ // sdk_conversations.py (+ /messages/batch)
219
+ "/v1/conversations/ingest",
220
+ // sdk_conversations.py
221
+ "/v1/events/batch",
222
+ // sdk_events.py
223
+ "/api/v1/memories/create",
224
+ // sdk_memories.py
225
+ "/api/v1/memories/batch",
226
+ // sdk_memories.py
227
+ "/api/v1/memories/upload",
228
+ // sdk_memories.py
229
+ "/v1/migrations"
230
+ // migrations.py (create, /{id}/approve, /{id}/run)
231
+ ];
232
+ var COOLDOWN_MAX_SECONDS = 300;
233
+ function isGatedPath(method, path) {
234
+ if (method.toUpperCase() !== "POST") return false;
235
+ const bare = (_nullishCoalesce(path.split("?", 1)[0], () => ( ""))).replace(/\/+$/, "");
236
+ return GATED_POST_PATHS.some((p) => bare === p || bare.startsWith(p + "/"));
237
+ }
206
238
  var DEFAULT_TIMEOUTS = {
207
239
  connect: 5,
208
240
  read: 30,
@@ -221,7 +253,12 @@ var HttpTransport = (_class2 = class {
221
253
 
222
254
 
223
255
  __init2() {this.closed = false}
224
- constructor(options) {;_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);
256
+
257
+ // instance id -> when the refusal's wait ends (monotonic ms), and what was said.
258
+ // One JS thread runs every request, so a plain Map needs no lock.
259
+ __init3() {this.notReadyCooldown = /* @__PURE__ */ new Map()}
260
+ constructor(options) {;_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);
261
+ this.clock = _nullishCoalesce(options.clock, () => ( (() => performance.now())));
225
262
  this.#credentials = options.credentials;
226
263
  this.baseUrl = (_nullishCoalesce(options.baseUrl, () => ( DEFAULT_BASE_URL))).replace(/\/+$/, "");
227
264
  this.timeouts = { ...DEFAULT_TIMEOUTS, ...options.timeouts };
@@ -268,14 +305,14 @@ var HttpTransport = (_class2 = class {
268
305
  * undefined means the server did not report it, which is true of any
269
306
  * deployment older than the field, and must mean "enforce nothing".
270
307
  */
271
- __init3() {this.userContextIsolation = void 0}
308
+ __init4() {this.userContextIsolation = void 0}
272
309
  /**
273
310
  * Set by the client to its identity resolution (`initialize()`'s whoami).
274
311
  * Python refuses every call before `initialize()`; here the first request
275
312
  * runs it instead, so a caller who skips it gets the same identity-dependent
276
313
  * behaviour (client-scope cache hits, the B2C check) rather than an error.
277
314
  */
278
- __init4() {this.identityResolver = void 0}
315
+ __init5() {this.identityResolver = void 0}
279
316
  /** Resolve identity once, before the first request. Never throws. */
280
317
  async ready() {
281
318
  if (this.identityResolver !== void 0) await this.identityResolver();
@@ -312,18 +349,54 @@ var HttpTransport = (_class2 = class {
312
349
  this.closed = true;
313
350
  this.heartbeat.stop();
314
351
  }
352
+ /** Throw InstanceNotReadyError locally if this instance is cooling down. */
353
+ cooldownCheck(instanceId, correlationId) {
354
+ const entry = this.notReadyCooldown.get(instanceId);
355
+ if (entry === void 0) return;
356
+ const remainingMs = entry.until - this.clock();
357
+ if (remainingMs <= 0) {
358
+ this.notReadyCooldown.delete(instanceId);
359
+ return;
360
+ }
361
+ throw new (0, _chunk7IZHVYO2cjs.InstanceNotReadyError)(entry.message, {
362
+ correlationId,
363
+ retryAfterSeconds: Math.max(1, Math.ceil(remainingMs / 1e3)),
364
+ instanceId,
365
+ state: entry.state,
366
+ fromCooldown: true
367
+ });
368
+ }
369
+ /** Remember a server refusal. Never longer than the server's hint. */
370
+ cooldownStart(instanceId, error) {
371
+ const hint = error.retryAfterSeconds;
372
+ if (hint === null || !(hint > 0)) return;
373
+ const waitMs = Math.min(hint, COOLDOWN_MAX_SECONDS) * 1e3;
374
+ this.notReadyCooldown.set(instanceId, {
375
+ until: this.clock() + waitMs,
376
+ message: error.message,
377
+ state: error.state
378
+ });
379
+ }
315
380
  async request(name, options = {}) {
316
381
  const spec = ENDPOINTS[name];
317
- const correlationId = _nullishCoalesce(options.correlationId, () => ( _chunkUXNVTP4Dcjs.newCorrelationId.call(void 0, )));
382
+ const correlationId = _nullishCoalesce(options.correlationId, () => ( _chunk7IZHVYO2cjs.newCorrelationId.call(void 0, )));
318
383
  const idempotent = _nullishCoalesce(options.idempotent, () => ( spec.idempotent));
319
384
  if (name !== "whoami") await this.ready();
385
+ const gated = isGatedPath(spec.method, resolvePath(name, options.pathParams));
386
+ const cooldownKey = this.#credentials.instanceId;
387
+ if (gated) this.cooldownCheck(cooldownKey, correlationId);
320
388
  let attempt = 0;
321
389
  let last = null;
322
390
  while (attempt < this.retryPolicy.maxAttempts) {
323
391
  attempt += 1;
324
392
  try {
325
- return await this.attempt(name, options, correlationId);
393
+ const result = await this.attempt(name, options, correlationId);
394
+ if (gated) this.notReadyCooldown.delete(cooldownKey);
395
+ return result;
326
396
  } catch (error) {
397
+ if (gated && error instanceof _chunk7IZHVYO2cjs.InstanceNotReadyError && !error.fromCooldown) {
398
+ this.cooldownStart(cooldownKey, error);
399
+ }
327
400
  last = { error, outcomeUnknown: isOutcomeUnknown(error) };
328
401
  const decision = shouldRetry({
329
402
  error,
@@ -337,7 +410,7 @@ var HttpTransport = (_class2 = class {
337
410
  await sleep(decision.delaySeconds * 1e3, options.signal);
338
411
  }
339
412
  }
340
- throw _nullishCoalesce(_optionalChain([last, 'optionalAccess', _9 => _9.error]), () => ( new (0, _chunkUXNVTP4Dcjs.SynapError)("Request failed with no recorded error")));
413
+ throw _nullishCoalesce(_optionalChain([last, 'optionalAccess', _9 => _9.error]), () => ( new (0, _chunk7IZHVYO2cjs.SynapError)("Request failed with no recorded error")));
341
414
  }
342
415
  async attempt(name, options, correlationId) {
343
416
  const spec = ENDPOINTS[name];
@@ -370,7 +443,7 @@ var HttpTransport = (_class2 = class {
370
443
  try {
371
444
  return JSON.parse(text);
372
445
  } catch (e3) {
373
- throw new (0, _chunkUXNVTP4Dcjs.SynapError)(`Malformed JSON in response from ${url}`, { correlationId });
446
+ throw new (0, _chunk7IZHVYO2cjs.SynapError)(`Malformed JSON in response from ${url}`, { correlationId });
374
447
  }
375
448
  }
376
449
  buildUrl(path, query) {
@@ -404,15 +477,15 @@ var HttpTransport = (_class2 = class {
404
477
  }
405
478
  }, _class2);
406
479
  function isOutcomeUnknown(error) {
407
- if (error instanceof _chunkUXNVTP4Dcjs.RateLimitError) return false;
408
- if (error instanceof _chunkUXNVTP4Dcjs.ServiceUnavailableError) return false;
409
- if (error instanceof _chunkUXNVTP4Dcjs.AuthenticationError) return false;
410
- if (error instanceof _chunkUXNVTP4Dcjs.InvalidInputError) return false;
411
- if (error instanceof _chunkUXNVTP4Dcjs.ConflictError) return false;
412
- if (error instanceof _chunkUXNVTP4Dcjs.InsufficientCreditsError) return false;
413
- if (error instanceof _chunkUXNVTP4Dcjs.ContextNotFoundError) return false;
480
+ if (error instanceof _chunk7IZHVYO2cjs.RateLimitError) return false;
481
+ if (error instanceof _chunk7IZHVYO2cjs.ServiceUnavailableError) return false;
482
+ if (error instanceof _chunk7IZHVYO2cjs.AuthenticationError) return false;
483
+ if (error instanceof _chunk7IZHVYO2cjs.InvalidInputError) return false;
484
+ if (error instanceof _chunk7IZHVYO2cjs.ConflictError) return false;
485
+ if (error instanceof _chunk7IZHVYO2cjs.InsufficientCreditsError) return false;
486
+ if (error instanceof _chunk7IZHVYO2cjs.ContextNotFoundError) return false;
414
487
  if (isConnectionRefusal(error)) return false;
415
- if (error instanceof _chunkUXNVTP4Dcjs.NetworkTimeoutError) return true;
488
+ if (error instanceof _chunk7IZHVYO2cjs.NetworkTimeoutError) return true;
416
489
  return true;
417
490
  }
418
491
  var CONNECTION_REFUSAL_CODES = /* @__PURE__ */ new Set([
@@ -432,18 +505,18 @@ function isConnectionRefusal(error) {
432
505
  return false;
433
506
  }
434
507
  function toTransportError(error, correlationId) {
435
- if (error instanceof _chunkUXNVTP4Dcjs.SynapError) return error;
508
+ if (error instanceof _chunk7IZHVYO2cjs.SynapError) return error;
436
509
  const name = _optionalChain([error, 'optionalAccess', _10 => _10.name]);
437
510
  if (name === "AbortError" || name === "TimeoutError") {
438
- return new (0, _chunkUXNVTP4Dcjs.NetworkTimeoutError)("Request timed out", { correlationId, cause: error });
511
+ return new (0, _chunk7IZHVYO2cjs.NetworkTimeoutError)("Request timed out", { correlationId, cause: error });
439
512
  }
440
513
  if (isConnectionRefusal(error)) {
441
- return new (0, _chunkUXNVTP4Dcjs.NetworkTimeoutError)(
514
+ return new (0, _chunk7IZHVYO2cjs.NetworkTimeoutError)(
442
515
  `Connection failed: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _11 => _11.message]), () => ( String(error)))}`,
443
516
  { correlationId, cause: error }
444
517
  );
445
518
  }
446
- return new (0, _chunkUXNVTP4Dcjs.ServiceUnavailableError)(
519
+ return new (0, _chunk7IZHVYO2cjs.ServiceUnavailableError)(
447
520
  `Network request failed: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _12 => _12.message]), () => ( String(error)))}`,
448
521
  { correlationId, cause: error }
449
522
  );
@@ -473,15 +546,15 @@ async function toHttpError(response, correlationId) {
473
546
  switch (response.status) {
474
547
  case 400:
475
548
  case 422:
476
- return new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(message, opts);
549
+ return new (0, _chunk7IZHVYO2cjs.InvalidInputError)(message, opts);
477
550
  case 401:
478
551
  case 403:
479
- return new (0, _chunkUXNVTP4Dcjs.AuthenticationError)(message, opts);
552
+ return new (0, _chunk7IZHVYO2cjs.AuthenticationError)(message, opts);
480
553
  case 404:
481
- return new (0, _chunkUXNVTP4Dcjs.ContextNotFoundError)(message, opts);
554
+ return new (0, _chunk7IZHVYO2cjs.ContextNotFoundError)(message, opts);
482
555
  case 402: {
483
556
  const credit = creditPayload(parsed, detailObject);
484
- return new (0, _chunkUXNVTP4Dcjs.InsufficientCreditsError)(message, {
557
+ return new (0, _chunk7IZHVYO2cjs.InsufficientCreditsError)(message, {
485
558
  ...opts,
486
559
  balanceCredits: numberOrNull(credit["balance_credits"]),
487
560
  requiredCredits: _nullishCoalesce(numberOrNull(credit["minimum_required_credits"]), () => ( numberOrNull(credit["required_credits"]))),
@@ -492,15 +565,44 @@ async function toHttpError(response, correlationId) {
492
565
  });
493
566
  }
494
567
  case 409:
568
+ if (parsed["error"] === "instance_build_failed" || _optionalChain([detailObject, 'optionalAccess', _13 => _13["code"]]) === "instance_build_failed" || _optionalChain([detailObject, 'optionalAccess', _14 => _14["error"]]) === "instance_build_failed") {
569
+ const pick4 = (key) => _nullishCoalesce(parsed[key], () => ( _optionalChain([detailObject, 'optionalAccess', _15 => _15[key]])));
570
+ const msg = pick4("message");
571
+ const attempts = Number(pick4("attempts"));
572
+ return new (0, _chunk7IZHVYO2cjs.InstanceBuildFailedError)(
573
+ typeof msg === "string" && msg !== "" ? msg : "This instance's memory architecture build failed.",
574
+ {
575
+ ...opts,
576
+ instanceId: stringOrNull(pick4("instance_id")),
577
+ attempts: pick4("attempts") !== void 0 && pick4("attempts") !== null && Number.isFinite(attempts) ? Math.trunc(attempts) : null,
578
+ hint: stringOrNull(pick4("hint"))
579
+ }
580
+ );
581
+ }
582
+ if (parsed["error"] === "instance_not_ready" || _optionalChain([detailObject, 'optionalAccess', _16 => _16["code"]]) === "instance_not_ready" || _optionalChain([detailObject, 'optionalAccess', _17 => _17["error"]]) === "instance_not_ready") {
583
+ const pick4 = (key) => _nullishCoalesce(parsed[key], () => ( _optionalChain([detailObject, 'optionalAccess', _18 => _18[key]])));
584
+ const rawWait = _nullishCoalesce(pick4("retry_after_seconds"), () => ( response.headers.get("retry-after")));
585
+ const wait = rawWait !== null && rawWait !== void 0 && String(rawWait).trim() !== "" ? Number(rawWait) : NaN;
586
+ const msg = pick4("message");
587
+ return new (0, _chunk7IZHVYO2cjs.InstanceNotReadyError)(
588
+ typeof msg === "string" && msg !== "" ? msg : "This instance's memory architecture is still being built.",
589
+ {
590
+ ...opts,
591
+ retryAfterSeconds: Number.isFinite(wait) ? Math.trunc(wait) : null,
592
+ instanceId: stringOrNull(pick4("instance_id")),
593
+ state: _nullishCoalesce(stringOrNull(pick4("state")), () => ( "building"))
594
+ }
595
+ );
596
+ }
495
597
  if (detailObject !== null && detailObject["code"] === "transcript_conflict") {
496
- return new (0, _chunkUXNVTP4Dcjs.TranscriptConflictError)(message, opts);
598
+ return new (0, _chunk7IZHVYO2cjs.TranscriptConflictError)(message, opts);
497
599
  }
498
- return new (0, _chunkUXNVTP4Dcjs.ConflictError)(message, opts);
600
+ return new (0, _chunk7IZHVYO2cjs.ConflictError)(message, opts);
499
601
  case 429: {
500
602
  const header = response.headers.get("retry-after");
501
603
  const retryAfter = header !== null && header.trim() !== "" ? Number(header) : null;
502
604
  const credit = creditPayload(parsed, detailObject);
503
- return new (0, _chunkUXNVTP4Dcjs.RateLimitError)(message, {
605
+ return new (0, _chunk7IZHVYO2cjs.RateLimitError)(message, {
504
606
  ...opts,
505
607
  retryAfterSeconds: retryAfter !== null && Number.isFinite(retryAfter) ? retryAfter : null,
506
608
  reason: creditReason(credit),
@@ -509,13 +611,13 @@ async function toHttpError(response, correlationId) {
509
611
  });
510
612
  }
511
613
  case 503:
512
- return new (0, _chunkUXNVTP4Dcjs.ServiceUnavailableError)(message, opts);
614
+ return new (0, _chunk7IZHVYO2cjs.ServiceUnavailableError)(message, opts);
513
615
  case 504:
514
- return new (0, _chunkUXNVTP4Dcjs.AgentUnavailableError)(message, opts);
616
+ return new (0, _chunk7IZHVYO2cjs.AgentUnavailableError)(message, opts);
515
617
  default:
516
- if (response.status >= 500) return new (0, _chunkUXNVTP4Dcjs.ServiceUnavailableError)(message, opts);
517
- if (response.status >= 400) return new (0, _chunkUXNVTP4Dcjs.SynapPermanentError)(message, opts);
518
- return new (0, _chunkUXNVTP4Dcjs.SynapError)(message, opts);
618
+ if (response.status >= 500) return new (0, _chunk7IZHVYO2cjs.ServiceUnavailableError)(message, opts);
619
+ if (response.status >= 400) return new (0, _chunk7IZHVYO2cjs.SynapPermanentError)(message, opts);
620
+ return new (0, _chunk7IZHVYO2cjs.SynapError)(message, opts);
519
621
  }
520
622
  }
521
623
  function numberOrNull(v) {
@@ -526,11 +628,11 @@ function stringOrNull(v) {
526
628
  }
527
629
  function withTimeout(ms, external) {
528
630
  const controller = new AbortController();
529
- const onExternalAbort = () => controller.abort(_optionalChain([external, 'optionalAccess', _13 => _13.reason]));
631
+ const onExternalAbort = () => controller.abort(_optionalChain([external, 'optionalAccess', _19 => _19.reason]));
530
632
  const timer = setTimeout(() => {
531
- controller.abort(new (0, _chunkUXNVTP4Dcjs.NetworkTimeoutError)(`Timed out after ${ms}ms`));
633
+ controller.abort(new (0, _chunk7IZHVYO2cjs.NetworkTimeoutError)(`Timed out after ${ms}ms`));
532
634
  }, ms);
533
- _optionalChain([timer, 'access', _14 => _14.unref, 'optionalCall', _15 => _15()]);
635
+ _optionalChain([timer, 'access', _20 => _20.unref, 'optionalCall', _21 => _21()]);
534
636
  if (external) {
535
637
  if (external.aborted) onExternalAbort();
536
638
  else external.addEventListener("abort", onExternalAbort, { once: true });
@@ -539,7 +641,7 @@ function withTimeout(ms, external) {
539
641
  signal: controller.signal,
540
642
  dispose() {
541
643
  clearTimeout(timer);
542
- _optionalChain([external, 'optionalAccess', _16 => _16.removeEventListener, 'call', _17 => _17("abort", onExternalAbort)]);
644
+ _optionalChain([external, 'optionalAccess', _22 => _22.removeEventListener, 'call', _23 => _23("abort", onExternalAbort)]);
543
645
  }
544
646
  };
545
647
  }
@@ -547,14 +649,14 @@ function sleep(ms, signal) {
547
649
  if (ms <= 0) return Promise.resolve();
548
650
  return new Promise((resolve, reject) => {
549
651
  const timer = setTimeout(() => {
550
- _optionalChain([signal, 'optionalAccess', _18 => _18.removeEventListener, 'call', _19 => _19("abort", onAbort)]);
652
+ _optionalChain([signal, 'optionalAccess', _24 => _24.removeEventListener, 'call', _25 => _25("abort", onAbort)]);
551
653
  resolve();
552
654
  }, ms);
553
655
  function onAbort() {
554
656
  clearTimeout(timer);
555
- reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _20 => _20.reason]), () => ( new Error("Aborted"))));
657
+ reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _26 => _26.reason]), () => ( new Error("Aborted"))));
556
658
  }
557
- _optionalChain([signal, 'optionalAccess', _21 => _21.addEventListener, 'call', _22 => _22("abort", onAbort, { once: true })]);
659
+ _optionalChain([signal, 'optionalAccess', _27 => _27.addEventListener, 'call', _28 => _28("abort", onAbort, { once: true })]);
558
660
  });
559
661
  }
560
662
 
@@ -663,10 +765,10 @@ function buildFetchRequest(scope, options) {
663
765
  const { mode, precisionLevel } = retrievalOptionsOf(options);
664
766
  const { contextMode, lastN } = scopeOptionsOf(scope, options);
665
767
  if (searchQuery !== void 0 && !Array.isArray(searchQuery)) {
666
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("search_query must be an array when provided");
768
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("search_query must be an array when provided");
667
769
  }
668
770
  if (options.types !== void 0 && !Array.isArray(options.types)) {
669
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("types must be an array when provided");
771
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("types must be an array when provided");
670
772
  }
671
773
  const body = {
672
774
  conversation_id: _nullishCoalesce(conversationId, () => ( null)),
@@ -715,7 +817,7 @@ var VALID_CONTEXT_MODES = ["in-conversation", "conversation-summary"];
715
817
  function responseShapeOf(options) {
716
818
  const shape = _nullishCoalesce(opt(options, "response_shape", "responseShape"), () => ( "by_type"));
717
819
  if (!RESPONSE_SHAPES.includes(shape)) {
718
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
820
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
719
821
  `Invalid response_shape '${shape}'. Must be one of: ${RESPONSE_SHAPES.join(", ")}`
720
822
  );
721
823
  }
@@ -730,21 +832,21 @@ var REQUIRED_ID = {
730
832
  function scopeOptionsOf(scope, options) {
731
833
  const required = REQUIRED_ID[scope];
732
834
  if (required !== null && !opt(options, required[0], required[1])) {
733
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(`${required[0]} is required`);
835
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(`${required[0]} is required`);
734
836
  }
735
837
  const contextMode = _nullishCoalesce(opt(options, "context_mode", "contextMode"), () => ( "in-conversation"));
736
838
  const lastN = _nullishCoalesce(opt(options, "last_n_conversations", "lastNConversations"), () => ( 1));
737
839
  if (scope !== "user") return { contextMode, lastN };
738
840
  if (!VALID_CONTEXT_MODES.includes(contextMode)) {
739
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
841
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
740
842
  `Invalid context_mode '${contextMode}'. Must be one of: ${VALID_CONTEXT_MODES.join(", ")}`
741
843
  );
742
844
  }
743
845
  if (!Number.isInteger(lastN)) {
744
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("last_n_conversations must be an integer");
846
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("last_n_conversations must be an integer");
745
847
  }
746
848
  if (lastN < 0 || lastN > 20) {
747
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("last_n_conversations must be between 0 and 20");
849
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("last_n_conversations must be between 0 and 20");
748
850
  }
749
851
  return { contextMode, lastN };
750
852
  }
@@ -753,13 +855,13 @@ var VALID_PRECISION = ["high", "medium"];
753
855
  function retrievalOptionsOf(options) {
754
856
  const mode = _nullishCoalesce(options.mode, () => ( "fast"));
755
857
  if (!VALID_MODES.includes(mode)) {
756
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
858
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
757
859
  `Invalid mode '${mode}'. Must be one of: ${VALID_MODES.join(", ")}`
758
860
  );
759
861
  }
760
862
  const precisionLevel = _nullishCoalesce(opt(options, "precision_level", "precisionLevel"), () => ( "high"));
761
863
  if (!VALID_PRECISION.includes(precisionLevel)) {
762
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
864
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
763
865
  `Invalid precision_level '${precisionLevel}'. Must be one of: ${VALID_PRECISION.join(", ")}`
764
866
  );
765
867
  }
@@ -767,7 +869,7 @@ function retrievalOptionsOf(options) {
767
869
  }
768
870
  async function fetchContext(transport, scope, options = {}, hooks = {}) {
769
871
  const startedAt = Date.now();
770
- await _optionalChain([transport, 'access', _23 => _23.ready, 'optionalCall', _24 => _24()]);
872
+ await _optionalChain([transport, 'access', _29 => _29.ready, 'optionalCall', _30 => _30()]);
771
873
  await transport.checkCustomerId(
772
874
  opt(options, "customer_id", "customerId"),
773
875
  `${scope}.context.fetch`
@@ -777,20 +879,20 @@ async function fetchContext(transport, scope, options = {}, hooks = {}) {
777
879
  const { contextMode } = scopeOptionsOf(scope, options);
778
880
  const summaryMode = scope === "user" && contextMode === "conversation-summary";
779
881
  const finish = (response2) => {
780
- _optionalChain([hooks, 'access', _25 => _25.onResponse, 'optionalCall', _26 => _26(scope, options, response2)]);
882
+ _optionalChain([hooks, 'access', _31 => _31.onResponse, 'optionalCall', _32 => _32(scope, options, response2)]);
781
883
  return response2;
782
884
  };
783
885
  const conversationId = opt(options, "conversation_id", "conversationId");
784
- const skipServerSt = conversationId ? _optionalChain([hooks, 'access', _27 => _27.skipServerShortTerm, 'optionalCall', _28 => _28(conversationId)]) === true : false;
886
+ const skipServerSt = conversationId ? _optionalChain([hooks, 'access', _33 => _33.skipServerShortTerm, 'optionalCall', _34 => _34(conversationId)]) === true : false;
785
887
  const network = async () => {
786
888
  const { endpoint, body } = buildFetchRequest(
787
889
  scope,
788
890
  skipServerSt ? { ...options, include_conversation_context: false } : options
789
891
  );
790
892
  const result = await transport.request(endpoint, { body });
791
- return applyResponseShape(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _29 => _29["context"]]), () => ( {})), responseShape);
893
+ return applyResponseShape(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _35 => _35["context"]]), () => ( {})), responseShape);
792
894
  };
793
- const anticipated = summaryMode ? null : await _asyncNullishCoalesce(await _optionalChain([hooks, 'access', _30 => _30.beforeFetch, 'optionalCall', _31 => _31(scope, options)]), async () => ( null));
895
+ const anticipated = summaryMode ? null : await _asyncNullishCoalesce(await _optionalChain([hooks, 'access', _36 => _36.beforeFetch, 'optionalCall', _37 => _37(scope, options)]), async () => ( null));
794
896
  if (anticipated !== null && anticipated.borderline) {
795
897
  const pending = network();
796
898
  pending.catch(() => void 0);
@@ -801,17 +903,17 @@ async function fetchContext(transport, scope, options = {}, hooks = {}) {
801
903
  const won = await Promise.race([pending.then((r) => r, () => null), late]);
802
904
  if (timer !== void 0) clearTimeout(timer);
803
905
  if (won !== null) {
804
- _optionalChain([hooks, 'access', _32 => _32.onAssembled, 'optionalCall', _33 => _33(scope, options, won, startedAt)]);
906
+ _optionalChain([hooks, 'access', _38 => _38.onAssembled, 'optionalCall', _39 => _39(scope, options, won, startedAt)]);
805
907
  return finish(won);
806
908
  }
807
909
  }
808
910
  if (anticipated !== null) {
809
- _optionalChain([hooks, 'access', _34 => _34.onServedFromCache, 'optionalCall', _35 => _35(scope, options, anticipated)]);
810
- _optionalChain([hooks, 'access', _36 => _36.onAssembled, 'optionalCall', _37 => _37(scope, options, anticipated.response, startedAt)]);
911
+ _optionalChain([hooks, 'access', _40 => _40.onServedFromCache, 'optionalCall', _41 => _41(scope, options, anticipated)]);
912
+ _optionalChain([hooks, 'access', _42 => _42.onAssembled, 'optionalCall', _43 => _43(scope, options, anticipated.response, startedAt)]);
811
913
  return finish(applyResponseShape(anticipated.response, responseShape));
812
914
  }
813
915
  const response = await network();
814
- _optionalChain([hooks, 'access', _38 => _38.onAssembled, 'optionalCall', _39 => _39(scope, options, response, startedAt)]);
916
+ _optionalChain([hooks, 'access', _44 => _44.onAssembled, 'optionalCall', _45 => _45(scope, options, response, startedAt)]);
815
917
  return finish(response);
816
918
  }
817
919
 
@@ -1066,17 +1168,17 @@ function isoOrNull(v) {
1066
1168
  return v instanceof Date ? v.toISOString() : v;
1067
1169
  }
1068
1170
  function buildCreateBody(options) {
1069
- if (!options.document) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("document is required");
1171
+ if (!options.document) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("document is required");
1070
1172
  const o2 = options;
1071
1173
  const documentType = _nullishCoalesce(either(o2, "document_type", "documentType"), () => ( DEFAULT_DOCUMENT_TYPE));
1072
1174
  const mode = _nullishCoalesce(options.mode, () => ( DEFAULT_INGEST_MODE));
1073
1175
  if (!DOCUMENT_TYPES.includes(documentType)) {
1074
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1176
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1075
1177
  `Invalid document_type '${documentType}'. Expected one of: ${DOCUMENT_TYPES.join(", ")}`
1076
1178
  );
1077
1179
  }
1078
1180
  if (!INGEST_MODES.includes(mode)) {
1079
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1181
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1080
1182
  `Invalid mode '${mode}'. Expected one of: ${INGEST_MODES.join(", ")}`
1081
1183
  );
1082
1184
  }
@@ -1105,13 +1207,13 @@ function buildForgetBody(options) {
1105
1207
  if (typeof description !== "string" || // Code points, as Python's len() and the server count; `.length` counts
1106
1208
  // UTF-16 units, so 251 emoji (502 units) were refused here only.
1107
1209
  [...description].length < FORGET_DESCRIPTION_MIN || [...description].length > FORGET_DESCRIPTION_MAX) {
1108
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1210
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1109
1211
  `description must be between ${FORGET_DESCRIPTION_MIN} and ${FORGET_DESCRIPTION_MAX} characters`
1110
1212
  );
1111
1213
  }
1112
1214
  const mode = _nullishCoalesce(options.mode, () => ( "preview"));
1113
1215
  if (!FORGET_MODES.includes(mode)) {
1114
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1216
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1115
1217
  `Invalid mode '${mode}'. Expected one of: ${FORGET_MODES.join(", ")}`
1116
1218
  );
1117
1219
  }
@@ -1135,7 +1237,7 @@ function createMemoriesInterface(transport, onForgotten) {
1135
1237
  async batch_create(options) {
1136
1238
  const docs = options.documents;
1137
1239
  if (!Array.isArray(docs) || docs.length === 0) {
1138
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("documents must be a non-empty array");
1240
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("documents must be a non-empty array");
1139
1241
  }
1140
1242
  const failFast = _nullishCoalesce(_nullishCoalesce(options.fail_fast, () => ( options.failFast)), () => ( false));
1141
1243
  return transport.request("memories_batch", {
@@ -1147,17 +1249,17 @@ function createMemoriesInterface(transport, onForgotten) {
1147
1249
  const customerId = _nullishCoalesce(options.customer_id, () => ( options.customerId));
1148
1250
  const scope = options.scope;
1149
1251
  if (scope !== void 0 && scope !== null && (typeof scope !== "object" || Array.isArray(scope) || !Object.values(scope).every((v) => typeof v === "string"))) {
1150
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("scope must be a flat dict of level key to id, both strings.");
1252
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("scope must be a flat dict of level key to id, both strings.");
1151
1253
  }
1152
- if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
1254
+ if (!userId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("user_id is required");
1153
1255
  await transport.checkCustomerId(customerId, "memories.create_from_file");
1154
1256
  const filePath = _nullishCoalesce(options.file_path, () => ( options.filePath));
1155
1257
  const sources = [filePath, options.file, options.text].filter((v) => v !== void 0);
1156
1258
  if (sources.length === 0) {
1157
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("One of file_path, file, or text must be provided.");
1259
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("One of file_path, file, or text must be provided.");
1158
1260
  }
1159
1261
  if (sources.length > 1) {
1160
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1262
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1161
1263
  "Provide exactly one of file_path, file, or text, not several."
1162
1264
  );
1163
1265
  }
@@ -1193,13 +1295,13 @@ function createMemoriesInterface(transport, onForgotten) {
1193
1295
  });
1194
1296
  },
1195
1297
  async get(memoryId) {
1196
- if (!memoryId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("memory_id is required");
1298
+ if (!memoryId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("memory_id is required");
1197
1299
  return transport.request("memories_get", { pathParams: { memory_id: memoryId } });
1198
1300
  },
1199
1301
  async update(options) {
1200
1302
  const memoryId = _nullishCoalesce(options.memory_id, () => ( options.memoryId));
1201
- if (!memoryId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("memory_id is required");
1202
- if (!options.document) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("document is required");
1303
+ if (!memoryId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("memory_id is required");
1304
+ if (!options.document) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("document is required");
1203
1305
  const body = {
1204
1306
  document: options.document,
1205
1307
  merge_strategy: _nullishCoalesce(_nullishCoalesce(options.merge_strategy, () => ( options.mergeStrategy)), () => ( "smart-merge"))
@@ -1214,7 +1316,7 @@ function createMemoriesInterface(transport, onForgotten) {
1214
1316
  },
1215
1317
  async delete(memoryId) {
1216
1318
  if (!memoryId) {
1217
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1319
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1218
1320
  "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."
1219
1321
  );
1220
1322
  }
@@ -1225,7 +1327,7 @@ function createMemoriesInterface(transport, onForgotten) {
1225
1327
  await transport.checkCustomerId(_nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])), "memories.forget");
1226
1328
  const body = buildForgetBody(options);
1227
1329
  const result = await transport.request("memories_forget", { body });
1228
- const removed = !!_optionalChain([result, 'optionalAccess', _40 => _40.deleted_ids, 'optionalAccess', _41 => _41.length]) || _optionalChain([result, 'optionalAccess', _42 => _42.status]) === "deleted" || _optionalChain([result, 'optionalAccess', _43 => _43.status]) === "partial";
1330
+ const removed = !!_optionalChain([result, 'optionalAccess', _46 => _46.deleted_ids, 'optionalAccess', _47 => _47.length]) || _optionalChain([result, 'optionalAccess', _48 => _48.status]) === "deleted" || _optionalChain([result, 'optionalAccess', _49 => _49.status]) === "partial";
1229
1331
  if (removed && onForgotten) {
1230
1332
  try {
1231
1333
  onForgotten({
@@ -1238,13 +1340,13 @@ function createMemoriesInterface(transport, onForgotten) {
1238
1340
  return result;
1239
1341
  },
1240
1342
  async status(ingestionId) {
1241
- if (!ingestionId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("ingestion_id is required");
1343
+ if (!ingestionId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("ingestion_id is required");
1242
1344
  return transport.request("memories_status", {
1243
1345
  pathParams: { ingestion_id: ingestionId }
1244
1346
  });
1245
1347
  },
1246
1348
  async wait_for_completion(ingestionId, options = {}) {
1247
- if (!ingestionId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("ingestion_id is required");
1349
+ if (!ingestionId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("ingestion_id is required");
1248
1350
  const timeoutMs = (_nullishCoalesce(_nullishCoalesce(options.timeout_seconds, () => ( options.timeoutSeconds)), () => ( 300))) * 1e3;
1249
1351
  const pollMs = (_nullishCoalesce(_nullishCoalesce(options.poll_interval_seconds, () => ( options.pollIntervalSeconds)), () => ( 2))) * 1e3;
1250
1352
  const deadline = Date.now() + timeoutMs;
@@ -1265,14 +1367,14 @@ function sleep2(ms, signal) {
1265
1367
  if (ms <= 0) return Promise.resolve();
1266
1368
  return new Promise((resolve, reject) => {
1267
1369
  const timer = setTimeout(() => {
1268
- _optionalChain([signal, 'optionalAccess', _44 => _44.removeEventListener, 'call', _45 => _45("abort", onAbort)]);
1370
+ _optionalChain([signal, 'optionalAccess', _50 => _50.removeEventListener, 'call', _51 => _51("abort", onAbort)]);
1269
1371
  resolve();
1270
1372
  }, ms);
1271
1373
  function onAbort() {
1272
1374
  clearTimeout(timer);
1273
- reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _46 => _46.reason]), () => ( new Error("Aborted"))));
1375
+ reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _52 => _52.reason]), () => ( new Error("Aborted"))));
1274
1376
  }
1275
- _optionalChain([signal, 'optionalAccess', _47 => _47.addEventListener, 'call', _48 => _48("abort", onAbort, { once: true })]);
1377
+ _optionalChain([signal, 'optionalAccess', _53 => _53.addEventListener, 'call', _54 => _54("abort", onAbort, { once: true })]);
1276
1378
  });
1277
1379
  }
1278
1380
 
@@ -1282,13 +1384,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
1282
1384
  function validateConversationId(conversationId) {
1283
1385
  if (conversationId === void 0 || conversationId === null || conversationId === "") return;
1284
1386
  if (typeof conversationId !== "string" || !UUID_RE.test(conversationId)) {
1285
- throw new (0, _chunkUXNVTP4Dcjs.InvalidConversationIdError)(`Invalid conversation ID: ${String(conversationId)}`);
1387
+ throw new (0, _chunk7IZHVYO2cjs.InvalidConversationIdError)(`Invalid conversation ID: ${String(conversationId)}`);
1286
1388
  }
1287
1389
  }
1288
1390
  function validateInstanceId(instanceId) {
1289
1391
  if (instanceId === void 0 || instanceId === null || instanceId === "") return;
1290
1392
  if (typeof instanceId !== "string" || !INSTANCE_ID_RE.test(instanceId)) {
1291
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInstanceIdError)(`Invalid instance ID: ${String(instanceId)}`);
1393
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInstanceIdError)(`Invalid instance ID: ${String(instanceId)}`);
1292
1394
  }
1293
1395
  }
1294
1396
 
@@ -1338,16 +1440,16 @@ function buildRecordMessageBody(options) {
1338
1440
  const conversationId = either2(o2, "conversation_id", "conversationId");
1339
1441
  const userId = either2(o2, "user_id", "userId");
1340
1442
  const customerId = either2(o2, "customer_id", "customerId");
1341
- if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1443
+ if (!conversationId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("conversation_id is required");
1342
1444
  validateConversationId(conversationId);
1343
- if (!options.role) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("role is required");
1445
+ if (!options.role) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("role is required");
1344
1446
  if (!MESSAGE_ROLES.includes(options.role)) {
1345
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(`Invalid role '${options.role}'. Must be 'user' or 'assistant'.`);
1447
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(`Invalid role '${options.role}'. Must be 'user' or 'assistant'.`);
1346
1448
  }
1347
1449
  if (options.content === void 0 || options.content === null) {
1348
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("content is required");
1450
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("content is required");
1349
1451
  }
1350
- if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
1452
+ if (!userId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("user_id is required");
1351
1453
  const body = {
1352
1454
  conversation_id: conversationId,
1353
1455
  role: options.role,
@@ -1369,10 +1471,10 @@ function buildIngestTranscriptBody(options) {
1369
1471
  const o2 = options;
1370
1472
  const conversationId = either2(o2, "conversation_id", "conversationId");
1371
1473
  const userId = either2(o2, "user_id", "userId");
1372
- if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1373
- if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
1474
+ if (!conversationId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("conversation_id is required");
1475
+ if (!userId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("user_id is required");
1374
1476
  if (options.transcript === void 0 || options.transcript === null) {
1375
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("transcript is required");
1477
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("transcript is required");
1376
1478
  }
1377
1479
  const body = {
1378
1480
  conversation_id: conversationId,
@@ -1398,7 +1500,7 @@ function buildIngestTranscriptBody(options) {
1398
1500
  function buildCompactBody(options) {
1399
1501
  const o2 = options;
1400
1502
  const conversationId = either2(o2, "conversation_id", "conversationId");
1401
- if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1503
+ if (!conversationId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("conversation_id is required");
1402
1504
  validateConversationId(conversationId);
1403
1505
  const body = { conversation_id: conversationId, force: _nullishCoalesce(options.force, () => ( false)) };
1404
1506
  const strategy = _nullishCoalesce(options.strategy, () => ( either2(o2, "compaction_level", "compactionLevel")));
@@ -1452,7 +1554,7 @@ function storedBatchRows(bodies, result) {
1452
1554
  const r = _nullishCoalesce(result, () => ( {}));
1453
1555
  const results = Array.isArray(r["results"]) ? r["results"] : [];
1454
1556
  const errors = Array.isArray(r["errors"]) ? r["errors"] : [];
1455
- const failed = new Set(errors.map((e) => _optionalChain([e, 'optionalAccess', _49 => _49["index"]])));
1557
+ const failed = new Set(errors.map((e) => _optionalChain([e, 'optionalAccess', _55 => _55["index"]])));
1456
1558
  const stored = bodies.filter((_, index) => !failed.has(index));
1457
1559
  if (stored.length !== results.length) return [];
1458
1560
  const pairs = [];
@@ -1496,7 +1598,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1496
1598
  };
1497
1599
  const convId = (v) => {
1498
1600
  const id = typeof v === "string" ? v : _nullishCoalesce(v.conversation_id, () => ( v.conversationId));
1499
- if (!id) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1601
+ if (!id) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("conversation_id is required");
1500
1602
  validateConversationId(id);
1501
1603
  return id;
1502
1604
  };
@@ -1530,7 +1632,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1530
1632
  },
1531
1633
  async record_messages_batch(messages) {
1532
1634
  if (!Array.isArray(messages) || messages.length === 0) {
1533
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("messages must be a non-empty array");
1635
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("messages must be a non-empty array");
1534
1636
  }
1535
1637
  for (const m of messages) {
1536
1638
  const mo = m;
@@ -1571,7 +1673,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1571
1673
  const raw = await transport.request("conversations_ingest", { body });
1572
1674
  const result = {
1573
1675
  ...raw,
1574
- warnings: Array.isArray(_optionalChain([raw, 'optionalAccess', _50 => _50.warnings])) ? raw.warnings.map(String) : []
1676
+ warnings: Array.isArray(_optionalChain([raw, 'optionalAccess', _56 => _56.warnings])) ? raw.warnings.map(String) : []
1575
1677
  };
1576
1678
  onWrite({
1577
1679
  userId: body["user_id"],
@@ -1596,7 +1698,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1596
1698
  const id = convId(options);
1597
1699
  const style = _nullishCoalesce(options.style, () => ( "structured"));
1598
1700
  if (!PROMPT_STYLES.includes(style)) {
1599
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1701
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1600
1702
  `Invalid style '${style}'. Must be one of: ${PROMPT_STYLES.join(", ")}`
1601
1703
  );
1602
1704
  }
@@ -1615,8 +1717,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1615
1717
  pathParams: { conversation_id: id },
1616
1718
  query: { style }
1617
1719
  });
1618
- const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _51 => _51["context_for_prompt"]]), () => ( result)), () => ( {}));
1619
- _optionalChain([localShortTerm, 'access', _52 => _52.reseed, 'optionalCall', _53 => _53(id, response)]);
1720
+ const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _57 => _57["context_for_prompt"]]), () => ( result)), () => ( {}));
1721
+ _optionalChain([localShortTerm, 'access', _58 => _58.reseed, 'optionalCall', _59 => _59(id, response)]);
1620
1722
  return withHistory(response);
1621
1723
  },
1622
1724
  async compact(options) {
@@ -1656,8 +1758,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1656
1758
  * Returns an idempotent unsubscribe thunk, matching Python.
1657
1759
  */
1658
1760
  subscribe_to_compaction_updates(conversationId, callback) {
1659
- if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1660
- if (typeof callback !== "function") throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("callback is required");
1761
+ if (!conversationId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("conversation_id is required");
1762
+ if (typeof callback !== "function") throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("callback is required");
1661
1763
  return subscribers.add(conversationId, callback);
1662
1764
  },
1663
1765
  /** Remove subscribers for one conversation, or all of them. Returns the count removed. */
@@ -1673,7 +1775,7 @@ function createUserNamespace(transport, hooks = {}) {
1673
1775
  return {
1674
1776
  async get_profile(options) {
1675
1777
  const userId = typeof options === "string" ? options : _nullishCoalesce(options.user_id, () => ( options.userId));
1676
- if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
1778
+ if (!userId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("user_id is required");
1677
1779
  const customerId = typeof options === "string" ? void 0 : _nullishCoalesce(options.customer_id, () => ( options.customerId));
1678
1780
  return transport.request("user_profile", {
1679
1781
  pathParams: { user_id: userId },
@@ -1722,7 +1824,7 @@ function createCreditsNamespace(transport) {
1722
1824
  });
1723
1825
  },
1724
1826
  async redeem(code) {
1725
- if (!code) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("code is required");
1827
+ if (!code) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("code is required");
1726
1828
  return transport.request("credits_redeem", { body: { code } });
1727
1829
  }
1728
1830
  };
@@ -1733,11 +1835,11 @@ function createCacheNamespace(cache) {
1733
1835
  return {
1734
1836
  clear: () => cache.clear(),
1735
1837
  clear_user: (userId) => {
1736
- if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
1838
+ if (!userId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("user_id is required");
1737
1839
  cache.dropEntity(userId);
1738
1840
  },
1739
1841
  clear_customer: (customerId) => {
1740
- if (!customerId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("customer_id is required");
1842
+ if (!customerId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("customer_id is required");
1741
1843
  cache.dropEntity(customerId);
1742
1844
  },
1743
1845
  stats: () => ({ bundles: cache.size, items: cache.itemCount })
@@ -1810,8 +1912,8 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1810
1912
  let onConversationState = null;
1811
1913
  const internals = {
1812
1914
  onCompactionUpdate(conversationId, bundle) {
1813
- _optionalChain([applyCompaction, 'optionalCall', _54 => _54(bundle)]);
1814
- _optionalChain([dispatchCompaction, 'optionalCall', _55 => _55(conversationId, bundle)]);
1915
+ _optionalChain([applyCompaction, 'optionalCall', _60 => _60(bundle)]);
1916
+ _optionalChain([dispatchCompaction, 'optionalCall', _61 => _61(conversationId, bundle)]);
1815
1917
  },
1816
1918
  setCompactionApplier(apply) {
1817
1919
  applyCompaction = apply;
@@ -1823,10 +1925,10 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1823
1925
  onConversationState = handle;
1824
1926
  },
1825
1927
  sendContextUsed(event) {
1826
- _optionalChain([client, 'optionalAccess', _56 => _56.sendContextUsed, 'call', _57 => _57(event)]);
1928
+ _optionalChain([client, 'optionalAccess', _62 => _62.sendContextUsed, 'call', _63 => _63(event)]);
1827
1929
  },
1828
1930
  sendContextAssembled(event) {
1829
- _optionalChain([client, 'optionalAccess', _58 => _58.sendContextAssembled, 'call', _59 => _59(event)]);
1931
+ _optionalChain([client, 'optionalAccess', _64 => _64.sendContextAssembled, 'call', _65 => _65(event)]);
1830
1932
  },
1831
1933
  setCompactionDispatcher(dispatch) {
1832
1934
  dispatchCompaction = dispatch;
@@ -1838,7 +1940,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1838
1940
  function ensureSession(conversationId, userId, customerId) {
1839
1941
  if (!conversationId || !userId || client === null) return;
1840
1942
  if (openSessions.has(conversationId)) return;
1841
- const sessionId = _chunkUXNVTP4Dcjs.newCorrelationId.call(void 0, );
1943
+ const sessionId = _chunk7IZHVYO2cjs.newCorrelationId.call(void 0, );
1842
1944
  try {
1843
1945
  client.sendSessionControl({
1844
1946
  action: "start",
@@ -1854,13 +1956,13 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1854
1956
  const namespace = {
1855
1957
  async listen(options = {}) {
1856
1958
  if (client !== null) {
1857
- throw new (0, _chunkUXNVTP4Dcjs.ListeningAlreadyActiveError)("Listening is already active on this instance");
1959
+ throw new (0, _chunk7IZHVYO2cjs.ListeningAlreadyActiveError)("Listening is already active on this instance");
1858
1960
  }
1859
1961
  try {
1860
- _optionalChain([onListen, 'optionalCall', _60 => _60()]);
1962
+ _optionalChain([onListen, 'optionalCall', _66 => _66()]);
1861
1963
  } catch (e10) {
1862
1964
  }
1863
- const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-FKKCBVCB.cjs")));
1965
+ const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-SZIYGVVJ.cjs")));
1864
1966
  const onContext = _nullishCoalesce(options.on_context, () => ( options.onContext));
1865
1967
  const onDisconnect = _nullishCoalesce(options.on_disconnect, () => ( options.onDisconnect));
1866
1968
  const onReconnect = _nullishCoalesce(options.on_reconnect, () => ( options.onReconnect));
@@ -1875,17 +1977,17 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1875
1977
  internals.onCompactionUpdate(conversationId, bundle);
1876
1978
  },
1877
1979
  onConversationState: (conversationId, messageCount) => {
1878
- _optionalChain([onConversationState, 'optionalCall', _61 => _61(conversationId, messageCount)]);
1980
+ _optionalChain([onConversationState, 'optionalCall', _67 => _67(conversationId, messageCount)]);
1879
1981
  },
1880
1982
  onStateChange: (state) => {
1881
1983
  if (state !== "connected") openSessions.clear();
1882
1984
  if (state === "reconnecting") {
1883
1985
  reconnectAttempts += 1;
1884
- _optionalChain([onReconnect, 'optionalCall', _62 => _62(reconnectAttempts)]);
1986
+ _optionalChain([onReconnect, 'optionalCall', _68 => _68(reconnectAttempts)]);
1885
1987
  } else if (state === "disconnected") {
1886
- const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _63 => _63.lastError]), () => ( null));
1988
+ const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _69 => _69.lastError]), () => ( null));
1887
1989
  const reason = stopped === null ? "stream disconnected" : `credit_stop:${_nullishCoalesce(stopped.reason, () => ( "unknown"))}`;
1888
- _optionalChain([onDisconnect, 'optionalCall', _64 => _64(reason)]);
1990
+ _optionalChain([onDisconnect, 'optionalCall', _70 => _70(reason)]);
1889
1991
  }
1890
1992
  }
1891
1993
  });
@@ -1893,9 +1995,9 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1893
1995
  try {
1894
1996
  await created.connect();
1895
1997
  } catch (error) {
1896
- if (error instanceof _chunkUXNVTP4Dcjs.SynapError) throw error;
1897
- throw new (0, _chunkUXNVTP4Dcjs.SynapError)(
1898
- `Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _65 => _65.message]), () => ( String(error)))}`,
1998
+ if (error instanceof _chunk7IZHVYO2cjs.SynapError) throw error;
1999
+ throw new (0, _chunk7IZHVYO2cjs.SynapError)(
2000
+ `Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _71 => _71.message]), () => ( String(error)))}`,
1899
2001
  { cause: error }
1900
2002
  );
1901
2003
  }
@@ -1928,15 +2030,15 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1928
2030
  _nullishCoalesce(options.customer_id, () => ( options.customerId)),
1929
2031
  "instance.send_message"
1930
2032
  );
1931
- if (client === null) throw new (0, _chunkUXNVTP4Dcjs.ListeningNotActiveError)("Listening is not active");
2033
+ if (client === null) throw new (0, _chunk7IZHVYO2cjs.ListeningNotActiveError)("Listening is not active");
1932
2034
  const eventType = _nullishCoalesce(_nullishCoalesce(options.event_type, () => ( options.eventType)), () => ( "user_message"));
1933
2035
  if (!KNOWN_EVENT_TYPES.has(eventType)) {
1934
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
2036
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1935
2037
  `unknown event_type '${eventType}'. Expected one of: ` + [...KNOWN_EVENT_TYPES].sort().join(", ")
1936
2038
  );
1937
2039
  }
1938
2040
  if (options.content === void 0 || options.content === null) {
1939
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("content is required");
2041
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("content is required");
1940
2042
  }
1941
2043
  const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
1942
2044
  ensureSession(
@@ -1945,7 +2047,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1945
2047
  _nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( ""))
1946
2048
  );
1947
2049
  if (eventType === "user_message" || eventType === "assistant_message") {
1948
- _optionalChain([onTurn, 'optionalCall', _66 => _66({
2050
+ _optionalChain([onTurn, 'optionalCall', _72 => _72({
1949
2051
  conversationId,
1950
2052
  role: _nullishCoalesce(options.role, () => ( "user")),
1951
2053
  content: options.content
@@ -1997,7 +2099,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1997
2099
  async record_tool_result(options) {
1998
2100
  const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
1999
2101
  if (conversationId) {
2000
- _optionalChain([onToolResult, 'optionalCall', _67 => _67({ conversationId, result: options.result, toolName: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")) })]);
2102
+ _optionalChain([onToolResult, 'optionalCall', _73 => _73({ conversationId, result: options.result, toolName: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")) })]);
2001
2103
  }
2002
2104
  await namespace.send_message({
2003
2105
  content: "",
@@ -2014,7 +2116,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
2014
2116
  });
2015
2117
  },
2016
2118
  async record_thinking(options) {
2017
- if (client === null) throw new (0, _chunkUXNVTP4Dcjs.ListeningNotActiveError)("Listening is not active");
2119
+ if (client === null) throw new (0, _chunk7IZHVYO2cjs.ListeningNotActiveError)("Listening is not active");
2018
2120
  const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
2019
2121
  ensureSession(
2020
2122
  conversationId,
@@ -2049,7 +2151,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
2049
2151
  }
2050
2152
 
2051
2153
  // src/version.ts
2052
- var SDK_VERSION = "0.5.21";
2154
+ var SDK_VERSION = "0.6.1";
2053
2155
 
2054
2156
  // src/registry.ts
2055
2157
  var instances = /* @__PURE__ */ new Map();
@@ -2396,13 +2498,13 @@ function bytesOf(text) {
2396
2498
  }
2397
2499
  var TurnStore = (_class3 = class {
2398
2500
 
2399
- __init5() {this.onDisk = false}
2501
+ __init6() {this.onDisk = false}
2400
2502
  #now;
2401
2503
  #seq = 0;
2402
2504
  #writes = 0;
2403
2505
  #conversations = /* @__PURE__ */ new Map();
2404
2506
  #vectors = /* @__PURE__ */ new Map();
2405
- constructor(options = {}) {;_class3.prototype.__init5.call(this);
2507
+ constructor(options = {}) {;_class3.prototype.__init6.call(this);
2406
2508
  this.limits = _nullishCoalesce(options.limits, () => ( { ..._chunkICUFS3B5cjs.HISTORY_SEARCH.store_limits }));
2407
2509
  this.#now = _nullishCoalesce(options.now, () => ( (() => Date.now() / 1e3)));
2408
2510
  }
@@ -2517,7 +2619,7 @@ var TurnStore = (_class3 = class {
2517
2619
  }
2518
2620
  /** Turns the server also holds: archived tool results are local only. Python: `count`. */
2519
2621
  count(conversationId) {
2520
- return (_nullishCoalesce(_optionalChain([this, 'access', _68 => _68.#conversations, 'access', _69 => _69.get, 'call', _70 => _70(conversationId), 'optionalAccess', _71 => _71.turns]), () => ( []))).filter((t) => t.role !== "tool").length;
2622
+ return (_nullishCoalesce(_optionalChain([this, 'access', _74 => _74.#conversations, 'access', _75 => _75.get, 'call', _76 => _76(conversationId), 'optionalAccess', _77 => _77.turns]), () => ( []))).filter((t) => t.role !== "tool").length;
2521
2623
  }
2522
2624
  sizeBytes() {
2523
2625
  let n2 = 0;
@@ -2696,7 +2798,7 @@ function askedKinds(query) {
2696
2798
  }
2697
2799
  function asksHowItStarted(query) {
2698
2800
  const spec = _chunkICUFS3B5cjs.HISTORY_SEARCH.early_query;
2699
- if (!_optionalChain([spec, 'optionalAccess', _72 => _72.pattern])) return false;
2801
+ if (!_optionalChain([spec, 'optionalAccess', _78 => _78.pattern])) return false;
2700
2802
  return new RegExp(spec.pattern, (_nullishCoalesce(spec.flags, () => ( ""))).includes("i") ? "i" : "").test(_nullishCoalesce(query, () => ( "")));
2701
2803
  }
2702
2804
  async function searchTurns(turns, query, options = {}) {
@@ -3712,7 +3814,7 @@ function buildTool(target, options = {}, onWarning = () => {
3712
3814
  const scope = String(_nullishCoalesce(options.scope, () => ( "user"))).toLowerCase();
3713
3815
  if (!VALID_SCOPES.includes(scope)) {
3714
3816
  const sorted = [...VALID_SCOPES].sort();
3715
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
3817
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
3716
3818
  `scope must be one of ['${sorted.join("', '")}'], got '${String(options.scope)}'`
3717
3819
  );
3718
3820
  }
@@ -3720,10 +3822,10 @@ function buildTool(target, options = {}, onWarning = () => {
3720
3822
  const customerId = _nullishCoalesce(options.customer_id, () => ( options.customerId));
3721
3823
  const conversationId = _nullishCoalesce(options.conversation_id, () => ( options.conversationId));
3722
3824
  if (scope === "user" && (userId === void 0 || userId === "")) {
3723
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("scope='user' requires user_id");
3825
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("scope='user' requires user_id");
3724
3826
  }
3725
3827
  if (scope === "customer" && (customerId === void 0 || customerId === "")) {
3726
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("scope='customer' requires customer_id");
3828
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("scope='customer' requires customer_id");
3727
3829
  }
3728
3830
  if (scope === "conversation" && (userId === void 0 || userId === "")) {
3729
3831
  onWarning(
@@ -3732,7 +3834,7 @@ function buildTool(target, options = {}, onWarning = () => {
3732
3834
  }
3733
3835
  const style = String(_nullishCoalesce(options.style, () => ( "openai")));
3734
3836
  if (style !== "openai" && style !== "anthropic") {
3735
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(`style must be 'openai' or 'anthropic', got '${style}'`);
3837
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(`style must be 'openai' or 'anthropic', got '${style}'`);
3736
3838
  }
3737
3839
  const toolName = _nullishCoalesce(options.name, () => ( `synap_fetch_${scope}_context`));
3738
3840
  const toolDesc = _nullishCoalesce(options.description, () => ( defaultToolDescription(scope)));
@@ -3909,7 +4011,7 @@ var SynapClient = (_class4 = class _SynapClient {
3909
4011
  this.#localEncoder = _nullishCoalesce(_nullishCoalesce(options.history_search_encoder, () => ( options.historySearchEncoder)), () => ( null));
3910
4012
  const modelOption = options.history_search_model !== void 0 ? options.history_search_model : options.historySearchModel;
3911
4013
  this.#localModelName = modelOption === void 0 ? "auto" : modelOption;
3912
- if (_optionalChain([this, 'access', _73 => _73.#localEncoder, 'optionalAccess', _74 => _74.model]) === _chunkICUFS3B5cjs.SEMANTIC_MATCH.model) this.#anticipationCache.setEncoder(this.#localEncoder);
4014
+ if (_optionalChain([this, 'access', _79 => _79.#localEncoder, 'optionalAccess', _80 => _80.model]) === _chunkICUFS3B5cjs.SEMANTIC_MATCH.model) this.#anticipationCache.setEncoder(this.#localEncoder);
3913
4015
  this.#turns = new TurnCounter();
3914
4016
  this.conversation = createConversationNamespace(
3915
4017
  this.#transport,
@@ -4009,9 +4111,9 @@ var SynapClient = (_class4 = class _SynapClient {
4009
4111
  */
4010
4112
  async searchMemory(options) {
4011
4113
  const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
4012
- if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
4114
+ if (!userId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("user_id is required");
4013
4115
  if (options.query === void 0 || options.query === null) {
4014
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("query is required");
4116
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("query is required");
4015
4117
  }
4016
4118
  const context = await fetchContext(this.#transport, "user", {
4017
4119
  user_id: userId,
@@ -4032,7 +4134,7 @@ var SynapClient = (_class4 = class _SynapClient {
4032
4134
  */
4033
4135
  async getMemories(options) {
4034
4136
  const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
4035
- if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
4137
+ if (!userId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("user_id is required");
4036
4138
  const context = await fetchContext(this.#transport, "user", {
4037
4139
  user_id: userId,
4038
4140
  ...pick3(options, "customer_id", "customerId") !== void 0 ? { customer_id: pick3(options, "customer_id", "customerId") } : {},
@@ -4137,7 +4239,7 @@ var SynapClient = (_class4 = class _SynapClient {
4137
4239
  */
4138
4240
  configure(options = {}) {
4139
4241
  if (this.#initialized) {
4140
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("Cannot reconfigure after initialization");
4242
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("Cannot reconfigure after initialization");
4141
4243
  }
4142
4244
  if (options.timeouts !== void 0) this.#transport.setTimeouts(options.timeouts);
4143
4245
  if (options.retryPolicy !== void 0 || options.retry_policy !== void 0) {
@@ -4258,7 +4360,7 @@ var SynapClient = (_class4 = class _SynapClient {
4258
4360
  successful.push([label, result.value]);
4259
4361
  continue;
4260
4362
  }
4261
- if (result.reason instanceof _chunkUXNVTP4Dcjs.InvalidInputError) throw result.reason;
4363
+ if (result.reason instanceof _chunk7IZHVYO2cjs.InvalidInputError) throw result.reason;
4262
4364
  this.#warn(`Scope '${label}' fetch failed in unified fetch (non-fatal): ${String(result.reason)}`);
4263
4365
  }
4264
4366
  const merged = mergeScopeResults(successful);
@@ -4337,7 +4439,7 @@ var SynapClient = (_class4 = class _SynapClient {
4337
4439
  if (!this.instance.is_listening) return;
4338
4440
  this.instance._internal.sendContextAssembled({
4339
4441
  ...buildAssembledEvent({
4340
- correlationId: _chunkUXNVTP4Dcjs.newCorrelationId.call(void 0, ),
4442
+ correlationId: _chunk7IZHVYO2cjs.newCorrelationId.call(void 0, ),
4341
4443
  response,
4342
4444
  conversationId: _nullishCoalesce(options["conversation_id"], () => ( options["conversationId"])),
4343
4445
  userId: _nullishCoalesce(options["user_id"], () => ( options["userId"])),
@@ -4408,14 +4510,14 @@ var SynapClient = (_class4 = class _SynapClient {
4408
4510
  }))
4409
4511
  );
4410
4512
  const entry = this.#shortTerm.get(conversationId);
4411
- const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess', _75 => _75.serverMessageCount]), () => ( 0))) || 0);
4513
+ const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess', _81 => _81.serverMessageCount]), () => ( 0))) || 0);
4412
4514
  this.#maybeBackfillTurns(conversationId, total);
4413
4515
  if (!r["context_block"]) return response;
4414
4516
  const turns = store.turns(conversationId);
4415
4517
  let q = query;
4416
4518
  if (!q) {
4417
4519
  const latest = [...recent].reverse().find((m) => m["role"] === "user");
4418
- q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access', _76 => _76.reverse, 'call', _77 => _77(), 'access', _78 => _78.find, 'call', _79 => _79((t) => t.role === "user"), 'optionalAccess', _80 => _80.content]), () => ( ""));
4520
+ q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access', _82 => _82.reverse, 'call', _83 => _83(), 'access', _84 => _84.find, 'call', _85 => _85((t) => t.role === "user"), 'optionalAccess', _86 => _86.content]), () => ( ""));
4419
4521
  }
4420
4522
  if (!q) return response;
4421
4523
  const exclude = /* @__PURE__ */ new Set();
@@ -4559,13 +4661,13 @@ function pick3(o2, snake, camel) {
4559
4661
  function resolveBaseUrl(options) {
4560
4662
  const explicit = _nullishCoalesce(options.baseUrl, () => ( options.api_base_url));
4561
4663
  if (explicit !== void 0) return explicit;
4562
- const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _81 => _81.trim, 'call', _82 => _82()]);
4664
+ const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _87 => _87.trim, 'call', _88 => _88()]);
4563
4665
  return fromEnv !== void 0 && fromEnv !== "" ? fromEnv : void 0;
4564
4666
  }
4565
4667
  function resolveCredentials(options) {
4566
4668
  const apiKey = _nullishCoalesce(options.apiKey, () => ( _chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_API_KEY")));
4567
4669
  if (!apiKey) {
4568
- throw new (0, _chunkUXNVTP4Dcjs.AuthenticationError)(
4670
+ throw new (0, _chunk7IZHVYO2cjs.AuthenticationError)(
4569
4671
  "No Synap API key found. Set SYNAP_API_KEY in your environment, or pass apiKey to the SynapClient constructor."
4570
4672
  );
4571
4673
  }
@@ -4634,5 +4736,7 @@ function resolveCredentials(options) {
4634
4736
 
4635
4737
 
4636
4738
 
4637
- 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;
4739
+
4740
+
4741
+ exports.ANY_SCOPE = _chunkICUFS3B5cjs.ANY_SCOPE; exports.AgentUnavailableError = _chunk7IZHVYO2cjs.AgentUnavailableError; exports.AnticipationCache = _chunkICUFS3B5cjs.AnticipationCache; exports.AuthenticationError = _chunk7IZHVYO2cjs.AuthenticationError; exports.BM25 = _chunkICUFS3B5cjs.BM25; exports.COMPACTION_LEVELS = COMPACTION_LEVELS; exports.CONTRACT = _chunkICUFS3B5cjs.CONTRACT; exports.ConflictError = _chunk7IZHVYO2cjs.ConflictError; exports.ConnectionError = _chunk7IZHVYO2cjs.ConnectionError; exports.ContextNotFoundError = _chunk7IZHVYO2cjs.ContextNotFoundError; exports.CustomerIdNotAcceptedError = _chunk7IZHVYO2cjs.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.InstanceBuildFailedError = _chunk7IZHVYO2cjs.InstanceBuildFailedError; exports.InstanceNotReadyError = _chunk7IZHVYO2cjs.InstanceNotReadyError; exports.InsufficientCreditsError = _chunk7IZHVYO2cjs.InsufficientCreditsError; exports.InvalidConversationIdError = _chunk7IZHVYO2cjs.InvalidConversationIdError; exports.InvalidInputError = _chunk7IZHVYO2cjs.InvalidInputError; exports.InvalidInstanceIdError = _chunk7IZHVYO2cjs.InvalidInstanceIdError; exports.ListeningAlreadyActiveError = _chunk7IZHVYO2cjs.ListeningAlreadyActiveError; exports.ListeningNotActiveError = _chunk7IZHVYO2cjs.ListeningNotActiveError; exports.MEMORY_TYPES = MEMORY_TYPES; exports.NetworkTimeoutError = _chunk7IZHVYO2cjs.NetworkTimeoutError; exports.PermanentError = _chunk7IZHVYO2cjs.PermanentError; exports.RESPONSE_SHAPES = RESPONSE_SHAPES; exports.RateLimitError = _chunk7IZHVYO2cjs.RateLimitError; exports.SDKError = _chunk7IZHVYO2cjs.SDKError; exports.SDK_VERSION = SDK_VERSION; exports.ServiceUnavailableError = _chunk7IZHVYO2cjs.ServiceUnavailableError; exports.SessionExpiredError = _chunk7IZHVYO2cjs.SessionExpiredError; exports.SynapClient = SynapClient; exports.SynapError = _chunk7IZHVYO2cjs.SynapError; exports.SynapPermanentError = _chunk7IZHVYO2cjs.SynapPermanentError; exports.SynapTransientError = _chunk7IZHVYO2cjs.SynapTransientError; exports.THRESHOLDS = _chunkICUFS3B5cjs.THRESHOLDS; exports.TranscriptConflictError = _chunk7IZHVYO2cjs.TranscriptConflictError; exports.TransientError = _chunk7IZHVYO2cjs.TransientError; exports.applyResponseShape = applyResponseShape; exports.flattenContextItems = flattenContextItems; exports.formatForPrompt = formatForPrompt; exports.isOutcomeUnknown = isOutcomeUnknown; exports.isRecallQuery = _chunkICUFS3B5cjs.isRecallQuery; exports.isSynapError = _chunk7IZHVYO2cjs.isSynapError; exports.mergeScopeResults = mergeScopeResults; exports.rankItems = rankItems; exports.resolvePath = resolvePath; exports.shouldRetry = shouldRetry; exports.stem = _chunkICUFS3B5cjs.stem; exports.tokenize = _chunkICUFS3B5cjs.tokenize; exports.wireRankScore = wireRankScore;
4638
4742
  //# sourceMappingURL=index.cjs.map