@maximem/synap-js-sdk 0.7.2 → 0.8.0

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/scaler/wt_shared_verify/synap/sdk/js/dist/grpc/index.cjs","../../src/grpc/index.ts"],"names":[],"mappings":"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","file":"/Users/scaler/wt_shared_verify/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/scaler/maximem_synap_wt_pitch/synap/sdk/js/dist/grpc/index.cjs","../../src/grpc/index.ts"],"names":[],"mappings":"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","file":"/Users/scaler/maximem_synap_wt_pitch/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
@@ -67,6 +67,7 @@ var ENDPOINTS = {
67
67
  memories_delete: { method: "DELETE", path: "/api/v1/memories/{memory_id}", idempotent: true },
68
68
  memories_forget: { method: "POST", path: "/api/v1/memories/forget", idempotent: false },
69
69
  data_delete: { method: "POST", path: "/v1/data/delete", idempotent: true },
70
+ data_restore: { method: "POST", path: "/v1/data/restore", idempotent: true },
70
71
  data_delete_status: { method: "GET", path: "/v1/data/delete/{deletion_id}", idempotent: true },
71
72
  context_fetch_user: { method: "POST", path: "/v1/context/user/fetch", idempotent: true },
72
73
  context_fetch_customer: { method: "POST", path: "/v1/context/customer/fetch", idempotent: true },
@@ -2130,20 +2131,35 @@ function createMemoriesInterface(transport, onForgotten) {
2130
2131
  body
2131
2132
  });
2132
2133
  },
2133
- async delete(memoryId) {
2134
+ async delete(memoryId, options) {
2135
+ const permanent = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _63 => _63.permanent]), () => ( false));
2136
+ if (typeof permanent !== "boolean") throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("permanent must be a boolean");
2134
2137
  if (!memoryId) {
2135
2138
  throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
2136
2139
  "memory_id is required. Deleting by user is no longer supported: the previous implementation tracked ids in process memory, so it silently deleted nothing in any serverless or multi-process deployment while reporting success."
2137
2140
  );
2138
2141
  }
2139
- return transport.request("memories_delete", { pathParams: { memory_id: memoryId } });
2142
+ const r = await transport.request("memories_delete", {
2143
+ pathParams: { memory_id: memoryId },
2144
+ ...permanent ? { query: { permanent: "true" } } : {}
2145
+ });
2146
+ return {
2147
+ memory_id: String(_nullishCoalesce(_optionalChain([r, 'optionalAccess', _64 => _64["memory_id"]]), () => ( memoryId))),
2148
+ deleted_at: String(_nullishCoalesce(_optionalChain([r, 'optionalAccess', _65 => _65["deleted_at"]]), () => ( ""))),
2149
+ fully_removed: _optionalChain([r, 'optionalAccess', _66 => _66["fully_removed"]]) === true,
2150
+ still_present_in: Array.isArray(_optionalChain([r, 'optionalAccess', _67 => _67["still_present_in"]])) ? r["still_present_in"] : [],
2151
+ source_text_kept: _optionalChain([r, 'optionalAccess', _68 => _68["source_text_kept"]]) === true,
2152
+ status: typeof _optionalChain([r, 'optionalAccess', _69 => _69["status"]]) === "string" && r["status"] ? r["status"] : "complete",
2153
+ purge_after: typeof _optionalChain([r, 'optionalAccess', _70 => _70["purge_after"]]) === "string" ? r["purge_after"] : null,
2154
+ permanent: _optionalChain([r, 'optionalAccess', _71 => _71["permanent"]]) === true
2155
+ };
2140
2156
  },
2141
2157
  async forget(options) {
2142
2158
  const o2 = options;
2143
2159
  await transport.checkCustomerId(_nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])), "memories.forget");
2144
2160
  const body = buildForgetBody(options);
2145
2161
  const result = await transport.request("memories_forget", { body });
2146
- const removed = !!_optionalChain([result, 'optionalAccess', _63 => _63.deleted_ids, 'optionalAccess', _64 => _64.length]) || _optionalChain([result, 'optionalAccess', _65 => _65.status]) === "deleted" || _optionalChain([result, 'optionalAccess', _66 => _66.status]) === "partial";
2162
+ const removed = !!_optionalChain([result, 'optionalAccess', _72 => _72.deleted_ids, 'optionalAccess', _73 => _73.length]) || _optionalChain([result, 'optionalAccess', _74 => _74.status]) === "deleted" || _optionalChain([result, 'optionalAccess', _75 => _75.status]) === "partial";
2147
2163
  if (removed && onForgotten) {
2148
2164
  try {
2149
2165
  onForgotten({
@@ -2183,14 +2199,14 @@ function sleep2(ms, signal) {
2183
2199
  if (ms <= 0) return Promise.resolve();
2184
2200
  return new Promise((resolve, reject) => {
2185
2201
  const timer = setTimeout(() => {
2186
- _optionalChain([signal, 'optionalAccess', _67 => _67.removeEventListener, 'call', _68 => _68("abort", onAbort)]);
2202
+ _optionalChain([signal, 'optionalAccess', _76 => _76.removeEventListener, 'call', _77 => _77("abort", onAbort)]);
2187
2203
  resolve();
2188
2204
  }, ms);
2189
2205
  function onAbort() {
2190
2206
  clearTimeout(timer);
2191
- reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _69 => _69.reason]), () => ( new Error("Aborted"))));
2207
+ reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _78 => _78.reason]), () => ( new Error("Aborted"))));
2192
2208
  }
