@maximem/synap-js-sdk 0.5.15 → 0.5.17

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 +1 @@
1
- {"version":3,"sources":["/Users/anish/maximemai/maximem_synap/synap/sdk/js/dist/grpc/index.cjs","../../src/grpc/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,yDAA8B;AAC9B;AACE;AACF,yDAA8B;AAC9B;AACA;ACkCA,MAAA,SAAsB,qBAAA,CAAA,EAAmD;AACvE,EAAA,MAAM,OAAA,EACJ,OAAO,QAAA,IAAY,YAAA,mBACnB,OAAA,mBAAQ,QAAA,6BAAU,OAAA,IAAS,KAAA,EAAA,GAC3B,OAAQ,UAAA,CAAyC,YAAA,IAAgB,WAAA;AAEnE,EAAA,GAAA,CAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO;AAAA,MACL,SAAA,EAAW,KAAA;AAAA,MACX,MAAA,EAAQ,UAAA;AAAA,MACR,MAAA,EACE;AAAA,IAIJ,CAAA;AAAA,EACF;AAEA,EAAA,IAAI;AACF,IAAA,MAAM,4DAAA;AAAA;AAAA,MAA0B;AAAA,IAAe,GAAA;AAC/C,IAAA,OAAO,EAAE,SAAA,EAAW,KAAK,CAAA;AAAA,EAC3B,EAAA,MAAA,CAAS,KAAA,EAAO;AACd,IAAA,OAAO;AAAA,MACL,SAAA,EAAW,KAAA;AAAA,MACX,MAAA,EAAQ,gBAAA;AAAA,MACR,MAAA,EACE,CAAA,oIAAA,mCAEK,KAAA,6BAAiB,SAAA,UAAW,MAAA,CAAO,KAAK,GAAC,CAAA,CAAA;AAAA,IAClD,CAAA;AAAA,EACF;AACF;AA4BA,MAAA,SAAsB,MAAA,CACpB,OAAA,EAQ2B;AAC3B,EAAA,GAAA,CAAI,CAAC,OAAA,CAAQ,cAAA,EAAgB;AAG3B,IAAA,MAAM,IAAI,8CAAA,CAAwB,yDAAyD,CAAA;AAAA,EAC7F;AAEA,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A,CAAQ,KAAK,EAAA,EAAI,CAAC,CAAA;AAAA,MAC3D,GAAI,OAAA,CAAQ,OAAA,IAAW,KAAA,EAAA,EAAY,EAAE,MAAA,EAAQ,OAAA,CAAQ,OAAO,EAAA,EAAI,CAAC,CAAA;AAAA,MACjE,GAAI,OAAA,CAAQ,SAAA,IAAa,KAAA,EAAA,EAAY,EAAE,SAAA,EAAW,OAAA,CAAQ,SAAS,EAAA,EAAI,CAAC;AAAA,IAC1E;AAAA,EACF,CAAA;AACA,EAAA,MAAM,MAAA,CAAO,OAAA,CAAQ,CAAA;AACrB,EAAA,MAAA,CAAO,kBAAA,CAAmB;AAAA,IACxB,MAAA,EAAQ,OAAA;AAAA,IACR,eAAA,EAAiB,OAAA,CAAQ,cAAA;AAAA,IACzB,GAAI,OAAA,CAAQ,OAAA,IAAW,KAAA,EAAA,EAAY,EAAE,OAAA,EAAS,OAAA,CAAQ,OAAO,EAAA,EAAI,CAAC,CAAA;AAAA,IAClE,GAAI,OAAA,CAAQ,WAAA,IAAe,KAAA,EAAA,EAAY,EAAE,WAAA,EAAa,OAAA,CAAQ,WAAW,EAAA,EAAI,CAAC;AAAA,EAChF,CAAC,CAAA;AAED,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,CAAA,EAAA,GAAM,MAAA,CAAO,UAAA,CAAW,CAAA;AAAA,IAC9B,IAAI,MAAA,CAAA,EAAS;AAAE,MAAA,OAAO,MAAA,CAAO,WAAA;AAAA,IAAa;AAAA,EAC5C,CAAA;AACF;ADlFA;AACE;AACA;AACA;AACA;AACF,+LAAC","file":"/Users/anish/maximemai/maximem_synap/synap/sdk/js/dist/grpc/index.cjs","sourcesContent":[null,"/**\n * gRPC anticipation stream: availability and loading.\n *\n * This is a SUBPATH export (`@maximem/synap-js-sdk/grpc`) and is never\n * imported by the main entry point. Three reasons, all of which have bitten\n * someone already:\n *\n * 1. `@grpc/grpc-js` plus its protos is roughly 5MB. HTTP-only and Edge users\n * should not pay for it (gotcha G-Q).\n * 2. grpc-js is built on `node:http2`, `node:net` and `node:tls`. Merely\n * importing it on Edge or Workers fails the *build*, not the call. Keeping\n * it behind a subpath plus a lazy `import()` means importing the SDK on\n * Edge stays safe.\n * 3. It is an `optionalDependency`, so it may legitimately be absent.\n *\n * ## Proto loading\n *\n * The stream is live. The proto ships as an INLINED JSON descriptor\n * (./descriptor.ts) loaded through `proto-loader.fromJSON`, not through\n * `loadSync(path)`. proto-loader's file-based path reads the `.proto` off disk\n * at runtime, which breaks under webpack/turbopack bundling and Vercel's `nft`\n * file tracing: at deploy time rather than at test time (gotcha G-P). Inlining\n * gets the same result as ts-proto codegen without a codegen toolchain.\n */\n\nimport { ListeningNotActiveError } from '../errors.js';\nexport { GrpcStreamClient } from './stream-client.js';\nexport type {\n StreamState, StreamCredentials, StreamClientOptions, ConversationEventInput,\n} from './stream-client.js';\nexport { PROTO_SHA } from './descriptor.js';\n\nexport type GrpcAvailability =\n | { available: true }\n | { available: false; reason: 'not-node' | 'module-missing'; detail: string };\n\n/**\n * Whether a gRPC stream could run here.\n *\n * Deliberately does not throw: callers use this to decide whether to offer the\n * stream at all, and a hard failure at that point is unhelpful.\n */\nexport async function checkGrpcAvailability(): Promise<GrpcAvailability> {\n const isNode =\n typeof process !== 'undefined' &&\n process.versions?.node !== undefined &&\n typeof (globalThis as { EdgeRuntime?: unknown }).EdgeRuntime === 'undefined';\n\n if (!isNode) {\n return {\n available: false,\n reason: 'not-node',\n detail:\n 'gRPC needs raw TCP and node:http2, which Edge runtimes and Workers do ' +\n 'not provide. HTTP context fetching works normally here; only the ' +\n 'anticipation stream is unavailable. Reaching Edge would require a ' +\n 'gRPC-Web or Connect endpoint on the server, which does not exist yet.',\n };\n }\n\n try {\n await import(/* @vite-ignore */ '@grpc/grpc-js');\n return { available: true };\n } catch (error) {\n return {\n available: false,\n reason: 'module-missing',\n detail:\n '@grpc/grpc-js is an optional dependency and is not installed. Run ' +\n '`npm install @grpc/grpc-js` to enable the anticipation stream. ' +\n `(${(error as Error)?.message ?? String(error)})`,\n };\n }\n}\n\nexport interface ListenOptions {\n conversationId: string;\n userId?: string;\n customerId?: string;\n onBundle?: (bundle: unknown) => void;\n}\n\nexport interface ListeningSession {\n stop(): Promise<void>;\n readonly active: boolean;\n}\n\n/**\n * Start the anticipation stream directly, without a SynapClient.\n *\n * Most callers want `client.instance.listen()` instead, which shares the\n * client's credentials and anticipation cache. This exists for the case where\n * only the stream is wanted.\n *\n * **Opt-in, and off by default.** The removed wrapper called `listen()`\n * unconditionally during init, so every user had a stream whether they asked\n * for one or not. Making it opt-in is the right default, but it is not a\n * neutral change: fewer streams means fewer anticipation hits and therefore\n * MORE billed cloud fetches for existing users. That has to be announced\n * rather than discovered (gotcha G-Y).\n */\nexport async function listen(\n options: ListenOptions & {\n apiKey?: string;\n clientId?: string;\n instanceId?: string;\n host?: string;\n port?: number;\n useTls?: boolean;\n },\n): Promise<ListeningSession> {\n if (!options.conversationId) {\n // conversation_id is not a scope tier, but the stream genuinely requires\n // one: it is what the server keys the anticipation session on.\n throw new ListeningNotActiveError('conversation_id is required to start a listening stream');\n }\n\n const availability = await checkGrpcAvailability();\n if (!availability.available) {\n throw new ListeningNotActiveError(availability.detail);\n }\n\n const [{ GrpcStreamClient: StreamClient }, { AnticipationCache }, { getEnv }] = await Promise.all([\n import('./stream-client.js'),\n import('../context/anticipation-cache.js'),\n import('../util/env.js'),\n ]);\n\n const apiKey = options.apiKey ?? getEnv('SYNAP_API_KEY') ?? '';\n if (apiKey === '') {\n throw new ListeningNotActiveError(\n 'No Synap API key found. Set SYNAP_API_KEY or pass apiKey.',\n );\n }\n\n const cache = new AnticipationCache();\n const client = new StreamClient(\n {\n apiKey,\n clientId: options.clientId ?? getEnv('SYNAP_CLIENT_ID') ?? '',\n instanceId: options.instanceId ?? getEnv('SYNAP_INSTANCE_ID') ?? '',\n },\n cache,\n {\n ...(options.host !== undefined ? { host: options.host } : {}),\n ...(options.port !== undefined ? { port: options.port } : {}),\n ...(options.useTls !== undefined ? { useTls: options.useTls } : {}),\n ...(options.onBundle !== undefined ? { onContext: options.onBundle } : {}),\n },\n );\n await client.connect();\n client.sendSessionControl({\n action: 'start',\n conversation_id: options.conversationId,\n ...(options.userId !== undefined ? { user_id: options.userId } : {}),\n ...(options.customerId !== undefined ? { customer_id: options.customerId } : {}),\n });\n\n return {\n stop: () => client.disconnect(),\n get active() { return client.isConnected; },\n };\n}\n"]}
1
+ {"version":3,"sources":["/Users/anish/maximemai/maximem_synap-js-parity/synap/sdk/js/dist/grpc/index.cjs","../../src/grpc/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,yDAA8B;AAC9B;AACE;AACF,yDAA8B;AAC9B;AACA;ACkCA,MAAA,SAAsB,qBAAA,CAAA,EAAmD;AACvE,EAAA,MAAM,OAAA,EACJ,OAAO,QAAA,IAAY,YAAA,mBACnB,OAAA,mBAAQ,QAAA,6BAAU,OAAA,IAAS,KAAA,EAAA,GAC3B,OAAQ,UAAA,CAAyC,YAAA,IAAgB,WAAA;AAEnE,EAAA,GAAA,CAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO;AAAA,MACL,SAAA,EAAW,KAAA;AAAA,MACX,MAAA,EAAQ,UAAA;AAAA,MACR,MAAA,EACE;AAAA,IAIJ,CAAA;AAAA,EACF;AAEA,EAAA,IAAI;AACF,IAAA,MAAM,4DAAA;AAAA;AAAA,MAA0B;AAAA,IAAe,GAAA;AAC/C,IAAA,OAAO,EAAE,SAAA,EAAW,KAAK,CAAA;AAAA,EAC3B,EAAA,MAAA,CAAS,KAAA,EAAO;AACd,IAAA,OAAO;AAAA,MACL,SAAA,EAAW,KAAA;AAAA,MACX,MAAA,EAAQ,gBAAA;AAAA,MACR,MAAA,EACE,CAAA,oIAAA,mCAEK,KAAA,6BAAiB,SAAA,UAAW,MAAA,CAAO,KAAK,GAAC,CAAA,CAAA;AAAA,IAClD,CAAA;AAAA,EACF;AACF;AA4BA,MAAA,SAAsB,MAAA,CACpB,OAAA,EAQ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A,EAAM,OAAA,CAAQ,KAAK,EAAA,EAAI,CAAC,CAAA;AAAA,MAC3D,GAAI,OAAA,CAAQ,KAAA,IAAS,KAAA,EAAA,EAAY,EAAE,IAAA,EAAM,OAAA,CAAQ,KAAK,EAAA,EAAI,CAAC,CAAA;AAAA,MAC3D,GAAI,OAAA,CAAQ,OAAA,IAAW,KAAA,EAAA,EAAY,EAAE,MAAA,EAAQ,OAAA,CAAQ,OAAO,EAAA,EAAI,CAAC,CAAA;AAAA,MACjE,GAAI,OAAA,CAAQ,SAAA,IAAa,KAAA,EAAA,EAAY,EAAE,SAAA,EAAW,OAAA,CAAQ,SAAS,EAAA,EAAI,CAAC;AAAA,IAC1E;AAAA,EACF,CAAA;AACA,EAAA,MAAM,MAAA,CAAO,OAAA,CAAQ,CAAA;AACrB,EAAA,MAAA,CAAO,kBAAA,CAAmB;AAAA,IACxB,MAAA,EAAQ,OAAA;AAAA,IACR,eAAA,EAAiB,OAAA,CAAQ,cAAA;AAAA,IACzB,GAAI,OAAA,CAAQ,OAAA,IAAW,KAAA,EAAA,EAAY,EAAE,OAAA,EAAS,OAAA,CAAQ,OAAO,EAAA,EAAI,CAAC,CAAA;AAAA,IAClE,GAAI,OAAA,CAAQ,WAAA,IAAe,KAAA,EAAA,EAAY,EAAE,WAAA,EAAa,OAAA,CAAQ,WAAW,EAAA,EAAI,CAAC;AAAA,EAChF,CAAC,CAAA;AAED,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,CAAA,EAAA,GAAM,MAAA,CAAO,UAAA,CAAW,CAAA;AAAA,IAC9B,IAAI,MAAA,CAAA,EAAS;AAAE,MAAA,OAAO,MAAA,CAAO,WAAA;AAAA,IAAa;AAAA,EAC5C,CAAA;AACF;ADlFA;AACE;AACA;AACA;AACA;AACF,+LAAC","file":"/Users/anish/maximemai/maximem_synap-js-parity/synap/sdk/js/dist/grpc/index.cjs","sourcesContent":[null,"/**\n * gRPC anticipation stream: availability and loading.\n *\n * This is a SUBPATH export (`@maximem/synap-js-sdk/grpc`) and is never\n * imported by the main entry point. Three reasons, all of which have bitten\n * someone already:\n *\n * 1. `@grpc/grpc-js` plus its protos is roughly 5MB. HTTP-only and Edge users\n * should not pay for it (gotcha G-Q).\n * 2. grpc-js is built on `node:http2`, `node:net` and `node:tls`. Merely\n * importing it on Edge or Workers fails the *build*, not the call. Keeping\n * it behind a subpath plus a lazy `import()` means importing the SDK on\n * Edge stays safe.\n * 3. It is an `optionalDependency`, so it may legitimately be absent.\n *\n * ## Proto loading\n *\n * The stream is live. The proto ships as an INLINED JSON descriptor\n * (./descriptor.ts) loaded through `proto-loader.fromJSON`, not through\n * `loadSync(path)`. proto-loader's file-based path reads the `.proto` off disk\n * at runtime, which breaks under webpack/turbopack bundling and Vercel's `nft`\n * file tracing: at deploy time rather than at test time (gotcha G-P). Inlining\n * gets the same result as ts-proto codegen without a codegen toolchain.\n */\n\nimport { ListeningNotActiveError } from '../errors.js';\nexport { GrpcStreamClient } from './stream-client.js';\nexport type {\n StreamState, StreamCredentials, StreamClientOptions, ConversationEventInput,\n} from './stream-client.js';\nexport { PROTO_SHA } from './descriptor.js';\n\nexport type GrpcAvailability =\n | { available: true }\n | { available: false; reason: 'not-node' | 'module-missing'; detail: string };\n\n/**\n * Whether a gRPC stream could run here.\n *\n * Deliberately does not throw: callers use this to decide whether to offer the\n * stream at all, and a hard failure at that point is unhelpful.\n */\nexport async function checkGrpcAvailability(): Promise<GrpcAvailability> {\n const isNode =\n typeof process !== 'undefined' &&\n process.versions?.node !== undefined &&\n typeof (globalThis as { EdgeRuntime?: unknown }).EdgeRuntime === 'undefined';\n\n if (!isNode) {\n return {\n available: false,\n reason: 'not-node',\n detail:\n 'gRPC needs raw TCP and node:http2, which Edge runtimes and Workers do ' +\n 'not provide. HTTP context fetching works normally here; only the ' +\n 'anticipation stream is unavailable. Reaching Edge would require a ' +\n 'gRPC-Web or Connect endpoint on the server, which does not exist yet.',\n };\n }\n\n try {\n await import(/* @vite-ignore */ '@grpc/grpc-js');\n return { available: true };\n } catch (error) {\n return {\n available: false,\n reason: 'module-missing',\n detail:\n '@grpc/grpc-js is an optional dependency and is not installed. Run ' +\n '`npm install @grpc/grpc-js` to enable the anticipation stream. ' +\n `(${(error as Error)?.message ?? String(error)})`,\n };\n }\n}\n\nexport interface ListenOptions {\n conversationId: string;\n userId?: string;\n customerId?: string;\n onBundle?: (bundle: unknown) => void;\n}\n\nexport interface ListeningSession {\n stop(): Promise<void>;\n readonly active: boolean;\n}\n\n/**\n * Start the anticipation stream directly, without a SynapClient.\n *\n * Most callers want `client.instance.listen()` instead, which shares the\n * client's credentials and anticipation cache. This exists for the case where\n * only the stream is wanted.\n *\n * **Opt-in, and off by default.** The removed wrapper called `listen()`\n * unconditionally during init, so every user had a stream whether they asked\n * for one or not. Making it opt-in is the right default, but it is not a\n * neutral change: fewer streams means fewer anticipation hits and therefore\n * MORE billed cloud fetches for existing users. That has to be announced\n * rather than discovered (gotcha G-Y).\n */\nexport async function listen(\n options: ListenOptions & {\n apiKey?: string;\n clientId?: string;\n instanceId?: string;\n host?: string;\n port?: number;\n useTls?: boolean;\n },\n): Promise<ListeningSession> {\n if (!options.conversationId) {\n // conversation_id is not a scope tier, but the stream genuinely requires\n // one: it is what the server keys the anticipation session on.\n throw new ListeningNotActiveError('conversation_id is required to start a listening stream');\n }\n\n const availability = await checkGrpcAvailability();\n if (!availability.available) {\n throw new ListeningNotActiveError(availability.detail);\n }\n\n const [{ GrpcStreamClient: StreamClient }, { AnticipationCache }, { getEnv }] = await Promise.all([\n import('./stream-client.js'),\n import('../context/anticipation-cache.js'),\n import('../util/env.js'),\n ]);\n\n const apiKey = options.apiKey ?? getEnv('SYNAP_API_KEY') ?? '';\n if (apiKey === '') {\n throw new ListeningNotActiveError(\n 'No Synap API key found. Set SYNAP_API_KEY or pass apiKey.',\n );\n }\n\n const cache = new AnticipationCache();\n const client = new StreamClient(\n {\n apiKey,\n clientId: options.clientId ?? getEnv('SYNAP_CLIENT_ID') ?? '',\n instanceId: options.instanceId ?? getEnv('SYNAP_INSTANCE_ID') ?? '',\n },\n cache,\n {\n ...(options.host !== undefined ? { host: options.host } : {}),\n ...(options.port !== undefined ? { port: options.port } : {}),\n ...(options.useTls !== undefined ? { useTls: options.useTls } : {}),\n ...(options.onBundle !== undefined ? { onContext: options.onBundle } : {}),\n },\n );\n await client.connect();\n client.sendSessionControl({\n action: 'start',\n conversation_id: options.conversationId,\n ...(options.userId !== undefined ? { user_id: options.userId } : {}),\n ...(options.customerId !== undefined ? { customer_id: options.customerId } : {}),\n });\n\n return {\n stop: () => client.disconnect(),\n get active() { return client.isConnected; },\n };\n}\n"]}
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) {
@@ -1376,7 +1381,9 @@ function buildIngestTranscriptBody(options) {
1376
1381
  if (startedAt !== void 0) body["started_at"] = startedAt;
1377
1382
  if (endedAt !== void 0) body["ended_at"] = endedAt;
1378
1383
  const scopePath = either2(o2, "scope_path", "scopePath");
1379
- if (scopePath !== void 0) body["scope"] = scopePath;
1384
+ if (scopePath !== void 0 && scopePath !== null && Object.keys(scopePath).length > 0) {
1385
+ body["scope"] = scopePath;
1386
+ }
1380
1387
  return body;
1381
1388
  }
1382
1389
  function buildCompactBody(options) {
@@ -1446,6 +1453,7 @@ function storedBatchRows(bodies, result) {
1446
1453
  });
1447
1454
  return pairs;
1448
1455
  }
1456
+ var MESSAGE_ROLES = ["user", "assistant"];
1449
1457
  var PROMPT_STYLES = ["structured", "narrative", "bullet_points"];
1450
1458
  function createConversationNamespace(transport, subscribers = new CompactionSubscribers(), onWrite = () => {
1451
1459
  }, onTurn = () => {
@@ -1545,8 +1553,17 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1545
1553
  return result;
1546
1554
  },
1547
1555
  async ingest_transcript(options) {
1556
+ const o2 = options;
1557
+ await transport.checkCustomerId(
1558
+ _nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])),
1559
+ "conversation.ingest_transcript"
1560
+ );
1548
1561
  const body = buildIngestTranscriptBody(options);
