@maximem/synap-js-sdk 0.4.6 → 0.4.8

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 (43) hide show
  1. package/dist/{anticipation-cache-BMVF5sXb.d.cts → anticipation-cache-C1rUEpaW.d.cts} +22 -1
  2. package/dist/{anticipation-cache-BMVF5sXb.d.ts → anticipation-cache-C1rUEpaW.d.ts} +22 -1
  3. package/dist/anticipation-cache-LRE3TLK4.cjs +14 -0
  4. package/dist/anticipation-cache-LRE3TLK4.cjs.map +1 -0
  5. package/dist/anticipation-cache-WLU4NMD5.js +14 -0
  6. package/dist/chunk-2TVL5IPQ.cjs.map +1 -1
  7. package/dist/{chunk-3JSE64GW.cjs → chunk-7CWBRHUO.cjs} +15 -2
  8. package/dist/chunk-7CWBRHUO.cjs.map +1 -0
  9. package/dist/{chunk-6LDUDKHS.js → chunk-ODVOQOSO.js} +124 -8
  10. package/dist/chunk-ODVOQOSO.js.map +1 -0
  11. package/dist/{chunk-ZU6ZC4SU.js → chunk-T5QQBJ6T.js} +15 -2
  12. package/dist/chunk-T5QQBJ6T.js.map +1 -0
  13. package/dist/{chunk-RB57I2IQ.cjs → chunk-T6U5PVAD.cjs} +125 -9
  14. package/dist/chunk-T6U5PVAD.cjs.map +1 -0
  15. package/dist/chunk-ZKOJDUN4.cjs.map +1 -1
  16. package/dist/env-55ULHNJZ.cjs.map +1 -1
  17. package/dist/grpc/index.cjs +4 -4
  18. package/dist/grpc/index.cjs.map +1 -1
  19. package/dist/grpc/index.d.cts +3 -3
  20. package/dist/grpc/index.d.ts +3 -3
  21. package/dist/grpc/index.js +3 -3
  22. package/dist/index.cjs +31 -16
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +41 -4
  25. package/dist/index.d.ts +41 -4
  26. package/dist/index.js +29 -14
  27. package/dist/index.js.map +1 -1
  28. package/dist/stream-client-2C5KIOWP.js +7 -0
  29. package/dist/stream-client-GPU37E6F.cjs +7 -0
  30. package/dist/stream-client-GPU37E6F.cjs.map +1 -0
  31. package/package.json +6 -1
  32. package/dist/anticipation-cache-ARYEEKMU.cjs +0 -10
  33. package/dist/anticipation-cache-ARYEEKMU.cjs.map +0 -1
  34. package/dist/anticipation-cache-H7HEVWQC.js +0 -10
  35. package/dist/chunk-3JSE64GW.cjs.map +0 -1
  36. package/dist/chunk-6LDUDKHS.js.map +0 -1
  37. package/dist/chunk-RB57I2IQ.cjs.map +0 -1
  38. package/dist/chunk-ZU6ZC4SU.js.map +0 -1
  39. package/dist/stream-client-6V4FGKZ3.js +0 -7
  40. package/dist/stream-client-PRTOH62B.cjs +0 -7
  41. package/dist/stream-client-PRTOH62B.cjs.map +0 -1
  42. /package/dist/{anticipation-cache-H7HEVWQC.js.map → anticipation-cache-WLU4NMD5.js.map} +0 -0
  43. /package/dist/{stream-client-6V4FGKZ3.js.map → stream-client-2C5KIOWP.js.map} +0 -0
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as AnticipationCacheSnapshot } from './anticipation-cache-BMVF5sXb.cjs';
2
- export { b as ANY_SCOPE, A as AnticipationCache, c as AnticipationCacheOptions, B as BundleItem, C as ContextBundle, E as ExitReason, L as LookupParams, d as LookupResult, e as LookupTelemetry, S as SnapshotBundle, f as SnapshotItemPreview, g as SnapshotItemRecord } from './anticipation-cache-BMVF5sXb.cjs';
1
+ import { a as AnticipationCacheSnapshot } from './anticipation-cache-C1rUEpaW.cjs';
2
+ export { b as ANY_SCOPE, A as AnticipationCache, c as AnticipationCacheOptions, B as BundleItem, C as ContextBundle, E as ExitReason, L as LookupParams, d as LookupResult, e as LookupTelemetry, S as SnapshotBundle, f as SnapshotItemPreview, g as SnapshotItemRecord } from './anticipation-cache-C1rUEpaW.cjs';
3
3
 
