@maximem/synap-js-sdk 0.5.20 → 0.6.0

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 (38) hide show
  1. package/dist/anticipation-cache-LPNKMRBH.cjs.map +1 -1
  2. package/dist/{chunk-CBK3H2LU.cjs → chunk-2VJV4HCF.cjs} +216 -23
  3. package/dist/chunk-2VJV4HCF.cjs.map +1 -0
  4. package/dist/{chunk-UXNVTP4D.cjs → chunk-7IZHVYO2.cjs} +50 -9
  5. package/dist/chunk-7IZHVYO2.cjs.map +1 -0
  6. package/dist/{chunk-4GE7SORD.js → chunk-DEFC7NHQ.js} +42 -1
  7. package/dist/chunk-DEFC7NHQ.js.map +1 -0
  8. package/dist/chunk-ICUFS3B5.cjs.map +1 -1
  9. package/dist/{chunk-5G3FNDB3.js → chunk-N55UBGER.js} +197 -4
  10. package/dist/chunk-N55UBGER.js.map +1 -0
  11. package/dist/chunk-ZKOJDUN4.cjs.map +1 -1
  12. package/dist/env-55ULHNJZ.cjs.map +1 -1
  13. package/dist/{errors-BvUA5EW8.d.ts → errors-DWjdpExq.d.cts} +60 -2
  14. package/dist/{errors-BvUA5EW8.d.cts → errors-DWjdpExq.d.ts} +60 -2
  15. package/dist/grpc/index.cjs +7 -7
  16. package/dist/grpc/index.cjs.map +1 -1
  17. package/dist/grpc/index.d.cts +22 -1
  18. package/dist/grpc/index.d.ts +22 -1
  19. package/dist/grpc/index.js +3 -3
  20. package/dist/index.cjs +256 -147
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +11 -3
  23. package/dist/index.d.ts +11 -3
  24. package/dist/index.js +114 -5
  25. package/dist/index.js.map +1 -1
  26. package/dist/onnx-encoder-4RSL6ID4.cjs.map +1 -1
  27. package/dist/stream-client-GRDVRBFA.js +22 -0
  28. package/dist/stream-client-SZIYGVVJ.cjs +22 -0
  29. package/dist/stream-client-SZIYGVVJ.cjs.map +1 -0
  30. package/package.json +1 -1
  31. package/dist/chunk-4GE7SORD.js.map +0 -1
  32. package/dist/chunk-5G3FNDB3.js.map +0 -1
  33. package/dist/chunk-CBK3H2LU.cjs.map +0 -1
  34. package/dist/chunk-UXNVTP4D.cjs.map +0 -1
  35. package/dist/stream-client-2UMDGCMQ.js +0 -16
  36. package/dist/stream-client-FKKCBVCB.cjs +0 -16
  37. package/dist/stream-client-FKKCBVCB.cjs.map +0 -1
  38. /package/dist/{stream-client-2UMDGCMQ.js.map → stream-client-GRDVRBFA.js.map} +0 -0
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,9 +105,12 @@ 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
  }
111
+ if (error instanceof _chunk7IZHVYO2cjs.RateLimitError && error.reason) {
112
+ return { retry: false, delaySeconds: 0, reason: "credit_stop" };
113
+ }
109
114
  const idempotent = _nullishCoalesce(input.idempotent, () => ( IDEMPOTENT_METHODS.has(method.toUpperCase())));
