@maximem/synap-js-sdk 0.6.1 → 0.6.5

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/README.md +2 -2
  2. package/dist/anticipation-cache-Q7IYC3ID.cjs +26 -0
  3. package/dist/anticipation-cache-Q7IYC3ID.cjs.map +1 -0
  4. package/dist/{anticipation-cache-RWKF55J4.js → anticipation-cache-VL5WHTJB.js} +8 -2
  5. package/dist/{chunk-N55UBGER.js → chunk-4HD6KU3D.js} +46 -3
  6. package/dist/chunk-4HD6KU3D.js.map +1 -0
  7. package/dist/chunk-7IZHVYO2.cjs.map +1 -1
  8. package/dist/{chunk-ICUFS3B5.cjs → chunk-BYUGILQI.cjs} +136 -142
  9. package/dist/chunk-BYUGILQI.cjs.map +1 -0
  10. package/dist/{chunk-R72YL6Q4.js → chunk-CSG3N5E3.js} +136 -142
  11. package/dist/chunk-CSG3N5E3.js.map +1 -0
  12. package/dist/{chunk-2VJV4HCF.cjs → chunk-IZUIPREP.cjs} +59 -16
  13. package/dist/chunk-IZUIPREP.cjs.map +1 -0
  14. package/dist/chunk-ZKOJDUN4.cjs.map +1 -1
  15. package/dist/env-55ULHNJZ.cjs.map +1 -1
  16. package/dist/{errors-DWjdpExq.d.cts → errors-x5bpgxmC.d.cts} +18 -3
  17. package/dist/{errors-DWjdpExq.d.ts → errors-x5bpgxmC.d.ts} +18 -3
  18. package/dist/grpc/index.cjs +4 -4
  19. package/dist/grpc/index.cjs.map +1 -1
  20. package/dist/grpc/index.d.cts +11 -3
  21. package/dist/grpc/index.d.ts +11 -3
  22. package/dist/grpc/index.js +3 -3
  23. package/dist/index.cjs +283 -56
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +85 -17
  26. package/dist/index.d.ts +85 -17
  27. package/dist/index.js +252 -25
  28. package/dist/index.js.map +1 -1
  29. package/dist/onnx-encoder-4RSL6ID4.cjs.map +1 -1
  30. package/dist/{stream-client-GRDVRBFA.js → stream-client-7YONF2GD.js} +2 -2
  31. package/dist/stream-client-IPHDTXQO.cjs +22 -0
  32. package/dist/stream-client-IPHDTXQO.cjs.map +1 -0
  33. package/package.json +1 -1
  34. package/dist/anticipation-cache-LPNKMRBH.cjs +0 -20
  35. package/dist/anticipation-cache-LPNKMRBH.cjs.map +0 -1
  36. package/dist/chunk-2VJV4HCF.cjs.map +0 -1
  37. package/dist/chunk-ICUFS3B5.cjs.map +0 -1
  38. package/dist/chunk-N55UBGER.js.map +0 -1
  39. package/dist/chunk-R72YL6Q4.js.map +0 -1
  40. package/dist/stream-client-SZIYGVVJ.cjs +0 -22
  41. package/dist/stream-client-SZIYGVVJ.cjs.map +0 -1
  42. /package/dist/{anticipation-cache-RWKF55J4.js.map → anticipation-cache-VL5WHTJB.js.map} +0 -0
  43. /package/dist/{stream-client-GRDVRBFA.js.map → stream-client-7YONF2GD.js.map} +0 -0
package/dist/index.js CHANGED
@@ -6,11 +6,10 @@ import {
6
6
  HISTORY_SEARCH,
7
7
  SEMANTIC_MATCH,
8
8
  THRESHOLDS,
9
- isRecallQuery,
10
9
  rungKey,
11
10
  stem,
12
11
  tokenize
13
- } from "./chunk-R72YL6Q4.js";
12
+ } from "./chunk-CSG3N5E3.js";
14
13
  import {
15
14
  getEnv
16
15
  } from "./chunk-QBCVMPGK.js";
