@maximem/synap-js-sdk 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -536,6 +536,7 @@ function buildFetchRequest(scope, options) {
536
536
  const searchQuery = opt(options, "search_query", "searchQuery");
537
537
  const maxResults = _nullishCoalesce(opt(options, "max_results", "maxResults"), () => ( 10));
538
538
  const precisionLevel = _nullishCoalesce(opt(options, "precision_level", "precisionLevel"), () => ( "high"));
539
+ const queryDate = opt(options, "query_date", "queryDate");
539
540
  const mode = _nullishCoalesce(options.mode, () => ( "fast"));
540
541
  if (searchQuery !== void 0 && !Array.isArray(searchQuery)) {
541
542
  throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("search_query must be an array when provided");
@@ -551,6 +552,7 @@ function buildFetchRequest(scope, options) {
551
552
  mode
552
553
  };
553
554
  if (precisionLevel !== "high") body["precision_level"] = precisionLevel;
555
+ if (queryDate) body["query_date"] = queryDate;
554
556
  if (options.include_conversation_context === false) {
555
557
  body["include_conversation_context"] = false;
556
558
  }
@@ -1391,7 +1393,22 @@ var KNOWN_EVENT_TYPES = /* @__PURE__ */ new Set([
1391
1393
  ]);
1392
1394
  function toolResultJson(result) {
1393
1395
  if (result === void 0 || result === null) return "";
1394
- return typeof result === "string" ? result : JSON.stringify(result);
1396
+ return typeof result === "string" ? result : jsonOrText(result);
1397
+ }
1398
+ function jsonOrText(value) {
1399
+ try {
1400
+ const out = JSON.stringify(
1401
+ value,
1402
+ (_k, v) => typeof v === "bigint" ? String(v) : v
1403
+ );
1404
+ return out === void 0 ? String(value) : out;
1405
+ } catch (e5) {
1406
+ try {
1407
+ return String(value);
1408
+ } catch (e6) {
1409
+ return "";
1410
+ }
1411
+ }
1395
1412
  }
1396
1413
  function createInstanceNamespace(credentials, cache, onTurn) {
1397
1414
  let client = null;
@@ -1432,7 +1449,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
1432
1449
  ...customerId ? { customer_id: customerId } : {}
1433
1450
  });
1434
1451
  openSessions.set(conversationId, sessionId);
1435
- } catch (e5) {
1452
+ } catch (e7) {
1436
1453
  }
1437
1454
  }
1438
1455
  const namespace = {
@@ -1497,7 +1514,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
1497
1514
  session_id: sessionId,
1498
1515
  conversation_id: conversationId
1499
1516
  });
1500
- } catch (e6) {
1517
+ } catch (e8) {
1501
1518
  }
1502
1519
  },
1503
1520
  async send_message(options) {
@@ -1538,7 +1555,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
1538
1555
  // Python serialises tool_args with json.dumps into tool_args_json.
1539
1556
  tool_args_json: (() => {
1540
1557
  const a = _nullishCoalesce(options.tool_args, () => ( options.toolArgs));
1541
- return a === void 0 ? "" : JSON.stringify(a);
1558
+ return a === void 0 ? "" : jsonOrText(a);
1542
1559
  })(),
1543
1560
  tool_result_json: toolResultJson(_nullishCoalesce(options.tool_result, () => ( options.toolResult))),
1544
1561
  tool_call_id: _nullishCoalesce(_nullishCoalesce(options.tool_call_id, () => ( options.toolCallId)), () => ( "")),
@@ -1612,7 +1629,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
1612
1629
  }
1613
1630
 
1614
1631
  // src/version.ts
1615
- var SDK_VERSION = "0.5.2";
1632
+ var SDK_VERSION = "0.5.4";
1616
1633
 
1617
1634
  // src/registry.ts
1618
1635
  var instances = /* @__PURE__ */ new Map();