110
115
  if (outcomeUnknown && !idempotent) {
111
116
  return {
@@ -121,7 +126,7 @@ function shouldRetry(input) {
121
126
  };
122
127
  }
123
128
  function backoffDelay(error, attempt, policy) {
124
- if (error instanceof _chunkUXNVTP4Dcjs.RateLimitError && error.retryAfterSeconds != null) {
129
+ if (error instanceof _chunk7IZHVYO2cjs.RateLimitError && error.retryAfterSeconds != null) {
125
130
  return Math.min(error.retryAfterSeconds, policy.backoffMax);
126
131
  }
127
132
  const exponential = policy.backoffBase * 2 ** (attempt - 1);
@@ -195,11 +200,41 @@ var B2C_ISOLATION = "equals_customer";
195
200
  function checkCustomerId(isolation, customerId, where, instanceId) {
196
201
  if (customerId === void 0 || customerId === null || customerId === "") return;
197
202
  if (isolation !== B2C_ISOLATION) return;
198
- throw new (0, _chunkUXNVTP4Dcjs.CustomerIdNotAcceptedError)(where, String(customerId), instanceId);
203
+ throw new (0, _chunk7IZHVYO2cjs.CustomerIdNotAcceptedError)(where, String(customerId), instanceId);
199
204
  }
200
205
 
201
206
  // src/transport/http.ts
202
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
+ }
203
238
  var DEFAULT_TIMEOUTS = {
204
239
  connect: 5,
205
240
  read: 30,
@@ -218,7 +253,12 @@ var HttpTransport = (_class2 = class {
218
253
 
219
254
 
220
255
  __init2() {this.closed = false}
221
- 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())));
222
262
  this.#credentials = options.credentials;
223
263
  this.baseUrl = (_nullishCoalesce(options.baseUrl, () => ( DEFAULT_BASE_URL))).replace(/\/+$/, "");
224
264
  this.timeouts = { ...DEFAULT_TIMEOUTS, ...options.timeouts };
@@ -265,14 +305,14 @@ var HttpTransport = (_class2 = class {
265
305
  * undefined means the server did not report it, which is true of any
266
306
  * deployment older than the field, and must mean "enforce nothing".
267
307
  */
268
- __init3() {this.userContextIsolation = void 0}
308
+ __init4() {this.userContextIsolation = void 0}
269
309
  /**
270
310
  * Set by the client to its identity resolution (`initialize()`'s whoami).
271
311
  * Python refuses every call before `initialize()`; here the first request
272
312
  * runs it instead, so a caller who skips it gets the same identity-dependent
273
313
  * behaviour (client-scope cache hits, the B2C check) rather than an error.
274
314
  */
275
- __init4() {this.identityResolver = void 0}
315
+ __init5() {this.identityResolver = void 0}
276
316
  /** Resolve identity once, before the first request. Never throws. */
277
317
  async ready() {
278
318
  if (this.identityResolver !== void 0) await this.identityResolver();
@@ -309,18 +349,54 @@ var HttpTransport = (_class2 = class {
309
349
  this.closed = true;
310
350
  this.heartbeat.stop();
311
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
+ }
312
380
  async request(name, options = {}) {
313
381
  const spec = ENDPOINTS[name];
314
- const correlationId = _nullishCoalesce(options.correlationId, () => ( _chunkUXNVTP4Dcjs.newCorrelationId.call(void 0, )));
382
+ const correlationId = _nullishCoalesce(options.correlationId, () => ( _chunk7IZHVYO2cjs.newCorrelationId.call(void 0, )));
315
383
  const idempotent = _nullishCoalesce(options.idempotent, () => ( spec.idempotent));
316
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);
317
388
  let attempt = 0;
318
389
  let last = null;
319
390
  while (attempt < this.retryPolicy.maxAttempts) {
320
391
  attempt += 1;
321
392
  try {
322
- 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;
323
396
  } catch (error) {
397
+ if (gated && error instanceof _chunk7IZHVYO2cjs.InstanceNotReadyError && !error.fromCooldown) {
398
+ this.cooldownStart(cooldownKey, error);
399
+ }
324
400
  last = { error, outcomeUnknown: isOutcomeUnknown(error) };
325
401
  const decision = shouldRetry({
326
402
  error,
@@ -334,7 +410,7 @@ var HttpTransport = (_class2 = class {
334
410
  await sleep(decision.delaySeconds * 1e3, options.signal);
335
411
  }
336
412
  }
337
- 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")));
338
414
  }
339
415
  async attempt(name, options, correlationId) {
340
416
  const spec = ENDPOINTS[name];
@@ -367,7 +443,7 @@ var HttpTransport = (_class2 = class {
367
443
  try {
368
444
  return JSON.parse(text);
369
445
  } catch (e3) {
370
- 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 });
371
447
  }
372
448
  }
373
449
  buildUrl(path, query) {
@@ -401,15 +477,15 @@ var HttpTransport = (_class2 = class {
401
477
  }
402
478
  }, _class2);
403
479
  function isOutcomeUnknown(error) {
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;
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;
411
487
  if (isConnectionRefusal(error)) return false;
412
- if (error instanceof _chunkUXNVTP4Dcjs.NetworkTimeoutError) return true;
488
+ if (error instanceof _chunk7IZHVYO2cjs.NetworkTimeoutError) return true;
413
489
  return true;
414
490
  }
415
491
  var CONNECTION_REFUSAL_CODES = /* @__PURE__ */ new Set([
@@ -429,18 +505,18 @@ function isConnectionRefusal(error) {
429
505
  return false;
430
506
  }
431
507
  function toTransportError(error, correlationId) {
432
- if (error instanceof _chunkUXNVTP4Dcjs.SynapError) return error;
508
+ if (error instanceof _chunk7IZHVYO2cjs.SynapError) return error;
433
509
  const name = _optionalChain([error, 'optionalAccess', _10 => _10.name]);
434
510
  if (name === "AbortError" || name === "TimeoutError") {
435
- return new (0, _chunkUXNVTP4Dcjs.NetworkTimeoutError)("Request timed out", { correlationId, cause: error });
511
+ return new (0, _chunk7IZHVYO2cjs.NetworkTimeoutError)("Request timed out", { correlationId, cause: error });
436
512
  }
437
513
  if (isConnectionRefusal(error)) {
438
- return new (0, _chunkUXNVTP4Dcjs.NetworkTimeoutError)(
514
+ return new (0, _chunk7IZHVYO2cjs.NetworkTimeoutError)(
439
515
  `Connection failed: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _11 => _11.message]), () => ( String(error)))}`,
440
516
  { correlationId, cause: error }
441
517
  );
442
518
  }
443
- return new (0, _chunkUXNVTP4Dcjs.ServiceUnavailableError)(
519
+ return new (0, _chunk7IZHVYO2cjs.ServiceUnavailableError)(
444
520
  `Network request failed: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _12 => _12.message]), () => ( String(error)))}`,
445
521
  { correlationId, cause: error }
446
522
  );
@@ -470,15 +546,15 @@ async function toHttpError(response, correlationId) {
470
546
  switch (response.status) {
471
547
  case 400:
472
548
  case 422:
473
- return new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(message, opts);
549
+ return new (0, _chunk7IZHVYO2cjs.InvalidInputError)(message, opts);
474
550
  case 401:
475
551
  case 403:
476
- return new (0, _chunkUXNVTP4Dcjs.AuthenticationError)(message, opts);
552
+ return new (0, _chunk7IZHVYO2cjs.AuthenticationError)(message, opts);
477
553
  case 404:
478
- return new (0, _chunkUXNVTP4Dcjs.ContextNotFoundError)(message, opts);
554
+ return new (0, _chunk7IZHVYO2cjs.ContextNotFoundError)(message, opts);
479
555
  case 402: {
480
556
  const credit = creditPayload(parsed, detailObject);
481
- return new (0, _chunkUXNVTP4Dcjs.InsufficientCreditsError)(message, {
557
+ return new (0, _chunk7IZHVYO2cjs.InsufficientCreditsError)(message, {
482
558
  ...opts,
483
559
  balanceCredits: numberOrNull(credit["balance_credits"]),
484
560
  requiredCredits: _nullishCoalesce(numberOrNull(credit["minimum_required_credits"]), () => ( numberOrNull(credit["required_credits"]))),
@@ -489,15 +565,44 @@ async function toHttpError(response, correlationId) {
489
565
  });
490
566
  }
491
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
+ }
492
597
  if (detailObject !== null && detailObject["code"] === "transcript_conflict") {
493
- return new (0, _chunkUXNVTP4Dcjs.TranscriptConflictError)(message, opts);
598
+ return new (0, _chunk7IZHVYO2cjs.TranscriptConflictError)(message, opts);
494
599
  }
495
- return new (0, _chunkUXNVTP4Dcjs.ConflictError)(message, opts);
600
+ return new (0, _chunk7IZHVYO2cjs.ConflictError)(message, opts);
496
601
  case 429: {
497
602
  const header = response.headers.get("retry-after");
498
603
  const retryAfter = header !== null && header.trim() !== "" ? Number(header) : null;
499
604
  const credit = creditPayload(parsed, detailObject);
500
- return new (0, _chunkUXNVTP4Dcjs.RateLimitError)(message, {
605
+ return new (0, _chunk7IZHVYO2cjs.RateLimitError)(message, {
501
606
  ...opts,
502
607
  retryAfterSeconds: retryAfter !== null && Number.isFinite(retryAfter) ? retryAfter : null,
503
608
  reason: creditReason(credit),
@@ -506,13 +611,13 @@ async function toHttpError(response, correlationId) {
506
611
  });
507
612
  }
508
613
  case 503:
509
- return new (0, _chunkUXNVTP4Dcjs.ServiceUnavailableError)(message, opts);
614
+ return new (0, _chunk7IZHVYO2cjs.ServiceUnavailableError)(message, opts);
510
615
  case 504:
511
- return new (0, _chunkUXNVTP4Dcjs.AgentUnavailableError)(message, opts);
616
+ return new (0, _chunk7IZHVYO2cjs.AgentUnavailableError)(message, opts);
512
617
  default:
513
- if (response.status >= 500) return new (0, _chunkUXNVTP4Dcjs.ServiceUnavailableError)(message, opts);
514
- if (response.status >= 400) return new (0, _chunkUXNVTP4Dcjs.SynapPermanentError)(message, opts);
515
- 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);
516
621
  }
517
622
  }
518
623
  function numberOrNull(v) {
@@ -523,11 +628,11 @@ function stringOrNull(v) {
523
628
  }
524
629
  function withTimeout(ms, external) {
525
630
  const controller = new AbortController();
526
- const onExternalAbort = () => controller.abort(_optionalChain([external, 'optionalAccess', _13 => _13.reason]));
631
+ const onExternalAbort = () => controller.abort(_optionalChain([external, 'optionalAccess', _19 => _19.reason]));
527
632
  const timer = setTimeout(() => {
528
- controller.abort(new (0, _chunkUXNVTP4Dcjs.NetworkTimeoutError)(`Timed out after ${ms}ms`));
633
+ controller.abort(new (0, _chunk7IZHVYO2cjs.NetworkTimeoutError)(`Timed out after ${ms}ms`));
529
634
  }, ms);
530
- _optionalChain([timer, 'access', _14 => _14.unref, 'optionalCall', _15 => _15()]);
635
+ _optionalChain([timer, 'access', _20 => _20.unref, 'optionalCall', _21 => _21()]);
531
636
  if (external) {
532
637
  if (external.aborted) onExternalAbort();
533
638
  else external.addEventListener("abort", onExternalAbort, { once: true });
@@ -536,7 +641,7 @@ function withTimeout(ms, external) {
536
641
  signal: controller.signal,
537
642
  dispose() {
538
643
  clearTimeout(timer);
539
- _optionalChain([external, 'optionalAccess', _16 => _16.removeEventListener, 'call', _17 => _17("abort", onExternalAbort)]);
644
+ _optionalChain([external, 'optionalAccess', _22 => _22.removeEventListener, 'call', _23 => _23("abort", onExternalAbort)]);
540
645
  }
541
646
  };
542
647
  }
@@ -544,14 +649,14 @@ function sleep(ms, signal) {
544
649
  if (ms <= 0) return Promise.resolve();
545
650
  return new Promise((resolve, reject) => {
546
651
  const timer = setTimeout(() => {
547
- _optionalChain([signal, 'optionalAccess', _18 => _18.removeEventListener, 'call', _19 => _19("abort", onAbort)]);
652
+ _optionalChain([signal, 'optionalAccess', _24 => _24.removeEventListener, 'call', _25 => _25("abort", onAbort)]);
548
653
  resolve();
549
654
  }, ms);
550
655
  function onAbort() {
551
656
  clearTimeout(timer);
552
- reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _20 => _20.reason]), () => ( new Error("Aborted"))));
657
+ reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _26 => _26.reason]), () => ( new Error("Aborted"))));
553
658
  }
554
- _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 })]);
555
660
  });
556
661
  }
557
662
 
@@ -660,10 +765,10 @@ function buildFetchRequest(scope, options) {
660
765
  const { mode, precisionLevel } = retrievalOptionsOf(options);
661
766
  const { contextMode, lastN } = scopeOptionsOf(scope, options);
662
767
  if (searchQuery !== void 0 && !Array.isArray(searchQuery)) {
663
- 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");
664
769
  }
665
770
  if (options.types !== void 0 && !Array.isArray(options.types)) {
666
- 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");
667
772
  }
668
773
  const body = {
669
774
  conversation_id: _nullishCoalesce(conversationId, () => ( null)),
@@ -712,7 +817,7 @@ var VALID_CONTEXT_MODES = ["in-conversation", "conversation-summary"];
712
817
  function responseShapeOf(options) {
713
818
  const shape = _nullishCoalesce(opt(options, "response_shape", "responseShape"), () => ( "by_type"));
714
819
  if (!RESPONSE_SHAPES.includes(shape)) {
715
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
820
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
716
821
  `Invalid response_shape '${shape}'. Must be one of: ${RESPONSE_SHAPES.join(", ")}`
717
822
  );
718
823
  }
@@ -727,21 +832,21 @@ var REQUIRED_ID = {
727
832
  function scopeOptionsOf(scope, options) {
728
833
  const required = REQUIRED_ID[scope];
729
834
  if (required !== null && !opt(options, required[0], required[1])) {
730
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(`${required[0]} is required`);
835
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(`${required[0]} is required`);
731
836
  }
732
837
  const contextMode = _nullishCoalesce(opt(options, "context_mode", "contextMode"), () => ( "in-conversation"));
733
838
  const lastN = _nullishCoalesce(opt(options, "last_n_conversations", "lastNConversations"), () => ( 1));
734
839
  if (scope !== "user") return { contextMode, lastN };
735
840
  if (!VALID_CONTEXT_MODES.includes(contextMode)) {
736
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
841
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
737
842
  `Invalid context_mode '${contextMode}'. Must be one of: ${VALID_CONTEXT_MODES.join(", ")}`
738
843
  );
739
844
  }
740
845
  if (!Number.isInteger(lastN)) {
741
- 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");
742
847
  }
743
848
  if (lastN < 0 || lastN > 20) {
744
- 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");
745
850
  }
746
851
  return { contextMode, lastN };
747
852
  }
@@ -750,13 +855,13 @@ var VALID_PRECISION = ["high", "medium"];
750
855
  function retrievalOptionsOf(options) {
751
856
  const mode = _nullishCoalesce(options.mode, () => ( "fast"));
752
857
  if (!VALID_MODES.includes(mode)) {
753
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
858
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
754
859
  `Invalid mode '${mode}'. Must be one of: ${VALID_MODES.join(", ")}`
755
860
  );
756
861
  }
757
862
  const precisionLevel = _nullishCoalesce(opt(options, "precision_level", "precisionLevel"), () => ( "high"));
758
863
  if (!VALID_PRECISION.includes(precisionLevel)) {
759
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
864
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
760
865
  `Invalid precision_level '${precisionLevel}'. Must be one of: ${VALID_PRECISION.join(", ")}`
761
866
  );
762
867
  }
@@ -764,7 +869,7 @@ function retrievalOptionsOf(options) {
764
869
  }
765
870
  async function fetchContext(transport, scope, options = {}, hooks = {}) {
766
871
  const startedAt = Date.now();
767
- await _optionalChain([transport, 'access', _23 => _23.ready, 'optionalCall', _24 => _24()]);
872
+ await _optionalChain([transport, 'access', _29 => _29.ready, 'optionalCall', _30 => _30()]);
768
873
  await transport.checkCustomerId(
769
874
  opt(options, "customer_id", "customerId"),
770
875
  `${scope}.context.fetch`
@@ -774,20 +879,20 @@ async function fetchContext(transport, scope, options = {}, hooks = {}) {
774
879
  const { contextMode } = scopeOptionsOf(scope, options);
775
880
  const summaryMode = scope === "user" && contextMode === "conversation-summary";
776
881
  const finish = (response2) => {
777
- _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)]);
778
883
  return response2;
779
884
  };
780
885
  const conversationId = opt(options, "conversation_id", "conversationId");
781
- 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;
782
887
  const network = async () => {
783
888
  const { endpoint, body } = buildFetchRequest(
784
889
  scope,
785
890
  skipServerSt ? { ...options, include_conversation_context: false } : options
786
891
  );
787
892
  const result = await transport.request(endpoint, { body });
788
- return applyResponseShape(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _29 => _29["context"]]), () => ( {})), responseShape);
893
+ return applyResponseShape(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _35 => _35["context"]]), () => ( {})), responseShape);
789
894
  };
790
- 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));
791
896
  if (anticipated !== null && anticipated.borderline) {
792
897
  const pending = network();
793
898
  pending.catch(() => void 0);
@@ -798,17 +903,17 @@ async function fetchContext(transport, scope, options = {}, hooks = {}) {
798
903
  const won = await Promise.race([pending.then((r) => r, () => null), late]);
799
904
  if (timer !== void 0) clearTimeout(timer);
800
905
  if (won !== null) {
801
- _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)]);
802
907
  return finish(won);
803
908
  }