2193
- _optionalChain([signal, 'optionalAccess', _70 => _70.addEventListener, 'call', _71 => _71("abort", onAbort, { once: true })]);
2209
+ _optionalChain([signal, 'optionalAccess', _79 => _79.addEventListener, 'call', _80 => _80("abort", onAbort, { once: true })]);
2194
2210
  });
2195
2211
  }
2196
2212
 
@@ -2271,7 +2287,7 @@ function buildRecordMessageBody(options, resolvedContent, field = "content") {
2271
2287
  content = resolvedContent;
2272
2288
  } else {
2273
2289
  const n2 = normaliseContent(options.content, field);
2274
- if (_optionalChain([n2, 'optionalAccess', _72 => _72.kind]) === "parts") {
2290
+ if (_optionalChain([n2, 'optionalAccess', _81 => _81.kind]) === "parts") {
2275
2291
  throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
2276
2292
  "content holds a FilePart, whose bytes have to be read first. Send it with conversation.record_message."
2277
2293
  );
@@ -2385,7 +2401,7 @@ function storedBatchRows(bodies, result) {
2385
2401
  const r = _nullishCoalesce(result, () => ( {}));
2386
2402
  const results = Array.isArray(r["results"]) ? r["results"] : [];
2387
2403
  const errors = Array.isArray(r["errors"]) ? r["errors"] : [];
2388
- const failed = new Set(errors.map((e) => _optionalChain([e, 'optionalAccess', _73 => _73["index"]])));
2404
+ const failed = new Set(errors.map((e) => _optionalChain([e, 'optionalAccess', _82 => _82["index"]])));
2389
2405
  const stored = bodies.filter((_, index) => !failed.has(index));
2390
2406
  if (stored.length !== results.length) return [];
2391
2407
  const pairs = [];
@@ -2429,7 +2445,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
2429
2445
  };
2430
2446
  const fetchImpl = ((url, init) => transport.fetchExternal(url, init));
2431
2447
  const validateMessage = (options, field = "content") => {
2432
- if (_optionalChain([normaliseContent, 'call', _74 => _74(options.content, field), 'optionalAccess', _75 => _75.kind]) === "parts") {
2448
+ if (_optionalChain([normaliseContent, 'call', _83 => _83(options.content, field), 'optionalAccess', _84 => _84.kind]) === "parts") {
2433
2449
  buildRecordMessageBody(options, "", field);
2434
2450
  } else {
2435
2451
  buildRecordMessageBody(options, void 0, field);
@@ -2437,7 +2453,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
2437
2453
  };
2438
2454
  const prepareMessage = async (options, field = "content") => {
2439
2455
  const n2 = normaliseContent(options.content, field);
2440
- if (_optionalChain([n2, 'optionalAccess', _76 => _76.kind]) !== "parts") {
2456
+ if (_optionalChain([n2, 'optionalAccess', _85 => _85.kind]) !== "parts") {
2441
2457
  const body = buildRecordMessageBody(options, void 0, field);
2442
2458
  return { body, mirror: String(_nullishCoalesce(body["content"], () => ( ""))) };
2443
2459
  }
@@ -2528,7 +2544,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
2528
2544
  const raw = await transport.request("conversations_ingest", { body });
2529
2545
  const result = {
2530
2546
  ...raw,
2531
- warnings: Array.isArray(_optionalChain([raw, 'optionalAccess', _77 => _77.warnings])) ? raw.warnings.map(String) : []
2547
+ warnings: Array.isArray(_optionalChain([raw, 'optionalAccess', _86 => _86.warnings])) ? raw.warnings.map(String) : []
2532
2548
  };
2533
2549
  onWrite({
2534
2550
  userId: body["user_id"],
@@ -2572,8 +2588,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
2572
2588
  pathParams: { conversation_id: id },
2573
2589
  query: { style }
2574
2590
  });
2575
- const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _78 => _78["context_for_prompt"]]), () => ( result)), () => ( {}));
2576
- _optionalChain([localShortTerm, 'access', _79 => _79.reseed, 'optionalCall', _80 => _80(id, response)]);
2591
+ const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _87 => _87["context_for_prompt"]]), () => ( result)), () => ( {}));
2592
+ _optionalChain([localShortTerm, 'access', _88 => _88.reseed, 'optionalCall', _89 => _89(id, response)]);
2577
2593
  return withHistory(response);
