@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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { E as Encoder, a as AnticipationCacheSnapshot } from './errors-BvUA5EW8.cjs';
2
- export { b as ANY_SCOPE, c as AgentUnavailableError, A as AnticipationCache, d as AnticipationCacheOptions, e as AuthenticationError, B as BundleItem, C as ConflictError, f as ConnectionError, g as ContextBundle, h as ContextNotFoundError, i as CustomerIdNotAcceptedError, j as ExitReason, I as InsufficientCreditsError, k as InvalidConversationIdError, l as InvalidInputError, m as InvalidInstanceIdError, L as ListeningAlreadyActiveError, n as ListeningNotActiveError, o as LookupParams, p as LookupResult, q as LookupTelemetry, N as NetworkTimeoutError, P as PermanentError, R as RateLimitError, r as SDKError, s as ServiceUnavailableError, t as SessionExpiredError, u as SnapshotBundle, v as SnapshotItemPreview, w as SnapshotItemRecord, S as SynapError, x as SynapErrorCode, y as SynapErrorOptions, z as SynapPermanentError, D as SynapTransientError, T as TranscriptConflictError, F as TransientError, G as isSynapError } from './errors-BvUA5EW8.cjs';
1
+ import { E as Encoder, a as AnticipationCacheSnapshot } from './errors-DWjdpExq.cjs';
2
+ export { b as ANY_SCOPE, c as AgentUnavailableError, A as AnticipationCache, d as AnticipationCacheOptions, e as AuthenticationError, B as BundleItem, C as ConflictError, f as ConnectionError, g as ContextBundle, h as ContextNotFoundError, i as CustomerIdNotAcceptedError, j as ExitReason, I as InstanceBuildFailedError, k as InstanceNotReadyError, l as InsufficientCreditsError, m as InvalidConversationIdError, n as InvalidInputError, o as InvalidInstanceIdError, L as ListeningAlreadyActiveError, p as ListeningNotActiveError, q as LookupParams, r as LookupResult, s as LookupTelemetry, N as NetworkTimeoutError, P as PermanentError, R as RateLimitError, t as SDKError, u as ServiceUnavailableError, v as SessionExpiredError, w as SnapshotBundle, x as SnapshotItemPreview, y as SnapshotItemRecord, S as SynapError, z as SynapErrorCode, D as SynapErrorOptions, F as SynapPermanentError, G as SynapTransientError, T as TranscriptConflictError, H as TransientError, J as isSynapError } from './errors-DWjdpExq.cjs';
3
3
 
4
4
  /**
5
5
  * AUTOGENERATED FROM synap/sdk/CONTRACT/endpoints.yaml -- DO NOT EDIT.
@@ -269,6 +269,8 @@ interface HttpTransportOptions {
269
269
  userAgent?: string;
270
270
  /** Injected in tests. Defaults to global fetch. */
271
271
  fetchImpl?: typeof fetch;
272
+ /** Monotonic clock in milliseconds. Injected in tests; defaults to `performance.now`. */
273
+ clock?: () => number;
272
274
  }