804
909
  }
805
910
  if (anticipated !== null) {
806
- _optionalChain([hooks, 'access', _34 => _34.onServedFromCache, 'optionalCall', _35 => _35(scope, options, anticipated)]);
807
- _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)]);
808
913
  return finish(applyResponseShape(anticipated.response, responseShape));
809
914
  }
810
915
  const response = await network();
811
- _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)]);
812
917
  return finish(response);
813
918
  }
814
919
 
@@ -1063,17 +1168,17 @@ function isoOrNull(v) {
1063
1168
  return v instanceof Date ? v.toISOString() : v;
1064
1169
  }
1065
1170
  function buildCreateBody(options) {
1066
- if (!options.document) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("document is required");
1171
+ if (!options.document) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("document is required");
1067
1172
  const o2 = options;
1068
1173
  const documentType = _nullishCoalesce(either(o2, "document_type", "documentType"), () => ( DEFAULT_DOCUMENT_TYPE));
1069
1174
  const mode = _nullishCoalesce(options.mode, () => ( DEFAULT_INGEST_MODE));
1070
1175
  if (!DOCUMENT_TYPES.includes(documentType)) {
1071
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1176
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1072
1177
  `Invalid document_type '${documentType}'. Expected one of: ${DOCUMENT_TYPES.join(", ")}`
1073
1178
  );
1074
1179
  }
