@maximem/synap-js-sdk 0.5.16 → 0.5.18

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  GrpcStreamClient,
3
3
  PROTO_SHA
4
- } from "../chunk-LJ66WCV3.js";
4
+ } from "../chunk-5G3FNDB3.js";
5
5
  import {
6
6
  ListeningNotActiveError
7
7
  } from "../chunk-4GE7SORD.js";
@@ -39,7 +39,7 @@ async function listen(options) {
39
39
  throw new ListeningNotActiveError(availability.detail);
40
40
  }
41
41
  const [{ GrpcStreamClient: StreamClient }, { AnticipationCache }, { getEnv }] = await Promise.all([
42
- import("../stream-client-ZBCKRU7S.js"),
42
+ import("../stream-client-2UMDGCMQ.js"),
43
43
  import("../anticipation-cache-RWKF55J4.js"),
44
44
  import("../env-QCUKKW36.js")
45
45
  ]);
package/dist/index.cjs CHANGED
@@ -1332,6 +1332,9 @@ function buildRecordMessageBody(options) {
1332
1332
  if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
1333
1333
  validateConversationId(conversationId);
1334
1334
  if (!options.role) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("role is required");
1335
+ if (!MESSAGE_ROLES.includes(options.role)) {
1336
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(`Invalid role '${options.role}'. Must be 'user' or 'assistant'.`);
1337
+ }
1335
1338
  if (options.content === void 0 || options.content === null) {
1336
1339
  throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("content is required");
1337
1340
  }
@@ -1346,9 +1349,11 @@ function buildRecordMessageBody(options) {
1346
1349
  metadata: _nullishCoalesce(options.metadata, () => ( {}))
1347
1350
  };
1348
1351
  const sessionId = either2(o2, "session_id", "sessionId");
1349
- if (sessionId !== void 0) body["session_id"] = sessionId;
1352
+ if (sessionId) body["session_id"] = sessionId;
1350
1353
  const scopePath = either2(o2, "scope_path", "scopePath");
1351
- if (scopePath !== void 0) body["scope"] = scopePath;
1354
+ if (scopePath !== void 0 && scopePath !== null && Object.keys(scopePath).length > 0) {
1355
+ body["scope"] = scopePath;
1356
+ }
1352
1357
  return body;
1353
1358
  }
1354
1359
  function buildIngestTranscriptBody(options) {
@@ -1448,6 +1453,7 @@ function storedBatchRows(bodies, result) {
1448
1453
  });
1449
1454
  return pairs;
1450
1455
  }
1456
+ var MESSAGE_ROLES = ["user", "assistant"];
1451
1457
  var PROMPT_STYLES = ["structured", "narrative", "bullet_points"];
1452
1458
  function createConversationNamespace(transport, subscribers = new CompactionSubscribers(), onWrite = () => {
1453
1459
  }, onTurn = () => {
@@ -1785,7 +1791,8 @@ function jsonOrText(value) {
1785
1791
  }
1786
1792
  }
1787
1793
  }
1788
- function createInstanceNamespace(credentials, cache, onTurn, agentModel = () => ({}), onToolResult) {
1794
+ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () => ({}), onToolResult, checkCustomerId3 = async () => {
1795
+ }) {
1789
1796
  let client = null;
1790
1797
  const openSessions = /* @__PURE__ */ new Map();
1791
1798
  let dispatchCompaction = null;
@@ -1844,7 +1851,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1844
1851
  _optionalChain([onListen, 'optionalCall', _60 => _60()]);
1845
1852
  } catch (e10) {
1846
1853
  }
1847
- const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-5GYUWETN.cjs")));
1854
+ const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-FKKCBVCB.cjs")));
1848
1855
  const onContext = _nullishCoalesce(options.on_context, () => ( options.onContext));
1849
1856
  const onDisconnect = _nullishCoalesce(options.on_disconnect, () => ( options.onDisconnect));
1850
1857
  const onReconnect = _nullishCoalesce(options.on_reconnect, () => ( options.onReconnect));
@@ -1908,16 +1915,20 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1908
1915
  }
1909
1916
  },
1910
1917
  async send_message(options) {
1918
+ await checkCustomerId3(
1919
+ _nullishCoalesce(options.customer_id, () => ( options.customerId)),
1920
+ "instance.send_message"
1921
+ );
1911
1922
  if (client === null) throw new (0, _chunkUXNVTP4Dcjs.ListeningNotActiveError)("Listening is not active");
1912
- if (options.content === void 0) {
1913
- throw new (0, _chunkUXNVTP4Dcjs.ListeningNotActiveError)("content is required");
1914
- }
1915
1923
  const eventType = _nullishCoalesce(_nullishCoalesce(options.event_type, () => ( options.eventType)), () => ( "user_message"));
1916
1924
  if (!KNOWN_EVENT_TYPES.has(eventType)) {
1917
- throw new (0, _chunkUXNVTP4Dcjs.SynapError)(
1925
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
1918
1926
  `unknown event_type '${eventType}'. Expected one of: ` + [...KNOWN_EVENT_TYPES].sort().join(", ")
1919
1927
  );
1920
1928
  }
1929
+ if (options.content === void 0 || options.content === null) {
1930
+ throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("content is required");
1931
+ }
1921
1932
  const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
1922
1933
  ensureSession(
1923
1934
  conversationId,
@@ -1950,7 +1961,13 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1950
1961
  tool_result_json: toolResultJson(_nullishCoalesce(options.tool_result, () => ( options.toolResult))),
1951
1962
  tool_call_id: _nullishCoalesce(_nullishCoalesce(options.tool_call_id, () => ( options.toolCallId)), () => ( "")),
1952
1963
  search_queries: _nullishCoalesce(_nullishCoalesce(options.search_queries, () => ( options.searchQueries)), () => ( [])),
1953
- context_types: _nullishCoalesce(_nullishCoalesce(options.context_types, () => ( options.contextTypes)), () => ( []))
1964
+ context_types: _nullishCoalesce(_nullishCoalesce(options.context_types, () => ( options.contextTypes)), () => ( [])),
1965
+ // The proto's `scope`: the conversation's rung, kept from the first
1966
+ // event that names one. Omitted when absent or empty, as in Python.
1967
+ ...(() => {
1968
+ const sp = _nullishCoalesce(options.scope_path, () => ( options.scopePath));
1969
+ return sp && Object.keys(sp).length > 0 ? { scope: sp } : {};
1970
+ })()
1954
1971
  });
1955
1972
  },
1956
1973
  async record_tool_call(options) {
@@ -2023,7 +2040,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
2023
2040
  }
2024
2041
 
2025
2042
  // src/version.ts
2026
- var SDK_VERSION = "0.5.16";
2043
+ var SDK_VERSION = "0.5.18";
2027
2044
 
2028
2045
  // src/registry.ts
2029
2046
  var instances = /* @__PURE__ */ new Map();
@@ -3938,7 +3955,8 @@ var SynapClient = (_class4 = class _SynapClient {
3938
3955
  this.#shortTerm.appendTurn(conversationId, role, content);
3939
3956
  },
3940
3957
  () => this.#agentModel,
3941
- ({ conversationId, result, toolName }) => this.archive_tool_result(conversationId, result, { tool_name: toolName })
3958
+ ({ conversationId, result, toolName }) => this.archive_tool_result(conversationId, result, { tool_name: toolName }),
3959
+ (customerId, where) => this.#transport.checkCustomerId(customerId, where)
3942
3960
  );
3943
3961
  this.instance._internal.setOnListen(() => this.#startLocalModel());
3944
3962
  this.instance._internal.setCompactionApplier((bundle) => {