2578
2594
  },
2579
2595
  async compact(options) {
@@ -2633,6 +2649,7 @@ var ID_FIELD = {
2633
2649
  customer: "customer_id",
2634
2650
  conversation: "conversation_id"
2635
2651
  };
2652
+ var MAX_RESTORE_IDS = 200;
2636
2653
  function either3(o2, snake, camel) {
2637
2654
  const a = o2[snake];
2638
2655
  if (a !== void 0) return a;
@@ -2680,15 +2697,39 @@ function buildDeleteBody(options, instanceId) {
2680
2697
  throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(`confirm must equal the ${field} being deleted`);
2681
2698
  }
2682
2699
  }
2683
- return {
2700
+ const instances2 = options.instances === void 0 || options.instances === null ? null : checkInstances(options.instances);
2701
+ const permanent = _nullishCoalesce(options.permanent, () => ( false));
2702
+ if (typeof permanent !== "boolean") throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("permanent must be a boolean");
2703
+ const body = {
2684
2704
  scope,
2685
- instance_id: instanceId,
2705
+ // Without `instances` the body is byte-identical to earlier versions.
2706
+ instance_id: instances2 === null ? instanceId : null,
2686
2707
  user_id: _nullishCoalesce(ids["user_id"], () => ( null)),
2687
2708
  customer_id: _nullishCoalesce(ids["customer_id"], () => ( null)),
2688
2709
  conversation_id: _nullishCoalesce(ids["conversation_id"], () => ( null)),
2689
2710
  dry_run: dryRun,
2690
2711
  confirm
2691
2712
  };
2713
+ if (instances2 !== null) body["instance_ids"] = instances2;
2714
+ if (permanent) body["permanent"] = true;
2715
+ return body;
2716
+ }
2717
+ function checkInstances(instances2) {
2718
+ if (instances2 === "all") return "all";
2719
+ if (!Array.isArray(instances2)) {
2720
+ throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)('instances must be "all" or a list of instance ids');
2721
+ }
2722
+ const out = [];
2723
+ for (const i of instances2) {
2724
+ if (typeof i !== "string" || i.trim() === "") {
2725
+ throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("instances must not contain an empty instance id");
2726
+ }
2727
+ if (!out.includes(i.trim())) out.push(i.trim());
2728
+ }
2729
+ if (out.length === 0) {
2730
+ throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)('instances is empty: name at least one instance, or "all"');
2731
+ }
2732
+ return out;
2692
2733
  }
