@maximem/synap-js-sdk 0.5.15 → 0.5.16

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
@@ -1376,7 +1376,9 @@ function buildIngestTranscriptBody(options) {
1376
1376
  if (startedAt !== void 0) body["started_at"] = startedAt;
1377
1377
  if (endedAt !== void 0) body["ended_at"] = endedAt;
1378
1378
  const scopePath = either2(o2, "scope_path", "scopePath");
1379
- if (scopePath !== void 0) body["scope"] = scopePath;
1379
+ if (scopePath !== void 0 && scopePath !== null && Object.keys(scopePath).length > 0) {
1380
+ body["scope"] = scopePath;
1381
+ }
1380
1382
  return body;
1381
1383
  }
1382
1384
  function buildCompactBody(options) {
@@ -1545,8 +1547,17 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1545
1547
  return result;
1546
1548
  },
1547
1549
  async ingest_transcript(options) {
1550
+ const o2 = options;
1551
+ await transport.checkCustomerId(
1552
+ _nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])),
1553
+ "conversation.ingest_transcript"
1554
+ );
1548
1555
  const body = buildIngestTranscriptBody(options);
1549
- const result = await transport.request("conversations_ingest", { body });
1556
+ const raw = await transport.request("conversations_ingest", { body });
1557
+ const result = {
1558
+ ...raw,
1559
+ warnings: Array.isArray(_optionalChain([raw, 'optionalAccess', _50 => _50.warnings])) ? raw.warnings.map(String) : []
1560
+ };
1550
1561
  onWrite({
1551
1562
  userId: body["user_id"],
1552
1563
  customerId: body["customer_id"]
@@ -1589,8 +1600,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
1589
1600
  pathParams: { conversation_id: id },
1590
1601
  query: { style }
1591
1602
  });
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)]);
1603
+ const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _51 => _51["context_for_prompt"]]), () => ( result)), () => ( {}));
1604
+ _optionalChain([localShortTerm, 'access', _52 => _52.reseed, 'optionalCall', _53 => _53(id, response)]);
1594
1605
  return withHistory(response);
1595
1606
  },
1596
1607
  async compact(options) {
@@ -1783,8 +1794,8 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1783
1794
  let onConversationState = null;
1784
1795
  const internals = {
1785
1796
  onCompactionUpdate(conversationId, bundle) {
1786
- _optionalChain([applyCompaction, 'optionalCall', _53 => _53(bundle)]);
1787
- _optionalChain([dispatchCompaction, 'optionalCall', _54 => _54(conversationId, bundle)]);
1797
+ _optionalChain([applyCompaction, 'optionalCall', _54 => _54(bundle)]);
1798
+ _optionalChain([dispatchCompaction, 'optionalCall', _55 => _55(conversationId, bundle)]);
1788
1799
  },
1789
1800
  setCompactionApplier(apply) {
1790
1801
  applyCompaction = apply;
@@ -1796,10 +1807,10 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1796
1807
  onConversationState = handle;
1797
1808
  },
1798
1809
  sendContextUsed(event) {
1799
- _optionalChain([client, 'optionalAccess', _55 => _55.sendContextUsed, 'call', _56 => _56(event)]);
1810
+ _optionalChain([client, 'optionalAccess', _56 => _56.sendContextUsed, 'call', _57 => _57(event)]);
1800
1811
  },
1801
1812
  sendContextAssembled(event) {
1802
- _optionalChain([client, 'optionalAccess', _57 => _57.sendContextAssembled, 'call', _58 => _58(event)]);
1813
+ _optionalChain([client, 'optionalAccess', _58 => _58.sendContextAssembled, 'call', _59 => _59(event)]);
1803
1814
  },
1804
1815
  setCompactionDispatcher(dispatch) {
1805
1816
  dispatchCompaction = dispatch;
@@ -1830,7 +1841,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1830
1841
  throw new (0, _chunkUXNVTP4Dcjs.ListeningAlreadyActiveError)("Listening is already active on this instance");
1831
1842
  }
1832
1843
  try {
1833
- _optionalChain([onListen, 'optionalCall', _59 => _59()]);
1844
+ _optionalChain([onListen, 'optionalCall', _60 => _60()]);
1834
1845
  } catch (e10) {
1835
1846
  }
1836
1847
  const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-5GYUWETN.cjs")));
@@ -1848,17 +1859,17 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1848
1859
  internals.onCompactionUpdate(conversationId, bundle);
1849
1860
  },
1850
1861
  onConversationState: (conversationId, messageCount) => {
1851
- _optionalChain([onConversationState, 'optionalCall', _60 => _60(conversationId, messageCount)]);
1862
+ _optionalChain([onConversationState, 'optionalCall', _61 => _61(conversationId, messageCount)]);
1852
1863
  },
1853
1864
  onStateChange: (state) => {
1854
1865
  if (state !== "connected") openSessions.clear();
1855
1866
  if (state === "reconnecting") {
1856
1867
  reconnectAttempts += 1;
1857
- _optionalChain([onReconnect, 'optionalCall', _61 => _61(reconnectAttempts)]);
1868
+ _optionalChain([onReconnect, 'optionalCall', _62 => _62(reconnectAttempts)]);
1858
1869
  } else if (state === "disconnected") {
1859
- const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _62 => _62.lastError]), () => ( null));
1870
+ const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _63 => _63.lastError]), () => ( null));
1860
1871
  const reason = stopped === null ? "stream disconnected" : `credit_stop:${_nullishCoalesce(stopped.reason, () => ( "unknown"))}`;