1549
- const result = await transport.request("conversations_ingest", { body });
1562
+ const raw = await transport.request("conversations_ingest", { body });
1563
+ const result = {
1564
+ ...raw,
1565
+ warnings: Array.isArray(_optionalChain([raw, 'optionalAccess', _50 => _50.warnings])) ? raw.warnings.map(String) : []
1566
+ };
1550
1567
  onWrite({
1551
1568
  userId: body["user_id"],
1552
1569
  customerId: body["customer_id"]
@@ -1589,8 +1606,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1589
1606
  pathParams: { conversation_id: id },
1590
1607
  query: { style }
1591
1608
  });
1592
- const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _50 => _50["context_for_prompt"]]), () => ( result)), () => ( {}));
1593
- _optionalChain([localShortTerm, 'access', _51 => _51.reseed, 'optionalCall', _52 => _52(id, response)]);
1609
+ const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _51 => _51["context_for_prompt"]]), () => ( result)), () => ( {}));
1610
+ _optionalChain([localShortTerm, 'access', _52 => _52.reseed, 'optionalCall', _53 => _53(id, response)]);
1594
1611
  return withHistory(response);
1595
1612
  },
1596
1613
  async compact(options) {
@@ -1783,8 +1800,8 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1783
1800
  let onConversationState = null;
1784
1801
  const internals = {
1785
1802
  onCompactionUpdate(conversationId, bundle) {
1786
- _optionalChain([applyCompaction, 'optionalCall', _53 => _53(bundle)]);
1787
- _optionalChain([dispatchCompaction, 'optionalCall', _54 => _54(conversationId, bundle)]);
1803
+ _optionalChain([applyCompaction, 'optionalCall', _54 => _54(bundle)]);
1804
+ _optionalChain([dispatchCompaction, 'optionalCall', _55 => _55(conversationId, bundle)]);
1788
1805
  },
1789
1806
  setCompactionApplier(apply) {
1790
1807
  applyCompaction = apply;
@@ -1796,10 +1813,10 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1796
1813
  onConversationState = handle;
1797
1814
  },
1798
1815
  sendContextUsed(event) {
1799
- _optionalChain([client, 'optionalAccess', _55 => _55.sendContextUsed, 'call', _56 => _56(event)]);
1816
+ _optionalChain([client, 'optionalAccess', _56 => _56.sendContextUsed, 'call', _57 => _57(event)]);
1800
1817
  },
1801
1818
  sendContextAssembled(event) {
1802
- _optionalChain([client, 'optionalAccess', _57 => _57.sendContextAssembled, 'call', _58 => _58(event)]);
1819
+ _optionalChain([client, 'optionalAccess', _58 => _58.sendContextAssembled, 'call', _59 => _59(event)]);
1803
1820
  },
1804
1821
  setCompactionDispatcher(dispatch) {
1805
1822
  dispatchCompaction = dispatch;
@@ -1830,7 +1847,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1830
1847
  throw new (0, _chunkUXNVTP4Dcjs.ListeningAlreadyActiveError)("Listening is already active on this instance");
1831
1848
  }
1832
1849
  try {
1833
- _optionalChain([onListen, 'optionalCall', _59 => _59()]);
1850
+ _optionalChain([onListen, 'optionalCall', _60 => _60()]);
1834
1851
  } catch (e10) {
1835
1852
  }
1836
1853
  const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-5GYUWETN.cjs")));
@@ -1848,17 +1865,17 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1848
1865
  internals.onCompactionUpdate(conversationId, bundle);
1849
1866
  },
1850
1867
  onConversationState: (conversationId, messageCount) => {
1851
- _optionalChain([onConversationState, 'optionalCall', _60 => _60(conversationId, messageCount)]);
1868
+ _optionalChain([onConversationState, 'optionalCall', _61 => _61(conversationId, messageCount)]);
1852
1869
  },
1853
1870
  onStateChange: (state) => {
1854
1871
  if (state !== "connected") openSessions.clear();
1855
1872
  if (state === "reconnecting") {
1856
1873
  reconnectAttempts += 1;
1857
- _optionalChain([onReconnect, 'optionalCall', _61 => _61(reconnectAttempts)]);
1874
+ _optionalChain([onReconnect, 'optionalCall', _62 => _62(reconnectAttempts)]);
1858
1875
  } else if (state === "disconnected") {
1859
- const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _62 => _62.lastError]), () => ( null));
1876
+ const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _63 => _63.lastError]), () => ( null));
1860
1877
  const reason = stopped === null ? "stream disconnected" : `credit_stop:${_nullishCoalesce(stopped.reason, () => ( "unknown"))}`;