1075
1180
  if (!INGEST_MODES.includes(mode)) {
1076
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1181
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1077
1182
  `Invalid mode '${mode}'. Expected one of: ${INGEST_MODES.join(", ")}`
1078
1183
  );
1079
1184
  }
@@ -1099,14 +1204,16 @@ var FORGET_DESCRIPTION_MIN = 3;
1099
1204
  var FORGET_DESCRIPTION_MAX = 500;
1100
1205
  function buildForgetBody(options) {
1101
1206
  const description = options.description;
1102
- if (typeof description !== "string" || description.length < FORGET_DESCRIPTION_MIN || description.length > FORGET_DESCRIPTION_MAX) {
1103
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1207
+ if (typeof description !== "string" || // Code points, as Python's len() and the server count; `.length` counts
1208
+ // UTF-16 units, so 251 emoji (502 units) were refused here only.
1209
+ [...description].length < FORGET_DESCRIPTION_MIN || [...description].length > FORGET_DESCRIPTION_MAX) {
1210
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1104
1211
  `description must be between ${FORGET_DESCRIPTION_MIN} and ${FORGET_DESCRIPTION_MAX} characters`
1105
1212
  );
1106
1213
  }
1107
1214
  const mode = _nullishCoalesce(options.mode, () => ( "preview"));
1108
1215
  if (!FORGET_MODES.includes(mode)) {
1109
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1216
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1110
1217
  `Invalid mode '${mode}'. Expected one of: ${FORGET_MODES.join(", ")}`
1111
1218
  );
1112
1219
  }