4
4
  /**
5
5
  * AUTOGENERATED FROM synap/sdk/CONTRACT/endpoints.yaml -- DO NOT EDIT.
@@ -597,6 +597,21 @@ interface CreateMemoryOptions {
597
597
  documentCreatedAt?: string | Date | null;
598
598
  mode?: IngestMode | string;
599
599
  metadata?: Json;
600
+ /**
601
+ * The level this memory belongs to, named in full, one entry per level down
602
+ * to it: `{ customer: "acme", team: "payments", user: "dana" }`.
603
+ *
604
+ * Only needed by an account whose scope ladder has a level between its
605
+ * customer and its user levels. `user_id` and `customer_id` cannot say which
606
+ * one a write belongs to, so on such a ladder the server refuses the write
607
+ * rather than guessing: a wrong guess at or above the customer level crosses
608
+ * a tenant boundary.
609
+ *
610
+ * Omit it and nothing changes. Sending one to an account without nested
611
+ * scoping is an error rather than ignored, because a caller who asks to be
612
+ * narrowed and is ignored gets widened instead.
613
+ */
614
+ scope?: Record<string, string> | null;
600
615
  }
601
616
  /**
602
617
  * Mirrors Python's `CreateMemoryResponse`.
@@ -672,6 +687,21 @@ interface CreateFromFileOptions {
672
687
  documentType?: string;
673
688
  mode?: IngestMode | string;
674
689
  metadata?: Json;
690
+ /**
691
+ * The level this memory belongs to, named in full, one entry per level down
692
+ * to it: `{ customer: "acme", team: "payments", user: "dana" }`.
693
+ *
694
+ * Only needed by an account whose scope ladder has a level between its
695
+ * customer and its user levels. `user_id` and `customer_id` cannot say which
696
+ * one a write belongs to, so on such a ladder the server refuses the write
697
+ * rather than guessing: a wrong guess at or above the customer level crosses
698
+ * a tenant boundary.
699
+ *
700
+ * Omit it and nothing changes. Sending one to an account without nested
701
+ * scoping is an error rather than ignored, because a caller who asks to be
702
+ * narrowed and is ignored gets widened instead.
703
+ */
704
+ scope?: Record<string, string> | null;
675
705
  }
676
706
  interface UpdateMemoryOptions {
677
707
  memory_id?: string;
@@ -1409,8 +1439,15 @@ declare class SynapClient {
1409
1439
  shutdown(): Promise<void>;
1410
1440
  }
1411
1441
 
1412
- /** Kept in sync with package.json by the release workflow. */
1413
- declare const SDK_VERSION = "1.0.0-beta.0";
1442
+ /**
1443
+ * Kept in sync with package.json by the release workflow, in the
1444
+ * "Sync SDK_VERSION to the resolved version" step of publish-npm-js-sdk.yml.
1445
+ *
1446
+ * Until that step existed nothing kept it in sync, so this constant sat at
1447
+ * 1.0.0-beta.0 while the package shipped 0.4.x, and every request's User-Agent
1448
+ * and every telemetry event reported a version that was never released.
1449
+ */
1450
+ declare const SDK_VERSION = "0.4.7";
1414
1451
 
1415
1452
  /**
1416
1453
  * Synap SDK error taxonomy.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as AnticipationCacheSnapshot } from './anticipation-cache-BMVF5sXb.js';
2
- export { b as ANY_SCOPE, A as AnticipationCache, c as AnticipationCacheOptions, B as BundleItem, C as ContextBundle, E as ExitReason, L as LookupParams, d as LookupResult, e as LookupTelemetry, S as SnapshotBundle, f as SnapshotItemPreview, g as SnapshotItemRecord } from './anticipation-cache-BMVF5sXb.js';
1
+ import { a as AnticipationCacheSnapshot } from './anticipation-cache-C1rUEpaW.js';
2
+ export { b as ANY_SCOPE, A as AnticipationCache, c as AnticipationCacheOptions, B as BundleItem, C as ContextBundle, E as ExitReason, L as LookupParams, d as LookupResult, e as LookupTelemetry, S as SnapshotBundle, f as SnapshotItemPreview, g as SnapshotItemRecord } from './anticipation-cache-C1rUEpaW.js';
3
3
 
4
4
  /**
5
5
  * AUTOGENERATED FROM synap/sdk/CONTRACT/endpoints.yaml -- DO NOT EDIT.
@@ -597,6 +597,21 @@ interface CreateMemoryOptions {
597
597
  documentCreatedAt?: string | Date | null;
598
598
  mode?: IngestMode | string;
599
599
  metadata?: Json;
600
+ /**
601
+ * The level this memory belongs to, named in full, one entry per level down
602
+ * to it: `{ customer: "acme", team: "payments", user: "dana" }`.
603
+ *
604
+ * Only needed by an account whose scope ladder has a level between its
605
+ * customer and its user levels. `user_id` and `customer_id` cannot say which
606
+ * one a write belongs to, so on such a ladder the server refuses the write
607
+ * rather than guessing: a wrong guess at or above the customer level crosses
608
+ * a tenant boundary.
609
+ *
610
+ * Omit it and nothing changes. Sending one to an account without nested
611
+ * scoping is an error rather than ignored, because a caller who asks to be
612
+ * narrowed and is ignored gets widened instead.
613
+ */
614
+ scope?: Record<string, string> | null;
600
615
  }