@@ -55,6 +54,8 @@ var ENDPOINTS = {
55
54
  memories_update: { method: "PATCH", path: "/api/v1/memories/{memory_id}", idempotent: false },
56
55
  memories_delete: { method: "DELETE", path: "/api/v1/memories/{memory_id}", idempotent: true },
57
56
  memories_forget: { method: "POST", path: "/api/v1/memories/forget", idempotent: false },
57
+ data_delete: { method: "POST", path: "/v1/data/delete", idempotent: true },
58
+ data_delete_status: { method: "GET", path: "/v1/data/delete/{deletion_id}", idempotent: true },
58
59
  context_fetch_user: { method: "POST", path: "/v1/context/user/fetch", idempotent: true },
59
60
  context_fetch_customer: { method: "POST", path: "/v1/context/customer/fetch", idempotent: true },
60
61
  context_fetch_client: { method: "POST", path: "/v1/context/client/fetch", idempotent: true },
@@ -387,7 +388,7 @@ var HttpTransport = class {
387
388
  if (gated) this.cooldownCheck(cooldownKey, correlationId);
388
389
  let attempt = 0;
389
390
  let last = null;
390
- while (attempt < this.retryPolicy.maxAttempts) {
391
+ while (attempt < Math.max(1, this.retryPolicy.maxAttempts)) {
391
392
  attempt += 1;
392
393
  try {
393
394
  const result = await this.attempt(name, options, correlationId);
@@ -740,6 +741,41 @@ function sortByRankScore(items) {
740
741
  return [...items].sort(byRankScore);
741
742
  }
742
743
 
744
+ // src/context/no-query.ts
745
+ var MEMORY_TYPES2 = ["facts", "preferences", "episodes", "emotions", "temporal_events"];
746
+ var emptyLists = () => Object.fromEntries(MEMORY_TYPES2.map((t) => [t, []]));
747
+ function hasQuery(searchQuery) {
748
+ if (typeof searchQuery === "string") return searchQuery.trim() !== "";
749
+ if (!Array.isArray(searchQuery)) return false;
750
+ return searchQuery.some((q) => typeof q === "string" && q.trim() !== "");
751
+ }
752
+ function conversationStateContext(prompt, conversationId) {
753
+ const recent = Array.isArray(prompt["recent_messages"]) ? prompt["recent_messages"] : [];
754
+ const turns = recent.filter((m) => typeof m === "object" && m !== null && !Array.isArray(m)).map((m) => ({ role: m["role"] ?? null, content: m["content"] ?? null, timestamp: m["timestamp"] ?? null }));
755
+ return {
756
+ ...emptyLists(),
757
+ conversation_context: {
758
+ conversation_id: conversationId,
759
+ summary: prompt["context_block"] || null,
760
+ recent_turns: turns,
761
+ compaction_id: prompt["compaction_id"] || null,
762
+ formatted_context: prompt["formatted_context"] || null
763
+ }
764
+ };
765
+ }
766
+ function profileContext(profile) {
767
+ if (typeof profile !== "object" || profile === null || Array.isArray(profile)) return null;
768
+ let doc = profile;
769
+ const inner = doc["profile"];
770
+ if (!("attributes" in doc) && typeof inner === "object" && inner !== null && !Array.isArray(inner)) {
771
+ doc = inner;
772
+ }
773
+ const attributes = doc["attributes"];
774
+ const hasAttributes = typeof attributes === "object" && attributes !== null && Object.keys(attributes).length > 0;
775
+ if (!hasAttributes && !doc["overview"]) return null;
776
+ return { ...emptyLists(), profile: doc };
777
+ }
778
+
743
779
  // src/context/fetch.ts
744
780
  var ENDPOINT_BY_SCOPE = {
745
781
  user: "context_fetch_user",
@@ -867,6 +903,12 @@ function retrievalOptionsOf(options) {
867
903
  }
868
904
  return { mode, precisionLevel };
869
905
  }
906
+ function validateSearchQuery(searchQuery) {
907
+ if (searchQuery === void 0 || searchQuery === null) return;
908
+ if (!Array.isArray(searchQuery) || searchQuery.some((query) => typeof query !== "string")) {
909
+ throw new InvalidInputError("search_query must be an array of strings when provided");
910
+ }
911
+ }
870
912
  async function fetchContext(transport, scope, options = {}, hooks = {}) {
871
913
  const startedAt = Date.now();
872
914
  await transport.ready?.();
@@ -877,7 +919,13 @@ async function fetchContext(transport, scope, options = {}, hooks = {}) {
877
919
  const responseShape = responseShapeOf(options);
878
920
  retrievalOptionsOf(options);
879
921
  const { contextMode } = scopeOptionsOf(scope, options);
922
+ const searchQuery = opt(options, "search_query", "searchQuery");
923
+ validateSearchQuery(searchQuery);
880
924
  const summaryMode = scope === "user" && contextMode === "conversation-summary";
925
+ if (!summaryMode && hooks.withoutQuery && !hasQuery(searchQuery)) {
926
+ const answer = await hooks.withoutQuery(scope, options);
927
+ if (answer !== null) return applyResponseShape(answer, responseShape);
928
+ }
881
929
  const finish = (response2) => {
882
930
  hooks.onResponse?.(scope, options, response2);
883
931
  return response2;
@@ -1770,6 +1818,138 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1770
1818
  };
1771
1819
  }
1772
1820
 
1821
+ // src/data/interface.ts
1822
+ var DATA_SCOPES = ["user", "conversation", "customer"];
1823
+ var MAX_WAIT_CALLS = 50;
1824
+ var ID_FIELD = {
1825
+ user: "user_id",
1826
+ customer: "customer_id",
1827
+ conversation: "conversation_id"
1828
+ };
1829
+ function either3(o2, snake, camel) {
1830
+ const a = o2[snake];
1831
+ if (a !== void 0) return a;
1832
+ const b = o2[camel];
1833
+ return b === void 0 ? void 0 : b;
1834
+ }
1835
+ function buildDeleteBody(options, instanceId) {
1836
+ const o2 = options;
1837
+ const scope = options.scope;
1838
+ if (scope !== null && typeof scope === "object") {
1839
+ throw new InvalidInputError(
1840
+ "scope must be one of: user, conversation, customer. A dict is not accepted here (the rung-path dict used by memories.create and fetch is a different parameter)."
1841
+ );
1842
+ }
1843
+ if (typeof scope !== "string" || !DATA_SCOPES.includes(scope)) {
1844
+ throw new InvalidInputError(
1845
+ `Invalid scope '${String(scope)}'. Expected one of: ${DATA_SCOPES.join(", ")}`
1846
+ );
1847
+ }
1848
+ const dryRun = either3(o2, "dry_run", "dryRun") ?? false;
1849
+ if (typeof dryRun !== "boolean") throw new InvalidInputError("dry_run must be a boolean");
1850
+ const ids = {
1851
+ user_id: either3(o2, "user_id", "userId"),
1852
+ customer_id: either3(o2, "customer_id", "customerId"),
1853
+ conversation_id: either3(o2, "conversation_id", "conversationId")
1854
+ };
1855
+ for (const [name, value] of Object.entries(ids)) {
1856
+ if (value !== void 0 && value !== null && (typeof value !== "string" || value.trim() === "")) {
1857
+ throw new InvalidInputError(`${name} must not be empty`);
1858
+ }
1859
+ }
1860
+ const field = ID_FIELD[scope];
1861
+ const target = ids[field];
1862
+ if (target === void 0 || target === null) {
1863
+ throw new InvalidInputError(`${field} is required for scope='${scope}'`);
1864
+ }
1865
+ const confirm = options.confirm ?? null;
1866
+ if (!dryRun) {
1867
+ if (confirm === null || confirm === "") {
1868
+ throw new InvalidInputError(
1869
+ `confirm is required unless dry_run=True: pass the ${field} being deleted as confirm`
1870
+ );
1871
+ }
1872
+ if (confirm !== target) {
1873
+ throw new InvalidInputError(`confirm must equal the ${field} being deleted`);
1874
+ }
1875
+ }
1876
+ return {
1877
+ scope,
1878
+ instance_id: instanceId,
1879
+ user_id: ids["user_id"] ?? null,
1880
+ customer_id: ids["customer_id"] ?? null,
1881
+ conversation_id: ids["conversation_id"] ?? null,
1882
+ dry_run: dryRun,
1883
+ confirm
1884
+ };
1885
+ }
1886
+ function normalise(raw) {
1887
+ return {
1888
+ deletion_id: null,
1889
+ status: "unknown",
1890
+ scope: null,
1891
+ dry_run: false,
1892
+ found: false,
1893
+ counts: {},
1894
+ stores: {},
1895
+ still_present_in: [],
1896
+ // Pessimistic: true only when the server said so.
1897
+ fully_removed: false,
1898
+ continue: false,
1899
+ kept: [],
1900
+ note: null,
1901
+ memories_kept: false,
1902
+ audit: null,
1903
+ local_cleared: [],
1904
+ ...raw
1905
+ };
1906
+ }
1907
+ function createDataInterface(transport, onDeleted) {
1908
+ return {
1909
+ async delete(options) {
1910
+ const o2 = options;
1911
+ await transport.checkCustomerId(
1912
+ either3(o2, "customer_id", "customerId"),
1913
+ "data.delete"
1914
+ );
1915
+ const body = buildDeleteBody(options, transport.currentCredentials().instanceId);
1916
+ const dryRun = body["dry_run"] === true;
1917
+ const wait = options.wait ?? true;
1918
+ let result = null;
1919
+ for (let i = 0; i < (wait ? MAX_WAIT_CALLS : 1); i += 1) {
1920
+ result = normalise(
1921
+ await transport.request("data_delete", { body })
1922
+ );
1923
+ if (dryRun || !result.continue) break;
1924
+ }
1925
+ const final = result;
1926
+ if (!dryRun && ["complete", "partial", "in_progress"].includes(final.status) && onDeleted) {
1927
+ try {
1928
+ final.local_cleared = onDeleted({
1929
+ scope: body["scope"],
1930
+ userId: body["user_id"] ?? null,
1931
+ customerId: body["customer_id"] ?? null,
1932
+ conversationId: body["conversation_id"] ?? null
1933
+ });
1934
+ } catch {
1935
+ }
1936
+ }
1937
+ return final;
1938
+ },
1939
+ async status(deletionId) {
1940
+ if (typeof deletionId !== "string" || deletionId.trim() === "") {
1941
+ throw new InvalidInputError("deletion_id is required");
1942
+ }
1943
+ return normalise(
1944
+ await transport.request("data_delete_status", {
1945
+ pathParams: { deletion_id: deletionId },
1946
+ query: { instance_id: transport.currentCredentials().instanceId }
1947
+ })
1948
+ );
1949
+ }
1950
+ };
1951
+ }
1952
+
1773
1953
  // src/user/interface.ts
1774
1954
  function createUserNamespace(transport, hooks = {}) {
1775
1955
  return {
@@ -1962,7 +2142,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1962
2142
  onListen?.();
1963
2143
  } catch {
1964
2144
  }
1965
- const { GrpcStreamClient } = await import("./stream-client-GRDVRBFA.js");
2145
+ const { GrpcStreamClient } = await import("./stream-client-7YONF2GD.js");
1966
2146
  const onContext = options.on_context ?? options.onContext;
1967
2147
  const onDisconnect = options.on_disconnect ?? options.onDisconnect;
1968
2148
  const onReconnect = options.on_reconnect ?? options.onReconnect;
@@ -2151,7 +2331,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
2151
2331
  }
2152
2332
 
2153
2333
  // src/version.ts
2154
- var SDK_VERSION = "0.6.1";
2334
+ var SDK_VERSION = "0.6.5";
2155
2335
 
2156
2336
  // src/registry.ts
2157
2337
  var instances = /* @__PURE__ */ new Map();
@@ -3283,7 +3463,7 @@ function pick2(item, ...names) {
3283
3463
  }
3284
3464
  return void 0;
3285
3465
  }
3286
- function normalise(item) {
3466
+ function normalise2(item) {
3287
3467
  const content = pick2(item, "content") ?? "";
3288
3468
  const confidence = pick2(item, "confidence") ?? 0;
3289
3469
  const extractedAt = pick2(item, "extracted_at", "created_at") ?? null;
@@ -3318,7 +3498,7 @@ function mergeUserSummary(response, bundle) {
3318
3498
  if (!Array.isArray(items)) continue;
3319
3499
  const existing = response[collection] ?? [];
3320
3500
  const existingIds = new Set(existing.map((i) => String(i.id ?? i.item_id ?? "")));
3321
- const fresh = items.filter((i) => typeof i === "object" && i !== null && !existingIds.has(itemId(i))).slice(0, MAX_SUMMARY_ITEMS).map(normalise);
3501
+ const fresh = items.filter((i) => typeof i === "object" && i !== null && !existingIds.has(itemId(i))).slice(0, MAX_SUMMARY_ITEMS).map(normalise2);
3322
3502
  if (fresh.length === 0) continue;
3323
3503
  response[collection] = [...existing, ...fresh];
3324
3504
  }
@@ -3327,16 +3507,16 @@ function mergeUserSummary(response, bundle) {
3327
3507
 
3328
3508
  // src/context/anticipated.ts
3329
3509
  function scopeLookupParams(scope, params) {
3330
- const { searchQuery, entityId, customerId, clientId, conversationId, scopeRung } = params;
3510
+ const { searchQuery, entityId, customerId, clientId, conversationId, scopeRung, maxResultsPerQuery } = params;
3331
3511
  switch (scope) {
3332
3512
  case "conversation":
3333
- return { searchQuery, entityId, customerId, clientId, conversationId, scopeRung };
3513
+ return { searchQuery, entityId, customerId, clientId, conversationId, scopeRung, maxResultsPerQuery };
3334
3514
  case "user":
3335
- return { searchQuery, entityId, customerId, clientId, scopeRung };
3515
+ return { searchQuery, entityId, customerId, clientId, scopeRung, maxResultsPerQuery };
3336
3516
  case "customer":
3337
- return { searchQuery, entityId: null, customerId, clientId, scopeRung };
3517
+ return { searchQuery, entityId: null, customerId, clientId, scopeRung, maxResultsPerQuery };
3338
3518
  case "client":
3339
- return { searchQuery, entityId: null, customerId: null, clientId, scopeRung };
3519
+ return { searchQuery, entityId: null, customerId: null, clientId, scopeRung, maxResultsPerQuery };
3340
3520
  }
3341
3521
  }
3342
3522
  function buildAnticipationResponse(hit) {
@@ -3372,7 +3552,8 @@ async function tryServeFromCache(cache, scope, params, maxItems) {
3372
3552
  clientId: scoped.clientId ?? null,
3373
3553
  conversationId: scoped.conversationId ?? null,
3374
3554
  scopeRung: scoped.scopeRung ?? null,
3375
- maxItems
3555
+ maxItems,
3556
+ maxResultsPerQuery: scoped.maxResultsPerQuery ?? null
3376
3557
  });
3377
3558
  if (hit === null) return { response: null, hit: null };
3378
3559
  return { response: buildAnticipationResponse(hit), hit };
@@ -3872,6 +4053,7 @@ var SynapClient = class _SynapClient {
3872
4053
  client;
3873
4054
  conversation;
3874
4055
  memories;
4056
+ data;
3875
4057
  credits;
3876
4058
  cache;
3877
4059
  instance;
@@ -3934,7 +4116,6 @@ var SynapClient = class _SynapClient {
3934
4116
  beforeFetch: async (scope, options2) => {
3935
4117
  const o2 = options2;
3936
4118
  if (o2["query_date"] ?? o2["queryDate"]) return null;
3937
- if (o2["max_results_per_query"] ?? o2["maxResultsPerQuery"]) return null;
3938
4119
  const attempt = await tryServeFromCache(
3939
4120
  this.#anticipationCache,
3940
4121
  scope,
@@ -3951,7 +4132,8 @@ var SynapClient = class _SynapClient {
3951
4132
  // process and invisible to every server log.
3952
4133
  scopeRung: rungKey(
3953
4134
  o2["scope_path"] ?? o2["scopePath"]
3954
- )
4135
+ ),
4136
+ maxResultsPerQuery: o2["max_results_per_query"] ?? o2["maxResultsPerQuery"] ?? null
3955
4137
  },
3956
4138
  Number(o2["max_results"] ?? o2["maxResults"] ?? 10)
3957
4139
  );
@@ -3977,6 +4159,30 @@ var SynapClient = class _SynapClient {
3977
4159
  // Python's `_should_skip_server_st`: when this process already holds the
3978
4160
  // conversation's compaction and every turn after it, the server is told
3979
4161
  // not to assemble them again.
4162
+ // A fetch with no query, as Python answers it inside the two scoped
4163
+ // fetches: the conversation's state, or the user's profile when there
4164
+ // is one. A profile read that fails falls back to the fetch as before.
4165
+ withoutQuery: async (scope, options2) => {
4166
+ const o2 = options2;
4167
+ if (scope === "conversation") {
4168
+ const id = o2["conversation_id"] ?? o2["conversationId"];
4169
+ const prompt = await this.conversation.context.get_context_for_prompt({ conversation_id: id });
4170
+ return conversationStateContext(prompt, id);
4171
+ }
4172
+ if (scope === "user") {
4173
+ try {
4174
+ const customerId = o2["customer_id"] ?? o2["customerId"];
4175
+ const profile = await this.user.get_profile({
4176
+ user_id: o2["user_id"] ?? o2["userId"],
4177
+ ...customerId !== void 0 ? { customer_id: customerId } : {}
4178
+ });
4179
+ return profileContext(profile);
4180
+ } catch {
4181
+ return null;
4182
+ }
4183
+ }
4184
+ return null;
4185
+ },
3980
4186
  skipServerShortTerm: (conversationId) => {
3981
4187
  if (!this.#isStAuthoritative()) return false;
3982
4188
  const entry = this.#shortTerm.get(conversationId);
@@ -4057,6 +4263,22 @@ var SynapClient = class _SynapClient {
4057
4263
  if (id) this.#anticipationCache.dropEntity(id);
4058
4264
  }
4059
4265
  });
4266
+ this.data = createDataInterface(this.#transport, ({ scope, userId, customerId, conversationId }) => {
4267
+ const cleared = [];
4268
+ if (scope === "conversation") {
4269
+ if (conversationId) {
4270
+ this.#shortTerm.invalidate(conversationId);
4271
+ this.#turnStore.drop(conversationId);
4272
+ cleared.push("short_term_context", "turns");
4273
+ }
4274
+ } else {
4275
+ for (const id of new Set(scope === "user" ? [userId, customerId] : [customerId])) {
4276
+ if (id) this.#anticipationCache.dropEntity(id);
4277
+ }
4278
+ cleared.push("anticipation_cache");
4279
+ }
4280
+ return cleared;
4281
+ });
4060
4282
  this.credits = createCreditsNamespace(this.#transport);
4061
4283
  this.cache = createCacheNamespace(this.#anticipationCache);
4062
4284
  this.instance = createInstanceNamespace(
@@ -4312,7 +4534,9 @@ var SynapClient = class _SynapClient {
4312
4534
  const labels = [];
4313
4535
  const tasks = [];
4314
4536
  const present = (v) => v !== void 0 && v !== null && v !== "";
4315
- if (present(conversationId) && wants("conversation")) {
4537
+ const conversationState = present(conversationId) && contextMode !== "conversation-summary" && !hasQuery(searchQuery) && wants("conversation");
4538
+ const withConversationContext = includeConversationContext;
4539
+ if (present(conversationId) && wants("conversation") && !conversationState) {
4316
4540
  labels.push("conversation");
4317
4541
  tasks.push(this.conversation.context.fetch({
4318
4542
  conversation_id: conversationId,
@@ -4348,7 +4572,7 @@ var SynapClient = class _SynapClient {
4348
4572
  ...shared
4349
4573
  }));
4350
4574
  }
4351
- if (tasks.length === 0) {
4575
+ if (tasks.length === 0 && !(conversationState && includeConversationContext)) {
4352
4576
  const empty = mergeScopeResults([]);
4353
4577
  return empty;
4354
4578
  }
@@ -4367,17 +4591,20 @@ var SynapClient = class _SynapClient {
4367
4591
  for (const [, response] of successful) {
4368
4592
  overlayLocalRecentTurns(response, this.#shortTerm, conversationId, this.#stVerbatimOverlay);
4369
4593
  }
4370
- if (includeConversationContext && present(conversationId)) {
4594
+ if (withConversationContext && present(conversationId)) {
4371
4595
  try {
4372
4596
  merged.conversation_context = await this.conversation.context.get_context_for_prompt({
4373
4597
  conversation_id: conversationId
4374
4598
  });
4599
+ if (conversationState && !merged.scopes_queried.includes("conversation")) {
4600
+ merged.scopes_queried.unshift("conversation");
4601
+ }
4375
4602
  } catch {
4376
4603
  }
4377
4604
  }
4378
4605
  merged.formatted_context = formatForPrompt(merged, {
4379
4606
  includeScope: includeScopeLabels,
4380
- includeConversationContext
4607
+ includeConversationContext: withConversationContext
4381
4608
  });
4382
4609
  return merged;
4383
4610
  }
@@ -4402,13 +4629,13 @@ var SynapClient = class _SynapClient {
4402
4629
  /**
4403
4630
  * Report a locally served fetch back to the server.
4404
4631
  *
4405
- * Only while listening: the event rides the Listen stream, and there is
4406
- * nowhere to put it otherwise. Never throws, because a telemetry failure
4407
- * must not fail a retrieval that already succeeded.
4632
+ * It rides the Listen stream. While the stream is reconnecting the stream
4633
+ * client holds it and sends it on reconnect: a hit never reaches a fetch
4634
+ * route, so this report is the only count of it. Never throws, because a
4635
+ * telemetry failure must not fail a retrieval that already succeeded.
4408
4636
  */
4409
4637
  #emitContextUsed(options, scope, served) {
4410
4638
  try {
4411
- if (!this.instance.is_listening) return;
4412
4639
  this.instance._internal.sendContextUsed({
4413
4640
  bundle_id: served.bundleId,
4414
4641
  conversation_id: String(options["conversation_id"] ?? options["conversationId"] ?? ""),
@@ -4665,7 +4892,7 @@ function resolveBaseUrl(options) {
4665
4892
  return fromEnv !== void 0 && fromEnv !== "" ? fromEnv : void 0;
4666
4893
  }
4667
4894
  function resolveCredentials(options) {
4668
- const apiKey = options.apiKey ?? getEnv("SYNAP_API_KEY");
4895
+ const apiKey = options.apiKey || getEnv("SYNAP_API_KEY");
4669
4896
  if (!apiKey) {
4670
4897
  throw new AuthenticationError(
4671
4898
  "No Synap API key found. Set SYNAP_API_KEY in your environment, or pass apiKey to the SynapClient constructor."
@@ -4689,6 +4916,7 @@ export {
4689
4916
  ConnectionError,
4690
4917
  ContextNotFoundError,
4691
4918
  CustomerIdNotAcceptedError,
4919
+ DATA_SCOPES,
4692
4920
  DEFAULT_BASE_URL,
4693
4921
  DEFAULT_DOCUMENT_TYPE,
4694
4922
  DEFAULT_INGEST_MODE,
@@ -4729,7 +4957,6 @@ export {
4729
4957
  flattenContextItems,
4730
4958
  formatForPrompt,
4731
4959
  isOutcomeUnknown,
4732
- isRecallQuery,
4733
4960
  isSynapError,
4734
4961
  mergeScopeResults,
4735
4962
  rankItems,