2693
2734
  function normalise(raw) {
2694
2735
  return {
@@ -2704,13 +2745,43 @@ function normalise(raw) {
2704
2745
  fully_removed: false,
2705
2746
  continue: false,
2706
2747
  kept: [],
2748
+ not_covered: [],
2707
2749
  note: null,
2708
2750
  memories_kept: false,
2709
2751
  audit: null,
2710
2752
  local_cleared: [],
2753
+ instances: [],
2754
+ not_started: [],
2755
+ deletion_ids: [],
2756
+ purge_after: null,
2711
2757
  ...raw
2712
2758
  };
2713
2759
  }
2760
+ function buildRestoreBody(memoryIds, instanceId, deletionId = null) {
2761
+ const noIds = memoryIds === null || memoryIds === void 0;
2762
+ const noDeletion = deletionId === null || deletionId === void 0;
2763
+ if (noIds === noDeletion) {
2764
+ throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("send exactly one of memory_ids or deletion_id");
2765
+ }
2766
+ if (!noDeletion) {
2767
+ if (typeof deletionId !== "string" || deletionId.trim() === "") {
2768
+ throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("deletion_id must not be empty");
2769
+ }
2770
+ return { deletion_id: deletionId.trim(), instance_id: instanceId };
2771
+ }
2772
+ if (typeof memoryIds === "string" || !Array.isArray(memoryIds)) {
2773
+ throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("memory_ids must be a list of memory ids");
2774
+ }
2775
+ const ids = memoryIds.map((i) => String(i));
2776
+ if (ids.length === 0) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("memory_ids must not be empty");
2777
+ if (ids.length > MAX_RESTORE_IDS) {
2778
+ throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("at most " + String(MAX_RESTORE_IDS) + " memory_ids per call");
2779
+ }
2780
+ if (ids.some((i) => i.trim() === "")) {
2781
+ throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("memory_ids must not contain empty ids");
2782
+ }
2783
+ return { memory_ids: ids, instance_id: instanceId };
2784
+ }
2714
2785
  function createDataInterface(transport, onDeleted) {
2715
2786
  return {
2716
2787
  async delete(options) {
@@ -2730,7 +2801,7 @@ function createDataInterface(transport, onDeleted) {
2730
2801
  if (dryRun || !result.continue) break;
2731
2802
  }
2732
2803
  const final = result;
2733
- if (!dryRun && ["complete", "partial", "in_progress"].includes(final.status) && onDeleted) {
2804
+ if (!dryRun && ["complete", "pending_purge", "partial", "in_progress"].includes(final.status) && onDeleted) {
2734
2805
  try {
2735
2806
  final.local_cleared = onDeleted({
2736
2807
  scope: body["scope"],
@@ -2753,6 +2824,29 @@ function createDataInterface(transport, onDeleted) {
2753
2824
  query: { instance_id: transport.currentCredentials().instanceId }
2754
2825
  })
2755
2826
  );
2827
+ },
2828
+ async restore(target) {
2829
+ const instanceId = transport.currentCredentials().instanceId;
2830
+ let body;
2831
+ if (Array.isArray(target) || typeof target === "string" || target === null || target === void 0) {
2832
+ body = buildRestoreBody(target, instanceId);
2833
+ } else {
2834
+ const o2 = target;
2835
+ body = buildRestoreBody(
2836
+ _nullishCoalesce(either3(o2, "memory_ids", "memoryIds"), () => ( null)),
2837
+ instanceId,
2838
+ _nullishCoalesce(either3(o2, "deletion_id", "deletionId"), () => ( null))
2839
+ );
2840
+ }
2841
+ const raw = await transport.request("data_restore", { body });
2842
+ return {
2843
+ restored_ids: [],
2844
+ not_restorable_ids: [],
2845
+ still_missing_in: [],
2846
+ reindexed_ids: [],
2847
+ fully_restored: false,
2848
+ ...raw
2849
+ };
2756
2850
  }
2757
2851
  };
2758
2852
  }
@@ -2970,8 +3064,8 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
2970
3064
  let onConversationState = null;
2971
3065
  const internals = {
2972
3066
  onCompactionUpdate(conversationId, bundle) {
2973
- _optionalChain([applyCompaction, 'optionalCall', _81 => _81(bundle)]);
2974
- _optionalChain([dispatchCompaction, 'optionalCall', _82 => _82(conversationId, bundle)]);
3067
+ _optionalChain([applyCompaction, 'optionalCall', _90 => _90(bundle)]);
3068
+ _optionalChain([dispatchCompaction, 'optionalCall', _91 => _91(conversationId, bundle)]);
2975
3069
  },
2976
3070
  setCompactionApplier(apply) {
2977
3071
  applyCompaction = apply;
@@ -2986,10 +3080,10 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
2986
3080
  onConversationState = handle;
2987
3081
  },
2988
3082
  sendContextUsed(event) {
2989
- _optionalChain([client, 'optionalAccess', _83 => _83.sendContextUsed, 'call', _84 => _84(event)]);
3083
+ _optionalChain([client, 'optionalAccess', _92 => _92.sendContextUsed, 'call', _93 => _93(event)]);
2990
3084
  },
2991
3085
  sendContextAssembled(event) {
2992
- _optionalChain([client, 'optionalAccess', _85 => _85.sendContextAssembled, 'call', _86 => _86(event)]);
3086
+ _optionalChain([client, 'optionalAccess', _94 => _94.sendContextAssembled, 'call', _95 => _95(event)]);
2993
3087
  },
2994
3088
  setCompactionDispatcher(dispatch) {
2995
3089
  dispatchCompaction = dispatch;
@@ -3030,7 +3124,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
3030
3124
  send(sync);
3031
3125
  return Promise.resolve();
3032
3126
  }
3033
- _optionalChain([prepared, 'optionalAccess', _87 => _87.catch, 'call', _88 => _88(() => {
3127
+ _optionalChain([prepared, 'optionalAccess', _96 => _96.catch, 'call', _97 => _97(() => {
3034
3128
  })]);
3035
3129
  queued += 1;
3036
3130
  const run = tail.then(async () => {
@@ -3049,7 +3143,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
3049
3143
  throw new (0, _chunkJPDEKN5Mcjs.ListeningAlreadyActiveError)("Listening is already active on this instance");
3050
3144
  }
3051
3145
  try {
3052
- _optionalChain([onListen, 'optionalCall', _89 => _89()]);
3146
+ _optionalChain([onListen, 'optionalCall', _98 => _98()]);
3053
3147
  } catch (e17) {
3054
3148
  }
3055
3149
  const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-H2ES74FF.cjs")));
@@ -3067,17 +3161,17 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
3067
3161
  internals.onCompactionUpdate(conversationId, bundle);
3068
3162
  },
3069
3163
  onConversationState: (conversationId, messageCount) => {
3070
- _optionalChain([onConversationState, 'optionalCall', _90 => _90(conversationId, messageCount)]);
3164
+ _optionalChain([onConversationState, 'optionalCall', _99 => _99(conversationId, messageCount)]);
3071
3165
  },
3072
3166
  onStateChange: (state) => {
3073
3167
  if (state !== "connected") openSessions.clear();
3074
3168
  if (state === "reconnecting") {
3075
3169
  reconnectAttempts += 1;
3076
- _optionalChain([onReconnect, 'optionalCall', _91 => _91(reconnectAttempts)]);
3170
+ _optionalChain([onReconnect, 'optionalCall', _100 => _100(reconnectAttempts)]);
3077
3171
  } else if (state === "disconnected") {
3078
- const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _92 => _92.lastError]), () => ( null));
3172
+ const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _101 => _101.lastError]), () => ( null));
3079
3173
  const reason = stopped === null ? "stream disconnected" : `credit_stop:${_nullishCoalesce(stopped.reason, () => ( "unknown"))}`;
3080
- _optionalChain([onDisconnect, 'optionalCall', _93 => _93(reason)]);
3174
+ _optionalChain([onDisconnect, 'optionalCall', _102 => _102(reason)]);
3081
3175
  }
3082
3176
  }
3083
3177
  });
@@ -3087,7 +3181,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
3087
3181
  } catch (error) {
3088
3182
  if (error instanceof _chunkJPDEKN5Mcjs.SynapError) throw error;
3089
3183
  throw new (0, _chunkJPDEKN5Mcjs.SynapError)(
3090
- `Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _94 => _94.message]), () => ( String(error)))}`,
3184
+ `Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _103 => _103.message]), () => ( String(error)))}`,
3091
3185
  { cause: error }
3092
3186
  );
3093
3187
  }
