@maximem/synap-js-sdk 0.4.3 → 0.4.4
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-ARYEEKMU.cjs.map +1 -1
- package/dist/{chunk-HR5Y3KXS.cjs → chunk-2TVL5IPQ.cjs} +7 -1
- package/dist/chunk-2TVL5IPQ.cjs.map +1 -0
- package/dist/{chunk-VXRCBMCY.cjs → chunk-3JSE64GW.cjs} +1 -1
- package/dist/chunk-3JSE64GW.cjs.map +1 -0
- package/dist/{chunk-T3NZBIV2.js → chunk-OCMM2Z5P.js} +7 -1
- package/dist/chunk-OCMM2Z5P.js.map +1 -0
- package/dist/chunk-RB57I2IQ.cjs.map +1 -1
- package/dist/chunk-ZKOJDUN4.cjs.map +1 -1
- package/dist/{chunk-5SC3ELNK.js → chunk-ZU6ZC4SU.js} +1 -1
- package/dist/chunk-ZU6ZC4SU.js.map +1 -0
- package/dist/env-55ULHNJZ.cjs.map +1 -1
- package/dist/grpc/index.cjs +7 -7
- package/dist/grpc/index.cjs.map +1 -1
- package/dist/grpc/index.d.cts +4 -0
- package/dist/grpc/index.d.ts +4 -0
- package/dist/grpc/index.js +3 -3
- package/dist/index.cjs +157 -94
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +174 -20
- package/dist/index.d.ts +174 -20
- package/dist/index.js +77 -14
- package/dist/index.js.map +1 -1
- package/dist/stream-client-6V4FGKZ3.js +7 -0
- package/dist/stream-client-PRTOH62B.cjs +7 -0
- package/dist/stream-client-PRTOH62B.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-5SC3ELNK.js.map +0 -1
- package/dist/chunk-HR5Y3KXS.cjs.map +0 -1
- package/dist/chunk-T3NZBIV2.js.map +0 -1
- package/dist/chunk-VXRCBMCY.cjs.map +0 -1
- package/dist/stream-client-ME5N5NK4.js +0 -7
- package/dist/stream-client-ZN6ADZBR.cjs +0 -7
- package/dist/stream-client-ZN6ADZBR.cjs.map +0 -1
- /package/dist/{stream-client-ME5N5NK4.js.map → stream-client-6V4FGKZ3.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
TranscriptConflictError,
|
|
23
23
|
TransientError,
|
|
24
24
|
isSynapError
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-OCMM2Z5P.js";
|
|
26
26
|
import {
|
|
27
27
|
ANY_SCOPE,
|
|
28
28
|
AnticipationCache,
|
|
@@ -229,7 +229,7 @@ var HttpTransport = class {
|
|
|
229
229
|
this.#credentials = options.credentials;
|
|
230
230
|
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
231
231
|
this.timeouts = { ...DEFAULT_TIMEOUTS, ...options.timeouts };
|
|
232
|
-
this.retryPolicy = { ...DEFAULT_RETRY_POLICY, ...options.retryPolicy };
|
|
232
|
+
this.retryPolicy = options.retryPolicy === null ? { ...DEFAULT_RETRY_POLICY, maxAttempts: 1 } : { ...DEFAULT_RETRY_POLICY, ...options.retryPolicy };
|
|
233
233
|
this.userAgent = options.userAgent ?? "@maximem/synap-js-sdk";
|
|
234
234
|
this.fetchImpl = options.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
235
235
|
this.keepAliveOptions = options.keepAlive ?? {};
|
|
@@ -285,9 +285,16 @@ var HttpTransport = class {
|
|
|
285
285
|
setTimeouts(timeouts) {
|
|
286
286
|
this.timeouts = { ...this.timeouts, ...timeouts };
|
|
287
287
|
}
|
|
288
|
-
/**
|
|
288
|
+
/**
|
|
289
|
+
* `null` DISABLES retries, matching Python.
|
|
290
|
+
*
|
|
291
|
+
* Python's `SDKConfig(retry_policy=None)` leaves `self.retry_policy` unset and
|
|
292
|
+
* `max_attempts` falls to 1 (http_client.py:180). We restored the default
|
|
293
|
+
* policy instead, so a caller following the "Disabling Retries" documentation
|
|
294
|
+
* got three attempts and no way to turn them off.
|
|
295
|
+
*/
|
|
289
296
|
setRetryPolicy(policy) {
|
|
290
|
-
this.retryPolicy = policy === null ? { ...DEFAULT_RETRY_POLICY } : { ...this.retryPolicy, ...policy };
|
|
297
|
+
this.retryPolicy = policy === null ? { ...DEFAULT_RETRY_POLICY, maxAttempts: 1 } : { ...this.retryPolicy, ...policy };
|
|
291
298
|
}
|
|
292
299
|
close() {
|
|
293
300
|
this.closed = true;
|
|
@@ -435,7 +442,9 @@ async function toHttpError(response, correlationId) {
|
|
|
435
442
|
return new InsufficientCreditsError(message, {
|
|
436
443
|
...opts,
|
|
437
444
|
balanceCredits: numberOrNull(parsed["balance_credits"]),
|
|
438
|
-
requiredCredits: numberOrNull(parsed["required_credits"])
|
|
445
|
+
requiredCredits: numberOrNull(parsed["minimum_required_credits"]) ?? numberOrNull(parsed["required_credits"]),
|
|
446
|
+
recoveryUrl: stringOrNull(parsed["recovery_url"]),
|
|
447
|
+
redeemUrl: stringOrNull(parsed["redeem_url"])
|
|
439
448
|
});
|
|
440
449
|
case 409:
|
|
441
450
|
if (detailObject !== null && detailObject["code"] === "transcript_conflict") {
|
|
@@ -462,6 +471,9 @@ async function toHttpError(response, correlationId) {
|
|
|
462
471
|
function numberOrNull(v) {
|
|
463
472
|
return typeof v === "number" && Number.isFinite(v) ? v : null;
|
|
464
473
|
}
|
|
474
|
+
function stringOrNull(v) {
|
|
475
|
+
return typeof v === "string" && v !== "" ? v : null;
|
|
476
|
+
}
|
|
465
477
|
function withTimeout(ms, external) {
|
|
466
478
|
const controller = new AbortController();
|
|
467
479
|
const onExternalAbort = () => controller.abort(external?.reason);
|
|
@@ -536,9 +548,32 @@ function buildFetchRequest(scope, options) {
|
|
|
536
548
|
}
|
|
537
549
|
switch (scope) {
|
|
538
550
|
case "user":
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
551
|
+
{
|
|
552
|
+
if (!userId) throw new InvalidInputError("user_id is required");
|
|
553
|
+
body["user_id"] = userId;
|
|
554
|
+
const scopePath = opt(options, "scope_path", "scopePath");
|
|
555
|
+
if (scopePath !== void 0) body["scope"] = scopePath;
|
|
556
|
+
const contextMode = opt(options, "context_mode", "contextMode") ?? "in-conversation";
|
|
557
|
+
if (!VALID_CONTEXT_MODES.includes(contextMode)) {
|
|
558
|
+
throw new InvalidInputError(
|
|
559
|
+
`Invalid context_mode '${contextMode}'. Must be one of: ${VALID_CONTEXT_MODES.join(", ")}`
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
const lastN = opt(options, "last_n_conversations", "lastNConversations") ?? 1;
|
|
563
|
+
if (!Number.isInteger(lastN)) {
|
|
564
|
+
throw new InvalidInputError("last_n_conversations must be an integer");
|
|
565
|
+
}
|
|
566
|
+
if (lastN < 0 || lastN > 20) {
|
|
567
|
+
throw new InvalidInputError("last_n_conversations must be between 0 and 20");
|
|
568
|
+
}
|
|
569
|
+
if (contextMode === "conversation-summary") {
|
|
570
|
+
body["context_mode"] = contextMode;
|
|
571
|
+
body["include_profile"] = opt(options, "include_profile", "includeProfile") ?? true;
|
|
572
|
+
body["last_n_conversations"] = lastN;
|
|
573
|
+
}
|
|
574
|
+
if (customerId !== void 0) body["customer_id"] = customerId;
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
542
577
|
break;
|
|
543
578
|
case "customer":
|
|
544
579
|
if (!customerId) throw new InvalidInputError("customer_id is required");
|
|
@@ -554,6 +589,7 @@ function buildFetchRequest(scope, options) {
|
|
|
554
589
|
}
|
|
555
590
|
return { endpoint: ENDPOINT_BY_SCOPE[scope], body };
|
|
556
591
|
}
|
|
592
|
+
var VALID_CONTEXT_MODES = ["in-conversation", "conversation-summary"];
|
|
557
593
|
async function fetchContext(transport, scope, options = {}, hooks = {}) {
|
|
558
594
|
const startedAt = Date.now();
|
|
559
595
|
transport.checkCustomerId(
|
|
@@ -959,6 +995,15 @@ function validateInstanceId(instanceId) {
|
|
|
959
995
|
}
|
|
960
996
|
|
|
961
997
|
// src/conversation/interface.ts
|
|
998
|
+
var COMPACTION_LEVELS = [
|
|
999
|
+
"low",
|
|
1000
|
+
"medium",
|
|
1001
|
+
"high",
|
|
1002
|
+
"adaptive",
|
|
1003
|
+
"aggressive",
|
|
1004
|
+
"balanced",
|
|
1005
|
+
"conservative"
|
|
1006
|
+
];
|
|
962
1007
|
function either2(o2, snake, camel) {
|
|
963
1008
|
const a = o2[snake];
|
|
964
1009
|
if (a !== void 0) return a;
|
|
@@ -1229,15 +1274,26 @@ function createUserNamespace(transport, hooks = {}) {
|
|
|
1229
1274
|
}
|
|
1230
1275
|
|
|
1231
1276
|
// src/credits/interface.ts
|
|
1277
|
+
function iso2(v) {
|
|
1278
|
+
return v instanceof Date ? v.toISOString() : v;
|
|
1279
|
+
}
|
|
1232
1280
|
function createCreditsNamespace(transport) {
|
|
1233
1281
|
return {
|
|
1234
1282
|
async get_balance() {
|
|
1235
1283
|
return transport.request("credits_balance");
|
|
1236
1284
|
},
|
|
1237
1285
|
async get_ledger(options = {}) {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1286
|
+
const query = {
|
|
1287
|
+
limit: options.limit ?? 100,
|
|
1288
|
+
offset: options.offset ?? 0
|
|
1289
|
+
};
|
|
1290
|
+
const entryType = options.entry_type ?? options.entryType;
|
|
1291
|
+
if (entryType !== void 0) query["entry_type"] = entryType;
|
|
1292
|
+
const from = options.from_time ?? options.fromTime;
|
|
1293
|
+
if (from !== void 0) query["from"] = iso2(from);
|
|
1294
|
+
const to = options.to_time ?? options.toTime;
|
|
1295
|
+
if (to !== void 0) query["to"] = iso2(to);
|
|
1296
|
+
return transport.request("credits_ledger", { query });
|
|
1241
1297
|
},
|
|
1242
1298
|
async estimate(options) {
|
|
1243
1299
|
return transport.request("credits_estimate", {
|
|
@@ -1317,7 +1373,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1317
1373
|
if (client !== null) {
|
|
1318
1374
|
throw new ListeningAlreadyActiveError("Listening is already active on this instance");
|
|
1319
1375
|
}
|
|
1320
|
-
const { GrpcStreamClient } = await import("./stream-client-
|
|
1376
|
+
const { GrpcStreamClient } = await import("./stream-client-6V4FGKZ3.js");
|
|
1321
1377
|
const onContext = options.on_context ?? options.onContext;
|
|
1322
1378
|
const onDisconnect = options.on_disconnect ?? options.onDisconnect;
|
|
1323
1379
|
const onReconnect = options.on_reconnect ?? options.onReconnect;
|
|
@@ -1377,6 +1433,12 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1377
1433
|
session_id: options.session_id ?? options.sessionId ?? "",
|
|
1378
1434
|
metadata: options.metadata ?? {},
|
|
1379
1435
|
timestamp_ms: Date.now(),
|
|
1436
|
+
tool_name: options.tool_name ?? options.toolName ?? "",
|
|
1437
|
+
// Python serialises tool_args with json.dumps into tool_args_json.
|
|
1438
|
+
tool_args_json: (() => {
|
|
1439
|
+
const a = options.tool_args ?? options.toolArgs;
|
|
1440
|
+
return a === void 0 ? "" : JSON.stringify(a);
|
|
1441
|
+
})(),
|
|
1380
1442
|
search_queries: options.search_queries ?? options.searchQueries ?? [],
|
|
1381
1443
|
context_types: options.context_types ?? options.contextTypes ?? []
|
|
1382
1444
|
});
|
|
@@ -2422,8 +2484,8 @@ var SynapClient = class {
|
|
|
2422
2484
|
const whoami = await this.#transport.request("whoami", {});
|
|
2423
2485
|
const resolvedClientId = String(whoami["client_id"] ?? "");
|
|
2424
2486
|
const resolvedInstanceId = String(whoami["instance_id"] ?? "");
|
|
2425
|
-
const
|
|
2426
|
-
this.#transport.userContextIsolation = typeof
|
|
2487
|
+
const iso3 = whoami["user_context_isolation"];
|
|
2488
|
+
this.#transport.userContextIsolation = typeof iso3 === "string" ? iso3 : void 0;
|
|
2427
2489
|
this.#transport.updateCredentials({
|
|
2428
2490
|
...resolvedClientId !== "" && credentials.clientId === "" ? { clientId: resolvedClientId } : {},
|
|
2429
2491
|
...resolvedInstanceId !== "" && credentials.instanceId === "" ? { instanceId: resolvedInstanceId } : {}
|
|
@@ -2712,6 +2774,7 @@ export {
|
|
|
2712
2774
|
AnticipationCache,
|
|
2713
2775
|
AuthenticationError,
|
|
2714
2776
|
BM25,
|
|
2777
|
+
COMPACTION_LEVELS,
|
|
2715
2778
|
CONTRACT,
|
|
2716
2779
|
ConflictError,
|
|
2717
2780
|
ConnectionError,
|