273
275
  interface RequestOptions {
274
276
  pathParams?: Record<string, string | number>;
@@ -296,6 +298,8 @@ declare class HttpTransport {
296
298
  private readonly keepAliveOptions;
297
299
  private readonly heartbeat;
298
300
  private closed;
301
+ private readonly clock;
302
+ private readonly notReadyCooldown;
299
303
  constructor(options: HttpTransportOptions);
300
304
  /** Start keeping the connection warm. Opt-in: it is pointless in serverless. */
301
305
  startHeartbeat(): void;
@@ -352,6 +356,10 @@ declare class HttpTransport {
352
356
  */
353
357
  setRetryPolicy(policy: Partial<RetryPolicy> | null): void;
354
358
  close(): void;
359
+ /** Throw InstanceNotReadyError locally if this instance is cooling down. */
360
+ private cooldownCheck;
361
+ /** Remember a server refusal. Never longer than the server's hint. */
362
+ private cooldownStart;
355
363
  request<T = unknown>(name: EndpointName, options?: RequestOptions): Promise<T>;
356
364
  private attempt;
357
365
  private buildUrl;
@@ -1892,7 +1900,7 @@ declare class SynapClient {
1892
1900
  * build when the two disagree, which is the only thing that makes a manual
1893
1901
  * publish safe.
1894
1902
  */
1895
- declare const SDK_VERSION = "0.5.20";
1903
+ declare const SDK_VERSION = "0.6.0";
1896
1904
 
1897
1905
  /**
1898
1906
  * `response_shape: "ranked"`: one list in the order the server ranked it.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { E as Encoder, a as AnticipationCacheSnapshot } from './errors-BvUA5EW8.js';
2
- export { b as ANY_SCOPE, c as AgentUnavailableError, A as AnticipationCache, d as AnticipationCacheOptions, e as AuthenticationError, B as BundleItem, C as ConflictError, f as ConnectionError, g as ContextBundle, h as ContextNotFoundError, i as CustomerIdNotAcceptedError, j as ExitReason, I as InsufficientCreditsError, k as InvalidConversationIdError, l as InvalidInputError, m as InvalidInstanceIdError, L as ListeningAlreadyActiveError, n as ListeningNotActiveError, o as LookupParams, p as LookupResult, q as LookupTelemetry, N as NetworkTimeoutError, P as PermanentError, R as RateLimitError, r as SDKError, s as ServiceUnavailableError, t as SessionExpiredError, u as SnapshotBundle, v as SnapshotItemPreview, w as SnapshotItemRecord, S as SynapError, x as SynapErrorCode, y as SynapErrorOptions, z as SynapPermanentError, D as SynapTransientError, T as TranscriptConflictError, F as TransientError, G as isSynapError } from './errors-BvUA5EW8.js';
1
+ import { E as Encoder, a as AnticipationCacheSnapshot } from './errors-DWjdpExq.js';
2
+ export { b as ANY_SCOPE, c as AgentUnavailableError, A as AnticipationCache, d as AnticipationCacheOptions, e as AuthenticationError, B as BundleItem, C as ConflictError, f as ConnectionError, g as ContextBundle, h as ContextNotFoundError, i as CustomerIdNotAcceptedError, j as ExitReason, I as InstanceBuildFailedError, k as InstanceNotReadyError, l as InsufficientCreditsError, m as InvalidConversationIdError, n as InvalidInputError, o as InvalidInstanceIdError, L as ListeningAlreadyActiveError, p as ListeningNotActiveError, q as LookupParams, r as LookupResult, s as LookupTelemetry, N as NetworkTimeoutError, P as PermanentError, R as RateLimitError, t as SDKError, u as ServiceUnavailableError, v as SessionExpiredError, w as SnapshotBundle, x as SnapshotItemPreview, y as SnapshotItemRecord, S as SynapError, z as SynapErrorCode, D as SynapErrorOptions, F as SynapPermanentError, G as SynapTransientError, T as TranscriptConflictError, H as TransientError, J as isSynapError } from './errors-DWjdpExq.js';
3
3
 
4
4
  /**
5
5
  * AUTOGENERATED FROM synap/sdk/CONTRACT/endpoints.yaml -- DO NOT EDIT.
@@ -269,6 +269,8 @@ interface HttpTransportOptions {
269
269
  userAgent?: string;
270
270
  /** Injected in tests. Defaults to global fetch. */
271
271
  fetchImpl?: typeof fetch;
272
+ /** Monotonic clock in milliseconds. Injected in tests; defaults to `performance.now`. */
273
+ clock?: () => number;
272
274
  }
273
275
  interface RequestOptions {
274
276
  pathParams?: Record<string, string | number>;
@@ -296,6 +298,8 @@ declare class HttpTransport {
296
298
  private readonly keepAliveOptions;
297
299
  private readonly heartbeat;
298
300
  private closed;
301
+ private readonly clock;
302
+ private readonly notReadyCooldown;
299
303
  constructor(options: HttpTransportOptions);
300
304
  /** Start keeping the connection warm. Opt-in: it is pointless in serverless. */
301
305
  startHeartbeat(): void;
@@ -352,6 +356,10 @@ declare class HttpTransport {
352
356
  */
353
357
  setRetryPolicy(policy: Partial<RetryPolicy> | null): void;
354
358
  close(): void;
359
+ /** Throw InstanceNotReadyError locally if this instance is cooling down. */
360
+ private cooldownCheck;
361
+ /** Remember a server refusal. Never longer than the server's hint. */
362
+ private cooldownStart;
355
363
  request<T = unknown>(name: EndpointName, options?: RequestOptions): Promise<T>;
356
364
  private attempt;
357
365
  private buildUrl;
@@ -1892,7 +1900,7 @@ declare class SynapClient {
1892
1900
  * build when the two disagree, which is the only thing that makes a manual
1893
1901
  * publish safe.
1894
1902
  */
1895
- declare const SDK_VERSION = "0.5.20";
1903
+ declare const SDK_VERSION = "0.6.0";
1896
1904
 
1897
1905
  /**
1898
1906
  * `response_shape: "ranked"`: one list in the order the server ranked it.
package/dist/index.js CHANGED
@@ -21,6 +21,8 @@ import {
21
21
  ConnectionError,
22
22
  ContextNotFoundError,
23
23
  CustomerIdNotAcceptedError,
24
+ InstanceBuildFailedError,
25
+ InstanceNotReadyError,
24
26
  InsufficientCreditsError,
25
27
  InvalidConversationIdError,
26
28
  InvalidInputError,
@@ -40,7 +42,7 @@ import {
40
42
  TransientError,
41
43
  isSynapError,
42
44
  newCorrelationId
43
- } from "./chunk-4GE7SORD.js";
45
+ } from "./chunk-DEFC7NHQ.js";
44
46
 
45
47
  // src/transport/endpoints.ts
46
48
  var ENDPOINTS = {
@@ -106,6 +108,9 @@ function shouldRetry(input) {
106
108
  if (!isSynapError(error) || !error.transient) {
107
109
  return { retry: false, delaySeconds: 0, reason: "not_transient" };
108
110
  }
111
+ if (error instanceof RateLimitError && error.reason) {
112
+ return { retry: false, delaySeconds: 0, reason: "credit_stop" };
113
+ }
109
114
  const idempotent = input.idempotent ?? IDEMPOTENT_METHODS.has(method.toUpperCase());
110
115
  if (outcomeUnknown && !idempotent) {
111
116
  return {
@@ -200,6 +205,36 @@ function checkCustomerId(isolation, customerId, where, instanceId) {
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 = (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 = class {
218
253
  keepAliveOptions;
219
254
  heartbeat;
220
255
  closed = false;
256
+ clock;
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
+ notReadyCooldown = /* @__PURE__ */ new Map();
221
260
  constructor(options) {
261
+ this.clock = options.clock ?? (() => performance.now());
222
262
  this.#credentials = options.credentials;
223
263
  this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
224
264
  this.timeouts = { ...DEFAULT_TIMEOUTS, ...options.timeouts };
@@ -309,18 +349,54 @@ var HttpTransport = 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 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
382
  const correlationId = options.correlationId ?? newCorrelationId();
315
383
  const idempotent = 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 InstanceNotReadyError && !error.fromCooldown) {
398
+ this.cooldownStart(cooldownKey, error);
399
+ }
324
400
  last = { error, outcomeUnknown: isOutcomeUnknown(error) };
325
401
  const decision = shouldRetry({
326
402
  error,
@@ -489,6 +565,35 @@ async function toHttpError(response, correlationId) {
489
565
  });
490
566
  }
491
567
  case 409:
568
+ if (parsed["error"] === "instance_build_failed" || detailObject?.["code"] === "instance_build_failed" || detailObject?.["error"] === "instance_build_failed") {
569
+ const pick4 = (key) => parsed[key] ?? detailObject?.[key];
570
+ const msg = pick4("message");
571
+ const attempts = Number(pick4("attempts"));
572
+ return new 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" || detailObject?.["code"] === "instance_not_ready" || detailObject?.["error"] === "instance_not_ready") {
583
+ const pick4 = (key) => parsed[key] ?? detailObject?.[key];
584
+ const rawWait = 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 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: stringOrNull(pick4("state")) ?? "building"
594
+ }
595
+ );
596
+ }
492
597
  if (detailObject !== null && detailObject["code"] === "transcript_conflict") {
493
598
  return new TranscriptConflictError(message, opts);
494
599
  }
@@ -1099,7 +1204,9 @@ 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) {
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) {
1103
1210
  throw new InvalidInputError(
1104
1211
  `description must be between ${FORGET_DESCRIPTION_MIN} and ${FORGET_DESCRIPTION_MAX} characters`
1105
1212
  );
@@ -1855,7 +1962,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1855
1962
  onListen?.();
1856
1963
  } catch {
1857
1964
  }
1858
- const { GrpcStreamClient } = await import("./stream-client-2UMDGCMQ.js");
1965
+ const { GrpcStreamClient } = await import("./stream-client-GRDVRBFA.js");
1859
1966
  const onContext = options.on_context ?? options.onContext;
1860
1967
  const onDisconnect = options.on_disconnect ?? options.onDisconnect;
1861
1968
  const onReconnect = options.on_reconnect ?? options.onReconnect;
@@ -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();
@@ -4594,6 +4701,8 @@ export {
4594
4701
  HttpTransport,
4595
4702
  INGEST_MODES,
4596
4703
  ITEM_COLLECTIONS,
4704
+ InstanceBuildFailedError,
4705
+ InstanceNotReadyError,
4597
4706
  InsufficientCreditsError,
4598
4707
  InvalidConversationIdError,
4599
4708
  InvalidInputError,