1861
- _optionalChain([onDisconnect, 'optionalCall', _63 => _63(reason)]);
1878
+ _optionalChain([onDisconnect, 'optionalCall', _64 => _64(reason)]);
1862
1879
  }
1863
1880
  }
1864
1881
  });
@@ -1868,7 +1885,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1868
1885
  } catch (error) {
1869
1886
  if (error instanceof _chunkUXNVTP4Dcjs.SynapError) throw error;
1870
1887
  throw new (0, _chunkUXNVTP4Dcjs.SynapError)(
1871
- `Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _64 => _64.message]), () => ( String(error)))}`,
1888
+ `Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _65 => _65.message]), () => ( String(error)))}`,
1872
1889
  { cause: error }
1873
1890
  );
1874
1891
  }
@@ -1914,7 +1931,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1914
1931
  _nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( ""))
1915
1932
  );
1916
1933
  if (eventType === "user_message" || eventType === "assistant_message") {
1917
- _optionalChain([onTurn, 'optionalCall', _65 => _65({
1934
+ _optionalChain([onTurn, 'optionalCall', _66 => _66({
1918
1935
  conversationId,
1919
1936
  role: _nullishCoalesce(options.role, () => ( "user")),
1920
1937
  content: options.content
@@ -1960,7 +1977,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1960
1977
  async record_tool_result(options) {
1961
1978
  const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
1962
1979
  if (conversationId) {
1963
- _optionalChain([onToolResult, 'optionalCall', _66 => _66({ conversationId, result: options.result, toolName: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")) })]);
1980
+ _optionalChain([onToolResult, 'optionalCall', _67 => _67({ conversationId, result: options.result, toolName: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")) })]);
1964
1981
  }
1965
1982
  await namespace.send_message({
1966
1983
  content: "",
@@ -2012,7 +2029,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
2012
2029
  }
2013
2030
 
2014
2031
  // src/version.ts
2015
- var SDK_VERSION = "0.5.15";
2032
+ var SDK_VERSION = "0.5.17";
2016
2033
 
2017
2034
  // src/registry.ts
2018
2035
  var instances = /* @__PURE__ */ new Map();
@@ -2480,7 +2497,7 @@ var TurnStore = (_class3 = class {
2480
2497
  }
2481
2498
  /** Turns the server also holds: archived tool results are local only. Python: `count`. */
2482
2499
  count(conversationId) {
2483
- return (_nullishCoalesce(_optionalChain([this, 'access', _67 => _67.#conversations, 'access', _68 => _68.get, 'call', _69 => _69(conversationId), 'optionalAccess', _70 => _70.turns]), () => ( []))).filter((t) => t.role !== "tool").length;
2500
+ return (_nullishCoalesce(_optionalChain([this, 'access', _68 => _68.#conversations, 'access', _69 => _69.get, 'call', _70 => _70(conversationId), 'optionalAccess', _71 => _71.turns]), () => ( []))).filter((t) => t.role !== "tool").length;
2484
2501
  }
2485
2502
  sizeBytes() {
2486
2503
  let n2 = 0;
@@ -2659,7 +2676,7 @@ function askedKinds(query) {
2659
2676
  }
2660
2677
  function asksHowItStarted(query) {
2661
2678
  const spec = _chunkICUFS3B5cjs.HISTORY_SEARCH.early_query;
2662
- if (!_optionalChain([spec, 'optionalAccess', _71 => _71.pattern])) return false;
2679
+ if (!_optionalChain([spec, 'optionalAccess', _72 => _72.pattern])) return false;
2663
2680
  return new RegExp(spec.pattern, (_nullishCoalesce(spec.flags, () => ( ""))).includes("i") ? "i" : "").test(_nullishCoalesce(query, () => ( "")));
2664
2681
  }
2665
2682
  async function searchTurns(turns, query, options = {}) {
@@ -3872,7 +3889,7 @@ var SynapClient = (_class4 = class _SynapClient {
3872
3889
  this.#localEncoder = _nullishCoalesce(_nullishCoalesce(options.history_search_encoder, () => ( options.historySearchEncoder)), () => ( null));
3873
3890
  const modelOption = options.history_search_model !== void 0 ? options.history_search_model : options.historySearchModel;
3874
3891
  this.#localModelName = modelOption === void 0 ? "auto" : modelOption;
3875
- if (_optionalChain([this, 'access', _72 => _72.#localEncoder, 'optionalAccess', _73 => _73.model]) === _chunkICUFS3B5cjs.SEMANTIC_MATCH.model) this.#anticipationCache.setEncoder(this.#localEncoder);
3892
+ if (_optionalChain([this, 'access', _73 => _73.#localEncoder, 'optionalAccess', _74 => _74.model]) === _chunkICUFS3B5cjs.SEMANTIC_MATCH.model) this.#anticipationCache.setEncoder(this.#localEncoder);
3876
3893
  this.#turns = new TurnCounter();
3877
3894
  this.conversation = createConversationNamespace(
3878
3895
  this.#transport,
@@ -4368,14 +4385,14 @@ var SynapClient = (_class4 = class _SynapClient {
4368
4385
  }))
4369
4386
  );
4370
4387
  const entry = this.#shortTerm.get(conversationId);
4371
- const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess', _74 => _74.serverMessageCount]), () => ( 0))) || 0);
4388
+ const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess', _75 => _75.serverMessageCount]), () => ( 0))) || 0);
4372
4389
  this.#maybeBackfillTurns(conversationId, total);
4373
4390
  if (!r["context_block"]) return response;
4374
4391
  const turns = store.turns(conversationId);
4375
4392
  let q = query;
4376
4393
  if (!q) {
4377
4394
  const latest = [...recent].reverse().find((m) => m["role"] === "user");
4378
- q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access', _75 => _75.reverse, 'call', _76 => _76(), 'access', _77 => _77.find, 'call', _78 => _78((t) => t.role === "user"), 'optionalAccess', _79 => _79.content]), () => ( ""));
4395
+ q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access', _76 => _76.reverse, 'call', _77 => _77(), 'access', _78 => _78.find, 'call', _79 => _79((t) => t.role === "user"), 'optionalAccess', _80 => _80.content]), () => ( ""));
4379
4396
  }
4380
4397
  if (!q) return response;
4381
4398
  const exclude = /* @__PURE__ */ new Set();
@@ -4519,7 +4536,7 @@ function pick3(o2, snake, camel) {
4519
4536
  function resolveBaseUrl(options) {
4520
4537
  const explicit = _nullishCoalesce(options.baseUrl, () => ( options.api_base_url));
4521
4538
  if (explicit !== void 0) return explicit;
4522
- const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _80 => _80.trim, 'call', _81 => _81()]);
4539
+ const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _81 => _81.trim, 'call', _82 => _82()]);
4523
4540
  return fromEnv !== void 0 && fromEnv !== "" ? fromEnv : void 0;
4524
4541
  }
4525
4542
  function resolveCredentials(options) {