@maximem/synap-js-sdk 0.5.2 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/anticipation-cache-LRE3TLK4.cjs.map +1 -1
- package/dist/{chunk-DJPYUPSV.js → chunk-RP4YOEUN.js} +6 -2
- package/dist/chunk-RP4YOEUN.js.map +1 -0
- package/dist/chunk-T372OL3Q.cjs.map +1 -1
- package/dist/chunk-T6U5PVAD.cjs.map +1 -1
- package/dist/{chunk-WWTGJZA7.cjs → chunk-WE4QSR6A.cjs} +6 -2
- package/dist/chunk-WE4QSR6A.cjs.map +1 -0
- package/dist/chunk-ZKOJDUN4.cjs.map +1 -1
- package/dist/env-55ULHNJZ.cjs.map +1 -1
- package/dist/grpc/index.cjs +3 -3
- package/dist/grpc/index.cjs.map +1 -1
- package/dist/grpc/index.d.cts +2 -2
- package/dist/grpc/index.d.ts +2 -2
- package/dist/grpc/index.js +2 -2
- package/dist/index.cjs +131 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +124 -7
- package/dist/index.d.ts +124 -7
- package/dist/index.js +107 -13
- package/dist/index.js.map +1 -1
- package/dist/stream-client-A6IO6E47.cjs +16 -0
- package/dist/stream-client-A6IO6E47.cjs.map +1 -0
- package/dist/{stream-client-5CGJNTH4.js → stream-client-Y5NFAMIH.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-DJPYUPSV.js.map +0 -1
- package/dist/chunk-WWTGJZA7.cjs.map +0 -1
- package/dist/stream-client-GJM4YSXW.cjs +0 -16
- package/dist/stream-client-GJM4YSXW.cjs.map +0 -1
- /package/dist/{stream-client-5CGJNTH4.js.map → stream-client-Y5NFAMIH.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/private/tmp/claude-501/-Users-anish-maximemai-maximem-synap/364ae6d0-b8b7-4119-bfaf-7676354661c6/scratchpad/jsrel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ADjBA;AACA;AACE;AACA;AACA;AACF,4FAAC","file":"/private/tmp/claude-501/-Users-anish-maximemai-maximem-synap/364ae6d0-b8b7-4119-bfaf-7676354661c6/scratchpad/jsrel/synap/sdk/js/dist/chunk-ZKOJDUN4.cjs","sourcesContent":[null,"/**\n * Environment access.\n *\n * Every read happens at CALL time, never at module load. Python does\n * `os.environ.get(...)` inside the function bodies, and tests plus runtime\n * toggles depend on that: a value captured at import time makes a later\n * `process.env` mutation look like the flag simply does not work. That is\n * gotcha G-S.\n *\n * `process` is absent on Workers and in the browser, so every accessor\n * tolerates it being missing.\n */\n\nconst TRUTHY = new Set(['true', '1', 'yes']);\n\nfunction readEnv(name: string): string | undefined {\n if (typeof process === 'undefined' || process.env === undefined) return undefined;\n return process.env[name];\n}\n\n/** Boolean flag. Defaults to false, matching the Python SDK's flags. */\nexport function getEnvFlag(name: string, fallback = false): boolean {\n const raw = readEnv(name);\n if (raw === undefined || raw.trim() === '') return fallback;\n return TRUTHY.has(raw.trim().toLowerCase());\n}\n\n/** Numeric setting. Returns null when unset OR malformed: a bad value must not fail closed. */\nexport function getEnvFloat(name: string): number | null {\n const raw = readEnv(name)?.trim();\n if (!raw) return null;\n const n = Number(raw);\n return Number.isFinite(n) ? n : null;\n}\n\nexport function getEnv(name: string): string | undefined {\n const v = readEnv(name);\n return v === undefined || v === '' ? undefined : v;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/private/tmp/claude-501/-Users-anish-maximemai-maximem-synap/364ae6d0-b8b7-4119-bfaf-7676354661c6/scratchpad/jsrel/synap/sdk/js/dist/env-55ULHNJZ.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,kJAAC","file":"/private/tmp/claude-501/-Users-anish-maximemai-maximem-synap/364ae6d0-b8b7-4119-bfaf-7676354661c6/scratchpad/jsrel/synap/sdk/js/dist/env-55ULHNJZ.cjs"}
|
package/dist/grpc/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkWE4QSR6Acjs = require('../chunk-WE4QSR6A.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
var _chunkT372OL3Qcjs = require('../chunk-T372OL3Q.cjs');
|
|
@@ -39,7 +39,7 @@ async function listen(options) {
|
|
|
39
39
|
throw new (0, _chunkT372OL3Qcjs.ListeningNotActiveError)(availability.detail);
|
|
40
40
|
}
|
|
41
41
|
const [{ GrpcStreamClient: StreamClient }, { AnticipationCache }, { getEnv }] = await Promise.all([
|
|
42
|
-
Promise.resolve().then(() => _interopRequireWildcard(require("../stream-client-
|
|
42
|
+
Promise.resolve().then(() => _interopRequireWildcard(require("../stream-client-A6IO6E47.cjs"))),
|
|
43
43
|
Promise.resolve().then(() => _interopRequireWildcard(require("../anticipation-cache-LRE3TLK4.cjs"))),
|
|
44
44
|
Promise.resolve().then(() => _interopRequireWildcard(require("../env-55ULHNJZ.cjs")))
|
|
45
45
|
]);
|
|
@@ -83,5 +83,5 @@ async function listen(options) {
|
|
|
83
83
|
|
|
84
84
|
|
|
85
85
|
|
|
86
|
-
exports.GrpcStreamClient =
|
|
86
|
+
exports.GrpcStreamClient = _chunkWE4QSR6Acjs.GrpcStreamClient; exports.PROTO_SHA = _chunkWE4QSR6Acjs.PROTO_SHA; exports.checkGrpcAvailability = checkGrpcAvailability; exports.listen = listen;
|
|
87
87
|
//# sourceMappingURL=index.cjs.map
|
package/dist/grpc/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/private/tmp/claude-501/-Users-anish-maximemai-maximem-synap/364ae6d0-b8b7-4119-bfaf-7676354661c6/scratchpad/jsrel/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,oI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AACA;AACA;AACA;AACF,+LAAC","file":"/private/tmp/claude-501/-Users-anish-maximemai-maximem-synap/364ae6d0-b8b7-4119-bfaf-7676354661c6/scratchpad/jsrel/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/grpc/index.d.cts
CHANGED
|
@@ -128,14 +128,14 @@ declare class GrpcStreamClient {
|
|
|
128
128
|
*
|
|
129
129
|
* Source: synap/proto/synap_service.proto
|
|
130
130
|
* Generator: synap/sdk/scripts/gen_proto_descriptor.mjs
|
|
131
|
-
* Proto SHA:
|
|
131
|
+
* Proto SHA: a0813b78a8c5d8dc
|
|
132
132
|
*
|
|
133
133
|
* The proto is inlined as a JSON descriptor rather than loaded from disk so
|
|
134
134
|
* that bundlers and Vercel file tracing cannot lose it. Regenerate with
|
|
135
135
|
* `npm run sync-behavior` in synap/sdk/js.
|
|
136
136
|
*/
|
|
137
137
|
/** sha256 (first 16 hex chars) of the proto this descriptor was built from. */
|
|
138
|
-
declare const PROTO_SHA = "
|
|
138
|
+
declare const PROTO_SHA = "a0813b78a8c5d8dc";
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
141
|
* gRPC anticipation stream: availability and loading.
|
package/dist/grpc/index.d.ts
CHANGED
|
@@ -128,14 +128,14 @@ declare class GrpcStreamClient {
|
|
|
128
128
|
*
|
|
129
129
|
* Source: synap/proto/synap_service.proto
|
|
130
130
|
* Generator: synap/sdk/scripts/gen_proto_descriptor.mjs
|
|
131
|
-
* Proto SHA:
|
|
131
|
+
* Proto SHA: a0813b78a8c5d8dc
|
|
132
132
|
*
|
|
133
133
|
* The proto is inlined as a JSON descriptor rather than loaded from disk so
|
|
134
134
|
* that bundlers and Vercel file tracing cannot lose it. Regenerate with
|
|
135
135
|
* `npm run sync-behavior` in synap/sdk/js.
|
|
136
136
|
*/
|
|
137
137
|
/** sha256 (first 16 hex chars) of the proto this descriptor was built from. */
|
|
138
|
-
declare const PROTO_SHA = "
|
|
138
|
+
declare const PROTO_SHA = "a0813b78a8c5d8dc";
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
141
|
* gRPC anticipation stream: availability and loading.
|
package/dist/grpc/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
GrpcStreamClient,
|
|
3
3
|
PROTO_SHA
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-RP4YOEUN.js";
|
|
5
5
|
import {
|
|
6
6
|
ListeningNotActiveError
|
|
7
7
|
} from "../chunk-BWMPKLFG.js";
|
|
@@ -39,7 +39,7 @@ async function listen(options) {
|
|
|
39
39
|
throw new ListeningNotActiveError(availability.detail);
|
|
40
40
|
}
|
|
41
41
|
const [{ GrpcStreamClient: StreamClient }, { AnticipationCache }, { getEnv }] = await Promise.all([
|
|
42
|
-
import("../stream-client-
|
|
42
|
+
import("../stream-client-Y5NFAMIH.js"),
|
|
43
43
|
import("../anticipation-cache-WLU4NMD5.js"),
|
|
44
44
|
import("../env-QCUKKW36.js")
|
|
45
45
|
]);
|
package/dist/index.cjs
CHANGED
|
@@ -49,6 +49,7 @@ var ENDPOINTS = {
|
|
|
49
49
|
memories_get: { method: "GET", path: "/api/v1/memories/{memory_id}", idempotent: true },
|
|
50
50
|
memories_update: { method: "PATCH", path: "/api/v1/memories/{memory_id}", idempotent: false },
|
|
51
51
|
memories_delete: { method: "DELETE", path: "/api/v1/memories/{memory_id}", idempotent: true },
|
|
52
|
+
memories_forget: { method: "POST", path: "/api/v1/memories/forget", idempotent: false },
|
|
52
53
|
context_fetch_user: { method: "POST", path: "/v1/context/user/fetch", idempotent: true },
|
|
53
54
|
context_fetch_customer: { method: "POST", path: "/v1/context/customer/fetch", idempotent: true },
|
|
54
55
|
context_fetch_client: { method: "POST", path: "/v1/context/client/fetch", idempotent: true },
|
|
@@ -536,6 +537,8 @@ function buildFetchRequest(scope, options) {
|
|
|
536
537
|
const searchQuery = opt(options, "search_query", "searchQuery");
|
|
537
538
|
const maxResults = _nullishCoalesce(opt(options, "max_results", "maxResults"), () => ( 10));
|
|
538
539
|
const precisionLevel = _nullishCoalesce(opt(options, "precision_level", "precisionLevel"), () => ( "high"));
|
|
540
|
+
const queryDate = opt(options, "query_date", "queryDate");
|
|
541
|
+
const perQuery = opt(options, "max_results_per_query", "maxResultsPerQuery");
|
|
539
542
|
const mode = _nullishCoalesce(options.mode, () => ( "fast"));
|
|
540
543
|
if (searchQuery !== void 0 && !Array.isArray(searchQuery)) {
|
|
541
544
|
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("search_query must be an array when provided");
|
|
@@ -551,6 +554,8 @@ function buildFetchRequest(scope, options) {
|
|
|
551
554
|
mode
|
|
552
555
|
};
|
|
553
556
|
if (precisionLevel !== "high") body["precision_level"] = precisionLevel;
|
|
557
|
+
if (queryDate) body["query_date"] = queryDate;
|
|
558
|
+
if (perQuery) body["max_results_per_query"] = perQuery;
|
|
554
559
|
if (options.include_conversation_context === false) {
|
|
555
560
|
body["include_conversation_context"] = false;
|
|
556
561
|
}
|
|
@@ -626,6 +631,10 @@ function pick(...values) {
|
|
|
626
631
|
return pickDefined(...values);
|
|
627
632
|
}
|
|
628
633
|
var obj = (v) => _nullishCoalesce(v, () => ( {}));
|
|
634
|
+
function matchedQueries(item = {}) {
|
|
635
|
+
const raw = _nullishCoalesce(item["matchedQueries"], () => ( item.matched_queries));
|
|
636
|
+
return Array.isArray(raw) ? raw : [];
|
|
637
|
+
}
|
|
629
638
|
function normalizeTemporalFields(item = {}) {
|
|
630
639
|
return {
|
|
631
640
|
eventDate: pick(item["eventDate"], item.event_date, null),
|
|
@@ -642,7 +651,8 @@ function normalizeFact(item = {}) {
|
|
|
642
651
|
source: item.source || "",
|
|
643
652
|
extractedAt: pick(item["extractedAt"], item.extracted_at, null),
|
|
644
653
|
metadata: obj(item.metadata),
|
|
645
|
-
...normalizeTemporalFields(item)
|
|
654
|
+
...normalizeTemporalFields(item),
|
|
655
|
+
matchedQueries: matchedQueries(item)
|
|
646
656
|
};
|
|
647
657
|
}
|
|
648
658
|
function normalizePreference(item = {}) {
|
|
@@ -654,7 +664,8 @@ function normalizePreference(item = {}) {
|
|
|
654
664
|
source: item.source || "",
|
|
655
665
|
extractedAt: pick(item["extractedAt"], item.extracted_at, null),
|
|
656
666
|
metadata: obj(item.metadata),
|
|
657
|
-
...normalizeTemporalFields(item)
|
|
667
|
+
...normalizeTemporalFields(item),
|
|
668
|
+
matchedQueries: matchedQueries(item)
|
|
658
669
|
};
|
|
659
670
|
}
|
|
660
671
|
function normalizeEpisode(item = {}) {
|
|
@@ -665,7 +676,8 @@ function normalizeEpisode(item = {}) {
|
|
|
665
676
|
significance: pick(item["significance"], item.confidence, 0),
|
|
666
677
|
participants: item["participants"] || [],
|
|
667
678
|
metadata: obj(item.metadata),
|
|
668
|
-
...normalizeTemporalFields(item)
|
|
679
|
+
...normalizeTemporalFields(item),
|
|
680
|
+
matchedQueries: matchedQueries(item)
|
|
669
681
|
};
|
|
670
682
|
}
|
|
671
683
|
function normalizeEmotion(item = {}) {
|
|
@@ -676,7 +688,8 @@ function normalizeEmotion(item = {}) {
|
|
|
676
688
|
detectedAt: pick(item["detectedAt"], item["detected_at"], null),
|
|
677
689
|
context: item["context"] || "",
|
|
678
690
|
metadata: obj(item.metadata),
|
|
679
|
-
...normalizeTemporalFields(item)
|
|
691
|
+
...normalizeTemporalFields(item),
|
|
692
|
+
matchedQueries: matchedQueries(item)
|
|
680
693
|
};
|
|
681
694
|
}
|
|
682
695
|
function normalizeTemporalEvent(item = {}) {
|
|
@@ -690,7 +703,8 @@ function normalizeTemporalEvent(item = {}) {
|
|
|
690
703
|
confidence: pick(item.confidence, 0),
|
|
691
704
|
source: item.source || "",
|
|
692
705
|
extractedAt: pick(item["extractedAt"], item.extracted_at, null),
|
|
693
|
-
metadata: obj(item.metadata)
|
|
706
|
+
metadata: obj(item.metadata),
|
|
707
|
+
matchedQueries: matchedQueries(item)
|
|
694
708
|
};
|
|
695
709
|
}
|
|
696
710
|
function normalizeContextMetadata(metadata = {}) {
|
|
@@ -864,8 +878,33 @@ function buildCreateBody(options) {
|
|
|
864
878
|
metadata: _nullishCoalesce(options.metadata, () => ( {}))
|
|
865
879
|
};
|
|
866
880
|
}
|
|
881
|
+
var FORGET_MODES = ["preview", "direct"];
|
|
882
|
+
var FORGET_DESCRIPTION_MIN = 3;
|
|
883
|
+
var FORGET_DESCRIPTION_MAX = 500;
|
|
884
|
+
function buildForgetBody(options) {
|
|
885
|
+
const description = options.description;
|
|
886
|
+
if (typeof description !== "string" || description.length < FORGET_DESCRIPTION_MIN || description.length > FORGET_DESCRIPTION_MAX) {
|
|
887
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
|
|
888
|
+
`description must be between ${FORGET_DESCRIPTION_MIN} and ${FORGET_DESCRIPTION_MAX} characters`
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
const mode = _nullishCoalesce(options.mode, () => ( "preview"));
|
|
892
|
+
if (!FORGET_MODES.includes(mode)) {
|
|
893
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
|
|
894
|
+
`Invalid mode '${mode}'. Expected one of: ${FORGET_MODES.join(", ")}`
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
const o2 = options;
|
|
898
|
+
return {
|
|
899
|
+
description,
|
|
900
|
+
user_id: _nullishCoalesce(either(o2, "user_id", "userId"), () => ( null)),
|
|
901
|
+
customer_id: _nullishCoalesce(either(o2, "customer_id", "customerId"), () => ( null)),
|
|
902
|
+
scope: _nullishCoalesce(options.scope, () => ( null)),
|
|
903
|
+
mode
|
|
904
|
+
};
|
|
905
|
+
}
|
|
867
906
|
var TERMINAL_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "error", "cancelled"]);
|
|
868
|
-
function createMemoriesInterface(transport) {
|
|
907
|
+
function createMemoriesInterface(transport, onForgotten) {
|
|
869
908
|
return {
|
|
870
909
|
async create(options) {
|
|
871
910
|
const o2 = options;
|
|
@@ -951,6 +990,23 @@ function createMemoriesInterface(transport) {
|
|
|
951
990
|
}
|
|
952
991
|
return transport.request("memories_delete", { pathParams: { memory_id: memoryId } });
|
|
953
992
|
},
|
|
993
|
+
async forget(options) {
|
|
994
|
+
const o2 = options;
|
|
995
|
+
transport.checkCustomerId(_nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])), "memories.forget");
|
|
996
|
+
const body = buildForgetBody(options);
|
|
997
|
+
const result = await transport.request("memories_forget", { body });
|
|
998
|
+
const removed = !!_optionalChain([result, 'optionalAccess', _33 => _33.deleted_ids, 'optionalAccess', _34 => _34.length]) || _optionalChain([result, 'optionalAccess', _35 => _35.status]) === "deleted" || _optionalChain([result, 'optionalAccess', _36 => _36.status]) === "partial";
|
|
999
|
+
if (removed && onForgotten) {
|
|
1000
|
+
try {
|
|
1001
|
+
onForgotten({
|
|
1002
|
+
userId: _nullishCoalesce(body["user_id"], () => ( null)),
|
|
1003
|
+
customerId: _nullishCoalesce(body["customer_id"], () => ( null))
|
|
1004
|
+
});
|
|
1005
|
+
} catch (e5) {
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
return result;
|
|
1009
|
+
},
|
|
954
1010
|
async status(ingestionId) {
|
|
955
1011
|
if (!ingestionId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("ingestion_id is required");
|
|
956
1012
|
return transport.request("memories_status", {
|
|
@@ -979,14 +1035,14 @@ function sleep2(ms, signal) {
|
|
|
979
1035
|
if (ms <= 0) return Promise.resolve();
|
|
980
1036
|
return new Promise((resolve, reject) => {
|
|
981
1037
|
const timer = setTimeout(() => {
|
|
982
|
-
_optionalChain([signal, 'optionalAccess',
|
|
1038
|
+
_optionalChain([signal, 'optionalAccess', _37 => _37.removeEventListener, 'call', _38 => _38("abort", onAbort)]);
|
|
983
1039
|
resolve();
|
|
984
1040
|
}, ms);
|
|
985
1041
|
function onAbort() {
|
|
986
1042
|
clearTimeout(timer);
|
|
987
|
-
reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess',
|
|
1043
|
+
reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _39 => _39.reason]), () => ( new Error("Aborted"))));
|
|
988
1044
|
}
|
|
989
|
-
_optionalChain([signal, 'optionalAccess',
|
|
1045
|
+
_optionalChain([signal, 'optionalAccess', _40 => _40.addEventListener, 'call', _41 => _41("abort", onAbort, { once: true })]);
|
|
990
1046
|
});
|
|
991
1047
|
}
|
|
992
1048
|
|
|
@@ -1225,7 +1281,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1225
1281
|
pathParams: { conversation_id: id },
|
|
1226
1282
|
query: { style: _nullishCoalesce(options.style, () => ( "structured")) }
|
|
1227
1283
|
});
|
|
1228
|
-
return _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
1284
|
+
return _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _42 => _42["context_for_prompt"]]), () => ( result)), () => ( {}));
|
|
1229
1285
|
},
|
|
1230
1286
|
async compact(options) {
|
|
1231
1287
|
return transport.request("conversations_compact", { body: buildCompactBody(options) });
|
|
@@ -1391,7 +1447,22 @@ var KNOWN_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
|
1391
1447
|
]);
|
|
1392
1448
|
function toolResultJson(result) {
|
|
1393
1449
|
if (result === void 0 || result === null) return "";
|
|
1394
|
-
return typeof result === "string" ? result :
|
|
1450
|
+
return typeof result === "string" ? result : jsonOrText(result);
|
|
1451
|
+
}
|
|
1452
|
+
function jsonOrText(value) {
|
|
1453
|
+
try {
|
|
1454
|
+
const out = JSON.stringify(
|
|
1455
|
+
value,
|
|
1456
|
+
(_k, v) => typeof v === "bigint" ? String(v) : v
|
|
1457
|
+
);
|
|
1458
|
+
return out === void 0 ? String(value) : out;
|
|
1459
|
+
} catch (e6) {
|
|
1460
|
+
try {
|
|
1461
|
+
return String(value);
|
|
1462
|
+
} catch (e7) {
|
|
1463
|
+
return "";
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1395
1466
|
}
|
|
1396
1467
|
function createInstanceNamespace(credentials, cache, onTurn) {
|
|
1397
1468
|
let client = null;
|
|
@@ -1400,17 +1471,17 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1400
1471
|
let applyCompaction = null;
|
|
1401
1472
|
const internals = {
|
|
1402
1473
|
onCompactionUpdate(conversationId, bundle) {
|
|
1403
|
-
_optionalChain([applyCompaction, 'optionalCall',
|
|
1404
|
-
_optionalChain([dispatchCompaction, 'optionalCall',
|
|
1474
|
+
_optionalChain([applyCompaction, 'optionalCall', _43 => _43(bundle)]);
|
|
1475
|
+
_optionalChain([dispatchCompaction, 'optionalCall', _44 => _44(conversationId, bundle)]);
|
|
1405
1476
|
},
|
|
1406
1477
|
setCompactionApplier(apply) {
|
|
1407
1478
|
applyCompaction = apply;
|
|
1408
1479
|
},
|
|
1409
1480
|
sendContextUsed(event) {
|
|
1410
|
-
_optionalChain([client, 'optionalAccess',
|
|
1481
|
+
_optionalChain([client, 'optionalAccess', _45 => _45.sendContextUsed, 'call', _46 => _46(event)]);
|
|
1411
1482
|
},
|
|
1412
1483
|
sendContextAssembled(event) {
|
|
1413
|
-
_optionalChain([client, 'optionalAccess',
|
|
1484
|
+
_optionalChain([client, 'optionalAccess', _47 => _47.sendContextAssembled, 'call', _48 => _48(event)]);
|
|
1414
1485
|
},
|
|
1415
1486
|
setCompactionDispatcher(dispatch) {
|
|
1416
1487
|
dispatchCompaction = dispatch;
|
|
@@ -1432,7 +1503,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1432
1503
|
...customerId ? { customer_id: customerId } : {}
|
|
1433
1504
|
});
|
|
1434
1505
|
openSessions.set(conversationId, sessionId);
|
|
1435
|
-
} catch (
|
|
1506
|
+
} catch (e8) {
|
|
1436
1507
|
}
|
|
1437
1508
|
}
|
|
1438
1509
|
const namespace = {
|
|
@@ -1440,7 +1511,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1440
1511
|
if (client !== null) {
|
|
1441
1512
|
throw new (0, _chunkT372OL3Qcjs.ListeningAlreadyActiveError)("Listening is already active on this instance");
|
|
1442
1513
|
}
|
|
1443
|
-
const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-
|
|
1514
|
+
const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-A6IO6E47.cjs")));
|
|
1444
1515
|
const onContext = _nullishCoalesce(options.on_context, () => ( options.onContext));
|
|
1445
1516
|
const onDisconnect = _nullishCoalesce(options.on_disconnect, () => ( options.onDisconnect));
|
|
1446
1517
|
const onReconnect = _nullishCoalesce(options.on_reconnect, () => ( options.onReconnect));
|
|
@@ -1458,11 +1529,11 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1458
1529
|
if (state !== "connected") openSessions.clear();
|
|
1459
1530
|
if (state === "reconnecting") {
|
|
1460
1531
|
reconnectAttempts += 1;
|
|
1461
|
-
_optionalChain([onReconnect, 'optionalCall',
|
|
1532
|
+
_optionalChain([onReconnect, 'optionalCall', _49 => _49(reconnectAttempts)]);
|
|
1462
1533
|
} else if (state === "disconnected") {
|
|
1463
|
-
const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess',
|
|
1534
|
+
const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _50 => _50.lastError]), () => ( null));
|
|
1464
1535
|
const reason = stopped === null ? "stream disconnected" : `credit_stop:${_nullishCoalesce(stopped.reason, () => ( "unknown"))}`;
|
|
1465
|
-
_optionalChain([onDisconnect, 'optionalCall',
|
|
1536
|
+
_optionalChain([onDisconnect, 'optionalCall', _51 => _51(reason)]);
|
|
1466
1537
|
}
|
|
1467
1538
|
}
|
|
1468
1539
|
});
|
|
@@ -1472,7 +1543,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1472
1543
|
} catch (error) {
|
|
1473
1544
|
if (error instanceof _chunkT372OL3Qcjs.SynapError) throw error;
|
|
1474
1545
|
throw new (0, _chunkT372OL3Qcjs.SynapError)(
|
|
1475
|
-
`Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess',
|
|
1546
|
+
`Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _52 => _52.message]), () => ( String(error)))}`,
|
|
1476
1547
|
{ cause: error }
|
|
1477
1548
|
);
|
|
1478
1549
|
}
|
|
@@ -1497,7 +1568,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1497
1568
|
session_id: sessionId,
|
|
1498
1569
|
conversation_id: conversationId
|
|
1499
1570
|
});
|
|
1500
|
-
} catch (
|
|
1571
|
+
} catch (e9) {
|
|
1501
1572
|
}
|
|
1502
1573
|
},
|
|
1503
1574
|
async send_message(options) {
|
|
@@ -1518,7 +1589,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1518
1589
|
_nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( ""))
|
|
1519
1590
|
);
|
|
1520
1591
|
if (eventType === "user_message" || eventType === "assistant_message") {
|
|
1521
|
-
_optionalChain([onTurn, 'optionalCall',
|
|
1592
|
+
_optionalChain([onTurn, 'optionalCall', _53 => _53({
|
|
1522
1593
|
conversationId,
|
|
1523
1594
|
role: _nullishCoalesce(options.role, () => ( "user")),
|
|
1524
1595
|
content: options.content
|
|
@@ -1538,7 +1609,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1538
1609
|
// Python serialises tool_args with json.dumps into tool_args_json.
|
|
1539
1610
|
tool_args_json: (() => {
|
|
1540
1611
|
const a = _nullishCoalesce(options.tool_args, () => ( options.toolArgs));
|
|
1541
|
-
return a === void 0 ? "" :
|
|
1612
|
+
return a === void 0 ? "" : jsonOrText(a);
|
|
1542
1613
|
})(),
|
|
1543
1614
|
tool_result_json: toolResultJson(_nullishCoalesce(options.tool_result, () => ( options.toolResult))),
|
|
1544
1615
|
tool_call_id: _nullishCoalesce(_nullishCoalesce(options.tool_call_id, () => ( options.toolCallId)), () => ( "")),
|
|
@@ -1612,7 +1683,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1612
1683
|
}
|
|
1613
1684
|
|
|
1614
1685
|
// src/version.ts
|
|
1615
|
-
var SDK_VERSION = "0.5.
|
|
1686
|
+
var SDK_VERSION = "0.5.6";
|
|
1616
1687
|
|
|
1617
1688
|
// src/registry.ts
|
|
1618
1689
|
var instances = /* @__PURE__ */ new Map();
|
|
@@ -1824,7 +1895,7 @@ function overlayLocalRecentTurns(response, store, conversationId, configured) {
|
|
|
1824
1895
|
compacted_at: orLocal("compacted_at", entry.compactedAt),
|
|
1825
1896
|
conversation_id: conversationId
|
|
1826
1897
|
};
|
|
1827
|
-
} catch (
|
|
1898
|
+
} catch (e10) {
|
|
1828
1899
|
}
|
|
1829
1900
|
}
|
|
1830
1901
|
|
|
@@ -1837,7 +1908,7 @@ function stringify(value) {
|
|
|
1837
1908
|
if (t === "string" || t === "number" || t === "boolean") return String(value);
|
|
1838
1909
|
try {
|
|
1839
1910
|
return _nullishCoalesce(JSON.stringify(value), () => ( ""));
|
|
1840
|
-
} catch (
|
|
1911
|
+
} catch (e11) {
|
|
1841
1912
|
return String(value);
|
|
1842
1913
|
}
|
|
1843
1914
|
}
|
|
@@ -2111,10 +2182,14 @@ function tryServeFromCache(cache, scope, params, maxItems) {
|
|
|
2111
2182
|
});
|
|
2112
2183
|
if (hit === null) return { response: null, hit: null };
|
|
2113
2184
|
return { response: buildAnticipationResponse(hit), hit };
|
|
2114
|
-
} catch (
|
|
2185
|
+
} catch (e12) {
|
|
2115
2186
|
return { response: null, hit: null };
|
|
2116
2187
|
}
|
|
2117
2188
|
}
|
|
2189
|
+
function distinctQueryCount(searchQuery) {
|
|
2190
|
+
if (!Array.isArray(searchQuery)) return 0;
|
|
2191
|
+
return new Set(searchQuery.filter((q) => typeof q === "string" && q.length > 0)).size;
|
|
2192
|
+
}
|
|
2118
2193
|
|
|
2119
2194
|
// src/context/assembled.ts
|
|
2120
2195
|
var COLLECTIONS2 = ["facts", "preferences", "episodes", "emotions", "temporal_events"];
|
|
@@ -2611,6 +2686,8 @@ var SynapClient = class {
|
|
|
2611
2686
|
this.#fetchHooks = {
|
|
2612
2687
|
beforeFetch: (scope, options2) => {
|
|
2613
2688
|
const o2 = options2;
|
|
2689
|
+
if (_nullishCoalesce(o2["query_date"], () => ( o2["queryDate"]))) return null;
|
|
2690
|
+
if (_nullishCoalesce(o2["max_results_per_query"], () => ( o2["maxResultsPerQuery"]))) return null;
|
|
2614
2691
|
const attempt = tryServeFromCache(
|
|
2615
2692
|
this.#anticipationCache,
|
|
2616
2693
|
scope,
|
|
@@ -2681,7 +2758,11 @@ var SynapClient = class {
|
|
|
2681
2758
|
compacted: (conversationId, format) => this.#localCompacted(conversationId, format)
|
|
2682
2759
|
}
|
|
2683
2760
|
);
|
|
2684
|
-
this.memories = createMemoriesInterface(this.#transport)
|
|
2761
|
+
this.memories = createMemoriesInterface(this.#transport, ({ userId, customerId }) => {
|
|
2762
|
+
for (const id of /* @__PURE__ */ new Set([userId, customerId])) {
|
|
2763
|
+
if (id) this.#anticipationCache.dropEntity(id);
|
|
2764
|
+
}
|
|
2765
|
+
});
|
|
2685
2766
|
this.credits = createCreditsNamespace(this.#transport);
|
|
2686
2767
|
this.cache = createCacheNamespace(this.#anticipationCache);
|
|
2687
2768
|
this.instance = createInstanceNamespace(
|
|
@@ -2811,7 +2892,7 @@ var SynapClient = class {
|
|
|
2811
2892
|
this.#registryKeys.push(resolvedInstanceId);
|
|
2812
2893
|
}
|
|
2813
2894
|
}
|
|
2814
|
-
} catch (
|
|
2895
|
+
} catch (e13) {
|
|
2815
2896
|
}
|
|
2816
2897
|
}
|
|
2817
2898
|
/**
|
|
@@ -2879,6 +2960,8 @@ var SynapClient = class {
|
|
|
2879
2960
|
types,
|
|
2880
2961
|
mode = "fast",
|
|
2881
2962
|
precision_level: precisionLevel = "high",
|
|
2963
|
+
query_date: queryDate,
|
|
2964
|
+
max_results_per_query: maxResultsPerQuery,
|
|
2882
2965
|
include_conversation_context: includeConversationContext = true,
|
|
2883
2966
|
scopes,
|
|
2884
2967
|
include_scope_labels: includeScopeLabels = false,
|
|
@@ -2893,7 +2976,12 @@ var SynapClient = class {
|
|
|
2893
2976
|
max_results: maxResults,
|
|
2894
2977
|
types,
|
|
2895
2978
|
mode,
|
|
2896
|
-
precision_level: precisionLevel
|
|
2979
|
+
precision_level: precisionLevel,
|
|
2980
|
+
// In `shared` so it reaches all four branches at once. The Python edit
|
|
2981
|
+
// threaded three call sites by hand and missed the client branch, which
|
|
2982
|
+
// sits one indent deeper; spreading removes that whole class of miss.
|
|
2983
|
+
query_date: queryDate,
|
|
2984
|
+
max_results_per_query: maxResultsPerQuery
|
|
2897
2985
|
};
|
|
2898
2986
|
const labels = [];
|
|
2899
2987
|
const tasks = [];
|
|
@@ -2958,7 +3046,7 @@ var SynapClient = class {
|
|
|
2958
3046
|
merged.conversation_context = await this.conversation.context.get_context_for_prompt({
|
|
2959
3047
|
conversation_id: conversationId
|
|
2960
3048
|
});
|
|
2961
|
-
} catch (
|
|
3049
|
+
} catch (e14) {
|
|
2962
3050
|
}
|
|
2963
3051
|
}
|
|
2964
3052
|
merged.formatted_context = formatForPrompt(merged, {
|
|
@@ -3003,9 +3091,14 @@ var SynapClient = class {
|
|
|
3003
3091
|
served_item_ids: served.servedItemIds,
|
|
3004
3092
|
scope,
|
|
3005
3093
|
source_bundle_ids: served.bundleId ? [served.bundleId] : [],
|
|
3006
|
-
timestamp_ms: Date.now()
|
|
3094
|
+
timestamp_ms: Date.now(),
|
|
3095
|
+
// How many distinct search queries the fetch carried. A hit never
|
|
3096
|
+
// reaches the fetch route, so this event is how the server learns it
|
|
3097
|
+
// happened and what it is charged by. The count only: this event must
|
|
3098
|
+
// not carry the caller's words.
|
|
3099
|
+
query_count: distinctQueryCount(_nullishCoalesce(options["search_query"], () => ( options["searchQuery"])))
|
|
3007
3100
|
});
|
|
3008
|
-
} catch (
|
|
3101
|
+
} catch (e15) {
|
|
3009
3102
|
}
|
|
3010
3103
|
}
|
|
3011
3104
|
/**
|
|
@@ -3030,7 +3123,7 @@ var SynapClient = class {
|
|
|
3030
3123
|
}),
|
|
3031
3124
|
scope
|
|
3032
3125
|
});
|
|
3033
|
-
} catch (
|
|
3126
|
+
} catch (e16) {
|
|
3034
3127
|
}
|
|
3035
3128
|
}
|
|
3036
3129
|
/**
|
|
@@ -3108,7 +3201,7 @@ function pick3(o2, snake, camel) {
|
|
|
3108
3201
|
function resolveBaseUrl(options) {
|
|
3109
3202
|
const explicit = _nullishCoalesce(options.baseUrl, () => ( options.api_base_url));
|
|
3110
3203
|
if (explicit !== void 0) return explicit;
|
|
3111
|
-
const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess',
|
|
3204
|
+
const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _54 => _54.trim, 'call', _55 => _55()]);
|
|
3112
3205
|
return fromEnv !== void 0 && fromEnv !== "" ? fromEnv : void 0;
|
|
3113
3206
|
}
|
|
3114
3207
|
function resolveCredentials(options) {
|
|
@@ -3175,5 +3268,6 @@ function resolveCredentials(options) {
|
|
|
3175
3268
|
|
|
3176
3269
|
|
|
3177
3270
|
|
|
3178
|
-
|
|
3271
|
+
|
|
3272
|
+
exports.ANY_SCOPE = _chunkT6U5PVADcjs.ANY_SCOPE; exports.AgentUnavailableError = _chunkT372OL3Qcjs.AgentUnavailableError; exports.AnticipationCache = _chunkT6U5PVADcjs.AnticipationCache; exports.AuthenticationError = _chunkT372OL3Qcjs.AuthenticationError; exports.BM25 = _chunkT6U5PVADcjs.BM25; exports.COMPACTION_LEVELS = COMPACTION_LEVELS; exports.CONTRACT = _chunkT6U5PVADcjs.CONTRACT; exports.ConflictError = _chunkT372OL3Qcjs.ConflictError; exports.ConnectionError = _chunkT372OL3Qcjs.ConnectionError; exports.ContextNotFoundError = _chunkT372OL3Qcjs.ContextNotFoundError; 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.FORGET_MODES = FORGET_MODES; exports.HttpTransport = HttpTransport; exports.INGEST_MODES = INGEST_MODES; exports.ITEM_COLLECTIONS = ITEM_COLLECTIONS; exports.InsufficientCreditsError = _chunkT372OL3Qcjs.InsufficientCreditsError; exports.InvalidConversationIdError = _chunkT372OL3Qcjs.InvalidConversationIdError; exports.InvalidInputError = _chunkT372OL3Qcjs.InvalidInputError; exports.InvalidInstanceIdError = _chunkT372OL3Qcjs.InvalidInstanceIdError; exports.ListeningAlreadyActiveError = _chunkT372OL3Qcjs.ListeningAlreadyActiveError; exports.ListeningNotActiveError = _chunkT372OL3Qcjs.ListeningNotActiveError; exports.NetworkTimeoutError = _chunkT372OL3Qcjs.NetworkTimeoutError; exports.PermanentError = _chunkT372OL3Qcjs.PermanentError; exports.RateLimitError = _chunkT372OL3Qcjs.RateLimitError; exports.SDKError = _chunkT372OL3Qcjs.SDKError; exports.SDK_VERSION = SDK_VERSION; exports.ServiceUnavailableError = _chunkT372OL3Qcjs.ServiceUnavailableError; exports.SessionExpiredError = _chunkT372OL3Qcjs.SessionExpiredError; exports.SynapClient = SynapClient; exports.SynapError = _chunkT372OL3Qcjs.SynapError; exports.SynapPermanentError = _chunkT372OL3Qcjs.SynapPermanentError; exports.SynapTransientError = _chunkT372OL3Qcjs.SynapTransientError; exports.THRESHOLDS = _chunkT6U5PVADcjs.THRESHOLDS; exports.TranscriptConflictError = _chunkT372OL3Qcjs.TranscriptConflictError; exports.TransientError = _chunkT372OL3Qcjs.TransientError; exports.flattenContextItems = flattenContextItems; exports.formatForPrompt = formatForPrompt; exports.isOutcomeUnknown = isOutcomeUnknown; exports.isRecallQuery = _chunkT6U5PVADcjs.isRecallQuery; exports.isSynapError = _chunkT372OL3Qcjs.isSynapError; exports.mergeScopeResults = mergeScopeResults; exports.resolvePath = resolvePath; exports.shouldRetry = shouldRetry; exports.stem = _chunkT6U5PVADcjs.stem; exports.tokenize = _chunkT6U5PVADcjs.tokenize;
|
|
3179
3273
|
//# sourceMappingURL=index.cjs.map
|