@@ -1130,7 +1237,7 @@ function createMemoriesInterface(transport, onForgotten) {
1130
1237
  async batch_create(options) {
1131
1238
  const docs = options.documents;
1132
1239
  if (!Array.isArray(docs) || docs.length === 0) {
1133
- 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");
1134
1241
  }
1135
1242
  const failFast = _nullishCoalesce(_nullishCoalesce(options.fail_fast, () => ( options.failFast)), () => ( false));
1136
1243
  return transport.request("memories_batch", {
@@ -1142,17 +1249,17 @@ function createMemoriesInterface(transport, onForgotten) {
1142
1249
  const customerId = _nullishCoalesce(options.customer_id, () => ( options.customerId));
1143
1250
  const scope = options.scope;
1144
1251
  if (scope !== void 0 && scope !== null && (typeof scope !== "object" || Array.isArray(scope) || !Object.values(scope).every((v) => typeof v === "string"))) {
1145
- 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.");
1146
1253
  }
1147
- if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
1254
+ if (!userId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("user_id is required");
1148
1255
  await transport.checkCustomerId(customerId, "memories.create_from_file");
1149
1256
  const filePath = _nullishCoalesce(options.file_path, () => ( options.filePath));
1150
1257
  const sources = [filePath, options.file, options.text].filter((v) => v !== void 0);
1151
1258
  if (sources.length === 0) {
1152
- 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.");
1153
1260
  }
1154
1261
  if (sources.length > 1) {
1155
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1262
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1156
1263
  "Provide exactly one of file_path, file, or text, not several."
1157
1264
  );
1158
1265
  }
@@ -1188,13 +1295,13 @@ function createMemoriesInterface(transport, onForgotten) {
1188
1295
  });
1189
1296
  },
1190
1297
  async get(memoryId) {
1191
- if (!memoryId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("memory_id is required");
1298
+ if (!memoryId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("memory_id is required");
1192
1299
  return transport.request("memories_get", { pathParams: { memory_id: memoryId } });
1193
1300
  },
1194
1301
  async update(options) {
1195
1302
  const memoryId = _nullishCoalesce(options.memory_id, () => ( options.memoryId));
1196
- if (!memoryId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("memory_id is required");
1197
- 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");
1198
1305
  const body = {
1199
1306
  document: options.document,
1200
1307
  merge_strategy: _nullishCoalesce(_nullishCoalesce(options.merge_strategy, () => ( options.mergeStrategy)), () => ( "smart-merge"))
@@ -1209,7 +1316,7 @@ function createMemoriesInterface(transport, onForgotten) {
1209
1316
  },
1210
1317
  async delete(memoryId) {
1211
1318
  if (!memoryId) {
1212
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1319
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1213
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."
1214
1321
  );
1215
1322
  }
@@ -1220,7 +1327,7 @@ function createMemoriesInterface(transport, onForgotten) {
1220
1327
  await transport.checkCustomerId(_nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])), "memories.forget");
1221
1328
  const body = buildForgetBody(options);
1222
1329
  const result = await transport.request("memories_forget", { body });
1223
- 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";
1224
1331
  if (removed && onForgotten) {
1225
1332
  try {
1226
1333
  onForgotten({
@@ -1233,13 +1340,13 @@ function createMemoriesInterface(transport, onForgotten) {
1233
1340
  return result;
1234
1341
  },
1235
1342
  async status(ingestionId) {
1236
- if (!ingestionId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("ingestion_id is required");
1343
+ if (!ingestionId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("ingestion_id is required");
1237
1344
  return transport.request("memories_status", {
1238
1345
  pathParams: { ingestion_id: ingestionId }
1239
1346
  });
1240
1347
  },
1241
1348
  async wait_for_completion(ingestionId, options = {}) {
1242
- if (!ingestionId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("ingestion_id is required");
1349
+ if (!ingestionId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("ingestion_id is required");
1243
1350
  const timeoutMs = (_nullishCoalesce(_nullishCoalesce(options.timeout_seconds, () => ( options.timeoutSeconds)), () => ( 300))) * 1e3;
1244
1351
  const pollMs = (_nullishCoalesce(_nullishCoalesce(options.poll_interval_seconds, () => ( options.pollIntervalSeconds)), () => ( 2))) * 1e3;
1245
1352
  const deadline = Date.now() + timeoutMs;
@@ -1260,14 +1367,14 @@ function sleep2(ms, signal) {
1260
1367
  if (ms <= 0) return Promise.resolve();
1261
1368
  return new Promise((resolve, reject) => {
1262
1369
  const timer = setTimeout(() => {
1263
- _optionalChain([signal, 'optionalAccess', _44 => _44.removeEventListener, 'call', _45 => _45("abort", onAbort)]);
1370
+ _optionalChain([signal, 'optionalAccess', _50 => _50.removeEventListener, 'call', _51 => _51("abort", onAbort)]);
1264
1371
  resolve();
1265
1372
  }, ms);
1266
1373
  function onAbort() {
1267
1374
  clearTimeout(timer);
1268
- reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _46 => _46.reason]), () => ( new Error("Aborted"))));
1375
+ reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _52 => _52.reason]), () => ( new Error("Aborted"))));
1269
1376
  }
1270
- _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 })]);
1271
1378
  });
1272
1379
  }
1273
1380
 
@@ -1277,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
1277
1384
  function validateConversationId(conversationId) {
1278
1385
  if (conversationId === void 0 || conversationId === null || conversationId === "") return;
1279
1386
  if (typeof conversationId !== "string" || !UUID_RE.test(conversationId)) {
1280
- throw new (0, _chunkUXNVTP4Dcjs.InvalidConversationIdError)(`Invalid conversation ID: ${String(conversationId)}`);
1387
+ throw new (0, _chunk7IZHVYO2cjs.InvalidConversationIdError)(`Invalid conversation ID: ${String(conversationId)}`);
1281
1388
  }
1282
1389
  }
1283
1390
  function validateInstanceId(instanceId) {
1284
1391
  if (instanceId === void 0 || instanceId === null || instanceId === "") return;
1285
1392
  if (typeof instanceId !== "string" || !INSTANCE_ID_RE.test(instanceId)) {
1286
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInstanceIdError)(`Invalid instance ID: ${String(instanceId)}`);
1393
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInstanceIdError)(`Invalid instance ID: ${String(instanceId)}`);
1287
1394
  }
1288
1395
  }
1289
1396
 
@@ -1333,16 +1440,16 @@ function buildRecordMessageBody(options) {
1333
1440
  const conversationId = either2(o2, "conversation_id", "conversationId");
1334
1441
  const userId = either2(o2, "user_id", "userId");
1335
1442
  const customerId = either2(o2, "customer_id", "customerId");
1336
- if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1443
+ if (!conversationId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("conversation_id is required");
1337
1444
  validateConversationId(conversationId);
1338
- if (!options.role) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("role is required");
1445
+ if (!options.role) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("role is required");
1339
1446
  if (!MESSAGE_ROLES.includes(options.role)) {
1340
- 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'.`);
1341
1448
  }
1342
1449
  if (options.content === void 0 || options.content === null) {
1343
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("content is required");
1450
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("content is required");
1344
1451
  }
1345
- if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
1452
+ if (!userId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("user_id is required");
1346
1453
  const body = {
1347
1454
  conversation_id: conversationId,
1348
1455
  role: options.role,
@@ -1364,10 +1471,10 @@ function buildIngestTranscriptBody(options) {
1364
1471
  const o2 = options;
1365
1472
  const conversationId = either2(o2, "conversation_id", "conversationId");
1366
1473
  const userId = either2(o2, "user_id", "userId");
1367
- if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1368
- 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");
1369
1476
  if (options.transcript === void 0 || options.transcript === null) {
1370
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("transcript is required");
1477
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("transcript is required");
1371
1478
  }
1372
1479
  const body = {
1373
1480
  conversation_id: conversationId,
@@ -1393,7 +1500,7 @@ function buildIngestTranscriptBody(options) {
1393
1500
  function buildCompactBody(options) {
1394
1501
  const o2 = options;
1395
1502
  const conversationId = either2(o2, "conversation_id", "conversationId");
1396
- if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1503
+ if (!conversationId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("conversation_id is required");
1397
1504
  validateConversationId(conversationId);
1398
1505
  const body = { conversation_id: conversationId, force: _nullishCoalesce(options.force, () => ( false)) };
1399
1506
  const strategy = _nullishCoalesce(options.strategy, () => ( either2(o2, "compaction_level", "compactionLevel")));
@@ -1447,7 +1554,7 @@ function storedBatchRows(bodies, result) {
1447
1554
  const r = _nullishCoalesce(result, () => ( {}));
1448
1555
  const results = Array.isArray(r["results"]) ? r["results"] : [];
1449
1556
  const errors = Array.isArray(r["errors"]) ? r["errors"] : [];
1450
- 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"]])));
1451
1558
  const stored = bodies.filter((_, index) => !failed.has(index));
1452
1559
  if (stored.length !== results.length) return [];
1453
1560
  const pairs = [];
@@ -1491,7 +1598,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1491
1598
  };
1492
1599
  const convId = (v) => {
1493
1600
  const id = typeof v === "string" ? v : _nullishCoalesce(v.conversation_id, () => ( v.conversationId));
1494
- if (!id) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1601
+ if (!id) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("conversation_id is required");
1495
1602
  validateConversationId(id);
1496
1603
  return id;
1497
1604
  };
@@ -1525,7 +1632,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1525
1632
  },
1526
1633
  async record_messages_batch(messages) {
1527
1634
  if (!Array.isArray(messages) || messages.length === 0) {
1528
- 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");
1529
1636
  }
1530
1637
  for (const m of messages) {
1531
1638
  const mo = m;
@@ -1566,7 +1673,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1566
1673
  const raw = await transport.request("conversations_ingest", { body });
1567
1674
  const result = {
1568
1675
  ...raw,
1569
- 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) : []
1570
1677
  };
1571
1678
  onWrite({
1572
1679
  userId: body["user_id"],
@@ -1591,7 +1698,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1591
1698
  const id = convId(options);
1592
1699
  const style = _nullishCoalesce(options.style, () => ( "structured"));
1593
1700
  if (!PROMPT_STYLES.includes(style)) {
1594
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1701
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1595
1702
  `Invalid style '${style}'. Must be one of: ${PROMPT_STYLES.join(", ")}`
1596
1703
  );
1597
1704
  }
@@ -1610,8 +1717,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1610
1717
  pathParams: { conversation_id: id },
1611
1718
  query: { style }
1612
1719
  });
1613
- const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _51 => _51["context_for_prompt"]]), () => ( result)), () => ( {}));
1614
- _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)]);
1615
1722
  return withHistory(response);
1616
1723
  },
1617
1724
  async compact(options) {
@@ -1651,8 +1758,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1651
1758
  * Returns an idempotent unsubscribe thunk, matching Python.
1652
1759
  */
1653
1760
  subscribe_to_compaction_updates(conversationId, callback) {
1654
- if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1655
- 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");
1656
1763
  return subscribers.add(conversationId, callback);
1657
1764
  },
1658
1765
  /** Remove subscribers for one conversation, or all of them. Returns the count removed. */
@@ -1668,7 +1775,7 @@ function createUserNamespace(transport, hooks = {}) {
1668
1775
  return {
1669
1776
  async get_profile(options) {
1670
1777
  const userId = typeof options === "string" ? options : _nullishCoalesce(options.user_id, () => ( options.userId));
1671
- if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
1778
+ if (!userId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("user_id is required");
1672
1779
  const customerId = typeof options === "string" ? void 0 : _nullishCoalesce(options.customer_id, () => ( options.customerId));
1673
1780
  return transport.request("user_profile", {
1674
1781
  pathParams: { user_id: userId },
@@ -1717,7 +1824,7 @@ function createCreditsNamespace(transport) {
1717
1824
  });
1718
1825
  },
1719
1826
  async redeem(code) {
1720
- if (!code) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("code is required");
1827
+ if (!code) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("code is required");
1721
1828
  return transport.request("credits_redeem", { body: { code } });
1722
1829
  }
1723
1830
  };
@@ -1728,11 +1835,11 @@ function createCacheNamespace(cache) {
1728
1835
  return {
1729
1836
  clear: () => cache.clear(),
1730
1837
  clear_user: (userId) => {
1731
- if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
1838
+ if (!userId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("user_id is required");
1732
1839
  cache.dropEntity(userId);
1733
1840
  },
1734
1841
  clear_customer: (customerId) => {
1735
- if (!customerId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("customer_id is required");
1842
+ if (!customerId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("customer_id is required");
1736
1843
  cache.dropEntity(customerId);
1737
1844
  },
1738
1845
  stats: () => ({ bundles: cache.size, items: cache.itemCount })
@@ -1805,8 +1912,8 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1805
1912
  let onConversationState = null;
1806
1913
  const internals = {
1807
1914
  onCompactionUpdate(conversationId, bundle) {
1808
- _optionalChain([applyCompaction, 'optionalCall', _54 => _54(bundle)]);
1809
- _optionalChain([dispatchCompaction, 'optionalCall', _55 => _55(conversationId, bundle)]);
1915
+ _optionalChain([applyCompaction, 'optionalCall', _60 => _60(bundle)]);
1916
+ _optionalChain([dispatchCompaction, 'optionalCall', _61 => _61(conversationId, bundle)]);
1810
1917
  },
1811
1918
  setCompactionApplier(apply) {
1812
1919
  applyCompaction = apply;
@@ -1818,10 +1925,10 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1818
1925
  onConversationState = handle;
1819
1926
  },
1820
1927
  sendContextUsed(event) {
1821
- _optionalChain([client, 'optionalAccess', _56 => _56.sendContextUsed, 'call', _57 => _57(event)]);
1928
+ _optionalChain([client, 'optionalAccess', _62 => _62.sendContextUsed, 'call', _63 => _63(event)]);
1822
1929
  },
1823
1930
  sendContextAssembled(event) {
1824
- _optionalChain([client, 'optionalAccess', _58 => _58.sendContextAssembled, 'call', _59 => _59(event)]);
1931
+ _optionalChain([client, 'optionalAccess', _64 => _64.sendContextAssembled, 'call', _65 => _65(event)]);
1825
1932
  },
1826
1933
  setCompactionDispatcher(dispatch) {
1827
1934
  dispatchCompaction = dispatch;
@@ -1833,7 +1940,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1833
1940
  function ensureSession(conversationId, userId, customerId) {
1834
1941
  if (!conversationId || !userId || client === null) return;
1835
1942
  if (openSessions.has(conversationId)) return;
1836
- const sessionId = _chunkUXNVTP4Dcjs.newCorrelationId.call(void 0, );
1943
+ const sessionId = _chunk7IZHVYO2cjs.newCorrelationId.call(void 0, );
1837
1944
  try {
1838
1945
  client.sendSessionControl({
1839
1946
  action: "start",
@@ -1849,13 +1956,13 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1849
1956
  const namespace = {
1850
1957
  async listen(options = {}) {
1851
1958
  if (client !== null) {
1852
- 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");
1853
1960
  }
1854
1961
  try {
1855
- _optionalChain([onListen, 'optionalCall', _60 => _60()]);
1962
+ _optionalChain([onListen, 'optionalCall', _66 => _66()]);
1856
1963
  } catch (e10) {
1857
1964
  }
1858
- 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")));
1859
1966
  const onContext = _nullishCoalesce(options.on_context, () => ( options.onContext));
1860
1967
  const onDisconnect = _nullishCoalesce(options.on_disconnect, () => ( options.onDisconnect));
1861
1968
  const onReconnect = _nullishCoalesce(options.on_reconnect, () => ( options.onReconnect));
@@ -1870,17 +1977,17 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1870
1977
  internals.onCompactionUpdate(conversationId, bundle);
1871
1978
  },
1872
1979
  onConversationState: (conversationId, messageCount) => {
1873
- _optionalChain([onConversationState, 'optionalCall', _61 => _61(conversationId, messageCount)]);
1980
+ _optionalChain([onConversationState, 'optionalCall', _67 => _67(conversationId, messageCount)]);
1874
1981
  },
1875
1982
  onStateChange: (state) => {
1876
1983
  if (state !== "connected") openSessions.clear();
1877
1984
  if (state === "reconnecting") {
1878
1985
  reconnectAttempts += 1;
1879
- _optionalChain([onReconnect, 'optionalCall', _62 => _62(reconnectAttempts)]);
1986
+ _optionalChain([onReconnect, 'optionalCall', _68 => _68(reconnectAttempts)]);
1880
1987
  } else if (state === "disconnected") {
1881
- const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _63 => _63.lastError]), () => ( null));
1988
+ const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _69 => _69.lastError]), () => ( null));
1882
1989
  const reason = stopped === null ? "stream disconnected" : `credit_stop:${_nullishCoalesce(stopped.reason, () => ( "unknown"))}`;
1883
- _optionalChain([onDisconnect, 'optionalCall', _64 => _64(reason)]);
1990
+ _optionalChain([onDisconnect, 'optionalCall', _70 => _70(reason)]);
1884
1991
  }
1885
1992
  }
1886
1993
  });
@@ -1888,9 +1995,9 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1888
1995
  try {
1889
1996
  await created.connect();
1890
1997
  } catch (error) {
1891
- if (error instanceof _chunkUXNVTP4Dcjs.SynapError) throw error;
1892
- throw new (0, _chunkUXNVTP4Dcjs.SynapError)(
1893
- `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)))}`,
1894
2001
  { cause: error }
1895
2002
  );
1896
2003
  }
@@ -1923,15 +2030,15 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1923
2030
  _nullishCoalesce(options.customer_id, () => ( options.customerId)),
1924
2031
  "instance.send_message"
1925
2032
  );
1926
- 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");
1927
2034
  const eventType = _nullishCoalesce(_nullishCoalesce(options.event_type, () => ( options.eventType)), () => ( "user_message"));
1928
2035
  if (!KNOWN_EVENT_TYPES.has(eventType)) {
1929
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
2036
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
1930
2037
  `unknown event_type '${eventType}'. Expected one of: ` + [...KNOWN_EVENT_TYPES].sort().join(", ")
1931
2038
  );
1932
2039
  }
1933
2040
  if (options.content === void 0 || options.content === null) {
1934
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("content is required");
2041
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("content is required");
1935
2042
  }
1936
2043
  const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
1937
2044
  ensureSession(
@@ -1940,7 +2047,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1940
2047
  _nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( ""))
1941
2048
  );
1942
2049
  if (eventType === "user_message" || eventType === "assistant_message") {
1943
- _optionalChain([onTurn, 'optionalCall', _66 => _66({
2050
+ _optionalChain([onTurn, 'optionalCall', _72 => _72({
1944
2051
  conversationId,
1945
2052
  role: _nullishCoalesce(options.role, () => ( "user")),
1946
2053
  content: options.content
@@ -1992,7 +2099,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1992
2099
  async record_tool_result(options) {
1993
2100
  const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
1994
2101
  if (conversationId) {
1995
- _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)), () => ( "")) })]);
1996
2103
  }
1997
2104
  await namespace.send_message({
1998
2105
  content: "",
@@ -2009,7 +2116,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
2009
2116
  });
2010
2117
  },
2011
2118
  async record_thinking(options) {
2012
- 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");
2013
2120
  const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
2014
2121
  ensureSession(
2015
2122
  conversationId,
@@ -2044,7 +2151,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
2044
2151
  }
2045
2152
 
2046
2153
  // src/version.ts
2047
- var SDK_VERSION = "0.5.20";
2154
+ var SDK_VERSION = "0.6.0";
2048
2155
 
2049
2156
  // src/registry.ts
2050
2157
  var instances = /* @__PURE__ */ new Map();
@@ -2391,13 +2498,13 @@ function bytesOf(text) {
2391
2498
  }
2392
2499
  var TurnStore = (_class3 = class {
2393
2500
 
2394
- __init5() {this.onDisk = false}
2501
+ __init6() {this.onDisk = false}
2395
2502
  #now;
2396
2503
  #seq = 0;
2397
2504
  #writes = 0;
2398
2505
  #conversations = /* @__PURE__ */ new Map();
2399
2506
  #vectors = /* @__PURE__ */ new Map();
2400
- constructor(options = {}) {;_class3.prototype.__init5.call(this);
2507
+ constructor(options = {}) {;_class3.prototype.__init6.call(this);
2401
2508
  this.limits = _nullishCoalesce(options.limits, () => ( { ..._chunkICUFS3B5cjs.HISTORY_SEARCH.store_limits }));
2402
2509
  this.#now = _nullishCoalesce(options.now, () => ( (() => Date.now() / 1e3)));
2403
2510
  }
@@ -2512,7 +2619,7 @@ var TurnStore = (_class3 = class {
2512
2619
  }
2513
2620
  /** Turns the server also holds: archived tool results are local only. Python: `count`. */
2514
2621
  count(conversationId) {
2515
- 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;
2516
2623
  }
2517
2624
  sizeBytes() {
2518
2625
  let n2 = 0;
@@ -2691,7 +2798,7 @@ function askedKinds(query) {
2691
2798
  }
2692
2799
  function asksHowItStarted(query) {
2693
2800
  const spec = _chunkICUFS3B5cjs.HISTORY_SEARCH.early_query;
2694
- if (!_optionalChain([spec, 'optionalAccess', _72 => _72.pattern])) return false;
2801
+ if (!_optionalChain([spec, 'optionalAccess', _78 => _78.pattern])) return false;
2695
2802
  return new RegExp(spec.pattern, (_nullishCoalesce(spec.flags, () => ( ""))).includes("i") ? "i" : "").test(_nullishCoalesce(query, () => ( "")));
2696
2803
  }
2697
2804
  async function searchTurns(turns, query, options = {}) {
@@ -3707,7 +3814,7 @@ function buildTool(target, options = {}, onWarning = () => {
3707
3814
  const scope = String(_nullishCoalesce(options.scope, () => ( "user"))).toLowerCase();
3708
3815
  if (!VALID_SCOPES.includes(scope)) {
3709
3816
  const sorted = [...VALID_SCOPES].sort();
3710
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
3817
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)(
3711
3818
  `scope must be one of ['${sorted.join("', '")}'], got '${String(options.scope)}'`
3712
3819
  );
3713
3820
  }
@@ -3715,10 +3822,10 @@ function buildTool(target, options = {}, onWarning = () => {
3715
3822
  const customerId = _nullishCoalesce(options.customer_id, () => ( options.customerId));
3716
3823
  const conversationId = _nullishCoalesce(options.conversation_id, () => ( options.conversationId));
3717
3824
  if (scope === "user" && (userId === void 0 || userId === "")) {
3718
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("scope='user' requires user_id");
3825
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("scope='user' requires user_id");
3719
3826
  }
3720
3827
  if (scope === "customer" && (customerId === void 0 || customerId === "")) {
3721
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("scope='customer' requires customer_id");
3828
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("scope='customer' requires customer_id");
3722
3829
  }
3723
3830
  if (scope === "conversation" && (userId === void 0 || userId === "")) {
3724
3831
  onWarning(
@@ -3727,7 +3834,7 @@ function buildTool(target, options = {}, onWarning = () => {
3727
3834
  }
3728
3835
  const style = String(_nullishCoalesce(options.style, () => ( "openai")));
3729
3836
  if (style !== "openai" && style !== "anthropic") {
3730
- 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}'`);
3731
3838
  }
3732
3839
  const toolName = _nullishCoalesce(options.name, () => ( `synap_fetch_${scope}_context`));
3733
3840
  const toolDesc = _nullishCoalesce(options.description, () => ( defaultToolDescription(scope)));
@@ -3904,7 +4011,7 @@ var SynapClient = (_class4 = class _SynapClient {
3904
4011
  this.#localEncoder = _nullishCoalesce(_nullishCoalesce(options.history_search_encoder, () => ( options.historySearchEncoder)), () => ( null));
3905
4012
  const modelOption = options.history_search_model !== void 0 ? options.history_search_model : options.historySearchModel;
3906
4013
  this.#localModelName = modelOption === void 0 ? "auto" : modelOption;
3907
- 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);
3908
4015
  this.#turns = new TurnCounter();
3909
4016
  this.conversation = createConversationNamespace(
3910
4017
  this.#transport,
@@ -4004,9 +4111,9 @@ var SynapClient = (_class4 = class _SynapClient {
4004
4111
  */
4005
4112
  async searchMemory(options) {
4006
4113
  const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
4007
- if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
4114
+ if (!userId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("user_id is required");
4008
4115
  if (options.query === void 0 || options.query === null) {
4009
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("query is required");
4116
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("query is required");
4010
4117
  }
4011
4118
  const context = await fetchContext(this.#transport, "user", {
4012
4119
  user_id: userId,
@@ -4027,7 +4134,7 @@ var SynapClient = (_class4 = class _SynapClient {
4027
4134
  */
4028
4135
  async getMemories(options) {
4029
4136
  const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
4030
- if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
4137
+ if (!userId) throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("user_id is required");
4031
4138
  const context = await fetchContext(this.#transport, "user", {
4032
4139
  user_id: userId,
4033
4140
  ...pick3(options, "customer_id", "customerId") !== void 0 ? { customer_id: pick3(options, "customer_id", "customerId") } : {},
@@ -4132,7 +4239,7 @@ var SynapClient = (_class4 = class _SynapClient {
4132
4239
  */
4133
4240
  configure(options = {}) {
4134
4241
  if (this.#initialized) {
4135
- throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("Cannot reconfigure after initialization");
4242
+ throw new (0, _chunk7IZHVYO2cjs.InvalidInputError)("Cannot reconfigure after initialization");
4136
4243
  }
4137
4244
  if (options.timeouts !== void 0) this.#transport.setTimeouts(options.timeouts);
4138
4245
  if (options.retryPolicy !== void 0 || options.retry_policy !== void 0) {
@@ -4253,7 +4360,7 @@ var SynapClient = (_class4 = class _SynapClient {
4253
4360
  successful.push([label, result.value]);
4254
4361
  continue;
4255
4362
  }
4256
- if (result.reason instanceof _chunkUXNVTP4Dcjs.InvalidInputError) throw result.reason;
4363
+ if (result.reason instanceof _chunk7IZHVYO2cjs.InvalidInputError) throw result.reason;
4257
4364
  this.#warn(`Scope '${label}' fetch failed in unified fetch (non-fatal): ${String(result.reason)}`);
4258
4365
  }
4259
4366
  const merged = mergeScopeResults(successful);
@@ -4332,7 +4439,7 @@ var SynapClient = (_class4 = class _SynapClient {
4332
4439
  if (!this.instance.is_listening) return;
4333
4440
  this.instance._internal.sendContextAssembled({
4334
4441
  ...buildAssembledEvent({
4335
- correlationId: _chunkUXNVTP4Dcjs.newCorrelationId.call(void 0, ),
4442
+ correlationId: _chunk7IZHVYO2cjs.newCorrelationId.call(void 0, ),
4336
4443
  response,
4337
4444
  conversationId: _nullishCoalesce(options["conversation_id"], () => ( options["conversationId"])),
4338
4445
  userId: _nullishCoalesce(options["user_id"], () => ( options["userId"])),
@@ -4403,14 +4510,14 @@ var SynapClient = (_class4 = class _SynapClient {
4403
4510
  }))
4404
4511
  );
4405
4512
  const entry = this.#shortTerm.get(conversationId);
4406
- 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);
4407
4514
  this.#maybeBackfillTurns(conversationId, total);
4408
4515
  if (!r["context_block"]) return response;
4409
4516
  const turns = store.turns(conversationId);
4410
4517
  let q = query;
4411
4518
  if (!q) {
4412
4519
  const latest = [...recent].reverse().find((m) => m["role"] === "user");
4413
- 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]), () => ( ""));
4414
4521
  }
4415
4522
  if (!q) return response;
4416
4523
  const exclude = /* @__PURE__ */ new Set();
@@ -4554,13 +4661,13 @@ function pick3(o2, snake, camel) {
4554
4661
  function resolveBaseUrl(options) {
4555
4662
  const explicit = _nullishCoalesce(options.baseUrl, () => ( options.api_base_url));
4556
4663
  if (explicit !== void 0) return explicit;
4557
- 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()]);
4558
4665
  return fromEnv !== void 0 && fromEnv !== "" ? fromEnv : void 0;
4559
4666
  }
4560
4667
  function resolveCredentials(options) {
4561
4668
  const apiKey = _nullishCoalesce(options.apiKey, () => ( _chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_API_KEY")));
4562
4669
  if (!apiKey) {
4563
- throw new (0, _chunkUXNVTP4Dcjs.AuthenticationError)(
4670
+ throw new (0, _chunk7IZHVYO2cjs.AuthenticationError)(
4564
4671
  "No Synap API key found. Set SYNAP_API_KEY in your environment, or pass apiKey to the SynapClient constructor."
4565
4672
  );
4566
4673
  }
@@ -4629,5 +4736,7 @@ function resolveCredentials(options) {
4629
4736
 
4630
4737
 
4631
4738
 
4632
- 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;
4633
4742
  //# sourceMappingURL=index.cjs.map