@maximem/synap-js-sdk 0.5.1 → 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.d.cts CHANGED
@@ -501,6 +501,21 @@ interface FetchOptions {
501
501
  mode?: string;
502
502
  precision_level?: string;
503
503
  precisionLevel?: string;
504
+ /**
505
+ * The moment the question is being asked, so the server can resolve a period
506
+ * the question names ("in March", "two months ago") instead of counting back
507
+ * from now.
508
+ *
509
+ * Sent only when provided, like `precision_level`: the golden payloads in
510
+ * CONTRACT/conformance/request_payloads.json are byte-for-byte, so an
511
+ * always-present key would break every existing case.
512
+ *
513
+ * Lenient on the server: `"2023-03-11"`, `"2023/03/11 21:26"` and
514
+ * `"2023/03/11 (Sat) 21:26"` all parse, and anything unreadable falls back to
515
+ * now with a warning rather than failing the read.
516
+ */
517
+ query_date?: string;
518
+ queryDate?: string;
504
519
  /** Sent only when explicitly false, matching the Python controllers. */
505
520
  include_conversation_context?: boolean;
506
521
  /**
@@ -1367,6 +1382,8 @@ interface UnifiedFetchOptions {
1367
1382
  types?: string[];
1368
1383
  mode?: string;
1369
1384
  precision_level?: string;
1385
+ /** The moment the question is being asked. See FetchOptions.query_date. */
1386
+ query_date?: string;
1370
1387
  include_conversation_context?: boolean;
1371
1388
  scopes?: string[];
1372
1389
  include_scope_labels?: boolean;
@@ -1537,7 +1554,7 @@ declare class SynapClient {
1537
1554
  * build when the two disagree, which is the only thing that makes a manual
1538
1555
  * publish safe.
1539
1556
  */
1540
- declare const SDK_VERSION = "0.5.1";
1557
+ declare const SDK_VERSION = "0.5.4";
1541
1558
 
1542
1559
  /**
1543
1560
  * BM25 scorer for the anticipation cache.
package/dist/index.d.ts CHANGED
@@ -501,6 +501,21 @@ interface FetchOptions {
501
501
  mode?: string;
502
502
  precision_level?: string;
503
503
  precisionLevel?: string;
504
+ /**
505
+ * The moment the question is being asked, so the server can resolve a period
506
+ * the question names ("in March", "two months ago") instead of counting back
507
+ * from now.
508
+ *
509
+ * Sent only when provided, like `precision_level`: the golden payloads in
510
+ * CONTRACT/conformance/request_payloads.json are byte-for-byte, so an
511
+ * always-present key would break every existing case.
512
+ *
513
+ * Lenient on the server: `"2023-03-11"`, `"2023/03/11 21:26"` and
514
+ * `"2023/03/11 (Sat) 21:26"` all parse, and anything unreadable falls back to
515
+ * now with a warning rather than failing the read.
516
+ */
517
+ query_date?: string;
518
+ queryDate?: string;
504
519
  /** Sent only when explicitly false, matching the Python controllers. */
505
520
  include_conversation_context?: boolean;
506
521
  /**
@@ -1367,6 +1382,8 @@ interface UnifiedFetchOptions {
1367
1382
  types?: string[];
1368
1383
  mode?: string;
1369
1384
  precision_level?: string;
1385
+ /** The moment the question is being asked. See FetchOptions.query_date. */
1386
+ query_date?: string;
1370
1387
  include_conversation_context?: boolean;
1371
1388
  scopes?: string[];
1372
1389
  include_scope_labels?: boolean;
@@ -1537,7 +1554,7 @@ declare class SynapClient {
1537
1554
  * build when the two disagree, which is the only thing that makes a manual
1538
1555
  * publish safe.
1539
1556
  */
1540
- declare const SDK_VERSION = "0.5.1";
1557
+ declare const SDK_VERSION = "0.5.4";
1541
1558
 
1542
1559
  /**
1543
1560
  * BM25 scorer for the anticipation cache.
package/dist/index.js CHANGED
@@ -536,6 +536,7 @@ function buildFetchRequest(scope, options) {
536
536
  const searchQuery = opt(options, "search_query", "searchQuery");
537
537
  const maxResults = opt(options, "max_results", "maxResults") ?? 10;
538
538
  const precisionLevel = opt(options, "precision_level", "precisionLevel") ?? "high";
539
+ const queryDate = opt(options, "query_date", "queryDate");
539
540
  const mode = options.mode ?? "fast";
540
541
  if (searchQuery !== void 0 && !Array.isArray(searchQuery)) {
541
542
  throw new 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 {
1406
+ try {
1407
+ return String(value);
1408
+ } catch {
1409
+ return "";
1410
+ }
1411
+ }
1395
1412
  }
1396
1413
  function createInstanceNamespace(credentials, cache, onTurn) {
1397
1414
  let client = null;
@@ -1440,7 +1457,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
1440
1457
  if (client !== null) {
1441
1458
  throw new ListeningAlreadyActiveError("Listening is already active on this instance");
1442
1459
  }
1443
- const { GrpcStreamClient } = await import("./stream-client-6OWRYOA4.js");
1460
+ const { GrpcStreamClient } = await import("./stream-client-5CGJNTH4.js");
1444
1461
  const onContext = options.on_context ?? options.onContext;
1445
1462
  const onDisconnect = options.on_disconnect ?? options.onDisconnect;
1446
1463
  const onReconnect = options.on_reconnect ?? options.onReconnect;
@@ -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 = 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(options.tool_result ?? options.toolResult),
1544
1561
  tool_call_id: 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.1";
1632
+ var SDK_VERSION = "0.5.4";
1616
1633
 
1617
1634
  // src/registry.ts
1618
1635
  var instances = /* @__PURE__ */ new Map();
@@ -2611,6 +2628,7 @@ var SynapClient = class {
2611
2628
  this.#fetchHooks = {
2612
2629
  beforeFetch: (scope, options2) => {
2613
2630
  const o2 = options2;
2631
+ if (o2["query_date"] ?? o2["queryDate"]) return null;
2614
2632
  const attempt = tryServeFromCache(
2615
2633
  this.#anticipationCache,
2616
2634
  scope,
@@ -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 = [];