@@ -1824,7 +1841,7 @@ function overlayLocalRecentTurns(response, store, conversationId, configured) {
1824
1841
  compacted_at: orLocal("compacted_at", entry.compactedAt),
1825
1842
  conversation_id: conversationId
1826
1843
  };
1827
- } catch (e7) {
1844
+ } catch (e9) {
1828
1845
  }
1829
1846
  }
1830
1847
 
@@ -1837,7 +1854,7 @@ function stringify(value) {
1837
1854
  if (t === "string" || t === "number" || t === "boolean") return String(value);
1838
1855
  try {
1839
1856
  return _nullishCoalesce(JSON.stringify(value), () => ( ""));
1840
- } catch (e8) {
1857
+ } catch (e10) {
1841
1858
  return String(value);
1842
1859
  }
1843
1860
  }
@@ -2111,7 +2128,7 @@ function tryServeFromCache(cache, scope, params, maxItems) {
2111
2128
  });
2112
2129
  if (hit === null) return { response: null, hit: null };
2113
2130
  return { response: buildAnticipationResponse(hit), hit };
2114
- } catch (e9) {
2131
+ } catch (e11) {
2115
2132
  return { response: null, hit: null };
2116
2133
  }
2117
2134
  }
@@ -2611,6 +2628,7 @@ var SynapClient = class {
2611
2628
  this.#fetchHooks = {
2612
2629
  beforeFetch: (scope, options2) => {
2613
2630
  const o2 = options2;
2631
+ if (_nullishCoalesce(o2["query_date"], () => ( o2["queryDate"]))) return null;
2614
2632
  const attempt = tryServeFromCache(
2615
2633
  this.#anticipationCache,
2616
2634
  scope,
@@ -2811,7 +2829,7 @@ var SynapClient = class {
2811
2829
  this.#registryKeys.push(resolvedInstanceId);
2812
2830
  }
2813
2831
  }
2814
- } catch (e10) {
2832
+ } catch (e12) {
2815
2833
  }
2816
2834
  }
2817
2835
  /**
@@ -2879,6 +2897,7 @@ var SynapClient = class {
2879
2897
  types,
2880
2898
  mode = "fast",
2881
2899
  precision_level: precisionLevel = "high",
2900
+ query_date: queryDate,
2882
2901
  include_conversation_context: includeConversationContext = true,
2883
2902
  scopes,
2884
2903
  include_scope_labels: includeScopeLabels = false,
@@ -2893,7 +2912,11 @@ var SynapClient = class {
2893
2912
  max_results: maxResults,
2894
2913
  types,
2895
2914
  mode,
2896
- precision_level: precisionLevel
2915
+ precision_level: precisionLevel,
2916
+ // In `shared` so it reaches all four branches at once. The Python edit
2917
+ // threaded three call sites by hand and missed the client branch, which
2918
+ // sits one indent deeper; spreading removes that whole class of miss.
2919
+ query_date: queryDate
2897
2920
  };
2898
2921
  const labels = [];
2899
2922
  const tasks = [];
@@ -2958,7 +2981,7 @@ var SynapClient = class {
2958
2981
  merged.conversation_context = await this.conversation.context.get_context_for_prompt({
2959
2982
  conversation_id: conversationId
2960
2983
  });
2961
- } catch (e11) {
2984
+ } catch (e13) {
2962
2985
  }
2963
2986
  }
2964
2987
  merged.formatted_context = formatForPrompt(merged, {
@@ -3005,7 +3028,7 @@ var SynapClient = class {
3005
3028
  source_bundle_ids: served.bundleId ? [served.bundleId] : [],
3006
3029
  timestamp_ms: Date.now()
3007
3030
  });
3008
- } catch (e12) {
3031
+ } catch (e14) {
3009
3032
  }
3010
3033
  }
3011
3034
  /**
@@ -3030,7 +3053,7 @@ var SynapClient = class {
3030
3053
  }),
3031
3054
  scope
3032
3055
  });
3033
- } catch (e13) {
3056
+ } catch (e15) {
3034
3057
  }
3035
3058
  }
3036
3059
  /**