@@ -3143,7 +3237,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
3143
3237
  _nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( ""))
3144
3238
  );
3145
3239
  if (eventType === "user_message" || eventType === "assistant_message") {
3146
- _optionalChain([onTurn, 'optionalCall', _95 => _95({
3240
+ _optionalChain([onTurn, 'optionalCall', _104 => _104({
3147
3241
  conversationId,
3148
3242
  role: _nullishCoalesce(options.role, () => ( "user")),
3149
3243
  content
@@ -3175,8 +3269,8 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
3175
3269
  })()
3176
3270
  });
3177
3271
  };
3178
- if (_optionalChain([parts, 'optionalAccess', _96 => _96.kind]) !== "parts") {
3179
- const content = _optionalChain([parts, 'optionalAccess', _97 => _97.kind]) === "text" ? parts.text : options.content;
3272
+ if (_optionalChain([parts, 'optionalAccess', _105 => _105.kind]) !== "parts") {
3273
+ const content = _optionalChain([parts, 'optionalAccess', _106 => _106.kind]) === "text" ? parts.text : options.content;
3180
3274
  return inOrder(null, emit, { content, metadata: _nullishCoalesce(options.metadata, () => ( {})) });
3181
3275
  }
3182
3276
  const prepared = (async () => {
@@ -3214,7 +3308,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
3214
3308
  async record_tool_result(options) {
3215
3309
  const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
3216
3310
  if (conversationId) {
3217
- _optionalChain([onToolResult, 'optionalCall', _98 => _98({ conversationId, result: options.result, toolName: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")) })]);
3311
+ _optionalChain([onToolResult, 'optionalCall', _107 => _107({ conversationId, result: options.result, toolName: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")) })]);
3218
3312
  }
3219
3313
  await namespace.send_message({
3220
3314
  content: "",
@@ -3269,7 +3363,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
3269
3363
  }
3270
3364
 
3271
3365
  // src/version.ts
3272
- var SDK_VERSION = "0.7.2";
3366
+ var SDK_VERSION = "0.8.0";
3273
3367
 
3274
3368
  // src/registry.ts
3275
3369
  var instances = /* @__PURE__ */ new Map();
@@ -3742,7 +3836,7 @@ var TurnStore = (_class3 = class {
3742
3836
  }
3743
3837
  /** Turns the server also holds: archived tool results are local only. Python: `count`. */
3744
3838
  count(conversationId) {
3745
- return (_nullishCoalesce(_optionalChain([this, 'access', _99 => _99.#conversations, 'access', _100 => _100.get, 'call', _101 => _101(conversationId), 'optionalAccess', _102 => _102.turns]), () => ( []))).filter((t) => t.role !== "tool").length;
3839
+ return (_nullishCoalesce(_optionalChain([this, 'access', _108 => _108.#conversations, 'access', _109 => _109.get, 'call', _110 => _110(conversationId), 'optionalAccess', _111 => _111.turns]), () => ( []))).filter((t) => t.role !== "tool").length;
3746
3840
  }
3747
3841
  sizeBytes() {
3748
3842
  let n2 = 0;
@@ -3921,7 +4015,7 @@ function askedKinds(query) {
3921
4015
  }
3922
4016
  function asksHowItStarted(query) {
3923
4017
  const spec = _chunk6GHXJD7Lcjs.HISTORY_SEARCH.early_query;
3924
- if (!_optionalChain([spec, 'optionalAccess', _103 => _103.pattern])) return false;
4018
+ if (!_optionalChain([spec, 'optionalAccess', _112 => _112.pattern])) return false;
3925
4019
  return new RegExp(spec.pattern, (_nullishCoalesce(spec.flags, () => ( ""))).includes("i") ? "i" : "").test(_nullishCoalesce(query, () => ( "")));
3926
4020
  }
3927
4021
  async function searchTurns(turns, query, options = {}) {
@@ -5184,7 +5278,7 @@ var SynapClient = (_class4 = class _SynapClient {
5184
5278
  this.#localEncoder = _nullishCoalesce(_nullishCoalesce(options.history_search_encoder, () => ( options.historySearchEncoder)), () => ( null));
5185
5279
  const modelOption = options.history_search_model !== void 0 ? options.history_search_model : options.historySearchModel;
5186
5280
  this.#localModelName = modelOption === void 0 ? "auto" : modelOption;
5187
- if (_optionalChain([this, 'access', _104 => _104.#localEncoder, 'optionalAccess', _105 => _105.model]) === _chunk6GHXJD7Lcjs.SEMANTIC_MATCH.model) this.#anticipationCache.setEncoder(this.#localEncoder);
5281
+ if (_optionalChain([this, 'access', _113 => _113.#localEncoder, 'optionalAccess', _114 => _114.model]) === _chunk6GHXJD7Lcjs.SEMANTIC_MATCH.model) this.#anticipationCache.setEncoder(this.#localEncoder);
5188
5282
  this.#turns = new TurnCounter();
5189
5283
  this.conversation = createConversationNamespace(
5190
5284
  this.#transport,
@@ -5426,7 +5520,7 @@ var SynapClient = (_class4 = class _SynapClient {
5426
5520
  } catch (error) {
5427
5521
  if (this.#localMode) {
5428
5522
  throw new (0, _chunkJPDEKN5Mcjs.AuthenticationError)(
5429
- `Could not reach the Synap server at ${this.#transport.baseUrl}, or it did not identify itself: GET /api/v1/auth/whoami failed (${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _106 => _106.message]), () => ( String(error)))}).`,
5523
+ `Could not reach the Synap server at ${this.#transport.baseUrl}, or it did not identify itself: GET /api/v1/auth/whoami failed (${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _115 => _115.message]), () => ( String(error)))}).`,
5430
5524
  { cause: error }
5431
5525
  );
5432
5526
  }
@@ -5766,14 +5860,14 @@ var SynapClient = (_class4 = class _SynapClient {
5766
5860
  }))
5767
5861
  );
5768
5862
  const entry = this.#shortTerm.get(conversationId);
5769
- const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess', _107 => _107.serverMessageCount]), () => ( 0))) || 0);
5863
+ const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess', _116 => _116.serverMessageCount]), () => ( 0))) || 0);
5770
5864
  this.#maybeBackfillTurns(conversationId, total);
5771
5865
  if (!r["context_block"]) return response;
5772
5866
  const turns = store.turns(conversationId);
5773
5867
  let q = query;
5774
5868
  if (!q) {
5775
5869
  const latest = [...recent].reverse().find((m) => m["role"] === "user");
5776
- q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access', _108 => _108.reverse, 'call', _109 => _109(), 'access', _110 => _110.find, 'call', _111 => _111((t) => t.role === "user"), 'optionalAccess', _112 => _112.content]), () => ( ""));
5870
+ q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access', _117 => _117.reverse, 'call', _118 => _118(), 'access', _119 => _119.find, 'call', _120 => _120((t) => t.role === "user"), 'optionalAccess', _121 => _121.content]), () => ( ""));
5777
5871
  }
5778
5872
  if (!q) return response;
5779
5873
  const exclude = /* @__PURE__ */ new Set();
@@ -5919,7 +6013,7 @@ function pick3(o2, snake, camel) {
5919
6013
  function resolveBaseUrl(options) {
5920
6014
  const explicit = _nullishCoalesce(options.baseUrl, () => ( options.api_base_url));
5921
6015
  if (explicit !== void 0) return explicit;
5922
- const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _113 => _113.trim, 'call', _114 => _114()]);
6016
+ const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _122 => _122.trim, 'call', _123 => _123()]);
5923
6017
  return fromEnv !== void 0 && fromEnv !== "" ? fromEnv : void 0;
5924
6018
  }
5925
6019
  function resolveCredentials(options, localMode) {
@@ -6003,5 +6097,6 @@ function resolveCredentials(options, localMode) {
6003
6097
 
6004
6098
 
6005
6099
 
6006
- exports.ANY_SCOPE = _chunk6GHXJD7Lcjs.ANY_SCOPE; exports.AgentUnavailableError = _chunkJPDEKN5Mcjs.AgentUnavailableError; exports.AnticipationCache = _chunk6GHXJD7Lcjs.AnticipationCache; exports.AuthenticationError = _chunkJPDEKN5Mcjs.AuthenticationError; exports.BM25 = _chunk6GHXJD7Lcjs.BM25; exports.COMPACTION_LEVELS = COMPACTION_LEVELS; exports.CONTRACT = _chunk6GHXJD7Lcjs.CONTRACT; exports.ConflictError = _chunkJPDEKN5Mcjs.ConflictError; exports.ConnectionError = _chunkJPDEKN5Mcjs.ConnectionError; exports.ContextNotFoundError = _chunkJPDEKN5Mcjs.ContextNotFoundError; exports.CustomerIdNotAcceptedError = _chunkJPDEKN5Mcjs.CustomerIdNotAcceptedError; exports.DATA_SCOPES = DATA_SCOPES; exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL; exports.DEFAULT_DOCUMENT_TYPE = DEFAULT_DOCUMENT_TYPE; exports.DEFAULT_INGEST_MODE = DEFAULT_INGEST_MODE; exports.DEFAULT_RETRY_POLICY = DEFAULT_RETRY_POLICY; exports.DEFAULT_TIMEOUTS = DEFAULT_TIMEOUTS; exports.DOCUMENT_TYPES = DOCUMENT_TYPES; exports.ENDPOINTS = ENDPOINTS; exports.EXCERPT_CATEGORY = EXCERPT_CATEGORY; exports.FORGET_MODES = FORGET_MODES; exports.HttpTransport = HttpTransport; exports.INGEST_MODES = INGEST_MODES; exports.ITEM_COLLECTIONS = ITEM_COLLECTIONS; exports.InstanceBuildFailedError = _chunkJPDEKN5Mcjs.InstanceBuildFailedError; exports.InstanceNotReadyError = _chunkJPDEKN5Mcjs.InstanceNotReadyError; exports.InsufficientCreditsError = _chunkJPDEKN5Mcjs.InsufficientCreditsError; exports.InvalidConversationIdError = _chunkJPDEKN5Mcjs.InvalidConversationIdError; exports.InvalidInputError = _chunkJPDEKN5Mcjs.InvalidInputError; exports.InvalidInstanceIdError = _chunkJPDEKN5Mcjs.InvalidInstanceIdError; exports.ListeningAlreadyActiveError = _chunkJPDEKN5Mcjs.ListeningAlreadyActiveError; exports.ListeningNotActiveError = _chunkJPDEKN5Mcjs.ListeningNotActiveError; exports.MEMORY_TYPES = MEMORY_TYPES; exports.NetworkTimeoutError = _chunkJPDEKN5Mcjs.NetworkTimeoutError; exports.OBJECTIVES = OBJECTIVES; exports.PermanentError = _chunkJPDEKN5Mcjs.PermanentError; exports.RESPONSE_SHAPES = RESPONSE_SHAPES; exports.RateLimitError = _chunkJPDEKN5Mcjs.RateLimitError; exports.SDKError = _chunkJPDEKN5Mcjs.SDKError; exports.SDK_VERSION = SDK_VERSION; exports.ScopeAddress = ScopeAddress; exports.ScopeLadder = ScopeLadder; exports.ScopeLadderError = _chunkJPDEKN5Mcjs.ScopeLadderError; exports.ServiceUnavailableError = _chunkJPDEKN5Mcjs.ServiceUnavailableError; exports.SessionExpiredError = _chunkJPDEKN5Mcjs.SessionExpiredError; exports.SynapClient = SynapClient; exports.SynapError = _chunkJPDEKN5Mcjs.SynapError; exports.SynapPermanentError = _chunkJPDEKN5Mcjs.SynapPermanentError; exports.SynapTransientError = _chunkJPDEKN5Mcjs.SynapTransientError; exports.THRESHOLDS = _chunk6GHXJD7Lcjs.THRESHOLDS; exports.TranscriptConflictError = _chunkJPDEKN5Mcjs.TranscriptConflictError; exports.TransientError = _chunkJPDEKN5Mcjs.TransientError; exports.applyResponseShape = applyResponseShape; exports.filePart = filePart; exports.flattenContextItems = flattenContextItems; exports.formatForPrompt = formatForPrompt; exports.isOutcomeUnknown = isOutcomeUnknown; exports.isSynapError = _chunkJPDEKN5Mcjs.isSynapError; exports.mergeScopeResults = mergeScopeResults; exports.rankItems = rankItems; exports.resolvePath = resolvePath; exports.shouldRetry = shouldRetry; exports.stem = _chunk6GHXJD7Lcjs.stem; exports.textPart = textPart; exports.tokenize = _chunk6GHXJD7Lcjs.tokenize; exports.wireRankScore = wireRankScore;
6100
+
6101
+ exports.ANY_SCOPE = _chunk6GHXJD7Lcjs.ANY_SCOPE; exports.AgentUnavailableError = _chunkJPDEKN5Mcjs.AgentUnavailableError; exports.AnticipationCache = _chunk6GHXJD7Lcjs.AnticipationCache; exports.AuthenticationError = _chunkJPDEKN5Mcjs.AuthenticationError; exports.BM25 = _chunk6GHXJD7Lcjs.BM25; exports.COMPACTION_LEVELS = COMPACTION_LEVELS; exports.CONTRACT = _chunk6GHXJD7Lcjs.CONTRACT; exports.ConflictError = _chunkJPDEKN5Mcjs.ConflictError; exports.ConnectionError = _chunkJPDEKN5Mcjs.ConnectionError; exports.ContextNotFoundError = _chunkJPDEKN5Mcjs.ContextNotFoundError; exports.CustomerIdNotAcceptedError = _chunkJPDEKN5Mcjs.CustomerIdNotAcceptedError; exports.DATA_SCOPES = DATA_SCOPES; exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL; exports.DEFAULT_DOCUMENT_TYPE = DEFAULT_DOCUMENT_TYPE; exports.DEFAULT_INGEST_MODE = DEFAULT_INGEST_MODE; exports.DEFAULT_RETRY_POLICY = DEFAULT_RETRY_POLICY; exports.DEFAULT_TIMEOUTS = DEFAULT_TIMEOUTS; exports.DOCUMENT_TYPES = DOCUMENT_TYPES; exports.ENDPOINTS = ENDPOINTS; exports.EXCERPT_CATEGORY = EXCERPT_CATEGORY; exports.FORGET_MODES = FORGET_MODES; exports.HttpTransport = HttpTransport; exports.INGEST_MODES = INGEST_MODES; exports.ITEM_COLLECTIONS = ITEM_COLLECTIONS; exports.InstanceBuildFailedError = _chunkJPDEKN5Mcjs.InstanceBuildFailedError; exports.InstanceNotReadyError = _chunkJPDEKN5Mcjs.InstanceNotReadyError; exports.InsufficientCreditsError = _chunkJPDEKN5Mcjs.InsufficientCreditsError; exports.InvalidConversationIdError = _chunkJPDEKN5Mcjs.InvalidConversationIdError; exports.InvalidInputError = _chunkJPDEKN5Mcjs.InvalidInputError; exports.InvalidInstanceIdError = _chunkJPDEKN5Mcjs.InvalidInstanceIdError; exports.ListeningAlreadyActiveError = _chunkJPDEKN5Mcjs.ListeningAlreadyActiveError; exports.ListeningNotActiveError = _chunkJPDEKN5Mcjs.ListeningNotActiveError; exports.MAX_RESTORE_IDS = MAX_RESTORE_IDS; exports.MEMORY_TYPES = MEMORY_TYPES; exports.NetworkTimeoutError = _chunkJPDEKN5Mcjs.NetworkTimeoutError; exports.OBJECTIVES = OBJECTIVES; exports.PermanentError = _chunkJPDEKN5Mcjs.PermanentError; exports.RESPONSE_SHAPES = RESPONSE_SHAPES; exports.RateLimitError = _chunkJPDEKN5Mcjs.RateLimitError; exports.SDKError = _chunkJPDEKN5Mcjs.SDKError; exports.SDK_VERSION = SDK_VERSION; exports.ScopeAddress = ScopeAddress; exports.ScopeLadder = ScopeLadder; exports.ScopeLadderError = _chunkJPDEKN5Mcjs.ScopeLadderError; exports.ServiceUnavailableError = _chunkJPDEKN5Mcjs.ServiceUnavailableError; exports.SessionExpiredError = _chunkJPDEKN5Mcjs.SessionExpiredError; exports.SynapClient = SynapClient; exports.SynapError = _chunkJPDEKN5Mcjs.SynapError; exports.SynapPermanentError = _chunkJPDEKN5Mcjs.SynapPermanentError; exports.SynapTransientError = _chunkJPDEKN5Mcjs.SynapTransientError; exports.THRESHOLDS = _chunk6GHXJD7Lcjs.THRESHOLDS; exports.TranscriptConflictError = _chunkJPDEKN5Mcjs.TranscriptConflictError; exports.TransientError = _chunkJPDEKN5Mcjs.TransientError; exports.applyResponseShape = applyResponseShape; exports.filePart = filePart; exports.flattenContextItems = flattenContextItems; exports.formatForPrompt = formatForPrompt; exports.isOutcomeUnknown = isOutcomeUnknown; exports.isSynapError = _chunkJPDEKN5Mcjs.isSynapError; exports.mergeScopeResults = mergeScopeResults; exports.rankItems = rankItems; exports.resolvePath = resolvePath; exports.shouldRetry = shouldRetry; exports.stem = _chunk6GHXJD7Lcjs.stem; exports.textPart = textPart; exports.tokenize = _chunk6GHXJD7Lcjs.tokenize; exports.wireRankScore = wireRankScore;
6007
6102
  //# sourceMappingURL=index.cjs.map