601
616
  /**
602
617
  * Mirrors Python's `CreateMemoryResponse`.
@@ -672,6 +687,21 @@ interface CreateFromFileOptions {
672
687
  documentType?: string;
673
688
  mode?: IngestMode | string;
674
689
  metadata?: Json;
690
+ /**
691
+ * The level this memory belongs to, named in full, one entry per level down
692
+ * to it: `{ customer: "acme", team: "payments", user: "dana" }`.
693
+ *
694
+ * Only needed by an account whose scope ladder has a level between its
695
+ * customer and its user levels. `user_id` and `customer_id` cannot say which
696
+ * one a write belongs to, so on such a ladder the server refuses the write
697
+ * rather than guessing: a wrong guess at or above the customer level crosses
698
+ * a tenant boundary.
699
+ *
700
+ * Omit it and nothing changes. Sending one to an account without nested
701
+ * scoping is an error rather than ignored, because a caller who asks to be
702
+ * narrowed and is ignored gets widened instead.
703
+ */
704
+ scope?: Record<string, string> | null;
675
705
  }
676
706
  interface UpdateMemoryOptions {
677
707
  memory_id?: string;
@@ -1409,8 +1439,15 @@ declare class SynapClient {
1409
1439
  shutdown(): Promise<void>;
1410
1440
  }
1411
1441
 
1412
- /** Kept in sync with package.json by the release workflow. */
1413
- declare const SDK_VERSION = "1.0.0-beta.0";
1442
+ /**
1443
+ * Kept in sync with package.json by the release workflow, in the
1444
+ * "Sync SDK_VERSION to the resolved version" step of publish-npm-js-sdk.yml.
1445
+ *
1446
+ * Until that step existed nothing kept it in sync, so this constant sat at
1447
+ * 1.0.0-beta.0 while the package shipped 0.4.x, and every request's User-Agent
1448
+ * and every telemetry event reported a version that was never released.
1449
+ */
1450
+ declare const SDK_VERSION = "0.4.7";
1414
1451
 
1415
1452
  /**
1416
1453
  * Synap SDK error taxonomy.
package/dist/index.js CHANGED
@@ -30,9 +30,10 @@ import {
30
30
  CONTRACT,
31
31
  THRESHOLDS,
32
32
  isRecallQuery,
33
+ rungKey,
33
34
  stem,
34
35
  tokenize
35
- } from "./chunk-6LDUDKHS.js";
36
+ } from "./chunk-ODVOQOSO.js";
36
37
  import {
37
38
  getEnv
38
39
  } from "./chunk-QBCVMPGK.js";
@@ -853,6 +854,10 @@ function buildCreateBody(options) {
853
854
  ),
854
855
  user_id: either(o2, "user_id", "userId") ?? null,
855
856
  customer_id: either(o2, "customer_id", "customerId") ?? null,
857
+ // null, never `{}`. An empty path is not absence: the server treats one as
858
+ // an error, because a caller asking to be narrowed and being ignored gets
859
+ // widened instead.
860
+ scope: options.scope ?? null,
856
861
  mode,
857
862
  metadata: options.metadata ?? {}
858
863
  };
@@ -1201,7 +1206,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1201
1206
  onFetched(
1202
1207
  response,
1203
1208
  id,
1204
- options.user_id ?? options.userId
1209
+ options.user_id ?? options.userId,
1210
+ options.scope_path ?? options.scopePath
1205
1211
  );
1206
1212
  return response;
1207
1213
  },
@@ -1396,7 +1402,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
1396
1402
  if (client !== null) {
1397
1403
  throw new ListeningAlreadyActiveError("Listening is already active on this instance");
1398
1404
  }
1399
- const { GrpcStreamClient } = await import("./stream-client-6V4FGKZ3.js");
1405
+ const { GrpcStreamClient } = await import("./stream-client-2C5KIOWP.js");
1400
1406
  const onContext = options.on_context ?? options.onContext;
1401
1407
  const onDisconnect = options.on_disconnect ?? options.onDisconnect;
1402
1408
  const onReconnect = options.on_reconnect ?? options.onReconnect;
@@ -1490,7 +1496,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
1490
1496
  }
1491
1497
 
1492
1498
  // src/version.ts
1493
- var SDK_VERSION = "1.0.0-beta.0";
1499
+ var SDK_VERSION = "0.4.7";
1494
1500
 
1495
1501
  // src/registry.ts
1496
1502
  var instances = /* @__PURE__ */ new Map();
@@ -1940,16 +1946,16 @@ function mergeUserSummary(response, bundle) {
1940
1946
 
1941
1947
  // src/context/anticipated.ts
1942
1948
  function scopeLookupParams(scope, params) {
1943
- const { searchQuery, entityId, customerId, clientId, conversationId } = params;
1949
+ const { searchQuery, entityId, customerId, clientId, conversationId, scopeRung } = params;
1944
1950
  switch (scope) {
1945
1951
  case "conversation":
1946
- return { searchQuery, entityId, customerId, clientId, conversationId };
1952
+ return { searchQuery, entityId, customerId, clientId, conversationId, scopeRung };
1947
1953
  case "user":
1948
- return { searchQuery, entityId, customerId, clientId };
1954
+ return { searchQuery, entityId, customerId, clientId, scopeRung };
1949
1955
  case "customer":
1950
- return { searchQuery, entityId: null, customerId, clientId };
1956
+ return { searchQuery, entityId: null, customerId, clientId, scopeRung };
1951
1957
  case "client":
1952
- return { searchQuery, entityId: null, customerId: null, clientId };
1958
+ return { searchQuery, entityId: null, customerId: null, clientId, scopeRung };
1953
1959
  }
1954
1960
  }
1955
1961
  function buildAnticipationResponse(hit) {
@@ -1984,6 +1990,7 @@ function tryServeFromCache(cache, scope, params, maxItems) {
1984
1990
  customerId: scoped.customerId ?? null,
1985
1991
  clientId: scoped.clientId ?? null,
1986
1992
  conversationId: scoped.conversationId ?? null,
1993
+ scopeRung: scoped.scopeRung ?? null,
1987
1994
  maxItems
1988
1995
  });
1989
1996
  if (hit === null) return { response: null, hit: null };
@@ -2496,7 +2503,15 @@ var SynapClient = class {
2496
2503
  entityId: o2["user_id"] ?? o2["userId"],
2497
2504
  customerId: o2["customer_id"] ?? o2["customerId"],
2498
2505
  clientId: this.#transport.currentCredentials().clientId || null,
2499
- conversationId: o2["conversation_id"] ?? o2["conversationId"]
2506
+ conversationId: o2["conversation_id"] ?? o2["conversationId"],
2507
+ // The rung this read is addressed to, in the same words the server
2508
+ // stamped on the bundles it pushed. Without it the cache matched
2509
+ // on entity and conversation alone, so a bundle prefetched for one
2510
+ // rung answered a caller standing at another, entirely inside this
2511
+ // process and invisible to every server log.
2512
+ scopeRung: rungKey(
2513
+ o2["scope_path"] ?? o2["scopePath"]
2514
+ )
2500
2515
  },
2501
2516
  Number(o2["max_results"] ?? o2["maxResults"] ?? 10)
2502
2517
  );
@@ -2541,9 +2556,9 @@ var SynapClient = class {
2541
2556
  ({ conversationId, role, content, timestamp }) => {
2542
2557
  this.#shortTerm.appendTurn(conversationId, role, content, timestamp);
2543
2558
  },
2544
- (response, conversationId, userId) => {
2559
+ (response, conversationId, userId, scopePath) => {
2545
2560
  overlayLocalRecentTurns(response, this.#shortTerm, conversationId, this.#stVerbatimOverlay);
2546
- this.#injectUserSummary(response, conversationId, userId);
2561
+ this.#injectUserSummary(response, conversationId, userId, rungKey(scopePath));
2547
2562
  },
2548
2563
  {
2549
2564
  prompt: (conversationId, style) => this.#localPrompt(conversationId, style),
@@ -2908,11 +2923,11 @@ var SynapClient = class {
2908
2923
  * cannot be scoped, and an unscoped lookup is how user A's summary ends up in
2909
2924
  * user B's response.
2910
2925
  */
2911
- #injectUserSummary(response, conversationId, userId) {
2926
+ #injectUserSummary(response, conversationId, userId, scopeRung) {
2912
2927
  this.#turns.increment(conversationId);
2913
2928
  if (userId === void 0 || userId === "") return;
2914
2929
  if (!this.#turns.shouldInject(conversationId)) return;
2915
- const summary = this.#anticipationCache.lookupUserSummary(userId);
2930
+ const summary = this.#anticipationCache.lookupUserSummary(userId, scopeRung);
2916
2931
  if (summary === null) return;
2917
2932
  mergeUserSummary(response, summary);
2918
2933
  }