1861
- _optionalChain([onDisconnect, 'optionalCall', _63 => _63(reason)]);
1872
+ _optionalChain([onDisconnect, 'optionalCall', _64 => _64(reason)]);
1862
1873
  }
1863
1874
  }
1864
1875
  });
@@ -1868,7 +1879,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1868
1879
  } catch (error) {
1869
1880
  if (error instanceof _chunkUXNVTP4Dcjs.SynapError) throw error;
1870
1881
  throw new (0, _chunkUXNVTP4Dcjs.SynapError)(
1871
- `Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _64 => _64.message]), () => ( String(error)))}`,
1882
+ `Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _65 => _65.message]), () => ( String(error)))}`,
1872
1883
  { cause: error }
1873
1884
  );
1874
1885
  }
@@ -1914,7 +1925,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1914
1925
  _nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( ""))
1915
1926
  );
1916
1927
  if (eventType === "user_message" || eventType === "assistant_message") {
1917
- _optionalChain([onTurn, 'optionalCall', _65 => _65({
1928
+ _optionalChain([onTurn, 'optionalCall', _66 => _66({
1918
1929
  conversationId,
1919
1930
  role: _nullishCoalesce(options.role, () => ( "user")),
1920
1931
  content: options.content
@@ -1960,7 +1971,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
1960
1971
  async record_tool_result(options) {
1961
1972
  const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
1962
1973
  if (conversationId) {
1963
- _optionalChain([onToolResult, 'optionalCall', _66 => _66({ conversationId, result: options.result, toolName: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")) })]);
1974
+ _optionalChain([onToolResult, 'optionalCall', _67 => _67({ conversationId, result: options.result, toolName: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")) })]);
1964
1975
  }
1965
1976
  await namespace.send_message({
1966
1977
  content: "",
@@ -2012,7 +2023,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
2012
2023
  }
2013
2024
 
2014
2025
  // src/version.ts
2015
- var SDK_VERSION = "0.5.15";
2026
+ var SDK_VERSION = "0.5.16";
2016
2027
 
2017
2028
  // src/registry.ts
2018
2029
  var instances = /* @__PURE__ */ new Map();
@@ -2480,7 +2491,7 @@ var TurnStore = (_class3 = class {
2480
2491
  }
2481
2492
  /** Turns the server also holds: archived tool results are local only. Python: `count`. */
2482
2493
  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;
2494
+ 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
2495
  }
2485
2496
  sizeBytes() {
2486
2497
  let n2 = 0;
@@ -2659,7 +2670,7 @@ function askedKinds(query) {
2659
2670
  }
2660
2671
  function asksHowItStarted(query) {
2661
2672
  const spec = _chunkICUFS3B5cjs.HISTORY_SEARCH.early_query;
2662
- if (!_optionalChain([spec, 'optionalAccess', _71 => _71.pattern])) return false;
2673
+ if (!_optionalChain([spec, 'optionalAccess', _72 => _72.pattern])) return false;
2663
2674
  return new RegExp(spec.pattern, (_nullishCoalesce(spec.flags, () => ( ""))).includes("i") ? "i" : "").test(_nullishCoalesce(query, () => ( "")));
2664
2675
  }
2665
2676
  async function searchTurns(turns, query, options = {}) {
@@ -3872,7 +3883,7 @@ var SynapClient = (_class4 = class _SynapClient {
3872
3883
  this.#localEncoder = _nullishCoalesce(_nullishCoalesce(options.history_search_encoder, () => ( options.historySearchEncoder)), () => ( null));
3873
3884
  const modelOption = options.history_search_model !== void 0 ? options.history_search_model : options.historySearchModel;
3874
3885
  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);
3886
+ if (_optionalChain([this, 'access', _73 => _73.#localEncoder, 'optionalAccess', _74 => _74.model]) === _chunkICUFS3B5cjs.SEMANTIC_MATCH.model) this.#anticipationCache.setEncoder(this.#localEncoder);
3876
3887
  this.#turns = new TurnCounter();
3877
3888
  this.conversation = createConversationNamespace(
3878
3889
  this.#transport,
@@ -4368,14 +4379,14 @@ var SynapClient = (_class4 = class _SynapClient {
4368
4379
  }))
4369
4380
  );
4370
4381
  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);
4382
+ const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess', _75 => _75.serverMessageCount]), () => ( 0))) || 0);
4372
4383
  this.#maybeBackfillTurns(conversationId, total);
4373
4384
  if (!r["context_block"]) return response;
4374
4385
  const turns = store.turns(conversationId);
4375
4386
  let q = query;
4376
4387
  if (!q) {
4377
4388
  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]), () => ( ""));
4389
+ 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
4390
  }
4380
4391
  if (!q) return response;
4381
4392
  const exclude = /* @__PURE__ */ new Set();
@@ -4519,7 +4530,7 @@ function pick3(o2, snake, camel) {
4519
4530
  function resolveBaseUrl(options) {
4520
4531
  const explicit = _nullishCoalesce(options.baseUrl, () => ( options.api_base_url));
4521
4532
  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()]);
4533
+ const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _81 => _81.trim, 'call', _82 => _82()]);
4523
4534
  return fromEnv !== void 0 && fromEnv !== "" ? fromEnv : void 0;
4524
4535
  }
4525
4536
  function resolveCredentials(options) {